From ee8f1e230de76a216052861b329ff5d584eb332c Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Tue, 18 Nov 2025 19:08:33 +0200 Subject: [PATCH 1/3] fix(types): add `found` to union search response type --- src/Typesense/Types.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Typesense/Types.ts b/src/Typesense/Types.ts index 5270c1f9..0ce44914 100644 --- a/src/Typesense/Types.ts +++ b/src/Typesense/Types.ts @@ -263,7 +263,14 @@ export type MultiSearchRequestsSchema< export interface UnionSearchResponse extends Omit, "request_params"> { - union_request_params: SearchResponseRequestParams[]; + union_request_params: UnionSearchResponseRequestParams[]; +} + +type AllRequiredBut = Required> & Pick; + +export interface UnionSearchResponseRequestParams + extends AllRequiredBut { + found: number; } export type MultiSearchResponse< From 33f6b10ede9a4a81ad98674b3f3a86def8529c07 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Tue, 18 Nov 2025 19:18:34 +0200 Subject: [PATCH 2/3] fix(document): don't accept write actions on dedicated functions - don't let users define actions on create, update and upsert --- src/Typesense/Documents.ts | 11 +++++++---- src/Typesense/Types.ts | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Typesense/Documents.ts b/src/Typesense/Documents.ts index 77ed9c57..df705cbd 100644 --- a/src/Typesense/Documents.ts +++ b/src/Typesense/Documents.ts @@ -214,12 +214,15 @@ export default class Documents super(collectionName, apiCall, configuration); } - async create(document: T, options: DocumentWriteParameters = {}): Promise { + async create( + document: T, + options: Omit = {}, + ): Promise { if (!document) throw new Error("No document provided"); return this.apiCall.post(this.endpointPath(), document, options); } - async upsert(document: T, options: DocumentWriteParameters = {}): Promise { + async upsert(document: T, options: Omit = {}): Promise { if (!document) throw new Error("No document provided"); return this.apiCall.post( this.endpointPath(), @@ -232,10 +235,10 @@ export default class Documents document: T, options: UpdateByFilterParameters, ): Promise; - async update(document: T, options: DocumentWriteParameters): Promise; + async update(document: T, options: Omit): Promise; async update( document: T, - options: DocumentWriteParameters | UpdateByFilterParameters = {}, + options: Omit | UpdateByFilterParameters = {}, ): Promise { if (!document) throw new Error("No document provided"); diff --git a/src/Typesense/Types.ts b/src/Typesense/Types.ts index 0ce44914..1dfe24af 100644 --- a/src/Typesense/Types.ts +++ b/src/Typesense/Types.ts @@ -202,9 +202,18 @@ export interface SearchableDocuments< } export interface WriteableDocuments { - create(document: T, options: DocumentWriteParameters): Promise; - upsert(document: T, options: DocumentWriteParameters): Promise; - update(document: T, options: DocumentWriteParameters): Promise; + create( + document: T, + options: Omit, + ): Promise; + upsert( + document: T, + options: Omit, + ): Promise; + update( + document: T, + options: Omit, + ): Promise; delete(query: DeleteQuery): Promise; import( documents: T[] | string, From 46a99db638b8857b38551b5d95359ddbb815fc2a Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Tue, 18 Nov 2025 19:18:51 +0200 Subject: [PATCH 3/3] feat(documents): add dedicated `emplace` function --- src/Typesense/Documents.ts | 29 +++++++++++++++++++++++++++++ src/Typesense/Types.ts | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/src/Typesense/Documents.ts b/src/Typesense/Documents.ts index df705cbd..683ddb37 100644 --- a/src/Typesense/Documents.ts +++ b/src/Typesense/Documents.ts @@ -257,6 +257,35 @@ export default class Documents } } + async emplace( + document: T, + options: UpdateByFilterParameters, + ): Promise; + async emplace( + document: T, + options: Omit, + ): Promise; + async emplace( + document: T, + options: Omit | UpdateByFilterParameters = {}, + ): Promise { + if (!document) throw new Error("No document provided"); + + if (options["filter_by"] != null) { + return this.apiCall.patch( + this.endpointPath(), + document, + Object.assign({}, options), + ); + } else { + return this.apiCall.post( + this.endpointPath(), + document, + Object.assign({}, options, { action: "emplace" }), + ); + } + } + async delete( query: DeleteQuery = {} as DeleteQuery, ): Promise> { diff --git a/src/Typesense/Types.ts b/src/Typesense/Types.ts index 1dfe24af..d9ac8c94 100644 --- a/src/Typesense/Types.ts +++ b/src/Typesense/Types.ts @@ -214,6 +214,10 @@ export interface WriteableDocuments { document: T, options: Omit, ): Promise; + emplace( + document: T, + options: Omit, + ): Promise; delete(query: DeleteQuery): Promise; import( documents: T[] | string,