@webiny/api-headless-cms-ddb-es 5.35.0 → 5.35.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/index.js +8 -6
  2. package/index.js.map +1 -1
  3. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  4. package/operations/entry/dataLoader/DataLoaderCache.js +43 -0
  5. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  6. package/operations/entry/dataLoader/constants.d.ts +1 -0
  7. package/operations/entry/dataLoader/constants.js +9 -0
  8. package/operations/entry/dataLoader/constants.js.map +1 -0
  9. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  10. package/operations/entry/dataLoader/createBatchScheduleFn.js +23 -0
  11. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  12. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  13. package/operations/entry/dataLoader/getAllEntryRevisions.js +43 -0
  14. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  15. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  16. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +53 -0
  17. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  18. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  19. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +53 -0
  20. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  21. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  22. package/operations/entry/dataLoader/getRevisionById.js +63 -0
  23. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  24. package/operations/entry/dataLoader/index.d.ts +8 -0
  25. package/operations/entry/dataLoader/index.js +38 -0
  26. package/operations/entry/dataLoader/index.js.map +1 -0
  27. package/operations/entry/dataLoader/types.d.ts +6 -0
  28. package/operations/entry/dataLoader/types.js +5 -0
  29. package/operations/entry/dataLoader/types.js.map +1 -0
  30. package/operations/entry/dataLoaders.d.ts +15 -36
  31. package/operations/entry/dataLoaders.js +43 -241
  32. package/operations/entry/dataLoaders.js.map +1 -1
  33. package/operations/entry/index.d.ts +1 -1
  34. package/operations/entry/index.js +88 -4
  35. package/operations/entry/index.js.map +1 -1
  36. package/package.json +33 -33
  37. package/types.d.ts +10 -1
  38. package/types.js.map +1 -1
  39. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
  40. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -24
  41. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
package/index.js CHANGED
@@ -120,6 +120,12 @@ const createStorageOperations = params => {
120
120
  * They are at the end because we can then override existing plugins.
121
121
  */
122
122
  ...(userPlugins || [])]);
123
+ const entries = (0, _entry.createEntriesStorageOperations)({
124
+ entity: entities.entries,
125
+ esEntity: entities.entriesEs,
126
+ plugins,
127
+ elasticsearch
128
+ });
123
129
  return {
124
130
  name: "dynamodb:elasticsearch",
125
131
  beforeInit: async context => {
@@ -145,6 +151,7 @@ const createStorageOperations = params => {
145
151
  for (const type of types) {
146
152
  plugins.mergeByType(context.plugins, type);
147
153
  }
154
+ entries.dataLoaders.clearAll();
148
155
  },
149
156
  init: async context => {
150
157
  /**
@@ -204,12 +211,7 @@ const createStorageOperations = params => {
204
211
  entity: entities.models,
205
212
  elasticsearch
206
213
  }),
207
- entries: (0, _entry.createEntriesStorageOperations)({
208
- entity: entities.entries,
209
- esEntity: entities.entriesEs,
210
- plugins,
211
- elasticsearch
212
- })
214
+ entries
213
215
  };
214
216
  };
215
217
  exports.createStorageOperations = createStorageOperations;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","types","CompressionPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryFilterPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsElasticsearchModelFieldPlugin","StorageOperationsCmsModelPlugin","mergeByType","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n CompressionPlugin,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsElasticsearchModelFieldPlugin,\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n // Elasticsearch\n CompressionPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Headless CMS\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsElasticsearchModelFieldPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AAaA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAJA;AACA;AACA;AAIO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UAAU;IACVC,KAAK;IACLC,OAAO;IACPC,cAAc;IACdC,aAAa;IACbC,OAAO,EAAEC;EACb,CAAC,GAAGP,MAAM;EAEV,MAAMQ,aAAa,GAAG,IAAAC,kBAAW,EAAC;IAC9BP,KAAK;IACLE;EACJ,CAAC,CAAC;EACF,MAAMM,0BAA0B,GAAG,IAAAC,4CAAwB,EAAC;IACxDT,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MAAM,EAAE3D,QAAQ,CAACS,MAAM;MACvBf;IACJ,CAAC,CAAC;IACFkB,MAAM,EAAE,IAAAkD,oCAA6B,EAAC;MAClCH,MAAM,EAAE3D,QAAQ,CAACY,MAAM;MACvBnB;IACJ,CAAC,CAAC;IACFsB,OAAO,EAAE,IAAAgD,qCAA8B,EAAC;MACpCJ,MAAM,EAAE3D,QAAQ,CAACe,OAAO;MACxBiD,QAAQ,EAAEhE,QAAQ,CAACkB,SAAS;MAC5BxB,OAAO;MACPD;IACJ,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","createEntriesStorageOperations","entity","esEntity","name","beforeInit","context","register","types","CompressionPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryFilterPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsElasticsearchModelFieldPlugin","StorageOperationsCmsModelPlugin","mergeByType","dataLoaders","clearAll","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n CompressionPlugin,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsElasticsearchModelFieldPlugin,\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n const entries = createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n });\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n // Elasticsearch\n CompressionPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Headless CMS\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsElasticsearchModelFieldPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n entries.dataLoaders.clearAll();\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n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CAAC;MACN,CAAC,CAAC;MACFsC,OAAO,CAACmB,GAAG,CAACM,kBAAkB,CAACJ,SAAS,CAAC,OAAO;QAAEC;MAAM,CAAC,KAAK;QAC1D,MAAM,IAAAI,kDAAwB,EAAC;UAC3BjE,aAAa;UACb6D;QACJ,CAAC,CAAC;MACN,CAAC,CAAC;MAEFtB,OAAO,CAACmB,GAAG,CAACQ,iBAAiB,CAACN,SAAS,CAAC,OAAO;QAAEC;MAAM,CAAC,KAAK;QACzD,MAAM,IAAAC,kDAAwB,EAAC;UAC3B9D,aAAa;UACb6D,KAAK;UACL5D;QACJ,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC;IACDkE,WAAW,EAAE,MAAM5D,QAAQ;IAC3B6D,QAAQ,EAAE,MAAMjE,aAAa;IAC7BkE,UAAU,EAAE,MAAMhE,0BAA0B;IAC5CQ,MAAM,EAAE,IAAAyD,qCAA6B,EAAC;MAClCnC,MAAM,EAAE5B,QAAQ,CAACM;IACrB,CAAC,CAAC;IACFL,QAAQ,EAAE,IAAA+D,yCAA+B,EAAC;MACtCpC,MAAM,EAAE5B,QAAQ,CAACC;IACrB,CAAC,CAAC;IACFQ,MAAM,EAAE,IAAAwD,qCAA6B,EAAC;MAClCrC,MAAM,EAAE5B,QAAQ,CAACS,MAAM;MACvBf;IACJ,CAAC,CAAC;IACFkB,MAAM,EAAE,IAAAsD,oCAA6B,EAAC;MAClCtC,MAAM,EAAE5B,QAAQ,CAACY,MAAM;MACvBnB;IACJ,CAAC,CAAC;IACFsB;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,17 @@
1
+ import DataLoader from "dataloader";
2
+ export interface CacheKeyParams {
3
+ name: string;
4
+ tenant: string;
5
+ locale: string;
6
+ }
7
+ export interface ClearAllParams {
8
+ tenant: string;
9
+ locale: string;
10
+ }
11
+ export declare class DataLoaderCache {
12
+ private readonly cache;
13
+ getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null;
14
+ setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void;
15
+ clearAll(params?: ClearAllParams): void;
16
+ private createKey;
17
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DataLoaderCache = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ class DataLoaderCache {
11
+ constructor() {
12
+ (0, _defineProperty2.default)(this, "cache", {});
13
+ }
14
+ getDataLoader(params) {
15
+ const key = this.createKey(params);
16
+ return this.cache[key] || null;
17
+ }
18
+ setDataLoader(params, dataLoader) {
19
+ const key = this.createKey(params);
20
+ this.cache[key] = dataLoader;
21
+ }
22
+ clearAll(params) {
23
+ if (!params) {
24
+ for (const current in this.cache) {
25
+ this.cache[current].clearAll();
26
+ }
27
+ return;
28
+ }
29
+ const key = this.createKey((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
30
+ name: ""
31
+ }));
32
+ for (const current in this.cache) {
33
+ if (current.startsWith(key) === false) {
34
+ continue;
35
+ }
36
+ this.cache[current].clearAll();
37
+ }
38
+ }
39
+ createKey(params) {
40
+ return `${params.tenant}_${params.locale}_${params.name}`;
41
+ }
42
+ }
43
+ exports.DataLoaderCache = DataLoaderCache;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataLoaderCache","getDataLoader","params","key","createKey","cache","setDataLoader","dataLoader","clearAll","current","name","startsWith","tenant","locale"],"sources":["DataLoaderCache.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\n\nexport interface CacheKeyParams {\n name: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ClearAllParams {\n tenant: string;\n locale: string;\n}\n\nexport class DataLoaderCache {\n private readonly cache: Record<string, DataLoader<any, any>> = {};\n\n public getDataLoader<I = any, R = any>(params: CacheKeyParams): DataLoader<I, R> | null {\n const key = this.createKey(params);\n\n return this.cache[key] || null;\n }\n\n public setDataLoader(params: CacheKeyParams, dataLoader: DataLoader<any, any>): void {\n const key = this.createKey(params);\n this.cache[key] = dataLoader;\n }\n\n public clearAll(params?: ClearAllParams): void {\n if (!params) {\n for (const current in this.cache) {\n this.cache[current].clearAll();\n }\n return;\n }\n const key = this.createKey({\n ...params,\n name: \"\"\n });\n for (const current in this.cache) {\n if (current.startsWith(key) === false) {\n continue;\n }\n this.cache[current].clearAll();\n }\n }\n\n private createKey(params: CacheKeyParams): string {\n return `${params.tenant}_${params.locale}_${params.name}`;\n }\n}\n"],"mappings":";;;;;;;;;AAaO,MAAMA,eAAe,CAAC;EAAA;IAAA,6CACsC,CAAC,CAAC;EAAA;EAE1DC,aAAa,CAAmBC,MAAsB,EAA2B;IACpF,MAAMC,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAElC,OAAO,IAAI,CAACG,KAAK,CAACF,GAAG,CAAC,IAAI,IAAI;EAClC;EAEOG,aAAa,CAACJ,MAAsB,EAAEK,UAAgC,EAAQ;IACjF,MAAMJ,GAAG,GAAG,IAAI,CAACC,SAAS,CAACF,MAAM,CAAC;IAClC,IAAI,CAACG,KAAK,CAACF,GAAG,CAAC,GAAGI,UAAU;EAChC;EAEOC,QAAQ,CAACN,MAAuB,EAAQ;IAC3C,IAAI,CAACA,MAAM,EAAE;MACT,KAAK,MAAMO,OAAO,IAAI,IAAI,CAACJ,KAAK,EAAE;QAC9B,IAAI,CAACA,KAAK,CAACI,OAAO,CAAC,CAACD,QAAQ,EAAE;MAClC;MACA;IACJ;IACA,MAAML,GAAG,GAAG,IAAI,CAACC,SAAS,6DACnBF,MAAM;MACTQ,IAAI,EAAE;IAAE,GACV;IACF,KAAK,MAAMD,OAAO,IAAI,IAAI,CAACJ,KAAK,EAAE;MAC9B,IAAII,OAAO,CAACE,UAAU,CAACR,GAAG,CAAC,KAAK,KAAK,EAAE;QACnC;MACJ;MACA,IAAI,CAACE,KAAK,CAACI,OAAO,CAAC,CAACD,QAAQ,EAAE;IAClC;EACJ;EAEQJ,SAAS,CAACF,MAAsB,EAAU;IAC9C,OAAQ,GAAEA,MAAM,CAACU,MAAO,IAAGV,MAAM,CAACW,MAAO,IAAGX,MAAM,CAACQ,IAAK,EAAC;EAC7D;AACJ;AAAC"}
@@ -0,0 +1 @@
1
+ export declare const CMS_ENTRY_BATCH_SCHEDULE_WAIT: number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = void 0;
7
+ const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || "0");
8
+ const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;
9
+ exports.CMS_ENTRY_BATCH_SCHEDULE_WAIT = CMS_ENTRY_BATCH_SCHEDULE_WAIT;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["batchScheduleWaitEnv","Number","process","env","WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT","CMS_ENTRY_BATCH_SCHEDULE_WAIT","isNaN"],"sources":["constants.ts"],"sourcesContent":["const batchScheduleWaitEnv = Number(process.env.WEBINY_API_CMS_ENTRY_BATCH_SCHEDULE_WAIT || \"0\");\nexport const CMS_ENTRY_BATCH_SCHEDULE_WAIT = isNaN(batchScheduleWaitEnv) ? 0 : batchScheduleWaitEnv;\n"],"mappings":";;;;;;AAAA,MAAMA,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,wCAAwC,IAAI,GAAG,CAAC;AACzF,MAAMC,6BAA6B,GAAGC,KAAK,CAACN,oBAAoB,CAAC,GAAG,CAAC,GAAGA,oBAAoB;AAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
3
+ * Intended to be used internally or for a specific user case.
4
+ * Not to be documented and exposed to publish as it can slow the data loading a lot.
5
+ *
6
+ * https://github.com/graphql/dataloader#batch-scheduling
7
+ */
8
+ export declare const createBatchScheduleFn: () => ((callback: () => void) => void) | undefined;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBatchScheduleFn = void 0;
7
+ var _constants = require("./constants");
8
+ /**
9
+ * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.
10
+ * Intended to be used internally or for a specific user case.
11
+ * Not to be documented and exposed to publish as it can slow the data loading a lot.
12
+ *
13
+ * https://github.com/graphql/dataloader#batch-scheduling
14
+ */
15
+ const createBatchScheduleFn = () => {
16
+ if (_constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {
17
+ return undefined;
18
+ }
19
+ return callback => {
20
+ setTimeout(callback, _constants.CMS_ENTRY_BATCH_SCHEDULE_WAIT);
21
+ };
22
+ };
23
+ exports.createBatchScheduleFn = createBatchScheduleFn;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createBatchScheduleFn","CMS_ENTRY_BATCH_SCHEDULE_WAIT","undefined","callback","setTimeout"],"sources":["createBatchScheduleFn.ts"],"sourcesContent":["import { CMS_ENTRY_BATCH_SCHEDULE_WAIT } from \"./constants\";\n\n/**\n * This is to be used when user wants to wait for a number of milliseconds before the batch is executed.\n * Intended to be used internally or for a specific user case.\n * Not to be documented and exposed to publish as it can slow the data loading a lot.\n *\n * https://github.com/graphql/dataloader#batch-scheduling\n */\nexport const createBatchScheduleFn = () => {\n if (CMS_ENTRY_BATCH_SCHEDULE_WAIT <= 0) {\n return undefined;\n }\n return (callback: () => void) => {\n setTimeout(callback, CMS_ENTRY_BATCH_SCHEDULE_WAIT);\n };\n};\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,qBAAqB,GAAG,MAAM;EACvC,IAAIC,wCAA6B,IAAI,CAAC,EAAE;IACpC,OAAOC,SAAS;EACpB;EACA,OAAQC,QAAoB,IAAK;IAC7BC,UAAU,CAACD,QAAQ,EAAEF,wCAA6B,CAAC;EACvD,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import { DataLoaderParams } from "./types";
4
+ export declare const createGetAllEntryRevisions: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetAllEntryRevisions = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _query = require("@webiny/db-dynamodb/utils/query");
10
+ var _keys = require("../keys");
11
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
12
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
13
+ const createGetAllEntryRevisions = params => {
14
+ const {
15
+ entity,
16
+ locale,
17
+ tenant
18
+ } = params;
19
+ return new _dataloader.default(async ids => {
20
+ const results = {};
21
+ for (const id of ids) {
22
+ const queryAllParams = {
23
+ entity,
24
+ partitionKey: (0, _keys.createPartitionKey)({
25
+ tenant,
26
+ locale,
27
+ id
28
+ }),
29
+ options: {
30
+ beginsWith: "REV#"
31
+ }
32
+ };
33
+ const items = await (0, _query.queryAll)(queryAllParams);
34
+ results[id] = (0, _cleanup.cleanupItems)(entity, items);
35
+ }
36
+ return ids.map(entryId => {
37
+ return results[entryId] || [];
38
+ });
39
+ }, {
40
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
41
+ });
42
+ };
43
+ exports.createGetAllEntryRevisions = createGetAllEntryRevisions;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createGetAllEntryRevisions","params","entity","locale","tenant","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","entryId","batchScheduleFn","createBatchScheduleFn"],"sources":["getAllEntryRevisions.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { createPartitionKey } from \"~/operations/entry/keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetAllEntryRevisions = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(entryId => {\n return results[entryId] || [];\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AACA;AAEA;AAEO,MAAMA,0BAA0B,GAAIC,MAAwB,IAAK;EACpE,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAA0C,GAAG,CAAC,CAAC;IACrD,KAAK,MAAMC,EAAE,IAAIF,GAAG,EAAE;MAClB,MAAMG,cAA8B,GAAG;QACnCP,MAAM;QACNQ,YAAY,EAAE,IAAAC,wBAAkB,EAAC;UAC7BP,MAAM;UACND,MAAM;UACNK;QACJ,CAAC,CAAC;QACFI,OAAO,EAAE;UACLC,UAAU,EAAE;QAChB;MACJ,CAAC;MACD,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAQ,EAAkBN,cAAc,CAAC;MAC7DF,OAAO,CAACC,EAAE,CAAC,GAAG,IAAAQ,qBAAY,EAACd,MAAM,EAAEY,KAAK,CAAC;IAC7C;IAEA,OAAOR,GAAG,CAACW,GAAG,CAACC,OAAO,IAAI;MACtB,OAAOX,OAAO,CAACW,OAAO,CAAC,IAAI,EAAE;IACjC,CAAC,CAAC;EACN,CAAC,EACD;IACIC,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import { DataLoaderParams } from "./types";
4
+ export declare const createGetLatestRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetLatestRevisionByEntryId = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
12
+ var _keys = require("../keys");
13
+ const createGetLatestRevisionByEntryId = params => {
14
+ const {
15
+ entity,
16
+ locale,
17
+ tenant
18
+ } = params;
19
+ const latestKey = (0, _keys.createLatestSortKey)();
20
+ return new _dataloader.default(async ids => {
21
+ const queries = ids.reduce((collection, id) => {
22
+ const partitionKey = (0, _keys.createPartitionKey)({
23
+ tenant,
24
+ locale,
25
+ id
26
+ });
27
+ if (collection[partitionKey]) {
28
+ return collection;
29
+ }
30
+ collection[partitionKey] = entity.getBatch({
31
+ PK: partitionKey,
32
+ SK: latestKey
33
+ });
34
+ return collection;
35
+ /**
36
+ * We cast as any because there is no return type defined.
37
+ */
38
+ }, {});
39
+ const records = await (0, _batchRead.batchReadAll)({
40
+ table: entity.table,
41
+ items: Object.values(queries)
42
+ });
43
+ const items = (0, _cleanup.cleanupItems)(entity, records);
44
+ return ids.map(entryId => {
45
+ return items.filter(item => {
46
+ return entryId === item.entryId;
47
+ });
48
+ });
49
+ }, {
50
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
51
+ });
52
+ };
53
+ exports.createGetLatestRevisionByEntryId = createGetLatestRevisionByEntryId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createGetLatestRevisionByEntryId","params","entity","locale","tenant","latestKey","createLatestSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getLatestRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\nimport { createLatestSortKey, createPartitionKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\n\nexport const createGetLatestRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce<Record<string, any>>((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {});\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEA;AACA;AAGO,MAAMA,gCAAgC,GAAIC,MAAwB,IAAK;EAC1E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,SAAS,GAAG,IAAAC,yBAAmB,GAAE;EAEvC,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAsB,CAACC,UAAU,EAAEC,EAAE,KAAK;MAChE,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCV,MAAM;QACND,MAAM;QACNS;MACJ,CAAC,CAAC;MACF,IAAID,UAAU,CAACE,YAAY,CAAC,EAAE;QAC1B,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,YAAY,CAAC,GAAGX,MAAM,CAACa,QAAQ,CAAC;QACvCC,EAAE,EAAEH,YAAY;QAChBI,EAAE,EAAEZ;MACR,CAAC,CAAC;MACF,OAAOM,UAAU;MACjB;AAChB;AACA;IACY,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,MAAMO,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAElB,MAAM,CAACkB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACd,OAAO;IAChC,CAAC,CAAC;IACF,MAAMY,KAAK,GAAG,IAAAG,qBAAY,EAACtB,MAAM,EAAEgB,OAAO,CAAC;IAE3C,OAAOV,GAAG,CAACiB,GAAG,CAACC,OAAO,IAAI;MACtB,OAAOL,KAAK,CAACM,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOF,OAAO,KAAKE,IAAI,CAACF,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIG,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
@@ -0,0 +1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import { DataLoaderParams } from "./types";
4
+ export declare const createGetPublishedRevisionByEntryId: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetPublishedRevisionByEntryId = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _keys = require("../keys");
12
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
13
+ const createGetPublishedRevisionByEntryId = params => {
14
+ const {
15
+ entity,
16
+ locale,
17
+ tenant
18
+ } = params;
19
+ const publishedKey = (0, _keys.createPublishedSortKey)();
20
+ return new _dataloader.default(async ids => {
21
+ const queries = ids.reduce((collection, id) => {
22
+ const partitionKey = (0, _keys.createPartitionKey)({
23
+ tenant,
24
+ locale,
25
+ id
26
+ });
27
+ if (collection[partitionKey]) {
28
+ return collection;
29
+ }
30
+ collection[partitionKey] = entity.getBatch({
31
+ PK: partitionKey,
32
+ SK: publishedKey
33
+ });
34
+ return collection;
35
+ /**
36
+ * We cast as any because there is no return type defined.
37
+ */
38
+ }, {});
39
+ const records = await (0, _batchRead.batchReadAll)({
40
+ table: entity.table,
41
+ items: Object.values(queries)
42
+ });
43
+ const items = (0, _cleanup.cleanupItems)(entity, records);
44
+ return ids.map(entryId => {
45
+ return items.filter(item => {
46
+ return entryId === item.entryId;
47
+ });
48
+ });
49
+ }, {
50
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
51
+ });
52
+ };
53
+ exports.createGetPublishedRevisionByEntryId = createGetPublishedRevisionByEntryId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createGetPublishedRevisionByEntryId","params","entity","locale","tenant","publishedKey","createPublishedSortKey","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","entryId","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetPublishedRevisionByEntryId = (params: DataLoaderParams) => {\n const { entity, locale, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(entryId => {\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()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+1,4 @@
1
+ import DataLoader from "dataloader";
2
+ import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
3
+ import { DataLoaderParams } from "./types";
4
+ export declare const createGetRevisionById: (params: DataLoaderParams) => DataLoader<string, CmsStorageEntry[], string>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createGetRevisionById = void 0;
8
+ var _dataloader = _interopRequireDefault(require("dataloader"));
9
+ var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
10
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
+ var _keys = require("../keys");
12
+ var _utils = require("@webiny/utils");
13
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
14
+ const createGetRevisionById = params => {
15
+ const {
16
+ entity,
17
+ tenant,
18
+ locale
19
+ } = params;
20
+ return new _dataloader.default(async ids => {
21
+ const queries = ids.reduce((collection, id) => {
22
+ const partitionKey = (0, _keys.createPartitionKey)({
23
+ tenant,
24
+ locale,
25
+ id
26
+ });
27
+ const {
28
+ version
29
+ } = (0, _utils.parseIdentifier)(id);
30
+ if (version === null) {
31
+ return collection;
32
+ }
33
+ const sortKey = (0, _keys.createRevisionSortKey)({
34
+ version
35
+ });
36
+ const keys = `${partitionKey}__${sortKey}`;
37
+ if (collection[keys]) {
38
+ return collection;
39
+ }
40
+ collection[keys] = entity.getBatch({
41
+ PK: partitionKey,
42
+ SK: sortKey
43
+ });
44
+ return collection;
45
+ /**
46
+ * We cast as any because there is no return type defined.
47
+ */
48
+ }, {});
49
+ const records = await (0, _batchRead.batchReadAll)({
50
+ table: entity.table,
51
+ items: Object.values(queries)
52
+ });
53
+ const items = (0, _cleanup.cleanupItems)(entity, records);
54
+ return ids.map(id => {
55
+ return items.filter(item => {
56
+ return id === item.id;
57
+ });
58
+ });
59
+ }, {
60
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
61
+ });
62
+ };
63
+ exports.createGetRevisionById = createGetRevisionById;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createGetRevisionById","params","entity","tenant","locale","DataLoader","ids","queries","reduce","collection","id","partitionKey","createPartitionKey","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","items","Object","values","cleanupItems","map","filter","item","batchScheduleFn","createBatchScheduleFn"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys\";\nimport { DataLoaderParams } from \"./types\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn\";\n\nexport const createGetRevisionById = (params: DataLoaderParams) => {\n const { entity, tenant, locale } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AACA;AAEA;AACA;AAE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EAAE,KAAKoB,IAAI,CAACpB,EAAE;MACzB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACIqB,eAAe,EAAE,IAAAC,4CAAqB;EAC1C,CAAC,CACJ;AACL,CAAC;AAAC"}
@@ -0,0 +1,8 @@
1
+ import DataLoader from "dataloader";
2
+ import { DataLoaderParams } from "./types";
3
+ export * from "./DataLoaderCache";
4
+ interface Callable {
5
+ (params: DataLoaderParams): DataLoader<any, any>;
6
+ }
7
+ export declare type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
8
+ export declare const getDataLoaderFactory: (name: string) => Callable;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ getDataLoaderFactory: true
8
+ };
9
+ exports.getDataLoaderFactory = void 0;
10
+ var _getAllEntryRevisions = require("./getAllEntryRevisions");
11
+ var _getLatestRevisionByEntryId = require("./getLatestRevisionByEntryId");
12
+ var _getPublishedRevisionByEntryId = require("./getPublishedRevisionByEntryId");
13
+ var _getRevisionById = require("./getRevisionById");
14
+ var _DataLoaderCache = require("./DataLoaderCache");
15
+ Object.keys(_DataLoaderCache).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
18
+ if (key in exports && exports[key] === _DataLoaderCache[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _DataLoaderCache[key];
23
+ }
24
+ });
25
+ });
26
+ const dataLoaders = {
27
+ getAllEntryRevisions: _getAllEntryRevisions.createGetAllEntryRevisions,
28
+ getLatestRevisionByEntryId: _getLatestRevisionByEntryId.createGetLatestRevisionByEntryId,
29
+ getPublishedRevisionByEntryId: _getPublishedRevisionByEntryId.createGetPublishedRevisionByEntryId,
30
+ getRevisionById: _getRevisionById.createGetRevisionById
31
+ };
32
+ const getDataLoaderFactory = name => {
33
+ if (!dataLoaders[name]) {
34
+ throw new Error(`Missing data loader "${name}".`);
35
+ }
36
+ return dataLoaders[name];
37
+ };
38
+ exports.getDataLoaderFactory = getDataLoaderFactory;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["dataLoaders","getAllEntryRevisions","createGetAllEntryRevisions","getLatestRevisionByEntryId","createGetLatestRevisionByEntryId","getPublishedRevisionByEntryId","createGetPublishedRevisionByEntryId","getRevisionById","createGetRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { DataLoaderParams } from \"./types\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId\";\nimport { createGetRevisionById } from \"./getRevisionById\";\n\nexport * from \"./DataLoaderCache\";\n\ninterface Callable {\n (params: DataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":";;;;;;;;;AAEA;AACA;AACA;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAMA,MAAMA,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEC,gDAA0B;EAChDC,0BAA0B,EAAEC,4DAAgC;EAC5DC,6BAA6B,EAAEC,kEAAmC;EAClEC,eAAe,EAAEC;AACrB,CAAC;AAQM,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACV,WAAW,CAACU,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAE,wBAAuBD,IAAK,IAAG,CAAC;EACrD;EACA,OAAOV,WAAW,CAACU,IAAI,CAAC;AAC5B,CAAC;AAAC"}
@@ -0,0 +1,6 @@
1
+ import { Entity } from "dynamodb-toolbox";
2
+ export interface DataLoaderParams {
3
+ entity: Entity<any>;
4
+ tenant: string;
5
+ locale: string;
6
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\n\nexport interface DataLoaderParams {\n entity: Entity<any>;\n tenant: string;\n locale: string;\n}\n"],"mappings":""}