/** * @module minions-sdk/storage/convex * ConvexDB storage adapter for the Minions structured object system. * * Requires the `convex` package as a peer dependency. * * @example * ```typescript * import { ConvexClient } from 'convex/browser'; * import { ConvexStorageAdapter } from 'minions-sdk'; * * const client = new ConvexClient('https://your-deployment.convex.cloud'); * const storage = new ConvexStorageAdapter(client); * * const minions = new Minions({ storage }); * ``` */ import type { Minion } from '../types/index.js'; import type { StorageAdapter, StorageFilter } from './StorageAdapter.js'; /** Minimal interface for a Convex query/mutation function reference. */ export interface ConvexFunctionReference { [key: string]: any; } /** * Minimal interface for a Convex client. * * Any object that exposes `query` and `mutation` methods matching the Convex * `ConvexClient` / `ConvexReactClient` contract will work. */ export interface ConvexClientLike { query(functionReference: ConvexFunctionReference, args?: Record): Promise; mutation(functionReference: ConvexFunctionReference, args?: Record): Promise; } /** Options for the Convex storage adapter. */ export interface ConvexStorageOptions { /** * Convex function references for the CRUD operations. * * You must deploy a Convex module that exposes these functions. * A reference implementation is provided in the docs. */ functions: { /** Query: get a single minion by `id` field. Returns `null` if not found. */ get: ConvexFunctionReference; /** Query: list all minions. Returns an array of minion documents. */ list: ConvexFunctionReference; /** Mutation: upsert a minion document (full replacement). */ set: ConvexFunctionReference; /** Mutation: delete a minion document by `id` field. */ delete: ConvexFunctionReference; }; } /** * Storage adapter backed by **ConvexDB**. * * Delegates CRUD operations to user-defined Convex query/mutation functions * via the Convex client. Filtering, sorting and pagination are applied * client-side using the shared {@link applyFilter} utility. * * **Setup**: You need to deploy a Convex module that stores minions as * documents with a string `id` field (the Minion UUID), plus the rest of the * Minion properties. Then pass the function references to the constructor. * * @example Convex schema (`convex/schema.ts`): * ```typescript * import { defineSchema, defineTable } from 'convex/server'; * import { v } from 'convex/values'; * * export default defineSchema({ * minions: defineTable({ * id: v.string(), // Minion UUID * data: v.string(), // JSON-serialised Minion object * }).index('by_id', ['id']), * }); * ``` * * @example Convex functions (`convex/minions.ts`): * ```typescript * import { query, mutation } from './_generated/server'; * import { v } from 'convex/values'; * * export const get = query({ * args: { id: v.string() }, * handler: async (ctx, { id }) => { * return await ctx.db.query('minions').withIndex('by_id', q => q.eq('id', id)).unique(); * }, * }); * * export const list = query({ * handler: async (ctx) => { * return await ctx.db.query('minions').collect(); * }, * }); * * export const set = mutation({ * args: { id: v.string(), data: v.string() }, * handler: async (ctx, { id, data }) => { * const existing = await ctx.db.query('minions').withIndex('by_id', q => q.eq('id', id)).unique(); * if (existing) { * await ctx.db.patch(existing._id, { data }); * } else { * await ctx.db.insert('minions', { id, data }); * } * }, * }); * * export const remove = mutation({ * args: { id: v.string() }, * handler: async (ctx, { id }) => { * const existing = await ctx.db.query('minions').withIndex('by_id', q => q.eq('id', id)).unique(); * if (existing) await ctx.db.delete(existing._id); * }, * }); * ``` */ export declare class ConvexStorageAdapter implements StorageAdapter { private client; private fns; constructor(client: ConvexClientLike, options: ConvexStorageOptions); get(id: string): Promise; set(minion: Minion): Promise; delete(id: string): Promise; list(filter?: StorageFilter): Promise; search(query: string): Promise; } //# sourceMappingURL=ConvexStorageAdapter.d.ts.map