import type { D1Database } from '@cloudflare/workers-types'; import { MastraCompositeStore } from '@mastra/core/storage'; import type { StorageDomains } from '@mastra/core/storage'; import Cloudflare from 'cloudflare'; import { BackgroundTasksStorageD1 } from './domains/background-tasks/index.js'; import { MemoryStorageD1 } from './domains/memory/index.js'; import { ScoresStorageD1 } from './domains/scores/index.js'; import { WorkflowsStorageD1 } from './domains/workflows/index.js'; export { BackgroundTasksStorageD1, MemoryStorageD1, ScoresStorageD1, WorkflowsStorageD1 }; export type { D1DomainConfig } from './db/index.js'; /** * Base configuration options shared across D1 configurations */ export interface D1BaseConfig { /** Storage instance ID */ id: string; /** Optional prefix for table names */ tablePrefix?: string; /** * When true, automatic initialization (table creation/migrations) is disabled. * This is useful for CI/CD pipelines where you want to: * 1. Run migrations explicitly during deployment (not at runtime) * 2. Use different credentials for schema changes vs runtime operations * * When disableInit is true: * - The storage will not automatically create/alter tables on first use * - You must call `storage.init()` explicitly in your CI/CD scripts * * @example * // In CI/CD script: * const storage = new D1Store({ ...config, disableInit: false }); * await storage.init(); // Explicitly run migrations * * // In runtime application: * const storage = new D1Store({ ...config, disableInit: true }); * // No auto-init, tables must already exist */ disableInit?: boolean; } /** * Configuration for D1 using the REST API */ export interface D1Config extends D1BaseConfig { /** Cloudflare account ID */ accountId: string; /** Cloudflare API token with D1 access */ apiToken: string; /** D1 database ID */ databaseId: string; } export interface D1ClientConfig extends D1BaseConfig { /** D1 Client */ client: D1Client; } /** * Configuration for D1 using the Workers Binding API */ export interface D1WorkersConfig extends D1BaseConfig { /** D1 database binding from Workers environment */ binding: D1Database; } /** * Combined configuration type supporting both REST API and Workers Binding API */ export type D1StoreConfig = D1Config | D1WorkersConfig | D1ClientConfig; export type D1QueryResult = Awaited>['result']; export interface D1Client { query(args: { sql: string; params: string[]; }): Promise<{ result: D1QueryResult; }>; } /** * Cloudflare D1 storage adapter for Mastra. * * Access domain-specific storage via `getStore()`: * * @example * ```typescript * const storage = new D1Store({ id: 'my-store', accountId: '...', apiToken: '...', databaseId: '...' }); * * // Access memory domain * const memory = await storage.getStore('memory'); * await memory?.saveThread({ thread }); * * // Access workflows domain * const workflows = await storage.getStore('workflows'); * await workflows?.persistWorkflowSnapshot({ workflowName, runId, snapshot }); * ``` */ export declare class D1Store extends MastraCompositeStore { private client?; private binding?; private tablePrefix; stores: StorageDomains; /** * Creates a new D1Store instance * @param config Configuration for D1 access (either REST API or Workers Binding API) */ constructor(config: D1StoreConfig); /** * Close the database connection * No explicit cleanup needed for D1 in either REST or Workers Binding mode */ close(): Promise; } //# sourceMappingURL=index.d.ts.map