@webiny/api-form-builder-so-ddb-es 5.34.8 → 5.35.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configurations.js +0 -11
- package/configurations.js.map +1 -1
- package/definitions/elasticsearch.js +0 -5
- package/definitions/elasticsearch.js.map +1 -1
- package/definitions/form.js +0 -5
- package/definitions/form.js.map +1 -1
- package/definitions/settings.js +0 -5
- package/definitions/settings.js.map +1 -1
- package/definitions/submission.js +0 -5
- package/definitions/submission.js.map +1 -1
- package/definitions/system.js +0 -5
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/definitions/tableElasticsearch.js +0 -3
- package/definitions/tableElasticsearch.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.js +0 -11
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/indices/base.js +0 -3
- package/elasticsearch/indices/base.js.map +1 -1
- package/elasticsearch/indices/index.d.ts +1 -1
- package/elasticsearch/indices/index.js +0 -4
- package/elasticsearch/indices/index.js.map +1 -1
- package/elasticsearch/indices/japanese.js +0 -3
- package/elasticsearch/indices/japanese.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +25 -35
- package/index.js.map +1 -1
- package/operations/form/elasticsearchBody.js +0 -27
- package/operations/form/elasticsearchBody.js.map +1 -1
- package/operations/form/elasticsearchFields.js +0 -3
- package/operations/form/elasticsearchFields.js.map +1 -1
- package/operations/form/fields.js +0 -3
- package/operations/form/fields.js.map +1 -1
- package/operations/form/index.js +2 -103
- package/operations/form/index.js.map +1 -1
- package/operations/settings/index.js +0 -20
- package/operations/settings/index.js.map +1 -1
- package/operations/submission/elasticsearchBody.js +0 -29
- package/operations/submission/elasticsearchBody.js.map +1 -1
- package/operations/submission/elasticsearchFields.js +0 -3
- package/operations/submission/elasticsearchFields.js.map +1 -1
- package/operations/submission/index.js +1 -49
- package/operations/submission/index.js.map +1 -1
- package/operations/system/index.js +0 -18
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -15
- package/plugins/FormDynamoDbFieldPlugin.js +0 -5
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -1
- package/plugins/FormElasticsearchBodyModifierPlugin.js +0 -5
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/FormElasticsearchFieldPlugin.js +0 -5
- package/plugins/FormElasticsearchFieldPlugin.js.map +1 -1
- package/plugins/FormElasticsearchIndexPlugin.js +0 -5
- package/plugins/FormElasticsearchIndexPlugin.js.map +1 -1
- package/plugins/FormElasticsearchQueryModifierPlugin.js +0 -5
- package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/FormElasticsearchSortModifierPlugin.js +0 -5
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +0 -5
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/SubmissionElasticsearchFieldPlugin.js +0 -5
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -1
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +0 -5
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js +0 -5
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/index.d.ts +10 -0
- package/plugins/index.js +115 -0
- package/plugins/index.js.map +1 -0
- package/types.js +0 -1
- package/types.js.map +1 -1
|
@@ -1 +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;;A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G,UALJ;QAMIsF;MANJ,CAHE,CAAN;IAYH;IACD;AACR;AACA;;;IACQ,IAAI,CAACC,MAAL,EAAa;MACT,OAAOnI,IAAP;IACH;;IACD,MAAM;MAAEqD;IAAF,IAAYC,8BAAA,CAAeC,EAAf,CAAkB;MAChCxC,MAAM,EAAEf,IAAI,CAACe,MADmB;MAEhCC,MAAM,EAAEhB,IAAI,CAACgB;IAFmB,CAAlB,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"}
|
|
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,IAAY,KAAqB;EACjEC,MAAM,EAAE,I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MACF,OAAOnI,IAAI;IACf,CAAC,CAAC,OAAOiD,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,kDAAkD,EAChEF,EAAE,CAACG,IAAI,IAAI,sBAAsB,EACjC;QACIpD,IAAI;QACJ2D,QAAQ;QACRG,UAAU;QACVrB,YAAY;QACZG,UAAU;QACVsF;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACH1F,UAAU;IACVkB,cAAc;IACdG,UAAU;IACVY,SAAS;IACTuB,iBAAiB;IACjBjC,OAAO;IACP4C,UAAU;IACVK,kBAAkB;IAClBiB,WAAW;IACXG,aAAa;IACbxG;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,47 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createSettingsStorageOperations = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
15
|
-
|
|
16
11
|
const createSettingsStorageOperations = params => {
|
|
17
12
|
const {
|
|
18
13
|
entity
|
|
19
14
|
} = params;
|
|
20
|
-
|
|
21
15
|
const createSettingsPartitionKey = ({
|
|
22
16
|
tenant,
|
|
23
17
|
locale
|
|
24
18
|
}) => {
|
|
25
19
|
return `T#${tenant}#L#${locale}#FB#SETTINGS`;
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
const createSettingsSortKey = () => {
|
|
29
22
|
return "default";
|
|
30
23
|
};
|
|
31
|
-
|
|
32
24
|
const createKeys = params => {
|
|
33
25
|
return {
|
|
34
26
|
PK: createSettingsPartitionKey(params),
|
|
35
27
|
SK: createSettingsSortKey()
|
|
36
28
|
};
|
|
37
29
|
};
|
|
38
|
-
|
|
39
30
|
const createSettings = async params => {
|
|
40
31
|
const {
|
|
41
32
|
settings
|
|
42
33
|
} = params;
|
|
43
34
|
const keys = createKeys(settings);
|
|
44
|
-
|
|
45
35
|
try {
|
|
46
36
|
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
47
37
|
return settings;
|
|
@@ -52,17 +42,13 @@ const createSettingsStorageOperations = params => {
|
|
|
52
42
|
});
|
|
53
43
|
}
|
|
54
44
|
};
|
|
55
|
-
|
|
56
45
|
const getSettings = async params => {
|
|
57
46
|
const keys = createKeys(params);
|
|
58
|
-
|
|
59
47
|
try {
|
|
60
48
|
const result = await entity.get(keys);
|
|
61
|
-
|
|
62
49
|
if (!result || !result.Item) {
|
|
63
50
|
return null;
|
|
64
51
|
}
|
|
65
|
-
|
|
66
52
|
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
67
53
|
} catch (ex) {
|
|
68
54
|
throw new _error.default(ex.message || "Could not get the settings record by given keys.", ex.code || "LOAD_SETTINGS_ERROR", {
|
|
@@ -70,14 +56,12 @@ const createSettingsStorageOperations = params => {
|
|
|
70
56
|
});
|
|
71
57
|
}
|
|
72
58
|
};
|
|
73
|
-
|
|
74
59
|
const updateSettings = async params => {
|
|
75
60
|
const {
|
|
76
61
|
settings,
|
|
77
62
|
original
|
|
78
63
|
} = params;
|
|
79
64
|
const keys = createKeys(settings);
|
|
80
|
-
|
|
81
65
|
try {
|
|
82
66
|
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), keys));
|
|
83
67
|
return settings;
|
|
@@ -89,13 +73,11 @@ const createSettingsStorageOperations = params => {
|
|
|
89
73
|
});
|
|
90
74
|
}
|
|
91
75
|
};
|
|
92
|
-
|
|
93
76
|
const deleteSettings = async params => {
|
|
94
77
|
const {
|
|
95
78
|
settings
|
|
96
79
|
} = params;
|
|
97
80
|
const keys = createKeys(settings);
|
|
98
|
-
|
|
99
81
|
try {
|
|
100
82
|
await entity.delete();
|
|
101
83
|
} catch (ex) {
|
|
@@ -104,7 +86,6 @@ const createSettingsStorageOperations = params => {
|
|
|
104
86
|
});
|
|
105
87
|
}
|
|
106
88
|
};
|
|
107
|
-
|
|
108
89
|
return {
|
|
109
90
|
createSettings,
|
|
110
91
|
getSettings,
|
|
@@ -114,5 +95,4 @@ const createSettingsStorageOperations = params => {
|
|
|
114
95
|
createSettingsSortKey
|
|
115
96
|
};
|
|
116
97
|
};
|
|
117
|
-
|
|
118
98
|
exports.createSettingsStorageOperations = createSettingsStorageOperations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createSettingsStorageOperations","params","entity","createSettingsPartitionKey","tenant","locale","createSettingsSortKey","createKeys","PK","SK","createSettings","settings","keys","put","ex","WebinyError","message","code","getSettings","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":"
|
|
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,MAA6C,IACN;EACvC,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EAEzB,MAAME,0BAA0B,GAAG,CAAC;IAChCC,MAAM;IACNC;EAC0D,CAAC,KAAa;IACxE,OAAQ,KAAID,MAAO,MAAKC,MAAO,cAAa;EAChD,CAAC;EAED,MAAMC,qBAAqB,GAAG,MAAc;IACxC,OAAO,SAAS;EACpB,CAAC;EAED,MAAMC,UAAU,GAAIN,MAAoE,IAAK;IACzF,OAAO;MACHO,EAAE,EAAEL,0BAA0B,CAACF,MAAM,CAAC;MACtCQ,EA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EACT;MACF,OAAOD,QAAQ;IACnB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,qDAAqD,EACnEF,EAAE,CAACG,IAAI,IAAI,uBAAuB,EAClC;QACIL,IAAI;QACJY,QAAQ;QACRb;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,MAAMc,cAAc,GAAG,MACnBxB,MAAwD,IACxC;IAChB,MAAM;MAAEU;IAAS,CAAC,GAAGV,MAAM;IAC3B,MAAMW,IAAI,GAAGL,UAAU,CAACI,QAAQ,CAAC;IACjC,IAAI;MACA,MAAMT,MAAM,CAACwB,MAAM,EAAE;IACzB,CAAC,CAAC,OAAOZ,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,qDAAqD,EACnEF,EAAE,CAACG,IAAI,IAAI,uBAAuB,EAClC;QACIL;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHF,cAAc;IACdQ,WAAW;IACXK,cAAc;IACdE,cAAc;IACdtB,0BAA0B;IAC1BG;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createSubmissionElasticType = exports.createElasticsearchBody = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
13
|
-
|
|
14
10
|
var _SubmissionElasticsearchFieldPlugin = require("../../plugins/SubmissionElasticsearchFieldPlugin");
|
|
15
|
-
|
|
16
11
|
var _SubmissionElasticsearchSortModifierPlugin = require("../../plugins/SubmissionElasticsearchSortModifierPlugin");
|
|
17
|
-
|
|
18
12
|
var _SubmissionElasticsearchBodyModifierPlugin = require("../../plugins/SubmissionElasticsearchBodyModifierPlugin");
|
|
19
|
-
|
|
20
13
|
var _SubmissionElasticsearchQueryModifierPlugin = require("../../plugins/SubmissionElasticsearchQueryModifierPlugin");
|
|
21
|
-
|
|
22
14
|
const createInitialQueryValue = () => {
|
|
23
15
|
return {
|
|
24
16
|
must: [
|
|
@@ -35,13 +27,10 @@ const createInitialQueryValue = () => {
|
|
|
35
27
|
filter: []
|
|
36
28
|
};
|
|
37
29
|
};
|
|
38
|
-
|
|
39
30
|
const createSubmissionElasticType = () => {
|
|
40
31
|
return "fb.submission";
|
|
41
32
|
};
|
|
42
|
-
|
|
43
33
|
exports.createSubmissionElasticType = createSubmissionElasticType;
|
|
44
|
-
|
|
45
34
|
const createElasticsearchQuery = params => {
|
|
46
35
|
const {
|
|
47
36
|
plugins,
|
|
@@ -52,12 +41,10 @@ const createElasticsearchQuery = params => {
|
|
|
52
41
|
/**
|
|
53
42
|
* Be aware that, if having more registered operator plugins of same type, the last one will be used.
|
|
54
43
|
*/
|
|
55
|
-
|
|
56
44
|
const operatorPlugins = plugins.byType(_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
|
|
57
45
|
if (plugin.isLocaleSupported(initialWhere.locale) === false) {
|
|
58
46
|
return acc;
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
acc[plugin.getOperator()] = plugin;
|
|
62
49
|
return acc;
|
|
63
50
|
}, {});
|
|
@@ -68,9 +55,7 @@ const createElasticsearchQuery = params => {
|
|
|
68
55
|
* When ES index is shared between tenants, we need to filter records by tenant ID.
|
|
69
56
|
* No need for the tenant filtering otherwise as each index is for single tenant.
|
|
70
57
|
*/
|
|
71
|
-
|
|
72
58
|
const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
|
|
73
|
-
|
|
74
59
|
if (sharedIndex && where.tenant) {
|
|
75
60
|
query.must.push({
|
|
76
61
|
term: {
|
|
@@ -82,13 +67,10 @@ const createElasticsearchQuery = params => {
|
|
|
82
67
|
* Remove tenant so it is not applied again later.
|
|
83
68
|
* Possibly tenant is not defined, but just in case, remove it.
|
|
84
69
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
70
|
delete where.tenant;
|
|
88
71
|
/**
|
|
89
72
|
* Add the locale to filtering.
|
|
90
73
|
*/
|
|
91
|
-
|
|
92
74
|
query.must.push({
|
|
93
75
|
term: {
|
|
94
76
|
"locale.keyword": where.locale
|
|
@@ -98,7 +80,6 @@ const createElasticsearchQuery = params => {
|
|
|
98
80
|
/**
|
|
99
81
|
* And add the parent (form) to the filtering, if it exists.
|
|
100
82
|
*/
|
|
101
|
-
|
|
102
83
|
query.must.push({
|
|
103
84
|
term: {
|
|
104
85
|
"form.parent.keyword": where.formId
|
|
@@ -108,7 +89,6 @@ const createElasticsearchQuery = params => {
|
|
|
108
89
|
/**
|
|
109
90
|
* We apply other conditions as they are passed via the where value.
|
|
110
91
|
*/
|
|
111
|
-
|
|
112
92
|
(0, _apiElasticsearch.applyWhere)({
|
|
113
93
|
query,
|
|
114
94
|
where,
|
|
@@ -117,7 +97,6 @@ const createElasticsearchQuery = params => {
|
|
|
117
97
|
});
|
|
118
98
|
return query;
|
|
119
99
|
};
|
|
120
|
-
|
|
121
100
|
const createElasticsearchBody = params => {
|
|
122
101
|
const {
|
|
123
102
|
plugins,
|
|
@@ -139,22 +118,18 @@ const createElasticsearchBody = params => {
|
|
|
139
118
|
fieldPlugins
|
|
140
119
|
});
|
|
141
120
|
const queryModifiers = plugins.byType(_SubmissionElasticsearchQueryModifierPlugin.SubmissionElasticsearchQueryModifierPlugin.type);
|
|
142
|
-
|
|
143
121
|
for (const plugin of queryModifiers) {
|
|
144
122
|
plugin.modifyQuery({
|
|
145
123
|
query,
|
|
146
124
|
where
|
|
147
125
|
});
|
|
148
126
|
}
|
|
149
|
-
|
|
150
127
|
const sortModifiers = plugins.byType(_SubmissionElasticsearchSortModifierPlugin.SubmissionElasticsearchSortModifierPlugin.type);
|
|
151
|
-
|
|
152
128
|
for (const plugin of sortModifiers) {
|
|
153
129
|
plugin.modifySort({
|
|
154
130
|
sort
|
|
155
131
|
});
|
|
156
132
|
}
|
|
157
|
-
|
|
158
133
|
const body = {
|
|
159
134
|
query: {
|
|
160
135
|
constant_score: {
|
|
@@ -164,7 +139,6 @@ const createElasticsearchBody = params => {
|
|
|
164
139
|
}
|
|
165
140
|
},
|
|
166
141
|
size: limit + 1,
|
|
167
|
-
|
|
168
142
|
/**
|
|
169
143
|
* Casting as any is required due to search_after is accepting an array of values.
|
|
170
144
|
* Which is correct in some cases. In our case, it is not.
|
|
@@ -174,14 +148,11 @@ const createElasticsearchBody = params => {
|
|
|
174
148
|
sort
|
|
175
149
|
};
|
|
176
150
|
const bodyModifiers = plugins.byType(_SubmissionElasticsearchBodyModifierPlugin.SubmissionElasticsearchBodyModifierPlugin.type);
|
|
177
|
-
|
|
178
151
|
for (const plugin of bodyModifiers) {
|
|
179
152
|
plugin.modifyBody({
|
|
180
153
|
body
|
|
181
154
|
});
|
|
182
155
|
}
|
|
183
|
-
|
|
184
156
|
return body;
|
|
185
157
|
};
|
|
186
|
-
|
|
187
158
|
exports.createElasticsearchBody = createElasticsearchBody;
|
|
@@ -1 +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,MAD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AAE,IAAAC,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"}
|
|
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,gBAAgB,EAAE;MACtB;IACJ,CAAC,CACJ;IACDC,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACZ,CAAC;AACL,CAAC;AAEM,MAAMC,2BAA2B,GAAG,MAAc;EACrD,OAAO,eAAe;AAC1B,CAAC;AAAC;AAMF,MAAMC,wBAAwB,GAAIC,MAAsC,IAAK;EACzE,MAAM;IAAEC,OAAO;IAAEC,KAAK,EAAEC,YAAY;IAAEC;EAAa,CAAC,GAAGJ,MAAM;EAC7D,MAAMK,KAAK,GAAGb,uBAAuB,EAAE;EACvC;AACJ;AACA;EACI,MAAMc,eAAe,GAAGL,OAAO,CAC1BM,MAAM,CACHC,yDAAuC,CAACC,IAAI,CAC/C,CACAC,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,KAAK;IACrB,IAAIA,MAAM,CAACC,iBAAiB,CAACV,YAAY,CAACW,MAAM,CAAC,KAAK,KAAK,EAAE;MACzD,OAAOH,GAAG;IACd;IACAA,GAAG,CAACC,MAAM,CAACG,WAAW,EAAE,CAAC,GAAGH,MAAM;IAClC,OAAOD,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAA4D;EAErE,MAAMT,KAA0E,mCACzEC,YAAY,CAClB;EACD;AACJ;AACA;AACA;AACA;AACA;EACI,MAAMa,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,4BAA4B,KAAK,MAAM;EACvE,IAAIH,WAAW,IAAId,KAAK,CAACkB,MAAM,EAAE;IAC7Bf,KAAK,CAACZ,IAAI,CAAC4B,IAAI,CAAC;MACZ3B,IAAI,EAAE;QACF,gBAAgB,E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pBN,IAAI,EAAEC,WAAW;IACjB1B;EACJ,CAAC,CAAC;EAEF,MAAMgC,cAAc,GAAGnC,OAAO,CAACM,MAAM,CACjC8B,sFAA0C,CAAC5B,IAAI,CAClD;EAED,KAAK,MAAMG,MAAM,IAAIwB,cAAc,EAAE;IACjCxB,MAAM,CAAC0B,WAAW,CAAC;MACfjC,KAAK;MACLH;IACJ,CAAC,CAAC;EACN;EAEA,MAAMqC,aAAa,GAAGtC,OAAO,CAACM,MAAM,CAChCiC,oFAAyC,CAAC/B,IAAI,CACjD;EAED,KAAK,MAAMG,MAAM,IAAI2B,aAAa,EAAE;IAChC3B,MAAM,CAAC6B,UAAU,CAAC;MACdZ;IACJ,CAAC,CAAC;EACN;EAEA,MAAMa,IAAI,GAAG;IACTrC,KAAK,EAAE;MACHsC,cAAc,EAAE;QACZ9C,MAAM,EAAE;UACJ+C,IAAI,kCACGvC,KAAK;QAEhB;MACJ;IACJ,CAAC;IACDwC,IAAI,EAAElB,KAAK,GAAG,CAAC;IACf;AACR;AACA;AACA;AACA;IACQmB,YAAY,EAAE,IAAAC,8BAAY,EAAChB,KAAK,CAAQ;IACxCF;EACJ,CAAC;EAED,MAAMmB,aAAa,GAAG/C,OAAO,CAACM,MAAM,CAChC0C,oFAAyC,CAACxC,IAAI,CACjD;EAED,KAAK,MAAMG,MAAM,IAAIoC,aAAa,EAAE;IAChCpC,MAAM,CAACsC,UAAU,CAAC;MACdR;IACJ,CAAC,CAAC;EACN;EAEA,OAAOA,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _SubmissionElasticsearchFieldPlugin = require("../../plugins/SubmissionElasticsearchFieldPlugin");
|
|
9
|
-
|
|
10
8
|
var _default = () => [new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
11
9
|
field: "parent",
|
|
12
10
|
path: "form.parent"
|
|
@@ -26,5 +24,4 @@ var _default = () => [new _SubmissionElasticsearchFieldPlugin.SubmissionElastics
|
|
|
26
24
|
new _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin({
|
|
27
25
|
field: _SubmissionElasticsearchFieldPlugin.SubmissionElasticsearchFieldPlugin.ALL
|
|
28
26
|
})];
|
|
29
|
-
|
|
30
27
|
exports.default = _default;
|
|
@@ -1 +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":"
|
|
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;AAAkG,eAEnF,MAAM,CACjB,IAAIA,sEAAkC,CAAC;EACnCC,KAAK,EAAE,QAAQ;EACfC,IAAI,EAAE;AACV,CAAC,CAAC,EACF,IAAIF,sEAAkC,CAAC;EACnCC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACV,CAAC,CAAC,EACF,IAAIF,sEAAkC,CAAC;EACnCC,KAAK,EAAE,WAAW;EAClBE,YAAY,EAAE;AAClB,CAAC,CAAC,EACF,IAAIH,sEAAkC,CAAC;EACnCC,KAAK,EAAE,SAAS;EAChBE,YAAY,EAAE;AAClB,CAAC,CAAC;AACF;AACJ;AACA;AACI,IAAIH,sEAAkC,CAAC;EACnCC,KAAK,EAAED,sEAAkC,CAACI;AAC9C,CAAC,CAAC,CACL;AAAA"}
|