@jarenjs/db 0.34.0
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.
- package/ARCHITECTURE.md +397 -0
- package/README.md +218 -0
- package/dist/types/algebra.d.ts +133 -0
- package/dist/types/app.d.ts +49 -0
- package/dist/types/capture.d.ts +85 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/dag-job.d.ts +40 -0
- package/dist/types/ddl.d.ts +170 -0
- package/dist/types/dialect.d.ts +130 -0
- package/dist/types/dialects/sqlite.d.ts +9 -0
- package/dist/types/driver.d.ts +128 -0
- package/dist/types/drivers/bun.d.ts +47 -0
- package/dist/types/drivers/node.d.ts +37 -0
- package/dist/types/drivers/wasm.d.ts +65 -0
- package/dist/types/emit-model.d.ts +44 -0
- package/dist/types/emit.d.ts +72 -0
- package/dist/types/entity.d.ts +23 -0
- package/dist/types/errors.d.ts +165 -0
- package/dist/types/graph.d.ts +28 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/jobs.d.ts +134 -0
- package/dist/types/live.d.ts +62 -0
- package/dist/types/migrate.d.ts +163 -0
- package/dist/types/model.d.ts +36 -0
- package/dist/types/patch-sql.d.ts +37 -0
- package/dist/types/plan.d.ts +119 -0
- package/dist/types/profile.d.ts +80 -0
- package/dist/types/query.d.ts +100 -0
- package/dist/types/residual.d.ts +50 -0
- package/dist/types/store.d.ts +53 -0
- package/dist/types/tracker.d.ts +43 -0
- package/dist/types/typed.d.ts +15 -0
- package/dist/types/types.d.ts +26 -0
- package/dist/types/udf.d.ts +70 -0
- package/dist/types/window.d.ts +52 -0
- package/docs/JOBS-FORMAT.md +218 -0
- package/docs/LIVE-FORMAT.md +348 -0
- package/docs/MIGRATION-FORMAT.md +302 -0
- package/docs/MODEL-FORMAT.md +928 -0
- package/package.json +81 -0
- package/schemas/jaren-migration.draft-07.schema.json +144 -0
- package/schemas/jaren-migration.schema.json +144 -0
- package/schemas/jaren-model.draft-07.schema.json +149 -0
- package/schemas/jaren-model.schema.json +149 -0
- package/src/algebra.js +105 -0
- package/src/app.js +108 -0
- package/src/capture.js +584 -0
- package/src/cli.js +264 -0
- package/src/dag-job.js +86 -0
- package/src/ddl.js +588 -0
- package/src/dialect.js +297 -0
- package/src/dialects/sqlite.js +175 -0
- package/src/driver.js +419 -0
- package/src/drivers/bun.js +101 -0
- package/src/drivers/node.js +93 -0
- package/src/drivers/wasm.js +178 -0
- package/src/emit-model.js +208 -0
- package/src/emit.js +393 -0
- package/src/entity.js +367 -0
- package/src/errors.js +173 -0
- package/src/graph.js +101 -0
- package/src/index.js +64 -0
- package/src/jobs.js +507 -0
- package/src/live.js +899 -0
- package/src/migrate.js +1411 -0
- package/src/model.js +476 -0
- package/src/patch-sql.js +150 -0
- package/src/plan.js +1038 -0
- package/src/profile.js +131 -0
- package/src/query.js +1010 -0
- package/src/residual.js +91 -0
- package/src/store.js +1422 -0
- package/src/tracker.js +776 -0
- package/src/typed.js +19 -0
- package/src/types.js +36 -0
- package/src/udf.js +132 -0
- package/src/window.js +125 -0
- package/types/app.d.ts +36 -0
- package/types/bun.d.ts +9 -0
- package/types/index.d.ts +592 -0
- package/types/node.d.ts +15 -0
- package/types/typed.d.ts +108 -0
- package/types/wasm.d.ts +5 -0
package/src/residual.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Residual compilation: the part of a query that stays in
|
|
4
|
+
* JavaScript is a REAL compiled Jaren query — the same engine, the
|
|
5
|
+
* same semantics — never a reimplementation.
|
|
6
|
+
*
|
|
7
|
+
* Two modes (ARCHITECTURE.md):
|
|
8
|
+
*
|
|
9
|
+
* - `set` — the whole original document compiled once, run over the
|
|
10
|
+
* materialized candidate array. Re-applying pushed conjuncts is
|
|
11
|
+
* idempotent, so SQL-side narrowing never changes the answer.
|
|
12
|
+
* - `row` — only the projection stayed behind: each fetched row runs
|
|
13
|
+
* `{ $for: { it: '$[*]' }, $return: [ <ret> ] }` over the one-row
|
|
14
|
+
* array; the array wrapper packs the item sequence so an
|
|
15
|
+
* array-VALUED item stays unambiguous, and the per-row results
|
|
16
|
+
* concatenate in row order (streamable).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { compileJsonQuery } from '@jarenjs/json/query';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The compile options for a residual: the profile's engine limits plus
|
|
23
|
+
* the store's registered operators (Ring 2 — a registered operator runs
|
|
24
|
+
* in the residual, so the residual compilation must carry its
|
|
25
|
+
* `{ functions, extensions }` or it would fail `JQ0002`/`JQ0010`).
|
|
26
|
+
* Returns `undefined` when neither is present, so a store opened with no
|
|
27
|
+
* profile and no registry compiles byte-identically to before.
|
|
28
|
+
* @param {any} limits
|
|
29
|
+
* @param {{ functions?: any, extensions?: any } | null} [operators]
|
|
30
|
+
* @returns {any}
|
|
31
|
+
*/
|
|
32
|
+
function residualOptions(limits, operators) {
|
|
33
|
+
const functions = operators?.functions;
|
|
34
|
+
const extensions = operators?.extensions;
|
|
35
|
+
if (limits === undefined && functions === undefined && extensions === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
/** @type {any} */
|
|
38
|
+
const options = {};
|
|
39
|
+
if (limits !== undefined) options.limits = limits;
|
|
40
|
+
if (functions !== undefined) options.functions = functions;
|
|
41
|
+
if (extensions !== undefined) options.extensions = extensions;
|
|
42
|
+
return options;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Compile the whole document for set-mode evaluation. A profile's
|
|
47
|
+
* engine limits ride into the compilation so the JavaScript portion is
|
|
48
|
+
* bounded by the engine's own enforcement.
|
|
49
|
+
* @param {any} document
|
|
50
|
+
* @param {any} [limits]
|
|
51
|
+
* @param {{ functions?: any, extensions?: any } | null} [operators] -
|
|
52
|
+
* the store's registered operators, so the residual can evaluate them
|
|
53
|
+
* @returns {(candidates: any[], externals: any) => any}
|
|
54
|
+
*/
|
|
55
|
+
export function compileSetResidual(document, limits, operators) {
|
|
56
|
+
const compiled = compileJsonQuery(document, residualOptions(limits, operators));
|
|
57
|
+
return (candidates, externals) => compiled(candidates, externals);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Compile the per-row projection for row-mode evaluation.
|
|
62
|
+
* @param {any} returnExpression - The document's raw `$return` value
|
|
63
|
+
* @param {any} [limits]
|
|
64
|
+
* @param {{ functions?: any, extensions?: any } | null} [operators]
|
|
65
|
+
* @returns {(row: any, externals: any) => any[]} the row's items
|
|
66
|
+
*/
|
|
67
|
+
export function compileRowResidual(returnExpression, limits, operators) {
|
|
68
|
+
const compiled = compileJsonQuery({
|
|
69
|
+
$for: { it: '$[*]' },
|
|
70
|
+
$return: [returnExpression],
|
|
71
|
+
}, residualOptions(limits, operators));
|
|
72
|
+
return (row, externals) => {
|
|
73
|
+
const packed = compiled([row], externals);
|
|
74
|
+
// one binding → exactly one packed array of that row's items
|
|
75
|
+
return /** @type {any[]} */ (packed);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Map a flat item array onto the engine's result shape: an empty
|
|
81
|
+
* sequence is `undefined`, a singleton is the item, anything longer is
|
|
82
|
+
* the array (probed engine behaviour, pinned by the differential
|
|
83
|
+
* tests).
|
|
84
|
+
* @param {any[]} items
|
|
85
|
+
* @returns {any}
|
|
86
|
+
*/
|
|
87
|
+
export function sequenceResult(items) {
|
|
88
|
+
if (items.length === 0) return undefined;
|
|
89
|
+
if (items.length === 1) return items[0];
|
|
90
|
+
return items;
|
|
91
|
+
}
|