@webiny/api-record-locking 6.3.0 → 6.4.0-beta.0
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/domain/LockRecord.js +63 -70
- package/domain/LockRecord.js.map +1 -1
- package/domain/RecordLockingModel.js +26 -23
- package/domain/RecordLockingModel.js.map +1 -1
- package/domain/abstractions.js +3 -7
- package/domain/abstractions.js.map +1 -1
- package/domain/calculateExpiresOn.js +5 -6
- package/domain/calculateExpiresOn.js.map +1 -1
- package/domain/errors.js +71 -81
- package/domain/errors.js.map +1 -1
- package/domain/index.js +0 -2
- package/domain/types.js +6 -9
- package/domain/types.js.map +1 -1
- package/features/GetLockRecord/GetLockRecordRepository.js +27 -24
- package/features/GetLockRecord/GetLockRecordRepository.js.map +1 -1
- package/features/GetLockRecord/GetLockRecordUseCase.js +13 -10
- package/features/GetLockRecord/GetLockRecordUseCase.js.map +1 -1
- package/features/GetLockRecord/abstractions.js +3 -14
- package/features/GetLockRecord/abstractions.js.map +1 -1
- package/features/GetLockRecord/feature.js +7 -6
- package/features/GetLockRecord/feature.js.map +1 -1
- package/features/GetLockRecord/index.js +0 -2
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +19 -28
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -1
- package/features/GetLockedEntryLockRecord/abstractions.js +2 -10
- package/features/GetLockedEntryLockRecord/abstractions.js.map +1 -1
- package/features/GetLockedEntryLockRecord/feature.js +6 -5
- package/features/GetLockedEntryLockRecord/feature.js.map +1 -1
- package/features/GetLockedEntryLockRecord/index.js +0 -2
- package/features/IsEntryLocked/IsEntryLockedUseCase.js +22 -28
- package/features/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -1
- package/features/IsEntryLocked/abstractions.js +2 -9
- package/features/IsEntryLocked/abstractions.js.map +1 -1
- package/features/IsEntryLocked/feature.js +6 -5
- package/features/IsEntryLocked/feature.js.map +1 -1
- package/features/IsEntryLocked/index.js +0 -2
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +32 -32
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -1
- package/features/KickOutCurrentUser/abstractions.js +2 -6
- package/features/KickOutCurrentUser/abstractions.js.map +1 -1
- package/features/KickOutCurrentUser/feature.js +6 -5
- package/features/KickOutCurrentUser/feature.js.map +1 -1
- package/features/KickOutCurrentUser/index.js +0 -2
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +31 -31
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js.map +1 -1
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js +13 -10
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js.map +1 -1
- package/features/ListAllLockRecords/abstractions.js +3 -14
- package/features/ListAllLockRecords/abstractions.js.map +1 -1
- package/features/ListAllLockRecords/feature.js +7 -6
- package/features/ListAllLockRecords/feature.js.map +1 -1
- package/features/ListAllLockRecords/index.js +0 -2
- package/features/ListLockRecords/ListLockRecordsRepository.js +31 -31
- package/features/ListLockRecords/ListLockRecordsRepository.js.map +1 -1
- package/features/ListLockRecords/ListLockRecordsUseCase.js +26 -23
- package/features/ListLockRecords/ListLockRecordsUseCase.js.map +1 -1
- package/features/ListLockRecords/abstractions.js +3 -14
- package/features/ListLockRecords/abstractions.js.map +1 -1
- package/features/ListLockRecords/feature.js +7 -6
- package/features/ListLockRecords/feature.js.map +1 -1
- package/features/ListLockRecords/index.js +0 -2
- package/features/LockEntry/LockEntryEventsDecorator.js +31 -31
- package/features/LockEntry/LockEntryEventsDecorator.js.map +1 -1
- package/features/LockEntry/LockEntryRepository.js +33 -30
- package/features/LockEntry/LockEntryRepository.js.map +1 -1
- package/features/LockEntry/LockEntryUseCase.js +21 -26
- package/features/LockEntry/LockEntryUseCase.js.map +1 -1
- package/features/LockEntry/abstractions.js +3 -14
- package/features/LockEntry/abstractions.js.map +1 -1
- package/features/LockEntry/events.js +25 -33
- package/features/LockEntry/events.js.map +1 -1
- package/features/LockEntry/feature.js +8 -7
- package/features/LockEntry/feature.js.map +1 -1
- package/features/LockEntry/index.js +0 -2
- package/features/RecordLockingFeature.js +19 -21
- package/features/RecordLockingFeature.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +32 -32
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryRepository.js +29 -27
- package/features/UnlockEntry/UnlockEntryRepository.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryUseCase.js +53 -69
- package/features/UnlockEntry/UnlockEntryUseCase.js.map +1 -1
- package/features/UnlockEntry/abstractions.js +3 -14
- package/features/UnlockEntry/abstractions.js.map +1 -1
- package/features/UnlockEntry/events.js +25 -33
- package/features/UnlockEntry/events.js.map +1 -1
- package/features/UnlockEntry/feature.js +8 -7
- package/features/UnlockEntry/feature.js.map +1 -1
- package/features/UnlockEntry/hasFullAccessPermission.js +6 -7
- package/features/UnlockEntry/hasFullAccessPermission.js.map +1 -1
- package/features/UnlockEntry/index.js +0 -2
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js +31 -31
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js.map +1 -1
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +31 -30
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js.map +1 -1
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js +62 -79
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js.map +1 -1
- package/features/UnlockEntryRequest/abstractions.js +3 -14
- package/features/UnlockEntryRequest/abstractions.js.map +1 -1
- package/features/UnlockEntryRequest/events.js +25 -33
- package/features/UnlockEntryRequest/events.js.map +1 -1
- package/features/UnlockEntryRequest/feature.js +8 -7
- package/features/UnlockEntryRequest/feature.js.map +1 -1
- package/features/UnlockEntryRequest/index.js +0 -2
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +45 -48
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js.map +1 -1
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js +40 -51
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -1
- package/features/UpdateEntryLock/abstractions.js +3 -14
- package/features/UpdateEntryLock/abstractions.js.map +1 -1
- package/features/UpdateEntryLock/feature.js +7 -6
- package/features/UpdateEntryLock/feature.js.map +1 -1
- package/features/UpdateEntryLock/index.js +0 -2
- package/graphql/checkPermissions.js +5 -9
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/resolve.js +15 -17
- package/graphql/resolve.js.map +1 -1
- package/graphql/schema.js +147 -165
- package/graphql/schema.js.map +1 -1
- package/index.js +40 -49
- package/index.js.map +1 -1
- package/package.json +17 -17
- package/types.js +6 -9
- package/types.js.map +1 -1
- package/utils/convertWhereCondition.js +20 -32
- package/utils/convertWhereCondition.js.map +1 -1
- package/utils/getTimeout.js +8 -15
- package/utils/getTimeout.js.map +1 -1
- package/utils/lockRecordDatabaseId.js +6 -11
- package/utils/lockRecordDatabaseId.js.map +1 -1
- package/domain/index.js.map +0 -1
- package/features/GetLockRecord/index.js.map +0 -1
- package/features/GetLockedEntryLockRecord/index.js.map +0 -1
- package/features/IsEntryLocked/index.js.map +0 -1
- package/features/KickOutCurrentUser/index.js.map +0 -1
- package/features/ListAllLockRecords/index.js.map +0 -1
- package/features/ListLockRecords/index.js.map +0 -1
- package/features/LockEntry/index.js.map +0 -1
- package/features/UnlockEntry/index.js.map +0 -1
- package/features/UnlockEntryRequest/index.js.map +0 -1
- package/features/UpdateEntryLock/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/LockEntryEventsDecorator.js","sources":["../../../src/features/LockEntry/LockEntryEventsDecorator.ts"],"sourcesContent":["import {\n type LockEntryInput,\n LockEntryUseCase as UseCaseAbstraction,\n LockEntryUseCase\n} from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { ILockRecord } from \"~/domain/index.js\";\nimport { Result } from \"@webiny/feature/api/index.js\";\nimport { EntryAfterLockEvent, EntryBeforeLockEvent, EntryLockErrorEvent } from \"./events.js\";\n\nclass LockEntryErrorDecoratorImpl implements LockEntryUseCase.Interface {\n constructor(\n private readonly eventPublisher: EventPublisher.Interface,\n private readonly decoratee: LockEntryUseCase.Interface\n ) {}\n async execute(input: LockEntryInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Publish before event\n await this.eventPublisher.publish(\n new EntryBeforeLockEvent({\n id: input.id,\n type: input.type\n })\n );\n\n const result = await this.decoratee.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n\n await this.eventPublisher.publish(\n new EntryLockErrorEvent({\n id: input.id,\n type: input.type,\n error\n })\n );\n\n return result;\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new EntryAfterLockEvent({\n id: input.id,\n type: input.type,\n record: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const LockEntryEventsDecorator = LockEntryUseCase.createDecorator({\n decorator: LockEntryErrorDecoratorImpl,\n dependencies: [EventPublisher]\n});\n"],"names":["LockEntryErrorDecoratorImpl","eventPublisher","decoratee","input","EntryBeforeLockEvent","result","error","EntryLockErrorEvent","EntryAfterLockEvent","LockEntryEventsDecorator","LockEntryUseCase","EventPublisher"],"mappings":";;;AAUA,MAAMA;IACF,YACqBC,cAAwC,EACxCC,SAAqC,CACxD;aAFmBD,cAAc,GAAdA;aACAC,SAAS,GAATA;IAClB;IACH,MAAM,QAAQC,KAAqB,EAA0D;QAEzF,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YACrB,IAAID,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;QACpB;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QAE5C,IAAIE,OAAO,MAAM,IAAI;YACjB,MAAMC,QAAQD,OAAO,KAAK;YAE1B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,oBAAoB;gBACpB,IAAIJ,MAAM,EAAE;gBACZ,MAAMA,MAAM,IAAI;gBAChBG;YACJ;YAGJ,OAAOD;QACX;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,oBAAoB;YACpB,IAAIL,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;YAChB,QAAQE,OAAO,KAAK;QACxB;QAGJ,OAAOA;IACX;AACJ;AAEO,MAAMI,2BAA2BC,iBAAiB,eAAe,CAAC;IACrE,WAAWV;IACX,cAAc;QAACW;KAAe;AAClC"}
|
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { CreateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/CreateEntry";
|
|
3
|
-
import { LockEntryRepository
|
|
3
|
+
import { LockEntryRepository } from "./abstractions.js";
|
|
4
4
|
import { RecordLockingConfig, RecordLockingModel } from "../../domain/abstractions.js";
|
|
5
5
|
import { LockRecord } from "../../domain/LockRecord.js";
|
|
6
6
|
import { LockRecordPersistenceError } from "../../domain/errors.js";
|
|
7
7
|
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
8
8
|
class LockEntryRepositoryImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return Result.fail(new LockRecordPersistenceError(error));
|
|
9
|
+
constructor(model, config, createEntry){
|
|
10
|
+
this.model = model;
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.createEntry = createEntry;
|
|
13
|
+
}
|
|
14
|
+
async create(input) {
|
|
15
|
+
try {
|
|
16
|
+
const id = createLockRecordDatabaseId(input.id);
|
|
17
|
+
const values = {
|
|
18
|
+
targetId: input.id,
|
|
19
|
+
type: input.type,
|
|
20
|
+
actions: []
|
|
21
|
+
};
|
|
22
|
+
const result = await this.createEntry.execute(this.model, {
|
|
23
|
+
id,
|
|
24
|
+
values
|
|
25
|
+
});
|
|
26
|
+
if (result.isFail()) return Result.fail(new LockRecordPersistenceError(result.error));
|
|
27
|
+
const entry = result.value;
|
|
28
|
+
const lockRecord = new LockRecord(entry, this.config.timeout);
|
|
29
|
+
return Result.ok(lockRecord);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return Result.fail(new LockRecordPersistenceError(error));
|
|
32
|
+
}
|
|
34
33
|
}
|
|
35
|
-
}
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const LockEntryRepository_LockEntryRepository = LockEntryRepository.createImplementation({
|
|
36
|
+
implementation: LockEntryRepositoryImpl,
|
|
37
|
+
dependencies: [
|
|
38
|
+
RecordLockingModel,
|
|
39
|
+
RecordLockingConfig,
|
|
40
|
+
CreateEntryUseCase
|
|
41
|
+
]
|
|
40
42
|
});
|
|
43
|
+
export { LockEntryRepository_LockEntryRepository as LockEntryRepository };
|
|
41
44
|
|
|
42
45
|
//# sourceMappingURL=LockEntryRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/LockEntryRepository.js","sources":["../../../src/features/LockEntry/LockEntryRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { LockEntryInput, LockEntryRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/types.js\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\n\nclass LockEntryRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.Interface,\n private config: RecordLockingConfig.Interface,\n private createEntry: CreateEntryUseCase.Interface\n ) {}\n\n async create(input: LockEntryInput): Promise<Result<ILockRecord, RepositoryAbstraction.Error>> {\n try {\n const id = createLockRecordDatabaseId(input.id);\n\n const values: LockRecordValues = {\n targetId: input.id,\n type: input.type,\n actions: []\n };\n\n const result = await this.createEntry.execute(this.model, {\n id,\n values\n });\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n const entry = result.value as CmsEntry<LockRecordValues>;\n const lockRecord = new LockRecord(entry, this.config.timeout);\n\n return Result.ok(lockRecord);\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const LockEntryRepository = RepositoryAbstraction.createImplementation({\n implementation: LockEntryRepositoryImpl,\n dependencies: [RecordLockingModel, RecordLockingConfig, CreateEntryUseCase]\n});\n"],"names":["LockEntryRepositoryImpl","model","config","createEntry","input","id","createLockRecordDatabaseId","values","result","Result","LockRecordPersistenceError","entry","lockRecord","LockRecord","error","LockEntryRepository","RepositoryAbstraction","RecordLockingModel","RecordLockingConfig","CreateEntryUseCase"],"mappings":";;;;;;;AAWA,MAAMA;IACF,YACYC,KAAmC,EACnCC,MAAqC,EACrCC,WAAyC,CACnD;aAHUF,KAAK,GAALA;aACAC,MAAM,GAANA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,OAAOC,KAAqB,EAA6D;QAC3F,IAAI;YACA,MAAMC,KAAKC,2BAA2BF,MAAM,EAAE;YAE9C,MAAMG,SAA2B;gBAC7B,UAAUH,MAAM,EAAE;gBAClB,MAAMA,MAAM,IAAI;gBAChB,SAAS,EAAE;YACf;YAEA,MAAMI,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;gBACtDH;gBACAE;YACJ;YAEA,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAGlE,MAAMG,QAAQH,OAAO,KAAK;YAC1B,MAAMI,aAAa,IAAIC,WAAWF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5D,OAAOF,OAAO,EAAE,CAACG;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAOL,OAAO,IAAI,CAAC,IAAIC,2BAA2BI;QACtD;IACJ;AACJ;AAEO,MAAMC,0CAAsBC,oBAAAA,oBAA0C,CAAC;IAC1E,gBAAgBhB;IAChB,cAAc;QAACiB;QAAoBC;QAAqBC;KAAmB;AAC/E"}
|
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
2
|
+
import { LockEntryRepository, LockEntryUseCase } from "./abstractions.js";
|
|
3
3
|
import { IsEntryLockedUseCase } from "../IsEntryLocked/abstractions.js";
|
|
4
4
|
import { EntryAlreadyLockedError, LockEntryError } from "../../domain/errors.js";
|
|
5
5
|
class LockEntryUseCaseImpl {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
async execute(input) {
|
|
11
|
-
// Check if entry is already locked
|
|
12
|
-
const lockedResult = await this.isEntryLocked.execute(input);
|
|
13
|
-
if (lockedResult.isFail()) {
|
|
14
|
-
return Result.fail(lockedResult.error);
|
|
6
|
+
constructor(isEntryLocked, repository){
|
|
7
|
+
this.isEntryLocked = isEntryLocked;
|
|
8
|
+
this.repository = repository;
|
|
15
9
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
async execute(input) {
|
|
11
|
+
const lockedResult = await this.isEntryLocked.execute(input);
|
|
12
|
+
if (lockedResult.isFail()) return Result.fail(lockedResult.error);
|
|
13
|
+
if (lockedResult.value) return Result.fail(new EntryAlreadyLockedError({
|
|
14
|
+
id: input.id,
|
|
15
|
+
type: input.type
|
|
16
|
+
}));
|
|
17
|
+
const result = await this.repository.create(input);
|
|
18
|
+
if (result.isFail()) return Result.fail(new LockEntryError(result.error));
|
|
19
|
+
return Result.ok(result.value);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
// Create the lock
|
|
24
|
-
const result = await this.repository.create(input);
|
|
25
|
-
if (result.isFail()) {
|
|
26
|
-
return Result.fail(new LockEntryError(result.error));
|
|
27
|
-
}
|
|
28
|
-
return Result.ok(result.value);
|
|
29
|
-
}
|
|
30
21
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
const LockEntryUseCase_LockEntryUseCase = LockEntryUseCase.createImplementation({
|
|
23
|
+
implementation: LockEntryUseCaseImpl,
|
|
24
|
+
dependencies: [
|
|
25
|
+
IsEntryLockedUseCase,
|
|
26
|
+
LockEntryRepository
|
|
27
|
+
]
|
|
34
28
|
});
|
|
29
|
+
export { LockEntryUseCase_LockEntryUseCase as LockEntryUseCase };
|
|
35
30
|
|
|
36
31
|
//# sourceMappingURL=LockEntryUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/LockEntryUseCase.js","sources":["../../../src/features/LockEntry/LockEntryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n LockEntryUseCase as UseCaseAbstraction,\n LockEntryRepository,\n LockEntryInput\n} from \"./abstractions.js\";\nimport { IsEntryLockedUseCase } from \"../IsEntryLocked/abstractions.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport { EntryAlreadyLockedError, LockEntryError } from \"~/domain/errors.js\";\n\nclass LockEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private isEntryLocked: IsEntryLockedUseCase.Interface,\n private repository: LockEntryRepository.Interface\n ) {}\n\n async execute(input: LockEntryInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Check if entry is already locked\n const lockedResult = await this.isEntryLocked.execute(input);\n\n if (lockedResult.isFail()) {\n return Result.fail(lockedResult.error);\n }\n\n if (lockedResult.value) {\n return Result.fail(new EntryAlreadyLockedError({ id: input.id, type: input.type }));\n }\n\n // Create the lock\n const result = await this.repository.create(input);\n\n if (result.isFail()) {\n return Result.fail(new LockEntryError(result.error));\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const LockEntryUseCase = UseCaseAbstraction.createImplementation({\n implementation: LockEntryUseCaseImpl,\n dependencies: [IsEntryLockedUseCase, LockEntryRepository]\n});\n"],"names":["LockEntryUseCaseImpl","isEntryLocked","repository","input","lockedResult","Result","EntryAlreadyLockedError","result","LockEntryError","LockEntryUseCase","UseCaseAbstraction","IsEntryLockedUseCase","LockEntryRepository"],"mappings":";;;;AAUA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,UAAyC,CACnD;aAFUD,aAAa,GAAbA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAqB,EAA0D;QAEzF,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAEtD,IAAIC,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAGzC,IAAIA,aAAa,KAAK,EAClB,OAAOC,OAAO,IAAI,CAAC,IAAIC,wBAAwB;YAAE,IAAIH,MAAM,EAAE;YAAE,MAAMA,MAAM,IAAI;QAAC;QAIpF,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAAC,IAAIG,eAAeD,OAAO,KAAK;QAGtD,OAAOF,OAAO,EAAE,CAACE,OAAO,KAAK;IACjC;AACJ;AAEO,MAAME,oCAAmBC,iBAAAA,oBAAuC,CAAC;IACpE,gBAAgBV;IAChB,cAAc;QAACW;QAAsBC;KAAoB;AAC7D"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* LockEntry Use Case - Creates a lock on an entry
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const LockEntryUseCase = createAbstraction("LockEntryUseCase");
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* LockEntryRepository - Creates lock record in storage
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const LockEntryRepository = createAbstraction("LockEntryRepository");
|
|
2
|
+
const LockEntryUseCase = createAbstraction("LockEntryUseCase");
|
|
3
|
+
const LockEntryRepository = createAbstraction("LockEntryRepository");
|
|
4
|
+
export { LockEntryRepository, LockEntryUseCase };
|
|
16
5
|
|
|
17
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/abstractions.js","sources":["../../../src/features/LockEntry/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordEntryType } from \"~/domain/types.js\";\nimport type {\n EntryAlreadyLockedError,\n LockEntryError,\n LockRecordPersistenceError\n} from \"~/domain/errors.js\";\n\n// Input types\nexport interface LockEntryInput {\n id: string;\n type: LockRecordEntryType;\n}\n\n/**\n * LockEntry Use Case - Creates a lock on an entry\n */\nexport interface ILockEntryUseCase {\n execute(input: LockEntryInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface ILockEntryUseCaseErrors {\n alreadyLocked: EntryAlreadyLockedError;\n persistence: LockRecordPersistenceError;\n lockError: LockEntryError;\n}\n\ntype UseCaseError = ILockEntryUseCaseErrors[keyof ILockEntryUseCaseErrors];\n\nexport const LockEntryUseCase = createAbstraction<ILockEntryUseCase>(\"LockEntryUseCase\");\n\nexport namespace LockEntryUseCase {\n export type Interface = ILockEntryUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * LockEntryRepository - Creates lock record in storage\n */\nexport interface ILockEntryRepository {\n create(input: LockEntryInput): Promise<Result<ILockRecord, RepositoryError>>;\n}\n\nexport interface ILockEntryRepositoryErrors {\n persistence: LockRecordPersistenceError;\n}\n\ntype RepositoryError = ILockEntryRepositoryErrors[keyof ILockEntryRepositoryErrors];\n\nexport const LockEntryRepository = createAbstraction<ILockEntryRepository>(\"LockEntryRepository\");\n\nexport namespace LockEntryRepository {\n export type Interface = ILockEntryRepository;\n export type Error = RepositoryError;\n}\n"],"names":["LockEntryUseCase","createAbstraction","LockEntryRepository"],"mappings":";AA+BO,MAAMA,mBAAmBC,kBAAqC;AAoB9D,MAAMC,sBAAsBD,kBAAwC"}
|
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getHandlerAbstraction() {
|
|
11
|
-
return EntryBeforeLockEventHandler;
|
|
12
|
-
}
|
|
3
|
+
class EntryBeforeLockEvent extends DomainEvent {
|
|
4
|
+
getHandlerAbstraction() {
|
|
5
|
+
return EntryBeforeLockEventHandler;
|
|
6
|
+
}
|
|
7
|
+
constructor(...args){
|
|
8
|
+
super(...args), this.eventType = "RecordLocking/Entry/BeforeLock";
|
|
9
|
+
}
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
getHandlerAbstraction() {
|
|
23
|
-
return EntryAfterLockEventHandler;
|
|
24
|
-
}
|
|
11
|
+
const EntryBeforeLockEventHandler = createAbstraction("EntryBeforeLockEventHandler");
|
|
12
|
+
class EntryAfterLockEvent extends DomainEvent {
|
|
13
|
+
getHandlerAbstraction() {
|
|
14
|
+
return EntryAfterLockEventHandler;
|
|
15
|
+
}
|
|
16
|
+
constructor(...args){
|
|
17
|
+
super(...args), this.eventType = "RecordLocking/Entry/AfterLock";
|
|
18
|
+
}
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
getHandlerAbstraction() {
|
|
35
|
-
return EntryLockErrorEventHandler;
|
|
36
|
-
}
|
|
20
|
+
const EntryAfterLockEventHandler = createAbstraction("EntryAfterLockEventHandler");
|
|
21
|
+
class EntryLockErrorEvent extends DomainEvent {
|
|
22
|
+
getHandlerAbstraction() {
|
|
23
|
+
return EntryLockErrorEventHandler;
|
|
24
|
+
}
|
|
25
|
+
constructor(...args){
|
|
26
|
+
super(...args), this.eventType = "RecordLocking/Entry/LockError";
|
|
27
|
+
}
|
|
37
28
|
}
|
|
38
|
-
|
|
29
|
+
const EntryLockErrorEventHandler = createAbstraction("EntryLockErrorEventHandler");
|
|
30
|
+
export { EntryAfterLockEvent, EntryAfterLockEventHandler, EntryBeforeLockEvent, EntryBeforeLockEventHandler, EntryLockErrorEvent, EntryLockErrorEventHandler };
|
|
39
31
|
|
|
40
32
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/events.js","sources":["../../../src/features/LockEntry/events.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { DomainEvent } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { IEventHandler } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordEntryType } from \"~/domain/types.js\";\n\n// ============================================================================\n// EntryBeforeLock Event\n// ============================================================================\n\nexport interface EntryBeforeLockPayload {\n id: string;\n type: LockRecordEntryType;\n}\n\nexport class EntryBeforeLockEvent extends DomainEvent<EntryBeforeLockPayload> {\n eventType = \"RecordLocking/Entry/BeforeLock\" as const;\n\n getHandlerAbstraction() {\n return EntryBeforeLockEventHandler;\n }\n}\n\nexport const EntryBeforeLockEventHandler = createAbstraction<IEventHandler<EntryBeforeLockEvent>>(\n \"EntryBeforeLockEventHandler\"\n);\n\nexport namespace EntryBeforeLockEventHandler {\n export type Interface = IEventHandler<EntryBeforeLockEvent>;\n export type Event = EntryBeforeLockEvent;\n}\n\n// ============================================================================\n// EntryAfterLock Event\n// ============================================================================\n\nexport interface EntryAfterLockPayload {\n id: string;\n type: LockRecordEntryType;\n record: ILockRecord;\n}\n\nexport class EntryAfterLockEvent extends DomainEvent<EntryAfterLockPayload> {\n eventType = \"RecordLocking/Entry/AfterLock\" as const;\n\n getHandlerAbstraction() {\n return EntryAfterLockEventHandler;\n }\n}\n\nexport const EntryAfterLockEventHandler = createAbstraction<IEventHandler<EntryAfterLockEvent>>(\n \"EntryAfterLockEventHandler\"\n);\n\nexport namespace EntryAfterLockEventHandler {\n export type Interface = IEventHandler<EntryAfterLockEvent>;\n export type Event = EntryAfterLockEvent;\n}\n\n// ============================================================================\n// EntryLockError Event\n// ============================================================================\n\nexport interface EntryLockErrorPayload {\n id: string;\n type: LockRecordEntryType;\n error: Error;\n}\n\nexport class EntryLockErrorEvent extends DomainEvent<EntryLockErrorPayload> {\n eventType = \"RecordLocking/Entry/LockError\" as const;\n\n getHandlerAbstraction() {\n return EntryLockErrorEventHandler;\n }\n}\n\nexport const EntryLockErrorEventHandler = createAbstraction<IEventHandler<EntryLockErrorEvent>>(\n \"EntryLockErrorEventHandler\"\n);\n\nexport namespace EntryLockErrorEventHandler {\n export type Interface = IEventHandler<EntryLockErrorEvent>;\n export type Event = EntryLockErrorEvent;\n}\n"],"names":["EntryBeforeLockEvent","DomainEvent","EntryBeforeLockEventHandler","createAbstraction","EntryAfterLockEvent","EntryAfterLockEventHandler","EntryLockErrorEvent","EntryLockErrorEventHandler"],"mappings":";;AAeO,MAAMA,6BAA6BC;IAGtC,wBAAwB;QACpB,OAAOC;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,8BAA8BC,kBACvC;AAkBG,MAAMC,4BAA4BH;IAGrC,wBAAwB;QACpB,OAAOI;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,6BAA6BF,kBACtC;AAkBG,MAAMG,4BAA4BL;IAGrC,wBAAwB;QACpB,OAAOM;IACX;;QALG,qBACH,SAAS,GAAG;;AAKhB;AAEO,MAAMA,6BAA6BJ,kBACtC"}
|
|
@@ -2,13 +2,14 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { LockEntryUseCase } from "./LockEntryUseCase.js";
|
|
3
3
|
import { LockEntryRepository } from "./LockEntryRepository.js";
|
|
4
4
|
import { LockEntryEventsDecorator } from "./LockEntryEventsDecorator.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const LockEntryFeature = createFeature({
|
|
6
|
+
name: "LockEntry",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(LockEntryUseCase);
|
|
9
|
+
container.register(LockEntryRepository).inSingletonScope();
|
|
10
|
+
container.registerDecorator(LockEntryEventsDecorator);
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
|
+
export { LockEntryFeature };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/LockEntry/feature.js","sources":["../../../src/features/LockEntry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { LockEntryUseCase } from \"./LockEntryUseCase.js\";\nimport { LockEntryRepository } from \"./LockEntryRepository.js\";\nimport { LockEntryEventsDecorator } from \"./LockEntryEventsDecorator.js\";\n\nexport const LockEntryFeature = createFeature({\n name: \"LockEntry\",\n register(container) {\n container.register(LockEntryUseCase);\n container.register(LockEntryRepository).inSingletonScope();\n container.registerDecorator(LockEntryEventsDecorator);\n }\n});\n"],"names":["LockEntryFeature","createFeature","container","LockEntryUseCase","LockEntryRepository","LockEntryEventsDecorator"],"mappings":";;;;AAKO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,qBAAqB,gBAAgB;QACxDF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -10,27 +10,25 @@ import { LockEntryFeature } from "./LockEntry/feature.js";
|
|
|
10
10
|
import { UpdateEntryLockFeature } from "./UpdateEntryLock/feature.js";
|
|
11
11
|
import { UnlockEntryFeature } from "./UnlockEntry/feature.js";
|
|
12
12
|
import { UnlockEntryRequestFeature } from "./UnlockEntryRequest/feature.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
UnlockEntryFeature.register(container);
|
|
32
|
-
UnlockEntryRequestFeature.register(container);
|
|
33
|
-
}
|
|
13
|
+
const RecordLockingFeature = createFeature({
|
|
14
|
+
name: "RecordLockingManagement",
|
|
15
|
+
register (container, params) {
|
|
16
|
+
container.registerInstance(RecordLockingConfig, {
|
|
17
|
+
timeout: params.timeout
|
|
18
|
+
});
|
|
19
|
+
container.registerInstance(RecordLockingModel, params.model);
|
|
20
|
+
GetLockRecordFeature.register(container);
|
|
21
|
+
GetLockedEntryLockRecordFeature.register(container);
|
|
22
|
+
KickOutCurrentUserFeature.register(container);
|
|
23
|
+
ListLockRecordsFeature.register(container);
|
|
24
|
+
ListAllLockRecordsFeature.register(container);
|
|
25
|
+
IsEntryLockedFeature.register(container);
|
|
26
|
+
LockEntryFeature.register(container);
|
|
27
|
+
UpdateEntryLockFeature.register(container);
|
|
28
|
+
UnlockEntryFeature.register(container);
|
|
29
|
+
UnlockEntryRequestFeature.register(container);
|
|
30
|
+
}
|
|
34
31
|
});
|
|
32
|
+
export { RecordLockingFeature };
|
|
35
33
|
|
|
36
34
|
//# sourceMappingURL=RecordLockingFeature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/RecordLockingFeature.js","sources":["../../src/features/RecordLockingFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport { GetLockRecordFeature } from \"./GetLockRecord/feature.js\";\nimport { GetLockedEntryLockRecordFeature } from \"./GetLockedEntryLockRecord/feature.js\";\nimport { KickOutCurrentUserFeature } from \"./KickOutCurrentUser/feature.js\";\nimport { ListLockRecordsFeature } from \"./ListLockRecords/feature.js\";\nimport { ListAllLockRecordsFeature } from \"./ListAllLockRecords/feature.js\";\nimport { IsEntryLockedFeature } from \"./IsEntryLocked/feature.js\";\nimport { LockEntryFeature } from \"./LockEntry/feature.js\";\nimport { UpdateEntryLockFeature } from \"./UpdateEntryLock/feature.js\";\nimport { UnlockEntryFeature } from \"./UnlockEntry/feature.js\";\nimport { UnlockEntryRequestFeature } from \"./UnlockEntryRequest/feature.js\";\n\nexport interface RecordLockingParams {\n /**\n * Timeout in milliseconds after which a lock expires\n */\n timeout: number;\n /**\n * The CMS model for storing lock records\n */\n model: CmsModel;\n}\n\nexport const RecordLockingFeature = createFeature<RecordLockingParams>({\n name: \"RecordLockingManagement\",\n register(container, params) {\n // Register domain abstractions\n container.registerInstance(RecordLockingConfig, { timeout: params.timeout });\n container.registerInstance(RecordLockingModel, params.model);\n\n // Register all sub-features\n GetLockRecordFeature.register(container);\n GetLockedEntryLockRecordFeature.register(container);\n KickOutCurrentUserFeature.register(container);\n ListLockRecordsFeature.register(container);\n ListAllLockRecordsFeature.register(container);\n IsEntryLockedFeature.register(container);\n LockEntryFeature.register(container);\n UpdateEntryLockFeature.register(container);\n UnlockEntryFeature.register(container);\n UnlockEntryRequestFeature.register(container);\n }\n});\n"],"names":["RecordLockingFeature","createFeature","container","params","RecordLockingConfig","RecordLockingModel","GetLockRecordFeature","GetLockedEntryLockRecordFeature","KickOutCurrentUserFeature","ListLockRecordsFeature","ListAllLockRecordsFeature","IsEntryLockedFeature","LockEntryFeature","UpdateEntryLockFeature","UnlockEntryFeature","UnlockEntryRequestFeature"],"mappings":";;;;;;;;;;;;AAyBO,MAAMA,uBAAuBC,cAAmC;IACnE,MAAM;IACN,UAASC,SAAS,EAAEC,MAAM;QAEtBD,UAAU,gBAAgB,CAACE,qBAAqB;YAAE,SAASD,OAAO,OAAO;QAAC;QAC1ED,UAAU,gBAAgB,CAACG,oBAAoBF,OAAO,KAAK;QAG3DG,qBAAqB,QAAQ,CAACJ;QAC9BK,gCAAgC,QAAQ,CAACL;QACzCM,0BAA0B,QAAQ,CAACN;QACnCO,uBAAuB,QAAQ,CAACP;QAChCQ,0BAA0B,QAAQ,CAACR;QACnCS,qBAAqB,QAAQ,CAACT;QAC9BU,iBAAiB,QAAQ,CAACV;QAC1BW,uBAAuB,QAAQ,CAACX;QAChCY,mBAAmB,QAAQ,CAACZ;QAC5Ba,0BAA0B,QAAQ,CAACb;IACvC;AACJ"}
|
|
@@ -2,40 +2,40 @@ import { UnlockEntryUseCase } from "./abstractions.js";
|
|
|
2
2
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
3
3
|
import { EntryAfterUnlockEvent, EntryBeforeUnlockEvent, EntryUnlockErrorEvent } from "./events.js";
|
|
4
4
|
class UnlockEntryEventsDecoratorImpl {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
constructor(eventPublisher, decoratee){
|
|
6
|
+
this.eventPublisher = eventPublisher;
|
|
7
|
+
this.decoratee = decoratee;
|
|
8
|
+
}
|
|
9
|
+
async execute(input) {
|
|
10
|
+
await this.eventPublisher.publish(new EntryBeforeUnlockEvent({
|
|
11
|
+
id: input.id,
|
|
12
|
+
type: input.type,
|
|
13
|
+
force: input.force
|
|
14
|
+
}));
|
|
15
|
+
const result = await this.decoratee.execute(input);
|
|
16
|
+
if (result.isFail()) {
|
|
17
|
+
const error = result.error;
|
|
18
|
+
await this.eventPublisher.publish(new EntryUnlockErrorEvent({
|
|
19
|
+
id: input.id,
|
|
20
|
+
type: input.type,
|
|
21
|
+
error
|
|
22
|
+
}));
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
await this.eventPublisher.publish(new EntryAfterUnlockEvent({
|
|
26
|
+
id: input.id,
|
|
27
|
+
type: input.type,
|
|
28
|
+
record: result.value
|
|
29
|
+
}));
|
|
30
|
+
return result;
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
// Publish after event
|
|
28
|
-
await this.eventPublisher.publish(new EntryAfterUnlockEvent({
|
|
29
|
-
id: input.id,
|
|
30
|
-
type: input.type,
|
|
31
|
-
record: result.value
|
|
32
|
-
}));
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const UnlockEntryEventsDecorator = UnlockEntryUseCase.createDecorator({
|
|
34
|
+
decorator: UnlockEntryEventsDecoratorImpl,
|
|
35
|
+
dependencies: [
|
|
36
|
+
EventPublisher
|
|
37
|
+
]
|
|
39
38
|
});
|
|
39
|
+
export { UnlockEntryEventsDecorator };
|
|
40
40
|
|
|
41
41
|
//# sourceMappingURL=UnlockEntryEventsDecorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntry/UnlockEntryEventsDecorator.js","sources":["../../../src/features/UnlockEntry/UnlockEntryEventsDecorator.ts"],"sourcesContent":["import {\n type UnlockEntryInput,\n UnlockEntryUseCase as UseCaseAbstraction,\n UnlockEntryUseCase\n} from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { ILockRecord } from \"~/domain/index.js\";\nimport { Result } from \"@webiny/feature/api/index.js\";\nimport { EntryAfterUnlockEvent, EntryBeforeUnlockEvent, EntryUnlockErrorEvent } from \"./events.js\";\n\nclass UnlockEntryEventsDecoratorImpl implements UnlockEntryUseCase.Interface {\n constructor(\n private readonly eventPublisher: EventPublisher.Interface,\n private readonly decoratee: UnlockEntryUseCase.Interface\n ) {}\n\n async execute(input: UnlockEntryInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Publish before event\n await this.eventPublisher.publish(\n new EntryBeforeUnlockEvent({\n id: input.id,\n type: input.type,\n force: input.force\n })\n );\n\n const result = await this.decoratee.execute(input);\n\n if (result.isFail()) {\n const error = result.error;\n\n await this.eventPublisher.publish(\n new EntryUnlockErrorEvent({\n id: input.id,\n type: input.type,\n error\n })\n );\n\n return result;\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new EntryAfterUnlockEvent({\n id: input.id,\n type: input.type,\n record: result.value\n })\n );\n\n return result;\n }\n}\n\nexport const UnlockEntryEventsDecorator = UnlockEntryUseCase.createDecorator({\n decorator: UnlockEntryEventsDecoratorImpl,\n dependencies: [EventPublisher]\n});\n"],"names":["UnlockEntryEventsDecoratorImpl","eventPublisher","decoratee","input","EntryBeforeUnlockEvent","result","error","EntryUnlockErrorEvent","EntryAfterUnlockEvent","UnlockEntryEventsDecorator","UnlockEntryUseCase","EventPublisher"],"mappings":";;;AAUA,MAAMA;IACF,YACqBC,cAAwC,EACxCC,SAAuC,CAC1D;aAFmBD,cAAc,GAAdA;aACAC,SAAS,GAATA;IAClB;IAEH,MAAM,QAAQC,KAAuB,EAA0D;QAE3F,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,uBAAuB;YACvB,IAAID,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;YAChB,OAAOA,MAAM,KAAK;QACtB;QAGJ,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QAE5C,IAAIE,OAAO,MAAM,IAAI;YACjB,MAAMC,QAAQD,OAAO,KAAK;YAE1B,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtB,IAAIJ,MAAM,EAAE;gBACZ,MAAMA,MAAM,IAAI;gBAChBG;YACJ;YAGJ,OAAOD;QACX;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,sBAAsB;YACtB,IAAIL,MAAM,EAAE;YACZ,MAAMA,MAAM,IAAI;YAChB,QAAQE,OAAO,KAAK;QACxB;QAGJ,OAAOA;IACX;AACJ;AAEO,MAAMI,6BAA6BC,mBAAmB,eAAe,CAAC;IACzE,WAAWV;IACX,cAAc;QAACW;KAAe;AAClC"}
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry";
|
|
3
3
|
import { createIdentifier } from "@webiny/utils";
|
|
4
|
-
import { UnlockEntryRepository
|
|
4
|
+
import { UnlockEntryRepository } from "./abstractions.js";
|
|
5
5
|
import { RecordLockingModel } from "../../domain/abstractions.js";
|
|
6
6
|
import { LockRecordNotFoundError, UnlockEntryError } from "../../domain/errors.js";
|
|
7
7
|
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
8
8
|
class UnlockEntryRepositoryImpl {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
constructor(model, deleteEntry){
|
|
10
|
+
this.model = model;
|
|
11
|
+
this.deleteEntry = deleteEntry;
|
|
12
|
+
}
|
|
13
|
+
async delete(lockRecordId) {
|
|
14
|
+
try {
|
|
15
|
+
const entryId = createLockRecordDatabaseId(lockRecordId);
|
|
16
|
+
const id = createIdentifier({
|
|
17
|
+
id: entryId,
|
|
18
|
+
version: 1
|
|
19
|
+
});
|
|
20
|
+
const result = await this.deleteEntry.execute(this.model, id, {
|
|
21
|
+
permanently: true
|
|
22
|
+
});
|
|
23
|
+
if (result.isFail()) {
|
|
24
|
+
if ("Cms/Entry/NotFound" === result.error.code) return Result.fail(new LockRecordNotFoundError());
|
|
25
|
+
return Result.fail(new UnlockEntryError(result.error));
|
|
26
|
+
}
|
|
27
|
+
return Result.ok();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return Result.fail(new UnlockEntryError(error));
|
|
26
30
|
}
|
|
27
|
-
return Result.fail(new UnlockEntryError(result.error));
|
|
28
|
-
}
|
|
29
|
-
return Result.ok();
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return Result.fail(new UnlockEntryError(error));
|
|
32
31
|
}
|
|
33
|
-
}
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const UnlockEntryRepository_UnlockEntryRepository = UnlockEntryRepository.createImplementation({
|
|
34
|
+
implementation: UnlockEntryRepositoryImpl,
|
|
35
|
+
dependencies: [
|
|
36
|
+
RecordLockingModel,
|
|
37
|
+
DeleteEntryUseCase
|
|
38
|
+
]
|
|
38
39
|
});
|
|
40
|
+
export { UnlockEntryRepository_UnlockEntryRepository as UnlockEntryRepository };
|
|
39
41
|
|
|
40
42
|
//# sourceMappingURL=UnlockEntryRepository.js.map
|