import { AnyFromSource, SelectAst } from "@prisma-next/sql-relational-core/ast"; import { CodecExpression, CodecTypesBase, Expression as Expression$1, RawSqlTag, ScopeField, TraitExpression } from "@prisma-next/sql-relational-core/expression"; import { AnnotationValue, OperationKind, ValidAnnotations } from "@prisma-next/framework-components/runtime"; import { ExtractCodecTypes, ExtractQueryOperationTypes, ExtractStorageColumnInputTypes, ExtractStorageColumnTypes, QueryOperationTypesBase, StorageColumnMapAt, StorageTable, StorageTable as StorageTable$1 } from "@prisma-next/sql-contract/types"; import { SqlQueryPlan } from "@prisma-next/sql-relational-core/plan"; //#region src/scope.d.ts type GatedMethod = Capabilities extends Required ? Method : never; declare const JoinOuterScope: unique symbol; declare const SubqueryMarker: unique symbol; type Expand = { [K in keyof T]: T[K]; } & unknown; type EmptyRow = Record; type ScopeTable = Record; type Scope = { topLevel: ScopeTable; namespaces: Record; }; type JoinSource = { readonly [JoinOuterScope]: { topLevel: Row; namespaces: Record; }; getJoinOuterScope(): Scope; buildAst(): AnyFromSource; }; type DefaultScope = { topLevel: StorageTableToScopeTable; namespaces: { [K in Name]: StorageTableToScopeTable
; }; }; type StorageTableToScopeTable = { [K in keyof T['columns']]: { codecId: T['columns'][K]['codecId']; nullable: T['columns'][K]['nullable']; } & (T['columns'][K] extends { many: true; } ? { many: true; } : Record); }; type MergeScopes = { topLevel: Expand & Omit>; namespaces: Expand; }; type RebindScope = { topLevel: S['topLevel']; namespaces: Expand & Record>; }; type NullableScopeTable = { [K in keyof S]: { codecId: S[K]['codecId']; nullable: true; }; }; type NullableScope = { topLevel: NullableScopeTable; namespaces: { [TableName in keyof S['namespaces']]: NullableScopeTable; }; }; type Subquery> = { [SubqueryMarker]: RowType; buildAst(): SelectAst; getRowFields(): Record; }; type QueryContext = { readonly codecTypes: CodecTypesBase; readonly capabilities: Record>; readonly queryOperationTypes: QueryOperationTypesBase; readonly resolvedColumnOutputTypes: Record; }; //#endregion //#region src/expression.d.ts type BooleanCodecType = { codecId: 'pg/bool@1'; nullable: boolean; }; type WithField = Expand; type WithFields = Expand>; type ExtractScopeFields>> = { [K in keyof T]: T[K] extends Expression$1 ? F : never; }; type FieldProxy = { [K in keyof AvailableScope['topLevel']]: Expression$1; } & { [TableName in keyof AvailableScope['namespaces']]: { [K in keyof AvailableScope['namespaces'][TableName]]: Expression$1; }; }; type ExpressionBuilder = (fields: FieldProxy, fns: Functions) => Expression$1; type OrderByDirection = 'asc' | 'desc'; type OrderByNulls = 'first' | 'last'; type OrderByOptions = { direction?: OrderByDirection; nulls?: OrderByNulls; }; type OrderByScope> = { topLevel: Expand; namespaces: AvailableScope['namespaces']; }; type DeriveExtFunctions = { [K in keyof OT]: OT[K]['impl']; }; type BuiltinFunctions> = { eq: (a: CodecExpression | null, b: CodecExpression | null) => Expression$1; ne: (a: CodecExpression | null, b: CodecExpression | null) => Expression$1; gt: (a: CodecExpression, b: CodecExpression) => Expression$1; gte: (a: CodecExpression, b: CodecExpression) => Expression$1; lt: (a: CodecExpression, b: CodecExpression) => Expression$1; lte: (a: CodecExpression, b: CodecExpression) => Expression$1; and: (...ands: CodecExpression<'pg/bool@1', boolean, CT>[]) => Expression$1; or: (...ors: CodecExpression<'pg/bool@1', boolean, CT>[]) => Expression$1; exists: (subquery: Subquery>) => Expression$1; notExists: (subquery: Subquery>) => Expression$1; in: { (expr: Expression$1<{ codecId: CodecId; nullable: boolean; }>, subquery: Subquery>): Expression$1; (expr: Expression$1<{ codecId: CodecId; nullable: boolean; }>, values: Array>): Expression$1; }; notIn: { (expr: Expression$1<{ codecId: CodecId; nullable: boolean; }>, subquery: Subquery>): Expression$1; (expr: Expression$1<{ codecId: CodecId; nullable: boolean; }>, values: Array>): Expression$1; }; readonly raw: RawSqlTag; }; type Functions = BuiltinFunctions & DeriveExtFunctions; type CountField = { codecId: 'pg/int8@1'; nullable: false; }; type AggregateOnlyFunctions = { count: (expr?: Expression$1) => Expression$1; sum: (expr: Expression$1) => Expression$1<{ codecId: T['codecId']; nullable: true; }>; avg: (expr: Expression$1) => Expression$1<{ codecId: T['codecId']; nullable: true; }>; min: (expr: Expression$1) => Expression$1<{ codecId: T['codecId']; nullable: true; }>; max: (expr: Expression$1) => Expression$1<{ codecId: T['codecId']; nullable: true; }>; }; type AggregateFunctions = Functions & AggregateOnlyFunctions; //#endregion //#region src/resolve.d.ts type ResolveField> = F['codecId'] extends keyof CodecTypes ? F['nullable'] extends true ? CodecTypes[F['codecId']]['output'] | null : CodecTypes[F['codecId']]['output'] : unknown; type ApplyNullable = F['nullable'] extends true ? T | null : T; type ResolveRow, CodecTypes extends Record, PreResolved extends Record = Record> = Expand<{ -readonly [K in keyof Row]: string extends keyof PreResolved ? ResolveField : K extends keyof PreResolved ? ApplyNullable, Row[K]> : ResolveField; }>; //#endregion //#region src/types/mutation-query.d.ts type ReturningCapability = { sql: { returning: true; }; }; type InsertValues
> = { [K in keyof Table['columns']]?: Table['columns'][K]['codecId'] extends keyof CT ? CT[Table['columns'][K]['codecId']]['input'] : unknown; }; interface InsertQuery> { /** * Attach one or more write-typed annotations to this query plan. * Annotations declare `applicableTo: ['write']` (or `['read', 'write']`) * via `defineAnnotation`; read-only annotations fail to compile here. * Annotations are merged into `plan.meta.annotations` at `.build()` time. * Chainable in any position; multiple calls compose with last-write-wins * on duplicate namespaces. */ annotate[]>(...annotations: As & ValidAnnotations<'write', As>): InsertQuery; returning: GatedMethod(...columns: Columns) => InsertQuery>>; build(): SqlQueryPlan>; } interface UpdateQuery> { /** * Attach one or more write-typed annotations to this query plan. * See `InsertQuery.annotate` for semantics. */ annotate[]>(...annotations: As & ValidAnnotations<'write', As>): UpdateQuery; where(expr: ExpressionBuilder): UpdateQuery; returning: GatedMethod(...columns: Columns) => UpdateQuery>>; build(): SqlQueryPlan>; } interface DeleteQuery> { /** * Attach one or more write-typed annotations to this query plan. * See `InsertQuery.annotate` for semantics. */ annotate[]>(...annotations: As & ValidAnnotations<'write', As>): DeleteQuery; where(expr: ExpressionBuilder): DeleteQuery; returning: GatedMethod(...columns: Columns) => DeleteQuery>>; build(): SqlQueryPlan>; } //#endregion //#region src/types/joined-tables.d.ts interface JoinedTables extends WithSelect, WithJoin {} //#endregion //#region src/types/grouped-query.d.ts interface GroupedQuery> extends Subquery, WithPagination, WithDistinct, WithAlias, WithBuild { /** * Attach one or more read-typed annotations to this query plan. * Annotations declare `applicableTo: ['read']` (or `['read', 'write']`) * via `defineAnnotation`; write-only annotations fail to compile here. * Annotations are merged into `plan.meta.annotations` at `.build()` time. * Chainable in any position; multiple calls compose with last-write-wins * on duplicate namespaces. */ annotate[]>(...annotations: As & ValidAnnotations<'read', As>): GroupedQuery; groupBy(...fields: ((keyof RowType | keyof AvailableScope['topLevel']) & string)[]): GroupedQuery; groupBy(expr: (fields: FieldProxy>, fns: Functions) => Expression$1): GroupedQuery; having(expr: (fields: FieldProxy>, fns: AggregateFunctions) => Expression$1): GroupedQuery; orderBy(field: (keyof RowType | keyof AvailableScope['topLevel']) & string, options?: OrderByOptions): GroupedQuery; orderBy(expr: (fields: FieldProxy>, fns: AggregateFunctions) => Expression$1, options?: OrderByOptions): GroupedQuery; distinctOn: GatedMethod; (expr: (fields: FieldProxy>, fns: Functions) => Expression$1): GroupedQuery; }>; } //#endregion //#region src/types/select-query.d.ts interface SelectQuery> extends Subquery, WithSelect, WithPagination, WithDistinct, WithAlias, WithBuild { /** * Attach one or more read-typed annotations to this query plan. * Annotations declare `applicableTo: ['read']` (or `['read', 'write']`) * via `defineAnnotation`; write-only annotations fail to compile here. * Annotations are merged into `plan.meta.annotations` at `.build()` time. * Chainable in any position; multiple calls compose with last-write-wins * on duplicate namespaces. */ annotate[]>(...annotations: As & ValidAnnotations<'read', As>): SelectQuery; where(expr: ExpressionBuilder): SelectQuery; orderBy(field: (keyof RowType | keyof AvailableScope['topLevel']) & string, options?: OrderByOptions): SelectQuery; orderBy(expr: (fields: FieldProxy>, fns: Functions) => Expression$1, options?: OrderByOptions): SelectQuery; groupBy(...fields: ((keyof RowType | keyof AvailableScope['topLevel']) & string)[]): GroupedQuery; groupBy(expr: (fields: FieldProxy>, fns: Functions) => Expression$1): GroupedQuery; distinctOn: GatedMethod; (expr: (fields: FieldProxy>, fns: Functions) => Expression$1): SelectQuery; }>; } //#endregion //#region src/types/shared.d.ts interface LateralBuilder { from>(other: Other): SelectQuery, EmptyRow>; } interface WithSelect = EmptyRow> { select(...columns: Columns): SelectQuery>; select(alias: Alias, expr: (fields: FieldProxy, fns: AggregateFunctions) => Expression$1): SelectQuery>; select>>(callback: (fields: FieldProxy, fns: AggregateFunctions) => Result): SelectQuery>>; } interface WithJoin { innerJoin>(other: Other, on: ExpressionBuilder, QC>): JoinedTables>; outerLeftJoin>(other: Other, on: ExpressionBuilder, QC>): JoinedTables>>; outerRightJoin>(other: Other, on: ExpressionBuilder, QC>): JoinedTables, Other[typeof JoinOuterScope]>>; outerFullJoin>(other: Other, on: ExpressionBuilder, QC>): JoinedTables, NullableScope>>; lateralJoin: GatedMethod>(alias: Alias, builder: (lateral: LateralBuilder) => Subquery) => JoinedTables; }>>>; outerLateralJoin: GatedMethod>(alias: Alias, builder: (lateral: LateralBuilder) => Subquery) => JoinedTables; }>>>>; } type PaginationValue = number | TraitExpression; interface WithPagination { limit(count: PaginationValue): this; offset(count: PaginationValue): this; } interface WithDistinct { distinct(): this; } interface WithAlias> { as(newAlias: Alias): JoinSource; } interface WithBuild> { build(): SqlQueryPlan>; } //#endregion //#region src/types/table-proxy.d.ts type ResolvedColumnTypes, NsId, TableName>, ColumnKeys extends string = [ColMap] extends [never] ? never : keyof ColMap & string> = { readonly [K in ColumnKeys]: ColMap extends Record ? ColMap[K] : never; }; type ResolvedInsertValues> = StorageColumnMapAt, NsId, TableName> extends (infer ColMap) ? [ColMap] extends [never] ? InsertValues : { [K in keyof ColMap]?: ColMap[K]; } : InsertValues; type ResolvedUpdateValues> = ResolvedInsertValues; type ResolvedUpdateExpressions
= { [K in keyof Table['columns']]?: Expression$1<{ codecId: Table['columns'][K]['codecId']; nullable: boolean; }>; }; type ContractToQC = { readonly codecTypes: ExtractCodecTypes; readonly capabilities: C['capabilities']; readonly queryOperationTypes: ExtractQueryOperationTypes; readonly resolvedColumnOutputTypes: ResolvedColumnTypes; }; interface TableProxy>, QC extends QueryContext = ContractToQC> extends JoinSource>, Alias>, WithSelect, WithJoin { as(newAlias: NewAlias): TableProxy, QC>; insert(rows: ReadonlyArray, Name, QC['codecTypes']>>): InsertQuery; update(set: ResolvedUpdateValues, Name, QC['codecTypes']>): UpdateQuery; update(callback: (fields: FieldProxy, fns: Functions) => ResolvedUpdateExpressions>): UpdateQuery; delete(): DeleteQuery; } //#endregion //#region src/types/db.d.ts type CapabilitiesBase = Record>; type NamespaceEntries = Readonly>>>; type NamespaceDomain = Readonly>; }>>; type TableProxyContract = { readonly domain: { readonly namespaces: NamespaceDomain; }; readonly storage: { readonly namespaces: Readonly>; }; readonly capabilities: CapabilitiesBase; }; type TablesInNamespace = NS['entries']['table'] extends Readonly> ? NS['entries']['table'] : Readonly>; type UnboundTables = { readonly [Name in TableNamesAcrossNamespaces]: TableInAnyNamespace; }; type TableNamesAcrossNamespaces = { [NSId in keyof C['storage']['namespaces']]: keyof TablesInNamespace & string; }[keyof C['storage']['namespaces']]; type TableInAnyNamespace = { [NSId in keyof C['storage']['namespaces']]: Name extends keyof TablesInNamespace ? TablesInNamespace[Name] : never; }[keyof C['storage']['namespaces']]; type NamespaceTable = TablesInNamespace[Name]; type Namespace = { readonly [Name in keyof TablesInNamespace & string]: TableProxy; }; type Db = { readonly [Ns in keyof C['storage']['namespaces'] & string]: Namespace; }; //#endregion export { Subquery as C, ScopeField as S, FieldProxy as _, TableProxyContract as a, QueryContext as b, SelectQuery as c, InsertQuery as d, UpdateQuery as f, Expression$1 as g, BooleanCodecType as h, TableNamesAcrossNamespaces as i, GroupedQuery as l, AggregateFunctions as m, Namespace as n, UnboundTables as o, ResolveRow as p, TableInAnyNamespace as r, TableProxy as s, Db as t, DeleteQuery as u, Functions as v, Scope as x, GatedMethod as y }; //# sourceMappingURL=db-D1Zq4FVc.d.mts.map