@tstdl/base 0.92.132 → 0.92.135
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/api/response.js +6 -6
- package/api/server/api-request-token.provider.d.ts +3 -0
- package/api/server/api-request-token.provider.js +9 -0
- package/api/server/module.js +1 -1
- package/database/mongo/module.js +6 -6
- package/document-management/api/document-management.api.d.ts +20 -4
- package/document-management/api/document-management.api.js +9 -3
- package/document-management/server/api/document-management.api.d.ts +1 -0
- package/document-management/server/api/document-management.api.js +9 -2
- package/document-management/server/module.d.ts +1 -0
- package/document-management/server/module.js +1 -0
- package/document-management/server/services/document-file.service.d.ts +16 -0
- package/document-management/server/services/document-file.service.js +55 -25
- package/document-management/server/services/document-management-ai.service.js +1 -1
- package/document-management/server/services/document-management-ancillary.service.d.ts +2 -2
- package/document-management/server/services/document-management.service.js +23 -11
- package/document-management/server/services/document-workflow.service.d.ts +1 -0
- package/document-management/server/services/document-workflow.service.js +15 -4
- package/document-management/server/services/document.service.d.ts +5 -1
- package/document-management/server/services/document.service.js +13 -10
- package/document-management/service-models/document-management.view-model.d.ts +15 -4
- package/document-management/service-models/document-management.view-model.js +42 -12
- package/document-management/service-models/document.service-model.d.ts +1 -0
- package/document-management/service-models/document.service-model.js +1 -0
- package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +13 -4
- package/document-management/service-models/enriched/enriched-document-assignment.view.js +29 -7
- package/document-management/service-models/enriched/enriched-document-collection.view.js +1 -1
- package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document.view.d.ts +2 -2
- package/document-management/service-models/enriched/enriched-document.view.js +2 -6
- package/examples/document-management/main.d.ts +1 -1
- package/examples/document-management/main.js +20 -8
- package/http/client/adapters/undici.adapter.js +3 -3
- package/http/client/http-client.js +29 -30
- package/http/http-body.js +4 -4
- package/http/http.error.d.ts +5 -1
- package/http/http.error.js +6 -6
- package/http/utils.js +4 -4
- package/injector/decorators.d.ts +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/interfaces.d.ts +1 -1
- package/injector/provider.d.ts +4 -4
- package/object-storage/object-storage.d.ts +38 -2
- package/object-storage/s3/s3.object-storage-provider.js +1 -1
- package/object-storage/s3/s3.object-storage.d.ts +6 -3
- package/object-storage/s3/s3.object-storage.js +88 -14
- package/object-storage/s3/s3.object.js +2 -3
- package/orm/server/repository.js +37 -37
- package/package.json +1 -1
- package/schema/schema.error.js +4 -7
- package/search-index/elastic/module.js +5 -5
- package/utils/cryptography.js +18 -18
- package/utils/object/object.d.ts +3 -2
- package/utils/object/object.js +5 -2
- package/utils/stream/size-limited-stream.js +1 -1
- package/utils/type-guards.d.ts +7 -1
- package/utils/type-guards.js +13 -1
package/orm/server/repository.js
CHANGED
|
@@ -84,7 +84,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
84
84
|
* @returns A promise that resolves to the loaded entity or `undefined` if not found.
|
|
85
85
|
*/
|
|
86
86
|
async tryLoad(id) {
|
|
87
|
-
return this.tryLoadByQuery(eq(this.#table.id, id));
|
|
87
|
+
return await this.tryLoadByQuery(eq(this.#table.id, id));
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Loads a single entity based on a query.
|
|
@@ -122,7 +122,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
122
122
|
if (isUndefined(row)) {
|
|
123
123
|
return undefined;
|
|
124
124
|
}
|
|
125
|
-
return this.mapToEntity(row);
|
|
125
|
+
return await this.mapToEntity(row);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Loads multiple entities by their IDs.
|
|
@@ -131,7 +131,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
131
131
|
* @returns A promise that resolves to an array of loaded entities.
|
|
132
132
|
*/
|
|
133
133
|
async loadMany(ids, options) {
|
|
134
|
-
return this.loadManyByQuery(inArray(this.#table.id, ids), options);
|
|
134
|
+
return await this.loadManyByQuery(inArray(this.#table.id, ids), options);
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Loads multiple entities by their IDs and returns them as an async iterable cursor.
|
|
@@ -168,7 +168,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
168
168
|
dbQuery = dbQuery.orderBy(...this.convertOrderBy(options.order));
|
|
169
169
|
}
|
|
170
170
|
const rows = await dbQuery;
|
|
171
|
-
return this.mapManyToEntity(rows);
|
|
171
|
+
return await this.mapManyToEntity(rows);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Loads multiple entities based on a query and returns them as an async iterable cursor.
|
|
@@ -186,7 +186,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
186
186
|
* @returns A promise that resolves to an array of all entities.
|
|
187
187
|
*/
|
|
188
188
|
async loadAll(options) {
|
|
189
|
-
return this.loadManyByQuery({}, options);
|
|
189
|
+
return await this.loadManyByQuery({}, options);
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* Loads all entities of the repository's type and returns them as an async iterable cursor.
|
|
@@ -230,7 +230,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
230
230
|
* @returns A promise that resolves to `true` if the entity exists, `false` otherwise.
|
|
231
231
|
*/
|
|
232
232
|
async has(id) {
|
|
233
|
-
return this.hasByQuery(eq(this.#table.id, id));
|
|
233
|
+
return await this.hasByQuery(eq(this.#table.id, id));
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* Checks if any entity matches the given query.
|
|
@@ -273,7 +273,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
273
273
|
if (isUndefined(row)) {
|
|
274
274
|
return undefined;
|
|
275
275
|
}
|
|
276
|
-
return this.mapToEntity(row);
|
|
276
|
+
return await this.mapToEntity(row);
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
279
279
|
* Inserts a new entity into the database.
|
|
@@ -286,7 +286,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
286
286
|
.insert(this.#table)
|
|
287
287
|
.values(columns)
|
|
288
288
|
.returning();
|
|
289
|
-
return this.mapToEntity(row);
|
|
289
|
+
return await this.mapToEntity(row);
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
292
|
* Inserts multiple new entities into the database.
|
|
@@ -296,7 +296,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
296
296
|
async insertMany(entities) {
|
|
297
297
|
const columns = await this.mapManyToInsertColumns(entities);
|
|
298
298
|
const rows = await this.session.insert(this.#table).values(columns).returning();
|
|
299
|
-
return this.mapManyToEntity(rows);
|
|
299
|
+
return await this.mapManyToEntity(rows);
|
|
300
300
|
}
|
|
301
301
|
/**
|
|
302
302
|
* Inserts an entity or updates it if a conflict occurs based on the target columns.
|
|
@@ -317,7 +317,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
317
317
|
set: mappedUpdate,
|
|
318
318
|
})
|
|
319
319
|
.returning();
|
|
320
|
-
return this.mapToEntity(row);
|
|
320
|
+
return await this.mapToEntity(row);
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
323
|
* Inserts multiple entities or updates them if a conflict occurs based on the target columns.
|
|
@@ -343,7 +343,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
343
343
|
set: mappedUpdate,
|
|
344
344
|
})
|
|
345
345
|
.returning();
|
|
346
|
-
return this.mapManyToEntity(rows);
|
|
346
|
+
return await this.mapManyToEntity(rows);
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* Updates an entity by its ID.
|
|
@@ -378,7 +378,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
378
378
|
if (isUndefined(row)) {
|
|
379
379
|
return undefined;
|
|
380
380
|
}
|
|
381
|
-
return this.mapToEntity(row);
|
|
381
|
+
return await this.mapToEntity(row);
|
|
382
382
|
}
|
|
383
383
|
/**
|
|
384
384
|
* Updates a single entity matching a query.
|
|
@@ -413,7 +413,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
413
413
|
if (isUndefined(row)) {
|
|
414
414
|
return undefined;
|
|
415
415
|
}
|
|
416
|
-
return this.mapToEntity(row);
|
|
416
|
+
return await this.mapToEntity(row);
|
|
417
417
|
}
|
|
418
418
|
/**
|
|
419
419
|
* Updates multiple entities by their IDs.
|
|
@@ -422,7 +422,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
422
422
|
* @returns A promise that resolves to an array of the updated entities.
|
|
423
423
|
*/
|
|
424
424
|
async updateMany(ids, update) {
|
|
425
|
-
return this.updateManyByQuery(inArray(this.#table.id, ids), update);
|
|
425
|
+
return await this.updateManyByQuery(inArray(this.#table.id, ids), update);
|
|
426
426
|
}
|
|
427
427
|
/**
|
|
428
428
|
* Updates multiple entities matching a query.
|
|
@@ -438,7 +438,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
438
438
|
.set(mappedUpdate)
|
|
439
439
|
.where(sqlQuery)
|
|
440
440
|
.returning();
|
|
441
|
-
return this.mapManyToEntity(rows);
|
|
441
|
+
return await this.mapManyToEntity(rows);
|
|
442
442
|
}
|
|
443
443
|
/**
|
|
444
444
|
* Deletes an entity by its ID (soft delete if metadata is available).
|
|
@@ -464,7 +464,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
464
464
|
*/
|
|
465
465
|
async tryDelete(id, metadataUpdate) {
|
|
466
466
|
if (!this.hasMetadata) {
|
|
467
|
-
return this.tryHardDelete(id);
|
|
467
|
+
return await this.tryHardDelete(id);
|
|
468
468
|
}
|
|
469
469
|
const sqlQuery = this.convertQuery(eq(this.#table.id, id));
|
|
470
470
|
const [row] = await this.session
|
|
@@ -478,7 +478,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
478
478
|
if (isUndefined(row)) {
|
|
479
479
|
return undefined;
|
|
480
480
|
}
|
|
481
|
-
return this.mapToEntity(row);
|
|
481
|
+
return await this.mapToEntity(row);
|
|
482
482
|
}
|
|
483
483
|
/**
|
|
484
484
|
* Deletes a single entity matching a query (soft delete if metadata is available).
|
|
@@ -504,7 +504,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
504
504
|
*/
|
|
505
505
|
async tryDeleteByQuery(query, metadataUpdate) {
|
|
506
506
|
if (!this.hasMetadata) {
|
|
507
|
-
return this.tryHardDeleteByQuery(query);
|
|
507
|
+
return await this.tryHardDeleteByQuery(query);
|
|
508
508
|
}
|
|
509
509
|
const idQuery = this.getIdLimitSelect(query);
|
|
510
510
|
const [row] = await this.session
|
|
@@ -518,7 +518,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
518
518
|
if (isUndefined(row)) {
|
|
519
519
|
return undefined;
|
|
520
520
|
}
|
|
521
|
-
return this.mapToEntity(row);
|
|
521
|
+
return await this.mapToEntity(row);
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
524
524
|
* Deletes multiple entities by their IDs (soft delete if metadata is available).
|
|
@@ -527,7 +527,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
527
527
|
* @returns A promise that resolves to an array of the deleted entities.
|
|
528
528
|
*/
|
|
529
529
|
async deleteMany(ids, metadataUpdate) {
|
|
530
|
-
return this.deleteManyByQuery(inArray(this.#table.id, ids), metadataUpdate);
|
|
530
|
+
return await this.deleteManyByQuery(inArray(this.#table.id, ids), metadataUpdate);
|
|
531
531
|
}
|
|
532
532
|
/**
|
|
533
533
|
* Deletes multiple entities matching a query (soft delete if metadata is available).
|
|
@@ -537,7 +537,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
537
537
|
*/
|
|
538
538
|
async deleteManyByQuery(query, metadataUpdate) {
|
|
539
539
|
if (!this.hasMetadata) {
|
|
540
|
-
return this.hardDeleteManyByQuery(query);
|
|
540
|
+
return await this.hardDeleteManyByQuery(query);
|
|
541
541
|
}
|
|
542
542
|
const sqlQuery = this.convertQuery(query);
|
|
543
543
|
const rows = await this.session
|
|
@@ -548,7 +548,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
548
548
|
})
|
|
549
549
|
.where(sqlQuery)
|
|
550
550
|
.returning();
|
|
551
|
-
return this.mapManyToEntity(rows);
|
|
551
|
+
return await this.mapManyToEntity(rows);
|
|
552
552
|
}
|
|
553
553
|
/**
|
|
554
554
|
* Hard deletes an entity by its ID (removes from the database).
|
|
@@ -579,7 +579,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
579
579
|
if (isUndefined(row)) {
|
|
580
580
|
return undefined;
|
|
581
581
|
}
|
|
582
|
-
return this.mapToEntity(row);
|
|
582
|
+
return await this.mapToEntity(row);
|
|
583
583
|
}
|
|
584
584
|
/**
|
|
585
585
|
* Hard deletes a single entity matching a query (removes from the database).
|
|
@@ -610,7 +610,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
610
610
|
if (isUndefined(row)) {
|
|
611
611
|
return undefined;
|
|
612
612
|
}
|
|
613
|
-
return this.mapToEntity(row);
|
|
613
|
+
return await this.mapToEntity(row);
|
|
614
614
|
}
|
|
615
615
|
/**
|
|
616
616
|
* Hard deletes multiple entities by their IDs (removes from the database).
|
|
@@ -618,7 +618,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
618
618
|
* @returns A promise that resolves to an array of the hard deleted entities.
|
|
619
619
|
*/
|
|
620
620
|
async hardDeleteMany(ids) {
|
|
621
|
-
return this.hardDeleteManyByQuery(inArray(this.#table.id, ids));
|
|
621
|
+
return await this.hardDeleteManyByQuery(inArray(this.#table.id, ids));
|
|
622
622
|
}
|
|
623
623
|
/**
|
|
624
624
|
* Hard deletes multiple entities matching a query (removes from the database).
|
|
@@ -631,7 +631,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
631
631
|
.delete(this.#table)
|
|
632
632
|
.where(sqlQuery)
|
|
633
633
|
.returning();
|
|
634
|
-
return this.mapManyToEntity(rows);
|
|
634
|
+
return await this.mapManyToEntity(rows);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* Retrieves the Drizzle PgColumn for a given object path or column definition.
|
|
@@ -693,7 +693,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
693
693
|
*/
|
|
694
694
|
async mapManyToEntity(columns) {
|
|
695
695
|
const transformContext = await this.getTransformContext();
|
|
696
|
-
return this._mapManyToEntity(columns, transformContext);
|
|
696
|
+
return await this._mapManyToEntity(columns, transformContext);
|
|
697
697
|
}
|
|
698
698
|
/**
|
|
699
699
|
* Maps a single database row to an entity.
|
|
@@ -702,7 +702,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
702
702
|
*/
|
|
703
703
|
async mapToEntity(columns) {
|
|
704
704
|
const transformContext = await this.getTransformContext();
|
|
705
|
-
return this._mapToEntity(columns, transformContext);
|
|
705
|
+
return await this._mapToEntity(columns, transformContext);
|
|
706
706
|
}
|
|
707
707
|
/**
|
|
708
708
|
* Maps multiple entity-like objects to database column values for insertion or update.
|
|
@@ -711,7 +711,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
711
711
|
*/
|
|
712
712
|
async mapManyToColumns(objects) {
|
|
713
713
|
const transformContext = await this.getTransformContext();
|
|
714
|
-
return this._mapManyToColumns(objects, transformContext);
|
|
714
|
+
return await this._mapManyToColumns(objects, transformContext);
|
|
715
715
|
}
|
|
716
716
|
/**
|
|
717
717
|
* Maps a single entity-like object to database column values for insertion or update.
|
|
@@ -720,7 +720,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
720
720
|
*/
|
|
721
721
|
async mapToColumns(obj) {
|
|
722
722
|
const transformContext = await this.getTransformContext();
|
|
723
|
-
return this._mapToColumns(obj, transformContext);
|
|
723
|
+
return await this._mapToColumns(obj, transformContext);
|
|
724
724
|
}
|
|
725
725
|
/**
|
|
726
726
|
* Maps multiple new entity objects to database column values for insertion.
|
|
@@ -729,7 +729,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
729
729
|
*/
|
|
730
730
|
async mapManyToInsertColumns(objects) {
|
|
731
731
|
const transformContext = await this.getTransformContext();
|
|
732
|
-
return this._mapManyToInsertColumns(objects, transformContext);
|
|
732
|
+
return await this._mapManyToInsertColumns(objects, transformContext);
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
735
|
* Maps a new entity object to database column values for insertion.
|
|
@@ -738,7 +738,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
738
738
|
*/
|
|
739
739
|
async mapToInsertColumns(obj) {
|
|
740
740
|
const transformContext = await this.getTransformContext();
|
|
741
|
-
return this._mapToInsertColumns(obj, transformContext);
|
|
741
|
+
return await this._mapToInsertColumns(obj, transformContext);
|
|
742
742
|
}
|
|
743
743
|
/**
|
|
744
744
|
* Maps an entity update object to database column values for updating.
|
|
@@ -747,7 +747,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
747
747
|
*/
|
|
748
748
|
async mapUpdate(update) {
|
|
749
749
|
const transformContext = await this.getTransformContext();
|
|
750
|
-
return this._mapUpdate(update, transformContext);
|
|
750
|
+
return await this._mapUpdate(update, transformContext);
|
|
751
751
|
}
|
|
752
752
|
/**
|
|
753
753
|
* Gets a Drizzle select query for the ID of a single entity matching the provided query, limited to 1 result.
|
|
@@ -768,7 +768,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
768
768
|
return sql `${this.#tableWithMetadata.attributes} || ${JSON.stringify(attributes)}::jsonb`;
|
|
769
769
|
}
|
|
770
770
|
async _mapManyToEntity(columns, transformContext) {
|
|
771
|
-
return toArrayAsync(mapAsync(columns, async (column) => this._mapToEntity(column, transformContext)));
|
|
771
|
+
return await toArrayAsync(mapAsync(columns, async (column) => await this._mapToEntity(column, transformContext)));
|
|
772
772
|
}
|
|
773
773
|
async _mapToEntity(columns, transformContext) {
|
|
774
774
|
const entries = [];
|
|
@@ -781,7 +781,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
781
781
|
return Schema.parse(this.type, obj);
|
|
782
782
|
}
|
|
783
783
|
async _mapManyToColumns(objects, transformContext) {
|
|
784
|
-
return toArrayAsync(mapAsync(objects, async (obj) => this._mapToColumns(obj, transformContext)));
|
|
784
|
+
return await toArrayAsync(mapAsync(objects, async (obj) => await this._mapToColumns(obj, transformContext)));
|
|
785
785
|
}
|
|
786
786
|
async _mapToColumns(obj, transformContext) {
|
|
787
787
|
const columns = {};
|
|
@@ -792,7 +792,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
792
792
|
return columns;
|
|
793
793
|
}
|
|
794
794
|
async _mapManyToInsertColumns(objects, transformContext) {
|
|
795
|
-
return toArrayAsync(mapAsync(objects, async (obj) => this._mapToInsertColumns(obj, transformContext)));
|
|
795
|
+
return await toArrayAsync(mapAsync(objects, async (obj) => await this._mapToInsertColumns(obj, transformContext)));
|
|
796
796
|
}
|
|
797
797
|
async _mapToInsertColumns(obj, transformContext) {
|
|
798
798
|
const mapped = await this._mapToColumns(obj, transformContext);
|
|
@@ -847,7 +847,7 @@ let EntityRepository = class EntityRepository extends Transactional {
|
|
|
847
847
|
const transformContext = await this.#transformContext;
|
|
848
848
|
this.#transformContext = transformContext;
|
|
849
849
|
}
|
|
850
|
-
return this.#transformContext;
|
|
850
|
+
return await this.#transformContext;
|
|
851
851
|
}
|
|
852
852
|
};
|
|
853
853
|
EntityRepository = __decorate([
|
package/package.json
CHANGED
package/schema/schema.error.js
CHANGED
|
@@ -8,8 +8,9 @@ export class SchemaError extends CustomError {
|
|
|
8
8
|
inner;
|
|
9
9
|
innerMessages;
|
|
10
10
|
constructor(message, options, cause) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const path = isString(options.path) ? options.path : options.path.path;
|
|
12
|
+
super({ message: `${path}: ${message}`, cause: cause ?? options.cause, fast: options.fast });
|
|
13
|
+
this.path = path;
|
|
13
14
|
if (isDefined(options.inner) && (!isArray(options.inner) || (options.inner.length > 0))) {
|
|
14
15
|
this.inner = isArray(options.inner)
|
|
15
16
|
? (options.inner.length == 1)
|
|
@@ -22,7 +23,6 @@ export class SchemaError extends CustomError {
|
|
|
22
23
|
this.details = options.details;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
26
26
|
static expectedButGot(expected, got, path, options) {
|
|
27
27
|
const expectedNames = toArray(expected).map((e) => isFunction(e) ? e.name : e);
|
|
28
28
|
const expectedString = expectedNames.length == 1
|
|
@@ -32,7 +32,6 @@ export class SchemaError extends CustomError {
|
|
|
32
32
|
const message = `Expected ${expectedString} but got ${got}${customMessage}`;
|
|
33
33
|
return new SchemaError(message, { path, ...options });
|
|
34
34
|
}
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
36
35
|
static couldNotCoerce(expected, got, path, options) {
|
|
37
36
|
const expectedNames = toArray(expected).map((e) => isFunction(e) ? e.name : e);
|
|
38
37
|
const expectedString = expectedNames.length == 1
|
|
@@ -43,9 +42,7 @@ export class SchemaError extends CustomError {
|
|
|
43
42
|
return new SchemaError(errorMessage, { path, ...options });
|
|
44
43
|
}
|
|
45
44
|
getExtraInfo(includeMessage = false) {
|
|
46
|
-
const obj = {
|
|
47
|
-
path: this.path
|
|
48
|
-
};
|
|
45
|
+
const obj = { path: this.path };
|
|
49
46
|
if (includeMessage) {
|
|
50
47
|
obj['message'] = this.message;
|
|
51
48
|
}
|
|
@@ -8,7 +8,7 @@ import { Client } from '@elastic/elasticsearch';
|
|
|
8
8
|
import { ElasticSearchIndexConfig } from './config.js';
|
|
9
9
|
export const elasticsearchModuleConfig = {
|
|
10
10
|
defaultOptions: { node: 'http://localhost:9200' },
|
|
11
|
-
logPrefix: 'ELASTIC'
|
|
11
|
+
logPrefix: 'ELASTIC',
|
|
12
12
|
};
|
|
13
13
|
export const ELASTIC_SEARCH_INDEX_CONFIG = injectionToken('ElasticSearchIndexConfig');
|
|
14
14
|
export function configureElasticsearch(config = {}) {
|
|
@@ -20,19 +20,19 @@ Injector.registerSingleton(Client, {
|
|
|
20
20
|
assertDefined(argument, 'missing elasticsearch client options');
|
|
21
21
|
context.data.logger = inject(Logger, elasticsearchModuleConfig.logPrefix);
|
|
22
22
|
const client = new Client(argument);
|
|
23
|
-
context.addDisposeHandler(async () => client.close().then(() => context.data.logger.info('closed connection')));
|
|
23
|
+
context.addDisposeHandler(async () => await client.close().then(() => context.data.logger.info('closed connection')));
|
|
24
24
|
return client;
|
|
25
25
|
},
|
|
26
26
|
async afterResolve(client, options, { cancellationSignal, data: { logger } }) {
|
|
27
27
|
const url = getUrl(options.node ?? options.nodes);
|
|
28
|
-
await connect(`elasticsearch (${url})`, async () => client.ping().then((alive) => assert(alive, 'failed to connect')), logger, cancellationSignal);
|
|
28
|
+
await connect(`elasticsearch (${url})`, async () => await client.ping().then((alive) => assert(alive, 'failed to connect')), logger, cancellationSignal);
|
|
29
29
|
},
|
|
30
30
|
defaultArgumentProvider() {
|
|
31
31
|
return elasticsearchModuleConfig.defaultOptions;
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
});
|
|
34
34
|
Injector.registerSingleton(ELASTIC_SEARCH_INDEX_CONFIG, {
|
|
35
|
-
useFactory: (argument, context) => context.resolve(ElasticSearchIndexConfig, argument)
|
|
35
|
+
useFactory: (argument, context) => context.resolve(ElasticSearchIndexConfig, argument),
|
|
36
36
|
});
|
|
37
37
|
function getUrl(node) {
|
|
38
38
|
if (isString(node)) {
|
package/utils/cryptography.js
CHANGED
|
@@ -14,11 +14,11 @@ export function encrypt(algorithm, key, data) {
|
|
|
14
14
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
15
15
|
const encryptedBuffer = globalThis.crypto.subtle.encrypt(algorithm, key, bytes);
|
|
16
16
|
return {
|
|
17
|
-
toBuffer: async () => encryptedBuffer,
|
|
17
|
+
toBuffer: async () => await encryptedBuffer,
|
|
18
18
|
toHex: async () => encodeHex(await encryptedBuffer),
|
|
19
19
|
toBase64: async () => encodeBase64(await encryptedBuffer),
|
|
20
20
|
toBase64Url: async () => encodeBase64Url(await encryptedBuffer),
|
|
21
|
-
toZBase32: async () => zBase32Encode(await encryptedBuffer)
|
|
21
|
+
toZBase32: async () => zBase32Encode(await encryptedBuffer),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -30,12 +30,12 @@ export function encrypt(algorithm, key, data) {
|
|
|
30
30
|
export function decrypt(algorithm, key, bytes) {
|
|
31
31
|
const decryptedBuffer = globalThis.crypto.subtle.decrypt(algorithm, key, bytes);
|
|
32
32
|
return {
|
|
33
|
-
toBuffer: async () => decryptedBuffer,
|
|
33
|
+
toBuffer: async () => await decryptedBuffer,
|
|
34
34
|
toHex: async () => encodeHex(await decryptedBuffer),
|
|
35
35
|
toBase64: async () => encodeBase64(await decryptedBuffer),
|
|
36
36
|
toBase64Url: async () => encodeBase64Url(await decryptedBuffer),
|
|
37
37
|
toZBase32: async () => zBase32Encode(await decryptedBuffer),
|
|
38
|
-
toUtf8: async () => decodeText(await decryptedBuffer)
|
|
38
|
+
toUtf8: async () => decodeText(await decryptedBuffer),
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
@@ -47,11 +47,11 @@ export function digest(algorithm, data) {
|
|
|
47
47
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
48
48
|
const arrayBufferPromise = globalThis.crypto.subtle.digest(algorithm, bytes);
|
|
49
49
|
const result = {
|
|
50
|
-
toBuffer: async () => arrayBufferPromise,
|
|
50
|
+
toBuffer: async () => await arrayBufferPromise,
|
|
51
51
|
toHex: async () => encodeHex(await arrayBufferPromise),
|
|
52
52
|
toBase64: async () => encodeBase64(await arrayBufferPromise),
|
|
53
53
|
toBase64Url: async () => encodeBase64Url(await arrayBufferPromise),
|
|
54
|
-
toZBase32: async () => zBase32Encode(await arrayBufferPromise)
|
|
54
|
+
toZBase32: async () => zBase32Encode(await arrayBufferPromise),
|
|
55
55
|
};
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
@@ -65,11 +65,11 @@ export function sign(algorithm, key, data) {
|
|
|
65
65
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
66
66
|
const arrayBufferPromise = globalThis.crypto.subtle.sign(algorithm, key, bytes);
|
|
67
67
|
const result = {
|
|
68
|
-
toBuffer: async () => arrayBufferPromise,
|
|
68
|
+
toBuffer: async () => await arrayBufferPromise,
|
|
69
69
|
toHex: async () => encodeHex(await arrayBufferPromise),
|
|
70
70
|
toBase64: async () => encodeBase64(await arrayBufferPromise),
|
|
71
71
|
toBase64Url: async () => encodeBase64Url(await arrayBufferPromise),
|
|
72
|
-
toZBase32: async () => zBase32Encode(await arrayBufferPromise)
|
|
72
|
+
toZBase32: async () => zBase32Encode(await arrayBufferPromise),
|
|
73
73
|
};
|
|
74
74
|
return result;
|
|
75
75
|
}
|
|
@@ -83,7 +83,7 @@ export function sign(algorithm, key, data) {
|
|
|
83
83
|
export async function verify(algorithm, key, signature, data) {
|
|
84
84
|
const signatureBytes = isString(signature) ? encodeUtf8(signature) : signature;
|
|
85
85
|
const dataBytes = isString(data) ? encodeUtf8(data) : data;
|
|
86
|
-
return globalThis.crypto.subtle.verify(algorithm, key, signatureBytes, dataBytes);
|
|
86
|
+
return await globalThis.crypto.subtle.verify(algorithm, key, signatureBytes, dataBytes);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Imports a HMAC CryptoKey
|
|
@@ -94,9 +94,9 @@ export async function verify(algorithm, key, signature, data) {
|
|
|
94
94
|
export async function importHmacKey(algorithm, key, extractable = false) {
|
|
95
95
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
96
96
|
if (isBinaryKey(binaryKey)) {
|
|
97
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
97
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
98
98
|
}
|
|
99
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
99
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Imports a CryptoKey for symmetric encryption
|
|
@@ -108,9 +108,9 @@ export async function importHmacKey(algorithm, key, extractable = false) {
|
|
|
108
108
|
export async function importSymmetricKey(algorithm, length, key, extractable = false) {
|
|
109
109
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
110
110
|
if (isBinaryKey(binaryKey)) {
|
|
111
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
111
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
112
112
|
}
|
|
113
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
113
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
116
|
* Imports an ECDSA CryptoKey
|
|
@@ -121,9 +121,9 @@ export async function importSymmetricKey(algorithm, length, key, extractable = f
|
|
|
121
121
|
export async function importEcdsaKey(curve, key, extractable = false) {
|
|
122
122
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
123
123
|
if (isBinaryKey(binaryKey)) {
|
|
124
|
-
return globalThis.crypto.subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
124
|
+
return await globalThis.crypto.subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
125
125
|
}
|
|
126
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
126
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Import a pbkdf2 CryptoKey
|
|
@@ -132,7 +132,7 @@ export async function importEcdsaKey(curve, key, extractable = false) {
|
|
|
132
132
|
*/
|
|
133
133
|
export async function importPbkdf2Key(key, extractable = false) {
|
|
134
134
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
135
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'PBKDF2' }, extractable, ['deriveKey', 'deriveBits']);
|
|
135
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'PBKDF2' }, extractable, ['deriveKey', 'deriveBits']);
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Generates a new ECDSA CryptoKeyPair
|
|
@@ -141,7 +141,7 @@ export async function importPbkdf2Key(key, extractable = false) {
|
|
|
141
141
|
* @param usages whether to generate a key for signing, verifiying or both. Defaults to both
|
|
142
142
|
*/
|
|
143
143
|
export async function generateEcdsaKey(curve, extractable = false, usages = ['sign', 'verify']) {
|
|
144
|
-
return globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
|
|
144
|
+
return await globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Generates a pbkdf2 CryptoKey
|
|
@@ -149,7 +149,7 @@ export async function generateEcdsaKey(curve, extractable = false, usages = ['si
|
|
|
149
149
|
*/
|
|
150
150
|
export async function generatePbkdf2Key(extractable = false) {
|
|
151
151
|
const key = getRandomBytes(16);
|
|
152
|
-
return importPbkdf2Key(key, extractable);
|
|
152
|
+
return await importPbkdf2Key(key, extractable);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Derive byte array from key
|
package/utils/object/object.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export declare function objectKeys<T extends ObjectLiteral>(object: T): (keyof T
|
|
|
13
13
|
export declare function objectValues<T extends ObjectLiteral>(object: T): (T[keyof T])[];
|
|
14
14
|
export declare function fromEntries<A>(entries: A): FromEntries<A>;
|
|
15
15
|
export declare function fromEntries<K extends PropertyKey, T>(entries: Iterable<readonly [K, T]>): Record<K, T>;
|
|
16
|
-
export declare function mapObject<T extends ObjectLiteral, K extends
|
|
17
|
-
export declare function mapObjectAsync<T extends ObjectLiteral, K extends
|
|
16
|
+
export declare function mapObject<T extends ObjectLiteral, K extends PropertyKey, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => [key: K, value: V]): Record<K, V>;
|
|
17
|
+
export declare function mapObjectAsync<T extends ObjectLiteral, K extends PropertyKey, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => Promise<[key: K, value: V]>): Promise<Record<K, V>>;
|
|
18
18
|
export declare function mapObjectValues<T extends ObjectLiteral, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => V): Record<keyof T, V>;
|
|
19
|
+
export declare function mapObjectKeys<T extends ObjectLiteral, K extends PropertyKey>(object: T, mapper: (key: keyof T, value: T[keyof T]) => K): Record<K, T[keyof T]>;
|
|
19
20
|
export declare function mapObjectValuesAsync<T extends ObjectLiteral, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => Promise<V>): Promise<Record<keyof T, V>>;
|
|
20
21
|
export declare function filterObject<T extends ObjectLiteral, U extends T[keyof T]>(object: T, predicate: (value: T[keyof T], key: keyof T) => value is U): PickBy<T, U>;
|
|
21
22
|
export declare function filterObject<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
package/utils/object/object.js
CHANGED
|
@@ -31,14 +31,17 @@ export function mapObject(object, mapper) {
|
|
|
31
31
|
}
|
|
32
32
|
export async function mapObjectAsync(object, mapper) {
|
|
33
33
|
const entries = objectKeys(object);
|
|
34
|
-
const mappedEntries = await toArrayAsync(mapAsync(entries, async (key) => mapper(object[key], key)));
|
|
34
|
+
const mappedEntries = await toArrayAsync(mapAsync(entries, async (key) => await mapper(object[key], key)));
|
|
35
35
|
return Object.fromEntries(mappedEntries);
|
|
36
36
|
}
|
|
37
37
|
export function mapObjectValues(object, mapper) {
|
|
38
38
|
return mapObject(object, (value, key) => [key, mapper(value, key)]);
|
|
39
39
|
}
|
|
40
|
+
export function mapObjectKeys(object, mapper) {
|
|
41
|
+
return mapObject(object, (value, key) => [mapper(key, value), value]);
|
|
42
|
+
}
|
|
40
43
|
export async function mapObjectValuesAsync(object, mapper) {
|
|
41
|
-
return mapObjectAsync(object, async (value, key) => [key, await mapper(value, key)]);
|
|
44
|
+
return await mapObjectAsync(object, async (value, key) => [key, await mapper(value, key)]);
|
|
42
45
|
}
|
|
43
46
|
export function filterObject(object, predicate) {
|
|
44
47
|
const mappedEntries = objectEntries(object).filter(([key, value]) => predicate(value, key));
|
package/utils/type-guards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractConstructor, BinaryData, JsonPrimitive, PascalCase, Primitive, TypedArray } from '../types.js';
|
|
1
|
+
import type { AbstractConstructor, BinaryData, JsonPrimitive, PascalCase, Primitive, Type, TypedArray } from '../types.js';
|
|
2
2
|
export type AssertionMessage = string | (() => string);
|
|
3
3
|
export type IsFunction<T> = <U extends T = T>(value: any) => value is U;
|
|
4
4
|
export type IsNotFunction<T> = <V>(value: V) => value is Exclude<V, T>;
|
|
@@ -257,3 +257,9 @@ export declare const assertReadableStream: <T = any>(value: any, message?: Asser
|
|
|
257
257
|
export declare const assertNotReadableStream: AssertNotFunction<ReadableStream>;
|
|
258
258
|
export declare const assertReadableStreamPass: <T = any>(value: any, message?: AssertionMessage) => ReadableStream<T>;
|
|
259
259
|
export declare const assertNotReadableStreamPass: AssertNotPassFunction<ReadableStream>;
|
|
260
|
+
export declare const isInstanceOf: <T>(value: any, type: Type<T>) => value is T;
|
|
261
|
+
export declare const isNotInstanceOf: <V, T>(value: V, type: Type<T>) => value is Exclude<V, T>;
|
|
262
|
+
export declare const assertInstanceOf: <T>(value: any, type: Type<T>, message?: AssertionMessage) => asserts value is T;
|
|
263
|
+
export declare const assertNotInstanceOf: <V, T>(value: V, type: Type<T>, message?: AssertionMessage) => asserts value is Exclude<V, T>;
|
|
264
|
+
export declare const assertInstanceOfPass: <T>(value: any, type: Type<T>, message?: AssertionMessage) => T;
|
|
265
|
+
export declare const assertNotInstanceOfPass: <V, T>(value: V, type: Type<T>, message?: AssertionMessage) => Exclude<V, T>;
|
package/utils/type-guards.js
CHANGED
|
@@ -36,7 +36,7 @@ export function createGuards(name, testFn) {
|
|
|
36
36
|
[`assertNot${normalizedName}Pass`](value, message = defaultNotMessage) {
|
|
37
37
|
assertNot(testFn(value), message);
|
|
38
38
|
return value;
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
export function createInstanceGuards(name, type) {
|
|
@@ -335,3 +335,15 @@ export const assertReadableStream = readableStreamGuards.assertReadableStream;
|
|
|
335
335
|
export const assertNotReadableStream = readableStreamGuards.assertNotReadableStream;
|
|
336
336
|
export const assertReadableStreamPass = readableStreamGuards.assertReadableStreamPass;
|
|
337
337
|
export const assertNotReadableStreamPass = readableStreamGuards.assertNotReadableStreamPass;
|
|
338
|
+
export const isInstanceOf = (value, type) => value instanceof type;
|
|
339
|
+
export const isNotInstanceOf = (value, type) => !isInstanceOf(value, type);
|
|
340
|
+
export const assertInstanceOf = (value, type, message) => assert(isInstanceOf(value, type), message);
|
|
341
|
+
export const assertNotInstanceOf = (value, type, message) => assertNot(isInstanceOf(value, type), message);
|
|
342
|
+
export const assertInstanceOfPass = (value, type, message) => {
|
|
343
|
+
assert(isInstanceOf(value, type), message);
|
|
344
|
+
return value;
|
|
345
|
+
};
|
|
346
|
+
export const assertNotInstanceOfPass = (value, type, message) => {
|
|
347
|
+
assertNot(isInstanceOf(value, type), message);
|
|
348
|
+
return value;
|
|
349
|
+
};
|