@prisma-next/contract 0.3.0-pr.93.5 → 0.3.0-pr.96.1
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.d.ts +2 -2
- package/dist/exports/framework-components.d.ts.map +1 -1
- package/dist/exports/framework-components.js +29 -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 +106 -0
- package/dist/framework-components.d.ts.map +1 -1
- package/dist/types.d.ts +103 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/exports/framework-components.ts +11 -1
- package/src/exports/types.ts +8 -0
- package/src/framework-components.ts +175 -1
- package/src/types.ts +124 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { AdapterDescriptor, AdapterInstance, AdapterPackRef, ComponentDescriptor, ComponentMetadata, ContractComponentRequirementsCheckInput, ContractComponentRequirementsCheckResult, DriverDescriptor, DriverInstance, DriverPackRef, ExtensionDescriptor, ExtensionInstance, ExtensionPackRef, FamilyDescriptor, FamilyInstance, PackRefBase, TargetBoundComponentDescriptor, TargetDescriptor, TargetInstance, TargetPackRef, } from '../framework-components';
|
|
2
|
-
export { checkContractComponentRequirements } from '../framework-components';
|
|
1
|
+
export type { AdapterDescriptor, AdapterInstance, AdapterPackRef, ComponentDescriptor, ComponentMetadata, ContractComponentRequirementsCheckInput, ContractComponentRequirementsCheckResult, DriverDescriptor, DriverInstance, DriverPackRef, ExtensionDescriptor, ExtensionInstance, ExtensionPackRef, FamilyDescriptor, FamilyInstance, NormalizedTypeRenderer, PackRefBase, RenderTypeContext, TargetBoundComponentDescriptor, TargetDescriptor, TargetInstance, TargetPackRef, TypeRenderer, TypeRendererFunction, TypeRendererTemplate, } from '../framework-components';
|
|
2
|
+
export { checkContractComponentRequirements, interpolateTypeTemplate, normalizeRenderer, } from '../framework-components';
|
|
3
3
|
//# sourceMappingURL=framework-components.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-components.d.ts","sourceRoot":"","sources":["../../src/exports/framework-components.ts"],"names":[],"mappings":"AAAA,YAAY,EAEV,iBAAiB,EAEjB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,uCAAuC,EACvC,wCAAwC,EACxC,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,
|
|
1
|
+
{"version":3,"file":"framework-components.d.ts","sourceRoot":"","sources":["../../src/exports/framework-components.ts"],"names":[],"mappings":"AAAA,YAAY,EAEV,iBAAiB,EAEjB,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,uCAAuC,EACvC,wCAAwC,EACxC,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EAEd,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,8BAA8B,EAC9B,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
// src/framework-components.ts
|
|
2
|
+
function interpolateTypeTemplate(template, params, ctx) {
|
|
3
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_, key) => {
|
|
4
|
+
if (key === "CodecTypes") return ctx.codecTypesName;
|
|
5
|
+
const value = params[key];
|
|
6
|
+
return value !== void 0 ? String(value) : "";
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function normalizeRenderer(codecId, renderer) {
|
|
10
|
+
if (typeof renderer === "string") {
|
|
11
|
+
return {
|
|
12
|
+
codecId,
|
|
13
|
+
render: (params, ctx) => interpolateTypeTemplate(renderer, params, ctx)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (typeof renderer === "function") {
|
|
17
|
+
return { codecId, render: renderer };
|
|
18
|
+
}
|
|
19
|
+
if (renderer.kind === "function") {
|
|
20
|
+
return { codecId, render: renderer.render };
|
|
21
|
+
}
|
|
22
|
+
const { template } = renderer;
|
|
23
|
+
return {
|
|
24
|
+
codecId,
|
|
25
|
+
render: (params, ctx) => interpolateTypeTemplate(template, params, ctx)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
2
28
|
function checkContractComponentRequirements(input) {
|
|
3
29
|
const providedIds = /* @__PURE__ */ new Set();
|
|
4
30
|
for (const id of input.providedComponentIds) {
|
|
@@ -19,6 +45,8 @@ function checkContractComponentRequirements(input) {
|
|
|
19
45
|
};
|
|
20
46
|
}
|
|
21
47
|
export {
|
|
22
|
-
checkContractComponentRequirements
|
|
48
|
+
checkContractComponentRequirements,
|
|
49
|
+
interpolateTypeTemplate,
|
|
50
|
+
normalizeRenderer
|
|
23
51
|
};
|
|
24
52
|
//# sourceMappingURL=framework-components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/framework-components.ts"],"sourcesContent":["import type { OperationManifest, TypesImportSpec } from './types';\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?: { readonly import: TypesImportSpec };\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":";AA6GO,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 */\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":[]}
|
package/dist/exports/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { ContractBase, ContractMarkerRecord, DocCollection, DocIndex, DocumentContract, DocumentStorage, ExecutionPlan, Expr, FieldType, OperationManifest, ParamDescriptor, PlanMeta, PlanRefs, ResultType, Source, TargetFamilyHook, TypesImportSpec, ValidationContext, } from '../types';
|
|
1
|
+
export type { ContractBase, ContractMarkerRecord, DocCollection, DocIndex, DocumentContract, DocumentStorage, ExecutionPlan, Expr, FieldType, GenerateContractTypesOptions, OperationManifest, ParamDescriptor, ParameterizedCodecDescriptor, PlanMeta, PlanRefs, RenderTypeContext, 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":"
|
|
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,iBAAiB,EACjB,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\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 * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\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"],"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 { 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\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,4 +1,102 @@
|
|
|
1
1
|
import type { OperationManifest, TypesImportSpec } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Context passed to type renderers during contract.d.ts generation.
|
|
4
|
+
*/
|
|
5
|
+
export interface RenderTypeContext {
|
|
6
|
+
/** The name of the CodecTypes type alias (typically 'CodecTypes') */
|
|
7
|
+
readonly codecTypesName: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A template-based type renderer (structured form).
|
|
11
|
+
* Uses mustache-style placeholders (e.g., `Vector<{{length}}>`) that are
|
|
12
|
+
* replaced with typeParams values during rendering.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* { kind: 'template', template: 'Vector<{{length}}>' }
|
|
17
|
+
* // With typeParams { length: 1536 }, renders: 'Vector<1536>'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface TypeRendererTemplate {
|
|
21
|
+
readonly kind: 'template';
|
|
22
|
+
/** Template string with `{{key}}` placeholders for typeParams values */
|
|
23
|
+
readonly template: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A function-based type renderer for full control over type expression generation.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* {
|
|
31
|
+
* kind: 'function',
|
|
32
|
+
* render: (params, ctx) => `Vector<${params.length}>`
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface TypeRendererFunction {
|
|
37
|
+
readonly kind: 'function';
|
|
38
|
+
/** Render function that produces a TypeScript type expression */
|
|
39
|
+
readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A raw template string type renderer (convenience form).
|
|
43
|
+
* Shorthand for TypeRendererTemplate - just the template string without wrapper.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* 'Vector<{{length}}>'
|
|
48
|
+
* // Equivalent to: { kind: 'template', template: 'Vector<{{length}}>' }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type TypeRendererString = string;
|
|
52
|
+
/**
|
|
53
|
+
* A raw function type renderer (convenience form).
|
|
54
|
+
* Shorthand for TypeRendererFunction - just the function without wrapper.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* (params, ctx) => `Vector<${params.length}>`
|
|
59
|
+
* // Equivalent to: { kind: 'function', render: ... }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export type TypeRendererRawFunction = (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
|
|
63
|
+
/**
|
|
64
|
+
* Union of type renderer formats.
|
|
65
|
+
*
|
|
66
|
+
* Supports both structured forms (with `kind` discriminator) and convenience forms:
|
|
67
|
+
* - `string` - Template string with `{{key}}` placeholders (manifest-safe, JSON-serializable)
|
|
68
|
+
* - `function` - Render function for full control (requires runtime execution)
|
|
69
|
+
* - `{ kind: 'template', template: string }` - Structured template form
|
|
70
|
+
* - `{ kind: 'function', render: fn }` - Structured function form
|
|
71
|
+
*
|
|
72
|
+
* Templates are normalized to functions during pack assembly.
|
|
73
|
+
* **Prefer template strings** for most cases - they are JSON-serializable.
|
|
74
|
+
*/
|
|
75
|
+
export type TypeRenderer = TypeRendererString | TypeRendererRawFunction | TypeRendererTemplate | TypeRendererFunction;
|
|
76
|
+
/**
|
|
77
|
+
* Normalized type renderer - always a function after assembly.
|
|
78
|
+
* This is the form received by the emitter.
|
|
79
|
+
*/
|
|
80
|
+
export interface NormalizedTypeRenderer {
|
|
81
|
+
readonly codecId: string;
|
|
82
|
+
readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Interpolates a template string with params values.
|
|
86
|
+
* Used internally by normalizeRenderer to compile templates to functions.
|
|
87
|
+
*/
|
|
88
|
+
export declare function interpolateTypeTemplate(template: string, params: Record<string, unknown>, ctx: RenderTypeContext): string;
|
|
89
|
+
/**
|
|
90
|
+
* Normalizes a TypeRenderer to function form.
|
|
91
|
+
* Called during pack assembly, not at emission time.
|
|
92
|
+
*
|
|
93
|
+
* Handles all TypeRenderer forms:
|
|
94
|
+
* - Raw string template: `'Vector<{{length}}>'`
|
|
95
|
+
* - Raw function: `(params, ctx) => ...`
|
|
96
|
+
* - Structured template: `{ kind: 'template', template: '...' }`
|
|
97
|
+
* - Structured function: `{ kind: 'function', render: fn }`
|
|
98
|
+
*/
|
|
99
|
+
export declare function normalizeRenderer(codecId: string, renderer: TypeRenderer): NormalizedTypeRenderer;
|
|
2
100
|
/**
|
|
3
101
|
* Declarative fields that describe component metadata.
|
|
4
102
|
* These fields are owned directly by descriptors (not nested under a manifest).
|
|
@@ -19,6 +117,14 @@ export interface ComponentMetadata {
|
|
|
19
117
|
readonly types?: {
|
|
20
118
|
readonly codecTypes?: {
|
|
21
119
|
readonly import: TypesImportSpec;
|
|
120
|
+
/**
|
|
121
|
+
* Optional renderers for parameterized codecs owned by this component.
|
|
122
|
+
* Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.
|
|
123
|
+
*
|
|
124
|
+
* Templates are normalized to functions during pack assembly.
|
|
125
|
+
* Duplicate codecId across descriptors is a hard error.
|
|
126
|
+
*/
|
|
127
|
+
readonly parameterized?: Record<string, TypeRenderer>;
|
|
22
128
|
};
|
|
23
129
|
readonly operationTypes?: {
|
|
24
130
|
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;AA+
|
|
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,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAA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AyC;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
|
@@ -165,6 +165,32 @@ export interface ValidationContext {
|
|
|
165
165
|
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
166
166
|
readonly extensionIds?: ReadonlyArray<string>;
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Context for rendering parameterized types during contract.d.ts generation.
|
|
170
|
+
* Passed to type renderers so they can reference CodecTypes by name.
|
|
171
|
+
*/
|
|
172
|
+
export interface TypeRenderContext {
|
|
173
|
+
readonly codecTypesName: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A normalized type renderer for parameterized codecs.
|
|
177
|
+
* This is the interface expected by TargetFamilyHook.generateContractTypes.
|
|
178
|
+
*/
|
|
179
|
+
export interface TypeRenderEntry {
|
|
180
|
+
readonly codecId: string;
|
|
181
|
+
readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Additional options for generateContractTypes.
|
|
185
|
+
*/
|
|
186
|
+
export interface GenerateContractTypesOptions {
|
|
187
|
+
/**
|
|
188
|
+
* Normalized parameterized type renderers, keyed by codecId.
|
|
189
|
+
* When a column has typeParams and a renderer exists for its codecId,
|
|
190
|
+
* the renderer is called to produce the TypeScript type expression.
|
|
191
|
+
*/
|
|
192
|
+
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
193
|
+
}
|
|
168
194
|
/**
|
|
169
195
|
* SPI interface for target family hooks that extend emission behavior.
|
|
170
196
|
* Implemented by family-specific emitter hooks (e.g., SQL family).
|
|
@@ -187,9 +213,10 @@ export interface TargetFamilyHook {
|
|
|
187
213
|
* @param ir - Contract IR
|
|
188
214
|
* @param codecTypeImports - Array of codec type import specs
|
|
189
215
|
* @param operationTypeImports - Array of operation type import specs
|
|
216
|
+
* @param options - Additional options including parameterized type renderers
|
|
190
217
|
* @returns Generated TypeScript type definitions as string
|
|
191
218
|
*/
|
|
192
|
-
generateContractTypes(ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec
|
|
219
|
+
generateContractTypes(ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec>, options?: GenerateContractTypesOptions): string;
|
|
193
220
|
}
|
|
194
221
|
export type ArgSpecManifest = {
|
|
195
222
|
readonly kind: 'typeId';
|
|
@@ -219,4 +246,79 @@ export interface OperationManifest {
|
|
|
219
246
|
readonly lowering: LoweringSpecManifest;
|
|
220
247
|
readonly capabilities?: ReadonlyArray<string>;
|
|
221
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Context passed to type renderer functions during contract.d.ts generation.
|
|
251
|
+
* Provides access to names used in the generated contract for proper references.
|
|
252
|
+
*/
|
|
253
|
+
export interface RenderTypeContext {
|
|
254
|
+
/** The name of the Contract type being generated (typically 'Contract') */
|
|
255
|
+
readonly contractTypeName: string;
|
|
256
|
+
/** The name of the merged CodecTypes map (typically 'CodecTypes') */
|
|
257
|
+
readonly codecTypesName: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Declarative type renderer that produces a TypeScript type expression.
|
|
261
|
+
*
|
|
262
|
+
* Renderers can be:
|
|
263
|
+
* - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)
|
|
264
|
+
* - A function that receives typeParams and context and returns a type expression
|
|
265
|
+
*
|
|
266
|
+
* **Prefer template strings** for most cases:
|
|
267
|
+
* - Templates are JSON-serializable (safe for pack-ref metadata)
|
|
268
|
+
* - Templates can be statically analyzed by tooling
|
|
269
|
+
*
|
|
270
|
+
* Function renderers are allowed but have tradeoffs:
|
|
271
|
+
* - Require runtime execution during emission (the emitter runs code)
|
|
272
|
+
* - Not JSON-serializable (can't be stored in contract.json)
|
|
273
|
+
* - The emitted artifacts (contract.json, contract.d.ts) still contain no
|
|
274
|
+
* executable code - this constraint applies to outputs, not the emission process
|
|
275
|
+
*/
|
|
276
|
+
export type TypeRenderer = string | ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);
|
|
277
|
+
/**
|
|
278
|
+
* Descriptor for a codec that supports type parameters.
|
|
279
|
+
*
|
|
280
|
+
* Parameterized codecs allow columns to carry additional metadata (typeParams)
|
|
281
|
+
* that affects the generated TypeScript types. For example:
|
|
282
|
+
* - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`
|
|
283
|
+
* - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`
|
|
284
|
+
*
|
|
285
|
+
* The SQL family emitter uses these descriptors to generate precise types
|
|
286
|
+
* without hard-coding knowledge of specific codec IDs.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const vectorCodecDescriptor: ParameterizedCodecDescriptor = {
|
|
291
|
+
* codecId: 'pg/vector@1',
|
|
292
|
+
* outputTypeRenderer: 'Vector<{{length}}>',
|
|
293
|
+
* // Optional: paramsSchema for runtime validation
|
|
294
|
+
* };
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export interface ParameterizedCodecDescriptor {
|
|
298
|
+
/** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */
|
|
299
|
+
readonly codecId: string;
|
|
300
|
+
/**
|
|
301
|
+
* Renderer for the output (read) type.
|
|
302
|
+
* Can be a template string or function.
|
|
303
|
+
*
|
|
304
|
+
* This is the primary renderer used by SQL emission to generate
|
|
305
|
+
* model field types in contract.d.ts.
|
|
306
|
+
*/
|
|
307
|
+
readonly outputTypeRenderer: TypeRenderer;
|
|
308
|
+
/**
|
|
309
|
+
* Optional renderer for the input (write) type.
|
|
310
|
+
* If not provided, outputTypeRenderer is used for both.
|
|
311
|
+
*
|
|
312
|
+
* **Reserved for future use**: Currently, SQL emission only uses
|
|
313
|
+
* outputTypeRenderer. This field is defined for future support of
|
|
314
|
+
* asymmetric codecs where input and output types differ (e.g., a
|
|
315
|
+
* codec that accepts `string | number` but always returns `number`).
|
|
316
|
+
*/
|
|
317
|
+
readonly inputTypeRenderer?: TypeRenderer;
|
|
318
|
+
/**
|
|
319
|
+
* Optional import spec for types used by this codec's renderers.
|
|
320
|
+
* The emitter will add this import to contract.d.ts.
|
|
321
|
+
*/
|
|
322
|
+
readonly typesImport?: TypesImportSpec;
|
|
323
|
+
}
|
|
222
324
|
//# sourceMappingURL=types.d.ts.map
|
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,QAA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ClC,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;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,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/contract",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.96.1",
|
|
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.
|
|
8
|
+
"@prisma-next/operations": "0.3.0-pr.96.1"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"tsup": "8.5.1",
|
|
12
12
|
"typescript": "5.9.3",
|
|
13
13
|
"vitest": "4.0.16",
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/
|
|
14
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
15
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"./schema-document": "./schemas/data-contract-document-v1.json"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "tsup && tsc",
|
|
42
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
43
43
|
"test": "vitest run --passWithNoTests",
|
|
44
44
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
45
|
-
"typecheck": "tsc --noEmit",
|
|
45
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
46
46
|
"lint": "biome check . --error-on-warnings",
|
|
47
47
|
"lint:fix": "biome check --write .",
|
|
48
48
|
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
@@ -16,11 +16,21 @@ export type {
|
|
|
16
16
|
ExtensionPackRef,
|
|
17
17
|
FamilyDescriptor,
|
|
18
18
|
FamilyInstance,
|
|
19
|
+
// Type renderers for parameterized codec emission
|
|
20
|
+
NormalizedTypeRenderer,
|
|
19
21
|
PackRefBase,
|
|
22
|
+
RenderTypeContext,
|
|
20
23
|
TargetBoundComponentDescriptor,
|
|
21
24
|
TargetDescriptor,
|
|
22
25
|
TargetInstance,
|
|
23
26
|
TargetPackRef,
|
|
27
|
+
TypeRenderer,
|
|
28
|
+
TypeRendererFunction,
|
|
29
|
+
TypeRendererTemplate,
|
|
24
30
|
} from '../framework-components';
|
|
25
31
|
|
|
26
|
-
export {
|
|
32
|
+
export {
|
|
33
|
+
checkContractComponentRequirements,
|
|
34
|
+
interpolateTypeTemplate,
|
|
35
|
+
normalizeRenderer,
|
|
36
|
+
} from '../framework-components';
|
package/src/exports/types.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Document family types
|
|
3
3
|
// Plan types - target-family agnostic execution types
|
|
4
4
|
// Emitter types (moved from @prisma-next/emitter)
|
|
5
|
+
// Parameterized codec descriptor types
|
|
5
6
|
export type {
|
|
6
7
|
ContractBase,
|
|
7
8
|
ContractMarkerRecord,
|
|
@@ -12,13 +13,20 @@ export type {
|
|
|
12
13
|
ExecutionPlan,
|
|
13
14
|
Expr,
|
|
14
15
|
FieldType,
|
|
16
|
+
// Type generation options for parameterized codecs
|
|
17
|
+
GenerateContractTypesOptions,
|
|
15
18
|
OperationManifest,
|
|
16
19
|
ParamDescriptor,
|
|
20
|
+
ParameterizedCodecDescriptor,
|
|
17
21
|
PlanMeta,
|
|
18
22
|
PlanRefs,
|
|
23
|
+
RenderTypeContext,
|
|
19
24
|
ResultType,
|
|
20
25
|
Source,
|
|
21
26
|
TargetFamilyHook,
|
|
27
|
+
TypeRenderContext,
|
|
28
|
+
TypeRenderEntry,
|
|
29
|
+
TypeRenderer,
|
|
22
30
|
TypesImportSpec,
|
|
23
31
|
ValidationContext,
|
|
24
32
|
} from '../types';
|
|
@@ -1,5 +1,169 @@
|
|
|
1
1
|
import type { OperationManifest, TypesImportSpec } from './types';
|
|
2
2
|
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Type Renderer Types (for parameterized codec emission)
|
|
5
|
+
// ============================================================================
|
|
6
|
+
//
|
|
7
|
+
// TypeRenderer supports author-friendly authoring (template strings) that are
|
|
8
|
+
// normalized to functions during pack assembly. The emitter only receives
|
|
9
|
+
// normalized (function-form) renderers.
|
|
10
|
+
//
|
|
11
|
+
// Lifecycle:
|
|
12
|
+
// 1. Authoring: Descriptor author uses template string or function
|
|
13
|
+
// 2. Assembly: Templates are compiled to functions via normalizeRenderer()
|
|
14
|
+
// 3. Emission: Emitter calls normalized render functions
|
|
15
|
+
//
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Context passed to type renderers during contract.d.ts generation.
|
|
20
|
+
*/
|
|
21
|
+
export interface RenderTypeContext {
|
|
22
|
+
/** The name of the CodecTypes type alias (typically 'CodecTypes') */
|
|
23
|
+
readonly codecTypesName: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A template-based type renderer (structured form).
|
|
28
|
+
* Uses mustache-style placeholders (e.g., `Vector<{{length}}>`) that are
|
|
29
|
+
* replaced with typeParams values during rendering.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* { kind: 'template', template: 'Vector<{{length}}>' }
|
|
34
|
+
* // With typeParams { length: 1536 }, renders: 'Vector<1536>'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export interface TypeRendererTemplate {
|
|
38
|
+
readonly kind: 'template';
|
|
39
|
+
/** Template string with `{{key}}` placeholders for typeParams values */
|
|
40
|
+
readonly template: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A function-based type renderer for full control over type expression generation.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* {
|
|
49
|
+
* kind: 'function',
|
|
50
|
+
* render: (params, ctx) => `Vector<${params.length}>`
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface TypeRendererFunction {
|
|
55
|
+
readonly kind: 'function';
|
|
56
|
+
/** Render function that produces a TypeScript type expression */
|
|
57
|
+
readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A raw template string type renderer (convenience form).
|
|
62
|
+
* Shorthand for TypeRendererTemplate - just the template string without wrapper.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* 'Vector<{{length}}>'
|
|
67
|
+
* // Equivalent to: { kind: 'template', template: 'Vector<{{length}}>' }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export type TypeRendererString = string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A raw function type renderer (convenience form).
|
|
74
|
+
* Shorthand for TypeRendererFunction - just the function without wrapper.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* (params, ctx) => `Vector<${params.length}>`
|
|
79
|
+
* // Equivalent to: { kind: 'function', render: ... }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export type TypeRendererRawFunction = (
|
|
83
|
+
params: Record<string, unknown>,
|
|
84
|
+
ctx: RenderTypeContext,
|
|
85
|
+
) => string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Union of type renderer formats.
|
|
89
|
+
*
|
|
90
|
+
* Supports both structured forms (with `kind` discriminator) and convenience forms:
|
|
91
|
+
* - `string` - Template string with `{{key}}` placeholders (manifest-safe, JSON-serializable)
|
|
92
|
+
* - `function` - Render function for full control (requires runtime execution)
|
|
93
|
+
* - `{ kind: 'template', template: string }` - Structured template form
|
|
94
|
+
* - `{ kind: 'function', render: fn }` - Structured function form
|
|
95
|
+
*
|
|
96
|
+
* Templates are normalized to functions during pack assembly.
|
|
97
|
+
* **Prefer template strings** for most cases - they are JSON-serializable.
|
|
98
|
+
*/
|
|
99
|
+
export type TypeRenderer =
|
|
100
|
+
| TypeRendererString
|
|
101
|
+
| TypeRendererRawFunction
|
|
102
|
+
| TypeRendererTemplate
|
|
103
|
+
| TypeRendererFunction;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Normalized type renderer - always a function after assembly.
|
|
107
|
+
* This is the form received by the emitter.
|
|
108
|
+
*/
|
|
109
|
+
export interface NormalizedTypeRenderer {
|
|
110
|
+
readonly codecId: string;
|
|
111
|
+
readonly render: (params: Record<string, unknown>, ctx: RenderTypeContext) => string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Interpolates a template string with params values.
|
|
116
|
+
* Used internally by normalizeRenderer to compile templates to functions.
|
|
117
|
+
*/
|
|
118
|
+
export function interpolateTypeTemplate(
|
|
119
|
+
template: string,
|
|
120
|
+
params: Record<string, unknown>,
|
|
121
|
+
ctx: RenderTypeContext,
|
|
122
|
+
): string {
|
|
123
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_, key: string) => {
|
|
124
|
+
if (key === 'CodecTypes') return ctx.codecTypesName;
|
|
125
|
+
const value = params[key];
|
|
126
|
+
return value !== undefined ? String(value) : '';
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Normalizes a TypeRenderer to function form.
|
|
132
|
+
* Called during pack assembly, not at emission time.
|
|
133
|
+
*
|
|
134
|
+
* Handles all TypeRenderer forms:
|
|
135
|
+
* - Raw string template: `'Vector<{{length}}>'`
|
|
136
|
+
* - Raw function: `(params, ctx) => ...`
|
|
137
|
+
* - Structured template: `{ kind: 'template', template: '...' }`
|
|
138
|
+
* - Structured function: `{ kind: 'function', render: fn }`
|
|
139
|
+
*/
|
|
140
|
+
export function normalizeRenderer(codecId: string, renderer: TypeRenderer): NormalizedTypeRenderer {
|
|
141
|
+
// Handle raw string (template shorthand)
|
|
142
|
+
if (typeof renderer === 'string') {
|
|
143
|
+
return {
|
|
144
|
+
codecId,
|
|
145
|
+
render: (params, ctx) => interpolateTypeTemplate(renderer, params, ctx),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Handle raw function (function shorthand)
|
|
150
|
+
if (typeof renderer === 'function') {
|
|
151
|
+
return { codecId, render: renderer };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Handle structured function form
|
|
155
|
+
if (renderer.kind === 'function') {
|
|
156
|
+
return { codecId, render: renderer.render };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Handle structured template form
|
|
160
|
+
const { template } = renderer;
|
|
161
|
+
return {
|
|
162
|
+
codecId,
|
|
163
|
+
render: (params, ctx) => interpolateTypeTemplate(template, params, ctx),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
3
167
|
// ============================================================================
|
|
4
168
|
// Framework Component Descriptor Base Types
|
|
5
169
|
// ============================================================================
|
|
@@ -49,7 +213,17 @@ export interface ComponentMetadata {
|
|
|
49
213
|
|
|
50
214
|
/** Type imports for contract.d.ts generation */
|
|
51
215
|
readonly types?: {
|
|
52
|
-
readonly codecTypes?: {
|
|
216
|
+
readonly codecTypes?: {
|
|
217
|
+
readonly import: TypesImportSpec;
|
|
218
|
+
/**
|
|
219
|
+
* Optional renderers for parameterized codecs owned by this component.
|
|
220
|
+
* Key is codecId (e.g., 'pg/vector@1'), value is the type renderer.
|
|
221
|
+
*
|
|
222
|
+
* Templates are normalized to functions during pack assembly.
|
|
223
|
+
* Duplicate codecId across descriptors is a hard error.
|
|
224
|
+
*/
|
|
225
|
+
readonly parameterized?: Record<string, TypeRenderer>;
|
|
226
|
+
};
|
|
53
227
|
readonly operationTypes?: { readonly import: TypesImportSpec };
|
|
54
228
|
readonly storage?: ReadonlyArray<{
|
|
55
229
|
readonly typeId: string;
|
package/src/types.ts
CHANGED
|
@@ -182,6 +182,35 @@ export interface ValidationContext {
|
|
|
182
182
|
readonly extensionIds?: ReadonlyArray<string>;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Context for rendering parameterized types during contract.d.ts generation.
|
|
187
|
+
* Passed to type renderers so they can reference CodecTypes by name.
|
|
188
|
+
*/
|
|
189
|
+
export interface TypeRenderContext {
|
|
190
|
+
readonly codecTypesName: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A normalized type renderer for parameterized codecs.
|
|
195
|
+
* This is the interface expected by TargetFamilyHook.generateContractTypes.
|
|
196
|
+
*/
|
|
197
|
+
export interface TypeRenderEntry {
|
|
198
|
+
readonly codecId: string;
|
|
199
|
+
readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Additional options for generateContractTypes.
|
|
204
|
+
*/
|
|
205
|
+
export interface GenerateContractTypesOptions {
|
|
206
|
+
/**
|
|
207
|
+
* Normalized parameterized type renderers, keyed by codecId.
|
|
208
|
+
* When a column has typeParams and a renderer exists for its codecId,
|
|
209
|
+
* the renderer is called to produce the TypeScript type expression.
|
|
210
|
+
*/
|
|
211
|
+
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
212
|
+
}
|
|
213
|
+
|
|
185
214
|
/**
|
|
186
215
|
* SPI interface for target family hooks that extend emission behavior.
|
|
187
216
|
* Implemented by family-specific emitter hooks (e.g., SQL family).
|
|
@@ -207,12 +236,14 @@ export interface TargetFamilyHook {
|
|
|
207
236
|
* @param ir - Contract IR
|
|
208
237
|
* @param codecTypeImports - Array of codec type import specs
|
|
209
238
|
* @param operationTypeImports - Array of operation type import specs
|
|
239
|
+
* @param options - Additional options including parameterized type renderers
|
|
210
240
|
* @returns Generated TypeScript type definitions as string
|
|
211
241
|
*/
|
|
212
242
|
generateContractTypes(
|
|
213
243
|
ir: ContractIR,
|
|
214
244
|
codecTypeImports: ReadonlyArray<TypesImportSpec>,
|
|
215
245
|
operationTypeImports: ReadonlyArray<TypesImportSpec>,
|
|
246
|
+
options?: GenerateContractTypesOptions,
|
|
216
247
|
): string;
|
|
217
248
|
}
|
|
218
249
|
|
|
@@ -240,3 +271,96 @@ export interface OperationManifest {
|
|
|
240
271
|
readonly lowering: LoweringSpecManifest;
|
|
241
272
|
readonly capabilities?: ReadonlyArray<string>;
|
|
242
273
|
}
|
|
274
|
+
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// Parameterized Codec Descriptor Types
|
|
277
|
+
// ============================================================================
|
|
278
|
+
//
|
|
279
|
+
// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).
|
|
280
|
+
// These enable precise TypeScript types for parameterized columns without
|
|
281
|
+
// coupling the SQL family emitter to specific adapter codec IDs.
|
|
282
|
+
//
|
|
283
|
+
// ============================================================================
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Context passed to type renderer functions during contract.d.ts generation.
|
|
287
|
+
* Provides access to names used in the generated contract for proper references.
|
|
288
|
+
*/
|
|
289
|
+
export interface RenderTypeContext {
|
|
290
|
+
/** The name of the Contract type being generated (typically 'Contract') */
|
|
291
|
+
readonly contractTypeName: string;
|
|
292
|
+
/** The name of the merged CodecTypes map (typically 'CodecTypes') */
|
|
293
|
+
readonly codecTypesName: string;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Declarative type renderer that produces a TypeScript type expression.
|
|
298
|
+
*
|
|
299
|
+
* Renderers can be:
|
|
300
|
+
* - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)
|
|
301
|
+
* - A function that receives typeParams and context and returns a type expression
|
|
302
|
+
*
|
|
303
|
+
* **Prefer template strings** for most cases:
|
|
304
|
+
* - Templates are JSON-serializable (safe for pack-ref metadata)
|
|
305
|
+
* - Templates can be statically analyzed by tooling
|
|
306
|
+
*
|
|
307
|
+
* Function renderers are allowed but have tradeoffs:
|
|
308
|
+
* - Require runtime execution during emission (the emitter runs code)
|
|
309
|
+
* - Not JSON-serializable (can't be stored in contract.json)
|
|
310
|
+
* - The emitted artifacts (contract.json, contract.d.ts) still contain no
|
|
311
|
+
* executable code - this constraint applies to outputs, not the emission process
|
|
312
|
+
*/
|
|
313
|
+
export type TypeRenderer =
|
|
314
|
+
| string
|
|
315
|
+
| ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Descriptor for a codec that supports type parameters.
|
|
319
|
+
*
|
|
320
|
+
* Parameterized codecs allow columns to carry additional metadata (typeParams)
|
|
321
|
+
* that affects the generated TypeScript types. For example:
|
|
322
|
+
* - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`
|
|
323
|
+
* - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`
|
|
324
|
+
*
|
|
325
|
+
* The SQL family emitter uses these descriptors to generate precise types
|
|
326
|
+
* without hard-coding knowledge of specific codec IDs.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const vectorCodecDescriptor: ParameterizedCodecDescriptor = {
|
|
331
|
+
* codecId: 'pg/vector@1',
|
|
332
|
+
* outputTypeRenderer: 'Vector<{{length}}>',
|
|
333
|
+
* // Optional: paramsSchema for runtime validation
|
|
334
|
+
* };
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
export interface ParameterizedCodecDescriptor {
|
|
338
|
+
/** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */
|
|
339
|
+
readonly codecId: string;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Renderer for the output (read) type.
|
|
343
|
+
* Can be a template string or function.
|
|
344
|
+
*
|
|
345
|
+
* This is the primary renderer used by SQL emission to generate
|
|
346
|
+
* model field types in contract.d.ts.
|
|
347
|
+
*/
|
|
348
|
+
readonly outputTypeRenderer: TypeRenderer;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Optional renderer for the input (write) type.
|
|
352
|
+
* If not provided, outputTypeRenderer is used for both.
|
|
353
|
+
*
|
|
354
|
+
* **Reserved for future use**: Currently, SQL emission only uses
|
|
355
|
+
* outputTypeRenderer. This field is defined for future support of
|
|
356
|
+
* asymmetric codecs where input and output types differ (e.g., a
|
|
357
|
+
* codec that accepts `string | number` but always returns `number`).
|
|
358
|
+
*/
|
|
359
|
+
readonly inputTypeRenderer?: TypeRenderer;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Optional import spec for types used by this codec's renderers.
|
|
363
|
+
* The emitter will add this import to contract.d.ts.
|
|
364
|
+
*/
|
|
365
|
+
readonly typesImport?: TypesImportSpec;
|
|
366
|
+
}
|