@prisma-next/contract 0.3.0-dev.40 → 0.3.0-dev.41

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,4 +1,4 @@
1
- import { M as TypesImportSpec, w as RenderTypeContext } from "./types-BJr2H3qm.mjs";
1
+ import { O as RenderTypeContext, z as TypesImportSpec } from "./types-7ZGMz-Uf.mjs";
2
2
 
3
3
  //#region src/framework-components.d.ts
4
4
 
@@ -66,9 +66,27 @@ type GeneratedValueSpec = {
66
66
  readonly id: 'ulid' | 'nanoid' | 'uuidv7' | 'uuidv4' | 'cuid2' | 'ksuid';
67
67
  readonly params?: Record<string, unknown>;
68
68
  };
69
+ type JsonPrimitive = string | number | boolean | null;
70
+ type JsonValue = JsonPrimitive | {
71
+ readonly [key: string]: JsonValue;
72
+ } | readonly JsonValue[];
73
+ type TaggedBigInt = {
74
+ readonly $type: 'bigint';
75
+ readonly value: string;
76
+ };
77
+ declare function isTaggedBigInt(value: unknown): value is TaggedBigInt;
78
+ declare function bigintJsonReplacer(_key: string, value: unknown): unknown;
79
+ type TaggedRaw = {
80
+ readonly $type: 'raw';
81
+ readonly value: JsonValue;
82
+ };
83
+ declare function isTaggedRaw(value: unknown): value is TaggedRaw;
84
+ type TaggedLiteralValue = TaggedBigInt | TaggedRaw;
85
+ type ColumnDefaultLiteralValue = JsonValue | TaggedLiteralValue;
86
+ type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | bigint | Date;
69
87
  type ColumnDefault = {
70
88
  readonly kind: 'literal';
71
- readonly expression: string;
89
+ readonly value: ColumnDefaultLiteralInputValue;
72
90
  } | {
73
91
  readonly kind: 'function';
74
92
  readonly expression: string;
@@ -373,5 +391,5 @@ interface ParameterizedCodecDescriptor {
373
391
  readonly typesImport?: TypesImportSpec;
374
392
  }
375
393
  //#endregion
376
- export { TypeRenderEntry as A, ProfileHashBase as C, StorageHashBase as D, Source as E, isDocumentContract as F, profileHash as I, TypesImportSpec as M, ValidationContext as N, TargetFamilyHook as O, coreHash as P, PlanRefs as S, ResultType as T, GenerateContractTypesOptions as _, ContractMarkerRecord as a, ParameterizedCodecDescriptor as b, DocumentContract as c, ExecutionMutationDefault as d, ExecutionMutationDefaultValue as f, FieldType as g, Expr as h, ContractBase as i, TypeRenderer as j, TypeRenderContext as k, DocumentStorage as l, ExecutionSection as m, Brand as n, DocCollection as o, ExecutionPlan as p, ColumnDefault as r, DocIndex as s, $ as t, ExecutionHashBase as u, GeneratedValueSpec as v, RenderTypeContext as w, PlanMeta as x, ParamDescriptor as y };
377
- //# sourceMappingURL=types-BJr2H3qm.d.mts.map
394
+ export { Source as A, ValidationContext as B, ParamDescriptor as C, ProfileHashBase as D, PlanRefs as E, TargetFamilyHook as F, isTaggedRaw as G, coreHash as H, TypeRenderContext as I, profileHash as K, TypeRenderEntry as L, TaggedBigInt as M, TaggedLiteralValue as N, RenderTypeContext as O, TaggedRaw as P, TypeRenderer as R, JsonValue as S, PlanMeta as T, isDocumentContract as U, bigintJsonReplacer as V, isTaggedBigInt as W, Expr as _, ColumnDefaultLiteralValue as a, GeneratedValueSpec as b, DocCollection as c, DocumentStorage as d, ExecutionHashBase as f, ExecutionSection as g, ExecutionPlan as h, ColumnDefaultLiteralInputValue as i, StorageHashBase as j, ResultType as k, DocIndex as l, ExecutionMutationDefaultValue as m, Brand as n, ContractBase as o, ExecutionMutationDefault as p, ColumnDefault as r, ContractMarkerRecord as s, $ as t, DocumentContract as u, FieldType as v, ParameterizedCodecDescriptor as w, JsonPrimitive as x, GenerateContractTypesOptions as y, TypesImportSpec as z };
395
+ //# sourceMappingURL=types-7ZGMz-Uf.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-7ZGMz-Uf.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAQY,cARC,CAQI,EAAA,OAAA,MAAA;;;;;AASjB;AAUA;AAOY,KA1BA,KA0BA,CAAA,aAAiB,M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;;;;+BAWA;;;;;yBAMN"}
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
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 };
1
+ import { A as Source, B as ValidationContext, C as ParamDescriptor, D as ProfileHashBase, E as PlanRefs, F as TargetFamilyHook, G as isTaggedRaw, H as coreHash, I as TypeRenderContext, K as profileHash, L as TypeRenderEntry, M as TaggedBigInt, N as TaggedLiteralValue, O as RenderTypeContext, P as TaggedRaw, R as TypeRenderer, S as JsonValue, T as PlanMeta, U as isDocumentContract, V as bigintJsonReplacer, W as isTaggedBigInt, _ as Expr, a as ColumnDefaultLiteralValue, b as GeneratedValueSpec, c as DocCollection, d as DocumentStorage, f as ExecutionHashBase, g as ExecutionSection, h as ExecutionPlan, i as ColumnDefaultLiteralInputValue, j as StorageHashBase, k as ResultType, l as DocIndex, m as ExecutionMutationDefaultValue, n as Brand, o as ContractBase, p as ExecutionMutationDefault, r as ColumnDefault, s as ContractMarkerRecord, t as $, u as DocumentContract, v as FieldType, w as ParameterizedCodecDescriptor, x as JsonPrimitive, y as GenerateContractTypesOptions, z as TypesImportSpec } from "./types-7ZGMz-Uf.mjs";
2
+ export { type $, type Brand, type ColumnDefault, type ColumnDefaultLiteralInputValue, type ColumnDefaultLiteralValue, 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 JsonPrimitive, type JsonValue, type ParamDescriptor, type ParameterizedCodecDescriptor, type PlanMeta, type PlanRefs, type ProfileHashBase, type RenderTypeContext, type ResultType, type Source, type StorageHashBase, type TaggedBigInt, type TaggedLiteralValue, type TaggedRaw, type TargetFamilyHook, type TypeRenderContext, type TypeRenderEntry, type TypeRenderer, type TypesImportSpec, type ValidationContext, bigintJsonReplacer, coreHash, isDocumentContract, isTaggedBigInt, isTaggedRaw, profileHash };
package/dist/types.mjs CHANGED
@@ -5,6 +5,19 @@ function coreHash(value) {
5
5
  function profileHash(value) {
6
6
  return value;
7
7
  }
8
+ function isTaggedBigInt(value) {
9
+ return typeof value === "object" && value !== null && value.$type === "bigint" && typeof value.value === "string";
10
+ }
11
+ function bigintJsonReplacer(_key, value) {
12
+ if (typeof value === "bigint") return {
13
+ $type: "bigint",
14
+ value: value.toString()
15
+ };
16
+ return value;
17
+ }
18
+ function isTaggedRaw(value) {
19
+ return typeof value === "object" && value !== null && value.$type === "raw" && "value" in value;
20
+ }
8
21
  /**
9
22
  * Type guard to check if a contract is a Document contract
10
23
  */
@@ -13,5 +26,5 @@ function isDocumentContract(contract) {
13
26
  }
14
27
 
15
28
  //#endregion
16
- export { coreHash, isDocumentContract, profileHash };
29
+ export { bigintJsonReplacer, coreHash, isDocumentContract, isTaggedBigInt, isTaggedRaw, profileHash };
17
30
  //# 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 { 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"}
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 JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type TaggedBigInt = { readonly $type: 'bigint'; readonly value: string };\n\nexport function isTaggedBigInt(value: unknown): value is TaggedBigInt {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { $type?: unknown }).$type === 'bigint' &&\n typeof (value as { value?: unknown }).value === 'string'\n );\n}\n\nexport function bigintJsonReplacer(_key: string, value: unknown): unknown {\n if (typeof value === 'bigint') {\n return { $type: 'bigint', value: value.toString() } satisfies TaggedBigInt;\n }\n return value;\n}\n\nexport type TaggedRaw = { readonly $type: 'raw'; readonly value: JsonValue };\n\nexport function isTaggedRaw(value: unknown): value is TaggedRaw {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { $type?: unknown }).$type === 'raw' &&\n 'value' in (value as object)\n );\n}\n\nexport type TaggedLiteralValue = TaggedBigInt | TaggedRaw;\n\nexport type ColumnDefaultLiteralValue = JsonValue | TaggedLiteralValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | bigint | Date;\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\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;;AA0CT,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA8B,UAAU,YACzC,OAAQ,MAA8B,UAAU;;AAIpD,SAAgB,mBAAmB,MAAc,OAAyB;AACxE,KAAI,OAAO,UAAU,SACnB,QAAO;EAAE,OAAO;EAAU,OAAO,MAAM,UAAU;EAAE;AAErD,QAAO;;AAKT,SAAgB,YAAY,OAAoC;AAC9D,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA8B,UAAU,SACzC,WAAY;;;;;AA4JhB,SAAgB,mBAAmB,UAAiD;AAClF,QACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.3.0-dev.40",
3
+ "version": "0.3.0-dev.41",
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.40"
8
+ "@prisma-next/operations": "0.3.0-dev.41"
9
9
  },
10
10
  "devDependencies": {
11
11
  "tsdown": "0.18.4",
@@ -2,6 +2,8 @@ export type {
2
2
  $,
3
3
  Brand,
4
4
  ColumnDefault,
5
+ ColumnDefaultLiteralInputValue,
6
+ ColumnDefaultLiteralValue,
5
7
  ContractBase,
6
8
  ContractMarkerRecord,
7
9
  DocCollection,
@@ -17,6 +19,8 @@ export type {
17
19
  FieldType,
18
20
  GenerateContractTypesOptions,
19
21
  GeneratedValueSpec,
22
+ JsonPrimitive,
23
+ JsonValue,
20
24
  ParamDescriptor,
21
25
  ParameterizedCodecDescriptor,
22
26
  PlanMeta,
@@ -26,6 +30,9 @@ export type {
26
30
  ResultType,
27
31
  Source,
28
32
  StorageHashBase,
33
+ TaggedBigInt,
34
+ TaggedLiteralValue,
35
+ TaggedRaw,
29
36
  TargetFamilyHook,
30
37
  TypeRenderContext,
31
38
  TypeRenderEntry,
@@ -33,4 +40,11 @@ export type {
33
40
  TypesImportSpec,
34
41
  ValidationContext,
35
42
  } from '../types';
36
- export { coreHash, isDocumentContract, profileHash } from '../types';
43
+ export {
44
+ bigintJsonReplacer,
45
+ coreHash,
46
+ isDocumentContract,
47
+ isTaggedBigInt,
48
+ isTaggedRaw,
49
+ profileHash,
50
+ } from '../types';
package/src/types.ts CHANGED
@@ -85,10 +85,52 @@ export type GeneratedValueSpec = {
85
85
  readonly params?: Record<string, unknown>;
86
86
  };
87
87
 
88
+ export type JsonPrimitive = string | number | boolean | null;
89
+
90
+ export type JsonValue =
91
+ | JsonPrimitive
92
+ | { readonly [key: string]: JsonValue }
93
+ | readonly JsonValue[];
94
+
95
+ export type TaggedBigInt = { readonly $type: 'bigint'; readonly value: string };
96
+
97
+ export function isTaggedBigInt(value: unknown): value is TaggedBigInt {
98
+ return (
99
+ typeof value === 'object' &&
100
+ value !== null &&
101
+ (value as { $type?: unknown }).$type === 'bigint' &&
102
+ typeof (value as { value?: unknown }).value === 'string'
103
+ );
104
+ }
105
+
106
+ export function bigintJsonReplacer(_key: string, value: unknown): unknown {
107
+ if (typeof value === 'bigint') {
108
+ return { $type: 'bigint', value: value.toString() } satisfies TaggedBigInt;
109
+ }
110
+ return value;
111
+ }
112
+
113
+ export type TaggedRaw = { readonly $type: 'raw'; readonly value: JsonValue };
114
+
115
+ export function isTaggedRaw(value: unknown): value is TaggedRaw {
116
+ return (
117
+ typeof value === 'object' &&
118
+ value !== null &&
119
+ (value as { $type?: unknown }).$type === 'raw' &&
120
+ 'value' in (value as object)
121
+ );
122
+ }
123
+
124
+ export type TaggedLiteralValue = TaggedBigInt | TaggedRaw;
125
+
126
+ export type ColumnDefaultLiteralValue = JsonValue | TaggedLiteralValue;
127
+
128
+ export type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | bigint | Date;
129
+
88
130
  export type ColumnDefault =
89
131
  | {
90
132
  readonly kind: 'literal';
91
- readonly expression: string;
133
+ readonly value: ColumnDefaultLiteralInputValue;
92
134
  }
93
135
  | { readonly kind: 'function'; readonly expression: string };
94
136
 
@@ -1 +0,0 @@
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,GAAA,MAAyB,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;AAG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