Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow additional upsert metadata properties #7

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/commands/client/upsert/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Command } from "@commands/command";

type NoInfer<T> = T extends infer U ? U : never

type UpsertCommandPayload<TMetadata> = {
id: number | string;
vector: number[];
metadata?: TMetadata;
metadata?: NoInfer<TMetadata>;
};

export class UpsertCommand<TMetadata> extends Command<string> {
Expand Down
8 changes: 4 additions & 4 deletions src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Index<TIndexMetadata extends Record<string, unknown> = Record<strin
*
* @returns A promise that resolves with an array of query result objects when the request to query the index is completed.
*/
query = <TMetadata extends TIndexMetadata = TIndexMetadata>(
query = <TMetadata extends Record<string, unknown> = TIndexMetadata>(
args: CommandArgs<typeof QueryCommand>
) => new QueryCommand<TMetadata>(args).exec(this.client);

Expand All @@ -90,7 +90,7 @@ export class Index<TIndexMetadata extends Record<string, unknown> = Record<strin
*
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
*/
upsert = <TMetadata extends TIndexMetadata = TIndexMetadata>(
upsert = <TMetadata extends Record<string, unknown> = TIndexMetadata>(
args: CommandArgs<typeof UpsertCommand<TMetadata>>
) => new UpsertCommand<TMetadata>(args).exec(this.client);

Expand All @@ -114,7 +114,7 @@ export class Index<TIndexMetadata extends Record<string, unknown> = Record<strin
*
* @returns {Promise<FetchReturnResponse<TMetadata>[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed.
*/
fetch = <TMetadata extends TIndexMetadata = TIndexMetadata>(
fetch = <TMetadata extends Record<string, unknown> = TIndexMetadata>(
...args: CommandArgs<typeof FetchCommand>
) => new FetchCommand<TMetadata>(args).exec(this.client);

Expand Down Expand Up @@ -154,7 +154,7 @@ export class Index<TIndexMetadata extends Record<string, unknown> = Record<strin
*
* @returns {Promise<RangeReturnResponse<TMetadata>>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed.
*/
range = <TMetadata extends TIndexMetadata = TIndexMetadata>(
range = <TMetadata extends Record<string, unknown> = TIndexMetadata>(
args: CommandArgs<typeof RangeCommand>
) => new RangeCommand<TMetadata>(args).exec(this.client);

Expand Down