Skip to content

Commit c32cd78

Browse files
committed
feat(sql-orm-client): require junction namespaceId on the include through descriptor
The contract now carries the junction's namespaceId on through (slice 0); the include descriptor passes it through as a required field instead of re-deriving it from storage. Re-emit the M:N fixture so the User<->Tag through block carries it. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 9d7344e commit c32cd78

7 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/3-extensions/sql-orm-client/src/collection-contract.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,11 @@ export function resolveIncludeRelation(
251251
);
252252
through = {
253253
table: relation.through.table,
254+
namespaceId: relation.through.namespaceId,
254255
parentColumns: relation.through.parentColumns,
255256
childColumns: relation.through.childColumns,
256257
targetColumns: relation.through.targetColumns,
257258
parentLocalColumns,
258-
...(relation.through.namespaceId !== undefined
259-
? { namespaceId: relation.through.namespaceId }
260-
: {}),
261259
};
262260
}
263261

packages/3-extensions/sql-orm-client/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface IncludeCombine<ResultShape extends Record<string, unknown>>
5252

5353
export interface IncludeThroughDescriptor {
5454
readonly table: string;
55+
/** Namespace the junction table lives in, as declared in the contract. */
56+
readonly namespaceId: string;
5557
/** FK columns in the junction table that point to the parent. */
5658
readonly parentColumns: readonly string[];
5759
/** FK columns in the junction table that point to the target (child). */
@@ -60,8 +62,6 @@ export interface IncludeThroughDescriptor {
6062
readonly targetColumns: readonly string[];
6163
/** Resolved column names in the parent table that junction.parentColumns reference. */
6264
readonly parentLocalColumns: readonly string[];
63-
/** Namespace of the junction table, resolved from storage. */
64-
readonly namespaceId?: string;
6565
}
6666

6767
export interface IncludeExpr {

packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/3-extensions/sql-orm-client/test/query-plan-select.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ describe('M:N include correlated subquery', () => {
638638
cardinality: 'N:M',
639639
through: {
640640
table: opts.junctionTable,
641+
namespaceId: 'public',
641642
parentColumns: opts.parentColumns,
642643
childColumns: opts.childColumns,
643644
targetColumns: opts.targetColumns,
@@ -912,6 +913,7 @@ describe('M:N include correlated subquery', () => {
912913
cardinality: 'N:M',
913914
through: {
914915
table: 'parent_child',
916+
namespaceId: 'public',
915917
parentColumns: ['parent_id'],
916918
childColumns: ['child_id'],
917919
targetColumns: ['id'],

test/integration/test/sql-orm-client/fixtures/generated/contract.d.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/test/sql-orm-client/fixtures/generated/contract.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)