@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (172) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +9 -94
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +9 -68
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +9 -90
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +8 -30
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +65 -0
  15. package/definitions/types.js +0 -0
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +11 -20
  18. package/dynamoDb/index.js.map +1 -1
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +21 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.d.ts +1 -1
  23. package/dynamoDb/path/plainObject.js +13 -37
  24. package/dynamoDb/path/plainObject.js.map +1 -1
  25. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  26. package/dynamoDb/transformValue/datetime.js +27 -50
  27. package/dynamoDb/transformValue/datetime.js.map +1 -1
  28. package/index.d.ts +2 -3
  29. package/index.js +83 -139
  30. package/index.js.map +1 -1
  31. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  32. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  33. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  34. package/operations/entry/dataLoader/constants.d.ts +1 -0
  35. package/operations/entry/dataLoader/constants.js +5 -0
  36. package/operations/entry/dataLoader/constants.js.map +1 -0
  37. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  38. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  39. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  40. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  41. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  42. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  43. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  44. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  45. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  46. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  47. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  48. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  49. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  50. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  51. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  52. package/operations/entry/dataLoader/index.d.ts +8 -0
  53. package/operations/entry/dataLoader/index.js +18 -0
  54. package/operations/entry/dataLoader/index.js.map +1 -0
  55. package/operations/entry/dataLoader/types.d.ts +6 -0
  56. package/operations/entry/dataLoader/types.js +0 -0
  57. package/operations/entry/dataLoaders.d.ts +14 -30
  58. package/operations/entry/dataLoaders.js +83 -314
  59. package/operations/entry/dataLoaders.js.map +1 -1
  60. package/operations/entry/filtering/createExpressions.d.ts +27 -0
  61. package/operations/entry/filtering/createExpressions.js +124 -0
  62. package/operations/entry/filtering/createExpressions.js.map +1 -0
  63. package/operations/entry/filtering/createFields.d.ts +16 -0
  64. package/operations/entry/filtering/createFields.js +93 -0
  65. package/operations/entry/filtering/createFields.js.map +1 -0
  66. package/operations/entry/filtering/extractSort.d.ts +17 -0
  67. package/operations/entry/filtering/extractSort.js +60 -0
  68. package/operations/entry/filtering/extractSort.js.map +1 -0
  69. package/operations/entry/filtering/filter.d.ts +16 -0
  70. package/operations/entry/filtering/filter.js +85 -0
  71. package/operations/entry/filtering/filter.js.map +1 -0
  72. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  73. package/operations/entry/filtering/fullTextSearch.js +25 -0
  74. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  75. package/operations/entry/filtering/getValue.d.ts +5 -0
  76. package/operations/entry/filtering/getValue.js +37 -0
  77. package/operations/entry/filtering/getValue.js.map +1 -0
  78. package/operations/entry/filtering/index.d.ts +2 -0
  79. package/operations/entry/filtering/index.js +2 -0
  80. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  81. package/operations/entry/filtering/mapPlugins.js +18 -0
  82. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  83. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  84. package/operations/entry/filtering/plugins/defaultFilterCreate.js +33 -0
  85. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  86. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  87. package/operations/entry/filtering/plugins/index.js +13 -0
  88. package/operations/entry/filtering/plugins/index.js.map +1 -0
  89. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  90. package/operations/entry/filtering/plugins/objectFilterCreate.js +68 -0
  91. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  92. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  93. package/operations/entry/filtering/plugins/refFilterCreate.js +63 -0
  94. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  95. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  96. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +49 -0
  97. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  98. package/operations/entry/filtering/sort.d.ts +12 -0
  99. package/operations/entry/filtering/sort.js +41 -0
  100. package/operations/entry/filtering/sort.js.map +1 -0
  101. package/operations/entry/filtering/systemFields.d.ts +2 -0
  102. package/operations/entry/filtering/systemFields.js +149 -0
  103. package/operations/entry/filtering/systemFields.js.map +1 -0
  104. package/operations/entry/filtering/transform.d.ts +6 -0
  105. package/operations/entry/filtering/transform.js +7 -0
  106. package/operations/entry/filtering/transform.js.map +1 -0
  107. package/operations/entry/filtering/types.d.ts +40 -0
  108. package/operations/entry/filtering/types.js +0 -0
  109. package/operations/entry/filtering/values.d.ts +2 -0
  110. package/operations/entry/filtering/values.js +15 -0
  111. package/operations/entry/filtering/values.js.map +1 -0
  112. package/operations/entry/filtering/where.d.ts +5 -0
  113. package/operations/entry/filtering/where.js +22 -0
  114. package/operations/entry/filtering/where.js.map +1 -0
  115. package/operations/entry/index.d.ts +5 -4
  116. package/operations/entry/index.js +931 -845
  117. package/operations/entry/index.js.map +1 -1
  118. package/operations/entry/keys.d.ts +46 -2
  119. package/operations/entry/keys.js +53 -66
  120. package/operations/entry/keys.js.map +1 -1
  121. package/operations/group/index.d.ts +4 -5
  122. package/operations/group/index.js +116 -187
  123. package/operations/group/index.js.map +1 -1
  124. package/operations/model/index.d.ts +3 -3
  125. package/operations/model/index.js +102 -158
  126. package/operations/model/index.js.map +1 -1
  127. package/package.json +34 -33
  128. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +5 -4
  129. package/plugins/CmsEntryFieldFilterPathPlugin.js +25 -50
  130. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  131. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  132. package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
  133. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  134. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  135. package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
  136. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  137. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  138. package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
  139. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  140. package/plugins/index.d.ts +4 -1
  141. package/plugins/index.js +4 -18
  142. package/types.d.ts +28 -21
  143. package/types.js +8 -15
  144. package/types.js.map +1 -1
  145. package/definitions/settings.d.ts +0 -9
  146. package/definitions/settings.js +0 -58
  147. package/definitions/settings.js.map +0 -1
  148. package/definitions/system.d.ts +0 -9
  149. package/definitions/system.js +0 -46
  150. package/definitions/system.js.map +0 -1
  151. package/dynamoDb/storage/date.d.ts +0 -2
  152. package/dynamoDb/storage/date.js +0 -99
  153. package/dynamoDb/storage/date.js.map +0 -1
  154. package/dynamoDb/storage/longText.d.ts +0 -10
  155. package/dynamoDb/storage/longText.js +0 -101
  156. package/dynamoDb/storage/longText.js.map +0 -1
  157. package/dynamoDb/storage/richText.d.ts +0 -2
  158. package/dynamoDb/storage/richText.js +0 -113
  159. package/dynamoDb/storage/richText.js.map +0 -1
  160. package/operations/entry/systemFields.d.ts +0 -2
  161. package/operations/entry/systemFields.js +0 -74
  162. package/operations/entry/systemFields.js.map +0 -1
  163. package/operations/entry/utils.d.ts +0 -36
  164. package/operations/entry/utils.js +0 -680
  165. package/operations/entry/utils.js.map +0 -1
  166. package/operations/settings/index.d.ts +0 -7
  167. package/operations/settings/index.js +0 -135
  168. package/operations/settings/index.js.map +0 -1
  169. package/operations/system/index.d.ts +0 -7
  170. package/operations/system/index.js +0 -99
  171. package/operations/system/index.js.map +0 -1
  172. package/plugins/index.js.map +0 -1
@@ -1,192 +1,121 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createGroupsStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
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
- const createPartitionKey = params => {
27
- const {
28
- tenant,
29
- locale
30
- } = params;
31
- return `T#${tenant}#L#${locale}#CMS#CMG`;
1
+ import error from "@webiny/error";
2
+ import { sortItems } from "@webiny/db-dynamodb";
3
+ import { FilterUtil } from "@webiny/db-dynamodb/feature/FilterUtil/index.js";
4
+ const createPartitionKey = (params)=>{
5
+ const { tenant } = params;
6
+ return `T#${tenant}#CMS#CMG`;
32
7
  };
33
-
34
- const createSortKeys = params => {
35
- const {
36
- id
37
- } = params;
38
- return id;
39
- };
40
-
41
- const createKeys = params => {
42
- return {
43
- PK: createPartitionKey(params),
44
- SK: createSortKeys(params)
45
- };
46
- };
47
-
48
- const createType = () => {
49
- return "cms.group";
8
+ const createSortKeys = (params)=>{
9
+ const { id } = params;
10
+ return id;
50
11
  };
51
-
52
- const createGroupsStorageOperations = params => {
53
- const {
54
- entity,
55
- plugins
56
- } = params;
57
- const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
58
-
59
- if (filteringPlugins.length === 0) {
60
- throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
61
- }
62
-
63
- const create = async params => {
64
- const {
65
- group
66
- } = params;
67
- const keys = createKeys(group);
68
-
69
- try {
70
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
71
- TYPE: createType()
72
- }, keys));
73
- return group;
74
- } catch (ex) {
75
- throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
76
- error: ex,
77
- group,
78
- keys
79
- });
80
- }
81
- };
82
-
83
- const update = async params => {
84
- const {
85
- group
86
- } = params;
87
- const keys = createKeys(group);
88
-
89
- try {
90
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
91
- TYPE: createType()
92
- }, keys));
93
- return group;
94
- } catch (ex) {
95
- throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
96
- error: ex,
97
- group,
98
- keys
99
- });
100
- }
101
- };
102
-
103
- const deleteGroup = async params => {
104
- const {
105
- group
106
- } = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
107
-
108
- const keys = createKeys(group);
109
-
110
- try {
111
- await entity.delete(keys);
112
- return group;
113
- } catch (ex) {
114
- throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
115
- error: ex,
116
- group,
117
- keys
118
- });
119
- }
120
- };
121
-
122
- const get = async params => {
123
- const keys = createKeys(params);
124
-
125
- try {
126
- const group = await (0, _get.get)({
127
- entity,
128
- keys
129
- });
130
- return (0, _cleanup.cleanupItem)(entity, group);
131
- } catch (ex) {
132
- throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
133
- error: ex
134
- }, params), {}, {
135
- keys
136
- }));
137
- }
138
- };
139
-
140
- const list = async params => {
141
- const {
142
- sort,
143
- where
144
- } = params;
145
- const queryAllParams = {
146
- entity,
147
- partitionKey: createPartitionKey(where),
148
- options: {
149
- gte: " "
150
- }
151
- };
152
- let records = [];
153
-
154
- try {
155
- records = await (0, _query.queryAll)(queryAllParams);
156
- } catch (ex) {
157
- throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
158
- error: ex
159
- }, params), {}, {
160
- sort,
161
- where
162
- }));
163
- }
164
-
165
- const filteredItems = (0, _filter.filterItems)({
166
- items: records,
167
- where,
168
- fields: [],
169
- plugins
12
+ const createKeys = (params)=>({
13
+ PK: createPartitionKey(params),
14
+ SK: createSortKeys(params),
15
+ GSI_TENANT: params.tenant
170
16
  });
171
-
172
- if (!sort || sort.length === 0) {
173
- return filteredItems;
174
- }
175
-
176
- return (0, _sort.sortItems)({
177
- items: filteredItems,
178
- sort,
179
- fields: []
180
- });
181
- };
182
-
183
- return {
184
- create,
185
- update,
186
- delete: deleteGroup,
187
- get,
188
- list
189
- };
17
+ const createType = ()=>"cms.group";
18
+ const createGroupsStorageOperations = (params)=>{
19
+ const { entity, container } = params;
20
+ const filterUtil = container.resolve(FilterUtil);
21
+ const create = async (params)=>{
22
+ const { group } = params;
23
+ const keys = createKeys(group);
24
+ try {
25
+ await entity.put({
26
+ data: group,
27
+ TYPE: createType(),
28
+ ...keys
29
+ });
30
+ } catch (ex) {
31
+ throw new error(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
32
+ error: ex,
33
+ group,
34
+ keys
35
+ });
36
+ }
37
+ };
38
+ const update = async (params)=>{
39
+ const { group } = params;
40
+ const keys = createKeys(group);
41
+ try {
42
+ await entity.put({
43
+ data: group,
44
+ TYPE: createType(),
45
+ ...keys
46
+ });
47
+ } catch (ex) {
48
+ throw new error(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
49
+ error: ex,
50
+ group,
51
+ keys
52
+ });
53
+ }
54
+ };
55
+ const deleteGroup = async (params)=>{
56
+ const { group } = params;
57
+ const keys = createKeys(group);
58
+ try {
59
+ await entity.delete(keys);
60
+ } catch (ex) {
61
+ throw new error(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
62
+ error: ex,
63
+ group,
64
+ keys
65
+ });
66
+ }
67
+ };
68
+ const get = async (params)=>{
69
+ const keys = createKeys(params);
70
+ try {
71
+ const result = await entity.get(keys);
72
+ return result?.data || null;
73
+ } catch (ex) {
74
+ throw new error(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
75
+ error: ex,
76
+ ...params,
77
+ keys
78
+ });
79
+ }
80
+ };
81
+ const list = async (params)=>{
82
+ const { sort, where } = params;
83
+ let records = [];
84
+ try {
85
+ const ddbRecords = await entity.queryAll({
86
+ partitionKey: createPartitionKey(where),
87
+ options: {
88
+ gte: " "
89
+ }
90
+ });
91
+ records = ddbRecords.map((item)=>item.data);
92
+ } catch (ex) {
93
+ throw new error(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
94
+ error: ex,
95
+ ...params,
96
+ sort,
97
+ where
98
+ });
99
+ }
100
+ const filteredItems = filterUtil.filter({
101
+ items: records,
102
+ where,
103
+ fields: []
104
+ });
105
+ if (!sort || 0 === sort.length) return filteredItems;
106
+ return sortItems({
107
+ items: filteredItems,
108
+ sort
109
+ });
110
+ };
111
+ return {
112
+ create,
113
+ update,
114
+ delete: deleteGroup,
115
+ get,
116
+ list
117
+ };
190
118
  };
119
+ export { createGroupsStorageOperations };
191
120
 
192
- exports.createGroupsStorageOperations = createGroupsStorageOperations;
121
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createPartitionKey","params","tenant","locale","createSortKeys","id","createKeys","PK","SK","createType","createGroupsStorageOperations","entity","plugins","filteringPlugins","byType","ValueFilterPlugin","type","length","WebinyError","create","group","keys","put","TYPE","ex","message","code","error","update","deleteGroup","delete","get","getRecord","cleanupItem","list","sort","where","queryAllParams","partitionKey","options","gte","records","queryAll","filteredItems","filterItems","items","fields","sortItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, plugins } = params;\n\n const filteringPlugins = plugins.byType<ValueFilterPlugin>(ValueFilterPlugin.type);\n if (filteringPlugins.length === 0) {\n throw new WebinyError(\n \"DynamoDB filtering plugins not loaded.\",\n \"MISSING_DYNAMODB_FILTERING_PLUGINS\"\n );\n }\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n ...group,\n TYPE: createType(),\n ...keys\n });\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n // TODO make sure that group has locale and tenant on it - add it in the crud just in case\n const keys = createKeys(group);\n\n try {\n await entity.delete(keys);\n return group;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const group = await getRecord<CmsGroup>({\n entity,\n keys\n });\n\n return cleanupItem(entity, group);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n\n let records: CmsGroup[] = [];\n try {\n records = await queryAll(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterItems({\n items: records,\n where,\n fields: [],\n plugins\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n return sortItems({\n items: filteredItems,\n sort,\n fields: []\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EAC/D,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,OAAQ,KAAIC,MAAO,MAAKC,MAAO,UAA/B;AACH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ent":["import type {\n CmsContext,\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport { sortItems } from \"@webiny/db-dynamodb\";\nimport type { IGroupEntity } from \"~/definitions/types.js\";\nimport { FilterUtil } from \"@webiny/db-dynamodb/feature/FilterUtil/index.js\";\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant } = params;\n return `T#${tenant}#CMS#CMG`;\n};\n\ninterface SortKeyParams {\n id: string;\n}\nconst createSortKeys = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeyParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKeys(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.group\";\n};\n\ninterface CreateGroupsStorageOperationsParams {\n entity: IGroupEntity;\n container: CmsContext[\"container\"];\n}\nexport const createGroupsStorageOperations = (\n params: CreateGroupsStorageOperationsParams\n): CmsGroupStorageOperations => {\n const { entity, container } = params;\n const filterUtil = container.resolve(FilterUtil);\n\n const create = async (params: CmsGroupStorageOperationsCreateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create group.\",\n ex.code || \"CREATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const update = async (params: CmsGroupStorageOperationsUpdateParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.put({\n data: group,\n TYPE: createType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update group.\",\n ex.code || \"UPDATE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const deleteGroup = async (params: CmsGroupStorageOperationsDeleteParams) => {\n const { group } = params;\n const keys = createKeys(group);\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete group.\",\n ex.code || \"DELETE_GROUP_ERROR\",\n {\n error: ex,\n group,\n keys\n }\n );\n }\n };\n const get = async (params: CmsGroupStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const result = await entity.get(keys);\n\n return result?.data || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get group.\",\n ex.code || \"GET_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n keys\n }\n );\n }\n };\n const list = async (params: CmsGroupStorageOperationsListParams) => {\n const { sort, where } = params;\n\n let records: CmsGroup[] = [];\n try {\n const ddbRecords = await entity.queryAll({\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n });\n records = ddbRecords.map(item => item.data);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list groups.\",\n ex.code || \"LIST_GROUP_ERROR\",\n {\n error: ex,\n ...params,\n sort,\n where\n }\n );\n }\n\n const filteredItems = filterUtil.filter({\n items: records,\n where,\n fields: []\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n\n return sortItems({\n items: filteredItems,\n sort\n });\n };\n\n return {\n create,\n update,\n delete: deleteGroup,\n get,\n list\n };\n};\n"],"names":["createPartitionKey","params","tenant","createSortKeys","id","createKeys","createType","createGroupsStorageOperations","entity","container","filterUtil","FilterUtil","create","group","keys","ex","WebinyError","update","deleteGroup","get","result","list","sort","where","records","ddbRecords","item","filteredItems","sortItems"],"mappings":";;;AAkBA,MAAMA,qBAAqB,CAACC;IACxB,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,OAAO,CAAC,EAAE,EAAEC,OAAO,QAA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AAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IACA,MAAMK,MAAM,OAAOlB;QACf,MAAMa,OAAOT,WAAWJ;QAExB,IAAI;YACA,MAAMmB,SAAS,MAAMZ,OAAO,GAAG,CAACM;YAEhC,OAAOM,QAAQ,QAAQ;QAC3B,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wBACdA,GAAG,IAAI,IAAI,mBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTa;YACJ;QAER;IACJ;IACA,MAAMO,OAAO,OAAOpB;QAChB,MAAM,EAAEqB,IAAI,EAAEC,KAAK,EAAE,GAAGtB;QAExB,IAAIuB,UAAsB,EAAE;QAC5B,IAAI;YACA,MAAMC,aAAa,MAAMjB,OAAO,QAAQ,CAAC;gBACrC,cAAcR,mBAAmBuB;gBACjC,SAAS;oBACL,KAAK;gBACT;YACJ;YACAC,UAAUC,WAAW,GAAG,CAACC,CAAAA,OAAQA,KAAK,IAAI;QAC9C,EAAE,OAAOX,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,0BACdA,GAAG,IAAI,IAAI,oBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTqB;gBACAC;YACJ;QAER;QAEA,MAAMI,gBAAgBjB,WAAW,MAAM,CAAC;YACpC,OAAOc;YACPD;YACA,QAAQ,EAAE;QACd;QACA,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,EACpB,OAAOK;QAGX,OAAOC,UAAU;YACb,OAAOD;YACPL;QACJ;IACJ;IAEA,OAAO;QACHV;QACAK;QACA,QAAQC;QACRC;QACAE;IACJ;AACJ"}
@@ -1,7 +1,7 @@
1
- import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
1
+ import type { CmsModelStorageOperations } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { IModelEntity } from "../../definitions/types.js";
3
3
  interface CreateModelsStorageOperationsParams {
4
- entity: Entity<any>;
4
+ entity: IModelEntity;
5
5
  }
6
6
  export declare const createModelsStorageOperations: (params: CreateModelsStorageOperationsParams) => CmsModelStorageOperations;
7
7
  export {};
@@ -1,162 +1,106 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createModelsStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
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
- const createPartitionKey = params => {
21
- const {
22
- tenant,
23
- locale
24
- } = params;
25
-
26
- if (!tenant) {
27
- throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
28
- } else if (!locale) {
29
- throw new _error.default(`Missing locale variable when creating model partitionKey.`);
30
- }
31
-
32
- return `T#${tenant}#L#${locale}#CMS#CM`;
33
- };
34
-
35
- const createSortKey = params => {
36
- return params.modelId;
37
- };
38
-
39
- const createKeys = params => {
40
- return {
41
- PK: createPartitionKey(params),
42
- SK: createSortKey(params)
43
- };
44
- };
45
-
46
- const createType = () => {
47
- return "cms.model";
1
+ import error from "@webiny/error";
2
+ import { convertException } from "@webiny/utils";
3
+ const createPartitionKey = (params)=>{
4
+ const { tenant } = params;
5
+ if (!tenant) throw new error("Missing tenant variable when creating model partitionKey.");
6
+ return `T#${tenant}#CMS#CM`;
48
7
  };
49
-
50
- const createModelsStorageOperations = params => {
51
- const {
52
- entity
53
- } = params;
54
-
55
- const create = async params => {
56
- const {
57
- model
58
- } = params;
59
- const keys = createKeys(model);
60
-
61
- try {
62
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
63
- TYPE: createType()
64
- }));
65
- return model;
66
- } catch (ex) {
67
- throw new _error.default(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
68
- error: ex,
69
- model,
70
- keys
71
- });
72
- }
73
- };
74
-
75
- const update = async params => {
76
- const {
77
- model
78
- } = params;
79
- const keys = createKeys(model);
80
-
81
- try {
82
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
83
- TYPE: createType()
84
- }));
85
- return model;
86
- } catch (ex) {
87
- throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
88
- error: ex,
89
- model,
90
- keys
91
- });
92
- }
93
- };
94
-
95
- const deleteModel = async params => {
96
- const {
97
- model
98
- } = params;
99
- const keys = createKeys(model);
100
-
101
- try {
102
- await entity.delete(keys);
103
- return model;
104
- } catch (ex) {
105
- throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
106
- error: ex,
107
- model,
108
- keys
109
- });
110
- }
111
- };
112
-
113
- const get = async params => {
114
- const keys = createKeys(params);
115
-
116
- try {
117
- const item = await (0, _get.get)({
118
- entity,
119
- keys
120
- });
121
- return (0, _cleanup.cleanupItem)(entity, item);
122
- } catch (ex) {
123
- throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
124
- error: ex,
125
- keys
126
- });
127
- }
128
- };
129
-
130
- const list = async params => {
131
- const {
132
- where
133
- } = params;
134
- const queryAllParams = {
135
- entity,
136
- partitionKey: createPartitionKey(where),
137
- options: {
138
- gte: " "
139
- }
8
+ const createSortKey = (params)=>params.modelId;
9
+ const createKeys = (params)=>({
10
+ PK: createPartitionKey(params),
11
+ SK: createSortKey(params),
12
+ GSI_TENANT: params.tenant
13
+ });
14
+ const createType = ()=>"cms.model";
15
+ const createModelsStorageOperations = (params)=>{
16
+ const { entity } = params;
17
+ const create = async (params)=>{
18
+ const { model } = params;
19
+ const keys = createKeys(model);
20
+ try {
21
+ await entity.put({
22
+ data: model,
23
+ ...keys,
24
+ TYPE: createType()
25
+ });
26
+ return model;
27
+ } catch (ex) {
28
+ throw new error("Could not create CMS Content Model.", "CREATE_MODEL_ERROR", {
29
+ error: convertException(ex),
30
+ model,
31
+ keys
32
+ });
33
+ }
34
+ };
35
+ const update = async (params)=>{
36
+ const { model } = params;
37
+ const keys = createKeys(model);
38
+ try {
39
+ await entity.put({
40
+ data: model,
41
+ ...keys,
42
+ TYPE: createType()
43
+ });
44
+ return model;
45
+ } catch (ex) {
46
+ throw new error(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
47
+ error: ex,
48
+ model,
49
+ keys
50
+ });
51
+ }
52
+ };
53
+ const deleteModel = async (params)=>{
54
+ const { model } = params;
55
+ const keys = createKeys(model);
56
+ try {
57
+ await entity.delete(keys);
58
+ } catch (ex) {
59
+ throw new error(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
60
+ error: ex,
61
+ model,
62
+ keys
63
+ });
64
+ }
65
+ };
66
+ const get = async (params)=>{
67
+ const keys = createKeys(params);
68
+ try {
69
+ const result = await entity.get(keys);
70
+ return result?.data || null;
71
+ } catch (ex) {
72
+ throw new error(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
73
+ error: ex,
74
+ keys
75
+ });
76
+ }
77
+ };
78
+ const list = async (params)=>{
79
+ const { where } = params;
80
+ const partitionKey = createPartitionKey(where);
81
+ try {
82
+ const result = await entity.queryAll({
83
+ partitionKey,
84
+ options: {
85
+ gte: " "
86
+ }
87
+ });
88
+ return result.map((item)=>item.data);
89
+ } catch (ex) {
90
+ throw new error(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
91
+ error: ex,
92
+ partitionKey
93
+ });
94
+ }
95
+ };
96
+ return {
97
+ create,
98
+ update,
99
+ delete: deleteModel,
100
+ get,
101
+ list
140
102
  };
141
-
142
- try {
143
- const items = await (0, _query.queryAll)(queryAllParams);
144
- return (0, _cleanup.cleanupItems)(entity, items);
145
- } catch (ex) {
146
- throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
147
- error: ex,
148
- partitionKey: queryAllParams.partitionKey
149
- });
150
- }
151
- };
152
-
153
- return {
154
- create,
155
- update,
156
- delete: deleteModel,
157
- get,
158
- list
159
- };
160
103
  };
104
+ export { createModelsStorageOperations };
161
105
 
162
- exports.createModelsStorageOperations = createModelsStorageOperations;
106
+ //# sourceMappingURL=index.js.map