@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.3386f66516

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 (243) hide show
  1. package/configurations.d.ts +2 -2
  2. package/configurations.js +18 -7
  3. package/configurations.js.map +1 -0
  4. package/definitions/entry.d.ts +2 -2
  5. package/definitions/entry.js +6 -7
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +3 -7
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +3 -7
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +8 -7
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +3 -7
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +3 -7
  21. package/definitions/system.js.map +1 -0
  22. package/definitions/table.d.ts +2 -2
  23. package/definitions/table.js.map +1 -0
  24. package/definitions/tableElasticsearch.d.ts +2 -2
  25. package/definitions/tableElasticsearch.js.map +1 -0
  26. package/dynamoDb/index.d.ts +1 -1
  27. package/dynamoDb/index.js +4 -6
  28. package/dynamoDb/index.js.map +1 -0
  29. package/dynamoDb/storage/date.d.ts +3 -3
  30. package/dynamoDb/storage/date.js +80 -46
  31. package/dynamoDb/storage/date.js.map +1 -0
  32. package/dynamoDb/storage/longText.d.ts +7 -4
  33. package/dynamoDb/storage/longText.js +79 -54
  34. package/dynamoDb/storage/longText.js.map +1 -0
  35. package/dynamoDb/storage/richText.d.ts +2 -3
  36. package/dynamoDb/storage/richText.js +85 -67
  37. package/dynamoDb/storage/richText.js.map +1 -0
  38. package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
  39. package/elasticsearch/createElasticsearchIndex.js +60 -0
  40. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  41. package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
  42. package/elasticsearch/deleteElasticsearchIndex.js +43 -0
  43. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
  44. package/elasticsearch/index.d.ts +1 -1
  45. package/elasticsearch/index.js +1 -1
  46. package/elasticsearch/index.js.map +1 -0
  47. package/elasticsearch/indexing/dateTimeIndexing.js +15 -1
  48. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  49. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  50. package/elasticsearch/indexing/index.js +1 -1
  51. package/elasticsearch/indexing/index.js.map +1 -0
  52. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  53. package/elasticsearch/indexing/longTextIndexing.js +20 -4
  54. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  55. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  56. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  57. package/elasticsearch/indexing/objectIndexing.js +32 -9
  58. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  59. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  60. package/elasticsearch/indices/base.d.ts +2 -0
  61. package/elasticsearch/indices/base.js +15 -0
  62. package/elasticsearch/indices/base.js.map +1 -0
  63. package/elasticsearch/indices/index.d.ts +1 -0
  64. package/elasticsearch/indices/index.js +16 -0
  65. package/elasticsearch/indices/index.js.map +1 -0
  66. package/elasticsearch/indices/japanese.d.ts +2 -0
  67. package/elasticsearch/indices/japanese.js +16 -0
  68. package/elasticsearch/indices/japanese.js.map +1 -0
  69. package/elasticsearch/search/index.d.ts +2 -2
  70. package/elasticsearch/search/index.js +3 -5
  71. package/elasticsearch/search/index.js.map +1 -0
  72. package/elasticsearch/search/refSearch.d.ts +2 -3
  73. package/elasticsearch/search/refSearch.js +27 -16
  74. package/elasticsearch/search/refSearch.js.map +1 -0
  75. package/elasticsearch/search/timeSearch.d.ts +2 -3
  76. package/elasticsearch/search/timeSearch.js +22 -14
  77. package/elasticsearch/search/timeSearch.js.map +1 -0
  78. package/helpers/entryIndexHelpers.js +33 -18
  79. package/helpers/entryIndexHelpers.js.map +1 -0
  80. package/helpers/index.d.ts +0 -1
  81. package/helpers/index.js +0 -13
  82. package/helpers/index.js.map +1 -0
  83. package/index.d.ts +1 -0
  84. package/index.js +132 -34
  85. package/index.js.map +1 -0
  86. package/operations/entry/dataLoaders.d.ts +6 -2
  87. package/operations/entry/dataLoaders.js +31 -13
  88. package/operations/entry/dataLoaders.js.map +1 -0
  89. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  90. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
  91. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  92. package/operations/entry/elasticsearch/body.d.ts +13 -0
  93. package/operations/entry/elasticsearch/body.js +162 -0
  94. package/operations/entry/elasticsearch/body.js.map +1 -0
  95. package/operations/entry/elasticsearch/fields.d.ts +9 -0
  96. package/operations/entry/elasticsearch/fields.js +248 -0
  97. package/operations/entry/elasticsearch/fields.js.map +1 -0
  98. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  99. package/operations/entry/elasticsearch/filtering/applyFiltering.js +66 -0
  100. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  101. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  102. package/operations/entry/elasticsearch/filtering/exec.js +215 -0
  103. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  104. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  105. package/operations/entry/elasticsearch/filtering/index.js +18 -0
  106. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  107. package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
  108. package/operations/entry/elasticsearch/filtering/path.js +52 -0
  109. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  110. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  111. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +35 -0
  112. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  113. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  114. package/operations/entry/elasticsearch/filtering/plugins/index.js +18 -0
  115. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  116. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  117. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +78 -0
  118. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  119. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  120. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +58 -0
  121. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  122. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  123. package/operations/entry/elasticsearch/filtering/populated.js +30 -0
  124. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  125. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  126. package/operations/entry/elasticsearch/filtering/values.js +28 -0
  127. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  128. package/operations/entry/elasticsearch/fullTextSearch.d.ts +9 -0
  129. package/operations/entry/elasticsearch/fullTextSearch.js +34 -0
  130. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  131. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  132. package/operations/entry/elasticsearch/fullTextSearchFields.js +52 -0
  133. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  134. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  135. package/operations/entry/elasticsearch/initialQuery.js +117 -0
  136. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  137. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  138. package/operations/entry/elasticsearch/keyword.js +38 -0
  139. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  140. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  141. package/operations/entry/elasticsearch/plugins/bodyModifier.js +19 -0
  142. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  143. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  144. package/operations/entry/elasticsearch/plugins/operator.js +45 -0
  145. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  146. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  147. package/operations/entry/elasticsearch/plugins/queryModifier.js +19 -0
  148. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  149. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  150. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +9 -5
  151. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  152. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  153. package/operations/entry/elasticsearch/plugins/sortModifier.js +19 -0
  154. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  155. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  156. package/operations/entry/elasticsearch/sort.js +97 -0
  157. package/operations/entry/elasticsearch/sort.js.map +1 -0
  158. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  159. package/operations/entry/elasticsearch/transformValueForSearch.js +34 -0
  160. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  161. package/operations/entry/elasticsearch/types.d.ts +41 -0
  162. package/operations/entry/elasticsearch/types.js +5 -0
  163. package/operations/entry/elasticsearch/types.js.map +1 -0
  164. package/operations/entry/index.d.ts +2 -4
  165. package/operations/entry/index.js +473 -374
  166. package/operations/entry/index.js.map +1 -0
  167. package/operations/entry/keys.js.map +1 -0
  168. package/operations/entry/recordType.d.ts +3 -0
  169. package/operations/entry/recordType.js +24 -0
  170. package/operations/entry/recordType.js.map +1 -0
  171. package/operations/group/index.d.ts +2 -2
  172. package/operations/group/index.js +8 -15
  173. package/operations/group/index.js.map +1 -0
  174. package/operations/model/index.d.ts +2 -2
  175. package/operations/model/index.js +38 -39
  176. package/operations/model/index.js.map +1 -0
  177. package/operations/settings/index.d.ts +2 -2
  178. package/operations/settings/index.js +7 -13
  179. package/operations/settings/index.js.map +1 -0
  180. package/operations/system/index.d.ts +2 -2
  181. package/operations/system/index.js +5 -11
  182. package/operations/system/index.js.map +1 -0
  183. package/package.json +24 -29
  184. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
  185. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +11 -5
  186. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  187. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  188. package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -3
  189. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  190. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  191. package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
  192. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  193. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  194. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +43 -0
  195. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  196. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
  197. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +11 -5
  198. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  199. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
  200. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +11 -5
  201. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  202. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  203. package/plugins/CmsEntryFilterPlugin.js +31 -0
  204. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  205. package/plugins/index.d.ts +6 -0
  206. package/plugins/index.js +83 -0
  207. package/plugins/index.js.map +1 -0
  208. package/types.d.ts +7 -34
  209. package/types.js +0 -13
  210. package/types.js.map +1 -0
  211. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  212. package/helpers/createElasticsearchQueryBody.js +0 -375
  213. package/helpers/fields.d.ts +0 -77
  214. package/helpers/fields.js +0 -174
  215. package/helpers/operatorPluginsList.d.ts +0 -7
  216. package/helpers/operatorPluginsList.js +0 -30
  217. package/helpers/searchPluginsList.d.ts +0 -6
  218. package/helpers/transformValueForSearch.d.ts +0 -9
  219. package/helpers/transformValueForSearch.js +0 -26
  220. package/operations/entry/elasticsearchFields.d.ts +0 -2
  221. package/operations/entry/elasticsearchFields.js +0 -32
  222. package/operations/entry/fields.d.ts +0 -3
  223. package/operations/entry/fields.js +0 -60
  224. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  225. package/operations/system/createElasticsearchTemplate.js +0 -62
  226. package/upgrades/index.d.ts +0 -2
  227. package/upgrades/index.js +0 -16
  228. package/upgrades/utils.d.ts +0 -1
  229. package/upgrades/utils.js +0 -16
  230. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  231. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  232. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  233. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  234. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  235. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  236. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  237. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  238. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  239. package/upgrades/v5.0.0/helpers.js +0 -57
  240. package/upgrades/v5.0.0/index.d.ts +0 -4
  241. package/upgrades/v5.0.0/index.js +0 -232
  242. package/upgrades/v5.8.0/index.d.ts +0 -4
  243. package/upgrades/v5.8.0/index.js +0 -426
@@ -1,20 +1,16 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.prepareEntryToIndex = exports.extractEntriesFromIndex = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
14
  const prepareEntryToIndex = params => {
19
15
  const {
20
16
  plugins,
@@ -49,7 +45,7 @@ const prepareEntryToIndex = params => {
49
45
  const rawValues = {}; // We're only interested in current model fields.
50
46
 
51
47
  for (const field of model.fields) {
52
- if (storageEntry.values.hasOwnProperty(field.fieldId) === false) {
48
+ if (storageEntry.values.hasOwnProperty(field.storageId) === false) {
53
49
  continue;
54
50
  }
55
51
 
@@ -66,22 +62,22 @@ const prepareEntryToIndex = params => {
66
62
  plugins,
67
63
  model,
68
64
  field,
69
- rawValue: entry.values[field.fieldId],
70
- value: storageEntry.values[field.fieldId],
65
+ rawValue: entry.values[field.storageId],
66
+ value: storageEntry.values[field.storageId],
71
67
  getFieldIndexPlugin,
72
68
  getFieldTypePlugin
73
69
  });
74
70
 
75
71
  if (typeof value !== "undefined") {
76
- values[field.fieldId] = value;
72
+ values[field.storageId] = value;
77
73
  }
78
74
 
79
75
  if (typeof rawValue !== "undefined") {
80
- rawValues[field.fieldId] = rawValue;
76
+ rawValues[field.storageId] = rawValue;
81
77
  }
82
78
  }
83
79
 
84
- return _objectSpread(_objectSpread({}, storageEntry), {}, {
80
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
85
81
  values,
86
82
  rawValues
87
83
  });
@@ -106,7 +102,7 @@ const setupEntriesIndexHelpers = ({
106
102
 
107
103
  const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*"); // CmsModelFieldToGraphQLPlugin plugins
108
104
 
109
- const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => _objectSpread(_objectSpread({}, plugins), {}, {
105
+ const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugins), {}, {
110
106
  [plugin.fieldType]: plugin
111
107
  }), {});
112
108
  return {
@@ -157,18 +153,18 @@ const extractEntriesFromIndex = ({
157
153
  }
158
154
 
159
155
  try {
160
- indexValues[field.fieldId] = targetFieldPlugin.fromIndex({
156
+ indexValues[field.storageId] = targetFieldPlugin.fromIndex({
161
157
  plugins,
162
158
  model,
163
159
  field,
164
160
  getFieldIndexPlugin,
165
161
  getFieldTypePlugin,
166
- value: entry.values[field.fieldId],
162
+ value: entry.values[field.storageId],
167
163
 
168
164
  /**
169
165
  * Possibly no rawValues so we must check for the existence of the field.
170
166
  */
171
- rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null
167
+ rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null
172
168
  });
173
169
  } catch (ex) {
174
170
  throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
@@ -177,10 +173,29 @@ const extractEntriesFromIndex = ({
177
173
  });
178
174
  }
179
175
  }
176
+ /**
177
+ * Let's have a new entry so we do not modify the original one.
178
+ */
179
+
180
180
 
181
- list.push(_objectSpread(_objectSpread({}, entry), {}, {
181
+ const newEntry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
182
182
  values: indexValues
183
- }));
183
+ });
184
+ /**
185
+ * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.
186
+ */
187
+ // @ts-ignore
188
+
189
+ delete newEntry["rawValues"]; // @ts-ignore
190
+
191
+ delete newEntry["TYPE"]; // @ts-ignore
192
+
193
+ delete newEntry["__type"]; // @ts-ignore
194
+
195
+ delete newEntry["latest"]; // @ts-ignore
196
+
197
+ delete newEntry["published"];
198
+ list.push((0, _objectSpread2.default)({}, newEntry));
184
199
  }
185
200
 
186
201
  return list;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","hasOwnProperty","storageId","targetFieldPlugin","type","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry[];\n}\n\ninterface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry;\n storageEntry: CmsEntry;\n}\n\nexport const prepareEntryToIndex = (params: PrepareElasticsearchDataParams): CmsIndexEntry => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n const pl = fieldTypePlugins[fieldType];\n if (pl) {\n return pl;\n }\n throw new WebinyError(`Missing field type plugin \"${fieldType}\". Prepare entry for index.`);\n }\n\n // These objects will contain values processed by field index plugins\n const values: Record<string, string> = {};\n const rawValues: Record<string, string> = {};\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n if (storageEntry.values.hasOwnProperty(field.storageId) === false) {\n continue;\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n\n // TODO: remove this `if` once we convert this plugin to proper plugin class\n if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {\n continue;\n }\n\n const { value, rawValue } = targetFieldPlugin.toIndex({\n plugins,\n model,\n field,\n rawValue: entry.values[field.storageId],\n value: storageEntry.values[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[field.storageId] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[field.storageId] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n } as CmsIndexEntry;\n};\n\nconst setupEntriesIndexHelpers = ({\n plugins: pluginsContainer\n}: SetupEntriesIndexHelpersParams) => {\n const plugins = pluginsContainer.byType<CmsModelFieldToElasticsearchPlugin>(\n \"cms-model-field-to-elastic-search\"\n );\n\n const fieldIndexPlugins: Record<string, CmsModelFieldToElasticsearchPlugin> = {};\n for (const plugin of plugins.reverse()) {\n if (fieldIndexPlugins[plugin.fieldType]) {\n continue;\n }\n fieldIndexPlugins[plugin.fieldType] = plugin;\n }\n // we will use this plugin if no targeted plugin found\n const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === \"*\");\n\n // CmsModelFieldToGraphQLPlugin plugins\n const fieldTypePlugins: Record<string, CmsModelFieldToGraphQLPlugin> = pluginsContainer\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((plugins, plugin) => ({ ...plugins, [plugin.fieldType]: plugin }), {});\n\n return {\n fieldIndexPlugins,\n defaultIndexFieldPlugin,\n fieldTypePlugins\n };\n};\n\nexport const extractEntriesFromIndex = ({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams): CmsEntry[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(fieldType: string) {\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(fieldType: string) {\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: Record<string, string> = {};\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = fieldTypePlugins[field.type];\n if (!fieldTypePlugin) {\n throw new WebinyError(\n `Missing field type plugin \"${field.type}\". Extract entries from index.`\n );\n }\n\n const targetFieldPlugin = getFieldIndexPlugin(field.type);\n if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {\n continue;\n }\n try {\n indexValues[field.storageId] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[field.storageId],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not transform entry field from index.\",\n ex.code || \"FIELD_FROM_INDEX_ERROR\",\n {\n field,\n entry\n }\n );\n }\n }\n /**\n * Let's have a new entry so we do not modify the original one.\n */\n const newEntry: CmsEntry = {\n ...entry,\n values: indexValues\n };\n /**\n * If we want to remove the rawValues, TYPE, latest, published and __type, we must make them optional or ignore them.\n */\n // @ts-ignore\n delete newEntry[\"rawValues\"];\n // @ts-ignore\n delete newEntry[\"TYPE\"];\n // @ts-ignore\n delete newEntry[\"__type\"];\n // @ts-ignore\n delete newEntry[\"latest\"];\n // @ts-ignore\n delete newEntry[\"published\"];\n list.push({ ...newEntry });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAoBO,MAAMA,mBAAmB,GAAIC,MAAD,IAA2D;EAC1F,MAAM;IAAEC,OAAF;IAAWC,YAAX;IAAyBC,KAAzB;IAAgCC;EAAhC,IAA0CJ,MAAhD;EACA,MAAM;IAAEK,iBAAF;IAAqBC,uBAArB;IAA8CC;EAA9C,IACFC,wBAAwB,CAAC;IAAEP;EAAF,CAAD,CAD5B;;EAGA,SAASQ,mBAAT,CAA6BC,SAA7B,EAAgD;IAC5C,OAAOL,iBAAiB,CAACK,SAAD,CAAjB,IAAgCJ,uBAAvC;EACH;;EAED,SAASK,kBAAT,CAA4BD,SAA5B,EAA+C;IAC3C,MAAME,EAAE,GAAGL,gBAAgB,CAACG,SAAD,CAA3B;;IACA,IAAIE,EAAJ,EAAQ;MACJ,OAAOA,EAAP;IACH;;IACD,MAAM,IAAIC,cAAJ,CAAiB,8BAA6BH,SAAU,6BAAxD,CAAN;EACH,CAfyF,CAiB1F;;;EACA,MAAMI,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OAAOA,QAAQ,CAAC,WAAD,CAAf;IACAP,IAAI,CAACQ,IAAL,iCAAeD,QAAf;EACH;;EAED,OAAOP,IAAP;AACH,CAnFM"}
@@ -1,2 +1 @@
1
- export * from "./createElasticsearchQueryBody";
2
1
  export * from "./entryIndexHelpers";
package/helpers/index.js CHANGED
@@ -4,19 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _createElasticsearchQueryBody = require("./createElasticsearchQueryBody");
8
-
9
- Object.keys(_createElasticsearchQueryBody).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _createElasticsearchQueryBody[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _createElasticsearchQueryBody[key];
16
- }
17
- });
18
- });
19
-
20
7
  var _entryIndexHelpers = require("./entryIndexHelpers");
21
8
 
22
9
  Object.keys(_entryIndexHelpers).forEach(function (key) {
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { StorageOperationsFactory } from "./types";
2
+ export * from "./plugins";
2
3
  export declare const createStorageOperations: StorageOperationsFactory;
package/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ var _exportNames = {
9
+ createStorageOperations: true
10
+ };
8
11
  exports.createStorageOperations = void 0;
9
12
 
10
13
  var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
@@ -39,25 +42,42 @@ var _system2 = require("./definitions/system");
39
42
 
40
43
  var _settings2 = require("./definitions/settings");
41
44
 
42
- var _createElasticsearchTemplate = require("./operations/system/createElasticsearchTemplate");
45
+ var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
43
46
 
44
47
  var _plugins = require("@webiny/plugins");
45
48
 
46
49
  var _group2 = require("./operations/group");
47
50
 
48
- var _operators = require("@webiny/api-elasticsearch/operators");
51
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
52
+
53
+ var _indices = require("./elasticsearch/indices");
54
+
55
+ var _deleteElasticsearchIndex = require("./elasticsearch/deleteElasticsearchIndex");
49
56
 
50
- var _elasticsearchFields = require("./operations/entry/elasticsearchFields");
57
+ var _plugins2 = require("./plugins");
58
+
59
+ Object.keys(_plugins2).forEach(function (key) {
60
+ if (key === "default" || key === "__esModule") return;
61
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
62
+ if (key in exports && exports[key] === _plugins2[key]) return;
63
+ Object.defineProperty(exports, key, {
64
+ enumerable: true,
65
+ get: function () {
66
+ return _plugins2[key];
67
+ }
68
+ });
69
+ });
70
+
71
+ var _plugins3 = require("./operations/entry/elasticsearch/filtering/plugins");
51
72
 
52
73
  const createStorageOperations = params => {
53
74
  const {
54
- attributes = {},
75
+ attributes,
55
76
  table,
56
77
  esTable,
57
78
  documentClient,
58
79
  elasticsearch,
59
- plugins: customPlugins,
60
- modelFieldToGraphQLPlugins
80
+ plugins: userPlugins
61
81
  } = params;
62
82
  const tableInstance = (0, _table.createTable)({
63
83
  table,
@@ -71,47 +91,39 @@ const createStorageOperations = params => {
71
91
  settings: (0, _settings2.createSettingsEntity)({
72
92
  entityName: _types.ENTITIES.SETTINGS,
73
93
  table: tableInstance,
74
- attributes: attributes[_types.ENTITIES.SETTINGS]
94
+ attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
75
95
  }),
76
96
  system: (0, _system2.createSystemEntity)({
77
97
  entityName: _types.ENTITIES.SYSTEM,
78
98
  table: tableInstance,
79
- attributes: attributes[_types.ENTITIES.SYSTEM]
99
+ attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
80
100
  }),
81
101
  groups: (0, _group.createGroupEntity)({
82
102
  entityName: _types.ENTITIES.GROUPS,
83
103
  table: tableInstance,
84
- attributes: attributes[_types.ENTITIES.GROUPS]
104
+ attributes: attributes ? attributes[_types.ENTITIES.GROUPS] : {}
85
105
  }),
86
106
  models: (0, _model2.createModelEntity)({
87
107
  entityName: _types.ENTITIES.MODELS,
88
108
  table: tableInstance,
89
- attributes: attributes[_types.ENTITIES.MODELS]
109
+ attributes: attributes ? attributes[_types.ENTITIES.MODELS] : {}
90
110
  }),
91
111
  entries: (0, _entry2.createEntryEntity)({
92
112
  entityName: _types.ENTITIES.ENTRIES,
93
113
  table: tableInstance,
94
- attributes: attributes[_types.ENTITIES.ENTRIES]
114
+ attributes: attributes ? attributes[_types.ENTITIES.ENTRIES] : {}
95
115
  }),
96
116
  entriesEs: (0, _entryElasticsearch.createEntryElasticsearchEntity)({
97
117
  entityName: _types.ENTITIES.ENTRIES_ES,
98
118
  table: tableElasticsearchInstance,
99
- attributes: attributes[_types.ENTITIES.ENTRIES_ES]
119
+ attributes: attributes ? attributes[_types.ENTITIES.ENTRIES_ES] : {}
100
120
  })
101
121
  };
102
122
  const plugins = new _plugins.PluginsContainer([
103
- /**
104
- * User defined custom plugins.
105
- */
106
- ...(customPlugins || []),
107
123
  /**
108
124
  * Plugins of type CmsModelFieldToGraphQLPlugin.
109
125
  */
110
- modelFieldToGraphQLPlugins,
111
- /**
112
- * Elasticsearch field definitions for the entry record.
113
- */
114
- _elasticsearchFields.elasticsearchFields,
126
+
115
127
  /**
116
128
  * DynamoDB filter plugins for the where conditions.
117
129
  */
@@ -119,7 +131,7 @@ const createStorageOperations = params => {
119
131
  /**
120
132
  * Elasticsearch operators.
121
133
  */
122
- (0, _operators.getElasticsearchOperators)(),
134
+ (0, _apiElasticsearch.getElasticsearchOperators)(),
123
135
  /**
124
136
  * Field plugins for DynamoDB.
125
137
  */
@@ -127,21 +139,107 @@ const createStorageOperations = params => {
127
139
  /**
128
140
  * Field plugins for Elasticsearch.
129
141
  */
130
- (0, _elasticsearch.default)()]);
142
+ (0, _elasticsearch.default)(),
143
+ /**
144
+ * Built-in Elasticsearch index templates.
145
+ */
146
+ (0, _indices.elasticsearchIndexPlugins)(),
147
+ /**
148
+ * Filter plugins used to apply filtering from where conditions to Elasticsearch query.
149
+ */
150
+ (0, _plugins3.createFilterPlugins)(),
151
+ /**
152
+ * User defined custom plugins.
153
+ * They are at the end because we can then override existing plugins.
154
+ */
155
+ ...(userPlugins || [])]);
131
156
  return {
132
- init: async cms => {
133
- cms.onBeforeSystemInstall.subscribe(async () => {
134
- await (0, _createElasticsearchTemplate.createElasticsearchTemplate)({
135
- elasticsearch
157
+ name: "dynamodb:elasticsearch",
158
+ beforeInit: async context => {
159
+ /**
160
+ * Attach the elasticsearch into context if it is not already attached.
161
+ */
162
+ if (!context.elasticsearch) {
163
+ context.elasticsearch = elasticsearch;
164
+ }
165
+ /**
166
+ * Pass the plugins to the parent context.
167
+ */
168
+
169
+
170
+ context.plugins.register([(0, _dynamoDb.default)()]);
171
+ /**
172
+ * Collect all required plugins from parent context.
173
+ */
174
+
175
+ const fieldPlugins = context.plugins.byType("cms-model-field-to-graphql");
176
+ plugins.register(fieldPlugins);
177
+ /**
178
+ * We need to get all the operator plugins from the main plugin container.
179
+ */
180
+
181
+ const elasticsearchOperatorPlugins = context.plugins.byType(_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type);
182
+ plugins.register(elasticsearchOperatorPlugins);
183
+ /**
184
+ * We need to get all the query modifier plugins
185
+ */
186
+
187
+ const queryModifierPlugins = context.plugins.byType(_plugins2.CmsEntryElasticsearchQueryModifierPlugin.type);
188
+ plugins.register(queryModifierPlugins);
189
+ /**
190
+ * We need to get all the sort modifier plugins
191
+ */
192
+
193
+ const sortModifierPlugins = context.plugins.byType(_plugins2.CmsEntryElasticsearchSortModifierPlugin.type);
194
+ plugins.register(sortModifierPlugins);
195
+ /**
196
+ * We need to get all the body modifier plugins
197
+ */
198
+
199
+ const bodyModifierPlugins = context.plugins.byType(_plugins2.CmsEntryElasticsearchBodyModifierPlugin.type);
200
+ plugins.register(bodyModifierPlugins);
201
+ },
202
+ init: async context => {
203
+ /**
204
+ * We need to create indexes on before model create and on clone (create from).
205
+ * Other apps create indexes on locale creation.
206
+ */
207
+ context.cms.onModelBeforeCreate.subscribe(async ({
208
+ model
209
+ }) => {
210
+ await (0, _createElasticsearchIndex.createElasticsearchIndex)({
211
+ elasticsearch,
212
+ model,
213
+ plugins
214
+ });
215
+ });
216
+ context.cms.onModelBeforeCreateFrom.subscribe(async ({
217
+ model
218
+ }) => {
219
+ await (0, _createElasticsearchIndex.createElasticsearchIndex)({
220
+ elasticsearch,
221
+ model,
222
+ plugins
223
+ });
224
+ });
225
+ context.cms.onModelAfterDelete.subscribe(async ({
226
+ model
227
+ }) => {
228
+ await (0, _deleteElasticsearchIndex.deleteElasticsearchIndex)({
229
+ elasticsearch,
230
+ model
231
+ });
232
+ });
233
+ context.cms.onModelInitialize.subscribe(async ({
234
+ model
235
+ }) => {
236
+ await (0, _createElasticsearchIndex.createElasticsearchIndex)({
237
+ elasticsearch,
238
+ model,
239
+ plugins
136
240
  });
137
241
  });
138
242
  },
139
- plugins: [
140
- /**
141
- * Field plugins for DynamoDB.
142
- * We must pass them to the base application.
143
- */
144
- (0, _dynamoDb.default)()],
145
243
  getEntities: () => entities,
146
244
  getTable: () => tableInstance,
147
245
  getEsTable: () => tableElasticsearchInstance,
package/index.js.map ADDED
@@ -0,0 +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","getElasticsearchOperators","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","fieldPlugins","byType","elasticsearchOperatorPlugins","ElasticsearchQueryBuilderOperatorPlugin","type","queryModifierPlugins","CmsEntryElasticsearchQueryModifierPlugin","sortModifierPlugins","CmsEntryElasticsearchSortModifierPlugin","bodyModifierPlugins","CmsEntryElasticsearchBodyModifierPlugin","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 ElasticsearchQueryBuilderOperatorPlugin,\n getElasticsearchOperators\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport { CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport {\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\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 * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\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 * Collect all required plugins from parent context.\n */\n const fieldPlugins = context.plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n plugins.register(fieldPlugins);\n /**\n * We need to get all the operator plugins from the main plugin container.\n */\n const elasticsearchOperatorPlugins =\n context.plugins.byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n );\n plugins.register(elasticsearchOperatorPlugins);\n /**\n * We need to get all the query modifier plugins\n */\n const queryModifierPlugins =\n context.plugins.byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n );\n plugins.register(queryModifierPlugins);\n /**\n * We need to get all the sort modifier plugins\n */\n const sortModifierPlugins =\n context.plugins.byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n );\n plugins.register(sortModifierPlugins);\n /**\n * We need to get all the body modifier plugins\n */\n const bodyModifierPlugins =\n context.plugins.byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n );\n plugins.register(bodyModifierPlugins);\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;;AAEA;;AAOA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAFA;;AAIO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UADE;IAEFC,KAFE;IAGFC,OAHE;IAIFC,cAJE;IAKFC,aALE;IAMFC,OAAO,EAAEC;EANP,IAOFP,MAPJ;EASA,MAAMQ,aAAa,GAAG,IAAAC,kBAAA,EAAY;IAC9BP,KAD8B;IAE9BE;EAF8B,CAAZ,CAAtB;EAIA,MAAMM,0BAA0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KAF2B;UAG3BrD;QAH2B,CAAzB,CAAN;MAKH,CAND;IAOH,CAtFE;IAuFH2D,WAAW,EAAE,MAAMrD,QAvFhB;IAwFHsD,QAAQ,EAAE,MAAM1D,aAxFb;IAyFH2D,UAAU,EAAE,MAAMzD,0BAzFf;IA0FHQ,MAAM,EAAE,IAAAkD,qCAAA,EAA8B;MAClCC,MAAM,EAAEzD,QAAQ,CAACM;IADiB,CAA9B,CA1FL;IA6FHL,QAAQ,EAAE,IAAAyD,yCAAA,EAAgC;MACtCD,MAAM,EAAEzD,QAAQ,CAACC;IADqB,CAAhC,CA7FP;IAgGHQ,MAAM,EAAE,IAAAkD,qCAAA,EAA8B;MAClCF,MAAM,EAAEzD,QAAQ,CAACS,MADiB;MAElCf;IAFkC,CAA9B,CAhGL;IAoGHkB,MAAM,EAAE,IAAAgD,oCAAA,EAA8B;MAClCH,MAAM,EAAEzD,QAAQ,CAACY,MADiB;MAElCnB;IAFkC,CAA9B,CApGL;IAwGHsB,OAAO,EAAE,IAAA8C,qCAAA,EAA+B;MACpCJ,MAAM,EAAEzD,QAAQ,CAACe,OADmB;MAEpC+C,QAAQ,EAAE9D,QAAQ,CAACkB,SAFiB;MAGpCxB,OAHoC;MAIpCD;IAJoC,CAA/B;EAxGN,CAAP;AA+GH,CAtMM"}
@@ -20,13 +20,13 @@ interface ClearLoaderParams {
20
20
  model: CmsModel;
21
21
  entry?: CmsEntry;
22
22
  }
23
- export interface Params {
23
+ export interface DataLoadersHandlerParams {
24
24
  entity: Entity<any>;
25
25
  }
26
26
  export declare class DataLoadersHandler {
27
27
  private readonly loaders;
28
28
  private readonly entity;
29
- constructor(params: any);
29
+ constructor(params: DataLoadersHandlerParams);
30
30
  getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]>;
31
31
  clearAllEntryRevisions(params: ClearLoaderParams): void;
32
32
  getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]>;
@@ -35,6 +35,10 @@ export declare class DataLoadersHandler {
35
35
  clearPublishedRevisionByEntryId(params: ClearLoaderParams): void;
36
36
  getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsEntry[]>;
37
37
  clearLatestRevisionByEntryId(params: ClearLoaderParams): void;
38
+ /**
39
+ * TODO @ts-refactor
40
+ * Maybe pass on the generics to DataLoader definition?
41
+ */
38
42
  private getLoader;
39
43
  private loadMany;
40
44
  clearAll(params: Omit<ClearLoaderParams, "entry">): void;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.DataLoadersHandler = void 0;
9
9
 
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
10
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
13
 
12
14
  var _dataloader = _interopRequireDefault(require("dataloader"));
@@ -23,10 +25,6 @@ var _utils = require("@webiny/utils");
23
25
 
24
26
  var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
25
27
 
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
27
-
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
-
30
28
  const getAllEntryRevisions = params => {
31
29
  const {
32
30
  entity,
@@ -37,7 +35,7 @@ const getAllEntryRevisions = params => {
37
35
  locale
38
36
  } = model;
39
37
  return new _dataloader.default(async ids => {
40
- const results = [];
38
+ const results = {};
41
39
 
42
40
  for (const id of ids) {
43
41
  const queryAllParams = {
@@ -52,11 +50,12 @@ const getAllEntryRevisions = params => {
52
50
  }
53
51
  };
54
52
  const items = await (0, _query.queryAll)(queryAllParams);
55
- const entries = (0, _cleanup.cleanupItems)(entity, items);
56
- results.push(entries);
53
+ results[id] = (0, _cleanup.cleanupItems)(entity, items);
57
54
  }
58
55
 
59
- return results;
56
+ return ids.map(id => {
57
+ return results[id] || [];
58
+ });
60
59
  });
61
60
  };
62
61
 
@@ -79,6 +78,11 @@ const getRevisionById = params => {
79
78
  const {
80
79
  version
81
80
  } = (0, _utils.parseIdentifier)(id);
81
+
82
+ if (!version) {
83
+ return collection;
84
+ }
85
+
82
86
  const sortKey = (0, _keys.createRevisionSortKey)({
83
87
  version
84
88
  });
@@ -93,6 +97,9 @@ const getRevisionById = params => {
93
97
  SK: sortKey
94
98
  });
95
99
  return collection;
100
+ /**
101
+ * We use any because there is no type for the return type.
102
+ */
96
103
  }, {});
97
104
  const records = await (0, _batchRead.batchReadAll)({
98
105
  table: entity.table,
@@ -134,6 +141,9 @@ const getPublishedRevisionByEntryId = params => {
134
141
  SK: publishedKey
135
142
  });
136
143
  return collection;
144
+ /**
145
+ * We use any because there is no type for the return type.
146
+ */
137
147
  }, {});
138
148
  const records = await (0, _batchRead.batchReadAll)({
139
149
  table: entity.table,
@@ -178,6 +188,9 @@ const getLatestRevisionByEntryId = params => {
178
188
  SK: latestKey
179
189
  });
180
190
  return collection;
191
+ /**
192
+ * We use any because there is no type for the return type.
193
+ */
181
194
  }, {});
182
195
  const records = await (0, _batchRead.batchReadAll)({
183
196
  table: entity.table,
@@ -241,6 +254,11 @@ class DataLoadersHandler {
241
254
  clearLatestRevisionByEntryId(params) {
242
255
  this.clear("getLatestRevisionByEntryId", params);
243
256
  }
257
+ /**
258
+ * TODO @ts-refactor
259
+ * Maybe pass on the generics to DataLoader definition?
260
+ */
261
+
244
262
 
245
263
  getLoader(name, params) {
246
264
  if (!dataLoaders[name]) {
@@ -259,7 +277,7 @@ class DataLoadersHandler {
259
277
  const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
260
278
 
261
279
  if (!this.loaders.has(loaderKey)) {
262
- this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
280
+ this.loaders.set(loaderKey, dataLoaders[name]((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
263
281
  entity: this.entity
264
282
  })));
265
283
  }
@@ -277,12 +295,12 @@ class DataLoadersHandler {
277
295
  return results.reduce((acc, res) => {
278
296
  if (Array.isArray(res) === false) {
279
297
  if (res && res.message) {
280
- throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
298
+ throw new _error.default(res.message, res.code, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, res), {}, {
281
299
  data: JSON.stringify(res.data || {})
282
300
  }));
283
301
  }
284
302
 
285
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", _objectSpread(_objectSpread({}, params), {}, {
303
+ throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
286
304
  loader
287
305
  }));
288
306
  }
@@ -292,7 +310,7 @@ class DataLoadersHandler {
292
310
  }, []);
293
311
  }
294
312
  } catch (ex) {
295
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
313
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
296
314
  error: ex
297
315
  }, params), {}, {
298
316
  loader,