@webiny/api-opensearch 6.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/client.d.ts +8 -0
  4. package/client.js +70 -0
  5. package/client.js.map +1 -0
  6. package/compression.d.ts +6 -0
  7. package/compression.js +25 -0
  8. package/compression.js.map +1 -0
  9. package/cursors.d.ts +10 -0
  10. package/cursors.js +37 -0
  11. package/cursors.js.map +1 -0
  12. package/db/entity.d.ts +7 -0
  13. package/db/entity.js +20 -0
  14. package/db/entity.js.map +1 -0
  15. package/db/index.d.ts +3 -0
  16. package/db/index.js +5 -0
  17. package/db/index.js.map +1 -0
  18. package/db/table.d.ts +7 -0
  19. package/db/table.js +17 -0
  20. package/db/table.js.map +1 -0
  21. package/db/types.d.ts +6 -0
  22. package/db/types.js +3 -0
  23. package/db/types.js.map +1 -0
  24. package/exports/api/opensearch.d.ts +4 -0
  25. package/exports/api/opensearch.js +6 -0
  26. package/exports/api/opensearch.js.map +1 -0
  27. package/features/OpenSearchClient/OpenSearchClient.d.ts +12 -0
  28. package/features/OpenSearchClient/OpenSearchClient.js +16 -0
  29. package/features/OpenSearchClient/OpenSearchClient.js.map +1 -0
  30. package/features/OpenSearchClient/abstraction.d.ts +9 -0
  31. package/features/OpenSearchClient/abstraction.js +4 -0
  32. package/features/OpenSearchClient/abstraction.js.map +1 -0
  33. package/features/OpenSearchClient/feature.d.ts +1 -0
  34. package/features/OpenSearchClient/feature.js +10 -0
  35. package/features/OpenSearchClient/feature.js.map +1 -0
  36. package/features/OpenSearchClientFactory/OpenSearchClientFactory.d.ts +9 -0
  37. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js +16 -0
  38. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js.map +1 -0
  39. package/features/OpenSearchClientFactory/abstraction.d.ts +10 -0
  40. package/features/OpenSearchClientFactory/abstraction.js +4 -0
  41. package/features/OpenSearchClientFactory/abstraction.js.map +1 -0
  42. package/features/OpenSearchClientFactory/feature.d.ts +1 -0
  43. package/features/OpenSearchClientFactory/feature.js +10 -0
  44. package/features/OpenSearchClientFactory/feature.js.map +1 -0
  45. package/features/OpenSearchContext/OpenSearchContext.d.ts +8 -0
  46. package/features/OpenSearchContext/OpenSearchContext.js +13 -0
  47. package/features/OpenSearchContext/OpenSearchContext.js.map +1 -0
  48. package/features/OpenSearchContext/abstraction.d.ts +14 -0
  49. package/features/OpenSearchContext/abstraction.js +4 -0
  50. package/features/OpenSearchContext/abstraction.js.map +1 -0
  51. package/features/OpenSearchContext/feature.d.ts +2 -0
  52. package/features/OpenSearchContext/feature.js +13 -0
  53. package/features/OpenSearchContext/feature.js.map +1 -0
  54. package/index.d.ts +22 -0
  55. package/index.js +41 -0
  56. package/index.js.map +1 -0
  57. package/indexConfiguration/base.d.ts +6 -0
  58. package/indexConfiguration/base.js +35 -0
  59. package/indexConfiguration/base.js.map +1 -0
  60. package/indexConfiguration/common.d.ts +9 -0
  61. package/indexConfiguration/common.js +47 -0
  62. package/indexConfiguration/common.js.map +1 -0
  63. package/indexConfiguration/index.d.ts +2 -0
  64. package/indexConfiguration/index.js +4 -0
  65. package/indexConfiguration/index.js.map +1 -0
  66. package/indexPrefix.d.ts +1 -0
  67. package/indexPrefix.js +5 -0
  68. package/indexPrefix.js.map +1 -0
  69. package/indices.d.ts +8 -0
  70. package/indices.js +20 -0
  71. package/indices.js.map +1 -0
  72. package/limit.d.ts +1 -0
  73. package/limit.js +32 -0
  74. package/limit.js.map +1 -0
  75. package/normalize.d.ts +6 -0
  76. package/normalize.js +54 -0
  77. package/normalize.js.map +1 -0
  78. package/operations/OpenSearchCatHealth.d.ts +7 -0
  79. package/operations/OpenSearchCatHealth.js +31 -0
  80. package/operations/OpenSearchCatHealth.js.map +1 -0
  81. package/operations/OpenSearchCatNodes.d.ts +7 -0
  82. package/operations/OpenSearchCatNodes.js +29 -0
  83. package/operations/OpenSearchCatNodes.js.map +1 -0
  84. package/operations/index.d.ts +3 -0
  85. package/operations/index.js +5 -0
  86. package/operations/index.js.map +1 -0
  87. package/operations/stripConnectionFromException.d.ts +1 -0
  88. package/operations/stripConnectionFromException.js +17 -0
  89. package/operations/stripConnectionFromException.js.map +1 -0
  90. package/operations/types.d.ts +35 -0
  91. package/operations/types.js +8 -0
  92. package/operations/types.js.map +1 -0
  93. package/operators.d.ts +6 -0
  94. package/operators.js +9 -0
  95. package/operators.js.map +1 -0
  96. package/package.json +36 -0
  97. package/plugins/definition/OpenSearchBodyModifierPlugin.d.ts +13 -0
  98. package/plugins/definition/OpenSearchBodyModifierPlugin.js +18 -0
  99. package/plugins/definition/OpenSearchBodyModifierPlugin.js.map +1 -0
  100. package/plugins/definition/OpenSearchFieldPlugin.d.ts +81 -0
  101. package/plugins/definition/OpenSearchFieldPlugin.js +68 -0
  102. package/plugins/definition/OpenSearchFieldPlugin.js.map +1 -0
  103. package/plugins/definition/OpenSearchIndexPlugin.d.ts +10 -0
  104. package/plugins/definition/OpenSearchIndexPlugin.js +17 -0
  105. package/plugins/definition/OpenSearchIndexPlugin.js.map +1 -0
  106. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.d.ts +10 -0
  107. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js +9 -0
  108. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js.map +1 -0
  109. package/plugins/definition/OpenSearchQueryModifierPlugin.d.ts +14 -0
  110. package/plugins/definition/OpenSearchQueryModifierPlugin.js +18 -0
  111. package/plugins/definition/OpenSearchQueryModifierPlugin.js.map +1 -0
  112. package/plugins/definition/OpenSearchSortModifierPlugin.d.ts +13 -0
  113. package/plugins/definition/OpenSearchSortModifierPlugin.js +18 -0
  114. package/plugins/definition/OpenSearchSortModifierPlugin.js.map +1 -0
  115. package/plugins/definition/index.d.ts +6 -0
  116. package/plugins/definition/index.js +8 -0
  117. package/plugins/definition/index.js.map +1 -0
  118. package/plugins/index.d.ts +2 -0
  119. package/plugins/index.js +4 -0
  120. package/plugins/index.js.map +1 -0
  121. package/plugins/operator/andIn.d.ts +7 -0
  122. package/plugins/operator/andIn.js +35 -0
  123. package/plugins/operator/andIn.js.map +1 -0
  124. package/plugins/operator/between.d.ts +7 -0
  125. package/plugins/operator/between.js +32 -0
  126. package/plugins/operator/between.js.map +1 -0
  127. package/plugins/operator/contains.d.ts +7 -0
  128. package/plugins/operator/contains.js +24 -0
  129. package/plugins/operator/contains.js.map +1 -0
  130. package/plugins/operator/equal.d.ts +7 -0
  131. package/plugins/operator/equal.js +50 -0
  132. package/plugins/operator/equal.js.map +1 -0
  133. package/plugins/operator/gt.d.ts +7 -0
  134. package/plugins/operator/gt.js +22 -0
  135. package/plugins/operator/gt.js.map +1 -0
  136. package/plugins/operator/gte.d.ts +7 -0
  137. package/plugins/operator/gte.js +22 -0
  138. package/plugins/operator/gte.js.map +1 -0
  139. package/plugins/operator/in.d.ts +7 -0
  140. package/plugins/operator/in.js +29 -0
  141. package/plugins/operator/in.js.map +1 -0
  142. package/plugins/operator/index.d.ts +15 -0
  143. package/plugins/operator/index.js +17 -0
  144. package/plugins/operator/index.js.map +1 -0
  145. package/plugins/operator/lt.d.ts +7 -0
  146. package/plugins/operator/lt.js +22 -0
  147. package/plugins/operator/lt.js.map +1 -0
  148. package/plugins/operator/lte.d.ts +7 -0
  149. package/plugins/operator/lte.js +22 -0
  150. package/plugins/operator/lte.js.map +1 -0
  151. package/plugins/operator/not.d.ts +7 -0
  152. package/plugins/operator/not.js +44 -0
  153. package/plugins/operator/not.js.map +1 -0
  154. package/plugins/operator/notBetween.d.ts +7 -0
  155. package/plugins/operator/notBetween.js +32 -0
  156. package/plugins/operator/notBetween.js.map +1 -0
  157. package/plugins/operator/notContains.d.ts +7 -0
  158. package/plugins/operator/notContains.js +24 -0
  159. package/plugins/operator/notContains.js.map +1 -0
  160. package/plugins/operator/notIn.d.ts +7 -0
  161. package/plugins/operator/notIn.js +27 -0
  162. package/plugins/operator/notIn.js.map +1 -0
  163. package/plugins/operator/notStartsWith.d.ts +7 -0
  164. package/plugins/operator/notStartsWith.js +23 -0
  165. package/plugins/operator/notStartsWith.js.map +1 -0
  166. package/plugins/operator/startsWith.d.ts +7 -0
  167. package/plugins/operator/startsWith.js +23 -0
  168. package/plugins/operator/startsWith.js.map +1 -0
  169. package/sharedIndex.d.ts +1 -0
  170. package/sharedIndex.js +5 -0
  171. package/sharedIndex.js.map +1 -0
  172. package/sort.d.ts +13 -0
  173. package/sort.js +64 -0
  174. package/sort.js.map +1 -0
  175. package/types.d.ts +179 -0
  176. package/types.js +3 -0
  177. package/types.js.map +1 -0
  178. package/utils/createIndex.d.ts +19 -0
  179. package/utils/createIndex.js +88 -0
  180. package/utils/createIndex.js.map +1 -0
  181. package/utils/index.d.ts +2 -0
  182. package/utils/index.js +4 -0
  183. package/utils/index.js.map +1 -0
  184. package/utils/waitUntilHealthy/UnhealthyClusterError.d.ts +4 -0
  185. package/utils/waitUntilHealthy/UnhealthyClusterError.js +11 -0
  186. package/utils/waitUntilHealthy/UnhealthyClusterError.js.map +1 -0
  187. package/utils/waitUntilHealthy/WaitUntilHealthy.d.ts +71 -0
  188. package/utils/waitUntilHealthy/WaitUntilHealthy.js +150 -0
  189. package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -0
  190. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.d.ts +4 -0
  191. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js +11 -0
  192. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js.map +1 -0
  193. package/utils/waitUntilHealthy/index.d.ts +4 -0
  194. package/utils/waitUntilHealthy/index.js +6 -0
  195. package/utils/waitUntilHealthy/index.js.map +1 -0
  196. package/utils/waitUntilHealthy/reason/ClusterHealthReason.d.ts +15 -0
  197. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js +13 -0
  198. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js.map +1 -0
  199. package/utils/waitUntilHealthy/reason/IReason.d.ts +4 -0
  200. package/utils/waitUntilHealthy/reason/IReason.js +3 -0
  201. package/utils/waitUntilHealthy/reason/IReason.js.map +1 -0
  202. package/utils/waitUntilHealthy/reason/MemoryReason.d.ts +14 -0
  203. package/utils/waitUntilHealthy/reason/MemoryReason.js +13 -0
  204. package/utils/waitUntilHealthy/reason/MemoryReason.js.map +1 -0
  205. package/utils/waitUntilHealthy/reason/ProcessorReason.d.ts +14 -0
  206. package/utils/waitUntilHealthy/reason/ProcessorReason.js +13 -0
  207. package/utils/waitUntilHealthy/reason/ProcessorReason.js.map +1 -0
  208. package/utils/waitUntilHealthy/reason/index.d.ts +3 -0
  209. package/utils/waitUntilHealthy/reason/index.js +5 -0
  210. package/utils/waitUntilHealthy/reason/index.js.map +1 -0
  211. package/where.d.ts +17 -0
  212. package/where.js +82 -0
  213. package/where.js.map +1 -0
@@ -0,0 +1,15 @@
1
+ import type { OpenSearchCatClusterHealthStatus } from "../../../operations/index.js";
2
+ import type { IReason } from "../../../utils/waitUntilHealthy/reason/IReason.js";
3
+ export interface IClusterHealthReasonParams {
4
+ minimum: OpenSearchCatClusterHealthStatus;
5
+ current: OpenSearchCatClusterHealthStatus;
6
+ description?: string;
7
+ }
8
+ export declare class ClusterHealthReason implements IReason {
9
+ readonly name = "clusterHealth";
10
+ readonly minimum: OpenSearchCatClusterHealthStatus;
11
+ readonly current: OpenSearchCatClusterHealthStatus;
12
+ readonly description?: string;
13
+ constructor(params: IClusterHealthReasonParams);
14
+ }
15
+ export declare const createClusterHealthStatusReason: (params: IClusterHealthReasonParams) => ClusterHealthReason;
@@ -0,0 +1,13 @@
1
+ export class ClusterHealthReason {
2
+ name = "clusterHealth";
3
+ constructor(params) {
4
+ this.minimum = params.minimum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ export const createClusterHealthStatusReason = params => {
10
+ return new ClusterHealthReason(params);
11
+ };
12
+
13
+ //# sourceMappingURL=ClusterHealthReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ClusterHealthReason","name","constructor","params","minimum","current","description","createClusterHealthStatusReason"],"sources":["ClusterHealthReason.ts"],"sourcesContent":["import type { OpenSearchCatClusterHealthStatus } from \"~/operations/index.js\";\nimport type { IReason } from \"~/utils/waitUntilHealthy/reason/IReason.js\";\n\nexport interface IClusterHealthReasonParams {\n minimum: OpenSearchCatClusterHealthStatus;\n current: OpenSearchCatClusterHealthStatus;\n description?: string;\n}\n\nexport class ClusterHealthReason implements IReason {\n public readonly name = \"clusterHealth\";\n public readonly minimum: OpenSearchCatClusterHealthStatus;\n public readonly current: OpenSearchCatClusterHealthStatus;\n public readonly description?: string;\n\n public constructor(params: IClusterHealthReasonParams) {\n this.minimum = params.minimum;\n this.current = params.current;\n this.description = params.description;\n }\n}\n\nexport const createClusterHealthStatusReason = (\n params: IClusterHealthReasonParams\n): ClusterHealthReason => {\n return new ClusterHealthReason(params);\n};\n"],"mappings":"AASA,OAAO,MAAMA,mBAAmB,CAAoB;EAChCC,IAAI,GAAG,eAAe;EAK/BC,WAAWA,CAACC,MAAkC,EAAE;IACnD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;AACJ;AAEA,OAAO,MAAMC,+BAA+B,GACxCJ,MAAkC,IACZ;EACtB,OAAO,IAAIH,mBAAmB,CAACG,MAAM,CAAC;AAC1C,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export interface IReason {
2
+ name: string;
3
+ description?: string;
4
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=IReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["IReason.ts"],"sourcesContent":["export interface IReason {\n name: string;\n description?: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import type { IReason } from "../../../utils/waitUntilHealthy/reason/IReason.js";
2
+ export interface IMemoryReasonParams {
3
+ maximum: number;
4
+ current: number;
5
+ description?: string;
6
+ }
7
+ export declare class MemoryReason implements IReason {
8
+ readonly name = "memory";
9
+ readonly maximum: number;
10
+ readonly current: number;
11
+ readonly description?: string;
12
+ constructor(params: IMemoryReasonParams);
13
+ }
14
+ export declare const createMemoryReason: (params: IMemoryReasonParams) => MemoryReason;
@@ -0,0 +1,13 @@
1
+ export class MemoryReason {
2
+ name = "memory";
3
+ constructor(params) {
4
+ this.maximum = params.maximum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ export const createMemoryReason = params => {
10
+ return new MemoryReason(params);
11
+ };
12
+
13
+ //# sourceMappingURL=MemoryReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MemoryReason","name","constructor","params","maximum","current","description","createMemoryReason"],"sources":["MemoryReason.ts"],"sourcesContent":["import type { IReason } from \"~/utils/waitUntilHealthy/reason/IReason.js\";\n\nexport interface IMemoryReasonParams {\n maximum: number;\n current: number;\n description?: string;\n}\n\nexport class MemoryReason implements IReason {\n public readonly name = \"memory\";\n public readonly maximum: number;\n public readonly current: number;\n public readonly description?: string;\n\n public constructor(params: IMemoryReasonParams) {\n this.maximum = params.maximum;\n this.current = params.current;\n this.description = params.description;\n }\n}\n\nexport const createMemoryReason = (params: IMemoryReasonParams): MemoryReason => {\n return new MemoryReason(params);\n};\n"],"mappings":"AAQA,OAAO,MAAMA,YAAY,CAAoB;EACzBC,IAAI,GAAG,QAAQ;EAKxBC,WAAWA,CAACC,MAA2B,EAAE;IAC5C,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAIJ,MAA2B,IAAmB;EAC7E,OAAO,IAAIH,YAAY,CAACG,MAAM,CAAC;AACnC,CAAC","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ import type { IReason } from "../../../utils/waitUntilHealthy/reason/IReason.js";
2
+ export interface IProcessorReasonParams {
3
+ maximum: number;
4
+ current: number;
5
+ description?: string;
6
+ }
7
+ export declare class ProcessorReason implements IReason {
8
+ readonly name = "processor";
9
+ readonly maximum: number;
10
+ readonly current: number;
11
+ readonly description?: string;
12
+ constructor(params: IProcessorReasonParams);
13
+ }
14
+ export declare const createProcessorReason: (params: IProcessorReasonParams) => ProcessorReason;
@@ -0,0 +1,13 @@
1
+ export class ProcessorReason {
2
+ name = "processor";
3
+ constructor(params) {
4
+ this.maximum = params.maximum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ export const createProcessorReason = params => {
10
+ return new ProcessorReason(params);
11
+ };
12
+
13
+ //# sourceMappingURL=ProcessorReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ProcessorReason","name","constructor","params","maximum","current","description","createProcessorReason"],"sources":["ProcessorReason.ts"],"sourcesContent":["import type { IReason } from \"~/utils/waitUntilHealthy/reason/IReason.js\";\n\nexport interface IProcessorReasonParams {\n maximum: number;\n current: number;\n description?: string;\n}\n\nexport class ProcessorReason implements IReason {\n public readonly name = \"processor\";\n public readonly maximum: number;\n public readonly current: number;\n public readonly description?: string;\n\n public constructor(params: IProcessorReasonParams) {\n this.maximum = params.maximum;\n this.current = params.current;\n this.description = params.description;\n }\n}\n\nexport const createProcessorReason = (params: IProcessorReasonParams): ProcessorReason => {\n return new ProcessorReason(params);\n};\n"],"mappings":"AAQA,OAAO,MAAMA,eAAe,CAAoB;EAC5BC,IAAI,GAAG,WAAW;EAK3BC,WAAWA,CAACC,MAA8B,EAAE;IAC/C,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,OAAO,GAAGF,MAAM,CAACE,OAAO;IAC7B,IAAI,CAACC,WAAW,GAAGH,MAAM,CAACG,WAAW;EACzC;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAIJ,MAA8B,IAAsB;EACtF,OAAO,IAAIH,eAAe,CAACG,MAAM,CAAC;AACtC,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./ClusterHealthReason.js";
2
+ export * from "./MemoryReason.js";
3
+ export * from "./ProcessorReason.js";
@@ -0,0 +1,5 @@
1
+ export * from "./ClusterHealthReason.js";
2
+ export * from "./MemoryReason.js";
3
+ export * from "./ProcessorReason.js";
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./ClusterHealthReason.js\";\nexport * from \"./MemoryReason.js\";\nexport * from \"./ProcessorReason.js\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
package/where.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { OpenSearchBoolQueryConfig } from "./types.js";
2
+ import { OpenSearchFieldPlugin } from "./plugins/definition/OpenSearchFieldPlugin.js";
3
+ import type { OpenSearchQueryBuilderOperatorPlugin } from "./plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js";
4
+ type Records<T> = Record<string, T>;
5
+ export interface ApplyWhereParams {
6
+ query: OpenSearchBoolQueryConfig;
7
+ where: Records<any>;
8
+ fields: Records<OpenSearchFieldPlugin>;
9
+ operators: Records<OpenSearchQueryBuilderOperatorPlugin>;
10
+ }
11
+ export interface ParseWhereKeyResult {
12
+ field: string;
13
+ operator: string;
14
+ }
15
+ export declare const parseWhereKey: (key: string) => ParseWhereKeyResult;
16
+ export declare const applyWhere: (params: ApplyWhereParams) => void;
17
+ export {};
package/where.js ADDED
@@ -0,0 +1,82 @@
1
+ import { OpenSearchFieldPlugin } from "./plugins/definition/OpenSearchFieldPlugin.js";
2
+ import WebinyError from "@webiny/error";
3
+ /**
4
+ * TODO remove the wbyAco prefix when we move the user fields to the values property.
5
+ */
6
+ const parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);
7
+ export const parseWhereKey = key => {
8
+ const match = key.match(parseWhereKeyRegExp);
9
+ if (!match) {
10
+ throw new Error(`It is not possible to search by key "${key}"`);
11
+ }
12
+ const [, field, operation = "eq"] = match;
13
+ if (!field.match(/^(?:wbyAco_)?([a-zA-Z0-9]+)$/)) {
14
+ throw new Error(`Cannot filter by "${field}".`);
15
+ }
16
+ const operator = operation.match(/^_/) ? operation.slice(1) : operation;
17
+ return {
18
+ field,
19
+ operator
20
+ };
21
+ };
22
+ const ALL = OpenSearchFieldPlugin.ALL;
23
+ export const applyWhere = params => {
24
+ const {
25
+ query,
26
+ where,
27
+ fields,
28
+ operators
29
+ } = params;
30
+ for (const key in where) {
31
+ if (where.hasOwnProperty(key) === false) {
32
+ continue;
33
+ }
34
+ const initialValue = where[key];
35
+ /**
36
+ * There is a possibility that undefined is sent as a value, so just skip it.
37
+ */
38
+ if (initialValue === undefined) {
39
+ continue;
40
+ }
41
+ const {
42
+ field,
43
+ operator
44
+ } = parseWhereKey(key);
45
+ const fieldPlugin = fields[field] || fields[ALL];
46
+ if (!fieldPlugin) {
47
+ throw new WebinyError(`Missing plugin for the field "${field}".`, "PLUGIN_WHERE_ERROR", {
48
+ field
49
+ });
50
+ }
51
+ const operatorPlugin = operators[operator];
52
+ if (!operatorPlugin) {
53
+ throw new WebinyError(`Missing plugin for the operator "${operator}"`, "PLUGIN_WHERE_ERROR", {
54
+ operator
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Get the path but in the case of * (all fields, replace * with the field.
60
+ * Custom path would return its own value anyways.
61
+ */
62
+ const path = fieldPlugin.getPath(field);
63
+ const basePath = fieldPlugin.getBasePath(field);
64
+ /**
65
+ * Transform the value for the search.
66
+ */
67
+ const value = fieldPlugin.toSearchValue({
68
+ value: initialValue,
69
+ path,
70
+ basePath
71
+ });
72
+ operatorPlugin.apply(query, {
73
+ name: field,
74
+ value,
75
+ path,
76
+ basePath,
77
+ keyword: fieldPlugin.keyword
78
+ });
79
+ }
80
+ };
81
+
82
+ //# sourceMappingURL=where.js.map
package/where.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OpenSearchFieldPlugin","WebinyError","parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","slice","ALL","applyWhere","params","query","where","fields","operators","hasOwnProperty","initialValue","undefined","fieldPlugin","operatorPlugin","path","getPath","basePath","getBasePath","value","toSearchValue","apply","name","keyword"],"sources":["where.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"~/types.js\";\nimport { OpenSearchFieldPlugin } from \"~/plugins/definition/OpenSearchFieldPlugin.js\";\nimport type { OpenSearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: OpenSearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<OpenSearchFieldPlugin>;\n operators: Records<OpenSearchQueryBuilderOperatorPlugin>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\n/**\n * TODO remove the wbyAco prefix when we move the user fields to the values property.\n */\nconst parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[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(/^(?:wbyAco_)?([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 = OpenSearchFieldPlugin.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: OpenSearchFieldPlugin = 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,SAASA,qBAAqB;AAE9B,OAAOC,WAAW,MAAM,eAAe;AAgBvC;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG,IAAIC,MAAM,CAAC,+CAA+C,CAAC;AAEvF,OAAO,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,CAAC,wCAAwCF,GAAG,GAAG,CAAC;EACnE;EAEA,MAAM,GAAGG,KAAK,EAAEC,SAAS,GAAG,IAAI,CAAC,GAAGH,KAAK;EAEzC,IAAI,CAACE,KAAK,CAACF,KAAK,CAAC,8BAA8B,CAAC,EAAE;IAC9C,MAAM,IAAIC,KAAK,CAAC,qBAAqBC,KAAK,IAAI,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;AAED,MAAME,GAAG,GAAGZ,qBAAqB,CAACY,GAAG;AAErC,OAAO,MAAMC,UAAU,GAAIC,MAAwB,IAAW;EAC1D,MAAM;IAAEC,KAAK;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAElD,KAAK,MAAMT,GAAG,IAAIW,KAAK,EAAE;IACrB,IAAIA,KAAK,CAACG,cAAc,CAACd,GAAG,CAAC,KAAK,KAAK,EAAE;MACrC;IACJ;IACA,MAAMe,YAAY,GAAGJ,KAAK,CAACX,GAAG,CAAC;IAC/B;AACR;AACA;IACQ,IAAIe,YAAY,KAAKC,SAAS,EAAE;MAC5B;IACJ;IACA,MAAM;MAAEb,KAAK;MAAEE;IAAS,CAAC,GAAGN,aAAa,CAACC,GAAG,CAAC;IAC9C,MAAMiB,WAAkC,GAAGL,MAAM,CAACT,KAAK,CAAC,IAAIS,MAAM,CAACL,GAAG,CAAC;IACvE,IAAI,CAACU,WAAW,EAAE;MACd,MAAM,IAAIrB,WAAW,CACjB,iCAAiCO,KAAK,IAAI,EAC1C,oBAAoB,EACpB;QACIA;MACJ,CACJ,CAAC;IACL;IACA,MAAMe,cAAc,GAAGL,SAAS,CAACR,QAAQ,CAAC;IAC1C,IAAI,CAACa,cAAc,EAAE;MACjB,MAAM,IAAItB,WAAW,CACjB,oCAAoCS,QAAQ,GAAG,EAC/C,oBAAoB,EACpB;QACIA;MACJ,CACJ,CAAC;IACL;;IAEA;AACR;AACA;AACA;IACQ,MAAMc,IAAI,GAAGF,WAAW,CAACG,OAAO,CAACjB,KAAK,CAAC;IACvC,MAAMkB,QAAQ,GAAGJ,WAAW,CAACK,WAAW,CAACnB,KAAK,CAAC;IAC/C;AACR;AACA;IACQ,MAAMoB,KAAK,GAAGN,WAAW,CAACO,aAAa,CAAC;MACpCD,KAAK,EAAER,YAAY;MACnBI,IAAI;MACJE;IACJ,CAAC,CAAC;IAEFH,cAAc,CAACO,KAAK,CAACf,KAAK,EAAE;MACxBgB,IAAI,EAAEvB,KAAK;MACXoB,KAAK;MACLJ,IAAI;MACJE,QAAQ;MACRM,OAAO,EAAEV,WAAW,CAACU;IACzB,CAAC,CAAC;EACN;AACJ,CAAC","ignoreList":[]}