@webiny/api-headless-cms-ddb 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +25 -0
- package/definitions/entry.d.ts +8 -0
- package/definitions/entry.js +97 -0
- 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 +8 -0
- package/definitions/table.js +30 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +24 -0
- package/dynamoDb/path/plainObject.d.ts +3 -0
- package/dynamoDb/path/plainObject.js +33 -0
- package/dynamoDb/path/ref.d.ts +3 -0
- package/dynamoDb/path/ref.js +27 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +65 -0
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +8 -0
- package/dynamoDb/storage/richText.js +110 -0
- package/dynamoDb/transformValue/datetime.d.ts +3 -0
- package/dynamoDb/transformValue/datetime.js +47 -0
- package/index.d.ts +2 -0
- package/index.js +125 -0
- package/operations/entry/dataLoaders.d.ts +38 -0
- package/operations/entry/dataLoaders.js +303 -0
- package/operations/entry/index.d.ts +8 -0
- package/operations/entry/index.js +823 -0
- package/operations/entry/keys.d.ts +25 -0
- package/operations/entry/keys.js +62 -0
- package/operations/entry/systemFields.d.ts +2 -0
- package/operations/entry/systemFields.js +50 -0
- package/operations/entry/utils.d.ts +31 -0
- package/operations/entry/utils.js +406 -0
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +198 -0
- package/operations/model/index.d.ts +6 -0
- package/operations/model/index.js +161 -0
- package/operations/settings/index.d.ts +6 -0
- package/operations/settings/index.js +141 -0
- package/operations/system/index.d.ts +6 -0
- package/operations/system/index.js +105 -0
- package/package.json +61 -0
- package/types.d.ts +84 -0
- package/types.js +16 -0
|
@@ -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;
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
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
|
+
};
|
|
160
|
+
|
|
161
|
+
exports.createModelsStorageOperations = createModelsStorageOperations;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CmsSettingsStorageOperations } 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 createSettingsStorageOperations: (params: Params) => CmsSettingsStorageOperations;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSettingsStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
const convertToDbData = settings => {
|
|
23
|
+
return _objectSpread(_objectSpread({}, settings), {}, {
|
|
24
|
+
contentModelLastChange: settings.contentModelLastChange.toISOString()
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const convertFromDbData = settings => {
|
|
29
|
+
if (!settings) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let contentModelLastChange;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
contentModelLastChange = new Date(settings.contentModelLastChange);
|
|
37
|
+
} catch {
|
|
38
|
+
contentModelLastChange = new Date();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return _objectSpread(_objectSpread({}, settings), {}, {
|
|
42
|
+
contentModelLastChange
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const createPartitionKey = ({
|
|
47
|
+
tenant,
|
|
48
|
+
locale
|
|
49
|
+
}) => {
|
|
50
|
+
return `T#${tenant}#L#${locale}#CMS#SETTINGS`;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const createSortKey = () => {
|
|
54
|
+
return "settings";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const createKeys = params => {
|
|
58
|
+
return {
|
|
59
|
+
PK: createPartitionKey(params),
|
|
60
|
+
SK: createSortKey()
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const createSettingsStorageOperations = params => {
|
|
65
|
+
const {
|
|
66
|
+
entity
|
|
67
|
+
} = params;
|
|
68
|
+
|
|
69
|
+
const create = async params => {
|
|
70
|
+
const {
|
|
71
|
+
settings
|
|
72
|
+
} = params;
|
|
73
|
+
const keys = createKeys(settings);
|
|
74
|
+
const dbSettings = convertToDbData(settings);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await entity.put(_objectSpread(_objectSpread({}, dbSettings), keys));
|
|
78
|
+
return settings;
|
|
79
|
+
} catch (ex) {
|
|
80
|
+
throw new _error.default(ex.message || "Could not create settings.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
81
|
+
error: ex,
|
|
82
|
+
settings,
|
|
83
|
+
dbSettings,
|
|
84
|
+
keys
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const update = async params => {
|
|
90
|
+
const {
|
|
91
|
+
settings,
|
|
92
|
+
original
|
|
93
|
+
} = params;
|
|
94
|
+
const keys = createKeys(settings);
|
|
95
|
+
const dbSettings = convertToDbData(settings);
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await entity.put(_objectSpread(_objectSpread({}, dbSettings), keys));
|
|
99
|
+
return settings;
|
|
100
|
+
} catch (ex) {
|
|
101
|
+
throw new _error.default(ex.message || "Could not update settings.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
102
|
+
error: ex,
|
|
103
|
+
settings,
|
|
104
|
+
dbSettings,
|
|
105
|
+
original,
|
|
106
|
+
keys
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const get = async params => {
|
|
112
|
+
const keys = createKeys(params);
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const record = await (0, _get.get)({
|
|
116
|
+
entity,
|
|
117
|
+
keys
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!record) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const settings = (0, _cleanup.cleanupItem)(entity, record);
|
|
125
|
+
return convertFromDbData(settings);
|
|
126
|
+
} catch (ex) {
|
|
127
|
+
throw new _error.default(ex.message || "Could not get settings.", ex.code || "GET_SETTINGS_ERROR", {
|
|
128
|
+
error: ex,
|
|
129
|
+
keys
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
create,
|
|
136
|
+
get,
|
|
137
|
+
update
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
exports.createSettingsStorageOperations = createSettingsStorageOperations;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CmsSystemStorageOperations } 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 createSystemStorageOperations: (params: Params) => CmsSystemStorageOperations;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSystemStorageOperations = 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
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
const createPartitionKey = ({
|
|
23
|
+
tenant
|
|
24
|
+
}) => {
|
|
25
|
+
return `T#${tenant.toLowerCase()}#SYSTEM`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const createSortKey = () => {
|
|
29
|
+
return "CMS";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createKeys = params => {
|
|
33
|
+
return {
|
|
34
|
+
PK: createPartitionKey(params),
|
|
35
|
+
SK: createSortKey()
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const createSystemStorageOperations = params => {
|
|
40
|
+
const {
|
|
41
|
+
entity
|
|
42
|
+
} = params;
|
|
43
|
+
|
|
44
|
+
const create = async ({
|
|
45
|
+
system
|
|
46
|
+
}) => {
|
|
47
|
+
const keys = createKeys(system);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
51
|
+
return system;
|
|
52
|
+
} catch (ex) {
|
|
53
|
+
throw new _error.default(ex.message || "Could not create system.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
54
|
+
error: ex,
|
|
55
|
+
system,
|
|
56
|
+
keys
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const update = async params => {
|
|
62
|
+
const {
|
|
63
|
+
system,
|
|
64
|
+
original
|
|
65
|
+
} = params;
|
|
66
|
+
const keys = createKeys(system);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
70
|
+
return system;
|
|
71
|
+
} catch (ex) {
|
|
72
|
+
throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
73
|
+
error: ex,
|
|
74
|
+
system,
|
|
75
|
+
original,
|
|
76
|
+
keys
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const get = async params => {
|
|
82
|
+
const keys = createKeys(params);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const system = await (0, _get.get)({
|
|
86
|
+
entity,
|
|
87
|
+
keys
|
|
88
|
+
});
|
|
89
|
+
return (0, _cleanup.cleanupItem)(entity, system);
|
|
90
|
+
} catch (ex) {
|
|
91
|
+
throw new _error.default(ex.message || "Could not get system.", ex.code || "GET_SYSTEM_ERROR", {
|
|
92
|
+
error: ex,
|
|
93
|
+
keys
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
create,
|
|
100
|
+
update,
|
|
101
|
+
get
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.createSystemStorageOperations = createSystemStorageOperations;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-headless-cms-ddb",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"@webiny/api-headless-cms",
|
|
7
|
+
"storage-operations",
|
|
8
|
+
"dynamodb",
|
|
9
|
+
"cms:ddb"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
14
|
+
"directory": "packages/api-headless-cms-ddb"
|
|
15
|
+
},
|
|
16
|
+
"description": "DynamoDB storage operations plugin for Headless CMS API.",
|
|
17
|
+
"contributors": [
|
|
18
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
19
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
20
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@babel/runtime": "7.15.4",
|
|
25
|
+
"@webiny/api-headless-cms": "0.0.0-mt-1",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-mt-1",
|
|
27
|
+
"@webiny/error": "0.0.0-mt-1",
|
|
28
|
+
"@webiny/handler-db": "0.0.0-mt-1",
|
|
29
|
+
"@webiny/utils": "0.0.0-mt-1",
|
|
30
|
+
"aws-sdk": "2.1026.0",
|
|
31
|
+
"dataloader": "2.0.0",
|
|
32
|
+
"dot-prop": "5.3.0",
|
|
33
|
+
"dynamodb-toolbox": "0.3.4",
|
|
34
|
+
"jsonpack": "1.1.5",
|
|
35
|
+
"lodash.sortby": "4.7.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@babel/cli": "^7.5.5",
|
|
39
|
+
"@babel/core": "^7.5.5",
|
|
40
|
+
"@babel/preset-env": "^7.5.5",
|
|
41
|
+
"@babel/preset-flow": "^7.0.0",
|
|
42
|
+
"@types/jsonpack": "^1.1.0",
|
|
43
|
+
"@webiny/cli": "^0.0.0-mt-1",
|
|
44
|
+
"@webiny/plugins": "^0.0.0-mt-1",
|
|
45
|
+
"@webiny/project-utils": "^0.0.0-mt-1",
|
|
46
|
+
"jest": "^26.6.3",
|
|
47
|
+
"jest-dynalite": "^3.2.0",
|
|
48
|
+
"jest-environment-node": "^26.6.2",
|
|
49
|
+
"ttypescript": "^1.5.12",
|
|
50
|
+
"typescript": "^4.1.3"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
|
+
"directory": "dist"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "yarn webiny run build",
|
|
58
|
+
"watch": "yarn webiny run watch"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
61
|
+
}
|