metal-orm 1.0.41 → 1.0.43
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 +74 -20
- package/dist/index.cjs +180 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -96
- package/dist/index.d.ts +142 -96
- package/dist/index.js +177 -74
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
- package/scripts/run-eslint.mjs +34 -0
- package/src/codegen/typescript.ts +32 -15
- package/src/core/ast/builders.ts +7 -2
- package/src/core/ast/expression-builders.ts +0 -2
- package/src/core/ast/expression-nodes.ts +14 -5
- package/src/core/ast/expression-visitor.ts +11 -8
- package/src/core/ast/expression.ts +2 -2
- package/src/core/ast/join-node.ts +1 -1
- package/src/core/ast/query.ts +6 -6
- package/src/core/ast/window-functions.ts +10 -2
- package/src/core/ddl/dialects/base-schema-dialect.ts +30 -3
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +4 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +2 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +13 -1
- package/src/core/ddl/dialects/render-reference.test.ts +69 -0
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -0
- package/src/core/ddl/introspect/mssql.ts +42 -8
- package/src/core/ddl/introspect/mysql.ts +30 -6
- package/src/core/ddl/introspect/postgres.ts +88 -34
- package/src/core/ddl/introspect/run-select.ts +6 -4
- package/src/core/ddl/introspect/sqlite.ts +56 -11
- package/src/core/ddl/introspect/types.ts +0 -1
- package/src/core/ddl/introspect/utils.ts +3 -3
- package/src/core/ddl/schema-dialect.ts +1 -0
- package/src/core/ddl/schema-generator.ts +4 -12
- package/src/core/ddl/sql-writing.ts +4 -4
- package/src/core/dialect/abstract.ts +18 -6
- package/src/core/dialect/base/function-table-formatter.ts +3 -2
- package/src/core/dialect/base/join-compiler.ts +5 -3
- package/src/core/dialect/base/returning-strategy.ts +1 -0
- package/src/core/dialect/base/sql-dialect.ts +3 -3
- package/src/core/dialect/mssql/functions.ts +24 -25
- package/src/core/dialect/mssql/index.ts +1 -4
- package/src/core/dialect/mysql/functions.ts +0 -1
- package/src/core/dialect/postgres/functions.ts +33 -34
- package/src/core/dialect/postgres/index.ts +1 -0
- package/src/core/dialect/sqlite/functions.ts +18 -19
- package/src/core/dialect/sqlite/index.ts +2 -0
- package/src/core/execution/db-executor.ts +1 -1
- package/src/core/execution/executors/mysql-executor.ts +2 -2
- package/src/core/execution/executors/postgres-executor.ts +1 -1
- package/src/core/execution/pooling/pool.ts +2 -0
- package/src/core/functions/datetime.ts +1 -1
- package/src/core/functions/numeric.ts +1 -1
- package/src/core/functions/text.ts +1 -1
- package/src/decorators/bootstrap.ts +27 -8
- package/src/decorators/column.ts +3 -11
- package/src/decorators/decorator-metadata.ts +3 -9
- package/src/decorators/entity.ts +21 -5
- package/src/decorators/relations.ts +2 -11
- package/src/orm/entity-context.ts +8 -8
- package/src/orm/entity-meta.ts +8 -8
- package/src/orm/entity-metadata.ts +11 -9
- package/src/orm/entity.ts +28 -29
- package/src/orm/execute.ts +4 -4
- package/src/orm/hydration.ts +42 -39
- package/src/orm/identity-map.ts +1 -1
- package/src/orm/lazy-batch.ts +9 -9
- package/src/orm/orm-session.ts +24 -23
- package/src/orm/orm.ts +2 -5
- package/src/orm/relation-change-processor.ts +12 -11
- package/src/orm/relations/belongs-to.ts +11 -11
- package/src/orm/relations/has-many.ts +10 -10
- package/src/orm/relations/has-one.ts +8 -7
- package/src/orm/relations/many-to-many.ts +13 -13
- package/src/orm/runtime-types.ts +4 -4
- package/src/orm/save-graph.ts +31 -25
- package/src/orm/unit-of-work.ts +17 -17
- package/src/query-builder/delete.ts +4 -3
- package/src/query-builder/hydration-manager.ts +6 -5
- package/src/query-builder/insert.ts +12 -8
- package/src/query-builder/query-ast-service.ts +2 -2
- package/src/query-builder/raw-column-parser.ts +2 -1
- package/src/query-builder/select-helpers.ts +2 -2
- package/src/query-builder/select.ts +31 -31
- package/src/query-builder/update.ts +4 -3
- package/src/schema/column.ts +26 -26
- package/src/schema/table.ts +239 -115
- package/src/schema/types.ts +22 -22
package/dist/index.d.cts
CHANGED
|
@@ -50,7 +50,7 @@ interface ColumnDef<T extends ColumnType = ColumnType, TRuntime = unknown> {
|
|
|
50
50
|
/** Column comment/description */
|
|
51
51
|
comment?: string;
|
|
52
52
|
/** Additional arguments for the column type (e.g., VARCHAR length) */
|
|
53
|
-
args?:
|
|
53
|
+
args?: unknown[];
|
|
54
54
|
/** Table name this column belongs to (filled at runtime by defineTable) */
|
|
55
55
|
table?: string;
|
|
56
56
|
}
|
|
@@ -312,12 +312,12 @@ interface TableOptions {
|
|
|
312
312
|
collation?: string;
|
|
313
313
|
}
|
|
314
314
|
interface TableHooks {
|
|
315
|
-
beforeInsert?(ctx: unknown, entity:
|
|
316
|
-
afterInsert?(ctx: unknown, entity:
|
|
317
|
-
beforeUpdate?(ctx: unknown, entity:
|
|
318
|
-
afterUpdate?(ctx: unknown, entity:
|
|
319
|
-
beforeDelete?(ctx: unknown, entity:
|
|
320
|
-
afterDelete?(ctx: unknown, entity:
|
|
315
|
+
beforeInsert?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
316
|
+
afterInsert?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
317
|
+
beforeUpdate?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
318
|
+
afterUpdate?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
319
|
+
beforeDelete?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
320
|
+
afterDelete?(ctx: unknown, entity: unknown): Promise<void> | void;
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
323
323
|
* Definition of a database table with its columns and relationships
|
|
@@ -365,6 +365,43 @@ interface TableDef<T extends Record<string, ColumnDef> = Record<string, ColumnDe
|
|
|
365
365
|
* ```
|
|
366
366
|
*/
|
|
367
367
|
declare const defineTable: <T extends Record<string, ColumnDef>>(name: string, columns: T, relations?: Record<string, RelationDef>, hooks?: TableHooks, options?: TableOptions) => TableDef<T>;
|
|
368
|
+
type DirectColumnKeys<T extends TableDef> = Exclude<keyof T["columns"] & string, keyof T | "$">;
|
|
369
|
+
type TableRef$1<T extends TableDef> = T & {
|
|
370
|
+
[K in DirectColumnKeys<T>]: T["columns"][K];
|
|
371
|
+
} & {
|
|
372
|
+
/**
|
|
373
|
+
* Escape hatch for collisions:
|
|
374
|
+
* - tref.name => table name (string)
|
|
375
|
+
* - tref.$.name => column def for "name"
|
|
376
|
+
*/
|
|
377
|
+
$: T["columns"];
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Public API: opt-in ergonomic table reference.
|
|
381
|
+
* Usage:
|
|
382
|
+
* const t = tableRef(todos);
|
|
383
|
+
* qb.where(eq(t.done, false)).orderBy(t.id, "ASC");
|
|
384
|
+
* Collisions:
|
|
385
|
+
* t.name is the table name (real field)
|
|
386
|
+
* t.$.name is the "name" column (escape hatch)
|
|
387
|
+
*/
|
|
388
|
+
declare const tableRef: <T extends TableDef>(table: T) => TableRef$1<T>;
|
|
389
|
+
/**
|
|
390
|
+
* Public API: dynamic column lookup by string key.
|
|
391
|
+
*
|
|
392
|
+
* Useful when the column name is only known at runtime, or when a column name
|
|
393
|
+
* collides with a real table field (e.g. "name").
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* const t = tableRef(todos);
|
|
398
|
+
* const key = runtimeKey();
|
|
399
|
+
* where(eq(getColumn(t, key), 123));
|
|
400
|
+
* // or: t.$.name (escape hatch)
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
declare function getColumn<T extends TableDef, K extends keyof T['columns'] & string>(table: T, key: K): T['columns'][K];
|
|
404
|
+
declare function getColumn<T extends TableDef>(table: T, key: string): ColumnDef;
|
|
368
405
|
|
|
369
406
|
/**
|
|
370
407
|
* Resolves a relation definition to its target table type.
|
|
@@ -383,7 +420,7 @@ type InferRow<TTable extends TableDef> = {
|
|
|
383
420
|
[K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
|
|
384
421
|
};
|
|
385
422
|
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> & {
|
|
386
|
-
_pivot?:
|
|
423
|
+
_pivot?: unknown;
|
|
387
424
|
})[] : never;
|
|
388
425
|
/**
|
|
389
426
|
* Maps relation names to the expected row results
|
|
@@ -652,10 +689,10 @@ interface ArithmeticExpressionNode {
|
|
|
652
689
|
* Union type representing any operand that can be used in expressions
|
|
653
690
|
*/
|
|
654
691
|
type OperandNode = AliasRefNode | ColumnNode | LiteralNode | FunctionNode | JsonPathNode | ScalarSubqueryNode | CaseExpressionNode | WindowFunctionNode;
|
|
655
|
-
declare const isOperandNode: (node:
|
|
656
|
-
declare const isFunctionNode: (node:
|
|
657
|
-
declare const isCaseExpressionNode: (node:
|
|
658
|
-
declare const isWindowFunctionNode: (node:
|
|
692
|
+
declare const isOperandNode: (node: unknown) => node is OperandNode;
|
|
693
|
+
declare const isFunctionNode: (node: unknown) => node is FunctionNode;
|
|
694
|
+
declare const isCaseExpressionNode: (node: unknown) => node is CaseExpressionNode;
|
|
695
|
+
declare const isWindowFunctionNode: (node: unknown) => node is WindowFunctionNode;
|
|
659
696
|
declare const isExpressionSelectionNode: (node: ColumnRef | FunctionNode | CaseExpressionNode | WindowFunctionNode) => node is FunctionNode | CaseExpressionNode | WindowFunctionNode;
|
|
660
697
|
/**
|
|
661
698
|
* AST node representing a binary expression (e.g., column = value)
|
|
@@ -925,7 +962,7 @@ declare const ntile: (n: number) => WindowFunctionNode;
|
|
|
925
962
|
* @param defaultValue - Default value if no row exists
|
|
926
963
|
* @returns Window function node for LAG
|
|
927
964
|
*/
|
|
928
|
-
declare const lag: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?:
|
|
965
|
+
declare const lag: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?: LiteralNode["value"]) => WindowFunctionNode;
|
|
929
966
|
/**
|
|
930
967
|
* Creates a LEAD window function
|
|
931
968
|
* @param col - Column to lead
|
|
@@ -933,7 +970,7 @@ declare const lag: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?:
|
|
|
933
970
|
* @param defaultValue - Default value if no row exists
|
|
934
971
|
* @returns Window function node for LEAD
|
|
935
972
|
*/
|
|
936
|
-
declare const lead: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?:
|
|
973
|
+
declare const lead: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?: LiteralNode["value"]) => WindowFunctionNode;
|
|
937
974
|
/**
|
|
938
975
|
* Creates a FIRST_VALUE window function
|
|
939
976
|
* @param col - Column to get first value from
|
|
@@ -1029,8 +1066,8 @@ interface OperandVisitor<R> {
|
|
|
1029
1066
|
visitAliasRef?(node: AliasRefNode): R;
|
|
1030
1067
|
otherwise?(node: OperandNode): R;
|
|
1031
1068
|
}
|
|
1032
|
-
type ExpressionDispatch = <R>(node:
|
|
1033
|
-
type OperandDispatch = <R>(node:
|
|
1069
|
+
type ExpressionDispatch = <R>(node: ExpressionNode, visitor: ExpressionVisitor<R>) => R;
|
|
1070
|
+
type OperandDispatch = <R>(node: OperandNode, visitor: OperandVisitor<R>) => R;
|
|
1034
1071
|
/**
|
|
1035
1072
|
* Registers a dispatcher for a custom expression node type.
|
|
1036
1073
|
* Allows new node kinds without modifying the core switch.
|
|
@@ -1105,7 +1142,7 @@ interface FunctionTableNode {
|
|
|
1105
1142
|
/** Optional schema for the function (some dialects) */
|
|
1106
1143
|
schema?: string;
|
|
1107
1144
|
/** Function arguments as operand nodes */
|
|
1108
|
-
args?:
|
|
1145
|
+
args?: OperandNode[];
|
|
1109
1146
|
/** Optional alias for the function table */
|
|
1110
1147
|
alias?: string;
|
|
1111
1148
|
/** LATERAL flag */
|
|
@@ -1400,7 +1437,7 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
1400
1437
|
* @returns SQL WHERE clause or empty string
|
|
1401
1438
|
*/
|
|
1402
1439
|
protected compileWhere(where: ExpressionNode | undefined, ctx: CompilerContext): string;
|
|
1403
|
-
protected compileReturning(returning: ColumnNode[] | undefined,
|
|
1440
|
+
protected compileReturning(returning: ColumnNode[] | undefined, _ctx: CompilerContext): string;
|
|
1404
1441
|
/**
|
|
1405
1442
|
* Generates subquery for EXISTS expressions
|
|
1406
1443
|
* Rule: Always forces SELECT 1, ignoring column list
|
|
@@ -1421,12 +1458,12 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
1421
1458
|
* @param index - Parameter index
|
|
1422
1459
|
* @returns Formatted placeholder string
|
|
1423
1460
|
*/
|
|
1424
|
-
protected formatPlaceholder(
|
|
1461
|
+
protected formatPlaceholder(_index: number): string;
|
|
1425
1462
|
/**
|
|
1426
1463
|
* Whether the current dialect supports a given set operation.
|
|
1427
1464
|
* Override in concrete dialects to restrict support.
|
|
1428
1465
|
*/
|
|
1429
|
-
protected supportsSetOperation(
|
|
1466
|
+
protected supportsSetOperation(_kind: SetOperationKind): boolean;
|
|
1430
1467
|
/**
|
|
1431
1468
|
* Validates set-operation semantics:
|
|
1432
1469
|
* - Ensures the dialect supports requested operators.
|
|
@@ -1489,7 +1526,7 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
1489
1526
|
protected compileOrderingTerm(term: OrderingTerm, ctx: CompilerContext): string;
|
|
1490
1527
|
private registerDefaultExpressionCompilers;
|
|
1491
1528
|
private registerDefaultOperandCompilers;
|
|
1492
|
-
protected compileJsonPath(
|
|
1529
|
+
protected compileJsonPath(_node: JsonPathNode): string;
|
|
1493
1530
|
/**
|
|
1494
1531
|
* Compiles a function operand, using the dialect's function strategy.
|
|
1495
1532
|
*/
|
|
@@ -2041,7 +2078,7 @@ interface SimpleQueryRunner {
|
|
|
2041
2078
|
declare function createExecutorFromQueryRunner(runner: SimpleQueryRunner): DbExecutor;
|
|
2042
2079
|
|
|
2043
2080
|
type EntityConstructor<T = object> = new (...args: any[]) => T;
|
|
2044
|
-
type EntityOrTableTarget = EntityConstructor
|
|
2081
|
+
type EntityOrTableTarget = EntityConstructor | TableDef;
|
|
2045
2082
|
type EntityOrTableTargetResolver = EntityOrTableTarget | (() => EntityOrTableTarget);
|
|
2046
2083
|
|
|
2047
2084
|
/**
|
|
@@ -2066,13 +2103,13 @@ interface TrackedEntity {
|
|
|
2066
2103
|
/** The table definition this entity belongs to */
|
|
2067
2104
|
table: TableDef;
|
|
2068
2105
|
/** The actual entity instance */
|
|
2069
|
-
entity:
|
|
2106
|
+
entity: unknown;
|
|
2070
2107
|
/** Primary key value of the entity */
|
|
2071
2108
|
pk: string | number | null;
|
|
2072
2109
|
/** Current status of the entity */
|
|
2073
2110
|
status: EntityStatus;
|
|
2074
2111
|
/** Original values of the entity when it was loaded */
|
|
2075
|
-
original: Record<string,
|
|
2112
|
+
original: Record<string, unknown> | null;
|
|
2076
2113
|
}
|
|
2077
2114
|
/**
|
|
2078
2115
|
* Type representing a key for relation navigation
|
|
@@ -2100,7 +2137,7 @@ type RelationChange<T> = {
|
|
|
2100
2137
|
*/
|
|
2101
2138
|
interface RelationChangeEntry {
|
|
2102
2139
|
/** Root entity that owns the relation */
|
|
2103
|
-
root:
|
|
2140
|
+
root: unknown;
|
|
2104
2141
|
/** Key of the relation being changed */
|
|
2105
2142
|
relationKey: RelationKey;
|
|
2106
2143
|
/** Table definition of the root entity */
|
|
@@ -2110,7 +2147,7 @@ interface RelationChangeEntry {
|
|
|
2110
2147
|
/** Relation definition */
|
|
2111
2148
|
relation: RelationDef;
|
|
2112
2149
|
/** The change being applied */
|
|
2113
|
-
change: RelationChange<
|
|
2150
|
+
change: RelationChange<unknown>;
|
|
2114
2151
|
}
|
|
2115
2152
|
/**
|
|
2116
2153
|
* Represents a domain event that can be emitted by entities
|
|
@@ -2170,9 +2207,8 @@ declare class InterceptorPipeline {
|
|
|
2170
2207
|
|
|
2171
2208
|
/**
|
|
2172
2209
|
* Options for creating an ORM instance.
|
|
2173
|
-
* @template E - The domain event type
|
|
2174
2210
|
*/
|
|
2175
|
-
interface OrmOptions
|
|
2211
|
+
interface OrmOptions {
|
|
2176
2212
|
/** The database dialect */
|
|
2177
2213
|
dialect: Dialect;
|
|
2178
2214
|
/** The database executor factory */
|
|
@@ -2217,7 +2253,7 @@ declare class Orm<E extends DomainEvent = OrmDomainEvent> {
|
|
|
2217
2253
|
* Creates a new ORM instance.
|
|
2218
2254
|
* @param opts - ORM options
|
|
2219
2255
|
*/
|
|
2220
|
-
constructor(opts: OrmOptions
|
|
2256
|
+
constructor(opts: OrmOptions);
|
|
2221
2257
|
/**
|
|
2222
2258
|
* Creates a new ORM session.
|
|
2223
2259
|
* @param options - Optional session options
|
|
@@ -2241,7 +2277,7 @@ declare class Orm<E extends DomainEvent = OrmDomainEvent> {
|
|
|
2241
2277
|
declare class IdentityMap {
|
|
2242
2278
|
private readonly buckets;
|
|
2243
2279
|
get bucketsMap(): Map<string, Map<string, TrackedEntity>>;
|
|
2244
|
-
getEntity(table: TableDef, pk: string | number):
|
|
2280
|
+
getEntity(table: TableDef, pk: string | number): unknown | undefined;
|
|
2245
2281
|
register(tracked: TrackedEntity): void;
|
|
2246
2282
|
remove(tracked: TrackedEntity): void;
|
|
2247
2283
|
getEntitiesForTable(table: TableDef): TrackedEntity[];
|
|
@@ -2281,7 +2317,7 @@ declare class UnitOfWork {
|
|
|
2281
2317
|
* @param pk - The primary key value
|
|
2282
2318
|
* @returns The entity or undefined if not found
|
|
2283
2319
|
*/
|
|
2284
|
-
getEntity(table: TableDef, pk: string | number):
|
|
2320
|
+
getEntity(table: TableDef, pk: string | number): unknown | undefined;
|
|
2285
2321
|
/**
|
|
2286
2322
|
* Gets all tracked entities for a specific table.
|
|
2287
2323
|
* @param table - The table definition
|
|
@@ -2293,38 +2329,38 @@ declare class UnitOfWork {
|
|
|
2293
2329
|
* @param entity - The entity to find
|
|
2294
2330
|
* @returns The tracked entity or undefined if not found
|
|
2295
2331
|
*/
|
|
2296
|
-
findTracked(entity:
|
|
2332
|
+
findTracked(entity: unknown): TrackedEntity | undefined;
|
|
2297
2333
|
/**
|
|
2298
2334
|
* Sets an entity in the identity map.
|
|
2299
2335
|
* @param table - The table definition
|
|
2300
2336
|
* @param pk - The primary key value
|
|
2301
2337
|
* @param entity - The entity instance
|
|
2302
2338
|
*/
|
|
2303
|
-
setEntity(table: TableDef, pk: string | number, entity:
|
|
2339
|
+
setEntity(table: TableDef, pk: string | number, entity: unknown): void;
|
|
2304
2340
|
/**
|
|
2305
2341
|
* Tracks a new entity.
|
|
2306
2342
|
* @param table - The table definition
|
|
2307
2343
|
* @param entity - The entity instance
|
|
2308
2344
|
* @param pk - Optional primary key value
|
|
2309
2345
|
*/
|
|
2310
|
-
trackNew(table: TableDef, entity:
|
|
2346
|
+
trackNew(table: TableDef, entity: unknown, pk?: string | number): void;
|
|
2311
2347
|
/**
|
|
2312
2348
|
* Tracks a managed entity.
|
|
2313
2349
|
* @param table - The table definition
|
|
2314
2350
|
* @param pk - The primary key value
|
|
2315
2351
|
* @param entity - The entity instance
|
|
2316
2352
|
*/
|
|
2317
|
-
trackManaged(table: TableDef, pk: string | number, entity:
|
|
2353
|
+
trackManaged(table: TableDef, pk: string | number, entity: unknown): void;
|
|
2318
2354
|
/**
|
|
2319
2355
|
* Marks an entity as dirty (modified).
|
|
2320
2356
|
* @param entity - The entity to mark as dirty
|
|
2321
2357
|
*/
|
|
2322
|
-
markDirty(entity:
|
|
2358
|
+
markDirty(entity: unknown): void;
|
|
2323
2359
|
/**
|
|
2324
2360
|
* Marks an entity as removed.
|
|
2325
2361
|
* @param entity - The entity to mark as removed
|
|
2326
2362
|
*/
|
|
2327
|
-
markRemoved(entity:
|
|
2363
|
+
markRemoved(entity: unknown): void;
|
|
2328
2364
|
/**
|
|
2329
2365
|
* Flushes pending changes to the database.
|
|
2330
2366
|
*/
|
|
@@ -2610,14 +2646,14 @@ interface ExecutionContext {
|
|
|
2610
2646
|
interface EntityContext {
|
|
2611
2647
|
dialect: Dialect;
|
|
2612
2648
|
executor: DbExecutor;
|
|
2613
|
-
getEntity(table: TableDef, pk:
|
|
2614
|
-
setEntity(table: TableDef, pk:
|
|
2615
|
-
trackNew(table: TableDef, entity:
|
|
2616
|
-
trackManaged(table: TableDef, pk:
|
|
2617
|
-
markDirty(entity:
|
|
2618
|
-
markRemoved(entity:
|
|
2649
|
+
getEntity(table: TableDef, pk: unknown): unknown;
|
|
2650
|
+
setEntity(table: TableDef, pk: unknown, entity: unknown): void;
|
|
2651
|
+
trackNew(table: TableDef, entity: unknown, pk?: unknown): void;
|
|
2652
|
+
trackManaged(table: TableDef, pk: unknown, entity: unknown): void;
|
|
2653
|
+
markDirty(entity: unknown): void;
|
|
2654
|
+
markRemoved(entity: unknown): void;
|
|
2619
2655
|
getEntitiesForTable(table: TableDef): TrackedEntity[];
|
|
2620
|
-
registerRelationChange(root:
|
|
2656
|
+
registerRelationChange(root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>): void;
|
|
2621
2657
|
}
|
|
2622
2658
|
|
|
2623
2659
|
interface HydrationContext<E extends DomainEvent = AnyDomainEvent> {
|
|
@@ -2710,38 +2746,38 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
2710
2746
|
* @param pk - The primary key value
|
|
2711
2747
|
* @returns The entity or undefined if not found
|
|
2712
2748
|
*/
|
|
2713
|
-
getEntity(table: TableDef, pk:
|
|
2749
|
+
getEntity(table: TableDef, pk: unknown): unknown | undefined;
|
|
2714
2750
|
/**
|
|
2715
2751
|
* Sets an entity in the identity map.
|
|
2716
2752
|
* @param table - The table definition
|
|
2717
2753
|
* @param pk - The primary key value
|
|
2718
2754
|
* @param entity - The entity instance
|
|
2719
2755
|
*/
|
|
2720
|
-
setEntity(table: TableDef, pk:
|
|
2756
|
+
setEntity(table: TableDef, pk: unknown, entity: unknown): void;
|
|
2721
2757
|
/**
|
|
2722
2758
|
* Tracks a new entity.
|
|
2723
2759
|
* @param table - The table definition
|
|
2724
2760
|
* @param entity - The entity instance
|
|
2725
2761
|
* @param pk - Optional primary key value
|
|
2726
2762
|
*/
|
|
2727
|
-
trackNew(table: TableDef, entity:
|
|
2763
|
+
trackNew(table: TableDef, entity: unknown, pk?: unknown): void;
|
|
2728
2764
|
/**
|
|
2729
2765
|
* Tracks a managed entity.
|
|
2730
2766
|
* @param table - The table definition
|
|
2731
2767
|
* @param pk - The primary key value
|
|
2732
2768
|
* @param entity - The entity instance
|
|
2733
2769
|
*/
|
|
2734
|
-
trackManaged(table: TableDef, pk:
|
|
2770
|
+
trackManaged(table: TableDef, pk: unknown, entity: unknown): void;
|
|
2735
2771
|
/**
|
|
2736
2772
|
* Marks an entity as dirty (modified).
|
|
2737
2773
|
* @param entity - The entity to mark as dirty
|
|
2738
2774
|
*/
|
|
2739
|
-
markDirty(entity:
|
|
2775
|
+
markDirty(entity: unknown): void;
|
|
2740
2776
|
/**
|
|
2741
2777
|
* Marks an entity as removed.
|
|
2742
2778
|
* @param entity - The entity to mark as removed
|
|
2743
2779
|
*/
|
|
2744
|
-
markRemoved(entity:
|
|
2780
|
+
markRemoved(entity: unknown): void;
|
|
2745
2781
|
/**
|
|
2746
2782
|
* Registers a relation change.
|
|
2747
2783
|
* @param root - The root entity
|
|
@@ -2751,7 +2787,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
2751
2787
|
* @param relation - The relation definition
|
|
2752
2788
|
* @param change - The relation change
|
|
2753
2789
|
*/
|
|
2754
|
-
registerRelationChange: (root:
|
|
2790
|
+
registerRelationChange: (root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>) => void;
|
|
2755
2791
|
/**
|
|
2756
2792
|
* Gets all tracked entities for a specific table.
|
|
2757
2793
|
* @param table - The table definition
|
|
@@ -2779,21 +2815,21 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
2779
2815
|
* @returns The entity instance or null if not found
|
|
2780
2816
|
* @throws If entity metadata is not bootstrapped or table has no primary key
|
|
2781
2817
|
*/
|
|
2782
|
-
find<TCtor extends EntityConstructor<
|
|
2818
|
+
find<TCtor extends EntityConstructor<object>>(entityClass: TCtor, id: unknown): Promise<InstanceType<TCtor> | null>;
|
|
2783
2819
|
/**
|
|
2784
2820
|
* Finds a single entity using a query builder.
|
|
2785
2821
|
* @template TTable - The table type
|
|
2786
2822
|
* @param qb - The query builder
|
|
2787
2823
|
* @returns The first entity instance or null if not found
|
|
2788
2824
|
*/
|
|
2789
|
-
findOne<TTable extends TableDef>(qb: SelectQueryBuilder<
|
|
2825
|
+
findOne<TTable extends TableDef>(qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable> | null>;
|
|
2790
2826
|
/**
|
|
2791
2827
|
* Finds multiple entities using a query builder.
|
|
2792
2828
|
* @template TTable - The table type
|
|
2793
2829
|
* @param qb - The query builder
|
|
2794
2830
|
* @returns Array of entity instances
|
|
2795
2831
|
*/
|
|
2796
|
-
findMany<TTable extends TableDef>(qb: SelectQueryBuilder<
|
|
2832
|
+
findMany<TTable extends TableDef>(qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
2797
2833
|
/**
|
|
2798
2834
|
* Saves an entity graph (root + nested relations) based on a DTO-like payload.
|
|
2799
2835
|
* @param entityClass - Root entity constructor
|
|
@@ -2801,7 +2837,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
2801
2837
|
* @param options - Graph save options
|
|
2802
2838
|
* @returns The root entity instance
|
|
2803
2839
|
*/
|
|
2804
|
-
saveGraph<TCtor extends EntityConstructor<
|
|
2840
|
+
saveGraph<TCtor extends EntityConstructor<object>>(entityClass: TCtor, payload: Record<string, unknown>, options?: SaveGraphOptions & {
|
|
2805
2841
|
transactional?: boolean;
|
|
2806
2842
|
}): Promise<InstanceType<TCtor>>;
|
|
2807
2843
|
/**
|
|
@@ -2862,7 +2898,7 @@ type DeepSelectConfig<TTable extends TableDef> = {
|
|
|
2862
2898
|
type WhereHasOptions = {
|
|
2863
2899
|
correlate?: ExpressionNode;
|
|
2864
2900
|
};
|
|
2865
|
-
type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<
|
|
2901
|
+
type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<unknown, TChildTable>) => SelectQueryBuilder<unknown, TChildTable>;
|
|
2866
2902
|
/**
|
|
2867
2903
|
|
|
2868
2904
|
* Main query builder class for constructing SQL SELECT queries
|
|
@@ -2872,7 +2908,7 @@ type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<an
|
|
|
2872
2908
|
* @typeParam TTable - Table definition being queried
|
|
2873
2909
|
|
|
2874
2910
|
*/
|
|
2875
|
-
declare class SelectQueryBuilder<T =
|
|
2911
|
+
declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef> {
|
|
2876
2912
|
private readonly env;
|
|
2877
2913
|
private readonly context;
|
|
2878
2914
|
private readonly columnSelector;
|
|
@@ -2942,7 +2978,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
2942
2978
|
* @returns New query builder instance with the CTE
|
|
2943
2979
|
|
|
2944
2980
|
*/
|
|
2945
|
-
with(name: string, query: SelectQueryBuilder<
|
|
2981
|
+
with<TSub extends TableDef>(name: string, query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
|
|
2946
2982
|
/**
|
|
2947
2983
|
|
|
2948
2984
|
* Adds a recursive Common Table Expression (CTE) to the query
|
|
@@ -2956,7 +2992,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
2956
2992
|
* @returns New query builder instance with the recursive CTE
|
|
2957
2993
|
|
|
2958
2994
|
*/
|
|
2959
|
-
withRecursive(name: string, query: SelectQueryBuilder<
|
|
2995
|
+
withRecursive<TSub extends TableDef>(name: string, query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
|
|
2960
2996
|
/**
|
|
2961
2997
|
* Replaces the FROM clause with a derived table (subquery with alias)
|
|
2962
2998
|
* @param subquery - Subquery to use as the FROM source
|
|
@@ -2964,7 +3000,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
2964
3000
|
* @param columnAliases - Optional column alias list
|
|
2965
3001
|
* @returns New query builder instance with updated FROM
|
|
2966
3002
|
*/
|
|
2967
|
-
fromSubquery(subquery: SelectQueryBuilder<
|
|
3003
|
+
fromSubquery<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, alias: string, columnAliases?: string[]): SelectQueryBuilder<T, TTable>;
|
|
2968
3004
|
/**
|
|
2969
3005
|
|
|
2970
3006
|
* Selects a subquery as a column
|
|
@@ -2976,7 +3012,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
2976
3012
|
* @returns New query builder instance with the subquery selection
|
|
2977
3013
|
|
|
2978
3014
|
*/
|
|
2979
|
-
selectSubquery(alias: string, sub: SelectQueryBuilder<
|
|
3015
|
+
selectSubquery<TSub extends TableDef>(alias: string, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
2980
3016
|
/**
|
|
2981
3017
|
* Adds a JOIN against a derived table (subquery with alias)
|
|
2982
3018
|
* @param subquery - Subquery to join
|
|
@@ -2986,7 +3022,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
2986
3022
|
* @param columnAliases - Optional column alias list for the derived table
|
|
2987
3023
|
* @returns New query builder instance with the derived-table join
|
|
2988
3024
|
*/
|
|
2989
|
-
joinSubquery(subquery: SelectQueryBuilder<
|
|
3025
|
+
joinSubquery<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, alias: string, condition: BinaryExpressionNode, joinKind?: JoinKind, columnAliases?: string[]): SelectQueryBuilder<T, TTable>;
|
|
2990
3026
|
/**
|
|
2991
3027
|
|
|
2992
3028
|
* Adds an INNER JOIN to the query
|
|
@@ -3154,7 +3190,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3154
3190
|
* @returns New query builder instance with the set operation
|
|
3155
3191
|
|
|
3156
3192
|
*/
|
|
3157
|
-
union(query: SelectQueryBuilder<
|
|
3193
|
+
union<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
3158
3194
|
/**
|
|
3159
3195
|
|
|
3160
3196
|
* Combines this query with another using UNION ALL
|
|
@@ -3164,7 +3200,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3164
3200
|
* @returns New query builder instance with the set operation
|
|
3165
3201
|
|
|
3166
3202
|
*/
|
|
3167
|
-
unionAll(query: SelectQueryBuilder<
|
|
3203
|
+
unionAll<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
3168
3204
|
/**
|
|
3169
3205
|
|
|
3170
3206
|
* Combines this query with another using INTERSECT
|
|
@@ -3174,7 +3210,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3174
3210
|
* @returns New query builder instance with the set operation
|
|
3175
3211
|
|
|
3176
3212
|
*/
|
|
3177
|
-
intersect(query: SelectQueryBuilder<
|
|
3213
|
+
intersect<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
3178
3214
|
/**
|
|
3179
3215
|
|
|
3180
3216
|
* Combines this query with another using EXCEPT
|
|
@@ -3184,7 +3220,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3184
3220
|
* @returns New query builder instance with the set operation
|
|
3185
3221
|
|
|
3186
3222
|
*/
|
|
3187
|
-
except(query: SelectQueryBuilder<
|
|
3223
|
+
except<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
3188
3224
|
/**
|
|
3189
3225
|
|
|
3190
3226
|
* Adds a WHERE EXISTS condition to the query
|
|
@@ -3194,7 +3230,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3194
3230
|
* @returns New query builder instance with the WHERE EXISTS condition
|
|
3195
3231
|
|
|
3196
3232
|
*/
|
|
3197
|
-
whereExists(subquery: SelectQueryBuilder<
|
|
3233
|
+
whereExists<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, correlate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
|
|
3198
3234
|
/**
|
|
3199
3235
|
|
|
3200
3236
|
* Adds a WHERE NOT EXISTS condition to the query
|
|
@@ -3204,7 +3240,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
3204
3240
|
* @returns New query builder instance with the WHERE NOT EXISTS condition
|
|
3205
3241
|
|
|
3206
3242
|
*/
|
|
3207
|
-
whereNotExists(subquery: SelectQueryBuilder<
|
|
3243
|
+
whereNotExists<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, correlate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
|
|
3208
3244
|
/**
|
|
3209
3245
|
|
|
3210
3246
|
* Adds a WHERE EXISTS condition based on a relationship
|
|
@@ -3294,12 +3330,12 @@ declare const createLiteral: (val: string | number) => LiteralNode;
|
|
|
3294
3330
|
*/
|
|
3295
3331
|
declare function sel<TTable extends TableDef, K extends keyof TTable['columns'] & string>(table: TTable, ...cols: K[]): Record<K, TTable['columns'][K]>;
|
|
3296
3332
|
type Ctor<T> = {
|
|
3297
|
-
new (...args:
|
|
3333
|
+
new (...args: unknown[]): T;
|
|
3298
3334
|
};
|
|
3299
3335
|
/**
|
|
3300
3336
|
* Build a typed selection map from an entity constructor.
|
|
3301
3337
|
*/
|
|
3302
|
-
declare function esel<TEntity, K extends keyof TEntity & string>(entity: Ctor<TEntity>, ...props: K[]): Record<K, ColumnDef>;
|
|
3338
|
+
declare function esel<TEntity extends object, K extends keyof TEntity & string>(entity: Ctor<TEntity>, ...props: K[]): Record<K, ColumnDef>;
|
|
3303
3339
|
|
|
3304
3340
|
/**
|
|
3305
3341
|
* Maintains immutable state for building INSERT queries
|
|
@@ -3329,7 +3365,7 @@ declare class InsertQueryBuilder<T> {
|
|
|
3329
3365
|
private clone;
|
|
3330
3366
|
values(rowOrRows: Record<string, unknown> | Record<string, unknown>[]): InsertQueryBuilder<T>;
|
|
3331
3367
|
columns(...columns: (ColumnDef | ColumnNode)[]): InsertQueryBuilder<T>;
|
|
3332
|
-
fromSelect(query: SelectQueryNode | SelectQueryBuilder<
|
|
3368
|
+
fromSelect<TSource extends TableDef>(query: SelectQueryNode | SelectQueryBuilder<unknown, TSource>, columns?: (ColumnDef | ColumnNode)[]): InsertQueryBuilder<T>;
|
|
3333
3369
|
returning(...columns: (ColumnDef | ColumnNode)[]): InsertQueryBuilder<T>;
|
|
3334
3370
|
private resolveColumnNodes;
|
|
3335
3371
|
private resolveSelectQuery;
|
|
@@ -3659,6 +3695,7 @@ interface SchemaDialect {
|
|
|
3659
3695
|
renderIndex(table: TableDef, index: IndexDef): string;
|
|
3660
3696
|
renderTableOptions(table: TableDef): string | undefined;
|
|
3661
3697
|
supportsPartialIndexes(): boolean;
|
|
3698
|
+
preferInlinePkAutoincrement(column: ColumnDef, table: TableDef, pk: string[]): boolean;
|
|
3662
3699
|
dropColumnSql?(table: DatabaseTable, column: string): string[];
|
|
3663
3700
|
dropIndexSql?(table: DatabaseTable, index: string): string[];
|
|
3664
3701
|
dropTableSql?(table: DatabaseTable): string[];
|
|
@@ -4054,17 +4091,18 @@ declare class AsyncLocalStorage<T> {
|
|
|
4054
4091
|
getStore(): T | undefined;
|
|
4055
4092
|
}
|
|
4056
4093
|
|
|
4094
|
+
/**
|
|
4095
|
+
* Hydrates query results according to a hydration plan
|
|
4096
|
+
* @param rows - Raw database rows
|
|
4097
|
+
|
|
4057
4098
|
/**
|
|
4058
4099
|
* Hydrates query results according to a hydration plan
|
|
4059
4100
|
* @param rows - Raw database rows
|
|
4060
4101
|
* @param plan - Hydration plan
|
|
4061
4102
|
* @returns Hydrated result objects with nested relations
|
|
4062
4103
|
*/
|
|
4063
|
-
declare const hydrateRows: (rows: Record<string,
|
|
4104
|
+
declare const hydrateRows: (rows: Record<string, unknown>[], plan?: HydrationPlan) => Record<string, unknown>[];
|
|
4064
4105
|
|
|
4065
|
-
/**
|
|
4066
|
-
* Generates TypeScript code from query AST nodes
|
|
4067
|
-
*/
|
|
4068
4106
|
declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandVisitor<string> {
|
|
4069
4107
|
private namingStrategy;
|
|
4070
4108
|
constructor(namingStrategy?: NamingStrategy);
|
|
@@ -4096,6 +4134,8 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
|
|
|
4096
4134
|
* Prints an ordering term (operand/expression/alias) to TypeScript code.
|
|
4097
4135
|
*/
|
|
4098
4136
|
private printOrderingTerm;
|
|
4137
|
+
private getSelectionKey;
|
|
4138
|
+
private isNamedSelection;
|
|
4099
4139
|
visitBinaryExpression(binary: BinaryExpressionNode): string;
|
|
4100
4140
|
visitLogicalExpression(logical: LogicalExpressionNode): string;
|
|
4101
4141
|
visitNullExpression(nullExpr: NullExpressionNode): string;
|
|
@@ -4214,7 +4254,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
|
|
|
4214
4254
|
* @param lazyRelations - Optional lazy relations
|
|
4215
4255
|
* @returns The entity instance
|
|
4216
4256
|
*/
|
|
4217
|
-
declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string,
|
|
4257
|
+
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>;
|
|
4218
4258
|
/**
|
|
4219
4259
|
* Creates an entity instance from a database row.
|
|
4220
4260
|
* @template TTable - The table type
|
|
@@ -4225,12 +4265,12 @@ declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof R
|
|
|
4225
4265
|
* @param lazyRelations - Optional lazy relations
|
|
4226
4266
|
* @returns The entity instance
|
|
4227
4267
|
*/
|
|
4228
|
-
declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string,
|
|
4268
|
+
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;
|
|
4229
4269
|
|
|
4230
|
-
type Rows$3 = Record<string,
|
|
4270
|
+
type Rows$3 = Record<string, unknown>[];
|
|
4231
4271
|
declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: HasManyRelation) => Promise<Map<string, Rows$3>>;
|
|
4232
|
-
declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: HasOneRelation) => Promise<Map<string, Record<string,
|
|
4233
|
-
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToRelation) => Promise<Map<string, Record<string,
|
|
4272
|
+
declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: HasOneRelation) => Promise<Map<string, Record<string, unknown>>>;
|
|
4273
|
+
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToRelation) => Promise<Map<string, Record<string, unknown>>>;
|
|
4234
4274
|
declare const loadBelongsToManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToManyRelation) => Promise<Map<string, Rows$3>>;
|
|
4235
4275
|
|
|
4236
4276
|
/**
|
|
@@ -4245,14 +4285,14 @@ interface EntityMeta<TTable extends TableDef> {
|
|
|
4245
4285
|
/** Relations that should be loaded lazily */
|
|
4246
4286
|
lazyRelations: (keyof RelationMap<TTable>)[];
|
|
4247
4287
|
/** Cache for relation promises */
|
|
4248
|
-
relationCache: Map<string, Promise<
|
|
4288
|
+
relationCache: Map<string, Promise<unknown>>;
|
|
4249
4289
|
/** Hydration data for relations */
|
|
4250
|
-
relationHydration: Map<string, Map<string,
|
|
4290
|
+
relationHydration: Map<string, Map<string, unknown>>;
|
|
4251
4291
|
/** Relation wrapper instances */
|
|
4252
4292
|
relationWrappers: Map<string, unknown>;
|
|
4253
4293
|
}
|
|
4254
4294
|
|
|
4255
|
-
type Rows$2 = Record<string,
|
|
4295
|
+
type Rows$2 = Record<string, unknown>[];
|
|
4256
4296
|
declare class DefaultHasManyCollection<TChild> implements HasManyCollection<TChild> {
|
|
4257
4297
|
private readonly ctx;
|
|
4258
4298
|
private readonly meta;
|
|
@@ -4267,7 +4307,7 @@ declare class DefaultHasManyCollection<TChild> implements HasManyCollection<TChi
|
|
|
4267
4307
|
private items;
|
|
4268
4308
|
private readonly added;
|
|
4269
4309
|
private readonly removed;
|
|
4270
|
-
constructor(ctx: EntityContext, meta: EntityMeta<
|
|
4310
|
+
constructor(ctx: EntityContext, meta: EntityMeta<TableDef>, root: unknown, relationName: string, relation: HasManyRelation, rootTable: TableDef, loader: () => Promise<Map<string, Rows$2>>, createEntity: (row: Record<string, unknown>) => TChild, localKey: string);
|
|
4271
4311
|
load(): Promise<TChild[]>;
|
|
4272
4312
|
getItems(): TChild[];
|
|
4273
4313
|
add(data: Partial<TChild>): TChild;
|
|
@@ -4279,7 +4319,7 @@ declare class DefaultHasManyCollection<TChild> implements HasManyCollection<TChi
|
|
|
4279
4319
|
toJSON(): TChild[];
|
|
4280
4320
|
}
|
|
4281
4321
|
|
|
4282
|
-
type Rows$1 = Record<string,
|
|
4322
|
+
type Rows$1 = Record<string, unknown>;
|
|
4283
4323
|
declare class DefaultBelongsToReference<TParent> implements BelongsToReference<TParent> {
|
|
4284
4324
|
private readonly ctx;
|
|
4285
4325
|
private readonly meta;
|
|
@@ -4292,7 +4332,7 @@ declare class DefaultBelongsToReference<TParent> implements BelongsToReference<T
|
|
|
4292
4332
|
private readonly targetKey;
|
|
4293
4333
|
private loaded;
|
|
4294
4334
|
private current;
|
|
4295
|
-
constructor(ctx: EntityContext, meta: EntityMeta<
|
|
4335
|
+
constructor(ctx: EntityContext, meta: EntityMeta<TableDef>, root: unknown, relationName: string, relation: BelongsToRelation, rootTable: TableDef, loader: () => Promise<Map<string, Rows$1>>, createEntity: (row: Record<string, unknown>) => TParent, targetKey: string);
|
|
4296
4336
|
load(): Promise<TParent | null>;
|
|
4297
4337
|
get(): TParent | null;
|
|
4298
4338
|
set(data: Partial<TParent> | TParent | null): TParent | null;
|
|
@@ -4301,7 +4341,7 @@ declare class DefaultBelongsToReference<TParent> implements BelongsToReference<T
|
|
|
4301
4341
|
toJSON(): TParent | null;
|
|
4302
4342
|
}
|
|
4303
4343
|
|
|
4304
|
-
type Rows = Record<string,
|
|
4344
|
+
type Rows = Record<string, unknown>[];
|
|
4305
4345
|
declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollection<TTarget> {
|
|
4306
4346
|
private readonly ctx;
|
|
4307
4347
|
private readonly meta;
|
|
@@ -4314,7 +4354,7 @@ declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollecti
|
|
|
4314
4354
|
private readonly localKey;
|
|
4315
4355
|
private loaded;
|
|
4316
4356
|
private items;
|
|
4317
|
-
constructor(ctx: EntityContext, meta: EntityMeta<
|
|
4357
|
+
constructor(ctx: EntityContext, meta: EntityMeta<TableDef>, root: unknown, relationName: string, relation: BelongsToManyRelation, rootTable: TableDef, loader: () => Promise<Map<string, Rows>>, createEntity: (row: Record<string, unknown>) => TTarget, localKey: string);
|
|
4318
4358
|
load(): Promise<TTarget[]>;
|
|
4319
4359
|
getItems(): TTarget[];
|
|
4320
4360
|
attach(target: TTarget | number | string): void;
|
|
@@ -4328,14 +4368,13 @@ declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollecti
|
|
|
4328
4368
|
toJSON(): TTarget[];
|
|
4329
4369
|
}
|
|
4330
4370
|
|
|
4331
|
-
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<
|
|
4332
|
-
declare function executeHydratedWithContexts<TTable extends TableDef>(_execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<
|
|
4371
|
+
declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
4372
|
+
declare function executeHydratedWithContexts<TTable extends TableDef>(_execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
|
|
4333
4373
|
|
|
4334
4374
|
interface StandardDecoratorContext {
|
|
4335
4375
|
kind: string;
|
|
4336
4376
|
name?: string | symbol;
|
|
4337
4377
|
metadata?: Record<PropertyKey, unknown>;
|
|
4338
|
-
addInitializer?(initializer: (this: unknown) => void): void;
|
|
4339
4378
|
static?: boolean;
|
|
4340
4379
|
private?: boolean;
|
|
4341
4380
|
}
|
|
@@ -4361,7 +4400,7 @@ interface ColumnOptions {
|
|
|
4361
4400
|
primary?: boolean;
|
|
4362
4401
|
tsType?: ColumnDef['tsType'];
|
|
4363
4402
|
}
|
|
4364
|
-
type ColumnInput = ColumnOptions | ColumnDef
|
|
4403
|
+
type ColumnInput = ColumnOptions | ColumnDef;
|
|
4365
4404
|
declare function Column(definition: ColumnInput): DualModePropertyDecorator;
|
|
4366
4405
|
declare function PrimaryKey(definition: ColumnInput): DualModePropertyDecorator;
|
|
4367
4406
|
|
|
@@ -4396,8 +4435,15 @@ declare function BelongsTo(options: BelongsToOptions): DualModePropertyDecorator
|
|
|
4396
4435
|
declare function BelongsToMany(options: BelongsToManyOptions): DualModePropertyDecorator;
|
|
4397
4436
|
|
|
4398
4437
|
declare const bootstrapEntities: () => TableDef[];
|
|
4399
|
-
declare const getTableDefFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor
|
|
4400
|
-
declare const selectFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor
|
|
4438
|
+
declare const getTableDefFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => TTable | undefined;
|
|
4439
|
+
declare const selectFromEntity: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => SelectQueryBuilder<unknown, TTable>;
|
|
4440
|
+
/**
|
|
4441
|
+
* Public API: opt-in ergonomic entity reference (decorator-level).
|
|
4442
|
+
*
|
|
4443
|
+
* Lazily bootstraps entity metadata (via getTableDefFromEntity) and returns a
|
|
4444
|
+
* `tableRef(...)`-style proxy so users can write `u.id` instead of `u.columns.id`.
|
|
4445
|
+
*/
|
|
4446
|
+
declare const entityRef: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => TableRef$1<TTable>;
|
|
4401
4447
|
|
|
4402
4448
|
type PoolOptions = {
|
|
4403
4449
|
/** Maximum number of live resources (idle + leased). */
|
|
@@ -4459,7 +4505,7 @@ interface PostgresClientLike {
|
|
|
4459
4505
|
declare function createPostgresExecutor(client: PostgresClientLike): DbExecutor;
|
|
4460
4506
|
|
|
4461
4507
|
interface MysqlClientLike {
|
|
4462
|
-
query(sql: string, params?: unknown[]): Promise<[
|
|
4508
|
+
query(sql: string, params?: unknown[]): Promise<[unknown, unknown?]>;
|
|
4463
4509
|
beginTransaction?(): Promise<void>;
|
|
4464
4510
|
commit?(): Promise<void>;
|
|
4465
4511
|
rollback?(): Promise<void>;
|
|
@@ -4542,4 +4588,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
4542
4588
|
*/
|
|
4543
4589
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
4544
4590
|
|
|
4545
|
-
export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type CascadeMode, type CaseExpressionNode, 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, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type 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, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createColumn, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createLiteral, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, getTableDefFromEntity, groupConcat, gt, gte, hasMany, hasOne, hydrateRows, inList, inSubquery, instr, introspectSchema, isCaseExpressionNode, 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, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, sel, selectFromEntity, sign, sin, space, sqrt, sub, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
4591
|
+
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 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, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, 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, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, col, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createColumn, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createLiteral, 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, 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, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, 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 };
|