@webiny/api-form-builder-so-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.40876133bb
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/configurations.d.ts +7 -5
- package/configurations.js +31 -9
- package/configurations.js.map +1 -0
- package/definitions/elasticsearch.d.ts +2 -1
- package/definitions/elasticsearch.js +3 -7
- package/definitions/elasticsearch.js.map +1 -0
- package/definitions/form.d.ts +2 -1
- package/definitions/form.js +3 -7
- package/definitions/form.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.d.ts +2 -1
- package/definitions/submission.js +3 -7
- package/definitions/submission.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +3 -2
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +2 -1
- package/definitions/tableElasticsearch.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +10 -0
- package/elasticsearch/createElasticsearchIndex.js +63 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +15 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +16 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +16 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/index.js +36 -33
- package/index.js.map +1 -0
- package/operations/form/elasticsearchBody.js +12 -29
- package/operations/form/elasticsearchBody.js.map +1 -0
- package/operations/form/elasticsearchFields.js.map +1 -0
- package/operations/form/fields.js.map +1 -0
- package/operations/form/index.d.ts +2 -2
- package/operations/form/index.js +51 -50
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +4 -8
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/elasticsearchBody.js +16 -26
- package/operations/submission/elasticsearchBody.js.map +1 -0
- package/operations/submission/elasticsearchFields.js.map +1 -0
- package/operations/submission/index.d.ts +2 -2
- package/operations/submission/index.js +22 -27
- package/operations/submission/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +4 -8
- package/operations/system/index.js.map +1 -0
- package/package.json +23 -27
- package/plugins/FormDynamoDbFieldPlugin.js +1 -1
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchBodyModifierPlugin.js +3 -3
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchFieldPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchFieldPlugin.js +3 -3
- package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchIndexPlugin.js +17 -0
- package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchQueryModifierPlugin.js +3 -3
- package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchSortModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchSortModifierPlugin.js +3 -3
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +3 -3
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchFieldPlugin.js +3 -3
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +3 -3
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js +3 -3
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
- package/types.d.ts +2 -2
- package/types.js.map +1 -0
- package/operations/system/createElasticsearchIndex.d.ts +0 -6
- package/operations/system/createElasticsearchIndex.js +0 -70
- package/upgrades/5.16.0/index.d.ts +0 -8
- package/upgrades/5.16.0/index.js +0 -141
package/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
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
|
-
var
|
|
12
|
+
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
13
|
+
|
|
14
|
+
var _elasticsearchFields = _interopRequireDefault(require("./operations/form/elasticsearchFields"));
|
|
15
|
+
|
|
16
|
+
var _elasticsearchFields2 = _interopRequireDefault(require("./operations/submission/elasticsearchFields"));
|
|
13
17
|
|
|
14
18
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
19
|
|
|
20
|
+
var _types = require("./types");
|
|
21
|
+
|
|
16
22
|
var _table = require("./definitions/table");
|
|
17
23
|
|
|
18
24
|
var _form = require("./definitions/form");
|
|
@@ -31,27 +37,17 @@ var _settings2 = require("./operations/settings");
|
|
|
31
37
|
|
|
32
38
|
var _form2 = require("./operations/form");
|
|
33
39
|
|
|
34
|
-
var _createElasticsearchIndex = require("./operations/system/createElasticsearchIndex");
|
|
35
|
-
|
|
36
40
|
var _tableElasticsearch = require("./definitions/tableElasticsearch");
|
|
37
41
|
|
|
38
42
|
var _plugins = require("@webiny/plugins");
|
|
39
43
|
|
|
40
44
|
var _elasticsearch = require("./definitions/elasticsearch");
|
|
41
45
|
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
var _elasticsearchFields2 = _interopRequireDefault(require("./operations/form/elasticsearchFields"));
|
|
45
|
-
|
|
46
|
-
var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
|
|
47
|
-
|
|
48
|
-
var _operators = require("@webiny/api-elasticsearch/operators");
|
|
49
|
-
|
|
50
|
-
var _ = _interopRequireDefault(require("./upgrades/5.16.0"));
|
|
46
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
51
47
|
|
|
52
|
-
|
|
48
|
+
var _indices = require("./elasticsearch/indices");
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
|
|
55
51
|
|
|
56
52
|
const reservedFields = ["PK", "SK", "index", "data", "TYPE", "__type", "GSI1_PK", "GSI1_SK"];
|
|
57
53
|
|
|
@@ -67,12 +63,12 @@ const isReserved = name => {
|
|
|
67
63
|
|
|
68
64
|
const createFormBuilderStorageOperations = params => {
|
|
69
65
|
const {
|
|
70
|
-
attributes
|
|
66
|
+
attributes,
|
|
71
67
|
table: tableName,
|
|
72
68
|
esTable: esTableName,
|
|
73
69
|
documentClient,
|
|
74
70
|
elasticsearch,
|
|
75
|
-
plugins:
|
|
71
|
+
plugins: userPlugins
|
|
76
72
|
} = params;
|
|
77
73
|
|
|
78
74
|
if (attributes) {
|
|
@@ -85,15 +81,15 @@ const createFormBuilderStorageOperations = params => {
|
|
|
85
81
|
/**
|
|
86
82
|
* User defined plugins.
|
|
87
83
|
*/
|
|
88
|
-
|
|
84
|
+
userPlugins || [],
|
|
89
85
|
/**
|
|
90
86
|
* Elasticsearch field definitions for the submission record.
|
|
91
87
|
*/
|
|
92
|
-
(0,
|
|
88
|
+
(0, _elasticsearchFields2.default)(),
|
|
93
89
|
/**
|
|
94
90
|
* Elasticsearch field definitions for the form record.
|
|
95
91
|
*/
|
|
96
|
-
(0,
|
|
92
|
+
(0, _elasticsearchFields.default)(),
|
|
97
93
|
/**
|
|
98
94
|
* DynamoDB filter plugins for the where conditions.
|
|
99
95
|
*/
|
|
@@ -101,7 +97,11 @@ const createFormBuilderStorageOperations = params => {
|
|
|
101
97
|
/**
|
|
102
98
|
* Elasticsearch operators.
|
|
103
99
|
*/
|
|
104
|
-
(0,
|
|
100
|
+
(0, _apiElasticsearch.getElasticsearchOperators)(),
|
|
101
|
+
/**
|
|
102
|
+
* Built-in Elasticsearch index plugins
|
|
103
|
+
*/
|
|
104
|
+
(0, _indices.elasticsearchIndexPlugins)()]);
|
|
105
105
|
const table = (0, _table.createTable)({
|
|
106
106
|
tableName,
|
|
107
107
|
documentClient
|
|
@@ -117,22 +117,22 @@ const createFormBuilderStorageOperations = params => {
|
|
|
117
117
|
form: (0, _form.createFormEntity)({
|
|
118
118
|
entityName: _types.ENTITIES.FORM,
|
|
119
119
|
table,
|
|
120
|
-
attributes: attributes[_types.ENTITIES.FORM]
|
|
120
|
+
attributes: attributes ? attributes[_types.ENTITIES.FORM] : {}
|
|
121
121
|
}),
|
|
122
122
|
submission: (0, _submission.createSubmissionEntity)({
|
|
123
123
|
entityName: _types.ENTITIES.SUBMISSION,
|
|
124
124
|
table,
|
|
125
|
-
attributes: attributes[_types.ENTITIES.SUBMISSION]
|
|
125
|
+
attributes: attributes ? attributes[_types.ENTITIES.SUBMISSION] : {}
|
|
126
126
|
}),
|
|
127
127
|
system: (0, _system.createSystemEntity)({
|
|
128
128
|
entityName: _types.ENTITIES.SYSTEM,
|
|
129
129
|
table,
|
|
130
|
-
attributes: attributes[_types.ENTITIES.SYSTEM]
|
|
130
|
+
attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
|
|
131
131
|
}),
|
|
132
132
|
settings: (0, _settings.createSettingsEntity)({
|
|
133
133
|
entityName: _types.ENTITIES.SETTINGS,
|
|
134
134
|
table,
|
|
135
|
-
attributes: attributes[_types.ENTITIES.SETTINGS]
|
|
135
|
+
attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
|
|
136
136
|
}),
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -141,26 +141,29 @@ const createFormBuilderStorageOperations = params => {
|
|
|
141
141
|
esForm: (0, _elasticsearch.createElasticsearchEntity)({
|
|
142
142
|
entityName: _types.ENTITIES.ES_FORM,
|
|
143
143
|
table: esTable,
|
|
144
|
-
attributes: attributes[_types.ENTITIES.ES_FORM]
|
|
144
|
+
attributes: attributes ? attributes[_types.ENTITIES.ES_FORM] : {}
|
|
145
145
|
}),
|
|
146
146
|
esSubmission: (0, _elasticsearch.createElasticsearchEntity)({
|
|
147
147
|
entityName: _types.ENTITIES.ES_SUBMISSION,
|
|
148
148
|
table: esTable,
|
|
149
|
-
attributes: attributes[_types.ENTITIES.ES_SUBMISSION]
|
|
149
|
+
attributes: attributes ? attributes[_types.ENTITIES.ES_SUBMISSION] : {}
|
|
150
150
|
})
|
|
151
151
|
};
|
|
152
|
-
return
|
|
153
|
-
init: async
|
|
154
|
-
|
|
152
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
153
|
+
init: async context => {
|
|
154
|
+
context.i18n.locales.onLocaleBeforeCreate.subscribe(async ({
|
|
155
|
+
locale,
|
|
155
156
|
tenant
|
|
156
157
|
}) => {
|
|
157
158
|
await (0, _createElasticsearchIndex.createElasticsearchIndex)({
|
|
158
159
|
elasticsearch,
|
|
159
|
-
|
|
160
|
+
plugins,
|
|
161
|
+
tenant,
|
|
162
|
+
locale: locale.code
|
|
160
163
|
});
|
|
161
164
|
});
|
|
162
165
|
},
|
|
163
|
-
upgrade:
|
|
166
|
+
upgrade: null,
|
|
164
167
|
getTable: () => table,
|
|
165
168
|
getEsTable: () => esTable,
|
|
166
169
|
getEntities: () => entities
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","userPlugins","Object","values","forEach","attrs","keys","PluginsContainer","submissionElasticsearchFields","formElasticsearchFields","dynamoDbValueFilters","getElasticsearchOperators","elasticsearchIndexPlugins","createTable","createElasticsearchTable","entities","form","createFormEntity","entityName","ENTITIES","FORM","submission","createSubmissionEntity","SUBMISSION","system","createSystemEntity","SYSTEM","settings","createSettingsEntity","SETTINGS","esForm","createElasticsearchEntity","ES_FORM","esSubmission","ES_SUBMISSION","init","context","i18n","locales","onLocaleBeforeCreate","subscribe","locale","tenant","createElasticsearchIndex","code","upgrade","getTable","getEsTable","getEntities","createSystemStorageOperations","entity","createSettingsStorageOperations","createFormStorageOperations","esEntity","createSubmissionStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport formElasticsearchFields from \"./operations/form/elasticsearchFields\";\nimport submissionElasticsearchFields from \"./operations/submission/elasticsearchFields\";\nimport WebinyError from \"@webiny/error\";\nimport { 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 { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createElasticsearchEntity } from \"~/definitions/elasticsearch\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"~/elasticsearch/indices\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\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 {\n attributes,\n table: tableName,\n esTable: esTableName,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = 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 * Elasticsearch field definitions for the submission record.\n */\n submissionElasticsearchFields(),\n /**\n * Elasticsearch field definitions for the form record.\n */\n formElasticsearchFields(),\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Built-in Elasticsearch index plugins\n */\n elasticsearchIndexPlugins()\n ]);\n\n const table = createTable({\n tableName,\n documentClient\n });\n\n const esTable = createElasticsearchTable({\n tableName: esTableName,\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 * Elasticsearch entities.\n */\n esForm: createElasticsearchEntity({\n entityName: ENTITIES.ES_FORM,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_FORM] : {}\n }),\n esSubmission: createElasticsearchEntity({\n entityName: ENTITIES.ES_SUBMISSION,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_SUBMISSION] : {}\n })\n };\n\n return {\n init: async context => {\n context.i18n.locales.onLocaleBeforeCreate.subscribe(async ({ locale, tenant }) => {\n await createElasticsearchIndex({\n elasticsearch,\n plugins,\n tenant,\n locale: locale.code\n });\n });\n },\n upgrade: null,\n getTable: () => table,\n getEsTable: () => esTable,\n getEntities: () => entities,\n ...createSystemStorageOperations({\n table,\n entity: entities.system\n }),\n ...createSettingsStorageOperations({\n table,\n entity: entities.settings\n }),\n ...createFormStorageOperations({\n elasticsearch,\n table,\n entity: entities.form,\n esEntity: entities.esForm,\n plugins\n }),\n ...createSubmissionStorageOperations({\n elasticsearch,\n table,\n entity: entities.submission,\n esEntity: entities.esSubmission,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;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,I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,CAA0CC,SAA1C,CAAoD,OAAO;QAAEC,MAAF;QAAUC;MAAV,CAAP,KAA8B;QAC9E,MAAM,IAAAC,kDAAA,EAAyB;UAC3B5C,aAD2B;UAE3BC,OAF2B;UAG3B0C,MAH2B;UAI3BD,MAAM,EAAEA,MAAM,CAACG;QAJY,CAAzB,CAAN;MAMH,CAPD;IAQH,CAVL;IAWIC,OAAO,EAAE,IAXb;IAYIC,QAAQ,EAAE,MAAMpD,KAZpB;IAaIqD,UAAU,EAAE,MAAMnD,OAbtB;IAcIoD,WAAW,EAAE,MAAMjC;EAdvB,GAeO,IAAAkC,sCAAA,EAA8B;IAC7BvD,KAD6B;IAE7BwD,MAAM,EAAEnC,QAAQ,CAACS;EAFY,CAA9B,CAfP,GAmBO,IAAA2B,0CAAA,EAAgC;IAC/BzD,KAD+B;IAE/BwD,MAAM,EAAEnC,QAAQ,CAACY;EAFc,CAAhC,CAnBP,GAuBO,IAAAyB,kCAAA,EAA4B;IAC3BrD,aAD2B;IAE3BL,KAF2B;IAG3BwD,MAAM,EAAEnC,QAAQ,CAACC,IAHU;IAI3BqC,QAAQ,EAAEtC,QAAQ,CAACe,MAJQ;IAK3B9B;EAL2B,CAA5B,CAvBP,GA8BO,IAAAsD,8CAAA,EAAkC;IACjCvD,aADiC;IAEjCL,KAFiC;IAGjCwD,MAAM,EAAEnC,QAAQ,CAACM,UAHgB;IAIjCgC,QAAQ,EAAEtC,QAAQ,CAACkB,YAJc;IAKjCjC;EALiC,CAAlC,CA9BP;AAsCH,CAlIM"}
|
|
@@ -1,21 +1,15 @@
|
|
|
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.createFormElasticType = exports.createElasticsearchBody = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _sort = require("@webiny/api-elasticsearch/sort");
|
|
15
|
-
|
|
16
|
-
var _limit = require("@webiny/api-elasticsearch/limit");
|
|
17
|
-
|
|
18
|
-
var _ElasticsearchQueryBuilderOperatorPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
12
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
19
13
|
|
|
20
14
|
var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
|
|
21
15
|
|
|
@@ -25,12 +19,6 @@ var _FormElasticsearchBodyModifierPlugin = require("../../plugins/FormElasticsea
|
|
|
25
19
|
|
|
26
20
|
var _FormElasticsearchQueryModifierPlugin = require("../../plugins/FormElasticsearchQueryModifierPlugin");
|
|
27
21
|
|
|
28
|
-
var _where = require("@webiny/api-elasticsearch/where");
|
|
29
|
-
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
31
|
-
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
33
|
-
|
|
34
22
|
const createFormElasticType = () => {
|
|
35
23
|
return "fb.form";
|
|
36
24
|
};
|
|
@@ -65,12 +53,8 @@ const createElasticsearchQuery = params => {
|
|
|
65
53
|
* Be aware that, if having more registered operator plugins of same type, the last one will be used.
|
|
66
54
|
*/
|
|
67
55
|
|
|
68
|
-
const operatorPlugins =
|
|
69
|
-
|
|
70
|
-
return acc;
|
|
71
|
-
}, {});
|
|
72
|
-
|
|
73
|
-
const where = _objectSpread({}, initialWhere);
|
|
56
|
+
const operatorPlugins = (0, _apiElasticsearch.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
|
|
57
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
74
58
|
/**
|
|
75
59
|
* !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
|
|
76
60
|
*
|
|
@@ -78,10 +62,9 @@ const createElasticsearchQuery = params => {
|
|
|
78
62
|
* No need for the tenant filtering otherwise as each index is for single tenant.
|
|
79
63
|
*/
|
|
80
64
|
|
|
81
|
-
|
|
82
65
|
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
83
66
|
|
|
84
|
-
if (sharedIndex) {
|
|
67
|
+
if (sharedIndex && where.tenant) {
|
|
85
68
|
query.must.push({
|
|
86
69
|
term: {
|
|
87
70
|
"tenant.keyword": where.tenant
|
|
@@ -109,7 +92,7 @@ const createElasticsearchQuery = params => {
|
|
|
109
92
|
* We apply other conditions as they are passed via the where value.
|
|
110
93
|
*/
|
|
111
94
|
|
|
112
|
-
(0,
|
|
95
|
+
(0, _apiElasticsearch.applyWhere)({
|
|
113
96
|
query,
|
|
114
97
|
where,
|
|
115
98
|
fields: fieldPlugins,
|
|
@@ -130,11 +113,11 @@ const createElasticsearchBody = params => {
|
|
|
130
113
|
acc[plugin.field] = plugin;
|
|
131
114
|
return acc;
|
|
132
115
|
}, {});
|
|
133
|
-
const limit = (0,
|
|
134
|
-
const query = createElasticsearchQuery(
|
|
116
|
+
const limit = (0, _apiElasticsearch.createLimit)(initialLimit, 100);
|
|
117
|
+
const query = createElasticsearchQuery((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
135
118
|
fieldPlugins
|
|
136
119
|
}));
|
|
137
|
-
const sort = (0,
|
|
120
|
+
const sort = (0, _apiElasticsearch.createSort)({
|
|
138
121
|
sort: initialSort,
|
|
139
122
|
fieldPlugins
|
|
140
123
|
});
|
|
@@ -159,7 +142,7 @@ const createElasticsearchBody = params => {
|
|
|
159
142
|
query: {
|
|
160
143
|
constant_score: {
|
|
161
144
|
filter: {
|
|
162
|
-
bool:
|
|
145
|
+
bool: (0, _objectSpread2.default)({}, query)
|
|
163
146
|
}
|
|
164
147
|
}
|
|
165
148
|
},
|
|
@@ -170,7 +153,7 @@ const createElasticsearchBody = params => {
|
|
|
170
153
|
* Which is correct in some cases. In our case, it is not.
|
|
171
154
|
* https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html
|
|
172
155
|
*/
|
|
173
|
-
search_after: (0,
|
|
156
|
+
search_after: (0, _apiElasticsearch.decodeCursor)(after),
|
|
174
157
|
sort
|
|
175
158
|
};
|
|
176
159
|
const bodyModifiers = plugins.byType(_FormElasticsearchBodyModifierPlugin.FormElasticsearchBodyModifierPlugin.type);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFormElasticType","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","getElasticsearchOperatorPluginsByLocale","locale","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","applyWhere","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","byType","FormElasticsearchFieldPlugin","type","reduce","acc","plugin","field","createLimit","createSort","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","decodeCursor","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchBody.ts"],"sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport {\n decodeCursor,\n getElasticsearchOperatorPluginsByLocale,\n applyWhere,\n createLimit,\n createSort\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\nimport { FormElasticsearchSortModifierPlugin } from \"~/plugins/FormElasticsearchSortModifierPlugin\";\nimport { FormElasticsearchBodyModifierPlugin } from \"~/plugins/FormElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListFormsParams } from \"@webiny/api-form-builder/types\";\nimport { FormElasticsearchQueryModifierPlugin } from \"~/plugins/FormElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\nexport const createFormElasticType = (): string => {\n return \"fb.form\";\n};\n\nconst createInitialQueryValue = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [\n /**\n * We add the __type filtering in the initial query because it must be applied.\n */\n {\n term: {\n \"__type.keyword\": createFormElasticType()\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, FormElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchQueryParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue();\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, initialWhere.locale);\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n * No need for the tenant filtering otherwise as each index is for single tenant.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({\n term: {\n \"tenant.keyword\": where.tenant\n }\n });\n }\n /**\n * Remove tenant so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where.tenant;\n /**\n * Add the locale to filtering.\n */\n query.must.push({\n term: {\n \"locale.keyword\": where.locale as string\n }\n });\n delete where.locale;\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: FormBuilderStorageOperationsListFormsParams[\"where\"];\n limit: number;\n after?: string;\n sort: string[];\n}\n\nexport const createElasticsearchBody = (params: CreateElasticsearchBodyParams): esSearchBody => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<FormElasticsearchFieldPlugin>(FormElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, FormElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<FormElasticsearchQueryModifierPlugin>(\n FormElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<FormElasticsearchSortModifierPlugin>(\n FormElasticsearchSortModifierPlugin.type\n );\n\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after) as any,\n sort\n };\n\n const bodyModifiers = plugins.byType<FormElasticsearchBodyModifierPlugin>(\n FormElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAQA;;AACA;;AACA;;AAEA;;AAGO,MAAMA,qBAAqB,GAAG,MAAc;EAC/C,OAAO,SAAP;AACH,CAFM;;;;AAIP,MAAMC,uBAAuB,GAAG,MAAoC;EAChE,OAAO;IACHC,IAAI,EAAE;IACF;AACZ;AACA;IACY;MACIC,IAAI,EAAE;QACF,kBAAkBH,qBAAqB;MADrC;IADV,CAJE,CADH;IAWHI,QAAQ,EAAE,EAXP;IAYHC,MAAM,EAAE,EAZL;IAaHC,MAAM,EAAE;EAbL,CAAP;AAeH,CAhBD;;AAsBA,MAAMC,wBAAwB,GAAIC,MAAD,IAA4C;EACzE,MAAM;IAAEC,OAAF;IAAWC,KAAK,EAAEC,YAAlB;IAAgCC;EAAhC,IAAiDJ,MAAvD;EACA,MAAMK,KAAK,GAAGZ,uBAAuB,EAArC;EACA;AACJ;AACA;;EACI,MAAMa,eAAe,GAAG,IAAAC,yDAAA,EAAwCN,OAAxC,EAAiDE,YAAY,CAACK,MAA9D,CAAxB;EAEA,MAAMN,KAAoE,mCACnEC,YADmE,CAA1E;EAGA;AACJ;AACA;AACA;AACA;AACA;;EACI,MAAMM,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,4BAAZ,KAA6C,MAAjE;;EACA,IAAIH,WAAW,IAAIP,KAAK,CAACW,MAAzB,EAAiC;IAC7BR,KAAK,CAACX,IAAN,CAAWoB,IAAX,CAAgB;MACZnB,IAAI,EAAE;QACF,kBAAkBO,KAAK,CAACW;MADtB;IADM,CAAhB;EAKH;EACD;AACJ;AACA;AACA;;;EACI,OAAOX,KAAK,CAACW,MAAb;EACA;AACJ;AACA;;EACIR,KAAK,CAACX,IAA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AAK,MAAMG,MAAX,IAAqBO,aAArB,EAAoC;IAChCP,MAAM,CAACS,UAAP,CAAkB;MACdjB;IADc,CAAlB;EAGH;;EAED,MAAMkB,IAAI,GAAG;IACTlC,KAAK,EAAE;MACHmC,cAAc,EAAE;QACZ1C,MAAM,EAAE;UACJ2C,IAAI,kCACGpC,KADH;QADA;MADI;IADb,CADE;IAUTqC,IAAI,EAAEvB,KAAK,GAAG,CAVL;;IAWT;AACR;AACA;AACA;AACA;IACQwB,YAAY,EAAE,IAAAC,8BAAA,EAAarB,KAAb,CAhBL;IAiBTF;EAjBS,CAAb;EAoBA,MAAMwB,aAAa,GAAG5C,OAAO,CAACuB,MAAR,CAClBsB,wEAAA,CAAoCpB,IADlB,CAAtB;;EAIA,KAAK,MAAMG,MAAX,IAAqBgB,aAArB,EAAoC;IAChChB,MAAM,CAACkB,UAAP,CAAkB;MACdR;IADc,CAAlB;EAGH;;EAED,OAAOA,IAAP;AACH,CA1EM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchFieldPlugin","field","unmappedType","path","ALL"],"sources":["elasticsearchFields.ts"],"sourcesContent":["import { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\n\nexport default () => [\n new FormElasticsearchFieldPlugin({\n field: \"createdOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"savedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"publishedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"ownedBy\",\n path: \"ownedBy.id\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n }),\n /**\n * Always add the ALL fields plugin because of the keyword/path build.\n */\n new FormElasticsearchFieldPlugin({\n field: FormElasticsearchFieldPlugin.ALL\n })\n];\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,WADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CADiB,EAKjB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,SADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CALiB,EASjB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,aADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CATiB,EAajB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,SADsB;EAE7BE,IAAI,EAAE;AAFuB,CAAjC,CAbiB,EAiBjB,IAAIH,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,WADsB;EAE7BE,IAAI,EAAE;AAFuB,CAAjC,CAjBiB;AAqBjB;AACJ;AACA;AACI,IAAIH,0DAAJ,CAAiC;EAC7BC,KAAK,EAAED,0DAAA,CAA6BI;AADP,CAAjC,CAxBiB,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormDynamoDbFieldPlugin","field","type"],"sources":["fields.ts"],"sourcesContent":["import { FormDynamoDbFieldPlugin } from \"~/plugins/FormDynamoDbFieldPlugin\";\n\nexport default () => [\n new FormDynamoDbFieldPlugin({\n field: \"publishedOn\",\n type: \"date\"\n })\n];\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,aADiB;EAExBC,IAAI,EAAE;AAFkB,CAA5B,CADiB,C"}
|
|
@@ -7,11 +7,11 @@ export declare type DbRecord<T = any> = T & {
|
|
|
7
7
|
SK: string;
|
|
8
8
|
TYPE: string;
|
|
9
9
|
};
|
|
10
|
-
export interface
|
|
10
|
+
export interface CreateFormStorageOperationsParams {
|
|
11
11
|
entity: Entity<any>;
|
|
12
12
|
esEntity: Entity<any>;
|
|
13
13
|
table: Table;
|
|
14
14
|
elasticsearch: Client;
|
|
15
15
|
plugins: PluginsContainer;
|
|
16
16
|
}
|
|
17
|
-
export declare const createFormStorageOperations: (params:
|
|
17
|
+
export declare const createFormStorageOperations: (params: CreateFormStorageOperationsParams) => FormBuilderFormStorageOperations;
|
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 _query = require("@webiny/db-dynamodb/utils/query");
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
|
17
17
|
|
|
18
18
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
19
19
|
|
|
20
|
-
var _configurations =
|
|
20
|
+
var _configurations = require("../../configurations");
|
|
21
21
|
|
|
22
22
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
23
23
|
|
|
@@ -29,11 +29,7 @@ var _utils = require("@webiny/utils");
|
|
|
29
29
|
|
|
30
30
|
var _elasticsearchBody = require("./elasticsearchBody");
|
|
31
31
|
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
-
|
|
36
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
32
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
37
33
|
|
|
38
34
|
const getESDataForLatestRevision = form => ({
|
|
39
35
|
__type: (0, _elasticsearchBody.createFormElasticType)(),
|
|
@@ -114,9 +110,9 @@ const createFormStorageOperations = params => {
|
|
|
114
110
|
PK: createFormPartitionKey(form),
|
|
115
111
|
SK: createLatestSortKey()
|
|
116
112
|
};
|
|
117
|
-
const items = [entity.putBatch(
|
|
113
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
118
114
|
TYPE: createFormType()
|
|
119
|
-
}, revisionKeys)), entity.putBatch(
|
|
115
|
+
}, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
120
116
|
TYPE: createFormLatestType()
|
|
121
117
|
}, latestKeys))];
|
|
122
118
|
|
|
@@ -136,11 +132,12 @@ const createFormStorageOperations = params => {
|
|
|
136
132
|
try {
|
|
137
133
|
const {
|
|
138
134
|
index
|
|
139
|
-
} = _configurations.
|
|
140
|
-
tenant: form.tenant
|
|
135
|
+
} = _configurations.configurations.es({
|
|
136
|
+
tenant: form.tenant,
|
|
137
|
+
locale: form.locale
|
|
141
138
|
});
|
|
142
139
|
|
|
143
|
-
await esEntity.put(
|
|
140
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
144
141
|
index,
|
|
145
142
|
data: getESDataForLatestRevision(form),
|
|
146
143
|
TYPE: createFormType()
|
|
@@ -169,9 +166,9 @@ const createFormStorageOperations = params => {
|
|
|
169
166
|
PK: createFormPartitionKey(form),
|
|
170
167
|
SK: createLatestSortKey()
|
|
171
168
|
};
|
|
172
|
-
const items = [entity.putBatch(
|
|
169
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
173
170
|
TYPE: createFormType()
|
|
174
|
-
})), entity.putBatch(
|
|
171
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
175
172
|
TYPE: createFormLatestType()
|
|
176
173
|
}))];
|
|
177
174
|
|
|
@@ -193,11 +190,12 @@ const createFormStorageOperations = params => {
|
|
|
193
190
|
try {
|
|
194
191
|
const {
|
|
195
192
|
index
|
|
196
|
-
} = _configurations.
|
|
197
|
-
tenant: form.tenant
|
|
193
|
+
} = _configurations.configurations.es({
|
|
194
|
+
tenant: form.tenant,
|
|
195
|
+
locale: form.locale
|
|
198
196
|
});
|
|
199
197
|
|
|
200
|
-
await esEntity.put(
|
|
198
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
201
199
|
index,
|
|
202
200
|
data: getESDataForLatestRevision(form),
|
|
203
201
|
TYPE: createFormLatestType()
|
|
@@ -241,12 +239,12 @@ const createFormStorageOperations = params => {
|
|
|
241
239
|
}
|
|
242
240
|
});
|
|
243
241
|
const isLatestForm = latestForm ? latestForm.id === form.id : false;
|
|
244
|
-
const items = [entity.putBatch(
|
|
242
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
245
243
|
TYPE: createFormType()
|
|
246
244
|
}, revisionKeys))];
|
|
247
245
|
|
|
248
246
|
if (isLatestForm) {
|
|
249
|
-
items.push(entity.putBatch(
|
|
247
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
250
248
|
TYPE: createFormLatestType()
|
|
251
249
|
}, latestKeys)));
|
|
252
250
|
}
|
|
@@ -277,11 +275,12 @@ const createFormStorageOperations = params => {
|
|
|
277
275
|
try {
|
|
278
276
|
const {
|
|
279
277
|
index
|
|
280
|
-
} = _configurations.
|
|
281
|
-
tenant: form.tenant
|
|
278
|
+
} = _configurations.configurations.es({
|
|
279
|
+
tenant: form.tenant,
|
|
280
|
+
locale: form.locale
|
|
282
281
|
});
|
|
283
282
|
|
|
284
|
-
await esEntity.put(
|
|
283
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
285
284
|
index,
|
|
286
285
|
data: getESDataForLatestRevision(form),
|
|
287
286
|
TYPE: createFormLatestType()
|
|
@@ -369,17 +368,17 @@ const createFormStorageOperations = params => {
|
|
|
369
368
|
sort,
|
|
370
369
|
limit: limit + 1,
|
|
371
370
|
where,
|
|
372
|
-
after: (0,
|
|
371
|
+
after: (0, _apiElasticsearch.decodeCursor)(after)
|
|
373
372
|
});
|
|
374
373
|
|
|
375
|
-
const esConfig = _configurations.
|
|
376
|
-
tenant: where.tenant
|
|
374
|
+
const esConfig = _configurations.configurations.es({
|
|
375
|
+
tenant: where.tenant,
|
|
376
|
+
locale: where.locale
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
-
const query =
|
|
379
|
+
const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
|
|
380
380
|
body
|
|
381
381
|
});
|
|
382
|
-
|
|
383
382
|
let response;
|
|
384
383
|
|
|
385
384
|
try {
|
|
@@ -413,7 +412,7 @@ const createFormStorageOperations = params => {
|
|
|
413
412
|
const meta = {
|
|
414
413
|
hasMoreItems,
|
|
415
414
|
totalCount: total.value,
|
|
416
|
-
cursor: items.length > 0 ? (0,
|
|
415
|
+
cursor: items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
417
416
|
};
|
|
418
417
|
return {
|
|
419
418
|
items,
|
|
@@ -454,11 +453,10 @@ const createFormStorageOperations = params => {
|
|
|
454
453
|
});
|
|
455
454
|
}
|
|
456
455
|
|
|
457
|
-
const where =
|
|
456
|
+
const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
|
|
458
457
|
id: undefined,
|
|
459
458
|
formId: undefined
|
|
460
459
|
});
|
|
461
|
-
|
|
462
460
|
const filteredItems = (0, _filter.filterItems)({
|
|
463
461
|
plugins,
|
|
464
462
|
items,
|
|
@@ -466,7 +464,7 @@ const createFormStorageOperations = params => {
|
|
|
466
464
|
fields: formDynamoDbFields
|
|
467
465
|
});
|
|
468
466
|
|
|
469
|
-
if (
|
|
467
|
+
if (!sort || sort.length === 0) {
|
|
470
468
|
return filteredItems;
|
|
471
469
|
}
|
|
472
470
|
|
|
@@ -573,14 +571,14 @@ const createFormStorageOperations = params => {
|
|
|
573
571
|
}).shift();
|
|
574
572
|
|
|
575
573
|
if (previouslyPublishedForm) {
|
|
576
|
-
items.push(entity.putBatch(
|
|
574
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), {}, {
|
|
577
575
|
PK: createFormPartitionKey(previouslyPublishedForm),
|
|
578
576
|
SK: createLatestPublishedSortKey(),
|
|
579
577
|
TYPE: createFormLatestPublishedType()
|
|
580
578
|
})));
|
|
581
579
|
} else {
|
|
582
580
|
items.push(entity.deleteBatch({
|
|
583
|
-
PK: createFormPartitionKey(
|
|
581
|
+
PK: createFormPartitionKey(form),
|
|
584
582
|
SK: createLatestPublishedSortKey()
|
|
585
583
|
}));
|
|
586
584
|
}
|
|
@@ -590,18 +588,19 @@ const createFormStorageOperations = params => {
|
|
|
590
588
|
*/
|
|
591
589
|
|
|
592
590
|
|
|
593
|
-
if (isLatest) {
|
|
594
|
-
items.push(entity.putBatch(
|
|
591
|
+
if (isLatest && previous) {
|
|
592
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
|
|
595
593
|
TYPE: createFormLatestType()
|
|
596
594
|
})));
|
|
597
595
|
|
|
598
596
|
const {
|
|
599
597
|
index
|
|
600
|
-
} = _configurations.
|
|
601
|
-
tenant: previous.tenant
|
|
598
|
+
} = _configurations.configurations.es({
|
|
599
|
+
tenant: previous.tenant,
|
|
600
|
+
locale: previous.locale
|
|
602
601
|
});
|
|
603
602
|
|
|
604
|
-
esDataItem =
|
|
603
|
+
esDataItem = (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
605
604
|
index
|
|
606
605
|
}, latestKeys), {}, {
|
|
607
606
|
data: getESDataForLatestRevision(previous)
|
|
@@ -691,9 +690,9 @@ const createFormStorageOperations = params => {
|
|
|
691
690
|
* Update revision and latest published records
|
|
692
691
|
*/
|
|
693
692
|
|
|
694
|
-
const items = [entity.putBatch(
|
|
693
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
695
694
|
TYPE: createFormType()
|
|
696
|
-
})), entity.putBatch(
|
|
695
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
|
|
697
696
|
TYPE: createFormLatestPublishedType()
|
|
698
697
|
}))];
|
|
699
698
|
/**
|
|
@@ -701,7 +700,7 @@ const createFormStorageOperations = params => {
|
|
|
701
700
|
*/
|
|
702
701
|
|
|
703
702
|
if (isLatestForm) {
|
|
704
|
-
items.push(entity.putBatch(
|
|
703
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
705
704
|
TYPE: createFormLatestType()
|
|
706
705
|
})));
|
|
707
706
|
}
|
|
@@ -728,14 +727,15 @@ const createFormStorageOperations = params => {
|
|
|
728
727
|
|
|
729
728
|
const {
|
|
730
729
|
index
|
|
731
|
-
} = _configurations.
|
|
732
|
-
tenant: form.tenant
|
|
730
|
+
} = _configurations.configurations.es({
|
|
731
|
+
tenant: form.tenant,
|
|
732
|
+
locale: form.locale
|
|
733
733
|
});
|
|
734
734
|
|
|
735
735
|
const esData = getESDataForLatestRevision(form);
|
|
736
736
|
|
|
737
737
|
try {
|
|
738
|
-
await esEntity.put(
|
|
738
|
+
await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
739
739
|
index,
|
|
740
740
|
TYPE: createFormLatestType(),
|
|
741
741
|
data: esData
|
|
@@ -800,7 +800,7 @@ const createFormStorageOperations = params => {
|
|
|
800
800
|
});
|
|
801
801
|
const isLatest = latestForm ? latestForm.id === form.id : false;
|
|
802
802
|
const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
|
|
803
|
-
const items = [entity.putBatch(
|
|
803
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
804
804
|
TYPE: createFormType()
|
|
805
805
|
}))];
|
|
806
806
|
let esData = undefined;
|
|
@@ -828,7 +828,7 @@ const createFormStorageOperations = params => {
|
|
|
828
828
|
const previouslyPublishedRevision = revisions.shift();
|
|
829
829
|
|
|
830
830
|
if (previouslyPublishedRevision) {
|
|
831
|
-
items.push(entity.putBatch(
|
|
831
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
|
|
832
832
|
TYPE: createFormLatestPublishedType()
|
|
833
833
|
})));
|
|
834
834
|
} else {
|
|
@@ -862,12 +862,13 @@ const createFormStorageOperations = params => {
|
|
|
862
862
|
|
|
863
863
|
const {
|
|
864
864
|
index
|
|
865
|
-
} = _configurations.
|
|
866
|
-
tenant: form.tenant
|
|
865
|
+
} = _configurations.configurations.es({
|
|
866
|
+
tenant: form.tenant,
|
|
867
|
+
locale: form.locale
|
|
867
868
|
});
|
|
868
869
|
|
|
869
870
|
try {
|
|
870
|
-
await esEntity.put(
|
|
871
|
+
await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
871
872
|
index,
|
|
872
873
|
TYPE: createFormLatestType(),
|
|
873
874
|
data: esData
|