summaryrefslogtreecommitdiffstats
path: root/src/schemas
diff options
context:
space:
mode:
Diffstat (limited to 'src/schemas')
-rw-r--r--src/schemas/common.ts17
-rw-r--r--src/schemas/releases.ts7
2 files changed, 21 insertions, 3 deletions
diff --git a/src/schemas/common.ts b/src/schemas/common.ts
new file mode 100644
index 0000000..ef1fefd
--- /dev/null
+++ b/src/schemas/common.ts
@@ -0,0 +1,17 @@
1import { fileAttributeSchema, imageAttributeSchema } from "$/deps/strapi.ts";
2
3const publicUrl = Deno.env.get("STRAPI_PUBLIC_URL") ?? Deno.env.get("STRAPI_URL");
4
5export const resolvedFileAttributeSchema = fileAttributeSchema.pipe(
6 ({ url, previewUrl, ...o }) => ({
7 ...o,
8 url: new URL(url, publicUrl).href,
9 ...(previewUrl ? { previewUrl: new URL(previewUrl, publicUrl).href } : {}),
10 }),
11);
12
13export const resolvedImageAttributeSchema = imageAttributeSchema.pipe((o) => ({
14 ...o,
15 previewUrl: o.previewUrl ? new URL(o.previewUrl, publicUrl).href : undefined,
16 url: new URL(o.url, publicUrl).href,
17}));
diff --git a/src/schemas/releases.ts b/src/schemas/releases.ts
index 0ccb6a6..529e8c9 100644
--- a/src/schemas/releases.ts
+++ b/src/schemas/releases.ts
@@ -1,13 +1,14 @@
1import { type } from "arktype"; 1import { type } from "arktype";
2 2
3import { nodeSchema } from "../deps/strapi.tsx"; 3import { resolvedFileAttributeSchema } from "$/schemas/common.ts";
4import { strapiLoader } from "../deps/strapi.tsx"; 4
5import { nodeSchema } from "../deps/strapi.ts";
5 6
6export const releaseStrapiSchema = type({ 7export const releaseStrapiSchema = type({
7 "version": "string", 8 "version": "string",
8 "date": "string.date.parse", 9 "date": "string.date.parse",
9 "notes?": nodeSchema.array().or("null"), 10 "notes?": nodeSchema.array().or("null"),
10 "files": strapiLoader.resolvedFileAttributeSchema, 11 "files": resolvedFileAttributeSchema,
11}); 12});
12 13
13export const releaseSchema = releaseStrapiSchema.merge({ 14export const releaseSchema = releaseStrapiSchema.merge({