@webiny/api-headless-cms-ddb 5.17.4 → 5.18.0-beta.3
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/definitions/entry.d.ts +6 -4
- package/definitions/entry.js +19 -8
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +8 -0
- package/definitions/model.js +96 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +6 -12
- package/definitions/table.js +15 -15
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -3
- package/dynamoDb/path/plainObject.js +1 -2
- package/dynamoDb/path/ref.js +1 -2
- package/dynamoDb/storage/date.d.ts +2 -2
- package/dynamoDb/storage/date.js +17 -21
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +2 -2
- package/dynamoDb/storage/richText.js +69 -67
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +1 -2
- package/index.d.ts +2 -6
- package/index.js +108 -13
- package/operations/entry/dataLoaders.d.ts +34 -19
- package/operations/entry/dataLoaders.js +158 -138
- package/operations/entry/index.d.ts +8 -4
- package/operations/entry/index.js +812 -16
- package/operations/entry/keys.d.ts +25 -0
- package/operations/entry/keys.js +62 -0
- package/operations/entry/systemFields.d.ts +2 -2
- package/operations/entry/systemFields.js +1 -2
- package/operations/entry/utils.d.ts +13 -9
- package/operations/entry/utils.js +62 -18
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +198 -0
- package/operations/model/index.d.ts +6 -3
- package/operations/model/index.js +153 -18
- package/operations/settings/index.d.ts +6 -3
- package/operations/settings/index.js +132 -16
- package/operations/system/index.d.ts +6 -3
- package/operations/system/index.js +94 -14
- package/package.json +11 -11
- package/types.d.ts +38 -8
- package/types.js +11 -1
- package/configurations.d.ts +0 -18
- package/configurations.js +0 -24
- package/configurations.js.map +0 -1
- package/definitions/entry.js.map +0 -1
- package/definitions/table.js.map +0 -1
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/path/plainObject.js.map +0 -1
- package/dynamoDb/path/ref.js.map +0 -1
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/richText.js.map +0 -1
- package/dynamoDb/transformValue/datetime.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/CmsContentEntryDynamo.d.ts +0 -86
- package/operations/entry/CmsContentEntryDynamo.js +0 -972
- package/operations/entry/CmsContentEntryDynamo.js.map +0 -1
- package/operations/entry/dataLoaders.js.map +0 -1
- package/operations/entry/index.js.map +0 -1
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/entry/utils.js.map +0 -1
- package/operations/helpers.d.ts +0 -5
- package/operations/helpers.js +0 -96
- package/operations/helpers.js.map +0 -1
- package/operations/model/CmsContentModelDynamo.d.ts +0 -18
- package/operations/model/CmsContentModelDynamo.js +0 -234
- package/operations/model/CmsContentModelDynamo.js.map +0 -1
- package/operations/model/index.js.map +0 -1
- package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +0 -42
- package/operations/modelGroup/CmsContentModelGroupDynamo.js +0 -230
- package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +0 -1
- package/operations/modelGroup/index.d.ts +0 -3
- package/operations/modelGroup/index.js +0 -26
- package/operations/modelGroup/index.js.map +0 -1
- package/operations/settings/CmsSettingsDynamo.d.ts +0 -16
- package/operations/settings/CmsSettingsDynamo.js +0 -145
- package/operations/settings/CmsSettingsDynamo.js.map +0 -1
- package/operations/settings/index.js.map +0 -1
- package/operations/system/CmsSystemDynamo.d.ts +0 -16
- package/operations/system/CmsSystemDynamo.js +0 -126
- package/operations/system/CmsSystemDynamo.js.map +0 -1
- package/operations/system/index.js.map +0 -1
- package/types.js.map +0 -1
- package/utils.d.ts +0 -5
- package/utils.js +0 -62
- package/utils.js.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface BasePartitionKeyParams {
|
|
2
|
+
tenant: string;
|
|
3
|
+
locale: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PartitionKeyParams extends BasePartitionKeyParams {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createPartitionKey: (params: PartitionKeyParams) => string;
|
|
9
|
+
export interface SortKeyParams {
|
|
10
|
+
version: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const createRevisionSortKey: (params: SortKeyParams) => string;
|
|
13
|
+
export declare const createLatestSortKey: () => string;
|
|
14
|
+
export declare const createPublishedSortKey: () => string;
|
|
15
|
+
export interface GSIPartitionKeyParams {
|
|
16
|
+
tenant: string;
|
|
17
|
+
locale: string;
|
|
18
|
+
modelId: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const createGSIPartitionKey: (params: GSIPartitionKeyParams, type: "A" | "L" | "P") => string;
|
|
21
|
+
export interface GSISortKeyParams {
|
|
22
|
+
id: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const createGSISortKey: (params: GSISortKeyParams) => string;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRevisionSortKey = exports.createPublishedSortKey = exports.createPartitionKey = exports.createLatestSortKey = exports.createGSISortKey = exports.createGSIPartitionKey = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@webiny/utils");
|
|
9
|
+
|
|
10
|
+
const createBasePartitionKey = params => {
|
|
11
|
+
const {
|
|
12
|
+
tenant,
|
|
13
|
+
locale
|
|
14
|
+
} = params;
|
|
15
|
+
return `T#${tenant}#L#${locale}#CMS#CME`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const createPartitionKey = params => {
|
|
19
|
+
const {
|
|
20
|
+
id: initialId
|
|
21
|
+
} = params;
|
|
22
|
+
const {
|
|
23
|
+
id
|
|
24
|
+
} = (0, _utils.parseIdentifier)(initialId);
|
|
25
|
+
return `${createBasePartitionKey(params)}#CME#${id}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.createPartitionKey = createPartitionKey;
|
|
29
|
+
|
|
30
|
+
const createRevisionSortKey = params => {
|
|
31
|
+
return `REV#${(0, _utils.zeroPad)(params.version)}`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createRevisionSortKey = createRevisionSortKey;
|
|
35
|
+
|
|
36
|
+
const createLatestSortKey = () => {
|
|
37
|
+
return "L";
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.createLatestSortKey = createLatestSortKey;
|
|
41
|
+
|
|
42
|
+
const createPublishedSortKey = () => {
|
|
43
|
+
return "P";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.createPublishedSortKey = createPublishedSortKey;
|
|
47
|
+
|
|
48
|
+
const createGSIPartitionKey = (params, type) => {
|
|
49
|
+
const {
|
|
50
|
+
modelId
|
|
51
|
+
} = params;
|
|
52
|
+
const partitionKey = createBasePartitionKey(params);
|
|
53
|
+
return `${partitionKey}#M#${modelId}#${type}`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.createGSIPartitionKey = createGSIPartitionKey;
|
|
57
|
+
|
|
58
|
+
const createGSISortKey = params => {
|
|
59
|
+
return params.id;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.createGSISortKey = createGSISortKey;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const systemFields: Record<string,
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
export declare const systemFields: Record<string, CmsModelField>;
|
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmsEntry, CmsEntryListWhere, CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { PluginsContainer } from "@webiny/plugins";
|
|
3
3
|
interface ModelField {
|
|
4
|
-
def:
|
|
4
|
+
def: CmsModelField;
|
|
5
5
|
valueTransformer: (value: any) => any;
|
|
6
6
|
valuePath: string;
|
|
7
7
|
isSystemField?: boolean;
|
|
8
8
|
}
|
|
9
9
|
declare type ModelFieldRecords = Record<string, ModelField>;
|
|
10
|
-
interface
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export interface FilterItemFromStorage {
|
|
11
|
+
(field: CmsModelField, value: any): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
interface FilterItemsParams {
|
|
14
|
+
items: CmsEntry[];
|
|
15
|
+
where: CmsEntryListWhere;
|
|
13
16
|
plugins: PluginsContainer;
|
|
14
17
|
fields: ModelFieldRecords;
|
|
18
|
+
fromStorage: FilterItemFromStorage;
|
|
15
19
|
}
|
|
16
|
-
export declare const filterItems: (
|
|
20
|
+
export declare const filterItems: (params: FilterItemsParams) => Promise<CmsEntry[]>;
|
|
17
21
|
interface SortEntryItemsArgs {
|
|
18
|
-
items:
|
|
22
|
+
items: CmsEntry[];
|
|
19
23
|
sort: string[];
|
|
20
24
|
fields: ModelFieldRecords;
|
|
21
25
|
}
|
|
22
|
-
export declare const sortEntryItems: (
|
|
26
|
+
export declare const sortEntryItems: (params: SortEntryItemsArgs) => CmsEntry[];
|
|
23
27
|
export declare const buildModelFields: ({ plugins, model }: {
|
|
24
28
|
plugins: PluginsContainer;
|
|
25
|
-
model:
|
|
29
|
+
model: CmsModel;
|
|
26
30
|
}) => Record<string, ModelField>;
|
|
27
31
|
export {};
|
|
@@ -19,7 +19,7 @@ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueF
|
|
|
19
19
|
|
|
20
20
|
const VALUES_ATTRIBUTE = "values";
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const extractWhereParams = key => {
|
|
23
23
|
const result = key.split("_");
|
|
24
24
|
const fieldId = result.shift();
|
|
25
25
|
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
@@ -52,12 +52,12 @@ const transformValue = (value, transform) => {
|
|
|
52
52
|
return transform(value);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const createFilters =
|
|
55
|
+
const createFilters = params => {
|
|
56
56
|
const {
|
|
57
57
|
where,
|
|
58
58
|
plugins,
|
|
59
59
|
fields
|
|
60
|
-
} =
|
|
60
|
+
} = params;
|
|
61
61
|
const filterPlugins = getMappedPlugins({
|
|
62
62
|
plugins,
|
|
63
63
|
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
@@ -78,7 +78,7 @@ const createFilters = args => {
|
|
|
78
78
|
fieldId,
|
|
79
79
|
operation,
|
|
80
80
|
negate
|
|
81
|
-
} =
|
|
81
|
+
} = extractWhereParams(key);
|
|
82
82
|
const field = fields[fieldId];
|
|
83
83
|
|
|
84
84
|
if (!field) {
|
|
@@ -138,33 +138,78 @@ const createFilters = args => {
|
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
const filterItems =
|
|
141
|
+
const filterItems = async params => {
|
|
142
142
|
const {
|
|
143
143
|
items,
|
|
144
144
|
where,
|
|
145
145
|
plugins,
|
|
146
|
-
fields
|
|
147
|
-
|
|
146
|
+
fields,
|
|
147
|
+
fromStorage
|
|
148
|
+
} = params;
|
|
148
149
|
const filters = createFilters({
|
|
149
150
|
plugins,
|
|
150
151
|
where,
|
|
151
152
|
fields
|
|
152
153
|
});
|
|
153
|
-
|
|
154
|
+
const results = [];
|
|
155
|
+
|
|
156
|
+
for (const key in items) {
|
|
157
|
+
if (items.hasOwnProperty(key) === false) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const item = items[key];
|
|
162
|
+
let passed = true;
|
|
163
|
+
|
|
154
164
|
for (const filter of filters) {
|
|
155
|
-
const
|
|
165
|
+
const rawValue = _dotProp.default.get(item, filter.path);
|
|
166
|
+
|
|
167
|
+
const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);
|
|
168
|
+
/**
|
|
169
|
+
* If raw value is not same as the value after the storage transform, set the value to the items being filtered.
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
if (plainValue !== rawValue) {
|
|
173
|
+
items[key] = _dotProp.default.set(item, filter.path, plainValue);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const value = transformValue(plainValue, filter.transformValue);
|
|
156
177
|
const matched = filter.filterPlugin.matches({
|
|
157
178
|
value,
|
|
158
179
|
compareValue: filter.compareValue
|
|
159
180
|
});
|
|
160
181
|
|
|
161
182
|
if ((filter.negate ? !matched : matched) === false) {
|
|
162
|
-
|
|
183
|
+
passed = false;
|
|
184
|
+
break;
|
|
163
185
|
}
|
|
164
186
|
}
|
|
165
187
|
|
|
166
|
-
|
|
167
|
-
|
|
188
|
+
if (!passed) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
results.push(item);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return results; // return items.filter(item => {
|
|
196
|
+
// for (const filter of filters) {
|
|
197
|
+
// const plainValue = await fromStorage(
|
|
198
|
+
// fields[filter.fieldId].def,
|
|
199
|
+
// dotProp.get(item, filter.path)
|
|
200
|
+
// );
|
|
201
|
+
//
|
|
202
|
+
// const value = transformValue(plainValue, filter.transformValue);
|
|
203
|
+
// const matched = filter.filterPlugin.matches({
|
|
204
|
+
// value,
|
|
205
|
+
// compareValue: filter.compareValue
|
|
206
|
+
// });
|
|
207
|
+
// if ((filter.negate ? !matched : matched) === false) {
|
|
208
|
+
// return false;
|
|
209
|
+
// }
|
|
210
|
+
// }
|
|
211
|
+
// return true;
|
|
212
|
+
// });
|
|
168
213
|
};
|
|
169
214
|
|
|
170
215
|
exports.filterItems = filterItems;
|
|
@@ -196,12 +241,12 @@ const extractSort = (sortBy, fields) => {
|
|
|
196
241
|
};
|
|
197
242
|
};
|
|
198
243
|
|
|
199
|
-
const sortEntryItems =
|
|
244
|
+
const sortEntryItems = params => {
|
|
200
245
|
const {
|
|
201
246
|
items,
|
|
202
247
|
sort = [],
|
|
203
248
|
fields
|
|
204
|
-
} =
|
|
249
|
+
} = params;
|
|
205
250
|
|
|
206
251
|
if (items.length <= 1) {
|
|
207
252
|
return items;
|
|
@@ -257,12 +302,12 @@ const sortEntryItems = args => {
|
|
|
257
302
|
|
|
258
303
|
exports.sortEntryItems = sortEntryItems;
|
|
259
304
|
|
|
260
|
-
const getMappedPlugins =
|
|
305
|
+
const getMappedPlugins = params => {
|
|
261
306
|
const {
|
|
262
307
|
plugins: pluginsContainer,
|
|
263
308
|
type,
|
|
264
309
|
property
|
|
265
|
-
} =
|
|
310
|
+
} = params;
|
|
266
311
|
const plugins = pluginsContainer.byType(type);
|
|
267
312
|
|
|
268
313
|
if (plugins.length === 0) {
|
|
@@ -358,5 +403,4 @@ const buildModelFields = ({
|
|
|
358
403
|
}, fields);
|
|
359
404
|
};
|
|
360
405
|
|
|
361
|
-
exports.buildModelFields = buildModelFields;
|
|
362
|
-
//# sourceMappingURL=utils.js.map
|
|
406
|
+
exports.buildModelFields = buildModelFields;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CmsGroupStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
export interface Params {
|
|
5
|
+
entity: Entity<any>;
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
}
|
|
8
|
+
export declare const createGroupsStorageOperations: (params: Params) => CmsGroupStorageOperations;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createGroupsStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
15
|
+
|
|
16
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
+
|
|
18
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
+
|
|
20
|
+
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
21
|
+
|
|
22
|
+
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
23
|
+
|
|
24
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
29
|
+
|
|
30
|
+
const createPartitionKey = params => {
|
|
31
|
+
const {
|
|
32
|
+
tenant,
|
|
33
|
+
locale
|
|
34
|
+
} = params;
|
|
35
|
+
return `T#${tenant}#L#${locale}#CMS#CMG`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createSortKeys = params => {
|
|
39
|
+
const {
|
|
40
|
+
id
|
|
41
|
+
} = params;
|
|
42
|
+
return id;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createKeys = params => {
|
|
46
|
+
return {
|
|
47
|
+
PK: createPartitionKey(params),
|
|
48
|
+
SK: createSortKeys(params)
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const createType = () => {
|
|
53
|
+
return "cms.group";
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const createGroupsStorageOperations = params => {
|
|
57
|
+
const {
|
|
58
|
+
entity,
|
|
59
|
+
plugins
|
|
60
|
+
} = params;
|
|
61
|
+
const filteringPlugins = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type);
|
|
62
|
+
|
|
63
|
+
if (filteringPlugins.length === 0) {
|
|
64
|
+
throw new _error.default("DynamoDB filtering plugins not loaded.", "MISSING_DYNAMODB_FILTERING_PLUGINS");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const create = async params => {
|
|
68
|
+
const {
|
|
69
|
+
group
|
|
70
|
+
} = params;
|
|
71
|
+
const keys = createKeys(group);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
await entity.put(_objectSpread(_objectSpread({}, group), {}, {
|
|
75
|
+
TYPE: createType()
|
|
76
|
+
}, keys));
|
|
77
|
+
return group;
|
|
78
|
+
} catch (ex) {
|
|
79
|
+
throw new _error.default(ex.message || "Could not create group.", ex.code || "CREATE_GROUP_ERROR", {
|
|
80
|
+
error: ex,
|
|
81
|
+
group,
|
|
82
|
+
keys
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const update = async params => {
|
|
88
|
+
const {
|
|
89
|
+
group,
|
|
90
|
+
original
|
|
91
|
+
} = params;
|
|
92
|
+
const keys = createKeys(group);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
await entity.put(_objectSpread(_objectSpread({}, group), {}, {
|
|
96
|
+
TYPE: createType()
|
|
97
|
+
}, keys));
|
|
98
|
+
return group;
|
|
99
|
+
} catch (ex) {
|
|
100
|
+
throw new _error.default(ex.message || "Could not update group.", ex.code || "UPDATE_GROUP_ERROR", {
|
|
101
|
+
error: ex,
|
|
102
|
+
group,
|
|
103
|
+
original,
|
|
104
|
+
keys
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const deleteGroup = async params => {
|
|
110
|
+
const {
|
|
111
|
+
group
|
|
112
|
+
} = params; // TODO make sure that group has locale and tenant on it - add it in the crud just in case
|
|
113
|
+
|
|
114
|
+
const keys = createKeys(group);
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
await entity.delete(keys);
|
|
118
|
+
return group;
|
|
119
|
+
} catch (ex) {
|
|
120
|
+
throw new _error.default(ex.message || "Could not delete group.", ex.code || "DELETE_GROUP_ERROR", {
|
|
121
|
+
error: ex,
|
|
122
|
+
group,
|
|
123
|
+
keys
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const get = async params => {
|
|
129
|
+
const keys = createKeys(params);
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const group = await (0, _get.get)({
|
|
133
|
+
entity,
|
|
134
|
+
keys
|
|
135
|
+
});
|
|
136
|
+
return (0, _cleanup.cleanupItem)(entity, group);
|
|
137
|
+
} catch (ex) {
|
|
138
|
+
throw new _error.default(ex.message || "Could not get group.", ex.code || "GET_GROUP_ERROR", _objectSpread(_objectSpread({
|
|
139
|
+
error: ex
|
|
140
|
+
}, params), {}, {
|
|
141
|
+
keys
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const list = async params => {
|
|
147
|
+
const {
|
|
148
|
+
sort,
|
|
149
|
+
where
|
|
150
|
+
} = params;
|
|
151
|
+
const queryAllParams = {
|
|
152
|
+
entity,
|
|
153
|
+
partitionKey: createPartitionKey(where),
|
|
154
|
+
options: {
|
|
155
|
+
gte: " "
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
let records = [];
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
records = await (0, _query.queryAll)(queryAllParams);
|
|
162
|
+
} catch (ex) {
|
|
163
|
+
throw new _error.default(ex.message || "Could not list groups.", ex.code || "LIST_GROUP_ERROR", _objectSpread(_objectSpread({
|
|
164
|
+
error: ex
|
|
165
|
+
}, params), {}, {
|
|
166
|
+
sort,
|
|
167
|
+
where
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const filteredItems = (0, _filter.filterItems)({
|
|
172
|
+
items: records,
|
|
173
|
+
where,
|
|
174
|
+
fields: [],
|
|
175
|
+
plugins
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
if (!sort || sort.length === 0) {
|
|
179
|
+
return filteredItems;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return (0, _sort.sortItems)({
|
|
183
|
+
items: filteredItems,
|
|
184
|
+
sort,
|
|
185
|
+
fields: []
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
create,
|
|
191
|
+
update,
|
|
192
|
+
delete: deleteGroup,
|
|
193
|
+
get,
|
|
194
|
+
list
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
exports.createGroupsStorageOperations = createGroupsStorageOperations;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { CmsModelStorageOperations } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
export interface Params {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
}
|
|
6
|
+
export declare const createModelsStorageOperations: (params: Params) => CmsModelStorageOperations;
|
|
@@ -5,22 +5,157 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
8
|
+
exports.createModelsStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
15
|
+
|
|
16
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
+
|
|
18
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
+
|
|
24
|
+
const createPartitionKey = params => {
|
|
25
|
+
const {
|
|
26
|
+
tenant,
|
|
27
|
+
locale
|
|
28
|
+
} = params;
|
|
29
|
+
return `T#${tenant}#L#${locale}#CMS#CM`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createSortKey = params => {
|
|
33
|
+
return params.modelId;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const createKeys = params => {
|
|
37
|
+
return {
|
|
38
|
+
PK: createPartitionKey(params),
|
|
39
|
+
SK: createSortKey(params)
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const createType = () => {
|
|
44
|
+
return "cms.model";
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createModelsStorageOperations = params => {
|
|
48
|
+
const {
|
|
49
|
+
entity
|
|
50
|
+
} = params;
|
|
51
|
+
|
|
52
|
+
const create = async params => {
|
|
53
|
+
const {
|
|
54
|
+
model
|
|
55
|
+
} = params;
|
|
56
|
+
const keys = createKeys(model);
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
|
|
60
|
+
TYPE: createType()
|
|
61
|
+
}));
|
|
62
|
+
return model;
|
|
63
|
+
} catch (ex) {
|
|
64
|
+
throw new _error.default(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
|
|
65
|
+
error: ex,
|
|
66
|
+
model,
|
|
67
|
+
keys
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const update = async params => {
|
|
73
|
+
const {
|
|
74
|
+
original,
|
|
75
|
+
model
|
|
76
|
+
} = params;
|
|
77
|
+
const keys = createKeys(model);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, model), keys), {}, {
|
|
81
|
+
TYPE: createType()
|
|
82
|
+
}));
|
|
83
|
+
return model;
|
|
84
|
+
} catch (ex) {
|
|
85
|
+
throw new _error.default(ex.messatge || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
|
|
86
|
+
error: ex,
|
|
87
|
+
model,
|
|
88
|
+
original,
|
|
89
|
+
keys
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const deleteModel = async params => {
|
|
95
|
+
const {
|
|
96
|
+
model
|
|
97
|
+
} = params;
|
|
98
|
+
const keys = createKeys(model);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await entity.delete(keys);
|
|
102
|
+
return model;
|
|
103
|
+
} catch (ex) {
|
|
104
|
+
throw new _error.default(ex.messatge || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
|
|
105
|
+
error: ex,
|
|
106
|
+
model,
|
|
107
|
+
keys
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const get = async params => {
|
|
113
|
+
const keys = createKeys(params);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const item = await (0, _get.get)({
|
|
117
|
+
entity,
|
|
118
|
+
keys
|
|
119
|
+
});
|
|
120
|
+
return (0, _cleanup.cleanupItem)(entity, item);
|
|
121
|
+
} catch (ex) {
|
|
122
|
+
throw new _error.default(ex.messatge || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
|
|
123
|
+
error: ex,
|
|
124
|
+
keys
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const list = async params => {
|
|
130
|
+
const {
|
|
131
|
+
where
|
|
132
|
+
} = params;
|
|
133
|
+
const queryAllParams = {
|
|
134
|
+
entity,
|
|
135
|
+
partitionKey: createPartitionKey(where),
|
|
136
|
+
options: {
|
|
137
|
+
gte: " "
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const items = await (0, _query.queryAll)(queryAllParams);
|
|
143
|
+
return (0, _cleanup.cleanupItems)(entity, items);
|
|
144
|
+
} catch (ex) {
|
|
145
|
+
throw new _error.default(ex.messatge || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
|
|
146
|
+
error: ex,
|
|
147
|
+
partitionKey: queryAllParams.partitionKey
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
create,
|
|
154
|
+
update,
|
|
155
|
+
delete: deleteModel,
|
|
156
|
+
get,
|
|
157
|
+
list
|
|
158
|
+
};
|
|
159
|
+
};
|
|
23
160
|
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
|
161
|
+
exports.createModelsStorageOperations = createModelsStorageOperations;
|