83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { z } from 'zod';
|
|
import { queryFilterSchema } from '@morten-olsen/stash-query-dsl';
|
|
|
|
import { createListResultSchema, queryDSLSchema } from '../../utils/utils.schema.js';
|
|
|
|
const documentSchema = z
|
|
.object({
|
|
id: z.guid(),
|
|
owner: z.string().nullable(),
|
|
createdAt: z.iso.datetime(),
|
|
updatedAt: z.iso.datetime(),
|
|
deletedAt: z.iso.datetime().nullable(),
|
|
contentType: z.string().nullable(),
|
|
text: z.string().nullable(),
|
|
source: z.string().nullable(),
|
|
sourceId: z.string().nullable(),
|
|
type: z.string().nullable(),
|
|
typeVersion: z.int().nullable(),
|
|
metadata: z.unknown().nullable(),
|
|
})
|
|
.meta({ id: 'Document' });
|
|
|
|
type Document = z.infer<typeof documentSchema>;
|
|
|
|
const documentUpsertSchema = z
|
|
.object({
|
|
id: z.guid().optional(),
|
|
owner: z.string().nullish(),
|
|
contentType: z.string().nullish(),
|
|
content: z.string().nullish(),
|
|
text: z.string().nullish(),
|
|
source: z.string().nullish(),
|
|
sourceId: z.string().nullish(),
|
|
type: z.string().nullish(),
|
|
typeVersion: z.int().nullish(),
|
|
metadata: z.unknown().nullish(),
|
|
})
|
|
.meta({
|
|
id: 'DocumentUpsert',
|
|
example: {
|
|
text: 'the cat is yellow',
|
|
contentType: 'text/plain',
|
|
source: 'test',
|
|
sourceId: 'test',
|
|
type: 'raw',
|
|
metadata: {
|
|
foo: 'bar',
|
|
bar: 'baz',
|
|
},
|
|
},
|
|
});
|
|
|
|
type DocumentUpsert = z.infer<typeof documentUpsertSchema>;
|
|
|
|
const documentUpsertResultSchema = z.object({
|
|
action: z.enum(['inserted', 'updated', 'skipped']),
|
|
id: z.string(),
|
|
document: documentSchema,
|
|
});
|
|
|
|
type DocumentUpsertResult = z.infer<typeof documentUpsertResultSchema>;
|
|
|
|
const documentFilterSchema = z.object({
|
|
offset: z.number().default(0),
|
|
limit: z.number().default(20),
|
|
condition: z.union([queryDSLSchema, queryFilterSchema]),
|
|
});
|
|
|
|
type DocumentFilter = z.infer<typeof documentFilterSchema>;
|
|
|
|
const documentFindResultSchema = createListResultSchema(documentSchema);
|
|
|
|
type DocumentFindResult = z.infer<typeof documentFindResultSchema>;
|
|
|
|
export type { Document, DocumentUpsert, DocumentUpsertResult, DocumentFilter, DocumentFindResult };
|
|
export {
|
|
documentSchema,
|
|
documentUpsertSchema,
|
|
documentUpsertResultSchema,
|
|
documentFilterSchema,
|
|
documentFindResultSchema,
|
|
};
|