@prisma-next/emitter 0.16.0-dev.3 → 0.16.0-dev.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- import { n as generateContractDts, r as getEmittedArtifactPaths, t as emit } from "../exports-Bsc1vgw7.mjs";
1
+ import { n as generateContractDts, r as getEmittedArtifactPaths, t as emit } from "../exports-BTdZ6er3.mjs";
2
2
  import { deduplicateImports, generateCodecTypeIntersection, generateFieldOutputTypesMap, generateHashTypeAliases, generateImportLines, generateModelRelationsType, generateRootsType, serializeObjectKey, serializeValue } from "../domain-type-generation.mjs";
3
3
  export { deduplicateImports, emit, generateCodecTypeIntersection, generateContractDts, generateFieldOutputTypesMap, generateHashTypeAliases, generateImportLines, generateModelRelationsType, generateRootsType, getEmittedArtifactPaths, serializeObjectKey, serializeValue };
@@ -97,7 +97,7 @@ ${domainNamespacesType};
97
97
  };
98
98
  };
99
99
  readonly capabilities: ${serializeValue(contract.capabilities)};
100
- readonly extensionPacks: ${serializeValue(contract.extensionPacks)};${executionClause}
100
+ readonly extensions: ${serializeValue(contract.extensions)};${executionClause}
101
101
  readonly meta: ${serializeValue(contract.meta)};
102
102
  ${valueObjects ? `readonly valueObjects: ${valueObjectsDescriptor};` : ""}
103
103
  readonly profileHash: ProfileHash;
@@ -151,4 +151,4 @@ async function emit(contract, stack, targetFamily, options) {
151
151
  //#endregion
152
152
  export { generateContractDts as n, getEmittedArtifactPaths as r, emit as t };
153
153
 
154
- //# sourceMappingURL=exports-Bsc1vgw7.mjs.map
154
+ //# sourceMappingURL=exports-BTdZ6er3.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports-Bsc1vgw7.mjs","names":[],"sources":["../src/artifact-paths.ts","../src/generate-contract-dts.ts","../src/emit.ts"],"sourcesContent":["const JSON_EXTENSION = '.json';\n\nexport interface EmittedArtifactPaths {\n readonly jsonPath: string;\n readonly dtsPath: string;\n}\n\nexport function getEmittedArtifactPaths(outputJsonPath: string): EmittedArtifactPaths {\n if (!outputJsonPath.endsWith(JSON_EXTENSION)) {\n throw new Error('Contract output path must end with .json');\n }\n\n return {\n jsonPath: outputJsonPath,\n dtsPath: `${outputJsonPath.slice(0, -JSON_EXTENSION.length)}.d.ts`,\n };\n}\n","import type {\n Contract,\n ContractEnum,\n ContractModelBase,\n ContractValueObject,\n} from '@prisma-next/contract/types';\nimport { DomainNamespaceResolutionError } from '@prisma-next/contract/types';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type {\n EmissionSpi,\n GenerateContractTypesOptions,\n TypesImportSpec,\n} from '@prisma-next/framework-components/emission';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport {\n deduplicateImports,\n generateCodecTypeIntersection,\n generateFieldTypesMapsByNamespace,\n generateHashTypeAliases,\n generateImportLines,\n generateModelsType,\n generateRootsType,\n generateValueObjectsDescriptorType,\n generateValueObjectTypeAliases,\n serializeExecutionType,\n serializeObjectKey,\n serializeValue,\n} from './domain-type-generation';\n\nfunction generateEnumBlockType(enums: Record<string, ContractEnum>): string {\n const entries = Object.entries(enums).map(([name, entry]) => {\n const memberTupleItems = entry.members.map(\n (m) =>\n `{ readonly name: ${serializeValue(m.name)}; readonly value: ${serializeValue(m.value)} }`,\n );\n const membersType = `readonly [${memberTupleItems.join(', ')}]`;\n return `readonly ${serializeObjectKey(name)}: { readonly codecId: ${serializeValue(entry.codecId)}; readonly members: ${membersType} }`;\n });\n return `{ ${entries.join('; ')} }`;\n}\n\nexport function generateContractDts(\n contract: Contract,\n emitter: EmissionSpi,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n codecLookup?: CodecLookup,\n): string {\n const allImports: TypesImportSpec[] = [...codecTypeImports];\n if (options?.queryOperationTypeImports) {\n allImports.push(...options.queryOperationTypeImports);\n }\n const uniqueImports = deduplicateImports(allImports);\n const importLines = generateImportLines(uniqueImports);\n\n const familyImportLines = emitter.getFamilyImports();\n\n const hashAliases = generateHashTypeAliases(hashes);\n\n const codecTypes = generateCodecTypeIntersection(codecTypeImports, 'CodecTypes');\n\n const familyTypeAliases = emitter.getFamilyTypeAliases(options);\n\n const typeMapsExpr = emitter.getTypeMapsExpression();\n\n const storageType = emitter.generateStorageType(contract, 'StorageHash');\n\n const namespaceEntries = Object.entries(contract.domain.namespaces);\n if (namespaceEntries.length === 0) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n\n // Validate all namespace entries are present.\n for (const [nsId, ns] of namespaceEntries) {\n if (ns === undefined) {\n throw new Error(`domain namespace \"${nsId}\" is not present on the contract`);\n }\n }\n\n const rootsType = generateRootsType(contract.roots);\n\n // Flatten value objects across all namespaces — first-name-wins on collision.\n const flatValueObjects: Record<string, ContractValueObject> = {};\n for (const [, ns] of namespaceEntries) {\n for (const [voName, vo] of Object.entries(\n blindCast<\n Record<string, ContractValueObject>,\n 'ns.valueObjects is a ContractValueObject record in the emitted IR (default to {} when absent)'\n >(ns.valueObjects ?? {}),\n )) {\n if (!(voName in flatValueObjects)) {\n flatValueObjects[voName] = vo;\n }\n }\n }\n const valueObjects = Object.keys(flatValueObjects).length > 0 ? flatValueObjects : undefined;\n const valueObjectTypeAliases = generateValueObjectTypeAliases(valueObjects, codecLookup);\n const valueObjectsDescriptor = generateValueObjectsDescriptorType(valueObjects);\n\n // Per-namespace models, value objects, and enum types for the domain.namespaces section.\n const perNamespaceTypes: Array<\n readonly [string, string, string | undefined, string | undefined]\n > = namespaceEntries.map(([nsId, ns]) => {\n const nsModels = ns.models;\n const nsModelsType = generateModelsType(nsModels, (name, model) =>\n emitter.generateModelStorageType(name, model),\n );\n const nsValueObjects = blindCast<\n Record<string, ContractValueObject> | undefined,\n 'ns.valueObjects is an optional ContractValueObject record in the emitted IR'\n >(ns.valueObjects);\n const nsValueObjectsDescriptor =\n nsValueObjects !== undefined && Object.keys(nsValueObjects).length > 0\n ? generateValueObjectsDescriptorType(nsValueObjects)\n : undefined;\n const nsEnums = blindCast<\n Record<string, ContractEnum> | undefined,\n 'ns.enum is an optional ContractEnum record in the emitted IR'\n >(ns.enum);\n const nsEnumBlock =\n nsEnums !== undefined && Object.keys(nsEnums).length > 0\n ? generateEnumBlockType(nsEnums)\n : undefined;\n return [nsId, nsModelsType, nsValueObjectsDescriptor, nsEnumBlock] as const;\n });\n\n const domainNamespacesType = perNamespaceTypes\n .map(([nsId, nsModelsType, nsValueObjectsDescriptor, nsEnumBlock]) => {\n const voLine =\n nsValueObjectsDescriptor !== undefined\n ? `\\n readonly valueObjects: ${nsValueObjectsDescriptor};`\n : '';\n const enumLine = nsEnumBlock !== undefined ? `\\n readonly enum: ${nsEnumBlock};` : '';\n return ` readonly ${nsId}: {\\n readonly models: ${nsModelsType};${voLine}${enumLine}\\n }`;\n })\n .join(';\\n');\n\n const executionClause =\n contract.execution !== undefined\n ? `\\n readonly execution: ${serializeExecutionType(contract.execution)};`\n : '';\n\n const resolveFieldTypeParams = emitter.resolveFieldTypeParams\n ? (modelName: string, fieldName: string, model: ContractModelBase) =>\n emitter.resolveFieldTypeParams?.(modelName, fieldName, model, contract)\n : undefined;\n\n const resolveFieldValueSet = emitter.resolveFieldValueSet\n ? (modelName: string, fieldName: string, model: ContractModelBase) =>\n emitter.resolveFieldValueSet?.(modelName, fieldName, model, contract)\n : undefined;\n\n const namespaceModelsForFieldTypes = namespaceEntries.map(\n ([nsId, ns]) => [nsId, ns.models] as const,\n );\n\n const fieldTypesMaps = generateFieldTypesMapsByNamespace(\n namespaceModelsForFieldTypes,\n codecLookup,\n resolveFieldTypeParams,\n resolveFieldValueSet,\n );\n\n const extraTypeExports = emitter.getStorageTypeExports?.(contract, codecLookup);\n\n const contractWrapper = emitter.getContractWrapper('ContractBase', 'TypeMaps');\n\n return `// ⚠️ GENERATED FILE - DO NOT EDIT\n// This file is automatically generated by 'prisma-next contract emit'.\n// To regenerate, run: prisma-next contract emit\n${importLines.join('\\n')}\n\n${familyImportLines.join('\\n')}\nimport type {\n Contract as ContractType,\n ExecutionHashBase,\n NamespaceId,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\n\n${hashAliases}\n\nexport type CodecTypes = ${codecTypes};\n${familyTypeAliases}\n${valueObjectTypeAliases}\nexport type FieldOutputTypes = ${fieldTypesMaps.output};\nexport type FieldInputTypes = ${fieldTypesMaps.input};\n${extraTypeExports ? `${extraTypeExports}\\n` : ''}export type TypeMaps = ${typeMapsExpr};\n\ntype ContractBase = Omit<\n ContractType<${storageType}>,\n 'roots' | 'domain'\n> & {\n readonly target: ${serializeValue(contract.target)};\n readonly targetFamily: ${serializeValue(contract.targetFamily)};\n readonly roots: ${rootsType};\n readonly domain: {\n readonly namespaces: {\n${domainNamespacesType};\n };\n };\n readonly capabilities: ${serializeValue(contract.capabilities)};\n readonly extensionPacks: ${serializeValue(contract.extensionPacks)};${executionClause}\n readonly meta: ${serializeValue(contract.meta)};\n ${valueObjects ? `readonly valueObjects: ${valueObjectsDescriptor};` : ''}\n readonly profileHash: ProfileHash;\n};\n\n${contractWrapper}\n`;\n}\n","import { canonicalizeContractToObject } from '@prisma-next/contract/hashing';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { EmissionSpi } from '@prisma-next/framework-components/emission';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { format } from 'prettier';\nimport { getEmittedArtifactPaths } from './artifact-paths';\nimport type { EmitOptions, EmitResult, EmitStackInput } from './emit-types';\nimport { generateContractDts } from './generate-contract-dts';\n\nconst SCHEMA_VERSION = '1';\n\nexport async function emit(\n contract: Contract,\n stack: EmitStackInput,\n targetFamily: EmissionSpi,\n options: EmitOptions,\n): Promise<EmitResult> {\n if (options.outputJsonPath !== undefined) {\n getEmittedArtifactPaths(options.outputJsonPath);\n }\n\n const { codecTypeImports, queryOperationTypeImports } = stack;\n\n const { storageHash } = contract.storage;\n const executionHash = contract.execution?.executionHash;\n const { profileHash } = contract;\n\n const canonicalized = canonicalizeContractToObject(contract, {\n schemaVersion: SCHEMA_VERSION,\n serializeContract: options.serializeContract,\n ...ifDefined('shouldPreserveEmpty', options.shouldPreserveEmpty),\n ...ifDefined('sortStorage', options.sortStorage),\n });\n const contractJsonString = JSON.stringify(\n {\n ...canonicalized,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next contract emit\".',\n regenerate: 'To regenerate, run: prisma-next contract emit',\n },\n },\n null,\n 2,\n );\n\n const generateOptions = queryOperationTypeImports ? { queryOperationTypeImports } : undefined;\n\n const contractTypeHashes = {\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n const contractDtsRaw = generateContractDts(\n contract,\n targetFamily,\n codecTypeImports ?? [],\n contractTypeHashes,\n generateOptions,\n stack.codecLookup,\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n}\n"],"mappings":";;;;;;;AAAA,MAAM,iBAAiB;AAOvB,SAAgB,wBAAwB,gBAA8C;CACpF,IAAI,CAAC,eAAe,SAAS,cAAc,GACzC,MAAM,IAAI,MAAM,0CAA0C;CAG5D,OAAO;EACL,UAAU;EACV,SAAS,GAAG,eAAe,MAAM,GAAG,EAAsB,EAAE;CAC9D;AACF;;;ACaA,SAAS,sBAAsB,OAA6C;CAS1E,OAAO,KARS,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;EAK3D,MAAM,cAAc,aAJK,MAAM,QAAQ,KACpC,MACC,oBAAoB,eAAe,EAAE,IAAI,EAAE,oBAAoB,eAAe,EAAE,KAAK,EAAE,GAE3C,CAAC,CAAC,KAAK,IAAI,EAAE;EAC7D,OAAO,YAAY,mBAAmB,IAAI,EAAE,wBAAwB,eAAe,MA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;GACN,YAAY;EACd,CAAC;EAKC;EACA,GAAG,UAAU,iBAAiB,aAAa;EAC3C;CACF;AACF"}
1
+ {"version":3,"file":"exports-BTdZ6er3.mjs","names":[],"sources":["../src/artifact-paths.ts","../src/generate-contract-dts.ts","../src/emit.ts"],"sourcesContent":["const JSON_EXTENSION = '.json';\n\nexport interface EmittedArtifactPaths {\n readonly jsonPath: string;\n readonly dtsPath: string;\n}\n\nexport function getEmittedArtifactPaths(outputJsonPath: string): EmittedArtifactPaths {\n if (!outputJsonPath.endsWith(JSON_EXTENSION)) {\n throw new Error('Contract output path must end with .json');\n }\n\n return {\n jsonPath: outputJsonPath,\n dtsPath: `${outputJsonPath.slice(0, -JSON_EXTENSION.length)}.d.ts`,\n };\n}\n","import type {\n Contract,\n ContractEnum,\n ContractModelBase,\n ContractValueObject,\n} from '@prisma-next/contract/types';\nimport { DomainNamespaceResolutionError } from '@prisma-next/contract/types';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type {\n EmissionSpi,\n GenerateContractTypesOptions,\n TypesImportSpec,\n} from '@prisma-next/framework-components/emission';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport {\n deduplicateImports,\n generateCodecTypeIntersection,\n generateFieldTypesMapsByNamespace,\n generateHashTypeAliases,\n generateImportLines,\n generateModelsType,\n generateRootsType,\n generateValueObjectsDescriptorType,\n generateValueObjectTypeAliases,\n serializeExecutionType,\n serializeObjectKey,\n serializeValue,\n} from './domain-type-generation';\n\nfunction generateEnumBlockType(enums: Record<string, ContractEnum>): string {\n const entries = Object.entries(enums).map(([name, entry]) => {\n const memberTupleItems = entry.members.map(\n (m) =>\n `{ readonly name: ${serializeValue(m.name)}; readonly value: ${serializeValue(m.value)} }`,\n );\n const membersType = `readonly [${memberTupleItems.join(', ')}]`;\n return `readonly ${serializeObjectKey(name)}: { readonly codecId: ${serializeValue(entry.codecId)}; readonly members: ${membersType} }`;\n });\n return `{ ${entries.join('; ')} }`;\n}\n\nexport function generateContractDts(\n contract: Contract,\n emitter: EmissionSpi,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n codecLookup?: CodecLookup,\n): string {\n const allImports: TypesImportSpec[] = [...codecTypeImports];\n if (options?.queryOperationTypeImports) {\n allImports.push(...options.queryOperationTypeImports);\n }\n const uniqueImports = deduplicateImports(allImports);\n const importLines = generateImportLines(uniqueImports);\n\n const familyImportLines = emitter.getFamilyImports();\n\n const hashAliases = generateHashTypeAliases(hashes);\n\n const codecTypes = generateCodecTypeIntersection(codecTypeImports, 'CodecTypes');\n\n const familyTypeAliases = emitter.getFamilyTypeAliases(options);\n\n const typeMapsExpr = emitter.getTypeMapsExpression();\n\n const storageType = emitter.generateStorageType(contract, 'StorageHash');\n\n const namespaceEntries = Object.entries(contract.domain.namespaces);\n if (namespaceEntries.length === 0) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n\n // Validate all namespace entries are present.\n for (const [nsId, ns] of namespaceEntries) {\n if (ns === undefined) {\n throw new Error(`domain namespace \"${nsId}\" is not present on the contract`);\n }\n }\n\n const rootsType = generateRootsType(contract.roots);\n\n // Flatten value objects across all namespaces — first-name-wins on collision.\n const flatValueObjects: Record<string, ContractValueObject> = {};\n for (const [, ns] of namespaceEntries) {\n for (const [voName, vo] of Object.entries(\n blindCast<\n Record<string, ContractValueObject>,\n 'ns.valueObjects is a ContractValueObject record in the emitted IR (default to {} when absent)'\n >(ns.valueObjects ?? {}),\n )) {\n if (!(voName in flatValueObjects)) {\n flatValueObjects[voName] = vo;\n }\n }\n }\n const valueObjects = Object.keys(flatValueObjects).length > 0 ? flatValueObjects : undefined;\n const valueObjectTypeAliases = generateValueObjectTypeAliases(valueObjects, codecLookup);\n const valueObjectsDescriptor = generateValueObjectsDescriptorType(valueObjects);\n\n // Per-namespace models, value objects, and enum types for the domain.namespaces section.\n const perNamespaceTypes: Array<\n readonly [string, string, string | undefined, string | undefined]\n > = namespaceEntries.map(([nsId, ns]) => {\n const nsModels = ns.models;\n const nsModelsType = generateModelsType(nsModels, (name, model) =>\n emitter.generateModelStorageType(name, model),\n );\n const nsValueObjects = blindCast<\n Record<string, ContractValueObject> | undefined,\n 'ns.valueObjects is an optional ContractValueObject record in the emitted IR'\n >(ns.valueObjects);\n const nsValueObjectsDescriptor =\n nsValueObjects !== undefined && Object.keys(nsValueObjects).length > 0\n ? generateValueObjectsDescriptorType(nsValueObjects)\n : undefined;\n const nsEnums = blindCast<\n Record<string, ContractEnum> | undefined,\n 'ns.enum is an optional ContractEnum record in the emitted IR'\n >(ns.enum);\n const nsEnumBlock =\n nsEnums !== undefined && Object.keys(nsEnums).length > 0\n ? generateEnumBlockType(nsEnums)\n : undefined;\n return [nsId, nsModelsType, nsValueObjectsDescriptor, nsEnumBlock] as const;\n });\n\n const domainNamespacesType = perNamespaceTypes\n .map(([nsId, nsModelsType, nsValueObjectsDescriptor, nsEnumBlock]) => {\n const voLine =\n nsValueObjectsDescriptor !== undefined\n ? `\\n readonly valueObjects: ${nsValueObjectsDescriptor};`\n : '';\n const enumLine = nsEnumBlock !== undefined ? `\\n readonly enum: ${nsEnumBlock};` : '';\n return ` readonly ${nsId}: {\\n readonly models: ${nsModelsType};${voLine}${enumLine}\\n }`;\n })\n .join(';\\n');\n\n const executionClause =\n contract.execution !== undefined\n ? `\\n readonly execution: ${serializeExecutionType(contract.execution)};`\n : '';\n\n const resolveFieldTypeParams = emitter.resolveFieldTypeParams\n ? (modelName: string, fieldName: string, model: ContractModelBase) =>\n emitter.resolveFieldTypeParams?.(modelName, fieldName, model, contract)\n : undefined;\n\n const resolveFieldValueSet = emitter.resolveFieldValueSet\n ? (modelName: string, fieldName: string, model: ContractModelBase) =>\n emitter.resolveFieldValueSet?.(modelName, fieldName, model, contract)\n : undefined;\n\n const namespaceModelsForFieldTypes = namespaceEntries.map(\n ([nsId, ns]) => [nsId, ns.models] as const,\n );\n\n const fieldTypesMaps = generateFieldTypesMapsByNamespace(\n namespaceModelsForFieldTypes,\n codecLookup,\n resolveFieldTypeParams,\n resolveFieldValueSet,\n );\n\n const extraTypeExports = emitter.getStorageTypeExports?.(contract, codecLookup);\n\n const contractWrapper = emitter.getContractWrapper('ContractBase', 'TypeMaps');\n\n return `// ⚠️ GENERATED FILE - DO NOT EDIT\n// This file is automatically generated by 'prisma-next contract emit'.\n// To regenerate, run: prisma-next contract emit\n${importLines.join('\\n')}\n\n${familyImportLines.join('\\n')}\nimport type {\n Contract as ContractType,\n ExecutionHashBase,\n NamespaceId,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\n\n${hashAliases}\n\nexport type CodecTypes = ${codecTypes};\n${familyTypeAliases}\n${valueObjectTypeAliases}\nexport type FieldOutputTypes = ${fieldTypesMaps.output};\nexport type FieldInputTypes = ${fieldTypesMaps.input};\n${extraTypeExports ? `${extraTypeExports}\\n` : ''}export type TypeMaps = ${typeMapsExpr};\n\ntype ContractBase = Omit<\n ContractType<${storageType}>,\n 'roots' | 'domain'\n> & {\n readonly target: ${serializeValue(contract.target)};\n readonly targetFamily: ${serializeValue(contract.targetFamily)};\n readonly roots: ${rootsType};\n readonly domain: {\n readonly namespaces: {\n${domainNamespacesType};\n };\n };\n readonly capabilities: ${serializeValue(contract.capabilities)};\n readonly extensions: ${serializeValue(contract.extensions)};${executionClause}\n readonly meta: ${serializeValue(contract.meta)};\n ${valueObjects ? `readonly valueObjects: ${valueObjectsDescriptor};` : ''}\n readonly profileHash: ProfileHash;\n};\n\n${contractWrapper}\n`;\n}\n","import { canonicalizeContractToObject } from '@prisma-next/contract/hashing';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { EmissionSpi } from '@prisma-next/framework-components/emission';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { format } from 'prettier';\nimport { getEmittedArtifactPaths } from './artifact-paths';\nimport type { EmitOptions, EmitResult, EmitStackInput } from './emit-types';\nimport { generateContractDts } from './generate-contract-dts';\n\nconst SCHEMA_VERSION = '1';\n\nexport async function emit(\n contract: Contract,\n stack: EmitStackInput,\n targetFamily: EmissionSpi,\n options: EmitOptions,\n): Promise<EmitResult> {\n if (options.outputJsonPath !== undefined) {\n getEmittedArtifactPaths(options.outputJsonPath);\n }\n\n const { codecTypeImports, queryOperationTypeImports } = stack;\n\n const { storageHash } = contract.storage;\n const executionHash = contract.execution?.executionHash;\n const { profileHash } = contract;\n\n const canonicalized = canonicalizeContractToObject(contract, {\n schemaVersion: SCHEMA_VERSION,\n serializeContract: options.serializeContract,\n ...ifDefined('shouldPreserveEmpty', options.shouldPreserveEmpty),\n ...ifDefined('sortStorage', options.sortStorage),\n });\n const contractJsonString = JSON.stringify(\n {\n ...canonicalized,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next contract emit\".',\n regenerate: 'To regenerate, run: prisma-next contract emit',\n },\n },\n null,\n 2,\n );\n\n const generateOptions = queryOperationTypeImports ? { queryOperationTypeImports } : undefined;\n\n const contractTypeHashes = {\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n const contractDtsRaw = generateContractDts(\n contract,\n targetFamily,\n codecTypeImports ?? [],\n contractTypeHashes,\n generateOptions,\n stack.codecLookup,\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n}\n"],"mappings":";;;;;;;AAAA,MAAM,iBAAiB;AAOvB,SAAgB,wBAAwB,gBAA8C;CACpF,IAAI,CAAC,eAAe,SAAS,cAAc,GACzC,MAAM,IAAI,MAAM,0CAA0C;CAG5D,OAAO;EACL,UAAU;EACV,SAAS,GAAG,eAAe,MAAM,GAAG,EAAsB,EAAE;CAC9D;AACF;;;ACaA,SAAS,sBAAsB,OAA6C;CAS1E,OAAO,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MAAM,kBAAkB,4BAA4B,EAAE,0BAA0B,IAAI,KAAA;CAEpF,MAAM,qBAAqB;EACzB;EACA,GAAG,UAAU,iBAAiB,aAAa;EAC3C;CACF;CAgBA,OAAO;EACL,cAAc;EACd,aAAA,MATwB,OARH,oBACrB,UACA,cACA,oBAAoB,CAAC,GACrB,oBACA,iBACA,MAAM,WAEsC,GAAG;GAC/C,QAAQ;GACR,aAAa;GACb,MAAM;GACN,YAAY;EACd,CAAC;EAKC;EACA,GAAG,UAAU,iBAAiB,aAAa;EAC3C;CACF;AACF"}
@@ -17,7 +17,7 @@ type TestContractOverrides = {
17
17
  enum?: Record<string, unknown>;
18
18
  storage?: Record<string, unknown>;
19
19
  capabilities?: Record<string, Record<string, boolean>>;
20
- extensionPacks?: Record<string, unknown>;
20
+ extensions?: Record<string, unknown>;
21
21
  execution?: Record<string, unknown>;
22
22
  meta?: Record<string, unknown>;
23
23
  storageHash?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/utils.ts"],"mappings":";;;;;;;;;iBA2CgB,KACd,UAAU,UACV,OAAO,gBACP,QAAQ,aACR,UAAU,KAAK,oCACd,QAAQ;KAQN;EACH;EACA;EACA,QAAQ,eAAe;EACvB,SAAS;EACT,eAAe;EACf,OAAO;EACP,UAAU;EACV,eAAe,eAAe;EAC9B,iBAAiB;EACjB,YAAY;EACZ,OAAO;EACP;EACA;EACA,UAAU;;;iBAII,4BACd,MAAM,0BACL;iBAoBa,mBAAmB,YAAW,wBAA6B"}
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../test/utils.ts"],"mappings":";;;;;;;;;iBA2CgB,KACd,UAAU,UACV,OAAO,gBACP,QAAQ,aACR,UAAU,KAAK,oCACd,QAAQ;KAQN;EACH;EACA;EACA,QAAQ,eAAe;EACvB,SAAS;EACT,eAAe;EACf,OAAO;EACP,UAAU;EACV,eAAe,eAAe;EAC9B,aAAa;EACb,YAAY;EACZ,OAAO;EACP;EACA;EACA,UAAU;;;iBAII,4BACd,MAAM,0BACL;iBAoBa,mBAAmB,YAAW,wBAA6B"}
@@ -1,9 +1,9 @@
1
- import { t as emit$1 } from "../exports-Bsc1vgw7.mjs";
1
+ import { t as emit$1 } from "../exports-BTdZ6er3.mjs";
2
2
  import { computeExecutionHash, computeProfileHash, computeStorageHash } from "@prisma-next/contract/hashing";
3
3
  import { ifDefined } from "@prisma-next/utils/defined";
4
4
  import { UNBOUND_DOMAIN_NAMESPACE_ID, coreHash } from "@prisma-next/contract/types";
5
5
  import { createPreserveEmptyPredicate, createStorageSort } from "@prisma-next/contract/hashing-utils";
6
- coreHash("sha256:test");
6
+ coreHash("test");
7
7
  const DEFAULT_FRAMEWORK_STORAGE = { namespaces: {} };
8
8
  function createContract(overrides = {}) {
9
9
  const target = overrides.target ?? "postgres";
@@ -37,7 +37,7 @@ function createContract(overrides = {}) {
37
37
  } } },
38
38
  storage,
39
39
  capabilities,
40
- extensionPacks: overrides.extensionPacks ?? {},
40
+ extensions: overrides.extensions ?? {},
41
41
  ...overrides.execution !== void 0 ? { execution: {
42
42
  ...overrides.execution,
43
43
  executionHash: computeExecutionHash({
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":["emitImpl"],"sources":["../../../../../../test/utils/dist/exports/contract-factories.mjs","../../test/utils.ts"],"sourcesContent":["import { UNBOUND_DOMAIN_NAMESPACE_ID, coreHash } from \"@prisma-next/contract/types\";\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from \"@prisma-next/contract/hashing\";\nimport { ifDefined } from \"@prisma-next/utils/defined\";\n//#region src/contract-factories.ts\nconst DUMMY_HASH = coreHash(\"sha256:test\");\nconst DEFAULT_FRAMEWORK_STORAGE = { namespaces: {} };\nconst UNBOUND_NAMESPACE_ID = \"__unbound__\";\nconst DEFAULT_SQL_STORAGE = { namespaces: { [UNBOUND_NAMESPACE_ID]: {\n\tid: UNBOUND_NAMESPACE_ID,\n\tentries: { table: {} }\n} } };\nfunction createContract(overrides = {}) {\n\tconst target = overrides.target ?? \"postgres\";\n\tconst targetFamily = overrides.targetFamily ?? \"sql\";\n\tconst capabilities = overrides.capabilities ?? {};\n\tconst rawStorage = overrides.storage ?? DEFAULT_FRAMEWORK_STORAGE;\n\tconst storageHash = computeStorageHash({\n\t\ttarget,\n\t\ttargetFamily,\n\t\tstorage: rawStorage,\n\t\t...ifDefined(\"shouldPreserveEmpty\", overrides.shouldPreserveEmpty),\n\t\t...ifDefined(\"sortStorage\", overrides.sortStorage)\n\t});\n\tconst storage = {\n\t\t...rawStorage,\n\t\tstorageHash\n\t};\n\tconst computedProfileHash = overrides.profileHash ?? computeProfileHash({\n\t\ttarget,\n\t\ttargetFamily,\n\t\tcapabilities\n\t});\n\treturn {\n\t\ttarget,\n\t\ttargetFamily,\n\t\troots: overrides.roots ?? {},\n\t\tdomain: { namespaces: { [UNBOUND_DOMAIN_NAMESPACE_ID]: {\n\t\t\tmodels: overrides.models ?? {},\n\t\t\t...ifDefined(\"valueObjects\", overrides.valueObjects),\n\t\t\t...ifDefined(\"enum\", overrides.enum)\n\t\t} } },\n\t\tstorage,\n\t\tcapabilities,\n\t\textensionPacks: overrides.extensionPacks ?? {},\n\t\t...overrides.execution !== void 0 ? { execution: {\n\t\t\t...overrides.execution,\n\t\t\texecutionHash: computeExecutionHash({\n\t\t\t\ttarget,\n\t\t\t\ttargetFamily,\n\t\t\t\texecution: overrides.execution\n\t\t\t})\n\t\t} } : {},\n\t\tprofileHash: computedProfileHash,\n\t\tmeta: overrides.meta ?? {}\n\t};\n}\nfunction createSqlContract(overrides = {}) {\n\treturn createContract({\n\t\t...overrides,\n\t\ttarget: overrides.target ?? \"postgres\",\n\t\ttargetFamily: overrides.targetFamily ?? \"sql\",\n\t\tstorage: overrides.storage ?? DEFAULT_SQL_STORAGE\n\t});\n}\n//#endregion\nexport { DUMMY_HASH, createContract, createSqlContract };\n\n//# sourceMappingURL=contract-factories.mjs.map","import type {\n CanonicalizeContractOptions,\n PreserveEmptyPredicate,\n} from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\nimport type { Contract, CrossReference } from '@prisma-next/contract/types';\nimport type { EmissionSpi } from '@prisma-next/framework-components/emission';\nimport { createContract } from '@prisma-next/test-utils/contract-factories';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport type { EmitOptions, EmitResult, EmitStackInput } from '../src/exports';\nimport { emit as emitImpl } from '../src/exports';\n\nconst identitySerialize = (c: Contract): JsonObject => c as unknown as JsonObject;\n\nconst sqlPreserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'foreignKeys', ['constraint', 'index']],\n] as const satisfies readonly PathPattern[];\n\nconst sqlSortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst sqlPreserveEmpty = createPreserveEmptyPredicate(sqlPreserveEmptyPatterns);\nconst sqlSortStorage = createStorageSort(sqlSortTargets);\n\nconst SQL_EMIT_HOOKS = {\n shouldPreserveEmpty: sqlPreserveEmpty satisfies PreserveEmptyPredicate,\n sortStorage: sqlSortStorage,\n} satisfies Pick<CanonicalizeContractOptions, 'shouldPreserveEmpty' | 'sortStorage'>;\n\n/**\n * Tests author JSON-clean contracts directly, so the canonicalisation\n * hook trivially passes through. Production callers thread the target\n * descriptor's `contractSerializer.serializeContract` instead.\n */\nexport function emit(\n contract: Contract,\n stack: EmitStackInput,\n family: EmissionSpi,\n options?: Omit<EmitOptions, 'serializeContract'>,\n): Promise<EmitResult> {\n return emitImpl(contract, stack, family, {\n ...SQL_EMIT_HOOKS,\n ...options,\n serializeContract: identitySerialize,\n });\n}\n\ntype TestContractOverrides = {\n target?: string;\n targetFamily?: string;\n roots?: Record<string, CrossReference>;\n models?: Record<string, unknown>;\n valueObjects?: Record<string, unknown>;\n enum?: Record<string, unknown>;\n storage?: Record<string, unknown>;\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n execution?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n storageHash?: string;\n schemaVersion?: string;\n sources?: Record<string, unknown>;\n};\n\n/** Models map from canonical contract JSON (`domain.namespaces`, single namespace only). */\nexport function modelsFromCanonicalContract(\n json: Record<string, unknown>,\n): Record<string, unknown> {\n const domain = json['domain'] as Record<string, unknown> | undefined;\n const namespaces = domain?.['namespaces'] as Record<string, unknown> | undefined;\n if (namespaces === undefined) {\n return {};\n }\n const namespaceIds = Object.keys(namespaces);\n if (namespaceIds.length !== 1) {\n throw new Error(\n `expected exactly one domain namespace in canonical JSON, found ${namespaceIds.length}`,\n );\n }\n const slice = namespaces[namespaceIds[0]!] as Record<string, unknown> | undefined;\n const models = slice?.['models'];\n if (models !== undefined && typeof models === 'object' && models !== null) {\n return models as Record<string, unknown>;\n }\n return {};\n}\n\nexport function createTestContract(overrides: TestContractOverrides = {}): Contract {\n const { storageHash: _sh, schemaVersion: _sv, sources: _src, storage, ...rest } = overrides;\n const cleanStorage = storage\n ? (() => {\n const { storageHash: _innerSh, ...storageRest } = storage as Record<string, unknown>;\n return storageRest;\n })()\n : undefined;\n return createContract({\n ...rest,\n ...(cleanStorage ? { storage: cleanStorage } : {}),\n } as Parameters<typeof createContract>[0]);\n}\n"],"mappings":";;;;;AAImB,SAAS,aAAa;AACzC,MAAM,4BAA4B,EAAE,YAAY,CAAC,EAAE;AAMnD,SAAS,eAAe,YAAY,CAAC,GAAG;CACvC,MAAM,SAAS,UAAU,UAAU;CACnC,MAAM,eAAe,UAAU,gBAAgB;CAC/C,MAAM,eAAe,UAAU,gBAAgB,CAAC;CAChD,MAAM,aAAa,UAAU,WAAW;C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A,OAAS,UAAU,OAAO,QAAQ;EACvC,GAAG;EACH,GAAG;EACH,mBAAmB;CACrB,CAAC;AACH;;AAoBA,SAAgB,4BACd,MACyB;CAEzB,MAAM,aADS,KAAK,SACK,GAAG;CAC5B,IAAI,eAAe,KAAA,GACjB,OAAO,CAAC;CAEV,MAAM,eAAe,OAAO,KAAK,UAAU;CAC3C,IAAI,aAAa,WAAW,GAC1B,MAAM,IAAI,MACR,kEAAkE,aAAa,QACjF;CAGF,MAAM,SADQ,WAAW,aAAa,GAClB,GAAG;CACvB,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,WAAW,MACnE,OAAO;CAET,OAAO,CAAC;AACV;AAEA,SAAgB,mBAAmB,YAAmC,CAAC,GAAa;CAClF,MAAM,EAAE,aAAa,KAAK,eAAe,KAAK,SAAS,MAAM,SAAS,GAAG,SAAS;CAClF,MAAM,eAAe,iBACV;EACL,MAAM,EAAE,aAAa,UAAU,GAAG,gBAAgB;EAClD,OAAO;CACT,EAAA,CAAG,IACH,KAAA;CACJ,OAAO,eAAe;EACpB,GAAG;EACH,GAAI,eAAe,EAAE,SAAS,aAAa,IAAI,CAAC;CAClD,CAAyC;AAC3C"}
1
+ {"version":3,"file":"utils.mjs","names":["emitImpl"],"sources":["../../../../../../test/utils/dist/exports/contract-factories.mjs","../../test/utils.ts"],"sourcesContent":["import { UNBOUND_DOMAIN_NAMESPACE_ID, coreHash } from \"@prisma-next/contract/types\";\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from \"@prisma-next/contract/hashing\";\nimport { ifDefined } from \"@prisma-next/utils/defined\";\n//#region src/contract-factories.ts\nconst DUMMY_HASH = coreHash(\"test\");\nconst DEFAULT_FRAMEWORK_STORAGE = { namespaces: {} };\nconst UNBOUND_NAMESPACE_ID = \"__unbound__\";\nconst DEFAULT_SQL_STORAGE = { namespaces: { [UNBOUND_NAMESPACE_ID]: {\n\tid: UNBOUND_NAMESPACE_ID,\n\tentries: { table: {} }\n} } };\nfunction createContract(overrides = {}) {\n\tconst target = overrides.target ?? \"postgres\";\n\tconst targetFamily = overrides.targetFamily ?? \"sql\";\n\tconst capabilities = overrides.capabilities ?? {};\n\tconst rawStorage = overrides.storage ?? DEFAULT_FRAMEWORK_STORAGE;\n\tconst storageHash = computeStorageHash({\n\t\ttarget,\n\t\ttargetFamily,\n\t\tstorage: rawStorage,\n\t\t...ifDefined(\"shouldPreserveEmpty\", overrides.shouldPreserveEmpty),\n\t\t...ifDefined(\"sortStorage\", overrides.sortStorage)\n\t});\n\tconst storage = {\n\t\t...rawStorage,\n\t\tstorageHash\n\t};\n\tconst computedProfileHash = overrides.profileHash ?? computeProfileHash({\n\t\ttarget,\n\t\ttargetFamily,\n\t\tcapabilities\n\t});\n\treturn {\n\t\ttarget,\n\t\ttargetFamily,\n\t\troots: overrides.roots ?? {},\n\t\tdomain: { namespaces: { [UNBOUND_DOMAIN_NAMESPACE_ID]: {\n\t\t\tmodels: overrides.models ?? {},\n\t\t\t...ifDefined(\"valueObjects\", overrides.valueObjects),\n\t\t\t...ifDefined(\"enum\", overrides.enum)\n\t\t} } },\n\t\tstorage,\n\t\tcapabilities,\n\t\textensions: overrides.extensions ?? {},\n\t\t...overrides.execution !== void 0 ? { execution: {\n\t\t\t...overrides.execution,\n\t\t\texecutionHash: computeExecutionHash({\n\t\t\t\ttarget,\n\t\t\t\ttargetFamily,\n\t\t\t\texecution: overrides.execution\n\t\t\t})\n\t\t} } : {},\n\t\tprofileHash: computedProfileHash,\n\t\tmeta: overrides.meta ?? {}\n\t};\n}\nfunction createSqlContract(overrides = {}) {\n\treturn createContract({\n\t\t...overrides,\n\t\ttarget: overrides.target ?? \"postgres\",\n\t\ttargetFamily: overrides.targetFamily ?? \"sql\",\n\t\tstorage: overrides.storage ?? DEFAULT_SQL_STORAGE\n\t});\n}\n//#endregion\nexport { DUMMY_HASH, createContract, createSqlContract };\n\n//# sourceMappingURL=contract-factories.mjs.map","import type {\n CanonicalizeContractOptions,\n PreserveEmptyPredicate,\n} from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\nimport type { Contract, CrossReference } from '@prisma-next/contract/types';\nimport type { EmissionSpi } from '@prisma-next/framework-components/emission';\nimport { createContract } from '@prisma-next/test-utils/contract-factories';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport type { EmitOptions, EmitResult, EmitStackInput } from '../src/exports';\nimport { emit as emitImpl } from '../src/exports';\n\nconst identitySerialize = (c: Contract): JsonObject => c as unknown as JsonObject;\n\nconst sqlPreserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'foreignKeys', ['constraint', 'index']],\n] as const satisfies readonly PathPattern[];\n\nconst sqlSortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst sqlPreserveEmpty = createPreserveEmptyPredicate(sqlPreserveEmptyPatterns);\nconst sqlSortStorage = createStorageSort(sqlSortTargets);\n\nconst SQL_EMIT_HOOKS = {\n shouldPreserveEmpty: sqlPreserveEmpty satisfies PreserveEmptyPredicate,\n sortStorage: sqlSortStorage,\n} satisfies Pick<CanonicalizeContractOptions, 'shouldPreserveEmpty' | 'sortStorage'>;\n\n/**\n * Tests author JSON-clean contracts directly, so the canonicalisation\n * hook trivially passes through. Production callers thread the target\n * descriptor's `contractSerializer.serializeContract` instead.\n */\nexport function emit(\n contract: Contract,\n stack: EmitStackInput,\n family: EmissionSpi,\n options?: Omit<EmitOptions, 'serializeContract'>,\n): Promise<EmitResult> {\n return emitImpl(contract, stack, family, {\n ...SQL_EMIT_HOOKS,\n ...options,\n serializeContract: identitySerialize,\n });\n}\n\ntype TestContractOverrides = {\n target?: string;\n targetFamily?: string;\n roots?: Record<string, CrossReference>;\n models?: Record<string, unknown>;\n valueObjects?: Record<string, unknown>;\n enum?: Record<string, unknown>;\n storage?: Record<string, unknown>;\n capabilities?: Record<string, Record<string, boolean>>;\n extensions?: Record<string, unknown>;\n execution?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n storageHash?: string;\n schemaVersion?: string;\n sources?: Record<string, unknown>;\n};\n\n/** Models map from canonical contract JSON (`domain.namespaces`, single namespace only). */\nexport function modelsFromCanonicalContract(\n json: Record<string, unknown>,\n): Record<string, unknown> {\n const domain = json['domain'] as Record<string, unknown> | undefined;\n const namespaces = domain?.['namespaces'] as Record<string, unknown> | undefined;\n if (namespaces === undefined) {\n return {};\n }\n const namespaceIds = Object.keys(namespaces);\n if (namespaceIds.length !== 1) {\n throw new Error(\n `expected exactly one domain namespace in canonical JSON, found ${namespaceIds.length}`,\n );\n }\n const slice = namespaces[namespaceIds[0]!] as Record<string, unknown> | undefined;\n const models = slice?.['models'];\n if (models !== undefined && typeof models === 'object' && models !== null) {\n return models as Record<string, unknown>;\n }\n return {};\n}\n\nexport function createTestContract(overrides: TestContractOverrides = {}): Contract {\n const { storageHash: _sh, schemaVersion: _sv, sources: _src, storage, ...rest } = overrides;\n const cleanStorage = storage\n ? (() => {\n const { storageHash: _innerSh, ...storageRest } = storage as Record<string, unknown>;\n return storageRest;\n })()\n : undefined;\n return createContract({\n ...rest,\n ...(cleanStorage ? { storage: cleanStorage } : {}),\n } as Parameters<typeof createContract>[0]);\n}\n"],"mappings":";;;;;AAImB,SAAS,MAAM;AAClC,MAAM,4BAA4B,EAAE,YAAY,CAAC,EAAE;AAMnD,SAAS,eAAe,YAAY,CAAC,GAAG;CACvC,MAAM,SAAS,UAAU,UAAU;CACnC,MAAM,eAAe,UAAU,gBAAgB;CAC/C,MAAM,eAAe,UAAU,gBAAgB,CAAC;CAChD,MAAM,aAAa,UAAU,WAAW;CACxC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AAU,OAAO,QAAQ;EACvC,GAAG;EACH,GAAG;EACH,mBAAmB;CACrB,CAAC;AACH;;AAoBA,SAAgB,4BACd,MACyB;CAEzB,MAAM,aADS,KAAK,SACK,GAAG;CAC5B,IAAI,eAAe,KAAA,GACjB,OAAO,CAAC;CAEV,MAAM,eAAe,OAAO,KAAK,UAAU;CAC3C,IAAI,aAAa,WAAW,GAC1B,MAAM,IAAI,MACR,kEAAkE,aAAa,QACjF;CAGF,MAAM,SADQ,WAAW,aAAa,GAClB,GAAG;CACvB,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,YAAY,WAAW,MACnE,OAAO;CAET,OAAO,CAAC;AACV;AAEA,SAAgB,mBAAmB,YAAmC,CAAC,GAAa;CAClF,MAAM,EAAE,aAAa,KAAK,eAAe,KAAK,SAAS,MAAM,SAAS,GAAG,SAAS;CAClF,MAAM,eAAe,iBACV;EACL,MAAM,EAAE,aAAa,UAAU,GAAG,gBAAgB;EAClD,OAAO;CACT,EAAA,CAAG,IACH,KAAA;CACJ,OAAO,eAAe;EACpB,GAAG;EACH,GAAI,eAAe,EAAE,SAAS,aAAa,IAAI,CAAC;CAClD,CAAyC;AAC3C"}
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@prisma-next/emitter",
3
- "version": "0.16.0-dev.3",
3
+ "version": "0.16.0-dev.30",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "dependencies": {
8
- "@prisma-next/contract": "0.16.0-dev.3",
9
- "@prisma-next/framework-components": "0.16.0-dev.3",
10
- "@prisma-next/operations": "0.16.0-dev.3",
11
- "@prisma-next/ts-render": "0.16.0-dev.3",
12
- "@prisma-next/utils": "0.16.0-dev.3",
8
+ "@prisma-next/contract": "0.16.0-dev.30",
9
+ "@prisma-next/framework-components": "0.16.0-dev.30",
10
+ "@prisma-next/operations": "0.16.0-dev.30",
11
+ "@prisma-next/ts-render": "0.16.0-dev.30",
12
+ "@prisma-next/utils": "0.16.0-dev.30",
13
13
  "arktype": "^2.2.2",
14
14
  "prettier": "^3.9.5"
15
15
  },
16
16
  "devDependencies": {
17
- "@prisma-next/test-utils": "0.16.0-dev.3",
18
- "@prisma-next/tsconfig": "0.16.0-dev.3",
17
+ "@prisma-next/test-utils": "0.16.0-dev.30",
18
+ "@prisma-next/tsconfig": "0.16.0-dev.30",
19
19
  "@types/node": "25.9.4",
20
- "@prisma-next/tsdown": "0.16.0-dev.3",
20
+ "@prisma-next/tsdown": "0.16.0-dev.30",
21
21
  "tsdown": "0.22.8",
22
22
  "typescript": "5.9.3",
23
23
  "vitest": "4.1.10"
@@ -206,7 +206,7 @@ ${domainNamespacesType};
206
206
  };
207
207
  };
208
208
  readonly capabilities: ${serializeValue(contract.capabilities)};
209
- readonly extensionPacks: ${serializeValue(contract.extensionPacks)};${executionClause}
209
+ readonly extensions: ${serializeValue(contract.extensions)};${executionClause}
210
210
  readonly meta: ${serializeValue(contract.meta)};
211
211
  ${valueObjects ? `readonly valueObjects: ${valueObjectsDescriptor};` : ''}
212
212
  readonly profileHash: ProfileHash;