@tstdl/base 0.92.88 → 0.92.90
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/document-management/models/document-property-value.model.js +3 -2
- package/document-management/server/services/document-management.service.d.ts +3 -6
- package/document-management/server/services/document-management.service.js +12 -10
- package/eslint.config.js +2 -1
- package/orm/index.d.ts +1 -0
- package/orm/index.js +1 -0
- package/orm/server/index.d.ts +0 -1
- package/orm/server/index.js +0 -1
- package/orm/server/repository.d.ts +25 -26
- package/orm/server/repository.js +78 -94
- package/orm/{server/sqls.d.ts → sqls.d.ts} +4 -3
- package/orm/{server/sqls.js → sqls.js} +6 -0
- package/package.json +2 -2
- package/queue/postgres/queue.js +4 -3
|
@@ -7,11 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
+
import { eq } from 'drizzle-orm';
|
|
10
11
|
import { References } from '../../orm/decorators.js';
|
|
11
12
|
import { Entity } from '../../orm/entity.js';
|
|
13
|
+
import { numNonNulls } from '../../orm/sqls.js';
|
|
12
14
|
import { Check, NumericDate, Unique, Uuid } from '../../orm/types.js';
|
|
13
15
|
import { BooleanProperty, Integer, NumberProperty, StringProperty } from '../../schema/index.js';
|
|
14
|
-
import { sql } from 'drizzle-orm';
|
|
15
16
|
import { DocumentProperty } from './document-property.model.js';
|
|
16
17
|
import { DocumentRequestAssignmentTask } from './document-request-assignment-task.model.js';
|
|
17
18
|
import { DocumentRequestFile } from './document-request-file.model.js';
|
|
@@ -50,7 +51,7 @@ __decorate([
|
|
|
50
51
|
__metadata("design:type", Object)
|
|
51
52
|
], DocumentPropertyValueBase.prototype, "date", void 0);
|
|
52
53
|
DocumentPropertyValueBase = __decorate([
|
|
53
|
-
Check('only_one_value', (table) =>
|
|
54
|
+
Check('only_one_value', (table) => eq(numNonNulls(table.text, table.integer, table.decimal, table.boolean, table.date), 1))
|
|
54
55
|
], DocumentPropertyValueBase);
|
|
55
56
|
export { DocumentPropertyValueBase };
|
|
56
57
|
let DocumentPropertyValue = class DocumentPropertyValue extends DocumentPropertyValueBase {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequireExactlyOne, Stringified } from 'type-fest';
|
|
2
2
|
import type { CancellationSignal } from '../../../cancellation/token.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type AfterResolveContext, afterResolve } from '../../../injector/index.js';
|
|
4
4
|
import { Logger } from '../../../logger/logger.js';
|
|
5
5
|
import { ObjectStorage } from '../../../object-storage/index.js';
|
|
6
6
|
import type { Query } from '../../../orm/index.js';
|
|
@@ -8,9 +8,7 @@ import { type Transaction } from '../../../orm/server/index.js';
|
|
|
8
8
|
import { Queue } from '../../../queue/queue.js';
|
|
9
9
|
import type { OneOrMany, Record } from '../../../types.js';
|
|
10
10
|
import { type AddOrArchiveDocumentToOrFromCollectionParameters, type ApplyDocumentRequestsTemplateParameters, type ApproveDocumentRequestFileParameters, type AssignPropertyToTypeParameters, type CategoryAndTypesView, type CreateCollectionParameters, type CreateDocumentCategoryParameters, type CreateDocumentParameters, type CreateDocumentPropertyParameters, type CreateDocumentRequestFileParameters, type CreateDocumentRequestParameters, type CreateDocumentRequestTemplateParameters, type CreateDocumentRequestsTemplateParameters, type CreateDocumentTypeParameters, type DeleteDocumentRequestFileParameters, type DeleteDocumentRequestParameters, type DeleteDocumentRequestTemplateParameters, type DeleteDocumentRequestsTemplateParameters, Document, DocumentCategory, DocumentCollection, DocumentCollectionDocument, DocumentFile, type DocumentManagementData, DocumentProperty, DocumentPropertyDataType, DocumentPropertyValue, DocumentRequest, DocumentRequestAssignmentTask, DocumentRequestAssignmentTaskCollection, DocumentRequestAssignmentTaskPropertyValue, DocumentRequestCollection, DocumentRequestFile, DocumentRequestFilePropertyValue, DocumentRequestTemplate, DocumentRequestsTemplate, type DocumentRequestsTemplateData, DocumentType, DocumentTypeProperty, type LoadDataCollectionsMetadataParameters, type RejectDocumentRequestFileParameters, type RequestFilesStats, type SetDocumentPropertiesParameters, type UpdateDocumentParameters, type UpdateDocumentRequestFileParameters, type UpdateDocumentRequestParameters, type UpdateDocumentRequestTemplateParameters, type UpdateDocumentRequestsTemplateParameters } from '../../models/index.js';
|
|
11
|
-
import { DocumentManagementConfig } from '../module.js';
|
|
12
11
|
import { DocumentManagementAncillaryService } from './document-management-ancillary.service.js';
|
|
13
|
-
export type DocumentServiceArgument = DocumentManagementConfig;
|
|
14
12
|
type DocumentInformationExtractionPropertyResult = {
|
|
15
13
|
propertyId: string;
|
|
16
14
|
dataType: DocumentPropertyDataType;
|
|
@@ -34,12 +32,12 @@ type ExtractionJobData = RequireExactlyOne<{
|
|
|
34
32
|
type AssignmentJobData = RequireExactlyOne<{
|
|
35
33
|
requestAssignmentTaskId: string;
|
|
36
34
|
}>;
|
|
37
|
-
|
|
35
|
+
declare const DocumentManagementService_base: import("../../../types.js").Type<import("../../../orm/server/index.js").EntityRepository<DocumentCollection>>;
|
|
36
|
+
export declare class DocumentManagementService extends DocumentManagementService_base {
|
|
38
37
|
#private;
|
|
39
38
|
protected readonly ancillaryService: DocumentManagementAncillaryService;
|
|
40
39
|
protected readonly documentCategoryService: import("../../../orm/server/index.js").EntityRepository<DocumentCategory>;
|
|
41
40
|
protected readonly documentCollectionDocumentService: import("../../../orm/server/index.js").EntityRepository<DocumentCollectionDocument>;
|
|
42
|
-
protected readonly documentCollectionService: import("../../../orm/server/index.js").EntityRepository<DocumentCollection>;
|
|
43
41
|
protected readonly documentFileService: import("../../../orm/server/index.js").EntityRepository<DocumentFile>;
|
|
44
42
|
protected readonly documentPropertyService: import("../../../orm/server/index.js").EntityRepository<DocumentProperty>;
|
|
45
43
|
protected readonly documentPropertyValueService: import("../../../orm/server/index.js").EntityRepository<DocumentPropertyValue>;
|
|
@@ -59,7 +57,6 @@ export declare class DocumentManagementService implements AfterResolve<DocumentS
|
|
|
59
57
|
protected readonly extractionQueue: Queue<ExtractionJobData>;
|
|
60
58
|
protected readonly assignmentQueue: Queue<AssignmentJobData>;
|
|
61
59
|
protected readonly logger: Logger;
|
|
62
|
-
readonly [resolveArgumentType]: DocumentServiceArgument;
|
|
63
60
|
[afterResolve](_: unknown, { cancellationSignal }: AfterResolveContext<any>): void;
|
|
64
61
|
processQueues(cancellationSignal: CancellationSignal): void;
|
|
65
62
|
resolveNames<const T extends (DocumentCollection | string)[]>(...collectionsOrIds: T): Promise<Stringified<T>>;
|
|
@@ -63,11 +63,11 @@ import { AiService } from '../../../ai/index.js';
|
|
|
63
63
|
import { Enumerable } from '../../../enumerable/index.js';
|
|
64
64
|
import { BadRequestError } from '../../../errors/index.js';
|
|
65
65
|
import { TemporaryFile, getMimeType, getMimeTypeExtensions } from '../../../file/index.js';
|
|
66
|
-
import { Singleton, afterResolve, inject,
|
|
66
|
+
import { Singleton, afterResolve, inject, provide } from '../../../injector/index.js';
|
|
67
67
|
import { Logger } from '../../../logger/logger.js';
|
|
68
68
|
import { ObjectStorage } from '../../../object-storage/index.js';
|
|
69
|
-
import { getEntityMap } from '../../../orm/index.js';
|
|
70
|
-
import { DatabaseConfig, EntityRepositoryConfig,
|
|
69
|
+
import { TRANSACTION_TIMESTAMP, arrayAgg, coalesce, getEntityMap, jsonAgg, toJsonb } from '../../../orm/index.js';
|
|
70
|
+
import { DatabaseConfig, EntityRepositoryConfig, getRepository, injectRepository } from '../../../orm/server/index.js';
|
|
71
71
|
import { getPdfPageCount } from '../../../pdf/index.js';
|
|
72
72
|
import { Queue } from '../../../queue/queue.js';
|
|
73
73
|
import { array, boolean, enumeration, integer, nullable, number, object, string } from '../../../schema/index.js';
|
|
@@ -93,12 +93,11 @@ const defaultGenerationOptions = {
|
|
|
93
93
|
topP: 0.2
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
let DocumentManagementService = DocumentManagementService_1 = class DocumentManagementService {
|
|
96
|
+
let DocumentManagementService = DocumentManagementService_1 = class DocumentManagementService extends getRepository(DocumentCollection) {
|
|
97
97
|
#aiService = inject(AiService);
|
|
98
98
|
ancillaryService = inject(DocumentManagementAncillaryService);
|
|
99
99
|
documentCategoryService = injectRepository(DocumentCategory);
|
|
100
100
|
documentCollectionDocumentService = injectRepository(DocumentCollectionDocument);
|
|
101
|
-
documentCollectionService = injectRepository(DocumentCollection);
|
|
102
101
|
documentFileService = injectRepository(DocumentFile);
|
|
103
102
|
documentPropertyService = injectRepository(DocumentProperty);
|
|
104
103
|
documentPropertyValueService = injectRepository(DocumentPropertyValue);
|
|
@@ -114,11 +113,14 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
114
113
|
documentService = injectRepository(Document);
|
|
115
114
|
documentTypePropertyService = injectRepository(DocumentTypeProperty);
|
|
116
115
|
documentTypeService = injectRepository(DocumentType);
|
|
117
|
-
fileObjectStorage = inject(ObjectStorage,
|
|
116
|
+
fileObjectStorage = inject(ObjectStorage, inject(DocumentManagementConfig).fileObjectStorageModule);
|
|
118
117
|
extractionQueue = inject((Queue), { name: 'DocumentManagement:extraction', processTimeout: 15 * millisecondsPerMinute });
|
|
119
118
|
assignmentQueue = inject((Queue), { name: 'DocumentManagement:assignment', processTimeout: 15 * millisecondsPerMinute });
|
|
120
119
|
logger = inject(Logger, DocumentManagementService_1.name);
|
|
121
120
|
[afterResolve](_, { cancellationSignal }) {
|
|
121
|
+
if (this.isFork) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
122
124
|
this.processQueues(cancellationSignal);
|
|
123
125
|
}
|
|
124
126
|
processQueues(cancellationSignal) {
|
|
@@ -144,7 +146,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
144
146
|
if (loadIds.length == 0) {
|
|
145
147
|
return this.ancillaryService.resolveNames(collectionsOrIds);
|
|
146
148
|
}
|
|
147
|
-
const loadedCollections = await this.
|
|
149
|
+
const loadedCollections = await this.loadManyByQuery({ id: { $in: loadIds } });
|
|
148
150
|
const collections = collectionsOrIds.map((collectionOrId) => isString(collectionOrId)
|
|
149
151
|
? assertDefinedPass(loadedCollections.find((collection) => collection.id == collectionOrId), `Could not load collection "${collectionOrId}".`)
|
|
150
152
|
: collectionOrId);
|
|
@@ -156,9 +158,9 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
156
158
|
return fromEntries(entries);
|
|
157
159
|
}
|
|
158
160
|
async loadData(collectionIds, collectionsMetadata) {
|
|
159
|
-
return this.
|
|
161
|
+
return this.transaction(async (_, transaction) => {
|
|
160
162
|
const [collections, collectionDocuments, requestCollections, categories, types] = await Promise.all([
|
|
161
|
-
this.
|
|
163
|
+
this.withTransaction(transaction).loadMany(collectionIds),
|
|
162
164
|
this.documentCollectionDocumentService.withTransaction(transaction).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
163
165
|
this.documentRequestCollectionService.withTransaction(transaction).loadManyByQuery({ collectionId: { $in: collectionIds } }),
|
|
164
166
|
this.documentCategoryService.withTransaction(transaction).loadManyByQuery({}, { order: 'label' }),
|
|
@@ -240,7 +242,7 @@ let DocumentManagementService = DocumentManagementService_1 = class DocumentMana
|
|
|
240
242
|
return this.documentTypeService.insert(parameters);
|
|
241
243
|
}
|
|
242
244
|
async createCollection(parameters) {
|
|
243
|
-
return this.
|
|
245
|
+
return this.insert(parameters ?? {});
|
|
244
246
|
}
|
|
245
247
|
async collectionHasDocumentByFilter(collectionId, filter) {
|
|
246
248
|
const collectionDocuments = await this.documentCollectionDocumentService.loadManyByQuery({ collectionId });
|
package/eslint.config.js
CHANGED
package/orm/index.d.ts
CHANGED
package/orm/index.js
CHANGED
package/orm/server/index.d.ts
CHANGED
package/orm/server/index.js
CHANGED
|
@@ -14,7 +14,8 @@ export declare const repositoryType: unique symbol;
|
|
|
14
14
|
export declare class EntityRepositoryConfig {
|
|
15
15
|
schema: string;
|
|
16
16
|
}
|
|
17
|
-
export type TransactionHandler<T extends
|
|
17
|
+
export type TransactionHandler<T extends EntityRepository<any>, R> = (repository: T, transaction: Transaction) => Promise<R>;
|
|
18
|
+
type InferSelect<T extends Entity | EntityWithoutMetadata = Entity | EntityWithoutMetadata> = PgTableFromType<EntityType<T>>['$inferSelect'];
|
|
18
19
|
export declare class EntityRepository<T extends Entity | EntityWithoutMetadata = EntityWithoutMetadata> implements Resolvable<EntityType<T>> {
|
|
19
20
|
#private;
|
|
20
21
|
readonly type: EntityType<T>;
|
|
@@ -23,15 +24,14 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
|
|
|
23
24
|
readonly isInTransaction: boolean;
|
|
24
25
|
readonly hasMetadata: boolean;
|
|
25
26
|
get table(): PgTableFromType<EntityType<T>>;
|
|
27
|
+
protected get isFork(): boolean;
|
|
26
28
|
readonly [resolveArgumentType]: EntityType<T>;
|
|
27
|
-
readonly _anyInferSelect: PgTableFromType<EntityType<Entity>>['$inferSelect'];
|
|
28
|
-
readonly _inferSelect: PgTableFromType<EntityType<T>>['$inferSelect'];
|
|
29
29
|
constructor();
|
|
30
|
-
withOptionalTransaction(transaction: Transaction | undefined):
|
|
31
|
-
withTransaction(transaction: Transaction):
|
|
30
|
+
withOptionalTransaction(transaction: Transaction | undefined): this;
|
|
31
|
+
withTransaction(transaction: Transaction): this;
|
|
32
32
|
startTransaction(config?: TransactionConfig): Promise<Transaction>;
|
|
33
|
-
useTransaction<R>(transaction: Transaction | undefined, handler: TransactionHandler<
|
|
34
|
-
transaction<R>(handler: TransactionHandler<
|
|
33
|
+
useTransaction<R>(transaction: Transaction | undefined, handler: TransactionHandler<this, R>): Promise<R>;
|
|
34
|
+
transaction<R>(handler: TransactionHandler<this, R>, config?: TransactionConfig): Promise<R>;
|
|
35
35
|
load(id: string): Promise<T>;
|
|
36
36
|
tryLoad(id: string): Promise<T | undefined>;
|
|
37
37
|
loadByQuery(query: Query<T>, options?: LoadOptions<T>): Promise<T>;
|
|
@@ -77,15 +77,15 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
|
|
|
77
77
|
hardDeleteManyByQuery(query: Query<T>): Promise<T[]>;
|
|
78
78
|
$getColumn(pathOrColumn: Paths<UntaggedDeep<T>> | ColumnDefinition): PgColumn;
|
|
79
79
|
$convertOrderBy(orderBy: Order<T>): SQL<unknown>[];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
convertQuery(query: Query<T>): SQL;
|
|
81
|
+
mapManyToEntity(columns: InferSelect[]): Promise<T[]>;
|
|
82
|
+
mapToEntity(columns: InferSelect): Promise<T>;
|
|
83
|
+
mapManyToColumns(objects: (DeepPartial<T> | NewEntity<T>)[]): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
84
|
+
mapToColumns(obj: DeepPartial<T> | NewEntity<T>): Promise<PgInsertValue<PgTableFromType>>;
|
|
85
|
+
mapManyToInsertColumns(objects: (DeepPartial<T> | NewEntity<T>)[]): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
86
|
+
mapToInsertColumns(obj: DeepPartial<T> | NewEntity<T>): Promise<PgInsertValue<PgTableFromType>>;
|
|
87
|
+
mapUpdate(update: EntityUpdate<T>): Promise<PgUpdateSetSource<PgTableFromType>>;
|
|
88
|
+
getIdLimitQuery(query: Query<T>): Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
89
89
|
id: PgColumn<{
|
|
90
90
|
name: string;
|
|
91
91
|
tableName: string;
|
|
@@ -124,15 +124,15 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
|
|
|
124
124
|
generated: undefined;
|
|
125
125
|
}, {}, {}>;
|
|
126
126
|
}>, "where" | "limit">;
|
|
127
|
-
|
|
128
|
-
protected
|
|
129
|
-
protected
|
|
130
|
-
protected
|
|
131
|
-
protected
|
|
132
|
-
protected
|
|
133
|
-
protected
|
|
134
|
-
protected
|
|
135
|
-
protected
|
|
127
|
+
protected getAttributesUpdate(attributes: SQL | EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
128
|
+
protected _mapManyToEntity(columns: InferSelect[], transformContext: TransformContext): Promise<T[]>;
|
|
129
|
+
protected _mapToEntity(columns: InferSelect, transformContext: TransformContext): Promise<T>;
|
|
130
|
+
protected _mapManyToColumns(objects: (DeepPartial<T> | NewEntity<T>)[], transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
131
|
+
protected _mapToColumns(obj: DeepPartial<T> | NewEntity<T>, transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>>;
|
|
132
|
+
protected _mapManyToInsertColumns(objects: (DeepPartial<T> | NewEntity<T>)[], transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>[]>;
|
|
133
|
+
protected _mapToInsertColumns(obj: DeepPartial<T> | NewEntity<T>, transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType>>;
|
|
134
|
+
protected _mapUpdate(update: EntityUpdate<T>, transformContext: TransformContext): Promise<PgUpdateSetSource<PgTableFromType>>;
|
|
135
|
+
protected _getMetadataUpdate(update?: EntityUpdate<T>): PgUpdateSetSource<PgTableFromType<EntityType<Entity>>> | undefined;
|
|
136
136
|
protected getIdLimitSelect(query: Query<T>): Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
137
137
|
id: PgColumn<{
|
|
138
138
|
name: string;
|
|
@@ -172,7 +172,6 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
|
|
|
172
172
|
generated: undefined;
|
|
173
173
|
}, {}, {}>;
|
|
174
174
|
}>, "where" | "limit">;
|
|
175
|
-
protected getAttributesUpdate(attributes: SQL | EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
176
175
|
protected getTransformContext(): Promise<TransformContext>;
|
|
177
176
|
}
|
|
178
177
|
export declare function injectRepository<T extends Entity | EntityWithoutMetadata>(type: EntityType<T>): EntityRepository<T>;
|
package/orm/server/repository.js
CHANGED
|
@@ -25,10 +25,10 @@ import { typeExtends } from '../../utils/index.js';
|
|
|
25
25
|
import { fromDeepObjectEntries, fromEntries, objectEntries } from '../../utils/object/object.js';
|
|
26
26
|
import { assertDefinedPass, isArray, isDefined, isString, isUndefined } from '../../utils/type-guards.js';
|
|
27
27
|
import { Entity } from '../entity.js';
|
|
28
|
+
import { TRANSACTION_TIMESTAMP } from '../sqls.js';
|
|
28
29
|
import { Database } from './database.js';
|
|
29
30
|
import { getColumnDefinitions, getDrizzleTableFromType } from './drizzle/schema-converter.js';
|
|
30
31
|
import { convertQuery } from './query-converter.js';
|
|
31
|
-
import { TRANSACTION_TIMESTAMP } from './sqls.js';
|
|
32
32
|
import { ENCRYPTION_SECRET } from './tokens.js';
|
|
33
33
|
import { DrizzleTransaction } from './transaction.js';
|
|
34
34
|
export const repositoryType = Symbol('repositoryType');
|
|
@@ -38,11 +38,11 @@ export class EntityRepositoryConfig {
|
|
|
38
38
|
const entityTypeToken = Symbol('EntityType');
|
|
39
39
|
const { getCurrentEntityRepositoryContext, runInEntityRepositoryContext, isInEntityRepositoryContext } = createContextProvider('EntityRepository');
|
|
40
40
|
let EntityRepository = class EntityRepository {
|
|
41
|
+
#context = getCurrentEntityRepositoryContext() ?? {};
|
|
41
42
|
#injector = inject(Injector);
|
|
42
43
|
#repositoryConstructor;
|
|
43
44
|
#withTransactionCache = new WeakMap();
|
|
44
|
-
#encryptionSecret = isInEntityRepositoryContext() ?
|
|
45
|
-
#context = getCurrentEntityRepositoryContext() ?? {};
|
|
45
|
+
#encryptionSecret = isInEntityRepositoryContext() ? this.#context.encryptionSecret : inject(ENCRYPTION_SECRET, undefined, { optional: true });
|
|
46
46
|
#transformContext = this.#context.transformContext;
|
|
47
47
|
type = this.#context.type ?? injectArgument(this, { optional: true }) ?? assertDefinedPass(this.constructor[entityTypeToken], 'Missing entity type.');
|
|
48
48
|
typeName = this.type.entityName ?? this.type.name;
|
|
@@ -56,6 +56,9 @@ let EntityRepository = class EntityRepository {
|
|
|
56
56
|
get table() {
|
|
57
57
|
return this.#table;
|
|
58
58
|
}
|
|
59
|
+
get isFork() {
|
|
60
|
+
return this.isInTransaction;
|
|
61
|
+
}
|
|
59
62
|
constructor() {
|
|
60
63
|
this.#repositoryConstructor = new.target;
|
|
61
64
|
}
|
|
@@ -115,7 +118,7 @@ let EntityRepository = class EntityRepository {
|
|
|
115
118
|
return entity;
|
|
116
119
|
}
|
|
117
120
|
async tryLoadByQuery(query, options) {
|
|
118
|
-
const sqlQuery = this
|
|
121
|
+
const sqlQuery = this.convertQuery(query);
|
|
119
122
|
let dbQuery = this.session.select()
|
|
120
123
|
.from(this.#table)
|
|
121
124
|
.where(sqlQuery)
|
|
@@ -128,8 +131,7 @@ let EntityRepository = class EntityRepository {
|
|
|
128
131
|
if (isUndefined(row)) {
|
|
129
132
|
return undefined;
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
return this.mapToEntity(row, transformContext);
|
|
134
|
+
return this.mapToEntity(row);
|
|
133
135
|
}
|
|
134
136
|
async loadMany(ids, options) {
|
|
135
137
|
return this.loadManyByQuery(inArray(this.#table.id, ids), options);
|
|
@@ -139,7 +141,7 @@ let EntityRepository = class EntityRepository {
|
|
|
139
141
|
yield* entities;
|
|
140
142
|
}
|
|
141
143
|
async loadManyByQuery(query, options) {
|
|
142
|
-
const sqlQuery = this
|
|
144
|
+
const sqlQuery = this.convertQuery(query);
|
|
143
145
|
let dbQuery = this.session.select()
|
|
144
146
|
.from(this.#table)
|
|
145
147
|
.where(sqlQuery)
|
|
@@ -151,8 +153,7 @@ let EntityRepository = class EntityRepository {
|
|
|
151
153
|
dbQuery = dbQuery.orderBy(...this.$convertOrderBy(options.order));
|
|
152
154
|
}
|
|
153
155
|
const rows = await dbQuery;
|
|
154
|
-
|
|
155
|
-
return this.mapManyToEntity(rows, transformContext);
|
|
156
|
+
return this.mapManyToEntity(rows);
|
|
156
157
|
}
|
|
157
158
|
async *loadManyByQueryCursor(query, options) {
|
|
158
159
|
const entities = await this.loadManyByQuery(query, options);
|
|
@@ -173,7 +174,7 @@ let EntityRepository = class EntityRepository {
|
|
|
173
174
|
return assertDefinedPass(result).count;
|
|
174
175
|
}
|
|
175
176
|
async countByQuery(query) {
|
|
176
|
-
const sqlQuery = this
|
|
177
|
+
const sqlQuery = this.convertQuery(query);
|
|
177
178
|
const dbQuery = this.session
|
|
178
179
|
.select({ count: count() })
|
|
179
180
|
.from(this.#table)
|
|
@@ -185,7 +186,7 @@ let EntityRepository = class EntityRepository {
|
|
|
185
186
|
return this.hasByQuery(eq(this.#table.id, id));
|
|
186
187
|
}
|
|
187
188
|
async hasByQuery(query) {
|
|
188
|
-
const sqlQuery = this
|
|
189
|
+
const sqlQuery = this.convertQuery(query);
|
|
189
190
|
const dbQuery = this.session
|
|
190
191
|
.select({ exists: sql `SELECT EXISTS(SELECT 1 FROM ${this.#table} WHERE ${sqlQuery})` })
|
|
191
192
|
.from(this.#table);
|
|
@@ -204,8 +205,7 @@ let EntityRepository = class EntityRepository {
|
|
|
204
205
|
* @returns entity if inserted, undefined on conflict
|
|
205
206
|
*/
|
|
206
207
|
async tryInsert(entity) {
|
|
207
|
-
const
|
|
208
|
-
const columns = await this.mapToInsertColumns(entity, transformContext);
|
|
208
|
+
const columns = await this.mapToInsertColumns(entity);
|
|
209
209
|
const [row] = await this.session
|
|
210
210
|
.insert(this.#table)
|
|
211
211
|
.values(columns)
|
|
@@ -214,28 +214,25 @@ let EntityRepository = class EntityRepository {
|
|
|
214
214
|
if (isUndefined(row)) {
|
|
215
215
|
return undefined;
|
|
216
216
|
}
|
|
217
|
-
return this.mapToEntity(row
|
|
217
|
+
return this.mapToEntity(row);
|
|
218
218
|
}
|
|
219
219
|
async insert(entity) {
|
|
220
|
-
const
|
|
221
|
-
const columns = await this.mapToInsertColumns(entity, transformContext);
|
|
220
|
+
const columns = await this.mapToInsertColumns(entity);
|
|
222
221
|
const [row] = await this.session
|
|
223
222
|
.insert(this.#table)
|
|
224
223
|
.values(columns)
|
|
225
224
|
.returning();
|
|
226
|
-
return this.mapToEntity(row
|
|
225
|
+
return this.mapToEntity(row);
|
|
227
226
|
}
|
|
228
227
|
async insertMany(entities) {
|
|
229
|
-
const
|
|
230
|
-
const columns = await this.mapManyToInsertColumns(entities, transformContext);
|
|
228
|
+
const columns = await this.mapManyToInsertColumns(entities);
|
|
231
229
|
const rows = await this.session.insert(this.#table).values(columns).returning();
|
|
232
|
-
return this.mapManyToEntity(rows
|
|
230
|
+
return this.mapManyToEntity(rows);
|
|
233
231
|
}
|
|
234
232
|
async upsert(target, entity, update) {
|
|
235
|
-
const transformContext = await this.getTransformContext();
|
|
236
233
|
const targetColumns = toArray(target).map((path) => this.$getColumn(path));
|
|
237
|
-
const columns = await this.mapToInsertColumns(entity
|
|
238
|
-
const mappedUpdate = await this.mapUpdate(update ?? entity
|
|
234
|
+
const columns = await this.mapToInsertColumns(entity);
|
|
235
|
+
const mappedUpdate = await this.mapUpdate(update ?? entity);
|
|
239
236
|
const [row] = await this.session
|
|
240
237
|
.insert(this.#table)
|
|
241
238
|
.values(columns)
|
|
@@ -244,17 +241,16 @@ let EntityRepository = class EntityRepository {
|
|
|
244
241
|
set: mappedUpdate
|
|
245
242
|
})
|
|
246
243
|
.returning();
|
|
247
|
-
return this.mapToEntity(row
|
|
244
|
+
return this.mapToEntity(row);
|
|
248
245
|
}
|
|
249
246
|
async upsertMany(target, entities, update) {
|
|
250
|
-
const transformContext = await this.getTransformContext();
|
|
251
247
|
const targetColumns = toArray(target).map((path) => this.$getColumn(path));
|
|
252
|
-
const columns = await this.mapManyToInsertColumns(entities
|
|
248
|
+
const columns = await this.mapManyToInsertColumns(entities);
|
|
253
249
|
const mappedUpdate = isDefined(update)
|
|
254
|
-
? await this.mapUpdate(update
|
|
250
|
+
? await this.mapUpdate(update)
|
|
255
251
|
: {
|
|
256
252
|
...fromEntries(this.#columnDefinitions.map((column) => [column.name, sql `excluded.${sql.identifier(this.$getColumn(column).name)}`])),
|
|
257
|
-
...this.
|
|
253
|
+
...this._getMetadataUpdate(update)
|
|
258
254
|
};
|
|
259
255
|
const rows = await this.session
|
|
260
256
|
.insert(this.#table)
|
|
@@ -264,7 +260,7 @@ let EntityRepository = class EntityRepository {
|
|
|
264
260
|
set: mappedUpdate
|
|
265
261
|
})
|
|
266
262
|
.returning();
|
|
267
|
-
return this.mapManyToEntity(rows
|
|
263
|
+
return this.mapManyToEntity(rows);
|
|
268
264
|
}
|
|
269
265
|
async update(id, update) {
|
|
270
266
|
const entity = await this.tryUpdate(id, update);
|
|
@@ -274,8 +270,7 @@ let EntityRepository = class EntityRepository {
|
|
|
274
270
|
return entity;
|
|
275
271
|
}
|
|
276
272
|
async tryUpdate(id, update) {
|
|
277
|
-
const
|
|
278
|
-
const mappedUpdate = await this.mapUpdate(update, transformContext);
|
|
273
|
+
const mappedUpdate = await this.mapUpdate(update);
|
|
279
274
|
const [row] = await this.session
|
|
280
275
|
.update(this.#table)
|
|
281
276
|
.set(mappedUpdate)
|
|
@@ -284,7 +279,7 @@ let EntityRepository = class EntityRepository {
|
|
|
284
279
|
if (isUndefined(row)) {
|
|
285
280
|
return undefined;
|
|
286
281
|
}
|
|
287
|
-
return this.mapToEntity(row
|
|
282
|
+
return this.mapToEntity(row);
|
|
288
283
|
}
|
|
289
284
|
async updateByQuery(query, update) {
|
|
290
285
|
const entity = await this.tryUpdateByQuery(query, update);
|
|
@@ -294,8 +289,7 @@ let EntityRepository = class EntityRepository {
|
|
|
294
289
|
return entity;
|
|
295
290
|
}
|
|
296
291
|
async tryUpdateByQuery(query, update) {
|
|
297
|
-
const
|
|
298
|
-
const mappedUpdate = await this.mapUpdate(update, transformContext);
|
|
292
|
+
const mappedUpdate = await this.mapUpdate(update);
|
|
299
293
|
const idQuery = this.getIdLimitSelect(query);
|
|
300
294
|
const [row] = await this.session
|
|
301
295
|
.update(this.#table)
|
|
@@ -305,21 +299,20 @@ let EntityRepository = class EntityRepository {
|
|
|
305
299
|
if (isUndefined(row)) {
|
|
306
300
|
return undefined;
|
|
307
301
|
}
|
|
308
|
-
return this.mapToEntity(row
|
|
302
|
+
return this.mapToEntity(row);
|
|
309
303
|
}
|
|
310
304
|
async updateMany(ids, update) {
|
|
311
305
|
return this.updateManyByQuery(inArray(this.#table.id, ids), update);
|
|
312
306
|
}
|
|
313
307
|
async updateManyByQuery(query, update) {
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
const mappedUpdate = await this.mapUpdate(update, transformContext);
|
|
308
|
+
const sqlQuery = this.convertQuery(query);
|
|
309
|
+
const mappedUpdate = await this.mapUpdate(update);
|
|
317
310
|
const rows = await this.session
|
|
318
311
|
.update(this.#table)
|
|
319
312
|
.set(mappedUpdate)
|
|
320
313
|
.where(sqlQuery)
|
|
321
314
|
.returning();
|
|
322
|
-
return this.mapManyToEntity(rows
|
|
315
|
+
return this.mapManyToEntity(rows);
|
|
323
316
|
}
|
|
324
317
|
async delete(id, metadataUpdate) {
|
|
325
318
|
const entity = await this.tryDelete(id, metadataUpdate);
|
|
@@ -343,8 +336,7 @@ let EntityRepository = class EntityRepository {
|
|
|
343
336
|
if (isUndefined(row)) {
|
|
344
337
|
return undefined;
|
|
345
338
|
}
|
|
346
|
-
|
|
347
|
-
return this.mapToEntity(row, transformContext);
|
|
339
|
+
return this.mapToEntity(row);
|
|
348
340
|
}
|
|
349
341
|
async deleteByQuery(query, metadataUpdate) {
|
|
350
342
|
const entity = await this.tryDeleteByQuery(query, metadataUpdate);
|
|
@@ -369,8 +361,7 @@ let EntityRepository = class EntityRepository {
|
|
|
369
361
|
if (isUndefined(row)) {
|
|
370
362
|
return undefined;
|
|
371
363
|
}
|
|
372
|
-
|
|
373
|
-
return this.mapToEntity(row, transformContext);
|
|
364
|
+
return this.mapToEntity(row);
|
|
374
365
|
}
|
|
375
366
|
async deleteMany(ids, metadataUpdate) {
|
|
376
367
|
return this.deleteManyByQuery(inArray(this.#table.id, ids), metadataUpdate);
|
|
@@ -379,7 +370,7 @@ let EntityRepository = class EntityRepository {
|
|
|
379
370
|
if (!this.hasMetadata) {
|
|
380
371
|
return this.hardDeleteManyByQuery(query);
|
|
381
372
|
}
|
|
382
|
-
const sqlQuery = this
|
|
373
|
+
const sqlQuery = this.convertQuery(query);
|
|
383
374
|
const rows = await this.session
|
|
384
375
|
.update(this.#tableWithMetadata)
|
|
385
376
|
.set({
|
|
@@ -388,8 +379,7 @@ let EntityRepository = class EntityRepository {
|
|
|
388
379
|
})
|
|
389
380
|
.where(sqlQuery)
|
|
390
381
|
.returning();
|
|
391
|
-
|
|
392
|
-
return this.mapManyToEntity(rows, transformContext);
|
|
382
|
+
return this.mapManyToEntity(rows);
|
|
393
383
|
}
|
|
394
384
|
async hardDelete(id) {
|
|
395
385
|
const result = await this.tryHardDelete(id);
|
|
@@ -406,8 +396,7 @@ let EntityRepository = class EntityRepository {
|
|
|
406
396
|
if (isUndefined(row)) {
|
|
407
397
|
return undefined;
|
|
408
398
|
}
|
|
409
|
-
|
|
410
|
-
return this.mapToEntity(row, transformContext);
|
|
399
|
+
return this.mapToEntity(row);
|
|
411
400
|
}
|
|
412
401
|
async hardDeleteByQuery(query) {
|
|
413
402
|
const result = await this.tryHardDeleteByQuery(query);
|
|
@@ -425,20 +414,18 @@ let EntityRepository = class EntityRepository {
|
|
|
425
414
|
if (isUndefined(row)) {
|
|
426
415
|
return undefined;
|
|
427
416
|
}
|
|
428
|
-
|
|
429
|
-
return this.mapToEntity(row, transformContext);
|
|
417
|
+
return this.mapToEntity(row);
|
|
430
418
|
}
|
|
431
419
|
async hardDeleteMany(ids) {
|
|
432
420
|
return this.hardDeleteManyByQuery(inArray(this.#table.id, ids));
|
|
433
421
|
}
|
|
434
422
|
async hardDeleteManyByQuery(query) {
|
|
435
|
-
const sqlQuery = this
|
|
423
|
+
const sqlQuery = this.convertQuery(query);
|
|
436
424
|
const rows = await this.session
|
|
437
425
|
.delete(this.#table)
|
|
438
426
|
.where(sqlQuery)
|
|
439
427
|
.returning();
|
|
440
|
-
|
|
441
|
-
return this.mapManyToEntity(rows, transformContext);
|
|
428
|
+
return this.mapManyToEntity(rows);
|
|
442
429
|
}
|
|
443
430
|
$getColumn(pathOrColumn) {
|
|
444
431
|
if (isString(pathOrColumn)) {
|
|
@@ -463,47 +450,53 @@ let EntityRepository = class EntityRepository {
|
|
|
463
450
|
return direction == 'asc' ? asc(column) : desc(column);
|
|
464
451
|
});
|
|
465
452
|
}
|
|
466
|
-
|
|
453
|
+
convertQuery(query) {
|
|
467
454
|
return convertQuery(query, this.#table, this.#columnDefinitionsMap);
|
|
468
455
|
}
|
|
469
|
-
async
|
|
456
|
+
async mapManyToEntity(columns) {
|
|
470
457
|
const transformContext = await this.getTransformContext();
|
|
471
|
-
return this.
|
|
458
|
+
return this._mapManyToEntity(columns, transformContext);
|
|
472
459
|
}
|
|
473
|
-
async
|
|
460
|
+
async mapToEntity(columns) {
|
|
474
461
|
const transformContext = await this.getTransformContext();
|
|
475
|
-
return this.
|
|
462
|
+
return this._mapToEntity(columns, transformContext);
|
|
476
463
|
}
|
|
477
|
-
async
|
|
464
|
+
async mapManyToColumns(objects) {
|
|
478
465
|
const transformContext = await this.getTransformContext();
|
|
479
|
-
return this.
|
|
466
|
+
return this._mapManyToColumns(objects, transformContext);
|
|
480
467
|
}
|
|
481
|
-
async
|
|
468
|
+
async mapToColumns(obj) {
|
|
482
469
|
const transformContext = await this.getTransformContext();
|
|
483
|
-
return this.
|
|
470
|
+
return this._mapToColumns(obj, transformContext);
|
|
484
471
|
}
|
|
485
|
-
async
|
|
472
|
+
async mapManyToInsertColumns(objects) {
|
|
486
473
|
const transformContext = await this.getTransformContext();
|
|
487
|
-
return this.
|
|
474
|
+
return this._mapManyToInsertColumns(objects, transformContext);
|
|
488
475
|
}
|
|
489
|
-
async
|
|
476
|
+
async mapToInsertColumns(obj) {
|
|
490
477
|
const transformContext = await this.getTransformContext();
|
|
491
|
-
return this.
|
|
478
|
+
return this._mapToInsertColumns(obj, transformContext);
|
|
492
479
|
}
|
|
493
|
-
async
|
|
480
|
+
async mapUpdate(update) {
|
|
494
481
|
const transformContext = await this.getTransformContext();
|
|
495
|
-
return this.
|
|
482
|
+
return this._mapUpdate(update, transformContext);
|
|
496
483
|
}
|
|
497
|
-
|
|
484
|
+
getIdLimitQuery(query) {
|
|
498
485
|
return this.getIdLimitSelect(query);
|
|
499
486
|
}
|
|
500
|
-
|
|
501
|
-
|
|
487
|
+
getAttributesUpdate(attributes) {
|
|
488
|
+
if (isUndefined(attributes)) {
|
|
489
|
+
return undefined;
|
|
490
|
+
}
|
|
491
|
+
if (attributes instanceof SQL) {
|
|
492
|
+
return attributes;
|
|
493
|
+
}
|
|
494
|
+
return sql `${this.#tableWithMetadata.attributes} || ${JSON.stringify(attributes)}::jsonb`;
|
|
502
495
|
}
|
|
503
|
-
async
|
|
504
|
-
return toArrayAsync(mapAsync(columns, async (column) => this.
|
|
496
|
+
async _mapManyToEntity(columns, transformContext) {
|
|
497
|
+
return toArrayAsync(mapAsync(columns, async (column) => this._mapToEntity(column, transformContext)));
|
|
505
498
|
}
|
|
506
|
-
async
|
|
499
|
+
async _mapToEntity(columns, transformContext) {
|
|
507
500
|
const entries = [];
|
|
508
501
|
for (const def of this.#columnDefinitions) {
|
|
509
502
|
const rawValue = columns[def.name];
|
|
@@ -513,10 +506,10 @@ let EntityRepository = class EntityRepository {
|
|
|
513
506
|
const obj = fromDeepObjectEntries(entries);
|
|
514
507
|
return Schema.parse(this.type, obj);
|
|
515
508
|
}
|
|
516
|
-
async
|
|
517
|
-
return toArrayAsync(mapAsync(objects, async (obj) => this.
|
|
509
|
+
async _mapManyToColumns(objects, transformContext) {
|
|
510
|
+
return toArrayAsync(mapAsync(objects, async (obj) => this._mapToColumns(obj, transformContext)));
|
|
518
511
|
}
|
|
519
|
-
async
|
|
512
|
+
async _mapToColumns(obj, transformContext) {
|
|
520
513
|
const columns = {};
|
|
521
514
|
for (const def of this.#columnDefinitions) {
|
|
522
515
|
const rawValue = def.dereferenceObjectPath(obj);
|
|
@@ -524,11 +517,11 @@ let EntityRepository = class EntityRepository {
|
|
|
524
517
|
}
|
|
525
518
|
return columns;
|
|
526
519
|
}
|
|
527
|
-
async
|
|
528
|
-
return toArrayAsync(mapAsync(objects, async (obj) => this.
|
|
520
|
+
async _mapManyToInsertColumns(objects, transformContext) {
|
|
521
|
+
return toArrayAsync(mapAsync(objects, async (obj) => this._mapToInsertColumns(obj, transformContext)));
|
|
529
522
|
}
|
|
530
|
-
async
|
|
531
|
-
const mapped = await this.
|
|
523
|
+
async _mapToInsertColumns(obj, transformContext) {
|
|
524
|
+
const mapped = await this._mapToColumns(obj, transformContext);
|
|
532
525
|
return {
|
|
533
526
|
...mapped,
|
|
534
527
|
...(this.hasMetadata
|
|
@@ -540,7 +533,7 @@ let EntityRepository = class EntityRepository {
|
|
|
540
533
|
: undefined)
|
|
541
534
|
};
|
|
542
535
|
}
|
|
543
|
-
async
|
|
536
|
+
async _mapUpdate(update, transformContext) {
|
|
544
537
|
const mappedUpdate = {};
|
|
545
538
|
for (const column of this.#columnDefinitions) {
|
|
546
539
|
const value = column.dereferenceObjectPath(update);
|
|
@@ -551,10 +544,10 @@ let EntityRepository = class EntityRepository {
|
|
|
551
544
|
}
|
|
552
545
|
return {
|
|
553
546
|
...mappedUpdate,
|
|
554
|
-
...this.
|
|
547
|
+
...this._getMetadataUpdate(update)
|
|
555
548
|
};
|
|
556
549
|
}
|
|
557
|
-
|
|
550
|
+
_getMetadataUpdate(update) {
|
|
558
551
|
return this.hasMetadata
|
|
559
552
|
? {
|
|
560
553
|
attributes: this.getAttributesUpdate(update?.metadata?.attributes),
|
|
@@ -564,21 +557,12 @@ let EntityRepository = class EntityRepository {
|
|
|
564
557
|
: undefined;
|
|
565
558
|
}
|
|
566
559
|
getIdLimitSelect(query) {
|
|
567
|
-
const sqlQuery = this
|
|
560
|
+
const sqlQuery = this.convertQuery(query);
|
|
568
561
|
return this.session.select({ id: this.#table.id })
|
|
569
562
|
.from(this.#table)
|
|
570
563
|
.where(sqlQuery)
|
|
571
564
|
.limit(1);
|
|
572
565
|
}
|
|
573
|
-
getAttributesUpdate(attributes) {
|
|
574
|
-
if (isUndefined(attributes)) {
|
|
575
|
-
return undefined;
|
|
576
|
-
}
|
|
577
|
-
if (attributes instanceof SQL) {
|
|
578
|
-
return attributes;
|
|
579
|
-
}
|
|
580
|
-
return sql `${this.#tableWithMetadata.attributes} || ${JSON.stringify(attributes)}::jsonb`;
|
|
581
|
-
}
|
|
582
566
|
async getTransformContext() {
|
|
583
567
|
if (isUndefined(this.#transformContext)) {
|
|
584
568
|
if (isUndefined(this.#encryptionSecret)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Column, type SQL } from 'drizzle-orm';
|
|
2
2
|
import type { GetSelectTableSelection, SelectResultField, TableLike } from 'drizzle-orm/query-builders/select.types';
|
|
3
|
-
import type { Uuid } from '
|
|
3
|
+
import type { Uuid } from './types.js';
|
|
4
4
|
export declare const TRANSACTION_TIMESTAMP: SQL<Date>;
|
|
5
5
|
export declare const RANDOM_UUID: SQL<Uuid>;
|
|
6
|
-
type IntervalUnit = 'millennium' | 'millenniums' | 'millennia' | 'century' | 'centuries' | 'decade' | 'decades' | 'year' | 'years' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds' | 'microsecond' | 'microseconds';
|
|
6
|
+
export type IntervalUnit = 'millennium' | 'millenniums' | 'millennia' | 'century' | 'centuries' | 'decade' | 'decades' | 'year' | 'years' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds' | 'microsecond' | 'microseconds';
|
|
7
7
|
export declare function interval(value: number, unit: IntervalUnit): SQL;
|
|
8
8
|
export declare function arrayAgg<T extends Column>(column: T): SQL<SelectResultField<T>[]>;
|
|
9
9
|
export declare function jsonAgg<T extends TableLike>(tableOrColumn: T): SQL<SelectResultField<GetSelectTableSelection<T>>[]>;
|
|
@@ -12,4 +12,5 @@ export declare namespace jsonAgg {
|
|
|
12
12
|
}
|
|
13
13
|
export declare function coalesce<T extends (Column | SQL)[]>(...columns: T): SQL<SelectResultField<T>[number]>;
|
|
14
14
|
export declare function toJsonb<T extends (Column | SQL)>(column: T): SQL<SelectResultField<T>>;
|
|
15
|
-
export
|
|
15
|
+
export declare function numNulls(...columns: Column[]): SQL<number>;
|
|
16
|
+
export declare function numNonNulls(...columns: Column[]): SQL<number>;
|
|
@@ -17,3 +17,9 @@ export function coalesce(...columns) {
|
|
|
17
17
|
export function toJsonb(column) {
|
|
18
18
|
return sql `to_jsonb(${column})`;
|
|
19
19
|
}
|
|
20
|
+
export function numNulls(...columns) {
|
|
21
|
+
return sql `num_nulls(${sql.join(columns, sql.raw(', '))})`;
|
|
22
|
+
}
|
|
23
|
+
export function numNonNulls(...columns) {
|
|
24
|
+
return sql `num_nonnulls(${sql.join(columns, sql.raw(', '))})`;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.90",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"mongodb": "^6.14",
|
|
174
174
|
"nodemailer": "^6.10",
|
|
175
175
|
"pg": "^8.13",
|
|
176
|
-
"playwright": "^1.
|
|
176
|
+
"playwright": "^1.51",
|
|
177
177
|
"preact": "^10.26",
|
|
178
178
|
"preact-render-to-string": "^6.5",
|
|
179
179
|
"undici": "^7.4",
|
package/queue/postgres/queue.js
CHANGED
|
@@ -9,7 +9,8 @@ import { merge } from 'rxjs';
|
|
|
9
9
|
import { CancellationSignal } from '../../cancellation/index.js';
|
|
10
10
|
import { inject, injectArgument, provide, Singleton } from '../../injector/index.js';
|
|
11
11
|
import { MessageBus } from '../../message-bus/index.js';
|
|
12
|
-
import {
|
|
12
|
+
import { interval, RANDOM_UUID, TRANSACTION_TIMESTAMP } from '../../orm/index.js';
|
|
13
|
+
import { DatabaseConfig, EntityRepositoryConfig, injectRepository } from '../../orm/server/index.js';
|
|
13
14
|
import { cancelableTimeout } from '../../utils/timing.js';
|
|
14
15
|
import { isDefined, isString } from '../../utils/type-guards.js';
|
|
15
16
|
import { millisecondsPerSecond } from '../../utils/units.js';
|
|
@@ -102,9 +103,9 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
102
103
|
.where(this.#dequeueQuery)
|
|
103
104
|
.orderBy(asc(job.priority), asc(job.enqueueTimestamp), asc(job.lastDequeueTimestamp), asc(job.tries))
|
|
104
105
|
.limit(count)
|
|
105
|
-
.for('update')))
|
|
106
|
+
.for('update', { skipLocked: true })))
|
|
106
107
|
.returning();
|
|
107
|
-
return this.#repository
|
|
108
|
+
return this.#repository.mapManyToEntity(rows);
|
|
108
109
|
}
|
|
109
110
|
async acknowledge(job) {
|
|
110
111
|
return this.cancel(job.id);
|