@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -20
- package/definitions/entry.d.ts +4 -5
- package/definitions/entry.js +9 -94
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +9 -68
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- package/definitions/model.js +9 -90
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +4 -6
- package/definitions/table.js +8 -30
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +65 -0
- package/definitions/types.js +0 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +11 -20
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +21 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +13 -37
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +27 -50
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +83 -139
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +5 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +42 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +18 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +0 -0
- package/operations/entry/dataLoaders.d.ts +14 -30
- package/operations/entry/dataLoaders.js +83 -314
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +27 -0
- package/operations/entry/filtering/createExpressions.js +124 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +16 -0
- package/operations/entry/filtering/createFields.js +93 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +17 -0
- package/operations/entry/filtering/extractSort.js +60 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +16 -0
- package/operations/entry/filtering/filter.js +85 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
- package/operations/entry/filtering/fullTextSearch.js +25 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +37 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +2 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +18 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +33 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +13 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +68 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +63 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +49 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +12 -0
- package/operations/entry/filtering/sort.js +41 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +2 -0
- package/operations/entry/filtering/systemFields.js +149 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +7 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +0 -0
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +15 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +22 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.d.ts +5 -4
- package/operations/entry/index.js +931 -845
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +46 -2
- package/operations/entry/keys.js +53 -66
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -5
- package/operations/group/index.js +116 -187
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +102 -158
- package/operations/model/index.js.map +1 -1
- package/package.json +34 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +5 -4
- package/plugins/CmsEntryFieldFilterPathPlugin.js +25 -50
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +4 -1
- package/plugins/index.js +4 -18
- package/types.d.ts +28 -21
- package/types.js +8 -15
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -58
- package/definitions/settings.js.map +0 -1
- package/definitions/system.d.ts +0 -9
- package/definitions/system.js +0 -46
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -2
- package/dynamoDb/storage/date.js +0 -99
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -101
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -113
- package/dynamoDb/storage/richText.js.map +0 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -74
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/entry/utils.d.ts +0 -36
- package/operations/entry/utils.js +0 -680
- package/operations/entry/utils.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -135
- package/operations/settings/index.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -99
- package/operations/system/index.js.map +0 -1
- package/plugins/index.js.map +0 -1
|
@@ -1,192 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
exports.createGroupsStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
|
-
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
15
|
-
|
|
16
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
-
|
|
18
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
-
|
|
20
|
-
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
21
|
-
|
|
22
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
23
|
-
|
|
24
|
-
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
25
|
-
|
|
26
|
-
const createPartitionKey = params => {
|
|
27
|
-
const {
|
|
28
|
-
tenant,
|
|
29
|
-
locale
|
|
30
|
-
} = params;
|
|
31
|
-
return `T#${tenant}#L#${locale}#CMS#CMG`;
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { sortItems } from "@webiny/db-dynamodb";
|
|
3
|
+
import { FilterUtil } from "@webiny/db-dynamodb/feature/FilterUtil/index.js";
|
|
4
|
+
const createPartitionKey = (params)=>{
|
|
5
|
+
const { tenant } = params;
|
|
6
|
+
return `T#${tenant}#CMS#CMG`;
|
|
32
7
|
};
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
id
|
|
37
|
-
} = params;
|
|
38
|
-
return id;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const createKeys = params => {
|
|
42
|
-
return {
|
|
43
|
-
PK: createPartitionKey(params),
|
|
44
|
-
SK: createSortKeys(params)
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const createType = () => {
|
|
49
|
-
return "cms.group";
|
|
8
|
+
const createSortKeys = (params)=>{
|
|
9
|
+
const { id } = params;
|
|
10
|
+
return id;
|
|
50
11
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
plugins
|
|
56
|
-
} = params;
|
|
57
|
-
const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
|
|
58
|
-
|
|
59
|
-
if (filteringPlugins.length === 0) {
|
|
60
|
-
throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const create = async params => {
|
|
64
|
-
const {
|
|
65
|
-
group
|
|
66
|
-
} = params;
|
|
67
|
-
const keys = createKeys(group);
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
|
|
71
|
-
TYPE: createType()
|
|
72
|
-
}, keys));
|
|
73
|
-
return group;
|
|
74
|
-
} catch (ex) {
|
|
75
|
-
throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
|
|
76
|
-
error: ex,
|
|
77
|
-
group,
|
|
78
|
-
keys
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const update = async params => {
|
|
84
|
-
const {
|
|
85
|
-
group
|
|
86
|
-
} = params;
|
|
87
|
-
const keys = createKeys(group);
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, group), {}, {
|
|
91
|
-
TYPE: createType()
|
|
92
|
-
}, keys));
|
|
93
|
-
return group;
|
|
94
|
-
} catch (ex) {
|
|
95
|
-
throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
|
|
96
|
-
error: ex,
|
|
97
|
-
group,
|
|
98
|
-
keys
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const deleteGroup = async params => {
|
|
104
|
-
const {
|
|
105
|
-
group
|
|
106
|
-
} = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
|
|
107
|
-
|
|
108
|
-
const keys = createKeys(group);
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await entity.delete(keys);
|
|
112
|
-
return group;
|
|
113
|
-
} catch (ex) {
|
|
114
|
-
throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
|
|
115
|
-
error: ex,
|
|
116
|
-
group,
|
|
117
|
-
keys
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const get = async params => {
|
|
123
|
-
const keys = createKeys(params);
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
const group = await (0, _get.get)({
|
|
127
|
-
entity,
|
|
128
|
-
keys
|
|
129
|
-
});
|
|
130
|
-
return (0, _cleanup.cleanupItem)(entity, group);
|
|
131
|
-
} catch (ex) {
|
|
132
|
-
throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
133
|
-
error: ex
|
|
134
|
-
}, params), {}, {
|
|
135
|
-
keys
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const list = async params => {
|
|
141
|
-
const {
|
|
142
|
-
sort,
|
|
143
|
-
where
|
|
144
|
-
} = params;
|
|
145
|
-
const queryAllParams = {
|
|
146
|
-
entity,
|
|
147
|
-
partitionKey: createPartitionKey(where),
|
|
148
|
-
options: {
|
|
149
|
-
gte: " "
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
let records = [];
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
records = await (0, _query.queryAll)(queryAllParams);
|
|
156
|
-
} catch (ex) {
|
|
157
|
-
throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
158
|
-
error: ex
|
|
159
|
-
}, params), {}, {
|
|
160
|
-
sort,
|
|
161
|
-
where
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const filteredItems = (0, _filter.filterItems)({
|
|
166
|
-
items: records,
|
|
167
|
-
where,
|
|
168
|
-
fields: [],
|
|
169
|
-
plugins
|
|
12
|
+
const createKeys = (params)=>({
|
|
13
|
+
PK: createPartitionKey(params),
|
|
14
|
+
SK: createSortKeys(params),
|
|
15
|
+
GSI_TENANT: params.tenant
|
|
170
16
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
17
|
+
const createType = ()=>"cms.group";
|
|
18
|
+
const createGroupsStorageOperations = (params)=>{
|
|
19
|
+
const { entity, container } = params;
|
|
20
|
+
const filterUtil = container.resolve(FilterUtil);
|
|
21
|
+
const create = async (params)=>{
|
|
22
|
+
const { group } = params;
|
|
23
|
+
const keys = createKeys(group);
|
|
24
|
+
try {
|
|
25
|
+
await entity.put({
|
|
26
|
+
data: group,
|
|
27
|
+
TYPE: createType(),
|
|
28
|
+
...keys
|
|
29
|
+
});
|
|
30
|
+
} catch (ex) {
|
|
31
|
+
throw new error(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
|
|
32
|
+
error: ex,
|
|
33
|
+
group,
|
|
34
|
+
keys
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const update = async (params)=>{
|
|
39
|
+
const { group } = params;
|
|
40
|
+
const keys = createKeys(group);
|
|
41
|
+
try {
|
|
42
|
+
await entity.put({
|
|
43
|
+
data: group,
|
|
44
|
+
TYPE: createType(),
|
|
45
|
+
...keys
|
|
46
|
+
});
|
|
47
|
+
} catch (ex) {
|
|
48
|
+
throw new error(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
|
|
49
|
+
error: ex,
|
|
50
|
+
group,
|
|
51
|
+
keys
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const deleteGroup = async (params)=>{
|
|
56
|
+
const { group } = params;
|
|
57
|
+
const keys = createKeys(group);
|
|
58
|
+
try {
|
|
59
|
+
await entity.delete(keys);
|
|
60
|
+
} catch (ex) {
|
|
61
|
+
throw new error(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
|
|
62
|
+
error: ex,
|
|
63
|
+
group,
|
|
64
|
+
keys
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const get = async (params)=>{
|
|
69
|
+
const keys = createKeys(params);
|
|
70
|
+
try {
|
|
71
|
+
const result = await entity.get(keys);
|
|
72
|
+
return result?.data || null;
|
|
73
|
+
} catch (ex) {
|
|
74
|
+
throw new error(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", {
|
|
75
|
+
error: ex,
|
|
76
|
+
...params,
|
|
77
|
+
keys
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const list = async (params)=>{
|
|
82
|
+
const { sort, where } = params;
|
|
83
|
+
let records = [];
|
|
84
|
+
try {
|
|
85
|
+
const ddbRecords = await entity.queryAll({
|
|
86
|
+
partitionKey: createPartitionKey(where),
|
|
87
|
+
options: {
|
|
88
|
+
gte: " "
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
records = ddbRecords.map((item)=>item.data);
|
|
92
|
+
} catch (ex) {
|
|
93
|
+
throw new error(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", {
|
|
94
|
+
error: ex,
|
|
95
|
+
...params,
|
|
96
|
+
sort,
|
|
97
|
+
where
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const filteredItems = filterUtil.filter({
|
|
101
|
+
items: records,
|
|
102
|
+
where,
|
|
103
|
+
fields: []
|
|
104
|
+
});
|
|
105
|
+
if (!sort || 0 === sort.length) return filteredItems;
|
|
106
|
+
return sortItems({
|
|
107
|
+
items: filteredItems,
|
|
108
|
+
sort
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
create,
|
|
113
|
+
update,
|
|
114
|
+
delete: deleteGroup,
|
|
115
|
+
get,
|
|
116
|
+
list
|
|
117
|
+
};
|
|
190
118
|
};
|
|
119
|
+
export { createGroupsStorageOperations };
|
|
191
120
|
|
|
192
|
-
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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;IAC9B,MAAMS,aAAaD,UAAU,OAAO,CAACE;IAErC,MAAMC,SAAS,OAAOX;QAClB,MAAM,EAAEY,KAAK,EAAE,GAAGZ;QAClB,MAAMa,OAAOT,WAAWQ;QACxB,IAAI;YACA,MAAML,OAAO,GAAG,CAAC;gBACb,MAAMK;gBACN,MAAMP;gBACN,GAAGQ,IAAI;YACX;QACJ,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IACA,MAAMG,SAAS,OAAOhB;QAClB,MAAM,EAAEY,KAAK,EAAE,GAAGZ;QAClB,MAAMa,OAAOT,WAAWQ;QACxB,IAAI;YACA,MAAML,OAAO,GAAG,CAAC;gBACb,MAAMK;gBACN,MAAMP;gBACN,GAAGQ,IAAI;YACX;QACJ,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IACA,MAAMI,cAAc,OAAOjB;QACvB,MAAM,EAAEY,KAAK,EAAE,GAAGZ;QAClB,MAAMa,OAAOT,WAAWQ;QACxB,IAAI;YACA,MAAML,OAAO,MAAM,CAACM;QACxB,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,2BACdA,GAAG,IAAI,IAAI,sBACX;gBACI,OAAOA;gBACPF;gBACAC;YACJ;QAER;IACJ;IACA,MAAMK,MAAM,OAAOlB;QACf,MAAMa,OAAOT,WAAWJ;QAExB,IAAI;YACA,MAAMmB,SAAS,MAAMZ,OAAO,GAAG,CAACM;YAEhC,OAAOM,QAAQ,QAAQ;QAC3B,EAAE,OAAOL,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wBACdA,GAAG,IAAI,IAAI,mBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTa;YACJ;QAER;IACJ;IACA,MAAMO,OAAO,OAAOpB;QAChB,MAAM,EAAEqB,IAAI,EAAEC,KAAK,EAAE,GAAGtB;QAExB,IAAIuB,UAAsB,EAAE;QAC5B,IAAI;YACA,MAAMC,aAAa,MAAMjB,OAAO,QAAQ,CAAC;gBACrC,cAAcR,mBAAmBuB;gBACjC,SAAS;oBACL,KAAK;gBACT;YACJ;YACAC,UAAUC,WAAW,GAAG,CAACC,CAAAA,OAAQA,KAAK,IAAI;QAC9C,EAAE,OAAOX,IAAI;YACT,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,0BACdA,GAAG,IAAI,IAAI,oBACX;gBACI,OAAOA;gBACP,GAAGd,MAAM;gBACTqB;gBACAC;YACJ;QAER;QAEA,MAAMI,gBAAgBjB,WAAW,MAAM,CAAC;YACpC,OAAOc;YACPD;YACA,QAAQ,EAAE;QACd;QACA,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,EACpB,OAAOK;QAGX,OAAOC,UAAU;YACb,OAAOD;YACPL;QACJ;IACJ;IAEA,OAAO;QACHV;QACAK;QACA,QAAQC;QACRC;QACAE;IACJ;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import {
|
|
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:
|
|
4
|
+
entity: IModelEntity;
|
|
5
5
|
}
|
|
6
6
|
export declare const createModelsStorageOperations: (params: CreateModelsStorageOperationsParams) => CmsModelStorageOperations;
|
|
7
7
|
export {};
|
|
@@ -1,162 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
exports.createModelsStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
|
-
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
15
|
-
|
|
16
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
-
|
|
18
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
-
|
|
20
|
-
const createPartitionKey = params => {
|
|
21
|
-
const {
|
|
22
|
-
tenant,
|
|
23
|
-
locale
|
|
24
|
-
} = params;
|
|
25
|
-
|
|
26
|
-
if (!tenant) {
|
|
27
|
-
throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
|
|
28
|
-
} else if (!locale) {
|
|
29
|
-
throw new _error.default(`Missing locale variable when creating model partitionKey.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return `T#${tenant}#L#${locale}#CMS#CM`;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const createSortKey = params => {
|
|
36
|
-
return params.modelId;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const createKeys = params => {
|
|
40
|
-
return {
|
|
41
|
-
PK: createPartitionKey(params),
|
|
42
|
-
SK: createSortKey(params)
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const createType = () => {
|
|
47
|
-
return "cms.model";
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { convertException } from "@webiny/utils";
|
|
3
|
+
const createPartitionKey = (params)=>{
|
|
4
|
+
const { tenant } = params;
|
|
5
|
+
if (!tenant) throw new error("Missing tenant variable when creating model partitionKey.");
|
|
6
|
+
return `T#${tenant}#CMS#CM`;
|
|
48
7
|
};
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
keys
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
8
|
+
const createSortKey = (params)=>params.modelId;
|
|
9
|
+
const createKeys = (params)=>({
|
|
10
|
+
PK: createPartitionKey(params),
|
|
11
|
+
SK: createSortKey(params),
|
|
12
|
+
GSI_TENANT: params.tenant
|
|
13
|
+
});
|
|
14
|
+
const createType = ()=>"cms.model";
|
|
15
|
+
const createModelsStorageOperations = (params)=>{
|
|
16
|
+
const { entity } = params;
|
|
17
|
+
const create = async (params)=>{
|
|
18
|
+
const { model } = params;
|
|
19
|
+
const keys = createKeys(model);
|
|
20
|
+
try {
|
|
21
|
+
await entity.put({
|
|
22
|
+
data: model,
|
|
23
|
+
...keys,
|
|
24
|
+
TYPE: createType()
|
|
25
|
+
});
|
|
26
|
+
return model;
|
|
27
|
+
} catch (ex) {
|
|
28
|
+
throw new error("Could not create CMS Content Model.", "CREATE_MODEL_ERROR", {
|
|
29
|
+
error: convertException(ex),
|
|
30
|
+
model,
|
|
31
|
+
keys
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const update = async (params)=>{
|
|
36
|
+
const { model } = params;
|
|
37
|
+
const keys = createKeys(model);
|
|
38
|
+
try {
|
|
39
|
+
await entity.put({
|
|
40
|
+
data: model,
|
|
41
|
+
...keys,
|
|
42
|
+
TYPE: createType()
|
|
43
|
+
});
|
|
44
|
+
return model;
|
|
45
|
+
} catch (ex) {
|
|
46
|
+
throw new error(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
|
|
47
|
+
error: ex,
|
|
48
|
+
model,
|
|
49
|
+
keys
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const deleteModel = async (params)=>{
|
|
54
|
+
const { model } = params;
|
|
55
|
+
const keys = createKeys(model);
|
|
56
|
+
try {
|
|
57
|
+
await entity.delete(keys);
|
|
58
|
+
} catch (ex) {
|
|
59
|
+
throw new error(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
|
|
60
|
+
error: ex,
|
|
61
|
+
model,
|
|
62
|
+
keys
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const get = async (params)=>{
|
|
67
|
+
const keys = createKeys(params);
|
|
68
|
+
try {
|
|
69
|
+
const result = await entity.get(keys);
|
|
70
|
+
return result?.data || null;
|
|
71
|
+
} catch (ex) {
|
|
72
|
+
throw new error(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
73
|
+
error: ex,
|
|
74
|
+
keys
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const list = async (params)=>{
|
|
79
|
+
const { where } = params;
|
|
80
|
+
const partitionKey = createPartitionKey(where);
|
|
81
|
+
try {
|
|
82
|
+
const result = await entity.queryAll({
|
|
83
|
+
partitionKey,
|
|
84
|
+
options: {
|
|
85
|
+
gte: " "
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return result.map((item)=>item.data);
|
|
89
|
+
} catch (ex) {
|
|
90
|
+
throw new error(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
91
|
+
error: ex,
|
|
92
|
+
partitionKey
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
create,
|
|
98
|
+
update,
|
|
99
|
+
delete: deleteModel,
|
|
100
|
+
get,
|
|
101
|
+
list
|
|
140
102
|
};
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const items = await (0, _query.queryAll)(queryAllParams);
|
|
144
|
-
return (0, _cleanup.cleanupItems)(entity, items);
|
|
145
|
-
} catch (ex) {
|
|
146
|
-
throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
147
|
-
error: ex,
|
|
148
|
-
partitionKey: queryAllParams.partitionKey
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
create,
|
|
155
|
-
update,
|
|
156
|
-
delete: deleteModel,
|
|
157
|
-
get,
|
|
158
|
-
list
|
|
159
|
-
};
|
|
160
103
|
};
|
|
104
|
+
export { createModelsStorageOperations };
|
|
161
105
|
|
|
162
|
-
|
|
106
|
+
//# sourceMappingURL=index.js.map
|