@better-schemic/core 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/lib/authoring.d.ts +114 -0
  4. package/lib/authoring.js +242 -0
  5. package/lib/authoring.js.map +1 -0
  6. package/lib/chunk-26D7WX7Q.js +31 -0
  7. package/lib/chunk-26D7WX7Q.js.map +1 -0
  8. package/lib/chunk-IUPOUD4L.js +330 -0
  9. package/lib/chunk-IUPOUD4L.js.map +1 -0
  10. package/lib/chunk-LC3VHUM2.js +56 -0
  11. package/lib/chunk-LC3VHUM2.js.map +1 -0
  12. package/lib/chunk-RSGP7GVO.js +252 -0
  13. package/lib/chunk-RSGP7GVO.js.map +1 -0
  14. package/lib/client-HZF4ZWGO.js +13 -0
  15. package/lib/client-HZF4ZWGO.js.map +1 -0
  16. package/lib/config-BYh7WA4P.d.ts +259 -0
  17. package/lib/config.d.ts +2 -0
  18. package/lib/config.js +27 -0
  19. package/lib/config.js.map +1 -0
  20. package/lib/driver-LVldBEhS.d.ts +818 -0
  21. package/lib/driver.d.ts +151 -0
  22. package/lib/driver.js +47 -0
  23. package/lib/driver.js.map +1 -0
  24. package/lib/index.d.ts +154 -0
  25. package/lib/index.js +758 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/query.d.ts +81 -0
  28. package/lib/query.js +30 -0
  29. package/lib/query.js.map +1 -0
  30. package/lib/secrets-BETi5p8g.d.ts +26 -0
  31. package/lib/testing.d.ts +99 -0
  32. package/lib/testing.js +212 -0
  33. package/lib/testing.js.map +1 -0
  34. package/package.json +102 -0
  35. package/src/authoring.ts +360 -0
  36. package/src/cli-kit/config.ts +226 -0
  37. package/src/cli-kit/diff.ts +273 -0
  38. package/src/cli-kit/filter.ts +159 -0
  39. package/src/cli-kit/merge.ts +380 -0
  40. package/src/cli-kit/meta.ts +123 -0
  41. package/src/cli-kit/pager.ts +42 -0
  42. package/src/cli-kit/schema.ts +214 -0
  43. package/src/cli-kit/style.ts +24 -0
  44. package/src/client.ts +244 -0
  45. package/src/config.ts +199 -0
  46. package/src/connection.ts +120 -0
  47. package/src/driver/driver.ts +413 -0
  48. package/src/driver/index.ts +31 -0
  49. package/src/driver/portable-ir.ts +51 -0
  50. package/src/driver/portable.ts +124 -0
  51. package/src/driver/sdk.ts +73 -0
  52. package/src/index.ts +185 -0
  53. package/src/kind/index.ts +28 -0
  54. package/src/kind/plan.ts +412 -0
  55. package/src/kind/registry.ts +270 -0
  56. package/src/query/call.ts +21 -0
  57. package/src/query/codec.ts +33 -0
  58. package/src/query/index.ts +22 -0
  59. package/src/query/project.ts +25 -0
  60. package/src/query/ref.ts +32 -0
  61. package/src/query.ts +5 -0
  62. package/src/secrets.ts +61 -0
  63. package/src/seed.ts +14 -0
  64. package/src/testing.ts +402 -0
@@ -0,0 +1,818 @@
1
+ import { R as ResolvedConfig } from './config-BYh7WA4P.js';
2
+ import { a as SecretRef, S as SecretProvider } from './secrets-BETi5p8g.js';
3
+ import { Command } from 'commander';
4
+
5
+ /**
6
+ * An authored definable, tagged with the KIND that owns it. Core dispatches on `kind` alone — every
7
+ * other field is the kind's own business, handed straight to {@link KindEngine.lower}. This is the
8
+ * neutral upper bound for a kind's authoring-object type (a driver's concrete `TableDef`/`FnDef` is a
9
+ * structural subtype).
10
+ */
11
+ interface Definable {
12
+ readonly kind: string;
13
+ readonly name: string;
14
+ }
15
+ /**
16
+ * A kind's PORTABLE object — the dialect-independent data shape core stores + diffs. A kind chooses
17
+ * how structured this is: a table's portable form carries fields/indexes (so core can field-level
18
+ * diff it); an opaque kind (function/access) carries a neutral identity + a `native` payload it
19
+ * round-trips. Either way it is tagged with `kind`/`name` for cross-kind dispatch + ordering.
20
+ */
21
+ interface PortableObject {
22
+ readonly kind: string;
23
+ readonly name: string;
24
+ }
25
+ /** A reference to another object in the schema graph — the unit of cross-kind dependency ordering. */
26
+ interface Ref {
27
+ readonly kind: string;
28
+ readonly name: string;
29
+ }
30
+
31
+ /**
32
+ * What core needs to orchestrate ONE kind generically — it never inspects the specifics. The
33
+ * change-vocabulary (`emit`/`remove`/`overwrite`) mirrors the Driver contract's, so a kind's behavior
34
+ * is parity-checkable against the fixed-slot engine. `A` is the kind's authoring object, `P` its
35
+ * portable object; both are opaque to core beyond the {@link Definable}/{@link PortableObject} bounds.
36
+ */
37
+ interface KindEngine<A extends Definable = Definable, P extends PortableObject = PortableObject> {
38
+ /** Authoring object -> this kind's portable object (normalized; both lowerings must converge here). */
39
+ lower(authored: A): P;
40
+ /** CREATE DDL for one portable object (a fresh apply / migration `up` for an added object). */
41
+ emit(portable: P): string[];
42
+ /** DROP DDL for one portable object (`up` for a removed object, `down` for an added one). */
43
+ remove(portable: P): string[];
44
+ /**
45
+ * In-place CHANGE DDL taking `prev` to `next` (the dialect's ALTER/OVERWRITE). The spine calls
46
+ * `overwrite(next, prev)` to roll a change back. A kind with no in-place form recreates: implement
47
+ * as `[...remove(prev), ...emit(next)]`. Default (omitted) = recreate via emit(next).
48
+ */
49
+ overwrite?(prev: P, next: P): string[];
50
+ /**
51
+ * The CANONICAL change-detection key: the spine treats prev/next of the same object as a CHANGE iff
52
+ * their `canonical` differs. Default (omitted) = `emit(portable).join("\n")` — so a kind whose `emit`
53
+ * is already its canonical form needs nothing. Override when `emit` is FAITHFUL but some clauses must
54
+ * be EXCLUDED from equality — because the DB rewrites them on read (a cast suffix like `'x'::text`,
55
+ * added parens like `(a>0)`) or never introspects them (a COMMENT, an index) — so a faithful `emit` would phantom-diff a
56
+ * freshly-applied schema against `introspect`. Return `emit` MINUS those clauses: they stay create-time
57
+ * faithful in `emit`, but don't count as changes. `canonical(a) === canonical(b)` MUST mean "no
58
+ * migration needed". Affects ONLY classification; `emit`/`overwrite` (the DDL) are unaffected.
59
+ */
60
+ canonical?(portable: P): string;
61
+ /**
62
+ * Fine-grained DISPLAY items for a change of this object — so `better-schemic diff` shows per-SUB-OBJECT
63
+ * changes (a table decomposes into per-FIELD items: `field:user:name` changed), each carrying its
64
+ * owner `table` so the display GROUPS them hierarchically under it, instead of one coarse whole-object
65
+ * item. Called `(prev, next)`: a change diffs the two; `(undefined, next)` lists the object's
66
+ * sub-items as adds — the `--full` projection core uses for the full desired-state view. Default
67
+ * (omitted) = ONE whole-object item. DISPLAY ONLY — never affects up/down DDL (that is
68
+ * `emit`/`overwrite`); a structured driver reuses the per-field diff it already computes. Leave
69
+ * `DiffItem.file` unset (the caller attaches source linkage).
70
+ */
71
+ displayItems?(prev: P | undefined, next: P | undefined): DiffItem[];
72
+ /**
73
+ * Objects this one must be emitted AFTER — the cross-kind dependency edges (a field/index -> its
74
+ * table; an edge table -> its in/out tables; an event -> its table + any function it calls). Drives
75
+ * the topological sort in ./plan.ts. Omitted = no dependencies.
76
+ */
77
+ deps?(portable: P): Ref[];
78
+ /**
79
+ * The owning object to CLUSTER next to in the emitted order (an index's table) — readability only,
80
+ * never overrides {@link deps}. Omitted = a top-level object.
81
+ */
82
+ owner?(portable: P): Ref | undefined;
83
+ /**
84
+ * The STRUCTURAL container this object is nested within (an index's/field's table) — used for
85
+ * ADDRESSING and grouping (the CLI's dotted `parent.child`, e.g. `sc index info user.email_idx`) and
86
+ * distinct from {@link owner}, which is a DISPLAY choice (diff clustering). A kind may declare `parent`
87
+ * (it IS nested) while declining `owner` (it doesn't want per-parent diff clustering), or vice versa.
88
+ * The CLI resolves a nesting address as `parent ?? owner` (so a kind that only sets `owner` still
89
+ * addresses dotted). Omitted (and no `owner`) = a top-level object, addressed by its bare name.
90
+ */
91
+ parent?(portable: P): Ref | undefined;
92
+ /**
93
+ * Live connection -> all portable objects of THIS kind (the reverse direction). Introspection is
94
+ * often one `INFO`/catalog read yielding every kind at once; a driver backs all of its kinds'
95
+ * `introspect` with one shared (memoized) read and slices out this kind's objects. Omitted -> this
96
+ * kind isn't introspectable (diff/emit still work from authored state).
97
+ */
98
+ introspect?(conn: unknown): Promise<P[]>;
99
+ /**
100
+ * How this kind is PRESENTED — its human labels and the folder its objects render into. All optional
101
+ * with sensible defaults off the kind name (see {@link KindRegistry.display}), so a kind only declares
102
+ * what the defaults get wrong (e.g. `plural: "Indexes"`, or `folder: "access"`). DISPLAY ONLY.
103
+ */
104
+ display?: KindDisplay;
105
+ /**
106
+ * UNMANAGED by the migration pipeline: when `true`, objects of this kind are EXCLUDED from
107
+ * snapshot / diff / gen AND from the introspect-compare — so they never enter a migration file nor
108
+ * phantom-diff. For a kind whose lifecycle doesn't fit committed migrations: e.g. SurrealDB
109
+ * `DEFINE ACCESS`, which carries a secret the DB redacts on introspection (can't round-trip) and
110
+ * rotates on its own cadence. Such a kind is managed OUT-OF-BAND via the driver's own commands
111
+ * (`sc <kind> …`). `emit`/`lower` still work (a driver command may use them); only the automatic
112
+ * migration lifecycle skips it. Omitted/false = a normal, migration-managed kind.
113
+ *
114
+ * A PREDICATE form (`(portable) => boolean`) decides PER OBJECT — for a kind whose objects are
115
+ * managed only when they round-trip cleanly (e.g. SurrealDB access: key-free defs are manageable,
116
+ * key-bearing/redacted ones are not). The object is REQUIRED by
117
+ * {@link KindRegistry.isExcludedFromMigrations}; only a boolean `true` also skips introspection
118
+ * ({@link KindRegistry.skipsIntrospection}) — a predicate can't be decided there.
119
+ */
120
+ excludeFromMigrations?: boolean | ((portable: PortableObject) => boolean);
121
+ }
122
+ /** Per-kind presentation metadata (labels + output folder). All optional; core fills defaults. */
123
+ interface KindDisplay {
124
+ /** Title-Case singular, e.g. `"Table"`, `"Field"`. Default: the kind name, capitalized. */
125
+ label?: string;
126
+ /** Title-Case plural, e.g. `"Tables"`, `"Indexes"`. Default: the English plural of `label`. */
127
+ plural?: string;
128
+ /** The directory this kind's objects render into. Default: the lowercase slug of `plural`. */
129
+ folder?: string;
130
+ }
131
+ /** A kind's resolved presentation — every field filled (the shape {@link KindRegistry.display} returns). */
132
+ type ResolvedDisplay = Required<KindDisplay>;
133
+ /** A kind's full spec: its `name`, its `build` (the driver's authoring entry), and its engine. */
134
+ type KindSpec<Build extends (...args: never[]) => unknown, A extends Definable, P extends PortableObject> = {
135
+ name: string;
136
+ build: Build;
137
+ } & KindEngine<A, P>;
138
+ /**
139
+ * A driver's set of registered kinds + the generic behavior the spine reads off them. Built once per
140
+ * driver; `define` registers a kind and returns the driver's OWN `build` function UNCHANGED — so the
141
+ * driver writes `export const defineTable = registry.define({ name: "table", build, ...engine })` and
142
+ * keeps full type-safety + DX (TS preserves a generic `build`'s parameters across the passthrough).
143
+ */
144
+ declare class KindRegistry {
145
+ private readonly kinds;
146
+ /**
147
+ * Register a KIND. `build` is the driver's own authoring entry — ANY shape/chain — and its type
148
+ * flows through unchanged (type-safety + DX are the driver's to design). The engine fns give core
149
+ * the generic behavior. Registration ORDER is the kind's ordinal (the stable tie-break among
150
+ * independent objects in {@link orderObjects}), so register coarse-to-fine (table before index).
151
+ */
152
+ define<Build extends (...args: never[]) => unknown, A extends Definable, P extends PortableObject>(spec: KindSpec<Build, A, P>): Build;
153
+ /** The engine for `kind`, or undefined if no such kind is registered. */
154
+ engine(kind: string): KindEngine<any, any> | undefined;
155
+ /**
156
+ * Is this PORTABLE OBJECT UNMANAGED by the migration pipeline (its engine set
157
+ * {@link KindEngine.excludeFromMigrations})? The snapshot/diff/emit spine skips such objects — see
158
+ * the flag's docs. The OBJECT is required: a per-object predicate can't be evaluated without it, and
159
+ * defaulting to "managed" would let a key-bearing object slip into a migration. An unregistered kind
160
+ * is treated as managed (false), so a stray object never gets silently dropped by a typo.
161
+ */
162
+ isExcludedFromMigrations(portable: PortableObject): boolean;
163
+ /**
164
+ * Whether `kind` is STATICALLY excluded from migrations (`excludeFromMigrations === true`), so even
165
+ * introspection skips it. A per-object PREDICATE can't be decided without an object: introspection
166
+ * runs for the kind, and the diff/snapshot/emit choke points filter by object afterwards.
167
+ */
168
+ skipsIntrospection(kind: string): boolean;
169
+ /**
170
+ * A kind's resolved presentation — `label`/`plural`/`folder`, with defaults derived from the kind
171
+ * name for whatever the driver left unset. Works for unregistered display sub-kinds too (e.g. the
172
+ * `"field"` items a table's `displayItems` emits) — they just get the name-derived defaults.
173
+ */
174
+ display(kind: string): ResolvedDisplay;
175
+ /** Registered kind names, in registration order (== ordinal order). */
176
+ names(): string[];
177
+ /**
178
+ * A kind's ORDINAL = its registration index. Used ONLY as a tie-break among objects with no
179
+ * dependency relation, so independent objects come out stably layered (readability); it never
180
+ * overrides the dependency graph. An unknown kind sorts last.
181
+ */
182
+ ordinal(kind: string): number;
183
+ /** [name, engine] pairs in registration order — the spine iterates these. */
184
+ entries(): [string, KindEngine<any, any>][];
185
+ }
186
+
187
+ /** A node in the dependency graph: identity + the edges/owner used to order it. */
188
+ interface OrderNode {
189
+ readonly kind: string;
190
+ readonly name: string;
191
+ /** Objects this node must come AFTER (only intra-set refs constrain; external refs are ignored). */
192
+ readonly deps: Ref[];
193
+ /** Owning object to cluster next to (readability tie-break only; never overrides `deps`). */
194
+ readonly owner?: Ref;
195
+ }
196
+ /**
197
+ * Kahn's topological sort with two presentation tweaks among the nodes whose deps are all satisfied:
198
+ * prefer one OWNED by the currently-open cluster (so a table's children follow it), then lowest
199
+ * (kind-ordinal, then name). Correctness (deps) always wins — an owned/low-ordinal node can't jump a
200
+ * dependency. A genuine cycle throws (a named error). Refs to nodes outside `nodes` are ignored (an
201
+ * object may depend on something untouched by this diff — it already exists / isn't changing).
202
+ */
203
+ declare function orderObjects<T extends OrderNode>(nodes: T[], ordinalOf: (kind: string) => number): T[];
204
+ /**
205
+ * Author -> portable: lower each definable through its kind's engine (skipping unregistered kinds).
206
+ * The single place authoring becomes portable; everything downstream (diff/emit/snapshot) is portable.
207
+ */
208
+ declare function lowerSchema(registry: KindRegistry, defs: Definable[]): PortableObject[];
209
+ /**
210
+ * The registry SNAPSHOT — portable objects grouped by kind. The open, generic replacement for
211
+ * `PortableDb`'s fixed slots; serializes as plain JSON (it is plain data). Pre-launch: the format is
212
+ * free to change, no version migration.
213
+ */
214
+ interface KindSnapshot {
215
+ kinds: Record<string, PortableObject[]>;
216
+ }
217
+ /**
218
+ * Group a flat portable schema into a snapshot (by kind). Pass `registry` to DROP kinds/objects
219
+ * marked {@link KindEngine.excludeFromMigrations} (e.g. SurrealDB key-bearing access) so unmanaged,
220
+ * secret-bearing objects never enter a snapshot / migration. Omit it to snapshot every object
221
+ * unchanged.
222
+ */
223
+ declare function snapshotKinds(schema: PortableObject[], registry?: KindRegistry): KindSnapshot;
224
+ /** Flatten a snapshot back into a portable schema (the inverse of {@link snapshotKinds}). */
225
+ declare function snapshotObjects(snap: KindSnapshot): PortableObject[];
226
+ /** An up/down DDL program (each a list of statements). */
227
+ interface KindPlan {
228
+ up: string[];
229
+ down: string[];
230
+ }
231
+ /**
232
+ * Diff two portable schema states into an executable up/down program, generically over the registry.
233
+ *
234
+ * `up` runs creates/changes parent-first (the dependency graph) then drops child-first; `down` is the
235
+ * mirror: recreate drops parent-first, then undo creates/changes child-first. We invert PER OBJECT (not
236
+ * by reversing the flat DDL list) so a kind's multi-line block — a table emitted with its fields —
237
+ * keeps its internal order in both directions.
238
+ */
239
+ declare function planKinds(registry: KindRegistry, prev: PortableObject[], next: PortableObject[]): KindPlan;
240
+ /**
241
+ * The full {@link Diff} the CLI + migration model consume — up/down DDL + per-object display items +
242
+ * the whole desired schema (`full`, for `--full`). This is what a driver's `Driver.diff` returns once
243
+ * its kinds are on the registry (the generic counterpart of the fixed-slot `buildDiff`). Source-file
244
+ * linkage on the items is attached by the caller (the snapshot's `files` map), so `file` is left unset.
245
+ */
246
+ declare function buildKindDiff(registry: KindRegistry, prev: PortableObject[], next: PortableObject[]): Diff;
247
+ /**
248
+ * Fresh-apply DDL for a portable schema: every object created, ordered across kinds by the graph.
249
+ * (The `up` of a diff from an empty state.) Lower authoring first via {@link lowerSchema}.
250
+ */
251
+ declare function emitKinds(registry: KindRegistry, schema: PortableObject[]): string[];
252
+ /**
253
+ * Reverse direction, fanned out across kinds: introspect every introspectable kind off one live
254
+ * connection and flatten into portable objects. The RESOLUTION of "per-kind vs one driver read":
255
+ * the contract is per-kind ({@link KindEngine.introspect}), but a driver backs all of its kinds with
256
+ * ONE shared (memoized) read of `conn` and slices out each kind's objects — so the fan-out here costs
257
+ * a single round-trip, not N. A kind without `introspect` contributes nothing (not introspectable).
258
+ */
259
+ declare function introspectKinds(registry: KindRegistry, conn: unknown): Promise<PortableObject[]>;
260
+
261
+ /**
262
+ * One object's change, for display. `kind` is the object kind, `table` its owner (a table name,
263
+ * or the object's own name for db-level objects). `add` carries the new DDL; `remove` carries the
264
+ * `REMOVE` statement (`ddl`) plus the dropped object's prior DDL (`old`, for the unified patch);
265
+ * `change` pairs old↔new.
266
+ */
267
+ type DiffItem = {
268
+ key: string;
269
+ table: string;
270
+ /** Dialect-defined object kind (e.g. "table"/"field"/"index") — opaque to the display. */
271
+ kind: string;
272
+ /** The source file this object lives in (or lived in, for a removal). Absent if unknown. */
273
+ file?: string;
274
+ } & ({
275
+ op: "add";
276
+ ddl: string;
277
+ } | {
278
+ op: "remove";
279
+ ddl: string;
280
+ old: string;
281
+ } | {
282
+ op: "change";
283
+ before: string;
284
+ after: string;
285
+ });
286
+ interface Diff {
287
+ up: string[];
288
+ down: string[];
289
+ /**
290
+ * Apply-time secret bindings: `$param` name -> a write-only {@link SecretRef} (e.g. `env("X")`).
291
+ * Populated by a driver whose DDL emits secret placeholders (SurrealDB `DEFINE ACCESS … KEY $param`).
292
+ * MODEL 1: stored in the migration so it replays without the live schema; the **value never appears
293
+ * here** — the apply layer resolves each ref through a `SecretProvider` and binds it (`db.query(ddl,
294
+ * resolved)`), so secrets stay out of the schema, snapshot, and migration files. Diff-excluded +
295
+ * snapshot-omitted, so a redacted secret never reads as drift.
296
+ */
297
+ bindings?: Record<string, SecretRef>;
298
+ /** Structured per-object changes for the human display (word-level diff). */
299
+ items?: DiffItem[];
300
+ /** Every desired statement (the `next` schema), for the `--full` context view. */
301
+ full?: {
302
+ key: string;
303
+ table: string;
304
+ ddl: string;
305
+ }[];
306
+ }
307
+ /** `true` if the two snapshots define the same objects with identical DDL. */
308
+ declare function isEmptyDiff(diff: Diff): boolean;
309
+ /**
310
+ * Inline word-level diff of two statements: shared tokens dim, removed tokens red, added tokens
311
+ * green (LCS over space-separated tokens). So a changed field shows the whole statement with only
312
+ * the changed words highlighted.
313
+ */
314
+ declare function tokenDiff(before: string, after: string): string;
315
+ /** Render display items as a git-style file diff: each group headed by its source file path. */
316
+ declare function formatItems(items: DiffItem[], inline?: boolean): string;
317
+ /**
318
+ * A standard **unified diff** of the change, grouped one section per source file (git-style) — for
319
+ * piping through a diff viewer (git's pager / delta). Objects with no file fall back to a section
320
+ * headed by the object's bare name. A statement may be pretty-printed multi-line, so every LINE gets
321
+ * its own `+`/`-` and the hunk counts count lines, not statements.
322
+ */
323
+ declare function formatPatch(diff: Diff): string;
324
+ /** A human-readable view of a diff's forward (and optionally reverse) changes. */
325
+ declare function formatDiff(diff: Diff, opts?: {
326
+ down?: boolean;
327
+ full?: boolean;
328
+ inline?: boolean;
329
+ }): string;
330
+ /**
331
+ * A per-kind breakdown of a set of changes, e.g. `1 Table, 2 Fields`. Counts each item by its
332
+ * structured `kind` and labels it from the registry's per-kind {@link KindRegistry.display} (singular
333
+ * when the count is one), so the summary is correct for every dialect — no DDL parsing.
334
+ */
335
+ declare function summarizeKinds(registry: KindRegistry, items: readonly {
336
+ kind: string;
337
+ }[]): string;
338
+
339
+ /**
340
+ * The STORED snapshot (`_snapshot.json`): the canonical schema is portable objects grouped by kind
341
+ * (a {@link KindSnapshot}); DDL is derived generically via the kind registry (`buildKindDiff`/
342
+ * `emitKinds`). Diffed against the next `generate`. `files` maps each object's name to its
343
+ * project-root-relative source file (display-only; attached to diff items by the CLI). Pre-launch:
344
+ * the format is free to change, so there is no on-disk version migration — an unrecognized snapshot
345
+ * is treated as empty (regenerate via `better-schemic gen --baseline`).
346
+ */
347
+ interface StoredSnapshot {
348
+ version: 3;
349
+ /** The driver that authored this snapshot ("surrealdb"). */
350
+ driver: string;
351
+ /** Portable objects grouped by kind. */
352
+ schema: KindSnapshot;
353
+ files?: Record<string, string>;
354
+ }
355
+ /** A migration file on disk. The filename is the source of truth — there's no journal. */
356
+ interface Migration {
357
+ /** Filename without the `.surql` extension, e.g. `20260607153045_add_users`. */
358
+ tag: string;
359
+ /** Filename, e.g. `20260607153045_add_users.surql`. */
360
+ file: string;
361
+ }
362
+ /** The empty STORED snapshot — used as `prev` for a `--baseline` generate (diff against nothing). */
363
+ declare const EMPTY_STORED: StoredSnapshot;
364
+ /**
365
+ * Read the stored snapshot. Pre-launch: any snapshot that isn't the current `version: 3` shape (a
366
+ * pre-portable v1/v2, or absent) is treated as EMPTY — regenerate with `better-schemic gen --baseline`.
367
+ */
368
+ declare function readSnapshot(metaDir: string): StoredSnapshot;
369
+ declare function writeSnapshot(metaDir: string, snapshot: StoredSnapshot): void;
370
+ /**
371
+ * All migration files in `migrationsDir`, in apply order. Filenames are timestamp-prefixed, so
372
+ * a plain ascending sort is chronological (and legacy `0001_` names sort before timestamped
373
+ * ones). The `meta/` directory and any file not ending in `ext` (the driver's migration extension)
374
+ * are ignored.
375
+ */
376
+ declare function listMigrations(migrationsDir: string, ext?: string): Migration[];
377
+ /** A sortable UTC timestamp prefix for a new migration, e.g. `20260607153045`. */
378
+ declare function timestamp(date: Date): string;
379
+ /** sha256 of a migration file's contents (drift detection / apply-time bookkeeping). */
380
+ declare function checksum(content: string): string;
381
+ /** Turn a free-form migration name into a filename-safe slug. */
382
+ declare function slug(name: string): string;
383
+
384
+ /**
385
+ * Per-kind object filter for `pull`/`diff`/`sync`/`generate`. Each kind is independently
386
+ * included (optionally name-restricted). `DEFINE ACCESS` is OPT-IN everywhere — excluded
387
+ * unless `--access` is given — so an introspection (which redacts access signing keys) can't
388
+ * silently rotate them. Table-scoped objects (fields/indexes/events) follow their table.
389
+ */
390
+ interface Cat {
391
+ on: boolean;
392
+ /** When set, only these names of the kind are included. */
393
+ names?: Set<string>;
394
+ }
395
+ interface Filter {
396
+ tables: Cat;
397
+ functions: Cat;
398
+ events: Cat;
399
+ access: Cat;
400
+ }
401
+ /** Commander's parse of one `--kind [names]` / `--no-kind` flag: `undefined`/`true`/string/`false`. */
402
+ type FlagValue = string | boolean | undefined;
403
+ interface FilterOpts {
404
+ tables?: FlagValue;
405
+ functions?: FlagValue;
406
+ events?: FlagValue;
407
+ access?: FlagValue;
408
+ }
409
+ /** Build a {@link Filter} from CLI flags. Access is opt-in (`--access`); the rest default to on. */
410
+ declare function parseFilter(o: FilterOpts): Filter;
411
+ /** Attach the per-kind `--tables/--functions/--events/--access [names]` (+ `--no-*`) options. */
412
+ declare function kindFlags(cmd: Command): Command;
413
+ /** Whether a name passes a category gate (kind on + name allowed). Shared with the surreal filters. */
414
+ declare const inCat: (c: Cat, name: string) => boolean;
415
+ /**
416
+ * Whether a portable object passes the filter. A TOP-LEVEL object (no owner) is gated by its kind's
417
+ * category + name. An OWNED object (owner set — an index/event/constraint) FOLLOWS its owner table's
418
+ * inclusion; an `event` is ADDITIONALLY gated by the `events` category. (Fields are substrate nested
419
+ * in their table object, never standalone here.)
420
+ */
421
+ declare function passesFilter(registry: KindRegistry, o: PortableObject, f: Filter): boolean;
422
+ /** Keep only the portable objects that pass the filter (the {@link filterStructured} analog). */
423
+ declare function filterKinds(registry: KindRegistry, objects: PortableObject[], f: Filter): PortableObject[];
424
+ /**
425
+ * The stored snapshot to persist after a filtered `generate`: INCLUDED objects take their new state
426
+ * from `next`, EXCLUDED objects keep `prev`'s. Dedup by `kind:name` (an included `next` object wins).
427
+ * `files` overlays next on prev.
428
+ */
429
+ declare function mergeStored(registry: KindRegistry, prev: StoredSnapshot, next: StoredSnapshot, f: Filter): StoredSnapshot;
430
+ /**
431
+ * Restrict the `disk` objects to those that ALSO exist `live` (intersect by `kind:name`) AND pass the
432
+ * filter — for `baseline`. Hand-written schema not yet in the DB stays pending; what's really there is
433
+ * captured. Each field/index/event/constraint is its own object, so intersect-by-key handles them.
434
+ */
435
+ declare function intersectKinds(registry: KindRegistry, disk: PortableObject[], live: PortableObject[], f: Filter): PortableObject[];
436
+
437
+ /** One rendered object (table / function / access): its const statement + the imports it needs. */
438
+ interface RenderedUnit {
439
+ kind: "table" | "function" | "access";
440
+ /** DB object name (drives the file path). */
441
+ name: string;
442
+ /** The exported const identifier (`User`, `math_add`, …). */
443
+ exportName: string;
444
+ /** The `export const … = define…(…);` statement source (no import lines). */
445
+ code: string;
446
+ /** The `import …` lines this unit needs. */
447
+ imports: string[];
448
+ }
449
+ /** Local-only content a merge would drop when mirroring the DB. */
450
+ interface LocalOnly {
451
+ /** Per existing const: field keys present locally but absent from the DB object. */
452
+ fields: {
453
+ exportName: string;
454
+ fields: string[];
455
+ }[];
456
+ /** Whole consts present locally whose object the DB no longer has. */
457
+ objects: string[];
458
+ }
459
+ interface MergeResult {
460
+ content: string;
461
+ localOnly: LocalOnly;
462
+ }
463
+ /** Options governing what happens to local-only content. */
464
+ interface MergeOptions {
465
+ /** Keep local-only fields (graft them back into the merged object). */
466
+ keepLocalFields: boolean;
467
+ /** Keep local-only consts (objects the DB no longer has). */
468
+ keepLocalObjects: boolean;
469
+ }
470
+ /** What pulling would do to one schema file. */
471
+ interface PullFilePlan {
472
+ /** Path relative to the project root (for display). */
473
+ rel: string;
474
+ /** Absolute path on disk. */
475
+ abs: string;
476
+ /**
477
+ * `create` (new file), `update` (merged edits), `unchanged` (already matches the DB), or `delete`
478
+ * (a file that is purely local-only entities the DB doesn't have — removed when mirroring).
479
+ */
480
+ action: "create" | "update" | "unchanged" | "delete";
481
+ /** Current file contents (`""` for a new file). */
482
+ before: string;
483
+ /** Contents after the pull (the merged result). */
484
+ after: string;
485
+ /** Local-only content this file would drop when mirroring the DB. */
486
+ localOnly: LocalOnly;
487
+ }
488
+ /** A driver's introspection rendered into a per-file write plan (see a driver's `planPull`). */
489
+ interface PullPlan {
490
+ files: PullFilePlan[];
491
+ }
492
+ /** Apply a plan: write created/updated files, delete local-only files. Returns the paths touched. */
493
+ declare function applyPull(plan: PullPlan): string[];
494
+ /**
495
+ * Merge `units` into `existingSrc`. Each unit replaces the matching `export const` in place (DB wins),
496
+ * preserving everything else in the file. New units are appended; needed imports are unioned in.
497
+ * Local-only fields/objects are reported, and kept or dropped per `opts`.
498
+ */
499
+ declare function mergeUnits(existingSrc: string, units: RenderedUnit[], opts: MergeOptions): MergeResult;
500
+ /**
501
+ * A compact colored line diff for previews. A new file renders as all-green additions; an edit
502
+ * renders removed (red `-`) / added (green `+`) lines with a little surrounding context (long
503
+ * unchanged runs collapse to `…`).
504
+ */
505
+ declare function lineDiff(before: string, after: string): string;
506
+ /**
507
+ * A git-style unified diff between two texts, headed by `label` as the file path — for piping to a
508
+ * diff viewer (delta / git's pager). Returns "" when there's no change.
509
+ */
510
+ declare function unifiedDiff(before: string, after: string, label: string): string;
511
+ /** Colored verb for a pull action (`new` / `update` / `delete` / `unchanged`). */
512
+ declare function actionLabel(action: "create" | "update" | "unchanged" | "delete"): string;
513
+
514
+ /**
515
+ * The dialect-NEUTRAL authoring contract — the only structure the orchestration reads off an
516
+ * authored object (everything else is opaque and handed straight to {@link Driver.explode}). A table
517
+ * contributes just its `name`; this is the upper bound for a driver's table-authoring type. The
518
+ * Surreal `TableDef` is a structural subtype, as is any future dialect's table builder.
519
+ */
520
+ interface Authored {
521
+ readonly name: string;
522
+ }
523
+ /**
524
+ * The neutral contract for a standalone (non-table) authored object — an event/function/access. It
525
+ * adds a `kind` discriminant and, for objects owned by a table (e.g. an event), the owner `table`
526
+ * name (so the snapshot can file-link a child object under its parent). The Surreal `StandaloneDef`
527
+ * union is a structural subtype.
528
+ */
529
+ interface AuthoredDef extends Authored {
530
+ readonly kind: string;
531
+ readonly table?: string;
532
+ }
533
+ /**
534
+ * A single emitted DDL statement, structured: object identity (`kind`/`name`/`table`) + the dialect
535
+ * `ddl` string, plus an optional clause map (each value an `ALTER … <set>` form) for dialects that
536
+ * diff clause-level. `kind` is a dialect-defined string the orchestration treats opaquely — the
537
+ * SurrealDB `DefineStatement` (with its fixed kind union) is a structural subtype of this.
538
+ */
539
+ interface Statement {
540
+ kind: string;
541
+ name: string;
542
+ table?: string;
543
+ ddl: string;
544
+ clauses?: Record<string, string>;
545
+ /**
546
+ * Apply-time secret bindings for this statement's `$param` placeholders — `param` name ->
547
+ * a write-only {@link SecretRef}. Collected into {@link Diff.bindings}; the value never lives here
548
+ * (resolved at apply through a `SecretProvider`). See {@link Diff.bindings}.
549
+ */
550
+ bindings?: Record<string, SecretRef>;
551
+ }
552
+ /** Options for {@link Driver.emit} — mirrors the existing `DefineOptions` (e.g. IF NOT EXISTS). */
553
+ interface EmitOptions {
554
+ ifNotExists?: boolean;
555
+ overwrite?: boolean;
556
+ }
557
+ /** Options for {@link Driver.apply}. */
558
+ interface ApplyOptions {
559
+ /**
560
+ * Run the whole batch atomically. `migrate` wraps up/down + `_migrations` bookkeeping in one
561
+ * transaction; a driver that can't MUST surface that (the migration model degrades to best-effort).
562
+ */
563
+ transactional?: boolean;
564
+ }
565
+ /** Per-connection overrides (url/namespace/credentials) — superset across dialects. */
566
+ interface ConnectionOverrides {
567
+ url?: string;
568
+ namespace?: string;
569
+ database?: string;
570
+ username?: string;
571
+ password?: string;
572
+ authLevel?: string;
573
+ }
574
+ /** The direction a migration is applied in. */
575
+ type MigrationDirection = "up" | "down";
576
+ /** A migration's bookkeeping identity, recorded in the migrations-tracking table. */
577
+ interface MigrationRecord {
578
+ tag: string;
579
+ file: string;
580
+ /** sha of the migration file at apply time (drift detection). */
581
+ checksum: string;
582
+ }
583
+ /**
584
+ * The apply-time, dialect-specific half of the migration runner. The orchestration (which
585
+ * migrations are pending, ordering, the lock-then-loop) stays driver-neutral in cli/migrate.ts;
586
+ * this capability owns the SQL: the tracking table, the applied-records, the advisory lock, and the
587
+ * atomic apply+record. A driver WITHOUT it can't run migrations (diff/gen still work). `Conn` is the
588
+ * driver's own connection type.
589
+ */
590
+ interface MigrationStore<Conn = unknown> {
591
+ /** This dialect's migration-file extension, e.g. `".surql"` (SurrealDB). */
592
+ readonly extension: string;
593
+ /** Render a diff as this dialect's migration-file body (e.g. SurrealQL `IF $direction` up/down). */
594
+ render(tag: string, diff: Diff): string;
595
+ /** Ensure the migrations-tracking table exists. */
596
+ ensure(conn: Conn, table: string): Promise<void>;
597
+ /** Applied migrations: tag -> checksum recorded at apply time. */
598
+ applied(conn: Conn, table: string): Promise<Map<string, string>>;
599
+ /**
600
+ * Apply one migration's `up`/`down` PROGRAM plus its bookkeeping write atomically: on `up` record
601
+ * the migration, on `down` erase it — so the record is written iff the DDL actually applied.
602
+ */
603
+ apply(conn: Conn, table: string, m: {
604
+ content: string;
605
+ direction: MigrationDirection;
606
+ record: MigrationRecord;
607
+ }): Promise<void>;
608
+ /** Record a migration as applied WITHOUT running its DDL (baseline of an existing DB). */
609
+ record(conn: Conn, table: string, record: MigrationRecord): Promise<void>;
610
+ /** Drop all applied records (baseline-squash reconcile). */
611
+ clear(conn: Conn, table: string): Promise<void>;
612
+ /** Take an advisory lock so two runs can't race — throws if already held. */
613
+ lock(conn: Conn, table: string): Promise<void>;
614
+ /** Release the advisory lock (idempotent). */
615
+ unlock(conn: Conn, table: string): Promise<void>;
616
+ }
617
+ /**
618
+ * An OPTIONAL throwaway-instance capability for round-trip canonicalization and `sz check`'s
619
+ * migration replay. Absent -> `check`/replay-verification is degraded/unavailable (diff/apply still
620
+ * work, since a kind's `lower`/`introspectAll` already canonicalize).
621
+ */
622
+ interface ShadowCapability<Conn> {
623
+ /** Apply `ddl` to a fresh scratch DB, introspect it back to portable objects, then drop it. */
624
+ roundTrip(conn: Conn, config: ResolvedConfig, ddl: string): Promise<PortableObject[]>;
625
+ /** Spin up a fully-isolated ephemeral instance (for migration replay). Caller must `stop()`. */
626
+ ephemeral?(): Promise<{
627
+ conn: Conn;
628
+ stop: () => Promise<void>;
629
+ }>;
630
+ }
631
+ /**
632
+ * User-defined DB functions — the `.call` side of the query layer's (B) surface (DB functions as code).
633
+ * `invoke` calls a defined function by name with already-encoded args and returns the function's RAW
634
+ * result (the driver extracts it from its own response shape — surreal `RETURN fn::name($a)` yields the
635
+ * value; a row-returning call yields a row set). The caller decodes that raw value through the
636
+ * function's `.returns(R)` schema via `callFunction` in `@better-schemic/core/query`. A defined function still
637
+ * emits/migrates via the schema engine regardless; this capability only adds INVOCATION.
638
+ */
639
+ interface CallableFunctions<Conn = unknown> {
640
+ invoke(conn: Conn, name: string, args: Record<string, unknown>): Promise<unknown>;
641
+ }
642
+ /** A declared argument for a {@link DriverCommand} — used for parsing + `--help`. */
643
+ interface CommandArgs {
644
+ /**
645
+ * Positional args, in order. Core collects ALL positional tokens into a list (incl. raw `key=value`)
646
+ * and the driver interprets + validates arity; mark the last `variadic` for "one or more".
647
+ */
648
+ positionals?: readonly {
649
+ name: string;
650
+ required?: boolean;
651
+ variadic?: boolean;
652
+ help?: string;
653
+ }[];
654
+ /** Named flags. `value: true` takes a value (`--user U`); otherwise it's a boolean (`--dry-run`). */
655
+ flags?: readonly {
656
+ name: string;
657
+ value?: boolean;
658
+ required?: boolean;
659
+ help?: string;
660
+ }[];
661
+ }
662
+ /** argv parsed against a command's {@link CommandArgs}: positional tokens (driver-interpreted) + flags. */
663
+ interface ParsedCommandArgs {
664
+ /** Every positional token in order (incl. raw `key=value`); the driver interprets them. */
665
+ positionals: string[];
666
+ /** Flags: a value-flag -> its string, a boolean flag -> `true`, an absent flag -> `undefined`. */
667
+ flags: Record<string, string | boolean | undefined>;
668
+ }
669
+ /** Output + input helpers core hands a command (so a driver never touches stdio directly). */
670
+ interface CommandIo {
671
+ ok(message: string): void;
672
+ fail(message: string): void;
673
+ info(message: string): void;
674
+ /** Prompt for a line of input (`hidden` masks it) — for a sensitive value not passed inline (no shell-history leak). */
675
+ prompt(question: string, opts?: {
676
+ hidden?: boolean;
677
+ }): Promise<string>;
678
+ }
679
+ /** The context core hands a {@link DriverCommand.run}: a connected db + the resolved config + io + secrets. */
680
+ interface CommandContext<Conn = unknown> {
681
+ conn: Conn;
682
+ config: ResolvedConfig;
683
+ io: CommandIo;
684
+ /** The configured secret provider (default reads `process.env`) for resolving {@link SecretRef}s. */
685
+ secrets: SecretProvider;
686
+ }
687
+ /**
688
+ * A driver-contributed CLI command — `sc <kind> <verb> [args]`. Core dispatches; the driver owns the
689
+ * dialect logic in {@link run}. The driver validates positional arity itself (core only collects them).
690
+ */
691
+ interface DriverCommand<Conn = unknown> {
692
+ /** Kind namespace — `sc <kind> …` (e.g. `"access"`, `"table"`). */
693
+ kind: string;
694
+ /** Verb under the kind — `sc <kind> <verb>` (e.g. `"rotate"`, `"check"`, `"find"`). */
695
+ verb: string;
696
+ /** One-line help shown in the command listing. */
697
+ summary: string;
698
+ /** Declared args for parsing + `--help`. */
699
+ args?: CommandArgs;
700
+ run(ctx: CommandContext<Conn>, args: ParsedCommandArgs): Promise<void>;
701
+ }
702
+ /**
703
+ * A database dialect, expressed as a SET OF KINDS (core-v2). The driver registers its object kinds on
704
+ * `registry`; core orchestrates schema ops GENERICALLY over it (`lowerSchema`/`buildKindDiff`/
705
+ * `emitKinds`/`orderObjects`) — it never names a kind. The driver owns only what isn't generic: the
706
+ * authoring -> kinded `explode`, a single-read `introspectAll`, the connection lifecycle, and the
707
+ * dialect-specific command capabilities. The field/type substrate (`PortableType`/`s.*`) stays core.
708
+ * See docs/kind-registry-flip-plan.md.
709
+ */
710
+ interface Driver<Conn = unknown, Tbl extends Authored = Authored, Def extends AuthoredDef = AuthoredDef> {
711
+ readonly name: string;
712
+ /** This driver's registered KINDS. Core runs lower/diff/emit/order generically over it. */
713
+ readonly registry: KindRegistry;
714
+ /**
715
+ * Authoring (loaded `defineTable`/standalone defs) -> kinded {@link Definable}s. The driver-side
716
+ * fan-out: one inline-authored table explodes into `[table, ...index, ...event/constraint]`, each
717
+ * tagged with its `kind`. Core then lowers via `lowerSchema(registry, explode(...))` — so
718
+ * `KindEngine.lower` stays 1:1 and the contract needs no explode hook.
719
+ */
720
+ explode(tables: Tbl[], defs: Def[]): Definable[];
721
+ /**
722
+ * Live connection -> ALL portable objects, fanned across kinds from ONE read (INFO STRUCTURE /
723
+ * the system catalog). Must canonicalize IDENTICALLY to lowering (a clean apply round-trips to a zero diff)
724
+ * and be COMPLETE (return every diffable kind, else presence-phantom-diffs). `exclude` skips tables
725
+ * by name.
726
+ */
727
+ introspectAll(conn: Conn, exclude?: Set<string>): Promise<PortableObject[]>;
728
+ connect(config: ResolvedConfig, over?: ConnectionOverrides): Promise<Conn>;
729
+ apply(conn: Conn, statements: string[], opts?: ApplyOptions): Promise<void>;
730
+ /** Tear down a connection opened by {@link connect} (the orchestration owns the lifecycle). */
731
+ close(conn: Conn): Promise<void>;
732
+ readonly shadow?: ShadowCapability<Conn>;
733
+ /** Apply-time migration bookkeeping. Absent -> this driver can't run migrations (diff/gen still do). */
734
+ readonly migrations?: MigrationStore<Conn>;
735
+ /**
736
+ * Diff the LIVE database against the loaded schema into executable up/down DDL. Owns every
737
+ * dialect-specific normalization and apply-time fixup (Surreal: a shadow-DB round-trip to cancel
738
+ * formatting noise, the redacted-access-key swap, and the implicit-wildcard OVERWRITE re-mark), so
739
+ * the result is safe to apply as-is. Backs `diff --live`, `push`, and the baseline reconcile.
740
+ */
741
+ diffLive?(conn: Conn, config: ResolvedConfig, filter: Filter): Promise<Diff>;
742
+ /** Reduce a live diff (from {@link diffLive}) to the statements `push` applies; `prune: false` keeps removals. */
743
+ syncPlan?(diff: Diff, prune?: boolean): string[];
744
+ /**
745
+ * Dialect-specific CLI commands invoked as `sc <kind> <verb> [args]` — e.g. surreal `access rotate`.
746
+ * Core discovers + dispatches them generically (see {@link DriverCommand});
747
+ * it never names a kind/verb. Absent -> this driver contributes no extra commands.
748
+ */
749
+ readonly commands?: readonly DriverCommand<Conn>[];
750
+ /**
751
+ * Render portable objects to per-file source in THIS dialect's `s.*` syntax, filtered — the codegen
752
+ * behind the offline `diff --ts` and `pull`. Takes `PortableObject[]` (this driver's own portable
753
+ * shape): `diff --ts` renders the SNAPSHOT side (stored portable) and the DESIRED side
754
+ * (`lowerSchema(explode(...))`) at MATCHING fidelity so an in-sync schema yields identical files;
755
+ * `pull` renders the introspected DB. The driver re-derives its structured form from the portable
756
+ * objects (parsing its own DDL where needed — docs/kind-registry-flip-plan.md §6b). `single` (a file
757
+ * key) folds everything into one module; otherwise `fileFor` maps each object to its own file.
758
+ */
759
+ renderSchema?(objects: PortableObject[], filter: Filter, fileFor: (kind: string, name: string) => string, single?: string): Map<string, string>;
760
+ /**
761
+ * The two sides of `diff --ts --live` rendered to per-file source: the live DB (`current`) and the
762
+ * declared schema (`desired`), both normalized through the dialect so an unchanged schema yields
763
+ * identical files.
764
+ */
765
+ diffTsLive?(conn: Conn, config: ResolvedConfig, filter: Filter, fileFor: (kind: string, name: string) => string, single?: string): Promise<{
766
+ current: Map<string, string>;
767
+ desired: Map<string, string>;
768
+ }>;
769
+ /**
770
+ * Replay every migration into a throwaway engine and diff the result against the schema (`check`).
771
+ * Owns ephemeral-engine selection + setup; `log` receives progress lines. Needs a {@link shadow}-
772
+ * class capability. An empty diff means the migrations reproduce the schema.
773
+ */
774
+ checkReplay?(config: ResolvedConfig, over: ConnectionOverrides, filter: Filter, log: (msg: string) => void): Promise<Diff>;
775
+ /** Introspect the live DB and plan schema-file codegen (`pull`); writing is the neutral `applyPull`. */
776
+ planPull?(conn: Conn, config: ResolvedConfig, opts: {
777
+ filter: Filter;
778
+ keepLocal?: boolean;
779
+ }): Promise<PullPlan>;
780
+ /** A human-readable server identity for `doctor` (e.g. "SurrealDB 3.1.3"); throws if unreachable. */
781
+ serverInfo?(conn: Conn): Promise<string>;
782
+ /**
783
+ * Run a raw READ query and return rows — for connection RESOLVERS (a multi-connection resolver's
784
+ * `ctx.connections.<name>.query(...)`) and `seed`. The `sql` is this dialect's query language; the
785
+ * orchestration treats the rows opaquely. Absent -> a resolver can't read from this connection.
786
+ */
787
+ query?<T = unknown>(conn: Conn, sql: string, vars?: Record<string, unknown>): Promise<T[]>;
788
+ /**
789
+ * User-defined DB functions ((B) of the query layer) — invoke a defined function + decode the result.
790
+ * Absent -> no `.call()` surface on this driver (the function still emits/migrates). See
791
+ * {@link CallableFunctions}.
792
+ */
793
+ readonly callable?: CallableFunctions<Conn>;
794
+ /**
795
+ * The dialect-specific files `better-schemic init` scaffolds, keyed by project-relative path: a
796
+ * connections-only `better-schemic.config.ts` (using this driver's `<driver>Connection` factory), a sample
797
+ * schema module in this dialect's `s.*`, a seed stub, a `.env.example`, … The CLI writes them
798
+ * verbatim (never overwriting) alongside the dialect-neutral migration snapshot it records itself.
799
+ * Absent -> `better-schemic init` can't scaffold a project for this driver.
800
+ */
801
+ initScaffold?(): Record<string, string>;
802
+ /**
803
+ * Scaffold a NEW entity file's contents — the starter `s.*` / `define*` module for an object of
804
+ * `kind` named `name` (e.g. `("table", "user")` -> a `defineTable("user", { … })` module in this
805
+ * dialect's authoring). Returns the file text; the CLI writes it under the kind's
806
+ * {@link KindRegistry.display} folder. THROW for a kind this driver can't author (the CLI surfaces
807
+ * the message). Absent -> `better-schemic new` is unavailable for this driver.
808
+ */
809
+ scaffoldEntity?(kind: string, name: string): string;
810
+ }
811
+ /** Register a driver under its `name` (idempotent; last write wins). */
812
+ declare function registerDriver(driver: Driver<unknown>): void;
813
+ /** Look up a registered driver, or throw with the list of known names. */
814
+ declare function getDriver(name: string): Driver<unknown>;
815
+ /** All registered driver names (for help text / config validation). */
816
+ declare function driverNames(): string[];
817
+
818
+ export { intersectKinds as $, type Authored as A, type ResolvedDisplay as B, type CallableFunctions as C, type Driver as D, EMPTY_STORED as E, type Filter as F, type Statement as G, type StoredSnapshot as H, actionLabel as I, applyPull as J, KindRegistry as K, type LocalOnly as L, type MergeOptions as M, buildKindDiff as N, type OrderNode as O, type ParsedCommandArgs as P, checksum as Q, type Ref as R, type ShadowCapability as S, driverNames as T, emitKinds as U, filterKinds as V, formatDiff as W, formatItems as X, formatPatch as Y, getDriver as Z, inCat as _, type AuthoredDef as a, introspectKinds as a0, isEmptyDiff as a1, kindFlags as a2, lineDiff as a3, listMigrations as a4, lowerSchema as a5, mergeStored as a6, mergeUnits as a7, orderObjects as a8, parseFilter as a9, passesFilter as aa, planKinds as ab, readSnapshot as ac, registerDriver as ad, slug as ae, snapshotKinds as af, snapshotObjects as ag, summarizeKinds as ah, timestamp as ai, tokenDiff as aj, unifiedDiff as ak, writeSnapshot as al, type ApplyOptions as b, type CommandArgs as c, type CommandContext as d, type CommandIo as e, type ConnectionOverrides as f, type Definable as g, type Diff as h, type DiffItem as i, type DriverCommand as j, type EmitOptions as k, type FilterOpts as l, type KindDisplay as m, type KindEngine as n, type KindPlan as o, type KindSnapshot as p, type KindSpec as q, type MergeResult as r, type Migration as s, type MigrationDirection as t, type MigrationRecord as u, type MigrationStore as v, type PortableObject as w, type PullFilePlan as x, type PullPlan as y, type RenderedUnit as z };