@prisma-next/contract 0.12.0-dev.1 → 0.12.0

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/dist/types.mjs CHANGED
@@ -3,7 +3,7 @@ import { t as asNamespaceId } from "./namespace-id-CVpkSFUK.mjs";
3
3
  import { blindCast } from "@prisma-next/utils/casts";
4
4
  import { type } from "arktype";
5
5
  //#region src/cross-reference.ts
6
- const CrossReferenceSchema = /* @__PURE__ */ blindCast(/* @__PURE__ */ type({
6
+ const CrossReferenceSchema = blindCast(type({
7
7
  "+": "reject",
8
8
  namespace: "string",
9
9
  model: "string"
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/cross-reference.ts","../src/domain-envelope.ts","../src/types.ts"],"sourcesContent":["import { blindCast } from '@prisma-next/utils/casts';\nimport { type Type, type } from 'arktype';\nimport { asNamespaceId, type NamespaceId } from './namespace-id';\n\nexport interface CrossReference {\n readonly namespace: NamespaceId;\n readonly model: string;\n}\n\nexport const CrossReferenceSchema = /* @__PURE__ */ blindCast<\n Type<CrossReference>,\n 'namespace is validated as string at runtime and branded to NamespaceId by asNamespaceId in crossRef(); the schema accepts plain strings but the public type reflects the branded shape'\n>(\n /* @__PURE__ */ type({\n '+': 'reject',\n namespace: 'string',\n model: 'string',\n }),\n);\n\nconst DEFAULT_CROSS_REF_NAMESPACE = '__unbound__';\n\nexport function crossRef(\n model: string,\n namespace: string = DEFAULT_CROSS_REF_NAMESPACE,\n): CrossReference {\n return { namespace: asNamespaceId(namespace), model };\n}\n","import { DomainNamespaceResolutionError } from './contract-validation-error';\nimport type { ContractModelBase, ContractValueObject } from './domain-types';\n\nexport const UNBOUND_DOMAIN_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * One namespace's application-domain entities — models and optional value\n * objects keyed by entity name within that namespace coordinate.\n */\nexport interface ApplicationDomainNamespace<\n TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>,\n> {\n readonly models: TModels;\n readonly valueObjects?: Record<string, ContractValueObject>;\n}\n\n/**\n * Application-domain envelope: entity content keyed by namespace id.\n * Mirrors the storage plane's `namespaces` segment (ADR 221).\n */\nexport interface ApplicationDomain<\n TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>,\n> {\n readonly namespaces: Readonly<Record<string, ApplicationDomainNamespace<TModels>>>;\n}\n\nexport type ContractWithDomain = {\n readonly domain: ApplicationDomain;\n};\n\nexport function resolveSingleDomainNamespaceId(\n domain: ApplicationDomain,\n namespaceId?: string,\n): string {\n if (namespaceId !== undefined) {\n if (!Object.hasOwn(domain.namespaces, namespaceId)) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${namespaceId}\" is not present on the contract`,\n );\n }\n return namespaceId;\n }\n\n const namespaceIds = Object.keys(domain.namespaces);\n if (namespaceIds.length === 0) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n if (namespaceIds.length > 1) {\n throw new DomainNamespaceResolutionError(\n `expected exactly one domain namespace, found ${namespaceIds.length} (${namespaceIds.join(', ')})`,\n );\n }\n const [soleNamespaceId] = namespaceIds;\n if (soleNamespaceId === undefined) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n return soleNamespaceId;\n}\n\n// Transitional single-namespace projection; pending runtime-qualification slice.\nexport function contractModels<TModels extends Record<string, ContractModelBase>>(\n contract: { readonly domain: ApplicationDomain<TModels> },\n namespaceId?: string,\n): TModels {\n const resolved = resolveSingleDomainNamespaceId(contract.domain, namespaceId);\n const domainNamespace = contract.domain.namespaces[resolved];\n if (domainNamespace === undefined) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${resolved}\" is not present on the contract`,\n );\n }\n return domainNamespace.models;\n}\n\nexport function contractValueObjects<TModels extends Record<string, ContractModelBase>>(\n contract: { readonly domain: ApplicationDomain<TModels> },\n namespaceId?: string,\n): Record<string, ContractValueObject> | undefined {\n const resolved = resolveSingleDomainNamespaceId(contract.domain, namespaceId);\n const domainNamespace = contract.domain.namespaces[resolved];\n if (domainNamespace === undefined) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${resolved}\" is not present on the contract`,\n );\n }\n return domainNamespace.valueObjects;\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 * 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 executionHash<const T extends string>(value: T): ExecutionHashBase<T> {\n return value as ExecutionHashBase<T>;\n}\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\n/**\n * One entity-kind slot in a namespace — a map of entity name to entry.\n * Values are opaque at the foundation layer; family and target concretions\n * refine them to typed IR classes.\n */\nexport type StorageEntitySlot = Readonly<Record<string, unknown>>;\n\n/**\n * Plain-data namespace entry in a storage block. Every hydrated contract\n * carries at least `id` plus zero or more entity-kind slot maps (`tables`,\n * `collections`, …). Foundation declares only this shape — no IR machinery.\n */\nexport interface StorageNamespace {\n readonly id: string;\n}\n\n/**\n * Base type for family-specific storage blocks.\n * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the\n * storage hash alongside family-specific data (tables, collections, etc.).\n *\n * The `namespaces` map is carried by every hydrated storage block. Serialized\n * envelope shape is target-owned; this types the in-memory contract after\n * `deserializeContract`.\n */\nexport interface StorageBase<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, StorageNamespace>>;\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: string;\n readonly params?: Record<string, unknown>;\n};\n\nexport type JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type ColumnDefaultLiteralValue = JsonValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;\n\n/**\n * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers\n * resolve template values from caller-supplied args (typed `unknown` at the\n * boundary) and need to validate before constructing a `ColumnDefault`.\n * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`\n * instances. Rejects functions, class instances (other than `Date`),\n * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.\n */\nexport function isColumnDefaultLiteralInputValue(\n value: unknown,\n): value is ColumnDefaultLiteralInputValue {\n if (value === null) return true;\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') return true;\n if (value instanceof Date) return true;\n if (Array.isArray(value)) return value.every(isColumnDefaultLiteralInputValue);\n if (t === 'object' && Object.getPrototypeOf(value) === Object.prototype) {\n return Object.values(value as Record<string, unknown>).every(isColumnDefaultLiteralInputValue);\n }\n return false;\n}\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport function isColumnDefault(value: unknown): value is ColumnDefault {\n if (typeof value !== 'object' || value === null) return false;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === 'literal') {\n return 'value' in value;\n }\n if (kind === 'function') {\n return typeof (value as { expression?: unknown }).expression === 'string';\n }\n return false;\n}\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport function isExecutionMutationDefaultValue(\n value: unknown,\n): value is ExecutionMutationDefaultValue {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as {\n kind?: unknown;\n id?: unknown;\n params?: unknown;\n };\n if (candidate.kind !== 'generator') return false;\n if (typeof candidate.id !== 'string') return false;\n if (\n candidate.params !== undefined &&\n (typeof candidate.params !== 'object' ||\n candidate.params === null ||\n Array.isArray(candidate.params))\n ) {\n return false;\n }\n return true;\n}\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\n/**\n * `ExecutionMutationDefault` minus its `ref` — the per-field phases value\n * authoring layers attach to a column before the column ref is known.\n */\nexport type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;\n\nexport type ExecutionSection<THash extends string = string> = {\n readonly executionHash: ExecutionHashBase<THash>;\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 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 readonly [key: string]: unknown;\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 readonly invariants: readonly string[];\n}\n"],"mappings":";;;;;AASA,MAAa,uBAAuC,0BAIlC,qBAAK;CACnB,KAAK;CACL,WAAW;CACX,OAAO;AACT,CAAC,CACH;AAEA,MAAM,8BAA8B;AAEpC,SAAgB,SACd,OACA,YAAoB,6BACJ;CAChB,OAAO;EAAE,WAAW,cAAc,SAAS;EAAG;CAAM;AACtD;;;ACxBA,MAAa,8BAA8B;AA2B3C,SAAgB,+BACd,QACA,aACQ;CACR,IAAI,gBAAgB,KAAA,GAAW;EAC7B,IAAI,CAAC,OAAO,OAAO,OAAO,YAAY,WAAW,GAC/C,MAAM,IAAI,+BACR,qBAAqB,YAAY,iCACnC;EAEF,OAAO;CACT;CAEA,MAAM,eAAe,OAAO,KAAK,OAAO,UAAU;CAClD,IAAI,aAAa,WAAW,GAC1B,MAAM,IAAI,+BAA+B,0BAA0B;CAErE,IAAI,aAAa,SAAS,GACxB,MAAM,IAAI,+BACR,gDAAgD,aAAa,OAAO,IAAI,aAAa,KAAK,IAAI,EAAE,EAClG;CAEF,MAAM,CAAC,mBAAmB;CAC1B,IAAI,oBAAoB,KAAA,GACtB,MAAM,IAAI,+BAA+B,0BAA0B;CAErE,OAAO;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;CAKlB,IAAI,UAAU,SAAS,aAAa,OAAO;CAC3C,IAAI,OAAO,UAAU,OAAO,UAAU,OAAO;CAC7C,IACE,UAAU,WAAW,KAAA,MACpB,OAAO,UAAU,WAAW,YAC3B,UAAU,WAAW,QACrB,MAAM,QAAQ,UAAU,MAAM,IAEhC,OAAO;CAET,OAAO;AACT"}
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../src/cross-reference.ts","../src/domain-envelope.ts","../src/types.ts"],"sourcesContent":["import { blindCast } from '@prisma-next/utils/casts';\nimport { type Type, type } from 'arktype';\nimport { asNamespaceId, type NamespaceId } from './namespace-id';\n\nexport interface CrossReference {\n readonly namespace: NamespaceId;\n readonly model: string;\n}\n\nexport const CrossReferenceSchema = blindCast<\n Type<CrossReference>,\n 'namespace is validated as string at runtime and branded to NamespaceId by asNamespaceId in crossRef(); the schema accepts plain strings but the public type reflects the branded shape'\n>(\n type({\n '+': 'reject',\n namespace: 'string',\n model: 'string',\n }),\n);\n\nconst DEFAULT_CROSS_REF_NAMESPACE = '__unbound__';\n\nexport function crossRef(\n model: string,\n namespace: string = DEFAULT_CROSS_REF_NAMESPACE,\n): CrossReference {\n return { namespace: asNamespaceId(namespace), model };\n}\n","import { DomainNamespaceResolutionError } from './contract-validation-error';\nimport type { ContractModelBase, ContractValueObject } from './domain-types';\n\nexport const UNBOUND_DOMAIN_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * One namespace's application-domain entities — models and optional value\n * objects keyed by entity name within that namespace coordinate.\n */\nexport interface ApplicationDomainNamespace<\n TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>,\n> {\n readonly models: TModels;\n readonly valueObjects?: Record<string, ContractValueObject>;\n}\n\n/**\n * Application-domain envelope: entity content keyed by namespace id.\n * Mirrors the storage plane's `namespaces` segment (ADR 221).\n */\nexport interface ApplicationDomain<\n TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>,\n> {\n readonly namespaces: Readonly<Record<string, ApplicationDomainNamespace<TModels>>>;\n}\n\nexport type ContractWithDomain = {\n readonly domain: ApplicationDomain;\n};\n\nexport function resolveSingleDomainNamespaceId(\n domain: ApplicationDomain,\n namespaceId?: string,\n): string {\n if (namespaceId !== undefined) {\n if (!Object.hasOwn(domain.namespaces, namespaceId)) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${namespaceId}\" is not present on the contract`,\n );\n }\n return namespaceId;\n }\n\n const namespaceIds = Object.keys(domain.namespaces);\n if (namespaceIds.length === 0) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n if (namespaceIds.length > 1) {\n throw new DomainNamespaceResolutionError(\n `expected exactly one domain namespace, found ${namespaceIds.length} (${namespaceIds.join(', ')})`,\n );\n }\n const [soleNamespaceId] = namespaceIds;\n if (soleNamespaceId === undefined) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n return soleNamespaceId;\n}\n\n// Transitional single-namespace projection; pending runtime-qualification slice.\nexport function contractModels<TModels extends Record<string, ContractModelBase>>(\n contract: { readonly domain: ApplicationDomain<TModels> },\n namespaceId?: string,\n): TModels {\n const resolved = resolveSingleDomainNamespaceId(contract.domain, namespaceId);\n const domainNamespace = contract.domain.namespaces[resolved];\n if (domainNamespace === undefined) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${resolved}\" is not present on the contract`,\n );\n }\n return domainNamespace.models;\n}\n\nexport function contractValueObjects<TModels extends Record<string, ContractModelBase>>(\n contract: { readonly domain: ApplicationDomain<TModels> },\n namespaceId?: string,\n): Record<string, ContractValueObject> | undefined {\n const resolved = resolveSingleDomainNamespaceId(contract.domain, namespaceId);\n const domainNamespace = contract.domain.namespaces[resolved];\n if (domainNamespace === undefined) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${resolved}\" is not present on the contract`,\n );\n }\n return domainNamespace.valueObjects;\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 * 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 executionHash<const T extends string>(value: T): ExecutionHashBase<T> {\n return value as ExecutionHashBase<T>;\n}\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\n/**\n * One entity-kind slot in a namespace — a map of entity name to entry.\n * Values are opaque at the foundation layer; family and target concretions\n * refine them to typed IR classes.\n */\nexport type StorageEntitySlot = Readonly<Record<string, unknown>>;\n\n/**\n * Plain-data namespace entry in a storage block. Every hydrated contract\n * carries at least `id` plus zero or more entity-kind slot maps (`tables`,\n * `collections`, …). Foundation declares only this shape — no IR machinery.\n */\nexport interface StorageNamespace {\n readonly id: string;\n}\n\n/**\n * Base type for family-specific storage blocks.\n * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the\n * storage hash alongside family-specific data (tables, collections, etc.).\n *\n * The `namespaces` map is carried by every hydrated storage block. Serialized\n * envelope shape is target-owned; this types the in-memory contract after\n * `deserializeContract`.\n */\nexport interface StorageBase<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, StorageNamespace>>;\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: string;\n readonly params?: Record<string, unknown>;\n};\n\nexport type JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type ColumnDefaultLiteralValue = JsonValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;\n\n/**\n * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers\n * resolve template values from caller-supplied args (typed `unknown` at the\n * boundary) and need to validate before constructing a `ColumnDefault`.\n * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`\n * instances. Rejects functions, class instances (other than `Date`),\n * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.\n */\nexport function isColumnDefaultLiteralInputValue(\n value: unknown,\n): value is ColumnDefaultLiteralInputValue {\n if (value === null) return true;\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') return true;\n if (value instanceof Date) return true;\n if (Array.isArray(value)) return value.every(isColumnDefaultLiteralInputValue);\n if (t === 'object' && Object.getPrototypeOf(value) === Object.prototype) {\n return Object.values(value as Record<string, unknown>).every(isColumnDefaultLiteralInputValue);\n }\n return false;\n}\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport function isColumnDefault(value: unknown): value is ColumnDefault {\n if (typeof value !== 'object' || value === null) return false;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === 'literal') {\n return 'value' in value;\n }\n if (kind === 'function') {\n return typeof (value as { expression?: unknown }).expression === 'string';\n }\n return false;\n}\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport function isExecutionMutationDefaultValue(\n value: unknown,\n): value is ExecutionMutationDefaultValue {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as {\n kind?: unknown;\n id?: unknown;\n params?: unknown;\n };\n if (candidate.kind !== 'generator') return false;\n if (typeof candidate.id !== 'string') return false;\n if (\n candidate.params !== undefined &&\n (typeof candidate.params !== 'object' ||\n candidate.params === null ||\n Array.isArray(candidate.params))\n ) {\n return false;\n }\n return true;\n}\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\n/**\n * `ExecutionMutationDefault` minus its `ref` — the per-field phases value\n * authoring layers attach to a column before the column ref is known.\n */\nexport type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;\n\nexport type ExecutionSection<THash extends string = string> = {\n readonly executionHash: ExecutionHashBase<THash>;\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 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 readonly [key: string]: unknown;\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 readonly invariants: readonly string[];\n}\n"],"mappings":";;;;;AASA,MAAa,uBAAuB,UAIlC,KAAK;CACH,KAAK;CACL,WAAW;CACX,OAAO;AACT,CAAC,CACH;AAEA,MAAM,8BAA8B;AAEpC,SAAgB,SACd,OACA,YAAoB,6BACJ;CAChB,OAAO;EAAE,WAAW,cAAc,SAAS;EAAG;CAAM;AACtD;;;ACxBA,MAAa,8BAA8B;AA2B3C,SAAgB,+BACd,QACA,aACQ;CACR,IAAI,gBAAgB,KAAA,GAAW;EAC7B,IAAI,CAAC,OAAO,OAAO,OAAO,YAAY,WAAW,GAC/C,MAAM,IAAI,+BACR,qBAAqB,YAAY,iCACnC;EAEF,OAAO;CACT;CAEA,MAAM,eAAe,OAAO,KAAK,OAAO,UAAU;CAClD,IAAI,aAAa,WAAW,GAC1B,MAAM,IAAI,+BAA+B,0BAA0B;CAErE,IAAI,aAAa,SAAS,GACxB,MAAM,IAAI,+BACR,gDAAgD,aAAa,OAAO,IAAI,aAAa,KAAK,IAAI,EAAE,EAClG;CAEF,MAAM,CAAC,mBAAmB;CAC1B,IAAI,oBAAoB,KAAA,GACtB,MAAM,IAAI,+BAA+B,0BAA0B;CAErE,OAAO;AACT;AAGA,SAAgB,eACd,UACA,aACS;CACT,MAAM,WAAW,+BAA+B,SAAS,QAAQ,WAAW;CAC5E,MAAM,kBAAkB,SAAS,OAAO,WAAW;CACnD,IAAI,oBAAoB,KAAA,GACtB,MAAM,IAAI,+BACR,qBAAqB,SAAS,iCAChC;CAEF,OAAO,gBAAgB;AACzB;AAEA,SAAgB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GED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.12.0-dev.1",
3
+ "version": "0.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Data contract type definitions and JSON schema for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/utils": "0.12.0-dev.1",
9
+ "@prisma-next/utils": "0.12.0",
10
10
  "@standard-schema/spec": "^1.1.0",
11
11
  "arktype": "^2.2.0"
12
12
  },
13
13
  "devDependencies": {
14
- "@prisma-next/tsconfig": "0.12.0-dev.1",
15
- "@prisma-next/tsdown": "0.12.0-dev.1",
14
+ "@prisma-next/tsconfig": "0.12.0",
15
+ "@prisma-next/tsdown": "0.12.0",
16
16
  "tsdown": "0.22.0",
17
17
  "typescript": "5.9.3",
18
18
  "vitest": "4.1.6"
@@ -7,11 +7,11 @@ export interface CrossReference {
7
7
  readonly model: string;
8
8
  }
9
9
 
10
- export const CrossReferenceSchema = /* @__PURE__ */ blindCast<
10
+ export const CrossReferenceSchema = blindCast<
11
11
  Type<CrossReference>,
12
12
  'namespace is validated as string at runtime and branded to NamespaceId by asNamespaceId in crossRef(); the schema accepts plain strings but the public type reflects the branded shape'
13
13
  >(
14
- /* @__PURE__ */ type({
14
+ type({
15
15
  '+': 'reject',
16
16
  namespace: 'string',
17
17
  model: 'string',