From 7adcea414876b636635b8e0a3027b89d53e4572d Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 19 Apr 2024 11:16:08 +0200 Subject: [PATCH] Update components and interfaces for radicle-surf v0.21 --- httpd-client/index.ts | 4 + httpd-client/lib/project/commit.ts | 75 +++++--- src/views/projects/Changeset.svelte | 167 ++++-------------- src/views/projects/Changeset/FileDiff.svelte | 14 +- .../Changeset/FileLocationChange.svelte | 8 +- src/views/projects/History.svelte | 5 +- src/views/projects/router.ts | 2 +- tests/e2e/node.spec.ts | 2 +- tests/e2e/project.spec.ts | 2 +- tests/e2e/project/commit.spec.ts | 2 +- tests/support/fixtures.ts | 1 + tests/support/heartwood-version | 2 +- tests/visual/desktop/cob.spec.ts | 2 +- 13 files changed, 110 insertions(+), 176 deletions(-) diff --git a/httpd-client/index.ts b/httpd-client/index.ts index 449f17e6c..51fc3bce5 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -19,6 +19,8 @@ import type { Commit, CommitBlob, CommitHeader, + ChangesetWithDiff, + ChangesetWithoutDiff, Diff, DiffBlob, DiffContent, @@ -50,6 +52,8 @@ import { nodeConfigSchema, successResponseSchema } from "./lib/shared.js"; export type { BaseUrl, Blob, + ChangesetWithDiff, + ChangesetWithoutDiff, CodeLocation, Comment, Commit, diff --git a/httpd-client/lib/project/commit.ts b/httpd-client/lib/project/commit.ts index 0f46f908f..125a26c40 100644 --- a/httpd-client/lib/project/commit.ts +++ b/httpd-client/lib/project/commit.ts @@ -6,6 +6,8 @@ export type { Diff, DiffContent, DiffFile, + ChangesetWithDiff, + ChangesetWithoutDiff, HunkLine, Hunks, }; @@ -13,6 +15,7 @@ export type { import { array, boolean, + discriminatedUnion, literal, number, object, @@ -115,35 +118,47 @@ const changesetHunkSchema = object({ type DiffContent = z.infer; -const diffContentSchema = object({ - type: union([literal("plain"), literal("binary"), literal("empty")]), - hunks: array(changesetHunkSchema), - eof: union([ - literal("noneMissing"), - literal("oldMissing"), - literal("newMissing"), - literal("bothMissing"), - ]), -}); - +const diffContentSchema = discriminatedUnion("type", [ + object({ + type: literal("plain"), + stats: object({ + additions: number(), + deletions: number(), + }), + hunks: array(changesetHunkSchema), + eof: union([ + literal("noneMissing"), + literal("oldMissing"), + literal("newMissing"), + literal("bothMissing"), + ]), + }), + object({ type: literal("binary") }), + object({ type: literal("empty") }), +]); const diffChangesetSchema = object({ path: string(), diff: diffContentSchema, }); const diffAddedChangesetSchema = diffChangesetSchema.merge( - object({ new: diffFileSchema }), + object({ state: literal("added"), new: diffFileSchema }), ); const diffDeletedChangesetSchema = diffChangesetSchema.merge( - object({ old: diffFileSchema }), + object({ state: literal("deleted"), old: diffFileSchema }), ); const diffModifiedChangesetSchema = diffChangesetSchema.merge( - object({ new: diffFileSchema, old: diffFileSchema }), + object({ + state: literal("modified"), + new: diffFileSchema, + old: diffFileSchema, + }), ); const diffCopiedChangesetSchema = object({ + state: literal("copied"), newPath: string(), oldPath: string(), }); @@ -158,6 +173,7 @@ const diffCopiedWithModificationsChangesetSchema = ); const diffMovedChangesetSchema = object({ + state: literal("moved"), newPath: string(), oldPath: string(), current: diffFileSchema, @@ -175,20 +191,31 @@ const diffMovedWithModificationsChangesetSchema = diffMovedChangesetSchema type Diff = z.infer; +type ChangesetWithDiff = z.infer; +type ChangesetWithoutDiff = z.infer; + +const changesetWithDiffSchema = union([ + diffAddedChangesetSchema, + diffDeletedChangesetSchema, + diffModifiedChangesetSchema, + diffMovedWithModificationsChangesetSchema, + diffCopiedWithModificationsChangesetSchema, +]); +const changesetWithoutDiffSchema = union([ + diffMovedChangesetSchema, + diffCopiedChangesetSchema, +]); + const diffSchema = object({ - added: array(diffAddedChangesetSchema), - deleted: array(diffDeletedChangesetSchema), - modified: array(diffModifiedChangesetSchema), - moved: array( + files: array( union([ + diffAddedChangesetSchema, + diffDeletedChangesetSchema, + diffModifiedChangesetSchema, diffMovedChangesetSchema, diffMovedWithModificationsChangesetSchema, - ]), - ), - copied: array( - union([ - diffCopiedWithModificationsChangesetSchema, diffCopiedChangesetSchema, + diffCopiedWithModificationsChangesetSchema, ]), ), stats: object({ @@ -210,7 +237,7 @@ const commitSchema = object({ type Commits = z.infer; const commitsSchema = object({ - commits: array(commitSchema.omit({ files: true })), + commits: array(commitHeaderSchema), stats: object({ commits: number(), branches: number(), diff --git a/src/views/projects/Changeset.svelte b/src/views/projects/Changeset.svelte index fe9945142..8c589dc98 100644 --- a/src/views/projects/Changeset.svelte +++ b/src/views/projects/Changeset.svelte @@ -1,11 +1,5 @@