@webiny/api-headless-cms-ddb-es 5.17.4 → 5.18.0-beta.3

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 (170) hide show
  1. package/configurations.d.ts +5 -17
  2. package/configurations.js +9 -38
  3. package/definitions/entry.d.ts +6 -11
  4. package/definitions/entry.js +17 -14
  5. package/definitions/entryElasticsearch.d.ts +8 -0
  6. package/definitions/entryElasticsearch.js +46 -0
  7. package/definitions/group.d.ts +8 -0
  8. package/definitions/group.js +74 -0
  9. package/definitions/model.d.ts +7 -6
  10. package/definitions/model.js +45 -20
  11. package/definitions/settings.d.ts +8 -0
  12. package/definitions/settings.js +62 -0
  13. package/definitions/system.d.ts +8 -0
  14. package/definitions/system.js +50 -0
  15. package/definitions/table.d.ts +7 -3
  16. package/definitions/table.js +12 -29
  17. package/definitions/tableElasticsearch.d.ts +7 -3
  18. package/definitions/tableElasticsearch.js +12 -29
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +4 -3
  21. package/dynamoDb/storage/date.d.ts +2 -2
  22. package/dynamoDb/storage/date.js +17 -17
  23. package/dynamoDb/storage/longText.d.ts +7 -0
  24. package/dynamoDb/storage/longText.js +83 -0
  25. package/dynamoDb/storage/richText.d.ts +2 -2
  26. package/dynamoDb/storage/richText.js +69 -67
  27. package/elasticsearch/index.d.ts +1 -1
  28. package/elasticsearch/index.js +1 -2
  29. package/elasticsearch/indexing/dateTimeIndexing.js +1 -2
  30. package/elasticsearch/indexing/defaultFieldIndexing.js +1 -2
  31. package/elasticsearch/indexing/index.js +4 -3
  32. package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
  33. package/elasticsearch/indexing/longTextIndexing.js +36 -0
  34. package/elasticsearch/indexing/numberIndexing.js +1 -2
  35. package/elasticsearch/indexing/objectIndexing.js +32 -27
  36. package/elasticsearch/indexing/richTextIndexing.js +1 -2
  37. package/elasticsearch/search/index.js +1 -2
  38. package/elasticsearch/search/refSearch.js +1 -2
  39. package/elasticsearch/search/timeSearch.js +1 -2
  40. package/helpers/createElasticsearchQueryBody.d.ts +5 -4
  41. package/helpers/createElasticsearchQueryBody.js +89 -44
  42. package/helpers/entryIndexHelpers.d.ts +14 -12
  43. package/helpers/entryIndexHelpers.js +63 -58
  44. package/helpers/fields.d.ts +11 -10
  45. package/helpers/fields.js +4 -5
  46. package/helpers/index.js +1 -2
  47. package/helpers/operatorPluginsList.d.ts +2 -2
  48. package/helpers/operatorPluginsList.js +3 -4
  49. package/helpers/searchPluginsList.d.ts +2 -2
  50. package/helpers/searchPluginsList.js +3 -4
  51. package/helpers/transformValueForSearch.d.ts +4 -5
  52. package/helpers/transformValueForSearch.js +3 -6
  53. package/index.d.ts +2 -2
  54. package/index.js +154 -12
  55. package/operations/entry/dataLoaders.d.ts +38 -14
  56. package/operations/entry/dataLoaders.js +193 -125
  57. package/operations/entry/elasticsearchFields.d.ts +2 -0
  58. package/operations/entry/elasticsearchFields.js +32 -0
  59. package/operations/entry/fields.d.ts +2 -2
  60. package/operations/entry/fields.js +1 -2
  61. package/operations/entry/index.d.ts +13 -3
  62. package/operations/entry/index.js +1148 -15
  63. package/operations/entry/keys.d.ts +12 -0
  64. package/operations/entry/keys.js +40 -0
  65. package/operations/group/index.d.ts +8 -0
  66. package/operations/group/index.js +202 -0
  67. package/operations/model/index.d.ts +8 -3
  68. package/operations/model/index.js +196 -17
  69. package/operations/settings/index.d.ts +6 -3
  70. package/operations/settings/index.js +132 -16
  71. package/operations/system/createElasticsearchTemplate.d.ts +5 -0
  72. package/operations/system/createElasticsearchTemplate.js +62 -0
  73. package/operations/system/index.d.ts +6 -3
  74. package/operations/system/index.js +93 -17
  75. package/package.json +15 -14
  76. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
  77. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
  78. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +9 -1
  79. package/plugins/CmsEntryElasticsearchFieldPlugin.js +9 -3
  80. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
  81. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
  82. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
  83. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
  84. package/types.d.ts +61 -80
  85. package/types.js +55 -1
  86. package/upgrades/index.js +1 -2
  87. package/upgrades/utils.js +1 -2
  88. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +2 -2
  89. package/upgrades/v5.0.0/cleanDatabaseRecord.js +1 -2
  90. package/upgrades/v5.0.0/createOldVersionIndiceName.js +1 -2
  91. package/upgrades/v5.0.0/entryValueFixer.d.ts +3 -3
  92. package/upgrades/v5.0.0/entryValueFixer.js +3 -4
  93. package/upgrades/v5.0.0/fieldFinder.d.ts +4 -4
  94. package/upgrades/v5.0.0/fieldFinder.js +1 -2
  95. package/upgrades/v5.0.0/helpers.js +1 -2
  96. package/upgrades/v5.0.0/index.js +1 -2
  97. package/upgrades/v5.8.0/index.js +3 -3
  98. package/configurations.js.map +0 -1
  99. package/definitions/elasticsearchEntry.d.ts +0 -13
  100. package/definitions/elasticsearchEntry.js +0 -43
  101. package/definitions/elasticsearchEntry.js.map +0 -1
  102. package/definitions/entry.js.map +0 -1
  103. package/definitions/index.d.ts +0 -17
  104. package/definitions/index.js +0 -28
  105. package/definitions/index.js.map +0 -1
  106. package/definitions/model.js.map +0 -1
  107. package/definitions/table.js.map +0 -1
  108. package/definitions/tableElasticsearch.js.map +0 -1
  109. package/dynamoDb/index.js.map +0 -1
  110. package/dynamoDb/storage/date.js.map +0 -1
  111. package/dynamoDb/storage/richText.js.map +0 -1
  112. package/elasticsearch/index.js.map +0 -1
  113. package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
  114. package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
  115. package/elasticsearch/indexing/index.js.map +0 -1
  116. package/elasticsearch/indexing/numberIndexing.js.map +0 -1
  117. package/elasticsearch/indexing/objectIndexing.js.map +0 -1
  118. package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
  119. package/elasticsearch/search/index.js.map +0 -1
  120. package/elasticsearch/search/refSearch.js.map +0 -1
  121. package/elasticsearch/search/timeSearch.js.map +0 -1
  122. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  123. package/helpers/entryIndexHelpers.js.map +0 -1
  124. package/helpers/fields.js.map +0 -1
  125. package/helpers/index.js.map +0 -1
  126. package/helpers/operatorPluginsList.js.map +0 -1
  127. package/helpers/searchPluginsList.js.map +0 -1
  128. package/helpers/transformValueForSearch.js.map +0 -1
  129. package/index.js.map +0 -1
  130. package/operations/entry/CmsContentEntryDynamoElastic.d.ts +0 -54
  131. package/operations/entry/CmsContentEntryDynamoElastic.js +0 -1128
  132. package/operations/entry/CmsContentEntryDynamoElastic.js.map +0 -1
  133. package/operations/entry/dataLoaders.js.map +0 -1
  134. package/operations/entry/fields.js.map +0 -1
  135. package/operations/entry/index.js.map +0 -1
  136. package/operations/model/CmsContentModelDynamoElastic.d.ts +0 -18
  137. package/operations/model/CmsContentModelDynamoElastic.js +0 -180
  138. package/operations/model/CmsContentModelDynamoElastic.js.map +0 -1
  139. package/operations/model/index.js.map +0 -1
  140. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.d.ts +0 -40
  141. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js +0 -193
  142. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js.map +0 -1
  143. package/operations/modelGroup/index.d.ts +0 -3
  144. package/operations/modelGroup/index.js +0 -26
  145. package/operations/modelGroup/index.js.map +0 -1
  146. package/operations/settings/CmsSettingsDynamoElastic.d.ts +0 -14
  147. package/operations/settings/CmsSettingsDynamoElastic.js +0 -127
  148. package/operations/settings/CmsSettingsDynamoElastic.js.map +0 -1
  149. package/operations/settings/index.js.map +0 -1
  150. package/operations/system/CmsSystemDynamoElastic.d.ts +0 -14
  151. package/operations/system/CmsSystemDynamoElastic.js +0 -101
  152. package/operations/system/CmsSystemDynamoElastic.js.map +0 -1
  153. package/operations/system/CmsSystemInstallationPlugin.d.ts +0 -11
  154. package/operations/system/CmsSystemInstallationPlugin.js +0 -78
  155. package/operations/system/CmsSystemInstallationPlugin.js.map +0 -1
  156. package/operations/system/index.js.map +0 -1
  157. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
  158. package/types.js.map +0 -1
  159. package/upgrades/index.js.map +0 -1
  160. package/upgrades/utils.js.map +0 -1
  161. package/upgrades/v5.0.0/cleanDatabaseRecord.js.map +0 -1
  162. package/upgrades/v5.0.0/createOldVersionIndiceName.js.map +0 -1
  163. package/upgrades/v5.0.0/entryValueFixer.js.map +0 -1
  164. package/upgrades/v5.0.0/fieldFinder.js.map +0 -1
  165. package/upgrades/v5.0.0/helpers.js.map +0 -1
  166. package/upgrades/v5.0.0/index.js.map +0 -1
  167. package/upgrades/v5.8.0/index.js.map +0 -1
  168. package/utils.d.ts +0 -3
  169. package/utils.js +0 -42
  170. package/utils.js.map +0 -1
@@ -21,5 +21,4 @@ var _default = () => ({
21
21
  }
22
22
  });
23
23
 
24
- exports.default = _default;
25
- //# sourceMappingURL=refSearch.js.map
24
+ exports.default = _default;
@@ -22,5 +22,4 @@ var _default = () => ({
22
22
  }
23
23
  });
24
24
 
25
- exports.default = _default;
26
- //# sourceMappingURL=timeSearch.js.map
25
+ exports.default = _default;
@@ -1,9 +1,10 @@
1
- import { CmsContentEntryListArgs, CmsContentModel, CmsContext } from "@webiny/api-headless-cms/types";
1
+ import { CmsEntryListParams, CmsModel } from "@webiny/api-headless-cms/types";
2
2
  import { SearchBody as esSearchBody } from "@webiny/api-elasticsearch/types";
3
+ import { PluginsContainer } from "@webiny/plugins";
3
4
  interface CreateElasticsearchParams {
4
- context: CmsContext;
5
- model: CmsContentModel;
6
- args: CmsContentEntryListArgs;
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ args: CmsEntryListParams;
7
8
  parentPath?: string;
8
9
  }
9
10
  export declare const createElasticsearchQueryBody: (params: CreateElasticsearchParams) => esSearchBody;
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.createElasticsearchQueryBody = void 0;
9
9
 
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
10
12
  var _error = _interopRequireDefault(require("@webiny/error"));
11
13
 
12
14
  var _operatorPluginsList = require("./operatorPluginsList");
@@ -15,8 +17,6 @@ var _transformValueForSearch = require("./transformValueForSearch");
15
17
 
16
18
  var _searchPluginsList = require("./searchPluginsList");
17
19
 
18
- var _CmsContentEntryDynamoElastic = require("../operations/entry/CmsContentEntryDynamoElastic");
19
-
20
20
  var _cursors = require("@webiny/api-elasticsearch/cursors");
21
21
 
22
22
  var _sort = require("@webiny/api-elasticsearch/sort");
@@ -27,12 +27,23 @@ var _CmsEntryElasticsearchFieldPlugin = require("../plugins/CmsEntryElasticsearc
27
27
 
28
28
  var _where = require("@webiny/api-elasticsearch/where");
29
29
 
30
- const specialFields = ["published", "latest"];
30
+ var _entry = require("../operations/entry");
31
+
32
+ var _CmsEntryElasticsearchQueryModifierPlugin = require("../plugins/CmsEntryElasticsearchQueryModifierPlugin");
33
+
34
+ var _CmsEntryElasticsearchSortModifierPlugin = require("../plugins/CmsEntryElasticsearchSortModifierPlugin");
35
+
36
+ var _CmsEntryElasticsearchBodyModifierPlugin = require("../plugins/CmsEntryElasticsearchBodyModifierPlugin");
37
+
38
+ 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; }
39
+
40
+ 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; }
41
+
42
+ const specialFields = ["published", "latest", "locale", "tenant"];
31
43
  const noKeywordFields = ["date", "number", "boolean"];
32
44
 
33
45
  const createElasticsearchSortParams = args => {
34
46
  const {
35
- context,
36
47
  sort,
37
48
  modelFields,
38
49
  parentPath,
@@ -52,7 +63,6 @@ const createElasticsearchSortParams = args => {
52
63
  searchable: modelField.isSearchable,
53
64
  field: modelField.field.fieldId,
54
65
  path: createFieldPath({
55
- context,
56
66
  parentPath,
57
67
  modelField: modelField,
58
68
  searchPlugin
@@ -74,8 +84,7 @@ const createElasticsearchSortParams = args => {
74
84
 
75
85
  const createInitialQueryValue = args => {
76
86
  const {
77
- where,
78
- context
87
+ where
79
88
  } = args;
80
89
  const query = {
81
90
  must: [],
@@ -87,28 +96,38 @@ const createInitialQueryValue = args => {
87
96
  const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
88
97
 
89
98
  if (sharedIndex) {
90
- const tenant = context.tenancy.getCurrentTenant();
91
99
  query.must.push({
92
100
  term: {
93
- "tenant.keyword": tenant.id
101
+ "tenant.keyword": where.tenant
94
102
  }
95
103
  });
96
104
  }
105
+
106
+ delete where["tenant"];
107
+
108
+ if (where.locale) {
109
+ query.must.push({
110
+ term: {
111
+ "locale.keyword": where.locale
112
+ }
113
+ });
114
+ }
115
+
116
+ delete where["locale"];
97
117
  /**
98
118
  * We must transform published and latest where args into something that is understandable by our Elasticsearch
99
119
  */
100
120
 
101
-
102
121
  if (where.published === true) {
103
122
  query.must.push({
104
123
  term: {
105
- "__type.keyword": _CmsContentEntryDynamoElastic.TYPE_ENTRY_PUBLISHED
124
+ "__type.keyword": (0, _entry.createPublishedType)()
106
125
  }
107
126
  });
108
127
  } else if (where.latest === true) {
109
128
  query.must.push({
110
129
  term: {
111
- "__type.keyword": _CmsContentEntryDynamoElastic.TYPE_ENTRY_LATEST
130
+ "__type.keyword": (0, _entry.createLatestType)()
112
131
  }
113
132
  });
114
133
  } // we do not allow not published and not latest
@@ -129,15 +148,13 @@ const createInitialQueryValue = args => {
129
148
  const createFieldPath = ({
130
149
  modelField,
131
150
  searchPlugin,
132
- context,
133
151
  parentPath
134
152
  }) => {
135
153
  let path;
136
154
 
137
155
  if (searchPlugin && typeof searchPlugin.createPath === "function") {
138
156
  path = searchPlugin.createPath({
139
- field: modelField.field,
140
- context
157
+ field: modelField.field
141
158
  });
142
159
  } else if (typeof modelField.path === "function") {
143
160
  path = modelField.path(modelField.field.fieldId);
@@ -179,15 +196,20 @@ const hasKeyword = modelField => {
179
196
  */
180
197
 
181
198
 
182
- const execElasticsearchBuildQueryPlugins = args => {
199
+ const execElasticsearchBuildQueryPlugins = params => {
183
200
  const {
184
- where,
201
+ where: initialWhere,
185
202
  modelFields,
186
203
  parentPath,
187
- context,
204
+ plugins,
188
205
  searchPlugins
189
- } = args;
190
- const query = createInitialQueryValue(args);
206
+ } = params;
207
+
208
+ const where = _objectSpread({}, initialWhere);
209
+
210
+ const query = createInitialQueryValue(_objectSpread(_objectSpread({}, params), {}, {
211
+ where
212
+ }));
191
213
  /**
192
214
  * Always remove special fields, as these do not exist in Elasticsearch.
193
215
  */
@@ -196,11 +218,11 @@ const execElasticsearchBuildQueryPlugins = args => {
196
218
  delete where[sf];
197
219
  }
198
220
 
199
- if (!where || Object.keys(where).length === 0) {
221
+ if (Object.keys(where).length === 0) {
200
222
  return query;
201
223
  }
202
224
 
203
- const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(context);
225
+ const operatorPlugins = (0, _operatorPluginsList.operatorPluginsList)(plugins);
204
226
 
205
227
  for (const key in where) {
206
228
  if (where.hasOwnProperty(key) === false) {
@@ -247,11 +269,9 @@ const execElasticsearchBuildQueryPlugins = args => {
247
269
  const value = (0, _transformValueForSearch.transformValueForSearch)({
248
270
  plugins: searchPlugins,
249
271
  field: cmsField,
250
- value: where[key],
251
- context
272
+ value: where[key]
252
273
  });
253
274
  const fieldPath = createFieldPath({
254
- context,
255
275
  searchPlugin: fieldSearchPlugin,
256
276
  modelField,
257
277
  parentPath: parentPath
@@ -270,7 +290,7 @@ const execElasticsearchBuildQueryPlugins = args => {
270
290
 
271
291
  const createElasticsearchQueryBody = params => {
272
292
  const {
273
- context,
293
+ plugins,
274
294
  model,
275
295
  args,
276
296
  parentPath = null
@@ -279,29 +299,50 @@ const createElasticsearchQueryBody = params => {
279
299
  where,
280
300
  after,
281
301
  limit,
282
- sort
302
+ sort: initialSort
283
303
  } = args;
284
- const modelFields = (0, _fields.createModelFields)(context, model);
285
- const searchPlugins = (0, _searchPluginsList.searchPluginsList)(context);
304
+ const modelFields = (0, _fields.createModelFields)(plugins, model);
305
+ const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
286
306
  const query = execElasticsearchBuildQueryPlugins({
287
307
  model,
288
- context,
308
+ plugins,
289
309
  where,
290
310
  modelFields,
291
311
  parentPath,
292
312
  searchPlugins
293
313
  });
294
- const queryPlugins = context.plugins.byType("cms-elasticsearch-query");
314
+ const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
315
+ return !pl.modelId || pl.modelId === model.modelId;
316
+ });
295
317
 
296
318
  for (const pl of queryPlugins) {
297
- pl.modify({
319
+ pl.modifyQuery({
298
320
  query,
299
321
  model,
300
- context
322
+ where
323
+ });
324
+ }
325
+
326
+ const sort = createElasticsearchSortParams({
327
+ plugins,
328
+ sort: initialSort,
329
+ modelFields,
330
+ parentPath,
331
+ model,
332
+ searchPlugins
333
+ });
334
+ const sortPlugins = plugins.byType(_CmsEntryElasticsearchSortModifierPlugin.CmsEntryElasticsearchSortModifierPlugin.type).filter(pl => {
335
+ return !pl.modelId || pl.modelId === model.modelId;
336
+ });
337
+
338
+ for (const pl of sortPlugins) {
339
+ pl.modifySort({
340
+ sort,
341
+ model
301
342
  });
302
343
  }
303
344
 
304
- return {
345
+ const body = {
305
346
  query: {
306
347
  bool: {
307
348
  must: query.must.length > 0 ? query.must : undefined,
@@ -310,21 +351,25 @@ const createElasticsearchQueryBody = params => {
310
351
  filter: query.filter.length > 0 ? query.filter : undefined
311
352
  }
312
353
  },
313
- sort: createElasticsearchSortParams({
314
- context,
315
- sort,
316
- modelFields,
317
- parentPath,
318
- model,
319
- searchPlugins
320
- }),
354
+ sort,
321
355
  size: limit + 1,
322
356
  // eslint-disable-next-line
323
357
  search_after: (0, _cursors.decodeCursor)(after),
324
358
  // eslint-disable-next-line
325
359
  track_total_hits: true
326
360
  };
361
+ const bodyPlugins = plugins.byType(_CmsEntryElasticsearchBodyModifierPlugin.CmsEntryElasticsearchBodyModifierPlugin.type).filter(pl => {
362
+ return !pl.modelId || pl.modelId === model.modelId;
363
+ });
364
+
365
+ for (const pl of bodyPlugins) {
366
+ pl.modifyBody({
367
+ body,
368
+ model
369
+ });
370
+ }
371
+
372
+ return body;
327
373
  };
328
374
 
329
- exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
330
- //# sourceMappingURL=createElasticsearchQueryBody.js.map
375
+ exports.createElasticsearchQueryBody = createElasticsearchQueryBody;
@@ -1,16 +1,18 @@
1
- import { CmsContentEntry, CmsContentModel, CmsContext } from "@webiny/api-headless-cms/types";
2
- import { CmsContentIndexEntry } from "../types";
3
- interface SetupEntriesIndexHelpersArgs {
4
- context: CmsContext;
1
+ import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
2
+ import { CmsIndexEntry } from "../types";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ interface SetupEntriesIndexHelpersParams {
5
+ plugins: PluginsContainer;
5
6
  }
6
- interface ExtractEntriesFromIndexArgs extends SetupEntriesIndexHelpersArgs {
7
- model: CmsContentModel;
8
- entries: CmsContentIndexEntry[];
7
+ interface ExtractEntriesFromIndexParams extends SetupEntriesIndexHelpersParams {
8
+ model: CmsModel;
9
+ entries: CmsIndexEntry[];
9
10
  }
10
- interface PrepareElasticsearchDataArgs extends SetupEntriesIndexHelpersArgs {
11
- model: CmsContentModel;
12
- storageEntry: CmsContentEntry;
11
+ interface PrepareElasticsearchDataParams extends SetupEntriesIndexHelpersParams {
12
+ model: CmsModel;
13
+ entry: CmsEntry;
14
+ storageEntry: CmsEntry;
13
15
  }
14
- export declare const prepareEntryToIndex: (args: PrepareElasticsearchDataArgs) => CmsContentIndexEntry;
15
- export declare const extractEntriesFromIndex: ({ context, entries, model }: ExtractEntriesFromIndexArgs) => CmsContentEntry[];
16
+ export declare const prepareEntryToIndex: (params: PrepareElasticsearchDataParams) => CmsIndexEntry;
17
+ export declare const extractEntriesFromIndex: ({ plugins, entries, model }: ExtractEntriesFromIndexParams) => CmsEntry[];
16
18
  export {};
@@ -15,18 +15,19 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
15
15
 
16
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
17
 
18
- const prepareEntryToIndex = args => {
18
+ const prepareEntryToIndex = params => {
19
19
  const {
20
- context,
20
+ plugins,
21
21
  storageEntry,
22
+ entry,
22
23
  model
23
- } = args;
24
+ } = params;
24
25
  const {
25
26
  fieldIndexPlugins,
26
27
  defaultIndexFieldPlugin,
27
28
  fieldTypePlugins
28
29
  } = setupEntriesIndexHelpers({
29
- context
30
+ plugins
30
31
  });
31
32
 
32
33
  function getFieldIndexPlugin(fieldType) {
@@ -34,7 +35,13 @@ const prepareEntryToIndex = args => {
34
35
  }
35
36
 
36
37
  function getFieldTypePlugin(fieldType) {
37
- return fieldTypePlugins[fieldType];
38
+ const pl = fieldTypePlugins[fieldType];
39
+
40
+ if (pl) {
41
+ return pl;
42
+ }
43
+
44
+ throw new _error.default(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
38
45
  } // These objects will contain values processed by field index plugins
39
46
 
40
47
 
@@ -46,34 +53,31 @@ const prepareEntryToIndex = args => {
46
53
  continue;
47
54
  }
48
55
 
49
- const fieldTypePlugin = getFieldTypePlugin(field.type);
56
+ const targetFieldPlugin = getFieldIndexPlugin(field.type); // TODO: remove this `if` once we convert this plugin to proper plugin class
50
57
 
51
- if (!fieldTypePlugin) {
52
- throw new _error.default(`Missing field type plugin "${field.type}".`);
58
+ if (!targetFieldPlugin || !targetFieldPlugin.toIndex) {
59
+ continue;
53
60
  }
54
61
 
55
- const targetFieldPlugin = getFieldIndexPlugin(field.type); // TODO: remove this `if` once we convert this plugin to proper plugin class
56
-
57
- if (targetFieldPlugin && targetFieldPlugin.toIndex) {
58
- const {
59
- value,
60
- rawValue
61
- } = targetFieldPlugin.toIndex({
62
- context,
63
- model,
64
- field,
65
- value: storageEntry.values[field.fieldId],
66
- getFieldIndexPlugin,
67
- getFieldTypePlugin
68
- });
69
-
70
- if (typeof value !== "undefined") {
71
- values[field.fieldId] = value;
72
- }
62
+ const {
63
+ value,
64
+ rawValue
65
+ } = targetFieldPlugin.toIndex({
66
+ plugins,
67
+ model,
68
+ field,
69
+ rawValue: entry.values[field.fieldId],
70
+ value: storageEntry.values[field.fieldId],
71
+ getFieldIndexPlugin,
72
+ getFieldTypePlugin
73
+ });
74
+
75
+ if (typeof value !== "undefined") {
76
+ values[field.fieldId] = value;
77
+ }
73
78
 
74
- if (typeof rawValue !== "undefined") {
75
- rawValues[field.fieldId] = rawValue;
76
- }
79
+ if (typeof rawValue !== "undefined") {
80
+ rawValues[field.fieldId] = rawValue;
77
81
  }
78
82
  }
79
83
 
@@ -86,9 +90,9 @@ const prepareEntryToIndex = args => {
86
90
  exports.prepareEntryToIndex = prepareEntryToIndex;
87
91
 
88
92
  const setupEntriesIndexHelpers = ({
89
- context
93
+ plugins: pluginsContainer
90
94
  }) => {
91
- const plugins = context.plugins.byType("cms-model-field-to-elastic-search");
95
+ const plugins = pluginsContainer.byType("cms-model-field-to-elastic-search");
92
96
  const fieldIndexPlugins = {};
93
97
 
94
98
  for (const plugin of plugins.reverse()) {
@@ -102,7 +106,7 @@ const setupEntriesIndexHelpers = ({
102
106
 
103
107
  const defaultIndexFieldPlugin = plugins.find(plugin => plugin.fieldType === "*"); // CmsModelFieldToGraphQLPlugin plugins
104
108
 
105
- const fieldTypePlugins = context.plugins.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => _objectSpread(_objectSpread({}, plugins), {}, {
109
+ const fieldTypePlugins = pluginsContainer.byType("cms-model-field-to-graphql").reduce((plugins, plugin) => _objectSpread(_objectSpread({}, plugins), {}, {
106
110
  [plugin.fieldType]: plugin
107
111
  }), {});
108
112
  return {
@@ -113,7 +117,7 @@ const setupEntriesIndexHelpers = ({
113
117
  };
114
118
 
115
119
  const extractEntriesFromIndex = ({
116
- context,
120
+ plugins,
117
121
  entries,
118
122
  model
119
123
  }) => {
@@ -122,7 +126,7 @@ const extractEntriesFromIndex = ({
122
126
  defaultIndexFieldPlugin,
123
127
  fieldTypePlugins
124
128
  } = setupEntriesIndexHelpers({
125
- context
129
+ plugins
126
130
  });
127
131
 
128
132
  function getFieldIndexPlugin(fieldType) {
@@ -143,32 +147,34 @@ const extractEntriesFromIndex = ({
143
147
  const fieldTypePlugin = fieldTypePlugins[field.type];
144
148
 
145
149
  if (!fieldTypePlugin) {
146
- throw new _error.default(`Missing field type plugin "${field.type}".`);
150
+ throw new _error.default(`Missing field type plugin "${field.type}". Extract entries from index.`);
147
151
  }
148
152
 
149
153
  const targetFieldPlugin = getFieldIndexPlugin(field.type);
150
154
 
151
- if (targetFieldPlugin && targetFieldPlugin.fromIndex) {
152
- try {
153
- indexValues[field.fieldId] = targetFieldPlugin.fromIndex({
154
- context,
155
- model,
156
- field,
157
- getFieldIndexPlugin,
158
- getFieldTypePlugin,
159
- value: entry.values[field.fieldId],
160
-
161
- /**
162
- * Possibly no rawValues so we must check for the existence of the field.
163
- */
164
- rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null
165
- });
166
- } catch (ex) {
167
- throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
168
- field,
169
- entry
170
- });
171
- }
155
+ if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {
156
+ continue;
157
+ }
158
+
159
+ try {
160
+ indexValues[field.fieldId] = targetFieldPlugin.fromIndex({
161
+ plugins,
162
+ model,
163
+ field,
164
+ getFieldIndexPlugin,
165
+ getFieldTypePlugin,
166
+ value: entry.values[field.fieldId],
167
+
168
+ /**
169
+ * Possibly no rawValues so we must check for the existence of the field.
170
+ */
171
+ rawValue: entry.rawValues ? entry.rawValues[field.fieldId] : null
172
+ });
173
+ } catch (ex) {
174
+ throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
175
+ field,
176
+ entry
177
+ });
172
178
  }
173
179
  }
174
180
 
@@ -180,5 +186,4 @@ const extractEntriesFromIndex = ({
180
186
  return list;
181
187
  };
182
188
 
183
- exports.extractEntriesFromIndex = extractEntriesFromIndex;
184
- //# sourceMappingURL=entryIndexHelpers.js.map
189
+ exports.extractEntriesFromIndex = extractEntriesFromIndex;
@@ -1,4 +1,5 @@
1
- import { CmsContentModel, CmsContentModelField, CmsContext } from "@webiny/api-headless-cms/types";
1
+ import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
2
+ import { PluginsContainer } from "@webiny/plugins";
2
3
  declare type ModelFieldPath = string | ((value: string) => string);
3
4
  export interface ModelField {
4
5
  unmappedType?: string;
@@ -7,7 +8,7 @@ export interface ModelField {
7
8
  isSortable: boolean;
8
9
  type: string;
9
10
  isSystemField?: boolean;
10
- field: CmsContentModelField;
11
+ field: CmsModelField;
11
12
  path?: ModelFieldPath;
12
13
  }
13
14
  export declare type ModelFields = Record<string, ModelField>;
@@ -17,14 +18,14 @@ export declare const systemFields: {
17
18
  isSystemField: boolean;
18
19
  isSearchable: boolean;
19
20
  isSortable: boolean;
20
- field: CmsContentModelField;
21
+ field: CmsModelField;
21
22
  };
22
23
  entryId: {
23
24
  type: string;
24
25
  isSystemField: boolean;
25
26
  isSearchable: boolean;
26
27
  isSortable: boolean;
27
- field: CmsContentModelField;
28
+ field: CmsModelField;
28
29
  };
29
30
  savedOn: {
30
31
  type: string;
@@ -33,7 +34,7 @@ export declare const systemFields: {
33
34
  isSystemField: boolean;
34
35
  isSearchable: boolean;
35
36
  isSortable: boolean;
36
- field: CmsContentModelField;
37
+ field: CmsModelField;
37
38
  };
38
39
  createdOn: {
39
40
  type: string;
@@ -42,7 +43,7 @@ export declare const systemFields: {
42
43
  isSystemField: boolean;
43
44
  isSearchable: boolean;
44
45
  isSortable: boolean;
45
- field: CmsContentModelField;
46
+ field: CmsModelField;
46
47
  };
47
48
  createdBy: {
48
49
  type: string;
@@ -51,7 +52,7 @@ export declare const systemFields: {
51
52
  isSearchable: boolean;
52
53
  isSortable: boolean;
53
54
  path: string;
54
- field: CmsContentModelField;
55
+ field: CmsModelField;
55
56
  };
56
57
  ownedBy: {
57
58
  type: string;
@@ -60,7 +61,7 @@ export declare const systemFields: {
60
61
  isSearchable: boolean;
61
62
  isSortable: boolean;
62
63
  path: string;
63
- field: CmsContentModelField;
64
+ field: CmsModelField;
64
65
  };
65
66
  version: {
66
67
  type: string;
@@ -69,8 +70,8 @@ export declare const systemFields: {
69
70
  isSystemField: boolean;
70
71
  isSearchable: boolean;
71
72
  isSortable: boolean;
72
- field: CmsContentModelField;
73
+ field: CmsModelField;
73
74
  };
74
75
  };
75
- export declare const createModelFields: (context: CmsContext, model: CmsContentModel) => ModelFields;
76
+ export declare const createModelFields: (plugins: PluginsContainer, model: CmsModel) => ModelFields;
76
77
  export {};
package/helpers/fields.js CHANGED
@@ -117,9 +117,9 @@ const systemFields = {
117
117
 
118
118
  exports.systemFields = systemFields;
119
119
 
120
- const createModelFields = (context, model) => {
120
+ const createModelFields = (plugins, model) => {
121
121
  // collect all unmappedType from elastic plugins
122
- const unmappedTypes = context.plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
122
+ const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
123
123
  if (!plugin.unmappedType) {
124
124
  return acc;
125
125
  }
@@ -131,7 +131,7 @@ const createModelFields = (context, model) => {
131
131
  * collect all field types from the plugins
132
132
  */
133
133
 
134
- const fieldTypePlugins = context.plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
134
+ const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
135
135
  const {
136
136
  fieldType,
137
137
  isSearchable,
@@ -171,5 +171,4 @@ const createModelFields = (context, model) => {
171
171
  }, systemFields);
172
172
  };
173
173
 
174
- exports.createModelFields = createModelFields;
175
- //# sourceMappingURL=fields.js.map
174
+ exports.createModelFields = createModelFields;
package/helpers/index.js CHANGED
@@ -28,5 +28,4 @@ Object.keys(_entryIndexHelpers).forEach(function (key) {
28
28
  return _entryIndexHelpers[key];
29
29
  }
30
30
  });
31
- });
32
- //# sourceMappingURL=index.js.map
31
+ });
@@ -1,7 +1,7 @@
1
- import { CmsContext } from "@webiny/api-headless-cms/types";
2
1
  import { ElasticsearchQueryBuilderOperatorPlugin } from "@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
3
  interface OperatorPlugins {
4
4
  [operator: string]: ElasticsearchQueryBuilderOperatorPlugin;
5
5
  }
6
- export declare const operatorPluginsList: (context: CmsContext) => OperatorPlugins;
6
+ export declare const operatorPluginsList: (plugins: PluginsContainer) => OperatorPlugins;
7
7
  export {};
@@ -11,8 +11,8 @@ var _error = _interopRequireDefault(require("@webiny/error"));
11
11
 
12
12
  var _ElasticsearchQueryBuilderOperatorPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
13
13
 
14
- const operatorPluginsList = context => {
15
- return context.plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((plugins, plugin) => {
14
+ const operatorPluginsList = plugins => {
15
+ return plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((plugins, plugin) => {
16
16
  const operator = plugin.getOperator();
17
17
 
18
18
  if (plugins[operator]) {
@@ -27,5 +27,4 @@ const operatorPluginsList = context => {
27
27
  }, {});
28
28
  };
29
29
 
30
- exports.operatorPluginsList = operatorPluginsList;
31
- //# sourceMappingURL=operatorPluginsList.js.map
30
+ exports.operatorPluginsList = operatorPluginsList;