@punks/backend-entity-manager 0.0.326 → 0.0.328
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 +67 -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 +67 -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);
|
|
@@ -23181,6 +23195,7 @@ exports.EntityManagerInitializer = EntityManagerInitializer_1 = class EntityMana
|
|
|
23181
23195
|
await this.registerBucketProviders();
|
|
23182
23196
|
await this.registerSecretsProviders();
|
|
23183
23197
|
await this.registerCacheInstances();
|
|
23198
|
+
await this.registerOperationLockService();
|
|
23184
23199
|
await this.executeInitializers(app);
|
|
23185
23200
|
await this.executeSeeders();
|
|
23186
23201
|
this.logger.log("Entity manager initialization completed 🚀");
|
|
@@ -23458,6 +23473,18 @@ exports.EntityManagerInitializer = EntityManagerInitializer_1 = class EntityMana
|
|
|
23458
23473
|
.getEntitiesServicesLocator()
|
|
23459
23474
|
.registerEmailTemplatesCollection(collection);
|
|
23460
23475
|
}
|
|
23476
|
+
async registerOperationLockService() {
|
|
23477
|
+
const operationLockServices = await this.discoverOperationLockService();
|
|
23478
|
+
if (!operationLockServices.length) {
|
|
23479
|
+
this.logger.warn("No operation lock services found ⚠️");
|
|
23480
|
+
return;
|
|
23481
|
+
}
|
|
23482
|
+
this.registry
|
|
23483
|
+
.getContainer()
|
|
23484
|
+
.getEntitiesServicesLocator()
|
|
23485
|
+
.registerOperationLockService(operationLockServices[0].discoveredClass
|
|
23486
|
+
.instance);
|
|
23487
|
+
}
|
|
23461
23488
|
async registerPipelinesServices() {
|
|
23462
23489
|
this.registry
|
|
23463
23490
|
.getContainer()
|
|
@@ -23523,6 +23550,9 @@ exports.EntityManagerInitializer = EntityManagerInitializer_1 = class EntityMana
|
|
|
23523
23550
|
async discoverEmailLogger() {
|
|
23524
23551
|
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.EmailLogger);
|
|
23525
23552
|
}
|
|
23553
|
+
async discoverOperationLockService() {
|
|
23554
|
+
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.OperationLockService);
|
|
23555
|
+
}
|
|
23526
23556
|
async discoverBucketProviders() {
|
|
23527
23557
|
return await this.discover.providersWithMetaAtKey(EntityManagerSymbols.BucketProvider);
|
|
23528
23558
|
}
|
|
@@ -34377,13 +34407,17 @@ class PipelineUtils {
|
|
|
34377
34407
|
}
|
|
34378
34408
|
|
|
34379
34409
|
class NestPipelineTemplate {
|
|
34380
|
-
constructor() {
|
|
34410
|
+
constructor(options) {
|
|
34411
|
+
this.options = options;
|
|
34381
34412
|
this.logger = backendCore.Log.getLogger(NestPipelineTemplate.name);
|
|
34382
34413
|
this.utils = new PipelineUtils();
|
|
34383
34414
|
}
|
|
34384
34415
|
isAuthorized(context) {
|
|
34385
34416
|
return true;
|
|
34386
34417
|
}
|
|
34418
|
+
getConcurrencyKey(input) {
|
|
34419
|
+
return this.constructor.name;
|
|
34420
|
+
}
|
|
34387
34421
|
async invoke(input) {
|
|
34388
34422
|
const result = await this.execute({
|
|
34389
34423
|
input,
|
|
@@ -34395,6 +34429,26 @@ class NestPipelineTemplate {
|
|
|
34395
34429
|
return result.output;
|
|
34396
34430
|
}
|
|
34397
34431
|
async execute(data) {
|
|
34432
|
+
if (this.options?.concurrency === "sequential") {
|
|
34433
|
+
return await this.operationsLockService.executeSequential({
|
|
34434
|
+
lockUid: this.getConcurrencyKey(data.input),
|
|
34435
|
+
operation: async () => {
|
|
34436
|
+
return await this.pipelineExecute(data);
|
|
34437
|
+
},
|
|
34438
|
+
});
|
|
34439
|
+
}
|
|
34440
|
+
if (this.options?.concurrency === "exclusive") {
|
|
34441
|
+
const result = await this.operationsLockService.executeExclusive({
|
|
34442
|
+
lockUid: this.getConcurrencyKey(data.input),
|
|
34443
|
+
operation: async () => {
|
|
34444
|
+
return await this.pipelineExecute(data);
|
|
34445
|
+
},
|
|
34446
|
+
});
|
|
34447
|
+
return result.result;
|
|
34448
|
+
}
|
|
34449
|
+
return await this.pipelineExecute(data);
|
|
34450
|
+
}
|
|
34451
|
+
async pipelineExecute(data) {
|
|
34398
34452
|
const instanceId = backendCore.newUuid();
|
|
34399
34453
|
const logMetadata = {
|
|
34400
34454
|
input: data.input,
|
|
@@ -34445,6 +34499,12 @@ class NestPipelineTemplate {
|
|
|
34445
34499
|
.resolveAuthenticationContextProvider();
|
|
34446
34500
|
return (await contextService?.getContext());
|
|
34447
34501
|
}
|
|
34502
|
+
get operationsLockService() {
|
|
34503
|
+
return this.registry
|
|
34504
|
+
.getContainer()
|
|
34505
|
+
.getEntitiesServicesLocator()
|
|
34506
|
+
.resolveOperationLockService();
|
|
34507
|
+
}
|
|
34448
34508
|
get controller() {
|
|
34449
34509
|
return this.registry
|
|
34450
34510
|
.getContainer()
|
|
@@ -43764,6 +43824,7 @@ exports.EntityOperationUnauthorizedException = EntityOperationUnauthorizedExcept
|
|
|
43764
43824
|
exports.EntitySeeder = EntitySeeder;
|
|
43765
43825
|
exports.EntitySerializer = EntitySerializer;
|
|
43766
43826
|
exports.EntitySnapshotService = EntitySnapshotService;
|
|
43827
|
+
exports.ExclusiveOperationResult = ExclusiveOperationResult;
|
|
43767
43828
|
exports.IEntityVersionsCursor = IEntityVersionsCursor;
|
|
43768
43829
|
exports.InvalidCredentialsError = InvalidCredentialsError;
|
|
43769
43830
|
exports.JobInstance = JobInstance;
|