@webiny/api-opensearch 6.4.12-beta.5 → 6.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/api/opensearch.d.ts +6 -1
- package/exports/api/opensearch.js +6 -1
- package/features/OpenSearchClient/abstraction.d.ts +3 -3
- package/features/OpenSearchClient/abstraction.js.map +1 -1
- package/features/OpenSearchClient/feature.d.ts +2 -1
- package/features/OpenSearchClient/feature.js +5 -3
- package/features/OpenSearchClient/feature.js.map +1 -1
- package/features/OpenSearchField/OpenSearchFieldFactory.d.ts +9 -0
- package/features/OpenSearchField/OpenSearchFieldFactory.js +14 -0
- package/features/OpenSearchField/OpenSearchFieldFactory.js.map +1 -0
- package/features/OpenSearchField/OpenSearchFieldImpl.d.ts +17 -0
- package/{plugins/definition/OpenSearchFieldPlugin.js → features/OpenSearchField/OpenSearchFieldImpl.js} +8 -14
- package/features/OpenSearchField/OpenSearchFieldImpl.js.map +1 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.d.ts +35 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.js +6 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.js.map +1 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.d.ts +8 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js +5 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js.map +1 -0
- package/features/OpenSearchField/feature.d.ts +4 -0
- package/features/OpenSearchField/feature.js +11 -0
- package/features/OpenSearchField/feature.js.map +1 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.d.ts +12 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.js +30 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.js.map +1 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.d.ts +9 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js +5 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js.map +1 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.d.ts +9 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js +5 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js.map +1 -0
- package/features/OpenSearchIndex/feature.d.ts +4 -0
- package/features/OpenSearchIndex/feature.js +11 -0
- package/features/OpenSearchIndex/feature.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.d.ts +12 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js +28 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.d.ts +11 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js +5 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.d.ts +10 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js +5 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/feature.d.ts +4 -0
- package/features/OpenSearchQueryBuilderOperator/feature.js +41 -0
- package/features/OpenSearchQueryBuilderOperator/feature.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/AndIn.d.ts +9 -0
- package/{plugins/operator/andIn.js → features/OpenSearchQueryBuilderOperator/operators/AndIn.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Equal.d.ts +9 -0
- package/{plugins/operator/equal.js → features/OpenSearchQueryBuilderOperator/operators/Equal.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/Equal.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/In.d.ts +9 -0
- package/{plugins/operator/in.js → features/OpenSearchQueryBuilderOperator/operators/In.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/In.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Not.d.ts +9 -0
- package/{plugins/operator/not.js → features/OpenSearchQueryBuilderOperator/operators/Not.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/Not.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotIn.d.ts +9 -0
- package/{plugins/operator/notIn.js → features/OpenSearchQueryBuilderOperator/operators/NotIn.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js +22 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js +22 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js.map +1 -0
- package/index.d.ts +2 -9
- package/index.js +3 -27
- package/indices.d.ts +2 -8
- package/indices.js +1 -12
- package/package.json +12 -11
- package/registerOpenSearchCore.d.ts +3 -0
- package/registerOpenSearchCore.js +20 -0
- package/registerOpenSearchCore.js.map +1 -0
- package/sort.d.ts +2 -2
- package/sort.js +2 -2
- package/sort.js.map +1 -1
- package/testing/createBlankQuery.d.ts +2 -0
- package/testing/createBlankQuery.js +9 -0
- package/testing/createBlankQuery.js.map +1 -0
- package/testing/createTestOpenSearchClient.d.ts +11 -0
- package/testing/createTestOpenSearchClient.js +162 -0
- package/testing/createTestOpenSearchClient.js.map +1 -0
- package/testing/index.d.ts +4 -0
- package/testing/index.js +4 -0
- package/testing/registerOpenSearchCoreForTests.d.ts +1 -0
- package/testing/registerOpenSearchCoreForTests.js +9 -0
- package/testing/registerOpenSearchCoreForTests.js.map +1 -0
- package/testing/setupTestIndexManager.d.ts +13 -0
- package/testing/setupTestIndexManager.js +26 -0
- package/testing/setupTestIndexManager.js.map +1 -0
- package/types.d.ts +0 -8
- package/types.js.map +1 -1
- package/utils/createIndex.d.ts +2 -2
- package/utils/createIndex.js +2 -8
- package/utils/createIndex.js.map +1 -1
- package/utils/waitUntilHealthy/WaitUntilHealthy.js +2 -1
- package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -1
- package/where.d.ts +4 -4
- package/where.js +5 -5
- package/where.js.map +1 -1
- package/features/OpenSearchClient/OpenSearchClient.d.ts +0 -12
- package/features/OpenSearchClient/OpenSearchClient.js +0 -19
- package/features/OpenSearchClient/OpenSearchClient.js.map +0 -1
- package/features/OpenSearchContext/OpenSearchContext.d.ts +0 -8
- package/features/OpenSearchContext/OpenSearchContext.js +0 -14
- package/features/OpenSearchContext/OpenSearchContext.js.map +0 -1
- package/features/OpenSearchContext/abstraction.d.ts +0 -14
- package/features/OpenSearchContext/abstraction.js +0 -5
- package/features/OpenSearchContext/abstraction.js.map +0 -1
- package/features/OpenSearchContext/feature.d.ts +0 -5
- package/features/OpenSearchContext/feature.js +0 -12
- package/features/OpenSearchContext/feature.js.map +0 -1
- package/index.js.map +0 -1
- package/indices.js.map +0 -1
- package/operators.d.ts +0 -6
- package/operators.js +0 -22
- package/operators.js.map +0 -1
- package/plugins/definition/OpenSearchBodyModifierPlugin.d.ts +0 -13
- package/plugins/definition/OpenSearchBodyModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchBodyModifierPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchFieldPlugin.d.ts +0 -81
- package/plugins/definition/OpenSearchFieldPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchIndexPlugin.d.ts +0 -10
- package/plugins/definition/OpenSearchIndexPlugin.js +0 -16
- package/plugins/definition/OpenSearchIndexPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.d.ts +0 -10
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js +0 -9
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchQueryModifierPlugin.d.ts +0 -14
- package/plugins/definition/OpenSearchQueryModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchQueryModifierPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchSortModifierPlugin.d.ts +0 -13
- package/plugins/definition/OpenSearchSortModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchSortModifierPlugin.js.map +0 -1
- package/plugins/definition/index.d.ts +0 -6
- package/plugins/definition/index.js +0 -6
- package/plugins/index.d.ts +0 -2
- package/plugins/index.js +0 -2
- package/plugins/operator/andIn.d.ts +0 -7
- package/plugins/operator/andIn.js.map +0 -1
- package/plugins/operator/between.d.ts +0 -7
- package/plugins/operator/between.js +0 -26
- package/plugins/operator/between.js.map +0 -1
- package/plugins/operator/contains.d.ts +0 -7
- package/plugins/operator/contains.js +0 -26
- package/plugins/operator/contains.js.map +0 -1
- package/plugins/operator/equal.d.ts +0 -7
- package/plugins/operator/equal.js.map +0 -1
- package/plugins/operator/gt.d.ts +0 -7
- package/plugins/operator/gt.js +0 -22
- package/plugins/operator/gt.js.map +0 -1
- package/plugins/operator/gte.d.ts +0 -7
- package/plugins/operator/gte.js +0 -22
- package/plugins/operator/gte.js.map +0 -1
- package/plugins/operator/in.d.ts +0 -7
- package/plugins/operator/in.js.map +0 -1
- package/plugins/operator/index.d.ts +0 -15
- package/plugins/operator/index.js +0 -15
- package/plugins/operator/lt.d.ts +0 -7
- package/plugins/operator/lt.js +0 -22
- package/plugins/operator/lt.js.map +0 -1
- package/plugins/operator/lte.d.ts +0 -7
- package/plugins/operator/lte.js +0 -22
- package/plugins/operator/lte.js.map +0 -1
- package/plugins/operator/not.d.ts +0 -7
- package/plugins/operator/not.js.map +0 -1
- package/plugins/operator/notBetween.d.ts +0 -7
- package/plugins/operator/notBetween.js +0 -26
- package/plugins/operator/notBetween.js.map +0 -1
- package/plugins/operator/notContains.d.ts +0 -7
- package/plugins/operator/notContains.js +0 -26
- package/plugins/operator/notContains.js.map +0 -1
- package/plugins/operator/notIn.d.ts +0 -7
- package/plugins/operator/notIn.js.map +0 -1
- package/plugins/operator/notStartsWith.d.ts +0 -7
- package/plugins/operator/notStartsWith.js +0 -21
- package/plugins/operator/notStartsWith.js.map +0 -1
- package/plugins/operator/startsWith.d.ts +0 -7
- package/plugins/operator/startsWith.js +0 -21
- package/plugins/operator/startsWith.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { OpenSearchClientOptions } from "./client.js";
|
|
4
|
-
import { Client } from "./client.js";
|
|
5
|
-
export * from "./indexConfiguration/index.js";
|
|
6
|
-
export * from "./plugins/index.js";
|
|
1
|
+
export { registerOpenSearchCore } from "./registerOpenSearchCore.js";
|
|
2
|
+
export { getCommonMappings, getBaseConfiguration } from "./indexConfiguration/index.js";
|
|
7
3
|
export * from "./sort.js";
|
|
8
|
-
export * from "./indices.js";
|
|
9
4
|
export * from "./where.js";
|
|
10
5
|
export * from "./limit.js";
|
|
11
6
|
export * from "./normalize.js";
|
|
12
|
-
export * from "./operators.js";
|
|
13
7
|
export * from "./cursors.js";
|
|
14
8
|
export { createOpenSearchClient, type Client, type ClientOptions, type OpenSearchClientOptions } from "./client.js";
|
|
15
9
|
export * from "./utils/index.js";
|
|
@@ -18,4 +12,3 @@ export * from "./sharedIndex.js";
|
|
|
18
12
|
export * from "./indexPrefix.js";
|
|
19
13
|
export * from "./db/index.js";
|
|
20
14
|
export * from "./types.js";
|
|
21
|
-
export declare const createOpenSearchContext: (params: OpenSearchClientOptions | Client) => ContextPlugin<OpenSearchContext>;
|
package/index.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { Client, createOpenSearchClient } from "./client.js";
|
|
3
|
-
import { getOpenSearchOperators } from "./operators.js";
|
|
4
|
-
import { OpenSearchClientFactoryFeature } from "./features/OpenSearchClientFactory/feature.js";
|
|
5
|
-
import { OpenSearchClientFeature } from "./features/OpenSearchClient/feature.js";
|
|
6
|
-
import { OpenSearchContextFeature } from "./features/OpenSearchContext/feature.js";
|
|
7
|
-
export * from "./indexConfiguration/index.js";
|
|
8
|
-
export * from "./plugins/index.js";
|
|
9
1
|
export * from "./sort.js";
|
|
10
|
-
export * from "./indices.js";
|
|
11
2
|
export * from "./where.js";
|
|
12
3
|
export * from "./limit.js";
|
|
13
4
|
export * from "./normalize.js";
|
|
14
|
-
export * from "./operators.js";
|
|
15
5
|
export * from "./cursors.js";
|
|
16
6
|
export * from "./utils/index.js";
|
|
17
7
|
export * from "./operations/index.js";
|
|
@@ -19,20 +9,6 @@ export * from "./sharedIndex.js";
|
|
|
19
9
|
export * from "./indexPrefix.js";
|
|
20
10
|
export * from "./db/index.js";
|
|
21
11
|
export * from "./types.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const client = params instanceof Client ? params : createOpenSearchClient(params);
|
|
26
|
-
context.opensearch = client;
|
|
27
|
-
context.elasticsearch = client;
|
|
28
|
-
context.plugins.register(getOpenSearchOperators());
|
|
29
|
-
OpenSearchContextFeature.register(context.container, context);
|
|
30
|
-
OpenSearchClientFeature.register(context.container);
|
|
31
|
-
OpenSearchClientFactoryFeature.register(context.container);
|
|
32
|
-
});
|
|
33
|
-
plugin.name = "context.opensearch";
|
|
34
|
-
return plugin;
|
|
35
|
-
};
|
|
36
|
-
export { createOpenSearchClient, createOpenSearchContext };
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=index.js.map
|
|
12
|
+
export { registerOpenSearchCore } from "./registerOpenSearchCore.js";
|
|
13
|
+
export { getBaseConfiguration, getCommonMappings } from "./indexConfiguration/index.js";
|
|
14
|
+
export { createOpenSearchClient } from "./client.js";
|
package/indices.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
interface IndicesPluginsParams {
|
|
4
|
-
container: PluginsContainer;
|
|
5
|
-
type: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const getLastAddedIndexPlugin: <T extends OpenSearchIndexPlugin>(params: IndicesPluginsParams) => T;
|
|
8
|
-
export {};
|
|
1
|
+
import { OpenSearchIndexRegistry } from "./features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js";
|
|
2
|
+
export { OpenSearchIndexRegistry };
|
package/indices.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const listIndicesPlugins = ({ container, type })=>container.byType(type).filter((plugin)=>plugin.canUse());
|
|
3
|
-
const getLastAddedIndexPlugin = (params)=>{
|
|
4
|
-
const plugins = listIndicesPlugins(params);
|
|
5
|
-
if (0 === plugins.length) throw new error(`Could not find a single OpenSearchIndexPlugin of type "${params.type}".`, "OPENSEARCH_INDEX_TEMPLATE_ERROR", {
|
|
6
|
-
type: params.type
|
|
7
|
-
});
|
|
8
|
-
return plugins.pop();
|
|
9
|
-
};
|
|
10
|
-
export { getLastAddedIndexPlugin };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=indices.js.map
|
|
1
|
+
export { OpenSearchIndexRegistry } from "./features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-opensearch",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,19 +18,20 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@opensearch-project/opensearch": "3.6.0",
|
|
21
|
-
"@webiny/api": "6.
|
|
22
|
-
"@webiny/aws-sdk": "6.
|
|
23
|
-
"@webiny/db-dynamodb": "6.
|
|
24
|
-
"@webiny/error": "6.
|
|
25
|
-
"@webiny/feature": "6.
|
|
26
|
-
"@webiny/
|
|
21
|
+
"@webiny/api": "6.5.0-beta.0",
|
|
22
|
+
"@webiny/aws-sdk": "6.5.0-beta.0",
|
|
23
|
+
"@webiny/db-dynamodb": "6.5.0-beta.0",
|
|
24
|
+
"@webiny/error": "6.5.0-beta.0",
|
|
25
|
+
"@webiny/feature": "6.5.0-beta.0",
|
|
26
|
+
"@webiny/handler": "6.5.0-beta.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@webiny/build-tools": "6.
|
|
30
|
-
"@webiny/
|
|
29
|
+
"@webiny/build-tools": "6.5.0-beta.0",
|
|
30
|
+
"@webiny/di": "1.0.2",
|
|
31
|
+
"@webiny/project-utils": "6.5.0-beta.0",
|
|
31
32
|
"rimraf": "6.1.3",
|
|
32
|
-
"typescript": "
|
|
33
|
-
"vitest": "
|
|
33
|
+
"typescript": "7.0.2",
|
|
34
|
+
"vitest": "4.1.10"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
@@ -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"}
|
package/sort.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SortOrder, SortType } from "./types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenSearchField } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
|
|
3
3
|
interface CreateSortParams {
|
|
4
4
|
sort: string[];
|
|
5
5
|
defaults?: {
|
|
@@ -7,7 +7,7 @@ interface CreateSortParams {
|
|
|
7
7
|
order?: SortOrder;
|
|
8
8
|
unmappedType?: string;
|
|
9
9
|
};
|
|
10
|
-
fieldPlugins: Record<string,
|
|
10
|
+
fieldPlugins: Record<string, OpenSearchField.Interface>;
|
|
11
11
|
}
|
|
12
12
|
export declare const createSort: (params: CreateSortParams) => SortType;
|
|
13
13
|
export {};
|
package/sort.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import error from "@webiny/error";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenSearchFieldAll } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
|
|
3
3
|
const sortRegExp = /^((?:values\.)?[a-zA-Z0-9_@-]+)_(ASC|DESC)$/;
|
|
4
4
|
const createSort = (params)=>{
|
|
5
5
|
const { sort, defaults, fieldPlugins } = params;
|
|
@@ -18,7 +18,7 @@ const createSort = (params)=>{
|
|
|
18
18
|
if (!match) throw new error(`Cannot sort by "${value}".`);
|
|
19
19
|
const [, field, initialOrder] = match;
|
|
20
20
|
const order = "asc" === initialOrder.toLowerCase() ? "asc" : "desc";
|
|
21
|
-
const plugin = fieldPlugins[field] || fieldPlugins[
|
|
21
|
+
const plugin = fieldPlugins[field] || fieldPlugins[OpenSearchFieldAll];
|
|
22
22
|
if (!plugin) throw new error(`Missing plugin for the field "${field}"`, "PLUGIN_SORT_ERROR", {
|
|
23
23
|
field
|
|
24
24
|
});
|
package/sort.js.map
CHANGED
|
@@ -1 +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 {
|
|
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 @@
|
|
|
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";
|
package/testing/index.js
ADDED
|
@@ -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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\";\
|
|
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"}
|
package/utils/createIndex.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Client } from "../client.js";
|
|
2
|
-
import type {
|
|
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
|
-
|
|
11
|
+
plugin: OpenSearchIndex.Interface;
|
|
12
12
|
type: string;
|
|
13
13
|
tenant: string;
|
|
14
14
|
index: string;
|
package/utils/createIndex.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { getLastAddedIndexPlugin } from "../indices.js";
|
|
2
1
|
import _webiny_error from "@webiny/error";
|
|
3
2
|
const indexExists = async (params)=>{
|
|
4
|
-
const { client, index
|
|
3
|
+
const { client, index } = params;
|
|
5
4
|
try {
|
|
6
5
|
const response = await client.indices.exists({
|
|
7
6
|
index,
|
|
@@ -12,7 +11,6 @@ const indexExists = async (params)=>{
|
|
|
12
11
|
local: false
|
|
13
12
|
});
|
|
14
13
|
if (!response.body) return false;
|
|
15
|
-
if (onExists) onExists();
|
|
16
14
|
return true;
|
|
17
15
|
} catch {
|
|
18
16
|
console.error(`Could not determine if the index "${index}" exists.`);
|
|
@@ -46,11 +44,7 @@ const indexCreate = async (params)=>{
|
|
|
46
44
|
}
|
|
47
45
|
};
|
|
48
46
|
const createIndex = async (params)=>{
|
|
49
|
-
const {
|
|
50
|
-
const plugin = getLastAddedIndexPlugin({
|
|
51
|
-
container: plugins,
|
|
52
|
-
type
|
|
53
|
-
});
|
|
47
|
+
const { plugin, onExists } = params;
|
|
54
48
|
const exists = await indexExists(params);
|
|
55
49
|
if (exists) {
|
|
56
50
|
if (onExists) onExists();
|