@webiny/api-elasticsearch 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c59b9cc5b9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-elasticsearch",
3
- "version": "0.0.0-unstable.bca7b3e350",
3
+ "version": "0.0.0-unstable.c59b9cc5b9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/webiny/webiny-js.git",
@@ -13,21 +13,21 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@elastic/elasticsearch": "7.12.0",
16
- "@webiny/api": "0.0.0-unstable.bca7b3e350",
17
- "@webiny/error": "0.0.0-unstable.bca7b3e350",
18
- "@webiny/plugins": "0.0.0-unstable.bca7b3e350",
19
- "@webiny/utils": "0.0.0-unstable.bca7b3e350",
16
+ "@webiny/api": "0.0.0-unstable.c59b9cc5b9",
17
+ "@webiny/error": "0.0.0-unstable.c59b9cc5b9",
18
+ "@webiny/plugins": "0.0.0-unstable.c59b9cc5b9",
19
+ "@webiny/utils": "0.0.0-unstable.c59b9cc5b9",
20
20
  "aws-elasticsearch-connector": "9.2.0",
21
21
  "aws-sdk": "2.1310.0",
22
22
  "elastic-ts": "0.8.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/cli": "^7.16.0",
26
- "@babel/core": "^7.16.0",
27
- "@webiny/cli": "^0.0.0-unstable.bca7b3e350",
28
- "@webiny/project-utils": "^0.0.0-unstable.bca7b3e350",
29
- "rimraf": "^3.0.2",
30
- "ttypescript": "^1.5.12",
25
+ "@babel/cli": "7.20.7",
26
+ "@babel/core": "7.20.12",
27
+ "@webiny/cli": "0.0.0-unstable.c59b9cc5b9",
28
+ "@webiny/project-utils": "0.0.0-unstable.c59b9cc5b9",
29
+ "rimraf": "3.0.2",
30
+ "ttypescript": "1.5.15",
31
31
  "typescript": "4.7.4"
32
32
  },
33
33
  "publishConfig": {
@@ -45,5 +45,5 @@
45
45
  ]
46
46
  }
47
47
  },
48
- "gitHead": "bca7b3e35084d7012061bda0d3f08202fe611581"
48
+ "gitHead": "c59b9cc5b96b7fd91388de93c7fff2d977d25220"
49
49
  }
@@ -48,7 +48,7 @@ export interface ElasticsearchFieldPluginParams {
48
48
  */
49
49
  toSearchValue?: (params: ToSearchValueParams) => any;
50
50
  }
51
- export declare abstract class ElasticsearchFieldPlugin extends Plugin {
51
+ export declare class ElasticsearchFieldPlugin extends Plugin {
52
52
  static readonly type: string;
53
53
  static readonly ALL: string;
54
54
  readonly field: string;
@@ -1 +1 @@
1
- {"version":3,"names":["keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","ElasticsearchFieldPlugin","Plugin","constructor","params","field","path","keyword","undefined","unmappedType","sortable","searchable","getSortOptions","order","options","unmapped_type","getPath","getBasePath","ALL","toSearchValue","value"],"sources":["ElasticsearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FieldSortOptions, SortOrder } from \"elastic-ts\";\n\nexport type UnmappedTypes = \"date\" | \"long\" | string;\n\nconst keywordLessUnmappedType = [\"date\", \"long\"];\n\nconst unmappedTypeHasKeyword = (type?: string): boolean => {\n if (!type) {\n return true;\n } else if (keywordLessUnmappedType.includes(type)) {\n return false;\n }\n return true;\n};\n\nexport interface ToSearchValueParams {\n /**\n * The value to transform.\n */\n value: any;\n /**\n * When using toSearchValue() in our code we send a field.getPath() value here.\n */\n path: string;\n /**\n * When using toSearchValue() in our code we send a field.getBasePath() value here.\n */\n basePath: string;\n}\nexport interface ElasticsearchFieldPluginParams {\n /**\n * Which field is this plugin for.\n */\n field: string;\n /**\n * Some specific path of a field?\n * Example: createdBy is createdBy.id\n */\n path?: string;\n /**\n * Add a .keyword at the end of the field path?\n */\n keyword?: boolean;\n /**\n * Is the field of a specific type, but possibly not mapped?\n * Happens when inserting a date in string format.\n * You need to cast it as date when running the search/sort to work correctly.\n */\n unmappedType?: UnmappedTypes;\n /**\n * Is the field sortable?\n */\n sortable?: boolean;\n /**\n * Is the field searchable?\n */\n searchable?: boolean;\n /**\n * Used to transform the input value for the search.\n */\n toSearchValue?: (params: ToSearchValueParams) => any;\n}\n\nexport abstract class ElasticsearchFieldPlugin extends Plugin {\n public static override readonly type: string = \"elasticsearch.fieldDefinition\";\n public static readonly ALL: string = \"*\";\n\n public readonly field: string;\n public readonly path: string;\n public readonly keyword: boolean;\n public readonly unmappedType?: string;\n public readonly sortable: boolean;\n public readonly searchable: boolean;\n\n constructor(params: ElasticsearchFieldPluginParams) {\n super();\n this.field = params.field;\n this.path = params.path || params.field;\n this.keyword = params.keyword === undefined ? true : params.keyword;\n this.unmappedType = params.unmappedType;\n if (unmappedTypeHasKeyword(params.unmappedType) === false) {\n this.keyword = false;\n }\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this.searchable = params.searchable === undefined ? true : params.searchable;\n }\n /**\n * The default sort options. Extend in your own plugin if you want to add more options.\n */\n public getSortOptions(order: SortOrder): FieldSortOptions {\n const options = {\n order\n };\n if (!this.unmappedType) {\n return options;\n }\n return {\n ...options,\n unmapped_type: this.unmappedType\n };\n }\n /**\n * The default path generator. Extend in your own plugin if you want to add more options.\n * Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.\n */\n public getPath(field: string): string {\n return `${this.getBasePath(field)}${this.keyword ? \".keyword\" : \"\"}`;\n }\n /**\n * @see getPath\n *\n * This is the default base path generator. Basically it replaces ALL with given field name.\n */\n public getBasePath(field: string): string {\n if (this.path === ElasticsearchFieldPlugin.ALL) {\n return field;\n }\n return this.path;\n }\n /**\n * The default transformer. Just returns the value by default.\n * Override to implement what ever is required.\n */\n public toSearchValue(params: ToSearchValueParams): any {\n return params.value;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AAKA,MAAMA,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;AAEhD,MAAMC,sBAAsB,GAAIC,IA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AE,IAAI,CAACE,OAAO,GAAG,UAAU,GAAG,EAAG,EAAC;EACxE;EACA;AACJ;AACA;AACA;AACA;EACWU,WAAW,CAACZ,KAAa,EAAU;IACtC,IAAI,IAAI,CAACC,IAAI,KAAKL,wBAAwB,CAACiB,GAAG,EAAE;MAC5C,OAAOb,KAAK;IAChB;IACA,OAAO,IAAI,CAACC,IAAI;EACpB;EACA;AACJ;AACA;AACA;EACWa,aAAa,CAACf,MAA2B,EAAO;IACnD,OAAOA,MAAM,CAACgB,KAAK;EACvB;AACJ;AAAC;AAAA,8BA/DqBnB,wBAAwB,UACK,+BAA+B;AAAA,8BAD5DA,wBAAwB,SAEL,GAAG"}
1
+ {"version":3,"names":["keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","ElasticsearchFieldPlugin","Plugin","constructor","params","field","path","keyword","undefined","unmappedType","sortable","searchable","getSortOptions","order","options","unmapped_type","getPath","getBasePath","ALL","toSearchValue","value"],"sources":["ElasticsearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FieldSortOptions, SortOrder } from \"elastic-ts\";\n\nexport type UnmappedTypes = \"date\" | \"long\" | string;\n\nconst keywordLessUnmappedType = [\"date\", \"long\"];\n\nconst unmappedTypeHasKeyword = (type?: string): boolean => {\n if (!type) {\n return true;\n } else if (keywordLessUnmappedType.includes(type)) {\n return false;\n }\n return true;\n};\n\nexport interface ToSearchValueParams {\n /**\n * The value to transform.\n */\n value: any;\n /**\n * When using toSearchValue() in our code we send a field.getPath() value here.\n */\n path: string;\n /**\n * When using toSearchValue() in our code we send a field.getBasePath() value here.\n */\n basePath: string;\n}\nexport interface ElasticsearchFieldPluginParams {\n /**\n * Which field is this plugin for.\n */\n field: string;\n /**\n * Some specific path of a field?\n * Example: createdBy is createdBy.id\n */\n path?: string;\n /**\n * Add a .keyword at the end of the field path?\n */\n keyword?: boolean;\n /**\n * Is the field of a specific type, but possibly not mapped?\n * Happens when inserting a date in string format.\n * You need to cast it as date when running the search/sort to work correctly.\n */\n unmappedType?: UnmappedTypes;\n /**\n * Is the field sortable?\n */\n sortable?: boolean;\n /**\n * Is the field searchable?\n */\n searchable?: boolean;\n /**\n * Used to transform the input value for the search.\n */\n toSearchValue?: (params: ToSearchValueParams) => any;\n}\n\nexport class ElasticsearchFieldPlugin extends Plugin {\n public static override readonly type: string = \"elasticsearch.fieldDefinition\";\n public static readonly ALL: string = \"*\";\n\n public readonly field: string;\n public readonly path: string;\n public readonly keyword: boolean;\n public readonly unmappedType?: string;\n public readonly sortable: boolean;\n public readonly searchable: boolean;\n\n constructor(params: ElasticsearchFieldPluginParams) {\n super();\n this.field = params.field;\n this.path = params.path || params.field;\n this.keyword = params.keyword === undefined ? true : params.keyword;\n this.unmappedType = params.unmappedType;\n if (unmappedTypeHasKeyword(params.unmappedType) === false) {\n this.keyword = false;\n }\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this.searchable = params.searchable === undefined ? true : params.searchable;\n }\n /**\n * The default sort options. Extend in your own plugin if you want to add more options.\n */\n public getSortOptions(order: SortOrder): FieldSortOptions {\n const options = {\n order\n };\n if (!this.unmappedType) {\n return options;\n }\n return {\n ...options,\n unmapped_type: this.unmappedType\n };\n }\n /**\n * The default path generator. Extend in your own plugin if you want to add more options.\n * Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.\n */\n public getPath(field: string): string {\n return `${this.getBasePath(field)}${this.keyword ? \".keyword\" : \"\"}`;\n }\n /**\n * @see getPath\n *\n * This is the default base path generator. Basically it replaces ALL with given field name.\n */\n public getBasePath(field: string): string {\n if (this.path === ElasticsearchFieldPlugin.ALL) {\n return field;\n }\n return this.path;\n }\n /**\n * The default transformer. Just returns the value by default.\n * Override to implement what ever is required.\n */\n public toSearchValue(params: ToSearchValueParams): any {\n return params.value;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AAKA,MAAMA,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;AAEhD,MAAMC,sBAAs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K,CAAE,GAAE,IAAI,CAACE,OAAO,GAAG,UAAU,GAAG,EAAG,EAAC;EACxE;EACA;AACJ;AACA;AACA;AACA;EACWU,WAAW,CAACZ,KAAa,EAAU;IACtC,IAAI,IAAI,CAACC,IAAI,KAAKL,wBAAwB,CAACiB,GAAG,EAAE;MAC5C,OAAOb,KAAK;IAChB;IACA,OAAO,IAAI,CAACC,IAAI;EACpB;EACA;AACJ;AACA;AACA;EACWa,aAAa,CAACf,MAA2B,EAAO;IACnD,OAAOA,MAAM,CAACgB,KAAK;EACvB;AACJ;AAAC;AAAA,8BA/DYnB,wBAAwB,UACc,+BAA+B;AAAA,8BADrEA,wBAAwB,SAEI,GAAG"}
package/types.d.ts CHANGED
@@ -64,6 +64,7 @@ export interface ElasticsearchSearchResponseHit<T> {
64
64
  }
65
65
  export interface ElasticsearchSearchResponseAggregationBucket<T> {
66
66
  key: T;
67
+ doc_count: number;
67
68
  }
68
69
  export interface ElasticsearchSearchResponse<T = any> {
69
70
  body: {
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Client, ApiResponse } from \"@elastic/elasticsearch\";\nimport { BoolQueryConfig as esBoolQueryConfig, Query as esQuery } from \"elastic-ts\";\nimport { Context } from \"@webiny/api/types\";\n/**\n * Re-export some dep lib types.\n */\nexport * from \"elastic-ts\";\nexport { ApiResponse };\n\nexport interface ElasticsearchContext extends Context {\n elasticsearch: Client;\n}\n\n/**\n * To simplify our plugins, we say that query contains arrays of objects, not single objects.\n * And that they all are defined as empty arrays at the start.\n */\nexport interface ElasticsearchBoolQueryConfig extends esBoolQueryConfig {\n must: esQuery[];\n filter: esQuery[];\n should: esQuery[];\n must_not: esQuery[];\n}\n\n/**\n * Definitions of possible Elasticsearch operators.\n *\n * @category Elasticsearch\n */\nexport type ElasticsearchQueryOperator =\n | \"eq\"\n | \"not\"\n | \"in\"\n | \"not_in\"\n | \"contains\"\n | \"not_contains\"\n | \"between\"\n | \"not_between\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | string;\n\n/**\n * Definition for arguments of the ElasticsearchQueryBuilderOperatorPlugin.apply method.\n *\n * @see ElasticsearchQueryBuilderOperatorPlugin.apply\n *\n * @category Plugin\n * @category Elasticsearch\n */\nexport interface ElasticsearchQueryBuilderArgsPlugin {\n /**\n * Name of the field.\n */\n name: string;\n /**\n * A full path to the field. Including the \".keyword\" if it is added.\n */\n path: string;\n /**\n * A path to the field, plain.\n */\n basePath: string;\n /**\n * Value to apply.\n */\n value: any;\n /**\n * Is path containing the \".keyword\"\n */\n keyword: boolean;\n}\n\n/**\n * Elasticsearch responses.\n */\nexport interface ElasticsearchSearchResponseHit<T> {\n _source: T;\n sort: string;\n}\nexport interface ElasticsearchSearchResponseAggregationBucket<T> {\n key: T;\n}\nexport interface ElasticsearchSearchResponse<T = any> {\n body: {\n hits: {\n hits: ElasticsearchSearchResponseHit<T>[];\n total: {\n value: number;\n };\n };\n aggregations: {\n [key: string]: {\n buckets: ElasticsearchSearchResponseAggregationBucket<T>[];\n };\n };\n };\n}\n\nexport interface ElasticsearchIndexRequestBodyMappingsDynamicTemplate {\n [key: string]: {\n path_match?: string;\n path_unmatch?: string;\n match_mapping_type?: string;\n match?: string;\n unmatch?: string;\n mapping?: {\n numeric_detection?: boolean;\n date_detection?: boolean;\n type?:\n | \"string\"\n | \"date\"\n | \"binary\"\n | \"boolean\"\n | \"object\"\n | \"ip\"\n | \"geo\"\n | \"long\"\n | \"integer\"\n | \"short\"\n | \"byte\"\n | \"double\"\n | \"float\"\n | \"half_float\"\n | \"scaled_float\"\n | \"unsigned_long\"\n | string;\n search_analyzer?: string;\n analyzer?: string;\n fields?: {\n [key: string]:\n | {\n type: string;\n search_analyzer?: string;\n analyzer?: string;\n ignore_above?: number;\n [key: string]: any;\n }\n | undefined;\n };\n [key: string]: any;\n };\n [key: string]: any;\n };\n}\n\ninterface ElasticsearchIndexRequestBodySettings {\n analysis?: {\n [key: string]: any;\n };\n number_of_shards?: number;\n number_of_routing_shards?: number;\n codec?: string;\n routing_partition_size?: number;\n soft_deletes?: {\n enabled?: boolean;\n retention_lease?: {\n period?: string;\n };\n };\n load_fixed_bitset_filters_eagerly?: boolean;\n shard?: {\n check_on_startup?: boolean | \"checksum\";\n };\n number_of_replicas?: number;\n auto_expand_replicas?: string | \"all\" | false;\n search?: {\n idle?: {\n after?: string;\n };\n };\n refresh_interval?: string;\n max_result_window?: number;\n max_inner_result_window?: number;\n max_rescore_window?: number;\n max_docvalue_fields_search?: number;\n max_script_fields?: number;\n max_ngram_diff?: number;\n max_shingle_diff?: number;\n max_refresh_listeners?: number;\n analyze?: {\n max_token_count?: number;\n };\n highlight?: {\n max_analyzed_offset?: number;\n };\n max_terms_count?: number;\n max_regex_length?: number;\n query?: {\n default_field?: string;\n };\n routing?: {\n allocation?: {\n enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\";\n };\n rebalance?: {\n enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\";\n };\n };\n gc_deletes?: string;\n default_pipeline?: string;\n final_pipeline?: string;\n hidden?: boolean;\n [key: string]: any;\n}\n\nexport interface ElasticsearchIndexRequestBody {\n settings?: {\n index?: Partial<ElasticsearchIndexRequestBodySettings>;\n };\n mappings: {\n numeric_detection?: boolean;\n dynamic_templates?: ElasticsearchIndexRequestBodyMappingsDynamicTemplate[];\n properties?: {\n [key: string]: {\n analyzer?: string;\n type?: string;\n normalizer?: string;\n index?: string;\n fields?: {\n [key: string]: {\n type: string;\n ignore_above?: number;\n search_analyzer?: string;\n analyzer?: string;\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n aliases?: {\n [key: string]: {\n filter?: {\n [key: string]: any;\n };\n index_routing?: string;\n is_hidden?: boolean;\n is_write_index?: boolean;\n routing?: string;\n search_routing?: string;\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAMA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Client, ApiResponse } from \"@elastic/elasticsearch\";\nimport { BoolQueryConfig as esBoolQueryConfig, Query as esQuery } from \"elastic-ts\";\nimport { Context } from \"@webiny/api/types\";\n/**\n * Re-export some dep lib types.\n */\nexport * from \"elastic-ts\";\nexport { ApiResponse };\n\nexport interface ElasticsearchContext extends Context {\n elasticsearch: Client;\n}\n\n/**\n * To simplify our plugins, we say that query contains arrays of objects, not single objects.\n * And that they all are defined as empty arrays at the start.\n */\nexport interface ElasticsearchBoolQueryConfig extends esBoolQueryConfig {\n must: esQuery[];\n filter: esQuery[];\n should: esQuery[];\n must_not: esQuery[];\n}\n\n/**\n * Definitions of possible Elasticsearch operators.\n *\n * @category Elasticsearch\n */\nexport type ElasticsearchQueryOperator =\n | \"eq\"\n | \"not\"\n | \"in\"\n | \"not_in\"\n | \"contains\"\n | \"not_contains\"\n | \"between\"\n | \"not_between\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | string;\n\n/**\n * Definition for arguments of the ElasticsearchQueryBuilderOperatorPlugin.apply method.\n *\n * @see ElasticsearchQueryBuilderOperatorPlugin.apply\n *\n * @category Plugin\n * @category Elasticsearch\n */\nexport interface ElasticsearchQueryBuilderArgsPlugin {\n /**\n * Name of the field.\n */\n name: string;\n /**\n * A full path to the field. Including the \".keyword\" if it is added.\n */\n path: string;\n /**\n * A path to the field, plain.\n */\n basePath: string;\n /**\n * Value to apply.\n */\n value: any;\n /**\n * Is path containing the \".keyword\"\n */\n keyword: boolean;\n}\n\n/**\n * Elasticsearch responses.\n */\nexport interface ElasticsearchSearchResponseHit<T> {\n _source: T;\n sort: string;\n}\nexport interface ElasticsearchSearchResponseAggregationBucket<T> {\n key: T;\n doc_count: number;\n}\nexport interface ElasticsearchSearchResponse<T = any> {\n body: {\n hits: {\n hits: ElasticsearchSearchResponseHit<T>[];\n total: {\n value: number;\n };\n };\n aggregations: {\n [key: string]: {\n buckets: ElasticsearchSearchResponseAggregationBucket<T>[];\n };\n };\n };\n}\n\nexport interface ElasticsearchIndexRequestBodyMappingsDynamicTemplate {\n [key: string]: {\n path_match?: string;\n path_unmatch?: string;\n match_mapping_type?: string;\n match?: string;\n unmatch?: string;\n mapping?: {\n numeric_detection?: boolean;\n date_detection?: boolean;\n type?:\n | \"string\"\n | \"date\"\n | \"binary\"\n | \"boolean\"\n | \"object\"\n | \"ip\"\n | \"geo\"\n | \"long\"\n | \"integer\"\n | \"short\"\n | \"byte\"\n | \"double\"\n | \"float\"\n | \"half_float\"\n | \"scaled_float\"\n | \"unsigned_long\"\n | string;\n search_analyzer?: string;\n analyzer?: string;\n fields?: {\n [key: string]:\n | {\n type: string;\n search_analyzer?: string;\n analyzer?: string;\n ignore_above?: number;\n [key: string]: any;\n }\n | undefined;\n };\n [key: string]: any;\n };\n [key: string]: any;\n };\n}\n\ninterface ElasticsearchIndexRequestBodySettings {\n analysis?: {\n [key: string]: any;\n };\n number_of_shards?: number;\n number_of_routing_shards?: number;\n codec?: string;\n routing_partition_size?: number;\n soft_deletes?: {\n enabled?: boolean;\n retention_lease?: {\n period?: string;\n };\n };\n load_fixed_bitset_filters_eagerly?: boolean;\n shard?: {\n check_on_startup?: boolean | \"checksum\";\n };\n number_of_replicas?: number;\n auto_expand_replicas?: string | \"all\" | false;\n search?: {\n idle?: {\n after?: string;\n };\n };\n refresh_interval?: string;\n max_result_window?: number;\n max_inner_result_window?: number;\n max_rescore_window?: number;\n max_docvalue_fields_search?: number;\n max_script_fields?: number;\n max_ngram_diff?: number;\n max_shingle_diff?: number;\n max_refresh_listeners?: number;\n analyze?: {\n max_token_count?: number;\n };\n highlight?: {\n max_analyzed_offset?: number;\n };\n max_terms_count?: number;\n max_regex_length?: number;\n query?: {\n default_field?: string;\n };\n routing?: {\n allocation?: {\n enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\";\n };\n rebalance?: {\n enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\";\n };\n };\n gc_deletes?: string;\n default_pipeline?: string;\n final_pipeline?: string;\n hidden?: boolean;\n [key: string]: any;\n}\n\nexport interface ElasticsearchIndexRequestBody {\n settings?: {\n index?: Partial<ElasticsearchIndexRequestBodySettings>;\n };\n mappings: {\n numeric_detection?: boolean;\n dynamic_templates?: ElasticsearchIndexRequestBodyMappingsDynamicTemplate[];\n properties?: {\n [key: string]: {\n analyzer?: string;\n type?: string;\n normalizer?: string;\n index?: string;\n fields?: {\n [key: string]: {\n type: string;\n ignore_above?: number;\n search_analyzer?: string;\n analyzer?: string;\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n aliases?: {\n [key: string]: {\n filter?: {\n [key: string]: any;\n };\n index_routing?: string;\n is_hidden?: boolean;\n is_write_index?: boolean;\n routing?: string;\n search_routing?: string;\n };\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAMA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/where.js CHANGED
@@ -14,7 +14,7 @@ const parseWhereKey = key => {
14
14
  throw new Error(`It is not possible to search by key "${key}"`);
15
15
  }
16
16
  const [, field, operation = "eq"] = match;
17
- if (!field.match(/^([a-zA-Z]+)$/)) {
17
+ if (!field.match(/^([a-zA-Z0-9]+)$/)) {
18
18
  throw new Error(`Cannot filter by "${field}".`);
19
19
  }
20
20
  const operator = operation.match(/^_/) ? operation.slice(1) : operation;
package/where.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","slice","ALL","ElasticsearchFieldPlugin","applyWhere","params","query","where","fields","operators","hasOwnProperty","initialValue","undefined","fieldPlugin","WebinyError","operatorPlugin","path","getPath","basePath","getBasePath","value","toSearchValue","apply","name","keyword"],"sources":["where.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins/definition/ElasticsearchFieldPlugin\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: ElasticsearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<ElasticsearchFieldPlugin>;\n operators: Records<ElasticsearchQueryBuilderOperatorPlugin>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\nconst parseWhereKeyRegExp = new RegExp(/^([a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);\n\nexport const parseWhereKey = (key: string): ParseWhereKeyResult => {\n const match = key.match(parseWhereKeyRegExp);\n\n if (!match) {\n throw new Error(`It is not possible to search by key \"${key}\"`);\n }\n\n const [, field, operation = \"eq\"] = match;\n\n if (!field.match(/^([a-zA-Z]+)$/)) {\n throw new Error(`Cannot filter by \"${field}\".`);\n }\n\n const operator = operation.match(/^_/) ? operation.slice(1) : operation;\n\n return { field, operator };\n};\n\nconst ALL = ElasticsearchFieldPlugin.ALL;\n\nexport const applyWhere = (params: ApplyWhereParams): void => {\n const { query, where, fields, operators } = params;\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n const initialValue = where[key];\n /**\n * There is a possibility that undefined is sent as a value, so just skip it.\n */\n if (initialValue === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const fieldPlugin: ElasticsearchFieldPlugin = fields[field] || fields[ALL];\n if (!fieldPlugin) {\n throw new WebinyError(\n `Missing plugin for the field \"${field}\".`,\n \"PLUGIN_WHERE_ERROR\",\n {\n field\n }\n );\n }\n const operatorPlugin = operators[operator];\n if (!operatorPlugin) {\n throw new WebinyError(\n `Missing plugin for the operator \"${operator}\"`,\n \"PLUGIN_WHERE_ERROR\",\n {\n operator\n }\n );\n }\n\n /**\n * Get the path but in the case of * (all fields, replace * with the field.\n * Custom path would return its own value anyways.\n */\n const path = fieldPlugin.getPath(field);\n const basePath = fieldPlugin.getBasePath(field);\n /**\n * Transform the value for the search.\n */\n const value = fieldPlugin.toSearchValue({\n value: initialValue,\n path,\n basePath\n });\n\n operatorPlugin.apply(query, {\n name: field,\n value,\n path,\n basePath,\n keyword: fieldPlugin.keyword\n });\n }\n};\n"],"mappings":";;;;;;;AACA;AAEA;AAgBA,MAAMA,mBAAmB,GAAG,IAAIC,MAAM,CAAC,mCAAmC,CAAC;AAEpE,MAAMC,aAAa,GAAIC,GAAW,IAA0B;EAC/D,MAAMC,KAAK,GAAGD,GAAG,CAACC,KAAK,CAACJ,mBAAmB,CAAC;EAE5C,IAAI,CAACI,KAAK,EAAE;IACR,MAAM,IAAIC,KAAK,CAAE,wCAAuCF,GAAI,GAAE,CAAC;EACnE;EAEA,MAAM,GAAGG,KAAK,EAAEC,SAAS,GAAG,IAAI,CAAC,GAAGH,KAAK;EAEzC,IAAI,CAACE,KAAK,CAACF,KAAK,CAAC,eAAe,CAAC,EAAE;IAC/B,MAAM,IAAIC,KAAK,CAAE,qBAAoBC,KAAM,IAAG,CAAC;EACnD;EAEA,MAAME,QAAQ,GAAGD,SAAS,CAACH,KAAK,CAAC,IAAI,CAAC,GAAGG,SAAS,CAACE,KAAK,CAAC,CAAC,CAAC,GAAGF,SAAS;EAEvE,OAAO;IAAED,KAAK;IAAEE;EAAS,CAAC;AAC9B,CAAC;AAAC;AAEF,MAAME,GAAG,GAAGC,kDAAwB,CAACD,GAAG;AAEjC,MAAME,UAAU,GAAIC,MAAwB,IAAW;EAC1D,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAElD,KAAK,MAAMV,GAAG,IAAIY,KAAK,EAAE;IACrB,IAAIA,KAAK,CAACG,cAAc,CAACf,GAAG,CAAC,KAAK,KAAK,EAAE;MACrC;IACJ;IACA,MAAMgB,YAAY,GAAGJ,KAAK,CAACZ,GAAG,CAAC;IAC/B;AACR;AACA;IACQ,IAAIgB,YAAY,KAAKC,SAAS,EAAE;MAC5B;IACJ;IACA,MAAM;MAAEd,KAAK;MAAEE;IAAS,CAAC,GAAGN,aAAa,CAACC,GAAG,CAAC;IAC9C,MAAMkB,WAAqC,GAAGL,MAAM,CAACV,KAAK,CAAC,IAAIU,MAAM,CAACN,GAAG,CAAC;IAC1E,IAAI,CAACW,WAAW,EAAE;MACd,MAAM,IAAIC,cAAW,CAChB,iCAAgChB,KAAM,IAAG,EAC1C,oBAAoB,EACpB;QACIA;MACJ,CAAC,CACJ;IACL;IACA,MAAMiB,cAAc,GAAGN,SAAS,CAACT,QAAQ,CAAC;IAC1C,IAAI,CAACe,cAAc,EAAE;MACjB,MAAM,IAAID,cAAW,CAChB,oCAAmCd,QAAS,GAAE,EAC/C,oBAAoB,EACpB;QACIA;MACJ,CAAC,CACJ;IACL;;IAEA;AACR;AACA;AACA;IACQ,MAAMgB,IAAI,GAAGH,WAAW,CAACI,OAAO,CAACnB,KAAK,CAAC;IACvC,MAAMoB,QAAQ,GAAGL,WAAW,CAACM,WAAW,CAACrB,KAAK,CAAC;IAC/C;AACR;AACA;IACQ,MAAMsB,KAAK,GAAGP,WAAW,CAACQ,aAAa,CAAC;MACpCD,KAAK,EAAET,YAAY;MACnBK,IAAI;MACJE;IACJ,CAAC,CAAC;IAEFH,cAAc,CAACO,KAAK,CAAChB,KAAK,EAAE;MACxBiB,IAAI,EAAEzB,KAAK;MACXsB,KAAK;MACLJ,IAAI;MACJE,QAAQ;MACRM,OAAO,EAAEX,WAAW,CAACW;IACzB,CAAC,CAAC;EACN;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","slice","ALL","ElasticsearchFieldPlugin","applyWhere","params","query","where","fields","operators","hasOwnProperty","initialValue","undefined","fieldPlugin","WebinyError","operatorPlugin","path","getPath","basePath","getBasePath","value","toSearchValue","apply","name","keyword"],"sources":["where.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins/definition/ElasticsearchFieldPlugin\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: ElasticsearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<ElasticsearchFieldPlugin>;\n operators: Records<ElasticsearchQueryBuilderOperatorPlugin>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\nconst parseWhereKeyRegExp = new RegExp(/^([a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);\n\nexport const parseWhereKey = (key: string): ParseWhereKeyResult => {\n const match = key.match(parseWhereKeyRegExp);\n\n if (!match) {\n throw new Error(`It is not possible to search by key \"${key}\"`);\n }\n\n const [, field, operation = \"eq\"] = match;\n\n if (!field.match(/^([a-zA-Z0-9]+)$/)) {\n throw new Error(`Cannot filter by \"${field}\".`);\n }\n\n const operator = operation.match(/^_/) ? operation.slice(1) : operation;\n\n return { field, operator };\n};\n\nconst ALL = ElasticsearchFieldPlugin.ALL;\n\nexport const applyWhere = (params: ApplyWhereParams): void => {\n const { query, where, fields, operators } = params;\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n const initialValue = where[key];\n /**\n * There is a possibility that undefined is sent as a value, so just skip it.\n */\n if (initialValue === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const fieldPlugin: ElasticsearchFieldPlugin = fields[field] || fields[ALL];\n if (!fieldPlugin) {\n throw new WebinyError(\n `Missing plugin for the field \"${field}\".`,\n \"PLUGIN_WHERE_ERROR\",\n {\n field\n }\n );\n }\n const operatorPlugin = operators[operator];\n if (!operatorPlugin) {\n throw new WebinyError(\n `Missing plugin for the operator \"${operator}\"`,\n \"PLUGIN_WHERE_ERROR\",\n {\n operator\n }\n );\n }\n\n /**\n * Get the path but in the case of * (all fields, replace * with the field.\n * Custom path would return its own value anyways.\n */\n const path = fieldPlugin.getPath(field);\n const basePath = fieldPlugin.getBasePath(field);\n /**\n * Transform the value for the search.\n */\n const value = fieldPlugin.toSearchValue({\n value: initialValue,\n path,\n basePath\n });\n\n operatorPlugin.apply(query, {\n name: field,\n value,\n path,\n basePath,\n keyword: fieldPlugin.keyword\n });\n }\n};\n"],"mappings":";;;;;;;AACA;AAEA;AAgBA,MAAMA,mBAAmB,GAAG,IAAIC,MAAM,CAAC,mCAAmC,CAAC;AAEpE,MAAMC,aAAa,GAAIC,GAAW,IAA0B;EAC/D,MAAMC,KAAK,GAAGD,GAAG,CAACC,KAAK,CAACJ,mBAAmB,CAAC;EAE5C,IAAI,CAACI,KAAK,EAAE;IACR,MAAM,IAAIC,KAAK,CAAE,wCAAuCF,GAAI,GAAE,CAAC;EACnE;EAEA,MAAM,GAAGG,KAAK,EAAEC,SAAS,GAAG,IAAI,CAAC,GAAGH,KAAK;EAEzC,IAAI,CAACE,KAAK,CAACF,KAAK,CAAC,kBAAkB,CAAC,EAAE;IAClC,MAAM,IAAIC,KAAK,CAAE,qBAAoBC,KAAM,IAAG,CAAC;EACnD;EAEA,MAAME,QAAQ,GAAGD,SAAS,CAACH,KAAK,CAAC,IAAI,CAAC,GAAGG,SAAS,CAACE,KAAK,CAAC,CAAC,CAAC,GAAGF,SAAS;EAEvE,OAAO;IAAED,KAAK;IAAEE;EAAS,CAAC;AAC9B,CAAC;AAAC;AAEF,MAAME,GAAG,GAAGC,kDAAwB,CAACD,GAAG;AAEjC,MAAME,UAAU,GAAIC,MAAwB,IAAW;EAC1D,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAElD,KAAK,MAAMV,GAAG,IAAIY,KAAK,EAAE;IAC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