@punks/backend-entity-manager 0.0.326 → 0.0.327
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/dist/cjs/index.js +66 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/operations.d.ts +21 -0
- package/dist/cjs/types/platforms/nest/decorators/operations.d.ts +2 -0
- package/dist/cjs/types/platforms/nest/decorators/pipelines.d.ts +2 -2
- package/dist/cjs/types/platforms/nest/decorators/symbols.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/pipelines/template/template.d.ts +9 -0
- package/dist/cjs/types/platforms/nest/processors/initializer/index.d.ts +2 -0
- package/dist/cjs/types/platforms/nest/services/operations/operation-lock.service.d.ts +2 -4
- package/dist/cjs/types/platforms/nest/services/operations/types.d.ts +0 -17
- package/dist/cjs/types/providers/services.d.ts +3 -1
- package/dist/cjs/types/symbols/ioc.d.ts +3 -0
- package/dist/esm/index.js +66 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/operations.d.ts +21 -0
- package/dist/esm/types/platforms/nest/decorators/operations.d.ts +2 -0
- package/dist/esm/types/platforms/nest/decorators/pipelines.d.ts +2 -2
- package/dist/esm/types/platforms/nest/decorators/symbols.d.ts +1 -0
- package/dist/esm/types/platforms/nest/pipelines/template/template.d.ts +9 -0
- package/dist/esm/types/platforms/nest/processors/initializer/index.d.ts +2 -0
- package/dist/esm/types/platforms/nest/services/operations/operation-lock.service.d.ts +2 -4
- package/dist/esm/types/platforms/nest/services/operations/types.d.ts +0 -17
- package/dist/esm/types/providers/services.d.ts +3 -1
- package/dist/esm/types/symbols/ioc.d.ts +3 -0
- package/dist/index.d.ts +39 -23
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -140,6 +140,8 @@ class MissingEntityIdError extends EntityManagerException {
|
|
|
140
140
|
|
|
141
141
|
class LockNotFoundError extends Error {
|
|
142
142
|
}
|
|
143
|
+
class ExclusiveOperationResult {
|
|
144
|
+
}
|
|
143
145
|
|
|
144
146
|
exports.ReplicationMode = void 0;
|
|
145
147
|
(function (ReplicationMode) {
|
|
@@ -1328,6 +1330,9 @@ const GlobalServices = {
|
|
|
1328
1330
|
IAuthenticationContextProvider: "IAuthenticationContextProvider",
|
|
1329
1331
|
IAuthenticationMiddleware: "IAuthenticationMiddleware",
|
|
1330
1332
|
},
|
|
1333
|
+
Operations: {
|
|
1334
|
+
IOperationLockService: "IOperationLockService",
|
|
1335
|
+
},
|
|
1331
1336
|
Pipelines: {
|
|
1332
1337
|
IPipelineController: "IPipelineController",
|
|
1333
1338
|
},
|
|
@@ -1624,6 +1629,12 @@ class EntitiesServiceLocator {
|
|
|
1624
1629
|
registerEventsTracker(instance) {
|
|
1625
1630
|
this.provider.register(GlobalServices.Events.IEventsTracker, instance);
|
|
1626
1631
|
}
|
|
1632
|
+
resolveOperationLockService() {
|
|
1633
|
+
return this.provider.resolve(GlobalServices.Operations.IOperationLockService);
|
|
1634
|
+
}
|
|
1635
|
+
registerOperationLockService(instance) {
|
|
1636
|
+
this.provider.register(GlobalServices.Operations.IOperationLockService, instance);
|
|
1637
|
+
}
|
|
1627
1638
|
resolveEmailTemplatesCollection() {
|
|
1628
1639
|
return this.provider.resolve(GlobalServices.Plugins.IEmailTemplatesCollection);
|
|
1629
1640
|
}
|
|
@@ -3628,6 +3639,7 @@ const EntityManagerSymbols = {
|
|
|
3628
3639
|
FileReferenceRepository: Symbol.for("WP:FILE_REFERENCE_REPO"),
|
|
3629
3640
|
PipelineTemplate: Symbol.for("WP:PIPELINE_TEMPLATE"),
|
|
3630
3641
|
CacheInstance: Symbol.for("WP:CACHE_INSTANCE"),
|
|
3642
|
+
OperationLockService: Symbol.for("WP:OPERATION_LOCK_SERVICE"),
|
|
3631
3643
|
};
|
|
3632
3644
|
|
|
3633
3645
|
const WpEntityAuthMiddleware = (entityName, props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.EntityAuthMiddleware, {
|
|
@@ -21961,12 +21973,14 @@ function subDays(dirtyDate, dirtyAmount) {
|
|
|
21961
21973
|
return addDays(dirtyDate, -amount);
|
|
21962
21974
|
}
|
|
21963
21975
|
|
|
21964
|
-
|
|
21976
|
+
const WpOperationLockService = (props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.OperationLockService, {
|
|
21977
|
+
...props,
|
|
21978
|
+
}));
|
|
21979
|
+
|
|
21965
21980
|
const DEFAULT_LOCK_POLLING = 100;
|
|
21966
|
-
exports.OperationLockService =
|
|
21981
|
+
exports.OperationLockService = class OperationLockService {
|
|
21967
21982
|
constructor(operations) {
|
|
21968
21983
|
this.operations = operations;
|
|
21969
|
-
this.logger = backendCore.Log.getLogger(OperationLockService_1.name);
|
|
21970
21984
|
this.executeSequential = async (input) => {
|
|
21971
21985
|
const lock = await this.operations.acquireLock({
|
|
21972
21986
|
lockUid: input.lockUid,
|
|
@@ -22029,8 +22043,8 @@ exports.OperationLockService = OperationLockService_1 = class OperationLockServi
|
|
|
22029
22043
|
};
|
|
22030
22044
|
}
|
|
22031
22045
|
};
|
|
22032
|
-
exports.OperationLockService =
|
|
22033
|
-
|
|
22046
|
+
exports.OperationLockService = __decorate([
|
|
22047
|
+
WpOperationLockService(),
|
|
22034
22048
|
__param(0, common.Inject(getEntityManagerProviderToken("OperationsLockRepository"))),
|
|
22035
22049
|
__metadata("design:paramtypes", [Object])
|
|
22036
22050
|
], exports.OperationLockService);
|
|
@@ -23458,6 +23472,18 @@ exports.EntityManagerInitializer = EntityManagerInitializer_1 = class EntityMana
|
|
|
23458
23472
|
.getEntitiesServicesLocator()
|
|
23459
23473
|
.registerEmailTemplatesCollection(collection);
|
|
23460
23474
|
}
|
|
23475
|
+
async registerOperationLockService() {
|
|
23476
|
+
const operationLockServices = await this.discoverOperationLockService();
|
|
23477
|
+
if (!operationLockServices.length) {
|
|
23478
|
+
this.logger.warn("No operation lock services found ⚠️");
|
|
23479
|
+
return;
|
|
23480
|
+
}
|
|
23481
|
+
this.registry
|
|
23482
|
+
.getContainer()
|
|
23483
|
+
.getEntitiesServicesLocator()
|
|
23484
|
+
.registerOperationLockService(operationLockServices[0].discoveredClass
|
|
23485
|
+
.instance);
|
|
23486
|
+
}
|
|
23461
23487
|
async registerPipelinesServices() {
|
|
23462
23488
|
this.registry
|
|
23463
23489
|
.getContainer()
|
|
@@ -23523,6 +23549,9 @@ exports.EntityManagerInitializer = EntityManagerInitializer_1 = class EntityMana
|
|
|
23523
23549
|
async discoverEmailLogger() {
|
|
23524
23550
|
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.EmailLogger);
|
|
23525
23551
|
}
|
|
23552
|
+
async discoverOperationLockService() {
|
|
23553
|
+
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.OperationLockService);
|
|
23554
|
+
}
|
|
23526
23555
|
async discoverBucketProviders() {
|
|
23527
23556
|
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.BucketProvider);
|
|
23528
23557
|
}
|
|
@@ -34377,13 +34406,17 @@ class PipelineUtils {
|
|
|
34377
34406
|
}
|
|
34378
34407
|
|
|
34379
34408
|
class NestPipelineTemplate {
|
|
34380
|
-
constructor() {
|
|
34409
|
+
constructor(options) {
|
|
34410
|
+
this.options = options;
|
|
34381
34411
|
this.logger = backendCore.Log.getLogger(NestPipelineTemplate.name);
|
|
34382
34412
|
this.utils = new PipelineUtils();
|
|
34383
34413
|
}
|
|
34384
34414
|
isAuthorized(context) {
|
|
34385
34415
|
return true;
|
|
34386
34416
|
}
|
|
34417
|
+
getConcurrencyKey(input) {
|
|
34418
|
+
return this.constructor.name;
|
|
34419
|
+
}
|
|
34387
34420
|
async invoke(input) {
|
|
34388
34421
|
const result = await this.execute({
|
|
34389
34422
|
input,
|
|
@@ -34395,6 +34428,26 @@ class NestPipelineTemplate {
|
|
|
34395
34428
|
return result.output;
|
|
34396
34429
|
}
|
|
34397
34430
|
async execute(data) {
|
|
34431
|
+
if (this.options?.concurrency === "sequential") {
|
|
34432
|
+
return await this.operationsLockService.executeSequential({
|
|
34433
|
+
lockUid: this.getConcurrencyKey(data.input),
|
|
34434
|
+
operation: async () => {
|
|
34435
|
+
return await this.pipelineExecute(data);
|
|
34436
|
+
},
|
|
34437
|
+
});
|
|
34438
|
+
}
|
|
34439
|
+
if (this.options?.concurrency === "exclusive") {
|
|
34440
|
+
const result = await this.operationsLockService.executeExclusive({
|
|
34441
|
+
lockUid: this.getConcurrencyKey(data.input),
|
|
34442
|
+
operation: async () => {
|
|
34443
|
+
return await this.pipelineExecute(data);
|
|
34444
|
+
},
|
|
34445
|
+
});
|
|
34446
|
+
return result.result;
|
|
34447
|
+
}
|
|
34448
|
+
return await this.pipelineExecute(data);
|
|
34449
|
+
}
|
|
34450
|
+
async pipelineExecute(data) {
|
|
34398
34451
|
const instanceId = backendCore.newUuid();
|
|
34399
34452
|
const logMetadata = {
|
|
34400
34453
|
input: data.input,
|
|
@@ -34445,6 +34498,12 @@ class NestPipelineTemplate {
|
|
|
34445
34498
|
.resolveAuthenticationContextProvider();
|
|
34446
34499
|
return (await contextService?.getContext());
|
|
34447
34500
|
}
|
|
34501
|
+
get operationsLockService() {
|
|
34502
|
+
return this.registry
|
|
34503
|
+
.getContainer()
|
|
34504
|
+
.getEntitiesServicesLocator()
|
|
34505
|
+
.resolveOperationLockService();
|
|
34506
|
+
}
|
|
34448
34507
|
get controller() {
|
|
34449
34508
|
return this.registry
|
|
34450
34509
|
.getContainer()
|
|
@@ -43764,6 +43823,7 @@ exports.EntityOperationUnauthorizedException = EntityOperationUnauthorizedExcept
|
|
|
43764
43823
|
exports.EntitySeeder = EntitySeeder;
|
|
43765
43824
|
exports.EntitySerializer = EntitySerializer;
|
|
43766
43825
|
exports.EntitySnapshotService = EntitySnapshotService;
|
|
43826
|
+
exports.ExclusiveOperationResult = ExclusiveOperationResult;
|
|
43767
43827
|
exports.IEntityVersionsCursor = IEntityVersionsCursor;
|
|
43768
43828
|
exports.InvalidCredentialsError = InvalidCredentialsError;
|
|
43769
43829
|
exports.JobInstance = JobInstance;
|