@prisma-next/contract 0.3.0-dev.9 → 0.3.0-dev.90
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/LICENSE +201 -0
- package/README.md +42 -6
- package/dist/framework-components.d.mts +529 -0
- package/dist/framework-components.d.mts.map +1 -0
- package/dist/framework-components.mjs +70 -0
- package/dist/framework-components.mjs.map +1 -0
- package/dist/ir-C9rRU5WS.d.mts +84 -0
- package/dist/ir-C9rRU5WS.d.mts.map +1 -0
- package/dist/ir.d.mts +2 -0
- package/dist/ir.mjs +51 -0
- package/dist/ir.mjs.map +1 -0
- package/dist/types-54JRJq9p.d.mts +395 -0
- package/dist/types-54JRJq9p.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +30 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +24 -28
- package/schemas/data-contract-document-v1.json +9 -4
- package/src/exports/framework-components.ts +10 -1
- package/src/exports/types.ts +31 -7
- package/src/framework-components.ts +179 -46
- package/src/ir.ts +28 -12
- package/src/types.ts +274 -37
- package/dist/exports/framework-components.d.ts +0 -3
- package/dist/exports/framework-components.d.ts.map +0 -1
- package/dist/exports/framework-components.js +0 -24
- package/dist/exports/framework-components.js.map +0 -1
- package/dist/exports/ir.d.ts +0 -2
- package/dist/exports/ir.d.ts.map +0 -1
- package/dist/exports/ir.js +0 -35
- package/dist/exports/ir.js.map +0 -1
- package/dist/exports/pack-manifest-types.d.ts +0 -2
- package/dist/exports/pack-manifest-types.d.ts.map +0 -1
- package/dist/exports/pack-manifest-types.js +0 -1
- package/dist/exports/pack-manifest-types.js.map +0 -1
- package/dist/exports/types.d.ts +0 -3
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -8
- package/dist/exports/types.js.map +0 -1
- package/dist/framework-components.d.ts +0 -408
- package/dist/framework-components.d.ts.map +0 -1
- package/dist/ir.d.ts +0 -76
- package/dist/ir.d.ts.map +0 -1
- package/dist/types.d.ts +0 -222
- package/dist/types.d.ts.map +0 -1
- package/src/exports/pack-manifest-types.ts +0 -6
package/src/types.ts
CHANGED
|
@@ -1,16 +1,76 @@
|
|
|
1
1
|
import type { OperationRegistry } from '@prisma-next/operations';
|
|
2
2
|
import type { ContractIR } from './ir';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Unique symbol used as the key for branding types.
|
|
6
|
+
*/
|
|
7
|
+
export const $: unique symbol = Symbol('__prisma_next_brand__');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A helper type to brand a given type with a unique identifier.
|
|
11
|
+
*
|
|
12
|
+
* @template TKey Text used as the brand key.
|
|
13
|
+
* @template TValue Optional value associated with the brand key. Defaults to `true`.
|
|
14
|
+
*/
|
|
15
|
+
export type Brand<TKey extends string | number | symbol, TValue = true> = {
|
|
16
|
+
[$]: {
|
|
17
|
+
[K in TKey]: TValue;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Context passed to type renderers during contract.d.ts generation.
|
|
23
|
+
*/
|
|
24
|
+
export interface RenderTypeContext {
|
|
25
|
+
/** The name of the CodecTypes type alias (typically 'CodecTypes') */
|
|
26
|
+
readonly codecTypesName: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Base type for storage contract hashes.
|
|
31
|
+
* Emitted contract.d.ts files use this with the hash value as a type parameter:
|
|
32
|
+
* `type StorageHash = StorageHashBase<'sha256:abc123...'>`
|
|
33
|
+
*/
|
|
34
|
+
export type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Base type for execution contract hashes.
|
|
38
|
+
* Emitted contract.d.ts files use this with the hash value as a type parameter:
|
|
39
|
+
* `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`
|
|
40
|
+
*/
|
|
41
|
+
export type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;
|
|
42
|
+
|
|
43
|
+
export function coreHash<const T extends string>(value: T): StorageHashBase<T> {
|
|
44
|
+
return value as StorageHashBase<T>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Base type for profile contract hashes.
|
|
49
|
+
* Emitted contract.d.ts files use this with the hash value as a type parameter:
|
|
50
|
+
* `type ProfileHash = ProfileHashBase<'sha256:def456...'>`
|
|
51
|
+
*/
|
|
52
|
+
export type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;
|
|
53
|
+
|
|
54
|
+
export function profileHash<const T extends string>(value: T): ProfileHashBase<T> {
|
|
55
|
+
return value as ProfileHashBase<T>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ContractBase<
|
|
59
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
60
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
61
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
62
|
+
> {
|
|
5
63
|
readonly schemaVersion: string;
|
|
6
64
|
readonly target: string;
|
|
7
65
|
readonly targetFamily: string;
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
66
|
+
readonly storageHash: TStorageHash;
|
|
67
|
+
readonly executionHash?: TExecutionHash | undefined;
|
|
68
|
+
readonly profileHash?: TProfileHash | undefined;
|
|
69
|
+
readonly capabilities: Record<string, Record<string, boolean>>;
|
|
70
|
+
readonly extensionPacks: Record<string, unknown>;
|
|
71
|
+
readonly meta: Record<string, unknown>;
|
|
72
|
+
readonly sources: Record<string, Source>;
|
|
73
|
+
readonly execution?: ExecutionSection;
|
|
14
74
|
}
|
|
15
75
|
|
|
16
76
|
export interface FieldType {
|
|
@@ -20,6 +80,78 @@ export interface FieldType {
|
|
|
20
80
|
readonly properties?: Record<string, FieldType>;
|
|
21
81
|
}
|
|
22
82
|
|
|
83
|
+
export type GeneratedValueSpec = {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly params?: Record<string, unknown>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
89
|
+
|
|
90
|
+
export type JsonValue =
|
|
91
|
+
| JsonPrimitive
|
|
92
|
+
| { readonly [key: string]: JsonValue }
|
|
93
|
+
| readonly JsonValue[];
|
|
94
|
+
|
|
95
|
+
export type TaggedBigInt = { readonly $type: 'bigint'; readonly value: string };
|
|
96
|
+
|
|
97
|
+
export function isTaggedBigInt(value: unknown): value is TaggedBigInt {
|
|
98
|
+
return (
|
|
99
|
+
typeof value === 'object' &&
|
|
100
|
+
value !== null &&
|
|
101
|
+
(value as { $type?: unknown }).$type === 'bigint' &&
|
|
102
|
+
typeof (value as { value?: unknown }).value === 'string'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function bigintJsonReplacer(_key: string, value: unknown): unknown {
|
|
107
|
+
if (typeof value === 'bigint') {
|
|
108
|
+
return { $type: 'bigint', value: value.toString() } satisfies TaggedBigInt;
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type TaggedRaw = { readonly $type: 'raw'; readonly value: JsonValue };
|
|
114
|
+
|
|
115
|
+
export function isTaggedRaw(value: unknown): value is TaggedRaw {
|
|
116
|
+
return (
|
|
117
|
+
typeof value === 'object' &&
|
|
118
|
+
value !== null &&
|
|
119
|
+
(value as { $type?: unknown }).$type === 'raw' &&
|
|
120
|
+
'value' in (value as object)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type TaggedLiteralValue = TaggedBigInt | TaggedRaw;
|
|
125
|
+
|
|
126
|
+
export type ColumnDefaultLiteralValue = JsonValue | TaggedLiteralValue;
|
|
127
|
+
|
|
128
|
+
export type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | bigint | Date;
|
|
129
|
+
|
|
130
|
+
export type ColumnDefault =
|
|
131
|
+
| {
|
|
132
|
+
readonly kind: 'literal';
|
|
133
|
+
readonly value: ColumnDefaultLiteralInputValue;
|
|
134
|
+
}
|
|
135
|
+
| { readonly kind: 'function'; readonly expression: string };
|
|
136
|
+
|
|
137
|
+
export type ExecutionMutationDefaultValue = {
|
|
138
|
+
readonly kind: 'generator';
|
|
139
|
+
readonly id: GeneratedValueSpec['id'];
|
|
140
|
+
readonly params?: Record<string, unknown>;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type ExecutionMutationDefault = {
|
|
144
|
+
readonly ref: { readonly table: string; readonly column: string };
|
|
145
|
+
readonly onCreate?: ExecutionMutationDefaultValue;
|
|
146
|
+
readonly onUpdate?: ExecutionMutationDefaultValue;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export type ExecutionSection = {
|
|
150
|
+
readonly mutations: {
|
|
151
|
+
readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
23
155
|
export interface Source {
|
|
24
156
|
readonly readOnly: boolean;
|
|
25
157
|
readonly projection: Record<string, FieldType>;
|
|
@@ -42,7 +174,7 @@ export type Expr =
|
|
|
42
174
|
export interface DocCollection {
|
|
43
175
|
readonly name: string;
|
|
44
176
|
readonly id?: {
|
|
45
|
-
readonly strategy: 'auto' | 'client' | 'uuid' | '
|
|
177
|
+
readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';
|
|
46
178
|
};
|
|
47
179
|
readonly fields: Record<string, FieldType>;
|
|
48
180
|
readonly indexes?: ReadonlyArray<DocIndex>;
|
|
@@ -55,7 +187,11 @@ export interface DocumentStorage {
|
|
|
55
187
|
};
|
|
56
188
|
}
|
|
57
189
|
|
|
58
|
-
export interface DocumentContract
|
|
190
|
+
export interface DocumentContract<
|
|
191
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
192
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
193
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
194
|
+
> extends ContractBase<TStorageHash, TExecutionHash, TProfileHash> {
|
|
59
195
|
// Accept string to work with JSON imports; runtime validation ensures 'document'
|
|
60
196
|
readonly targetFamily: string;
|
|
61
197
|
readonly storage: DocumentStorage;
|
|
@@ -68,7 +204,7 @@ export interface ParamDescriptor {
|
|
|
68
204
|
readonly codecId?: string;
|
|
69
205
|
readonly nativeType?: string;
|
|
70
206
|
readonly nullable?: boolean;
|
|
71
|
-
readonly source: 'dsl' | 'raw';
|
|
207
|
+
readonly source: 'dsl' | 'raw' | 'lane';
|
|
72
208
|
readonly refs?: { table: string; column: string };
|
|
73
209
|
}
|
|
74
210
|
|
|
@@ -85,7 +221,7 @@ export interface PlanRefs {
|
|
|
85
221
|
export interface PlanMeta {
|
|
86
222
|
readonly target: string;
|
|
87
223
|
readonly targetFamily?: string;
|
|
88
|
-
readonly
|
|
224
|
+
readonly storageHash: string;
|
|
89
225
|
readonly profileHash?: string;
|
|
90
226
|
readonly lane: string;
|
|
91
227
|
readonly annotations?: {
|
|
@@ -131,11 +267,8 @@ export interface ExecutionPlan<Row = unknown, Ast = unknown> {
|
|
|
131
267
|
* SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter
|
|
132
268
|
* for type extraction.
|
|
133
269
|
*/
|
|
134
|
-
export type ResultType<P> =
|
|
135
|
-
? R
|
|
136
|
-
: P extends { readonly _Row?: infer R }
|
|
137
|
-
? R
|
|
138
|
-
: never;
|
|
270
|
+
export type ResultType<P> =
|
|
271
|
+
P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : never;
|
|
139
272
|
|
|
140
273
|
/**
|
|
141
274
|
* Type guard to check if a contract is a Document contract
|
|
@@ -154,7 +287,7 @@ export function isDocumentContract(contract: unknown): contract is DocumentContr
|
|
|
154
287
|
* Represents the current contract identity for a database.
|
|
155
288
|
*/
|
|
156
289
|
export interface ContractMarkerRecord {
|
|
157
|
-
readonly
|
|
290
|
+
readonly storageHash: string;
|
|
158
291
|
readonly profileHash: string;
|
|
159
292
|
readonly contractJson: unknown | null;
|
|
160
293
|
readonly canonicalVersion: number | null;
|
|
@@ -183,6 +316,45 @@ export interface ValidationContext {
|
|
|
183
316
|
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
184
317
|
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
185
318
|
readonly extensionIds?: ReadonlyArray<string>;
|
|
319
|
+
/**
|
|
320
|
+
* Parameterized codec descriptors collected from adapters and extensions.
|
|
321
|
+
* Map of codecId → descriptor for quick lookup during type generation.
|
|
322
|
+
*/
|
|
323
|
+
readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Context for rendering parameterized types during contract.d.ts generation.
|
|
328
|
+
* Passed to type renderers so they can reference CodecTypes by name.
|
|
329
|
+
*/
|
|
330
|
+
export interface TypeRenderContext {
|
|
331
|
+
readonly codecTypesName: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* A normalized type renderer for parameterized codecs.
|
|
336
|
+
* This is the interface expected by TargetFamilyHook.generateContractTypes.
|
|
337
|
+
*/
|
|
338
|
+
export interface TypeRenderEntry {
|
|
339
|
+
readonly codecId: string;
|
|
340
|
+
readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Additional options for generateContractTypes.
|
|
345
|
+
*/
|
|
346
|
+
export interface GenerateContractTypesOptions {
|
|
347
|
+
/**
|
|
348
|
+
* Normalized parameterized type renderers, keyed by codecId.
|
|
349
|
+
* When a column has typeParams and a renderer exists for its codecId,
|
|
350
|
+
* the renderer is called to produce the TypeScript type expression.
|
|
351
|
+
*/
|
|
352
|
+
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
353
|
+
/**
|
|
354
|
+
* Type imports for parameterized codecs.
|
|
355
|
+
* These are merged with codec and operation type imports in contract.d.ts.
|
|
356
|
+
*/
|
|
357
|
+
readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
186
358
|
}
|
|
187
359
|
|
|
188
360
|
/**
|
|
@@ -210,36 +382,101 @@ export interface TargetFamilyHook {
|
|
|
210
382
|
* @param ir - Contract IR
|
|
211
383
|
* @param codecTypeImports - Array of codec type import specs
|
|
212
384
|
* @param operationTypeImports - Array of operation type import specs
|
|
385
|
+
* @param hashes - Contract hash values (storageHash, executionHash, profileHash)
|
|
386
|
+
* @param options - Additional options including parameterized type renderers
|
|
213
387
|
* @returns Generated TypeScript type definitions as string
|
|
214
388
|
*/
|
|
215
389
|
generateContractTypes(
|
|
216
390
|
ir: ContractIR,
|
|
217
391
|
codecTypeImports: ReadonlyArray<TypesImportSpec>,
|
|
218
392
|
operationTypeImports: ReadonlyArray<TypesImportSpec>,
|
|
393
|
+
hashes: {
|
|
394
|
+
readonly storageHash: string;
|
|
395
|
+
readonly executionHash?: string;
|
|
396
|
+
readonly profileHash: string;
|
|
397
|
+
},
|
|
398
|
+
options?: GenerateContractTypesOptions,
|
|
219
399
|
): string;
|
|
220
400
|
}
|
|
221
401
|
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
402
|
+
// ============================================================================
|
|
403
|
+
// Parameterized Codec Descriptor Types
|
|
404
|
+
// ============================================================================
|
|
405
|
+
//
|
|
406
|
+
// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).
|
|
407
|
+
// These enable precise TypeScript types for parameterized columns without
|
|
408
|
+
// coupling the SQL family emitter to specific adapter codec IDs.
|
|
409
|
+
//
|
|
410
|
+
// ============================================================================
|
|
227
411
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
412
|
+
/**
|
|
413
|
+
* Declarative type renderer that produces a TypeScript type expression.
|
|
414
|
+
*
|
|
415
|
+
* Renderers can be:
|
|
416
|
+
* - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)
|
|
417
|
+
* - A function that receives typeParams and context and returns a type expression
|
|
418
|
+
*
|
|
419
|
+
* **Prefer template strings** for most cases:
|
|
420
|
+
* - Templates are JSON-serializable (safe for pack-ref metadata)
|
|
421
|
+
* - Templates can be statically analyzed by tooling
|
|
422
|
+
*
|
|
423
|
+
* Function renderers are allowed but have tradeoffs:
|
|
424
|
+
* - Require runtime execution during emission (the emitter runs code)
|
|
425
|
+
* - Not JSON-serializable (can't be stored in contract.json)
|
|
426
|
+
* - The emitted artifacts (contract.json, contract.d.ts) still contain no
|
|
427
|
+
* executable code - this constraint applies to outputs, not the emission process
|
|
428
|
+
*/
|
|
429
|
+
export type TypeRenderer =
|
|
430
|
+
| string
|
|
431
|
+
| ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);
|
|
231
432
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
433
|
+
/**
|
|
434
|
+
* Descriptor for a codec that supports type parameters.
|
|
435
|
+
*
|
|
436
|
+
* Parameterized codecs allow columns to carry additional metadata (typeParams)
|
|
437
|
+
* that affects the generated TypeScript types. For example:
|
|
438
|
+
* - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`
|
|
439
|
+
* - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`
|
|
440
|
+
*
|
|
441
|
+
* The SQL family emitter uses these descriptors to generate precise types
|
|
442
|
+
* without hard-coding knowledge of specific codec IDs.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const vectorCodecDescriptor: ParameterizedCodecDescriptor = {
|
|
447
|
+
* codecId: 'pg/vector@1',
|
|
448
|
+
* outputTypeRenderer: 'Vector<{{length}}>',
|
|
449
|
+
* // Optional: paramsSchema for runtime validation
|
|
450
|
+
* };
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
export interface ParameterizedCodecDescriptor {
|
|
454
|
+
/** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */
|
|
455
|
+
readonly codecId: string;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Renderer for the output (read) type.
|
|
459
|
+
* Can be a template string or function.
|
|
460
|
+
*
|
|
461
|
+
* This is the primary renderer used by SQL emission to generate
|
|
462
|
+
* model field types in contract.d.ts.
|
|
463
|
+
*/
|
|
464
|
+
readonly outputTypeRenderer: TypeRenderer;
|
|
237
465
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Optional renderer for the input (write) type.
|
|
468
|
+
* If not provided, outputTypeRenderer is used for both.
|
|
469
|
+
*
|
|
470
|
+
* **Reserved for future use**: Currently, SQL emission only uses
|
|
471
|
+
* outputTypeRenderer. This field is defined for future support of
|
|
472
|
+
* asymmetric codecs where input and output types differ (e.g., a
|
|
473
|
+
* codec that accepts `string | number` but always returns `number`).
|
|
474
|
+
*/
|
|
475
|
+
readonly inputTypeRenderer?: TypeRenderer;
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Optional import spec for types used by this codec's renderers.
|
|
479
|
+
* The emitter will add this import to contract.d.ts.
|
|
480
|
+
*/
|
|
481
|
+
readonly typesImport?: TypesImportSpec;
|
|
245
482
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export type { AdapterDescriptor, AdapterInstance, AdapterPackRef, ComponentDescriptor, ComponentMetadata, ContractComponentRequirementsCheckInput, ContractComponentRequirementsCheckResult, DriverDescriptor, DriverInstance, DriverPackRef, ExtensionDescriptor, ExtensionInstance, ExtensionPackRef, FamilyDescriptor, FamilyInstance, PackRefBase, TargetBoundComponentDescriptor, TargetDescriptor, TargetInstance, TargetPackRef, } from '../framework-components';
|
|
2
|
-
export { checkContractComponentRequirements } from '../framework-components';
|
|
3
|
-
//# sourceMappingURL=framework-components.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framework-components.d.ts","sourceRoot":"","sources":["../../src/exports/framework-components.ts"],"names":[],"mappings":"AAAA,YAAY,EAEV,iBAAiB,EAEjB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,uCAAuC,EACvC,wCAAwC,EACxC,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,8BAA8B,EAC9B,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/dist/exports/ir.d.ts
DELETED
package/dist/exports/ir.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../src/exports/ir.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
|
package/dist/exports/ir.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// src/ir.ts
|
|
2
|
-
function irHeader(opts) {
|
|
3
|
-
return {
|
|
4
|
-
schemaVersion: "1",
|
|
5
|
-
target: opts.target,
|
|
6
|
-
targetFamily: opts.targetFamily,
|
|
7
|
-
coreHash: opts.coreHash,
|
|
8
|
-
...opts.profileHash !== void 0 && { profileHash: opts.profileHash }
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function irMeta(opts) {
|
|
12
|
-
return {
|
|
13
|
-
capabilities: opts?.capabilities ?? {},
|
|
14
|
-
extensionPacks: opts?.extensionPacks ?? {},
|
|
15
|
-
meta: opts?.meta ?? {},
|
|
16
|
-
sources: opts?.sources ?? {}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function contractIR(opts) {
|
|
20
|
-
return {
|
|
21
|
-
schemaVersion: opts.header.schemaVersion,
|
|
22
|
-
target: opts.header.target,
|
|
23
|
-
targetFamily: opts.header.targetFamily,
|
|
24
|
-
...opts.meta,
|
|
25
|
-
storage: opts.storage,
|
|
26
|
-
models: opts.models,
|
|
27
|
-
relations: opts.relations
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
contractIR,
|
|
32
|
-
irHeader,
|
|
33
|
-
irMeta
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=ir.js.map
|
package/dist/exports/ir.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pack-manifest-types.d.ts","sourceRoot":"","sources":["../../src/exports/pack-manifest-types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=pack-manifest-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/exports/types.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export type { ContractBase, ContractMarkerRecord, DocCollection, DocIndex, DocumentContract, DocumentStorage, ExecutionPlan, Expr, FieldType, OperationManifest, ParamDescriptor, PlanMeta, PlanRefs, ResultType, Source, TargetFamilyHook, TypesImportSpec, ValidationContext, } from '../types';
|
|
2
|
-
export { isDocumentContract } from '../types';
|
|
3
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,IAAI,EACJ,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/exports/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|