@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f

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 (168) hide show
  1. package/definitions/entry.d.ts +2 -1
  2. package/definitions/entry.js +12 -12
  3. package/definitions/entry.js.map +1 -0
  4. package/definitions/group.d.ts +2 -1
  5. package/definitions/group.js +3 -12
  6. package/definitions/group.js.map +1 -0
  7. package/definitions/model.d.ts +2 -1
  8. package/definitions/model.js +25 -12
  9. package/definitions/model.js.map +1 -0
  10. package/definitions/settings.d.ts +2 -1
  11. package/definitions/settings.js +3 -12
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/system.d.ts +2 -1
  14. package/definitions/system.js +3 -12
  15. package/definitions/system.js.map +1 -0
  16. package/definitions/table.d.ts +2 -1
  17. package/definitions/table.js +0 -3
  18. package/definitions/table.js.map +1 -0
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +7 -17
  21. package/dynamoDb/index.js.map +1 -0
  22. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  23. package/dynamoDb/path/locationFolderId.js +41 -0
  24. package/dynamoDb/path/locationFolderId.js.map +1 -0
  25. package/dynamoDb/path/plainObject.d.ts +2 -3
  26. package/dynamoDb/path/plainObject.js +25 -25
  27. package/dynamoDb/path/plainObject.js.map +1 -0
  28. package/dynamoDb/storage/date.d.ts +3 -3
  29. package/dynamoDb/storage/date.js +71 -54
  30. package/dynamoDb/storage/date.js.map +1 -0
  31. package/dynamoDb/storage/longText.d.ts +7 -4
  32. package/dynamoDb/storage/longText.js +72 -64
  33. package/dynamoDb/storage/longText.js.map +1 -0
  34. package/dynamoDb/storage/richText.d.ts +2 -8
  35. package/dynamoDb/storage/richText.js +62 -77
  36. package/dynamoDb/storage/richText.js.map +1 -0
  37. package/dynamoDb/transformValue/datetime.d.ts +4 -2
  38. package/dynamoDb/transformValue/datetime.js +28 -30
  39. package/dynamoDb/transformValue/datetime.js.map +1 -0
  40. package/index.d.ts +1 -0
  41. package/index.js +54 -45
  42. package/index.js.map +1 -0
  43. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  44. package/operations/entry/dataLoader/DataLoaderCache.js +43 -0
  45. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  46. package/operations/entry/dataLoader/constants.d.ts +1 -0
  47. package/operations/entry/dataLoader/constants.js +9 -0
  48. package/operations/entry/dataLoader/constants.js.map +1 -0
  49. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  50. package/operations/entry/dataLoader/createBatchScheduleFn.js +23 -0
  51. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  52. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  53. package/operations/entry/dataLoader/getAllEntryRevisions.js +43 -0
  54. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  55. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  56. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +57 -0
  57. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  58. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  59. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +57 -0
  60. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  61. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  62. package/operations/entry/dataLoader/getRevisionById.js +63 -0
  63. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  64. package/operations/entry/dataLoader/index.d.ts +8 -0
  65. package/operations/entry/dataLoader/index.js +38 -0
  66. package/operations/entry/dataLoader/index.js.map +1 -0
  67. package/operations/entry/dataLoader/types.d.ts +6 -0
  68. package/operations/entry/dataLoader/types.js +5 -0
  69. package/operations/entry/dataLoader/types.js.map +1 -0
  70. package/operations/entry/dataLoaders.d.ts +17 -28
  71. package/operations/entry/dataLoaders.js +51 -239
  72. package/operations/entry/dataLoaders.js.map +1 -0
  73. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  74. package/operations/entry/filtering/createExpressions.js +176 -0
  75. package/operations/entry/filtering/createExpressions.js.map +1 -0
  76. package/operations/entry/filtering/createFields.d.ts +16 -0
  77. package/operations/entry/filtering/createFields.js +105 -0
  78. package/operations/entry/filtering/createFields.js.map +1 -0
  79. package/operations/entry/filtering/extractSort.d.ts +17 -0
  80. package/operations/entry/filtering/extractSort.js +67 -0
  81. package/operations/entry/filtering/extractSort.js.map +1 -0
  82. package/operations/entry/filtering/filter.d.ts +15 -0
  83. package/operations/entry/filtering/filter.js +143 -0
  84. package/operations/entry/filtering/filter.js.map +1 -0
  85. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  86. package/operations/entry/filtering/fullTextSearch.js +48 -0
  87. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  88. package/operations/entry/filtering/getValue.d.ts +5 -0
  89. package/operations/entry/filtering/getValue.js +63 -0
  90. package/operations/entry/filtering/getValue.js.map +1 -0
  91. package/operations/entry/filtering/index.d.ts +2 -0
  92. package/operations/entry/filtering/index.js +19 -0
  93. package/operations/entry/filtering/index.js.map +1 -0
  94. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  95. package/operations/entry/filtering/mapPlugins.js +31 -0
  96. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  97. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  98. package/operations/entry/filtering/plugins/defaultFilterCreate.js +43 -0
  99. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  100. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  101. package/operations/entry/filtering/plugins/index.js +13 -0
  102. package/operations/entry/filtering/plugins/index.js.map +1 -0
  103. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  104. package/operations/entry/filtering/plugins/objectFilterCreate.js +88 -0
  105. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  106. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  107. package/operations/entry/filtering/plugins/refFilterCreate.js +73 -0
  108. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  109. package/operations/entry/filtering/sort.d.ts +12 -0
  110. package/operations/entry/filtering/sort.js +69 -0
  111. package/operations/entry/filtering/sort.js.map +1 -0
  112. package/operations/entry/filtering/systemFields.d.ts +4 -0
  113. package/operations/entry/filtering/systemFields.js +88 -0
  114. package/operations/entry/filtering/systemFields.js.map +1 -0
  115. package/operations/entry/filtering/transform.d.ts +6 -0
  116. package/operations/entry/filtering/transform.js +16 -0
  117. package/operations/entry/filtering/transform.js.map +1 -0
  118. package/operations/entry/filtering/types.d.ts +40 -0
  119. package/operations/entry/filtering/types.js +5 -0
  120. package/operations/entry/filtering/types.js.map +1 -0
  121. package/operations/entry/filtering/values.d.ts +2 -0
  122. package/operations/entry/filtering/values.js +22 -0
  123. package/operations/entry/filtering/values.js.map +1 -0
  124. package/operations/entry/filtering/where.d.ts +5 -0
  125. package/operations/entry/filtering/where.js +33 -0
  126. package/operations/entry/filtering/where.js.map +1 -0
  127. package/operations/entry/index.d.ts +3 -3
  128. package/operations/entry/index.js +425 -330
  129. package/operations/entry/index.js.map +1 -0
  130. package/operations/entry/keys.js +7 -14
  131. package/operations/entry/keys.js.map +1 -0
  132. package/operations/group/index.d.ts +3 -2
  133. package/operations/group/index.js +9 -45
  134. package/operations/group/index.js.map +1 -0
  135. package/operations/model/index.d.ts +3 -2
  136. package/operations/model/index.js +13 -37
  137. package/operations/model/index.js.map +1 -0
  138. package/operations/settings/index.d.ts +3 -2
  139. package/operations/settings/index.js +7 -37
  140. package/operations/settings/index.js.map +1 -0
  141. package/operations/system/index.d.ts +3 -2
  142. package/operations/system/index.js +5 -28
  143. package/operations/system/index.js.map +1 -0
  144. package/package.json +25 -26
  145. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
  146. package/plugins/CmsEntryFieldFilterPathPlugin.js +43 -0
  147. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  148. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  149. package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
  150. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  151. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  152. package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
  153. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  154. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  155. package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
  156. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  157. package/plugins/index.d.ts +4 -0
  158. package/plugins/index.js +49 -0
  159. package/plugins/index.js.map +1 -0
  160. package/types.d.ts +11 -33
  161. package/types.js +0 -1
  162. package/types.js.map +1 -0
  163. package/dynamoDb/path/ref.d.ts +0 -3
  164. package/dynamoDb/path/ref.js +0 -27
  165. package/operations/entry/systemFields.d.ts +0 -2
  166. package/operations/entry/systemFields.js +0 -50
  167. package/operations/entry/utils.d.ts +0 -31
  168. package/operations/entry/utils.js +0 -406
package/index.js CHANGED
@@ -1,49 +1,49 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
7
+ var _exportNames = {
8
+ createStorageOperations: true
9
+ };
8
10
  exports.createStorageOperations = void 0;
9
-
10
11
  var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
11
-
12
12
  var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
13
-
14
13
  var _types = require("./types");
15
-
16
14
  var _table = require("./definitions/table");
17
-
18
15
  var _settings = require("./definitions/settings");
19
-
20
16
  var _system = require("./definitions/system");
21
-
22
17
  var _group = require("./definitions/group");
23
-
24
18
  var _model = require("./definitions/model");
25
-
26
19
  var _entry = require("./definitions/entry");
27
-
28
20
  var _plugins = require("@webiny/plugins");
29
-
30
21
  var _system2 = require("./operations/system");
31
-
32
22
  var _settings2 = require("./operations/settings");
33
-
34
23
  var _group2 = require("./operations/group");
35
-
36
24
  var _model2 = require("./operations/model");
37
-
38
25
  var _entry2 = require("./operations/entry");
39
-
26
+ var _plugins2 = require("./operations/entry/filtering/plugins");
27
+ var _plugins3 = require("./plugins");
28
+ Object.keys(_plugins3).forEach(function (key) {
29
+ if (key === "default" || key === "__esModule") return;
30
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
+ if (key in exports && exports[key] === _plugins3[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _plugins3[key];
36
+ }
37
+ });
38
+ });
39
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
40
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
40
41
  const createStorageOperations = params => {
41
42
  const {
42
- attributes = {},
43
+ attributes,
43
44
  table,
44
45
  documentClient,
45
- plugins: customPlugins,
46
- modelFieldToGraphQLPlugins
46
+ plugins: userPlugins
47
47
  } = params;
48
48
  const tableInstance = (0, _table.createTable)({
49
49
  table,
@@ -53,53 +53,66 @@ const createStorageOperations = params => {
53
53
  settings: (0, _settings.createSettingsEntity)({
54
54
  entityName: _types.ENTITIES.SETTINGS,
55
55
  table: tableInstance,
56
- attributes: attributes[_types.ENTITIES.SETTINGS]
56
+ attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
57
57
  }),
58
58
  system: (0, _system.createSystemEntity)({
59
59
  entityName: _types.ENTITIES.SYSTEM,
60
60
  table: tableInstance,
61
- attributes: attributes[_types.ENTITIES.SYSTEM]
61
+ attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
62
62
  }),
63
63
  groups: (0, _group.createGroupEntity)({
64
64
  entityName: _types.ENTITIES.GROUPS,
65
65
  table: tableInstance,
66
- attributes: attributes[_types.ENTITIES.GROUPS]
66
+ attributes: attributes ? attributes[_types.ENTITIES.GROUPS] : {}
67
67
  }),
68
68
  models: (0, _model.createModelEntity)({
69
69
  entityName: _types.ENTITIES.MODELS,
70
70
  table: tableInstance,
71
- attributes: attributes[_types.ENTITIES.MODELS]
71
+ attributes: attributes ? attributes[_types.ENTITIES.MODELS] : {}
72
72
  }),
73
73
  entries: (0, _entry.createEntryEntity)({
74
74
  entityName: _types.ENTITIES.ENTRIES,
75
75
  table: tableInstance,
76
- attributes: attributes[_types.ENTITIES.ENTRIES]
76
+ attributes: attributes ? attributes[_types.ENTITIES.ENTRIES] : {}
77
77
  })
78
78
  };
79
79
  const plugins = new _plugins.PluginsContainer([
80
80
  /**
81
- * User defined custom plugins.
81
+ * DynamoDB filter plugins for the where conditions.
82
82
  */
83
- ...(customPlugins || []),
83
+ (0, _filters.default)(),
84
84
  /**
85
- * Plugins of type CmsModelFieldToGraphQLPlugin.
85
+ * Field plugins for DynamoDB.
86
86
  */
87
- modelFieldToGraphQLPlugins,
87
+ (0, _dynamoDb.default)(),
88
88
  /**
89
- * DynamoDB filter plugins for the where conditions.
89
+ * Filter create plugins.
90
90
  */
91
- (0, _filters.default)(),
91
+ (0, _plugins2.createFilterCreatePlugins)(),
92
92
  /**
93
- * Field plugins for DynamoDB.
93
+ * User defined custom plugins.
94
94
  */
95
- (0, _dynamoDb.default)()]);
95
+ ...(userPlugins || [])]);
96
+ const entries = (0, _entry2.createEntriesStorageOperations)({
97
+ entity: entities.entries,
98
+ plugins
99
+ });
96
100
  return {
97
- plugins: [
98
- /**
99
- * Field plugins for DynamoDB.
100
- * We must pass them to the base application.
101
- */
102
- (0, _dynamoDb.default)()],
101
+ name: "dynamodb",
102
+ beforeInit: async context => {
103
+ const types = ["cms-model-field-to-graphql", _plugins3.CmsEntryFieldFilterPathPlugin.type, _plugins3.CmsFieldFilterValueTransformPlugin.type, _plugins3.CmsEntryFieldFilterPlugin.type, _plugins3.CmsEntryFieldSortingPlugin.type, _ValueFilterPlugin.ValueFilterPlugin.type, _apiHeadlessCms.StorageOperationsCmsModelPlugin.type];
104
+ /**
105
+ * Collect all required plugins from parent context.
106
+ */
107
+ for (const type of types) {
108
+ plugins.mergeByType(context.plugins, type);
109
+ }
110
+ /**
111
+ * Pass the plugins to the parent context.
112
+ */
113
+ context.plugins.register([(0, _dynamoDb.default)()]);
114
+ entries.dataLoaders.clearAll();
115
+ },
103
116
  getEntities: () => entities,
104
117
  getTable: () => tableInstance,
105
118
  system: (0, _system2.createSystemStorageOperations)({
@@ -115,11 +128,7 @@ const createStorageOperations = params => {
115
128
  models: (0, _model2.createModelsStorageOperations)({
116
129
  entity: entities.models
117
130
  }),
118
- entries: (0, _entry2.createEntriesStorageOperations)({
119
- entity: entities.entries,
120
- plugins
121
- })
131
+ entries
122
132
  };
123
133
  };
124
-
125
134
  exports.createStorageOperations = createStorageOperations;
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createStorageOperations","params","attributes","table","documentClient","plugins","userPlugins","tableInstance","createTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","createFilterCreatePlugins","createEntriesStorageOperations","entity","name","beforeInit","context","types","CmsEntryFieldFilterPathPlugin","type","CmsFieldFilterValueTransformPlugin","CmsEntryFieldFilterPlugin","CmsEntryFieldSortingPlugin","ValueFilterPlugin","StorageOperationsCmsModelPlugin","mergeByType","register","dataLoaders","clearAll","getEntities","getTable","createSystemStorageOperations","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { createModelsStorageOperations } from \"~/operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\n\nimport { createFilterCreatePlugins } from \"~/operations/entry/filtering/plugins\";\nimport {\n CmsEntryFieldFilterPathPlugin,\n CmsEntryFieldFilterPlugin,\n CmsEntryFieldSortingPlugin,\n CmsFieldFilterValueTransformPlugin\n} from \"~/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const { attributes, table, documentClient, plugins: userPlugins } = params;\n\n const tableInstance = createTable({\n table,\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 };\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 * Filter create plugins.\n */\n createFilterCreatePlugins(),\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || [])\n ]);\n\n const entries = createEntriesStorageOperations({\n entity: entities.entries,\n plugins\n });\n\n return {\n name: \"dynamodb\",\n beforeInit: async context => {\n const types: string[] = [\n \"cms-model-field-to-graphql\",\n CmsEntryFieldFilterPathPlugin.type,\n CmsFieldFilterValueTransformPlugin.type,\n CmsEntryFieldFilterPlugin.type,\n CmsEntryFieldSortingPlugin.type,\n ValueFilterPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n /**\n * Collect all required plugins from parent context.\n */\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n\n entries.dataLoaders.clearAll();\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\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 }),\n entries\n };\n};\n"],"mappings":"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"}
@@ -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(id => {
37
+ return results[id] || [];
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","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(id => {\n return results[id] || [];\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,CAACT,EAAE,IAAI;MACjB,OAAOD,OAAO,CAACC,EAAE,CAAC,IAAI,EAAE;IAC5B,CAAC,CAAC;EACN,CAAC,EACD;IACIU,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,57 @@
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
+ var _utils = require("@webiny/utils");
14
+ const createGetLatestRevisionByEntryId = params => {
15
+ const {
16
+ entity,
17
+ locale,
18
+ tenant
19
+ } = params;
20
+ const latestKey = (0, _keys.createLatestSortKey)();
21
+ return new _dataloader.default(async ids => {
22
+ const queries = ids.reduce((collection, id) => {
23
+ const partitionKey = (0, _keys.createPartitionKey)({
24
+ tenant,
25
+ locale,
26
+ id
27
+ });
28
+ if (collection[partitionKey]) {
29
+ return collection;
30
+ }
31
+ collection[partitionKey] = entity.getBatch({
32
+ PK: partitionKey,
33
+ SK: latestKey
34
+ });
35
+ return collection;
36
+ /**
37
+ * We cast as any because there is no return type defined.
38
+ */
39
+ }, {});
40
+ const records = await (0, _batchRead.batchReadAll)({
41
+ table: entity.table,
42
+ items: Object.values(queries)
43
+ });
44
+ const items = (0, _cleanup.cleanupItems)(entity, records);
45
+ return ids.map(id => {
46
+ const {
47
+ id: entryId
48
+ } = (0, _utils.parseIdentifier)(id);
49
+ return items.filter(item => {
50
+ return entryId === item.entryId;
51
+ });
52
+ });
53
+ }, {
54
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
55
+ });
56
+ };
57
+ 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","parseIdentifier","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\";\nimport { parseIdentifier } from \"@webiny/utils\";\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(id => {\n const { id: entryId } = parseIdentifier(id);\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;AAEA;AAEO,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,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,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,57 @@
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 _utils = require("@webiny/utils");
13
+ var _createBatchScheduleFn = require("./createBatchScheduleFn");
14
+ const createGetPublishedRevisionByEntryId = params => {
15
+ const {
16
+ entity,
17
+ locale,
18
+ tenant
19
+ } = params;
20
+ const publishedKey = (0, _keys.createPublishedSortKey)();
21
+ return new _dataloader.default(async ids => {
22
+ const queries = ids.reduce((collection, id) => {
23
+ const partitionKey = (0, _keys.createPartitionKey)({
24
+ tenant,
25
+ locale,
26
+ id
27
+ });
28
+ if (collection[partitionKey]) {
29
+ return collection;
30
+ }
31
+ collection[partitionKey] = entity.getBatch({
32
+ PK: partitionKey,
33
+ SK: publishedKey
34
+ });
35
+ return collection;
36
+ /**
37
+ * We cast as any because there is no return type defined.
38
+ */
39
+ }, {});
40
+ const records = await (0, _batchRead.batchReadAll)({
41
+ table: entity.table,
42
+ items: Object.values(queries)
43
+ });
44
+ const items = (0, _cleanup.cleanupItems)(entity, records);
45
+ return ids.map(id => {
46
+ const {
47
+ id: entryId
48
+ } = (0, _utils.parseIdentifier)(id);
49
+ return items.filter(item => {
50
+ return entryId === item.entryId;
51
+ });
52
+ });
53
+ }, {
54
+ batchScheduleFn: (0, _createBatchScheduleFn.createBatchScheduleFn)()
55
+ });
56
+ };
57
+ 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","parseIdentifier","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 { parseIdentifier } from \"@webiny/utils\";\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(id => {\n const { id: entryId } = parseIdentifier(id);\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;AAEA;AACA;AAEO,MAAMA,mCAAmC,GAAIC,MAAwB,IAAK;EAC7E,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,MAAMI,YAAY,GAAG,IAAAC,4BAAsB,GAAE;EAC7C,OAAO,IAAIC,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAC,CAACC,UAAU,EAAEC,EAAE,KAAK;MAC3C,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,CAAwB;IAE7B,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,CAACb,EAAE,IAAI;MACjB,MAAM;QAAEA,EAAE,EAAEc;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACf,EAAE,CAAC;MAC3C,OAAOS,KAAK,CAACO,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOH,OAAO,KAAKG,IAAI,CAACH,OAAO;MACnC,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,EACD;IACII,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 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
+ locale,
18
+ tenant
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","locale","tenant","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, locale, tenant } = 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;AAEO,MAAMA,qBAAqB,GAAIC,MAAwB,IAAK;EAC/D,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGH,MAAM;EAEzC,OAAO,IAAII,mBAAU,CACjB,MAAOC,GAAsB,IAAK;IAC9B,MAAMC,OAAO,GAAGD,GAAG,CAACE,MAAM,CAAC,CAACC,UAAU,EAAEC,EAAE,KAAK;MAC3C,MAAMC,YAAY,GAAG,IAAAC,wBAAkB,EAAC;QACpCR,MAAM;QACND,MAAM;QACNO;MACJ,CAAC,CAAC;MACF,MAAM;QAAEG;MAAQ,CAAC,GAAG,IAAAC,sBAAe,EAACJ,EAAE,CAAC;MACvC,IAAIG,OAAO,KAAK,IAAI,EAAE;QAClB,OAAOJ,UAAU;MACrB;MACA,MAAMM,OAAO,GAAG,IAAAC,2BAAqB,EAAC;QAClCH;MACJ,CAAC,CAAC;MACF,MAAMI,IAAI,GAAI,GAAEN,YAAa,KAAII,OAAQ,EAAC;MAC1C,IAAIN,UAAU,CAACQ,IAAI,CAAC,EAAE;QAClB,OAAOR,UAAU;MACrB;MAEAA,UAAU,CAACQ,IAAI,CAAC,GAAGf,MAAM,CAACgB,QAAQ,CAAC;QAC/BC,EAAE,EAAER,YAAY;QAChBS,EAAE,EAAEL;MACR,CAAC,CAAC;MAEF,OAAON,UAAU;MACjB;AAChB;AACA;IACY,CAAC,EAAE,CAAC,CAAC,CAAwB;IAE7B,MAAMY,OAAO,GAAG,MAAM,IAAAC,uBAAY,EAAkB;MAChDC,KAAK,EAAErB,MAAM,CAACqB,KAAK;MACnBC,KAAK,EAAEC,MAAM,CAACC,MAAM,CAACnB,OAAO;IAChC,CAAC,CAAC;IACF,MAAMiB,KAAK,GAAG,IAAAG,qBAAY,EAACzB,MAAM,EAAEmB,OAAO,CAAC;IAE3C,OAAOf,GAAG,CAACsB,GAAG,CAAClB,EAAE,IAAI;MACjB,OAAOc,KAAK,CAACK,MAAM,CAACC,IAAI,IAAI;QACxB,OAAOpB,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;