@danceroutine/tango-orm 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Adapter-DKxAaL4l.d.ts +73 -0
- package/dist/DBClient-DuYcXolQ.d.ts +27 -0
- package/dist/{InternalDialect-ClSaUNso.js → InternalDialect-U3mwJjKA.js} +3 -4
- package/dist/InternalDialect-U3mwJjKA.js.map +1 -0
- package/dist/QuerySetState-CjyvAUBs.d.ts +1310 -0
- package/dist/SqliteAdapter-6oyUmoJf.js +279 -0
- package/dist/SqliteAdapter-6oyUmoJf.js.map +1 -0
- package/dist/chunk-8H4AJuhK.js +14 -0
- package/dist/connection/index.d.ts +4 -11
- package/dist/connection/index.js +3 -6
- package/dist/{connection-Dmhgx31M.js → connection-D-E6_Yf1.js} +28 -30
- package/dist/connection-D-E6_Yf1.js.map +1 -0
- package/dist/{defaultRuntime-DzqBQ9Hb.js → defaultRuntime-CdTX8cXm.js} +41 -35
- package/dist/defaultRuntime-CdTX8cXm.js.map +1 -0
- package/dist/index-B-aibguC.d.ts +226 -0
- package/dist/index-D9B6gKez.d.ts +70 -0
- package/dist/index-rjKca3U_.d.ts +31 -0
- package/dist/index-uuG57Y7C.d.ts +97 -0
- package/dist/index.d.ts +9 -22
- package/dist/index.js +9 -12
- package/dist/manager/index.d.ts +4 -12
- package/dist/manager/index.js +3 -9
- package/dist/{manager-DrDTiCAz.js → manager-CiYqAYpn.js} +7 -11
- package/dist/{manager-DrDTiCAz.js.map → manager-CiYqAYpn.js.map} +1 -1
- package/dist/query/index.d.ts +3 -14
- package/dist/query/index.js +2 -4
- package/dist/{query-DUZnBFhf.js → query-CP1UMIX6.js} +163 -121
- package/dist/query-CP1UMIX6.js.map +1 -0
- package/dist/registerModelObjects-C-MliIiM.d.ts +229 -0
- package/dist/{registerModelObjects-Djpt45KK.js → registerModelObjects-DZfZ20fa.js} +150 -69
- package/dist/registerModelObjects-DZfZ20fa.js.map +1 -0
- package/dist/runtime/index.d.ts +3 -15
- package/dist/runtime/index.js +15 -8
- package/dist/runtime/index.js.map +1 -0
- package/dist/transaction/index.d.ts +2 -6
- package/dist/transaction/index.js +2 -7
- package/dist/{transaction-ZhfDf-f8.js → transaction-2_2m7VUo.js} +26 -10
- package/dist/transaction-2_2m7VUo.js.map +1 -0
- package/package.json +8 -8
- package/dist/InternalDialect-ClSaUNso.js.map +0 -1
- package/dist/PostgresAdapter-CXKdKBG-.js +0 -4
- package/dist/PostgresAdapter-DySFW6vy.js +0 -128
- package/dist/PostgresAdapter-DySFW6vy.js.map +0 -1
- package/dist/SqliteAdapter-CDdOjRmW.js +0 -151
- package/dist/SqliteAdapter-CDdOjRmW.js.map +0 -1
- package/dist/SqliteAdapter-mjtXuVTg.js +0 -4
- package/dist/chunk-DLY2FNSh.js +0 -12
- package/dist/connection/adapters/Adapter.d.ts +0 -60
- package/dist/connection/adapters/AdapterRegistry.d.ts +0 -44
- package/dist/connection/adapters/dialects/PostgresAdapter.d.ts +0 -30
- package/dist/connection/adapters/dialects/SqliteAdapter.d.ts +0 -22
- package/dist/connection/adapters/dialects/index.d.ts +0 -5
- package/dist/connection/adapters/index.d.ts +0 -8
- package/dist/connection/clients/DBClient.d.ts +0 -23
- package/dist/connection/clients/dialects/PostgresClient.d.ts +0 -54
- package/dist/connection/clients/dialects/SqliteClient.d.ts +0 -54
- package/dist/connection/clients/dialects/index.d.ts +0 -5
- package/dist/connection/clients/index.d.ts +0 -7
- package/dist/connection-Dmhgx31M.js.map +0 -1
- package/dist/defaultRuntime-DzqBQ9Hb.js.map +0 -1
- package/dist/manager/ManagerLike.d.ts +0 -34
- package/dist/manager/ModelManager.d.ts +0 -97
- package/dist/manager/internal/MutationCompiler.d.ts +0 -23
- package/dist/manager/internal/RuntimeBoundClient.d.ts +0 -20
- package/dist/manager/registerModelObjects.d.ts +0 -5
- package/dist/manager/relations/ManyToManyRelatedManager.d.ts +0 -181
- package/dist/manager/relations/ManyToManyRelatedQuerySet.d.ts +0 -62
- package/dist/manager/relations/MaterializedModelRecord.d.ts +0 -28
- package/dist/manager/relations/index.d.ts +0 -9
- package/dist/manager/relations/internal/ThroughTableManager.d.ts +0 -85
- package/dist/query/ModelQuerySet.d.ts +0 -20
- package/dist/query/QBuilder.d.ts +0 -29
- package/dist/query/QuerySet.d.ts +0 -215
- package/dist/query/compiler/QueryCompiler.d.ts +0 -49
- package/dist/query/compiler/index.d.ts +0 -4
- package/dist/query/domain/CompiledQuery.d.ts +0 -209
- package/dist/query/domain/Dialect.d.ts +0 -2
- package/dist/query/domain/Direction.d.ts +0 -2
- package/dist/query/domain/FilterInput.d.ts +0 -3
- package/dist/query/domain/FilterKey.d.ts +0 -4
- package/dist/query/domain/FilterValue.d.ts +0 -1
- package/dist/query/domain/LookupType.d.ts +0 -2
- package/dist/query/domain/OrderSpec.d.ts +0 -5
- package/dist/query/domain/OrderToken.d.ts +0 -1
- package/dist/query/domain/QNode.d.ts +0 -9
- package/dist/query/domain/QueryResult.d.ts +0 -35
- package/dist/query/domain/QuerySetState.d.ts +0 -13
- package/dist/query/domain/RelationMeta.d.ts +0 -56
- package/dist/query/domain/RelationTyping.d.ts +0 -163
- package/dist/query/domain/TableMeta.d.ts +0 -16
- package/dist/query/domain/TableMetaFactory.d.ts +0 -10
- package/dist/query/domain/WhereClause.d.ts +0 -4
- package/dist/query/domain/index.d.ts +0 -21
- package/dist/query/domain/internal/InternalDialect.d.ts +0 -4
- package/dist/query/domain/internal/InternalDirection.d.ts +0 -4
- package/dist/query/domain/internal/InternalLookupType.d.ts +0 -15
- package/dist/query/domain/internal/InternalPrefetchQueryKind.d.ts +0 -20
- package/dist/query/domain/internal/InternalQNodeType.d.ts +0 -6
- package/dist/query/domain/internal/InternalRelationKind.d.ts +0 -6
- package/dist/query/internal/isQNodeLike.d.ts +0 -3
- package/dist/query/planning/QueryPlanner.d.ts +0 -16
- package/dist/query/planning/domain/QueryHydrationPlan.d.ts +0 -20
- package/dist/query/planning/index.d.ts +0 -2
- package/dist/query-DUZnBFhf.js.map +0 -1
- package/dist/registerModelObjects-Djpt45KK.js.map +0 -1
- package/dist/runtime/TangoRuntime.d.ts +0 -56
- package/dist/runtime/defaultRuntime.d.ts +0 -13
- package/dist/runtime/internal/DBClientProvider.d.ts +0 -12
- package/dist/runtime/internal/PostgresDBClientProvider.d.ts +0 -12
- package/dist/runtime/internal/SqliteDBClientProvider.d.ts +0 -19
- package/dist/runtime/internal/createDBClientProvider.d.ts +0 -5
- package/dist/runtime-1H88J3nN.js +0 -18
- package/dist/runtime-1H88J3nN.js.map +0 -1
- package/dist/transaction/AtomicTransaction.d.ts +0 -32
- package/dist/transaction/UnitOfWork.d.ts +0 -52
- package/dist/transaction/atomic.d.ts +0 -2
- package/dist/transaction/internal/context/AsyncLocalTransactionEngine.d.ts +0 -21
- package/dist/transaction/internal/context/CallbackRecord.d.ts +0 -5
- package/dist/transaction/internal/context/FrameBoundTransaction.d.ts +0 -20
- package/dist/transaction/internal/context/FrameTransactionHandle.d.ts +0 -4
- package/dist/transaction/internal/context/TransactionEngine.d.ts +0 -16
- package/dist/transaction/internal/context/TransactionFrame.d.ts +0 -7
- package/dist/transaction/internal/context/TransactionState.d.ts +0 -10
- package/dist/transaction/internal/context/index.d.ts +0 -1
- package/dist/transaction-ZhfDf-f8.js.map +0 -1
- package/dist/validation/OrmSqlSafetyAdapter.d.ts +0 -22
- package/dist/validation/SQLValidationEngine.d.ts +0 -68
- package/dist/validation/SqlValidationPlan.d.ts +0 -43
- package/dist/validation/index.d.ts +0 -3
- package/dist/validation/internal/InternalSqlValidationPlanKind.d.ts +0 -25
- package/dist/validation/internal/InternalValidatedFilterDescriptorKind.d.ts +0 -4
|
@@ -0,0 +1,1310 @@
|
|
|
1
|
+
import { t as DBClient } from "./DBClient-DuYcXolQ.js";
|
|
2
|
+
import { i as Dialect, t as Adapter } from "./Adapter-DKxAaL4l.js";
|
|
3
|
+
import { SqlSafetyEngine } from "@danceroutine/tango-core";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { Model, PersistedModelOutput } from "@danceroutine/tango-schema/domain";
|
|
6
|
+
import { DecoratedFieldKind, InternalDecoratedFieldKind, RelationDecoratedSchema } from "@danceroutine/tango-schema/model";
|
|
7
|
+
|
|
8
|
+
//#region src/query/domain/QueryResult.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Values materialized by {@link QuerySet.fetch}, iterable like an array plus `length`, `map`, `at`, and `toArray`.
|
|
11
|
+
*
|
|
12
|
+
* Prefer iteration or `items` over the deprecated `results` getter, which warns once per process when accessed.
|
|
13
|
+
*/
|
|
14
|
+
declare class QueryResult<T> implements Iterable<T> {
|
|
15
|
+
static readonly BRAND: "tango.orm.query_result";
|
|
16
|
+
readonly __tangoBrand: typeof QueryResult.BRAND;
|
|
17
|
+
readonly items: readonly T[];
|
|
18
|
+
constructor(items: readonly T[]);
|
|
19
|
+
/**
|
|
20
|
+
* Runtime narrowing for values that may be a plain array or a `QueryResult` instance.
|
|
21
|
+
*/
|
|
22
|
+
static isQueryResult<T>(value: unknown): value is QueryResult<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Sync iteration over materialized rows.
|
|
25
|
+
*/
|
|
26
|
+
[Symbol.iterator](): Iterator<T>;
|
|
27
|
+
/** Number of materialized rows. */
|
|
28
|
+
get length(): number;
|
|
29
|
+
/** Same as `Array#map` on the materialized rows. */
|
|
30
|
+
map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U, thisArg?: unknown): U[];
|
|
31
|
+
/** Indexed read with support for negative indices, like `Array#at`. */
|
|
32
|
+
at(index: number): T | undefined;
|
|
33
|
+
/** Returns a shallow copy of the materialized rows as a plain array. */
|
|
34
|
+
toArray(): T[];
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use iteration, `length`, `map`, or `toArray()` instead.
|
|
37
|
+
*/
|
|
38
|
+
get results(): readonly T[];
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/query/domain/internal/InternalRelationKind.d.ts
|
|
42
|
+
declare const InternalRelationKind: {
|
|
43
|
+
readonly HAS_MANY: "hasMany";
|
|
44
|
+
readonly BELONGS_TO: "belongsTo";
|
|
45
|
+
readonly HAS_ONE: "hasOne";
|
|
46
|
+
readonly MANY_TO_MANY: "manyToMany";
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/query/domain/TableMeta.d.ts
|
|
50
|
+
/**
|
|
51
|
+
* SQL-facing model metadata visible to the ORM layer.
|
|
52
|
+
*/
|
|
53
|
+
interface TableMeta {
|
|
54
|
+
/** Stable model key when the table comes from a registered Tango model. */
|
|
55
|
+
modelKey?: string;
|
|
56
|
+
/** Physical table name used in compiled SQL. */
|
|
57
|
+
table: string;
|
|
58
|
+
/** Primary key column name. */
|
|
59
|
+
pk: string;
|
|
60
|
+
/** Base columns and their storage types. */
|
|
61
|
+
columns: Record<string, string>;
|
|
62
|
+
/** Relation metadata keyed by public relation name. */
|
|
63
|
+
relations?: Record<string, RelationMeta>;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/query/compiler/QueryCompiler.d.ts
|
|
67
|
+
/**
|
|
68
|
+
* Compiles immutable `QuerySet` state into parameterized SQL and recursive
|
|
69
|
+
* hydration execution artifacts.
|
|
70
|
+
*/
|
|
71
|
+
declare class QueryCompiler {
|
|
72
|
+
private meta;
|
|
73
|
+
private adapter;
|
|
74
|
+
static readonly BRAND: "tango.orm.query_compiler";
|
|
75
|
+
readonly __tangoBrand: typeof QueryCompiler.BRAND;
|
|
76
|
+
private readonly placeholders;
|
|
77
|
+
constructor(meta: TableMeta, adapter: Adapter);
|
|
78
|
+
static isQueryCompiler(value: unknown): value is QueryCompiler;
|
|
79
|
+
compile<T, TSourceModel = unknown>(state: QuerySetState<T, TSourceModel>): CompiledQuery;
|
|
80
|
+
compilePrefetch(node: CompiledHydrationNode, sourceValues: readonly (string | number)[]): CompiledPrefetchQuery;
|
|
81
|
+
compileManyToManyTargets(node: CompiledHydrationNode, targetIds: readonly (string | number)[]): {
|
|
82
|
+
sql: string;
|
|
83
|
+
params: readonly unknown[];
|
|
84
|
+
};
|
|
85
|
+
private compileManyToManyPrefetch;
|
|
86
|
+
private compileHydrationNode;
|
|
87
|
+
private validateHydrationRelation;
|
|
88
|
+
private buildRootHiddenSelects;
|
|
89
|
+
private validatePrefetchTarget;
|
|
90
|
+
private collectNestedJoinSql;
|
|
91
|
+
private validatePrefetchJoinTarget;
|
|
92
|
+
private validateInternalAlias;
|
|
93
|
+
private buildJoinAlias;
|
|
94
|
+
private buildPrefetchBaseAlias;
|
|
95
|
+
private buildHydrationColumnAlias;
|
|
96
|
+
private buildPrefetchSourceAlias;
|
|
97
|
+
private buildFilterAlias;
|
|
98
|
+
private sanitizeRelationPath;
|
|
99
|
+
private assertInternalAliasDoesNotCollide;
|
|
100
|
+
private compileQNode;
|
|
101
|
+
private compileAtom;
|
|
102
|
+
private compileAnd;
|
|
103
|
+
private compileOr;
|
|
104
|
+
private compileNot;
|
|
105
|
+
private compileRelationFilter;
|
|
106
|
+
private buildRelationFilterExists;
|
|
107
|
+
private lookupToSQL;
|
|
108
|
+
private normalizeParam;
|
|
109
|
+
private collectStateFilterKeys;
|
|
110
|
+
private collectNodeFilterKeys;
|
|
111
|
+
}
|
|
112
|
+
declare namespace index_d_exports$2 {
|
|
113
|
+
export { QueryCompiler };
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/query/domain/internal/InternalLookupType.d.ts
|
|
117
|
+
declare const InternalLookupType: {
|
|
118
|
+
readonly EXACT: "exact";
|
|
119
|
+
readonly LT: "lt";
|
|
120
|
+
readonly LTE: "lte";
|
|
121
|
+
readonly GT: "gt";
|
|
122
|
+
readonly GTE: "gte";
|
|
123
|
+
readonly IN: "in";
|
|
124
|
+
readonly ISNULL: "isnull";
|
|
125
|
+
readonly CONTAINS: "contains";
|
|
126
|
+
readonly ICONTAINS: "icontains";
|
|
127
|
+
readonly STARTSWITH: "startswith";
|
|
128
|
+
readonly ISTARTSWITH: "istartswith";
|
|
129
|
+
readonly ENDSWITH: "endswith";
|
|
130
|
+
readonly IENDSWITH: "iendswith";
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/query/domain/LookupType.d.ts
|
|
134
|
+
type LookupType = (typeof InternalLookupType)[keyof typeof InternalLookupType];
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/query/domain/FilterKey.d.ts
|
|
137
|
+
type ScalarFilterKey<T> = Extract<keyof T, string> | `${Extract<keyof T, string>}__${LookupType}`;
|
|
138
|
+
type FilterKey<T, _TSourceModel = unknown> = ScalarFilterKey<T> | string;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/query/domain/FilterValue.d.ts
|
|
141
|
+
type FilterValue = string | number | boolean | Date | null | undefined | Array<string | number>;
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/query/domain/FilterInput.d.ts
|
|
144
|
+
type FilterInput<T, TSourceModel = unknown> = Partial<Record<FilterKey<T, TSourceModel>, FilterValue>>;
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/query/domain/internal/InternalQNodeType.d.ts
|
|
147
|
+
declare const InternalQNodeType: {
|
|
148
|
+
readonly ATOM: "atom";
|
|
149
|
+
readonly AND: "and";
|
|
150
|
+
readonly OR: "or";
|
|
151
|
+
readonly NOT: "not";
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/query/domain/QNode.d.ts
|
|
155
|
+
type QNodeType = (typeof InternalQNodeType)[keyof typeof InternalQNodeType];
|
|
156
|
+
interface QNode<T, TSourceModel = unknown> {
|
|
157
|
+
kind: QNodeType;
|
|
158
|
+
where?: FilterInput<T, TSourceModel>;
|
|
159
|
+
nodes?: QNode<T, TSourceModel>[];
|
|
160
|
+
node?: QNode<T, TSourceModel>;
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/query/domain/OrderToken.d.ts
|
|
164
|
+
type OrderToken<T> = keyof T | `-${string & keyof T}`;
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/query/QuerySet.d.ts
|
|
167
|
+
/**
|
|
168
|
+
* Query execution seam consumed by `QuerySet`.
|
|
169
|
+
*
|
|
170
|
+
* Application code usually reaches this through `Model.objects` or testing
|
|
171
|
+
* fixtures rather than implementing it directly.
|
|
172
|
+
*
|
|
173
|
+
* @template TModel - The model row type returned by the database client
|
|
174
|
+
*/
|
|
175
|
+
interface QueryExecutor<TModel> {
|
|
176
|
+
meta: TableMeta;
|
|
177
|
+
client: DBClient;
|
|
178
|
+
adapter: Adapter;
|
|
179
|
+
run(compiled: CompiledQuery): Promise<TModel[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Optional hook invoked by `QuerySet` after a record has been
|
|
182
|
+
* materialized so executors can attach related-manager accessors
|
|
183
|
+
* (such as the many-to-many related manager) onto the record.
|
|
184
|
+
*
|
|
185
|
+
* The optional `modelKey` argument lets the executor route the attach
|
|
186
|
+
* call to the correct model when the record belongs to a related
|
|
187
|
+
* model rather than the executor's own source model. Implementations
|
|
188
|
+
* must not overwrite existing properties on the record so prior
|
|
189
|
+
* hydration assignments survive the attach pass.
|
|
190
|
+
*/
|
|
191
|
+
attachPersistedRecordAccessors?(record: Record<string, unknown>, modelKey?: string): void;
|
|
192
|
+
}
|
|
193
|
+
type QueryShapeFunction<TInput, TOutput> = (row: TInput) => TOutput;
|
|
194
|
+
type QueryShapeParser<TInput, TOutput> = {
|
|
195
|
+
parse: (row: TInput) => TOutput;
|
|
196
|
+
};
|
|
197
|
+
type QueryShape<TInput> = QueryShapeFunction<TInput, unknown> | QueryShapeParser<TInput, unknown>;
|
|
198
|
+
type QueryShapeOutput<TInput, TShape> = TShape extends QueryShapeFunction<TInput, infer TOutput> ? TOutput : TShape extends QueryShapeParser<TInput, infer TOutput> ? TOutput : never;
|
|
199
|
+
type ProjectedResult<TModel extends Record<string, unknown>, TKeys extends readonly (keyof TModel)[]> = number extends TKeys['length'] ? TModel : [TKeys[number]] extends [never] ? TModel : Pick<TModel, TKeys[number]>;
|
|
200
|
+
/**
|
|
201
|
+
* Django-inspired query builder for constructing and executing database queries.
|
|
202
|
+
* Provides a fluent API for filtering, ordering, pagination, projection, and
|
|
203
|
+
* nested relation hydration.
|
|
204
|
+
*
|
|
205
|
+
* @template TModel - The full model row type used for query composition
|
|
206
|
+
* @template TBaseResult - The selected base-row shape returned by execution methods
|
|
207
|
+
* @template TSourceModel - The source Tango model used for typed relation metadata
|
|
208
|
+
* @template THydrated - Relation properties accumulated by eager-loading calls
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const users = await TodoModel.objects
|
|
213
|
+
* .query()
|
|
214
|
+
* .filter({ active: true })
|
|
215
|
+
* .filter(Q.or({ role: 'admin' }, { role: 'moderator' }))
|
|
216
|
+
* .orderBy('-createdAt')
|
|
217
|
+
* .limit(10)
|
|
218
|
+
* .fetch();
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
declare abstract class QuerySet<TModel extends Record<string, unknown>, TBaseResult extends Record<string, unknown> = TModel, TSourceModel = unknown, THydrated extends Record<string, unknown> = Record<never, never>> implements AsyncIterable<HydratedQueryResult<TBaseResult, THydrated>> {
|
|
222
|
+
protected executor: QueryExecutor<TModel>;
|
|
223
|
+
protected state: QuerySetState<TModel, TSourceModel>;
|
|
224
|
+
static readonly BRAND: "tango.orm.query_set";
|
|
225
|
+
readonly __tangoBrand: typeof QuerySet.BRAND;
|
|
226
|
+
private evaluationCache?;
|
|
227
|
+
constructor(executor: QueryExecutor<TModel>, state?: QuerySetState<TModel, TSourceModel>);
|
|
228
|
+
/**
|
|
229
|
+
* Create another queryset of the same runtime family with the supplied
|
|
230
|
+
* query state. Concrete subclasses implement this so fluent calls keep
|
|
231
|
+
* their subclass-specific execution behavior instead of falling back to
|
|
232
|
+
* the standard queryset implementation.
|
|
233
|
+
*/
|
|
234
|
+
protected abstract spawn<TNextBaseResult extends Record<string, unknown> = TBaseResult, TNextHydrated extends Record<string, unknown> = THydrated>(state: QuerySetState<TModel, TSourceModel>): QuerySet<TModel, TNextBaseResult, TSourceModel, TNextHydrated>;
|
|
235
|
+
/**
|
|
236
|
+
* Narrow an unknown value to `QuerySet`.
|
|
237
|
+
*/
|
|
238
|
+
static isQuerySet<TModel extends Record<string, unknown>, TResult extends Record<string, unknown> = TModel>(value: unknown): value is QuerySet<TModel, TResult>;
|
|
239
|
+
/**
|
|
240
|
+
* Translate user-facing order tokens like `'name'` or `'-createdAt'` into
|
|
241
|
+
* the internal `OrderSpec` array used by `QuerySetState`.
|
|
242
|
+
*
|
|
243
|
+
* Exposed as `protected` so subclasses can compose the same parse logic
|
|
244
|
+
* when they need to return their own concrete type from `orderBy` without
|
|
245
|
+
* reaching into a base-class instance's protected state.
|
|
246
|
+
*/
|
|
247
|
+
protected static buildOrderSpecs<T extends Record<string, unknown>>(tokens: readonly OrderToken<T>[]): OrderSpec<T>[];
|
|
248
|
+
private static invertOrderSpec;
|
|
249
|
+
/**
|
|
250
|
+
* Add a filter expression to the query.
|
|
251
|
+
*
|
|
252
|
+
* Multiple `filter()` calls are composed with `AND`.
|
|
253
|
+
*/
|
|
254
|
+
filter(q: FilterInput<TModel, TSourceModel> | QNode<TModel, TSourceModel>): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
255
|
+
/**
|
|
256
|
+
* Add an exclusion expression to the query.
|
|
257
|
+
*
|
|
258
|
+
* Exclusions are translated to `NOT (...)` predicates.
|
|
259
|
+
*/
|
|
260
|
+
exclude(q: FilterInput<TModel, TSourceModel> | QNode<TModel, TSourceModel>): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
261
|
+
/**
|
|
262
|
+
* Apply ordering tokens such as `'name'` or `'-createdAt'`.
|
|
263
|
+
*/
|
|
264
|
+
orderBy(...tokens: OrderToken<TModel>[]): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
265
|
+
/**
|
|
266
|
+
* Limit the maximum number of rows returned.
|
|
267
|
+
*/
|
|
268
|
+
limit(n: number): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
269
|
+
/**
|
|
270
|
+
* Skip the first `n` rows.
|
|
271
|
+
*/
|
|
272
|
+
offset(n: number): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
273
|
+
/**
|
|
274
|
+
* Restrict selected fields and narrow the fetched row type when the
|
|
275
|
+
* selected keys are known precisely at the call site.
|
|
276
|
+
*
|
|
277
|
+
* Empty selections reset back to the full model row, and repeated
|
|
278
|
+
* `select(...)` calls replace the previous projection rather than
|
|
279
|
+
* intersecting it.
|
|
280
|
+
*/
|
|
281
|
+
select<const TKeys extends readonly (keyof TModel)[]>(fields: TKeys): QuerySet<TModel, ProjectedResult<TModel, TKeys>, TSourceModel, THydrated>;
|
|
282
|
+
select(fields: readonly (keyof TModel)[]): QuerySet<TModel, ProjectedResult<TModel, readonly (keyof TModel)[]>, TSourceModel, THydrated>;
|
|
283
|
+
/**
|
|
284
|
+
* Hydrate single-valued relation paths through SQL joins.
|
|
285
|
+
*
|
|
286
|
+
* Forward `belongsTo` relations can be inferred from the source model's
|
|
287
|
+
* field-authored relation metadata. Reverse `hasOne` relations can be
|
|
288
|
+
* selected with a target model generic when the target model points back to
|
|
289
|
+
* the source model. Generated relation typing also enables nested `__`
|
|
290
|
+
* path keys for applications that keep the app-local registry current.
|
|
291
|
+
*/
|
|
292
|
+
selectRelated<TTargetModel = undefined, const TRelationName extends RelationKeys<SelectRelatedRelations<TSourceModel, NoInfer<TTargetModel>>> | GeneratedSelectRelatedPathKeys<TSourceModel> = RelationKeys<SelectRelatedRelations<TSourceModel, NoInfer<TTargetModel>>> | GeneratedSelectRelatedPathKeys<TSourceModel>>(...rels: readonly TRelationName[]): QuerySet<TModel, TBaseResult, TSourceModel, THydrated & MaybeHydratedRelationMap<TSourceModel, SelectRelatedRelations<TSourceModel, NoInfer<TTargetModel>>, Extract<TRelationName, RelationKeys<SelectRelatedRelations<TSourceModel, NoInfer<TTargetModel>>>>, SingleRelationHydrationCardinality> & GeneratedHydratedRelationMap<TSourceModel, Extract<TRelationName, GeneratedSelectRelatedPathKeys<TSourceModel>>>>;
|
|
293
|
+
/**
|
|
294
|
+
* Hydrate collection-rooted relation paths with follow-up queries.
|
|
295
|
+
*
|
|
296
|
+
* Reverse `hasMany` relations can be prefetched with a target model generic
|
|
297
|
+
* when the target model points back to the source model. Generated relation
|
|
298
|
+
* typing also enables nested `__` path keys for applications that keep the
|
|
299
|
+
* app-local registry current.
|
|
300
|
+
*/
|
|
301
|
+
prefetchRelated<TTargetModel = undefined, const TRelationName extends RelationKeys<PrefetchRelatedRelations<TSourceModel, NoInfer<TTargetModel>>> | GeneratedPrefetchRelatedPathKeys<TSourceModel> = RelationKeys<PrefetchRelatedRelations<TSourceModel, NoInfer<TTargetModel>>> | GeneratedPrefetchRelatedPathKeys<TSourceModel>>(...rels: readonly TRelationName[]): QuerySet<TModel, TBaseResult, TSourceModel, THydrated & MaybeHydratedRelationMap<TSourceModel, PrefetchRelatedRelations<TSourceModel, NoInfer<TTargetModel>>, Extract<TRelationName, RelationKeys<PrefetchRelatedRelations<TSourceModel, NoInfer<TTargetModel>>>>, ManyRelationHydrationCardinality> & GeneratedHydratedRelationMap<TSourceModel, Extract<TRelationName, GeneratedPrefetchRelatedPathKeys<TSourceModel>>>>;
|
|
302
|
+
all(): QuerySet<TModel, TBaseResult, TSourceModel, THydrated>;
|
|
303
|
+
/**
|
|
304
|
+
* Execute the query and optionally shape each row.
|
|
305
|
+
*
|
|
306
|
+
* When the queryset has been narrowed by `select(...)`, rows passed to the
|
|
307
|
+
* shaping callback or parser use that narrowed fetched-row type.
|
|
308
|
+
*/
|
|
309
|
+
fetch(): Promise<QueryResult<HydratedQueryResult<TBaseResult, THydrated>>>;
|
|
310
|
+
fetch<Out>(shape: QueryShapeFunction<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<QueryResult<Out>>;
|
|
311
|
+
fetch<Out>(shape: QueryShapeParser<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<QueryResult<Out>>;
|
|
312
|
+
fetch<TShape extends QueryShape<HydratedQueryResult<TBaseResult, THydrated>> | undefined>(shape: TShape): Promise<QueryResult<HydratedQueryResult<TBaseResult, THydrated> | QueryShapeOutput<HydratedQueryResult<TBaseResult, THydrated>, NonNullable<TShape>>>>;
|
|
313
|
+
/**
|
|
314
|
+
* Async iterable surface for `for await (... of queryset)`.
|
|
315
|
+
*
|
|
316
|
+
* Evaluates this queryset on first use by awaiting `fetch()` without
|
|
317
|
+
* arguments, then yields each element from that materialized result.
|
|
318
|
+
* Later async iterations over the same queryset instance reuse the cached
|
|
319
|
+
* materialized result instead of issuing another database round-trip.
|
|
320
|
+
*/
|
|
321
|
+
[Symbol.asyncIterator](): AsyncIterator<HydratedQueryResult<TBaseResult, THydrated>>;
|
|
322
|
+
/**
|
|
323
|
+
* Execute the query and return the first row, or `null`.
|
|
324
|
+
*
|
|
325
|
+
* As with `fetch(...)`, parser and function overloads receive the current
|
|
326
|
+
* fetched-row type after any `select(...)` projection narrowing.
|
|
327
|
+
*/
|
|
328
|
+
fetchOne(): Promise<HydratedQueryResult<TBaseResult, THydrated> | null>;
|
|
329
|
+
fetchOne<Out>(shape: QueryShapeFunction<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
330
|
+
fetchOne<Out>(shape: QueryShapeParser<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
331
|
+
fetchOne<TShape extends QueryShape<HydratedQueryResult<TBaseResult, THydrated>> | undefined>(shape: TShape): Promise<HydratedQueryResult<TBaseResult, THydrated> | QueryShapeOutput<HydratedQueryResult<TBaseResult, THydrated>, NonNullable<TShape>> | null>;
|
|
332
|
+
first(): Promise<HydratedQueryResult<TBaseResult, THydrated> | null>;
|
|
333
|
+
first<Out>(shape: QueryShapeFunction<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
334
|
+
first<Out>(shape: QueryShapeParser<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
335
|
+
last(): Promise<HydratedQueryResult<TBaseResult, THydrated> | null>;
|
|
336
|
+
last<Out>(shape: QueryShapeFunction<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
337
|
+
last<Out>(shape: QueryShapeParser<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out | null>;
|
|
338
|
+
get(q: FilterInput<TModel, TSourceModel> | QNode<TModel, TSourceModel>): Promise<HydratedQueryResult<TBaseResult, THydrated>>;
|
|
339
|
+
get<Out>(q: FilterInput<TModel, TSourceModel> | QNode<TModel, TSourceModel>, shape: QueryShapeFunction<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out>;
|
|
340
|
+
get<Out>(q: FilterInput<TModel, TSourceModel> | QNode<TModel, TSourceModel>, shape: QueryShapeParser<HydratedQueryResult<TBaseResult, THydrated>, Out>): Promise<Out>;
|
|
341
|
+
/**
|
|
342
|
+
* Execute a `COUNT(*)` query for the current filtered state.
|
|
343
|
+
*/
|
|
344
|
+
count(): Promise<number>;
|
|
345
|
+
/**
|
|
346
|
+
* Return whether at least one row matches the current query state.
|
|
347
|
+
*/
|
|
348
|
+
exists(): Promise<boolean>;
|
|
349
|
+
private shapeFetchedRow;
|
|
350
|
+
private getOrCreateEvaluationCache;
|
|
351
|
+
private evaluateRows;
|
|
352
|
+
private normalizeRowsForSchemaParsing;
|
|
353
|
+
private normalizeHydratedRowsForParserShape;
|
|
354
|
+
private hydrateRows;
|
|
355
|
+
private primeManyToManyOwnerCache;
|
|
356
|
+
private attachRootRecordAccessors;
|
|
357
|
+
private hydrateJoinNodesForOwner;
|
|
358
|
+
private hydratePrefetchNode;
|
|
359
|
+
private chunkValues;
|
|
360
|
+
private groupOwnersByAccessor;
|
|
361
|
+
private canonicalizeEntity;
|
|
362
|
+
private normalizeTargetRow;
|
|
363
|
+
private normalizeColumnValue;
|
|
364
|
+
private isBooleanColumnType;
|
|
365
|
+
private normalizeSqliteBoolean;
|
|
366
|
+
private normalizeBooleanColumns;
|
|
367
|
+
private withoutHydrationState;
|
|
368
|
+
}
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/query/ModelQuerySet.d.ts
|
|
371
|
+
/**
|
|
372
|
+
* Concrete `QuerySet` implementation returned by `Model.objects.query()`.
|
|
373
|
+
*
|
|
374
|
+
* It executes the accumulated queryset state directly against the bound
|
|
375
|
+
* model executor.
|
|
376
|
+
*/
|
|
377
|
+
declare class ModelQuerySet<TModel extends Record<string, unknown>, TBaseResult extends Record<string, unknown> = TModel, TSourceModel = unknown, THydrated extends Record<string, unknown> = Record<never, never>> extends QuerySet<TModel, TBaseResult, TSourceModel, THydrated> {
|
|
378
|
+
constructor(executor: QueryExecutor<TModel>, state?: QuerySetState<TModel, TSourceModel>);
|
|
379
|
+
protected spawn<TNextBaseResult extends Record<string, unknown> = TBaseResult, TNextHydrated extends Record<string, unknown> = THydrated>(state: QuerySetState<TModel, TSourceModel>): ModelQuerySet<TModel, TNextBaseResult, TSourceModel, TNextHydrated>;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/query/QBuilder.d.ts
|
|
383
|
+
/**
|
|
384
|
+
* Static builder for composing boolean query expressions.
|
|
385
|
+
*
|
|
386
|
+
* This mirrors Django's `Q(...)` composition patterns and is intended
|
|
387
|
+
* for ergonomic construction of nested `AND`/`OR`/`NOT` trees.
|
|
388
|
+
*/
|
|
389
|
+
declare class QBuilder {
|
|
390
|
+
static readonly BRAND: "tango.orm.q_builder";
|
|
391
|
+
readonly __tangoBrand: typeof QBuilder.BRAND;
|
|
392
|
+
/**
|
|
393
|
+
* Narrow an unknown value to `QBuilder`.
|
|
394
|
+
*/
|
|
395
|
+
static isQBuilder(value: unknown): value is QBuilder;
|
|
396
|
+
/**
|
|
397
|
+
* Combine multiple filter fragments using logical `AND`.
|
|
398
|
+
*/
|
|
399
|
+
static and<T, TSourceModel = unknown>(...nodes: Array<FilterInput<T, TSourceModel> | QNode<T, TSourceModel>>): QNode<T, TSourceModel>;
|
|
400
|
+
/**
|
|
401
|
+
* Combine multiple filter fragments using logical `OR`.
|
|
402
|
+
*/
|
|
403
|
+
static or<T, TSourceModel = unknown>(...nodes: Array<FilterInput<T, TSourceModel> | QNode<T, TSourceModel>>): QNode<T, TSourceModel>;
|
|
404
|
+
/**
|
|
405
|
+
* Negate a filter fragment using logical `NOT`.
|
|
406
|
+
*/
|
|
407
|
+
static not<T, TSourceModel = unknown>(node: FilterInput<T, TSourceModel> | QNode<T, TSourceModel>): QNode<T, TSourceModel>;
|
|
408
|
+
private static wrapNode;
|
|
409
|
+
}
|
|
410
|
+
declare namespace index_d_exports$1 {
|
|
411
|
+
export { CompiledQuery, Dialect, Direction, FilterInput, FilterKey, FilterValue, ForwardSingleRelations, GeneratedHydratedRelationMap, GeneratedPrefetchRelatedPathKeys, GeneratedRelationFilterKeys, GeneratedSelectRelatedPathKeys, HydratedQueryResult, HydratedRelationMap, InternalRelationHydrationCardinality, LookupType, ManyRelationHydrationCardinality, MaybeHydratedRelationMap, ModelQuerySet, OrderSpec, OrderToken, PrefetchRelatedRelations, QBuilder as Q, QBuilder, QNode, QueryCompiler, QueryExecutor, QueryResult, QuerySet, QuerySetState, RelationHydrationCardinality, RelationKeys, RelationMeta, ReverseCollectionRelations, ReverseSingleRelations, SelectRelatedRelations, SingleRelationHydrationCardinality, TableMeta, TableMetaFactory, WhereClause, index_d_exports$2 as compiler, index_d_exports as domain };
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/validation/internal/InternalSqlValidationPlanKind.d.ts
|
|
415
|
+
/**
|
|
416
|
+
* Discriminator strings for {@link SqlValidationPlan} / {@link ValidatedSqlPlan}: which validation
|
|
417
|
+
* branch {@link OrmSqlSafetyAdapter} runs before SQL is assembled or executed.
|
|
418
|
+
*/
|
|
419
|
+
declare const InternalSqlValidationPlanKind: {
|
|
420
|
+
/**
|
|
421
|
+
* Read/query validation: table metadata, projected columns, `WHERE` filter keys, ordering, and
|
|
422
|
+
* optional relation handles. Used when compiling selects (including M2M through-table selects
|
|
423
|
+
* issued inside prefetch compilation).
|
|
424
|
+
*/
|
|
425
|
+
readonly SELECT: "select";
|
|
426
|
+
/**
|
|
427
|
+
* Insert validation: resolved write columns for `INSERT … VALUES`.
|
|
428
|
+
*/
|
|
429
|
+
readonly INSERT: "insert";
|
|
430
|
+
/**
|
|
431
|
+
* Update validation: resolved write columns for `UPDATE … SET`.
|
|
432
|
+
*/
|
|
433
|
+
readonly UPDATE: "update";
|
|
434
|
+
/**
|
|
435
|
+
* Delete validation: scope delete-by-primary-key against validated table metadata.
|
|
436
|
+
*/
|
|
437
|
+
readonly DELETE: "delete";
|
|
438
|
+
};
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/validation/SqlValidationPlan.d.ts
|
|
441
|
+
/**
|
|
442
|
+
* Validation request for read/query compilation.
|
|
443
|
+
*
|
|
444
|
+
* The ORM uses this plan to validate selected fields, filter keys, ordering,
|
|
445
|
+
* and relation names before SQL is assembled.
|
|
446
|
+
*/
|
|
447
|
+
type SelectSqlValidationPlan = {
|
|
448
|
+
kind: typeof InternalSqlValidationPlanKind.SELECT;
|
|
449
|
+
meta: TableMeta;
|
|
450
|
+
selectFields?: readonly string[];
|
|
451
|
+
filterKeys?: readonly string[];
|
|
452
|
+
orderFields?: readonly string[];
|
|
453
|
+
relationNames?: readonly string[];
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Validation request for insert statements.
|
|
457
|
+
*/
|
|
458
|
+
type InsertSqlValidationPlan = {
|
|
459
|
+
kind: typeof InternalSqlValidationPlanKind.INSERT;
|
|
460
|
+
meta: TableMeta;
|
|
461
|
+
writeKeys: readonly string[];
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Validation request for update statements.
|
|
465
|
+
*/
|
|
466
|
+
type UpdateSqlValidationPlan = {
|
|
467
|
+
kind: typeof InternalSqlValidationPlanKind.UPDATE;
|
|
468
|
+
meta: TableMeta;
|
|
469
|
+
writeKeys: readonly string[];
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Validation request for delete statements.
|
|
473
|
+
*/
|
|
474
|
+
type DeleteSqlValidationPlan = {
|
|
475
|
+
kind: typeof InternalSqlValidationPlanKind.DELETE;
|
|
476
|
+
meta: TableMeta;
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* ORM-local SQL validation requests routed through `OrmSqlSafetyAdapter`.
|
|
480
|
+
*/
|
|
481
|
+
type SqlValidationPlan = SelectSqlValidationPlan | InsertSqlValidationPlan | UpdateSqlValidationPlan | DeleteSqlValidationPlan;
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/validation/internal/InternalValidatedFilterDescriptorKind.d.ts
|
|
484
|
+
declare const InternalValidatedFilterDescriptorKind: {
|
|
485
|
+
readonly COLUMN: "column";
|
|
486
|
+
readonly RELATION: "relation";
|
|
487
|
+
};
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/validation/SQLValidationEngine.d.ts
|
|
490
|
+
type ValidatedRelationMeta = RelationMeta & {
|
|
491
|
+
table: string;
|
|
492
|
+
alias: string;
|
|
493
|
+
sourceKey: string;
|
|
494
|
+
targetKey: string;
|
|
495
|
+
targetPrimaryKey: string;
|
|
496
|
+
targetColumns: Record<string, string>;
|
|
497
|
+
throughTable?: string;
|
|
498
|
+
throughSourceKey?: string;
|
|
499
|
+
throughTargetKey?: string;
|
|
500
|
+
};
|
|
501
|
+
type ValidatedTableMeta = {
|
|
502
|
+
table: string;
|
|
503
|
+
pk: string;
|
|
504
|
+
columns: Record<string, string>;
|
|
505
|
+
relations?: Record<string, ValidatedRelationMeta>;
|
|
506
|
+
};
|
|
507
|
+
type ValidatedColumnFilterDescriptor = {
|
|
508
|
+
kind: typeof InternalValidatedFilterDescriptorKind.COLUMN;
|
|
509
|
+
rawKey: string;
|
|
510
|
+
field: string;
|
|
511
|
+
lookup: LookupType;
|
|
512
|
+
qualifiedColumn: string;
|
|
513
|
+
};
|
|
514
|
+
type ValidatedRelationFilterDescriptor = {
|
|
515
|
+
kind: typeof InternalValidatedFilterDescriptorKind.RELATION;
|
|
516
|
+
rawKey: string;
|
|
517
|
+
field: string;
|
|
518
|
+
lookup: LookupType;
|
|
519
|
+
relationPath: string;
|
|
520
|
+
relationChain: ValidatedRelationMeta[];
|
|
521
|
+
terminalColumn: string;
|
|
522
|
+
};
|
|
523
|
+
type ValidatedFilterDescriptor = ValidatedColumnFilterDescriptor | ValidatedRelationFilterDescriptor;
|
|
524
|
+
type ValidatedSelectSqlPlan = {
|
|
525
|
+
kind: typeof InternalSqlValidationPlanKind.SELECT;
|
|
526
|
+
meta: ValidatedTableMeta;
|
|
527
|
+
selectFields: Record<string, string>;
|
|
528
|
+
filterKeys: Record<string, ValidatedFilterDescriptor>;
|
|
529
|
+
orderFields: Record<string, string>;
|
|
530
|
+
relations: Record<string, ValidatedRelationMeta>;
|
|
531
|
+
};
|
|
532
|
+
type ValidatedInsertSqlPlan = {
|
|
533
|
+
kind: typeof InternalSqlValidationPlanKind.INSERT;
|
|
534
|
+
meta: ValidatedTableMeta;
|
|
535
|
+
writeKeys: string[];
|
|
536
|
+
};
|
|
537
|
+
type ValidatedUpdateSqlPlan = {
|
|
538
|
+
kind: typeof InternalSqlValidationPlanKind.UPDATE;
|
|
539
|
+
meta: ValidatedTableMeta;
|
|
540
|
+
writeKeys: string[];
|
|
541
|
+
};
|
|
542
|
+
type ValidatedDeleteSqlPlan = {
|
|
543
|
+
kind: typeof InternalSqlValidationPlanKind.DELETE;
|
|
544
|
+
meta: ValidatedTableMeta;
|
|
545
|
+
};
|
|
546
|
+
type ValidatedSqlPlan = ValidatedSelectSqlPlan | ValidatedInsertSqlPlan | ValidatedUpdateSqlPlan | ValidatedDeleteSqlPlan;
|
|
547
|
+
interface SQLValidationEngine {
|
|
548
|
+
validate(plan: SelectSqlValidationPlan): ValidatedSelectSqlPlan;
|
|
549
|
+
validate(plan: InsertSqlValidationPlan): ValidatedInsertSqlPlan;
|
|
550
|
+
validate(plan: UpdateSqlValidationPlan): ValidatedUpdateSqlPlan;
|
|
551
|
+
validate(plan: DeleteSqlValidationPlan): ValidatedDeleteSqlPlan;
|
|
552
|
+
validate(plan: SqlValidationPlan): ValidatedSqlPlan;
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/validation/OrmSqlSafetyAdapter.d.ts
|
|
556
|
+
/**
|
|
557
|
+
* ORM-local adapter that translates query validation plans into the
|
|
558
|
+
* shared Tango SQL safety engine.
|
|
559
|
+
*/
|
|
560
|
+
declare class OrmSqlSafetyAdapter implements SQLValidationEngine {
|
|
561
|
+
private readonly engine;
|
|
562
|
+
static readonly BRAND: "tango.orm.orm_sql_safety_adapter";
|
|
563
|
+
readonly __tangoBrand: typeof OrmSqlSafetyAdapter.BRAND;
|
|
564
|
+
constructor(engine?: SqlSafetyEngine);
|
|
565
|
+
validate(plan: SelectSqlValidationPlan): ValidatedSelectSqlPlan;
|
|
566
|
+
validate(plan: InsertSqlValidationPlan): ValidatedInsertSqlPlan;
|
|
567
|
+
validate(plan: UpdateSqlValidationPlan): ValidatedUpdateSqlPlan;
|
|
568
|
+
validate(plan: DeleteSqlValidationPlan): ValidatedDeleteSqlPlan;
|
|
569
|
+
private validateTableMeta;
|
|
570
|
+
private validateRelationMeta;
|
|
571
|
+
private validateFilterKey;
|
|
572
|
+
private resolveColumn;
|
|
573
|
+
private resolveRelation;
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/manager/internal/MutationCompiler.d.ts
|
|
577
|
+
declare const InternalDuplicateInsertPolicy: {
|
|
578
|
+
readonly ERROR: "error";
|
|
579
|
+
readonly IGNORE: "ignore";
|
|
580
|
+
};
|
|
581
|
+
type DuplicateInsertPolicy = (typeof InternalDuplicateInsertPolicy)[keyof typeof InternalDuplicateInsertPolicy];
|
|
582
|
+
/**
|
|
583
|
+
* Internal compiler for manager-owned INSERT/UPDATE/DELETE statements.
|
|
584
|
+
*/
|
|
585
|
+
declare class MutationCompiler {
|
|
586
|
+
private readonly adapter;
|
|
587
|
+
private readonly placeholders;
|
|
588
|
+
constructor(adapter: Adapter);
|
|
589
|
+
compileInsert(plan: ValidatedInsertSqlPlan, values: readonly unknown[]): CompiledQuery;
|
|
590
|
+
compileUpdate(plan: ValidatedUpdateSqlPlan, values: readonly unknown[], id: unknown): CompiledQuery;
|
|
591
|
+
compileDelete(plan: ValidatedDeleteSqlPlan, id: unknown): CompiledQuery;
|
|
592
|
+
compileDeleteByJoinKeys(plan: ValidatedSelectSqlPlan, leftFilterKey: string, rightFilterKey: string, leftValue: unknown, rightValue: unknown): CompiledQuery;
|
|
593
|
+
compileBulkInsert(plan: ValidatedInsertSqlPlan, valueRows: ReadonlyArray<ReadonlyArray<unknown>>): CompiledQuery;
|
|
594
|
+
compileInsertJoinLinks(plan: ValidatedInsertSqlPlan, sourceKey: string, targetKey: string, ownerValue: unknown, targetValues: readonly unknown[], duplicatePolicy: DuplicateInsertPolicy): CompiledQuery;
|
|
595
|
+
compileDeleteJoinLinks(plan: ValidatedSelectSqlPlan, leftFilterKey: string, rightFilterKey: string, leftValue: unknown, rightValues: readonly unknown[]): CompiledQuery;
|
|
596
|
+
}
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/manager/relations/internal/ThroughTableManager.d.ts
|
|
599
|
+
/**
|
|
600
|
+
* Resolved through-table descriptor used by {@link ThroughTableManager}. The
|
|
601
|
+
* descriptor is derived once from a relation edge plus its through-model
|
|
602
|
+
* metadata, then reused for every link insert, delete, and read.
|
|
603
|
+
*/
|
|
604
|
+
interface ThroughTableLinkDescriptor {
|
|
605
|
+
/** Physical join-table name validated against SQL identifier safety rules. */
|
|
606
|
+
table: string;
|
|
607
|
+
/** Primary-key column name on the join table. */
|
|
608
|
+
primaryKey: string;
|
|
609
|
+
/** Full column map for the join table, used by the SQL safety adapter. */
|
|
610
|
+
columns: Record<string, string>;
|
|
611
|
+
/** Join-table column that stores the owner-side primary-key value. */
|
|
612
|
+
sourceColumn: string;
|
|
613
|
+
/** Join-table column that stores the target-side primary-key value. */
|
|
614
|
+
targetColumn: string;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Inputs accepted by {@link ThroughTableManager.fromRelation}.
|
|
618
|
+
*/
|
|
619
|
+
interface ThroughTableManagerFromRelationInputs {
|
|
620
|
+
relation: NonNullable<TableMeta['relations']>[string];
|
|
621
|
+
throughModelFields: ReadonlyArray<{
|
|
622
|
+
name: string;
|
|
623
|
+
type: string;
|
|
624
|
+
primaryKey?: boolean;
|
|
625
|
+
}>;
|
|
626
|
+
client: DBClient;
|
|
627
|
+
mutationCompiler: MutationCompiler;
|
|
628
|
+
adapter: Adapter;
|
|
629
|
+
sqlSafetyAdapter: OrmSqlSafetyAdapter;
|
|
630
|
+
}
|
|
631
|
+
interface InsertLinkOptions {
|
|
632
|
+
onDuplicate?: DuplicateInsertPolicy;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Internal helper that issues the INSERT, DELETE, and SELECT statements for
|
|
636
|
+
* a single many-to-many join table. Centralizes SQL safety validation and
|
|
637
|
+
* compilation so {@link ManyToManyRelatedManager} implementations only deal
|
|
638
|
+
* in primary-key values.
|
|
639
|
+
*/
|
|
640
|
+
declare class ThroughTableManager {
|
|
641
|
+
private readonly client;
|
|
642
|
+
private readonly mutationCompiler;
|
|
643
|
+
private readonly descriptor;
|
|
644
|
+
private readonly adapter;
|
|
645
|
+
private readonly sqlSafetyAdapter;
|
|
646
|
+
constructor(client: DBClient, mutationCompiler: MutationCompiler, descriptor: ThroughTableLinkDescriptor, adapter: Adapter, sqlSafetyAdapter?: OrmSqlSafetyAdapter);
|
|
647
|
+
/**
|
|
648
|
+
* Derive a {@link ThroughTableLinkDescriptor} from the through-model
|
|
649
|
+
* metadata exposed by a many-to-many relation edge.
|
|
650
|
+
*/
|
|
651
|
+
static buildLinkDescriptor(relation: NonNullable<TableMeta['relations']>[string], throughModelFields: ReadonlyArray<{
|
|
652
|
+
name: string;
|
|
653
|
+
type: string;
|
|
654
|
+
primaryKey?: boolean;
|
|
655
|
+
}>): ThroughTableLinkDescriptor;
|
|
656
|
+
/**
|
|
657
|
+
* Convenience factory that derives the join-table descriptor from the
|
|
658
|
+
* relation edge and instantiates a {@link ThroughTableManager} in one
|
|
659
|
+
* step.
|
|
660
|
+
*/
|
|
661
|
+
static fromRelation(inputs: ThroughTableManagerFromRelationInputs): ThroughTableManager;
|
|
662
|
+
/**
|
|
663
|
+
* Read every target primary-key value linked to the supplied owner via
|
|
664
|
+
* the join table. Used by ManyToManyRelatedManager.all to scope
|
|
665
|
+
* follow-up target queries to the current owner.
|
|
666
|
+
*/
|
|
667
|
+
selectTargetIdsForOwner(ownerPrimaryKey: unknown): Promise<readonly (string | number)[]>;
|
|
668
|
+
insertLink(ownerPrimaryKey: unknown, targetPrimaryKey: unknown, options?: InsertLinkOptions): Promise<void>;
|
|
669
|
+
insertLinks(ownerPrimaryKey: unknown, targetPrimaryKeys: readonly unknown[], options?: InsertLinkOptions): Promise<void>;
|
|
670
|
+
deleteLink(ownerPrimaryKey: unknown, targetPrimaryKey: unknown): Promise<void>;
|
|
671
|
+
deleteLinks(ownerPrimaryKey: unknown, targetPrimaryKeys: readonly unknown[]): Promise<void>;
|
|
672
|
+
/**
|
|
673
|
+
* Delete every join-table row linked to one owner record. Used by
|
|
674
|
+
* `ManyToManyRelatedManager.clear()` so the related manager can clear a
|
|
675
|
+
* relation without first loading the current target ids.
|
|
676
|
+
*/
|
|
677
|
+
deleteAllLinksForOwner(ownerPrimaryKey: unknown): Promise<void>;
|
|
678
|
+
}
|
|
679
|
+
//#endregion
|
|
680
|
+
//#region src/manager/relations/ManyToManyRelatedManager.d.ts
|
|
681
|
+
/**
|
|
682
|
+
* Accepted target reference shapes for {@link ManyToManyRelatedManager.add},
|
|
683
|
+
* {@link ManyToManyRelatedManager.remove}, and
|
|
684
|
+
* {@link ManyToManyRelatedManager.set}.
|
|
685
|
+
*
|
|
686
|
+
* Application code may pass a target record, a primary-key carrier object, or
|
|
687
|
+
* a bare primary-key value.
|
|
688
|
+
*
|
|
689
|
+
* @template TTarget - The persisted target record shape.
|
|
690
|
+
*/
|
|
691
|
+
type ManyToManyTargetRef<TTarget extends Record<string, unknown>> = TTarget | {
|
|
692
|
+
readonly [pk: string]: unknown;
|
|
693
|
+
} | string | number;
|
|
694
|
+
/**
|
|
695
|
+
* Inputs accepted by the {@link ManyToManyRelatedManager.create} factory. The
|
|
696
|
+
* factory owns the wiring between relation metadata, the SQL safety adapter,
|
|
697
|
+
* and the {@link ThroughTableManager}, so callers only supply context they
|
|
698
|
+
* already have on hand.
|
|
699
|
+
*/
|
|
700
|
+
interface ManyToManyRelatedManagerCreateInputs<TTarget extends Record<string, unknown>> {
|
|
701
|
+
/** Persisted primary-key value of the owning record. */
|
|
702
|
+
ownerPrimaryKey: unknown;
|
|
703
|
+
/** Relation name on the owning model (for error messages). */
|
|
704
|
+
relationName: string;
|
|
705
|
+
/** Display name of the owning model (for error messages). */
|
|
706
|
+
ownerModelLabel: string;
|
|
707
|
+
/** Resolved relation edge metadata for the many-to-many relation. */
|
|
708
|
+
relation: NonNullable<TableMeta['relations']>[string];
|
|
709
|
+
/** Through-model column metadata used to derive the join-table descriptor. */
|
|
710
|
+
throughModelFields: ReadonlyArray<{
|
|
711
|
+
name: string;
|
|
712
|
+
type: string;
|
|
713
|
+
primaryKey?: boolean;
|
|
714
|
+
}>;
|
|
715
|
+
/** Runtime-bound database client shared with the owning manager. */
|
|
716
|
+
client: DBClient;
|
|
717
|
+
/** Shared {@link MutationCompiler} configured for the active dialect. */
|
|
718
|
+
mutationCompiler: MutationCompiler;
|
|
719
|
+
/** Active database adapter. Supplies placeholder formatting and dialect flags. */
|
|
720
|
+
adapter: Adapter;
|
|
721
|
+
/** SQL safety adapter shared with the owning manager. */
|
|
722
|
+
sqlSafetyAdapter: OrmSqlSafetyAdapter;
|
|
723
|
+
/** Lazy resolver returning the target model's {@link QueryExecutor}. */
|
|
724
|
+
targetExecutorProvider: () => QueryExecutor<TTarget> | null;
|
|
725
|
+
/** Model-manager-backed create path for new target records. */
|
|
726
|
+
createTarget: (input: Partial<TTarget>) => Promise<TTarget>;
|
|
727
|
+
/** Internal transaction runner used for multi-target membership writes. */
|
|
728
|
+
runAtomic: <T>(work: () => Promise<T>) => Promise<T>;
|
|
729
|
+
}
|
|
730
|
+
interface ManyToManyRelatedManagerInternalInputs<TTarget extends Record<string, unknown>> {
|
|
731
|
+
ownerPrimaryKey: unknown;
|
|
732
|
+
relationName: string;
|
|
733
|
+
ownerModelLabel: string;
|
|
734
|
+
targetPrimaryKeyField: string;
|
|
735
|
+
throughTableManager: ThroughTableManager;
|
|
736
|
+
targetExecutorProvider: () => QueryExecutor<TTarget> | null;
|
|
737
|
+
createTarget: (input: Partial<TTarget>) => Promise<TTarget>;
|
|
738
|
+
runAtomic: <T>(work: () => Promise<T>) => Promise<T>;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Django-style related manager exposed on materialized model records for each
|
|
742
|
+
* many-to-many relation.
|
|
743
|
+
*
|
|
744
|
+
* Use the manager to add or remove join-table membership and to query the
|
|
745
|
+
* related target rows. The owning record's primary key and the relation name
|
|
746
|
+
* are bound when the manager is attached, so application code does not need
|
|
747
|
+
* to pass them on every call.
|
|
748
|
+
*
|
|
749
|
+
* Prefetched memberships seed an internal cache that the queryset returned
|
|
750
|
+
* from `all()` short-circuits to without re-querying. Mutations through
|
|
751
|
+
* `add`, `remove`, `set`, `clear`, and `create` invalidate the cache so
|
|
752
|
+
* subsequent reads observe the updated membership. `set(...)` applies
|
|
753
|
+
* Django-shaped replacement semantics:
|
|
754
|
+
* it diffs the current relation membership against the supplied targets,
|
|
755
|
+
* removes any missing links, and inserts any new links inside one atomic
|
|
756
|
+
* write boundary. `clear()` removes every join row for the owner, and
|
|
757
|
+
* `create(...)` persists a new target row plus its join-row link inside one
|
|
758
|
+
* atomic boundary.
|
|
759
|
+
*
|
|
760
|
+
* @template TTarget - The persisted target record shape returned by `all()`.
|
|
761
|
+
*/
|
|
762
|
+
declare class ManyToManyRelatedManager<TTarget extends Record<string, unknown>> {
|
|
763
|
+
private readonly inputs;
|
|
764
|
+
private static readonly BRAND;
|
|
765
|
+
readonly __tangoBrand: typeof ManyToManyRelatedManager.BRAND;
|
|
766
|
+
private prefetchCache;
|
|
767
|
+
/**
|
|
768
|
+
* Constructor is internal. Application and ORM code must build instances
|
|
769
|
+
* through {@link ManyToManyRelatedManager.create}, which owns the wiring
|
|
770
|
+
* between relation metadata and the backing through-table mutator. The
|
|
771
|
+
* testing package exposes a fixture for unit tests that need a custom
|
|
772
|
+
* mutator.
|
|
773
|
+
*/
|
|
774
|
+
constructor(inputs: ManyToManyRelatedManagerInternalInputs<TTarget>);
|
|
775
|
+
/**
|
|
776
|
+
* Narrow an unknown value to {@link ManyToManyRelatedManager}.
|
|
777
|
+
*/
|
|
778
|
+
static isManyToManyRelatedManager<TTarget extends Record<string, unknown>>(value: unknown): value is ManyToManyRelatedManager<TTarget>;
|
|
779
|
+
/**
|
|
780
|
+
* Build a {@link ManyToManyRelatedManager} bound to a single owner record.
|
|
781
|
+
* The factory derives the join-table descriptor from the relation edge and
|
|
782
|
+
* through-model fields, wires a {@link ThroughTableManager} against the
|
|
783
|
+
* supplied runtime-bound client, and returns a manager whose `add`,
|
|
784
|
+
* `remove`, `clear`, `create`, and `all` methods enroll in any active
|
|
785
|
+
* `transaction.atomic(...)` boundary.
|
|
786
|
+
*/
|
|
787
|
+
static create<TTarget extends Record<string, unknown>>(inputs: ManyToManyRelatedManagerCreateInputs<TTarget>): ManyToManyRelatedManager<TTarget>;
|
|
788
|
+
/**
|
|
789
|
+
* Insert join-table rows linking the owning record to the supplied
|
|
790
|
+
* targets. Duplicate links are ignored so repeated `add(...)` calls are
|
|
791
|
+
* idempotent. When multiple targets are supplied, Tango performs the
|
|
792
|
+
* membership write inside one `transaction.atomic(...)` boundary.
|
|
793
|
+
*/
|
|
794
|
+
add(...targets: ManyToManyTargetRef<TTarget>[]): Promise<void>;
|
|
795
|
+
/**
|
|
796
|
+
* Delete join-table rows linking the owning record to the supplied
|
|
797
|
+
* targets. When multiple targets are supplied, Tango performs the
|
|
798
|
+
* membership write inside one `transaction.atomic(...)` boundary.
|
|
799
|
+
*/
|
|
800
|
+
remove(...targets: ManyToManyTargetRef<TTarget>[]): Promise<void>;
|
|
801
|
+
/**
|
|
802
|
+
* Delete every join-table row linked to the owning record and invalidate
|
|
803
|
+
* any prefetched membership cache after the delete succeeds.
|
|
804
|
+
*/
|
|
805
|
+
clear(): Promise<void>;
|
|
806
|
+
/**
|
|
807
|
+
* Create a new target record through the related model's manager and link
|
|
808
|
+
* it to the owning record inside one `transaction.atomic(...)` boundary.
|
|
809
|
+
* This preserves target-manager hooks and defaults while preventing a
|
|
810
|
+
* created target row from leaking if the join-row insert fails.
|
|
811
|
+
*/
|
|
812
|
+
create(input: Partial<TTarget>): Promise<TTarget>;
|
|
813
|
+
/**
|
|
814
|
+
* Replace the current relation membership with exactly the supplied
|
|
815
|
+
* targets. Duplicate inputs are collapsed before diffing against the
|
|
816
|
+
* current through-table rows, so repeated values do not trigger extra
|
|
817
|
+
* writes. Calling `set()` with no targets clears the relation.
|
|
818
|
+
*
|
|
819
|
+
* When replacement requires writes, Tango performs the delete/insert
|
|
820
|
+
* sequence inside one `transaction.atomic(...)` boundary.
|
|
821
|
+
*/
|
|
822
|
+
set(...targets: ManyToManyTargetRef<TTarget>[]): Promise<void>;
|
|
823
|
+
/**
|
|
824
|
+
* Return a {@link QuerySet} for the related target rows of this many-to-many
|
|
825
|
+
* relation. When the relation was already loaded by `prefetchRelated(...)`,
|
|
826
|
+
* the first `fetch()` resolves with the cached materialization without
|
|
827
|
+
* re-querying. Mutating the membership through `add`/`remove`/`set`/
|
|
828
|
+
* `clear`/`create` invalidates that cache.
|
|
829
|
+
*/
|
|
830
|
+
all(): QuerySet<TTarget>;
|
|
831
|
+
/**
|
|
832
|
+
* Replace the prefetch cache with the supplied target rows. Called by the
|
|
833
|
+
* many-to-many prefetch path so a follow-up `all()` resolves without an
|
|
834
|
+
* extra database round-trip.
|
|
835
|
+
*/
|
|
836
|
+
primePrefetchCache(targets: readonly TTarget[]): void;
|
|
837
|
+
/**
|
|
838
|
+
* Drop any cached prefetch results. Mutating helpers call this so reads
|
|
839
|
+
* after an `add`/`remove`/`set`/`clear`/`create` go back to the database.
|
|
840
|
+
*/
|
|
841
|
+
invalidateCache(): void;
|
|
842
|
+
/**
|
|
843
|
+
* Snapshot of the current prefetch cache, exposed for diagnostics and
|
|
844
|
+
* focused unit testing. Returns a fresh array copy so callers cannot
|
|
845
|
+
* mutate the manager's internal state.
|
|
846
|
+
*/
|
|
847
|
+
snapshotCache(): readonly TTarget[] | null;
|
|
848
|
+
private insertTargetPrimaryKeys;
|
|
849
|
+
private deleteTargetPrimaryKeys;
|
|
850
|
+
private resolveTargetPrimaryKeys;
|
|
851
|
+
private resolveTargetPrimaryKey;
|
|
852
|
+
private canonicalizePrimaryKey;
|
|
853
|
+
}
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/query/domain/RelationTyping.d.ts
|
|
856
|
+
declare const InternalRelationHydrationCardinality: {
|
|
857
|
+
readonly SINGLE: "single";
|
|
858
|
+
readonly MANY: "many";
|
|
859
|
+
};
|
|
860
|
+
type RelationHydrationCardinality = (typeof InternalRelationHydrationCardinality)[keyof typeof InternalRelationHydrationCardinality];
|
|
861
|
+
type SingleRelationHydrationCardinality = typeof InternalRelationHydrationCardinality.SINGLE;
|
|
862
|
+
type ManyRelationHydrationCardinality = typeof InternalRelationHydrationCardinality.MANY;
|
|
863
|
+
type HydratedQueryResult<TBase extends Record<string, unknown>, THydrated extends Record<string, unknown>> = [keyof THydrated] extends [never] ? TBase : Omit<TBase, keyof THydrated> & THydrated;
|
|
864
|
+
declare global {
|
|
865
|
+
interface TangoGeneratedRelationRegistry {}
|
|
866
|
+
}
|
|
867
|
+
type AnyModel = Model<z.ZodObject<z.ZodRawShape>, string>;
|
|
868
|
+
type ModelSchema<TModel> = TModel extends Model<infer TSchema extends z.ZodObject<z.ZodRawShape>, string> ? TSchema : never;
|
|
869
|
+
type ModelShape<TModel> = ModelSchema<TModel> extends z.ZodObject<infer TShape> ? TShape : never;
|
|
870
|
+
type ModelRow<TModel> = TModel extends Model<infer TSchema extends z.ZodObject<z.ZodRawShape>, string> ? PersistedModelOutput<TSchema> : never;
|
|
871
|
+
type IsLiteralString<TValue> = TValue extends string ? (string extends TValue ? false : true) : false;
|
|
872
|
+
type HasStrictModelKey<TModel> = TModel extends Model<z.ZodObject<z.ZodRawShape>, infer TKey> ? IsLiteralString<TKey> : false;
|
|
873
|
+
type ModelKey<TModel> = TModel extends Model<z.ZodObject<z.ZodRawShape>, infer TKey extends string> ? TKey : never;
|
|
874
|
+
type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends ((value: infer TIntersection) => void) ? TIntersection : never;
|
|
875
|
+
type JoinPathSegments<TSegments extends readonly string[]> = TSegments extends readonly [infer THead extends string, ...infer TRest extends string[]] ? TRest['length'] extends 0 ? THead : `${THead}__${JoinPathSegments<TRest>}` : never;
|
|
876
|
+
type SplitPath<TPath extends string> = TPath extends `${infer THead}__${infer TRest}` ? [THead, ...SplitPath<TRest>] : [TPath];
|
|
877
|
+
type TailTuple<TTuple extends readonly unknown[]> = TTuple extends readonly [unknown, ...infer TRest] ? TRest : [];
|
|
878
|
+
type DefaultGeneratedCycleBudget = readonly [1, 1, 1, 1];
|
|
879
|
+
type GeneratedRelationRegistry = TangoGeneratedRelationRegistry;
|
|
880
|
+
type GeneratedRelationKeys<TSourceModel> = Extract<keyof GeneratedRelations<TSourceModel>, string>;
|
|
881
|
+
type GeneratedRelations<TSourceModel> = HasStrictModelKey<TSourceModel> extends true ? ModelKey<TSourceModel> extends keyof GeneratedRelationRegistry ? GeneratedRelationRegistry[ModelKey<TSourceModel>] : {} : {};
|
|
882
|
+
type NextSeenModels<TSeen extends readonly string[], TTargetModel> = ModelKey<TTargetModel> extends string ? [...TSeen, ModelKey<TTargetModel>] : TSeen;
|
|
883
|
+
type CanTraverseGeneratedTarget<TTargetModel, TSeen extends readonly string[], TCycleBudget extends readonly unknown[]> = ModelKey<TTargetModel> extends TSeen[number] ? (TCycleBudget extends [] ? false : true) : true;
|
|
884
|
+
type NextGeneratedCycleBudget<TTargetModel, TSeen extends readonly string[], TCycleBudget extends readonly unknown[]> = ModelKey<TTargetModel> extends TSeen[number] ? TailTuple<TCycleBudget> : TCycleBudget;
|
|
885
|
+
type GeneratedCardinalityIncludesMany<TCardinality extends RelationHydrationCardinality> = TCardinality extends typeof InternalRelationHydrationCardinality.MANY ? true : false;
|
|
886
|
+
/**
|
|
887
|
+
* Generated path keys accepted by `selectRelated(...)`.
|
|
888
|
+
*
|
|
889
|
+
* Walks the ambient relation registry one hop at a time. Each hop contributes:
|
|
890
|
+
* (a) the bare relation key (e.g. `author`) as a valid path terminus, and
|
|
891
|
+
* (b) a dunder-joined extension (`author__profile`, ...) that recurses into
|
|
892
|
+
* the target model.
|
|
893
|
+
*
|
|
894
|
+
* Because `selectRelated` only composes single-valued hops, the mapped type
|
|
895
|
+
* filters relations whose `cardinality` is not `SINGLE`. The `TSeen` tuple
|
|
896
|
+
* tracks which model keys the recursion has visited so cyclic schemas
|
|
897
|
+
* (`manager -> manager`) are allowed a bounded number of revisits before
|
|
898
|
+
* typing falls back to `never`. `TCycleBudget` is that revisit budget; see
|
|
899
|
+
* `CanTraverseGeneratedTarget` / `NextGeneratedCycleBudget` for how it
|
|
900
|
+
* shrinks only when the next hop actually re-enters a seen model.
|
|
901
|
+
*/
|
|
902
|
+
type GeneratedSelectRelatedPathKeys<TSourceModel, TSeen extends readonly string[] = [ModelKey<TSourceModel>], TCycleBudget extends readonly unknown[] = DefaultGeneratedCycleBudget> = { [TKey in GeneratedRelationKeys<TSourceModel>]: GeneratedRelations<TSourceModel>[TKey] extends {
|
|
903
|
+
target: infer TTarget extends AnyModel;
|
|
904
|
+
cardinality: typeof InternalRelationHydrationCardinality.SINGLE;
|
|
905
|
+
} ? TKey | (CanTraverseGeneratedTarget<TTarget, TSeen, TCycleBudget> extends true ? `${TKey}__${GeneratedSelectRelatedPathKeys<TTarget, NextSeenModels<TSeen, TTarget>, NextGeneratedCycleBudget<TTarget, TSeen, TCycleBudget>>}` : never) : never }[GeneratedRelationKeys<TSourceModel>];
|
|
906
|
+
/**
|
|
907
|
+
* Generated path keys accepted by `prefetchRelated(...)`.
|
|
908
|
+
*
|
|
909
|
+
* Similar in shape to {@link GeneratedSelectRelatedPathKeys}, but relaxes two
|
|
910
|
+
* constraints because prefetch can cross and continue past collection edges:
|
|
911
|
+
* 1. Any hop whose cardinality is `MANY` is a valid terminus. The
|
|
912
|
+
* `THasMany` flag threads through recursion so once a collection edge
|
|
913
|
+
* has been crossed, every subsequent hop is also a valid terminus
|
|
914
|
+
* (matches Django's `prefetch_related` semantics).
|
|
915
|
+
* 2. Single-valued hops are still accepted as terminators so paths like
|
|
916
|
+
* `posts__author` survive the join.
|
|
917
|
+
*
|
|
918
|
+
* Cycle handling reuses the same `TSeen` / `TCycleBudget` machinery described
|
|
919
|
+
* in {@link GeneratedSelectRelatedPathKeys}: cyclic schemas are typed up to
|
|
920
|
+
* the bound, then fall back to weaker typing rather than failing.
|
|
921
|
+
*/
|
|
922
|
+
type GeneratedPrefetchRelatedPathKeys<TSourceModel, THasMany extends boolean = false, TSeen extends readonly string[] = [ModelKey<TSourceModel>], TCycleBudget extends readonly unknown[] = DefaultGeneratedCycleBudget> = { [TKey in GeneratedRelationKeys<TSourceModel>]: GeneratedRelations<TSourceModel>[TKey] extends {
|
|
923
|
+
target: infer TTarget extends AnyModel;
|
|
924
|
+
cardinality: infer TCardinality extends RelationHydrationCardinality;
|
|
925
|
+
} ? (THasMany extends true ? TKey : GeneratedCardinalityIncludesMany<TCardinality> extends true ? TKey : never) | (CanTraverseGeneratedTarget<TTarget, TSeen, TCycleBudget> extends true ? `${TKey}__${GeneratedPrefetchRelatedPathKeys<TTarget, THasMany extends true ? true : GeneratedCardinalityIncludesMany<TCardinality>, NextSeenModels<TSeen, TTarget>, NextGeneratedCycleBudget<TTarget, TSeen, TCycleBudget>>}` : never) : never }[GeneratedRelationKeys<TSourceModel>];
|
|
926
|
+
/**
|
|
927
|
+
* Generated relation-path filter keys accepted by `filter(...)`, `exclude(...)`,
|
|
928
|
+
* and `Q(...)`.
|
|
929
|
+
*
|
|
930
|
+
* This stays intentionally lighter than the eager-loading path typing:
|
|
931
|
+
* applications with generated relation registries get completion for the
|
|
932
|
+
* relation path prefix, while the terminal field and lookup suffix remain a
|
|
933
|
+
* string tail so the compiler does not explode on deep recursive field
|
|
934
|
+
* extraction.
|
|
935
|
+
*/
|
|
936
|
+
type GeneratedRelationFilterKeys<TSourceModel> = `${GeneratedSelectRelatedPathKeys<TSourceModel>}__${string}` | `${GeneratedPrefetchRelatedPathKeys<TSourceModel>}__${string}`;
|
|
937
|
+
type GeneratedHydratedTarget<TDescriptor, TPath extends string | never> = TDescriptor extends {
|
|
938
|
+
target: infer TTarget extends AnyModel;
|
|
939
|
+
} ? [TPath] extends [never] ? ModelRow<TTarget> : HydratedQueryResult<ModelRow<TTarget>, GeneratedHydratedRelationMap<TTarget, TPath>> : never;
|
|
940
|
+
type GeneratedHydratedValue<TDescriptor, TPath extends string | never> = TDescriptor extends {
|
|
941
|
+
target: infer TTarget extends AnyModel;
|
|
942
|
+
kind: 'manyToMany';
|
|
943
|
+
} ? ManyToManyRelatedManager<ModelRow<TTarget>> : TDescriptor extends {
|
|
944
|
+
cardinality: infer TCardinality extends RelationHydrationCardinality;
|
|
945
|
+
} ? TCardinality extends typeof InternalRelationHydrationCardinality.SINGLE ? GeneratedHydratedTarget<TDescriptor, TPath> | null : GeneratedHydratedTarget<TDescriptor, TPath>[] : never;
|
|
946
|
+
type GeneratedHydrationForPath<TSourceModel, TPath extends string> = SplitPath<TPath> extends [infer THead extends string, ...infer TRest extends string[]] ? THead extends GeneratedRelationKeys<TSourceModel> ? { [TKey in THead]: GeneratedHydratedValue<GeneratedRelations<TSourceModel>[THead], JoinPathSegments<TRest>> } : {} : {};
|
|
947
|
+
type GeneratedHydratedRelationMap<TSourceModel, TPaths extends string | never> = ([TPaths] extends [never] ? Record<never, never> : UnionToIntersection<TPaths extends string ? GeneratedHydrationForPath<TSourceModel, TPaths> : never>) & Record<never, never>;
|
|
948
|
+
type ModelKeysMatch<TCandidate, TExpected> = TCandidate extends Model<z.ZodObject<z.ZodRawShape>, infer TCandidateKey> ? TExpected extends Model<z.ZodObject<z.ZodRawShape>, infer TExpectedKey> ? IsLiteralString<TCandidateKey> extends true ? IsLiteralString<TExpectedKey> extends true ? [TCandidateKey] extends [TExpectedKey] ? true : false : false : false : false : false;
|
|
949
|
+
type FieldNamingHint<TKey extends string> = TKey extends `${infer TBase}Id` ? TBase : TKey extends `${infer TBase}_id` ? TBase : TKey;
|
|
950
|
+
type RelationName<TKey extends string, TName> = TName extends string ? TName : FieldNamingHint<TKey>;
|
|
951
|
+
type RelatedName<TName> = TName extends string ? TName : never;
|
|
952
|
+
type RelationTarget<TField> = TField extends RelationDecoratedSchema<z.ZodTypeAny, DecoratedFieldKind, infer TTarget, string | undefined, string | undefined> ? TTarget : never;
|
|
953
|
+
type RelationConfiguredName<TField> = TField extends RelationDecoratedSchema<z.ZodTypeAny, DecoratedFieldKind, AnyModel, infer TName, string | undefined> ? TName : undefined;
|
|
954
|
+
type RelationConfiguredRelatedName<TField> = TField extends RelationDecoratedSchema<z.ZodTypeAny, DecoratedFieldKind, AnyModel, string | undefined, infer TRelatedName> ? TRelatedName : undefined;
|
|
955
|
+
type RelationKindOf<TField> = TField extends RelationDecoratedSchema<z.ZodTypeAny, infer TKind, AnyModel, string | undefined, string | undefined> ? TKind : never;
|
|
956
|
+
type ForwardSingleRelations<TSourceModel> = HasStrictModelKey<TSourceModel> extends true ? { [TKey in keyof ModelShape<TSourceModel> as TKey extends string ? [RelationKindOf<ModelShape<TSourceModel>[TKey]>] extends [never] ? never : RelationKindOf<ModelShape<TSourceModel>[TKey]> extends typeof InternalDecoratedFieldKind.FOREIGN_KEY | typeof InternalDecoratedFieldKind.ONE_TO_ONE ? RelationTarget<ModelShape<TSourceModel>[TKey]> extends AnyModel ? RelationName<TKey, RelationConfiguredName<ModelShape<TSourceModel>[TKey]>> : never : never : never]: {
|
|
957
|
+
kind: typeof InternalDecoratedFieldKind.FOREIGN_KEY;
|
|
958
|
+
target: RelationTarget<ModelShape<TSourceModel>[TKey]>;
|
|
959
|
+
} } : Record<string, {
|
|
960
|
+
kind: typeof InternalDecoratedFieldKind.FOREIGN_KEY;
|
|
961
|
+
target: AnyModel;
|
|
962
|
+
}>;
|
|
963
|
+
type ReverseSingleRelations<TSourceModel, TTargetModel> = HasStrictModelKey<TSourceModel> extends true ? HasStrictModelKey<TTargetModel> extends true ? { [TKey in keyof ModelShape<TTargetModel> as [RelationKindOf<ModelShape<TTargetModel>[TKey]>] extends [never] ? never : RelationKindOf<ModelShape<TTargetModel>[TKey]> extends typeof InternalDecoratedFieldKind.ONE_TO_ONE ? ModelKeysMatch<RelationTarget<ModelShape<TTargetModel>[TKey]>, TSourceModel> extends true ? RelatedName<RelationConfiguredRelatedName<ModelShape<TTargetModel>[TKey]>> : never : never]: {
|
|
964
|
+
kind: typeof InternalDecoratedFieldKind.ONE_TO_ONE;
|
|
965
|
+
target: TTargetModel;
|
|
966
|
+
} } : {} : Record<string, {
|
|
967
|
+
kind: typeof InternalDecoratedFieldKind.ONE_TO_ONE;
|
|
968
|
+
target: AnyModel;
|
|
969
|
+
}>;
|
|
970
|
+
type ReverseCollectionRelations<TSourceModel, TTargetModel> = HasStrictModelKey<TSourceModel> extends true ? HasStrictModelKey<TTargetModel> extends true ? { [TKey in keyof ModelShape<TTargetModel> as [RelationKindOf<ModelShape<TTargetModel>[TKey]>] extends [never] ? never : RelationKindOf<ModelShape<TTargetModel>[TKey]> extends typeof InternalDecoratedFieldKind.FOREIGN_KEY ? ModelKeysMatch<RelationTarget<ModelShape<TTargetModel>[TKey]>, TSourceModel> extends true ? RelatedName<RelationConfiguredRelatedName<ModelShape<TTargetModel>[TKey]>> : never : never]: {
|
|
971
|
+
kind: typeof InternalDecoratedFieldKind.FOREIGN_KEY;
|
|
972
|
+
target: TTargetModel;
|
|
973
|
+
} } : {} : Record<string, {
|
|
974
|
+
kind: typeof InternalDecoratedFieldKind.FOREIGN_KEY;
|
|
975
|
+
target: AnyModel;
|
|
976
|
+
}>;
|
|
977
|
+
type SelectRelatedRelations<TSourceModel, TTargetModel> = [TTargetModel] extends [undefined] ? ForwardSingleRelations<TSourceModel> : // Target generic supplied: include reverse hasOne relations discovered on that target model.
|
|
978
|
+
ForwardSingleRelations<TSourceModel> & ReverseSingleRelations<TSourceModel, TTargetModel>;
|
|
979
|
+
type PrefetchRelatedRelations<TSourceModel, TTargetModel> = ReverseCollectionRelations<TSourceModel, TTargetModel>;
|
|
980
|
+
type RelationKeys<TRelations> = Extract<keyof TRelations, string>;
|
|
981
|
+
type HydratedRelationMap<TRelations, TKeys extends string, TCardinality extends RelationHydrationCardinality> = { [TKey in TKeys]: TKey extends keyof TRelations ? TRelations[TKey] extends {
|
|
982
|
+
target: infer TTarget;
|
|
983
|
+
} ? TCardinality extends typeof InternalRelationHydrationCardinality.SINGLE ? ModelRow<TTarget> | null : ModelRow<TTarget>[] : never : never };
|
|
984
|
+
type MaybeHydratedRelationMap<TSourceModel, TRelations, TKeys extends string, TCardinality extends RelationHydrationCardinality> = HasStrictModelKey<TSourceModel> extends true ? HydratedRelationMap<TRelations, TKeys, TCardinality> : Record<never, never>;
|
|
985
|
+
//#endregion
|
|
986
|
+
//#region src/query/domain/RelationMeta.d.ts
|
|
987
|
+
type RelationKind = (typeof InternalRelationKind)[keyof typeof InternalRelationKind];
|
|
988
|
+
declare const InternalRelationHydrationLoadMode: {
|
|
989
|
+
readonly JOIN: "join";
|
|
990
|
+
readonly PREFETCH: "prefetch";
|
|
991
|
+
};
|
|
992
|
+
type RelationHydrationLoadMode = (typeof InternalRelationHydrationLoadMode)[keyof typeof InternalRelationHydrationLoadMode];
|
|
993
|
+
interface RelationHydrationCapabilities {
|
|
994
|
+
queryable: boolean;
|
|
995
|
+
hydratable: boolean;
|
|
996
|
+
joinable: boolean;
|
|
997
|
+
prefetchable: boolean;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Runtime relation metadata consumed by validation, planning, compilation, and
|
|
1001
|
+
* hydration.
|
|
1002
|
+
*/
|
|
1003
|
+
interface RelationMeta {
|
|
1004
|
+
/** Stable edge identity from the resolved relation graph. */
|
|
1005
|
+
edgeId: string;
|
|
1006
|
+
/** Model key that owns the public relation name. */
|
|
1007
|
+
sourceModelKey: string;
|
|
1008
|
+
/** Model key reached by traversing this relation. */
|
|
1009
|
+
targetModelKey: string;
|
|
1010
|
+
/** Public relation kind such as belongsTo or hasMany. */
|
|
1011
|
+
kind: RelationKind;
|
|
1012
|
+
/** Hydration cardinality used by eager-loading APIs. */
|
|
1013
|
+
cardinality: RelationHydrationCardinality;
|
|
1014
|
+
/** Capability flags distilled from the resolved relation graph. */
|
|
1015
|
+
capabilities: RelationHydrationCapabilities;
|
|
1016
|
+
/** Physical table storing the target model rows. */
|
|
1017
|
+
table: string;
|
|
1018
|
+
/** Owner-side column used to attach or query related rows. */
|
|
1019
|
+
sourceKey: string;
|
|
1020
|
+
/** Target-side column matched against the source key. */
|
|
1021
|
+
targetKey: string;
|
|
1022
|
+
/** Many-to-many through table name when applicable. */
|
|
1023
|
+
throughTable?: string;
|
|
1024
|
+
throughModelKey?: string;
|
|
1025
|
+
/** Many-to-many through column that matches the owner source key. */
|
|
1026
|
+
throughSourceKey?: string;
|
|
1027
|
+
/** Many-to-many through column that matches the target primary key. */
|
|
1028
|
+
throughTargetKey?: string;
|
|
1029
|
+
throughSourceColumnType?: string;
|
|
1030
|
+
throughTargetColumnType?: string;
|
|
1031
|
+
/** Primary key column for the target model. */
|
|
1032
|
+
targetPrimaryKey: string;
|
|
1033
|
+
/** Target model columns and their storage types. */
|
|
1034
|
+
targetColumns: Record<string, string>;
|
|
1035
|
+
/** Deterministic alias base used by join compilation. */
|
|
1036
|
+
alias: string;
|
|
1037
|
+
/** Recursive target metadata used for nested planning. */
|
|
1038
|
+
targetMeta?: TableMeta;
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/query/domain/internal/InternalPrefetchQueryKind.d.ts
|
|
1042
|
+
/**
|
|
1043
|
+
* Discriminator strings for compiled prefetch hydration: how `QueryCompiler.compilePrefetch`
|
|
1044
|
+
* batches related rows for hydration (`CompiledPrefetchQuery`).
|
|
1045
|
+
*/
|
|
1046
|
+
declare const InternalPrefetchQueryKind: {
|
|
1047
|
+
/**
|
|
1048
|
+
* Single-query prefetch against the related table (`SELECT … FROM target WHERE fk IN (...)`).
|
|
1049
|
+
* Used when each related row is reachable from one physical table via a foreign key or
|
|
1050
|
+
* symmetric join path (belongsTo, hasMany, hasOne, reverse one-to-one).
|
|
1051
|
+
*/
|
|
1052
|
+
readonly DIRECT: "direct";
|
|
1053
|
+
/**
|
|
1054
|
+
* Two-phase many-to-many prefetch: first query reads join (through) rows pairing owner ids to
|
|
1055
|
+
* target ids (`throughSql`), then target rows load by primary key (`compileManyToManyTargets`).
|
|
1056
|
+
* Distinct from relation metadata’s `manyToMany` relation *kind* on an endpoint—this marks the
|
|
1057
|
+
* compiled prefetch *strategy*, not the schema edge type.
|
|
1058
|
+
*/
|
|
1059
|
+
readonly MANY_TO_MANY: "manyToMany";
|
|
1060
|
+
};
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region src/query/domain/CompiledQuery.d.ts
|
|
1063
|
+
/**
|
|
1064
|
+
* Result of compiling a {@link QuerySet} into an executable SQL statement plus
|
|
1065
|
+
* the hydration plan the executor needs to reshape flat rows into nested
|
|
1066
|
+
* relation graphs.
|
|
1067
|
+
*/
|
|
1068
|
+
interface CompiledQuery {
|
|
1069
|
+
/**
|
|
1070
|
+
* Parameterized SQL string ready for `client.query(...)`. Identifiers and
|
|
1071
|
+
* relation names are pre-validated; values never appear inline.
|
|
1072
|
+
*/
|
|
1073
|
+
sql: string;
|
|
1074
|
+
/**
|
|
1075
|
+
* Parameter values bound to the SQL statement in the same order the
|
|
1076
|
+
* placeholders appear.
|
|
1077
|
+
*/
|
|
1078
|
+
params: readonly unknown[];
|
|
1079
|
+
/**
|
|
1080
|
+
* Optional hydration plan produced when the query declared selected or
|
|
1081
|
+
* prefetched relations. Absent for plain row reads that do no
|
|
1082
|
+
* relation-shaping work.
|
|
1083
|
+
*/
|
|
1084
|
+
hydrationPlan?: CompiledHydrationPlanRoot;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Top-level hydration plan for a compiled query. Groups the join-time
|
|
1088
|
+
* hydration nodes (emitted inline with the root query) with the prefetch
|
|
1089
|
+
* hydration nodes (executed as follow-up queries after the root rows land).
|
|
1090
|
+
*/
|
|
1091
|
+
interface CompiledHydrationPlanRoot {
|
|
1092
|
+
/**
|
|
1093
|
+
* The relation paths the caller originally requested via
|
|
1094
|
+
* `selectRelated(...)` / `prefetchRelated(...)`. Retained for diagnostic
|
|
1095
|
+
* messages and snapshot stability.
|
|
1096
|
+
*/
|
|
1097
|
+
requestedPaths: readonly string[];
|
|
1098
|
+
/**
|
|
1099
|
+
* Column aliases on the root query that exist solely to support hydration
|
|
1100
|
+
* (for example, join-mirrored primary keys). The hydrator strips these
|
|
1101
|
+
* before handing rows back to application code.
|
|
1102
|
+
*/
|
|
1103
|
+
hiddenRootAliases: readonly string[];
|
|
1104
|
+
/**
|
|
1105
|
+
* Hydration nodes whose rows arrive joined into the root query's result
|
|
1106
|
+
* set. Each node describes how to fold those joined columns back into a
|
|
1107
|
+
* nested relation attribute.
|
|
1108
|
+
*/
|
|
1109
|
+
joinNodes: readonly CompiledHydrationNode[];
|
|
1110
|
+
/**
|
|
1111
|
+
* Hydration nodes that require a follow-up prefetch query after the root
|
|
1112
|
+
* rows land. Each node drives one or more `compilePrefetch(...)` calls.
|
|
1113
|
+
*/
|
|
1114
|
+
prefetchNodes: readonly CompiledHydrationNode[];
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Recursive description of how to hydrate one relation edge and its
|
|
1118
|
+
* descendants. The same node shape is used for join-loaded and
|
|
1119
|
+
* prefetch-loaded relations; {@link loadMode} distinguishes them.
|
|
1120
|
+
*/
|
|
1121
|
+
interface CompiledHydrationNode {
|
|
1122
|
+
/** Stable identifier for this node in the plan. */
|
|
1123
|
+
nodeId: string;
|
|
1124
|
+
/**
|
|
1125
|
+
* Public relation name as declared in the schema, mirrored onto the
|
|
1126
|
+
* hydrated record (for example, `author` or `tags`).
|
|
1127
|
+
*/
|
|
1128
|
+
relationName: string;
|
|
1129
|
+
/**
|
|
1130
|
+
* Dot-less path expression that reaches this node from the root, used in
|
|
1131
|
+
* error messages and plan diagnostics.
|
|
1132
|
+
*/
|
|
1133
|
+
relationPath: string;
|
|
1134
|
+
/** Model key of the owner side of this edge. */
|
|
1135
|
+
ownerModelKey: string;
|
|
1136
|
+
/** Model key of the target side of this edge. */
|
|
1137
|
+
targetModelKey: string;
|
|
1138
|
+
/** Join-inline vs follow-up prefetch load strategy. */
|
|
1139
|
+
loadMode: RelationHydrationLoadMode;
|
|
1140
|
+
/** Whether this edge yields one target or many. */
|
|
1141
|
+
cardinality: RelationHydrationCardinality;
|
|
1142
|
+
/**
|
|
1143
|
+
* Owner-side column whose value scopes the hydration read. For
|
|
1144
|
+
* foreign-key relations this is the local column; for many-to-many this
|
|
1145
|
+
* is the owner primary key.
|
|
1146
|
+
*/
|
|
1147
|
+
sourceKey: string;
|
|
1148
|
+
/**
|
|
1149
|
+
* Column alias on the root SQL row that surfaces `sourceKey` to the
|
|
1150
|
+
* hydrator after projection.
|
|
1151
|
+
*/
|
|
1152
|
+
ownerSourceAccessor: string;
|
|
1153
|
+
/**
|
|
1154
|
+
* Target-side column that matches `sourceKey` during resolution.
|
|
1155
|
+
*/
|
|
1156
|
+
targetKey: string;
|
|
1157
|
+
/** Target table name for the related rows. */
|
|
1158
|
+
targetTable: string;
|
|
1159
|
+
/** Primary-key column name on the target table. */
|
|
1160
|
+
targetPrimaryKey: string;
|
|
1161
|
+
/** Join table name for many-to-many edges. */
|
|
1162
|
+
throughTable?: string;
|
|
1163
|
+
/**
|
|
1164
|
+
* Join-table column storing the owner-side primary key for many-to-many
|
|
1165
|
+
* edges.
|
|
1166
|
+
*/
|
|
1167
|
+
throughSourceKey?: string;
|
|
1168
|
+
/**
|
|
1169
|
+
* Join-table column storing the target-side primary key for many-to-many
|
|
1170
|
+
* edges.
|
|
1171
|
+
*/
|
|
1172
|
+
throughTargetKey?: string;
|
|
1173
|
+
/**
|
|
1174
|
+
* SQL type of the owner-side join column, used to validate compiled
|
|
1175
|
+
* placeholder values.
|
|
1176
|
+
*/
|
|
1177
|
+
throughSourceColumnType?: string;
|
|
1178
|
+
/**
|
|
1179
|
+
* SQL type of the target-side join column, used to validate compiled
|
|
1180
|
+
* placeholder values.
|
|
1181
|
+
*/
|
|
1182
|
+
throughTargetColumnType?: string;
|
|
1183
|
+
/**
|
|
1184
|
+
* Column map for the target table keyed by column name. Used by the
|
|
1185
|
+
* hydrator to materialize target rows and by the compiler to emit a
|
|
1186
|
+
* stable projection.
|
|
1187
|
+
*/
|
|
1188
|
+
targetColumns: Record<string, string>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Ordered trail of relation names that led to this node. Used to produce
|
|
1191
|
+
* precise error messages when a hydration plan fails to compile.
|
|
1192
|
+
*/
|
|
1193
|
+
provenance: readonly string[];
|
|
1194
|
+
/** Child nodes whose rows arrive joined with this node's rows. */
|
|
1195
|
+
joinChildren: readonly CompiledHydrationNode[];
|
|
1196
|
+
/** Child nodes that require their own follow-up prefetch. */
|
|
1197
|
+
prefetchChildren: readonly CompiledHydrationNode[];
|
|
1198
|
+
/** SQL join descriptor attached when this node is loaded inline. */
|
|
1199
|
+
join?: CompiledJoinHydrationDescriptor;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Join-specific details for a hydration node loaded inline with its parent
|
|
1203
|
+
* query. Captures the alias the compiler emitted for the joined table and
|
|
1204
|
+
* the column aliases under which each projected column appears in the result
|
|
1205
|
+
* row.
|
|
1206
|
+
*/
|
|
1207
|
+
interface CompiledJoinHydrationDescriptor {
|
|
1208
|
+
/** SQL alias emitted for the joined table. */
|
|
1209
|
+
alias: string;
|
|
1210
|
+
/**
|
|
1211
|
+
* Aliases for each projected target column, keyed by column name.
|
|
1212
|
+
* Ensures the hydrator can pull the column out of the flat SQL row.
|
|
1213
|
+
*/
|
|
1214
|
+
columns: Record<string, string>;
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Discriminated union describing a prefetch query that must run after the
|
|
1218
|
+
* root rows load. `direct` is a one-shot select against the target table;
|
|
1219
|
+
* `manyToMany` is a two-phase plan that first reads join rows, then loads
|
|
1220
|
+
* the target rows by primary key.
|
|
1221
|
+
*/
|
|
1222
|
+
type CompiledPrefetchQuery = {
|
|
1223
|
+
/** Marks a single-query prefetch against the target table. */kind: typeof InternalPrefetchQueryKind.DIRECT; /** Parameterized select statement to execute. */
|
|
1224
|
+
sql: string; /** Parameter values bound to the statement. */
|
|
1225
|
+
params: readonly unknown[];
|
|
1226
|
+
/**
|
|
1227
|
+
* Target column whose value matches the owner-side `sourceKey`. The
|
|
1228
|
+
* hydrator buckets the returned rows by this column.
|
|
1229
|
+
*/
|
|
1230
|
+
targetKey: string; /** Column map for the target rows the hydrator will materialize. */
|
|
1231
|
+
targetColumns: Record<string, string>;
|
|
1232
|
+
} | {
|
|
1233
|
+
/**
|
|
1234
|
+
* Marks a two-phase many-to-many prefetch: the join-row query runs
|
|
1235
|
+
* first, then a follow-up target query resolves the actual rows by
|
|
1236
|
+
* primary key.
|
|
1237
|
+
*/
|
|
1238
|
+
kind: typeof InternalPrefetchQueryKind.MANY_TO_MANY;
|
|
1239
|
+
/**
|
|
1240
|
+
* SQL for the first phase: select owner/target id pairs from the
|
|
1241
|
+
* join table.
|
|
1242
|
+
*/
|
|
1243
|
+
throughSql: string; /** Parameter values bound to the join-row statement. */
|
|
1244
|
+
throughParams: readonly unknown[];
|
|
1245
|
+
/**
|
|
1246
|
+
* Alias the compiler assigned to the owner-side join column in the
|
|
1247
|
+
* join-row result set. The hydrator uses it to group targets by
|
|
1248
|
+
* owner.
|
|
1249
|
+
*/
|
|
1250
|
+
ownerAlias: string;
|
|
1251
|
+
/**
|
|
1252
|
+
* Alias the compiler assigned to the target-side join column in
|
|
1253
|
+
* the join-row result set. The hydrator uses it to assemble the
|
|
1254
|
+
* target primary-key list for phase two.
|
|
1255
|
+
*/
|
|
1256
|
+
targetAlias: string; /** Target table name for the phase-two read. */
|
|
1257
|
+
targetTable: string; /** Primary-key column on the target table for the phase-two read. */
|
|
1258
|
+
targetPrimaryKey: string; /** Column map for the target rows the hydrator will materialize. */
|
|
1259
|
+
targetColumns: Record<string, string>;
|
|
1260
|
+
};
|
|
1261
|
+
//#endregion
|
|
1262
|
+
//#region src/query/domain/internal/InternalDirection.d.ts
|
|
1263
|
+
declare const InternalDirection: {
|
|
1264
|
+
readonly ASC: "asc";
|
|
1265
|
+
readonly DESC: "desc";
|
|
1266
|
+
};
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region src/query/domain/Direction.d.ts
|
|
1269
|
+
type Direction = (typeof InternalDirection)[keyof typeof InternalDirection];
|
|
1270
|
+
//#endregion
|
|
1271
|
+
//#region src/query/domain/TableMetaFactory.d.ts
|
|
1272
|
+
/**
|
|
1273
|
+
* Build registry-backed recursive table metadata for query planning and
|
|
1274
|
+
* hydration execution.
|
|
1275
|
+
*/
|
|
1276
|
+
declare class TableMetaFactory {
|
|
1277
|
+
static create(model: Model): TableMeta;
|
|
1278
|
+
private static createWithCache;
|
|
1279
|
+
}
|
|
1280
|
+
//#endregion
|
|
1281
|
+
//#region src/query/domain/WhereClause.d.ts
|
|
1282
|
+
interface WhereClause {
|
|
1283
|
+
sql: string;
|
|
1284
|
+
params: readonly unknown[];
|
|
1285
|
+
}
|
|
1286
|
+
declare namespace index_d_exports {
|
|
1287
|
+
export { CompiledQuery, Dialect, Direction, FilterInput, FilterKey, FilterValue, ForwardSingleRelations, GeneratedHydratedRelationMap, GeneratedPrefetchRelatedPathKeys, GeneratedRelationFilterKeys, GeneratedSelectRelatedPathKeys, HydratedQueryResult, HydratedRelationMap, InternalRelationHydrationCardinality, LookupType, ManyRelationHydrationCardinality, MaybeHydratedRelationMap, OrderSpec, OrderToken, PrefetchRelatedRelations, QNode, QueryResult, QuerySetState, RelationHydrationCardinality, RelationKeys, RelationMeta, ReverseCollectionRelations, ReverseSingleRelations, SelectRelatedRelations, SingleRelationHydrationCardinality, TableMeta, TableMetaFactory, WhereClause };
|
|
1288
|
+
}
|
|
1289
|
+
//#endregion
|
|
1290
|
+
//#region src/query/domain/OrderSpec.d.ts
|
|
1291
|
+
interface OrderSpec<T> {
|
|
1292
|
+
by: keyof T;
|
|
1293
|
+
dir: Direction;
|
|
1294
|
+
}
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/query/domain/QuerySetState.d.ts
|
|
1297
|
+
interface QuerySetState<T, TSourceModel = unknown> {
|
|
1298
|
+
q?: QNode<T, TSourceModel>;
|
|
1299
|
+
excludes?: QNode<T, TSourceModel>[];
|
|
1300
|
+
order?: OrderSpec<T>[];
|
|
1301
|
+
limit?: number;
|
|
1302
|
+
offset?: number;
|
|
1303
|
+
cursor?: string | null;
|
|
1304
|
+
selectRelated?: string[];
|
|
1305
|
+
prefetchRelated?: string[];
|
|
1306
|
+
select?: (keyof T)[];
|
|
1307
|
+
}
|
|
1308
|
+
//#endregion
|
|
1309
|
+
export { QBuilder as A, index_d_exports$2 as B, ReverseSingleRelations as C, ManyToManyRelatedManagerCreateInputs as D, ManyToManyRelatedManager as E, QNode as F, TableMeta as H, FilterInput as I, FilterValue as L, QueryExecutor as M, QuerySet as N, ManyToManyTargetRef as O, OrderToken as P, FilterKey as R, ReverseCollectionRelations as S, SingleRelationHydrationCardinality as T, QueryResult as U, QueryCompiler as V, ManyRelationHydrationCardinality as _, TableMetaFactory as a, RelationHydrationCardinality as b, RelationMeta as c, GeneratedPrefetchRelatedPathKeys as d, GeneratedRelationFilterKeys as f, InternalRelationHydrationCardinality as g, HydratedRelationMap as h, WhereClause as i, ModelQuerySet as j, index_d_exports$1 as k, ForwardSingleRelations as l, HydratedQueryResult as m, OrderSpec as n, Direction as o, GeneratedSelectRelatedPathKeys as p, index_d_exports as r, CompiledQuery as s, QuerySetState as t, GeneratedHydratedRelationMap as u, MaybeHydratedRelationMap as v, SelectRelatedRelations as w, RelationKeys as x, PrefetchRelatedRelations as y, LookupType as z };
|
|
1310
|
+
//# sourceMappingURL=QuerySetState-CjyvAUBs.d.ts.map
|