From d309c363881210bd8e01bc76fc5c870a70743b56 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:07:28 -0700 Subject: [PATCH] Review --- libs/sdk-js/src/client.ts | 46 ++++++++++++++++++++++++++++++++++----- libs/sdk-js/src/schema.ts | 4 ++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 1e47c1fe8..6ceb5333b 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -986,6 +986,17 @@ export class RunsClient extends BaseClient { } } +interface APIItem { + namespace: string[]; + key: string; + value: Record; + created_at: string; + updated_at: string; +} +interface APISearchItemsResponse { + items: APIItem[]; +} + export class StoreClient extends BaseClient { /** * Store or update an item. @@ -1027,7 +1038,7 @@ export class StoreClient extends BaseClient { * @param key The unique identifier for the item. * @returns Promise */ - async getItem(namespace: string[], key: string): Promise { + async getItem(namespace: string[], key: string): Promise { namespace.forEach((label) => { if (label.includes(".")) { throw new Error( @@ -1036,9 +1047,14 @@ export class StoreClient extends BaseClient { } }); - return this.fetch("/store/items", { + const response = await this.fetch("/store/items", { params: { namespace: namespace.join("."), key }, }); + return { + ...response, + createdAt: response.created_at, + updatedAt: response.updated_at, + }; } /** @@ -1049,6 +1065,14 @@ export class StoreClient extends BaseClient { * @returns Promise */ async deleteItem(namespace: string[], key: string): Promise { + namespace.forEach((label) => { + if (label.includes(".")) { + throw new Error( + `Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`, + ); + } + }); + return this.fetch("/store/items", { method: "DELETE", json: { namespace, key }, @@ -1079,10 +1103,20 @@ export class StoreClient extends BaseClient { offset: options?.offset ?? 0, }; - return this.fetch("/store/items/search", { - method: "POST", - json: payload, - }); + const response = await this.fetch( + "/store/items/search", + { + method: "POST", + json: payload, + }, + ); + return { + items: response.items.map((item) => ({ + ...item, + createdAt: item.created_at, + updatedAt: item.updated_at, + })), + }; } /** diff --git a/libs/sdk-js/src/schema.ts b/libs/sdk-js/src/schema.ts index a215a1a29..979c198ef 100644 --- a/libs/sdk-js/src/schema.ts +++ b/libs/sdk-js/src/schema.ts @@ -232,6 +232,6 @@ export interface Item { namespace: string[]; key: string; value: Record; - created_at: string; - updated_at: string; + createdAt: string; + updatedAt: string; }