relation-matcher 1.0.6 → 1.0.7
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/src/types/index.d.ts +5 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/inputs.d.ts +7 -6
- package/dist/src/types/return.d.ts +8 -7
- package/dist/src/types/typetest.d.ts +5 -4
- package/dist/src/types/typetest.js +0 -5
- package/dist/src/types/utils.d.ts +8 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -1
- package/src/index.ts +1 -1
- package/src/testing/test-data.ts +1 -0
- package/src/types/index.ts +5 -0
- package/src/types/inputs.ts +8 -7
- package/src/types/return.ts +43 -9
- package/src/types/typetest.ts +59 -29
- package/src/types/utils.ts +20 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,18 +2,19 @@ import type { TInputBase, TJoinedFromBase } from "./generic-bases";
|
|
|
2
2
|
export type RelationMapRoot<TInput extends TInputBase> = {
|
|
3
3
|
[k in keyof TInput]: {
|
|
4
4
|
base: k;
|
|
5
|
-
id: keyof TInput[k]
|
|
6
|
-
} & RelationMapJoiner<TInput, TInput[k]
|
|
5
|
+
id: keyof NonNullable<TInput[k]>;
|
|
6
|
+
} & RelationMapJoiner<TInput, NonNullable<TInput[k]>>;
|
|
7
7
|
}[keyof TInput];
|
|
8
8
|
export type RelationMapBase<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase> = {
|
|
9
9
|
[k in keyof TInput]: {
|
|
10
10
|
base: k;
|
|
11
|
-
id
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/** The id that uniqueness is checked against. Either the primary key of the table, or the id you are joining **to** on a join table. */
|
|
12
|
+
id: keyof NonNullable<TInput[k]>;
|
|
13
|
+
joinsTo: keyof NonNullable<TInput[k]>;
|
|
14
|
+
joinsFrom: keyof NonNullable<TJoinedFrom>;
|
|
14
15
|
joinType: "single" | "array";
|
|
15
16
|
} & RelationMapJoiner<TInput, TInput[k]>;
|
|
16
17
|
}[keyof TInput];
|
|
17
18
|
export type RelationMapJoiner<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase> = {
|
|
18
|
-
[k: `_${string}`]:
|
|
19
|
+
[k: `_${string}`]: RelationMapBase<TInput, TJoinedFrom> & RelationMapJoiner<TInput, TJoinedFrom>;
|
|
19
20
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { TInputBase, TJoinedFromBase, TOutputBase } from "./generic-bases";
|
|
2
2
|
import type { RelationMapRoot } from "./inputs";
|
|
3
|
-
import type { NoUnderscore } from "./utils";
|
|
4
|
-
export type RelationMapperReturnRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>> = {
|
|
5
|
-
[inputKey in keyof TInput]: TInput[TOutput["base"]] &
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import type { ExtendsNull, NoUnderscore, Simplify } from "./utils";
|
|
4
|
+
export type RelationMapperReturnRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>> = Simplify<{
|
|
5
|
+
[inputKey in keyof TInput]: ExtendsNull<TInput[TOutput["base"]]> extends true ? Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, inputKey>> | null : Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoinRoot<TInput, TOutput, inputKey>>;
|
|
6
|
+
}[keyof TInput]>;
|
|
7
|
+
export type RelationMapperReturnJoinRoot<TInput extends TInputBase, TOutput extends RelationMapRoot<TInput>, TInputKey extends keyof TInput> = {
|
|
8
|
+
[outputKey in NoUnderscore<keyof TOutput>]: Simplify<RelationMapperReturn<TInput, TInput[TInputKey], TOutput[`_${outputKey}`]>>;
|
|
9
|
+
};
|
|
9
10
|
/** Fill current object with value specified in base */
|
|
10
|
-
export type RelationMapperReturn<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase, TOutput extends TOutputBase<TInput, TJoinedFrom>> = TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput
|
|
11
|
+
export type RelationMapperReturn<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase, TOutput extends TOutputBase<TInput, TJoinedFrom>> = TOutput["joinType"] extends "array" ? Array<Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>>> : ExtendsNull<TInput[TOutput["base"]]> extends true ? Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>> | null : Simplify<TInput[TOutput["base"]] & RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>>;
|
|
11
12
|
/** Takes underscored values (joins) and replaces their values with the actual output. */
|
|
12
13
|
export type RelationMapperReturnJoin<TInput extends TInputBase, TJoinedFrom extends TJoinedFromBase, TOutput extends TOutputBase<TInput, TJoinedFrom>> = {
|
|
13
14
|
[k in NoUnderscore<keyof TOutput>]: RelationMapperReturn<TInput, TJoinedFrom, TOutput[`_${k}`]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RelationMapperReturnRoot } from "./return";
|
|
2
|
-
|
|
2
|
+
import type { DeepSimplify } from "./utils";
|
|
3
|
+
export type A = DeepSimplify<RelationMapperReturnRoot<{
|
|
3
4
|
team: {
|
|
4
5
|
created_at: Date;
|
|
5
6
|
updated_at: Date | null;
|
|
@@ -13,7 +14,7 @@ export type A = RelationMapperReturnRoot<{
|
|
|
13
14
|
updated_at: Date | null;
|
|
14
15
|
user_clerk_id: string;
|
|
15
16
|
team_id: string;
|
|
16
|
-
};
|
|
17
|
+
} | null;
|
|
17
18
|
}, {
|
|
18
19
|
base: "team";
|
|
19
20
|
id: "id";
|
|
@@ -23,7 +24,7 @@ export type A = RelationMapperReturnRoot<{
|
|
|
23
24
|
joinsTo: "team_id";
|
|
24
25
|
joinsFrom: "id";
|
|
25
26
|
joinType: "single";
|
|
26
|
-
|
|
27
|
+
_team: {
|
|
27
28
|
base: "team";
|
|
28
29
|
id: "id";
|
|
29
30
|
joinsFrom: "team_id";
|
|
@@ -31,4 +32,4 @@ export type A = RelationMapperReturnRoot<{
|
|
|
31
32
|
joinType: "array";
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
}>;
|
|
35
|
+
}>, Date | null | number>;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export type Simplify<T> = {
|
|
2
2
|
[k in keyof T]: T[k];
|
|
3
3
|
} & {};
|
|
4
|
-
export type DeepSimplify<
|
|
5
|
-
[k in keyof
|
|
4
|
+
export type DeepSimplify<TInput, TDontSimplify> = {
|
|
5
|
+
[k in keyof TInput]: TInput[k] extends TDontSimplify ? TInput[k] : DeepSimplify<TInput[k], TDontSimplify>;
|
|
6
6
|
} & {};
|
|
7
7
|
export type NoUnderscore<T extends string | number | symbol> = T extends `_${infer Result}` ? Result : never;
|
|
8
|
+
export type DeepNonNullable<T extends object> = {
|
|
9
|
+
[k in keyof T]: T[k] extends infer NonNull | null ? NonNull : T[k];
|
|
10
|
+
};
|
|
11
|
+
export type ArrayOrSingle<T, TType extends "single" | "array"> = TType extends "array" ? Array<T> : T;
|
|
12
|
+
export type IsNullIfNull<TIsNull extends object | null, TReturn extends object | never = never> = TIsNull extends infer T ? (T & TReturn) | null : TIsNull & TReturn;
|
|
13
|
+
export type ExtendsNull<T> = null extends T ? true : false;
|