@webiny/api-opensearch 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.eb81deee7e

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 (282) hide show
  1. package/client.js +30 -63
  2. package/client.js.map +1 -1
  3. package/cursors.js +20 -32
  4. package/cursors.js.map +1 -1
  5. package/exports/api/opensearch.d.ts +6 -1
  6. package/exports/api/opensearch.js +6 -3
  7. package/features/OpenSearchClient/abstraction.d.ts +3 -3
  8. package/features/OpenSearchClient/abstraction.js +2 -1
  9. package/features/OpenSearchClient/abstraction.js.map +1 -1
  10. package/features/OpenSearchClient/feature.d.ts +2 -1
  11. package/features/OpenSearchClient/feature.js +9 -6
  12. package/features/OpenSearchClient/feature.js.map +1 -1
  13. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js +8 -9
  14. package/features/OpenSearchClientFactory/OpenSearchClientFactory.js.map +1 -1
  15. package/features/OpenSearchClientFactory/abstraction.js +2 -1
  16. package/features/OpenSearchClientFactory/abstraction.js.map +1 -1
  17. package/features/OpenSearchClientFactory/feature.js +6 -5
  18. package/features/OpenSearchClientFactory/feature.js.map +1 -1
  19. package/features/OpenSearchField/OpenSearchField.d.ts +18 -0
  20. package/features/OpenSearchField/OpenSearchField.js +49 -0
  21. package/features/OpenSearchField/OpenSearchField.js.map +1 -0
  22. package/features/OpenSearchField/OpenSearchFieldFactory.d.ts +9 -0
  23. package/features/OpenSearchField/OpenSearchFieldFactory.js +14 -0
  24. package/features/OpenSearchField/OpenSearchFieldFactory.js.map +1 -0
  25. package/features/OpenSearchField/abstractions/OpenSearchField.d.ts +35 -0
  26. package/features/OpenSearchField/abstractions/OpenSearchField.js +6 -0
  27. package/features/OpenSearchField/abstractions/OpenSearchField.js.map +1 -0
  28. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.d.ts +8 -0
  29. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js +5 -0
  30. package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js.map +1 -0
  31. package/features/OpenSearchField/feature.d.ts +4 -0
  32. package/features/OpenSearchField/feature.js +11 -0
  33. package/features/OpenSearchField/feature.js.map +1 -0
  34. package/features/OpenSearchIndex/OpenSearchIndexRegistry.d.ts +12 -0
  35. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js +30 -0
  36. package/features/OpenSearchIndex/OpenSearchIndexRegistry.js.map +1 -0
  37. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.d.ts +9 -0
  38. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js +5 -0
  39. package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js.map +1 -0
  40. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.d.ts +9 -0
  41. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js +5 -0
  42. package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js.map +1 -0
  43. package/features/OpenSearchIndex/feature.d.ts +4 -0
  44. package/features/OpenSearchIndex/feature.js +11 -0
  45. package/features/OpenSearchIndex/feature.js.map +1 -0
  46. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.d.ts +12 -0
  47. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js +28 -0
  48. package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  49. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.d.ts +11 -0
  50. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js +5 -0
  51. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js.map +1 -0
  52. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.d.ts +10 -0
  53. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js +5 -0
  54. package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
  55. package/features/OpenSearchQueryBuilderOperator/feature.d.ts +4 -0
  56. package/features/OpenSearchQueryBuilderOperator/feature.js +41 -0
  57. package/features/OpenSearchQueryBuilderOperator/feature.js.map +1 -0
  58. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.d.ts +9 -0
  59. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js +28 -0
  60. package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js.map +1 -0
  61. package/features/OpenSearchQueryBuilderOperator/operators/Between.d.ts +9 -0
  62. package/features/OpenSearchQueryBuilderOperator/operators/Between.js +27 -0
  63. package/features/OpenSearchQueryBuilderOperator/operators/Between.js.map +1 -0
  64. package/features/OpenSearchQueryBuilderOperator/operators/Contains.d.ts +9 -0
  65. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js +27 -0
  66. package/features/OpenSearchQueryBuilderOperator/operators/Contains.js.map +1 -0
  67. package/features/OpenSearchQueryBuilderOperator/operators/Equal.d.ts +9 -0
  68. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js +34 -0
  69. package/features/OpenSearchQueryBuilderOperator/operators/Equal.js.map +1 -0
  70. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.d.ts +9 -0
  71. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js +23 -0
  72. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js.map +1 -0
  73. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.d.ts +9 -0
  74. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js +23 -0
  75. package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js.map +1 -0
  76. package/features/OpenSearchQueryBuilderOperator/operators/In.d.ts +9 -0
  77. package/features/OpenSearchQueryBuilderOperator/operators/In.js +24 -0
  78. package/features/OpenSearchQueryBuilderOperator/operators/In.js.map +1 -0
  79. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.d.ts +9 -0
  80. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js +23 -0
  81. package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js.map +1 -0
  82. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.d.ts +9 -0
  83. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js +23 -0
  84. package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js.map +1 -0
  85. package/features/OpenSearchQueryBuilderOperator/operators/Not.d.ts +9 -0
  86. package/features/OpenSearchQueryBuilderOperator/operators/Not.js +38 -0
  87. package/features/OpenSearchQueryBuilderOperator/operators/Not.js.map +1 -0
  88. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.d.ts +9 -0
  89. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js +27 -0
  90. package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js.map +1 -0
  91. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.d.ts +9 -0
  92. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js +27 -0
  93. package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js.map +1 -0
  94. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.d.ts +9 -0
  95. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js +24 -0
  96. package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js.map +1 -0
  97. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.d.ts +9 -0
  98. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js +22 -0
  99. package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js.map +1 -0
  100. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.d.ts +9 -0
  101. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js +22 -0
  102. package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js.map +1 -0
  103. package/index.d.ts +2 -10
  104. package/index.js +3 -30
  105. package/indexConfiguration/base.js +25 -26
  106. package/indexConfiguration/base.js.map +1 -1
  107. package/indexConfiguration/common.js +39 -41
  108. package/indexConfiguration/common.js.map +1 -1
  109. package/indexConfiguration/index.js +0 -2
  110. package/indexPrefix.js +2 -3
  111. package/indexPrefix.js.map +1 -1
  112. package/indices.d.ts +2 -8
  113. package/indices.js +1 -20
  114. package/limit.js +5 -27
  115. package/limit.js.map +1 -1
  116. package/normalize.js +50 -49
  117. package/normalize.js.map +1 -1
  118. package/operations/OpenSearchCatHealth.js +24 -25
  119. package/operations/OpenSearchCatHealth.js.map +1 -1
  120. package/operations/OpenSearchCatNodes.js +22 -23
  121. package/operations/OpenSearchCatNodes.js.map +1 -1
  122. package/operations/index.js +0 -2
  123. package/operations/stripConnectionFromException.js +11 -14
  124. package/operations/stripConnectionFromException.js.map +1 -1
  125. package/operations/types.js +6 -5
  126. package/operations/types.js.map +1 -1
  127. package/package.json +12 -14
  128. package/registerOpenSearchCore.d.ts +3 -0
  129. package/registerOpenSearchCore.js +20 -0
  130. package/registerOpenSearchCore.js.map +1 -0
  131. package/sharedIndex.js +2 -3
  132. package/sharedIndex.js.map +1 -1
  133. package/sort.d.ts +2 -2
  134. package/sort.js +30 -59
  135. package/sort.js.map +1 -1
  136. package/testing/createBlankQuery.d.ts +2 -0
  137. package/testing/createBlankQuery.js +9 -0
  138. package/testing/createBlankQuery.js.map +1 -0
  139. package/testing/createTestOpenSearchClient.d.ts +11 -0
  140. package/testing/createTestOpenSearchClient.js +162 -0
  141. package/testing/createTestOpenSearchClient.js.map +1 -0
  142. package/testing/index.d.ts +4 -0
  143. package/testing/index.js +4 -0
  144. package/testing/registerOpenSearchCoreForTests.d.ts +1 -0
  145. package/testing/registerOpenSearchCoreForTests.js +9 -0
  146. package/testing/registerOpenSearchCoreForTests.js.map +1 -0
  147. package/testing/setupTestIndexManager.d.ts +13 -0
  148. package/testing/setupTestIndexManager.js +26 -0
  149. package/testing/setupTestIndexManager.js.map +1 -0
  150. package/types.d.ts +0 -8
  151. package/types.js +5 -65
  152. package/types.js.map +1 -1
  153. package/utils/createIndex.d.ts +2 -2
  154. package/utils/createIndex.js +52 -80
  155. package/utils/createIndex.js.map +1 -1
  156. package/utils/index.js +0 -2
  157. package/utils/waitUntilHealthy/UnhealthyClusterError.js +8 -7
  158. package/utils/waitUntilHealthy/UnhealthyClusterError.js.map +1 -1
  159. package/utils/waitUntilHealthy/WaitUntilHealthy.js +111 -141
  160. package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -1
  161. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js +8 -7
  162. package/utils/waitUntilHealthy/WaitingHealthyClusterAbortedError.js.map +1 -1
  163. package/utils/waitUntilHealthy/index.js +0 -2
  164. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js +9 -10
  165. package/utils/waitUntilHealthy/reason/ClusterHealthReason.js.map +1 -1
  166. package/utils/waitUntilHealthy/reason/IReason.js +0 -3
  167. package/utils/waitUntilHealthy/reason/MemoryReason.js +9 -10
  168. package/utils/waitUntilHealthy/reason/MemoryReason.js.map +1 -1
  169. package/utils/waitUntilHealthy/reason/ProcessorReason.js +9 -10
  170. package/utils/waitUntilHealthy/reason/ProcessorReason.js.map +1 -1
  171. package/utils/waitUntilHealthy/reason/index.js +0 -2
  172. package/where.d.ts +4 -4
  173. package/where.js +43 -76
  174. package/where.js.map +1 -1
  175. package/db/entity.d.ts +0 -7
  176. package/db/entity.js +0 -20
  177. package/db/entity.js.map +0 -1
  178. package/db/index.d.ts +0 -3
  179. package/db/index.js +0 -5
  180. package/db/index.js.map +0 -1
  181. package/db/table.d.ts +0 -7
  182. package/db/table.js +0 -17
  183. package/db/table.js.map +0 -1
  184. package/db/types.d.ts +0 -6
  185. package/db/types.js +0 -3
  186. package/db/types.js.map +0 -1
  187. package/exports/api/opensearch.js.map +0 -1
  188. package/features/OpenSearchClient/OpenSearchClient.d.ts +0 -12
  189. package/features/OpenSearchClient/OpenSearchClient.js +0 -16
  190. package/features/OpenSearchClient/OpenSearchClient.js.map +0 -1
  191. package/features/OpenSearchContext/OpenSearchContext.d.ts +0 -8
  192. package/features/OpenSearchContext/OpenSearchContext.js +0 -13
  193. package/features/OpenSearchContext/OpenSearchContext.js.map +0 -1
  194. package/features/OpenSearchContext/abstraction.d.ts +0 -14
  195. package/features/OpenSearchContext/abstraction.js +0 -4
  196. package/features/OpenSearchContext/abstraction.js.map +0 -1
  197. package/features/OpenSearchContext/feature.d.ts +0 -5
  198. package/features/OpenSearchContext/feature.js +0 -13
  199. package/features/OpenSearchContext/feature.js.map +0 -1
  200. package/index.js.map +0 -1
  201. package/indexConfiguration/index.js.map +0 -1
  202. package/indices.js.map +0 -1
  203. package/operations/index.js.map +0 -1
  204. package/operators.d.ts +0 -6
  205. package/operators.js +0 -9
  206. package/operators.js.map +0 -1
  207. package/plugins/definition/OpenSearchBodyModifierPlugin.d.ts +0 -13
  208. package/plugins/definition/OpenSearchBodyModifierPlugin.js +0 -18
  209. package/plugins/definition/OpenSearchBodyModifierPlugin.js.map +0 -1
  210. package/plugins/definition/OpenSearchFieldPlugin.d.ts +0 -81
  211. package/plugins/definition/OpenSearchFieldPlugin.js +0 -69
  212. package/plugins/definition/OpenSearchFieldPlugin.js.map +0 -1
  213. package/plugins/definition/OpenSearchIndexPlugin.d.ts +0 -10
  214. package/plugins/definition/OpenSearchIndexPlugin.js +0 -17
  215. package/plugins/definition/OpenSearchIndexPlugin.js.map +0 -1
  216. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.d.ts +0 -10
  217. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js +0 -9
  218. package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js.map +0 -1
  219. package/plugins/definition/OpenSearchQueryModifierPlugin.d.ts +0 -14
  220. package/plugins/definition/OpenSearchQueryModifierPlugin.js +0 -18
  221. package/plugins/definition/OpenSearchQueryModifierPlugin.js.map +0 -1
  222. package/plugins/definition/OpenSearchSortModifierPlugin.d.ts +0 -13
  223. package/plugins/definition/OpenSearchSortModifierPlugin.js +0 -18
  224. package/plugins/definition/OpenSearchSortModifierPlugin.js.map +0 -1
  225. package/plugins/definition/index.d.ts +0 -6
  226. package/plugins/definition/index.js +0 -8
  227. package/plugins/definition/index.js.map +0 -1
  228. package/plugins/index.d.ts +0 -2
  229. package/plugins/index.js +0 -4
  230. package/plugins/index.js.map +0 -1
  231. package/plugins/operator/andIn.d.ts +0 -7
  232. package/plugins/operator/andIn.js +0 -35
  233. package/plugins/operator/andIn.js.map +0 -1
  234. package/plugins/operator/between.d.ts +0 -7
  235. package/plugins/operator/between.js +0 -32
  236. package/plugins/operator/between.js.map +0 -1
  237. package/plugins/operator/contains.d.ts +0 -7
  238. package/plugins/operator/contains.js +0 -24
  239. package/plugins/operator/contains.js.map +0 -1
  240. package/plugins/operator/equal.d.ts +0 -7
  241. package/plugins/operator/equal.js +0 -50
  242. package/plugins/operator/equal.js.map +0 -1
  243. package/plugins/operator/gt.d.ts +0 -7
  244. package/plugins/operator/gt.js +0 -22
  245. package/plugins/operator/gt.js.map +0 -1
  246. package/plugins/operator/gte.d.ts +0 -7
  247. package/plugins/operator/gte.js +0 -22
  248. package/plugins/operator/gte.js.map +0 -1
  249. package/plugins/operator/in.d.ts +0 -7
  250. package/plugins/operator/in.js +0 -29
  251. package/plugins/operator/in.js.map +0 -1
  252. package/plugins/operator/index.d.ts +0 -15
  253. package/plugins/operator/index.js +0 -17
  254. package/plugins/operator/index.js.map +0 -1
  255. package/plugins/operator/lt.d.ts +0 -7
  256. package/plugins/operator/lt.js +0 -22
  257. package/plugins/operator/lt.js.map +0 -1
  258. package/plugins/operator/lte.d.ts +0 -7
  259. package/plugins/operator/lte.js +0 -22
  260. package/plugins/operator/lte.js.map +0 -1
  261. package/plugins/operator/not.d.ts +0 -7
  262. package/plugins/operator/not.js +0 -44
  263. package/plugins/operator/not.js.map +0 -1
  264. package/plugins/operator/notBetween.d.ts +0 -7
  265. package/plugins/operator/notBetween.js +0 -32
  266. package/plugins/operator/notBetween.js.map +0 -1
  267. package/plugins/operator/notContains.d.ts +0 -7
  268. package/plugins/operator/notContains.js +0 -24
  269. package/plugins/operator/notContains.js.map +0 -1
  270. package/plugins/operator/notIn.d.ts +0 -7
  271. package/plugins/operator/notIn.js +0 -27
  272. package/plugins/operator/notIn.js.map +0 -1
  273. package/plugins/operator/notStartsWith.d.ts +0 -7
  274. package/plugins/operator/notStartsWith.js +0 -23
  275. package/plugins/operator/notStartsWith.js.map +0 -1
  276. package/plugins/operator/startsWith.d.ts +0 -7
  277. package/plugins/operator/startsWith.js +0 -23
  278. package/plugins/operator/startsWith.js.map +0 -1
  279. package/utils/index.js.map +0 -1
  280. package/utils/waitUntilHealthy/index.js.map +0 -1
  281. package/utils/waitUntilHealthy/reason/IReason.js.map +0 -1
  282. package/utils/waitUntilHealthy/reason/index.js.map +0 -1
package/sort.js CHANGED
@@ -1,65 +1,36 @@
1
- import WebinyError from "@webiny/error";
2
- import { OpenSearchFieldPlugin } from "./plugins/index.js";
1
+ import error from "@webiny/error";
2
+ import { OpenSearchFieldAll } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
3
3
  const sortRegExp = /^((?:values\.)?[a-zA-Z0-9_@-]+)_(ASC|DESC)$/;
4
- export const createSort = params => {
5
- const {
6
- sort,
7
- defaults,
8
- fieldPlugins
9
- } = params;
10
- if (!sort || sort.length === 0) {
11
- const {
12
- field,
13
- order,
14
- unmappedType
15
- } = defaults || {};
16
- /**
17
- * We say that our system defaults is always id since all records we create have some kind of primary ID.
18
- */
19
- return {
20
- [field || "id.keyword"]: {
21
- order: order || "desc",
22
- // TODO: Cast to the proper MappingFieldType once deep opensearch _types/ imports are resolvable under bundler resolution.
23
- unmapped_type: unmappedType || undefined
24
- }
25
- };
26
- }
27
- /**
28
- * Cast as string because nothing else should be allowed yet.
29
- */
30
- const result = sort.reduce((acc, value) => {
31
- if (typeof value !== "string") {
32
- throw new WebinyError(`Sort as object is not supported..`);
33
- }
34
- const match = value.match(sortRegExp);
35
- if (!match) {
36
- throw new WebinyError(`Cannot sort by "${value}".`);
37
- }
38
- const [, field, initialOrder] = match;
39
- const order = initialOrder.toLowerCase() === "asc" ? "asc" : "desc";
40
- const plugin = fieldPlugins[field] || fieldPlugins[OpenSearchFieldPlugin.ALL];
41
- if (!plugin) {
42
- throw new WebinyError(`Missing plugin for the field "${field}"`, "PLUGIN_SORT_ERROR", {
43
- field
44
- });
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
+ };
45
14
  }
46
- /**
47
- * In case field plugin is the global one, change the * with actual field name.
48
- * Custom path methods will return their own values anyway so replacing * will not matter.
49
- */
50
- const path = plugin.getPath(field);
51
- acc[path] = plugin.getSortOptions(order);
52
- return acc;
53
- }, {});
54
- /**
55
- * If we do not have id in the sort, we add it as we need a tie_breaker for the OpenSearch to be able to sort consistently.
56
- */
57
- if (!result["id.keyword"] && !result["id"]) {
58
- result["id.keyword"] = {
59
- order: "asc"
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"
60
31
  };
61
- }
62
- return result;
32
+ return result;
63
33
  };
34
+ export { createSort };
64
35
 
65
36
  //# sourceMappingURL=sort.js.map
package/sort.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","OpenSearchFieldPlugin","sortRegExp","createSort","params","sort","defaults","fieldPlugins","length","field","order","unmappedType","unmapped_type","undefined","result","reduce","acc","value","match","initialOrder","toLowerCase","plugin","ALL","path","getPath","getSortOptions"],"sources":["sort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldSortOptions, SortOrder, SortType } from \"~/types.js\";\nimport { OpenSearchFieldPlugin } from \"~/plugins/index.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, OpenSearchFieldPlugin>;\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 /**\n * We say that our system defaults is always id since all records we create have some kind of primary ID.\n */\n return {\n [field || \"id.keyword\"]: {\n order: order || \"desc\",\n // TODO: Cast to the proper MappingFieldType once deep opensearch _types/ imports are resolvable under bundler resolution.\n unmapped_type: (unmappedType || undefined) as any\n }\n };\n }\n /**\n * Cast as string because nothing else should be allowed yet.\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: OpenSearchFieldPlugin =\n fieldPlugins[field] || fieldPlugins[OpenSearchFieldPlugin.ALL];\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 /**\n * In case field plugin is the global one, change the * with actual field name.\n * Custom path methods will return their own values anyway so replacing * will not matter.\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 /**\n * If we do not have id in the sort, we add it as we need a tie_breaker for the OpenSearch to be able to sort consistently.\n */\n if (!result[\"id.keyword\"] && !result[\"id\"]) {\n result[\"id.keyword\"] = {\n order: \"asc\"\n };\n }\n return result;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,qBAAqB;AAE9B,MAAMC,UAAU,GAAG,6CAA6C;AAYhE,OAAO,MAAMC,UAAU,GAAIC,MAAwB,IAAe;EAC9D,MAAM;IAAEC,IAAI;IAAEC,QAAQ;IAAEC;EAAa,CAAC,GAAGH,MAAM;EAC/C,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM;MAAEC,KAAK;MAAEC,KAAK;MAAEC;IAAa,CAAC,GAAGL,QAAQ,IAAI,CAAC,CAAC;IACrD;AACR;AACA;IACQ,OAAO;MACH,CAACG,KAAK,IAAI,YAAY,GAAG;QACrBC,KAAK,EAAEA,KAAK,IAAI,MAAM;QACtB;QACAE,aAAa,EAAGD,YAAY,IAAIE;MACpC;IACJ,CAAC;EACL;EACA;AACJ;AACA;EACI,MAAMC,MAAM,GAAGT,IAAI,CAACU,MAAM,CACtB,CAACC,GAAG,EAAEC,KAAK,KAAK;IACZ,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC3B,MAAM,IAAIjB,WAAW,CAAC,mCAAmC,CAAC;IAC9D;IACA,MAAMkB,KAAK,GAAGD,KAAK,CAACC,KAAK,CAAChB,UAAU,CAAC;IAErC,IAAI,CAACgB,KAAK,EAAE;MACR,MAAM,IAAIlB,WAAW,CAAC,mBAAmBiB,KAAK,IAAI,CAAC;IACvD;IAEA,MAAM,GAAGR,KAAK,EAAEU,YAAY,CAAC,GAAGD,KAAK;IACrC,MAAMR,KAAgB,GAAGS,YAAY,CAACC,WAAW,CAAC,CAAC,KAAK,KAAK,GAAG,KAAK,GAAG,MAAM;IAE9E,MAAMC,MAA6B,GAC/Bd,YAAY,CAACE,KAAK,CAAC,IAAIF,YAAY,CAACN,qBAAqB,CAACqB,GAAG,CAAC;IAClE,IAAI,CAACD,MAAM,EAAE;MACT,MAAM,IAAIrB,WAAW,CACjB,iCAAiCS,KAAK,GAAG,EACzC,mBAAmB,EACnB;QACIA;MACJ,CACJ,CAAC;IACL;IACA;AACZ;AACA;AACA;IACY,MAAMc,IAAI,GAAGF,MAAM,CAACG,OAAO,CAACf,KAAK,CAAC;IAElCO,GAAG,CAACO,IAAI,CAAC,GAAGF,MAAM,CAACI,cAAc,CAACf,KAAK,CAAC;IAExC,OAAOM,GAAG;EACd,CAAC,EACD,CAAC,CACL,CAAC;EACD;AACJ;AACA;EACI,IAAI,CAACF,MAAM,CAAC,YAAY,CAAC,IAAI,CAACA,MAAM,CAAC,IAAI,CAAC,EAAE;IACxCA,MAAM,CAAC,YAAY,CAAC,GAAG;MACnBJ,KAAK,EAAE;IACX,CAAC;EACL;EACA,OAAOI,MAAM;AACjB,CAAC","ignoreList":[]}
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":"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"}
@@ -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"}
package/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { Client } from "@opensearch-project/opensearch";
2
2
  import type { Search_RequestBody as SearchRequestBody, Search_Response, Indices_Create_RequestBody } from "@opensearch-project/opensearch/api/index.js";
3
- import type { Context } from "@webiny/api/types.js";
4
3
  type QueryDslQueryContainer = NonNullable<SearchRequestBody["query"]>;
5
4
  type QueryDslBoolQuery = NonNullable<QueryDslQueryContainer["bool"]>;
6
5
  type SearchSort = NonNullable<SearchRequestBody["sort"]>;
@@ -29,13 +28,6 @@ export type SortType = Record<string, FieldSortOptions>;
29
28
  export type SearchBody = Omit<SearchRequestBody, "search_after"> & {
30
29
  search_after?: PrimitiveValue[];
31
30
  };
32
- export interface OpenSearchContext extends Context {
33
- /**
34
- * @deprecated Use `context.opensearch` instead.
35
- */
36
- elasticsearch: Client;
37
- opensearch: Client;
38
- }
39
31
  export interface OpenSearchBoolQueryConfig extends QueryDslBoolQuery {
40
32
  must: QueryDslQueryContainer[];
41
33
  filter: QueryDslQueryContainer[];
package/types.js CHANGED
@@ -1,68 +1,8 @@
1
- // ---------------------------------------------------------------------------
2
- // Types inferred from the accessible API surface.
3
- // The `_types/` directory in the opensearch package only ships `.d.ts` files
4
- // (no `.js` runtime modules), so deep imports are unresolvable under
5
- // `moduleResolution: "bundler"`. We infer what we can from the public
6
- // barrel (`api/index.js`) and use `string` where structural extraction
7
- // is not possible.
8
- // ---------------------------------------------------------------------------
9
-
10
- // Distribute over the SortOptions union and extract only the Record<string, FieldSort> variant.
11
-
12
- // ---------------------------------------------------------------------------
13
- // Local type aliases replacing elastic-ts
14
- // ---------------------------------------------------------------------------
15
-
16
- /** Replaces elastic-ts PrimitiveValue. Aligns with opensearch FieldValue. */
17
-
18
- /** Replaces elastic-ts Query */
19
-
20
- /** Replaces elastic-ts BoolQueryConfig */
21
-
22
- /** Replaces elastic-ts FieldSortOptions */
23
-
24
- /** Replaces elastic-ts SortOrder. Narrowed to "asc" | "desc" (excludes "_doc"). */
25
-
26
- /** Replaces elastic-ts Sort */
27
-
28
- /** Single sort entry as an object map. Replaces elastic-ts SortType. */
29
-
30
- /** Replaces elastic-ts SearchBody. Overrides search_after to allow PrimitiveValue[] (null | boolean | string | number). */
31
-
32
- // ---------------------------------------------------------------------------
33
- // Context
34
- // ---------------------------------------------------------------------------
35
-
36
- // ---------------------------------------------------------------------------
37
- // Bool query with required arrays (our convention)
38
- // ---------------------------------------------------------------------------
39
-
40
- // ---------------------------------------------------------------------------
41
- // Operator plugin types
42
- // ---------------------------------------------------------------------------
43
-
44
- // ---------------------------------------------------------------------------
45
- // Search response shapes (aligned with @opensearch-project/opensearch v3)
46
- // ---------------------------------------------------------------------------
47
-
48
- /**
49
- * Extract the total count from an opensearch hits response.
50
- * Handles both `TotalHits` (object with `value`) and plain `number` formats.
51
- */
52
- export const getTotalCount = total => {
53
- if (total === undefined || total === null) {
54
- return 0;
55
- }
56
- if (typeof total === "number") {
57
- return total;
58
- }
59
- return total.value;
1
+ const getTotalCount = (total)=>{
2
+ if (null == total) return 0;
3
+ if ("number" == typeof total) return total;
4
+ return total.value;
60
5
  };
61
-
62
- // ---------------------------------------------------------------------------
63
- // Index request body shapes (re-exported from opensearch package)
64
- // ---------------------------------------------------------------------------
65
-
66
- // Re-export SearchSortOrder for consumers that need it (including "_doc")
6
+ export { getTotalCount };
67
7
 
68
8
  //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["getTotalCount","total","undefined","value"],"sources":["types.ts"],"sourcesContent":["import type { Client } from \"@opensearch-project/opensearch\";\nimport type {\n Search_RequestBody as SearchRequestBody,\n Search_Response,\n Indices_Create_RequestBody\n} from \"@opensearch-project/opensearch/api/index.js\";\nimport type { Context } from \"@webiny/api/types.js\";\n\n// ---------------------------------------------------------------------------\n// Types inferred from the accessible API surface.\n// The `_types/` directory in the opensearch package only ships `.d.ts` files\n// (no `.js` runtime modules), so deep imports are unresolvable under\n// `moduleResolution: \"bundler\"`. We infer what we can from the public\n// barrel (`api/index.js`) and use `string` where structural extraction\n// is not possible.\n// ---------------------------------------------------------------------------\n\ntype QueryDslQueryContainer = NonNullable<SearchRequestBody[\"query\"]>;\ntype QueryDslBoolQuery = NonNullable<QueryDslQueryContainer[\"bool\"]>;\ntype SearchSort = NonNullable<SearchRequestBody[\"sort\"]>;\ntype SearchSortOrder = \"asc\" | \"desc\";\n\n// Distribute over the SortOptions union and extract only the Record<string, FieldSort> variant.\ntype _ExtractRecordValue<T> = T extends Record<string, infer V> ? V : never;\ntype _SortMember =\n NonNullable<SearchRequestBody[\"sort\"]> extends (infer U)[] | (infer U) ? U : never;\ntype SearchFieldSort = _ExtractRecordValue<Exclude<_SortMember, string>>;\n\ntype DynamicTemplate = NonNullable<\n NonNullable<Indices_Create_RequestBody[\"mappings\"]>[\"dynamic_templates\"]\n>[number][string];\n\nexport type { ApiResponse } from \"@opensearch-project/opensearch\";\n\nexport type { Client };\n\n// ---------------------------------------------------------------------------\n// Local type aliases replacing elastic-ts\n// ---------------------------------------------------------------------------\n\n/** Replaces elastic-ts PrimitiveValue. Aligns with opensearch FieldValue. */\nexport type PrimitiveValue = boolean | undefined | number | string;\n\n/** Replaces elastic-ts Query */\nexport type { QueryDslQueryContainer };\n\n/** Replaces elastic-ts BoolQueryConfig */\nexport type { QueryDslBoolQuery };\n\n/** Replaces elastic-ts FieldSortOptions */\nexport type FieldSortOptions = SearchFieldSort;\n\n/** Replaces elastic-ts SortOrder. Narrowed to \"asc\" | \"desc\" (excludes \"_doc\"). */\nexport type SortOrder = \"asc\" | \"desc\";\n\n/** Replaces elastic-ts Sort */\nexport type { SearchSort as Sort };\n\n/** Single sort entry as an object map. Replaces elastic-ts SortType. */\nexport type SortType = Record<string, FieldSortOptions>;\n\n/** Replaces elastic-ts SearchBody. Overrides search_after to allow PrimitiveValue[] (null | boolean | string | number). */\nexport type SearchBody = Omit<SearchRequestBody, \"search_after\"> & {\n search_after?: PrimitiveValue[];\n};\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nexport interface OpenSearchContext extends Context {\n /**\n * @deprecated Use `context.opensearch` instead.\n */\n elasticsearch: Client;\n opensearch: Client;\n}\n\n// ---------------------------------------------------------------------------\n// Bool query with required arrays (our convention)\n// ---------------------------------------------------------------------------\n\nexport interface OpenSearchBoolQueryConfig extends QueryDslBoolQuery {\n must: QueryDslQueryContainer[];\n filter: QueryDslQueryContainer[];\n should: QueryDslQueryContainer[];\n must_not: QueryDslQueryContainer[];\n}\n\n// ---------------------------------------------------------------------------\n// Operator plugin types\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchQueryOperator =\n | \"eq\"\n | \"not\"\n | \"in\"\n | \"not_in\"\n | \"contains\"\n | \"not_contains\"\n | \"between\"\n | \"not_between\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | string;\n\nexport interface OpenSearchQueryBuilderArgsPlugin {\n name: string;\n path: string;\n basePath: string;\n value: any;\n keyword: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Search response shapes (aligned with @opensearch-project/opensearch v3)\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchSearchResponseHit = Search_Response[\"body\"][\"hits\"][\"hits\"][number];\n\nexport interface OpenSearchSearchResponseAggregationBucket {\n key: PrimitiveValue;\n doc_count: number;\n}\n\nexport type OpenSearchSearchResponseBodyHits = Search_Response[\"body\"][\"hits\"];\n\nexport type OpenSearchSearchResponseBody = Search_Response[\"body\"];\n\nexport type OpenSearchSearchResponse = Search_Response;\n\n/**\n * Extract the total count from an opensearch hits response.\n * Handles both `TotalHits` (object with `value`) and plain `number` formats.\n */\nexport const getTotalCount = (total: OpenSearchSearchResponseBodyHits[\"total\"]): number => {\n if (total === undefined || total === null) {\n return 0;\n }\n if (typeof total === \"number\") {\n return total;\n }\n return total.value;\n};\n\n// ---------------------------------------------------------------------------\n// Index request body shapes (re-exported from opensearch package)\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchIndexRequestBodyMappingsDynamicTemplate = Record<string, DynamicTemplate>;\n\nexport type OpenSearchIndexRequestBody = Indices_Create_RequestBody;\n\n// Re-export SearchSortOrder for consumers that need it (including \"_doc\")\nexport type { SearchSortOrder };\n"],"mappings":"AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;;AAcA;AACA;AACA;;AAEA;;AAGA;;AAGA;;AAGA;;AAGA;;AAGA;;AAGA;;AAGA;;AAKA;AACA;AACA;;AAUA;AACA;AACA;;AASA;AACA;AACA;;AAyBA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA,OAAO,MAAMA,aAAa,GAAIC,KAAgD,IAAa;EACvF,IAAIA,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,EAAE;IACvC,OAAO,CAAC;EACZ;EACA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB;EACA,OAAOA,KAAK,CAACE,KAAK;AACtB,CAAC;;AAED;AACA;AACA;;AAMA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type { Client } from \"@opensearch-project/opensearch\";\nimport type {\n Search_RequestBody as SearchRequestBody,\n Search_Response,\n Indices_Create_RequestBody\n} from \"@opensearch-project/opensearch/api/index.js\";\n\n// ---------------------------------------------------------------------------\n// Types inferred from the accessible API surface.\n// The `_types/` directory in the opensearch package only ships `.d.ts` files\n// (no `.js` runtime modules), so deep imports are unresolvable under\n// `moduleResolution: \"bundler\"`. We infer what we can from the public\n// barrel (`api/index.js`) and use `string` where structural extraction\n// is not possible.\n// ---------------------------------------------------------------------------\n\ntype QueryDslQueryContainer = NonNullable<SearchRequestBody[\"query\"]>;\ntype QueryDslBoolQuery = NonNullable<QueryDslQueryContainer[\"bool\"]>;\ntype SearchSort = NonNullable<SearchRequestBody[\"sort\"]>;\ntype SearchSortOrder = \"asc\" | \"desc\";\n\n// Distribute over the SortOptions union and extract only the Record<string, FieldSort> variant.\ntype _ExtractRecordValue<T> = T extends Record<string, infer V> ? V : never;\ntype _SortMember =\n NonNullable<SearchRequestBody[\"sort\"]> extends (infer U)[] | (infer U) ? U : never;\ntype SearchFieldSort = _ExtractRecordValue<Exclude<_SortMember, string>>;\n\ntype DynamicTemplate = NonNullable<\n NonNullable<Indices_Create_RequestBody[\"mappings\"]>[\"dynamic_templates\"]\n>[number][string];\n\nexport type { ApiResponse } from \"@opensearch-project/opensearch\";\n\nexport type { Client };\n\n// ---------------------------------------------------------------------------\n// Local type aliases replacing elastic-ts\n// ---------------------------------------------------------------------------\n\n/** Replaces elastic-ts PrimitiveValue. Aligns with opensearch FieldValue. */\nexport type PrimitiveValue = boolean | undefined | number | string;\n\n/** Replaces elastic-ts Query */\nexport type { QueryDslQueryContainer };\n\n/** Replaces elastic-ts BoolQueryConfig */\nexport type { QueryDslBoolQuery };\n\n/** Replaces elastic-ts FieldSortOptions */\nexport type FieldSortOptions = SearchFieldSort;\n\n/** Replaces elastic-ts SortOrder. Narrowed to \"asc\" | \"desc\" (excludes \"_doc\"). */\nexport type SortOrder = \"asc\" | \"desc\";\n\n/** Replaces elastic-ts Sort */\nexport type { SearchSort as Sort };\n\n/** Single sort entry as an object map. Replaces elastic-ts SortType. */\nexport type SortType = Record<string, FieldSortOptions>;\n\n/** Replaces elastic-ts SearchBody. Overrides search_after to allow PrimitiveValue[] (null | boolean | string | number). */\nexport type SearchBody = Omit<SearchRequestBody, \"search_after\"> & {\n search_after?: PrimitiveValue[];\n};\n\n// ---------------------------------------------------------------------------\n// Bool query with required arrays (our convention)\n// ---------------------------------------------------------------------------\n\nexport interface OpenSearchBoolQueryConfig extends QueryDslBoolQuery {\n must: QueryDslQueryContainer[];\n filter: QueryDslQueryContainer[];\n should: QueryDslQueryContainer[];\n must_not: QueryDslQueryContainer[];\n}\n\n// ---------------------------------------------------------------------------\n// Operator plugin types\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchQueryOperator =\n | \"eq\"\n | \"not\"\n | \"in\"\n | \"not_in\"\n | \"contains\"\n | \"not_contains\"\n | \"between\"\n | \"not_between\"\n | \"gt\"\n | \"gte\"\n | \"lt\"\n | \"lte\"\n | string;\n\nexport interface OpenSearchQueryBuilderArgsPlugin {\n name: string;\n path: string;\n basePath: string;\n value: any;\n keyword: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Search response shapes (aligned with @opensearch-project/opensearch v3)\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchSearchResponseHit = Search_Response[\"body\"][\"hits\"][\"hits\"][number];\n\nexport interface OpenSearchSearchResponseAggregationBucket {\n key: PrimitiveValue;\n doc_count: number;\n}\n\nexport type OpenSearchSearchResponseBodyHits = Search_Response[\"body\"][\"hits\"];\n\nexport type OpenSearchSearchResponseBody = Search_Response[\"body\"];\n\nexport type OpenSearchSearchResponse = Search_Response;\n\n/**\n * Extract the total count from an opensearch hits response.\n * Handles both `TotalHits` (object with `value`) and plain `number` formats.\n */\nexport const getTotalCount = (total: OpenSearchSearchResponseBodyHits[\"total\"]): number => {\n if (total === undefined || total === null) {\n return 0;\n }\n if (typeof total === \"number\") {\n return total;\n }\n return total.value;\n};\n\n// ---------------------------------------------------------------------------\n// Index request body shapes (re-exported from opensearch package)\n// ---------------------------------------------------------------------------\n\nexport type OpenSearchIndexRequestBodyMappingsDynamicTemplate = Record<string, DynamicTemplate>;\n\nexport type OpenSearchIndexRequestBody = Indices_Create_RequestBody;\n\n// Re-export SearchSortOrder for consumers that need it (including \"_doc\")\nexport type { SearchSortOrder };\n"],"names":["getTotalCount","total"],"mappings":"AA4HO,MAAMA,gBAAgB,CAACC;IAC1B,IAAIA,QAAAA,OACA,OAAO;IAEX,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAOA;IAEX,OAAOA,MAAM,KAAK;AACtB"}
@@ -1,5 +1,5 @@
1
1
  import type { Client } from "../client.js";
2
- import type { PluginsContainer } from "@webiny/plugins";
2
+ import type { OpenSearchIndex } from "../features/OpenSearchIndex/abstractions/OpenSearchIndex.js";
3
3
  interface OnExists {
4
4
  (): void;
5
5
  }
@@ -8,7 +8,7 @@ interface OnError {
8
8
  }
9
9
  interface CreateIndexParams {
10
10
  client: Client;
11
- plugins: PluginsContainer;
11
+ plugin: OpenSearchIndex.Interface;
12
12
  type: string;
13
13
  tenant: string;
14
14
  index: string;