chore: improved schema
This commit is contained in:
@@ -1,31 +1,37 @@
|
||||
import { z } from 'zod';
|
||||
import { queryFilterSchema } from '@morten-olsen/stash-query-dsl';
|
||||
|
||||
import { createListResultSchema } from '#root/utils/utils.schema.js';
|
||||
import { createListResultSchema, queryDSLSchema } from '#root/utils/utils.schema.js';
|
||||
|
||||
const documentChunkSchema = z.object({
|
||||
id: z.string(),
|
||||
owner: z.string(),
|
||||
content: z.string(),
|
||||
metadata: z.unknown(),
|
||||
});
|
||||
const documentChunkSchema = z
|
||||
.object({
|
||||
id: z.guid(),
|
||||
owner: z.string(),
|
||||
content: z.string(),
|
||||
metadata: z.unknown(),
|
||||
})
|
||||
.meta({ id: 'DocumentChunk' });
|
||||
|
||||
type DocumentChunk = z.infer<typeof documentChunkSchema>;
|
||||
|
||||
const documentChunkFilterSchema = z.object({
|
||||
limit: z.number().default(20),
|
||||
offset: z.number().default(0),
|
||||
semanticText: z.string().optional(),
|
||||
conditions: z.union([queryFilterSchema, z.string()]).optional(),
|
||||
});
|
||||
const documentChunkFilterSchema = z
|
||||
.object({
|
||||
limit: z.number().default(20),
|
||||
offset: z.number().default(0),
|
||||
semanticText: z.string().optional(),
|
||||
conditions: z.union([queryDSLSchema, queryFilterSchema]).optional(),
|
||||
})
|
||||
.meta({ id: 'DocumentChunkFilter' });
|
||||
|
||||
type DocumentChunkFilter = z.infer<typeof documentChunkFilterSchema>;
|
||||
|
||||
const documentChunksFindResultSchema = createListResultSchema(
|
||||
documentChunkSchema.extend({
|
||||
distance: z.number().optional(),
|
||||
}),
|
||||
);
|
||||
documentChunkSchema
|
||||
.extend({
|
||||
distance: z.number().optional(),
|
||||
})
|
||||
.meta({ id: 'DocumentChunkWithDistance' }),
|
||||
).meta({ id: 'DocumentChunkFindResult' });
|
||||
|
||||
type DocumentChunksFindResult = z.infer<typeof documentChunksFindResultSchema>;
|
||||
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
import { z } from 'zod';
|
||||
import { queryFilterSchema } from '@morten-olsen/stash-query-dsl';
|
||||
|
||||
import { createListResultSchema } from '#root/utils/utils.schema.js';
|
||||
import { createListResultSchema, queryDSLSchema } from '#root/utils/utils.schema.js';
|
||||
|
||||
const documentSchema = z.object({
|
||||
id: z.string(),
|
||||
owner: z.string().nullable(),
|
||||
createdAt: z.iso.datetime(),
|
||||
updatedAt: z.iso.datetime(),
|
||||
deletedAt: z.iso.datetime().nullable(),
|
||||
contentType: z.string().nullable(),
|
||||
content: z.string().nullable(),
|
||||
source: z.string().nullable(),
|
||||
sourceId: z.string().nullable(),
|
||||
type: z.string(),
|
||||
typeVersion: z.int().nullable(),
|
||||
searchText: z.string().nullable(),
|
||||
metadata: z.unknown(),
|
||||
});
|
||||
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(),
|
||||
content: z.string().nullable(),
|
||||
source: z.string().nullable(),
|
||||
sourceId: z.string().nullable(),
|
||||
type: z.string(),
|
||||
typeVersion: z.int().nullable(),
|
||||
searchText: z.string().nullable(),
|
||||
metadata: z.unknown(),
|
||||
})
|
||||
.meta({ id: 'Document' });
|
||||
|
||||
type Document = z.infer<typeof documentSchema>;
|
||||
|
||||
const documentUpsertSchema = z
|
||||
.object({
|
||||
id: z.string().nullish(),
|
||||
id: z.guid().optional(),
|
||||
owner: z.string().nullish(),
|
||||
contentType: z.string().nullish(),
|
||||
content: z.string().nullish(),
|
||||
@@ -35,6 +37,7 @@ const documentUpsertSchema = z
|
||||
metadata: z.unknown().nullish(),
|
||||
})
|
||||
.meta({
|
||||
id: 'DocumentUpsert',
|
||||
example: {
|
||||
content: 'the cat is yellow',
|
||||
contentType: 'text/plain',
|
||||
@@ -61,7 +64,7 @@ type DocumentUpsertResult = z.infer<typeof documentUpsertResultSchema>;
|
||||
const documentFilterSchema = z.object({
|
||||
offset: z.number().default(0),
|
||||
limit: z.number().default(20),
|
||||
condition: z.union([queryFilterSchema, z.string()]),
|
||||
condition: z.union([queryDSLSchema, queryFilterSchema]),
|
||||
});
|
||||
|
||||
type DocumentFilter = z.infer<typeof documentFilterSchema>;
|
||||
|
||||
@@ -5,4 +5,12 @@ const createListResultSchema = <T extends ZodType>(schema: T) =>
|
||||
items: z.array(schema),
|
||||
});
|
||||
|
||||
export { createListResultSchema };
|
||||
const queryDSLSchema = z
|
||||
.string()
|
||||
.describe('Query DSL based filter')
|
||||
.meta({
|
||||
id: 'QueryDSLString',
|
||||
examples: ["metadata.foo = 'bar'"],
|
||||
});
|
||||
|
||||
export { createListResultSchema, queryDSLSchema };
|
||||
|
||||
Reference in New Issue
Block a user