@webiny/api-record-locking 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.e9333b3f0b
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/RecordLockingAppFeature.d.ts +11 -0
- package/RecordLockingAppFeature.js +20 -0
- package/RecordLockingAppFeature.js.map +1 -0
- package/domain/LockRecord.js +63 -70
- package/domain/LockRecord.js.map +1 -1
- package/domain/RecordLockingModel.js +27 -23
- package/domain/RecordLockingModel.js.map +1 -1
- package/domain/abstractions.d.ts +9 -3
- 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.d.ts +4 -3
- package/features/GetLockRecord/GetLockRecordRepository.js +33 -25
- 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.d.ts +3 -3
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +27 -33
- 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.d.ts +5 -3
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +39 -32
- 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.d.ts +6 -3
- package/features/ListLockRecords/ListLockRecordsRepository.js +39 -32
- 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.d.ts +4 -3
- package/features/LockEntry/LockEntryRepository.js +35 -31
- 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.d.ts +0 -5
- package/features/RecordLockingFeature.js +21 -22
- package/features/RecordLockingFeature.js.map +1 -1
- package/features/RecordLockingModelProvider.d.ts +18 -0
- package/features/RecordLockingModelProvider.js +22 -0
- package/features/RecordLockingModelProvider.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +32 -32
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -1
- package/features/UnlockEntry/UnlockEntryRepository.d.ts +3 -3
- package/features/UnlockEntry/UnlockEntryRepository.js +31 -28
- 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.d.ts +3 -3
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +33 -31
- 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.d.ts +4 -3
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +47 -49
- 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/RecordLockingGraphQLSchema.d.ts +25 -0
- package/graphql/RecordLockingGraphQLSchema.js +390 -0
- package/graphql/RecordLockingGraphQLSchema.js.map +1 -0
- package/graphql/checkPermissions.d.ts +3 -3
- package/graphql/checkPermissions.js +4 -10
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/resolve.d.ts +1 -1
- package/graphql/resolve.js +16 -18
- package/graphql/resolve.js.map +1 -1
- package/index.d.ts +2 -9
- package/index.js +1 -63
- package/package.json +23 -21
- 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
- package/graphql/schema.d.ts +0 -11
- package/graphql/schema.js +0 -315
- package/graphql/schema.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -2,13 +2,14 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { UnlockEntryRequestUseCase } from "./UnlockEntryRequestUseCase.js";
|
|
3
3
|
import { UnlockEntryRequestRepository } from "./UnlockEntryRequestRepository.js";
|
|
4
4
|
import { UnlockEntryRequestEventsDecorator } from "./UnlockEntryRequestEventsDecorator.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const UnlockEntryRequestFeature = createFeature({
|
|
6
|
+
name: "UnlockEntryRequest",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(UnlockEntryRequestUseCase);
|
|
9
|
+
container.register(UnlockEntryRequestRepository).inSingletonScope();
|
|
10
|
+
container.registerDecorator(UnlockEntryRequestEventsDecorator);
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
|
+
export { UnlockEntryRequestFeature };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UnlockEntryRequest/feature.js","sources":["../../../src/features/UnlockEntryRequest/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UnlockEntryRequestUseCase } from \"./UnlockEntryRequestUseCase.js\";\nimport { UnlockEntryRequestRepository } from \"./UnlockEntryRequestRepository.js\";\nimport { UnlockEntryRequestEventsDecorator } from \"./UnlockEntryRequestEventsDecorator.js\";\n\nexport const UnlockEntryRequestFeature = createFeature({\n name: \"UnlockEntryRequest\",\n register(container) {\n container.register(UnlockEntryRequestUseCase);\n container.register(UnlockEntryRequestRepository).inSingletonScope();\n container.registerDecorator(UnlockEntryRequestEventsDecorator);\n }\n});\n"],"names":["UnlockEntryRequestFeature","createFeature","container","UnlockEntryRequestUseCase","UnlockEntryRequestRepository","UnlockEntryRequestEventsDecorator"],"mappings":";;;;AAKO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,8BAA8B,gBAAgB;QACjEF,UAAU,iBAAiB,CAACG;IAChC;AACJ"}
|
|
@@ -3,15 +3,16 @@ import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEnt
|
|
|
3
3
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
4
|
import { Result } from "@webiny/feature/api";
|
|
5
5
|
import { UpdateEntryLockRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
6
|
-
import { RecordLockingConfig
|
|
6
|
+
import { RecordLockingConfig } from "../../domain/abstractions.js";
|
|
7
|
+
import { RecordLockingModelProvider } from "../../domain/abstractions.js";
|
|
7
8
|
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
8
9
|
declare class UpdateEntryLockRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
9
|
-
private
|
|
10
|
+
private modelProvider;
|
|
10
11
|
private config;
|
|
11
12
|
private identityContext;
|
|
12
13
|
private updateEntry;
|
|
13
14
|
private getEntryById;
|
|
14
|
-
constructor(
|
|
15
|
+
constructor(modelProvider: RecordLockingModelProvider.Interface, config: RecordLockingConfig.Interface, identityContext: IdentityContext.Interface, updateEntry: UpdateEntryUseCase.Interface, getEntryById: GetEntryByIdUseCase.Interface);
|
|
15
16
|
update(lockRecordId: string, updateOwner: boolean): Promise<Result<ILockRecord, RepositoryAbstraction.Error>>;
|
|
16
17
|
}
|
|
17
18
|
export declare const UpdateEntryLockRepository: typeof UpdateEntryLockRepositoryImpl & {
|
|
@@ -3,61 +3,59 @@ import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEnt
|
|
|
3
3
|
import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
|
|
4
4
|
import { Result } from "@webiny/feature/api";
|
|
5
5
|
import { createIdentifier } from "@webiny/utils";
|
|
6
|
-
import { UpdateEntryLockRepository
|
|
7
|
-
import { RecordLockingConfig,
|
|
6
|
+
import { UpdateEntryLockRepository } from "./abstractions.js";
|
|
7
|
+
import { RecordLockingConfig, RecordLockingModelProvider } from "../../domain/abstractions.js";
|
|
8
8
|
import { LockRecord } from "../../domain/LockRecord.js";
|
|
9
9
|
import { LockRecordPersistenceError } from "../../domain/errors.js";
|
|
10
10
|
import { createLockRecordDatabaseId } from "../../utils/lockRecordDatabaseId.js";
|
|
11
11
|
class UpdateEntryLockRepositoryImpl {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (getResult.isFail()) {
|
|
48
|
-
return Result.fail(new LockRecordPersistenceError(getResult.error));
|
|
49
|
-
}
|
|
50
|
-
const entry = getResult.value;
|
|
51
|
-
const lockRecord = new LockRecord(entry, this.config.timeout);
|
|
52
|
-
return Result.ok(lockRecord);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
return Result.fail(new LockRecordPersistenceError(error));
|
|
12
|
+
constructor(modelProvider, config, identityContext, updateEntry, getEntryById){
|
|
13
|
+
this.modelProvider = modelProvider;
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.identityContext = identityContext;
|
|
16
|
+
this.updateEntry = updateEntry;
|
|
17
|
+
this.getEntryById = getEntryById;
|
|
18
|
+
}
|
|
19
|
+
async update(lockRecordId, updateOwner) {
|
|
20
|
+
try {
|
|
21
|
+
const model = await this.modelProvider.get();
|
|
22
|
+
const entryId = createLockRecordDatabaseId(lockRecordId);
|
|
23
|
+
const id = createIdentifier({
|
|
24
|
+
id: entryId,
|
|
25
|
+
version: 1
|
|
26
|
+
});
|
|
27
|
+
const identity = this.identityContext.getIdentity();
|
|
28
|
+
const now = new Date().toISOString();
|
|
29
|
+
const updateData = {
|
|
30
|
+
savedOn: now
|
|
31
|
+
};
|
|
32
|
+
if (updateOwner) {
|
|
33
|
+
updateData.createdOn = now;
|
|
34
|
+
updateData.createdBy = identity;
|
|
35
|
+
updateData.savedBy = identity;
|
|
36
|
+
}
|
|
37
|
+
const result = await this.updateEntry.execute(model, id, updateData);
|
|
38
|
+
if (result.isFail()) return Result.fail(new LockRecordPersistenceError(result.error));
|
|
39
|
+
const getResult = await this.getEntryById.execute(model, id);
|
|
40
|
+
if (getResult.isFail()) return Result.fail(new LockRecordPersistenceError(getResult.error));
|
|
41
|
+
const entry = getResult.value;
|
|
42
|
+
const lockRecord = new LockRecord(entry, this.config.timeout);
|
|
43
|
+
return Result.ok(lockRecord);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return Result.fail(new LockRecordPersistenceError(error));
|
|
46
|
+
}
|
|
55
47
|
}
|
|
56
|
-
}
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
const UpdateEntryLockRepository_UpdateEntryLockRepository = UpdateEntryLockRepository.createImplementation({
|
|
50
|
+
implementation: UpdateEntryLockRepositoryImpl,
|
|
51
|
+
dependencies: [
|
|
52
|
+
RecordLockingModelProvider,
|
|
53
|
+
RecordLockingConfig,
|
|
54
|
+
IdentityContext,
|
|
55
|
+
UpdateEntryUseCase,
|
|
56
|
+
GetEntryByIdUseCase
|
|
57
|
+
]
|
|
61
58
|
});
|
|
59
|
+
export { UpdateEntryLockRepository_UpdateEntryLockRepository as UpdateEntryLockRepository };
|
|
62
60
|
|
|
63
61
|
//# sourceMappingURL=UpdateEntryLockRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/UpdateEntryLockRepository.js","sources":["../../../src/features/UpdateEntryLock/UpdateEntryLockRepository.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { Result } from \"@webiny/feature/api\";\nimport { createIdentifier } from \"@webiny/utils\";\nimport { UpdateEntryLockRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { RecordLockingConfig } from \"~/domain/abstractions.js\";\nimport { RecordLockingModelProvider } 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 UpdateEntryLockRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private modelProvider: RecordLockingModelProvider.Interface,\n private config: RecordLockingConfig.Interface,\n private identityContext: IdentityContext.Interface,\n private updateEntry: UpdateEntryUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface\n ) {}\n\n async update(\n lockRecordId: string,\n updateOwner: boolean\n ): Promise<Result<ILockRecord, RepositoryAbstraction.Error>> {\n try {\n const model = await this.modelProvider.get();\n\n const entryId = createLockRecordDatabaseId(lockRecordId);\n const id = createIdentifier({\n id: entryId,\n version: 1\n });\n\n const identity = this.identityContext.getIdentity();\n const now = new Date().toISOString();\n\n // Build update data\n const updateData: any = {\n savedOn: now\n };\n\n // If updating owner (expired lock), also update created fields\n if (updateOwner) {\n updateData.createdOn = now;\n updateData.createdBy = identity;\n updateData.savedBy = identity;\n }\n\n const result = await this.updateEntry.execute(model, id, updateData);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n // Fetch the updated entry to return full lock record\n const getResult = await this.getEntryById.execute<LockRecordValues>(model, id);\n\n if (getResult.isFail()) {\n return Result.fail(new LockRecordPersistenceError(getResult.error));\n }\n\n const entry = getResult.value;\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 UpdateEntryLockRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateEntryLockRepositoryImpl,\n dependencies: [\n RecordLockingModelProvider,\n RecordLockingConfig,\n IdentityContext,\n UpdateEntryUseCase,\n GetEntryByIdUseCase\n ]\n});\n"],"names":["UpdateEntryLockRepositoryImpl","modelProvider","config","identityContext","updateEntry","getEntryById","lockRecordId","updateOwner","model","entryId","createLockRecordDatabaseId","id","createIdentifier","identity","now","Date","updateData","result","Result","LockRecordPersistenceError","getResult","entry","lockRecord","LockRecord","error","UpdateEntryLockRepository","RepositoryAbstraction","RecordLockingModelProvider","RecordLockingConfig","IdentityContext","UpdateEntryUseCase","GetEntryByIdUseCase"],"mappings":";;;;;;;;;;AAcA,MAAMA;IACF,YACYC,aAAmD,EACnDC,MAAqC,EACrCC,eAA0C,EAC1CC,WAAyC,EACzCC,YAA2C,CACrD;aALUJ,aAAa,GAAbA;aACAC,MAAM,GAANA;aACAC,eAAe,GAAfA;aACAC,WAAW,GAAXA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,OACFC,YAAoB,EACpBC,WAAoB,EACqC;QACzD,IAAI;YACA,MAAMC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG;YAE1C,MAAMC,UAAUC,2BAA2BJ;YAC3C,MAAMK,KAAKC,iBAAiB;gBACxB,IAAIH;gBACJ,SAAS;YACb;YAEA,MAAMI,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;YACjD,MAAMC,MAAM,IAAIC,OAAO,WAAW;YAGlC,MAAMC,aAAkB;gBACpB,SAASF;YACb;YAGA,IAAIP,aAAa;gBACbS,WAAW,SAAS,GAAGF;gBACvBE,WAAW,SAAS,GAAGH;gBACvBG,WAAW,OAAO,GAAGH;YACzB;YAEA,MAAMI,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACT,OAAOG,IAAIK;YAEzD,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAIlE,MAAMG,YAAY,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAmBZ,OAAOG;YAE3E,IAAIS,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAAC,IAAIC,2BAA2BC,UAAU,KAAK;YAGrE,MAAMC,QAAQD,UAAU,KAAK;YAC7B,MAAME,aAAa,IAAIC,WAAWF,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5D,OAAOH,OAAO,EAAE,CAACI;QACrB,EAAE,OAAOE,OAAO;YACZ,OAAON,OAAO,IAAI,CAAC,IAAIC,2BAA2BK;QACtD;IACJ;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAA0C,CAAC;IAChF,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,62 +1,51 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
2
|
+
import { UpdateEntryLockRepository, UpdateEntryLockUseCase } from "./abstractions.js";
|
|
3
3
|
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
4
|
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
5
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { IdentityMismatchError, LockRecordNotFoundError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
7
7
|
class UpdateEntryLockUseCaseImpl {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
async execute(input) {
|
|
15
|
-
// Try to get existing lock record
|
|
16
|
-
const recordResult = await this.getLockRecord.execute(input);
|
|
17
|
-
|
|
18
|
-
// If doesn't exist, create a new lock
|
|
19
|
-
if (recordResult.isFail()) {
|
|
20
|
-
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
21
|
-
const lockResult = await this.lockEntry.execute(input);
|
|
22
|
-
if (lockResult.isFail()) {
|
|
23
|
-
return Result.fail(new UpdateEntryLockError(lockResult.error));
|
|
24
|
-
}
|
|
25
|
-
return Result.ok(lockResult.value);
|
|
26
|
-
}
|
|
27
|
-
return Result.fail(recordResult.error);
|
|
8
|
+
constructor(getLockRecord, lockEntry, repository, identityContext){
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.lockEntry = lockEntry;
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.identityContext = identityContext;
|
|
28
13
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
14
|
+
async execute(input) {
|
|
15
|
+
const recordResult = await this.getLockRecord.execute(input);
|
|
16
|
+
if (recordResult.isFail()) {
|
|
17
|
+
if (recordResult.error instanceof LockRecordNotFoundError) {
|
|
18
|
+
const lockResult = await this.lockEntry.execute(input);
|
|
19
|
+
if (lockResult.isFail()) return Result.fail(new UpdateEntryLockError(lockResult.error));
|
|
20
|
+
return Result.ok(lockResult.value);
|
|
21
|
+
}
|
|
22
|
+
return Result.fail(recordResult.error);
|
|
23
|
+
}
|
|
24
|
+
const record = recordResult.value;
|
|
25
|
+
if (record.isExpired()) {
|
|
26
|
+
const updateResult = await this.repository.update(record.id, true);
|
|
27
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
28
|
+
return Result.ok(updateResult.value);
|
|
29
|
+
}
|
|
30
|
+
const identity = this.identityContext.getIdentity();
|
|
31
|
+
if (record.lockedBy.id !== identity.id) return Result.fail(new IdentityMismatchError({
|
|
32
|
+
currentId: identity.id,
|
|
33
|
+
targetId: record.lockedBy.id
|
|
34
|
+
}));
|
|
35
|
+
const updateResult = await this.repository.update(record.id, false);
|
|
36
|
+
if (updateResult.isFail()) return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
37
|
+
return Result.ok(updateResult.value);
|
|
53
38
|
}
|
|
54
|
-
return Result.ok(updateResult.value);
|
|
55
|
-
}
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
const UpdateEntryLockUseCase_UpdateEntryLockUseCase = UpdateEntryLockUseCase.createImplementation({
|
|
41
|
+
implementation: UpdateEntryLockUseCaseImpl,
|
|
42
|
+
dependencies: [
|
|
43
|
+
GetLockRecordUseCase,
|
|
44
|
+
LockEntryUseCase,
|
|
45
|
+
UpdateEntryLockRepository,
|
|
46
|
+
IdentityContext
|
|
47
|
+
]
|
|
60
48
|
});
|
|
49
|
+
export { UpdateEntryLockUseCase_UpdateEntryLockUseCase as UpdateEntryLockUseCase };
|
|
61
50
|
|
|
62
51
|
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/UpdateEntryLockUseCase.js","sources":["../../../src/features/UpdateEntryLock/UpdateEntryLockUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateEntryLockUseCase as UseCaseAbstraction,\n UpdateEntryLockRepository,\n UpdateEntryLockInput\n} from \"./abstractions.js\";\nimport { GetLockRecordUseCase } from \"../GetLockRecord/abstractions.js\";\nimport { LockEntryUseCase } from \"../LockEntry/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ILockRecord } from \"~/domain/LockRecord.js\";\nimport {\n LockRecordNotFoundError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\nclass UpdateEntryLockUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private getLockRecord: GetLockRecordUseCase.Interface,\n private lockEntry: LockEntryUseCase.Interface,\n private repository: UpdateEntryLockRepository.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n input: UpdateEntryLockInput\n ): Promise<Result<ILockRecord, UseCaseAbstraction.Error>> {\n // Try to get existing lock record\n const recordResult = await this.getLockRecord.execute(input);\n\n // If doesn't exist, create a new lock\n if (recordResult.isFail()) {\n if (recordResult.error instanceof LockRecordNotFoundError) {\n const lockResult = await this.lockEntry.execute(input);\n if (lockResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(lockResult.error));\n }\n return Result.ok(lockResult.value);\n }\n return Result.fail(recordResult.error);\n }\n\n const record = recordResult.value;\n\n // If expired, update with current user as new owner\n if (record.isExpired()) {\n const updateResult = await this.repository.update(record.id, true);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n return Result.ok(updateResult.value);\n }\n\n // If not expired, validate same owner\n const identity = this.identityContext.getIdentity();\n if (record.lockedBy.id !== identity.id) {\n return Result.fail(\n new IdentityMismatchError({\n currentId: identity.id,\n targetId: record.lockedBy.id\n })\n );\n }\n\n // Update timestamp only\n const updateResult = await this.repository.update(record.id, false);\n if (updateResult.isFail()) {\n return Result.fail(new UpdateEntryLockError(updateResult.error));\n }\n\n return Result.ok(updateResult.value);\n }\n}\n\nexport const UpdateEntryLockUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateEntryLockUseCaseImpl,\n dependencies: [\n GetLockRecordUseCase,\n LockEntryUseCase,\n UpdateEntryLockRepository,\n IdentityContext\n ]\n});\n"],"names":["UpdateEntryLockUseCaseImpl","getLockRecord","lockEntry","repository","identityContext","input","recordResult","LockRecordNotFoundError","lockResult","Result","UpdateEntryLockError","record","updateResult","identity","IdentityMismatchError","UpdateEntryLockUseCase","UseCaseAbstraction","GetLockRecordUseCase","LockEntryUseCase","UpdateEntryLockRepository","IdentityContext"],"mappings":";;;;;;AAgBA,MAAMA;IACF,YACYC,aAA6C,EAC7CC,SAAqC,EACrCC,UAA+C,EAC/CC,eAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,SAAS,GAATA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,KAA2B,EAC2B;QAEtD,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD;QAGtD,IAAIC,aAAa,MAAM,IAAI;YACvB,IAAIA,aAAa,KAAK,YAAYC,yBAAyB;gBACvD,MAAMC,aAAa,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH;gBAChD,IAAIG,WAAW,MAAM,IACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC,qBAAqBF,WAAW,KAAK;gBAEhE,OAAOC,OAAO,EAAE,CAACD,WAAW,KAAK;YACrC;YACA,OAAOC,OAAO,IAAI,CAACH,aAAa,KAAK;QACzC;QAEA,MAAMK,SAASL,aAAa,KAAK;QAGjC,IAAIK,OAAO,SAAS,IAAI;YACpB,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;YAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;YAElE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;QACvC;QAGA,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,IAAIF,OAAO,QAAQ,CAAC,EAAE,KAAKE,SAAS,EAAE,EAClC,OAAOJ,OAAO,IAAI,CACd,IAAIK,sBAAsB;YACtB,WAAWD,SAAS,EAAE;YACtB,UAAUF,OAAO,QAAQ,CAAC,EAAE;QAChC;QAKR,MAAMC,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACD,OAAO,EAAE,EAAE;QAC7D,IAAIC,aAAa,MAAM,IACnB,OAAOH,OAAO,IAAI,CAAC,IAAIC,qBAAqBE,aAAa,KAAK;QAGlE,OAAOH,OAAO,EAAE,CAACG,aAAa,KAAK;IACvC;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAAuC,CAAC;IAC1E,gBAAgBhB;IAChB,cAAc;QACViB;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* UpdateEntryLock Use Case - Updates lock timestamp to keep it alive
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const UpdateEntryLockUseCase = createAbstraction("UpdateEntryLockUseCase");
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* UpdateEntryLockRepository - Updates lock record in storage
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const UpdateEntryLockRepository = createAbstraction("UpdateEntryLockRepository");
|
|
2
|
+
const UpdateEntryLockUseCase = createAbstraction("UpdateEntryLockUseCase");
|
|
3
|
+
const UpdateEntryLockRepository = createAbstraction("UpdateEntryLockRepository");
|
|
4
|
+
export { UpdateEntryLockRepository, UpdateEntryLockUseCase };
|
|
16
5
|
|
|
17
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/abstractions.js","sources":["../../../src/features/UpdateEntryLock/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 LockRecordNotFoundError,\n LockRecordPersistenceError,\n IdentityMismatchError,\n UpdateEntryLockError\n} from \"~/domain/errors.js\";\n\n// Input types\nexport interface UpdateEntryLockInput {\n id: string;\n type: LockRecordEntryType;\n}\n\n/**\n * UpdateEntryLock Use Case - Updates lock timestamp to keep it alive\n */\nexport interface IUpdateEntryLockUseCase {\n execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseError>>;\n}\n\nexport interface IUpdateEntryLockUseCaseErrors {\n notFound: LockRecordNotFoundError;\n notSameIdentity: IdentityMismatchError;\n persistence: LockRecordPersistenceError;\n updateError: UpdateEntryLockError;\n}\n\ntype UseCaseError = IUpdateEntryLockUseCaseErrors[keyof IUpdateEntryLockUseCaseErrors];\n\nexport const UpdateEntryLockUseCase =\n createAbstraction<IUpdateEntryLockUseCase>(\"UpdateEntryLockUseCase\");\n\nexport namespace UpdateEntryLockUseCase {\n export type Interface = IUpdateEntryLockUseCase;\n export type Error = UseCaseError;\n}\n\n/**\n * UpdateEntryLockRepository - Updates lock record in storage\n */\nexport interface IUpdateEntryLockRepository {\n update(\n lockRecordId: string,\n updateOwner: boolean\n ): Promise<Result<ILockRecord, RepositoryError>>;\n}\n\nexport interface IUpdateEntryLockRepositoryErrors {\n persistence: LockRecordPersistenceError;\n}\n\ntype RepositoryError = IUpdateEntryLockRepositoryErrors[keyof IUpdateEntryLockRepositoryErrors];\n\nexport const UpdateEntryLockRepository = createAbstraction<IUpdateEntryLockRepository>(\n \"UpdateEntryLockRepository\"\n);\n\nexport namespace UpdateEntryLockRepository {\n export type Interface = IUpdateEntryLockRepository;\n export type Error = RepositoryError;\n}\n"],"names":["UpdateEntryLockUseCase","createAbstraction","UpdateEntryLockRepository"],"mappings":";AAiCO,MAAMA,yBACTC,kBAA2C;AAuBxC,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateEntryLockUseCase } from "./UpdateEntryLockUseCase.js";
|
|
3
3
|
import { UpdateEntryLockRepository } from "./UpdateEntryLockRepository.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const UpdateEntryLockFeature = createFeature({
|
|
5
|
+
name: "UpdateEntryLock",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(UpdateEntryLockUseCase);
|
|
8
|
+
container.register(UpdateEntryLockRepository).inSingletonScope();
|
|
9
|
+
}
|
|
10
10
|
});
|
|
11
|
+
export { UpdateEntryLockFeature };
|
|
11
12
|
|
|
12
13
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/UpdateEntryLock/feature.js","sources":["../../../src/features/UpdateEntryLock/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UpdateEntryLockUseCase } from \"./UpdateEntryLockUseCase.js\";\nimport { UpdateEntryLockRepository } from \"./UpdateEntryLockRepository.js\";\n\nexport const UpdateEntryLockFeature = createFeature({\n name: \"UpdateEntryLock\",\n register(container) {\n container.register(UpdateEntryLockUseCase);\n container.register(UpdateEntryLockRepository).inSingletonScope();\n }\n});\n"],"names":["UpdateEntryLockFeature","createFeature","container","UpdateEntryLockUseCase","UpdateEntryLockRepository"],"mappings":";;;AAIO,MAAMA,yBAAyBC,cAAc;IAChD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,2BAA2B,gBAAgB;IAClE;AACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
|
+
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
6
|
+
import { RecordLockingModelProvider } from "../domain/abstractions.js";
|
|
7
|
+
/**
|
|
8
|
+
* The record locking GraphQL schema. The lock record type is rendered from the lock record model,
|
|
9
|
+
* which is loaded when the schema is composed.
|
|
10
|
+
*/
|
|
11
|
+
declare class RecordLockingGraphQLSchemaImpl implements GraphQLSchemaFactory.Interface {
|
|
12
|
+
private readonly tenantContext;
|
|
13
|
+
private readonly identityContext;
|
|
14
|
+
private readonly modelProvider;
|
|
15
|
+
private readonly listModelsUseCase;
|
|
16
|
+
private readonly fieldRegistry;
|
|
17
|
+
constructor(tenantContext: TenantContext.Interface, identityContext: IdentityContext.Interface, modelProvider: RecordLockingModelProvider.Interface, listModelsUseCase: ListModelsUseCase.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface);
|
|
18
|
+
getSchemaKey(): Promise<string>;
|
|
19
|
+
execute(builder: GraphQLSchemaFactory.SchemaBuilder): Promise<GraphQLSchemaFactory.SchemaBuilder>;
|
|
20
|
+
private loadInputs;
|
|
21
|
+
}
|
|
22
|
+
export declare const RecordLockingGraphQLSchema: typeof RecordLockingGraphQLSchemaImpl & {
|
|
23
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.public.js").IGraphQLSchemaFactory>;
|
|
24
|
+
};
|
|
25
|
+
export {};
|