relation-matcher 1.0.13 → 1.1.1
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 +185 -150
- package/dist/src/index.d.ts +10 -5
- package/dist/src/index.js +35 -46
- package/dist/src/types/generic-bases.d.ts +2 -1
- package/dist/src/types/generic-less.d.ts +8 -3
- 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/types/utils.d.ts +3 -0
- package/dist/src/utils/invertInput.d.ts +2 -1
- package/dist/src/utils/invertInput.js +4 -9
- package/dist/src/utils/isNullable.d.ts +2 -0
- package/dist/src/utils/isNullable.js +6 -0
- package/dist/src/utils/joins.d.ts +5 -0
- package/dist/src/utils/joins.js +9 -0
- package/dist/src/utils/keys.js +6 -1
- package/dist/src/utils/matcher.d.ts +3 -3
- package/dist/src/utils/matcher.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -36
- package/src/index.test.ts +105 -105
- package/src/index.ts +124 -151
- package/src/testing/file-output.ts +15 -15
- package/src/testing/test-data.ts +172 -172
- package/src/types/generic-bases.ts +10 -9
- package/src/types/generic-less.ts +20 -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 +33 -28
- package/src/utils/invertInput.ts +27 -28
- package/src/utils/isNullable.ts +11 -0
- package/src/utils/joins.ts +22 -0
- package/src/utils/keys.ts +7 -1
- package/src/utils/matcher.ts +16 -8
package/src/testing/test-data.ts
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
import type { RelationMapRoot } from "~/types/inputs";
|
|
2
|
-
import type { Simplify } from "~/types/utils";
|
|
3
|
-
|
|
4
|
-
export const testData = [
|
|
5
|
-
{
|
|
6
|
-
users: {
|
|
7
|
-
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
8
|
-
clerkId: "user_abc123",
|
|
9
|
-
email: "alice@example.com",
|
|
10
|
-
createdAt: "2025-01-12T09:41:22.000Z",
|
|
11
|
-
},
|
|
12
|
-
teamToUser: {
|
|
13
|
-
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
14
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
15
|
-
role: "admin",
|
|
16
|
-
},
|
|
17
|
-
teams: {
|
|
18
|
-
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
19
|
-
name: "Red Dragons",
|
|
20
|
-
},
|
|
21
|
-
posts: {
|
|
22
|
-
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
23
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
24
|
-
title: "First post",
|
|
25
|
-
published: true,
|
|
26
|
-
},
|
|
27
|
-
comments: {
|
|
28
|
-
id: "9d1a7c3b-2f6a-4f7c-bf4b-8f6e3c5d9e01",
|
|
29
|
-
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
30
|
-
body: "Nice post!",
|
|
31
|
-
authorEmail: "bob@example.com",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
users: {
|
|
36
|
-
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
37
|
-
clerkId: "user_abc123",
|
|
38
|
-
email: "alice@example.com",
|
|
39
|
-
createdAt: "2025-01-12T09:41:22.000Z",
|
|
40
|
-
},
|
|
41
|
-
teamToUser: {
|
|
42
|
-
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
43
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
44
|
-
role: "admin",
|
|
45
|
-
},
|
|
46
|
-
teams: {
|
|
47
|
-
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
48
|
-
name: "Red Dragons",
|
|
49
|
-
},
|
|
50
|
-
posts: {
|
|
51
|
-
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
52
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
53
|
-
title: "First post",
|
|
54
|
-
published: true,
|
|
55
|
-
},
|
|
56
|
-
comments: {
|
|
57
|
-
id: "e3c9b5a2-7f42-4b7e-9e3d-4a6f1d8b2c44",
|
|
58
|
-
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
59
|
-
body: "Thanks for sharing",
|
|
60
|
-
authorEmail: "charlie@example.com",
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
users: {
|
|
65
|
-
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
66
|
-
clerkId: "user_abc123",
|
|
67
|
-
email: "alice@example.com",
|
|
68
|
-
createdAt: "2025-01-12T09:41:22.000Z",
|
|
69
|
-
},
|
|
70
|
-
teamToUser: {
|
|
71
|
-
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
72
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
73
|
-
role: "admin",
|
|
74
|
-
},
|
|
75
|
-
teams: {
|
|
76
|
-
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
77
|
-
name: "Red Dragons",
|
|
78
|
-
},
|
|
79
|
-
posts: {
|
|
80
|
-
id: "6bcb2b74-9b2f-4b38-bdb5-77c2e63d9c10",
|
|
81
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
82
|
-
title: "Second post",
|
|
83
|
-
published: false,
|
|
84
|
-
},
|
|
85
|
-
comments: null,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
users: {
|
|
89
|
-
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
90
|
-
clerkId: "user_abc123",
|
|
91
|
-
email: "alice@example.com",
|
|
92
|
-
createdAt: "2025-01-12T09:41:22.000Z",
|
|
93
|
-
},
|
|
94
|
-
teamToUser: {
|
|
95
|
-
teamId: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
96
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
97
|
-
role: "member",
|
|
98
|
-
},
|
|
99
|
-
teams: {
|
|
100
|
-
id: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
101
|
-
name: "Blue Sharks",
|
|
102
|
-
},
|
|
103
|
-
posts: {
|
|
104
|
-
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
105
|
-
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
106
|
-
title: "First post",
|
|
107
|
-
published: true,
|
|
108
|
-
},
|
|
109
|
-
comments: {
|
|
110
|
-
id: "9d1a7c3b-2f6a-4f7c-bf4b-8f6e3c5d9e01",
|
|
111
|
-
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
112
|
-
body: "Nice post!",
|
|
113
|
-
authorEmail: "bob@example.com",
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
users: {
|
|
118
|
-
id: "f44a8c17-3c6d-4e38-9f61-0a9f2b1c8d55",
|
|
119
|
-
clerkId: "user_xyz789",
|
|
120
|
-
email: "dave@example.com",
|
|
121
|
-
createdAt: "2025-02-03T14:18:10.000Z",
|
|
122
|
-
},
|
|
123
|
-
teamToUser: {
|
|
124
|
-
teamId: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
125
|
-
userId: "f44a8c17-3c6d-4e38-9f61-0a9f2b1c8d55",
|
|
126
|
-
role: "admin",
|
|
127
|
-
},
|
|
128
|
-
teams: {
|
|
129
|
-
id: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
130
|
-
name: "Blue Sharks",
|
|
131
|
-
},
|
|
132
|
-
posts: null,
|
|
133
|
-
comments: null,
|
|
134
|
-
},
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
export const testSchema = {
|
|
138
|
-
base: "users",
|
|
139
|
-
id: "id",
|
|
140
|
-
|
|
141
|
-
_teamToUsers: {
|
|
142
|
-
base: "teamToUser",
|
|
143
|
-
id: "teamId",
|
|
144
|
-
joinsFrom: "id",
|
|
145
|
-
joinsTo: "userId",
|
|
146
|
-
joinType: "array",
|
|
147
|
-
|
|
148
|
-
_team: {
|
|
149
|
-
base: "teams",
|
|
150
|
-
id: "id",
|
|
151
|
-
joinsFrom: "teamId",
|
|
152
|
-
joinsTo: "id",
|
|
153
|
-
joinType: "single",
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
_posts: {
|
|
158
|
-
base: "posts",
|
|
159
|
-
id: "id",
|
|
160
|
-
joinsFrom: "id",
|
|
161
|
-
joinsTo: "userId",
|
|
162
|
-
joinType: "array",
|
|
163
|
-
|
|
164
|
-
_comments: {
|
|
165
|
-
base: "comments",
|
|
166
|
-
id: "id",
|
|
167
|
-
joinsFrom: "id",
|
|
168
|
-
joinsTo: "postId",
|
|
169
|
-
joinType: "array",
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
} satisfies RelationMapRoot<(typeof testData)[number]>;
|
|
1
|
+
import type { RelationMapRoot } from "~/types/inputs";
|
|
2
|
+
import type { Simplify } from "~/types/utils";
|
|
3
|
+
|
|
4
|
+
export const testData = [
|
|
5
|
+
{
|
|
6
|
+
users: {
|
|
7
|
+
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
8
|
+
clerkId: "user_abc123",
|
|
9
|
+
email: "alice@example.com",
|
|
10
|
+
createdAt: "2025-01-12T09:41:22.000Z",
|
|
11
|
+
},
|
|
12
|
+
teamToUser: {
|
|
13
|
+
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
14
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
15
|
+
role: "admin",
|
|
16
|
+
},
|
|
17
|
+
teams: {
|
|
18
|
+
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
19
|
+
name: "Red Dragons",
|
|
20
|
+
},
|
|
21
|
+
posts: {
|
|
22
|
+
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
23
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
24
|
+
title: "First post",
|
|
25
|
+
published: true,
|
|
26
|
+
},
|
|
27
|
+
comments: {
|
|
28
|
+
id: "9d1a7c3b-2f6a-4f7c-bf4b-8f6e3c5d9e01",
|
|
29
|
+
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
30
|
+
body: "Nice post!",
|
|
31
|
+
authorEmail: "bob@example.com",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
users: {
|
|
36
|
+
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
37
|
+
clerkId: "user_abc123",
|
|
38
|
+
email: "alice@example.com",
|
|
39
|
+
createdAt: "2025-01-12T09:41:22.000Z",
|
|
40
|
+
},
|
|
41
|
+
teamToUser: {
|
|
42
|
+
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
43
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
44
|
+
role: "admin",
|
|
45
|
+
},
|
|
46
|
+
teams: {
|
|
47
|
+
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
48
|
+
name: "Red Dragons",
|
|
49
|
+
},
|
|
50
|
+
posts: {
|
|
51
|
+
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
52
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
53
|
+
title: "First post",
|
|
54
|
+
published: true,
|
|
55
|
+
},
|
|
56
|
+
comments: {
|
|
57
|
+
id: "e3c9b5a2-7f42-4b7e-9e3d-4a6f1d8b2c44",
|
|
58
|
+
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
59
|
+
body: "Thanks for sharing",
|
|
60
|
+
authorEmail: "charlie@example.com",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
users: {
|
|
65
|
+
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
66
|
+
clerkId: "user_abc123",
|
|
67
|
+
email: "alice@example.com",
|
|
68
|
+
createdAt: "2025-01-12T09:41:22.000Z",
|
|
69
|
+
},
|
|
70
|
+
teamToUser: {
|
|
71
|
+
teamId: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
72
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
73
|
+
role: "admin",
|
|
74
|
+
},
|
|
75
|
+
teams: {
|
|
76
|
+
id: "a2e5a3de-6d14-4e9b-9c9f-3cbb2cdb8a10",
|
|
77
|
+
name: "Red Dragons",
|
|
78
|
+
},
|
|
79
|
+
posts: {
|
|
80
|
+
id: "6bcb2b74-9b2f-4b38-bdb5-77c2e63d9c10",
|
|
81
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
82
|
+
title: "Second post",
|
|
83
|
+
published: false,
|
|
84
|
+
},
|
|
85
|
+
comments: null,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
users: {
|
|
89
|
+
id: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
90
|
+
clerkId: "user_abc123",
|
|
91
|
+
email: "alice@example.com",
|
|
92
|
+
createdAt: "2025-01-12T09:41:22.000Z",
|
|
93
|
+
},
|
|
94
|
+
teamToUser: {
|
|
95
|
+
teamId: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
96
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
97
|
+
role: "member",
|
|
98
|
+
},
|
|
99
|
+
teams: {
|
|
100
|
+
id: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
101
|
+
name: "Blue Sharks",
|
|
102
|
+
},
|
|
103
|
+
posts: {
|
|
104
|
+
id: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
105
|
+
userId: "c7a2c1c8-9f4c-4f89-9d72-6b5a2f0c1e01",
|
|
106
|
+
title: "First post",
|
|
107
|
+
published: true,
|
|
108
|
+
},
|
|
109
|
+
comments: {
|
|
110
|
+
id: "9d1a7c3b-2f6a-4f7c-bf4b-8f6e3c5d9e01",
|
|
111
|
+
postId: "f13d8f22-0b61-4d6a-8b1e-5b6b3d0c8a21",
|
|
112
|
+
body: "Nice post!",
|
|
113
|
+
authorEmail: "bob@example.com",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
users: {
|
|
118
|
+
id: "f44a8c17-3c6d-4e38-9f61-0a9f2b1c8d55",
|
|
119
|
+
clerkId: "user_xyz789",
|
|
120
|
+
email: "dave@example.com",
|
|
121
|
+
createdAt: "2025-02-03T14:18:10.000Z",
|
|
122
|
+
},
|
|
123
|
+
teamToUser: {
|
|
124
|
+
teamId: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
125
|
+
userId: "f44a8c17-3c6d-4e38-9f61-0a9f2b1c8d55",
|
|
126
|
+
role: "admin",
|
|
127
|
+
},
|
|
128
|
+
teams: {
|
|
129
|
+
id: "d91f42a6-8cbb-4e63-9b5c-8d1b4f2a7e77",
|
|
130
|
+
name: "Blue Sharks",
|
|
131
|
+
},
|
|
132
|
+
posts: null,
|
|
133
|
+
comments: null,
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
export const testSchema = {
|
|
138
|
+
base: "users",
|
|
139
|
+
id: "id",
|
|
140
|
+
|
|
141
|
+
_teamToUsers: {
|
|
142
|
+
base: "teamToUser",
|
|
143
|
+
id: "teamId",
|
|
144
|
+
joinsFrom: "id",
|
|
145
|
+
joinsTo: "userId",
|
|
146
|
+
joinType: "array",
|
|
147
|
+
|
|
148
|
+
_team: {
|
|
149
|
+
base: "teams",
|
|
150
|
+
id: "id",
|
|
151
|
+
joinsFrom: "teamId",
|
|
152
|
+
joinsTo: "id",
|
|
153
|
+
joinType: "single",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
_posts: {
|
|
158
|
+
base: "posts",
|
|
159
|
+
id: "id",
|
|
160
|
+
joinsFrom: "id",
|
|
161
|
+
joinsTo: "userId",
|
|
162
|
+
joinType: "array",
|
|
163
|
+
|
|
164
|
+
_comments: {
|
|
165
|
+
base: "comments",
|
|
166
|
+
id: "id",
|
|
167
|
+
joinsFrom: "id",
|
|
168
|
+
joinsTo: "postId",
|
|
169
|
+
joinType: "array",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
} satisfies RelationMapRoot<(typeof testData)[number]>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { RelationMapBase, RelationMapJoiner } from "./inputs";
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { RelationMapBase, RelationMapJoiner } from "./inputs";
|
|
2
|
+
|
|
3
|
+
export type TInputBaseJoin = Record<string, unknown>;
|
|
4
|
+
export type TInputBase = Record<string, TInputBaseJoin | null>;
|
|
5
|
+
export type TJoinedFromBase = TInputBase[keyof TInputBase];
|
|
6
|
+
export type TOutputBase<
|
|
7
|
+
TInput extends TInputBase,
|
|
8
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
9
|
+
> = RelationMapBase<TInput, TJoinedFrom> &
|
|
10
|
+
RelationMapJoiner<TInput, TJoinedFrom>;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import type { TInputBase } from "./generic-bases";
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
1
|
+
import type { TInputBase } from "./generic-bases";
|
|
2
|
+
|
|
3
|
+
export type OutputBase<
|
|
4
|
+
TJoinType extends "single" | "array" = "single" | "array",
|
|
5
|
+
> = {
|
|
6
|
+
base: string;
|
|
7
|
+
id: string;
|
|
8
|
+
joinsTo: string;
|
|
9
|
+
joinsFrom: string;
|
|
10
|
+
joinType: TJoinType;
|
|
11
|
+
isNullable?: false;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type OutputRoot = OutputJoins & { base: string; id: string };
|
|
15
|
+
export type Output<TJoinType extends "single" | "array" = "single" | "array"> =
|
|
16
|
+
OutputJoins & OutputBase<TJoinType>;
|
|
17
|
+
|
|
18
|
+
export type OutputJoins = {
|
|
19
|
+
[k: `_${string}`]: Output;
|
|
20
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type * from "./generic-bases";
|
|
2
|
-
export type * from "./generic-less";
|
|
3
|
-
export type * from "./return";
|
|
4
|
-
export type * from "./typetest";
|
|
5
|
-
export type * from "./utils";
|
|
1
|
+
export type * from "./generic-bases";
|
|
2
|
+
export type * from "./generic-less";
|
|
3
|
+
export type * from "./return";
|
|
4
|
+
export type * from "./typetest";
|
|
5
|
+
export type * from "./utils";
|
package/src/types/inputs.ts
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import type { TInputBase, TJoinedFromBase } from "./generic-bases";
|
|
2
|
-
|
|
3
|
-
export type RelationMapRoot<TInput extends TInputBase> = {
|
|
4
|
-
[k in keyof TInput]: {
|
|
5
|
-
base: k;
|
|
6
|
-
id: keyof NonNullable<TInput[k]>;
|
|
7
|
-
} & RelationMapJoiner<TInput, NonNullable<TInput[k]>>;
|
|
8
|
-
}[keyof TInput];
|
|
9
|
-
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import type { TInputBase, TJoinedFromBase } from "./generic-bases";
|
|
2
|
+
|
|
3
|
+
export type RelationMapRoot<TInput extends TInputBase> = {
|
|
4
|
+
[k in keyof TInput]: {
|
|
5
|
+
base: k;
|
|
6
|
+
id: keyof NonNullable<TInput[k]>;
|
|
7
|
+
} & RelationMapJoiner<TInput, NonNullable<TInput[k]>>;
|
|
8
|
+
}[keyof TInput];
|
|
9
|
+
|
|
10
|
+
export type IsNullable = { false: false; undefined: undefined };
|
|
11
|
+
|
|
12
|
+
export type RelationMapBase<
|
|
13
|
+
TInput extends TInputBase,
|
|
14
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
15
|
+
> = {
|
|
16
|
+
[k in keyof TInput]: {
|
|
17
|
+
[n in keyof IsNullable]: {
|
|
18
|
+
base: k;
|
|
19
|
+
/** 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. */
|
|
20
|
+
id: keyof NonNullable<TInput[k]>;
|
|
21
|
+
joinsTo: keyof NonNullable<TInput[k]>;
|
|
22
|
+
joinsFrom: keyof NonNullable<TJoinedFrom>;
|
|
23
|
+
joinType: "single" | "array";
|
|
24
|
+
isNullable?: IsNullable[n];
|
|
25
|
+
};
|
|
26
|
+
}[keyof IsNullable] &
|
|
27
|
+
RelationMapJoiner<TInput, TInput[k]>;
|
|
28
|
+
}[keyof TInput];
|
|
29
|
+
|
|
30
|
+
export type RelationMapJoiner<
|
|
31
|
+
TInput extends TInputBase,
|
|
32
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
33
|
+
> = {
|
|
34
|
+
[k: `_${string}`]: RelationMapBase<TInput, TJoinedFrom> &
|
|
35
|
+
RelationMapJoiner<TInput, TJoinedFrom>;
|
|
36
|
+
};
|
package/src/types/return.ts
CHANGED
|
@@ -1,67 +1,65 @@
|
|
|
1
|
-
import type { TInputBase, TJoinedFromBase, TOutputBase } from "./generic-bases";
|
|
2
|
-
import type { RelationMapRoot } from "./inputs";
|
|
3
|
-
import type { ExtendsNull, NoUnderscore, Simplify } from "./utils";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
TInput extends TInputBase,
|
|
7
|
-
TOutput extends RelationMapRoot<TInput>,
|
|
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
|
-
};
|
|
1
|
+
import type { TInputBase, TJoinedFromBase, TOutputBase } from "./generic-bases";
|
|
2
|
+
import type { RelationMapRoot } from "./inputs";
|
|
3
|
+
import type { ExtendsNull, NoUnderscore, Simplify } from "./utils";
|
|
4
|
+
|
|
5
|
+
type JoinedRoot<
|
|
6
|
+
TInput extends TInputBase,
|
|
7
|
+
TOutput extends RelationMapRoot<TInput>,
|
|
8
|
+
> = TInput[TOutput["base"]] &
|
|
9
|
+
RelationMapperReturnJoinRoot<TInput, TOutput, TOutput["base"]>;
|
|
10
|
+
|
|
11
|
+
export type RelationMapperReturnRoot<
|
|
12
|
+
TInput extends TInputBase,
|
|
13
|
+
TOutput extends RelationMapRoot<TInput>,
|
|
14
|
+
> = Simplify<
|
|
15
|
+
ExtendsNull<TInput[TOutput["base"]]> extends true
|
|
16
|
+
? JoinedRoot<TInput, TOutput> | null
|
|
17
|
+
: JoinedRoot<TInput, TOutput>
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export type RelationMapperReturnJoinRoot<
|
|
21
|
+
TInput extends TInputBase,
|
|
22
|
+
TOutput extends RelationMapRoot<TInput>,
|
|
23
|
+
TInputKey extends keyof TInput,
|
|
24
|
+
> = {
|
|
25
|
+
[outputKey in NoUnderscore<keyof TOutput>]: RelationMapperReturn<
|
|
26
|
+
TInput,
|
|
27
|
+
TInput[TInputKey],
|
|
28
|
+
TOutput[`_${outputKey}`]
|
|
29
|
+
>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type Joined<
|
|
33
|
+
TInput extends TInputBase,
|
|
34
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
35
|
+
TOutput extends TOutputBase<TInput, TJoinedFrom>,
|
|
36
|
+
> = Simplify<
|
|
37
|
+
TInput[TOutput["base"]] &
|
|
38
|
+
RelationMapperReturnJoin<TInput, TJoinedFrom, TOutput>
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
/** Fill current object with value specified in base */
|
|
42
|
+
export type RelationMapperReturn<
|
|
43
|
+
TInput extends TInputBase,
|
|
44
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
45
|
+
TOutput extends TOutputBase<TInput, TJoinedFrom>,
|
|
46
|
+
> = TOutput["joinType"] extends "array"
|
|
47
|
+
? Array<Joined<TInput, TJoinedFrom, TOutput>>
|
|
48
|
+
: ExtendsNull<TInput[TOutput["base"]]> extends true
|
|
49
|
+
? TOutput["isNullable"] extends false
|
|
50
|
+
? Joined<TInput, TJoinedFrom, TOutput>
|
|
51
|
+
: Joined<TInput, TJoinedFrom, TOutput> | null
|
|
52
|
+
: Joined<TInput, TJoinedFrom, TOutput>;
|
|
53
|
+
|
|
54
|
+
/** Takes underscored values (joins) and replaces their values with the actual output. */
|
|
55
|
+
export type RelationMapperReturnJoin<
|
|
56
|
+
TInput extends TInputBase,
|
|
57
|
+
TJoinedFrom extends TJoinedFromBase,
|
|
58
|
+
TOutput extends TOutputBase<TInput, TJoinedFrom>,
|
|
59
|
+
> = {
|
|
60
|
+
[k in NoUnderscore<keyof TOutput>]: RelationMapperReturn<
|
|
61
|
+
TInput,
|
|
62
|
+
TJoinedFrom,
|
|
63
|
+
TOutput[`_${k}`]
|
|
64
|
+
>;
|
|
65
|
+
};
|