@prisma-next/framework-components 0.5.0-dev.7 → 0.5.0-dev.71

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 +63 -3
  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 +370 -72
  13. package/dist/control.d.mts.map +1 -1
  14. package/dist/control.mjs +82 -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-BwWNqTlD.mjs +205 -0
  25. package/dist/framework-authoring-BwWNqTlD.mjs.map +1 -0
  26. package/dist/{framework-authoring-D1-JZ37B.d.mts → framework-authoring-Cm5f9U64.d.mts} +41 -12
  27. package/dist/framework-authoring-Cm5f9U64.d.mts.map +1 -0
  28. package/dist/{framework-components-EJXe-pum.d.mts → framework-components-DgIEy9eJ.d.mts} +45 -55
  29. package/dist/framework-components-DgIEy9eJ.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 +346 -19
  37. package/dist/runtime.d.mts.map +1 -1
  38. package/dist/runtime.mjs +254 -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 +11 -8
  43. package/src/control/control-capabilities.ts +95 -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} +202 -61
  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 +85 -0
  57. package/src/execution/run-with-middleware.ts +132 -0
  58. package/src/execution/runtime-core.ts +133 -0
  59. package/src/execution/runtime-error.ts +83 -0
  60. package/src/execution/runtime-middleware.ts +182 -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 +40 -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 +17 -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} +202 -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-B58nCJiu.d.mts +0 -40
  78. package/dist/codec-types-B58nCJiu.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-EJXe-pum.d.mts.map +0 -1
  84. package/dist/types-import-spec-C4sc7wbb.d.mts.map +0 -1
  85. package/src/codec-types.ts +0 -46
  86. package/src/control-capabilities.ts +0 -34
  87. package/src/emission-types.ts +0 -28
  88. package/src/runtime-error.ts +0 -39
  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,2 +1,2 @@
1
- import { S as checkContractComponentRequirements, _ as PackRefBase, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, g as FamilyPackRef, h as FamilyInstance, i as ComponentDescriptor, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, o as ContractComponentRequirementsCheckInput, p as ExtensionPackRef, r as AdapterPackRef, s as ContractComponentRequirementsCheckResult, t as AdapterDescriptor, u as DriverPackRef, v as TargetBoundComponentDescriptor, x as TargetPackRef, y as TargetDescriptor } from "./framework-components-EJXe-pum.mjs";
1
+ import { S as checkContractComponentRequirements, _ as PackRefBase, a as ComponentMetadata, b as TargetInstance, c as DriverDescriptor, d as ExtensionDescriptor, f as ExtensionInstance, g as FamilyPackRef, h as FamilyInstance, i as ComponentDescriptor, l as DriverInstance, m as FamilyDescriptor, n as AdapterInstance, o as ContractComponentRequirementsCheckInput, p as ExtensionPackRef, r as AdapterPackRef, s as ContractComponentRequirementsCheckResult, t as AdapterDescriptor, u as DriverPackRef, v as TargetBoundComponentDescriptor, x as TargetPackRef, y as TargetDescriptor } from "./framework-components-DgIEy9eJ.mjs";
2
2
  export { type AdapterDescriptor, type AdapterInstance, type AdapterPackRef, type ComponentDescriptor, type ComponentMetadata, type ContractComponentRequirementsCheckInput, type ContractComponentRequirementsCheckResult, type DriverDescriptor, type DriverInstance, type DriverPackRef, type ExtensionDescriptor, type ExtensionInstance, type ExtensionPackRef, type FamilyDescriptor, type FamilyInstance, type FamilyPackRef, type PackRefBase, type TargetBoundComponentDescriptor, type TargetDescriptor, type TargetInstance, type TargetPackRef, checkContractComponentRequirements };
@@ -1,3 +1,2 @@
1
- import { t as checkContractComponentRequirements } from "./framework-components-C8ZhSwXe.mjs";
2
-
3
- export { checkContractComponentRequirements };
1
+ import { t as checkContractComponentRequirements } from "./framework-components-FdqmlGUj.mjs";
2
+ export { checkContractComponentRequirements };
@@ -1,12 +1,13 @@
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-B58nCJiu.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-EJXe-pum.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-Cm5f9U64.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-DgIEy9eJ.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";
7
8
  import { Result } from "@prisma-next/utils/result";
8
9
 
9
- //#region src/control-result-types.d.ts
10
+ //#region src/control/control-result-types.d.ts
10
11
  declare const VERIFY_CODE_MARKER_MISSING = "PN-RUN-3001";
11
12
  declare const VERIFY_CODE_HASH_MISMATCH = "PN-RUN-3002";
12
13
  declare const VERIFY_CODE_TARGET_MISMATCH = "PN-RUN-3003";
@@ -154,7 +155,7 @@ interface SignDatabaseResult {
154
155
  };
155
156
  }
156
157
  //#endregion
157
- //#region src/control-instances.d.ts
158
+ //#region src/control/control-instances.d.ts
158
159
  interface ControlFamilyInstance<TFamilyId extends string, TSchemaIR> extends FamilyInstance<TFamilyId> {
159
160
  validateContract(contractJson: unknown): Contract;
160
161
  verify(options: {
@@ -172,15 +173,59 @@ interface ControlFamilyInstance<TFamilyId extends string, TSchemaIR> extends Fam
172
173
  readonly configPath?: string;
173
174
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, string>>;
174
175
  }): Promise<VerifyDatabaseSchemaResult>;
176
+ /**
177
+ * Verify a contract against an already-introspected schema slice.
178
+ *
179
+ * Difference from {@link schemaVerify}: no `driver`, no introspection
180
+ * — the caller hands over the schema directly. Used by the aggregate
181
+ * verifier to invoke the family's verification logic per member,
182
+ * with the schema **pre-projected** to that member's claimed slice
183
+ * via {@link import('@prisma-next/migration-tools/aggregate').projectSchemaToSpace}.
184
+ *
185
+ * Synchronous — no I/O. Idempotent.
186
+ */
187
+ schemaVerifyAgainstSchema(options: {
188
+ readonly contract: unknown;
189
+ readonly schema: TSchemaIR;
190
+ readonly strict: boolean;
191
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, string>>;
192
+ }): VerifyDatabaseSchemaResult;
175
193
  sign(options: {
176
194
  readonly driver: ControlDriverInstance<TFamilyId, string>;
177
195
  readonly contract: unknown;
178
196
  readonly contractPath: string;
179
197
  readonly configPath?: string;
180
198
  }): Promise<SignDatabaseResult>;
199
+ /**
200
+ * Reads the contract marker for `space` from the database, returning
201
+ * `null` if no marker row exists for that space (or if the marker
202
+ * table itself is missing).
203
+ *
204
+ * `space` is required at every call site so the type system surfaces
205
+ * every place that needs to thread the value: callers in single-app
206
+ * paths pass {@link import('./control-spaces').APP_SPACE_ID}
207
+ * (`'app'`); per-extension callers pass the extension's space id.
208
+ * Defaulting at the family-interface level was a silent bug door —
209
+ * it let multi-space-aware callers forget to pass `space` and
210
+ * collapse onto the app's marker row.
211
+ *
212
+ * Families whose underlying storage doesn't yet support per-space
213
+ * markers (Mongo, today) accept `space` for interface conformance and
214
+ * reject any non-`APP_SPACE_ID` value rather than silently ignoring
215
+ * it; see the family-specific implementation for details.
216
+ */
181
217
  readMarker(options: {
182
218
  readonly driver: ControlDriverInstance<TFamilyId, string>;
219
+ readonly space: string;
183
220
  }): Promise<ContractMarkerRecord | null>;
221
+ /**
222
+ * Reads every marker row keyed by `space`. Used by the per-space
223
+ * verifier to detect orphan marker rows and marker-vs-on-disk drift.
224
+ * Returns an empty map when the marker table does not yet exist.
225
+ */
226
+ readAllMarkers(options: {
227
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
228
+ }): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
184
229
  introspect(options: {
185
230
  readonly driver: ControlDriverInstance<TFamilyId, string>;
186
231
  readonly contract?: unknown;
@@ -196,7 +241,7 @@ interface ControlDriverInstance<TFamilyId extends string, TTargetId extends stri
196
241
  }
197
242
  interface ControlExtensionInstance<TFamilyId extends string, TTargetId extends string> extends ExtensionInstance<TFamilyId, TTargetId> {}
198
243
  //#endregion
199
- //#region src/control-stack.d.ts
244
+ //#region src/control/control-stack.d.ts
200
245
  interface AssembledAuthoringContributions {
201
246
  readonly field: AuthoringFieldNamespace;
202
247
  readonly type: AuthoringTypeNamespace;
@@ -252,11 +297,11 @@ declare function assembleControlMutationDefaults(descriptors: ReadonlyArray<Pick
252
297
  readonly id?: string;
253
298
  }>): ControlMutationDefaults;
254
299
  declare function extractCodecLookup(descriptors: ReadonlyArray<Pick<ComponentMetadata & {
255
- id?: string;
300
+ id: string;
256
301
  }, 'types' | 'id'>>): CodecLookup;
257
302
  declare function createControlStack<TFamilyId extends string, TTargetId extends string>(input: CreateControlStackInput<TFamilyId, TTargetId>): ControlStack<TFamilyId, TTargetId>;
258
303
  //#endregion
259
- //#region src/control-descriptors.d.ts
304
+ //#region src/control/control-descriptors.d.ts
260
305
  interface ControlFamilyDescriptor<TFamilyId extends string, TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<TFamilyId, unknown>> extends FamilyDescriptor<TFamilyId> {
261
306
  readonly emission: EmissionSpi;
262
307
  create<TTargetId extends string>(stack: ControlStack<TFamilyId, TTargetId>): TFamilyInstance;
@@ -281,7 +326,62 @@ interface ControlExtensionDescriptor<TFamilyId extends string, TTargetId extends
281
326
  create(): TExtensionInstance;
282
327
  }
283
328
  //#endregion
284
- //#region src/control-migration-types.d.ts
329
+ //#region src/control/control-migration-types.d.ts
330
+ /**
331
+ * Planner provenance recorded inside {@link MigrationMetadata}.
332
+ *
333
+ * `used` / `applied` track which migration hints the planner consulted
334
+ * vs. which it actually applied during emission; `plannerVersion`
335
+ * pins the planner build that produced the migration so future
336
+ * verification passes can recognise plans authored against an older
337
+ * planner.
338
+ */
339
+ interface MigrationHints {
340
+ readonly used: readonly string[];
341
+ readonly applied: readonly string[];
342
+ readonly plannerVersion: string;
343
+ }
344
+ /**
345
+ * In-memory migration metadata envelope. Every migration is
346
+ * content-addressed: the `migrationHash` is a hash over the metadata
347
+ * envelope plus the operations list, computed at write time. There is no
348
+ * draft state — a migration directory either exists with fully attested
349
+ * metadata or it does not.
350
+ *
351
+ * When the planner cannot lower an operation because of an unfilled
352
+ * `placeholder(...)` slot, the migration is still written with
353
+ * `migrationHash` hashed over `ops: []`. Re-running self-emit after the
354
+ * user fills the placeholder produces a *different* `migrationHash`
355
+ * (committed to the real ops); this is intentional.
356
+ *
357
+ * The on-disk JSON shape in `migration.json` matches this type
358
+ * field-for-field — `JSON.stringify(metadata, null, 2)` is the canonical
359
+ * writer output (defined in `@prisma-next/migration-tools/io`).
360
+ */
361
+ interface MigrationMetadata {
362
+ readonly migrationHash: string;
363
+ readonly from: string | null;
364
+ readonly to: string;
365
+ readonly fromContract: Contract | null;
366
+ readonly toContract: Contract;
367
+ readonly hints: MigrationHints;
368
+ readonly labels: readonly string[];
369
+ /**
370
+ * Sorted, deduplicated list of `invariantId`s declared by the
371
+ * migration's data-transform ops. Always present; an empty array
372
+ * means the migration has no routing-visible data transforms.
373
+ */
374
+ readonly providedInvariants: readonly string[];
375
+ readonly authorship?: {
376
+ readonly author?: string;
377
+ readonly email?: string;
378
+ };
379
+ readonly signature?: {
380
+ readonly keyId: string;
381
+ readonly value: string;
382
+ } | null;
383
+ readonly createdAt: string;
384
+ }
285
385
  /**
286
386
  * Migration operation classes define the safety level of an operation.
287
387
  * - 'additive': Adds new structures without modifying existing ones (safe)
@@ -294,52 +394,15 @@ type MigrationOperationClass = 'additive' | 'widening' | 'destructive' | 'data';
294
394
  * A lowered query statement as stored in ops.json.
295
395
  * Contains the SQL string and parameter values — ready for execution.
296
396
  * Lowering from query builder AST to SQL happens at verify time.
397
+ *
398
+ * The Postgres `dataTransform` factory uses this shape internally to
399
+ * carry the user's lowered `check`/`run` plans before wrapping them
400
+ * into precheck/execute/postcheck steps on the unified migration op.
297
401
  */
298
402
  interface SerializedQueryPlan {
299
403
  readonly sql: string;
300
404
  readonly params: readonly unknown[];
301
405
  }
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
406
  /**
344
407
  * Policy defining which operation classes are allowed during a migration.
345
408
  */
@@ -357,6 +420,17 @@ interface MigrationPlanOperation {
357
420
  readonly label: string;
358
421
  /** The class of operation (additive, widening, destructive). */
359
422
  readonly operationClass: MigrationOperationClass;
423
+ /**
424
+ * Optional opt-in routing identity for data-transform operations.
425
+ * Presence opts the transform into invariant-aware routing; absence
426
+ * means it is path-dependent and not referenceable from refs.
427
+ *
428
+ * Lives on the base op so the manifest emitter and
429
+ * `deriveProvidedInvariants` can read it without depending on a
430
+ * target-specific shape. Schema-DDL ops (additive / widening /
431
+ * destructive) leave it undefined.
432
+ */
433
+ readonly invariantId?: string;
360
434
  }
361
435
  /**
362
436
  * Framework-level contract for a single factory call in a target's planner IR.
@@ -378,6 +452,16 @@ interface OpFactoryCall {
378
452
  interface MigrationPlan {
379
453
  /** The target ID this plan is for (e.g., 'postgres'). */
380
454
  readonly targetId: string;
455
+ /**
456
+ * Contract space this plan applies to. Runners cross-check
457
+ * `options.space` against `plan.spaceId` so the marker row gets keyed
458
+ * by the right space when applying via `executeAcrossSpaces`.
459
+ *
460
+ * Optional for backward compatibility with single-space callers that
461
+ * pre-date the contract-space aggregate; when present, runners
462
+ * enforce that it matches `options.space`.
463
+ */
464
+ readonly spaceId?: string;
381
465
  /**
382
466
  * Origin contract identity that the plan expects the database to currently be at.
383
467
  * If omitted or null, the runner skips origin validation entirely.
@@ -393,6 +477,17 @@ interface MigrationPlan {
393
477
  };
394
478
  /** Ordered list of operations to execute. */
395
479
  readonly operations: readonly MigrationPlanOperation[];
480
+ /**
481
+ * Sorted, deduplicated invariant ids declared by this plan's data-transform
482
+ * ops. Authored migrations carry the canonical value from
483
+ * `migration.json.providedInvariants`; planner-built plans (`db init`,
484
+ * `db update`) omit it (the runner treats it as `[]`). Runners read this
485
+ * field for marker writes and self-edge no-op detection rather than
486
+ * re-deriving from `operations`, since the manifest is the canonical
487
+ * source for the invariant set across all runners (postgres, sqlite,
488
+ * mongo).
489
+ */
490
+ readonly providedInvariants?: readonly string[];
396
491
  }
397
492
  /**
398
493
  * A migration plan that can also render itself back to user-editable
@@ -502,27 +597,36 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
502
597
  readonly contract: unknown;
503
598
  readonly schema: unknown;
504
599
  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
600
  /**
513
601
  * 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.
602
+ * at), or `null` for a baseline plan with no prior state.
603
+ *
604
+ * Planners derive any "from" identity they need to stamp onto the
605
+ * produced plan's `describe()` from `fromContract?.storage.storageHash
606
+ * ?? null`. They also pass this to data-safety strategies so they can
607
+ * compare `from` and `to` column shapes (e.g. to detect unsafe type
608
+ * changes).
609
+ *
610
+ * Required at every call site to make the structural fact "I have a
611
+ * prior contract / I don't" visible in the type. Reconciliation
612
+ * commands (`db init`, `db update`) introspect a live schema and pass
613
+ * `null`; authoring commands (`migration plan`) pass the previous
614
+ * bundle's `metadata.toContract`.
518
615
  */
519
- readonly fromContract?: unknown;
616
+ readonly fromContract: Contract | null;
520
617
  /**
521
618
  * Active framework components participating in this composition.
522
619
  * Families/targets can interpret this list to derive family-specific metadata.
523
620
  * All components must have matching familyId and targetId.
524
621
  */
525
622
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
623
+ /**
624
+ * Contract space this plan applies to. Stamped onto the produced
625
+ * plan so the runner keys the marker row by the right space when
626
+ * executing. App-plan callers pass `APP_SPACE_ID` (`'app'`);
627
+ * per-extension callers pass the extension's space id.
628
+ */
629
+ readonly spaceId: string;
526
630
  }): MigrationPlannerResult;
527
631
  /**
528
632
  * Produce an empty migration with the target's authoring conventions.
@@ -530,8 +634,12 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
530
634
  * Used by `migration new` to scaffold a fresh `migration.ts`. The
531
635
  * returned plan has no operations; its `renderTypeScript()` yields a
532
636
  * stub the user can edit.
637
+ *
638
+ * `spaceId` is stamped onto the produced plan; reconciliation flows
639
+ * (`db init`, `db update`) and authoring flows (`migration new`) all
640
+ * pass it explicitly.
533
641
  */
534
- emptyMigration(context: MigrationScaffoldContext): MigrationPlanWithAuthoringSurface;
642
+ emptyMigration(context: MigrationScaffoldContext, spaceId: string): MigrationPlanWithAuthoringSurface;
535
643
  }
536
644
  /**
537
645
  * Migration runner interface for executing migration plans.
@@ -541,6 +649,16 @@ interface MigrationPlanner<TFamilyId extends string = string, TTargetId extends
541
649
  * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
542
650
  */
543
651
  interface MigrationRunner<TFamilyId extends string = string, TTargetId extends string = string> {
652
+ /**
653
+ * Execute a migration plan against the configured driver.
654
+ *
655
+ * The `plan` parameter is trusted input. Callers are responsible for
656
+ * upstream verification of the originating migration package — typically
657
+ * by obtaining the package via `readMigrationPackage` from
658
+ * `@prisma-next/migration-tools/io`, which performs hash-integrity checks
659
+ * at the load boundary. Runners do not re-verify the plan and assume the
660
+ * `(metadata, ops)` pair on disk has not been tampered with since emit.
661
+ */
544
662
  execute(options: {
545
663
  readonly plan: MigrationPlan;
546
664
  readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
@@ -563,6 +681,56 @@ interface MigrationRunner<TFamilyId extends string = string, TTargetId extends s
563
681
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
564
682
  }): Promise<MigrationRunnerResult>;
565
683
  }
684
+ /**
685
+ * Per-space input for {@link MultiSpaceCapableRunner.executeAcrossSpaces}.
686
+ *
687
+ * Mirrors the single-space `MigrationRunner.execute` options, extended with a
688
+ * required `space` identifier. Each entry's `driver` must reference the same
689
+ * connection the outer transaction is opened on (typically the same value as
690
+ * the top-level `driver` on `executeAcrossSpaces`).
691
+ *
692
+ * Family-specific runners (e.g. the SQL family's `SqlMigrationRunner`) define
693
+ * a richer per-space option shape that is structurally compatible with this
694
+ * one — additional optional fields (e.g. SQL's `strictVerification`,
695
+ * `schemaName`, `callbacks`) are tolerated by the underlying runner without
696
+ * affecting cross-target wiring.
697
+ */
698
+ interface MultiSpaceRunnerPerSpaceOptions<TFamilyId extends string = string, TTargetId extends string = string> {
699
+ readonly space: string;
700
+ readonly plan: MigrationPlan;
701
+ readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
702
+ readonly destinationContract: unknown;
703
+ readonly policy: MigrationOperationPolicy;
704
+ readonly executionChecks?: MigrationRunnerExecutionChecks;
705
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
706
+ }
707
+ interface MultiSpaceRunnerSuccessValue {
708
+ readonly perSpaceResults: ReadonlyArray<{
709
+ readonly space: string;
710
+ readonly value: MigrationRunnerSuccessValue;
711
+ }>;
712
+ }
713
+ interface MultiSpaceRunnerFailure extends MigrationRunnerFailure {
714
+ /** Identifier of the space whose plan caused the rollback. */
715
+ readonly failingSpace: string;
716
+ }
717
+ type MultiSpaceRunnerResult = Result<MultiSpaceRunnerSuccessValue, MultiSpaceRunnerFailure>;
718
+ /**
719
+ * Optional capability for runners that can apply a list of per-space plans
720
+ * inside a single outer transaction. A failure on any space rolls back every
721
+ * space's writes.
722
+ *
723
+ * Today's only implementer is the SQL family (`SqlMigrationRunner`); Mongo
724
+ * per-space is a non-goal per the project spec. The capability is declared
725
+ * at the framework layer so CLI utilities can route through it without
726
+ * importing the SQL family directly.
727
+ */
728
+ interface MultiSpaceCapableRunner<TFamilyId extends string = string, TTargetId extends string = string> {
729
+ executeAcrossSpaces(options: {
730
+ readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
731
+ readonly perSpaceOptions: ReadonlyArray<MultiSpaceRunnerPerSpaceOptions<TFamilyId, TTargetId>>;
732
+ }): Promise<MultiSpaceRunnerResult>;
733
+ }
566
734
  /**
567
735
  * Optional capability interface for targets that support migrations.
568
736
  * Targets that implement migrations expose this via their descriptor.
@@ -598,11 +766,12 @@ interface MigrationScaffoldContext {
598
766
  /** Absolute path to the contract.json file, if one exists. Used by targets that emit typed-contract imports. */
599
767
  readonly contractJsonPath?: string;
600
768
  /**
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.
769
+ * Storage hash of the "from" contract, or `null` for a baseline scaffold
770
+ * with no prior state. Targets use this to populate `describe()` on the
771
+ * rendered empty migration so that identity metadata is correctly
772
+ * populated.
604
773
  */
605
- readonly fromHash: string;
774
+ readonly fromHash: string | null;
606
775
  /**
607
776
  * Storage hash of the "to" contract. Same purpose as `fromHash` — threaded
608
777
  * through so the rendered class's `describe()` declares the correct
@@ -611,7 +780,30 @@ interface MigrationScaffoldContext {
611
780
  readonly toHash: string;
612
781
  }
613
782
  //#endregion
614
- //#region src/control-schema-view.d.ts
783
+ //#region src/control/control-operation-preview.d.ts
784
+ /**
785
+ * Family-agnostic textual preview of a migration plan, used by the CLI to
786
+ * render a "DDL preview" section for `db init` / `db update` / `migration plan`
787
+ * / `migration show`. Each statement carries a free-form `language` tag so
788
+ * formatters can suffix `;` for SQL but render Mongo shell lines verbatim.
789
+ *
790
+ * Producers are family-specific: SQL emits `language: 'sql'` (existing DDL
791
+ * extraction); Mongo emits `language: 'mongodb-shell'` via the
792
+ * `MongoDdlCommandFormatter` visitor.
793
+ *
794
+ * The capability `OperationPreviewCapable` (declared in
795
+ * `./control-capabilities`) is how a family announces it can produce these.
796
+ */
797
+ interface OperationPreviewStatement {
798
+ readonly text: string;
799
+ /** Dialect identifier, e.g. `'sql'`, `'mongodb-shell'`. Free-form by design (OQ-3). */
800
+ readonly language: string;
801
+ }
802
+ interface OperationPreview {
803
+ readonly statements: readonly OperationPreviewStatement[];
804
+ }
805
+ //#endregion
806
+ //#region src/control/control-schema-view.d.ts
615
807
  /**
616
808
  * Core schema view types for family-agnostic schema visualization.
617
809
  *
@@ -649,7 +841,7 @@ interface CoreSchemaView {
649
841
  readonly root: SchemaTreeNode;
650
842
  }
651
843
  //#endregion
652
- //#region src/control-capabilities.d.ts
844
+ //#region src/control/control-capabilities.d.ts
653
845
  interface MigratableTargetDescriptor<TFamilyId extends string, TTargetId extends string, TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<TFamilyId, unknown>> extends ControlTargetDescriptor<TFamilyId, TTargetId> {
654
846
  readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, TFamilyInstance>;
655
847
  }
@@ -658,6 +850,112 @@ interface SchemaViewCapable<TSchemaIR = unknown> {
658
850
  toSchemaView(schema: TSchemaIR): CoreSchemaView;
659
851
  }
660
852
  declare function hasSchemaView<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & SchemaViewCapable<TSchemaIR>;
853
+ /**
854
+ * Capability declaring that a family can infer a PSL contract AST from its
855
+ * opaque introspected schema IR. Consumed by `prisma-next contract infer`.
856
+ */
857
+ interface PslContractInferCapable<TSchemaIR = unknown> {
858
+ inferPslContract(schemaIR: TSchemaIR): PslDocumentAst;
859
+ }
860
+ declare function hasPslContractInfer<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & PslContractInferCapable<TSchemaIR>;
861
+ /**
862
+ * Capability declaring that a family can render a textual preview of migration
863
+ * operations for the CLI's "DDL preview" output. SQL families emit
864
+ * `language: 'sql'` statements; Mongo families emit `language: 'mongodb-shell'`.
865
+ */
866
+ interface OperationPreviewCapable {
867
+ toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;
868
+ }
869
+ declare function hasOperationPreview<TFamilyId extends string, TSchemaIR>(instance: ControlFamilyInstance<TFamilyId, TSchemaIR>): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & OperationPreviewCapable;
870
+ /**
871
+ * Capability declaring that a runner can apply per-space plans inside a
872
+ * single outer transaction. Today's only implementer is the SQL family
873
+ * (`SqlMigrationRunner`); Mongo per-space is a non-goal per the project
874
+ * spec for extension contract spaces (TML-2397).
875
+ *
876
+ * The CLI uses this guard to route `db init` / `db update` through a
877
+ * per-space wiring when extensions expose a `contractSpace`, falling back
878
+ * to the single-space path when no multi-space capability is present.
879
+ */
880
+ declare function hasMultiSpaceRunner<TFamilyId extends string, TTargetId extends string>(runner: MigrationRunner<TFamilyId, TTargetId>): runner is MigrationRunner<TFamilyId, TTargetId> & MultiSpaceCapableRunner<TFamilyId, TTargetId>;
881
+ //#endregion
882
+ //#region src/control/control-spaces.d.ts
883
+ /**
884
+ * Canonical control-plane identifiers for contract spaces.
885
+ *
886
+ * A contract space is the disjoint `(contract.json, migration-graph)` unit
887
+ * the per-space planner / runner / verifier (project: extension contract
888
+ * spaces, TML-2397) operates on. The application owns one well-known
889
+ * space — the value below — and each loaded extension that contributes
890
+ * schema owns a uniquely-named space.
891
+ *
892
+ * Lives in `framework-components/control` so every layer that has to
893
+ * reason about space identity (the migration tooling, the SQL runtime's
894
+ * marker reader, target-side statement builders, target-side adapters)
895
+ * can import a single value rather than duplicating the literal. Raw
896
+ * `'app'` string literals in framework / target / runtime / adapter
897
+ * source code are forbidden and policed by
898
+ * `scripts/lint-app-space-id.mjs` (wired into `pnpm lint:deps`).
899
+ *
900
+ * @see specs/framework-mechanism.spec.md § 3 — Layout convention (γ).
901
+ */
902
+ declare const APP_SPACE_ID: "app";
903
+ /**
904
+ * Head ref for a contract space — the `(hash, invariants)` tuple
905
+ * a runner targets when applying that space's migration graph. Identical
906
+ * in shape to the on-disk `migrations/<space-id>/refs/head.json` the
907
+ * framework writes per loaded extension, and to the app-space
908
+ * `<projectRoot>/refs/head.json`. Family-agnostic: SQL, Mongo, and any
909
+ * future family share the same head-ref shape.
910
+ *
911
+ * @see specs/framework-mechanism.spec.md § 1.
912
+ */
913
+ interface ContractSpaceHeadRef {
914
+ readonly hash: string;
915
+ readonly invariants: readonly string[];
916
+ }
917
+ /**
918
+ * Canonical structural shape of a migration package — the unit a planner
919
+ * produces and a runner consumes: a directory name, the ADR 197 metadata
920
+ * envelope (which carries the `toContract` snapshot), and the operation
921
+ * list.
922
+ *
923
+ * In-memory by default. Readers in `@prisma-next/migration-tools`
924
+ * (`readMigrationPackage` / `readMigrationsDir`) return the augmented
925
+ * {@link import('@prisma-next/migration-tools/package').OnDiskMigrationPackage}
926
+ * variant which adds `dirPath`; everything else operates against the
927
+ * canonical shape so the same value flows through pre-emission
928
+ * authoring, on-disk loading, and runner execution without conversion.
929
+ *
930
+ * @see specs/framework-mechanism.spec.md § 1.
931
+ */
932
+ interface MigrationPackage {
933
+ readonly dirName: string;
934
+ readonly metadata: MigrationMetadata;
935
+ readonly ops: readonly MigrationPlanOperation[];
936
+ }
937
+ /**
938
+ * Canonical structural shape of a contract space — one disjoint
939
+ * `(contractJson, migration-graph)` unit the per-space planner / runner
940
+ * / verifier operates on. The application owns one well-known space
941
+ * ({@link APP_SPACE_ID}); each loaded extension that contributes schema
942
+ * owns a uniquely-named space. Whether a value is the app's space or an
943
+ * extension's space is a control-plane concern; the type carries no
944
+ * such distinction.
945
+ *
946
+ * Generic over the contract so each family pins a typed contract value
947
+ * at consumption time. The SQL family specialises to
948
+ * `ContractSpace<Contract<SqlStorage>>` at the descriptor surface;
949
+ * Mongo's symmetrical `ContractSpace<Contract<MongoStorage>>` will land
950
+ * with that family.
951
+ *
952
+ * @see specs/framework-mechanism.spec.md § 1.
953
+ */
954
+ interface ContractSpace<TContract extends Contract = Contract> {
955
+ readonly contractJson: TContract;
956
+ readonly migrations: readonly MigrationPackage[];
957
+ readonly headRef: ContractSpaceHeadRef;
958
+ }
661
959
  //#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 };
960
+ 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 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
961
  //# sourceMappingURL=control.d.mts.map