@prisma-next/core-control-plane 0.1.0-dev.16 → 0.1.0-dev.17

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.
@@ -2,6 +2,7 @@ import { ControlFamilyDescriptor, ControlTargetDescriptor, ControlAdapterDescrip
2
2
  import '@prisma-next/contract/ir';
3
3
  import '@prisma-next/contract/pack-manifest-types';
4
4
  import '@prisma-next/contract/types';
5
+ import '@prisma-next/utils/result';
5
6
  import './schema-view.js';
6
7
 
7
8
  /**
@@ -3,6 +3,7 @@ import './types.js';
3
3
  import '@prisma-next/contract/ir';
4
4
  import '@prisma-next/contract/pack-manifest-types';
5
5
  import '@prisma-next/contract/types';
6
+ import '@prisma-next/utils/result';
6
7
  import './schema-view.js';
7
8
 
8
9
  /**
@@ -1,8 +1,149 @@
1
1
  import { ContractIR } from '@prisma-next/contract/ir';
2
2
  import { ExtensionPackManifest } from '@prisma-next/contract/pack-manifest-types';
3
3
  import { TargetFamilyHook } from '@prisma-next/contract/types';
4
+ import { Result } from '@prisma-next/utils/result';
4
5
  import { CoreSchemaView } from './schema-view.js';
5
6
 
7
+ /**
8
+ * Core migration types for the framework control plane.
9
+ *
10
+ * These are family-agnostic, display-oriented types that provide a stable
11
+ * vocabulary for CLI commands to work with migration planners and runners
12
+ * without importing family-specific types.
13
+ *
14
+ * Family-specific types (e.g., SqlMigrationPlan) extend these base types
15
+ * with additional fields for execution (precheck SQL, execute SQL, etc.).
16
+ */
17
+
18
+ /**
19
+ * Migration operation classes define the safety level of an operation.
20
+ * - 'additive': Adds new structures without modifying existing ones (safe)
21
+ * - 'widening': Relaxes constraints or expands types (generally safe)
22
+ * - 'destructive': Removes or alters existing structures (potentially unsafe)
23
+ */
24
+ type MigrationOperationClass = 'additive' | 'widening' | 'destructive';
25
+ /**
26
+ * Policy defining which operation classes are allowed during a migration.
27
+ */
28
+ interface MigrationOperationPolicy {
29
+ readonly allowedOperationClasses: readonly MigrationOperationClass[];
30
+ }
31
+ /**
32
+ * A single migration operation for display purposes.
33
+ * Contains only the fields needed for CLI output (tree view, JSON envelope).
34
+ */
35
+ interface MigrationPlanOperation {
36
+ /** Unique identifier for this operation (e.g., "table.users.create"). */
37
+ readonly id: string;
38
+ /** Human-readable label for display in UI/CLI (e.g., "Create table users"). */
39
+ readonly label: string;
40
+ /** The class of operation (additive, widening, destructive). */
41
+ readonly operationClass: MigrationOperationClass;
42
+ }
43
+ /**
44
+ * A migration plan for display purposes.
45
+ * Contains only the fields needed for CLI output (summary, JSON envelope).
46
+ */
47
+ interface MigrationPlan {
48
+ /** The target ID this plan is for (e.g., 'postgres'). */
49
+ readonly targetId: string;
50
+ /** Destination contract identity that the plan intends to reach. */
51
+ readonly destination: {
52
+ readonly coreHash: string;
53
+ readonly profileHash?: string;
54
+ };
55
+ /** Ordered list of operations to execute. */
56
+ readonly operations: readonly MigrationPlanOperation[];
57
+ }
58
+ /**
59
+ * A conflict detected during migration planning.
60
+ */
61
+ interface MigrationPlannerConflict {
62
+ /** Kind of conflict (e.g., 'typeMismatch', 'nullabilityConflict'). */
63
+ readonly kind: string;
64
+ /** Human-readable summary of the conflict. */
65
+ readonly summary: string;
66
+ /** Optional explanation of why this conflict occurred. */
67
+ readonly why?: string;
68
+ }
69
+ /**
70
+ * Successful planner result with the migration plan.
71
+ */
72
+ interface MigrationPlannerSuccessResult {
73
+ readonly kind: 'success';
74
+ readonly plan: MigrationPlan;
75
+ }
76
+ /**
77
+ * Failed planner result with the list of conflicts.
78
+ */
79
+ interface MigrationPlannerFailureResult {
80
+ readonly kind: 'failure';
81
+ readonly conflicts: readonly MigrationPlannerConflict[];
82
+ }
83
+ /**
84
+ * Union type for planner results.
85
+ */
86
+ type MigrationPlannerResult = MigrationPlannerSuccessResult | MigrationPlannerFailureResult;
87
+ /**
88
+ * Success value for migration runner execution.
89
+ */
90
+ interface MigrationRunnerSuccessValue {
91
+ readonly operationsPlanned: number;
92
+ readonly operationsExecuted: number;
93
+ }
94
+ /**
95
+ * Failure details for migration runner execution.
96
+ */
97
+ interface MigrationRunnerFailure {
98
+ /** Error code for the failure. */
99
+ readonly code: string;
100
+ /** Human-readable summary of the failure. */
101
+ readonly summary: string;
102
+ /** Optional explanation of why the failure occurred. */
103
+ readonly why?: string;
104
+ }
105
+ /**
106
+ * Result type for migration runner execution.
107
+ */
108
+ type MigrationRunnerResult = Result<MigrationRunnerSuccessValue, MigrationRunnerFailure>;
109
+ /**
110
+ * Migration planner interface for planning schema changes.
111
+ * This is the minimal interface that CLI commands use.
112
+ */
113
+ interface MigrationPlanner {
114
+ plan(options: {
115
+ readonly contract: unknown;
116
+ readonly schema: unknown;
117
+ readonly policy: MigrationOperationPolicy;
118
+ }): MigrationPlannerResult;
119
+ }
120
+ /**
121
+ * Migration runner interface for executing migration plans.
122
+ * This is the minimal interface that CLI commands use.
123
+ */
124
+ interface MigrationRunner {
125
+ execute(options: {
126
+ readonly plan: MigrationPlan;
127
+ readonly driver: ControlDriverInstance;
128
+ readonly destinationContract: unknown;
129
+ readonly policy: MigrationOperationPolicy;
130
+ readonly callbacks?: {
131
+ onOperationStart?(op: MigrationPlanOperation): void;
132
+ onOperationComplete?(op: MigrationPlanOperation): void;
133
+ };
134
+ }): Promise<MigrationRunnerResult>;
135
+ }
136
+ /**
137
+ * Optional capability interface for targets that support migrations.
138
+ * Targets that implement migrations expose this via their descriptor.
139
+ *
140
+ * @template TFamilyInstance - The family instance type (e.g., SqlControlFamilyInstance)
141
+ */
142
+ interface TargetMigrationsCapability<TFamilyInstance extends ControlFamilyInstance<string> = ControlFamilyInstance<string>> {
143
+ createPlanner(family: TFamilyInstance): MigrationPlanner;
144
+ createRunner(family: TFamilyInstance): MigrationRunner;
145
+ }
146
+
6
147
  /**
7
148
  * Base interface for control-plane family instances.
8
149
  * Families extend this with domain-specific methods.
@@ -117,13 +258,19 @@ interface ControlFamilyDescriptor<TFamilyId extends string, TFamilyInstance exte
117
258
  * @template TFamilyId - The family ID (e.g., 'sql', 'document')
118
259
  * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
119
260
  * @template TTargetInstance - The target instance type
261
+ * @template TFamilyInstance - The family instance type for migrations (optional)
120
262
  */
121
- interface ControlTargetDescriptor<TFamilyId extends string, TTargetId extends string, TTargetInstance extends ControlTargetInstance<TFamilyId, TTargetId> = ControlTargetInstance<TFamilyId, TTargetId>> {
263
+ interface ControlTargetDescriptor<TFamilyId extends string, TTargetId extends string, TTargetInstance extends ControlTargetInstance<TFamilyId, TTargetId> = ControlTargetInstance<TFamilyId, TTargetId>, TFamilyInstance extends ControlFamilyInstance<TFamilyId> = ControlFamilyInstance<TFamilyId>> {
122
264
  readonly kind: 'target';
123
265
  readonly id: string;
124
266
  readonly familyId: TFamilyId;
125
267
  readonly targetId: TTargetId;
126
268
  readonly manifest: ExtensionPackManifest;
269
+ /**
270
+ * Optional migrations capability.
271
+ * Targets that support migrations expose this property.
272
+ */
273
+ readonly migrations?: TargetMigrationsCapability<TFamilyInstance>;
127
274
  create(): TTargetInstance;
128
275
  }
129
276
  /**
@@ -403,4 +550,4 @@ interface SignDatabaseResult {
403
550
  };
404
551
  }
405
552
 
406
- export type { ControlAdapterDescriptor, ControlAdapterInstance, ControlDriverDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlExtensionInstance, ControlFamilyDescriptor, ControlFamilyInstance, ControlTargetDescriptor, ControlTargetInstance, EmitContractResult, FamilyInstance, IntrospectSchemaResult, OperationContext, SchemaIssue, SchemaVerificationNode, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult };
553
+ export type { ControlAdapterDescriptor, ControlAdapterInstance, ControlDriverDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlExtensionInstance, ControlFamilyDescriptor, ControlFamilyInstance, ControlTargetDescriptor, ControlTargetInstance, EmitContractResult, FamilyInstance, IntrospectSchemaResult, MigrationOperationClass, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerResult, MigrationPlannerSuccessResult, MigrationRunner, MigrationRunnerFailure, MigrationRunnerResult, MigrationRunnerSuccessValue, OperationContext, SchemaIssue, SchemaVerificationNode, SignDatabaseResult, TargetMigrationsCapability, VerifyDatabaseResult, VerifyDatabaseSchemaResult };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@prisma-next/core-control-plane",
3
- "version": "0.1.0-dev.16",
3
+ "version": "0.1.0-dev.17",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Control plane domain actions, config types, validation, and error factories for Prisma Next",
7
7
  "dependencies": {
8
8
  "arktype": "^2.1.26",
9
9
  "prettier": "^3.3.3",
10
- "@prisma-next/contract": "0.1.0-dev.16",
11
- "@prisma-next/operations": "0.1.0-dev.16",
12
- "@prisma-next/utils": "0.1.0-dev.16"
10
+ "@prisma-next/contract": "0.1.0-dev.17",
11
+ "@prisma-next/operations": "0.1.0-dev.17",
12
+ "@prisma-next/utils": "0.1.0-dev.17"
13
13
  },
14
14
  "devDependencies": {
15
15
  "tsup": "^8.3.0",