@webiny/api-form-builder-so-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 +13 -0
- package/definitions/form.d.ts +8 -0
- package/definitions/form.js +110 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +53 -0
- package/definitions/submission.d.ts +8 -0
- package/definitions/submission.js +74 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +44 -0
- package/definitions/table.d.ts +7 -0
- package/definitions/table.js +29 -0
- package/index.d.ts +2 -0
- package/index.js +139 -0
- package/operations/form/fields.d.ts +3 -0
- package/operations/form/fields.js +43 -0
- package/operations/form/index.d.ts +9 -0
- package/operations/form/index.js +745 -0
- package/operations/settings/index.d.ts +7 -0
- package/operations/settings/index.js +122 -0
- package/operations/submission/fields.d.ts +3 -0
- package/operations/submission/fields.js +18 -0
- package/operations/submission/index.d.ts +9 -0
- package/operations/submission/index.js +247 -0
- package/operations/system/index.d.ts +7 -0
- package/operations/system/index.js +105 -0
- package/package.json +56 -0
- package/plugins/FormDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/FormDynamoDbFieldPlugin.js +17 -0
- package/plugins/FormSubmissionDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/FormSubmissionDynamoDbFieldPlugin.js +17 -0
- package/types.d.ts +65 -0
- package/types.js +15 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { FormBuilderSettingsStorageOperations } from "../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
table: Table;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSettingsStorageOperations: (params: Params) => FormBuilderSettingsStorageOperations;
|
|
@@ -0,0 +1,122 @@
|
|
|
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 _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
+
|
|
16
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
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 createSettingsStorageOperations = params => {
|
|
23
|
+
const {
|
|
24
|
+
entity
|
|
25
|
+
} = params;
|
|
26
|
+
|
|
27
|
+
const createSettingsPartitionKey = ({
|
|
28
|
+
tenant,
|
|
29
|
+
locale
|
|
30
|
+
}) => {
|
|
31
|
+
return `T#${tenant}#L#${locale}#FB#SETTINGS`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const createSettingsSortKey = () => {
|
|
35
|
+
return "default";
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createKeys = params => {
|
|
39
|
+
return {
|
|
40
|
+
PK: createSettingsPartitionKey(params),
|
|
41
|
+
SK: createSettingsSortKey()
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createSettings = async params => {
|
|
46
|
+
const {
|
|
47
|
+
settings
|
|
48
|
+
} = params;
|
|
49
|
+
const keys = createKeys(settings);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await entity.put(_objectSpread(_objectSpread({}, settings), keys));
|
|
53
|
+
return settings;
|
|
54
|
+
} catch (ex) {
|
|
55
|
+
throw new _error.default(ex.message || "Could not create the settings record by given keys.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
56
|
+
keys,
|
|
57
|
+
settings
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getSettings = async params => {
|
|
63
|
+
const keys = createKeys(params);
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const item = await (0, _get.get)({
|
|
67
|
+
entity,
|
|
68
|
+
keys
|
|
69
|
+
});
|
|
70
|
+
return (0, _cleanup.cleanupItem)(entity, item);
|
|
71
|
+
} catch (ex) {
|
|
72
|
+
throw new _error.default(ex.message || "Could not get the settings record by given keys.", ex.code || "LOAD_SETTINGS_ERROR", {
|
|
73
|
+
keys
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const updateSettings = async params => {
|
|
79
|
+
const {
|
|
80
|
+
settings,
|
|
81
|
+
original
|
|
82
|
+
} = params;
|
|
83
|
+
const keys = createKeys(settings);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
await entity.put(_objectSpread(_objectSpread({}, settings), keys));
|
|
87
|
+
return settings;
|
|
88
|
+
} catch (ex) {
|
|
89
|
+
throw new _error.default(ex.message || "Could not update the settings record by given keys.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
90
|
+
keys,
|
|
91
|
+
original,
|
|
92
|
+
settings
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const deleteSettings = async params => {
|
|
98
|
+
const {
|
|
99
|
+
settings
|
|
100
|
+
} = params;
|
|
101
|
+
const keys = createKeys(settings);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await entity.delete();
|
|
105
|
+
} catch (ex) {
|
|
106
|
+
throw new _error.default(ex.message || "Could not delete the settings record by given keys.", ex.code || "DELETE_SETTINGS_ERROR", {
|
|
107
|
+
keys
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
createSettings,
|
|
114
|
+
getSettings,
|
|
115
|
+
updateSettings,
|
|
116
|
+
deleteSettings,
|
|
117
|
+
createSettingsPartitionKey,
|
|
118
|
+
createSettingsSortKey
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
exports.createSettingsStorageOperations = createSettingsStorageOperations;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _FormSubmissionDynamoDbFieldPlugin = require("../../plugins/FormSubmissionDynamoDbFieldPlugin");
|
|
9
|
+
|
|
10
|
+
var _default = () => [new _FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynamoDbFieldPlugin({
|
|
11
|
+
field: "createdOn",
|
|
12
|
+
type: "date"
|
|
13
|
+
}), new _FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynamoDbFieldPlugin({
|
|
14
|
+
field: "savedOn",
|
|
15
|
+
type: "date"
|
|
16
|
+
})];
|
|
17
|
+
|
|
18
|
+
exports.default = _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { FormBuilderSubmissionStorageOperations } from "../../types";
|
|
4
|
+
export interface Params {
|
|
5
|
+
entity: Entity<any>;
|
|
6
|
+
table: Table;
|
|
7
|
+
plugins: PluginsContainer;
|
|
8
|
+
}
|
|
9
|
+
export declare const createSubmissionStorageOperations: (params: Params) => FormBuilderSubmissionStorageOperations;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSubmissionStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
+
|
|
16
|
+
var _utils = require("@webiny/utils");
|
|
17
|
+
|
|
18
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
+
|
|
20
|
+
var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
21
|
+
|
|
22
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
23
|
+
|
|
24
|
+
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
25
|
+
|
|
26
|
+
var _FormSubmissionDynamoDbFieldPlugin = require("../../plugins/FormSubmissionDynamoDbFieldPlugin");
|
|
27
|
+
|
|
28
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
const createSubmissionStorageOperations = params => {
|
|
35
|
+
const {
|
|
36
|
+
entity,
|
|
37
|
+
plugins
|
|
38
|
+
} = params;
|
|
39
|
+
|
|
40
|
+
const createSubmissionPartitionKey = params => {
|
|
41
|
+
const {
|
|
42
|
+
tenant,
|
|
43
|
+
locale,
|
|
44
|
+
formId
|
|
45
|
+
} = params;
|
|
46
|
+
const {
|
|
47
|
+
id
|
|
48
|
+
} = (0, _utils.parseIdentifier)(formId);
|
|
49
|
+
return `T#${tenant}#L#${locale}#FB#FS#${id}`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const createSubmissionSortKey = id => {
|
|
53
|
+
return id;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const createSubmissionType = () => {
|
|
57
|
+
return "fb.formSubmission";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const createSubmission = async params => {
|
|
61
|
+
const {
|
|
62
|
+
submission,
|
|
63
|
+
form
|
|
64
|
+
} = params;
|
|
65
|
+
const keys = {
|
|
66
|
+
PK: createSubmissionPartitionKey(form),
|
|
67
|
+
SK: createSubmissionSortKey(submission.id)
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
|
|
72
|
+
TYPE: createSubmissionType()
|
|
73
|
+
}));
|
|
74
|
+
} catch (ex) {
|
|
75
|
+
throw new _error.default(ex.message || "Could not create form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
76
|
+
submission,
|
|
77
|
+
form,
|
|
78
|
+
keys
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return submission;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const updateSubmission = async params => {
|
|
86
|
+
const {
|
|
87
|
+
submission,
|
|
88
|
+
form,
|
|
89
|
+
original
|
|
90
|
+
} = params;
|
|
91
|
+
const keys = {
|
|
92
|
+
PK: createSubmissionPartitionKey(form),
|
|
93
|
+
SK: createSubmissionSortKey(submission.id)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
|
|
98
|
+
TYPE: createSubmissionType()
|
|
99
|
+
}));
|
|
100
|
+
return submission;
|
|
101
|
+
} catch (ex) {
|
|
102
|
+
throw new _error.default(ex.message || "Could not update form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
103
|
+
submission,
|
|
104
|
+
original,
|
|
105
|
+
form,
|
|
106
|
+
keys
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const deleteSubmission = async params => {
|
|
112
|
+
const {
|
|
113
|
+
submission,
|
|
114
|
+
form
|
|
115
|
+
} = params;
|
|
116
|
+
const keys = {
|
|
117
|
+
PK: createSubmissionPartitionKey(form),
|
|
118
|
+
SK: createSubmissionSortKey(submission.id)
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
await entity.delete(keys);
|
|
123
|
+
} catch (ex) {
|
|
124
|
+
throw new _error.default(ex.message || "Could not delete form submission from DynamoDB.", ex.code || "DELETE_FORM_SUBMISSION_ERROR", {
|
|
125
|
+
submission,
|
|
126
|
+
form,
|
|
127
|
+
keys
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return submission;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const listSubmissions = async params => {
|
|
135
|
+
const {
|
|
136
|
+
where: initialWhere,
|
|
137
|
+
sort,
|
|
138
|
+
limit = 100000,
|
|
139
|
+
after
|
|
140
|
+
} = params;
|
|
141
|
+
|
|
142
|
+
const where = _objectSpread({}, initialWhere);
|
|
143
|
+
|
|
144
|
+
const {
|
|
145
|
+
tenant,
|
|
146
|
+
locale,
|
|
147
|
+
formId
|
|
148
|
+
} = where;
|
|
149
|
+
/**
|
|
150
|
+
* We need to remove conditions so we do not filter by them again.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
delete where.tenant;
|
|
154
|
+
delete where.locale;
|
|
155
|
+
delete where.formId;
|
|
156
|
+
const queryAllParams = {
|
|
157
|
+
entity,
|
|
158
|
+
partitionKey: createSubmissionPartitionKey({
|
|
159
|
+
tenant,
|
|
160
|
+
locale,
|
|
161
|
+
formId
|
|
162
|
+
}),
|
|
163
|
+
options: {
|
|
164
|
+
gte: " ",
|
|
165
|
+
reverse: true
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
let results;
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
results = await (0, _query.queryAll)(queryAllParams);
|
|
172
|
+
} catch (ex) {
|
|
173
|
+
throw new _error.default(ex.message || "Could list form submissions.", ex.code || "LIST_SUBMISSIONS_ERROR", {
|
|
174
|
+
where: initialWhere,
|
|
175
|
+
partitionKey: queryAllParams.partitionKey
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const fields = plugins.byType(_FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynamoDbFieldPlugin.type);
|
|
180
|
+
const filteredSubmissions = (0, _filter.filterItems)({
|
|
181
|
+
plugins,
|
|
182
|
+
items: results,
|
|
183
|
+
where,
|
|
184
|
+
fields
|
|
185
|
+
});
|
|
186
|
+
const sortedSubmissions = (0, _sort.sortItems)({
|
|
187
|
+
items: filteredSubmissions,
|
|
188
|
+
sort,
|
|
189
|
+
fields
|
|
190
|
+
});
|
|
191
|
+
const totalCount = sortedSubmissions.length;
|
|
192
|
+
const start = (0, _cursor.decodeCursor)(after) || 0;
|
|
193
|
+
const hasMoreItems = totalCount > start + limit;
|
|
194
|
+
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
195
|
+
const items = sortedSubmissions.slice(start, end);
|
|
196
|
+
/**
|
|
197
|
+
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
198
|
+
* Number is simply encoded.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
const cursor = items.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
|
|
202
|
+
const meta = {
|
|
203
|
+
hasMoreItems,
|
|
204
|
+
totalCount,
|
|
205
|
+
cursor
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
items,
|
|
209
|
+
meta
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const getSubmission = async params => {
|
|
214
|
+
const {
|
|
215
|
+
where
|
|
216
|
+
} = params;
|
|
217
|
+
const keys = {
|
|
218
|
+
PK: createSubmissionPartitionKey(where),
|
|
219
|
+
SK: createSubmissionSortKey(where.id)
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const item = await (0, _get.get)({
|
|
224
|
+
entity,
|
|
225
|
+
keys
|
|
226
|
+
});
|
|
227
|
+
return (0, _cleanup.cleanupItem)(entity, item);
|
|
228
|
+
} catch (ex) {
|
|
229
|
+
throw new _error.default(ex.message || "Could not oad submission.", ex.code || "GET_SUBMISSION_ERROR", {
|
|
230
|
+
where,
|
|
231
|
+
keys
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
createSubmission,
|
|
238
|
+
deleteSubmission,
|
|
239
|
+
updateSubmission,
|
|
240
|
+
listSubmissions,
|
|
241
|
+
getSubmission,
|
|
242
|
+
createSubmissionPartitionKey,
|
|
243
|
+
createSubmissionSortKey
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
table: Table;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSystemStorageOperations: (params: Params) => FormBuilderSystemStorageOperations;
|
|
@@ -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 _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
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 createSystemStorageOperations = params => {
|
|
23
|
+
const {
|
|
24
|
+
entity
|
|
25
|
+
} = params;
|
|
26
|
+
|
|
27
|
+
const createSystemPartitionKey = ({
|
|
28
|
+
tenant
|
|
29
|
+
}) => {
|
|
30
|
+
return `T#${tenant}#SYSTEM`;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const createSystemSortKey = () => {
|
|
34
|
+
return "FB";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const createKeys = params => {
|
|
38
|
+
return {
|
|
39
|
+
PK: createSystemPartitionKey(params),
|
|
40
|
+
SK: createSystemSortKey()
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const createSystem = async params => {
|
|
45
|
+
const {
|
|
46
|
+
system
|
|
47
|
+
} = params;
|
|
48
|
+
const keys = createKeys(system);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
52
|
+
return system;
|
|
53
|
+
} catch (ex) {
|
|
54
|
+
throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
55
|
+
keys,
|
|
56
|
+
system
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getSystem = async params => {
|
|
62
|
+
const keys = createKeys(params);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const item = await (0, _get.get)({
|
|
66
|
+
entity,
|
|
67
|
+
keys
|
|
68
|
+
});
|
|
69
|
+
return (0, _cleanup.cleanupItem)(entity, item);
|
|
70
|
+
} catch (ex) {
|
|
71
|
+
throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", {
|
|
72
|
+
keys
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const updateSystem = async params => {
|
|
78
|
+
const {
|
|
79
|
+
system,
|
|
80
|
+
original
|
|
81
|
+
} = params;
|
|
82
|
+
const keys = createKeys(system);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
86
|
+
return system;
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
89
|
+
keys,
|
|
90
|
+
original,
|
|
91
|
+
system
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
createSystem,
|
|
98
|
+
getSystem,
|
|
99
|
+
updateSystem,
|
|
100
|
+
createSystemPartitionKey,
|
|
101
|
+
createSystemSortKey
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.createSystemStorageOperations = createSystemStorageOperations;
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-form-builder-so-ddb",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"@webiny/api-form-builder",
|
|
7
|
+
"storage-operations",
|
|
8
|
+
"dynamodb",
|
|
9
|
+
"fb:ddb"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
14
|
+
"directory": "packages/api-form-builder-so-ddb"
|
|
15
|
+
},
|
|
16
|
+
"contributors": [
|
|
17
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
18
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
19
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@babel/runtime": "7.15.4",
|
|
24
|
+
"@webiny/api-form-builder": "0.0.0-mt-1",
|
|
25
|
+
"@webiny/db-dynamodb": "0.0.0-mt-1",
|
|
26
|
+
"@webiny/error": "0.0.0-mt-1",
|
|
27
|
+
"@webiny/plugins": "0.0.0-mt-1",
|
|
28
|
+
"@webiny/utils": "0.0.0-mt-1",
|
|
29
|
+
"dynamodb-toolbox": "0.3.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@babel/cli": "^7.5.5",
|
|
33
|
+
"@babel/core": "^7.5.5",
|
|
34
|
+
"@babel/preset-env": "^7.5.5",
|
|
35
|
+
"@babel/preset-typescript": "^7.8.3",
|
|
36
|
+
"@webiny/cli": "^0.0.0-mt-1",
|
|
37
|
+
"@webiny/handler-db": "^0.0.0-mt-1",
|
|
38
|
+
"@webiny/project-utils": "^0.0.0-mt-1",
|
|
39
|
+
"csvtojson": "^2.0.10",
|
|
40
|
+
"jest": "^26.6.3",
|
|
41
|
+
"jest-dynalite": "^3.2.0",
|
|
42
|
+
"jest-environment-node": "^27.2.4",
|
|
43
|
+
"rimraf": "^3.0.2",
|
|
44
|
+
"ttypescript": "^1.5.12",
|
|
45
|
+
"typescript": "^4.1.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"directory": "dist"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "yarn webiny run build",
|
|
53
|
+
"watch": "yarn webiny run watch"
|
|
54
|
+
},
|
|
55
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormDynamoDbFieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
|
|
13
|
+
|
|
14
|
+
class FormDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormDynamoDbFieldPlugin = FormDynamoDbFieldPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.form");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormSubmissionDynamoDbFieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
|
|
13
|
+
|
|
14
|
+
class FormSubmissionDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormSubmissionDynamoDbFieldPlugin = FormSubmissionDynamoDbFieldPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormSubmissionDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.formSubmission");
|