@webiny/api-opensearch 0.0.0-unstable.0d717d18dd

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 +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/db/entity.d.ts +7 -0
  10. package/db/entity.js +18 -0
  11. package/db/entity.js.map +1 -0
  12. package/db/index.d.ts +3 -0
  13. package/db/index.js +3 -0
  14. package/db/table.d.ts +7 -0
  15. package/db/table.js +13 -0
  16. package/db/table.js.map +1 -0
  17. package/db/types.d.ts +6 -0
  18. package/db/types.js +0 -0
  19. package/exports/api/opensearch.d.ts +9 -0
  20. package/exports/api/opensearch.js +9 -0
  21. package/features/OpenSearchClient/abstraction.d.ts +9 -0
  22. package/features/OpenSearchClient/abstraction.js +5 -0
  23. package/features/OpenSearchClient/abstraction.js.map +1 -0
  24. package/features/OpenSearchClient/feature.d.ts +5 -0
  25. package/features/OpenSearchClient/feature.js +13 -0
  26. package/features/OpenSearchClient/feature.js.map +1 -0
  27. package/features/OpenSearchClientFactory/OpenSearchClientFactory.d.ts +9 -0
  28. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js +15 -0
  29. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js.map +1 -0
  30. package/features/OpenSearchClientFactory/abstraction.d.ts +10 -0
  31. package/features/OpenSearchClientFactory/abstraction.js +5 -0
  32. package/features/OpenSearchClientFactory/abstraction.js.map +1 -0
  33. package/features/OpenSearchClientFactory/feature.d.ts +4 -0
  34. package/features/OpenSearchClientFactory/feature.js +11 -0
  35. package/features/OpenSearchClientFactory/feature.js.map +1 -0
  36. package/features/OpenSearchField/OpenSearchField.d.ts +18 -0
  37. package/features/OpenSearchField/OpenSearchField.js +49 -0
  38. package/features/OpenSearchField/OpenSearchField.js.map +1 -0
  39. package/features/OpenSearchField/OpenSearchFieldFactory.d.ts +9 -0
  40. package/features/OpenSearchField/OpenSearchFieldFactory.js +14 -0
  41. package/features/OpenSearchField/OpenSearchFieldFactory.js.map +1 -0
  42. package/features/OpenSearchField/abstractions/OpenSearchField.d.ts +35 -0
  43. package/features/OpenSearchField/abstractions/OpenSearchField.js +6 -0
  44. package/features/OpenSearchField/abstractions/OpenSearchField.js.map +1 -0
  45. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.d.ts +8 -0
  46. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js +5 -0
  47. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js.map +1 -0
  48. package/features/OpenSearchField/feature.d.ts +4 -0
  49. package/features/OpenSearchField/feature.js +11 -0
  50. package/features/OpenSearchField/feature.js.map +1 -0
  51. package/features/OpenSearchIndex/OpenSearchIndexRegistry.d.ts +12 -0
  52. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js +30 -0
  53. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js.map +1 -0
  54. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.d.ts +9 -0
  55. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js +5 -0
  56. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js.map +1 -0
  57. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.d.ts +9 -0
  58. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js +5 -0
  59. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js.map +1 -0
  60. package/features/OpenSearchIndex/feature.d.ts +4 -0
  61. package/features/OpenSearchIndex/feature.js +11 -0
  62. package/features/OpenSearchIndex/feature.js.map +1 -0
  63. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.d.ts +12 -0
  64. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js +28 -0
  65. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  66. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.d.ts +11 -0
  67. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js +5 -0
  68. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js.map +1 -0
  69. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.d.ts +10 -0
  70. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js +5 -0
  71. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  72. package/features/OpenSearchQueryBuilderOperator/feature.d.ts +4 -0
  73. package/features/OpenSearchQueryBuilderOperator/feature.js +41 -0
  74. package/features/OpenSearchQueryBuilderOperator/feature.js.map +1 -0
  75. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.d.ts +9 -0
  76. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js +28 -0
  77. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js.map +1 -0
  78. package/features/OpenSearchQueryBuilderOperator/operators/Between.d.ts +9 -0
  79. package/features/OpenSearchQueryBuilderOperator/operators/Between.js +27 -0
  80. package/features/OpenSearchQueryBuilderOperator/operators/Between.js.map +1 -0
  81. package/features/OpenSearchQueryBuilderOperator/operators/Contains.d.ts +9 -0
  82. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js +27 -0
  83. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js.map +1 -0
  84. package/features/OpenSearchQueryBuilderOperator/operators/Equal.d.ts +9 -0
  85. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js +34 -0
  86. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js.map +1 -0
  87. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.d.ts +9 -0
  88. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js +23 -0
  89. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js.map +1 -0
  90. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.d.ts +9 -0
  91. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js +23 -0
  92. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js.map +1 -0
  93. package/features/OpenSearchQueryBuilderOperator/operators/In.d.ts +9 -0
  94. package/features/OpenSearchQueryBuilderOperator/operators/In.js +24 -0
  95. package/features/OpenSearchQueryBuilderOperator/operators/In.js.map +1 -0
  96. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.d.ts +9 -0
  97. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js +23 -0
  98. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js.map +1 -0
  99. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.d.ts +9 -0
  100. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js +23 -0
  101. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js.map +1 -0
  102. package/features/OpenSearchQueryBuilderOperator/operators/Not.d.ts +9 -0
  103. package/features/OpenSearchQueryBuilderOperator/operators/Not.js +38 -0
  104. package/features/OpenSearchQueryBuilderOperator/operators/Not.js.map +1 -0
  105. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.d.ts +9 -0
  106. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js +27 -0
  107. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js.map +1 -0
  108. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.d.ts +9 -0
  109. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js +27 -0
  110. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js.map +1 -0
  111. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.d.ts +9 -0
  112. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js +24 -0
  113. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js.map +1 -0
  114. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.d.ts +9 -0
  115. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js +22 -0
  116. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js.map +1 -0
  117. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.d.ts +9 -0
  118. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js +22 -0
  119. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js.map +1 -0
  120. package/index.d.ts +14 -0
  121. package/index.js +14 -0
  122. package/indexConfiguration/base.d.ts +6 -0
  123. package/indexConfiguration/base.js +34 -0
  124. package/indexConfiguration/base.js.map +1 -0
  125. package/indexConfiguration/common.d.ts +9 -0
  126. package/indexConfiguration/common.js +42 -0
  127. package/indexConfiguration/common.js.map +1 -0
  128. package/indexConfiguration/index.d.ts +2 -0
  129. package/indexConfiguration/index.js +2 -0
  130. package/indexPrefix.d.ts +1 -0
  131. package/indexPrefix.js +4 -0
  132. package/indexPrefix.js.map +1 -0
  133. package/indices.d.ts +2 -0
  134. package/indices.js +1 -0
  135. package/limit.d.ts +1 -0
  136. package/limit.js +10 -0
  137. package/limit.js.map +1 -0
  138. package/normalize.d.ts +6 -0
  139. package/normalize.js +55 -0
  140. package/normalize.js.map +1 -0
  141. package/operations/OpenSearchCatHealth.d.ts +7 -0
  142. package/operations/OpenSearchCatHealth.js +30 -0
  143. package/operations/OpenSearchCatHealth.js.map +1 -0
  144. package/operations/OpenSearchCatNodes.d.ts +7 -0
  145. package/operations/OpenSearchCatNodes.js +28 -0
  146. package/operations/OpenSearchCatNodes.js.map +1 -0
  147. package/operations/index.d.ts +3 -0
  148. package/operations/index.js +3 -0
  149. package/operations/stripConnectionFromException.d.ts +1 -0
  150. package/operations/stripConnectionFromException.js +14 -0
  151. package/operations/stripConnectionFromException.js.map +1 -0
  152. package/operations/types.d.ts +12 -0
  153. package/operations/types.js +9 -0
  154. package/operations/types.js.map +1 -0
  155. package/package.json +42 -0
  156. package/registerOpenSearchCore.d.ts +3 -0
  157. package/registerOpenSearchCore.js +20 -0
  158. package/registerOpenSearchCore.js.map +1 -0
  159. package/sharedIndex.d.ts +1 -0
  160. package/sharedIndex.js +4 -0
  161. package/sharedIndex.js.map +1 -0
  162. package/sort.d.ts +13 -0
  163. package/sort.js +36 -0
  164. package/sort.js.map +1 -0
  165. package/testing/createBlankQuery.d.ts +2 -0
  166. package/testing/createBlankQuery.js +9 -0
  167. package/testing/createBlankQuery.js.map +1 -0
  168. package/testing/createTestOpenSearchClient.d.ts +11 -0
  169. package/testing/createTestOpenSearchClient.js +162 -0
  170. package/testing/createTestOpenSearchClient.js.map +1 -0
  171. package/testing/index.d.ts +4 -0
  172. package/testing/index.js +4 -0
  173. package/testing/registerOpenSearchCoreForTests.d.ts +1 -0
  174. package/testing/registerOpenSearchCoreForTests.js +9 -0
  175. package/testing/registerOpenSearchCoreForTests.js.map +1 -0
  176. package/testing/setupTestIndexManager.d.ts +13 -0
  177. package/testing/setupTestIndexManager.js +26 -0
  178. package/testing/setupTestIndexManager.js.map +1 -0
  179. package/types.d.ts +60 -0
  180. package/types.js +8 -0
  181. package/types.js.map +1 -0
  182. package/utils/createIndex.d.ts +19 -0
  183. package/utils/createIndex.js +60 -0
  184. package/utils/createIndex.js.map +1 -0
  185. package/utils/index.d.ts +2 -0
  186. package/utils/index.js +2 -0
  187. package/utils/waitUntilHealthy/UnhealthyClusterError.d.ts +4 -0
  188. package/utils/waitUntilHealthy/UnhealthyClusterError.js +12 -0
  189. package/utils/waitUntilHealthy/UnhealthyClusterError.js.map +1 -0
  190. package/utils/waitUntilHealthy/WaitUntilHealthy.d.ts +72 -0
  191. package/utils/waitUntilHealthy/WaitUntilHealthy.js +131 -0
  192. package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -0
  193. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.d.ts +4 -0
  194. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js +12 -0
  195. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js.map +1 -0
  196. package/utils/waitUntilHealthy/index.d.ts +4 -0
  197. package/utils/waitUntilHealthy/index.js +4 -0
  198. package/utils/waitUntilHealthy/reason/ClusterHealthReason.d.ts +15 -0
  199. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js +12 -0
  200. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js.map +1 -0
  201. package/utils/waitUntilHealthy/reason/IReason.d.ts +4 -0
  202. package/utils/waitUntilHealthy/reason/IReason.js +0 -0
  203. package/utils/waitUntilHealthy/reason/MemoryReason.d.ts +14 -0
  204. package/utils/waitUntilHealthy/reason/MemoryReason.js +12 -0
  205. package/utils/waitUntilHealthy/reason/MemoryReason.js.map +1 -0
  206. package/utils/waitUntilHealthy/reason/ProcessorReason.d.ts +14 -0
  207. package/utils/waitUntilHealthy/reason/ProcessorReason.js +12 -0
  208. package/utils/waitUntilHealthy/reason/ProcessorReason.js.map +1 -0
  209. package/utils/waitUntilHealthy/reason/index.d.ts +3 -0
  210. package/utils/waitUntilHealthy/reason/index.js +3 -0
  211. package/where.d.ts +17 -0
  212. package/where.js +49 -0
  213. package/where.js.map +1 -0
@@ -0,0 +1,30 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { stripConnectionFromException } from "./stripConnectionFromException.js";
3
+ class OpenSearchCatHealth {
4
+ constructor(client){
5
+ this.client = client;
6
+ }
7
+ async getHealth() {
8
+ try {
9
+ const response = await this.client.cat.health({
10
+ format: "json"
11
+ });
12
+ if (!Array.isArray(response.body) || 0 === response.body.length) throw new WebinyError({
13
+ message: "There is no valid response from cat.health operation.",
14
+ code: "OPENSEARCH_HEALTH_INVALID_RESPONSE",
15
+ data: response.body
16
+ });
17
+ return {
18
+ ...response.body[0]
19
+ };
20
+ } catch (ex) {
21
+ console.error(`Could not fetch cluster health information: ${ex.message}`);
22
+ const error = stripConnectionFromException(ex);
23
+ console.log(JSON.stringify(error));
24
+ throw error;
25
+ }
26
+ }
27
+ }
28
+ export { OpenSearchCatHealth };
29
+
30
+ //# sourceMappingURL=OpenSearchCatHealth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/OpenSearchCatHealth.js","sources":["../../src/operations/OpenSearchCatHealth.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { Client } from \"~/client.js\";\nimport type { IOpenSearchCatHealthResponse } from \"./types.js\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatHealth {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getHealth(): Promise<IOpenSearchCatHealthResponse> {\n try {\n const response = await this.client.cat.health({\n format: \"json\"\n });\n\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.health operation.`,\n code: \"OPENSEARCH_HEALTH_INVALID_RESPONSE\",\n data: response.body\n });\n }\n\n return {\n ...response.body[0]\n };\n } catch (ex) {\n console.error(`Could not fetch cluster health information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"names":["OpenSearchCatHealth","client","response","Array","WebinyError","ex","console","error","stripConnectionFromException","JSON"],"mappings":";;AAKO,MAAMA;IAGT,YAAmBC,MAAc,CAAE;QAC/B,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAa,YAAmD;QAC5D,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC1C,QAAQ;YACZ;YAEA,IAAI,CAACC,MAAM,OAAO,CAACD,SAAS,IAAI,KAAKA,AAAyB,MAAzBA,SAAS,IAAI,CAAC,MAAM,EACrD,MAAM,IAAIE,YAAY;gBAClB,SAAS;gBACT,MAAM;gBACN,MAAMF,SAAS,IAAI;YACvB;YAGJ,OAAO;gBACH,GAAGA,SAAS,IAAI,CAAC,EAAE;YACvB;QACJ,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CAAC,CAAC,4CAA4C,EAAED,GAAG,OAAO,EAAE;YACzE,MAAME,QAAQC,6BAA6BH;YAC3CC,QAAQ,GAAG,CAACG,KAAK,SAAS,CAACF;YAC3B,MAAMA;QACV;IACJ;AACJ"}
@@ -0,0 +1,7 @@
1
+ import type { IOpenSearchCatNodesResponse } from "./types.js";
2
+ import type { Client } from "../client.js";
3
+ export declare class OpenSearchCatNodes {
4
+ private readonly client;
5
+ constructor(client: Client);
6
+ getNodes(): Promise<IOpenSearchCatNodesResponse>;
7
+ }
@@ -0,0 +1,28 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { stripConnectionFromException } from "./stripConnectionFromException.js";
3
+ class OpenSearchCatNodes {
4
+ constructor(client){
5
+ this.client = client;
6
+ }
7
+ async getNodes() {
8
+ try {
9
+ const response = await this.client.cat.nodes({
10
+ format: "json"
11
+ });
12
+ if (!Array.isArray(response.body) || 0 === response.body.length) throw new WebinyError({
13
+ message: "There is no valid response from cat.nodes operation.",
14
+ code: "OPENSEARCH_NODES_INVALID_RESPONSE",
15
+ data: response.body
16
+ });
17
+ return response.body;
18
+ } catch (ex) {
19
+ console.error(`Could not fetch cluster nodes information: ${ex.message}`);
20
+ const error = stripConnectionFromException(ex);
21
+ console.log(JSON.stringify(error));
22
+ throw error;
23
+ }
24
+ }
25
+ }
26
+ export { OpenSearchCatNodes };
27
+
28
+ //# sourceMappingURL=OpenSearchCatNodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/OpenSearchCatNodes.js","sources":["../../src/operations/OpenSearchCatNodes.ts"],"sourcesContent":["import type { IOpenSearchCatNodesResponse } from \"./types.js\";\nimport type { Client } from \"~/client.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatNodes {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getNodes(): Promise<IOpenSearchCatNodesResponse> {\n try {\n const response = await this.client.cat.nodes({\n format: \"json\"\n });\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.nodes operation.`,\n code: \"OPENSEARCH_NODES_INVALID_RESPONSE\",\n data: response.body\n });\n }\n return response.body;\n } catch (ex) {\n console.error(`Could not fetch cluster nodes information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"names":["OpenSearchCatNodes","client","response","Array","WebinyError","ex","console","error","stripConnectionFromException","JSON"],"mappings":";;AAKO,MAAMA;IAGT,YAAmBC,MAAc,CAAE;QAC/B,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEA,MAAa,WAAiD;QAC1D,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;gBACzC,QAAQ;YACZ;YACA,IAAI,CAACC,MAAM,OAAO,CAACD,SAAS,IAAI,KAAKA,AAAyB,MAAzBA,SAAS,IAAI,CAAC,MAAM,EACrD,MAAM,IAAIE,YAAY;gBAClB,SAAS;gBACT,MAAM;gBACN,MAAMF,SAAS,IAAI;YACvB;YAEJ,OAAOA,SAAS,IAAI;QACxB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CAAC,CAAC,2CAA2C,EAAED,GAAG,OAAO,EAAE;YACxE,MAAME,QAAQC,6BAA6BH;YAC3CC,QAAQ,GAAG,CAACG,KAAK,SAAS,CAACF;YAC3B,MAAMA;QACV;IACJ;AACJ"}
@@ -0,0 +1,3 @@
1
+ export * from "./OpenSearchCatHealth.js";
2
+ export * from "./OpenSearchCatNodes.js";
3
+ export * from "./types.js";
@@ -0,0 +1,3 @@
1
+ export * from "./OpenSearchCatHealth.js";
2
+ export * from "./OpenSearchCatNodes.js";
3
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export declare const stripConnectionFromException: (ex: any) => any;
@@ -0,0 +1,14 @@
1
+ const stripConnectionFromException = (ex)=>{
2
+ if ("object" != typeof ex) return ex;
3
+ if (!ex?.meta?.meta?.connection) return ex;
4
+ return {
5
+ ...ex.meta,
6
+ meta: {
7
+ ...ex.meta.meta,
8
+ connection: null
9
+ }
10
+ };
11
+ };
12
+ export { stripConnectionFromException };
13
+
14
+ //# sourceMappingURL=stripConnectionFromException.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/stripConnectionFromException.js","sources":["../../src/operations/stripConnectionFromException.ts"],"sourcesContent":["export const stripConnectionFromException = (ex: any): any => {\n if (typeof ex !== \"object\") {\n return ex;\n }\n if (!ex?.meta?.meta?.connection) {\n return ex;\n }\n return {\n ...ex.meta,\n meta: {\n ...ex.meta.meta,\n connection: null\n }\n };\n};\n"],"names":["stripConnectionFromException","ex"],"mappings":"AAAO,MAAMA,+BAA+B,CAACC;IACzC,IAAI,AAAc,YAAd,OAAOA,IACP,OAAOA;IAEX,IAAI,CAACA,IAAI,MAAM,MAAM,YACjB,OAAOA;IAEX,OAAO;QACH,GAAGA,GAAG,IAAI;QACV,MAAM;YACF,GAAGA,GAAG,IAAI,CAAC,IAAI;YACf,YAAY;QAChB;IACJ;AACJ"}
@@ -0,0 +1,12 @@
1
+ import type { Cat_Health_ResponseBody, Cat_Nodes_ResponseBody } from "@opensearch-project/opensearch/api/index.js";
2
+ export declare enum OpenSearchCatClusterHealthStatus {
3
+ Green = "green",
4
+ Yellow = "yellow",
5
+ Red = "red"
6
+ }
7
+ type HealthRecord = Cat_Health_ResponseBody[number];
8
+ type NodesRecord = Cat_Nodes_ResponseBody[number];
9
+ export type IOpenSearchCatHealthResponse = HealthRecord;
10
+ export type IOpenSearchCatNodeResponse = NodesRecord;
11
+ export type IOpenSearchCatNodesResponse = IOpenSearchCatNodeResponse[];
12
+ export {};
@@ -0,0 +1,9 @@
1
+ var types_OpenSearchCatClusterHealthStatus = /*#__PURE__*/ function(OpenSearchCatClusterHealthStatus) {
2
+ OpenSearchCatClusterHealthStatus["Green"] = "green";
3
+ OpenSearchCatClusterHealthStatus["Yellow"] = "yellow";
4
+ OpenSearchCatClusterHealthStatus["Red"] = "red";
5
+ return OpenSearchCatClusterHealthStatus;
6
+ }({});
7
+ export { types_OpenSearchCatClusterHealthStatus as OpenSearchCatClusterHealthStatus };
8
+
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/types.js","sources":["../../src/operations/types.ts"],"sourcesContent":["import type {\n Cat_Health_ResponseBody,\n Cat_Nodes_ResponseBody\n} from \"@opensearch-project/opensearch/api/index.js\";\n\nexport enum OpenSearchCatClusterHealthStatus {\n Green = \"green\",\n Yellow = \"yellow\",\n Red = \"red\"\n}\n\ntype HealthRecord = Cat_Health_ResponseBody[number];\n\ntype NodesRecord = Cat_Nodes_ResponseBody[number];\n\nexport type IOpenSearchCatHealthResponse = HealthRecord;\n\nexport type IOpenSearchCatNodeResponse = NodesRecord;\n\nexport type IOpenSearchCatNodesResponse = IOpenSearchCatNodeResponse[];\n"],"names":["OpenSearchCatClusterHealthStatus"],"mappings":"AAKO,IAAKA,yCAAgCA,WAAAA,GAAAA,SAAhCA,gCAAgC;;;;WAAhCA"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@webiny/api-opensearch",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/webiny/webiny-js.git",
12
+ "directory": "packages/api-opensearch"
13
+ },
14
+ "description": "A set of plugins to work with OpenSearch.",
15
+ "contributors": [
16
+ "Pavel Denisjuk <pavel@webiny.com>"
17
+ ],
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "@opensearch-project/opensearch": "3.6.0",
21
+ "@webiny/api": "0.0.0-unstable.0d717d18dd",
22
+ "@webiny/aws-sdk": "0.0.0-unstable.0d717d18dd",
23
+ "@webiny/db-dynamodb": "0.0.0-unstable.0d717d18dd",
24
+ "@webiny/error": "0.0.0-unstable.0d717d18dd",
25
+ "@webiny/feature": "0.0.0-unstable.0d717d18dd",
26
+ "@webiny/handler": "0.0.0-unstable.0d717d18dd"
27
+ },
28
+ "devDependencies": {
29
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
30
+ "@webiny/di": "1.0.2",
31
+ "@webiny/project-utils": "0.0.0-unstable.0d717d18dd",
32
+ "rimraf": "6.1.3",
33
+ "typescript": "7.0.2",
34
+ "vitest": "4.1.10"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "webiny": {
40
+ "publishFrom": "dist"
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ import type { OpenSearchClientOptions } from "./client.js";
2
+ import { Client } from "./client.js";
3
+ export declare const registerOpenSearchCore: (params: OpenSearchClientOptions | Client) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>;
@@ -0,0 +1,20 @@
1
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
2
+ import { OpenSearchClientFeature } from "./features/OpenSearchClient/feature.js";
3
+ import { OpenSearchClientFactoryFeature } from "./features/OpenSearchClientFactory/feature.js";
4
+ import { OpenSearchQueryBuilderOperatorFeature } from "./features/OpenSearchQueryBuilderOperator/feature.js";
5
+ import { OpenSearchFieldFeature } from "./features/OpenSearchField/feature.js";
6
+ import { OpenSearchIndexFeature } from "./features/OpenSearchIndex/feature.js";
7
+ import { Client, createOpenSearchClient } from "./client.js";
8
+ const registerOpenSearchCore = (params)=>createRegisterExtensionPlugin(async (context)=>{
9
+ if (context.__registeredOpensearch) throw new Error("OpenSearch core must not be loaded more than once!");
10
+ const client = params instanceof Client ? params : createOpenSearchClient(params);
11
+ context.__registeredOpensearch = true;
12
+ OpenSearchClientFeature.register(context.container, client);
13
+ OpenSearchClientFactoryFeature.register(context.container);
14
+ OpenSearchQueryBuilderOperatorFeature.register(context.container);
15
+ OpenSearchFieldFeature.register(context.container);
16
+ OpenSearchIndexFeature.register(context.container);
17
+ });
18
+ export { registerOpenSearchCore };
19
+
20
+ //# sourceMappingURL=registerOpenSearchCore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerOpenSearchCore.js","sources":["../src/registerOpenSearchCore.ts"],"sourcesContent":["import { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { OpenSearchClientFeature } from \"~/features/OpenSearchClient/feature.js\";\nimport { OpenSearchClientFactoryFeature } from \"~/features/OpenSearchClientFactory/feature.js\";\nimport { OpenSearchQueryBuilderOperatorFeature } from \"~/features/OpenSearchQueryBuilderOperator/feature.js\";\nimport { OpenSearchFieldFeature } from \"~/features/OpenSearchField/feature.js\";\nimport { OpenSearchIndexFeature } from \"~/features/OpenSearchIndex/feature.js\";\nimport type { OpenSearchClientOptions } from \"~/client.js\";\nimport { Client, createOpenSearchClient } from \"~/client.js\";\n\nexport const registerOpenSearchCore = (params: OpenSearchClientOptions | Client) => {\n return createRegisterExtensionPlugin(async context => {\n // @ts-expect-error\n if (context.__registeredOpensearch) {\n throw new Error(\"OpenSearch core must not be loaded more than once!\");\n }\n const client = params instanceof Client ? params : createOpenSearchClient(params);\n // @ts-expect-error\n context.__registeredOpensearch = true;\n\n OpenSearchClientFeature.register(context.container, client);\n OpenSearchClientFactoryFeature.register(context.container);\n OpenSearchQueryBuilderOperatorFeature.register(context.container);\n OpenSearchFieldFeature.register(context.container);\n OpenSearchIndexFeature.register(context.container);\n });\n};\n"],"names":["registerOpenSearchCore","params","createRegisterExtensionPlugin","context","Error","client","Client","createOpenSearchClient","OpenSearchClientFeature","OpenSearchClientFactoryFeature","OpenSearchQueryBuilderOperatorFeature","OpenSearchFieldFeature","OpenSearchIndexFeature"],"mappings":";;;;;;;AASO,MAAMA,yBAAyB,CAACC,SAC5BC,8BAA8B,OAAMC;QAEvC,IAAIA,QAAQ,sBAAsB,EAC9B,MAAM,IAAIC,MAAM;QAEpB,MAAMC,SAASJ,kBAAkBK,SAASL,SAASM,uBAAuBN;QAE1EE,QAAQ,sBAAsB,GAAG;QAEjCK,wBAAwB,QAAQ,CAACL,QAAQ,SAAS,EAAEE;QACpDI,+BAA+B,QAAQ,CAACN,QAAQ,SAAS;QACzDO,sCAAsC,QAAQ,CAACP,QAAQ,SAAS;QAChEQ,uBAAuB,QAAQ,CAACR,QAAQ,SAAS;QACjDS,uBAAuB,QAAQ,CAACT,QAAQ,SAAS;IACrD"}
@@ -0,0 +1 @@
1
+ export declare const isSharedOpenSearchIndex: () => boolean;
package/sharedIndex.js ADDED
@@ -0,0 +1,4 @@
1
+ const isSharedOpenSearchIndex = ()=>"true" === process.env.OPENSEARCH_SHARED_INDEXES;
2
+ export { isSharedOpenSearchIndex };
3
+
4
+ //# sourceMappingURL=sharedIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedIndex.js","sources":["../src/sharedIndex.ts"],"sourcesContent":["export const isSharedOpenSearchIndex = () => {\n return process.env.OPENSEARCH_SHARED_INDEXES === \"true\";\n};\n"],"names":["isSharedOpenSearchIndex","process"],"mappings":"AAAO,MAAMA,0BAA0B,IAC5BC,AAA0C,WAA1CA,QAAQ,GAAG,CAAC,yBAAyB"}
package/sort.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { SortOrder, SortType } from "./types.js";
2
+ import { OpenSearchField } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
3
+ interface CreateSortParams {
4
+ sort: string[];
5
+ defaults?: {
6
+ field?: string;
7
+ order?: SortOrder;
8
+ unmappedType?: string;
9
+ };
10
+ fieldPlugins: Record<string, OpenSearchField.Interface>;
11
+ }
12
+ export declare const createSort: (params: CreateSortParams) => SortType;
13
+ export {};
package/sort.js ADDED
@@ -0,0 +1,36 @@
1
+ import error from "@webiny/error";
2
+ import { OpenSearchFieldAll } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
3
+ const sortRegExp = /^((?:values\.)?[a-zA-Z0-9_@-]+)_(ASC|DESC)$/;
4
+ const createSort = (params)=>{
5
+ const { sort, defaults, fieldPlugins } = params;
6
+ if (!sort || 0 === sort.length) {
7
+ const { field, order, unmappedType } = defaults || {};
8
+ return {
9
+ [field || "id.keyword"]: {
10
+ order: order || "desc",
11
+ unmapped_type: unmappedType || void 0
12
+ }
13
+ };
14
+ }
15
+ const result = sort.reduce((acc, value)=>{
16
+ if ("string" != typeof value) throw new error("Sort as object is not supported..");
17
+ const match = value.match(sortRegExp);
18
+ if (!match) throw new error(`Cannot sort by "${value}".`);
19
+ const [, field, initialOrder] = match;
20
+ const order = "asc" === initialOrder.toLowerCase() ? "asc" : "desc";
21
+ const plugin = fieldPlugins[field] || fieldPlugins[OpenSearchFieldAll];
22
+ if (!plugin) throw new error(`Missing plugin for the field "${field}"`, "PLUGIN_SORT_ERROR", {
23
+ field
24
+ });
25
+ const path = plugin.getPath(field);
26
+ acc[path] = plugin.getSortOptions(order);
27
+ return acc;
28
+ }, {});
29
+ if (!result["id.keyword"] && !result["id"]) result["id.keyword"] = {
30
+ order: "asc"
31
+ };
32
+ return result;
33
+ };
34
+ export { createSort };
35
+
36
+ //# sourceMappingURL=sort.js.map
package/sort.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.js","sources":["../src/sort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldSortOptions, SortOrder, SortType } from \"~/types.js\";\nimport {\n OpenSearchField,\n OpenSearchFieldAll\n} from \"~/features/OpenSearchField/abstractions/OpenSearchField.js\";\n\nconst sortRegExp = /^((?:values\\.)?[a-zA-Z0-9_@-]+)_(ASC|DESC)$/;\n\ninterface CreateSortParams {\n sort: string[];\n defaults?: {\n field?: string;\n order?: SortOrder;\n unmappedType?: string;\n };\n fieldPlugins: Record<string, OpenSearchField.Interface>;\n}\n\nexport const createSort = (params: CreateSortParams): SortType => {\n const { sort, defaults, fieldPlugins } = params;\n if (!sort || sort.length === 0) {\n const { field, order, unmappedType } = defaults || {};\n return {\n [field || \"id.keyword\"]: {\n order: order || \"desc\",\n unmapped_type: (unmappedType || undefined) as any\n }\n };\n }\n const result = sort.reduce(\n (acc, value) => {\n if (typeof value !== \"string\") {\n throw new WebinyError(`Sort as object is not supported..`);\n }\n const match = value.match(sortRegExp);\n\n if (!match) {\n throw new WebinyError(`Cannot sort by \"${value}\".`);\n }\n\n const [, field, initialOrder] = match;\n const order: SortOrder = initialOrder.toLowerCase() === \"asc\" ? \"asc\" : \"desc\";\n\n const plugin: OpenSearchField.Interface =\n fieldPlugins[field] || fieldPlugins[OpenSearchFieldAll];\n if (!plugin) {\n throw new WebinyError(\n `Missing plugin for the field \"${field}\"`,\n \"PLUGIN_SORT_ERROR\",\n {\n field\n }\n );\n }\n const path = plugin.getPath(field);\n\n acc[path] = plugin.getSortOptions(order);\n\n return acc;\n },\n {} as Record<string, FieldSortOptions>\n );\n if (!result[\"id.keyword\"] && !result[\"id\"]) {\n result[\"id.keyword\"] = {\n order: \"asc\"\n };\n }\n return result;\n};\n"],"names":["sortRegExp","createSort","params","sort","defaults","fieldPlugins","field","order","unmappedType","undefined","result","acc","value","WebinyError","match","initialOrder","plugin","OpenSearchFieldAll","path"],"mappings":";;AAOA,MAAMA,aAAa;AAYZ,MAAMC,aAAa,CAACC;IACvB,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,YAAY,EAAE,GAAGH;IACzC,IAAI,CAACC,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,EAAQ;QAC5B,MAAM,EAAEG,KAAK,EAAEC,KAAK,EAAEC,YAAY,EAAE,GAAGJ,YAAY,CAAC;QACpD,OAAO;YACH,CAACE,SAAS,aAAa,EAAE;gBACrB,OAAOC,SAAS;gBAChB,eAAgBC,gBAAgBC;YACpC;QACJ;IACJ;IACA,MAAMC,SAASP,KAAK,MAAM,CACtB,CAACQ,KAAKC;QACF,IAAI,AAAiB,YAAjB,OAAOA,OACP,MAAM,IAAIC,MAAY;QAE1B,MAAMC,QAAQF,MAAM,KAAK,CAACZ;QAE1B,IAAI,CAACc,OACD,MAAM,IAAID,MAAY,CAAC,gBAAgB,EAAED,MAAM,EAAE,CAAC;QAGtD,MAAM,GAAGN,OAAOS,aAAa,GAAGD;QAChC,MAAMP,QAAmBQ,AAA+B,UAA/BA,aAAa,WAAW,KAAe,QAAQ;QAExE,MAAMC,SACFX,YAAY,CAACC,MAAM,IAAID,YAAY,CAACY,mBAAmB;QAC3D,IAAI,CAACD,QACD,MAAM,IAAIH,MACN,CAAC,8BAA8B,EAAEP,MAAM,CAAC,CAAC,EACzC,qBACA;YACIA;QACJ;QAGR,MAAMY,OAAOF,OAAO,OAAO,CAACV;QAE5BK,GAAG,CAACO,KAAK,GAAGF,OAAO,cAAc,CAACT;QAElC,OAAOI;IACX,GACA,CAAC;IAEL,IAAI,CAACD,MAAM,CAAC,aAAa,IAAI,CAACA,MAAM,CAAC,KAAK,EACtCA,MAAM,CAAC,aAAa,GAAG;QACnB,OAAO;IACX;IAEJ,OAAOA;AACX"}
@@ -0,0 +1,2 @@
1
+ import type { OpenSearchBoolQueryConfig } from "../types.js";
2
+ export declare const createBlankQuery: () => OpenSearchBoolQueryConfig;
@@ -0,0 +1,9 @@
1
+ const createBlankQuery = ()=>({
2
+ must_not: [],
3
+ must: [],
4
+ filter: [],
5
+ should: []
6
+ });
7
+ export { createBlankQuery };
8
+
9
+ //# sourceMappingURL=createBlankQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/createBlankQuery.js","sources":["../../src/testing/createBlankQuery.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"~/types.js\";\n\nexport const createBlankQuery = (): OpenSearchBoolQueryConfig => ({\n must_not: [],\n must: [],\n filter: [],\n should: []\n});\n"],"names":["createBlankQuery"],"mappings":"AAEO,MAAMA,mBAAmB,IAAkC;QAC9D,UAAU,EAAE;QACZ,MAAM,EAAE;QACR,QAAQ,EAAE;QACV,QAAQ,EAAE;IACd"}
@@ -0,0 +1,11 @@
1
+ import { Client } from "@opensearch-project/opensearch";
2
+ import type { ClientOptions } from "@opensearch-project/opensearch";
3
+ export interface TestOpenSearchClient extends Client {
4
+ indices: Client["indices"] & {
5
+ deleteAll: () => Promise<void>;
6
+ refreshAll: (indexes?: string[] | null) => Promise<void>;
7
+ registerIndex: (names: string[] | string) => void;
8
+ };
9
+ }
10
+ export declare const createTestOpenSearchClient: (options?: Partial<ClientOptions>) => TestOpenSearchClient;
11
+ export declare const getTestOpenSearchClient: () => TestOpenSearchClient;
@@ -0,0 +1,162 @@
1
+ import { Client } from "@opensearch-project/opensearch";
2
+ const OPENSEARCH_PORT = process.env.OPENSEARCH_PORT || 9200;
3
+ const getDefaultOptions = ()=>{
4
+ const endpoint = process.env.OPENSEARCH_ENDPOINT;
5
+ const username = process.env.OPENSEARCH_USERNAME;
6
+ const password = process.env.OPENSEARCH_PASSWORD;
7
+ const options = {
8
+ node: `http://localhost:${OPENSEARCH_PORT}`,
9
+ maxRetries: 10,
10
+ pingTimeout: 500
11
+ };
12
+ if (username && password) options.auth = {
13
+ username,
14
+ password
15
+ };
16
+ if (endpoint) options.node = null === endpoint.match(/^http/) ? `https://${endpoint}` : endpoint;
17
+ return options;
18
+ };
19
+ const SNAPSHOT_ERROR = "snapshot_in_progress_exception";
20
+ const isSnapshotError = (ex)=>{
21
+ if (ex.meta?.body?.error?.type === SNAPSHOT_ERROR) return true;
22
+ const rootCauses = ex.meta?.body?.error?.root_cause;
23
+ if (!Array.isArray(rootCauses)) return false;
24
+ return rootCauses.some((rc)=>rc.type === SNAPSHOT_ERROR);
25
+ };
26
+ const wait = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms));
27
+ const createDeleteIndex = (client)=>{
28
+ const maxRetries = 10;
29
+ return async (index)=>{
30
+ for(let attempt = 0; attempt <= maxRetries; attempt++){
31
+ try {
32
+ const { body: exists } = await client.indices.exists({
33
+ index,
34
+ ignore_unavailable: true
35
+ });
36
+ if (!exists) return;
37
+ } catch (ex) {
38
+ console.log(`Could not determine that index exists: ${index}`);
39
+ console.log(ex.message);
40
+ return;
41
+ }
42
+ try {
43
+ await client.indices.delete({
44
+ index,
45
+ ignore_unavailable: true
46
+ });
47
+ return;
48
+ } catch (ex) {
49
+ console.log(`Could not delete index: ${index}`);
50
+ if (!isSnapshotError(ex)) return;
51
+ console.log("Snapshot in progress, retrying...");
52
+ }
53
+ await wait(1000);
54
+ }
55
+ };
56
+ };
57
+ const attachTestBehavior = (client)=>{
58
+ const registeredIndexes = new Set();
59
+ const dirtyIndexes = new Set();
60
+ const originalCreate = client.indices.create;
61
+ const originalExists = client.indices.exists;
62
+ const deleteIndex = createDeleteIndex(client);
63
+ const registerIndex = (input)=>{
64
+ if (!input) return;
65
+ const names = Array.isArray(input) ? input : [
66
+ input
67
+ ];
68
+ for (const name of names)registeredIndexes.add(name);
69
+ };
70
+ const refreshIndex = async (index)=>{
71
+ try {
72
+ await client.indices.refresh({
73
+ index,
74
+ ignore_unavailable: true
75
+ });
76
+ } catch (ex) {
77
+ console.log(`Could not refresh index "${index}": ${ex.message}`);
78
+ throw ex;
79
+ }
80
+ };
81
+ const refreshAll = async (indexes = null)=>{
82
+ const targets = indexes?.length ? indexes : Array.from(registeredIndexes.values());
83
+ for (const index of targets){
84
+ await refreshIndex(index);
85
+ dirtyIndexes.delete(index);
86
+ }
87
+ };
88
+ client.indices.exists = async (params, options = {})=>{
89
+ registerIndex(params.index);
90
+ return originalExists.apply(client.indices, [
91
+ params,
92
+ options
93
+ ]);
94
+ };
95
+ client.indices.create = async (params, options = {})=>{
96
+ await deleteIndex(params.index);
97
+ const response = await originalCreate.apply(client.indices, [
98
+ params,
99
+ options
100
+ ]);
101
+ registeredIndexes.add(params.index);
102
+ await client.indices.refresh({
103
+ index: params.index
104
+ });
105
+ return response;
106
+ };
107
+ const testClient = client;
108
+ testClient.indices.deleteAll = async ()=>{
109
+ const indexes = Array.from(registeredIndexes.values());
110
+ for (const index of indexes)try {
111
+ await deleteIndex(index);
112
+ } catch {
113
+ console.log(`Could not delete index "${index}".`);
114
+ }
115
+ };
116
+ testClient.indices.refreshAll = refreshAll;
117
+ testClient.indices.registerIndex = registerIndex;
118
+ const originalSearch = client.search;
119
+ client.search = async (...params)=>{
120
+ const [param] = params;
121
+ const index = param?.index;
122
+ if (index && dirtyIndexes.has(index)) {
123
+ await refreshIndex(index);
124
+ dirtyIndexes.delete(index);
125
+ }
126
+ return await originalSearch.apply(client, params);
127
+ };
128
+ const originalBulk = client.bulk;
129
+ client.bulk = async (...params)=>{
130
+ const [param] = params;
131
+ const { body } = param;
132
+ const deletedIndexes = new Set();
133
+ if (Array.isArray(body)) {
134
+ for (const item of body)if (item.index?._index) {
135
+ dirtyIndexes.add(item.index._index);
136
+ registerIndex(item.index._index);
137
+ } else if (item.delete?._index) {
138
+ deletedIndexes.add(item.delete._index);
139
+ registerIndex(item.delete._index);
140
+ }
141
+ }
142
+ const result = await originalBulk.apply(client, params);
143
+ if (deletedIndexes.size > 0) await refreshAll(Array.from(deletedIndexes));
144
+ return result;
145
+ };
146
+ return testClient;
147
+ };
148
+ const createTestOpenSearchClient = (options = {})=>{
149
+ const client = new Client({
150
+ ...getDefaultOptions(),
151
+ ...options
152
+ });
153
+ return attachTestBehavior(client);
154
+ };
155
+ let singletonClient = null;
156
+ const getTestOpenSearchClient = ()=>{
157
+ if (!singletonClient) singletonClient = createTestOpenSearchClient();
158
+ return singletonClient;
159
+ };
160
+ export { createTestOpenSearchClient, getTestOpenSearchClient };
161
+
162
+ //# sourceMappingURL=createTestOpenSearchClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/createTestOpenSearchClient.js","sources":["../../src/testing/createTestOpenSearchClient.ts"],"sourcesContent":["import { Client } from \"@opensearch-project/opensearch\";\nimport type { ClientOptions } from \"@opensearch-project/opensearch\";\n\nconst OPENSEARCH_PORT = process.env.OPENSEARCH_PORT || 9200;\n\nconst getDefaultOptions = (): Partial<ClientOptions> => {\n const endpoint = process.env.OPENSEARCH_ENDPOINT;\n const username = process.env.OPENSEARCH_USERNAME;\n const password = process.env.OPENSEARCH_PASSWORD;\n\n const options: Partial<ClientOptions> = {\n node: `http://localhost:${OPENSEARCH_PORT}`,\n maxRetries: 10,\n pingTimeout: 500\n };\n\n if (username && password) {\n options.auth = { username, password };\n }\n\n if (endpoint) {\n options.node = endpoint.match(/^http/) === null ? `https://${endpoint}` : endpoint;\n }\n\n return options;\n};\n\nconst SNAPSHOT_ERROR = \"snapshot_in_progress_exception\";\n\nconst isSnapshotError = (ex: any): boolean => {\n if (ex.meta?.body?.error?.type === SNAPSHOT_ERROR) {\n return true;\n }\n const rootCauses = ex.meta?.body?.error?.root_cause;\n if (!Array.isArray(rootCauses)) {\n return false;\n }\n return rootCauses.some((rc: any) => rc.type === SNAPSHOT_ERROR);\n};\n\nconst wait = (ms: number): Promise<void> => {\n return new Promise(resolve => setTimeout(resolve, ms));\n};\n\nconst createDeleteIndex = (client: Client) => {\n const maxRetries = 10;\n\n return async (index: string): Promise<void> => {\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const { body: exists } = await client.indices.exists({\n index,\n ignore_unavailable: true\n });\n if (!exists) {\n return;\n }\n } catch (ex: any) {\n console.log(`Could not determine that index exists: ${index}`);\n console.log(ex.message);\n return;\n }\n\n try {\n await client.indices.delete({ index, ignore_unavailable: true });\n return;\n } catch (ex: any) {\n console.log(`Could not delete index: ${index}`);\n if (!isSnapshotError(ex)) {\n return;\n }\n console.log(\"Snapshot in progress, retrying...\");\n }\n\n await wait(1000);\n }\n };\n};\n\nexport interface TestOpenSearchClient extends Client {\n indices: Client[\"indices\"] & {\n deleteAll: () => Promise<void>;\n refreshAll: (indexes?: string[] | null) => Promise<void>;\n registerIndex: (names: string[] | string) => void;\n };\n}\n\nconst attachTestBehavior = (client: Client): TestOpenSearchClient => {\n const registeredIndexes = new Set<string>();\n const dirtyIndexes = new Set<string>();\n const originalCreate = client.indices.create;\n const originalExists = client.indices.exists;\n const deleteIndex = createDeleteIndex(client);\n\n const registerIndex = (input: string[] | string) => {\n if (!input) {\n return;\n }\n const names = Array.isArray(input) ? input : [input];\n for (const name of names) {\n registeredIndexes.add(name);\n }\n };\n\n const refreshIndex = async (index: string) => {\n try {\n await client.indices.refresh({ index, ignore_unavailable: true });\n } catch (ex: any) {\n console.log(`Could not refresh index \"${index}\": ${ex.message}`);\n throw ex;\n }\n };\n\n const refreshAll = async (indexes: string[] | null = null) => {\n const targets = indexes?.length ? indexes : Array.from(registeredIndexes.values());\n for (const index of targets) {\n await refreshIndex(index);\n dirtyIndexes.delete(index);\n }\n };\n\n // @ts-expect-error\n client.indices.exists = async (params: any, options: any = {}) => {\n registerIndex(params.index);\n // @ts-expect-error\n return originalExists.apply(client.indices, [params, options]);\n };\n\n // @ts-expect-error\n client.indices.create = async (params: any, options: any = {}) => {\n await deleteIndex(params.index);\n // @ts-expect-error\n const response = await originalCreate.apply(client.indices, [params, options]);\n registeredIndexes.add(params.index);\n await client.indices.refresh({ index: params.index });\n return response;\n };\n\n const testClient = client as TestOpenSearchClient;\n\n testClient.indices.deleteAll = async () => {\n const indexes = Array.from(registeredIndexes.values());\n for (const index of indexes) {\n try {\n await deleteIndex(index);\n } catch {\n console.log(`Could not delete index \"${index}\".`);\n }\n }\n };\n\n testClient.indices.refreshAll = refreshAll;\n testClient.indices.registerIndex = registerIndex;\n\n const originalSearch = client.search;\n // @ts-expect-error\n client.search = async (...params: any[]) => {\n const [param] = params;\n const index = param?.index;\n if (index && dirtyIndexes.has(index)) {\n await refreshIndex(index);\n dirtyIndexes.delete(index);\n }\n // @ts-expect-error\n return await originalSearch.apply(client, params);\n };\n\n const originalBulk = client.bulk;\n // @ts-expect-error\n client.bulk = async (...params: any[]) => {\n const [param] = params;\n const { body } = param;\n const deletedIndexes = new Set<string>();\n if (Array.isArray(body)) {\n for (const item of body) {\n if (item.index?._index) {\n dirtyIndexes.add(item.index._index);\n registerIndex(item.index._index);\n } else if (item.delete?._index) {\n deletedIndexes.add(item.delete._index);\n registerIndex(item.delete._index);\n }\n }\n }\n // @ts-expect-error\n const result = await originalBulk.apply(client, params);\n if (deletedIndexes.size > 0) {\n await refreshAll(Array.from(deletedIndexes));\n }\n return result;\n };\n\n return testClient;\n};\n\nexport const createTestOpenSearchClient = (\n options: Partial<ClientOptions> = {}\n): TestOpenSearchClient => {\n const client = new Client({\n ...getDefaultOptions(),\n ...options\n });\n return attachTestBehavior(client);\n};\n\nlet singletonClient: TestOpenSearchClient | null = null;\n\nexport const getTestOpenSearchClient = (): TestOpenSearchClient => {\n if (!singletonClient) {\n singletonClient = createTestOpenSearchClient();\n }\n return singletonClient;\n};\n"],"names":["OPENSEARCH_PORT","process","getDefaultOptions","endpoint","username","password","options","SNAPSHOT_ERROR","isSnapshotError","ex","rootCauses","Array","rc","wait","ms","Promise","resolve","setTimeout","createDeleteIndex","client","maxRetries","index","attempt","exists","console","attachTestBehavior","registeredIndexes","Set","dirtyIndexes","originalCreate","originalExists","deleteIndex","registerIndex","input","names","name","refreshIndex","refreshAll","indexes","targets","params","response","testClient","originalSearch","param","originalBulk","body","deletedIndexes","item","result","createTestOpenSearchClient","Client","singletonClient","getTestOpenSearchClient"],"mappings":";AAGA,MAAMA,kBAAkBC,QAAQ,GAAG,CAAC,eAAe,IAAI;AAEvD,MAAMC,oBAAoB;IACtB,MAAMC,WAAWF,QAAQ,GAAG,CAAC,mBAAmB;IAChD,MAAMG,WAAWH,QAAQ,GAAG,CAAC,mBAAmB;IAChD,MAAMI,WAAWJ,QAAQ,GAAG,CAAC,mBAAmB;IAEhD,MAAMK,UAAkC;QACpC,MAAM,CAAC,iBAAiB,EAAEN,iBAAiB;QAC3C,YAAY;QACZ,aAAa;IACjB;IAEA,IAAII,YAAYC,UACZC,QAAQ,IAAI,GAAG;QAAEF;QAAUC;IAAS;IAGxC,IAAIF,UACAG,QAAQ,IAAI,GAAGH,AAA4B,SAA5BA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AI,GAAG,GACtB,MAAMV,WAAW1B,MAAM,IAAI,CAACoC;QAEhC,OAAOE;IACX;IAEA,OAAOP;AACX;AAEO,MAAMQ,6BAA6B,CACtC5C,UAAkC,CAAC,CAAC;IAEpC,MAAMa,SAAS,IAAIgC,OAAO;QACtB,GAAGjD,mBAAmB;QACtB,GAAGI,OAAO;IACd;IACA,OAAOmB,mBAAmBN;AAC9B;AAEA,IAAIiC,kBAA+C;AAE5C,MAAMC,0BAA0B;IACnC,IAAI,CAACD,iBACDA,kBAAkBF;IAEtB,OAAOE;AACX"}
@@ -0,0 +1,4 @@
1
+ export { createTestOpenSearchClient, getTestOpenSearchClient, type TestOpenSearchClient } from "./createTestOpenSearchClient.js";
2
+ export { registerOpenSearchCoreForTests } from "./registerOpenSearchCoreForTests.js";
3
+ export { setupTestIndexManager } from "./setupTestIndexManager.js";
4
+ export { createBlankQuery } from "./createBlankQuery.js";
@@ -0,0 +1,4 @@
1
+ export { createTestOpenSearchClient, getTestOpenSearchClient } from "./createTestOpenSearchClient.js";
2
+ export { registerOpenSearchCoreForTests } from "./registerOpenSearchCoreForTests.js";
3
+ export { setupTestIndexManager } from "./setupTestIndexManager.js";
4
+ export { createBlankQuery } from "./createBlankQuery.js";
@@ -0,0 +1 @@
1
+ export declare const registerOpenSearchCoreForTests: () => import("@webiny/handler/index.js").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
@@ -0,0 +1,9 @@
1
+ import { registerOpenSearchCore } from "../registerOpenSearchCore.js";
2
+ import { getTestOpenSearchClient } from "./createTestOpenSearchClient.js";
3
+ const registerOpenSearchCoreForTests = ()=>{
4
+ const client = getTestOpenSearchClient();
5
+ return registerOpenSearchCore(client);
6
+ };
7
+ export { registerOpenSearchCoreForTests };
8
+
9
+ //# sourceMappingURL=registerOpenSearchCoreForTests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/registerOpenSearchCoreForTests.js","sources":["../../src/testing/registerOpenSearchCoreForTests.ts"],"sourcesContent":["import { registerOpenSearchCore } from \"~/registerOpenSearchCore.js\";\nimport { getTestOpenSearchClient } from \"./createTestOpenSearchClient.js\";\n\nexport const registerOpenSearchCoreForTests = () => {\n const client = getTestOpenSearchClient();\n return registerOpenSearchCore(client);\n};\n"],"names":["registerOpenSearchCoreForTests","client","getTestOpenSearchClient","registerOpenSearchCore"],"mappings":";;AAGO,MAAMA,iCAAiC;IAC1C,MAAMC,SAASC;IACf,OAAOC,uBAAuBF;AAClC"}
@@ -0,0 +1,13 @@
1
+ type LifecycleHook = () => Promise<void>;
2
+ interface TestGlobal {
3
+ __beforeEach: LifecycleHook;
4
+ __afterEach: LifecycleHook;
5
+ __beforeAll: LifecycleHook;
6
+ __afterAll: LifecycleHook;
7
+ }
8
+ interface SetupTestIndexManagerParams {
9
+ global: typeof globalThis & Partial<TestGlobal>;
10
+ onBeforeEach?: () => Promise<void> | void;
11
+ }
12
+ export declare const setupTestIndexManager: (params: SetupTestIndexManagerParams) => void;
13
+ export {};
@@ -0,0 +1,26 @@
1
+ import { getTestOpenSearchClient } from "./createTestOpenSearchClient.js";
2
+ const setupTestIndexManager = (params)=>{
3
+ const { global, onBeforeEach } = params;
4
+ const client = getTestOpenSearchClient();
5
+ const clearIndices = async ()=>{
6
+ try {
7
+ await client.indices.deleteAll();
8
+ } catch {}
9
+ };
10
+ global.__beforeEach = async ()=>{
11
+ await clearIndices();
12
+ if (onBeforeEach) await onBeforeEach();
13
+ };
14
+ global.__afterEach = async ()=>{
15
+ await clearIndices();
16
+ };
17
+ global.__beforeAll = async ()=>{
18
+ await clearIndices();
19
+ };
20
+ global.__afterAll = async ()=>{
21
+ await clearIndices();
22
+ };
23
+ };
24
+ export { setupTestIndexManager };
25
+
26
+ //# sourceMappingURL=setupTestIndexManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/setupTestIndexManager.js","sources":["../../src/testing/setupTestIndexManager.ts"],"sourcesContent":["import { getTestOpenSearchClient } from \"./createTestOpenSearchClient.js\";\n\ntype LifecycleHook = () => Promise<void>;\n\ninterface TestGlobal {\n __beforeEach: LifecycleHook;\n __afterEach: LifecycleHook;\n __beforeAll: LifecycleHook;\n __afterAll: LifecycleHook;\n}\n\ninterface SetupTestIndexManagerParams {\n global: typeof globalThis & Partial<TestGlobal>;\n onBeforeEach?: () => Promise<void> | void;\n}\n\nexport const setupTestIndexManager = (params: SetupTestIndexManagerParams) => {\n const { global, onBeforeEach } = params;\n const client = getTestOpenSearchClient();\n\n const clearIndices = async () => {\n try {\n await client.indices.deleteAll();\n } catch {\n /* Intentionally swallowed. */\n }\n };\n\n global.__beforeEach = async () => {\n await clearIndices();\n if (onBeforeEach) {\n await onBeforeEach();\n }\n };\n\n global.__afterEach = async () => {\n await clearIndices();\n };\n\n global.__beforeAll = async () => {\n await clearIndices();\n };\n\n global.__afterAll = async () => {\n await clearIndices();\n };\n};\n"],"names":["setupTestIndexManager","params","global","onBeforeEach","client","getTestOpenSearchClient","clearIndices"],"mappings":";AAgBO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAE,GAAGF;IACjC,MAAMG,SAASC;IAEf,MAAMC,eAAe;QACjB,IAAI;YACA,MAAMF,OAAO,OAAO,CAAC,SAAS;QAClC,EAAE,OAAM,CAER;IACJ;IAEAF,OAAO,YAAY,GAAG;QAClB,MAAMI;QACN,IAAIH,cACA,MAAMA;IAEd;IAEAD,OAAO,WAAW,GAAG;QACjB,MAAMI;IACV;IAEAJ,OAAO,WAAW,GAAG;QACjB,MAAMI;IACV;IAEAJ,OAAO,UAAU,GAAG;QAChB,MAAMI;IACV;AACJ"}