This commit is contained in:
Morten Olsen
2025-09-08 22:22:40 +02:00
commit 1b02bc8e81
30 changed files with 5459 additions and 0 deletions

View File

View File

View File

@@ -0,0 +1,93 @@
import { z } from 'zod';
const metaValueSchema = z.union([z.string(), z.number(), z.boolean()]);
const documentSchema = z.object({
uri: z.string(),
created: z.iso.datetime(),
updated: z.iso.datetime(),
deleted: z.iso.datetime().nullish(),
type: z.string(),
title: z.string().nullish(),
description: z.string().nullish(),
tags: z.array(z.string()),
metadata: z.record(z.string(), metaValueSchema),
data: z.record(z.string(), z.unknown()),
});
type Document = z.infer<typeof Document>;
const documentUpsertSchema = documentSchema.omit({
created: true,
updated: true,
deleted: true,
});
type DocumentUpsert = z.infer<typeof documentUpsertSchema>;
const metaDateFilterSchema = z.object({
type: z.literal('date'),
field: z.string(),
filter: z.object({
gt: z.iso.datetime().optional(),
gte: z.iso.datetime().optional(),
lt: z.iso.datetime().optional(),
lte: z.iso.datetime().optional(),
nill: z.boolean().optional(),
}),
});
const metaNumberFilterSchema = z.object({
type: z.literal('number'),
field: z.string(),
filter: z.object({
gt: z.number().optional(),
gte: z.number().optional(),
lt: z.number().optional(),
lte: z.number().optional(),
eq: z.number().optional(),
neq: z.number().optional(),
nill: z.boolean().optional(),
}),
});
const metaTextFilterSchema = z.object({
type: z.literal('text'),
field: z.string(),
filter: z.object({
eq: z.string().optional(),
neq: z.string().optional(),
like: z.string().optional(),
nlike: z.string().optional(),
nill: z.boolean().optional(),
}),
});
const metaBoolFilterSchema = z.object({
type: z.literal('bool'),
field: z.string(),
filter: z.object({
eq: z.boolean(),
nill: z.boolean().optional(),
}),
});
const metaFilterSchema = z.union([
metaDateFilterSchema,
metaNumberFilterSchema,
metaTextFilterSchema,
metaBoolFilterSchema,
]);
type MetaFilter = z.infer<typeof metaFilterSchema>;
const documentSearchOptionsSchema = z.object({
uris: z.array(z.string()).optional(),
types: z.array(z.string()).optional(),
meta: z.array(metaFilterSchema).optional(),
});
type DocumentSearchOptions = z.infer<typeof documentSearchOptionsSchema>;
export type { Document, DocumentUpsert, MetaFilter, DocumentSearchOptions };
export { documentSchema, documentUpsertSchema, metaFilterSchema, documentSearchOptionsSchema };

View File