@webiny/api-headless-cms-ddb-es 6.0.0-alpha.5 → 6.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +6 -30
  2. package/configurations.d.ts +4 -5
  3. package/configurations.js +12 -24
  4. package/configurations.js.map +1 -1
  5. package/definitions/entry.d.ts +4 -6
  6. package/definitions/entry.js +5 -174
  7. package/definitions/entry.js.map +1 -1
  8. package/definitions/group.d.ts +6 -7
  9. package/definitions/group.js +5 -58
  10. package/definitions/group.js.map +1 -1
  11. package/definitions/model.d.ts +6 -7
  12. package/definitions/model.js +5 -102
  13. package/definitions/model.js.map +1 -1
  14. package/definitions/types.d.ts +59 -0
  15. package/definitions/types.js +3 -0
  16. package/definitions/types.js.map +1 -0
  17. package/dynamoDb/index.d.ts +2 -2
  18. package/dynamoDb/index.js +5 -13
  19. package/dynamoDb/index.js.map +1 -1
  20. package/dynamoDb/storage/longText.js +10 -18
  21. package/dynamoDb/storage/longText.js.map +1 -1
  22. package/dynamoDb/storage/richText.js +10 -18
  23. package/dynamoDb/storage/richText.js.map +1 -1
  24. package/elasticsearch/createElasticsearchIndex.d.ts +1 -1
  25. package/elasticsearch/createElasticsearchIndex.js +7 -15
  26. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  27. package/elasticsearch/deleteElasticsearchIndex.d.ts +1 -1
  28. package/elasticsearch/deleteElasticsearchIndex.js +3 -10
  29. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  30. package/elasticsearch/index.d.ts +1 -1
  31. package/elasticsearch/index.js +3 -11
  32. package/elasticsearch/index.js.map +1 -1
  33. package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
  34. package/elasticsearch/indexing/dateTimeIndexing.js +1 -8
  35. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  36. package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
  37. package/elasticsearch/indexing/defaultFieldIndexing.js +1 -8
  38. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  39. package/elasticsearch/indexing/index.d.ts +1 -1
  40. package/elasticsearch/indexing/index.js +8 -16
  41. package/elasticsearch/indexing/index.js.map +1 -1
  42. package/elasticsearch/indexing/jsonIndexing.d.ts +1 -1
  43. package/elasticsearch/indexing/jsonIndexing.js +1 -8
  44. package/elasticsearch/indexing/jsonIndexing.js.map +1 -1
  45. package/elasticsearch/indexing/longTextIndexing.d.ts +1 -1
  46. package/elasticsearch/indexing/longTextIndexing.js +1 -8
  47. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  48. package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
  49. package/elasticsearch/indexing/numberIndexing.js +1 -8
  50. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  51. package/elasticsearch/indexing/objectIndexing.d.ts +1 -1
  52. package/elasticsearch/indexing/objectIndexing.js +6 -13
  53. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  54. package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
  55. package/elasticsearch/indexing/richTextIndexing.js +1 -8
  56. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  57. package/elasticsearch/indices/base.d.ts +1 -1
  58. package/elasticsearch/indices/base.js +4 -10
  59. package/elasticsearch/indices/base.js.map +1 -1
  60. package/elasticsearch/indices/index.d.ts +1 -1
  61. package/elasticsearch/indices/index.js +3 -11
  62. package/elasticsearch/indices/index.js.map +1 -1
  63. package/elasticsearch/search/index.d.ts +1 -1
  64. package/elasticsearch/search/index.js +4 -11
  65. package/elasticsearch/search/index.js.map +1 -1
  66. package/elasticsearch/search/refSearch.d.ts +1 -1
  67. package/elasticsearch/search/refSearch.js +3 -10
  68. package/elasticsearch/search/refSearch.js.map +1 -1
  69. package/elasticsearch/search/searchableJson.d.ts +1 -1
  70. package/elasticsearch/search/searchableJson.js +9 -16
  71. package/elasticsearch/search/searchableJson.js.map +1 -1
  72. package/elasticsearch/search/timeSearch.d.ts +1 -1
  73. package/elasticsearch/search/timeSearch.js +3 -10
  74. package/elasticsearch/search/timeSearch.js.map +1 -1
  75. package/helpers/entryIndexHelpers.d.ts +9 -9
  76. package/helpers/entryIndexHelpers.js +32 -26
  77. package/helpers/entryIndexHelpers.js.map +1 -1
  78. package/helpers/fieldIdentifier.d.ts +1 -1
  79. package/helpers/fieldIdentifier.js +2 -10
  80. package/helpers/fieldIdentifier.js.map +1 -1
  81. package/helpers/index.d.ts +2 -2
  82. package/helpers/index.js +2 -27
  83. package/helpers/index.js.map +1 -1
  84. package/index.d.ts +2 -2
  85. package/index.js +98 -133
  86. package/index.js.map +1 -1
  87. package/operations/entry/dataLoader/DataLoaderCache.d.ts +0 -2
  88. package/operations/entry/dataLoader/DataLoaderCache.js +2 -9
  89. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  90. package/operations/entry/dataLoader/constants.js +1 -7
  91. package/operations/entry/dataLoader/constants.js.map +1 -1
  92. package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -10
  93. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  94. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
  95. package/operations/entry/dataLoader/getAllEntryRevisions.js +11 -24
  96. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  97. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
  98. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +18 -30
  99. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  100. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
  101. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +18 -30
  102. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  103. package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
  104. package/operations/entry/dataLoader/getRevisionById.js +23 -35
  105. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  106. package/operations/entry/dataLoader/index.d.ts +3 -3
  107. package/operations/entry/dataLoader/index.js +10 -31
  108. package/operations/entry/dataLoader/index.js.map +1 -1
  109. package/operations/entry/dataLoader/types.d.ts +3 -4
  110. package/operations/entry/dataLoader/types.js +1 -5
  111. package/operations/entry/dataLoader/types.js.map +1 -1
  112. package/operations/entry/dataLoaders.d.ts +13 -13
  113. package/operations/entry/dataLoaders.js +15 -25
  114. package/operations/entry/dataLoaders.js.map +1 -1
  115. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +1 -1
  116. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +1 -8
  117. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
  118. package/operations/entry/elasticsearch/body.d.ts +2 -2
  119. package/operations/entry/elasticsearch/body.js +21 -28
  120. package/operations/entry/elasticsearch/body.js.map +1 -1
  121. package/operations/entry/elasticsearch/fields.d.ts +2 -2
  122. package/operations/entry/elasticsearch/fields.js +110 -24
  123. package/operations/entry/elasticsearch/fields.js.map +1 -1
  124. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +2 -2
  125. package/operations/entry/elasticsearch/filtering/applyFiltering.js +9 -17
  126. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  127. package/operations/entry/elasticsearch/filtering/exec.d.ts +6 -5
  128. package/operations/entry/elasticsearch/filtering/exec.js +48 -45
  129. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  130. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -1
  131. package/operations/entry/elasticsearch/filtering/index.js +1 -16
  132. package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
  133. package/operations/entry/elasticsearch/filtering/path.d.ts +1 -1
  134. package/operations/entry/elasticsearch/filtering/path.js +5 -15
  135. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  136. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +1 -1
  137. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +6 -14
  138. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
  139. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -1
  140. package/operations/entry/elasticsearch/filtering/plugins/index.js +5 -12
  141. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
  142. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +1 -1
  143. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +7 -15
  144. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
  145. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +1 -1
  146. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +7 -15
  147. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
  148. package/operations/entry/elasticsearch/filtering/populated.d.ts +1 -1
  149. package/operations/entry/elasticsearch/filtering/populated.js +1 -8
  150. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  151. package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
  152. package/operations/entry/elasticsearch/filtering/values.js +4 -12
  153. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  154. package/operations/entry/elasticsearch/fullTextSearch.d.ts +2 -2
  155. package/operations/entry/elasticsearch/fullTextSearch.js +6 -12
  156. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  157. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +1 -1
  158. package/operations/entry/elasticsearch/fullTextSearchFields.js +1 -8
  159. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  160. package/operations/entry/elasticsearch/initialQuery.d.ts +2 -2
  161. package/operations/entry/elasticsearch/initialQuery.js +9 -27
  162. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  163. package/operations/entry/elasticsearch/keyword.d.ts +1 -1
  164. package/operations/entry/elasticsearch/keyword.js +4 -9
  165. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  166. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +2 -2
  167. package/operations/entry/elasticsearch/plugins/bodyModifier.js +3 -10
  168. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
  169. package/operations/entry/elasticsearch/plugins/operator.d.ts +1 -2
  170. package/operations/entry/elasticsearch/plugins/operator.js +4 -19
  171. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  172. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +2 -2
  173. package/operations/entry/elasticsearch/plugins/queryModifier.js +3 -10
  174. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
  175. package/operations/entry/elasticsearch/plugins/search.d.ts +1 -1
  176. package/operations/entry/elasticsearch/plugins/search.js +5 -13
  177. package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
  178. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +2 -2
  179. package/operations/entry/elasticsearch/plugins/sortModifier.js +3 -10
  180. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
  181. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +1 -8
  182. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
  183. package/operations/entry/elasticsearch/sort.d.ts +3 -3
  184. package/operations/entry/elasticsearch/sort.js +51 -33
  185. package/operations/entry/elasticsearch/sort.js.map +1 -1
  186. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +2 -2
  187. package/operations/entry/elasticsearch/transformValueForSearch.js +4 -9
  188. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  189. package/operations/entry/elasticsearch/types.d.ts +2 -2
  190. package/operations/entry/elasticsearch/types.js +1 -5
  191. package/operations/entry/elasticsearch/types.js.map +1 -1
  192. package/operations/entry/index.d.ts +5 -4
  193. package/operations/entry/index.js +333 -515
  194. package/operations/entry/index.js.map +1 -1
  195. package/operations/entry/keys.d.ts +31 -1
  196. package/operations/entry/keys.js +56 -19
  197. package/operations/entry/keys.js.map +1 -1
  198. package/operations/entry/recordType.js +3 -12
  199. package/operations/entry/recordType.js.map +1 -1
  200. package/operations/entry/transformations/convertEntryKeys.d.ts +6 -6
  201. package/operations/entry/transformations/convertEntryKeys.js +2 -10
  202. package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
  203. package/operations/entry/transformations/index.d.ts +16 -16
  204. package/operations/entry/transformations/index.js +22 -30
  205. package/operations/entry/transformations/index.js.map +1 -1
  206. package/operations/entry/transformations/modifyEntryValues.d.ts +27 -34
  207. package/operations/entry/transformations/modifyEntryValues.js +1 -8
  208. package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
  209. package/operations/entry/transformations/transformEntryKeys.d.ts +8 -8
  210. package/operations/entry/transformations/transformEntryKeys.js +4 -11
  211. package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
  212. package/operations/entry/transformations/transformEntryToIndex.d.ts +6 -6
  213. package/operations/entry/transformations/transformEntryToIndex.js +3 -10
  214. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
  215. package/operations/group/index.d.ts +5 -4
  216. package/operations/group/index.js +39 -73
  217. package/operations/group/index.js.map +1 -1
  218. package/operations/model/index.d.ts +3 -3
  219. package/operations/model/index.js +38 -57
  220. package/operations/model/index.js.map +1 -1
  221. package/package.json +27 -32
  222. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +1 -1
  223. package/plugins/CmsElasticsearchModelFieldPlugin.js +2 -8
  224. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -1
  225. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -1
  226. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +3 -11
  227. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  228. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +2 -2
  229. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +3 -11
  230. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
  231. package/plugins/CmsEntryElasticsearchIndexPlugin.js +2 -9
  232. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  233. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +2 -2
  234. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +3 -11
  235. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  236. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -1
  237. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +3 -11
  238. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  239. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -1
  240. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +3 -11
  241. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  242. package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +12 -12
  243. package/plugins/CmsEntryElasticsearchValuesModifier.js +4 -12
  244. package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -1
  245. package/plugins/CmsEntryFilterPlugin.d.ts +3 -3
  246. package/plugins/CmsEntryFilterPlugin.js +2 -9
  247. package/plugins/CmsEntryFilterPlugin.js.map +1 -1
  248. package/plugins/index.d.ts +8 -8
  249. package/plugins/index.js +8 -93
  250. package/plugins/index.js.map +1 -1
  251. package/tasks/createIndexTaskPlugin.d.ts +2 -2
  252. package/tasks/createIndexTaskPlugin.js +36 -62
  253. package/tasks/createIndexTaskPlugin.js.map +1 -1
  254. package/types.d.ts +23 -26
  255. package/types.js +5 -8
  256. package/types.js.map +1 -1
  257. package/values/NoValueContainer.js +1 -8
  258. package/values/NoValueContainer.js.map +1 -1
  259. package/definitions/entryElasticsearch.d.ts +0 -9
  260. package/definitions/entryElasticsearch.js +0 -41
  261. package/definitions/entryElasticsearch.js.map +0 -1
  262. package/definitions/system.d.ts +0 -9
  263. package/definitions/system.js +0 -42
  264. package/definitions/system.js.map +0 -1
  265. package/definitions/table.d.ts +0 -8
  266. package/definitions/table.js +0 -25
  267. package/definitions/table.js.map +0 -1
  268. package/definitions/tableElasticsearch.d.ts +0 -8
  269. package/definitions/tableElasticsearch.js +0 -25
  270. package/definitions/tableElasticsearch.js.map +0 -1
  271. package/elasticsearch/indices/japanese.d.ts +0 -2
  272. package/elasticsearch/indices/japanese.js +0 -14
  273. package/elasticsearch/indices/japanese.js.map +0 -1
  274. package/operations/entry/elasticsearch/logIgnoredEsResponseError.d.ts +0 -9
  275. package/operations/entry/elasticsearch/logIgnoredEsResponseError.js +0 -26
  276. package/operations/entry/elasticsearch/logIgnoredEsResponseError.js.map +0 -1
  277. package/operations/system/index.d.ts +0 -6
  278. package/operations/system/index.js +0 -94
  279. package/operations/system/index.js.map +0 -1
  280. package/operations/system/indexes.d.ts +0 -10
  281. package/operations/system/indexes.js +0 -41
  282. package/operations/system/indexes.js.map +0 -1
@@ -1,13 +1,7 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.prepareEntryToIndex = exports.extractEntriesFromIndex = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _fieldIdentifier = require("./fieldIdentifier");
10
- const prepareEntryToIndex = params => {
1
+ import WebinyError from "@webiny/error";
2
+ import { getFieldIdentifier, getFieldIdentifiers } from "./fieldIdentifier.js";
3
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
4
+ export const prepareEntryToIndex = params => {
11
5
  const {
12
6
  plugins,
13
7
  storageEntry,
@@ -21,15 +15,21 @@ const prepareEntryToIndex = params => {
21
15
  } = setupEntriesIndexHelpers({
22
16
  plugins
23
17
  });
24
- function getFieldIndexPlugin(fieldType) {
18
+ function getFieldIndexPlugin(type) {
19
+ const fieldType = getBaseFieldType({
20
+ type
21
+ });
25
22
  return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
26
23
  }
27
- function getFieldTypePlugin(fieldType) {
24
+ function getFieldTypePlugin(type) {
25
+ const fieldType = getBaseFieldType({
26
+ type
27
+ });
28
28
  const pl = fieldTypePlugins[fieldType];
29
29
  if (pl) {
30
30
  return pl;
31
31
  }
32
- throw new _error.default(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
32
+ throw new WebinyError(`Missing field type plugin "${fieldType}". Prepare entry for index.`);
33
33
  }
34
34
 
35
35
  // These objects will contain values processed by field index plugins
@@ -38,7 +38,7 @@ const prepareEntryToIndex = params => {
38
38
 
39
39
  // We're only interested in current model fields.
40
40
  for (const field of model.fields) {
41
- const identifier = (0, _fieldIdentifier.getFieldIdentifier)(storageEntry.values, field);
41
+ const identifier = getFieldIdentifier(storageEntry.values, field);
42
42
  if (!identifier) {
43
43
  continue;
44
44
  }
@@ -73,7 +73,6 @@ const prepareEntryToIndex = params => {
73
73
  rawValues
74
74
  };
75
75
  };
76
- exports.prepareEntryToIndex = prepareEntryToIndex;
77
76
  const setupEntriesIndexHelpers = ({
78
77
  plugins: pluginsContainer
79
78
  }) => {
@@ -99,7 +98,7 @@ const setupEntriesIndexHelpers = ({
99
98
  fieldTypePlugins
100
99
  };
101
100
  };
102
- const extractEntriesFromIndex = ({
101
+ export const extractEntriesFromIndex = ({
103
102
  plugins,
104
103
  entries,
105
104
  model
@@ -111,10 +110,16 @@ const extractEntriesFromIndex = ({
111
110
  } = setupEntriesIndexHelpers({
112
111
  plugins
113
112
  });
114
- function getFieldIndexPlugin(fieldType) {
113
+ function getFieldIndexPlugin(type) {
114
+ const fieldType = getBaseFieldType({
115
+ type
116
+ });
115
117
  return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;
116
118
  }
117
- function getFieldTypePlugin(fieldType) {
119
+ function getFieldTypePlugin(type) {
120
+ const fieldType = getBaseFieldType({
121
+ type
122
+ });
118
123
  return fieldTypePlugins[fieldType];
119
124
  }
120
125
  const list = [];
@@ -124,9 +129,9 @@ const extractEntriesFromIndex = ({
124
129
 
125
130
  // We only consider fields that are present in the model
126
131
  for (const field of model.fields) {
127
- const fieldTypePlugin = fieldTypePlugins[field.type];
132
+ const fieldTypePlugin = getFieldTypePlugin(field.type);
128
133
  if (!fieldTypePlugin) {
129
- throw new _error.default(`Missing field type plugin "${field.type}". Extract entries from index.`);
134
+ throw new WebinyError(`Missing field type plugin "${field.type}". Extract entries from index.`);
130
135
  }
131
136
  const targetFieldPlugin = getFieldIndexPlugin(field.type);
132
137
  if (!targetFieldPlugin || !targetFieldPlugin.fromIndex) {
@@ -135,25 +140,27 @@ const extractEntriesFromIndex = ({
135
140
  /**
136
141
  * We can safely cast as the code will not continue in case of no identifiers.
137
142
  */
138
- const identifiers = (0, _fieldIdentifier.getFieldIdentifiers)(entry.values, entry.rawValues, field);
143
+ const identifiers = getFieldIdentifiers(entry.values, entry.rawValues, field);
139
144
  if (!identifiers) {
140
145
  continue;
141
146
  }
142
147
  try {
143
- indexValues[identifiers.valueIdentifier] = targetFieldPlugin.fromIndex({
148
+ const key = identifiers.valueIdentifier;
149
+ const rawKey = identifiers.rawValueIdentifier;
150
+ indexValues[key] = targetFieldPlugin.fromIndex({
144
151
  plugins,
145
152
  model,
146
153
  field,
147
154
  getFieldIndexPlugin,
148
155
  getFieldTypePlugin,
149
- value: entry.values[identifiers.valueIdentifier || identifiers.rawValueIdentifier],
156
+ value: entry.values[key || rawKey],
150
157
  /**
151
158
  * Possibly no rawValues so we must check for the existence of the field.
152
159
  */
153
- rawValue: entry.rawValues ? entry.rawValues[identifiers.rawValueIdentifier || identifiers.valueIdentifier] : null
160
+ rawValue: entry.rawValues ? entry.rawValues[rawKey || key] : null
154
161
  });
155
162
  } catch (ex) {
156
- throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
163
+ throw new WebinyError(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
157
164
  field,
158
165
  entry
159
166
  });
@@ -185,6 +192,5 @@ const extractEntriesFromIndex = ({
185
192
  }
186
193
  return list;
187
194
  };
188
- exports.extractEntriesFromIndex = extractEntriesFromIndex;
189
195
 
190
196
  //# sourceMappingURL=entryIndexHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_fieldIdentifier","prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","fieldType","getFieldTypePlugin","pl","WebinyError","values","rawValues","field","fields","identifier","getFieldIdentifier","targetFieldPlugin","type","toIndex","value","rawValue","exports","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","identifiers","getFieldIdentifiers","valueIdentifier","rawValueIdentifier","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsModel,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport type { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { getFieldIdentifier, getFieldIdentifiers } from \"~/helpers/fieldIdentifier\";\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 const identifier = getFieldIdentifier(storageEntry.values, field);\n if (!identifier) {\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[identifier],\n value: storageEntry.values[identifier],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[identifier] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[identifier] = 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 /**\n * We can safely cast as the code will not continue in case of no identifiers.\n */\n const identifiers = getFieldIdentifiers(entry.values, entry.rawValues, field);\n if (!identifiers) {\n continue;\n }\n\n try {\n indexValues[identifiers.valueIdentifier] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[\n identifiers.valueIdentifier || identifiers.rawValueIdentifier\n ],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues\n ? entry.rawValues[\n identifiers.rawValueIdentifier || identifiers.valueIdentifier\n ]\n : 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-expect-error\n delete newEntry[\"rawValues\"];\n // @ts-expect-error\n delete newEntry[\"TYPE\"];\n // @ts-expect-error\n delete newEntry[\"__type\"];\n // @ts-expect-error\n delete newEntry[\"latest\"];\n // @ts-expect-error\n delete newEntry[\"published\"];\n list.push({ ...newEntry });\n }\n\n return list;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,gBAAA,GAAAD,OAAA;AAiBO,MAAME,mBAAmB,GAAIC,MAAsC,IAAoB;EAC1F,MAAM;IAAEC,OAAO;IAAEC,YAAY;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EACtD,MAAM;IAAEK,iBAAiB;IAAEC,uBAAuB;IAAEC;EAAiB,CAAC,GAClEC,wBAAwB,CAAC;IAAEP;EAAQ,CAAC,CAAC;EAEzC,SAASQ,mBAAmBA,CAACC,SAAiB,EAAE;IAC5C,OAAOL,iBAAiB,CAACK,SAAS,CAAC,IAAIJ,uBAAuB;EAClE;EAEA,SAASK,kBAAkBA,CAACD,SAAiB,EAAE;IAC3C,MAAME,EAAE,GAAGL,gBAAgB,CAACG,SAAS,CAAC;IACtC,IAAIE,EAAE,EAAE;MACJ,OAAOA,EAAE;IACb;IACA,MAAM,IAAIC,cAAW,CAAC,8BAA8BH,SAAS,6BAA6B,CAAC;EAC/F;;EAEA;EACA,MAAMI,MAA8B,GAAG,CAAC,CAAC;EACzC,MAAMC,SAAiC,GAAG,CAAC,CAAC;;EAE5C;EACA,KAAK,MAAMC,KAAK,IAAIZ,KAAK,CAACa,MAAM,EAAE;IAC9B,MAAMC,UAAU,GAAG,IAAAC,mCAAkB,EAACjB,YAAY,CAACY,MAAM,EAAEE,KAAK,CAAC;IACjE,IAAI,CAACE,UAAU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ACf,CAAC;AAACT,OAAA,CAAAO,uBAAA,GAAAA,uBAAA","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","getFieldIdentifier","getFieldIdentifiers","getBaseFieldType","prepareEntryToIndex","params","plugins","storageEntry","entry","model","fieldIndexPlugins","defaultIndexFieldPlugin","fieldTypePlugins","setupEntriesIndexHelpers","getFieldIndexPlugin","type","fieldType","getFieldTypePlugin","pl","values","rawValues","field","fields","identifier","targetFieldPlugin","toIndex","value","rawValue","pluginsContainer","byType","plugin","reverse","find","reduce","extractEntriesFromIndex","entries","list","indexValues","fieldTypePlugin","fromIndex","identifiers","key","valueIdentifier","rawKey","rawValueIdentifier","ex","message","code","newEntry","push"],"sources":["entryIndexHelpers.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsIndexEntry, CmsModelFieldToElasticsearchPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { getFieldIdentifier, getFieldIdentifiers } from \"~/helpers/fieldIdentifier.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface SetupEntriesIndexHelpersParams {\n plugins: PluginsContainer;\n}\n\ninterface ExtractEntriesFromIndexParams<T extends CmsEntryValues = CmsEntryValues>\n extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entries: CmsIndexEntry<T>[];\n}\n\ninterface PrepareElasticsearchDataParams<T extends CmsEntryValues = CmsEntryValues>\n extends SetupEntriesIndexHelpersParams {\n model: CmsModel;\n entry: CmsEntry<T>;\n storageEntry: CmsEntry<T>;\n}\n\nexport const prepareEntryToIndex = <T extends CmsEntryValues = CmsEntryValues>(\n params: PrepareElasticsearchDataParams<T>\n): CmsIndexEntry<T> => {\n const { plugins, storageEntry, entry, model } = params;\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\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: T = {} as T;\n const rawValues: T = {} as T;\n\n // We're only interested in current model fields.\n for (const field of model.fields) {\n const identifier = getFieldIdentifier(storageEntry.values, field) as keyof T;\n if (!identifier) {\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[identifier],\n value: storageEntry.values[identifier],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (typeof value !== \"undefined\") {\n values[identifier] = value;\n }\n\n if (typeof rawValue !== \"undefined\") {\n rawValues[identifier] = rawValue;\n }\n }\n return {\n ...storageEntry,\n values,\n rawValues\n };\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 = <T extends CmsEntryValues = CmsEntryValues>({\n plugins,\n entries,\n model\n}: ExtractEntriesFromIndexParams<T>): CmsEntry<T>[] => {\n const { fieldIndexPlugins, defaultIndexFieldPlugin, fieldTypePlugins } =\n setupEntriesIndexHelpers({ plugins });\n\n function getFieldIndexPlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldIndexPlugins[fieldType] || defaultIndexFieldPlugin;\n }\n\n function getFieldTypePlugin(type: string) {\n const fieldType = getBaseFieldType({\n type\n });\n return fieldTypePlugins[fieldType];\n }\n\n const list: CmsEntry<T>[] = [];\n\n for (const entry of entries) {\n // This object will contain values processed by field index plugins\n const indexValues: T = {} as T;\n\n // We only consider fields that are present in the model\n for (const field of model.fields) {\n const fieldTypePlugin = getFieldTypePlugin(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 /**\n * We can safely cast as the code will not continue in case of no identifiers.\n */\n const identifiers = getFieldIdentifiers(entry.values, entry.rawValues, field);\n if (!identifiers) {\n continue;\n }\n\n try {\n const key = identifiers.valueIdentifier as keyof T;\n const rawKey = identifiers.rawValueIdentifier as keyof T;\n indexValues[key] = targetFieldPlugin.fromIndex({\n plugins,\n model,\n field,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n value: entry.values[key || rawKey],\n /**\n * Possibly no rawValues so we must check for the existence of the field.\n */\n rawValue: entry.rawValues ? entry.rawValues[rawKey || key] : 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<T> = {\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-expect-error\n delete newEntry[\"rawValues\"];\n // @ts-expect-error\n delete newEntry[\"TYPE\"];\n // @ts-expect-error\n delete newEntry[\"__type\"];\n // @ts-expect-error\n delete newEntry[\"latest\"];\n // @ts-expect-error\n delete newEntry[\"published\"];\n list.push({\n ...newEntry\n });\n }\n\n return list;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AASvC,SAASC,kBAAkB,EAAEC,mBAAmB;AAChD,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,OAAO,MAAMC,mBAAmB,GAC5BC,MAAyC,IACtB;EACnB,MAAM;IAAEC,OAAO;IAAEC,YAAY;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EACtD,MAAM;IAAEK,iBAAiB;IAAEC,uBAAuB;IAAEC;EAAiB,CAAC,GAClEC,wBAAwB,CAAC;IAAEP;EAAQ,CAAC,CAAC;EAEzC,SAASQ,mBAAmBA,CAACC,IAAY,EAAE;IACvC,MAAMC,SAAS,GAAGb,gBAAgB,CAAC;MAC/BY;IACJ,CAAC,CAAC;IACF,OAAOL,iBAAiB,CAACM,SAAS,CAAC,IAAIL,uBAAuB;EAClE;EAEA,SAASM,kBAAkBA,CAACF,IAAY,EAAE;IACtC,MAAMC,SAAS,GAAGb,gBAAgB,CAAC;MAC/BY;IACJ,CAAC,CAAC;IACF,MAAMG,EAAE,GAAGN,gBAAgB,CAACI,SAAS,CAAC;IACtC,IAAIE,EAAE,EAAE;MACJ,OAAOA,EAAE;IACb;IACA,MAAM,IAAIlB,WAAW,CAAC,8BAA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AqB,GAAG;MAC1B,GAAGxC,KAAK;MACRW,MAAM,EAAEkB;IACZ,CAAC;IACD;AACR;AACA;IACQ;IACA,OAAOW,QAAQ,CAAC,WAAW,CAAC;IAC5B;IACA,OAAOA,QAAQ,CAAC,MAAM,CAAC;IACvB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,QAAQ,CAAC;IACzB;IACA,OAAOA,QAAQ,CAAC,WAAW,CAAC;IAC5BZ,IAAI,CAACa,IAAI,CAAC;MACN,GAAGD;IACP,CAAC,CAAC;EACN;EAEA,OAAOZ,IAAI;AACf,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { CmsEntryValues, CmsModelField } from "@webiny/api-headless-cms/types";
1
+ import type { CmsEntryValues, CmsModelField } from "@webiny/api-headless-cms/types/index.js";
2
2
  export declare const getFieldIdentifier: (values: CmsEntryValues | null | undefined, field: CmsModelField) => string | undefined;
3
3
  export declare const getFieldIdentifiers: (values: CmsEntryValues, rawValues: CmsEntryValues | null | undefined, field: CmsModelField) => {
4
4
  valueIdentifier: string;
@@ -1,9 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getFieldIdentifiers = exports.getFieldIdentifier = void 0;
7
1
  const hasOwnProperty = (values = {}, property) => {
8
2
  if (!values) {
9
3
  return false;
@@ -12,7 +6,7 @@ const hasOwnProperty = (values = {}, property) => {
12
6
  }
13
7
  return values[property] !== undefined;
14
8
  };
15
- const getFieldIdentifier = (values, field) => {
9
+ export const getFieldIdentifier = (values, field) => {
16
10
  if (field.storageId && hasOwnProperty(values, field.storageId)) {
17
11
  return field.storageId;
18
12
  } else if (hasOwnProperty(values, field.fieldId)) {
@@ -20,8 +14,7 @@ const getFieldIdentifier = (values, field) => {
20
14
  }
21
15
  return undefined;
22
16
  };
23
- exports.getFieldIdentifier = getFieldIdentifier;
24
- const getFieldIdentifiers = (values, rawValues, field) => {
17
+ export const getFieldIdentifiers = (values, rawValues, field) => {
25
18
  let valueIdentifier = getFieldIdentifier(values, field);
26
19
  let rawValueIdentifier = getFieldIdentifier(rawValues, field);
27
20
  if (!valueIdentifier && !rawValueIdentifier) {
@@ -38,6 +31,5 @@ const getFieldIdentifiers = (values, rawValues, field) => {
38
31
  rawValueIdentifier
39
32
  };
40
33
  };
41
- exports.getFieldIdentifiers = getFieldIdentifiers;
42
34
 
43
35
  //# sourceMappingURL=fieldIdentifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["hasOwnProperty","values","property","undefined","getFieldIdentifier","field","storageId","fieldId","exports","getFieldIdentifiers","rawValues","valueIdentifier","rawValueIdentifier"],"sources":["fieldIdentifier.ts"],"sourcesContent":["import type { CmsEntryValues, CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nconst hasOwnProperty = (\n values: CmsEntryValues | null | undefined = {},\n property: string\n): boolean => {\n if (!values) {\n return false;\n } else if (values.hasOwnProperty) {\n return values.hasOwnProperty(property);\n }\n return values[property] !== undefined;\n};\n\nexport const getFieldIdentifier = (\n values: CmsEntryValues | null | undefined,\n field: CmsModelField\n): string | undefined => {\n if (field.storageId && hasOwnProperty(values, field.storageId)) {\n return field.storageId;\n } else if (hasOwnProperty(values, field.fieldId)) {\n return field.fieldId;\n }\n return undefined;\n};\n\nexport const getFieldIdentifiers = (\n values: CmsEntryValues,\n rawValues: CmsEntryValues | null | undefined,\n field: CmsModelField\n) => {\n let valueIdentifier = getFieldIdentifier(values, field);\n let rawValueIdentifier = getFieldIdentifier(rawValues, field);\n if (!valueIdentifier && !rawValueIdentifier) {\n return null;\n }\n if (!valueIdentifier) {\n valueIdentifier = rawValueIdentifier as string;\n }\n if (!rawValueIdentifier) {\n rawValueIdentifier = valueIdentifier as string;\n }\n return {\n valueIdentifier,\n rawValueIdentifier\n };\n};\n"],"mappings":";;;;;;AAEA,MAAMA,cAAc,GAAGA,CACnBC,MAAyC,GAAG,CAAC,CAAC,EAC9CC,QAAgB,KACN;EACV,IAAI,CAACD,MAAM,EAAE;IACT,OAAO,KAAK;EAChB,CAAC,MAAM,IAAIA,MAAM,CAACD,cAAc,EAAE;IAC9B,OAAOC,MAAM,CAACD,cAAc,CAACE,QAAQ,CAAC;EAC1C;EACA,OAAOD,MAAM,CAACC,QAAQ,CAAC,KAAKC,SAAS;AACzC,CAAC;AAEM,MAAMC,kBAAkB,GAAGA,CAC9BH,MAAyC,EACzCI,KAAoB,KACC;EACrB,IAAIA,KAAK,CAACC,SAAS,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACC,SAAS,CAAC,EAAE;IAC5D,OAAOD,KAAK,CAACC,SAAS;EAC1B,CAAC,MAAM,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACE,OAAO,CAAC,EAAE;IAC9C,OAAOF,KAAK,CAACE,OAAO;EACxB;EACA,OAAOJ,SAAS;AACpB,CAAC;AAACK,OAAA,CAAAJ,kBAAA,GAAAA,kBAAA;AAEK,MAAMK,mBAAmB,GAAGA,CAC/BR,MAAsB,EACtBS,SAA4C,EAC5CL,KAAoB,KACnB;EACD,IAAIM,eAAe,GAAGP,kBAAkB,CAACH,MAAM,EAAEI,KAAK,CAAC;EACvD,IAAIO,kBAAkB,GAAGR,kBAAkB,CAACM,SAAS,EAAEL,KAAK,CAAC;EAC7D,IAAI,CAACM,eAAe,IAAI,CAACC,kBAAkB,EAAE;IACzC,OAAO,IAAI;EACf;EACA,IAAI,CAACD,eAAe,EAAE;IAClBA,eAAe,GAAGC,kBAA4B;EAClD;EACA,IAAI,CAACA,kBAAkB,EAAE;IACrBA,kBAAkB,GAAGD,eAAyB;EAClD;EACA,OAAO;IACHA,eAAe;IACfC;EACJ,CAAC;AACL,CAAC;AAACJ,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["hasOwnProperty","values","property","undefined","getFieldIdentifier","field","storageId","fieldId","getFieldIdentifiers","rawValues","valueIdentifier","rawValueIdentifier"],"sources":["fieldIdentifier.ts"],"sourcesContent":["import type { CmsEntryValues, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst hasOwnProperty = (\n values: CmsEntryValues | null | undefined = {},\n property: string\n): boolean => {\n if (!values) {\n return false;\n } else if (values.hasOwnProperty) {\n return values.hasOwnProperty(property);\n }\n return values[property] !== undefined;\n};\n\nexport const getFieldIdentifier = (\n values: CmsEntryValues | null | undefined,\n field: CmsModelField\n): string | undefined => {\n if (field.storageId && hasOwnProperty(values, field.storageId)) {\n return field.storageId;\n } else if (hasOwnProperty(values, field.fieldId)) {\n return field.fieldId;\n }\n return undefined;\n};\n\nexport const getFieldIdentifiers = (\n values: CmsEntryValues,\n rawValues: CmsEntryValues | null | undefined,\n field: CmsModelField\n) => {\n let valueIdentifier = getFieldIdentifier(values, field);\n let rawValueIdentifier = getFieldIdentifier(rawValues, field);\n if (!valueIdentifier && !rawValueIdentifier) {\n return null;\n }\n if (!valueIdentifier) {\n valueIdentifier = rawValueIdentifier as string;\n }\n if (!rawValueIdentifier) {\n rawValueIdentifier = valueIdentifier as string;\n }\n return {\n valueIdentifier,\n rawValueIdentifier\n };\n};\n"],"mappings":"AAEA,MAAMA,cAAc,GAAGA,CACnBC,MAAyC,GAAG,CAAC,CAAC,EAC9CC,QAAgB,KACN;EACV,IAAI,CAACD,MAAM,EAAE;IACT,OAAO,KAAK;EAChB,CAAC,MAAM,IAAIA,MAAM,CAACD,cAAc,EAAE;IAC9B,OAAOC,MAAM,CAACD,cAAc,CAACE,QAAQ,CAAC;EAC1C;EACA,OAAOD,MAAM,CAACC,QAAQ,CAAC,KAAKC,SAAS;AACzC,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAAGA,CAC9BH,MAAyC,EACzCI,KAAoB,KACC;EACrB,IAAIA,KAAK,CAACC,SAAS,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACC,SAAS,CAAC,EAAE;IAC5D,OAAOD,KAAK,CAACC,SAAS;EAC1B,CAAC,MAAM,IAAIN,cAAc,CAACC,MAAM,EAAEI,KAAK,CAACE,OAAO,CAAC,EAAE;IAC9C,OAAOF,KAAK,CAACE,OAAO;EACxB;EACA,OAAOJ,SAAS;AACpB,CAAC;AAED,OAAO,MAAMK,mBAAmB,GAAGA,CAC/BP,MAAsB,EACtBQ,SAA4C,EAC5CJ,KAAoB,KACnB;EACD,IAAIK,eAAe,GAAGN,kBAAkB,CAACH,MAAM,EAAEI,KAAK,CAAC;EACvD,IAAIM,kBAAkB,GAAGP,kBAAkB,CAACK,SAAS,EAAEJ,KAAK,CAAC;EAC7D,IAAI,CAACK,eAAe,IAAI,CAACC,kBAAkB,EAAE;IACzC,OAAO,IAAI;EACf;EACA,IAAI,CAACD,eAAe,EAAE;IAClBA,eAAe,GAAGC,kBAA4B;EAClD;EACA,IAAI,CAACA,kBAAkB,EAAE;IACrBA,kBAAkB,GAAGD,eAAyB;EAClD;EACA,OAAO;IACHA,eAAe;IACfC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- export * from "./entryIndexHelpers";
2
- export * from "./fieldIdentifier";
1
+ export * from "./entryIndexHelpers.js";
2
+ export * from "./fieldIdentifier.js";
package/helpers/index.js CHANGED
@@ -1,29 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _entryIndexHelpers = require("./entryIndexHelpers");
7
- Object.keys(_entryIndexHelpers).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _entryIndexHelpers[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _entryIndexHelpers[key];
14
- }
15
- });
16
- });
17
- var _fieldIdentifier = require("./fieldIdentifier");
18
- Object.keys(_fieldIdentifier).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _fieldIdentifier[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _fieldIdentifier[key];
25
- }
26
- });
27
- });
1
+ export * from "./entryIndexHelpers.js";
2
+ export * from "./fieldIdentifier.js";
28
3
 
29
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_entryIndexHelpers","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_fieldIdentifier"],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers\";\nexport * from \"./fieldIdentifier\";\n"],"mappings":";;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,kBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,kBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,kBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,gBAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,gBAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,gBAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,gBAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./entryIndexHelpers.js\";\nexport * from \"./fieldIdentifier.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { StorageOperationsFactory } from "./types";
2
- export * from "./plugins";
1
+ import type { StorageOperationsFactory } from "./types.js";
2
+ export * from "./plugins/index.js";
3
3
  export declare const createStorageOperations: StorageOperationsFactory;
package/index.js CHANGED
@@ -1,122 +1,90 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- var _exportNames = {
8
- createStorageOperations: true
9
- };
10
- exports.createStorageOperations = void 0;
11
- var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
12
- var _elasticsearch = _interopRequireDefault(require("./elasticsearch"));
13
- var _dynamoDb = _interopRequireDefault(require("./dynamoDb"));
14
- var _system = require("./operations/system");
15
- var _model = require("./operations/model");
16
- var _entry = require("./operations/entry");
17
- var _types = require("./types");
18
- var _table = require("./definitions/table");
19
- var _tableElasticsearch = require("./definitions/tableElasticsearch");
20
- var _group = require("./definitions/group");
21
- var _model2 = require("./definitions/model");
22
- var _entry2 = require("./definitions/entry");
23
- var _entryElasticsearch = require("./definitions/entryElasticsearch");
24
- var _system2 = require("./definitions/system");
25
- var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
26
- var _plugins = require("@webiny/plugins");
27
- var _group2 = require("./operations/group");
28
- var _apiElasticsearch = require("@webiny/api-elasticsearch");
29
- var _indices = require("./elasticsearch/indices");
30
- var _deleteElasticsearchIndex = require("./elasticsearch/deleteElasticsearchIndex");
31
- var _plugins2 = require("./plugins");
32
- Object.keys(_plugins2).forEach(function (key) {
33
- if (key === "default" || key === "__esModule") return;
34
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
- if (key in exports && exports[key] === _plugins2[key]) return;
36
- Object.defineProperty(exports, key, {
37
- enumerable: true,
38
- get: function () {
39
- return _plugins2[key];
40
- }
41
- });
42
- });
43
- var _plugins3 = require("./operations/entry/elasticsearch/filtering/plugins");
44
- var _CmsEntryFilterPlugin = require("./plugins/CmsEntryFilterPlugin");
45
- var _apiHeadlessCms = require("@webiny/api-headless-cms");
46
- var _indexes = require("./operations/system/indexes");
47
- var _createIndexTaskPlugin = require("./tasks/createIndexTaskPlugin");
48
- var _api = require("@webiny/api");
49
- const createStorageOperations = params => {
1
+ import dynamoDbValueFilters from "@webiny/db-dynamodb/plugins/filters/index.js";
2
+ import elasticsearchPlugins from "./elasticsearch/index.js";
3
+ import dynamoDbPlugins from "./dynamoDb/index.js";
4
+ import { createModelsStorageOperations } from "./operations/model/index.js";
5
+ import { createEntriesStorageOperations } from "./operations/entry/index.js";
6
+ import { ENTITIES } from "./types.js";
7
+ import { createGroupEntity } from "./definitions/group.js";
8
+ import { createModelEntity } from "./definitions/model.js";
9
+ import { createEntryEntity } from "./definitions/entry.js";
10
+ import { createElasticsearchIndex } from "./elasticsearch/createElasticsearchIndex.js";
11
+ import { PluginsContainer } from "@webiny/plugins";
12
+ import { createGroupsStorageOperations } from "./operations/group/index.js";
13
+ import { createElasticsearchEntity, createElasticsearchTable, ElasticsearchQueryBuilderOperatorPlugin } from "@webiny/api-elasticsearch";
14
+ import { elasticsearchIndexPlugins } from "./elasticsearch/indices/index.js";
15
+ import { deleteElasticsearchIndex } from "./elasticsearch/deleteElasticsearchIndex.js";
16
+ import { CmsElasticsearchModelFieldPlugin, CmsEntryElasticsearchBodyModifierPlugin, CmsEntryElasticsearchFullTextSearchPlugin, CmsEntryElasticsearchIndexPlugin, CmsEntryElasticsearchQueryBuilderValueSearchPlugin, CmsEntryElasticsearchQueryModifierPlugin, CmsEntryElasticsearchSortModifierPlugin, CmsEntryElasticsearchValuesModifier } from "./plugins/index.js";
17
+ import { createFilterPlugins } from "./operations/entry/elasticsearch/filtering/plugins/index.js";
18
+ import { CmsEntryFilterPlugin } from "./plugins/CmsEntryFilterPlugin.js";
19
+ import { StorageOperationsCmsModelPlugin, StorageTransformPlugin } from "@webiny/api-headless-cms";
20
+ import { createCreateIndexTask } from "./tasks/createIndexTaskPlugin.js";
21
+ import { CompressorPlugin } from "@webiny/api";
22
+ import { ModelAfterCreateEventHandler } from "@webiny/api-headless-cms/features/contentModel/CreateModel/index.js";
23
+ import { ModelAfterCreateFromEventHandler } from "@webiny/api-headless-cms/features/contentModel/CreateModelFrom/events.js";
24
+ import { ModelAfterDeleteEventHandler } from "@webiny/api-headless-cms/features/contentModel/DeleteModel/events.js";
25
+ import { createTable } from "@webiny/db-dynamodb";
26
+ export * from "./plugins/index.js";
27
+ export const createStorageOperations = params => {
50
28
  const {
51
- attributes,
52
29
  table,
53
30
  esTable,
54
31
  documentClient,
55
32
  elasticsearch,
56
33
  plugins: userPlugins
57
34
  } = params;
58
- const tableInstance = (0, _table.createTable)({
59
- table,
35
+ const tableInstance = createTable({
36
+ name: table || process.env.DB_TABLE,
60
37
  documentClient
61
38
  });
62
- const tableElasticsearchInstance = (0, _tableElasticsearch.createElasticsearchTable)({
63
- table: esTable,
39
+ const tableElasticsearchInstance = createElasticsearchTable({
40
+ name: esTable,
64
41
  documentClient
65
42
  });
66
43
  const entities = {
67
- system: (0, _system2.createSystemEntity)({
68
- entityName: _types.ENTITIES.SYSTEM,
69
- table: tableInstance,
70
- attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
44
+ groups: createGroupEntity({
45
+ entityName: ENTITIES.GROUPS,
46
+ table: tableInstance
71
47
  }),
72
- groups: (0, _group.createGroupEntity)({
73
- entityName: _types.ENTITIES.GROUPS,
74
- table: tableInstance,
75
- attributes: attributes ? attributes[_types.ENTITIES.GROUPS] : {}
48
+ models: createModelEntity({
49
+ entityName: ENTITIES.MODELS,
50
+ table: tableInstance
76
51
  }),
77
- models: (0, _model2.createModelEntity)({
78
- entityName: _types.ENTITIES.MODELS,
79
- table: tableInstance,
80
- attributes: attributes ? attributes[_types.ENTITIES.MODELS] : {}
52
+ entries: createEntryEntity({
53
+ entityName: ENTITIES.ENTRIES,
54
+ table: tableInstance
81
55
  }),
82
- entries: (0, _entry2.createEntryEntity)({
83
- entityName: _types.ENTITIES.ENTRIES,
84
- table: tableInstance,
85
- attributes: attributes ? attributes[_types.ENTITIES.ENTRIES] : {}
86
- }),
87
- entriesEs: (0, _entryElasticsearch.createEntryElasticsearchEntity)({
88
- entityName: _types.ENTITIES.ENTRIES_ES,
89
- table: tableElasticsearchInstance,
90
- attributes: attributes ? attributes[_types.ENTITIES.ENTRIES_ES] : {}
56
+ entriesEs: createElasticsearchEntity({
57
+ entityName: ENTITIES.ENTRIES_ES,
58
+ table: tableElasticsearchInstance
91
59
  })
92
60
  };
93
- const plugins = new _plugins.PluginsContainer([
61
+ const plugins = new PluginsContainer([
94
62
  /**
95
63
  * DynamoDB filter plugins for the where conditions.
96
64
  */
97
- (0, _filters.default)(),
65
+ dynamoDbValueFilters(),
98
66
  /**
99
67
  * Field plugins for DynamoDB.
100
68
  */
101
- (0, _dynamoDb.default)(),
69
+ dynamoDbPlugins(),
102
70
  /**
103
71
  * Field plugins for Elasticsearch.
104
72
  */
105
- (0, _elasticsearch.default)(),
73
+ elasticsearchPlugins(),
106
74
  /**
107
75
  * Built-in Elasticsearch index templates.
108
76
  */
109
- (0, _indices.elasticsearchIndexPlugins)(),
77
+ elasticsearchIndexPlugins(),
110
78
  /**
111
79
  * Filter plugins used to apply filtering from where conditions to Elasticsearch query.
112
80
  */
113
- (0, _plugins3.createFilterPlugins)(),
81
+ createFilterPlugins(),
114
82
  /**
115
83
  * User defined custom plugins.
116
84
  * They are at the end because we can then override existing plugins.
117
85
  */
118
86
  ...(userPlugins || [])]);
119
- const entries = (0, _entry.createEntriesStorageOperations)({
87
+ const entries = createEntriesStorageOperations({
120
88
  entity: entities.entries,
121
89
  esEntity: entities.entriesEs,
122
90
  plugins,
@@ -141,17 +109,23 @@ const createStorageOperations = params => {
141
109
  if (!context.elasticsearch) {
142
110
  context.elasticsearch = elasticsearch;
143
111
  }
112
+
113
+ /**
114
+ * This registers the task implementation
115
+ */
116
+ createCreateIndexTask(context);
117
+
144
118
  /**
145
119
  * Pass the plugins to the parent context.
146
120
  */
147
- context.plugins.register([(0, _dynamoDb.default)(), (0, _createIndexTaskPlugin.createIndexTaskPluginTest)(), (0, _indices.elasticsearchIndexPlugins)()]);
121
+ context.plugins.register([dynamoDbPlugins(), elasticsearchIndexPlugins()]);
148
122
  /**
149
123
  * We need to fetch all the plugin types in the list from the main container.
150
124
  * This way we do not need to register plugins in the storage plugins contains.
151
125
  */
152
- const types = [_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type,
126
+ const types = [ElasticsearchQueryBuilderOperatorPlugin.type,
153
127
  // Headless CMS
154
- "cms-model-field-to-graphql", _CmsEntryFilterPlugin.CmsEntryFilterPlugin.type, _plugins2.CmsEntryElasticsearchBodyModifierPlugin.type, _plugins2.CmsEntryElasticsearchFullTextSearchPlugin.type, _plugins2.CmsEntryElasticsearchIndexPlugin.type, _plugins2.CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type, _plugins2.CmsEntryElasticsearchQueryModifierPlugin.type, _plugins2.CmsEntryElasticsearchSortModifierPlugin.type, _plugins2.CmsElasticsearchModelFieldPlugin.type, _apiHeadlessCms.StorageOperationsCmsModelPlugin.type, _apiHeadlessCms.StorageTransformPlugin.type, _plugins2.CmsEntryElasticsearchValuesModifier.type, _api.CompressorPlugin.type];
128
+ "cms-model-field-to-graphql", CmsEntryFilterPlugin.type, CmsEntryElasticsearchBodyModifierPlugin.type, CmsEntryElasticsearchFullTextSearchPlugin.type, CmsEntryElasticsearchIndexPlugin.type, CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type, CmsEntryElasticsearchQueryModifierPlugin.type, CmsEntryElasticsearchSortModifierPlugin.type, CmsElasticsearchModelFieldPlugin.type, StorageOperationsCmsModelPlugin.type, StorageTransformPlugin.type, CmsEntryElasticsearchValuesModifier.type, CompressorPlugin.type];
155
129
  for (const type of types) {
156
130
  plugins.mergeByType(context.plugins, type);
157
131
  }
@@ -159,67 +133,58 @@ const createStorageOperations = params => {
159
133
  },
160
134
  init: async context => {
161
135
  /**
162
- * We need to create indexes on before model create and on clone (create from).
163
- * Other apps create indexes on locale creation.
136
+ * TODO @pavel
137
+ * Moved operations to AFTER create/from because at in before the model does not have modelId - to create the index.
164
138
  */
165
- await (0, _indexes.createElasticsearchIndexesOnLocaleAfterCreate)({
166
- context,
167
- client: elasticsearch,
168
- plugins
169
- });
170
- context.cms.onModelBeforeCreate.subscribe(async ({
171
- model
172
- }) => {
173
- await (0, _createElasticsearchIndex.createElasticsearchIndex)({
174
- client: elasticsearch,
175
- model,
176
- plugins
177
- });
178
- });
179
- context.cms.onModelBeforeCreateFrom.subscribe(async ({
180
- model
181
- }) => {
182
- await (0, _createElasticsearchIndex.createElasticsearchIndex)({
183
- client: elasticsearch,
184
- model,
185
- plugins
186
- });
187
- });
188
- context.cms.onModelAfterDelete.subscribe(async ({
189
- model
190
- }) => {
191
- await (0, _deleteElasticsearchIndex.deleteElasticsearchIndex)({
192
- client: elasticsearch,
193
- model
194
- });
195
- });
196
- context.cms.onModelInitialize.subscribe(async ({
197
- model
198
- }) => {
199
- await (0, _createElasticsearchIndex.createElasticsearchIndex)({
200
- client: elasticsearch,
201
- model,
202
- plugins
203
- });
204
- });
139
+ context.container.registerFactory(ModelAfterCreateEventHandler, () => ({
140
+ async handle(event) {
141
+ const {
142
+ model
143
+ } = event.payload;
144
+ await createElasticsearchIndex({
145
+ client: elasticsearch,
146
+ model,
147
+ plugins
148
+ });
149
+ }
150
+ }));
151
+ context.container.registerFactory(ModelAfterCreateFromEventHandler, () => ({
152
+ async handle(event) {
153
+ const {
154
+ model
155
+ } = event.payload;
156
+ await createElasticsearchIndex({
157
+ client: elasticsearch,
158
+ model,
159
+ plugins
160
+ });
161
+ }
162
+ }));
163
+ context.container.registerFactory(ModelAfterDeleteEventHandler, () => ({
164
+ async handle(event) {
165
+ const {
166
+ model
167
+ } = event.payload;
168
+ await deleteElasticsearchIndex({
169
+ client: elasticsearch,
170
+ model
171
+ });
172
+ }
173
+ }));
205
174
  },
206
175
  getEntities: () => entities,
207
176
  getTable: () => tableInstance,
208
177
  getEsTable: () => tableElasticsearchInstance,
209
- system: (0, _system.createSystemStorageOperations)({
210
- entity: entities.system
211
- }),
212
- groups: (0, _group2.createGroupsStorageOperations)({
178
+ groups: createGroupsStorageOperations({
213
179
  entity: entities.groups,
214
180
  plugins
215
181
  }),
216
- models: (0, _model.createModelsStorageOperations)({
182
+ models: createModelsStorageOperations({
217
183
  entity: entities.models,
218
184
  elasticsearch
219
185
  }),
220
186
  entries
221
187
  };
222
188
  };
223
- exports.createStorageOperations = createStorageOperations;
224
189
 
225
190
  //# sourceMappingURL=index.js.map