@webiny/api-headless-cms-ddb-es 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866

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.
Files changed (35) hide show
  1. package/configurations.d.ts +1 -1
  2. package/configurations.js.map +1 -1
  3. package/elasticsearch/indexing/longTextIndexing.js +2 -8
  4. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  5. package/index.js +2 -1
  6. package/index.js.map +1 -1
  7. package/operations/entry/elasticsearch/body.js +1 -1
  8. package/operations/entry/elasticsearch/body.js.map +1 -1
  9. package/operations/entry/elasticsearch/fields.d.ts +5 -4
  10. package/operations/entry/elasticsearch/fields.js +73 -41
  11. package/operations/entry/elasticsearch/fields.js.map +1 -1
  12. package/operations/entry/elasticsearch/filtering/exec.js +1 -1
  13. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  14. package/operations/entry/elasticsearch/filtering/path.js +1 -1
  15. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  16. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +1 -1
  17. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
  18. package/operations/entry/elasticsearch/sort.js +5 -6
  19. package/operations/entry/elasticsearch/sort.js.map +1 -1
  20. package/operations/entry/elasticsearch/types.d.ts +3 -3
  21. package/operations/entry/elasticsearch/types.js.map +1 -1
  22. package/operations/entry/index.js +119 -18
  23. package/operations/entry/index.js.map +1 -1
  24. package/package.json +21 -14
  25. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
  26. package/plugins/CmsElasticsearchModelFieldPlugin.js +48 -0
  27. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
  28. package/plugins/index.d.ts +1 -1
  29. package/plugins/index.js +11 -11
  30. package/plugins/index.js.map +1 -1
  31. package/types.d.ts +1 -1
  32. package/types.js.map +1 -1
  33. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
  34. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -18
  35. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
@@ -15,7 +15,7 @@ const createDefaultFilterPlugin = () => {
15
15
  applyFiltering,
16
16
  field
17
17
  } = params;
18
- if (!params.field.isSearchable) {
18
+ if (!params.field.searchable) {
19
19
  const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(".");
20
20
  throw new _error.default(`Field "${identifier}" is not searchable.`);
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"names":["createDefaultFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","ALL","exec","params","applyFiltering","field","isSearchable","identifier","parents","map","p","fieldId","join","WebinyError","name","type"],"sources":["defaultFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport const createDefaultFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: CmsEntryFilterPlugin.ALL,\n exec: params => {\n const { applyFiltering, field } = params;\n if (!params.field.isSearchable) {\n const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(\n \".\"\n );\n throw new WebinyError(`Field \"${identifier}\" is not searchable.`);\n }\n applyFiltering(params);\n }\n });\n\n plugin.name = `${plugin.type}.default.all`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,0CAAoB,CAAC;IACpCC,SAAS,EAAED,0CAAoB,CAACE,GAAG;IACnCC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAc;QAAEC;MAAM,CAAC,GAAGF,MAAM;MACxC,IAAI,CAACA,MAAM,CAACE,KAAK,CAACC,YAAY,EAAE;QAC5B,MAAMC,UAAU,GAAG,CAAC,GAAGF,KAAK,CAACG,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEN,KAAK,CAACA,KAAK,CAACM,OAAO,CAAC,CAACC,IAAI,CAC/E,GAAG,CACN;QACD,MAAM,IAAIC,cAAW,CAAE,UAASN,UAAW,sBAAqB,CAAC;MACrE;MACAH,cAAc,CAACD,MAAM,CAAC;IAC1B;EACJ,CAAC,CAAC;EAEFL,MAAM,CAACgB,IAAI,GAAI,GAAEhB,MAAM,CAACiB,IAAK,cAAa;EAE1C,OAAOjB,MAAM;AACjB,CAAC;AAAC"}
1
+ {"version":3,"names":["createDefaultFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","ALL","exec","params","applyFiltering","field","searchable","identifier","parents","map","p","fieldId","join","WebinyError","name","type"],"sources":["defaultFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport const createDefaultFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: CmsEntryFilterPlugin.ALL,\n exec: params => {\n const { applyFiltering, field } = params;\n if (!params.field.searchable) {\n const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(\n \".\"\n );\n throw new WebinyError(`Field \"${identifier}\" is not searchable.`);\n }\n applyFiltering(params);\n }\n });\n\n plugin.name = `${plugin.type}.default.all`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,0CAAoB,CAAC;IACpCC,SAAS,EAAED,0CAAoB,CAACE,GAAG;IACnCC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAc;QAAEC;MAAM,CAAC,GAAGF,MAAM;MACxC,IAAI,CAACA,MAAM,CAACE,KAAK,CAACC,UAAU,EAAE;QAC1B,MAAMC,UAAU,GAAG,CAAC,GAAGF,KAAK,CAACG,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEN,KAAK,CAACA,KAAK,CAACM,OAAO,CAAC,CAACC,IAAI,CAC/E,GAAG,CACN;QACD,MAAM,IAAIC,cAAW,CAAE,UAASN,UAAW,sBAAqB,CAAC;MACrE;MACAH,cAAc,CAACD,MAAM,CAAC;IAC1B;EACJ,CAAC,CAAC;EAEFL,MAAM,CAACgB,IAAI,GAAI,GAAEhB,MAAM,CAACiB,IAAK,cAAa;EAE1C,OAAOjB,MAAM;AACjB,CAAC;AAAC"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createElasticsearchSort = void 0;
7
- var _plugins = require("../../../plugins");
8
7
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
9
8
  var _keyword = require("./keyword");
10
9
  var _search = require("./plugins/search");
@@ -48,18 +47,18 @@ const createElasticsearchSort = params => {
48
47
  /**
49
48
  * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.
50
49
  */
51
- plugins[fieldId] = new _plugins.CmsEntryElasticsearchFieldPlugin({
50
+ plugins[fieldId] = new _apiElasticsearch.ElasticsearchFieldPlugin({
52
51
  unmappedType: field.unmappedType,
53
52
  keyword: (0, _keyword.hasKeyword)(field),
54
- sortable: field.isSortable,
55
- searchable: field.isSearchable,
53
+ sortable: field.sortable,
54
+ searchable: field.searchable,
56
55
  field: fieldId,
57
56
  path
58
57
  });
59
58
  return plugins;
60
59
  }, {
61
- ["*"]: new _plugins.CmsEntryElasticsearchFieldPlugin({
62
- field: _plugins.CmsEntryElasticsearchFieldPlugin.ALL,
60
+ ["*"]: new _apiElasticsearch.ElasticsearchFieldPlugin({
61
+ field: _apiElasticsearch.ElasticsearchFieldPlugin.ALL,
63
62
  keyword: false
64
63
  })
65
64
  });
@@ -1 +1 @@
1
- {"version":3,"names":["createElasticsearchSort","params","sort","modelFields","plugins","length","searchPlugins","createSearchPluginList","createFieldPath","createFieldPathFactory","fieldIdToStorageIdIdMap","sortPlugins","Object","values","reduce","field","parents","fieldId","storageId","path","key","value","keyword","CmsEntryElasticsearchFieldPlugin","unmappedType","hasKeyword","sortable","isSortable","searchable","isSearchable","ALL","transformedSort","map","matched","match","order","filter","Boolean","createSort","fieldPlugins"],"sources":["sort.ts"],"sourcesContent":["import { Sort as esSort } from \"@webiny/api-elasticsearch/types\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins\";\nimport { createSort } from \"@webiny/api-elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListSort, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"./types\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\n\ninterface Params {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n model: CmsModel;\n}\nexport const createElasticsearchSort = (params: Params): esSort => {\n const { sort, modelFields, plugins } = params;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const searchPlugins = createSearchPluginList({\n plugins\n });\n\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce<\n Record<string, CmsEntryElasticsearchFieldPlugin>\n >(\n (plugins, field) => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return plugins;\n }\n const { fieldId, storageId } = field.field;\n\n fieldIdToStorageIdIdMap[fieldId] = fieldId;\n\n const { path } = createFieldPath({\n key: storageId,\n field,\n value: \"\",\n keyword: false\n });\n /**\n * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.\n */\n plugins[fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: field.unmappedType,\n keyword: hasKeyword(field),\n sortable: field.isSortable,\n searchable: field.isSearchable,\n field: fieldId,\n path\n });\n return plugins;\n },\n {\n [\"*\"]: new CmsEntryElasticsearchFieldPlugin({\n field: CmsEntryElasticsearchFieldPlugin.ALL,\n keyword: false\n })\n }\n );\n\n const transformedSort = sort\n .map(value => {\n const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!matched) {\n return null;\n }\n const [, fieldId, order] = matched;\n if (fieldIdToStorageIdIdMap[fieldId]) {\n return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n"],"mappings":";;;;;;AACA;AACA;AAIA;AACA;AACA;AAQO,MAAMA,uBAAuB,GAAIC,MAAc,IAAa;EAC/D,MAAM;IAAEC,IAAI;IAAEC,WAAW;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAE7C,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAO,EAAE;EACb;EAEA,MAAMC,aAAa,GAAG,IAAAC,8BAAsB,EAAC;IACzCH;EACJ,CAAC,CAAC;EAEF,MAAMI,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CL,OAAO,EAAEE;EACb,CAAC,CAAC;EAEF,MAAMI,uBAA+C,GAAG,CAAC,CAAC;EAE1D,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACV,WAAW,CAAC,CAACW,MAAM,CAGjD,CAACV,OAAO,EAAEW,KAAK,KAAK;IAChB;AACZ;AACA;IACY,IAAIA,KAAK,CAACC,OAAO,CAACX,MAAM,GAAG,CAAC,EAAE;MAC1B,OAAOD,OAAO;IAClB;IACA,MAAM;MAAEa,OAAO;MAAEC;IAAU,CAAC,GAAGH,KAAK,CAACA,KAAK;IAE1CL,uBAAuB,CAACO,OAAO,CAAC,GAAGA,OAAO;IAE1C,MAAM;MAAEE;IAAK,CAAC,GAAGX,eAAe,CAAC;MAC7BY,GAAG,EAAEF,SAAS;MACdH,KAAK;MACLM,KAAK,EAAE,EAAE;MACTC,OAAO,EAAE;IACb,CAAC,CAAC;IACF;AACZ;AACA;IACYlB,OAAO,CAACa,OAAO,CAAC,GAAG,IAAIM,yCAAgC,CAAC;MACpDC,YAAY,EAAET,KAAK,CAACS,YAAY;MAChCF,OAAO,EAAE,IAAAG,mBAAU,EAACV,KAAK,CAAC;MAC1BW,QAAQ,EAAEX,KAAK,CAACY,UAAU;MAC1BC,UAAU,EAAEb,KAAK,CAACc,YAAY;MAC9Bd,KAAK,EAAEE,OAAO;MACdE;IACJ,CAAC,CAAC;IACF,OAAOf,OAAO;EAClB,CAAC,EACD;IACI,CAAC,GAAG,GAAG,IAAImB,yCAAgC,CAAC;MACxCR,KAAK,EAAEQ,yCAAgC,CAACO,GAAG;MAC3CR,OAAO,EAAE;IACb,CAAC;EACL,CAAC,CACJ;EAED,MAAMS,eAAe,GAAG7B,IAAI,CACvB8B,GAAG,CAACX,KAAK,IAAI;IACV,MAAMY,OAAO,GAAGZ,KAAK,CAACa,KAAK,CAAC,+BAA+B,CAAC;IAC5D,IAAI,CAACD,OAAO,EAAE;MACV,OAAO,IAAI;IACf;IACA,MAAM,GAAGhB,OAAO,EAAEkB,KAAK,CAAC,GAAGF,OAAO;IAClC,IAAIvB,uBAAuB,CAACO,OAAO,CAAC,EAAE;MAClC,OAAQ,GAAEP,uBAAuB,CAACO,OAAO,CAAE,IAAGkB,KAAM,EAAC;IACzD;IAEA,OAAOd,KAAK;EAChB,CAAC,CAAC,CACDe,MAAM,CAACC,OAAO,CAAa;EAChC,OAAO,IAAAC,4BAAU,EAAC;IACdC,YAAY,EAAE5B,WAAW;IACzBT,IAAI,EAAE6B;EACV,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["createElasticsearchSort","params","sort","modelFields","plugins","length","searchPlugins","createSearchPluginList","createFieldPath","createFieldPathFactory","fieldIdToStorageIdIdMap","sortPlugins","Object","values","reduce","field","parents","fieldId","storageId","path","key","value","keyword","ElasticsearchFieldPlugin","unmappedType","hasKeyword","sortable","searchable","ALL","transformedSort","map","matched","match","order","filter","Boolean","createSort","fieldPlugins"],"sources":["sort.ts"],"sourcesContent":["import { Sort as esSort } from \"@webiny/api-elasticsearch/types\";\nimport { createSort, ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListSort, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"./types\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\n\ninterface Params {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n model: CmsModel;\n}\nexport const createElasticsearchSort = (params: Params): esSort => {\n const { sort, modelFields, plugins } = params;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const searchPlugins = createSearchPluginList({\n plugins\n });\n\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce<Record<string, ElasticsearchFieldPlugin>>(\n (plugins, field) => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return plugins;\n }\n const { fieldId, storageId } = field.field;\n\n fieldIdToStorageIdIdMap[fieldId] = fieldId;\n\n const { path } = createFieldPath({\n key: storageId,\n field,\n value: \"\",\n keyword: false\n });\n /**\n * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.\n */\n plugins[fieldId] = new ElasticsearchFieldPlugin({\n unmappedType: field.unmappedType,\n keyword: hasKeyword(field),\n sortable: field.sortable,\n searchable: field.searchable,\n field: fieldId,\n path\n });\n return plugins;\n },\n {\n [\"*\"]: new ElasticsearchFieldPlugin({\n field: ElasticsearchFieldPlugin.ALL,\n keyword: false\n })\n }\n );\n\n const transformedSort = sort\n .map(value => {\n const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!matched) {\n return null;\n }\n const [, fieldId, order] = matched;\n if (fieldIdToStorageIdIdMap[fieldId]) {\n return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n"],"mappings":";;;;;;AACA;AAIA;AACA;AACA;AAQO,MAAMA,uBAAuB,GAAIC,MAAc,IAAa;EAC/D,MAAM;IAAEC,IAAI;IAAEC,WAAW;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAE7C,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAO,EAAE;EACb;EAEA,MAAMC,aAAa,GAAG,IAAAC,8BAAsB,EAAC;IACzCH;EACJ,CAAC,CAAC;EAEF,MAAMI,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CL,OAAO,EAAEE;EACb,CAAC,CAAC;EAEF,MAAMI,uBAA+C,GAAG,CAAC,CAAC;EAE1D,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACV,WAAW,CAAC,CAACW,MAAM,CACjD,CAACV,OAAO,EAAEW,KAAK,KAAK;IAChB;AACZ;AACA;IACY,IAAIA,KAAK,CAACC,OAAO,CAACX,MAAM,GAAG,CAAC,EAAE;MAC1B,OAAOD,OAAO;IAClB;IACA,MAAM;MAAEa,OAAO;MAAEC;IAAU,CAAC,GAAGH,KAAK,CAACA,KAAK;IAE1CL,uBAAuB,CAACO,OAAO,CAAC,GAAGA,OAAO;IAE1C,MAAM;MAAEE;IAAK,CAAC,GAAGX,eAAe,CAAC;MAC7BY,GAAG,EAAEF,SAAS;MACdH,KAAK;MACLM,KAAK,EAAE,EAAE;MACTC,OAAO,EAAE;IACb,CAAC,CAAC;IACF;AACZ;AACA;IACYlB,OAAO,CAACa,OAAO,CAAC,GAAG,IAAIM,0CAAwB,CAAC;MAC5CC,YAAY,EAAET,KAAK,CAACS,YAAY;MAChCF,OAAO,EAAE,IAAAG,mBAAU,EAACV,KAAK,CAAC;MAC1BW,QAAQ,EAAEX,KAAK,CAACW,QAAQ;MACxBC,UAAU,EAAEZ,KAAK,CAACY,UAAU;MAC5BZ,KAAK,EAAEE,OAAO;MACdE;IACJ,CAAC,CAAC;IACF,OAAOf,OAAO;EAClB,CAAC,EACD;IACI,CAAC,GAAG,GAAG,IAAImB,0CAAwB,CAAC;MAChCR,KAAK,EAAEQ,0CAAwB,CAACK,GAAG;MACnCN,OAAO,EAAE;IACb,CAAC;EACL,CAAC,CACJ;EAED,MAAMO,eAAe,GAAG3B,IAAI,CACvB4B,GAAG,CAACT,KAAK,IAAI;IACV,MAAMU,OAAO,GAAGV,KAAK,CAACW,KAAK,CAAC,+BAA+B,CAAC;IAC5D,IAAI,CAACD,OAAO,EAAE;MACV,OAAO,IAAI;IACf;IACA,MAAM,GAAGd,OAAO,EAAEgB,KAAK,CAAC,GAAGF,OAAO;IAClC,IAAIrB,uBAAuB,CAACO,OAAO,CAAC,EAAE;MAClC,OAAQ,GAAEP,uBAAuB,CAACO,OAAO,CAAE,IAAGgB,KAAM,EAAC;IACzD;IAEA,OAAOZ,KAAK;EAChB,CAAC,CAAC,CACDa,MAAM,CAACC,OAAO,CAAa;EAChC,OAAO,IAAAC,4BAAU,EAAC;IACdC,YAAY,EAAE1B,WAAW;IACzBT,IAAI,EAAE2B;EACV,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -14,10 +14,10 @@ export interface ModelFieldParent {
14
14
  export interface ModelField {
15
15
  unmappedType?: string;
16
16
  keyword?: boolean;
17
- isSearchable: boolean;
18
- isSortable: boolean;
17
+ searchable: boolean;
18
+ sortable: boolean;
19
19
  type: FieldType;
20
- isSystemField?: boolean;
20
+ systemField?: boolean;
21
21
  field: CmsModelField;
22
22
  path?: ModelFieldPath;
23
23
  fullTextSearch?: boolean;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from \"~/plugins\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\n/**\n * ./fields\n */\ntype ModelFieldPath = string | ((value: string) => string);\n\nexport type FieldType = \"text\" | \"date\" | \"datetime\" | \"time\" | \"number\" | \"boolean\" | string;\n\nexport interface ModelFieldParent {\n fieldId: string;\n storageId: string;\n type: FieldType;\n}\nexport interface ModelField {\n unmappedType?: string;\n keyword?: boolean;\n isSearchable: boolean;\n isSortable: boolean;\n type: FieldType;\n isSystemField?: boolean;\n field: CmsModelField;\n path?: ModelFieldPath;\n fullTextSearch?: boolean;\n parents: ModelFieldParent[];\n}\n\nexport interface ModelFields {\n [fieldId: string]: ModelField;\n}\n\n/**\n * ./plugins/operator\n */\nexport interface ElasticsearchQueryBuilderOperatorPlugins {\n [key: string]: ElasticsearchQueryBuilderOperatorPlugin;\n}\n/**\n * ./plugins/search\n */\nexport interface ElasticsearchQuerySearchValuePlugins {\n [fieldType: string]: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from \"~/plugins\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\n/**\n * ./fields\n */\ntype ModelFieldPath = string | ((value: string) => string);\n\nexport type FieldType = \"text\" | \"date\" | \"datetime\" | \"time\" | \"number\" | \"boolean\" | string;\n\nexport interface ModelFieldParent {\n fieldId: string;\n storageId: string;\n type: FieldType;\n}\nexport interface ModelField {\n unmappedType?: string;\n keyword?: boolean;\n searchable: boolean;\n sortable: boolean;\n type: FieldType;\n systemField?: boolean;\n field: CmsModelField;\n path?: ModelFieldPath;\n fullTextSearch?: boolean;\n parents: ModelFieldParent[];\n}\n\nexport interface ModelFields {\n [fieldId: string]: ModelField;\n}\n\n/**\n * ./plugins/operator\n */\nexport interface ElasticsearchQueryBuilderOperatorPlugins {\n [key: string]: ElasticsearchQueryBuilderOperatorPlugin;\n}\n/**\n * ./plugins/search\n */\nexport interface ElasticsearchQuerySearchValuePlugins {\n [fieldType: string]: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n}\n"],"mappings":""}
@@ -21,6 +21,7 @@ var _utils = require("@webiny/utils");
21
21
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
22
22
  var _body = require("./elasticsearch/body");
23
23
  var _recordType = require("./recordType");
24
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
24
25
  const getEntryData = input => {
25
26
  const output = (0, _objectSpread2.default)({}, input);
26
27
  delete output["PK"];
@@ -76,14 +77,27 @@ const createEntriesStorageOperations = params => {
76
77
  elasticsearch,
77
78
  plugins
78
79
  } = params;
80
+ let storageOperationsCmsModelPlugin;
81
+ const getStorageOperationsCmsModelPlugin = () => {
82
+ if (storageOperationsCmsModelPlugin) {
83
+ return storageOperationsCmsModelPlugin;
84
+ }
85
+ storageOperationsCmsModelPlugin = plugins.oneByType(_apiHeadlessCms.StorageOperationsCmsModelPlugin.type);
86
+ return storageOperationsCmsModelPlugin;
87
+ };
88
+ const getStorageOperationsModel = model => {
89
+ const plugin = getStorageOperationsCmsModelPlugin();
90
+ return plugin.getModel(model);
91
+ };
79
92
  const dataLoaders = new _dataLoaders.DataLoadersHandler({
80
93
  entity
81
94
  });
82
- const create = async (model, params) => {
95
+ const create = async (initialModel, params) => {
83
96
  const {
84
97
  entry: initialEntry,
85
98
  storageEntry: initialStorageEntry
86
99
  } = params;
100
+ const model = getStorageOperationsModel(initialModel);
87
101
  const isPublished = initialEntry.status === "published";
88
102
  const locked = isPublished ? true : initialEntry.locked;
89
103
  const entry = convertEntryKeysToStorage({
@@ -190,11 +204,12 @@ const createEntriesStorageOperations = params => {
190
204
  }
191
205
  return initialStorageEntry;
192
206
  };
193
- const createRevisionFrom = async (model, params) => {
207
+ const createRevisionFrom = async (initialModel, params) => {
194
208
  const {
195
209
  entry: initialEntry,
196
210
  storageEntry: initialStorageEntry
197
211
  } = params;
212
+ const model = getStorageOperationsModel(initialModel);
198
213
  const entry = convertEntryKeysToStorage({
199
214
  model,
200
215
  entry: initialEntry
@@ -270,11 +285,12 @@ const createEntriesStorageOperations = params => {
270
285
  */
271
286
  return initialStorageEntry;
272
287
  };
273
- const update = async (model, params) => {
288
+ const update = async (initialModel, params) => {
274
289
  const {
275
290
  entry: initialEntry,
276
291
  storageEntry: initialStorageEntry
277
292
  } = params;
293
+ const model = getStorageOperationsModel(initialModel);
278
294
  const entry = convertEntryKeysToStorage({
279
295
  model,
280
296
  entry: initialEntry
@@ -436,10 +452,11 @@ const createEntriesStorageOperations = params => {
436
452
  }
437
453
  return initialStorageEntry;
438
454
  };
439
- const deleteEntry = async (model, params) => {
455
+ const deleteEntry = async (initialModel, params) => {
440
456
  const {
441
457
  entry
442
458
  } = params;
459
+ const model = getStorageOperationsModel(initialModel);
443
460
  const partitionKey = (0, _keys.createPartitionKey)({
444
461
  id: entry.id,
445
462
  locale: model.locale,
@@ -497,12 +514,13 @@ const createEntriesStorageOperations = params => {
497
514
  });
498
515
  }
499
516
  };
500
- const deleteRevision = async (model, params) => {
517
+ const deleteRevision = async (initialModel, params) => {
501
518
  const {
502
519
  entry,
503
520
  latestEntry,
504
521
  latestStorageEntry
505
522
  } = params;
523
+ const model = getStorageOperationsModel(initialModel);
506
524
  const partitionKey = (0, _keys.createPartitionKey)({
507
525
  id: entry.id,
508
526
  locale: model.locale,
@@ -602,8 +620,9 @@ const createEntriesStorageOperations = params => {
602
620
  });
603
621
  }
604
622
  };
605
- const list = async (model, params) => {
623
+ const list = async (initialModel, params) => {
606
624
  var _response, _response$body;
625
+ const model = getStorageOperationsModel(initialModel);
607
626
  const limit = (0, _apiElasticsearch.createLimit)(params.limit, 50);
608
627
  const {
609
628
  index
@@ -683,7 +702,8 @@ const createEntriesStorageOperations = params => {
683
702
  items
684
703
  };
685
704
  };
686
- const get = async (model, params) => {
705
+ const get = async (initialModel, params) => {
706
+ const model = getStorageOperationsModel(initialModel);
687
707
  const {
688
708
  items
689
709
  } = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
@@ -691,11 +711,12 @@ const createEntriesStorageOperations = params => {
691
711
  }));
692
712
  return items.shift() || null;
693
713
  };
694
- const publish = async (model, params) => {
714
+ const publish = async (initialModel, params) => {
695
715
  const {
696
716
  entry: initialEntry,
697
717
  storageEntry: initialStorageEntry
698
718
  } = params;
719
+ const model = getStorageOperationsModel(initialModel);
699
720
  const entry = convertEntryKeysToStorage({
700
721
  model,
701
722
  entry: initialEntry
@@ -873,11 +894,12 @@ const createEntriesStorageOperations = params => {
873
894
  }
874
895
  return initialStorageEntry;
875
896
  };
876
- const unpublish = async (model, params) => {
897
+ const unpublish = async (initialModel, params) => {
877
898
  const {
878
899
  entry: initialEntry,
879
900
  storageEntry: initialStorageEntry
880
901
  } = params;
902
+ const model = getStorageOperationsModel(initialModel);
881
903
  const entry = convertEntryKeysToStorage({
882
904
  model,
883
905
  entry: initialEntry
@@ -968,7 +990,8 @@ const createEntriesStorageOperations = params => {
968
990
  }
969
991
  return initialStorageEntry;
970
992
  };
971
- const getLatestRevisionByEntryId = async (model, params) => {
993
+ const getLatestRevisionByEntryId = async (initialModel, params) => {
994
+ const model = getStorageOperationsModel(initialModel);
972
995
  const [entry] = await dataLoaders.getLatestRevisionByEntryId({
973
996
  model,
974
997
  ids: [params.id]
@@ -981,7 +1004,8 @@ const createEntriesStorageOperations = params => {
981
1004
  entry
982
1005
  });
983
1006
  };
984
- const getPublishedRevisionByEntryId = async (model, params) => {
1007
+ const getPublishedRevisionByEntryId = async (initialModel, params) => {
1008
+ const model = getStorageOperationsModel(initialModel);
985
1009
  const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
986
1010
  model,
987
1011
  ids: [params.id]
@@ -994,7 +1018,8 @@ const createEntriesStorageOperations = params => {
994
1018
  entry
995
1019
  });
996
1020
  };
997
- const getRevisionById = async (model, params) => {
1021
+ const getRevisionById = async (initialModel, params) => {
1022
+ const model = getStorageOperationsModel(initialModel);
998
1023
  const [entry] = await dataLoaders.getRevisionById({
999
1024
  model,
1000
1025
  ids: [params.id]
@@ -1007,7 +1032,8 @@ const createEntriesStorageOperations = params => {
1007
1032
  entry
1008
1033
  });
1009
1034
  };
1010
- const getRevisions = async (model, params) => {
1035
+ const getRevisions = async (initialModel, params) => {
1036
+ const model = getStorageOperationsModel(initialModel);
1011
1037
  const entries = await dataLoaders.getAllEntryRevisions({
1012
1038
  model,
1013
1039
  ids: [params.id]
@@ -1019,7 +1045,8 @@ const createEntriesStorageOperations = params => {
1019
1045
  });
1020
1046
  });
1021
1047
  };
1022
- const getByIds = async (model, params) => {
1048
+ const getByIds = async (initialModel, params) => {
1049
+ const model = getStorageOperationsModel(initialModel);
1023
1050
  const entries = await dataLoaders.getRevisionById({
1024
1051
  model,
1025
1052
  ids: params.ids
@@ -1031,7 +1058,8 @@ const createEntriesStorageOperations = params => {
1031
1058
  });
1032
1059
  });
1033
1060
  };
1034
- const getLatestByIds = async (model, params) => {
1061
+ const getLatestByIds = async (initialModel, params) => {
1062
+ const model = getStorageOperationsModel(initialModel);
1035
1063
  const entries = await dataLoaders.getLatestRevisionByEntryId({
1036
1064
  model,
1037
1065
  ids: params.ids
@@ -1043,7 +1071,8 @@ const createEntriesStorageOperations = params => {
1043
1071
  });
1044
1072
  });
1045
1073
  };
1046
- const getPublishedByIds = async (model, params) => {
1074
+ const getPublishedByIds = async (initialModel, params) => {
1075
+ const model = getStorageOperationsModel(initialModel);
1047
1076
  const entries = await dataLoaders.getPublishedRevisionByEntryId({
1048
1077
  model,
1049
1078
  ids: params.ids
@@ -1055,7 +1084,8 @@ const createEntriesStorageOperations = params => {
1055
1084
  });
1056
1085
  });
1057
1086
  };
1058
- const getPreviousRevision = async (model, params) => {
1087
+ const getPreviousRevision = async (initialModel, params) => {
1088
+ const model = getStorageOperationsModel(initialModel);
1059
1089
  const {
1060
1090
  tenant,
1061
1091
  locale
@@ -1105,6 +1135,76 @@ const createEntriesStorageOperations = params => {
1105
1135
  }));
1106
1136
  }
1107
1137
  };
1138
+ const getUniqueFieldValues = async (model, params) => {
1139
+ const {
1140
+ where,
1141
+ fieldId
1142
+ } = params;
1143
+ const {
1144
+ index
1145
+ } = _configurations.configurations.es({
1146
+ model
1147
+ });
1148
+ try {
1149
+ const result = await elasticsearch.indices.exists({
1150
+ index
1151
+ });
1152
+ if (!(result !== null && result !== void 0 && result.body)) {
1153
+ return [];
1154
+ }
1155
+ } catch (ex) {
1156
+ throw new _error.default("Could not determine if Elasticsearch index exists.", "ELASTICSEARCH_INDEX_CHECK_ERROR", {
1157
+ error: ex,
1158
+ index
1159
+ });
1160
+ }
1161
+ const initialBody = (0, _body.createElasticsearchBody)({
1162
+ model,
1163
+ params: {
1164
+ limit: 1,
1165
+ where
1166
+ },
1167
+ plugins
1168
+ });
1169
+ const field = model.fields.find(f => f.fieldId === fieldId);
1170
+ if (!field) {
1171
+ throw new _error.default(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
1172
+ fieldId
1173
+ });
1174
+ }
1175
+ const body = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialBody), {}, {
1176
+ /**
1177
+ * We do not need any hits returned, we only need the aggregations.
1178
+ */
1179
+ size: 0,
1180
+ aggregations: {
1181
+ getUniqueFieldValues: {
1182
+ terms: {
1183
+ field: `values.${field.storageId}.keyword`,
1184
+ size: 1000000
1185
+ }
1186
+ }
1187
+ }
1188
+ });
1189
+ let response = undefined;
1190
+ try {
1191
+ response = await elasticsearch.search({
1192
+ index,
1193
+ body
1194
+ });
1195
+ } catch (ex) {
1196
+ throw new _error.default(ex.message || "Error in the Elasticsearch query.", ex.code || "ELASTICSEARCH_ERROR", {
1197
+ error: ex,
1198
+ index,
1199
+ model,
1200
+ body
1201
+ });
1202
+ }
1203
+ const values = response.body.aggregations["getUniqueFieldValues"] || {
1204
+ buckets: []
1205
+ };
1206
+ return values.buckets.map(item => item.key) || [];
1207
+ };
1108
1208
  return {
1109
1209
  create,
1110
1210
  createRevisionFrom,
@@ -1122,7 +1222,8 @@ const createEntriesStorageOperations = params => {
1122
1222
  getByIds,
1123
1223
  getLatestByIds,
1124
1224
  getPublishedByIds,
1125
- getPreviousRevision
1225
+ getPreviousRevision,
1226
+ getUniqueFieldValues
1126
1227
  };
1127
1228
  };
1128
1229
  exports.createEntriesStorageOperations = createEntriesStorageOperations;