linkgress-orm 0.4.80 → 0.4.81
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/query/grouped-query.d.ts +6 -2
- package/dist/query/grouped-query.d.ts.map +1 -1
- package/dist/query/grouped-query.js +28 -3
- package/dist/query/grouped-query.js.map +1 -1
- package/dist/query/query-builder.d.ts +46 -3
- package/dist/query/query-builder.d.ts.map +1 -1
- package/dist/query/query-builder.js +184 -91
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/query-utils.d.ts +41 -0
- package/dist/query/query-utils.d.ts.map +1 -1
- package/dist/query/query-utils.js +56 -0
- package/dist/query/query-utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -43,4 +43,45 @@ export declare function getQualifiedFieldName(fieldRef: any): string;
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function getTableAlias(fieldRef: any): string | undefined;
|
|
45
45
|
export declare function collectionMarkerPattern(targetTable: string, withDot: boolean): RegExp;
|
|
46
|
+
/**
|
|
47
|
+
* Whether `ref` was minted by a query chain OTHER than `ownChainId` — i.e. it is a
|
|
48
|
+
* correlation to an enclosing query rather than something this builder owns.
|
|
49
|
+
*
|
|
50
|
+
* Alias identity alone cannot answer this. A subquery's own navigation aliases are its
|
|
51
|
+
* relation NAMES, and a relation name may coincide with an outer table's alias: a child with
|
|
52
|
+
* a `library` navigation, correlated against a parent table also called `library`. Resolving
|
|
53
|
+
* such a ref by name makes the builder join a second, inner copy of the parent and bind the
|
|
54
|
+
* correlation to it, which turns the predicate into a comparison of the inner row with
|
|
55
|
+
* itself — true for every row, no SQL error, no type error. Singular table names
|
|
56
|
+
* (`library` + `shelf.library`) produce that collision as a matter of course; the
|
|
57
|
+
* plural-table/singular-navigation convention (`users` + `post.user`) hides it.
|
|
58
|
+
*
|
|
59
|
+
* The builder families stamp identity differently, and both are handled here:
|
|
60
|
+
*
|
|
61
|
+
* - `QueryBuilder` / `SelectQueryBuilder` / `GroupedQueryBuilder` carry their own chain id,
|
|
62
|
+
* so a ref is foreign when its id differs from `ownChainId`.
|
|
63
|
+
* - `CollectionQueryBuilder` stamps nothing: the refs IT mints — plain columns under the
|
|
64
|
+
* `__collection_<table>__` marker AND navigation traversals under the relation name — all
|
|
65
|
+
* carry no id, while a reference to the enclosing row carries that query's id. Callers
|
|
66
|
+
* there pass `ownChainId: undefined`, for which "has an id at all" is exactly the right
|
|
67
|
+
* test. That is what lets `s.library.name` (inner navigation) be told apart from `l.name`
|
|
68
|
+
* (outer row) when both render under the alias `library`.
|
|
69
|
+
*
|
|
70
|
+
* A ref with no id is never foreign: paths that do not stamp identity keep their previous,
|
|
71
|
+
* name-based treatment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isForeignChainRef(ref: any, ownChainId: number | undefined): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Refuse a subquery that correlates to an outer table AND joins a navigation of its own under
|
|
76
|
+
* the same alias.
|
|
77
|
+
*
|
|
78
|
+
* Both want one identifier in one scope. The inner join wins, so it shadows the outer table and
|
|
79
|
+
* the correlation predicate silently rebinds to the inner row — true for every row, no SQL
|
|
80
|
+
* error. There is no correct SQL to emit for this shape, so it is refused at build time; the
|
|
81
|
+
* message names the alias and the three ways out.
|
|
82
|
+
*
|
|
83
|
+
* Shared by every builder that resolves aliases into joins, so `.groupBy()` and the collection
|
|
84
|
+
* path cannot become quiet bypasses of a rule the standalone path enforces loudly.
|
|
85
|
+
*/
|
|
86
|
+
export declare function assertNoCorrelatedAliasShadowing(tableName: string, correlatedAliases: Iterable<string>, ownJoinAliases: ReadonlySet<string>): void;
|
|
46
87
|
//# sourceMappingURL=query-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-utils.d.ts","sourceRoot":"","sources":["../../src/query/query-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAkB,aAAa,EA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iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAMnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gCAAgC,CAC9C,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,EACnC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,IAAI,CAUN"}
|
|
@@ -7,6 +7,8 @@ exports.parseOrderBy = parseOrderBy;
|
|
|
7
7
|
exports.getQualifiedFieldName = getQualifiedFieldName;
|
|
8
8
|
exports.getTableAlias = getTableAlias;
|
|
9
9
|
exports.collectionMarkerPattern = collectionMarkerPattern;
|
|
10
|
+
exports.isForeignChainRef = isForeignChainRef;
|
|
11
|
+
exports.assertNoCorrelatedAliasShadowing = assertNoCorrelatedAliasShadowing;
|
|
10
12
|
/**
|
|
11
13
|
* Type guard to check if a value is a FieldRef
|
|
12
14
|
*/
|
|
@@ -120,4 +122,58 @@ function collectionMarkerPattern(targetTable, withDot) {
|
|
|
120
122
|
}
|
|
121
123
|
return pattern;
|
|
122
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Whether `ref` was minted by a query chain OTHER than `ownChainId` — i.e. it is a
|
|
127
|
+
* correlation to an enclosing query rather than something this builder owns.
|
|
128
|
+
*
|
|
129
|
+
* Alias identity alone cannot answer this. A subquery's own navigation aliases are its
|
|
130
|
+
* relation NAMES, and a relation name may coincide with an outer table's alias: a child with
|
|
131
|
+
* a `library` navigation, correlated against a parent table also called `library`. Resolving
|
|
132
|
+
* such a ref by name makes the builder join a second, inner copy of the parent and bind the
|
|
133
|
+
* correlation to it, which turns the predicate into a comparison of the inner row with
|
|
134
|
+
* itself — true for every row, no SQL error, no type error. Singular table names
|
|
135
|
+
* (`library` + `shelf.library`) produce that collision as a matter of course; the
|
|
136
|
+
* plural-table/singular-navigation convention (`users` + `post.user`) hides it.
|
|
137
|
+
*
|
|
138
|
+
* The builder families stamp identity differently, and both are handled here:
|
|
139
|
+
*
|
|
140
|
+
* - `QueryBuilder` / `SelectQueryBuilder` / `GroupedQueryBuilder` carry their own chain id,
|
|
141
|
+
* so a ref is foreign when its id differs from `ownChainId`.
|
|
142
|
+
* - `CollectionQueryBuilder` stamps nothing: the refs IT mints — plain columns under the
|
|
143
|
+
* `__collection_<table>__` marker AND navigation traversals under the relation name — all
|
|
144
|
+
* carry no id, while a reference to the enclosing row carries that query's id. Callers
|
|
145
|
+
* there pass `ownChainId: undefined`, for which "has an id at all" is exactly the right
|
|
146
|
+
* test. That is what lets `s.library.name` (inner navigation) be told apart from `l.name`
|
|
147
|
+
* (outer row) when both render under the alias `library`.
|
|
148
|
+
*
|
|
149
|
+
* A ref with no id is never foreign: paths that do not stamp identity keep their previous,
|
|
150
|
+
* name-based treatment.
|
|
151
|
+
*/
|
|
152
|
+
function isForeignChainRef(ref, ownChainId) {
|
|
153
|
+
if (ref?.__chainId == null) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return ownChainId == null || ref.__chainId !== ownChainId;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Refuse a subquery that correlates to an outer table AND joins a navigation of its own under
|
|
160
|
+
* the same alias.
|
|
161
|
+
*
|
|
162
|
+
* Both want one identifier in one scope. The inner join wins, so it shadows the outer table and
|
|
163
|
+
* the correlation predicate silently rebinds to the inner row — true for every row, no SQL
|
|
164
|
+
* error. There is no correct SQL to emit for this shape, so it is refused at build time; the
|
|
165
|
+
* message names the alias and the three ways out.
|
|
166
|
+
*
|
|
167
|
+
* Shared by every builder that resolves aliases into joins, so `.groupBy()` and the collection
|
|
168
|
+
* path cannot become quiet bypasses of a rule the standalone path enforces loudly.
|
|
169
|
+
*/
|
|
170
|
+
function assertNoCorrelatedAliasShadowing(tableName, correlatedAliases, ownJoinAliases) {
|
|
171
|
+
for (const alias of correlatedAliases) {
|
|
172
|
+
if (ownJoinAliases.has(alias)) {
|
|
173
|
+
throw new Error(`Correlated subquery over table "${tableName}" both correlates to an outer "${alias}" and joins its own "${alias}" navigation. `
|
|
174
|
+
+ `Both would use the alias "${alias}", so the inner join would shadow the outer table and the correlation would silently bind to the inner row. `
|
|
175
|
+
+ `Traverse the navigation in the OUTER query, correlate on a plain key column instead of the navigation, or rename the navigation property.`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
123
179
|
//# sourceMappingURL=query-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-utils.js","sourceRoot":"","sources":["../../src/query/query-utils.ts"],"names":[],"mappings":";;AAMA,gCAOC;AAKD,oCAMC;AAKD,kDAEC;AAkBD,oCAgDC;AAYD,sDAIC;AAKD,sCAEC;AAaD,0DAQC;
|
|
1
|
+
{"version":3,"file":"query-utils.js","sourceRoot":"","sources":["../../src/query/query-utils.ts"],"names":[],"mappings":";;AAMA,gCAOC;AAKD,oCAMC;AAKD,kDAEC;AAkBD,oCAgDC;AAYD,sDAIC;AAKD,sCAEC;AAaD,0DAQC;AA6BD,8CAMC;AAcD,4EAcC;AAzMD;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,aAAa,IAAI,KAAK;QACtB,gBAAgB,IAAI,KAAK,CAC1B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,aAAa,IAAI,KAAK,CACvB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAc;IAChD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,eAAe,IAAI,KAAK,IAAK,KAAa,CAAC,aAAa,KAAK,IAAI,CAAC;AAChG,CAAC;AAWD;;;;;;GAMG;AACH,SAAgB,YAAY,CAC1B,MAAwB,EACx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