@jarenjs/db 0.49.2 → 0.66.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 (110) hide show
  1. package/ARCHITECTURE.md +420 -71
  2. package/README.md +711 -79
  3. package/docs/HOSTS.md +269 -0
  4. package/docs/JOBS-FORMAT.md +309 -45
  5. package/docs/LIVE-FORMAT.md +156 -19
  6. package/docs/MIGRATION-FORMAT.md +247 -40
  7. package/docs/MODEL-FORMAT.md +968 -86
  8. package/package.json +21 -8
  9. package/schemas/jaren-migration.draft-07.schema.json +73 -0
  10. package/schemas/jaren-migration.schema.json +73 -0
  11. package/schemas/jaren-model.draft-07.schema.json +224 -162
  12. package/schemas/jaren-model.schema.json +224 -162
  13. package/src/algebra.js +227 -9
  14. package/src/backup.js +161 -0
  15. package/src/cancellation.js +48 -0
  16. package/src/capture.js +255 -44
  17. package/src/cli.js +337 -50
  18. package/src/cursor.js +411 -0
  19. package/src/dag-job.js +154 -21
  20. package/src/ddl.js +125 -11
  21. package/src/dialect.js +267 -112
  22. package/src/dialects/expression-read.js +158 -0
  23. package/src/dialects/postgres.js +618 -0
  24. package/src/dialects/rtree-ddl.js +129 -0
  25. package/src/dialects/sqlite.js +245 -12
  26. package/src/document-files.js +311 -0
  27. package/src/document-steps.js +422 -0
  28. package/src/documents.js +335 -0
  29. package/src/driver.js +503 -69
  30. package/src/drivers/bun.js +37 -1
  31. package/src/drivers/indexeddb-snapshot.js +149 -0
  32. package/src/drivers/node-pool.js +11 -0
  33. package/src/drivers/node-worker-endpoint.js +105 -0
  34. package/src/drivers/node-worker.js +204 -0
  35. package/src/drivers/node.js +41 -7
  36. package/src/drivers/postgres.js +331 -0
  37. package/src/drivers/wasm-oo1.js +97 -0
  38. package/src/drivers/wasm-session.js +67 -0
  39. package/src/drivers/wasm.js +18 -83
  40. package/src/drivers/worker-pool.js +183 -0
  41. package/src/drivers/worker-protocol.js +79 -0
  42. package/src/drivers/worker-queue.js +60 -0
  43. package/src/emit-model.js +14 -0
  44. package/src/emit.js +349 -51
  45. package/src/entity.js +102 -59
  46. package/src/errors.js +430 -2
  47. package/src/expression.js +284 -0
  48. package/src/graph.js +64 -8
  49. package/src/index.js +48 -19
  50. package/src/introspect.js +583 -0
  51. package/src/jobs.js +870 -99
  52. package/src/json-bytes.js +58 -0
  53. package/src/live-time.js +12 -3
  54. package/src/live.js +11 -1
  55. package/src/maintenance.js +175 -0
  56. package/src/migrate.js +606 -333
  57. package/src/model.js +241 -8
  58. package/src/plan.js +1238 -160
  59. package/src/pragmas.js +314 -0
  60. package/src/profile.js +151 -3
  61. package/src/query.js +1748 -312
  62. package/src/residual.js +17 -0
  63. package/src/series.js +12 -4
  64. package/src/store.js +1672 -276
  65. package/src/tracker.js +367 -68
  66. package/src/udf.js +88 -7
  67. package/types/index.d.ts +1246 -32
  68. package/types/node-pool.d.ts +28 -0
  69. package/types/node-worker.d.ts +54 -0
  70. package/types/node.d.ts +72 -3
  71. package/types/postgres.d.ts +46 -0
  72. package/types/typed.d.ts +81 -3
  73. package/types/wasm.d.ts +21 -0
  74. package/dist/types/algebra.d.ts +0 -230
  75. package/dist/types/app.d.ts +0 -49
  76. package/dist/types/capture.d.ts +0 -85
  77. package/dist/types/cli.d.ts +0 -2
  78. package/dist/types/dag-job.d.ts +0 -40
  79. package/dist/types/ddl.d.ts +0 -229
  80. package/dist/types/derive.d.ts +0 -250
  81. package/dist/types/dialect.d.ts +0 -154
  82. package/dist/types/dialects/sqlite.d.ts +0 -9
  83. package/dist/types/driver.d.ts +0 -110
  84. package/dist/types/drivers/bun.d.ts +0 -47
  85. package/dist/types/drivers/node.d.ts +0 -37
  86. package/dist/types/drivers/wasm.d.ts +0 -65
  87. package/dist/types/emit-model.d.ts +0 -44
  88. package/dist/types/emit.d.ts +0 -75
  89. package/dist/types/entity.d.ts +0 -23
  90. package/dist/types/errors.d.ts +0 -170
  91. package/dist/types/graph.d.ts +0 -28
  92. package/dist/types/index.d.ts +0 -37
  93. package/dist/types/jobs.d.ts +0 -140
  94. package/dist/types/knn.d.ts +0 -69
  95. package/dist/types/live-time.d.ts +0 -141
  96. package/dist/types/live.d.ts +0 -64
  97. package/dist/types/migrate.d.ts +0 -170
  98. package/dist/types/model.d.ts +0 -36
  99. package/dist/types/patch-sql.d.ts +0 -37
  100. package/dist/types/plan.d.ts +0 -142
  101. package/dist/types/profile.d.ts +0 -80
  102. package/dist/types/query.d.ts +0 -112
  103. package/dist/types/residual.d.ts +0 -64
  104. package/dist/types/series.d.ts +0 -227
  105. package/dist/types/store.d.ts +0 -60
  106. package/dist/types/tracker.d.ts +0 -43
  107. package/dist/types/typed.d.ts +0 -15
  108. package/dist/types/types.d.ts +0 -26
  109. package/dist/types/udf.d.ts +0 -75
  110. package/dist/types/window.d.ts +0 -52
@@ -1,154 +0,0 @@
1
- /**
2
- * @file The dialect seam: the ONLY place SQL text is produced. A
3
- * dialect is data plus a small emitter — a spelling spec (how to quote
4
- * an identifier, reference a parameter, extract a JSON member, open a
5
- * savepoint) composed by {@link createDialect} into the DDL and DML
6
- * statement builders the store consumes. Nothing outside a dialect
7
- * concatenates SQL; that costs one indirection now, and without it a
8
- * second backend is a rewrite.
9
- *
10
- * Deliberately NOT in the dialect, because they are behavioural rather
11
- * than syntactic: whether functions can be registered per connection,
12
- * whether change capture exists and in what form, and whether tables
13
- * can be restructured in place. Those are capabilities on the
14
- * connection.
15
- */
16
- export type JsonPathSegment = {
17
- name: string;
18
- } | {
19
- index: number;
20
- };
21
- /**
22
- * A typed member path into the JSON document column: name segments for
23
- * object members, index segments for array positions. Produced by the
24
- * DDL planner (from analyzed index paths) and the patch translator
25
- * (from pointers discriminated against the live document).
26
- * @typedef {{ name: string } | { index: number }} JsonPathSegment
27
- */
28
- /**
29
- * Compose a dialect from its spelling spec. Every statement the store
30
- * ever runs is built here from the spec's primitives, so a spec with
31
- * different quoting or parameter style produces correspondingly
32
- * different SQL from the same model — the property the test-double
33
- * dialect pins.
34
- * @param {{
35
- * name: string,
36
- * capabilities: Record<string, any>,
37
- * tableSuffix: string,
38
- * docColumnType: string,
39
- * packedVectorType: string,
40
- * quoteIdentifier: (s: string) => string,
41
- * parameterRef: (i: number, name: string) => string,
42
- * stringLiteral: (s: string) => string,
43
- * booleanLiteral: (b: boolean) => string,
44
- * typeFor: (schemaType: string | undefined, hint: string) => string,
45
- * limitClause: (limit: number, offset?: number) => string,
46
- * jsonPathText: (segments: JsonPathSegment[]) => string | null,
47
- * jsonExtract: (columnSql: string, pathText: string) => string,
48
- * derivedExpression?: (memberSql: string, column: { derive: string,
49
- * precision?: number, component?: string, dims?: number }) => string,
50
- * jsonSet: (exprSql: string, pathText: string, valueSql: string) => string,
51
- * jsonRemove: (exprSql: string, pathText: string) => string,
52
- * jsonAppend: (exprSql: string, arrayPathText: string, valueSql: string) => string,
53
- * jsonEncode: (paramSql: string) => string,
54
- * jsonText: (columnSql: string) => string,
55
- * jsonAgg: (exprSql: string) => string,
56
- * jsonTypeOf: (columnSql: string, pathText: string) => string,
57
- * valueTypeOf: (paramSql: string) => string,
58
- * strStartsWith: (valueSql: string, lowerParamSql: string, upperParamSql: string) => string,
59
- * strStartsWithExact: (valueSql: string, patternA: string, patternB: string) => string,
60
- * strEndsWith: (valueSql: string, patternA: string, patternB: string, patternC: string) => string,
61
- * strContains: (valueSql: string, patternSql: string) => string,
62
- * orderNulls: (nullsFirst: boolean) => string,
63
- * timeBucket: (instantSql: string, originSql: string, everyA: string,
64
- * everyB: string, everyC: string) => string,
65
- * groupAggregate: (fn: string, valueSql: string | null) => string,
66
- * rowIdentity: () => string,
67
- * identityIn: (identitySql: string, paramSqls: string[]) => string,
68
- * rtree?: { module: string, columns: readonly string[] },
69
- * explainQuery: (sql: string) => string,
70
- * excludedRef: (columnSql: string) => string,
71
- * tx: { begin: string, beginImmediate: string, commit: string,
72
- * rollback: string,
73
- * savepoint: (n: string) => string, release: (n: string) => string,
74
- * rollbackTo: (n: string) => string },
75
- * pragma: { busyTimeout: (ms: number) => string,
76
- * journalMode: (mode: string) => string,
77
- * foreignKeys: (on: boolean) => string },
78
- * introspect: { version: () => string, compileOptions: () => string,
79
- * tableExists: () => string, columns: (table: string) => string,
80
- * indexes: (table: string) => string,
81
- * indexColumns: (index: string) => string,
82
- * foreignKeysOn: () => string,
83
- * foreignKeyList: (table: string) => string },
84
- * }} spec
85
- * @returns {any} the frozen dialect
86
- */
87
- export declare function createDialect(spec: {
88
- name: string;
89
- capabilities: Record<string, any>;
90
- tableSuffix: string;
91
- docColumnType: string;
92
- packedVectorType: string;
93
- quoteIdentifier: (s: string) => string;
94
- parameterRef: (i: number, name: string) => string;
95
- stringLiteral: (s: string) => string;
96
- booleanLiteral: (b: boolean) => string;
97
- typeFor: (schemaType: string | undefined, hint: string) => string;
98
- limitClause: (limit: number, offset?: number) => string;
99
- jsonPathText: (segments: JsonPathSegment[]) => string | null;
100
- jsonExtract: (columnSql: string, pathText: string) => string;
101
- derivedExpression?: (memberSql: string, column: {
102
- derive: string;
103
- precision?: number;
104
- component?: string;
105
- dims?: number;
106
- }) => string;
107
- jsonSet: (exprSql: string, pathText: string, valueSql: string) => string;
108
- jsonRemove: (exprSql: string, pathText: string) => string;
109
- jsonAppend: (exprSql: string, arrayPathText: string, valueSql: string) => string;
110
- jsonEncode: (paramSql: string) => string;
111
- jsonText: (columnSql: string) => string;
112
- jsonAgg: (exprSql: string) => string;
113
- jsonTypeOf: (columnSql: string, pathText: string) => string;
114
- valueTypeOf: (paramSql: string) => string;
115
- strStartsWith: (valueSql: string, lowerParamSql: string, upperParamSql: string) => string;
116
- strStartsWithExact: (valueSql: string, patternA: string, patternB: string) => string;
117
- strEndsWith: (valueSql: string, patternA: string, patternB: string, patternC: string) => string;
118
- strContains: (valueSql: string, patternSql: string) => string;
119
- orderNulls: (nullsFirst: boolean) => string;
120
- timeBucket: (instantSql: string, originSql: string, everyA: string, everyB: string, everyC: string) => string;
121
- groupAggregate: (fn: string, valueSql: string | null) => string;
122
- rowIdentity: () => string;
123
- identityIn: (identitySql: string, paramSqls: string[]) => string;
124
- rtree?: {
125
- module: string;
126
- columns: readonly string[];
127
- };
128
- explainQuery: (sql: string) => string;
129
- excludedRef: (columnSql: string) => string;
130
- tx: {
131
- begin: string;
132
- beginImmediate: string;
133
- commit: string;
134
- rollback: string;
135
- savepoint: (n: string) => string;
136
- release: (n: string) => string;
137
- rollbackTo: (n: string) => string;
138
- };
139
- pragma: {
140
- busyTimeout: (ms: number) => string;
141
- journalMode: (mode: string) => string;
142
- foreignKeys: (on: boolean) => string;
143
- };
144
- introspect: {
145
- version: () => string;
146
- compileOptions: () => string;
147
- tableExists: () => string;
148
- columns: (table: string) => string;
149
- indexes: (table: string) => string;
150
- indexColumns: (index: string) => string;
151
- foreignKeysOn: () => string;
152
- foreignKeyList: (table: string) => string;
153
- };
154
- }): any;
@@ -1,9 +0,0 @@
1
- /**
2
- * @file The SQLite dialect — the first spelling of the dialect
3
- * contract, not the only conceivable one. Documents are stored JSONB
4
- * in a BLOB column of a STRICT table; indexed paths become virtual
5
- * generated columns over `jsonb_extract`; reads render back to text
6
- * through `json()`. Parameters are positional (`?`) because every
7
- * binding this package ships binds arrays.
8
- */
9
- export declare const sqliteDialect: any;
@@ -1,110 +0,0 @@
1
- /**
2
- * @file The driver seam: the contract every binding satisfies, the
3
- * capability probe that runs once at open, and the sync-capable-async
4
- * helpers the store composes with.
5
- *
6
- * A driver is `{ name, dialect, open(path, options) }`; `open` returns
7
- * a `Connection` or a promise of one. Every connection method may
8
- * return a value or a promise — the store never assumes either, and
9
- * composes through {@link chain}, which does not allocate a promise
10
- * when the driver answered with a value. That is what keeps the public
11
- * asynchronous surface from paying twice while the synchronous fast
12
- * path stays exact.
13
- *
14
- * The runtime builtin behind a binding is imported LAZILY inside
15
- * `open()` via {@link lazyOpen} — never at module scope — because the
16
- * packed-consumer gate imports every export subpath under Node *and*
17
- * Bun, Bun ships no `node:sqlite`, and Node cannot resolve `bun:`
18
- * specifiers. `open()` is where "this driver does not exist here"
19
- * becomes the coded `JD0003` instead of a module-load crash.
20
- *
21
- * `capabilities` is read once at open — from the library's version
22
- * report, its compile options and the binding's declaration — and is
23
- * the single source of truth for feature gating; never a `typeof`
24
- * sniff at a call site. Two slots are deliberately EMPTY on every
25
- * SQLite driver: `statementTimeout` (no interrupt or progress handler
26
- * exists to build one on) and `rowEstimates` (the query plan is prose,
27
- * not numbers). They exist so a driver that has the facts can fill
28
- * them without a contract change; pretending SQLite has them is the
29
- * silent degradation this suite refuses.
30
- */
31
- import { isThenable, chain, toPromise } from '@jarenjs/core/function';
32
- /** The minimum SQLite the store accepts, asserted at open. */
33
- export declare const SQLITE_FLOOR = "3.45.0";
34
- /**
35
- * How long work may wait for an open transaction to settle before it is
36
- * rejected with `JD0012`. Matches the store's default busy timeout: the
37
- * question "has this waited unreasonably long?" has one answer per
38
- * connection whether the contention is another process (SQLite's own
39
- * busy timeout) or another transaction on this one.
40
- */
41
- export declare const DEFAULT_QUEUE_TIMEOUT = 5000;
42
- export { isThenable, chain, toPromise };
43
- /**
44
- * Compare two dotted version strings numerically.
45
- * @param {string} a
46
- * @param {string} b
47
- * @returns {number} negative when a < b, zero when equal
48
- */
49
- export declare function compareVersions(a: string, b: string): number;
50
- /**
51
- * Load a runtime builtin lazily and hand it to the binding's adapter.
52
- * A failed import — the specifier does not exist on this runtime —
53
- * becomes `JD0003` carrying the loader's error as `cause`.
54
- * @param {string} specifier - The builtin module specifier
55
- * @param {string} reason - The `JD0003` reason for this binding
56
- * @param {(mod: any, ...args: any[]) => any} use - The binding's
57
- * module-to-connection adapter (a named export so the suite can
58
- * exercise it with a substitute module on any runtime)
59
- * @param {any[]} args - Extra arguments forwarded to `use`
60
- * @returns {Promise<any>}
61
- */
62
- export declare function lazyOpen(specifier: string, reason: string, use: (mod: any, ...args: any[]) => any, args: any[]): Promise<any>;
63
- /**
64
- * Normalize a raw statement to the contract shape. A binding without a
65
- * native `iterate` gets one composed over `all` — eager, but the same
66
- * rows in the same order.
67
- * @param {{ run: Function, get: Function, all: Function,
68
- * iterate?: Function }} statement
69
- * @returns {{ run: Function, get: Function, all: Function,
70
- * iterate: Function }}
71
- */
72
- export declare function wrapStatement(statement: {
73
- run: Function;
74
- get: Function;
75
- all: Function;
76
- iterate?: Function;
77
- }): {
78
- run: Function;
79
- get: Function;
80
- all: Function;
81
- iterate: Function;
82
- };
83
- /**
84
- * Finish a raw binding into the connection contract: probe the library
85
- * once, assert the version floor, freeze the capability table, and
86
- * attach the savepoint-nested `transaction`.
87
- *
88
- * The raw shape a binding supplies:
89
- * `{ exec(sql), prepare(sql) -> { run, get, all, iterate? }, close(),
90
- * registerFunction?, registerAggregate?, session? }` — every method
91
- * value-or-promise.
92
- *
93
- * @param {any} raw
94
- * @param {{ dialect: any, synchronous?: boolean, queueTimeout?: number,
95
- * declared?: { sessions?: boolean, userFunctions?: boolean,
96
- * deterministicIndexableFunctions?: boolean,
97
- * aggregateFunctions?: boolean } }} options
98
- * @returns {any} a Connection, or a promise of one
99
- */
100
- export declare function openConnection(raw: any, options: {
101
- dialect: any;
102
- synchronous?: boolean;
103
- queueTimeout?: number;
104
- declared?: {
105
- sessions?: boolean;
106
- userFunctions?: boolean;
107
- deterministicIndexableFunctions?: boolean;
108
- aggregateFunctions?: boolean;
109
- };
110
- }): any;
@@ -1,47 +0,0 @@
1
- /**
2
- * @file The Bun binding: `bun:sqlite` behind the driver contract. The
3
- * builtin is imported lazily inside `open()` — never at module scope —
4
- * so this module itself loads under any runtime; on a runtime that
5
- * cannot resolve `bun:` specifiers the open fails with the coded
6
- * `JD0003`.
7
- *
8
- * Probed reality this binding declares rather than papers over:
9
- * `bun:sqlite`'s `Database` exposes no `function`, no `aggregate` and
10
- * no `createSession` — on Bun the UDF hatch does not exist and there
11
- * is no session-based change capture. The capability table says so.
12
- *
13
- * What it DOES expose is a native lazy row iterator, forwarded below.
14
- * Without it the driver's generic fallback composes a cursor over
15
- * `all()`, which materialises every row first — so a query that streams
16
- * on Node would spike memory in a compiled Bun binary, on the same code
17
- * and the same data. A cursor that is not lazy is not a cursor.
18
- */
19
- /**
20
- * Adapt an already-constructed `bun:sqlite` `Database` (or any object
21
- * with its shape) into a probed connection. Exported so the adapter is
22
- * exercisable without the builtin.
23
- * @param {any} db - A Bun `Database`-shaped database
24
- * @param {{ queueTimeout?: number }} [options]
25
- * @returns {any} a Connection, or a promise of one
26
- */
27
- export declare function adaptBunDatabase(db: any, options?: {
28
- queueTimeout?: number;
29
- }): any;
30
- /**
31
- * Construct and adapt the database from a loaded `bun:sqlite` module.
32
- * Exported so the whole open path runs under any runtime with a
33
- * substitute module.
34
- * @param {any} mod - The `bun:sqlite` module (or a substitute)
35
- * @param {string} path
36
- * @param {{ readOnly?: boolean, queueTimeout?: number }} [options]
37
- * @returns {any}
38
- */
39
- export declare function fromBunModule(mod: any, path: string, options?: {
40
- readOnly?: boolean;
41
- queueTimeout?: number;
42
- }): any;
43
- /**
44
- * The Bun driver: `{ name, dialect, open }` over `bun:sqlite`.
45
- * @returns {any}
46
- */
47
- export declare function bunDriver(): any;
@@ -1,37 +0,0 @@
1
- /**
2
- * @file The Node binding: `node:sqlite` behind the driver contract.
3
- * The builtin is imported lazily inside `open()` — never at module
4
- * scope — so this module itself loads under any runtime; on a runtime
5
- * without `node:sqlite` the open fails with the coded `JD0003`.
6
- */
7
- /**
8
- * Adapt an already-constructed `node:sqlite` `DatabaseSync` (or any
9
- * object with its shape) into a probed connection. Exported so the
10
- * adapter is exercisable without the builtin.
11
- * @param {any} db - A `DatabaseSync`-shaped database
12
- * @param {{ queueTimeout?: number }} [options]
13
- * @returns {any} a Connection, or a promise of one
14
- */
15
- export declare function adaptNodeDatabase(db: any, options?: {
16
- queueTimeout?: number;
17
- }): any;
18
- /**
19
- * Construct and adapt the database from a loaded `node:sqlite` module.
20
- * The seam {@link nodeDriver} feeds through `lazyOpen`; exported so the
21
- * whole open path runs under any runtime with a substitute module.
22
- * @param {any} mod - The `node:sqlite` module (or a substitute)
23
- * @param {string} path
24
- * @param {{ timeout?: number, readOnly?: boolean,
25
- * queueTimeout?: number }} [options]
26
- * @returns {any}
27
- */
28
- export declare function fromNodeModule(mod: any, path: string, options?: {
29
- timeout?: number;
30
- readOnly?: boolean;
31
- queueTimeout?: number;
32
- }): any;
33
- /**
34
- * The Node driver: `{ name, dialect, open }` over `node:sqlite`.
35
- * @returns {any}
36
- */
37
- export declare function nodeDriver(): any;
@@ -1,65 +0,0 @@
1
- /**
2
- * @file The wasm binding: an INJECTED handle behind the driver
3
- * contract. This module imports no runtime builtin at all — the host
4
- * (a browser, a worker) supplies the SQLite build, and this driver
5
- * only adapts it. Every handle method may return a value or a promise;
6
- * a main-thread OPFS-backed build is asynchronous and that is exactly
7
- * why the public store surface is.
8
- *
9
- * The injected contract:
10
- *
11
- * handle = {
12
- * open(path, options) -> raw | Promise<raw>,
13
- * synchronous?: boolean, // default false
14
- * declares?: { userFunctions?, deterministicIndexableFunctions?,
15
- * sessions? } // default all false
16
- * }
17
- * raw = { exec(sql), prepare(sql) -> { run, get, all, iterate? },
18
- * close(), registerFunction?, registerAggregate?, session? }
19
- *
20
- * Capability truth still comes from the probe: whatever the handle
21
- * declares is intersected with what the loaded library actually
22
- * compiled in.
23
- */
24
- /**
25
- * Adapt an already-constructed `sqlite3.oo1` database (the official
26
- * SQLite wasm build's object API) into the raw contract. The oo1 API
27
- * is SYNCHRONOUS — wasm SQLite computes in place and the SAH-pool
28
- * OPFS VFS does synchronous I/O inside a dedicated worker — which is
29
- * exactly what keeps journal capture, live queries and the job queue
30
- * working unchanged in a browser.
31
- *
32
- * Statements are REUSED by the store's prepared caches: every
33
- * operation ends in `reset()`, never `finalize()`. oo1 user functions
34
- * receive a context pointer first — stripped here — and register
35
- * variadic (`arity: -1`), matching the engine's fragment shapes.
36
- * @param {any} sqlite3 - the loaded sqlite3 module (for `capi`)
37
- * @param {any} db - an `sqlite3.oo1.DB`-shaped database
38
- * @returns {any} the raw binding for {@link openConnection}
39
- */
40
- export declare function adaptOo1Database(sqlite3: any, db: any): any;
41
- /**
42
- * Build the injected HANDLE from a loaded sqlite3 module — the D6
43
- * recipe: the host loads the wasm build and picks the database class
44
- * (`sqlite3.oo1.DB` for `:memory:`, the SAH-pool util's `OpfsSAHPoolDb`
45
- * for OPFS persistence), and this package only adapts it.
46
- *
47
- * `sessions` is deliberately NOT declared even though the canonical
48
- * wasm build compiles `ENABLE_SESSION`: this adapter does not yet map
49
- * the session C API, so capture runs in the journal mode — stated in
50
- * the capability matrix, adapting it is a roadmap item.
51
- * @param {any} sqlite3 - the loaded sqlite3 module
52
- * @param {{ DbClass?: any }} [handleOptions] - the database class to
53
- * construct (default `sqlite3.oo1.DB`)
54
- * @returns {any} a handle for {@link wasmDriver}
55
- */
56
- export declare function sqlite3Handle(sqlite3: any, handleOptions?: {
57
- DbClass?: any;
58
- }): any;
59
- /**
60
- * The wasm driver over an injected handle.
61
- * @param {any} handle - The host-supplied SQLite handle (see the file
62
- * header for the contract)
63
- * @returns {any}
64
- */
65
- export declare function wasmDriver(handle: any): any;
@@ -1,44 +0,0 @@
1
- /**
2
- * @file Entity types from models (D17): build an EMIT MODEL DOCUMENT
3
- * — the published contract from EMIT-FORMAT.md — that renders entity
4
- * interfaces, input variants and the typed-store metadata from the
5
- * same model document the runtime validates against.
6
- *
7
- * The seam (EMIT-FORMAT §4.1, recorded here as the order demanded):
8
- * the schema compiler is INJECTED (`options.compile` is
9
- * `compileEmitModel` from `@jarenjs/emit`), called with
10
- * `extensions: ['x-entity']` so the vocabulary rides the member nodes
11
- * verbatim; this module then post-processes the MODEL DOCUMENT —
12
- * replacing relation member types with references, flipping
13
- * optionality, adding declarations — and never renders a character of
14
- * TypeScript itself. Emit stays database-free, db stays
15
- * renderer-free, and the injection keeps `@jarenjs/emit` out of db's
16
- * dependency graph (the generator script wires the two).
17
- *
18
- * What the artifact says, deliberately:
19
- * - entity interfaces are CLOSED objects (excess-property checking is
20
- * the point of generated types; the runtime validator stays
21
- * authoritative for what a database accepts);
22
- * - relation members are optional references — present only when a
23
- * graph load included them; `date-time`/`date` strings carry the
24
- * `DateTime` brand so the linq date operators light up;
25
- * - the `<Name>Input` variant makes defaulted and generated members
26
- * optional, drops to-one/to-many relation members (`create`/`add`
27
- * refuse them), and types many-to-many members as key-or-document
28
- * arrays (what `add()` accepts);
29
- * - `EntityMetaMap` carries doc/input/key/relations per entity — the
30
- * generic typed-store surface (`@jarenjs/db/typed`) binds to it.
31
- */
32
- /**
33
- * Build the emit-model document for a model's entities.
34
- * @param {any} model - a jaren-model document with `entities`
35
- * @param {{ compile: (schema: any, options?: any) => any,
36
- * source?: string, reserved?: string[] }} options - `compile` is
37
- * `compileEmitModel` (injected; see the header)
38
- * @returns {any} an EMIT-FORMAT `0.1` model document
39
- */
40
- export declare function entityEmitModel(model: any, options: {
41
- compile: (schema: any, options?: any) => any;
42
- source?: string;
43
- reserved?: string[];
44
- }): any;
@@ -1,75 +0,0 @@
1
- /**
2
- * @file Plan → SQL through a dialect. This is the query layer's shared
3
- * emitter, the same division of labour as `createDialect`'s DDL/DML
4
- * builders: structural SQL composition lives here, every
5
- * dialect-varying spelling (identifiers, parameters, string literals,
6
- * JSON access, `json_type`, `typeof`, string-operator forms, NULLS
7
- * placement, EXPLAIN phrasing) comes from the dialect. Values are
8
- * NEVER interpolated into the text: every literal and every external
9
- * becomes an ordered parameter slot, which is what makes injection
10
- * structurally impossible.
11
- *
12
- * Every emitted predicate is TOTAL (two-valued) by construction — the
13
- * `json_type` guards from the truth table in ARCHITECTURE.md — so
14
- * `NOT`/`AND`/`OR` compose classically and SQL's three-valued NULL
15
- * logic never decides a row.
16
- */
17
- export type ParamSlot = {
18
- external: string;
19
- } | {
20
- literal: unknown;
21
- } | {
22
- derived: {
23
- kind: 'bboxAxis';
24
- external: string;
25
- axis: 'w' | 's' | 'e' | 'n';
26
- };
27
- };
28
- /**
29
- * Emit one plan as SQL plus its ordered parameter slots.
30
- * @param {import('./algebra.js').Plan} plan
31
- * @param {any} dialect
32
- * @param {{ table: string, keyColumn: string, docColumn: string }} physical
33
- * @returns {{ sql: string, slots: ParamSlot[] }}
34
- */
35
- export declare function emitPlan(plan: import('./algebra.js').Plan, dialect: any, physical: {
36
- table: string;
37
- keyColumn: string;
38
- docColumn: string;
39
- }): {
40
- sql: string;
41
- slots: ParamSlot[];
42
- };
43
- /**
44
- * The entity predicate emitters, shared by the entity plan emitter
45
- * and the graph-load builder: given an alias and its document column,
46
- * emit one predicate with the flavor-correct forms.
47
- * @param {any} dialect
48
- * @param {(slot: ParamSlot) => string} param
49
- * @returns {{ emitPred: (aliasSql: string, docSql: string, pred: any) => string }}
50
- */
51
- export declare function createEntityPredicateEmitters(dialect: any, param: (slot: ParamSlot) => string): {
52
- emitPred: (aliasSql: string, docSql: string, pred: any) => string;
53
- };
54
- /**
55
- * Emit an entity plan (`entity-select` or `entity-join`) as SQL plus
56
- * ordered parameter slots. Entity-COLUMN refs compare real typed
57
- * columns with TOTAL forms and no `json_type` guard — a column-mapped
58
- * property has no present-`null` (§9.3), so presence IS `IS NOT
59
- * NULL`; entity-EPOCH refs compare the derived integer column against
60
- * a plan-time epoch translation; entity-DOC refs ride the phase-A
61
- * guarded truth table over the entity's JSONB column. Join emission
62
- * appends BOTH bindings' row identities in binding order, which is
63
- * exactly the engine's nested-loop order — determinism the oracle
64
- * depends on.
65
- * @param {any} plan - from `planEntityQuery`
66
- * @param {any} dialect
67
- * @param {(entity: string) => { table: string }} physicalOf
68
- * @returns {{ sql: string, slots: ParamSlot[] }}
69
- */
70
- export declare function emitEntityPlan(plan: any, dialect: any, physicalOf: (entity: string) => {
71
- table: string;
72
- }): {
73
- sql: string;
74
- slots: ParamSlot[];
75
- };
@@ -1,23 +0,0 @@
1
- /**
2
- * @file Entity sets: create / read by key / update / delete over the
3
- * hybrid mapping. The physical row is the mapped scalar columns, the
4
- * foreign-key columns, and one JSONB `doc` column for everything
5
- * else; a write SPLITS the completed document along the mapping and a
6
- * read MERGES it back. Defaults apply in JavaScript before validation
7
- * — the value the application sees and the value stored are the same
8
- * — and identity follows the declared strategy (caller, uuid, auto).
9
- *
10
- * Epoch date columns are DERIVED: the document keeps the RFC 3339
11
- * string, the column carries `getEpochOf…RFC3339(value)` so range
12
- * predicates are index-friendly; reads take the string from the
13
- * document and skip the derived column.
14
- */
15
- /**
16
- * The write/read machinery for one entity, prepared once.
17
- * @param {any} connection
18
- * @param {any} entity - the normalized entity (model.js)
19
- * @param {any} entityMapping - `explainMapping(...).entities[name]`
20
- * @param {((doc: any) => any) | null} validate
21
- * @returns {any}
22
- */
23
- export declare function entityCore(connection: any, entity: any, entityMapping: any, validate: ((doc: any) => any) | null): any;