@webiny/api-opensearch 6.4.12-beta.5 → 6.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/api/opensearch.d.ts +6 -1
- package/exports/api/opensearch.js +6 -1
- package/features/OpenSearchClient/abstraction.d.ts +3 -3
- package/features/OpenSearchClient/abstraction.js.map +1 -1
- package/features/OpenSearchClient/feature.d.ts +2 -1
- package/features/OpenSearchClient/feature.js +5 -3
- package/features/OpenSearchClient/feature.js.map +1 -1
- package/features/OpenSearchField/OpenSearchFieldFactory.d.ts +9 -0
- package/features/OpenSearchField/OpenSearchFieldFactory.js +14 -0
- package/features/OpenSearchField/OpenSearchFieldFactory.js.map +1 -0
- package/features/OpenSearchField/OpenSearchFieldImpl.d.ts +17 -0
- package/{plugins/definition/OpenSearchFieldPlugin.js → features/OpenSearchField/OpenSearchFieldImpl.js} +8 -14
- package/features/OpenSearchField/OpenSearchFieldImpl.js.map +1 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.d.ts +35 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.js +6 -0
- package/features/OpenSearchField/abstractions/OpenSearchField.js.map +1 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.d.ts +8 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js +5 -0
- package/features/OpenSearchField/abstractions/OpenSearchFieldFactory.js.map +1 -0
- package/features/OpenSearchField/feature.d.ts +4 -0
- package/features/OpenSearchField/feature.js +11 -0
- package/features/OpenSearchField/feature.js.map +1 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.d.ts +12 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.js +30 -0
- package/features/OpenSearchIndex/OpenSearchIndexRegistry.js.map +1 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.d.ts +9 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js +5 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndex.js.map +1 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.d.ts +9 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js +5 -0
- package/features/OpenSearchIndex/abstractions/OpenSearchIndexRegistry.js.map +1 -0
- package/features/OpenSearchIndex/feature.d.ts +4 -0
- package/features/OpenSearchIndex/feature.js +11 -0
- package/features/OpenSearchIndex/feature.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.d.ts +12 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js +28 -0
- package/features/OpenSearchQueryBuilderOperator/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.d.ts +11 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js +5 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.d.ts +10 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js +5 -0
- package/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperatorRegistry.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/feature.d.ts +4 -0
- package/features/OpenSearchQueryBuilderOperator/feature.js +41 -0
- package/features/OpenSearchQueryBuilderOperator/feature.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/AndIn.d.ts +9 -0
- package/{plugins/operator/andIn.js → features/OpenSearchQueryBuilderOperator/operators/AndIn.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/AndIn.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Between.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Contains.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Equal.d.ts +9 -0
- package/{plugins/operator/equal.js → features/OpenSearchQueryBuilderOperator/operators/Equal.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/Equal.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThan.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/GreaterThanOrEqual.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/In.d.ts +9 -0
- package/{plugins/operator/in.js → features/OpenSearchQueryBuilderOperator/operators/In.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/In.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThan.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js +23 -0
- package/features/OpenSearchQueryBuilderOperator/operators/LesserThanOrEqual.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/Not.d.ts +9 -0
- package/{plugins/operator/not.js → features/OpenSearchQueryBuilderOperator/operators/Not.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/Not.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotBetween.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js +27 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotContains.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotIn.d.ts +9 -0
- package/{plugins/operator/notIn.js → features/OpenSearchQueryBuilderOperator/operators/NotIn.js} +8 -7
- package/features/OpenSearchQueryBuilderOperator/operators/NotIn.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js +22 -0
- package/features/OpenSearchQueryBuilderOperator/operators/NotStartsWith.js.map +1 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.d.ts +9 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js +22 -0
- package/features/OpenSearchQueryBuilderOperator/operators/StartsWith.js.map +1 -0
- package/index.d.ts +2 -9
- package/index.js +3 -27
- package/indices.d.ts +2 -8
- package/indices.js +1 -12
- package/package.json +12 -11
- package/registerOpenSearchCore.d.ts +3 -0
- package/registerOpenSearchCore.js +20 -0
- package/registerOpenSearchCore.js.map +1 -0
- package/sort.d.ts +2 -2
- package/sort.js +2 -2
- package/sort.js.map +1 -1
- package/testing/createBlankQuery.d.ts +2 -0
- package/testing/createBlankQuery.js +9 -0
- package/testing/createBlankQuery.js.map +1 -0
- package/testing/createTestOpenSearchClient.d.ts +11 -0
- package/testing/createTestOpenSearchClient.js +162 -0
- package/testing/createTestOpenSearchClient.js.map +1 -0
- package/testing/index.d.ts +4 -0
- package/testing/index.js +4 -0
- package/testing/registerOpenSearchCoreForTests.d.ts +1 -0
- package/testing/registerOpenSearchCoreForTests.js +9 -0
- package/testing/registerOpenSearchCoreForTests.js.map +1 -0
- package/testing/setupTestIndexManager.d.ts +13 -0
- package/testing/setupTestIndexManager.js +26 -0
- package/testing/setupTestIndexManager.js.map +1 -0
- package/types.d.ts +0 -8
- package/types.js.map +1 -1
- package/utils/createIndex.d.ts +2 -2
- package/utils/createIndex.js +2 -8
- package/utils/createIndex.js.map +1 -1
- package/utils/waitUntilHealthy/WaitUntilHealthy.js +2 -1
- package/utils/waitUntilHealthy/WaitUntilHealthy.js.map +1 -1
- package/where.d.ts +4 -4
- package/where.js +5 -5
- package/where.js.map +1 -1
- package/features/OpenSearchClient/OpenSearchClient.d.ts +0 -12
- package/features/OpenSearchClient/OpenSearchClient.js +0 -19
- package/features/OpenSearchClient/OpenSearchClient.js.map +0 -1
- package/features/OpenSearchContext/OpenSearchContext.d.ts +0 -8
- package/features/OpenSearchContext/OpenSearchContext.js +0 -14
- package/features/OpenSearchContext/OpenSearchContext.js.map +0 -1
- package/features/OpenSearchContext/abstraction.d.ts +0 -14
- package/features/OpenSearchContext/abstraction.js +0 -5
- package/features/OpenSearchContext/abstraction.js.map +0 -1
- package/features/OpenSearchContext/feature.d.ts +0 -5
- package/features/OpenSearchContext/feature.js +0 -12
- package/features/OpenSearchContext/feature.js.map +0 -1
- package/index.js.map +0 -1
- package/indices.js.map +0 -1
- package/operators.d.ts +0 -6
- package/operators.js +0 -22
- package/operators.js.map +0 -1
- package/plugins/definition/OpenSearchBodyModifierPlugin.d.ts +0 -13
- package/plugins/definition/OpenSearchBodyModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchBodyModifierPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchFieldPlugin.d.ts +0 -81
- package/plugins/definition/OpenSearchFieldPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchIndexPlugin.d.ts +0 -10
- package/plugins/definition/OpenSearchIndexPlugin.js +0 -16
- package/plugins/definition/OpenSearchIndexPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.d.ts +0 -10
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js +0 -9
- package/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchQueryModifierPlugin.d.ts +0 -14
- package/plugins/definition/OpenSearchQueryModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchQueryModifierPlugin.js.map +0 -1
- package/plugins/definition/OpenSearchSortModifierPlugin.d.ts +0 -13
- package/plugins/definition/OpenSearchSortModifierPlugin.js +0 -17
- package/plugins/definition/OpenSearchSortModifierPlugin.js.map +0 -1
- package/plugins/definition/index.d.ts +0 -6
- package/plugins/definition/index.js +0 -6
- package/plugins/index.d.ts +0 -2
- package/plugins/index.js +0 -2
- package/plugins/operator/andIn.d.ts +0 -7
- package/plugins/operator/andIn.js.map +0 -1
- package/plugins/operator/between.d.ts +0 -7
- package/plugins/operator/between.js +0 -26
- package/plugins/operator/between.js.map +0 -1
- package/plugins/operator/contains.d.ts +0 -7
- package/plugins/operator/contains.js +0 -26
- package/plugins/operator/contains.js.map +0 -1
- package/plugins/operator/equal.d.ts +0 -7
- package/plugins/operator/equal.js.map +0 -1
- package/plugins/operator/gt.d.ts +0 -7
- package/plugins/operator/gt.js +0 -22
- package/plugins/operator/gt.js.map +0 -1
- package/plugins/operator/gte.d.ts +0 -7
- package/plugins/operator/gte.js +0 -22
- package/plugins/operator/gte.js.map +0 -1
- package/plugins/operator/in.d.ts +0 -7
- package/plugins/operator/in.js.map +0 -1
- package/plugins/operator/index.d.ts +0 -15
- package/plugins/operator/index.js +0 -15
- package/plugins/operator/lt.d.ts +0 -7
- package/plugins/operator/lt.js +0 -22
- package/plugins/operator/lt.js.map +0 -1
- package/plugins/operator/lte.d.ts +0 -7
- package/plugins/operator/lte.js +0 -22
- package/plugins/operator/lte.js.map +0 -1
- package/plugins/operator/not.d.ts +0 -7
- package/plugins/operator/not.js.map +0 -1
- package/plugins/operator/notBetween.d.ts +0 -7
- package/plugins/operator/notBetween.js +0 -26
- package/plugins/operator/notBetween.js.map +0 -1
- package/plugins/operator/notContains.d.ts +0 -7
- package/plugins/operator/notContains.js +0 -26
- package/plugins/operator/notContains.js.map +0 -1
- package/plugins/operator/notIn.d.ts +0 -7
- package/plugins/operator/notIn.js.map +0 -1
- package/plugins/operator/notStartsWith.d.ts +0 -7
- package/plugins/operator/notStartsWith.js +0 -21
- package/plugins/operator/notStartsWith.js.map +0 -1
- package/plugins/operator/startsWith.d.ts +0 -7
- package/plugins/operator/startsWith.js +0 -21
- package/plugins/operator/startsWith.js.map +0 -1
package/utils/createIndex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/createIndex.js","sources":["../../src/utils/createIndex.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"utils/createIndex.js","sources":["../../src/utils/createIndex.ts"],"sourcesContent":["import type { Client } from \"~/client.js\";\nimport type { OpenSearchIndex } from \"~/features/OpenSearchIndex/abstractions/OpenSearchIndex.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface OnExists {\n (): void;\n}\n\ninterface OnError {\n (ex: Error): Error;\n}\n\ninterface ExistsIndexParams {\n client: Client;\n index: string;\n}\n\nconst indexExists = async (params: ExistsIndexParams): Promise<boolean> => {\n const { client, index } = params;\n\n try {\n const response = await client.indices.exists({\n index,\n ignore_unavailable: false,\n allow_no_indices: true,\n include_defaults: true,\n flat_settings: false,\n local: false\n });\n if (!response.body) {\n return false;\n }\n return true;\n } catch {\n console.error(`Could not determine if the index \"${index}\" exists.`);\n }\n return false;\n};\n\ninterface IndexCreateParams {\n client: Client;\n index: string;\n type: string;\n tenant: string;\n plugin: OpenSearchIndex.Interface;\n onError?: OnError;\n}\n\nconst indexCreate = async (params: IndexCreateParams): Promise<void> => {\n const { client, index, plugin, tenant, type, onError } = params;\n\n try {\n await client.indices.create({\n index,\n body: {\n ...plugin.body\n }\n });\n } catch (ex) {\n let error = ex;\n if (onError) {\n error = onError(ex);\n }\n throw new WebinyError(\n error.message || `Could not create OpenSearch index for the ${type}.`,\n error.code || \"CREATE_OPENSEARCH_INDEX_ERROR\",\n {\n error: {\n ...error,\n message: error.message,\n code: error.code,\n data: error.data\n },\n type,\n tenant,\n index,\n body: plugin.body\n }\n );\n }\n};\n\ninterface CreateIndexParams {\n client: Client;\n plugin: OpenSearchIndex.Interface;\n type: string;\n tenant: string;\n index: string;\n onExists?: OnExists;\n onError?: OnError;\n}\n\nexport const createIndex = async (params: CreateIndexParams): Promise<void> => {\n const { plugin, onExists } = params;\n\n const exists = await indexExists(params);\n if (exists) {\n if (onExists) {\n onExists();\n }\n return;\n }\n\n await indexCreate({\n ...params,\n plugin\n });\n};\n"],"names":["indexExists","params","client","index","response","console","indexCreate","plugin","tenant","type","onError","ex","error","WebinyError","createIndex","onExists","exists"],"mappings":";AAiBA,MAAMA,cAAc,OAAOC;IACvB,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGF;IAE1B,IAAI;QACA,MAAMG,WAAW,MAAMF,OAAO,OAAO,CAAC,MAAM,CAAC;YACzCC;YACA,oBAAoB;YACpB,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,OAAO;QACX;QACA,IAAI,CAACC,SAAS,IAAI,EACd,OAAO;QAEX,OAAO;IACX,EAAE,OAAM;QACJC,QAAQ,KAAK,CAAC,CAAC,kCAAkC,EAAEF,MAAM,SAAS,CAAC;IACvE;IACA,OAAO;AACX;AAWA,MAAMG,cAAc,OAAOL;IACvB,MAAM,EAAEC,MAAM,EAAEC,KAAK,EAAEI,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAGT;IAEzD,IAAI;QACA,MAAMC,OAAO,OAAO,CAAC,MAAM,CAAC;YACxBC;YACA,MAAM;gBACF,GAAGI,OAAO,IAAI;YAClB;QACJ;IACJ,EAAE,OAAOI,IAAI;QACT,IAAIC,QAAQD;QACZ,IAAID,SACAE,QAAQF,QAAQC;QAEpB,MAAM,IAAIE,cACND,MAAM,OAAO,IAAI,CAAC,0CAA0C,EAAEH,KAAK,CAAC,CAAC,EACrEG,MAAM,IAAI,IAAI,iCACd;YACI,OAAO;gBACH,GAAGA,KAAK;gBACR,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAChB,MAAMA,MAAM,IAAI;YACpB;YACAH;YACAD;YACAL;YACA,MAAMI,OAAO,IAAI;QACrB;IAER;AACJ;AAYO,MAAMO,cAAc,OAAOb;IAC9B,MAAM,EAAEM,MAAM,EAAEQ,QAAQ,EAAE,GAAGd;IAE7B,MAAMe,SAAS,MAAMhB,YAAYC;IACjC,IAAIe,QAAQ;QACR,IAAID,UACAA;QAEJ;IACJ;IAEA,MAAMT,YAAY;QACd,GAAGL,MAAM;QACTM;IACJ;AACJ"}
|
|
@@ -33,7 +33,8 @@ class WaitUntilHealthy {
|
|
|
33
33
|
runs
|
|
34
34
|
});
|
|
35
35
|
throw new UnhealthyClusterError(this.options.maxWaitingTime);
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
if (options?.onUnhealthy) await options.onUnhealthy({
|
|
37
38
|
startedAt,
|
|
38
39
|
mustEndAt,
|
|
39
40
|
waitingTimeStep,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/waitUntilHealthy/WaitUntilHealthy.js","sources":["../../../src/utils/waitUntilHealthy/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"],"names":["WAITING_TIME_STEP","WaitUntilHealthy","client","options","OpenSearchCatHealth","OpenSearchCatNodes","WaitingHealthyClusterAbortedError","startedAt","Date","mustEndAt","waitingTimeStep","runs","waitingReason","UnhealthyClusterError","Promise","resolve","setTimeout","runningTime","health","nodes","ex","createClusterHealthStatusReason","OpenSearchCatClusterHealthStatus","currentStatus","clusterHealthStatus","minClusterHealthStatus","processorPercent","createProcessorReason","undefined","ramPercent","createMemoryReason","total","node","parseFloat","status","createWaitUntilHealthy","params"],"mappings":";;;;;;AAiBA,MAAMA,oBAAoB;AA0D1B,MAAMC;IASF,YAAmBC,MAAc,EAAEC,OAAgC,CAAE;aAF7D,OAAO,GAAG;QAGd,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,OAAO,GAAGC;QAEf,IAAI,CAAC,SAAS,GAAG,IAAIC,oBAAoB,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAIC,mBAAmB,IAAI,CAAC,MAAM;IACtD;IAEO,QAAc;QACjB,IAAI,CAAC,OAAO,GAAG;IACnB;IAKA,MAAa,KAAKF,OAAsB,EAA0C;QAC9E,IAAI,IAAI,CAAC,OAAO,EACZ,MAAM,IAAIG,kCACN;QAGR,MAAMC,YAAY,IAAIC;QACtB,MAAMC,YAAY,IAAID,KAAKD,UAAU,OAAO,KAAK,AAA8B,OAA9B,IAAI,CAAC,OAAO,CAAC,cAAc;QAC5E,MAAMG,kBAAkB,IAAI,CAAC,OAAO,CAAC,eAAe,IAAIV;QACxD,IAAIW,OAAO;QACX,IAAIC;QACJ,MAAQA,gBAAgB,MAAM,IAAI,CAAC,UAAU,GAAK;YAC9C,IAAI,IAAIJ,UAAUC,WAAW;gBACzB,IAAIN,SAAS,WACT,MAAMA,QAAQ,SAAS,CAAC;oBACpBI;oBACAE;oBACAC;oBACAE;oBACAD;gBACJ;gBAEJ,MAAM,IAAIE,sBAAsB,IAAI,CA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ntilHealthy.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"],"names":["WAITING_TIME_STEP","WaitUntilHealthy","client","options","OpenSearchCatHealth","OpenSearchCatNodes","WaitingHealthyClusterAbortedError","startedAt","Date","mustEndAt","waitingTimeStep","runs","waitingReason","UnhealthyClusterError","Promise","resolve","setTimeout","runningTime","health","nodes","ex","createClusterHealthStatusReason","OpenSearchCatClusterHealthStatus","currentStatus","clusterHealthStatus","minClusterHealthStatus","processorPercent","createProcessorReason","undefined","ramPercent","createMemoryReason","total","node","parseFloat","status","createWaitUntilHealthy","params"],"mappings":";;;;;;AAiBA,MAAMA,oBAAoB;AA0D1B,MAAMC;IASF,YAAmBC,MAAc,EAAEC,OAAgC,CAAE;aAF7D,OAAO,GAAG;QAGd,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,OAAO,GAAGC;QAEf,IAAI,CAAC,SAAS,GAAG,IAAIC,oBAAoB,IAAI,CAAC,MAAM;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAIC,mBAAmB,IAAI,CAAC,MAAM;IACtD;IAEO,QAAc;QACjB,IAAI,CAAC,OAAO,GAAG;IACnB;IAKA,MAAa,KAAKF,OAAsB,EAA0C;QAC9E,IAAI,IAAI,CAAC,OAAO,EACZ,MAAM,IAAIG,kCACN;QAGR,MAAMC,YAAY,IAAIC;QACtB,MAAMC,YAAY,IAAID,KAAKD,UAAU,OAAO,KAAK,AAA8B,OAA9B,IAAI,C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wC,EAAU;QACnF,OAAQA;YACJ,KAAKZ,iCAAiC,KAAK;gBACvC,OAAO;YACX,KAAKA,iCAAiC,MAAM;gBACxC,OAAO;YACX,KAAKA,iCAAiC,GAAG;gBACrC,OAAO;YACX;gBACI,OAAO;QACf;IACJ;AACJ;AAIO,MAAMa,yBAAyB,CAClCjC,QACAkC,SAEO,IAAInC,iBAAiBC,QAAQkC"}
|
package/where.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { OpenSearchBoolQueryConfig } from "./types.js";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { OpenSearchField } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
|
|
3
|
+
import type { OpenSearchQueryBuilderOperator } from "./features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js";
|
|
4
4
|
type Records<T> = Record<string, T>;
|
|
5
5
|
export interface ApplyWhereParams {
|
|
6
6
|
query: OpenSearchBoolQueryConfig;
|
|
7
7
|
where: Records<any>;
|
|
8
|
-
fields: Records<
|
|
9
|
-
operators: Records<
|
|
8
|
+
fields: Records<OpenSearchField.Interface>;
|
|
9
|
+
operators: Records<OpenSearchQueryBuilderOperator.Interface>;
|
|
10
10
|
}
|
|
11
11
|
export interface ParseWhereKeyResult {
|
|
12
12
|
field: string;
|
package/where.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenSearchFieldAll } from "./features/OpenSearchField/abstractions/OpenSearchField.js";
|
|
2
2
|
import error from "@webiny/error";
|
|
3
3
|
const parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);
|
|
4
4
|
const parseWhereKey = (key)=>{
|
|
@@ -12,7 +12,7 @@ const parseWhereKey = (key)=>{
|
|
|
12
12
|
operator
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
const ALL =
|
|
15
|
+
const ALL = OpenSearchFieldAll;
|
|
16
16
|
const applyWhere = (params)=>{
|
|
17
17
|
const { query, where, fields, operators } = params;
|
|
18
18
|
for(const key in where){
|
|
@@ -24,8 +24,8 @@ const applyWhere = (params)=>{
|
|
|
24
24
|
if (!fieldPlugin) throw new error(`Missing plugin for the field "${field}".`, "PLUGIN_WHERE_ERROR", {
|
|
25
25
|
field
|
|
26
26
|
});
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
27
|
+
const operatorInstance = operators[operator];
|
|
28
|
+
if (!operatorInstance) throw new error(`Missing plugin for the operator "${operator}"`, "PLUGIN_WHERE_ERROR", {
|
|
29
29
|
operator
|
|
30
30
|
});
|
|
31
31
|
const path = fieldPlugin.getPath(field);
|
|
@@ -35,7 +35,7 @@ const applyWhere = (params)=>{
|
|
|
35
35
|
path,
|
|
36
36
|
basePath
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
operatorInstance.apply(query, {
|
|
39
39
|
name: field,
|
|
40
40
|
value,
|
|
41
41
|
path,
|
package/where.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"where.js","sources":["../src/where.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"~/types.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"where.js","sources":["../src/where.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"~/types.js\";\nimport {\n OpenSearchField,\n OpenSearchFieldAll\n} from \"~/features/OpenSearchField/abstractions/OpenSearchField.js\";\nimport type { OpenSearchQueryBuilderOperator } from \"~/features/OpenSearchQueryBuilderOperator/abstractions/OpenSearchQueryBuilderOperator.js\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: OpenSearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<OpenSearchField.Interface>;\n operators: Records<OpenSearchQueryBuilderOperator.Interface>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\nconst parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);\n\nexport const parseWhereKey = (key: string): ParseWhereKeyResult => {\n const match = key.match(parseWhereKeyRegExp);\n\n if (!match) {\n throw new Error(`It is not possible to search by key \"${key}\"`);\n }\n\n const [, field, operation = \"eq\"] = match;\n\n if (!field.match(/^(?:wbyAco_)?([a-zA-Z0-9]+)$/)) {\n throw new Error(`Cannot filter by \"${field}\".`);\n }\n\n const operator = operation.match(/^_/) ? operation.slice(1) : operation;\n\n return { field, operator };\n};\n\nconst ALL = OpenSearchFieldAll;\n\nexport const applyWhere = (params: ApplyWhereParams): void => {\n const { query, where, fields, operators } = params;\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n const initialValue = where[key];\n if (initialValue === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const fieldPlugin: OpenSearchField.Interface = fields[field] || fields[ALL];\n if (!fieldPlugin) {\n throw new WebinyError(\n `Missing plugin for the field \"${field}\".`,\n \"PLUGIN_WHERE_ERROR\",\n {\n field\n }\n );\n }\n const operatorInstance = operators[operator];\n if (!operatorInstance) {\n throw new WebinyError(\n `Missing plugin for the operator \"${operator}\"`,\n \"PLUGIN_WHERE_ERROR\",\n {\n operator\n }\n );\n }\n\n const path = fieldPlugin.getPath(field);\n const basePath = fieldPlugin.getBasePath(field);\n const value = fieldPlugin.toSearchValue({\n value: initialValue,\n path,\n basePath\n });\n\n operatorInstance.apply(query, {\n name: field,\n value,\n path,\n basePath,\n keyword: fieldPlugin.keyword\n });\n }\n};\n"],"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","ALL","OpenSearchFieldAll","applyWhere","params","query","where","fields","operators","initialValue","undefined","fieldPlugin","WebinyError","operatorInstance","path","basePath","value"],"mappings":";;AAsBA,MAAMA,sBAAsB,IAAIC,OAAO;AAEhC,MAAMC,gBAAgB,CAACC;IAC1B,MA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O;YAC1B,MAAMP;YACNkB;YACAF;YACAC;YACA,SAASJ,YAAY,OAAO;QAChC;IACJ;AACJ"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OpenSearchClient as OpenSearchClientAbstraction } from "./abstraction.js";
|
|
2
|
-
import type { Client } from "../../types.js";
|
|
3
|
-
import { OpenSearchContext } from "../../features/OpenSearchContext/abstraction.js";
|
|
4
|
-
declare class OpenSearchClientImpl implements OpenSearchClientAbstraction.Interface {
|
|
5
|
-
private readonly context;
|
|
6
|
-
constructor(context: OpenSearchContext.Interface);
|
|
7
|
-
use(): Client;
|
|
8
|
-
}
|
|
9
|
-
export declare const OpenSearchClient: typeof OpenSearchClientImpl & {
|
|
10
|
-
__abstraction: import("@webiny/di").Abstraction<import("./abstraction.js").IOpenSearchClient>;
|
|
11
|
-
};
|
|
12
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OpenSearchClient } from "./abstraction.js";
|
|
2
|
-
import { OpenSearchContext } from "../OpenSearchContext/abstraction.js";
|
|
3
|
-
class OpenSearchClientImpl {
|
|
4
|
-
constructor(context){
|
|
5
|
-
this.context = context;
|
|
6
|
-
}
|
|
7
|
-
use() {
|
|
8
|
-
return this.context.opensearch;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const OpenSearchClient_OpenSearchClient = OpenSearchClient.createImplementation({
|
|
12
|
-
implementation: OpenSearchClientImpl,
|
|
13
|
-
dependencies: [
|
|
14
|
-
OpenSearchContext
|
|
15
|
-
]
|
|
16
|
-
});
|
|
17
|
-
export { OpenSearchClient_OpenSearchClient as OpenSearchClient };
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=OpenSearchClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/OpenSearchClient/OpenSearchClient.js","sources":["../../../src/features/OpenSearchClient/OpenSearchClient.ts"],"sourcesContent":["import { OpenSearchClient as OpenSearchClientAbstraction } from \"./abstraction.js\";\nimport type { Client } from \"~/types.js\";\nimport { OpenSearchContext } from \"~/features/OpenSearchContext/abstraction.js\";\n\nclass OpenSearchClientImpl implements OpenSearchClientAbstraction.Interface {\n public constructor(private readonly context: OpenSearchContext.Interface) {}\n\n public use(): Client {\n return this.context.opensearch;\n }\n}\n\nexport const OpenSearchClient = OpenSearchClientAbstraction.createImplementation({\n implementation: OpenSearchClientImpl,\n dependencies: [OpenSearchContext]\n});\n"],"names":["OpenSearchClientImpl","context","OpenSearchClient","OpenSearchClientAbstraction","OpenSearchContext"],"mappings":";;AAIA,MAAMA;IACF,YAAoCC,OAAoC,CAAE;aAAtCA,OAAO,GAAPA;IAAuC;IAEpE,MAAc;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;IAClC;AACJ;AAEO,MAAMC,oCAAmBC,iBAAAA,oBAAgD,CAAC;IAC7E,gBAAgBH;IAChB,cAAc;QAACI;KAAkB;AACrC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { OpenSearchContext as OpenSearchContextAbstraction } from "./abstraction.js";
|
|
2
|
-
import { OpenSearchContext as OpenSearchContextType } from "../../types.js";
|
|
3
|
-
export declare class OpenSearchContext implements OpenSearchContextAbstraction.Interface {
|
|
4
|
-
private readonly context;
|
|
5
|
-
constructor(context: OpenSearchContextType);
|
|
6
|
-
get opensearch(): OpenSearchContextAbstraction.Client;
|
|
7
|
-
get elasticsearch(): OpenSearchContextAbstraction.Client;
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class OpenSearchContext {
|
|
2
|
-
constructor(context){
|
|
3
|
-
this.context = context;
|
|
4
|
-
}
|
|
5
|
-
get opensearch() {
|
|
6
|
-
return this.context.opensearch;
|
|
7
|
-
}
|
|
8
|
-
get elasticsearch() {
|
|
9
|
-
return this.context.opensearch;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export { OpenSearchContext };
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=OpenSearchContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/OpenSearchContext/OpenSearchContext.js","sources":["../../../src/features/OpenSearchContext/OpenSearchContext.ts"],"sourcesContent":["import { OpenSearchContext as OpenSearchContextAbstraction } from \"./abstraction.js\";\nimport { OpenSearchContext as OpenSearchContextType } from \"~/types.js\";\n\nexport class OpenSearchContext implements OpenSearchContextAbstraction.Interface {\n private readonly context;\n\n public constructor(context: OpenSearchContextType) {\n this.context = context;\n }\n\n public get opensearch(): OpenSearchContextAbstraction.Client {\n return this.context.opensearch;\n }\n\n public get elasticsearch(): OpenSearchContextAbstraction.Client {\n return this.context.opensearch;\n }\n}\n"],"names":["OpenSearchContext","context"],"mappings":"AAGO,MAAMA;IAGT,YAAmBC,OAA8B,CAAE;QAC/C,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,IAAW,aAAkD;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;IAClC;IAEA,IAAW,gBAAqD;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;IAClC;AACJ"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Client as OpenSearchClient } from "../../types.js";
|
|
2
|
-
export interface IOpenSearchContext {
|
|
3
|
-
opensearch: OpenSearchClient;
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated use `opensearch`property instead.
|
|
6
|
-
* @see IOpenSearchContext.opensearch
|
|
7
|
-
*/
|
|
8
|
-
elasticsearch: OpenSearchClient;
|
|
9
|
-
}
|
|
10
|
-
export declare const OpenSearchContext: import("@webiny/di").Abstraction<IOpenSearchContext>;
|
|
11
|
-
export declare namespace OpenSearchContext {
|
|
12
|
-
type Interface = IOpenSearchContext;
|
|
13
|
-
type Client = OpenSearchClient;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/OpenSearchContext/abstraction.js","sources":["../../../src/features/OpenSearchContext/abstraction.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Client as OpenSearchClient } from \"~/types.js\";\n\nexport interface IOpenSearchContext {\n opensearch: OpenSearchClient;\n /**\n * @deprecated use `opensearch`property instead.\n * @see IOpenSearchContext.opensearch\n */\n elasticsearch: OpenSearchClient;\n}\n\nexport const OpenSearchContext = createAbstraction<IOpenSearchContext>(\"OpenSearch/Context\");\n\nexport namespace OpenSearchContext {\n export type Interface = IOpenSearchContext;\n export type Client = OpenSearchClient;\n}\n"],"names":["OpenSearchContext","createAbstraction"],"mappings":";AAYO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api/index.js";
|
|
2
|
-
import { OpenSearchContext } from "./abstraction.js";
|
|
3
|
-
import { OpenSearchContext as external_OpenSearchContext_js_OpenSearchContext } from "./OpenSearchContext.js";
|
|
4
|
-
const OpenSearchContextFeature = createFeature({
|
|
5
|
-
name: "opensearch.internal.context",
|
|
6
|
-
register (container, context) {
|
|
7
|
-
container.registerFactory(OpenSearchContext, ()=>new external_OpenSearchContext_js_OpenSearchContext(context));
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
export { OpenSearchContextFeature };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/OpenSearchContext/feature.js","sources":["../../../src/features/OpenSearchContext/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { OpenSearchContext } from \"./abstraction.js\";\nimport { OpenSearchContext as OpenSearchContextType } from \"~/types.js\";\nimport { OpenSearchContext as OpenSearchContextImplementation } from \"./OpenSearchContext.js\";\n\nexport const OpenSearchContextFeature = createFeature<OpenSearchContextType>({\n name: \"opensearch.internal.context\",\n register(container, context) {\n container.registerFactory(OpenSearchContext, () => {\n return new OpenSearchContextImplementation(context!);\n });\n }\n});\n"],"names":["OpenSearchContextFeature","createFeature","container","context","OpenSearchContext","OpenSearchContextImplementation"],"mappings":";;;AAKO,MAAMA,2BAA2BC,cAAqC;IACzE,MAAM;IACN,UAASC,SAAS,EAAEC,OAAO;QACvBD,UAAU,eAAe,CAACE,mBAAmB,IAClC,IAAIC,gDAAgCF;IAEnD;AACJ"}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/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"],"names":["createOpenSearchContext","params","plugin","ContextPlugin","context","Error","client","Client","createOpenSearchClient","getOpenSearchOperators","OpenSearchContextFeature","OpenSearchClientFeature","OpenSearchClientFactoryFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+BO,MAAMA,0BAA0B,CACnCC;IAEA,MAAMC,SAAS,IAAIC,cAAiCC,CAAAA;QAChD,IAAIA,QAAQ,UAAU,EAClB,MAAM,IAAIC,MAAM;QAEpB,MAAMC,SAASL,kBAAkBM,SAASN,SAASO,uBAAuBP;QAC1EG,QAAQ,UAAU,GAAGE;QACrBF,QAAQ,aAAa,GAAGE;QAExBF,QAAQ,OAAO,CAAC,QAAQ,CAACK;QAEzBC,yBAAyB,QAAQ,CAACN,QAAQ,SAAS,EAAEA;QACrDO,wBAAwB,QAAQ,CAACP,QAAQ,SAAS;QAClDQ,+BAA+B,QAAQ,CAACR,QAAQ,SAAS;IAC7D;IAEAF,OAAO,IAAI,GAAG;IAEd,OAAOA;AACX"}
|
package/indices.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"indices.js","sources":["../src/indices.ts"],"sourcesContent":["import type { OpenSearchIndexPlugin } from \"~/plugins/definition/OpenSearchIndexPlugin.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\n\ninterface IndicesPluginsParams {\n container: PluginsContainer;\n type: string;\n}\nconst listIndicesPlugins = <T extends OpenSearchIndexPlugin>({\n container,\n type\n}: IndicesPluginsParams): T[] => {\n return container.byType<T>(type).filter(plugin => {\n return plugin.canUse();\n });\n};\n\nexport const getLastAddedIndexPlugin = <T extends OpenSearchIndexPlugin>(\n params: IndicesPluginsParams\n): T => {\n const plugins = listIndicesPlugins<T>(params);\n if (plugins.length === 0) {\n throw new WebinyError(\n `Could not find a single OpenSearchIndexPlugin of type \"${params.type}\".`,\n \"OPENSEARCH_INDEX_TEMPLATE_ERROR\",\n {\n type: params.type\n }\n );\n }\n\n return plugins.pop() as T;\n};\n"],"names":["listIndicesPlugins","container","type","plugin","getLastAddedIndexPlugin","params","plugins","WebinyError"],"mappings":";AAQA,MAAMA,qBAAqB,CAAkC,EACzDC,SAAS,EACTC,IAAI,EACe,GACZD,UAAU,MAAM,CAAIC,MAAM,MAAM,CAACC,CAAAA,SAC7BA,OAAO,MAAM;AAIrB,MAAMC,0BAA0B,CACnCC;IAEA,MAAMC,UAAUN,mBAAsBK;IACtC,IAAIC,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIC,MACN,CAAC,uDAAuD,EAAEF,OAAO,IAAI,CAAC,EAAE,CAAC,EACzE,mCACA;QACI,MAAMA,OAAO,IAAI;IACrB;IAIR,OAAOC,QAAQ,GAAG;AACtB"}
|
package/operators.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { OpenSearchQueryBuilderOperatorBetweenPlugin, OpenSearchQueryBuilderOperatorAndInPlugin, OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin, OpenSearchQueryBuilderOperatorGreaterThanPlugin, OpenSearchQueryBuilderOperatorContainsPlugin, OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin, OpenSearchQueryBuilderOperatorInPlugin, OpenSearchQueryBuilderOperatorLesserThanPlugin, OpenSearchQueryBuilderOperatorNotBetweenPlugin, OpenSearchQueryBuilderOperatorNotContainsPlugin, OpenSearchQueryBuilderOperatorNotPlugin, OpenSearchQueryBuilderOperatorNotInPlugin, OpenSearchQueryBuilderOperatorEqualPlugin, OpenSearchQueryBuilderOperatorStartsWithPlugin, OpenSearchQueryBuilderOperatorNotStartsWithPlugin } from "./plugins/operator/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* We export as a function because there might be something to be sent to the operators at some point.
|
|
4
|
-
* This way, we make it easier to upgrade.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getOpenSearchOperators: () => (OpenSearchQueryBuilderOperatorBetweenPlugin | OpenSearchQueryBuilderOperatorContainsPlugin | OpenSearchQueryBuilderOperatorEqualPlugin | OpenSearchQueryBuilderOperatorGreaterThanPlugin | OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin | OpenSearchQueryBuilderOperatorAndInPlugin | OpenSearchQueryBuilderOperatorInPlugin | OpenSearchQueryBuilderOperatorLesserThanPlugin | OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin | OpenSearchQueryBuilderOperatorNotPlugin | OpenSearchQueryBuilderOperatorNotBetweenPlugin | OpenSearchQueryBuilderOperatorNotContainsPlugin | OpenSearchQueryBuilderOperatorNotInPlugin | OpenSearchQueryBuilderOperatorStartsWithPlugin | OpenSearchQueryBuilderOperatorNotStartsWithPlugin)[];
|
package/operators.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { OpenSearchQueryBuilderOperatorAndInPlugin, OpenSearchQueryBuilderOperatorBetweenPlugin, OpenSearchQueryBuilderOperatorContainsPlugin, OpenSearchQueryBuilderOperatorEqualPlugin, OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin, OpenSearchQueryBuilderOperatorGreaterThanPlugin, OpenSearchQueryBuilderOperatorInPlugin, OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin, OpenSearchQueryBuilderOperatorLesserThanPlugin, OpenSearchQueryBuilderOperatorNotBetweenPlugin, OpenSearchQueryBuilderOperatorNotContainsPlugin, OpenSearchQueryBuilderOperatorNotInPlugin, OpenSearchQueryBuilderOperatorNotPlugin, OpenSearchQueryBuilderOperatorNotStartsWithPlugin, OpenSearchQueryBuilderOperatorStartsWithPlugin } from "./plugins/operator/index.js";
|
|
2
|
-
const operators = [
|
|
3
|
-
new OpenSearchQueryBuilderOperatorBetweenPlugin(),
|
|
4
|
-
new OpenSearchQueryBuilderOperatorNotBetweenPlugin(),
|
|
5
|
-
new OpenSearchQueryBuilderOperatorContainsPlugin(),
|
|
6
|
-
new OpenSearchQueryBuilderOperatorNotContainsPlugin(),
|
|
7
|
-
new OpenSearchQueryBuilderOperatorEqualPlugin(),
|
|
8
|
-
new OpenSearchQueryBuilderOperatorNotPlugin(),
|
|
9
|
-
new OpenSearchQueryBuilderOperatorGreaterThanPlugin(),
|
|
10
|
-
new OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin(),
|
|
11
|
-
new OpenSearchQueryBuilderOperatorLesserThanPlugin(),
|
|
12
|
-
new OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin(),
|
|
13
|
-
new OpenSearchQueryBuilderOperatorInPlugin(),
|
|
14
|
-
new OpenSearchQueryBuilderOperatorAndInPlugin(),
|
|
15
|
-
new OpenSearchQueryBuilderOperatorNotInPlugin(),
|
|
16
|
-
new OpenSearchQueryBuilderOperatorStartsWithPlugin(),
|
|
17
|
-
new OpenSearchQueryBuilderOperatorNotStartsWithPlugin()
|
|
18
|
-
];
|
|
19
|
-
const getOpenSearchOperators = ()=>operators;
|
|
20
|
-
export { getOpenSearchOperators };
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=operators.js.map
|
package/operators.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operators.js","sources":["../src/operators.ts"],"sourcesContent":["import {\n OpenSearchQueryBuilderOperatorBetweenPlugin,\n OpenSearchQueryBuilderOperatorAndInPlugin,\n OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin,\n OpenSearchQueryBuilderOperatorGreaterThanPlugin,\n OpenSearchQueryBuilderOperatorContainsPlugin,\n OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin,\n OpenSearchQueryBuilderOperatorInPlugin,\n OpenSearchQueryBuilderOperatorLesserThanPlugin,\n OpenSearchQueryBuilderOperatorNotBetweenPlugin,\n OpenSearchQueryBuilderOperatorNotContainsPlugin,\n OpenSearchQueryBuilderOperatorNotPlugin,\n OpenSearchQueryBuilderOperatorNotInPlugin,\n OpenSearchQueryBuilderOperatorEqualPlugin,\n OpenSearchQueryBuilderOperatorStartsWithPlugin,\n OpenSearchQueryBuilderOperatorNotStartsWithPlugin\n} from \"~/plugins/operator/index.js\";\n\nconst operators = [\n new OpenSearchQueryBuilderOperatorBetweenPlugin(),\n new OpenSearchQueryBuilderOperatorNotBetweenPlugin(),\n new OpenSearchQueryBuilderOperatorContainsPlugin(),\n new OpenSearchQueryBuilderOperatorNotContainsPlugin(),\n new OpenSearchQueryBuilderOperatorEqualPlugin(),\n new OpenSearchQueryBuilderOperatorNotPlugin(),\n new OpenSearchQueryBuilderOperatorGreaterThanPlugin(),\n new OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin(),\n new OpenSearchQueryBuilderOperatorLesserThanPlugin(),\n new OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin(),\n new OpenSearchQueryBuilderOperatorInPlugin(),\n new OpenSearchQueryBuilderOperatorAndInPlugin(),\n new OpenSearchQueryBuilderOperatorNotInPlugin(),\n new OpenSearchQueryBuilderOperatorStartsWithPlugin(),\n new OpenSearchQueryBuilderOperatorNotStartsWithPlugin()\n];\n/**\n * We export as a function because there might be something to be sent to the operators at some point.\n * This way, we make it easier to upgrade.\n */\nexport const getOpenSearchOperators = () => operators;\n"],"names":["operators","OpenSearchQueryBuilderOperatorBetweenPlugin","OpenSearchQueryBuilderOperatorNotBetweenPlugin","OpenSearchQueryBuilderOperatorContainsPlugin","OpenSearchQueryBuilderOperatorNotContainsPlugin","OpenSearchQueryBuilderOperatorEqualPlugin","OpenSearchQueryBuilderOperatorNotPlugin","OpenSearchQueryBuilderOperatorGreaterThanPlugin","OpenSearchQueryBuilderOperatorGreaterThanOrEqualToPlugin","OpenSearchQueryBuilderOperatorLesserThanPlugin","OpenSearchQueryBuilderOperatorLesserThanOrEqualToPlugin","OpenSearchQueryBuilderOperatorInPlugin","OpenSearchQueryBuilderOperatorAndInPlugin","OpenSearchQueryBuilderOperatorNotInPlugin","OpenSearchQueryBuilderOperatorStartsWithPlugin","OpenSearchQueryBuilderOperatorNotStartsWithPlugin","getOpenSearchOperators"],"mappings":";AAkBA,MAAMA,YAAY;IACd,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;CACP;AAKM,MAAMC,yBAAyB,IAAMhB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { SearchBody } from "../../types.js";
|
|
3
|
-
export interface ModifyBodyParams {
|
|
4
|
-
body: SearchBody;
|
|
5
|
-
}
|
|
6
|
-
export interface ModifyBodyCallable<T extends ModifyBodyParams> {
|
|
7
|
-
(params: T): void;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class OpenSearchBodyModifierPlugin<T extends ModifyBodyParams = ModifyBodyParams> extends Plugin {
|
|
10
|
-
private readonly callable?;
|
|
11
|
-
constructor(callable?: ModifyBodyCallable<T>);
|
|
12
|
-
modifyBody(params: T): void;
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
class OpenSearchBodyModifierPlugin extends Plugin {
|
|
4
|
-
constructor(callable){
|
|
5
|
-
super();
|
|
6
|
-
this.callable = callable;
|
|
7
|
-
}
|
|
8
|
-
modifyBody(params) {
|
|
9
|
-
if ("function" != typeof this.callable) throw new error("Missing modification for the body.", "BODY_MODIFICATION_MISSING", {
|
|
10
|
-
params
|
|
11
|
-
});
|
|
12
|
-
this.callable(params);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export { OpenSearchBodyModifierPlugin };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=OpenSearchBodyModifierPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins/definition/OpenSearchBodyModifierPlugin.js","sources":["../../../src/plugins/definition/OpenSearchBodyModifierPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { SearchBody } from \"~/types.js\";\n\nexport interface ModifyBodyParams {\n body: SearchBody;\n}\n\nexport interface ModifyBodyCallable<T extends ModifyBodyParams> {\n (params: T): void;\n}\n\nexport abstract class OpenSearchBodyModifierPlugin<\n T extends ModifyBodyParams = ModifyBodyParams\n> extends Plugin {\n private readonly callable?: ModifyBodyCallable<T>;\n\n public constructor(callable?: ModifyBodyCallable<T>) {\n super();\n this.callable = callable;\n }\n\n public modifyBody(params: T): void {\n if (typeof this.callable !== \"function\") {\n throw new WebinyError(\n `Missing modification for the body.`,\n \"BODY_MODIFICATION_MISSING\",\n {\n params\n }\n );\n }\n this.callable(params);\n }\n}\n"],"names":["OpenSearchBodyModifierPlugin","Plugin","callable","params","WebinyError"],"mappings":";;AAYO,MAAeA,qCAEZC;IAGN,YAAmBC,QAAgC,CAAE;QACjD,KAAK;QACL,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEO,WAAWC,MAAS,EAAQ;QAC/B,IAAI,AAAyB,cAAzB,OAAO,IAAI,CAAC,QAAQ,EACpB,MAAM,IAAIC,MACN,sCACA,6BACA;YACID;QACJ;QAGR,IAAI,CAAC,QAAQ,CAACA;IAClB;AACJ"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { FieldSortOptions, SortOrder } from "../../types.js";
|
|
3
|
-
export type UnmappedTypes = "date" | "long" | string;
|
|
4
|
-
export interface ToSearchValueParams {
|
|
5
|
-
/**
|
|
6
|
-
* The value to transform.
|
|
7
|
-
*/
|
|
8
|
-
value: any;
|
|
9
|
-
/**
|
|
10
|
-
* When using toSearchValue() in our code we send a field.getPath() value here.
|
|
11
|
-
*/
|
|
12
|
-
path: string;
|
|
13
|
-
/**
|
|
14
|
-
* When using toSearchValue() in our code we send a field.getBasePath() value here.
|
|
15
|
-
*/
|
|
16
|
-
basePath: string;
|
|
17
|
-
}
|
|
18
|
-
export interface OpenSearchFieldPluginParams {
|
|
19
|
-
/**
|
|
20
|
-
* Which field is this plugin for.
|
|
21
|
-
*/
|
|
22
|
-
field: string;
|
|
23
|
-
/**
|
|
24
|
-
* Some specific path of a field?
|
|
25
|
-
* Example: createdBy is createdBy.id
|
|
26
|
-
*/
|
|
27
|
-
path?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Add a .keyword at the end of the field path?
|
|
30
|
-
*/
|
|
31
|
-
keyword?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Is the field of a specific type, but possibly not mapped?
|
|
34
|
-
* Happens when inserting a date in string format.
|
|
35
|
-
* You need to cast it as date when running the search/sort to work correctly.
|
|
36
|
-
*/
|
|
37
|
-
unmappedType?: UnmappedTypes;
|
|
38
|
-
/**
|
|
39
|
-
* Is the field sortable?
|
|
40
|
-
*/
|
|
41
|
-
sortable?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Is the field searchable?
|
|
44
|
-
*/
|
|
45
|
-
searchable?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Used to transform the input value for the search.
|
|
48
|
-
*/
|
|
49
|
-
toSearchValue?: (params: ToSearchValueParams) => any;
|
|
50
|
-
}
|
|
51
|
-
export declare class OpenSearchFieldPlugin extends Plugin {
|
|
52
|
-
static readonly type: string;
|
|
53
|
-
static readonly ALL: string;
|
|
54
|
-
readonly field: string;
|
|
55
|
-
readonly path: string;
|
|
56
|
-
readonly keyword: boolean;
|
|
57
|
-
readonly unmappedType?: string;
|
|
58
|
-
readonly sortable: boolean;
|
|
59
|
-
readonly searchable: boolean;
|
|
60
|
-
constructor(params: OpenSearchFieldPluginParams);
|
|
61
|
-
/**
|
|
62
|
-
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
63
|
-
*/
|
|
64
|
-
getSortOptions(order: SortOrder): FieldSortOptions;
|
|
65
|
-
/**
|
|
66
|
-
* The default path generator. Extend in your own plugin if you want to add more options.
|
|
67
|
-
* 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.
|
|
68
|
-
*/
|
|
69
|
-
getPath(field: string): string;
|
|
70
|
-
/**
|
|
71
|
-
* @see getPath
|
|
72
|
-
*
|
|
73
|
-
* This is the default base path generator. Basically it replaces ALL with given field name.
|
|
74
|
-
*/
|
|
75
|
-
getBasePath(field: string): string;
|
|
76
|
-
/**
|
|
77
|
-
* The default transformer. Just returns the value by default.
|
|
78
|
-
* Override to implement what ever is required.
|
|
79
|
-
*/
|
|
80
|
-
toSearchValue(params: ToSearchValueParams): any;
|
|
81
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins/definition/OpenSearchFieldPlugin.js","sources":["../../../src/plugins/definition/OpenSearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\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 // TODO: Cast to the proper MappingFieldType once deep opensearch _types/ imports are resolvable under bundler resolution.\n unmapped_type: this.unmappedType as any\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"],"names":["keywordLessUnmappedType","unmappedTypeHasKeyword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IAKO,cAAcJ,MAA2B,EAAO;QACnD,OAAOA,OAAO,KAAK;IACvB;AACJ"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { OpenSearchIndexRequestBody } from "../../types.js";
|
|
3
|
-
export interface OpenSearchIndexPluginParams {
|
|
4
|
-
body: OpenSearchIndexRequestBody;
|
|
5
|
-
}
|
|
6
|
-
export declare abstract class OpenSearchIndexPlugin extends Plugin {
|
|
7
|
-
readonly body: OpenSearchIndexRequestBody;
|
|
8
|
-
constructor(params: OpenSearchIndexPluginParams);
|
|
9
|
-
canUse(): boolean;
|
|
10
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
class OpenSearchIndexPlugin extends Plugin {
|
|
3
|
-
constructor(params){
|
|
4
|
-
super();
|
|
5
|
-
const { body } = params;
|
|
6
|
-
this.body = {
|
|
7
|
-
...body
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
canUse() {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export { OpenSearchIndexPlugin };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=OpenSearchIndexPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins/definition/OpenSearchIndexPlugin.js","sources":["../../../src/plugins/definition/OpenSearchIndexPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { OpenSearchIndexRequestBody } from \"~/types.js\";\n\nexport interface OpenSearchIndexPluginParams {\n body: OpenSearchIndexRequestBody;\n}\n\nexport abstract class OpenSearchIndexPlugin extends Plugin {\n public readonly body: OpenSearchIndexRequestBody;\n\n public constructor(params: OpenSearchIndexPluginParams) {\n super();\n const { body } = params;\n this.body = {\n ...body\n };\n }\n\n public canUse(): boolean {\n return true;\n }\n}\n"],"names":["OpenSearchIndexPlugin","Plugin","params","body"],"mappings":";AAOO,MAAeA,8BAA8BC;IAGhD,YAAmBC,MAAmC,CAAE;QACpD,KAAK;QACL,MAAM,EAAEC,IAAI,EAAE,GAAGD;QACjB,IAAI,CAAC,IAAI,GAAG;YACR,GAAGC,IAAI;QACX;IACJ;IAEO,SAAkB;QACrB,OAAO;IACX;AACJ"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { OpenSearchBoolQueryConfig, OpenSearchQueryBuilderArgsPlugin } from "../../types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Built-in operators name ends with .default because user can override the operator, just write a name without the .default keyword.
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class OpenSearchQueryBuilderOperatorPlugin extends Plugin {
|
|
7
|
-
static readonly type: string;
|
|
8
|
-
abstract getOperator(): string;
|
|
9
|
-
abstract apply(query: OpenSearchBoolQueryConfig, params: OpenSearchQueryBuilderArgsPlugin): void;
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
class OpenSearchQueryBuilderOperatorPlugin extends Plugin {
|
|
3
|
-
static{
|
|
4
|
-
this.type = "opensearch.queryBuilder.operator";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export { OpenSearchQueryBuilderOperatorPlugin };
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=OpenSearchQueryBuilderOperatorPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins/definition/OpenSearchQueryBuilderOperatorPlugin.js","sources":["../../../src/plugins/definition/OpenSearchQueryBuilderOperatorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { OpenSearchBoolQueryConfig, OpenSearchQueryBuilderArgsPlugin } from \"~/types.js\";\n\n/**\n * Built-in operators name ends with .default because user can override the operator, just write a name without the .default keyword.\n */\nexport abstract class OpenSearchQueryBuilderOperatorPlugin extends Plugin {\n public static override readonly type: string = \"opensearch.queryBuilder.operator\";\n\n public abstract getOperator(): string;\n\n public abstract apply(\n query: OpenSearchBoolQueryConfig,\n params: OpenSearchQueryBuilderArgsPlugin\n ): void;\n}\n"],"names":["OpenSearchQueryBuilderOperatorPlugin","Plugin"],"mappings":";AAMO,MAAeA,6CAA6CC;;aAC/B,IAAI,GAAW;;AAQnD"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { OpenSearchBoolQueryConfig } from "../../types.js";
|
|
3
|
-
export interface ModifyQueryParams {
|
|
4
|
-
query: OpenSearchBoolQueryConfig;
|
|
5
|
-
where: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
export interface ModifyQueryCallable<T extends ModifyQueryParams> {
|
|
8
|
-
(params: T): void;
|
|
9
|
-
}
|
|
10
|
-
export declare abstract class OpenSearchQueryModifierPlugin<T extends ModifyQueryParams = ModifyQueryParams> extends Plugin {
|
|
11
|
-
private readonly callable?;
|
|
12
|
-
constructor(callable?: ModifyQueryCallable<T>);
|
|
13
|
-
modifyQuery(params: T): void;
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
class OpenSearchQueryModifierPlugin extends Plugin {
|
|
4
|
-
constructor(callable){
|
|
5
|
-
super();
|
|
6
|
-
this.callable = callable;
|
|
7
|
-
}
|
|
8
|
-
modifyQuery(params) {
|
|
9
|
-
if ("function" != typeof this.callable) throw new error("Missing modification for the query.", "QUERY_MODIFICATION_MISSING", {
|
|
10
|
-
params
|
|
11
|
-
});
|
|
12
|
-
this.callable(params);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export { OpenSearchQueryModifierPlugin };
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=OpenSearchQueryModifierPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugins/definition/OpenSearchQueryModifierPlugin.js","sources":["../../../src/plugins/definition/OpenSearchQueryModifierPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { OpenSearchBoolQueryConfig } from \"~/types.js\";\n\nexport interface ModifyQueryParams {\n query: OpenSearchBoolQueryConfig;\n where: Record<string, any>;\n}\n\nexport interface ModifyQueryCallable<T extends ModifyQueryParams> {\n (params: T): void;\n}\n\nexport abstract class OpenSearchQueryModifierPlugin<\n T extends ModifyQueryParams = ModifyQueryParams\n> extends Plugin {\n private readonly callable?: ModifyQueryCallable<T>;\n\n public constructor(callable?: ModifyQueryCallable<T>) {\n super();\n this.callable = callable;\n }\n\n public modifyQuery(params: T): void {\n if (typeof this.callable !== \"function\") {\n throw new WebinyError(\n `Missing modification for the query.`,\n \"QUERY_MODIFICATION_MISSING\",\n {\n params\n }\n );\n }\n this.callable(params);\n }\n}\n"],"names":["OpenSearchQueryModifierPlugin","Plugin","callable","params","WebinyError"],"mappings":";;AAaO,MAAeA,sCAEZC;IAGN,YAAmBC,QAAiC,CAAE;QAClD,KAAK;QACL,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEO,YAAYC,MAAS,EAAQ;QAChC,IAAI,AAAyB,cAAzB,OAAO,IAAI,CAAC,QAAQ,EACpB,MAAM,IAAIC,MACN,uCACA,8BACA;YACID;QACJ;QAGR,IAAI,CAAC,QAAQ,CAACA;IAClB;AACJ"}
|