relation-matcher 1.0.12 → 1.1.0
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/.vscode/settings.json +4 -4
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.13.0.cjs +940 -940
- package/.yarnrc.yml +3 -3
- package/README.md +181 -0
- package/dist/src/index.js +6 -1
- package/dist/src/types/generic-less.d.ts +1 -0
- package/dist/src/types/inputs.d.ts +14 -7
- package/dist/src/types/return.d.ts +5 -2
- package/dist/src/types/typetest.d.ts +1 -0
- package/dist/src/utils/invertInput.js +4 -9
- package/dist/src/utils/keys.js +6 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -36
- package/src/index.test.ts +105 -105
- package/src/index.ts +160 -151
- package/src/testing/file-output.ts +15 -15
- package/src/testing/test-data.ts +172 -172
- package/src/types/generic-bases.ts +9 -9
- package/src/types/generic-less.ts +15 -14
- package/src/types/index.ts +5 -5
- package/src/types/inputs.ts +36 -30
- package/src/types/return.ts +65 -67
- package/src/types/typetest.ts +87 -84
- package/src/types/utils.ts +28 -28
- package/src/utils/invertInput.ts +25 -28
- package/src/utils/keys.ts +7 -1
- package/src/utils/matcher.ts +8 -8
package/src/types/typetest.ts
CHANGED
|
@@ -1,84 +1,87 @@
|
|
|
1
|
-
import type { RelationMapperReturnRoot } from "./return";
|
|
2
|
-
import type { DeepSimplify, ExtendsNull, Simplify } from "./utils";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import type { RelationMapperReturnRoot } from "./return";
|
|
2
|
+
import type { DeepSimplify, ExtendsNull, Simplify } from "./utils";
|
|
3
|
+
|
|
4
|
+
type E = true extends undefined ? true : false;
|
|
5
|
+
|
|
6
|
+
export type A = DeepSimplify<
|
|
7
|
+
RelationMapperReturnRoot<
|
|
8
|
+
{
|
|
9
|
+
team: {
|
|
10
|
+
created_at: Date;
|
|
11
|
+
updated_at: Date | null;
|
|
12
|
+
id: string;
|
|
13
|
+
team_name: string;
|
|
14
|
+
club_name: string;
|
|
15
|
+
club_postcode: string;
|
|
16
|
+
};
|
|
17
|
+
team_to_user: {
|
|
18
|
+
created_at: Date;
|
|
19
|
+
updated_at: Date | null;
|
|
20
|
+
user_clerk_id: string;
|
|
21
|
+
team_id: string;
|
|
22
|
+
} | null;
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
base: "team";
|
|
26
|
+
id: "id";
|
|
27
|
+
|
|
28
|
+
_teamToUser: {
|
|
29
|
+
base: "team_to_user";
|
|
30
|
+
id: "user_clerk_id";
|
|
31
|
+
joinsTo: "team_id";
|
|
32
|
+
joinsFrom: "id";
|
|
33
|
+
joinType: "single";
|
|
34
|
+
isNullable: false;
|
|
35
|
+
|
|
36
|
+
_team: {
|
|
37
|
+
base: "team";
|
|
38
|
+
id: "id";
|
|
39
|
+
joinsFrom: "team_id";
|
|
40
|
+
joinsTo: "id";
|
|
41
|
+
joinType: "array";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
>,
|
|
46
|
+
Date | null | number
|
|
47
|
+
>;
|
|
48
|
+
|
|
49
|
+
type B = RelationMapperReturnRoot<
|
|
50
|
+
{
|
|
51
|
+
user: {
|
|
52
|
+
clerk_id: string;
|
|
53
|
+
};
|
|
54
|
+
team_to_user: {
|
|
55
|
+
team_id: string;
|
|
56
|
+
user_clerk_id: string;
|
|
57
|
+
} | null;
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
base: "user";
|
|
61
|
+
id: "clerk_id";
|
|
62
|
+
|
|
63
|
+
_teamToUser: {
|
|
64
|
+
base: "team_to_user";
|
|
65
|
+
id: "team_id";
|
|
66
|
+
joinsFrom: "clerk_id";
|
|
67
|
+
joinsTo: "user_clerk_id";
|
|
68
|
+
joinType: "single";
|
|
69
|
+
|
|
70
|
+
_user: {
|
|
71
|
+
base: "user";
|
|
72
|
+
id: "clerk_id";
|
|
73
|
+
joinsFrom: "user_clerk_id";
|
|
74
|
+
joinsTo: "clerk_id";
|
|
75
|
+
joinType: "array";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
>;
|
|
80
|
+
|
|
81
|
+
type C = Simplify<B>;
|
|
82
|
+
// ^?
|
|
83
|
+
|
|
84
|
+
type D = ExtendsNull<{
|
|
85
|
+
team_id: string;
|
|
86
|
+
user_clerk_id: string;
|
|
87
|
+
} | null>;
|
package/src/types/utils.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export type Simplify<T> = {
|
|
2
|
-
[k in keyof T]: T[k];
|
|
3
|
-
} & {};
|
|
4
|
-
|
|
5
|
-
export type DeepSimplify<TInput, TDontSimplify> = {
|
|
6
|
-
[k in keyof TInput]: TInput[k] extends TDontSimplify
|
|
7
|
-
? TInput[k]
|
|
8
|
-
: DeepSimplify<TInput[k], TDontSimplify>;
|
|
9
|
-
} & {};
|
|
10
|
-
|
|
11
|
-
export type NoUnderscore<T extends string | number | symbol> =
|
|
12
|
-
T extends `_${infer Result}` ? Result : never;
|
|
13
|
-
|
|
14
|
-
export type DeepNonNullable<T extends object> = {
|
|
15
|
-
[k in keyof T]: T[k] extends infer NonNull | null ? NonNull : T[k];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type ArrayOrSingle<
|
|
19
|
-
T,
|
|
20
|
-
TType extends "single" | "array",
|
|
21
|
-
> = TType extends "array" ? Array<T> : T;
|
|
22
|
-
|
|
23
|
-
export type IsNullIfNull<
|
|
24
|
-
TIsNull extends object | null,
|
|
25
|
-
TReturn extends object | never = never,
|
|
26
|
-
> = TIsNull extends infer T ? (T & TReturn) | null : TIsNull & TReturn;
|
|
27
|
-
|
|
28
|
-
export type ExtendsNull<T> = null extends T ? true : false;
|
|
1
|
+
export type Simplify<T> = {
|
|
2
|
+
[k in keyof T]: T[k];
|
|
3
|
+
} & {};
|
|
4
|
+
|
|
5
|
+
export type DeepSimplify<TInput, TDontSimplify> = {
|
|
6
|
+
[k in keyof TInput]: TInput[k] extends TDontSimplify
|
|
7
|
+
? TInput[k]
|
|
8
|
+
: DeepSimplify<TInput[k], TDontSimplify>;
|
|
9
|
+
} & {};
|
|
10
|
+
|
|
11
|
+
export type NoUnderscore<T extends string | number | symbol> =
|
|
12
|
+
T extends `_${infer Result}` ? Result : never;
|
|
13
|
+
|
|
14
|
+
export type DeepNonNullable<T extends object> = {
|
|
15
|
+
[k in keyof T]: T[k] extends infer NonNull | null ? NonNull : T[k];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ArrayOrSingle<
|
|
19
|
+
T,
|
|
20
|
+
TType extends "single" | "array",
|
|
21
|
+
> = TType extends "array" ? Array<T> : T;
|
|
22
|
+
|
|
23
|
+
export type IsNullIfNull<
|
|
24
|
+
TIsNull extends object | null,
|
|
25
|
+
TReturn extends object | never = never,
|
|
26
|
+
> = TIsNull extends infer T ? (T & TReturn) | null : TIsNull & TReturn;
|
|
27
|
+
|
|
28
|
+
export type ExtendsNull<T> = null extends T ? true : false;
|
package/src/utils/invertInput.ts
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import type { TInputBase } from "~/types/generic-bases";
|
|
2
|
-
|
|
3
|
-
export type InvertedInput<TInput extends TInputBase = TInputBase> = Record<
|
|
4
|
-
keyof TInput,
|
|
5
|
-
TInput[keyof TInput][]
|
|
6
|
-
>;
|
|
7
|
-
|
|
8
|
-
const invertInput = <TInput extends TInputBase>(
|
|
9
|
-
inputs: TInputBase[],
|
|
10
|
-
): InvertedInput<TInput> => {
|
|
11
|
-
const invertedInput = inputs.reduce<InvertedInput<TInput>>((final, row) => {
|
|
12
|
-
Object.entries(row).forEach(([header, value]) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default invertInput;
|
|
1
|
+
import type { TInputBase } from "~/types/generic-bases";
|
|
2
|
+
|
|
3
|
+
export type InvertedInput<TInput extends TInputBase = TInputBase> = Record<
|
|
4
|
+
keyof TInput,
|
|
5
|
+
TInput[keyof TInput][]
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
const invertInput = <TInput extends TInputBase>(
|
|
9
|
+
inputs: TInputBase[],
|
|
10
|
+
): InvertedInput<TInput> => {
|
|
11
|
+
const invertedInput = inputs.reduce<InvertedInput<TInput>>((final, row) => {
|
|
12
|
+
Object.entries(row).forEach(([header, value]) => {
|
|
13
|
+
final[header as keyof TInput] ??= [];
|
|
14
|
+
|
|
15
|
+
// Instantiated above.
|
|
16
|
+
if (value) final[header]!.push(value as TInput[keyof TInput]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return final;
|
|
20
|
+
}, {} as InvertedInput<TInput>);
|
|
21
|
+
|
|
22
|
+
return invertedInput;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default invertInput;
|
package/src/utils/keys.ts
CHANGED
package/src/utils/matcher.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { TInputBase } from "~/types/generic-bases";
|
|
2
|
-
import type { InvertedInput } from "./invertInput";
|
|
3
|
-
import type { Output } from "~/types/generic-less";
|
|
4
|
-
|
|
5
|
-
export const matcherFunc =
|
|
6
|
-
<TInput extends TInputBase>(row: TInput[keyof TInput], value: Output) =>
|
|
7
|
-
(item: InvertedInput[keyof InvertedInput][number]) =>
|
|
8
|
-
row?.[value.joinsFrom as string] === item?.[value.joinsTo as string];
|
|
1
|
+
import type { TInputBase } from "~/types/generic-bases";
|
|
2
|
+
import type { InvertedInput } from "./invertInput";
|
|
3
|
+
import type { Output } from "~/types/generic-less";
|
|
4
|
+
|
|
5
|
+
export const matcherFunc =
|
|
6
|
+
<TInput extends TInputBase>(row: TInput[keyof TInput], value: Output) =>
|
|
7
|
+
(item: InvertedInput[keyof InvertedInput][number]) =>
|
|
8
|
+
row?.[value.joinsFrom as string] === item?.[value.joinsTo as string];
|