@vibeorm/runtime 2.0.0-alpha.1 → 2.0.0-alpha.10

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 (76) hide show
  1. package/dist/adapter.d.ts +132 -6
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/bulk-upsert.d.ts +282 -0
  4. package/dist/bulk-upsert.d.ts.map +1 -0
  5. package/dist/client.d.ts +70 -19
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/codecs.d.ts.map +1 -1
  8. package/dist/computed.d.ts +43 -0
  9. package/dist/computed.d.ts.map +1 -0
  10. package/dist/db-now.d.ts +41 -0
  11. package/dist/db-now.d.ts.map +1 -0
  12. package/dist/diagnostics/index.d.ts +12 -0
  13. package/dist/diagnostics/index.d.ts.map +1 -0
  14. package/dist/diagnostics/insight.d.ts +63 -0
  15. package/dist/diagnostics/insight.d.ts.map +1 -0
  16. package/dist/diagnostics/plan.d.ts +88 -0
  17. package/dist/diagnostics/plan.d.ts.map +1 -0
  18. package/dist/diagnostics/preview.d.ts +43 -0
  19. package/dist/diagnostics/preview.d.ts.map +1 -0
  20. package/dist/diagnostics/types.d.ts +223 -0
  21. package/dist/diagnostics/types.d.ts.map +1 -0
  22. package/dist/diagnostics/workload.d.ts +32 -0
  23. package/dist/diagnostics/workload.d.ts.map +1 -0
  24. package/dist/index.d.ts +33 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +10958 -4325
  27. package/dist/index.js.map +36 -13
  28. package/dist/keyset-iterator.d.ts +73 -0
  29. package/dist/keyset-iterator.d.ts.map +1 -0
  30. package/dist/keyset.d.ts +121 -0
  31. package/dist/keyset.d.ts.map +1 -0
  32. package/dist/model-meta.d.ts +62 -6
  33. package/dist/model-meta.d.ts.map +1 -1
  34. package/dist/nested-writes.d.ts +0 -33
  35. package/dist/nested-writes.d.ts.map +1 -1
  36. package/dist/policy-operation.d.ts +14 -0
  37. package/dist/policy-operation.d.ts.map +1 -0
  38. package/dist/policy.d.ts +17 -0
  39. package/dist/policy.d.ts.map +1 -0
  40. package/dist/query-builder.d.ts +30 -1
  41. package/dist/query-builder.d.ts.map +1 -1
  42. package/dist/relation-key.d.ts +23 -0
  43. package/dist/relation-key.d.ts.map +1 -0
  44. package/dist/relation-loader.d.ts +0 -29
  45. package/dist/relation-loader.d.ts.map +1 -1
  46. package/dist/relation-plan.d.ts +47 -7
  47. package/dist/relation-plan.d.ts.map +1 -1
  48. package/dist/render-cache.d.ts.map +1 -1
  49. package/dist/rls-context.d.ts +14 -0
  50. package/dist/rls-context.d.ts.map +1 -0
  51. package/dist/rls-readiness.d.ts +114 -0
  52. package/dist/rls-readiness.d.ts.map +1 -0
  53. package/dist/scoped.d.ts +104 -0
  54. package/dist/scoped.d.ts.map +1 -0
  55. package/dist/strict-args.d.ts +47 -0
  56. package/dist/strict-args.d.ts.map +1 -0
  57. package/dist/telemetry/collector.d.ts +53 -0
  58. package/dist/telemetry/collector.d.ts.map +1 -0
  59. package/dist/telemetry/config.d.ts +53 -0
  60. package/dist/telemetry/config.d.ts.map +1 -0
  61. package/dist/telemetry/fingerprint.d.ts +38 -0
  62. package/dist/telemetry/fingerprint.d.ts.map +1 -0
  63. package/dist/telemetry/index.d.ts +18 -0
  64. package/dist/telemetry/index.d.ts.map +1 -0
  65. package/dist/telemetry/recorder.d.ts +93 -0
  66. package/dist/telemetry/recorder.d.ts.map +1 -0
  67. package/dist/telemetry/statement.d.ts +53 -0
  68. package/dist/telemetry/statement.d.ts.map +1 -0
  69. package/dist/telemetry/types.d.ts +265 -0
  70. package/dist/telemetry/types.d.ts.map +1 -0
  71. package/dist/validators.d.ts +61 -0
  72. package/dist/validators.d.ts.map +1 -0
  73. package/dist/views.d.ts.map +1 -1
  74. package/dist/write-scope.d.ts +14 -0
  75. package/dist/write-scope.d.ts.map +1 -0
  76. package/package.json +6 -4
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Bounded-memory export: a sequential async iterator over keyset pages.
3
+ *
4
+ * One page is held at a time and the next one is fetched only when the
5
+ * consumer asks for a row the buffer cannot serve. There is no prefetch, no
6
+ * look-ahead and no unbounded accumulation — `pagesFetched()` is the receipt.
7
+ *
8
+ * What this deliberately is NOT:
9
+ * - **not a snapshot.** No transaction is opened, so the traversal is a LIVE
10
+ * view: concurrent inserts, deletes and sort-key updates change what a
11
+ * later page sees. A row that moves behind the position is missed; one
12
+ * that moves ahead of it is seen twice. A consistent export means running
13
+ * the whole iteration inside `$transaction` at an explicit isolation
14
+ * level, paying its connection and deadline cost — never a secretly
15
+ * long-lived transaction.
16
+ * - **not exactly-once.** `checkpoint()` records the last row the consumer
17
+ * came BACK for, so a `break` or an exception leaves the in-flight row
18
+ * uncheckpointed and resuming re-delivers it. At-least-once. The consumer
19
+ * owns acknowledgement and de-duplication; this is not a durable job
20
+ * engine.
21
+ * - **not statement cancellation.** Aborting the signal stops FUTURE page
22
+ * fetches. A page query already in flight keeps running: per EPIC 6 only
23
+ * `adapter-pg` / `adapter-bun` can cancel a running statement, and only
24
+ * inside a transaction carrying a deadline — which this iterator does not
25
+ * open.
26
+ */
27
+ import type { SqlDialect } from "@vibeorm/sql";
28
+ import type { KeysetTimestampPrecision } from "./keyset.ts";
29
+ import type { RuntimeMeta } from "./model-meta.ts";
30
+ /** The one method this iterator needs — a model delegate satisfies it. */
31
+ export type KeysetPageSource = {
32
+ readonly findMany: (args: Record<string, unknown>) => Promise<Record<string, unknown>[]>;
33
+ };
34
+ export type KeysetIterateOptions = {
35
+ readonly source: KeysetPageSource;
36
+ readonly meta: RuntimeMeta;
37
+ readonly dialect: SqlDialect;
38
+ readonly model: string;
39
+ readonly orderBy: unknown;
40
+ /** Bounded and required, 1…{@link KEYSET_MAX_PAGE_SIZE}. There is no unbounded default. */
41
+ readonly pageSize: number;
42
+ readonly where?: Record<string, unknown>;
43
+ readonly select?: Record<string, unknown>;
44
+ readonly omit?: Record<string, unknown>;
45
+ readonly include?: Record<string, unknown>;
46
+ /** Resume from a checkpoint minted by a previous run over the SAME ordering. */
47
+ readonly after?: string;
48
+ /** Consumer cancellation: stops future page fetches; ends iteration cleanly. */
49
+ readonly signal?: AbortSignal;
50
+ readonly timestampPrecision?: KeysetTimestampPrecision;
51
+ };
52
+ export type KeysetIterator = AsyncIterableIterator<Record<string, unknown>> & {
53
+ /** Always present: `break` and an exception both have to be able to release the traversal. */
54
+ readonly return: (value?: unknown) => Promise<IteratorResult<Record<string, unknown>>>;
55
+ readonly throw: (error?: unknown) => Promise<IteratorResult<Record<string, unknown>>>;
56
+ /** Token for the last SUCCESSFULLY CONSUMED row; `null` before the first one settles. */
57
+ readonly checkpoint: () => string | null;
58
+ /** Pages fetched so far — the bounded-fetch receipt. */
59
+ readonly pagesFetched: () => number;
60
+ /** True when the signal aborted the traversal. */
61
+ readonly cancelled: () => boolean;
62
+ };
63
+ /**
64
+ * Iterate a model in keyset order, one bounded page at a time.
65
+ *
66
+ * @example
67
+ * const rows = iterateKeyset({ source: db.$models.product, meta, dialect,
68
+ * model: "Product", orderBy: [{ price: "asc" }, { id: "asc" }], pageSize: 500 });
69
+ * for await (const row of rows) { … }
70
+ * const resumeFrom = rows.checkpoint();
71
+ */
72
+ export declare function iterateKeyset(options: KeysetIterateOptions): KeysetIterator;
73
+ //# sourceMappingURL=keyset-iterator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyset-iterator.d.ts","sourceRoot":"","sources":["../src/keyset-iterator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAS/C,OAAO,KAAK,EAAmB,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EA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AAK,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACtF,yFAAyF;IACzF,QAAQ,CAAC,UAAU,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACzC,wDAAwD;IACxD,QAAQ,CAAC,YAAY,EAAE,MAAM,MAAM,CAAC;IACpC,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC;CACnC,CAAC;AAuCF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,cAAc,CA2I3E"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Sort-aware keyset pagination — the order plan and the opaque position token.
3
+ *
4
+ * A keyset position describes ORDERING VALUES plus a unique tie-breaker, not
5
+ * the identity of one row: the row a token was minted from may since have been
6
+ * deleted or had its sort key changed, and traversal still continues from the
7
+ * right place. That is the whole difference from the legacy `cursor`, which
8
+ * addresses a row by a unique key and is left untouched by this module.
9
+ *
10
+ * Two rules this module exists to enforce:
11
+ * - a position is only meaningful against ONE effective ordering, so the
12
+ * token carries that ordering's signature and a mismatch is refused loudly
13
+ * rather than silently paginating the wrong sequence;
14
+ * - a position's values are encoded LOSSLESSLY per scalar type — never
15
+ * through a float64 detour and never from a rounded display value.
16
+ *
17
+ * The token is ENCODED, not encrypted: anyone holding it can read the ordering
18
+ * values inside. It is also NOT an authorization credential — it selects a
19
+ * position, never a row; every query consuming one still compiles the caller's
20
+ * own `where` and keeps its `$scoped` / `$withPolicy` / RLS filters.
21
+ */
22
+ import type { SqlDialect } from "@vibeorm/sql";
23
+ import type { FieldMeta, ModelMeta } from "./model-meta.ts";
24
+ export type KeysetDirection = "asc" | "desc";
25
+ export type KeysetNulls = "first" | "last";
26
+ /**
27
+ * The caller's assertion that every `DateTime` ordering column holds
28
+ * millisecond-exact values. See {@link compileKeysetOrderPlan}.
29
+ */
30
+ export type KeysetTimestampPrecision = "milliseconds";
31
+ /** One order term, already resolved by the query builder. */
32
+ export type KeysetOrderInput = {
33
+ readonly field: FieldMeta;
34
+ readonly direction: KeysetDirection;
35
+ /** Resolved NULL placement: the explicit request, else the dialect's native one. */
36
+ readonly nulls: KeysetNulls;
37
+ };
38
+ /** One key of the effective keyset order. */
39
+ export type KeysetOrderKey = {
40
+ readonly field: FieldMeta;
41
+ readonly direction: KeysetDirection;
42
+ readonly nulls: KeysetNulls;
43
+ readonly tag: KeysetValueTag;
44
+ };
45
+ /** The effective order a token is bound to. */
46
+ export type KeysetOrderPlan = {
47
+ readonly model: string;
48
+ readonly keys: readonly KeysetOrderKey[];
49
+ /** Plain-text order signature carried inside the token. */
50
+ readonly signature: string;
51
+ };
52
+ /** Per-scalar lossless encoding tag stored in the token. */
53
+ export type KeysetValueTag = "s" | "i" | "b" | "f" | "c" | "t" | "o" | "y";
54
+ /** Token version. A token from another version is refused, never guessed at. */
55
+ export declare const KEYSET_TOKEN_VERSION: number;
56
+ /** Token prefix — `vk` for "vibe keyset", then the version. */
57
+ export declare const KEYSET_TOKEN_PREFIX: string;
58
+ /** Upper bound on an iterator page — memory is bounded by construction, not by hope. */
59
+ export declare const KEYSET_MAX_PAGE_SIZE: number;
60
+ /**
61
+ * Compile and VALIDATE the effective keyset order.
62
+ *
63
+ * Refuses, at build time and before any statement runs: list/Json/Bytes order
64
+ * keys, an order with no unique tie-breaker, and a `DateTime` key on a dialect
65
+ * that may store sub-millisecond values unless the caller passes
66
+ * `timestampPrecision: "milliseconds"` — the caller's explicit assertion that
67
+ * the column is millisecond-exact. That assertion is NOT safe for a
68
+ * `@default(now())` column on postgres, which is microsecond-precise: a
69
+ * truncated cursor value re-admits rows already delivered in that same
70
+ * millisecond, i.e. duplicates.
71
+ */
72
+ export declare function compileKeysetOrderPlan(params: {
73
+ model: ModelMeta;
74
+ dialect: SqlDialect;
75
+ terms: readonly KeysetOrderInput[];
76
+ timestampPrecision?: KeysetTimestampPrecision;
77
+ }): KeysetOrderPlan;
78
+ /**
79
+ * Is `row` strictly after `position` in this ordering? `null` means the
80
+ * comparison is inconclusive in JavaScript (a collated string key), never
81
+ * "yes".
82
+ *
83
+ * Used as a LIVENESS guard, not as a filter: the SQL bound does the real work,
84
+ * and this only catches a traversal that fails to advance — which happens when
85
+ * an ordering is not actually total, or when a cursor value was lossy (a
86
+ * truncated sub-millisecond timestamp being the case this codebase can
87
+ * demonstrate). Without it that situation is an infinite page loop.
88
+ */
89
+ export declare function keysetRowIsAfter(params: {
90
+ keys: readonly KeysetOrderKey[];
91
+ row: readonly unknown[];
92
+ position: readonly unknown[];
93
+ }): boolean | null;
94
+ /** Read a row's ordering values in plan order. */
95
+ export declare function keysetRowValues(params: {
96
+ plan: KeysetOrderPlan;
97
+ row: Readonly<Record<string, unknown>>;
98
+ }): readonly unknown[];
99
+ /**
100
+ * Mint a continuation token from a row that carries every ordering value.
101
+ *
102
+ * The row must contain each ordering field — a missing one is refused rather
103
+ * than encoded as a null, because a silently null position paginates the wrong
104
+ * sequence. Callers that project a subset (`select`) fetch the ordering
105
+ * columns HIDDEN and strip them from the payload; see `keyset-iterator.ts`.
106
+ */
107
+ export declare function encodeKeysetToken(params: {
108
+ plan: KeysetOrderPlan;
109
+ row: Readonly<Record<string, unknown>>;
110
+ }): string;
111
+ /**
112
+ * Read a token back into ordering values, validating version, model and the
113
+ * effective order. A token minted under a different ordering (or for another
114
+ * model, or by a future version) is refused with a precise, non-guessing
115
+ * error — never used to paginate a sequence it does not describe.
116
+ */
117
+ export declare function decodeKeysetToken(params: {
118
+ plan: KeysetOrderPlan;
119
+ token: string;
120
+ }): readonly unknown[];
121
+ //# sourceMappingURL=keyset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyset.d.ts","sourceRoot":"","sources":["../src/keyset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE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MAAe,CAAC;AAuHnD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,wBAAwB,CAAC;CAC/C,GAAG,eAAe,CA+ClB;AA0ID;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,IAAI,EAAE,SAAS,cAAc,EAAE,CAAC;IAChC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACxB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B,GAAG,OAAO,GAAG,IAAI,CAmBjB;AAED,kDAAkD;AAClD,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxC,GAAG,SAAS,OAAO,EAAE,CAGrB;AAID;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxC,GAAG,MAAM,CAcT;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,OAAO,EAAE,CA8EtG"}
@@ -11,8 +11,8 @@
11
11
  * which is dialect-free by design: the id exists before the INSERT, which is
12
12
  * what lets dialects without RETURNING re-select the row they just wrote.
13
13
  */
14
- import type { DefaultValueIR, FieldType, RelationIR, ScalarType, SchemaIR } from "@vibeorm/schema";
15
- import type { SqlExpr } from "@vibeorm/sql";
14
+ import type { ComputedConfig, DefaultValueIR, EnumStorage, FieldType, RelationIR, ScalarType, SchemaIR } from "@vibeorm/schema";
15
+ import type { ScalarCodec, SqlExpr } from "@vibeorm/sql";
16
16
  /** Where a field's default value is produced. */
17
17
  export type DefaultOrigin = "app" | "database" | "none";
18
18
  /** A scalar or enum column, resolved for the runtime. */
@@ -21,11 +21,29 @@ export type FieldMeta = {
21
21
  readonly name: string;
22
22
  /** Database column name (`dbName ?? name`). */
23
23
  readonly columnName: string;
24
+ /** Explicit column collation (@collation, board #36) — mysql insensitive-filter rendering reads it. */
25
+ readonly collation?: string;
26
+ /**
27
+ * The declared `@db.*` native column type, verbatim as Prisma writes it
28
+ * (`Uuid`, `VarChar(191)`, `Char(10)`, `Decimal(10, 2)`), or `undefined`
29
+ * when the field takes the dialect's canonical mapping.
30
+ *
31
+ * Carried because the physical type decides value equality on its own,
32
+ * before any collation: `char(n)` pads, `uuid` folds case, `timestamp(0)`
33
+ * truncates, `real` narrows a Float. `upsertMany`'s duplicate rule reads it
34
+ * (`conflictKeyComparisonOf` in bulk-upsert.ts). It is a schema claim, not a
35
+ * reading of the live column.
36
+ */
37
+ readonly nativeType?: string;
24
38
  readonly type: FieldType;
25
39
  /** The scalar type, or `null` when the field is an enum reference. */
26
40
  readonly scalarType: ScalarType | null;
27
41
  /** The enum name, or `null` when the field is a scalar. */
28
42
  readonly enumName: string | null;
43
+ /** Physical enum storage, or `null` for ordinary scalar fields. */
44
+ readonly enumStorage: EnumStorage | null;
45
+ /** Precomputed membership codec for string-backed enums only. */
46
+ readonly enumCodec: ScalarCodec | null;
29
47
  readonly isList: boolean;
30
48
  readonly isOptional: boolean;
31
49
  readonly isId: boolean;
@@ -39,6 +57,15 @@ export type FieldMeta = {
39
57
  */
40
58
  readonly defaultOrigin: DefaultOrigin;
41
59
  };
60
+ /** One computed field, resolved for the runtime (config-declared, see @vibeorm/schema computed.ts). */
61
+ export type ComputedFieldMeta = {
62
+ readonly name: string;
63
+ /** The declared TypeScript type (informational at runtime; the generator wrote it into the .d.ts). */
64
+ readonly type: string;
65
+ /** Scalar fields the compute reads — fetched with the computed field, stripped unless selected. */
66
+ readonly needs: readonly string[];
67
+ readonly compute: (row: Record<string, unknown>) => unknown;
68
+ };
42
69
  /** A model, resolved for the runtime. */
43
70
  export type ModelMeta = {
44
71
  /** IR model name, e.g. `"User"`. */
@@ -57,15 +84,30 @@ export type ModelMeta = {
57
84
  readonly uniqueFields: readonly FieldMeta[];
58
85
  /**
59
86
  * COMPOSITE ways to address one row, keyed exactly like the generated
60
- * `…WhereUniqueInput` property — member field names joined with `_`
61
- * (`projectId_userId`). The composite `@@id` comes first, then every
62
- * multi-field `@@unique`, in schema order. Empty for models without one.
87
+ * `…WhereUniqueInput` property — the declared client selector name
88
+ * (`@@unique`/`@@id` `name:`) when present, else member field names joined
89
+ * with `_` (`projectId_userId`). The composite `@@id` comes first, then
90
+ * every multi-field `@@unique`, in schema order. Empty for models without
91
+ * one.
92
+ */
93
+ readonly compoundUniques: ReadonlyMap<string, UniqueGroupMeta>;
94
+ /**
95
+ * Single-field unique INDEXES that are addressable but not folded into
96
+ * `field.isUnique` (today: NULLS NOT DISTINCT singles) — mirrors the
97
+ * generator's WhereUniqueInput surface.
63
98
  */
64
- readonly compoundUniques: ReadonlyMap<string, readonly FieldMeta[]>;
99
+ readonly singleIndexUniques: readonly UniqueGroupMeta[];
65
100
  /** Carried verbatim from the IR — consumed by relation loading in P3. */
66
101
  readonly relations: readonly RelationIR[];
67
102
  readonly relationByName: ReadonlyMap<string, RelationIR>;
68
103
  readonly isView: boolean;
104
+ /** Row-scoping policy (@@policy) — the client fails closed on it ($withPolicy). */
105
+ readonly policy?: {
106
+ readonly field: string;
107
+ readonly context: string;
108
+ };
109
+ /** Computed fields configured for this model, or `null` (the common case). */
110
+ readonly computed: ReadonlyMap<string, ComputedFieldMeta> | null;
69
111
  };
70
112
  /**
71
113
  * A pre-bound extension where-operator: compiles one use (`{ similarTo: … }`)
@@ -79,6 +121,19 @@ export type ExtensionOperatorFn = (params: {
79
121
  readonly model: string;
80
122
  readonly field: string;
81
123
  }) => SqlExpr;
124
+ /**
125
+ * One addressable unique group beyond the flat `@id`/`@unique` fields: a
126
+ * composite `@@id`/`@@unique`, or a single-field unique INDEX that does not
127
+ * fold into `field.isUnique` (today: `nullsNotDistinct` uniques). Under
128
+ * NULLS NOT DISTINCT the database keeps at most one row per key INCLUDING
129
+ * null dimensions, so a `null` member addresses exactly one row — those
130
+ * groups accept `null` where members; default (nulls-distinct) groups never
131
+ * do.
132
+ */
133
+ export type UniqueGroupMeta = {
134
+ readonly fields: readonly FieldMeta[];
135
+ readonly nullsNotDistinct: boolean;
136
+ };
82
137
  /** All runtime metadata for one schema. */
83
138
  export type RuntimeMeta = {
84
139
  readonly models: readonly ModelMeta[];
@@ -129,6 +184,7 @@ export declare function generateDefaultValue(params: {
129
184
  /** Resolve a whole schema into the runtime's read-only metadata. */
130
185
  export declare function buildRuntimeMeta(params: {
131
186
  schema: SchemaIR;
187
+ computed?: ComputedConfig;
132
188
  }): RuntimeMeta;
133
189
  /** Look a model up by client name or model name; unknown names are a caller error. */
134
190
  export declare function getModelMeta(params: {
@@ -1 +1 @@
1
- {"version":3,"file":"model-meta.d.ts","sourceRoot":"","sources":["../src/model-meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAW,SAAS,EAAW,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,iDAAiD;AACjD,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC;AAExD,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG;IACtB,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,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AA;CAAE,GAAG,SAAS,CAWpF;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAyBpG"}
@@ -1,36 +1,3 @@
1
- /**
2
- * Nested writes (Prisma-shaped, v1 parity plus implicit-M2M support):
3
- *
4
- * create data: relation: { create | connect | connectOrCreate }
5
- * update data: … plus { update | updateMany | upsert | set | disconnect |
6
- * delete | deleteMany }
7
- *
8
- * STATEMENT ORDER (deterministic, pinned by unit tests):
9
- * create: [owner-side to-one resolutions: SELECT/INSERT per verb] →
10
- * parent INSERT → [list/M2M ops in data-key order, item order;
11
- * each M2M child op is followed immediately by its join-row INSERT].
12
- * PLAIN multi-item FK-side `create` lists collapse into ONE
13
- * multi-row INSERT (v1 parity — one fewer round-trip per item) when
14
- * no item carries nested ops of its own and all items write the
15
- * same columns (so no NULL-vs-database-default drift can appear).
16
- * update: parent pre-SELECT (findUnique) → [owner-side to-one resolutions]
17
- * → parent UPDATE (scalars + FK changes, skipped when empty) →
18
- * [deferred owner-side child DELETEs] → [list/M2M ops in data-key
19
- * order] — the returned row is the UPDATE's result (or the
20
- * pre-SELECT when nothing on the parent changed).
21
- *
22
- * TRANSACTIONS: any nested write that produces more than one statement wraps
23
- * in `adapter.transaction` automatically; inside an outer `$transaction` that
24
- * nests as a savepoint (the adapter contract). A mid-write failure therefore
25
- * rolls the whole write back.
26
- *
27
- * Implicit M2M goes through the ONE shared join-table rule (`implicitJoinTable`
28
- * via relation-plan's link resolution); `connect` writes join rows with
29
- * conflict-skip, so re-connecting an existing pair is a no-op.
30
- *
31
- * Unknown verbs are loud: VIBE_VALIDATION naming the verb (v1 silently
32
- * ignored them — that was a bug class, not a feature).
33
- */
34
1
  import type { SqlDialect, SqlStatement } from "@vibeorm/sql";
35
2
  import type { ModelMeta, RuntimeMeta } from "./model-meta.ts";
36
3
  import type { QueryMethod } from "./query-builder.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"nested-writes.d.ts","sourceRoot":"","sources":["../src/nested-writes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE;QACtB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE;QAC3B,SAAS,EAAE,YAAY,CAAC;QACxB,KAAK,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QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,GAAG,EAAE,eAAe,CAAC;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACrF,CAAC;AAmCF,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAQpF;AA4eD;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,GAAG,EAAE,YAAY,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,OAAO,CAAC,aAAa,CAAC,CAOzB;AA0hBD;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,GAAG,EAAE,YAAY,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,OAAO,CAAC,aAAa,CAAC,CAqCzB"}
@@ -0,0 +1,14 @@
1
+ import type { DynamicClient } from "./client.ts";
2
+ type PolicyOperationFactory = <T>(run: (client: DynamicClient) => Promise<T>) => Promise<T>;
3
+ /** Register the engine-owned deferred-operation factory without exposing it on clients. */
4
+ export declare function registerPolicyOperations(params: {
5
+ client: DynamicClient;
6
+ factory: PolicyOperationFactory;
7
+ }): void;
8
+ /** Defer the whole policy flow; its client is selected by the ordinary array-transaction runner. */
9
+ export declare function deferPolicyOperation<T>(params: {
10
+ client: DynamicClient;
11
+ run: (client: DynamicClient) => Promise<T>;
12
+ }): Promise<T>;
13
+ export {};
14
+ //# sourceMappingURL=policy-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-operation.d.ts","sourceRoot":"","sources":["../src/policy-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,KAAK,sBAAsB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAG5F,2FAA2F;AAC3F,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,sBAAsB,CAAA;CAAE,GAAG,IAAI,CAEjH;AAED,oGAAoG;AACpG,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAIjI"}
@@ -0,0 +1,17 @@
1
+ import type { RuntimeMeta } from "./model-meta.ts";
2
+ import type { DynamicClient, ModelDelegate } from "./client.ts";
3
+ /** Values a policy context may bind — the scoping column's scalar shape. */
4
+ export type PolicyContextValue = string | number | bigint;
5
+ /**
6
+ * Attach `$withPolicy`/`$bypassPolicy` and fail-close the base delegates of
7
+ * policied models. No-op on schemas without @@policy.
8
+ */
9
+ export declare function attachPolicy(params: {
10
+ client: DynamicClient;
11
+ meta: RuntimeMeta;
12
+ wrapDelegate?: (params: {
13
+ model: string;
14
+ delegate: ModelDelegate;
15
+ }) => ModelDelegate;
16
+ }): void;
17
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAA0B,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGxF,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAkrB1D;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC;IAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,aAAa,CAAA;KAAE,KAAK,aAAa,CAAC;CAAE,GAAG,IAAI,CAmK9K"}
@@ -14,10 +14,11 @@
14
14
  * - bad input becomes VIBE_VALIDATION naming the model, field and operator.
15
15
  */
16
16
  import type { OrderByColumn, SqlDialect, SqlExpr, SqlStatement } from "@vibeorm/sql";
17
+ import type { KeysetOrderInput } from "./keyset.ts";
17
18
  import type { ModelMeta, RuntimeMeta } from "./model-meta.ts";
18
19
  import type { RelationSelection, RelationTreeNode } from "./relation-plan.ts";
19
20
  /** Every ORM method the query builder builds SQL for. */
20
- export type QueryMethod = "findMany" | "findFirst" | "findUnique" | "create" | "createMany" | "createManyAndReturn" | "update" | "updateMany" | "upsert" | "delete" | "deleteMany" | "count" | "aggregate" | "groupBy";
21
+ export type QueryMethod = "findMany" | "findFirst" | "findUnique" | "create" | "createMany" | "createManyAndReturn" | "update" | "updateMany" | "updateManyAndReturn" | "upsert" | "upsertMany" | "delete" | "deleteMany" | "count" | "aggregate" | "groupBy";
21
22
  /** Client-level options that shape SQL (subset of ClientOptions the builder needs). */
22
23
  export type BuilderClientOptions = {
23
24
  /** Append the primary key to ORDER BY when no explicit orderBy was given (default false). */
@@ -66,6 +67,13 @@ export type QueryPlan = {
66
67
  * projection — the client narrows back down to this after relation loading.
67
68
  */
68
69
  readonly resultFields: readonly string[] | null;
70
+ /**
71
+ * Computed fields to attach to result rows (config-declared), resolved from
72
+ * select/omit — always a concrete name list, `null` when none apply. Their
73
+ * `needs` ride `selectedFields` like stitch keys and are narrowed away by
74
+ * `resultFields` unless selected themselves.
75
+ */
76
+ readonly computed: readonly string[] | null;
69
77
  /** Relations to load after the base rows, or `null` when none were asked for. */
70
78
  readonly relations: RelationSelection | null;
71
79
  /**
@@ -99,6 +107,15 @@ export type QueryPlan = {
99
107
  * concatenating returned rows. Absent for single-statement calls.
100
108
  */
101
109
  readonly batch?: readonly SqlStatement[];
110
+ /**
111
+ * upsertMany only (EPIC 10): the number of rows this plan submits, summed
112
+ * across chunks. It IS the operation's affected count under the one
113
+ * cross-dialect definition — every submitted row is inserted or updated —
114
+ * and it is computed here because the drivers do not agree: mysql's ON
115
+ * DUPLICATE KEY scores an insert 1, a changed update 2 and an unchanged
116
+ * update 0, so its number is not a row count at all.
117
+ */
118
+ readonly upsertRowCount?: number;
102
119
  /** The caller's `select`, replayed on that re-select. */
103
120
  readonly selectArg: Readonly<Record<string, unknown>> | null;
104
121
  /** How to decode aggregate/groupBy/count-select rows; `null` elsewhere. */
@@ -192,6 +209,17 @@ export declare function upsertUsesNativeStatement(params: {
192
209
  model: ModelMeta;
193
210
  args: Record<string, unknown>;
194
211
  }): boolean;
212
+ /**
213
+ * Compile a raw `orderBy` argument into keyset order inputs — the ONE parsing
214
+ * path the iterator and the `after` bound share, so a token's signature can
215
+ * never drift from the ordering the statement carries.
216
+ */
217
+ export declare function compileKeysetOrderInputs(params: {
218
+ dialect: SqlDialect;
219
+ meta: RuntimeMeta;
220
+ model: ModelMeta;
221
+ orderBy: unknown;
222
+ }): KeysetOrderInput[];
195
223
  /** The column a relation's JSON payload is exposed under in the outer row. */
196
224
  export declare function lateralColumnAlias(params: {
197
225
  relation: string;
@@ -221,6 +249,7 @@ export declare function resolveResultShape(params: {
221
249
  }): {
222
250
  relations: RelationSelection | null;
223
251
  resultFields: readonly string[] | null;
252
+ computed: readonly string[] | null;
224
253
  };
225
254
  /**
226
255
  * Build the SQL plan for one ORM call. Pure: same inputs, same statement —
@@ -1 +1 @@
1
- {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,KAAK,EAMV,aAAa,EAKb,UAAU,EACV,OAAO,EACP,YAAY,EACb,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAa,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAgB,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI5F,yDAAyD;AACzD,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,YAAY,GACZ,qBAAqB,GACrB,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,YAAY,GACZ,OAAO,GACP,WAAW,GACX,SAAS,CAAC;AAEd,uFAAuF;AACvF,MAAM,MAAM,oBAAoB,GAAG;IACjC,6FAA6F;IAC7F,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,yFAAyF;IACzF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CACtC,CAAC;AAIF,iFAAiF;AACjF,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,mFAAmF;AACnF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAA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C;CAC/B,GAAG;IACF,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CACpC,CAkBA;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,uBAAuB,CAAC,EAAE,gBAAgB,CAAC;IAC3C,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC,GAAG,SAAS,CAkwBZ"}
@@ -0,0 +1,23 @@
1
+ /** Compare decoded relation keys by value, including DateTime milliseconds and binary bytes. */
2
+ export declare function relationValueKey(params: {
3
+ value: unknown;
4
+ }): unknown;
5
+ /**
6
+ * A collision-safe Map key for an ORDERED key tuple, or `null` when the tuple
7
+ * is INCOMPLETE (any member null/undefined) — an incomplete foreign key must
8
+ * never attach a parent, so it gets no key at all rather than a key that could
9
+ * collide with another incomplete tuple.
10
+ *
11
+ * The encoding is `JSON.stringify` over the per-member {@link relationValueKey}
12
+ * tags, NOT a separator join: JSON string escaping is injective, so a member
13
+ * containing the separator of a naive `a + "\u0000" + b` scheme (or `","`, or
14
+ * `"|"`) cannot forge another tuple's key.
15
+ *
16
+ * A member whose equality cannot be implemented faithfully — any object that is
17
+ * neither `Date` nor `Uint8Array`, where `String(value)` would be a lossy stand-in
18
+ * — is refused rather than silently mis-grouped.
19
+ */
20
+ export declare function relationTupleKey(params: {
21
+ values: readonly unknown[];
22
+ }): string | null;
23
+ //# sourceMappingURL=relation-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation-key.d.ts","sourceRoot":"","sources":["../src/relation-key.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAqBpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAgBtF"}
@@ -1,32 +1,3 @@
1
- /**
2
- * Relation LOADING: attach included relations onto already-materialized rows.
3
- *
4
- * The portable "query" strategy (default, all dialects): one batched statement
5
- * per relation per level (`WHERE childKey IN (parent keys)`), grouped and
6
- * stitched in memory — never one query per parent. Implicit M2M loads in ONE
7
- * statement per level (board #12, v1's shape): children INNER JOINed to their
8
- * join-table membership rows, the join table's parent-key column projected
9
- * under a reserved alias and decoded through the PARENT key's codec (rule 6).
10
- * Deeper levels recurse over the level's loaded children.
11
- *
12
- * PER-PARENT take/skip MECHANISM (differs from v1's SQL, matches its
13
- * semantics): v1 windowed with `ROW_NUMBER() OVER (PARTITION BY fk)`; v2 loads
14
- * the batch fully ordered (the user's orderBy, or the child PK when paginating
15
- * without one) and applies each parent's skip/take at stitch time. Same
16
- * observable result for any deterministic ordering, no window functions in the
17
- * AST. The trade-off — overfetching children that fall outside a page — is
18
- * accepted for 2.0 and confined to this module.
19
- *
20
- * The "join" strategy's rows arrive with `__rel_<name>` JSON columns (built by
21
- * the query builder's lateral statement); `attachLateralRelations` parses,
22
- * DECODES (codecs on every child row — to_jsonb strings timestamps and drops
23
- * BigInt-ness, LEARNINGS) and stitches them, then recurses deeper levels
24
- * through the query strategy exactly like v1.
25
- *
26
- * Statements run SEQUENTIALLY in relation-declaration order, so the statement
27
- * stream is deterministic (scripted-adapter tests pin it; real adapters get
28
- * predictable logs).
29
- */
30
1
  import type { SelectStatement, SqlDialect, WireFidelity } from "@vibeorm/sql";
31
2
  import type { ModelMeta, RuntimeMeta } from "./model-meta.ts";
32
3
  import type { RelationSelection } from "./relation-plan.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"relation-loader.d.ts","sourceRoot":"","sources":["../src/relation-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAW,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9D,OAAO,KAAK,EAAgB,iBAAiB,EAAoB,MAAM,oBAAoB,CAAC;AAI5F,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE;IACtC,SAAS,EAAE,eAAe,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAqczC;;;GAGG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,4DAA4D;IAC5D,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,GAAG,OAAO,CAAC,IAAI,CAAC,CAShB;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE;IACnD,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,SAAS,EAAE,CAA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