@sebspark/opensearch 3.0.8 → 3.0.9
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/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/client.ts","../src/helpers.ts"],"sourcesContent":["import { type API, Client } from '@opensearch-project/opensearch'\nimport type {\n BulkRequest,\n BulkResponse,\n IndexDefinition,\n IndexRequest,\n SearchRequest,\n SearchResponse,\n} from './types'\nimport type {\n Indices,\n TransportRequestOptions,\n TransportRequestPromise,\n} from './types/common'\nimport type { IndicesExistsRequest } from './types/indx'\n\ntype TypedIndices = Omit<Indices, 'exists'> & {\n exists<T extends IndexDefinition>(\n params: IndicesExistsRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<API.Indices_Exists_Response>\n}\n\n/**\n * ✅ Custom interface that extends `Client`, but replaces the `search()` method signature.\n * - Uses `Omit<Client, \"search\">` to remove `search()` from `Client`.\n * - Defines a new `search<T>()` method with stricter type safety.\n */\nexport interface OpenSearchClient\n extends Omit<Client, 'search' | 'index' | 'bulk' | 'indices'> {\n search<T extends IndexDefinition>(\n params: SearchRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<SearchResponse<T>>\n\n index<T extends IndexDefinition>(\n params: IndexRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<API.Index_Response>\n\n bulk<T extends IndexDefinition>(\n params: BulkRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<BulkResponse<T>>\n\n indices: TypedIndices\n}\n\n/**\n * ✅ Constructor type that ensures `new OpenSearchClient()` works.\n * - This type is necessary because `OpenSearchClient` is actually a function (not a class).\n */\ntype OpenSearchClientConstructor = new (\n ...args: ConstructorParameters<typeof Client>\n) => OpenSearchClient\n\n/**\n * ✅ A function that behaves like a class constructor.\n * - Instantiates a new `Client` internally.\n * - Casts the instance to `OpenSearchClient` so TypeScript recognizes the new `search<T>()` signature.\n * - The `as unknown as` trick ensures `new OpenSearchClient()` is valid.\n */\nexport const OpenSearchClient: OpenSearchClientConstructor = function (\n this: Client,\n ...args: ConstructorParameters<typeof Client>\n) {\n const clientInstance = new Client(...args)\n return clientInstance as unknown as OpenSearchClient\n} as unknown as {\n new (...args: ConstructorParameters<typeof Client>): OpenSearchClient\n}\n","import type { Types } from '@opensearch-project/opensearch'\nimport type {\n BulkRequest,\n CreateOperation,\n DeleteOperation,\n IndexOperation,\n UpdateAction,\n UpdateOperation,\n} from './types/bulk'\nimport type { IndexDefinition } from './types/common'\nimport type { DocumentFor } from './types/documents'\n\nexport type IdFunction<T extends IndexDefinition> = (\n doc: DocumentFor<T>\n) => Types.Common.Id\n\n/**\n * Constructs a bulk request payload for indexing documents.\n *\n * For each document in the provided array, this helper creates a two‑line bulk operation:\n * 1. An action object for an index operation. If an id generator is provided, its result is used as _id.\n * 2. The document itself.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to insert.\n * @param idFn - Optional function that returns an _id for a given document.\n * @returns A BulkRequest payload for insert operations.\n */\nexport function bulkIndex<T extends IndexDefinition>(\n index: T['index'],\n docs: DocumentFor<T>[],\n idFn?: IdFunction<T>\n): BulkRequest<T> {\n const body = docs.flatMap((doc) => {\n const op: IndexOperation<T> = idFn ? { _id: idFn(doc) } : {}\n return [{ index: op }, doc]\n })\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for creating documents.\n *\n * For each document in the provided array, this helper creates a two‑line bulk operation:\n * 1. An action object for a create operation with a generated _id.\n * 2. The document itself.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to create.\n * @param idFn - A function that returns a unique _id for each document.\n * @returns A BulkRequest payload for create operations.\n */\nexport function bulkCreate<T extends IndexDefinition>(\n index: T['index'],\n docs: DocumentFor<T>[],\n idFn: IdFunction<T>\n): BulkRequest<T> {\n const body = docs.flatMap((doc) => {\n const op: CreateOperation<T> = { _id: idFn(doc) }\n return [{ create: op }, doc]\n })\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for update operations.\n *\n * This helper takes an array of update actions (of type UpdateAction<T>),\n * splits each into its action metadata and payload (with the `doc` and/or `upsert` properties),\n * and returns a BulkRequest payload formatted as a flat array.\n *\n * @param index - The name of the index.\n * @param updates - An array of update actions.\n * @param idFn - A function that returns a unique _id for each document.\n * @returns A BulkRequest payload for update operations.\n */\nexport function bulkUpdate<T extends IndexDefinition>(\n index: T['index'],\n updates: UpdateAction<T>[],\n idFn: IdFunction<T>\n): BulkRequest<T> {\n const body = updates.flatMap((update) => {\n const op: UpdateOperation<T> = {\n _id: idFn((update.doc as DocumentFor<T>) || update.upsert),\n }\n return [{ update: op }, update]\n })\n\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for deleting documents.\n *\n * For each document in the provided array, this helper creates a single‑line bulk operation:\n * { delete: { _id: <id> } }\n * The provided id generator function is used to compute the _id for each document.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to delete.\n * @param idFn - A function that returns the _id for a given document.\n * @returns A BulkRequest payload for delete operations.\n */\nexport function bulkDelete<T extends IndexDefinition>(\n index: T['index'],\n ids: Types.Common.Id[]\n): BulkRequest<T> {\n const body = ids.map((_id) => {\n const op: DeleteOperation<T> = { _id }\n return { delete: op }\n })\n return { index, body }\n}\n"],"mappings":";;;;;;;;;AA8DA,MAAa,mBAAgD,SAE3D,GAAG,MACH;AAEA,QADuB,IAAI,OAAO,GAAG,KAAK;;;;;;;;;;;;;;;;;ACtC5C,SAAgB,UACd,OACA,MACA,MACgB;AAKhB,QAAO;EAAE;EAAO,MAJH,KAAK,SAAS,QAAQ;AAEjC,UAAO,CAAC,EAAE,OADoB,OAAO,EAAE,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,EACvC,EAAE,IAAI;IAC3B;EACoB;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,MACA,MACgB;AAKhB,QAAO;EAAE;EAAO,MAJH,KAAK,SAAS,QAAQ;AAEjC,UAAO,CAAC,EAAE,QADqB,EAAE,KAAK,KAAK,IAAI,EAAE,EAC3B,EAAE,IAAI;IAC5B;EACoB;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,SACA,MACgB;AAQhB,QAAO;EAAE;EAAO,MAPH,QAAQ,SAAS,WAAW;AAIvC,UAAO,CAAC,EAAE,QAHqB,EAC7B,KAAK,KAAM,OAAO,OAA0B,OAAO,OAAO,EAC3D,EACqB,EAAE,OAAO;IAC/B;EAEoB;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,KACgB;AAKhB,QAAO;EAAE;EAAO,MAJH,IAAI,KAAK,QAAQ;AAE5B,UAAO,EAAE,QADsB,EAAE,KAAK,EACjB;IACrB;EACoB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/opensearch",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@sebspark/tsconfig": "
|
|
26
|
+
"@sebspark/tsconfig": "3.0.5",
|
|
27
27
|
"testcontainers": "11.11.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|