Skip to content

Commit

Permalink
NotNullable relations closes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
lroal committed Jun 7, 2024
1 parent 5c04698 commit 2773612
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orange-orm",
"version": "4.0.1",
"version": "4.1.0",
"main": "./src/index.js",
"browser": "./src/client/index.mjs",
"bin": {
Expand Down
31 changes: 19 additions & 12 deletions src/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ type ReferenceMapperHelper<TFrom, TTo, TPrimaryCount> =
column4: C4,
column5: C5,
column6: C6
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: 5 extends TPrimaryCount
? {
Expand All @@ -847,7 +847,7 @@ type ReferenceMapperHelper<TFrom, TTo, TPrimaryCount> =
column3: C3,
column4: C4,
column5: C5
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: 4 extends TPrimaryCount
? {
Expand All @@ -856,31 +856,33 @@ type ReferenceMapperHelper<TFrom, TTo, TPrimaryCount> =
column2: C2,
column3: C3,
column4: C4
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: 3 extends TPrimaryCount
? {
by<C1 extends keyof KeyCandidates1<TFrom, TTo>, C2 extends keyof KeyCandidates2<TFrom, TTo>, C3 extends keyof KeyCandidates2<TFrom, TTo>>(
column: C1,
column2: C2,
column3: C3
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: 2 extends TPrimaryCount
? {
by<C1 extends keyof KeyCandidates1<TFrom, TTo>, C2 extends keyof KeyCandidates2<TFrom, TTo>>(
column: C1,
column2: C2
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: 1 extends TPrimaryCount
? {
by<C1 extends keyof KeyCandidates1<TFrom, TTo>>(
column: C1
): MappedTableDef<TTo> & RelatedTable;
): MappedTableDef<TTo> & RelatedTable & NegotiateNotNullColumn<C1,TFrom>;
}
: {};

type NegotiateNotNullColumn<C, TFrom> = C extends keyof TFrom ? TFrom[C] extends NotNullExceptInsert ? NotNullExceptInsert : TFrom[C] extends NotNull ? NotNull : {}: {};

type HasMapperHelper<
TFrom,
TTo,
Expand All @@ -895,7 +897,7 @@ type HasMapperHelper<
column4: keyof KeyCandidates4<TTo, TFrom>,
column5: keyof KeyCandidates5<TTo, TFrom>,
column6: keyof KeyCandidates6<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: 5 extends TPrimaryCount
? {
Expand All @@ -905,7 +907,7 @@ type HasMapperHelper<
column3: keyof KeyCandidates3<TTo, TFrom>,
column4: keyof KeyCandidates4<TTo, TFrom>,
column5: keyof KeyCandidates5<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: 4 extends TPrimaryCount
? {
Expand All @@ -914,31 +916,36 @@ type HasMapperHelper<
column2: keyof KeyCandidates2<TTo, TFrom>,
column3: keyof KeyCandidates3<TTo, TFrom>,
column4: keyof KeyCandidates4<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: 3 extends TPrimaryCount
? {
by(
column: keyof KeyCandidates1<TTo, TFrom>,
column2: keyof KeyCandidates2<TTo, TFrom>,
column3: keyof KeyCandidates3<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: 2 extends TPrimaryCount
? {
by(
column: keyof KeyCandidates1<TTo, TFrom>,
column2: keyof KeyCandidates2<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: 1 extends TPrimaryCount
? {
by(
column: keyof KeyCandidates1<TTo, TFrom>
): MappedTableDef<TTo> & RelatedTable & TExtra;
): MappedTableDef<TTo> & RelatedTable & TExtra & HasMapperHelper2<MappedTableDef<TTo> & RelatedTable & TExtra>;
}
: {};

type HasMapperHelper2<T> = {
notNull(): T & NotNull;
notNullExceptInsert(): T & NotNull & NotNullExceptInsert;
}

type ColumnMapperInit<T> = {
column(columnName: string): ColumnType<{}>;
primaryColumn(columnName: string): ColumnType<IsPrimary>;
Expand Down

0 comments on commit 2773612

Please sign in to comment.