litedbmodel 1.2.9 → 2.0.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/dist/DBModel.d.ts.map +1 -1
  3. package/dist/DBModel.js +6 -0
  4. package/dist/DBModel.js.map +1 -1
  5. package/dist/scp/authoring-sql.d.ts +56 -0
  6. package/dist/scp/authoring-sql.d.ts.map +1 -0
  7. package/dist/scp/authoring-sql.js +83 -0
  8. package/dist/scp/authoring-sql.js.map +1 -0
  9. package/dist/scp/authoring.d.ts +155 -0
  10. package/dist/scp/authoring.d.ts.map +1 -0
  11. package/dist/scp/authoring.js +162 -0
  12. package/dist/scp/authoring.js.map +1 -0
  13. package/dist/scp/bridge.d.ts +64 -0
  14. package/dist/scp/bridge.d.ts.map +1 -0
  15. package/dist/scp/bridge.js +329 -0
  16. package/dist/scp/bridge.js.map +1 -0
  17. package/dist/scp/catalog.d.ts +91 -0
  18. package/dist/scp/catalog.d.ts.map +1 -0
  19. package/dist/scp/catalog.js +203 -0
  20. package/dist/scp/catalog.js.map +1 -0
  21. package/dist/scp/codegen.d.ts +131 -0
  22. package/dist/scp/codegen.d.ts.map +1 -0
  23. package/dist/scp/codegen.js +137 -0
  24. package/dist/scp/codegen.js.map +1 -0
  25. package/dist/scp/compile-dialect.d.ts +39 -0
  26. package/dist/scp/compile-dialect.d.ts.map +1 -0
  27. package/dist/scp/compile-dialect.js +62 -0
  28. package/dist/scp/compile-dialect.js.map +1 -0
  29. package/dist/scp/compile-sqlite.d.ts +114 -0
  30. package/dist/scp/compile-sqlite.d.ts.map +1 -0
  31. package/dist/scp/compile-sqlite.js +149 -0
  32. package/dist/scp/compile-sqlite.js.map +1 -0
  33. package/dist/scp/dialect.d.ts +141 -0
  34. package/dist/scp/dialect.d.ts.map +1 -0
  35. package/dist/scp/dialect.js +194 -0
  36. package/dist/scp/dialect.js.map +1 -0
  37. package/dist/scp/errors.d.ts +36 -0
  38. package/dist/scp/errors.d.ts.map +1 -0
  39. package/dist/scp/errors.js +72 -0
  40. package/dist/scp/errors.js.map +1 -0
  41. package/dist/scp/guard.d.ts +47 -0
  42. package/dist/scp/guard.d.ts.map +1 -0
  43. package/dist/scp/guard.js +137 -0
  44. package/dist/scp/guard.js.map +1 -0
  45. package/dist/scp/index.cjs +4744 -0
  46. package/dist/scp/index.d.ts +49 -0
  47. package/dist/scp/index.d.ts.map +1 -0
  48. package/dist/scp/index.js +164 -0
  49. package/dist/scp/index.js.map +1 -0
  50. package/dist/scp/index.mjs +2000 -0
  51. package/dist/scp/ir.d.ts +92 -0
  52. package/dist/scp/ir.d.ts.map +1 -0
  53. package/dist/scp/ir.js +28 -0
  54. package/dist/scp/ir.js.map +1 -0
  55. package/dist/scp/relation.d.ts +136 -0
  56. package/dist/scp/relation.d.ts.map +1 -0
  57. package/dist/scp/relation.js +191 -0
  58. package/dist/scp/relation.js.map +1 -0
  59. package/dist/scp/render.d.ts +40 -0
  60. package/dist/scp/render.d.ts.map +1 -0
  61. package/dist/scp/render.js +170 -0
  62. package/dist/scp/render.js.map +1 -0
  63. package/dist/scp/runtime.d.ts +295 -0
  64. package/dist/scp/runtime.d.ts.map +1 -0
  65. package/dist/scp/runtime.js +665 -0
  66. package/dist/scp/runtime.js.map +1 -0
  67. package/dist/scp/typed-object.d.ts +88 -0
  68. package/dist/scp/typed-object.d.ts.map +1 -0
  69. package/dist/scp/typed-object.js +163 -0
  70. package/dist/scp/typed-object.js.map +1 -0
  71. package/dist/scp/write-plan.d.ts +161 -0
  72. package/dist/scp/write-plan.d.ts.map +1 -0
  73. package/dist/scp/write-plan.js +528 -0
  74. package/dist/scp/write-plan.js.map +1 -0
  75. package/dist/scp/write-runtime.d.ts +80 -0
  76. package/dist/scp/write-runtime.d.ts.map +1 -0
  77. package/dist/scp/write-runtime.js +167 -0
  78. package/dist/scp/write-runtime.js.map +1 -0
  79. package/dist/scp/writes.d.ts +251 -0
  80. package/dist/scp/writes.d.ts.map +1 -0
  81. package/dist/scp/writes.js +176 -0
  82. package/dist/scp/writes.js.map +1 -0
  83. package/docs/proposal/contracts-architecture-feasibility.md +328 -0
  84. package/docs/proposal/contracts-architecture.md +579 -0
  85. package/docs/proposal/litedbmodel-v2-scp-architecture.md +382 -0
  86. package/docs/proposal/sql-dynamic-expansion-spec.md +175 -0
  87. package/package.json +27 -5
  88. package/docs/README_REVIEW.md +0 -23
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/scp/runtime.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;;;AAoPH,sCAeC;AAcD,wCASC;AA0FD,0CAMC;AAUD,sCAmCC;AAYD,sCAmBC;AAqCD,gDAoCC;AA6BD,kEAoCC;AAOD,0DASC;AAUD,wCASC;AAYD,4DAKC;AAyBD,oBAMC;AAGD,gCAkBC;AAsBD,wDAkDC;AA9vBD,2DAS4B;AAE5B,qCAAiD;AACjD,qCAA2C;AAE3C,qCAAsD;AAiwB7C,2FAjwBgB,mBAAU,OAiwBhB;AAhwBnB,yCAA2I;AAC3I,iDAAkE;AAClE,qCAAuC;AACvC,6CAA2F;AAC3F,mDAA6E;AAC7E,qCAAuH;AACvH,uCAAuE;AAEvE,kFAAkF;AAClF,MAAM,UAAU,GAAG,SAAS,CAAC;AAgB7B,iFAAiF;AAEjF;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,CAAQ;IAC7B,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;YAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;QACnG,OAAO,CAAC,CAAC,CAAC,gEAAgE;IAC5E,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AA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E,CAAC,IAAA,6BAAkB,EAAC,EAAE,EAAE,CAAC,EAAE,KAAK,CAAU,CAAC,CAAC;YAC9E,OAAO,EAAE,EAAE,EAAE,OAA2B,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;IAEF,MAAM,GAAG,GAAG,IAAA,gCAAW,EAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,OAA2B,EAAE,EAAE,mBAAmB,CAAC,CAAC;IACvG,OAAO,GAA2C,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,CAAU;IACrC,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE,CAAC;QACN,oFAAoF;QACpF,OAAO,IAAA,uBAAc,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * litedbmodel v2 SCP — typed-object result + hydrate factory + lazy relations (WS4, #24).
3
+ *
4
+ * v2's read result is a plain **typed-object** (spec §4 / §12): its OWN enumerable props are
5
+ * DATA ONLY (the projected columns + any declaratively-selected relations). It is NOT a
6
+ * DBModel instance — `JSON.stringify` / `Object.keys` / spread stay clean (feasibility §9).
7
+ *
8
+ * The v1 method-like UX is recovered via a graphddb-shaped {@link hydrate} factory
9
+ * (`(raw) => HostObject`): host-object construction is a CONSUMER concern that stays in the
10
+ * litedbmodel runtime and NEVER leaks into the portable IR/bundle (per the runtime boundary —
11
+ * the bundle carries the relation op + assembly shape only). `hydrate` is applied AFTER
12
+ * relation resolution and is NOT applied to `null` (a null single-relation), matching
13
+ * graphddb's `options.hydrate`.
14
+ *
15
+ * ## Lazy relations: prototype getter + non-enumerable Symbol batch context
16
+ *
17
+ * A typed-object gets a per-result-set prototype carrying a lazy getter per relation
18
+ * (feasibility §9 "prototype で良い"). The getter, on access, reads a NON-ENUMERABLE Symbol
19
+ * batch context (graphddb's `GRAPHDDB_KEY` technique — invisible to spread/JSON) shared by
20
+ * every sibling in the result set, and fires the SAME pre-compiled relation op ONCE over the
21
+ * whole sibling set (batch — so no N+1 even though it can't prefetch). A declaratively-selected
22
+ * relation is attached as an OWN property (`Post[]`/`Author`) and naturally SHADOWS the
23
+ * prototype getter (own prop wins) — the exact "宣言済み → データ / 未宣言 → lazy" unification
24
+ * from feasibility §9.
25
+ *
26
+ * Both surfaces resolve through {@link import('./relation').runRelationOp} — the identical
27
+ * compiled op — so there is one relation-execution code path, not two.
28
+ */
29
+ import { type RelationOp, type RelationDriver } from './relation';
30
+ /** The non-enumerable Symbol under which the shared lazy batch context is stashed. */
31
+ export declare const RELATION_CONTEXT: unique symbol;
32
+ /** A hydrate factory (graphddb-shaped): raw typed-object → host object. */
33
+ export type HydrateFactory<R> = (raw: Record<string, unknown>) => R;
34
+ /**
35
+ * The shared lazy batch context for one result set. Holds the sibling rows, the driver, the
36
+ * compiled relation ops (keyed by name), the (optional) hydrate factory, and a per-relation
37
+ * memo so a relation is batched at most ONCE across all siblings (structural no-N+1 for lazy).
38
+ * Stored as a non-enumerable Symbol prop so spread/JSON/`Object.keys` never see it (a spread
39
+ * or clone drops it — "designed degradation", feasibility §9).
40
+ */
41
+ export declare class RelationContext {
42
+ private readonly siblings;
43
+ private readonly ops;
44
+ private readonly db;
45
+ private readonly hydrate?;
46
+ /** Per-relation resolved batch (name → grouping), memoized: one batch query per relation. */
47
+ private readonly resolved;
48
+ constructor(siblings: Record<string, unknown>[], ops: Readonly<Record<string, RelationOp>>, db: RelationDriver, hydrate?: HydrateFactory<unknown>);
49
+ /**
50
+ * Resolve `relationName` for `parent` (lazy access). The relation is batch-loaded across
51
+ * ALL siblings on first access and memoized, so N sibling accesses issue ONE query. Returns
52
+ * the hydrated child(ren) per cardinality (`hasMany` → array, else single-or-null).
53
+ */
54
+ resolve(relationName: string, parent: Record<string, unknown>): unknown;
55
+ }
56
+ /** Read the non-enumerable batch context off a typed-object (undefined if spread/cloned away). */
57
+ export declare function readRelationContext(o: Record<string, unknown>): RelationContext | undefined;
58
+ /**
59
+ * Read options bag (graphddb-shaped): declaratively-select relations to prefetch and/or a
60
+ * `hydrate` factory to recover host objects.
61
+ */
62
+ export interface ReadOptions<R = Record<string, unknown>> {
63
+ /**
64
+ * Declarative select: relation name → `true`. Selected relations are batch-prefetched
65
+ * (staged) and attached as OWN props (shadowing the lazy getter). Unselected relations stay
66
+ * lazy on the prototype.
67
+ */
68
+ readonly with?: Readonly<Record<string, true>>;
69
+ /** Host-object factory applied AFTER relation resolution (not applied to `null`). */
70
+ readonly hydrate?: HydrateFactory<R>;
71
+ }
72
+ /**
73
+ * Build the typed-object result set for a page of raw child rows plus the relation ops
74
+ * declared for this model. Every raw row becomes a typed-object whose:
75
+ * - OWN enumerable props = the raw data columns (+ any declaratively-selected relation);
76
+ * - PROTOTYPE carries a lazy getter per UNSELECTED relation (fires the same op at access);
77
+ * - non-enumerable {@link RELATION_CONTEXT} Symbol = the shared lazy batch context.
78
+ *
79
+ * Declaratively-selected relations (`options.with`) are batch-prefetched HERE (one query per
80
+ * relation over the whole page — staged, no N+1) via the SAME {@link runRelationOp}, and
81
+ * attached as own props (so they shadow the prototype getter). `hydrate`, when supplied, is
82
+ * applied to each parent row AND to resolved relations.
83
+ *
84
+ * Returns the typed-objects (hydrated if `options.hydrate` given). This is the litedbmodel
85
+ * runtime concern; the bundle carries only the relation ops + assembly shape (no hydrate).
86
+ */
87
+ export declare function buildResultSet<R = Record<string, unknown>>(rawRows: readonly Record<string, unknown>[], ops: Readonly<Record<string, RelationOp>>, db: RelationDriver, options?: ReadOptions<R>): R[];
88
+ //# sourceMappingURL=typed-object.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,EAAE,OAAO,CAAC;IACtD;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC/C,qFAAqF;IACrF,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxD,OAAO,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC3C,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EACzC,EAAE,EAAE,cAAc,EAClB,OAAO,GAAE,WAAW,CAAC,CAAC,CAAM,GAC3B,CAAC,EAAE,CA6DL"}
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * litedbmodel v2 SCP — typed-object result + hydrate factory + lazy relations (WS4, #24).
4
+ *
5
+ * v2's read result is a plain **typed-object** (spec §4 / §12): its OWN enumerable props are
6
+ * DATA ONLY (the projected columns + any declaratively-selected relations). It is NOT a
7
+ * DBModel instance — `JSON.stringify` / `Object.keys` / spread stay clean (feasibility §9).
8
+ *
9
+ * The v1 method-like UX is recovered via a graphddb-shaped {@link hydrate} factory
10
+ * (`(raw) => HostObject`): host-object construction is a CONSUMER concern that stays in the
11
+ * litedbmodel runtime and NEVER leaks into the portable IR/bundle (per the runtime boundary —
12
+ * the bundle carries the relation op + assembly shape only). `hydrate` is applied AFTER
13
+ * relation resolution and is NOT applied to `null` (a null single-relation), matching
14
+ * graphddb's `options.hydrate`.
15
+ *
16
+ * ## Lazy relations: prototype getter + non-enumerable Symbol batch context
17
+ *
18
+ * A typed-object gets a per-result-set prototype carrying a lazy getter per relation
19
+ * (feasibility §9 "prototype で良い"). The getter, on access, reads a NON-ENUMERABLE Symbol
20
+ * batch context (graphddb's `GRAPHDDB_KEY` technique — invisible to spread/JSON) shared by
21
+ * every sibling in the result set, and fires the SAME pre-compiled relation op ONCE over the
22
+ * whole sibling set (batch — so no N+1 even though it can't prefetch). A declaratively-selected
23
+ * relation is attached as an OWN property (`Post[]`/`Author`) and naturally SHADOWS the
24
+ * prototype getter (own prop wins) — the exact "宣言済み → データ / 未宣言 → lazy" unification
25
+ * from feasibility §9.
26
+ *
27
+ * Both surfaces resolve through {@link import('./relation').runRelationOp} — the identical
28
+ * compiled op — so there is one relation-execution code path, not two.
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.RelationContext = exports.RELATION_CONTEXT = void 0;
32
+ exports.readRelationContext = readRelationContext;
33
+ exports.buildResultSet = buildResultSet;
34
+ const relation_1 = require("./relation");
35
+ /** The non-enumerable Symbol under which the shared lazy batch context is stashed. */
36
+ exports.RELATION_CONTEXT = Symbol('litedbmodel:relation-context');
37
+ /**
38
+ * The shared lazy batch context for one result set. Holds the sibling rows, the driver, the
39
+ * compiled relation ops (keyed by name), the (optional) hydrate factory, and a per-relation
40
+ * memo so a relation is batched at most ONCE across all siblings (structural no-N+1 for lazy).
41
+ * Stored as a non-enumerable Symbol prop so spread/JSON/`Object.keys` never see it (a spread
42
+ * or clone drops it — "designed degradation", feasibility §9).
43
+ */
44
+ class RelationContext {
45
+ siblings;
46
+ ops;
47
+ db;
48
+ hydrate;
49
+ /** Per-relation resolved batch (name → grouping), memoized: one batch query per relation. */
50
+ resolved = new Map();
51
+ constructor(siblings, ops, db, hydrate) {
52
+ this.siblings = siblings;
53
+ this.ops = ops;
54
+ this.db = db;
55
+ this.hydrate = hydrate;
56
+ }
57
+ /**
58
+ * Resolve `relationName` for `parent` (lazy access). The relation is batch-loaded across
59
+ * ALL siblings on first access and memoized, so N sibling accesses issue ONE query. Returns
60
+ * the hydrated child(ren) per cardinality (`hasMany` → array, else single-or-null).
61
+ */
62
+ resolve(relationName, parent) {
63
+ const op = this.ops[relationName];
64
+ if (op === undefined) {
65
+ throw new Error(`relation '${relationName}' is not declared on this result set`);
66
+ }
67
+ let batch = this.resolved.get(relationName);
68
+ if (batch === undefined) {
69
+ batch = (0, relation_1.runRelationOp)(op, this.siblings, this.db).batch;
70
+ this.resolved.set(relationName, batch);
71
+ }
72
+ return applyHydrate((0, relation_1.distributeToParent)(op, parent, batch), this.hydrate);
73
+ }
74
+ }
75
+ exports.RelationContext = RelationContext;
76
+ /** Read the non-enumerable batch context off a typed-object (undefined if spread/cloned away). */
77
+ function readRelationContext(o) {
78
+ const v = o[exports.RELATION_CONTEXT];
79
+ return v instanceof RelationContext ? v : undefined;
80
+ }
81
+ /** Apply the hydrate factory to a resolved relation value (skip `null`; map arrays). */
82
+ function applyHydrate(value, hydrate) {
83
+ if (hydrate === undefined)
84
+ return value;
85
+ if (value === null)
86
+ return null; // graphddb: hydrate is NOT applied to null
87
+ if (Array.isArray(value))
88
+ return value.map((v) => (v === null ? null : hydrate(v)));
89
+ return hydrate(value);
90
+ }
91
+ /**
92
+ * Build the typed-object result set for a page of raw child rows plus the relation ops
93
+ * declared for this model. Every raw row becomes a typed-object whose:
94
+ * - OWN enumerable props = the raw data columns (+ any declaratively-selected relation);
95
+ * - PROTOTYPE carries a lazy getter per UNSELECTED relation (fires the same op at access);
96
+ * - non-enumerable {@link RELATION_CONTEXT} Symbol = the shared lazy batch context.
97
+ *
98
+ * Declaratively-selected relations (`options.with`) are batch-prefetched HERE (one query per
99
+ * relation over the whole page — staged, no N+1) via the SAME {@link runRelationOp}, and
100
+ * attached as own props (so they shadow the prototype getter). `hydrate`, when supplied, is
101
+ * applied to each parent row AND to resolved relations.
102
+ *
103
+ * Returns the typed-objects (hydrated if `options.hydrate` given). This is the litedbmodel
104
+ * runtime concern; the bundle carries only the relation ops + assembly shape (no hydrate).
105
+ */
106
+ function buildResultSet(rawRows, ops, db, options = {}) {
107
+ const selected = options.with ?? {};
108
+ const hydrate = options.hydrate;
109
+ // The prototype carries a lazy getter for every relation NOT declaratively selected. A
110
+ // selected relation is an own prop, so it shadows the getter (feasibility §9 unification).
111
+ const proto = {};
112
+ for (const name of Object.keys(ops)) {
113
+ if (selected[name] === true)
114
+ continue;
115
+ Object.defineProperty(proto, name, {
116
+ enumerable: false,
117
+ configurable: true,
118
+ get() {
119
+ const ctx = readRelationContext(this);
120
+ if (ctx === undefined) {
121
+ return Promise.reject(new Error(`lazy relation '${name}': the batch context was dropped (spread/clone/JSON); ` +
122
+ `re-read through the query API or declaratively select it via { with: { ${name}: true } }`));
123
+ }
124
+ // v1 parity: `await post.author` yields a Promise (getter → relation-op launch,
125
+ // feasibility §9). The batch itself is synchronous (better-sqlite3) but memoized
126
+ // across siblings, so N accesses still issue ONE query (no N+1).
127
+ return Promise.resolve(ctx.resolve(name, this));
128
+ },
129
+ });
130
+ }
131
+ // The raw typed-objects (own props = data only), sharing `proto`.
132
+ const rows = rawRows.map((raw) => {
133
+ const o = Object.create(proto);
134
+ for (const k of Object.keys(raw))
135
+ o[k] = raw[k];
136
+ return o;
137
+ });
138
+ // The shared lazy batch context (non-enumerable Symbol) — the whole page is the sibling set.
139
+ const ctx = new RelationContext(rows, ops, db, hydrate);
140
+ for (const o of rows) {
141
+ Object.defineProperty(o, exports.RELATION_CONTEXT, {
142
+ value: ctx,
143
+ enumerable: false,
144
+ writable: false,
145
+ configurable: false,
146
+ });
147
+ }
148
+ // Declarative select: batch-prefetch each selected relation ONCE (staged) and attach as an
149
+ // own prop (shadowing the lazy getter). SAME runRelationOp — identical compiled op + SQL.
150
+ for (const name of Object.keys(selected)) {
151
+ const op = ops[name];
152
+ if (op === undefined)
153
+ throw new Error(`declarative select: relation '${name}' is not declared on this model`);
154
+ const { batch } = (0, relation_1.runRelationOp)(op, rows, db);
155
+ for (const o of rows) {
156
+ o[name] = applyHydrate((0, relation_1.distributeToParent)(op, o, batch), hydrate);
157
+ }
158
+ }
159
+ if (hydrate === undefined)
160
+ return rows;
161
+ return rows.map((o) => hydrate(o));
162
+ }
163
+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AC;IACL,CAAC;IAED,2FAA2F;IAC3F,0FAA0F;IAC1F,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,EAAE,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,iCAAiC,CAAC,CAAC;QAC9G,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,wBAAa,EAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,CAAC,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,IAAA,6BAAkB,EAAC,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,IAAsB,CAAC;IACzD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAQ,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * litedbmodel v2 SCP — write-time relations → ordered SQL transaction plan (WS5, #25; spec §6).
3
+ *
4
+ * Derives a declarative {@link LifecycleContract} (the §6 effect arrays) + a base write op
5
+ * (the Command's `Insert`/`Update`/`Delete`, e.g. `Insert(Post, {onWrite: Post.writes.create})`)
6
+ * into ONE ordered, gate-first multi-statement transaction plan — exactly the §6 example:
7
+ *
8
+ * ```
9
+ * BEGIN;
10
+ * -- Gate First (short-circuit + ROLLBACK before any body write)
11
+ * requires: SELECT 1 FROM users WHERE id = :author_id; -- absent ⇒ fail
12
+ * idempotency: INSERT INTO idem(token) VALUES(:request_id); -- duplicate ⇒ short-circuit
13
+ * unique: INSERT INTO uniq(...) ON CONFLICT DO NOTHING; … -- collision ⇒ fail
14
+ * -- Body
15
+ * INSERT INTO posts(author_id,title) VALUES(:author_id,:title) RETURNING id;
16
+ * derive: UPDATE users SET post_count = post_count + 1 WHERE id = :author_id;
17
+ * edges: … (M:N intermediate INSERT/DELETE or 1:N FK UPDATE) …
18
+ * emits: INSERT INTO outbox(type,payload) VALUES('PostCreated', :payload);
19
+ * COMMIT;
20
+ * ```
21
+ *
22
+ * The plan is PURE JSON (each statement is a WS1 {@link CompiledOperation} rendered by the
23
+ * SAME {@link import('./render').renderOperation}), so it serializes into the §8 bundle and a
24
+ * thin per-language runtime honors the SAME ordering + gate-first (no re-derivation, spec §6:
25
+ * "多言語 runtime は同一計画を honor"). `Transaction` は公開仕様にしない — this plan is DERIVED
26
+ * from the Command's declared intent, never authored.
27
+ *
28
+ * ## Gate-first is a real execution behavior, not a text ordering (spec §6 "Gate First")
29
+ *
30
+ * Each gate statement carries a {@link GateRule} the runtime evaluates AFTER executing it: a
31
+ * failing gate short-circuits — the remaining statements (body + derive + edges + emits) never
32
+ * execute and the transaction ROLLBACKs. This is semantically-invariant early termination
33
+ * ({@link import('./write-runtime').executeTransaction} proves it with real query counts + DB state).
34
+ *
35
+ * ## Path lowering (spec §6) — `$.input.*` / `$.entity.*` → closed-set Expression IR
36
+ *
37
+ * A `$.input.<field>` value lowers to `{ref:['<field>']}` (bc flat input scope); a
38
+ * `$.entity.<field>` value lowers to `{ref:['__entity','<field>']}` (the body write's
39
+ * RETURNING row, exposed to the derive/edges/emits stages under {@link ENTITY_ROOT}). Only
40
+ * bc's closed operator set (`ref`) is emitted — no invented opcode (hard rule).
41
+ *
42
+ * ## Transaction derivation (spec §6 / §14) — tx-DAG + gate-first
43
+ *
44
+ * A Command carries one or more named base writes, each with its §6 effects. Statements form a
45
+ * data-dependency DAG (`$.ref.<writeName>.<field>` consumes an earlier write's RETURNING row,
46
+ * exposed via `TxStatement.binds`), with a gate-first constraint (every gate precedes every
47
+ * body/derive/edge/emit). The DAG is topologically ordered (Kahn, stable ascending declaration
48
+ * `seq` tie-break) into a single-transaction statement plan. Underivable shapes (dependency
49
+ * cycle, dangling `$.ref`, referenced write without RETURNING, duplicate bind, composite
50
+ * `$.entity`) are LOUD rejects — never a silently mis-ordered plan.
51
+ */
52
+ import type { CompiledOperation } from './ir';
53
+ import { type Dialect } from './dialect';
54
+ import { type LifecycleContract, type LifecycleEffects, type WriteLifecyclePhase } from './writes';
55
+ /** The role a transaction statement plays (drives the runtime's gate-first interpretation). */
56
+ export type StatementRole = 'gate:requires' | 'gate:idempotency' | 'gate:unique' | 'body' | 'derive' | 'edge' | 'emit';
57
+ /**
58
+ * The gate rule the runtime evaluates on a gate statement's result to decide short-circuit
59
+ * (spec §6 "Gate First"):
60
+ * - `existsElseRollback` — the statement is a `SELECT 1 …` existence probe; ZERO rows ⇒
61
+ * the required row is absent ⇒ short-circuit + ROLLBACK (`requires`).
62
+ * - `insertedElseRollback` — the statement is a guard `INSERT … ON CONFLICT DO NOTHING`;
63
+ * ZERO affected rows ⇒ a collision ⇒ short-circuit + ROLLBACK (`unique`).
64
+ * - `insertedElseNoop` — the statement is an idempotency-token `INSERT … ON CONFLICT DO
65
+ * NOTHING`; ZERO affected rows ⇒ a DUPLICATE request ⇒ short-circuit WITHOUT error
66
+ * (idempotent: the prior write already happened; the tx commits the no-op / rolls back
67
+ * the empty body per {@link TransactionPlan.onIdempotentHit}).
68
+ */
69
+ export type GateRule = 'existsElseRollback' | 'insertedElseRollback' | 'insertedElseNoop';
70
+ /** One ordered statement of a transaction plan (pure JSON — a WS1 compiled op + its role). */
71
+ export interface TxStatement {
72
+ /** Stable statement id (ordering key + diagnostics). */
73
+ readonly id: string;
74
+ /** The statement's role in the §6 derivation order. */
75
+ readonly role: StatementRole;
76
+ /** The compiled SQL op (rendered by the normative {@link import('./render').renderOperation}). */
77
+ readonly op: CompiledOperation;
78
+ /** For a gate statement: the short-circuit rule. Absent for body/derive/edge/emit. */
79
+ readonly gate?: GateRule;
80
+ /**
81
+ * For a composite (multi-write) body statement: the scope binding under which THIS statement's
82
+ * RETURNING row is exposed to LATER statements — a downstream `$.ref.<binds>.<field>` resolves
83
+ * to `scope[<binds>][<field>]` (spec §6 nested write). This is the DAG's data-dependency edge,
84
+ * self-describing so the 5 runtimes just bind the row and continue (no re-derivation). Absent for
85
+ * a statement no later statement depends on; the WS5 single-base write additionally exposes its
86
+ * row under {@link TransactionPlan.entityFrom} / {@link ENTITY_ROOT} for `$.entity.*` back-compat.
87
+ */
88
+ readonly binds?: string;
89
+ /** Human label (diagnostics; e.g. `requires users`, `derive users.post_count`). */
90
+ readonly label: string;
91
+ }
92
+ /** How the runtime resolves an idempotency short-circuit hit (a duplicate request). */
93
+ export type IdempotentHitPolicy = 'rollback';
94
+ /**
95
+ * A derived write-time-relations transaction plan (spec §6 / §8 `transaction plan`). Pure JSON:
96
+ * ordered statements + gate-first rules + the body-write's `entity` exposure. Serializes into
97
+ * the §8 bundle so a WS7 runtime executes the SAME plan.
98
+ */
99
+ export interface TransactionPlan {
100
+ /** The lifecycle phase this plan realizes (`create` / `update` / `remove`). */
101
+ readonly phase: WriteLifecyclePhase;
102
+ /**
103
+ * The statement id whose RETURNING row is exposed to later stages under `$.entity.*`
104
+ * ({@link ENTITY_ROOT}). Always the body write. `null` when the body has no RETURNING
105
+ * (then no later stage may reference `$.entity.*` — validated at derivation time).
106
+ */
107
+ readonly entityFrom: string | null;
108
+ /** The ordered statements (gate-first, then body, then derive/edges/emits). */
109
+ readonly statements: readonly TxStatement[];
110
+ /** What a duplicate-idempotency-token short-circuit does (α: rollback the empty tx). */
111
+ readonly onIdempotentHit: IdempotentHitPolicy;
112
+ }
113
+ /**
114
+ * The base write op the Command declares (`Insert`/`Update`/`Delete` with `onWrite`). This is
115
+ * the Command body statement the plan wraps in a transaction. A Command may declare ONE base
116
+ * write (WS5 single-statement scope) OR several (WS8a composite / nested write, spec §6:
117
+ * "多対多や nested write(親作成と同時に子作成)は edges/追加 write で表現し、同一 tx にまとめる").
118
+ */
119
+ export interface BaseWrite {
120
+ /** The compiled base write op (from the bridge, e.g. `compileNode` of the Insert node). */
121
+ readonly op: CompiledOperation;
122
+ /** The body statement's role (always `body`). */
123
+ readonly label: string;
124
+ /**
125
+ * The write's stable NAME (WS8a composite scope) — later statements reference its RETURNING row
126
+ * as `$.ref.<name>.<field>`, and the derived body statement `binds` this name. Omitted for the
127
+ * WS5 single-base write (its row is addressed as `$.entity.*` under {@link ENTITY_ROOT}).
128
+ */
129
+ readonly name?: string;
130
+ /**
131
+ * The write's OWN save-contract effects (WS8a composite scope): its gates/derive/edges/emits.
132
+ * For the WS5 single-base write, the lifecycle is passed as the top-level `lifecycle` arg and
133
+ * this is omitted. When a base write carries `effects`, the derivation treats it as one DAG
134
+ * node group (its gates → its body → its after-effects), then topologically orders ALL groups.
135
+ */
136
+ readonly effects?: LifecycleEffects;
137
+ }
138
+ /**
139
+ * Derive the ORDERED, gate-first {@link TransactionPlan} from a Command's base write(s) + its
140
+ * lifecycle save contract (spec §6 / §14).
141
+ *
142
+ * ## Single base write (WS5 scope)
143
+ *
144
+ * One base write + a top-level `lifecycle`; the order is the fixed §6 group
145
+ * (requires → idempotency → unique → BODY → derive → edges → emits). `$.entity.*` references in
146
+ * derive/edges/emits require the body write to RETURN the entity row (else a loud build error).
147
+ *
148
+ * ## Composite / nested write (WS8a scope) — real DAG derivation
149
+ *
150
+ * Multiple base writes, each carrying its OWN {@link BaseWrite.effects} and a `name`. A later
151
+ * write references an earlier write's RETURNING row via `$.ref.<name>.<field>` (e.g. a child
152
+ * INSERT keyed by the parent's returned id). The derivation builds the data-dependency graph
153
+ * (statement → the writes it references) + the gate-first constraint, TOPOLOGICALLY orders it
154
+ * (deterministic, stable tie-break), and emits ONE ordered gate-first transaction plan. A cycle
155
+ * or dangling reference is ESCALATED (no silent mis-derivation).
156
+ *
157
+ * @throws if a `$.entity.*` reference lacks a RETURNING body, a `$.ref.*` is dangling, two writes
158
+ * bind the same name, or the dependency graph has a cycle.
159
+ */
160
+ export declare function deriveTransactionPlan(phase: WriteLifecyclePhase, bases: readonly BaseWrite[], lifecycle: LifecycleContract, dialect?: Dialect): TransactionPlan;
161
+ //# sourceMappingURL=write-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-plan.d.ts","sourceRoot":"","sources":["../../src/scp/write-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAY,MAAM,MAAM,CAAC;AAGxD,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAOL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAGrB,KAAK,mBAAmB,EACzB,MAAM,UAAU,CAAC;AAElB,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,kBAAkB,GAClB,aAAa,GACb,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,CAAC;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,QAAQ,GAAG,oBAAoB,GAAG,sBAAsB,GAAG,kBAAkB,CAAC;AAE1F,8FAA8F;AAC9F,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,kGAAkG;IAClG,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,uFAAuF;AACvF,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WA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