metal-orm 1.0.80 → 1.0.81

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/index.d.cts CHANGED
@@ -2676,6 +2676,7 @@ type NormalizedRelationIncludeTree = Record<string, NormalizedRelationIncludeNod
2676
2676
  type QueryResult = {
2677
2677
  columns: string[];
2678
2678
  values: unknown[][];
2679
+ insertId?: number;
2679
2680
  };
2680
2681
  interface DbExecutor {
2681
2682
  /** Capability flags so the runtime can make correct decisions without relying on optional methods. */
@@ -3229,6 +3230,7 @@ declare class UnitOfWork {
3229
3230
  * @param results - Query results
3230
3231
  */
3231
3232
  private applyReturningResults;
3233
+ private applyInsertId;
3232
3234
  /**
3233
3235
  * Normalizes a column name by removing quotes and table prefixes.
3234
3236
  * @param column - The column name to normalize
@@ -3793,6 +3795,8 @@ interface JsonSchemaProperty {
3793
3795
  format?: JsonSchemaFormat;
3794
3796
  description?: string;
3795
3797
  nullable?: boolean;
3798
+ readOnly?: boolean;
3799
+ writeOnly?: boolean;
3796
3800
  minimum?: number;
3797
3801
  maximum?: number;
3798
3802
  minLength?: number;
@@ -3810,6 +3814,21 @@ interface JsonSchemaProperty {
3810
3814
  oneOf?: JsonSchemaProperty[];
3811
3815
  [key: string]: unknown;
3812
3816
  }
3817
+ /**
3818
+ * OpenAPI 3.1 parameter definition
3819
+ */
3820
+ interface OpenApiParameter {
3821
+ name: string;
3822
+ in: 'query' | 'path' | 'header' | 'cookie';
3823
+ description?: string;
3824
+ required?: boolean;
3825
+ deprecated?: boolean;
3826
+ allowEmptyValue?: boolean;
3827
+ style?: string;
3828
+ explode?: boolean;
3829
+ schema?: JsonSchemaProperty;
3830
+ [key: string]: unknown;
3831
+ }
3813
3832
  /**
3814
3833
  * Complete OpenAPI 3.1 Schema for an entity or query result
3815
3834
  */
@@ -3820,22 +3839,65 @@ interface OpenApiSchema {
3820
3839
  description?: string;
3821
3840
  }
3822
3841
  /**
3823
- * Schema generation options
3842
+ * Column-level schema flags
3824
3843
  */
3825
- interface SchemaOptions {
3826
- /** Use selected columns only (from select/include) vs full entity */
3827
- mode?: 'selected' | 'full';
3844
+ interface ColumnSchemaOptions {
3828
3845
  /** Include description from column comments */
3829
3846
  includeDescriptions?: boolean;
3830
3847
  /** Include enum values for enum columns */
3831
3848
  includeEnums?: boolean;
3832
3849
  /** Include column examples if available */
3833
3850
  includeExamples?: boolean;
3834
- /** Format output for pretty printing (debugging) */
3835
- pretty?: boolean;
3851
+ /** Include column defaults */
3852
+ includeDefaults?: boolean;
3853
+ /** Include nullable flag when applicable */
3854
+ includeNullable?: boolean;
3855
+ }
3856
+ /**
3857
+ * Output schema generation options (query result)
3858
+ */
3859
+ interface OutputSchemaOptions extends ColumnSchemaOptions {
3860
+ /** Use selected columns only (from select/include) vs full entity */
3861
+ mode?: 'selected' | 'full';
3836
3862
  /** Maximum depth for relation recursion */
3837
3863
  maxDepth?: number;
3838
3864
  }
3865
+ type InputRelationMode = 'ids' | 'objects' | 'mixed';
3866
+ type InputSchemaMode = 'create' | 'update';
3867
+ /**
3868
+ * Input schema generation options (write payloads)
3869
+ */
3870
+ interface InputSchemaOptions extends ColumnSchemaOptions {
3871
+ /** Create vs update payload shape */
3872
+ mode?: InputSchemaMode;
3873
+ /** Include relation payloads */
3874
+ includeRelations?: boolean;
3875
+ /** How relations are represented (ids, nested objects, or both) */
3876
+ relationMode?: InputRelationMode;
3877
+ /** Maximum depth for relation recursion */
3878
+ maxDepth?: number;
3879
+ /** Omit read-only/generated columns from input */
3880
+ omitReadOnly?: boolean;
3881
+ /** Exclude primary key columns from input */
3882
+ excludePrimaryKey?: boolean;
3883
+ /** Require primary key columns on update payloads */
3884
+ requirePrimaryKey?: boolean;
3885
+ }
3886
+ /**
3887
+ * Schema generation options
3888
+ */
3889
+ interface SchemaOptions extends OutputSchemaOptions {
3890
+ /** Input schema options, or false to skip input generation */
3891
+ input?: InputSchemaOptions | false;
3892
+ }
3893
+ /**
3894
+ * Input + output schema bundle
3895
+ */
3896
+ interface OpenApiSchemaBundle {
3897
+ output: OpenApiSchema;
3898
+ input?: OpenApiSchema;
3899
+ parameters?: OpenApiParameter[];
3900
+ }
3839
3901
  /**
3840
3902
  * Schema extraction context for handling circular references
3841
3903
  */
@@ -3853,7 +3915,7 @@ interface SchemaExtractionContext {
3853
3915
  /**
3854
3916
  * Maps SQL column types to OpenAPI JSON Schema types
3855
3917
  */
3856
- declare const mapColumnType: (column: ColumnDef) => JsonSchemaProperty;
3918
+ declare const mapColumnType: (column: ColumnDef, options?: ColumnSchemaOptions) => JsonSchemaProperty;
3857
3919
  /**
3858
3920
  * Maps relation type to array or single object
3859
3921
  */
@@ -3867,22 +3929,16 @@ declare const mapRelationType: (relationType: string) => {
3867
3929
  declare const getTemporalFormat: (sqlType: string) => JsonSchemaFormat | undefined;
3868
3930
 
3869
3931
  /**
3870
- * Extracts OpenAPI 3.1 schema from a query builder's hydration plan
3871
- * @param table - Table definition
3872
- * @param plan - Hydration plan from query builder
3873
- * @param projectionNodes - Projection AST nodes (for computed fields)
3874
- * @param options - Schema generation options
3875
- * @returns OpenAPI 3.1 JSON Schema
3932
+ * Extracts OpenAPI 3.1 schemas for output and optional input payloads.
3876
3933
  */
3877
- declare const extractSchema: (table: TableDef, plan: HydrationPlan | undefined, projectionNodes: ProjectionNode[] | undefined, options?: SchemaOptions) => OpenApiSchema;
3934
+ declare const extractSchema: (table: TableDef, plan: HydrationPlan | undefined, projectionNodes: ProjectionNode[] | undefined, options?: SchemaOptions) => OpenApiSchemaBundle;
3878
3935
  /**
3879
3936
  * Converts a schema to a JSON string with optional pretty printing
3880
- * @param schema - OpenAPI schema
3881
- * @param pretty - Whether to pretty print
3882
- * @returns JSON string
3883
3937
  */
3884
3938
  declare const schemaToJson: (schema: OpenApiSchema, pretty?: boolean) => string;
3885
3939
 
3940
+ declare const buildFilterParameters: (table: TableDef, where: ExpressionNode | undefined, from: TableSourceNode | undefined, options?: ColumnSchemaOptions) => OpenApiParameter[];
3941
+
3886
3942
  type SelectDialectInput = Dialect | DialectKey;
3887
3943
 
3888
3944
  type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode | TypedExpression<unknown>;
@@ -4499,14 +4555,14 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
4499
4555
  */
4500
4556
  getHydrationPlan(): HydrationPlan | undefined;
4501
4557
  /**
4502
- * Gets OpenAPI 3.1 JSON Schema for query result
4558
+ * Gets OpenAPI 3.1 JSON Schemas for query output and optional input payloads
4503
4559
  * @param options - Schema generation options
4504
- * @returns OpenAPI 3.1 JSON Schema for query result
4560
+ * @returns OpenAPI 3.1 JSON Schemas for query output and input payloads
4505
4561
  * @example
4506
- * const schema = qb.select('id', 'title', 'author').getSchema();
4507
- * console.log(JSON.stringify(schema, null, 2));
4562
+ * const { output } = qb.select('id', 'title', 'author').getSchema();
4563
+ * console.log(JSON.stringify(output, null, 2));
4508
4564
  */
4509
- getSchema(options?: SchemaOptions): OpenApiSchema;
4565
+ getSchema(options?: SchemaOptions): OpenApiSchemaBundle;
4510
4566
  /**
4511
4567
  * Gets the Abstract Syntax Tree (AST) representation of the query
4512
4568
  * @returns Query AST with hydration applied
@@ -7131,4 +7187,4 @@ type PooledExecutorFactoryOptions<TConn> = {
7131
7187
  */
7132
7188
  declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
7133
7189
 
7134
- export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, type PrimaryKey$1 as EntityPrimaryKey, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, InterceptorPipeline, type IntrospectOptions, type JsonPathNode, type JsonSchemaFormat, type JsonSchemaProperty, type JsonSchemaType, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OpenApiSchema, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type PaginatedResult, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryContext, type QueryInterceptor, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type SaveGraphSessionOptions, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaExtractionContext, type SchemaGenerateResult, type SchemaIntrospector, type SchemaOptions, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, type TypedLike, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, entityRefs, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, extractSchema, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, getTemporalFormat, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, mapColumnType, mapRelationType, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, schemaToJson, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
7190
+ export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnSchemaOptions, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, type PrimaryKey$1 as EntityPrimaryKey, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, type InputRelationMode, type InputSchemaMode, type InputSchemaOptions, InsertQueryBuilder, InterceptorPipeline, type IntrospectOptions, type JsonPathNode, type JsonSchemaFormat, type JsonSchemaProperty, type JsonSchemaType, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OpenApiParameter, type OpenApiSchema, type OpenApiSchemaBundle, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type OutputSchemaOptions, type PaginatedResult, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryContext, type QueryInterceptor, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type SaveGraphSessionOptions, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaExtractionContext, type SchemaGenerateResult, type SchemaIntrospector, type SchemaOptions, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, type TypedLike, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, buildFilterParameters, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, entityRefs, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, extractSchema, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, getTemporalFormat, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, mapColumnType, mapRelationType, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, schemaToJson, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
package/dist/index.d.ts CHANGED
@@ -2676,6 +2676,7 @@ type NormalizedRelationIncludeTree = Record<string, NormalizedRelationIncludeNod
2676
2676
  type QueryResult = {
2677
2677
  columns: string[];
2678
2678
  values: unknown[][];
2679
+ insertId?: number;
2679
2680
  };
2680
2681
  interface DbExecutor {
2681
2682
  /** Capability flags so the runtime can make correct decisions without relying on optional methods. */
@@ -3229,6 +3230,7 @@ declare class UnitOfWork {
3229
3230
  * @param results - Query results
3230
3231
  */
3231
3232
  private applyReturningResults;
3233
+ private applyInsertId;
3232
3234
  /**
3233
3235
  * Normalizes a column name by removing quotes and table prefixes.
3234
3236
  * @param column - The column name to normalize
@@ -3793,6 +3795,8 @@ interface JsonSchemaProperty {
3793
3795
  format?: JsonSchemaFormat;
3794
3796
  description?: string;
3795
3797
  nullable?: boolean;
3798
+ readOnly?: boolean;
3799
+ writeOnly?: boolean;
3796
3800
  minimum?: number;
3797
3801
  maximum?: number;
3798
3802
  minLength?: number;
@@ -3810,6 +3814,21 @@ interface JsonSchemaProperty {
3810
3814
  oneOf?: JsonSchemaProperty[];
3811
3815
  [key: string]: unknown;
3812
3816
  }
3817
+ /**
3818
+ * OpenAPI 3.1 parameter definition
3819
+ */
3820
+ interface OpenApiParameter {
3821
+ name: string;
3822
+ in: 'query' | 'path' | 'header' | 'cookie';
3823
+ description?: string;
3824
+ required?: boolean;
3825
+ deprecated?: boolean;
3826
+ allowEmptyValue?: boolean;
3827
+ style?: string;
3828
+ explode?: boolean;
3829
+ schema?: JsonSchemaProperty;
3830
+ [key: string]: unknown;
3831
+ }
3813
3832
  /**
3814
3833
  * Complete OpenAPI 3.1 Schema for an entity or query result
3815
3834
  */
@@ -3820,22 +3839,65 @@ interface OpenApiSchema {
3820
3839
  description?: string;
3821
3840
  }
3822
3841
  /**
3823
- * Schema generation options
3842
+ * Column-level schema flags
3824
3843
  */
3825
- interface SchemaOptions {
3826
- /** Use selected columns only (from select/include) vs full entity */
3827
- mode?: 'selected' | 'full';
3844
+ interface ColumnSchemaOptions {
3828
3845
  /** Include description from column comments */
3829
3846
  includeDescriptions?: boolean;
3830
3847
  /** Include enum values for enum columns */
3831
3848
  includeEnums?: boolean;
3832
3849
  /** Include column examples if available */
3833
3850
  includeExamples?: boolean;
3834
- /** Format output for pretty printing (debugging) */
3835
- pretty?: boolean;
3851
+ /** Include column defaults */
3852
+ includeDefaults?: boolean;
3853
+ /** Include nullable flag when applicable */
3854
+ includeNullable?: boolean;
3855
+ }
3856
+ /**
3857
+ * Output schema generation options (query result)
3858
+ */
3859
+ interface OutputSchemaOptions extends ColumnSchemaOptions {
3860
+ /** Use selected columns only (from select/include) vs full entity */
3861
+ mode?: 'selected' | 'full';
3836
3862
  /** Maximum depth for relation recursion */
3837
3863
  maxDepth?: number;
3838
3864
  }
3865
+ type InputRelationMode = 'ids' | 'objects' | 'mixed';
3866
+ type InputSchemaMode = 'create' | 'update';
3867
+ /**
3868
+ * Input schema generation options (write payloads)
3869
+ */
3870
+ interface InputSchemaOptions extends ColumnSchemaOptions {
3871
+ /** Create vs update payload shape */
3872
+ mode?: InputSchemaMode;
3873
+ /** Include relation payloads */
3874
+ includeRelations?: boolean;
3875
+ /** How relations are represented (ids, nested objects, or both) */
3876
+ relationMode?: InputRelationMode;
3877
+ /** Maximum depth for relation recursion */
3878
+ maxDepth?: number;
3879
+ /** Omit read-only/generated columns from input */
3880
+ omitReadOnly?: boolean;
3881
+ /** Exclude primary key columns from input */
3882
+ excludePrimaryKey?: boolean;
3883
+ /** Require primary key columns on update payloads */
3884
+ requirePrimaryKey?: boolean;
3885
+ }
3886
+ /**
3887
+ * Schema generation options
3888
+ */
3889
+ interface SchemaOptions extends OutputSchemaOptions {
3890
+ /** Input schema options, or false to skip input generation */
3891
+ input?: InputSchemaOptions | false;
3892
+ }
3893
+ /**
3894
+ * Input + output schema bundle
3895
+ */
3896
+ interface OpenApiSchemaBundle {
3897
+ output: OpenApiSchema;
3898
+ input?: OpenApiSchema;
3899
+ parameters?: OpenApiParameter[];
3900
+ }
3839
3901
  /**
3840
3902
  * Schema extraction context for handling circular references
3841
3903
  */
@@ -3853,7 +3915,7 @@ interface SchemaExtractionContext {
3853
3915
  /**
3854
3916
  * Maps SQL column types to OpenAPI JSON Schema types
3855
3917
  */
3856
- declare const mapColumnType: (column: ColumnDef) => JsonSchemaProperty;
3918
+ declare const mapColumnType: (column: ColumnDef, options?: ColumnSchemaOptions) => JsonSchemaProperty;
3857
3919
  /**
3858
3920
  * Maps relation type to array or single object
3859
3921
  */
@@ -3867,22 +3929,16 @@ declare const mapRelationType: (relationType: string) => {
3867
3929
  declare const getTemporalFormat: (sqlType: string) => JsonSchemaFormat | undefined;
3868
3930
 
3869
3931
  /**
3870
- * Extracts OpenAPI 3.1 schema from a query builder's hydration plan
3871
- * @param table - Table definition
3872
- * @param plan - Hydration plan from query builder
3873
- * @param projectionNodes - Projection AST nodes (for computed fields)
3874
- * @param options - Schema generation options
3875
- * @returns OpenAPI 3.1 JSON Schema
3932
+ * Extracts OpenAPI 3.1 schemas for output and optional input payloads.
3876
3933
  */
3877
- declare const extractSchema: (table: TableDef, plan: HydrationPlan | undefined, projectionNodes: ProjectionNode[] | undefined, options?: SchemaOptions) => OpenApiSchema;
3934
+ declare const extractSchema: (table: TableDef, plan: HydrationPlan | undefined, projectionNodes: ProjectionNode[] | undefined, options?: SchemaOptions) => OpenApiSchemaBundle;
3878
3935
  /**
3879
3936
  * Converts a schema to a JSON string with optional pretty printing
3880
- * @param schema - OpenAPI schema
3881
- * @param pretty - Whether to pretty print
3882
- * @returns JSON string
3883
3937
  */
3884
3938
  declare const schemaToJson: (schema: OpenApiSchema, pretty?: boolean) => string;
3885
3939
 
3940
+ declare const buildFilterParameters: (table: TableDef, where: ExpressionNode | undefined, from: TableSourceNode | undefined, options?: ColumnSchemaOptions) => OpenApiParameter[];
3941
+
3886
3942
  type SelectDialectInput = Dialect | DialectKey;
3887
3943
 
3888
3944
  type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode | TypedExpression<unknown>;
@@ -4499,14 +4555,14 @@ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Ta
4499
4555
  */
4500
4556
  getHydrationPlan(): HydrationPlan | undefined;
4501
4557
  /**
4502
- * Gets OpenAPI 3.1 JSON Schema for query result
4558
+ * Gets OpenAPI 3.1 JSON Schemas for query output and optional input payloads
4503
4559
  * @param options - Schema generation options
4504
- * @returns OpenAPI 3.1 JSON Schema for query result
4560
+ * @returns OpenAPI 3.1 JSON Schemas for query output and input payloads
4505
4561
  * @example
4506
- * const schema = qb.select('id', 'title', 'author').getSchema();
4507
- * console.log(JSON.stringify(schema, null, 2));
4562
+ * const { output } = qb.select('id', 'title', 'author').getSchema();
4563
+ * console.log(JSON.stringify(output, null, 2));
4508
4564
  */
4509
- getSchema(options?: SchemaOptions): OpenApiSchema;
4565
+ getSchema(options?: SchemaOptions): OpenApiSchemaBundle;
4510
4566
  /**
4511
4567
  * Gets the Abstract Syntax Tree (AST) representation of the query
4512
4568
  * @returns Query AST with hydration applied
@@ -7131,4 +7187,4 @@ type PooledExecutorFactoryOptions<TConn> = {
7131
7187
  */
7132
7188
  declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
7133
7189
 
7134
- export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, type PrimaryKey$1 as EntityPrimaryKey, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, InterceptorPipeline, type IntrospectOptions, type JsonPathNode, type JsonSchemaFormat, type JsonSchemaProperty, type JsonSchemaType, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OpenApiSchema, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type PaginatedResult, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryContext, type QueryInterceptor, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type SaveGraphSessionOptions, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaExtractionContext, type SchemaGenerateResult, type SchemaIntrospector, type SchemaOptions, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, type TypedLike, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, entityRefs, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, extractSchema, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, getTemporalFormat, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, mapColumnType, mapRelationType, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, schemaToJson, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
7190
+ export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnSchemaOptions, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, type PrimaryKey$1 as EntityPrimaryKey, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, type InputRelationMode, type InputSchemaMode, type InputSchemaOptions, InsertQueryBuilder, InterceptorPipeline, type IntrospectOptions, type JsonPathNode, type JsonSchemaFormat, type JsonSchemaProperty, type JsonSchemaType, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OpenApiParameter, type OpenApiSchema, type OpenApiSchemaBundle, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type OutputSchemaOptions, type PaginatedResult, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryContext, type QueryInterceptor, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type SaveGraphSessionOptions, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaExtractionContext, type SchemaGenerateResult, type SchemaIntrospector, type SchemaOptions, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, type TypedLike, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, buildFilterParameters, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, entityRefs, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, extractSchema, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, getTemporalFormat, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, mapColumnType, mapRelationType, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, schemaToJson, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };