From c9ef649af96ec71ce02dda7681340ae3268c5e06 Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 5 Feb 2024 09:11:03 +0100 Subject: [PATCH 1/2] fix: disallow additional upsert metadata properties --- src/vector.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/vector.ts b/src/vector.ts index 466b1c4..ed37c7a 100644 --- a/src/vector.ts +++ b/src/vector.ts @@ -9,6 +9,14 @@ import { import { Requester } from "@http"; import { InfoCommand } from "./commands"; +type ValidateShape = T extends Base + ? Exclude extends never + ? T + : ExtraProperties> + : never; + +type ExtraProperties = Record; + export type CommandArgs any> = ConstructorParameters[0]; @@ -91,8 +99,8 @@ export class Index = Record( - args: CommandArgs> - ) => new UpsertCommand(args).exec(this.client); + args: CommandArgs>> + ) => new UpsertCommand>(args).exec(this.client); /** * It's used for retrieving specific items from the index, optionally including From 44b0c757458d70dc66aee71d96e59d4a59aab702 Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 5 Feb 2024 14:28:25 +0100 Subject: [PATCH 2/2] feat: allow overriding index-level generics --- src/commands/client/upsert/index.ts | 4 +++- src/vector.ts | 20 ++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/commands/client/upsert/index.ts b/src/commands/client/upsert/index.ts index ee28e0a..8929b8e 100644 --- a/src/commands/client/upsert/index.ts +++ b/src/commands/client/upsert/index.ts @@ -1,9 +1,11 @@ import { Command } from "@commands/command"; +type NoInfer = T extends infer U ? U : never + type UpsertCommandPayload = { id: number | string; vector: number[]; - metadata?: TMetadata; + metadata?: NoInfer; }; export class UpsertCommand extends Command { diff --git a/src/vector.ts b/src/vector.ts index ed37c7a..a273ab1 100644 --- a/src/vector.ts +++ b/src/vector.ts @@ -9,14 +9,6 @@ import { import { Requester } from "@http"; import { InfoCommand } from "./commands"; -type ValidateShape = T extends Base - ? Exclude extends never - ? T - : ExtraProperties> - : never; - -type ExtraProperties = Record; - export type CommandArgs any> = ConstructorParameters[0]; @@ -72,7 +64,7 @@ export class Index = Record( + query = = TIndexMetadata>( args: CommandArgs ) => new QueryCommand(args).exec(this.client); @@ -98,9 +90,9 @@ export class Index = Record( - args: CommandArgs>> - ) => new UpsertCommand>(args).exec(this.client); + upsert = = TIndexMetadata>( + args: CommandArgs> + ) => new UpsertCommand(args).exec(this.client); /** * It's used for retrieving specific items from the index, optionally including @@ -122,7 +114,7 @@ export class Index = Record[]>} A promise that resolves with an array of fetched items or null if not found, after the command is executed. */ - fetch = ( + fetch = = TIndexMetadata>( ...args: CommandArgs ) => new FetchCommand(args).exec(this.client); @@ -162,7 +154,7 @@ export class Index = Record>} A promise that resolves with the response containing the next cursor and an array of vectors, after the command is executed. */ - range = ( + range = = TIndexMetadata>( args: CommandArgs ) => new RangeCommand(args).exec(this.client);