@webiny/api-headless-cms-ddb-es 5.25.0-beta.5 → 5.25.1-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.d.ts +2 -2
- package/configurations.js +18 -7
- package/configurations.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +60 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
- package/elasticsearch/deleteElasticsearchIndex.js +43 -0
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +23 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +16 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +24 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/helpers/createElasticsearchQueryBody.js +83 -28
- package/helpers/createElasticsearchQueryBody.js.map +1 -1
- package/index.js +49 -14
- package/index.js.map +1 -1
- package/operations/entry/index.js +37 -47
- package/operations/entry/index.js.map +1 -1
- package/operations/group/index.js +1 -3
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +18 -36
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +1 -3
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +1 -3
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -17
- package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
- package/types.d.ts +2 -2
- package/types.js.map +1 -1
- package/upgrades/index.d.ts +1 -1
- package/upgrades/index.js +1 -7
- package/upgrades/index.js.map +1 -1
- package/helpers/operatorPluginsList.d.ts +0 -6
- package/helpers/operatorPluginsList.js +0 -30
- package/helpers/operatorPluginsList.js.map +0 -1
- package/operations/system/createElasticsearchTemplate.d.ts +0 -5
- package/operations/system/createElasticsearchTemplate.js +0 -62
- package/operations/system/createElasticsearchTemplate.js.map +0 -1
- package/upgrades/utils.d.ts +0 -4
- package/upgrades/utils.js +0 -20
- package/upgrades/utils.js.map +0 -1
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -9
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -20
- package/upgrades/v5.0.0/cleanDatabaseRecord.js.map +0 -1
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
- package/upgrades/v5.0.0/createOldVersionIndiceName.js.map +0 -1
- package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -7
- package/upgrades/v5.0.0/entryValueFixer.js +0 -124
- package/upgrades/v5.0.0/entryValueFixer.js.map +0 -1
- package/upgrades/v5.0.0/fieldFinder.d.ts +0 -9
- package/upgrades/v5.0.0/fieldFinder.js +0 -46
- package/upgrades/v5.0.0/fieldFinder.js.map +0 -1
- package/upgrades/v5.0.0/helpers.d.ts +0 -4
- package/upgrades/v5.0.0/helpers.js +0 -57
- package/upgrades/v5.0.0/helpers.js.map +0 -1
- package/upgrades/v5.0.0/index.d.ts +0 -4
- package/upgrades/v5.0.0/index.js +0 -232
- package/upgrades/v5.0.0/index.js.map +0 -1
- package/upgrades/v5.8.0/index.d.ts +0 -7
- package/upgrades/v5.8.0/index.js +0 -426
- package/upgrades/v5.8.0/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["createElasticsearchQueryBody.ts"],"names":["specialFields","noKeywordFields","createElasticsearchSortParams","args","sort","modelFields","parentPath","searchPlugins","length","sortPlugins","Object","values","reduce","plugins","modelField","searchPlugin","type","field","fieldId","CmsEntryElasticsearchFieldPlugin","unmappedType","keyword","hasKeyword","sortable","isSortable","searchable","isSearchable","path","createFieldPath","key","fieldPlugins","createInitialQueryValue","where","query","must","must_not","should","filter","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","term","locale","published","latest","WebinyError","createPath","value","id","isSystemField","match","includes","nonRefFieldTypes","isRefFieldFiltering","params","typeOf","Array","isArray","Date","toISOString","fieldPathFactory","plugin","fieldPath","keywordValue","applyFiltering","operator","initialValue","operatorPlugins","fieldSearchPlugin","apply","basePath","execElasticsearchBuildQueryPlugins","initialWhere","sf","keys","hasOwnProperty","undefined","cmsField","whereKey","createElasticsearchQueryBody","model","after","limit","initialSort","queryPlugins","byType","CmsEntryElasticsearchQueryModifierPlugin","pl","modelId","modifyQuery","CmsEntryElasticsearchSortModifierPlugin","modifySort","body","bool","size","search_after","track_total_hits","bodyPlugins","CmsEntryElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;;;AA+BA,MAAMA,aAAa,GAAG,CAAC,WAAD,EAAc,QAAd,EAAwB,QAAxB,EAAkC,QAAlC,CAAtB;AACA,MAAMC,eAAe,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,CAAxB;;AAEA,MAAMC,6BAA6B,GAAIC,IAAD,IAAiD;AACnF,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,WAAR;AAAqBC,IAAAA,UAArB;AAAiCC,IAAAA;AAAjC,MAAmDJ,IAAzD;;AAEA,MAAI,CAACC,IAAD,IAASA,IAAI,CAACI,MAAL,KAAgB,CAA7B,EAAgC;AAC5B,WAAO,EAAP;AACH;;AAED,QAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAcN,WAAd,EAA2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gB,EAAE;AAdK,GAA3B;AAiBA,QAAMC,WAAW,GAAGvF,OAAO,CACtB2E,MADe,CAEZa,iFAAwCrF,IAF5B,EAIfqB,MAJe,CAIRqD,EAAE,IAAI;AACV,WAAO,CAACA,EAAE,CAACC,OAAJ,IAAeD,EAAE,CAACC,OAAH,KAAeR,KAAK,CAACQ,OAA3C;AACH,GANe,CAApB;;AAOA,OAAK,MAAMD,EAAX,IAAiBU,WAAjB,EAA8B;AAC1BV,IAAAA,EAAE,CAACY,UAAH,CAAc;AACVP,MAAAA,IADU;AAEVZ,MAAAA;AAFU,KAAd;AAIH;;AAED,SAAOY,IAAP;AACH,CAlFM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { OperatorPlugins, operatorPluginsList } from \"./operatorPluginsList\";\nimport { transformValueForSearch } from \"./transformValueForSearch\";\nimport { searchPluginsList } from \"./searchPluginsList\";\nimport {\n CmsEntryListParams,\n CmsEntryListSort,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport {\n SearchBody as esSearchBody,\n Sort as esSort,\n ElasticsearchBoolQueryConfig\n} from \"@webiny/api-elasticsearch/types\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch/where\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createLatestType, createPublishedType } from \"~/operations/entry\";\nimport { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins/CmsEntryElasticsearchQueryModifierPlugin\";\nimport { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins/CmsEntryElasticsearchSortModifierPlugin\";\nimport { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins/CmsEntryElasticsearchBodyModifierPlugin\";\nimport {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallableParams\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\n\ninterface CreateElasticsearchParams {\n plugins: PluginsContainer;\n model: CmsModel;\n args: CmsEntryListParams;\n parentPath?: string;\n}\n\ninterface CreateElasticsearchSortParams {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n parentPath?: string | null;\n model: CmsModel;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\ninterface CreateElasticsearchQueryArgs {\n model: CmsModel;\n plugins: PluginsContainer;\n where: CmsEntryListWhere;\n modelFields: ModelFields;\n parentPath?: string | null;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\nconst specialFields = [\"published\", \"latest\", \"locale\", \"tenant\"];\nconst noKeywordFields = [\"date\", \"number\", \"boolean\"];\n\nconst createElasticsearchSortParams = (args: CreateElasticsearchSortParams): esSort => {\n const { sort, modelFields, parentPath, searchPlugins } = args;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {\n const searchPlugin = searchPlugins[modelField.type];\n\n plugins[modelField.field.fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: modelField.unmappedType,\n keyword: hasKeyword(modelField),\n sortable: modelField.isSortable,\n searchable: modelField.isSearchable,\n field: modelField.field.fieldId,\n path: createFieldPath({\n key: modelField.field.fieldId,\n parentPath,\n modelField,\n searchPlugin\n })\n });\n return plugins;\n }, {} as Record<string, CmsEntryElasticsearchFieldPlugin>);\n\n return createSort({\n fieldPlugins: sortPlugins,\n sort\n });\n};\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n args: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n /**\n * Cast as partial so we can remove unnecessary keys.\n */\n const where = args.where as Partial<CmsEntryListWhere>;\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n // When ES index is shared between tenants, we need to filter records by tenant ID\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({ term: { \"tenant.keyword\": where.tenant } });\n }\n delete where[\"tenant\"];\n\n if (where.locale) {\n query.must.push({\n term: {\n \"locale.keyword\": where.locale\n }\n });\n }\n delete where[\"locale\"];\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createPublishedType()\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createLatestType()\n }\n });\n }\n // we do not allow not published and not latest\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n //\n return query;\n};\n\ninterface CreateFieldPathParams {\n modelField: ModelField;\n key: string;\n searchPlugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n parentPath?: string | null;\n}\nconst createFieldPath = ({\n modelField,\n searchPlugin,\n parentPath,\n key\n}: CreateFieldPathParams): string => {\n let path: string | null = null;\n if (searchPlugin && typeof searchPlugin.createPath === \"function\") {\n path = searchPlugin.createPath({\n field: modelField.field,\n value: null,\n key\n });\n } else if (typeof modelField.path === \"function\") {\n path = modelField.path(modelField.field.fieldId);\n }\n if (!path) {\n /**\n * We know that modelFieldPath is a string or undefined at this point.\n */\n path = (modelField.path as string) || modelField.field.fieldId || modelField.field.id;\n }\n return modelField.isSystemField || !parentPath || path.match(parentPath)\n ? path\n : `${parentPath}.${path}`;\n};\n\nconst hasKeyword = (modelField: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(modelField.type)) {\n return false;\n } else if (modelField.unmappedType) {\n /**\n * If modelField has unmapped type defined, do not add keyword.\n */\n return false;\n } else if (modelField.keyword === false) {\n /**\n * And if specifically defined that modelField has no keyword, do not add it.\n */\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n\ninterface IsRefFieldFilteringParams {\n key: string;\n value: any;\n field: CmsModelField;\n}\n\n/**\n * A list of typeof strings that are 100% not ref field filtering.\n * We also need to check for array and date.\n */\nconst nonRefFieldTypes: string[] = [\n \"string\",\n \"number\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"function\",\n \"boolean\"\n];\nconst isRefFieldFiltering = (params: IsRefFieldFilteringParams): boolean => {\n const { key, value, field } = params;\n const typeOf = typeof value;\n if (\n !value ||\n nonRefFieldTypes.includes(typeOf) ||\n Array.isArray(value) ||\n value instanceof Date ||\n !!value.toISOString\n ) {\n return false;\n } else if (typeOf === \"object\" && field.type === \"ref\") {\n return true;\n }\n throw new WebinyError(\n \"Could not determine if the search value is ref field search.\",\n \"REF_FIELD_SEARCH_ERROR\",\n {\n value,\n field,\n key\n }\n );\n};\n\ninterface FieldPathFactoryParams extends Omit<CreatePathCallableParams, \"field\"> {\n plugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n modelField: ModelField;\n key: string;\n parentPath?: string | null;\n keyword?: boolean;\n}\nconst fieldPathFactory = (params: FieldPathFactoryParams): string => {\n const { plugin, modelField, value, parentPath, keyword, key } = params;\n\n const field = modelField.field;\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.fieldId;\n if (modelField.path) {\n fieldPath =\n typeof modelField.path === \"function\" ? modelField.path(value) : modelField.path;\n }\n }\n\n const keywordValue = keyword ? \".keyword\" : \"\";\n if (!parentPath) {\n return `${fieldPath}${keywordValue}`;\n }\n return `${parentPath}.${fieldPath}${keywordValue}`;\n};\n\ninterface ApplyFilteringParams {\n query: ElasticsearchBoolQueryConfig;\n modelField: ModelField;\n operator: string;\n key: string;\n value: any;\n operatorPlugins: OperatorPlugins;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n parentPath?: string | null;\n}\nconst applyFiltering = (params: ApplyFilteringParams) => {\n const {\n query,\n modelField,\n operator,\n key,\n value: initialValue,\n operatorPlugins,\n searchPlugins,\n parentPath\n } = params;\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n const fieldSearchPlugin = searchPlugins[modelField.type];\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: modelField.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(modelField);\n plugin.apply(query, {\n basePath: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n parentPath: modelField.isSystemField ? null : parentPath,\n value,\n key\n }),\n path: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n value,\n parentPath: modelField.isSystemField ? null : parentPath,\n keyword,\n key\n }),\n value,\n keyword\n });\n};\n/*\n * Iterate through where keys and apply plugins where necessary\n */\nconst execElasticsearchBuildQueryPlugins = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { where: initialWhere, modelFields, parentPath, plugins, searchPlugins } = params;\n\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n const query = createInitialQueryValue({\n ...params,\n where\n });\n\n /**\n * Always remove special fields, as these do not exist in Elasticsearch.\n */\n for (const sf of specialFields) {\n delete where[sf];\n }\n\n if (Object.keys(where).length === 0) {\n return query;\n }\n\n const operatorPlugins = operatorPluginsList(plugins);\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * We do not need to go further if value is undefined.\n * There are few hardcoded possibilities when value is undefined, for example, ownedBy.\n */\n if (where[key] === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const modelField = modelFields[field];\n\n if (!modelField) {\n throw new WebinyError(`There is no field \"${field}\".`);\n }\n const { isSearchable = false, field: cmsField } = modelField;\n if (!isSearchable) {\n throw new WebinyError(`Field \"${field}\" is not searchable.`);\n }\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value: where[key], field: cmsField })) {\n /**\n * We we need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in where[key]) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n modelField,\n operator,\n key: whereKey,\n value: where[key][whereKey],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n continue;\n }\n applyFiltering({\n query,\n modelField,\n operator,\n key,\n value: where[key],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (params: CreateElasticsearchParams): esSearchBody => {\n const { plugins, model, args, parentPath = null } = params;\n const { where, after, limit, sort: initialSort } = args;\n\n const modelFields = createModelFields(plugins, model);\n const searchPlugins = searchPluginsList(plugins);\n\n const query = execElasticsearchBuildQueryPlugins({\n model,\n plugins,\n where,\n modelFields,\n parentPath,\n searchPlugins\n });\n\n const queryPlugins = plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of queryPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSortParams({\n plugins,\n sort: initialSort,\n modelFields,\n parentPath,\n model,\n searchPlugins\n });\n\n const sortPlugins = plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of sortPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const body: esSearchBody = {\n query: {\n bool: {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n }\n },\n sort,\n size: (limit || 0) + 1,\n // eslint-disable-next-line\n search_after: decodeCursor(after) as any,\n // eslint-disable-next-line\n track_total_hits: true\n };\n\n const bodyPlugins = plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of bodyPlugins) {\n pl.modifyBody({\n body,\n model\n });\n }\n\n return body;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["createElasticsearchQueryBody.ts"],"names":["specialFields","noKeywordFields","createElasticsearchSortParams","args","sort","modelFields","parentPath","searchPlugins","length","sortPlugins","Object","values","reduce","plugins","modelField","searchPlugin","type","field","fieldId","CmsEntryElasticsearchFieldPlugin","unmappedType","keyword","hasKeyword","sortable","isSortable","searchable","isSearchable","path","createFieldPath","key","fieldPlugins","createInitialQueryValue","params","model","where","initialWhere","query","must","must_not","should","filter","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","push","term","tenant","locale","published","latest","WebinyError","createPath","value","id","isSystemField","match","includes","nonRefFieldTypes","isRefFieldFiltering","typeOf","Array","isArray","Date","toISOString","fieldPathFactory","plugin","fieldPath","keywordValue","applyFiltering","operator","initialValue","operatorPlugins","fieldSearchPlugin","apply","basePath","applyFullTextSearch","fields","fieldPaths","collection","query_string","allow_leading_wildcard","default_operator","execElasticsearchBuildQueryPlugins","fullTextSearch","sf","keys","hasOwnProperty","undefined","cmsField","whereKey","createElasticsearchQueryBody","after","limit","initialSort","search","queryPlugins","byType","CmsEntryElasticsearchQueryModifierPlugin","pl","modelId","modifyQuery","CmsEntryElasticsearchSortModifierPlugin","modifySort","body","bool","size","search_after","track_total_hits","bodyPlugins","CmsEntryElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;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KAAK,CAACE,QAAlC,GAA6CkD,SAFrD;AAGFjD,QAAAA,MAAM,EAAEH,KAAK,CAACG,MAAN,CAAa/B,MAAb,GAAsB,CAAtB,GAA0B4B,KAAK,CAACG,MAAhC,GAAyCiD,SAH/C;AAIFhD,QAAAA,MAAM,EAAEJ,KAAK,CAACI,MAAN,CAAahC,MAAb,GAAsB,CAAtB,GAA0B4B,KAAK,CAACI,MAAhC,GAAyCgD;AAJ/C;AADH,KADgB;AASvBpF,IAAAA,IATuB;AAUvBsG,IAAAA,IAAI,EAAE,CAACb,KAAK,IAAI,CAAV,IAAe,CAVE;AAWvB;AACAc,IAAAA,YAAY,EAAE,2BAAaf,KAAb,CAZS;AAavB;AACAgB,IAAAA,gBAAgB,EAAE;AAdK,GAA3B;AAiBA,QAAMC,WAAW,GAAGhG,OAAO,CACtBoF,MADe,CAEZa,iFAAwC9F,IAF5B,EAIfwB,MAJe,CAIR2D,EAAE,IAAI;AACV,WAAO,CAACA,EAAE,CAACC,OAAJ,IAAeD,EAAE,CAACC,OAAH,KAAenE,KAAK,CAACmE,OAA3C;AACH,GANe,CAApB;;AAOA,OAAK,MAAMD,EAAX,IAAiBU,WAAjB,EAA8B;AAC1BV,IAAAA,EAAE,CAACY,UAAH,CAAc;AACVP,MAAAA,IADU;AAEVvE,MAAAA;AAFU,KAAd;AAIH;;AAED,SAAOuE,IAAP;AACH,CAtFM","sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"./transformValueForSearch\";\nimport { searchPluginsList } from \"./searchPluginsList\";\nimport {\n CmsEntryListParams,\n CmsEntryListSort,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport {\n SearchBody as esSearchBody,\n Sort as esSort,\n ElasticsearchBoolQueryConfig\n} from \"@webiny/api-elasticsearch/types\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch/where\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createLatestType, createPublishedType } from \"~/operations/entry\";\nimport { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins/CmsEntryElasticsearchQueryModifierPlugin\";\nimport { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins/CmsEntryElasticsearchSortModifierPlugin\";\nimport { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins/CmsEntryElasticsearchBodyModifierPlugin\";\nimport {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallableParams\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\nimport { getElasticsearchOperatorPluginsByLocale } from \"@webiny/api-elasticsearch/operators\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch/normalize\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\n\ninterface CreateElasticsearchParams {\n plugins: PluginsContainer;\n model: CmsModel;\n args: CmsEntryListParams;\n parentPath?: string;\n}\n\ninterface CreateElasticsearchSortParams {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n parentPath?: string | null;\n model: CmsModel;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\ninterface CreateElasticsearchQueryArgs {\n model: CmsModel;\n plugins: PluginsContainer;\n where: CmsEntryListWhere;\n modelFields: ModelFields;\n parentPath?: string | null;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n fullTextSearch: {\n term?: string;\n fields: string[];\n };\n}\n\nconst specialFields: (keyof Partial<CmsEntryListWhere>)[] = [\"published\", \"latest\"];\nconst noKeywordFields = [\"date\", \"number\", \"boolean\"];\n\nconst createElasticsearchSortParams = (args: CreateElasticsearchSortParams): esSort => {\n const { sort, modelFields, parentPath, searchPlugins } = args;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {\n const searchPlugin = searchPlugins[modelField.type];\n\n plugins[modelField.field.fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: modelField.unmappedType,\n keyword: hasKeyword(modelField),\n sortable: modelField.isSortable,\n searchable: modelField.isSearchable,\n field: modelField.field.fieldId,\n path: createFieldPath({\n key: modelField.field.fieldId,\n parentPath,\n modelField,\n searchPlugin\n })\n });\n return plugins;\n }, {} as Record<string, CmsEntryElasticsearchFieldPlugin>);\n\n return createSort({\n fieldPlugins: sortPlugins,\n sort\n });\n};\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { model, where: initialWhere } = params;\n /**\n * Cast as partial so we can remove unnecessary keys.\n */\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n // When ES index is shared between tenants, we need to filter records by tenant ID\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n query.must.push({ term: { \"tenant.keyword\": model.tenant } });\n }\n\n query.must.push({\n term: {\n \"locale.keyword\": model.locale\n }\n });\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createPublishedType()\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createLatestType()\n }\n });\n }\n // we do not allow not published and not latest\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n //\n return query;\n};\n\ninterface CreateFieldPathParams {\n modelField: ModelField;\n key: string;\n searchPlugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n parentPath?: string | null;\n}\nconst createFieldPath = ({\n modelField,\n searchPlugin,\n parentPath,\n key\n}: CreateFieldPathParams): string => {\n let path: string | null = null;\n if (searchPlugin && typeof searchPlugin.createPath === \"function\") {\n path = searchPlugin.createPath({\n field: modelField.field,\n value: null,\n key\n });\n } else if (typeof modelField.path === \"function\") {\n path = modelField.path(modelField.field.fieldId);\n }\n if (!path) {\n /**\n * We know that modelFieldPath is a string or undefined at this point.\n */\n path = (modelField.path as string) || modelField.field.fieldId || modelField.field.id;\n }\n return modelField.isSystemField || !parentPath || path.match(parentPath)\n ? path\n : `${parentPath}.${path}`;\n};\n\nconst hasKeyword = (modelField: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(modelField.type)) {\n return false;\n } else if (modelField.unmappedType) {\n /**\n * If modelField has unmapped type defined, do not add keyword.\n */\n return false;\n } else if (modelField.keyword === false) {\n /**\n * And if specifically defined that modelField has no keyword, do not add it.\n */\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n\ninterface IsRefFieldFilteringParams {\n key: string;\n value: any;\n field: CmsModelField;\n}\n\n/**\n * A list of typeof strings that are 100% not ref field filtering.\n * We also need to check for array and date.\n */\nconst nonRefFieldTypes: string[] = [\n \"string\",\n \"number\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"function\",\n \"boolean\"\n];\nconst isRefFieldFiltering = (params: IsRefFieldFilteringParams): boolean => {\n const { key, value, field } = params;\n const typeOf = typeof value;\n if (\n !value ||\n nonRefFieldTypes.includes(typeOf) ||\n Array.isArray(value) ||\n value instanceof Date ||\n !!value.toISOString\n ) {\n return false;\n } else if (typeOf === \"object\" && field.type === \"ref\") {\n return true;\n }\n throw new WebinyError(\n \"Could not determine if the search value is ref field search.\",\n \"REF_FIELD_SEARCH_ERROR\",\n {\n value,\n field,\n key\n }\n );\n};\n\ninterface FieldPathFactoryParams extends Omit<CreatePathCallableParams, \"field\"> {\n plugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n modelField: ModelField;\n key: string;\n parentPath?: string | null;\n keyword?: boolean;\n}\nconst fieldPathFactory = (params: FieldPathFactoryParams): string => {\n const { plugin, modelField, value, parentPath, keyword, key } = params;\n\n const field = modelField.field;\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.fieldId;\n if (modelField.path) {\n fieldPath =\n typeof modelField.path === \"function\" ? modelField.path(value) : modelField.path;\n }\n }\n\n const keywordValue = keyword ? \".keyword\" : \"\";\n if (!parentPath) {\n return `${fieldPath}${keywordValue}`;\n }\n return `${parentPath}.${fieldPath}${keywordValue}`;\n};\n\ninterface ApplyFilteringParams {\n query: ElasticsearchBoolQueryConfig;\n modelField: ModelField;\n operator: string;\n key: string;\n value: any;\n operatorPlugins: Record<string, ElasticsearchQueryBuilderOperatorPlugin>;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n parentPath?: string | null;\n}\nconst applyFiltering = (params: ApplyFilteringParams) => {\n const {\n query,\n modelField,\n operator,\n key,\n value: initialValue,\n operatorPlugins,\n searchPlugins,\n parentPath\n } = params;\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n const fieldSearchPlugin = searchPlugins[modelField.type];\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: modelField.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(modelField);\n plugin.apply(query, {\n basePath: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n parentPath: modelField.isSystemField ? null : parentPath,\n value,\n key\n }),\n path: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n value,\n parentPath: modelField.isSystemField ? null : parentPath,\n keyword,\n key\n }),\n value,\n keyword\n });\n};\n\ninterface ApplyFullTextSearchParams {\n query: ElasticsearchBoolQueryConfig;\n modelFields: ModelFields;\n term?: string;\n fields: string[];\n}\nconst applyFullTextSearch = (params: ApplyFullTextSearchParams): void => {\n const { query, modelFields, term, fields } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const fieldPaths = fields.reduce((collection, field) => {\n const modelField = modelFields[field];\n if (!modelField) {\n return collection;\n }\n\n collection.push(`values.${field}`);\n\n return collection;\n }, [] as string[]);\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: fieldPaths,\n query: normalizeValue(term),\n default_operator: \"or\"\n }\n });\n};\n/*\n * Iterate through where keys and apply plugins where necessary\n */\nconst execElasticsearchBuildQueryPlugins = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const {\n model,\n where: initialWhere,\n modelFields,\n parentPath,\n plugins,\n searchPlugins,\n fullTextSearch\n } = params;\n\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n const query = createInitialQueryValue({\n ...params,\n where\n });\n\n /**\n * Add full text search for requested fields.\n */\n applyFullTextSearch({\n query,\n modelFields,\n term: fullTextSearch.term,\n fields: fullTextSearch.fields\n });\n\n /**\n * Always remove special fields, as these do not exist in Elasticsearch.\n */\n for (const sf of specialFields) {\n delete where[sf];\n }\n\n if (Object.keys(where).length === 0) {\n return query;\n }\n\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, model.locale);\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * We do not need to go further if value is undefined.\n * There are few hardcoded possibilities when value is undefined, for example, ownedBy.\n */\n // TODO figure out how to have type.\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const modelField = modelFields[field];\n\n if (!modelField) {\n throw new WebinyError(`There is no field \"${field}\".`);\n }\n const { isSearchable = false, field: cmsField } = modelField;\n if (!isSearchable) {\n throw new WebinyError(`Field \"${field}\" is not searchable.`);\n }\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value, field: cmsField })) {\n /**\n * We we need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in value) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n modelField,\n operator,\n key: whereKey,\n value: value[whereKey],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n continue;\n }\n applyFiltering({\n query,\n modelField,\n operator,\n key,\n value,\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (params: CreateElasticsearchParams): esSearchBody => {\n const { plugins, model, args, parentPath = null } = params;\n const { where = {}, after, limit, sort: initialSort, search, fields } = args;\n\n const modelFields = createModelFields(plugins, model);\n const searchPlugins = searchPluginsList(plugins);\n\n const query = execElasticsearchBuildQueryPlugins({\n model,\n plugins,\n where,\n modelFields,\n parentPath,\n searchPlugins,\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const queryPlugins = plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of queryPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSortParams({\n plugins,\n sort: initialSort,\n modelFields,\n parentPath,\n model,\n searchPlugins\n });\n\n const sortPlugins = plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of sortPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const body: esSearchBody = {\n query: {\n bool: {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n }\n },\n sort,\n size: (limit || 0) + 1,\n // eslint-disable-next-line\n search_after: decodeCursor(after) as any,\n // eslint-disable-next-line\n track_total_hits: true\n };\n\n const bodyPlugins = plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of bodyPlugins) {\n pl.modifyBody({\n body,\n model\n });\n }\n\n return body;\n};\n"]}
|
package/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var _system2 = require("./definitions/system");
|
|
|
39
39
|
|
|
40
40
|
var _settings2 = require("./definitions/settings");
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
|
|
43
43
|
|
|
44
44
|
var _plugins = require("@webiny/plugins");
|
|
45
45
|
|
|
@@ -49,6 +49,10 @@ var _operators = require("@webiny/api-elasticsearch/operators");
|
|
|
49
49
|
|
|
50
50
|
var _elasticsearchFields = require("./operations/entry/elasticsearchFields");
|
|
51
51
|
|
|
52
|
+
var _indices = require("./elasticsearch/indices");
|
|
53
|
+
|
|
54
|
+
var _deleteElasticsearchIndex = require("./elasticsearch/deleteElasticsearchIndex");
|
|
55
|
+
|
|
52
56
|
const createStorageOperations = params => {
|
|
53
57
|
const {
|
|
54
58
|
attributes,
|
|
@@ -56,7 +60,7 @@ const createStorageOperations = params => {
|
|
|
56
60
|
esTable,
|
|
57
61
|
documentClient,
|
|
58
62
|
elasticsearch,
|
|
59
|
-
plugins:
|
|
63
|
+
plugins: userPlugins,
|
|
60
64
|
modelFieldToGraphQLPlugins
|
|
61
65
|
} = params;
|
|
62
66
|
const tableInstance = (0, _table.createTable)({
|
|
@@ -103,7 +107,7 @@ const createStorageOperations = params => {
|
|
|
103
107
|
/**
|
|
104
108
|
* User defined custom plugins.
|
|
105
109
|
*/
|
|
106
|
-
...(
|
|
110
|
+
...(userPlugins || []),
|
|
107
111
|
/**
|
|
108
112
|
* Plugins of type CmsModelFieldToGraphQLPlugin.
|
|
109
113
|
*/
|
|
@@ -127,21 +131,52 @@ const createStorageOperations = params => {
|
|
|
127
131
|
/**
|
|
128
132
|
* Field plugins for Elasticsearch.
|
|
129
133
|
*/
|
|
130
|
-
(0, _elasticsearch.default)()
|
|
134
|
+
(0, _elasticsearch.default)(),
|
|
135
|
+
/**
|
|
136
|
+
* Built-in Elasticsearch index templates.
|
|
137
|
+
*/
|
|
138
|
+
(0, _indices.elasticsearchIndexPlugins)()]);
|
|
131
139
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
beforeInit: async context => {
|
|
141
|
+
context.plugins.register([
|
|
142
|
+
/**
|
|
143
|
+
* Field plugins for DynamoDB.
|
|
144
|
+
* We must pass them to the base application.
|
|
145
|
+
*/
|
|
146
|
+
(0, _dynamoDb.default)()]);
|
|
147
|
+
},
|
|
148
|
+
init: async context => {
|
|
149
|
+
/**
|
|
150
|
+
* We need to create indexes on before model create and on clone (create from).
|
|
151
|
+
* Other apps create indexes on locale creation.
|
|
152
|
+
*/
|
|
153
|
+
context.cms.onBeforeModelCreate.subscribe(async ({
|
|
154
|
+
model
|
|
155
|
+
}) => {
|
|
156
|
+
await (0, _createElasticsearchIndex.createElasticsearchIndex)({
|
|
157
|
+
elasticsearch,
|
|
158
|
+
model,
|
|
159
|
+
plugins
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
context.cms.onBeforeModelCreateFrom.subscribe(async ({
|
|
163
|
+
model
|
|
164
|
+
}) => {
|
|
165
|
+
await (0, _createElasticsearchIndex.createElasticsearchIndex)({
|
|
166
|
+
elasticsearch,
|
|
167
|
+
model,
|
|
168
|
+
plugins
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
context.cms.onAfterModelDelete.subscribe(async ({
|
|
172
|
+
model
|
|
173
|
+
}) => {
|
|
174
|
+
await (0, _deleteElasticsearchIndex.deleteElasticsearchIndex)({
|
|
175
|
+
elasticsearch,
|
|
176
|
+
model
|
|
136
177
|
});
|
|
137
178
|
});
|
|
138
179
|
},
|
|
139
|
-
plugins: [
|
|
140
|
-
/**
|
|
141
|
-
* Field plugins for DynamoDB.
|
|
142
|
-
* We must pass them to the base application.
|
|
143
|
-
*/
|
|
144
|
-
(0, _dynamoDb.default)()],
|
|
145
180
|
getEntities: () => entities,
|
|
146
181
|
getTable: () => tableInstance,
|
|
147
182
|
getEsTable: () => tableElasticsearchInstance,
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","customPlugins","modelFieldToGraphQLPlugins","tableInstance","tableElasticsearchInstance","entities","settings","entityName","ENTITIES","SETTINGS","system","SYSTEM","groups","GROUPS","models","MODELS","entries","ENTRIES","entriesEs","ENTRIES_ES","PluginsContainer","cmsEntryElasticsearchFields","init","cms","onBeforeSystemInstall","subscribe","getEntities","getTable","getEsTable","entity","esEntity"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;AACvE,QAAM;AACFC,IAAAA,UADE;AAEFC,IAAAA,KAFE;AAGFC,IAAAA,OAHE;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aALE;AAMFC,IAAAA,OAAO,EAAEC,aANP;AAOFC,IAAAA;AAPE,MAQFR,MARJ;AAUA,QAAMS,aAAa,GAAG,wBAAY;AAC9BP,IAAAA,KAD8B;AAE9BE,IAAAA;AAF8B,GAAZ,CAA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BL;AA4BHc,IAAAA,MAAM,EAAE,0CAA8B;AAClCe,MAAAA,MAAM,EAAExB,QAAQ,CAACS,MADiB;AAElCf,MAAAA;AAFkC,KAA9B,CA5BL;AAgCHiB,IAAAA,OAAO,EAAE,2CAA+B;AACpCa,MAAAA,MAAM,EAAExB,QAAQ,CAACW,OADmB;AAEpCc,MAAAA,QAAQ,EAAEzB,QAAQ,CAACa,SAFiB;AAGpClB,MAAAA,OAHoC;AAIpCD,MAAAA;AAJoC,KAA/B;AAhCN,GAAP;AAuCH,CA3HM","sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { createElasticsearchTemplate } from \"~/operations/system/createElasticsearchTemplate\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\nimport { elasticsearchFields as cmsEntryElasticsearchFields } from \"~/operations/entry/elasticsearchFields\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: customPlugins,\n modelFieldToGraphQLPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * User defined custom plugins.\n */\n ...(customPlugins || []),\n /**\n * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n modelFieldToGraphQLPlugins,\n /**\n * Elasticsearch field definitions for the entry record.\n */\n cmsEntryElasticsearchFields,\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins()\n ]);\n\n return {\n init: async (cms: HeadlessCms) => {\n cms.onBeforeSystemInstall.subscribe(async () => {\n await createElasticsearchTemplate({\n elasticsearch\n });\n });\n },\n plugins: [\n /**\n * Field plugins for DynamoDB.\n * We must pass them to the base application.\n */\n dynamoDbPlugins()\n ],\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","modelFieldToGraphQLPlugins","tableInstance","tableElasticsearchInstance","entities","settings","entityName","ENTITIES","SETTINGS","system","SYSTEM","groups","GROUPS","models","MODELS","entries","ENTRIES","entriesEs","ENTRIES_ES","PluginsContainer","cmsEntryElasticsearchFields","beforeInit","context","register","init","cms","onBeforeModelCreate","subscribe","model","onBeforeModelCreateFrom","onAfterModelDelete","getEntities","getTable","getEsTable","entity","esEntity"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;AACvE,QAAM;AACFC,IAAAA,UADE;AAEFC,IAAAA,KAFE;AAGFC,IAAAA,OAHE;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aALE;AAMFC,IAAAA,OAAO,EAAEC,WANP;AAOFC,IAAAA;AAPE,MAQFR,MARJ;AAUA,QAAMS,aAAa,GAAG,wBAAY;AAC9BP,IAAAA,KAD8B;AAE9BE,IAAAA;AAF8B,GAAZ,CAAtB;AAIA,QAAMM,0BAA0B,GAAG,kDAAyB;AACxDR,IAAAA,KAAK,EAAEC,OADiD;AAExDC,IAAAA;AAFwD,GAAz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;AAAF,OAAP,KAAqB;AAC1D,cAAM,wDAAyB;AAC3B9B,UAAAA,aAD2B;AAE3B8B,UAAAA;AAF2B,SAAzB,CAAN;AAIH,OALD;AAMH,KAnCE;AAoCHG,IAAAA,WAAW,EAAE,MAAM3B,QApChB;AAqCH4B,IAAAA,QAAQ,EAAE,MAAM9B,aArCb;AAsCH+B,IAAAA,UAAU,EAAE,MAAM9B,0BAtCf;AAuCHM,IAAAA,MAAM,EAAE,2CAA8B;AAClCyB,MAAAA,MAAM,EAAE9B,QAAQ,CAACK;AADiB,KAA9B,CAvCL;AA0CHJ,IAAAA,QAAQ,EAAE,+CAAgC;AACtC6B,MAAAA,MAAM,EAAE9B,QAAQ,CAACC;AADqB,KAAhC,CA1CP;AA6CHM,IAAAA,MAAM,EAAE,2CAA8B;AAClCuB,MAAAA,MAAM,EAAE9B,QAAQ,CAACO,MADiB;AAElCZ,MAAAA;AAFkC,KAA9B,CA7CL;AAiDHc,IAAAA,MAAM,EAAE,0CAA8B;AAClCqB,MAAAA,MAAM,EAAE9B,QAAQ,CAACS,MADiB;AAElCf,MAAAA;AAFkC,KAA9B,CAjDL;AAqDHiB,IAAAA,OAAO,EAAE,2CAA+B;AACpCmB,MAAAA,MAAM,EAAE9B,QAAQ,CAACW,OADmB;AAEpCoB,MAAAA,QAAQ,EAAE/B,QAAQ,CAACa,SAFiB;AAGpClB,MAAAA,OAHoC;AAIpCD,MAAAA;AAJoC,KAA/B;AArDN,GAAP;AA4DH,CApJM","sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\nimport { elasticsearchFields as cmsEntryElasticsearchFields } from \"~/operations/entry/elasticsearchFields\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins,\n modelFieldToGraphQLPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * User defined custom plugins.\n */\n ...(userPlugins || []),\n /**\n * Plugins of type CmsModelFieldToGraphQLPlugin.\n */\n modelFieldToGraphQLPlugins,\n /**\n * Elasticsearch field definitions for the entry record.\n */\n cmsEntryElasticsearchFields,\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins()\n ]);\n\n return {\n beforeInit: async context => {\n context.plugins.register([\n /**\n * Field plugins for DynamoDB.\n * We must pass them to the base application.\n */\n dynamoDbPlugins()\n ]);\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onBeforeModelCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onBeforeModelCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onAfterModelDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"]}
|
|
@@ -13,7 +13,7 @@ var _types = require("@webiny/api-headless-cms/types");
|
|
|
13
13
|
|
|
14
14
|
var _helpers = require("../../helpers");
|
|
15
15
|
|
|
16
|
-
var _configurations =
|
|
16
|
+
var _configurations = require("../../configurations");
|
|
17
17
|
|
|
18
18
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
19
|
|
|
@@ -109,7 +109,7 @@ const createEntriesStorageOperations = params => {
|
|
|
109
109
|
|
|
110
110
|
const {
|
|
111
111
|
index: esIndex
|
|
112
|
-
} = _configurations.
|
|
112
|
+
} = _configurations.configurations.es({
|
|
113
113
|
model
|
|
114
114
|
});
|
|
115
115
|
|
|
@@ -162,7 +162,6 @@ const createEntriesStorageOperations = params => {
|
|
|
162
162
|
|
|
163
163
|
const createRevisionFrom = async (model, params) => {
|
|
164
164
|
const {
|
|
165
|
-
originalEntry,
|
|
166
165
|
entry,
|
|
167
166
|
storageEntry
|
|
168
167
|
} = params;
|
|
@@ -189,7 +188,7 @@ const createEntriesStorageOperations = params => {
|
|
|
189
188
|
|
|
190
189
|
const {
|
|
191
190
|
index
|
|
192
|
-
} = _configurations.
|
|
191
|
+
} = _configurations.configurations.es({
|
|
193
192
|
model
|
|
194
193
|
});
|
|
195
194
|
|
|
@@ -204,7 +203,6 @@ const createEntriesStorageOperations = params => {
|
|
|
204
203
|
} catch (ex) {
|
|
205
204
|
throw new _error.default(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
206
205
|
error: ex,
|
|
207
|
-
originalEntry,
|
|
208
206
|
entry,
|
|
209
207
|
storageEntry
|
|
210
208
|
});
|
|
@@ -222,7 +220,6 @@ const createEntriesStorageOperations = params => {
|
|
|
222
220
|
} catch (ex) {
|
|
223
221
|
throw new _error.default(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
224
222
|
error: ex,
|
|
225
|
-
originalEntry,
|
|
226
223
|
entry
|
|
227
224
|
});
|
|
228
225
|
}
|
|
@@ -236,7 +233,6 @@ const createEntriesStorageOperations = params => {
|
|
|
236
233
|
|
|
237
234
|
const update = async (model, params) => {
|
|
238
235
|
const {
|
|
239
|
-
originalEntry,
|
|
240
236
|
entry,
|
|
241
237
|
storageEntry
|
|
242
238
|
} = params;
|
|
@@ -254,7 +250,7 @@ const createEntriesStorageOperations = params => {
|
|
|
254
250
|
|
|
255
251
|
const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
256
252
|
model,
|
|
257
|
-
ids: [
|
|
253
|
+
ids: [entry.id]
|
|
258
254
|
});
|
|
259
255
|
const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
|
|
260
256
|
TYPE: createType()
|
|
@@ -265,7 +261,7 @@ const createEntriesStorageOperations = params => {
|
|
|
265
261
|
|
|
266
262
|
let elasticsearchLatestData = null;
|
|
267
263
|
|
|
268
|
-
if (latestStorageEntry.id ===
|
|
264
|
+
if (latestStorageEntry.id === entry.id) {
|
|
269
265
|
/**
|
|
270
266
|
* First we update the regular DynamoDB table
|
|
271
267
|
*/
|
|
@@ -296,7 +292,6 @@ const createEntriesStorageOperations = params => {
|
|
|
296
292
|
} catch (ex) {
|
|
297
293
|
throw new _error.default(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
|
|
298
294
|
error: ex,
|
|
299
|
-
originalEntry,
|
|
300
295
|
entry,
|
|
301
296
|
storageEntry
|
|
302
297
|
});
|
|
@@ -308,7 +303,7 @@ const createEntriesStorageOperations = params => {
|
|
|
308
303
|
|
|
309
304
|
const {
|
|
310
305
|
index: esIndex
|
|
311
|
-
} = _configurations.
|
|
306
|
+
} = _configurations.configurations.es({
|
|
312
307
|
model
|
|
313
308
|
});
|
|
314
309
|
|
|
@@ -320,7 +315,6 @@ const createEntriesStorageOperations = params => {
|
|
|
320
315
|
} catch (ex) {
|
|
321
316
|
throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch record.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
|
|
322
317
|
error: ex,
|
|
323
|
-
originalEntry,
|
|
324
318
|
entry
|
|
325
319
|
});
|
|
326
320
|
}
|
|
@@ -390,15 +384,15 @@ const createEntriesStorageOperations = params => {
|
|
|
390
384
|
|
|
391
385
|
const deleteRevision = async (model, params) => {
|
|
392
386
|
const {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
entry,
|
|
388
|
+
latestEntry,
|
|
389
|
+
latestStorageEntry
|
|
396
390
|
} = params;
|
|
397
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
391
|
+
const partitionKey = (0, _keys.createPartitionKey)(entry);
|
|
398
392
|
|
|
399
393
|
const {
|
|
400
394
|
index
|
|
401
|
-
} = _configurations.
|
|
395
|
+
} = _configurations.configurations.es({
|
|
402
396
|
model
|
|
403
397
|
});
|
|
404
398
|
/**
|
|
@@ -408,7 +402,7 @@ const createEntriesStorageOperations = params => {
|
|
|
408
402
|
|
|
409
403
|
const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
|
|
410
404
|
model,
|
|
411
|
-
ids: [
|
|
405
|
+
ids: [entry.id]
|
|
412
406
|
});
|
|
413
407
|
/**
|
|
414
408
|
* We need to delete all existing records of the given entry revision.
|
|
@@ -420,14 +414,14 @@ const createEntriesStorageOperations = params => {
|
|
|
420
414
|
*/
|
|
421
415
|
entity.deleteBatch({
|
|
422
416
|
PK: partitionKey,
|
|
423
|
-
SK: (0, _keys.createRevisionSortKey)(
|
|
417
|
+
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
424
418
|
})];
|
|
425
419
|
const esItems = [];
|
|
426
420
|
/**
|
|
427
421
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
428
422
|
*/
|
|
429
423
|
|
|
430
|
-
if (publishedStorageEntry &&
|
|
424
|
+
if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
|
|
431
425
|
items.push(entity.deleteBatch({
|
|
432
426
|
PK: partitionKey,
|
|
433
427
|
SK: (0, _keys.createPublishedSortKey)()
|
|
@@ -438,19 +432,19 @@ const createEntriesStorageOperations = params => {
|
|
|
438
432
|
}));
|
|
439
433
|
}
|
|
440
434
|
|
|
441
|
-
if (
|
|
435
|
+
if (latestEntry && latestStorageEntry) {
|
|
442
436
|
const esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
443
437
|
plugins,
|
|
444
438
|
model,
|
|
445
|
-
entry: (0, _cloneDeep.default)(
|
|
446
|
-
storageEntry: (0, _cloneDeep.default)(
|
|
439
|
+
entry: (0, _cloneDeep.default)(latestEntry),
|
|
440
|
+
storageEntry: (0, _cloneDeep.default)(latestStorageEntry)
|
|
447
441
|
});
|
|
448
442
|
const esLatestData = await getESLatestEntryData(plugins, esEntry);
|
|
449
443
|
/**
|
|
450
444
|
* In the end we need to set the new latest entry
|
|
451
445
|
*/
|
|
452
446
|
|
|
453
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({},
|
|
447
|
+
items.push(entity.putBatch(_objectSpread(_objectSpread({}, latestStorageEntry), {}, {
|
|
454
448
|
PK: partitionKey,
|
|
455
449
|
SK: (0, _keys.createLatestSortKey)(),
|
|
456
450
|
TYPE: createLatestType()
|
|
@@ -474,9 +468,9 @@ const createEntriesStorageOperations = params => {
|
|
|
474
468
|
} catch (ex) {
|
|
475
469
|
throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
476
470
|
error: ex,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
471
|
+
entry,
|
|
472
|
+
latestEntry,
|
|
473
|
+
latestStorageEntry
|
|
480
474
|
});
|
|
481
475
|
}
|
|
482
476
|
|
|
@@ -492,9 +486,9 @@ const createEntriesStorageOperations = params => {
|
|
|
492
486
|
} catch (ex) {
|
|
493
487
|
throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
494
488
|
error: ex,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
489
|
+
entry,
|
|
490
|
+
latestEntry,
|
|
491
|
+
latestStorageEntry
|
|
498
492
|
});
|
|
499
493
|
}
|
|
500
494
|
};
|
|
@@ -504,7 +498,7 @@ const createEntriesStorageOperations = params => {
|
|
|
504
498
|
|
|
505
499
|
const {
|
|
506
500
|
index
|
|
507
|
-
} = _configurations.
|
|
501
|
+
} = _configurations.configurations.es({
|
|
508
502
|
model
|
|
509
503
|
});
|
|
510
504
|
|
|
@@ -639,7 +633,7 @@ const createEntriesStorageOperations = params => {
|
|
|
639
633
|
|
|
640
634
|
const {
|
|
641
635
|
index
|
|
642
|
-
} = _configurations.
|
|
636
|
+
} = _configurations.configurations.es({
|
|
643
637
|
model
|
|
644
638
|
});
|
|
645
639
|
|
|
@@ -800,7 +794,7 @@ const createEntriesStorageOperations = params => {
|
|
|
800
794
|
if (latestStorageEntry.id === entry.id) {
|
|
801
795
|
const {
|
|
802
796
|
index
|
|
803
|
-
} = _configurations.
|
|
797
|
+
} = _configurations.configurations.es({
|
|
804
798
|
model
|
|
805
799
|
});
|
|
806
800
|
|
|
@@ -860,8 +854,7 @@ const createEntriesStorageOperations = params => {
|
|
|
860
854
|
const requestReview = async (model, params) => {
|
|
861
855
|
const {
|
|
862
856
|
entry,
|
|
863
|
-
storageEntry
|
|
864
|
-
originalEntry
|
|
857
|
+
storageEntry
|
|
865
858
|
} = params;
|
|
866
859
|
/**
|
|
867
860
|
* We need the latest entry to check if it needs to be updated.
|
|
@@ -880,7 +873,7 @@ const createEntriesStorageOperations = params => {
|
|
|
880
873
|
|
|
881
874
|
const {
|
|
882
875
|
index
|
|
883
|
-
} = _configurations.
|
|
876
|
+
} = _configurations.configurations.es({
|
|
884
877
|
model
|
|
885
878
|
});
|
|
886
879
|
|
|
@@ -906,8 +899,8 @@ const createEntriesStorageOperations = params => {
|
|
|
906
899
|
} catch (ex) {
|
|
907
900
|
throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB table.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
908
901
|
entry,
|
|
909
|
-
|
|
910
|
-
|
|
902
|
+
storageEntry,
|
|
903
|
+
latestStorageEntry
|
|
911
904
|
});
|
|
912
905
|
}
|
|
913
906
|
/**
|
|
@@ -929,8 +922,8 @@ const createEntriesStorageOperations = params => {
|
|
|
929
922
|
} catch (ex) {
|
|
930
923
|
throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
931
924
|
entry,
|
|
932
|
-
|
|
933
|
-
|
|
925
|
+
storageEntry,
|
|
926
|
+
latestStorageEntry
|
|
934
927
|
});
|
|
935
928
|
}
|
|
936
929
|
|
|
@@ -940,8 +933,7 @@ const createEntriesStorageOperations = params => {
|
|
|
940
933
|
const requestChanges = async (model, params) => {
|
|
941
934
|
const {
|
|
942
935
|
entry,
|
|
943
|
-
storageEntry
|
|
944
|
-
originalEntry
|
|
936
|
+
storageEntry
|
|
945
937
|
} = params;
|
|
946
938
|
/**
|
|
947
939
|
* We need the latest entry to check if it needs to be updated.
|
|
@@ -963,7 +955,7 @@ const createEntriesStorageOperations = params => {
|
|
|
963
955
|
|
|
964
956
|
const {
|
|
965
957
|
index
|
|
966
|
-
} = _configurations.
|
|
958
|
+
} = _configurations.configurations.es({
|
|
967
959
|
model
|
|
968
960
|
});
|
|
969
961
|
|
|
@@ -995,8 +987,7 @@ const createEntriesStorageOperations = params => {
|
|
|
995
987
|
} catch (ex) {
|
|
996
988
|
throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB table.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
997
989
|
entry,
|
|
998
|
-
latestStorageEntry
|
|
999
|
-
originalEntry
|
|
990
|
+
latestStorageEntry
|
|
1000
991
|
});
|
|
1001
992
|
}
|
|
1002
993
|
/**
|
|
@@ -1018,8 +1009,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1018
1009
|
} catch (ex) {
|
|
1019
1010
|
throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
1020
1011
|
entry,
|
|
1021
|
-
latestStorageEntry
|
|
1022
|
-
originalEntry
|
|
1012
|
+
latestStorageEntry
|
|
1023
1013
|
});
|
|
1024
1014
|
}
|
|
1025
1015
|
|