Skip to content

Commit f482cd8

Browse files
committed
refactor(sql-orm-client): canonicalise cardinality tag from 'M:N' to 'N:M'
The SQL contract already emits 'N:M' (landed in D1). sql-orm-client was the lone holdout still spelling it 'M:N', meaning a real emitted M:N relation parsed to undefined and the mutation guard silently never fired. Flip all four literal sites in src/: - RelationCardinalityTag union (types.ts) - partitionByOwnership guard + error message (mutation-executor.ts) - IsToManyRelation type-level check (collection-internal-types.ts) - parseRelationCardinality acceptance check (collection-contract.ts) Update tests to match: move the rejection test's cardinality literal to 'N:M' (stays a rejection test), update the guard error message regex, and update the isToOneCardinality argument in collection-contract.test.ts (required for typecheck: 'M:N' is no longer assignable to RelationCardinalityTag). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 348775c commit f482cd8

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export function resolveModelRelations(
298298
}
299299

300300
export function parseRelationCardinality(value: unknown): RelationCardinalityTag | undefined {
301-
if (value === '1:1' || value === 'N:1' || value === '1:N' || value === 'M:N') {
301+
if (value === '1:1' || value === 'N:1' || value === '1:N' || value === 'N:M') {
302302
return value;
303303
}
304304
return undefined;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type IsToManyRelation<
8383
TContract extends Contract<SqlStorage>,
8484
ModelName extends string,
8585
RelName extends string,
86-
> = RelationCardinality<TContract, ModelName, RelName> extends '1:N' | 'M:N' ? true : false;
86+
> = RelationCardinality<TContract, ModelName, RelName> extends '1:N' | 'N:M' ? true : false;
8787

8888
export type IncludeRefinementResult<
8989
TContract extends Contract<SqlStorage>,

packages/3-extensions/sql-orm-client/src/mutation-executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ function partitionByOwnership(relationMutations: readonly ParsedRelationMutation
348348
continue;
349349
}
350350

351-
if (relationMutation.relation.cardinality === 'M:N') {
352-
throw new Error('M:N nested mutations are not supported yet');
351+
if (relationMutation.relation.cardinality === 'N:M') {
352+
throw new Error('N:M nested mutations are not supported yet');
353353
}
354354

355355
childOwned.push(relationMutation);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface CollectionTypeState {
106106
readonly variantName: string | undefined;
107107
}
108108

109-
export type RelationCardinalityTag = '1:1' | 'N:1' | '1:N' | 'M:N';
109+
export type RelationCardinalityTag = '1:1' | 'N:1' | '1:N' | 'N:M';
110110

111111
export type DefaultCollectionTypeState = {
112112
readonly hasOrderBy: false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe('collection-contract capability detection', () => {
222222
expect(isToOneCardinality('1:1')).toBe(true);
223223
expect(isToOneCardinality('N:1')).toBe(true);
224224
expect(isToOneCardinality('1:N')).toBe(false);
225-
expect(isToOneCardinality('M:N')).toBe(false);
225+
expect(isToOneCardinality('N:M')).toBe(false);
226226
expect(isToOneCardinality(undefined)).toBe(false);
227227
});
228228

packages/3-extensions/sql-orm-client/test/mutation-executor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ describe('mutation-executor', () => {
405405
...user.relations,
406406
posts: {
407407
...user.relations.posts,
408-
cardinality: 'M:N',
408+
cardinality: 'N:M',
409409
},
410410
},
411411
},
@@ -425,7 +425,7 @@ describe('mutation-executor', () => {
425425
posts.connect({ id: 10 }),
426426
} as never,
427427
}),
428-
).rejects.toThrow(/M:N nested mutations are not supported yet/);
428+
).rejects.toThrow(/N:M nested mutations are not supported yet/);
429429
});
430430

431431
it('executeNestedCreateMutation() supports parent-owned nested create() payloads', async () => {

0 commit comments

Comments
 (0)