@prisma-next/contract 0.1.0-dev.17 → 0.1.0-dev.18

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.
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @prisma-next/contract
2
2
 
3
- Data contract type definitions and JSON schema for Prisma Next.
3
+ Core contract types, framework component descriptors, and JSON schemas for Prisma Next.
4
4
 
5
5
  ## Overview
6
6
 
7
- This package provides TypeScript type definitions and JSON Schemas for Prisma Next data contracts. The data contract is the canonical description of an application's data model and storage layout, independent of any specific query language or database target.
7
+ This package provides the foundational type definitions for Prisma Next, including:
8
+ - **Data contracts**: The canonical description of an application's data model and storage layout
9
+ - **Framework component descriptors**: Base interfaces for the modular component system (families, targets, adapters, drivers, extensions)
10
+ - **JSON Schemas**: Validation schemas for contract files
8
11
 
9
12
  ## Responsibilities
10
13
 
11
- - **Core Contract Types**: Defines framework-level contract types (`ContractBase`, `Source`) that are shared across all target families
14
+ - **Core Contract Types**: Defines framework-level contract types (`ContractBase`, `Source`, `FamilyInstance`) that are shared across all target families
15
+ - **Framework Component Model**: Provides base descriptor interfaces (`FamilyDescriptor`, `TargetDescriptor`, `AdapterDescriptor`, `DriverDescriptor`, `ExtensionDescriptor`) and identity instance bases (`FamilyInstance`, `TargetInstance`, `AdapterInstance`, `DriverInstance`, `ExtensionInstance`) that plane-specific types extend
12
16
  - **Document Family Types**: Provides TypeScript types for document target family contracts (`DocumentContract`)
13
17
  - **JSON Schema Validation**: Provides JSON Schemas for validating contract structure in IDEs and tooling
14
18
  - **Type Guards**: Provides runtime type guards for narrowing contract types (`isDocumentContract`)
@@ -69,6 +73,67 @@ const myFamilyHook: TargetFamilyHook = {
69
73
  };
70
74
  ```
71
75
 
76
+ ### Framework Component Model
77
+
78
+ Import base descriptor and instance interfaces to define or type-check framework components:
79
+
80
+ ```typescript
81
+ import type {
82
+ // Descriptors
83
+ ComponentDescriptor,
84
+ FamilyDescriptor,
85
+ TargetDescriptor,
86
+ AdapterDescriptor,
87
+ DriverDescriptor,
88
+ ExtensionDescriptor,
89
+ // Instances
90
+ FamilyInstance,
91
+ TargetInstance,
92
+ AdapterInstance,
93
+ DriverInstance,
94
+ ExtensionInstance,
95
+ } from '@prisma-next/contract/framework-components';
96
+
97
+ // Component descriptors share common properties
98
+ interface MyDescriptor extends ComponentDescriptor<'custom'> {
99
+ readonly customField: string;
100
+ }
101
+
102
+ // Use FamilyDescriptor for family components
103
+ const sqlFamily: FamilyDescriptor<'sql'> = {
104
+ kind: 'family',
105
+ id: 'sql',
106
+ familyId: 'sql',
107
+ manifest: { /* ... */ },
108
+ };
109
+
110
+ // Use TargetDescriptor for target components
111
+ const postgresTarget: TargetDescriptor<'sql', 'postgres'> = {
112
+ kind: 'target',
113
+ id: 'postgres',
114
+ familyId: 'sql',
115
+ targetId: 'postgres',
116
+ manifest: { /* ... */ },
117
+ };
118
+
119
+ // Identity instance bases are extended by plane-specific instances
120
+ interface MySqlInstance extends FamilyInstance<'sql'> {
121
+ // Plane-specific methods...
122
+ }
123
+ ```
124
+
125
+ The component hierarchy is:
126
+
127
+ ```
128
+ Family (e.g., 'sql', 'document')
129
+ └── Target (e.g., 'postgres', 'mysql', 'mongodb')
130
+ ├── Adapter (protocol/dialect implementation)
131
+ ├── Driver (connection/execution layer)
132
+ └── Extension (optional capabilities like pgvector)
133
+ ```
134
+
135
+ Plane-specific descriptors (`ControlFamilyDescriptor`, `RuntimeTargetDescriptor`, etc.) extend these bases with plane-specific factory methods and capabilities.
136
+
72
137
  ### JSON Schema Validation
73
138
 
74
139
  Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation and autocomplete.
@@ -175,7 +240,10 @@ if (isDocumentContract(contract)) {
175
240
 
176
241
  ## Exports
177
242
 
178
- - `./types`: TypeScript type definitions and type guards
243
+ - `./types`: Core contract type definitions, type guards, and emitter SPI types
244
+ - `./framework-components`: Framework component model (descriptors + identity instance bases)
245
+ - `./pack-manifest-types`: Extension pack manifest types
246
+ - `./ir`: Contract IR types
179
247
  - `./schema-document`: Document family JSON Schema (`schemas/data-contract-document-v1.json`)
180
248
 
181
249
  ## Architecture
@@ -0,0 +1,312 @@
1
+ import { E as ExtensionPackManifest } from './pack-manifest-types-BYh8H2fb.js';
2
+ import '@prisma-next/operations';
3
+ import './ir.js';
4
+
5
+ /**
6
+ * Base descriptor for any framework component.
7
+ *
8
+ * All component descriptors share these fundamental properties that identify
9
+ * the component and provide its metadata. This interface is extended by
10
+ * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
11
+ *
12
+ * @template Kind - Discriminator literal identifying the component type.
13
+ * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',
14
+ * but the type accepts any string to allow ecosystem extensions.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * // All descriptors have these properties
19
+ * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)
20
+ * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')
21
+ * descriptor.manifest // Package metadata (version, capabilities, types, etc.)
22
+ * ```
23
+ */
24
+ interface ComponentDescriptor<Kind extends string> {
25
+ /** Discriminator identifying the component type */
26
+ readonly kind: Kind;
27
+ /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */
28
+ readonly id: string;
29
+ /** Package manifest containing version, capabilities, type imports, and operations */
30
+ readonly manifest: ExtensionPackManifest;
31
+ }
32
+ /**
33
+ * Descriptor for a family component.
34
+ *
35
+ * A "family" represents a category of data sources with shared semantics
36
+ * (e.g., SQL databases, document stores). Families define:
37
+ * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
38
+ * - Contract structure (tables vs collections, columns vs fields)
39
+ * - Type system and codecs
40
+ *
41
+ * Families are the top-level grouping. Each family contains multiple targets
42
+ * (e.g., SQL family contains Postgres, MySQL, SQLite targets).
43
+ *
44
+ * Extended by plane-specific descriptors:
45
+ * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations
46
+ * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods
47
+ *
48
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import sql from '@prisma-next/family-sql/control';
53
+ *
54
+ * sql.kind // 'family'
55
+ * sql.familyId // 'sql'
56
+ * sql.id // 'sql'
57
+ * ```
58
+ */
59
+ interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {
60
+ /** The family identifier (e.g., 'sql', 'document') */
61
+ readonly familyId: TFamilyId;
62
+ }
63
+ /**
64
+ * Descriptor for a target component.
65
+ *
66
+ * A "target" represents a specific database or data store within a family
67
+ * (e.g., Postgres, MySQL, MongoDB). Targets define:
68
+ * - Native type mappings (e.g., Postgres int4 → TypeScript number)
69
+ * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
70
+ * - Version constraints and compatibility
71
+ *
72
+ * Targets are bound to a family and provide the target-specific implementation
73
+ * details that adapters and drivers use.
74
+ *
75
+ * Extended by plane-specific descriptors:
76
+ * - `ControlTargetDescriptor` - adds optional `migrations` capability
77
+ * - `RuntimeTargetDescriptor` - adds runtime factory method
78
+ *
79
+ * @template TFamilyId - Literal type for the family identifier
80
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import postgres from '@prisma-next/target-postgres/control';
85
+ *
86
+ * postgres.kind // 'target'
87
+ * postgres.familyId // 'sql'
88
+ * postgres.targetId // 'postgres'
89
+ * ```
90
+ */
91
+ interface TargetDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'target'> {
92
+ /** The family this target belongs to */
93
+ readonly familyId: TFamilyId;
94
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
95
+ readonly targetId: TTargetId;
96
+ }
97
+ /**
98
+ * Descriptor for an adapter component.
99
+ *
100
+ * An "adapter" provides the protocol and dialect implementation for a target.
101
+ * Adapters handle:
102
+ * - SQL/query generation (lowering AST to target-specific syntax)
103
+ * - Codec registration (encoding/decoding between JS and wire types)
104
+ * - Type mappings and coercions
105
+ *
106
+ * Adapters are bound to a specific family+target combination and work with
107
+ * any compatible driver for that target.
108
+ *
109
+ * Extended by plane-specific descriptors:
110
+ * - `ControlAdapterDescriptor` - control-plane factory
111
+ * - `RuntimeAdapterDescriptor` - runtime factory
112
+ *
113
+ * @template TFamilyId - Literal type for the family identifier
114
+ * @template TTargetId - Literal type for the target identifier
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import postgresAdapter from '@prisma-next/adapter-postgres/control';
119
+ *
120
+ * postgresAdapter.kind // 'adapter'
121
+ * postgresAdapter.familyId // 'sql'
122
+ * postgresAdapter.targetId // 'postgres'
123
+ * ```
124
+ */
125
+ interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'adapter'> {
126
+ /** The family this adapter belongs to */
127
+ readonly familyId: TFamilyId;
128
+ /** The target this adapter is designed for */
129
+ readonly targetId: TTargetId;
130
+ }
131
+ /**
132
+ * Descriptor for a driver component.
133
+ *
134
+ * A "driver" provides the connection and execution layer for a target.
135
+ * Drivers handle:
136
+ * - Connection management (pooling, timeouts, retries)
137
+ * - Query execution (sending SQL/commands, receiving results)
138
+ * - Transaction management
139
+ * - Wire protocol communication
140
+ *
141
+ * Drivers are bound to a specific family+target and work with any compatible
142
+ * adapter. Multiple drivers can exist for the same target (e.g., node-postgres
143
+ * vs postgres.js for Postgres).
144
+ *
145
+ * Extended by plane-specific descriptors:
146
+ * - `ControlDriverDescriptor` - creates driver from connection URL
147
+ * - `RuntimeDriverDescriptor` - creates driver with runtime options
148
+ *
149
+ * @template TFamilyId - Literal type for the family identifier
150
+ * @template TTargetId - Literal type for the target identifier
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * import postgresDriver from '@prisma-next/driver-postgres/control';
155
+ *
156
+ * postgresDriver.kind // 'driver'
157
+ * postgresDriver.familyId // 'sql'
158
+ * postgresDriver.targetId // 'postgres'
159
+ * ```
160
+ */
161
+ interface DriverDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'driver'> {
162
+ /** The family this driver belongs to */
163
+ readonly familyId: TFamilyId;
164
+ /** The target this driver connects to */
165
+ readonly targetId: TTargetId;
166
+ }
167
+ /**
168
+ * Descriptor for an extension component.
169
+ *
170
+ * An "extension" adds optional capabilities to a target. Extensions can provide:
171
+ * - Additional operations (e.g., vector similarity search with pgvector)
172
+ * - Custom types and codecs (e.g., vector type)
173
+ * - Extended query capabilities
174
+ *
175
+ * Extensions are bound to a specific family+target and are registered in the
176
+ * config alongside the core components. Multiple extensions can be used together.
177
+ *
178
+ * Extended by plane-specific descriptors:
179
+ * - `ControlExtensionDescriptor` - control-plane extension factory
180
+ * - `RuntimeExtensionDescriptor` - runtime extension factory
181
+ *
182
+ * @template TFamilyId - Literal type for the family identifier
183
+ * @template TTargetId - Literal type for the target identifier
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import pgvector from '@prisma-next/extension-pgvector/control';
188
+ *
189
+ * pgvector.kind // 'extension'
190
+ * pgvector.familyId // 'sql'
191
+ * pgvector.targetId // 'postgres'
192
+ * ```
193
+ */
194
+ interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'extension'> {
195
+ /** The family this extension belongs to */
196
+ readonly familyId: TFamilyId;
197
+ /** The target this extension is designed for */
198
+ readonly targetId: TTargetId;
199
+ }
200
+ /**
201
+ * Base interface for family instances.
202
+ *
203
+ * A family instance is created by a family descriptor's `create()` method.
204
+ * This base interface carries only the identity; plane-specific interfaces
205
+ * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).
206
+ *
207
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const instance = sql.create({ target, adapter, driver, extensions });
212
+ * instance.familyId // 'sql'
213
+ * ```
214
+ */
215
+ interface FamilyInstance<TFamilyId extends string> {
216
+ /** The family identifier (e.g., 'sql', 'document') */
217
+ readonly familyId: TFamilyId;
218
+ }
219
+ /**
220
+ * Base interface for target instances.
221
+ *
222
+ * A target instance is created by a target descriptor's `create()` method.
223
+ * This base interface carries only the identity; plane-specific interfaces
224
+ * add target-specific behavior.
225
+ *
226
+ * @template TFamilyId - Literal type for the family identifier
227
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * const instance = postgres.create();
232
+ * instance.familyId // 'sql'
233
+ * instance.targetId // 'postgres'
234
+ * ```
235
+ */
236
+ interface TargetInstance<TFamilyId extends string, TTargetId extends string> {
237
+ /** The family this target belongs to */
238
+ readonly familyId: TFamilyId;
239
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
240
+ readonly targetId: TTargetId;
241
+ }
242
+ /**
243
+ * Base interface for adapter instances.
244
+ *
245
+ * An adapter instance is created by an adapter descriptor's `create()` method.
246
+ * This base interface carries only the identity; plane-specific interfaces
247
+ * add adapter-specific behavior (e.g., codec registration, query lowering).
248
+ *
249
+ * @template TFamilyId - Literal type for the family identifier
250
+ * @template TTargetId - Literal type for the target identifier
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const instance = postgresAdapter.create();
255
+ * instance.familyId // 'sql'
256
+ * instance.targetId // 'postgres'
257
+ * ```
258
+ */
259
+ interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {
260
+ /** The family this adapter belongs to */
261
+ readonly familyId: TFamilyId;
262
+ /** The target this adapter is designed for */
263
+ readonly targetId: TTargetId;
264
+ }
265
+ /**
266
+ * Base interface for driver instances.
267
+ *
268
+ * A driver instance is created by a driver descriptor's `create()` method.
269
+ * This base interface carries only the identity; plane-specific interfaces
270
+ * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).
271
+ *
272
+ * @template TFamilyId - Literal type for the family identifier
273
+ * @template TTargetId - Literal type for the target identifier
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * const instance = postgresDriver.create({ databaseUrl });
278
+ * instance.familyId // 'sql'
279
+ * instance.targetId // 'postgres'
280
+ * ```
281
+ */
282
+ interface DriverInstance<TFamilyId extends string, TTargetId extends string> {
283
+ /** The family this driver belongs to */
284
+ readonly familyId: TFamilyId;
285
+ /** The target this driver connects to */
286
+ readonly targetId: TTargetId;
287
+ }
288
+ /**
289
+ * Base interface for extension instances.
290
+ *
291
+ * An extension instance is created by an extension descriptor's `create()` method.
292
+ * This base interface carries only the identity; plane-specific interfaces
293
+ * add extension-specific behavior.
294
+ *
295
+ * @template TFamilyId - Literal type for the family identifier
296
+ * @template TTargetId - Literal type for the target identifier
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * const instance = pgvector.create();
301
+ * instance.familyId // 'sql'
302
+ * instance.targetId // 'postgres'
303
+ * ```
304
+ */
305
+ interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {
306
+ /** The family this extension belongs to */
307
+ readonly familyId: TFamilyId;
308
+ /** The target this extension is designed for */
309
+ readonly targetId: TTargetId;
310
+ }
311
+
312
+ export type { AdapterDescriptor, AdapterInstance, ComponentDescriptor, DriverDescriptor, DriverInstance, ExtensionDescriptor, ExtensionInstance, FamilyDescriptor, FamilyInstance, TargetDescriptor, TargetInstance };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=framework-components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,251 @@
1
+ import { OperationRegistry } from '@prisma-next/operations';
2
+ import { ContractIR } from './ir.js';
3
+
4
+ interface ContractBase {
5
+ readonly schemaVersion: string;
6
+ readonly target: string;
7
+ readonly targetFamily: string;
8
+ readonly coreHash: string;
9
+ readonly profileHash?: string;
10
+ readonly capabilities?: Record<string, Record<string, boolean>>;
11
+ readonly extensions?: Record<string, unknown>;
12
+ readonly meta?: Record<string, unknown>;
13
+ readonly sources?: Record<string, Source>;
14
+ }
15
+ interface FieldType {
16
+ readonly type: string;
17
+ readonly nullable: boolean;
18
+ readonly items?: FieldType;
19
+ readonly properties?: Record<string, FieldType>;
20
+ }
21
+ interface Source {
22
+ readonly readOnly: boolean;
23
+ readonly projection: Record<string, FieldType>;
24
+ readonly origin?: Record<string, unknown>;
25
+ readonly capabilities?: Record<string, boolean>;
26
+ }
27
+ interface DocIndex {
28
+ readonly name: string;
29
+ readonly keys: Record<string, 'asc' | 'desc'>;
30
+ readonly unique?: boolean;
31
+ readonly where?: Expr;
32
+ }
33
+ type Expr = {
34
+ readonly kind: 'eq';
35
+ readonly path: ReadonlyArray<string>;
36
+ readonly value: unknown;
37
+ } | {
38
+ readonly kind: 'exists';
39
+ readonly path: ReadonlyArray<string>;
40
+ };
41
+ interface DocCollection {
42
+ readonly name: string;
43
+ readonly id?: {
44
+ readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';
45
+ };
46
+ readonly fields: Record<string, FieldType>;
47
+ readonly indexes?: ReadonlyArray<DocIndex>;
48
+ readonly readOnly?: boolean;
49
+ }
50
+ interface DocumentStorage {
51
+ readonly document: {
52
+ readonly collections: Record<string, DocCollection>;
53
+ };
54
+ }
55
+ interface DocumentContract extends ContractBase {
56
+ readonly targetFamily: string;
57
+ readonly storage: DocumentStorage;
58
+ }
59
+ interface ParamDescriptor {
60
+ readonly index?: number;
61
+ readonly name?: string;
62
+ readonly codecId?: string;
63
+ readonly nativeType?: string;
64
+ readonly nullable?: boolean;
65
+ readonly source: 'dsl' | 'raw';
66
+ readonly refs?: {
67
+ table: string;
68
+ column: string;
69
+ };
70
+ }
71
+ interface PlanRefs {
72
+ readonly tables?: readonly string[];
73
+ readonly columns?: ReadonlyArray<{
74
+ table: string;
75
+ column: string;
76
+ }>;
77
+ readonly indexes?: ReadonlyArray<{
78
+ readonly table: string;
79
+ readonly columns: ReadonlyArray<string>;
80
+ readonly name?: string;
81
+ }>;
82
+ }
83
+ interface PlanMeta {
84
+ readonly target: string;
85
+ readonly targetFamily?: string;
86
+ readonly coreHash: string;
87
+ readonly profileHash?: string;
88
+ readonly lane: string;
89
+ readonly annotations?: {
90
+ codecs?: Record<string, string>;
91
+ [key: string]: unknown;
92
+ };
93
+ readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;
94
+ readonly refs?: PlanRefs;
95
+ readonly projection?: Record<string, string> | ReadonlyArray<string>;
96
+ /**
97
+ * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).
98
+ * Used for codec resolution when AST+refs don't provide enough type info.
99
+ */
100
+ readonly projectionTypes?: Record<string, string>;
101
+ }
102
+ /**
103
+ * Canonical execution plan shape used by runtimes.
104
+ *
105
+ * - Row is the inferred result row type (TypeScript-only).
106
+ * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).
107
+ *
108
+ * The payload executed by the runtime is represented by the sql + params pair
109
+ * for now; future families can specialize this via Ast or additional metadata.
110
+ */
111
+ interface ExecutionPlan<Row = unknown, Ast = unknown> {
112
+ readonly sql: string;
113
+ readonly params: readonly unknown[];
114
+ readonly ast?: Ast;
115
+ readonly meta: PlanMeta;
116
+ /**
117
+ * Phantom property to carry the Row generic for type-level utilities.
118
+ * Not set at runtime; used only for ResultType extraction.
119
+ */
120
+ readonly _row?: Row;
121
+ }
122
+ /**
123
+ * Utility type to extract the Row type from an ExecutionPlan.
124
+ * Example: `type Row = ResultType<typeof plan>`
125
+ *
126
+ * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).
127
+ * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter
128
+ * for type extraction.
129
+ */
130
+ type ResultType<P> = P extends ExecutionPlan<infer R, unknown> ? R : P extends {
131
+ readonly _Row?: infer R;
132
+ } ? R : never;
133
+ /**
134
+ * Type guard to check if a contract is a Document contract
135
+ */
136
+ declare function isDocumentContract(contract: unknown): contract is DocumentContract;
137
+ /**
138
+ * Contract marker record stored in the database.
139
+ * Represents the current contract identity for a database.
140
+ */
141
+ interface ContractMarkerRecord {
142
+ readonly coreHash: string;
143
+ readonly profileHash: string;
144
+ readonly contractJson: unknown | null;
145
+ readonly canonicalVersion: number | null;
146
+ readonly updatedAt: Date;
147
+ readonly appTag: string | null;
148
+ readonly meta: Record<string, unknown>;
149
+ }
150
+ /**
151
+ * Specifies how to import TypeScript types from a package.
152
+ * Used in extension pack manifests to declare codec and operation type imports.
153
+ */
154
+ interface TypesImportSpec {
155
+ readonly package: string;
156
+ readonly named: string;
157
+ readonly alias: string;
158
+ }
159
+ /**
160
+ * Validation context passed to TargetFamilyHook.validateTypes().
161
+ * Contains pre-assembled operation registry, type imports, and extension IDs.
162
+ */
163
+ interface ValidationContext {
164
+ readonly operationRegistry?: OperationRegistry;
165
+ readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
166
+ readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
167
+ readonly extensionIds?: ReadonlyArray<string>;
168
+ }
169
+ /**
170
+ * SPI interface for target family hooks that extend emission behavior.
171
+ * Implemented by family-specific emitter hooks (e.g., SQL family).
172
+ */
173
+ interface TargetFamilyHook {
174
+ readonly id: string;
175
+ /**
176
+ * Validates that all type IDs in the contract come from referenced extensions.
177
+ * @param ir - Contract IR to validate
178
+ * @param ctx - Validation context with operation registry and extension IDs
179
+ */
180
+ validateTypes(ir: ContractIR, ctx: ValidationContext): void;
181
+ /**
182
+ * Validates family-specific contract structure.
183
+ * @param ir - Contract IR to validate
184
+ */
185
+ validateStructure(ir: ContractIR): void;
186
+ /**
187
+ * Generates contract.d.ts file content.
188
+ * @param ir - Contract IR
189
+ * @param codecTypeImports - Array of codec type import specs
190
+ * @param operationTypeImports - Array of operation type import specs
191
+ * @returns Generated TypeScript type definitions as string
192
+ */
193
+ generateContractTypes(ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec>): string;
194
+ }
195
+ type ArgSpecManifest = {
196
+ readonly kind: 'typeId';
197
+ readonly type: string;
198
+ } | {
199
+ readonly kind: 'param';
200
+ } | {
201
+ readonly kind: 'literal';
202
+ };
203
+ type ReturnSpecManifest = {
204
+ readonly kind: 'typeId';
205
+ readonly type: string;
206
+ } | {
207
+ readonly kind: 'builtin';
208
+ readonly type: 'number' | 'boolean' | 'string';
209
+ };
210
+ interface LoweringSpecManifest {
211
+ readonly targetFamily: 'sql';
212
+ readonly strategy: 'infix' | 'function';
213
+ readonly template: string;
214
+ }
215
+ interface OperationManifest {
216
+ readonly for: string;
217
+ readonly method: string;
218
+ readonly args: ReadonlyArray<ArgSpecManifest>;
219
+ readonly returns: ReturnSpecManifest;
220
+ readonly lowering: LoweringSpecManifest;
221
+ readonly capabilities?: ReadonlyArray<string>;
222
+ }
223
+ interface ExtensionPackManifest {
224
+ readonly id: string;
225
+ readonly version: string;
226
+ readonly targets?: Record<string, {
227
+ readonly minVersion?: string;
228
+ }>;
229
+ readonly capabilities?: Record<string, unknown>;
230
+ readonly types?: {
231
+ readonly codecTypes?: {
232
+ readonly import: TypesImportSpec;
233
+ };
234
+ readonly operationTypes?: {
235
+ readonly import: TypesImportSpec;
236
+ };
237
+ readonly storage?: readonly {
238
+ readonly typeId: string;
239
+ readonly familyId: string;
240
+ readonly targetId: string;
241
+ readonly nativeType?: string;
242
+ }[];
243
+ };
244
+ readonly operations?: ReadonlyArray<OperationManifest>;
245
+ }
246
+ interface ExtensionPack {
247
+ readonly manifest: ExtensionPackManifest;
248
+ readonly path: string;
249
+ }
250
+
251
+ export { type ArgSpecManifest as A, type ContractBase as C, type DocCollection as D, type ExtensionPackManifest as E, type FieldType as F, type LoweringSpecManifest as L, type OperationManifest as O, type ParamDescriptor as P, type ResultType as R, type Source as S, type TargetFamilyHook as T, type ValidationContext as V, type ContractMarkerRecord as a, type DocIndex as b, type DocumentContract as c, type DocumentStorage as d, type ExecutionPlan as e, type Expr as f, type PlanMeta as g, type PlanRefs as h, type TypesImportSpec as i, isDocumentContract as j, type ExtensionPack as k, type ReturnSpecManifest as l };
@@ -1,3 +1,3 @@
1
- export { A as ArgSpecManifest, E as ExtensionPack, a as ExtensionPackManifest, L as LoweringSpecManifest, O as OperationManifest, R as ReturnSpecManifest } from './types.js';
1
+ export { A as ArgSpecManifest, k as ExtensionPack, E as ExtensionPackManifest, L as LoweringSpecManifest, O as OperationManifest, l as ReturnSpecManifest } from './pack-manifest-types-BYh8H2fb.js';
2
2
  import '@prisma-next/operations';
3
3
  import './ir.js';
@@ -1,251 +1,3 @@
1
- import { OperationRegistry } from '@prisma-next/operations';
2
- import { ContractIR } from './ir.js';
3
-
4
- interface ContractBase {
5
- readonly schemaVersion: string;
6
- readonly target: string;
7
- readonly targetFamily: string;
8
- readonly coreHash: string;
9
- readonly profileHash?: string;
10
- readonly capabilities?: Record<string, Record<string, boolean>>;
11
- readonly extensions?: Record<string, unknown>;
12
- readonly meta?: Record<string, unknown>;
13
- readonly sources?: Record<string, Source>;
14
- }
15
- interface FieldType {
16
- readonly type: string;
17
- readonly nullable: boolean;
18
- readonly items?: FieldType;
19
- readonly properties?: Record<string, FieldType>;
20
- }
21
- interface Source {
22
- readonly readOnly: boolean;
23
- readonly projection: Record<string, FieldType>;
24
- readonly origin?: Record<string, unknown>;
25
- readonly capabilities?: Record<string, boolean>;
26
- }
27
- interface DocIndex {
28
- readonly name: string;
29
- readonly keys: Record<string, 'asc' | 'desc'>;
30
- readonly unique?: boolean;
31
- readonly where?: Expr;
32
- }
33
- type Expr = {
34
- readonly kind: 'eq';
35
- readonly path: ReadonlyArray<string>;
36
- readonly value: unknown;
37
- } | {
38
- readonly kind: 'exists';
39
- readonly path: ReadonlyArray<string>;
40
- };
41
- interface DocCollection {
42
- readonly name: string;
43
- readonly id?: {
44
- readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';
45
- };
46
- readonly fields: Record<string, FieldType>;
47
- readonly indexes?: ReadonlyArray<DocIndex>;
48
- readonly readOnly?: boolean;
49
- }
50
- interface DocumentStorage {
51
- readonly document: {
52
- readonly collections: Record<string, DocCollection>;
53
- };
54
- }
55
- interface DocumentContract extends ContractBase {
56
- readonly targetFamily: string;
57
- readonly storage: DocumentStorage;
58
- }
59
- interface ParamDescriptor {
60
- readonly index?: number;
61
- readonly name?: string;
62
- readonly codecId?: string;
63
- readonly nativeType?: string;
64
- readonly nullable?: boolean;
65
- readonly source: 'dsl' | 'raw';
66
- readonly refs?: {
67
- table: string;
68
- column: string;
69
- };
70
- }
71
- interface PlanRefs {
72
- readonly tables?: readonly string[];
73
- readonly columns?: ReadonlyArray<{
74
- table: string;
75
- column: string;
76
- }>;
77
- readonly indexes?: ReadonlyArray<{
78
- readonly table: string;
79
- readonly columns: ReadonlyArray<string>;
80
- readonly name?: string;
81
- }>;
82
- }
83
- interface PlanMeta {
84
- readonly target: string;
85
- readonly targetFamily?: string;
86
- readonly coreHash: string;
87
- readonly profileHash?: string;
88
- readonly lane: string;
89
- readonly annotations?: {
90
- codecs?: Record<string, string>;
91
- [key: string]: unknown;
92
- };
93
- readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;
94
- readonly refs?: PlanRefs;
95
- readonly projection?: Record<string, string> | ReadonlyArray<string>;
96
- /**
97
- * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).
98
- * Used for codec resolution when AST+refs don't provide enough type info.
99
- */
100
- readonly projectionTypes?: Record<string, string>;
101
- }
102
- /**
103
- * Canonical execution plan shape used by runtimes.
104
- *
105
- * - Row is the inferred result row type (TypeScript-only).
106
- * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).
107
- *
108
- * The payload executed by the runtime is represented by the sql + params pair
109
- * for now; future families can specialize this via Ast or additional metadata.
110
- */
111
- interface ExecutionPlan<Row = unknown, Ast = unknown> {
112
- readonly sql: string;
113
- readonly params: readonly unknown[];
114
- readonly ast?: Ast;
115
- readonly meta: PlanMeta;
116
- /**
117
- * Phantom property to carry the Row generic for type-level utilities.
118
- * Not set at runtime; used only for ResultType extraction.
119
- */
120
- readonly _row?: Row;
121
- }
122
- /**
123
- * Utility type to extract the Row type from an ExecutionPlan.
124
- * Example: `type Row = ResultType<typeof plan>`
125
- *
126
- * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).
127
- * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter
128
- * for type extraction.
129
- */
130
- type ResultType<P> = P extends ExecutionPlan<infer R, unknown> ? R : P extends {
131
- readonly _Row?: infer R;
132
- } ? R : never;
133
- /**
134
- * Type guard to check if a contract is a Document contract
135
- */
136
- declare function isDocumentContract(contract: unknown): contract is DocumentContract;
137
- /**
138
- * Contract marker record stored in the database.
139
- * Represents the current contract identity for a database.
140
- */
141
- interface ContractMarkerRecord {
142
- readonly coreHash: string;
143
- readonly profileHash: string;
144
- readonly contractJson: unknown | null;
145
- readonly canonicalVersion: number | null;
146
- readonly updatedAt: Date;
147
- readonly appTag: string | null;
148
- readonly meta: Record<string, unknown>;
149
- }
150
- /**
151
- * Specifies how to import TypeScript types from a package.
152
- * Used in extension pack manifests to declare codec and operation type imports.
153
- */
154
- interface TypesImportSpec {
155
- readonly package: string;
156
- readonly named: string;
157
- readonly alias: string;
158
- }
159
- /**
160
- * Validation context passed to TargetFamilyHook.validateTypes().
161
- * Contains pre-assembled operation registry, type imports, and extension IDs.
162
- */
163
- interface ValidationContext {
164
- readonly operationRegistry?: OperationRegistry;
165
- readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
166
- readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
167
- readonly extensionIds?: ReadonlyArray<string>;
168
- }
169
- /**
170
- * SPI interface for target family hooks that extend emission behavior.
171
- * Implemented by family-specific emitter hooks (e.g., SQL family).
172
- */
173
- interface TargetFamilyHook {
174
- readonly id: string;
175
- /**
176
- * Validates that all type IDs in the contract come from referenced extensions.
177
- * @param ir - Contract IR to validate
178
- * @param ctx - Validation context with operation registry and extension IDs
179
- */
180
- validateTypes(ir: ContractIR, ctx: ValidationContext): void;
181
- /**
182
- * Validates family-specific contract structure.
183
- * @param ir - Contract IR to validate
184
- */
185
- validateStructure(ir: ContractIR): void;
186
- /**
187
- * Generates contract.d.ts file content.
188
- * @param ir - Contract IR
189
- * @param codecTypeImports - Array of codec type import specs
190
- * @param operationTypeImports - Array of operation type import specs
191
- * @returns Generated TypeScript type definitions as string
192
- */
193
- generateContractTypes(ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec>): string;
194
- }
195
- type ArgSpecManifest = {
196
- readonly kind: 'typeId';
197
- readonly type: string;
198
- } | {
199
- readonly kind: 'param';
200
- } | {
201
- readonly kind: 'literal';
202
- };
203
- type ReturnSpecManifest = {
204
- readonly kind: 'typeId';
205
- readonly type: string;
206
- } | {
207
- readonly kind: 'builtin';
208
- readonly type: 'number' | 'boolean' | 'string';
209
- };
210
- interface LoweringSpecManifest {
211
- readonly targetFamily: 'sql';
212
- readonly strategy: 'infix' | 'function';
213
- readonly template: string;
214
- }
215
- interface OperationManifest {
216
- readonly for: string;
217
- readonly method: string;
218
- readonly args: ReadonlyArray<ArgSpecManifest>;
219
- readonly returns: ReturnSpecManifest;
220
- readonly lowering: LoweringSpecManifest;
221
- readonly capabilities?: ReadonlyArray<string>;
222
- }
223
- interface ExtensionPackManifest {
224
- readonly id: string;
225
- readonly version: string;
226
- readonly targets?: Record<string, {
227
- readonly minVersion?: string;
228
- }>;
229
- readonly capabilities?: Record<string, unknown>;
230
- readonly types?: {
231
- readonly codecTypes?: {
232
- readonly import: TypesImportSpec;
233
- };
234
- readonly operationTypes?: {
235
- readonly import: TypesImportSpec;
236
- };
237
- readonly storage?: readonly {
238
- readonly typeId: string;
239
- readonly familyId: string;
240
- readonly targetId: string;
241
- readonly nativeType?: string;
242
- }[];
243
- };
244
- readonly operations?: ReadonlyArray<OperationManifest>;
245
- }
246
- interface ExtensionPack {
247
- readonly manifest: ExtensionPackManifest;
248
- readonly path: string;
249
- }
250
-
251
- export { type ArgSpecManifest as A, type ContractBase, type ContractMarkerRecord, type DocCollection, type DocIndex, type DocumentContract, type DocumentStorage, type ExtensionPack as E, type ExecutionPlan, type Expr, type FieldType, type LoweringSpecManifest as L, type OperationManifest as O, type ParamDescriptor, type PlanMeta, type PlanRefs, type ReturnSpecManifest as R, type ResultType, type Source, type TargetFamilyHook, type TypesImportSpec, type ValidationContext, type ExtensionPackManifest as a, isDocumentContract };
1
+ export { C as ContractBase, a as ContractMarkerRecord, D as DocCollection, b as DocIndex, c as DocumentContract, d as DocumentStorage, e as ExecutionPlan, f as Expr, F as FieldType, P as ParamDescriptor, g as PlanMeta, h as PlanRefs, R as ResultType, S as Source, T as TargetFamilyHook, i as TypesImportSpec, V as ValidationContext, j as isDocumentContract } from './pack-manifest-types-BYh8H2fb.js';
2
+ import '@prisma-next/operations';
3
+ import './ir.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { ContractIR } from './ir';\n\n// Shared header and neutral types\n// Note: Fields like targetFamily accept string to work with JSON imports,\n// which don't preserve literal types. Runtime validation ensures correct values\nexport interface ContractBase {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly capabilities?: Record<string, Record<string, boolean>>;\n readonly extensions?: Record<string, unknown>;\n readonly meta?: Record<string, unknown>;\n readonly sources?: Record<string, Source>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface DocumentStorage {\n readonly document: {\n readonly collections: Record<string, DocCollection>;\n };\n}\n\nexport interface DocumentContract extends ContractBase {\n // Accept string to work with JSON imports; runtime validation ensures 'document'\n readonly targetFamily: string;\n readonly storage: DocumentStorage;\n}\n\n// Plan types - target-family agnostic execution types\nexport interface ParamDescriptor {\n readonly index?: number;\n readonly name?: string;\n readonly codecId?: string;\n readonly nativeType?: string;\n readonly nullable?: boolean;\n readonly source: 'dsl' | 'raw';\n readonly refs?: { table: string; column: string };\n}\n\nexport interface PlanRefs {\n readonly tables?: readonly string[];\n readonly columns?: ReadonlyArray<{ table: string; column: string }>;\n readonly indexes?: ReadonlyArray<{\n readonly table: string;\n readonly columns: ReadonlyArray<string>;\n readonly name?: string;\n }>;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n codecs?: Record<string, string>; // alias/param → codec id ('ns/name@v')\n [key: string]: unknown;\n };\n readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;\n readonly refs?: PlanRefs;\n readonly projection?: Record<string, string> | ReadonlyArray<string>;\n /**\n * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).\n * Used for codec resolution when AST+refs don't provide enough type info.\n */\n readonly projectionTypes?: Record<string, string>;\n}\n\n/**\n * Canonical execution plan shape used by runtimes.\n *\n * - Row is the inferred result row type (TypeScript-only).\n * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).\n *\n * The payload executed by the runtime is represented by the sql + params pair\n * for now; future families can specialize this via Ast or additional metadata.\n */\nexport interface ExecutionPlan<Row = unknown, Ast = unknown> {\n readonly sql: string;\n readonly params: readonly unknown[];\n readonly ast?: Ast;\n readonly meta: PlanMeta;\n /**\n * Phantom property to carry the Row generic for type-level utilities.\n * Not set at runtime; used only for ResultType extraction.\n */\n readonly _row?: Row;\n}\n\n/**\n * Utility type to extract the Row type from an ExecutionPlan.\n * Example: `type Row = ResultType<typeof plan>`\n *\n * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).\n * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter\n * for type extraction.\n */\nexport type ResultType<P> = P extends ExecutionPlan<infer R, unknown>\n ? R\n : P extends { readonly _Row?: infer R }\n ? R\n : never;\n\n/**\n * Type guard to check if a contract is a Document contract\n */\nexport function isDocumentContract(contract: unknown): contract is DocumentContract {\n return (\n typeof contract === 'object' &&\n contract !== null &&\n 'targetFamily' in contract &&\n contract.targetFamily === 'document'\n );\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly coreHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n}\n\n// Emitter types - moved from @prisma-next/emitter to shared location\n/**\n * Specifies how to import TypeScript types from a package.\n * Used in extension pack manifests to declare codec and operation type imports.\n */\nexport interface TypesImportSpec {\n readonly package: string;\n readonly named: string;\n readonly alias: string;\n}\n\n/**\n * Validation context passed to TargetFamilyHook.validateTypes().\n * Contains pre-assembled operation registry, type imports, and extension IDs.\n */\nexport interface ValidationContext {\n readonly operationRegistry?: OperationRegistry;\n readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds?: ReadonlyArray<string>;\n}\n\n/**\n * SPI interface for target family hooks that extend emission behavior.\n * Implemented by family-specific emitter hooks (e.g., SQL family).\n */\nexport interface TargetFamilyHook {\n readonly id: string;\n\n /**\n * Validates that all type IDs in the contract come from referenced extensions.\n * @param ir - Contract IR to validate\n * @param ctx - Validation context with operation registry and extension IDs\n */\n validateTypes(ir: ContractIR, ctx: ValidationContext): void;\n\n /**\n * Validates family-specific contract structure.\n * @param ir - Contract IR to validate\n */\n validateStructure(ir: ContractIR): void;\n\n /**\n * Generates contract.d.ts file content.\n * @param ir - Contract IR\n * @param codecTypeImports - Array of codec type import specs\n * @param operationTypeImports - Array of operation type import specs\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n ): string;\n}\n\n// Extension pack manifest types - moved from @prisma-next/core-control-plane to shared location\nexport type ArgSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'param' }\n | { readonly kind: 'literal' };\n\nexport type ReturnSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };\n\nexport interface LoweringSpecManifest {\n readonly targetFamily: 'sql';\n readonly strategy: 'infix' | 'function';\n readonly template: string;\n}\n\nexport interface OperationManifest {\n readonly for: string;\n readonly method: string;\n readonly args: ReadonlyArray<ArgSpecManifest>;\n readonly returns: ReturnSpecManifest;\n readonly lowering: LoweringSpecManifest;\n readonly capabilities?: ReadonlyArray<string>;\n}\n\nexport interface ExtensionPackManifest {\n readonly id: string;\n readonly version: string;\n readonly targets?: Record<string, { readonly minVersion?: string }>;\n readonly capabilities?: Record<string, unknown>;\n readonly types?: {\n readonly codecTypes?: {\n readonly import: TypesImportSpec;\n };\n readonly operationTypes?: {\n readonly import: TypesImportSpec;\n };\n readonly storage?: readonly {\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string;\n }[];\n };\n readonly operations?: ReadonlyArray<OperationManifest>;\n}\n\nexport interface ExtensionPack {\n readonly manifest: ExtensionPackManifest;\n readonly path: string;\n}\n"],"mappings":";AAiJO,SAAS,mBAAmB,UAAiD;AAClF,SACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB;AAE9B;","names":[]}
1
+ {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { ContractIR } from './ir';\n\nexport interface ContractBase {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly capabilities?: Record<string, Record<string, boolean>>;\n readonly extensions?: Record<string, unknown>;\n readonly meta?: Record<string, unknown>;\n readonly sources?: Record<string, Source>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface DocumentStorage {\n readonly document: {\n readonly collections: Record<string, DocCollection>;\n };\n}\n\nexport interface DocumentContract extends ContractBase {\n // Accept string to work with JSON imports; runtime validation ensures 'document'\n readonly targetFamily: string;\n readonly storage: DocumentStorage;\n}\n\n// Plan types - target-family agnostic execution types\nexport interface ParamDescriptor {\n readonly index?: number;\n readonly name?: string;\n readonly codecId?: string;\n readonly nativeType?: string;\n readonly nullable?: boolean;\n readonly source: 'dsl' | 'raw';\n readonly refs?: { table: string; column: string };\n}\n\nexport interface PlanRefs {\n readonly tables?: readonly string[];\n readonly columns?: ReadonlyArray<{ table: string; column: string }>;\n readonly indexes?: ReadonlyArray<{\n readonly table: string;\n readonly columns: ReadonlyArray<string>;\n readonly name?: string;\n }>;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n codecs?: Record<string, string>; // alias/param → codec id ('ns/name@v')\n [key: string]: unknown;\n };\n readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;\n readonly refs?: PlanRefs;\n readonly projection?: Record<string, string> | ReadonlyArray<string>;\n /**\n * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).\n * Used for codec resolution when AST+refs don't provide enough type info.\n */\n readonly projectionTypes?: Record<string, string>;\n}\n\n/**\n * Canonical execution plan shape used by runtimes.\n *\n * - Row is the inferred result row type (TypeScript-only).\n * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).\n *\n * The payload executed by the runtime is represented by the sql + params pair\n * for now; future families can specialize this via Ast or additional metadata.\n */\nexport interface ExecutionPlan<Row = unknown, Ast = unknown> {\n readonly sql: string;\n readonly params: readonly unknown[];\n readonly ast?: Ast;\n readonly meta: PlanMeta;\n /**\n * Phantom property to carry the Row generic for type-level utilities.\n * Not set at runtime; used only for ResultType extraction.\n */\n readonly _row?: Row;\n}\n\n/**\n * Utility type to extract the Row type from an ExecutionPlan.\n * Example: `type Row = ResultType<typeof plan>`\n *\n * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).\n * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter\n * for type extraction.\n */\nexport type ResultType<P> = P extends ExecutionPlan<infer R, unknown>\n ? R\n : P extends { readonly _Row?: infer R }\n ? R\n : never;\n\n/**\n * Type guard to check if a contract is a Document contract\n */\nexport function isDocumentContract(contract: unknown): contract is DocumentContract {\n return (\n typeof contract === 'object' &&\n contract !== null &&\n 'targetFamily' in contract &&\n contract.targetFamily === 'document'\n );\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly coreHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n}\n\n// Emitter types - moved from @prisma-next/emitter to shared location\n/**\n * Specifies how to import TypeScript types from a package.\n * Used in extension pack manifests to declare codec and operation type imports.\n */\nexport interface TypesImportSpec {\n readonly package: string;\n readonly named: string;\n readonly alias: string;\n}\n\n/**\n * Validation context passed to TargetFamilyHook.validateTypes().\n * Contains pre-assembled operation registry, type imports, and extension IDs.\n */\nexport interface ValidationContext {\n readonly operationRegistry?: OperationRegistry;\n readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds?: ReadonlyArray<string>;\n}\n\n/**\n * SPI interface for target family hooks that extend emission behavior.\n * Implemented by family-specific emitter hooks (e.g., SQL family).\n */\nexport interface TargetFamilyHook {\n readonly id: string;\n\n /**\n * Validates that all type IDs in the contract come from referenced extensions.\n * @param ir - Contract IR to validate\n * @param ctx - Validation context with operation registry and extension IDs\n */\n validateTypes(ir: ContractIR, ctx: ValidationContext): void;\n\n /**\n * Validates family-specific contract structure.\n * @param ir - Contract IR to validate\n */\n validateStructure(ir: ContractIR): void;\n\n /**\n * Generates contract.d.ts file content.\n * @param ir - Contract IR\n * @param codecTypeImports - Array of codec type import specs\n * @param operationTypeImports - Array of operation type import specs\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n ): string;\n}\n\n// Extension pack manifest types - moved from @prisma-next/core-control-plane to shared location\nexport type ArgSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'param' }\n | { readonly kind: 'literal' };\n\nexport type ReturnSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };\n\nexport interface LoweringSpecManifest {\n readonly targetFamily: 'sql';\n readonly strategy: 'infix' | 'function';\n readonly template: string;\n}\n\nexport interface OperationManifest {\n readonly for: string;\n readonly method: string;\n readonly args: ReadonlyArray<ArgSpecManifest>;\n readonly returns: ReturnSpecManifest;\n readonly lowering: LoweringSpecManifest;\n readonly capabilities?: ReadonlyArray<string>;\n}\n\nexport interface ExtensionPackManifest {\n readonly id: string;\n readonly version: string;\n readonly targets?: Record<string, { readonly minVersion?: string }>;\n readonly capabilities?: Record<string, unknown>;\n readonly types?: {\n readonly codecTypes?: {\n readonly import: TypesImportSpec;\n };\n readonly operationTypes?: {\n readonly import: TypesImportSpec;\n };\n readonly storage?: readonly {\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string;\n }[];\n };\n readonly operations?: ReadonlyArray<OperationManifest>;\n}\n\nexport interface ExtensionPack {\n readonly manifest: ExtensionPackManifest;\n readonly path: string;\n}\n"],"mappings":";AA8IO,SAAS,mBAAmB,UAAiD;AAClF,SACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB;AAE9B;","names":[]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.1.0-dev.17",
3
+ "version": "0.1.0-dev.18",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Data contract type definitions and JSON schema for Prisma Next",
7
7
  "dependencies": {
8
- "@prisma-next/operations": "0.1.0-dev.17"
8
+ "@prisma-next/operations": "0.1.0-dev.18"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@vitest/coverage-v8": "^2.1.1",
@@ -31,6 +31,10 @@
31
31
  "types": "./dist/exports/ir.d.ts",
32
32
  "import": "./dist/exports/ir.js"
33
33
  },
34
+ "./framework-components": {
35
+ "types": "./dist/exports/framework-components.d.ts",
36
+ "import": "./dist/exports/framework-components.js"
37
+ },
34
38
  "./schema-document": "./schemas/data-contract-document-v1.json"
35
39
  },
36
40
  "scripts": {