@prisma-next/framework-components 0.7.0 → 0.8.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.
@@ -1,6 +1,236 @@
1
1
  import { o as CodecCallContext } from "./codec-DcjlJbcO.mjs";
2
2
  import { PlanMeta } from "@prisma-next/contract/types";
3
3
 
4
+ //#region src/annotations.d.ts
5
+ /**
6
+ * The kinds of operations an annotation may apply to.
7
+ *
8
+ * - `'read'` — `SELECT` / `find` / `first` / `all` / `count` / aggregates.
9
+ * - `'write'` — `INSERT` / `UPDATE` / `DELETE` / `create` / `update` / `delete` / `upsert`.
10
+ *
11
+ * Annotations declare which kinds they apply to via `defineAnnotation`'s
12
+ * `applicableTo` option; lane terminals enforce the constraint at both the
13
+ * type level (via `ValidAnnotations`) and at runtime (via
14
+ * `assertAnnotationsApplicable`).
15
+ *
16
+ * Finer-grained kinds (`'select' | 'insert' | 'update' | 'delete' | 'upsert'`)
17
+ * are deliberately deferred. The binary covers the common case (the cache
18
+ * middleware applies to reads; an audit annotation would apply to writes;
19
+ * tracing/OTel applies to both). When a real annotation surfaces that needs
20
+ * a finer split, the union widens and existing handles remain typecheckable.
21
+ */
22
+ type OperationKind = 'read' | 'write';
23
+ /**
24
+ * An applied annotation. Carries the namespace, the typed payload, and the
25
+ * `applicableTo` set the underlying handle declared. The `__annotation`
26
+ * brand lets `read` distinguish branded user annotations from arbitrary
27
+ * data that may happen to live under the same namespace key in
28
+ * `plan.meta.annotations` (e.g. framework-internal metadata such as
29
+ * `meta.annotations.codecs`).
30
+ *
31
+ * Constructed by calling an `AnnotationHandle` directly (e.g.
32
+ * `cacheAnnotation({ ttl: 60 })`); never instantiated by hand.
33
+ */
34
+ interface AnnotationValue<Payload, Kinds extends OperationKind> {
35
+ readonly __annotation: true;
36
+ readonly namespace: string;
37
+ readonly value: Payload;
38
+ readonly applicableTo: ReadonlySet<Kinds>;
39
+ }
40
+ /**
41
+ * Handle returned by `defineAnnotation`. The handle is **callable**: the
42
+ * call signature wraps a `Payload` into an `AnnotationValue` ready to
43
+ * pass to a lane terminal's variadic `annotations` argument. The handle
44
+ * also carries static metadata as own properties:
45
+ *
46
+ * - `namespace` — the namespace string the handle was declared with.
47
+ * - `applicableTo` — the frozen `ReadonlySet<Kinds>` consumed by both
48
+ * the type-level `ValidAnnotations` gate and the runtime
49
+ * `assertAnnotationsApplicable` gate.
50
+ * - `read(plan)` — extract the `Payload` from a plan's `meta.annotations`
51
+ * if a value was previously written under this handle's namespace.
52
+ * Returns `undefined` when the annotation is absent or when the stored
53
+ * value is not a branded `AnnotationValue` (e.g. framework-internal
54
+ * metadata under the same namespace key).
55
+ *
56
+ * Handles are the only supported public entry point for reading and
57
+ * writing annotations. Direct mutation of `plan.meta.annotations` is not
58
+ * part of the public API.
59
+ *
60
+ * ```typescript
61
+ * const cacheAnnotation = defineAnnotation<{ ttl: number }>()({
62
+ * namespace: 'cache',
63
+ * applicableTo: ['read'],
64
+ * });
65
+ *
66
+ * // Call the handle to construct a value:
67
+ * const applied = cacheAnnotation({ ttl: 60 });
68
+ *
69
+ * // Read a stored value off a plan:
70
+ * const payload = cacheAnnotation.read(plan);
71
+ * ```
72
+ *
73
+ * Note on the inherited `Function.prototype.apply`: because the handle is
74
+ * a function, the property name `apply` resolves to JavaScript's built-in
75
+ * `Function.prototype.apply` (which lets you invoke a function with an
76
+ * array of arguments). This is **not** the construction entry point — to
77
+ * build an `AnnotationValue`, call the handle directly. The
78
+ * `AnnotationHandle` interface deliberately does not declare an `apply`
79
+ * member of its own.
80
+ */
81
+ interface AnnotationHandle<Payload, Kinds extends OperationKind> {
82
+ (value: Payload): AnnotationValue<Payload, Kinds>;
83
+ readonly namespace: string;
84
+ readonly applicableTo: ReadonlySet<Kinds>;
85
+ read(plan: {
86
+ readonly meta: {
87
+ readonly annotations?: Record<string, unknown>;
88
+ };
89
+ }): Payload | undefined;
90
+ }
91
+ /**
92
+ * Options accepted by `defineAnnotation`.
93
+ *
94
+ * `namespace` is the string key under which the annotation is stored in
95
+ * `plan.meta.annotations`. **Reserved namespaces** include framework-
96
+ * internal metadata keys; user handles must not use them:
97
+ *
98
+ * - `codecs` — used by the SQL emitter to record per-alias codec ids
99
+ * (`meta.annotations.codecs[alias] = 'pg/text@1'`); the SQL runtime's
100
+ * `decodeRow` reads from this key. A user `defineAnnotation('codecs')`
101
+ * handle is not structurally prevented, but its behavior with the
102
+ * emitter and the runtime is undefined and we make no compatibility
103
+ * guarantees about it.
104
+ * - Target-specific keys such as `pg` (and equivalents on other
105
+ * targets) are similarly reserved for adapter / target use.
106
+ *
107
+ * `applicableTo` declares which operation kinds the annotation may attach
108
+ * to. The lane terminals' type-level `ValidAnnotations<K, As>` gate rejects
109
+ * annotations whose `Kinds` does not include the terminal's `K`; the
110
+ * runtime helper `assertAnnotationsApplicable` does the equivalent at
111
+ * runtime so casts and `any` cannot bypass the gate.
112
+ */
113
+ interface DefineAnnotationOptions<Kinds extends OperationKind> {
114
+ readonly namespace: string;
115
+ readonly applicableTo: readonly Kinds[];
116
+ }
117
+ /**
118
+ * Defines a typed annotation handle.
119
+ *
120
+ * Two-step call form. The first step takes the `Payload` type argument
121
+ * (TypeScript cannot infer `Payload` from anything in the options, so it
122
+ * must be supplied explicitly); the second step takes the runtime options
123
+ * and infers `Kinds` from the `applicableTo` array via a `const` type
124
+ * parameter, so the operation kinds appear exactly once at the call site.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Read-only annotation. Lane terminals like `db.User.first(...)` accept
129
+ * // it; `db.User.create(...)` rejects it at the type level.
130
+ * const cacheAnnotation = defineAnnotation<{ ttl?: number; skip?: boolean }>()({
131
+ * namespace: 'cache',
132
+ * applicableTo: ['read'],
133
+ * }); // Kinds inferred as 'read'
134
+ *
135
+ * // Write-only annotation. Mirror image.
136
+ * const auditAnnotation = defineAnnotation<{ actor: string }>()({
137
+ * namespace: 'audit',
138
+ * applicableTo: ['write'],
139
+ * }); // Kinds inferred as 'write'
140
+ *
141
+ * // Annotation applicable to both kinds (e.g. tracing).
142
+ * const otelAnnotation = defineAnnotation<{ traceId: string }>()({
143
+ * namespace: 'otel',
144
+ * applicableTo: ['read', 'write'],
145
+ * }); // Kinds inferred as 'read' | 'write'
146
+ * ```
147
+ *
148
+ * **Reserved namespaces.** See `DefineAnnotationOptions.namespace` for the
149
+ * list of framework-internal namespaces (`codecs`, target-specific keys).
150
+ * `defineAnnotation` does not structurally prevent a user from naming a
151
+ * reserved namespace, but the framework makes no compatibility guarantee
152
+ * about handles that do.
153
+ */
154
+ declare function defineAnnotation<Payload>(): <const Kinds extends OperationKind>(options: DefineAnnotationOptions<Kinds>) => AnnotationHandle<Payload, Kinds>;
155
+ /**
156
+ * Type-level applicability gate consumed by lane terminals.
157
+ *
158
+ * Maps a tuple of `AnnotationValue`s to a tuple where each element either
159
+ * keeps its annotation type (when the annotation's declared `Kinds`
160
+ * includes the terminal's operation kind `K`) or resolves to `never`
161
+ * (when the kinds are incompatible). A `never` element makes the entire
162
+ * tuple unassignable, surfacing the mismatch as a type error at the call
163
+ * site of the terminal.
164
+ *
165
+ * The SQL DSL builders constrain their variadic `...annotations`
166
+ * parameter via `As & ValidAnnotations<K, As>`. **The intersection is
167
+ * load-bearing** — see the note below. The ORM terminals deliberately
168
+ * sidestep this trick by taking one annotation per `meta.annotate(...)`
169
+ * call (no variadic-tuple inference involved), so `ValidAnnotations` is
170
+ * consumed only by the SQL DSL today.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * class SelectQuery<Row> {
175
+ * annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(
176
+ * ...annotations: As & ValidAnnotations<'read', As>
177
+ * ): SelectQuery<Row>;
178
+ * }
179
+ *
180
+ * class InsertQuery<Row> {
181
+ * annotate<As extends readonly AnnotationValue<unknown, OperationKind>[]>(
182
+ * ...annotations: As & ValidAnnotations<'write', As>
183
+ * ): InsertQuery<Row>;
184
+ * }
185
+ *
186
+ * db.users.select('id').annotate(cacheAnnotation({ ttl: 60 }));
187
+ * // ✓ cacheAnnotation declares 'read'; SelectQuery.annotate requires 'read'.
188
+ *
189
+ * db.users.insert({ name: 'Alice' }).annotate(cacheAnnotation({ ttl: 60 }));
190
+ * // ✗ cacheAnnotation declares 'read'; InsertQuery.annotate requires 'write'.
191
+ * // Element resolves to `never` → tuple unassignable → type error.
192
+ * ```
193
+ *
194
+ * **Why `As & ValidAnnotations<K, As>` and not `ValidAnnotations<K, As>`
195
+ * alone.** TypeScript's variadic-tuple inference is too forgiving when
196
+ * the parameter type refers to `As` only through `ValidAnnotations`: it
197
+ * will pick an `As` that makes the call valid even when the gated tuple
198
+ * would contain `never` for an inapplicable element. The intersection
199
+ * pins `As` to the actual call-site tuple AND requires it to be
200
+ * assignable to the gated form. A `never` element in the gated tuple
201
+ * then collapses the corresponding intersection position to `never`,
202
+ * and the inapplicable argument fails to assign — surfacing the mismatch
203
+ * as a type error at the call site.
204
+ *
205
+ * The runtime helper `assertAnnotationsApplicable` covers the equivalent
206
+ * check at runtime so casts and `any` cannot bypass this gate.
207
+ */
208
+ type ValidAnnotations<K extends OperationKind, As extends readonly AnnotationValue<unknown, OperationKind>[]> = { readonly [I in keyof As]: As[I] extends AnnotationValue<infer P, infer Kinds> ? K extends Kinds ? AnnotationValue<P, Kinds> : never : never };
209
+ /**
210
+ * Runtime applicability gate. Throws `RUNTIME.ANNOTATION_INAPPLICABLE` if
211
+ * any annotation in `annotations` declares an `applicableTo` set that does
212
+ * not include `kind`. Used by lane terminals (SQL DSL builders' `.build()`,
213
+ * ORM `Collection` terminals) to fail closed when the type-level
214
+ * `ValidAnnotations` gate is bypassed via cast / `any` / dynamic
215
+ * invocation.
216
+ *
217
+ * Passes silently on:
218
+ * - empty arrays
219
+ * - annotations whose `applicableTo` includes `kind`
220
+ *
221
+ * Throws on:
222
+ * - any annotation whose `applicableTo` does not include `kind`. The
223
+ * error names the offending annotation's `namespace` and the
224
+ * `terminalName` so users can locate the misuse.
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * // Inside an ORM read terminal:
229
+ * assertAnnotationsApplicable(annotations, 'read', 'first');
230
+ * ```
231
+ */
232
+ declare function assertAnnotationsApplicable(annotations: readonly AnnotationValue<unknown, OperationKind>[], kind: OperationKind, terminalName: string): void;
233
+ //#endregion
4
234
  //#region src/execution/async-iterable-result.d.ts
5
235
  declare class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLike<Row[]> {
6
236
  private readonly generator;
@@ -120,6 +350,27 @@ interface RuntimeMiddlewareContext {
120
350
  * cancels.
121
351
  */
122
352
  readonly signal?: AbortSignal;
353
+ /**
354
+ * Identifies the queryable scope this execution is running under.
355
+ *
356
+ * - `'runtime'` — top-level `runtime.execute(plan)`. The default scope
357
+ * used by the standard read/write paths.
358
+ * - `'connection'` — `connection.execute(plan)` after
359
+ * `runtime.connection()` checked out a connection from the pool.
360
+ * - `'transaction'` — `transaction.execute(plan)` inside an explicit
361
+ * transaction, or a query routed through `withTransaction`.
362
+ *
363
+ * Middleware that should only act at the top level read this field to
364
+ * bypass non-runtime scopes. The cache middleware uses it to skip
365
+ * caching inside transactions (where read-after-write coherence is the
366
+ * caller's expectation) and dedicated connections (where the user has
367
+ * explicitly stepped outside the shared cache surface). Observers that
368
+ * don't care about the scope can ignore the field.
369
+ *
370
+ * Family runtimes populate this at context-construction time per
371
+ * scope. Existing middleware that ignore the field are unaffected.
372
+ */
373
+ readonly scope: 'runtime' | 'connection' | 'transaction';
123
374
  }
124
375
  interface AfterExecuteResult {
125
376
  readonly rowCount: number;
@@ -249,6 +500,31 @@ interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan, TMutator extend
249
500
  onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;
250
501
  afterExecute?(plan: TPlan, result: AfterExecuteResult, ctx: RuntimeMiddlewareContext): Promise<void>;
251
502
  }
503
+ /**
504
+ * Cross-family middleware — one that doesn't constrain `familyId` or
505
+ * `targetId` and is therefore compatible with any family runtime's
506
+ * middleware array (`SqlMiddleware[]`, `MongoMiddleware[]`, etc.).
507
+ *
508
+ * The intersection `RuntimeMiddleware & { familyId?: undefined; targetId?: undefined }`
509
+ * pins both optional properties to exactly `undefined` (intersecting
510
+ * `string | undefined` with `undefined` collapses to `undefined`). Under
511
+ * `exactOptionalPropertyTypes: true`, the plain `RuntimeMiddleware` shape
512
+ * — with `familyId?: string` — is *not* assignable to `SqlMiddleware`
513
+ * (which narrows `familyId?: 'sql'`) because `string` is wider than
514
+ * `'sql'`. Pinning the property to `undefined` makes the value a subtype
515
+ * of every narrowed variant: `undefined` extends both `'sql' | undefined`
516
+ * and `'mongo' | undefined`, so a `CrossFamilyMiddleware` value drops
517
+ * into a SQL or Mongo middleware slot without a cast.
518
+ *
519
+ * Cross-family middleware factories (`createCacheMiddleware`, future
520
+ * `audit` / OTel middleware) declare this as their return type so the
521
+ * cross-family typing is named once rather than re-spelled at every call
522
+ * site.
523
+ */
524
+ type CrossFamilyMiddleware<TPlan extends QueryPlan = QueryPlan> = RuntimeMiddleware<TPlan> & {
525
+ readonly familyId?: undefined;
526
+ readonly targetId?: undefined;
527
+ };
252
528
  /**
253
529
  * Optional per-`execute` options accepted by every family runtime.
254
530
  *
@@ -260,6 +536,7 @@ interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan, TMutator extend
260
536
  */
261
537
  interface RuntimeExecuteOptions {
262
538
  readonly signal?: AbortSignal;
539
+ readonly scope?: 'runtime' | 'connection' | 'transaction';
263
540
  }
264
541
  /**
265
542
  * Cross-family SPI for any runtime that can execute plans and be shut down.
@@ -549,5 +826,63 @@ declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends Execut
549
826
  }, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
550
827
  }
551
828
  //#endregion
552
- export { type AfterExecuteResult, AsyncIterableResult, type ExecutionPlan, type InterceptResult, type ParamRefMutator, type QueryPlan, RUNTIME_ABORTED, type ResultType, type RuntimeAbortedPhase, RuntimeCore, type RuntimeCoreOptions, type RuntimeErrorEnvelope, type RuntimeExecuteOptions, type RuntimeExecutor, type RuntimeLog, type RuntimeMiddleware, type RuntimeMiddlewareContext, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeAborted, runtimeError };
829
+ //#region src/meta-builder.d.ts
830
+ /**
831
+ * Per-terminal meta configurator handed to user callbacks. The terminal's
832
+ * operation kind `K` is fixed by the terminal that constructed the builder;
833
+ * `annotate(...)` accepts only annotations whose declared `Kinds` include
834
+ * `K`.
835
+ *
836
+ * The conditional parameter type
837
+ * `K extends Kinds ? AnnotationValue<P, Kinds> : never` collapses to `never`
838
+ * for inapplicable annotations, surfacing the mismatch as a type error at
839
+ * the call site of `meta.annotate(...)`. No variadic-tuple inference is
840
+ * involved — TypeScript infers `Kinds` from the annotation argument and
841
+ * checks the conditional directly.
842
+ *
843
+ * The runtime gate inside `annotate` (via
844
+ * `assertAnnotationsApplicable`) catches cast / `any` / dynamic bypasses
845
+ * and throws `RUNTIME.ANNOTATION_INAPPLICABLE`.
846
+ *
847
+ * `annotate` returns the builder for chaining; the return value of the
848
+ * configurator callback is unused, so both block-body and expression-body
849
+ * callbacks compile.
850
+ *
851
+ * @example
852
+ * ```typescript
853
+ * await db.User.find({ id }, (meta) => meta.annotate(cacheAnnotation({ ttl: 60 })));
854
+ * await db.User.create(input, (meta) => {
855
+ * meta.annotate(auditAnnotation({ actor: 'system' }));
856
+ * meta.annotate(otelAnnotation({ traceId }));
857
+ * });
858
+ * ```
859
+ */
860
+ interface MetaBuilder<K extends OperationKind> {
861
+ annotate<P, Kinds extends OperationKind>(annotation: K extends Kinds ? AnnotationValue<P, Kinds> : never): this;
862
+ }
863
+ /**
864
+ * Lane-side view of a meta builder. Extends the public `MetaBuilder<K>`
865
+ * surface with `annotations` so lane terminals can read the recorded map
866
+ * after invoking the user configurator.
867
+ *
868
+ * Lane terminals construct one of these via `createMetaBuilder(kind, terminalName)`,
869
+ * pass it to the user callback as `MetaBuilder<K>` (the narrower public
870
+ * view), then read `meta.annotations` to thread the recorded values into
871
+ * `plan.meta.annotations`.
872
+ */
873
+ interface LaneMetaBuilder<K extends OperationKind> extends MetaBuilder<K> {
874
+ readonly annotations: ReadonlyMap<string, AnnotationValue<unknown, OperationKind>>;
875
+ }
876
+ /**
877
+ * Construct a lane-side meta builder for a terminal of operation kind `K`.
878
+ *
879
+ * Lane terminals call this with their `kind` (`'read'` or `'write'`) and a
880
+ * `terminalName` for error messages, hand the resulting builder to the
881
+ * user-supplied configurator callback (typed as `MetaBuilder<K>`, the
882
+ * narrower public view), and read `meta.annotations` afterwards to thread
883
+ * the recorded values into `plan.meta.annotations`.
884
+ */
885
+ declare function createMetaBuilder<K extends OperationKind>(kind: K, terminalName: string): LaneMetaBuilder<K>;
886
+ //#endregion
887
+ export { type AfterExecuteResult, type AnnotationHandle, type AnnotationValue, AsyncIterableResult, type CrossFamilyMiddleware, type DefineAnnotationOptions, type ExecutionPlan, type InterceptResult, type LaneMetaBuilder, type MetaBuilder, type OperationKind, type ParamRefMutator, type QueryPlan, RUNTIME_ABORTED, type ResultType, type RuntimeAbortedPhase, RuntimeCore, type RuntimeCoreOptions, type RuntimeErrorEnvelope, type RuntimeExecuteOptions, type RuntimeExecutor, type RuntimeLog, type RuntimeMiddleware, type RuntimeMiddlewareContext, type ValidAnnotations, assertAnnotationsApplicable, checkAborted, checkMiddlewareCompatibility, createMetaBuilder, defineAnnotation, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeAborted, runtimeError };
553
888
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/execution/async-iterable-result.ts","../src/execution/query-plan.ts","../src/execution/runtime-middleware.ts","../src/execution/before-execute-chain.ts","../src/execution/runtime-error.ts","../src/execution/race-against-abort.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts"],"mappings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BAAuC,iBAAA,CAAkB,aAAA;EAAA,SAC/D,UAAA,EAAY,aAAA,CAAc,WAAA;EAAA,SAC1B,GAAA,EAAK,wBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAmCM,WAAA,eACN,SAAA,gBACA,aAAA,sBACM,iBAAA,CAAkB,KAAA,cAC3B,eAAA,CAAgB,KAAA;EAAA,mBAER,UAAA,EAAY,aAAA,CAAc,WAAA;EAAA,mBAC1B,GAAA,EAAK,wBAAA;cAEZ,OAAA,EAAS,kBAAA,CAAmB,WAAA;EPtDA;;;;;EAAA,UOgE9B,gBAAA,CAAiB,IAAA,EAAM,KAAA,GAAQ,KAAA,GAAQ,OAAA,CAAQ,KAAA;EPdlC;;;;;;;;;;;;;EAAA,mBO+BJ,KAAA,CAAM,IAAA,EAAM,KAAA,EAAO,GAAA,EAAK,gBAAA,GAAmB,KAAA,GAAQ,OAAA,CAAQ,KAAA;EPZ7D;;;;;;;;;;EAAA,mBOwBE,SAAA,CAAU,IAAA,EAAM,KAAA,GAAQ,aAAA,CAAc,MAAA;EAAA,SAEhD,KAAA,CAAA,GAAS,OAAA;EAElB,OAAA,KAAA,CACE,IAAA,EAAM,KAAA;IAAA,SAAmB,IAAA,GAAO,GAAA;EAAA,GAChC,OAAA,GAAU,qBAAA,GACT,mBAAA,CAAoB,GAAA;AAAA"}
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/annotations.ts","../src/execution/async-iterable-result.ts","../src/execution/query-plan.ts","../src/execution/runtime-middleware.ts","../src/execution/before-execute-chain.ts","../src/execution/runtime-error.ts","../src/execution/race-against-abort.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts","../src/meta-builder.ts"],"mappings":";;;;;;;;AAmBA;;;;;AAaA;;;;;;;;KAbY,aAAA;;;;;;;;;;;;UAaK,eAAA,wBAAuC,aAAA;EAAA,SAC7C,YAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA,EAAO,OAAA;EAAA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,EAAM,CAAA,EACN,YAAA,WACC,eAAA,CAAgB,CAAA"}
package/dist/runtime.mjs CHANGED
@@ -61,6 +61,113 @@ function runtimeAborted(phase, cause) {
61
61
  return Object.assign(envelope, { cause });
62
62
  }
63
63
  //#endregion
64
+ //#region src/annotations.ts
65
+ /**
66
+ * Defines a typed annotation handle.
67
+ *
68
+ * Two-step call form. The first step takes the `Payload` type argument
69
+ * (TypeScript cannot infer `Payload` from anything in the options, so it
70
+ * must be supplied explicitly); the second step takes the runtime options
71
+ * and infers `Kinds` from the `applicableTo` array via a `const` type
72
+ * parameter, so the operation kinds appear exactly once at the call site.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // Read-only annotation. Lane terminals like `db.User.first(...)` accept
77
+ * // it; `db.User.create(...)` rejects it at the type level.
78
+ * const cacheAnnotation = defineAnnotation<{ ttl?: number; skip?: boolean }>()({
79
+ * namespace: 'cache',
80
+ * applicableTo: ['read'],
81
+ * }); // Kinds inferred as 'read'
82
+ *
83
+ * // Write-only annotation. Mirror image.
84
+ * const auditAnnotation = defineAnnotation<{ actor: string }>()({
85
+ * namespace: 'audit',
86
+ * applicableTo: ['write'],
87
+ * }); // Kinds inferred as 'write'
88
+ *
89
+ * // Annotation applicable to both kinds (e.g. tracing).
90
+ * const otelAnnotation = defineAnnotation<{ traceId: string }>()({
91
+ * namespace: 'otel',
92
+ * applicableTo: ['read', 'write'],
93
+ * }); // Kinds inferred as 'read' | 'write'
94
+ * ```
95
+ *
96
+ * **Reserved namespaces.** See `DefineAnnotationOptions.namespace` for the
97
+ * list of framework-internal namespaces (`codecs`, target-specific keys).
98
+ * `defineAnnotation` does not structurally prevent a user from naming a
99
+ * reserved namespace, but the framework makes no compatibility guarantee
100
+ * about handles that do.
101
+ */
102
+ function defineAnnotation() {
103
+ return (options) => {
104
+ const namespace = options.namespace;
105
+ const applicableTo = Object.freeze(new Set(options.applicableTo));
106
+ function handle(value) {
107
+ return Object.freeze({
108
+ __annotation: true,
109
+ namespace,
110
+ value,
111
+ applicableTo
112
+ });
113
+ }
114
+ function read(plan) {
115
+ const stored = plan.meta.annotations?.[namespace];
116
+ if (!isAnnotationValue(stored)) return;
117
+ if (stored.namespace !== namespace) return;
118
+ return stored.value;
119
+ }
120
+ return Object.freeze(Object.assign(handle, {
121
+ namespace,
122
+ applicableTo,
123
+ read
124
+ }));
125
+ };
126
+ }
127
+ /**
128
+ * Runtime applicability gate. Throws `RUNTIME.ANNOTATION_INAPPLICABLE` if
129
+ * any annotation in `annotations` declares an `applicableTo` set that does
130
+ * not include `kind`. Used by lane terminals (SQL DSL builders' `.build()`,
131
+ * ORM `Collection` terminals) to fail closed when the type-level
132
+ * `ValidAnnotations` gate is bypassed via cast / `any` / dynamic
133
+ * invocation.
134
+ *
135
+ * Passes silently on:
136
+ * - empty arrays
137
+ * - annotations whose `applicableTo` includes `kind`
138
+ *
139
+ * Throws on:
140
+ * - any annotation whose `applicableTo` does not include `kind`. The
141
+ * error names the offending annotation's `namespace` and the
142
+ * `terminalName` so users can locate the misuse.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Inside an ORM read terminal:
147
+ * assertAnnotationsApplicable(annotations, 'read', 'first');
148
+ * ```
149
+ */
150
+ function assertAnnotationsApplicable(annotations, kind, terminalName) {
151
+ for (const annotation of annotations) if (!annotation.applicableTo.has(kind)) throw runtimeError("RUNTIME.ANNOTATION_INAPPLICABLE", `Annotation '${annotation.namespace}' is not applicable to '${kind}' operations (terminal: '${terminalName}'). The annotation declares applicableTo = [${Array.from(annotation.applicableTo).map((k) => `'${k}'`).join(", ")}].`, {
152
+ namespace: annotation.namespace,
153
+ terminalName,
154
+ kind,
155
+ applicableTo: Array.from(annotation.applicableTo)
156
+ });
157
+ }
158
+ /**
159
+ * Type guard for branded annotation values stored in `plan.meta.annotations`.
160
+ *
161
+ * Internal — used by `AnnotationHandle.read` to distinguish user
162
+ * annotations (created by calling a handle returned from
163
+ * `defineAnnotation(...)`) from framework-internal metadata that may
164
+ * happen to live under the same namespace key.
165
+ */
166
+ function isAnnotationValue(value) {
167
+ if (value === null || typeof value !== "object") return false;
168
+ return value.__annotation === true;
169
+ }
170
+ //#endregion
64
171
  //#region src/execution/async-iterable-result.ts
65
172
  var AsyncIterableResult = class {
66
173
  generator;
@@ -416,6 +523,38 @@ function checkMiddlewareCompatibility(middleware, runtimeFamilyId, runtimeTarget
416
523
  });
417
524
  }
418
525
  //#endregion
419
- export { AsyncIterableResult, RUNTIME_ABORTED, RuntimeCore, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeAborted, runtimeError };
526
+ //#region src/meta-builder.ts
527
+ var MetaBuilderImpl = class {
528
+ #kind;
529
+ #terminalName;
530
+ #annotations = /* @__PURE__ */ new Map();
531
+ constructor(kind, terminalName) {
532
+ this.#kind = kind;
533
+ this.#terminalName = terminalName;
534
+ }
535
+ get annotations() {
536
+ return this.#annotations;
537
+ }
538
+ annotate(annotation) {
539
+ const value = annotation;
540
+ assertAnnotationsApplicable([value], this.#kind, this.#terminalName);
541
+ this.#annotations.set(value.namespace, value);
542
+ return this;
543
+ }
544
+ };
545
+ /**
546
+ * Construct a lane-side meta builder for a terminal of operation kind `K`.
547
+ *
548
+ * Lane terminals call this with their `kind` (`'read'` or `'write'`) and a
549
+ * `terminalName` for error messages, hand the resulting builder to the
550
+ * user-supplied configurator callback (typed as `MetaBuilder<K>`, the
551
+ * narrower public view), and read `meta.annotations` afterwards to thread
552
+ * the recorded values into `plan.meta.annotations`.
553
+ */
554
+ function createMetaBuilder(kind, terminalName) {
555
+ return new MetaBuilderImpl(kind, terminalName);
556
+ }
557
+ //#endregion
558
+ export { AsyncIterableResult, RUNTIME_ABORTED, RuntimeCore, assertAnnotationsApplicable, checkAborted, checkMiddlewareCompatibility, createMetaBuilder, defineAnnotation, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeAborted, runtimeError };
420
559
 
421
560
  //# sourceMappingURL=runtime.mjs.map