You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1002 B
TypeScript
60 lines
1002 B
TypeScript
import { z } from "./deps/zod.ts";
|
|
import { ReplacerFn, ReviverFn, sig } from "./deps/yaypi.ts";
|
|
|
|
import { Schema } from "./schema.ts";
|
|
|
|
export const Api = {
|
|
v1: {
|
|
listSchemas: sig(
|
|
z.number().nullable(),
|
|
z.array(
|
|
z.object({
|
|
id: z.number(),
|
|
latestVersion: z.object({
|
|
version: z.number(),
|
|
schema: Schema,
|
|
}),
|
|
}),
|
|
),
|
|
),
|
|
saveSchema: sig(
|
|
z.object({
|
|
id: z.number().optional(),
|
|
schema: Schema,
|
|
}),
|
|
z.union([
|
|
z.object({
|
|
id: z.number(),
|
|
version: z.number(),
|
|
}),
|
|
z.string(),
|
|
]),
|
|
),
|
|
},
|
|
};
|
|
|
|
export const reviver: ReviverFn = (key, value) => {
|
|
if (typeof value !== "object") {
|
|
return value;
|
|
}
|
|
|
|
if ("__map" in value) {
|
|
delete value["__map"];
|
|
|
|
return new Map(Object.entries(value));
|
|
}
|
|
|
|
return value;
|
|
};
|
|
|
|
export const replacer: ReplacerFn = (key: string, value: any) => {
|
|
if (value instanceof Map) {
|
|
const res = Object.fromEntries(value.entries());
|
|
res["__map"] = 0;
|
|
|
|
return res;
|
|
}
|
|
|
|
return value;
|
|
};
|