@webiny/api-form-builder-so-ddb 0.0.0-mt-3 → 0.0.0-unstable.085ff6572f
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/form.d.ts +2 -1
- package/definitions/form.js +3 -12
- package/definitions/form.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +3 -12
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.d.ts +2 -1
- package/definitions/submission.js +3 -12
- package/definitions/submission.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +3 -12
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +3 -2
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +35 -43
- package/index.js.map +1 -0
- package/operations/form/fields.js +0 -3
- package/operations/form/fields.js.map +1 -0
- package/operations/form/index.d.ts +2 -2
- package/operations/form/index.js +25 -115
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +5 -28
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/fields.js +0 -3
- package/operations/submission/fields.js.map +1 -0
- package/operations/submission/index.d.ts +2 -2
- package/operations/submission/index.js +7 -45
- package/operations/submission/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +4 -25
- package/operations/system/index.js.map +1 -0
- package/package.json +23 -23
- package/plugins/FormDynamoDbFieldPlugin.js +1 -6
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormSubmissionDynamoDbFieldPlugin.js +1 -6
- package/plugins/FormSubmissionDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +27 -0
- package/plugins/index.js.map +1 -0
- package/types.js +0 -1
- package/types.js.map +1 -0
|
@@ -1,55 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createSettingsStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
-
|
|
16
11
|
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
12
|
const createSettingsStorageOperations = params => {
|
|
23
13
|
const {
|
|
24
14
|
entity
|
|
25
15
|
} = params;
|
|
26
|
-
|
|
27
16
|
const createSettingsPartitionKey = ({
|
|
28
17
|
tenant,
|
|
29
18
|
locale
|
|
30
19
|
}) => {
|
|
31
20
|
return `T#${tenant}#L#${locale}#FB#SETTINGS`;
|
|
32
21
|
};
|
|
33
|
-
|
|
34
22
|
const createSettingsSortKey = () => {
|
|
35
23
|
return "default";
|
|
36
24
|
};
|
|
37
|
-
|
|
38
25
|
const createKeys = params => {
|
|
39
26
|
return {
|
|
40
27
|
PK: createSettingsPartitionKey(params),
|
|
41
28
|
SK: createSettingsSortKey()
|
|
42
29
|
};
|
|
43
30
|
};
|
|
44
|
-
|
|
45
31
|
const createSettings = async params => {
|
|
46
32
|
const {
|
|
47
33
|
settings
|
|
48
34
|
} = params;
|
|
49
35
|
const keys = createKeys(settings);
|
|
50
|
-
|
|
51
36
|
try {
|
|
52
|
-
await entity.put(
|
|
37
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
53
38
|
return settings;
|
|
54
39
|
} catch (ex) {
|
|
55
40
|
throw new _error.default(ex.message || "Could not create the settings record by given keys.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
@@ -58,10 +43,8 @@ const createSettingsStorageOperations = params => {
|
|
|
58
43
|
});
|
|
59
44
|
}
|
|
60
45
|
};
|
|
61
|
-
|
|
62
46
|
const getSettings = async params => {
|
|
63
47
|
const keys = createKeys(params);
|
|
64
|
-
|
|
65
48
|
try {
|
|
66
49
|
const item = await (0, _get.get)({
|
|
67
50
|
entity,
|
|
@@ -74,16 +57,14 @@ const createSettingsStorageOperations = params => {
|
|
|
74
57
|
});
|
|
75
58
|
}
|
|
76
59
|
};
|
|
77
|
-
|
|
78
60
|
const updateSettings = async params => {
|
|
79
61
|
const {
|
|
80
62
|
settings,
|
|
81
63
|
original
|
|
82
64
|
} = params;
|
|
83
65
|
const keys = createKeys(settings);
|
|
84
|
-
|
|
85
66
|
try {
|
|
86
|
-
await entity.put(
|
|
67
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
87
68
|
return settings;
|
|
88
69
|
} catch (ex) {
|
|
89
70
|
throw new _error.default(ex.message || "Could not update the settings record by given keys.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
@@ -93,22 +74,19 @@ const createSettingsStorageOperations = params => {
|
|
|
93
74
|
});
|
|
94
75
|
}
|
|
95
76
|
};
|
|
96
|
-
|
|
97
77
|
const deleteSettings = async params => {
|
|
98
78
|
const {
|
|
99
79
|
settings
|
|
100
80
|
} = params;
|
|
101
81
|
const keys = createKeys(settings);
|
|
102
|
-
|
|
103
82
|
try {
|
|
104
|
-
await entity.delete();
|
|
83
|
+
await entity.delete(keys);
|
|
105
84
|
} catch (ex) {
|
|
106
85
|
throw new _error.default(ex.message || "Could not delete the settings record by given keys.", ex.code || "DELETE_SETTINGS_ERROR", {
|
|
107
86
|
keys
|
|
108
87
|
});
|
|
109
88
|
}
|
|
110
89
|
};
|
|
111
|
-
|
|
112
90
|
return {
|
|
113
91
|
createSettings,
|
|
114
92
|
getSettings,
|
|
@@ -118,5 +96,4 @@ const createSettingsStorageOperations = params => {
|
|
|
118
96
|
createSettingsSortKey
|
|
119
97
|
};
|
|
120
98
|
};
|
|
121
|
-
|
|
122
99
|
exports.createSettingsStorageOperations = createSettingsStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSettingsStorageOperations","params","entity","createSettingsPartitionKey","tenant","locale","createSettingsSortKey","createKeys","PK","SK","createSettings","settings","keys","put","ex","WebinyError","message","code","getSettings","item","get","cleanupItem","updateSettings","original","deleteSettings","delete"],"sources":["index.ts"],"sourcesContent":["import {\n FormBuilderStorageOperationsCreateSettingsParams,\n FormBuilderStorageOperationsDeleteSettingsParams,\n FormBuilderStorageOperationsGetSettingsParams,\n FormBuilderStorageOperationsUpdateSettingsParams,\n Settings\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport {\n FormBuilderSettingsStorageOperations,\n FormBuilderSettingsStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { get } from \"@webiny/db-dynamodb/utils/get\";\n\nexport interface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): FormBuilderSettingsStorageOperations => {\n const { entity } = params;\n\n const createSettingsPartitionKey = ({\n tenant,\n locale\n }: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#FB#SETTINGS`;\n };\n\n const createSettingsSortKey = (): string => {\n return \"default\";\n };\n\n const createKeys = (params: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams) => {\n return {\n PK: createSettingsPartitionKey(params),\n SK: createSettingsSortKey()\n };\n };\n\n const createSettings = async (\n params: FormBuilderStorageOperationsCreateSettingsParams\n ): Promise<Settings> => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the settings record by given keys.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n keys,\n settings\n }\n );\n }\n };\n\n const getSettings = async (\n params: FormBuilderStorageOperationsGetSettingsParams\n ): Promise<Settings | null> => {\n const keys = createKeys(params);\n\n try {\n const item = await get<Settings>({ entity, keys });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get the settings record by given keys.\",\n ex.code || \"LOAD_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSettings = async (\n params: FormBuilderStorageOperationsUpdateSettingsParams\n ): Promise<Settings> => {\n const { settings, original } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the settings record by given keys.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n keys,\n original,\n settings\n }\n );\n }\n };\n\n const deleteSettings = async (\n params: FormBuilderStorageOperationsDeleteSettingsParams\n ): Promise<void> => {\n const { settings } = params;\n const keys = createKeys(settings);\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the settings record by given keys.\",\n ex.code || \"DELETE_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n return {\n createSettings,\n getSettings,\n updateSettings,\n deleteSettings,\n createSettingsPartitionKey,\n createSettingsSortKey\n };\n};\n"],"mappings":";;;;;;;;AAYA;AACA;AACA;AAOO,MAAMA,+BAA+B,GACxCC,MAA6C,IACN;EACvC,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EAEzB,MAAME,0BAA0B,GAAG,CAAC;IAChCC,MAAM;IACNC;EAC0D,CAAC,KAAa;IACxE,OAAQ,KAAID,MAAO,MAAKC,MAAO,cAAa;EAChD,CAAC;EAED,MAAMC,qBAAqB,GAAG,MAAc;IACxC,OAAO,SAAS;EACpB,CAAC;EAED,MAAMC,UAAU,GAAIN,MAAoE,IAAK;IACzF,OAAO;MACHO,EAAE,EAAEL,0BAA0B,CAACF,MAAM,CAAC;MACtCQ,EAAE,EAAEH,qBAAqB;IAC7B,CAAC;EACL,CAAC;EAED,MAAMI,cAAc,GAAG,MACnBT,MAAwD,IACpC;IACpB,MAAM;MAAEU;IAAS,CAAC,GAAGV,MAAM;IAC3B,MAAMW,IAAI,GAAGL,UAAU,CAACI,QAAQ,CAAC;IAEjC,IAAI;MACA,MAAMT,MAAM,CAACW,GAAG,6DACTF,QAAQ,GACRC,IAAI,EACT;MACF,OAAOD,QAAQ;IACnB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,qDAAqD,EACnEF,EAAE,CAACG,IAAI,IAAI,uBAAuB,EAClC;QACIL,IAAI;QACJD;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,MAAMO,WAAW,GAAG,MAChBjB,MAAqD,IAC1B;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CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHF,cAAc;IACdQ,WAAW;IACXI,cAAc;IACdE,cAAc;IACdrB,0BAA0B;IAC1BG;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _FormSubmissionDynamoDbFieldPlugin = require("../../plugins/FormSubmissionDynamoDbFieldPlugin");
|
|
9
|
-
|
|
10
8
|
var _default = () => [new _FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynamoDbFieldPlugin({
|
|
11
9
|
field: "createdOn",
|
|
12
10
|
type: "date"
|
|
@@ -14,5 +12,4 @@ var _default = () => [new _FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynam
|
|
|
14
12
|
field: "savedOn",
|
|
15
13
|
type: "date"
|
|
16
14
|
})];
|
|
17
|
-
|
|
18
15
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormSubmissionDynamoDbFieldPlugin","field","type"],"sources":["fields.ts"],"sourcesContent":["import { FormSubmissionDynamoDbFieldPlugin } from \"~/plugins/FormSubmissionDynamoDbFieldPlugin\";\n\nexport default () => [\n new FormSubmissionDynamoDbFieldPlugin({\n field: \"createdOn\",\n type: \"date\"\n }),\n new FormSubmissionDynamoDbFieldPlugin({\n field: \"savedOn\",\n type: \"date\"\n })\n];\n"],"mappings":";;;;;;AAAA;AAAgG,eAEjF,MAAM,CACjB,IAAIA,oEAAiC,CAAC;EAClCC,KAAK,EAAE,WAAW;EAClBC,IAAI,EAAE;AACV,CAAC,CAAC,EACF,IAAIF,oEAAiC,CAAC;EAClCC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACV,CAAC,CAAC,CACL;AAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
import { PluginsContainer } from "@webiny/plugins";
|
|
3
3
|
import { FormBuilderSubmissionStorageOperations } from "../../types";
|
|
4
|
-
export interface
|
|
4
|
+
export interface CreateSubmissionStorageOperationsParams {
|
|
5
5
|
entity: Entity<any>;
|
|
6
6
|
table: Table;
|
|
7
7
|
plugins: PluginsContainer;
|
|
8
8
|
}
|
|
9
|
-
export declare const createSubmissionStorageOperations: (params:
|
|
9
|
+
export declare const createSubmissionStorageOperations: (params: CreateSubmissionStorageOperationsParams) => FormBuilderSubmissionStorageOperations;
|
|
@@ -1,42 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createSubmissionStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
-
|
|
16
11
|
var _utils = require("@webiny/utils");
|
|
17
|
-
|
|
18
12
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
-
|
|
20
13
|
var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
21
|
-
|
|
22
14
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
23
|
-
|
|
24
15
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
25
|
-
|
|
26
16
|
var _FormSubmissionDynamoDbFieldPlugin = require("../../plugins/FormSubmissionDynamoDbFieldPlugin");
|
|
27
|
-
|
|
28
17
|
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
18
|
const createSubmissionStorageOperations = params => {
|
|
35
19
|
const {
|
|
36
20
|
entity,
|
|
37
21
|
plugins
|
|
38
22
|
} = params;
|
|
39
|
-
|
|
40
23
|
const createSubmissionPartitionKey = params => {
|
|
41
24
|
const {
|
|
42
25
|
tenant,
|
|
@@ -48,15 +31,12 @@ const createSubmissionStorageOperations = params => {
|
|
|
48
31
|
} = (0, _utils.parseIdentifier)(formId);
|
|
49
32
|
return `T#${tenant}#L#${locale}#FB#FS#${id}`;
|
|
50
33
|
};
|
|
51
|
-
|
|
52
34
|
const createSubmissionSortKey = id => {
|
|
53
35
|
return id;
|
|
54
36
|
};
|
|
55
|
-
|
|
56
37
|
const createSubmissionType = () => {
|
|
57
38
|
return "fb.formSubmission";
|
|
58
39
|
};
|
|
59
|
-
|
|
60
40
|
const createSubmission = async params => {
|
|
61
41
|
const {
|
|
62
42
|
submission,
|
|
@@ -66,9 +46,8 @@ const createSubmissionStorageOperations = params => {
|
|
|
66
46
|
PK: createSubmissionPartitionKey(form),
|
|
67
47
|
SK: createSubmissionSortKey(submission.id)
|
|
68
48
|
};
|
|
69
|
-
|
|
70
49
|
try {
|
|
71
|
-
await entity.put(
|
|
50
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
|
|
72
51
|
TYPE: createSubmissionType()
|
|
73
52
|
}));
|
|
74
53
|
} catch (ex) {
|
|
@@ -78,10 +57,8 @@ const createSubmissionStorageOperations = params => {
|
|
|
78
57
|
keys
|
|
79
58
|
});
|
|
80
59
|
}
|
|
81
|
-
|
|
82
60
|
return submission;
|
|
83
61
|
};
|
|
84
|
-
|
|
85
62
|
const updateSubmission = async params => {
|
|
86
63
|
const {
|
|
87
64
|
submission,
|
|
@@ -92,9 +69,8 @@ const createSubmissionStorageOperations = params => {
|
|
|
92
69
|
PK: createSubmissionPartitionKey(form),
|
|
93
70
|
SK: createSubmissionSortKey(submission.id)
|
|
94
71
|
};
|
|
95
|
-
|
|
96
72
|
try {
|
|
97
|
-
await entity.put(
|
|
73
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
|
|
98
74
|
TYPE: createSubmissionType()
|
|
99
75
|
}));
|
|
100
76
|
return submission;
|
|
@@ -107,7 +83,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
107
83
|
});
|
|
108
84
|
}
|
|
109
85
|
};
|
|
110
|
-
|
|
111
86
|
const deleteSubmission = async params => {
|
|
112
87
|
const {
|
|
113
88
|
submission,
|
|
@@ -117,7 +92,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
117
92
|
PK: createSubmissionPartitionKey(form),
|
|
118
93
|
SK: createSubmissionSortKey(submission.id)
|
|
119
94
|
};
|
|
120
|
-
|
|
121
95
|
try {
|
|
122
96
|
await entity.delete(keys);
|
|
123
97
|
} catch (ex) {
|
|
@@ -127,10 +101,8 @@ const createSubmissionStorageOperations = params => {
|
|
|
127
101
|
keys
|
|
128
102
|
});
|
|
129
103
|
}
|
|
130
|
-
|
|
131
104
|
return submission;
|
|
132
105
|
};
|
|
133
|
-
|
|
134
106
|
const listSubmissions = async params => {
|
|
135
107
|
const {
|
|
136
108
|
where: initialWhere,
|
|
@@ -138,18 +110,15 @@ const createSubmissionStorageOperations = params => {
|
|
|
138
110
|
limit = 100000,
|
|
139
111
|
after
|
|
140
112
|
} = params;
|
|
141
|
-
|
|
142
|
-
const where = _objectSpread({}, initialWhere);
|
|
143
|
-
|
|
144
113
|
const {
|
|
145
114
|
tenant,
|
|
146
115
|
locale,
|
|
147
116
|
formId
|
|
148
|
-
} =
|
|
117
|
+
} = initialWhere;
|
|
118
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
149
119
|
/**
|
|
150
120
|
* We need to remove conditions so we do not filter by them again.
|
|
151
121
|
*/
|
|
152
|
-
|
|
153
122
|
delete where.tenant;
|
|
154
123
|
delete where.locale;
|
|
155
124
|
delete where.formId;
|
|
@@ -166,7 +135,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
166
135
|
}
|
|
167
136
|
};
|
|
168
137
|
let results;
|
|
169
|
-
|
|
170
138
|
try {
|
|
171
139
|
results = await (0, _query.queryAll)(queryAllParams);
|
|
172
140
|
} catch (ex) {
|
|
@@ -175,7 +143,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
175
143
|
partitionKey: queryAllParams.partitionKey
|
|
176
144
|
});
|
|
177
145
|
}
|
|
178
|
-
|
|
179
146
|
const fields = plugins.byType(_FormSubmissionDynamoDbFieldPlugin.FormSubmissionDynamoDbFieldPlugin.type);
|
|
180
147
|
const filteredSubmissions = (0, _filter.filterItems)({
|
|
181
148
|
plugins,
|
|
@@ -189,7 +156,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
189
156
|
fields
|
|
190
157
|
});
|
|
191
158
|
const totalCount = sortedSubmissions.length;
|
|
192
|
-
const start = (0, _cursor.decodeCursor)(after) || 0;
|
|
159
|
+
const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
|
|
193
160
|
const hasMoreItems = totalCount > start + limit;
|
|
194
161
|
const end = limit > totalCount + start + limit ? undefined : start + limit;
|
|
195
162
|
const items = sortedSubmissions.slice(start, end);
|
|
@@ -197,7 +164,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
197
164
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
198
165
|
* Number is simply encoded.
|
|
199
166
|
*/
|
|
200
|
-
|
|
201
167
|
const cursor = items.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
|
|
202
168
|
const meta = {
|
|
203
169
|
hasMoreItems,
|
|
@@ -209,7 +175,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
209
175
|
meta
|
|
210
176
|
};
|
|
211
177
|
};
|
|
212
|
-
|
|
213
178
|
const getSubmission = async params => {
|
|
214
179
|
const {
|
|
215
180
|
where
|
|
@@ -218,7 +183,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
218
183
|
PK: createSubmissionPartitionKey(where),
|
|
219
184
|
SK: createSubmissionSortKey(where.id)
|
|
220
185
|
};
|
|
221
|
-
|
|
222
186
|
try {
|
|
223
187
|
const item = await (0, _get.get)({
|
|
224
188
|
entity,
|
|
@@ -232,7 +196,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
232
196
|
});
|
|
233
197
|
}
|
|
234
198
|
};
|
|
235
|
-
|
|
236
199
|
return {
|
|
237
200
|
createSubmission,
|
|
238
201
|
deleteSubmission,
|
|
@@ -243,5 +206,4 @@ const createSubmissionStorageOperations = params => {
|
|
|
243
206
|
createSubmissionSortKey
|
|
244
207
|
};
|
|
245
208
|
};
|
|
246
|
-
|
|
247
209
|
exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSubmissionStorageOperations","params","entity","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","parseIdentifier","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","TYPE","ex","WebinyError","message","code","updateSubmission","original","deleteSubmission","delete","listSubmissions","where","initialWhere","sort","limit","after","queryAllParams","partitionKey","options","gte","reverse","results","queryAll","fields","byType","FormSubmissionDynamoDbFieldPlugin","type","filteredSubmissions","filterItems","items","sortedSubmissions","sortItems","totalCount","length","start","parseInt","decodeCursor","hasMoreItems","end","undefined","slice","cursor","encodeCursor","meta","getSubmission","item","get","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n FbSubmission,\n FormBuilderStorageOperationsCreateSubmissionParams,\n FormBuilderStorageOperationsDeleteSubmissionParams,\n FormBuilderStorageOperationsGetSubmissionParams,\n FormBuilderStorageOperationsListSubmissionsParams,\n FormBuilderStorageOperationsListSubmissionsResponse,\n FormBuilderStorageOperationsUpdateSubmissionParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n FormBuilderSubmissionStorageOperations,\n FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { FormSubmissionDynamoDbFieldPlugin } from \"~/plugins/FormSubmissionDynamoDbFieldPlugin\";\nimport { get } from \"@webiny/db-dynamodb/utils/get\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n plugins: PluginsContainer;\n}\n\nexport const createSubmissionStorageOperations = (\n params: CreateSubmissionStorageOperationsParams\n): FormBuilderSubmissionStorageOperations => {\n const { entity, plugins } = params;\n\n const createSubmissionPartitionKey = (\n params: FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n ) => {\n const { tenant, locale, formId } = params;\n\n const { id } = parseIdentifier(formId);\n\n return `T#${tenant}#L#${locale}#FB#FS#${id}`;\n };\n const createSubmissionSortKey = (id: string) => {\n return id;\n };\n\n const createSubmissionType = () => {\n return \"fb.formSubmission\";\n };\n\n const createSubmission = async (\n params: FormBuilderStorageOperationsCreateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n\n const updateSubmission = async (\n params: FormBuilderStorageOperationsUpdateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form, original } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n });\n return submission;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n original,\n form,\n keys\n }\n );\n }\n };\n\n const deleteSubmission = async (\n params: FormBuilderStorageOperationsDeleteSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from DynamoDB.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n\n const listSubmissions = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FormBuilderStorageOperationsListSubmissionsResponse> => {\n const { where: initialWhere, sort, limit = 100000, after } = params;\n\n const { tenant, locale, formId } = initialWhere;\n\n const where: Partial<FormBuilderStorageOperationsListSubmissionsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * We need to remove conditions so we do not filter by them again.\n */\n delete where.tenant;\n delete where.locale;\n delete where.formId;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createSubmissionPartitionKey({\n tenant,\n locale,\n formId\n }),\n options: {\n gte: \" \",\n reverse: true\n }\n };\n\n let results;\n try {\n results = await queryAll<FbSubmission>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list form submissions.\",\n ex.code || \"LIST_SUBMISSIONS_ERROR\",\n {\n where: initialWhere,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n\n const fields = plugins.byType<FormSubmissionDynamoDbFieldPlugin>(\n FormSubmissionDynamoDbFieldPlugin.type\n );\n\n const filteredSubmissions = filterItems({\n plugins,\n items: results,\n where,\n fields\n });\n\n const sortedSubmissions = sortItems({\n items: filteredSubmissions,\n sort,\n fields\n });\n\n const totalCount = sortedSubmissions.length;\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const items = sortedSubmissions.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = items.length > 0 ? encodeCursor(start + limit) : null;\n\n const meta = {\n hasMoreItems,\n totalCount,\n cursor\n };\n\n return {\n items,\n meta\n };\n };\n\n const getSubmission = async (\n params: FormBuilderStorageOperationsGetSubmissionParams\n ): Promise<FbSubmission | null> => {\n const { where } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey(where),\n SK: createSubmissionSortKey(where.id)\n };\n\n try {\n const item = await get<FbSubmission>({ entity, keys });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not oad submission.\",\n ex.code || \"GET_SUBMISSION_ERROR\",\n {\n where,\n keys\n }\n );\n }\n };\n\n return {\n createSubmission,\n deleteSubmission,\n updateSubmission,\n listSubmissions,\n getSubmission,\n createSubmissionPartitionKey,\n createSubmissionSortKey\n };\n};\n"],"mappings":";;;;;;;;AAUA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAQO,MAAMA,iCAAiC,GAC1CC,MAA+C,IACN;EACzC,MAAM;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAElC,MAAMG,4BAA4B,GAC9BH,MAAsE,IACrE;IACD,MAAM;MAAEI,MAAM;MAAEC,MAAM;MAAEC;IAAO,CAAC,GAAGN,MAAM;IAEzC,MAAM;MAAEO;IAAG,CAAC,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;IAEtC,OAAQ,KAAIF,MAAO,MAAKC,MAAO,UAASE,EAAG,EAAC;EAChD,CAAC;EACD,MAAME,uBAAuB,GAAIF,EAAU,IAAK;IAC5C,OAAOA,EAAE;EACb,CAAC;EAED,MAAMG,oBAAoB,GAAG,MAAM;IAC/B,OAAO,mBAAmB;EAC9B,CAAC;EAED,MAAMC,gBAAgB,GAAG,MACrBX,MAA0D,IAClC;IACxB,MAAM;MAAEY,UAAU;MAAEC;IAAK,CAAC,GAAGb,MAAM;IACnC,MAAMc,IAAI,GAAG;MACTC,EAAE,EAAEZ,4BAA4B,CAACU,IAAI,CAAC;MACtCG,EAAE,EAAEP,uBAAuB,CAACG,UAAU,CAACL,EAAE;IAC7C,CAAC;IAED,IAAI;MACA,MAAMN,MAAM,CAACgB,GAAG,yFACTL,UAAU,GACVE,IAAI;QACPI,IAAI,EAAER,oBAAoB;MAAE,GAC9B;IACN,CAAC,CAAC,OAAOS,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,mDAAmD,EACjEF,EAAE,CAACG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AAI,sBAAsB,EACjC;QACIM,KAAK;QACLd;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHH,gBAAgB;IAChBc,gBAAgB;IAChBF,gBAAgB;IAChBI,eAAe;IACfkC,aAAa;IACb1D,4BAA4B;IAC5BM;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface CreateSystemStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
table: Table;
|
|
6
6
|
}
|
|
7
|
-
export declare const createSystemStorageOperations: (params:
|
|
7
|
+
export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => FormBuilderSystemStorageOperations;
|
|
@@ -1,54 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createSystemStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
13
|
-
|
|
14
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
11
|
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
12
|
const createSystemStorageOperations = params => {
|
|
23
13
|
const {
|
|
24
14
|
entity
|
|
25
15
|
} = params;
|
|
26
|
-
|
|
27
16
|
const createSystemPartitionKey = ({
|
|
28
17
|
tenant
|
|
29
18
|
}) => {
|
|
30
19
|
return `T#${tenant}#SYSTEM`;
|
|
31
20
|
};
|
|
32
|
-
|
|
33
21
|
const createSystemSortKey = () => {
|
|
34
22
|
return "FB";
|
|
35
23
|
};
|
|
36
|
-
|
|
37
24
|
const createKeys = params => {
|
|
38
25
|
return {
|
|
39
26
|
PK: createSystemPartitionKey(params),
|
|
40
27
|
SK: createSystemSortKey()
|
|
41
28
|
};
|
|
42
29
|
};
|
|
43
|
-
|
|
44
30
|
const createSystem = async params => {
|
|
45
31
|
const {
|
|
46
32
|
system
|
|
47
33
|
} = params;
|
|
48
34
|
const keys = createKeys(system);
|
|
49
|
-
|
|
50
35
|
try {
|
|
51
|
-
await entity.put(
|
|
36
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
|
|
52
37
|
return system;
|
|
53
38
|
} catch (ex) {
|
|
54
39
|
throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
@@ -57,10 +42,8 @@ const createSystemStorageOperations = params => {
|
|
|
57
42
|
});
|
|
58
43
|
}
|
|
59
44
|
};
|
|
60
|
-
|
|
61
45
|
const getSystem = async params => {
|
|
62
46
|
const keys = createKeys(params);
|
|
63
|
-
|
|
64
47
|
try {
|
|
65
48
|
const item = await (0, _get.get)({
|
|
66
49
|
entity,
|
|
@@ -73,16 +56,14 @@ const createSystemStorageOperations = params => {
|
|
|
73
56
|
});
|
|
74
57
|
}
|
|
75
58
|
};
|
|
76
|
-
|
|
77
59
|
const updateSystem = async params => {
|
|
78
60
|
const {
|
|
79
61
|
system,
|
|
80
62
|
original
|
|
81
63
|
} = params;
|
|
82
64
|
const keys = createKeys(system);
|
|
83
|
-
|
|
84
65
|
try {
|
|
85
|
-
await entity.put(
|
|
66
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
|
|
86
67
|
return system;
|
|
87
68
|
} catch (ex) {
|
|
88
69
|
throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
@@ -92,7 +73,6 @@ const createSystemStorageOperations = params => {
|
|
|
92
73
|
});
|
|
93
74
|
}
|
|
94
75
|
};
|
|
95
|
-
|
|
96
76
|
return {
|
|
97
77
|
createSystem,
|
|
98
78
|
getSystem,
|
|
@@ -101,5 +81,4 @@ const createSystemStorageOperations = params => {
|
|
|
101
81
|
createSystemSortKey
|
|
102
82
|
};
|
|
103
83
|
};
|
|
104
|
-
|
|
105
84
|
exports.createSystemStorageOperations = createSystemStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","ex","WebinyError","message","code","getSystem","item","get","cleanupItem","updateSystem","original"],"sources":["index.ts"],"sourcesContent":["import {\n FormBuilderStorageOperationsCreateSystemParams,\n FormBuilderStorageOperationsGetSystemParams,\n FormBuilderStorageOperationsUpdateSystemParams,\n System\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { FormBuilderSystemCreateKeysParams, FormBuilderSystemStorageOperations } from \"~/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport WebinyError from \"@webiny/error\";\nimport { get } from \"@webiny/db-dynamodb/utils/get\";\n\nexport interface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n}\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): FormBuilderSystemStorageOperations => {\n const { entity } = params;\n\n const createSystemPartitionKey = ({ tenant }: FormBuilderSystemCreateKeysParams): string => {\n return `T#${tenant}#SYSTEM`;\n };\n\n const createSystemSortKey = (): string => {\n return \"FB\";\n };\n\n const createKeys = (params: FormBuilderSystemCreateKeysParams) => {\n return {\n PK: createSystemPartitionKey(params),\n SK: createSystemSortKey()\n };\n };\n\n const createSystem = async (\n params: FormBuilderStorageOperationsCreateSystemParams\n ): Promise<System> => {\n const { system } = params;\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the system record by given keys.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n keys,\n system\n }\n );\n }\n };\n\n const getSystem = async (\n params: FormBuilderStorageOperationsGetSystemParams\n ): Promise<System | null> => {\n const keys = createKeys(params);\n\n try {\n const item = await get<System>({ entity, keys });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get the system record by given keys.\",\n ex.code || \"LOAD_SYSTEM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSystem = async (\n params: FormBuilderStorageOperationsUpdateSystemParams\n ): Promise<System> => {\n const { system, original } = params;\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the system record by given keys.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n keys,\n original,\n system\n }\n );\n }\n };\n\n return {\n createSystem,\n getSystem,\n updateSystem,\n createSystemPartitionKey,\n createSystemSortKey\n };\n};\n"],"mappings":";;;;;;;;AAQA;AACA;AACA;AAOO,MAAMA,6BAA6B,GACtCC,MAA2C,IACN;EACrC,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EAEzB,MAAME,wBAAwB,GAAG,CAAC;IAAEC;EAA0C,CAAC,KAAa;IACxF,OAAQ,KAAIA,MAAO,SAAQ;EAC/B,CAAC;EAED,MAAMC,mBAAmB,GAAG,MAAc;IACtC,OAAO,IAAI;EACf,CAAC;EAED,MAAMC,UAAU,GAAIL,MAAyC,IAAK;IAC9D,OAAO;MACHM,EAAE,EAAEJ,wBAAwB,CAACF,MAAM,CAAC;MACpCO,EAAE,EAAEH,mBAAmB;IAC3B,CAAC;EACL,CAAC;EAED,MAAMI,YAAY,GAAG,MACjBR,MAAsD,IACpC;IAClB,MAAM;MAAES;IAAO,CAAC,GAAGT,MAAM;IACzB,MAAMU,IAAI,GAAGL,UAAU,CAACI,MAAM,CAAC;IAE/B,IAAI;MACA,MAAMR,MAAM,CAACU,GAAG,6DACTF,MAAM,GACNC,IAAI,EACT;MACF,OAAOD,MAAM;IACjB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,mDAAmD,EACjEF,EAAE,CAACG,IAAI,IAAI,qBAAqB,EAChC;QACIL,IAAI;QACJD;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,MAAMO,SAAS,GAAG,MACdhB,MAAmD,IAC1B;IACzB,MAAMU,IAAI,GAAGL,UAAU,CAACL,MAAM,CAAC;IAE/B,IAAI;MACA,MAAMiB,IAAI,GAAG,MAAM,IAAAC,QAAG,EAAS;QAAEjB,MAAM;QAAES;MAAK,CAAC,CAAC;MAChD,OAAO,IAAAS,oBAAW,EAAClB,MAAM,EAAEgB,IAAI,CAAC;IACpC,CAAC,CAAC,OAAOL,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,gDAAgD,EAC9DF,EAAE,CAACG,IAAI,IAAI,mBAAmB,EAC9B;QACIL;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,MAAMU,YAAY,GAAG,MACjBpB,MAAsD,IACpC;IAClB,MAAM;MAAES,MAAM;MAAEY;IAAS,CAAC,GAAGrB,MAAM;IACnC,MAAMU,IAAI,GAAGL,UAAU,CAACI,MAAM,CAAC;IAE/B,IAAI;MACA,MAAMR,MAAM,CAACU,GAAG,6DACTF,MAAM,GACNC,IAAI,EACT;MACF,OAAOD,MAAM;IACjB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,mDAAmD,EACjEF,EAAE,CAACG,IAAI,IAAI,qBAAqB,EAChC;QACIL,IAAI;QACJW,QAAQ;QACRZ;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHD,YAAY;IACZQ,SAAS;IACTI,YAAY;IACZlB,wBAAwB;IACxBE;EACJ,CAAC;AACL,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-form-builder-so-ddb",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.085ff6572f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-form-builder",
|
|
7
7
|
"storage-operations",
|
|
8
8
|
"dynamodb",
|
|
9
|
+
"ddb",
|
|
9
10
|
"fb:ddb"
|
|
10
11
|
],
|
|
11
12
|
"repository": {
|
|
@@ -20,29 +21,28 @@
|
|
|
20
21
|
],
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@babel/runtime": "7.
|
|
24
|
-
"@webiny/api-form-builder": "0.0.0-
|
|
25
|
-
"@webiny/db-dynamodb": "0.0.0-
|
|
26
|
-
"@webiny/error": "0.0.0-
|
|
27
|
-
"@webiny/plugins": "0.0.0-
|
|
28
|
-
"@webiny/utils": "0.0.0-
|
|
29
|
-
"dynamodb-toolbox": "0.3.
|
|
24
|
+
"@babel/runtime": "7.20.13",
|
|
25
|
+
"@webiny/api-form-builder": "0.0.0-unstable.085ff6572f",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.085ff6572f",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.085ff6572f",
|
|
28
|
+
"@webiny/plugins": "0.0.0-unstable.085ff6572f",
|
|
29
|
+
"@webiny/utils": "0.0.0-unstable.085ff6572f",
|
|
30
|
+
"dynamodb-toolbox": "0.3.5"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@babel/cli": "
|
|
33
|
-
"@babel/core": "
|
|
34
|
-
"@babel/preset-env": "
|
|
35
|
-
"@babel/preset-typescript": "
|
|
36
|
-
"@webiny/cli": "
|
|
37
|
-
"@webiny/handler-db": "
|
|
38
|
-
"@webiny/project-utils": "
|
|
39
|
-
"csvtojson": "
|
|
40
|
-
"jest": "
|
|
41
|
-
"jest-dynalite": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"typescript": "^4.1.3"
|
|
33
|
+
"@babel/cli": "7.20.7",
|
|
34
|
+
"@babel/core": "7.20.12",
|
|
35
|
+
"@babel/preset-env": "7.20.2",
|
|
36
|
+
"@babel/preset-typescript": "7.18.6",
|
|
37
|
+
"@webiny/cli": "0.0.0-unstable.085ff6572f",
|
|
38
|
+
"@webiny/handler-db": "0.0.0-unstable.085ff6572f",
|
|
39
|
+
"@webiny/project-utils": "0.0.0-unstable.085ff6572f",
|
|
40
|
+
"csvtojson": "2.0.10",
|
|
41
|
+
"jest": "29.5.0",
|
|
42
|
+
"jest-dynalite": "3.6.1",
|
|
43
|
+
"rimraf": "3.0.2",
|
|
44
|
+
"ttypescript": "1.5.15",
|
|
45
|
+
"typescript": "4.7.4"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"build": "yarn webiny run build",
|
|
53
53
|
"watch": "yarn webiny run watch"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
|
|
56
56
|
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.FormDynamoDbFieldPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
|
|
13
|
-
|
|
14
10
|
class FormDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
|
|
15
|
-
|
|
16
11
|
exports.FormDynamoDbFieldPlugin = FormDynamoDbFieldPlugin;
|
|
17
12
|
(0, _defineProperty2.default)(FormDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.form");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormDynamoDbFieldPlugin","FieldPlugin"],"sources":["FormDynamoDbFieldPlugin.ts"],"sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.form\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,uBAAuB,SAASC,wBAAW,CAAC;AAExD;AAAA,8BAFYD,uBAAuB,UACe,iCAAiC"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.FormSubmissionDynamoDbFieldPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
|
|
13
|
-
|
|
14
10
|
class FormSubmissionDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
|
|
15
|
-
|
|
16
11
|
exports.FormSubmissionDynamoDbFieldPlugin = FormSubmissionDynamoDbFieldPlugin;
|
|
17
12
|
(0, _defineProperty2.default)(FormSubmissionDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.formSubmission");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormSubmissionDynamoDbFieldPlugin","FieldPlugin"],"sources":["FormSubmissionDynamoDbFieldPlugin.ts"],"sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormSubmissionDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.formSubmission\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,iCAAiC,SAASC,wBAAW,CAAC;AAElE;AAAA,8BAFYD,iCAAiC,UACK,2CAA2C"}
|