@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
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsRestoreFromBin.js","sources":["../../../src/operations/entry/DdbEsRestoreFromBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsRestoreFromBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { RestoreFromBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.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 isRestoredEntryMetaField,\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 DdbEsRestoreFromBinImpl implements RestoreFromBinStorageOperation.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: CmsEntryStorageOperationsRestoreFromBinParams<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 /**\n * Let's pick the `restored` meta fields from the storage entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isRestoredEntryMetaField);\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 * 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 not restore all entry records from in the DynamoDB table.\",\n ex.code || \"RESTORE_ENTRY_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\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 initialStorageEntry;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\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 || \"Could not restore entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"RESTORE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({\n implementation: DdbEsRestoreFromBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsRestoreFromBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","updatedEntryMetaFields","pickEntryMetaFields","isRestoredEntryMetaField","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsRestoreFromBin","RestoreFromBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AA0BA,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,MAAwD,EAC1D;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;QAK9D,MAAMI,yBAAyBC,oBAAoBH,OAAOI;QAE1D,MAAMC,eAAeC,mBAAmB;YACpC,IAAIN,MAAM,EAAE;YACZ,QAAQH,MAAM,MAAM;QACxB;QAKA,MAAMU,iBAAwC;YAC1CF;YACA,SAAS;gBACL,KAAK;YACT;QACJ;QAEA,MAAMG,gBAAgBC;QACtB,MAAMC,mBAAmBC;QACzB,MAAMC,UAAU,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAACL;QAK3C,IAAIM;QACJ,IAAIC;QAEJ,MAAMC,cAAc,IAAI,CAAC,MAAM,CAAC,kBAAkB;Q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AK,MAAMD,QAAQF,QACfG,yBAAyB,GAAG,CAAC;YACzB,GAAGD,IAAI;YACP,MAAM,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;gBACzC,GAAGA,KAAK,IAAI;gBACZ,GAAGrB,sBAAsB;gBACzB,YAAYF,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,IAAI,sEACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPjB;gBACAC;YACJ;QAER;QAEA,OAAOL;IACX;AACJ;AAEO,MAAM6B,sBAAsBC,+BAA+B,oBAAoB,CAAC;IACnF,gBAAgBzC;IAChB,cAAc;QACV0C;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsRestoreFromBin.js","sources":["../../../src/operations/entry/DdbEsRestoreFromBin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsRestoreFromBinParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { RestoreFromBinStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/RestoreFromBinStorageOperation.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 isRestoredEntryMetaField,\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 DdbEsRestoreFromBinImpl implements RestoreFromBinStorageOperation.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: CmsEntryStorageOperationsRestoreFromBinParams<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 /**\n * Let's pick the `restored` meta fields from the storage entry.\n */\n const updatedEntryMetaFields = pickEntryMetaFields(entry, isRestoredEntryMetaField);\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 * 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 not restore all entry records from in the DynamoDB table.\",\n ex.code || \"RESTORE_ENTRY_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\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 initialStorageEntry;\n }\n\n /**\n * We update all ES records with data received.\n */\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\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 || \"Could not restore entry records from DynamoDB Elasticsearch table.\",\n ex.code || \"RESTORE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsRestoreFromBin = RestoreFromBinStorageOperation.createImplementation({\n implementation: DdbEsRestoreFromBinImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsRestoreFromBinImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","updatedEntryMetaFields","pickEntryMetaFields","isRestoredEntryMetaField","partitionKey","createPartitionKey","queryAllParams","latestSortKey","createLatestSortKey","publishedSortKey","createPublishedSortKey","records","latestRecord","publishedRecord","entityBatch","record","ex","WebinyError","esEntityReader","esRecords","esItems","Promise","item","elasticsearchEntityBatch","DdbEsRestoreFromBin","RestoreFromBinStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AA0BA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,eAA6D,CACv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AAMwB,yBAAyB,OAAO;QAC1C,EAAE,OAAOP,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,sEACdA,GAAG,IAAI,IAAI,uBACX;gBACI,OAAOA;gBACPjB;gBACAC;YACJ;QAER;QAEA,OAAOL;IACX;AACJ;AAEO,MAAM6B,sBAAsBC,+BAA+B,oBAAoB,CAAC;IACnF,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 DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.Interface {
10
10
  private entity;
@@ -13,8 +13,9 @@ declare class DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.
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: CmsEntryStorageOperationsUnpublishParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
19
20
  }
20
21
  export declare const DdbEsUnpublishEntry: typeof DdbEsUnpublishEntryImpl & {
@@ -4,19 +4,20 @@ 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
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
9
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
10
10
  import { createTransformer } from "./transformations/index.js";
11
11
  import { createEntryLatestKeys, createEntryRevisionKeys, createPartitionKey, createPublishedSortKey } from "./keys.js";
12
12
  class DdbEsUnpublishEntryImpl {
13
- constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, valuesModifiers){
13
+ constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers){
14
14
  this.entity = entity;
15
15
  this.esEntity = esEntity;
16
16
  this.dataLoaders = dataLoaders;
17
17
  this.storageModelProvider = storageModelProvider;
18
18
  this.fieldIndexRegistry = fieldIndexRegistry;
19
19
  this.compressionHandler = compressionHandler;
20
+ this.indexProvider = indexProvider;
20
21
  this.valuesModifiers = valuesModifiers;
21
22
  }
22
23
  async execute(initialModel, params) {
@@ -65,7 +66,8 @@ class DdbEsUnpublishEntryImpl {
65
66
  ]
66
67
  });
67
68
  if (latestStorageEntry?.id === entry.id) {
68
- const { index } = configurations.es({
69
+ const configurations = createConfigurations(this.indexProvider);
70
+ const { index } = await configurations.es({
69
71
  model
70
72
  });
71
73
  const entryLatestKeys = createEntryLatestKeys(storageEntry);
@@ -111,6 +113,7 @@ const DdbEsUnpublishEntry = UnpublishEntryStorageOperation.createImplementation(
111
113
  CmsStorageModelProvider,
112
114
  CmsEntryOpenSearchFieldIndexRegistry,
113
115
  CompressionHandler,
116
+ CmsModelOpenSearchIndexProvider,
114
117
  [
115
118
  CmsEntryOpenSearchValuesModifier,
116
119
  {
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsUnpublishEntry.js","sources":["../../../src/operations/entry/DdbEsUnpublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUnpublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UnpublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.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 createEntryRevisionKeys,\n createPartitionKey,\n createPublishedSortKey\n} from \"./keys.js\";\n\nclass DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.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: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel<T>(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 const { entry, storageEntry } = await transformer.transformEntryKeys();\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n const entryRevisionKeys = createEntryRevisionKeys(entry);\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...entryRevisionKeys,\n data: storageEntry\n }\n ],\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n /**\n * If we are unpublishing the latest revision, let's also update the latest revision entry's status in both DynamoDB tables.\n */\n if (latestStorageEntry?.id === entry.id) {\n const { index } = configurations.es({\n model\n });\n\n const entryLatestKeys = createEntryLatestKeys(storageEntry);\n entityBatch.put({\n ...entryLatestKeys,\n data: storageEntry\n });\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n index,\n data: esLatestData,\n ...entryLatestKeys\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 unpublished entry records in DynamoDB table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n /**\n * And Elasticsearch table batch.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not store unpublished entry records in DynamoDB Elasticsearch table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({\n implementation: DdbEsUnpublishEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsUnpublishEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","latestStorageEntry","partitionKey","createPartitionKey","entryRevisionKeys","createEntryRevisionKeys","entityBatch","createPublishedSortKey","elasticsearchEntityBatch","index","configurations","entryLatestKeys","createEntryLatestKeys","esLatestData","ex","WebinyError","DdbEsUnpublishEntry","UnpublishEntryStorageOperation","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,EACtBC,MAAmD,EACrD;QACE,MAAM,EAAE,OAAOC,YAAY,EAAE,cAAcC,mBAAmB,EAAE,GAAGF;QACnE,MAAMG,QAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAIJ;QAEpD,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;QACA,MAAM,EAAEI,KAAK,EAAEC,YAAY,EAAE,GAAG,MAAMH,YAAY,kBAAkB;QAKpE,MAAM,CAACI,mBAAmB,GAAG,MAAM,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BACX;gBACIf;gBACAC;YACJ;QAER;QACA,OAAOL;IACX;AACJ;AAEO,MAAMqB,sBAAsBC,+BAA+B,oBAAoB,CAAC;IACnF,gBAAgBjC;IAChB,cAAc;QACVkC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
1
+ {"version":3,"file":"operations/entry/DdbEsUnpublishEntry.js","sources":["../../../src/operations/entry/DdbEsUnpublishEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUnpublishParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UnpublishEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UnpublishEntryStorageOperation.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 createEntryRevisionKeys,\n createPartitionKey,\n createPublishedSortKey\n} from \"./keys.js\";\n\nclass DdbEsUnpublishEntryImpl implements UnpublishEntryStorageOperation.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: CmsEntryStorageOperationsUnpublishParams<T>\n ) {\n const { entry: initialEntry, storageEntry: initialStorageEntry } = params;\n const model = this.storageModelProvider.getModel<T>(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 const { entry, storageEntry } = await transformer.transformEntryKeys();\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const partitionKey = createPartitionKey({\n id: entry.id,\n tenant: model.tenant\n });\n\n const entryRevisionKeys = createEntryRevisionKeys(entry);\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...entryRevisionKeys,\n data: storageEntry\n }\n ],\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter({\n delete: [\n {\n PK: partitionKey,\n SK: createPublishedSortKey()\n }\n ]\n });\n\n /**\n * If we are unpublishing the latest revision, let's also update the latest revision entry's status in both DynamoDB tables.\n */\n if (latestStorageEntry?.id === entry.id) {\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({\n model\n });\n\n const entryLatestKeys = createEntryLatestKeys(storageEntry);\n entityBatch.put({\n ...entryLatestKeys,\n data: storageEntry\n });\n\n const esLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n index,\n data: esLatestData,\n ...entryLatestKeys\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 unpublished entry records in DynamoDB table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n /**\n * And Elasticsearch table batch.\n */\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not store unpublished entry records in DynamoDB Elasticsearch table.\",\n ex.code || \"UNPUBLISH_ERROR\",\n {\n entry,\n storageEntry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUnpublishEntry = UnpublishEntryStorageOperation.createImplementation({\n implementation: DdbEsUnpublishEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsUnpublishEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","latestStorageEntry","partitionKey","createPartitionKey","entryRevisionKeys","createEntryRevisionKeys","entityBatch","createPublishedSortKey","elasticsearchEntityBatch","configurations","createConfigurations","index","entryLatestKeys","createEntryLatestKeys","esLatestData","ex","WebinyError","DdbEsUnpublishEntry","UnpublishEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;AA0BA,MAAMA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;oBACI,IAAIN;oBACJ,IAAIK;gBACR;aACH;QACL;QAKA,IAAIN,oBAAoB,OAAOF,MAAM,EAAE,EAAE;YACrC,MAAMU,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;YAC9D,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;gBACtCb;YACJ;YAEA,MAAMgB,kBAAkBC,sBAAsBb;YAC9CM,YAAY,GAAG,CAAC;gBACZ,GAAGM,eAAe;gBAClB,MAAMZ;YACV;YAEA,MAAMc,eAAe,MAAMjB,YAAY,+BAA+B;YAEtEW,yBAAyB,GAAG,CAAC;gBACzBG;gBACA,MAAMG;gBACN,GAAGF,eAAe;YACtB;QACJ;QAKA,IAAI;YACA,MAAMN,YAAY,OAAO;YAEzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQP,MAAM,MAAM;YACxB;QACJ,EAAE,OAAOgB,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,gEACdA,GAAG,IAAI,IAAI,mBACX;gBACIhB;gBACAC;YACJ;QAER;QAIA,IAAI;YACA,MAAMQ,yBAAyB,OAAO;QAC1C,EAAE,OAAOO,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IACN,8EACJA,GAAG,IAAI,IAAI,mBACX;gBACIhB;gBACAC;YACJ;QAER;QACA,OAAOL;IACX;AACJ;AAEO,MAAMsB,sBAAsBC,+BAA+B,oBAAoB,CAAC;IACnF,gBAAgBnC;IAChB,cAAc;QACVoC;QACAC;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 DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interface {
10
10
  private entity;
@@ -13,8 +13,9 @@ declare class DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.Interf
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: CmsEntryStorageOperationsUpdateParams<T>): Promise<import("@webiny/api-headless-cms/types/types.js").CmsStorageEntry<T>>;
19
20
  }
20
21
  export declare const DdbEsUpdateEntry: typeof DdbEsUpdateEntryImpl & {
@@ -4,20 +4,21 @@ 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
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
9
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
10
10
  import { createTransformer } from "./transformations/index.js";
11
11
  import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createPartitionKey, createRevisionSortKey } from "./keys.js";
12
12
  import { isEntryLevelEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
13
13
  class DdbEsUpdateEntryImpl {
14
- constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, valuesModifiers){
14
+ constructor(entity, esEntity, dataLoaders, storageModelProvider, fieldIndexRegistry, compressionHandler, indexProvider, valuesModifiers){
15
15
  this.entity = entity;
16
16
  this.esEntity = esEntity;
17
17
  this.dataLoaders = dataLoaders;
18
18
  this.storageModelProvider = storageModelProvider;
19
19
  this.fieldIndexRegistry = fieldIndexRegistry;
20
20
  this.compressionHandler = compressionHandler;
21
+ this.indexProvider = indexProvider;
21
22
  this.valuesModifiers = valuesModifiers;
22
23
  }
23
24
  async execute(initialModel, params) {
@@ -68,7 +69,8 @@ class DdbEsUpdateEntryImpl {
68
69
  }
69
70
  });
70
71
  const elasticsearchEntityBatch = this.esEntity.createEntityWriter();
71
- const { index: esIndex } = configurations.es({
72
+ const configurations = createConfigurations(this.indexProvider);
73
+ const { index: esIndex } = await configurations.es({
72
74
  model
73
75
  });
74
76
  if (latestStorageEntry) {
@@ -159,6 +161,7 @@ const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({
159
161
  CmsStorageModelProvider,
160
162
  CmsEntryOpenSearchFieldIndexRegistry,
161
163
  CompressionHandler,
164
+ CmsModelOpenSearchIndexProvider,
162
165
  [
163
166
  CmsEntryOpenSearchValuesModifier,
164
167
  {
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/DdbEsUpdateEntry.js","sources":["../../../src/operations/entry/DdbEsUpdateEntry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UpdateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.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 createPartitionKey,\n createRevisionSortKey\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IEntryEntityAttributes } from \"~/definitions/types.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\n\nclass DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.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: CmsEntryStorageOperationsUpdateParams<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 isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n const { index: esIndex } = configurations.es({\n model\n });\n\n /**\n * If the latest entry is the one being updated, we need to create a new latest entry records.\n */\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n /**\n * First we update the regular DynamoDB table.\n */\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n /**\n * And then update the Elasticsearch table to propagate changes to the Elasticsearch\n */\n const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: elasticsearchLatestData\n });\n } else {\n /**\n * If not updating latest revision, we still want to update the latest revision's\n * entry-level meta fields to match the current revision's entry-level meta fields.\n */\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n const updatedLatestStorageEntry: IEntryEntityAttributes = {\n ...latestKeys,\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n };\n\n /**\n * First we update the regular DynamoDB table. Two updates are needed:\n * - one for the actual revision record\n * - one for the latest record\n */\n entityBatch.put({\n ...updatedLatestStorageEntry,\n PK: createPartitionKey({\n id: latestStorageEntry.id,\n tenant: model.tenant\n }),\n SK: createRevisionSortKey(latestStorageEntry)\n });\n\n entityBatch.put({\n ...updatedLatestStorageEntry\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 const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields\n });\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n }\n\n if (isPublished && publishedStorageEntry?.id === entry.id) {\n const elasticsearchPublishedData =\n await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: elasticsearchPublishedData\n });\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 update entry DynamoDB records.\",\n ex.code || \"UPDATE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry DynamoDB Elasticsearch records.\",\n ex.code || \"UPDATE_ES_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbEsUpdateEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsUpdateEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","isPublished","locked","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityBatch","esIndex","configurations","updatingLatestRevision","elasticsearchLatestData","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","updatedLatestStorageEntry","createPartitionKey","createRevisionSortKey","latestEsEntry","latestEsEntryDataDecompressed","updatedLatestEntry","elasticsearchPublishedData","ex","WebinyError","DdbEsUpdateEntry","UpdateEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;AAgCA,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,MAAgD,EAClD;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,cAAcF,AAAiB,gBAAjBA,MAAM,MAAM;QAChC,MAAMG,SAASD,cAAc,OAAOF,MAAM,MAAM;QAEhD,MAAMI,eAAeC,wBAAwBL;QAC7C,MAAMM,aAAaC,sBAAsBP;QACzC,MAAMQ,gBAAgBC,yBAAyBT;QAK/C,MAAM,CAACU,mBAAmB,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAC;YAC3Eb;YACA,KAAK;gBAACG,MAAM,EAAE;aAAC;QACnB;QAEA,MAAM,CAACW,sBAAsB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Entry.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsEntryValues,\n CmsEntryStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { UpdateEntryStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/entry/UpdateEntryStorageOperation.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 createPartitionKey,\n createRevisionSortKey\n} from \"./keys.js\";\nimport {\n isEntryLevelEntryMetaField,\n pickEntryMetaFields\n} from \"@webiny/api-headless-cms/constants.js\";\nimport type { IEntryEntityAttributes } from \"~/definitions/types.js\";\nimport type { CmsIndexEntry } from \"@webiny/api-headless-cms-utils-os/types.js\";\n\nclass DdbEsUpdateEntryImpl implements UpdateEntryStorageOperation.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: CmsEntryStorageOperationsUpdateParams<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 isPublished = entry.status === \"published\";\n const locked = isPublished ? true : entry.locked;\n\n const revisionKeys = createEntryRevisionKeys(entry);\n const latestKeys = createEntryLatestKeys(entry);\n const publishedKeys = createEntryPublishedKeys(entry);\n\n /**\n * We need the latest entry to check if it needs to be updated.\n */\n const [latestStorageEntry] = await this.dataLoaders.getLatestRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const [publishedStorageEntry] = await this.dataLoaders.getPublishedRevisionByEntryId({\n model,\n ids: [entry.id]\n });\n\n const entityBatch = this.entity.createEntityWriter({\n put: [\n {\n ...revisionKeys,\n data: {\n ...storageEntry,\n locked\n }\n }\n ]\n });\n\n if (isPublished) {\n entityBatch.put({\n ...publishedKeys,\n data: {\n ...storageEntry,\n locked\n }\n });\n }\n\n const elasticsearchEntityBatch = this.esEntity.createEntityWriter();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index: esIndex } = await configurations.es({\n model\n });\n\n /**\n * If the latest entry is the one being updated, we need to create a new latest entry records.\n */\n if (latestStorageEntry) {\n const updatingLatestRevision = latestStorageEntry.id === entry.id;\n if (updatingLatestRevision) {\n /**\n * First we update the regular DynamoDB table.\n */\n entityBatch.put({\n ...latestKeys,\n data: storageEntry\n });\n\n /**\n * And then update the Elasticsearch table to propagate changes to the Elasticsearch\n */\n const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: elasticsearchLatestData\n });\n } else {\n /**\n * If not updating latest revision, we still want to update the latest revision's\n * entry-level meta fields to match the current revision's entry-level meta fields.\n */\n const updatedEntryLevelMetaFields = pickEntryMetaFields(\n entry,\n isEntryLevelEntryMetaField\n );\n\n const updatedLatestStorageEntry: IEntryEntityAttributes = {\n ...latestKeys,\n data: {\n ...latestStorageEntry,\n ...updatedEntryLevelMetaFields\n }\n };\n\n /**\n * First we update the regular DynamoDB table. Two updates are needed:\n * - one for the actual revision record\n * - one for the latest record\n */\n entityBatch.put({\n ...updatedLatestStorageEntry,\n PK: createPartitionKey({\n id: latestStorageEntry.id,\n tenant: model.tenant\n }),\n SK: createRevisionSortKey(latestStorageEntry)\n });\n\n entityBatch.put({\n ...updatedLatestStorageEntry\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 const updatedLatestEntry = await this.compressionHandler.compress({\n ...latestEsEntryDataDecompressed,\n ...updatedEntryLevelMetaFields\n });\n\n elasticsearchEntityBatch.put({\n ...latestKeys,\n index: esIndex,\n data: updatedLatestEntry\n });\n }\n }\n }\n\n if (isPublished && publishedStorageEntry?.id === entry.id) {\n const elasticsearchPublishedData =\n await transformer.getElasticsearchPublishedEntryData();\n elasticsearchEntityBatch.put({\n ...publishedKeys,\n index: esIndex,\n data: elasticsearchPublishedData\n });\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 update entry DynamoDB records.\",\n ex.code || \"UPDATE_ENTRY_ERROR\",\n {\n error: ex,\n entry,\n storageEntry\n }\n );\n }\n try {\n await elasticsearchEntityBatch.execute();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update entry DynamoDB Elasticsearch records.\",\n ex.code || \"UPDATE_ES_ENTRY_ERROR\",\n {\n error: ex,\n entry\n }\n );\n }\n return initialStorageEntry;\n }\n}\n\nexport const DdbEsUpdateEntry = UpdateEntryStorageOperation.createImplementation({\n implementation: DdbEsUpdateEntryImpl,\n dependencies: [\n CmsDdbEsEntryEntity,\n CmsDdbEsEntriesEsEntity,\n CmsDdbEsDataLoaders,\n CmsStorageModelProvider,\n CmsEntryOpenSearchFieldIndexRegistry,\n CompressionHandler,\n CmsModelOpenSearchIndexProvider,\n [CmsEntryOpenSearchValuesModifier, { multiple: true }]\n ]\n});\n"],"names":["DdbEsUpdateEntryImpl","entity","esEntity","dataLoaders","storageModelProvider","fieldIndexRegistry","compressionHandler","indexProvider","valuesModifiers","initialModel","params","initialEntry","initialStorageEntry","model","transformer","createTransformer","entry","storageEntry","isPublished","locked","revisionKeys","createEntryRevisionKeys","latestKeys","createEntryLatestKeys","publishedKeys","createEntryPublishedKeys","latestStorageEntry","publishedStorageEntry","entityBatch","elasticsearchEntityBatch","configurations","createConfigurations","esIndex","updatingLatestRevision","elasticsearchLatestData","updatedEntryLevelMetaFields","pickEntryMetaFields","isEntryLevelEntryMetaField","updatedLatestStorageEntry","createPartitionKey","createRevisionSortKey","latestEsEntry","latestEsEntryDataDecompressed","updatedLatestEntry","elasticsearchPublishedData","ex","WebinyError","DdbEsUpdateEntry","UpdateEntryStorageOperation","CmsDdbEsEntryEntity","CmsDdbEsEntriesEsEntity","CmsDdbEsDataLoaders","CmsStorageModelProvider","CmsEntryOpenSearchFieldIndexRegistry","CompressionHandler","CmsModelOpenSearchIndexProvider","CmsEntryOpenSearchValuesModifier"],"mappings":";;;;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,MAAqC,EACrCC,QAA2C,EAC3CC,WAA0C,EAC1CC,oBAAuD,EACvDC,kBAAkE,EAClEC,kBAAgD,EAChDC,aAAwD,EACxDC,eAA6D,C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oBAClC;oBAEAN,yBAAyB,GAAG,CAAC;wBACzB,GAAGP,UAAU;wBACb,OAAOU;wBACP,MAAMW;oBACV;gBACJ;YACJ;QACJ;QAEA,IAAIzB,eAAeS,uBAAuB,OAAOX,MAAM,EAAE,EAAE;YACvD,MAAM4B,6BACF,MAAM9B,YAAY,kCAAkC;YACxDe,yBAAyB,GAAG,CAAC;gBACzB,GAAGL,aAAa;gBAChB,OAAOQ;gBACP,MAAMY;YACV;QACJ;QACA,IAAI;YACA,MAAMhB,YAAY,OAAO;YAEzB,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtB,QAAQZ,MAAM,MAAM;YACxB;QACJ,EAAE,OAAO6B,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,4CACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACP7B;gBACAC;YACJ;QAER;QACA,IAAI;YACA,MAAMY,yBAAyB,OAAO;QAC1C,EAAE,OAAOgB,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,0DACdA,GAAG,IAAI,IAAI,yBACX;gBACI,OAAOA;gBACP7B;YACJ;QAER;QACA,OAAOJ;IACX;AACJ;AAEO,MAAMmC,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBhD;IAChB,cAAc;QACViD;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;KACzD;AACL"}
@@ -25,7 +25,7 @@ import { DdbEsGetUniqueFieldValues } from "./DdbEsGetUniqueFieldValues.js";
25
25
  const DdbEsEntryStorageOpsFeature = createFeature({
26
26
  name: "cms.ddbEs.entryStorageOps",
27
27
  register: (container)=>{
28
- container.register(DataLoadersHandler).inSingletonScope();
28
+ container.register(DataLoadersHandler).inContainerScope();
29
29
  container.register(DdbEsCreateEntry);
30
30
  container.register(DdbEsCreateEntryRevisionFrom);
31
31
  container.register(DdbEsUpdateEntry);
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DataLoadersHandler } from \"./dataLoaders.js\";\nimport { DdbEsCreateEntry } from \"./DdbEsCreateEntry.js\";\nimport { DdbEsCreateEntryRevisionFrom } from \"./DdbEsCreateEntryRevisionFrom.js\";\nimport { DdbEsUpdateEntry } from \"./DdbEsUpdateEntry.js\";\nimport { DdbEsMoveEntry } from \"./DdbEsMoveEntry.js\";\nimport { DdbEsMoveToBin } from \"./DdbEsMoveToBin.js\";\nimport { DdbEsDeleteEntry } from \"./DdbEsDeleteEntry.js\";\nimport { DdbEsRestoreFromBin } from \"./DdbEsRestoreFromBin.js\";\nimport { DdbEsDeleteEntryRevision } from \"./DdbEsDeleteEntryRevision.js\";\nimport { DdbEsDeleteMultipleEntries } from \"./DdbEsDeleteMultipleEntries.js\";\nimport { DdbEsGetEntry } from \"./DdbEsGetEntry.js\";\nimport { DdbEsListEntries } from \"./DdbEsListEntries.js\";\nimport { DdbEsPublishEntry } from \"./DdbEsPublishEntry.js\";\nimport { DdbEsUnpublishEntry } from \"./DdbEsUnpublishEntry.js\";\nimport { DdbEsGetEntriesByIds } from \"./DdbEsGetEntriesByIds.js\";\nimport { DdbEsGetLatestEntriesByIds } from \"./DdbEsGetLatestEntriesByIds.js\";\nimport { DdbEsGetPublishedEntriesByIds } from \"./DdbEsGetPublishedEntriesByIds.js\";\nimport { DdbEsGetRevisions } from \"./DdbEsGetRevisions.js\";\nimport { DdbEsGetRevisionById } from \"./DdbEsGetRevisionById.js\";\nimport { DdbEsGetLatestRevisionByEntryId } from \"./DdbEsGetLatestRevisionByEntryId.js\";\nimport { DdbEsGetPublishedRevisionByEntryId } from \"./DdbEsGetPublishedRevisionByEntryId.js\";\nimport { DdbEsGetPreviousRevision } from \"./DdbEsGetPreviousRevision.js\";\nimport { DdbEsGetUniqueFieldValues } from \"./DdbEsGetUniqueFieldValues.js\";\n\nexport const DdbEsEntryStorageOpsFeature = createFeature({\n name: \"cms.ddbEs.entryStorageOps\",\n register: container => {\n container.register(DataLoadersHandler).inSingletonScope();\n container.register(DdbEsCreateEntry);\n container.register(DdbEsCreateEntryRevisionFrom);\n container.register(DdbEsUpdateEntry);\n container.register(DdbEsMoveEntry);\n container.register(DdbEsMoveToBin);\n container.register(DdbEsDeleteEntry);\n container.register(DdbEsRestoreFromBin);\n container.register(DdbEsDeleteEntryRevision);\n container.register(DdbEsDeleteMultipleEntries);\n container.register(DdbEsGetEntry);\n container.register(DdbEsListEntries);\n container.register(DdbEsPublishEntry);\n container.register(DdbEsUnpublishEntry);\n container.register(DdbEsGetEntriesByIds);\n container.register(DdbEsGetLatestEntriesByIds);\n container.register(DdbEsGetPublishedEntriesByIds);\n container.register(DdbEsGetRevisions);\n container.register(DdbEsGetRevisionById);\n container.register(DdbEsGetLatestRevisionByEntryId);\n container.register(DdbEsGetPublishedRevisionByEntryId);\n container.register(DdbEsGetPreviousRevision);\n container.register(DdbEsGetUniqueFieldValues);\n }\n});\n"],"names":["DdbEsEntryStorageOpsFeature","createFeature","container","DataLoadersHandler","DdbEsCreateEntry","DdbEsCreateEntryRevisionFrom","DdbEsUpdateEntry","DdbEsMoveEntry","DdbEsMoveToBin","DdbEsDeleteEntry","DdbEsRestoreFromBin","DdbEsDeleteEntryRevision","DdbEsDeleteMultipleEntries","DdbEsGetEntry","DdbEsListEntries","DdbEsPublishEntry","DdbEsUnpublishEntry","DdbEsGetEntriesByIds","DdbEsGetLatestEntriesByIds","DdbEsGetPublishedEntriesByIds","DdbEsGetRevisions","DdbEsGetRevisionById","DdbEsGetLatestRevisionByEntryId","DdbEsGetPublishedRevisionByEntryId","DdbEsGetPreviousRevision","DdbEsGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;QACnBtB,UAAU,QAAQ,CAACuB;IACvB;AACJ"}
1
+ {"version":3,"file":"operations/entry/feature.js","sources":["../../../src/operations/entry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DataLoadersHandler } from \"./dataLoaders.js\";\nimport { DdbEsCreateEntry } from \"./DdbEsCreateEntry.js\";\nimport { DdbEsCreateEntryRevisionFrom } from \"./DdbEsCreateEntryRevisionFrom.js\";\nimport { DdbEsUpdateEntry } from \"./DdbEsUpdateEntry.js\";\nimport { DdbEsMoveEntry } from \"./DdbEsMoveEntry.js\";\nimport { DdbEsMoveToBin } from \"./DdbEsMoveToBin.js\";\nimport { DdbEsDeleteEntry } from \"./DdbEsDeleteEntry.js\";\nimport { DdbEsRestoreFromBin } from \"./DdbEsRestoreFromBin.js\";\nimport { DdbEsDeleteEntryRevision } from \"./DdbEsDeleteEntryRevision.js\";\nimport { DdbEsDeleteMultipleEntries } from \"./DdbEsDeleteMultipleEntries.js\";\nimport { DdbEsGetEntry } from \"./DdbEsGetEntry.js\";\nimport { DdbEsListEntries } from \"./DdbEsListEntries.js\";\nimport { DdbEsPublishEntry } from \"./DdbEsPublishEntry.js\";\nimport { DdbEsUnpublishEntry } from \"./DdbEsUnpublishEntry.js\";\nimport { DdbEsGetEntriesByIds } from \"./DdbEsGetEntriesByIds.js\";\nimport { DdbEsGetLatestEntriesByIds } from \"./DdbEsGetLatestEntriesByIds.js\";\nimport { DdbEsGetPublishedEntriesByIds } from \"./DdbEsGetPublishedEntriesByIds.js\";\nimport { DdbEsGetRevisions } from \"./DdbEsGetRevisions.js\";\nimport { DdbEsGetRevisionById } from \"./DdbEsGetRevisionById.js\";\nimport { DdbEsGetLatestRevisionByEntryId } from \"./DdbEsGetLatestRevisionByEntryId.js\";\nimport { DdbEsGetPublishedRevisionByEntryId } from \"./DdbEsGetPublishedRevisionByEntryId.js\";\nimport { DdbEsGetPreviousRevision } from \"./DdbEsGetPreviousRevision.js\";\nimport { DdbEsGetUniqueFieldValues } from \"./DdbEsGetUniqueFieldValues.js\";\n\nexport const DdbEsEntryStorageOpsFeature = createFeature({\n name: \"cms.ddbEs.entryStorageOps\",\n register: container => {\n // The DataLoader caches reads, so it must live for one request: container scoped, it is built\n // per request (child) container even though the feature is registered once in the root.\n container.register(DataLoadersHandler).inContainerScope();\n container.register(DdbEsCreateEntry);\n container.register(DdbEsCreateEntryRevisionFrom);\n container.register(DdbEsUpdateEntry);\n container.register(DdbEsMoveEntry);\n container.register(DdbEsMoveToBin);\n container.register(DdbEsDeleteEntry);\n container.register(DdbEsRestoreFromBin);\n container.register(DdbEsDeleteEntryRevision);\n container.register(DdbEsDeleteMultipleEntries);\n container.register(DdbEsGetEntry);\n container.register(DdbEsListEntries);\n container.register(DdbEsPublishEntry);\n container.register(DdbEsUnpublishEntry);\n container.register(DdbEsGetEntriesByIds);\n container.register(DdbEsGetLatestEntriesByIds);\n container.register(DdbEsGetPublishedEntriesByIds);\n container.register(DdbEsGetRevisions);\n container.register(DdbEsGetRevisionById);\n container.register(DdbEsGetLatestRevisionByEntryId);\n container.register(DdbEsGetPublishedRevisionByEntryId);\n container.register(DdbEsGetPreviousRevision);\n container.register(DdbEsGetUniqueFieldValues);\n }\n});\n"],"names":["DdbEsEntryStorageOpsFeature","createFeature","container","DataLoadersHandler","DdbEsCreateEntry","DdbEsCreateEntryRevisionFrom","DdbEsUpdateEntry","DdbEsMoveEntry","DdbEsMoveToBin","DdbEsDeleteEntry","DdbEsRestoreFromBin","DdbEsDeleteEntryRevision","DdbEsDeleteMultipleEntries","DdbEsGetEntry","DdbEsListEntries","DdbEsPublishEntry","DdbEsUnpublishEntry","DdbEsGetEntriesByIds","DdbEsGetLatestEntriesByIds","DdbEsGetPublishedEntriesByIds","DdbEsGetRevisions","DdbEsGetRevisionById","DdbEsGetLatestRevisionByEntryId","DdbEsGetPublishedRevisionByEntryId","DdbEsGetPreviousRevision","DdbEsGetUniqueFieldValues"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAAUC,CAAAA;QAGNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QACnBhB,UAAU,QAAQ,CAACiB;QACnBjB,UAAU,QAAQ,CAACkB;QACnBlB,UAAU,QAAQ,CAACmB;QACnBnB,UAAU,QAAQ,CAACoB;QACnBpB,UAAU,QAAQ,CAACqB;QACnBrB,UAAU,QAAQ,CAACsB;QACnBtB,UAAU,QAAQ,CAACuB;IACvB;AACJ"}
@@ -2,10 +2,12 @@ import type { CmsModelStorageOperationsCreateParams } from "@webiny/api-headless
2
2
  import { CreateModelStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/model/CreateModelStorageOperation.js";
3
3
  import { CmsDdbEsModelEntity } from "../../abstractions/CmsDdbEsModelEntity.js";
4
4
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
5
+ import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
5
6
  declare class DdbEsCreateModelImpl implements CreateModelStorageOperation.Interface {
6
7
  private entity;
8
+ private indexProvider;
7
9
  private elasticsearch;
8
- constructor(entity: CmsDdbEsModelEntity.Interface, openSearchClient: OpenSearchClient.Interface);
10
+ constructor(entity: CmsDdbEsModelEntity.Interface, openSearchClient: OpenSearchClient.Interface, indexProvider: CmsModelOpenSearchIndexProvider.Interface);
9
11
  execute(params: CmsModelStorageOperationsCreateParams): Promise<import("@webiny/api-headless-cms/types/model.js").StorageCmsModel>;
10
12
  }
11
13
  export declare const DdbEsCreateModel: typeof DdbEsCreateModelImpl & {
@@ -1,17 +1,20 @@
1
1
  import _webiny_error from "@webiny/error";
2
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
2
+ import { createConfigurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
3
3
  import { CreateModelStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/model/CreateModelStorageOperation.js";
4
4
  import { CmsDdbEsModelEntity } from "../../abstractions/CmsDdbEsModelEntity.js";
5
5
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
6
6
  import { createKeys, createType } from "./keys.js";
7
+ import { CmsModelOpenSearchIndexProvider } from "@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js";
7
8
  class DdbEsCreateModelImpl {
8
- constructor(entity, openSearchClient){
9
+ constructor(entity, openSearchClient, indexProvider){
9
10
  this.entity = entity;
11
+ this.indexProvider = indexProvider;
10
12
  this.elasticsearch = openSearchClient.use();
11
13
  }
12
14
  async execute(params) {
13
15
  const { model } = params;
14
- const { index } = configurations.es({
16
+ const configurations = createConfigurations(this.indexProvider);
17
+ const { index } = await configurations.es({
15
18
  model
16
19
  });
17
20
  const keys = createKeys(model);
@@ -44,7 +47,8 @@ const DdbEsCreateModel = CreateModelStorageOperation.createImplementation({
44
47
  implementation: DdbEsCreateModelImpl,
45
48
  dependencies: [
46
49
  CmsDdbEsModelEntity,
47
- OpenSearchClient
50
+ OpenSearchClient,
51
+ CmsModelOpenSearchIndexProvider
48
52
  ]
49
53
  });
50
54
  export { DdbEsCreateModel };
@@ -1 +1 @@
1
- {"version":3,"file":"operations/model/DdbEsCreateModel.js","sources":["../../../src/operations/model/DdbEsCreateModel.ts"],"sourcesContent":["import type { CmsModelStorageOperationsCreateParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { configurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { CreateModelStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/model/CreateModelStorageOperation.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { createKeys, createType } from \"./keys.js\";\n\nclass DdbEsCreateModelImpl implements CreateModelStorageOperation.Interface {\n private elasticsearch;\n\n constructor(\n private entity: CmsDdbEsModelEntity.Interface,\n openSearchClient: OpenSearchClient.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(params: CmsModelStorageOperationsCreateParams) {\n const { model } = params;\n\n const { index } = configurations.es({\n model\n });\n\n const keys = createKeys(model);\n\n let error;\n try {\n await this.entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n error = ex;\n }\n try {\n await this.elasticsearch.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not delete elasticsearch index \"${index}\" after model record failed to be created.`,\n \"DELETE_MODEL_INDEX_ERROR\",\n {\n dynamodbError: error,\n elasticsearchError: ex\n }\n );\n }\n throw error;\n }\n}\n\nexport const DdbEsCreateModel = CreateModelStorageOperation.createImplementation({\n implementation: DdbEsCreateModelImpl,\n dependencies: [CmsDdbEsModelEntity, OpenSearchClient]\n});\n"],"names":["DdbEsCreateModelImpl","entity","openSearchClient","params","model","index","configurations","keys","createKeys","error","createType","ex","WebinyError","DdbEsCreateModel","CreateModelStorageOperation","CmsDdbEsModelEntity","OpenSearchClient"],"mappings":";;;;;;AAQA,MAAMA;IAGF,YACYC,MAAqC,EAC7CC,gBAA4C,CAC9C;aAFUD,MAAM,GAANA;QAGR,IAAI,CAAC,aAAa,GAAGC,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQC,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,MAAM,EAAEE,KAAK,EAAE,GAAGC,eAAe,EAAE,CAAC;YAChCF;QACJ;QAEA,MAAMG,OAAOC,WAAWJ;QAExB,IAAIK;QACJ,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBAClB,MAAML;gBACN,GAAGG,IAAI;gBACP,MAAMG;YACV;YACA,OAAON;QACX,EAAE,OAAOO,IAAI;YACTF,QAAQE;QACZ;QACA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;gBACpCN;gBACA,oBAAoB;YACxB;QACJ,EAAE,OAAOM,IAAI;YACT,MAAM,IAAIC,cACN,CAAC,sCAAsC,EAAEP,MAAM,0CAA0C,CAAC,EAC1F,4BACA;gBACI,eAAeI;gBACf,oBAAoBE;YACxB;QAER;QACA,MAAMF;IACV;AACJ;AAEO,MAAMI,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBd;IAChB,cAAc;QAACe;QAAqBC;KAAiB;AACzD"}
1
+ {"version":3,"file":"operations/model/DdbEsCreateModel.js","sources":["../../../src/operations/model/DdbEsCreateModel.ts"],"sourcesContent":["import type { CmsModelStorageOperationsCreateParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { createConfigurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { CreateModelStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/model/CreateModelStorageOperation.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { createKeys, createType } from \"./keys.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"@webiny/api-headless-cms-utils-os/exports/api/cms/opensearch.js\";\n\nclass DdbEsCreateModelImpl implements CreateModelStorageOperation.Interface {\n private elasticsearch;\n\n constructor(\n private entity: CmsDdbEsModelEntity.Interface,\n openSearchClient: OpenSearchClient.Interface,\n private indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(params: CmsModelStorageOperationsCreateParams) {\n const { model } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index } = await configurations.es({\n model\n });\n\n const keys = createKeys(model);\n\n let error;\n try {\n await this.entity.put({\n data: model,\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n error = ex;\n }\n try {\n await this.elasticsearch.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not delete elasticsearch index \"${index}\" after model record failed to be created.`,\n \"DELETE_MODEL_INDEX_ERROR\",\n {\n dynamodbError: error,\n elasticsearchError: ex\n }\n );\n }\n throw error;\n }\n}\n\nexport const DdbEsCreateModel = CreateModelStorageOperation.createImplementation({\n implementation: DdbEsCreateModelImpl,\n dependencies: [CmsDdbEsModelEntity, OpenSearchClient, CmsModelOpenSearchIndexProvider]\n});\n"],"names":["DdbEsCreateModelImpl","entity","openSearchClient","indexProvider","params","model","configurations","createConfigurations","index","keys","createKeys","error","createType","ex","WebinyError","DdbEsCreateModel","CreateModelStorageOperation","CmsDdbEsModelEntity","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;;;AASA,MAAMA;IAGF,YACYC,MAAqC,EAC7CC,gBAA4C,EACpCC,aAAwD,CAClE;aAHUF,MAAM,GAANA;aAEAE,aAAa,GAAbA;QAER,IAAI,CAAC,aAAa,GAAGD,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQE,MAA6C,EAAE;QACzD,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,MAAME,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMF,eAAe,EAAE,CAAC;YACtCD;QACJ;QAEA,MAAMI,OAAOC,WAAWL;QAExB,IAAIM;QACJ,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;gBAClB,MAAMN;gBACN,GAAGI,IAAI;gBACP,MAAMG;YACV;YACA,OAAOP;QACX,EAAE,OAAOQ,IAAI;YACTF,QAAQE;QACZ;QACA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;gBACpCL;gBACA,oBAAoB;YACxB;QACJ,EAAE,OAAOK,IAAI;YACT,MAAM,IAAIC,cACN,CAAC,sCAAsC,EAAEN,MAAM,0CAA0C,CAAC,EAC1F,4BACA;gBACI,eAAeG;gBACf,oBAAoBE;YACxB;QAER;QACA,MAAMF;IACV;AACJ;AAEO,MAAMI,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBhB;IAChB,cAAc;QAACiB;QAAqBC;QAAkBC;KAAgC;AAC1F"}
@@ -1,11 +1,9 @@
1
1
  import type { CmsModelStorageOperationsDeleteParams } from "@webiny/api-headless-cms/types/index.js";
2
2
  import { DeleteModelStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/model/DeleteModelStorageOperation.js";
3
3
  import { CmsDdbEsModelEntity } from "../../abstractions/CmsDdbEsModelEntity.js";
4
- import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
5
4
  declare class DdbEsDeleteModelImpl implements DeleteModelStorageOperation.Interface {
6
5
  private entity;
7
- private elasticsearch;
8
- constructor(entity: CmsDdbEsModelEntity.Interface, openSearchClient: OpenSearchClient.Interface);
6
+ constructor(entity: CmsDdbEsModelEntity.Interface);
9
7
  execute(params: CmsModelStorageOperationsDeleteParams): Promise<void>;
10
8
  }
11
9
  export declare const DdbEsDeleteModel: typeof DdbEsDeleteModelImpl & {
@@ -1,20 +1,14 @@
1
1
  import error from "@webiny/error";
2
- import { configurations } from "@webiny/api-headless-cms-utils-os/configurations.js";
3
2
  import { DeleteModelStorageOperation } from "@webiny/api-headless-cms/features/shared/storageOperations/model/DeleteModelStorageOperation.js";
4
3
  import { CmsDdbEsModelEntity } from "../../abstractions/CmsDdbEsModelEntity.js";
5
- import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
6
4
  import { createKeys } from "./keys.js";
7
5
  class DdbEsDeleteModelImpl {
8
- constructor(entity, openSearchClient){
6
+ constructor(entity){
9
7
  this.entity = entity;
10
- this.elasticsearch = openSearchClient.use();
11
8
  }
12
9
  async execute(params) {
13
10
  const { model } = params;
14
11
  const keys = createKeys(model);
15
- const { index } = configurations.es({
16
- model
17
- });
18
12
  try {
19
13
  await this.entity.delete(keys);
20
14
  } catch (ex) {
@@ -24,25 +18,12 @@ class DdbEsDeleteModelImpl {
24
18
  keys
25
19
  });
26
20
  }
27
- try {
28
- await this.elasticsearch.indices.delete({
29
- index,
30
- ignore_unavailable: true
31
- });
32
- } catch (ex) {
33
- throw new error(`Could not delete elasticsearch index "${index}" after model record delete.`, "DELETE_MODEL_INDEX_ERROR", {
34
- error: ex,
35
- index,
36
- model
37
- });
38
- }
39
21
  }
40
22
  }
41
23
  const DdbEsDeleteModel = DeleteModelStorageOperation.createImplementation({
42
24
  implementation: DdbEsDeleteModelImpl,
43
25
  dependencies: [
44
- CmsDdbEsModelEntity,
45
- OpenSearchClient
26
+ CmsDdbEsModelEntity
46
27
  ]
47
28
  });
48
29
  export { DdbEsDeleteModel };
@@ -1 +1 @@
1
- {"version":3,"file":"operations/model/DdbEsDeleteModel.js","sources":["../../../src/operations/model/DdbEsDeleteModel.ts"],"sourcesContent":["import type { CmsModelStorageOperationsDeleteParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { configurations } from \"@webiny/api-headless-cms-utils-os/configurations.js\";\nimport { DeleteModelStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/model/DeleteModelStorageOperation.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsDeleteModelImpl implements DeleteModelStorageOperation.Interface {\n private elasticsearch;\n\n constructor(\n private entity: CmsDdbEsModelEntity.Interface,\n openSearchClient: OpenSearchClient.Interface\n ) {\n this.elasticsearch = openSearchClient.use();\n }\n\n async execute(params: CmsModelStorageOperationsDeleteParams): Promise<void> {\n const { model } = params;\n const keys = createKeys(model);\n\n const { index } = configurations.es({\n model\n });\n\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n try {\n await this.elasticsearch.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not delete elasticsearch index \"${index}\" after model record delete.`,\n \"DELETE_MODEL_INDEX_ERROR\",\n {\n error: ex,\n index,\n model\n }\n );\n }\n }\n}\n\nexport const DdbEsDeleteModel = DeleteModelStorageOperation.createImplementation({\n implementation: DdbEsDeleteModelImpl,\n dependencies: [CmsDdbEsModelEntity, OpenSearchClient]\n});\n"],"names":["DdbEsDeleteModelImpl","entity","openSearchClient","params","model","keys","createKeys","index","configurations","ex","WebinyError","DdbEsDeleteModel","DeleteModelStorageOperation","CmsDdbEsModelEntity","OpenSearchClient"],"mappings":";;;;;;AAQA,MAAMA;IAGF,YACYC,MAAqC,EAC7CC,gBAA4C,CAC9C;aAFUD,MAAM,GAANA;QAGR,IAAI,CAAC,aAAa,GAAGC,iBAAiB,GAAG;IAC7C;IAEA,MAAM,QAAQC,MAA6C,EAAiB;QACxE,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,OAAOC,WAAWF;QAExB,MAAM,EAAEG,KAAK,EAAE,GAAGC,eAAe,EAAE,CAAC;YAChCJ;QACJ;QAEA,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAACC;QAC7B,EAAE,OAAOI,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPL;gBACAC;YACJ;QAER;QACA,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;gBACpCE;gBACA,oBAAoB;YACxB;QACJ,EAAE,OAAOE,IAAI;YACT,MAAM,IAAIC,MACN,CAAC,sCAAsC,EAAEH,MAAM,4BAA4B,CAAC,EAC5E,4BACA;gBACI,OAAOE;gBACPF;gBACAH;YACJ;QAER;IACJ;AACJ;AAEO,MAAMO,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBZ;IAChB,cAAc;QAACa;QAAqBC;KAAiB;AACzD"}
1
+ {"version":3,"file":"operations/model/DdbEsDeleteModel.js","sources":["../../../src/operations/model/DdbEsDeleteModel.ts"],"sourcesContent":["import type { CmsModelStorageOperationsDeleteParams } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { DeleteModelStorageOperation } from \"@webiny/api-headless-cms/features/shared/storageOperations/model/DeleteModelStorageOperation.js\";\nimport { CmsDdbEsModelEntity } from \"~/abstractions/CmsDdbEsModelEntity.js\";\nimport { createKeys } from \"./keys.js\";\n\nclass DdbEsDeleteModelImpl implements DeleteModelStorageOperation.Interface {\n constructor(private entity: CmsDdbEsModelEntity.Interface) {}\n\n async execute(params: CmsModelStorageOperationsDeleteParams): Promise<void> {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n }\n}\n\nexport const DdbEsDeleteModel = DeleteModelStorageOperation.createImplementation({\n implementation: DdbEsDeleteModelImpl,\n dependencies: [CmsDdbEsModelEntity]\n});\n"],"names":["DdbEsDeleteModelImpl","entity","params","model","keys","createKeys","ex","WebinyError","DdbEsDeleteModel","DeleteModelStorageOperation","CmsDdbEsModelEntity"],"mappings":";;;;AAMA,MAAMA;IACF,YAAoBC,MAAqC,CAAE;aAAvCA,MAAM,GAANA;IAAwC;IAE5D,MAAM,QAAQC,MAA6C,EAAiB;QACxE,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,OAAOC,WAAWF;QAExB,IAAI;YACA,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAACC;QAC7B,EAAE,OAAOE,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPH;gBACAC;YACJ;QAER;IACJ;AACJ;AAEO,MAAMI,mBAAmBC,4BAA4B,oBAAoB,CAAC;IAC7E,gBAAgBT;IAChB,cAAc;QAACU;KAAoB;AACvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-ddb-es",
3
- "version": "6.6.0-alpha.0",
3
+ "version": "6.6.0-alpha.10",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -30,40 +30,40 @@
30
30
  ],
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@webiny/api": "6.6.0-alpha.0",
34
- "@webiny/api-headless-cms": "6.6.0-alpha.0",
35
- "@webiny/api-headless-cms-storage": "6.6.0-alpha.0",
36
- "@webiny/api-headless-cms-utils-os": "6.6.0-alpha.0",
37
- "@webiny/api-opensearch": "6.6.0-alpha.0",
38
- "@webiny/api-search-index-tasks": "6.6.0-alpha.0",
39
- "@webiny/db": "6.6.0-alpha.0",
40
- "@webiny/db-dynamodb": "6.6.0-alpha.0",
41
- "@webiny/error": "6.6.0-alpha.0",
42
- "@webiny/feature": "6.6.0-alpha.0",
43
- "@webiny/plugins": "6.6.0-alpha.0",
44
- "@webiny/stdlib": "0.0.14",
45
- "@webiny/utils": "6.6.0-alpha.0",
33
+ "@webiny/api": "6.6.0-alpha.10",
34
+ "@webiny/api-core": "6.6.0-alpha.10",
35
+ "@webiny/api-headless-cms": "6.6.0-alpha.10",
36
+ "@webiny/api-headless-cms-storage": "6.6.0-alpha.10",
37
+ "@webiny/api-headless-cms-utils-os": "6.6.0-alpha.10",
38
+ "@webiny/api-opensearch": "6.6.0-alpha.10",
39
+ "@webiny/api-opensearch-aws": "6.6.0-alpha.10",
40
+ "@webiny/api-search-index-tasks": "6.6.0-alpha.10",
41
+ "@webiny/db": "6.6.0-alpha.10",
42
+ "@webiny/db-dynamodb": "6.6.0-alpha.10",
43
+ "@webiny/error": "6.6.0-alpha.10",
44
+ "@webiny/feature": "6.6.0-alpha.10",
45
+ "@webiny/plugins": "6.6.0-alpha.10",
46
+ "@webiny/stdlib": "0.0.21",
47
+ "@webiny/utils": "6.6.0-alpha.10",
46
48
  "dataloader": "2.2.3",
47
49
  "lodash": "4.18.1"
48
50
  },
49
51
  "devDependencies": {
50
52
  "@types/jsonpack": "1.1.6",
51
- "@webiny/api-core": "6.6.0-alpha.0",
52
- "@webiny/api-core-testing": "6.6.0-alpha.0",
53
- "@webiny/api-graphql": "6.6.0-alpha.0",
54
- "@webiny/api-search-index-tasks-ddb-os": "6.6.0-alpha.0",
55
- "@webiny/api-sync-ddb-to-opensearch": "6.6.0-alpha.0",
56
- "@webiny/background-tasks": "6.6.0-alpha.0",
57
- "@webiny/build-tools": "6.6.0-alpha.0",
58
- "@webiny/di": "1.0.2",
59
- "@webiny/event-handler-core": "6.6.0-alpha.0",
60
- "@webiny/handler": "6.6.0-alpha.0",
61
- "@webiny/project-utils": "6.6.0-alpha.0",
62
- "@webiny/wcp": "6.6.0-alpha.0",
53
+ "@webiny/api-core-testing": "6.6.0-alpha.10",
54
+ "@webiny/api-graphql": "6.6.0-alpha.10",
55
+ "@webiny/api-search-index-tasks-ddb-os": "6.6.0-alpha.10",
56
+ "@webiny/api-sync-ddb-to-opensearch": "6.6.0-alpha.10",
57
+ "@webiny/background-tasks": "6.6.0-alpha.10",
58
+ "@webiny/build-tools": "6.6.0-alpha.10",
59
+ "@webiny/di": "2.0.0",
60
+ "@webiny/event-handler-core": "6.6.0-alpha.10",
61
+ "@webiny/handler": "6.6.0-alpha.10",
62
+ "@webiny/wcp": "6.6.0-alpha.10",
63
63
  "jest-dynalite": "3.6.1",
64
64
  "rimraf": "6.1.3",
65
65
  "typescript": "7.0.2",
66
- "vitest": "4.1.10"
66
+ "vitest": "5.0.5"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"