@webiny/api-headless-cms-ddb 0.0.0-unstable.a4637c5ce6 → 0.0.0-unstable.a4f3e4ea8b

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 (158) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -6
  3. package/definitions/entry.js +8 -185
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -6
  6. package/definitions/group.js +8 -63
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -6
  9. package/definitions/model.js +8 -107
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +3 -5
  12. package/definitions/table.js +6 -29
  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 +7 -13
  18. package/dynamoDb/index.js.map +1 -1
  19. package/index.d.ts +2 -3
  20. package/index.js +85 -121
  21. package/index.js.map +1 -1
  22. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -2
  23. package/operations/entry/dataLoader/DataLoaderCache.js +21 -35
  24. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  25. package/operations/entry/dataLoader/constants.js +2 -7
  26. package/operations/entry/dataLoader/constants.js.map +1 -1
  27. package/operations/entry/dataLoader/createBatchScheduleFn.js +7 -22
  28. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  29. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
  30. package/operations/entry/dataLoader/getAllEntryRevisions.js +20 -41
  31. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  32. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
  33. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +36 -52
  34. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  35. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
  36. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +36 -52
  37. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  38. package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
  39. package/operations/entry/dataLoader/getRevisionById.js +38 -58
  40. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  41. package/operations/entry/dataLoader/index.d.ts +3 -3
  42. package/operations/entry/dataLoader/index.js +13 -35
  43. package/operations/entry/dataLoader/index.js.map +1 -1
  44. package/operations/entry/dataLoader/types.d.ts +4 -4
  45. package/operations/entry/dataLoader/types.js +0 -7
  46. package/operations/entry/dataLoaders.d.ts +11 -12
  47. package/operations/entry/dataLoaders.js +83 -109
  48. package/operations/entry/dataLoaders.js.map +1 -1
  49. package/operations/entry/index.d.ts +4 -3
  50. package/operations/entry/index.js +908 -1277
  51. package/operations/entry/index.js.map +1 -1
  52. package/operations/entry/keys.d.ts +46 -2
  53. package/operations/entry/keys.js +52 -49
  54. package/operations/entry/keys.js.map +1 -1
  55. package/operations/group/index.d.ts +4 -5
  56. package/operations/group/index.js +113 -166
  57. package/operations/group/index.js.map +1 -1
  58. package/operations/model/index.d.ts +3 -3
  59. package/operations/model/index.js +99 -143
  60. package/operations/model/index.js.map +1 -1
  61. package/package.json +29 -25
  62. package/plugins/index.d.ts +2 -4
  63. package/plugins/index.js +1 -51
  64. package/types.d.ts +19 -42
  65. package/types.js +6 -12
  66. package/types.js.map +1 -1
  67. package/definitions/system.d.ts +0 -10
  68. package/definitions/system.js +0 -42
  69. package/definitions/system.js.map +0 -1
  70. package/dynamoDb/path/locationFolderId.d.ts +0 -2
  71. package/dynamoDb/path/locationFolderId.js +0 -43
  72. package/dynamoDb/path/locationFolderId.js.map +0 -1
  73. package/dynamoDb/path/plainObject.d.ts +0 -2
  74. package/dynamoDb/path/plainObject.js +0 -35
  75. package/dynamoDb/path/plainObject.js.map +0 -1
  76. package/dynamoDb/storage/longText.d.ts +0 -10
  77. package/dynamoDb/storage/longText.js +0 -94
  78. package/dynamoDb/storage/longText.js.map +0 -1
  79. package/dynamoDb/storage/richText.d.ts +0 -2
  80. package/dynamoDb/storage/richText.js +0 -61
  81. package/dynamoDb/storage/richText.js.map +0 -1
  82. package/dynamoDb/transformValue/datetime.d.ts +0 -5
  83. package/dynamoDb/transformValue/datetime.js +0 -47
  84. package/dynamoDb/transformValue/datetime.js.map +0 -1
  85. package/operations/entry/dataLoader/types.js.map +0 -1
  86. package/operations/entry/filtering/createExpressions.d.ts +0 -26
  87. package/operations/entry/filtering/createExpressions.js +0 -178
  88. package/operations/entry/filtering/createExpressions.js.map +0 -1
  89. package/operations/entry/filtering/createFields.d.ts +0 -16
  90. package/operations/entry/filtering/createFields.js +0 -108
  91. package/operations/entry/filtering/createFields.js.map +0 -1
  92. package/operations/entry/filtering/extractSort.d.ts +0 -17
  93. package/operations/entry/filtering/extractSort.js +0 -69
  94. package/operations/entry/filtering/extractSort.js.map +0 -1
  95. package/operations/entry/filtering/filter.d.ts +0 -15
  96. package/operations/entry/filtering/filter.js +0 -158
  97. package/operations/entry/filtering/filter.js.map +0 -1
  98. package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
  99. package/operations/entry/filtering/fullTextSearch.js +0 -50
  100. package/operations/entry/filtering/fullTextSearch.js.map +0 -1
  101. package/operations/entry/filtering/getValue.d.ts +0 -5
  102. package/operations/entry/filtering/getValue.js +0 -66
  103. package/operations/entry/filtering/getValue.js.map +0 -1
  104. package/operations/entry/filtering/index.d.ts +0 -2
  105. package/operations/entry/filtering/index.js +0 -21
  106. package/operations/entry/filtering/index.js.map +0 -1
  107. package/operations/entry/filtering/mapPlugins.d.ts +0 -8
  108. package/operations/entry/filtering/mapPlugins.js +0 -33
  109. package/operations/entry/filtering/mapPlugins.js.map +0 -1
  110. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
  111. package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -45
  112. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
  113. package/operations/entry/filtering/plugins/index.d.ts +0 -1
  114. package/operations/entry/filtering/plugins/index.js +0 -16
  115. package/operations/entry/filtering/plugins/index.js.map +0 -1
  116. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
  117. package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -90
  118. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
  119. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
  120. package/operations/entry/filtering/plugins/refFilterCreate.js +0 -80
  121. package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
  122. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
  123. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -65
  124. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
  125. package/operations/entry/filtering/sort.d.ts +0 -12
  126. package/operations/entry/filtering/sort.js +0 -71
  127. package/operations/entry/filtering/sort.js.map +0 -1
  128. package/operations/entry/filtering/systemFields.d.ts +0 -4
  129. package/operations/entry/filtering/systemFields.js +0 -90
  130. package/operations/entry/filtering/systemFields.js.map +0 -1
  131. package/operations/entry/filtering/transform.d.ts +0 -6
  132. package/operations/entry/filtering/transform.js +0 -18
  133. package/operations/entry/filtering/transform.js.map +0 -1
  134. package/operations/entry/filtering/types.d.ts +0 -40
  135. package/operations/entry/filtering/types.js +0 -7
  136. package/operations/entry/filtering/types.js.map +0 -1
  137. package/operations/entry/filtering/values.d.ts +0 -2
  138. package/operations/entry/filtering/values.js +0 -24
  139. package/operations/entry/filtering/values.js.map +0 -1
  140. package/operations/entry/filtering/where.d.ts +0 -5
  141. package/operations/entry/filtering/where.js +0 -35
  142. package/operations/entry/filtering/where.js.map +0 -1
  143. package/operations/system/index.d.ts +0 -7
  144. package/operations/system/index.js +0 -94
  145. package/operations/system/index.js.map +0 -1
  146. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
  147. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -48
  148. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
  149. package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
  150. package/plugins/CmsEntryFieldFilterPlugin.js +0 -27
  151. package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
  152. package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
  153. package/plugins/CmsEntryFieldSortingPlugin.js +0 -27
  154. package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
  155. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
  156. package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -23
  157. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
  158. package/plugins/index.js.map +0 -1
@@ -1,174 +1,121 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createGroupsStorageOperations = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _get = require("@webiny/db-dynamodb/utils/get");
10
- var _query = require("@webiny/db-dynamodb/utils/query");
11
- var _filter = require("@webiny/db-dynamodb/utils/filter");
12
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
13
- var _sort = require("@webiny/db-dynamodb/utils/sort");
14
- var _dbDynamodb = require("@webiny/db-dynamodb");
15
- const createPartitionKey = params => {
16
- const {
17
- tenant,
18
- locale
19
- } = params;
20
- return `T#${tenant}#L#${locale}#CMS#CMG`;
21
- };
22
- const createSortKeys = params => {
23
- const {
24
- id
25
- } = params;
26
- return id;
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`;
27
7
  };
28
- const createKeys = params => {
29
- return {
30
- PK: createPartitionKey(params),
31
- SK: createSortKeys(params)
32
- };
8
+ const createSortKeys = (params)=>{
9
+ const { id } = params;
10
+ return id;
33
11
  };
34
- const createType = () => {
35
- return "cms.group";
36
- };
37
- const createGroupsStorageOperations = params => {
38
- const {
39
- entity,
40
- plugins
41
- } = params;
42
- const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
43
- if (filteringPlugins.length === 0) {
44
- throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
45
- }
46
- const create = async params => {
47
- const {
48
- group
49
- } = params;
50
- const keys = createKeys(group);
51
- try {
52
- await (0, _dbDynamodb.put)({
53
- entity,
54
- item: {
55
- ...group,
56
- TYPE: createType(),
57
- ...keys
12
+ const createKeys = (params)=>({
13
+ PK: createPartitionKey(params),
14
+ SK: createSortKeys(params),
15
+ GSI_TENANT: params.tenant
16
+ });
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
+ });
58
36
  }
59
- });
60
- return group;
61
- } catch (ex) {
62
- throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
63
- error: ex,
64
- group,
65
- keys
66
- });
67
- }
68
- };
69
- const update = async params => {
70
- const {
71
- group
72
- } = params;
73
- const keys = createKeys(group);
74
- try {
75
- await (0, _dbDynamodb.put)({
76
- entity,
77
- item: {
78
- ...group,
79
- TYPE: createType(),
80
- ...keys
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
+ });
81
53
  }
82
- });
83
- return group;
84
- } catch (ex) {
85
- throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
86
- error: ex,
87
- group,
88
- keys
89
- });
90
- }
91
- };
92
- const deleteGroup = async params => {
93
- const {
94
- group
95
- } = params;
96
- const keys = createKeys(group);
97
- try {
98
- await (0, _dbDynamodb.deleteItem)({
99
- entity,
100
- keys
101
- });
102
- return group;
103
- } catch (ex) {
104
- throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
105
- error: ex,
106
- group,
107
- keys
108
- });
109
- }
110
- };
111
- const get = async params => {
112
- const keys = createKeys(params);
113
- try {
114
- return await (0, _get.getClean)({
115
- entity,
116
- keys
117
- });
118
- } catch (ex) {
119
- throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
120
- error: ex,
121
- ...params,
122
- keys
123
- });
124
- }
125
- };
126
- const list = async params => {
127
- const {
128
- sort,
129
- where
130
- } = params;
131
- const queryAllParams = {
132
- entity,
133
- partitionKey: createPartitionKey(where),
134
- options: {
135
- gte: " "
136
- }
137
54
  };
138
- let records = [];
139
- try {
140
- records = await (0, _query.queryAll)(queryAllParams);
141
- } catch (ex) {
142
- throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
143
- error: ex,
144
- ...params,
145
- sort,
146
- where
147
- });
148
- }
149
- const filteredItems = (0, _filter.filterItems)({
150
- items: records,
151
- where,
152
- fields: [],
153
- plugins
154
- });
155
- if (!sort || sort.length === 0) {
156
- return filteredItems;
157
- }
158
- return (0, _sort.sortItems)({
159
- items: filteredItems,
160
- sort,
161
- fields: []
162
- });
163
- };
164
- return {
165
- create,
166
- update,
167
- delete: deleteGroup,
168
- get,
169
- list
170
- };
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
+ };
171
118
  };
172
- exports.createGroupsStorageOperations = createGroupsStorageOperations;
119
+ export { createGroupsStorageOperations };
173
120
 
174
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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;EACrE,OAAO;IACHM,EAAE,EAAEP,kBAAkB,CAACC,MAAM,CAAC;IAC9BO,EAAE,EAAEJ,cAAc,CAACH,MAAM;EAC7B,CAAC;AACL,CAAC;AAED,MAAMQ,UAAU,GAAGA,CAAA,KAAc;EAC7B,OAAO,WAAW;AACtB,CAAC;AAMM,MAAMC,6BAA6B,GACtCT,MAA2C,IACf;EAC5B,MAAM;IAAEU,MAAM;IAAEC;E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T;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
+ {"version":3,"file":"operations/group/index.js","sources":["../../../src/operations/group/index.ts"],"sourcesContent":["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,QAAQ,CAAC;AAChC;AAKA,MAAMC,iBAAiB,CAACF;IACpB,MAAM,EAAEG,EAAE,EAAE,GAAGH;IACf,OAAOG;AACX;AAOA,MAAMC,aAAa,CAACJ,SACT;QACH,IAAID,mBAAmBC;QACvB,IAAIE,eAAeF;QACnB,YAAYA,OAAO,MAAM;IAC7B;AAGJ,MAAMK,aAAa,IACR;AAOJ,MAAMC,gCAAgC,CACzCN;IAEA,MAAM,EAAEO,MAAM,EAAEC,SAAS,EAAE,GAAGR;IAC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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 type { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
2
- import type { Entity } from "@webiny/db-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,150 +1,106 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createModelsStorageOperations = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _get = require("@webiny/db-dynamodb/utils/get");
10
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
11
- var _query = require("@webiny/db-dynamodb/utils/query");
12
- var _dbDynamodb = require("@webiny/db-dynamodb");
13
- const createPartitionKey = params => {
14
- const {
15
- tenant,
16
- locale
17
- } = params;
18
- if (!tenant) {
19
- throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
20
- } else if (!locale) {
21
- throw new _error.default(`Missing locale variable when creating model partitionKey.`);
22
- }
23
- return `T#${tenant}#L#${locale}#CMS#CM`;
24
- };
25
- const createSortKey = params => {
26
- return params.modelId;
27
- };
28
- const createKeys = params => {
29
- return {
30
- PK: createPartitionKey(params),
31
- SK: createSortKey(params)
32
- };
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`;
33
7
  };
34
- const createType = () => {
35
- return "cms.model";
36
- };
37
- const createModelsStorageOperations = params => {
38
- const {
39
- entity
40
- } = params;
41
- const create = async params => {
42
- const {
43
- model
44
- } = params;
45
- const keys = createKeys(model);
46
- try {
47
- await (0, _dbDynamodb.put)({
48
- entity,
49
- item: {
50
- ...(0, _cleanup.cleanupItem)(entity, model),
51
- ...keys,
52
- TYPE: createType()
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
+ });
53
51
  }
54
- });
55
- return model;
56
- } catch (ex) {
57
- throw new _error.default(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
58
- error: ex,
59
- model,
60
- keys
61
- });
62
- }
63
- };
64
- const update = async params => {
65
- const {
66
- model
67
- } = params;
68
- const keys = createKeys(model);
69
- try {
70
- await (0, _dbDynamodb.put)({
71
- entity,
72
- item: {
73
- ...(0, _cleanup.cleanupItem)(entity, model),
74
- ...keys,
75
- TYPE: createType()
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
76
  }
77
- });
78
- return model;
79
- } catch (ex) {
80
- throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
81
- error: ex,
82
- model,
83
- keys
84
- });
85
- }
86
- };
87
- const deleteModel = async params => {
88
- const {
89
- model
90
- } = params;
91
- const keys = createKeys(model);
92
- try {
93
- await (0, _dbDynamodb.deleteItem)({
94
- entity,
95
- keys
96
- });
97
- return model;
98
- } catch (ex) {
99
- throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
100
- error: ex,
101
- model,
102
- keys
103
- });
104
- }
105
- };
106
- const get = async params => {
107
- const keys = createKeys(params);
108
- try {
109
- return await (0, _get.getClean)({
110
- entity,
111
- keys
112
- });
113
- } catch (ex) {
114
- throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
115
- error: ex,
116
- keys
117
- });
118
- }
119
- };
120
- const list = async params => {
121
- const {
122
- where
123
- } = params;
124
- const queryAllParams = {
125
- entity,
126
- partitionKey: createPartitionKey(where),
127
- options: {
128
- gte: " "
129
- }
130
77
  };
131
- try {
132
- return await (0, _query.queryAllClean)(queryAllParams);
133
- } catch (ex) {
134
- throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
135
- error: ex,
136
- partitionKey: queryAllParams.partitionKey
137
- });
138
- }
139
- };
140
- return {
141
- create,
142
- update,
143
- delete: deleteModel,
144
- get,
145
- list
146
- };
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
102
+ };
147
103
  };
148
- exports.createModelsStorageOperations = createModelsStorageOperations;
104
+ export { createModelsStorageOperations };
149
105
 
150
106
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,GA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AC;IACL;EACJ,CAAC;EAED,MAAMY,GAAG,GAAG,MAAO1B,MAA0C,IAAK;IAC9D,MAAMc,IAAI,GAAGR,UAAU,CAACN,MAAM,CAAC;IAE/B,IAAI;MACA,OAAO,MAAM,IAAA2B,aAAQ,EAAW;QAC5BhB,MAAM;QACNG;MACJ,CAAC,CAAC;IACN,CAAC,CAAC,OAAOK,EAAE,EAAE;MACT,MAAM,IAAIhB,cAAW,CACjBgB,EAAE,CAACG,OAAO,IAAI,sBAAsB,EACpCH,EAAE,CAACI,IAAI,IAAI,iBAAiB,EAC5B;QACIH,KAAK,EAAED,EAAE;QACTL;MACJ,CACJ,CAAC;IACL;EACJ,CAAC;EAED,MAAMc,IAAI,GAAG,MAAO5B,MAA2C,IAAK;IAChE,MAAM;MAAE6B;IAAM,CAAC,GAAG7B,MAAM;IACxB,MAAM8B,cAA8B,GAAG;MACnCnB,MAAM;MACNoB,YAAY,EAAEhC,kBAAkB,CAAC8B,KAAK,CAAC;MACvCG,OAAO,EAAE;QACLC,GAAG,EAAE;MACT;IACJ,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
+ {"version":3,"file":"operations/model/index.js","sources":["../../../src/operations/model/index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { convertException } from \"@webiny/utils\";\nimport type { IModelEntity } from \"~/definitions/types.js\";\n\ninterface PartitionKeysParams {\n tenant: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n }\n return `T#${tenant}#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 GSI_TENANT: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params),\n GSI_TENANT: params.tenant\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: IModelEntity;\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 data: 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: convertException(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 data: 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 } 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 result = await entity.get(keys);\n return result?.data || null;\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\n const partitionKey = createPartitionKey(where);\n\n try {\n const result = await entity.queryAll({\n partitionKey,\n options: {\n gte: \" \"\n }\n });\n return result.map(item => {\n return item.data;\n });\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\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"names":["createPartitionKey","params","tenant","WebinyError","createSortKey","createKeys","createType","createModelsStorageOperations","entity","create","model","keys","ex","convertException","update","deleteModel","get","result","list","where","partitionKey","item"],"mappings":";;AAeA,MAAMA,qBAAqB,CAACC;IACxB,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,IAAI,CAACC,QACD,MAAM,IAAIC,MAAY;IAE1B,OAAO,CAAC,EAAE,EAAED,OAAO,OAAO,CAAC;AAC/B;AAKA,MAAME,gBAAgB,CAACH,SACZA,OAAO,OAAO;AAQzB,MAAMI,aAAa,CAACJ,SACT;QACH,IAAID,mBAAmBC;QACvB,IAAIG,cAAcH;QAClB,YAAYA,OAAO,MAAM;IAC7B;AAGJ,MAAMK,aAAa,IACR;AAMJ,MAAMC,gCAAgC,CACzCN;IAEA,MAAM,EAAEO,MAAM,EAAE,GAAGP;IAEnB,MAAMQ,SAA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