Skip to content

Commit

Permalink
Merge pull request #7 from upstash/vec-114-index-level-generic-support
Browse files Browse the repository at this point in the history
fix: disallow additional upsert metadata properties
  • Loading branch information
joschan21 authored Feb 5, 2024
2 parents bf0b424 + e330c00 commit 6c9035b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 6c9035b

Please sign in to comment.