@webiny/api-form-builder-so-ddb 5.33.5 → 5.34.0-beta.0
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.js +3 -7
- package/definitions/form.js.map +1 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -1
- package/definitions/submission.js +3 -7
- package/definitions/submission.js.map +1 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -1
- package/index.js +3 -7
- package/index.js.map +1 -1
- package/operations/form/index.js +18 -25
- package/operations/form/index.js.map +1 -1
- package/operations/settings/index.js +4 -8
- package/operations/settings/index.js.map +1 -1
- package/operations/submission/index.js +5 -11
- package/operations/submission/index.js.map +1 -1
- package/operations/system/index.js +4 -8
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -15
- package/plugins/FormDynamoDbFieldPlugin.js +1 -1
- package/plugins/FormSubmissionDynamoDbFieldPlugin.js +1 -1
package/definitions/form.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createFormEntity = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
const createFormEntity = params => {
|
|
19
15
|
const {
|
|
20
16
|
table,
|
|
@@ -24,7 +20,7 @@ const createFormEntity = params => {
|
|
|
24
20
|
return new _dynamodbToolbox.Entity({
|
|
25
21
|
table,
|
|
26
22
|
name: entityName,
|
|
27
|
-
attributes:
|
|
23
|
+
attributes: (0, _objectSpread2.default)({
|
|
28
24
|
PK: {
|
|
29
25
|
partitionKey: true
|
|
30
26
|
},
|
package/definitions/form.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFormEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","id","formId","tenant","locale","createdBy","ownedBy","savedOn","createdOn","slug","version","locked","published","publishedOn","status","fields","layout","stats","settings","triggers","webinyVersion"],"sources":["form.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createFormEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n formId: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n savedOn: {\n type: \"string\"\n },\n createdOn: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n slug: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n published: {\n type: \"boolean\"\n },\n publishedOn: {\n type: \"string\"\n },\n status: {\n type: \"string\"\n },\n fields: {\n type: \"list\"\n },\n layout: {\n type: \"list\"\n },\n stats: {\n type: \"map\"\n },\n settings: {\n type: \"map\"\n },\n triggers: {\n type: \"map\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"names":["createFormEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","id","formId","tenant","locale","createdBy","ownedBy","savedOn","createdOn","slug","version","locked","published","publishedOn","status","fields","layout","stats","settings","triggers","webinyVersion"],"sources":["form.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createFormEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n formId: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n ownedBy: {\n type: \"map\"\n },\n savedOn: {\n type: \"string\"\n },\n createdOn: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n slug: {\n type: \"string\"\n },\n version: {\n type: \"number\"\n },\n locked: {\n type: \"boolean\"\n },\n published: {\n type: \"boolean\"\n },\n publishedOn: {\n type: \"string\"\n },\n status: {\n type: \"string\"\n },\n fields: {\n type: \"list\"\n },\n layout: {\n type: \"list\"\n },\n stats: {\n type: \"map\"\n },\n settings: {\n type: \"map\"\n },\n triggers: {\n type: \"map\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,gBAAgB,GAAIC,MAAD,IAAiC;EAC7D,MAAM;IAAEC,KAAF;IAASC,UAAT;IAAqBC;EAArB,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdH,KADc;IAEdI,IAAI,EAAEH,UAFQ;IAGdC,UAAU;MACNG,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,OAAO,EAAE;QACLC,IAAI,EAAE;MADD,CAPH;MAUNC,OAAO,EAAE;QACLD,IAAI,EAAE;MADD,CAVH;MAaNE,IAAI,EAAE;QACFF,IAAI,EAAE;MADJ,CAbA;MAgBNG,EAAE,EAAE;QACAH,IAAI,EAAE;MADN,CAhBE;MAmBNI,MAAM,EAAE;QACJJ,IAAI,EAAE;MADF,CAnBF;MAsBNK,MAAM,EAAE;QACJL,IAAI,EAAE;MADF,CAtBF;MAyBNM,MAAM,EAAE;QACJN,IAAI,EAAE;MADF,CAzBF;MA4BNO,SAAS,EAAE;QACPP,IAAI,EAAE;MADC,CA5BL;MA+BNQ,OAAO,EAAE;QACLR,IAAI,EAAE;MADD,CA/BH;MAkCNS,OAAO,EAAE;QACLT,IAAI,EAAE;MADD,CAlCH;MAqCNU,SAAS,EAAE;QACPV,IAAI,EAAE;MADC,CArCL;MAwCNN,IAAI,EAAE;QACFM,IAAI,EAAE;MADJ,CAxCA;MA2CNW,IAAI,EAAE;QACFX,IAAI,EAAE;MADJ,CA3CA;MA8CNY,OAAO,EAAE;QACLZ,IAAI,EAAE;MADD,CA9CH;MAiDNa,MAAM,EAAE;QACJb,IAAI,EAAE;MADF,CAjDF;MAoDNc,SAAS,EAAE;QACPd,IAAI,EAAE;MADC,CApDL;MAuDNe,WAAW,EAAE;QACTf,IAAI,EAAE;MADG,CAvDP;MA0DNgB,MAAM,EAAE;QACJhB,IAAI,EAAE;MADF,CA1DF;MA6DNiB,MAAM,EAAE;QACJjB,IAAI,EAAE;MADF,CA7DF;MAgENkB,MAAM,EAAE;QACJlB,IAAI,EAAE;MADF,CAhEF;MAmENmB,KAAK,EAAE;QACHnB,IAAI,EAAE;MADH,CAnED;MAsENoB,QAAQ,EAAE;QACNpB,IAAI,EAAE;MADA,CAtEJ;MAyENqB,QAAQ,EAAE;QACNrB,IAAI,EAAE;MADA,CAzEJ;MA4ENsB,aAAa,EAAE;QACXtB,IAAI,EAAE;MADK;IA5ET,GA+EFR,UAAU,IAAI,EA/EZ;EAHI,CAAX,CAAP;AAqFH,CAvFM"}
|
package/definitions/settings.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSettingsEntity = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
const createSettingsEntity = params => {
|
|
19
15
|
const {
|
|
20
16
|
entityName,
|
|
@@ -24,7 +20,7 @@ const createSettingsEntity = params => {
|
|
|
24
20
|
return new _dynamodbToolbox.Entity({
|
|
25
21
|
name: entityName,
|
|
26
22
|
table,
|
|
27
|
-
attributes:
|
|
23
|
+
attributes: (0, _objectSpread2.default)({
|
|
28
24
|
PK: {
|
|
29
25
|
partitionKey: true
|
|
30
26
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSettingsEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","reCaptcha","domain","tenant","locale"],"sources":["settings.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSettingsEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n reCaptcha: {\n type: \"map\"\n },\n domain: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"names":["createSettingsEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","reCaptcha","domain","tenant","locale"],"sources":["settings.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSettingsEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n reCaptcha: {\n type: \"map\"\n },\n domain: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,oBAAoB,GAAIC,MAAD,IAAiC;EACjE,MAAM;IAAEC,UAAF;IAAcC,UAAd;IAA0BC;EAA1B,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdE,KAFc;IAGdD,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,IAAI,EAAE;QACFC,IAAI,EAAE;MADJ,CAPA;MAUNC,SAAS,EAAE;QACPD,IAAI,EAAE;MADC,CAVL;MAaNE,MAAM,EAAE;QACJF,IAAI,EAAE;MADF,CAbF;MAgBNG,MAAM,EAAE;QACJH,IAAI,EAAE;MADF,CAhBF;MAmBNI,MAAM,EAAE;QACJJ,IAAI,EAAE;MADF;IAnBF,GAsBFT,UAAU,IAAI,EAtBZ;EAHI,CAAX,CAAP;AA4BH,CA9BM"}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSubmissionEntity = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
const createSubmissionEntity = params => {
|
|
19
15
|
const {
|
|
20
16
|
table,
|
|
@@ -24,7 +20,7 @@ const createSubmissionEntity = params => {
|
|
|
24
20
|
return new _dynamodbToolbox.Entity({
|
|
25
21
|
table,
|
|
26
22
|
name: entityName,
|
|
27
|
-
attributes:
|
|
23
|
+
attributes: (0, _objectSpread2.default)({
|
|
28
24
|
PK: {
|
|
29
25
|
partitionKey: true
|
|
30
26
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSubmissionEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","id","type","TYPE","data","meta","form","logs","createdOn","savedOn","ownedBy","tenant","locale","webinyVersion"],"sources":["submission.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSubmissionEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n id: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n form: {\n type: \"map\"\n },\n logs: {\n type: \"list\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n ownedBy: {\n type: \"map\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"names":["createSubmissionEntity","params","table","entityName","attributes","Entity","name","PK","partitionKey","SK","sortKey","id","type","TYPE","data","meta","form","logs","createdOn","savedOn","ownedBy","tenant","locale","webinyVersion"],"sources":["submission.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSubmissionEntity = (params: Params): Entity<any> => {\n const { table, entityName, attributes } = params;\n return new Entity({\n table,\n name: entityName,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n id: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n },\n meta: {\n type: \"map\"\n },\n form: {\n type: \"map\"\n },\n logs: {\n type: \"list\"\n },\n createdOn: {\n type: \"string\"\n },\n savedOn: {\n type: \"string\"\n },\n ownedBy: {\n type: \"map\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,sBAAsB,GAAIC,MAAD,IAAiC;EACnE,MAAM;IAAEC,KAAF;IAASC,UAAT;IAAqBC;EAArB,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdH,KADc;IAEdI,IAAI,EAAEH,UAFQ;IAGdC,UAAU;MACNG,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,EAAE,EAAE;QACAC,IAAI,EAAE;MADN,CAPE;MAUNC,IAAI,EAAE;QACFD,IAAI,EAAE;MADJ,CAVA;MAaNE,IAAI,EAAE;QACFF,IAAI,EAAE;MADJ,CAbA;MAgBNG,IAAI,EAAE;QACFH,IAAI,EAAE;MADJ,CAhBA;MAmBNI,IAAI,EAAE;QACFJ,IAAI,EAAE;MADJ,CAnBA;MAsBNK,IAAI,EAAE;QACFL,IAAI,EAAE;MADJ,CAtBA;MAyBNM,SAAS,EAAE;QACPN,IAAI,EAAE;MADC,CAzBL;MA4BNO,OAAO,EAAE;QACLP,IAAI,EAAE;MADD,CA5BH;MA+BNQ,OAAO,EAAE;QACLR,IAAI,EAAE;MADD,CA/BH;MAkCNS,MAAM,EAAE;QACJT,IAAI,EAAE;MADF,CAlCF;MAqCNU,MAAM,EAAE;QACJV,IAAI,EAAE;MADF,CArCF;MAwCNW,aAAa,EAAE;QACXX,IAAI,EAAE;MADK;IAxCT,GA2CFR,UAAU,IAAI,EA3CZ;EAHI,CAAX,CAAP;AAiDH,CAnDM"}
|
package/definitions/system.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSystemEntity = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
13
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
14
|
const createSystemEntity = params => {
|
|
19
15
|
const {
|
|
20
16
|
entityName,
|
|
@@ -24,7 +20,7 @@ const createSystemEntity = params => {
|
|
|
24
20
|
return new _dynamodbToolbox.Entity({
|
|
25
21
|
name: entityName,
|
|
26
22
|
table,
|
|
27
|
-
attributes:
|
|
23
|
+
attributes: (0, _objectSpread2.default)({
|
|
28
24
|
PK: {
|
|
29
25
|
partitionKey: true
|
|
30
26
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSystemEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"sources":["system.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSystemEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"names":["createSystemEntity","params","entityName","attributes","table","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"sources":["system.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { Attributes } from \"~/types\";\n\ninterface Params {\n table: Table;\n entityName: string;\n attributes: Attributes;\n}\n\nexport const createSystemEntity = (params: Params): Entity<any> => {\n const { entityName, attributes, table } = params;\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...(attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAMA,kBAAkB,GAAIC,MAAD,IAAiC;EAC/D,MAAM;IAAEC,UAAF;IAAcC,UAAd;IAA0BC;EAA1B,IAAoCH,MAA1C;EACA,OAAO,IAAII,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdE,KAFc;IAGdD,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,OAAO,EAAE;QACLC,IAAI,EAAE;MADD,CAPH;MAUNC,MAAM,EAAE;QACJD,IAAI,EAAE;MADF;IAVF,GAaFT,UAAU,IAAI,EAbZ;EAHI,CAAX,CAAP;AAmBH,CArBM"}
|
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createFormBuilderStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _types = require("./types");
|
|
13
13
|
|
|
@@ -39,10 +39,6 @@ var _fields2 = _interopRequireDefault(require("./operations/form/fields"));
|
|
|
39
39
|
|
|
40
40
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
41
41
|
|
|
42
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
43
|
-
|
|
44
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
45
|
-
|
|
46
42
|
const reservedFields = ["PK", "SK", "index", "data", "TYPE", "__type", "GSI1_PK", "GSI1_SK"];
|
|
47
43
|
|
|
48
44
|
const isReserved = name => {
|
|
@@ -115,7 +111,7 @@ const createFormBuilderStorageOperations = params => {
|
|
|
115
111
|
attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
|
|
116
112
|
})
|
|
117
113
|
};
|
|
118
|
-
return
|
|
114
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
119
115
|
upgrade: null,
|
|
120
116
|
getTable: () => table,
|
|
121
117
|
getEntities: () => entities
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","documentClient","plugins","userPlugins","Object","values","forEach","attrs","keys","PluginsContainer","formSubmissionFields","formFields","dynamoDbValueFilters","createTable","entities","form","createFormEntity","entityName","ENTITIES","FORM","submission","createSubmissionEntity","SUBMISSION","system","createSystemEntity","SYSTEM","settings","createSettingsEntity","SETTINGS","upgrade","getTable","getEntities","createSystemStorageOperations","entity","createSettingsStorageOperations","createFormStorageOperations","createSubmissionStorageOperations"],"sources":["index.ts"],"sourcesContent":["import { FormBuilderStorageOperationsFactory, ENTITIES } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createFormEntity } from \"~/definitions/form\";\nimport { createSubmissionEntity } from \"~/definitions/submission\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSubmissionStorageOperations } from \"~/operations/submission\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createFormStorageOperations } from \"~/operations/form\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport formSubmissionFields from \"~/operations/submission/fields\";\nimport formFields from \"~/operations/form/fields\";\nimport WebinyError from \"@webiny/error\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\", \"TYPE\", \"__type\", \"GSI1_PK\", \"GSI1_SK\"];\n\nconst isReserved = (name: string): void => {\n if (reservedFields.includes(name) === false) {\n return;\n }\n throw new WebinyError(`Attribute name \"${name}\" is not allowed.`, \"ATTRIBUTE_NOT_ALLOWED\", {\n name\n });\n};\n\nexport const createFormBuilderStorageOperations: FormBuilderStorageOperationsFactory = params => {\n const { attributes, table: tableName, documentClient, plugins: userPlugins } = params;\n\n if (attributes) {\n Object.values(attributes).forEach(attrs => {\n Object.keys(attrs).forEach(isReserved);\n });\n }\n\n const plugins = new PluginsContainer([\n /**\n * User defined plugins.\n */\n userPlugins || [],\n /**\n * Form submission DynamoDB fields.\n */\n formSubmissionFields(),\n /**\n * Form DynamoDB fields.\n */\n formFields(),\n\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters()\n ]);\n\n const table = createTable({\n tableName,\n documentClient\n });\n\n const entities = {\n /**\n * Regular entities.\n */\n form: createFormEntity({\n entityName: ENTITIES.FORM,\n table,\n attributes: attributes ? attributes[ENTITIES.FORM] : {}\n }),\n submission: createSubmissionEntity({\n entityName: ENTITIES.SUBMISSION,\n table,\n attributes: attributes ? attributes[ENTITIES.SUBMISSION] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n })\n };\n\n return {\n upgrade: null,\n getTable: () => table,\n getEntities: () => entities,\n ...createSystemStorageOperations({\n table,\n entity: entities.system\n }),\n ...createSettingsStorageOperations({\n table,\n entity: entities.settings\n }),\n ...createFormStorageOperations({\n table,\n entity: entities.form,\n plugins\n }),\n ...createSubmissionStorageOperations({\n table,\n entity: entities.submission,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA
|
|
1
|
+
{"version":3,"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","documentClient","plugins","userPlugins","Object","values","forEach","attrs","keys","PluginsContainer","formSubmissionFields","formFields","dynamoDbValueFilters","createTable","entities","form","createFormEntity","entityName","ENTITIES","FORM","submission","createSubmissionEntity","SUBMISSION","system","createSystemEntity","SYSTEM","settings","createSettingsEntity","SETTINGS","upgrade","getTable","getEntities","createSystemStorageOperations","entity","createSettingsStorageOperations","createFormStorageOperations","createSubmissionStorageOperations"],"sources":["index.ts"],"sourcesContent":["import { FormBuilderStorageOperationsFactory, ENTITIES } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createFormEntity } from \"~/definitions/form\";\nimport { createSubmissionEntity } from \"~/definitions/submission\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSubmissionStorageOperations } from \"~/operations/submission\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createFormStorageOperations } from \"~/operations/form\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport formSubmissionFields from \"~/operations/submission/fields\";\nimport formFields from \"~/operations/form/fields\";\nimport WebinyError from \"@webiny/error\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\", \"TYPE\", \"__type\", \"GSI1_PK\", \"GSI1_SK\"];\n\nconst isReserved = (name: string): void => {\n if (reservedFields.includes(name) === false) {\n return;\n }\n throw new WebinyError(`Attribute name \"${name}\" is not allowed.`, \"ATTRIBUTE_NOT_ALLOWED\", {\n name\n });\n};\n\nexport const createFormBuilderStorageOperations: FormBuilderStorageOperationsFactory = params => {\n const { attributes, table: tableName, documentClient, plugins: userPlugins } = params;\n\n if (attributes) {\n Object.values(attributes).forEach(attrs => {\n Object.keys(attrs).forEach(isReserved);\n });\n }\n\n const plugins = new PluginsContainer([\n /**\n * User defined plugins.\n */\n userPlugins || [],\n /**\n * Form submission DynamoDB fields.\n */\n formSubmissionFields(),\n /**\n * Form DynamoDB fields.\n */\n formFields(),\n\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters()\n ]);\n\n const table = createTable({\n tableName,\n documentClient\n });\n\n const entities = {\n /**\n * Regular entities.\n */\n form: createFormEntity({\n entityName: ENTITIES.FORM,\n table,\n attributes: attributes ? attributes[ENTITIES.FORM] : {}\n }),\n submission: createSubmissionEntity({\n entityName: ENTITIES.SUBMISSION,\n table,\n attributes: attributes ? attributes[ENTITIES.SUBMISSION] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n })\n };\n\n return {\n upgrade: null,\n getTable: () => table,\n getEntities: () => entities,\n ...createSystemStorageOperations({\n table,\n entity: entities.system\n }),\n ...createSettingsStorageOperations({\n table,\n entity: entities.settings\n }),\n ...createFormStorageOperations({\n table,\n entity: entities.form,\n plugins\n }),\n ...createSubmissionStorageOperations({\n table,\n entity: entities.submission,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,cAAc,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,OAAb,EAAsB,MAAtB,EAA8B,MAA9B,EAAsC,QAAtC,EAAgD,SAAhD,EAA2D,SAA3D,CAAvB;;AAEA,MAAMC,UAAU,GAAIC,IAAD,IAAwB;EACvC,IAAIF,cAAc,CAACG,QAAf,CAAwBD,IAAxB,MAAkC,KAAtC,EAA6C;IACzC;EACH;;EACD,MAAM,IAAIE,cAAJ,CAAiB,mBAAkBF,IAAK,mBAAxC,EAA4D,uBAA5D,EAAqF;IACvFA;EADuF,CAArF,CAAN;AAGH,CAPD;;AASO,MAAMG,kCAAuE,GAAGC,MAAM,IAAI;EAC7F,MAAM;IA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AdK;IAmBbC,QAAQ,EAAE,IAAAC,8BAAA,EAAqB;MAC3BV,UAAU,EAAEC,eAAA,CAASU,QADM;MAE3B7B,KAF2B;MAG3BD,UAAU,EAAEA,UAAU,GAAGA,UAAU,CAACoB,eAAA,CAASU,QAAV,CAAb,GAAmC;IAH9B,CAArB;EAnBG,CAAjB;EA0BA;IACIC,OAAO,EAAE,IADb;IAEIC,QAAQ,EAAE,MAAM/B,KAFpB;IAGIgC,WAAW,EAAE,MAAMjB;EAHvB,GAIO,IAAAkB,sCAAA,EAA8B;IAC7BjC,KAD6B;IAE7BkC,MAAM,EAAEnB,QAAQ,CAACS;EAFY,CAA9B,CAJP,GAQO,IAAAW,0CAAA,EAAgC;IAC/BnC,KAD+B;IAE/BkC,MAAM,EAAEnB,QAAQ,CAACY;EAFc,CAAhC,CARP,GAYO,IAAAS,kCAAA,EAA4B;IAC3BpC,KAD2B;IAE3BkC,MAAM,EAAEnB,QAAQ,CAACC,IAFU;IAG3Bb;EAH2B,CAA5B,CAZP,GAiBO,IAAAkC,8CAAA,EAAkC;IACjCrC,KADiC;IAEjCkC,MAAM,EAAEnB,QAAQ,CAACM,UAFgB;IAGjClB;EAHiC,CAAlC,CAjBP;AAuBH,CAnFM"}
|
package/operations/form/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createFormStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
@@ -29,10 +29,6 @@ var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
|
29
29
|
|
|
30
30
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
31
31
|
|
|
32
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
-
|
|
34
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
35
|
-
|
|
36
32
|
const createFormStorageOperations = params => {
|
|
37
33
|
const {
|
|
38
34
|
entity,
|
|
@@ -142,9 +138,9 @@ const createFormStorageOperations = params => {
|
|
|
142
138
|
const revisionKeys = createRevisionKeys(form);
|
|
143
139
|
const latestKeys = createLatestKeys(form);
|
|
144
140
|
const gsiKeys = createGSIKeys(form);
|
|
145
|
-
const items = [entity.putBatch(
|
|
141
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
|
|
146
142
|
TYPE: createFormType()
|
|
147
|
-
})), entity.putBatch(
|
|
143
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
148
144
|
TYPE: createFormLatestType()
|
|
149
145
|
}))];
|
|
150
146
|
|
|
@@ -173,9 +169,9 @@ const createFormStorageOperations = params => {
|
|
|
173
169
|
const revisionKeys = createRevisionKeys(form);
|
|
174
170
|
const latestKeys = createLatestKeys(form);
|
|
175
171
|
const gsiKeys = createGSIKeys(form);
|
|
176
|
-
const items = [entity.putBatch(
|
|
172
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
|
|
177
173
|
TYPE: createFormType()
|
|
178
|
-
})), entity.putBatch(
|
|
174
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
179
175
|
TYPE: createFormLatestType()
|
|
180
176
|
}))];
|
|
181
177
|
|
|
@@ -219,12 +215,12 @@ const createFormStorageOperations = params => {
|
|
|
219
215
|
}
|
|
220
216
|
});
|
|
221
217
|
const isLatestForm = latestForm ? latestForm.id === form.id : false;
|
|
222
|
-
const items = [entity.putBatch(
|
|
218
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
|
|
223
219
|
TYPE: createFormType()
|
|
224
220
|
}))];
|
|
225
221
|
|
|
226
222
|
if (isLatestForm) {
|
|
227
|
-
items.push(entity.putBatch(
|
|
223
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
228
224
|
TYPE: createFormLatestType()
|
|
229
225
|
})));
|
|
230
226
|
}
|
|
@@ -333,13 +329,11 @@ const createFormStorageOperations = params => {
|
|
|
333
329
|
}
|
|
334
330
|
|
|
335
331
|
const totalCount = results.length;
|
|
336
|
-
|
|
337
|
-
const where = _objectSpread({}, initialWhere);
|
|
332
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
338
333
|
/**
|
|
339
334
|
* We need to remove conditions so we do not filter by them again.
|
|
340
335
|
*/
|
|
341
336
|
|
|
342
|
-
|
|
343
337
|
delete where.tenant;
|
|
344
338
|
delete where.locale;
|
|
345
339
|
const filteredItems = (0, _filter.filterItems)({
|
|
@@ -408,12 +402,11 @@ const createFormStorageOperations = params => {
|
|
|
408
402
|
});
|
|
409
403
|
}
|
|
410
404
|
|
|
411
|
-
const where =
|
|
405
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
412
406
|
/**
|
|
413
407
|
* We need to remove conditions so we do not filter by them again.
|
|
414
408
|
*/
|
|
415
409
|
|
|
416
|
-
|
|
417
410
|
delete where.id;
|
|
418
411
|
delete where.formId;
|
|
419
412
|
delete where.tenant;
|
|
@@ -518,7 +511,7 @@ const createFormStorageOperations = params => {
|
|
|
518
511
|
}).shift();
|
|
519
512
|
|
|
520
513
|
if (previouslyPublishedForm) {
|
|
521
|
-
items.push(entity.putBatch(
|
|
514
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), createLatestPublishedKeys(previouslyPublishedForm)), {}, {
|
|
522
515
|
GSI1_PK: null,
|
|
523
516
|
GSI1_SK: null,
|
|
524
517
|
TYPE: createFormLatestPublishedType()
|
|
@@ -533,7 +526,7 @@ const createFormStorageOperations = params => {
|
|
|
533
526
|
|
|
534
527
|
|
|
535
528
|
if (isLatest) {
|
|
536
|
-
items.push(entity.putBatch(
|
|
529
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
|
|
537
530
|
GSI1_PK: null,
|
|
538
531
|
GSI1_SK: null,
|
|
539
532
|
TYPE: createFormLatestType()
|
|
@@ -599,9 +592,9 @@ const createFormStorageOperations = params => {
|
|
|
599
592
|
* Update revision and latest published records
|
|
600
593
|
*/
|
|
601
594
|
|
|
602
|
-
const items = [entity.putBatch(
|
|
595
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
|
|
603
596
|
TYPE: createFormType()
|
|
604
|
-
})), entity.putBatch(
|
|
597
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
|
|
605
598
|
TYPE: createFormLatestPublishedType()
|
|
606
599
|
}))];
|
|
607
600
|
/**
|
|
@@ -609,7 +602,7 @@ const createFormStorageOperations = params => {
|
|
|
609
602
|
*/
|
|
610
603
|
|
|
611
604
|
if (isLatestForm) {
|
|
612
|
-
items.push(entity.putBatch(
|
|
605
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
613
606
|
TYPE: createFormLatestType()
|
|
614
607
|
})));
|
|
615
608
|
}
|
|
@@ -672,12 +665,12 @@ const createFormStorageOperations = params => {
|
|
|
672
665
|
});
|
|
673
666
|
const isLatest = latestForm ? latestForm.id === form.id : false;
|
|
674
667
|
const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
|
|
675
|
-
const items = [entity.putBatch(
|
|
668
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
|
|
676
669
|
TYPE: createFormType()
|
|
677
670
|
}))];
|
|
678
671
|
|
|
679
672
|
if (isLatest) {
|
|
680
|
-
entity.putBatch(
|
|
673
|
+
entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
681
674
|
TYPE: createFormLatestType()
|
|
682
675
|
}));
|
|
683
676
|
}
|
|
@@ -701,7 +694,7 @@ const createFormStorageOperations = params => {
|
|
|
701
694
|
const previouslyPublishedRevision = revisions.shift();
|
|
702
695
|
|
|
703
696
|
if (previouslyPublishedRevision) {
|
|
704
|
-
items.push(entity.putBatch(
|
|
697
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
|
|
705
698
|
TYPE: createFormLatestPublishedType()
|
|
706
699
|
})));
|
|
707
700
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFormStorageOperations","params","entity","table","plugins","formDynamoDbFields","byType","FormDynamoDbFieldPlugin","type","createFormPartitionKey","tenant","locale","createFormLatestPartitionKey","createFormLatestPublishedPartitionKey","createFormGSIPartitionKey","id","targetId","parseIdentifier","createRevisionSortKey","createFormLatestSortKey","formId","value","createLatestPublishedSortKey","createGSISortKey","version","createFormType","createFormLatestType","createFormLatestPublishedType","createRevisionKeys","form","PK","SK","createLatestKeys","createLatestPublishedKeys","createGSIKeys","GSI1_PK","GSI1_SK","createForm","revisionKeys","latestKeys","gsiKeys","items","putBatch","TYPE","batchWriteAll","ex","WebinyError","message","code","createFormFrom","original","latest","updateForm","latestForm","getForm","where","isLatestForm","push","published","partitionKey","sortKey","createIdentifier","keys","item","get","cleanupItem","listForms","sort","limit","initialWhere","after","queryAllParams","options","gte","results","queryAll","totalCount","length","filteredItems","filterItems","fields","sortedItems","sortItems","start","parseInt","decodeCursor","hasMoreItems","end","undefined","slice","cursor","encodeCursor","meta","listFormRevisions","index","deleteForm","beginsWith","hasLatestPublishedRecord","deleteItems","map","deleteBatch","deleteFormRevision","revisions","previous","latestPublishedForm","find","rev","isLatest","isLatestPublished","previouslyPublishedForm","filter","f","publishedOn","a","b","Date","getTime","shift","publishForm","latestPublishedKeys","unpublishForm","version_not","publishedOn_not","previouslyPublishedRevision"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n FbForm,\n FormBuilderStorageOperationsCreateFormFromParams,\n FormBuilderStorageOperationsCreateFormParams,\n FormBuilderStorageOperationsDeleteFormParams,\n FormBuilderStorageOperationsDeleteFormRevisionParams,\n FormBuilderStorageOperationsGetFormParams,\n FormBuilderStorageOperationsListFormRevisionsParams,\n FormBuilderStorageOperationsListFormRevisionsParamsWhere,\n FormBuilderStorageOperationsListFormsParams,\n FormBuilderStorageOperationsListFormsResponse,\n FormBuilderStorageOperationsPublishFormParams,\n FormBuilderStorageOperationsUnpublishFormParams,\n FormBuilderStorageOperationsUpdateFormParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n FormBuilderFormCreateGSIPartitionKeyParams,\n FormBuilderFormCreatePartitionKeyParams,\n FormBuilderFormStorageOperations\n} from \"~/types\";\nimport { FormDynamoDbFieldPlugin } from \"~/plugins/FormDynamoDbFieldPlugin\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { get } from \"@webiny/db-dynamodb/utils/get\";\n\ntype DbRecord<T = any> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\n\ninterface FormLatestSortKeyParams {\n id?: string;\n formId?: string;\n}\n\ninterface GsiKeys {\n GSI1_PK: string;\n GSI1_SK: string;\n}\n\nexport interface CreateFormStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n plugins: PluginsContainer;\n}\n\nexport const createFormStorageOperations = (\n params: CreateFormStorageOperationsParams\n): FormBuilderFormStorageOperations => {\n const { entity, table, plugins } = params;\n\n const formDynamoDbFields = plugins.byType<FormDynamoDbFieldPlugin>(\n FormDynamoDbFieldPlugin.type\n );\n\n const createFormPartitionKey = (params: FormBuilderFormCreatePartitionKeyParams): string => {\n const { tenant, locale } = params;\n\n return `T#${tenant}#L#${locale}#FB#F`;\n };\n\n const createFormLatestPartitionKey = (\n params: FormBuilderFormCreatePartitionKeyParams\n ): string => {\n return `${createFormPartitionKey(params)}#L`;\n };\n\n const createFormLatestPublishedPartitionKey = (\n params: FormBuilderFormCreatePartitionKeyParams\n ): string => {\n return `${createFormPartitionKey(params)}#LP`;\n };\n\n const createFormGSIPartitionKey = (\n params: FormBuilderFormCreateGSIPartitionKeyParams\n ): string => {\n const { tenant, locale, id: targetId } = params;\n const { id } = parseIdentifier(targetId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n\n const createRevisionSortKey = ({ id }: { id: string }): string => {\n return `${id}`;\n };\n\n const createFormLatestSortKey = ({ id, formId }: FormLatestSortKeyParams): string => {\n const value = parseIdentifier(id || formId);\n return value.id;\n };\n\n const createLatestPublishedSortKey = ({ id, formId }: FormLatestSortKeyParams): string => {\n const value = parseIdentifier(id || formId);\n return value.id;\n };\n\n const createGSISortKey = (version: number) => {\n return `${version}`;\n };\n\n const createFormType = (): string => {\n return \"fb.form\";\n };\n\n const createFormLatestType = (): string => {\n return \"fb.form.latest\";\n };\n\n const createFormLatestPublishedType = (): string => {\n return \"fb.form.latestPublished\";\n };\n\n const createRevisionKeys = (form: FbForm): Keys => {\n return {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form)\n };\n };\n\n const createLatestKeys = (form: FbForm): Keys => {\n return {\n PK: createFormLatestPartitionKey(form),\n SK: createFormLatestSortKey(form)\n };\n };\n\n const createLatestPublishedKeys = (form: FbForm): Keys => {\n return {\n PK: createFormLatestPublishedPartitionKey(form),\n SK: createLatestPublishedSortKey(form)\n };\n };\n\n const createGSIKeys = (form: FbForm): GsiKeys => {\n return {\n GSI1_PK: createFormGSIPartitionKey(form),\n GSI1_SK: createGSISortKey(form.version)\n };\n };\n\n const createForm = async (\n params: FormBuilderStorageOperationsCreateFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n form\n }\n );\n }\n return form;\n };\n\n const createFormFrom = async (\n params: FormBuilderStorageOperationsCreateFormFromParams\n ): Promise<FbForm> => {\n const { form, original, latest } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form data in the table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latest\n }\n );\n }\n\n return form;\n };\n\n const updateForm = async (\n params: FormBuilderStorageOperationsUpdateFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n })\n ];\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latestForm\n }\n );\n }\n\n return form;\n };\n\n const getForm = async (\n params: FormBuilderStorageOperationsGetFormParams\n ): Promise<FbForm | null> => {\n const { where } = params;\n const { id, formId, latest, published, version } = where;\n if (latest && published) {\n throw new WebinyError(\"Cannot have both latest and published params.\");\n }\n let partitionKey: string;\n let sortKey: string;\n if (latest) {\n partitionKey = createFormLatestPartitionKey(where);\n sortKey = createFormLatestSortKey(where);\n } else if (published && !version) {\n /**\n * Because of the specifics how DynamoDB works, we must not load the published record if version is sent.\n */\n partitionKey = createFormLatestPublishedPartitionKey(where);\n sortKey = createLatestPublishedSortKey(where);\n } else if (id || version) {\n partitionKey = createFormPartitionKey(where);\n sortKey = createRevisionSortKey({\n id:\n id ||\n createIdentifier({\n id: formId as string,\n version: version as number\n })\n });\n } else {\n throw new WebinyError(\n \"Missing parameter to create a sort key.\",\n \"MISSING_WHERE_PARAMETER\",\n {\n where\n }\n );\n }\n\n const keys = {\n PK: partitionKey,\n SK: sortKey\n };\n\n try {\n const item = await get<FbForm>({ entity, keys });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get form by keys.\",\n ex.code || \"GET_FORM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const listForms = async (\n params: FormBuilderStorageOperationsListFormsParams\n ): Promise<FormBuilderStorageOperationsListFormsResponse> => {\n const { sort, limit, where: initialWhere, after } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormLatestPartitionKey(initialWhere),\n options: {\n gte: \" \"\n }\n };\n\n let results;\n try {\n results = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list forms.\",\n ex.code || \"LIST_FORMS_ERROR\",\n {\n where: initialWhere,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n const totalCount = results.length;\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"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\n const filteredItems = filterItems({\n plugins,\n items: results,\n where,\n fields: formDynamoDbFields\n });\n\n const sortedItems = sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n\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 = sortedItems.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 listFormRevisions = async (\n params: FormBuilderStorageOperationsListFormRevisionsParams\n ): Promise<FbForm[]> => {\n const { where: initialWhere, sort } = params;\n const { id, formId, tenant, locale } = initialWhere;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormGSIPartitionKey({\n tenant,\n locale,\n id: formId || id\n }),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n\n let items: FbForm[] = [];\n try {\n items = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms by given params.\",\n ex.code || \"QUERY_FORMS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n const where: Partial<FormBuilderStorageOperationsListFormRevisionsParamsWhere> = {\n ...initialWhere\n };\n /**\n * We need to remove conditions so we do not filter by them again.\n */\n delete where.id;\n delete where.formId;\n delete where.tenant;\n delete where.locale;\n\n const filteredItems = filterItems({\n plugins,\n items,\n where,\n fields: formDynamoDbFields\n });\n return sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n };\n\n const deleteForm = async (\n params: FormBuilderStorageOperationsDeleteFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n let items: any[];\n /**\n * This will find all form records.\n */\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormPartitionKey(form),\n options: {\n beginsWith: form.formId\n }\n };\n try {\n items = await queryAll<DbRecord>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms and submissions by given params.\",\n ex.code || \"QUERY_FORM_AND_SUBMISSIONS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n let hasLatestPublishedRecord = false;\n\n const deleteItems = items.map(item => {\n if (!hasLatestPublishedRecord && item.published) {\n hasLatestPublishedRecord = true;\n }\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n if (hasLatestPublishedRecord) {\n deleteItems.push(entity.deleteBatch(createLatestPublishedKeys(items[0])));\n }\n\n deleteItems.push(entity.deleteBatch(createLatestKeys(items[0])));\n\n try {\n await batchWriteAll({\n table,\n items: deleteItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form and it's submissions.\",\n ex.code || \"DELETE_FORM_AND_SUBMISSIONS_ERROR\"\n );\n }\n return form;\n };\n /**\n * We need to:\n * - delete current revision\n * - get previously published revision and update the record if it exists or delete if it does not\n * - update latest record if current one is the latest\n */\n const deleteFormRevision = async (\n params: FormBuilderStorageOperationsDeleteFormRevisionParams\n ): Promise<FbForm> => {\n const { form, revisions, previous } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n\n const latestForm = revisions[0];\n const latestPublishedForm = revisions.find(rev => rev.published === true);\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [entity.deleteBatch(revisionKeys)];\n\n if (isLatest || isLatestPublished) {\n /**\n * Sort out the latest published record.\n */\n if (isLatestPublished) {\n const previouslyPublishedForm = revisions\n .filter(f => !!f.publishedOn && f.version !== form.version)\n .sort((a, b) => {\n return (\n new Date(b.publishedOn as string).getTime() -\n new Date(a.publishedOn as string).getTime()\n );\n })\n .shift();\n if (previouslyPublishedForm) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedForm,\n ...createLatestPublishedKeys(previouslyPublishedForm),\n GSI1_PK: null,\n GSI1_SK: null,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(createLatestPublishedKeys(form)));\n }\n }\n /**\n * Sort out the latest record.\n */\n if (isLatest) {\n items.push(\n entity.putBatch({\n ...previous,\n ...latestKeys,\n GSI1_PK: null,\n GSI1_SK: null,\n TYPE: createFormLatestType()\n })\n );\n }\n }\n /**\n * Now save the batch data.\n */\n try {\n await batchWriteAll({\n table,\n items\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form revision from table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n };\n\n /**\n * We need to save form in:\n * - regular form record\n * - latest published form record\n * - latest form record - if form is latest one\n * - elasticsearch latest form record\n */\n const publishForm = async (\n params: FormBuilderStorageOperationsPublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n\n const latestKeys = createLatestKeys(form);\n\n const latestPublishedKeys = createLatestPublishedKeys(form);\n\n const gsiKeys = {\n GSI1_PK: createFormGSIPartitionKey(form),\n GSI1_SK: createGSISortKey(form.version)\n };\n\n const { locale, tenant, formId } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n /**\n * Update revision and latest published records\n */\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n ];\n /**\n * Update the latest form as well\n */\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n return form;\n };\n\n /**\n * We need to:\n * - update form revision record\n * - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise\n * - if is latest update the Elasticsearch record\n */\n const unpublishForm = async (\n params: FormBuilderStorageOperationsUnpublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const latestPublishedKeys = createLatestPublishedKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const latestPublishedForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n published: true\n }\n });\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n })\n ];\n\n if (isLatest) {\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n });\n }\n /**\n * In case previously published revision exists, replace current one with that one.\n * And if it does not, delete the record.\n */\n if (isLatestPublished) {\n const revisions = await listFormRevisions({\n where: {\n formId,\n tenant,\n locale,\n version_not: form.version,\n publishedOn_not: null\n },\n sort: [\"savedOn_DESC\"]\n });\n\n const previouslyPublishedRevision = revisions.shift();\n if (previouslyPublishedRevision) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedRevision,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(latestPublishedKeys));\n }\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n return {\n createForm,\n createFormFrom,\n updateForm,\n listForms,\n listFormRevisions,\n getForm,\n deleteForm,\n deleteFormRevision,\n publishForm,\n unpublishForm,\n createFormPartitionKey\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAiBA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;;;;;AA6BO,MAAMA,2BAA2B,GACpCC,MADuC,IAEJ;EACnC,MAAM;IAAEC,MAAF;IAAUC,KAAV;IAAiBC;EAAjB,IAA6BH,MAAnC;EAEA,MAAMI,kBAAkB,GAAGD,OAAO,CAACE,MAAR,CACvBC,gDAAA,CAAwBC,IADD,CAA3B;;EAIA,MAAMC,sBAAsB,GAAIR,MAAD,IAA6D;IACxF,MAAM;MAAES,MAAF;MAAUC;IAAV,IAAqBV,MAA3B;IAEA,OAAQ,KAAIS,MAAO,MAAKC,MAAO,OAA/B;EACH,CAJD;;EAMA,MAAMC,4BAA4B,GAC9BX,MADiC,IAExB;IACT,OAAQ,GAAEQ,sBAAsB,CAACR,MAAD,CAAS,IAAzC;EACH,CAJD;;EAMA,MAAMY,qCAAqC,GACvCZ,MAD0C,IAEjC;IACT,OAAQ,GAAEQ,sBAAsB,CAACR,MAAD,CAAS,KAAzC;EACH,CAJD;;EAMA,MAAMa,yBAAyB,GAC3Bb,MAD8B,IAErB;IACT,MAAM;MAAES,MAAF;MAAUC,MAAV;MAAkBI,EAAE,EAAEC;IAAtB,IAAmCf,MAAz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,CAAd,CAAN;MAIA,OAAOZ,IAAP;IACH,CAND,CAME,OAAOgB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACInB,IADJ;QAEIqB,QAFJ;QAGIG,UAHJ;QAIIf,YAJJ;QAKIC,UALJ;QAMIgF;MANJ,CAHE,CAAN;IAYH;EACJ,CAnGD;;EAqGA,OAAO;IACHlF,UADG;IAEHY,cAFG;IAGHG,UAHG;IAIHc,SAJG;IAKH2B,iBALG;IAMHvC,OANG;IAOHyC,UAPG;IAQHM,kBARG;IASHiB,WATG;IAUHE,aAVG;IAWH/G;EAXG,CAAP;AAaH,CA3wBM"}
|
|
1
|
+
{"version":3,"names":["createFormStorageOperations","params","entity","table","plugins","formDynamoDbFields","byType","FormDynamoDbFieldPlugin","type","createFormPartitionKey","tenant","locale","createFormLatestPartitionKey","createFormLatestPublishedPartitionKey","createFormGSIPartitionKey","id","targetId","parseIdentifier","createRevisionSortKey","createFormLatestSortKey","formId","value","createLatestPublishedSortKey","createGSISortKey","version","createFormType","createFormLatestType","createFormLatestPublishedType","createRevisionKeys","form","PK","SK","createLatestKeys","createLatestPublishedKeys","createGSIKeys","GSI1_PK","GSI1_SK","createForm","revisionKeys","latestKeys","gsiKeys","items","putBatch","TYPE","batchWriteAll","ex","WebinyError","message","code","createFormFrom","original","latest","updateForm","latestForm","getForm","where","isLatestForm","push","published","partitionKey","sortKey","createIdentifier","keys","item","get","cleanupItem","listForms","sort","limit","initialWhere","after","queryAllParams","options","gte","results","queryAll","totalCount","length","filteredItems","filterItems","fields","sortedItems","sortItems","start","parseInt","decodeCursor","hasMoreItems","end","undefined","slice","cursor","encodeCursor","meta","listFormRevisions","index","deleteForm","beginsWith","hasLatestPublishedRecord","deleteItems","map","deleteBatch","deleteFormRevision","revisions","previous","latestPublishedForm","find","rev","isLatest","isLatestPublished","previouslyPublishedForm","filter","f","publishedOn","a","b","Date","getTime","shift","publishForm","latestPublishedKeys","unpublishForm","version_not","publishedOn_not","previouslyPublishedRevision"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n FbForm,\n FormBuilderStorageOperationsCreateFormFromParams,\n FormBuilderStorageOperationsCreateFormParams,\n FormBuilderStorageOperationsDeleteFormParams,\n FormBuilderStorageOperationsDeleteFormRevisionParams,\n FormBuilderStorageOperationsGetFormParams,\n FormBuilderStorageOperationsListFormRevisionsParams,\n FormBuilderStorageOperationsListFormRevisionsParamsWhere,\n FormBuilderStorageOperationsListFormsParams,\n FormBuilderStorageOperationsListFormsResponse,\n FormBuilderStorageOperationsPublishFormParams,\n FormBuilderStorageOperationsUnpublishFormParams,\n FormBuilderStorageOperationsUpdateFormParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n FormBuilderFormCreateGSIPartitionKeyParams,\n FormBuilderFormCreatePartitionKeyParams,\n FormBuilderFormStorageOperations\n} from \"~/types\";\nimport { FormDynamoDbFieldPlugin } from \"~/plugins/FormDynamoDbFieldPlugin\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { get } from \"@webiny/db-dynamodb/utils/get\";\n\ntype DbRecord<T = any> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\n\ninterface FormLatestSortKeyParams {\n id?: string;\n formId?: string;\n}\n\ninterface GsiKeys {\n GSI1_PK: string;\n GSI1_SK: string;\n}\n\nexport interface CreateFormStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n plugins: PluginsContainer;\n}\n\nexport const createFormStorageOperations = (\n params: CreateFormStorageOperationsParams\n): FormBuilderFormStorageOperations => {\n const { entity, table, plugins } = params;\n\n const formDynamoDbFields = plugins.byType<FormDynamoDbFieldPlugin>(\n FormDynamoDbFieldPlugin.type\n );\n\n const createFormPartitionKey = (params: FormBuilderFormCreatePartitionKeyParams): string => {\n const { tenant, locale } = params;\n\n return `T#${tenant}#L#${locale}#FB#F`;\n };\n\n const createFormLatestPartitionKey = (\n params: FormBuilderFormCreatePartitionKeyParams\n ): string => {\n return `${createFormPartitionKey(params)}#L`;\n };\n\n const createFormLatestPublishedPartitionKey = (\n params: FormBuilderFormCreatePartitionKeyParams\n ): string => {\n return `${createFormPartitionKey(params)}#LP`;\n };\n\n const createFormGSIPartitionKey = (\n params: FormBuilderFormCreateGSIPartitionKeyParams\n ): string => {\n const { tenant, locale, id: targetId } = params;\n const { id } = parseIdentifier(targetId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n\n const createRevisionSortKey = ({ id }: { id: string }): string => {\n return `${id}`;\n };\n\n const createFormLatestSortKey = ({ id, formId }: FormLatestSortKeyParams): string => {\n const value = parseIdentifier(id || formId);\n return value.id;\n };\n\n const createLatestPublishedSortKey = ({ id, formId }: FormLatestSortKeyParams): string => {\n const value = parseIdentifier(id || formId);\n return value.id;\n };\n\n const createGSISortKey = (version: number) => {\n return `${version}`;\n };\n\n const createFormType = (): string => {\n return \"fb.form\";\n };\n\n const createFormLatestType = (): string => {\n return \"fb.form.latest\";\n };\n\n const createFormLatestPublishedType = (): string => {\n return \"fb.form.latestPublished\";\n };\n\n const createRevisionKeys = (form: FbForm): Keys => {\n return {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form)\n };\n };\n\n const createLatestKeys = (form: FbForm): Keys => {\n return {\n PK: createFormLatestPartitionKey(form),\n SK: createFormLatestSortKey(form)\n };\n };\n\n const createLatestPublishedKeys = (form: FbForm): Keys => {\n return {\n PK: createFormLatestPublishedPartitionKey(form),\n SK: createLatestPublishedSortKey(form)\n };\n };\n\n const createGSIKeys = (form: FbForm): GsiKeys => {\n return {\n GSI1_PK: createFormGSIPartitionKey(form),\n GSI1_SK: createGSISortKey(form.version)\n };\n };\n\n const createForm = async (\n params: FormBuilderStorageOperationsCreateFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n form\n }\n );\n }\n return form;\n };\n\n const createFormFrom = async (\n params: FormBuilderStorageOperationsCreateFormFromParams\n ): Promise<FbForm> => {\n const { form, original, latest } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form data in the table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latest\n }\n );\n }\n\n return form;\n };\n\n const updateForm = async (\n params: FormBuilderStorageOperationsUpdateFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n })\n ];\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latestForm\n }\n );\n }\n\n return form;\n };\n\n const getForm = async (\n params: FormBuilderStorageOperationsGetFormParams\n ): Promise<FbForm | null> => {\n const { where } = params;\n const { id, formId, latest, published, version } = where;\n if (latest && published) {\n throw new WebinyError(\"Cannot have both latest and published params.\");\n }\n let partitionKey: string;\n let sortKey: string;\n if (latest) {\n partitionKey = createFormLatestPartitionKey(where);\n sortKey = createFormLatestSortKey(where);\n } else if (published && !version) {\n /**\n * Because of the specifics how DynamoDB works, we must not load the published record if version is sent.\n */\n partitionKey = createFormLatestPublishedPartitionKey(where);\n sortKey = createLatestPublishedSortKey(where);\n } else if (id || version) {\n partitionKey = createFormPartitionKey(where);\n sortKey = createRevisionSortKey({\n id:\n id ||\n createIdentifier({\n id: formId as string,\n version: version as number\n })\n });\n } else {\n throw new WebinyError(\n \"Missing parameter to create a sort key.\",\n \"MISSING_WHERE_PARAMETER\",\n {\n where\n }\n );\n }\n\n const keys = {\n PK: partitionKey,\n SK: sortKey\n };\n\n try {\n const item = await get<FbForm>({ entity, keys });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get form by keys.\",\n ex.code || \"GET_FORM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const listForms = async (\n params: FormBuilderStorageOperationsListFormsParams\n ): Promise<FormBuilderStorageOperationsListFormsResponse> => {\n const { sort, limit, where: initialWhere, after } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormLatestPartitionKey(initialWhere),\n options: {\n gte: \" \"\n }\n };\n\n let results;\n try {\n results = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list forms.\",\n ex.code || \"LIST_FORMS_ERROR\",\n {\n where: initialWhere,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n const totalCount = results.length;\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"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\n const filteredItems = filterItems({\n plugins,\n items: results,\n where,\n fields: formDynamoDbFields\n });\n\n const sortedItems = sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n\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 = sortedItems.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 listFormRevisions = async (\n params: FormBuilderStorageOperationsListFormRevisionsParams\n ): Promise<FbForm[]> => {\n const { where: initialWhere, sort } = params;\n const { id, formId, tenant, locale } = initialWhere;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormGSIPartitionKey({\n tenant,\n locale,\n id: formId || id\n }),\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n };\n\n let items: FbForm[] = [];\n try {\n items = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms by given params.\",\n ex.code || \"QUERY_FORMS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n const where: Partial<FormBuilderStorageOperationsListFormRevisionsParamsWhere> = {\n ...initialWhere\n };\n /**\n * We need to remove conditions so we do not filter by them again.\n */\n delete where.id;\n delete where.formId;\n delete where.tenant;\n delete where.locale;\n\n const filteredItems = filterItems({\n plugins,\n items,\n where,\n fields: formDynamoDbFields\n });\n return sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n };\n\n const deleteForm = async (\n params: FormBuilderStorageOperationsDeleteFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n let items: any[];\n /**\n * This will find all form records.\n */\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormPartitionKey(form),\n options: {\n beginsWith: form.formId\n }\n };\n try {\n items = await queryAll<DbRecord>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms and submissions by given params.\",\n ex.code || \"QUERY_FORM_AND_SUBMISSIONS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n let hasLatestPublishedRecord = false;\n\n const deleteItems = items.map(item => {\n if (!hasLatestPublishedRecord && item.published) {\n hasLatestPublishedRecord = true;\n }\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n if (hasLatestPublishedRecord) {\n deleteItems.push(entity.deleteBatch(createLatestPublishedKeys(items[0])));\n }\n\n deleteItems.push(entity.deleteBatch(createLatestKeys(items[0])));\n\n try {\n await batchWriteAll({\n table,\n items: deleteItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form and it's submissions.\",\n ex.code || \"DELETE_FORM_AND_SUBMISSIONS_ERROR\"\n );\n }\n return form;\n };\n /**\n * We need to:\n * - delete current revision\n * - get previously published revision and update the record if it exists or delete if it does not\n * - update latest record if current one is the latest\n */\n const deleteFormRevision = async (\n params: FormBuilderStorageOperationsDeleteFormRevisionParams\n ): Promise<FbForm> => {\n const { form, revisions, previous } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n\n const latestForm = revisions[0];\n const latestPublishedForm = revisions.find(rev => rev.published === true);\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [entity.deleteBatch(revisionKeys)];\n\n if (isLatest || isLatestPublished) {\n /**\n * Sort out the latest published record.\n */\n if (isLatestPublished) {\n const previouslyPublishedForm = revisions\n .filter(f => !!f.publishedOn && f.version !== form.version)\n .sort((a, b) => {\n return (\n new Date(b.publishedOn as string).getTime() -\n new Date(a.publishedOn as string).getTime()\n );\n })\n .shift();\n if (previouslyPublishedForm) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedForm,\n ...createLatestPublishedKeys(previouslyPublishedForm),\n GSI1_PK: null,\n GSI1_SK: null,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(createLatestPublishedKeys(form)));\n }\n }\n /**\n * Sort out the latest record.\n */\n if (isLatest) {\n items.push(\n entity.putBatch({\n ...previous,\n ...latestKeys,\n GSI1_PK: null,\n GSI1_SK: null,\n TYPE: createFormLatestType()\n })\n );\n }\n }\n /**\n * Now save the batch data.\n */\n try {\n await batchWriteAll({\n table,\n items\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form revision from table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n };\n\n /**\n * We need to save form in:\n * - regular form record\n * - latest published form record\n * - latest form record - if form is latest one\n * - elasticsearch latest form record\n */\n const publishForm = async (\n params: FormBuilderStorageOperationsPublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n\n const latestKeys = createLatestKeys(form);\n\n const latestPublishedKeys = createLatestPublishedKeys(form);\n\n const gsiKeys = {\n GSI1_PK: createFormGSIPartitionKey(form),\n GSI1_SK: createGSISortKey(form.version)\n };\n\n const { locale, tenant, formId } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n /**\n * Update revision and latest published records\n */\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n ];\n /**\n * Update the latest form as well\n */\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n return form;\n };\n\n /**\n * We need to:\n * - update form revision record\n * - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise\n * - if is latest update the Elasticsearch record\n */\n const unpublishForm = async (\n params: FormBuilderStorageOperationsUnpublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = createRevisionKeys(form);\n const latestKeys = createLatestKeys(form);\n const latestPublishedKeys = createLatestPublishedKeys(form);\n const gsiKeys = createGSIKeys(form);\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const latestPublishedForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n published: true\n }\n });\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n ...gsiKeys,\n TYPE: createFormType()\n })\n ];\n\n if (isLatest) {\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n });\n }\n /**\n * In case previously published revision exists, replace current one with that one.\n * And if it does not, delete the record.\n */\n if (isLatestPublished) {\n const revisions = await listFormRevisions({\n where: {\n formId,\n tenant,\n locale,\n version_not: form.version,\n publishedOn_not: null\n },\n sort: [\"savedOn_DESC\"]\n });\n\n const previouslyPublishedRevision = revisions.shift();\n if (previouslyPublishedRevision) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedRevision,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(latestPublishedKeys));\n }\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n return {\n createForm,\n createFormFrom,\n updateForm,\n listForms,\n listFormRevisions,\n getForm,\n deleteForm,\n deleteFormRevision,\n publishForm,\n unpublishForm,\n createFormPartitionKey\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAiBA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AA6BO,MAAMA,2BAA2B,GACpCC,MADuC,IAEJ;EACnC,MAAM;IAAEC,MAAF;IAAUC,KAAV;IAAiBC;EAAjB,IAA6BH,MAAnC;EAEA,MAAMI,kBAAkB,GAAGD,OAAO,CAACE,MAAR,CACvBC,gDAAA,CAAwBC,IADD,CAA3B;;EAIA,MAAMC,sBAAsB,GAAIR,MAAD,IAA6D;IACxF,MAAM;MAAES,MAAF;MAAUC;IAAV,IAAqBV,MAA3B;IAEA,OAAQ,KAAIS,MAAO,MAAKC,MAAO,OAA/B;EACH,CAJD;;EAMA,MAAMC,4BAA4B,GAC9BX,MADiC,IAExB;IACT,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ACgB,IAAN,CACIvD,MAAM,CAACwC,QAAP,yFACOiF,2BADP,GAEOJ,mBAFP;UAGI5E,IAAI,EAAEhB,6BAA6B;QAHvC,GADJ;MAOH,CARD,MAQO;QACHc,KAAK,CAACgB,IAAN,CAAWvD,MAAM,CAACkG,WAAP,CAAmBmB,mBAAnB,CAAX;MACH;IACJ;;IAED,IAAI;MACA,MAAM,IAAA3E,yBAAA,EAAc;QAChBzC,KADgB;QAEhBsC;MAFgB,CAAd,CAAN;MAIA,OAAOZ,IAAP;IACH,CAND,CAME,OAAOgB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACInB,IADJ;QAEIqB,QAFJ;QAGIG,UAHJ;QAIIf,YAJJ;QAKIC,UALJ;QAMIgF;MANJ,CAHE,CAAN;IAYH;EACJ,CAnGD;;EAqGA,OAAO;IACHlF,UADG;IAEHY,cAFG;IAGHG,UAHG;IAIHc,SAJG;IAKH2B,iBALG;IAMHvC,OANG;IAOHyC,UAPG;IAQHM,kBARG;IASHiB,WATG;IAUHE,aAVG;IAWH/G;EAXG,CAAP;AAaH,CA3wBM"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSettingsStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
@@ -15,10 +15,6 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
|
15
15
|
|
|
16
16
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
18
|
const createSettingsStorageOperations = params => {
|
|
23
19
|
const {
|
|
24
20
|
entity
|
|
@@ -49,7 +45,7 @@ const createSettingsStorageOperations = params => {
|
|
|
49
45
|
const keys = createKeys(settings);
|
|
50
46
|
|
|
51
47
|
try {
|
|
52
|
-
await entity.put(
|
|
48
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
53
49
|
return settings;
|
|
54
50
|
} catch (ex) {
|
|
55
51
|
throw new _error.default(ex.message || "Could not create the settings record by given keys.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
@@ -83,7 +79,7 @@ const createSettingsStorageOperations = params => {
|
|
|
83
79
|
const keys = createKeys(settings);
|
|
84
80
|
|
|
85
81
|
try {
|
|
86
|
-
await entity.put(
|
|
82
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
87
83
|
return settings;
|
|
88
84
|
} catch (ex) {
|
|
89
85
|
throw new _error.default(ex.message || "Could not update the settings record by given keys.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
@@ -1 +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();\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
|
|
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();\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,MAD2C,IAEJ;EACvC,MAAM;IAAEC;EAAF,IAAaD,MAAnB;;EAEA,MAAME,0BAA0B,GAAG,CAAC;IAChCC,MADgC;IAEhCC;EAFgC,CAAD,KAGyC;IACxE,OAAQ,KAAID,MAAO,MAAKC,MAAO,cAA/B;EACH,CALD;;EAOA,MAAMC,qBAAqB,GAAG,MAAc;IACxC,OAAO,SAAP;EACH,CAFD;;EAIA,MAAMC,UAAU,GAAIN,MAAD,IAA0E;IACzF,OAAO;MACHO,EAAE,EAAEL,0BAA0B,CAACF,MAAD,CAD3B;MAEHQ,EAAE,EAAEH,qBAAqB;IAFtB,CAAP;EAIH,CALD;;EAOA,MAAMI,cAAc,GAAG,MACnBT,MADmB,IAEC;IACpB,MAAM;MAAEU;IAAF,IAAeV,MAArB;IACA,MAAMW,IAAI,GAAGL,UAAU,CAACI,QAAD,CAAvB;;IAEA,IAAI;MACA,MAAMT,MAAM,CAACW,GAAP,6DACCF,QADD,GAECC,IAFD,EAAN;MAIA,OAAOD,QAAP;IACH,CAND,CAME,OAAOG,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,qDADZ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P,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,qDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;EACJ,CAhBD;;EAkBA,OAAO;IACHF,cADG;IAEHQ,WAFG;IAGHI,cAHG;IAIHE,cAJG;IAKHrB,0BALG;IAMHG;EANG,CAAP;AAQH,CArHM"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSubmissionStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
13
|
|
|
@@ -27,10 +27,6 @@ var _FormSubmissionDynamoDbFieldPlugin = require("../../plugins/FormSubmissionDy
|
|
|
27
27
|
|
|
28
28
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
29
29
|
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
-
|
|
34
30
|
const createSubmissionStorageOperations = params => {
|
|
35
31
|
const {
|
|
36
32
|
entity,
|
|
@@ -68,7 +64,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
68
64
|
};
|
|
69
65
|
|
|
70
66
|
try {
|
|
71
|
-
await entity.put(
|
|
67
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
|
|
72
68
|
TYPE: createSubmissionType()
|
|
73
69
|
}));
|
|
74
70
|
} catch (ex) {
|
|
@@ -94,7 +90,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
try {
|
|
97
|
-
await entity.put(
|
|
93
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
|
|
98
94
|
TYPE: createSubmissionType()
|
|
99
95
|
}));
|
|
100
96
|
return submission;
|
|
@@ -143,13 +139,11 @@ const createSubmissionStorageOperations = params => {
|
|
|
143
139
|
locale,
|
|
144
140
|
formId
|
|
145
141
|
} = initialWhere;
|
|
146
|
-
|
|
147
|
-
const where = _objectSpread({}, initialWhere);
|
|
142
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
148
143
|
/**
|
|
149
144
|
* We need to remove conditions so we do not filter by them again.
|
|
150
145
|
*/
|
|
151
146
|
|
|
152
|
-
|
|
153
147
|
delete where.tenant;
|
|
154
148
|
delete where.locale;
|
|
155
149
|
delete where.formId;
|
|
@@ -1 +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,MAD6C,IAEJ;EACzC,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAsBF,MAA5B;;EAEA,MAAMG,4BAA4B,GAC9BH,MADiC,IAEhC;IACD,MAAM;MAAEI,MAAF;MAAUC,MAAV;MAAkBC;IAAlB,IAA6BN,MAAnC;IAEA,MAAM;MAAEO;IAAF,IAAS,IAAAC,sBAAA,EAAgBF,MAAhB,CAAf;IAEA,OAAQ,KAAIF,MAAO,MAAKC,MAAO,UAASE,EAAG,EAA3C;EACH,CARD;;EASA,MAAME,uBAAuB,GAAIF,EAAD,IAAgB;IAC5C,OAAOA,EAAP;EACH,CAFD;;EAIA,MAAMG,oBAAoB,GAAG,MAAM;IAC/B,OAAO,mBAAP;EACH,CAFD;;EAIA,MAAMC,gBAAgB,GAAG,MACrBX,MADqB,IAEG;IACxB,MAAM;MAAEY,UAAF;MAAcC;IAAd,IAAuBb,MAA7B;IACA,MAAMc,IAAI,GAAG;MACTC,EAAE,EAAEZ,4BAA4B,CAACU,IAAD,CADvB;MAETG,EAAE,EAAEP,uBAAuB,CAACG,UAAU,CAACL,EAAZ;IAFlB,CAAb;;IAKA,IAAI;MACA,MAAMN,MAAM,CAACgB,GAAP,+CACCL,UADD,GAECE,IAFD;QAGFI,IAAI,EAAER,oBAAoB;MAHxB,GAAN;IAKH,CAND,CAME,OAAOS,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,mDADZ,EAEFF,EAAE,CAACG,IAAH,IAA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E,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACIM,KADJ;QAEId;MAFJ,CAHE,CAAN;IAQH;EACJ,CAvBD;;EAyBA,OAAO;IACHH,gBADG;IAEHc,gBAFG;IAGHF,gBAHG;IAIHI,eAJG;IAKHkC,aALG;IAMH1D,4BANG;IAOHM;EAPG,CAAP;AASH,CAnOM"}
|
|
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,MAD6C,IAEJ;EACzC,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAsBF,MAA5B;;EAEA,MAAMG,4BAA4B,GAC9BH,MADiC,IAEhC;IACD,MAAM;MAAEI,MAAF;MAAUC,MAAV;MAAkBC;IAAlB,IAA6BN,MAAnC;IAEA,MAAM;MAAEO;IAAF,IAAS,IAAAC,sBAAA,EAAgBF,MAAhB,CAAf;IAEA,OAAQ,KAAIF,MAAO,MAAKC,MAAO,UAASE,EAAG,EAA3C;EACH,CARD;;EASA,MAAME,uBAAuB,GAAIF,EAAD,IAAgB;IAC5C,OAAOA,EAAP;EACH,CAFD;;EAIA,MAAMG,oBAAoB,GAAG,MAAM;IAC/B,OAAO,mBAAP;EACH,CAFD;;EAIA,MAAMC,gBAAgB,GAAG,MACrBX,MADqB,IAEG;IACxB,MAAM;MA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4B;IAAF,IAAY5B,MAAlB;IAEA,MAAMc,IAAI,GAAG;MACTC,EAAE,EAAEZ,4BAA4B,CAACyB,KAAD,CADvB;MAETZ,EAAE,EAAEP,uBAAuB,CAACmB,KAAK,CAACrB,EAAP;IAFlB,CAAb;;IAKA,IAAI;MACA,MAAMuD,IAAI,GAAG,MAAM,IAAAC,QAAA,EAAkB;QAAE9D,MAAF;QAAUa;MAAV,CAAlB,CAAnB;MACA,OAAO,IAAAkD,oBAAA,EAAY/D,MAAZ,EAAoB6D,IAApB,CAAP;IACH,CAHD,CAGE,OAAO3C,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACIM,KADJ;QAEId;MAFJ,CAHE,CAAN;IAQH;EACJ,CAvBD;;EAyBA,OAAO;IACHH,gBADG;IAEHc,gBAFG;IAGHF,gBAHG;IAIHI,eAJG;IAKHkC,aALG;IAMH1D,4BANG;IAOHM;EAPG,CAAP;AASH,CAnOM"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createSystemStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
12
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
13
13
|
|
|
@@ -15,10 +15,6 @@ var _error = _interopRequireDefault(require("@webiny/error"));
|
|
|
15
15
|
|
|
16
16
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
22
18
|
const createSystemStorageOperations = params => {
|
|
23
19
|
const {
|
|
24
20
|
entity
|
|
@@ -48,7 +44,7 @@ const createSystemStorageOperations = params => {
|
|
|
48
44
|
const keys = createKeys(system);
|
|
49
45
|
|
|
50
46
|
try {
|
|
51
|
-
await entity.put(
|
|
47
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
|
|
52
48
|
return system;
|
|
53
49
|
} catch (ex) {
|
|
54
50
|
throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
@@ -82,7 +78,7 @@ const createSystemStorageOperations = params => {
|
|
|
82
78
|
const keys = createKeys(system);
|
|
83
79
|
|
|
84
80
|
try {
|
|
85
|
-
await entity.put(
|
|
81
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
|
|
86
82
|
return system;
|
|
87
83
|
} catch (ex) {
|
|
88
84
|
throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
@@ -1 +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
|
|
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,MADyC,IAEJ;EACrC,MAAM;IAAEC;EAAF,IAAaD,MAAnB;;EAEA,MAAME,wBAAwB,GAAG,CAAC;IAAEC;EAAF,CAAD,KAA2D;IACxF,OAAQ,KAAIA,MAAO,SAAnB;EACH,CAFD;;EAIA,MAAMC,mBAAmB,GAAG,MAAc;IACtC,OAAO,IAAP;EACH,CAFD;;EAIA,MAAMC,UAAU,GAAIL,MAAD,IAA+C;IAC9D,OAAO;MACHM,EAAE,EAAEJ,wBAAwB,CAACF,MAAD,CADzB;MAEHO,EAAE,EAAEH,mBAAmB;IAFpB,CAAP;EAIH,CALD;;EAOA,MAAMI,YAAY,GAAG,MACj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;QACIL,IADJ;QAEIW,QAFJ;QAGIZ;MAHJ,CAHE,CAAN;IASH;EACJ,CAvBD;;EAyBA,OAAO;IACHD,YADG;IAEHQ,SAFG;IAGHI,YAHG;IAIHlB,wBAJG;IAKHE;EALG,CAAP;AAOH,CA/FM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-form-builder-so-ddb",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.34.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-form-builder",
|
|
@@ -20,22 +20,22 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/runtime": "7.
|
|
24
|
-
"@webiny/api-form-builder": "5.
|
|
25
|
-
"@webiny/db-dynamodb": "5.
|
|
26
|
-
"@webiny/error": "5.
|
|
27
|
-
"@webiny/plugins": "5.
|
|
28
|
-
"@webiny/utils": "5.
|
|
23
|
+
"@babel/runtime": "7.19.0",
|
|
24
|
+
"@webiny/api-form-builder": "5.34.0-beta.0",
|
|
25
|
+
"@webiny/db-dynamodb": "5.34.0-beta.0",
|
|
26
|
+
"@webiny/error": "5.34.0-beta.0",
|
|
27
|
+
"@webiny/plugins": "5.34.0-beta.0",
|
|
28
|
+
"@webiny/utils": "5.34.0-beta.0",
|
|
29
29
|
"dynamodb-toolbox": "0.3.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/cli": "^7.
|
|
33
|
-
"@babel/core": "^7.
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
35
|
-
"@babel/preset-typescript": "^7.
|
|
36
|
-
"@webiny/cli": "^5.
|
|
37
|
-
"@webiny/handler-db": "^5.
|
|
38
|
-
"@webiny/project-utils": "^5.
|
|
32
|
+
"@babel/cli": "^7.19.3",
|
|
33
|
+
"@babel/core": "^7.19.3",
|
|
34
|
+
"@babel/preset-env": "^7.19.4",
|
|
35
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
36
|
+
"@webiny/cli": "^5.34.0-beta.0",
|
|
37
|
+
"@webiny/handler-db": "^5.34.0-beta.0",
|
|
38
|
+
"@webiny/project-utils": "^5.34.0-beta.0",
|
|
39
39
|
"csvtojson": "^2.0.10",
|
|
40
40
|
"jest": "^28.1.0",
|
|
41
41
|
"jest-dynalite": "^3.2.0",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"build": "yarn webiny run build",
|
|
53
53
|
"watch": "yarn webiny run watch"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "9648454619a1bfb35040eb00f27a64ed75194e61"
|
|
56
56
|
}
|