@webiny/api-opensearch 6.1.0 → 6.2.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/client.js CHANGED
@@ -6,7 +6,7 @@ export { Client };
6
6
  const clients = new Map();
7
7
  const createClientKey = options => {
8
8
  const key = JSON.stringify(options);
9
- const hash = crypto.createHash("sha1");
9
+ const hash = crypto.createHash("sha256");
10
10
  hash.update(key);
11
11
  return hash.digest("hex");
12
12
  };
package/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["crypto","WebinyError","Client","AwsSigv4Signer","clients","Map","createClientKey","options","key","JSON","stringify","hash","createHash","update","digest","createOpenSearchClient","existing","get","endpoint","node","rest","clientOptions","auth","region","process","env","AWS_REGION","service","getCredentials","accessKeyId","AWS_ACCESS_KEY_ID","secretAccessKey","AWS_SECRET_ACCESS_KEY","sessionToken","AWS_SESSION_TOKEN","Promise","resolve","client","set","ex","data","error","undefined","console"],"sources":["client.ts"],"sourcesContent":["import crypto from \"crypto\";\nimport WebinyError from \"@webiny/error\";\nimport { Client } from \"@opensearch-project/opensearch\";\nimport type { ClientOptions } from \"@opensearch-project/opensearch\";\nimport { AwsSigv4Signer } from \"@opensearch-project/opensearch/aws\";\n\nexport interface OpenSearchClientOptions extends ClientOptions {\n endpoint?: string;\n}\n\nexport { Client };\nexport type { OpenSearchClientOptions as ClientOptions };\n\nconst clients = new Map<string, Client>();\n\nconst createClientKey = (options: OpenSearchClientOptions): string => {\n const key = JSON.stringify(options);\n const hash = crypto.createHash(\"sha1\");\n hash.update(key);\n return hash.digest(\"hex\");\n};\n\nexport const createOpenSearchClient = (options: OpenSearchClientOptions): Client => {\n const key = createClientKey(options);\n const existing = clients.get(key);\n if (existing) {\n return existing;\n }\n\n const { endpoint, node, ...rest } = options;\n\n let clientOptions: ClientOptions = {\n node: endpoint || node,\n ...rest\n };\n\n if (!clientOptions.auth) {\n const region = process.env.AWS_REGION;\n if (!region) {\n throw new WebinyError(\"Missing AWS_REGION environment variable.\", \"MISSING_AWS_REGION\");\n }\n\n clientOptions = {\n ...clientOptions,\n ...AwsSigv4Signer({\n region,\n service: \"es\",\n getCredentials: () => {\n const accessKeyId = process.env.AWS_ACCESS_KEY_ID;\n const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;\n const sessionToken = process.env.AWS_SESSION_TOKEN;\n\n if (!accessKeyId || !secretAccessKey) {\n throw new WebinyError(\n \"Missing AWS credentials (AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY).\",\n \"MISSING_AWS_CREDENTIALS\"\n );\n }\n\n return Promise.resolve({ accessKeyId, secretAccessKey, sessionToken });\n }\n })\n };\n }\n\n try {\n const client = new Client(clientOptions);\n clients.set(key, client);\n return client;\n } catch (ex) {\n const data = {\n error: ex,\n node: endpoint || node,\n ...rest,\n auth: undefined\n };\n console.error(data);\n throw new WebinyError(\"Could not connect to OpenSearch.\", \"OPENSEARCH_CLIENT_ERROR\", data);\n }\n};\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,QAAQ;AAC3B,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,gCAAgC;AAEvD,SAASC,cAAc,QAAQ,oCAAoC;AAMnE,SAASD,MAAM;AAGf,MAAME,OAAO,GAAG,IAAIC,GAAG,CAAiB,CAAC;AAEzC,MAAMC,eAAe,GAAIC,OAAgC,IAAa;EAClE,MAAMC,GAAG,GAAGC,IAAI,CAACC,SAAS,CAACH,OAAO,CAAC;EACnC,MAAMI,IAAI,GAAGX,MAAM,CAACY,UAAU,CAAC,MAAM,CAAC;EACtCD,IAAI,CAACE,MAAM,CAACL,GAAG,CAAC;EAChB,OAAOG,IAAI,CAACG,MAAM,CAAC,KAAK,CAAC;AAC7B,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAIR,OAAgC,IAAa;EAChF,MAAMC,GAAG,GAAGF,eAAe,CAACC,OAAO,CAAC;EACpC,MAAMS,QAAQ,GAAGZ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EF,EAAE;MACTpB,IAAI,EAAED,QAAQ,IAAIC,IAAI;MACtB,GAAGC,IAAI;MACPE,IAAI,EAAEoB;IACV,CAAC;IACDC,OAAO,CAACF,KAAK,CAACD,IAAI,CAAC;IACnB,MAAM,IAAIvC,WAAW,CAAC,kCAAkC,EAAE,yBAAyB,EAAEuC,IAAI,CAAC;EAC9F;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["crypto","WebinyError","Client","AwsSigv4Signer","clients","Map","createClientKey","options","key","JSON","stringify","hash","createHash","update","digest","createOpenSearchClient","existing","get","endpoint","node","rest","clientOptions","auth","region","process","env","AWS_REGION","service","getCredentials","accessKeyId","AWS_ACCESS_KEY_ID","secretAccessKey","AWS_SECRET_ACCESS_KEY","sessionToken","AWS_SESSION_TOKEN","Promise","resolve","client","set","ex","data","error","undefined","console"],"sources":["client.ts"],"sourcesContent":["import crypto from \"crypto\";\nimport WebinyError from \"@webiny/error\";\nimport { Client } from \"@opensearch-project/opensearch\";\nimport type { ClientOptions } from \"@opensearch-project/opensearch\";\nimport { AwsSigv4Signer } from \"@opensearch-project/opensearch/aws\";\n\nexport interface OpenSearchClientOptions extends ClientOptions {\n endpoint?: string;\n}\n\nexport { Client };\nexport type { OpenSearchClientOptions as ClientOptions };\n\nconst clients = new Map<string, Client>();\n\nconst createClientKey = (options: OpenSearchClientOptions): string => {\n const key = JSON.stringify(options);\n const hash = crypto.createHash(\"sha256\");\n hash.update(key);\n return hash.digest(\"hex\");\n};\n\nexport const createOpenSearchClient = (options: OpenSearchClientOptions): Client => {\n const key = createClientKey(options);\n const existing = clients.get(key);\n if (existing) {\n return existing;\n }\n\n const { endpoint, node, ...rest } = options;\n\n let clientOptions: ClientOptions = {\n node: endpoint || node,\n ...rest\n };\n\n if (!clientOptions.auth) {\n const region = process.env.AWS_REGION;\n if (!region) {\n throw new WebinyError(\"Missing AWS_REGION environment variable.\", \"MISSING_AWS_REGION\");\n }\n\n clientOptions = {\n ...clientOptions,\n ...AwsSigv4Signer({\n region,\n service: \"es\",\n getCredentials: () => {\n const accessKeyId = process.env.AWS_ACCESS_KEY_ID;\n const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;\n const sessionToken = process.env.AWS_SESSION_TOKEN;\n\n if (!accessKeyId || !secretAccessKey) {\n throw new WebinyError(\n \"Missing AWS credentials (AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY).\",\n \"MISSING_AWS_CREDENTIALS\"\n );\n }\n\n return Promise.resolve({ accessKeyId, secretAccessKey, sessionToken });\n }\n })\n };\n }\n\n try {\n const client = new Client(clientOptions);\n clients.set(key, client);\n return client;\n } catch (ex) {\n const data = {\n error: ex,\n node: endpoint || node,\n ...rest,\n auth: undefined\n };\n console.error(data);\n throw new WebinyError(\"Could not connect to OpenSearch.\", \"OPENSEARCH_CLIENT_ERROR\", data);\n }\n};\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,QAAQ;AAC3B,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,gCAAgC;AAEvD,SAASC,cAAc,QAAQ,oCAAoC;AAMnE,SAASD,MAAM;AAGf,MAAME,OAAO,GAAG,IAAIC,GAAG,CAAiB,CAAC;AAEzC,MAAMC,eAAe,GAAIC,OAAgC,IAAa;EAClE,MAAMC,GAAG,GAAGC,IAAI,CAACC,SAAS,CAACH,OAAO,CAAC;EACnC,MAAMI,IAAI,GAAGX,MAAM,CAACY,UAAU,CAAC,QAAQ,CAAC;EACxCD,IAAI,CAACE,MAAM,CAACL,GAAG,CAAC;EAChB,OAAOG,IAAI,CAACG,MAAM,CAAC,KAAK,CAAC;AAC7B,CAAC;AAED,OAAO,MAAMC,sBAAsB,GAAIR,OAAgC,IAAa;EAChF,MAAMC,GAAG,GAAGF,eAAe,CAACC,OAAO,CAAC;EACpC,MAAMS,QAAQ,GAAGZ,OAAO,CAACa,GAAG,CAACT,GAAG,CAAC;EACjC,IAAIQ,QAAQ,EAAE;IACV,OAAOA,QAAQ;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EoB;IACV,CAAC;IACDC,OAAO,CAACF,KAAK,CAACD,IAAI,CAAC;IACnB,MAAM,IAAIvC,WAAW,CAAC,kCAAkC,EAAE,yBAAyB,EAAEuC,IAAI,CAAC;EAC9F;AACJ,CAAC","ignoreList":[]}
package/cursors.js CHANGED
@@ -5,7 +5,7 @@ export const encodeCursor = input => {
5
5
  if (!input) {
6
6
  return undefined;
7
7
  }
8
- const cursor = Array.isArray(input) ? input.filter(item => item !== null).map(item => encodeURIComponent(item)) : encodeURIComponent(input);
8
+ const cursor = Array.isArray(input) ? input.filter(item => item != null).map(item => encodeURIComponent(item)) : encodeURIComponent(input);
9
9
  try {
10
10
  return Buffer.from(JSON.stringify(cursor)).toString("base64");
11
11
  } catch (ex) {
package/cursors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["encodeCursor","input","undefined","cursor","Array","isArray","filter","item","map","encodeURIComponent","Buffer","from","JSON","stringify","toString","ex","console","error","message","decodeCursor","value","parse","decodeURIComponent","decoded"],"sources":["cursors.ts"],"sourcesContent":["import type { PrimitiveValue } from \"~/types.js\";\n\n/**\n * Encode a received cursor value into something that can be passed on to the user.\n */\nexport const encodeCursor = (input?: PrimitiveValue[]): string | undefined => {\n if (!input) {\n return undefined;\n }\n\n const cursor = Array.isArray(input)\n ? input\n .filter((item: PrimitiveValue): item is string | number | boolean => item !== null)\n .map(item => encodeURIComponent(item))\n : encodeURIComponent(input);\n\n try {\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n } catch (ex) {\n console.error(ex.message);\n }\n return undefined;\n};\n/**\n * Decode a received value into an OpenSearch cursor.\n * If no value is received or is not decodable, return undefined.\n */\nexport const decodeCursor = (cursor?: string | null): PrimitiveValue[] | undefined => {\n if (!cursor) {\n return undefined;\n }\n try {\n const value = JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n if (Array.isArray(value)) {\n return value.filter(item => item !== null).map(decodeURIComponent);\n }\n const decoded = decodeURIComponent(value);\n return decoded ? [decoded] : undefined;\n } catch (ex) {\n console.error(ex.message);\n }\n return undefined;\n};\n"],"mappings":"AAEA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAIC,KAAwB,IAAyB;EAC1E,IAAI,CAACA,KAAK,EAAE;IACR,OAAOC,SAAS;EACpB;EAEA,MAAMC,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,GAC7BA,KAAK,CACAK,MAAM,CAAEC,IAAoB,IAAwCA,IAAI,KAAK,IAAI,CAAC,CAClFC,GAAG,CAACD,IAAI,IAAIE,kBAAkB,CAACF,IAAI,CAAC,CAAC,GAC1CE,kBAAkB,CAACR,KAAK,CAAC;EAE/B,IAAI;IACA,OAAOS,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACV,MAAM,CAAC,CAAC,CAACW,QAAQ,CAAC,QAAQ,CAAC;EACjE,CAAC,CAAC,OAAOC,EAAE,EAAE;IACTC,OAAO,CAACC,KAAK,CAACF,EAAE,CAACG,OAAO,CAAC;EAC7B;EACA,OAAOhB,SAAS;AACpB,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMiB,YAAY,GAAIhB,MAAsB,IAAmC;EAClF,IAAI,CAACA,MAAM,EAAE;IACT,OAAOD,SAAS;EACpB;EACA,IAAI;IACA,MAAMkB,KAAK,GAAGR,IAAI,CAACS,KAAK,CAACX,MAAM,CAACC,IAAI,CAACR,MAAM,EAAE,QAAQ,CAAC,CAACW,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzE,IAAIV,KAAK,CAACC,OAAO,CAACe,KAAK,CAAC,EAAE;MACtB,OAAOA,KAAK,CAACd,MAAM,CAACC,IAAI,IAAIA,IAAI,KAAK,IAAI,CAAC,CAACC,GAAG,CAACc,kBAAkB,CAAC;IACtE;IACA,MAAMC,OAAO,GAAGD,kBAAkB,CAACF,KAAK,CAAC;IACzC,OAAOG,OAAO,GAAG,CAACA,OAAO,CAAC,GAAGrB,SAAS;EAC1C,CAAC,CAAC,OAAOa,EAAE,EAAE;IACTC,OAAO,CAACC,KAAK,CAACF,EAAE,CAACG,OAAO,CAAC;EAC7B;EACA,OAAOhB,SAAS;AACpB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["encodeCursor","input","undefined","cursor","Array","isArray","filter","item","map","encodeURIComponent","Buffer","from","JSON","stringify","toString","ex","console","error","message","decodeCursor","value","parse","decodeURIComponent","decoded"],"sources":["cursors.ts"],"sourcesContent":["import type { PrimitiveValue } from \"~/types.js\";\n\n/**\n * Encode a received cursor value into something that can be passed on to the user.\n */\nexport const encodeCursor = (input?: PrimitiveValue[]): string | undefined => {\n if (!input) {\n return undefined;\n }\n\n const cursor = Array.isArray(input)\n ? input\n .filter((item: PrimitiveValue): item is string | number | boolean => item != null)\n .map(item => encodeURIComponent(item))\n : encodeURIComponent(input);\n\n try {\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n } catch (ex) {\n console.error(ex.message);\n }\n return undefined;\n};\n/**\n * Decode a received value into an OpenSearch cursor.\n * If no value is received or is not decodable, return undefined.\n */\nexport const decodeCursor = (cursor?: string | null): PrimitiveValue[] | undefined => {\n if (!cursor) {\n return undefined;\n }\n try {\n const value = JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n if (Array.isArray(value)) {\n return value.filter(item => item !== null).map(decodeURIComponent);\n }\n const decoded = decodeURIComponent(value);\n return decoded ? [decoded] : undefined;\n } catch (ex) {\n console.error(ex.message);\n }\n return undefined;\n};\n"],"mappings":"AAEA;AACA;AACA;AACA,OAAO,MAAMA,YAAY,GAAIC,KAAwB,IAAyB;EAC1E,IAAI,CAACA,KAAK,EAAE;IACR,OAAOC,SAAS;EACpB;EAEA,MAAMC,MAAM,GAAGC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,GAC7BA,KAAK,CACAK,MAAM,CAAEC,IAAoB,IAAwCA,IAAI,IAAI,IAAI,CAAC,CACjFC,GAAG,CAACD,IAAI,IAAIE,kBAAkB,CAACF,IAAI,CAAC,CAAC,GAC1CE,kBAAkB,CAACR,KAAK,CAAC;EAE/B,IAAI;IACA,OAAOS,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACV,MAAM,CAAC,CAAC,CAACW,QAAQ,CAAC,QAAQ,CAAC;EACjE,CAAC,CAAC,OAAOC,EAAE,EAAE;IACTC,OAAO,CAACC,KAAK,CAACF,EAAE,CAACG,OAAO,CAAC;EAC7B;EACA,OAAOhB,SAAS;AACpB,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMiB,YAAY,GAAIhB,MAAsB,IAAmC;EAClF,IAAI,CAACA,MAAM,EAAE;IACT,OAAOD,SAAS;EACpB;EACA,IAAI;IACA,MAAMkB,KAAK,GAAGR,IAAI,CAACS,KAAK,CAACX,MAAM,CAACC,IAAI,CAACR,MAAM,EAAE,QAAQ,CAAC,CAACW,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzE,IAAIV,KAAK,CAACC,OAAO,CAACe,KAAK,CAAC,EAAE;MACtB,OAAOA,KAAK,CAACd,MAAM,CAACC,IAAI,IAAIA,IAAI,KAAK,IAAI,CAAC,CAACC,GAAG,CAACc,kBAAkB,CAAC;IACtE;IACA,MAAMC,OAAO,GAAGD,kBAAkB,CAACF,KAAK,CAAC;IACzC,OAAOG,OAAO,GAAG,CAACA,OAAO,CAAC,GAAGrB,SAAS;EAC1C,CAAC,CAAC,OAAOa,EAAE,EAAE;IACTC,OAAO,CAACC,KAAK,CAACF,EAAE,CAACG,OAAO,CAAC;EAC7B;EACA,OAAOhB,SAAS;AACpB,CAAC","ignoreList":[]}
package/index.d.ts CHANGED
@@ -9,7 +9,6 @@ export * from "./indices.js";
9
9
  export * from "./where.js";
10
10
  export * from "./limit.js";
11
11
  export * from "./normalize.js";
12
- export * from "./compression.js";
13
12
  export * from "./operators.js";
14
13
  export * from "./cursors.js";
15
14
  export { createOpenSearchClient, type Client, type ClientOptions, type OpenSearchClientOptions } from "./client.js";
package/index.js CHANGED
@@ -11,7 +11,6 @@ export * from "./indices.js";
11
11
  export * from "./where.js";
12
12
  export * from "./limit.js";
13
13
  export * from "./normalize.js";
14
- export * from "./compression.js";
15
14
  export * from "./operators.js";
16
15
  export * from "./cursors.js";
17
16
  export { createOpenSearchClient } from "./client.js";
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ContextPlugin","Client","createOpenSearchClient","getOpenSearchOperators","OpenSearchClientFactoryFeature","OpenSearchClientFeature","OpenSearchContextFeature","createOpenSearchContext","params","plugin","context","opensearch","Error","client","elasticsearch","plugins","register","container","name"],"sources":["index.ts"],"sourcesContent":["import type { OpenSearchContext } from \"./types.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type { OpenSearchClientOptions } from \"./client.js\";\nimport { Client, createOpenSearchClient } from \"./client.js\";\nimport { getOpenSearchOperators } from \"./operators.js\";\nimport { OpenSearchClientFactoryFeature } from \"./features/OpenSearchClientFactory/feature.js\";\nimport { OpenSearchClientFeature } from \"./features/OpenSearchClient/feature.js\";\nimport { OpenSearchContextFeature } from \"~/features/OpenSearchContext/feature.js\";\n\nexport * from \"./indexConfiguration/index.js\";\nexport * from \"./plugins/index.js\";\nexport * from \"./sort.js\";\nexport * from \"./indices.js\";\nexport * from \"./where.js\";\nexport * from \"./limit.js\";\nexport * from \"./normalize.js\";\nexport * from \"./compression.js\";\nexport * from \"./operators.js\";\nexport * from \"./cursors.js\";\nexport {\n createOpenSearchClient,\n type Client,\n type ClientOptions,\n type OpenSearchClientOptions\n} from \"./client.js\";\nexport * from \"./utils/index.js\";\nexport * from \"./operations/index.js\";\nexport * from \"./sharedIndex.js\";\nexport * from \"./indexPrefix.js\";\nexport * from \"./db/index.js\";\nexport * from \"./types.js\";\n\nexport const createOpenSearchContext = (\n params: OpenSearchClientOptions | Client\n): ContextPlugin<OpenSearchContext> => {\n const plugin = new ContextPlugin<OpenSearchContext>(context => {\n if (context.opensearch) {\n throw new Error(\"OpenSearch context must not be loaded more than once!\");\n }\n const client = params instanceof Client ? params : createOpenSearchClient(params);\n context.opensearch = client;\n context.elasticsearch = client;\n\n context.plugins.register(getOpenSearchOperators());\n\n OpenSearchContextFeature.register(context.container, context);\n OpenSearchClientFeature.register(context.container);\n OpenSearchClientFactoryFeature.register(context.container);\n });\n\n plugin.name = \"context.opensearch\";\n\n return plugin;\n};\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,aAAa;AAE3C,SAASC,MAAM,EAAEC,sBAAsB;AACvC,SAASC,sBAAsB;AAC/B,SAASC,8BAA8B;AACvC,SAASC,uBAAuB;AAChC,SAASC,wBAAwB;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACIJ,sBAAsB;AAK1B;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMK,uBAAuB,GAChCC,MAAwC,IACL;EACnC,MAAMC,MAAM,GAAG,IAAIT,aAAa,CAAoBU,OAAO,IAAI;IAC3D,IAAIA,OAAO,CAACC,UAAU,EAAE;MACpB,MAAM,IAAIC,KAAK,CAAC,uDAAuD,CAAC;IAC5E;IACA,MAAMC,MAAM,GAAGL,MAAM,YAAYP,MAAM,GAAGO,MAAM,GAAGN,sBAAsB,CAACM,MAAM,CAAC;IACjFE,OAAO,CAACC,UAAU,GAAGE,MAAM;IAC3BH,OAAO,CAACI,aAAa,GAAGD,MAAM;IAE9BH,OAAO,CAACK,OAAO,CAACC,QAAQ,CAACb,sBAAsB,CAAC,CAAC,CAAC;IAElDG,wBAAwB,CAACU,QAAQ,CAACN,OAAO,CAACO,SAAS,EAAEP,OAAO,CAAC;IAC7DL,uBAAuB,CAACW,QAAQ,CAACN,OAAO,CAACO,SAAS,CAAC;IACnDb,8BAA8B,CAACY,QAAQ,CAACN,OAAO,CAACO,SAAS,CAAC;EAC9D,CAAC,CAAC;EAEFR,MAAM,CAACS,IAAI,GAAG,oBAAoB;EAElC,OAAOT,MAAM;AACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["ContextPlugin","Client","createOpenSearchClient","getOpenSearchOperators","OpenSearchClientFactoryFeature","OpenSearchClientFeature","OpenSearchContextFeature","createOpenSearchContext","params","plugin","context","opensearch","Error","client","elasticsearch","plugins","register","container","name"],"sources":["index.ts"],"sourcesContent":["import type { OpenSearchContext } from \"./types.js\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport type { OpenSearchClientOptions } from \"./client.js\";\nimport { Client, createOpenSearchClient } from \"./client.js\";\nimport { getOpenSearchOperators } from \"./operators.js\";\nimport { OpenSearchClientFactoryFeature } from \"./features/OpenSearchClientFactory/feature.js\";\nimport { OpenSearchClientFeature } from \"./features/OpenSearchClient/feature.js\";\nimport { OpenSearchContextFeature } from \"~/features/OpenSearchContext/feature.js\";\n\nexport * from \"./indexConfiguration/index.js\";\nexport * from \"./plugins/index.js\";\nexport * from \"./sort.js\";\nexport * from \"./indices.js\";\nexport * from \"./where.js\";\nexport * from \"./limit.js\";\nexport * from \"./normalize.js\";\nexport * from \"./operators.js\";\nexport * from \"./cursors.js\";\nexport {\n createOpenSearchClient,\n type Client,\n type ClientOptions,\n type OpenSearchClientOptions\n} from \"./client.js\";\nexport * from \"./utils/index.js\";\nexport * from \"./operations/index.js\";\nexport * from \"./sharedIndex.js\";\nexport * from \"./indexPrefix.js\";\nexport * from \"./db/index.js\";\nexport * from \"./types.js\";\n\nexport const createOpenSearchContext = (\n params: OpenSearchClientOptions | Client\n): ContextPlugin<OpenSearchContext> => {\n const plugin = new ContextPlugin<OpenSearchContext>(context => {\n if (context.opensearch) {\n throw new Error(\"OpenSearch context must not be loaded more than once!\");\n }\n const client = params instanceof Client ? params : createOpenSearchClient(params);\n context.opensearch = client;\n context.elasticsearch = client;\n\n context.plugins.register(getOpenSearchOperators());\n\n OpenSearchContextFeature.register(context.container, context);\n OpenSearchClientFeature.register(context.container);\n OpenSearchClientFactoryFeature.register(context.container);\n });\n\n plugin.name = \"context.opensearch\";\n\n return plugin;\n};\n"],"mappings":"AACA,SAASA,aAAa,QAAQ,aAAa;AAE3C,SAASC,MAAM,EAAEC,sBAAsB;AACvC,SAASC,sBAAsB;AAC/B,SAASC,8BAA8B;AACvC,SAASC,uBAAuB;AAChC,SAASC,wBAAwB;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACIJ,sBAAsB;AAK1B;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMK,uBAAuB,GAChCC,MAAwC,IACL;EACnC,MAAMC,MAAM,GAAG,IAAIT,aAAa,CAAoBU,OAAO,IAAI;IAC3D,IAAIA,OAAO,CAACC,UAAU,EAAE;MACpB,MAAM,IAAIC,KAAK,CAAC,uDAAuD,CAAC;IAC5E;IACA,MAAMC,MAAM,GAAGL,MAAM,YAAYP,MAAM,GAAGO,MAAM,GAAGN,sBAAsB,CAACM,MAAM,CAAC;IACjFE,OAAO,CAACC,UAAU,GAAGE,MAAM;IAC3BH,OAAO,CAACI,aAAa,GAAGD,MAAM;IAE9BH,OAAO,CAACK,OAAO,CAACC,QAAQ,CAACb,sBAAsB,CAAC,CAAC,CAAC;IAElDG,wBAAwB,CAACU,QAAQ,CAACN,OAAO,CAACO,SAAS,EAAEP,OAAO,CAAC;IAC7DL,uBAAuB,CAACW,QAAQ,CAACN,OAAO,CAACO,SAAS,CAAC;IACnDb,8BAA8B,CAACY,QAAQ,CAACN,OAAO,CAACO,SAAS,CAAC;EAC9D,CAAC,CAAC;EAEFR,MAAM,CAACS,IAAI,GAAG,oBAAoB;EAElC,OAAOT,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -2,5 +2,5 @@ import type { OpenSearchIndexRequestBody } from "../types.js";
2
2
  interface Modifier {
3
3
  (config: OpenSearchIndexRequestBody): OpenSearchIndexRequestBody;
4
4
  }
5
- export declare const getBaseConfiguration: (modifier?: Modifier) => OpenSearchIndexRequestBody;
5
+ export declare const getBaseConfiguration: (modifier?: Modifier) => import("@opensearch-project/opensearch/api/index.js").Indices_Create_RequestBody;
6
6
  export {};
@@ -3,14 +3,11 @@ const getDefaultMappings = () => {
3
3
  ids: {
4
4
  match: "^id|entryId$",
5
5
  mapping: {
6
- type: "string",
7
- keyword: true
6
+ type: "keyword"
8
7
  }
9
8
  }
10
9
  }, {
11
- /**
12
- * Update with the correct date fields.
13
- */
10
+ /* Update with the correct date fields. */
14
11
  dates: {
15
12
  match: "^createdOn|savedOn|publishedOn$",
16
13
  mapping: {
@@ -1 +1 @@
1
- {"version":3,"names":["getDefaultMappings","ids","match","mapping","type","keyword","dates","numbers","scaling_factor","booleans","getCommonMappings","cb"],"sources":["common.ts"],"sourcesContent":["import type { OpenSearchIndexRequestBodyMappingsDynamicTemplate } from \"~/types.js\";\n\nconst getDefaultMappings = (): OpenSearchIndexRequestBodyMappingsDynamicTemplate[] => {\n return [\n {\n ids: {\n match: \"^id|entryId$\",\n mapping: {\n type: \"string\",\n keyword: true\n }\n }\n },\n {\n /**\n * Update with the correct date fields.\n */\n dates: {\n match: \"^createdOn|savedOn|publishedOn$\",\n mapping: {\n type: \"date\"\n }\n }\n },\n {\n numbers: {\n match: \"number@*\",\n mapping: {\n type: \"scaled_float\",\n scaling_factor: 10000\n }\n }\n },\n {\n booleans: {\n match: \"boolean@*\",\n mapping: {\n type: \"boolean\"\n }\n }\n }\n ];\n};\n\ninterface Modifier {\n (\n mappings: OpenSearchIndexRequestBodyMappingsDynamicTemplate[]\n ): OpenSearchIndexRequestBodyMappingsDynamicTemplate[];\n}\n/**\n * @internal\n */\nexport const getCommonMappings = (\n cb?: Modifier\n): OpenSearchIndexRequestBodyMappingsDynamicTemplate[] => {\n if (!cb) {\n return getDefaultMappings();\n }\n\n return cb(getDefaultMappings());\n};\n"],"mappings":"AAEA,MAAMA,kBAAkB,GAAGA,CAAA,KAA2D;EAClF,OAAO,CACH;IACIC,GAAG,EAAE;MACDC,KAAK,EAAE,cAAc;MACrBC,OAAO,EAAE;QACLC,IAAI,EAAE,QAAQ;QACdC,OAAO,EAAE;MACb;IACJ;EACJ,CAAC,EACD;IACI;AACZ;AACA;IACYC,KAAK,EAAE;MACHJ,KAAK,EAAE,iCAAiC;MACxCC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,EACD;IACIG,OAAO,EAAE;MACLL,KAAK,EAAE,UAAU;MACjBC,OAAO,EAAE;QACLC,IAAI,EAAE,cAAc;QACpBI,cAAc,EAAE;MACpB;IACJ;EACJ,CAAC,EACD;IACIC,QAAQ,EAAE;MACNP,KAAK,EAAE,WAAW;MAClBC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CACJ;AACL,CAAC;AAOD;AACA;AACA;AACA,OAAO,MAAMM,iBAAiB,GAC1BC,EAAa,IACyC;EACtD,IAAI,CAACA,EAAE,EAAE;IACL,OAAOX,kBAAkB,CAAC,CAAC;EAC/B;EAEA,OAAOW,EAAE,CAACX,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["getDefaultMappings","ids","match","mapping","type","dates","numbers","scaling_factor","booleans","getCommonMappings","cb"],"sources":["common.ts"],"sourcesContent":["import type { OpenSearchIndexRequestBodyMappingsDynamicTemplate } from \"~/types.js\";\n\nconst getDefaultMappings = (): OpenSearchIndexRequestBodyMappingsDynamicTemplate[] => {\n return [\n {\n ids: {\n match: \"^id|entryId$\",\n mapping: {\n type: \"keyword\"\n }\n }\n },\n {\n /* Update with the correct date fields. */\n dates: {\n match: \"^createdOn|savedOn|publishedOn$\",\n mapping: {\n type: \"date\"\n }\n }\n },\n {\n numbers: {\n match: \"number@*\",\n mapping: {\n type: \"scaled_float\",\n scaling_factor: 10000\n }\n }\n },\n {\n booleans: {\n match: \"boolean@*\",\n mapping: {\n type: \"boolean\"\n }\n }\n }\n ];\n};\n\ninterface Modifier {\n (\n mappings: OpenSearchIndexRequestBodyMappingsDynamicTemplate[]\n ): OpenSearchIndexRequestBodyMappingsDynamicTemplate[];\n}\n/**\n * @internal\n */\nexport const getCommonMappings = (\n cb?: Modifier\n): OpenSearchIndexRequestBodyMappingsDynamicTemplate[] => {\n if (!cb) {\n return getDefaultMappings();\n }\n\n return cb(getDefaultMappings());\n};\n"],"mappings":"AAEA,MAAMA,kBAAkB,GAAGA,CAAA,KAA2D;EAClF,OAAO,CACH;IACIC,GAAG,EAAE;MACDC,KAAK,EAAE,cAAc;MACrBC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,EACD;IACI;IACAC,KAAK,EAAE;MACHH,KAAK,EAAE,iCAAiC;MACxCC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,EACD;IACIE,OAAO,EAAE;MACLJ,KAAK,EAAE,UAAU;MACjBC,OAAO,EAAE;QACLC,IAAI,EAAE,cAAc;QACpBG,cAAc,EAAE;MACpB;IACJ;EACJ,CAAC,EACD;IACIC,QAAQ,EAAE;MACNN,KAAK,EAAE,WAAW;MAClBC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CACJ;AACL,CAAC;AAOD;AACA;AACA;AACA,OAAO,MAAMK,iBAAiB,GAC1BC,EAAa,IACyC;EACtD,IAAI,CAACA,EAAE,EAAE;IACL,OAAOV,kBAAkB,CAAC,CAAC;EAC/B;EAEA,OAAOU,EAAE,CAACV,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","stripConnectionFromException","OpenSearchCatHealth","constructor","client","getHealth","response","cat","health","format","Array","isArray","body","length","message","code","data","ex","console","error","log","JSON","stringify"],"sources":["OpenSearchCatHealth.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { Client } from \"~/client.js\";\nimport type { IOpenSearchCatHealthResponse } from \"./types.js\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatHealth {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getHealth(): Promise<IOpenSearchCatHealthResponse> {\n try {\n const response = await this.client.cat.health<unknown | [IOpenSearchCatHealthResponse]>(\n {\n format: \"json\"\n }\n );\n\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.health operation.`,\n code: \"OPENSEARCH_HEALTH_INVALID_RESPONSE\",\n data: response.body\n });\n }\n\n return {\n ...response.body[0]\n };\n } catch (ex) {\n console.error(`Could not fetch cluster health information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,eAAe;AAG3C,SAASC,4BAA4B;AAErC,OAAO,MAAMC,mBAAmB,CAAC;EAGtBC,WAAWA,CAACC,MAAc,EAAE;IAC/B,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAaC,SAASA,CAAA,EAA0C;IAC5D,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACF,MAAM,CAACG,GAAG,CAACC,MAAM,CACzC;QACIC,MAAM,EAAE;MACZ,CACJ,CAAC;MAED,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,QAAQ,CAACM,IAAI,CAAC,IAAIN,QAAQ,CAACM,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE;QAC7D,MAAM,IAAIb,WAAW,CAAC;UAClBc,OAAO,EAAE,uDAAuD;UAChEC,IAAI,EAAE,oCAAoC;UAC1CC,IAAI,EAAEV,QAAQ,CAACM;QACnB,CAAC,CAAC;MACN;MAEA,OAAO;QACH,GAAGN,QAAQ,CAACM,IAAI,CAAC,CAAC;MACtB,CAAC;IACL,CAAC,CAAC,OAAOK,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,+CAA+CF,EAAE,CAACH,OAAO,EAAE,CAAC;MAC1E,MAAMK,KAAK,GAAGlB,4BAA4B,CAACgB,EAAE,CAAC;MAC9CC,OAAO,CAACE,GAAG,CAACC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC,CAAC;MAClC,MAAMA,KAAK;IACf;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","stripConnectionFromException","OpenSearchCatHealth","constructor","client","getHealth","response","cat","health","format","Array","isArray","body","length","message","code","data","ex","console","error","log","JSON","stringify"],"sources":["OpenSearchCatHealth.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport type { Client } from \"~/client.js\";\nimport type { IOpenSearchCatHealthResponse } from \"./types.js\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatHealth {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getHealth(): Promise<IOpenSearchCatHealthResponse> {\n try {\n const response = await this.client.cat.health({\n format: \"json\"\n });\n\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.health operation.`,\n code: \"OPENSEARCH_HEALTH_INVALID_RESPONSE\",\n data: response.body\n });\n }\n\n return {\n ...response.body[0]\n };\n } catch (ex) {\n console.error(`Could not fetch cluster health information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,eAAe;AAG3C,SAASC,4BAA4B;AAErC,OAAO,MAAMC,mBAAmB,CAAC;EAGtBC,WAAWA,CAACC,MAAc,EAAE;IAC/B,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAaC,SAASA,CAAA,EAA0C;IAC5D,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACF,MAAM,CAACG,GAAG,CAACC,MAAM,CAAC;QAC1CC,MAAM,EAAE;MACZ,CAAC,CAAC;MAEF,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,QAAQ,CAACM,IAAI,CAAC,IAAIN,QAAQ,CAACM,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE;QAC7D,MAAM,IAAIb,WAAW,CAAC;UAClBc,OAAO,EAAE,uDAAuD;UAChEC,IAAI,EAAE,oCAAoC;UAC1CC,IAAI,EAAEV,QAAQ,CAACM;QACnB,CAAC,CAAC;MACN;MAEA,OAAO;QACH,GAAGN,QAAQ,CAACM,IAAI,CAAC,CAAC;MACtB,CAAC;IACL,CAAC,CAAC,OAAOK,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,+CAA+CF,EAAE,CAACH,OAAO,EAAE,CAAC;MAC1E,MAAMK,KAAK,GAAGlB,4BAA4B,CAACgB,EAAE,CAAC;MAC9CC,OAAO,CAACE,GAAG,CAACC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC,CAAC;MAClC,MAAMA,KAAK;IACf;EACJ;AACJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","stripConnectionFromException","OpenSearchCatNodes","constructor","client","getNodes","response","cat","nodes","format","Array","isArray","body","length","message","code","data","ex","console","error","log","JSON","stringify"],"sources":["OpenSearchCatNodes.ts"],"sourcesContent":["import type { IOpenSearchCatNodesResponse } from \"./types.js\";\nimport type { Client } from \"~/client.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatNodes {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getNodes(): Promise<IOpenSearchCatNodesResponse> {\n try {\n const response = await this.client.cat.nodes<IOpenSearchCatNodesResponse>({\n format: \"json\"\n });\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.nodes operation.`,\n code: \"OPENSEARCH_NODES_INVALID_RESPONSE\",\n data: response.body\n });\n }\n return response.body;\n } catch (ex) {\n console.error(`Could not fetch cluster nodes information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"mappings":"AAEA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,4BAA4B;AAErC,OAAO,MAAMC,kBAAkB,CAAC;EAGrBC,WAAWA,CAACC,MAAc,EAAE;IAC/B,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAaC,QAAQA,CAAA,EAAyC;IAC1D,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACF,MAAM,CAACG,GAAG,CAACC,KAAK,CAA8B;QACtEC,MAAM,EAAE;MACZ,CAAC,CAAC;MACF,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,QAAQ,CAACM,IAAI,CAAC,IAAIN,QAAQ,CAACM,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE;QAC7D,MAAM,IAAIb,WAAW,CAAC;UAClBc,OAAO,EAAE,sDAAsD;UAC/DC,IAAI,EAAE,mCAAmC;UACzCC,IAAI,EAAEV,QAAQ,CAACM;QACnB,CAAC,CAAC;MACN;MACA,OAAON,QAAQ,CAACM,IAAI;IACxB,CAAC,CAAC,OAAOK,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,8CAA8CF,EAAE,CAACH,OAAO,EAAE,CAAC;MACzE,MAAMK,KAAK,GAAGlB,4BAA4B,CAACgB,EAAE,CAAC;MAC9CC,OAAO,CAACE,GAAG,CAACC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC,CAAC;MAClC,MAAMA,KAAK;IACf;EACJ;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","stripConnectionFromException","OpenSearchCatNodes","constructor","client","getNodes","response","cat","nodes","format","Array","isArray","body","length","message","code","data","ex","console","error","log","JSON","stringify"],"sources":["OpenSearchCatNodes.ts"],"sourcesContent":["import type { IOpenSearchCatNodesResponse } from \"./types.js\";\nimport type { Client } from \"~/client.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { stripConnectionFromException } from \"~/operations/stripConnectionFromException.js\";\n\nexport class OpenSearchCatNodes {\n private readonly client: Client;\n\n public constructor(client: Client) {\n this.client = client;\n }\n\n public async getNodes(): Promise<IOpenSearchCatNodesResponse> {\n try {\n const response = await this.client.cat.nodes({\n format: \"json\"\n });\n if (!Array.isArray(response.body) || response.body.length === 0) {\n throw new WebinyError({\n message: `There is no valid response from cat.nodes operation.`,\n code: \"OPENSEARCH_NODES_INVALID_RESPONSE\",\n data: response.body\n });\n }\n return response.body;\n } catch (ex) {\n console.error(`Could not fetch cluster nodes information: ${ex.message}`);\n const error = stripConnectionFromException(ex);\n console.log(JSON.stringify(error));\n throw error;\n }\n }\n}\n"],"mappings":"AAEA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,4BAA4B;AAErC,OAAO,MAAMC,kBAAkB,CAAC;EAGrBC,WAAWA,CAACC,MAAc,EAAE;IAC/B,IAAI,CAACA,MAAM,GAAGA,MAAM;EACxB;EAEA,MAAaC,QAAQA,CAAA,EAAyC;IAC1D,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACF,MAAM,CAACG,GAAG,CAACC,KAAK,CAAC;QACzCC,MAAM,EAAE;MACZ,CAAC,CAAC;MACF,IAAI,CAACC,KAAK,CAACC,OAAO,CAACL,QAAQ,CAACM,IAAI,CAAC,IAAIN,QAAQ,CAACM,IAAI,CAACC,MAAM,KAAK,CAAC,EAAE;QAC7D,MAAM,IAAIb,WAAW,CAAC;UAClBc,OAAO,EAAE,sDAAsD;UAC/DC,IAAI,EAAE,mCAAmC;UACzCC,IAAI,EAAEV,QAAQ,CAACM;QACnB,CAAC,CAAC;MACN;MACA,OAAON,QAAQ,CAACM,IAAI;IACxB,CAAC,CAAC,OAAOK,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,8CAA8CF,EAAE,CAACH,OAAO,EAAE,CAAC;MACzE,MAAMK,KAAK,GAAGlB,4BAA4B,CAACgB,EAAE,CAAC;MAC9CC,OAAO,CAACE,GAAG,CAACC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC,CAAC;MAClC,MAAMA,KAAK;IACf;EACJ;AACJ","ignoreList":[]}
@@ -1,35 +1,10 @@
1
+ import type { HealthRecord } from "@opensearch-project/opensearch/api/_types/cat.health";
2
+ import type { NodesRecord } from "@opensearch-project/opensearch/api/_types/cat.nodes";
1
3
  export declare enum OpenSearchCatClusterHealthStatus {
2
4
  Green = "green",
3
5
  Yellow = "yellow",
4
6
  Red = "red"
5
7
  }
6
- export interface IOpenSearchCatHealthResponse {
7
- epoch: number;
8
- timestamp: `${number}:${number}:${number}`;
9
- cluster: string;
10
- status: OpenSearchCatClusterHealthStatus;
11
- "node.total": `${number}`;
12
- "node.data": `${number}`;
13
- shards: `${number}`;
14
- pri: `${number}`;
15
- relo: `${number}`;
16
- init: `${number}`;
17
- unassign: `${number}`;
18
- pending_tasks: `${number}`;
19
- max_task_wait_time: string;
20
- active_shards_percent: `${number}%`;
21
- discovered_cluster_manager?: `${boolean}`;
22
- }
23
- export interface IOpenSearchCatNodeResponse {
24
- ip: string;
25
- "heap.percent": `${number}`;
26
- "ram.percent": `${number}`;
27
- cpu: `${number}`;
28
- load_1m: `${number}` | null;
29
- load_5m: `${number}` | null;
30
- load_15m: `${number}` | null;
31
- "node.role": string;
32
- master?: string;
33
- name: string;
34
- }
8
+ export type IOpenSearchCatHealthResponse = HealthRecord;
9
+ export type IOpenSearchCatNodeResponse = NodesRecord;
35
10
  export type IOpenSearchCatNodesResponse = IOpenSearchCatNodeResponse[];
@@ -1 +1 @@
1
- {"version":3,"names":["OpenSearchCatClusterHealthStatus"],"sources":["types.ts"],"sourcesContent":["export enum OpenSearchCatClusterHealthStatus {\n Green = \"green\",\n Yellow = \"yellow\",\n Red = \"red\"\n}\n\nexport interface IOpenSearchCatHealthResponse {\n epoch: number;\n timestamp: `${number}:${number}:${number}`;\n cluster: string;\n status: OpenSearchCatClusterHealthStatus;\n \"node.total\": `${number}`;\n \"node.data\": `${number}`;\n shards: `${number}`;\n pri: `${number}`;\n relo: `${number}`;\n init: `${number}`;\n unassign: `${number}`;\n pending_tasks: `${number}`;\n max_task_wait_time: string;\n active_shards_percent: `${number}%`;\n discovered_cluster_manager?: `${boolean}`;\n}\n\nexport interface IOpenSearchCatNodeResponse {\n ip: string;\n \"heap.percent\": `${number}`;\n \"ram.percent\": `${number}`;\n cpu: `${number}`;\n load_1m: `${number}` | null;\n load_5m: `${number}` | null;\n load_15m: `${number}` | null;\n \"node.role\": string;\n master?: string;\n name: string;\n}\n\nexport type IOpenSearchCatNodesResponse = IOpenSearchCatNodeResponse[];\n"],"mappings":"AAAA,WAAYA,gCAAgC,0BAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAA,OAAhCA,gCAAgC;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["OpenSearchCatClusterHealthStatus"],"sources":["types.ts"],"sourcesContent":["import type { HealthRecord } from \"@opensearch-project/opensearch/api/_types/cat.health\";\nimport type { NodesRecord } from \"@opensearch-project/opensearch/api/_types/cat.nodes\";\n\nexport enum OpenSearchCatClusterHealthStatus {\n Green = \"green\",\n Yellow = \"yellow\",\n Red = \"red\"\n}\n\nexport type IOpenSearchCatHealthResponse = HealthRecord;\n\nexport type IOpenSearchCatNodeResponse = NodesRecord;\n\nexport type IOpenSearchCatNodesResponse = IOpenSearchCatNodeResponse[];\n"],"mappings":"AAGA,WAAYA,gCAAgC,0BAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAhCA,gCAAgC;EAAA,OAAhCA,gCAAgC;AAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-opensearch",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,24 +13,24 @@
13
13
  ],
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@opensearch-project/opensearch": "2.13.0",
17
- "@webiny/api": "6.1.0",
18
- "@webiny/aws-sdk": "6.1.0",
19
- "@webiny/db-dynamodb": "6.1.0",
20
- "@webiny/error": "6.1.0",
21
- "@webiny/feature": "6.1.0",
22
- "@webiny/plugins": "6.1.0"
16
+ "@opensearch-project/opensearch": "3.5.1",
17
+ "@webiny/api": "6.2.0",
18
+ "@webiny/aws-sdk": "6.2.0",
19
+ "@webiny/db-dynamodb": "6.2.0",
20
+ "@webiny/error": "6.2.0",
21
+ "@webiny/feature": "6.2.0",
22
+ "@webiny/plugins": "6.2.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@webiny/build-tools": "6.1.0",
26
- "@webiny/project-utils": "6.1.0",
25
+ "@webiny/build-tools": "6.2.0",
26
+ "@webiny/project-utils": "6.2.0",
27
27
  "rimraf": "6.1.3",
28
28
  "typescript": "5.9.3",
29
- "vitest": "4.1.2"
29
+ "vitest": "4.1.4"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public",
33
33
  "directory": "dist"
34
34
  },
35
- "gitHead": "65e0ac1889b3392c99b8cac6cde508e1e831c715"
35
+ "gitHead": "3d3148358b6febbc857371930871743bec3b3939"
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Plugin","keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","OpenSearchFieldPlugin","ALL","constructor","params","field","path","keyword","undefined","unmappedType","sortable","searchable","getSortOptions","order","options","unmapped_type","getPath","getBasePath","toSearchValue","value"],"sources":["OpenSearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { MappingFieldType } from \"@opensearch-project/opensearch/api/types\";\nimport type { FieldSortOptions, SortOrder } from \"~/types.js\";\n\nexport type UnmappedTypes = \"date\" | \"long\" | string;\n\nconst keywordLessUnmappedType = [\"date\", \"long\"];\n\nconst unmappedTypeHasKeyword = (type?: string): boolean => {\n if (!type) {\n return true;\n } else if (keywordLessUnmappedType.includes(type)) {\n return false;\n }\n return true;\n};\n\nexport interface ToSearchValueParams {\n /**\n * The value to transform.\n */\n value: any;\n /**\n * When using toSearchValue() in our code we send a field.getPath() value here.\n */\n path: string;\n /**\n * When using toSearchValue() in our code we send a field.getBasePath() value here.\n */\n basePath: string;\n}\nexport interface OpenSearchFieldPluginParams {\n /**\n * Which field is this plugin for.\n */\n field: string;\n /**\n * Some specific path of a field?\n * Example: createdBy is createdBy.id\n */\n path?: string;\n /**\n * Add a .keyword at the end of the field path?\n */\n keyword?: boolean;\n /**\n * Is the field of a specific type, but possibly not mapped?\n * Happens when inserting a date in string format.\n * You need to cast it as date when running the search/sort to work correctly.\n */\n unmappedType?: UnmappedTypes;\n /**\n * Is the field sortable?\n */\n sortable?: boolean;\n /**\n * Is the field searchable?\n */\n searchable?: boolean;\n /**\n * Used to transform the input value for the search.\n */\n toSearchValue?: (params: ToSearchValueParams) => any;\n}\n\nexport class OpenSearchFieldPlugin extends Plugin {\n public static override readonly type: string = \"opensearch.fieldDefinition\";\n public static readonly ALL: string = \"*\";\n\n public readonly field: string;\n public readonly path: string;\n public readonly keyword: boolean;\n public readonly unmappedType?: string;\n public readonly sortable: boolean;\n public readonly searchable: boolean;\n\n constructor(params: OpenSearchFieldPluginParams) {\n super();\n this.field = params.field;\n this.path = params.path || params.field;\n this.keyword = params.keyword === undefined ? true : params.keyword;\n this.unmappedType = params.unmappedType;\n if (unmappedTypeHasKeyword(params.unmappedType) === false) {\n this.keyword = false;\n }\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this.searchable = params.searchable === undefined ? true : params.searchable;\n }\n /**\n * The default sort options. Extend in your own plugin if you want to add more options.\n */\n public getSortOptions(order: SortOrder): FieldSortOptions {\n const options = {\n order\n };\n if (!this.unmappedType) {\n return options;\n }\n return {\n ...options,\n unmapped_type: this.unmappedType as MappingFieldType\n };\n }\n /**\n * The default path generator. Extend in your own plugin if you want to add more options.\n * Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.\n */\n public getPath(field: string): string {\n return `${this.getBasePath(field)}${this.keyword ? \".keyword\" : \"\"}`;\n }\n /**\n * @see getPath\n *\n * This is the default base path generator. Basically it replaces ALL with given field name.\n */\n public getBasePath(field: string): string {\n if (this.path === OpenSearchFieldPlugin.ALL) {\n return field;\n }\n return this.path;\n }\n /**\n * The default transformer. Just returns the value by default.\n * Override to implement what ever is required.\n */\n public toSearchValue(params: ToSearchValueParams): any {\n return params.value;\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AAMxC,MAAMC,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;AAEhD,MAAMC,sBAAsB,GAAIC,IAAa,IAAc;EACvD,IAAI,CAACA,IAAI,EAAE;IACP,OAAO,IAAI;EACf,CAAC,MAAM,IAAIF,uBAAuB,CAACG,QAAQ,CAACD,IAAI,CAAC,EAAE;IAC/C,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CAAC;AAkDD,OAAO,MAAME,qBAAqB,SAASL,MAAM,CAAC;EAC9C,OAAgCG,IAAI,GAAW,4BAA4B;EAC3E,OAAuBG,GAAG,GAAW,GAAG;EASxCC,WAAWA,CAACC,MAAmC,EAAE;IAC7C,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACC,IAAI,GAAGF,MAAM,CAACE,IAAI,IAAIF,MAAM,CAACC,KAAK;IACvC,IAAI,CAACE,OAAO,GAAGH,MAAM,CAACG,OAAO,KAAKC,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACG,OAAO;IACnE,IAAI,CAACE,YAAY,GAAGL,MAAM,CAACK,YAAY;IACvC,IAAIX,sBAAsB,CAACM,MAAM,CAACK,YAAY,CAAC,KAAK,KAAK,EAAE;MACvD,IAAI,CAACF,OAAO,GAAG,KAAK;IACxB;IACA,IAAI,CAACG,QAAQ,GAAGN,MAAM,CAACM,QAAQ,KAAKF,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACM,QAAQ;IACtE,IAAI,CAACC,UAAU,GAAGP,MAAM,CAACO,UAAU,KAAKH,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACO,UAAU;EAChF;EACA;AACJ;AACA;EACWC,cAAcA,CAACC,KAAgB,EAAoB;IACtD,MAAMC,OAAO,GAAG;MACZD;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,CAACJ,YAAY,EAAE;MACpB,OAAOK,OAAO;IAClB;IACA,OAAO;MACH,GAAGA,OAAO;MACVC,aAAa,EAAE,IAAI,CAACN;IACxB,CAAC;EACL;EACA;AACJ;AACA;AACA;EACWO,OAAOA,CAACX,KAAa,EAAU;IAClC,OAAO,GAAG,IAAI,CAACY,WAAW,CAACZ,KAAK,CAAC,GAAG,IAAI,CAACE,OAAO,GAAG,UAAU,GAAG,EAAE,EAAE;EACxE;EACA;AACJ;AACA;AACA;AACA;EACWU,WAAWA,CAACZ,KAAa,EAAU;IACtC,IAAI,IAAI,CAACC,IAAI,KAAKL,qBAAqB,CAACC,GAAG,EAAE;MACzC,OAAOG,KAAK;IAChB;IACA,OAAO,IAAI,CAACC,IAAI;EACpB;EACA;AACJ;AACA;AACA;EACWY,aAAaA,CAACd,MAA2B,EAAO;IACnD,OAAOA,MAAM,CAACe,KAAK;EACvB;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["Plugin","keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","OpenSearchFieldPlugin","ALL","constructor","params","field","path","keyword","undefined","unmappedType","sortable","searchable","getSortOptions","order","options","unmapped_type","getPath","getBasePath","toSearchValue","value"],"sources":["OpenSearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { FieldType as MappingFieldType } from \"@opensearch-project/opensearch/api/_types/_common.mapping\";\nimport type { FieldSortOptions, SortOrder } from \"~/types.js\";\n\nexport type UnmappedTypes = \"date\" | \"long\" | string;\n\nconst keywordLessUnmappedType = [\"date\", \"long\"];\n\nconst unmappedTypeHasKeyword = (type?: string): boolean => {\n if (!type) {\n return true;\n } else if (keywordLessUnmappedType.includes(type)) {\n return false;\n }\n return true;\n};\n\nexport interface ToSearchValueParams {\n /**\n * The value to transform.\n */\n value: any;\n /**\n * When using toSearchValue() in our code we send a field.getPath() value here.\n */\n path: string;\n /**\n * When using toSearchValue() in our code we send a field.getBasePath() value here.\n */\n basePath: string;\n}\nexport interface OpenSearchFieldPluginParams {\n /**\n * Which field is this plugin for.\n */\n field: string;\n /**\n * Some specific path of a field?\n * Example: createdBy is createdBy.id\n */\n path?: string;\n /**\n * Add a .keyword at the end of the field path?\n */\n keyword?: boolean;\n /**\n * Is the field of a specific type, but possibly not mapped?\n * Happens when inserting a date in string format.\n * You need to cast it as date when running the search/sort to work correctly.\n */\n unmappedType?: UnmappedTypes;\n /**\n * Is the field sortable?\n */\n sortable?: boolean;\n /**\n * Is the field searchable?\n */\n searchable?: boolean;\n /**\n * Used to transform the input value for the search.\n */\n toSearchValue?: (params: ToSearchValueParams) => any;\n}\n\nexport class OpenSearchFieldPlugin extends Plugin {\n public static override readonly type: string = \"opensearch.fieldDefinition\";\n public static readonly ALL: string = \"*\";\n\n public readonly field: string;\n public readonly path: string;\n public readonly keyword: boolean;\n public readonly unmappedType?: string;\n public readonly sortable: boolean;\n public readonly searchable: boolean;\n\n constructor(params: OpenSearchFieldPluginParams) {\n super();\n this.field = params.field;\n this.path = params.path || params.field;\n this.keyword = params.keyword === undefined ? true : params.keyword;\n this.unmappedType = params.unmappedType;\n if (unmappedTypeHasKeyword(params.unmappedType) === false) {\n this.keyword = false;\n }\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this.searchable = params.searchable === undefined ? true : params.searchable;\n }\n /**\n * The default sort options. Extend in your own plugin if you want to add more options.\n */\n public getSortOptions(order: SortOrder): FieldSortOptions {\n const options = {\n order\n };\n if (!this.unmappedType) {\n return options;\n }\n return {\n ...options,\n unmapped_type: this.unmappedType as MappingFieldType\n };\n }\n /**\n * The default path generator. Extend in your own plugin if you want to add more options.\n * Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.\n */\n public getPath(field: string): string {\n return `${this.getBasePath(field)}${this.keyword ? \".keyword\" : \"\"}`;\n }\n /**\n * @see getPath\n *\n * This is the default base path generator. Basically it replaces ALL with given field name.\n */\n public getBasePath(field: string): string {\n if (this.path === OpenSearchFieldPlugin.ALL) {\n return field;\n }\n return this.path;\n }\n /**\n * The default transformer. Just returns the value by default.\n * Override to implement what ever is required.\n */\n public toSearchValue(params: ToSearchValueParams): any {\n return params.value;\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AAMxC,MAAMC,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;AAEhD,MAAMC,sBAAsB,GAAIC,IAAa,IAAc;EACvD,IAAI,CAACA,IAAI,EAAE;IACP,OAAO,IAAI;EACf,CAAC,MAAM,IAAIF,uBAAuB,CAACG,QAAQ,CAACD,IAAI,CAAC,EAAE;IAC/C,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CAAC;AAkDD,OAAO,MAAME,qBAAqB,SAASL,MAAM,CAAC;EAC9C,OAAgCG,IAAI,GAAW,4BAA4B;EAC3E,OAAuBG,GAAG,GAAW,GAAG;EASxCC,WAAWA,CAACC,MAAmC,EAAE;IAC7C,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACC,IAAI,GAAGF,MAAM,CAACE,IAAI,IAAIF,MAAM,CAACC,KAAK;IACvC,IAAI,CAACE,OAAO,GAAGH,MAAM,CAACG,OAAO,KAAKC,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACG,OAAO;IACnE,IAAI,CAACE,YAAY,GAAGL,MAAM,CAACK,YAAY;IACvC,IAAIX,sBAAsB,CAACM,MAAM,CAACK,YAAY,CAAC,KAAK,KAAK,EAAE;MACvD,IAAI,CAACF,OAAO,GAAG,KAAK;IACxB;IACA,IAAI,CAACG,QAAQ,GAAGN,MAAM,CAACM,QAAQ,KAAKF,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACM,QAAQ;IACtE,IAAI,CAACC,UAAU,GAAGP,MAAM,CAACO,UAAU,KAAKH,SAAS,GAAG,IAAI,GAAGJ,MAAM,CAACO,UAAU;EAChF;EACA;AACJ;AACA;EACWC,cAAcA,CAACC,KAAgB,EAAoB;IACtD,MAAMC,OAAO,GAAG;MACZD;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,CAACJ,YAAY,EAAE;MACpB,OAAOK,OAAO;IAClB;IACA,OAAO;MACH,GAAGA,OAAO;MACVC,aAAa,EAAE,IAAI,CAACN;IACxB,CAAC;EACL;EACA;AACJ;AACA;AACA;EACWO,OAAOA,CAACX,KAAa,EAAU;IAClC,OAAO,GAAG,IAAI,CAACY,WAAW,CAACZ,KAAK,CAAC,GAAG,IAAI,CAACE,OAAO,GAAG,UAAU,GAAG,EAAE,EAAE;EACxE;EACA;AACJ;AACA;AACA;AACA;EACWU,WAAWA,CAACZ,KAAa,EAAU;IACtC,IAAI,IAAI,CAACC,IAAI,KAAKL,qBAAqB,CAACC,GAAG,EAAE;MACzC,OAAOG,KAAK;IAChB;IACA,OAAO,IAAI,CAACC,IAAI;EACpB;EACA;AACJ;AACA;AACA;EACWY,aAAaA,CAACd,MAA2B,EAAO;IACnD,OAAOA,MAAM,CAACe,KAAK;EACvB;AACJ","ignoreList":[]}
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 type { MappingFieldType } from \"@opensearch-project/opensearch/api/types\";\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 unmapped_type: (unmappedType || undefined) as MappingFieldType | undefined\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;AAGvC,SAASC,qBAAqB;AAE9B,MAAMC,UAAU,GAAG,6CAA6C;AAYhE,OAAO,MAAMC,UAAU,GAAI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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,"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 type { FieldType as MappingFieldType } from \"@opensearch-project/opensearch/api/_types/_common.mapping\";\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 unmapped_type: (unmappedType || undefined) as MappingFieldType | undefined\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;AAGvC,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;QACtBE,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":[]}
package/types.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import type { Client } from "@opensearch-project/opensearch";
2
- import type { QueryDslQueryContainer, QueryDslBoolQuery, SearchFieldSort, SearchSortOrder, SearchSort, SearchRequest } from "@opensearch-project/opensearch/api/types";
3
- import type { Context, GenericRecord } from "@webiny/api/types.js";
2
+ import type { QueryContainer as QueryDslQueryContainer, BoolQuery as QueryDslBoolQuery } from "@opensearch-project/opensearch/api/_types/_common.query_dsl";
3
+ import type { FieldSort as SearchFieldSort, SortOrder as SearchSortOrder, Sort as SearchSort } from "@opensearch-project/opensearch/api/_types/_common";
4
+ import type { Search_RequestBody as SearchRequestBody, Search_Response } from "@opensearch-project/opensearch/api/_core/search";
5
+ import type { Indices_Create_RequestBody } from "@opensearch-project/opensearch/api/indices/create";
6
+ import type { DynamicTemplate } from "@opensearch-project/opensearch/api/_types/_common.mapping";
7
+ import type { Context } from "@webiny/api/types.js";
4
8
  export type { ApiResponse } from "@opensearch-project/opensearch";
5
9
  export type { Client };
6
- /** Replaces elastic-ts PrimitiveValue */
7
- export type PrimitiveValue = null | number | string | boolean;
10
+ /** Replaces elastic-ts PrimitiveValue. Aligns with opensearch FieldValue. */
11
+ export type PrimitiveValue = boolean | undefined | number | string;
8
12
  /** Replaces elastic-ts Query */
9
13
  export type { QueryDslQueryContainer };
10
14
  /** Replaces elastic-ts BoolQueryConfig */
@@ -18,7 +22,7 @@ export type { SearchSort as Sort };
18
22
  /** Single sort entry as an object map. Replaces elastic-ts SortType. */
19
23
  export type SortType = Record<string, FieldSortOptions>;
20
24
  /** Replaces elastic-ts SearchBody. Overrides search_after to allow PrimitiveValue[] (null | boolean | string | number). */
21
- export type SearchBody = Omit<NonNullable<SearchRequest["body"]>, "search_after"> & {
25
+ export type SearchBody = Omit<SearchRequestBody, "search_after"> & {
22
26
  search_after?: PrimitiveValue[];
23
27
  };
24
28
  export interface OpenSearchContext extends Context {
@@ -42,138 +46,19 @@ export interface OpenSearchQueryBuilderArgsPlugin {
42
46
  value: any;
43
47
  keyword: boolean;
44
48
  }
45
- export interface OpenSearchSearchResponseHit<T> {
46
- _index: string;
47
- _type: string;
48
- _id: string;
49
- _score: number | null;
50
- _source: T;
51
- sort: PrimitiveValue[];
52
- }
53
- export interface OpenSearchSearchResponseAggregationBucket<T> {
54
- key: T;
49
+ export type OpenSearchSearchResponseHit = Search_Response["body"]["hits"]["hits"][number];
50
+ export interface OpenSearchSearchResponseAggregationBucket {
51
+ key: PrimitiveValue;
55
52
  doc_count: number;
56
53
  }
57
- export interface OpenSearchSearchResponseBodyHits<T> {
58
- hits: OpenSearchSearchResponseHit<T>[];
59
- total: {
60
- value: number;
61
- };
62
- }
63
- export interface OpenSearchSearchResponseBodyAggregations<T> {
64
- [key: string]: {
65
- buckets: OpenSearchSearchResponseAggregationBucket<T>[];
66
- };
67
- }
68
- export interface OpenSearchSearchResponseBody<T> {
69
- hits: OpenSearchSearchResponseBodyHits<T>;
70
- aggregations: OpenSearchSearchResponseBodyAggregations<T>;
71
- }
72
- export interface OpenSearchSearchResponse<T = GenericRecord> {
73
- body: OpenSearchSearchResponseBody<T>;
74
- }
75
- export interface OpenSearchIndexRequestBodyMappingsDynamicTemplate {
76
- [key: string]: {
77
- path_match?: string;
78
- path_unmatch?: string;
79
- match_mapping_type?: string;
80
- match?: string;
81
- unmatch?: string;
82
- mapping?: {
83
- numeric_detection?: boolean;
84
- date_detection?: boolean;
85
- type?: string;
86
- search_analyzer?: string;
87
- analyzer?: string;
88
- fields?: {
89
- [key: string]: {
90
- type: string;
91
- search_analyzer?: string;
92
- analyzer?: string;
93
- ignore_above?: number;
94
- [key: string]: any;
95
- } | undefined;
96
- };
97
- [key: string]: any;
98
- };
99
- [key: string]: any;
100
- };
101
- }
102
- export interface OpenSearchIndexRequestBody {
103
- settings?: {
104
- index?: {
105
- analysis?: {
106
- [key: string]: any;
107
- };
108
- number_of_shards?: number;
109
- number_of_routing_shards?: number;
110
- codec?: string;
111
- soft_deletes?: {
112
- enabled?: boolean;
113
- retention_lease?: {
114
- period?: string;
115
- };
116
- };
117
- number_of_replicas?: number;
118
- auto_expand_replicas?: string | "all" | false;
119
- refresh_interval?: string;
120
- max_result_window?: number;
121
- max_inner_result_window?: number;
122
- max_rescore_window?: number;
123
- max_script_fields?: number;
124
- max_ngram_diff?: number;
125
- max_shingle_diff?: number;
126
- max_terms_count?: number;
127
- max_regex_length?: number;
128
- routing?: {
129
- allocation?: {
130
- enable?: "all" | "primaries" | "new_primaries" | "none";
131
- };
132
- rebalance?: {
133
- enable?: "all" | "primaries" | "new_primaries" | "none";
134
- };
135
- };
136
- hidden?: boolean;
137
- total_fields?: {
138
- limit?: number;
139
- };
140
- [key: string]: any;
141
- };
142
- };
143
- mappings: {
144
- numeric_detection?: boolean;
145
- dynamic_templates?: OpenSearchIndexRequestBodyMappingsDynamicTemplate[];
146
- properties?: {
147
- [key: string]: {
148
- analyzer?: string;
149
- type?: string;
150
- normalizer?: string;
151
- index?: string;
152
- fields?: {
153
- [key: string]: {
154
- type: string;
155
- ignore_above?: number;
156
- search_analyzer?: string;
157
- analyzer?: string;
158
- [key: string]: any;
159
- };
160
- };
161
- [key: string]: any;
162
- };
163
- };
164
- [key: string]: any;
165
- };
166
- aliases?: {
167
- [key: string]: {
168
- filter?: {
169
- [key: string]: any;
170
- };
171
- index_routing?: string;
172
- is_hidden?: boolean;
173
- is_write_index?: boolean;
174
- routing?: string;
175
- search_routing?: string;
176
- };
177
- };
178
- }
54
+ export type OpenSearchSearchResponseBodyHits = Search_Response["body"]["hits"];
55
+ export type OpenSearchSearchResponseBody = Search_Response["body"];
56
+ export type OpenSearchSearchResponse = Search_Response;
57
+ /**
58
+ * Extract the total count from an opensearch hits response.
59
+ * Handles both `TotalHits` (object with `value`) and plain `number` formats.
60
+ */
61
+ export declare const getTotalCount: (total: OpenSearchSearchResponseBodyHits["total"]) => number;
62
+ export type OpenSearchIndexRequestBodyMappingsDynamicTemplate = Record<string, DynamicTemplate>;
63
+ export type OpenSearchIndexRequestBody = Indices_Create_RequestBody;
179
64
  export type { SearchSortOrder };
package/types.js CHANGED
@@ -1,3 +1,57 @@
1
- export {};
1
+ // ---------------------------------------------------------------------------
2
+ // Local type aliases replacing elastic-ts
3
+ // ---------------------------------------------------------------------------
4
+
5
+ /** Replaces elastic-ts PrimitiveValue. Aligns with opensearch FieldValue. */
6
+
7
+ /** Replaces elastic-ts Query */
8
+
9
+ /** Replaces elastic-ts BoolQueryConfig */
10
+
11
+ /** Replaces elastic-ts FieldSortOptions */
12
+
13
+ /** Replaces elastic-ts SortOrder. Narrowed to "asc" | "desc" (excludes "_doc"). */
14
+
15
+ /** Replaces elastic-ts Sort */
16
+
17
+ /** Single sort entry as an object map. Replaces elastic-ts SortType. */
18
+
19
+ /** Replaces elastic-ts SearchBody. Overrides search_after to allow PrimitiveValue[] (null | boolean | string | number). */
20
+
21
+ // ---------------------------------------------------------------------------
22
+ // Context
23
+ // ---------------------------------------------------------------------------
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Bool query with required arrays (our convention)
27
+ // ---------------------------------------------------------------------------
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Operator plugin types
31
+ // ---------------------------------------------------------------------------
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // Search response shapes (aligned with @opensearch-project/opensearch v3)
35
+ // ---------------------------------------------------------------------------
36
+
37
+ /**
38
+ * Extract the total count from an opensearch hits response.
39
+ * Handles both `TotalHits` (object with `value`) and plain `number` formats.
40
+ */
41
+ export const getTotalCount = total => {
42
+ if (total === undefined || total === null) {
43
+ return 0;
44
+ }
45
+ if (typeof total === "number") {
46
+ return total;
47
+ }
48
+ return total.value;
49
+ };
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Index request body shapes (re-exported from opensearch package)
53
+ // ---------------------------------------------------------------------------
54
+
55
+ // Re-export SearchSortOrder for consumers that need it (including "_doc")
2
56
 
3
57
  //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { Client } from \"@opensearch-project/opensearch\";\nimport type {\n QueryDslQueryContainer,\n QueryDslBoolQuery,\n SearchFieldSort,\n SearchSortOrder,\n SearchSort,\n SearchRequest\n} from \"@opensearch-project/opensearch/api/types\";\nimport type { Context, GenericRecord } from \"@webiny/api/types.js\";\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 */\nexport type PrimitiveValue = null | number | string | boolean;\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<NonNullable<SearchRequest[\"body\"]>, \"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\n// ---------------------------------------------------------------------------\n\nexport interface OpenSearchSearchResponseHit<T> {\n _index: string;\n _type: string;\n _id: string;\n _score: number | null;\n _source: T;\n sort: PrimitiveValue[];\n}\n\nexport interface OpenSearchSearchResponseAggregationBucket<T> {\n key: T;\n doc_count: number;\n}\n\nexport interface OpenSearchSearchResponseBodyHits<T> {\n hits: OpenSearchSearchResponseHit<T>[];\n total: {\n value: number;\n };\n}\n\nexport interface OpenSearchSearchResponseBodyAggregations<T> {\n [key: string]: {\n buckets: OpenSearchSearchResponseAggregationBucket<T>[];\n };\n}\n\nexport interface OpenSearchSearchResponseBody<T> {\n hits: OpenSearchSearchResponseBodyHits<T>;\n aggregations: OpenSearchSearchResponseBodyAggregations<T>;\n}\n\nexport interface OpenSearchSearchResponse<T = GenericRecord> {\n body: OpenSearchSearchResponseBody<T>;\n}\n\n// ---------------------------------------------------------------------------\n// Index request body shapes (our own definitions, not from opensearch package)\n// ---------------------------------------------------------------------------\n\nexport interface OpenSearchIndexRequestBodyMappingsDynamicTemplate {\n [key: string]: {\n path_match?: string;\n path_unmatch?: string;\n match_mapping_type?: string;\n match?: string;\n unmatch?: string;\n mapping?: {\n numeric_detection?: boolean;\n date_detection?: boolean;\n type?: string;\n search_analyzer?: string;\n analyzer?: string;\n fields?: {\n [key: string]:\n | {\n type: string;\n search_analyzer?: string;\n analyzer?: string;\n ignore_above?: number;\n [key: string]: any;\n }\n | undefined;\n };\n [key: string]: any;\n };\n [key: string]: any;\n };\n}\n\nexport interface OpenSearchIndexRequestBody {\n settings?: {\n index?: {\n analysis?: { [key: string]: any };\n number_of_shards?: number;\n number_of_routing_shards?: number;\n codec?: string;\n soft_deletes?: { enabled?: boolean; retention_lease?: { period?: string } };\n number_of_replicas?: number;\n auto_expand_replicas?: string | \"all\" | false;\n refresh_interval?: string;\n max_result_window?: number;\n max_inner_result_window?: number;\n max_rescore_window?: number;\n max_script_fields?: number;\n max_ngram_diff?: number;\n max_shingle_diff?: number;\n max_terms_count?: number;\n max_regex_length?: number;\n routing?: {\n allocation?: { enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\" };\n rebalance?: { enable?: \"all\" | \"primaries\" | \"new_primaries\" | \"none\" };\n };\n hidden?: boolean;\n total_fields?: { limit?: number };\n [key: string]: any;\n };\n };\n mappings: {\n numeric_detection?: boolean;\n dynamic_templates?: OpenSearchIndexRequestBodyMappingsDynamicTemplate[];\n properties?: {\n [key: string]: {\n analyzer?: string;\n type?: string;\n normalizer?: string;\n index?: string;\n fields?: {\n [key: string]: {\n type: string;\n ignore_above?: number;\n search_analyzer?: string;\n analyzer?: string;\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n };\n [key: string]: any;\n };\n aliases?: {\n [key: string]: {\n filter?: { [key: string]: any };\n index_routing?: string;\n is_hidden?: boolean;\n is_write_index?: boolean;\n routing?: string;\n search_routing?: string;\n };\n };\n}\n\n// Re-export SearchSortOrder for consumers that need it (including \"_doc\")\nexport type { SearchSortOrder };\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":["getTotalCount","total","undefined","value"],"sources":["types.ts"],"sourcesContent":["import type { Client } from \"@opensearch-project/opensearch\";\nimport type {\n QueryContainer as QueryDslQueryContainer,\n BoolQuery as QueryDslBoolQuery\n} from \"@opensearch-project/opensearch/api/_types/_common.query_dsl\";\nimport type {\n FieldSort as SearchFieldSort,\n SortOrder as SearchSortOrder,\n Sort as SearchSort\n} from \"@opensearch-project/opensearch/api/_types/_common\";\nimport type {\n Search_RequestBody as SearchRequestBody,\n Search_Response\n} from \"@opensearch-project/opensearch/api/_core/search\";\nimport type { Indices_Create_RequestBody } from \"@opensearch-project/opensearch/api/indices/create\";\nimport type { DynamicTemplate } from \"@opensearch-project/opensearch/api/_types/_common.mapping\";\nimport type { Context } from \"@webiny/api/types.js\";\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":"AAsBA;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":[]}
@@ -65,6 +65,7 @@ declare class WaitUntilHealthy {
65
65
  private shouldWait;
66
66
  private getProcessorPercent;
67
67
  private getRamPercent;
68
+ private toClusterHealthStatus;
68
69
  private transformClusterHealthStatus;
69
70
  }
70
71
  export type { WaitUntilHealthy };
@@ -88,12 +88,13 @@ class WaitUntilHealthy {
88
88
  current: OpenSearchCatClusterHealthStatus.Red
89
89
  });
90
90
  }
91
- const clusterHealthStatus = this.transformClusterHealthStatus(health.status);
91
+ const currentStatus = this.toClusterHealthStatus(health.status);
92
+ const clusterHealthStatus = this.transformClusterHealthStatus(currentStatus);
92
93
  const minClusterHealthStatus = this.transformClusterHealthStatus(this.options.minClusterHealthStatus);
93
94
  if (clusterHealthStatus > minClusterHealthStatus) {
94
95
  return createClusterHealthStatusReason({
95
96
  minimum: this.options.minClusterHealthStatus,
96
- current: health.status
97
+ current: currentStatus
97
98
  });
98
99
  }
99
100
  const processorPercent = this.getProcessorPercent(nodes);
@@ -120,16 +121,26 @@ class WaitUntilHealthy {
120
121
  }
121
122
  getProcessorPercent(nodes) {
122
123
  const total = nodes.reduce((total, node) => {
123
- return total + parseFloat(node.cpu);
124
+ return total + parseFloat(node.cpu || "0");
124
125
  }, 0);
125
126
  return total / nodes.length;
126
127
  }
127
128
  getRamPercent(nodes) {
128
129
  const total = nodes.reduce((total, node) => {
129
- return total + parseFloat(node["ram.percent"]);
130
+ return total + parseFloat(node["ram.percent"] || "0");
130
131
  }, 0);
131
132
  return total / nodes.length;
132
133
  }
134
+ toClusterHealthStatus(status) {
135
+ switch (status) {
136
+ case "green":
137
+ return OpenSearchCatClusterHealthStatus.Green;
138
+ case "yellow":
139
+ return OpenSearchCatClusterHealthStatus.Yellow;
140
+ default:
141
+ return OpenSearchCatClusterHealthStatus.Red;
142
+ }
143
+ }
133
144
  transformClusterHealthStatus(status) {
134
145
  switch (status) {
135
146
  case OpenSearchCatClusterHealthStatus.Green:
@@ -1 +1 @@
1
- {"version":3,"names":["OpenSearchCatHealth","OpenSearchCatNodes","OpenSearchCatClusterHealthStatus","UnhealthyClusterError","createClusterHealthStatusReason","createMemoryReason","createProcessorReason","WaitingHealthyClusterAbortedError","WAITING_TIME_STEP","WaitUntilHealthy","aborted","constructor","client","options","catHealth","catNodes","abort","wait","startedAt","Date","mustEndAt","getTime","maxWaitingTime","waitingTimeStep","runs","waitingReason","shouldWait","onTimeout","onUnhealthy","Promise","resolve","setTimeout","runningTime","health","nodes","getHealth","ex","description","message","minimum","minClusterHealthStatus","current","Red","getNodes","clusterHealthStatus","transformClusterHealthStatus","status","processorPercent","getProcessorPercent","maxProcessorPercent","maximum","maxRamPercent","undefined","ramPercent","getRamPercent","total","reduce","node","parseFloat","cpu","length","Green","Yellow","createWaitUntilHealthy","params"],"sources":["WaitUntilHealthy.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport { OpenSearchCatHealth } from \"~/operations/OpenSearchCatHealth.js\";\nimport { OpenSearchCatNodes } from \"~/operations/OpenSearchCatNodes.js\";\nimport type {\n IOpenSearchCatHealthResponse,\n IOpenSearchCatNodesResponse\n} from \"~/operations/types.js\";\nimport { OpenSearchCatClusterHealthStatus } from \"~/operations/types.js\";\nimport { UnhealthyClusterError } from \"~/utils/waitUntilHealthy/UnhealthyClusterError.js\";\nimport type { ClusterHealthReason, MemoryReason, ProcessorReason } from \"./reason/index.js\";\nimport {\n createClusterHealthStatusReason,\n createMemoryReason,\n createProcessorReason\n} from \"./reason/index.js\";\nimport { WaitingHealthyClusterAbortedError } from \"./WaitingHealthyClusterAbortedError.js\";\n\nconst WAITING_TIME_STEP = 10;\n\nexport type WaitingReason = ProcessorReason | MemoryReason | ClusterHealthReason;\n\nexport interface IWaitUntilHealthyParams {\n /**\n * Minimum status allowed, otherwise the cluster is considered unhealthy.\n */\n minClusterHealthStatus:\n | OpenSearchCatClusterHealthStatus.Green\n | OpenSearchCatClusterHealthStatus.Yellow;\n /**\n * Maximum processor percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxProcessorPercent: number;\n /**\n * Maximum RAM percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxRamPercent?: number;\n /**\n * Maximum time to wait in seconds.\n * This is to prevent infinite waiting in case the cluster never becomes healthy.\n */\n maxWaitingTime: number;\n /**\n * Time in seconds to wait between each check.\n * This is to prevent spamming the cluster with requests.\n * Default is WAITING_TIME_STEP seconds.\n */\n waitingTimeStep?: number;\n}\n\nexport interface IWaitOptionsOnUnhealthyParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptionsOnTimeoutParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptions {\n onUnhealthy?(params: IWaitOptionsOnUnhealthyParams): Promise<void>;\n onTimeout?(params: IWaitOptionsOnTimeoutParams): Promise<void>;\n}\n\nexport interface IWaitUntilHealthyWaitResponse {\n runningTime: number;\n runs: number;\n}\n\nclass WaitUntilHealthy {\n private readonly client: Client;\n private readonly options: IWaitUntilHealthyParams;\n\n private readonly catHealth: OpenSearchCatHealth;\n private readonly catNodes: OpenSearchCatNodes;\n\n private aborted = false;\n\n public constructor(client: Client, options: IWaitUntilHealthyParams) {\n this.client = client;\n this.options = options;\n\n this.catHealth = new OpenSearchCatHealth(this.client);\n this.catNodes = new OpenSearchCatNodes(this.client);\n }\n\n public abort(): void {\n this.aborted = true;\n }\n /**\n * @throws UnhealthyClusterError\n * @throws WaitingHealthyClusterAbortedError\n */\n public async wait(options?: IWaitOptions): Promise<IWaitUntilHealthyWaitResponse> {\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError(\n `Waiting for the cluster to become healthy was aborted even before it started.`\n );\n }\n const startedAt = new Date();\n const mustEndAt = new Date(startedAt.getTime() + this.options.maxWaitingTime * 1000);\n const waitingTimeStep = this.options.waitingTimeStep || WAITING_TIME_STEP;\n let runs = 1;\n let waitingReason: WaitingReason | false;\n while ((waitingReason = await this.shouldWait())) {\n if (new Date() >= mustEndAt) {\n if (options?.onTimeout) {\n await options.onTimeout({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n throw new UnhealthyClusterError(this.options.maxWaitingTime);\n } else if (options?.onUnhealthy) {\n await options.onUnhealthy({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n /**\n * Abort check is separated from other IFs because it can be aborted in onUnhealthy callback.\n */\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError();\n }\n runs++;\n await new Promise(resolve => {\n setTimeout(resolve, waitingTimeStep * 1000);\n });\n }\n\n const runningTime = new Date().getTime() - startedAt.getTime();\n\n return {\n runningTime,\n runs\n };\n }\n\n private async shouldWait(): Promise<WaitingReason | false> {\n let health: IOpenSearchCatHealthResponse;\n let nodes: IOpenSearchCatNodesResponse;\n try {\n health = await this.catHealth.getHealth();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n try {\n nodes = await this.catNodes.getNodes();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n\n const clusterHealthStatus = this.transformClusterHealthStatus(health.status);\n const minClusterHealthStatus = this.transformClusterHealthStatus(\n this.options.minClusterHealthStatus\n );\n if (clusterHealthStatus > minClusterHealthStatus) {\n return createClusterHealthStatusReason({\n minimum: this.options.minClusterHealthStatus,\n current: health.status\n });\n }\n\n const processorPercent = this.getProcessorPercent(nodes);\n if (processorPercent > this.options.maxProcessorPercent) {\n return createProcessorReason({\n maximum: this.options.maxProcessorPercent,\n current: processorPercent\n });\n }\n /**\n * Possibly no max ram definition?\n */\n if (this.options.maxRamPercent === undefined) {\n return false;\n }\n\n const ramPercent = this.getRamPercent(nodes);\n if (ramPercent > this.options.maxRamPercent) {\n return createMemoryReason({\n maximum: this.options.maxRamPercent,\n current: ramPercent\n });\n }\n return false;\n }\n\n private getProcessorPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node.cpu);\n }, 0);\n return total / nodes.length;\n }\n\n private getRamPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node[\"ram.percent\"]);\n }, 0);\n return total / nodes.length;\n }\n\n private transformClusterHealthStatus(status: OpenSearchCatClusterHealthStatus): number {\n switch (status) {\n case OpenSearchCatClusterHealthStatus.Green:\n return 1;\n case OpenSearchCatClusterHealthStatus.Yellow:\n return 2;\n case OpenSearchCatClusterHealthStatus.Red:\n return 3;\n default:\n return 99;\n }\n }\n}\n\nexport type { WaitUntilHealthy };\n\nexport const createWaitUntilHealthy = (\n client: Client,\n params: IWaitUntilHealthyParams\n): WaitUntilHealthy => {\n return new WaitUntilHealthy(client, params);\n};\n"],"mappings":"AACA,SAASA,mBAAmB;AAC5B,SAASC,kBAAkB;AAK3B,SAASC,gCAAgC;AACzC,SAASC,qBAAqB;AAE9B,SACIC,+BAA+B,EAC/BC,kBAAkB,EAClBC,qBAAqB;AAEzB,SAASC,iCAAiC;AAE1C,MAAMC,iBAAiB,GAAG,EAAE;AA0D5B,MAAMC,gBAAgB,CAAC;EAOXC,OAAO,GAAG,KAAK;EAEhBC,WAAWA,CAACC,MAAc,EAAEC,OAAgC,EAAE;IACjE,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAGA,OAAO;IAEtB,IAAI,CAACC,SAAS,GAAG,IAAId,mBAAmB,CAAC,IAAI,CAACY,MAAM,CAAC;IACrD,IAAI,CAACG,QAAQ,GAAG,IAAId,kBAAkB,CAAC,IA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,4BAA4BA,CAACC,MAAwC,EAAU;IACnF,QAAQA,MAAM;MACV,KAAK5C,gCAAgC,CAAC2D,KAAK;QACvC,OAAO,CAAC;MACZ,KAAK3D,gCAAgC,CAAC4D,MAAM;QACxC,OAAO,CAAC;MACZ,KAAK5D,gCAAgC,CAACwC,GAAG;QACrC,OAAO,CAAC;MACZ;QACI,OAAO,EAAE;IACjB;EACJ;AACJ;AAIA,OAAO,MAAMqB,sBAAsB,GAAGA,CAClCnD,MAAc,EACdoD,MAA+B,KACZ;EACnB,OAAO,IAAIvD,gBAAgB,CAACG,MAAM,EAAEoD,MAAM,CAAC;AAC/C,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["OpenSearchCatHealth","OpenSearchCatNodes","OpenSearchCatClusterHealthStatus","UnhealthyClusterError","createClusterHealthStatusReason","createMemoryReason","createProcessorReason","WaitingHealthyClusterAbortedError","WAITING_TIME_STEP","WaitUntilHealthy","aborted","constructor","client","options","catHealth","catNodes","abort","wait","startedAt","Date","mustEndAt","getTime","maxWaitingTime","waitingTimeStep","runs","waitingReason","shouldWait","onTimeout","onUnhealthy","Promise","resolve","setTimeout","runningTime","health","nodes","getHealth","ex","description","message","minimum","minClusterHealthStatus","current","Red","getNodes","currentStatus","toClusterHealthStatus","status","clusterHealthStatus","transformClusterHealthStatus","processorPercent","getProcessorPercent","maxProcessorPercent","maximum","maxRamPercent","undefined","ramPercent","getRamPercent","total","reduce","node","parseFloat","cpu","length","Green","Yellow","createWaitUntilHealthy","params"],"sources":["WaitUntilHealthy.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport { OpenSearchCatHealth } from \"~/operations/OpenSearchCatHealth.js\";\nimport { OpenSearchCatNodes } from \"~/operations/OpenSearchCatNodes.js\";\nimport type {\n IOpenSearchCatHealthResponse,\n IOpenSearchCatNodesResponse\n} from \"~/operations/types.js\";\nimport { OpenSearchCatClusterHealthStatus } from \"~/operations/types.js\";\nimport { UnhealthyClusterError } from \"~/utils/waitUntilHealthy/UnhealthyClusterError.js\";\nimport type { ClusterHealthReason, MemoryReason, ProcessorReason } from \"./reason/index.js\";\nimport {\n createClusterHealthStatusReason,\n createMemoryReason,\n createProcessorReason\n} from \"./reason/index.js\";\nimport { WaitingHealthyClusterAbortedError } from \"./WaitingHealthyClusterAbortedError.js\";\n\nconst WAITING_TIME_STEP = 10;\n\nexport type WaitingReason = ProcessorReason | MemoryReason | ClusterHealthReason;\n\nexport interface IWaitUntilHealthyParams {\n /**\n * Minimum status allowed, otherwise the cluster is considered unhealthy.\n */\n minClusterHealthStatus:\n | OpenSearchCatClusterHealthStatus.Green\n | OpenSearchCatClusterHealthStatus.Yellow;\n /**\n * Maximum processor percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxProcessorPercent: number;\n /**\n * Maximum RAM percent allowed, otherwise the cluster is considered unhealthy.\n */\n maxRamPercent?: number;\n /**\n * Maximum time to wait in seconds.\n * This is to prevent infinite waiting in case the cluster never becomes healthy.\n */\n maxWaitingTime: number;\n /**\n * Time in seconds to wait between each check.\n * This is to prevent spamming the cluster with requests.\n * Default is WAITING_TIME_STEP seconds.\n */\n waitingTimeStep?: number;\n}\n\nexport interface IWaitOptionsOnUnhealthyParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptionsOnTimeoutParams {\n startedAt: Date;\n mustEndAt: Date;\n waitingTimeStep: number;\n runs: number;\n waitingReason: WaitingReason;\n}\n\nexport interface IWaitOptions {\n onUnhealthy?(params: IWaitOptionsOnUnhealthyParams): Promise<void>;\n onTimeout?(params: IWaitOptionsOnTimeoutParams): Promise<void>;\n}\n\nexport interface IWaitUntilHealthyWaitResponse {\n runningTime: number;\n runs: number;\n}\n\nclass WaitUntilHealthy {\n private readonly client: Client;\n private readonly options: IWaitUntilHealthyParams;\n\n private readonly catHealth: OpenSearchCatHealth;\n private readonly catNodes: OpenSearchCatNodes;\n\n private aborted = false;\n\n public constructor(client: Client, options: IWaitUntilHealthyParams) {\n this.client = client;\n this.options = options;\n\n this.catHealth = new OpenSearchCatHealth(this.client);\n this.catNodes = new OpenSearchCatNodes(this.client);\n }\n\n public abort(): void {\n this.aborted = true;\n }\n /**\n * @throws UnhealthyClusterError\n * @throws WaitingHealthyClusterAbortedError\n */\n public async wait(options?: IWaitOptions): Promise<IWaitUntilHealthyWaitResponse> {\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError(\n `Waiting for the cluster to become healthy was aborted even before it started.`\n );\n }\n const startedAt = new Date();\n const mustEndAt = new Date(startedAt.getTime() + this.options.maxWaitingTime * 1000);\n const waitingTimeStep = this.options.waitingTimeStep || WAITING_TIME_STEP;\n let runs = 1;\n let waitingReason: WaitingReason | false;\n while ((waitingReason = await this.shouldWait())) {\n if (new Date() >= mustEndAt) {\n if (options?.onTimeout) {\n await options.onTimeout({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n throw new UnhealthyClusterError(this.options.maxWaitingTime);\n } else if (options?.onUnhealthy) {\n await options.onUnhealthy({\n startedAt,\n mustEndAt,\n waitingTimeStep,\n waitingReason,\n runs\n });\n }\n /**\n * Abort check is separated from other IFs because it can be aborted in onUnhealthy callback.\n */\n if (this.aborted) {\n throw new WaitingHealthyClusterAbortedError();\n }\n runs++;\n await new Promise(resolve => {\n setTimeout(resolve, waitingTimeStep * 1000);\n });\n }\n\n const runningTime = new Date().getTime() - startedAt.getTime();\n\n return {\n runningTime,\n runs\n };\n }\n\n private async shouldWait(): Promise<WaitingReason | false> {\n let health: IOpenSearchCatHealthResponse;\n let nodes: IOpenSearchCatNodesResponse;\n try {\n health = await this.catHealth.getHealth();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n try {\n nodes = await this.catNodes.getNodes();\n } catch (ex) {\n return createClusterHealthStatusReason({\n description: ex.message,\n minimum: this.options.minClusterHealthStatus,\n current: OpenSearchCatClusterHealthStatus.Red\n });\n }\n\n const currentStatus = this.toClusterHealthStatus(health.status);\n const clusterHealthStatus = this.transformClusterHealthStatus(currentStatus);\n const minClusterHealthStatus = this.transformClusterHealthStatus(\n this.options.minClusterHealthStatus\n );\n if (clusterHealthStatus > minClusterHealthStatus) {\n return createClusterHealthStatusReason({\n minimum: this.options.minClusterHealthStatus,\n current: currentStatus\n });\n }\n\n const processorPercent = this.getProcessorPercent(nodes);\n if (processorPercent > this.options.maxProcessorPercent) {\n return createProcessorReason({\n maximum: this.options.maxProcessorPercent,\n current: processorPercent\n });\n }\n /**\n * Possibly no max ram definition?\n */\n if (this.options.maxRamPercent === undefined) {\n return false;\n }\n\n const ramPercent = this.getRamPercent(nodes);\n if (ramPercent > this.options.maxRamPercent) {\n return createMemoryReason({\n maximum: this.options.maxRamPercent,\n current: ramPercent\n });\n }\n return false;\n }\n\n private getProcessorPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node.cpu || \"0\");\n }, 0);\n return total / nodes.length;\n }\n\n private getRamPercent(nodes: IOpenSearchCatNodesResponse): number {\n const total = nodes.reduce<number>((total, node) => {\n return total + parseFloat(node[\"ram.percent\"] || \"0\");\n }, 0);\n return total / nodes.length;\n }\n\n private toClusterHealthStatus(status?: string): OpenSearchCatClusterHealthStatus {\n switch (status) {\n case \"green\":\n return OpenSearchCatClusterHealthStatus.Green;\n case \"yellow\":\n return OpenSearchCatClusterHealthStatus.Yellow;\n default:\n return OpenSearchCatClusterHealthStatus.Red;\n }\n }\n\n private transformClusterHealthStatus(status: OpenSearchCatClusterHealthStatus): number {\n switch (status) {\n case OpenSearchCatClusterHealthStatus.Green:\n return 1;\n case OpenSearchCatClusterHealthStatus.Yellow:\n return 2;\n case OpenSearchCatClusterHealthStatus.Red:\n return 3;\n default:\n return 99;\n }\n }\n}\n\nexport type { WaitUntilHealthy };\n\nexport const createWaitUntilHealthy = (\n client: Client,\n params: IWaitUntilHealthyParams\n): WaitUntilHealthy => {\n return new WaitUntilHealthy(client, params);\n};\n"],"mappings":"AACA,SAASA,mBAAmB;AAC5B,SAASC,kBAAkB;AAK3B,SAASC,gCAAgC;AACzC,SAASC,qBAAqB;AAE9B,SACIC,+BAA+B,EAC/BC,kBAAkB,EAClBC,qBAAqB;AAEzB,SAASC,iCAAiC;AAE1C,MAAMC,iBAAiB,GAAG,EAAE;AA0D5B,MAAMC,gBAAgB,CAAC;EAOXC,OAAO,GAAG,KAAK;EAEhBC,WAAWA,CAACC,MAAc,EAAEC,OAAgC,EAAE;IACjE,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAGA,OAAO;IAEtB,IAAI,CAACC,SAAS,GAAG,IAAId,mBAAmB,CAAC,IAAI,CAACY,MAAM,CAAC;IACrD,IAAI,CAACG,QAAQ,GAAG,IAAId,kBAAkB,CAAC,IAAI,CAACW,MAAM,CAAC;EACvD;EAEOI,KAAKA,CAAA,EAAS;IACjB,IAAI,CAACN,OAAO,GAAG,IAAI;EACvB;EACA;AACJ;AACA;AACA;EACI,MAAaO,IAAIA,CAACJ,OAAsB,EAA0C;IAC9E,IAAI,IAAI,CAACH,OAAO,EAAE;MACd,MAAM,IAAIH,iCAAiC,CACvC,+EACJ,CAAC;IACL;IACA,MAAMW,SAAS,GAAG,IAAIC,IAAI,CAAC,CAAC;IAC5B,MAAMC,SAAS,GAAG,IAAID,IAAI,CAACD,SAAS,CAACG,OAAO,CAAC,CAAC,GAAG,IAAI,CAACR,OAAO,CAACS,cAAc,GAAG,IAAI,CAAC;IACpF,MAAMC,eAAe,GAAG,IAAI,CAACV,OAAO,CAACU,eAAe,IAAIf,iBAAiB;IACzE,IAAIgB,IAAI,GAAG,CAAC;IACZ,IAAIC,aAAoC;IACxC,OAAQA,aAAa,GAAG,MAAM,IAAI,CAACC,UAAU,CAAC,CAAC,EAAG;MAC9C,IAAI,IAAIP,IAAI,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AO,IAAIzD,gBAAgB,CAACG,MAAM,EAAEsD,MAAM,CAAC;AAC/C,CAAC","ignoreList":[]}
package/compression.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { PluginsContainer } from "@webiny/plugins";
2
- /**
3
- * Method to compress the opensearch data that is going to be stored into the DynamoDB table that is meant for opensearch.
4
- */
5
- export declare const compress: (pluginsContainer: PluginsContainer, data: Record<string, any>) => Promise<Record<string, any>>;
6
- export declare const decompress: (pluginsContainer: PluginsContainer, data: Record<string, any>) => Promise<Record<string, any>>;
package/compression.js DELETED
@@ -1,25 +0,0 @@
1
- import { CompressorPlugin } from "@webiny/api";
2
-
3
- /**
4
- * Method to compress the opensearch data that is going to be stored into the DynamoDB table that is meant for opensearch.
5
- */
6
- export const compress = async (pluginsContainer, data) => {
7
- let plugin;
8
- try {
9
- plugin = pluginsContainer.oneByType(CompressorPlugin.type);
10
- } catch {
11
- return data;
12
- }
13
- return plugin.getCompressor().compress(data);
14
- };
15
- export const decompress = async (pluginsContainer, data) => {
16
- let plugin;
17
- try {
18
- plugin = pluginsContainer.oneByType(CompressorPlugin.type);
19
- } catch {
20
- return data;
21
- }
22
- return plugin.getCompressor().decompress(data);
23
- };
24
-
25
- //# sourceMappingURL=compression.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CompressorPlugin","compress","pluginsContainer","data","plugin","oneByType","type","getCompressor","decompress"],"sources":["compression.ts"],"sourcesContent":["import type { PluginsContainer } from \"@webiny/plugins\";\nimport { CompressorPlugin } from \"@webiny/api\";\n\n/**\n * Method to compress the opensearch data that is going to be stored into the DynamoDB table that is meant for opensearch.\n */\nexport const compress = async (\n pluginsContainer: PluginsContainer,\n data: Record<string, any>\n): Promise<Record<string, any>> => {\n let plugin: CompressorPlugin;\n try {\n plugin = pluginsContainer.oneByType<CompressorPlugin>(CompressorPlugin.type);\n } catch {\n return data;\n }\n return plugin.getCompressor().compress(data);\n};\n\nexport const decompress = async (\n pluginsContainer: PluginsContainer,\n data: Record<string, any>\n): Promise<Record<string, any>> => {\n let plugin: CompressorPlugin;\n try {\n plugin = pluginsContainer.oneByType<CompressorPlugin>(CompressorPlugin.type);\n } catch {\n return data;\n }\n return plugin.getCompressor().decompress(data);\n};\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,aAAa;;AAE9C;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,MAAAA,CACpBC,gBAAkC,EAClCC,IAAyB,KACM;EAC/B,IAAIC,MAAwB;EAC5B,IAAI;IACAA,MAAM,GAAGF,gBAAgB,CAACG,SAAS,CAAmBL,gBAAgB,CAACM,IAAI,CAAC;EAChF,CAAC,CAAC,MAAM;IACJ,OAAOH,IAAI;EACf;EACA,OAAOC,MAAM,CAACG,aAAa,CAAC,CAAC,CAACN,QAAQ,CAACE,IAAI,CAAC;AAChD,CAAC;AAED,OAAO,MAAMK,UAAU,GAAG,MAAAA,CACtBN,gBAAkC,EAClCC,IAAyB,KACM;EAC/B,IAAIC,MAAwB;EAC5B,IAAI;IACAA,MAAM,GAAGF,gBAAgB,CAACG,SAAS,CAAmBL,gBAAgB,CAACM,IAAI,CAAC;EAChF,CAAC,CAAC,MAAM;IACJ,OAAOH,IAAI;EACf;EACA,OAAOC,MAAM,CAACG,aAAa,CAAC,CAAC,CAACC,UAAU,CAACL,IAAI,CAAC;AAClD,CAAC","ignoreList":[]}