@prisma-next/contract 0.3.0-dev.34 → 0.3.0-dev.36

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/src/types.ts CHANGED
@@ -1,17 +1,76 @@
1
1
  import type { OperationRegistry } from '@prisma-next/operations';
2
- import type { RenderTypeContext } from './framework-components';
3
2
  import type { ContractIR } from './ir';
4
3
 
5
- export interface ContractBase {
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
+ > {
6
63
  readonly schemaVersion: string;
7
64
  readonly target: string;
8
65
  readonly targetFamily: string;
9
- readonly coreHash: string;
10
- readonly profileHash?: string;
66
+ readonly storageHash: TStorageHash;
67
+ readonly executionHash?: TExecutionHash | undefined;
68
+ readonly profileHash?: TProfileHash | undefined;
11
69
  readonly capabilities: Record<string, Record<string, boolean>>;
12
70
  readonly extensionPacks: Record<string, unknown>;
13
71
  readonly meta: Record<string, unknown>;
14
72
  readonly sources: Record<string, Source>;
73
+ readonly execution?: ExecutionSection;
15
74
  }
16
75
 
17
76
  export interface FieldType {
@@ -21,6 +80,36 @@ export interface FieldType {
21
80
  readonly properties?: Record<string, FieldType>;
22
81
  }
23
82
 
83
+ export type GeneratedValueSpec = {
84
+ readonly id: 'ulid' | 'nanoid' | 'uuidv7' | 'uuidv4' | 'cuid2' | 'ksuid';
85
+ readonly params?: Record<string, unknown>;
86
+ };
87
+
88
+ export type ColumnDefault =
89
+ | {
90
+ readonly kind: 'literal';
91
+ readonly expression: string;
92
+ }
93
+ | { readonly kind: 'function'; readonly expression: string };
94
+
95
+ export type ExecutionMutationDefaultValue = {
96
+ readonly kind: 'generator';
97
+ readonly id: GeneratedValueSpec['id'];
98
+ readonly params?: Record<string, unknown>;
99
+ };
100
+
101
+ export type ExecutionMutationDefault = {
102
+ readonly ref: { readonly table: string; readonly column: string };
103
+ readonly onCreate?: ExecutionMutationDefaultValue;
104
+ readonly onUpdate?: ExecutionMutationDefaultValue;
105
+ };
106
+
107
+ export type ExecutionSection = {
108
+ readonly mutations: {
109
+ readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
110
+ };
111
+ };
112
+
24
113
  export interface Source {
25
114
  readonly readOnly: boolean;
26
115
  readonly projection: Record<string, FieldType>;
@@ -43,7 +132,7 @@ export type Expr =
43
132
  export interface DocCollection {
44
133
  readonly name: string;
45
134
  readonly id?: {
46
- readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';
135
+ readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';
47
136
  };
48
137
  readonly fields: Record<string, FieldType>;
49
138
  readonly indexes?: ReadonlyArray<DocIndex>;
@@ -56,7 +145,11 @@ export interface DocumentStorage {
56
145
  };
57
146
  }
58
147
 
59
- export interface DocumentContract extends ContractBase {
148
+ export interface DocumentContract<
149
+ TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
150
+ TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
151
+ TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
152
+ > extends ContractBase<TStorageHash, TExecutionHash, TProfileHash> {
60
153
  // Accept string to work with JSON imports; runtime validation ensures 'document'
61
154
  readonly targetFamily: string;
62
155
  readonly storage: DocumentStorage;
@@ -86,7 +179,7 @@ export interface PlanRefs {
86
179
  export interface PlanMeta {
87
180
  readonly target: string;
88
181
  readonly targetFamily?: string;
89
- readonly coreHash: string;
182
+ readonly storageHash: string;
90
183
  readonly profileHash?: string;
91
184
  readonly lane: string;
92
185
  readonly annotations?: {
@@ -152,7 +245,7 @@ export function isDocumentContract(contract: unknown): contract is DocumentContr
152
245
  * Represents the current contract identity for a database.
153
246
  */
154
247
  export interface ContractMarkerRecord {
155
- readonly coreHash: string;
248
+ readonly storageHash: string;
156
249
  readonly profileHash: string;
157
250
  readonly contractJson: unknown | null;
158
251
  readonly canonicalVersion: number | null;
@@ -247,6 +340,7 @@ export interface TargetFamilyHook {
247
340
  * @param ir - Contract IR
248
341
  * @param codecTypeImports - Array of codec type import specs
249
342
  * @param operationTypeImports - Array of operation type import specs
343
+ * @param hashes - Contract hash values (storageHash, executionHash, profileHash)
250
344
  * @param options - Additional options including parameterized type renderers
251
345
  * @returns Generated TypeScript type definitions as string
252
346
  */
@@ -254,35 +348,15 @@ export interface TargetFamilyHook {
254
348
  ir: ContractIR,
255
349
  codecTypeImports: ReadonlyArray<TypesImportSpec>,
256
350
  operationTypeImports: ReadonlyArray<TypesImportSpec>,
351
+ hashes: {
352
+ readonly storageHash: string;
353
+ readonly executionHash?: string;
354
+ readonly profileHash: string;
355
+ },
257
356
  options?: GenerateContractTypesOptions,
258
357
  ): string;
259
358
  }
260
359
 
261
- // Extension pack manifest types - moved from @prisma-next/core-control-plane to shared location
262
- export type ArgSpecManifest =
263
- | { readonly kind: 'typeId'; readonly type: string }
264
- | { readonly kind: 'param' }
265
- | { readonly kind: 'literal' };
266
-
267
- export type ReturnSpecManifest =
268
- | { readonly kind: 'typeId'; readonly type: string }
269
- | { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };
270
-
271
- export interface LoweringSpecManifest {
272
- readonly targetFamily: 'sql';
273
- readonly strategy: 'infix' | 'function';
274
- readonly template: string;
275
- }
276
-
277
- export interface OperationManifest {
278
- readonly for: string;
279
- readonly method: string;
280
- readonly args: ReadonlyArray<ArgSpecManifest>;
281
- readonly returns: ReturnSpecManifest;
282
- readonly lowering: LoweringSpecManifest;
283
- readonly capabilities?: ReadonlyArray<string>;
284
- }
285
-
286
360
  // ============================================================================
287
361
  // Parameterized Codec Descriptor Types
288
362
  // ============================================================================
@@ -293,9 +367,6 @@ export interface OperationManifest {
293
367
  //
294
368
  // ============================================================================
295
369
 
296
- // Re-export RenderTypeContext so it's available alongside TypeRenderer
297
- export type { RenderTypeContext };
298
-
299
370
  /**
300
371
  * Declarative type renderer that produces a TypeScript type expression.
301
372
  *