@prisma-next/contract 0.1.0-dev.3 → 0.1.0-dev.30

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,68 @@ 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
+ version: '0.0.1',
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
+ version: '0.0.1',
117
+ capabilities: { postgres: { returning: true } },
118
+ };
119
+
120
+ // Identity instance bases are extended by plane-specific instances
121
+ interface MySqlInstance extends FamilyInstance<'sql'> {
122
+ // Plane-specific methods...
123
+ }
124
+ ```
125
+
126
+ The component hierarchy is:
127
+
128
+ ```
129
+ Family (e.g., 'sql', 'document')
130
+ └── Target (e.g., 'postgres', 'mysql', 'mongodb')
131
+ ├── Adapter (protocol/dialect implementation)
132
+ ├── Driver (connection/execution layer)
133
+ └── Extension (optional capabilities like pgvector)
134
+ ```
135
+
136
+ Plane-specific descriptors (`ControlFamilyDescriptor`, `RuntimeTargetDescriptor`, etc.) extend these bases with plane-specific factory methods and capabilities.
137
+
72
138
  ### JSON Schema Validation
73
139
 
74
140
  Reference the appropriate JSON schema in your `contract.json` files to enable IDE validation and autocomplete.
@@ -144,7 +210,7 @@ All contracts share these common fields:
144
210
  - **`coreHash`** (required): SHA-256 hash of the core schema structure
145
211
  - **`profileHash`** (optional): SHA-256 hash of the capability profile
146
212
  - **`capabilities`** (optional): Capability flags declared by the contract
147
- - **`extensions`** (optional): Extension packs and their configuration
213
+ - **`extensionPacks`** (optional): Extension packs and their configuration
148
214
  - **`meta`** (optional): Non-semantic metadata (excluded from hashing)
149
215
  - **`sources`** (optional): Read-only sources (views, etc.) available for querying
150
216
 
@@ -175,7 +241,10 @@ if (isDocumentContract(contract)) {
175
241
 
176
242
  ## Exports
177
243
 
178
- - `./types`: TypeScript type definitions and type guards
244
+ - `./types`: Core contract type definitions, type guards, and emitter SPI types
245
+ - `./framework-components`: Framework component model (descriptors + identity instance bases)
246
+ - `./pack-manifest-types`: Extension pack manifest types
247
+ - `./ir`: Contract IR types
179
248
  - `./schema-document`: Document family JSON Schema (`schemas/data-contract-document-v1.json`)
180
249
 
181
250
  ## Architecture
@@ -0,0 +1,412 @@
1
+ import { TypesImportSpec, OperationManifest } from './types.js';
2
+ import '@prisma-next/operations';
3
+ import './ir.js';
4
+
5
+ /**
6
+ * Declarative fields that describe component metadata.
7
+ * These fields are owned directly by descriptors (not nested under a manifest).
8
+ */
9
+ interface ComponentMetadata {
10
+ /** Component version (semver) */
11
+ readonly version: string;
12
+ /**
13
+ * Capabilities this component provides.
14
+ *
15
+ * For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into
16
+ * the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);
17
+ * keep these declarations in sync. Targets are identifiers/descriptors and typically do not
18
+ * declare capabilities.
19
+ */
20
+ readonly capabilities?: Record<string, unknown>;
21
+ /** Type imports for contract.d.ts generation */
22
+ readonly types?: {
23
+ readonly codecTypes?: {
24
+ readonly import: TypesImportSpec;
25
+ };
26
+ readonly operationTypes?: {
27
+ readonly import: TypesImportSpec;
28
+ };
29
+ readonly storage?: ReadonlyArray<{
30
+ readonly typeId: string;
31
+ readonly familyId: string;
32
+ readonly targetId: string;
33
+ readonly nativeType?: string;
34
+ }>;
35
+ };
36
+ /** Operation manifests for building operation registries */
37
+ readonly operations?: ReadonlyArray<OperationManifest>;
38
+ }
39
+ /**
40
+ * Base descriptor for any framework component.
41
+ *
42
+ * All component descriptors share these fundamental properties that identify
43
+ * the component and provide its metadata. This interface is extended by
44
+ * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
45
+ *
46
+ * @template Kind - Discriminator literal identifying the component type.
47
+ * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',
48
+ * but the type accepts any string to allow ecosystem extensions.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // All descriptors have these properties
53
+ * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)
54
+ * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')
55
+ * descriptor.version // Component version (semver)
56
+ * ```
57
+ */
58
+ interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {
59
+ /** Discriminator identifying the component type */
60
+ readonly kind: Kind;
61
+ /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */
62
+ readonly id: string;
63
+ }
64
+ interface ContractComponentRequirementsCheckInput {
65
+ readonly contract: {
66
+ readonly target: string;
67
+ readonly targetFamily?: string | undefined;
68
+ readonly extensionPacks?: Record<string, unknown> | undefined;
69
+ };
70
+ readonly expectedTargetFamily?: string | undefined;
71
+ readonly expectedTargetId?: string | undefined;
72
+ readonly providedComponentIds: Iterable<string>;
73
+ }
74
+ interface ContractComponentRequirementsCheckResult {
75
+ readonly familyMismatch?: {
76
+ readonly expected: string;
77
+ readonly actual: string;
78
+ } | undefined;
79
+ readonly targetMismatch?: {
80
+ readonly expected: string;
81
+ readonly actual: string;
82
+ } | undefined;
83
+ readonly missingExtensionPackIds: readonly string[];
84
+ }
85
+ declare function checkContractComponentRequirements(input: ContractComponentRequirementsCheckInput): ContractComponentRequirementsCheckResult;
86
+ /**
87
+ * Descriptor for a family component.
88
+ *
89
+ * A "family" represents a category of data sources with shared semantics
90
+ * (e.g., SQL databases, document stores). Families define:
91
+ * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
92
+ * - Contract structure (tables vs collections, columns vs fields)
93
+ * - Type system and codecs
94
+ *
95
+ * Families are the top-level grouping. Each family contains multiple targets
96
+ * (e.g., SQL family contains Postgres, MySQL, SQLite targets).
97
+ *
98
+ * Extended by plane-specific descriptors:
99
+ * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations
100
+ * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods
101
+ *
102
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import sql from '@prisma-next/family-sql/control';
107
+ *
108
+ * sql.kind // 'family'
109
+ * sql.familyId // 'sql'
110
+ * sql.id // 'sql'
111
+ * ```
112
+ */
113
+ interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {
114
+ /** The family identifier (e.g., 'sql', 'document') */
115
+ readonly familyId: TFamilyId;
116
+ }
117
+ /**
118
+ * Descriptor for a target component.
119
+ *
120
+ * A "target" represents a specific database or data store within a family
121
+ * (e.g., Postgres, MySQL, MongoDB). Targets define:
122
+ * - Native type mappings (e.g., Postgres int4 → TypeScript number)
123
+ * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
124
+ *
125
+ * Targets are bound to a family and provide the target-specific implementation
126
+ * details that adapters and drivers use.
127
+ *
128
+ * Extended by plane-specific descriptors:
129
+ * - `ControlTargetDescriptor` - adds optional `migrations` capability
130
+ * - `RuntimeTargetDescriptor` - adds runtime factory method
131
+ *
132
+ * @template TFamilyId - Literal type for the family identifier
133
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import postgres from '@prisma-next/target-postgres/control';
138
+ *
139
+ * postgres.kind // 'target'
140
+ * postgres.familyId // 'sql'
141
+ * postgres.targetId // 'postgres'
142
+ * ```
143
+ */
144
+ interface TargetDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'target'> {
145
+ /** The family this target belongs to */
146
+ readonly familyId: TFamilyId;
147
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
148
+ readonly targetId: TTargetId;
149
+ }
150
+ /**
151
+ * Base shape for any pack reference.
152
+ * Pack refs are pure JSON-friendly objects safe to import in authoring flows.
153
+ */
154
+ interface PackRefBase<Kind extends string, TFamilyId extends string> extends ComponentMetadata {
155
+ readonly kind: Kind;
156
+ readonly id: string;
157
+ readonly familyId: TFamilyId;
158
+ readonly targetId?: string;
159
+ }
160
+ type TargetPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'target', TFamilyId> & {
161
+ readonly targetId: TTargetId;
162
+ };
163
+ type AdapterPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'adapter', TFamilyId> & {
164
+ readonly targetId: TTargetId;
165
+ };
166
+ type ExtensionPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'extension', TFamilyId> & {
167
+ readonly targetId: TTargetId;
168
+ };
169
+ type DriverPackRef<TFamilyId extends string = string, TTargetId extends string = string> = PackRefBase<'driver', TFamilyId> & {
170
+ readonly targetId: TTargetId;
171
+ };
172
+ /**
173
+ * Descriptor for an adapter component.
174
+ *
175
+ * An "adapter" provides the protocol and dialect implementation for a target.
176
+ * Adapters handle:
177
+ * - SQL/query generation (lowering AST to target-specific syntax)
178
+ * - Codec registration (encoding/decoding between JS and wire types)
179
+ * - Type mappings and coercions
180
+ *
181
+ * Adapters are bound to a specific family+target combination and work with
182
+ * any compatible driver for that target.
183
+ *
184
+ * Extended by plane-specific descriptors:
185
+ * - `ControlAdapterDescriptor` - control-plane factory
186
+ * - `RuntimeAdapterDescriptor` - runtime factory
187
+ *
188
+ * @template TFamilyId - Literal type for the family identifier
189
+ * @template TTargetId - Literal type for the target identifier
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * import postgresAdapter from '@prisma-next/adapter-postgres/control';
194
+ *
195
+ * postgresAdapter.kind // 'adapter'
196
+ * postgresAdapter.familyId // 'sql'
197
+ * postgresAdapter.targetId // 'postgres'
198
+ * ```
199
+ */
200
+ interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'adapter'> {
201
+ /** The family this adapter belongs to */
202
+ readonly familyId: TFamilyId;
203
+ /** The target this adapter is designed for */
204
+ readonly targetId: TTargetId;
205
+ }
206
+ /**
207
+ * Descriptor for a driver component.
208
+ *
209
+ * A "driver" provides the connection and execution layer for a target.
210
+ * Drivers handle:
211
+ * - Connection management (pooling, timeouts, retries)
212
+ * - Query execution (sending SQL/commands, receiving results)
213
+ * - Transaction management
214
+ * - Wire protocol communication
215
+ *
216
+ * Drivers are bound to a specific family+target and work with any compatible
217
+ * adapter. Multiple drivers can exist for the same target (e.g., node-postgres
218
+ * vs postgres.js for Postgres).
219
+ *
220
+ * Extended by plane-specific descriptors:
221
+ * - `ControlDriverDescriptor` - creates driver from connection URL
222
+ * - `RuntimeDriverDescriptor` - creates driver with runtime options
223
+ *
224
+ * @template TFamilyId - Literal type for the family identifier
225
+ * @template TTargetId - Literal type for the target identifier
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * import postgresDriver from '@prisma-next/driver-postgres/control';
230
+ *
231
+ * postgresDriver.kind // 'driver'
232
+ * postgresDriver.familyId // 'sql'
233
+ * postgresDriver.targetId // 'postgres'
234
+ * ```
235
+ */
236
+ interface DriverDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'driver'> {
237
+ /** The family this driver belongs to */
238
+ readonly familyId: TFamilyId;
239
+ /** The target this driver connects to */
240
+ readonly targetId: TTargetId;
241
+ }
242
+ /**
243
+ * Descriptor for an extension component.
244
+ *
245
+ * An "extension" adds optional capabilities to a target. Extensions can provide:
246
+ * - Additional operations (e.g., vector similarity search with pgvector)
247
+ * - Custom types and codecs (e.g., vector type)
248
+ * - Extended query capabilities
249
+ *
250
+ * Extensions are bound to a specific family+target and are registered in the
251
+ * config alongside the core components. Multiple extensions can be used together.
252
+ *
253
+ * Extended by plane-specific descriptors:
254
+ * - `ControlExtensionDescriptor` - control-plane extension factory
255
+ * - `RuntimeExtensionDescriptor` - runtime extension factory
256
+ *
257
+ * @template TFamilyId - Literal type for the family identifier
258
+ * @template TTargetId - Literal type for the target identifier
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * import pgvector from '@prisma-next/extension-pgvector/control';
263
+ *
264
+ * pgvector.kind // 'extension'
265
+ * pgvector.familyId // 'sql'
266
+ * pgvector.targetId // 'postgres'
267
+ * ```
268
+ */
269
+ interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string> extends ComponentDescriptor<'extension'> {
270
+ /** The family this extension belongs to */
271
+ readonly familyId: TFamilyId;
272
+ /** The target this extension is designed for */
273
+ readonly targetId: TTargetId;
274
+ }
275
+ /**
276
+ * Union type for target-bound component descriptors.
277
+ *
278
+ * Target-bound components are those that must be compatible with a specific
279
+ * family+target combination. This includes targets, adapters, drivers, and
280
+ * extensions. Families are not target-bound.
281
+ *
282
+ * This type is used in migration and verification interfaces to enforce
283
+ * type-level compatibility between components.
284
+ *
285
+ * @template TFamilyId - Literal type for the family identifier
286
+ * @template TTargetId - Literal type for the target identifier
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * // All these components must have matching familyId and targetId
291
+ * const components: TargetBoundComponentDescriptor<'sql', 'postgres'>[] = [
292
+ * postgresTarget,
293
+ * postgresAdapter,
294
+ * postgresDriver,
295
+ * pgvectorExtension,
296
+ * ];
297
+ * ```
298
+ */
299
+ type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> = TargetDescriptor<TFamilyId, TTargetId> | AdapterDescriptor<TFamilyId, TTargetId> | DriverDescriptor<TFamilyId, TTargetId> | ExtensionDescriptor<TFamilyId, TTargetId>;
300
+ /**
301
+ * Base interface for family instances.
302
+ *
303
+ * A family instance is created by a family descriptor's `create()` method.
304
+ * This base interface carries only the identity; plane-specific interfaces
305
+ * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).
306
+ *
307
+ * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * const instance = sql.create({ target, adapter, driver, extensions });
312
+ * instance.familyId // 'sql'
313
+ * ```
314
+ */
315
+ interface FamilyInstance<TFamilyId extends string> {
316
+ /** The family identifier (e.g., 'sql', 'document') */
317
+ readonly familyId: TFamilyId;
318
+ }
319
+ /**
320
+ * Base interface for target instances.
321
+ *
322
+ * A target instance is created by a target descriptor's `create()` method.
323
+ * This base interface carries only the identity; plane-specific interfaces
324
+ * add target-specific behavior.
325
+ *
326
+ * @template TFamilyId - Literal type for the family identifier
327
+ * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * const instance = postgres.create();
332
+ * instance.familyId // 'sql'
333
+ * instance.targetId // 'postgres'
334
+ * ```
335
+ */
336
+ interface TargetInstance<TFamilyId extends string, TTargetId extends string> {
337
+ /** The family this target belongs to */
338
+ readonly familyId: TFamilyId;
339
+ /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */
340
+ readonly targetId: TTargetId;
341
+ }
342
+ /**
343
+ * Base interface for adapter instances.
344
+ *
345
+ * An adapter instance is created by an adapter descriptor's `create()` method.
346
+ * This base interface carries only the identity; plane-specific interfaces
347
+ * add adapter-specific behavior (e.g., codec registration, query lowering).
348
+ *
349
+ * @template TFamilyId - Literal type for the family identifier
350
+ * @template TTargetId - Literal type for the target identifier
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const instance = postgresAdapter.create();
355
+ * instance.familyId // 'sql'
356
+ * instance.targetId // 'postgres'
357
+ * ```
358
+ */
359
+ interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {
360
+ /** The family this adapter belongs to */
361
+ readonly familyId: TFamilyId;
362
+ /** The target this adapter is designed for */
363
+ readonly targetId: TTargetId;
364
+ }
365
+ /**
366
+ * Base interface for driver instances.
367
+ *
368
+ * A driver instance is created by a driver descriptor's `create()` method.
369
+ * This base interface carries only the identity; plane-specific interfaces
370
+ * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).
371
+ *
372
+ * @template TFamilyId - Literal type for the family identifier
373
+ * @template TTargetId - Literal type for the target identifier
374
+ *
375
+ * @example
376
+ * ```ts
377
+ * const instance = postgresDriver.create({ databaseUrl });
378
+ * instance.familyId // 'sql'
379
+ * instance.targetId // 'postgres'
380
+ * ```
381
+ */
382
+ interface DriverInstance<TFamilyId extends string, TTargetId extends string> {
383
+ /** The family this driver belongs to */
384
+ readonly familyId: TFamilyId;
385
+ /** The target this driver connects to */
386
+ readonly targetId: TTargetId;
387
+ }
388
+ /**
389
+ * Base interface for extension instances.
390
+ *
391
+ * An extension instance is created by an extension descriptor's `create()` method.
392
+ * This base interface carries only the identity; plane-specific interfaces
393
+ * add extension-specific behavior.
394
+ *
395
+ * @template TFamilyId - Literal type for the family identifier
396
+ * @template TTargetId - Literal type for the target identifier
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * const instance = pgvector.create();
401
+ * instance.familyId // 'sql'
402
+ * instance.targetId // 'postgres'
403
+ * ```
404
+ */
405
+ interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {
406
+ /** The family this extension belongs to */
407
+ readonly familyId: TFamilyId;
408
+ /** The target this extension is designed for */
409
+ readonly targetId: TTargetId;
410
+ }
411
+
412
+ 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 PackRefBase, type TargetBoundComponentDescriptor, type TargetDescriptor, type TargetInstance, type TargetPackRef, checkContractComponentRequirements };
@@ -0,0 +1,24 @@
1
+ // src/framework-components.ts
2
+ function checkContractComponentRequirements(input) {
3
+ const providedIds = /* @__PURE__ */ new Set();
4
+ for (const id of input.providedComponentIds) {
5
+ providedIds.add(id);
6
+ }
7
+ const requiredExtensionPackIds = input.contract.extensionPacks ? Object.keys(input.contract.extensionPacks) : [];
8
+ const missingExtensionPackIds = requiredExtensionPackIds.filter((id) => !providedIds.has(id));
9
+ const expectedTargetFamily = input.expectedTargetFamily;
10
+ const contractTargetFamily = input.contract.targetFamily;
11
+ const familyMismatch = expectedTargetFamily !== void 0 && contractTargetFamily !== void 0 && contractTargetFamily !== expectedTargetFamily ? { expected: expectedTargetFamily, actual: contractTargetFamily } : void 0;
12
+ const expectedTargetId = input.expectedTargetId;
13
+ const contractTargetId = input.contract.target;
14
+ const targetMismatch = expectedTargetId !== void 0 && contractTargetId !== expectedTargetId ? { expected: expectedTargetId, actual: contractTargetId } : void 0;
15
+ return {
16
+ ...familyMismatch ? { familyMismatch } : {},
17
+ ...targetMismatch ? { targetMismatch } : {},
18
+ missingExtensionPackIds
19
+ };
20
+ }
21
+ export {
22
+ checkContractComponentRequirements
23
+ };
24
+ //# sourceMappingURL=framework-components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/framework-components.ts"],"sourcesContent":["import type { OperationManifest, TypesImportSpec } from './types';\n\n// ============================================================================\n// Framework Component Descriptor Base Types\n// ============================================================================\n//\n// Prisma Next uses a modular architecture where functionality is composed from\n// discrete \"components\". Each component has a descriptor that identifies it and\n// provides metadata. These base types define the shared structure for all\n// component descriptors across both control-plane (CLI/tooling) and runtime-plane.\n//\n// Component Hierarchy:\n//\n// Family (e.g., 'sql', 'document')\n// └── Target (e.g., 'postgres', 'mysql', 'mongodb')\n// ├── Adapter (protocol/dialect implementation)\n// ├── Driver (connection/execution layer)\n// └── Extension (optional capabilities like pgvector)\n//\n// Key design decisions:\n// - \"Component\" terminology separates framework building blocks from delivery\n// mechanism (\"pack\" refers to how components are packaged/distributed)\n// - `kind` is extensible (Kind extends string) - no closed union, allowing\n// ecosystem authors to define new component kinds\n// - Target-bound descriptors are generic in TFamilyId and TTargetId for type-safe\n// composition (e.g., TypeScript rejects Postgres adapter with MySQL target)\n// - Descriptors own declarative fields directly (version, types, operations, etc.)\n// rather than nesting them under a `manifest` property\n//\n// ============================================================================\n\n/**\n * Declarative fields that describe component metadata.\n * These fields are owned directly by descriptors (not nested under a manifest).\n */\nexport interface ComponentMetadata {\n /** Component version (semver) */\n readonly version: string;\n\n /**\n * Capabilities this component provides.\n *\n * For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into\n * the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);\n * keep these declarations in sync. Targets are identifiers/descriptors and typically do not\n * declare capabilities.\n */\n readonly capabilities?: Record<string, unknown>;\n\n /** Type imports for contract.d.ts generation */\n readonly types?: {\n readonly codecTypes?: { readonly import: TypesImportSpec };\n readonly operationTypes?: { readonly import: TypesImportSpec };\n readonly storage?: ReadonlyArray<{\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string;\n }>;\n };\n\n /** Operation manifests for building operation registries */\n readonly operations?: ReadonlyArray<OperationManifest>;\n}\n\n/**\n * Base descriptor for any framework component.\n *\n * All component descriptors share these fundamental properties that identify\n * the component and provide its metadata. This interface is extended by\n * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).\n *\n * @template Kind - Discriminator literal identifying the component type.\n * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',\n * but the type accepts any string to allow ecosystem extensions.\n *\n * @example\n * ```ts\n * // All descriptors have these properties\n * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)\n * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')\n * descriptor.version // Component version (semver)\n * ```\n */\nexport interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {\n /** Discriminator identifying the component type */\n readonly kind: Kind;\n\n /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */\n readonly id: string;\n}\n\nexport interface ContractComponentRequirementsCheckInput {\n readonly contract: {\n readonly target: string;\n readonly targetFamily?: string | undefined;\n readonly extensionPacks?: Record<string, unknown> | undefined;\n };\n readonly expectedTargetFamily?: string | undefined;\n readonly expectedTargetId?: string | undefined;\n readonly providedComponentIds: Iterable<string>;\n}\n\nexport interface ContractComponentRequirementsCheckResult {\n readonly familyMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly targetMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly missingExtensionPackIds: readonly string[];\n}\n\nexport function checkContractComponentRequirements(\n input: ContractComponentRequirementsCheckInput,\n): ContractComponentRequirementsCheckResult {\n const providedIds = new Set<string>();\n for (const id of input.providedComponentIds) {\n providedIds.add(id);\n }\n\n const requiredExtensionPackIds = input.contract.extensionPacks\n ? Object.keys(input.contract.extensionPacks)\n : [];\n const missingExtensionPackIds = requiredExtensionPackIds.filter((id) => !providedIds.has(id));\n\n const expectedTargetFamily = input.expectedTargetFamily;\n const contractTargetFamily = input.contract.targetFamily;\n const familyMismatch =\n expectedTargetFamily !== undefined &&\n contractTargetFamily !== undefined &&\n contractTargetFamily !== expectedTargetFamily\n ? { expected: expectedTargetFamily, actual: contractTargetFamily }\n : undefined;\n\n const expectedTargetId = input.expectedTargetId;\n const contractTargetId = input.contract.target;\n const targetMismatch =\n expectedTargetId !== undefined && contractTargetId !== expectedTargetId\n ? { expected: expectedTargetId, actual: contractTargetId }\n : undefined;\n\n return {\n ...(familyMismatch ? { familyMismatch } : {}),\n ...(targetMismatch ? { targetMismatch } : {}),\n missingExtensionPackIds,\n };\n}\n\n/**\n * Descriptor for a family component.\n *\n * A \"family\" represents a category of data sources with shared semantics\n * (e.g., SQL databases, document stores). Families define:\n * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)\n * - Contract structure (tables vs collections, columns vs fields)\n * - Type system and codecs\n *\n * Families are the top-level grouping. Each family contains multiple targets\n * (e.g., SQL family contains Postgres, MySQL, SQLite targets).\n *\n * Extended by plane-specific descriptors:\n * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations\n * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * import sql from '@prisma-next/family-sql/control';\n *\n * sql.kind // 'family'\n * sql.familyId // 'sql'\n * sql.id // 'sql'\n * ```\n */\nexport interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Descriptor for a target component.\n *\n * A \"target\" represents a specific database or data store within a family\n * (e.g., Postgres, MySQL, MongoDB). Targets define:\n * - Native type mappings (e.g., Postgres int4 → TypeScript number)\n * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)\n *\n * Targets are bound to a family and provide the target-specific implementation\n * details that adapters and drivers use.\n *\n * Extended by plane-specific descriptors:\n * - `ControlTargetDescriptor` - adds optional `migrations` capability\n * - `RuntimeTargetDescriptor` - adds runtime factory method\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * import postgres from '@prisma-next/target-postgres/control';\n *\n * postgres.kind // 'target'\n * postgres.familyId // 'sql'\n * postgres.targetId // 'postgres'\n * ```\n */\nexport interface TargetDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'target'> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base shape for any pack reference.\n * Pack refs are pure JSON-friendly objects safe to import in authoring flows.\n */\nexport interface PackRefBase<Kind extends string, TFamilyId extends string>\n extends ComponentMetadata {\n readonly kind: Kind;\n readonly id: string;\n readonly familyId: TFamilyId;\n readonly targetId?: string;\n}\n\nexport type TargetPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'target', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type AdapterPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'adapter', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type ExtensionPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'extension', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type DriverPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'driver', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\n/**\n * Descriptor for an adapter component.\n *\n * An \"adapter\" provides the protocol and dialect implementation for a target.\n * Adapters handle:\n * - SQL/query generation (lowering AST to target-specific syntax)\n * - Codec registration (encoding/decoding between JS and wire types)\n * - Type mappings and coercions\n *\n * Adapters are bound to a specific family+target combination and work with\n * any compatible driver for that target.\n *\n * Extended by plane-specific descriptors:\n * - `ControlAdapterDescriptor` - control-plane factory\n * - `RuntimeAdapterDescriptor` - runtime factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresAdapter from '@prisma-next/adapter-postgres/control';\n *\n * postgresAdapter.kind // 'adapter'\n * postgresAdapter.familyId // 'sql'\n * postgresAdapter.targetId // 'postgres'\n * ```\n */\nexport interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'adapter'> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for a driver component.\n *\n * A \"driver\" provides the connection and execution layer for a target.\n * Drivers handle:\n * - Connection management (pooling, timeouts, retries)\n * - Query execution (sending SQL/commands, receiving results)\n * - Transaction management\n * - Wire protocol communication\n *\n * Drivers are bound to a specific family+target and work with any compatible\n * adapter. Multiple drivers can exist for the same target (e.g., node-postgres\n * vs postgres.js for Postgres).\n *\n * Extended by plane-specific descriptors:\n * - `ControlDriverDescriptor` - creates driver from connection URL\n * - `RuntimeDriverDescriptor` - creates driver with runtime options\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresDriver from '@prisma-next/driver-postgres/control';\n *\n * postgresDriver.kind // 'driver'\n * postgresDriver.familyId // 'sql'\n * postgresDriver.targetId // 'postgres'\n * ```\n */\nexport interface DriverDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'driver'> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for an extension component.\n *\n * An \"extension\" adds optional capabilities to a target. Extensions can provide:\n * - Additional operations (e.g., vector similarity search with pgvector)\n * - Custom types and codecs (e.g., vector type)\n * - Extended query capabilities\n *\n * Extensions are bound to a specific family+target and are registered in the\n * config alongside the core components. Multiple extensions can be used together.\n *\n * Extended by plane-specific descriptors:\n * - `ControlExtensionDescriptor` - control-plane extension factory\n * - `RuntimeExtensionDescriptor` - runtime extension factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import pgvector from '@prisma-next/extension-pgvector/control';\n *\n * pgvector.kind // 'extension'\n * pgvector.familyId // 'sql'\n * pgvector.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'extension'> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Union type for target-bound component descriptors.\n *\n * Target-bound components are those that must be compatible with a specific\n * family+target combination. This includes targets, adapters, drivers, and\n * extensions. Families are not target-bound.\n *\n * This type is used in migration and verification interfaces to enforce\n * type-level compatibility between components.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * // All these components must have matching familyId and targetId\n * const components: TargetBoundComponentDescriptor<'sql', 'postgres'>[] = [\n * postgresTarget,\n * postgresAdapter,\n * postgresDriver,\n * pgvectorExtension,\n * ];\n * ```\n */\nexport type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> =\n | TargetDescriptor<TFamilyId, TTargetId>\n | AdapterDescriptor<TFamilyId, TTargetId>\n | DriverDescriptor<TFamilyId, TTargetId>\n | ExtensionDescriptor<TFamilyId, TTargetId>;\n\n// ============================================================================\n// Framework Component Instance Base Types\n// ============================================================================\n//\n// These are minimal, identity-only interfaces for component instances.\n// They carry the component's identity (familyId, targetId) without any\n// behavior methods. Plane-specific interfaces (ControlFamilyInstance,\n// RuntimeFamilyInstance, etc.) extend these bases and add domain actions.\n//\n// ============================================================================\n\n/**\n * Base interface for family instances.\n *\n * A family instance is created by a family descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * const instance = sql.create({ target, adapter, driver, extensions });\n * instance.familyId // 'sql'\n * ```\n */\nexport interface FamilyInstance<TFamilyId extends string> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Base interface for target instances.\n *\n * A target instance is created by a target descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add target-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * const instance = postgres.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface TargetInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for adapter instances.\n *\n * An adapter instance is created by an adapter descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add adapter-specific behavior (e.g., codec registration, query lowering).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresAdapter.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for driver instances.\n *\n * A driver instance is created by a driver descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresDriver.create({ databaseUrl });\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface DriverInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for extension instances.\n *\n * An extension instance is created by an extension descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add extension-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = pgvector.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n"],"mappings":";AA6GO,SAAS,mCACd,OAC0C;AAC1C,QAAM,cAAc,oBAAI,IAAY;AACpC,aAAW,MAAM,MAAM,sBAAsB;AAC3C,gBAAY,IAAI,EAAE;AAAA,EACpB;AAEA,QAAM,2BAA2B,MAAM,SAAS,iBAC5C,OAAO,KAAK,MAAM,SAAS,cAAc,IACzC,CAAC;AACL,QAAM,0BAA0B,yBAAyB,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;AAE5F,QAAM,uBAAuB,MAAM;AACnC,QAAM,uBAAuB,MAAM,SAAS;AAC5C,QAAM,iBACJ,yBAAyB,UACzB,yBAAyB,UACzB,yBAAyB,uBACrB,EAAE,UAAU,sBAAsB,QAAQ,qBAAqB,IAC/D;AAEN,QAAM,mBAAmB,MAAM;AAC/B,QAAM,mBAAmB,MAAM,SAAS;AACxC,QAAM,iBACJ,qBAAqB,UAAa,qBAAqB,mBACnD,EAAE,UAAU,kBAAkB,QAAQ,iBAAiB,IACvD;AAEN,SAAO;AAAA,IACL,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -14,7 +14,7 @@ interface ContractIR<TStorage extends Record<string, unknown> = Record<string, u
14
14
  readonly models: TModels;
15
15
  readonly relations: TRelations;
16
16
  readonly storage: TStorage;
17
- readonly extensions: Record<string, unknown>;
17
+ readonly extensionPacks: Record<string, unknown>;
18
18
  readonly capabilities: Record<string, Record<string, boolean>>;
19
19
  readonly meta: Record<string, unknown>;
20
20
  readonly sources: Record<string, unknown>;
@@ -37,17 +37,17 @@ declare function irHeader(opts: {
37
37
  };
38
38
  /**
39
39
  * Creates the meta portion of a ContractIR.
40
- * Contains capabilities, extensions, meta, and sources with empty object defaults.
40
+ * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.
41
41
  * If a field is explicitly `undefined`, it will be omitted (for testing validation).
42
42
  */
43
43
  declare function irMeta(opts?: {
44
44
  capabilities?: Record<string, Record<string, boolean>> | undefined;
45
- extensions?: Record<string, unknown> | undefined;
45
+ extensionPacks?: Record<string, unknown> | undefined;
46
46
  meta?: Record<string, unknown> | undefined;
47
47
  sources?: Record<string, unknown> | undefined;
48
48
  }): {
49
49
  readonly capabilities: Record<string, Record<string, boolean>>;
50
- readonly extensions: Record<string, unknown>;
50
+ readonly extensionPacks: Record<string, unknown>;
51
51
  readonly meta: Record<string, unknown>;
52
52
  readonly sources: Record<string, unknown>;
53
53
  };
@@ -65,7 +65,7 @@ declare function contractIR<TStorage extends Record<string, unknown>, TModels ex
65
65
  };
66
66
  meta: {
67
67
  readonly capabilities: Record<string, Record<string, boolean>>;
68
- readonly extensions: Record<string, unknown>;
68
+ readonly extensionPacks: Record<string, unknown>;
69
69
  readonly meta: Record<string, unknown>;
70
70
  readonly sources: Record<string, unknown>;
71
71
  };
@@ -11,7 +11,7 @@ function irHeader(opts) {
11
11
  function irMeta(opts) {
12
12
  return {
13
13
  capabilities: opts?.capabilities ?? {},
14
- extensions: opts?.extensions ?? {},
14
+ extensionPacks: opts?.extensionPacks ?? {},
15
15
  meta: opts?.meta ?? {},
16
16
  sources: opts?.sources ?? {}
17
17
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ir.ts"],"sourcesContent":["/**\n * ContractIR types and factories for building contract intermediate representation.\n * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.\n */\n\n/**\n * ContractIR represents the intermediate representation of a contract.\n * It is family-agnostic and contains generic storage, models, and relations.\n * Note: coreHash and profileHash are computed by the emitter, not part of the IR.\n */\nexport interface ContractIR<\n TStorage extends Record<string, unknown> = Record<string, unknown>,\n TModels extends Record<string, unknown> = Record<string, unknown>,\n TRelations extends Record<string, unknown> = Record<string, unknown>,\n> {\n readonly schemaVersion: string;\n readonly targetFamily: string;\n readonly target: string;\n readonly models: TModels;\n readonly relations: TRelations;\n readonly storage: TStorage;\n readonly extensions: Record<string, unknown>;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n}\n\n/**\n * Creates the header portion of a ContractIR.\n * Contains schema version, target, target family, core hash, and optional profile hash.\n */\nexport function irHeader(opts: {\n target: string;\n targetFamily: string;\n coreHash: string;\n profileHash?: string;\n}): {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n} {\n return {\n schemaVersion: '1',\n target: opts.target,\n targetFamily: opts.targetFamily,\n coreHash: opts.coreHash,\n ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),\n };\n}\n\n/**\n * Creates the meta portion of a ContractIR.\n * Contains capabilities, extensions, meta, and sources with empty object defaults.\n * If a field is explicitly `undefined`, it will be omitted (for testing validation).\n */\nexport function irMeta(opts?: {\n capabilities?: Record<string, Record<string, boolean>> | undefined;\n extensions?: Record<string, unknown> | undefined;\n meta?: Record<string, unknown> | undefined;\n sources?: Record<string, unknown> | undefined;\n}): {\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, unknown>;\n} {\n return {\n capabilities: opts?.capabilities ?? {},\n extensions: opts?.extensions ?? {},\n meta: opts?.meta ?? {},\n sources: opts?.sources ?? {},\n };\n}\n\n/**\n * Creates a complete ContractIR by combining header, meta, and family-specific sections.\n * This is a family-agnostic factory that accepts generic storage, models, and relations.\n */\nexport function contractIR<\n TStorage extends Record<string, unknown>,\n TModels extends Record<string, unknown>,\n TRelations extends Record<string, unknown>,\n>(opts: {\n header: {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n };\n meta: {\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, unknown>;\n };\n storage: TStorage;\n models: TModels;\n relations: TRelations;\n}): ContractIR<TStorage, TModels, TRelations> {\n // ContractIR doesn't include coreHash or profileHash (those are computed by emitter)\n return {\n schemaVersion: opts.header.schemaVersion,\n target: opts.header.target,\n targetFamily: opts.header.targetFamily,\n ...opts.meta,\n storage: opts.storage,\n models: opts.models,\n relations: opts.relations,\n };\n}\n"],"mappings":";AA+BO,SAAS,SAAS,MAWvB;AACA,SAAO;AAAA,IACL,eAAe;AAAA,IACf,QAAQ,KAAK;AAAA,IACb,cAAc,KAAK;AAAA,IACnB,UAAU,KAAK;AAAA,IACf,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,YAAY;AAAA,EACxE;AACF;AAOO,SAAS,OAAO,MAUrB;AACA,SAAO;AAAA,IACL,cAAc,MAAM,gBAAgB,CAAC;AAAA,IACrC,YAAY,MAAM,cAAc,CAAC;AAAA,IACjC,MAAM,MAAM,QAAQ,CAAC;AAAA,IACrB,SAAS,MAAM,WAAW,CAAC;AAAA,EAC7B;AACF;AAMO,SAAS,WAId,MAiB4C;AAE5C,SAAO;AAAA,IACL,eAAe,KAAK,OAAO;AAAA,IAC3B,QAAQ,KAAK,OAAO;AAAA,IACpB,cAAc,KAAK,OAAO;AAAA,IAC1B,GAAG,KAAK;AAAA,IACR,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK;AAAA,IACb,WAAW,KAAK;AAAA,EAClB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/ir.ts"],"sourcesContent":["/**\n * ContractIR types and factories for building contract intermediate representation.\n * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.\n */\n\n/**\n * ContractIR represents the intermediate representation of a contract.\n * It is family-agnostic and contains generic storage, models, and relations.\n * Note: coreHash and profileHash are computed by the emitter, not part of the IR.\n */\nexport interface ContractIR<\n TStorage extends Record<string, unknown> = Record<string, unknown>,\n TModels extends Record<string, unknown> = Record<string, unknown>,\n TRelations extends Record<string, unknown> = Record<string, unknown>,\n> {\n readonly schemaVersion: string;\n readonly targetFamily: string;\n readonly target: string;\n readonly models: TModels;\n readonly relations: TRelations;\n readonly storage: TStorage;\n readonly extensionPacks: Record<string, unknown>;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n}\n\n/**\n * Creates the header portion of a ContractIR.\n * Contains schema version, target, target family, core hash, and optional profile hash.\n */\nexport function irHeader(opts: {\n target: string;\n targetFamily: string;\n coreHash: string;\n profileHash?: string;\n}): {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n} {\n return {\n schemaVersion: '1',\n target: opts.target,\n targetFamily: opts.targetFamily,\n coreHash: opts.coreHash,\n ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),\n };\n}\n\n/**\n * Creates the meta portion of a ContractIR.\n * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.\n * If a field is explicitly `undefined`, it will be omitted (for testing validation).\n */\nexport function irMeta(opts?: {\n capabilities?: Record<string, Record<string, boolean>> | undefined;\n extensionPacks?: Record<string, unknown> | undefined;\n meta?: Record<string, unknown> | undefined;\n sources?: Record<string, unknown> | undefined;\n}): {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n} {\n return {\n capabilities: opts?.capabilities ?? {},\n extensionPacks: opts?.extensionPacks ?? {},\n meta: opts?.meta ?? {},\n sources: opts?.sources ?? {},\n };\n}\n\n/**\n * Creates a complete ContractIR by combining header, meta, and family-specific sections.\n * This is a family-agnostic factory that accepts generic storage, models, and relations.\n */\nexport function contractIR<\n TStorage extends Record<string, unknown>,\n TModels extends Record<string, unknown>,\n TRelations extends Record<string, unknown>,\n>(opts: {\n header: {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n };\n meta: {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n };\n storage: TStorage;\n models: TModels;\n relations: TRelations;\n}): ContractIR<TStorage, TModels, TRelations> {\n // ContractIR doesn't include coreHash or profileHash (those are computed by emitter)\n return {\n schemaVersion: opts.header.schemaVersion,\n target: opts.header.target,\n targetFamily: opts.header.targetFamily,\n ...opts.meta,\n storage: opts.storage,\n models: opts.models,\n relations: opts.relations,\n };\n}\n"],"mappings":";AA+BO,SAAS,SAAS,MAWvB;AACA,SAAO;AAAA,IACL,eAAe;AAAA,IACf,QAAQ,KAAK;AAAA,IACb,cAAc,KAAK;AAAA,IACnB,UAAU,KAAK;AAAA,IACf,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,YAAY;AAAA,EACxE;AACF;AAOO,SAAS,OAAO,MAUrB;AACA,SAAO;AAAA,IACL,cAAc,MAAM,gBAAgB,CAAC;AAAA,IACrC,gBAAgB,MAAM,kBAAkB,CAAC;AAAA,IACzC,MAAM,MAAM,QAAQ,CAAC;AAAA,IACrB,SAAS,MAAM,WAAW,CAAC;AAAA,EAC7B;AACF;AAMO,SAAS,WAId,MAiB4C;AAE5C,SAAO;AAAA,IACL,eAAe,KAAK,OAAO;AAAA,IAC3B,QAAQ,KAAK,OAAO;AAAA,IACpB,cAAc,KAAK,OAAO;AAAA,IAC1B,GAAG,KAAK;AAAA,IACR,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK;AAAA,IACb,WAAW,KAAK;AAAA,EAClB;AACF;","names":[]}
@@ -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, L as LoweringSpecManifest, OperationManifest, R as ReturnSpecManifest } from './types.js';
2
2
  import '@prisma-next/operations';
3
3
  import './ir.js';
@@ -8,7 +8,7 @@ interface ContractBase {
8
8
  readonly coreHash: string;
9
9
  readonly profileHash?: string;
10
10
  readonly capabilities?: Record<string, Record<string, boolean>>;
11
- readonly extensions?: Record<string, unknown>;
11
+ readonly extensionPacks?: Record<string, unknown>;
12
12
  readonly meta?: Record<string, unknown>;
13
13
  readonly sources?: Record<string, Source>;
14
14
  }
@@ -173,7 +173,7 @@ interface ValidationContext {
173
173
  interface TargetFamilyHook {
174
174
  readonly id: string;
175
175
  /**
176
- * Validates that all type IDs in the contract come from referenced extensions.
176
+ * Validates that all type IDs in the contract come from referenced extension packs.
177
177
  * @param ir - Contract IR to validate
178
178
  * @param ctx - Validation context with operation registry and extension IDs
179
179
  */
@@ -220,32 +220,5 @@ interface OperationManifest {
220
220
  readonly lowering: LoweringSpecManifest;
221
221
  readonly capabilities?: ReadonlyArray<string>;
222
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
223
 
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 };
224
+ export { type ArgSpecManifest as A, type ContractBase, type ContractMarkerRecord, type DocCollection, type DocIndex, type DocumentContract, type DocumentStorage, type ExecutionPlan, type Expr, type FieldType, type LoweringSpecManifest as L, type OperationManifest, type ParamDescriptor, type PlanMeta, type PlanRefs, type ReturnSpecManifest as R, type ResultType, type Source, type TargetFamilyHook, type TypesImportSpec, type ValidationContext, isDocumentContract };
@@ -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 extensionPacks?: 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 extension packs.\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"],"mappings":";AA8IO,SAAS,mBAAmB,UAAiD;AAClF,SACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB;AAE9B;","names":[]}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.1.0-dev.3",
3
+ "version": "0.1.0-dev.30",
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.3"
8
+ "@prisma-next/operations": "0.1.0-dev.30"
9
9
  },
10
10
  "devDependencies": {
11
- "@vitest/coverage-v8": "^2.1.1",
11
+ "@vitest/coverage-v8": "^4.0.0",
12
12
  "tsup": "^8.3.0",
13
13
  "typescript": "^5.9.3",
14
- "vitest": "^2.1.1",
14
+ "vitest": "^4.0.16",
15
15
  "@prisma-next/test-utils": "0.0.1"
16
16
  },
17
17
  "files": [
@@ -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": {
@@ -38,7 +42,9 @@
38
42
  "test": "vitest run --passWithNoTests",
39
43
  "test:coverage": "vitest run --coverage --passWithNoTests",
40
44
  "typecheck": "tsc --project tsconfig.json --noEmit",
41
- "lint": "biome check . --config-path ../../../biome.json --error-on-warnings",
42
- "clean": "node ../../scripts/clean.mjs"
45
+ "lint": "biome check . --config-path ../../../../../biome.json --error-on-warnings",
46
+ "lint:fix": "biome check --write . --config-path ../../../biome.json",
47
+ "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../biome.json",
48
+ "clean": "node ../../../../../scripts/clean.mjs"
43
49
  }
44
50
  }