metal-orm 1.0.87 → 1.0.89
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.cjs +226 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +226 -62
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/openapi/schema-extractor-input.ts +193 -0
- package/src/openapi/schema-extractor-output.ts +427 -0
- package/src/openapi/schema-extractor-utils.ts +110 -0
- package/src/openapi/schema-extractor.ts +51 -517
- package/src/openapi/schema-types.ts +30 -1
package/dist/index.d.cts
CHANGED
|
@@ -3872,6 +3872,12 @@ interface OpenApiSchema {
|
|
|
3872
3872
|
required: string[];
|
|
3873
3873
|
description?: string;
|
|
3874
3874
|
}
|
|
3875
|
+
/**
|
|
3876
|
+
* OpenAPI 3.1 components container
|
|
3877
|
+
*/
|
|
3878
|
+
interface OpenApiComponents {
|
|
3879
|
+
schemas: Record<string, OpenApiSchema>;
|
|
3880
|
+
}
|
|
3875
3881
|
/**
|
|
3876
3882
|
* Column-level schema flags
|
|
3877
3883
|
*/
|
|
@@ -3895,9 +3901,21 @@ interface OutputSchemaOptions extends ColumnSchemaOptions {
|
|
|
3895
3901
|
mode?: 'selected' | 'full';
|
|
3896
3902
|
/** Maximum depth for relation recursion */
|
|
3897
3903
|
maxDepth?: number;
|
|
3904
|
+
/** Inline schemas vs $ref components */
|
|
3905
|
+
refMode?: 'inline' | 'components';
|
|
3906
|
+
/** Selected schemas inline vs components when refMode is components */
|
|
3907
|
+
selectedRefMode?: 'inline' | 'components';
|
|
3908
|
+
/** Customize component names */
|
|
3909
|
+
componentName?: (table: TableDef) => string;
|
|
3910
|
+
/** Emit output schema as a component $ref when refMode is components */
|
|
3911
|
+
outputAsRef?: boolean;
|
|
3898
3912
|
}
|
|
3899
3913
|
type InputRelationMode = 'ids' | 'objects' | 'mixed';
|
|
3900
3914
|
type InputSchemaMode = 'create' | 'update';
|
|
3915
|
+
interface RelationSelection {
|
|
3916
|
+
pick?: string[];
|
|
3917
|
+
omit?: string[];
|
|
3918
|
+
}
|
|
3901
3919
|
/**
|
|
3902
3920
|
* Input schema generation options (write payloads)
|
|
3903
3921
|
*/
|
|
@@ -3916,6 +3934,10 @@ interface InputSchemaOptions extends ColumnSchemaOptions {
|
|
|
3916
3934
|
excludePrimaryKey?: boolean;
|
|
3917
3935
|
/** Require primary key columns on update payloads */
|
|
3918
3936
|
requirePrimaryKey?: boolean;
|
|
3937
|
+
/** Remove relation foreign keys pointing to the parent from nested inputs */
|
|
3938
|
+
excludeRelationForeignKeys?: boolean;
|
|
3939
|
+
/** Per-relation field selection for nested inputs */
|
|
3940
|
+
relationSelections?: Record<string, RelationSelection>;
|
|
3919
3941
|
}
|
|
3920
3942
|
/**
|
|
3921
3943
|
* Schema generation options
|
|
@@ -3928,9 +3950,10 @@ interface SchemaOptions extends OutputSchemaOptions {
|
|
|
3928
3950
|
* Input + output schema bundle
|
|
3929
3951
|
*/
|
|
3930
3952
|
interface OpenApiSchemaBundle {
|
|
3931
|
-
output: OpenApiSchema;
|
|
3953
|
+
output: OpenApiSchema | JsonSchemaProperty;
|
|
3932
3954
|
input?: OpenApiSchema;
|
|
3933
3955
|
parameters?: OpenApiParameter[];
|
|
3956
|
+
components?: OpenApiComponents;
|
|
3934
3957
|
}
|
|
3935
3958
|
/**
|
|
3936
3959
|
* Schema extraction context for handling circular references
|
|
@@ -3944,6 +3967,8 @@ interface SchemaExtractionContext {
|
|
|
3944
3967
|
depth: number;
|
|
3945
3968
|
/** Maximum depth to recurse */
|
|
3946
3969
|
maxDepth: number;
|
|
3970
|
+
/** Component registry when using refMode=components */
|
|
3971
|
+
components?: OpenApiComponents;
|
|
3947
3972
|
}
|
|
3948
3973
|
|
|
3949
3974
|
/**
|
|
@@ -7231,4 +7256,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
7231
7256
|
*/
|
|
7232
7257
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
7233
7258
|
|
|
7234
|
-
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, type ParamNode, type ParamProxy, type ParamProxyRoot, 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, createParamProxy, 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, hasExpressionDispatcher, hasMany, hasOne, hasOperandDispatcher, 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 };
|
|
7259
|
+
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 OpenApiComponents, type OpenApiParameter, type OpenApiSchema, type OpenApiSchemaBundle, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type OutputSchemaOptions, type PaginatedResult, type ParamNode, type ParamProxy, type ParamProxyRoot, 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 RelationSelection, 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, createParamProxy, 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, hasExpressionDispatcher, hasMany, hasOne, hasOperandDispatcher, 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
|
@@ -3872,6 +3872,12 @@ interface OpenApiSchema {
|
|
|
3872
3872
|
required: string[];
|
|
3873
3873
|
description?: string;
|
|
3874
3874
|
}
|
|
3875
|
+
/**
|
|
3876
|
+
* OpenAPI 3.1 components container
|
|
3877
|
+
*/
|
|
3878
|
+
interface OpenApiComponents {
|
|
3879
|
+
schemas: Record<string, OpenApiSchema>;
|
|
3880
|
+
}
|
|
3875
3881
|
/**
|
|
3876
3882
|
* Column-level schema flags
|
|
3877
3883
|
*/
|
|
@@ -3895,9 +3901,21 @@ interface OutputSchemaOptions extends ColumnSchemaOptions {
|
|
|
3895
3901
|
mode?: 'selected' | 'full';
|
|
3896
3902
|
/** Maximum depth for relation recursion */
|
|
3897
3903
|
maxDepth?: number;
|
|
3904
|
+
/** Inline schemas vs $ref components */
|
|
3905
|
+
refMode?: 'inline' | 'components';
|
|
3906
|
+
/** Selected schemas inline vs components when refMode is components */
|
|
3907
|
+
selectedRefMode?: 'inline' | 'components';
|
|
3908
|
+
/** Customize component names */
|
|
3909
|
+
componentName?: (table: TableDef) => string;
|
|
3910
|
+
/** Emit output schema as a component $ref when refMode is components */
|
|
3911
|
+
outputAsRef?: boolean;
|
|
3898
3912
|
}
|
|
3899
3913
|
type InputRelationMode = 'ids' | 'objects' | 'mixed';
|
|
3900
3914
|
type InputSchemaMode = 'create' | 'update';
|
|
3915
|
+
interface RelationSelection {
|
|
3916
|
+
pick?: string[];
|
|
3917
|
+
omit?: string[];
|
|
3918
|
+
}
|
|
3901
3919
|
/**
|
|
3902
3920
|
* Input schema generation options (write payloads)
|
|
3903
3921
|
*/
|
|
@@ -3916,6 +3934,10 @@ interface InputSchemaOptions extends ColumnSchemaOptions {
|
|
|
3916
3934
|
excludePrimaryKey?: boolean;
|
|
3917
3935
|
/** Require primary key columns on update payloads */
|
|
3918
3936
|
requirePrimaryKey?: boolean;
|
|
3937
|
+
/** Remove relation foreign keys pointing to the parent from nested inputs */
|
|
3938
|
+
excludeRelationForeignKeys?: boolean;
|
|
3939
|
+
/** Per-relation field selection for nested inputs */
|
|
3940
|
+
relationSelections?: Record<string, RelationSelection>;
|
|
3919
3941
|
}
|
|
3920
3942
|
/**
|
|
3921
3943
|
* Schema generation options
|
|
@@ -3928,9 +3950,10 @@ interface SchemaOptions extends OutputSchemaOptions {
|
|
|
3928
3950
|
* Input + output schema bundle
|
|
3929
3951
|
*/
|
|
3930
3952
|
interface OpenApiSchemaBundle {
|
|
3931
|
-
output: OpenApiSchema;
|
|
3953
|
+
output: OpenApiSchema | JsonSchemaProperty;
|
|
3932
3954
|
input?: OpenApiSchema;
|
|
3933
3955
|
parameters?: OpenApiParameter[];
|
|
3956
|
+
components?: OpenApiComponents;
|
|
3934
3957
|
}
|
|
3935
3958
|
/**
|
|
3936
3959
|
* Schema extraction context for handling circular references
|
|
@@ -3944,6 +3967,8 @@ interface SchemaExtractionContext {
|
|
|
3944
3967
|
depth: number;
|
|
3945
3968
|
/** Maximum depth to recurse */
|
|
3946
3969
|
maxDepth: number;
|
|
3970
|
+
/** Component registry when using refMode=components */
|
|
3971
|
+
components?: OpenApiComponents;
|
|
3947
3972
|
}
|
|
3948
3973
|
|
|
3949
3974
|
/**
|
|
@@ -7231,4 +7256,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
7231
7256
|
*/
|
|
7232
7257
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
7233
7258
|
|
|
7234
|
-
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, type ParamNode, type ParamProxy, type ParamProxyRoot, 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, createParamProxy, 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, hasExpressionDispatcher, hasMany, hasOne, hasOperandDispatcher, 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 };
|
|
7259
|
+
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 OpenApiComponents, type OpenApiParameter, type OpenApiSchema, type OpenApiSchemaBundle, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, type OutputSchemaOptions, type PaginatedResult, type ParamNode, type ParamProxy, type ParamProxyRoot, 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 RelationSelection, 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, createParamProxy, 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, hasExpressionDispatcher, hasMany, hasOne, hasOperandDispatcher, 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.js
CHANGED
|
@@ -6963,47 +6963,52 @@ var getTemporalFormat = (sqlType) => {
|
|
|
6963
6963
|
}
|
|
6964
6964
|
};
|
|
6965
6965
|
|
|
6966
|
-
// src/openapi/schema-extractor.ts
|
|
6967
|
-
var
|
|
6968
|
-
var
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6966
|
+
// src/openapi/schema-extractor-utils.ts
|
|
6967
|
+
var hasComputedProjection = (projectionNodes) => Boolean(projectionNodes && projectionNodes.some((node) => node.type !== "Column"));
|
|
6968
|
+
var shouldUseSelectedSchema = (options, plan, projectionNodes) => {
|
|
6969
|
+
if (!plan || options.mode !== "selected") return false;
|
|
6970
|
+
if (hasComputedProjection(projectionNodes)) return false;
|
|
6971
|
+
if (options.refMode === "components" && options.selectedRefMode !== "components") return false;
|
|
6972
|
+
return true;
|
|
6973
|
+
};
|
|
6974
|
+
var resolveComponentName = (table, options) => options.componentName ? options.componentName(table) : table.name;
|
|
6975
|
+
var normalizeColumns = (columns) => Array.from(new Set(columns)).sort((a, b) => a.localeCompare(b));
|
|
6976
|
+
var buildSelectionSignature = (plan) => {
|
|
6977
|
+
const relations = plan.relations.map((relation) => ({
|
|
6978
|
+
name: relation.name,
|
|
6979
|
+
columns: normalizeColumns(relation.columns)
|
|
6980
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
6981
|
+
return JSON.stringify({
|
|
6982
|
+
root: normalizeColumns(plan.rootColumns),
|
|
6983
|
+
relations
|
|
6984
|
+
});
|
|
6985
|
+
};
|
|
6986
|
+
var hashString = (value) => {
|
|
6987
|
+
let hash = 2166136261;
|
|
6988
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
6989
|
+
hash ^= value.charCodeAt(i);
|
|
6990
|
+
hash = hash * 16777619 >>> 0;
|
|
6975
6991
|
}
|
|
6976
|
-
|
|
6977
|
-
const input = extractInputSchema(table, inputContext, inputOptions);
|
|
6978
|
-
return { output, input };
|
|
6992
|
+
return hash.toString(16).padStart(8, "0");
|
|
6979
6993
|
};
|
|
6980
|
-
var
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
includeEnums: input.includeEnums ?? options.includeEnums,
|
|
6999
|
-
includeExamples: input.includeExamples ?? options.includeExamples,
|
|
7000
|
-
includeDefaults: input.includeDefaults ?? options.includeDefaults,
|
|
7001
|
-
includeNullable: input.includeNullable ?? options.includeNullable,
|
|
7002
|
-
maxDepth: input.maxDepth ?? options.maxDepth ?? DEFAULT_MAX_DEPTH,
|
|
7003
|
-
omitReadOnly: input.omitReadOnly ?? true,
|
|
7004
|
-
excludePrimaryKey: input.excludePrimaryKey ?? false,
|
|
7005
|
-
requirePrimaryKey: input.requirePrimaryKey ?? mode === "update"
|
|
7006
|
-
};
|
|
6994
|
+
var resolveSelectedComponentName = (table, plan, options) => {
|
|
6995
|
+
const base = resolveComponentName(table, options);
|
|
6996
|
+
const signature = buildSelectionSignature(plan);
|
|
6997
|
+
return `${base}__sel_${hashString(signature)}`;
|
|
6998
|
+
};
|
|
6999
|
+
var ensureComponentRef = (table, componentName, context, schemaFactory) => {
|
|
7000
|
+
if (context.components && !context.components.schemas[componentName]) {
|
|
7001
|
+
if (!context.visitedTables.has(table.name)) {
|
|
7002
|
+
context.components.schemas[componentName] = schemaFactory();
|
|
7003
|
+
}
|
|
7004
|
+
}
|
|
7005
|
+
return { $ref: `#/components/schemas/${componentName}` };
|
|
7006
|
+
};
|
|
7007
|
+
var registerComponentSchema = (name, schema, context) => {
|
|
7008
|
+
if (!context.components) return;
|
|
7009
|
+
if (!context.components.schemas[name]) {
|
|
7010
|
+
context.components.schemas[name] = schema;
|
|
7011
|
+
}
|
|
7007
7012
|
};
|
|
7008
7013
|
var createContext = (maxDepth) => ({
|
|
7009
7014
|
visitedTables: /* @__PURE__ */ new Set(),
|
|
@@ -7011,19 +7016,18 @@ var createContext = (maxDepth) => ({
|
|
|
7011
7016
|
depth: 0,
|
|
7012
7017
|
maxDepth
|
|
7013
7018
|
});
|
|
7014
|
-
var
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
}
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
};
|
|
7019
|
+
var buildCircularReferenceSchema = (tableName, kind) => ({
|
|
7020
|
+
type: "object",
|
|
7021
|
+
properties: {
|
|
7022
|
+
_ref: {
|
|
7023
|
+
type: "string",
|
|
7024
|
+
description: `Circular ${kind} reference to ${tableName}`
|
|
7025
|
+
}
|
|
7026
|
+
},
|
|
7027
|
+
required: []
|
|
7028
|
+
});
|
|
7029
|
+
|
|
7030
|
+
// src/openapi/schema-extractor-input.ts
|
|
7027
7031
|
var extractInputSchema = (table, context, options) => {
|
|
7028
7032
|
const cacheKey = `${table.name}:${options.mode ?? "create"}`;
|
|
7029
7033
|
if (context.schemaCache.has(cacheKey)) {
|
|
@@ -7051,6 +7055,7 @@ var extractInputSchema = (table, context, options) => {
|
|
|
7051
7055
|
if (options.includeRelations && context.depth < context.maxDepth) {
|
|
7052
7056
|
for (const [relationName, relation] of Object.entries(table.relations)) {
|
|
7053
7057
|
properties[relationName] = extractInputRelationSchema(
|
|
7058
|
+
relationName,
|
|
7054
7059
|
relation,
|
|
7055
7060
|
{ ...context, depth: context.depth + 1 },
|
|
7056
7061
|
options
|
|
@@ -7085,7 +7090,7 @@ var buildPrimaryKeySchema = (table, options) => {
|
|
|
7085
7090
|
}
|
|
7086
7091
|
return mapColumnType(column, options);
|
|
7087
7092
|
};
|
|
7088
|
-
var extractInputRelationSchema = (relation, context, options) => {
|
|
7093
|
+
var extractInputRelationSchema = (relationName, relation, context, options) => {
|
|
7089
7094
|
const { type: relationType, isNullable } = mapRelationType(relation.type);
|
|
7090
7095
|
const relationMode = options.relationMode ?? "mixed";
|
|
7091
7096
|
const allowIds = relationMode !== "objects";
|
|
@@ -7095,7 +7100,11 @@ var extractInputRelationSchema = (relation, context, options) => {
|
|
|
7095
7100
|
variants.push(buildPrimaryKeySchema(relation.target, options));
|
|
7096
7101
|
}
|
|
7097
7102
|
if (allowObjects) {
|
|
7098
|
-
|
|
7103
|
+
let targetSchema = extractInputSchema(relation.target, context, options);
|
|
7104
|
+
targetSchema = applyRelationSelection(targetSchema, options.relationSelections?.[relationName]);
|
|
7105
|
+
if (options.excludeRelationForeignKeys && isRelationForeignKeyToParent(relation)) {
|
|
7106
|
+
targetSchema = removeForeignKey(targetSchema, relation.foreignKey);
|
|
7107
|
+
}
|
|
7099
7108
|
variants.push(targetSchema);
|
|
7100
7109
|
}
|
|
7101
7110
|
const itemSchema = variants.length === 1 ? variants[0] : { anyOf: variants };
|
|
@@ -7111,6 +7120,55 @@ var extractInputRelationSchema = (relation, context, options) => {
|
|
|
7111
7120
|
nullable: isNullable
|
|
7112
7121
|
};
|
|
7113
7122
|
};
|
|
7123
|
+
var applyRelationSelection = (schema, selection) => {
|
|
7124
|
+
if (!selection || selection.pick === void 0 && selection.omit === void 0) {
|
|
7125
|
+
return schema;
|
|
7126
|
+
}
|
|
7127
|
+
const hasPick = selection.pick !== void 0;
|
|
7128
|
+
const pick = hasPick ? new Set(selection.pick ?? []) : void 0;
|
|
7129
|
+
const omit = selection.omit !== void 0 ? new Set(selection.omit ?? []) : void 0;
|
|
7130
|
+
const properties = Object.entries(schema.properties).reduce(
|
|
7131
|
+
(acc, [key, value]) => {
|
|
7132
|
+
if (pick && !pick.has(key)) return acc;
|
|
7133
|
+
if (omit && omit.has(key)) return acc;
|
|
7134
|
+
acc[key] = value;
|
|
7135
|
+
return acc;
|
|
7136
|
+
},
|
|
7137
|
+
{}
|
|
7138
|
+
);
|
|
7139
|
+
const required = schema.required.filter((name) => properties[name] !== void 0);
|
|
7140
|
+
return {
|
|
7141
|
+
...schema,
|
|
7142
|
+
properties,
|
|
7143
|
+
required
|
|
7144
|
+
};
|
|
7145
|
+
};
|
|
7146
|
+
var removeForeignKey = (schema, foreignKey) => {
|
|
7147
|
+
if (!foreignKey || !schema.properties[foreignKey]) return schema;
|
|
7148
|
+
const properties = { ...schema.properties };
|
|
7149
|
+
delete properties[foreignKey];
|
|
7150
|
+
const required = schema.required.filter((name) => name !== foreignKey);
|
|
7151
|
+
return {
|
|
7152
|
+
...schema,
|
|
7153
|
+
properties,
|
|
7154
|
+
required
|
|
7155
|
+
};
|
|
7156
|
+
};
|
|
7157
|
+
var isRelationForeignKeyToParent = (relation) => {
|
|
7158
|
+
return relation.type === RelationKinds.HasMany || relation.type === RelationKinds.HasOne;
|
|
7159
|
+
};
|
|
7160
|
+
|
|
7161
|
+
// src/openapi/schema-extractor-output.ts
|
|
7162
|
+
var extractOutputSchema = (table, plan, projectionNodes, context, options) => {
|
|
7163
|
+
const hasComputedFields = hasComputedProjection(projectionNodes);
|
|
7164
|
+
if (hasComputedFields) {
|
|
7165
|
+
return extractFromProjectionNodes(table, projectionNodes, context, options);
|
|
7166
|
+
}
|
|
7167
|
+
if (shouldUseSelectedSchema(options, plan, projectionNodes)) {
|
|
7168
|
+
return extractSelectedSchema(table, plan, context, options);
|
|
7169
|
+
}
|
|
7170
|
+
return extractFullTableSchema(table, context, options);
|
|
7171
|
+
};
|
|
7114
7172
|
var extractFromProjectionNodes = (table, projectionNodes, context, options) => {
|
|
7115
7173
|
const properties = {};
|
|
7116
7174
|
const required = [];
|
|
@@ -7316,6 +7374,52 @@ var extractFullTableSchema = (table, context, options) => {
|
|
|
7316
7374
|
var extractRelationSchema = (relation, relationPlan, selectedColumns, context, options) => {
|
|
7317
7375
|
const targetTable = relation.target;
|
|
7318
7376
|
const { type: relationType, isNullable } = mapRelationType(relation.type);
|
|
7377
|
+
if (options.refMode === "components" && context.components) {
|
|
7378
|
+
if (relationPlan && selectedColumns.length > 0 && options.selectedRefMode === "components") {
|
|
7379
|
+
const plan = {
|
|
7380
|
+
rootTable: targetTable.name,
|
|
7381
|
+
rootPrimaryKey: relationPlan.targetPrimaryKey,
|
|
7382
|
+
rootColumns: selectedColumns,
|
|
7383
|
+
relations: []
|
|
7384
|
+
};
|
|
7385
|
+
const componentName2 = resolveSelectedComponentName(targetTable, plan, options);
|
|
7386
|
+
const ref2 = ensureComponentRef(
|
|
7387
|
+
targetTable,
|
|
7388
|
+
componentName2,
|
|
7389
|
+
context,
|
|
7390
|
+
() => extractSelectedSchema(targetTable, plan, context, options)
|
|
7391
|
+
);
|
|
7392
|
+
if (relationType === "array") {
|
|
7393
|
+
return {
|
|
7394
|
+
type: "array",
|
|
7395
|
+
items: ref2,
|
|
7396
|
+
nullable: isNullable
|
|
7397
|
+
};
|
|
7398
|
+
}
|
|
7399
|
+
return {
|
|
7400
|
+
...ref2,
|
|
7401
|
+
nullable: isNullable
|
|
7402
|
+
};
|
|
7403
|
+
}
|
|
7404
|
+
const componentName = resolveComponentName(targetTable, options);
|
|
7405
|
+
const ref = ensureComponentRef(
|
|
7406
|
+
targetTable,
|
|
7407
|
+
componentName,
|
|
7408
|
+
context,
|
|
7409
|
+
() => extractFullTableSchema(targetTable, context, options)
|
|
7410
|
+
);
|
|
7411
|
+
if (relationType === "array") {
|
|
7412
|
+
return {
|
|
7413
|
+
type: "array",
|
|
7414
|
+
items: ref,
|
|
7415
|
+
nullable: isNullable
|
|
7416
|
+
};
|
|
7417
|
+
}
|
|
7418
|
+
return {
|
|
7419
|
+
...ref,
|
|
7420
|
+
nullable: isNullable
|
|
7421
|
+
};
|
|
7422
|
+
}
|
|
7319
7423
|
let targetSchema;
|
|
7320
7424
|
if (relationPlan && selectedColumns.length > 0) {
|
|
7321
7425
|
const plan = {
|
|
@@ -7343,16 +7447,76 @@ var extractRelationSchema = (relation, relationPlan, selectedColumns, context, o
|
|
|
7343
7447
|
description: targetSchema.description
|
|
7344
7448
|
};
|
|
7345
7449
|
};
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7450
|
+
|
|
7451
|
+
// src/openapi/schema-extractor.ts
|
|
7452
|
+
var DEFAULT_MAX_DEPTH = 5;
|
|
7453
|
+
var extractSchema = (table, plan, projectionNodes, options = {}) => {
|
|
7454
|
+
const outputOptions = resolveOutputOptions(options);
|
|
7455
|
+
const outputContext = createContext(outputOptions.maxDepth ?? DEFAULT_MAX_DEPTH);
|
|
7456
|
+
if (outputOptions.refMode === "components") {
|
|
7457
|
+
outputContext.components = { schemas: {} };
|
|
7458
|
+
}
|
|
7459
|
+
const outputSchema = extractOutputSchema(table, plan, projectionNodes, outputContext, outputOptions);
|
|
7460
|
+
let output = outputSchema;
|
|
7461
|
+
const useSelected = shouldUseSelectedSchema(outputOptions, plan, projectionNodes);
|
|
7462
|
+
const hasComputedFields = hasComputedProjection(projectionNodes);
|
|
7463
|
+
const canUseComponents = outputOptions.refMode === "components" && outputContext.components && !hasComputedFields;
|
|
7464
|
+
if (canUseComponents) {
|
|
7465
|
+
const componentName = useSelected && plan ? resolveSelectedComponentName(table, plan, outputOptions) : resolveComponentName(table, outputOptions);
|
|
7466
|
+
registerComponentSchema(componentName, outputSchema, outputContext);
|
|
7467
|
+
if (outputOptions.outputAsRef) {
|
|
7468
|
+
output = { $ref: `#/components/schemas/${componentName}` };
|
|
7352
7469
|
}
|
|
7353
|
-
}
|
|
7354
|
-
|
|
7470
|
+
}
|
|
7471
|
+
const inputOptions = resolveInputOptions(options);
|
|
7472
|
+
if (!inputOptions) {
|
|
7473
|
+
return {
|
|
7474
|
+
output,
|
|
7475
|
+
components: outputContext.components && Object.keys(outputContext.components.schemas).length ? outputContext.components : void 0
|
|
7476
|
+
};
|
|
7477
|
+
}
|
|
7478
|
+
const inputContext = createContext(inputOptions.maxDepth ?? DEFAULT_MAX_DEPTH);
|
|
7479
|
+
const input = extractInputSchema(table, inputContext, inputOptions);
|
|
7480
|
+
return {
|
|
7481
|
+
output,
|
|
7482
|
+
input,
|
|
7483
|
+
components: outputContext.components && Object.keys(outputContext.components.schemas).length ? outputContext.components : void 0
|
|
7484
|
+
};
|
|
7485
|
+
};
|
|
7486
|
+
var resolveOutputOptions = (options) => ({
|
|
7487
|
+
mode: options.mode ?? "full",
|
|
7488
|
+
includeDescriptions: options.includeDescriptions,
|
|
7489
|
+
includeEnums: options.includeEnums,
|
|
7490
|
+
includeExamples: options.includeExamples,
|
|
7491
|
+
includeDefaults: options.includeDefaults,
|
|
7492
|
+
includeNullable: options.includeNullable,
|
|
7493
|
+
maxDepth: options.maxDepth ?? DEFAULT_MAX_DEPTH,
|
|
7494
|
+
refMode: options.refMode ?? "inline",
|
|
7495
|
+
selectedRefMode: options.selectedRefMode ?? "inline",
|
|
7496
|
+
componentName: options.componentName,
|
|
7497
|
+
outputAsRef: options.outputAsRef ?? false
|
|
7355
7498
|
});
|
|
7499
|
+
var resolveInputOptions = (options) => {
|
|
7500
|
+
if (options.input === false) return void 0;
|
|
7501
|
+
const input = options.input ?? {};
|
|
7502
|
+
const mode = input.mode ?? "create";
|
|
7503
|
+
return {
|
|
7504
|
+
mode,
|
|
7505
|
+
includeRelations: input.includeRelations ?? true,
|
|
7506
|
+
relationMode: input.relationMode ?? "mixed",
|
|
7507
|
+
includeDescriptions: input.includeDescriptions ?? options.includeDescriptions,
|
|
7508
|
+
includeEnums: input.includeEnums ?? options.includeEnums,
|
|
7509
|
+
includeExamples: input.includeExamples ?? options.includeExamples,
|
|
7510
|
+
includeDefaults: input.includeDefaults ?? options.includeDefaults,
|
|
7511
|
+
includeNullable: input.includeNullable ?? options.includeNullable,
|
|
7512
|
+
maxDepth: input.maxDepth ?? options.maxDepth ?? DEFAULT_MAX_DEPTH,
|
|
7513
|
+
omitReadOnly: input.omitReadOnly ?? true,
|
|
7514
|
+
excludePrimaryKey: input.excludePrimaryKey ?? false,
|
|
7515
|
+
requirePrimaryKey: input.requirePrimaryKey ?? mode === "update",
|
|
7516
|
+
excludeRelationForeignKeys: input.excludeRelationForeignKeys ?? false,
|
|
7517
|
+
relationSelections: input.relationSelections
|
|
7518
|
+
};
|
|
7519
|
+
};
|
|
7356
7520
|
var schemaToJson = (schema, pretty = false) => {
|
|
7357
7521
|
return JSON.stringify(schema, null, pretty ? 2 : 0);
|
|
7358
7522
|
};
|