@webiny/api-record-locking 6.4.12-beta.5 → 6.5.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.
@@ -1,12 +1,12 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
- import { WebsocketService } from "@webiny/api-websockets/features/WebsocketService/index.js";
3
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-websockets/features/SendToIdentity/abstractions.js";
4
4
  import { KickOutCurrentUserUseCase as UseCaseAbstraction } from "./abstractions.js";
5
5
  import type { ILockRecord } from "../../domain/index.js";
6
6
  declare class KickOutCurrentUserUseCaseImpl implements UseCaseAbstraction.Interface {
7
7
  private identityContext;
8
- private websocketService?;
9
- constructor(identityContext: IdentityContext.Interface, websocketService?: WebsocketService.Interface | undefined);
8
+ private sendToIdentity;
9
+ constructor(identityContext: IdentityContext.Interface, sendToIdentity: WebsocketsSendToIdentityUseCase.Interface);
10
10
  execute(record: ILockRecord): Promise<Result<void, UseCaseAbstraction.Error>>;
11
11
  }
12
12
  export declare const KickOutCurrentUserUseCase: typeof KickOutCurrentUserUseCaseImpl & {
@@ -1,19 +1,18 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
3
- import { WebsocketService } from "@webiny/api-websockets/features/WebsocketService/index.js";
3
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-websockets/features/SendToIdentity/abstractions.js";
4
4
  import { parseIdentifier } from "@webiny/utils";
5
5
  import { KickOutCurrentUserUseCase } from "./abstractions.js";
6
6
  class KickOutCurrentUserUseCaseImpl {
7
- constructor(identityContext, websocketService){
7
+ constructor(identityContext, sendToIdentity){
8
8
  this.identityContext = identityContext;
9
- this.websocketService = websocketService;
9
+ this.sendToIdentity = sendToIdentity;
10
10
  }
11
11
  async execute(record) {
12
- if (!this.websocketService) return Result.ok();
13
12
  const { lockedBy, id } = record;
14
13
  const { id: entryId } = parseIdentifier(id);
15
14
  const identity = this.identityContext.getIdentity();
16
- await this.websocketService.send({
15
+ await this.sendToIdentity.execute({
17
16
  id: lockedBy.id
18
17
  }, {
19
18
  action: `recordLocking.entry.kickOut.${entryId}`,
@@ -29,12 +28,7 @@ const KickOutCurrentUserUseCase_KickOutCurrentUserUseCase = KickOutCurrentUserUs
29
28
  implementation: KickOutCurrentUserUseCaseImpl,
30
29
  dependencies: [
31
30
  IdentityContext,
32
- [
33
- WebsocketService,
34
- {
35
- optional: true
36
- }
37
- ]
31
+ WebsocketsSendToIdentityUseCase
38
32
  ]
39
33
  });
40
34
  export { KickOutCurrentUserUseCase_KickOutCurrentUserUseCase as KickOutCurrentUserUseCase };
@@ -1 +1 @@
1
- {"version":3,"file":"features/KickOutCurrentUser/KickOutCurrentUserUseCase.js","sources":["../../../src/features/KickOutCurrentUser/KickOutCurrentUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { WebsocketService } from \"@webiny/api-websockets/features/WebsocketService/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { KickOutCurrentUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { ILockRecord } from \"~/domain/index.js\";\n\nclass KickOutCurrentUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private websocketService?: WebsocketService.Interface\n ) {}\n\n async execute(record: ILockRecord): Promise<Result<void, UseCaseAbstraction.Error>> {\n if (!this.websocketService) {\n return Result.ok();\n }\n\n const { lockedBy, id } = record;\n\n const { id: entryId } = parseIdentifier(id);\n const identity = this.identityContext.getIdentity();\n\n await this.websocketService.send(\n { id: lockedBy.id },\n {\n action: `recordLocking.entry.kickOut.${entryId}`,\n data: {\n record: record.toObject(),\n user: identity\n }\n }\n );\n\n return Result.ok();\n }\n}\n\nexport const KickOutCurrentUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: KickOutCurrentUserUseCaseImpl,\n dependencies: [IdentityContext, [WebsocketService, { optional: true }]]\n});\n"],"names":["KickOutCurrentUserUseCaseImpl","identityContext","websocketService","record","Result","lockedBy","id","entryId","parseIdentifier","identity","KickOutCurrentUserUseCase","UseCaseAbstraction","IdentityContext","WebsocketService"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,gBAA6C,CACvD;aAFUD,eAAe,GAAfA;aACAC,gBAAgB,GAAhBA;IACT;IAEH,MAAM,QAAQC,MAAmB,EAAmD;QAChF,IAAI,CAAC,IAAI,CAAC,gBAAgB,EACtB,OAAOC,OAAO,EAAE;QAGpB,MAAM,EAAEC,QAAQ,EAAEC,EAAE,EAAE,GAAGH;QAEzB,MAAM,EAAE,IAAII,OAAO,EAAE,GAAGC,gBAAgBF;QACxC,MAAMG,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAEjD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAC5B;YAAE,IAAIJ,SAAS,EAAE;QAAC,GAClB;YACI,QAAQ,CAAC,4BAA4B,EAAEE,SAAS;YAChD,MAAM;gBACF,QAAQJ,OAAO,QAAQ;gBACvB,MAAMM;YACV;QACJ;QAGJ,OAAOL,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMM,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBX;IAChB,cAAc;QAACY;QAAiB;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;KAAC;AAC3E"}
1
+ {"version":3,"file":"features/KickOutCurrentUser/KickOutCurrentUserUseCase.js","sources":["../../../src/features/KickOutCurrentUser/KickOutCurrentUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { WebsocketsSendToIdentityUseCase } from \"@webiny/api-websockets/features/SendToIdentity/abstractions.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { KickOutCurrentUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { ILockRecord } from \"~/domain/index.js\";\n\nclass KickOutCurrentUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private sendToIdentity: WebsocketsSendToIdentityUseCase.Interface\n ) {}\n\n async execute(record: ILockRecord): Promise<Result<void, UseCaseAbstraction.Error>> {\n const { lockedBy, id } = record;\n\n const { id: entryId } = parseIdentifier(id);\n const identity = this.identityContext.getIdentity();\n\n await this.sendToIdentity.execute(\n { id: lockedBy.id },\n {\n action: `recordLocking.entry.kickOut.${entryId}`,\n data: {\n record: record.toObject(),\n user: identity\n }\n }\n );\n\n return Result.ok();\n }\n}\n\nexport const KickOutCurrentUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: KickOutCurrentUserUseCaseImpl,\n dependencies: [IdentityContext, WebsocketsSendToIdentityUseCase]\n});\n"],"names":["KickOutCurrentUserUseCaseImpl","identityContext","sendToIdentity","record","lockedBy","id","entryId","parseIdentifier","identity","Result","KickOutCurrentUserUseCase","UseCaseAbstraction","IdentityContext","WebsocketsSendToIdentityUseCase"],"mappings":";;;;;AAOA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAyD,CACnE;aAFUD,eAAe,GAAfA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,MAAmB,EAAmD;QAChF,MAAM,EAAEC,QAAQ,EAAEC,EAAE,EAAE,GAAGF;QAEzB,MAAM,EAAE,IAAIG,OAAO,EAAE,GAAGC,gBAAgBF;QACxC,MAAMG,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAEjD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B;YAAE,IAAIJ,SAAS,EAAE;QAAC,GAClB;YACI,QAAQ,CAAC,4BAA4B,EAAEE,SAAS;YAChD,MAAM;gBACF,QAAQH,OAAO,QAAQ;gBACvB,MAAMK;YACV;QACJ;QAGJ,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBX;IAChB,cAAc;QAACY;QAAiBC;KAAgC;AACpE"}
@@ -1,13 +1,15 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { ListAllLockRecordsRepository as RepositoryAbstraction, ListAllLockRecordsInput, ListAllLockRecordsOutput } from "./abstractions.js";
3
3
  import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries";
4
- import { RecordLockingConfig } from "../../domain/abstractions.js";
5
4
  import type { CmsModel } from "@webiny/api-headless-cms/types";
5
+ import { CmsWhereMapper } from "@webiny/api-headless-cms";
6
+ import { RecordLockingConfig } from "../../domain/abstractions.js";
6
7
  declare class ListAllLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {
7
8
  private config;
8
9
  private listEntries;
9
10
  private model;
10
- constructor(config: RecordLockingConfig.Interface, listEntries: ListLatestEntriesUseCase.Interface, model: CmsModel);
11
+ private cmsWhereMapper;
12
+ constructor(config: RecordLockingConfig.Interface, listEntries: ListLatestEntriesUseCase.Interface, model: CmsModel, cmsWhereMapper: CmsWhereMapper.Interface);
11
13
  execute(input?: ListAllLockRecordsInput): Promise<Result<ListAllLockRecordsOutput, RepositoryAbstraction.Error>>;
12
14
  }
13
15
  export declare const ListAllLockRecordsRepository: typeof ListAllLockRecordsRepositoryImpl & {
@@ -1,21 +1,26 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { ListAllLockRecordsRepository } from "./abstractions.js";
3
3
  import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries";
4
+ import { CmsWhereMapper } from "@webiny/api-headless-cms";
4
5
  import { RecordLockingConfig, RecordLockingModel } from "../../domain/abstractions.js";
5
6
  import { LockRecordPersistenceError } from "../../domain/errors.js";
6
7
  import { convertWhereCondition } from "../../utils/convertWhereCondition.js";
7
8
  import { LockRecord } from "../../domain/LockRecord.js";
8
9
  class ListAllLockRecordsRepositoryImpl {
9
- constructor(config, listEntries, model){
10
+ constructor(config, listEntries, model, cmsWhereMapper){
10
11
  this.config = config;
11
12
  this.listEntries = listEntries;
12
13
  this.model = model;
14
+ this.cmsWhereMapper = cmsWhereMapper;
13
15
  }
14
16
  async execute(input) {
15
17
  try {
16
18
  const params = {
17
19
  ...input,
18
- where: convertWhereCondition(input?.where)
20
+ where: this.cmsWhereMapper.map({
21
+ input: convertWhereCondition(input?.where),
22
+ fields: this.model.fields
23
+ })
19
24
  };
20
25
  const result = await this.listEntries.execute(this.model, params);
21
26
  if (result.isFail()) return Result.fail(new LockRecordPersistenceError(result.error));
@@ -35,7 +40,8 @@ const ListAllLockRecordsRepository_ListAllLockRecordsRepository = ListAllLockRec
35
40
  dependencies: [
36
41
  RecordLockingConfig,
37
42
  ListLatestEntriesUseCase,
38
- RecordLockingModel
43
+ RecordLockingModel,
44
+ CmsWhereMapper
39
45
  ]
40
46
  });
41
47
  export { ListAllLockRecordsRepository_ListAllLockRecordsRepository as ListAllLockRecordsRepository };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ListAllLockRecords/ListAllLockRecordsRepository.js","sources":["../../../src/features/ListAllLockRecords/ListAllLockRecordsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListAllLockRecordsRepository as RepositoryAbstraction,\n ListAllLockRecordsInput,\n ListAllLockRecordsOutput\n} from \"./abstractions.js\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/index.js\";\n\nclass ListAllLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private config: RecordLockingConfig.Interface,\n private listEntries: ListLatestEntriesUseCase.Interface,\n private model: CmsModel\n ) {}\n\n async execute(\n input?: ListAllLockRecordsInput\n ): Promise<Result<ListAllLockRecordsOutput, RepositoryAbstraction.Error>> {\n try {\n const params = {\n ...input,\n where: convertWhereCondition(input?.where)\n };\n\n const result = await this.listEntries.execute<LockRecordValues>(this.model, params);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n const { entries, meta } = result.value;\n\n const items = entries.map(entry => new LockRecord(entry, this.config.timeout));\n\n return Result.ok({\n items,\n meta\n });\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const ListAllLockRecordsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListAllLockRecordsRepositoryImpl,\n dependencies: [RecordLockingConfig, ListLatestEntriesUseCase, RecordLockingModel]\n});\n"],"names":["ListAllLockRecordsRepositoryImpl","config","listEntries","model","input","params","convertWhereCondition","result","Result","LockRecordPersistenceError","entries","meta","items","entry","LockRecord","error","ListAllLockRecordsRepository","RepositoryAbstraction","RecordLockingConfig","ListLatestEntriesUseCase","RecordLockingModel"],"mappings":";;;;;;;AAcA,MAAMA;IACF,YACYC,MAAqC,EACrCC,WAA+C,EAC/CC,KAAe,CACzB;aAHUF,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,QACFC,KAA+B,EACuC;QACtE,IAAI;YACA,MAAMC,SAAS;gBACX,GAAGD,KAAK;gBACR,OAAOE,sBAAsBF,OAAO;YACxC;YAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAmB,IAAI,CAAC,KAAK,EAAEF;YAE5E,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAGlE,MAAM,EAAEG,OAAO,EAAEC,IAAI,EAAE,GAAGJ,OAAO,KAAK;YAEtC,MAAMK,QAAQF,QAAQ,GAAG,CAACG,CAAAA,QAAS,IAAIC,WAAWD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5E,OAAOL,OAAO,EAAE,CAAC;gBACbI;gBACAD;YACJ;QACJ,EAAE,OAAOI,OAAO;YACZ,OAAOP,OAAO,IAAI,CAAC,IAAIC,2BAA2BM;QACtD;IACJ;AACJ;AAEO,MAAMC,4DAA+BC,6BAAAA,oBAA0C,CAAC;IACnF,gBAAgBjB;IAChB,cAAc;QAACkB;QAAqBC;QAA0BC;KAAmB;AACrF"}
1
+ {"version":3,"file":"features/ListAllLockRecords/ListAllLockRecordsRepository.js","sources":["../../../src/features/ListAllLockRecords/ListAllLockRecordsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListAllLockRecordsRepository as RepositoryAbstraction,\n ListAllLockRecordsInput,\n ListAllLockRecordsOutput\n} from \"./abstractions.js\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { CmsWhereMapper } from \"@webiny/api-headless-cms\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/index.js\";\n\nclass ListAllLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private config: RecordLockingConfig.Interface,\n private listEntries: ListLatestEntriesUseCase.Interface,\n private model: CmsModel,\n private cmsWhereMapper: CmsWhereMapper.Interface\n ) {}\n\n async execute(\n input?: ListAllLockRecordsInput\n ): Promise<Result<ListAllLockRecordsOutput, RepositoryAbstraction.Error>> {\n try {\n const params = {\n ...input,\n where: this.cmsWhereMapper.map({\n input: convertWhereCondition(input?.where),\n fields: this.model.fields\n })\n };\n\n const result = await this.listEntries.execute<LockRecordValues>(this.model, params);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n const { entries, meta } = result.value;\n\n const items = entries.map(entry => new LockRecord(entry, this.config.timeout));\n\n return Result.ok({\n items,\n meta\n });\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const ListAllLockRecordsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListAllLockRecordsRepositoryImpl,\n dependencies: [\n RecordLockingConfig,\n ListLatestEntriesUseCase,\n RecordLockingModel,\n CmsWhereMapper\n ]\n});\n"],"names":["ListAllLockRecordsRepositoryImpl","config","listEntries","model","cmsWhereMapper","input","params","convertWhereCondition","result","Result","LockRecordPersistenceError","entries","meta","items","entry","LockRecord","error","ListAllLockRecordsRepository","RepositoryAbstraction","RecordLockingConfig","ListLatestEntriesUseCase","RecordLockingModel","CmsWhereMapper"],"mappings":";;;;;;;;AAeA,MAAMA;IACF,YACYC,MAAqC,EACrCC,WAA+C,EAC/CC,KAAe,EACfC,cAAwC,CAClD;aAJUH,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,KAAK,GAALA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QACFC,KAA+B,EACuC;QACtE,IAAI;YACA,MAAMC,SAAS;gBACX,GAAGD,KAAK;gBACR,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;oBAC3B,OAAOE,sBAAsBF,OAAO;oBACpC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM;gBAC7B;YACJ;YAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAmB,IAAI,CAAC,KAAK,EAAEF;YAE5E,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAGlE,MAAM,EAAEG,OAAO,EAAEC,IAAI,EAAE,GAAGJ,OAAO,KAAK;YAEtC,MAAMK,QAAQF,QAAQ,GAAG,CAACG,CAAAA,QAAS,IAAIC,WAAWD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5E,OAAOL,OAAO,EAAE,CAAC;gBACbI;gBACAD;YACJ;QACJ,EAAE,OAAOI,OAAO;YACZ,OAAOP,OAAO,IAAI,CAAC,IAAIC,2BAA2BM;QACtD;IACJ;AACJ;AAEO,MAAMC,4DAA+BC,6BAAAA,oBAA0C,CAAC;IACnF,gBAAgBlB;IAChB,cAAc;QACVmB;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -2,11 +2,13 @@ import { Result } from "@webiny/feature/api";
2
2
  import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries";
3
3
  import { ListLockRecordsRepository as RepositoryAbstraction, ListLockRecordsInput, ListLockRecordsOutput } from "./abstractions.js";
4
4
  import { RecordLockingConfig, RecordLockingModel } from "../../domain/abstractions.js";
5
+ import { CmsWhereMapper } from "@webiny/api-headless-cms";
5
6
  declare class ListLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {
6
7
  private model;
7
8
  private config;
8
9
  private listEntries;
9
- constructor(model: RecordLockingModel.Interface, config: RecordLockingConfig.Interface, listEntries: ListLatestEntriesUseCase.Interface);
10
+ private cmsWhereMapper;
11
+ constructor(model: RecordLockingModel.Interface, config: RecordLockingConfig.Interface, listEntries: ListLatestEntriesUseCase.Interface, cmsWhereMapper: CmsWhereMapper.Interface);
10
12
  execute(input?: ListLockRecordsInput): Promise<Result<ListLockRecordsOutput, RepositoryAbstraction.Error>>;
11
13
  }
12
14
  export declare const ListLockRecordsRepository: typeof ListLockRecordsRepositoryImpl & {
@@ -4,18 +4,23 @@ import { ListLockRecordsRepository } 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
+ import { CmsWhereMapper } from "@webiny/api-headless-cms";
7
8
  import { convertWhereCondition } from "../../utils/convertWhereCondition.js";
8
9
  class ListLockRecordsRepositoryImpl {
9
- constructor(model, config, listEntries){
10
+ constructor(model, config, listEntries, cmsWhereMapper){
10
11
  this.model = model;
11
12
  this.config = config;
12
13
  this.listEntries = listEntries;
14
+ this.cmsWhereMapper = cmsWhereMapper;
13
15
  }
14
16
  async execute(input) {
15
17
  try {
16
18
  const params = {
17
19
  ...input,
18
- where: convertWhereCondition(input?.where || {})
20
+ where: this.cmsWhereMapper.map({
21
+ input: convertWhereCondition(input?.where),
22
+ fields: this.model.fields
23
+ })
19
24
  };
20
25
  const result = await this.listEntries.execute(this.model, params);
21
26
  if (result.isFail()) return Result.fail(new LockRecordPersistenceError(result.error));
@@ -35,7 +40,8 @@ const ListLockRecordsRepository_ListLockRecordsRepository = ListLockRecordsRepos
35
40
  dependencies: [
36
41
  RecordLockingModel,
37
42
  RecordLockingConfig,
38
- ListLatestEntriesUseCase
43
+ ListLatestEntriesUseCase,
44
+ CmsWhereMapper
39
45
  ]
40
46
  });
41
47
  export { ListLockRecordsRepository_ListLockRecordsRepository as ListLockRecordsRepository };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ListLockRecords/ListLockRecordsRepository.js","sources":["../../../src/features/ListLockRecords/ListLockRecordsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport {\n ListLockRecordsRepository as RepositoryAbstraction,\n ListLockRecordsInput,\n ListLockRecordsOutput\n} from \"./abstractions.js\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/types.js\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition.js\";\n\nclass ListLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.Interface,\n private config: RecordLockingConfig.Interface,\n private listEntries: ListLatestEntriesUseCase.Interface\n ) {}\n\n async execute(\n input?: ListLockRecordsInput\n ): Promise<Result<ListLockRecordsOutput, RepositoryAbstraction.Error>> {\n try {\n const params = {\n ...input,\n where: convertWhereCondition(input?.where || {})\n };\n\n const result = await this.listEntries.execute<LockRecordValues>(this.model, params);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n const { entries, meta } = result.value;\n\n const items = entries.map(entry => new LockRecord(entry, this.config.timeout));\n\n return Result.ok({\n items,\n meta\n });\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const ListLockRecordsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListLockRecordsRepositoryImpl,\n dependencies: [RecordLockingModel, RecordLockingConfig, ListLatestEntriesUseCase]\n});\n"],"names":["ListLockRecordsRepositoryImpl","model","config","listEntries","input","params","convertWhereCondition","result","Result","LockRecordPersistenceError","entries","meta","items","entry","LockRecord","error","ListLockRecordsRepository","RepositoryAbstraction","RecordLockingModel","RecordLockingConfig","ListLatestEntriesUseCase"],"mappings":";;;;;;;AAaA,MAAMA;IACF,YACYC,KAAmC,EACnCC,MAAqC,EACrCC,WAA+C,CACzD;aAHUF,KAAK,GAALA;aACAC,MAAM,GAANA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QACFC,KAA4B,EACuC;QACnE,IAAI;YACA,MAAMC,SAAS;gBACX,GAAGD,KAAK;gBACR,OAAOE,sBAAsBF,OAAO,SAAS,CAAC;YAClD;YAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAmB,IAAI,CAAC,KAAK,EAAEF;YAE5E,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAGlE,MAAM,EAAEG,OAAO,EAAEC,IAAI,EAAE,GAAGJ,OAAO,KAAK;YAEtC,MAAMK,QAAQF,QAAQ,GAAG,CAACG,CAAAA,QAAS,IAAIC,WAAWD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5E,OAAOL,OAAO,EAAE,CAAC;gBACbI;gBACAD;YACJ;QACJ,EAAE,OAAOI,OAAO;YACZ,OAAOP,OAAO,IAAI,CAAC,IAAIC,2BAA2BM;QACtD;IACJ;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAA0C,CAAC;IAChF,gBAAgBjB;IAChB,cAAc;QAACkB;QAAoBC;QAAqBC;KAAyB;AACrF"}
1
+ {"version":3,"file":"features/ListLockRecords/ListLockRecordsRepository.js","sources":["../../../src/features/ListLockRecords/ListLockRecordsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport {\n ListLockRecordsRepository as RepositoryAbstraction,\n ListLockRecordsInput,\n ListLockRecordsOutput\n} from \"./abstractions.js\";\nimport { RecordLockingConfig, RecordLockingModel } from \"~/domain/abstractions.js\";\nimport { LockRecord } from \"~/domain/LockRecord.js\";\nimport type { LockRecordValues } from \"~/domain/types.js\";\nimport { LockRecordPersistenceError } from \"~/domain/errors.js\";\nimport { CmsWhereMapper } from \"@webiny/api-headless-cms\";\nimport { convertWhereCondition } from \"~/utils/convertWhereCondition.js\";\n\nclass ListLockRecordsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private model: RecordLockingModel.Interface,\n private config: RecordLockingConfig.Interface,\n private listEntries: ListLatestEntriesUseCase.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface\n ) {}\n\n async execute(\n input?: ListLockRecordsInput\n ): Promise<Result<ListLockRecordsOutput, RepositoryAbstraction.Error>> {\n try {\n const params = {\n ...input,\n where: this.cmsWhereMapper.map({\n input: convertWhereCondition(input?.where),\n fields: this.model.fields\n })\n };\n\n const result = await this.listEntries.execute<LockRecordValues>(this.model, params);\n\n if (result.isFail()) {\n return Result.fail(new LockRecordPersistenceError(result.error));\n }\n\n const { entries, meta } = result.value;\n\n const items = entries.map(entry => new LockRecord(entry, this.config.timeout));\n\n return Result.ok({\n items,\n meta\n });\n } catch (error) {\n return Result.fail(new LockRecordPersistenceError(error as Error));\n }\n }\n}\n\nexport const ListLockRecordsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListLockRecordsRepositoryImpl,\n dependencies: [\n RecordLockingModel,\n RecordLockingConfig,\n ListLatestEntriesUseCase,\n CmsWhereMapper\n ]\n});\n"],"names":["ListLockRecordsRepositoryImpl","model","config","listEntries","cmsWhereMapper","input","params","convertWhereCondition","result","Result","LockRecordPersistenceError","entries","meta","items","entry","LockRecord","error","ListLockRecordsRepository","RepositoryAbstraction","RecordLockingModel","RecordLockingConfig","ListLatestEntriesUseCase","CmsWhereMapper"],"mappings":";;;;;;;;AAcA,MAAMA;IACF,YACYC,KAAmC,EACnCC,MAAqC,EACrCC,WAA+C,EAC/CC,cAAwC,CAClD;aAJUH,KAAK,GAALA;aACAC,MAAM,GAANA;aACAC,WAAW,GAAXA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QACFC,KAA4B,EACuC;QACnE,IAAI;YACA,MAAMC,SAAS;gBACX,GAAGD,KAAK;gBACR,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;oBAC3B,OAAOE,sBAAsBF,OAAO;oBACpC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM;gBAC7B;YACJ;YAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAmB,IAAI,CAAC,KAAK,EAAEF;YAE5E,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,2BAA2BF,OAAO,KAAK;YAGlE,MAAM,EAAEG,OAAO,EAAEC,IAAI,EAAE,GAAGJ,OAAO,KAAK;YAEtC,MAAMK,QAAQF,QAAQ,GAAG,CAACG,CAAAA,QAAS,IAAIC,WAAWD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO;YAE5E,OAAOL,OAAO,EAAE,CAAC;gBACbI;gBACAD;YACJ;QACJ,EAAE,OAAOI,OAAO;YACZ,OAAOP,OAAO,IAAI,CAAC,IAAIC,2BAA2BM;QACtD;IACJ;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAA0C,CAAC;IAChF,gBAAgBlB;IAChB,cAAc;QACVmB;QACAC;QACAC;QACAC;KACH;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-record-locking",
3
- "version": "6.4.12-beta.5",
3
+ "version": "6.5.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -16,26 +16,26 @@
16
16
  ],
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@webiny/api": "6.4.12-beta.5",
20
- "@webiny/api-headless-cms": "6.4.12-beta.5",
21
- "@webiny/api-websockets": "6.4.12-beta.5",
22
- "@webiny/feature": "6.4.12-beta.5",
23
- "@webiny/handler": "6.4.12-beta.5",
24
- "@webiny/handler-aws": "6.4.12-beta.5",
25
- "@webiny/handler-graphql": "6.4.12-beta.5",
26
- "@webiny/plugins": "6.4.12-beta.5",
27
- "@webiny/utils": "6.4.12-beta.5"
19
+ "@webiny/api": "6.5.0-beta.0",
20
+ "@webiny/api-headless-cms": "6.5.0-beta.0",
21
+ "@webiny/api-websockets": "6.5.0-beta.0",
22
+ "@webiny/feature": "6.5.0-beta.0",
23
+ "@webiny/handler": "6.5.0-beta.0",
24
+ "@webiny/handler-aws": "6.5.0-beta.0",
25
+ "@webiny/handler-graphql": "6.5.0-beta.0",
26
+ "@webiny/plugins": "6.5.0-beta.0",
27
+ "@webiny/utils": "6.5.0-beta.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@webiny/api-core": "6.4.12-beta.5",
31
- "@webiny/build-tools": "6.4.12-beta.5",
32
- "@webiny/project-utils": "6.4.12-beta.5",
33
- "@webiny/wcp": "6.4.12-beta.5",
30
+ "@webiny/api-core": "6.5.0-beta.0",
31
+ "@webiny/build-tools": "6.5.0-beta.0",
32
+ "@webiny/project-utils": "6.5.0-beta.0",
33
+ "@webiny/wcp": "6.5.0-beta.0",
34
34
  "graphql": "16.14.2",
35
35
  "rimraf": "6.1.3",
36
- "type-fest": "5.10.0",
37
- "typescript": "6.0.3",
38
- "vitest": "5.0.1"
36
+ "type-fest": "5.8.0",
37
+ "typescript": "7.0.2",
38
+ "vitest": "4.1.10"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -11,7 +11,8 @@ const convertWhereCondition = (where)=>{
11
11
  if (!value) continue;
12
12
  for(const subKey in value)value[subKey] = convertWhereCondition(value[subKey]);
13
13
  continue;
14
- } else if (false === key.startsWith("id")) continue;
14
+ }
15
+ if (false === key.startsWith("id")) continue;
15
16
  const value = where[key];
16
17
  if (!value) continue;
17
18
  const newKey = key.replace("id", "entryId");
@@ -1 +1 @@
1
- {"version":3,"file":"utils/convertWhereCondition.js","sources":["../../src/utils/convertWhereCondition.ts"],"sourcesContent":["import type { IRecordLockingListLockRecordsParams } from \"~/types.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\n\ntype IWhere = IRecordLockingListLockRecordsParams[\"where\"] | undefined;\n\nconst attachPrefix = (value: string | string[]) => {\n if (Array.isArray(value)) {\n return value.map(createLockRecordDatabaseId);\n }\n return createLockRecordDatabaseId(value);\n};\n\nexport const convertWhereCondition = (where: IWhere): IWhere => {\n if (!where) {\n return where;\n }\n for (const key in where) {\n if (key.startsWith(\"AND\") || key.startsWith(\"OR\")) {\n const value = where[key as keyof typeof where] as IWhere[] | undefined;\n if (!value) {\n continue;\n }\n for (const subKey in value) {\n value[subKey] = convertWhereCondition(value[subKey]);\n }\n continue;\n } else if (key.startsWith(\"id\") === false) {\n continue;\n }\n const value = where[key as keyof typeof where];\n if (!value) {\n continue;\n }\n\n const newKey = key.replace(\"id\", \"entryId\") as keyof typeof where;\n // @ts-expect-error\n where[newKey] = attachPrefix(where[key]);\n // @ts-expect-error\n delete where[key];\n }\n return where;\n};\n"],"names":["attachPrefix","value","Array","createLockRecordDatabaseId","convertWhereCondition","where","key","subKey","newKey"],"mappings":";AAKA,MAAMA,eAAe,CAACC;IAClB,IAAIC,MAAM,OAAO,CAACD,QACd,OAAOA,MAAM,GAAG,CAACE;IAErB,OAAOA,2BAA2BF;AACtC;AAEO,MAAMG,wBAAwB,CAACC;IAClC,IAAI,CAACA,OACD,OAAOA;IAEX,IAAK,MAAMC,OAAOD,MAAO;QACrB,IAAIC,IAAI,UAAU,CAAC,UAAUA,IAAI,UAAU,CAAC,OAAO;YAC/C,MAAML,QAAQI,KAAK,CAACC,IAA0B;YAC9C,IAAI,CAACL,OACD;YAEJ,IAAK,MAAMM,UAAUN,MACjBA,KAAK,CAACM,OAAO,GAAGH,sBAAsBH,KAAK,CAACM,OAAO;YAEvD;QACJ,OAAO,IAAID,AAAyB,UAAzBA,IAAI,UAAU,CAAC,OACtB;QAEJ,MAAML,QAAQI,KAAK,CAACC,IAA0B;QAC9C,IAAI,CAACL,OACD;QAGJ,MAAMO,SAASF,IAAI,OAAO,CAAC,MAAM;QAEjCD,KAAK,CAACG,OAAO,GAAGR,aAAaK,KAAK,CAACC,IAAI;QAEvC,OAAOD,KAAK,CAACC,IAAI;IACrB;IACA,OAAOD;AACX"}
1
+ {"version":3,"file":"utils/convertWhereCondition.js","sources":["../../src/utils/convertWhereCondition.ts"],"sourcesContent":["import type { IRecordLockingListLockRecordsParams } from \"~/types.js\";\nimport { createLockRecordDatabaseId } from \"~/utils/lockRecordDatabaseId.js\";\n\ntype IWhere = IRecordLockingListLockRecordsParams[\"where\"] | undefined;\n\nconst attachPrefix = (value: string | string[]) => {\n if (Array.isArray(value)) {\n return value.map(createLockRecordDatabaseId);\n }\n return createLockRecordDatabaseId(value);\n};\n\nexport const convertWhereCondition = (where: IWhere): IWhere => {\n if (!where) {\n return where;\n }\n for (const key in where) {\n if (key.startsWith(\"AND\") || key.startsWith(\"OR\")) {\n const value = where[key as keyof typeof where] as IWhere[] | undefined;\n if (!value) {\n continue;\n }\n for (const subKey in value) {\n value[subKey] = convertWhereCondition(value[subKey]);\n }\n continue;\n } else if (key.startsWith(\"id\") === false) {\n continue;\n }\n const value = where[key as keyof typeof where];\n if (!value) {\n continue;\n }\n\n const newKey = key.replace(\"id\", \"entryId\") as keyof typeof where;\n // @ts-expect-error\n where[newKey] = attachPrefix(where[key]);\n // @ts-expect-error\n delete where[key];\n }\n return where;\n};\n"],"names":["attachPrefix","value","Array","createLockRecordDatabaseId","convertWhereCondition","where","key","subKey","newKey"],"mappings":";AAKA,MAAMA,eAAe,CAACC;IAClB,IAAIC,MAAM,OAAO,CAACD,QACd,OAAOA,MAAM,GAAG,CAACE;IAErB,OAAOA,2BAA2BF;AACtC;AAEO,MAAMG,wBAAwB,CAACC;IAClC,IAAI,CAACA,OACD,OAAOA;IAEX,IAAK,MAAMC,OAAOD,MAAO;QACrB,IAAIC,IAAI,UAAU,CAAC,UAAUA,IAAI,UAAU,CAAC,OAAO;YAC/C,MAAML,QAAQI,KAAK,CAACC,IAA0B;YAC9C,IAAI,CAACL,OACD;YAEJ,IAAK,MAAMM,UAAUN,MACjBA,KAAK,CAACM,OAAO,GAAGH,sBAAsBH,KAAK,CAACM,OAAO;YAEvD;QACJ;QAAO,IAAID,AAAyB,UAAzBA,IAAI,UAAU,CAAC,OACtB;QAEJ,MAAML,QAAQI,KAAK,CAACC,IAA0B;QAC9C,IAAI,CAACL,OACD;QAGJ,MAAMO,SAASF,IAAI,OAAO,CAAC,MAAM;QAEjCD,KAAK,CAACG,OAAO,GAAGR,aAAaK,KAAK,CAACC,IAAI;QAEvC,OAAOD,KAAK,CAACC,IAAI;IACrB;IACA,OAAOD;AACX"}