@tstdl/base 0.92.85 → 0.92.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/ai.service.d.ts +1 -1
- package/ai/ai.service.js +3 -3
- package/ai/types.d.ts +1 -1
- package/authentication/authentication.api.d.ts +9 -9
- package/authentication/models/schemas.d.ts +2 -2
- package/cancellation/token.d.ts +1 -1
- package/document-management/api/document-management.api.d.ts +94 -94
- package/document-management/models/document-category.model.d.ts +1 -0
- package/document-management/models/document-index.model.d.ts +7 -0
- package/document-management/models/document-index.model.js +32 -0
- package/document-management/models/document-request-file.model.d.ts +1 -1
- package/document-management/models/document-request-file.model.js +2 -2
- package/document-management/models/document-type.model.d.ts +1 -0
- package/document-management/models/document.model.d.ts +1 -1
- package/document-management/models/document.model.js +2 -2
- package/document-management/models/service-models/document.service-model.d.ts +51 -51
- package/document-management/models/service-models/document.service-model.js +2 -2
- package/document-management/server/drizzle/{0000_sloppy_fenris.sql → 0000_useful_overlord.sql} +2 -2
- package/document-management/server/drizzle/meta/0000_snapshot.json +5 -5
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/drizzle.config.js +1 -1
- package/document-management/server/module.d.ts +1 -1
- package/document-management/server/module.js +1 -1
- package/document-management/server/schemas.d.ts +33 -0
- package/document-management/{models → server}/schemas.js +14 -14
- package/document-management/server/services/document-management.service.d.ts +17 -3
- package/document-management/server/services/document-management.service.js +65 -17
- package/examples/orm/schemas.d.ts +1 -1
- package/mail/drizzle.config.js +1 -1
- package/mail/models/schemas.d.ts +1 -1
- package/orm/decorators.d.ts +4 -4
- package/orm/entity.d.ts +5 -7
- package/orm/entity.js +9 -1
- package/orm/index.d.ts +1 -0
- package/orm/index.js +1 -0
- package/orm/query.d.ts +1 -3
- package/orm/query.js +0 -1
- package/orm/repository.types.d.ts +32 -0
- package/orm/repository.types.js +1 -0
- package/orm/server/database-schema.d.ts +4 -4
- package/orm/server/drizzle/schema-converter.d.ts +1 -1
- package/orm/server/index.d.ts +1 -0
- package/orm/server/index.js +1 -0
- package/orm/server/query-converter.d.ts +1 -2
- package/orm/server/query-converter.js +66 -61
- package/orm/server/repository.d.ts +78 -42
- package/orm/server/repository.js +202 -106
- package/orm/server/sqls.d.ts +7 -0
- package/orm/server/sqls.js +6 -0
- package/orm/server/types.d.ts +3 -3
- package/orm/types.d.ts +1 -1
- package/package.json +11 -9
- package/queue/enqueue-batch.d.ts +1 -0
- package/queue/enqueue-batch.js +1 -1
- package/queue/mongo/queue.d.ts +9 -4
- package/queue/mongo/queue.js +5 -6
- package/queue/postgres/drizzle/0000_zippy_moondragon.sql +11 -0
- package/queue/postgres/drizzle/meta/0000_snapshot.json +90 -0
- package/queue/postgres/drizzle/meta/_journal.json +13 -0
- package/queue/postgres/drizzle.config.d.ts +2 -0
- package/queue/postgres/drizzle.config.js +11 -0
- package/queue/postgres/index.d.ts +4 -0
- package/queue/postgres/index.js +4 -0
- package/queue/postgres/job.model.d.ts +13 -0
- package/queue/postgres/job.model.js +55 -0
- package/queue/postgres/module.d.ts +9 -0
- package/queue/postgres/module.js +29 -0
- package/queue/postgres/queue.d.ts +28 -0
- package/queue/postgres/queue.js +149 -0
- package/queue/postgres/queue.provider.d.ts +7 -0
- package/queue/postgres/queue.provider.js +21 -0
- package/queue/postgres/schemas.d.ts +3 -0
- package/queue/postgres/schemas.js +4 -0
- package/queue/provider.d.ts +2 -1
- package/queue/queue.d.ts +18 -6
- package/schema/schemas/object.d.ts +1 -1
- package/utils/timing.d.ts +4 -3
- package/utils/timing.js +3 -1
- package/document-management/models/schemas.d.ts +0 -33
|
@@ -4,6 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
import { AiService } from '../../../ai/ai.service.js';
|
|
7
8
|
import { getEntityMap } from '../../../database/index.js';
|
|
8
9
|
import { Enumerable } from '../../../enumerable/index.js';
|
|
9
10
|
import { BadRequestError } from '../../../errors/index.js';
|
|
@@ -11,13 +12,15 @@ import { getMimeType, getMimeTypeExtensions } from '../../../file/index.js';
|
|
|
11
12
|
import { Singleton, inject, injectArgument, provide, resolveArgumentType } from '../../../injector/index.js';
|
|
12
13
|
import { ObjectStorage } from '../../../object-storage/index.js';
|
|
13
14
|
import { DatabaseConfig, EntityRepositoryConfig, injectRepository } from '../../../orm/server/index.js';
|
|
15
|
+
import { array, enumeration, integer, nullable, object, string } from '../../../schema/index.js';
|
|
14
16
|
import { toArray } from '../../../utils/array/index.js';
|
|
15
|
-
import { assertDefinedPass, compareByValueSelectionToOrder, currentTimestamp, digest, isBoolean, isDefined, isNotNull, isNull, isNumber, isString, isUint8Array, millisecondsPerMinute } from '../../../utils/index.js';
|
|
17
|
+
import { assertDefinedPass, assertStringPass, compareByValueSelectionToOrder, currentTimestamp, digest, isBoolean, isDefined, isNotNull, isNull, isNumber, isString, isUint8Array, millisecondsPerMinute } from '../../../utils/index.js';
|
|
16
18
|
import { groupToMap } from '../../../utils/iterable-helpers/index.js';
|
|
17
19
|
import { readBinaryStream } from '../../../utils/stream/index.js';
|
|
18
20
|
import { Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, DocumentProperty, DocumentPropertyBooleanValue, DocumentPropertyDataType, DocumentPropertyDecimalValue, DocumentPropertyIntegerValue, DocumentPropertyTextValue, DocumentRequest, DocumentRequestCollection, DocumentRequestFile, DocumentRequestTemplate, DocumentRequestsTemplate, DocumentType, DocumentTypeProperty } from '../../models/index.js';
|
|
19
21
|
import { DocumentManagementConfig } from '../module.js';
|
|
20
22
|
let DocumentManagementService = class DocumentManagementService {
|
|
23
|
+
#aiService = inject(AiService);
|
|
21
24
|
documentService = injectRepository(Document);
|
|
22
25
|
documentFileService = injectRepository(DocumentFile);
|
|
23
26
|
documentCollectionService = injectRepository(DocumentCollection);
|
|
@@ -42,8 +45,8 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
42
45
|
this.documentCollectionService.withTransaction(transaction).loadMany(collectionIds),
|
|
43
46
|
this.documentCollectionDocumentService.withTransaction(transaction).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
44
47
|
this.documentRequestCollectionService.withTransaction(transaction).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
45
|
-
this.documentCategoryService.withTransaction(transaction).loadManyByQuery({}, { order:
|
|
46
|
-
this.documentTypeService.withTransaction(transaction).loadManyByQuery({}, { order:
|
|
48
|
+
this.documentCategoryService.withTransaction(transaction).loadManyByQuery({}, { order: 'label' }),
|
|
49
|
+
this.documentTypeService.withTransaction(transaction).loadManyByQuery({}, { order: 'label' })
|
|
47
50
|
]);
|
|
48
51
|
const documentIds = collectionDocuments.map((document) => document.documentId);
|
|
49
52
|
const requestIds = requestCollections.map((requestCollection) => requestCollection.requestId);
|
|
@@ -88,7 +91,7 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
88
91
|
}
|
|
89
92
|
async loadDocumentRequestsTemplateData() {
|
|
90
93
|
const [requestsTemplates, requestTemplates] = await Promise.all([
|
|
91
|
-
this.documentRequestsTemplateService.loadManyByQuery({}, { order:
|
|
94
|
+
this.documentRequestsTemplateService.loadManyByQuery({}, { order: 'label' }),
|
|
92
95
|
this.documentRequestTemplateService.loadManyByQuery({})
|
|
93
96
|
]);
|
|
94
97
|
const templates = requestsTemplates.map((requestsTemplate) => ({
|
|
@@ -99,8 +102,8 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
99
102
|
}
|
|
100
103
|
async loadCategoriesAndTypes() {
|
|
101
104
|
const [categories, types] = await Promise.all([
|
|
102
|
-
this.documentCategoryService.loadManyByQuery({}, { order:
|
|
103
|
-
this.documentTypeService.loadManyByQuery({}, { order:
|
|
105
|
+
this.documentCategoryService.loadManyByQuery({}, { order: 'label' }),
|
|
106
|
+
this.documentTypeService.loadManyByQuery({}, { order: 'label' })
|
|
104
107
|
]);
|
|
105
108
|
return { categories, types };
|
|
106
109
|
}
|
|
@@ -169,14 +172,12 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
169
172
|
async deleteDocumentRequestTemplate(parameters) {
|
|
170
173
|
return this.documentRequestTemplateService.delete(parameters.id);
|
|
171
174
|
}
|
|
172
|
-
async createDocument({ typeId,
|
|
175
|
+
async createDocument({ typeId, title, date, expiration, originalFileName, collectionIds, properties, metadata }, content) {
|
|
173
176
|
return this.documentService.transaction(async (_, transaction) => {
|
|
174
177
|
const documentFile = await this.createDocumentFile(content, originalFileName, transaction);
|
|
175
|
-
const document = await this.documentService.withTransaction(transaction).insert({ fileId: documentFile.id, typeId,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
await this.documentCollectionDocumentService.withTransaction(transaction).insert({ collectionId, documentId: document.id, archiveTimestamp: null });
|
|
179
|
-
}
|
|
178
|
+
const document = await this.documentService.withTransaction(transaction).insert({ fileId: documentFile.id, typeId, title, date, expiration, metadata });
|
|
179
|
+
for (const collectionId of toArray(collectionIds)) {
|
|
180
|
+
await this.documentCollectionDocumentService.withTransaction(transaction).insert({ collectionId, documentId: document.id, archiveTimestamp: null });
|
|
180
181
|
}
|
|
181
182
|
if (isDefined(properties)) {
|
|
182
183
|
const mappedProperties = properties.map((property) => ({ ...property, documentId: document.id }));
|
|
@@ -196,7 +197,7 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
196
197
|
const document = await this.documentService.withTransaction(transaction).insert({
|
|
197
198
|
fileId: requestFile.fileId,
|
|
198
199
|
typeId: request.typeId,
|
|
199
|
-
|
|
200
|
+
title: requestFile.title,
|
|
200
201
|
date: null,
|
|
201
202
|
expiration: null,
|
|
202
203
|
metadata: documentMetadata
|
|
@@ -217,8 +218,8 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
217
218
|
await this.documentRequestFileService.withTransaction(transaction).update(id, { approval: false, approvalComment, approvalTimestamp: currentTimestamp(), metadata });
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
|
-
async updateDocumentRequestFile({ id,
|
|
221
|
-
return this.documentRequestFileService.update(id, {
|
|
221
|
+
async updateDocumentRequestFile({ id, title, approvalComment, metadata }) {
|
|
222
|
+
return this.documentRequestFileService.update(id, { title, approvalComment, metadata });
|
|
222
223
|
}
|
|
223
224
|
async deleteDocumentRequestFile({ id, metadata }) {
|
|
224
225
|
const requestFile = await this.documentRequestFileService.load(id);
|
|
@@ -243,7 +244,7 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
243
244
|
return documentFile;
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
|
-
async createDocumentRequestFile({ requestId,
|
|
247
|
+
async createDocumentRequestFile({ requestId, title, originalFileName, metadata }, content) {
|
|
247
248
|
return this.documentRequestFileService.transaction(async (_, transaction) => {
|
|
248
249
|
const [request, existingRequestFiles] = await Promise.all([
|
|
249
250
|
this.documentRequestService.withTransaction(transaction).load(requestId),
|
|
@@ -254,7 +255,7 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
254
255
|
throw new BadRequestError('Maximum amount of allowed files reached.');
|
|
255
256
|
}
|
|
256
257
|
const file = await this.createDocumentFile(content, originalFileName, transaction);
|
|
257
|
-
return this.documentRequestFileService.withTransaction(transaction).insert({ requestId, fileId: file.id,
|
|
258
|
+
return this.documentRequestFileService.withTransaction(transaction).insert({ requestId, fileId: file.id, title, createdDocumentId: null, approval: null, approvalComment: null, approvalTimestamp: null, metadata });
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
261
|
async createDocumentRequest(parameters, transaction) {
|
|
@@ -325,6 +326,53 @@ let DocumentManagementService = class DocumentManagementService {
|
|
|
325
326
|
async assignPropertyToType(parameters) {
|
|
326
327
|
await this.documentTypePropertyService.insert(parameters);
|
|
327
328
|
}
|
|
329
|
+
async extractDocumentInformation() {
|
|
330
|
+
const file = await this.#aiService.processFile({ path: '', mimeType: '' });
|
|
331
|
+
const types = await this.documentTypeService.loadAll();
|
|
332
|
+
const typeLabels = types.map((type) => type.label);
|
|
333
|
+
const generationSchema = object({
|
|
334
|
+
documentTitle: string(),
|
|
335
|
+
documentSubtitle: nullable(string()),
|
|
336
|
+
documentTypes: array(enumeration(typeLabels)),
|
|
337
|
+
documentSummary: string(),
|
|
338
|
+
documentTags: array(string()),
|
|
339
|
+
documentDate: nullable(object({ year: integer(), month: integer(), day: integer() }))
|
|
340
|
+
});
|
|
341
|
+
const generation = await this.#aiService.generate({
|
|
342
|
+
model: 'gemini-2.0-flash',
|
|
343
|
+
generationOptions: {
|
|
344
|
+
maxOutputTokens: 2048,
|
|
345
|
+
temperature: 0.2,
|
|
346
|
+
topP: 0.2
|
|
347
|
+
},
|
|
348
|
+
generationSchema,
|
|
349
|
+
contents: [
|
|
350
|
+
{
|
|
351
|
+
role: 'user', parts: [
|
|
352
|
+
{ file: file.file },
|
|
353
|
+
{
|
|
354
|
+
text: `Extrahiere den Inhalt des Dokuments in das angegebenen JSON Schema.
|
|
355
|
+
|
|
356
|
+
Gib in der summary ausführlich an, welche Informationen in dem Dokument vorkommen (ohne konkrete Werte).
|
|
357
|
+
Erstelle bis zu 7 möglichst spezifische Tags ohne allgemeinen Worte.
|
|
358
|
+
Antworte auf deutsch.`
|
|
359
|
+
}
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
});
|
|
364
|
+
const resultJson = JSON.parse(assertStringPass(generation.text, 'No text generated.'));
|
|
365
|
+
const result = generationSchema.parse(resultJson);
|
|
366
|
+
result.documentTags = result.documentTags.filter((tag) => (tag != result.documentTitle) && (tag != result.documentSubtitle));
|
|
367
|
+
return {
|
|
368
|
+
title: result.documentTitle,
|
|
369
|
+
subtitle: result.documentSubtitle,
|
|
370
|
+
types: result.documentTypes.map((typeLabel) => types.find((type) => type.label == typeLabel)).filter(isDefined),
|
|
371
|
+
summary: result.documentSummary,
|
|
372
|
+
tags: result.documentTags,
|
|
373
|
+
date: result.documentDate
|
|
374
|
+
};
|
|
375
|
+
}
|
|
328
376
|
getDocumentPropertyValueService(dataType) {
|
|
329
377
|
switch (dataType) {
|
|
330
378
|
case DocumentPropertyDataType.Text:
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { User } from './user.model.js';
|
|
2
2
|
export declare const mySchema: import("../../orm/server/database-schema.js").DatabaseSchema<"my_application">;
|
|
3
|
-
export declare const user: import("../../orm/server/types.js").PgTableFromType<"my_application"
|
|
3
|
+
export declare const user: import("../../orm/server/types.js").PgTableFromType<typeof User, "my_application">;
|
package/mail/drizzle.config.js
CHANGED
package/mail/models/schemas.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { MailLog } from './mail-log.model.js';
|
|
2
2
|
export declare const mailSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"mail">;
|
|
3
|
-
export declare const mailLog: import("../../orm/server/types.js").PgTableFromType<"mail"
|
|
3
|
+
export declare const mailLog: import("../../orm/server/types.js").PgTableFromType<typeof MailLog, "mail">;
|
package/orm/decorators.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { AbstractConstructor, TypedOmit } from '../types.js';
|
|
|
4
4
|
import type { Entity, EntityType } from './entity.js';
|
|
5
5
|
import type { PgTableFromType } from './server/types.js';
|
|
6
6
|
type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat', string>;
|
|
7
|
-
export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<
|
|
7
|
+
export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<EntityType<T>>) => SQL;
|
|
8
8
|
export type OrmTableReflectionData = {
|
|
9
9
|
name?: string;
|
|
10
10
|
schema?: string;
|
|
@@ -60,9 +60,9 @@ type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
|
|
|
60
60
|
export declare function Table(name?: string, options?: TypedOmit<TableOptions, 'schema'>): ClassDecorator;
|
|
61
61
|
export declare function Table(options?: TableOptions): ClassDecorator;
|
|
62
62
|
export declare function Unique(name?: string, options?: UniqueReflectionData['options']): PropertyDecorator;
|
|
63
|
-
export declare function Unique(name: string | undefined, columns: [string,
|
|
64
|
-
export declare function Unique(columns: [string,
|
|
63
|
+
export declare function Unique<T>(name: string | undefined, columns: [Extract<keyof T, string>, ...Extract<keyof T, string>[]], options?: UniqueReflectionData['options']): ClassDecorator;
|
|
64
|
+
export declare function Unique<T>(columns: [Extract<keyof T, string>, ...Extract<keyof T, string>[]], options?: UniqueReflectionData['options']): ClassDecorator;
|
|
65
65
|
export declare function Index(name?: string, options?: IndexReflectionData['options']): PropertyDecorator;
|
|
66
|
-
export declare function Index(name: string
|
|
66
|
+
export declare function Index(name: string, columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
|
|
67
67
|
export declare function Index(columns: [string, ...string[]], options?: IndexReflectionData['options']): ClassDecorator;
|
|
68
68
|
export {};
|
package/orm/entity.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import type { Type
|
|
2
|
-
import type { UntaggedDeep } from '../types/index.js';
|
|
1
|
+
import type { Type } from '../types.js';
|
|
3
2
|
import { Embedded, type HasDefault, type IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
|
|
4
|
-
export interface EntityType<T extends Entity = Entity> extends Type<T> {
|
|
3
|
+
export interface EntityType<T extends Entity | EntityWithoutMetadata = Entity | EntityWithoutMetadata> extends Type<T> {
|
|
5
4
|
readonly entityName?: string;
|
|
6
5
|
}
|
|
7
|
-
export type NewEntity<T extends Entity> = UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
8
|
-
id?: string;
|
|
9
|
-
metadata?: Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
10
|
-
}>;
|
|
11
6
|
export declare abstract class EntityMetadataAttributes {
|
|
12
7
|
[key: string]: unknown;
|
|
13
8
|
}
|
|
@@ -22,3 +17,6 @@ export declare abstract class Entity {
|
|
|
22
17
|
id: IsPrimaryKey<HasDefault<Uuid>>;
|
|
23
18
|
metadata: Embedded<EntityMetadata>;
|
|
24
19
|
}
|
|
20
|
+
export declare abstract class EntityWithoutMetadata {
|
|
21
|
+
id: IsPrimaryKey<HasDefault<Uuid>>;
|
|
22
|
+
}
|
package/orm/entity.js
CHANGED
|
@@ -44,7 +44,7 @@ __decorate([
|
|
|
44
44
|
__metadata("design:type", Object)
|
|
45
45
|
], EntityMetadata.prototype, "attributes", void 0);
|
|
46
46
|
EntityMetadata = __decorate([
|
|
47
|
-
Index(
|
|
47
|
+
Index(['revision', 'revisionTimestamp'])
|
|
48
48
|
], EntityMetadata);
|
|
49
49
|
export { EntityMetadata };
|
|
50
50
|
export class Entity {
|
|
@@ -60,3 +60,11 @@ __decorate([
|
|
|
60
60
|
Embedded(EntityMetadata, { prefix: null }),
|
|
61
61
|
__metadata("design:type", Object)
|
|
62
62
|
], Entity.prototype, "metadata", void 0);
|
|
63
|
+
export class EntityWithoutMetadata {
|
|
64
|
+
id;
|
|
65
|
+
}
|
|
66
|
+
__decorate([
|
|
67
|
+
PrimaryKey(),
|
|
68
|
+
Uuid({ defaultRandom: true }),
|
|
69
|
+
__metadata("design:type", Object)
|
|
70
|
+
], EntityWithoutMetadata.prototype, "id", void 0);
|
package/orm/index.d.ts
CHANGED
package/orm/index.js
CHANGED
package/orm/query.d.ts
CHANGED
|
@@ -19,8 +19,6 @@ export type Query<T = any> = SQLWrapper | QueryObject<T>;
|
|
|
19
19
|
export type QueryObject<T> = LogicalQuery<T> | (ComparisonQueryBody<T> & SpecialQuery<T>);
|
|
20
20
|
export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
|
|
21
21
|
export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$text" | "$geoShape" | "$geoDistance" | "$textSpan")[];
|
|
22
|
-
export type Order = 'asc' | 'desc';
|
|
23
|
-
export declare const allOrders: Order[];
|
|
24
22
|
export type Operator = 'and' | 'or';
|
|
25
23
|
export declare const allOperators: Operator[];
|
|
26
24
|
export type LogicalAndQuery<T = any> = {
|
|
@@ -32,7 +30,7 @@ export type LogicalOrQuery<T = any> = {
|
|
|
32
30
|
export type LogicalNorQuery<T = any> = {
|
|
33
31
|
$nor: readonly Query<T>[];
|
|
34
32
|
};
|
|
35
|
-
export type ComparisonValue<T> = Untagged<T | Flatten<T
|
|
33
|
+
export type ComparisonValue<T> = Untagged<T | Flatten<T>> | SQLWrapper;
|
|
36
34
|
export type ComparisonValueWithRegex<T> = T extends string ? ComparisonValue<T | RegExp> : T extends readonly string[] ? ComparisonValue<readonly (Flatten<T> | RegExp)[]> : (T | Flatten<T>);
|
|
37
35
|
export type ComparisonNotQuery<T = any> = {
|
|
38
36
|
$not: ComparisonQuery<T>;
|
package/orm/query.js
CHANGED
|
@@ -2,6 +2,5 @@ export const allLogicalQueryTypes = ['$and', '$or', '$nor'];
|
|
|
2
2
|
export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$text', '$geoDistance', '$geoShape'];
|
|
3
3
|
export const allSpecialQueryTypes = ['$textSpan'];
|
|
4
4
|
export const allQueryTypes = [...allLogicalQueryTypes, ...allComparisonQueryTypes, ...allSpecialQueryTypes];
|
|
5
|
-
export const allOrders = ['asc', 'desc'];
|
|
6
5
|
export const allOperators = ['and', 'or'];
|
|
7
6
|
export const allTextSpanQueryModes = ['best', 'most', 'cross'];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Paths, Record, TypedOmit } from '../types.js';
|
|
2
|
+
import type { UntaggedDeep } from '../types/tagged.js';
|
|
3
|
+
import type { SQL, SQLWrapper } from 'drizzle-orm';
|
|
4
|
+
import type { PartialDeep } from 'type-fest';
|
|
5
|
+
import type { Entity, EntityMetadata, EntityWithoutMetadata } from './entity.js';
|
|
6
|
+
type WithSql<T> = {
|
|
7
|
+
[P in keyof T]: T[P] extends Record ? WithSql<T[P]> : (T[P] | SQL);
|
|
8
|
+
};
|
|
9
|
+
export type OrderDirection = 'asc' | 'desc';
|
|
10
|
+
export type OrderTarget<T extends EntityWithoutMetadata> = Paths<UntaggedDeep<T>> | SQLWrapper;
|
|
11
|
+
export type Order<T extends EntityWithoutMetadata> = OrderTarget<T> | (OrderTarget<T> | [OrderTarget<T>, OrderDirection])[] | Partial<Record<Exclude<OrderTarget<T>, SQLWrapper>, OrderDirection>>;
|
|
12
|
+
export type OrderOptions<T extends EntityWithoutMetadata> = {
|
|
13
|
+
order?: Order<T>;
|
|
14
|
+
};
|
|
15
|
+
export type LoadOptions<T extends EntityWithoutMetadata> = OrderOptions<T> & {
|
|
16
|
+
offset?: number;
|
|
17
|
+
};
|
|
18
|
+
export type LoadManyOptions<T extends EntityWithoutMetadata> = LoadOptions<T> & {
|
|
19
|
+
limit?: number;
|
|
20
|
+
};
|
|
21
|
+
export type UpdateOptions<T extends EntityWithoutMetadata> = LoadOptions<T>;
|
|
22
|
+
export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>>;
|
|
23
|
+
export type NewEntity<T extends Entity | EntityWithoutMetadata> = T extends Entity ? WithSql<UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
24
|
+
id?: string;
|
|
25
|
+
metadata?: Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
26
|
+
}>> : WithSql<UntaggedDeep<TypedOmit<T, 'id'> & {
|
|
27
|
+
id?: string;
|
|
28
|
+
}>>;
|
|
29
|
+
export type EntityUpdate<T extends EntityWithoutMetadata> = T extends Entity ? WithSql<PartialDeep<UntaggedDeep<TypedOmit<T, 'metadata'>>>> & {
|
|
30
|
+
metadata?: EntityMetadataUpdate;
|
|
31
|
+
} : WithSql<PartialDeep<UntaggedDeep<T>>>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,10 +2,10 @@ import type { PgEnum } from 'drizzle-orm/pg-core';
|
|
|
2
2
|
import type { Enumeration, EnumerationValue, UnionToTuple } from '../../types.js';
|
|
3
3
|
import type { EntityType } from '../entity.js';
|
|
4
4
|
import type { PgTableFromType } from './types.js';
|
|
5
|
-
export declare class DatabaseSchema<
|
|
6
|
-
readonly name:
|
|
7
|
-
constructor(name:
|
|
8
|
-
getTable<T extends EntityType>(type: T): PgTableFromType<
|
|
5
|
+
export declare class DatabaseSchema<SchemaName extends string> {
|
|
6
|
+
readonly name: SchemaName;
|
|
7
|
+
constructor(name: SchemaName);
|
|
8
|
+
getTable<T extends EntityType>(type: T): PgTableFromType<T, SchemaName>;
|
|
9
9
|
getEnum<T extends Enumeration>(enumeration: T, name?: string): PgEnum<UnionToTuple<`${EnumerationValue<T>}`> extends [string, ...string[]] ? UnionToTuple<`${EnumerationValue<T>}`> : never>;
|
|
10
10
|
}
|
|
11
11
|
export declare function databaseSchema<Name extends string>(name: Name): DatabaseSchema<Name>;
|
|
@@ -8,7 +8,7 @@ type ConverterContext = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const getDrizzleTableFromType: typeof _getDrizzleTableFromType;
|
|
10
10
|
export declare function getColumnDefinitions(table: PgTableWithColumns<any>): ColumnDefinition[];
|
|
11
|
-
export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, schemaName?: S): PgTableFromType<
|
|
11
|
+
export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, schemaName?: S): PgTableFromType<T, S>;
|
|
12
12
|
export declare function registerEnum(enumeration: Enumeration, name: string): void;
|
|
13
13
|
export declare function getPgEnum(schema: string | PgSchema, enumeration: Enumeration, context?: ConverterContext): PgEnum<[string, ...string[]]>;
|
|
14
14
|
export {};
|
package/orm/server/index.d.ts
CHANGED
package/orm/server/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import type { EntityType } from '../entity.js';
|
|
3
2
|
import type { Query } from '../query.js';
|
|
4
3
|
import type { ColumnDefinition, PgTableFromType } from './types.js';
|
|
5
|
-
export declare function convertQuery(query: Query, table: PgTableFromType
|
|
4
|
+
export declare function convertQuery(query: Query, table: PgTableFromType, columnDefinitionsMap: Map<string, ColumnDefinition>): SQL;
|
|
@@ -14,8 +14,8 @@ export function convertQuery(query, table, columnDefinitionsMap) {
|
|
|
14
14
|
if (queryEntries.length == 0) {
|
|
15
15
|
return sqlTrue;
|
|
16
16
|
}
|
|
17
|
+
const conditions = [];
|
|
17
18
|
for (const [property, value] of queryEntries) {
|
|
18
|
-
const isPrimitiveValue = isPrimitive(value);
|
|
19
19
|
if (property == '$and') {
|
|
20
20
|
if (queryEntries.length > 1) {
|
|
21
21
|
throw new Error('only one logical operator per level allowed');
|
|
@@ -48,66 +48,71 @@ export function convertQuery(query, table, columnDefinitionsMap) {
|
|
|
48
48
|
}
|
|
49
49
|
const columnDef = assertDefinedPass(columnDefinitionsMap.get(property), `Could not map property ${property} to column.`);
|
|
50
50
|
const column = table[columnDef.name];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const queryValue = value.$in;
|
|
70
|
-
return inArray(column, queryValue);
|
|
71
|
-
}
|
|
72
|
-
if (hasOwnProperty(value, '$nin')) {
|
|
73
|
-
const queryValue = value.$nin;
|
|
74
|
-
return notInArray(column, queryValue);
|
|
75
|
-
}
|
|
76
|
-
if (hasOwnProperty(value, '$lt')) {
|
|
77
|
-
const queryValue = value.$lt;
|
|
78
|
-
return lt(column, queryValue);
|
|
79
|
-
}
|
|
80
|
-
if (hasOwnProperty(value, '$lte')) {
|
|
81
|
-
const queryValue = value.$lte;
|
|
82
|
-
return lte(column, queryValue);
|
|
83
|
-
}
|
|
84
|
-
if (hasOwnProperty(value, '$gt')) {
|
|
85
|
-
const queryValue = value.$gt;
|
|
86
|
-
return gt(column, queryValue);
|
|
87
|
-
}
|
|
88
|
-
if (hasOwnProperty(value, '$gte')) {
|
|
89
|
-
const queryValue = value.$gte;
|
|
90
|
-
return gte(column, queryValue);
|
|
91
|
-
}
|
|
92
|
-
if (hasOwnProperty(value, '$regex')) {
|
|
93
|
-
const queryValue = value.$regex;
|
|
94
|
-
const regexp = isString(queryValue)
|
|
95
|
-
? ({ value: queryValue })
|
|
96
|
-
: isRegExp(queryValue)
|
|
97
|
-
? ({ flags: queryValue.flags, value: queryValue.source })
|
|
98
|
-
: ({ flags: queryValue.flags, value: queryValue.pattern });
|
|
99
|
-
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
100
|
-
}
|
|
101
|
-
if (hasOwnProperty(value, '$text')) {
|
|
102
|
-
throw new NotSupportedError('$text is not supported.');
|
|
103
|
-
}
|
|
104
|
-
if (hasOwnProperty(value, '$geoShape')) {
|
|
105
|
-
throw new NotSupportedError('$geoShape is not supported.');
|
|
106
|
-
}
|
|
107
|
-
if (hasOwnProperty(value, '$geoDistance')) {
|
|
108
|
-
throw new NotSupportedError('$geoDistance is not supported.');
|
|
51
|
+
const condition = getCondition(property, value, column);
|
|
52
|
+
conditions.push(condition);
|
|
53
|
+
}
|
|
54
|
+
return and(...conditions);
|
|
55
|
+
}
|
|
56
|
+
function getCondition(property, value, column) {
|
|
57
|
+
const isPrimitiveValue = isPrimitive(value);
|
|
58
|
+
if (isPrimitiveValue || hasOwnProperty(value, '$eq')) {
|
|
59
|
+
const queryValue = isPrimitiveValue ? value : value.$eq;
|
|
60
|
+
if (queryValue === null) {
|
|
61
|
+
return isNull(column);
|
|
62
|
+
}
|
|
63
|
+
return eq(column, queryValue);
|
|
64
|
+
}
|
|
65
|
+
if (hasOwnProperty(value, '$neq')) {
|
|
66
|
+
const queryValue = value.$neq;
|
|
67
|
+
if (queryValue === null) {
|
|
68
|
+
return isNotNull(column);
|
|
109
69
|
}
|
|
110
|
-
|
|
70
|
+
return ne(column, queryValue);
|
|
71
|
+
}
|
|
72
|
+
if (hasOwnProperty(value, '$exists')) {
|
|
73
|
+
throw new NotSupportedError('$exists is not supported.');
|
|
74
|
+
}
|
|
75
|
+
if (hasOwnProperty(value, '$in')) {
|
|
76
|
+
const queryValue = value.$in;
|
|
77
|
+
return inArray(column, queryValue);
|
|
78
|
+
}
|
|
79
|
+
if (hasOwnProperty(value, '$nin')) {
|
|
80
|
+
const queryValue = value.$nin;
|
|
81
|
+
return notInArray(column, queryValue);
|
|
82
|
+
}
|
|
83
|
+
if (hasOwnProperty(value, '$lt')) {
|
|
84
|
+
const queryValue = value.$lt;
|
|
85
|
+
return lt(column, queryValue);
|
|
86
|
+
}
|
|
87
|
+
if (hasOwnProperty(value, '$lte')) {
|
|
88
|
+
const queryValue = value.$lte;
|
|
89
|
+
return lte(column, queryValue);
|
|
90
|
+
}
|
|
91
|
+
if (hasOwnProperty(value, '$gt')) {
|
|
92
|
+
const queryValue = value.$gt;
|
|
93
|
+
return gt(column, queryValue);
|
|
94
|
+
}
|
|
95
|
+
if (hasOwnProperty(value, '$gte')) {
|
|
96
|
+
const queryValue = value.$gte;
|
|
97
|
+
return gte(column, queryValue);
|
|
98
|
+
}
|
|
99
|
+
if (hasOwnProperty(value, '$regex')) {
|
|
100
|
+
const queryValue = value.$regex;
|
|
101
|
+
const regexp = isString(queryValue)
|
|
102
|
+
? ({ value: queryValue })
|
|
103
|
+
: isRegExp(queryValue)
|
|
104
|
+
? ({ flags: queryValue.flags, value: queryValue.source })
|
|
105
|
+
: ({ flags: queryValue.flags, value: queryValue.pattern });
|
|
106
|
+
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
107
|
+
}
|
|
108
|
+
if (hasOwnProperty(value, '$text')) {
|
|
109
|
+
throw new NotSupportedError('$text is not supported.');
|
|
110
|
+
}
|
|
111
|
+
if (hasOwnProperty(value, '$geoShape')) {
|
|
112
|
+
throw new NotSupportedError('$geoShape is not supported.');
|
|
113
|
+
}
|
|
114
|
+
if (hasOwnProperty(value, '$geoDistance')) {
|
|
115
|
+
throw new NotSupportedError('$geoDistance is not supported.');
|
|
111
116
|
}
|
|
112
|
-
throw new Error(
|
|
117
|
+
throw new Error(`Unsupported query type "${property}".`);
|
|
113
118
|
}
|