import type { AnnotationValue, OperationKind, ValidAnnotations, } from '@prisma-next/framework-components/runtime'; import type { StorageTable } from '@prisma-next/sql-contract/types'; import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan'; import type { ExpressionBuilder, WithFields } from '../expression'; import type { ResolveRow } from '../resolve'; import type { EmptyRow, GatedMethod, QueryContext, Scope, ScopeField } from '../scope'; export type ReturningCapability = { sql: { returning: true } }; // Map table columns to their codec input types export type InsertValues< Table extends StorageTable, CT extends Record, > = { [K in keyof Table['columns']]?: Table['columns'][K]['codecId'] extends keyof CT ? CT[Table['columns'][K]['codecId']]['input'] : unknown; }; export type UpdateValues< Table extends StorageTable, CT extends Record, > = { [K in keyof Table['columns']]?: Table['columns'][K]['codecId'] extends keyof CT ? CT[Table['columns'][K]['codecId']]['input'] : unknown; }; export interface InsertQuery< QC extends QueryContext, AvailableScope extends Scope, RowType extends Record, > { /** * 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< QC['capabilities'], ReturningCapability, ( ...columns: Columns ) => InsertQuery> >; build(): SqlQueryPlan>; } export interface UpdateQuery< QC extends QueryContext, AvailableScope extends Scope, RowType extends Record, > { /** * 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< QC['capabilities'], ReturningCapability, ( ...columns: Columns ) => UpdateQuery> >; build(): SqlQueryPlan>; } export interface DeleteQuery< QC extends QueryContext, AvailableScope extends Scope, RowType extends Record, > { /** * 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< QC['capabilities'], ReturningCapability, ( ...columns: Columns ) => DeleteQuery> >; build(): SqlQueryPlan>; }