metal-orm 1.0.51 → 1.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -14
- package/dist/index.cjs +37 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.js +36 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -2
- package/src/orm/jsonify.ts +27 -0
- package/src/orm/orm-session.ts +28 -22
- package/src/orm/save-graph-types.ts +57 -0
- package/src/orm/save-graph.ts +141 -105
package/dist/index.d.cts
CHANGED
|
@@ -2989,8 +2989,45 @@ interface HydrationContext<E extends DomainEvent = AnyDomainEvent> {
|
|
|
2989
2989
|
interface SaveGraphOptions {
|
|
2990
2990
|
/** Remove existing collection members that are not present in the payload */
|
|
2991
2991
|
pruneMissing?: boolean;
|
|
2992
|
+
/**
|
|
2993
|
+
* Coerce JSON-friendly input values into DB-friendly primitives.
|
|
2994
|
+
* Currently:
|
|
2995
|
+
* - Date -> ISO string (for DATE/DATETIME/TIMESTAMP/TIMESTAMPTZ columns)
|
|
2996
|
+
*/
|
|
2997
|
+
coerce?: 'json';
|
|
2992
2998
|
}
|
|
2993
2999
|
|
|
3000
|
+
type AnyId = number | string;
|
|
3001
|
+
type AnyFn = (...args: unknown[]) => unknown;
|
|
3002
|
+
type RelationWrapper = HasManyCollection<unknown> | HasOneReference<unknown> | BelongsToReference<unknown> | ManyToManyCollection<unknown>;
|
|
3003
|
+
type FunctionKeys<T> = {
|
|
3004
|
+
[K in keyof T & string]-?: T[K] extends AnyFn ? K : never;
|
|
3005
|
+
}[keyof T & string];
|
|
3006
|
+
type RelationKeys<T> = {
|
|
3007
|
+
[K in keyof T & string]-?: NonNullable<T[K]> extends RelationWrapper ? K : never;
|
|
3008
|
+
}[keyof T & string];
|
|
3009
|
+
type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys<T>>;
|
|
3010
|
+
type SaveGraphJsonScalar<T> = T extends Date ? string : T;
|
|
3011
|
+
/**
|
|
3012
|
+
* Input scalar type that accepts JSON-friendly values for common runtime types.
|
|
3013
|
+
* Currently:
|
|
3014
|
+
* - Date fields accept `Date | string` (ISO string recommended)
|
|
3015
|
+
*/
|
|
3016
|
+
type SaveGraphInputScalar<T> = T extends Date ? Date | string : T;
|
|
3017
|
+
type ColumnInput$1<TEntity> = {
|
|
3018
|
+
[K in ColumnKeys<TEntity>]?: SaveGraphInputScalar<TEntity[K]>;
|
|
3019
|
+
};
|
|
3020
|
+
type RelationInputValue<T> = T extends HasManyCollection<infer C> ? Array<SaveGraphInputPayload<C> | AnyId> : T extends HasOneReference<infer C> ? SaveGraphInputPayload<C> | AnyId | null : T extends BelongsToReference<infer P> ? SaveGraphInputPayload<P> | AnyId | null : T extends ManyToManyCollection<infer Tgt> ? Array<SaveGraphInputPayload<Tgt> | AnyId> : never;
|
|
3021
|
+
type RelationInput<TEntity> = {
|
|
3022
|
+
[K in RelationKeys<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
|
|
3023
|
+
};
|
|
3024
|
+
/**
|
|
3025
|
+
* Typed payload accepted by `OrmSession.saveGraph`:
|
|
3026
|
+
* - Only entity scalar keys + relation keys are accepted.
|
|
3027
|
+
* - Scalars can use JSON-friendly values (e.g., Date fields accept ISO strings).
|
|
3028
|
+
*/
|
|
3029
|
+
type SaveGraphInputPayload<TEntity> = ColumnInput$1<TEntity> & RelationInput<TEntity>;
|
|
3030
|
+
|
|
2994
3031
|
/**
|
|
2995
3032
|
* Interface for ORM interceptors that allow hooking into the flush lifecycle.
|
|
2996
3033
|
*/
|
|
@@ -3159,7 +3196,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
3159
3196
|
* @param options - Graph save options
|
|
3160
3197
|
* @returns The root entity instance
|
|
3161
3198
|
*/
|
|
3162
|
-
saveGraph<TCtor extends EntityConstructor<object>>(entityClass: TCtor, payload:
|
|
3199
|
+
saveGraph<TCtor extends EntityConstructor<object>>(entityClass: TCtor, payload: SaveGraphInputPayload<InstanceType<TCtor>>, options?: SaveGraphOptions & {
|
|
3163
3200
|
transactional?: boolean;
|
|
3164
3201
|
}): Promise<InstanceType<TCtor>>;
|
|
3165
3202
|
/**
|
|
@@ -5254,6 +5291,21 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
|
|
|
5254
5291
|
*/
|
|
5255
5292
|
declare function executeHydratedWithContexts<TTable extends TableDef>(_execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
5256
5293
|
|
|
5294
|
+
type JsonifyScalar<T> = T extends Date ? string : T;
|
|
5295
|
+
/**
|
|
5296
|
+
* Shallow JSON-friendly mapping:
|
|
5297
|
+
* - Date -> ISO string
|
|
5298
|
+
* - Everything else unchanged
|
|
5299
|
+
*/
|
|
5300
|
+
type Jsonify<T> = {
|
|
5301
|
+
[K in keyof T]: JsonifyScalar<T[K]>;
|
|
5302
|
+
};
|
|
5303
|
+
/**
|
|
5304
|
+
* Creates a shallow, JSON-friendly copy of an object by converting `Date` values to ISO strings.
|
|
5305
|
+
* This intentionally does not deep-walk nested objects/relations.
|
|
5306
|
+
*/
|
|
5307
|
+
declare const jsonify: <T extends object>(value: T) => Jsonify<T>;
|
|
5308
|
+
|
|
5257
5309
|
/**
|
|
5258
5310
|
* Context object provided by standard decorators in newer TypeScript versions.
|
|
5259
5311
|
*/
|
|
@@ -5553,4 +5605,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
5553
5605
|
*/
|
|
5554
5606
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
5555
5607
|
|
|
5556
|
-
export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, 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 HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, 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, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, aliasRef, and, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bootstrapEntities, caseWhen, cast, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getSchemaIntrospector, getTableDefFromEntity, groupConcat, gt, gte, hasMany, hasOne, hydrateRows, inList, inSubquery, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, renderTypeWithArgs, repeat, replace, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, sel, selectFromEntity, sign, sin, space, sqrt, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
5608
|
+
export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, 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 HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, 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, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, aliasRef, and, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bootstrapEntities, caseWhen, cast, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getSchemaIntrospector, getTableDefFromEntity, groupConcat, gt, gte, hasMany, hasOne, hydrateRows, inList, inSubquery, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonPath, jsonify, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, renderTypeWithArgs, repeat, replace, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, sel, selectFromEntity, sign, sin, space, sqrt, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
package/dist/index.d.ts
CHANGED
|
@@ -2989,8 +2989,45 @@ interface HydrationContext<E extends DomainEvent = AnyDomainEvent> {
|
|
|
2989
2989
|
interface SaveGraphOptions {
|
|
2990
2990
|
/** Remove existing collection members that are not present in the payload */
|
|
2991
2991
|
pruneMissing?: boolean;
|
|
2992
|
+
/**
|
|
2993
|
+
* Coerce JSON-friendly input values into DB-friendly primitives.
|
|
2994
|
+
* Currently:
|
|
2995
|
+
* - Date -> ISO string (for DATE/DATETIME/TIMESTAMP/TIMESTAMPTZ columns)
|
|
2996
|
+
*/
|
|
2997
|
+
coerce?: 'json';
|
|
2992
2998
|
}
|
|
2993
2999
|
|
|
3000
|
+
type AnyId = number | string;
|
|
3001
|
+
type AnyFn = (...args: unknown[]) => unknown;
|
|
3002
|
+
type RelationWrapper = HasManyCollection<unknown> | HasOneReference<unknown> | BelongsToReference<unknown> | ManyToManyCollection<unknown>;
|
|
3003
|
+
type FunctionKeys<T> = {
|
|
3004
|
+
[K in keyof T & string]-?: T[K] extends AnyFn ? K : never;
|
|
3005
|
+
}[keyof T & string];
|
|
3006
|
+
type RelationKeys<T> = {
|
|
3007
|
+
[K in keyof T & string]-?: NonNullable<T[K]> extends RelationWrapper ? K : never;
|
|
3008
|
+
}[keyof T & string];
|
|
3009
|
+
type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys<T>>;
|
|
3010
|
+
type SaveGraphJsonScalar<T> = T extends Date ? string : T;
|
|
3011
|
+
/**
|
|
3012
|
+
* Input scalar type that accepts JSON-friendly values for common runtime types.
|
|
3013
|
+
* Currently:
|
|
3014
|
+
* - Date fields accept `Date | string` (ISO string recommended)
|
|
3015
|
+
*/
|
|
3016
|
+
type SaveGraphInputScalar<T> = T extends Date ? Date | string : T;
|
|
3017
|
+
type ColumnInput$1<TEntity> = {
|
|
3018
|
+
[K in ColumnKeys<TEntity>]?: SaveGraphInputScalar<TEntity[K]>;
|
|
3019
|
+
};
|
|
3020
|
+
type RelationInputValue<T> = T extends HasManyCollection<infer C> ? Array<SaveGraphInputPayload<C> | AnyId> : T extends HasOneReference<infer C> ? SaveGraphInputPayload<C> | AnyId | null : T extends BelongsToReference<infer P> ? SaveGraphInputPayload<P> | AnyId | null : T extends ManyToManyCollection<infer Tgt> ? Array<SaveGraphInputPayload<Tgt> | AnyId> : never;
|
|
3021
|
+
type RelationInput<TEntity> = {
|
|
3022
|
+
[K in RelationKeys<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
|
|
3023
|
+
};
|
|
3024
|
+
/**
|
|
3025
|
+
* Typed payload accepted by `OrmSession.saveGraph`:
|
|
3026
|
+
* - Only entity scalar keys + relation keys are accepted.
|
|
3027
|
+
* - Scalars can use JSON-friendly values (e.g., Date fields accept ISO strings).
|
|
3028
|
+
*/
|
|
3029
|
+
type SaveGraphInputPayload<TEntity> = ColumnInput$1<TEntity> & RelationInput<TEntity>;
|
|
3030
|
+
|
|
2994
3031
|
/**
|
|
2995
3032
|
* Interface for ORM interceptors that allow hooking into the flush lifecycle.
|
|
2996
3033
|
*/
|
|
@@ -3159,7 +3196,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
3159
3196
|
* @param options - Graph save options
|
|
3160
3197
|
* @returns The root entity instance
|
|
3161
3198
|
*/
|
|
3162
|
-
saveGraph<TCtor extends EntityConstructor<object>>(entityClass: TCtor, payload:
|
|
3199
|
+
saveGraph<TCtor extends EntityConstructor<object>>(entityClass: TCtor, payload: SaveGraphInputPayload<InstanceType<TCtor>>, options?: SaveGraphOptions & {
|
|
3163
3200
|
transactional?: boolean;
|
|
3164
3201
|
}): Promise<InstanceType<TCtor>>;
|
|
3165
3202
|
/**
|
|
@@ -5254,6 +5291,21 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
|
|
|
5254
5291
|
*/
|
|
5255
5292
|
declare function executeHydratedWithContexts<TTable extends TableDef>(_execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
5256
5293
|
|
|
5294
|
+
type JsonifyScalar<T> = T extends Date ? string : T;
|
|
5295
|
+
/**
|
|
5296
|
+
* Shallow JSON-friendly mapping:
|
|
5297
|
+
* - Date -> ISO string
|
|
5298
|
+
* - Everything else unchanged
|
|
5299
|
+
*/
|
|
5300
|
+
type Jsonify<T> = {
|
|
5301
|
+
[K in keyof T]: JsonifyScalar<T[K]>;
|
|
5302
|
+
};
|
|
5303
|
+
/**
|
|
5304
|
+
* Creates a shallow, JSON-friendly copy of an object by converting `Date` values to ISO strings.
|
|
5305
|
+
* This intentionally does not deep-walk nested objects/relations.
|
|
5306
|
+
*/
|
|
5307
|
+
declare const jsonify: <T extends object>(value: T) => Jsonify<T>;
|
|
5308
|
+
|
|
5257
5309
|
/**
|
|
5258
5310
|
* Context object provided by standard decorators in newer TypeScript versions.
|
|
5259
5311
|
*/
|
|
@@ -5553,4 +5605,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
5553
5605
|
*/
|
|
5554
5606
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
5555
5607
|
|
|
5556
|
-
export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, 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 HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, 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, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, aliasRef, and, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bootstrapEntities, caseWhen, cast, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getSchemaIntrospector, getTableDefFromEntity, groupConcat, gt, gte, hasMany, hasOne, hydrateRows, inList, inSubquery, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, renderTypeWithArgs, repeat, replace, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, sel, selectFromEntity, sign, sin, space, sqrt, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
5608
|
+
export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, 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 HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, 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, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, aliasRef, and, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bootstrapEntities, caseWhen, cast, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getSchemaIntrospector, getTableDefFromEntity, groupConcat, gt, gte, hasMany, hasOne, hydrateRows, inList, inSubquery, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonPath, jsonify, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, renderTypeWithArgs, repeat, replace, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, sel, selectFromEntity, sign, sin, space, sqrt, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
package/dist/index.js
CHANGED
|
@@ -9301,18 +9301,30 @@ var runInTransaction = async (executor, action) => {
|
|
|
9301
9301
|
|
|
9302
9302
|
// src/orm/save-graph.ts
|
|
9303
9303
|
var toKey8 = (value) => value === null || value === void 0 ? "" : String(value);
|
|
9304
|
-
var
|
|
9304
|
+
var coerceColumnValue = (table, columnName, value, options) => {
|
|
9305
|
+
if (options.coerce !== "json") return value;
|
|
9306
|
+
if (value === null || value === void 0) return value;
|
|
9307
|
+
const column = table.columns[columnName];
|
|
9308
|
+
if (!column) return value;
|
|
9309
|
+
const normalized = normalizeColumnType(column.type);
|
|
9310
|
+
const isDateLikeColumn = normalized === "date" || normalized === "datetime" || normalized === "timestamp" || normalized === "timestamptz";
|
|
9311
|
+
if (isDateLikeColumn && value instanceof Date) {
|
|
9312
|
+
return value.toISOString();
|
|
9313
|
+
}
|
|
9314
|
+
return value;
|
|
9315
|
+
};
|
|
9316
|
+
var pickColumns = (table, payload, options) => {
|
|
9305
9317
|
const columns = {};
|
|
9306
9318
|
for (const key of Object.keys(table.columns)) {
|
|
9307
9319
|
if (payload[key] !== void 0) {
|
|
9308
|
-
columns[key] = payload[key];
|
|
9320
|
+
columns[key] = coerceColumnValue(table, key, payload[key], options);
|
|
9309
9321
|
}
|
|
9310
9322
|
}
|
|
9311
9323
|
return columns;
|
|
9312
9324
|
};
|
|
9313
|
-
var ensureEntity = (session, table, payload) => {
|
|
9325
|
+
var ensureEntity = (session, table, payload, options) => {
|
|
9314
9326
|
const pk = findPrimaryKey(table);
|
|
9315
|
-
const row = pickColumns(table, payload);
|
|
9327
|
+
const row = pickColumns(table, payload, options);
|
|
9316
9328
|
const pkValue = payload[pk];
|
|
9317
9329
|
if (pkValue !== void 0 && pkValue !== null) {
|
|
9318
9330
|
const tracked = session.getEntity(table, pkValue);
|
|
@@ -9325,10 +9337,10 @@ var ensureEntity = (session, table, payload) => {
|
|
|
9325
9337
|
}
|
|
9326
9338
|
return createEntityFromRow(session, table, row);
|
|
9327
9339
|
};
|
|
9328
|
-
var assignColumns = (table, entity, payload) => {
|
|
9340
|
+
var assignColumns = (table, entity, payload, options) => {
|
|
9329
9341
|
for (const key of Object.keys(table.columns)) {
|
|
9330
9342
|
if (payload[key] !== void 0) {
|
|
9331
|
-
entity[key] = payload[key];
|
|
9343
|
+
entity[key] = coerceColumnValue(table, key, payload[key], options);
|
|
9332
9344
|
}
|
|
9333
9345
|
}
|
|
9334
9346
|
};
|
|
@@ -9355,8 +9367,8 @@ var handleHasMany = async (session, root, relationName, relation, payload, optio
|
|
|
9355
9367
|
const asObj = typeof item === "object" ? item : { [targetPk]: item };
|
|
9356
9368
|
const pkValue = asObj[targetPk];
|
|
9357
9369
|
const current = findInCollectionByPk(existing, targetPk, pkValue) ?? (pkValue !== void 0 && pkValue !== null ? session.getEntity(targetTable, pkValue) : void 0);
|
|
9358
|
-
const entity = current ?? ensureEntity(session, targetTable, asObj);
|
|
9359
|
-
assignColumns(targetTable, entity, asObj);
|
|
9370
|
+
const entity = current ?? ensureEntity(session, targetTable, asObj, options);
|
|
9371
|
+
assignColumns(targetTable, entity, asObj, options);
|
|
9360
9372
|
await applyGraphToEntity(session, targetTable, entity, asObj, options);
|
|
9361
9373
|
if (!isEntityInCollection(collection.getItems(), targetPk, entity)) {
|
|
9362
9374
|
collection.attach(entity);
|
|
@@ -9431,8 +9443,8 @@ var handleBelongsToMany = async (session, root, relationName, relation, payload,
|
|
|
9431
9443
|
}
|
|
9432
9444
|
const asObj = item;
|
|
9433
9445
|
const pkValue = asObj[targetPk];
|
|
9434
|
-
const entity = pkValue !== void 0 && pkValue !== null ? session.getEntity(targetTable, pkValue) ?? ensureEntity(session, targetTable, asObj) : ensureEntity(session, targetTable, asObj);
|
|
9435
|
-
assignColumns(targetTable, entity, asObj);
|
|
9446
|
+
const entity = pkValue !== void 0 && pkValue !== null ? session.getEntity(targetTable, pkValue) ?? ensureEntity(session, targetTable, asObj, options) : ensureEntity(session, targetTable, asObj, options);
|
|
9447
|
+
assignColumns(targetTable, entity, asObj, options);
|
|
9436
9448
|
await applyGraphToEntity(session, targetTable, entity, asObj, options);
|
|
9437
9449
|
if (!isEntityInCollection(collection.getItems(), targetPk, entity)) {
|
|
9438
9450
|
collection.attach(entity);
|
|
@@ -9463,7 +9475,7 @@ var applyRelation = async (session, table, entity, relationName, relation, paylo
|
|
|
9463
9475
|
}
|
|
9464
9476
|
};
|
|
9465
9477
|
var applyGraphToEntity = async (session, table, entity, payload, options) => {
|
|
9466
|
-
assignColumns(table, entity, payload);
|
|
9478
|
+
assignColumns(table, entity, payload, options);
|
|
9467
9479
|
for (const [relationName, relation] of Object.entries(table.relations)) {
|
|
9468
9480
|
if (!(relationName in payload)) continue;
|
|
9469
9481
|
await applyRelation(session, table, entity, relationName, relation, payload[relationName], options);
|
|
@@ -9474,7 +9486,7 @@ var saveGraphInternal = async (session, entityClass, payload, options = {}) => {
|
|
|
9474
9486
|
if (!table) {
|
|
9475
9487
|
throw new Error("Entity metadata has not been bootstrapped");
|
|
9476
9488
|
}
|
|
9477
|
-
const root = ensureEntity(session, table, payload);
|
|
9489
|
+
const root = ensureEntity(session, table, payload, options);
|
|
9478
9490
|
await applyGraphToEntity(session, table, root, payload, options);
|
|
9479
9491
|
return root;
|
|
9480
9492
|
};
|
|
@@ -9657,13 +9669,6 @@ var OrmSession = class {
|
|
|
9657
9669
|
async findMany(qb) {
|
|
9658
9670
|
return executeHydrated(this, qb);
|
|
9659
9671
|
}
|
|
9660
|
-
/**
|
|
9661
|
-
* Saves an entity graph (root + nested relations) based on a DTO-like payload.
|
|
9662
|
-
* @param entityClass - Root entity constructor
|
|
9663
|
-
* @param payload - DTO payload containing column values and nested relations
|
|
9664
|
-
* @param options - Graph save options
|
|
9665
|
-
* @returns The root entity instance
|
|
9666
|
-
*/
|
|
9667
9672
|
async saveGraph(entityClass, payload, options) {
|
|
9668
9673
|
const { transactional = true, ...graphOptions } = options ?? {};
|
|
9669
9674
|
const execute = () => saveGraphInternal(this, entityClass, payload, graphOptions);
|
|
@@ -9864,6 +9869,17 @@ var Orm = class {
|
|
|
9864
9869
|
}
|
|
9865
9870
|
};
|
|
9866
9871
|
|
|
9872
|
+
// src/orm/jsonify.ts
|
|
9873
|
+
var jsonify = (value) => {
|
|
9874
|
+
const record = value;
|
|
9875
|
+
const result = {};
|
|
9876
|
+
for (const key of Object.keys(record)) {
|
|
9877
|
+
const entry = record[key];
|
|
9878
|
+
result[key] = entry instanceof Date ? entry.toISOString() : entry;
|
|
9879
|
+
}
|
|
9880
|
+
return result;
|
|
9881
|
+
};
|
|
9882
|
+
|
|
9867
9883
|
// src/decorators/decorator-metadata.ts
|
|
9868
9884
|
var METADATA_KEY = "metal-orm:decorators";
|
|
9869
9885
|
var isStandardDecoratorContext = (value) => {
|
|
@@ -10747,6 +10763,7 @@ export {
|
|
|
10747
10763
|
isValueOperandInput,
|
|
10748
10764
|
isWindowFunctionNode,
|
|
10749
10765
|
jsonPath,
|
|
10766
|
+
jsonify,
|
|
10750
10767
|
lag,
|
|
10751
10768
|
lastValue,
|
|
10752
10769
|
lead,
|