Skip to content

Commit

Permalink
fix: pass query params to delete calls (#217) (#218)
Browse files Browse the repository at this point in the history
* fix(delete-query): make filter by optional

* fix(delete-query): pass query params to api call

* test(delete-query): test that it passes query params to api call

* build(delete-query): add build files
  • Loading branch information
tharropoulos authored Jul 18, 2024
1 parent f7ba556 commit d6b2487
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 17 deletions.
8 changes: 4 additions & 4 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.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/Typesense/Document.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ApiCall from "./ApiCall";
import { DocumentSchema, DocumentWriteParameters } from "./Documents";
import { DeleteQuery, DocumentSchema, DocumentWriteParameters } from "./Documents";
export declare class Document<T extends DocumentSchema = object> {
private collectionName;
private documentId;
private apiCall;
constructor(collectionName: string, documentId: string, apiCall: ApiCall);
retrieve(): Promise<T>;
delete(): Promise<T>;
delete(options?: DeleteQuery): Promise<T>;
update(partialDocument: Partial<T>, options?: DocumentWriteParameters): Promise<T>;
private endpointPath;
}
4 changes: 2 additions & 2 deletions lib/Typesense/Document.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/Document.js.map

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

3 changes: 1 addition & 2 deletions lib/Typesense/Documents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ApiCall from "./ApiCall";
import Configuration from "./Configuration";
import { SearchOnlyDocuments } from "./SearchOnlyDocuments";
export interface DeleteQuery {
filter_by: string;
filter_by?: string;
batch_size?: number;
ignore_not_found?: boolean;
}
Expand Down Expand Up @@ -102,7 +102,6 @@ export interface SearchResponseHit<T extends DocumentSchema> {
field: keyof T;
snippet?: string;
value?: string;
values?: string[];
snippets?: string[];
indices?: number[];
matched_tokens: string[][] | string[];
Expand Down
5 changes: 3 additions & 2 deletions src/Typesense/Document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ApiCall from "./ApiCall";
import Collections from "./Collections";
import Documents, {
DeleteQuery,
DocumentSchema,
DocumentWriteParameters,
} from "./Documents";
Expand All @@ -16,8 +17,8 @@ export class Document<T extends DocumentSchema = object> {
return this.apiCall.get<T>(this.endpointPath());
}

async delete(): Promise<T> {
return this.apiCall.delete<T>(this.endpointPath());
async delete(options?: DeleteQuery): Promise<T> {
return this.apiCall.delete<T>(this.endpointPath(), options);
}

async update(
Expand Down
2 changes: 1 addition & 1 deletion src/Typesense/Documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SearchOnlyDocuments } from "./SearchOnlyDocuments";

// Todo: use generic to extract filter_by values
export interface DeleteQuery {
filter_by: string;
filter_by?: string;
batch_size?: number;
ignore_not_found?: boolean;
}
Expand Down
28 changes: 28 additions & 0 deletions test/Typesense/Document.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,32 @@ describe("Document", function () {
expect(returnData).to.eventually.deep.equal(documentResult).notify(done);
});
});
it("passes query params to delete", function (done) {
const queryParams = { ignore_not_found: true };
mockAxios
.onDelete(
apiCall.uriFor(
"/collections/companies/documents/124",
typesense.configuration.nodes[0],
),
null,
{
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
},
)
.reply((config) => {
expect(config.params).to.deep.equal(queryParams);
return [
200,
JSON.stringify(documentResult),
{ "content-type": "application/json" },
];
});

let returnData = document.delete(queryParams);

expect(returnData).to.eventually.deep.equal(documentResult).notify(done);
});
});

0 comments on commit d6b2487

Please sign in to comment.