metal-orm 1.0.57 → 1.0.58
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 +22 -15
- package/dist/index.cjs +640 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -45
- package/dist/index.d.ts +113 -45
- package/dist/index.js +639 -83
- package/dist/index.js.map +1 -1
- package/package.json +69 -69
- package/src/decorators/bootstrap.ts +39 -3
- package/src/orm/entity-meta.ts +6 -3
- package/src/orm/entity.ts +81 -14
- package/src/orm/execute.ts +87 -20
- package/src/orm/lazy-batch.ts +237 -54
- package/src/orm/relations/belongs-to.ts +2 -2
- package/src/orm/relations/has-many.ts +23 -9
- package/src/orm/relations/has-one.ts +2 -2
- package/src/orm/relations/many-to-many.ts +27 -13
- package/src/orm/save-graph-types.ts +2 -2
- package/src/orm/save-graph.ts +18 -18
- package/src/query-builder/relation-conditions.ts +80 -59
- package/src/query-builder/relation-service.ts +399 -95
- package/src/query-builder/relation-types.ts +2 -2
- package/src/query-builder/select.ts +58 -40
- package/src/schema/types.ts +106 -89
package/dist/index.d.cts
CHANGED
|
@@ -453,7 +453,7 @@ type InferRow<TTable extends TableDef> = {
|
|
|
453
453
|
[K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
|
|
454
454
|
};
|
|
455
455
|
type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & {
|
|
456
|
-
_pivot?: unknown
|
|
456
|
+
_pivot?: Record<string, unknown>;
|
|
457
457
|
})[] : never;
|
|
458
458
|
/**
|
|
459
459
|
* Maps relation names to the expected row results
|
|
@@ -461,7 +461,14 @@ type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer T
|
|
|
461
461
|
type RelationMap<TTable extends TableDef> = {
|
|
462
462
|
[K in keyof TTable['relations']]: RelationResult$1<TTable['relations'][K]>;
|
|
463
463
|
};
|
|
464
|
+
type RelationWrapper$1<TRel extends RelationDef> = TRel extends HasManyRelation<infer TTarget> ? HasManyCollection<EntityInstance<TTarget>> & ReadonlyArray<EntityInstance<TTarget>> : TRel extends HasOneRelation<infer TTarget> ? HasOneReference<EntityInstance<TTarget>> : TRel extends BelongsToManyRelation<infer TTarget> ? ManyToManyCollection<EntityInstance<TTarget> & {
|
|
465
|
+
_pivot?: Record<string, unknown>;
|
|
466
|
+
}> & ReadonlyArray<EntityInstance<TTarget> & {
|
|
467
|
+
_pivot?: Record<string, unknown>;
|
|
468
|
+
}> : TRel extends BelongsToRelation<infer TTarget> ? BelongsToReference<EntityInstance<TTarget>> : never;
|
|
464
469
|
interface HasManyCollection<TChild> {
|
|
470
|
+
length: number;
|
|
471
|
+
[Symbol.iterator](): Iterator<TChild>;
|
|
465
472
|
load(): Promise<TChild[]>;
|
|
466
473
|
getItems(): TChild[];
|
|
467
474
|
add(data: Partial<TChild>): TChild;
|
|
@@ -469,17 +476,21 @@ interface HasManyCollection<TChild> {
|
|
|
469
476
|
remove(entity: TChild): void;
|
|
470
477
|
clear(): void;
|
|
471
478
|
}
|
|
472
|
-
interface
|
|
479
|
+
interface BelongsToReferenceApi<TParent extends object = object> {
|
|
473
480
|
load(): Promise<TParent | null>;
|
|
474
481
|
get(): TParent | null;
|
|
475
482
|
set(data: Partial<TParent> | TParent | null): TParent | null;
|
|
476
483
|
}
|
|
477
|
-
|
|
484
|
+
type BelongsToReference<TParent extends object = object> = BelongsToReferenceApi<TParent> & Partial<TParent>;
|
|
485
|
+
interface HasOneReferenceApi<TChild extends object = object> {
|
|
478
486
|
load(): Promise<TChild | null>;
|
|
479
487
|
get(): TChild | null;
|
|
480
488
|
set(data: Partial<TChild> | TChild | null): TChild | null;
|
|
481
489
|
}
|
|
490
|
+
type HasOneReference<TChild extends object = object> = HasOneReferenceApi<TChild> & Partial<TChild>;
|
|
482
491
|
interface ManyToManyCollection<TTarget> {
|
|
492
|
+
length: number;
|
|
493
|
+
[Symbol.iterator](): Iterator<TTarget>;
|
|
483
494
|
load(): Promise<TTarget[]>;
|
|
484
495
|
getItems(): TTarget[];
|
|
485
496
|
attach(target: TTarget | number | string): void;
|
|
@@ -487,10 +498,15 @@ interface ManyToManyCollection<TTarget> {
|
|
|
487
498
|
syncByIds(ids: (number | string)[]): Promise<void>;
|
|
488
499
|
}
|
|
489
500
|
type EntityInstance<TTable extends TableDef, TRow = InferRow<TTable>> = TRow & {
|
|
490
|
-
[K in keyof RelationMap<TTable>]:
|
|
501
|
+
[K in keyof RelationMap<TTable>]: RelationWrapper$1<TTable['relations'][K]>;
|
|
491
502
|
} & {
|
|
492
503
|
$load<K extends keyof RelationMap<TTable>>(relation: K): Promise<RelationMap<TTable>[K]>;
|
|
493
504
|
};
|
|
505
|
+
type Primitive = string | number | boolean | Date | bigint | Buffer | null | undefined;
|
|
506
|
+
type IsAny<T> = 0 extends (1 & T) ? true : false;
|
|
507
|
+
type SelectableKeys<T> = {
|
|
508
|
+
[K in keyof T]-?: IsAny<T[K]> extends true ? never : NonNullable<T[K]> extends Primitive ? K : never;
|
|
509
|
+
}[keyof T];
|
|
494
510
|
|
|
495
511
|
/**
|
|
496
512
|
* SQL operators used in query conditions
|
|
@@ -2136,7 +2152,7 @@ type RelationIncludeJoinKind = typeof JOIN_KINDS.LEFT | typeof JOIN_KINDS.INNER;
|
|
|
2136
2152
|
* Options for including a relation in a query
|
|
2137
2153
|
*/
|
|
2138
2154
|
interface RelationIncludeOptions {
|
|
2139
|
-
columns?: string[];
|
|
2155
|
+
columns?: readonly string[];
|
|
2140
2156
|
aliasPrefix?: string;
|
|
2141
2157
|
filter?: ExpressionNode;
|
|
2142
2158
|
joinKind?: RelationIncludeJoinKind;
|
|
@@ -2169,7 +2185,7 @@ declare class RelationService {
|
|
|
2169
2185
|
* @param extraCondition - Additional join condition
|
|
2170
2186
|
* @returns Relation result with updated state and hydration
|
|
2171
2187
|
*/
|
|
2172
|
-
joinRelation(relationName: string, joinKind: JoinKind, extraCondition?: ExpressionNode): RelationResult;
|
|
2188
|
+
joinRelation(relationName: string, joinKind: JoinKind, extraCondition?: ExpressionNode, tableSource?: TableSourceNode): RelationResult;
|
|
2173
2189
|
/**
|
|
2174
2190
|
* Matches records based on a relation with an optional predicate
|
|
2175
2191
|
* @param relationName - Name of the relation to match
|
|
@@ -2208,6 +2224,17 @@ declare class RelationService {
|
|
|
2208
2224
|
* @returns Relation result with updated state and hydration
|
|
2209
2225
|
*/
|
|
2210
2226
|
private selectColumns;
|
|
2227
|
+
private combineWithAnd;
|
|
2228
|
+
private splitFilterExpressions;
|
|
2229
|
+
private flattenAnd;
|
|
2230
|
+
private isExpressionSelfContained;
|
|
2231
|
+
private collectReferencedTables;
|
|
2232
|
+
private collectFromExpression;
|
|
2233
|
+
private collectFromOperand;
|
|
2234
|
+
private collectFromOrderingTerm;
|
|
2235
|
+
private createFilteredRelationCte;
|
|
2236
|
+
private generateUniqueCteName;
|
|
2237
|
+
private resolveTargetTableName;
|
|
2211
2238
|
/**
|
|
2212
2239
|
* Gets a relation definition by name
|
|
2213
2240
|
* @param relationName - Name of the relation
|
|
@@ -3207,14 +3234,14 @@ interface SaveGraphOptions {
|
|
|
3207
3234
|
|
|
3208
3235
|
type AnyId = number | string;
|
|
3209
3236
|
type AnyFn = (...args: unknown[]) => unknown;
|
|
3210
|
-
type RelationWrapper = HasManyCollection<unknown> | HasOneReference
|
|
3237
|
+
type RelationWrapper = HasManyCollection<unknown> | HasOneReference | BelongsToReference | ManyToManyCollection<unknown>;
|
|
3211
3238
|
type FunctionKeys<T> = {
|
|
3212
3239
|
[K in keyof T & string]-?: T[K] extends AnyFn ? K : never;
|
|
3213
3240
|
}[keyof T & string];
|
|
3214
|
-
type RelationKeys<T> = {
|
|
3241
|
+
type RelationKeys$1<T> = {
|
|
3215
3242
|
[K in keyof T & string]-?: NonNullable<T[K]> extends RelationWrapper ? K : never;
|
|
3216
3243
|
}[keyof T & string];
|
|
3217
|
-
type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys<T>>;
|
|
3244
|
+
type ColumnKeys<T> = Exclude<keyof T & string, FunctionKeys<T> | RelationKeys$1<T>>;
|
|
3218
3245
|
type SaveGraphJsonScalar<T> = T extends Date ? string : T;
|
|
3219
3246
|
/**
|
|
3220
3247
|
* Input scalar type for `OrmSession.saveGraph` payloads.
|
|
@@ -3227,7 +3254,7 @@ type ColumnInput$1<TEntity> = {
|
|
|
3227
3254
|
};
|
|
3228
3255
|
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;
|
|
3229
3256
|
type RelationInput<TEntity> = {
|
|
3230
|
-
[K in RelationKeys<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
|
|
3257
|
+
[K in RelationKeys$1<TEntity>]?: RelationInputValue<NonNullable<TEntity[K]>>;
|
|
3231
3258
|
};
|
|
3232
3259
|
/**
|
|
3233
3260
|
* Typed payload accepted by `OrmSession.saveGraph`:
|
|
@@ -3480,6 +3507,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3480
3507
|
private readonly columnSelector;
|
|
3481
3508
|
private readonly relationManager;
|
|
3482
3509
|
private readonly lazyRelations;
|
|
3510
|
+
private readonly lazyRelationOptions;
|
|
3483
3511
|
/**
|
|
3484
3512
|
* Creates a new SelectQueryBuilder instance
|
|
3485
3513
|
* @param table - Table definition to query
|
|
@@ -3487,7 +3515,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3487
3515
|
* @param hydration - Optional hydration manager
|
|
3488
3516
|
* @param dependencies - Optional query builder dependencies
|
|
3489
3517
|
*/
|
|
3490
|
-
constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>);
|
|
3518
|
+
constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>, lazyRelationOptions?: Map<string, RelationIncludeOptions>);
|
|
3491
3519
|
/**
|
|
3492
3520
|
* Creates a new SelectQueryBuilder instance with updated context and lazy relations
|
|
3493
3521
|
* @param context - Updated query context
|
|
@@ -3665,15 +3693,12 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3665
3693
|
/**
|
|
3666
3694
|
* Includes a relation lazily in the query results
|
|
3667
3695
|
* @param relationName - Name of the relation to include lazily
|
|
3696
|
+
* @param options - Optional include options for lazy loading
|
|
3668
3697
|
* @returns New query builder instance with lazy relation inclusion
|
|
3669
3698
|
*/
|
|
3670
|
-
includeLazy<K extends keyof RelationMap<TTable>>(relationName: K): SelectQueryBuilder<T, TTable>;
|
|
3671
|
-
/**
|
|
3672
|
-
* Selects columns for a related table in a single hop.
|
|
3673
|
-
*/
|
|
3674
|
-
selectRelationColumns<K extends keyof TTable['relations'] & string, TRel extends RelationDef = TTable['relations'][K], TTarget extends TableDef = RelationTargetTable<TRel>, C extends keyof TTarget['columns'] & string = keyof TTarget['columns'] & string>(relationName: K, ...cols: C[]): SelectQueryBuilder<T, TTable>;
|
|
3699
|
+
includeLazy<K extends keyof RelationMap<TTable>>(relationName: K, options?: RelationIncludeOptions): SelectQueryBuilder<T, TTable>;
|
|
3675
3700
|
/**
|
|
3676
|
-
* Convenience alias for
|
|
3701
|
+
* Convenience alias for including only specific columns from a relation.
|
|
3677
3702
|
*/
|
|
3678
3703
|
includePick<K extends keyof TTable['relations'] & string, TRel extends RelationDef = TTable['relations'][K], TTarget extends TableDef = RelationTargetTable<TRel>, C extends keyof TTarget['columns'] & string = keyof TTarget['columns'] & string>(relationName: K, cols: C[]): SelectQueryBuilder<T, TTable>;
|
|
3679
3704
|
/**
|
|
@@ -3687,6 +3712,11 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3687
3712
|
* @returns Array of lazy relation names
|
|
3688
3713
|
*/
|
|
3689
3714
|
getLazyRelations(): (keyof RelationMap<TTable>)[];
|
|
3715
|
+
/**
|
|
3716
|
+
* Gets lazy relation include options
|
|
3717
|
+
* @returns Map of relation names to include options
|
|
3718
|
+
*/
|
|
3719
|
+
getLazyRelationOptions(): Map<string, RelationIncludeOptions>;
|
|
3690
3720
|
/**
|
|
3691
3721
|
* Gets the table definition for this query builder
|
|
3692
3722
|
* @returns Table definition
|
|
@@ -5438,6 +5468,36 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
|
|
|
5438
5468
|
private mapOp;
|
|
5439
5469
|
}
|
|
5440
5470
|
|
|
5471
|
+
/**
|
|
5472
|
+
* Metadata stored on entity instances for ORM internal use
|
|
5473
|
+
* @typeParam TTable - Table definition type
|
|
5474
|
+
*/
|
|
5475
|
+
interface EntityMeta<TTable extends TableDef> {
|
|
5476
|
+
/** Entity context */
|
|
5477
|
+
ctx: EntityContext;
|
|
5478
|
+
/** Table definition */
|
|
5479
|
+
table: TTable;
|
|
5480
|
+
/** Relations that should be loaded lazily */
|
|
5481
|
+
lazyRelations: (keyof RelationMap<TTable>)[];
|
|
5482
|
+
/** Include options for lazy relations */
|
|
5483
|
+
lazyRelationOptions: Map<string, RelationIncludeOptions>;
|
|
5484
|
+
/** Cache for relation promises */
|
|
5485
|
+
relationCache: Map<string, Promise<unknown>>;
|
|
5486
|
+
/** Hydration data for relations */
|
|
5487
|
+
relationHydration: Map<string, Map<string, unknown>>;
|
|
5488
|
+
/** Relation wrapper instances */
|
|
5489
|
+
relationWrappers: Map<string, unknown>;
|
|
5490
|
+
}
|
|
5491
|
+
|
|
5492
|
+
/**
|
|
5493
|
+
* Caches relation loader results across entities of the same type.
|
|
5494
|
+
* @template T - The cache type
|
|
5495
|
+
* @param meta - The entity metadata
|
|
5496
|
+
* @param relationName - The relation name
|
|
5497
|
+
* @param factory - The factory function to create the cache
|
|
5498
|
+
* @returns Promise with the cached relation data
|
|
5499
|
+
*/
|
|
5500
|
+
declare const relationLoaderCache: <T extends Map<string, unknown>>(meta: EntityMeta<TableDef>, relationName: string, factory: () => Promise<T>) => Promise<T>;
|
|
5441
5501
|
/**
|
|
5442
5502
|
* Creates an entity proxy with lazy loading capabilities.
|
|
5443
5503
|
* @template TTable - The table type
|
|
@@ -5448,7 +5508,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
|
|
|
5448
5508
|
* @param lazyRelations - Optional lazy relations
|
|
5449
5509
|
* @returns The entity instance
|
|
5450
5510
|
*/
|
|
5451
|
-
declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: TLazy[]) => EntityInstance<TTable>;
|
|
5511
|
+
declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: TLazy[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => EntityInstance<TTable>;
|
|
5452
5512
|
/**
|
|
5453
5513
|
* Creates an entity instance from a database row.
|
|
5454
5514
|
* @template TTable - The table type
|
|
@@ -5459,7 +5519,7 @@ declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof R
|
|
|
5459
5519
|
* @param lazyRelations - Optional lazy relations
|
|
5460
5520
|
* @returns The entity instance
|
|
5461
5521
|
*/
|
|
5462
|
-
declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: (keyof RelationMap<TTable>)[]) => TResult;
|
|
5522
|
+
declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: (keyof RelationMap<TTable>)[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => TResult;
|
|
5463
5523
|
|
|
5464
5524
|
/**
|
|
5465
5525
|
* An array of database rows, each represented as a record of string keys to unknown values.
|
|
@@ -5473,7 +5533,7 @@ type Rows$3 = Record<string, unknown>[];
|
|
|
5473
5533
|
* @param relation - The has-many relation definition.
|
|
5474
5534
|
* @returns A promise resolving to a map of root keys to arrays of related rows.
|
|
5475
5535
|
*/
|
|
5476
|
-
declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef,
|
|
5536
|
+
declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasManyRelation, options?: RelationIncludeOptions) => Promise<Map<string, Rows$3>>;
|
|
5477
5537
|
/**
|
|
5478
5538
|
* Loads related entities for a has-one relation in batch.
|
|
5479
5539
|
* @param ctx - The entity context.
|
|
@@ -5482,7 +5542,7 @@ declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, _re
|
|
|
5482
5542
|
* @param relation - The has-one relation definition.
|
|
5483
5543
|
* @returns A promise resolving to a map of root keys to single related rows.
|
|
5484
5544
|
*/
|
|
5485
|
-
declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef,
|
|
5545
|
+
declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasOneRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
|
|
5486
5546
|
/**
|
|
5487
5547
|
* Loads related entities for a belongs-to relation in batch.
|
|
5488
5548
|
* @param ctx - The entity context.
|
|
@@ -5491,7 +5551,7 @@ declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, _rel
|
|
|
5491
5551
|
* @param relation - The belongs-to relation definition.
|
|
5492
5552
|
* @returns A promise resolving to a map of foreign keys to single related rows.
|
|
5493
5553
|
*/
|
|
5494
|
-
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef,
|
|
5554
|
+
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: BelongsToRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
|
|
5495
5555
|
/**
|
|
5496
5556
|
* Loads related entities for a belongs-to-many relation in batch, including pivot data.
|
|
5497
5557
|
* @param ctx - The entity context.
|
|
@@ -5500,26 +5560,7 @@ declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, _
|
|
|
5500
5560
|
* @param relation - The belongs-to-many relation definition.
|
|
5501
5561
|
* @returns A promise resolving to a map of root keys to arrays of related rows with pivot data.
|
|
5502
5562
|
*/
|
|
5503
|
-
declare const loadBelongsToManyRelation: (ctx: EntityContext, rootTable: TableDef,
|
|
5504
|
-
|
|
5505
|
-
/**
|
|
5506
|
-
* Metadata stored on entity instances for ORM internal use
|
|
5507
|
-
* @typeParam TTable - Table definition type
|
|
5508
|
-
*/
|
|
5509
|
-
interface EntityMeta<TTable extends TableDef> {
|
|
5510
|
-
/** Entity context */
|
|
5511
|
-
ctx: EntityContext;
|
|
5512
|
-
/** Table definition */
|
|
5513
|
-
table: TTable;
|
|
5514
|
-
/** Relations that should be loaded lazily */
|
|
5515
|
-
lazyRelations: (keyof RelationMap<TTable>)[];
|
|
5516
|
-
/** Cache for relation promises */
|
|
5517
|
-
relationCache: Map<string, Promise<unknown>>;
|
|
5518
|
-
/** Hydration data for relations */
|
|
5519
|
-
relationHydration: Map<string, Map<string, unknown>>;
|
|
5520
|
-
/** Relation wrapper instances */
|
|
5521
|
-
relationWrappers: Map<string, unknown>;
|
|
5522
|
-
}
|
|
5563
|
+
declare const loadBelongsToManyRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: BelongsToManyRelation, options?: RelationIncludeOptions) => Promise<Map<string, Rows$3>>;
|
|
5523
5564
|
|
|
5524
5565
|
type Rows$2 = Record<string, unknown>[];
|
|
5525
5566
|
/**
|
|
@@ -5563,6 +5604,14 @@ declare class DefaultHasManyCollection<TChild> implements HasManyCollection<TChi
|
|
|
5563
5604
|
* @returns Array of child entities
|
|
5564
5605
|
*/
|
|
5565
5606
|
getItems(): TChild[];
|
|
5607
|
+
/**
|
|
5608
|
+
* Array-compatible length for testing frameworks.
|
|
5609
|
+
*/
|
|
5610
|
+
get length(): number;
|
|
5611
|
+
/**
|
|
5612
|
+
* Enables iteration over the collection like an array.
|
|
5613
|
+
*/
|
|
5614
|
+
[Symbol.iterator](): Iterator<TChild>;
|
|
5566
5615
|
/**
|
|
5567
5616
|
* Adds a new child entity to the collection.
|
|
5568
5617
|
* @param data - Partial data for the new entity
|
|
@@ -5599,7 +5648,7 @@ type Rows$1 = Record<string, unknown>;
|
|
|
5599
5648
|
*
|
|
5600
5649
|
* @template TParent The type of the parent entity.
|
|
5601
5650
|
*/
|
|
5602
|
-
declare class DefaultBelongsToReference<TParent> implements
|
|
5651
|
+
declare class DefaultBelongsToReference<TParent extends object> implements BelongsToReferenceApi<TParent> {
|
|
5603
5652
|
private readonly ctx;
|
|
5604
5653
|
private readonly meta;
|
|
5605
5654
|
private readonly root;
|
|
@@ -5673,6 +5722,14 @@ declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollecti
|
|
|
5673
5722
|
* @returns Array of target entities.
|
|
5674
5723
|
*/
|
|
5675
5724
|
getItems(): TTarget[];
|
|
5725
|
+
/**
|
|
5726
|
+
* Array-compatible length for testing frameworks.
|
|
5727
|
+
*/
|
|
5728
|
+
get length(): number;
|
|
5729
|
+
/**
|
|
5730
|
+
* Enables iteration over the collection like an array.
|
|
5731
|
+
*/
|
|
5732
|
+
[Symbol.iterator](): Iterator<TTarget>;
|
|
5676
5733
|
/**
|
|
5677
5734
|
* Attaches an entity to the collection.
|
|
5678
5735
|
* Registers an 'attach' change in the entity context.
|
|
@@ -5899,7 +5956,18 @@ declare const getTableDefFromEntity: <TTable extends TableDef = TableDef>(ctor:
|
|
|
5899
5956
|
* @param ctor - The entity constructor.
|
|
5900
5957
|
* @returns A select query builder for the entity.
|
|
5901
5958
|
*/
|
|
5902
|
-
|
|
5959
|
+
type NonFunctionKeys<T> = {
|
|
5960
|
+
[K in keyof T]-?: T[K] extends (...args: unknown[]) => unknown ? never : K;
|
|
5961
|
+
}[keyof T];
|
|
5962
|
+
type RelationKeys<TEntity extends object> = Exclude<NonFunctionKeys<TEntity>, SelectableKeys<TEntity>> & string;
|
|
5963
|
+
type EntityTable<TEntity extends object> = Omit<TableDef<{
|
|
5964
|
+
[K in SelectableKeys<TEntity>]: ColumnDef;
|
|
5965
|
+
}>, 'relations'> & {
|
|
5966
|
+
relations: {
|
|
5967
|
+
[K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object>> : NonNullable<TEntity[K]> extends HasOneReference<infer TChild> ? HasOneRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends BelongsToReference<infer TParent> ? BelongsToRelation<EntityTable<NonNullable<TParent> & object>> : NonNullable<TEntity[K]> extends object ? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>> : never;
|
|
5968
|
+
};
|
|
5969
|
+
};
|
|
5970
|
+
declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<unknown, EntityTable<TEntity>>;
|
|
5903
5971
|
/**
|
|
5904
5972
|
* Public API: opt-in ergonomic entity reference (decorator-level).
|
|
5905
5973
|
*
|
|
@@ -6071,4 +6139,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
6071
6139
|
*/
|
|
6072
6140
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
6073
6141
|
|
|
6074
|
-
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 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, 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, age, aliasRef, and, arrayAppend, 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, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, 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, 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, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFromEntity, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
6142
|
+
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, 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 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, 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 Primitive, 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 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, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, 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, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, 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, 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, second, sel, selectFromEntity, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|