@webiny/api-record-locking 6.0.0-beta.0 → 6.0.0-rc.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/README.md +10 -9
- package/domain/LockRecord.d.ts +45 -0
- package/{utils/convertEntryToLockRecord.js → domain/LockRecord.js} +14 -22
- package/domain/LockRecord.js.map +1 -0
- package/domain/RecordLockingModel.d.ts +9 -0
- package/domain/RecordLockingModel.js +29 -0
- package/domain/RecordLockingModel.js.map +1 -0
- package/domain/abstractions.d.ts +18 -0
- package/domain/abstractions.js +10 -0
- package/domain/abstractions.js.map +1 -0
- package/domain/calculateExpiresOn.d.ts +1 -0
- package/domain/calculateExpiresOn.js +9 -0
- package/domain/calculateExpiresOn.js.map +1 -0
- package/domain/errors.d.ts +71 -0
- package/domain/errors.js +95 -0
- package/domain/errors.js.map +1 -0
- package/domain/index.d.ts +4 -0
- package/domain/index.js +6 -0
- package/domain/index.js.map +1 -0
- package/domain/types.d.ts +44 -0
- package/domain/types.js +12 -0
- package/domain/types.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordRepository.d.ts +16 -0
- package/features/GetLockRecord/GetLockRecordRepository.js +37 -0
- package/features/GetLockRecord/GetLockRecordRepository.js.map +1 -0
- package/features/GetLockRecord/GetLockRecordUseCase.d.ts +12 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js +15 -0
- package/features/GetLockRecord/GetLockRecordUseCase.js.map +1 -0
- package/features/GetLockRecord/abstractions.d.ts +41 -0
- package/features/GetLockRecord/abstractions.js +17 -0
- package/features/GetLockRecord/abstractions.js.map +1 -0
- package/features/GetLockRecord/feature.d.ts +1 -0
- package/features/GetLockRecord/feature.js +12 -0
- package/features/GetLockRecord/feature.js.map +1 -0
- package/features/GetLockRecord/index.d.ts +2 -0
- package/features/GetLockRecord/index.js +4 -0
- package/features/GetLockRecord/index.js.map +1 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +15 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +39 -0
- package/features/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +1 -0
- package/features/GetLockedEntryLockRecord/abstractions.d.ts +26 -0
- package/features/GetLockedEntryLockRecord/abstractions.js +13 -0
- package/features/GetLockedEntryLockRecord/abstractions.js.map +1 -0
- package/features/GetLockedEntryLockRecord/feature.d.ts +1 -0
- package/features/GetLockedEntryLockRecord/feature.js +10 -0
- package/features/GetLockedEntryLockRecord/feature.js.map +1 -0
- package/features/GetLockedEntryLockRecord/index.d.ts +2 -0
- package/features/GetLockedEntryLockRecord/index.js +4 -0
- package/features/GetLockedEntryLockRecord/index.js.map +1 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.d.ts +14 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js +39 -0
- package/features/IsEntryLocked/IsEntryLockedUseCase.js.map +1 -0
- package/features/IsEntryLocked/abstractions.d.ts +24 -0
- package/features/IsEntryLocked/abstractions.js +12 -0
- package/features/IsEntryLocked/abstractions.js.map +1 -0
- package/features/IsEntryLocked/feature.d.ts +1 -0
- package/features/IsEntryLocked/feature.js +10 -0
- package/features/IsEntryLocked/feature.js.map +1 -0
- package/features/IsEntryLocked/index.d.ts +1 -0
- package/features/IsEntryLocked/index.js +3 -0
- package/features/IsEntryLocked/index.js.map +1 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +15 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js +42 -0
- package/features/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +1 -0
- package/features/KickOutCurrentUser/abstractions.d.ts +17 -0
- package/features/KickOutCurrentUser/abstractions.js +9 -0
- package/features/KickOutCurrentUser/abstractions.js.map +1 -0
- package/features/KickOutCurrentUser/feature.d.ts +1 -0
- package/features/KickOutCurrentUser/feature.js +10 -0
- package/features/KickOutCurrentUser/feature.js.map +1 -0
- package/features/KickOutCurrentUser/index.d.ts +1 -0
- package/features/KickOutCurrentUser/index.js +3 -0
- package/features/KickOutCurrentUser/index.js.map +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.d.ts +16 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js +43 -0
- package/features/ListAllLockRecords/ListAllLockRecordsRepository.js.map +1 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.d.ts +11 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js +15 -0
- package/features/ListAllLockRecords/ListAllLockRecordsUseCase.js.map +1 -0
- package/features/ListAllLockRecords/abstractions.d.ts +40 -0
- package/features/ListAllLockRecords/abstractions.js +17 -0
- package/features/ListAllLockRecords/abstractions.js.map +1 -0
- package/features/ListAllLockRecords/feature.d.ts +1 -0
- package/features/ListAllLockRecords/feature.js +12 -0
- package/features/ListAllLockRecords/feature.js.map +1 -0
- package/features/ListAllLockRecords/index.d.ts +2 -0
- package/features/ListAllLockRecords/index.js +4 -0
- package/features/ListAllLockRecords/index.js.map +1 -0
- package/features/ListLockRecords/ListLockRecordsRepository.d.ts +15 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js +43 -0
- package/features/ListLockRecords/ListLockRecordsRepository.js.map +1 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.d.ts +15 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js +30 -0
- package/features/ListLockRecords/ListLockRecordsUseCase.js.map +1 -0
- package/features/ListLockRecords/abstractions.d.ts +45 -0
- package/features/ListLockRecords/abstractions.js +17 -0
- package/features/ListLockRecords/abstractions.js.map +1 -0
- package/features/ListLockRecords/feature.d.ts +1 -0
- package/features/ListLockRecords/feature.js +12 -0
- package/features/ListLockRecords/feature.js.map +1 -0
- package/features/ListLockRecords/index.d.ts +1 -0
- package/features/ListLockRecords/index.js +3 -0
- package/features/ListLockRecords/index.js.map +1 -0
- package/features/LockEntry/LockEntryEventsDecorator.d.ts +14 -0
- package/features/LockEntry/LockEntryEventsDecorator.js +40 -0
- package/features/LockEntry/LockEntryEventsDecorator.js.map +1 -0
- package/features/LockEntry/LockEntryRepository.d.ts +16 -0
- package/features/LockEntry/LockEntryRepository.js +42 -0
- package/features/LockEntry/LockEntryRepository.js.map +1 -0
- package/features/LockEntry/LockEntryUseCase.d.ts +14 -0
- package/features/LockEntry/LockEntryUseCase.js +36 -0
- package/features/LockEntry/LockEntryUseCase.js.map +1 -0
- package/features/LockEntry/abstractions.d.ts +41 -0
- package/features/LockEntry/abstractions.js +17 -0
- package/features/LockEntry/abstractions.js.map +1 -0
- package/features/LockEntry/events.d.ts +45 -0
- package/features/LockEntry/events.js +40 -0
- package/features/LockEntry/events.js.map +1 -0
- package/features/LockEntry/feature.d.ts +1 -0
- package/features/LockEntry/feature.js +14 -0
- package/features/LockEntry/feature.js.map +1 -0
- package/features/LockEntry/index.d.ts +1 -0
- package/features/LockEntry/index.js +3 -0
- package/features/LockEntry/index.js.map +1 -0
- package/features/RecordLockingFeature.d.ts +12 -0
- package/features/RecordLockingFeature.js +36 -0
- package/features/RecordLockingFeature.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js +41 -0
- package/features/UnlockEntry/UnlockEntryEventsDecorator.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryRepository.d.ts +14 -0
- package/features/UnlockEntry/UnlockEntryRepository.js +40 -0
- package/features/UnlockEntry/UnlockEntryRepository.js.map +1 -0
- package/features/UnlockEntry/UnlockEntryUseCase.d.ts +18 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js +81 -0
- package/features/UnlockEntry/UnlockEntryUseCase.js.map +1 -0
- package/features/UnlockEntry/abstractions.d.ts +44 -0
- package/features/UnlockEntry/abstractions.js +17 -0
- package/features/UnlockEntry/abstractions.js.map +1 -0
- package/features/UnlockEntry/events.d.ts +46 -0
- package/features/UnlockEntry/events.js +40 -0
- package/features/UnlockEntry/events.js.map +1 -0
- package/features/UnlockEntry/feature.d.ts +1 -0
- package/features/UnlockEntry/feature.js +14 -0
- package/features/UnlockEntry/feature.js.map +1 -0
- package/features/UnlockEntry/hasFullAccessPermission.d.ts +2 -0
- package/features/UnlockEntry/hasFullAccessPermission.js +10 -0
- package/features/UnlockEntry/hasFullAccessPermission.js.map +1 -0
- package/features/UnlockEntry/index.d.ts +1 -0
- package/features/UnlockEntry/index.js +3 -0
- package/features/UnlockEntry/index.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.d.ts +14 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js +40 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestEventsDecorator.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.d.ts +17 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js +43 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestRepository.js.map +1 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.d.ts +16 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js +92 -0
- package/features/UnlockEntryRequest/UnlockEntryRequestUseCase.js.map +1 -0
- package/features/UnlockEntryRequest/abstractions.d.ts +42 -0
- package/features/UnlockEntryRequest/abstractions.js +17 -0
- package/features/UnlockEntryRequest/abstractions.js.map +1 -0
- package/features/UnlockEntryRequest/events.d.ts +45 -0
- package/features/UnlockEntryRequest/events.js +40 -0
- package/features/UnlockEntryRequest/events.js.map +1 -0
- package/features/UnlockEntryRequest/feature.d.ts +1 -0
- package/features/UnlockEntryRequest/feature.js +14 -0
- package/features/UnlockEntryRequest/feature.js.map +1 -0
- package/features/UnlockEntryRequest/index.d.ts +3 -0
- package/features/UnlockEntryRequest/index.js +5 -0
- package/features/UnlockEntryRequest/index.js.map +1 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.d.ts +20 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js +63 -0
- package/features/UpdateEntryLock/UpdateEntryLockRepository.js.map +1 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +18 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js +62 -0
- package/features/UpdateEntryLock/UpdateEntryLockUseCase.js.map +1 -0
- package/features/UpdateEntryLock/abstractions.d.ts +42 -0
- package/features/UpdateEntryLock/abstractions.js +17 -0
- package/features/UpdateEntryLock/abstractions.js.map +1 -0
- package/features/UpdateEntryLock/feature.d.ts +1 -0
- package/features/UpdateEntryLock/feature.js +12 -0
- package/features/UpdateEntryLock/feature.js.map +1 -0
- package/features/UpdateEntryLock/index.d.ts +1 -0
- package/features/UpdateEntryLock/index.js +3 -0
- package/features/UpdateEntryLock/index.js.map +1 -0
- package/graphql/checkPermissions.d.ts +5 -0
- package/graphql/checkPermissions.js +14 -0
- package/graphql/checkPermissions.js.map +1 -0
- package/{utils → graphql}/resolve.d.ts +2 -2
- package/graphql/resolve.js +22 -0
- package/graphql/resolve.js.map +1 -0
- package/graphql/schema.d.ts +8 -4
- package/graphql/schema.js +99 -61
- package/graphql/schema.js.map +1 -1
- package/index.d.ts +8 -2
- package/index.js +50 -26
- package/index.js.map +1 -1
- package/package.json +21 -43
- package/types.d.ts +14 -133
- package/types.js +6 -24
- package/types.js.map +1 -1
- package/utils/convertWhereCondition.d.ts +2 -2
- package/utils/convertWhereCondition.js +11 -14
- package/utils/convertWhereCondition.js.map +1 -1
- package/utils/getTimeout.d.ts +3 -2
- package/utils/getTimeout.js +11 -10
- package/utils/getTimeout.js.map +1 -1
- package/utils/lockRecordDatabaseId.js +4 -12
- package/utils/lockRecordDatabaseId.js.map +1 -1
- package/abstractions/IGetLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockRecordUseCase.js.map +0 -1
- package/abstractions/IGetLockedEntryLockRecordUseCase.d.ts +0 -8
- package/abstractions/IGetLockedEntryLockRecordUseCase.js +0 -7
- package/abstractions/IGetLockedEntryLockRecordUseCase.js.map +0 -1
- package/abstractions/IIsEntryLocked.d.ts +0 -8
- package/abstractions/IIsEntryLocked.js +0 -7
- package/abstractions/IIsEntryLocked.js.map +0 -1
- package/abstractions/IKickOutCurrentUserUseCase.d.ts +0 -5
- package/abstractions/IKickOutCurrentUserUseCase.js +0 -7
- package/abstractions/IKickOutCurrentUserUseCase.js.map +0 -1
- package/abstractions/IListAllLockRecordsUseCase.d.ts +0 -9
- package/abstractions/IListAllLockRecordsUseCase.js +0 -7
- package/abstractions/IListAllLockRecordsUseCase.js.map +0 -1
- package/abstractions/IListLockRecordsUseCase.d.ts +0 -10
- package/abstractions/IListLockRecordsUseCase.js +0 -7
- package/abstractions/IListLockRecordsUseCase.js.map +0 -1
- package/abstractions/ILockEntryUseCase.d.ts +0 -11
- package/abstractions/ILockEntryUseCase.js +0 -7
- package/abstractions/ILockEntryUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryRequestUseCase.d.ts +0 -11
- package/abstractions/IUnlockEntryRequestUseCase.js +0 -7
- package/abstractions/IUnlockEntryRequestUseCase.js.map +0 -1
- package/abstractions/IUnlockEntryUseCase.d.ts +0 -12
- package/abstractions/IUnlockEntryUseCase.js +0 -7
- package/abstractions/IUnlockEntryUseCase.js.map +0 -1
- package/abstractions/IUpdateEntryLockUseCase.d.ts +0 -11
- package/abstractions/IUpdateEntryLockUseCase.js +0 -7
- package/abstractions/IUpdateEntryLockUseCase.js.map +0 -1
- package/crud/crud.d.ts +0 -6
- package/crud/crud.js +0 -188
- package/crud/crud.js.map +0 -1
- package/crud/model.d.ts +0 -2
- package/crud/model.js +0 -127
- package/crud/model.js.map +0 -1
- package/useCases/GetLockRecord/GetLockRecordUseCase.d.ts +0 -10
- package/useCases/GetLockRecord/GetLockRecordUseCase.js +0 -35
- package/useCases/GetLockRecord/GetLockRecordUseCase.js.map +0 -1
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.d.ts +0 -16
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js +0 -27
- package/useCases/GetLockedEntryLockRecord/GetLockedEntryLockRecordUseCase.js.map +0 -1
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.d.ts +0 -16
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js +0 -35
- package/useCases/IsEntryLocked/IsEntryLockedUseCase.js.map +0 -1
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.d.ts +0 -12
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js +0 -46
- package/useCases/KickOutCurrentUser/KickOutCurrentUserUseCase.js.map +0 -1
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.d.ts +0 -10
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js +0 -32
- package/useCases/ListAllLockRecordsUseCase/ListAllLockRecordsUseCase.js.map +0 -1
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.d.ts +0 -14
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js +0 -27
- package/useCases/ListLockRecordsUseCase/ListLockRecordsUseCase.js.map +0 -1
- package/useCases/LockEntryUseCase/LockEntryUseCase.d.ts +0 -13
- package/useCases/LockEntryUseCase/LockEntryUseCase.js +0 -51
- package/useCases/LockEntryUseCase/LockEntryUseCase.js.map +0 -1
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.d.ts +0 -20
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js +0 -67
- package/useCases/UnlockEntryUseCase/UnlockEntryUseCase.js.map +0 -1
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.d.ts +0 -15
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js +0 -78
- package/useCases/UnlockRequestUseCase/UnlockEntryRequestUseCase.js.map +0 -1
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.d.ts +0 -18
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js +0 -48
- package/useCases/UpdateEntryLock/UpdateEntryLockUseCase.js.map +0 -1
- package/useCases/index.d.ts +0 -28
- package/useCases/index.js +0 -83
- package/useCases/index.js.map +0 -1
- package/utils/calculateExpiresOn.d.ts +0 -2
- package/utils/calculateExpiresOn.js +0 -15
- package/utils/calculateExpiresOn.js.map +0 -1
- package/utils/checkPermissions.d.ts +0 -7
- package/utils/checkPermissions.js +0 -21
- package/utils/checkPermissions.js.map +0 -1
- package/utils/convertEntryToLockRecord.d.ts +0 -28
- package/utils/convertEntryToLockRecord.js.map +0 -1
- package/utils/isLockedFactory.d.ts +0 -5
- package/utils/isLockedFactory.js +0 -20
- package/utils/isLockedFactory.js.map +0 -1
- package/utils/resolve.js +0 -30
- package/utils/resolve.js.map +0 -1
- package/utils/validateSameIdentity.d.ts +0 -6
- package/utils/validateSameIdentity.js +0 -24
- package/utils/validateSameIdentity.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IdentityContext","UpdateEntryUseCase","GetEntryByIdUseCase","Result","createIdentifier","UpdateEntryLockRepository","RepositoryAbstraction","RecordLockingConfig","RecordLockingModel","LockRecord","LockRecordPersistenceError","createLockRecordDatabaseId","UpdateEntryLockRepositoryImpl","constructor","model","config","identityContext","updateEntry","getEntryById","update","lockRecordId","updateOwner","entryId","id","version","identity","getIdentity","now","Date","toISOString","updateData","savedOn","createdOn","createdBy","savedBy","result","execute","isFail","fail","error","getResult","entry","value","lockRecord","timeout","ok","createImplementation","implementation","dependencies"],"sources":["UpdateEntryLockRepository.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/IdentityContext\";\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, 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 UpdateEntryLockRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.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 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(this.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>(this.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 RecordLockingModel,\n RecordLockingConfig,\n IdentityContext,\n UpdateEntryUseCase,\n GetEntryByIdUseCase\n ]\n});\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,2CAA2C;AAC3E,SAASC,kBAAkB,QAAQ,4DAA4D;AAC/F,SAASC,mBAAmB,QAAQ,6DAA6D;AACjG,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,gBAAgB,QAAQ,eAAe;AAChD,SAASC,yBAAyB,IAAIC,qBAAqB;AAC3D,SAASC,mBAAmB,EAAEC,kBAAkB;AAEhD,SAASC,UAAU;AAEnB,SAASC,0BAA0B;AACnC,SAASC,0BAA0B;AAEnC,MAAMC,6BAA6B,CAA4C;EAC3EC,WAAWA,CACCC,KAAmC,EACnCC,MAAqC,EACrCC,eAA0C,EAC1CC,WAAyC,EACzCC,YAA2C,EACrD;IAAA,KALUJ,KAAmC,GAAnCA,KAAmC;IAAA,KACnCC,MAAqC,GAArCA,MAAqC;IAAA,KACrCC,eAA0C,GAA1CA,eAA0C;IAAA,KAC1CC,WAAyC,GAAzCA,WAAyC;IAAA,KACzCC,YAA2C,GAA3CA,YAA2C;EACpD;EAEH,MAAMC,MAAMA,CACRC,YAAoB,EACpBC,WAAoB,EACqC;IACzD,IAAI;MACA,MAAMC,OAAO,GAAGX,0BAA0B,CAACS,YAAY,CAAC;MACxD,MAAMG,EAAE,GAAGnB,gBAAgB,CAAC;QACxBmB,EAAE,EAAED,OAAO;QACXE,OAAO,EAAE;MACb,CAAC,CAAC;MAEF,MAAMC,QAAQ,GAAG,IAAI,CAACT,eAAe,CAACU,WAAW,CAAC,CAAC;MACnD,MAAMC,GAAG,GAAG,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC;;MAEpC;MACA,MAAMC,UAAe,GAAG;QACpBC,OAAO,EAAEJ;MACb,CAAC;;MAED;MACA,IAAIN,WAAW,EAAE;QACbS,UAAU,CAACE,SAAS,GAAGL,GAAG;QAC1BG,UAAU,CAACG,SAAS,GAAGR,QAAQ;QAC/BK,UAAU,CAACI,OAAO,GAAGT,QAAQ;MACjC;MAEA,MAAMU,MAAM,GAAG,MAAM,IAAI,CAAClB,WAAW,CAACmB,OAAO,CAAC,IAAI,CAACtB,KAAK,EAAES,EAAE,EAAEO,UAAU,CAAC;MAEzE,IAAIK,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;QACjB,OAAOlC,MAAM,CAACmC,IAAI,CAAC,IAAI5B,0BAA0B,CAACyB,MAAM,CAACI,KAAK,CAAC,CAAC;MACpE;;MAEA;MACA,MAAMC,SAAS,GAAG,MAAM,IAAI,CAACtB,YAAY,CAACkB,OAAO,CAAmB,IAAI,CAACtB,KAAK,EAAES,EAAE,CAAC;MAEnF,IAAIiB,SAAS,CAACH,MAAM,CAAC,CAAC,EAAE;QACpB,OAAOlC,MAAM,CAACmC,IAAI,CAAC,IAAI5B,0BAA0B,CAAC8B,SAAS,CAACD,KAAK,CAAC,CAAC;MACvE;MAEA,MAAME,KAAK,GAAGD,SAAS,CAACE,KAAK;MAC7B,MAAMC,UAAU,GAAG,IAAIlC,UAAU,CAACgC,KAAK,EAAE,IAAI,CAAC1B,MAAM,CAAC6B,OAAO,CAAC;MAE7D,OAAOzC,MAAM,CAAC0C,EAAE,CAACF,UAAU,CAAC;IAChC,CAAC,CAAC,OAAOJ,KAAK,EAAE;MACZ,OAAOpC,MAAM,CAACmC,IAAI,CAAC,IAAI5B,0BAA0B,CAAC6B,KAAc,CAAC,CAAC;IACtE;EACJ;AACJ;AAEA,OAAO,MAAMlC,yBAAyB,GAAGC,qBAAqB,CAACwC,oBAAoB,CAAC;EAChFC,cAAc,EAAEnC,6BAA6B;EAC7CoC,YAAY,EAAE,CACVxC,kBAAkB,EAClBD,mBAAmB,EACnBP,eAAe,EACfC,kBAAkB,EAClBC,mBAAmB;AAE3B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockUseCase as UseCaseAbstraction, UpdateEntryLockRepository, UpdateEntryLockInput } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
6
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
7
|
+
declare class UpdateEntryLockUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
|
+
private getLockRecord;
|
|
9
|
+
private lockEntry;
|
|
10
|
+
private repository;
|
|
11
|
+
private identityContext;
|
|
12
|
+
constructor(getLockRecord: GetLockRecordUseCase.Interface, lockEntry: LockEntryUseCase.Interface, repository: UpdateEntryLockRepository.Interface, identityContext: IdentityContext.Interface);
|
|
13
|
+
execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseAbstraction.Error>>;
|
|
14
|
+
}
|
|
15
|
+
export declare const UpdateEntryLockUseCase: typeof UpdateEntryLockUseCaseImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateEntryLockUseCase>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockUseCase as UseCaseAbstraction, UpdateEntryLockRepository } from "./abstractions.js";
|
|
3
|
+
import { GetLockRecordUseCase } from "../GetLockRecord/abstractions.js";
|
|
4
|
+
import { LockEntryUseCase } from "../LockEntry/abstractions.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
6
|
+
import { LockRecordNotFoundError, IdentityMismatchError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
7
|
+
class UpdateEntryLockUseCaseImpl {
|
|
8
|
+
constructor(getLockRecord, lockEntry, repository, identityContext) {
|
|
9
|
+
this.getLockRecord = getLockRecord;
|
|
10
|
+
this.lockEntry = lockEntry;
|
|
11
|
+
this.repository = repository;
|
|
12
|
+
this.identityContext = identityContext;
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
const record = recordResult.value;
|
|
30
|
+
|
|
31
|
+
// If expired, update with current user as new owner
|
|
32
|
+
if (record.isExpired()) {
|
|
33
|
+
const updateResult = await this.repository.update(record.id, true);
|
|
34
|
+
if (updateResult.isFail()) {
|
|
35
|
+
return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
36
|
+
}
|
|
37
|
+
return Result.ok(updateResult.value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// If not expired, validate same owner
|
|
41
|
+
const identity = this.identityContext.getIdentity();
|
|
42
|
+
if (record.lockedBy.id !== identity.id) {
|
|
43
|
+
return Result.fail(new IdentityMismatchError({
|
|
44
|
+
currentId: identity.id,
|
|
45
|
+
targetId: record.lockedBy.id
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Update timestamp only
|
|
50
|
+
const updateResult = await this.repository.update(record.id, false);
|
|
51
|
+
if (updateResult.isFail()) {
|
|
52
|
+
return Result.fail(new UpdateEntryLockError(updateResult.error));
|
|
53
|
+
}
|
|
54
|
+
return Result.ok(updateResult.value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export const UpdateEntryLockUseCase = UseCaseAbstraction.createImplementation({
|
|
58
|
+
implementation: UpdateEntryLockUseCaseImpl,
|
|
59
|
+
dependencies: [GetLockRecordUseCase, LockEntryUseCase, UpdateEntryLockRepository, IdentityContext]
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=UpdateEntryLockUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","UpdateEntryLockUseCase","UseCaseAbstraction","UpdateEntryLockRepository","GetLockRecordUseCase","LockEntryUseCase","IdentityContext","LockRecordNotFoundError","IdentityMismatchError","UpdateEntryLockError","UpdateEntryLockUseCaseImpl","constructor","getLockRecord","lockEntry","repository","identityContext","execute","input","recordResult","isFail","error","lockResult","fail","ok","value","record","isExpired","updateResult","update","id","identity","getIdentity","lockedBy","currentId","targetId","createImplementation","implementation","dependencies"],"sources":["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/IdentityContext\";\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"],"mappings":"AAAA,SAASA,MAAM,QAAQ,qBAAqB;AAC5C,SACIC,sBAAsB,IAAIC,kBAAkB,EAC5CC,yBAAyB;AAG7B,SAASC,oBAAoB;AAC7B,SAASC,gBAAgB;AACzB,SAASC,eAAe,QAAQ,2CAA2C;AAE3E,SACIC,uBAAuB,EACvBC,qBAAqB,EACrBC,oBAAoB;AAGxB,MAAMC,0BAA0B,CAAyC;EACrEC,WAAWA,CACCC,aAA6C,EAC7CC,SAAqC,EACrCC,UAA+C,EAC/CC,eAA0C,EACpD;IAAA,KAJUH,aAA6C,GAA7CA,aAA6C;IAAA,KAC7CC,SAAqC,GAArCA,SAAqC;IAAA,KACrCC,UAA+C,GAA/CA,UAA+C;IAAA,KAC/CC,eAA0C,GAA1CA,eAA0C;EACnD;EAEH,MAAMC,OAAOA,CACTC,KAA2B,EAC2B;IACtD;IACA,MAAMC,YAAY,GAAG,MAAM,IAAI,CAACN,aAAa,CAACI,OAAO,CAACC,KAAK,CAAC;;IAE5D;IACA,IAAIC,YAAY,CAACC,MAAM,CAAC,CAAC,EAAE;MACvB,IAAID,YAAY,CAACE,KAAK,YAAYb,uBAAuB,EAAE;QACvD,MAAMc,UAAU,GAAG,MAAM,IAAI,CAACR,SAAS,CAACG,OAAO,CAACC,KAAK,CAAC;QACtD,IAAII,UAAU,CAACF,MAAM,CAAC,CAAC,EAAE;UACrB,OAAOnB,MAAM,CAACsB,IAAI,CAAC,IAAIb,oBAAoB,CAACY,UAAU,CAACD,KAAK,CAAC,CAAC;QAClE;QACA,OAAOpB,MAAM,CAACuB,EAAE,CAACF,UAAU,CAACG,KAAK,CAAC;MACtC;MACA,OAAOxB,MAAM,CAACsB,IAAI,CAACJ,YAAY,CAACE,KAAK,CAAC;IAC1C;IAEA,MAAMK,MAAM,GAAGP,YAAY,CAACM,KAAK;;IAEjC;IACA,IAAIC,MAAM,CAACC,SAAS,CAAC,CAAC,EAAE;MACpB,MAAMC,YAAY,GAAG,MAAM,IAAI,CAACb,UAAU,CAACc,MAAM,CAACH,MAAM,CAACI,EAAE,EAAE,IAAI,CAAC;MAClE,IAAIF,YAAY,CAACR,MAAM,CAAC,CAAC,EAAE;QACvB,OAAOnB,MAAM,CAACsB,IAAI,CAAC,IAAIb,oBAAoB,CAACkB,YAAY,CAACP,KAAK,CAAC,CAAC;MACpE;MACA,OAAOpB,MAAM,CAACuB,EAAE,CAACI,YAAY,CAACH,KAAK,CAAC;IACxC;;IAEA;IACA,MAAMM,QAAQ,GAAG,IAAI,CAACf,eAAe,CAACgB,WAAW,CAAC,CAAC;IACnD,IAAIN,MAAM,CAACO,QAAQ,CAACH,EAAE,KAAKC,QAAQ,CAACD,EAAE,EAAE;MACpC,OAAO7B,MAAM,CAACsB,IAAI,CACd,IAAId,qBAAqB,CAAC;QACtByB,SAAS,EAAEH,QAAQ,CAACD,EAAE;QACtBK,QAAQ,EAAET,MAAM,CAACO,QAAQ,CAACH;MAC9B,CAAC,CACL,CAAC;IACL;;IAEA;IACA,MAAMF,YAAY,GAAG,MAAM,IAAI,CAACb,UAAU,CAACc,MAAM,CAACH,MAAM,CAACI,EAAE,EAAE,KAAK,CAAC;IACnE,IAAIF,YAAY,CAACR,MAAM,CAAC,CAAC,EAAE;MACvB,OAAOnB,MAAM,CAACsB,IAAI,CAAC,IAAIb,oBAAoB,CAACkB,YAAY,CAACP,KAAK,CAAC,CAAC;IACpE;IAEA,OAAOpB,MAAM,CAACuB,EAAE,CAACI,YAAY,CAACH,KAAK,CAAC;EACxC;AACJ;AAEA,OAAO,MAAMvB,sBAAsB,GAAGC,kBAAkB,CAACiC,oBAAoB,CAAC;EAC1EC,cAAc,EAAE1B,0BAA0B;EAC1C2B,YAAY,EAAE,CACVjC,oBAAoB,EACpBC,gBAAgB,EAChBF,yBAAyB,EACzBG,eAAe;AAEvB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { ILockRecord } from "../../domain/LockRecord.js";
|
|
3
|
+
import type { LockRecordEntryType } from "../../domain/types.js";
|
|
4
|
+
import type { LockRecordNotFoundError, LockRecordPersistenceError, IdentityMismatchError, UpdateEntryLockError } from "../../domain/errors.js";
|
|
5
|
+
export interface UpdateEntryLockInput {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LockRecordEntryType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* UpdateEntryLock Use Case - Updates lock timestamp to keep it alive
|
|
11
|
+
*/
|
|
12
|
+
export interface IUpdateEntryLockUseCase {
|
|
13
|
+
execute(input: UpdateEntryLockInput): Promise<Result<ILockRecord, UseCaseError>>;
|
|
14
|
+
}
|
|
15
|
+
export interface IUpdateEntryLockUseCaseErrors {
|
|
16
|
+
notFound: LockRecordNotFoundError;
|
|
17
|
+
notSameIdentity: IdentityMismatchError;
|
|
18
|
+
persistence: LockRecordPersistenceError;
|
|
19
|
+
updateError: UpdateEntryLockError;
|
|
20
|
+
}
|
|
21
|
+
type UseCaseError = IUpdateEntryLockUseCaseErrors[keyof IUpdateEntryLockUseCaseErrors];
|
|
22
|
+
export declare const UpdateEntryLockUseCase: import("@webiny/di").Abstraction<IUpdateEntryLockUseCase>;
|
|
23
|
+
export declare namespace UpdateEntryLockUseCase {
|
|
24
|
+
type Interface = IUpdateEntryLockUseCase;
|
|
25
|
+
type Error = UseCaseError;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* UpdateEntryLockRepository - Updates lock record in storage
|
|
29
|
+
*/
|
|
30
|
+
export interface IUpdateEntryLockRepository {
|
|
31
|
+
update(lockRecordId: string, updateOwner: boolean): Promise<Result<ILockRecord, RepositoryError>>;
|
|
32
|
+
}
|
|
33
|
+
export interface IUpdateEntryLockRepositoryErrors {
|
|
34
|
+
persistence: LockRecordPersistenceError;
|
|
35
|
+
}
|
|
36
|
+
type RepositoryError = IUpdateEntryLockRepositoryErrors[keyof IUpdateEntryLockRepositoryErrors];
|
|
37
|
+
export declare const UpdateEntryLockRepository: import("@webiny/di").Abstraction<IUpdateEntryLockRepository>;
|
|
38
|
+
export declare namespace UpdateEntryLockRepository {
|
|
39
|
+
type Interface = IUpdateEntryLockRepository;
|
|
40
|
+
type Error = RepositoryError;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
// Input types
|
|
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");
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","UpdateEntryLockUseCase","UpdateEntryLockRepository"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAWvD;;AAMA;AACA;AACA;;AAcA,OAAO,MAAMC,sBAAsB,GAC/BD,iBAAiB,CAA0B,wBAAwB,CAAC;;AAOxE;AACA;AACA;;AAcA,OAAO,MAAME,yBAAyB,GAAGF,iBAAiB,CACtD,2BACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UpdateEntryLockFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateEntryLockUseCase } from "./UpdateEntryLockUseCase.js";
|
|
3
|
+
import { UpdateEntryLockRepository } from "./UpdateEntryLockRepository.js";
|
|
4
|
+
export const UpdateEntryLockFeature = createFeature({
|
|
5
|
+
name: "UpdateEntryLock",
|
|
6
|
+
register(container) {
|
|
7
|
+
container.register(UpdateEntryLockUseCase);
|
|
8
|
+
container.register(UpdateEntryLockRepository).inSingletonScope();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","UpdateEntryLockUseCase","UpdateEntryLockRepository","UpdateEntryLockFeature","name","register","container","inSingletonScope"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,sBAAsB;AAC/B,SAASC,yBAAyB;AAElC,OAAO,MAAMC,sBAAsB,GAAGH,aAAa,CAAC;EAChDI,IAAI,EAAE,iBAAiB;EACvBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACJ,sBAAsB,CAAC;IAC1CK,SAAS,CAACD,QAAQ,CAACH,yBAAyB,CAAC,CAACK,gBAAgB,CAAC,CAAC;EACpE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./abstractions.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/IdentityContext";
|
|
2
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared";
|
|
3
|
+
/**
|
|
4
|
+
* Simple permission check. Only authenticated users can access the websockets API via GraphQL
|
|
5
|
+
*/
|
|
6
|
+
export const checkPermissions = async context => {
|
|
7
|
+
const identityContext = context.container.resolve(IdentityContext);
|
|
8
|
+
const identity = identityContext.getIdentity();
|
|
9
|
+
if (identity.isAnonymous()) {
|
|
10
|
+
throw new NotAuthorizedError();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IdentityContext","NotAuthorizedError","checkPermissions","context","identityContext","container","resolve","identity","getIdentity","isAnonymous"],"sources":["checkPermissions.ts"],"sourcesContent":["import { IdentityContext } from \"@webiny/api-core/features/IdentityContext\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\n/**\n * Simple permission check. Only authenticated users can access the websockets API via GraphQL\n */\nexport const checkPermissions = async (context: ApiCoreContext): Promise<void> => {\n const identityContext = context.container.resolve(IdentityContext);\n const identity = identityContext.getIdentity();\n\n if (identity.isAnonymous()) {\n throw new NotAuthorizedError();\n }\n};\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,2CAA2C;AAC3E,SAASC,kBAAkB,QAAQ,2CAA2C;AAG9E;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAG,MAAOC,OAAuB,IAAoB;EAC9E,MAAMC,eAAe,GAAGD,OAAO,CAACE,SAAS,CAACC,OAAO,CAACN,eAAe,CAAC;EAClE,MAAMO,QAAQ,GAAGH,eAAe,CAACI,WAAW,CAAC,CAAC;EAE9C,IAAID,QAAQ,CAACE,WAAW,CAAC,CAAC,EAAE;IACxB,MAAM,IAAIR,kBAAkB,CAAC,CAAC;EAClC;AACJ,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ErrorResponse, Response } from "@webiny/handler-graphql";
|
|
2
|
-
import { IRecordLockingMeta } from "../types";
|
|
2
|
+
import type { IRecordLockingMeta } from "../types.js";
|
|
3
3
|
export declare const resolve: <T>(cb: () => Promise<T>) => Promise<Response<T> | ErrorResponse>;
|
|
4
4
|
export interface IListResponse<T> {
|
|
5
5
|
items: T[];
|
|
6
6
|
meta: IRecordLockingMeta;
|
|
7
7
|
}
|
|
8
|
-
export declare const resolveList: <T>(cb: () => Promise<IListResponse<T>>) => Promise<
|
|
8
|
+
export declare const resolveList: <T>(cb: () => Promise<IListResponse<T>>) => Promise<Response<T[]> | ErrorResponse>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "@webiny/handler-graphql";
|
|
2
|
+
export const resolve = async cb => {
|
|
3
|
+
try {
|
|
4
|
+
const result = await cb();
|
|
5
|
+
return new Response(result);
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
return new ErrorResponse(ex);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const resolveList = async cb => {
|
|
11
|
+
try {
|
|
12
|
+
const {
|
|
13
|
+
items,
|
|
14
|
+
meta
|
|
15
|
+
} = await cb();
|
|
16
|
+
return new ListResponse(items, meta);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
return new ListErrorResponse(ex);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ErrorResponse","ListErrorResponse","ListResponse","Response","resolve","cb","result","ex","resolveList","items","meta"],"sources":["resolve.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"@webiny/handler-graphql\";\nimport type { IRecordLockingMeta } from \"~/types.js\";\n\nexport const resolve = async <T>(cb: () => Promise<T>): Promise<Response<T> | ErrorResponse> => {\n try {\n const result = await cb();\n return new Response<T>(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\nexport interface IListResponse<T> {\n items: T[];\n meta: IRecordLockingMeta;\n}\n\nexport const resolveList = async <T>(\n cb: () => Promise<IListResponse<T>>\n): Promise<Response<T[]> | ErrorResponse> => {\n try {\n const { items, meta } = await cb();\n return new ListResponse(items, meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,yBAAyB;AAGlG,OAAO,MAAMC,OAAO,GAAG,MAAUC,EAAoB,IAA2C;EAC5F,IAAI;IACA,MAAMC,MAAM,GAAG,MAAMD,EAAE,CAAC,CAAC;IACzB,OAAO,IAAIF,QAAQ,CAAIG,MAAM,CAAC;EAClC,CAAC,CAAC,OAAOC,EAAE,EAAE;IACT,OAAO,IAAIP,aAAa,CAACO,EAAE,CAAC;EAChC;AACJ,CAAC;AAOD,OAAO,MAAMC,WAAW,GAAG,MACvBH,EAAmC,IACM;EACzC,IAAI;IACA,MAAM;MAAEI,KAAK;MAAEC;IAAK,CAAC,GAAG,MAAML,EAAE,CAAC,CAAC;IAClC,OAAO,IAAIH,YAAY,CAACO,KAAK,EAAEC,IAAI,CAAC;EACxC,CAAC,CAAC,OAAOH,EAAE,EAAE;IACT,OAAO,IAAIN,iBAAiB,CAACM,EAAE,CAAC;EACpC;AACJ,CAAC","ignoreList":[]}
|
package/graphql/schema.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { IGraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
2
|
+
import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
|
|
3
|
+
import { CmsModel } from "@webiny/api-headless-cms/types/model.js";
|
|
4
|
+
import type { CmsFieldTypePlugins } from "@webiny/api-headless-cms/types/index.js";
|
|
3
5
|
interface Params {
|
|
4
|
-
|
|
6
|
+
model: CmsModel;
|
|
7
|
+
models: CmsModel[];
|
|
8
|
+
fieldTypePlugins: CmsFieldTypePlugins;
|
|
5
9
|
}
|
|
6
|
-
export declare const createGraphQLSchema: (params: Params) => Promise<IGraphQLSchemaPlugin<
|
|
10
|
+
export declare const createGraphQLSchema: (params: Params) => Promise<IGraphQLSchemaPlugin<ApiCoreContext>>;
|
|
7
11
|
export {};
|
package/graphql/schema.js
CHANGED
|
@@ -1,51 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve, resolveList } from "./resolve.js";
|
|
2
|
+
import { createGraphQLSchemaPlugin } from "@webiny/handler-graphql";
|
|
3
|
+
import { renderFields } from "@webiny/api-headless-cms/utils/renderFields.js";
|
|
4
|
+
import { renderListFilterFields } from "@webiny/api-headless-cms/utils/renderListFilterFields.js";
|
|
5
|
+
import { renderSortEnum } from "@webiny/api-headless-cms/utils/renderSortEnum.js";
|
|
6
|
+
import { checkPermissions } from "./checkPermissions.js";
|
|
7
|
+
import { IsEntryLockedUseCase } from "../features/IsEntryLocked/abstractions.js";
|
|
8
|
+
import { GetLockRecordUseCase } from "../features/GetLockRecord/abstractions.js";
|
|
9
|
+
import { GetLockedEntryLockRecordUseCase } from "../features/GetLockedEntryLockRecord/abstractions.js";
|
|
10
|
+
import { ListLockRecordsUseCase } from "../features/ListLockRecords/abstractions.js";
|
|
11
|
+
import { ListAllLockRecordsUseCase } from "../features/ListAllLockRecords/abstractions.js";
|
|
12
|
+
import { LockEntryUseCase } from "../features/LockEntry/abstractions.js";
|
|
13
|
+
import { UpdateEntryLockUseCase } from "../features/UpdateEntryLock/abstractions.js";
|
|
14
|
+
import { UnlockEntryUseCase } from "../features/UnlockEntry/abstractions.js";
|
|
15
|
+
import { UnlockEntryRequestUseCase } from "../features/UnlockEntryRequest/abstractions.js";
|
|
16
|
+
export const createGraphQLSchema = async params => {
|
|
17
|
+
// Record locking model
|
|
18
|
+
const model = params.model;
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.createGraphQLSchema = void 0;
|
|
7
|
-
var _resolve = require("../utils/resolve");
|
|
8
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
9
|
-
var _renderFields = require("@webiny/api-headless-cms/utils/renderFields");
|
|
10
|
-
var _createFieldTypePluginRecords = require("@webiny/api-headless-cms/graphql/schema/createFieldTypePluginRecords");
|
|
11
|
-
var _renderListFilterFields = require("@webiny/api-headless-cms/utils/renderListFilterFields");
|
|
12
|
-
var _renderSortEnum = require("@webiny/api-headless-cms/utils/renderSortEnum");
|
|
13
|
-
var _checkPermissions = require("../utils/checkPermissions");
|
|
14
|
-
const createGraphQLSchema = async params => {
|
|
15
|
-
const context = params.context;
|
|
16
|
-
const model = await context.recordLocking.getModel();
|
|
17
|
-
const models = await context.security.withoutAuthorization(async () => {
|
|
18
|
-
return (await context.cms.listModels()).filter(model => {
|
|
19
|
-
if (model.fields.length === 0) {
|
|
20
|
-
return false;
|
|
21
|
-
} else if (model.isPrivate) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
});
|
|
20
|
+
// Other public models that have at least one field
|
|
21
|
+
const models = params.models.filter(model => {
|
|
22
|
+
return model.fields.length > 0;
|
|
26
23
|
});
|
|
27
|
-
const fieldTypePlugins =
|
|
28
|
-
const recordLockingFields =
|
|
24
|
+
const fieldTypePlugins = params.fieldTypePlugins;
|
|
25
|
+
const recordLockingFields = renderFields({
|
|
29
26
|
models,
|
|
30
27
|
model,
|
|
31
28
|
fields: model.fields,
|
|
32
29
|
type: "manage",
|
|
33
30
|
fieldTypePlugins
|
|
34
31
|
});
|
|
35
|
-
const listFilterFieldsRender =
|
|
32
|
+
const listFilterFieldsRender = renderListFilterFields({
|
|
36
33
|
model,
|
|
37
34
|
fields: model.fields,
|
|
38
35
|
type: "manage",
|
|
39
36
|
fieldTypePlugins,
|
|
40
37
|
excludeFields: ["entryId"]
|
|
41
38
|
});
|
|
42
|
-
const sortEnumRender =
|
|
39
|
+
const sortEnumRender = renderSortEnum({
|
|
43
40
|
model,
|
|
44
41
|
fields: model.fields,
|
|
45
42
|
fieldTypePlugins,
|
|
46
43
|
sorterPlugins: []
|
|
47
44
|
});
|
|
48
|
-
const plugin =
|
|
45
|
+
const plugin = createGraphQLSchemaPlugin({
|
|
49
46
|
typeDefs: /* GraphQL */`
|
|
50
47
|
${recordLockingFields.map(f => f.typeDefs).join("\n")}
|
|
51
48
|
|
|
@@ -126,7 +123,7 @@ const createGraphQLSchema = async params => {
|
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
input RecordLockingListWhereInput {
|
|
129
|
-
${listFilterFieldsRender}
|
|
126
|
+
${listFilterFieldsRender.allFiltersAsString()}
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
enum RecordLockingListSorter {
|
|
@@ -188,85 +185,127 @@ const createGraphQLSchema = async params => {
|
|
|
188
185
|
},
|
|
189
186
|
RecordLockingQuery: {
|
|
190
187
|
async isEntryLocked(_, args, context) {
|
|
191
|
-
return
|
|
192
|
-
await
|
|
193
|
-
|
|
188
|
+
return resolve(async () => {
|
|
189
|
+
await checkPermissions(context);
|
|
190
|
+
const useCase = context.container.resolve(IsEntryLockedUseCase);
|
|
191
|
+
const result = await useCase.execute({
|
|
194
192
|
id: args.id,
|
|
195
193
|
type: args.type
|
|
196
194
|
});
|
|
195
|
+
if (result.isFail()) {
|
|
196
|
+
throw result.error;
|
|
197
|
+
}
|
|
198
|
+
return result.value;
|
|
197
199
|
});
|
|
198
200
|
},
|
|
199
201
|
async getLockRecord(_, args, context) {
|
|
200
|
-
return
|
|
201
|
-
await
|
|
202
|
-
const
|
|
202
|
+
return resolve(async () => {
|
|
203
|
+
await checkPermissions(context);
|
|
204
|
+
const useCase = context.container.resolve(GetLockRecordUseCase);
|
|
205
|
+
const result = await useCase.execute({
|
|
203
206
|
id: args.id,
|
|
204
207
|
type: args.type
|
|
205
208
|
});
|
|
206
|
-
if (result) {
|
|
207
|
-
|
|
209
|
+
if (result.isFail()) {
|
|
210
|
+
throw result.error;
|
|
208
211
|
}
|
|
209
|
-
|
|
212
|
+
return result.value;
|
|
210
213
|
});
|
|
211
214
|
},
|
|
212
215
|
async getLockedEntryLockRecord(_, args, context) {
|
|
213
|
-
return
|
|
214
|
-
await
|
|
215
|
-
|
|
216
|
+
return resolve(async () => {
|
|
217
|
+
await checkPermissions(context);
|
|
218
|
+
const useCase = context.container.resolve(GetLockedEntryLockRecordUseCase);
|
|
219
|
+
const result = await useCase.execute({
|
|
216
220
|
id: args.id,
|
|
217
221
|
type: args.type
|
|
218
222
|
});
|
|
223
|
+
// Returns null if not found/expired/locked by current user
|
|
224
|
+
if (result.isFail()) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return result.value;
|
|
219
228
|
});
|
|
220
229
|
},
|
|
221
230
|
async listLockRecords(_, args, context) {
|
|
222
|
-
return
|
|
223
|
-
await
|
|
224
|
-
|
|
231
|
+
return resolveList(async () => {
|
|
232
|
+
await checkPermissions(context);
|
|
233
|
+
const useCase = context.container.resolve(ListLockRecordsUseCase);
|
|
234
|
+
const result = await useCase.execute(args);
|
|
235
|
+
if (result.isFail()) {
|
|
236
|
+
throw result.error;
|
|
237
|
+
}
|
|
238
|
+
return result.value;
|
|
225
239
|
});
|
|
226
240
|
},
|
|
227
241
|
listAllLockRecords(_, args, context) {
|
|
228
|
-
return
|
|
229
|
-
await
|
|
230
|
-
|
|
242
|
+
return resolveList(async () => {
|
|
243
|
+
await checkPermissions(context);
|
|
244
|
+
const useCase = context.container.resolve(ListAllLockRecordsUseCase);
|
|
245
|
+
const result = await useCase.execute(args);
|
|
246
|
+
if (result.isFail()) {
|
|
247
|
+
throw result.error;
|
|
248
|
+
}
|
|
249
|
+
return result.value;
|
|
231
250
|
});
|
|
232
251
|
}
|
|
233
252
|
},
|
|
234
253
|
RecordLockingMutation: {
|
|
235
254
|
async lockEntry(_, args, context) {
|
|
236
|
-
return
|
|
237
|
-
await
|
|
238
|
-
|
|
255
|
+
return resolve(async () => {
|
|
256
|
+
await checkPermissions(context);
|
|
257
|
+
const useCase = context.container.resolve(LockEntryUseCase);
|
|
258
|
+
const result = await useCase.execute({
|
|
239
259
|
id: args.id,
|
|
240
260
|
type: args.type
|
|
241
261
|
});
|
|
262
|
+
if (result.isFail()) {
|
|
263
|
+
throw result.error;
|
|
264
|
+
}
|
|
265
|
+
return result.value;
|
|
242
266
|
});
|
|
243
267
|
},
|
|
244
268
|
async updateEntryLock(_, args, context) {
|
|
245
|
-
return
|
|
246
|
-
await
|
|
247
|
-
|
|
269
|
+
return resolve(async () => {
|
|
270
|
+
await checkPermissions(context);
|
|
271
|
+
const useCase = context.container.resolve(UpdateEntryLockUseCase);
|
|
272
|
+
const result = await useCase.execute({
|
|
248
273
|
id: args.id,
|
|
249
274
|
type: args.type
|
|
250
275
|
});
|
|
276
|
+
if (result.isFail()) {
|
|
277
|
+
throw result.error;
|
|
278
|
+
}
|
|
279
|
+
return result.value;
|
|
251
280
|
});
|
|
252
281
|
},
|
|
253
282
|
async unlockEntry(_, args, context) {
|
|
254
|
-
return
|
|
255
|
-
await
|
|
256
|
-
|
|
283
|
+
return resolve(async () => {
|
|
284
|
+
await checkPermissions(context);
|
|
285
|
+
const useCase = context.container.resolve(UnlockEntryUseCase);
|
|
286
|
+
const result = await useCase.execute({
|
|
257
287
|
id: args.id,
|
|
258
288
|
type: args.type,
|
|
259
289
|
force: args.force
|
|
260
290
|
});
|
|
291
|
+
if (result.isFail()) {
|
|
292
|
+
throw result.error;
|
|
293
|
+
}
|
|
294
|
+
return result.value;
|
|
261
295
|
});
|
|
262
296
|
},
|
|
263
297
|
async unlockEntryRequest(_, args, context) {
|
|
264
|
-
return
|
|
265
|
-
await
|
|
266
|
-
|
|
298
|
+
return resolve(async () => {
|
|
299
|
+
await checkPermissions(context);
|
|
300
|
+
const useCase = context.container.resolve(UnlockEntryRequestUseCase);
|
|
301
|
+
const result = await useCase.execute({
|
|
267
302
|
id: args.id,
|
|
268
303
|
type: args.type
|
|
269
304
|
});
|
|
305
|
+
if (result.isFail()) {
|
|
306
|
+
throw result.error;
|
|
307
|
+
}
|
|
308
|
+
return result.value;
|
|
270
309
|
});
|
|
271
310
|
}
|
|
272
311
|
}
|
|
@@ -275,6 +314,5 @@ const createGraphQLSchema = async params => {
|
|
|
275
314
|
plugin.name = "recordLocking.graphql.schema.locking";
|
|
276
315
|
return plugin;
|
|
277
316
|
};
|
|
278
|
-
exports.createGraphQLSchema = createGraphQLSchema;
|
|
279
317
|
|
|
280
318
|
//# sourceMappingURL=schema.js.map
|