@webiny/api-form-builder-so-ddb-es 0.0.0-ee-vpcs.549378cf03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/configurations.d.ts +11 -0
- package/configurations.js +50 -0
- package/configurations.js.map +1 -0
- package/definitions/elasticsearch.d.ts +9 -0
- package/definitions/elasticsearch.js +43 -0
- package/definitions/elasticsearch.js.map +1 -0
- package/definitions/form.d.ts +9 -0
- package/definitions/form.js +100 -0
- package/definitions/form.js.map +1 -0
- package/definitions/settings.d.ts +9 -0
- package/definitions/settings.js +49 -0
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.d.ts +9 -0
- package/definitions/submission.js +70 -0
- package/definitions/submission.js.map +1 -0
- package/definitions/system.d.ts +9 -0
- package/definitions/system.js +40 -0
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +8 -0
- package/definitions/table.js +23 -0
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +8 -0
- package/definitions/tableElasticsearch.js +23 -0
- 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.d.ts +2 -0
- package/index.js +191 -0
- package/index.js.map +1 -0
- package/operations/form/elasticsearchBody.d.ts +13 -0
- package/operations/form/elasticsearchBody.js +170 -0
- package/operations/form/elasticsearchBody.js.map +1 -0
- package/operations/form/elasticsearchFields.d.ts +3 -0
- package/operations/form/elasticsearchFields.js +33 -0
- package/operations/form/elasticsearchFields.js.map +1 -0
- package/operations/form/fields.d.ts +3 -0
- package/operations/form/fields.js +15 -0
- package/operations/form/fields.js.map +1 -0
- package/operations/form/index.d.ts +17 -0
- package/operations/form/index.js +904 -0
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +7 -0
- package/operations/settings/index.js +118 -0
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/elasticsearchBody.d.ts +13 -0
- package/operations/submission/elasticsearchBody.js +187 -0
- package/operations/submission/elasticsearchBody.js.map +1 -0
- package/operations/submission/elasticsearchFields.d.ts +3 -0
- package/operations/submission/elasticsearchFields.js +30 -0
- package/operations/submission/elasticsearchFields.js.map +1 -0
- package/operations/submission/index.d.ts +12 -0
- package/operations/submission/index.js +335 -0
- package/operations/submission/index.js.map +1 -0
- package/operations/system/index.d.ts +7 -0
- package/operations/system/index.js +101 -0
- package/operations/system/index.js.map +1 -0
- package/package.json +63 -0
- package/plugins/FormDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/FormDynamoDbFieldPlugin.js +17 -0
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.js +17 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchFieldPlugin.js +17 -0
- 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 +4 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.js +17 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchSortModifierPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchSortModifierPlugin.js +17 -0
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
- package/types.d.ts +66 -0
- package/types.js +17 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.base = void 0;
|
|
7
|
+
|
|
8
|
+
var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
|
|
9
|
+
|
|
10
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
11
|
+
|
|
12
|
+
const base = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
|
|
13
|
+
body: (0, _apiElasticsearch.getBaseConfiguration)()
|
|
14
|
+
});
|
|
15
|
+
exports.base = base;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["base","FormElasticsearchIndexPlugin","body","getBaseConfiguration"],"sources":["base.ts"],"sourcesContent":["import { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\nimport { getBaseConfiguration } from \"@webiny/api-elasticsearch\";\n\nexport const base = new FormElasticsearchIndexPlugin({\n body: getBaseConfiguration()\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,IAAI,GAAG,IAAIC,0DAAJ,CAAiC;EACjDC,IAAI,EAAE,IAAAC,sCAAA;AAD2C,CAAjC,CAAb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const elasticsearchIndexPlugins: () => import("../../plugins/FormElasticsearchIndexPlugin").FormElasticsearchIndexPlugin[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.elasticsearchIndexPlugins = void 0;
|
|
7
|
+
|
|
8
|
+
var _base = require("./base");
|
|
9
|
+
|
|
10
|
+
var _japanese = require("./japanese");
|
|
11
|
+
|
|
12
|
+
const elasticsearchIndexPlugins = () => {
|
|
13
|
+
return [_base.base, _japanese.japanese];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.elasticsearchIndexPlugins = elasticsearchIndexPlugins;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["elasticsearchIndexPlugins","base","japanese"],"sources":["index.ts"],"sourcesContent":["import { base } from \"./base\";\nimport { japanese } from \"./japanese\";\n\nexport const elasticsearchIndexPlugins = () => {\n return [base, japanese];\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,CAACC,UAAD,EAAOC,kBAAP,CAAP;AACH,CAFM"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.japanese = void 0;
|
|
7
|
+
|
|
8
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
9
|
+
|
|
10
|
+
var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
|
|
11
|
+
|
|
12
|
+
const japanese = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
|
|
13
|
+
body: (0, _apiElasticsearch.getJapaneseConfiguration)(),
|
|
14
|
+
locales: ["ja", "ja-jp"]
|
|
15
|
+
});
|
|
16
|
+
exports.japanese = japanese;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["japanese","FormElasticsearchIndexPlugin","body","getJapaneseConfiguration","locales"],"sources":["japanese.ts"],"sourcesContent":["import { getJapaneseConfiguration } from \"@webiny/api-elasticsearch\";\nimport { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\n\nexport const japanese = new FormElasticsearchIndexPlugin({\n body: getJapaneseConfiguration(),\n locales: [\"ja\", \"ja-jp\"]\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,QAAQ,GAAG,IAAIC,0DAAJ,CAAiC;EACrDC,IAAI,EAAE,IAAAC,0CAAA,GAD+C;EAErDC,OAAO,EAAE,CAAC,IAAD,EAAO,OAAP;AAF4C,CAAjC,CAAjB"}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createFormBuilderStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
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"));
|
|
17
|
+
|
|
18
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
+
|
|
20
|
+
var _types = require("./types");
|
|
21
|
+
|
|
22
|
+
var _table = require("./definitions/table");
|
|
23
|
+
|
|
24
|
+
var _form = require("./definitions/form");
|
|
25
|
+
|
|
26
|
+
var _submission = require("./definitions/submission");
|
|
27
|
+
|
|
28
|
+
var _system = require("./definitions/system");
|
|
29
|
+
|
|
30
|
+
var _settings = require("./definitions/settings");
|
|
31
|
+
|
|
32
|
+
var _system2 = require("./operations/system");
|
|
33
|
+
|
|
34
|
+
var _submission2 = require("./operations/submission");
|
|
35
|
+
|
|
36
|
+
var _settings2 = require("./operations/settings");
|
|
37
|
+
|
|
38
|
+
var _form2 = require("./operations/form");
|
|
39
|
+
|
|
40
|
+
var _tableElasticsearch = require("./definitions/tableElasticsearch");
|
|
41
|
+
|
|
42
|
+
var _plugins = require("@webiny/plugins");
|
|
43
|
+
|
|
44
|
+
var _elasticsearch = require("./definitions/elasticsearch");
|
|
45
|
+
|
|
46
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
47
|
+
|
|
48
|
+
var _indices = require("./elasticsearch/indices");
|
|
49
|
+
|
|
50
|
+
var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
|
|
51
|
+
|
|
52
|
+
const reservedFields = ["PK", "SK", "index", "data", "TYPE", "__type", "GSI1_PK", "GSI1_SK"];
|
|
53
|
+
|
|
54
|
+
const isReserved = name => {
|
|
55
|
+
if (reservedFields.includes(name) === false) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
throw new _error.default(`Attribute name "${name}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
|
|
60
|
+
name
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const createFormBuilderStorageOperations = params => {
|
|
65
|
+
const {
|
|
66
|
+
attributes,
|
|
67
|
+
table: tableName,
|
|
68
|
+
esTable: esTableName,
|
|
69
|
+
documentClient,
|
|
70
|
+
elasticsearch,
|
|
71
|
+
plugins: userPlugins
|
|
72
|
+
} = params;
|
|
73
|
+
|
|
74
|
+
if (attributes) {
|
|
75
|
+
Object.values(attributes).forEach(attrs => {
|
|
76
|
+
Object.keys(attrs).forEach(isReserved);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const plugins = new _plugins.PluginsContainer([
|
|
81
|
+
/**
|
|
82
|
+
* User defined plugins.
|
|
83
|
+
*/
|
|
84
|
+
userPlugins || [],
|
|
85
|
+
/**
|
|
86
|
+
* Elasticsearch field definitions for the submission record.
|
|
87
|
+
*/
|
|
88
|
+
(0, _elasticsearchFields2.default)(),
|
|
89
|
+
/**
|
|
90
|
+
* Elasticsearch field definitions for the form record.
|
|
91
|
+
*/
|
|
92
|
+
(0, _elasticsearchFields.default)(),
|
|
93
|
+
/**
|
|
94
|
+
* DynamoDB filter plugins for the where conditions.
|
|
95
|
+
*/
|
|
96
|
+
(0, _filters.default)(),
|
|
97
|
+
/**
|
|
98
|
+
* Elasticsearch operators.
|
|
99
|
+
*/
|
|
100
|
+
(0, _apiElasticsearch.getElasticsearchOperators)(),
|
|
101
|
+
/**
|
|
102
|
+
* Built-in Elasticsearch index plugins
|
|
103
|
+
*/
|
|
104
|
+
(0, _indices.elasticsearchIndexPlugins)()]);
|
|
105
|
+
const table = (0, _table.createTable)({
|
|
106
|
+
tableName,
|
|
107
|
+
documentClient
|
|
108
|
+
});
|
|
109
|
+
const esTable = (0, _tableElasticsearch.createElasticsearchTable)({
|
|
110
|
+
tableName: esTableName,
|
|
111
|
+
documentClient
|
|
112
|
+
});
|
|
113
|
+
const entities = {
|
|
114
|
+
/**
|
|
115
|
+
* Regular entities.
|
|
116
|
+
*/
|
|
117
|
+
form: (0, _form.createFormEntity)({
|
|
118
|
+
entityName: _types.ENTITIES.FORM,
|
|
119
|
+
table,
|
|
120
|
+
attributes: attributes ? attributes[_types.ENTITIES.FORM] : {}
|
|
121
|
+
}),
|
|
122
|
+
submission: (0, _submission.createSubmissionEntity)({
|
|
123
|
+
entityName: _types.ENTITIES.SUBMISSION,
|
|
124
|
+
table,
|
|
125
|
+
attributes: attributes ? attributes[_types.ENTITIES.SUBMISSION] : {}
|
|
126
|
+
}),
|
|
127
|
+
system: (0, _system.createSystemEntity)({
|
|
128
|
+
entityName: _types.ENTITIES.SYSTEM,
|
|
129
|
+
table,
|
|
130
|
+
attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
|
|
131
|
+
}),
|
|
132
|
+
settings: (0, _settings.createSettingsEntity)({
|
|
133
|
+
entityName: _types.ENTITIES.SETTINGS,
|
|
134
|
+
table,
|
|
135
|
+
attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
|
|
136
|
+
}),
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Elasticsearch entities.
|
|
140
|
+
*/
|
|
141
|
+
esForm: (0, _elasticsearch.createElasticsearchEntity)({
|
|
142
|
+
entityName: _types.ENTITIES.ES_FORM,
|
|
143
|
+
table: esTable,
|
|
144
|
+
attributes: attributes ? attributes[_types.ENTITIES.ES_FORM] : {}
|
|
145
|
+
}),
|
|
146
|
+
esSubmission: (0, _elasticsearch.createElasticsearchEntity)({
|
|
147
|
+
entityName: _types.ENTITIES.ES_SUBMISSION,
|
|
148
|
+
table: esTable,
|
|
149
|
+
attributes: attributes ? attributes[_types.ENTITIES.ES_SUBMISSION] : {}
|
|
150
|
+
})
|
|
151
|
+
};
|
|
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,
|
|
156
|
+
tenant
|
|
157
|
+
}) => {
|
|
158
|
+
await (0, _createElasticsearchIndex.createElasticsearchIndex)({
|
|
159
|
+
elasticsearch,
|
|
160
|
+
plugins,
|
|
161
|
+
tenant,
|
|
162
|
+
locale: locale.code
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
upgrade: null,
|
|
167
|
+
getTable: () => table,
|
|
168
|
+
getEsTable: () => esTable,
|
|
169
|
+
getEntities: () => entities
|
|
170
|
+
}, (0, _system2.createSystemStorageOperations)({
|
|
171
|
+
table,
|
|
172
|
+
entity: entities.system
|
|
173
|
+
})), (0, _settings2.createSettingsStorageOperations)({
|
|
174
|
+
table,
|
|
175
|
+
entity: entities.settings
|
|
176
|
+
})), (0, _form2.createFormStorageOperations)({
|
|
177
|
+
elasticsearch,
|
|
178
|
+
table,
|
|
179
|
+
entity: entities.form,
|
|
180
|
+
esEntity: entities.esForm,
|
|
181
|
+
plugins
|
|
182
|
+
})), (0, _submission2.createSubmissionStorageOperations)({
|
|
183
|
+
elasticsearch,
|
|
184
|
+
table,
|
|
185
|
+
entity: entities.submission,
|
|
186
|
+
esEntity: entities.esSubmission,
|
|
187
|
+
plugins
|
|
188
|
+
}));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
exports.createFormBuilderStorageOperations = createFormBuilderStorageOperations;
|
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,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;IACFC,UADE;IAEFC,KAAK,EAAEC,SAFL;IAGFC,OAAO,EAAEC,WAHP;IAIFC,cAJE;IAKFC,aALE;IAMFC,OAAO,EAAEC;EANP,IAOFT,MAPJ;;EASA,IAAIC,UAAJ,EAAgB;IACZS,MAAM,CAACC,MAAP,CAAcV,UAAd,EAA0BW,OAA1B,CAAkCC,KAAK,IAAI;MACvCH,MAAM,CAACI,IAAP,CAAYD,KAAZ,EAAmBD,OAAnB,CAA2BjB,UAA3B;IACH,CAFD;EAGH;;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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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SearchBody as esSearchBody } from "elastic-ts";
|
|
2
|
+
import { FormBuilderStorageOperationsListFormsParams } from "@webiny/api-form-builder/types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
export declare const createFormElasticType: () => string;
|
|
5
|
+
interface CreateElasticsearchBodyParams {
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
where: FormBuilderStorageOperationsListFormsParams["where"];
|
|
8
|
+
limit: number;
|
|
9
|
+
after?: string;
|
|
10
|
+
sort: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const createElasticsearchBody: (params: CreateElasticsearchBodyParams) => esSearchBody;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createFormElasticType = exports.createElasticsearchBody = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
13
|
+
|
|
14
|
+
var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
|
|
15
|
+
|
|
16
|
+
var _FormElasticsearchSortModifierPlugin = require("../../plugins/FormElasticsearchSortModifierPlugin");
|
|
17
|
+
|
|
18
|
+
var _FormElasticsearchBodyModifierPlugin = require("../../plugins/FormElasticsearchBodyModifierPlugin");
|
|
19
|
+
|
|
20
|
+
var _FormElasticsearchQueryModifierPlugin = require("../../plugins/FormElasticsearchQueryModifierPlugin");
|
|
21
|
+
|
|
22
|
+
const createFormElasticType = () => {
|
|
23
|
+
return "fb.form";
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.createFormElasticType = createFormElasticType;
|
|
27
|
+
|
|
28
|
+
const createInitialQueryValue = () => {
|
|
29
|
+
return {
|
|
30
|
+
must: [
|
|
31
|
+
/**
|
|
32
|
+
* We add the __type filtering in the initial query because it must be applied.
|
|
33
|
+
*/
|
|
34
|
+
{
|
|
35
|
+
term: {
|
|
36
|
+
"__type.keyword": createFormElasticType()
|
|
37
|
+
}
|
|
38
|
+
}],
|
|
39
|
+
must_not: [],
|
|
40
|
+
should: [],
|
|
41
|
+
filter: []
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createElasticsearchQuery = params => {
|
|
46
|
+
const {
|
|
47
|
+
plugins,
|
|
48
|
+
where: initialWhere,
|
|
49
|
+
fieldPlugins
|
|
50
|
+
} = params;
|
|
51
|
+
const query = createInitialQueryValue();
|
|
52
|
+
/**
|
|
53
|
+
* Be aware that, if having more registered operator plugins of same type, the last one will be used.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
const operatorPlugins = (0, _apiElasticsearch.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
|
|
57
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
58
|
+
/**
|
|
59
|
+
* !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
|
|
60
|
+
*
|
|
61
|
+
* When ES index is shared between tenants, we need to filter records by tenant ID.
|
|
62
|
+
* No need for the tenant filtering otherwise as each index is for single tenant.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
66
|
+
|
|
67
|
+
if (sharedIndex && where.tenant) {
|
|
68
|
+
query.must.push({
|
|
69
|
+
term: {
|
|
70
|
+
"tenant.keyword": where.tenant
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Remove tenant so it is not applied again later.
|
|
76
|
+
* Possibly tenant is not defined, but just in case, remove it.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
delete where.tenant;
|
|
81
|
+
/**
|
|
82
|
+
* Add the locale to filtering.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
query.must.push({
|
|
86
|
+
term: {
|
|
87
|
+
"locale.keyword": where.locale
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
delete where.locale;
|
|
91
|
+
/**
|
|
92
|
+
* We apply other conditions as they are passed via the where value.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
(0, _apiElasticsearch.applyWhere)({
|
|
96
|
+
query,
|
|
97
|
+
where,
|
|
98
|
+
fields: fieldPlugins,
|
|
99
|
+
operators: operatorPlugins
|
|
100
|
+
});
|
|
101
|
+
return query;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const createElasticsearchBody = params => {
|
|
105
|
+
const {
|
|
106
|
+
plugins,
|
|
107
|
+
where,
|
|
108
|
+
limit: initialLimit,
|
|
109
|
+
sort: initialSort,
|
|
110
|
+
after
|
|
111
|
+
} = params;
|
|
112
|
+
const fieldPlugins = plugins.byType(_FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin.type).reduce((acc, plugin) => {
|
|
113
|
+
acc[plugin.field] = plugin;
|
|
114
|
+
return acc;
|
|
115
|
+
}, {});
|
|
116
|
+
const limit = (0, _apiElasticsearch.createLimit)(initialLimit, 100);
|
|
117
|
+
const query = createElasticsearchQuery((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
118
|
+
fieldPlugins
|
|
119
|
+
}));
|
|
120
|
+
const sort = (0, _apiElasticsearch.createSort)({
|
|
121
|
+
sort: initialSort,
|
|
122
|
+
fieldPlugins
|
|
123
|
+
});
|
|
124
|
+
const queryModifiers = plugins.byType(_FormElasticsearchQueryModifierPlugin.FormElasticsearchQueryModifierPlugin.type);
|
|
125
|
+
|
|
126
|
+
for (const plugin of queryModifiers) {
|
|
127
|
+
plugin.modifyQuery({
|
|
128
|
+
query,
|
|
129
|
+
where
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const sortModifiers = plugins.byType(_FormElasticsearchSortModifierPlugin.FormElasticsearchSortModifierPlugin.type);
|
|
134
|
+
|
|
135
|
+
for (const plugin of sortModifiers) {
|
|
136
|
+
plugin.modifySort({
|
|
137
|
+
sort
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const body = {
|
|
142
|
+
query: {
|
|
143
|
+
constant_score: {
|
|
144
|
+
filter: {
|
|
145
|
+
bool: (0, _objectSpread2.default)({}, query)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
size: limit + 1,
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Casting as any is required due to search_after is accepting an array of values.
|
|
153
|
+
* Which is correct in some cases. In our case, it is not.
|
|
154
|
+
* https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html
|
|
155
|
+
*/
|
|
156
|
+
search_after: (0, _apiElasticsearch.decodeCursor)(after),
|
|
157
|
+
sort
|
|
158
|
+
};
|
|
159
|
+
const bodyModifiers = plugins.byType(_FormElasticsearchBodyModifierPlugin.FormElasticsearchBodyModifierPlugin.type);
|
|
160
|
+
|
|
161
|
+
for (const plugin of bodyModifiers) {
|
|
162
|
+
plugin.modifyBody({
|
|
163
|
+
body
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return body;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
exports.createElasticsearchBody = createElasticsearchBody;
|
|
@@ -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,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 -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
|
|
9
|
+
|
|
10
|
+
var _default = () => [new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
11
|
+
field: "createdOn",
|
|
12
|
+
unmappedType: "date"
|
|
13
|
+
}), new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
14
|
+
field: "savedOn",
|
|
15
|
+
unmappedType: "date"
|
|
16
|
+
}), new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
17
|
+
field: "publishedOn",
|
|
18
|
+
unmappedType: "date"
|
|
19
|
+
}), new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
20
|
+
field: "ownedBy",
|
|
21
|
+
path: "ownedBy.id"
|
|
22
|
+
}), new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
23
|
+
field: "createdBy",
|
|
24
|
+
path: "createdBy.id"
|
|
25
|
+
}),
|
|
26
|
+
/**
|
|
27
|
+
* Always add the ALL fields plugin because of the keyword/path build.
|
|
28
|
+
*/
|
|
29
|
+
new _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin({
|
|
30
|
+
field: _FormElasticsearchFieldPlugin.FormElasticsearchFieldPlugin.ALL
|
|
31
|
+
})];
|
|
32
|
+
|
|
33
|
+
exports.default = _default;
|
|
@@ -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,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _FormDynamoDbFieldPlugin = require("../../plugins/FormDynamoDbFieldPlugin");
|
|
9
|
+
|
|
10
|
+
var _default = () => [new _FormDynamoDbFieldPlugin.FormDynamoDbFieldPlugin({
|
|
11
|
+
field: "publishedOn",
|
|
12
|
+
type: "date"
|
|
13
|
+
})];
|
|
14
|
+
|
|
15
|
+
exports.default = _default;
|
|
@@ -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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { Client } from "@elastic/elasticsearch";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import { FormBuilderFormStorageOperations } from "../../types";
|
|
5
|
+
export declare type DbRecord<T = any> = T & {
|
|
6
|
+
PK: string;
|
|
7
|
+
SK: string;
|
|
8
|
+
TYPE: string;
|
|
9
|
+
};
|
|
10
|
+
export interface CreateFormStorageOperationsParams {
|
|
11
|
+
entity: Entity<any>;
|
|
12
|
+
esEntity: Entity<any>;
|
|
13
|
+
table: Table;
|
|
14
|
+
elasticsearch: Client;
|
|
15
|
+
plugins: PluginsContainer;
|
|
16
|
+
}
|
|
17
|
+
export declare const createFormStorageOperations: (params: CreateFormStorageOperationsParams) => FormBuilderFormStorageOperations;
|