@webiny/api-headless-cms-ddb-es 6.6.0-alpha.0 → 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.
Files changed (53) hide show
  1. package/abstractions/CmsDdbEsEntriesEsEntity.d.ts +1 -1
  2. package/abstractions/CmsDdbEsEntriesEsEntity.js.map +1 -1
  3. package/debuggerNamespaces.d.ts +12 -0
  4. package/debuggerNamespaces.js +0 -0
  5. package/feature.d.ts +6 -0
  6. package/feature.js +9 -27
  7. package/feature.js.map +1 -1
  8. package/operations/entry/DdbEsCreateEntry.d.ts +3 -2
  9. package/operations/entry/DdbEsCreateEntry.js +7 -4
  10. package/operations/entry/DdbEsCreateEntry.js.map +1 -1
  11. package/operations/entry/DdbEsCreateEntryRevisionFrom.d.ts +3 -2
  12. package/operations/entry/DdbEsCreateEntryRevisionFrom.js +7 -4
  13. package/operations/entry/DdbEsCreateEntryRevisionFrom.js.map +1 -1
  14. package/operations/entry/DdbEsDeleteEntryRevision.d.ts +3 -2
  15. package/operations/entry/DdbEsDeleteEntryRevision.js +7 -4
  16. package/operations/entry/DdbEsDeleteEntryRevision.js.map +1 -1
  17. package/operations/entry/DdbEsDeleteMultipleEntries.js +23 -22
  18. package/operations/entry/DdbEsDeleteMultipleEntries.js.map +1 -1
  19. package/operations/entry/DdbEsGetPreviousRevision.js +1 -1
  20. package/operations/entry/DdbEsGetPreviousRevision.js.map +1 -1
  21. package/operations/entry/DdbEsGetUniqueFieldValues.d.ts +3 -2
  22. package/operations/entry/DdbEsGetUniqueFieldValues.js +9 -5
  23. package/operations/entry/DdbEsGetUniqueFieldValues.js.map +1 -1
  24. package/operations/entry/DdbEsListEntries.d.ts +6 -2
  25. package/operations/entry/DdbEsListEntries.js +27 -5
  26. package/operations/entry/DdbEsListEntries.js.map +1 -1
  27. package/operations/entry/DdbEsMoveEntry.js.map +1 -1
  28. package/operations/entry/DdbEsMoveToBin.js.map +1 -1
  29. package/operations/entry/DdbEsPublishEntry.d.ts +3 -2
  30. package/operations/entry/DdbEsPublishEntry.js +7 -4
  31. package/operations/entry/DdbEsPublishEntry.js.map +1 -1
  32. package/operations/entry/DdbEsRestoreFromBin.js.map +1 -1
  33. package/operations/entry/DdbEsUnpublishEntry.d.ts +3 -2
  34. package/operations/entry/DdbEsUnpublishEntry.js +7 -4
  35. package/operations/entry/DdbEsUnpublishEntry.js.map +1 -1
  36. package/operations/entry/DdbEsUpdateEntry.d.ts +3 -2
  37. package/operations/entry/DdbEsUpdateEntry.js +7 -4
  38. package/operations/entry/DdbEsUpdateEntry.js.map +1 -1
  39. package/operations/entry/feature.js +1 -1
  40. package/operations/entry/feature.js.map +1 -1
  41. package/operations/model/DdbEsCreateModel.d.ts +3 -1
  42. package/operations/model/DdbEsCreateModel.js +8 -4
  43. package/operations/model/DdbEsCreateModel.js.map +1 -1
  44. package/operations/model/DdbEsDeleteModel.d.ts +1 -3
  45. package/operations/model/DdbEsDeleteModel.js +2 -21
  46. package/operations/model/DdbEsDeleteModel.js.map +1 -1
  47. package/package.json +27 -27
  48. package/registry/CmsEntitiesDbRegistryDecorator.d.ts +27 -0
  49. package/registry/CmsEntitiesDbRegistryDecorator.js +46 -0
  50. package/registry/CmsEntitiesDbRegistryDecorator.js.map +1 -0
  51. package/tasks/CreateElasticsearchIndexTask.d.ts +5 -3
  52. package/tasks/CreateElasticsearchIndexTask.js +25 -25
  53. package/tasks/CreateElasticsearchIndexTask.js.map +1 -1
@@ -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"}
@@ -1,11 +1,12 @@
1
1
  import type { CmsModel, CmsEntryStorageOperationsGetUniqueFieldValuesParams } from "@webiny/api-headless-cms/types/index.js";
2
2
  import { GetUniqueFieldValuesStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js";
3
3
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
4
- import { CmsEntryOpenSearchBodyBuilder } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
4
+ import { CmsEntryOpenSearchBodyBuilder, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
5
5
  declare class DdbEsGetUniqueFieldValuesImpl implements GetUniqueFieldValuesStorageOperation.Interface {
6
6
  private bodyBuilder;
7
+ private indexProvider;
7
8
  private elasticsearch;
8
- constructor(bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, openSearchClient: OpenSearchClient.Interface);
9
+ constructor(bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
9
10
  execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams): Promise<{
10
11
  value: string;
11
12
  count: number;
@@ -1,21 +1,24 @@
1
1
  import _webiny_error from "@webiny/error";
2
2
  import { GetUniqueFieldValuesStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/entry/GetUniqueFieldValuesStorageOperation.js";
3
3
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
4
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
4
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
5
5
  import { shouldIgnoreEsResponseError } from "@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js";
6
- import { CmsEntryOpenSearchBodyBuilder } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
6
+ import { CmsEntryOpenSearchBodyBuilder, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
7
7
  class DdbEsGetUniqueFieldValuesImpl {
8
- constructor(bodyBuilder, openSearchClient){
8
+ constructor(bodyBuilder, openSearchClient, indexProvider){
9
9
  this.bodyBuilder = bodyBuilder;
10
+ this.indexProvider = indexProvider;
10
11
  this.elasticsearch = openSearchClient.use();
11
12
  }
12
13
  async execute(model, params) {
13
14
  const { where, fieldId } = params;
14
- const { index } = configurations.es({
15
+ const configurations = createConfigurations(this.indexProvider);
16
+ const { index, shared } = await configurations.es({
15
17
  model
16
18
  });
17
19
  const initialBody = this.bodyBuilder.build({
18
20
  model,
21
+ shared,
19
22
  params: {
20
23
  limit: 1,
21
24
  where
@@ -65,7 +68,8 @@ const DdbEsGetUniqueFieldValues = GetUniqueFieldValuesStorageOperation.createImp
65
68
  implementation: DdbEsGetUniqueFieldValuesImpl,
66
69
  dependencies: [
67
70
  CmsEntryOpenSearchBodyBuilder,
68
- OpenSearchClient
71
+ OpenSearchClient,
72
+ CmsModelOpenSearchIndexProvider
69
73
  ]
70
74
  });
71
75
  export { DdbEsGetUniqueFieldValues };
@@ -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 { configurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { shouldIgnoreEsResponseError } from \"@webiny/api-headless-cms-utils-os/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js\";\nimport { CmsEntryOpenSearchBodyBuilder } 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 ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(model: CmsModel, params: CmsEntryStorageOperationsGetUniqueFieldValuesParams) {\n const { where, fieldId } = params;\n\n const { index } = 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]\n});\n"],"names":["DdbEsGetUniqueFieldValuesImpl","bodyBuilder","openSearchClient","model","params","where","fieldId","index","configurations","initialBody","field","f","WebinyError","body","response","error","shouldIgnoreEsResponseError","aggregations","agg","buckets","Array","bucket","DdbEsGetUniqueFieldValues","GetUniqueFieldValuesStorageOperation","CmsEntryOpenSearchBodyBuilder","OpenSearchClient"],"mappings":";;;;;;AAgBA,MAAMA;IAGF,YACYC,WAAoD,EAC5DC,gBAA4C,CAC9C;aAFUD,WAAW,GAAXA;QAGR,IAAI,CAAC,aAAa,GAAGC,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQC,KAAe,EAAEC,MAA2D,EAAE;QACxF,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAE,GAAGF;QAE3B,MAAM,EAAEG,KAAK,EAAE,GAAGC,eAAe,EAAE,CAAC;YAChCL;QACJ;QAEA,MAAMM,cAAc,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YACvCN;YACA,QAAQ;gBACJ,OAAO;gBACPE;YACJ;QACJ;QAEA,MAAMK,QAAQP,MAAM,MAAM,CAAC,IAAI,CAACQ,CAAAA,IAAKA,EAAE,OAAO,KAAKL;QACnD,IAAI,CAACI,OACD,MAAM,IAAIE,cACN,oDACA,mBACA;YACIN;QACJ;QAIR,MAAMO,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;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;gBACAJ;gBACAU;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,gBAAgBvB;IAChB,cAAc;QAACwB;QAA+BC;KAAiB;AACnE"}
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"}
@@ -3,14 +3,18 @@ import { ListEntriesStorageOperation } from "@webiny/api-headless-cms/features/s
3
3
  import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
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
- import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
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;
14
+ private indexProvider;
15
+ private debuggerService;
12
16
  private elasticsearch;
13
- constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface);
17
+ constructor(storageModelProvider: CmsStorageModelProvider.Interface, bodyBuilder: CmsEntryOpenSearchBodyBuilder.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, debuggerService: Debugger.Interface);
14
18
  execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsListParams): Promise<{
15
19
  hasMoreItems: boolean;
16
20
  totalCount: number;
@@ -5,27 +5,33 @@ import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports
5
5
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
6
6
  import { createLimit, decodeCursor, encodeCursor } from "@webiny/api-opensearch";
7
7
  import { getTotalCount } from "@webiny/api-opensearch/types.js";
8
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
8
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
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
- import { CmsEntryOpenSearchBodyBuilder, CmsEntryOpenSearchFieldIndexRegistry } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
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){
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;
21
+ this.indexProvider = indexProvider;
22
+ this.debuggerService = debuggerService;
19
23
  this.elasticsearch = openSearchClient.use();
20
24
  }
21
25
  async execute(initialModel, params) {
22
26
  const model = this.storageModelProvider.getModel(initialModel);
23
27
  const limit = createLimit(params.limit, 50);
24
- const { index } = configurations.es({
28
+ const configurations = createConfigurations(this.indexProvider);
29
+ const { index, shared } = await configurations.es({
25
30
  model
26
31
  });
27
32
  const body = this.bodyBuilder.build({
28
33
  model,
34
+ shared,
29
35
  params: {
30
36
  ...params,
31
37
  limit,
@@ -33,12 +39,26 @@ class DdbEsListEntriesImpl {
33
39
  }
34
40
  });
35
41
  let response;
42
+ const startedAt = Date.now();
36
43
  try {
37
44
  response = await this.elasticsearch.search({
38
45
  index,
39
46
  body
40
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
+ }));
41
55
  } catch (error) {
56
+ this.debuggerService.log("cms.os.list", ()=>({
57
+ index,
58
+ query: body,
59
+ error,
60
+ tookMs: Date.now() - startedAt
61
+ }));
42
62
  if (shouldIgnoreEsResponseError(error)) return {
43
63
  hasMoreItems: false,
44
64
  totalCount: 0,
@@ -80,7 +100,9 @@ const DdbEsListEntries = ListEntriesStorageOperation.createImplementation({
80
100
  CmsEntryOpenSearchBodyBuilder,
81
101
  CmsModelFieldToGraphQLRegistry,
82
102
  CmsEntryOpenSearchFieldIndexRegistry,
83
- OpenSearchClient
103
+ OpenSearchClient,
104
+ CmsModelOpenSearchIndexProvider,
105
+ Debugger
84
106
  ]
85
107
  });
86
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 { configurations } 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} 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 ) {\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 { index } = 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 ]\n});\n"],"names":["DdbEsListEntriesImpl","storageModelProvider","bodyBuilder","fieldRegistry","fieldIndexRegistry","openSearchClient","initialModel","params","model","limit","createLimit","index","configurations","body","decodeCursor","response","error","shouldIgnoreEsResponseError","WebinyError","hits","total","items","extractEntriesFromIndex","item","convertEntryKeysFromStorage","hasMoreItems","cursor","encodeCursor","getTotalCount","DdbEsListEntries","ListEntriesStorageOperation","CmsStorageModelProvider","CmsEntryOpenSearchBodyBuilder","CmsModelFieldToGraphQLReg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AA,OACPA,KAAK,OAAO;QAE3B,GAAG,GAAG,CAACA,CAAAA,OACIC,4BAA+B;gBAClChB;gBACA,OAAOe;YACX;QAGJ,MAAME,eAAeJ,MAAM,MAAM,GAAGZ;QACpC,IAAIgB,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,gBAAgB9B;IAChB,cAAc;QACV+B;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,OAA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entry/DdbEsMoveEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveEntryStorageOperation.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 { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\n\nclass DdbEsMoveEntryImpl implements MoveEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private compressionHandler: CompressionHandler.Interface\n ) {}\n\n async execute(initialModel: CmsModel, id: string, folderId: string) {\n const model = this.storageModelProvider.getModel(initialModel);\n\n const partitionKey = createPartitionKey({\n id,\n tenant: model.tenant\n });\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n /**\n * Then update the folderId in each record and prepare it to be stored.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n location: {\n ...record.data.location,\n folderId\n }\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: initialModel.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not move all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_ERROR\",\n {\n error: ex,\n id\n }\n );\n }\n\n const esEntityReader = this.esEntity.createEntityReader();\n\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n try {\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: await Promise.all(\n esItems.map(async item => {\n return {\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n location: {\n ...item.data?.location,\n folderId\n }\n })\n };\n })\n )\n });\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not move entry DynamoDB Elasticsearch records.\",\n ex.code || \"MOVE_ES_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveEntry = MoveEntryStorageOperation.createImplementation({\n implementation: DdbEsMoveEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CompressionHandler\n ]\n});\n"],"names":["DdbEsMoveEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","compressionHandler","initialModel","id","folderId","model","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveEntry","MoveEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CompressionHandler"],"mappings":";;;;;;;;AAYA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAgD,CAC1D;aALUJ,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,EAAU,EAAEC,QAAgB,EAAE;QAChE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACH;QAEjD,MAAMI,eAAeC,mBAAmB;YACpCJ;YACA,QAAQE,MAAM,MAAM;QACxB;QAIA,MAAMG,iBAAwC;YAC1CF;YACA,SAAS;gBACL,KAAK;YACT;QACJ;QACA,MAAMG,gBAAgBC;QACtB,MAAMC,mBAAmBC;QACzB,MAAMC,UAAU,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAACL;QAI3C,IAAIM;QACJ,IAAIC;QACJ,MAAMC,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB;QAElD,KAAK,MAAMC,UAAUJ,QAAS;YAC1BG,YAAY,GAAG,CAAC;gBACZ,GAAGC,MAAM;gBACT,MAAM;oBACF,GAAGA,OAAO,IAAI;oBACd,UAAU;wBACN,GAAGA,OAAO,IAAI,CAAC,QAAQ;wBACvBb;oBACJ;gB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;gCACN,GAAGA,KAAK,IAAI,EAAE,QAAQ;gCACtBpB;4BACJ;wBACJ;oBACJ;YAGZ;YACA,MAAMqB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wDACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPZ;YACJ;QAER;IACJ;AACJ;AAEO,MAAMoB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsMoveEntry.js","sources":["../../../src/operations/entry/DdbEsMoveEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveEntryStorageOperation.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 { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\n\nclass DdbEsMoveEntryImpl implements MoveEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private compressionHandler: CompressionHandler.Interface\n ) {}\n\n async execute(initialModel: CmsModel, id: string, folderId: string) {\n const model = this.storageModelProvider.getModel(initialModel);\n\n const partitionKey = createPartitionKey({\n id,\n tenant: model.tenant\n });\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n /**\n * Then update the folderId in each record and prepare it to be stored.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n location: {\n ...record.data.location,\n folderId\n }\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n try {\n await entityBatch.execute();\n this.dataLoaders.clearAll({\n tenant: initialModel.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not move all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_ERROR\",\n {\n error: ex,\n id\n }\n );\n }\n\n const esEntityReader = this.esEntity.createEntityReader();\n\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n try {\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n put: await Promise.all(\n esItems.map(async item => {\n return {\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n location: {\n ...item.data?.location,\n folderId\n }\n })\n };\n })\n )\n });\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not move entry DynamoDB Elasticsearch records.\",\n ex.code || \"MOVE_ES_ENTRY_ERROR\",\n {\n error: ex,\n partitionKey\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveEntry = MoveEntryStorageOperation.createImplementation({\n implementation: DdbEsMoveEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CompressionHandler\n ]\n});\n"],"names":["DdbEsMoveEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","compressionHandler","initialModel","id","folderId","model","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveEntry","MoveEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CompressionHandler"],"mappings":";;;;;;;;AAYA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAgD,CAC1D;aALUJ,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,QAAQC,YAAsB,EAAEC,EAAU,EAAEC,QAAgB,EAAE;QAChE,MAAMC,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACH;QAEjD,MAAMI,eAAeC,mBAAmB;YACpCJ;YACA,QAAQE,MAAM,MAAM;QACxB;QAIA,MAA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MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAACA,OAAO,IAAI;YAC9D;QACJ,GAAE,EAER,MAAM,CAAC,CAACO,OAAiD,CAAC,CAACA;QAE7D,IAAIF,AAAmB,MAAnBA,QAAQ,MAAM,EACd;QAGJ,IAAI;YACA,MAAMG,2BAA2B,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;gBAC9D,KAAK,MAAMF,QAAQ,GAAG,CAClBD,QAAQ,GAAG,CAAC,OAAME,OACP;wBACH,GAAGA,IAAI;wBACP,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;4BACzC,GAAGA,KAAK,IAAI;4BACZ,UAAU;gCACN,GAAGA,KAAK,IAAI,EAAE,QAAQ;gCACtBpB;4BACJ;wBACJ;oBACJ;YAGZ;YACA,MAAMqB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wDACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPZ;YACJ;QAER;IACJ;AACJ;AAEO,MAAMoB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsMoveToBin.js","sources":["../../../src/operations/entry/DdbEsMoveToBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryStorageOperationsMoveToBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveToBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.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 {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\nimport {\n isDeletedEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsMoveToBinImpl implements MoveToBinStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsMoveToBinParams\n ): Promise<void> {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n\n /**\n * Let's pick the `deleted` meta fields from the entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);\n\n /**\n * Then update all the records with data received.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n ...updatedEntryMetaFields,\n wbyDeleted: storageEntry.wbyDeleted,\n location: storageEntry.location,\n binOriginalFolderId: storageEntry.binOriginalFolderId\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n\n /**\n * We write the records back to the primary DynamoDB table.\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could mark as deleted all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n /**\n * We need to get the published and latest records from Elasticsearch.\n */\n const esEntityReader = this.esEntity.createEntityReader();\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n for (const item of esItems) {\n elasticsearchEntityBatch.put({\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n ...updatedEntryMetaFields,\n wbyDeleted: entry.wbyDeleted,\n location: entry.location,\n binOriginalFolderId: entry.binOriginalFolderId\n })\n });\n }\n\n /**\n * We write the records back to the primary DynamoDB Elasticsearch table.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not mark as deleted entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveToBin = MoveToBinStorageOperation.createImplementation({\n implementation: DdbEsMoveToBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsMoveToBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","updatedEntryMetaFields","pickEntryMetaFields","isDeletedEntryMetaField","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveToBin","MoveToBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AAyBA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BACzC,GAAGA,KAAK,IAAI;gBACZ,GAAGb,sBAAsB;gBACzB,YAAYV,MAAM,UAAU;gBAC5B,UAAUA,MAAM,QAAQ;gBACxB,qBAAqBA,MAAM,mBAAmB;YAClD;QACJ;QAMJ,IAAI;YACA,MAAMwB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IACN,8EACJA,GAAG,IAAI,IAAI,2BACX;gBACI,OAAOA;gBACPjB;gBACAC;YACJ;QAER;IACJ;AACJ;AAEO,MAAMwB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsMoveToBin.js","sources":["../../../src/operations/entry/DdbEsMoveToBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryStorageOperationsMoveToBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { MoveToBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/MoveToBinStorageOperation.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 {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport { createLatestSortKey, createPartitionKey, createPublishedSortKey } from \"./keys.js\";\nimport {\n isDeletedEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\nimport type { IEntityQueryAllParams } from \"@webiny/db-dynamodb\";\n\nclass DdbEsMoveToBinImpl implements MoveToBinStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsMoveToBinParams\n ): Promise<void> {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n /**\n * First we need to fetch all the records in the regular DynamoDB table.\n */\n const queryAllParams: IEntityQueryAllParams = {\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n\n const latestSortKey = createLatestSortKey();\n const publishedSortKey = createPublishedSortKey();\n const records = await this.entity.queryAll(queryAllParams);\n\n /**\n * Let's pick the `deleted` meta fields from the entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);\n\n /**\n * Then update all the records with data received.\n */\n let latestRecord: CmsEntry | undefined = undefined;\n let publishedRecord: CmsEntry | undefined = undefined;\n\n const entityBatch = this.entity.createEntityWriter();\n\n for (const record of records) {\n entityBatch.put({\n ...record,\n data: {\n ...record.data,\n ...updatedEntryMetaFields,\n wbyDeleted: storageEntry.wbyDeleted,\n location: storageEntry.location,\n binOriginalFolderId: storageEntry.binOriginalFolderId\n }\n });\n\n /**\n * We need to get the published and latest records, so we can update the Elasticsearch.\n */\n if (record.SK === publishedSortKey) {\n publishedRecord = record.data;\n } else if (record.SK === latestSortKey) {\n latestRecord = record.data;\n }\n }\n\n /**\n * We write the records back to the primary DynamoDB table.\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could mark as deleted all entry records from in the DynamoDB table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n /**\n * We need to get the published and latest records from Elasticsearch.\n */\n const esEntityReader = this.esEntity.createEntityReader();\n if (publishedRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: publishedSortKey\n });\n }\n if (latestRecord) {\n esEntityReader.get({\n PK: partitionKey,\n SK: latestSortKey\n });\n }\n if (esEntityReader.total === 0) {\n return;\n }\n\n const esRecords = await esEntityReader.execute();\n\n const esItems = (\n await Promise.all(\n esRecords.map(async record => {\n if (!record) {\n return null;\n }\n return {\n ...record,\n data: await this.compressionHandler.decompress(record.data)\n };\n })\n )\n ).filter((item): item is IElasticsearchEntityAttributes => !!item);\n\n if (esItems.length === 0) {\n return;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n for (const item of esItems) {\n elasticsearchEntityBatch.put({\n ...item,\n data: await this.compressionHandler.compress({\n ...item.data,\n ...updatedEntryMetaFields,\n wbyDeleted: entry.wbyDeleted,\n location: entry.location,\n binOriginalFolderId: entry.binOriginalFolderId\n })\n });\n }\n\n /**\n * We write the records back to the primary DynamoDB Elasticsearch table.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not mark as deleted entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"MOVE_ENTRY_TO_BIN_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n }\n}\n\nexport const DdbEsMoveToBin = MoveToBinStorageOperation.createImplementation({\n implementation: DdbEsMoveToBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsMoveToBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","updatedEntryMetaFields","pickEntryMetaFields","isDeletedEntryMetaField","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsMoveToBin","MoveToBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,eAA6D,CACvE;aAPUN,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,YAAsB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gBACPjB;gBACAC;YACJ;QAER;IACJ;AACJ;AAEO,MAAMwB,iBAAiBC,0BAA0B,oBAAoB,CAAC;IACzE,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
@@ -4,7 +4,7 @@ import { CmsDdbEsEntryEntity } from "../../abstractions/CmsDdbEsEntryEntity.js";
4
4
  import { CmsDdbEsEntriesEsEntity } from "../../abstractions/CmsDdbEsEntriesEsEntity.js";
5
5
  import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
6
6
  import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
7
- import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
7
+ import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
8
8
  import { CompressionHandler } from "@webiny/utils/exports/api.js";
9
9
  declare class DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Interface {
10
10
  private entity;
@@ -13,8 +13,9 @@ declare class DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Inte
13
13
  private storageModelProvider;
14
14
  private fieldIndexRegistry;
15
15
  private compressionHandler;
16
+ private indexProvider;
16
17
  private valuesModifiers;
17
- constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, compressionHandler: CompressionHandler.Interface, valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]);
18
+ constructor(entity: CmsDdbEsEntryEntity.Interface, esEntity: CmsDdbEsEntriesEsEntity.Interface, dataLoaders: CmsDdbEsDataLoaders.Interface, storageModelProvider: CmsStorageModelProvider.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, compressionHandler: CompressionHandler.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface, valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]);
18
19
  execute<T extends CmsEntryValues = CmsEntryValues>(initialModel: CmsModel, params: CmsEntryStorageOperationsPublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
19
20
  }
20
21
  export declare const DdbEsPublishEntry: typeof DdbEsPublishEntryImpl & {
@@ -5,20 +5,21 @@ import { CmsDdbEsEntryEntity } from "../../abstractions/CmsDdbEsEntryEntity.js";
5
5
  import { CmsDdbEsEntriesEsEntity } from "../../abstractions/CmsDdbEsEntriesEsEntity.js";
6
6
  import { CmsDdbEsDataLoaders } from "../../abstractions/CmsDdbEsDataLoaders.js";
7
7
  import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
8
- import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
8
+ import { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchValuesModifier, CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
9
9
  import { CompressionHandler } from "@webiny/utils/exports/api.js";
10
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
10
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
11
11
  import { createTransformer } from "./transformations/index.js";
12
12
  import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys } from "./keys.js";
13
13
  import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
14
14
  class DdbEsPublishEntryImpl {
15
- constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, valuesModifiers){
15
+ constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers){
16
16
  this.entity = entity;
17
17
  this.esEntity = esEntity;
18
18
  this.dataLoaders = dataLoaders;
19
19
  this.storageModelProvider = storageModelProvider;
20
20
  this.fieldIndexRegistry = fieldIndexRegistry;
21
21
  this.compressionHandler = compressionHandler;
22
+ this.indexProvider = indexProvider;
22
23
  this.valuesModifiers = valuesModifiers;
23
24
  }
24
25
  async execute(initialModel, params) {
@@ -77,7 +78,8 @@ class DdbEsPublishEntryImpl {
77
78
  ]
78
79
  });
79
80
  const elasticsearchEntityWriter = this.esEntity.createEntityWriter();
80
- const { index: esIndex } = configurations.es({
81
+ const configurations = createConfigurations(this.indexProvider);
82
+ const { index: esIndex } = await configurations.es({
81
83
  model
82
84
  });
83
85
  const publishedRevisionId = publishedStorageEntry?.id;
@@ -215,6 +217,7 @@ const DdbEsPublishEntry = PublishEntryStorageOperation.createImplementation({
215
217
  CmsStorageModelProvider,
216
218
  CmsEntryOpenSearchFieldIndexRegistry,
217
219
  CompressionHandler,
220
+ CmsModelOpenSearchIndexProvider,
218
221
  [
219
222
  CmsEntryOpenSearchValuesModifier,
220
223
  {
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsPublishEntry.js","sources":["../../../src/operations/entry/DdbEsPublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsPublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { CONTENT_ENTRY_STATUS } from \"@webiny/api-headless-cms/types/index.js\";\nimport { PublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.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 {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { configurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch\";\n\nclass DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsPublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n let latestEsEntry: IElasticsearchEntityAttributes | null = null;\n try {\n latestEsEntry = await this.esEntity.getClean(latestKeys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not read Elasticsearch latest data.\",\n ex.code || \"PUBLISH_LATEST_READ\",\n {\n error: ex,\n latestKeys: latestKeys,\n publishedKeys: publishedKeys\n }\n );\n }\n\n if (!latestEsEntry) {\n throw new WebinyError(\n `Could not publish entry. Could not load latest (\"L\") record (ES table).`,\n \"PUBLISH_ERROR\",\n { entry }\n );\n }\n\n /**\n * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n if (!latestStorageEntry) {\n throw new WebinyError(\n `Could not publish entry. Could not load latest (\"L\") record.`,\n \"PUBLISH_ERROR\",\n { entry }\n );\n }\n\n /**\n * We need currently published entry to check if need to remove it.\n */\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n // 1. Update REV# and P records with new data.\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: storageEntry\n },\n {\n ...publishedKeys,\n data: storageEntry\n }\n ]\n });\n\n const elasticsearchEntityWriter = this.esEntity.createEntityWriter();\n\n const { index: esIndex } = configurations.es({\n model\n });\n\n // 2. When it comes to the latest record, we need to perform a couple of different\n // updates, based on whether the entry being published is the latest revision or not.\n const publishedRevisionId = publishedStorageEntry?.id;\n const publishingLatestRevision = latestStorageEntry?.id === entry.id;\n\n if (publishingLatestRevision) {\n // 2.1 If we're publishing the latest revision, we first need to update the L record.\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n // 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.\n // Note that we need to take re-publishing into account (same published revision being\n // published again), in which case the below code does not apply. This is because the\n // required updates were already applied above.\n if (publishedStorageEntry) {\n const isRepublishing = publishedStorageEntry.id === entry.id;\n if (!isRepublishing) {\n /**\n * Update currently published entry (unpublish it)\n */\n const publishedStorageEntryKeys =\n createEntryRevisionKeys(publishedStorageEntry);\n entityBatch.put({\n ...publishedStorageEntryKeys,\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n }\n } else {\n // 2.3 If the published revision is not the latest one, the situation is a bit\n // more complex. We first need to update the L and REV# records with the new\n // values of *only entry-level* meta fields.\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n // 2.4 Update L record. Apart from updating the entry-level meta fields, we also need\n // to change the status from \"published\" to \"unpublished\" (if the status is set to \"published\").\n let latestRevisionStatus = latestStorageEntry.status;\n if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {\n latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;\n }\n\n const latestStorageEntryFields = {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields,\n status: latestRevisionStatus\n };\n\n const latestStorageEntryLatestKeys = createEntryLatestKeys(latestStorageEntry);\n entityBatch.put({\n ...latestStorageEntryLatestKeys,\n data: latestStorageEntryFields\n });\n\n // 2.5 Update REV# record.\n const latestStorageEntryRevisionKeys = createEntryRevisionKeys(latestStorageEntry);\n entityBatch.put({\n ...latestStorageEntryRevisionKeys,\n data: latestStorageEntryFields\n });\n\n // 2.6 Additionally, if we have a previously published entry, we need to mark it as unpublished.\n // Note that we need to take re-publishing into account (same published revision being\n // published again), in which case the below code does not apply. This is because the\n // required updates were already applied above.\n if (publishedStorageEntry) {\n const isRepublishing = publishedStorageEntry.id === entry.id;\n const publishedRevisionDifferentFromLatest =\n publishedRevisionId !== latestStorageEntry.id;\n\n if (!isRepublishing && publishedRevisionDifferentFromLatest) {\n const publishedStorageEntryRevisionKeys =\n createEntryRevisionKeys(publishedStorageEntry);\n entityBatch.put({\n ...publishedStorageEntryRevisionKeys,\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n }\n }\n\n // 3. Update records in ES -> DDB table.\n\n /**\n * Update the published revision entry in ES.\n */\n const esPublishedData = await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityWriter.put({\n ...publishedKeys,\n index: esIndex,\n data: esPublishedData\n });\n\n /**\n * Need to decompress the data from Elasticsearch DynamoDB table.\n *\n * No need to transform it for the storage because it was fetched\n * directly from the Elasticsearch table, where it sits transformed.\n */\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n if (publishingLatestRevision) {\n const updatedMetaFields = pickEntryMetaFields(entry);\n\n const latestTransformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n transformedToIndex: {\n ...latestEsEntryDataDecompressed,\n status: CONTENT_ENTRY_STATUS.PUBLISHED,\n locked: true,\n ...updatedMetaFields\n },\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const esEntryLatestKeys = createEntryLatestKeys(latestEsEntryDataDecompressed);\n elasticsearchEntityWriter.put({\n index: esIndex,\n data: await latestTransformer.getElasticsearchLatestEntryData(),\n ...esEntryLatestKeys\n });\n } else {\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n /**\n * Update the Elasticsearch table to propagate changes to the Elasticsearch.\n */\n const latestEsEntry = await this.esEntity.getClean(latestKeys);\n\n if (latestEsEntry) {\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n let latestRevisionStatus = latestEsEntryDataDecompressed.status;\n if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {\n latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;\n }\n\n const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields,\n status: latestRevisionStatus\n });\n\n elasticsearchEntityWriter.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n\n /**\n * Finally, execute regular table batch.\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not store publish entry records in DynamoDB table.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n /**\n * And Elasticsearch table batch.\n */\n try {\n await elasticsearchEntityWriter.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not store publish entry records in DynamoDB Elasticsearch table.\",\n ex.code || \"PUBLISH_ES_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsPublishEntry = PublishEntryStorageOperation.createImplementation({\n implementation: DdbEsPublishEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsPublishEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestEsEntry","ex","WebinyError","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityWriter","esIndex","configurations","publishedRevisionId","publishingLatestRevision","isRepublishing","publishedStorageEntryKeys","CONTENT_ENTRY_STATUS","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","latestRevisionStatus","latestStorageEntryFields","latestStorageEntryLatestKeys","latestStorageEntryRevisionKeys","publishedRevisionDifferentFromLatest","publishedStorageEntryRevisionKeys","esPublishedData","latestEsEntryDataDecompressed","updatedMetaFields","latestTransformer","esEntryLatestKeys","updatedLatestEntry","DdbEsPublishEntry","PublishEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;;AA+BA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,eAA6D,CACvE;aAPUN,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAiD,EACnD;QACE,MAAM,EAAE,OAAOC,YAAY,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACnE,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,cAAcC,kBAAkB;YAClC,iBAAiB,IAAI,CAAC,eAAe;YACrCF;YACA,OAAOF;YACP,cAAcC;YACd,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAM,EAAEI,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAkB;QAE9D,MAAMI,eAAeC,wBAAwBH;QAC7C,MAAMI,aAAaC,sBAAsBL;QACzC,MAAMM,gBAAgBC,yBAAyBP;QAE/C,IAAIQ,gBAAuD;QAC3D,IAAI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ACA,MAAME,0BAA0B,OAAO;QAC3C,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IACN,0EACJA,GAAG,IAAI,IAAI,oBACX;gBACI,OAAOA;gBACPT;gBACAW;gBACAC;YACJ;QAER;QACA,OAAOhB;IACX;AACJ;AAEO,MAAMyC,oBAAoBC,6BAA6B,oBAAoB,CAAC;IAC/E,gBAAgBrD;IAChB,cAAc;QACVsD;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsPublishEntry.js","sources":["../../../src/operations/entry/DdbEsPublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsPublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { CONTENT_ENTRY_STATUS } from \"@webiny/api-headless-cms/types/index.js\";\nimport { PublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/PublishEntryStorageOperation.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 {\n CmsEntryOpenSearchFieldIndexRegistry,\n CmsEntryOpenSearchValuesModifier,\n CmsModelOpenSearchIndexProvider\n} from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\nimport { CompressionHandler } from \"@webiny/utils/exports/api.js\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { createTransformer } from \"./transformations/index.js\";\nimport {\n createEntryLatestKeys,\n createEntryPublishedKeys,\n createEntryRevisionKeys\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\nimport type { IOpenSearchEntityAttributes as IElasticsearchEntityAttributes } from \"@webiny/api-opensearch-aws\";\n\nclass DdbEsPublishEntryImpl implements PublishEntryStorageOperation.Interface {\n constructor(\n private entity: CmsDdbEsEntryEntity.Interface,\n private esEntity: CmsDdbEsEntriesEsEntity.Interface,\n private dataLoaders: CmsDdbEsDataLoaders.Interface,\n private storageModelProvider: CmsStorageModelProvider.Interface,\n private fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private compressionHandler: CompressionHandler.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface,\n private valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[]\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n initialModel: CmsModel,\n params: CmsEntryStorageOperationsPublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel(initialModel);\n\n const transformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n entry: initialEntry,\n storageEntry: initialStorageEntry,\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const { entry, storageEntry } = transformer.transformEntryKeys();\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n let latestEsEntry: IElasticsearchEntityAttributes | null = null;\n try {\n latestEsEntry = await this.esEntity.getClean(latestKeys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not read Elasticsearch latest data.\",\n ex.code || \"PUBLISH_LATEST_READ\",\n {\n error: ex,\n latestKeys: latestKeys,\n publishedKeys: publishedKeys\n }\n );\n }\n\n if (!latestEsEntry) {\n throw new WebinyError(\n `Could not publish entry. Could not load latest (\"L\") record (ES table).`,\n \"PUBLISH_ERROR\",\n { entry }\n );\n }\n\n /**\n * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n if (!latestStorageEntry) {\n throw new WebinyError(\n `Could not publish entry. Could not load latest (\"L\") record.`,\n \"PUBLISH_ERROR\",\n { entry }\n );\n }\n\n /**\n * We need currently published entry to check if need to remove it.\n */\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n // 1. Update REV# and P records with new data.\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: storageEntry\n },\n {\n ...publishedKeys,\n data: storageEntry\n }\n ]\n });\n\n const elasticsearchEntityWriter = this.esEntity.createEntityWriter();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n // 2. When it comes to the latest record, we need to perform a couple of different\n // updates, based on whether the entry being published is the latest revision or not.\n const publishedRevisionId = publishedStorageEntry?.id;\n const publishingLatestRevision = latestStorageEntry?.id === entry.id;\n\n if (publishingLatestRevision) {\n // 2.1 If we're publishing the latest revision, we first need to update the L record.\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n // 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.\n // Note that we need to take re-publishing into account (same published revision being\n // published again), in which case the below code does not apply. This is because the\n // required updates were already applied above.\n if (publishedStorageEntry) {\n const isRepublishing = publishedStorageEntry.id === entry.id;\n if (!isRepublishing) {\n /**\n * Update currently published entry (unpublish it)\n */\n const publishedStorageEntryKeys =\n createEntryRevisionKeys(publishedStorageEntry);\n entityBatch.put({\n ...publishedStorageEntryKeys,\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n }\n } else {\n // 2.3 If the published revision is not the latest one, the situation is a bit\n // more complex. We first need to update the L and REV# records with the new\n // values of *only entry-level* meta fields.\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n // 2.4 Update L record. Apart from updating the entry-level meta fields, we also need\n // to change the status from \"published\" to \"unpublished\" (if the status is set to \"published\").\n let latestRevisionStatus = latestStorageEntry.status;\n if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {\n latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;\n }\n\n const latestStorageEntryFields = {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields,\n status: latestRevisionStatus\n };\n\n const latestStorageEntryLatestKeys = createEntryLatestKeys(latestStorageEntry);\n entityBatch.put({\n ...latestStorageEntryLatestKeys,\n data: latestStorageEntryFields\n });\n\n // 2.5 Update REV# record.\n const latestStorageEntryRevisionKeys = createEntryRevisionKeys(latestStorageEntry);\n entityBatch.put({\n ...latestStorageEntryRevisionKeys,\n data: latestStorageEntryFields\n });\n\n // 2.6 Additionally, if we have a previously published entry, we need to mark it as unpublished.\n // Note that we need to take re-publishing into account (same published revision being\n // published again), in which case the below code does not apply. This is because the\n // required updates were already applied above.\n if (publishedStorageEntry) {\n const isRepublishing = publishedStorageEntry.id === entry.id;\n const publishedRevisionDifferentFromLatest =\n publishedRevisionId !== latestStorageEntry.id;\n\n if (!isRepublishing && publishedRevisionDifferentFromLatest) {\n const publishedStorageEntryRevisionKeys =\n createEntryRevisionKeys(publishedStorageEntry);\n entityBatch.put({\n ...publishedStorageEntryRevisionKeys,\n data: {\n ...publishedStorageEntry,\n status: CONTENT_ENTRY_STATUS.UNPUBLISHED\n }\n });\n }\n }\n }\n\n // 3. Update records in ES -> DDB table.\n\n /**\n * Update the published revision entry in ES.\n */\n const esPublishedData = await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityWriter.put({\n ...publishedKeys,\n index: esIndex,\n data: esPublishedData\n });\n\n /**\n * Need to decompress the data from Elasticsearch DynamoDB table.\n *\n * No need to transform it for the storage because it was fetched\n * directly from the Elasticsearch table, where it sits transformed.\n */\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n if (publishingLatestRevision) {\n const updatedMetaFields = pickEntryMetaFields(entry);\n\n const latestTransformer = createTransformer({\n valuesModifiers: this.valuesModifiers,\n model,\n transformedToIndex: {\n ...latestEsEntryDataDecompressed,\n status: CONTENT_ENTRY_STATUS.PUBLISHED,\n locked: true,\n ...updatedMetaFields\n },\n fieldIndexRegistry: this.fieldIndexRegistry,\n compressionHandler: this.compressionHandler\n });\n\n const esEntryLatestKeys = createEntryLatestKeys(latestEsEntryDataDecompressed);\n elasticsearchEntityWriter.put({\n index: esIndex,\n data: await latestTransformer.getElasticsearchLatestEntryData(),\n ...esEntryLatestKeys\n });\n } else {\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n /**\n * Update the Elasticsearch table to propagate changes to the Elasticsearch.\n */\n const latestEsEntry = await this.esEntity.getClean(latestKeys);\n\n if (latestEsEntry) {\n const latestEsEntryDataDecompressed = (await this.compressionHandler.decompress(\n latestEsEntry.data\n )) as CmsIndexEntry;\n\n let latestRevisionStatus = latestEsEntryDataDecompressed.status;\n if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {\n latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;\n }\n\n const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields,\n status: latestRevisionStatus\n });\n\n elasticsearchEntityWriter.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n\n /**\n * Finally, execute regular table batch.\n */\n try {\n await entityBatch.execute();\n\n this.dataLoaders.clearAll({\n tenant: entry.tenant\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not store publish entry records in DynamoDB table.\",\n ex.code || \"PUBLISH_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n /**\n * And Elasticsearch table batch.\n */\n try {\n await elasticsearchEntityWriter.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not store publish entry records in DynamoDB Elasticsearch table.\",\n ex.code || \"PUBLISH_ES_ERROR\",\n {\n error: ex,\n entry,\n latestStorageEntry,\n publishedStorageEntry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsPublishEntry = PublishEntryStorageOperation.createImplementation({\n implementation: DdbEsPublishEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsPublishEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestEsEntry","ex","WebinyError","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityWriter","configurations","createConfigurations","esIndex","publishedRevisionId","publishingLatestRevision","isRepublishing","publishedStorageEntryKeys","CONTENT_ENTRY_STATUS","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","latestRevisionStatus","latestStorageEntryFields","latestStorageEntryLatestKeys","latestStorageEntryRevisionKeys","publishedRevisionDifferentFromLatest","publishedStorageEntryRevisionKeys","esPublishedData","latestEsEntryDataDecompressed","updatedMetaFields","latestTransformer","esEntryLatestKeys","updatedLatestEntry","DdbEsPublishEntry","PublishEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;;AAgCA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,aAAwD,EACxDC,eAA6D,CACvE;aARUP,MAAM,GAANA;aACAC,QAAQ,GAARA;aACAC,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,kBAAkB,GAAlBA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,YAAsB,EACtBC,MAAiD,EACnD;QACE,MAAM,EAAE,OAAOC,YAAY,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACnE,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAACJ;QAEjD,MAAMK,cAAcC,kBAAkB;YAClC,iBAAiB,IAAI,CAAC,eAAe;YACrCF;YACA,OAAOF;YACP,cAAcC;YACd,oBAAoB,IAAI,CAAC,kBAAkB;YAC3C,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAM,EAAEI,KAAK,EAAEC,YAAY,EAAE,GAAGH,YAAY,kBAAkB;QAE9D,MAAMI,eAAeC,wBAAwBH;QAC7C,MAAMI,aAAaC,sBAAsBL;QACzC,MAAMM,gBAAgBC,yBAAyBP;QAE/C,IAAIQ,gBAAuD;QAC3D,IAAI;YACAA,gBAAgB,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAACJ;QACjD,EAAE,OAAOK,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,6CACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACP,YAAYL;gBACZ,eAAeE;YACnB;QAER;QAEA,IAAI,CAACE,eACD,MAAM,IA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