@webiny/api-search-index-tasks-os 0.0.0-unstable.0d717d18dd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/api-search-index-tasks-os
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -0,0 +1,4 @@
1
+ export declare class IndexSettingsGetError extends Error {
2
+ readonly index: string;
3
+ constructor(cause: unknown, index: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ class IndexSettingsGetError extends Error {
2
+ constructor(cause, index){
3
+ super(`Failed to get settings for index "${index}".`);
4
+ this.index = index;
5
+ this.cause = cause;
6
+ }
7
+ }
8
+ export { IndexSettingsGetError };
9
+
10
+ //# sourceMappingURL=IndexSettingsGetError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors/IndexSettingsGetError.js","sources":["../../src/errors/IndexSettingsGetError.ts"],"sourcesContent":["export class IndexSettingsGetError extends Error {\n public readonly index: string;\n constructor(cause: unknown, index: string) {\n super(`Failed to get settings for index \"${index}\".`);\n this.index = index;\n this.cause = cause;\n }\n}\n"],"names":["IndexSettingsGetError","Error","cause","index"],"mappings":"AAAO,MAAMA,8BAA8BC;IAEvC,YAAYC,KAAc,EAAEC,KAAa,CAAE;QACvC,KAAK,CAAC,CAAC,kCAAkC,EAAEA,MAAM,EAAE,CAAC;QACpD,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,KAAK,GAAGD;IACjB;AACJ"}
@@ -0,0 +1,4 @@
1
+ export declare class IndexSettingsSetError extends Error {
2
+ readonly index: string;
3
+ constructor(cause: unknown, index: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ class IndexSettingsSetError extends Error {
2
+ constructor(cause, index){
3
+ super(`Failed to set settings for index "${index}".`);
4
+ this.index = index;
5
+ this.cause = cause;
6
+ }
7
+ }
8
+ export { IndexSettingsSetError };
9
+
10
+ //# sourceMappingURL=IndexSettingsSetError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors/IndexSettingsSetError.js","sources":["../../src/errors/IndexSettingsSetError.ts"],"sourcesContent":["export class IndexSettingsSetError extends Error {\n public readonly index: string;\n constructor(cause: unknown, index: string) {\n super(`Failed to set settings for index \"${index}\".`);\n this.index = index;\n this.cause = cause;\n }\n}\n"],"names":["IndexSettingsSetError","Error","cause","index"],"mappings":"AAAO,MAAMA,8BAA8BC;IAEvC,YAAYC,KAAc,EAAEC,KAAa,CAAE;QACvC,KAAK,CAAC,CAAC,kCAAkC,EAAEA,MAAM,EAAE,CAAC;QACpD,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,KAAK,GAAGD;IACjB;AACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const SearchIndexTasksOsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { IndexSettingsManager } from "./settings/IndexSettingsManager.js";
3
+ import { IndexManagerFactory } from "./indexManager/IndexManagerFactory.js";
4
+ const SearchIndexTasksOsFeature = createFeature({
5
+ name: "SearchIndexTasksOs",
6
+ register (container) {
7
+ container.register(IndexSettingsManager);
8
+ container.register(IndexManagerFactory);
9
+ }
10
+ });
11
+ export { SearchIndexTasksOsFeature };
12
+
13
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { IndexSettingsManager } from \"~/settings/IndexSettingsManager.js\";\nimport { IndexManagerFactory } from \"~/indexManager/IndexManagerFactory.js\";\n\nexport const SearchIndexTasksOsFeature = createFeature({\n name: \"SearchIndexTasksOs\",\n register(container) {\n container.register(IndexSettingsManager);\n container.register(IndexManagerFactory);\n }\n});\n"],"names":["SearchIndexTasksOsFeature","createFeature","container","IndexSettingsManager","IndexManagerFactory"],"mappings":";;;AAIO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
@@ -0,0 +1,19 @@
1
+ import type { IndexManager as IndexManagerAbstraction } from "@webiny/api-search-index-tasks/abstractions/IndexManager.js";
2
+ import type { DisableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/DisableIndexing.js";
3
+ import type { EnableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/EnableIndexing.js";
4
+ import type { Client } from "@webiny/api-opensearch";
5
+ import type { GenericRecord } from "@webiny/api/types.js";
6
+ export declare class OsIndexManager implements IndexManagerAbstraction.Interface {
7
+ private readonly client;
8
+ private readonly disable;
9
+ private readonly enable;
10
+ private readonly _settings;
11
+ private readonly defaults;
12
+ get settings(): IndexManagerAbstraction.SettingsMap;
13
+ constructor(client: Client, disableIndexing: DisableIndexing.Interface, enableIndexing: EnableIndexing.Interface, settings: IndexManagerAbstraction.SettingsMap, defaults?: Partial<IndexManagerAbstraction.Settings>);
14
+ list(): Promise<string[]>;
15
+ disableIndexing(index: string): Promise<IndexManagerAbstraction.Settings>;
16
+ enableIndexing(index?: string): Promise<void>;
17
+ createIndex(index: string, settings?: GenericRecord): Promise<void>;
18
+ indexExists(index: string): Promise<boolean>;
19
+ }
@@ -0,0 +1,77 @@
1
+ import { getObjectProperties } from "@webiny/utils";
2
+ const defaultIndexSettings = {
3
+ numberOfReplicas: 1,
4
+ refreshInterval: "1s"
5
+ };
6
+ const indexPrefix = process.env.OPENSEARCH_INDEX_PREFIX || "";
7
+ const filterIndex = (item)=>{
8
+ if (!item) return false;
9
+ if (item.startsWith(".")) return false;
10
+ if (indexPrefix) return item.startsWith(indexPrefix);
11
+ return true;
12
+ };
13
+ class OsIndexManager {
14
+ get settings() {
15
+ return this._settings;
16
+ }
17
+ constructor(client, disableIndexing, enableIndexing, settings, defaults){
18
+ this.client = client;
19
+ this.disable = disableIndexing;
20
+ this.enable = enableIndexing;
21
+ this._settings = settings;
22
+ this.defaults = {
23
+ refreshInterval: defaults?.refreshInterval || defaultIndexSettings.refreshInterval,
24
+ numberOfReplicas: defaults?.numberOfReplicas || defaultIndexSettings.numberOfReplicas
25
+ };
26
+ }
27
+ async list() {
28
+ try {
29
+ const response = await this.client.cat.indices({
30
+ format: "json"
31
+ });
32
+ if (!Array.isArray(response.body)) return [];
33
+ return response.body.map((item)=>item.index).filter((index)=>filterIndex(index));
34
+ } catch (ex) {
35
+ console.error(JSON.stringify({
36
+ message: "Failed to list indices.",
37
+ error: getObjectProperties(ex)
38
+ }));
39
+ return [];
40
+ }
41
+ }
42
+ async disableIndexing(index) {
43
+ if (this._settings[index]) return this._settings[index];
44
+ const settings = await this.disable.execute(index);
45
+ this._settings[index] = settings;
46
+ return settings;
47
+ }
48
+ async enableIndexing(index) {
49
+ if (!index) {
50
+ const indexes = Object.keys(this._settings);
51
+ for (const index of indexes)await this.enableIndexing(index);
52
+ return;
53
+ }
54
+ const settings = this._settings[index] || this.defaults;
55
+ await this.enable.execute(index, settings);
56
+ }
57
+ async createIndex(index, settings) {
58
+ await this.client.indices.create({
59
+ index,
60
+ body: settings
61
+ });
62
+ }
63
+ async indexExists(index) {
64
+ const response = await this.client.indices.exists({
65
+ index,
66
+ ignore_unavailable: false,
67
+ allow_no_indices: true,
68
+ include_defaults: true,
69
+ flat_settings: false,
70
+ local: false
71
+ });
72
+ return !!response.body;
73
+ }
74
+ }
75
+ export { OsIndexManager };
76
+
77
+ //# sourceMappingURL=IndexManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexManager/IndexManager.js","sources":["../../src/indexManager/IndexManager.ts"],"sourcesContent":["import type { IndexManager as IndexManagerAbstraction } from \"@webiny/api-search-index-tasks/abstractions/IndexManager.js\";\nimport type { DisableIndexing } from \"@webiny/api-search-index-tasks/settings/abstractions/DisableIndexing.js\";\nimport type { EnableIndexing } from \"@webiny/api-search-index-tasks/settings/abstractions/EnableIndexing.js\";\nimport type { Client } from \"@webiny/api-opensearch\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { getObjectProperties } from \"@webiny/utils\";\n\nconst defaultIndexSettings: IndexManagerAbstraction.Settings = {\n numberOfReplicas: 1,\n refreshInterval: \"1s\"\n};\n\nconst indexPrefix = process.env.OPENSEARCH_INDEX_PREFIX || \"\";\nconst filterIndex = (item?: string) => {\n if (!item) {\n return false;\n } else if (item.startsWith(\".\")) {\n return false;\n } else if (indexPrefix) {\n return item.startsWith(indexPrefix);\n }\n return true;\n};\n\nexport class OsIndexManager implements IndexManagerAbstraction.Interface {\n private readonly client: Client;\n private readonly disable: DisableIndexing.Interface;\n private readonly enable: EnableIndexing.Interface;\n private readonly _settings: IndexManagerAbstraction.SettingsMap;\n private readonly defaults: IndexManagerAbstraction.Settings;\n\n public get settings(): IndexManagerAbstraction.SettingsMap {\n return this._settings;\n }\n\n public constructor(\n client: Client,\n disableIndexing: DisableIndexing.Interface,\n enableIndexing: EnableIndexing.Interface,\n settings: IndexManagerAbstraction.SettingsMap,\n defaults?: Partial<IndexManagerAbstraction.Settings>\n ) {\n this.client = client;\n this.disable = disableIndexing;\n this.enable = enableIndexing;\n this._settings = settings;\n this.defaults = {\n refreshInterval: defaults?.refreshInterval || defaultIndexSettings.refreshInterval,\n numberOfReplicas: defaults?.numberOfReplicas || defaultIndexSettings.numberOfReplicas\n };\n }\n\n public async list(): Promise<string[]> {\n try {\n const response = await this.client.cat.indices({\n format: \"json\"\n });\n if (!Array.isArray(response.body)) {\n return [];\n }\n return response.body\n .map(item => item.index)\n .filter((index): index is string => filterIndex(index));\n } catch (ex) {\n console.error(\n JSON.stringify({\n message: \"Failed to list indices.\",\n error: getObjectProperties(ex)\n })\n );\n return [];\n }\n }\n\n public async disableIndexing(index: string): Promise<IndexManagerAbstraction.Settings> {\n if (this._settings[index]) {\n return this._settings[index];\n }\n const settings = await this.disable.execute(index);\n this._settings[index] = settings;\n return settings;\n }\n\n public async enableIndexing(index?: string): Promise<void> {\n if (!index) {\n const indexes = Object.keys(this._settings);\n for (const index of indexes) {\n await this.enableIndexing(index);\n }\n return;\n }\n const settings = this._settings[index] || this.defaults;\n await this.enable.execute(index, settings);\n }\n\n public async createIndex(index: string, settings?: GenericRecord): Promise<void> {\n await this.client.indices.create({\n index,\n body: settings\n });\n }\n\n public async indexExists(index: string): Promise<boolean> {\n const response = await this.client.indices.exists({\n index,\n ignore_unavailable: false,\n allow_no_indices: true,\n include_defaults: true,\n flat_settings: false,\n local: false\n });\n return !!response.body;\n }\n}\n"],"names":["defaultIndexSettings","indexPrefix","process","filterIndex","item","OsIndexManager","client","disableIndexing","enableIndexing","settings","defaults","response","Array","index","ex","console","JSON","getObjectProperties","indexes","Object"],"mappings":";AAOA,MAAMA,uBAAyD;IAC3D,kBAAkB;IAClB,iBAAiB;AACrB;AAEA,MAAMC,cAAcC,QAAQ,GAAG,CAAC,uBAAuB,IAAI;AAC3D,MAAMC,cAAc,CAACC;IACjB,IAAI,CAACA,MACD,OAAO;IACJ,IAAIA,KAAK,UAAU,CAAC,MACvB,OAAO;IACJ,IAAIH,aACP,OAAOG,KAAK,UAAU,CAACH;IAE3B,OAAO;AACX;AAEO,MAAMI;IAOT,IAAW,WAAgD;QACvD,OAAO,IAAI,CAAC,SAAS;IACzB;IAEA,YACIC,MAAc,EACdC,eAA0C,EAC1CC,cAAwC,EACxCC,QAA6C,EAC7CC,QAAoD,CACtD;QACE,IAAI,CAAC,MAAM,GAAGJ;QACd,IAAI,CAAC,OAAO,GAAGC;QACf,IAAI,CAAC,MAAM,GAAGC;QACd,IAAI,CAAC,SAAS,GAAGC;QACjB,IAAI,CAAC,QAAQ,GAAG;YACZ,iBAAiBC,UAAU,mBAAmBV,qBAAqB,eAAe;YAClF,kBAAkBU,UAAU,oBAAoBV,qBAAqB,gBAAgB;QACzF;IACJ;IAEA,MAAa,OAA0B;QACnC,IAAI;YACA,MAAMW,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC3C,QAAQ;YACZ;YACA,IAAI,CAACC,MAAM,OAAO,CAACD,SAAS,IAAI,GAC5B,OAAO,EAAE;YAEb,OAAOA,SAAS,IAAI,CACf,GAAG,CAACP,CAAAA,OAAQA,KAAK,KAAK,EACtB,MAAM,CAAC,CAACS,QAA2BV,YAAYU;QACxD,EAAE,OAAOC,IAAI;YACTC,QAAQ,KAAK,CACTC,KAAK,SAAS,CAAC;gBACX,SAAS;gBACT,OAAOC,oBAAoBH;YAC/B;YAEJ,OAAO,EAAE;QACb;IACJ;IAEA,MAAa,gBAAgBD,KAAa,EAA6C;QACnF,IAAI,IAAI,CAAC,SAAS,CAACA,MAAM,EACrB,OAAO,IAAI,CAAC,SAAS,CAACA,MAAM;QAEhC,MAAMJ,WAAW,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAACI;QAC5C,IAAI,CAAC,SAAS,CAACA,MAAM,GAAGJ;QACxB,OAAOA;IACX;IAEA,MAAa,eAAeI,KAAc,EAAiB;QACvD,IAAI,CAACA,OAAO;YACR,MAAMK,UAAUC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS;YAC1C,KAAK,MAAMN,SAASK,QAChB,MAAM,IAAI,CAAC,cAAc,CAACL;YAE9B;QACJ;QACA,MAAMJ,WAAW,IAAI,CAAC,SAAS,CAACI,MAAM,IAAI,IAAI,CAAC,QAAQ;QACvD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAACA,OAAOJ;IACrC;IAEA,MAAa,YAAYI,KAAa,EAAEJ,QAAwB,EAAiB;QAC7E,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC7BI;YACA,MAAMJ;QACV;IACJ;IAEA,MAAa,YAAYI,KAAa,EAAoB;QACtD,MAAMF,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;YAC9CE;YACA,oBAAoB;YACpB,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,OAAO;QACX;QACA,OAAO,CAAC,CAACF,SAAS,IAAI;IAC1B;AACJ"}
@@ -0,0 +1,16 @@
1
+ import { OsIndexManager } from "./IndexManager.js";
2
+ import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
3
+ import { DisableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/DisableIndexing.js";
4
+ import { EnableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/EnableIndexing.js";
5
+ import { IndexManagerFactory as Abstraction } from "@webiny/api-search-index-tasks/abstractions/IndexManagerFactory.js";
6
+ declare class IndexManagerFactoryImpl implements Abstraction.Interface {
7
+ private readonly openSearchClient;
8
+ private readonly disableIndexing;
9
+ private readonly enableIndexing;
10
+ constructor(openSearchClient: OpenSearchClient.Interface, disableIndexing: DisableIndexing.Interface, enableIndexing: EnableIndexing.Interface);
11
+ createIndexManager(params: Abstraction.Params): OsIndexManager;
12
+ }
13
+ export declare const IndexManagerFactory: typeof IndexManagerFactoryImpl & {
14
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-search-index-tasks/abstractions/IndexManagerFactory.js").IIndexManagerFactory>;
15
+ };
16
+ export {};
@@ -0,0 +1,26 @@
1
+ import { OsIndexManager } from "./IndexManager.js";
2
+ import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
3
+ import { DisableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/DisableIndexing.js";
4
+ import { EnableIndexing } from "@webiny/api-search-index-tasks/settings/abstractions/EnableIndexing.js";
5
+ import { IndexManagerFactory } from "@webiny/api-search-index-tasks/abstractions/IndexManagerFactory.js";
6
+ class IndexManagerFactoryImpl {
7
+ constructor(openSearchClient, disableIndexing, enableIndexing){
8
+ this.openSearchClient = openSearchClient;
9
+ this.disableIndexing = disableIndexing;
10
+ this.enableIndexing = enableIndexing;
11
+ }
12
+ createIndexManager(params) {
13
+ return new OsIndexManager(this.openSearchClient.use(), this.disableIndexing, this.enableIndexing, params.settings, params.defaults);
14
+ }
15
+ }
16
+ const IndexManagerFactory_IndexManagerFactory = IndexManagerFactory.createImplementation({
17
+ implementation: IndexManagerFactoryImpl,
18
+ dependencies: [
19
+ OpenSearchClient,
20
+ DisableIndexing,
21
+ EnableIndexing
22
+ ]
23
+ });
24
+ export { IndexManagerFactory_IndexManagerFactory as IndexManagerFactory };
25
+
26
+ //# sourceMappingURL=IndexManagerFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexManager/IndexManagerFactory.js","sources":["../../src/indexManager/IndexManagerFactory.ts"],"sourcesContent":["import { OsIndexManager } from \"./IndexManager.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { DisableIndexing } from \"@webiny/api-search-index-tasks/settings/abstractions/DisableIndexing.js\";\nimport { EnableIndexing } from \"@webiny/api-search-index-tasks/settings/abstractions/EnableIndexing.js\";\nimport { IndexManagerFactory as Abstraction } from \"@webiny/api-search-index-tasks/abstractions/IndexManagerFactory.js\";\n\nclass IndexManagerFactoryImpl implements Abstraction.Interface {\n public constructor(\n private readonly openSearchClient: OpenSearchClient.Interface,\n private readonly disableIndexing: DisableIndexing.Interface,\n private readonly enableIndexing: EnableIndexing.Interface\n ) {}\n\n public createIndexManager(params: Abstraction.Params) {\n return new OsIndexManager(\n this.openSearchClient.use(),\n this.disableIndexing,\n this.enableIndexing,\n params.settings,\n params.defaults\n );\n }\n}\n\nexport const IndexManagerFactory = Abstraction.createImplementation({\n implementation: IndexManagerFactoryImpl,\n dependencies: [OpenSearchClient, DisableIndexing, EnableIndexing]\n});\n"],"names":["IndexManagerFactoryImpl","openSearchClient","disableIndexing","enableIndexing","params","OsIndexManager","IndexManagerFactory","Abstraction","OpenSearchClient","DisableIndexing","EnableIndexing"],"mappings":";;;;;AAMA,MAAMA;IACF,YACqBC,gBAA4C,EAC5CC,eAA0C,EAC1CC,cAAwC,CAC3D;aAHmBF,gBAAgB,GAAhBA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;IAClB;IAEI,mBAAmBC,MAA0B,EAAE;QAClD,OAAO,IAAIC,eACP,IAAI,CAAC,gBAAgB,CAAC,GAAG,IACzB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,EACnBD,OAAO,QAAQ,EACfA,OAAO,QAAQ;IAEvB;AACJ;AAEO,MAAME,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgBP;IAChB,cAAc;QAACQ;QAAkBC;QAAiBC;KAAe;AACrE"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@webiny/api-search-index-tasks-os",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/webiny/webiny-js.git",
12
+ "directory": "packages/api-search-index-tasks-os"
13
+ },
14
+ "description": "OpenSearch bridge for @webiny/api-search-index-tasks.",
15
+ "license": "MIT",
16
+ "author": "Webiny Ltd.",
17
+ "dependencies": {
18
+ "@webiny/api": "0.0.0-unstable.0d717d18dd",
19
+ "@webiny/api-opensearch": "0.0.0-unstable.0d717d18dd",
20
+ "@webiny/api-search-index-tasks": "0.0.0-unstable.0d717d18dd",
21
+ "@webiny/feature": "0.0.0-unstable.0d717d18dd",
22
+ "@webiny/utils": "0.0.0-unstable.0d717d18dd"
23
+ },
24
+ "devDependencies": {
25
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
26
+ "typescript": "7.0.2",
27
+ "vitest": "4.1.10"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "webiny": {
33
+ "publishFrom": "dist"
34
+ }
35
+ }
@@ -0,0 +1,12 @@
1
+ import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
2
+ import { IndexSettingsManager as Abstraction } from "@webiny/api-search-index-tasks/abstractions/IndexSettingsManager.js";
3
+ declare class IndexSettingsManagerImpl implements Abstraction.Interface {
4
+ private readonly openSearchClient;
5
+ constructor(openSearchClient: OpenSearchClient.Interface);
6
+ getSettings(index: string): Promise<Abstraction.Settings>;
7
+ setSettings(index: string, settings: Abstraction.Settings): Promise<void>;
8
+ }
9
+ export declare const IndexSettingsManager: typeof IndexSettingsManagerImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-search-index-tasks/abstractions/IndexSettingsManager.js").IIndexSettingsManager>;
11
+ };
12
+ export {};
@@ -0,0 +1,47 @@
1
+ import { IndexSettingsGetError } from "../errors/IndexSettingsGetError.js";
2
+ import { IndexSettingsSetError } from "../errors/IndexSettingsSetError.js";
3
+ import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
4
+ import { IndexSettingsManager } from "@webiny/api-search-index-tasks/abstractions/IndexSettingsManager.js";
5
+ class IndexSettingsManagerImpl {
6
+ constructor(openSearchClient){
7
+ this.openSearchClient = openSearchClient;
8
+ }
9
+ async getSettings(index) {
10
+ try {
11
+ const response = await this.openSearchClient.use().indices.getSettings({
12
+ index
13
+ });
14
+ const setting = response.body[index]?.settings?.index;
15
+ return {
16
+ numberOfReplicas: parseInt(String(setting?.number_of_replicas ?? "0"), 10),
17
+ refreshInterval: setting?.refresh_interval ?? "1s"
18
+ };
19
+ } catch (ex) {
20
+ throw new IndexSettingsGetError(ex, index);
21
+ }
22
+ }
23
+ async setSettings(index, settings) {
24
+ try {
25
+ await this.openSearchClient.use().indices.putSettings({
26
+ index,
27
+ body: {
28
+ index: {
29
+ number_of_replicas: settings.numberOfReplicas,
30
+ refresh_interval: settings.refreshInterval
31
+ }
32
+ }
33
+ });
34
+ } catch (ex) {
35
+ throw new IndexSettingsSetError(ex, index);
36
+ }
37
+ }
38
+ }
39
+ const IndexSettingsManager_IndexSettingsManager = IndexSettingsManager.createImplementation({
40
+ implementation: IndexSettingsManagerImpl,
41
+ dependencies: [
42
+ OpenSearchClient
43
+ ]
44
+ });
45
+ export { IndexSettingsManager_IndexSettingsManager as IndexSettingsManager };
46
+
47
+ //# sourceMappingURL=IndexSettingsManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings/IndexSettingsManager.js","sources":["../../src/settings/IndexSettingsManager.ts"],"sourcesContent":["import { IndexSettingsGetError } from \"~/errors/IndexSettingsGetError.js\";\nimport { IndexSettingsSetError } from \"~/errors/IndexSettingsSetError.js\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { IndexSettingsManager as Abstraction } from \"@webiny/api-search-index-tasks/abstractions/IndexSettingsManager.js\";\n\nclass IndexSettingsManagerImpl implements Abstraction.Interface {\n constructor(private readonly openSearchClient: OpenSearchClient.Interface) {}\n\n public async getSettings(index: string): Promise<Abstraction.Settings> {\n try {\n const response = await this.openSearchClient.use().indices.getSettings({\n index\n });\n\n const setting = response.body[index]?.settings?.index;\n\n return {\n numberOfReplicas: parseInt(String(setting?.number_of_replicas ?? \"0\"), 10),\n refreshInterval: setting?.refresh_interval ?? \"1s\"\n };\n } catch (ex) {\n throw new IndexSettingsGetError(ex, index);\n }\n }\n\n public async setSettings(index: string, settings: Abstraction.Settings): Promise<void> {\n try {\n await this.openSearchClient.use().indices.putSettings({\n index,\n body: {\n index: {\n number_of_replicas: settings.numberOfReplicas,\n refresh_interval: settings.refreshInterval\n }\n }\n });\n } catch (ex) {\n throw new IndexSettingsSetError(ex, index);\n }\n }\n}\n\nexport const IndexSettingsManager = Abstraction.createImplementation({\n implementation: IndexSettingsManagerImpl,\n dependencies: [OpenSearchClient]\n});\n"],"names":["IndexSettingsManagerImpl","openSearchClient","index","response","setting","parseInt","String","ex","IndexSettingsGetError","settings","IndexSettingsSetError","IndexSettingsManager","Abstraction","OpenSearchClient"],"mappings":";;;;AAKA,MAAMA;IACF,YAA6BC,gBAA4C,CAAE;aAA9CA,gBAAgB,GAAhBA;IAA+C;IAE5E,MAAa,YAAYC,KAAa,EAAiC;QACnE,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;gBACnED;YACJ;YAEA,MAAME,UAAUD,SAAS,IAAI,CAACD,MAAM,EAAE,UAAU;YAEhD,OAAO;gBACH,kBAAkBG,SAASC,OAAOF,SAAS,sBAAsB,MAAM;gBACvE,iBAAiBA,SAAS,oBAAoB;YAClD;QACJ,EAAE,OAAOG,IAAI;YACT,MAAM,IAAIC,sBAAsBD,IAAIL;QACxC;IACJ;IAEA,MAAa,YAAYA,KAAa,EAAEO,QAA8B,EAAiB;QACnF,IAAI;YACA,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;gBAClDP;gBACA,MAAM;oBACF,OAAO;wBACH,oBAAoBO,SAAS,gBAAgB;wBAC7C,kBAAkBA,SAAS,eAAe;oBAC9C;gBACJ;YACJ;QACJ,EAAE,OAAOF,IAAI;YACT,MAAM,IAAIG,sBAAsBH,IAAIL;QACxC;IACJ;AACJ;AAEO,MAAMS,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBZ;IAChB,cAAc;QAACa;KAAiB;AACpC"}