@punks/backend-entity-manager 0.0.260 → 0.0.262
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 +59 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/services/operations/operation-lock.service.d.ts +1 -0
- package/dist/esm/index.js +61 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/services/operations/operation-lock.service.d.ts +1 -0
- package/dist/index.d.ts +17 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -21865,9 +21865,11 @@ function differenceInMinutes(dateLeft, dateRight, options) {
|
|
|
21865
21865
|
return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
|
|
21866
21866
|
}
|
|
21867
21867
|
|
|
21868
|
-
|
|
21868
|
+
var OperationLockService_1;
|
|
21869
|
+
exports.OperationLockService = OperationLockService_1 = class OperationLockService {
|
|
21869
21870
|
constructor(operations) {
|
|
21870
21871
|
this.operations = operations;
|
|
21872
|
+
this.logger = backendCore.Log.getLogger(OperationLockService_1.name);
|
|
21871
21873
|
this.executeExclusive = async (input) => {
|
|
21872
21874
|
const lock = await this.operations.acquire({
|
|
21873
21875
|
lockUid: input.lockUid,
|
|
@@ -21905,15 +21907,70 @@ exports.OperationLockService = class OperationLockService {
|
|
|
21905
21907
|
this.isLockExpired = (item, refDate, timeoutMinutes) => {
|
|
21906
21908
|
return differenceInMinutes(refDate, item.createdOn) > timeoutMinutes;
|
|
21907
21909
|
};
|
|
21910
|
+
if (!operations) {
|
|
21911
|
+
this.logger.warn(`Cannot resolve locks repository: ${getEntityManagerProviderToken("OperationsLockRepository")}`);
|
|
21912
|
+
}
|
|
21908
21913
|
}
|
|
21909
21914
|
};
|
|
21910
|
-
exports.OperationLockService = __decorate([
|
|
21915
|
+
exports.OperationLockService = OperationLockService_1 = __decorate([
|
|
21911
21916
|
common.Injectable(),
|
|
21912
21917
|
__param(0, common.Optional()),
|
|
21913
21918
|
__param(0, common.Inject(getEntityManagerProviderToken("OperationsLockRepository"))),
|
|
21914
21919
|
__metadata("design:paramtypes", [Object])
|
|
21915
21920
|
], exports.OperationLockService);
|
|
21916
21921
|
|
|
21922
|
+
exports.TypeormOperationLockRepository = class TypeormOperationLockRepository {
|
|
21923
|
+
constructor(repo, entityClass) {
|
|
21924
|
+
this.repo = repo;
|
|
21925
|
+
this.entityClass = entityClass;
|
|
21926
|
+
// todo: fix typing (and remove as any)
|
|
21927
|
+
this.get = async (lockUid) => (await this.repo.findOne({
|
|
21928
|
+
where: {
|
|
21929
|
+
uid: lockUid,
|
|
21930
|
+
},
|
|
21931
|
+
})) ?? undefined;
|
|
21932
|
+
this.acquire = async (input) => {
|
|
21933
|
+
return await this.repo.manager.transaction(async (manager) => {
|
|
21934
|
+
const currentLock = await manager.findOne(this.entityClass, {
|
|
21935
|
+
where: [
|
|
21936
|
+
{
|
|
21937
|
+
uid: input.lockUid,
|
|
21938
|
+
},
|
|
21939
|
+
],
|
|
21940
|
+
});
|
|
21941
|
+
if (currentLock) {
|
|
21942
|
+
return {
|
|
21943
|
+
available: false,
|
|
21944
|
+
lockItem: currentLock,
|
|
21945
|
+
};
|
|
21946
|
+
}
|
|
21947
|
+
const newLock = manager.create(this.entityClass, {
|
|
21948
|
+
id: backendCore.newUuid(),
|
|
21949
|
+
uid: input.lockUid,
|
|
21950
|
+
lockedBy: input.requestedBy,
|
|
21951
|
+
});
|
|
21952
|
+
await manager.save([newLock]);
|
|
21953
|
+
return {
|
|
21954
|
+
available: true,
|
|
21955
|
+
lockItem: newLock,
|
|
21956
|
+
};
|
|
21957
|
+
});
|
|
21958
|
+
};
|
|
21959
|
+
this.release = async (input) => {
|
|
21960
|
+
const result = await this.repo.delete({
|
|
21961
|
+
uid: input.lockUid,
|
|
21962
|
+
});
|
|
21963
|
+
if (result.affected === 0) {
|
|
21964
|
+
throw new LockNotFoundError(`Lock ${input.lockUid} was not found`);
|
|
21965
|
+
}
|
|
21966
|
+
};
|
|
21967
|
+
}
|
|
21968
|
+
};
|
|
21969
|
+
exports.TypeormOperationLockRepository = __decorate([
|
|
21970
|
+
common.Injectable(),
|
|
21971
|
+
__metadata("design:paramtypes", [typeorm.Repository, Object])
|
|
21972
|
+
], exports.TypeormOperationLockRepository);
|
|
21973
|
+
|
|
21917
21974
|
exports.EmailService = class EmailService {
|
|
21918
21975
|
constructor(registry) {
|
|
21919
21976
|
this.registry = registry;
|