@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 @@
|
|
|
1
|
+
{"version":3,"names":["getESDataForLatestRevision","form","__type","createFormElasticType","id","createdOn","savedOn","name","slug","published","publishedOn","version","locked","status","createdBy","ownedBy","tenant","locale","webinyVersion","formId","createFormStorageOperations","params","entity","esEntity","table","plugins","elasticsearch","formDynamoDbFields","fields","createFormPartitionKey","targetId","parseIdentifier","createRevisionSortKey","value","Number","zeroPad","createLatestSortKey","createLatestPublishedSortKey","createFormType","createFormLatestType","createFormLatestPublishedType","createForm","revisionKeys","PK","SK","latestKeys","items","putBatch","TYPE","batchWriteAll","ex","WebinyError","message","code","index","configurations","es","put","data","createFormFrom","original","latest","updateForm","latestForm","getForm","where","isLatestForm","push","sortKey","keys","result","get","Item","cleanupItem","listForms","sort","limit","after","body","createElasticsearchBody","decodeCursor","esConfig","query","response","search","hits","total","map","item","_source","hasMoreItems","length","pop","meta","totalCount","cursor","encodeCursor","listFormRevisions","initialWhere","queryAllParams","partitionKey","options","beginsWith","queryAll","undefined","filteredItems","filterItems","sortItems","deleteForm","gte","deleteItems","deleteBatch","delete","deleteFormRevision","revisions","previous","latestPublishedForm","find","rev","isLatest","isLatestPublished","esDataItem","previouslyPublishedForm","filter","f","a","b","Date","getTime","shift","publishForm","latestPublishedKeys","esData","unpublishForm","version_not","publishedOn_not","previouslyPublishedRevision"],"sources":["index.ts"],"sourcesContent":["import {\n FbForm,\n FormBuilderStorageOperationsCreateFormFromParams,\n FormBuilderStorageOperationsCreateFormParams,\n FormBuilderStorageOperationsDeleteFormParams,\n FormBuilderStorageOperationsDeleteFormRevisionParams,\n FormBuilderStorageOperationsGetFormParams,\n FormBuilderStorageOperationsListFormRevisionsParams,\n FormBuilderStorageOperationsListFormRevisionsParamsWhere,\n FormBuilderStorageOperationsListFormsParams,\n FormBuilderStorageOperationsListFormsResponse,\n FormBuilderStorageOperationsPublishFormParams,\n FormBuilderStorageOperationsUnpublishFormParams,\n FormBuilderStorageOperationsUpdateFormParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { configurations } from \"~/configurations\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport fields from \"./fields\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { parseIdentifier, zeroPad } from \"@webiny/utils\";\nimport { createElasticsearchBody, createFormElasticType } from \"./elasticsearchBody\";\nimport { decodeCursor, encodeCursor } from \"@webiny/api-elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { FormBuilderFormCreateKeyParams, FormBuilderFormStorageOperations } from \"~/types\";\nimport { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport type DbRecord<T = any> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\nexport interface CreateFormStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\n\ntype FbFormElastic = Omit<FbForm, \"triggers\" | \"fields\" | \"settings\" | \"layout\" | \"stats\"> & {\n __type: string;\n};\n\nconst getESDataForLatestRevision = (form: FbForm): FbFormElastic => ({\n __type: createFormElasticType(),\n id: form.id,\n createdOn: form.createdOn,\n savedOn: form.savedOn,\n name: form.name,\n slug: form.slug,\n published: form.published,\n publishedOn: form.publishedOn,\n version: form.version,\n locked: form.locked,\n status: form.status,\n createdBy: form.createdBy,\n ownedBy: form.ownedBy,\n tenant: form.tenant,\n locale: form.locale,\n webinyVersion: form.webinyVersion,\n formId: form.formId\n});\n\nexport const createFormStorageOperations = (\n params: CreateFormStorageOperationsParams\n): FormBuilderFormStorageOperations => {\n const { entity, esEntity, table, plugins, elasticsearch } = params;\n\n const formDynamoDbFields = fields();\n\n const createFormPartitionKey = (params: FormBuilderFormCreateKeyParams): string => {\n const { tenant, locale, id: targetId } = params;\n\n const { id } = parseIdentifier(targetId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n\n const createRevisionSortKey = (value: string | number | undefined): string => {\n const version =\n typeof value === \"number\" ? Number(value) : (parseIdentifier(value).version as number);\n return `REV#${zeroPad(version)}`;\n };\n\n const createLatestSortKey = (): string => {\n return \"L\";\n };\n\n const createLatestPublishedSortKey = (): string => {\n return \"LP\";\n };\n\n const createFormType = (): string => {\n return \"fb.form\";\n };\n\n const createFormLatestType = (): string => {\n return \"fb.form.latest\";\n };\n\n const createFormLatestPublishedType = (): string => {\n return \"fb.form.latestPublished\";\n };\n\n const createForm = async (\n params: FormBuilderStorageOperationsCreateFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...form,\n TYPE: createFormType(),\n ...revisionKeys\n }),\n entity.putBatch({\n ...form,\n TYPE: createFormLatestType(),\n ...latestKeys\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into regular table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n form\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: getESDataForLatestRevision(form),\n TYPE: createFormType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not insert form data into Elasticsearch table.\",\n ex.code || \"CREATE_FORM_ERROR\",\n {\n latestKeys,\n form\n }\n );\n }\n return form;\n };\n\n const createFormFrom = async (\n params: FormBuilderStorageOperationsCreateFormFromParams\n ): Promise<FbForm> => {\n const { form, original, latest } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n ];\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not create form data in the regular table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latest\n }\n );\n }\n\n try {\n const { index } = configurations.es({\n tenant: form.tenant,\n locale: form.locale\n });\n await esEntity.put({\n index,\n data: getESDataForLatestRevision(form),\n TYPE: createFormLatestType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not create form in the Elasticsearch table, from existing form.\",\n ex.code || \"CREATE_FORM_FROM_ERROR\",\n {\n latestKeys,\n form,\n latest,\n original\n }\n );\n }\n return form;\n };\n\n const updateForm = async (\n params: FormBuilderStorageOperationsUpdateFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n TYPE: createFormType(),\n ...revisionKeys\n })\n ];\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n TYPE: createFormLatestType(),\n ...latestKeys\n })\n );\n }\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the regular table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n revisionKeys,\n latestKeys,\n original,\n form,\n latestForm\n }\n );\n }\n /**\n * No need to go further if its not latest form.\n */\n if (!isLatestForm) {\n return form;\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: getESDataForLatestRevision(form),\n TYPE: createFormLatestType(),\n ...latestKeys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form data in the Elasticsearch table.\",\n ex.code || \"UPDATE_FORM_ERROR\",\n {\n latestKeys,\n form,\n latestForm,\n original\n }\n );\n }\n return form;\n };\n\n const getForm = async (\n params: FormBuilderStorageOperationsGetFormParams\n ): Promise<FbForm | null> => {\n const { where } = params;\n const { id, formId, latest, published, version, tenant, locale } = where;\n if (latest && published) {\n throw new WebinyError(\"Cannot have both latest and published params.\");\n }\n let sortKey: string;\n if (latest) {\n sortKey = createLatestSortKey();\n } else if (published && !version) {\n /**\n * Because of the specifics how DynamoDB works, we must not load the published record if version is sent.\n */\n sortKey = createLatestPublishedSortKey();\n } else if (id || version) {\n sortKey = createRevisionSortKey(version || id);\n } else {\n throw new WebinyError(\n \"Missing parameter to create a sort key.\",\n \"MISSING_WHERE_PARAMETER\",\n {\n where\n }\n );\n }\n\n const keys = {\n PK: createFormPartitionKey({\n tenant,\n locale,\n id: (formId || id) as string\n }),\n SK: sortKey\n };\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 form by keys.\",\n ex.code || \"GET_FORM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const listForms = async (\n params: FormBuilderStorageOperationsListFormsParams\n ): Promise<FormBuilderStorageOperationsListFormsResponse> => {\n const { sort, limit, where, after } = params;\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<FbForm>;\n try {\n response = await elasticsearch.search(query);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list forms.\",\n ex.code || \"LIST_FORMS_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\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 listFormRevisions = async (\n params: FormBuilderStorageOperationsListFormRevisionsParams\n ): Promise<FbForm[]> => {\n const { where: initialWhere, sort } = params;\n const { id, formId, tenant, locale } = initialWhere;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createFormPartitionKey({\n tenant,\n locale,\n id: (id || formId) as string\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n\n let items: FbForm[] = [];\n try {\n items = await queryAll<FbForm>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms by given params.\",\n ex.code || \"QUERY_FORMS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n const where: Partial<FormBuilderStorageOperationsListFormRevisionsParamsWhere> = {\n ...initialWhere,\n id: undefined,\n formId: undefined\n };\n const filteredItems = filterItems({\n plugins,\n items,\n where,\n fields: formDynamoDbFields\n });\n if (!sort || sort.length === 0) {\n return filteredItems;\n }\n return sortItems({\n items: filteredItems,\n sort,\n fields: formDynamoDbFields\n });\n };\n\n const deleteForm = async (\n params: FormBuilderStorageOperationsDeleteFormParams\n ): Promise<FbForm> => {\n const { form } = params;\n let items: any[];\n /**\n * This will find all form and submission records.\n */\n const queryAllParams = {\n entity,\n partitionKey: createFormPartitionKey(form),\n options: {\n gte: \" \"\n }\n };\n try {\n items = await queryAll<DbRecord>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query forms and submissions by given params.\",\n ex.code || \"QUERY_FORM_AND_SUBMISSIONS_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n const deleteItems = items.map(item => {\n return entity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n });\n });\n try {\n await batchWriteAll({\n table,\n items: deleteItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form and it's submissions.\",\n ex.code || \"DELETE_FORM_AND_SUBMISSIONS_ERROR\"\n );\n }\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n try {\n await esEntity.delete(latestKeys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete latest form record from Elasticsearch.\",\n ex.code || \"DELETE_FORM_ERROR\",\n {\n latestKeys\n }\n );\n }\n return form;\n };\n /**\n * We need to:\n * - delete current revision\n * - get previously published revision and update the record if it exists or delete if it does not\n * - update latest record if current one is the latest\n */\n const deleteFormRevision = async (\n params: FormBuilderStorageOperationsDeleteFormRevisionParams\n ): Promise<FbForm> => {\n const { form, revisions, previous } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.id)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestForm = revisions[0];\n const latestPublishedForm = revisions.find(rev => rev.published === true);\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [entity.deleteBatch(revisionKeys)];\n let esDataItem = undefined;\n\n if (isLatest || isLatestPublished) {\n /**\n * Sort out the latest published record.\n */\n if (isLatestPublished) {\n const previouslyPublishedForm = revisions\n .filter(f => !!f.publishedOn && f.version !== form.version)\n .sort((a, b) => {\n return (\n new Date(b.publishedOn as string).getTime() -\n new Date(a.publishedOn as string).getTime()\n );\n })\n .shift();\n if (previouslyPublishedForm) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedForm,\n PK: createFormPartitionKey(previouslyPublishedForm),\n SK: createLatestPublishedSortKey(),\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(\n entity.deleteBatch({\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n })\n );\n }\n }\n /**\n * Sort out the latest record.\n */\n if (isLatest && previous) {\n items.push(\n entity.putBatch({\n ...previous,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n\n const { index } = configurations.es({\n tenant: previous.tenant,\n locale: previous.locale\n });\n\n esDataItem = {\n index,\n ...latestKeys,\n data: getESDataForLatestRevision(previous)\n };\n }\n }\n /**\n * Now save the batch data.\n */\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form revision from regular table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n /**\n * And then the Elasticsearch data, if any.\n */\n if (!esDataItem) {\n return form;\n }\n try {\n await esEntity.put(esDataItem);\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form from to the Elasticsearch table.\",\n ex.code || \"DELETE_FORM_REVISION_ERROR\",\n {\n form,\n latestForm,\n revisionKeys,\n latestKeys\n }\n );\n }\n };\n\n /**\n * We need to save form in:\n * - regular form record\n * - latest published form record\n * - latest form record - if form is latest one\n * - elasticsearch latest form record\n */\n const publishForm = async (\n params: FormBuilderStorageOperationsPublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestPublishedKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n };\n\n const { locale, tenant, formId } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const isLatestForm = latestForm ? latestForm.id === form.id : false;\n /**\n * Update revision and latest published records\n */\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n }),\n entity.putBatch({\n ...form,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n ];\n /**\n * Update the latest form as well\n */\n if (isLatestForm) {\n items.push(\n entity.putBatch({\n ...form,\n ...latestKeys,\n TYPE: createFormLatestType()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n if (!isLatestForm) {\n return form;\n }\n const { index } = configurations.es({\n tenant: form.tenant,\n locale: form.locale\n });\n const esData = getESDataForLatestRevision(form);\n try {\n await esEntity.put({\n ...latestKeys,\n index,\n TYPE: createFormLatestType(),\n data: esData\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not publish form to the Elasticsearch.\",\n ex.code || \"PUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n /**\n * We need to:\n * - update form revision record\n * - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise\n * - if is latest update the Elasticsearch record\n */\n const unpublishForm = async (\n params: FormBuilderStorageOperationsUnpublishFormParams\n ): Promise<FbForm> => {\n const { form, original } = params;\n\n const revisionKeys = {\n PK: createFormPartitionKey(form),\n SK: createRevisionSortKey(form.version)\n };\n\n const latestKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestSortKey()\n };\n\n const latestPublishedKeys = {\n PK: createFormPartitionKey(form),\n SK: createLatestPublishedSortKey()\n };\n\n const { formId, tenant, locale } = form;\n\n const latestForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n latest: true\n }\n });\n\n const latestPublishedForm = await getForm({\n where: {\n formId,\n tenant,\n locale,\n published: true\n }\n });\n\n const isLatest = latestForm ? latestForm.id === form.id : false;\n const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;\n\n const items = [\n entity.putBatch({\n ...form,\n ...revisionKeys,\n TYPE: createFormType()\n })\n ];\n let esData: any = undefined;\n if (isLatest) {\n esData = getESDataForLatestRevision(form);\n }\n /**\n * In case previously published revision exists, replace current one with that one.\n * And if it does not, delete the record.\n */\n if (isLatestPublished) {\n const revisions = await listFormRevisions({\n where: {\n formId,\n tenant,\n locale,\n version_not: form.version,\n publishedOn_not: null\n },\n sort: [\"savedOn_DESC\"]\n });\n\n const previouslyPublishedRevision = revisions.shift();\n if (previouslyPublishedRevision) {\n items.push(\n entity.putBatch({\n ...previouslyPublishedRevision,\n ...latestPublishedKeys,\n TYPE: createFormLatestPublishedType()\n })\n );\n } else {\n items.push(entity.deleteBatch(latestPublishedKeys));\n }\n }\n\n try {\n await batchWriteAll({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n /**\n * No need to go further in case of non-existing Elasticsearch data.\n */\n if (!esData) {\n return form;\n }\n const { index } = configurations.es({\n tenant: form.tenant,\n locale: form.locale\n });\n try {\n await esEntity.put({\n ...latestKeys,\n index,\n TYPE: createFormLatestType(),\n data: esData\n });\n return form;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not unpublish form from the Elasticsearch.\",\n ex.code || \"UNPUBLISH_FORM_ERROR\",\n {\n form,\n original,\n latestForm,\n revisionKeys,\n latestKeys,\n latestPublishedKeys\n }\n );\n }\n };\n\n return {\n createForm,\n createFormFrom,\n updateForm,\n listForms,\n listFormRevisions,\n getForm,\n deleteForm,\n deleteFormRevision,\n publishForm,\n unpublishForm,\n createFormPartitionKey\n };\n};\n"],"mappings":";;;;;;;;;;;AAiBA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuBA,MAAMA,0BAA0B,GAAIC,IAAD,KAAkC;EACjEC,MAAM,EAAE,IAAAC,wCAAA,GADyD;EAEjEC,EAAE,EAAEH,IAAI,CAACG,EAFwD;EAGjEC,SAAS,EAAEJ,IAAI,CAACI,SAHiD;EAIjEC,OAAO,EAAEL,IAAI,CAACK,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AlB,CAAlB;;IAIA,IAAI;MACA,MAAMM,QAAQ,CAACkC,GAAT,6DACCZ,UADD;QAEFS,KAFE;QAGFN,IAAI,EAAET,oBAAoB,EAHxB;QAIFmB,IAAI,EAAE0E;MAJJ,GAAN;MAMA,OAAOnI,IAAP;IACH,CARD,CAQE,OAAOiD,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,kDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACIpD,IADJ;QAEI2D,QAFJ;QAGIG,UAHJ;QAIIrB,YAJJ;QAKIG,UALJ;QAMIsF;MANJ,CAHE,CAAN;IAYH;EACJ,CAvID;;EAyIA,OAAO;IACH1F,UADG;IAEHkB,cAFG;IAGHG,UAHG;IAIHY,SAJG;IAKHuB,iBALG;IAMHjC,OANG;IAOH4C,UAPG;IAQHK,kBARG;IASHiB,WATG;IAUHG,aAVG;IAWHxG;EAXG,CAAP;AAaH,CA/4BM"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { FormBuilderSettingsStorageOperations } from "../../types";
|
|
3
|
+
export interface CreateSettingsStorageOperationsParams {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
table: Table;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => FormBuilderSettingsStorageOperations;
|
|
@@ -0,0 +1,118 @@
|
|
|
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.createSettingsStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
+
|
|
16
|
+
const createSettingsStorageOperations = params => {
|
|
17
|
+
const {
|
|
18
|
+
entity
|
|
19
|
+
} = params;
|
|
20
|
+
|
|
21
|
+
const createSettingsPartitionKey = ({
|
|
22
|
+
tenant,
|
|
23
|
+
locale
|
|
24
|
+
}) => {
|
|
25
|
+
return `T#${tenant}#L#${locale}#FB#SETTINGS`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const createSettingsSortKey = () => {
|
|
29
|
+
return "default";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createKeys = params => {
|
|
33
|
+
return {
|
|
34
|
+
PK: createSettingsPartitionKey(params),
|
|
35
|
+
SK: createSettingsSortKey()
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const createSettings = async params => {
|
|
40
|
+
const {
|
|
41
|
+
settings
|
|
42
|
+
} = params;
|
|
43
|
+
const keys = createKeys(settings);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
47
|
+
return settings;
|
|
48
|
+
} catch (ex) {
|
|
49
|
+
throw new _error.default(ex.message || "Could not create the settings record by given keys.", ex.code || "CREATE_SETTINGS_ERROR", {
|
|
50
|
+
keys,
|
|
51
|
+
settings
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getSettings = async params => {
|
|
57
|
+
const keys = createKeys(params);
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const result = await entity.get(keys);
|
|
61
|
+
|
|
62
|
+
if (!result || !result.Item) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
67
|
+
} catch (ex) {
|
|
68
|
+
throw new _error.default(ex.message || "Could not get the settings record by given keys.", ex.code || "LOAD_SETTINGS_ERROR", {
|
|
69
|
+
keys
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const updateSettings = async params => {
|
|
75
|
+
const {
|
|
76
|
+
settings,
|
|
77
|
+
original
|
|
78
|
+
} = params;
|
|
79
|
+
const keys = createKeys(settings);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
83
|
+
return settings;
|
|
84
|
+
} catch (ex) {
|
|
85
|
+
throw new _error.default(ex.message || "Could not update the settings record by given keys.", ex.code || "UPDATE_SETTINGS_ERROR", {
|
|
86
|
+
keys,
|
|
87
|
+
original,
|
|
88
|
+
settings
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const deleteSettings = async params => {
|
|
94
|
+
const {
|
|
95
|
+
settings
|
|
96
|
+
} = params;
|
|
97
|
+
const keys = createKeys(settings);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
await entity.delete();
|
|
101
|
+
} catch (ex) {
|
|
102
|
+
throw new _error.default(ex.message || "Could not delete the settings record by given keys.", ex.code || "DELETE_SETTINGS_ERROR", {
|
|
103
|
+
keys
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
createSettings,
|
|
110
|
+
getSettings,
|
|
111
|
+
updateSettings,
|
|
112
|
+
deleteSettings,
|
|
113
|
+
createSettingsPartitionKey,
|
|
114
|
+
createSettingsSortKey
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.createSettingsStorageOperations = createSettingsStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSettingsStorageOperations","params","entity","createSettingsPartitionKey","tenant","locale","createSettingsSortKey","createKeys","PK","SK","createSettings","settings","keys","put","ex","WebinyError","message","code","getSettings","result","get","Item","cleanupItem","updateSettings","original","deleteSettings","delete"],"sources":["index.ts"],"sourcesContent":["import {\n FormBuilderStorageOperationsCreateSettingsParams,\n FormBuilderStorageOperationsDeleteSettingsParams,\n FormBuilderStorageOperationsGetSettingsParams,\n FormBuilderStorageOperationsUpdateSettingsParams,\n Settings\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport {\n FormBuilderSettingsStorageOperations,\n FormBuilderSettingsStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\nexport interface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): FormBuilderSettingsStorageOperations => {\n const { entity } = params;\n\n const createSettingsPartitionKey = ({\n tenant,\n locale\n }: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#FB#SETTINGS`;\n };\n\n const createSettingsSortKey = (): string => {\n return \"default\";\n };\n\n const createKeys = (params: FormBuilderSettingsStorageOperationsCreatePartitionKeyParams) => {\n return {\n PK: createSettingsPartitionKey(params),\n SK: createSettingsSortKey()\n };\n };\n\n const createSettings = async (\n params: FormBuilderStorageOperationsCreateSettingsParams\n ): Promise<Settings> => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the settings record by given keys.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n keys,\n settings\n }\n );\n }\n };\n\n const getSettings = async (\n params: FormBuilderStorageOperationsGetSettingsParams\n ): Promise<Settings | null> => {\n const keys = createKeys(params);\n\n try {\n const 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 settings record by given keys.\",\n ex.code || \"LOAD_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSettings = async (\n params: FormBuilderStorageOperationsUpdateSettingsParams\n ): Promise<Settings> => {\n const { settings, original } = params;\n const keys = createKeys(settings);\n\n try {\n await entity.put({\n ...settings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the settings record by given keys.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n keys,\n original,\n settings\n }\n );\n }\n };\n\n const deleteSettings = async (\n params: FormBuilderStorageOperationsDeleteSettingsParams\n ): Promise<void> => {\n const { settings } = params;\n const keys = createKeys(settings);\n try {\n await entity.delete();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete the settings record by given keys.\",\n ex.code || \"DELETE_SETTINGS_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n return {\n createSettings,\n getSettings,\n updateSettings,\n deleteSettings,\n createSettingsPartitionKey,\n createSettingsSortKey\n };\n};\n"],"mappings":";;;;;;;;;;;AAYA;;AACA;;AAOO,MAAMA,+BAA+B,GACxCC,MAD2C,IAEJ;EACvC,MAAM;IAAEC;EAAF,IAAaD,MAAnB;;EAEA,MAAME,0BAA0B,GAAG,CAAC;IAChCC,MADgC;IAEhCC;EAFgC,CAAD,KAGyC;IACxE,OAAQ,KAAID,MAAO,MAAKC,MAAO,cAA/B;EACH,CALD;;EAOA,MAAMC,qBAAqB,GAAG,MAAc;IACxC,OAAO,SAAP;EACH,CAFD;;EAIA,MAAMC,UAAU,GAAIN,MAAD,IAA0E;IACzF,OAAO;MACHO,EAAE,EAAEL,0BAA0B,CAACF,MAAD,CAD3B;MAEHQ,EAAE,EAAEH,qBAAqB;IAFtB,CAAP;EAIH,CALD;;EAOA,MAAMI,cAAc,GAAG,MACnBT,MADmB,IAEC;IACpB,MAAM;MAAEU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ADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;QACIL,IADJ;QAEIY,QAFJ;QAGIb;MAHJ,CAHE,CAAN;IASH;EACJ,CAvBD;;EAyBA,MAAMc,cAAc,GAAG,MACnBxB,MADmB,IAEH;IAChB,MAAM;MAAEU;IAAF,IAAeV,MAArB;IACA,MAAMW,IAAI,GAAGL,UAAU,CAACI,QAAD,CAAvB;;IACA,IAAI;MACA,MAAMT,MAAM,CAACwB,MAAP,EAAN;IACH,CAFD,CAEE,OAAOZ,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,qDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;EACJ,CAhBD;;EAkBA,OAAO;IACHF,cADG;IAEHQ,WAFG;IAGHK,cAHG;IAIHE,cAJG;IAKHtB,0BALG;IAMHG;EANG,CAAP;AAQH,CAxHM"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SearchBody as esSearchBody } from "elastic-ts";
|
|
2
|
+
import { FormBuilderStorageOperationsListSubmissionsParams } from "@webiny/api-form-builder/types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
export declare const createSubmissionElasticType: () => string;
|
|
5
|
+
interface CreateElasticsearchBodyParams {
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
where: FormBuilderStorageOperationsListSubmissionsParams["where"];
|
|
8
|
+
limit: number;
|
|
9
|
+
after?: string;
|
|
10
|
+
sort: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const createElasticsearchBody: (params: CreateElasticsearchBodyParams) => esSearchBody;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
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.createSubmissionElasticType = 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 _SubmissionElasticsearchFieldPlugin = require("../../plugins/SubmissionElasticsearchFieldPlugin");
|
|
15
|
+
|
|
16
|
+
var _SubmissionElasticsearchSortModifierPlugin = require("../../plugins/SubmissionElasticsearchSortModifierPlugin");
|
|
17
|
+
|
|
18
|
+
var _SubmissionElasticsearchBodyModifierPlugin = require("../../plugins/SubmissionElasticsearchBodyModifierPlugin");
|
|
19
|
+
|
|
20
|
+
var _SubmissionElasticsearchQueryModifierPlugin = require("../../plugins/SubmissionElasticsearchQueryModifierPlugin");
|
|
21
|
+
|
|
22
|
+
const createInitialQueryValue = () => {
|
|
23
|
+
return {
|
|
24
|
+
must: [
|
|
25
|
+
/**
|
|
26
|
+
* We add the __type filtering in the initial query because it must be applied.
|
|
27
|
+
*/
|
|
28
|
+
{
|
|
29
|
+
term: {
|
|
30
|
+
"__type.keyword": "fb.submission"
|
|
31
|
+
}
|
|
32
|
+
}],
|
|
33
|
+
must_not: [],
|
|
34
|
+
should: [],
|
|
35
|
+
filter: []
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const createSubmissionElasticType = () => {
|
|
40
|
+
return "fb.submission";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.createSubmissionElasticType = createSubmissionElasticType;
|
|
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 = plugins.byType(_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
|
|
57
|
+
if (plugin.isLocaleSupported(initialWhere.locale) === false) {
|
|
58
|
+
return acc;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
acc[plugin.getOperator()] = plugin;
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
65
|
+
/**
|
|
66
|
+
* !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
|
|
67
|
+
*
|
|
68
|
+
* When ES index is shared between tenants, we need to filter records by tenant ID.
|
|
69
|
+
* No need for the tenant filtering otherwise as each index is for single tenant.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
73
|
+
|
|
74
|
+
if (sharedIndex && where.tenant) {
|
|
75
|
+
query.must.push({
|
|
76
|
+
term: {
|
|
77
|
+
"tenant.keyword": where.tenant
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Remove tenant so it is not applied again later.
|
|
83
|
+
* Possibly tenant is not defined, but just in case, remove it.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
delete where.tenant;
|
|
88
|
+
/**
|
|
89
|
+
* Add the locale to filtering.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
query.must.push({
|
|
93
|
+
term: {
|
|
94
|
+
"locale.keyword": where.locale
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
delete where.locale;
|
|
98
|
+
/**
|
|
99
|
+
* And add the parent (form) to the filtering, if it exists.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
query.must.push({
|
|
103
|
+
term: {
|
|
104
|
+
"form.parent.keyword": where.formId
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
delete where.formId;
|
|
108
|
+
/**
|
|
109
|
+
* We apply other conditions as they are passed via the where value.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
(0, _apiElasticsearch.applyWhere)({
|
|
113
|
+
query,
|
|
114
|
+
where,
|
|
115
|
+
fields: fieldPlugins,
|
|
116
|
+
operators: operatorPlugins
|
|
117
|
+
});
|
|
118
|
+
return query;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const createElasticsearchBody = params => {
|
|
122
|
+
const {
|
|
123
|
+
plugins,
|
|
124
|
+
where,
|
|
125
|
+
limit: initialLimit,
|
|
126
|
+
sort: initialSort,
|
|
127
|
+
after
|
|
128
|
+
} = params;
|
|
129
|
+
const fieldPlugins = plugins.byType(_SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin.type).reduce((acc, plugin) => {
|
|
130
|
+
acc[plugin.field] = plugin;
|
|
131
|
+
return acc;
|
|
132
|
+
}, {});
|
|
133
|
+
const limit = (0, _apiElasticsearch.createLimit)(initialLimit, 100);
|
|
134
|
+
const query = createElasticsearchQuery((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
135
|
+
fieldPlugins
|
|
136
|
+
}));
|
|
137
|
+
const sort = (0, _apiElasticsearch.createSort)({
|
|
138
|
+
sort: initialSort,
|
|
139
|
+
fieldPlugins
|
|
140
|
+
});
|
|
141
|
+
const queryModifiers = plugins.byType(_SubmissionElasticsearchQueryModifierPlugin.SubmissionElasticsearchQueryModifierPlugin.type);
|
|
142
|
+
|
|
143
|
+
for (const plugin of queryModifiers) {
|
|
144
|
+
plugin.modifyQuery({
|
|
145
|
+
query,
|
|
146
|
+
where
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const sortModifiers = plugins.byType(_SubmissionElasticsearchSortModifierPlugin.SubmissionElasticsearchSortModifierPlugin.type);
|
|
151
|
+
|
|
152
|
+
for (const plugin of sortModifiers) {
|
|
153
|
+
plugin.modifySort({
|
|
154
|
+
sort
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const body = {
|
|
159
|
+
query: {
|
|
160
|
+
constant_score: {
|
|
161
|
+
filter: {
|
|
162
|
+
bool: (0, _objectSpread2.default)({}, query)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
size: limit + 1,
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Casting as any is required due to search_after is accepting an array of values.
|
|
170
|
+
* Which is correct in some cases. In our case, it is not.
|
|
171
|
+
* https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html
|
|
172
|
+
*/
|
|
173
|
+
search_after: (0, _apiElasticsearch.decodeCursor)(after),
|
|
174
|
+
sort
|
|
175
|
+
};
|
|
176
|
+
const bodyModifiers = plugins.byType(_SubmissionElasticsearchBodyModifierPlugin.SubmissionElasticsearchBodyModifierPlugin.type);
|
|
177
|
+
|
|
178
|
+
for (const plugin of bodyModifiers) {
|
|
179
|
+
plugin.modifyBody({
|
|
180
|
+
body
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return body;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
exports.createElasticsearchBody = createElasticsearchBody;
|
|
@@ -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 {\n decodeCursor,\n createLimit,\n createSort,\n applyWhere,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\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\";\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;;AAQA;;AACA;;AACA;;AAEA;;AAGA,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,CAhBD;;AAkBO,MAAMC,2BAA2B,GAAG,MAAc;EACrD,OAAO,eAAP;AACH,CAFM;;;;AAQP,MAAMC,wBAAwB,GAAIC,MAAD,IAA4C;EACzE,MAAM;IAAEC,OAAF;IAAWC,KAAK,EAAEC,YAAlB;IAAgCC;EAAhC,IAAiDJ,MAAvD;EACA,MAAMK,KAAK,GAAGb,uBAAuB,EAArC;EACA;AACJ;AACA;;EACI,MAAMc,eAAe,GAAGL,OAAO,CAC1BM,MADmB,CAE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AAC,8BAAA,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,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _SubmissionElasticsearchFieldPlugin = require("../../plugins/SubmissionElasticsearchFieldPlugin");
|
|
9
|
+
|
|
10
|
+
var _default = () => [new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
11
|
+
field: "parent",
|
|
12
|
+
path: "form.parent"
|
|
13
|
+
}), new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
14
|
+
field: "ownedBy",
|
|
15
|
+
path: "ownedBy.id"
|
|
16
|
+
}), new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
17
|
+
field: "createdOn",
|
|
18
|
+
unmappedType: "date"
|
|
19
|
+
}), new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
20
|
+
field: "savedOn",
|
|
21
|
+
unmappedType: "date"
|
|
22
|
+
}),
|
|
23
|
+
/**
|
|
24
|
+
* Always add the ALL fields plugin because of the keyword/path build.
|
|
25
|
+
*/
|
|
26
|
+
new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
27
|
+
field: _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin.ALL
|
|
28
|
+
})];
|
|
29
|
+
|
|
30
|
+
exports.default = _default;
|
|
@@ -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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { Client } from "@elastic/elasticsearch";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import { FormBuilderSubmissionStorageOperations } from "../../types";
|
|
5
|
+
export interface CreateSubmissionStorageOperationsParams {
|
|
6
|
+
entity: Entity<any>;
|
|
7
|
+
esEntity: Entity<any>;
|
|
8
|
+
table: Table;
|
|
9
|
+
elasticsearch: Client;
|
|
10
|
+
plugins: PluginsContainer;
|
|
11
|
+
}
|
|
12
|
+
export declare const createSubmissionStorageOperations: (params: CreateSubmissionStorageOperationsParams) => FormBuilderSubmissionStorageOperations;
|