@prisma-next/sql-relational-core 0.0.1 → 0.1.0-pr.32.2
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/README.md +6 -1
- package/dist/{chunk-FMVAOBWJ.js → chunk-FWAA4JVC.js} +7 -4
- package/dist/chunk-FWAA4JVC.js.map +1 -0
- package/dist/{chunk-ENOLRQZS.js → chunk-G6INLDKB.js} +2 -2
- package/dist/chunk-KYSP7L5C.js +16 -0
- package/dist/chunk-KYSP7L5C.js.map +1 -0
- package/dist/{chunk-ILC64YWE.js → chunk-PKJGE34J.js} +1 -1
- package/dist/chunk-PKJGE34J.js.map +1 -0
- package/dist/{chunk-7FMQVMSM.js → chunk-SJT6UU52.js} +2 -2
- package/dist/exports/ast.d.ts +2 -2
- package/dist/exports/ast.js +2 -2
- package/dist/exports/operations-registry.d.ts +1 -1
- package/dist/exports/operations-registry.js +1 -1
- package/dist/exports/param.d.ts +1 -1
- package/dist/exports/plan.d.ts +2 -1
- package/dist/exports/plan.js +6 -1
- package/dist/exports/schema.d.ts +1 -1
- package/dist/exports/schema.js +2 -2
- package/dist/exports/types.d.ts +25 -10
- package/dist/exports/types.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -5
- package/dist/{plan-D6dOf1wQ.d.ts → plan-CBlAzo8T.d.ts} +8 -2
- package/package.json +7 -7
- package/dist/chunk-FMVAOBWJ.js.map +0 -1
- package/dist/chunk-ILC64YWE.js.map +0 -1
- package/dist/chunk-UVFWELV2.js +0 -1
- package/dist/chunk-UVFWELV2.js.map +0 -1
- /package/dist/{chunk-ENOLRQZS.js.map → chunk-G6INLDKB.js.map} +0 -0
- /package/dist/{chunk-7FMQVMSM.js.map → chunk-SJT6UU52.js.map} +0 -0
package/README.md
CHANGED
|
@@ -82,6 +82,10 @@ flowchart TD
|
|
|
82
82
|
- Dynamically exposes operations based on column `typeId` and contract capabilities
|
|
83
83
|
- Handles operation chaining when operations return typeIds
|
|
84
84
|
|
|
85
|
+
### Plan Helpers (`plan.ts`)
|
|
86
|
+
- Defines `SqlQueryPlan<Row>` interface for SQL query plans produced by lanes before lowering
|
|
87
|
+
- Provides `augmentDescriptorWithColumnMeta(descriptors, columnMeta)` helper to update ParamDescriptor with `codecId` and `nativeType` from column metadata
|
|
88
|
+
|
|
85
89
|
### Type Definitions (`types.ts`)
|
|
86
90
|
- Defines TypeScript types for column builders, operations, projections
|
|
87
91
|
- Provides type inference utilities for extracting JavaScript types from codec types (e.g., `ExtractJsTypeFromColumnBuilder`)
|
|
@@ -107,10 +111,11 @@ This package follows the standard `exports/` directory pattern:
|
|
|
107
111
|
- `src/exports/param.ts` - Re-exports parameter helpers
|
|
108
112
|
- `src/exports/types.ts` - Re-exports type definitions
|
|
109
113
|
- `src/exports/operations-registry.ts` - Re-exports operations registry
|
|
114
|
+
- `src/exports/plan.ts` - Re-exports plan types and helpers
|
|
110
115
|
- `src/exports/errors.ts` - Re-exports error helpers (from `@prisma-next/plan`)
|
|
111
116
|
- `src/index.ts` - Main entry point that re-exports from `exports/`
|
|
112
117
|
|
|
113
|
-
This enables subpath imports like `@prisma-next/sql-relational-core/schema`, `@prisma-next/sql-relational-core/param`, etc.
|
|
118
|
+
This enables subpath imports like `@prisma-next/sql-relational-core/schema`, `@prisma-next/sql-relational-core/param`, `@prisma-next/sql-relational-core/plan`, etc.
|
|
114
119
|
|
|
115
120
|
## Related Subsystems
|
|
116
121
|
|
|
@@ -68,7 +68,7 @@ function executeOperation(signature, selfBuilder, args, columnMeta, operationReg
|
|
|
68
68
|
const returnTypeId = signature.returns.kind === "typeId" ? signature.returns.type : void 0;
|
|
69
69
|
const returnColumnMeta = returnTypeId ? {
|
|
70
70
|
...columnMeta,
|
|
71
|
-
|
|
71
|
+
codecId: returnTypeId
|
|
72
72
|
} : columnMeta;
|
|
73
73
|
const baseResult = {
|
|
74
74
|
kind: "column",
|
|
@@ -116,8 +116,11 @@ function attachOperationsToColumnBuilder(columnBuilder, columnMeta, registry, co
|
|
|
116
116
|
if (!registry) {
|
|
117
117
|
return columnBuilder;
|
|
118
118
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
119
|
+
const codecId = columnMeta.codecId;
|
|
120
|
+
if (!codecId) {
|
|
121
|
+
return columnBuilder;
|
|
122
|
+
}
|
|
123
|
+
const operations = registry.byType(codecId);
|
|
121
124
|
if (operations.length === 0) {
|
|
122
125
|
return columnBuilder;
|
|
123
126
|
}
|
|
@@ -148,4 +151,4 @@ function attachOperationsToColumnBuilder(columnBuilder, columnMeta, registry, co
|
|
|
148
151
|
export {
|
|
149
152
|
attachOperationsToColumnBuilder
|
|
150
153
|
};
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
154
|
+
//# sourceMappingURL=chunk-FWAA4JVC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/operations-registry.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport { hasAllCapabilities } from '@prisma-next/operations';\nimport { planInvalid } from '@prisma-next/plan';\nimport type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { ColumnRef, LiteralExpr, OperationExpr, ParamRef } from './ast/types';\nimport type { AnyColumnBuilder, ColumnBuilder, OperationTypes, ParamPlaceholder } from './types';\n\nfunction isParamPlaceholder(value: unknown): value is ParamPlaceholder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'param-placeholder' &&\n 'name' in value &&\n typeof (value as { name: unknown }).name === 'string'\n );\n}\n\nfunction isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\n/**\n * Executes an operation and returns a column-shaped result object.\n * This is the canonical entrypoint for operation invocation, enabling\n * future enhancements like telemetry, caching, or tracing.\n *\n * @param signature - The operation signature from the registry\n * @param selfBuilder - The column builder that the operation is called on\n * @param args - The arguments passed to the operation\n * @param columnMeta - The metadata of the column the operation is called on\n * @returns A column-shaped builder with the operation expression attached\n */\nfunction executeOperation(\n signature: SqlOperationSignature,\n selfBuilder: AnyColumnBuilder,\n args: unknown[],\n columnMeta: StorageColumn,\n operationRegistry?: OperationRegistry,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): AnyColumnBuilder & { _operationExpr?: OperationExpr } {\n if (args.length !== signature.args.length) {\n throw planInvalid(\n `Operation ${signature.method} expects ${signature.args.length} arguments, got ${args.length}`,\n );\n }\n\n // Check if this column builder has an existing operation expression\n const selfBuilderWithExpr = selfBuilder as unknown as {\n _operationExpr?: OperationExpr;\n table: string;\n column: string;\n };\n const selfExpr: ColumnRef | OperationExpr = selfBuilderWithExpr._operationExpr\n ? selfBuilderWithExpr._operationExpr\n : {\n kind: 'col',\n table: selfBuilderWithExpr.table,\n column: selfBuilderWithExpr.column,\n };\n\n const operationArgs: Array<ColumnRef | ParamRef | LiteralExpr | OperationExpr> = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const argSpec = signature.args[i];\n if (!argSpec) {\n throw planInvalid(`Missing argument spec for argument ${i}`);\n }\n\n if (argSpec.kind === 'param') {\n if (!isParamPlaceholder(arg)) {\n throw planInvalid(`Argument ${i} must be a parameter placeholder`);\n }\n operationArgs.push({\n kind: 'param',\n index: 0,\n name: arg.name,\n });\n } else if (argSpec.kind === 'typeId') {\n if (!isColumnBuilder(arg)) {\n throw planInvalid(`Argument ${i} must be a ColumnBuilder`);\n }\n const colBuilderWithExpr = arg as unknown as {\n _operationExpr?: OperationExpr;\n table: string;\n column: string;\n };\n // Check if the column builder has an operation expression\n if (colBuilderWithExpr._operationExpr) {\n operationArgs.push(colBuilderWithExpr._operationExpr);\n } else {\n // Fall back to raw ColumnRef\n operationArgs.push({\n kind: 'col',\n table: colBuilderWithExpr.table,\n column: colBuilderWithExpr.column,\n });\n }\n } else if (argSpec.kind === 'literal') {\n operationArgs.push({\n kind: 'literal',\n value: arg,\n });\n }\n }\n\n const operationExpr: OperationExpr = {\n kind: 'operation',\n method: signature.method,\n forTypeId: signature.forTypeId,\n self: selfExpr,\n args: operationArgs,\n returns: signature.returns,\n lowering: signature.lowering,\n };\n\n const returnTypeId = signature.returns.kind === 'typeId' ? signature.returns.type : undefined;\n const returnColumnMeta: StorageColumn = returnTypeId\n ? {\n ...columnMeta,\n codecId: returnTypeId,\n }\n : columnMeta;\n\n const baseResult = {\n kind: 'column' as const,\n table: selfBuilderWithExpr.table,\n column: selfBuilderWithExpr.column,\n get columnMeta() {\n return returnColumnMeta;\n },\n eq(value: ParamPlaceholder) {\n return Object.freeze({\n kind: 'binary' as const,\n op: 'eq' as const,\n left: operationExpr,\n right: value,\n });\n },\n asc() {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'asc' as const,\n });\n },\n desc() {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'desc' as const,\n });\n },\n _operationExpr: operationExpr,\n } as unknown as AnyColumnBuilder & {\n _operationExpr?: OperationExpr;\n };\n\n // If the return type is a typeId, attach operations for that type\n if (returnTypeId && operationRegistry) {\n const resultWithOps = attachOperationsToColumnBuilder(\n baseResult as ColumnBuilder<string, StorageColumn, unknown, Record<string, never>>,\n returnColumnMeta,\n operationRegistry,\n contractCapabilities,\n ) as AnyColumnBuilder & {\n _operationExpr?: OperationExpr;\n };\n return Object.freeze(resultWithOps);\n }\n\n return Object.freeze(baseResult);\n}\n\nexport function attachOperationsToColumnBuilder<\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n>(\n columnBuilder: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n columnMeta: ColumnMeta,\n registry: OperationRegistry | undefined,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations> {\n if (!registry) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n // Use codecId to look up operations registered for this column's type\n const codecId = columnMeta.codecId;\n if (!codecId) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const operations = registry.byType(codecId) as SqlOperationSignature[];\n if (operations.length === 0) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const builderWithOps = columnBuilder as unknown as ColumnBuilder<\n ColumnName,\n ColumnMeta,\n JsType,\n Operations\n >;\n\n for (const operation of operations) {\n if (operation.capabilities && operation.capabilities.length > 0) {\n if (!contractCapabilities) {\n continue;\n }\n\n if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {\n continue;\n }\n }\n // Method sugar: attach operation as a method on the column builder\n (builderWithOps as Record<string, unknown>)[operation.method] = function (\n this: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n ...args: unknown[]\n ) {\n return executeOperation(\n operation,\n this as unknown as ColumnBuilder<string, StorageColumn, unknown>,\n args,\n columnMeta,\n registry,\n contractCapabilities,\n );\n };\n }\n\n return builderWithOps;\n}\n"],"mappings":";AACA,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAM5B,SAAS,mBAAmB,OAA2C;AACrE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS,uBACtC,UAAU,SACV,OAAQ,MAA4B,SAAS;AAEjD;AAEA,SAAS,gBAAgB,OAA2C;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;AAaA,SAAS,iBACP,WACA,aACA,MACA,YACA,mBACA,sBACuD;AACvD,MAAI,KAAK,WAAW,UAAU,KAAK,QAAQ;AACzC,UAAM;AAAA,MACJ,aAAa,UAAU,MAAM,YAAY,UAAU,KAAK,MAAM,mBAAmB,KAAK,MAAM;AAAA,IAC9F;AAAA,EACF;AAGA,QAAM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G;AAC/D,UAAI,CAAC,sBAAsB;AACzB;AAAA,MACF;AAEA,UAAI,CAAC,mBAAmB,UAAU,cAAc,oBAAoB,GAAG;AACrE;AAAA,MACF;AAAA,IACF;AAEA,IAAC,eAA2C,UAAU,MAAM,IAAI,YAE3D,MACH;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isColumnBuilder
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PKJGE34J.js";
|
|
4
4
|
|
|
5
5
|
// src/ast/codec-types.ts
|
|
6
6
|
var CodecRegistryImpl = class {
|
|
@@ -317,4 +317,4 @@ export {
|
|
|
317
317
|
isOperationExpr,
|
|
318
318
|
createUpdateAst
|
|
319
319
|
};
|
|
320
|
-
//# sourceMappingURL=chunk-
|
|
320
|
+
//# sourceMappingURL=chunk-G6INLDKB.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/plan.ts
|
|
2
|
+
function augmentDescriptorWithColumnMeta(descriptors, columnMeta) {
|
|
3
|
+
const descriptor = descriptors[descriptors.length - 1];
|
|
4
|
+
if (descriptor && columnMeta) {
|
|
5
|
+
descriptors[descriptors.length - 1] = {
|
|
6
|
+
...descriptor,
|
|
7
|
+
codecId: columnMeta.codecId,
|
|
8
|
+
nativeType: columnMeta.nativeType
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
augmentDescriptorWithColumnMeta
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-KYSP7L5C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plan.ts"],"sourcesContent":["import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';\nimport type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { QueryAst } from './ast/types';\n\n/**\n * SQL query plan produced by lanes before lowering.\n *\n * Lanes build ASTs and metadata but do not perform SQL lowering.\n * The `sql` field is absent - lowering happens in the runtime executor.\n *\n * Structurally aligns with ExecutionPlan<Row, QueryAst> (without sql field) to maintain\n * compatibility with ExecutionPlan/Plan-based utilities.\n * The generic parameter `_Row` is preserved for type extraction via ResultType.\n */\nexport interface SqlQueryPlan<_Row = unknown>\n extends Pick<ExecutionPlan<_Row, QueryAst>, 'params' | 'meta'> {\n readonly ast: QueryAst;\n // Phantom property to preserve generic parameter for type extraction\n // This allows ResultType to extract _Row for SqlQueryPlan values.\n readonly _Row?: _Row;\n}\n\n/**\n * Augments the last ParamDescriptor in the array with codecId and nativeType from columnMeta.\n * This is used when building WHERE expressions to ensure param descriptors have type information.\n */\nexport function augmentDescriptorWithColumnMeta(\n descriptors: ParamDescriptor[],\n columnMeta: StorageColumn | undefined,\n): void {\n const descriptor = descriptors[descriptors.length - 1];\n if (descriptor && columnMeta) {\n descriptors[descriptors.length - 1] = {\n ...descriptor,\n codecId: columnMeta.codecId,\n nativeType: columnMeta.nativeType,\n };\n }\n}\n"],"mappings":";AA0BO,SAAS,gCACd,aACA,YACM;AACN,QAAM,aAAa,YAAY,YAAY,SAAS,CAAC;AACrD,MAAI,cAAc,YAAY;AAC5B,gBAAY,YAAY,SAAS,CAAC,IAAI;AAAA,MACpC,GAAG;AAAA,MACH,SAAS,WAAW;AAAA,MACpB,YAAY,WAAW;AAAA,IACzB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n ResultType as CoreResultType,\n ExecutionPlan,\n PlanRefs,\n} from '@prisma-next/contract/types';\nimport type { ArgSpec, ReturnSpec } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlLoweringSpec } from '@prisma-next/sql-operations';\nimport type { ColumnRef, Direction, OperationExpr, ParamRef, QueryAst } from './ast/types';\nimport type { SqlQueryPlan } from './plan';\nimport type { QueryLaneContext } from './query-lane-context';\n\nexport interface ParamPlaceholder {\n readonly kind: 'param-placeholder';\n readonly name: string;\n}\n\nexport interface OrderBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n> {\n readonly kind: 'order';\n readonly expr: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;\n readonly dir: Direction;\n}\n\n/**\n * ColumnBuilder with optional operation methods based on the column's typeId.\n * When Operations is provided and the column's typeId matches, operation methods are included.\n */\nexport type ColumnBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n> = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: ColumnName;\n readonly columnMeta: ColumnMeta;\n eq(value: ParamPlaceholder): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n} & (ColumnMeta['codecId'] extends string\n ? ColumnMeta['codecId'] extends keyof Operations\n ? OperationMethods<\n OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>,\n ColumnName,\n StorageColumn,\n JsType\n >\n : Record<string, never>\n : Record<string, never>);\n\nexport interface BinaryBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n> {\n readonly kind: 'binary';\n readonly op: 'eq';\n readonly left: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;\n readonly right: ParamPlaceholder;\n}\n\n// Helper aliases for usage sites where the specific column parameters are irrelevant\n// Accepts any ColumnBuilder regardless of its Operations parameter\n// Note: We use `any` here because TypeScript's variance rules don't allow us to express\n// \"any type that extends OperationTypes\" in a way that works for assignment.\n// Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable\n// to the base OperationTypes in generic parameter position, even though they extend it structurally.\n// Helper type that accepts any ColumnBuilder regardless of its generic parameters\n// This is needed because conditional types in ColumnBuilder create incompatible intersection types\n// when Operations differs, even though structurally they're compatible\ntype AnyColumnBuilderBase = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: string;\n readonly columnMeta: StorageColumn;\n eq(value: ParamPlaceholder): AnyBinaryBuilder;\n asc(): AnyOrderBuilder;\n desc(): AnyOrderBuilder;\n readonly __jsType: unknown;\n // Allow any operation methods (from conditional type)\n readonly [key: string]: unknown;\n};\n\nexport type AnyColumnBuilder =\n | ColumnBuilder<\n string,\n StorageColumn,\n unknown,\n // biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types\n any\n >\n | AnyColumnBuilderBase;\nexport type AnyBinaryBuilder = BinaryBuilder<string, StorageColumn, unknown>;\nexport type AnyOrderBuilder = OrderBuilder<string, StorageColumn, unknown>;\n\nexport function isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\nexport interface JoinOnBuilder {\n eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;\n}\n\nexport interface JoinOnPredicate {\n readonly kind: 'join-on';\n readonly left: AnyColumnBuilder;\n readonly right: AnyColumnBuilder;\n}\n\nexport type Expr = ColumnRef | ParamRef;\n\n/**\n * Helper type to extract codec output type from CodecTypes.\n * Returns never if the codecId is not found in CodecTypes.\n */\ntype ExtractCodecOutputType<\n CodecId extends string,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer Output }\n ? Output\n : never\n : never;\n\n/**\n * Type-level operation signature.\n * Represents an operation at the type level, similar to OperationSignature at runtime.\n */\nexport type OperationTypeSignature = {\n readonly args: ReadonlyArray<ArgSpec>;\n readonly returns: ReturnSpec;\n readonly lowering: SqlLoweringSpec;\n readonly capabilities?: ReadonlyArray<string>;\n};\n\n/**\n * Type-level operation registry.\n * Maps typeId → operations, where operations is a record of method name → operation signature.\n *\n * Example:\n * ```typescript\n * type MyOperations: OperationTypes = {\n * 'pg/vector@1': {\n * cosineDistance: {\n * args: [{ kind: 'typeId'; type: 'pg/vector@1' }];\n * returns: { kind: 'builtin'; type: 'number' };\n * lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };\n * };\n * };\n * };\n * ```\n */\nexport type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;\n\n/**\n * CodecTypes represents a map of typeId to codec definitions.\n * Each codec definition must have an `output` property indicating the JavaScript type.\n *\n * Example:\n * ```typescript\n * type MyCodecTypes: CodecTypes = {\n * 'pg/int4@1': { output: number };\n * 'pg/text@1': { output: string };\n * };\n * ```\n */\nexport type CodecTypes = Record<string, { readonly output: unknown }>;\n\n/**\n * Extracts operations for a given typeId from the operation registry.\n * Returns an empty record if the typeId is not found.\n *\n * @example\n * ```typescript\n * type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;\n * // Ops = { cosineDistance: { ... }, l2Distance: { ... } }\n * ```\n */\nexport type OperationsForTypeId<\n TypeId extends string,\n Operations extends OperationTypes,\n> = Operations extends Record<string, never>\n ? Record<string, never>\n : TypeId extends keyof Operations\n ? Operations[TypeId]\n : Record<string, never>;\n\n/**\n * Maps operation signatures to method signatures on ColumnBuilder.\n * Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder\n * based on the return type.\n */\ntype OperationMethods<\n Ops extends Record<string, OperationTypeSignature>,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType,\n> = {\n [K in keyof Ops]: Ops[K] extends OperationTypeSignature\n ? (\n ...args: OperationArgs<Ops[K]['args']>\n ) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>\n : never;\n};\n\n/**\n * Maps operation argument specs to TypeScript argument types.\n * - typeId args: ColumnBuilder (accepts base columns or operation results)\n * - param args: ParamPlaceholder\n * - literal args: unknown (could be more specific in future)\n */\ntype OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [\n infer First,\n ...infer Rest,\n]\n ? First extends ArgSpec\n ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]\n : []\n : [];\n\ntype ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }\n ? AnyColumnBuilder\n : Arg extends { kind: 'param' }\n ? ParamPlaceholder\n : Arg extends { kind: 'literal' }\n ? unknown\n : never;\n\n/**\n * Maps operation return spec to return type.\n * - builtin types: ColumnBuilder with appropriate JsType (matches runtime behavior)\n * - typeId types: ColumnBuilder (for now, could be more specific in future)\n */\ntype OperationReturn<\n Returns extends ReturnSpec,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n _JsType,\n> = Returns extends { kind: 'builtin'; type: infer T }\n ? T extends 'number'\n ? ColumnBuilder<ColumnName, ColumnMeta, number>\n : T extends 'boolean'\n ? ColumnBuilder<ColumnName, ColumnMeta, boolean>\n : T extends 'string'\n ? ColumnBuilder<ColumnName, ColumnMeta, string>\n : ColumnBuilder<ColumnName, ColumnMeta, unknown>\n : Returns extends { kind: 'typeId' }\n ? AnyColumnBuilder\n : ColumnBuilder<ColumnName, ColumnMeta, unknown>;\n\n/**\n * Computes JavaScript type for a column at column creation time.\n *\n * Type inference:\n * - Read columnMeta.codecId as typeId string literal\n * - Look up CodecTypes[typeId].output\n * - Apply nullability: nullable ? Output | null : Output\n */\ntype ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends { codecId: infer CodecId extends string }\n ? CodecId\n : ColumnMeta extends { type: infer TypeId extends string }\n ? TypeId\n : never;\n\nexport type ComputeColumnJsType<\n _Contract extends SqlContract<SqlStorage>,\n _TableName extends string,\n _ColumnName extends string,\n ColumnMeta extends StorageColumn,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = ColumnMeta extends { nullable: infer Nullable }\n ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId\n ? TypeId extends string\n ? ExtractCodecOutputType<TypeId, CodecTypes> extends infer CodecOutput\n ? [CodecOutput] extends [never]\n ? unknown // Codec not found in CodecTypes\n : Nullable extends true\n ? CodecOutput | null\n : CodecOutput\n : unknown\n : unknown\n : unknown\n : unknown;\n\n/**\n * Infers Row type from a projection object.\n * Maps Record<string, ColumnBuilder> to Record<string, JSType>\n *\n * Extracts the pre-computed JsType from each ColumnBuilder in the projection.\n */\n/**\n * Extracts the inferred JsType carried by a ColumnBuilder.\n */\ntype ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> = CB extends ColumnBuilder<\n infer _ColumnName extends string,\n infer _ColumnMeta extends StorageColumn,\n infer JsType,\n infer _Ops\n>\n ? JsType\n : never;\n\nexport type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {\n [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;\n};\n\n/**\n * Nested projection type - allows recursive nesting of ColumnBuilder or nested objects.\n */\nexport type NestedProjection = Record<\n string,\n | AnyColumnBuilder\n | Record<\n string,\n | AnyColumnBuilder\n | Record<\n string,\n AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder>>\n >\n >\n>;\n\n/**\n * Helper type to extract include type from Includes map.\n * Returns the value type if K is a key of Includes, otherwise returns unknown.\n */\ntype ExtractIncludeType<\n K extends string,\n Includes extends Record<string, unknown>,\n> = K extends keyof Includes ? Includes[K] : unknown;\n\n/**\n * Infers Row type from a nested projection object.\n * Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.\n *\n * Extracts the pre-computed JsType from each ColumnBuilder at leaves.\n * When a value is `true`, it represents an include reference and infers `Array<ChildShape>`\n * by looking up the include alias in the Includes type map.\n */\nexport type InferNestedProjectionRow<\n P extends Record<string, AnyColumnBuilder | boolean | NestedProjection>,\n CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,\n Includes extends Record<string, unknown> = Record<string, never>,\n> = {\n [K in keyof P]: P[K] extends AnyColumnBuilder\n ? ExtractJsTypeFromColumnBuilder<P[K]>\n : P[K] extends true\n ? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map\n : P[K] extends NestedProjection\n ? InferNestedProjectionRow<P[K], CodecTypes, Includes>\n : never;\n};\n\n/**\n * Infers Row type from a tuple of ColumnBuilders used in returning() clause.\n * Extracts column name and JsType from each ColumnBuilder and creates a Record.\n */\nexport type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =\n Columns extends readonly [infer First, ...infer Rest]\n ? First extends ColumnBuilder<\n infer Name,\n infer _Meta,\n infer JsType,\n infer _Ops extends OperationTypes\n >\n ? Name extends string\n ? Rest extends readonly AnyColumnBuilder[]\n ? { [K in Name]: JsType } & InferReturningRow<Rest>\n : { [K in Name]: JsType }\n : never\n : never\n : Record<string, never>;\n\n/**\n * Utility type to check if a contract has the required capabilities for includeMany.\n * Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.\n * Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`\n */\nexport type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> =\n TContract extends { capabilities: infer C; target: infer T }\n ? T extends string\n ? C extends Record<string, Record<string, boolean>>\n ? C extends { [K in T]: infer TargetCaps }\n ? TargetCaps extends { lateral: true; jsonAgg: true }\n ? true\n : false\n : false\n : false\n : false\n : false;\n\n/**\n * SQL-specific Plan type that refines the ast field to use QueryAst.\n * This is the type used by SQL query builders.\n */\nexport type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;\n\n/**\n * Helper types for extracting contract structure.\n */\nexport type TablesOf<TContract> = TContract extends {\n storage: { tables: infer U };\n}\n ? U\n : never;\n\nexport type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;\n\n// Common types for contract.d.ts generation (SQL-specific)\n// These types are used by emitted contract.d.ts files to provide type-safe DSL/ORM types\n\n/**\n * Unique symbol for metadata property to avoid collisions with user-defined properties\n */\nexport declare const META: unique symbol;\n\n/**\n * Extracts metadata from a type that has a META property\n */\nexport type Meta<T extends { [META]: unknown }> = T[typeof META];\n\n/**\n * Metadata interface for table definitions\n */\nexport interface TableMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Metadata interface for model definitions\n */\nexport interface ModelMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Base interface for table definitions with metadata\n * Used in contract.d.ts to define storage-level table types\n */\nexport interface TableDef<Name extends string> {\n readonly [META]: TableMetadata<Name>;\n}\n\n/**\n * Base interface for model definitions with metadata\n * Used in contract.d.ts to define application-level model types\n */\nexport interface ModelDef<Name extends string> {\n readonly [META]: ModelMetadata<Name>;\n}\n\nexport type ColumnsOf<\n TContract,\n K extends TableKey<TContract>,\n> = K extends keyof TablesOf<TContract>\n ? TablesOf<TContract>[K] extends { columns: infer C }\n ? C\n : never\n : never;\n\nexport interface RawTemplateOptions {\n readonly refs?: PlanRefs;\n readonly annotations?: Record<string, unknown>;\n readonly projection?: ReadonlyArray<string>;\n}\n\nexport interface RawFunctionOptions extends RawTemplateOptions {\n readonly params: ReadonlyArray<unknown>;\n}\n\nexport type RawTemplateFactory = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n) => ExecutionPlan;\n\nexport interface RawFactory extends RawTemplateFactory {\n (text: string, options: RawFunctionOptions): ExecutionPlan;\n with(options: RawTemplateOptions): RawTemplateFactory;\n}\n\nexport type { RuntimeError } from '@prisma-next/plan';\n\nexport interface BuildParamsMap {\n readonly [name: string]: unknown;\n}\n\nexport interface BuildOptions {\n readonly params?: BuildParamsMap;\n}\n\nexport interface SqlBuilderOptions<\n TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,\n> {\n readonly context: QueryLaneContext<TContract>;\n}\n\n/**\n * SQL-specific ResultType that works with both Plan and SqlQueryPlan.\n * This extends the core ResultType to also handle SqlQueryPlan.\n * Example: `type Row = ResultType<typeof plan>`\n */\nexport type ResultType<P> = P extends SqlQueryPlan<infer R> ? R : CoreResultType<P>;\n"],"mappings":";AAsGO,SAAS,gBAAgB,OAA2C;AACzE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
attachOperationsToColumnBuilder
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FWAA4JVC.js";
|
|
4
4
|
|
|
5
5
|
// src/schema.ts
|
|
6
6
|
import { planInvalid } from "@prisma-next/plan";
|
|
@@ -125,4 +125,4 @@ export {
|
|
|
125
125
|
TableBuilderImpl,
|
|
126
126
|
schema
|
|
127
127
|
};
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-SJT6UU52.js.map
|
package/dist/exports/ast.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { b as CodecRegistry } from '../query-lane-context-BhOMmb_K.js';
|
|
2
2
|
export { a as Codec, h as CodecDefBuilder, d as CodecId, e as CodecInput, C as CodecMeta, f as CodecOutput, E as ExtractCodecTypes, g as ExtractDataTypes, c as codec, i as createCodecRegistry, j as defineCodecs } from '../query-lane-context-BhOMmb_K.js';
|
|
3
|
-
import { T as TableRef, C as ColumnRef, P as ParamRef, O as OperationExpr, L as LiteralExpr, B as BinaryExpr, d as DeleteAst, c as InsertAst, J as JoinOnExpr, a as JoinAst, D as Direction, S as SelectAst, E as ExistsExpr, b as IncludeAst, I as IncludeRef, U as UpdateAst } from '../plan-
|
|
4
|
-
export { e as LoweredStatement, Q as QueryAst, i as isOperationExpr } from '../plan-
|
|
3
|
+
import { T as TableRef, C as ColumnRef, P as ParamRef, O as OperationExpr, L as LiteralExpr, B as BinaryExpr, d as DeleteAst, c as InsertAst, J as JoinOnExpr, a as JoinAst, D as Direction, S as SelectAst, E as ExistsExpr, b as IncludeAst, I as IncludeRef, U as UpdateAst } from '../plan-CBlAzo8T.js';
|
|
4
|
+
export { e as LoweredStatement, Q as QueryAst, i as isOperationExpr } from '../plan-CBlAzo8T.js';
|
|
5
5
|
import { JoinOnBuilder } from './types.js';
|
|
6
6
|
import '@prisma-next/operations';
|
|
7
7
|
import '@prisma-next/sql-contract/types';
|
package/dist/exports/ast.js
CHANGED
|
@@ -3,7 +3,7 @@ import { StorageColumn } from '@prisma-next/sql-contract/types';
|
|
|
3
3
|
import { OperationTypes, ColumnBuilder } from './types.js';
|
|
4
4
|
import '@prisma-next/contract/types';
|
|
5
5
|
import '@prisma-next/sql-operations';
|
|
6
|
-
import '../plan-
|
|
6
|
+
import '../plan-CBlAzo8T.js';
|
|
7
7
|
import '../query-lane-context-BhOMmb_K.js';
|
|
8
8
|
import 'ts-toolbelt';
|
|
9
9
|
import '@prisma-next/plan';
|
package/dist/exports/param.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import '@prisma-next/contract/types';
|
|
|
3
3
|
import '@prisma-next/operations';
|
|
4
4
|
import '@prisma-next/sql-contract/types';
|
|
5
5
|
import '@prisma-next/sql-operations';
|
|
6
|
-
import '../plan-
|
|
6
|
+
import '../plan-CBlAzo8T.js';
|
|
7
7
|
import '../query-lane-context-BhOMmb_K.js';
|
|
8
8
|
import 'ts-toolbelt';
|
|
9
9
|
import '@prisma-next/plan';
|
package/dist/exports/plan.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { f as SqlQueryPlan } from '../plan-
|
|
1
|
+
export { f as SqlQueryPlan, g as augmentDescriptorWithColumnMeta } from '../plan-CBlAzo8T.js';
|
|
2
2
|
import '@prisma-next/contract/types';
|
|
3
|
+
import '@prisma-next/sql-contract/types';
|
|
3
4
|
import '@prisma-next/operations';
|
|
4
5
|
import '@prisma-next/sql-operations';
|
package/dist/exports/plan.js
CHANGED
package/dist/exports/schema.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StorageColumn, SqlContract, SqlStorage, ExtractCodecTypes, ExtractOperationTypes } from '@prisma-next/sql-contract/types';
|
|
2
|
-
import { T as TableRef } from '../plan-
|
|
2
|
+
import { T as TableRef } from '../plan-CBlAzo8T.js';
|
|
3
3
|
import { Q as QueryLaneContext } from '../query-lane-context-BhOMmb_K.js';
|
|
4
4
|
import { ParamPlaceholder, BinaryBuilder, OrderBuilder, CodecTypes, OperationTypes, ColumnBuilder, ComputeColumnJsType, OperationTypeSignature } from './types.js';
|
|
5
5
|
import '@prisma-next/contract/types';
|
package/dist/exports/schema.js
CHANGED
package/dist/exports/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ExecutionPlan, PlanRefs, ResultType as ResultType$1 } from '@prisma-nex
|
|
|
2
2
|
import { ArgSpec, ReturnSpec } from '@prisma-next/operations';
|
|
3
3
|
import { StorageColumn, SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
4
4
|
import { SqlLoweringSpec } from '@prisma-next/sql-operations';
|
|
5
|
-
import { O as OperationExpr, D as Direction, C as ColumnRef, P as ParamRef, Q as QueryAst, f as SqlQueryPlan } from '../plan-
|
|
5
|
+
import { O as OperationExpr, D as Direction, C as ColumnRef, P as ParamRef, Q as QueryAst, f as SqlQueryPlan } from '../plan-CBlAzo8T.js';
|
|
6
6
|
import { Q as QueryLaneContext } from '../query-lane-context-BhOMmb_K.js';
|
|
7
7
|
export { RuntimeError } from '@prisma-next/plan';
|
|
8
8
|
import 'ts-toolbelt';
|
|
@@ -29,14 +29,25 @@ type ColumnBuilder<ColumnName extends string = string, ColumnMeta extends Storag
|
|
|
29
29
|
asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
30
30
|
desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;
|
|
31
31
|
readonly __jsType: JsType;
|
|
32
|
-
} & (ColumnMeta['
|
|
32
|
+
} & (ColumnMeta['codecId'] extends string ? ColumnMeta['codecId'] extends keyof Operations ? OperationMethods<OperationsForTypeId<ColumnMeta['codecId'] & string, Operations>, ColumnName, StorageColumn, JsType> : Record<string, never> : Record<string, never>);
|
|
33
33
|
interface BinaryBuilder<ColumnName extends string = string, ColumnMeta extends StorageColumn = StorageColumn, JsType = unknown> {
|
|
34
34
|
readonly kind: 'binary';
|
|
35
35
|
readonly op: 'eq';
|
|
36
36
|
readonly left: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;
|
|
37
37
|
readonly right: ParamPlaceholder;
|
|
38
38
|
}
|
|
39
|
-
type
|
|
39
|
+
type AnyColumnBuilderBase = {
|
|
40
|
+
readonly kind: 'column';
|
|
41
|
+
readonly table: string;
|
|
42
|
+
readonly column: string;
|
|
43
|
+
readonly columnMeta: StorageColumn;
|
|
44
|
+
eq(value: ParamPlaceholder): AnyBinaryBuilder;
|
|
45
|
+
asc(): AnyOrderBuilder;
|
|
46
|
+
desc(): AnyOrderBuilder;
|
|
47
|
+
readonly __jsType: unknown;
|
|
48
|
+
readonly [key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
type AnyColumnBuilder = ColumnBuilder<string, StorageColumn, unknown, any> | AnyColumnBuilderBase;
|
|
40
51
|
type AnyBinaryBuilder = BinaryBuilder<string, StorageColumn, unknown>;
|
|
41
52
|
type AnyOrderBuilder = OrderBuilder<string, StorageColumn, unknown>;
|
|
42
53
|
declare function isColumnBuilder(value: unknown): value is AnyColumnBuilder;
|
|
@@ -75,9 +86,9 @@ type OperationTypeSignature = {
|
|
|
75
86
|
* Example:
|
|
76
87
|
* ```typescript
|
|
77
88
|
* type MyOperations: OperationTypes = {
|
|
78
|
-
* '
|
|
89
|
+
* 'pg/vector@1': {
|
|
79
90
|
* cosineDistance: {
|
|
80
|
-
* args: [{ kind: 'typeId'; type: '
|
|
91
|
+
* args: [{ kind: 'typeId'; type: 'pg/vector@1' }];
|
|
81
92
|
* returns: { kind: 'builtin'; type: 'number' };
|
|
82
93
|
* lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };
|
|
83
94
|
* };
|
|
@@ -107,7 +118,7 @@ type CodecTypes = Record<string, {
|
|
|
107
118
|
*
|
|
108
119
|
* @example
|
|
109
120
|
* ```typescript
|
|
110
|
-
* type Ops = OperationsForTypeId<'
|
|
121
|
+
* type Ops = OperationsForTypeId<'pg/vector@1', MyOperations>;
|
|
111
122
|
* // Ops = { cosineDistance: { ... }, l2Distance: { ... } }
|
|
112
123
|
* ```
|
|
113
124
|
*/
|
|
@@ -152,16 +163,20 @@ type OperationReturn<Returns extends ReturnSpec, ColumnName extends string, Colu
|
|
|
152
163
|
* Computes JavaScript type for a column at column creation time.
|
|
153
164
|
*
|
|
154
165
|
* Type inference:
|
|
155
|
-
* - Read columnMeta.
|
|
166
|
+
* - Read columnMeta.codecId as typeId string literal
|
|
156
167
|
* - Look up CodecTypes[typeId].output
|
|
157
168
|
* - Apply nullability: nullable ? Output | null : Output
|
|
158
169
|
*/
|
|
170
|
+
type ColumnMetaTypeId<ColumnMeta> = ColumnMeta extends {
|
|
171
|
+
codecId: infer CodecId extends string;
|
|
172
|
+
} ? CodecId : ColumnMeta extends {
|
|
173
|
+
type: infer TypeId extends string;
|
|
174
|
+
} ? TypeId : never;
|
|
159
175
|
type ComputeColumnJsType<_Contract extends SqlContract<SqlStorage>, _TableName extends string, _ColumnName extends string, ColumnMeta extends StorageColumn, CodecTypes extends Record<string, {
|
|
160
176
|
readonly output: unknown;
|
|
161
177
|
}>> = ColumnMeta extends {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
} ? T extends string ? ExtractCodecOutputType<T, CodecTypes> extends infer CodecOutput ? [CodecOutput] extends [never] ? unknown : N extends true ? CodecOutput | null : CodecOutput : unknown : unknown : unknown;
|
|
178
|
+
nullable: infer Nullable;
|
|
179
|
+
} ? ColumnMetaTypeId<ColumnMeta> extends infer TypeId ? TypeId extends string ? ExtractCodecOutputType<TypeId, CodecTypes> extends infer CodecOutput ? [CodecOutput] extends [never] ? unknown : Nullable extends true ? CodecOutput | null : CodecOutput : unknown : unknown : unknown : unknown;
|
|
165
180
|
/**
|
|
166
181
|
* Infers Row type from a projection object.
|
|
167
182
|
* Maps Record<string, ColumnBuilder> to Record<string, JSType>
|
package/dist/exports/types.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Adapter, AdapterProfile, AdapterTarget, CreateDeleteAstOptions, CreateInsertAstOptions, CreateSelectAstOptions, CreateUpdateAstOptions, LoweredPayload, Lowerer, LowererContext, SqlDriver, SqlExecuteRequest, SqlExplainResult, SqlQueryResult, compact, createBinaryExpr, createColumnRef, createDeleteAst, createExistsExpr, createInsertAst, createJoin, createJoinOnBuilder, createJoinOnExpr, createLiteralExpr, createOperationExpr, createOrderByItem, createParamRef, createSelectAst, createTableRef, createUpdateAst } from './exports/ast.js';
|
|
2
2
|
export { a as Codec, h as CodecDefBuilder, d as CodecId, e as CodecInput, C as CodecMeta, f as CodecOutput, b as CodecRegistry, E as ExtractCodecTypes, g as ExtractDataTypes, Q as QueryLaneContext, c as codec, i as createCodecRegistry, j as defineCodecs } from './query-lane-context-BhOMmb_K.js';
|
|
3
|
-
export { B as BinaryExpr, C as ColumnRef, d as DeleteAst, D as Direction, E as ExistsExpr, b as IncludeAst, I as IncludeRef, c as InsertAst, a as JoinAst, J as JoinOnExpr, L as LiteralExpr, e as LoweredStatement, O as OperationExpr, P as ParamRef, Q as QueryAst, S as SelectAst, f as SqlQueryPlan, T as TableRef, U as UpdateAst, i as isOperationExpr } from './plan-
|
|
3
|
+
export { B as BinaryExpr, C as ColumnRef, d as DeleteAst, D as Direction, E as ExistsExpr, b as IncludeAst, I as IncludeRef, c as InsertAst, a as JoinAst, J as JoinOnExpr, L as LiteralExpr, e as LoweredStatement, O as OperationExpr, P as ParamRef, Q as QueryAst, S as SelectAst, f as SqlQueryPlan, T as TableRef, U as UpdateAst, g as augmentDescriptorWithColumnMeta, i as isOperationExpr } from './plan-CBlAzo8T.js';
|
|
4
4
|
export { RuntimeError, planInvalid, planUnsupported } from '@prisma-next/plan';
|
|
5
5
|
export { attachOperationsToColumnBuilder } from './exports/operations-registry.js';
|
|
6
6
|
export { Parameter, param } from './exports/param.js';
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
ColumnBuilderImpl,
|
|
4
4
|
TableBuilderImpl,
|
|
5
5
|
schema
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SJT6UU52.js";
|
|
7
7
|
import {
|
|
8
8
|
param
|
|
9
9
|
} from "./chunk-7I3EMQID.js";
|
|
10
10
|
import "./chunk-G52ENULI.js";
|
|
11
11
|
import {
|
|
12
12
|
attachOperationsToColumnBuilder
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-FWAA4JVC.js";
|
|
14
14
|
import {
|
|
15
15
|
planInvalid,
|
|
16
16
|
planUnsupported
|
|
@@ -36,15 +36,18 @@ import {
|
|
|
36
36
|
createUpdateAst,
|
|
37
37
|
defineCodecs,
|
|
38
38
|
isOperationExpr
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-G6INLDKB.js";
|
|
40
40
|
import {
|
|
41
41
|
isColumnBuilder
|
|
42
|
-
} from "./chunk-
|
|
43
|
-
import
|
|
42
|
+
} from "./chunk-PKJGE34J.js";
|
|
43
|
+
import {
|
|
44
|
+
augmentDescriptorWithColumnMeta
|
|
45
|
+
} from "./chunk-KYSP7L5C.js";
|
|
44
46
|
export {
|
|
45
47
|
ColumnBuilderImpl,
|
|
46
48
|
TableBuilderImpl,
|
|
47
49
|
attachOperationsToColumnBuilder,
|
|
50
|
+
augmentDescriptorWithColumnMeta,
|
|
48
51
|
codec,
|
|
49
52
|
compact,
|
|
50
53
|
createBinaryExpr,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExecutionPlan } from '@prisma-next/contract/types';
|
|
1
|
+
import { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';
|
|
2
|
+
import { StorageColumn } from '@prisma-next/sql-contract/types';
|
|
2
3
|
import { ReturnSpec } from '@prisma-next/operations';
|
|
3
4
|
import { SqlLoweringSpec } from '@prisma-next/sql-operations';
|
|
4
5
|
|
|
@@ -131,5 +132,10 @@ interface SqlQueryPlan<_Row = unknown> extends Pick<ExecutionPlan<_Row, QueryAst
|
|
|
131
132
|
readonly ast: QueryAst;
|
|
132
133
|
readonly _Row?: _Row;
|
|
133
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Augments the last ParamDescriptor in the array with codecId and nativeType from columnMeta.
|
|
137
|
+
* This is used when building WHERE expressions to ensure param descriptors have type information.
|
|
138
|
+
*/
|
|
139
|
+
declare function augmentDescriptorWithColumnMeta(descriptors: ParamDescriptor[], columnMeta: StorageColumn | undefined): void;
|
|
134
140
|
|
|
135
|
-
export { type BinaryExpr as B, type ColumnRef as C, type Direction as D, type ExistsExpr as E, type IncludeRef as I, type JoinOnExpr as J, type LiteralExpr as L, type OperationExpr as O, type ParamRef as P, type QueryAst as Q, type SelectAst as S, type TableRef as T, type UpdateAst as U, type JoinAst as a, type IncludeAst as b, type InsertAst as c, type DeleteAst as d, type LoweredStatement as e, type SqlQueryPlan as f, isOperationExpr as i };
|
|
141
|
+
export { type BinaryExpr as B, type ColumnRef as C, type Direction as D, type ExistsExpr as E, type IncludeRef as I, type JoinOnExpr as J, type LiteralExpr as L, type OperationExpr as O, type ParamRef as P, type QueryAst as Q, type SelectAst as S, type TableRef as T, type UpdateAst as U, type JoinAst as a, type IncludeAst as b, type InsertAst as c, type DeleteAst as d, type LoweredStatement as e, type SqlQueryPlan as f, augmentDescriptorWithColumnMeta as g, isOperationExpr as i };
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-pr.32.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Schema and column builders, operation attachment, and AST types for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"ts-toolbelt": "^9.6.0",
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/sql-operations": "0.0.
|
|
13
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/operations": "0.1.0-pr.32.2",
|
|
10
|
+
"@prisma-next/contract": "0.1.0-pr.32.2",
|
|
11
|
+
"@prisma-next/sql-contract": "0.1.0-pr.32.2",
|
|
12
|
+
"@prisma-next/sql-operations": "0.1.0-pr.32.2",
|
|
13
|
+
"@prisma-next/plan": "0.1.0-pr.32.2"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"tsup": "^8.3.0",
|
|
17
17
|
"typescript": "^5.9.3",
|
|
18
18
|
"vite-tsconfig-paths": "^5.1.4",
|
|
19
19
|
"vitest": "^2.1.1",
|
|
20
|
-
"@prisma-next/sql-contract-ts": "0.0.
|
|
20
|
+
"@prisma-next/sql-contract-ts": "0.1.0-pr.32.2",
|
|
21
21
|
"@prisma-next/test-utils": "0.0.1"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/operations-registry.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport { hasAllCapabilities } from '@prisma-next/operations';\nimport { planInvalid } from '@prisma-next/plan';\nimport type { StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlOperationSignature } from '@prisma-next/sql-operations';\nimport type { ColumnRef, LiteralExpr, OperationExpr, ParamRef } from './ast/types';\nimport type { AnyColumnBuilder, ColumnBuilder, OperationTypes, ParamPlaceholder } from './types';\n\nfunction isParamPlaceholder(value: unknown): value is ParamPlaceholder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'param-placeholder' &&\n 'name' in value &&\n typeof (value as { name: unknown }).name === 'string'\n );\n}\n\nfunction isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\n/**\n * Executes an operation and returns a column-shaped result object.\n * This is the canonical entrypoint for operation invocation, enabling\n * future enhancements like telemetry, caching, or tracing.\n *\n * @param signature - The operation signature from the registry\n * @param selfBuilder - The column builder that the operation is called on\n * @param args - The arguments passed to the operation\n * @param columnMeta - The metadata of the column the operation is called on\n * @returns A column-shaped builder with the operation expression attached\n */\nfunction executeOperation(\n signature: SqlOperationSignature,\n selfBuilder: AnyColumnBuilder,\n args: unknown[],\n columnMeta: StorageColumn,\n operationRegistry?: OperationRegistry,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): AnyColumnBuilder & { _operationExpr?: OperationExpr } {\n if (args.length !== signature.args.length) {\n throw planInvalid(\n `Operation ${signature.method} expects ${signature.args.length} arguments, got ${args.length}`,\n );\n }\n\n // Check if this column builder has an existing operation expression\n const selfBuilderWithExpr = selfBuilder as unknown as {\n _operationExpr?: OperationExpr;\n table: string;\n column: string;\n };\n const selfExpr: ColumnRef | OperationExpr = selfBuilderWithExpr._operationExpr\n ? selfBuilderWithExpr._operationExpr\n : {\n kind: 'col',\n table: selfBuilderWithExpr.table,\n column: selfBuilderWithExpr.column,\n };\n\n const operationArgs: Array<ColumnRef | ParamRef | LiteralExpr | OperationExpr> = [];\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const argSpec = signature.args[i];\n if (!argSpec) {\n throw planInvalid(`Missing argument spec for argument ${i}`);\n }\n\n if (argSpec.kind === 'param') {\n if (!isParamPlaceholder(arg)) {\n throw planInvalid(`Argument ${i} must be a parameter placeholder`);\n }\n operationArgs.push({\n kind: 'param',\n index: 0,\n name: arg.name,\n });\n } else if (argSpec.kind === 'typeId') {\n if (!isColumnBuilder(arg)) {\n throw planInvalid(`Argument ${i} must be a ColumnBuilder`);\n }\n const colBuilderWithExpr = arg as unknown as {\n _operationExpr?: OperationExpr;\n table: string;\n column: string;\n };\n // Check if the column builder has an operation expression\n if (colBuilderWithExpr._operationExpr) {\n operationArgs.push(colBuilderWithExpr._operationExpr);\n } else {\n // Fall back to raw ColumnRef\n operationArgs.push({\n kind: 'col',\n table: colBuilderWithExpr.table,\n column: colBuilderWithExpr.column,\n });\n }\n } else if (argSpec.kind === 'literal') {\n operationArgs.push({\n kind: 'literal',\n value: arg,\n });\n }\n }\n\n const operationExpr: OperationExpr = {\n kind: 'operation',\n method: signature.method,\n forTypeId: signature.forTypeId,\n self: selfExpr,\n args: operationArgs,\n returns: signature.returns,\n lowering: signature.lowering,\n };\n\n const returnTypeId = signature.returns.kind === 'typeId' ? signature.returns.type : undefined;\n const returnColumnMeta: StorageColumn = returnTypeId\n ? {\n ...columnMeta,\n type: returnTypeId,\n }\n : columnMeta;\n\n const baseResult = {\n kind: 'column' as const,\n table: selfBuilderWithExpr.table,\n column: selfBuilderWithExpr.column,\n get columnMeta() {\n return returnColumnMeta;\n },\n eq(value: ParamPlaceholder) {\n return Object.freeze({\n kind: 'binary' as const,\n op: 'eq' as const,\n left: operationExpr,\n right: value,\n });\n },\n asc() {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'asc' as const,\n });\n },\n desc() {\n return Object.freeze({\n kind: 'order' as const,\n expr: operationExpr,\n dir: 'desc' as const,\n });\n },\n _operationExpr: operationExpr,\n } as unknown as AnyColumnBuilder & {\n _operationExpr?: OperationExpr;\n };\n\n // If the return type is a typeId, attach operations for that type\n if (returnTypeId && operationRegistry) {\n const resultWithOps = attachOperationsToColumnBuilder(\n baseResult as ColumnBuilder<string, StorageColumn, unknown, Record<string, never>>,\n returnColumnMeta,\n operationRegistry,\n contractCapabilities,\n ) as AnyColumnBuilder & {\n _operationExpr?: OperationExpr;\n };\n return Object.freeze(resultWithOps);\n }\n\n return Object.freeze(baseResult);\n}\n\nexport function attachOperationsToColumnBuilder<\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n>(\n columnBuilder: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n columnMeta: ColumnMeta,\n registry: OperationRegistry | undefined,\n contractCapabilities?: Record<string, Record<string, boolean>>,\n): ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations> {\n if (!registry) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const typeId = columnMeta.type;\n\n const operations = registry.byType(typeId) as SqlOperationSignature[];\n if (operations.length === 0) {\n return columnBuilder as ColumnBuilder<ColumnName, ColumnMeta, JsType, Operations>;\n }\n\n const builderWithOps = columnBuilder as unknown as ColumnBuilder<\n ColumnName,\n ColumnMeta,\n JsType,\n Operations\n >;\n\n for (const operation of operations) {\n if (operation.capabilities && operation.capabilities.length > 0) {\n if (!contractCapabilities) {\n continue;\n }\n\n if (!hasAllCapabilities(operation.capabilities, contractCapabilities)) {\n continue;\n }\n }\n // Method sugar: attach operation as a method on the column builder\n (builderWithOps as Record<string, unknown>)[operation.method] = function (\n this: ColumnBuilder<ColumnName, ColumnMeta, JsType, Record<string, never>>,\n ...args: unknown[]\n ) {\n return executeOperation(\n operation,\n this as unknown as ColumnBuilder<string, StorageColumn, unknown>,\n args,\n columnMeta,\n registry,\n contractCapabilities,\n );\n };\n }\n\n return builderWithOps;\n}\n"],"mappings":";AACA,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;AAM5B,SAAS,mBAAmB,OAA2C;AACrE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS,uBACtC,UAAU,SACV,OAAQ,MAA4B,SAAS;AAEjD;AAEA,SAAS,gBAAgB,OAA2C;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;A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SAAS,OAAO,MAAM;AACzC,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,QAAM,iBAAiB;AAOvB,aAAW,aAAa,YAAY;AAClC,QAAI,UAAU,gBAAgB,UAAU,aAAa,SAAS,GAAG;AAC/D,UAAI,CAAC,sBAAsB;AACzB;AAAA,MACF;AAEA,UAAI,CAAC,mBAAmB,UAAU,cAAc,oBAAoB,GAAG;AACrE;AAAA,MACF;AAAA,IACF;AAEA,IAAC,eAA2C,UAAU,MAAM,IAAI,YAE3D,MACH;AACA,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n ResultType as CoreResultType,\n ExecutionPlan,\n PlanRefs,\n} from '@prisma-next/contract/types';\nimport type { ArgSpec, ReturnSpec } from '@prisma-next/operations';\nimport type { SqlContract, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';\nimport type { SqlLoweringSpec } from '@prisma-next/sql-operations';\nimport type { ColumnRef, Direction, OperationExpr, ParamRef, QueryAst } from './ast/types';\nimport type { SqlQueryPlan } from './plan';\nimport type { QueryLaneContext } from './query-lane-context';\n\nexport interface ParamPlaceholder {\n readonly kind: 'param-placeholder';\n readonly name: string;\n}\n\nexport interface OrderBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n> {\n readonly kind: 'order';\n readonly expr: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;\n readonly dir: Direction;\n}\n\n/**\n * ColumnBuilder with optional operation methods based on the column's typeId.\n * When Operations is provided and the column's typeId matches, operation methods are included.\n */\nexport type ColumnBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n Operations extends OperationTypes = Record<string, never>,\n> = {\n readonly kind: 'column';\n readonly table: string;\n readonly column: ColumnName;\n readonly columnMeta: ColumnMeta;\n eq(value: ParamPlaceholder): BinaryBuilder<ColumnName, ColumnMeta, JsType>;\n asc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n desc(): OrderBuilder<ColumnName, ColumnMeta, JsType>;\n // Helper property for type extraction (not used at runtime)\n readonly __jsType: JsType;\n} & (ColumnMeta['type'] extends keyof Operations\n ? OperationMethods<\n OperationsForTypeId<ColumnMeta['type'], Operations>,\n ColumnName,\n StorageColumn,\n JsType\n >\n : Record<string, never>);\n\nexport interface BinaryBuilder<\n ColumnName extends string = string,\n ColumnMeta extends StorageColumn = StorageColumn,\n JsType = unknown,\n> {\n readonly kind: 'binary';\n readonly op: 'eq';\n readonly left: ColumnBuilder<ColumnName, ColumnMeta, JsType> | OperationExpr;\n readonly right: ParamPlaceholder;\n}\n\n// Helper aliases for usage sites where the specific column parameters are irrelevant\n// Accepts any ColumnBuilder regardless of its Operations parameter\n// Note: We use `any` here because TypeScript's variance rules don't allow us to express\n// \"any type that extends OperationTypes\" in a way that works for assignment.\n// Contract-specific OperationTypes (e.g., PgVectorOperationTypes) are not assignable\n// to the base OperationTypes in generic parameter position, even though they extend it structurally.\n// biome-ignore lint/suspicious/noExplicitAny: AnyColumnBuilder must accept column builders with any operation types\nexport type AnyColumnBuilder = ColumnBuilder<string, StorageColumn, unknown, any>;\nexport type AnyBinaryBuilder = BinaryBuilder<string, StorageColumn, unknown>;\nexport type AnyOrderBuilder = OrderBuilder<string, StorageColumn, unknown>;\n\nexport function isColumnBuilder(value: unknown): value is AnyColumnBuilder {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'kind' in value &&\n (value as { kind: unknown }).kind === 'column'\n );\n}\n\nexport interface JoinOnBuilder {\n eqCol(left: AnyColumnBuilder, right: AnyColumnBuilder): JoinOnPredicate;\n}\n\nexport interface JoinOnPredicate {\n readonly kind: 'join-on';\n readonly left: AnyColumnBuilder;\n readonly right: AnyColumnBuilder;\n}\n\nexport type Expr = ColumnRef | ParamRef;\n\n/**\n * Helper type to extract codec output type from CodecTypes.\n * Returns never if the codecId is not found in CodecTypes.\n */\ntype ExtractCodecOutputType<\n CodecId extends string,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer Output }\n ? Output\n : never\n : never;\n\n/**\n * Type-level operation signature.\n * Represents an operation at the type level, similar to OperationSignature at runtime.\n */\nexport type OperationTypeSignature = {\n readonly args: ReadonlyArray<ArgSpec>;\n readonly returns: ReturnSpec;\n readonly lowering: SqlLoweringSpec;\n readonly capabilities?: ReadonlyArray<string>;\n};\n\n/**\n * Type-level operation registry.\n * Maps typeId → operations, where operations is a record of method name → operation signature.\n *\n * Example:\n * ```typescript\n * type MyOperations: OperationTypes = {\n * 'pgvector/vector@1': {\n * cosineDistance: {\n * args: [{ kind: 'typeId'; type: 'pgvector/vector@1' }];\n * returns: { kind: 'builtin'; type: 'number' };\n * lowering: { targetFamily: 'sql'; strategy: 'function'; template: '...' };\n * };\n * };\n * };\n * ```\n */\nexport type OperationTypes = Record<string, Record<string, OperationTypeSignature>>;\n\n/**\n * CodecTypes represents a map of typeId to codec definitions.\n * Each codec definition must have an `output` property indicating the JavaScript type.\n *\n * Example:\n * ```typescript\n * type MyCodecTypes: CodecTypes = {\n * 'pg/int4@1': { output: number };\n * 'pg/text@1': { output: string };\n * };\n * ```\n */\nexport type CodecTypes = Record<string, { readonly output: unknown }>;\n\n/**\n * Extracts operations for a given typeId from the operation registry.\n * Returns an empty record if the typeId is not found.\n *\n * @example\n * ```typescript\n * type Ops = OperationsForTypeId<'pgvector/vector@1', MyOperations>;\n * // Ops = { cosineDistance: { ... }, l2Distance: { ... } }\n * ```\n */\nexport type OperationsForTypeId<\n TypeId extends string,\n Operations extends OperationTypes,\n> = Operations extends Record<string, never>\n ? Record<string, never>\n : TypeId extends keyof Operations\n ? Operations[TypeId]\n : Record<string, never>;\n\n/**\n * Maps operation signatures to method signatures on ColumnBuilder.\n * Each operation becomes a method that returns a ColumnBuilder or BinaryBuilder\n * based on the return type.\n */\ntype OperationMethods<\n Ops extends Record<string, OperationTypeSignature>,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n JsType,\n> = {\n [K in keyof Ops]: Ops[K] extends OperationTypeSignature\n ? (\n ...args: OperationArgs<Ops[K]['args']>\n ) => OperationReturn<Ops[K]['returns'], ColumnName, ColumnMeta, JsType>\n : never;\n};\n\n/**\n * Maps operation argument specs to TypeScript argument types.\n * - typeId args: ColumnBuilder (accepts base columns or operation results)\n * - param args: ParamPlaceholder\n * - literal args: unknown (could be more specific in future)\n */\ntype OperationArgs<Args extends ReadonlyArray<ArgSpec>> = Args extends readonly [\n infer First,\n ...infer Rest,\n]\n ? First extends ArgSpec\n ? [ArgToType<First>, ...(Rest extends ReadonlyArray<ArgSpec> ? OperationArgs<Rest> : [])]\n : []\n : [];\n\ntype ArgToType<Arg extends ArgSpec> = Arg extends { kind: 'typeId' }\n ? AnyColumnBuilder\n : Arg extends { kind: 'param' }\n ? ParamPlaceholder\n : Arg extends { kind: 'literal' }\n ? unknown\n : never;\n\n/**\n * Maps operation return spec to return type.\n * - builtin types: ColumnBuilder with appropriate JsType (matches runtime behavior)\n * - typeId types: ColumnBuilder (for now, could be more specific in future)\n */\ntype OperationReturn<\n Returns extends ReturnSpec,\n ColumnName extends string,\n ColumnMeta extends StorageColumn,\n _JsType,\n> = Returns extends { kind: 'builtin'; type: infer T }\n ? T extends 'number'\n ? ColumnBuilder<ColumnName, ColumnMeta, number>\n : T extends 'boolean'\n ? ColumnBuilder<ColumnName, ColumnMeta, boolean>\n : T extends 'string'\n ? ColumnBuilder<ColumnName, ColumnMeta, string>\n : ColumnBuilder<ColumnName, ColumnMeta, unknown>\n : Returns extends { kind: 'typeId' }\n ? AnyColumnBuilder\n : ColumnBuilder<ColumnName, ColumnMeta, unknown>;\n\n/**\n * Computes JavaScript type for a column at column creation time.\n *\n * Type inference:\n * - Read columnMeta.type as typeId string literal\n * - Look up CodecTypes[typeId].output\n * - Apply nullability: nullable ? Output | null : Output\n */\nexport type ComputeColumnJsType<\n _Contract extends SqlContract<SqlStorage>,\n _TableName extends string,\n _ColumnName extends string,\n ColumnMeta extends StorageColumn,\n CodecTypes extends Record<string, { readonly output: unknown }>,\n> = ColumnMeta extends { type: infer T; nullable: infer N }\n ? T extends string\n ? ExtractCodecOutputType<T, CodecTypes> extends infer CodecOutput\n ? [CodecOutput] extends [never]\n ? unknown // Codec not found in CodecTypes\n : N extends true\n ? CodecOutput | null\n : CodecOutput\n : unknown\n : unknown\n : unknown;\n\n/**\n * Infers Row type from a projection object.\n * Maps Record<string, ColumnBuilder> to Record<string, JSType>\n *\n * Extracts the pre-computed JsType from each ColumnBuilder in the projection.\n */\n/**\n * Extracts the inferred JsType carried by a ColumnBuilder.\n */\ntype ExtractJsTypeFromColumnBuilder<CB extends AnyColumnBuilder> = CB extends ColumnBuilder<\n infer _ColumnName extends string,\n infer _ColumnMeta extends StorageColumn,\n infer JsType,\n infer _Ops\n>\n ? JsType\n : never;\n\nexport type InferProjectionRow<P extends Record<string, AnyColumnBuilder>> = {\n [K in keyof P]: ExtractJsTypeFromColumnBuilder<P[K]>;\n};\n\n/**\n * Nested projection type - allows recursive nesting of ColumnBuilder or nested objects.\n */\nexport type NestedProjection = Record<\n string,\n | AnyColumnBuilder\n | Record<\n string,\n | AnyColumnBuilder\n | Record<\n string,\n AnyColumnBuilder | Record<string, AnyColumnBuilder | Record<string, AnyColumnBuilder>>\n >\n >\n>;\n\n/**\n * Helper type to extract include type from Includes map.\n * Returns the value type if K is a key of Includes, otherwise returns unknown.\n */\ntype ExtractIncludeType<\n K extends string,\n Includes extends Record<string, unknown>,\n> = K extends keyof Includes ? Includes[K] : unknown;\n\n/**\n * Infers Row type from a nested projection object.\n * Recursively maps Record<string, ColumnBuilder | boolean | NestedProjection> to nested object types.\n *\n * Extracts the pre-computed JsType from each ColumnBuilder at leaves.\n * When a value is `true`, it represents an include reference and infers `Array<ChildShape>`\n * by looking up the include alias in the Includes type map.\n */\nexport type InferNestedProjectionRow<\n P extends Record<string, AnyColumnBuilder | boolean | NestedProjection>,\n CodecTypes extends Record<string, { readonly output: unknown }> = Record<string, never>,\n Includes extends Record<string, unknown> = Record<string, never>,\n> = {\n [K in keyof P]: P[K] extends AnyColumnBuilder\n ? ExtractJsTypeFromColumnBuilder<P[K]>\n : P[K] extends true\n ? Array<ExtractIncludeType<K & string, Includes>> // Include reference - infers Array<ChildShape> from Includes map\n : P[K] extends NestedProjection\n ? InferNestedProjectionRow<P[K], CodecTypes, Includes>\n : never;\n};\n\n/**\n * Infers Row type from a tuple of ColumnBuilders used in returning() clause.\n * Extracts column name and JsType from each ColumnBuilder and creates a Record.\n */\nexport type InferReturningRow<Columns extends readonly AnyColumnBuilder[]> =\n Columns extends readonly [infer First, ...infer Rest]\n ? First extends ColumnBuilder<\n infer Name,\n infer _Meta,\n infer JsType,\n infer _Ops extends OperationTypes\n >\n ? Name extends string\n ? Rest extends readonly AnyColumnBuilder[]\n ? { [K in Name]: JsType } & InferReturningRow<Rest>\n : { [K in Name]: JsType }\n : never\n : never\n : Record<string, never>;\n\n/**\n * Utility type to check if a contract has the required capabilities for includeMany.\n * Requires both `lateral` and `jsonAgg` to be `true` in the contract's capabilities for the target.\n * Capabilities are nested by target: `{ [target]: { lateral: true, jsonAgg: true } }`\n */\nexport type HasIncludeManyCapabilities<TContract extends SqlContract<SqlStorage>> =\n TContract extends { capabilities: infer C; target: infer T }\n ? T extends string\n ? C extends Record<string, Record<string, boolean>>\n ? C extends { [K in T]: infer TargetCaps }\n ? TargetCaps extends { lateral: true; jsonAgg: true }\n ? true\n : false\n : false\n : false\n : false\n : false;\n\n/**\n * SQL-specific Plan type that refines the ast field to use QueryAst.\n * This is the type used by SQL query builders.\n */\nexport type SqlPlan<Row = unknown> = ExecutionPlan<Row, QueryAst>;\n\n/**\n * Helper types for extracting contract structure.\n */\nexport type TablesOf<TContract> = TContract extends {\n storage: { tables: infer U };\n}\n ? U\n : never;\n\nexport type TableKey<TContract> = Extract<keyof TablesOf<TContract>, string>;\n\n// Common types for contract.d.ts generation (SQL-specific)\n// These types are used by emitted contract.d.ts files to provide type-safe DSL/ORM types\n\n/**\n * Unique symbol for metadata property to avoid collisions with user-defined properties\n */\nexport declare const META: unique symbol;\n\n/**\n * Extracts metadata from a type that has a META property\n */\nexport type Meta<T extends { [META]: unknown }> = T[typeof META];\n\n/**\n * Metadata interface for table definitions\n */\nexport interface TableMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Metadata interface for model definitions\n */\nexport interface ModelMetadata<Name extends string> {\n name: Name;\n}\n\n/**\n * Base interface for table definitions with metadata\n * Used in contract.d.ts to define storage-level table types\n */\nexport interface TableDef<Name extends string> {\n readonly [META]: TableMetadata<Name>;\n}\n\n/**\n * Base interface for model definitions with metadata\n * Used in contract.d.ts to define application-level model types\n */\nexport interface ModelDef<Name extends string> {\n readonly [META]: ModelMetadata<Name>;\n}\n\nexport type ColumnsOf<\n TContract,\n K extends TableKey<TContract>,\n> = K extends keyof TablesOf<TContract>\n ? TablesOf<TContract>[K] extends { columns: infer C }\n ? C\n : never\n : never;\n\nexport interface RawTemplateOptions {\n readonly refs?: PlanRefs;\n readonly annotations?: Record<string, unknown>;\n readonly projection?: ReadonlyArray<string>;\n}\n\nexport interface RawFunctionOptions extends RawTemplateOptions {\n readonly params: ReadonlyArray<unknown>;\n}\n\nexport type RawTemplateFactory = (\n strings: TemplateStringsArray,\n ...values: readonly unknown[]\n) => ExecutionPlan;\n\nexport interface RawFactory extends RawTemplateFactory {\n (text: string, options: RawFunctionOptions): ExecutionPlan;\n with(options: RawTemplateOptions): RawTemplateFactory;\n}\n\nexport type { RuntimeError } from '@prisma-next/plan';\n\nexport interface BuildParamsMap {\n readonly [name: string]: unknown;\n}\n\nexport interface BuildOptions {\n readonly params?: BuildParamsMap;\n}\n\nexport interface SqlBuilderOptions<\n TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>,\n> {\n readonly context: QueryLaneContext<TContract>;\n}\n\n/**\n * SQL-specific ResultType that works with both Plan and SqlQueryPlan.\n * This extends the core ResultType to also handle SqlQueryPlan.\n * Example: `type Row = ResultType<typeof plan>`\n */\nexport type ResultType<P> = P extends SqlQueryPlan<infer R> ? R : CoreResultType<P>;\n"],"mappings":";AA6EO,SAAS,gBAAgB,OAA2C;AACzE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAA4B,SAAS;AAE1C;","names":[]}
|
package/dist/chunk-UVFWELV2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-UVFWELV2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|
|
File without changes
|