-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from upstash/dx-905-vectorjs-update-command
DX-905: Update Command
- Loading branch information
Showing
11 changed files
with
207 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { afterAll, describe, expect, test } from "bun:test"; | ||
import { FetchCommand, UpdateCommand, UpsertCommand } from "@commands/index"; | ||
import { awaitUntilIndexed, newHttpClient, range, resetIndexes } from "@utils/test-utils"; | ||
|
||
const client = newHttpClient(); | ||
|
||
describe("UPDATE", () => { | ||
afterAll(async () => await resetIndexes()); | ||
|
||
test("should update vector metadata", async () => { | ||
await new UpsertCommand({ | ||
id: 1, | ||
vector: range(0, 384), | ||
metadata: { upstash: "test-simple" }, | ||
}).exec(client); | ||
|
||
const res = await new UpdateCommand({ | ||
id: 1, | ||
metadata: { upstash: "test-update" }, | ||
}).exec(client); | ||
|
||
expect(res).toEqual({ updated: 1 }); | ||
|
||
await awaitUntilIndexed(client, 5000); | ||
|
||
const fetchData = await new FetchCommand<{ upstash: string }>([ | ||
["1"], | ||
{ includeMetadata: true }, | ||
]).exec(client); | ||
|
||
expect(fetchData[0]?.metadata?.upstash).toBe("test-update"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { NAMESPACE } from "@commands/client/types"; | ||
import { Command } from "@commands/command"; | ||
|
||
type NoInfer<T> = T extends infer U ? U : never; | ||
|
||
type MetadataUpdatePayload<TMetadata> = { | ||
id: string | number; | ||
metadata: NoInfer<TMetadata>; | ||
}; | ||
|
||
type VectorUpdatePayload = { | ||
id: string | number; | ||
vector: number[]; | ||
}; | ||
|
||
type DataUpdatePayload = { | ||
id: string | number; | ||
data: string; | ||
}; | ||
|
||
type Payload<TMetadata> = | ||
| MetadataUpdatePayload<TMetadata> | ||
| VectorUpdatePayload | ||
| DataUpdatePayload; | ||
|
||
type UpdateCommandOptions = { namespace?: string }; | ||
|
||
type UpdateEndpointVariants = `update` | `update/${NAMESPACE}`; | ||
|
||
type UpdateCommandResponse = { updated: number }; | ||
export class UpdateCommand<TMetadata> extends Command<UpdateCommandResponse> { | ||
constructor(payload: Payload<TMetadata>, opts?: UpdateCommandOptions) { | ||
let endpoint: UpdateEndpointVariants = "update"; | ||
|
||
if (opts?.namespace) { | ||
endpoint = `${endpoint}/${opts.namespace}`; | ||
} | ||
|
||
super(payload, endpoint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters