@prisma-next/framework-components 0.5.0-dev.8 → 0.5.0-dev.81

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 (94) hide show
  1. package/README.md +53 -4
  2. package/dist/authoring.d.mts +2 -2
  3. package/dist/authoring.mjs +2 -122
  4. package/dist/codec-m_-FAyQn.d.mts +168 -0
  5. package/dist/codec-m_-FAyQn.d.mts.map +1 -0
  6. package/dist/codec.d.mts +48 -2
  7. package/dist/codec.d.mts.map +1 -0
  8. package/dist/codec.mjs +67 -4
  9. package/dist/codec.mjs.map +1 -1
  10. package/dist/components.d.mts +1 -1
  11. package/dist/components.mjs +2 -3
  12. package/dist/control.d.mts +420 -74
  13. package/dist/control.d.mts.map +1 -1
  14. package/dist/control.mjs +83 -49
  15. package/dist/control.mjs.map +1 -1
  16. package/dist/emission-types-BKa4bR9m.d.mts +39 -0
  17. package/dist/emission-types-BKa4bR9m.d.mts.map +1 -0
  18. package/dist/emission.d.mts +2 -2
  19. package/dist/emission.mjs +1 -1
  20. package/dist/execution.d.mts +5 -5
  21. package/dist/execution.d.mts.map +1 -1
  22. package/dist/execution.mjs +4 -6
  23. package/dist/execution.mjs.map +1 -1
  24. package/dist/{framework-authoring-D1-JZ37B.d.mts → framework-authoring-DGIQbNPt.d.mts} +43 -12
  25. package/dist/framework-authoring-DGIQbNPt.d.mts.map +1 -0
  26. package/dist/framework-authoring-DxXcjyJX.mjs +209 -0
  27. package/dist/framework-authoring-DxXcjyJX.mjs.map +1 -0
  28. package/dist/{framework-components-DFZMi2h7.d.mts → framework-components-BGo7HsbL.d.mts} +45 -55
  29. package/dist/framework-components-BGo7HsbL.d.mts.map +1 -0
  30. package/dist/{framework-components-C8ZhSwXe.mjs → framework-components-FdqmlGUj.mjs} +3 -3
  31. package/dist/framework-components-FdqmlGUj.mjs.map +1 -0
  32. package/dist/psl-ast-Ckn_G-jv.d.mts +159 -0
  33. package/dist/psl-ast-Ckn_G-jv.d.mts.map +1 -0
  34. package/dist/psl-ast.d.mts +2 -0
  35. package/dist/psl-ast.mjs +1 -0
  36. package/dist/runtime.d.mts +395 -19
  37. package/dist/runtime.d.mts.map +1 -1
  38. package/dist/runtime.mjs +256 -7
  39. package/dist/runtime.mjs.map +1 -1
  40. package/dist/{types-import-spec-C4sc7wbb.d.mts → types-import-spec-BxI5cSQy.d.mts} +2 -2
  41. package/dist/types-import-spec-BxI5cSQy.d.mts.map +1 -0
  42. package/package.json +10 -6
  43. package/src/control/control-capabilities.ts +96 -0
  44. package/src/{control-descriptors.ts → control/control-descriptors.ts} +7 -7
  45. package/src/{control-instances.ts → control/control-instances.ts} +52 -6
  46. package/src/{control-migration-types.ts → control/control-migration-types.ts} +251 -63
  47. package/src/control/control-operation-preview.ts +23 -0
  48. package/src/control/control-spaces.ts +82 -0
  49. package/src/{control-stack.ts → control/control-stack.ts} +77 -94
  50. package/src/control/emission-types.ts +49 -0
  51. package/src/control/psl-ast.ts +193 -0
  52. package/src/{execution-descriptors.ts → execution/execution-descriptors.ts} +7 -7
  53. package/src/{execution-instances.ts → execution/execution-instances.ts} +1 -1
  54. package/src/{execution-requirements.ts → execution/execution-requirements.ts} +1 -1
  55. package/src/execution/query-plan.ts +53 -0
  56. package/src/execution/race-against-abort.ts +89 -0
  57. package/src/execution/run-with-middleware.ts +153 -0
  58. package/src/execution/runtime-core.ts +133 -0
  59. package/src/execution/runtime-error.ts +94 -0
  60. package/src/execution/runtime-middleware.ts +235 -0
  61. package/src/exports/authoring.ts +5 -2
  62. package/src/exports/codec.ts +27 -2
  63. package/src/exports/components.ts +2 -2
  64. package/src/exports/control.ts +41 -13
  65. package/src/exports/emission.ts +2 -2
  66. package/src/exports/execution.ts +5 -5
  67. package/src/exports/psl-ast.ts +1 -0
  68. package/src/exports/runtime.ts +18 -5
  69. package/src/shared/codec-descriptor.ts +87 -0
  70. package/src/shared/codec-types.ts +79 -0
  71. package/src/shared/codec.ts +80 -0
  72. package/src/shared/column-spec.ts +83 -0
  73. package/src/{framework-authoring.ts → shared/framework-authoring.ts} +210 -23
  74. package/src/{framework-components.ts → shared/framework-components.ts} +22 -48
  75. package/src/{mutation-default-types.ts → shared/mutation-default-types.ts} +22 -2
  76. package/dist/authoring.mjs.map +0 -1
  77. package/dist/codec-types-DQ1Agjom.d.mts +0 -58
  78. package/dist/codec-types-DQ1Agjom.d.mts.map +0 -1
  79. package/dist/emission-types-BPAALJbF.d.mts +0 -24
  80. package/dist/emission-types-BPAALJbF.d.mts.map +0 -1
  81. package/dist/framework-authoring-D1-JZ37B.d.mts.map +0 -1
  82. package/dist/framework-components-C8ZhSwXe.mjs.map +0 -1
  83. package/dist/framework-components-DFZMi2h7.d.mts.map +0 -1
  84. package/dist/types-import-spec-C4sc7wbb.d.mts.map +0 -1
  85. package/src/codec-types.ts +0 -64
  86. package/src/control-capabilities.ts +0 -34
  87. package/src/emission-types.ts +0 -28
  88. package/src/runtime-error.ts +0 -55
  89. package/src/runtime-middleware.ts +0 -83
  90. /package/src/{control-result-types.ts → control/control-result-types.ts} +0 -0
  91. /package/src/{control-schema-view.ts → control/control-schema-view.ts} +0 -0
  92. /package/src/{async-iterable-result.ts → execution/async-iterable-result.ts} +0 -0
  93. /package/src/{execution-stack.ts → execution/execution-stack.ts} +0 -0
  94. /package/src/{types-import-spec.ts → shared/types-import-spec.ts} +0 -0
@@ -1,12 +1,14 @@
1
- import { a as AuthoringFieldNamespace, d as AuthoringTypeNamespace, i as AuthoringContributions } from "./framework-authoring-D1-JZ37B.mjs";
2
- import { n as CodecLookup } from "./codec-types-DQ1Agjom.mjs";
3
- import { A as LoweredDefaultResult, C as ControlMutationDefaultEntry, D as DefaultFunctionLoweringHandler, E as DefaultFunctionLoweringContext, F as SourceSpan, M as MutationDefaultGeneratorDescriptor, N as ParsedDefaultFunctionCall, O as DefaultFunctionRegistry, P as SourceDiagnostic, T as ControlMutationDefaults, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, j as LoweredDefaultValue, k as DefaultFunctionRegistryEntry, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, v as TargetBoundComponentDescriptor, w as ControlMutationDefaultRegistry, y as TargetDescriptor } from "./framework-components-DFZMi2h7.mjs";
4
- import { t as TypesImportSpec } from "./types-import-spec-C4sc7wbb.mjs";
5
- import { t as EmissionSpi } from "./emission-types-BPAALJbF.mjs";
1
+ import { a as AuthoringFieldNamespace, d as AuthoringTypeNamespace, i as AuthoringContributions } from "./framework-authoring-DGIQbNPt.mjs";
2
+ import { c as CodecLookup } from "./codec-m_-FAyQn.mjs";
3
+ import { A as LoweredDefaultResult, C as ControlMutationDefaultEntry, D as DefaultFunctionLoweringHandler, E as DefaultFunctionLoweringContext, F as SourceSpan, M as MutationDefaultGeneratorDescriptor, N as ParsedDefaultFunctionCall, O as DefaultFunctionRegistry, P as SourceDiagnostic, T as ControlMutationDefaults, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, h as FamilyInstance, j as LoweredDefaultValue, k as DefaultFunctionRegistryEntry, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, t as AdapterDescriptor, v as TargetBoundComponentDescriptor, w as ControlMutationDefaultRegistry, y as TargetDescriptor } from "./framework-components-BGo7HsbL.mjs";
4
+ import { t as TypesImportSpec } from "./types-import-spec-BxI5cSQy.mjs";
5
+ import { t as EmissionSpi } from "./emission-types-BKa4bR9m.mjs";
6
+ import { m as PslDocumentAst } from "./psl-ast-Ckn_G-jv.mjs";
6
7
  import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
8
+ import { ImportRequirement, ImportRequirement as ImportRequirement$1 } from "@prisma-next/ts-render";
7
9
  import { Result } from "@prisma-next/utils/result";
8
10
 
9
- //#region src/control-result-types.d.ts
11
+ //#region src/control/control-result-types.d.ts
10
12
  declare const VERIFY_CODE_MARKER_MISSING = "PN-RUN-3001";
11
13
  declare const VERIFY_CODE_HASH_MISMATCH = "PN-RUN-3002";
12
14
  declare const VERIFY_CODE_TARGET_MISMATCH = "PN-RUN-3003";
@@ -154,7 +156,7 @@ interface SignDatabaseResult {
154
156
  };
155
157
  }
156
158
  //#endregion
157
- //#region src/control-instances.d.ts
159
+ //#region src/control/control-instances.d.ts
158
160
  interface ControlFamilyInstance<TFamilyId extends string, TSchemaIR> extends FamilyInstance<TFamilyId> {
159
161
  validateContract(contractJson: unknown): Contract;
160
162
  verify(options: {
@@ -172,15 +174,59 @@ interface ControlFamilyInstance<TFamilyId extends string, TSchemaIR> extends Fam
172
174
  readonly configPath?: string;
173
175
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, string>>;
174
176
  }): Promise<VerifyDatabaseSchemaResult>;
177
+ /**
178
+ * Verify a contract against an already-introspected schema slice.
179
+ *
180
+ * Difference from {@link schemaVerify}: no `driver`, no introspection
181
+ * — the caller hands over the schema directly. Used by the aggregate
182
+ * verifier to invoke the family's verification logic per member,
183
+ * with the schema **pre-projected** to that member's claimed slice
184
+ * via {@link import('@prisma-next/migration-tools/aggregate').projectSchemaToSpace}.
185
+ *
186
+ * Synchronous — no I/O. Idempotent.
187
+ */
188
+ schemaVerifyAgainstSchema(options: {
189
+ readonly contract: unknown;
190
+ readonly schema: TSchemaIR;
191
+ readonly strict: boolean;
192
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, string>>;
193
+ }): VerifyDatabaseSchemaResult;
175
194
  sign(options: {
176
195
  readonly driver: ControlDriverInstance<TFamilyId, string>;
177
196
  readonly contract: unknown;
178
197
  readonly contractPath: string;
179
198
  readonly configPath?: string;
180
199
  }): Promise<SignDatabaseResult>;
200
+ /**
201
+ * Reads the contract marker for `space` from the database, returning
202
+ * `null` if no marker row exists for that space (or if the marker
203
+ * table itself is missing).
204
+ *
205
+ * `space` is required at every call site so the type system surfaces
206
+ * every place that needs to thread the value: callers in single-app
207
+ * paths pass {@link import('./control-spaces').APP_SPACE_ID}
208
+ * (`'app'`); per-extension callers pass the extension's space id.
209
+ * Defaulting at the family-interface level was a silent bug door —
210
+ * it let multi-space-aware callers forget to pass `space` and
211
+ * collapse onto the app's marker row.
212
+ *
213
+ * Families whose underlying storage doesn't yet support per-space
214
+ * markers (Mongo, today) accept `space` for interface conformance and
215
+ * reject any non-`APP_SPACE_ID` value rather than silently ignoring
216
+ * it; see the family-specific implementation for details.
217
+ */
181
218
  readMarker(options: {
182
219
  readonly driver: ControlDriverInstance<TFamilyId, string>;
220
+ readonly space: string;
183
221
  }): Promise<ContractMarkerRecord | null>;
222
+ /**
223
+ * Reads every marker row keyed by `space`. Used by the per-space
224
+ * verifier to detect orphan marker rows and marker-vs-on-disk drift.
225
+ * Returns an empty map when the marker table does not yet exist.
226
+ */
227
+ readAllMarkers(options: {
228
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
229
+ }): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
184
230
  introspect(options: {
185
231
  readonly driver: ControlDriverInstance<TFamilyId, string>;
186
232
  readonly contract?: unknown;
@@ -196,7 +242,7 @@ interface ControlDriverInstance<TFamilyId extends string, TTargetId extends stri
196
242
  }
197
243
  interface ControlExtensionInstance<TFamilyId extends string, TTargetId extends string> extends ExtensionInstance<TFamilyId, TTargetId> {}
198
244
  //#endregion
199
- //#region src/control-stack.d.ts
245
+ //#region src/control/control-stack.d.ts
200
246
  interface AssembledAuthoringContributions {
201
247
  readonly field: AuthoringFieldNamespace;
202
248
  readonly type: AuthoringTypeNamespace;
@@ -252,11 +298,11 @@ declare function assembleControlMutationDefaults(descriptors: ReadonlyArray<Pick
252
298
  readonly id?: string;
253
299
  }>): ControlMutationDefaults;
254
300
  declare function extractCodecLookup(descriptors: ReadonlyArray<Pick<ComponentMetadata & {
255
- id?: string;
301
+ id: string;
256
302
  }, 'types' | 'id'>>): CodecLookup;
257
303
  declare function createControlStack<TFamilyId extends string, TTargetId extends string>(input: CreateControlStackInput<TFamilyId, TTargetId>): ControlStack<TFamilyId, TTargetId>;
258
304
  //#endregion
259
- //#region src/control-descriptors.d.ts
305
+ //#region src/control/control-descriptors.d.ts
260
306
  interface ControlFamilyDescriptor<TFamilyId extends string, TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<TFamilyId, unknown>> extends FamilyDescriptor<TFamilyId> {
261
307
  readonly emission: EmissionSpi;
262
308
  create<TTargetId extends string>(stack: ControlStack<TFamilyId, TTargetId>): TFamilyInstance;
@@ -281,7 +327,62 @@ interface ControlExtensionDescriptor<TFamilyId extends string, TTargetId extends
281
327
  create(): TExtensionInstance;
282
328
  }
283
329
  //#endregion
284
- //#region src/control-migration-types.d.ts
330
+ //#region src/control/control-migration-types.d.ts
331
+ /**
332
+ * Planner provenance recorded inside {@link MigrationMetadata}.
333
+ *
334
+ * `used` / `applied` track which migration hints the planner consulted
335
+ * vs. which it actually applied during emission; `plannerVersion`
336
+ * pins the planner build that produced the migration so future
337
+ * verification passes can recognise plans authored against an older
338
+ * planner.
339
+ */
340
+ interface MigrationHints {
341
+ readonly used: readonly string[];
342
+ readonly applied: readonly string[];
343
+ readonly plannerVersion: string;
344
+ }
345
+ /**
346
+ * In-memory migration metadata envelope. Every migration is
347
+ * content-addressed: the `migrationHash` is a hash over the metadata
348
+ * envelope plus the operations list, computed at write time. There is no
349
+ * draft state — a migration directory either exists with fully attested
350
+ * metadata or it does not.
351
+ *
352
+ * When the planner cannot lower an operation because of an unfilled
353
+ * `placeholder(...)` slot, the migration is still written with
354
+ * `migrationHash` hashed over `ops: []`. Re-running self-emit after the
355
+ * user fills the placeholder produces a *different* `migrationHash`
356
+ * (committed to the real ops); this is intentional.
357
+ *
358
+ * The on-disk JSON shape in `migration.json` matches this type
359
+ * field-for-field — `JSON.stringify(metadata, null, 2)` is the canonical
360
+ * writer output (defined in `@prisma-next/migration-tools/io`).
361
+ */
362
+ interface MigrationMetadata {
363
+ readonly migrationHash: string;
364
+ readonly from: string | null;
365
+ readonly to: string;
366
+ readonly fromContract: Contract | null;
367
+ readonly toContract: Contract;
368
+ readonly hints: MigrationHints;
369
+ readonly labels: readonly string[];
370
+ /**
371
+ * Sorted, deduplicated list of `invariantId`s declared by the
372
+ * migration's data-transform ops. Always present; an empty array
373
+ * means the migration has no routing-visible data transforms.
374
+ */
375
+ readonly providedInvariants: readonly string[];
376
+ readonly authorship?: {
377
+ readonly author?: string;
378
+ readonly email?: string;
379
+ };
380
+ readonly signature?: {
381
+ readonly keyId: string;
382
+ readonly value: string;
383
+ } | null;
384
+ readonly createdAt: string;
385
+ }
285
386
  /**
286
387
  * Migration operation classes define the safety level of an operation.
287
388
  * - 'additive': Adds new structures without modifying existing ones (safe)
@@ -294,52 +395,15 @@ type MigrationOperationClass = 'additive' | 'widening' | 'destructive' | 'data';
294
395
  * A lowered query statement as stored in ops.json.
295
396
  * Contains the SQL string and parameter values — ready for execution.
296
397
  * Lowering from query builder AST to SQL happens at verify time.
398
+ *
399
+ * The Postgres `dataTransform` factory uses this shape internally to
400
+ * carry the user's lowered `check`/`run` plans before wrapping them
401
+ * into precheck/execute/postcheck steps on the unified migration op.
297
402
  */
298
403
  interface SerializedQueryPlan {
299
404
  readonly sql: string;
300
405
  readonly params: readonly unknown[];
301
406
  }
302
- /**
303
- * A data transform operation within a migration edge.
304
- *
305
- * Data transforms are authored in TypeScript using the query builder,
306
- * serialized to JSON ASTs at verification time, and rendered to SQL
307
- * by the target adapter at apply time.
308
- *
309
- * The `name` serves as the invariant identity — it's recorded in the
310
- * ledger and used for invariant-aware routing via environment refs.
311
- *
312
- * In draft state (before verification), `check` and `run` are null.
313
- * After verification, they contain the serialized query ASTs.
314
- */
315
- interface DataTransformOperation extends MigrationPlanOperation {
316
- readonly operationClass: 'data';
317
- /**
318
- * The invariant name for this data transform.
319
- * Recorded in the ledger on successful edge completion.
320
- * Used by environment refs to declare required invariants.
321
- */
322
- readonly name: string;
323
- /**
324
- * Path to the TypeScript source file that produced this operation.
325
- * Not part of edgeId computation — for traceability only.
326
- */
327
- readonly source: string;
328
- /**
329
- * Serialized check query plan, or a boolean literal.
330
- * - SerializedQueryPlan: describes violations; empty result = already applied.
331
- * - false: always run (no check).
332
- * - true: always skip.
333
- * - null: not yet serialized (draft state).
334
- */
335
- readonly check: SerializedQueryPlan | boolean | null;
336
- /**
337
- * Serialized run query plans.
338
- * - Array of serialized query plans to execute sequentially.
339
- * - null: not yet serialized (draft state).
340
- */
341
- readonly run: readonly SerializedQueryPlan[] | null;
342
- }
343
407
  /**
344
408
  * Policy defining which operation classes are allowed during a migration.
345
409
  */
@@ -357,11 +421,46 @@ interface MigrationPlanOperation {
357
421
  readonly label: string;
358
422
  /** The class of operation (additive, widening, destructive). */
359
423
  readonly operationClass: MigrationOperationClass;
424
+ /**
425
+ * Optional opt-in routing identity for data-transform operations.
426
+ * Presence opts the transform into invariant-aware routing; absence
427
+ * means it is path-dependent and not referenceable from refs.
428
+ *
429
+ * Lives on the base op so the manifest emitter and
430
+ * `deriveProvidedInvariants` can read it without depending on a
431
+ * target-specific shape. Schema-DDL ops (additive / widening /
432
+ * destructive) leave it undefined.
433
+ */
434
+ readonly invariantId?: string;
360
435
  }
361
436
  /**
362
- * Framework-level contract for a single factory call in a target's planner IR.
437
+ * Framework-level contract for a single factory call in a target's planner
438
+ * IR — the canonical shape for any node participating in the two-renderer
439
+ * pattern (source-text rendering for `migration.ts` + runtime-op derivation
440
+ * for `ops.json`).
441
+ *
442
+ * Implementations declare:
443
+ *
444
+ * - **Identity / display metadata** (`factoryName`, `operationClass`,
445
+ * `label`) used by CLI summaries and the issue planner.
446
+ * - **`renderTypeScript()`** — emit the call as a TypeScript expression
447
+ * suitable for inclusion in a generated `migration.ts`. Polymorphic
448
+ * across postgres / mongo / sqlite / extension-owned calls.
449
+ * - **`importRequirements()`** — the symbols this rendered expression
450
+ * pulls in. Aggregated and deduplicated by the top-level renderer
451
+ * into a single import block per file.
452
+ * - **`toOp()`** — lower the call to a runtime
453
+ * `MigrationPlanOperation`. Returns the framework base; concrete
454
+ * implementations narrow via covariant return (e.g. SQL targets
455
+ * return `SqlMigrationPlanOperation<TTargetDetails>`).
456
+ *
457
+ * Each domain (target, extension) defines its own set of concrete `*Call`
458
+ * classes that implement this interface — typically by extending
459
+ * {@link import('@prisma-next/ts-render').TsExpression} and adding the
460
+ * concrete `toOp()` body. Extensions can implement the interface
461
+ * directly without depending on a target's package-private base.
363
462
  *
364
- * @see ADR 195
463
+ * @see ADR 195 — Planner IR with two renderers.
365
464
  */
366
465
  interface OpFactoryCall {
367
466
  /** The name of the factory that would produce this call's runtime op. */
@@ -370,6 +469,26 @@ interface OpFactoryCall {
370
469
  readonly operationClass: MigrationOperationClass;
371
470
  /** Human-readable label for CLI output and diagnostics. */
372
471
  readonly label: string;
472
+ /**
473
+ * Render this call as a TypeScript expression suitable for inclusion in
474
+ * a generated `migration.ts`. The output is composed alongside other
475
+ * calls' rendered expressions inside the migration's `operations`
476
+ * array.
477
+ */
478
+ renderTypeScript(): string;
479
+ /**
480
+ * Import requirements pulled in by the rendered TypeScript expression.
481
+ * Aggregated and deduplicated across all calls into a single import
482
+ * block per file.
483
+ */
484
+ importRequirements(): readonly ImportRequirement$1[];
485
+ /**
486
+ * Lower this call to a runtime migration plan operation suitable for
487
+ * execution / inclusion in `ops.json`. Concrete implementations narrow
488
+ * the return type via covariant return (e.g. SQL targets return
489
+ * `SqlMigrationPlanOperation<TTargetDetails>`).
490
+ */
491
+ toOp(): MigrationPlanOperation;
373
492
  }
374
493
  /**
375
494
  * A migration plan for display purposes.
@@ -378,6 +497,16 @@ interface OpFactoryCall {
378
497
  interface MigrationPlan {
379
498
  /** The target ID this plan is for (e.g., 'postgres'). */
380
499
  readonly targetId: string;
500
+ /**
501
+ * Contract space this plan applies to. Runners cross-check
502
+ * `options.space` against `plan.spaceId` so the marker row gets keyed
503
+ * by the right space when applying via `executeAcrossSpaces`.
504
+ *
505
+ * Optional for backward compatibility with single-space callers that
506
+ * pre-date the contract-space aggregate; when present, runners
507
+ * enforce that it matches `options.space`.
508
+ */
509
+ readonly spaceId?: string;
381
510
  /**
382
511
  * Origin contract identity that the plan expects the database to currently be at.
383
512
  * If omitted or null, the runner skips origin validation entirely.
@@ -393,6 +522,17 @@ interface MigrationPlan {
393
522
  };
394
523
  /** Ordered list of operations to execute. */
395
524
  readonly operations: readonly MigrationPlanOperation[];
525
+ /**
526
+ * Sorted, deduplicated invariant ids declared by this plan's data-transform
527
+ * ops. Authored migrations carry the canonical value from
528
+ * `migration.json.providedInvariants`; planner-built plans (`db init`,
529
+ * `db update`) omit it (the runner treats it as `[]`). Runners read this
530
+ * field for marker writes and self-edge no-op detection rather than
531
+ * re-deriving from `operations`, since the manifest is the canonical
532
+ * source for the invariant set across all runners (postgres, sqlite,
533
+ * mongo).
534
+ */
535
+ readonly providedInvariants?: readonly string[];
396
536
  }
397
537
  /**
398
538
  * A migration plan that can also render itself back to user-editable
@@ -502,27 +642,36 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
502
642
  readonly contract: unknown;
503
643
  readonly schema: unknown;
504
644
  readonly policy: MigrationOperationPolicy;
505
- /**
506
- * Storage hash of the "from" contract (the state the planner assumes the
507
- * database starts at). Planners use this to populate `describe()` on the
508
- * produced plan so the rendered `migration.ts` has correct `from`/`to`
509
- * metadata.
510
- */
511
- readonly fromHash: string;
512
645
  /**
513
646
  * The "from" contract (the state the planner assumes the database starts
514
- * at). Planners pass this to data-safety strategies so they can compare
515
- * `from` and `to` column shapes (e.g. to detect unsafe type changes).
516
- * `db update` / `db init` reconcile against the live schema and have no
517
- * "from" contract; only `migration plan` provides one.
647
+ * at), or `null` for a baseline plan with no prior state.
648
+ *
649
+ * Planners derive any "from" identity they need to stamp onto the
650
+ * produced plan's `describe()` from `fromContract?.storage.storageHash
651
+ * ?? null`. They also pass this to data-safety strategies so they can
652
+ * compare `from` and `to` column shapes (e.g. to detect unsafe type
653
+ * changes).
654
+ *
655
+ * Required at every call site to make the structural fact "I have a
656
+ * prior contract / I don't" visible in the type. Reconciliation
657
+ * commands (`db init`, `db update`) introspect a live schema and pass
658
+ * `null`; authoring commands (`migration plan`) pass the previous
659
+ * bundle's `metadata.toContract`.
518
660
  */
519
- readonly fromContract?: unknown;
661
+ readonly fromContract: Contract | null;
520
662
  /**
521
663
  * Active framework components participating in this composition.
522
664
  * Families/targets can interpret this list to derive family-specific metadata.
523
665
  * All components must have matching familyId and targetId.
524
666
  */
525
667
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
668
+ /**
669
+ * Contract space this plan applies to. Stamped onto the produced
670
+ * plan so the runner keys the marker row by the right space when
671
+ * executing. App-plan callers pass `APP_SPACE_ID` (`'app'`);
672
+ * per-extension callers pass the extension's space id.
673
+ */
674
+ readonly spaceId: string;
526
675
  }): MigrationPlannerResult;
527
676
  /**
528
677
  * Produce an empty migration with the target's authoring conventions.
@@ -530,8 +679,12 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
530
679
  * Used by `migration new` to scaffold a fresh `migration.ts`. The
531
680
  * returned plan has no operations; its `renderTypeScript()` yields a
532
681
  * stub the user can edit.
682
+ *
683
+ * `spaceId` is stamped onto the produced plan; reconciliation flows
684
+ * (`db init`, `db update`) and authoring flows (`migration new`) all
685
+ * pass it explicitly.
533
686
  */
534
- emptyMigration(context: MigrationScaffoldContext): MigrationPlanWithAuthoringSurface;
687
+ emptyMigration(context: MigrationScaffoldContext, spaceId: string): MigrationPlanWithAuthoringSurface;
535
688
  }
536
689
  /**
537
690
  * Migration runner interface for executing migration plans.
@@ -541,6 +694,16 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
541
694
  * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
542
695
  */
543
696
  interface MigrationRunner<TFamilyId extends string = string, TTargetId extends string = string> {
697
+ /**
698
+ * Execute a migration plan against the configured driver.
699
+ *
700
+ * The `plan` parameter is trusted input. Callers are responsible for
701
+ * upstream verification of the originating migration package — typically
702
+ * by obtaining the package via `readMigrationPackage` from
703
+ * `@prisma-next/migration-tools/io`, which performs hash-integrity checks
704
+ * at the load boundary. Runners do not re-verify the plan and assume the
705
+ * `(metadata, ops)` pair on disk has not been tampered with since emit.
706
+ */
544
707
  execute(options: {
545
708
  readonly plan: MigrationPlan;
546
709
  readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
@@ -563,6 +726,58 @@ interface MigrationRunner<TFamilyId extends string = string, TTargetId extends s
563
726
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
564
727
  }): Promise<MigrationRunnerResult>;
565
728
  }
729
+ /**
730
+ * Per-space input for {@link MultiSpaceCapableRunner.executeAcrossSpaces}.
731
+ *
732
+ * Mirrors the single-space `MigrationRunner.execute` options, extended with a
733
+ * required `space` identifier. Each entry's `driver` must reference the same
734
+ * connection the outer transaction is opened on (typically the same value as
735
+ * the top-level `driver` on `executeAcrossSpaces`).
736
+ *
737
+ * Family-specific runners (e.g. the SQL family's `SqlMigrationRunner`) define
738
+ * a richer per-space option shape that is structurally compatible with this
739
+ * one — additional optional fields (e.g. SQL's `strictVerification`,
740
+ * `schemaName`, `callbacks`) are tolerated by the underlying runner without
741
+ * affecting cross-target wiring.
742
+ */
743
+ interface MultiSpaceRunnerPerSpaceOptions<TFamilyId extends string = string, TTargetId extends string = string> {
744
+ readonly space: string;
745
+ readonly plan: MigrationPlan;
746
+ readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
747
+ readonly destinationContract: unknown;
748
+ readonly policy: MigrationOperationPolicy;
749
+ readonly executionChecks?: MigrationRunnerExecutionChecks;
750
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
751
+ }
752
+ interface MultiSpaceRunnerSuccessValue {
753
+ readonly perSpaceResults: ReadonlyArray<{
754
+ readonly space: string;
755
+ readonly value: MigrationRunnerSuccessValue;
756
+ }>;
757
+ }
758
+ interface MultiSpaceRunnerFailure extends MigrationRunnerFailure {
759
+ /** Identifier of the space whose plan caused the rollback. */
760
+ readonly failingSpace: string;
761
+ }
762
+ type MultiSpaceRunnerResult = Result<MultiSpaceRunnerSuccessValue, MultiSpaceRunnerFailure>;
763
+ /**
764
+ * Optional capability for runners that can apply a list of per-space plans
765
+ * inside a single outer transaction. A failure on any space rolls back every
766
+ * space's writes.
767
+ *
768
+ * The SQL family (`SqlMigrationRunner`) implements this with a true outer
769
+ * transaction across every space. The Mongo family implements a degenerate
770
+ * single-space shim (per-space is a non-goal per the extension-contract-spaces
771
+ * project spec — Mongo aggregates are always single-member). The capability
772
+ * is declared at the framework layer so CLI utilities can route through it
773
+ * without importing any specific family directly.
774
+ */
775
+ interface MultiSpaceCapableRunner<TFamilyId extends string = string, TTargetId extends string = string> {
776
+ executeAcrossSpaces(options: {
777
+ readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
778
+ readonly perSpaceOptions: ReadonlyArray<MultiSpaceRunnerPerSpaceOptions<TFamilyId, TTargetId>>;
779
+ }): Promise<MultiSpaceRunnerResult>;
780
+ }
566
781
  /**
567
782
  * Optional capability interface for targets that support migrations.
568
783
  * Targets that implement migrations expose this via their descriptor.
@@ -598,11 +813,12 @@ interface MigrationScaffoldContext {
598
813
  /** Absolute path to the contract.json file, if one exists. Used by targets that emit typed-contract imports. */
599
814
  readonly contractJsonPath?: string;
600
815
  /**
601
- * Storage hash of the "from" contract. Targets use this to populate
602
- * `describe()` on the rendered empty migration so that identity metadata
603
- * is correctly populated.
816
+ * Storage hash of the "from" contract, or `null` for a baseline scaffold
817
+ * with no prior state. Targets use this to populate `describe()` on the
818
+ * rendered empty migration so that identity metadata is correctly
819
+ * populated.
604
820
  */
605
- readonly fromHash: string;
821
+ readonly fromHash: string | null;
606
822
  /**
607
823
  * Storage hash of the "to" contract. Same purpose as `fromHash` — threaded
608
824
  * through so the rendered class's `describe()` declares the correct
@@ -611,7 +827,30 @@ interface MigrationScaffoldContext {
611
827
  readonly toHash: string;
612
828
  }
613
829
  //#endregion
614
- //#region src/control-schema-view.d.ts
830
+ //#region src/control/control-operation-preview.d.ts
831
+ /**
832
+ * Family-agnostic textual preview of a migration plan, used by the CLI to
833
+ * render a "DDL preview" section for `db init` / `db update` / `migration plan`
834
+ * / `migration show`. Each statement carries a free-form `language` tag so
835
+ * formatters can suffix `;` for SQL but render Mongo shell lines verbatim.
836
+ *
837
+ * Producers are family-specific: SQL emits `language: 'sql'` (existing DDL
838
+ * extraction); Mongo emits `language: 'mongodb-shell'` via the
839
+ * `MongoDdlCommandFormatter` visitor.
840
+ *
841
+ * The capability `OperationPreviewCapable` (declared in
842
+ * `./control-capabilities`) is how a family announces it can produce these.
843
+ */
844
+ interface OperationPreviewStatement {
845
+ readonly text: string;
846
+ /** Dialect identifier, e.g. `'sql'`, `'mongodb-shell'`. Free-form by design (OQ-3). */
847
+ readonly language: string;
848
+ }
849
+ interface OperationPreview {
850
+ readonly statements: readonly OperationPreviewStatement[];
851
+ }
852
+ //#endregion
853
+ //#region src/control/control-schema-view.d.ts
615
854
  /**
616
855
  * Core schema view types for family-agnostic schema visualization.
617
856
  *
@@ -649,7 +888,7 @@ interface CoreSchemaView {
649
888
  readonly root: SchemaTreeNode;
650
889
  }
651
890
  //#endregion
652
- //#region src/control-capabilities.d.ts
891
+ //#region src/control/control-capabilities.d.ts
653
892
  interface MigratableTargetDescriptor<TFamilyId extends string, TTargetId extends string, TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<TFamilyId, unknown>> extends ControlTargetDescriptor<TFamilyId, TTargetId> {
654
893
  readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, TFamilyInstance>;
655
894
  }
@@ -658,6 +897,113 @@ interface SchemaViewCapable<TSchemaIR = unknown> {
658
897
  toSchemaView(schema: TSchemaIR): CoreSchemaView;
659
898
  }
660
899
  declare function hasSchemaView<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & SchemaViewCapable<TSchemaIR>;
900
+ /**
901
+ * Capability declaring that a family can infer a PSL contract AST from its
902
+ * opaque introspected schema IR. Consumed by `prisma-next contract infer`.
903
+ */
904
+ interface PslContractInferCapable<TSchemaIR = unknown> {
905
+ inferPslContract(schemaIR: TSchemaIR): PslDocumentAst;
906
+ }
907
+ declare function hasPslContractInfer<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & PslContractInferCapable<TSchemaIR>;
908
+ /**
909
+ * Capability declaring that a family can render a textual preview of migration
910
+ * operations for the CLI's "DDL preview" output. SQL families emit
911
+ * `language: 'sql'` statements; Mongo families emit `language: 'mongodb-shell'`.
912
+ */
913
+ interface OperationPreviewCapable {
914
+ toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;
915
+ }
916
+ declare function hasOperationPreview<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & OperationPreviewCapable;
917
+ /**
918
+ * Capability declaring that a runner can apply per-space plans inside a
919
+ * single outer transaction. The SQL family (`SqlMigrationRunner`) implements
920
+ * this with a true outer transaction. The Mongo family implements a
921
+ * degenerate single-space shim (Mongo per-space is a non-goal per the
922
+ * extension-contract-spaces project spec — TML-2397).
923
+ *
924
+ * The CLI's shared `applyAggregate` primitive uses this guard so that
925
+ * `db init` / `db update` / `migration apply` route uniformly through one
926
+ * dispatch path regardless of family.
927
+ */
928
+ declare function hasMultiSpaceRunner<TFamilyId extends string, TTargetId extends string>(runner: MigrationRunner<TFamilyId, TTargetId>): runner is MigrationRunner<TFamilyId, TTargetId> & MultiSpaceCapableRunner<TFamilyId, TTargetId>;
929
+ //#endregion
930
+ //#region src/control/control-spaces.d.ts
931
+ /**
932
+ * Canonical control-plane identifiers for contract spaces.
933
+ *
934
+ * A contract space is the disjoint `(contract.json, migration-graph)` unit
935
+ * the per-space planner / runner / verifier (project: extension contract
936
+ * spaces, TML-2397) operates on. The application owns one well-known
937
+ * space — the value below — and each loaded extension that contributes
938
+ * schema owns a uniquely-named space.
939
+ *
940
+ * Lives in `framework-components/control` so every layer that has to
941
+ * reason about space identity (the migration tooling, the SQL runtime's
942
+ * marker reader, target-side statement builders, target-side adapters)
943
+ * can import a single value rather than duplicating the literal. Raw
944
+ * `'app'` string literals in framework / target / runtime / adapter
945
+ * source code are forbidden and policed by
946
+ * `scripts/lint-app-space-id.mjs` (wired into `pnpm lint:deps`).
947
+ *
948
+ * @see specs/framework-mechanism.spec.md § 3 — Layout convention (γ).
949
+ */
950
+ declare const APP_SPACE_ID: "app";
951
+ /**
952
+ * Head ref for a contract space — the `(hash, invariants)` tuple
953
+ * a runner targets when applying that space's migration graph. Identical
954
+ * in shape to the on-disk `migrations/<space-id>/refs/head.json` the
955
+ * framework writes per loaded extension, and to the app-space
956
+ * `<projectRoot>/refs/head.json`. Family-agnostic: SQL, Mongo, and any
957
+ * future family share the same head-ref shape.
958
+ *
959
+ * @see specs/framework-mechanism.spec.md § 1.
960
+ */
961
+ interface ContractSpaceHeadRef {
962
+ readonly hash: string;
963
+ readonly invariants: readonly string[];
964
+ }
965
+ /**
966
+ * Canonical structural shape of a migration package — the unit a planner
967
+ * produces and a runner consumes: a directory name, the ADR 197 metadata
968
+ * envelope (which carries the `toContract` snapshot), and the operation
969
+ * list.
970
+ *
971
+ * In-memory by default. Readers in `@prisma-next/migration-tools`
972
+ * (`readMigrationPackage` / `readMigrationsDir`) return the augmented
973
+ * {@link import('@prisma-next/migration-tools/package').OnDiskMigrationPackage}
974
+ * variant which adds `dirPath`; everything else operates against the
975
+ * canonical shape so the same value flows through pre-emission
976
+ * authoring, on-disk loading, and runner execution without conversion.
977
+ *
978
+ * @see specs/framework-mechanism.spec.md § 1.
979
+ */
980
+ interface MigrationPackage {
981
+ readonly dirName: string;
982
+ readonly metadata: MigrationMetadata;
983
+ readonly ops: readonly MigrationPlanOperation[];
984
+ }
985
+ /**
986
+ * Canonical structural shape of a contract space — one disjoint
987
+ * `(contractJson, migration-graph)` unit the per-space planner / runner
988
+ * / verifier operates on. The application owns one well-known space
989
+ * ({@link APP_SPACE_ID}); each loaded extension that contributes schema
990
+ * owns a uniquely-named space. Whether a value is the app's space or an
991
+ * extension's space is a control-plane concern; the type carries no
992
+ * such distinction.
993
+ *
994
+ * Generic over the contract so each family pins a typed contract value
995
+ * at consumption time. The SQL family specialises to
996
+ * `ContractSpace<Contract<SqlStorage>>` at the descriptor surface;
997
+ * Mongo's symmetrical `ContractSpace<Contract<MongoStorage>>` will land
998
+ * with that family.
999
+ *
1000
+ * @see specs/framework-mechanism.spec.md § 1.
1001
+ */
1002
+ interface ContractSpace<TContract extends Contract = Contract> {
1003
+ readonly contractJson: TContract;
1004
+ readonly migrations: readonly MigrationPackage[];
1005
+ readonly headRef: ContractSpaceHeadRef;
1006
+ }
661
1007
  //#endregion
662
- export { type AssembledAuthoringContributions, type BaseSchemaIssue, type ControlAdapterDescriptor, type ControlAdapterInstance, type ControlDriverDescriptor, type ControlDriverInstance, type ControlExtensionDescriptor, type ControlExtensionInstance, type ControlFamilyDescriptor, type ControlFamilyInstance, type ControlMutationDefaultEntry, type ControlMutationDefaultRegistry, type ControlMutationDefaults, type ControlStack, type ControlTargetDescriptor, type ControlTargetInstance, type CoreSchemaView, type CreateControlStackInput, type DataTransformOperation, type DefaultFunctionLoweringContext, type DefaultFunctionLoweringHandler, type DefaultFunctionRegistry, type DefaultFunctionRegistryEntry, type EmitContractResult, type EnumValuesChangedIssue, type IntrospectSchemaResult, type LoweredDefaultResult, type LoweredDefaultValue, type MigratableTargetDescriptor, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanWithAuthoringSurface, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerFailureResult, type MigrationPlannerResult, type MigrationPlannerSuccessResult, type MigrationRunner, type MigrationRunnerExecutionChecks, type MigrationRunnerFailure, type MigrationRunnerResult, type MigrationRunnerSuccessValue, type MigrationScaffoldContext, type MutationDefaultGeneratorDescriptor, type OpFactoryCall, type OperationContext, type ParsedDefaultFunctionCall, type SchemaIssue, type SchemaNodeKind, SchemaTreeNode, type SchemaTreeNodeOptions, type SchemaTreeVisitor, type SchemaVerificationNode, type SchemaViewCapable, type SerializedQueryPlan, type SignDatabaseResult, type SourceDiagnostic, type SourceSpan, type TargetMigrationsCapability, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, assembleAuthoringContributions, assembleControlMutationDefaults, assembleScalarTypeDescriptors, assertUniqueCodecOwner, createControlStack, extractCodecLookup, extractCodecTypeImports, extractComponentIds, extractOperationTypeImports, extractQueryOperationTypeImports, hasMigrations, hasSchemaView };
1008
+ export { APP_SPACE_ID, type AssembledAuthoringContributions, type BaseSchemaIssue, type ContractSpace, type ContractSpaceHeadRef, type ControlAdapterDescriptor, type ControlAdapterInstance, type ControlDriverDescriptor, type ControlDriverInstance, type ControlExtensionDescriptor, type ControlExtensionInstance, type ControlFamilyDescriptor, type ControlFamilyInstance, type ControlMutationDefaultEntry, type ControlMutationDefaultRegistry, type ControlMutationDefaults, type ControlStack, type ControlTargetDescriptor, type ControlTargetInstance, type CoreSchemaView, type CreateControlStackInput, type DefaultFunctionLoweringContext, type DefaultFunctionLoweringHandler, type DefaultFunctionRegistry, type DefaultFunctionRegistryEntry, type EmitContractResult, type EnumValuesChangedIssue, type ImportRequirement, type IntrospectSchemaResult, type LoweredDefaultResult, type LoweredDefaultValue, type MigratableTargetDescriptor, type MigrationHints, type MigrationMetadata, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPackage, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanWithAuthoringSurface, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerFailureResult, type MigrationPlannerResult, type MigrationPlannerSuccessResult, type MigrationRunner, type MigrationRunnerExecutionChecks, type MigrationRunnerFailure, type MigrationRunnerResult, type MigrationRunnerSuccessValue, type MigrationScaffoldContext, type MultiSpaceCapableRunner, type MultiSpaceRunnerFailure, type MultiSpaceRunnerPerSpaceOptions, type MultiSpaceRunnerResult, type MultiSpaceRunnerSuccessValue, type MutationDefaultGeneratorDescriptor, type OpFactoryCall, type OperationContext, type OperationPreview, type OperationPreviewCapable, type OperationPreviewStatement, type ParsedDefaultFunctionCall, type PslContractInferCapable, type SchemaIssue, type SchemaNodeKind, SchemaTreeNode, type SchemaTreeNodeOptions, type SchemaTreeVisitor, type SchemaVerificationNode, type SchemaViewCapable, type SerializedQueryPlan, type SignDatabaseResult, type SourceDiagnostic, type SourceSpan, type TargetMigrationsCapability, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_SCHEMA_FAILURE, VERIFY_CODE_TARGET_MISMATCH, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, assembleAuthoringContributions, assembleControlMutationDefaults, assembleScalarTypeDescriptors, assertUniqueCodecOwner, createControlStack, extractCodecLookup, extractCodecTypeImports, extractComponentIds, extractOperationTypeImports, extractQueryOperationTypeImports, hasMigrations, hasMultiSpaceRunner, hasOperationPreview, hasPslContractInfer, hasSchemaView };
663
1009
  //# sourceMappingURL=control.d.mts.map