@orkestrel/database 0.0.13 → 0.0.14

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.
@@ -1,26 +1,21 @@
1
- import { AggregateOperation } from '@orkestrel/database';
2
- import { AggregateOperation as AggregateOperation_2 } from '@orkestrel/database';
3
- import { ColumnSchema } from '@orkestrel/database';
4
- import { ColumnStorage } from '@orkestrel/database';
5
- import { Condition } from '@orkestrel/database';
6
- import { DriverInterface } from '@orkestrel/database';
7
- import { DriverInterface as DriverInterface_2 } from '@orkestrel/database';
8
- import { DriverMetadata } from '@orkestrel/database';
9
- import { FieldPath } from '@orkestrel/contract';
10
- import { Key } from '@orkestrel/database';
11
- import { MigrationInput } from '@orkestrel/database';
12
- import { MigrationStep } from '@orkestrel/database';
13
- import { OperationOptions } from '@orkestrel/database';
14
- import { Order } from '@orkestrel/database';
15
- import { QueryInput } from '@orkestrel/database';
16
- import { QueryInput as QueryInput_2 } from '@orkestrel/database';
17
- import { Row } from '@orkestrel/database';
18
- import { Row as Row_2 } from '@orkestrel/database';
19
- import { SQLiteRow } from '@orkestrel/sqlite';
20
- import { SQLiteValue } from '@orkestrel/sqlite';
21
- import { StorageInterface } from '@orkestrel/database';
22
- import { TableSchema } from '@orkestrel/database';
23
- import { TableSchema as TableSchema_2 } from '@orkestrel/database';
1
+ import type { AggregateOperation } from '@orkestrel/database';
2
+ import type { ColumnSchema } from '@orkestrel/database';
3
+ import type { ColumnStorage } from '@orkestrel/database';
4
+ import type { Condition } from '@orkestrel/database';
5
+ import type { DriverInterface } from '@orkestrel/database';
6
+ import type { DriverMetadata } from '@orkestrel/database';
7
+ import type { FieldPath } from '@orkestrel/contract';
8
+ import type { Key } from '@orkestrel/database';
9
+ import type { MigrationInput } from '@orkestrel/database';
10
+ import type { MigrationStep } from '@orkestrel/database';
11
+ import type { OperationOptions } from '@orkestrel/database';
12
+ import type { Order } from '@orkestrel/database';
13
+ import type { QueryInput } from '@orkestrel/database';
14
+ import type { Row } from '@orkestrel/database';
15
+ import type { SQLiteRow } from '@orkestrel/sqlite';
16
+ import type { SQLiteValue } from '@orkestrel/sqlite';
17
+ import type { StorageInterface } from '@orkestrel/database';
18
+ import type { TableSchema } from '@orkestrel/database';
24
19
 
25
20
  /**
26
21
  * Compiles an {@link AggregateOperation} over a {@link FieldPath}.
@@ -45,20 +40,20 @@ export declare function compileColumnSQL(storage: ColumnStorage): string;
45
40
  *
46
41
  * @remarks
47
42
  * Every operand is run through `encodeValue`, so a bound value matches the SQL
48
- * the column side compiles to. A flat column encodes operands with its DECLARED
43
+ * the column side compiles to. A flat column encodes operands with its declared
49
44
  * schema type (a flat `json` column → `JSON.stringify`); a nested `FieldPath`
50
- * encodes each operand as the NATIVE scalar `json_extract` returns, derived from
45
+ * encodes each operand as the native scalar `json_extract` returns, derived from
51
46
  * the operand's runtime type (per-operand, since `between` / `any` / `none` can
52
47
  * mix types). `any` / `none` collapse an empty list to a constant (`0` matches
53
48
  * nothing, `1` matches all) with no parameters.
54
49
  *
55
- * The core engine's total order ranks `undefined` (rank 0) BELOW `null`
56
- * (rank 1) (see `compareValues`), so a MISSING/`NULL` column MATCHES
50
+ * The core engine's total order ranks `undefined` (rank 0) below `null`
51
+ * (rank 1) (see `compareValues`), so a missing/`NULL` column matches
57
52
  * `below` / `to` / a scalar `not` / `none` — the opposite of raw SQL, where a
58
53
  * comparison against `NULL` is `NULL` (excluded). This fragment replicates the
59
54
  * engine exactly. Truth table (`value` = the engine's decoded field read; a
60
- * FLAT column's stored `NULL` decodes to `undefined` per `decodeRow`, so a
61
- * flat `value` is NEVER a present `null` — only a NESTED path can be
55
+ * flat column's stored `NULL` decodes to `undefined` per `decodeRow`, so a
56
+ * flat `value` is never a present `null` — only a nested path can be
62
57
  * present-but-`null`):
63
58
  *
64
59
  * ```text
@@ -84,15 +79,15 @@ export declare function compileColumnSQL(storage: ColumnStorage): string;
84
79
  * refines every optional or nullable scalar comparison through the core engine.
85
80
  * This compiler still emits a total SQL fragment for direct consumers.
86
81
  *
87
- * A NESTED path can be present-but-`null` (a stored JSON `null`), which
88
- * `json_extract` reads back as SQL `NULL` — indistinguishable from an ABSENT
82
+ * A nested path can be present-but-`null` (a stored JSON `null`), which
83
+ * `json_extract` reads back as SQL `NULL` — indistinguishable from an absent
89
84
  * path. `json_type(col, path)` disambiguates them (`'null'` for present-null,
90
85
  * SQL `NULL` for absent), so nested `equals` / `not` against a `null` operand
91
86
  * compile through `json_type` instead of `IS NULL` / `IS NOT NULL`.
92
87
  *
93
88
  * Every other MATCH-on-null-or-absent row is expressed uniformly (flat and
94
89
  * nested alike) as `(<column> <op> ? OR <column> IS NULL)` — for a nested
95
- * path, `json_extract` already collapses BOTH absent and present-null to SQL
90
+ * path, `json_extract` already collapses both absent and present-null to SQL
96
91
  * `NULL`, so `IS NULL` catches both in one clause; for a flat column there is
97
92
  * only the absent case to catch.
98
93
  *
@@ -111,7 +106,8 @@ export declare function compileColumnSQL(storage: ColumnStorage): string;
111
106
  export declare function compileConditionSQL(condition: Condition, schema: TableSchema): CompiledSQL;
112
107
 
113
108
  /**
114
- * Represents a parameterized SQL fragment or statement plus its bind values.
109
+ * Represents a parameterized SQL fragment or statement plus its bind values. The
110
+ * `@orkestrel/database/server` entry point exports this type.
115
111
  *
116
112
  * @remarks
117
113
  * Produced by the pure SQL compilers (`compilers.ts`) that turn a core
@@ -128,15 +124,19 @@ export declare interface CompiledSQL {
128
124
  /**
129
125
  * Compiles a {@link FieldPath} to the SQL expression that reads it.
130
126
  *
127
+ * @remarks
128
+ * A flat path compiles to the quoted column; a nested path compiles to a
129
+ * `json_extract` over the head column with the rest of the path as its accessor.
130
+ *
131
131
  * @param path - The field path
132
132
  * @returns The SQL expression selecting the value
133
133
  */
134
134
  export declare function compileFieldSQL(path: FieldPath): string;
135
135
 
136
136
  /**
137
- * Compiles a NESTED {@link FieldPath} to the `json_type(<col>, <path>)` SQL
137
+ * Compiles a nested {@link FieldPath} to the `json_type(<col>, <path>)` SQL
138
138
  * expression — the {@link compileFieldSQL} `json_extract` sibling used to tell a
139
- * PRESENT JSON `null` apart from an ABSENT path (both read back as SQL `NULL`
139
+ * present JSON `null` apart from an absent path (both read back as SQL `NULL`
140
140
  * through `json_extract`, but `json_type` reports `'null'` for the former and
141
141
  * SQL `NULL` for the latter).
142
142
  *
@@ -211,7 +211,7 @@ export declare function compilePageSQL(limit: number | undefined, offset: number
211
211
  * `FieldPath` (a `json_extract` read) encodes each operand as the native scalar
212
212
  * the extract returns — derived from the operand's runtime type — so it compares.
213
213
  * Every operator maps per the databases guide's operator table, with
214
- * `starts` / `ends` compiling to a CODE-POINT `substr` slice guarded by
214
+ * `starts` / `ends` compiling to a code-point `substr` slice guarded by
215
215
  * `typeof(<column>) = 'text'` (case-sensitive, matching the engine's
216
216
  * `String.prototype.startsWith` / `endsWith`) and an empty `any` / `none` list
217
217
  * collapsing to a constant. An `undefined` input (or one with no parts)
@@ -236,7 +236,7 @@ export declare function compileQuerySQL(input: QueryInput | undefined, schema: T
236
236
  * @remarks
237
237
  * The first condition's connector is ignored, per the {@link Condition} types.
238
238
  * Every fragment (see {@link compileConditionSQL}'s truth table) replicates the core
239
- * engine's total order EXACTLY under SQL's three-valued NULL logic, so this
239
+ * engine's total order exactly under SQL's three-valued NULL logic, so this
240
240
  * clause matches `applyQuery` row-for-row over the same table — a native
241
241
  * `records` / `count` read never disagrees with a scan-and-filter fallback.
242
242
  *
@@ -253,7 +253,7 @@ export declare function compileQuerySQL(input: QueryInput | undefined, schema: T
253
253
  export declare function compileWhereSQL(conditions: readonly Condition[], schema: TableSchema): CompiledSQL;
254
254
 
255
255
  /**
256
- * Creates a persistent JSON-file {@link DriverInterface} for the core database layer.
256
+ * Creates a persistent JSON-file {@link DriverInterface} for a given path.
257
257
  *
258
258
  * @remarks
259
259
  * Pass it to `createDatabase` from `@orkestrel/database` to run the typed
@@ -285,7 +285,8 @@ export declare function compileWhereSQL(conditions: readonly Condition[], schema
285
285
  export declare function createJSONDriver(path: string): DriverInterface;
286
286
 
287
287
  /**
288
- * Creates a trusted-mode SQLite {@link DriverInterface} for the core database layer.
288
+ * Creates a trusted-mode, server-native SQLite {@link DriverInterface} for a database path,
289
+ * or for `:memory:` when the options bag omits one.
289
290
  *
290
291
  * @remarks
291
292
  * Pass it to `createDatabase` from `@orkestrel/database` to run the typed
@@ -371,7 +372,7 @@ export declare function decodeValue(value: SQLiteValue, column: ColumnSchema): u
371
372
  * so a plan-built index name always matches one `open` would have created.
372
373
  *
373
374
  * @remarks
374
- * A naive `idx_<table>_<cols joined by _>` is AMBIGUOUS: table `'a_b'` with
375
+ * A naive `idx_<table>_<cols joined by _>` is ambiguous: table `'a_b'` with
375
376
  * column `'c'` and table `'a'` with columns `['b', 'c']` both produce
376
377
  * `idx_a_b_c`. This encodes each part (the table name, then each column name)
377
378
  * length-prefixed (`<len>_<part>`) so the boundary between parts is always
@@ -431,28 +432,28 @@ export declare function encodeRow(row: Row, schema: TableSchema): SQLiteRow;
431
432
  export declare function encodeValue(value: unknown, column: ColumnSchema): SQLiteValue;
432
433
 
433
434
  /**
434
- * Lists the declared {@link ColumnStorage}s whose SQL EQUALITY comparisons (`equals` /
435
+ * Lists the declared {@link ColumnStorage}s whose SQL equality comparisons (`equals` /
435
436
  * `not` / `any` / `none`) and `starts` / `ends` compiles are provably
436
437
  * engine-exact under declared-type trust — `text` / `integer` / `real` /
437
438
  * `boolean`; a `json` or `blob` column always refines instead.
438
439
  *
439
440
  * @remarks
440
- * This set governs equality and prefix/suffix matching only. RANGE
441
+ * This set governs equality and prefix/suffix matching only. Range
441
442
  * comparisons (`above` / `below` / `from` / `to` / `between`) and `ORDER BY`
442
- * are exact for `integer` / `real` / `boolean` but NOT for `text`: compiled
443
+ * are exact for `integer` / `real` / `boolean` but not for `text`: compiled
443
444
  * SQL orders/ranges under SQLite's default BINARY collation, which compares
444
- * TEXT byte-for-byte as UTF-8 — equivalent to Unicode CODE-POINT order —
445
+ * TEXT byte-for-byte as UTF-8 — equivalent to Unicode code-point order —
445
446
  * while the core engine's `compareValues` orders JS strings with `<`, which
446
- * compares UTF-16 CODE-UNIT order. The two orders diverge for supplementary-
447
+ * compares UTF-16 code-unit order. The two orders diverge for supplementary-
447
448
  * plane characters (code points ≥ U+10000, for example many emoji): a lead surrogate
448
- * (`\uD800`–`\uDBFF`) sorts BELOW ``–`￿` in code-unit order, while
449
- * its code point sorts ABOVE them. So `matchesConditionExactly`'s range family and
449
+ * (`\uD800`–`\uDBFF`) sorts below ``–`￿` in code-unit order, while
450
+ * its code point sorts above them. So `matchesConditionExactly`'s range family and
450
451
  * `matchesOrderExactly` exclude `text`, refining through the core engine instead.
451
452
  */
452
453
  export declare const EXACT_COLUMN_STORAGE: readonly ColumnStorage[];
453
454
 
454
455
  /**
455
- * Lists the declared {@link ColumnStorage}s whose SQL RANGE comparisons
456
+ * Lists the declared {@link ColumnStorage}s whose SQL range comparisons
456
457
  * (`above` / `below` / `from` / `to` / `between`) and `ORDER BY` compiles are
457
458
  * provably engine-exact — `integer` / `real` / `boolean` only. `text` is
458
459
  * excluded: see {@link EXACT_COLUMN_STORAGE}'s remarks for the BINARY-collation
@@ -484,7 +485,7 @@ export declare function extractValues(row: SQLiteRow, names: readonly string[],
484
485
 
485
486
  /**
486
487
  * Reads the storage type a nested (`json_extract`) operand encodes as from its
487
- * RUNTIME value NOT `json`.
488
+ * runtime value, never as `json`.
488
489
  *
489
490
  * @remarks
490
491
  * `json_extract` returns the unquoted, natively-typed scalar (a JSON boolean as
@@ -541,17 +542,17 @@ export declare function inferValueStorage(value: unknown): ColumnStorage;
541
542
  * remains an `ABORTED` `DatabaseError` in `context.cause`. The fail-closed read path
542
543
  * ({@link JSONDriver.#document}) remains separate from this write-error contract.
543
544
  */
544
- export declare class JSONDriver implements DriverInterface_2 {
545
+ export declare class JSONDriver implements DriverInterface {
545
546
  #private;
546
547
  constructor(path: string);
547
- open(schema: readonly TableSchema_2[]): Promise<void>;
548
+ open(schema: readonly TableSchema[]): Promise<void>;
548
549
  close(): Promise<void>;
549
- read(table: string, key: Key): Promise<Row_2 | undefined>;
550
- write(table: string, key: Key, row: Row_2, options?: OperationOptions): Promise<void>;
551
- insert(table: string, key: Key, row: Row_2, options?: OperationOptions): Promise<void>;
550
+ read(table: string, key: Key): Promise<Row | undefined>;
551
+ write(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
552
+ insert(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
552
553
  delete(table: string, key: Key, options?: OperationOptions): Promise<boolean>;
553
554
  keys(table: string): Promise<readonly Key[]>;
554
- scan(table: string): AsyncIterable<Row_2>;
555
+ scan(table: string): AsyncIterable<Row>;
555
556
  /**
556
557
  * Iterates rows lazily with native filtering — delegates to the inner {@link MemoryDriver}.
557
558
  *
@@ -563,7 +564,7 @@ export declare class JSONDriver implements DriverInterface_2 {
563
564
  * @param table - The table to stream
564
565
  * @param input - The filter / offset / limit to apply lazily
565
566
  */
566
- stream(table: string, input: QueryInput_2): AsyncIterable<Row_2>;
567
+ stream(table: string, input: QueryInput): AsyncIterable<Row>;
567
568
  clear(table: string): Promise<void>;
568
569
  /**
569
570
  * Runs an isolated native transaction callback over a candidate memory store.
@@ -660,7 +661,7 @@ export declare function matchesAbsentPath(error: unknown): boolean;
660
661
  export declare function matchesAggregateExactly(operation: AggregateOperation, column: FieldPath, schema: TableSchema): boolean;
661
662
 
662
663
  /**
663
- * Reports whether one {@link Condition} compiles to SQL that is PROVABLY
664
+ * Reports whether one {@link Condition} compiles to SQL that is provably
664
665
  * identical to the core engine's `matchesCondition` for every value its
665
666
  * column's declared type can store.
666
667
  *
@@ -674,18 +675,18 @@ export declare function matchesAggregateExactly(operation: AggregateOperation, c
674
675
  * Required non-null `equals` / `not` require an operand matching the declared
675
676
  * storage and exclude `json` / `blob`. `above` / `below` / `from` / `to` /
676
677
  * `between` are exact only for {@link EXACT_RANGE_COLUMN_STORAGE} (`integer` /
677
- * `real` / `boolean`) — a `text` column's range conditions REFINE, because
678
- * SQLite's default BINARY collation orders TEXT by Unicode CODE POINT while
679
- * the core engine's `compareValues` orders JS strings by UTF-16 CODE UNIT,
678
+ * `real` / `boolean`) — a `text` column's range conditions refine, because
679
+ * SQLite's default BINARY collation orders TEXT by Unicode code point while
680
+ * the core engine's `compareValues` orders JS strings by UTF-16 code unit,
680
681
  * and the two diverge for supplementary-plane characters (see
681
682
  * {@link EXACT_COLUMN_STORAGE}'s remarks for the full rationale).
682
- * `any` / `none` require a NON-EMPTY list where every element matches (an empty
683
+ * `any` / `none` require a non-empty list where every element matches (an empty
683
684
  * list is exact under neither: the engine's `any([])` matches nothing while
684
685
  * `none([])` matches everything, and SQL `IN ()` is a syntax error) — these
685
686
  * stay exact on `text` (byte equality is collation-independent and engine-
686
687
  * identical). `starts` / `ends` are exact only on a `text` column with a
687
688
  * string operand (case-sensitive `substr` compile, see {@link compileConditionSQL}) —
688
- * likewise collation-independent. `like` / `glob` are NEVER exact — SQLite
689
+ * likewise collation-independent. `like` / `glob` are never exact — SQLite
689
690
  * `LIKE` folds case ASCII-only against the engine's Unicode fold, and `GLOB`
690
691
  * has character classes the engine treats literally.
691
692
  *
@@ -700,7 +701,7 @@ export declare function matchesConditionExactly(condition: Condition, schema: Ta
700
701
  * — the operand side of the declared-type-trust proof.
701
702
  *
702
703
  * @remarks
703
- * `text` ↔ string, `integer` / `real` ↔ FINITE number (`NaN` / `±Infinity`
704
+ * `text` ↔ string, `integer` / `real` ↔ finite number (`NaN` / `±Infinity`
704
705
  * fail), `boolean` ↔ boolean. Backs {@link matchesConditionExactly}'s operand checks.
705
706
  *
706
707
  * @param value - The condition operand to test
@@ -717,16 +718,19 @@ export declare function matchesDeclaredStorage(value: unknown, storage: ColumnSt
717
718
 
718
719
  /**
719
720
  * Reports whether one {@link Order} term's column compiles to an `ORDER BY`
720
- * that matches the engine's {@link import('@src/core').sortRows} exactly.
721
+ * that matches the engine's {@link import('@orkestrel/database').sortRows} exactly.
721
722
  *
722
723
  * @remarks
723
724
  * `false` for a nested `FieldPath`, a column absent from `schema`, or a
724
725
  * declared type outside {@link EXACT_RANGE_COLUMN_STORAGE} (`integer` / `real` /
725
- * `boolean`). `text` is NOT exact here: SQLite's default BINARY collation
726
+ * `boolean`). `text` is not exact here: SQLite's default BINARY collation
726
727
  * orders TEXT by Unicode code point while the core engine's `compareValues`
727
728
  * orders JS strings by UTF-16 code unit, and the two diverge for
728
729
  * supplementary-plane characters (see {@link EXACT_COLUMN_STORAGE}'s remarks) —
729
- * a `text` order term REFINES through the core engine instead.
730
+ * a `text` order term refines through the core engine instead. The column must
731
+ * also be required and non-null: an optional or nullable column refines, because
732
+ * SQL orders its `NULL`s ahead of every value while the core total order ranks
733
+ * `undefined` before `null` before every other value.
730
734
  *
731
735
  * @param order - The order term to test
732
736
  * @param schema - The table's schema
@@ -739,6 +743,10 @@ export declare function matchesOrderExactly(order: Order, schema: TableSchema):
739
743
  * every order term is exact. `limit` / `offset` never affect exactness (SQL
740
744
  * `LIMIT` / `OFFSET` are always engine-identical).
741
745
  *
746
+ * @remarks
747
+ * The gate {@link import('./drivers/SQLiteDriver.js').SQLiteDriver} checks before
748
+ * trusting a native SQL read over a full-scan refine through the core engine.
749
+ *
742
750
  * @param input - The query input to test
743
751
  * @param schema - The table's schema
744
752
  * @returns True if every part of `input` is exact; false otherwise
@@ -786,6 +794,10 @@ export declare function quoteIdentifier(identifier: string): string;
786
794
  /**
787
795
  * Projects a {@link TableSchema} to its declared SQLite indexes.
788
796
  *
797
+ * @remarks
798
+ * Each statement is a `CREATE INDEX IF NOT EXISTS` named by
799
+ * {@link deriveSQLiteIndexName}, so a reopen re-issues the set safely.
800
+ *
789
801
  * @param schema - The table schema
790
802
  * @returns One statement per declared index
791
803
  */
@@ -847,21 +859,21 @@ export declare function schemaToTable(schema: TableSchema): string;
847
859
  * from a migration-plan fault) passes through `#guard` unchanged, never
848
860
  * re-wrapped.
849
861
  */
850
- export declare class SQLiteDriver implements DriverInterface_2 {
862
+ export declare class SQLiteDriver implements DriverInterface {
851
863
  #private;
852
864
  constructor(options?: SQLiteDriverOptions);
853
- open(schema: readonly TableSchema_2[]): Promise<void>;
865
+ open(schema: readonly TableSchema[]): Promise<void>;
854
866
  close(): Promise<void>;
855
- read(table: string, key: Key): Promise<Row_2 | undefined>;
856
- write(table: string, key: Key, row: Row_2, options?: OperationOptions): Promise<void>;
857
- insert(table: string, key: Key, row: Row_2, options?: OperationOptions): Promise<void>;
867
+ read(table: string, key: Key): Promise<Row | undefined>;
868
+ write(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
869
+ insert(table: string, key: Key, row: Row, options?: OperationOptions): Promise<void>;
858
870
  delete(table: string, key: Key, options?: OperationOptions): Promise<boolean>;
859
871
  keys(table: string): Promise<readonly Key[]>;
860
- scan(table: string): AsyncIterable<Row_2>;
872
+ scan(table: string): AsyncIterable<Row>;
861
873
  clear(table: string): Promise<void>;
862
- records(table: string, input: QueryInput_2): Promise<readonly Row_2[]>;
863
- aggregate(table: string, operation: AggregateOperation_2, column: FieldPath, input: QueryInput_2): Promise<number | undefined>;
864
- stream(table: string, input: QueryInput_2): AsyncIterable<Row_2>;
874
+ records(table: string, input: QueryInput): Promise<readonly Row[]>;
875
+ aggregate(table: string, operation: AggregateOperation, column: FieldPath, input: QueryInput): Promise<number | undefined>;
876
+ stream(table: string, input: QueryInput): AsyncIterable<Row>;
865
877
  /**
866
878
  * Begins a native transaction — real `BEGIN`, `COMMIT`, `ROLLBACK`.
867
879
  *
@@ -918,7 +930,8 @@ export declare class SQLiteDriver implements DriverInterface_2 {
918
930
  }
919
931
 
920
932
  /**
921
- * Options for {@link import('./factories.js').createSQLiteDriver}.
933
+ * Configures {@link import('./factories.js').createSQLiteDriver}. The
934
+ * `@orkestrel/database/server` entry point exports this type.
922
935
  *
923
936
  * @remarks
924
937
  * Threaded into the underlying `@orkestrel/sqlite` wrapper's connection.
@@ -945,6 +958,10 @@ export declare interface SQLiteDriverOptions {
945
958
  /**
946
959
  * Projects one {@link MigrationStep} to SQLite DDL.
947
960
  *
961
+ * @remarks
962
+ * These are the statements the SQLite driver's `migrate` executes for the step,
963
+ * inside whichever native transaction is active.
964
+ *
948
965
  * @param step - The migration step
949
966
  * @returns The statements that apply the step
950
967
  */
@@ -5,22 +5,22 @@ import { dirname } from "node:path";
5
5
  import { createSQLiteDatabase, isSQLiteError } from "@orkestrel/sqlite";
6
6
  //#region src/server/constants.ts
7
7
  /**
8
- * Lists the declared {@link ColumnStorage}s whose SQL EQUALITY comparisons (`equals` /
8
+ * Lists the declared {@link ColumnStorage}s whose SQL equality comparisons (`equals` /
9
9
  * `not` / `any` / `none`) and `starts` / `ends` compiles are provably
10
10
  * engine-exact under declared-type trust — `text` / `integer` / `real` /
11
11
  * `boolean`; a `json` or `blob` column always refines instead.
12
12
  *
13
13
  * @remarks
14
- * This set governs equality and prefix/suffix matching only. RANGE
14
+ * This set governs equality and prefix/suffix matching only. Range
15
15
  * comparisons (`above` / `below` / `from` / `to` / `between`) and `ORDER BY`
16
- * are exact for `integer` / `real` / `boolean` but NOT for `text`: compiled
16
+ * are exact for `integer` / `real` / `boolean` but not for `text`: compiled
17
17
  * SQL orders/ranges under SQLite's default BINARY collation, which compares
18
- * TEXT byte-for-byte as UTF-8 — equivalent to Unicode CODE-POINT order —
18
+ * TEXT byte-for-byte as UTF-8 — equivalent to Unicode code-point order —
19
19
  * while the core engine's `compareValues` orders JS strings with `<`, which
20
- * compares UTF-16 CODE-UNIT order. The two orders diverge for supplementary-
20
+ * compares UTF-16 code-unit order. The two orders diverge for supplementary-
21
21
  * plane characters (code points ≥ U+10000, for example many emoji): a lead surrogate
22
- * (`\uD800`–`\uDBFF`) sorts BELOW ``–`￿` in code-unit order, while
23
- * its code point sorts ABOVE them. So `matchesConditionExactly`'s range family and
22
+ * (`\uD800`–`\uDBFF`) sorts below ``–`￿` in code-unit order, while
23
+ * its code point sorts above them. So `matchesConditionExactly`'s range family and
24
24
  * `matchesOrderExactly` exclude `text`, refining through the core engine instead.
25
25
  */
26
26
  var EXACT_COLUMN_STORAGE = Object.freeze([
@@ -30,7 +30,7 @@ var EXACT_COLUMN_STORAGE = Object.freeze([
30
30
  "boolean"
31
31
  ]);
32
32
  /**
33
- * Lists the declared {@link ColumnStorage}s whose SQL RANGE comparisons
33
+ * Lists the declared {@link ColumnStorage}s whose SQL range comparisons
34
34
  * (`above` / `below` / `from` / `to` / `between`) and `ORDER BY` compiles are
35
35
  * provably engine-exact — `integer` / `real` / `boolean` only. `text` is
36
36
  * excluded: see {@link EXACT_COLUMN_STORAGE}'s remarks for the BINARY-collation
@@ -90,7 +90,7 @@ function matchesAbsentPath(error) {
90
90
  * — the operand side of the declared-type-trust proof.
91
91
  *
92
92
  * @remarks
93
- * `text` ↔ string, `integer` / `real` ↔ FINITE number (`NaN` / `±Infinity`
93
+ * `text` ↔ string, `integer` / `real` ↔ finite number (`NaN` / `±Infinity`
94
94
  * fail), `boolean` ↔ boolean. Backs {@link matchesConditionExactly}'s operand checks.
95
95
  *
96
96
  * @param value - The condition operand to test
@@ -109,7 +109,7 @@ function matchesDeclaredStorage(value, storage) {
109
109
  return isFiniteNumber(value);
110
110
  }
111
111
  /**
112
- * Reports whether one {@link Condition} compiles to SQL that is PROVABLY
112
+ * Reports whether one {@link Condition} compiles to SQL that is provably
113
113
  * identical to the core engine's `matchesCondition` for every value its
114
114
  * column's declared type can store.
115
115
  *
@@ -123,18 +123,18 @@ function matchesDeclaredStorage(value, storage) {
123
123
  * Required non-null `equals` / `not` require an operand matching the declared
124
124
  * storage and exclude `json` / `blob`. `above` / `below` / `from` / `to` /
125
125
  * `between` are exact only for {@link EXACT_RANGE_COLUMN_STORAGE} (`integer` /
126
- * `real` / `boolean`) — a `text` column's range conditions REFINE, because
127
- * SQLite's default BINARY collation orders TEXT by Unicode CODE POINT while
128
- * the core engine's `compareValues` orders JS strings by UTF-16 CODE UNIT,
126
+ * `real` / `boolean`) — a `text` column's range conditions refine, because
127
+ * SQLite's default BINARY collation orders TEXT by Unicode code point while
128
+ * the core engine's `compareValues` orders JS strings by UTF-16 code unit,
129
129
  * and the two diverge for supplementary-plane characters (see
130
130
  * {@link EXACT_COLUMN_STORAGE}'s remarks for the full rationale).
131
- * `any` / `none` require a NON-EMPTY list where every element matches (an empty
131
+ * `any` / `none` require a non-empty list where every element matches (an empty
132
132
  * list is exact under neither: the engine's `any([])` matches nothing while
133
133
  * `none([])` matches everything, and SQL `IN ()` is a syntax error) — these
134
134
  * stay exact on `text` (byte equality is collation-independent and engine-
135
135
  * identical). `starts` / `ends` are exact only on a `text` column with a
136
136
  * string operand (case-sensitive `substr` compile, see {@link compileConditionSQL}) —
137
- * likewise collation-independent. `like` / `glob` are NEVER exact — SQLite
137
+ * likewise collation-independent. `like` / `glob` are never exact — SQLite
138
138
  * `LIKE` folds case ASCII-only against the engine's Unicode fold, and `GLOB`
139
139
  * has character classes the engine treats literally.
140
140
  *
@@ -174,11 +174,14 @@ function matchesConditionExactly(condition, schema) {
174
174
  * @remarks
175
175
  * `false` for a nested `FieldPath`, a column absent from `schema`, or a
176
176
  * declared type outside {@link EXACT_RANGE_COLUMN_STORAGE} (`integer` / `real` /
177
- * `boolean`). `text` is NOT exact here: SQLite's default BINARY collation
177
+ * `boolean`). `text` is not exact here: SQLite's default BINARY collation
178
178
  * orders TEXT by Unicode code point while the core engine's `compareValues`
179
179
  * orders JS strings by UTF-16 code unit, and the two diverge for
180
180
  * supplementary-plane characters (see {@link EXACT_COLUMN_STORAGE}'s remarks) —
181
- * a `text` order term REFINES through the core engine instead.
181
+ * a `text` order term refines through the core engine instead. The column must
182
+ * also be required and non-null: an optional or nullable column refines, because
183
+ * SQL orders its `NULL`s ahead of every value while the core total order ranks
184
+ * `undefined` before `null` before every other value.
182
185
  *
183
186
  * @param order - The order term to test
184
187
  * @param schema - The table's schema
@@ -195,6 +198,10 @@ function matchesOrderExactly(order, schema) {
195
198
  * every order term is exact. `limit` / `offset` never affect exactness (SQL
196
199
  * `LIMIT` / `OFFSET` are always engine-identical).
197
200
  *
201
+ * @remarks
202
+ * The gate {@link import('./drivers/SQLiteDriver.js').SQLiteDriver} checks before
203
+ * trusting a native SQL read over a full-scan refine through the core engine.
204
+ *
198
205
  * @param input - The query input to test
199
206
  * @param schema - The table's schema
200
207
  * @returns True if every part of `input` is exact; false otherwise
@@ -426,7 +433,7 @@ function decodeRow(row, schema) {
426
433
  * so a plan-built index name always matches one `open` would have created.
427
434
  *
428
435
  * @remarks
429
- * A naive `idx_<table>_<cols joined by _>` is AMBIGUOUS: table `'a_b'` with
436
+ * A naive `idx_<table>_<cols joined by _>` is ambiguous: table `'a_b'` with
430
437
  * column `'c'` and table `'a'` with columns `['b', 'c']` both produce
431
438
  * `idx_a_b_c`. This encodes each part (the table name, then each column name)
432
439
  * length-prefixed (`<len>_<part>`) so the boundary between parts is always
@@ -450,7 +457,7 @@ function deriveSQLiteIndexName(table, columns) {
450
457
  //#region src/server/inferers.ts
451
458
  /**
452
459
  * Reads the storage type a nested (`json_extract`) operand encodes as from its
453
- * RUNTIME value NOT `json`.
460
+ * runtime value, never as `json`.
454
461
  *
455
462
  * @remarks
456
463
  * `json_extract` returns the unquoted, natively-typed scalar (a JSON boolean as
@@ -497,6 +504,10 @@ function compileColumnSQL(storage) {
497
504
  /**
498
505
  * Compiles a {@link FieldPath} to the SQL expression that reads it.
499
506
  *
507
+ * @remarks
508
+ * A flat path compiles to the quoted column; a nested path compiles to a
509
+ * `json_extract` over the head column with the rest of the path as its accessor.
510
+ *
500
511
  * @param path - The field path
501
512
  * @returns The SQL expression selecting the value
502
513
  */
@@ -524,9 +535,9 @@ function compileAggregateSQL(operation, column) {
524
535
  }
525
536
  }
526
537
  /**
527
- * Compiles a NESTED {@link FieldPath} to the `json_type(<col>, <path>)` SQL
538
+ * Compiles a nested {@link FieldPath} to the `json_type(<col>, <path>)` SQL
528
539
  * expression — the {@link compileFieldSQL} `json_extract` sibling used to tell a
529
- * PRESENT JSON `null` apart from an ABSENT path (both read back as SQL `NULL`
540
+ * present JSON `null` apart from an absent path (both read back as SQL `NULL`
530
541
  * through `json_extract`, but `json_type` reports `'null'` for the former and
531
542
  * SQL `NULL` for the latter).
532
543
  *
@@ -550,20 +561,20 @@ function compileJSONTypeSQL(path) {
550
561
  *
551
562
  * @remarks
552
563
  * Every operand is run through `encodeValue`, so a bound value matches the SQL
553
- * the column side compiles to. A flat column encodes operands with its DECLARED
564
+ * the column side compiles to. A flat column encodes operands with its declared
554
565
  * schema type (a flat `json` column → `JSON.stringify`); a nested `FieldPath`
555
- * encodes each operand as the NATIVE scalar `json_extract` returns, derived from
566
+ * encodes each operand as the native scalar `json_extract` returns, derived from
556
567
  * the operand's runtime type (per-operand, since `between` / `any` / `none` can
557
568
  * mix types). `any` / `none` collapse an empty list to a constant (`0` matches
558
569
  * nothing, `1` matches all) with no parameters.
559
570
  *
560
- * The core engine's total order ranks `undefined` (rank 0) BELOW `null`
561
- * (rank 1) (see `compareValues`), so a MISSING/`NULL` column MATCHES
571
+ * The core engine's total order ranks `undefined` (rank 0) below `null`
572
+ * (rank 1) (see `compareValues`), so a missing/`NULL` column matches
562
573
  * `below` / `to` / a scalar `not` / `none` — the opposite of raw SQL, where a
563
574
  * comparison against `NULL` is `NULL` (excluded). This fragment replicates the
564
575
  * engine exactly. Truth table (`value` = the engine's decoded field read; a
565
- * FLAT column's stored `NULL` decodes to `undefined` per `decodeRow`, so a
566
- * flat `value` is NEVER a present `null` — only a NESTED path can be
576
+ * flat column's stored `NULL` decodes to `undefined` per `decodeRow`, so a
577
+ * flat `value` is never a present `null` — only a nested path can be
567
578
  * present-but-`null`):
568
579
  *
569
580
  * ```text
@@ -589,15 +600,15 @@ function compileJSONTypeSQL(path) {
589
600
  * refines every optional or nullable scalar comparison through the core engine.
590
601
  * This compiler still emits a total SQL fragment for direct consumers.
591
602
  *
592
- * A NESTED path can be present-but-`null` (a stored JSON `null`), which
593
- * `json_extract` reads back as SQL `NULL` — indistinguishable from an ABSENT
603
+ * A nested path can be present-but-`null` (a stored JSON `null`), which
604
+ * `json_extract` reads back as SQL `NULL` — indistinguishable from an absent
594
605
  * path. `json_type(col, path)` disambiguates them (`'null'` for present-null,
595
606
  * SQL `NULL` for absent), so nested `equals` / `not` against a `null` operand
596
607
  * compile through `json_type` instead of `IS NULL` / `IS NOT NULL`.
597
608
  *
598
609
  * Every other MATCH-on-null-or-absent row is expressed uniformly (flat and
599
610
  * nested alike) as `(<column> <op> ? OR <column> IS NULL)` — for a nested
600
- * path, `json_extract` already collapses BOTH absent and present-null to SQL
611
+ * path, `json_extract` already collapses both absent and present-null to SQL
601
612
  * `NULL`, so `IS NULL` catches both in one clause; for a flat column there is
602
613
  * only the absent case to catch.
603
614
  *
@@ -741,7 +752,7 @@ function compileConditionSQL(condition, schema) {
741
752
  * @remarks
742
753
  * The first condition's connector is ignored, per the {@link Condition} types.
743
754
  * Every fragment (see {@link compileConditionSQL}'s truth table) replicates the core
744
- * engine's total order EXACTLY under SQL's three-valued NULL logic, so this
755
+ * engine's total order exactly under SQL's three-valued NULL logic, so this
745
756
  * clause matches `applyQuery` row-for-row over the same table — a native
746
757
  * `records` / `count` read never disagrees with a scan-and-filter fallback.
747
758
  *
@@ -859,7 +870,7 @@ function compilePageSQL(limit, offset) {
859
870
  * `FieldPath` (a `json_extract` read) encodes each operand as the native scalar
860
871
  * the extract returns — derived from the operand's runtime type — so it compares.
861
872
  * Every operator maps per the databases guide's operator table, with
862
- * `starts` / `ends` compiling to a CODE-POINT `substr` slice guarded by
873
+ * `starts` / `ends` compiling to a code-point `substr` slice guarded by
863
874
  * `typeof(<column>) = 'text'` (case-sensitive, matching the engine's
864
875
  * `String.prototype.startsWith` / `endsWith`) and an empty `any` / `none` list
865
876
  * collapsing to a constant. An `undefined` input (or one with no parts)
@@ -902,6 +913,10 @@ function schemaToTable(schema) {
902
913
  /**
903
914
  * Projects a {@link TableSchema} to its declared SQLite indexes.
904
915
  *
916
+ * @remarks
917
+ * Each statement is a `CREATE INDEX IF NOT EXISTS` named by
918
+ * {@link deriveSQLiteIndexName}, so a reopen re-issues the set safely.
919
+ *
905
920
  * @param schema - The table schema
906
921
  * @returns One statement per declared index
907
922
  */
@@ -911,6 +926,10 @@ function schemaToIndexes(schema) {
911
926
  /**
912
927
  * Projects one {@link MigrationStep} to SQLite DDL.
913
928
  *
929
+ * @remarks
930
+ * These are the statements the SQLite driver's `migrate` executes for the step,
931
+ * inside whichever native transaction is active.
932
+ *
914
933
  * @param step - The migration step
915
934
  * @returns The statements that apply the step
916
935
  */
@@ -2297,7 +2316,7 @@ var SQLiteDriver = class {
2297
2316
  //#endregion
2298
2317
  //#region src/server/factories.ts
2299
2318
  /**
2300
- * Creates a persistent JSON-file {@link DriverInterface} for the core database layer.
2319
+ * Creates a persistent JSON-file {@link DriverInterface} for a given path.
2301
2320
  *
2302
2321
  * @remarks
2303
2322
  * Pass it to `createDatabase` from `@orkestrel/database` to run the typed
@@ -2330,7 +2349,8 @@ function createJSONDriver(path) {
2330
2349
  return new JSONDriver(path);
2331
2350
  }
2332
2351
  /**
2333
- * Creates a trusted-mode SQLite {@link DriverInterface} for the core database layer.
2352
+ * Creates a trusted-mode, server-native SQLite {@link DriverInterface} for a database path,
2353
+ * or for `:memory:` when the options bag omits one.
2334
2354
  *
2335
2355
  * @remarks
2336
2356
  * Pass it to `createDatabase` from `@orkestrel/database` to run the typed