@webiny/api-headless-cms-ddb-es 6.6.0-alpha.1 → 6.6.0-alpha.10

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Claims the `cms.` debug namespace prefix.
3
+ *
4
+ * The module specifier has to be exactly this one: augmenting a relative path would silently do
5
+ * nothing.
6
+ */
7
+ declare module "@webiny/api-core/features/debugger/abstractions.js" {
8
+ interface DebugNamespaces {
9
+ cms: `cms.${string}`;
10
+ }
11
+ }
12
+ export {};
File without changes
package/feature.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * DynamoDB+OpenSearch CMS storage. Register it once, in the root container. Tables and entities are
3
+ * built once per process; the storage operations are transient, and per-request state (the entry
4
+ * DataLoaders, the filter registries, the OpenSearch field indexes and model index cache) is
5
+ * container scoped, so each request (child) container gets its own.
6
+ */
1
7
  export declare const HeadlessCmsDdbEsFeature: {
2
8
  name: string;
3
9
  register(container: import("@webiny/di").Container): void;
package/feature.js CHANGED
@@ -1,31 +1,28 @@
1
1
  import { DynamoDBClient, createTable } from "@webiny/db-dynamodb";
2
2
  import { ENTITIES } from "./types.js";
3
3
  import { createFeature } from "@webiny/feature/api/index.js";
4
- import { CmsEntryOpenSearchUtilsFeature } from "@webiny/api-headless-cms-utils-os";
5
4
  import { createGroupEntity } from "./definitions/group.js";
6
5
  import { createModelEntity } from "./definitions/model.js";
7
6
  import { createEntryEntity } from "./definitions/entry.js";
8
7
  import { createOpenSearchEntity, createOpenSearchTable } from "@webiny/api-opensearch-aws";
9
- import { CreateElasticsearchIndexTask } from "./tasks/CreateElasticsearchIndexTask.js";
10
- import { FilterRegistriesFeature } from "@webiny/api-headless-cms-storage";
11
8
  import { FilterUtilFeature } from "@webiny/db-dynamodb/feature/FilterUtil/feature.js";
12
- import { DbRegistry } from "@webiny/db/exports/api/db.js";
13
9
  import { CmsDdbEsTable } from "./abstractions/CmsDdbEsTable.js";
14
10
  import { CmsDdbEsOsTable } from "./abstractions/CmsDdbEsOsTable.js";
15
11
  import { CmsDdbEsGroupEntity } from "./abstractions/CmsDdbEsGroupEntity.js";
16
12
  import { CmsDdbEsModelEntity } from "./abstractions/CmsDdbEsModelEntity.js";
17
13
  import { CmsDdbEsEntryEntity } from "./abstractions/CmsDdbEsEntryEntity.js";
18
14
  import { CmsDdbEsEntriesEsEntity } from "./abstractions/CmsDdbEsEntriesEsEntity.js";
15
+ import { CmsEntryOpenSearchUtilsFeature } from "@webiny/api-headless-cms-utils-os";
16
+ import { FilterRegistriesFeature } from "@webiny/api-headless-cms-storage";
17
+ import { CreateElasticsearchIndexTask } from "./tasks/CreateElasticsearchIndexTask.js";
18
+ import { CmsEntitiesDbRegistryDecorator } from "./registry/CmsEntitiesDbRegistryDecorator.js";
19
19
  import { DdbEsGroupStorageOpsFeature } from "./operations/group/feature.js";
20
20
  import { DdbEsModelStorageOpsFeature } from "./operations/model/feature.js";
21
21
  import { DdbEsEntryStorageOpsFeature } from "./operations/entry/feature.js";
22
22
  const HeadlessCmsDdbEsFeature = createFeature({
23
23
  name: "cms.storageOperations.openSearch",
24
24
  register: (container)=>{
25
- CmsEntryOpenSearchUtilsFeature.register(container);
26
- FilterRegistriesFeature.register(container);
27
25
  FilterUtilFeature.register(container);
28
- container.register(CreateElasticsearchIndexTask);
29
26
  const db = container.resolve(DynamoDBClient);
30
27
  const documentClient = db.client;
31
28
  const tableInstance = createTable({
@@ -58,25 +55,10 @@ const HeadlessCmsDdbEsFeature = createFeature({
58
55
  container.registerInstance(CmsDdbEsModelEntity, modelEntity);
59
56
  container.registerInstance(CmsDdbEsEntryEntity, entryEntity);
60
57
  container.registerInstance(CmsDdbEsEntriesEsEntity, entriesEsEntity);
61
- try {
62
- const dbRegistry = container.resolve(DbRegistry);
63
- dbRegistry.register({
64
- item: entryEntity,
65
- app: "cms",
66
- tags: [
67
- "regular",
68
- entryEntity.name
69
- ]
70
- });
71
- dbRegistry.register({
72
- item: entriesEsEntity,
73
- app: "cms",
74
- tags: [
75
- "es",
76
- entriesEsEntity.name
77
- ]
78
- });
79
- } catch {}
58
+ CmsEntryOpenSearchUtilsFeature.register(container);
59
+ FilterRegistriesFeature.register(container);
60
+ container.register(CreateElasticsearchIndexTask);
61
+ container.registerDecorator(CmsEntitiesDbRegistryDecorator);
80
62
  DdbEsGroupStorageOpsFeature.register(container);
81
63
  DdbEsModelStorageOpsFeature.register(container);
82
64
  DdbEsEntryStorageOpsFeature.register(container);
package/feature.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import { createTable, DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { ENTITIES } from \"~/types.js\";\nimport { createFeature } from \"@webiny/feature/api/index.js\";\nimport { CmsEntryOpenSearchUtilsFeature } from \"@webiny/api-headless-cms-utils-os\";\nimport { createGroupEntity } from \"~/definitions/group.js\";\nimport { createModelEntity } from \"~/definitions/model.js\";\nimport { createEntryEntity } from \"~/definitions/entry.js\";\nimport { createOpenSearchEntity, createOpenSearchTable } from \"@webiny/api-opensearch-aws\";\nimport { CreateElasticsearchIndexTask } from \"~/tasks/CreateElasticsearchIndexTask.js\";\nimport { FilterRegistriesFeature } from \"@webiny/api-headless-cms-storage\";\nimport { FilterUtilFeature } from \"@webiny/db-dynamodb/feature/FilterUtil/feature.js\";\nimport { DbRegistry } from \"@webiny/db/exports/api/db.js\";\nimport { CmsDdbEsTable } from \"~/abstractions/CmsDdbEsTable.js\";\nimport { CmsDdbEsOsTable } from \"~/abstractions/CmsDdbEsOsTable.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { DdbEsGroupStorageOpsFeature } from \"~/operations/group/feature.js\";\nimport { DdbEsModelStorageOpsFeature } from \"~/operations/model/feature.js\";\nimport { DdbEsEntryStorageOpsFeature } from \"~/operations/entry/feature.js\";\n\nexport const HeadlessCmsDdbEsFeature = createFeature({\n name: \"cms.storageOperations.openSearch\",\n register: container => {\n CmsEntryOpenSearchUtilsFeature.register(container);\n FilterRegistriesFeature.register(container);\n FilterUtilFeature.register(container);\n\n container.register(CreateElasticsearchIndexTask);\n\n const db = container.resolve(DynamoDBClient);\n const documentClient = db.client;\n\n const tableInstance = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n const tableElasticsearchInstance = createOpenSearchTable({\n name: process.env.DB_TABLE_OPENSEARCH as string,\n documentClient\n });\n\n const groupEntity = createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance\n });\n const modelEntity = createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance\n });\n const entryEntity = createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance\n });\n const entriesEsEntity = createOpenSearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance\n });\n\n // Register infrastructure instances (app-scoped)\n container.registerInstance(CmsDdbEsTable, tableInstance);\n container.registerInstance(CmsDdbEsOsTable, tableElasticsearchInstance);\n container.registerInstance(CmsDdbEsGroupEntity, groupEntity);\n container.registerInstance(CmsDdbEsModelEntity, modelEntity);\n container.registerInstance(CmsDdbEsEntryEntity, entryEntity);\n container.registerInstance(CmsDdbEsEntriesEsEntity, entriesEsEntity);\n\n // Register entities in DbRegistry (optional — may not be available in all contexts)\n try {\n const dbRegistry = container.resolve(DbRegistry);\n dbRegistry.register({\n item: entryEntity,\n app: \"cms\",\n tags: [\"regular\", entryEntity.name]\n });\n dbRegistry.register({\n item: entriesEsEntity,\n app: \"cms\",\n tags: [\"es\", entriesEsEntity.name]\n });\n } catch {\n // DbRegistry not registered — skip entity registration\n }\n\n DdbEsGroupStorageOpsFeature.register(container);\n DdbEsModelStorageOpsFeature.register(container);\n DdbEsEntryStorageOpsFeature.register(container);\n }\n});\n"],"names":["HeadlessCmsDdbEsFeature","createFeature","container","CmsEntryOpenSearchUtilsFeature","FilterRegistriesFeature","FilterUtilFeature","CreateElasticsearchIndexTask","db","DynamoDBClient","documentClient","tableInstance","createTable","process","tableElasticsearchInstance","createOpenSearchTable","groupEntity","createGroupEntity","ENTITIES","modelEntity","createModelEntity","entryEntity","createEntryEntity","entriesEsEntity","createOpenSearchEntity","CmsDdbEsTable","CmsDdbEsOsTable","CmsDdbEsGroupEntity","CmsDdbEsModelEntity","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","dbRegistry","DbRegistry","DdbEsGroupStorageOpsFeature","DdbEsModelStorageOpsFeature","DdbEsEntryStorageOpsFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAAUC,CAAAA;QACNC,+BAA+B,QAAQ,CAACD;QACxCE,wBAAwB,QAAQ,CAACF;QACjCG,kBAAkB,QAAQ,CAACH;QAE3BA,UAAU,QAAQ,CAACI;QAEnB,MAAMC,KAAKL,UAAU,OAAO,CAACM;QAC7B,MAAMC,iBAAiBF,GAAG,MAAM;QAEhC,MAAMG,gBAAgBC,YAAY;YAC9B,MAAMC,QAAQ,GAAG,CAAC,QAAQ;YAC1BH;QACJ;QACA,MAAMI,6BAA6BC,sBAAsB;YACrD,MAAMF,QAAQ,GAAG,CAAC,mBAAmB;YACrCH;QACJ;QAEA,MAAMM,cAAcC,kBAAkB;YAClC,YAAYC,SAAS,MAAM;YAC3B,OAAOP;QACX;QACA,MAAMQ,cAAcC,kBAAkB;YAClC,YAAYF,SAAS,MAAM;YAC3B,OAAOP;QACX;QACA,MAAMU,cAAcC,kBAAkB;YAClC,YAAYJ,SAAS,OAAO;YAC5B,OAAOP;QACX;QACA,MAAMY,kBAAkBC,uBAAuB;YAC3C,YAAYN,SAAS,UAAU;YAC/B,OAAOJ;QACX;QAGAX,UAAU,gBAAgB,CAACsB,eAAed;QAC1CR,UAAU,gBAAgB,CAACuB,iBAAiBZ;QAC5CX,UAAU,gBAAgB,CAACwB,qBAAqBX;QAChDb,UAAU,gBAAgB,CAACyB,qBAAqBT;QAChDhB,UAAU,gBAAgB,CAAC0B,qBAAqBR;QAChDlB,UAAU,gBAAgB,CAAC2B,yBAAyBP;QAGpD,IAAI;YACA,MAAMQ,aAAa5B,UAAU,OAAO,CAAC6B;YACrCD,WAAW,QAAQ,CAAC;gBAChB,MAAMV;gBACN,KAAK;gBACL,MAAM;oBAAC;oBAAWA,YAAY,IAAI;iBAAC;YACvC;YACAU,WAAW,QAAQ,CAAC;gBAChB,MAAMR;gBACN,KAAK;gBACL,MAAM;oBAAC;oBAAMA,gBAAgB,IAAI;iBAAC;YACtC;QACJ,EAAE,OAAM,CAER;QAEAU,4BAA4B,QAAQ,CAAC9B;QACrC+B,4BAA4B,QAAQ,CAAC/B;QACrCgC,4BAA4B,QAAQ,CAAChC;IACzC;AACJ"}
1
+ {"version":3,"file":"feature.js","sources":["../src/feature.ts"],"sourcesContent":["import { createTable, DynamoDBClient } from \"@webiny/db-dynamodb\";\nimport { ENTITIES } from \"~/types.js\";\nimport { createFeature } from \"@webiny/feature/api/index.js\";\nimport { createGroupEntity } from \"~/definitions/group.js\";\nimport { createModelEntity } from \"~/definitions/model.js\";\nimport { createEntryEntity } from \"~/definitions/entry.js\";\nimport { createOpenSearchEntity, createOpenSearchTable } from \"@webiny/api-opensearch-aws\";\nimport { FilterUtilFeature } from \"@webiny/db-dynamodb/feature/FilterUtil/feature.js\";\nimport { CmsDdbEsTable } from \"~/abstractions/CmsDdbEsTable.js\";\nimport { CmsDdbEsOsTable } from \"~/abstractions/CmsDdbEsOsTable.js\";\nimport { CmsDdbEsGroupEntity } from \"~/abstractions/CmsDdbEsGroupEntity.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsEntryOpenSearchUtilsFeature } from \"@webiny/api-headless-cms-utils-os\";\nimport { FilterRegistriesFeature } from \"@webiny/api-headless-cms-storage\";\nimport { CreateElasticsearchIndexTask } from \"~/tasks/CreateElasticsearchIndexTask.js\";\nimport { CmsEntitiesDbRegistryDecorator } from \"~/registry/CmsEntitiesDbRegistryDecorator.js\";\nimport { DdbEsGroupStorageOpsFeature } from \"~/operations/group/feature.js\";\nimport { DdbEsModelStorageOpsFeature } from \"~/operations/model/feature.js\";\nimport { DdbEsEntryStorageOpsFeature } from \"~/operations/entry/feature.js\";\n\n/**\n * DynamoDB+OpenSearch CMS storage. Register it once, in the root container. Tables and entities are\n * built once per process; the storage operations are transient, and per-request state (the entry\n * DataLoaders, the filter registries, the OpenSearch field indexes and model index cache) is\n * container scoped, so each request (child) container gets its own.\n */\nexport const HeadlessCmsDdbEsFeature = createFeature({\n name: \"cms.storageOperations.openSearch\",\n register: container => {\n FilterUtilFeature.register(container);\n\n const db = container.resolve(DynamoDBClient);\n const documentClient = db.client;\n\n const tableInstance = createTable({\n name: process.env.DB_TABLE as string,\n documentClient\n });\n const tableElasticsearchInstance = createOpenSearchTable({\n name: process.env.DB_TABLE_OPENSEARCH as string,\n documentClient\n });\n\n const groupEntity = createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance\n });\n const modelEntity = createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance\n });\n const entryEntity = createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance\n });\n const entriesEsEntity = createOpenSearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance\n });\n\n // Register infrastructure instances (app-scoped)\n container.registerInstance(CmsDdbEsTable, tableInstance);\n container.registerInstance(CmsDdbEsOsTable, tableElasticsearchInstance);\n container.registerInstance(CmsDdbEsGroupEntity, groupEntity);\n container.registerInstance(CmsDdbEsModelEntity, modelEntity);\n container.registerInstance(CmsDdbEsEntryEntity, entryEntity);\n container.registerInstance(CmsDdbEsEntriesEsEntity, entriesEsEntity);\n\n CmsEntryOpenSearchUtilsFeature.register(container);\n FilterRegistriesFeature.register(container);\n\n container.register(CreateElasticsearchIndexTask);\n\n // Adds the CMS entities to every request's DbRegistry, for the DDB to OpenSearch sync.\n container.registerDecorator(CmsEntitiesDbRegistryDecorator);\n\n DdbEsGroupStorageOpsFeature.register(container);\n DdbEsModelStorageOpsFeature.register(container);\n DdbEsEntryStorageOpsFeature.register(container);\n }\n});\n"],"names":["HeadlessCmsDdbEsFeature","createFeature","container","FilterUtilFeature","db","DynamoDBClient","documentClient","tableInstance","createTable","process","tableElasticsearchInstance","createOpenSearchTable","groupEntity","createGroupEntity","ENTITIES","modelEntity","createModelEntity","entryEntity","createEntryEntity","entriesEsEntity","createOpenSearchEntity","CmsDdbEsTable","CmsDdbEsOsTable","CmsDdbEsGroupEntity","CmsDdbEsModelEntity","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsEntryOpenSearchUtilsFeature","FilterRegistriesFeature","CreateElasticsearchIndexTask","CmsEntitiesDbRegistryDecorator","DdbEsGroupStorageOpsFeature","DdbEsModelStorageOpsFeature","DdbEsEntryStorageOpsFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAAUC,CAAAA;QACNC,kBAAkB,QAAQ,CAACD;QAE3B,MAAME,KAAKF,UAAU,OAAO,CAACG;QAC7B,MAAMC,iBAAiBF,GAAG,MAAM;QAEhC,MAAMG,gBAAgBC,YAAY;YAC9B,MAAMC,QAAQ,GAAG,CAAC,QAAQ;YAC1BH;QACJ;QACA,MAAMI,6BAA6BC,sBAAsB;YACrD,MAAMF,QAAQ,GAAG,CAAC,mBAAmB;YACrCH;QACJ;QAEA,MAAMM,cAAcC,kBAAkB;YAClC,YAAYC,SAAS,MAAM;YAC3B,OAAOP;QACX;QACA,MAAMQ,cAAcC,kBAAkB;YAClC,YAAYF,SAAS,MAAM;YAC3B,OAAOP;QACX;QACA,MAAMU,cAAcC,kBAAkB;YAClC,YAAYJ,SAAS,OAAO;YAC5B,OAAOP;QACX;QACA,MAAMY,kBAAkBC,uBAAuB;YAC3C,YAAYN,SAAS,UAAU;YAC/B,OAAOJ;QACX;QAGAR,UAAU,gBAAgB,CAACmB,eAAed;QAC1CL,UAAU,gBAAgB,CAACoB,iBAAiBZ;QAC5CR,UAAU,gBAAgB,CAACqB,qBAAqBX;QAChDV,UAAU,gBAAgB,CAACsB,qBAAqBT;QAChDb,UAAU,gBAAgB,CAACuB,qBAAqBR;QAChDf,UAAU,gBAAgB,CAACwB,yBAAyBP;QAEpDQ,+BAA+B,QAAQ,CAACzB;QACxC0B,wBAAwB,QAAQ,CAAC1B;QAEjCA,UAAU,QAAQ,CAAC2B;QAGnB3B,UAAU,iBAAiB,CAAC4B;QAE5BC,4BAA4B,QAAQ,CAAC7B;QACrC8B,4BAA4B,QAAQ,CAAC9B;QACrC+B,4BAA4B,QAAQ,CAAC/B;IACzC;AACJ"}
@@ -18,35 +18,33 @@ class DdbEsDeleteMultipleEntriesImpl {
18
18
  model,
19
19
  ids: entries
20
20
  });
21
- const entityBatch = this.entity.createEntityWriter();
22
- const elasticsearchEntityBatch = this.esEntity.createEntityWriter();
23
- for (const id of entries){
24
- entityBatch.delete({
25
- PK: createPartitionKey({
21
+ const esItems = (await Promise.all(entries.map((id)=>this.esEntity.queryAll({
22
+ partitionKey: createPartitionKey({
26
23
  id,
27
24
  tenant: model.tenant
28
25
  }),
29
- SK: "L"
26
+ options: {
27
+ gte: " "
28
+ }
29
+ })))).flat();
30
+ const entityBatch = this.entity.createEntityWriter();
31
+ const elasticsearchEntityBatch = this.esEntity.createEntityWriter({
32
+ delete: esItems.map((item)=>({
33
+ PK: item.PK,
34
+ SK: item.SK
35
+ }))
36
+ });
37
+ for (const id of entries){
38
+ const partitionKey = createPartitionKey({
39
+ id,
40
+ tenant: model.tenant
30
41
  });
31
- elasticsearchEntityBatch.delete({
32
- PK: createPartitionKey({
33
- id,
34
- tenant: model.tenant
35
- }),
42
+ entityBatch.delete({
43
+ PK: partitionKey,
36
44
  SK: "L"
37
45
  });
38
46
  entityBatch.delete({
39
- PK: createPartitionKey({
40
- id,
41
- tenant: model.tenant
42
- }),
43
- SK: "P"
44
- });
45
- elasticsearchEntityBatch.delete({
46
- PK: createPartitionKey({
47
- id,
48
- tenant: model.tenant
49
- }),
47
+ PK: partitionKey,
50
48
  SK: "P"
51
49
  });
52
50
  }
@@ -61,6 +59,9 @@ class DdbEsDeleteMultipleEntriesImpl {
61
59
  });
62
60
  await entityBatch.execute();
63
61
  await elasticsearchEntityBatch.execute();
62
+ this.dataLoaders.clearAll({
63
+ tenant: model.tenant
64
+ });
64
65
  }
65
66
  }
66
67
  const DdbEsDeleteMultipleEntries = DeleteMultipleEntriesStorageOperation.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsDeleteMultipleEntries.js","sources":["../../../src/operations/entry/DdbEsDeleteMultipleEntries.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryStorageOperationsDeleteEntriesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { DeleteMultipleEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteMultipleEntriesStorageOperation.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { createPartitionKey, createRevisionSortKey } from \"./keys.js\";\n\nclass DdbEsDeleteMultipleEntriesImpl implements DeleteMultipleEntriesStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteEntriesParams) {\n const { entries } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n /**\n * First we need all the revisions of the entries we want to delete.\n */\n const revisions = await this.dataLoaders.getAllEntryRevisions({\n model,\n ids: entries\n });\n /**\n * Then we need to construct the queries for all the revisions and entries.\n */\n\n const entityBatch = this.entity.createEntityWriter();\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n for (const id of entries) {\n /**\n * Latest item.\n */\n entityBatch.delete({\n PK: createPartitionKey({\n id,\n tenant: model.tenant\n }),\n SK: \"L\"\n });\n\n elasticsearchEntityBatch.delete({\n PK: createPartitionKey({\n id,\n tenant: model.tenant\n }),\n SK: \"L\"\n });\n\n /**\n * Published item.\n */\n entityBatch.delete({\n PK: createPartitionKey({\n id,\n tenant: model.tenant\n }),\n SK: \"P\"\n });\n\n elasticsearchEntityBatch.delete({\n PK: createPartitionKey({\n id,\n tenant: model.tenant\n }),\n SK: \"P\"\n });\n }\n /**\n * Exact revisions of all the entries\n */\n for (const revision of revisions) {\n entityBatch.delete({\n PK: createPartitionKey({\n id: revision.id,\n tenant: model.tenant\n }),\n SK: createRevisionSortKey({\n version: revision.version\n })\n });\n }\n\n await entityBatch.execute();\n await elasticsearchEntityBatch.execute();\n }\n}\n\nexport const DdbEsDeleteMultipleEntries =\n DeleteMultipleEntriesStorageOperation.createImplementation({\n implementation: DdbEsDeleteMultipleEntriesImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider\n ]\n });\n"],"names":["DdbEsDeleteMultipleEntriesImpl","entity","esEntity","dataLoaders","storageModelProvider","initialModel","params","entries","model","revisions","entityBatch","elasticsearchEntityBatch","id","createPartitionKey","revision","createRevisionSortKey","DdbEsDeleteMultipleEntries","DeleteMultipleEntriesStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,CACjE;aAJUH,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,MAAoD,EAAE;QACxF,MAAM,EAAEC,OAAO,EAAE,GAAGD;QACpB,MAAME,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACH;QAIjD,MAAMI,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;YAC1DD;YACA,KAAKD;QACT;QAKA,MAAMG,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB;QAClD,MAAMC,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB;QACjE,KAAK,MAAMC,MAAML,QAAS;YAItBG,YAAY,MAAM,CAAC;gBACf,IAAIG,mBAAmB;oBACnBD;oBACA,QAAQJ,MAAM,MAAM;gBACxB;gBACA,IAAI;YACR;YAEAG,yBAAyB,MAAM,CAAC;gBAC5B,IAAIE,mBAAmB;oBACnBD;oBACA,QAAQJ,MAAM,MAAM;gBACxB;gBACA,IAAI;YACR;YAKAE,YAAY,MAAM,CAAC;gBACf,IAAIG,mBAAmB;oBACnBD;oBACA,QAAQJ,MAAM,MAAM;gBACxB;gBACA,IAAI;YACR;YAEAG,yBAAyB,MAAM,CAAC;gBAC5B,IAAIE,mBAAmB;oBACnBD;oBACA,QAAQJ,MAAM,MAAM;gBACxB;gBACA,IAAI;YACR;QACJ;QAIA,KAAK,MAAMM,YAAYL,UACnBC,YAAY,MAAM,CAAC;YACf,IAAIG,mBAAmB;gBACnB,IAAIC,SAAS,EAAE;gBACf,QAAQN,MAAM,MAAM;YACxB;YACA,IAAIO,sBAAsB;gBACtB,SAASD,SAAS,OAAO;YAC7B;QACJ;QAGJ,MAAMJ,YAAY,OAAO;QACzB,MAAMC,yBAAyB,OAAO;IAC1C;AACJ;AAEO,MAAMK,6BACTC,sCAAsC,oBAAoB,CAAC;IACvD,gBAAgBjB;IAChB,cAAc;QACVkB;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsDeleteMultipleEntries.js","sources":["../../../src/operations/entry/DdbEsDeleteMultipleEntries.ts"],"sourcesContent":["import type {\n CmsModel,\n CmsEntryStorageOperationsDeleteEntriesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { DeleteMultipleEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/DeleteMultipleEntriesStorageOperation.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\nimport { CmsDdbEsDataLoaders } from \"~/abstractions/CmsDdbEsDataLoaders.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { createPartitionKey, createRevisionSortKey } from \"./keys.js\";\n\nclass DdbEsDeleteMultipleEntriesImpl implements DeleteMultipleEntriesStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute(initialModel: CmsModel, params: CmsEntryStorageOperationsDeleteEntriesParams) {\n const { entries } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n /**\n * First we need all the revisions of the entries we want to delete.\n */\n const revisions = await this.dataLoaders.getAllEntryRevisions({\n model,\n ids: entries\n });\n /**\n * The Elasticsearch records that exist: an entry that was never published (or was\n * unpublished) has no published record, and deleting a missing record is an error in the\n * stream handling. As DdbEsDeleteEntry does, only the stored records are deleted.\n */\n const esItems = (\n await Promise.all(\n entries.map(id =>\n this.esEntity.queryAll({\n partitionKey: createPartitionKey({\n id,\n tenant: model.tenant\n }),\n options: {\n gte: \" \"\n }\n })\n )\n )\n ).flat();\n\n const entityBatch = this.entity.createEntityWriter();\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n delete: esItems.map(item => ({ PK: item.PK, SK: item.SK }))\n });\n for (const id of entries) {\n const partitionKey = createPartitionKey({\n id,\n tenant: model.tenant\n });\n /**\n * Latest and published items.\n */\n entityBatch.delete({ PK: partitionKey, SK: \"L\" });\n entityBatch.delete({ PK: partitionKey, SK: \"P\" });\n }\n /**\n * Exact revisions of all the entries\n */\n for (const revision of revisions) {\n entityBatch.delete({\n PK: createPartitionKey({\n id: revision.id,\n tenant: model.tenant\n }),\n SK: createRevisionSortKey({\n version: revision.version\n })\n });\n }\n\n await entityBatch.execute();\n await elasticsearchEntityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: model.tenant\n });\n }\n}\n\nexport const DdbEsDeleteMultipleEntries =\n DeleteMultipleEntriesStorageOperation.createImplementation({\n implementation: DdbEsDeleteMultipleEntriesImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider\n ]\n });\n"],"names":["DdbEsDeleteMultipleEntriesImpl","entity","esEntity","dataLoaders","storageModelProvider","initialModel","params","entries","model","revisions","esItems","Promise","id","createPartitionKey","entityBatch","elasticsearchEntityBatch","item","partitionKey","revision","createRevisionSortKey","DdbEsDeleteMultipleEntries","DeleteMultipleEntriesStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,CACjE;aAJUH,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,MAAoD,EAAE;QACxF,MAAM,EAAEC,OAAO,EAAE,GAAGD;QACpB,MAAME,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACH;QAIjD,MAAMI,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;YAC1DD;YACA,KAAKD;QACT;QAMA,MAAMG,UACF,OAAMC,QAAQ,GAAG,CACbJ,QAAQ,GAAG,CAACK,CAAAA,KACR,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACnB,cAAcC,mBAAmB;oBAC7BD;oBACA,QAAQJ,MAAM,MAAM;gBACxB;gBACA,SAAS;oBACL,KAAK;gBACT;YACJ,MAGV,IAAI;QAEN,MAAMM,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB;QAClD,MAAMC,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YAC9D,QAAQL,QAAQ,GAAG,CAACM,CAAAA,OAAS;oBAAE,IAAIA,KAAK,EAAE;oBAAE,IAAIA,KAAK,EAAE;gBAAC;QAC5D;QACA,KAAK,MAAMJ,MAAML,QAAS;YACtB,MAAMU,eAAeJ,mBAAmB;gBACpCD;gBACA,QAAQJ,MAAM,MAAM;YACxB;YAIAM,YAAY,MAAM,CAAC;gBAAE,IAAIG;gBAAc,IAAI;YAAI;YAC/CH,YAAY,MAAM,CAAC;gBAAE,IAAIG;gBAAc,IAAI;YAAI;QACnD;QAIA,KAAK,MAAMC,YAAYT,UACnBK,YAAY,MAAM,CAAC;YACf,IAAID,mBAAmB;gBACnB,IAAIK,SAAS,EAAE;gBACf,QAAQV,MAAM,MAAM;YACxB;YACA,IAAIW,sBAAsB;gBACtB,SAASD,SAAS,OAAO;YAC7B;QACJ;QAGJ,MAAMJ,YAAY,OAAO;QACzB,MAAMC,yBAAyB,OAAO;QAEtC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YACtB,QAAQP,MAAM,MAAM;QACxB;IACJ;AACJ;AAEO,MAAMY,6BACTC,sCAAsC,oBAAoB,CAAC;IACvD,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -26,7 +26,7 @@ class DdbEsGetPreviousRevisionImpl {
26
26
  partitionKey,
27
27
  options
28
28
  })).map((item)=>item.data);
29
- const entries = unfilteredEntries.filter((item)=>item.version < version);
29
+ const entries = unfilteredEntries.filter((item)=>item.modelId === model.modelId && item.version < version);
30
30
  const entry = entries[0];
31
31
  if (!entry) return null;
32
32
  return convertEntryKeysFromStorage({
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsGetPreviousRevision.js","sources":["../../../src/operations/entry/DdbEsGetPreviousRevision.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetPreviousRevisionParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetPreviousRevisionStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetPreviousRevisionStorageOperation.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { createPartitionKey } from \"./keys.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsGetPreviousRevisionImpl implements GetPreviousRevisionStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const { tenant } = model;\n const { entryId, version } = params;\n\n const partitionKey = createPartitionKey({\n tenant,\n id: entryId\n });\n const options: IEntityQueryAllParams[\"options\"] = {\n beginsWith: `REV#`,\n reverse: true\n };\n\n try {\n const unfilteredEntries = (\n await this.entity.queryAll({\n partitionKey,\n options\n })\n ).map(item => {\n return item.data;\n });\n\n const entries = unfilteredEntries.filter(item => {\n return item.version < version;\n });\n\n const entry = entries[0];\n\n if (!entry) {\n return null;\n }\n return convertEntryKeysFromStorage<T>({\n entry,\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey,\n options,\n model\n }\n );\n }\n }\n}\n\nexport const DdbEsGetPreviousRevision = GetPreviousRevisionStorageOperation.createImplementation({\n implementation: DdbEsGetPreviousRevisionImpl,\n dependencies: [CmsDdbEsEntryEntity, CmsStorageModelProvider]\n});\n"],"names":["DdbEsGetPreviousRevisionImpl","entity","storageModelProvider","initialModel","params","model","tenant","entryId","version","partitionKey","createPartitionKey","options","unfilteredEntries","item","entries","entry","convertEntryKeysFromStorage","ex","WebinyError","DdbEsGetPreviousRevision","GetPreviousRevisionStorageOperation","CmsDdbEsEntryEntity","CmsStorageModelProvider"],"mappings":";;;;;;AAaA,MAAMA;IACF,YACYC,MAAqC,EACrCC,oBAAuD,CACjE;aAFUD,MAAM,GAANA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAA0D,EAC5D;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAM,EAAEG,MAAM,EAAE,GAAGD;QACnB,MAAM,EAAEE,OAAO,EAAEC,OAAO,EAAE,GAAGJ;QAE7B,MAAMK,eAAeC,mBAAmB;YACpCJ;YACA,IAAIC;QACR;QACA,MAAMI,UAA4C;YAC9C,YAAY;YACZ,SAAS;QACb;QAEA,IAAI;YACA,MAAMC,oBACF,OAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACvBH;gBACAE;YACJ,EAAC,EACH,GAAG,CAACE,CAAAA,OACKA,KAAK,IAAI;YAGpB,MAAMC,UAAUF,kBAAkB,MAAM,CAACC,CAAAA,OAC9BA,KAAK,OAAO,GAAGL;YAG1B,MAAMO,QAAQD,OAAO,CAAC,EAAE;YAExB,IAAI,CAACC,OACD,OAAO;YAEX,OAAOC,4BAA+B;gBAClCD;gBACAV;YACJ;QACJ,EAAE,OAAOY,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,kDACdA,GAAG,IAAI,IAAI,8BACX;gBACI,GAAGb,MAAM;gBACT,OAAOa;gBACPR;gBACAE;gBACAN;YACJ;QAER;IACJ;AACJ;AAEO,MAAMc,2BAA2BC,oCAAoC,oBAAoB,CAAC;IAC7F,gBAAgBpB;IAChB,cAAc;QAACqB;QAAqBC;KAAwB;AAChE"}
1
+ {"version":3,"file":"operations/entry/DdbEsGetPreviousRevision.js","sources":["../../../src/operations/entry/DdbEsGetPreviousRevision.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsGetPreviousRevisionParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetPreviousRevisionStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetPreviousRevisionStorageOperation.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { createPartitionKey } from \"./keys.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsGetPreviousRevisionImpl implements GetPreviousRevisionStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const { tenant } = model;\n const { entryId, version } = params;\n\n const partitionKey = createPartitionKey({\n tenant,\n id: entryId\n });\n const options: IEntityQueryAllParams[\"options\"] = {\n beginsWith: `REV#`,\n reverse: true\n };\n\n try {\n const unfilteredEntries = (\n await this.entity.queryAll({\n partitionKey,\n options\n })\n ).map(item => {\n return item.data;\n });\n\n /**\n * The partition key does not include the model, so filter by it as well.\n */\n const entries = unfilteredEntries.filter(item => {\n return item.modelId === model.modelId && item.version < version;\n });\n\n const entry = entries[0];\n\n if (!entry) {\n return null;\n }\n return convertEntryKeysFromStorage<T>({\n entry,\n model\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get previous version of given entry.\",\n ex.code || \"GET_PREVIOUS_VERSION_ERROR\",\n {\n ...params,\n error: ex,\n partitionKey,\n options,\n model\n }\n );\n }\n }\n}\n\nexport const DdbEsGetPreviousRevision = GetPreviousRevisionStorageOperation.createImplementation({\n implementation: DdbEsGetPreviousRevisionImpl,\n dependencies: [CmsDdbEsEntryEntity, CmsStorageModelProvider]\n});\n"],"names":["DdbEsGetPreviousRevisionImpl","entity","storageModelProvider","initialModel","params","model","tenant","entryId","version","partitionKey","createPartitionKey","options","unfilteredEntries","item","entries","entry","convertEntryKeysFromStorage","ex","WebinyError","DdbEsGetPreviousRevision","GetPreviousRevisionStorageOperation","CmsDdbEsEntryEntity","CmsStorageModelProvider"],"mappings":";;;;;;AAaA,MAAMA;IACF,YACYC,MAAqC,EACrCC,oBAAuD,CACjE;aAFUD,MAAM,GAANA;aACAC,oBAAoB,GAApBA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAA0D,EAC5D;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAM,EAAEG,MAAM,EAAE,GAAGD;QACnB,MAAM,EAAEE,OAAO,EAAEC,OAAO,EAAE,GAAGJ;QAE7B,MAAMK,eAAeC,mBAAmB;YACpCJ;YACA,IAAIC;QACR;QACA,MAAMI,UAA4C;YAC9C,YAAY;YACZ,SAAS;QACb;QAEA,IAAI;YACA,MAAMC,oBACF,OAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACvBH;gBACAE;YACJ,EAAC,EACH,GAAG,CAACE,CAAAA,OACKA,KAAK,IAAI;YAMpB,MAAMC,UAAUF,kBAAkB,MAAM,CAACC,CAAAA,OAC9BA,KAAK,OAAO,KAAKR,MAAM,OAAO,IAAIQ,KAAK,OAAO,GAAGL;YAG5D,MAAMO,QAAQD,OAAO,CAAC,EAAE;YAExB,IAAI,CAACC,OACD,OAAO;YAEX,OAAOC,4BAA+B;gBAClCD;gBACAV;YACJ;QACJ,EAAE,OAAOY,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,kDACdA,GAAG,IAAI,IAAI,8BACX;gBACI,GAAGb,MAAM;gBACT,OAAOa;gBACPR;gBACAE;gBACAN;YACJ;QAER;IACJ;AACJ;AAEO,MAAMc,2BAA2BC,oCAAoC,oBAAoB,CAAC;IAC7F,gBAAgBpB;IAChB,cAAc;QAACqB;QAAqBC;KAAwB;AAChE"}
@@ -13,11 +13,12 @@ class DdbEsGetUniqueFieldValuesImpl {
13
13
  async execute(model, params) {
14
14
  const { where, fieldId } = params;
15
15
  const configurations = createConfigurations(this.indexProvider);
16
- const { index } = await configurations.es({
16
+ const { index, shared } = await configurations.es({
17
17
  model
18
18
  });
19
19
  const initialBody = this.bodyBuilder.build({
20
20
  model,
21
+ shared,
21
22
  params: {
22
23
  limit: 1,
23
24
  where
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsGetUniqueFieldValues.js","sources":["../../../src/operations/entry/DdbEsGetUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryStorageOperationsGetUniqueFieldValuesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetUniqueFieldValuesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport type {\n OpenSearchSearchResponse,\n SearchBody as OpenSearchSearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\n\nclass DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams) {\n const { where, fieldId } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({\n model\n });\n\n const initialBody = this.bodyBuilder.build({\n model,\n params: {\n limit: 1,\n where\n }\n });\n\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n throw new WebinyError(\n `Could not find field with given \"fieldId\" value.`,\n \"FIELD_NOT_FOUND\",\n {\n fieldId\n }\n );\n }\n\n const body: OpenSearchSearchBody = {\n ...initialBody,\n /**\n * We do not need any hits returned, we only need the aggregations.\n */\n size: 0,\n aggregations: {\n getUniqueFieldValues: {\n terms: {\n field: `values.${field.storageId}.keyword`,\n size: 1000000\n }\n }\n }\n };\n\n let response: OpenSearchSearchResponse | undefined = undefined;\n\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return [];\n }\n\n throw new WebinyError(\n error.message || \"Error in the Elasticsearch query.\",\n error.code || \"OPENSEARCH_ERROR\",\n {\n error,\n index,\n model,\n body\n }\n );\n }\n\n const aggregations = response.body.aggregations || {};\n const agg = aggregations[\"getUniqueFieldValues\"];\n const buckets = agg && \"buckets\" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];\n return buckets.map((bucket: { key: string; doc_count: number }) => {\n return {\n value: bucket.key,\n count: bucket.doc_count\n };\n });\n }\n}\n\nexport const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImplementation({\n implementation: DdbEsGetUniqueFieldValuesImpl,\n dependencies: [CmsEntryOpenSearchBodyBuilder, OpenSearchClient, CmsModelOpenSearchIndexProvider]\n});\n"],"names":["DdbEsGetUniqueFieldValuesImpl","bodyBuilder","openSearchClient","indexProvider","model","params","where","fieldId","configurations","createConfigurations","index","initialBody","field","f","WebinyError","body","response","error","shouldIgnoreEsResponseError","aggregations","agg","buckets","Array","bucket","DdbEsGetUniqueFieldValues","GetUniqueFieldValuesStorageOperation","CmsEntryOpenSearchBodyBuilder","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;AAmBA,MAAMA;IAGF,YACYC,WAAoD,EAC5DC,gBAA4C,EACpCC,aAAwD,CAClE;aAHUF,WAAW,GAAXA;aAEAE,aAAa,GAAbA;QAER,IAAI,CAAC,aAAa,GAAGD,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQE,KAAe,EAAEC,MAA2D,EAAE;QACxF,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGF;QAE3B,MAAMG,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YACtCJ;QACJ;QAEA,MAAMO,cAAc,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YACvCP;YACA,QAAQ;gBACJ,OAAO;gBACPE;YACJ;QACJ;QAEA,MAAMM,QAAQR,MAAM,MAAM,CAAC,IAAI,CAACS,CAAAA,IAAKA,EAAE,OAAO,KAAKN;QACnD,IAAI,CAACK,OACD,MAAM,IAAIE,cACN,oDACA,mBACA;YACIP;QACJ;QAIR,MAAMQ,OAA6B;YAC/B,GAAGJ,WAAW;YAId,MAAM;YACN,cAAc;gBACV,sBAAsB;oBAClB,OAAO;wBACH,OAAO,CAAC,OAAO,EAAEC,MAAM,SAAS,CAAC,QAAQ,CAAC;wBAC1C,MAAM;oBACV;gBACJ;YACJ;QACJ;QAEA,IAAII;QAEJ,IAAI;YACAA,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBACvCN;gBACAK;YACJ;QACJ,EAAE,OAAOE,OAAO;YACZ,IAAIC,4BAA4BD,QAC5B,OAAO,EAAE;YAGb,MAAM,IAAIH,cACNG,MAAM,OAAO,IAAI,qCACjBA,MAAM,IAAI,IAAI,oBACd;gBACIA;gBACAP;gBACAN;gBACAW;YACJ;QAER;QAEA,MAAMI,eAAeH,SAAS,IAAI,CAAC,YAAY,IAAI,CAAC;QACpD,MAAMI,MAAMD,YAAY,CAAC,uBAAuB;QAChD,MAAME,UAAUD,OAAO,aAAaA,OAAOE,MAAM,OAAO,CAACF,IAAI,OAAO,IAAIA,IAAI,OAAO,GAAG,EAAE;QACxF,OAAOC,QAAQ,GAAG,CAAC,CAACE,SACT;gBACH,OAAOA,OAAO,GAAG;gBACjB,OAAOA,OAAO,SAAS;YAC3B;IAER;AACJ;AAEO,MAAMC,4BAA4BC,qCAAqC,oBAAoB,CAAC;IAC/F,gBAAgBzB;IAChB,cAAc;QAAC0B;QAA+BC;QAAkBC;KAAgC;AACpG"}
1
+ {"version":3,"file":"operations/entry/DdbEsGetUniqueFieldValues.js","sources":["../../../src/operations/entry/DdbEsGetUniqueFieldValues.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryStorageOperationsGetUniqueFieldValuesParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { GetUniqueFieldValuesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport type {\n OpenSearchSearchResponse,\n SearchBody as OpenSearchSearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\n\nclass DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams) {\n const { where, fieldId } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const initialBody = this.bodyBuilder.build({\n model,\n shared,\n params: {\n limit: 1,\n where\n }\n });\n\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n throw new WebinyError(\n `Could not find field with given \"fieldId\" value.`,\n \"FIELD_NOT_FOUND\",\n {\n fieldId\n }\n );\n }\n\n const body: OpenSearchSearchBody = {\n ...initialBody,\n /**\n * We do not need any hits returned, we only need the aggregations.\n */\n size: 0,\n aggregations: {\n getUniqueFieldValues: {\n terms: {\n // @ts-expect-error opensearch 3.9 types omit `field` from TermsAggregationFields\n field: `values.${field.storageId}.keyword`,\n size: 1000000\n }\n }\n }\n };\n\n let response: OpenSearchSearchResponse | undefined = undefined;\n\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n } catch (error) {\n if (shouldIgnoreEsResponseError(error)) {\n return [];\n }\n\n throw new WebinyError(\n error.message || \"Error in the Elasticsearch query.\",\n error.code || \"OPENSEARCH_ERROR\",\n {\n error,\n index,\n model,\n body\n }\n );\n }\n\n const aggregations = response.body.aggregations || {};\n const agg = aggregations[\"getUniqueFieldValues\"];\n const buckets = agg && \"buckets\" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];\n return buckets.map((bucket: { key: string; doc_count: number }) => {\n return {\n value: bucket.key,\n count: bucket.doc_count\n };\n });\n }\n}\n\nexport const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImplementation({\n implementation: DdbEsGetUniqueFieldValuesImpl,\n dependencies: [CmsEntryOpenSearchBodyBuilder, OpenSearchClient, CmsModelOpenSearchIndexProvider]\n});\n"],"names":["DdbEsGetUniqueFieldValuesImpl","bodyBuilder","openSearchClient","indexProvider","model","params","where","fieldId","configurations","createConfigurations","index","shared","initialBody","field","f","WebinyError","body","response","error","shouldIgnoreEsResponseError","aggregations","agg","buckets","Array","bucket","DdbEsGetUniqueFieldValues","GetUniqueFieldValuesStorageOperation","CmsEntryOpenSearchBodyBuilder","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;AAmBA,MAAMA;IAGF,YACYC,WAAoD,EAC5DC,gBAA4C,EACpCC,aAAwD,CAClE;aAHUF,WAAW,GAAXA;aAEAE,aAAa,GAAbA;QAER,IAAI,CAAC,aAAa,GAAGD,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQE,KAAe,EAAEC,MAA2D,EAAE;QACxF,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGF;QAE3B,MAAMG,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAG,MAAMH,eAAe,EAAE,CAAC;YAC9CJ;QACJ;QAEA,MAAMQ,cAAc,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YACvCR;YACAO;YACA,QAAQ;gBACJ,OAAO;gBACPL;YACJ;QACJ;QAEA,MAAMO,QAAQT,MAAM,MAAM,CAAC,IAAI,CAACU,CAAAA,IAAKA,EAAE,OAAO,KAAKP;QACnD,IAAI,CAACM,OACD,MAAM,IAAIE,cACN,oDACA,mBACA;YACIR;QACJ;QAIR,MAAMS,OAA6B;YAC/B,GAAGJ,WAAW;YAId,MAAM;YACN,cAAc;gBACV,sBAAsB;oBAClB,OAAO;wBAEH,OAAO,CAAC,OAAO,EAAEC,MAAM,SAAS,CAAC,QAAQ,CAAC;wBAC1C,MAAM;oBACV;gBACJ;YACJ;QACJ;QAEA,IAAII;QAEJ,IAAI;YACAA,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBACvCP;gBACAM;YACJ;QACJ,EAAE,OAAOE,OAAO;YACZ,IAAIC,4BAA4BD,QAC5B,OAAO,EAAE;YAGb,MAAM,IAAIH,cACNG,MAAM,OAAO,IAAI,qCACjBA,MAAM,IAAI,IAAI,oBACd;gBACIA;gBACAR;gBACAN;gBACAY;YACJ;QAER;QAEA,MAAMI,eAAeH,SAAS,IAAI,CAAC,YAAY,IAAI,CAAC;QACpD,MAAMI,MAAMD,YAAY,CAAC,uBAAuB;QAChD,MAAME,UAAUD,OAAO,aAAaA,OAAOE,MAAM,OAAO,CAACF,IAAI,OAAO,IAAIA,IAAI,OAAO,GAAG,EAAE;QACxF,OAAOC,QAAQ,GAAG,CAAC,CAACE,SACT;gBACH,OAAOA,OAAO,GAAG;gBACjB,OAAOA,OAAO,SAAS;YAC3B;IAER;AACJ;AAEO,MAAMC,4BAA4BC,qCAAqC,oBAAoB,CAAC;IAC/F,gBAAgB1B;IAChB,cAAc;QAAC2B;QAA+BC;QAAkBC;KAAgC;AACpG"}
@@ -4,14 +4,17 @@ import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/share
4
4
  import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
5
5
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
6
6
  import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
7
+ import { Debugger } from "@webiny/api-core/features/debugger/index.js";
8
+ import "~/debuggerNamespaces.js";
7
9
  declare class DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {
8
10
  private storageModelProvider;
9
11
  private bodyBuilder;
10
12
  private fieldRegistry;
11
13
  private fieldIndexRegistry;
12
14
  private indexProvider;
15
+ private debuggerService;
13
16
  private elasticsearch;
14
- constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
17
+ constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, debuggerService: Debugger.Interface);
15
18
  execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsListParams): Promise<{
16
19
  hasMoreItems: boolean;
17
20
  totalCount: number;
@@ -9,25 +9,29 @@ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configur
9
9
  import { extractEntriesFromIndex } from "@webiny/api-headless-cms-utils-os/helpers/index.js";
10
10
  import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
11
11
  import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
12
+ import { Debugger } from "@webiny/api-core/features/debugger/index.js";
13
+ import "../../debuggerNamespaces.js";
12
14
  import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
13
15
  class DdbEsListEntriesImpl {
14
- constructor(storageModelProvider, bodyBuilder, fieldRegistry, fieldIndexRegistry, openSearchClient, indexProvider){
16
+ constructor(storageModelProvider, bodyBuilder, fieldRegistry, fieldIndexRegistry, openSearchClient, indexProvider, debuggerService){
15
17
  this.storageModelProvider = storageModelProvider;
16
18
  this.bodyBuilder = bodyBuilder;
17
19
  this.fieldRegistry = fieldRegistry;
18
20
  this.fieldIndexRegistry = fieldIndexRegistry;
19
21
  this.indexProvider = indexProvider;
22
+ this.debuggerService = debuggerService;
20
23
  this.elasticsearch = openSearchClient.use();
21
24
  }
22
25
  async execute(initialModel, params) {
23
26
  const model = this.storageModelProvider.getModel(initialModel);
24
27
  const limit = createLimit(params.limit, 50);
25
28
  const configurations = createConfigurations(this.indexProvider);
26
- const { index } = await configurations.es({
29
+ const { index, shared } = await configurations.es({
27
30
  model
28
31
  });
29
32
  const body = this.bodyBuilder.build({
30
33
  model,
34
+ shared,
31
35
  params: {
32
36
  ...params,
33
37
  limit,
@@ -35,12 +39,26 @@ class DdbEsListEntriesImpl {
35
39
  }
36
40
  });
37
41
  let response;
42
+ const startedAt = Date.now();
38
43
  try {
39
44
  response = await this.elasticsearch.search({
40
45
  index,
41
46
  body
42
47
  });
48
+ this.debuggerService.log("cms.os.list", ()=>({
49
+ index,
50
+ query: body,
51
+ body: response.body,
52
+ statusCode: response.statusCode,
53
+ tookMs: Date.now() - startedAt
54
+ }));
43
55
  } catch (error) {
56
+ this.debuggerService.log("cms.os.list", ()=>({
57
+ index,
58
+ query: body,
59
+ error,
60
+ tookMs: Date.now() - startedAt
61
+ }));
44
62
  if (shouldIgnoreEsResponseError(error)) return {
45
63
  hasMoreItems: false,
46
64
  totalCount: 0,
@@ -83,7 +101,8 @@ const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({
83
101
  CmsModelFieldToGraphQLRegistry,
84
102
  CmsEntryOpenSearchFieldIndexRegistry,
85
103
  OpenSearchClient,
86
- CmsModelOpenSearchIndexProvider
104
+ CmsModelOpenSearchIndexProvider,
105
+ Debugger
87
106
  ]
88
107
  });
89
108
  export { DdbEsListEntries };
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsListEntries.js","sources":["../../../src/operations/entry/DdbEsListEntries.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsListParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/ListEntriesStorageOperation.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport { createLimit, decodeCursor, encodeCursor } from \"@webiny/api-opensearch\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch/types.js\";\nimport { getTotalCount } from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/index.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n private fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsListParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const limit = createLimit(params.limit, 50);\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({\n model\n });\n\n const body = this.bodyBuilder.build({\n model,\n params: {\n ...params,\n limit,\n after: decodeCursor(params.after)\n }\n });\n\n let response: OpenSearchSearchResponse;\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n } catch (error) {\n /**\n * We will silently ignore the `index_not_found_exception` error and return an empty result set.\n * This is because the index might not exist yet, and we don't want to throw an error.\n */\n if (shouldIgnoreEsResponseError(error)) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n body,\n model\n });\n }\n\n const { hits, total } = response.body.hits;\n\n const items = extractEntriesFromIndex<T>({\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n entries: hits.map(item => {\n return item._source as CmsIndexEntry<T>;\n })\n }).map(item => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry: item\n });\n });\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n /**\n * TODO expect errors over hit properties is required due to opensearch library narrowing types too much because of the _source: false. At least what Claude says, didnt go into it too much.\n * Properties are there, but types are not correct.\n */\n // @ts-expect-error\n const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;\n return {\n hasMoreItems,\n totalCount: getTotalCount(total),\n cursor,\n items\n };\n }\n}\n\nexport const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({\n implementation: DdbEsListEntriesImpl,\n dependencies: [\n CmsStorageModelProvider,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n OpenSearchClient,\n CmsModelOpenSearchIndexProvider\n ]\n});\n"],"names":["DdbEsListEntriesImpl","storageModelProvider","bodyBuilder","fieldRegistry","fieldIndexRegistry","openSearchClient","indexProvider","initialModel","params","model","limit","createLimit","configurations","createConfigurations","index","body","decodeCursor","response","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","convertEntryKeysFromStorage","hasMoreItems","cursor","encodeCursor","getTotalCount","DdbEsListEntries","ListEntriesStorageOperation","CmsStorageModelProvider","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;;;;;;;AAyBA,MAAMA;IAGF,YACYC,oBAAuD,EACvDC,WAAoD,EACpDC,aAAuD,EACvDC,kBAAkE,EAC1EC,gBAA4C,EACpCC,aAAwD,CAClE;aANUL,oBAAoB,GAApBA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aAEAE,aAAa,GAAbA;QAER,IAAI,CAAC,aAAa,GAAGD,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QACFE,YAAsB,EACtBC,MAA2C,EAC7C;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQC,YAAYH,OAAO,KAAK,EAAE;QACxC,MAAMI,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YACtCH;QACJ;QAEA,MAAMM,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAChCN;YACA,QAAQ;gBACJ,GAAGD,MAAM;gBACTE;gBACA,OAAOM,aAAaR,OAAO,KAAK;YACpC;QACJ;QAEA,IAAIS;QACJ,IAAI;YACAA,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBACvCH;gBACAC;YACJ;QACJ,EAAE,OAAOG,OAAO;YAKZ,IAAIC,4BAA4BD,QAC5B,OAAO;gBACH,cAAc;gBACd,YAAY;gBACZ,QAAQ;gBACR,OAAO,EAAE;YACb;YAGJ,MAAM,IAAIE,cAAYF,MAAM,OAAO,EAAEA,MAAM,IAAI,IAAI,oBAAoB;gBACnEA;gBACAJ;gBACAC;gBACAN;YACJ;QACJ;QAEA,MAAM,EAAEY,IAAI,EAAEC,KAAK,EAAE,GAAGL,SAAS,IAAI,CAAC,IAAI;QAE1C,MAAMM,QAAQC,wBAA2B;YACrC,eAAe,IAAI,CAAC,aAAa;YACjC,oBAAoB,IAAI,CAAC,kBAAkB;YAC3Cf;YACA,SAASY,KAAK,GAAG,CAACI,CAAAA,OACPA,KAAK,OAAO;QAE3B,GAAG,GAAG,CAACA,CAAAA,OACIC,4BAA+B;gBAClCjB;gBACA,OAAOgB;YACX;QAGJ,MAAME,eAAeJ,MAAM,MAAM,GAAGb;QACpC,IAAIiB,cAIAJ,MAAM,GAAG;QAWb,MAAMK,SAASL,MAAM,MAAM,GAAG,IAAIM,aAAaR,IAAI,CAACE,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,KAAK,OAAO;QACtF,OAAO;YACHI;YACA,YAAYG,cAAcR;YAC1BM;YACAL;QACJ;IACJ;AACJ;AAEO,MAAMQ,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBhC;IAChB,cAAc;QACViC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsListEntries.js","sources":["../../../src/operations/entry/DdbEsListEntries.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsListParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ListEntriesStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/ListEntriesStorageOperation.js\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport { createLimit, decodeCursor, encodeCursor } from \"@webiny/api-opensearch\";\nimport type { OpenSearchSearchResponse } from \"@webiny/api-opensearch/types.js\";\nimport { getTotalCount } from \"@webiny/api-opensearch/types.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { extractEntriesFromIndex } from \"@webiny/api-headless-cms-utils-os/helpers/index.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport {\n CmsEntryOpenSearchBodyBuilder,\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport { Debugger } from \"@webiny/api-core/features/debugger/index.js\";\nimport \"~/debuggerNamespaces.js\";\nimport { convertEntryKeysFromStorage } from \"./transformations/convertEntryKeys.js\";\n\nclass DdbEsListEntriesImpl implements ListEntriesStorageOperation.Interface {\n private elasticsearch: Client;\n\n constructor(\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface,\n private fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private debuggerService: Debugger.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsListParams\n ) {\n const model = this.storageModelProvider.getModel<T>(initialModel);\n\n const limit = createLimit(params.limit, 50);\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({\n model\n });\n\n const body = this.bodyBuilder.build({\n model,\n shared,\n params: {\n ...params,\n limit,\n after: decodeCursor(params.after)\n }\n });\n\n let response: OpenSearchSearchResponse;\n const startedAt = Date.now();\n try {\n response = await this.elasticsearch.search({\n index,\n body\n });\n\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n /**\n * Only the response body and status. The full client response also carries\n * `meta.connection.url` (the cluster endpoint) plus request headers.\n */\n body: response.body,\n statusCode: response.statusCode,\n tookMs: Date.now() - startedAt\n }));\n } catch (error) {\n /**\n * Logged before the `index_not_found` check below, which swallows the error and returns\n * an empty result. That silent exit is exactly what is hard to see from the outside.\n */\n this.debuggerService.log(\"cms.os.list\", () => ({\n index,\n query: body,\n error,\n tookMs: Date.now() - startedAt\n }));\n\n /**\n * We will silently ignore the `index_not_found_exception` error and return an empty result set.\n * This is because the index might not exist yet, and we don't want to throw an error.\n */\n if (shouldIgnoreEsResponseError(error)) {\n return {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null,\n items: []\n };\n }\n\n throw new WebinyError(error.message, error.code || \"OPENSEARCH_ERROR\", {\n error,\n index,\n body,\n model\n });\n }\n\n const { hits, total } = response.body.hits;\n\n const items = extractEntriesFromIndex<T>({\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n model,\n entries: hits.map(item => {\n return item._source as CmsIndexEntry<T>;\n })\n }).map(item => {\n return convertEntryKeysFromStorage<T>({\n model,\n entry: item\n });\n });\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;\n return {\n hasMoreItems,\n totalCount: getTotalCount(total),\n cursor,\n items\n };\n }\n}\n\nexport const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({\n implementation: DdbEsListEntriesImpl,\n dependencies: [\n CmsStorageModelProvider,\n CmsEntryOpenSearchBodyBuilder,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n OpenSearchClient,\n CmsModelOpenSearchIndexProvider,\n Debugger\n ]\n});\n"],"names":["DdbEsListEntriesImpl","storageModelProvider","bodyBuilder","fieldRegistry","fieldIndexRegistry","openSearchClient","indexProvider","debuggerService","initialModel","params","model","limit","createLimit","configurations","createConfigurations","index","shared","body","decodeCursor","response","startedAt","Date","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","convertEntryKeysFromStorage","hasMoreItems","cursor","encodeCursor","getTotalCount","DdbEsListEntries","ListEntriesStorageOperation","CmsStorageModelProvider","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","OpenSearchClient","CmsModelOpenSearchIndexProvider","Debugger"],"mappings":";;;;;;;;;;;;;;AA2BA,MAAMA;IAGF,YACYC,oBAAuD,EACvDC,WAAoD,EACpDC,aAAuD,EACvDC,kBAAkE,EAC1EC,gBAA4C,EACpCC,aAAwD,EACxDC,eAAmC,CAC7C;aAPUN,oBAAoB,GAApBA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aAEAE,aAAa,GAAbA;aACAC,eAAe,GAAfA;QAER,IAAI,CAAC,aAAa,GAAGF,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QACFG,YAAsB,EACtBC,MAA2C,EAC7C;QACE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIF;QAEpD,MAAMG,QAAQC,YAAYH,OAAO,KAAK,EAAE;QACxC,MAAMI,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAG,MAAMH,eAAe,EAAE,CAAC;YAC9CH;QACJ;QAEA,MAAMO,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAChCP;YACAM;YACA,QAAQ;gBACJ,GAAGP,MAAM;gBACTE;gBACA,OAAOO,aAAaT,OAAO,KAAK;YACpC;QACJ;QAEA,IAAIU;QACJ,MAAMC,YAAYC,KAAK,GAAG;QAC1B,IAAI;YACAF,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;gBACvCJ;gBACAE;YACJ;YAEA,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,eAAe,IAAO;oBAC3CF;oBACA,OAAOE;oBAKP,MAAME,SAAS,IAAI;oBACnB,YAAYA,SAAS,UAAU;oBAC/B,QAAQE,KAAK,GAAG,KAAKD;gBACzB;QACJ,EAAE,OAAOE,OAAO;YAKZ,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,eAAe,IAAO;oBAC3CP;oBACA,OAAOE;oBACPK;oBACA,QAAQD,KAAK,GAAG,KAAKD;gBACzB;YAMA,IAAIG,4BAA4BD,QAC5B,OAAO;gBACH,cAAc;gBACd,YAAY;gBACZ,QAAQ;gBACR,OAAO,EAAE;YACb;YAGJ,MAAM,IAAIE,cAAYF,MAAM,OAAO,EAAEA,MAAM,IAAI,IAAI,oBAAoB;gBACnEA;gBACAP;gBACAE;gBACAP;YACJ;QACJ;QAEA,MAAM,EAAEe,IAAI,EAAEC,KAAK,EAAE,GAAGP,SAAS,IAAI,CAAC,IAAI;QAE1C,MAAMQ,QAAQC,wBAA2B;YACrC,eAAe,IAAI,CAAC,aAAa;YACjC,oBAAoB,IAAI,CAAC,kBAAkB;YAC3ClB;YACA,SAASe,KAAK,GAAG,CAACI,CAAAA,OACPA,KAAK,OAAO;QAE3B,GAAG,GAAG,CAACA,CAAAA,OACIC,4BAA+B;gBAClCpB;gBACA,OAAOmB;YACX;QAGJ,MAAME,eAAeJ,MAAM,MAAM,GAAGhB;QACpC,IAAIoB,cAIAJ,MAAM,GAAG;QAMb,MAAMK,SAASL,MAAM,MAAM,GAAG,IAAIM,aAAaR,IAAI,CAACE,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,KAAK,OAAO;QACtF,OAAO;YACHI;YACA,YAAYG,cAAcR;YAC1BM;YACAL;QACJ;IACJ;AACJ;AAEO,MAAMQ,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBpC;IAChB,cAAc;QACVqC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -25,7 +25,7 @@ import { DdbEsGetUniqueFieldValues } from "./DdbEsGetUniqueFieldValues.js";
25
25
  const DdbEsEntryStorageOpsFeature = createFeature({
26
26
  name: "cms.ddbEs.entryStorageOps",
27
27
  register: (container)=>{
28
- container.register(DataLoadersHandler).inSingletonScope();
28
+ container.register(DataLoadersHandler).inContainerScope();
29
29
  container.register(DdbEsCreateEntry);
30
30
  container.register(DdbEsCreateEntryRevisionFrom);
31
31
  container.register(DdbEsUpdateEntry);
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DataLoadersHandler } from \"./dataLoaders.js\";\nimport { DdbEsCreateEntry } from \"./DdbEsCreateEntry.js\";\nimport { DdbEsCreateEntryRevisionFrom } from \"./DdbEsCreateEntryRevisionFrom.js\";\nimport { DdbEsUpdateEntry } from \"./DdbEsUpdateEntry.js\";\nimport { DdbEsMoveEntry } from \"./DdbEsMoveEntry.js\";\nimport { DdbEsMoveToBin } from \"./DdbEsMoveToBin.js\";\nimport { DdbEsDeleteEntry } from \"./DdbEsDeleteEntry.js\";\nimport { DdbEsRestoreFromBin } from \"./DdbEsRestoreFromBin.js\";\nimport { DdbEsDeleteEntryRevision } from \"./DdbEsDeleteEntryRevision.js\";\nimport { DdbEsDeleteMultipleEntries } from \"./DdbEsDeleteMultipleEntries.js\";\nimport { DdbEsGetEntry } from \"./DdbEsGetEntry.js\";\nimport { DdbEsListEntries } from \"./DdbEsListEntries.js\";\nimport { DdbEsPublishEntry } from \"./DdbEsPublishEntry.js\";\nimport { DdbEsUnpublishEntry } from \"./DdbEsUnpublishEntry.js\";\nimport { DdbEsGetEntriesByIds } from \"./DdbEsGetEntriesByIds.js\";\nimport { DdbEsGetLatestEntriesByIds } from \"./DdbEsGetLatestEntriesByIds.js\";\nimport { DdbEsGetPublishedEntriesByIds } from \"./DdbEsGetPublishedEntriesByIds.js\";\nimport { DdbEsGetRevisions } from \"./DdbEsGetRevisions.js\";\nimport { DdbEsGetRevisionById } from \"./DdbEsGetRevisionById.js\";\nimport { DdbEsGetLatestRevisionByEntryId } from \"./DdbEsGetLatestRevisionByEntryId.js\";\nimport { DdbEsGetPublishedRevisionByEntryId } from \"./DdbEsGetPublishedRevisionByEntryId.js\";\nimport { DdbEsGetPreviousRevision } from \"./DdbEsGetPreviousRevision.js\";\nimport { DdbEsGetUniqueFieldValues } from \"./DdbEsGetUniqueFieldValues.js\";\n\nexport const DdbEsEntryStorageOpsFeature = createFeature({\n name: \"cms.ddbEs.entryStorageOps\",\n register: container => {\n container.register(DataLoadersHandler).inSingletonScope();\n container.register(DdbEsCreateEntry);\n container.register(DdbEsCreateEntryRevisionFrom);\n container.register(DdbEsUpdateEntry);\n container.register(DdbEsMoveEntry);\n container.register(DdbEsMoveToBin);\n container.register(DdbEsDeleteEntry);\n container.register(DdbEsRestoreFromBin);\n container.register(DdbEsDeleteEntryRevision);\n container.register(DdbEsDeleteMultipleEntries);\n container.register(DdbEsGetEntry);\n container.register(DdbEsListEntries);\n container.register(DdbEsPublishEntry);\n container.register(DdbEsUnpublishEntry);\n container.register(DdbEsGetEntriesByIds);\n container.register(DdbEsGetLatestEntriesByIds);\n container.register(DdbEsGetPublishedEntriesByIds);\n container.register(DdbEsGetRevisions);\n container.register(DdbEsGetRevisionById);\n container.register(DdbEsGetLatestRevisionByEntryId);\n container.register(DdbEsGetPublishedRevisionByEntryId);\n container.register(DdbEsGetPreviousRevision);\n container.register(DdbEsGetUniqueFieldValues);\n }\n});\n"],"names":["DdbEsEntryStorageOpsFeature","createFeature","container","DataLoadersHandler","DdbEsCreateEntry","DdbEsCreateEntryRevisionFrom","DdbEsUpdateEntry","DdbEsMoveEntry","DdbEsMoveToBin","DdbEsDeleteEntry","DdbEsRestoreFromBin","DdbEsDeleteEntryRevision","DdbEsDeleteMultipleEntries","DdbEsGetEntry","DdbEsListEntries","DdbEsPublishEntry","DdbEsUnpublishEntry","DdbEsGetEntriesByIds","DdbEsGetLatestEntriesByIds","DdbEsGetPublishedEntriesByIds","DdbEsGetRevisions","DdbEsGetRevisionById","DdbEsGetLatestRevisionByEntryId","DdbEsGetPublishedRevisionByEntryId","DdbEsGetPreviousRevision","DdbEsGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;QACnBtB,UAAU,QAAQ,CAACuB;IACvB;AACJ"}
1
+ {"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DataLoadersHandler } from \"./dataLoaders.js\";\nimport { DdbEsCreateEntry } from \"./DdbEsCreateEntry.js\";\nimport { DdbEsCreateEntryRevisionFrom } from \"./DdbEsCreateEntryRevisionFrom.js\";\nimport { DdbEsUpdateEntry } from \"./DdbEsUpdateEntry.js\";\nimport { DdbEsMoveEntry } from \"./DdbEsMoveEntry.js\";\nimport { DdbEsMoveToBin } from \"./DdbEsMoveToBin.js\";\nimport { DdbEsDeleteEntry } from \"./DdbEsDeleteEntry.js\";\nimport { DdbEsRestoreFromBin } from \"./DdbEsRestoreFromBin.js\";\nimport { DdbEsDeleteEntryRevision } from \"./DdbEsDeleteEntryRevision.js\";\nimport { DdbEsDeleteMultipleEntries } from \"./DdbEsDeleteMultipleEntries.js\";\nimport { DdbEsGetEntry } from \"./DdbEsGetEntry.js\";\nimport { DdbEsListEntries } from \"./DdbEsListEntries.js\";\nimport { DdbEsPublishEntry } from \"./DdbEsPublishEntry.js\";\nimport { DdbEsUnpublishEntry } from \"./DdbEsUnpublishEntry.js\";\nimport { DdbEsGetEntriesByIds } from \"./DdbEsGetEntriesByIds.js\";\nimport { DdbEsGetLatestEntriesByIds } from \"./DdbEsGetLatestEntriesByIds.js\";\nimport { DdbEsGetPublishedEntriesByIds } from \"./DdbEsGetPublishedEntriesByIds.js\";\nimport { DdbEsGetRevisions } from \"./DdbEsGetRevisions.js\";\nimport { DdbEsGetRevisionById } from \"./DdbEsGetRevisionById.js\";\nimport { DdbEsGetLatestRevisionByEntryId } from \"./DdbEsGetLatestRevisionByEntryId.js\";\nimport { DdbEsGetPublishedRevisionByEntryId } from \"./DdbEsGetPublishedRevisionByEntryId.js\";\nimport { DdbEsGetPreviousRevision } from \"./DdbEsGetPreviousRevision.js\";\nimport { DdbEsGetUniqueFieldValues } from \"./DdbEsGetUniqueFieldValues.js\";\n\nexport const DdbEsEntryStorageOpsFeature = createFeature({\n name: \"cms.ddbEs.entryStorageOps\",\n register: container => {\n // The DataLoader caches reads, so it must live for one request: container scoped, it is built\n // per request (child) container even though the feature is registered once in the root.\n container.register(DataLoadersHandler).inContainerScope();\n container.register(DdbEsCreateEntry);\n container.register(DdbEsCreateEntryRevisionFrom);\n container.register(DdbEsUpdateEntry);\n container.register(DdbEsMoveEntry);\n container.register(DdbEsMoveToBin);\n container.register(DdbEsDeleteEntry);\n container.register(DdbEsRestoreFromBin);\n container.register(DdbEsDeleteEntryRevision);\n container.register(DdbEsDeleteMultipleEntries);\n container.register(DdbEsGetEntry);\n container.register(DdbEsListEntries);\n container.register(DdbEsPublishEntry);\n container.register(DdbEsUnpublishEntry);\n container.register(DdbEsGetEntriesByIds);\n container.register(DdbEsGetLatestEntriesByIds);\n container.register(DdbEsGetPublishedEntriesByIds);\n container.register(DdbEsGetRevisions);\n container.register(DdbEsGetRevisionById);\n container.register(DdbEsGetLatestRevisionByEntryId);\n container.register(DdbEsGetPublishedRevisionByEntryId);\n container.register(DdbEsGetPreviousRevision);\n container.register(DdbEsGetUniqueFieldValues);\n }\n});\n"],"names":["DdbEsEntryStorageOpsFeature","createFeature","container","DataLoadersHandler","DdbEsCreateEntry","DdbEsCreateEntryRevisionFrom","DdbEsUpdateEntry","DdbEsMoveEntry","DdbEsMoveToBin","DdbEsDeleteEntry","DdbEsRestoreFromBin","DdbEsDeleteEntryRevision","DdbEsDeleteMultipleEntries","DdbEsGetEntry","DdbEsListEntries","DdbEsPublishEntry","DdbEsUnpublishEntry","DdbEsGetEntriesByIds","DdbEsGetLatestEntriesByIds","DdbEsGetPublishedEntriesByIds","DdbEsGetRevisions","DdbEsGetRevisionById","DdbEsGetLatestRevisionByEntryId","DdbEsGetPublishedRevisionByEntryId","DdbEsGetPreviousRevision","DdbEsGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAAUC,CAAAA;QAGNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;QACnBtB,UAAU,QAAQ,CAACuB;IACvB;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-ddb-es",
3
- "version": "6.6.0-alpha.1",
3
+ "version": "6.6.0-alpha.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -30,40 +30,40 @@
30
30
  ],
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@webiny/api": "6.6.0-alpha.1",
34
- "@webiny/api-headless-cms": "6.6.0-alpha.1",
35
- "@webiny/api-headless-cms-storage": "6.6.0-alpha.1",
36
- "@webiny/api-headless-cms-utils-os": "6.6.0-alpha.1",
37
- "@webiny/api-opensearch": "6.6.0-alpha.1",
38
- "@webiny/api-opensearch-aws": "6.6.0-alpha.1",
39
- "@webiny/api-search-index-tasks": "6.6.0-alpha.1",
40
- "@webiny/db": "6.6.0-alpha.1",
41
- "@webiny/db-dynamodb": "6.6.0-alpha.1",
42
- "@webiny/error": "6.6.0-alpha.1",
43
- "@webiny/feature": "6.6.0-alpha.1",
44
- "@webiny/plugins": "6.6.0-alpha.1",
45
- "@webiny/stdlib": "0.0.17",
46
- "@webiny/utils": "6.6.0-alpha.1",
33
+ "@webiny/api": "6.6.0-alpha.10",
34
+ "@webiny/api-core": "6.6.0-alpha.10",
35
+ "@webiny/api-headless-cms": "6.6.0-alpha.10",
36
+ "@webiny/api-headless-cms-storage": "6.6.0-alpha.10",
37
+ "@webiny/api-headless-cms-utils-os": "6.6.0-alpha.10",
38
+ "@webiny/api-opensearch": "6.6.0-alpha.10",
39
+ "@webiny/api-opensearch-aws": "6.6.0-alpha.10",
40
+ "@webiny/api-search-index-tasks": "6.6.0-alpha.10",
41
+ "@webiny/db": "6.6.0-alpha.10",
42
+ "@webiny/db-dynamodb": "6.6.0-alpha.10",
43
+ "@webiny/error": "6.6.0-alpha.10",
44
+ "@webiny/feature": "6.6.0-alpha.10",
45
+ "@webiny/plugins": "6.6.0-alpha.10",
46
+ "@webiny/stdlib": "0.0.21",
47
+ "@webiny/utils": "6.6.0-alpha.10",
47
48
  "dataloader": "2.2.3",
48
49
  "lodash": "4.18.1"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@types/jsonpack": "1.1.6",
52
- "@webiny/api-core": "6.6.0-alpha.1",
53
- "@webiny/api-core-testing": "6.6.0-alpha.1",
54
- "@webiny/api-graphql": "6.6.0-alpha.1",
55
- "@webiny/api-search-index-tasks-ddb-os": "6.6.0-alpha.1",
56
- "@webiny/api-sync-ddb-to-opensearch": "6.6.0-alpha.1",
57
- "@webiny/background-tasks": "6.6.0-alpha.1",
58
- "@webiny/build-tools": "6.6.0-alpha.1",
59
- "@webiny/di": "1.1.0",
60
- "@webiny/event-handler-core": "6.6.0-alpha.1",
61
- "@webiny/handler": "6.6.0-alpha.1",
62
- "@webiny/wcp": "6.6.0-alpha.1",
53
+ "@webiny/api-core-testing": "6.6.0-alpha.10",
54
+ "@webiny/api-graphql": "6.6.0-alpha.10",
55
+ "@webiny/api-search-index-tasks-ddb-os": "6.6.0-alpha.10",
56
+ "@webiny/api-sync-ddb-to-opensearch": "6.6.0-alpha.10",
57
+ "@webiny/background-tasks": "6.6.0-alpha.10",
58
+ "@webiny/build-tools": "6.6.0-alpha.10",
59
+ "@webiny/di": "2.0.0",
60
+ "@webiny/event-handler-core": "6.6.0-alpha.10",
61
+ "@webiny/handler": "6.6.0-alpha.10",
62
+ "@webiny/wcp": "6.6.0-alpha.10",
63
63
  "jest-dynalite": "3.6.1",
64
64
  "rimraf": "6.1.3",
65
65
  "typescript": "7.0.2",
66
- "vitest": "4.1.11"
66
+ "vitest": "5.0.5"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"
@@ -0,0 +1,27 @@
1
+ import { DbRegistry } from "@webiny/db/exports/api/db.js";
2
+ import { CmsDdbEsEntryEntity } from "../abstractions/CmsDdbEsEntryEntity.js";
3
+ import { CmsDdbEsEntriesEsEntity } from "../abstractions/CmsDdbEsEntriesEsEntity.js";
4
+ /**
5
+ * Adds the CMS entities to every request's DbRegistry.
6
+ *
7
+ * DbRegistry is container scoped: each request (child) container builds its own, empty registry. The
8
+ * DDB to OpenSearch sync looks up two CMS entities in it (the DynamoDB entries entity and the
9
+ * OpenSearch entries entity), so every one of those registries needs them.
10
+ *
11
+ * The CMS storage feature runs once, in the root, before any request exists, so it can't register into
12
+ * per-request registries directly. Instead it registers this decorator in the root. Decorators on a
13
+ * container-scoped registration apply to every instance as it is built, so this constructor runs once
14
+ * per request registry and adds the two entities. Every other call passes through to the registry.
15
+ */
16
+ declare class CmsEntitiesDbRegistryDecoratorImpl implements DbRegistry.Interface {
17
+ private readonly decoratee;
18
+ constructor(entryEntity: CmsDdbEsEntryEntity.Interface, entriesEsEntity: CmsDdbEsEntriesEsEntity.Interface, decoratee: DbRegistry.Interface);
19
+ register<T = unknown>(params: DbRegistry.RegisterParams<T>): void;
20
+ getOneItem<T = unknown>(cb: (item: DbRegistry.RegistryItem<T>) => boolean): DbRegistry.RegistryItem<T>;
21
+ getItem<T = unknown>(cb: (item: DbRegistry.RegistryItem<T>) => boolean): DbRegistry.RegistryItem<T> | null;
22
+ getItems<T = unknown>(cb: (item: DbRegistry.RegistryItem<T>) => boolean): DbRegistry.RegistryItem<T>[];
23
+ }
24
+ export declare const CmsEntitiesDbRegistryDecorator: typeof CmsEntitiesDbRegistryDecoratorImpl & {
25
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/db/features/DbRegistry/abstractions").IRegistry>;
26
+ };
27
+ export {};
@@ -0,0 +1,46 @@
1
+ import { DbRegistry } from "@webiny/db/exports/api/db.js";
2
+ import { CmsDdbEsEntryEntity } from "../abstractions/CmsDdbEsEntryEntity.js";
3
+ import { CmsDdbEsEntriesEsEntity } from "../abstractions/CmsDdbEsEntriesEsEntity.js";
4
+ class CmsEntitiesDbRegistryDecoratorImpl {
5
+ constructor(entryEntity, entriesEsEntity, decoratee){
6
+ this.decoratee = decoratee;
7
+ decoratee.register({
8
+ item: entryEntity,
9
+ app: "cms",
10
+ tags: [
11
+ "regular",
12
+ entryEntity.name
13
+ ]
14
+ });
15
+ decoratee.register({
16
+ item: entriesEsEntity,
17
+ app: "cms",
18
+ tags: [
19
+ "es",
20
+ entriesEsEntity.name
21
+ ]
22
+ });
23
+ }
24
+ register(params) {
25
+ this.decoratee.register(params);
26
+ }
27
+ getOneItem(cb) {
28
+ return this.decoratee.getOneItem(cb);
29
+ }
30
+ getItem(cb) {
31
+ return this.decoratee.getItem(cb);
32
+ }
33
+ getItems(cb) {
34
+ return this.decoratee.getItems(cb);
35
+ }
36
+ }
37
+ const CmsEntitiesDbRegistryDecorator = DbRegistry.createDecorator({
38
+ decorator: CmsEntitiesDbRegistryDecoratorImpl,
39
+ dependencies: [
40
+ CmsDdbEsEntryEntity,
41
+ CmsDdbEsEntriesEsEntity
42
+ ]
43
+ });
44
+ export { CmsEntitiesDbRegistryDecorator };
45
+
46
+ //# sourceMappingURL=CmsEntitiesDbRegistryDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry/CmsEntitiesDbRegistryDecorator.js","sources":["../../src/registry/CmsEntitiesDbRegistryDecorator.ts"],"sourcesContent":["import { DbRegistry } from \"@webiny/db/exports/api/db.js\";\nimport { CmsDdbEsEntryEntity } from \"~/abstractions/CmsDdbEsEntryEntity.js\";\nimport { CmsDdbEsEntriesEsEntity } from \"~/abstractions/CmsDdbEsEntriesEsEntity.js\";\n\n/**\n * Adds the CMS entities to every request's DbRegistry.\n *\n * DbRegistry is container scoped: each request (child) container builds its own, empty registry. The\n * DDB to OpenSearch sync looks up two CMS entities in it (the DynamoDB entries entity and the\n * OpenSearch entries entity), so every one of those registries needs them.\n *\n * The CMS storage feature runs once, in the root, before any request exists, so it can't register into\n * per-request registries directly. Instead it registers this decorator in the root. Decorators on a\n * container-scoped registration apply to every instance as it is built, so this constructor runs once\n * per request registry and adds the two entities. Every other call passes through to the registry.\n */\nclass CmsEntitiesDbRegistryDecoratorImpl implements DbRegistry.Interface {\n public constructor(\n entryEntity: CmsDdbEsEntryEntity.Interface,\n entriesEsEntity: CmsDdbEsEntriesEsEntity.Interface,\n private readonly decoratee: DbRegistry.Interface\n ) {\n decoratee.register({\n item: entryEntity,\n app: \"cms\",\n tags: [\"regular\", entryEntity.name]\n });\n decoratee.register({\n item: entriesEsEntity,\n app: \"cms\",\n tags: [\"es\", entriesEsEntity.name]\n });\n }\n\n public register<T = unknown>(params: DbRegistry.RegisterParams<T>): void {\n this.decoratee.register(params);\n }\n\n public getOneItem<T = unknown>(\n cb: (item: DbRegistry.RegistryItem<T>) => boolean\n ): DbRegistry.RegistryItem<T> {\n return this.decoratee.getOneItem(cb);\n }\n\n public getItem<T = unknown>(\n cb: (item: DbRegistry.RegistryItem<T>) => boolean\n ): DbRegistry.RegistryItem<T> | null {\n return this.decoratee.getItem(cb);\n }\n\n public getItems<T = unknown>(\n cb: (item: DbRegistry.RegistryItem<T>) => boolean\n ): DbRegistry.RegistryItem<T>[] {\n return this.decoratee.getItems(cb);\n }\n}\n\nexport const CmsEntitiesDbRegistryDecorator = DbRegistry.createDecorator({\n decorator: CmsEntitiesDbRegistryDecoratorImpl,\n dependencies: [CmsDdbEsEntryEntity, CmsDdbEsEntriesEsEntity]\n});\n"],"names":["CmsEntitiesDbRegistryDecoratorImpl","entryEntity","entriesEsEntity","decoratee","params","cb","CmsEntitiesDbRegistryDecorator","DbRegistry","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity"],"mappings":";;;AAgBA,MAAMA;IACF,YACIC,WAA0C,EAC1CC,eAAkD,EACjCC,SAA+B,CAClD;aADmBA,SAAS,GAATA;QAEjBA,UAAU,QAAQ,CAAC;YACf,MAAMF;YACN,KAAK;YACL,MAAM;gBAAC;gBAAWA,YAAY,IAAI;aAAC;QACvC;QACAE,UAAU,QAAQ,CAAC;YACf,MAAMD;YACN,KAAK;YACL,MAAM;gBAAC;gBAAMA,gBAAgB,IAAI;aAAC;QACtC;IACJ;IAEO,SAAsBE,MAAoC,EAAQ;QACrE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAACA;IAC5B;IAEO,WACHC,EAAiD,EACvB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAACA;IACrC;IAEO,QACHA,EAAiD,EAChB;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA;IAClC;IAEO,SACHA,EAAiD,EACrB;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAACA;IACnC;AACJ;AAEO,MAAMC,iCAAiCC,WAAW,eAAe,CAAC;IACrE,WAAWP;IACX,cAAc;QAACQ;QAAqBC;KAAwB;AAChE"}
@@ -1,10 +1,12 @@
1
1
  import { TenantIndexFactory } from "@webiny/api-search-index-tasks";
2
2
  import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
3
3
  import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
4
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
4
5
  declare class CreateElasticsearchIndexTaskImpl implements TenantIndexFactory.Interface {
5
6
  private readonly indexProvider;
6
7
  private listModels;
7
- constructor(indexProvider: CmsModelOpenSearchIndexProvider.Interface, listModels: ListModelsUseCase.Interface);
8
+ private readonly logger;
9
+ constructor(indexProvider: CmsModelOpenSearchIndexProvider.Interface, listModels: ListModelsUseCase.Interface, logger: Logger.Interface);
8
10
  getIndexList(tenant: TenantIndexFactory.Tenant): Promise<TenantIndexFactory.IndexConfig[]>;
9
11
  }
10
12
  export declare const CreateElasticsearchIndexTask: typeof CreateElasticsearchIndexTaskImpl & {
@@ -2,13 +2,21 @@ import { TenantIndexFactory } from "@webiny/api-search-index-tasks";
2
2
  import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
3
3
  import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
4
4
  import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
5
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
5
6
  class CreateElasticsearchIndexTaskImpl {
6
- constructor(indexProvider, listModels){
7
+ constructor(indexProvider, listModels, logger){
7
8
  this.indexProvider = indexProvider;
8
9
  this.listModels = listModels;
10
+ this.logger = logger;
9
11
  }
10
12
  async getIndexList(tenant) {
11
13
  const result = await this.listModels.execute();
14
+ if (result.isFail()) {
15
+ this.logger.error({
16
+ error: result.error
17
+ }, "Failed to list models for index creation.");
18
+ return [];
19
+ }
12
20
  const models = result.value;
13
21
  if (0 === models.length) return [];
14
22
  const configurations = createConfigurations(this.indexProvider);
@@ -32,7 +40,8 @@ const CreateElasticsearchIndexTask = TenantIndexFactory.createImplementation({
32
40
  implementation: CreateElasticsearchIndexTaskImpl,
33
41
  dependencies: [
34
42
  CmsModelOpenSearchIndexProvider,
35
- ListModelsUseCase
43
+ ListModelsUseCase,
44
+ Logger
36
45
  ]
37
46
  });
38
47
  export { CreateElasticsearchIndexTask };
@@ -1 +1 @@
1
- {"version":3,"file":"tasks/CreateElasticsearchIndexTask.js","sources":["../../src/tasks/CreateElasticsearchIndexTask.ts"],"sourcesContent":["import { TenantIndexFactory } from \"@webiny/api-search-index-tasks\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\n\nclass CreateElasticsearchIndexTaskImpl implements TenantIndexFactory.Interface {\n constructor(\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private listModels: ListModelsUseCase.Interface\n ) {}\n\n async getIndexList(\n tenant: TenantIndexFactory.Tenant\n ): Promise<TenantIndexFactory.IndexConfig[]> {\n const result = await this.listModels.execute();\n const models = result.value;\n\n if (models.length === 0) {\n return [];\n }\n\n const configurations = createConfigurations(this.indexProvider);\n\n const indices: TenantIndexFactory.IndexConfig[] = [];\n for (const model of models) {\n const { index, settings } = await configurations.es({\n model: {\n ...model,\n tenant: tenant.id\n }\n });\n indices.push({ index, settings });\n }\n return indices;\n }\n}\n\nexport const CreateElasticsearchIndexTask = TenantIndexFactory.createImplementation({\n implementation: CreateElasticsearchIndexTaskImpl,\n dependencies: [CmsModelOpenSearchIndexProvider, ListModelsUseCase]\n});\n"],"names":["CreateElasticsearchIndexTaskImpl","indexProvider","listModels","tenant","result","models","configurations","createConfigurations","indices","model","index","settings","CreateElasticsearchIndexTask","TenantIndexFactory","CmsModelOpenSearchIndexProvider","ListModelsUseCase"],"mappings":";;;;AAKA,MAAMA;IACF,YACqBC,aAAwD,EACjEC,UAAuC,CACjD;aAFmBD,aAAa,GAAbA;aACTC,UAAU,GAAVA;IACT;IAEH,MAAM,aACFC,MAAiC,EACQ;QACzC,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO;QAC5C,MAAMC,SAASD,OAAO,KAAK;QAE3B,IAAIC,AAAkB,MAAlBA,OAAO,MAAM,EACb,OAAO,EAAE;QAGb,MAAMC,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAE9D,MAAMC,UAA4C,EAAE;QACpD,KAAK,MAAMC,SAASJ,OAAQ;YACxB,MAAM,EAAEK,KAAK,EAAEC,QAAQ,EAAE,GAAG,MAAML,eAAe,EAAE,CAAC;gBAChD,OAAO;oBACH,GAAGG,KAAK;oBACR,QAAQN,OAAO,EAAE;gBACrB;YACJ;YACAK,QAAQ,IAAI,CAAC;gBAAEE;gBAAOC;YAAS;QACnC;QACA,OAAOH;IACX;AACJ;AAEO,MAAMI,+BAA+BC,mBAAmB,oBAAoB,CAAC;IAChF,gBAAgBb;IAChB,cAAc;QAACc;QAAiCC;KAAkB;AACtE"}
1
+ {"version":3,"file":"tasks/CreateElasticsearchIndexTask.js","sources":["../../src/tasks/CreateElasticsearchIndexTask.ts"],"sourcesContent":["import { TenantIndexFactory } from \"@webiny/api-search-index-tasks\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\n\nclass CreateElasticsearchIndexTaskImpl implements TenantIndexFactory.Interface {\n constructor(\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private listModels: ListModelsUseCase.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n async getIndexList(\n tenant: TenantIndexFactory.Tenant\n ): Promise<TenantIndexFactory.IndexConfig[]> {\n const result = await this.listModels.execute();\n if (result.isFail()) {\n this.logger.error({ error: result.error }, \"Failed to list models for index creation.\");\n return [];\n }\n const models = result.value;\n\n if (models.length === 0) {\n return [];\n }\n\n const configurations = createConfigurations(this.indexProvider);\n\n const indices: TenantIndexFactory.IndexConfig[] = [];\n for (const model of models) {\n const { index, settings } = await configurations.es({\n model: {\n ...model,\n tenant: tenant.id\n }\n });\n indices.push({ index, settings });\n }\n return indices;\n }\n}\n\nexport const CreateElasticsearchIndexTask = TenantIndexFactory.createImplementation({\n implementation: CreateElasticsearchIndexTaskImpl,\n dependencies: [CmsModelOpenSearchIndexProvider, ListModelsUseCase, Logger]\n});\n"],"names":["CreateElasticsearchIndexTaskImpl","indexProvider","listModels","logger","tenant","result","models","configurations","createConfigurations","indices","model","index","settings","CreateElasticsearchIndexTask","TenantIndexFactory","CmsModelOpenSearchIndexProvider","ListModelsUseCase","Logger"],"mappings":";;;;;AAMA,MAAMA;IACF,YACqBC,aAAwD,EACjEC,UAAuC,EAC9BC,MAAwB,CAC3C;aAHmBF,aAAa,GAAbA;aACTC,UAAU,GAAVA;aACSC,MAAM,GAANA;IAClB;IAEH,MAAM,aACFC,MAAiC,EACQ;QACzC,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO;QAC5C,IAAIA,OAAO,MAAM,IAAI;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAOA,OAAO,KAAK;YAAC,GAAG;YAC3C,OAAO,EAAE;QACb;QACA,MAAMC,SAASD,OAAO,KAAK;QAE3B,IAAIC,AAAkB,MAAlBA,OAAO,MAAM,EACb,OAAO,EAAE;QAGb,MAAMC,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAE9D,MAAMC,UAA4C,EAAE;QACpD,KAAK,MAAMC,SAASJ,OAAQ;YACxB,MAAM,EAAEK,KAAK,EAAEC,QAAQ,EAAE,GAAG,MAAML,eAAe,EAAE,CAAC;gBAChD,OAAO;oBACH,GAAGG,KAAK;oBACR,QAAQN,OAAO,EAAE;gBACrB;YACJ;YACAK,QAAQ,IAAI,CAAC;gBAAEE;gBAAOC;YAAS;QACnC;QACA,OAAOH;IACX;AACJ;AAEO,MAAMI,+BAA+BC,mBAAmB,oBAAoB,CAAC;IAChF,gBAAgBd;IAChB,cAAc;QAACe;QAAiCC;QAAmBC;KAAO;AAC9E"}