@punks/backend-entity-manager 0.0.260 → 0.0.261
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 +52 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/esm/index.js +54 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/platforms/nest/services/index.d.ts +1 -1
- package/dist/index.d.ts +16 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -21914,6 +21914,58 @@ exports.OperationLockService = __decorate([
|
|
|
21914
21914
|
__metadata("design:paramtypes", [Object])
|
|
21915
21915
|
], exports.OperationLockService);
|
|
21916
21916
|
|
|
21917
|
+
exports.TypeormOperationLockRepository = class TypeormOperationLockRepository {
|
|
21918
|
+
constructor(repo, entityClass) {
|
|
21919
|
+
this.repo = repo;
|
|
21920
|
+
this.entityClass = entityClass;
|
|
21921
|
+
// todo: fix typing (and remove as any)
|
|
21922
|
+
this.get = async (lockUid) => (await this.repo.findOne({
|
|
21923
|
+
where: {
|
|
21924
|
+
uid: lockUid,
|
|
21925
|
+
},
|
|
21926
|
+
})) ?? undefined;
|
|
21927
|
+
this.acquire = async (input) => {
|
|
21928
|
+
return await this.repo.manager.transaction(async (manager) => {
|
|
21929
|
+
const currentLock = await manager.findOne(this.entityClass, {
|
|
21930
|
+
where: [
|
|
21931
|
+
{
|
|
21932
|
+
uid: input.lockUid,
|
|
21933
|
+
},
|
|
21934
|
+
],
|
|
21935
|
+
});
|
|
21936
|
+
if (currentLock) {
|
|
21937
|
+
return {
|
|
21938
|
+
available: false,
|
|
21939
|
+
lockItem: currentLock,
|
|
21940
|
+
};
|
|
21941
|
+
}
|
|
21942
|
+
const newLock = manager.create(this.entityClass, {
|
|
21943
|
+
id: backendCore.newUuid(),
|
|
21944
|
+
uid: input.lockUid,
|
|
21945
|
+
lockedBy: input.requestedBy,
|
|
21946
|
+
});
|
|
21947
|
+
await manager.save([newLock]);
|
|
21948
|
+
return {
|
|
21949
|
+
available: true,
|
|
21950
|
+
lockItem: newLock,
|
|
21951
|
+
};
|
|
21952
|
+
});
|
|
21953
|
+
};
|
|
21954
|
+
this.release = async (input) => {
|
|
21955
|
+
const result = await this.repo.delete({
|
|
21956
|
+
uid: input.lockUid,
|
|
21957
|
+
});
|
|
21958
|
+
if (result.affected === 0) {
|
|
21959
|
+
throw new LockNotFoundError(`Lock ${input.lockUid} was not found`);
|
|
21960
|
+
}
|
|
21961
|
+
};
|
|
21962
|
+
}
|
|
21963
|
+
};
|
|
21964
|
+
exports.TypeormOperationLockRepository = __decorate([
|
|
21965
|
+
common.Injectable(),
|
|
21966
|
+
__metadata("design:paramtypes", [typeorm.Repository, Object])
|
|
21967
|
+
], exports.TypeormOperationLockRepository);
|
|
21968
|
+
|
|
21917
21969
|
exports.EmailService = class EmailService {
|
|
21918
21970
|
constructor(registry) {
|
|
21919
21971
|
this.registry = registry;
|