init
This commit is contained in:
0
packages/core/src/database/database.ts
Normal file
0
packages/core/src/database/database.ts
Normal file
0
packages/core/src/database/migrations/migrations.ts
Normal file
0
packages/core/src/database/migrations/migrations.ts
Normal file
0
packages/core/src/exports.ts
Normal file
0
packages/core/src/exports.ts
Normal file
93
packages/core/src/services/documents/documents.schemas.ts
Normal file
93
packages/core/src/services/documents/documents.schemas.ts
Normal 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 };
|
||||
0
packages/core/src/services/documents/documents.ts
Normal file
0
packages/core/src/services/documents/documents.ts
Normal file
0
packages/core/src/services/types/types.schemas.ts
Normal file
0
packages/core/src/services/types/types.schemas.ts
Normal file
0
packages/core/src/services/types/types.ts
Normal file
0
packages/core/src/services/types/types.ts
Normal file
0
packages/core/src/utils/services.ts
Normal file
0
packages/core/src/utils/services.ts
Normal file
Reference in New Issue
Block a user