import { Config } from "drizzle-kit"; //#region src/drizzle-config.d.ts /** * Options for configuring a Drizzle Kit setup targeting a Cloudflare D1 database. */ interface DrizzleD1Options { /** Path to the Wrangler configuration file (`wrangler.toml` or `wrangler.json`). */ configPath?: string; /** Directory where the local D1 SQLite database file is persisted. */ persistTo?: string; /** Wrangler environment name (e.g. `"staging"`, `"production"`). */ environment?: string; /** Name of the D1 binding as declared in the Wrangler config. * * Defaults to the first D1 binding found. */ binding?: string; /** * When `true`, connects to the remote Cloudflare D1 database via the HTTP API * instead of a local SQLite file. * * Requires `accountId` and `apiToken`. * * Defaults to the `remote` flag on the resolved D1 binding if set, otherwise `false`. */ remote?: boolean; /** When `true`, targets the D1 preview database instead of the production one. */ preview?: boolean; /** * Cloudflare account ID. * * Required when using remote database. */ accountId?: string; /** * Cloudflare API token with D1 read/write permissions. * * Required when using remote database. */ apiToken?: string; } /** * A Drizzle Kit `Config` object with the dialect, driver, and database * credential fields omitted — those are injected automatically by {@link drizzleD1Config}. */ type DrizzleKitConfig = Omit; /** * Builds a complete Drizzle Kit {@link Config} object pre-configured for a * Cloudflare D1 database. * * Behaviour: * - **Local mode** (default): resolves the SQLite file path from the Wrangler * config and points `dbCredentials.url` at it. If the file does not yet exist * the user is prompted to run `wrangler d1 execute --local` to create it. * - **Remote mode** (`options.remote = true`): switches the driver to `d1-http` * and forwards `accountId` / `apiToken` as HTTP credentials. Both options are * required in this mode. * - **Preview mode** (`options.preview = true`): targets the `preview_database_id` * declared in the Wrangler config rather than the production `database_id`. * * @param config Base Drizzle Kit configuration (schemas, migrations directory, etc.) * — everything except dialect, driver, and credentials. * @param options D1-specific options that control which binding, environment, * and mode (local / remote / preview) to use. * @returns A complete Drizzle Kit `Config` ready to be exported from * `drizzle.config.ts`. * * @throws {Error} If required remote options (`accountId`, `apiToken`) are missing * when `remote` is `true`. * @throws {Error} If the resolved `database_id` / `preview_database_id` is not set * for the target binding. * @throws {Error} If the local SQLite file cannot be found or created. * * @example * // drizzle.config.ts — local mode * import { drizzleD1Config } from '@deox/drizzle-d1-utils'; * * export default drizzleD1Config( * { schema: './src/schema.ts', out: './drizzle' }, * { binding: 'DB' }, * ); * * @example * // drizzle.config.ts — remote mode * import { drizzleD1Config } from '@deox/drizzle-d1-utils'; * * export default drizzleD1Config( * { schema: './src/schema.ts', out: './drizzle' }, * { * binding: 'DB', * remote: true, * accountId: process.env.CF_ACCOUNT_ID, * apiToken: process.env.CF_API_TOKEN, * }, * ); */ declare function drizzleD1Config(config: DrizzleKitConfig, options?: DrizzleD1Options): Config; //#endregion export { DrizzleD1Options, DrizzleKitConfig, drizzleD1Config }; //# sourceMappingURL=drizzle-config.d.cts.map