@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.0156a4c312

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 (215) hide show
  1. package/README.md +6 -20
  2. package/abstractions/CmsDdbDataLoaders.d.ts +5 -0
  3. package/abstractions/CmsDdbDataLoaders.js +5 -0
  4. package/abstractions/CmsDdbDataLoaders.js.map +1 -0
  5. package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
  6. package/abstractions/CmsDdbEntryEntity.js +5 -0
  7. package/abstractions/CmsDdbEntryEntity.js.map +1 -0
  8. package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
  9. package/abstractions/CmsDdbGroupEntity.js +5 -0
  10. package/abstractions/CmsDdbGroupEntity.js.map +1 -0
  11. package/abstractions/CmsDdbModelEntity.d.ts +5 -0
  12. package/abstractions/CmsDdbModelEntity.js +5 -0
  13. package/abstractions/CmsDdbModelEntity.js.map +1 -0
  14. package/abstractions/CmsDdbTable.d.ts +5 -0
  15. package/abstractions/CmsDdbTable.js +5 -0
  16. package/abstractions/CmsDdbTable.js.map +1 -0
  17. package/definitions/entry.d.ts +6 -6
  18. package/definitions/entry.js +9 -95
  19. package/definitions/entry.js.map +1 -0
  20. package/definitions/group.d.ts +6 -6
  21. package/definitions/group.js +9 -72
  22. package/definitions/group.js.map +1 -0
  23. package/definitions/model.d.ts +6 -6
  24. package/definitions/model.js +9 -94
  25. package/definitions/model.js.map +1 -0
  26. package/definitions/table.d.ts +6 -7
  27. package/definitions/table.js +8 -30
  28. package/definitions/table.js.map +1 -0
  29. package/definitions/types.d.ts +65 -0
  30. package/definitions/types.js +0 -0
  31. package/index.d.ts +10 -2
  32. package/index.js +45 -123
  33. package/index.js.map +1 -0
  34. package/operations/entry/DdbCreateEntry.d.ts +16 -0
  35. package/operations/entry/DdbCreateEntry.js +77 -0
  36. package/operations/entry/DdbCreateEntry.js.map +1 -0
  37. package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
  38. package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
  39. package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
  40. package/operations/entry/DdbDeleteEntry.d.ts +16 -0
  41. package/operations/entry/DdbDeleteEntry.js +65 -0
  42. package/operations/entry/DdbDeleteEntry.js.map +1 -0
  43. package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
  44. package/operations/entry/DdbDeleteEntryRevision.js +91 -0
  45. package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
  46. package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
  47. package/operations/entry/DdbDeleteMultipleEntries.js +59 -0
  48. package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
  49. package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
  50. package/operations/entry/DdbGetEntriesByIds.js +31 -0
  51. package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
  52. package/operations/entry/DdbGetEntry.d.ts +14 -0
  53. package/operations/entry/DdbGetEntry.js +27 -0
  54. package/operations/entry/DdbGetEntry.js.map +1 -0
  55. package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
  56. package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
  57. package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
  58. package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
  59. package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
  60. package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
  61. package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
  62. package/operations/entry/DdbGetPreviousRevision.js +53 -0
  63. package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
  64. package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
  65. package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
  66. package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
  67. package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
  68. package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
  69. package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
  70. package/operations/entry/DdbGetRevisionById.d.ts +14 -0
  71. package/operations/entry/DdbGetRevisionById.js +34 -0
  72. package/operations/entry/DdbGetRevisionById.js.map +1 -0
  73. package/operations/entry/DdbGetRevisions.d.ts +14 -0
  74. package/operations/entry/DdbGetRevisions.js +33 -0
  75. package/operations/entry/DdbGetRevisions.js.map +1 -0
  76. package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
  77. package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
  78. package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
  79. package/operations/entry/DdbListEntries.d.ts +30 -0
  80. package/operations/entry/DdbListEntries.js +133 -0
  81. package/operations/entry/DdbListEntries.js.map +1 -0
  82. package/operations/entry/DdbMoveEntry.d.ts +16 -0
  83. package/operations/entry/DdbMoveEntry.js +63 -0
  84. package/operations/entry/DdbMoveEntry.js.map +1 -0
  85. package/operations/entry/DdbMoveToBin.d.ts +16 -0
  86. package/operations/entry/DdbMoveToBin.js +77 -0
  87. package/operations/entry/DdbMoveToBin.js.map +1 -0
  88. package/operations/entry/DdbPublishEntry.d.ts +18 -0
  89. package/operations/entry/DdbPublishEntry.js +162 -0
  90. package/operations/entry/DdbPublishEntry.js.map +1 -0
  91. package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
  92. package/operations/entry/DdbRestoreFromBin.js +78 -0
  93. package/operations/entry/DdbRestoreFromBin.js.map +1 -0
  94. package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
  95. package/operations/entry/DdbUnpublishEntry.js +112 -0
  96. package/operations/entry/DdbUnpublishEntry.js.map +1 -0
  97. package/operations/entry/DdbUpdateEntry.d.ts +17 -0
  98. package/operations/entry/DdbUpdateEntry.js +105 -0
  99. package/operations/entry/DdbUpdateEntry.js.map +1 -0
  100. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  101. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  102. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  103. package/operations/entry/dataLoader/constants.d.ts +1 -0
  104. package/operations/entry/dataLoader/constants.js +5 -0
  105. package/operations/entry/dataLoader/constants.js.map +1 -0
  106. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  107. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  108. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  109. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  110. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  111. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  112. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  113. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  114. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  115. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  116. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  117. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  118. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  119. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  120. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  121. package/operations/entry/dataLoader/index.d.ts +8 -0
  122. package/operations/entry/dataLoader/index.js +18 -0
  123. package/operations/entry/dataLoader/index.js.map +1 -0
  124. package/operations/entry/dataLoader/types.d.ts +6 -0
  125. package/operations/entry/dataLoader/types.js +0 -0
  126. package/operations/entry/dataLoaders.d.ts +20 -31
  127. package/operations/entry/dataLoaders.js +91 -296
  128. package/operations/entry/dataLoaders.js.map +1 -0
  129. package/operations/entry/feature.d.ts +4 -0
  130. package/operations/entry/feature.js +55 -0
  131. package/operations/entry/feature.js.map +1 -0
  132. package/operations/entry/keys.d.ts +46 -2
  133. package/operations/entry/keys.js +53 -55
  134. package/operations/entry/keys.js.map +1 -0
  135. package/operations/entry/storageEntryUtils.d.ts +8 -0
  136. package/operations/entry/storageEntryUtils.js +25 -0
  137. package/operations/entry/storageEntryUtils.js.map +1 -0
  138. package/operations/group/DdbCreateGroup.d.ts +12 -0
  139. package/operations/group/DdbCreateGroup.js +35 -0
  140. package/operations/group/DdbCreateGroup.js.map +1 -0
  141. package/operations/group/DdbDeleteGroup.d.ts +12 -0
  142. package/operations/group/DdbDeleteGroup.js +31 -0
  143. package/operations/group/DdbDeleteGroup.js.map +1 -0
  144. package/operations/group/DdbGetGroup.d.ts +12 -0
  145. package/operations/group/DdbGetGroup.js +31 -0
  146. package/operations/group/DdbGetGroup.js.map +1 -0
  147. package/operations/group/DdbListGroups.d.ts +14 -0
  148. package/operations/group/DdbListGroups.js +52 -0
  149. package/operations/group/DdbListGroups.js.map +1 -0
  150. package/operations/group/DdbUpdateGroup.d.ts +12 -0
  151. package/operations/group/DdbUpdateGroup.js +35 -0
  152. package/operations/group/DdbUpdateGroup.js.map +1 -0
  153. package/operations/group/feature.d.ts +4 -0
  154. package/operations/group/feature.js +19 -0
  155. package/operations/group/feature.js.map +1 -0
  156. package/operations/group/keys.d.ts +15 -0
  157. package/operations/group/keys.js +17 -0
  158. package/operations/group/keys.js.map +1 -0
  159. package/operations/model/DdbCreateModel.d.ts +12 -0
  160. package/operations/model/DdbCreateModel.js +37 -0
  161. package/operations/model/DdbCreateModel.js.map +1 -0
  162. package/operations/model/DdbDeleteModel.d.ts +12 -0
  163. package/operations/model/DdbDeleteModel.js +31 -0
  164. package/operations/model/DdbDeleteModel.js.map +1 -0
  165. package/operations/model/DdbGetModel.d.ts +12 -0
  166. package/operations/model/DdbGetModel.js +30 -0
  167. package/operations/model/DdbGetModel.js.map +1 -0
  168. package/operations/model/DdbListModels.d.ts +12 -0
  169. package/operations/model/DdbListModels.js +36 -0
  170. package/operations/model/DdbListModels.js.map +1 -0
  171. package/operations/model/DdbUpdateModel.d.ts +12 -0
  172. package/operations/model/DdbUpdateModel.js +36 -0
  173. package/operations/model/DdbUpdateModel.js.map +1 -0
  174. package/operations/model/feature.d.ts +4 -0
  175. package/operations/model/feature.js +19 -0
  176. package/operations/model/feature.js.map +1 -0
  177. package/operations/model/keys.d.ts +15 -0
  178. package/operations/model/keys.js +16 -0
  179. package/operations/model/keys.js.map +1 -0
  180. package/package.json +30 -34
  181. package/types.d.ts +12 -76
  182. package/types.js +8 -15
  183. package/types.js.map +1 -0
  184. package/definitions/settings.d.ts +0 -8
  185. package/definitions/settings.js +0 -62
  186. package/definitions/system.d.ts +0 -8
  187. package/definitions/system.js +0 -50
  188. package/dynamoDb/index.d.ts +0 -2
  189. package/dynamoDb/index.js +0 -24
  190. package/dynamoDb/path/plainObject.d.ts +0 -3
  191. package/dynamoDb/path/plainObject.js +0 -33
  192. package/dynamoDb/path/ref.d.ts +0 -3
  193. package/dynamoDb/path/ref.js +0 -27
  194. package/dynamoDb/storage/date.d.ts +0 -3
  195. package/dynamoDb/storage/date.js +0 -65
  196. package/dynamoDb/storage/longText.d.ts +0 -7
  197. package/dynamoDb/storage/longText.js +0 -83
  198. package/dynamoDb/storage/richText.d.ts +0 -8
  199. package/dynamoDb/storage/richText.js +0 -110
  200. package/dynamoDb/transformValue/datetime.d.ts +0 -3
  201. package/dynamoDb/transformValue/datetime.js +0 -47
  202. package/operations/entry/index.d.ts +0 -8
  203. package/operations/entry/index.js +0 -823
  204. package/operations/entry/systemFields.d.ts +0 -2
  205. package/operations/entry/systemFields.js +0 -50
  206. package/operations/entry/utils.d.ts +0 -31
  207. package/operations/entry/utils.js +0 -406
  208. package/operations/group/index.d.ts +0 -8
  209. package/operations/group/index.js +0 -198
  210. package/operations/model/index.d.ts +0 -6
  211. package/operations/model/index.js +0 -161
  212. package/operations/settings/index.d.ts +0 -6
  213. package/operations/settings/index.js +0 -141
  214. package/operations/system/index.d.ts +0 -6
  215. package/operations/system/index.js +0 -105
@@ -1,2 +0,0 @@
1
- import { CmsModelField } from "@webiny/api-headless-cms/types";
2
- export declare const systemFields: Record<string, CmsModelField>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.systemFields = void 0;
7
-
8
- const createSystemField = field => {
9
- return field;
10
- };
11
-
12
- const systemFields = {
13
- id: createSystemField({
14
- id: "id",
15
- type: "text",
16
- fieldId: "id"
17
- }),
18
- entryId: createSystemField({
19
- id: "entryId",
20
- type: "text",
21
- fieldId: "entryId"
22
- }),
23
- createdOn: createSystemField({
24
- id: "createdOn",
25
- type: "datetime",
26
- fieldId: "createdOn"
27
- }),
28
- savedOn: createSystemField({
29
- id: "savedOn",
30
- type: "datetime",
31
- fieldId: "savedOn"
32
- }),
33
- createdBy: createSystemField({
34
- id: "createdBy",
35
- type: "plainObject",
36
- fieldId: "createdBy",
37
- settings: {
38
- path: "createdBy.id"
39
- }
40
- }),
41
- ownedBy: createSystemField({
42
- id: "ownedBy",
43
- type: "plainObject",
44
- fieldId: "ownedBy",
45
- settings: {
46
- path: "ownedBy.id"
47
- }
48
- })
49
- };
50
- exports.systemFields = systemFields;
@@ -1,31 +0,0 @@
1
- import { CmsEntry, CmsEntryListWhere, CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
2
- import { PluginsContainer } from "@webiny/plugins";
3
- interface ModelField {
4
- def: CmsModelField;
5
- valueTransformer: (value: any) => any;
6
- valuePath: string;
7
- isSystemField?: boolean;
8
- }
9
- declare type ModelFieldRecords = Record<string, ModelField>;
10
- export interface FilterItemFromStorage {
11
- (field: CmsModelField, value: any): Promise<any>;
12
- }
13
- interface FilterItemsParams {
14
- items: CmsEntry[];
15
- where: CmsEntryListWhere;
16
- plugins: PluginsContainer;
17
- fields: ModelFieldRecords;
18
- fromStorage: FilterItemFromStorage;
19
- }
20
- export declare const filterItems: (params: FilterItemsParams) => Promise<CmsEntry[]>;
21
- interface SortEntryItemsArgs {
22
- items: CmsEntry[];
23
- sort: string[];
24
- fields: ModelFieldRecords;
25
- }
26
- export declare const sortEntryItems: (params: SortEntryItemsArgs) => CmsEntry[];
27
- export declare const buildModelFields: ({ plugins, model }: {
28
- plugins: PluginsContainer;
29
- model: CmsModel;
30
- }) => Record<string, ModelField>;
31
- export {};
@@ -1,406 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.sortEntryItems = exports.filterItems = exports.buildModelFields = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- var _lodash = _interopRequireDefault(require("lodash.sortby"));
13
-
14
- var _dotProp = _interopRequireDefault(require("dot-prop"));
15
-
16
- var _systemFields = require("./systemFields");
17
-
18
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
19
-
20
- const VALUES_ATTRIBUTE = "values";
21
-
22
- const extractWhereParams = key => {
23
- const result = key.split("_");
24
- const fieldId = result.shift();
25
- const rawOp = result.length === 0 ? "eq" : result.join("_");
26
- /**
27
- * When rawOp is not, it means it is equal negated so just return that.
28
- */
29
-
30
- if (rawOp === "not") {
31
- return {
32
- fieldId,
33
- operation: "eq",
34
- negate: true
35
- };
36
- }
37
-
38
- const negate = rawOp.match("not_") !== null;
39
- const operation = rawOp.replace("not_", "");
40
- return {
41
- fieldId,
42
- operation,
43
- negate
44
- };
45
- };
46
-
47
- const transformValue = (value, transform) => {
48
- if (Array.isArray(value)) {
49
- return value.map(v => transform(v));
50
- }
51
-
52
- return transform(value);
53
- };
54
-
55
- const createFilters = params => {
56
- const {
57
- where,
58
- plugins,
59
- fields
60
- } = params;
61
- const filterPlugins = getMappedPlugins({
62
- plugins,
63
- type: _ValueFilterPlugin.ValueFilterPlugin.type,
64
- property: "operation"
65
- });
66
- const transformValuePlugins = getMappedPlugins({
67
- plugins,
68
- type: "cms-field-filter-value-transform",
69
- property: "fieldType"
70
- });
71
- const valuePathPlugins = getMappedPlugins({
72
- plugins,
73
- type: "cms-field-filter-path",
74
- property: "fieldType"
75
- });
76
- return Object.keys(where).map(key => {
77
- const {
78
- fieldId,
79
- operation,
80
- negate
81
- } = extractWhereParams(key);
82
- const field = fields[fieldId];
83
-
84
- if (!field) {
85
- throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
86
- fieldId
87
- });
88
- }
89
-
90
- const transformValuePlugin = transformValuePlugins[field.def.type];
91
- const valuePathPlugin = valuePathPlugins[field.def.type];
92
- let targetValuePath;
93
- /**
94
- * add the base path if field is not a system field
95
- * pathPlugin should not know about that
96
- */
97
-
98
- const basePath = _systemFields.systemFields[fieldId] ? "" : `${VALUES_ATTRIBUTE}.`;
99
-
100
- if (valuePathPlugin) {
101
- targetValuePath = valuePathPlugin.createPath({
102
- field: field.def
103
- });
104
- } else if (_systemFields.systemFields[fieldId]) {
105
- targetValuePath = fieldId;
106
- } else {
107
- targetValuePath = field.def.fieldId;
108
- }
109
-
110
- const valuePath = `${basePath}${targetValuePath}`;
111
- const filterPlugin = filterPlugins[operation];
112
-
113
- if (!filterPlugin) {
114
- throw new _error.default(`There is no filter plugin for operation "${operation}".`, "FILTER_PLUGIN_ERROR", {
115
- operation
116
- });
117
- }
118
-
119
- const transformValueCallable = value => {
120
- if (!transformValuePlugin) {
121
- return value;
122
- }
123
-
124
- return transformValuePlugin.transform({
125
- field: field.def,
126
- value
127
- });
128
- };
129
-
130
- return {
131
- fieldId,
132
- path: valuePath,
133
- filterPlugin,
134
- negate,
135
- compareValue: transformValue(where[key], transformValueCallable),
136
- transformValue: transformValueCallable
137
- };
138
- });
139
- };
140
-
141
- const filterItems = async params => {
142
- const {
143
- items,
144
- where,
145
- plugins,
146
- fields,
147
- fromStorage
148
- } = params;
149
- const filters = createFilters({
150
- plugins,
151
- where,
152
- fields
153
- });
154
- const results = [];
155
-
156
- for (const key in items) {
157
- if (items.hasOwnProperty(key) === false) {
158
- continue;
159
- }
160
-
161
- const item = items[key];
162
- let passed = true;
163
-
164
- for (const filter of filters) {
165
- const rawValue = _dotProp.default.get(item, filter.path);
166
-
167
- const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);
168
- /**
169
- * If raw value is not same as the value after the storage transform, set the value to the items being filtered.
170
- */
171
-
172
- if (plainValue !== rawValue) {
173
- items[key] = _dotProp.default.set(item, filter.path, plainValue);
174
- }
175
-
176
- const value = transformValue(plainValue, filter.transformValue);
177
- const matched = filter.filterPlugin.matches({
178
- value,
179
- compareValue: filter.compareValue
180
- });
181
-
182
- if ((filter.negate ? !matched : matched) === false) {
183
- passed = false;
184
- break;
185
- }
186
- }
187
-
188
- if (!passed) {
189
- continue;
190
- }
191
-
192
- results.push(item);
193
- }
194
-
195
- return results; // return items.filter(item => {
196
- // for (const filter of filters) {
197
- // const plainValue = await fromStorage(
198
- // fields[filter.fieldId].def,
199
- // dotProp.get(item, filter.path)
200
- // );
201
- //
202
- // const value = transformValue(plainValue, filter.transformValue);
203
- // const matched = filter.filterPlugin.matches({
204
- // value,
205
- // compareValue: filter.compareValue
206
- // });
207
- // if ((filter.negate ? !matched : matched) === false) {
208
- // return false;
209
- // }
210
- // }
211
- // return true;
212
- // });
213
- };
214
-
215
- exports.filterItems = filterItems;
216
-
217
- const extractSort = (sortBy, fields) => {
218
- const result = sortBy.split("_");
219
-
220
- if (result.length !== 2) {
221
- throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
222
- sortBy
223
- });
224
- }
225
-
226
- const [fieldId, order] = result;
227
- const modelField = fields[fieldId];
228
-
229
- if (!modelField) {
230
- throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
231
- fieldId,
232
- fields
233
- });
234
- }
235
-
236
- const valuePath = modelField.valuePath;
237
- return {
238
- fieldId,
239
- valuePath,
240
- reverse: order === "DESC"
241
- };
242
- };
243
-
244
- const sortEntryItems = params => {
245
- const {
246
- items,
247
- sort = [],
248
- fields
249
- } = params;
250
-
251
- if (items.length <= 1) {
252
- return items;
253
- } else if (sort.length === 0) {
254
- sort.push("savedOn_DESC");
255
- } else if (sort.length > 1) {
256
- throw new _error.default("Sorting is limited to a single field.", "SORT_ERROR", {
257
- sort: sort
258
- });
259
- }
260
-
261
- const [firstSort] = sort;
262
-
263
- if (!firstSort) {
264
- throw new _error.default("Empty sort array item.", "SORT_ERROR", {
265
- sort
266
- });
267
- }
268
-
269
- const {
270
- fieldId,
271
- valuePath,
272
- reverse
273
- } = extractSort(firstSort, fields);
274
- const field = fields[fieldId];
275
- const itemsToSort = items.map(item => {
276
- return {
277
- id: item.id,
278
- value: field.valueTransformer(_dotProp.default.get(item, valuePath))
279
- };
280
- });
281
- const sortedItems = (0, _lodash.default)(itemsToSort, "value");
282
- const newItems = sortedItems.map(s => {
283
- const item = items.find(i => i.id === s.id);
284
-
285
- if (item) {
286
- return item;
287
- }
288
-
289
- throw new _error.default("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
290
- id: s.id,
291
- sortingBy: fieldId,
292
- reverse
293
- });
294
- });
295
-
296
- if (!reverse) {
297
- return newItems;
298
- }
299
-
300
- return newItems.reverse();
301
- };
302
-
303
- exports.sortEntryItems = sortEntryItems;
304
-
305
- const getMappedPlugins = params => {
306
- const {
307
- plugins: pluginsContainer,
308
- type,
309
- property
310
- } = params;
311
- const plugins = pluginsContainer.byType(type);
312
-
313
- if (plugins.length === 0) {
314
- throw new _error.default(`There are no plugins of type "${type}".`, "PLUGINS_ERROR", {
315
- type
316
- });
317
- }
318
-
319
- return plugins.reduce((collection, plugin) => {
320
- const key = plugin[property];
321
-
322
- if (typeof key !== "string") {
323
- throw new _error.default("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
324
- type,
325
- property
326
- });
327
- }
328
-
329
- collection[key] = plugin;
330
- return collection;
331
- }, {});
332
- };
333
-
334
- const buildModelFields = ({
335
- plugins,
336
- model
337
- }) => {
338
- const transformValuePlugins = getMappedPlugins({
339
- plugins,
340
- type: "cms-field-filter-value-transform",
341
- property: "fieldType"
342
- });
343
- const valuePathPlugins = getMappedPlugins({
344
- plugins,
345
- type: "cms-field-filter-path",
346
- property: "fieldType"
347
- });
348
- const fields = Object.values(_systemFields.systemFields).reduce((collection, field) => {
349
- const transformValuePlugin = transformValuePlugins[field.type];
350
- const valuePathPlugin = valuePathPlugins[field.type];
351
- let valuePath;
352
-
353
- if (valuePathPlugin) {
354
- valuePath = valuePathPlugin.createPath({
355
- field
356
- });
357
- }
358
-
359
- collection[field.fieldId] = {
360
- def: field,
361
- valueTransformer: value => {
362
- if (!transformValuePlugin) {
363
- return value;
364
- }
365
-
366
- return transformValuePlugin.transform({
367
- field,
368
- value
369
- });
370
- },
371
- valuePath: valuePath || field.fieldId,
372
- isSystemField: true
373
- };
374
- return collection;
375
- }, {});
376
- return model.fields.reduce((collection, field) => {
377
- const transformValuePlugin = transformValuePlugins[field.type];
378
- const valuePathPlugin = valuePathPlugins[field.type];
379
- let valuePath;
380
-
381
- if (valuePathPlugin) {
382
- valuePath = valuePathPlugin.createPath({
383
- field
384
- });
385
- }
386
-
387
- const targetValuePath = `${VALUES_ATTRIBUTE}.${valuePath || field.fieldId}`;
388
- collection[field.fieldId] = {
389
- def: field,
390
- valueTransformer: value => {
391
- if (!transformValuePlugin) {
392
- return value;
393
- }
394
-
395
- return transformValuePlugin.transform({
396
- field,
397
- value
398
- });
399
- },
400
- valuePath: targetValuePath || field.fieldId
401
- };
402
- return collection;
403
- }, fields);
404
- };
405
-
406
- exports.buildModelFields = buildModelFields;
@@ -1,8 +0,0 @@
1
- import { CmsGroupStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- import { PluginsContainer } from "@webiny/plugins";
4
- export interface Params {
5
- entity: Entity<any>;
6
- plugins: PluginsContainer;
7
- }
8
- export declare const createGroupsStorageOperations: (params: Params) => CmsGroupStorageOperations;
@@ -1,198 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createGroupsStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
- var _filter = require("@webiny/db-dynamodb/utils/filter");
21
-
22
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
23
-
24
- var _sort = require("@webiny/db-dynamodb/utils/sort");
25
-
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
27
-
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
-
30
- const createPartitionKey = params => {
31
- const {
32
- tenant,
33
- locale
34
- } = params;
35
- return `T#${tenant}#L#${locale}#CMS#CMG`;
36
- };
37
-
38
- const createSortKeys = params => {
39
- const {
40
- id
41
- } = params;
42
- return id;
43
- };
44
-
45
- const createKeys = params => {
46
- return {
47
- PK: createPartitionKey(params),
48
- SK: createSortKeys(params)
49
- };
50
- };
51
-
52
- const createType = () => {
53
- return "cms.group";
54
- };
55
-
56
- const createGroupsStorageOperations = params => {
57
- const {
58
- entity,
59
- plugins
60
- } = params;
61
- const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
62
-
63
- if (filteringPlugins.length === 0) {
64
- throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
65
- }
66
-
67
- const create = async params => {
68
- const {
69
- group
70
- } = params;
71
- const keys = createKeys(group);
72
-
73
- try {
74
- await entity.put(_objectSpread(_objectSpread({}, group), {}, {
75
- TYPE: createType()
76
- }, keys));
77
- return group;
78
- } catch (ex) {
79
- throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
80
- error: ex,
81
- group,
82
- keys
83
- });
84
- }
85
- };
86
-
87
- const update = async params => {
88
- const {
89
- group,
90
- original
91
- } = params;
92
- const keys = createKeys(group);
93
-
94
- try {
95
- await entity.put(_objectSpread(_objectSpread({}, group), {}, {
96
- TYPE: createType()
97
- }, keys));
98
- return group;
99
- } catch (ex) {
100
- throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
101
- error: ex,
102
- group,
103
- original,
104
- keys
105
- });
106
- }
107
- };
108
-
109
- const deleteGroup = async params => {
110
- const {
111
- group
112
- } = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
113
-
114
- const keys = createKeys(group);
115
-
116
- try {
117
- await entity.delete(keys);
118
- return group;
119
- } catch (ex) {
120
- throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
121
- error: ex,
122
- group,
123
- keys
124
- });
125
- }
126
- };
127
-
128
- const get = async params => {
129
- const keys = createKeys(params);
130
-
131
- try {
132
- const group = await (0, _get.get)({
133
- entity,
134
- keys
135
- });
136
- return (0, _cleanup.cleanupItem)(entity, group);
137
- } catch (ex) {
138
- throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", _objectSpread(_objectSpread({
139
- error: ex
140
- }, params), {}, {
141
- keys
142
- }));
143
- }
144
- };
145
-
146
- const list = async params => {
147
- const {
148
- sort,
149
- where
150
- } = params;
151
- const queryAllParams = {
152
- entity,
153
- partitionKey: createPartitionKey(where),
154
- options: {
155
- gte: " "
156
- }
157
- };
158
- let records = [];
159
-
160
- try {
161
- records = await (0, _query.queryAll)(queryAllParams);
162
- } catch (ex) {
163
- throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", _objectSpread(_objectSpread({
164
- error: ex
165
- }, params), {}, {
166
- sort,
167
- where
168
- }));
169
- }
170
-
171
- const filteredItems = (0, _filter.filterItems)({
172
- items: records,
173
- where,
174
- fields: [],
175
- plugins
176
- });
177
-
178
- if (!sort || sort.length === 0) {
179
- return filteredItems;
180
- }
181
-
182
- return (0, _sort.sortItems)({
183
- items: filteredItems,
184
- sort,
185
- fields: []
186
- });
187
- };
188
-
189
- return {
190
- create,
191
- update,
192
- delete: deleteGroup,
193
- get,
194
- list
195
- };
196
- };
197
-
198
- exports.createGroupsStorageOperations = createGroupsStorageOperations;
@@ -1,6 +0,0 @@
1
- import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- export interface Params {
4
- entity: Entity<any>;
5
- }
6
- export declare const createModelsStorageOperations: (params: Params) => CmsModelStorageOperations;