@webiny/api-form-builder-so-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.5e7233243f
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 +2 -2
- package/definitions/elasticsearch.js.map +1 -0
- package/definitions/form.d.ts +2 -1
- package/definitions/form.js +2 -2
- package/definitions/form.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +2 -2
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.d.ts +2 -1
- package/definitions/submission.js +2 -2
- package/definitions/submission.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +2 -2
- 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 +23 -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 +24 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/index.js +35 -28
- package/index.js.map +1 -0
- package/operations/form/elasticsearchBody.js +6 -9
- 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 +28 -21
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +2 -2
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/elasticsearchBody.js +7 -3
- 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 +12 -10
- package/operations/submission/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +2 -2
- package/operations/system/index.js.map +1 -0
- package/package.json +22 -26
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -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.js.map +1 -0
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createInitialQueryValue","must","term","must_not","should","filter","createSubmissionElasticType","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","isLocaleSupported","locale","getOperator","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","formId","applyWhere","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","SubmissionElasticsearchFieldPlugin","field","createLimit","createSort","queryModifiers","SubmissionElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","SubmissionElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","decodeCursor","bodyModifiers","SubmissionElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchBody.ts"],"sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { SubmissionElasticsearchFieldPlugin } from \"~/plugins/SubmissionElasticsearchFieldPlugin\";\nimport { SubmissionElasticsearchSortModifierPlugin } from \"~/plugins/SubmissionElasticsearchSortModifierPlugin\";\nimport { SubmissionElasticsearchBodyModifierPlugin } from \"~/plugins/SubmissionElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListSubmissionsParams } from \"@webiny/api-form-builder/types\";\nimport { SubmissionElasticsearchQueryModifierPlugin } from \"~/plugins/SubmissionElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { applyWhere } from \"@webiny/api-elasticsearch/where\";\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\": \"fb.submission\"\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\nexport const createSubmissionElasticType = (): string => {\n return \"fb.submission\";\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, SubmissionElasticsearchFieldPlugin>;\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 = plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce((acc, plugin) => {\n if (plugin.isLocaleSupported(initialWhere.locale) === false) {\n return acc;\n }\n acc[plugin.getOperator()] = plugin;\n return acc;\n }, {} as Record<string, ElasticsearchQueryBuilderOperatorPlugin>);\n\n const where: Partial<FormBuilderStorageOperationsListSubmissionsParams[\"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 * And add the parent (form) to the filtering, if it exists.\n */\n query.must.push({\n term: {\n \"form.parent.keyword\": where.formId as string\n }\n });\n delete where.formId;\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: FormBuilderStorageOperationsListSubmissionsParams[\"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<SubmissionElasticsearchFieldPlugin>(SubmissionElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, SubmissionElasticsearchFieldPlugin>);\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<SubmissionElasticsearchQueryModifierPlugin>(\n SubmissionElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<SubmissionElasticsearchSortModifierPlugin>(\n SubmissionElasticsearchSortModifierPlugin.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<SubmissionElasticsearchBodyModifierPlugin>(\n SubmissionElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;AAEA,MAAMA,uBAAuB,GAAG,MAAoC;EAChE,OAAO;IACHC,IAAI,EAAE;IACF;AACZ;AACA;IACY;MACIC,IAAI,EAAE;QACF,kBAAkB;MADhB;IADV,CAJE,CADH;IAWHC,QAAQ,EAAE,EAXP;IAYHC,MAAM,EAAE,EAZL;IAaHC,MAAM,EAAE;EAbL,CAAP;AAeH,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G,MAAX,IAAqB2B,aAArB,EAAoC;IAChC3B,MAAM,CAAC6B,UAAP,CAAkB;MACdZ;IADc,CAAlB;EAGH;;EAED,MAAMa,IAAI,GAAG;IACTrC,KAAK,EAAE;MACHsC,cAAc,EAAE;QACZ9C,MAAM,EAAE;UACJ+C,IAAI,oBACGvC,KADH;QADA;MADI;IADb,CADE;IAUTwC,IAAI,EAAElB,KAAK,GAAG,CAVL;;IAWT;AACR;AACA;AACA;AACA;IACQmB,YAAY,EAAE,IAAAC,qBAAA,EAAahB,KAAb,CAhBL;IAiBTF;EAjBS,CAAb;EAoBA,MAAMmB,aAAa,GAAG/C,OAAO,CAACM,MAAR,CAClB0C,oFAAA,CAA0CxC,IADxB,CAAtB;;EAIA,KAAK,MAAMG,MAAX,IAAqBoC,aAArB,EAAoC;IAChCpC,MAAM,CAACsC,UAAP,CAAkB;MACdR;IADc,CAAlB;EAGH;;EAED,OAAOA,IAAP;AACH,CA1EM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SubmissionElasticsearchFieldPlugin","field","path","unmappedType","ALL"],"sources":["elasticsearchFields.ts"],"sourcesContent":["import { SubmissionElasticsearchFieldPlugin } from \"~/plugins/SubmissionElasticsearchFieldPlugin\";\n\nexport default () => [\n new SubmissionElasticsearchFieldPlugin({\n field: \"parent\",\n path: \"form.parent\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"ownedBy\",\n path: \"ownedBy.id\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"createdOn\",\n unmappedType: \"date\"\n }),\n new SubmissionElasticsearchFieldPlugin({\n field: \"savedOn\",\n unmappedType: \"date\"\n }),\n /**\n * Always add the ALL fields plugin because of the keyword/path build.\n */\n new SubmissionElasticsearchFieldPlugin({\n field: SubmissionElasticsearchFieldPlugin.ALL\n })\n];\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,sEAAJ,CAAuC;EACnCC,KAAK,EAAE,QAD4B;EAEnCC,IAAI,EAAE;AAF6B,CAAvC,CADiB,EAKjB,IAAIF,sEAAJ,CAAuC;EACnCC,KAAK,EAAE,SAD4B;EAEnCC,IAAI,EAAE;AAF6B,CAAvC,CALiB,EASjB,IAAIF,sEAAJ,CAAuC;EACnCC,KAAK,EAAE,WAD4B;EAEnCE,YAAY,EAAE;AAFqB,CAAvC,CATiB,EAajB,IAAIH,sEAAJ,CAAuC;EACnCC,KAAK,EAAE,SAD4B;EAEnCE,YAAY,EAAE;AAFqB,CAAvC,CAbiB;AAiBjB;AACJ;AACA;AACI,IAAIH,sEAAJ,CAAuC;EACnCC,KAAK,EAAED,sEAAA,CAAmCI;AADP,CAAvC,CApBiB,C"}
|
|
@@ -2,11 +2,11 @@ import { Entity, Table } from "dynamodb-toolbox";
|
|
|
2
2
|
import { Client } from "@elastic/elasticsearch";
|
|
3
3
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
import { FormBuilderSubmissionStorageOperations } from "../../types";
|
|
5
|
-
export interface
|
|
5
|
+
export interface CreateSubmissionStorageOperationsParams {
|
|
6
6
|
entity: Entity<any>;
|
|
7
7
|
esEntity: Entity<any>;
|
|
8
8
|
table: Table;
|
|
9
9
|
elasticsearch: Client;
|
|
10
10
|
plugins: PluginsContainer;
|
|
11
11
|
}
|
|
12
|
-
export declare const createSubmissionStorageOperations: (params:
|
|
12
|
+
export declare const createSubmissionStorageOperations: (params: CreateSubmissionStorageOperationsParams) => FormBuilderSubmissionStorageOperations;
|
|
@@ -19,7 +19,7 @@ var _limit = require("@webiny/api-elasticsearch/limit");
|
|
|
19
19
|
|
|
20
20
|
var _elasticsearchBody = require("./elasticsearchBody");
|
|
21
21
|
|
|
22
|
-
var _configurations =
|
|
22
|
+
var _configurations = require("../../configurations");
|
|
23
23
|
|
|
24
24
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
25
25
|
|
|
@@ -27,9 +27,9 @@ var _utils = require("@webiny/utils");
|
|
|
27
27
|
|
|
28
28
|
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
29
29
|
|
|
30
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
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
31
|
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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
33
|
|
|
34
34
|
const createSubmissionStorageOperations = params => {
|
|
35
35
|
const {
|
|
@@ -85,8 +85,9 @@ const createSubmissionStorageOperations = params => {
|
|
|
85
85
|
try {
|
|
86
86
|
const {
|
|
87
87
|
index
|
|
88
|
-
} = _configurations.
|
|
89
|
-
tenant: form.tenant
|
|
88
|
+
} = _configurations.configurations.es({
|
|
89
|
+
tenant: form.tenant,
|
|
90
|
+
locale: form.locale
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
await esEntity.put(_objectSpread({
|
|
@@ -182,7 +183,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
182
183
|
where,
|
|
183
184
|
sort
|
|
184
185
|
} = params;
|
|
185
|
-
const items = where.id_in.map(id => {
|
|
186
|
+
const items = (where.id_in || []).map(id => {
|
|
186
187
|
return entity.getBatch({
|
|
187
188
|
PK: createSubmissionPartitionKey(_objectSpread({}, where)),
|
|
188
189
|
SK: createSubmissionSortKey(id)
|
|
@@ -224,7 +225,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
224
225
|
const listSubmissions = async params => {
|
|
225
226
|
const {
|
|
226
227
|
where,
|
|
227
|
-
sort,
|
|
228
|
+
sort = [],
|
|
228
229
|
limit: initialLimit,
|
|
229
230
|
after
|
|
230
231
|
} = params;
|
|
@@ -250,8 +251,9 @@ const createSubmissionStorageOperations = params => {
|
|
|
250
251
|
after: (0, _cursors.decodeCursor)(after)
|
|
251
252
|
});
|
|
252
253
|
|
|
253
|
-
const esConfig = _configurations.
|
|
254
|
-
tenant: where.tenant
|
|
254
|
+
const esConfig = _configurations.configurations.es({
|
|
255
|
+
tenant: where.tenant,
|
|
256
|
+
locale: where.locale
|
|
255
257
|
});
|
|
256
258
|
|
|
257
259
|
const query = _objectSpread(_objectSpread({}, esConfig), {}, {
|
|
@@ -291,7 +293,7 @@ const createSubmissionStorageOperations = params => {
|
|
|
291
293
|
const meta = {
|
|
292
294
|
hasMoreItems,
|
|
293
295
|
totalCount: total.value,
|
|
294
|
-
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
|
|
296
|
+
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
295
297
|
};
|
|
296
298
|
return {
|
|
297
299
|
items,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSubmissionStorageOperations","params","entity","esEntity","table","elasticsearch","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","parseIdentifier","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","TYPE","ex","WebinyError","message","code","index","configurations","es","data","__type","createSubmissionElasticType","updateSubmission","original","deleteSubmission","delete","listSubmissionsByIds","where","sort","items","id_in","map","getBatch","results","batchReadAll","submissions","filter","Boolean","cleanupItem","sortItems","fields","listSubmissions","limit","initialLimit","after","meta","hasMoreItems","cursor","totalCount","length","createLimit","body","createElasticsearchBody","decodeCursor","esConfig","query","response","search","hits","total","item","_source","pop","value","encodeCursor","getSubmission","result","get","Item"],"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 { Client } from \"@elastic/elasticsearch\";\nimport WebinyError from \"@webiny/error\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\nimport {\n createElasticsearchBody,\n createSubmissionElasticType\n} from \"~/operations/submission/elasticsearchBody\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n FormBuilderSubmissionStorageOperations,\n FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport { configurations } from \"~/configurations\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { decodeCursor, encodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\n\nexport const createSubmissionStorageOperations = (\n params: CreateSubmissionStorageOperationsParams\n): FormBuilderSubmissionStorageOperations => {\n const { entity, esEntity, table, elasticsearch, 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#F#${id}`;\n };\n const createSubmissionSortKey = (id: string) => {\n return `FS#${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 try {\n const { index } = configurations.es({\n tenant: form.tenant,\n locale: form.locale\n });\n await esEntity.put({\n index,\n data: {\n ...submission,\n __type: createSubmissionElasticType()\n },\n TYPE: createSubmissionType(),\n ...keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the Elasticsearch.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n /**\n * We do not save the data in the Elasticsearch because there is no need for that.\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 try {\n await esEntity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from Elasticsearch.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n\n /**\n *\n * We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.\n *\n * @internal\n */\n const listSubmissionsByIds = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FbSubmission[]> => {\n const { where, sort } = params;\n const items = (where.id_in || []).map(id => {\n return entity.getBatch({\n PK: createSubmissionPartitionKey({\n ...where\n }),\n SK: createSubmissionSortKey(id)\n });\n });\n\n let results: FbSubmission[] = [];\n\n try {\n results = await batchReadAll<FbSubmission>({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch read form submissions.\",\n ex.code || \"BATCH_READ_SUBMISSIONS_ERROR\",\n {\n where,\n sort\n }\n );\n }\n /**\n * We need to remove empty results because it is a possibility that batch read returned null for non-existing record.\n */\n const submissions = results.filter(Boolean).map(submission => {\n return cleanupItem(entity, submission);\n }) as FbSubmission[];\n if (!sort) {\n return submissions;\n }\n return sortItems<FbSubmission>({\n items: submissions,\n sort,\n fields: []\n });\n };\n\n const listSubmissions = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FormBuilderStorageOperationsListSubmissionsResponse> => {\n const { where, sort = [], limit: initialLimit, after } = params;\n\n if (where.id_in) {\n const items = await listSubmissionsByIds(params);\n\n return {\n items,\n meta: {\n hasMoreItems: false,\n cursor: null,\n totalCount: items.length\n }\n };\n }\n\n const limit = createLimit(initialLimit);\n\n const body = createElasticsearchBody({\n plugins,\n sort,\n limit: limit + 1,\n where,\n after: decodeCursor(after) as any\n });\n\n const esConfig = configurations.es({\n tenant: where.tenant,\n locale: where.locale\n });\n\n const query = {\n ...esConfig,\n body\n };\n\n let response: ElasticsearchSearchResponse<FbSubmission>;\n try {\n response = await elasticsearch.search(query);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list form submissions.\",\n ex.code || \"LIST_SUBMISSIONS_ERROR\",\n {\n where,\n query\n }\n );\n }\n\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source);\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const meta = {\n hasMoreItems,\n totalCount: total.value,\n cursor: items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null\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({\n ...where,\n formId: where.formId as string\n }),\n SK: createSubmissionSortKey(where.id)\n };\n\n try {\n const result = await entity.get(keys);\n\n if (!result || !result.Item) {\n return null;\n }\n\n return cleanupItem(entity, result.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":";;;;;;;;;;;AAWA;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA;;AACA;;AACA;;;;;;AAWO,MAAMA,iCAAiC,GAC1CC,MAD6C,IAEJ;EACzC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,4BAA4B,iCACzB+B,KADyB;QAE5B5B,MAAM,EAAE4B,KAAK,CAAC5B;MAFc,GADvB;MAKTU,EAAE,EAAEP,uBAAuB,CAACyB,KAAK,CAAC3B,EAAP;IALlB,CAAb;;IAQA,IAAI;MACA,MAAMkE,MAAM,GAAG,MAAM3E,MAAM,CAAC4E,GAAP,CAAW5D,IAAX,CAArB;;MAEA,IAAI,CAAC2D,MAAD,IAAW,CAACA,MAAM,CAACE,IAAvB,EAA6B;QACzB,OAAO,IAAP;MACH;;MAED,OAAO,IAAA9B,oBAAA,EAAY/C,MAAZ,EAAoB2E,MAAM,CAACE,IAA3B,CAAP;IACH,CARD,CAQE,OAAOxD,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACIY,KADJ;QAEIpB;MAFJ,CAHE,CAAN;IAQH;EACJ,CA/BD;;EAiCA,OAAO;IACHH,gBADG;IAEHoB,gBAFG;IAGHF,gBAHG;IAIHmB,eAJG;IAKHwB,aALG;IAMHrE,4BANG;IAOHM;EAPG,CAAP;AASH,CAnUM"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
2
|
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface CreateSystemStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
5
|
table: Table;
|
|
6
6
|
}
|
|
7
|
-
export declare const createSystemStorageOperations: (params:
|
|
7
|
+
export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => FormBuilderSystemStorageOperations;
|
|
@@ -13,9 +13,9 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
|
13
13
|
|
|
14
14
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
15
|
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
16
|
+
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; }
|
|
17
17
|
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
18
|
+
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; }
|
|
19
19
|
|
|
20
20
|
const createSystemStorageOperations = params => {
|
|
21
21
|
const {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","ex","WebinyError","message","code","getSystem","result","get","Item","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\";\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 result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.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;;;;;;AAOO,MAAMA,6BAA6B,GACtCC,MADyC,IAEJ;EACrC,MAAM;IAAEC;EAAF,IAAaD,MAAnB;;EAEA,MAAME,wBAAwB,GAAG,CAAC;IAAEC;E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;;EAsBA,MAAMW,YAAY,GAAG,MACjBrB,MADiB,IAEC;IAClB,MAAM;MAAES,MAAF;MAAUa;IAAV,IAAuBtB,MAA7B;IACA,MAAMU,IAAI,GAAGL,UAAU,CAACI,MAAD,CAAvB;;IAEA,IAAI;MACA,MAAMR,MAAM,CAACU,GAAP,iCACCF,MADD,GAECC,IAFD,EAAN;MAIA,OAAOD,MAAP;IACH,CAND,CAME,OAAOG,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,mDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,qBAFT,EAGF;QACIL,IADJ;QAEIY,QAFJ;QAGIb;MAHJ,CAHE,CAAN;IASH;EACJ,CAvBD;;EAyBA,OAAO;IACHD,YADG;IAEHQ,SAFG;IAGHK,YAHG;IAIHnB,wBAJG;IAKHE;EALG,CAAP;AAOH,CAlGM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-form-builder-so-ddb-es",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.5e7233243f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-form-builder",
|
|
@@ -21,39 +21,35 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/runtime": "7.
|
|
24
|
+
"@babel/runtime": "7.18.9",
|
|
25
25
|
"@elastic/elasticsearch": "7.12.0",
|
|
26
|
-
"@webiny/api
|
|
27
|
-
"@webiny/api-
|
|
28
|
-
"@webiny/api-
|
|
29
|
-
"@webiny/
|
|
30
|
-
"@webiny/
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"
|
|
34
|
-
"@webiny/handler-aws": "0.0.0-mt-3",
|
|
35
|
-
"@webiny/plugins": "0.0.0-mt-3",
|
|
36
|
-
"@webiny/utils": "0.0.0-mt-3",
|
|
37
|
-
"dynamodb-toolbox": "0.3.4",
|
|
26
|
+
"@webiny/api": "0.0.0-unstable.5e7233243f",
|
|
27
|
+
"@webiny/api-elasticsearch": "0.0.0-unstable.5e7233243f",
|
|
28
|
+
"@webiny/api-form-builder": "0.0.0-unstable.5e7233243f",
|
|
29
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.5e7233243f",
|
|
30
|
+
"@webiny/error": "0.0.0-unstable.5e7233243f",
|
|
31
|
+
"@webiny/plugins": "0.0.0-unstable.5e7233243f",
|
|
32
|
+
"@webiny/utils": "0.0.0-unstable.5e7233243f",
|
|
33
|
+
"dynamodb-toolbox": "0.3.5",
|
|
38
34
|
"elastic-ts": "0.7.0"
|
|
39
35
|
},
|
|
40
36
|
"devDependencies": {
|
|
41
|
-
"@babel/cli": "^7.
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/preset-env": "^7.
|
|
44
|
-
"@babel/preset-typescript": "^7.
|
|
45
|
-
"@
|
|
46
|
-
"@webiny/
|
|
47
|
-
"@webiny/
|
|
48
|
-
"@webiny/handler-db": "^0.0.0-
|
|
49
|
-
"@webiny/project-utils": "^0.0.0-
|
|
37
|
+
"@babel/cli": "^7.16.0",
|
|
38
|
+
"@babel/core": "^7.16.0",
|
|
39
|
+
"@babel/preset-env": "^7.16.4",
|
|
40
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
41
|
+
"@webiny/api-dynamodb-to-elasticsearch": "^0.0.0-unstable.5e7233243f",
|
|
42
|
+
"@webiny/cli": "^0.0.0-unstable.5e7233243f",
|
|
43
|
+
"@webiny/handler-aws": "^0.0.0-unstable.5e7233243f",
|
|
44
|
+
"@webiny/handler-db": "^0.0.0-unstable.5e7233243f",
|
|
45
|
+
"@webiny/project-utils": "^0.0.0-unstable.5e7233243f",
|
|
50
46
|
"csvtojson": "^2.0.10",
|
|
51
|
-
"jest": "^
|
|
47
|
+
"jest": "^28.1.0",
|
|
52
48
|
"jest-dynalite": "^3.2.0",
|
|
53
49
|
"jest-environment-node": "^27.2.4",
|
|
54
50
|
"rimraf": "^3.0.2",
|
|
55
51
|
"ttypescript": "^1.5.12",
|
|
56
|
-
"typescript": "
|
|
52
|
+
"typescript": "4.7.4"
|
|
57
53
|
},
|
|
58
54
|
"publishConfig": {
|
|
59
55
|
"access": "public",
|
|
@@ -63,5 +59,5 @@
|
|
|
63
59
|
"build": "yarn webiny run build",
|
|
64
60
|
"watch": "yarn webiny run watch"
|
|
65
61
|
},
|
|
66
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "995a4b337db9b8497c6615e335dcd206afe26f8f"
|
|
67
63
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormDynamoDbFieldPlugin","FieldPlugin"],"sources":["FormDynamoDbFieldPlugin.ts"],"sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,uBAAN,SAAsCC,wBAAtC,CAAkD;;;8BAA5CD,uB,UACsC,iC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"sources":["FormElasticsearchBodyModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin\";\n\nexport class FormElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.body.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,mCAAN,SAAkDC,gEAAlD,CAAkF;;;8BAA5ED,mC,UACsC,8C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"sources":["FormElasticsearchFieldPlugin.ts"],"sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin\";\n\nexport class FormElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.fieldDefinition.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,4BAAN,SAA2CC,kDAA3C,CAAoE;;;8BAA9DD,4B,UACsC,gD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormElasticsearchIndexPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchIndexPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchIndexPlugin");
|
|
13
|
+
|
|
14
|
+
class FormElasticsearchIndexPlugin extends _ElasticsearchIndexPlugin.ElasticsearchIndexPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormElasticsearchIndexPlugin = FormElasticsearchIndexPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormElasticsearchIndexPlugin, "type", "formBuilder.form.elasticsearch.index");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchIndexPlugin","ElasticsearchIndexPlugin"],"sources":["FormElasticsearchIndexPlugin.ts"],"sourcesContent":["import { ElasticsearchIndexPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchIndexPlugin\";\n\nexport class FormElasticsearchIndexPlugin extends ElasticsearchIndexPlugin {\n public static override readonly type: string = \"formBuilder.form.elasticsearch.index\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,4BAAN,SAA2CC,kDAA3C,CAAoE;;;8BAA9DD,4B,UACsC,sC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchQueryModifierPlugin","ElasticsearchQueryModifierPlugin"],"sources":["FormElasticsearchQueryModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchQueryModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryModifierPlugin\";\n\nexport class FormElasticsearchQueryModifierPlugin extends ElasticsearchQueryModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.query.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,oCAAN,SAAmDC,kEAAnD,CAAoF;;;8BAA9ED,oC,UACsC,+C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormElasticsearchSortModifierPlugin","ElasticsearchSortModifierPlugin"],"sources":["FormElasticsearchSortModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchSortModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchSortModifierPlugin\";\n\nexport class FormElasticsearchSortModifierPlugin extends ElasticsearchSortModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.sort.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,mCAAN,SAAkDC,gEAAlD,CAAkF;;;8BAA5ED,mC,UACsC,8C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SubmissionElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"sources":["SubmissionElasticsearchBodyModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin\";\n\nexport class SubmissionElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.body.submission\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,yCAAN,SAAwDC,gEAAxD,CAAwF;;;8BAAlFD,yC,UAEL,oD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SubmissionElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"sources":["SubmissionElasticsearchFieldPlugin.ts"],"sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin\";\n\nexport class SubmissionElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.fieldDefinition.submission\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,kCAAN,SAAiDC,kDAAjD,CAA0E;;;8BAApED,kC,UAEL,sD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SubmissionElasticsearchQueryModifierPlugin","ElasticsearchQueryModifierPlugin"],"sources":["SubmissionElasticsearchQueryModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchQueryModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryModifierPlugin\";\n\nexport class SubmissionElasticsearchQueryModifierPlugin extends ElasticsearchQueryModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.query.submission\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,0CAAN,SAAyDC,kEAAzD,CAA0F;;;8BAApFD,0C,UAEL,qD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SubmissionElasticsearchSortModifierPlugin","ElasticsearchSortModifierPlugin"],"sources":["SubmissionElasticsearchSortModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchSortModifierPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchSortModifierPlugin\";\n\nexport class SubmissionElasticsearchSortModifierPlugin extends ElasticsearchSortModifierPlugin {\n public static override readonly type: string =\n \"formBuilder.elasticsearch.modifier.sort.submission\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,yCAAN,SAAwDC,gEAAxD,CAAwF;;;8BAAlFD,yC,UAEL,oD"}
|
package/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Table, Entity } from "dynamodb-toolbox";
|
|
|
4
4
|
import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
|
|
5
5
|
import { EntityAttributeConfig, EntityCompositeAttributes } from "dynamodb-toolbox/dist/classes/Entity";
|
|
6
6
|
import { Client } from "@elastic/elasticsearch";
|
|
7
|
-
import {
|
|
7
|
+
import { PluginCollection } from "@webiny/plugins/types";
|
|
8
8
|
export declare type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;
|
|
9
9
|
export declare type Attributes = Record<string, AttributeDefinition>;
|
|
10
10
|
export declare enum ENTITIES {
|
|
@@ -21,7 +21,7 @@ export interface FormBuilderStorageOperationsFactoryParams {
|
|
|
21
21
|
table?: string;
|
|
22
22
|
esTable?: string;
|
|
23
23
|
attributes?: Record<ENTITIES, Attributes>;
|
|
24
|
-
plugins?:
|
|
24
|
+
plugins?: PluginCollection;
|
|
25
25
|
}
|
|
26
26
|
export interface FormBuilderSystemCreateKeysParams {
|
|
27
27
|
tenant: string;
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ENTITIES"],"sources":["types.ts"],"sourcesContent":["import {\n FormBuilderStorageOperations as BaseFormBuilderStorageOperations,\n FormBuilderSystemStorageOperations as BaseFormBuilderSystemStorageOperations,\n FormBuilderSubmissionStorageOperations as BaseFormBuilderSubmissionStorageOperations,\n FormBuilderSettingsStorageOperations as BaseFormBuilderSettingsStorageOperations,\n FormBuilderFormStorageOperations as BaseFormBuilderFormStorageOperations\n} from \"@webiny/api-form-builder/types\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { Table, Entity } from \"dynamodb-toolbox\";\nimport { DynamoDBTypes } from \"dynamodb-toolbox/dist/classes/Table\";\nimport {\n EntityAttributeConfig,\n EntityCompositeAttributes\n} from \"dynamodb-toolbox/dist/classes/Entity\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\n\nexport type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;\n\nexport type Attributes = Record<string, AttributeDefinition>;\n\nexport enum ENTITIES {\n FORM = \"FormBuilderForm\",\n ES_FORM = \"FormBuilderFormEs\",\n SUBMISSION = \"FormBuilderSubmission\",\n ES_SUBMISSION = \"FormBuilderSubmissionEs\",\n SYSTEM = \"FormBuilderSystem\",\n SETTINGS = \"FormBuilderSettings\"\n}\n\nexport interface FormBuilderStorageOperationsFactoryParams {\n documentClient: DocumentClient;\n elasticsearch: Client;\n table?: string;\n esTable?: string;\n attributes?: Record<ENTITIES, Attributes>;\n plugins?: PluginCollection;\n}\n\nexport interface FormBuilderSystemCreateKeysParams {\n tenant: string;\n}\n\nexport interface FormBuilderSystemStorageOperations extends BaseFormBuilderSystemStorageOperations {\n createSystemPartitionKey: (params: FormBuilderSystemCreateKeysParams) => string;\n createSystemSortKey: () => string;\n}\n\nexport interface FormBuilderFormCreateKeyParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface FormBuilderFormStorageOperations extends BaseFormBuilderFormStorageOperations {\n createFormPartitionKey: (params: FormBuilderFormCreateKeyParams) => string;\n}\n\nexport interface FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams {\n tenant: string;\n locale: string;\n formId: string;\n}\n\nexport interface FormBuilderSubmissionStorageOperations\n extends BaseFormBuilderSubmissionStorageOperations {\n createSubmissionPartitionKey: (\n params: FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n ) => string;\n createSubmissionSortKey: (id: string) => string;\n}\n\nexport interface FormBuilderSettingsStorageOperationsCreatePartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nexport interface FormBuilderSettingsStorageOperations\n extends BaseFormBuilderSettingsStorageOperations {\n createSettingsPartitionKey: (\n params: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams\n ) => string;\n createSettingsSortKey: () => string;\n}\n\nexport type Entities = \"form\" | \"esForm\" | \"submission\" | \"esSubmission\" | \"system\" | \"settings\";\n\nexport interface FormBuilderStorageOperations\n extends BaseFormBuilderStorageOperations,\n FormBuilderSettingsStorageOperations,\n FormBuilderSubmissionStorageOperations,\n FormBuilderFormStorageOperations,\n FormBuilderSystemStorageOperations {\n getTable(): Table;\n getEsTable(): Table;\n getEntities(): Record<Entities, Entity<any>>;\n}\n\nexport interface FormBuilderStorageOperationsFactory {\n (params: FormBuilderStorageOperationsFactoryParams): FormBuilderStorageOperations;\n}\n"],"mappings":";;;;;;IAqBYA,Q;;;WAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;GAAAA,Q,wBAAAA,Q"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.createElasticsearchIndex = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
|
|
18
|
-
const createElasticsearchIndex = async params => {
|
|
19
|
-
const {
|
|
20
|
-
tenant,
|
|
21
|
-
elasticsearch
|
|
22
|
-
} = params;
|
|
23
|
-
|
|
24
|
-
const esIndex = _configurations.default.es({
|
|
25
|
-
tenant
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
body: exists
|
|
30
|
-
} = await elasticsearch.indices.exists(esIndex);
|
|
31
|
-
|
|
32
|
-
if (exists) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await elasticsearch.indices.create(_objectSpread(_objectSpread({}, esIndex), {}, {
|
|
37
|
-
body: {
|
|
38
|
-
/**
|
|
39
|
-
* need this part for sorting to work on text fields
|
|
40
|
-
*/
|
|
41
|
-
settings: {
|
|
42
|
-
analysis: {
|
|
43
|
-
analyzer: {
|
|
44
|
-
lowercase_analyzer: {
|
|
45
|
-
type: "custom",
|
|
46
|
-
filter: ["lowercase", "trim"],
|
|
47
|
-
tokenizer: "keyword"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
mappings: {
|
|
53
|
-
properties: {
|
|
54
|
-
property: {
|
|
55
|
-
type: "text",
|
|
56
|
-
fields: {
|
|
57
|
-
keyword: {
|
|
58
|
-
type: "keyword",
|
|
59
|
-
ignore_above: 256
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
analyzer: "lowercase_analyzer"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
exports.createElasticsearchIndex = createElasticsearchIndex;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UpgradePlugin } from "@webiny/api-upgrade/types";
|
|
2
|
-
import { FormBuilderContext } from "@webiny/api-form-builder/types";
|
|
3
|
-
declare const _default: () => UpgradePlugin<FormBuilderContext>;
|
|
4
|
-
/**
|
|
5
|
-
* This upgrade adds:
|
|
6
|
-
* - formId (first part of the id) and webinyVersion to the form records
|
|
7
|
-
*/
|
|
8
|
-
export default _default;
|
package/upgrades/5.16.0/index.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
13
|
-
|
|
14
|
-
var _utils = require("@webiny/utils");
|
|
15
|
-
|
|
16
|
-
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
17
|
-
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
const upgradeForms = async params => {
|
|
25
|
-
const {
|
|
26
|
-
storageOperations,
|
|
27
|
-
tenant,
|
|
28
|
-
locale,
|
|
29
|
-
webinyVersion
|
|
30
|
-
} = params;
|
|
31
|
-
/**
|
|
32
|
-
* We need all of the forms from the database.
|
|
33
|
-
* We are getting them from the Elasticsearch because there is no general PK for the forms.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
let forms = [];
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const {
|
|
40
|
-
items
|
|
41
|
-
} = await storageOperations.listForms({
|
|
42
|
-
where: {
|
|
43
|
-
latest: true,
|
|
44
|
-
tenant: tenant.id,
|
|
45
|
-
locale: locale.code
|
|
46
|
-
},
|
|
47
|
-
after: null,
|
|
48
|
-
limit: 10000,
|
|
49
|
-
sort: ["createdOn_DESC"]
|
|
50
|
-
});
|
|
51
|
-
forms = items;
|
|
52
|
-
} catch (ex) {
|
|
53
|
-
console.log(ex.message);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (forms.length === 0) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const entity = storageOperations.getEntities().form;
|
|
62
|
-
const items = [];
|
|
63
|
-
/**
|
|
64
|
-
* ## Regular DynamoDB table.
|
|
65
|
-
* We need to get all the records from all of the forms.
|
|
66
|
-
* Unfortunately, we need to query in a loop to be able to get those forms.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
for (const form of forms) {
|
|
70
|
-
const {
|
|
71
|
-
id: formId
|
|
72
|
-
} = (0, _utils.parseIdentifier)(form.id);
|
|
73
|
-
const formRecords = await (0, _query.queryAll)({
|
|
74
|
-
entity,
|
|
75
|
-
partitionKey: storageOperations.createFormPartitionKey({
|
|
76
|
-
id: form.id,
|
|
77
|
-
tenant: tenant.id,
|
|
78
|
-
locale: locale.code
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
for (const record of formRecords) {
|
|
83
|
-
/**
|
|
84
|
-
* Checks for "just in case".
|
|
85
|
-
*/
|
|
86
|
-
if (!record || !record.PK || !record.SK) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({}, record), {}, {
|
|
91
|
-
formId,
|
|
92
|
-
webinyVersion
|
|
93
|
-
})));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* And finally write all the records to the database again.
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
103
|
-
table: entity.table,
|
|
104
|
-
items
|
|
105
|
-
});
|
|
106
|
-
} catch (ex) {
|
|
107
|
-
throw new _error.default("Could not update all form records.", "UPGRADE_FORM_RECORDS_ERROR", {
|
|
108
|
-
error: ex
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* ## Elasticsearch DynamoDB table.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* This upgrade adds:
|
|
118
|
-
* - formId (first part of the id) and webinyVersion to the form records
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var _default = () => {
|
|
123
|
-
return {
|
|
124
|
-
type: "api-upgrade",
|
|
125
|
-
app: "form-builder",
|
|
126
|
-
version: "5.16.0",
|
|
127
|
-
apply: async context => {
|
|
128
|
-
const tenant = context.tenancy.getCurrentTenant();
|
|
129
|
-
const locale = context.i18nContent.getLocale();
|
|
130
|
-
const storageOperations = context.formBuilder.storageOperations;
|
|
131
|
-
await upgradeForms({
|
|
132
|
-
storageOperations,
|
|
133
|
-
tenant,
|
|
134
|
-
locale,
|
|
135
|
-
webinyVersion: context.WEBINY_VERSION
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
exports.default = _default;
|