@webiny/api-opensearch 0.0.0-unstable.0156a4c312

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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/client.d.ts +8 -0
  4. package/client.js +37 -0
  5. package/client.js.map +1 -0
  6. package/cursors.d.ts +10 -0
  7. package/cursors.js +25 -0
  8. package/cursors.js.map +1 -0
  9. package/exports/api/opensearch.d.ts +9 -0
  10. package/exports/api/opensearch.js +9 -0
  11. package/features/OpenSearchClient/abstraction.d.ts +9 -0
  12. package/features/OpenSearchClient/abstraction.js +5 -0
  13. package/features/OpenSearchClient/abstraction.js.map +1 -0
  14. package/features/OpenSearchClient/feature.d.ts +5 -0
  15. package/features/OpenSearchClient/feature.js +13 -0
  16. package/features/OpenSearchClient/feature.js.map +1 -0
  17. package/features/OpenSearchClientFactory/OpenSearchClientFactory.d.ts +9 -0
  18. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js +15 -0
  19. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js.map +1 -0
  20. package/features/OpenSearchClientFactory/abstraction.d.ts +10 -0
  21. package/features/OpenSearchClientFactory/abstraction.js +5 -0
  22. package/features/OpenSearchClientFactory/abstraction.js.map +1 -0
  23. package/features/OpenSearchClientFactory/feature.d.ts +4 -0
  24. package/features/OpenSearchClientFactory/feature.js +11 -0
  25. package/features/OpenSearchClientFactory/feature.js.map +1 -0
  26. package/features/OpenSearchField/OpenSearchField.d.ts +18 -0
  27. package/features/OpenSearchField/OpenSearchField.js +49 -0
  28. package/features/OpenSearchField/OpenSearchField.js.map +1 -0
  29. package/features/OpenSearchField/OpenSearchFieldFactory.d.ts +9 -0
  30. package/features/OpenSearchField/OpenSearchFieldFactory.js +14 -0
  31. package/features/OpenSearchField/OpenSearchFieldFactory.js.map +1 -0
  32. package/features/OpenSearchField/abstractions/OpenSearchField.d.ts +35 -0
  33. package/features/OpenSearchField/abstractions/OpenSearchField.js +6 -0
  34. package/features/OpenSearchField/abstractions/OpenSearchField.js.map +1 -0
  35. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.d.ts +8 -0
  36. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js +5 -0
  37. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js.map +1 -0
  38. package/features/OpenSearchField/feature.d.ts +4 -0
  39. package/features/OpenSearchField/feature.js +11 -0
  40. package/features/OpenSearchField/feature.js.map +1 -0
  41. package/features/OpenSearchIndex/OpenSearchIndexRegistry.d.ts +12 -0
  42. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js +30 -0
  43. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js.map +1 -0
  44. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.d.ts +9 -0
  45. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js +5 -0
  46. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js.map +1 -0
  47. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.d.ts +9 -0
  48. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js +5 -0
  49. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js.map +1 -0
  50. package/features/OpenSearchIndex/feature.d.ts +4 -0
  51. package/features/OpenSearchIndex/feature.js +11 -0
  52. package/features/OpenSearchIndex/feature.js.map +1 -0
  53. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.d.ts +12 -0
  54. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js +28 -0
  55. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  56. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.d.ts +11 -0
  57. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js +5 -0
  58. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js.map +1 -0
  59. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.d.ts +10 -0
  60. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js +5 -0
  61. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  62. package/features/OpenSearchQueryBuilderOperator/feature.d.ts +4 -0
  63. package/features/OpenSearchQueryBuilderOperator/feature.js +41 -0
  64. package/features/OpenSearchQueryBuilderOperator/feature.js.map +1 -0
  65. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.d.ts +9 -0
  66. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js +28 -0
  67. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js.map +1 -0
  68. package/features/OpenSearchQueryBuilderOperator/operators/Between.d.ts +9 -0
  69. package/features/OpenSearchQueryBuilderOperator/operators/Between.js +27 -0
  70. package/features/OpenSearchQueryBuilderOperator/operators/Between.js.map +1 -0
  71. package/features/OpenSearchQueryBuilderOperator/operators/Contains.d.ts +9 -0
  72. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js +27 -0
  73. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js.map +1 -0
  74. package/features/OpenSearchQueryBuilderOperator/operators/Equal.d.ts +9 -0
  75. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js +34 -0
  76. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js.map +1 -0
  77. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.d.ts +9 -0
  78. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js +23 -0
  79. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js.map +1 -0
  80. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.d.ts +9 -0
  81. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js +23 -0
  82. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js.map +1 -0
  83. package/features/OpenSearchQueryBuilderOperator/operators/In.d.ts +9 -0
  84. package/features/OpenSearchQueryBuilderOperator/operators/In.js +24 -0
  85. package/features/OpenSearchQueryBuilderOperator/operators/In.js.map +1 -0
  86. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.d.ts +9 -0
  87. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js +23 -0
  88. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js.map +1 -0
  89. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.d.ts +9 -0
  90. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js +23 -0
  91. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js.map +1 -0
  92. package/features/OpenSearchQueryBuilderOperator/operators/Not.d.ts +9 -0
  93. package/features/OpenSearchQueryBuilderOperator/operators/Not.js +38 -0
  94. package/features/OpenSearchQueryBuilderOperator/operators/Not.js.map +1 -0
  95. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.d.ts +9 -0
  96. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js +27 -0
  97. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js.map +1 -0
  98. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.d.ts +9 -0
  99. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js +27 -0
  100. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js.map +1 -0
  101. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.d.ts +9 -0
  102. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js +24 -0
  103. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js.map +1 -0
  104. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.d.ts +9 -0
  105. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js +22 -0
  106. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js.map +1 -0
  107. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.d.ts +9 -0
  108. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js +22 -0
  109. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js.map +1 -0
  110. package/index.d.ts +13 -0
  111. package/index.js +13 -0
  112. package/indexConfiguration/base.d.ts +6 -0
  113. package/indexConfiguration/base.js +34 -0
  114. package/indexConfiguration/base.js.map +1 -0
  115. package/indexConfiguration/common.d.ts +9 -0
  116. package/indexConfiguration/common.js +42 -0
  117. package/indexConfiguration/common.js.map +1 -0
  118. package/indexConfiguration/index.d.ts +2 -0
  119. package/indexConfiguration/index.js +2 -0
  120. package/indexPrefix.d.ts +1 -0
  121. package/indexPrefix.js +4 -0
  122. package/indexPrefix.js.map +1 -0
  123. package/indices.d.ts +2 -0
  124. package/indices.js +1 -0
  125. package/limit.d.ts +1 -0
  126. package/limit.js +10 -0
  127. package/limit.js.map +1 -0
  128. package/normalize.d.ts +6 -0
  129. package/normalize.js +55 -0
  130. package/normalize.js.map +1 -0
  131. package/operations/OpenSearchCatHealth.d.ts +7 -0
  132. package/operations/OpenSearchCatHealth.js +30 -0
  133. package/operations/OpenSearchCatHealth.js.map +1 -0
  134. package/operations/OpenSearchCatNodes.d.ts +7 -0
  135. package/operations/OpenSearchCatNodes.js +28 -0
  136. package/operations/OpenSearchCatNodes.js.map +1 -0
  137. package/operations/index.d.ts +3 -0
  138. package/operations/index.js +3 -0
  139. package/operations/stripConnectionFromException.d.ts +1 -0
  140. package/operations/stripConnectionFromException.js +14 -0
  141. package/operations/stripConnectionFromException.js.map +1 -0
  142. package/operations/types.d.ts +12 -0
  143. package/operations/types.js +9 -0
  144. package/operations/types.js.map +1 -0
  145. package/package.json +38 -0
  146. package/registerOpenSearchCore.d.ts +3 -0
  147. package/registerOpenSearchCore.js +20 -0
  148. package/registerOpenSearchCore.js.map +1 -0
  149. package/sharedIndex.d.ts +1 -0
  150. package/sharedIndex.js +4 -0
  151. package/sharedIndex.js.map +1 -0
  152. package/sort.d.ts +13 -0
  153. package/sort.js +36 -0
  154. package/sort.js.map +1 -0
  155. package/testing/createBlankQuery.d.ts +2 -0
  156. package/testing/createBlankQuery.js +9 -0
  157. package/testing/createBlankQuery.js.map +1 -0
  158. package/testing/createTestOpenSearchClient.d.ts +11 -0
  159. package/testing/createTestOpenSearchClient.js +162 -0
  160. package/testing/createTestOpenSearchClient.js.map +1 -0
  161. package/testing/index.d.ts +4 -0
  162. package/testing/index.js +4 -0
  163. package/testing/registerOpenSearchCoreForTests.d.ts +1 -0
  164. package/testing/registerOpenSearchCoreForTests.js +9 -0
  165. package/testing/registerOpenSearchCoreForTests.js.map +1 -0
  166. package/testing/setupTestIndexManager.d.ts +13 -0
  167. package/testing/setupTestIndexManager.js +26 -0
  168. package/testing/setupTestIndexManager.js.map +1 -0
  169. package/types.d.ts +60 -0
  170. package/types.js +8 -0
  171. package/types.js.map +1 -0
  172. package/utils/createIndex.d.ts +19 -0
  173. package/utils/createIndex.js +60 -0
  174. package/utils/createIndex.js.map +1 -0
  175. package/utils/index.d.ts +2 -0
  176. package/utils/index.js +2 -0
  177. package/utils/waitUntilHealthy/UnhealthyClusterError.d.ts +4 -0
  178. package/utils/waitUntilHealthy/UnhealthyClusterError.js +12 -0
  179. package/utils/waitUntilHealthy/UnhealthyClusterError.js.map +1 -0
  180. package/utils/waitUntilHealthy/WaitUntilHealthy.d.ts +72 -0
  181. package/utils/waitUntilHealthy/WaitUntilHealthy.js +130 -0
  182. package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -0
  183. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.d.ts +4 -0
  184. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js +12 -0
  185. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js.map +1 -0
  186. package/utils/waitUntilHealthy/index.d.ts +4 -0
  187. package/utils/waitUntilHealthy/index.js +4 -0
  188. package/utils/waitUntilHealthy/reason/ClusterHealthReason.d.ts +15 -0
  189. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js +12 -0
  190. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js.map +1 -0
  191. package/utils/waitUntilHealthy/reason/IReason.d.ts +4 -0
  192. package/utils/waitUntilHealthy/reason/IReason.js +0 -0
  193. package/utils/waitUntilHealthy/reason/MemoryReason.d.ts +14 -0
  194. package/utils/waitUntilHealthy/reason/MemoryReason.js +12 -0
  195. package/utils/waitUntilHealthy/reason/MemoryReason.js.map +1 -0
  196. package/utils/waitUntilHealthy/reason/ProcessorReason.d.ts +14 -0
  197. package/utils/waitUntilHealthy/reason/ProcessorReason.js +12 -0
  198. package/utils/waitUntilHealthy/reason/ProcessorReason.js.map +1 -0
  199. package/utils/waitUntilHealthy/reason/index.d.ts +3 -0
  200. package/utils/waitUntilHealthy/reason/index.js +3 -0
  201. package/where.d.ts +17 -0
  202. package/where.js +49 -0
  203. package/where.js.map +1 -0
@@ -0,0 +1,60 @@
1
+ import _webiny_error from "@webiny/error";
2
+ const indexExists = async (params)=>{
3
+ const { client, index } = params;
4
+ try {
5
+ const response = await client.indices.exists({
6
+ index,
7
+ ignore_unavailable: false,
8
+ allow_no_indices: true,
9
+ include_defaults: true,
10
+ flat_settings: false,
11
+ local: false
12
+ });
13
+ if (!response.body) return false;
14
+ return true;
15
+ } catch {
16
+ console.error(`Could not determine if the index "${index}" exists.`);
17
+ }
18
+ return false;
19
+ };
20
+ const indexCreate = async (params)=>{
21
+ const { client, index, plugin, tenant, type, onError } = params;
22
+ try {
23
+ await client.indices.create({
24
+ index,
25
+ body: {
26
+ ...plugin.body
27
+ }
28
+ });
29
+ } catch (ex) {
30
+ let error = ex;
31
+ if (onError) error = onError(ex);
32
+ throw new _webiny_error(error.message || `Could not create OpenSearch index for the ${type}.`, error.code || "CREATE_OPENSEARCH_INDEX_ERROR", {
33
+ error: {
34
+ ...error,
35
+ message: error.message,
36
+ code: error.code,
37
+ data: error.data
38
+ },
39
+ type,
40
+ tenant,
41
+ index,
42
+ body: plugin.body
43
+ });
44
+ }
45
+ };
46
+ const createIndex = async (params)=>{
47
+ const { plugin, onExists } = params;
48
+ const exists = await indexExists(params);
49
+ if (exists) {
50
+ if (onExists) onExists();
51
+ return;
52
+ }
53
+ await indexCreate({
54
+ ...params,
55
+ plugin
56
+ });
57
+ };
58
+ export { createIndex };
59
+
60
+ //# sourceMappingURL=createIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/createIndex.js","sources":["../../src/utils/createIndex.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport type { OpenSearchIndex } from \"~/features/OpenSearchIndex/abstractions/OpenSearchIndex.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface OnExists {\n (): void;\n}\n\ninterface OnError {\n (ex: Error): Error;\n}\n\ninterface ExistsIndexParams {\n client: Client;\n index: string;\n}\n\nconst indexExists = async (params: ExistsIndexParams): Promise<boolean> => {\n const { client, index } = params;\n\n try {\n const response = await client.indices.exists({\n index,\n ignore_unavailable: false,\n allow_no_indices: true,\n include_defaults: true,\n flat_settings: false,\n local: false\n });\n if (!response.body) {\n return false;\n }\n return true;\n } catch {\n console.error(`Could not determine if the index \"${index}\" exists.`);\n }\n return false;\n};\n\ninterface IndexCreateParams {\n client: Client;\n index: string;\n type: string;\n tenant: string;\n plugin: OpenSearchIndex.Interface;\n onError?: OnError;\n}\n\nconst indexCreate = async (params: IndexCreateParams): Promise<void> => {\n const { client, index, plugin, tenant, type, onError } = params;\n\n try {\n await client.indices.create({\n index,\n body: {\n ...plugin.body\n }\n });\n } catch (ex) {\n let error = ex;\n if (onError) {\n error = onError(ex);\n }\n throw new WebinyError(\n error.message || `Could not create OpenSearch index for the ${type}.`,\n error.code || \"CREATE_OPENSEARCH_INDEX_ERROR\",\n {\n error: {\n ...error,\n message: error.message,\n code: error.code,\n data: error.data\n },\n type,\n tenant,\n index,\n body: plugin.body\n }\n );\n }\n};\n\ninterface CreateIndexParams {\n client: Client;\n plugin: OpenSearchIndex.Interface;\n type: string;\n tenant: string;\n index: string;\n onExists?: OnExists;\n onError?: OnError;\n}\n\nexport const createIndex = async (params: CreateIndexParams): Promise<void> => {\n const { plugin, onExists } = params;\n\n const exists = await indexExists(params);\n if (exists) {\n if (onExists) {\n onExists();\n }\n return;\n }\n\n await indexCreate({\n ...params,\n plugin\n });\n};\n"],"names":["indexExists","params","client","index","response","console","indexCreate","plugin","tenant","type","onError","ex","error","WebinyError","createIndex","onExists","exists"],"mappings":";AAiBA,MAAMA,cAAc,OAAOC;IACvB,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGF;IAE1B,IAAI;QACA,MAAMG,WAAW,MAAMF,OAAO,OAAO,CAAC,MAAM,CAAC;YACzCC;YACA,oBAAoB;YACpB,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,OAAO;QACX;QACA,IAAI,CAACC,SAAS,IAAI,EACd,OAAO;QAEX,OAAO;IACX,EAAE,OAAM;QACJC,QAAQ,KAAK,CAAC,CAAC,kCAAkC,EAAEF,MAAM,SAAS,CAAC;IACvE;IACA,OAAO;AACX;AAWA,MAAMG,cAAc,OAAOL;IACvB,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEI,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAGT;IAEzD,IAAI;QACA,MAAMC,OAAO,OAAO,CAAC,MAAM,CAAC;YACxBC;YACA,MAAM;gBACF,GAAGI,OAAO,IAAI;YAClB;QACJ;IACJ,EAAE,OAAOI,IAAI;QACT,IAAIC,QAAQD;QACZ,IAAID,SACAE,QAAQF,QAAQC;QAEpB,MAAM,IAAIE,cACND,MAAM,OAAO,IAAI,CAAC,0CAA0C,EAAEH,KAAK,CAAC,CAAC,EACrEG,MAAM,IAAI,IAAI,iCACd;YACI,OAAO;gBACH,GAAGA,KAAK;gBACR,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;YACpB;YACAH;YACAD;YACAL;YACA,MAAMI,OAAO,IAAI;QACrB;IAER;AACJ;AAYO,MAAMO,cAAc,OAAOb;IAC9B,MAAM,EAAEM,MAAM,EAAEQ,QAAQ,EAAE,GAAGd;IAE7B,MAAMe,SAAS,MAAMhB,YAAYC;IACjC,IAAIe,QAAQ;QACR,IAAID,UACAA;QAEJ;IACJ;IAEA,MAAMT,YAAY;QACd,GAAGL,MAAM;QACTM;IACJ;AACJ"}
@@ -0,0 +1,2 @@
1
+ export * from "./waitUntilHealthy/index.js";
2
+ export * from "./createIndex.js";
package/utils/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./waitUntilHealthy/index.js";
2
+ export * from "./createIndex.js";
@@ -0,0 +1,4 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ export declare class UnhealthyClusterError extends WebinyError {
3
+ constructor(maxWaitingTime: number);
4
+ }
@@ -0,0 +1,12 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ class UnhealthyClusterError extends WebinyError {
3
+ constructor(maxWaitingTime){
4
+ super({
5
+ message: `Cluster did not become healthy in ${maxWaitingTime} seconds.`,
6
+ code: "UNHEALTHY_CLUSTER"
7
+ });
8
+ }
9
+ }
10
+ export { UnhealthyClusterError };
11
+
12
+ //# sourceMappingURL=UnhealthyClusterError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/UnhealthyClusterError.js","sources":["../../../src/utils/waitUntilHealthy/UnhealthyClusterError.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\n\nexport class UnhealthyClusterError extends WebinyError {\n public constructor(maxWaitingTime: number) {\n super({\n message: `Cluster did not become healthy in ${maxWaitingTime} seconds.`,\n code: \"UNHEALTHY_CLUSTER\"\n });\n }\n}\n"],"names":["UnhealthyClusterError","WebinyError","maxWaitingTime"],"mappings":";AAEO,MAAMA,8BAA8BC;IACvC,YAAmBC,cAAsB,CAAE;QACvC,KAAK,CAAC;YACF,SAAS,CAAC,kCAAkC,EAAEA,eAAe,SAAS,CAAC;YACvE,MAAM;QACV;IACJ;AACJ"}
@@ -0,0 +1,72 @@
1
+ import type { Client } from "../../client.js";
2
+ import { OpenSearchCatClusterHealthStatus } from "../../operations/types.js";
3
+ import type { ClusterHealthReason, MemoryReason, ProcessorReason } from "./reason/index.js";
4
+ export type WaitingReason = ProcessorReason | MemoryReason | ClusterHealthReason;
5
+ export interface IWaitUntilHealthyParams {
6
+ /**
7
+ * Minimum status allowed, otherwise the cluster is considered unhealthy.
8
+ */
9
+ minClusterHealthStatus: OpenSearchCatClusterHealthStatus.Green | OpenSearchCatClusterHealthStatus.Yellow;
10
+ /**
11
+ * Maximum processor percent allowed, otherwise the cluster is considered unhealthy.
12
+ */
13
+ maxProcessorPercent: number;
14
+ /**
15
+ * Maximum RAM percent allowed, otherwise the cluster is considered unhealthy.
16
+ */
17
+ maxRamPercent?: number;
18
+ /**
19
+ * Maximum time to wait in seconds.
20
+ * This is to prevent infinite waiting in case the cluster never becomes healthy.
21
+ */
22
+ maxWaitingTime: number;
23
+ /**
24
+ * Time in seconds to wait between each check.
25
+ * This is to prevent spamming the cluster with requests.
26
+ * Default is WAITING_TIME_STEP seconds.
27
+ */
28
+ waitingTimeStep?: number;
29
+ }
30
+ export interface IWaitOptionsOnUnhealthyParams {
31
+ startedAt: Date;
32
+ mustEndAt: Date;
33
+ waitingTimeStep: number;
34
+ runs: number;
35
+ waitingReason: WaitingReason;
36
+ }
37
+ export interface IWaitOptionsOnTimeoutParams {
38
+ startedAt: Date;
39
+ mustEndAt: Date;
40
+ waitingTimeStep: number;
41
+ runs: number;
42
+ waitingReason: WaitingReason;
43
+ }
44
+ export interface IWaitOptions {
45
+ onUnhealthy?(params: IWaitOptionsOnUnhealthyParams): Promise<void>;
46
+ onTimeout?(params: IWaitOptionsOnTimeoutParams): Promise<void>;
47
+ }
48
+ export interface IWaitUntilHealthyWaitResponse {
49
+ runningTime: number;
50
+ runs: number;
51
+ }
52
+ declare class WaitUntilHealthy {
53
+ private readonly client;
54
+ private readonly options;
55
+ private readonly catHealth;
56
+ private readonly catNodes;
57
+ private aborted;
58
+ constructor(client: Client, options: IWaitUntilHealthyParams);
59
+ abort(): void;
60
+ /**
61
+ * @throws UnhealthyClusterError
62
+ * @throws WaitingHealthyClusterAbortedError
63
+ */
64
+ wait(options?: IWaitOptions): Promise<IWaitUntilHealthyWaitResponse>;
65
+ private shouldWait;
66
+ private getProcessorPercent;
67
+ private getRamPercent;
68
+ private toClusterHealthStatus;
69
+ private transformClusterHealthStatus;
70
+ }
71
+ export type { WaitUntilHealthy };
72
+ export declare const createWaitUntilHealthy: (client: Client, params: IWaitUntilHealthyParams) => WaitUntilHealthy;
@@ -0,0 +1,130 @@
1
+ import { OpenSearchCatHealth } from "../../operations/OpenSearchCatHealth.js";
2
+ import { OpenSearchCatNodes } from "../../operations/OpenSearchCatNodes.js";
3
+ import { OpenSearchCatClusterHealthStatus } from "../../operations/types.js";
4
+ import { UnhealthyClusterError } from "./UnhealthyClusterError.js";
5
+ import { createClusterHealthStatusReason, createMemoryReason, createProcessorReason } from "./reason/index.js";
6
+ import { WaitingHealthyClusterAbortedError } from "./WaitingHealthyClusterAbortedError.js";
7
+ const WAITING_TIME_STEP = 10;
8
+ class WaitUntilHealthy {
9
+ constructor(client, options){
10
+ this.aborted = false;
11
+ this.client = client;
12
+ this.options = options;
13
+ this.catHealth = new OpenSearchCatHealth(this.client);
14
+ this.catNodes = new OpenSearchCatNodes(this.client);
15
+ }
16
+ abort() {
17
+ this.aborted = true;
18
+ }
19
+ async wait(options) {
20
+ if (this.aborted) throw new WaitingHealthyClusterAbortedError("Waiting for the cluster to become healthy was aborted even before it started.");
21
+ const startedAt = new Date();
22
+ const mustEndAt = new Date(startedAt.getTime() + 1000 * this.options.maxWaitingTime);
23
+ const waitingTimeStep = this.options.waitingTimeStep || WAITING_TIME_STEP;
24
+ let runs = 1;
25
+ let waitingReason;
26
+ while(waitingReason = await this.shouldWait()){
27
+ if (new Date() >= mustEndAt) {
28
+ if (options?.onTimeout) await options.onTimeout({
29
+ startedAt,
30
+ mustEndAt,
31
+ waitingTimeStep,
32
+ waitingReason,
33
+ runs
34
+ });
35
+ throw new UnhealthyClusterError(this.options.maxWaitingTime);
36
+ } else if (options?.onUnhealthy) await options.onUnhealthy({
37
+ startedAt,
38
+ mustEndAt,
39
+ waitingTimeStep,
40
+ waitingReason,
41
+ runs
42
+ });
43
+ if (this.aborted) throw new WaitingHealthyClusterAbortedError();
44
+ runs++;
45
+ await new Promise((resolve)=>{
46
+ setTimeout(resolve, 1000 * waitingTimeStep);
47
+ });
48
+ }
49
+ const runningTime = new Date().getTime() - startedAt.getTime();
50
+ return {
51
+ runningTime,
52
+ runs
53
+ };
54
+ }
55
+ async shouldWait() {
56
+ let health;
57
+ let nodes;
58
+ try {
59
+ health = await this.catHealth.getHealth();
60
+ } catch (ex) {
61
+ return createClusterHealthStatusReason({
62
+ description: ex.message,
63
+ minimum: this.options.minClusterHealthStatus,
64
+ current: OpenSearchCatClusterHealthStatus.Red
65
+ });
66
+ }
67
+ try {
68
+ nodes = await this.catNodes.getNodes();
69
+ } catch (ex) {
70
+ return createClusterHealthStatusReason({
71
+ description: ex.message,
72
+ minimum: this.options.minClusterHealthStatus,
73
+ current: OpenSearchCatClusterHealthStatus.Red
74
+ });
75
+ }
76
+ const currentStatus = this.toClusterHealthStatus(health.status);
77
+ const clusterHealthStatus = this.transformClusterHealthStatus(currentStatus);
78
+ const minClusterHealthStatus = this.transformClusterHealthStatus(this.options.minClusterHealthStatus);
79
+ if (clusterHealthStatus > minClusterHealthStatus) return createClusterHealthStatusReason({
80
+ minimum: this.options.minClusterHealthStatus,
81
+ current: currentStatus
82
+ });
83
+ const processorPercent = this.getProcessorPercent(nodes);
84
+ if (processorPercent > this.options.maxProcessorPercent) return createProcessorReason({
85
+ maximum: this.options.maxProcessorPercent,
86
+ current: processorPercent
87
+ });
88
+ if (void 0 === this.options.maxRamPercent) return false;
89
+ const ramPercent = this.getRamPercent(nodes);
90
+ if (ramPercent > this.options.maxRamPercent) return createMemoryReason({
91
+ maximum: this.options.maxRamPercent,
92
+ current: ramPercent
93
+ });
94
+ return false;
95
+ }
96
+ getProcessorPercent(nodes) {
97
+ const total = nodes.reduce((total, node)=>total + parseFloat(node.cpu || "0"), 0);
98
+ return total / nodes.length;
99
+ }
100
+ getRamPercent(nodes) {
101
+ const total = nodes.reduce((total, node)=>total + parseFloat(node["ram.percent"] || "0"), 0);
102
+ return total / nodes.length;
103
+ }
104
+ toClusterHealthStatus(status) {
105
+ switch(status){
106
+ case "green":
107
+ return OpenSearchCatClusterHealthStatus.Green;
108
+ case "yellow":
109
+ return OpenSearchCatClusterHealthStatus.Yellow;
110
+ default:
111
+ return OpenSearchCatClusterHealthStatus.Red;
112
+ }
113
+ }
114
+ transformClusterHealthStatus(status) {
115
+ switch(status){
116
+ case OpenSearchCatClusterHealthStatus.Green:
117
+ return 1;
118
+ case OpenSearchCatClusterHealthStatus.Yellow:
119
+ return 2;
120
+ case OpenSearchCatClusterHealthStatus.Red:
121
+ return 3;
122
+ default:
123
+ return 99;
124
+ }
125
+ }
126
+ }
127
+ const createWaitUntilHealthy = (client, params)=>new WaitUntilHealthy(client, params);
128
+ export { createWaitUntilHealthy };
129
+
130
+ //# sourceMappingURL=WaitUntilHealthy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/WaitUntilHealthy.js","sources":["../../../src/utils/waitUntilHealthy/WaitUntilHealthy.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport { OpenSearchCatHealth } from \"~/operations/OpenSearchCatHealth.js\";\nimport { OpenSearchCatNodes } from \"~/operations/OpenSearchCatNodes.js\";\nimport type {\n IOpenSearchCatHealthResponse,\n IOpenSearchCatNodesResponse\n} from \"~/operations/types.js\";\nimport { OpenSearchCatClusterHealthStatus } from \"~/operations/types.js\";\nimport { UnhealthyClusterError } from \"~/utils/waitUntilHealthy/UnhealthyClusterError.js\";\nimport type { ClusterHealthReason, MemoryReason, ProcessorReason } from \"./reason/index.js\";\nimport {\n createClusterHealthStatusReason,\n createMemoryReason,\n createProcessorReason\n} from \"./reason/index.js\";\nimport { WaitingHealthyClusterAbortedError } from \"./WaitingHealthyClusterAbortedError.js\";\n\nconst WAITING_TIME_STEP = 10;\n\nexport type WaitingReason = ProcessorReason | MemoryReason | ClusterHealthReason;\n\nexport interface IWaitUntilHealthyParams {\n /**\n * Minimum status allowed, otherwise the cluster is considered unhealthy.\n */\n minClusterHealthStatus:\n | OpenSearchCatClusterHealthStatus.Green\n | OpenSearchCatClusterHealthStatus.Yellow;\n /**\n * Maximum processor percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxProcessorPercent: number;\n /**\n * Maximum RAM percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxRamPercent?: number;\n /**\n * Maximum time to wait in seconds.\n * This is to prevent infinite waiting in case the cluster never becomes healthy.\n */\n maxWaitingTime: number;\n /**\n * Time in seconds to wait between each check.\n * This is to prevent spamming the cluster with requests.\n * Default is WAITING_TIME_STEP seconds.\n */\n waitingTimeStep?: number;\n}\n\nexport interface IWaitOptionsOnUnhealthyParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptionsOnTimeoutParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptions {\n onUnhealthy?(params: IWaitOptionsOnUnhealthyParams): Promise<void>;\n onTimeout?(params: IWaitOptionsOnTimeoutParams): Promise<void>;\n}\n\nexport interface IWaitUntilHealthyWaitResponse {\n runningTime: number;\n runs: number;\n}\n\nclass WaitUntilHealthy {\n private readonly client: Client;\n private readonly options: IWaitUntilHealthyParams;\n\n private readonly catHealth: OpenSearchCatHealth;\n private readonly catNodes: OpenSearchCatNodes;\n\n private aborted = false;\n\n public constructor(client: Client, options: IWaitUntilHealthyParams) {\n this.client = client;\n this.options = options;\n\n this.catHealth = new OpenSearchCatHealth(this.client);\n this.catNodes = new OpenSearchCatNodes(this.client);\n }\n\n public abort(): void {\n this.aborted = true;\n }\n /**\n * @throws UnhealthyClusterError\n * @throws WaitingHealthyClusterAbortedError\n */\n public async wait(options?: IWaitOptions): Promise<IWaitUntilHealthyWaitResponse> {\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError(\n `Waiting for the cluster to become healthy was aborted even before it started.`\n );\n }\n const startedAt = new Date();\n const mustEndAt = new Date(startedAt.getTime() + this.options.maxWaitingTime * 1000);\n const waitingTimeStep = this.options.waitingTimeStep || WAITING_TIME_STEP;\n let runs = 1;\n let waitingReason: WaitingReason | false;\n while ((waitingReason = await this.shouldWait())) {\n if (new Date() >= mustEndAt) {\n if (options?.onTimeout) {\n await options.onTimeout({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n throw new UnhealthyClusterError(this.options.maxWaitingTime);\n } else if (options?.onUnhealthy) {\n await options.onUnhealthy({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n /**\n * Abort check is separated from other IFs because it can be aborted in onUnhealthy callback.\n */\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError();\n }\n runs++;\n await new Promise(resolve => {\n setTimeout(resolve, waitingTimeStep * 1000);\n });\n }\n\n const runningTime = new Date().getTime() - startedAt.getTime();\n\n return {\n runningTime,\n runs\n };\n }\n\n private async shouldWait(): Promise<WaitingReason | false> {\n let health: IOpenSearchCatHealthResponse;\n let nodes: IOpenSearchCatNodesResponse;\n try {\n health = await this.catHealth.getHealth();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n try {\n nodes = await this.catNodes.getNodes();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n\n const currentStatus = this.toClusterHealthStatus(health.status);\n const clusterHealthStatus = this.transformClusterHealthStatus(currentStatus);\n const minClusterHealthStatus = this.transformClusterHealthStatus(\n this.options.minClusterHealthStatus\n );\n if (clusterHealthStatus > minClusterHealthStatus) {\n return createClusterHealthStatusReason({\n minimum: this.options.minClusterHealthStatus,\n current: currentStatus\n });\n }\n\n const processorPercent = this.getProcessorPercent(nodes);\n if (processorPercent > this.options.maxProcessorPercent) {\n return createProcessorReason({\n maximum: this.options.maxProcessorPercent,\n current: processorPercent\n });\n }\n /**\n * Possibly no max ram definition?\n */\n if (this.options.maxRamPercent === undefined) {\n return false;\n }\n\n const ramPercent = this.getRamPercent(nodes);\n if (ramPercent > this.options.maxRamPercent) {\n return createMemoryReason({\n maximum: this.options.maxRamPercent,\n current: ramPercent\n });\n }\n return false;\n }\n\n private getProcessorPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node.cpu || \"0\");\n }, 0);\n return total / nodes.length;\n }\n\n private getRamPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node[\"ram.percent\"] || \"0\");\n }, 0);\n return total / nodes.length;\n }\n\n private toClusterHealthStatus(status?: string): OpenSearchCatClusterHealthStatus {\n switch (status) {\n case \"green\":\n return OpenSearchCatClusterHealthStatus.Green;\n case \"yellow\":\n return OpenSearchCatClusterHealthStatus.Yellow;\n default:\n return OpenSearchCatClusterHealthStatus.Red;\n }\n }\n\n private transformClusterHealthStatus(status: OpenSearchCatClusterHealthStatus): number {\n switch (status) {\n case OpenSearchCatClusterHealthStatus.Green:\n return 1;\n case OpenSearchCatClusterHealthStatus.Yellow:\n return 2;\n case OpenSearchCatClusterHealthStatus.Red:\n return 3;\n default:\n return 99;\n }\n }\n}\n\nexport type { WaitUntilHealthy };\n\nexport const createWaitUntilHealthy = (\n client: Client,\n params: IWaitUntilHealthyParams\n): WaitUntilHealthy => {\n return new WaitUntilHealthy(client, params);\n};\n"],"names":["WAITING_TIME_STEP","WaitUntilHealthy","client","options","OpenSearchCatHealth","OpenSearchCatNodes","WaitingHealthyClusterAbortedError","startedAt","Date","mustEndAt","waitingTimeStep","runs","waitingReason","UnhealthyClusterError","Promise","resolve","setTimeout","runningTime","health","nodes","ex","createClusterHealthStatusReason","OpenSearchCatClusterHealthStatus","currentStatus","clusterHealthStatus","minClusterHealthStatus","processorPercent","createProcessorReason","undefined","ramPercent","createMemoryReason","total","node","parseFloat","status","createWaitUntilHealthy","params"],"mappings":"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"}
@@ -0,0 +1,4 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ export declare class WaitingHealthyClusterAbortedError extends WebinyError {
3
+ constructor(message?: string);
4
+ }
@@ -0,0 +1,12 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ class WaitingHealthyClusterAbortedError extends WebinyError {
3
+ constructor(message){
4
+ super({
5
+ message: message || "Waiting for the cluster to become healthy was aborted.",
6
+ code: "WAITING_HEALTHY_CLUSTER_ABORTED"
7
+ });
8
+ }
9
+ }
10
+ export { WaitingHealthyClusterAbortedError };
11
+
12
+ //# sourceMappingURL=WaitingHealthyClusterAbortedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js","sources":["../../../src/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\n\nexport class WaitingHealthyClusterAbortedError extends WebinyError {\n public constructor(message?: string) {\n super({\n message: message || `Waiting for the cluster to become healthy was aborted.`,\n code: \"WAITING_HEALTHY_CLUSTER_ABORTED\"\n });\n }\n}\n"],"names":["WaitingHealthyClusterAbortedError","WebinyError","message"],"mappings":";AAEO,MAAMA,0CAA0CC;IACnD,YAAmBC,OAAgB,CAAE;QACjC,KAAK,CAAC;YACF,SAASA,WAAW;YACpB,MAAM;QACV;IACJ;AACJ"}
@@ -0,0 +1,4 @@
1
+ export * from "./WaitingHealthyClusterAbortedError.js";
2
+ export * from "./UnhealthyClusterError.js";
3
+ export * from "./WaitUntilHealthy.js";
4
+ export * from "./reason/index.js";
@@ -0,0 +1,4 @@
1
+ export * from "./WaitingHealthyClusterAbortedError.js";
2
+ export * from "./UnhealthyClusterError.js";
3
+ export * from "./WaitUntilHealthy.js";
4
+ export * from "./reason/index.js";
@@ -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,12 @@
1
+ class ClusterHealthReason {
2
+ constructor(params){
3
+ this.name = "clusterHealth";
4
+ this.minimum = params.minimum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ const createClusterHealthStatusReason = (params)=>new ClusterHealthReason(params);
10
+ export { ClusterHealthReason, createClusterHealthStatusReason };
11
+
12
+ //# sourceMappingURL=ClusterHealthReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/reason/ClusterHealthReason.js","sources":["../../../../src/utils/waitUntilHealthy/reason/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"],"names":["ClusterHealthReason","params","createClusterHealthStatusReason"],"mappings":"AASO,MAAMA;IAMT,YAAmBC,MAAkC,CAAE;aALvC,IAAI,GAAG;QAMnB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;IACzC;AACJ;AAEO,MAAMC,kCAAkC,CAC3CD,SAEO,IAAID,oBAAoBC"}
@@ -0,0 +1,4 @@
1
+ export interface IReason {
2
+ name: string;
3
+ description?: string;
4
+ }
File without changes
@@ -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,12 @@
1
+ class MemoryReason {
2
+ constructor(params){
3
+ this.name = "memory";
4
+ this.maximum = params.maximum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ const createMemoryReason = (params)=>new MemoryReason(params);
10
+ export { MemoryReason, createMemoryReason };
11
+
12
+ //# sourceMappingURL=MemoryReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/reason/MemoryReason.js","sources":["../../../../src/utils/waitUntilHealthy/reason/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"],"names":["MemoryReason","params","createMemoryReason"],"mappings":"AAQO,MAAMA;IAMT,YAAmBC,MAA2B,CAAE;aALhC,IAAI,GAAG;QAMnB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;IACzC;AACJ;AAEO,MAAMC,qBAAqB,CAACD,SACxB,IAAID,aAAaC"}
@@ -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,12 @@
1
+ class ProcessorReason {
2
+ constructor(params){
3
+ this.name = "processor";
4
+ this.maximum = params.maximum;
5
+ this.current = params.current;
6
+ this.description = params.description;
7
+ }
8
+ }
9
+ const createProcessorReason = (params)=>new ProcessorReason(params);
10
+ export { ProcessorReason, createProcessorReason };
11
+
12
+ //# sourceMappingURL=ProcessorReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/waitUntilHealthy/reason/ProcessorReason.js","sources":["../../../../src/utils/waitUntilHealthy/reason/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"],"names":["ProcessorReason","params","createProcessorReason"],"mappings":"AAQO,MAAMA;IAMT,YAAmBC,MAA8B,CAAE;aALnC,IAAI,GAAG;QAMnB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO;QAC7B,IAAI,CAAC,WAAW,GAAGA,OAAO,WAAW;IACzC;AACJ;AAEO,MAAMC,wBAAwB,CAACD,SAC3B,IAAID,gBAAgBC"}
@@ -0,0 +1,3 @@
1
+ export * from "./ClusterHealthReason.js";
2
+ export * from "./MemoryReason.js";
3
+ export * from "./ProcessorReason.js";
@@ -0,0 +1,3 @@
1
+ export * from "./ClusterHealthReason.js";
2
+ export * from "./MemoryReason.js";
3
+ export * from "./ProcessorReason.js";
package/where.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { OpenSearchBoolQueryConfig } from "./types.js";
2
+ import { OpenSearchField } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
3
+ import type { OpenSearchQueryBuilderOperator } from "./features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js";
4
+ type Records<T> = Record<string, T>;
5
+ export interface ApplyWhereParams {
6
+ query: OpenSearchBoolQueryConfig;
7
+ where: Records<any>;
8
+ fields: Records<OpenSearchField.Interface>;
9
+ operators: Records<OpenSearchQueryBuilderOperator.Interface>;
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,49 @@
1
+ import { OpenSearchFieldAll } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
2
+ import error from "@webiny/error";
3
+ const parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);
4
+ const parseWhereKey = (key)=>{
5
+ const match = key.match(parseWhereKeyRegExp);
6
+ if (!match) throw new Error(`It is not possible to search by key "${key}"`);
7
+ const [, field, operation = "eq"] = match;
8
+ if (!field.match(/^(?:wbyAco_)?([a-zA-Z0-9]+)$/)) throw new Error(`Cannot filter by "${field}".`);
9
+ const operator = operation.match(/^_/) ? operation.slice(1) : operation;
10
+ return {
11
+ field,
12
+ operator
13
+ };
14
+ };
15
+ const ALL = OpenSearchFieldAll;
16
+ const applyWhere = (params)=>{
17
+ const { query, where, fields, operators } = params;
18
+ for(const key in where){
19
+ if (false === where.hasOwnProperty(key)) continue;
20
+ const initialValue = where[key];
21
+ if (void 0 === initialValue) continue;
22
+ const { field, operator } = parseWhereKey(key);
23
+ const fieldPlugin = fields[field] || fields[ALL];
24
+ if (!fieldPlugin) throw new error(`Missing plugin for the field "${field}".`, "PLUGIN_WHERE_ERROR", {
25
+ field
26
+ });
27
+ const operatorInstance = operators[operator];
28
+ if (!operatorInstance) throw new error(`Missing plugin for the operator "${operator}"`, "PLUGIN_WHERE_ERROR", {
29
+ operator
30
+ });
31
+ const path = fieldPlugin.getPath(field);
32
+ const basePath = fieldPlugin.getBasePath(field);
33
+ const value = fieldPlugin.toSearchValue({
34
+ value: initialValue,
35
+ path,
36
+ basePath
37
+ });
38
+ operatorInstance.apply(query, {
39
+ name: field,
40
+ value,
41
+ path,
42
+ basePath,
43
+ keyword: fieldPlugin.keyword
44
+ });
45
+ }
46
+ };
47
+ export { applyWhere, parseWhereKey };
48
+
49
+ //# sourceMappingURL=where.js.map
package/where.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where.js","sources":["../src/where.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"~/types.js\";\nimport {\n OpenSearchField,\n OpenSearchFieldAll\n} from \"~/features/OpenSearchField/abstractions/OpenSearchField.js\";\nimport type { OpenSearchQueryBuilderOperator } from \"~/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.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<OpenSearchField.Interface>;\n operators: Records<OpenSearchQueryBuilderOperator.Interface>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\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 = OpenSearchFieldAll;\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 if (initialValue === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const fieldPlugin: OpenSearchField.Interface = 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 operatorInstance = operators[operator];\n if (!operatorInstance) {\n throw new WebinyError(\n `Missing plugin for the operator \"${operator}\"`,\n \"PLUGIN_WHERE_ERROR\",\n {\n operator\n }\n );\n }\n\n const path = fieldPlugin.getPath(field);\n const basePath = fieldPlugin.getBasePath(field);\n const value = fieldPlugin.toSearchValue({\n value: initialValue,\n path,\n basePath\n });\n\n operatorInstance.apply(query, {\n name: field,\n value,\n path,\n basePath,\n keyword: fieldPlugin.keyword\n });\n }\n};\n"],"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","ALL","OpenSearchFieldAll","applyWhere","params","query","where","fields","operators","initialValue","undefined","fieldPlugin","WebinyError","operatorInstance","path","basePath","value"],"mappings":";;AAsBA,MAAMA,sBAAsB,IAAIC,OAAO;AAEhC,MAAMC,gBAAgB,CAACC;IAC1B,MAAMC,QAAQD,IAAI,KAAK,CAACH;IAExB,IAAI,CAACI,OACD,MAAM,IAAIC,MAAM,CAAC,qCAAqC,EAAEF,IAAI,CAAC,CAAC;IAGlE,MAAM,GAAGG,OAAOC,YAAY,IAAI,CAAC,GAAGH;IAEpC,IAAI,CAACE,MAAM,KAAK,CAAC,iCACb,MAAM,IAAID,MAAM,CAAC,kBAAkB,EAAEC,MAAM,EAAE,CAAC;IAGlD,MAAME,WAAWD,UAAU,KAAK,CAAC,QAAQA,UAAU,KAAK,CAAC,KAAKA;IAE9D,OAAO;QAAED;QAAOE;IAAS;AAC7B;AAEA,MAAMC,MAAMC;AAEL,MAAMC,aAAa,CAACC;IACvB,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;IAE5C,IAAK,MAAMT,OAAOW,MAAO;QACrB,IAAIA,AAA8B,UAA9BA,MAAM,cAAc,CAACX,MACrB;QAEJ,MAAMc,eAAeH,KAAK,CAACX,IAAI;QAC/B,IAAIc,AAAiBC,WAAjBD,cACA;QAEJ,MAAM,EAAEX,KAAK,EAAEE,QAAQ,EAAE,GAAGN,cAAcC;QAC1C,MAAMgB,cAAyCJ,MAAM,CAACT,MAAM,IAAIS,MAAM,CAACN,IAAI;QAC3E,IAAI,CAACU,aACD,MAAM,IAAIC,MACN,CAAC,8BAA8B,EAAEd,MAAM,EAAE,CAAC,EAC1C,sBACA;YACIA;QACJ;QAGR,MAAMe,mBAAmBL,SAAS,CAACR,SAAS;QAC5C,IAAI,CAACa,kBACD,MAAM,IAAID,MACN,CAAC,iCAAiC,EAAEZ,SAAS,CAAC,CAAC,EAC/C,sBACA;YACIA;QACJ;QAIR,MAAMc,OAAOH,YAAY,OAAO,CAACb;QACjC,MAAMiB,WAAWJ,YAAY,WAAW,CAACb;QACzC,MAAMkB,QAAQL,YAAY,aAAa,CAAC;YACpC,OAAOF;YACPK;YACAC;QACJ;QAEAF,iBAAiB,KAAK,CAACR,OAAO;YAC1B,MAAMP;YACNkB;YACAF;YACAC;YACA,SAASJ,YAAY,OAAO;QAChC;IACJ;AACJ"}