Hierarchy

  • BaseClient
    • StoreClient

Constructors

  • Parameters

    Returns StoreClient

Properties

apiUrl: string
asyncCaller: AsyncCaller
defaultHeaders: Record<string, HeaderValue>
onRequest?: RequestHook
timeoutMs: undefined | number

Methods

  • Delete an item.

    Parameters

    • namespace: string[]

      A list of strings representing the namespace path.

    • key: string

      The unique identifier for the item.

    Returns Promise<void>

    Promise

  • Type Parameters

    • T

    Parameters

    • path: string
    • options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse: true;
      }

    Returns Promise<[T, Response]>

  • Type Parameters

    • T

    Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse?: false;
      }

    Returns Promise<T>

  • Retrieve a single item.

    Parameters

    • namespace: string[]

      A list of strings representing the namespace path.

    • key: string

      The unique identifier for the item.

    • Optional options: {
          refreshTtl?: null | boolean;
      }
      • Optional refreshTtl?: null | boolean

        Whether to refresh the TTL on this read operation. If null, uses the store's default behavior.

    Returns Promise<null | Item>

    Promise

    Example

    const item = await client.store.getItem(
    ["documents", "user123"],
    "item456",
    { refreshTtl: true }
    );
    console.log(item);
    // {
    // namespace: ["documents", "user123"],
    // key: "item456",
    // value: { title: "My Document", content: "Hello World" },
    // createdAt: "2024-07-30T12:00:00Z",
    // updatedAt: "2024-07-30T12:00:00Z"
    // }
  • List namespaces with optional match conditions.

    Parameters

    • Optional options: {
          limit?: number;
          maxDepth?: number;
          offset?: number;
          prefix?: string[];
          suffix?: string[];
      }
      • Optional limit?: number

        Maximum number of namespaces to return (default is 100).

      • Optional maxDepth?: number

        Optional integer specifying the maximum depth of namespaces to return.

      • Optional offset?: number

        Number of namespaces to skip before returning results (default is 0).

      • Optional prefix?: string[]

        Optional list of strings representing the prefix to filter namespaces.

      • Optional suffix?: string[]

        Optional list of strings representing the suffix to filter namespaces.

    Returns Promise<ListNamespaceResponse>

    Promise

  • Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          timeoutMs?: null | number;
          withResponse?: boolean;
      }

    Returns [url: URL, init: RequestInit]

  • Store or update an item.

    Parameters

    • namespace: string[]

      A list of strings representing the namespace path.

    • key: string

      The unique identifier for the item within the namespace.

    • value: Record<string, any>

      A dictionary containing the item's data.

    • Optional options: {
          index?: null | false | string[];
          ttl?: null | number;
      }
      • Optional index?: null | false | string[]

        Controls search indexing - null (use defaults), false (disable), or list of field paths to index.

      • Optional ttl?: null | number

        Optional time-to-live in minutes for the item, or null for no expiration.

    Returns Promise<void>

    Promise

    Example

    await client.store.putItem(
    ["documents", "user123"],
    "item456",
    { title: "My Document", content: "Hello World" },
    { ttl: 60 } // expires in 60 minutes
    );
  • Search for items within a namespace prefix.

    Parameters

    • namespacePrefix: string[]

      List of strings representing the namespace prefix.

    • Optional options: {
          filter?: Record<string, any>;
          limit?: number;
          offset?: number;
          query?: string;
          refreshTtl?: null | boolean;
      }
      • Optional filter?: Record<string, any>

        Optional dictionary of key-value pairs to filter results.

      • Optional limit?: number

        Maximum number of items to return (default is 10).

      • Optional offset?: number

        Number of items to skip before returning results (default is 0).

      • Optional query?: string

        Optional search query.

      • Optional refreshTtl?: null | boolean

        Whether to refresh the TTL on items returned by this search. If null, uses the store's default behavior.

    Returns Promise<SearchItemsResponse>

    Promise

    Example

    const results = await client.store.searchItems(
    ["documents"],
    {
    filter: { author: "John Doe" },
    limit: 5,
    refreshTtl: true
    }
    );
    console.log(results);
    // {
    // items: [
    // {
    // namespace: ["documents", "user123"],
    // key: "item789",
    // value: { title: "Another Document", author: "John Doe" },
    // createdAt: "2024-07-30T12:00:00Z",
    // updatedAt: "2024-07-30T12:00:00Z"
    // },
    // // ... additional items ...
    // ]
    // }