@webiny/api-headless-cms-ddb 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/definitions/entry.d.ts +4 -3
  2. package/definitions/entry.js +108 -16
  3. package/definitions/entry.js.map +1 -1
  4. package/definitions/group.d.ts +4 -3
  5. package/definitions/group.js +8 -12
  6. package/definitions/group.js.map +1 -1
  7. package/definitions/model.d.ts +4 -3
  8. package/definitions/model.js +30 -12
  9. package/definitions/model.js.map +1 -1
  10. package/definitions/system.d.ts +4 -3
  11. package/definitions/system.js +8 -12
  12. package/definitions/system.js.map +1 -1
  13. package/definitions/table.d.ts +5 -5
  14. package/definitions/table.js +7 -6
  15. package/definitions/table.js.map +1 -1
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +4 -9
  18. package/dynamoDb/index.js.map +1 -1
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +43 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.js +3 -8
  23. package/dynamoDb/path/plainObject.js.map +1 -1
  24. package/dynamoDb/storage/longText.d.ts +1 -1
  25. package/dynamoDb/storage/longText.js +10 -17
  26. package/dynamoDb/storage/longText.js.map +1 -1
  27. package/dynamoDb/storage/richText.d.ts +1 -1
  28. package/dynamoDb/storage/richText.js +23 -75
  29. package/dynamoDb/storage/richText.js.map +1 -1
  30. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  31. package/dynamoDb/transformValue/datetime.js +3 -8
  32. package/dynamoDb/transformValue/datetime.js.map +1 -1
  33. package/index.d.ts +1 -1
  34. package/index.js +25 -41
  35. package/index.js.map +1 -1
  36. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  37. package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
  38. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  39. package/operations/entry/dataLoader/constants.d.ts +1 -0
  40. package/operations/entry/dataLoader/constants.js +10 -0
  41. package/operations/entry/dataLoader/constants.js.map +1 -0
  42. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  43. package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
  44. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  45. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  46. package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
  47. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  48. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  49. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +56 -0
  50. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  51. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  52. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +56 -0
  53. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  54. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  55. package/operations/entry/dataLoader/getRevisionById.js +62 -0
  56. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  57. package/operations/entry/dataLoader/index.d.ts +8 -0
  58. package/operations/entry/dataLoader/index.js +40 -0
  59. package/operations/entry/dataLoader/index.js.map +1 -0
  60. package/operations/entry/dataLoader/types.d.ts +6 -0
  61. package/operations/entry/dataLoader/types.js +7 -0
  62. package/operations/entry/dataLoader/types.js.map +1 -0
  63. package/operations/entry/dataLoaders.d.ts +12 -27
  64. package/operations/entry/dataLoaders.js +55 -260
  65. package/operations/entry/dataLoaders.js.map +1 -1
  66. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  67. package/operations/entry/filtering/createExpressions.js +178 -0
  68. package/operations/entry/filtering/createExpressions.js.map +1 -0
  69. package/operations/entry/filtering/createFields.d.ts +16 -0
  70. package/operations/entry/filtering/createFields.js +108 -0
  71. package/operations/entry/filtering/createFields.js.map +1 -0
  72. package/operations/entry/filtering/extractSort.d.ts +17 -0
  73. package/operations/entry/filtering/extractSort.js +69 -0
  74. package/operations/entry/filtering/extractSort.js.map +1 -0
  75. package/operations/entry/filtering/filter.d.ts +15 -0
  76. package/operations/entry/filtering/filter.js +158 -0
  77. package/operations/entry/filtering/filter.js.map +1 -0
  78. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  79. package/operations/entry/filtering/fullTextSearch.js +50 -0
  80. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  81. package/operations/entry/filtering/getValue.d.ts +5 -0
  82. package/operations/entry/filtering/getValue.js +66 -0
  83. package/operations/entry/filtering/getValue.js.map +1 -0
  84. package/operations/entry/filtering/index.d.ts +2 -0
  85. package/operations/entry/filtering/index.js +21 -0
  86. package/operations/entry/filtering/index.js.map +1 -0
  87. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  88. package/operations/entry/filtering/mapPlugins.js +33 -0
  89. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  90. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.js +45 -0
  92. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  93. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  94. package/operations/entry/filtering/plugins/index.js +16 -0
  95. package/operations/entry/filtering/plugins/index.js.map +1 -0
  96. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  97. package/operations/entry/filtering/plugins/objectFilterCreate.js +90 -0
  98. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  99. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  100. package/operations/entry/filtering/plugins/refFilterCreate.js +80 -0
  101. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  102. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +65 -0
  104. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  105. package/operations/entry/filtering/sort.d.ts +12 -0
  106. package/operations/entry/filtering/sort.js +71 -0
  107. package/operations/entry/filtering/sort.js.map +1 -0
  108. package/operations/entry/filtering/systemFields.d.ts +4 -0
  109. package/operations/entry/filtering/systemFields.js +90 -0
  110. package/operations/entry/filtering/systemFields.js.map +1 -0
  111. package/operations/entry/filtering/transform.d.ts +6 -0
  112. package/operations/entry/filtering/transform.js +18 -0
  113. package/operations/entry/filtering/transform.js.map +1 -0
  114. package/operations/entry/filtering/types.d.ts +40 -0
  115. package/operations/entry/filtering/types.js +7 -0
  116. package/operations/entry/filtering/types.js.map +1 -0
  117. package/operations/entry/filtering/values.d.ts +2 -0
  118. package/operations/entry/filtering/values.js +24 -0
  119. package/operations/entry/filtering/values.js.map +1 -0
  120. package/operations/entry/filtering/where.d.ts +5 -0
  121. package/operations/entry/filtering/where.js +35 -0
  122. package/operations/entry/filtering/where.js.map +1 -0
  123. package/operations/entry/index.d.ts +3 -3
  124. package/operations/entry/index.js +733 -284
  125. package/operations/entry/index.js.map +1 -1
  126. package/operations/entry/keys.js +2 -18
  127. package/operations/entry/keys.js.map +1 -1
  128. package/operations/group/index.d.ts +3 -3
  129. package/operations/group/index.js +33 -51
  130. package/operations/group/index.js.map +1 -1
  131. package/operations/model/index.d.ts +2 -2
  132. package/operations/model/index.js +25 -37
  133. package/operations/model/index.js.map +1 -1
  134. package/operations/system/index.d.ts +2 -2
  135. package/operations/system/index.js +18 -23
  136. package/operations/system/index.js.map +1 -1
  137. package/package.json +21 -26
  138. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  139. package/plugins/CmsEntryFieldFilterPathPlugin.js +11 -18
  140. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  141. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  142. package/plugins/CmsEntryFieldFilterPlugin.js +27 -0
  143. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  144. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  145. package/plugins/CmsEntryFieldSortingPlugin.js +27 -0
  146. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  147. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  148. package/plugins/CmsFieldFilterValueTransformPlugin.js +23 -0
  149. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  150. package/plugins/index.d.ts +3 -0
  151. package/plugins/index.js +36 -3
  152. package/plugins/index.js.map +1 -1
  153. package/types.d.ts +21 -14
  154. package/types.js +5 -6
  155. package/types.js.map +1 -1
  156. package/definitions/settings.d.ts +0 -9
  157. package/definitions/settings.js +0 -58
  158. package/definitions/settings.js.map +0 -1
  159. package/dynamoDb/storage/date.d.ts +0 -2
  160. package/dynamoDb/storage/date.js +0 -99
  161. package/dynamoDb/storage/date.js.map +0 -1
  162. package/operations/entry/systemFields.d.ts +0 -2
  163. package/operations/entry/systemFields.js +0 -74
  164. package/operations/entry/systemFields.js.map +0 -1
  165. package/operations/entry/utils.d.ts +0 -36
  166. package/operations/entry/utils.js +0 -680
  167. package/operations/entry/utils.js.map +0 -1
  168. package/operations/settings/index.d.ts +0 -7
  169. package/operations/settings/index.js +0 -135
  170. package/operations/settings/index.js.map +0 -1
@@ -1,28 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createGroupsStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
9
  var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
10
  var _query = require("@webiny/db-dynamodb/utils/query");
19
-
20
11
  var _filter = require("@webiny/db-dynamodb/utils/filter");
21
-
22
12
  var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
23
-
24
13
  var _sort = require("@webiny/db-dynamodb/utils/sort");
25
-
14
+ var _dbDynamodb = require("@webiny/db-dynamodb");
26
15
  const createPartitionKey = params => {
27
16
  const {
28
17
  tenant,
@@ -30,46 +19,44 @@ const createPartitionKey = params => {
30
19
  } = params;
31
20
  return `T#${tenant}#L#${locale}#CMS#CMG`;
32
21
  };
33
-
34
22
  const createSortKeys = params => {
35
23
  const {
36
24
  id
37
25
  } = params;
38
26
  return id;
39
27
  };
40
-
41
28
  const createKeys = params => {
42
29
  return {
43
30
  PK: createPartitionKey(params),
44
31
  SK: createSortKeys(params)
45
32
  };
46
33
  };
47
-
48
34
  const createType = () => {
49
35
  return "cms.group";
50
36
  };
51
-
52
37
  const createGroupsStorageOperations = params => {
53
38
  const {
54
39
  entity,
55
40
  plugins
56
41
  } = params;
57
42
  const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
58
-
59
43
  if (filteringPlugins.length === 0) {
60
44
  throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
61
45
  }
62
-
63
46
  const create = async params => {
64
47
  const {
65
48
  group
66
49
  } = params;
67
50
  const keys = createKeys(group);
68
-
69
51
  try {
70
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
71
- TYPE: createType()
72
- }, keys));
52
+ await (0, _dbDynamodb.put)({
53
+ entity,
54
+ item: {
55
+ ...group,
56
+ TYPE: createType(),
57
+ ...keys
58
+ }
59
+ });
73
60
  return group;
74
61
  } catch (ex) {
75
62
  throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
@@ -79,17 +66,20 @@ const createGroupsStorageOperations = params => {
79
66
  });
80
67
  }
81
68
  };
82
-
83
69
  const update = async params => {
84
70
  const {
85
71
  group
86
72
  } = params;
87
73
  const keys = createKeys(group);
88
-
89
74
  try {
90
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
91
- TYPE: createType()
92
- }, keys));
75
+ await (0, _dbDynamodb.put)({
76
+ entity,
77
+ item: {
78
+ ...group,
79
+ TYPE: createType(),
80
+ ...keys
81
+ }
82
+ });
93
83
  return group;
94
84
  } catch (ex) {
95
85
  throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
@@ -99,16 +89,16 @@ const createGroupsStorageOperations = params => {
99
89
  });
100
90
  }
101
91
  };
102
-
103
92
  const deleteGroup = async params => {
104
93
  const {
105
94
  group
106
- } = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
107
-
95
+ } = params;
108
96
  const keys = createKeys(group);
109
-
110
97
  try {
111
- await entity.delete(keys);
98
+ await (0, _dbDynamodb.deleteItem)({
99
+ entity,
100
+ keys
101
+ });
112
102
  return group;
113
103
  } catch (ex) {
114
104
  throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
@@ -118,25 +108,21 @@ const createGroupsStorageOperations = params => {
118
108
  });
119
109
  }
120
110
  };
121
-
122
111
  const get = async params => {
123
112
  const keys = createKeys(params);
124
-
125
113
  try {
126
- const group = await (0, _get.get)({
114
+ return await (0, _get.getClean)({
127
115
  entity,
128
116
  keys
129
117
  });
130
- return (0, _cleanup.cleanupItem)(entity, group);
131
118
  } 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), {}, {
119
+ throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
120
+ error: ex,
121
+ ...params,
135
122
  keys
136
- }));
123
+ });
137
124
  }
138
125
  };
139
-
140
126
  const list = async params => {
141
127
  const {
142
128
  sort,
@@ -150,36 +136,31 @@ const createGroupsStorageOperations = params => {
150
136
  }
151
137
  };
152
138
  let records = [];
153
-
154
139
  try {
155
140
  records = await (0, _query.queryAll)(queryAllParams);
156
141
  } 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), {}, {
142
+ throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
143
+ error: ex,
144
+ ...params,
160
145
  sort,
161
146
  where
162
- }));
147
+ });
163
148
  }
164
-
165
149
  const filteredItems = (0, _filter.filterItems)({
166
150
  items: records,
167
151
  where,
168
152
  fields: [],
169
153
  plugins
170
154
  });
171
-
172
155
  if (!sort || sort.length === 0) {
173
156
  return filteredItems;
174
157
  }
175
-
176
158
  return (0, _sort.sortItems)({
177
159
  items: filteredItems,
178
160
  sort,
179
161
  fields: []
180
162
  });
181
163
  };
182
-
183
164
  return {
184
165
  create,
185
166
  update,
@@ -188,5 +169,6 @@ const createGroupsStorageOperations = params => {
188
169
  list
189
170
  };
190
171
  };
172
+ exports.createGroupsStorageOperations = createGroupsStorageOperations;
191
173
 
192
- exports.createGroupsStorageOperations = createGroupsStorageOperations;
174
+ //# 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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AEbR,IAFa;MAGbW,MAAM,EAAE;IAHK,CAAV,CAAP;EAKH,CAzCD;;EA2CA,OAAO;IACH3B,MADG;IAEHS,MAFG;IAGHE,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CArJM"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_get","_query","_filter","_ValueFilterPlugin","_sort","_dbDynamodb","createPartitionKey","params","tenant","locale","createSortKeys","id","createKeys","PK","SK","createType","createGroupsStorageOperations","entity","plugins","filteringPlugins","byType","ValueFilterPlugin","type","length","WebinyError","create","group","keys","put","item","TYPE","ex","message","code","error","update","deleteGroup","deleteItem","get","getClean","list","sort","where","queryAllParams","partitionKey","options","gte","records","queryAll","filteredItems","filterItems","items","fields","sortItems","delete","exports"],"sources":["index.ts"],"sourcesContent":["import type {\n CmsGroup,\n CmsGroupStorageOperations,\n CmsGroupStorageOperationsCreateParams,\n CmsGroupStorageOperationsDeleteParams,\n CmsGroupStorageOperationsGetParams,\n CmsGroupStorageOperationsListParams,\n CmsGroupStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { getClean } from \"@webiny/db-dynamodb/utils/get\";\nimport type { QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { deleteItem, put } from \"@webiny/db-dynamodb\";\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 put({\n entity,\n item: {\n ...group,\n TYPE: createType(),\n ...keys\n }\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 put({\n entity,\n item: {\n ...group,\n TYPE: createType(),\n ...keys\n }\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 const keys = createKeys(group);\n try {\n await deleteItem({\n entity,\n keys\n });\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 return await getClean<CmsGroup>({\n entity,\n keys\n });\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAMA,MAAMO,kBAAkB,GAAIC,MAA0B,IAAa;EAC/D,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EACjC,OAAO,KAAKC,MAAM,MAAMC,MAAM,UAAU;AAC5C,CAAC;AAKD,MAAMC,cAAc,GAAIH,MAAqB,IAAa;EACtD,MAAM;IAAEI;EAAG,CAAC,GAAGJ,MAAM;EACrB,OAAOI,EAAE;AACb,CAAC;AAMD,MAAMC,UAAU,GAAIL,MAA0C,IAAW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,CACJ,CAAC;IACL;EACJ,CAAC;EACD,MAAMa,IAAI,GAAG,MAAOjC,MAA2C,IAAK;IAChE,MAAM;MAAEkC,IAAI;MAAEC;IAAM,CAAC,GAAGnC,MAAM;IAE9B,MAAMoC,cAA8B,GAAG;MACnC1B,MAAM;MACN2B,YAAY,EAAEtC,kBAAkB,CAACoC,KAAK,CAAC;MACvCG,OAAO,EAAE;QACLC,GAAG,EAAE;MACT;IACJ,CAAC;IAED,IAAIC,OAAmB,GAAG,EAAE;IAC5B,IAAI;MACAA,OAAO,GAAG,MAAM,IAAAC,eAAQ,EAACL,cAAc,CAAC;IAC5C,CAAC,CAAC,OAAOZ,EAAE,EAAE;MACT,MAAM,IAAIP,cAAW,CACjBO,EAAE,CAACC,OAAO,IAAI,wBAAwB,EACtCD,EAAE,CAACE,IAAI,IAAI,kBAAkB,EAC7B;QACIC,KAAK,EAAEH,EAAE;QACT,GAAGxB,MAAM;QACTkC,IAAI;QACJC;MACJ,CACJ,CAAC;IACL;IAEA,MAAMO,aAAa,GAAG,IAAAC,mBAAW,EAAC;MAC9BC,KAAK,EAAEJ,OAAO;MACdL,KAAK;MACLU,MAAM,EAAE,EAAE;MACVlC;IACJ,CAAC,CAAC;IACF,IAAI,CAACuB,IAAI,IAAIA,IAAI,CAAClB,MAAM,KAAK,CAAC,EAAE;MAC5B,OAAO0B,aAAa;IACxB;IACA,OAAO,IAAAI,eAAS,EAAC;MACbF,KAAK,EAAEF,aAAa;MACpBR,IAAI;MACJW,MAAM,EAAE;IACZ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACH3B,MAAM;IACNU,MAAM;IACNmB,MAAM,EAAElB,WAAW;IACnBE,GAAG;IACHE;EACJ,CAAC;AACL,CAAC;AAACe,OAAA,CAAAvC,6BAAA,GAAAA,6BAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
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";
2
+ import type { Entity } from "@webiny/db-dynamodb/toolbox";
3
3
  interface CreateModelsStorageOperationsParams {
4
4
  entity: Entity<any>;
5
5
  }
@@ -1,67 +1,57 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createModelsStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
9
  var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
10
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
11
  var _query = require("@webiny/db-dynamodb/utils/query");
19
-
12
+ var _dbDynamodb = require("@webiny/db-dynamodb");
20
13
  const createPartitionKey = params => {
21
14
  const {
22
15
  tenant,
23
16
  locale
24
17
  } = params;
25
-
26
18
  if (!tenant) {
27
19
  throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
28
20
  } else if (!locale) {
29
21
  throw new _error.default(`Missing locale variable when creating model partitionKey.`);
30
22
  }
31
-
32
23
  return `T#${tenant}#L#${locale}#CMS#CM`;
33
24
  };
34
-
35
25
  const createSortKey = params => {
36
26
  return params.modelId;
37
27
  };
38
-
39
28
  const createKeys = params => {
40
29
  return {
41
30
  PK: createPartitionKey(params),
42
31
  SK: createSortKey(params)
43
32
  };
44
33
  };
45
-
46
34
  const createType = () => {
47
35
  return "cms.model";
48
36
  };
49
-
50
37
  const createModelsStorageOperations = params => {
51
38
  const {
52
39
  entity
53
40
  } = params;
54
-
55
41
  const create = async params => {
56
42
  const {
57
43
  model
58
44
  } = params;
59
45
  const keys = createKeys(model);
60
-
61
46
  try {
62
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
63
- TYPE: createType()
64
- }));
47
+ await (0, _dbDynamodb.put)({
48
+ entity,
49
+ item: {
50
+ ...(0, _cleanup.cleanupItem)(entity, model),
51
+ ...keys,
52
+ TYPE: createType()
53
+ }
54
+ });
65
55
  return model;
66
56
  } catch (ex) {
67
57
  throw new _error.default(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
@@ -71,17 +61,20 @@ const createModelsStorageOperations = params => {
71
61
  });
72
62
  }
73
63
  };
74
-
75
64
  const update = async params => {
76
65
  const {
77
66
  model
78
67
  } = params;
79
68
  const keys = createKeys(model);
80
-
81
69
  try {
82
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
83
- TYPE: createType()
84
- }));
70
+ await (0, _dbDynamodb.put)({
71
+ entity,
72
+ item: {
73
+ ...(0, _cleanup.cleanupItem)(entity, model),
74
+ ...keys,
75
+ TYPE: createType()
76
+ }
77
+ });
85
78
  return model;
86
79
  } catch (ex) {
87
80
  throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
@@ -91,15 +84,16 @@ const createModelsStorageOperations = params => {
91
84
  });
92
85
  }
93
86
  };
94
-
95
87
  const deleteModel = async params => {
96
88
  const {
97
89
  model
98
90
  } = params;
99
91
  const keys = createKeys(model);
100
-
101
92
  try {
102
- await entity.delete(keys);
93
+ await (0, _dbDynamodb.deleteItem)({
94
+ entity,
95
+ keys
96
+ });
103
97
  return model;
104
98
  } catch (ex) {
105
99
  throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
@@ -109,16 +103,13 @@ const createModelsStorageOperations = params => {
109
103
  });
110
104
  }
111
105
  };
112
-
113
106
  const get = async params => {
114
107
  const keys = createKeys(params);
115
-
116
108
  try {
117
- const item = await (0, _get.get)({
109
+ return await (0, _get.getClean)({
118
110
  entity,
119
111
  keys
120
112
  });
121
- return (0, _cleanup.cleanupItem)(entity, item);
122
113
  } catch (ex) {
123
114
  throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
124
115
  error: ex,
@@ -126,7 +117,6 @@ const createModelsStorageOperations = params => {
126
117
  });
127
118
  }
128
119
  };
129
-
130
120
  const list = async params => {
131
121
  const {
132
122
  where
@@ -138,10 +128,8 @@ const createModelsStorageOperations = params => {
138
128
  gte: " "
139
129
  }
140
130
  };
141
-
142
131
  try {
143
- const items = await (0, _query.queryAll)(queryAllParams);
144
- return (0, _cleanup.cleanupItems)(entity, items);
132
+ return await (0, _query.queryAllClean)(queryAllParams);
145
133
  } catch (ex) {
146
134
  throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
147
135
  error: ex,
@@ -149,7 +137,6 @@ const createModelsStorageOperations = params => {
149
137
  });
150
138
  }
151
139
  };
152
-
153
140
  return {
154
141
  create,
155
142
  update,
@@ -158,5 +145,6 @@ const createModelsStorageOperations = params => {
158
145
  list
159
146
  };
160
147
  };
148
+ exports.createModelsStorageOperations = createModelsStorageOperations;
161
149
 
162
- exports.createModelsStorageOperations = createModelsStorageOperations;
150
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createPartitionKey","params","tenant","locale","WebinyError","createSortKey","modelId","createKeys","PK","SK","createType","createModelsStorageOperations","entity","create","model","keys","put","cleanupItem","TYPE","ex","error","update","message","code","deleteModel","delete","get","item","getRecord","list","where","queryAllParams","partitionKey","options","gte","items","queryAll","cleanupItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\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, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\n\ninterface PartitionKeysParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n } else if (!locale) {\n throw new WebinyError(`Missing locale variable when creating model partitionKey.`);\n }\n return `T#${tenant}#L#${locale}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: Entity<any>;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: ex,\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const item = await getRecord<CmsModel>({\n entity,\n keys\n });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n try {\n const items = await queryAll<CmsModel>(queryAllParams);\n\n return cleanupItems(entity, items);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAyC;EAChE,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;;EACA,IAAI,CAACC,MAAL,EAAa;IACT,MAAM,IAAIE,cAAJ,CAAiB,2DAAjB,CAAN;EACH,CAFD,MAEO,IAAI,CAACD,MAAL,EAAa;IAChB,MAAM,IAAIC,cAAJ,CAAiB,2DAAjB,CAAN;EACH;;EACD,OAAQ,KAAIF,MAAO,MAAKC,MAAO,SAA/B;AACH,CARD;;AAaA,MAAME,aAAa,GAAIJ,MAAD,IAAmC;EACrD,OAAOA,MAAM,CAACK,OAAd;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIN,MAAD,IAAuD;EACtE,OAAO;IACHO,EA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AAMC,KAAK,GAAG,MAAM,IAAAC,eAAA,EAAmBL,cAAnB,CAApB;MAEA,OAAO,IAAAM,qBAAA,EAAazB,MAAb,EAAqBuB,KAArB,CAAP;IACH,CAJD,CAIE,OAAOhB,EAAP,EAAW;MACT,MAAM,IAAIf,cAAJ,CACFe,EAAE,CAACG,OAAH,IAAc,wBADZ,EAEFH,EAAE,CAACI,IAAH,IAAW,kBAFT,EAGF;QACIH,KAAK,EAAED,EADX;QAEIa,YAAY,EAAED,cAAc,CAACC;MAFjC,CAHE,CAAN;IAQH;EACJ,CAvBD;;EAyBA,OAAO;IACHnB,MADG;IAEHQ,MAFG;IAGHI,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CA5HM"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_get","_cleanup","_query","_dbDynamodb","createPartitionKey","params","tenant","locale","WebinyError","createSortKey","modelId","createKeys","PK","SK","createType","createModelsStorageOperations","entity","create","model","keys","put","item","cleanupItem","TYPE","ex","error","update","message","code","deleteModel","deleteItem","get","getClean","list","where","queryAllParams","partitionKey","options","gte","queryAllClean","delete","exports"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModel,\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport { getClean } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { queryAllClean } from \"@webiny/db-dynamodb/utils/query\";\nimport { deleteItem, put } from \"@webiny/db-dynamodb\";\n\ninterface PartitionKeysParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n } else if (!locale) {\n throw new WebinyError(`Missing locale variable when creating model partitionKey.`);\n }\n return `T#${tenant}#L#${locale}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: Entity<any>;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await put({\n entity,\n item: {\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n }\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: ex,\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await put({\n entity,\n item: {\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n }\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await deleteItem({\n entity,\n keys\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n return await getClean<CmsModel>({\n entity,\n keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n try {\n return await queryAllClean<CmsModel>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAMA,MAAMK,kBAAkB,GAAIC,MAA2B,IAAa;EAChE,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EACjC,IAAI,CAACC,MAAM,EAAE;IACT,MAAM,IAAIE,cAAW,CAAC,2DAA2D,CAAC;EACtF,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;IAChB,MAAM,IAAIC,cAAW,CAAC,2DAA2D,CAAC;EACtF;EACA,OAAO,KAAKF,MAAM,MAAMC,MAAM,SAAS;AAC3C,CAAC;AAKD,MAAME,aAAa,GAAIJ,MAAqB,IAAa;EACrD,OAAOA,MAAM,CAACK,OAAO;AACzB,CAAC;AAMD,MAAMC,UAAU,GAAIN,MAA2C,IAAW;EACtE,OAAO;IACHO,EAAE,EAAER,kBAAkB,CAACC,MAAM,CAAC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CAAC;IACD,IAAI;MACA,OAAO,MAAM,IAAAC,oBAAa,EAAWJ,cAAc,CAAC;IACxD,CAAC,CAAC,OAAOX,EAAE,EAAE;MACT,MAAM,IAAIhB,cAAW,CACjBgB,EAAE,CAACG,OAAO,IAAI,wBAAwB,EACtCH,EAAE,CAACI,IAAI,IAAI,kBAAkB,EAC7B;QACIH,KAAK,EAAED,EAAE;QACTY,YAAY,EAAED,cAAc,CAACC;MACjC,CACJ,CAAC;IACL;EACJ,CAAC;EAED,OAAO;IACHnB,MAAM;IACNS,MAAM;IACNc,MAAM,EAAEX,WAAW;IACnBE,GAAG;IACHE;EACJ,CAAC;AACL,CAAC;AAACQ,OAAA,CAAA1B,6BAAA,GAAAA,6BAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
1
+ import type { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import type { Entity } from "@webiny/db-dynamodb/toolbox";
3
3
  interface CreateSystemStorageOperationsParams {
4
4
  entity: Entity<any>;
5
5
  }
@@ -1,49 +1,43 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSystemStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
9
  var _get = require("@webiny/db-dynamodb/utils/get");
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
10
+ var _dbDynamodb = require("@webiny/db-dynamodb");
18
11
  const createPartitionKey = ({
19
12
  tenant
20
13
  }) => {
21
14
  return `T#${tenant.toLowerCase()}#SYSTEM`;
22
15
  };
23
-
24
16
  const createSortKey = () => {
25
17
  return "CMS";
26
18
  };
27
-
28
19
  const createKeys = params => {
29
20
  return {
30
21
  PK: createPartitionKey(params),
31
22
  SK: createSortKey()
32
23
  };
33
24
  };
34
-
35
25
  const createSystemStorageOperations = params => {
36
26
  const {
37
27
  entity
38
28
  } = params;
39
-
40
29
  const create = async ({
41
30
  system
42
31
  }) => {
43
32
  const keys = createKeys(system);
44
-
45
33
  try {
46
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
34
+ await (0, _dbDynamodb.put)({
35
+ entity,
36
+ item: {
37
+ ...system,
38
+ ...keys
39
+ }
40
+ });
47
41
  return system;
48
42
  } catch (ex) {
49
43
  throw new _error.default(ex.message || "Could not create system.", ex.code || "CREATE_SYSTEM_ERROR", {
@@ -53,15 +47,19 @@ const createSystemStorageOperations = params => {
53
47
  });
54
48
  }
55
49
  };
56
-
57
50
  const update = async params => {
58
51
  const {
59
52
  system
60
53
  } = params;
61
54
  const keys = createKeys(system);
62
-
63
55
  try {
64
- await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
56
+ await (0, _dbDynamodb.put)({
57
+ entity,
58
+ item: {
59
+ ...system,
60
+ ...keys
61
+ }
62
+ });
65
63
  return system;
66
64
  } catch (ex) {
67
65
  throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
@@ -71,16 +69,13 @@ const createSystemStorageOperations = params => {
71
69
  });
72
70
  }
73
71
  };
74
-
75
72
  const get = async params => {
76
73
  const keys = createKeys(params);
77
-
78
74
  try {
79
- const system = await (0, _get.get)({
75
+ return await (0, _get.getClean)({
80
76
  entity,
81
77
  keys
82
78
  });
83
- return (0, _cleanup.cleanupItem)(entity, system);
84
79
  } catch (ex) {
85
80
  throw new _error.default(ex.message || "Could not get system.", ex.code || "GET_SYSTEM_ERROR", {
86
81
  error: ex,
@@ -88,12 +83,12 @@ const createSystemStorageOperations = params => {
88
83
  });
89
84
  }
90
85
  };
91
-
92
86
  return {
93
87
  create,
94
88
  update,
95
89
  get
96
90
  };
97
91
  };
92
+ exports.createSystemStorageOperations = createSystemStorageOperations;
98
93
 
99
- exports.createSystemStorageOperations = createSystemStorageOperations;
94
+ //# sourceMappingURL=index.js.map