@punks/backend-entity-manager 0.0.324 → 0.0.326
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 +41 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/pipelines/template/utils.d.ts +6 -6
- package/dist/cjs/types/platforms/nest/services/operations/operation-lock.service.d.ts +2 -2
- package/dist/cjs/types/platforms/nest/services/operations/types.d.ts +9 -0
- package/dist/esm/index.js +42 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/pipelines/template/utils.d.ts +6 -6
- package/dist/esm/types/platforms/nest/services/operations/operation-lock-execute-exclusive.spec.d.ts +1 -0
- package/dist/esm/types/platforms/nest/services/operations/operation-lock-execute-sequential.spec.d.ts +1 -0
- package/dist/esm/types/platforms/nest/services/operations/operation-lock.service.d.ts +2 -2
- package/dist/esm/types/platforms/nest/services/operations/types.d.ts +9 -0
- package/dist/index.d.ts +14 -7
- package/package.json +1 -1
- /package/dist/cjs/types/platforms/nest/services/operations/{operation-lock.service.spec.d.ts → operation-lock-execute-exclusive.spec.d.ts} +0 -0
- /package/dist/{esm/types/platforms/nest/services/operations/operation-lock.service.spec.d.ts → cjs/types/platforms/nest/services/operations/operation-lock-execute-sequential.spec.d.ts} +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -21962,10 +21962,37 @@ function subDays(dirtyDate, dirtyAmount) {
|
|
|
21962
21962
|
}
|
|
21963
21963
|
|
|
21964
21964
|
var OperationLockService_1;
|
|
21965
|
+
const DEFAULT_LOCK_POLLING = 100;
|
|
21965
21966
|
exports.OperationLockService = OperationLockService_1 = class OperationLockService {
|
|
21966
21967
|
constructor(operations) {
|
|
21967
21968
|
this.operations = operations;
|
|
21968
21969
|
this.logger = backendCore.Log.getLogger(OperationLockService_1.name);
|
|
21970
|
+
this.executeSequential = async (input) => {
|
|
21971
|
+
const lock = await this.operations.acquireLock({
|
|
21972
|
+
lockUid: input.lockUid,
|
|
21973
|
+
requestedBy: input.requestedBy,
|
|
21974
|
+
});
|
|
21975
|
+
if (!lock.available &&
|
|
21976
|
+
input.lockTimeout &&
|
|
21977
|
+
this.isLockExpired(lock.lockItem, new Date(), input.lockTimeout)) {
|
|
21978
|
+
await this.operations.releaseLock({
|
|
21979
|
+
lockUid: input.lockUid,
|
|
21980
|
+
});
|
|
21981
|
+
return await this.executeSequential(input);
|
|
21982
|
+
}
|
|
21983
|
+
if (!lock.available) {
|
|
21984
|
+
await backendCore.sleep(input.lockPolling ?? DEFAULT_LOCK_POLLING);
|
|
21985
|
+
return await this.executeSequential(input);
|
|
21986
|
+
}
|
|
21987
|
+
try {
|
|
21988
|
+
return await input.operation();
|
|
21989
|
+
}
|
|
21990
|
+
finally {
|
|
21991
|
+
await this.operations.releaseLock({
|
|
21992
|
+
lockUid: input.lockUid,
|
|
21993
|
+
});
|
|
21994
|
+
}
|
|
21995
|
+
};
|
|
21969
21996
|
this.executeExclusive = async (input) => {
|
|
21970
21997
|
const lock = await this.operations.acquireLock({
|
|
21971
21998
|
lockUid: input.lockUid,
|
|
@@ -21988,7 +22015,7 @@ exports.OperationLockService = OperationLockService_1 = class OperationLockServi
|
|
|
21988
22015
|
try {
|
|
21989
22016
|
return {
|
|
21990
22017
|
skipped: false,
|
|
21991
|
-
result: await
|
|
22018
|
+
result: await input.operation(),
|
|
21992
22019
|
};
|
|
21993
22020
|
}
|
|
21994
22021
|
finally {
|
|
@@ -21997,9 +22024,6 @@ exports.OperationLockService = OperationLockService_1 = class OperationLockServi
|
|
|
21997
22024
|
});
|
|
21998
22025
|
}
|
|
21999
22026
|
};
|
|
22000
|
-
this.executeOperation = async (input) => {
|
|
22001
|
-
return await input.operation();
|
|
22002
|
-
};
|
|
22003
22027
|
this.isLockExpired = (item, refDate, timeoutMinutes) => {
|
|
22004
22028
|
return differenceInMinutes(refDate, item.createdOn) > timeoutMinutes;
|
|
22005
22029
|
};
|
|
@@ -23546,6 +23570,7 @@ class PipelineStepOperationOptionsBuilder {
|
|
|
23546
23570
|
}
|
|
23547
23571
|
build() {
|
|
23548
23572
|
return {
|
|
23573
|
+
key: this.operation.key,
|
|
23549
23574
|
name: this.operation.name,
|
|
23550
23575
|
operation: this.operation,
|
|
23551
23576
|
rollbackOperations: this.rollbackOperations,
|
|
@@ -34321,32 +34346,32 @@ const buildCompletedStepsSequence = (step) => {
|
|
|
34321
34346
|
};
|
|
34322
34347
|
class PipelineUtils {
|
|
34323
34348
|
constructor() {
|
|
34324
|
-
this.getStepByKey = (
|
|
34325
|
-
const sequence = buildCompletedStepsSequence(
|
|
34349
|
+
this.getStepByKey = (state, key) => {
|
|
34350
|
+
const sequence = buildCompletedStepsSequence(state);
|
|
34326
34351
|
const matchingStep = sequence.find((x) => x.reference.key === key);
|
|
34327
34352
|
if (!matchingStep) {
|
|
34328
34353
|
throw new Error(`Step key ${key} not found`);
|
|
34329
34354
|
}
|
|
34330
34355
|
return matchingStep;
|
|
34331
34356
|
};
|
|
34332
|
-
this.getStepInputByKey = (
|
|
34333
|
-
return this.getStepByKey(
|
|
34357
|
+
this.getStepInputByKey = (state, key) => {
|
|
34358
|
+
return this.getStepByKey(state, key).stepInput;
|
|
34334
34359
|
};
|
|
34335
|
-
this.getStepOutputByKey = (
|
|
34336
|
-
return this.getStepByKey(
|
|
34360
|
+
this.getStepOutputByKey = (state, key) => {
|
|
34361
|
+
return this.getStepByKey(state, key).stepOutput;
|
|
34337
34362
|
};
|
|
34338
|
-
this.getStep = (
|
|
34339
|
-
const sequence = buildCompletedStepsSequence(
|
|
34363
|
+
this.getStep = (state, index) => {
|
|
34364
|
+
const sequence = buildCompletedStepsSequence(state);
|
|
34340
34365
|
if (index >= sequence.length) {
|
|
34341
34366
|
throw new Error(`Step index ${index} is out of range`);
|
|
34342
34367
|
}
|
|
34343
34368
|
return sequence[index];
|
|
34344
34369
|
};
|
|
34345
|
-
this.getStepInput = (
|
|
34346
|
-
return this.getStep(
|
|
34370
|
+
this.getStepInput = (state, index) => {
|
|
34371
|
+
return this.getStep(state, index).stepInput;
|
|
34347
34372
|
};
|
|
34348
|
-
this.getStepOutput = (
|
|
34349
|
-
return this.getStep(
|
|
34373
|
+
this.getStepOutput = (state, index) => {
|
|
34374
|
+
return this.getStep(state, index).stepOutput;
|
|
34350
34375
|
};
|
|
34351
34376
|
}
|
|
34352
34377
|
}
|