@prisma-next/contract 0.3.0-pr.98.1 → 0.3.0-pr.98.3
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/exports/framework-components.js +6 -1
- package/dist/exports/framework-components.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/framework-components.d.ts +13 -1
- package/dist/framework-components.d.ts.map +1 -1
- package/dist/types.d.ts +7 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/exports/types.ts +0 -1
- package/src/framework-components.ts +20 -2
- package/src/types.ts +8 -10
|
@@ -3,7 +3,12 @@ function interpolateTypeTemplate(template, params, ctx) {
|
|
|
3
3
|
return template.replace(/\{\{(\w+)\}\}/g, (_, key) => {
|
|
4
4
|
if (key === "CodecTypes") return ctx.codecTypesName;
|
|
5
5
|
const value = params[key];
|
|
6
|
-
|
|
6
|
+
if (value === void 0) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`Missing template parameter "${key}" in template "${template}". Available params: ${Object.keys(params).join(", ") || "(none)"}`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return String(value);
|
|
7
12
|
});
|
|
8
13
|
}
|
|
9
14
|
function normalizeRenderer(codecId, renderer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/framework-components.ts"],"sourcesContent":["import type { OperationManifest, TypesImportSpec } from './types';\n\n// ============================================================================\n// Type Renderer Types (for parameterized codec emission)\n// ============================================================================\n//\n// TypeRenderer supports author-friendly authoring (template strings) that are\n// normalized to functions during pack assembly. The emitter only receives\n// normalized (function-form) renderers.\n//\n// Lifecycle:\n// 1. Authoring: Descriptor author uses template string or function\n// 2. Assembly: Templates are compiled to functions via normalizeRenderer()\n// 3. Emission: Emitter calls normalized render functions\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 * A template-based type renderer (structured form).\n * Uses mustache-style placeholders (e.g., `Vector<{{length}}>`) that are\n * replaced with typeParams values during rendering.\n *\n * @example\n * ```ts\n * { kind: 'template', template: 'Vector<{{length}}>' }\n * // With typeParams { length: 1536 }, renders: 'Vector<1536>'\n * ```\n */\nexport interface TypeRendererTemplate {\n readonly kind: 'template';\n /** Template string with `{{key}}` placeholders for typeParams values */\n readonly template: string;\n}\n\n/**\n * A function-based type renderer for full control over type expression generation.\n *\n * @example\n * ```ts\n * {\n * kind: 'function',\n * render: (params, ctx) => `Vector<${params.length}>`\n * }\n * ```\n */\nexport interface TypeRendererFunction {\n readonly kind: 'function';\n /** Render function that produces a TypeScript type expression */\n readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;\n}\n\n/**\n * A raw template string type renderer (convenience form).\n * Shorthand for TypeRendererTemplate - just the template string without wrapper.\n *\n * @example\n * ```ts\n * 'Vector<{{length}}>'\n * // Equivalent to: { kind: 'template', template: 'Vector<{{length}}>' }\n * ```\n */\nexport type TypeRendererString = string;\n\n/**\n * A raw function type renderer (convenience form).\n * Shorthand for TypeRendererFunction - just the function without wrapper.\n *\n * @example\n * ```ts\n * (params, ctx) => `Vector<${params.length}>`\n * // Equivalent to: { kind: 'function', render: ... }\n * ```\n */\nexport type TypeRendererRawFunction = (\n params: Record<string, unknown>,\n ctx: RenderTypeContext,\n) => string;\n\n/**\n * Union of type renderer formats.\n *\n * Supports both structured forms (with `kind` discriminator) and convenience forms:\n * - `string` - Template string with `{{key}}` placeholders (manifest-safe, JSON-serializable)\n * - `function` - Render function for full control (requires runtime execution)\n * - `{ kind: 'template', template: string }` - Structured template form\n * - `{ kind: 'function', render: fn }` - Structured function form\n *\n * Templates are normalized to functions during pack assembly.\n * **Prefer template strings** for most cases - they are JSON-serializable.\n */\nexport type TypeRenderer =\n | TypeRendererString\n | TypeRendererRawFunction\n | TypeRendererTemplate\n | TypeRendererFunction;\n\n/**\n * Normalized type renderer - always a function after assembly.\n * This is the form received by the emitter.\n */\nexport interface NormalizedTypeRenderer {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;\n}\n\n/**\n * Interpolates a template string with params values.\n * Used internally by normalizeRenderer to compile templates to functions.\n */\nexport function interpolateTypeTemplate(\n template: string,\n params: Record<string, unknown>,\n ctx: RenderTypeContext,\n): string {\n return template.replace(/\\{\\{(\\w+)\\}\\}/g, (_, key: string) => {\n if (key === 'CodecTypes') return ctx.codecTypesName;\n const value = params[key];\n return value !== undefined ? String(value) : '';\n });\n}\n\n/**\n * Normalizes a TypeRenderer to function form.\n * Called during pack assembly, not at emission time.\n *\n * Handles all TypeRenderer forms:\n * - Raw string template: `'Vector<{{length}}>'`\n * - Raw function: `(params, ctx) => ...`\n * - Structured template: `{ kind: 'template', template: '...' }`\n * - Structured function: `{ kind: 'function', render: fn }`\n */\nexport function normalizeRenderer(codecId: string, renderer: TypeRenderer): NormalizedTypeRenderer {\n // Handle raw string (template shorthand)\n if (typeof renderer === 'string') {\n return {\n codecId,\n render: (params, ctx) => interpolateTypeTemplate(renderer, params, ctx),\n };\n }\n\n // Handle raw function (function shorthand)\n if (typeof renderer === 'function') {\n return { codecId, render: renderer };\n }\n\n // Handle structured function form\n if (renderer.kind === 'function') {\n return { codecId, render: renderer.render };\n }\n\n // Handle structured template form\n const { template } = renderer;\n return {\n codecId,\n render: (params, ctx) => interpolateTypeTemplate(template, params, ctx),\n };\n}\n\n// ============================================================================\n// Framework Component Descriptor Base Types\n// ============================================================================\n//\n// Prisma Next uses a modular architecture where functionality is composed from\n// discrete \"components\". Each component has a descriptor that identifies it and\n// provides metadata. These base types define the shared structure for all\n// component descriptors across both control-plane (CLI/tooling) and runtime-plane.\n//\n// Component Hierarchy:\n//\n// Family (e.g., 'sql', 'document')\n// └── Target (e.g., 'postgres', 'mysql', 'mongodb')\n// ├── Adapter (protocol/dialect implementation)\n// ├── Driver (connection/execution layer)\n// └── Extension (optional capabilities like pgvector)\n//\n// Key design decisions:\n// - \"Component\" terminology separates framework building blocks from delivery\n// mechanism (\"pack\" refers to how components are packaged/distributed)\n// - `kind` is extensible (Kind extends string) - no closed union, allowing\n// ecosystem authors to define new component kinds\n// - Target-bound descriptors are generic in TFamilyId and TTargetId for type-safe\n// composition (e.g., TypeScript rejects Postgres adapter with MySQL target)\n// - Descriptors own declarative fields directly (version, types, operations, etc.)\n// rather than nesting them under a `manifest` property\n//\n// ============================================================================\n\n/**\n * Declarative fields that describe component metadata.\n * These fields are owned directly by descriptors (not nested under a manifest).\n */\nexport interface ComponentMetadata {\n /** Component version (semver) */\n readonly version: string;\n\n /**\n * Capabilities this component provides.\n *\n * For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into\n * the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);\n * keep these declarations in sync. Targets are identifiers/descriptors and typically do not\n * declare capabilities.\n */\n readonly capabilities?: Record<string, unknown>;\n\n /** Type imports for contract.d.ts generation */\n readonly types?: {\n readonly codecTypes?: {\n readonly import: TypesImportSpec;\n /**\n * Optional renderers for parameterized codecs owned by this component.\n * Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.\n *\n * Templates are normalized to functions during pack assembly.\n * Duplicate codecId across descriptors is a hard error.\n */\n readonly parameterized?: Record<string, TypeRenderer>;\n };\n readonly operationTypes?: { readonly import: TypesImportSpec };\n readonly storage?: ReadonlyArray<{\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string;\n }>;\n };\n\n /** Operation manifests for building operation registries */\n readonly operations?: ReadonlyArray<OperationManifest>;\n}\n\n/**\n * Base descriptor for any framework component.\n *\n * All component descriptors share these fundamental properties that identify\n * the component and provide its metadata. This interface is extended by\n * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).\n *\n * @template Kind - Discriminator literal identifying the component type.\n * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',\n * but the type accepts any string to allow ecosystem extensions.\n *\n * @example\n * ```ts\n * // All descriptors have these properties\n * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)\n * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')\n * descriptor.version // Component version (semver)\n * ```\n */\nexport interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {\n /** Discriminator identifying the component type */\n readonly kind: Kind;\n\n /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */\n readonly id: string;\n}\n\nexport interface ContractComponentRequirementsCheckInput {\n readonly contract: {\n readonly target: string;\n readonly targetFamily?: string | undefined;\n readonly extensionPacks?: Record<string, unknown> | undefined;\n };\n readonly expectedTargetFamily?: string | undefined;\n readonly expectedTargetId?: string | undefined;\n readonly providedComponentIds: Iterable<string>;\n}\n\nexport interface ContractComponentRequirementsCheckResult {\n readonly familyMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly targetMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly missingExtensionPackIds: readonly string[];\n}\n\nexport function checkContractComponentRequirements(\n input: ContractComponentRequirementsCheckInput,\n): ContractComponentRequirementsCheckResult {\n const providedIds = new Set<string>();\n for (const id of input.providedComponentIds) {\n providedIds.add(id);\n }\n\n const requiredExtensionPackIds = input.contract.extensionPacks\n ? Object.keys(input.contract.extensionPacks)\n : [];\n const missingExtensionPackIds = requiredExtensionPackIds.filter((id) => !providedIds.has(id));\n\n const expectedTargetFamily = input.expectedTargetFamily;\n const contractTargetFamily = input.contract.targetFamily;\n const familyMismatch =\n expectedTargetFamily !== undefined &&\n contractTargetFamily !== undefined &&\n contractTargetFamily !== expectedTargetFamily\n ? { expected: expectedTargetFamily, actual: contractTargetFamily }\n : undefined;\n\n const expectedTargetId = input.expectedTargetId;\n const contractTargetId = input.contract.target;\n const targetMismatch =\n expectedTargetId !== undefined && contractTargetId !== expectedTargetId\n ? { expected: expectedTargetId, actual: contractTargetId }\n : undefined;\n\n return {\n ...(familyMismatch ? { familyMismatch } : {}),\n ...(targetMismatch ? { targetMismatch } : {}),\n missingExtensionPackIds,\n };\n}\n\n/**\n * Descriptor for a family component.\n *\n * A \"family\" represents a category of data sources with shared semantics\n * (e.g., SQL databases, document stores). Families define:\n * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)\n * - Contract structure (tables vs collections, columns vs fields)\n * - Type system and codecs\n *\n * Families are the top-level grouping. Each family contains multiple targets\n * (e.g., SQL family contains Postgres, MySQL, SQLite targets).\n *\n * Extended by plane-specific descriptors:\n * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations\n * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * import sql from '@prisma-next/family-sql/control';\n *\n * sql.kind // 'family'\n * sql.familyId // 'sql'\n * sql.id // 'sql'\n * ```\n */\nexport interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Descriptor for a target component.\n *\n * A \"target\" represents a specific database or data store within a family\n * (e.g., Postgres, MySQL, MongoDB). Targets define:\n * - Native type mappings (e.g., Postgres int4 → TypeScript number)\n * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)\n *\n * Targets are bound to a family and provide the target-specific implementation\n * details that adapters and drivers use.\n *\n * Extended by plane-specific descriptors:\n * - `ControlTargetDescriptor` - adds optional `migrations` capability\n * - `RuntimeTargetDescriptor` - adds runtime factory method\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * import postgres from '@prisma-next/target-postgres/control';\n *\n * postgres.kind // 'target'\n * postgres.familyId // 'sql'\n * postgres.targetId // 'postgres'\n * ```\n */\nexport interface TargetDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'target'> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base shape for any pack reference.\n * Pack refs are pure JSON-friendly objects safe to import in authoring flows.\n */\nexport interface PackRefBase<Kind extends string, TFamilyId extends string>\n extends ComponentMetadata {\n readonly kind: Kind;\n readonly id: string;\n readonly familyId: TFamilyId;\n readonly targetId?: string;\n}\n\nexport type TargetPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'target', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type AdapterPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'adapter', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type ExtensionPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'extension', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type DriverPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'driver', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\n/**\n * Descriptor for an adapter component.\n *\n * An \"adapter\" provides the protocol and dialect implementation for a target.\n * Adapters handle:\n * - SQL/query generation (lowering AST to target-specific syntax)\n * - Codec registration (encoding/decoding between JS and wire types)\n * - Type mappings and coercions\n *\n * Adapters are bound to a specific family+target combination and work with\n * any compatible driver for that target.\n *\n * Extended by plane-specific descriptors:\n * - `ControlAdapterDescriptor` - control-plane factory\n * - `RuntimeAdapterDescriptor` - runtime factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresAdapter from '@prisma-next/adapter-postgres/control';\n *\n * postgresAdapter.kind // 'adapter'\n * postgresAdapter.familyId // 'sql'\n * postgresAdapter.targetId // 'postgres'\n * ```\n */\nexport interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'adapter'> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for a driver component.\n *\n * A \"driver\" provides the connection and execution layer for a target.\n * Drivers handle:\n * - Connection management (pooling, timeouts, retries)\n * - Query execution (sending SQL/commands, receiving results)\n * - Transaction management\n * - Wire protocol communication\n *\n * Drivers are bound to a specific family+target and work with any compatible\n * adapter. Multiple drivers can exist for the same target (e.g., node-postgres\n * vs postgres.js for Postgres).\n *\n * Extended by plane-specific descriptors:\n * - `ControlDriverDescriptor` - creates driver from connection URL\n * - `RuntimeDriverDescriptor` - creates driver with runtime options\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresDriver from '@prisma-next/driver-postgres/control';\n *\n * postgresDriver.kind // 'driver'\n * postgresDriver.familyId // 'sql'\n * postgresDriver.targetId // 'postgres'\n * ```\n */\nexport interface DriverDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'driver'> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for an extension component.\n *\n * An \"extension\" adds optional capabilities to a target. Extensions can provide:\n * - Additional operations (e.g., vector similarity search with pgvector)\n * - Custom types and codecs (e.g., vector type)\n * - Extended query capabilities\n *\n * Extensions are bound to a specific family+target and are registered in the\n * config alongside the core components. Multiple extensions can be used together.\n *\n * Extended by plane-specific descriptors:\n * - `ControlExtensionDescriptor` - control-plane extension factory\n * - `RuntimeExtensionDescriptor` - runtime extension factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import pgvector from '@prisma-next/extension-pgvector/control';\n *\n * pgvector.kind // 'extension'\n * pgvector.familyId // 'sql'\n * pgvector.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'extension'> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Union type for target-bound component descriptors.\n *\n * Target-bound components are those that must be compatible with a specific\n * family+target combination. This includes targets, adapters, drivers, and\n * extensions. Families are not target-bound.\n *\n * This type is used in migration and verification interfaces to enforce\n * type-level compatibility between components.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * // All these components must have matching familyId and targetId\n * const components: TargetBoundComponentDescriptor<'sql', 'postgres'>[] = [\n * postgresTarget,\n * postgresAdapter,\n * postgresDriver,\n * pgvectorExtension,\n * ];\n * ```\n */\nexport type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> =\n | TargetDescriptor<TFamilyId, TTargetId>\n | AdapterDescriptor<TFamilyId, TTargetId>\n | DriverDescriptor<TFamilyId, TTargetId>\n | ExtensionDescriptor<TFamilyId, TTargetId>;\n\n// ============================================================================\n// Framework Component Instance Base Types\n// ============================================================================\n//\n// These are minimal, identity-only interfaces for component instances.\n// They carry the component's identity (familyId, targetId) without any\n// behavior methods. Plane-specific interfaces (ControlFamilyInstance,\n// RuntimeFamilyInstance, etc.) extend these bases and add domain actions.\n//\n// ============================================================================\n\n/**\n * Base interface for family instances.\n *\n * A family instance is created by a family descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * const instance = sql.create({ target, adapter, driver, extensions });\n * instance.familyId // 'sql'\n * ```\n */\nexport interface FamilyInstance<TFamilyId extends string> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Base interface for target instances.\n *\n * A target instance is created by a target descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add target-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * const instance = postgres.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface TargetInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for adapter instances.\n *\n * An adapter instance is created by an adapter descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add adapter-specific behavior (e.g., codec registration, query lowering).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresAdapter.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for driver instances.\n *\n * A driver instance is created by a driver descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresDriver.create({ databaseUrl });\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface DriverInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for extension instances.\n *\n * An extension instance is created by an extension descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add extension-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = pgvector.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n"],"mappings":";AAqHO,SAAS,wBACd,UACA,QACA,KACQ;AACR,SAAO,SAAS,QAAQ,kBAAkB,CAAC,GAAG,QAAgB;AAC5D,QAAI,QAAQ,aAAc,QAAO,IAAI;AACrC,UAAM,QAAQ,OAAO,GAAG;AACxB,WAAO,UAAU,SAAY,OAAO,KAAK,IAAI;AAAA,EAC/C,CAAC;AACH;AAYO,SAAS,kBAAkB,SAAiB,UAAgD;AAEjG,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,CAAC,QAAQ,QAAQ,wBAAwB,UAAU,QAAQ,GAAG;AAAA,IACxE;AAAA,EACF;AAGA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,EAAE,SAAS,QAAQ,SAAS;AAAA,EACrC;AAGA,MAAI,SAAS,SAAS,YAAY;AAChC,WAAO,EAAE,SAAS,QAAQ,SAAS,OAAO;AAAA,EAC5C;AAGA,QAAM,EAAE,SAAS,IAAI;AACrB,SAAO;AAAA,IACL;AAAA,IACA,QAAQ,CAAC,QAAQ,QAAQ,wBAAwB,UAAU,QAAQ,GAAG;AAAA,EACxE;AACF;AAuHO,SAAS,mCACd,OAC0C;AAC1C,QAAM,cAAc,oBAAI,IAAY;AACpC,aAAW,MAAM,MAAM,sBAAsB;AAC3C,gBAAY,IAAI,EAAE;AAAA,EACpB;AAEA,QAAM,2BAA2B,MAAM,SAAS,iBAC5C,OAAO,KAAK,MAAM,SAAS,cAAc,IACzC,CAAC;AACL,QAAM,0BAA0B,yBAAyB,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;AAE5F,QAAM,uBAAuB,MAAM;AACnC,QAAM,uBAAuB,MAAM,SAAS;AAC5C,QAAM,iBACJ,yBAAyB,UACzB,yBAAyB,UACzB,yBAAyB,uBACrB,EAAE,UAAU,sBAAsB,QAAQ,qBAAqB,IAC/D;AAEN,QAAM,mBAAmB,MAAM;AAC/B,QAAM,mBAAmB,MAAM,SAAS;AACxC,QAAM,iBACJ,qBAAqB,UAAa,qBAAqB,mBACnD,EAAE,UAAU,kBAAkB,QAAQ,iBAAiB,IACvD;AAEN,SAAO;AAAA,IACL,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/framework-components.ts"],"sourcesContent":["import type { OperationManifest, TypesImportSpec } from './types';\n\n// ============================================================================\n// Type Renderer Types (for parameterized codec emission)\n// ============================================================================\n//\n// TypeRenderer supports author-friendly authoring (template strings) that are\n// normalized to functions during pack assembly. The emitter only receives\n// normalized (function-form) renderers.\n//\n// Lifecycle:\n// 1. Authoring: Descriptor author uses template string or function\n// 2. Assembly: Templates are compiled to functions via normalizeRenderer()\n// 3. Emission: Emitter calls normalized render functions\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 * A template-based type renderer (structured form).\n * Uses mustache-style placeholders (e.g., `Vector<{{length}}>`) that are\n * replaced with typeParams values during rendering.\n *\n * @example\n * ```ts\n * { kind: 'template', template: 'Vector<{{length}}>' }\n * // With typeParams { length: 1536 }, renders: 'Vector<1536>'\n * ```\n */\nexport interface TypeRendererTemplate {\n readonly kind: 'template';\n /** Template string with `{{key}}` placeholders for typeParams values */\n readonly template: string;\n}\n\n/**\n * A function-based type renderer for full control over type expression generation.\n *\n * @example\n * ```ts\n * {\n * kind: 'function',\n * render: (params, ctx) => `Vector<${params.length}>`\n * }\n * ```\n */\nexport interface TypeRendererFunction {\n readonly kind: 'function';\n /** Render function that produces a TypeScript type expression */\n readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;\n}\n\n/**\n * A raw template string type renderer (convenience form).\n * Shorthand for TypeRendererTemplate - just the template string without wrapper.\n *\n * @example\n * ```ts\n * 'Vector<{{length}}>'\n * // Equivalent to: { kind: 'template', template: 'Vector<{{length}}>' }\n * ```\n */\nexport type TypeRendererString = string;\n\n/**\n * A raw function type renderer (convenience form).\n * Shorthand for TypeRendererFunction - just the function without wrapper.\n *\n * @example\n * ```ts\n * (params, ctx) => `Vector<${params.length}>`\n * // Equivalent to: { kind: 'function', render: ... }\n * ```\n */\nexport type TypeRendererRawFunction = (\n params: Record<string, unknown>,\n ctx: RenderTypeContext,\n) => string;\n\n/**\n * Union of type renderer formats.\n *\n * Supports both structured forms (with `kind` discriminator) and convenience forms:\n * - `string` - Template string with `{{key}}` placeholders (manifest-safe, JSON-serializable)\n * - `function` - Render function for full control (requires runtime execution)\n * - `{ kind: 'template', template: string }` - Structured template form\n * - `{ kind: 'function', render: fn }` - Structured function form\n *\n * Templates are normalized to functions during pack assembly.\n * **Prefer template strings** for most cases - they are JSON-serializable.\n */\nexport type TypeRenderer =\n | TypeRendererString\n | TypeRendererRawFunction\n | TypeRendererTemplate\n | TypeRendererFunction;\n\n/**\n * Normalized type renderer - always a function after assembly.\n * This is the form received by the emitter.\n */\nexport interface NormalizedTypeRenderer {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;\n}\n\n/**\n * Interpolates a template string with params values.\n * Used internally by normalizeRenderer to compile templates to functions.\n *\n * @throws Error if a placeholder key is not found in params (except 'CodecTypes')\n */\nexport function interpolateTypeTemplate(\n template: string,\n params: Record<string, unknown>,\n ctx: RenderTypeContext,\n): string {\n return template.replace(/\\{\\{(\\w+)\\}\\}/g, (_, key: string) => {\n if (key === 'CodecTypes') return ctx.codecTypesName;\n const value = params[key];\n if (value === undefined) {\n throw new Error(\n `Missing template parameter \"${key}\" in template \"${template}\". ` +\n `Available params: ${Object.keys(params).join(', ') || '(none)'}`,\n );\n }\n return String(value);\n });\n}\n\n/**\n * Normalizes a TypeRenderer to function form.\n * Called during pack assembly, not at emission time.\n *\n * Handles all TypeRenderer forms:\n * - Raw string template: `'Vector<{{length}}>'`\n * - Raw function: `(params, ctx) => ...`\n * - Structured template: `{ kind: 'template', template: '...' }`\n * - Structured function: `{ kind: 'function', render: fn }`\n */\nexport function normalizeRenderer(codecId: string, renderer: TypeRenderer): NormalizedTypeRenderer {\n // Handle raw string (template shorthand)\n if (typeof renderer === 'string') {\n return {\n codecId,\n render: (params, ctx) => interpolateTypeTemplate(renderer, params, ctx),\n };\n }\n\n // Handle raw function (function shorthand)\n if (typeof renderer === 'function') {\n return { codecId, render: renderer };\n }\n\n // Handle structured function form\n if (renderer.kind === 'function') {\n return { codecId, render: renderer.render };\n }\n\n // Handle structured template form\n const { template } = renderer;\n return {\n codecId,\n render: (params, ctx) => interpolateTypeTemplate(template, params, ctx),\n };\n}\n\n// ============================================================================\n// Framework Component Descriptor Base Types\n// ============================================================================\n//\n// Prisma Next uses a modular architecture where functionality is composed from\n// discrete \"components\". Each component has a descriptor that identifies it and\n// provides metadata. These base types define the shared structure for all\n// component descriptors across both control-plane (CLI/tooling) and runtime-plane.\n//\n// Component Hierarchy:\n//\n// Family (e.g., 'sql', 'document')\n// └── Target (e.g., 'postgres', 'mysql', 'mongodb')\n// ├── Adapter (protocol/dialect implementation)\n// ├── Driver (connection/execution layer)\n// └── Extension (optional capabilities like pgvector)\n//\n// Key design decisions:\n// - \"Component\" terminology separates framework building blocks from delivery\n// mechanism (\"pack\" refers to how components are packaged/distributed)\n// - `kind` is extensible (Kind extends string) - no closed union, allowing\n// ecosystem authors to define new component kinds\n// - Target-bound descriptors are generic in TFamilyId and TTargetId for type-safe\n// composition (e.g., TypeScript rejects Postgres adapter with MySQL target)\n// - Descriptors own declarative fields directly (version, types, operations, etc.)\n// rather than nesting them under a `manifest` property\n//\n// ============================================================================\n\n/**\n * Declarative fields that describe component metadata.\n * These fields are owned directly by descriptors (not nested under a manifest).\n */\nexport interface ComponentMetadata {\n /** Component version (semver) */\n readonly version: string;\n\n /**\n * Capabilities this component provides.\n *\n * For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into\n * the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);\n * keep these declarations in sync. Targets are identifiers/descriptors and typically do not\n * declare capabilities.\n */\n readonly capabilities?: Record<string, unknown>;\n\n /** Type imports for contract.d.ts generation */\n readonly types?: {\n readonly codecTypes?: {\n /**\n * Base codec types import spec.\n * Optional: adapters typically provide this, extensions usually don't.\n */\n readonly import?: TypesImportSpec;\n /**\n * Optional renderers for parameterized codecs owned by this component.\n * Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.\n *\n * Templates are normalized to functions during pack assembly.\n * Duplicate codecId across descriptors is a hard error.\n */\n readonly parameterized?: Record<string, TypeRenderer>;\n /**\n * Optional type imports for parameterized codecs.\n * These imports are added to contract.d.ts when parameterized renderers\n * reference types from external packages.\n */\n readonly parameterizedImports?: ReadonlyArray<TypesImportSpec>;\n };\n readonly operationTypes?: { readonly import: TypesImportSpec };\n readonly storage?: ReadonlyArray<{\n readonly typeId: string;\n readonly familyId: string;\n readonly targetId: string;\n readonly nativeType?: string;\n }>;\n };\n\n /** Operation manifests for building operation registries */\n readonly operations?: ReadonlyArray<OperationManifest>;\n}\n\n/**\n * Base descriptor for any framework component.\n *\n * All component descriptors share these fundamental properties that identify\n * the component and provide its metadata. This interface is extended by\n * specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).\n *\n * @template Kind - Discriminator literal identifying the component type.\n * Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',\n * but the type accepts any string to allow ecosystem extensions.\n *\n * @example\n * ```ts\n * // All descriptors have these properties\n * descriptor.kind // The Kind type parameter (e.g., 'family', 'target', or custom kinds)\n * descriptor.id // Unique string identifier (e.g., 'sql', 'postgres')\n * descriptor.version // Component version (semver)\n * ```\n */\nexport interface ComponentDescriptor<Kind extends string> extends ComponentMetadata {\n /** Discriminator identifying the component type */\n readonly kind: Kind;\n\n /** Unique identifier for this component (e.g., 'sql', 'postgres', 'pgvector') */\n readonly id: string;\n}\n\nexport interface ContractComponentRequirementsCheckInput {\n readonly contract: {\n readonly target: string;\n readonly targetFamily?: string | undefined;\n readonly extensionPacks?: Record<string, unknown> | undefined;\n };\n readonly expectedTargetFamily?: string | undefined;\n readonly expectedTargetId?: string | undefined;\n readonly providedComponentIds: Iterable<string>;\n}\n\nexport interface ContractComponentRequirementsCheckResult {\n readonly familyMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly targetMismatch?: { readonly expected: string; readonly actual: string } | undefined;\n readonly missingExtensionPackIds: readonly string[];\n}\n\nexport function checkContractComponentRequirements(\n input: ContractComponentRequirementsCheckInput,\n): ContractComponentRequirementsCheckResult {\n const providedIds = new Set<string>();\n for (const id of input.providedComponentIds) {\n providedIds.add(id);\n }\n\n const requiredExtensionPackIds = input.contract.extensionPacks\n ? Object.keys(input.contract.extensionPacks)\n : [];\n const missingExtensionPackIds = requiredExtensionPackIds.filter((id) => !providedIds.has(id));\n\n const expectedTargetFamily = input.expectedTargetFamily;\n const contractTargetFamily = input.contract.targetFamily;\n const familyMismatch =\n expectedTargetFamily !== undefined &&\n contractTargetFamily !== undefined &&\n contractTargetFamily !== expectedTargetFamily\n ? { expected: expectedTargetFamily, actual: contractTargetFamily }\n : undefined;\n\n const expectedTargetId = input.expectedTargetId;\n const contractTargetId = input.contract.target;\n const targetMismatch =\n expectedTargetId !== undefined && contractTargetId !== expectedTargetId\n ? { expected: expectedTargetId, actual: contractTargetId }\n : undefined;\n\n return {\n ...(familyMismatch ? { familyMismatch } : {}),\n ...(targetMismatch ? { targetMismatch } : {}),\n missingExtensionPackIds,\n };\n}\n\n/**\n * Descriptor for a family component.\n *\n * A \"family\" represents a category of data sources with shared semantics\n * (e.g., SQL databases, document stores). Families define:\n * - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)\n * - Contract structure (tables vs collections, columns vs fields)\n * - Type system and codecs\n *\n * Families are the top-level grouping. Each family contains multiple targets\n * (e.g., SQL family contains Postgres, MySQL, SQLite targets).\n *\n * Extended by plane-specific descriptors:\n * - `ControlFamilyDescriptor` - adds `hook` for CLI/tooling operations\n * - `RuntimeFamilyDescriptor` - adds runtime-specific factory methods\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * import sql from '@prisma-next/family-sql/control';\n *\n * sql.kind // 'family'\n * sql.familyId // 'sql'\n * sql.id // 'sql'\n * ```\n */\nexport interface FamilyDescriptor<TFamilyId extends string> extends ComponentDescriptor<'family'> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Descriptor for a target component.\n *\n * A \"target\" represents a specific database or data store within a family\n * (e.g., Postgres, MySQL, MongoDB). Targets define:\n * - Native type mappings (e.g., Postgres int4 → TypeScript number)\n * - Target-specific capabilities (e.g., RETURNING, LATERAL joins)\n *\n * Targets are bound to a family and provide the target-specific implementation\n * details that adapters and drivers use.\n *\n * Extended by plane-specific descriptors:\n * - `ControlTargetDescriptor` - adds optional `migrations` capability\n * - `RuntimeTargetDescriptor` - adds runtime factory method\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * import postgres from '@prisma-next/target-postgres/control';\n *\n * postgres.kind // 'target'\n * postgres.familyId // 'sql'\n * postgres.targetId // 'postgres'\n * ```\n */\nexport interface TargetDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'target'> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base shape for any pack reference.\n * Pack refs are pure JSON-friendly objects safe to import in authoring flows.\n */\nexport interface PackRefBase<Kind extends string, TFamilyId extends string>\n extends ComponentMetadata {\n readonly kind: Kind;\n readonly id: string;\n readonly familyId: TFamilyId;\n readonly targetId?: string;\n}\n\nexport type TargetPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'target', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type AdapterPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'adapter', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type ExtensionPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'extension', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\nexport type DriverPackRef<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n> = PackRefBase<'driver', TFamilyId> & {\n readonly targetId: TTargetId;\n};\n\n/**\n * Descriptor for an adapter component.\n *\n * An \"adapter\" provides the protocol and dialect implementation for a target.\n * Adapters handle:\n * - SQL/query generation (lowering AST to target-specific syntax)\n * - Codec registration (encoding/decoding between JS and wire types)\n * - Type mappings and coercions\n *\n * Adapters are bound to a specific family+target combination and work with\n * any compatible driver for that target.\n *\n * Extended by plane-specific descriptors:\n * - `ControlAdapterDescriptor` - control-plane factory\n * - `RuntimeAdapterDescriptor` - runtime factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresAdapter from '@prisma-next/adapter-postgres/control';\n *\n * postgresAdapter.kind // 'adapter'\n * postgresAdapter.familyId // 'sql'\n * postgresAdapter.targetId // 'postgres'\n * ```\n */\nexport interface AdapterDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'adapter'> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for a driver component.\n *\n * A \"driver\" provides the connection and execution layer for a target.\n * Drivers handle:\n * - Connection management (pooling, timeouts, retries)\n * - Query execution (sending SQL/commands, receiving results)\n * - Transaction management\n * - Wire protocol communication\n *\n * Drivers are bound to a specific family+target and work with any compatible\n * adapter. Multiple drivers can exist for the same target (e.g., node-postgres\n * vs postgres.js for Postgres).\n *\n * Extended by plane-specific descriptors:\n * - `ControlDriverDescriptor` - creates driver from connection URL\n * - `RuntimeDriverDescriptor` - creates driver with runtime options\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import postgresDriver from '@prisma-next/driver-postgres/control';\n *\n * postgresDriver.kind // 'driver'\n * postgresDriver.familyId // 'sql'\n * postgresDriver.targetId // 'postgres'\n * ```\n */\nexport interface DriverDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'driver'> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Descriptor for an extension component.\n *\n * An \"extension\" adds optional capabilities to a target. Extensions can provide:\n * - Additional operations (e.g., vector similarity search with pgvector)\n * - Custom types and codecs (e.g., vector type)\n * - Extended query capabilities\n *\n * Extensions are bound to a specific family+target and are registered in the\n * config alongside the core components. Multiple extensions can be used together.\n *\n * Extended by plane-specific descriptors:\n * - `ControlExtensionDescriptor` - control-plane extension factory\n * - `RuntimeExtensionDescriptor` - runtime extension factory\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * import pgvector from '@prisma-next/extension-pgvector/control';\n *\n * pgvector.kind // 'extension'\n * pgvector.familyId // 'sql'\n * pgvector.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionDescriptor<TFamilyId extends string, TTargetId extends string>\n extends ComponentDescriptor<'extension'> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Union type for target-bound component descriptors.\n *\n * Target-bound components are those that must be compatible with a specific\n * family+target combination. This includes targets, adapters, drivers, and\n * extensions. Families are not target-bound.\n *\n * This type is used in migration and verification interfaces to enforce\n * type-level compatibility between components.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * // All these components must have matching familyId and targetId\n * const components: TargetBoundComponentDescriptor<'sql', 'postgres'>[] = [\n * postgresTarget,\n * postgresAdapter,\n * postgresDriver,\n * pgvectorExtension,\n * ];\n * ```\n */\nexport type TargetBoundComponentDescriptor<TFamilyId extends string, TTargetId extends string> =\n | TargetDescriptor<TFamilyId, TTargetId>\n | AdapterDescriptor<TFamilyId, TTargetId>\n | DriverDescriptor<TFamilyId, TTargetId>\n | ExtensionDescriptor<TFamilyId, TTargetId>;\n\n// ============================================================================\n// Framework Component Instance Base Types\n// ============================================================================\n//\n// These are minimal, identity-only interfaces for component instances.\n// They carry the component's identity (familyId, targetId) without any\n// behavior methods. Plane-specific interfaces (ControlFamilyInstance,\n// RuntimeFamilyInstance, etc.) extend these bases and add domain actions.\n//\n// ============================================================================\n\n/**\n * Base interface for family instances.\n *\n * A family instance is created by a family descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add domain actions (e.g., `emitContract`, `verify` on ControlFamilyInstance).\n *\n * @template TFamilyId - Literal type for the family identifier (e.g., 'sql', 'document')\n *\n * @example\n * ```ts\n * const instance = sql.create({ target, adapter, driver, extensions });\n * instance.familyId // 'sql'\n * ```\n */\nexport interface FamilyInstance<TFamilyId extends string> {\n /** The family identifier (e.g., 'sql', 'document') */\n readonly familyId: TFamilyId;\n}\n\n/**\n * Base interface for target instances.\n *\n * A target instance is created by a target descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add target-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier (e.g., 'postgres', 'mysql')\n *\n * @example\n * ```ts\n * const instance = postgres.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface TargetInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this target belongs to */\n readonly familyId: TFamilyId;\n\n /** The target identifier (e.g., 'postgres', 'mysql', 'mongodb') */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for adapter instances.\n *\n * An adapter instance is created by an adapter descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add adapter-specific behavior (e.g., codec registration, query lowering).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresAdapter.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface AdapterInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this adapter belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this adapter is designed for */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for driver instances.\n *\n * A driver instance is created by a driver descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add driver-specific behavior (e.g., `query`, `close` on ControlDriverInstance).\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = postgresDriver.create({ databaseUrl });\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface DriverInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this driver belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this driver connects to */\n readonly targetId: TTargetId;\n}\n\n/**\n * Base interface for extension instances.\n *\n * An extension instance is created by an extension descriptor's `create()` method.\n * This base interface carries only the identity; plane-specific interfaces\n * add extension-specific behavior.\n *\n * @template TFamilyId - Literal type for the family identifier\n * @template TTargetId - Literal type for the target identifier\n *\n * @example\n * ```ts\n * const instance = pgvector.create();\n * instance.familyId // 'sql'\n * instance.targetId // 'postgres'\n * ```\n */\nexport interface ExtensionInstance<TFamilyId extends string, TTargetId extends string> {\n /** The family this extension belongs to */\n readonly familyId: TFamilyId;\n\n /** The target this extension is designed for */\n readonly targetId: TTargetId;\n}\n"],"mappings":";AAuHO,SAAS,wBACd,UACA,QACA,KACQ;AACR,SAAO,SAAS,QAAQ,kBAAkB,CAAC,GAAG,QAAgB;AAC5D,QAAI,QAAQ,aAAc,QAAO,IAAI;AACrC,UAAM,QAAQ,OAAO,GAAG;AACxB,QAAI,UAAU,QAAW;AACvB,YAAM,IAAI;AAAA,QACR,+BAA+B,GAAG,kBAAkB,QAAQ,wBACrC,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI,KAAK,QAAQ;AAAA,MACnE;AAAA,IACF;AACA,WAAO,OAAO,KAAK;AAAA,EACrB,CAAC;AACH;AAYO,SAAS,kBAAkB,SAAiB,UAAgD;AAEjG,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,CAAC,QAAQ,QAAQ,wBAAwB,UAAU,QAAQ,GAAG;AAAA,IACxE;AAAA,EACF;AAGA,MAAI,OAAO,aAAa,YAAY;AAClC,WAAO,EAAE,SAAS,QAAQ,SAAS;AAAA,EACrC;AAGA,MAAI,SAAS,SAAS,YAAY;AAChC,WAAO,EAAE,SAAS,QAAQ,SAAS,OAAO;AAAA,EAC5C;AAGA,QAAM,EAAE,SAAS,IAAI;AACrB,SAAO;AAAA,IACL;AAAA,IACA,QAAQ,CAAC,QAAQ,QAAQ,wBAAwB,UAAU,QAAQ,GAAG;AAAA,EACxE;AACF;AAiIO,SAAS,mCACd,OAC0C;AAC1C,QAAM,cAAc,oBAAI,IAAY;AACpC,aAAW,MAAM,MAAM,sBAAsB;AAC3C,gBAAY,IAAI,EAAE;AAAA,EACpB;AAEA,QAAM,2BAA2B,MAAM,SAAS,iBAC5C,OAAO,KAAK,MAAM,SAAS,cAAc,IACzC,CAAC;AACL,QAAM,0BAA0B,yBAAyB,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;AAE5F,QAAM,uBAAuB,MAAM;AACnC,QAAM,uBAAuB,MAAM,SAAS;AAC5C,QAAM,iBACJ,yBAAyB,UACzB,yBAAyB,UACzB,yBAAyB,uBACrB,EAAE,UAAU,sBAAsB,QAAQ,qBAAqB,IAC/D;AAEN,QAAM,mBAAmB,MAAM;AAC/B,QAAM,mBAAmB,MAAM,SAAS;AACxC,QAAM,iBACJ,qBAAqB,UAAa,qBAAqB,mBACnD,EAAE,UAAU,kBAAkB,QAAQ,iBAAiB,IACvD;AAEN,SAAO;AAAA,IACL,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
package/dist/exports/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { ContractBase, ContractMarkerRecord, DocCollection, DocIndex, DocumentContract, DocumentStorage, ExecutionPlan, Expr, FieldType, GenerateContractTypesOptions, OperationManifest, ParamDescriptor, ParameterizedCodecDescriptor, PlanMeta, PlanRefs,
|
|
1
|
+
export type { ContractBase, ContractMarkerRecord, DocCollection, DocIndex, DocumentContract, DocumentStorage, ExecutionPlan, Expr, FieldType, GenerateContractTypesOptions, OperationManifest, ParamDescriptor, ParameterizedCodecDescriptor, PlanMeta, PlanRefs, ResultType, Source, TargetFamilyHook, TypeRenderContext, TypeRenderEntry, TypeRenderer, TypesImportSpec, ValidationContext, } from '../types';
|
|
2
2
|
export { isDocumentContract } from '../types';
|
|
3
3
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,IAAI,EACJ,SAAS,EAET,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,4BAA4B,EAC5B,QAAQ,EACR,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,IAAI,EACJ,SAAS,EAET,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,4BAA4B,EAC5B,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { ContractIR } from './ir';\n\nexport interface ContractBase {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, Source>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface DocumentStorage {\n readonly document: {\n readonly collections: Record<string, DocCollection>;\n };\n}\n\nexport interface DocumentContract extends ContractBase {\n // Accept string to work with JSON imports; runtime validation ensures 'document'\n readonly targetFamily: string;\n readonly storage: DocumentStorage;\n}\n\n// Plan types - target-family agnostic execution types\nexport interface ParamDescriptor {\n readonly index?: number;\n readonly name?: string;\n readonly codecId?: string;\n readonly nativeType?: string;\n readonly nullable?: boolean;\n readonly source: 'dsl' | 'raw';\n readonly refs?: { table: string; column: string };\n}\n\nexport interface PlanRefs {\n readonly tables?: readonly string[];\n readonly columns?: ReadonlyArray<{ table: string; column: string }>;\n readonly indexes?: ReadonlyArray<{\n readonly table: string;\n readonly columns: ReadonlyArray<string>;\n readonly name?: string;\n }>;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n codecs?: Record<string, string>; // alias/param → codec id ('ns/name@v')\n [key: string]: unknown;\n };\n readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;\n readonly refs?: PlanRefs;\n readonly projection?: Record<string, string> | ReadonlyArray<string>;\n /**\n * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).\n * Used for codec resolution when AST+refs don't provide enough type info.\n */\n readonly projectionTypes?: Record<string, string>;\n}\n\n/**\n * Canonical execution plan shape used by runtimes.\n *\n * - Row is the inferred result row type (TypeScript-only).\n * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).\n *\n * The payload executed by the runtime is represented by the sql + params pair\n * for now; future families can specialize this via Ast or additional metadata.\n */\nexport interface ExecutionPlan<Row = unknown, Ast = unknown> {\n readonly sql: string;\n readonly params: readonly unknown[];\n readonly ast?: Ast;\n readonly meta: PlanMeta;\n /**\n * Phantom property to carry the Row generic for type-level utilities.\n * Not set at runtime; used only for ResultType extraction.\n */\n readonly _row?: Row;\n}\n\n/**\n * Utility type to extract the Row type from an ExecutionPlan.\n * Example: `type Row = ResultType<typeof plan>`\n *\n * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).\n * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter\n * for type extraction.\n */\nexport type ResultType<P> =\n P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : never;\n\n/**\n * Type guard to check if a contract is a Document contract\n */\nexport function isDocumentContract(contract: unknown): contract is DocumentContract {\n return (\n typeof contract === 'object' &&\n contract !== null &&\n 'targetFamily' in contract &&\n contract.targetFamily === 'document'\n );\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly coreHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n}\n\n// Emitter types - moved from @prisma-next/emitter to shared location\n/**\n * Specifies how to import TypeScript types from a package.\n * Used in extension pack manifests to declare codec and operation type imports.\n */\nexport interface TypesImportSpec {\n readonly package: string;\n readonly named: string;\n readonly alias: string;\n}\n\n/**\n * Validation context passed to TargetFamilyHook.validateTypes().\n * Contains pre-assembled operation registry, type imports, and extension IDs.\n */\nexport interface ValidationContext {\n readonly operationRegistry?: OperationRegistry;\n readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds?: ReadonlyArray<string>;\n /**\n * Parameterized codec descriptors collected from adapters and extensions.\n * Map of codecId → descriptor for quick lookup during type generation.\n */\n readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;\n}\n\n/**\n * Context for rendering parameterized types during contract.d.ts generation.\n * Passed to type renderers so they can reference CodecTypes by name.\n */\nexport interface TypeRenderContext {\n readonly codecTypesName: string;\n}\n\n/**\n * A normalized type renderer for parameterized codecs.\n * This is the interface expected by TargetFamilyHook.generateContractTypes.\n */\nexport interface TypeRenderEntry {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;\n}\n\n/**\n * Additional options for generateContractTypes.\n */\nexport interface GenerateContractTypesOptions {\n /**\n * Normalized parameterized type renderers, keyed by codecId.\n * When a column has typeParams and a renderer exists for its codecId,\n * the renderer is called to produce the TypeScript type expression.\n */\n readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;\n}\n\n/**\n * SPI interface for target family hooks that extend emission behavior.\n * Implemented by family-specific emitter hooks (e.g., SQL family).\n */\nexport interface TargetFamilyHook {\n readonly id: string;\n\n /**\n * Validates that all type IDs in the contract come from referenced extension packs.\n * @param ir - Contract IR to validate\n * @param ctx - Validation context with operation registry and extension IDs\n */\n validateTypes(ir: ContractIR, ctx: ValidationContext): void;\n\n /**\n * Validates family-specific contract structure.\n * @param ir - Contract IR to validate\n */\n validateStructure(ir: ContractIR): void;\n\n /**\n * Generates contract.d.ts file content.\n * @param ir - Contract IR\n * @param codecTypeImports - Array of codec type import specs\n * @param operationTypeImports - Array of operation type import specs\n * @param options - Additional options including parameterized type renderers\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n options?: GenerateContractTypesOptions,\n ): string;\n}\n\n// Extension pack manifest types - moved from @prisma-next/core-control-plane to shared location\nexport type ArgSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'param' }\n | { readonly kind: 'literal' };\n\nexport type ReturnSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };\n\nexport interface LoweringSpecManifest {\n readonly targetFamily: 'sql';\n readonly strategy: 'infix' | 'function';\n readonly template: string;\n}\n\nexport interface OperationManifest {\n readonly for: string;\n readonly method: string;\n readonly args: ReadonlyArray<ArgSpecManifest>;\n readonly returns: ReturnSpecManifest;\n readonly lowering: LoweringSpecManifest;\n readonly capabilities?: ReadonlyArray<string>;\n}\n\n// ============================================================================\n// Parameterized Codec Descriptor Types\n// ============================================================================\n//\n// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).\n// These enable precise TypeScript types for parameterized columns without\n// coupling the SQL family emitter to specific adapter codec IDs.\n//\n// ============================================================================\n\n/**\n * Context passed to type renderer functions during contract.d.ts generation.\n * Provides access to names used in the generated contract for proper references.\n */\nexport interface RenderTypeContext {\n /** The name of the Contract type being generated (typically 'Contract') */\n readonly contractTypeName: string;\n /** The name of the merged CodecTypes map (typically 'CodecTypes') */\n readonly codecTypesName: string;\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":";AA2IO,SAAS,mBAAmB,UAAiD;AAClF,SACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB;AAE9B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { RenderTypeContext } from './framework-components';\nimport type { ContractIR } from './ir';\n\nexport interface ContractBase {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, Source>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'cuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface DocumentStorage {\n readonly document: {\n readonly collections: Record<string, DocCollection>;\n };\n}\n\nexport interface DocumentContract extends ContractBase {\n // Accept string to work with JSON imports; runtime validation ensures 'document'\n readonly targetFamily: string;\n readonly storage: DocumentStorage;\n}\n\n// Plan types - target-family agnostic execution types\nexport interface ParamDescriptor {\n readonly index?: number;\n readonly name?: string;\n readonly codecId?: string;\n readonly nativeType?: string;\n readonly nullable?: boolean;\n readonly source: 'dsl' | 'raw';\n readonly refs?: { table: string; column: string };\n}\n\nexport interface PlanRefs {\n readonly tables?: readonly string[];\n readonly columns?: ReadonlyArray<{ table: string; column: string }>;\n readonly indexes?: ReadonlyArray<{\n readonly table: string;\n readonly columns: ReadonlyArray<string>;\n readonly name?: string;\n }>;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly coreHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n codecs?: Record<string, string>; // alias/param → codec id ('ns/name@v')\n [key: string]: unknown;\n };\n readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;\n readonly refs?: PlanRefs;\n readonly projection?: Record<string, string> | ReadonlyArray<string>;\n /**\n * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).\n * Used for codec resolution when AST+refs don't provide enough type info.\n */\n readonly projectionTypes?: Record<string, string>;\n}\n\n/**\n * Canonical execution plan shape used by runtimes.\n *\n * - Row is the inferred result row type (TypeScript-only).\n * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).\n *\n * The payload executed by the runtime is represented by the sql + params pair\n * for now; future families can specialize this via Ast or additional metadata.\n */\nexport interface ExecutionPlan<Row = unknown, Ast = unknown> {\n readonly sql: string;\n readonly params: readonly unknown[];\n readonly ast?: Ast;\n readonly meta: PlanMeta;\n /**\n * Phantom property to carry the Row generic for type-level utilities.\n * Not set at runtime; used only for ResultType extraction.\n */\n readonly _row?: Row;\n}\n\n/**\n * Utility type to extract the Row type from an ExecutionPlan.\n * Example: `type Row = ResultType<typeof plan>`\n *\n * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).\n * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter\n * for type extraction.\n */\nexport type ResultType<P> =\n P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : never;\n\n/**\n * Type guard to check if a contract is a Document contract\n */\nexport function isDocumentContract(contract: unknown): contract is DocumentContract {\n return (\n typeof contract === 'object' &&\n contract !== null &&\n 'targetFamily' in contract &&\n contract.targetFamily === 'document'\n );\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly coreHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n}\n\n// Emitter types - moved from @prisma-next/emitter to shared location\n/**\n * Specifies how to import TypeScript types from a package.\n * Used in extension pack manifests to declare codec and operation type imports.\n */\nexport interface TypesImportSpec {\n readonly package: string;\n readonly named: string;\n readonly alias: string;\n}\n\n/**\n * Validation context passed to TargetFamilyHook.validateTypes().\n * Contains pre-assembled operation registry, type imports, and extension IDs.\n */\nexport interface ValidationContext {\n readonly operationRegistry?: OperationRegistry;\n readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds?: ReadonlyArray<string>;\n /**\n * Parameterized codec descriptors collected from adapters and extensions.\n * Map of codecId → descriptor for quick lookup during type generation.\n */\n readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;\n}\n\n/**\n * Context for rendering parameterized types during contract.d.ts generation.\n * Passed to type renderers so they can reference CodecTypes by name.\n */\nexport interface TypeRenderContext {\n readonly codecTypesName: string;\n}\n\n/**\n * A normalized type renderer for parameterized codecs.\n * This is the interface expected by TargetFamilyHook.generateContractTypes.\n */\nexport interface TypeRenderEntry {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;\n}\n\n/**\n * Additional options for generateContractTypes.\n */\nexport interface GenerateContractTypesOptions {\n /**\n * Normalized parameterized type renderers, keyed by codecId.\n * When a column has typeParams and a renderer exists for its codecId,\n * the renderer is called to produce the TypeScript type expression.\n */\n readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;\n /**\n * Type imports for parameterized codecs.\n * These are merged with codec and operation type imports in contract.d.ts.\n */\n readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;\n}\n\n/**\n * SPI interface for target family hooks that extend emission behavior.\n * Implemented by family-specific emitter hooks (e.g., SQL family).\n */\nexport interface TargetFamilyHook {\n readonly id: string;\n\n /**\n * Validates that all type IDs in the contract come from referenced extension packs.\n * @param ir - Contract IR to validate\n * @param ctx - Validation context with operation registry and extension IDs\n */\n validateTypes(ir: ContractIR, ctx: ValidationContext): void;\n\n /**\n * Validates family-specific contract structure.\n * @param ir - Contract IR to validate\n */\n validateStructure(ir: ContractIR): void;\n\n /**\n * Generates contract.d.ts file content.\n * @param ir - Contract IR\n * @param codecTypeImports - Array of codec type import specs\n * @param operationTypeImports - Array of operation type import specs\n * @param options - Additional options including parameterized type renderers\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n options?: GenerateContractTypesOptions,\n ): string;\n}\n\n// Extension pack manifest types - moved from @prisma-next/core-control-plane to shared location\nexport type ArgSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'param' }\n | { readonly kind: 'literal' };\n\nexport type ReturnSpecManifest =\n | { readonly kind: 'typeId'; readonly type: string }\n | { readonly kind: 'builtin'; readonly type: 'number' | 'boolean' | 'string' };\n\nexport interface LoweringSpecManifest {\n readonly targetFamily: 'sql';\n readonly strategy: 'infix' | 'function';\n readonly template: string;\n}\n\nexport interface OperationManifest {\n readonly for: string;\n readonly method: string;\n readonly args: ReadonlyArray<ArgSpecManifest>;\n readonly returns: ReturnSpecManifest;\n readonly lowering: LoweringSpecManifest;\n readonly capabilities?: ReadonlyArray<string>;\n}\n\n// ============================================================================\n// Parameterized Codec Descriptor Types\n// ============================================================================\n//\n// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).\n// These enable precise TypeScript types for parameterized columns without\n// coupling the SQL family emitter to specific adapter codec IDs.\n//\n// ============================================================================\n\n// Re-export RenderTypeContext so it's available alongside TypeRenderer\nexport type { RenderTypeContext };\n\n/**\n * Declarative type renderer that produces a TypeScript type expression.\n *\n * Renderers can be:\n * - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)\n * - A function that receives typeParams and context and returns a type expression\n *\n * **Prefer template strings** for most cases:\n * - Templates are JSON-serializable (safe for pack-ref metadata)\n * - Templates can be statically analyzed by tooling\n *\n * Function renderers are allowed but have tradeoffs:\n * - Require runtime execution during emission (the emitter runs code)\n * - Not JSON-serializable (can't be stored in contract.json)\n * - The emitted artifacts (contract.json, contract.d.ts) still contain no\n * executable code - this constraint applies to outputs, not the emission process\n */\nexport type TypeRenderer =\n | string\n | ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);\n\n/**\n * Descriptor for a codec that supports type parameters.\n *\n * Parameterized codecs allow columns to carry additional metadata (typeParams)\n * that affects the generated TypeScript types. For example:\n * - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`\n * - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`\n *\n * The SQL family emitter uses these descriptors to generate precise types\n * without hard-coding knowledge of specific codec IDs.\n *\n * @example\n * ```typescript\n * const vectorCodecDescriptor: ParameterizedCodecDescriptor = {\n * codecId: 'pg/vector@1',\n * outputTypeRenderer: 'Vector<{{length}}>',\n * // Optional: paramsSchema for runtime validation\n * };\n * ```\n */\nexport interface ParameterizedCodecDescriptor {\n /** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */\n readonly codecId: string;\n\n /**\n * Renderer for the output (read) type.\n * Can be a template string or function.\n *\n * This is the primary renderer used by SQL emission to generate\n * model field types in contract.d.ts.\n */\n readonly outputTypeRenderer: TypeRenderer;\n\n /**\n * Optional renderer for the input (write) type.\n * If not provided, outputTypeRenderer is used for both.\n *\n * **Reserved for future use**: Currently, SQL emission only uses\n * outputTypeRenderer. This field is defined for future support of\n * asymmetric codecs where input and output types differ (e.g., a\n * codec that accepts `string | number` but always returns `number`).\n */\n readonly inputTypeRenderer?: TypeRenderer;\n\n /**\n * Optional import spec for types used by this codec's renderers.\n * The emitter will add this import to contract.d.ts.\n */\n readonly typesImport?: TypesImportSpec;\n}\n"],"mappings":";AA4IO,SAAS,mBAAmB,UAAiD;AAClF,SACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB;AAE9B;","names":[]}
|
|
@@ -84,6 +84,8 @@ export interface NormalizedTypeRenderer {
|
|
|
84
84
|
/**
|
|
85
85
|
* Interpolates a template string with params values.
|
|
86
86
|
* Used internally by normalizeRenderer to compile templates to functions.
|
|
87
|
+
*
|
|
88
|
+
* @throws Error if a placeholder key is not found in params (except 'CodecTypes')
|
|
87
89
|
*/
|
|
88
90
|
export declare function interpolateTypeTemplate(template: string, params: Record<string, unknown>, ctx: RenderTypeContext): string;
|
|
89
91
|
/**
|
|
@@ -116,7 +118,11 @@ export interface ComponentMetadata {
|
|
|
116
118
|
/** Type imports for contract.d.ts generation */
|
|
117
119
|
readonly types?: {
|
|
118
120
|
readonly codecTypes?: {
|
|
119
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Base codec types import spec.
|
|
123
|
+
* Optional: adapters typically provide this, extensions usually don't.
|
|
124
|
+
*/
|
|
125
|
+
readonly import?: TypesImportSpec;
|
|
120
126
|
/**
|
|
121
127
|
* Optional renderers for parameterized codecs owned by this component.
|
|
122
128
|
* Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.
|
|
@@ -125,6 +131,12 @@ export interface ComponentMetadata {
|
|
|
125
131
|
* Duplicate codecId across descriptors is a hard error.
|
|
126
132
|
*/
|
|
127
133
|
readonly parameterized?: Record<string, TypeRenderer>;
|
|
134
|
+
/**
|
|
135
|
+
* Optional type imports for parameterized codecs.
|
|
136
|
+
* These imports are added to contract.d.ts when parameterized renderers
|
|
137
|
+
* reference types from external packages.
|
|
138
|
+
*/
|
|
139
|
+
readonly parameterizedImports?: ReadonlyArray<TypesImportSpec>;
|
|
128
140
|
};
|
|
129
141
|
readonly operationTypes?: {
|
|
130
142
|
readonly import: TypesImportSpec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-components.d.ts","sourceRoot":"","sources":["../src/framework-components.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAiBlE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,MAAM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,EAAE,SAAS,SAAS,MAAM;IAChF,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE7B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,eAAe,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IACjF,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE7B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cAAc,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IAChF,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE7B,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,iBAAiB,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IACnF,2CAA2C;IAC3C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE7B,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OperationRegistry } from '@prisma-next/operations';
|
|
2
|
+
import type { RenderTypeContext } from './framework-components';
|
|
2
3
|
import type { ContractIR } from './ir';
|
|
3
4
|
export interface ContractBase {
|
|
4
5
|
readonly schemaVersion: string;
|
|
@@ -195,6 +196,11 @@ export interface GenerateContractTypesOptions {
|
|
|
195
196
|
* the renderer is called to produce the TypeScript type expression.
|
|
196
197
|
*/
|
|
197
198
|
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
199
|
+
/**
|
|
200
|
+
* Type imports for parameterized codecs.
|
|
201
|
+
* These are merged with codec and operation type imports in contract.d.ts.
|
|
202
|
+
*/
|
|
203
|
+
readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
198
204
|
}
|
|
199
205
|
/**
|
|
200
206
|
* SPI interface for target family hooks that extend emission behavior.
|
|
@@ -251,16 +257,7 @@ export interface OperationManifest {
|
|
|
251
257
|
readonly lowering: LoweringSpecManifest;
|
|
252
258
|
readonly capabilities?: ReadonlyArray<string>;
|
|
253
259
|
}
|
|
254
|
-
|
|
255
|
-
* Context passed to type renderer functions during contract.d.ts generation.
|
|
256
|
-
* Provides access to names used in the generated contract for proper references.
|
|
257
|
-
*/
|
|
258
|
-
export interface RenderTypeContext {
|
|
259
|
-
/** The name of the Contract type being generated (typically 'Contract') */
|
|
260
|
-
readonly contractTypeName: string;
|
|
261
|
-
/** The name of the merged CodecTypes map (typically 'CodecTypes') */
|
|
262
|
-
readonly codecTypesName: string;
|
|
263
|
-
}
|
|
260
|
+
export type { RenderTypeContext };
|
|
264
261
|
/**
|
|
265
262
|
* Declarative type renderer that produces a TypeScript type expression.
|
|
266
263
|
*
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAA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G,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC/C;AAaD,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,iBAAiB,KAAK,MAAM,CAAC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;;;;OAMG;IACH,QAAQ,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAE1C;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,YAAY,CAAC;IAE1C;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC;CACxC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/contract",
|
|
3
|
-
"version": "0.3.0-pr.98.
|
|
3
|
+
"version": "0.3.0-pr.98.3",
|
|
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-pr.98.
|
|
8
|
+
"@prisma-next/operations": "0.3.0-pr.98.3"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"tsup": "8.5.1",
|
package/src/exports/types.ts
CHANGED
|
@@ -114,6 +114,8 @@ export interface NormalizedTypeRenderer {
|
|
|
114
114
|
/**
|
|
115
115
|
* Interpolates a template string with params values.
|
|
116
116
|
* Used internally by normalizeRenderer to compile templates to functions.
|
|
117
|
+
*
|
|
118
|
+
* @throws Error if a placeholder key is not found in params (except 'CodecTypes')
|
|
117
119
|
*/
|
|
118
120
|
export function interpolateTypeTemplate(
|
|
119
121
|
template: string,
|
|
@@ -123,7 +125,13 @@ export function interpolateTypeTemplate(
|
|
|
123
125
|
return template.replace(/\{\{(\w+)\}\}/g, (_, key: string) => {
|
|
124
126
|
if (key === 'CodecTypes') return ctx.codecTypesName;
|
|
125
127
|
const value = params[key];
|
|
126
|
-
|
|
128
|
+
if (value === undefined) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Missing template parameter "${key}" in template "${template}". ` +
|
|
131
|
+
`Available params: ${Object.keys(params).join(', ') || '(none)'}`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return String(value);
|
|
127
135
|
});
|
|
128
136
|
}
|
|
129
137
|
|
|
@@ -214,7 +222,11 @@ export interface ComponentMetadata {
|
|
|
214
222
|
/** Type imports for contract.d.ts generation */
|
|
215
223
|
readonly types?: {
|
|
216
224
|
readonly codecTypes?: {
|
|
217
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Base codec types import spec.
|
|
227
|
+
* Optional: adapters typically provide this, extensions usually don't.
|
|
228
|
+
*/
|
|
229
|
+
readonly import?: TypesImportSpec;
|
|
218
230
|
/**
|
|
219
231
|
* Optional renderers for parameterized codecs owned by this component.
|
|
220
232
|
* Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.
|
|
@@ -223,6 +235,12 @@ export interface ComponentMetadata {
|
|
|
223
235
|
* Duplicate codecId across descriptors is a hard error.
|
|
224
236
|
*/
|
|
225
237
|
readonly parameterized?: Record<string, TypeRenderer>;
|
|
238
|
+
/**
|
|
239
|
+
* Optional type imports for parameterized codecs.
|
|
240
|
+
* These imports are added to contract.d.ts when parameterized renderers
|
|
241
|
+
* reference types from external packages.
|
|
242
|
+
*/
|
|
243
|
+
readonly parameterizedImports?: ReadonlyArray<TypesImportSpec>;
|
|
226
244
|
};
|
|
227
245
|
readonly operationTypes?: { readonly import: TypesImportSpec };
|
|
228
246
|
readonly storage?: ReadonlyArray<{
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { OperationRegistry } from '@prisma-next/operations';
|
|
2
|
+
import type { RenderTypeContext } from './framework-components';
|
|
2
3
|
import type { ContractIR } from './ir';
|
|
3
4
|
|
|
4
5
|
export interface ContractBase {
|
|
@@ -214,6 +215,11 @@ export interface GenerateContractTypesOptions {
|
|
|
214
215
|
* the renderer is called to produce the TypeScript type expression.
|
|
215
216
|
*/
|
|
216
217
|
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
218
|
+
/**
|
|
219
|
+
* Type imports for parameterized codecs.
|
|
220
|
+
* These are merged with codec and operation type imports in contract.d.ts.
|
|
221
|
+
*/
|
|
222
|
+
readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
/**
|
|
@@ -287,16 +293,8 @@ export interface OperationManifest {
|
|
|
287
293
|
//
|
|
288
294
|
// ============================================================================
|
|
289
295
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
* Provides access to names used in the generated contract for proper references.
|
|
293
|
-
*/
|
|
294
|
-
export interface RenderTypeContext {
|
|
295
|
-
/** The name of the Contract type being generated (typically 'Contract') */
|
|
296
|
-
readonly contractTypeName: string;
|
|
297
|
-
/** The name of the merged CodecTypes map (typically 'CodecTypes') */
|
|
298
|
-
readonly codecTypesName: string;
|
|
299
|
-
}
|
|
296
|
+
// Re-export RenderTypeContext so it's available alongside TypeRenderer
|
|
297
|
+
export type { RenderTypeContext };
|
|
300
298
|
|
|
301
299
|
/**
|
|
302
300
|
* Declarative type renderer that produces a TypeScript type expression.
|