Move docs/ package mirror into document-navigator plugin
Relocate the ~6k-file docs tree from the repo root into plugins/document-navigator/docs/ so the plugin is self-contained and portable. docs/superpowers/ (specs and plans) stays at the repo root. Moved via cp+rm rather than git mv because directory rename() fails with EPERM on this WSL /mnt DrvFs mount; git rename-detection pairs the identical-content files at commit time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# `db-adapter-options` — Zod-validated configuration for `createDbAdapter`
|
||||
|
||||
<!-- begin:auto-docs -->
|
||||
_(no submodules)_
|
||||
<!-- end:auto-docs -->
|
||||
|
||||
## Purpose
|
||||
|
||||
`DbAdapterOptions` is the single config object accepted by every public factory
|
||||
in this package — `createDbAdapter`, `createDbAdapterWorkerProxy`, and
|
||||
`runMigrations` all derive from it. The schema is Zod-driven so that host code
|
||||
catches configuration mistakes at construction time, before any TCP socket is
|
||||
opened.
|
||||
|
||||
The schema is intentionally narrow: engine, url, optional pool tuning, the
|
||||
tenant column name, an optional migrations directory, and a strict-mode flag
|
||||
that decides whether the tenant-scoped wrapper rejects or auto-injects `INSERT`
|
||||
payloads.
|
||||
|
||||
## Features
|
||||
|
||||
- Zod schema with sensible defaults (`tenantColumn = "tenant_id"`,
|
||||
`autoInjectInserts = true`, pool max `10`, idle `30_000` ms).
|
||||
- `parseDbAdapterOptions(input)` — convenience wrapper that converts every Zod
|
||||
failure into a typed `DbAdapterError` with code `INVALID_OPTIONS`. Issues
|
||||
are surfaced through `error.context.issues`.
|
||||
- `engine` is `z.string().min(1)` — the *literal value* check happens against
|
||||
the open `DatabaseEngineRegistry` so declaration-merged engines pass.
|
||||
- `pool` is an optional sub-schema with its own defaults; absent values are
|
||||
forwarded as `undefined` to the engine layer rather than guessed.
|
||||
|
||||
## Usage: Basic
|
||||
|
||||
```ts
|
||||
import { parseDbAdapterOptions } from "@suaveplan/api-db-adapter/options";
|
||||
|
||||
const options = parseDbAdapterOptions({
|
||||
engine: "sqlite",
|
||||
url: ":memory:",
|
||||
});
|
||||
// options.tenantColumn === "tenant_id"
|
||||
// options.autoInjectInserts === true
|
||||
```
|
||||
|
||||
## Usage: Advanced
|
||||
|
||||
```ts
|
||||
import { parseDbAdapterOptions } from "@suaveplan/api-db-adapter/options";
|
||||
|
||||
const options = parseDbAdapterOptions({
|
||||
engine: "postgres",
|
||||
url: "postgres://app@db.local:5432/app",
|
||||
tenantColumn: "org_id",
|
||||
autoInjectInserts: false,
|
||||
pool: { min: 2, max: 16, idleMs: 60_000 },
|
||||
migrationsDir: "./db/migrations",
|
||||
});
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
- `DbAdapterOptionsSchema` — top-level Zod schema.
|
||||
- `DbAdapterPoolSchema` — pool sub-schema with `min`, `max`, `idleMs`.
|
||||
- `DbAdapterOptions` — inferred output type (post-parse).
|
||||
- `DbAdapterOptionsInput` — inferred input type (pre-parse).
|
||||
- `parseDbAdapterOptions(input): DbAdapterOptions` — throws `DbAdapterError`
|
||||
with code `DB_ADAPTER.INVALID_OPTIONS` on failure.
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
The defaults are applied via `.default(...)` on each field so the output type is
|
||||
non-optional after parsing. Pool fields have their own defaults so `pool: {}`
|
||||
parses to the full default block; total absence (`pool` undefined) is preserved
|
||||
because it lets the engine layer pick its own defaults. Engine identity is
|
||||
validated separately by the engine registry so this module stays decoupled from
|
||||
the concrete `DatabaseEngineRegistry` keys.
|
||||
Reference in New Issue
Block a user