Skip to content

Commit

Permalink
Disambiguate delete by query method singature types
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed Jan 4, 2024
1 parent 6369b2d commit ba1e283
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 37 deletions.
14 changes: 4 additions & 10 deletions dist/typesense.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/typesense.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions lib/Typesense/Documents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export interface WriteableDocuments<T> {
create(document: T, options: DocumentWriteParameters): Promise<T>;
upsert(document: T, options: DocumentWriteParameters): Promise<T>;
update(document: T, options: DocumentWriteParameters): Promise<T>;
delete(idOrQuery: string | DeleteQuery): Promise<DeleteResponse> | Promise<T>;
delete(query: DeleteQuery): Promise<DeleteResponse>;
import(documents: T[] | string, options: DocumentWriteParameters): Promise<string | ImportResponse[]>;
export(options: DocumentsExportParameters): Promise<string>;
}
Expand All @@ -184,8 +184,7 @@ export default class Documents<T extends DocumentSchema = object> extends Search
upsert(document: T, options?: DocumentWriteParameters): Promise<T>;
update(document: T, options: UpdateByFilterParameters): Promise<UpdateByFilterResponse>;
update(document: T, options: DocumentWriteParameters): Promise<T>;
delete(idOrQuery: DeleteQuery): Promise<DeleteResponse>;
delete(idOrQuery: string): Promise<T>;
delete(query?: DeleteQuery): Promise<DeleteResponse>;
createMany(documents: T[], options?: DocumentImportParameters): Promise<ImportResponse[]>;
/**
* Import a set of documents in a batch.
Expand Down
12 changes: 3 additions & 9 deletions lib/Typesense/Documents.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Typesense/Documents.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions src/Typesense/Documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export interface WriteableDocuments<T> {
create(document: T, options: DocumentWriteParameters): Promise<T>;
upsert(document: T, options: DocumentWriteParameters): Promise<T>;
update(document: T, options: DocumentWriteParameters): Promise<T>;
delete(idOrQuery: string | DeleteQuery): Promise<DeleteResponse> | Promise<T>;
delete(query: DeleteQuery): Promise<DeleteResponse>;
import(
documents: T[] | string,
options: DocumentWriteParameters,
Expand Down Expand Up @@ -264,19 +264,10 @@ export default class Documents<T extends DocumentSchema = object>
}
}

async delete(idOrQuery: DeleteQuery): Promise<DeleteResponse>;
async delete(idOrQuery: string): Promise<T>;
async delete(
idOrQuery: string | DeleteQuery = {} as DeleteQuery,
): Promise<DeleteResponse | T> {
if (typeof idOrQuery === "string") {
return this.apiCall.delete<T>(this.endpointPath(idOrQuery), idOrQuery);
} else {
return this.apiCall.delete<DeleteResponse>(
this.endpointPath(),
idOrQuery,
);
}
query: DeleteQuery = {} as DeleteQuery,
): Promise<DeleteResponse> {
return this.apiCall.delete<DeleteResponse>(this.endpointPath(), query);
}

async createMany(documents: T[], options: DocumentImportParameters = {}) {
Expand Down

0 comments on commit ba1e283

Please sign in to comment.