Skip to content

Commit

Permalink
Update other httpd types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Dec 13, 2023
1 parent 24ea4ad commit 80e6705
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 70 deletions.
36 changes: 35 additions & 1 deletion httpd-client/lib/project/comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type { z } from "zod";
import { array, number, object, string, tuple } from "zod";
import {
array,
boolean,
literal,
number,
object,
string,
tuple,
union,
} from "zod";

export type Comment = z.infer<typeof commentSchema>;
export type Embed = z.infer<typeof commentSchema>["embeds"][0];
Expand All @@ -20,4 +29,29 @@ export const commentSchema = object({
reactions: array(tuple([string(), string()])),
timestamp: number(),
replyTo: string().nullable(),
resolved: boolean(),
});

const fileRangeSchema = union([
object({
type: literal("lines"),
range: object({ start: number(), end: number() }),
}),
object({
type: literal("chars"),
line: number(),
range: object({ start: number(), end: number() }),
}),
]);

const codeLocationSchema = object({
path: string(),
old: fileRangeSchema.optional(),
new: fileRangeSchema.optional(),
});

export type CodeLocation = z.infer<typeof codeLocationSchema>;

export const reviewCommentSchema = commentSchema.merge(
object({ location: codeLocationSchema }),
);
86 changes: 17 additions & 69 deletions httpd-client/lib/project/patch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Comment, Embed } from "./comment.js";
import type { CodeLocation, Embed } from "./comment.js";
import type { ZodSchema, z } from "zod";

import { commentSchema } from "./comment.js";
import { commentSchema, reviewCommentSchema } from "./comment.js";

import {
array,
Expand All @@ -15,12 +15,6 @@ import {
union,
} from "zod";

export type PatchState =
| { status: "draft" }
| { status: "open"; conflicts?: [string, string][] }
| { status: "archived" }
| { status: "merged"; revision: string; commit: string };

const patchStateSchema = union([
object({
status: literal("draft"),
Expand All @@ -37,51 +31,30 @@ const patchStateSchema = union([
revision: string(),
commit: string(),
}),
]) satisfies ZodSchema<PatchState>;
]);

export interface Merge {
author: { id: string; alias?: string };
revision: string;
commit: string;
timestamp: number;
}
export type PatchState = z.infer<typeof patchStateSchema>;

const mergeSchema = object({
author: object({ id: string(), alias: string().optional() }),
revision: string(),
commit: string(),
timestamp: number(),
}) satisfies ZodSchema<Merge>;
});

export type Verdict = "accept" | "reject";
export type Merge = z.infer<typeof mergeSchema>;

export interface Review {
author: { id: string; alias?: string };
verdict?: Verdict | null;
summary: string | null;
comments: string[];
timestamp: number;
}
export type Verdict = "accept" | "reject";

const reviewSchema = object({
author: object({ id: string(), alias: string().optional() }),
verdict: optional(union([literal("accept"), literal("reject")]).nullable()),
comments: array(string()),
comments: array(reviewCommentSchema),
summary: string().nullable(),
timestamp: number(),
}) satisfies ZodSchema<Review>;

export interface Revision {
id: string;
author: { id: string; alias?: string };
description: string;
base: string;
oid: string;
refs: string[];
discussions: Comment[];
reviews: Review[];
timestamp: number;
}
});

export type Review = z.infer<typeof reviewSchema>;

const revisionSchema = object({
id: string(),
Expand All @@ -93,19 +66,9 @@ const revisionSchema = object({
discussions: array(commentSchema),
reviews: array(reviewSchema),
timestamp: number(),
}) satisfies ZodSchema<Revision>;

export interface Patch {
id: string;
author: { id: string; alias?: string };
title: string;
state: PatchState;
target: string;
labels: string[];
merges: Merge[];
assignees: string[];
revisions: Revision[];
}
});

export type Revision = z.infer<typeof revisionSchema>;

export const patchSchema = object({
id: string(),
Expand All @@ -117,7 +80,9 @@ export const patchSchema = object({
merges: array(mergeSchema),
assignees: array(string()),
revisions: array(revisionSchema),
}) satisfies ZodSchema<Patch>;
});

export type Patch = z.infer<typeof patchSchema>;

export const patchesSchema = array(patchSchema) satisfies ZodSchema<Patch[]>;

Expand All @@ -126,23 +91,6 @@ export type LifecycleState =
| { status: "open" }
| { status: "archived" };

export type Range =
| {
type: "lines";
range: { start: number; end: number };
}
| {
type: "chars";
line: number;
range: { start: number; end: number };
};

export type CodeLocation = {
path: string;
old?: Range;
new?: Range;
};

export type PatchUpdateAction =
| { type: "edit"; title: string; target: "delegates" }
| { type: "label"; labels: string[] }
Expand Down

0 comments on commit 80e6705

Please sign in to comment.