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

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-BJr2H3qm.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAQY,cARC,CAQI,EAAA,OAAA,MAAA;;;;;AASjB;AAUA;AAOY,KA1BA,KA0BA,CAAA,aAAiB,MAAA,GAAyB,MAAA,GAAQ,MAAK,EAAA,SAAA,IAAA,CAAA,GAAA;EAEnD,CA3Bb,CAAA,CA2Ba,EAAA,QA1BN,IA0B8C,GA1BvC,MA0BuC,EAAoB;CAAhB;;AAS5D;AAEA;AAA2D,UA9B1C,iBAAA,CA8B0C;EAAoB;EAAhB,SAAA,cAAA,EAAA,MAAA;;AAI/D;;;;;AAGuB,KA3BX,eA2BW,CAAA,cAAA,MAAA,CAAA,GA3B6B,KA2B7B,GA3BqC,KA2BrC,CAAA,aAAA,CAAA;;;;;;AAQE,KA5Bb,iBA4Ba,CAAA,cAAA,MAAA,CAAA,GA5B6B,KA4B7B,GA5BqC,KA4BrC,CAAA,eAAA,CAAA;AACE,iBA3BX,QA2BW,CAAA,gBAAA,MAAA,CAAA,CAAA,KAAA,EA3B6B,CA2B7B,CAAA,EA3BiC,eA2BjC,CA3BiD,CA2BjD,CAAA;;;;;;AAMV,KAxBL,eAwBc,CAAA,cAAA,MAAA,CAAA,GAxB0B,KAwB1B,GAxBkC,KAwBlC,CAAA,aAAA,CAAA;AAGP,iBAzBH,WAyBG,CAAA,gBAAA,MAAA,CAAA,CAAA,KAAA,EAzBwC,CAyBxC,CAAA,EAzB4C,eAyB5C,CAzB4D,CAyB5D,CAAA;AACoB,UAtBtB,YAsBsB,CAAA,qBArBhB,eAqBgB,CAAA,MAAA,CAAA,GArBU,eAqBV,CAAA,MAAA,CAAA,EAAA,uBApBd,iBAoBc,CAAA,MA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AA;IAWc,MAAA,EAAA,MAAA;EAWA,CAAA;;AAMS,UA9QvB,QAAA,CA8QuB;;qBA5QnB;;;;qBACA;;sBAEC;;;;UAKL,QAAA;;;;;;;aAOJ;;;6BAGgB,cAAc;kBACzB;wBACM,yBAAyB;;;;;6BAKpB;;;;;;;;;;;UAYZ;;;iBAGA;iBACA;;;;;kBAKC;;;;;;;;;;KAWN,gBACV,UAAU,sCAAsC;;;;;;iBAKlC,kBAAA,iCAAmD;;;;;UAalD,oBAAA;;;;;sBAKK;;iBAEL;;;;;;UAQA,eAAA;;;;;;;;;UAUA,iBAAA;+BACc;8BACD,cAAc;kCACV,cAAc;0BACtB;;;;;iCAKO,YAAY;;;;;;UAO5B,iBAAA;;;;;;;UAQA,eAAA;;4BAEW,8BAA8B;;;;;UAMzC,4BAAA;;;;;;oCAMmB,YAAY;;;;;sCAKV,cAAc;;;;;;UAOnC,gBAAA;;;;;;;oBAQG,iBAAiB;;;;;wBAMb;;;;;;;;;;4BAYhB,8BACc,cAAc,wCACV,cAAc;;;;eAM1B;;;;;;;;;;;;;;;;;;;KA+BF,YAAA,sBAEE,8BAA8B;;;;;;;;;;;;;;;;;;;;;UAsB3B,4BAAA;;;;;;;;;;+BAWc;;;;;;;;;;+BAWA;;;;;yBAMN"}
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as TypesImportSpec, A as ContractBase, F as DocumentStorage, G as PlanRefs, H as ParamDescriptor, I as ExecutionPlan, J as Source, K as ResultType, L as Expr, M as DocCollection, N as DocIndex, P as DocumentContract, Q as TypeRenderer, R as FieldType, U as ParameterizedCodecDescriptor, V as OperationManifest, W as PlanMeta, X as TypeRenderContext, Y as TargetFamilyHook, Z as TypeRenderEntry, et as ValidationContext, j as ContractMarkerRecord, tt as isDocumentContract, z as GenerateContractTypesOptions } from "./framework-components-CLCmcNJY.mjs";
2
- export { type ContractBase, type ContractMarkerRecord, type DocCollection, type DocIndex, type DocumentContract, type DocumentStorage, type ExecutionPlan, type Expr, type FieldType, type GenerateContractTypesOptions, type OperationManifest, type ParamDescriptor, type ParameterizedCodecDescriptor, type PlanMeta, type PlanRefs, type ResultType, type Source, type TargetFamilyHook, type TypeRenderContext, type TypeRenderEntry, type TypeRenderer, type TypesImportSpec, type ValidationContext, isDocumentContract };
1
+ import { A as TypeRenderEntry, C as ProfileHashBase, D as StorageHashBase, E as Source, F as isDocumentContract, I as profileHash, M as TypesImportSpec, N as ValidationContext, O as TargetFamilyHook, P as coreHash, S as PlanRefs, T as ResultType, _ as GenerateContractTypesOptions, a as ContractMarkerRecord, b as ParameterizedCodecDescriptor, c as DocumentContract, d as ExecutionMutationDefault, f as ExecutionMutationDefaultValue, g as FieldType, h as Expr, i as ContractBase, j as TypeRenderer, k as TypeRenderContext, l as DocumentStorage, m as ExecutionSection, n as Brand, o as DocCollection, p as ExecutionPlan, r as ColumnDefault, s as DocIndex, t as $, u as ExecutionHashBase, v as GeneratedValueSpec, w as RenderTypeContext, x as PlanMeta, y as ParamDescriptor } from "./types-BJr2H3qm.mjs";
2
+ export { type $, type Brand, type ColumnDefault, type ContractBase, type ContractMarkerRecord, type DocCollection, type DocIndex, type DocumentContract, type DocumentStorage, type ExecutionHashBase, type ExecutionMutationDefault, type ExecutionMutationDefaultValue, type ExecutionPlan, type ExecutionSection, type Expr, type FieldType, type GenerateContractTypesOptions, type GeneratedValueSpec, type ParamDescriptor, type ParameterizedCodecDescriptor, type PlanMeta, type PlanRefs, type ProfileHashBase, type RenderTypeContext, type ResultType, type Source, type StorageHashBase, type TargetFamilyHook, type TypeRenderContext, type TypeRenderEntry, type TypeRenderer, type TypesImportSpec, type ValidationContext, coreHash, isDocumentContract, profileHash };
package/dist/types.mjs CHANGED
@@ -1,4 +1,10 @@
1
1
  //#region src/types.ts
2
+ function coreHash(value) {
3
+ return value;
4
+ }
5
+ function profileHash(value) {
6
+ return value;
7
+ }
2
8
  /**
3
9
  * Type guard to check if a contract is a Document contract
4
10
  */
@@ -7,5 +13,5 @@ function isDocumentContract(contract) {
7
13
  }
8
14
 
9
15
  //#endregion
10
- export { isDocumentContract };
16
+ export { coreHash, isDocumentContract, profileHash };
11
17
  //# sourceMappingURL=types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { RenderTypeContext } from './framework-components';\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> =\n P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : 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 * Parameterized codec descriptors collected from adapters and extensions.\n * Map of codecId → descriptor for quick lookup during type generation.\n */\n readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;\n}\n\n/**\n * Context for rendering parameterized types during contract.d.ts generation.\n * Passed to type renderers so they can reference CodecTypes by name.\n */\nexport interface TypeRenderContext {\n readonly codecTypesName: string;\n}\n\n/**\n * A normalized type renderer for parameterized codecs.\n * This is the interface expected by TargetFamilyHook.generateContractTypes.\n */\nexport interface TypeRenderEntry {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;\n}\n\n/**\n * Additional options for generateContractTypes.\n */\nexport interface GenerateContractTypesOptions {\n /**\n * Normalized parameterized type renderers, keyed by codecId.\n * When a column has typeParams and a renderer exists for its codecId,\n * the renderer is called to produce the TypeScript type expression.\n */\n readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;\n /**\n * Type imports for parameterized codecs.\n * These are merged with codec and operation type imports in contract.d.ts.\n */\n readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;\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 * @param options - Additional options including parameterized type renderers\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n options?: GenerateContractTypesOptions,\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\n// ============================================================================\n// Parameterized Codec Descriptor Types\n// ============================================================================\n//\n// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).\n// These enable precise TypeScript types for parameterized columns without\n// coupling the SQL family emitter to specific adapter codec IDs.\n//\n// ============================================================================\n\n// Re-export RenderTypeContext so it's available alongside TypeRenderer\nexport type { RenderTypeContext };\n\n/**\n * Declarative type renderer that produces a TypeScript type expression.\n *\n * Renderers can be:\n * - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)\n * - A function that receives typeParams and context and returns a type expression\n *\n * **Prefer template strings** for most cases:\n * - Templates are JSON-serializable (safe for pack-ref metadata)\n * - Templates can be statically analyzed by tooling\n *\n * Function renderers are allowed but have tradeoffs:\n * - Require runtime execution during emission (the emitter runs code)\n * - Not JSON-serializable (can't be stored in contract.json)\n * - The emitted artifacts (contract.json, contract.d.ts) still contain no\n * executable code - this constraint applies to outputs, not the emission process\n */\nexport type TypeRenderer =\n | string\n | ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);\n\n/**\n * Descriptor for a codec that supports type parameters.\n *\n * Parameterized codecs allow columns to carry additional metadata (typeParams)\n * that affects the generated TypeScript types. For example:\n * - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`\n * - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`\n *\n * The SQL family emitter uses these descriptors to generate precise types\n * without hard-coding knowledge of specific codec IDs.\n *\n * @example\n * ```typescript\n * const vectorCodecDescriptor: ParameterizedCodecDescriptor = {\n * codecId: 'pg/vector@1',\n * outputTypeRenderer: 'Vector<{{length}}>',\n * // Optional: paramsSchema for runtime validation\n * };\n * ```\n */\nexport interface ParameterizedCodecDescriptor {\n /** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */\n readonly codecId: string;\n\n /**\n * Renderer for the output (read) type.\n * Can be a template string or function.\n *\n * This is the primary renderer used by SQL emission to generate\n * model field types in contract.d.ts.\n */\n readonly outputTypeRenderer: TypeRenderer;\n\n /**\n * Optional renderer for the input (write) type.\n * If not provided, outputTypeRenderer is used for both.\n *\n * **Reserved for future use**: Currently, SQL emission only uses\n * outputTypeRenderer. This field is defined for future support of\n * asymmetric codecs where input and output types differ (e.g., a\n * codec that accepts `string | number` but always returns `number`).\n */\n readonly inputTypeRenderer?: TypeRenderer;\n\n /**\n * Optional import spec for types used by this codec's renderers.\n * The emitter will add this import to contract.d.ts.\n */\n readonly typesImport?: TypesImportSpec;\n}\n"],"mappings":";;;;AA4IA,SAAgB,mBAAmB,UAAiD;AAClF,QACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB"}
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { ContractIR } from './ir';\n\n/**\n * Unique symbol used as the key for branding types.\n */\nexport const $: unique symbol = Symbol('__prisma_next_brand__');\n\n/**\n * A helper type to brand a given type with a unique identifier.\n *\n * @template TKey Text used as the brand key.\n * @template TValue Optional value associated with the brand key. Defaults to `true`.\n */\nexport type Brand<TKey extends string | number | symbol, TValue = true> = {\n [$]: {\n [K in TKey]: TValue;\n };\n};\n\n/**\n * Context passed to type renderers during contract.d.ts generation.\n */\nexport interface RenderTypeContext {\n /** The name of the CodecTypes type alias (typically 'CodecTypes') */\n readonly codecTypesName: string;\n}\n\n/**\n * Base type for storage contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type StorageHash = StorageHashBase<'sha256:abc123...'>`\n */\nexport type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;\n\n/**\n * Base type for execution contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`\n */\nexport type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;\n\nexport function coreHash<const T extends string>(value: T): StorageHashBase<T> {\n return value as StorageHashBase<T>;\n}\n\n/**\n * Base type for profile contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`\n */\nexport type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;\n\nexport function profileHash<const T extends string>(value: T): ProfileHashBase<T> {\n return value as ProfileHashBase<T>;\n}\n\nexport interface ContractBase<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly storageHash: TStorageHash;\n readonly executionHash?: TExecutionHash | undefined;\n readonly profileHash?: TProfileHash | undefined;\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 readonly execution?: ExecutionSection;\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 type GeneratedValueSpec = {\n readonly id: 'ulid' | 'nanoid' | 'uuidv7' | 'uuidv4' | 'cuid2' | 'ksuid';\n readonly params?: Record<string, unknown>;\n};\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly expression: string;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\nexport type ExecutionSection = {\n readonly mutations: {\n readonly defaults: ReadonlyArray<ExecutionMutationDefault>;\n };\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' | '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<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> extends ContractBase<TStorageHash, TExecutionHash, TProfileHash> {\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 storageHash: 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> =\n P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : 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 storageHash: 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 * Parameterized codec descriptors collected from adapters and extensions.\n * Map of codecId → descriptor for quick lookup during type generation.\n */\n readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;\n}\n\n/**\n * Context for rendering parameterized types during contract.d.ts generation.\n * Passed to type renderers so they can reference CodecTypes by name.\n */\nexport interface TypeRenderContext {\n readonly codecTypesName: string;\n}\n\n/**\n * A normalized type renderer for parameterized codecs.\n * This is the interface expected by TargetFamilyHook.generateContractTypes.\n */\nexport interface TypeRenderEntry {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;\n}\n\n/**\n * Additional options for generateContractTypes.\n */\nexport interface GenerateContractTypesOptions {\n /**\n * Normalized parameterized type renderers, keyed by codecId.\n * When a column has typeParams and a renderer exists for its codecId,\n * the renderer is called to produce the TypeScript type expression.\n */\n readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;\n /**\n * Type imports for parameterized codecs.\n * These are merged with codec and operation type imports in contract.d.ts.\n */\n readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;\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 * @param hashes - Contract hash values (storageHash, executionHash, profileHash)\n * @param options - Additional options including parameterized type renderers\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n ): string;\n}\n\n// ============================================================================\n// Parameterized Codec Descriptor Types\n// ============================================================================\n//\n// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).\n// These enable precise TypeScript types for parameterized columns without\n// coupling the SQL family emitter to specific adapter codec IDs.\n//\n// ============================================================================\n\n/**\n * Declarative type renderer that produces a TypeScript type expression.\n *\n * Renderers can be:\n * - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)\n * - A function that receives typeParams and context and returns a type expression\n *\n * **Prefer template strings** for most cases:\n * - Templates are JSON-serializable (safe for pack-ref metadata)\n * - Templates can be statically analyzed by tooling\n *\n * Function renderers are allowed but have tradeoffs:\n * - Require runtime execution during emission (the emitter runs code)\n * - Not JSON-serializable (can't be stored in contract.json)\n * - The emitted artifacts (contract.json, contract.d.ts) still contain no\n * executable code - this constraint applies to outputs, not the emission process\n */\nexport type TypeRenderer =\n | string\n | ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);\n\n/**\n * Descriptor for a codec that supports type parameters.\n *\n * Parameterized codecs allow columns to carry additional metadata (typeParams)\n * that affects the generated TypeScript types. For example:\n * - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`\n * - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`\n *\n * The SQL family emitter uses these descriptors to generate precise types\n * without hard-coding knowledge of specific codec IDs.\n *\n * @example\n * ```typescript\n * const vectorCodecDescriptor: ParameterizedCodecDescriptor = {\n * codecId: 'pg/vector@1',\n * outputTypeRenderer: 'Vector<{{length}}>',\n * // Optional: paramsSchema for runtime validation\n * };\n * ```\n */\nexport interface ParameterizedCodecDescriptor {\n /** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */\n readonly codecId: string;\n\n /**\n * Renderer for the output (read) type.\n * Can be a template string or function.\n *\n * This is the primary renderer used by SQL emission to generate\n * model field types in contract.d.ts.\n */\n readonly outputTypeRenderer: TypeRenderer;\n\n /**\n * Optional renderer for the input (write) type.\n * If not provided, outputTypeRenderer is used for both.\n *\n * **Reserved for future use**: Currently, SQL emission only uses\n * outputTypeRenderer. This field is defined for future support of\n * asymmetric codecs where input and output types differ (e.g., a\n * codec that accepts `string | number` but always returns `number`).\n */\n readonly inputTypeRenderer?: TypeRenderer;\n\n /**\n * Optional import spec for types used by this codec's renderers.\n * The emitter will add this import to contract.d.ts.\n */\n readonly typesImport?: TypesImportSpec;\n}\n"],"mappings":";AA0CA,SAAgB,SAAiC,OAA8B;AAC7E,QAAO;;AAUT,SAAgB,YAAoC,OAA8B;AAChF,QAAO;;;;;AAmLT,SAAgB,mBAAmB,UAAiD;AAClF,QACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB"}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.3.0-dev.34",
3
+ "version": "0.3.0-dev.35",
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.3.0-dev.34"
8
+ "@prisma-next/operations": "0.3.0-dev.35"
9
9
  },
10
10
  "devDependencies": {
11
11
  "tsdown": "0.18.4",
12
12
  "typescript": "5.9.3",
13
- "vitest": "4.0.16",
13
+ "vitest": "4.0.17",
14
14
  "@prisma-next/test-utils": "0.0.1",
15
15
  "@prisma-next/tsconfig": "0.0.0",
16
16
  "@prisma-next/tsdown": "0.0.0"
@@ -26,10 +26,14 @@
26
26
  "exports": {
27
27
  "./framework-components": "./dist/framework-components.mjs",
28
28
  "./ir": "./dist/ir.mjs",
29
- "./pack-manifest-types": "./dist/pack-manifest-types.mjs",
30
29
  "./types": "./dist/types.mjs",
31
30
  "./package.json": "./package.json"
32
31
  },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/prisma/prisma-next.git",
35
+ "directory": "packages/1-framework/1-core/shared/contract"
36
+ },
33
37
  "scripts": {
34
38
  "build": "tsdown",
35
39
  "test": "vitest run --passWithNoTests",
@@ -24,10 +24,15 @@
24
24
  "enum": ["document"],
25
25
  "description": "Target family classification"
26
26
  },
27
- "coreHash": {
27
+ "storageHash": {
28
28
  "type": "string",
29
29
  "pattern": "^sha256:[a-f0-9]{64}$",
30
- "description": "SHA-256 hash of the core schema structure (models, fields, relations, storage layout)"
30
+ "description": "SHA-256 hash of the storage section (DB-satisfied expectations)"
31
+ },
32
+ "executionHash": {
33
+ "type": "string",
34
+ "pattern": "^sha256:[a-f0-9]{64}$",
35
+ "description": "SHA-256 hash of the execution section (client-side behavior)"
31
36
  },
32
37
  "profileHash": {
33
38
  "type": "string",
@@ -85,7 +90,7 @@
85
90
  "required": ["document"]
86
91
  }
87
92
  },
88
- "required": ["schemaVersion", "target", "targetFamily", "coreHash", "storage"],
93
+ "required": ["schemaVersion", "target", "targetFamily", "storageHash", "storage"],
89
94
  "$defs": {
90
95
  "DocCollection": {
91
96
  "type": "object",
@@ -103,7 +108,7 @@
103
108
  "properties": {
104
109
  "strategy": {
105
110
  "type": "string",
106
- "enum": ["auto", "client", "uuid", "cuid", "objectId"],
111
+ "enum": ["auto", "client", "uuid", "objectId"],
107
112
  "description": "ID generation strategy"
108
113
  }
109
114
  }
@@ -19,7 +19,6 @@ export type {
19
19
  // Type renderers for parameterized codec emission
20
20
  NormalizedTypeRenderer,
21
21
  PackRefBase,
22
- RenderTypeContext,
23
22
  TargetBoundComponentDescriptor,
24
23
  TargetDescriptor,
25
24
  TargetInstance,
@@ -1,27 +1,31 @@
1
- // Shared types
2
- // Document family types
3
- // Plan types - target-family agnostic execution types
4
- // Emitter types (moved from @prisma-next/emitter)
5
- // Parameterized codec descriptor types
6
1
  export type {
2
+ $,
3
+ Brand,
4
+ ColumnDefault,
7
5
  ContractBase,
8
6
  ContractMarkerRecord,
9
7
  DocCollection,
10
8
  DocIndex,
11
9
  DocumentContract,
12
10
  DocumentStorage,
11
+ ExecutionHashBase,
12
+ ExecutionMutationDefault,
13
+ ExecutionMutationDefaultValue,
13
14
  ExecutionPlan,
15
+ ExecutionSection,
14
16
  Expr,
15
17
  FieldType,
16
- // Type generation options for parameterized codecs
17
18
  GenerateContractTypesOptions,
18
- OperationManifest,
19
+ GeneratedValueSpec,
19
20
  ParamDescriptor,
20
21
  ParameterizedCodecDescriptor,
21
22
  PlanMeta,
22
23
  PlanRefs,
24
+ ProfileHashBase,
25
+ RenderTypeContext,
23
26
  ResultType,
24
27
  Source,
28
+ StorageHashBase,
25
29
  TargetFamilyHook,
26
30
  TypeRenderContext,
27
31
  TypeRenderEntry,
@@ -29,5 +33,4 @@ export type {
29
33
  TypesImportSpec,
30
34
  ValidationContext,
31
35
  } from '../types';
32
- // Type guards
33
- export { isDocumentContract } from '../types';
36
+ export { coreHash, isDocumentContract, profileHash } from '../types';
@@ -1,27 +1,4 @@
1
- import type { OperationManifest, TypesImportSpec } from './types';
2
-
3
- // ============================================================================
4
- // Type Renderer Types (for parameterized codec emission)
5
- // ============================================================================
6
- //
7
- // TypeRenderer supports author-friendly authoring (template strings) that are
8
- // normalized to functions during pack assembly. The emitter only receives
9
- // normalized (function-form) renderers.
10
- //
11
- // Lifecycle:
12
- // 1. Authoring: Descriptor author uses template string or function
13
- // 2. Assembly: Templates are compiled to functions via normalizeRenderer()
14
- // 3. Emission: Emitter calls normalized render functions
15
- //
16
- // ============================================================================
17
-
18
- /**
19
- * Context passed to type renderers during contract.d.ts generation.
20
- */
21
- export interface RenderTypeContext {
22
- /** The name of the CodecTypes type alias (typically 'CodecTypes') */
23
- readonly codecTypesName: string;
24
- }
1
+ import type { RenderTypeContext, TypesImportSpec } from './types';
25
2
 
26
3
  /**
27
4
  * A template-based type renderer (structured form).
@@ -172,38 +149,8 @@ export function normalizeRenderer(codecId: string, renderer: TypeRenderer): Norm
172
149
  };
173
150
  }
174
151
 
175
- // ============================================================================
176
- // Framework Component Descriptor Base Types
177
- // ============================================================================
178
- //
179
- // Prisma Next uses a modular architecture where functionality is composed from
180
- // discrete "components". Each component has a descriptor that identifies it and
181
- // provides metadata. These base types define the shared structure for all
182
- // component descriptors across both control-plane (CLI/tooling) and runtime-plane.
183
- //
184
- // Component Hierarchy:
185
- //
186
- // Family (e.g., 'sql', 'document')
187
- // └── Target (e.g., 'postgres', 'mysql', 'mongodb')
188
- // ├── Adapter (protocol/dialect implementation)
189
- // ├── Driver (connection/execution layer)
190
- // └── Extension (optional capabilities like pgvector)
191
- //
192
- // Key design decisions:
193
- // - "Component" terminology separates framework building blocks from delivery
194
- // mechanism ("pack" refers to how components are packaged/distributed)
195
- // - `kind` is extensible (Kind extends string) - no closed union, allowing
196
- // ecosystem authors to define new component kinds
197
- // - Target-bound descriptors are generic in TFamilyId and TTargetId for type-safe
198
- // composition (e.g., TypeScript rejects Postgres adapter with MySQL target)
199
- // - Descriptors own declarative fields directly (version, types, operations, etc.)
200
- // rather than nesting them under a `manifest` property
201
- //
202
- // ============================================================================
203
-
204
152
  /**
205
153
  * Declarative fields that describe component metadata.
206
- * These fields are owned directly by descriptors (not nested under a manifest).
207
154
  */
208
155
  export interface ComponentMetadata {
209
156
  /** Component version (semver) */
@@ -244,6 +191,11 @@ export interface ComponentMetadata {
244
191
  * Example: `Vector<N>` for pgvector renderers that emit `Vector<{{length}}>`
245
192
  */
246
193
  readonly typeImports?: ReadonlyArray<TypesImportSpec>;
194
+ /**
195
+ * Optional control-plane hooks keyed by codecId.
196
+ * Used by family-specific planners/verifiers to handle storage types.
197
+ */
198
+ readonly controlPlaneHooks?: Record<string, unknown>;
247
199
  };
248
200
  readonly operationTypes?: { readonly import: TypesImportSpec };
249
201
  readonly storage?: ReadonlyArray<{
@@ -253,9 +205,6 @@ export interface ComponentMetadata {
253
205
  readonly nativeType?: string;
254
206
  }>;
255
207
  };
256
-
257
- /** Operation manifests for building operation registries */
258
- readonly operations?: ReadonlyArray<OperationManifest>;
259
208
  }
260
209
 
261
210
  /**
@@ -588,17 +537,6 @@ export type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId e
588
537
  | DriverDescriptor<TFamilyId, TTargetId>
589
538
  | ExtensionDescriptor<TFamilyId, TTargetId>;
590
539
 
591
- // ============================================================================
592
- // Framework Component Instance Base Types
593
- // ============================================================================
594
- //
595
- // These are minimal, identity-only interfaces for component instances.
596
- // They carry the component's identity (familyId, targetId) without any
597
- // behavior methods. Plane-specific interfaces (ControlFamilyInstance,
598
- // RuntimeFamilyInstance, etc.) extend these bases and add domain actions.
599
- //
600
- // ============================================================================
601
-
602
540
  /**
603
541
  * Base interface for family instances.
604
542
  *
package/src/ir.ts CHANGED
@@ -1,3 +1,10 @@
1
+ function ifDefined<K extends string, V>(
2
+ key: K,
3
+ value: V | undefined,
4
+ ): Record<never, never> | { [P in K]: V } {
5
+ return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};
6
+ }
7
+
1
8
  /**
2
9
  * ContractIR types and factories for building contract intermediate representation.
3
10
  * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.
@@ -6,12 +13,13 @@
6
13
  /**
7
14
  * ContractIR represents the intermediate representation of a contract.
8
15
  * It is family-agnostic and contains generic storage, models, and relations.
9
- * Note: coreHash and profileHash are computed by the emitter, not part of the IR.
16
+ * Note: storageHash/executionHash and profileHash are computed by the emitter, not part of the IR.
10
17
  */
11
18
  export interface ContractIR<
12
19
  TStorage extends Record<string, unknown> = Record<string, unknown>,
13
20
  TModels extends Record<string, unknown> = Record<string, unknown>,
14
21
  TRelations extends Record<string, unknown> = Record<string, unknown>,
22
+ TExecution extends Record<string, unknown> = Record<string, unknown>,
15
23
  > {
16
24
  readonly schemaVersion: string;
17
25
  readonly targetFamily: string;
@@ -19,6 +27,7 @@ export interface ContractIR<
19
27
  readonly models: TModels;
20
28
  readonly relations: TRelations;
21
29
  readonly storage: TStorage;
30
+ readonly execution?: TExecution;
22
31
  readonly extensionPacks: Record<string, unknown>;
23
32
  readonly capabilities: Record<string, Record<string, boolean>>;
24
33
  readonly meta: Record<string, unknown>;
@@ -27,26 +36,29 @@ export interface ContractIR<
27
36
 
28
37
  /**
29
38
  * Creates the header portion of a ContractIR.
30
- * Contains schema version, target, target family, core hash, and optional profile hash.
39
+ * Contains schema version, target, target family, storage hash, and optional profile hash.
31
40
  */
32
41
  export function irHeader(opts: {
33
42
  target: string;
34
43
  targetFamily: string;
35
- coreHash: string;
44
+ storageHash: string;
45
+ executionHash?: string | undefined;
36
46
  profileHash?: string | undefined;
37
47
  }): {
38
48
  readonly schemaVersion: string;
39
49
  readonly target: string;
40
50
  readonly targetFamily: string;
41
- readonly coreHash: string;
51
+ readonly storageHash: string;
52
+ readonly executionHash?: string | undefined;
42
53
  readonly profileHash?: string | undefined;
43
54
  } {
44
55
  return {
45
56
  schemaVersion: '1',
46
57
  target: opts.target,
47
58
  targetFamily: opts.targetFamily,
48
- coreHash: opts.coreHash,
49
- ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),
59
+ storageHash: opts.storageHash,
60
+ ...ifDefined('executionHash', opts.executionHash),
61
+ ...ifDefined('profileHash', opts.profileHash),
50
62
  };
51
63
  }
52
64
 
@@ -82,12 +94,14 @@ export function contractIR<
82
94
  TStorage extends Record<string, unknown>,
83
95
  TModels extends Record<string, unknown>,
84
96
  TRelations extends Record<string, unknown>,
97
+ TExecution extends Record<string, unknown>,
85
98
  >(opts: {
86
99
  header: {
87
100
  readonly schemaVersion: string;
88
101
  readonly target: string;
89
102
  readonly targetFamily: string;
90
- readonly coreHash: string;
103
+ readonly storageHash: string;
104
+ readonly executionHash?: string | undefined;
91
105
  readonly profileHash?: string | undefined;
92
106
  };
93
107
  meta: {
@@ -99,8 +113,9 @@ export function contractIR<
99
113
  storage: TStorage;
100
114
  models: TModels;
101
115
  relations: TRelations;
102
- }): ContractIR<TStorage, TModels, TRelations> {
103
- // ContractIR doesn't include coreHash or profileHash (those are computed by emitter)
116
+ execution?: TExecution;
117
+ }): ContractIR<TStorage, TModels, TRelations, TExecution> {
118
+ // ContractIR doesn't include storageHash/executionHash or profileHash (those are computed by emitter)
104
119
  return {
105
120
  schemaVersion: opts.header.schemaVersion,
106
121
  target: opts.header.target,
@@ -109,5 +124,6 @@ export function contractIR<
109
124
  storage: opts.storage,
110
125
  models: opts.models,
111
126
  relations: opts.relations,
127
+ ...ifDefined('execution', opts.execution),
112
128
  };
113
129
  }