@sebspark/opensearch
Advanced tools
@@ -1,1 +0,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,QAAO,IADoB,OAAO,GAAG,KAChB;;;;;;;;;;;;;;;;ACvCvB,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;IAET;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,MACA,MACgB;AAKhB,QAAO;EAAE;EAAO,MAJH,KAAK,SAAS,QAAQ;AAEjC,UAAO,CAAC,EAAE,QAAQ,EADe,KAAK,KAAK,IAAI,EAC3B,EAAE,EAAE,IAAI;IAEV;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,SACA,MACgB;AAQhB,QAAO;EAAE;EAAO,MAPH,QAAQ,SAAS,WAAW;AAIvC,UAAO,CAAC,EAAE,QAAQ,EAFhB,KAAK,KAAM,OAAO,OAA0B,OAAO,OAAO,EAExC,EAAE,EAAE,OAAO;IAGb;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,KACgB;AAKhB,QAAO;EAAE;EAAO,MAJH,IAAI,KAAK,QAAQ;AAE5B,UAAO,EAAE,QAAQ,EADgB,KACd,EAAE;IAEH;EAAE"} | ||
| {"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;CAEA,OAAO,IADoB,OAAO,GAAG,KAChB;;;;;;;;;;;;;;;;ACvCvB,SAAgB,UACd,OACA,MACA,MACgB;CAKhB,OAAO;EAAE;EAAO,MAJH,KAAK,SAAS,QAAQ;GAEjC,OAAO,CAAC,EAAE,OADoB,OAAO,EAAE,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,EACvC,EAAE,IAAI;IAET;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,MACA,MACgB;CAKhB,OAAO;EAAE;EAAO,MAJH,KAAK,SAAS,QAAQ;GAEjC,OAAO,CAAC,EAAE,QAAQ,EADe,KAAK,KAAK,IAAI,EAC3B,EAAE,EAAE,IAAI;IAEV;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,SACA,MACgB;CAQhB,OAAO;EAAE;EAAO,MAPH,QAAQ,SAAS,WAAW;GAIvC,OAAO,CAAC,EAAE,QAAQ,EAFhB,KAAK,KAAM,OAAO,OAA0B,OAAO,OAAO,EAExC,EAAE,EAAE,OAAO;IAGb;EAAE;;;;;;;;;;;;;;AAexB,SAAgB,WACd,OACA,KACgB;CAKhB,OAAO;EAAE;EAAO,MAJH,IAAI,KAAK,QAAQ;GAE5B,OAAO,EAAE,QAAQ,EADgB,KACd,EAAE;IAEH;EAAE"} |
+4
-1
| { | ||
| "name": "@sebspark/opensearch", | ||
| "version": "3.1.3", | ||
| "version": "3.1.4", | ||
| "license": "Apache-2.0", | ||
@@ -31,2 +31,5 @@ "type": "module", | ||
| }, | ||
| "resolutions": { | ||
| "protobufjs": "8.3.0" | ||
| }, | ||
| "repository": { | ||
@@ -33,0 +36,0 @@ "type": "git", |
62869
0.08%