appflare 0.2.48 → 0.2.50
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/Documentation.md +898 -898
- package/cli/commands/index.ts +247 -247
- package/cli/generate.ts +360 -360
- package/cli/index.ts +120 -120
- package/cli/load-config.ts +184 -184
- package/cli/schema-compiler.ts +1373 -1366
- package/cli/templates/auth/README.md +156 -156
- package/cli/templates/auth/config.ts +61 -61
- package/cli/templates/auth/route-config.ts +1 -1
- package/cli/templates/auth/route-handler.ts +1 -1
- package/cli/templates/auth/route-request-utils.ts +5 -5
- package/cli/templates/auth/route.config.ts +18 -18
- package/cli/templates/auth/route.handler.ts +18 -18
- package/cli/templates/auth/route.request-utils.ts +55 -55
- package/cli/templates/auth/route.ts +14 -14
- package/cli/templates/core/README.md +266 -266
- package/cli/templates/core/app-creation.ts +19 -19
- package/cli/templates/core/client/appflare.ts +112 -112
- package/cli/templates/core/client/handlers/index.ts +763 -763
- package/cli/templates/core/client/handlers.ts +1 -1
- package/cli/templates/core/client/index.ts +7 -7
- package/cli/templates/core/client/storage.ts +195 -195
- package/cli/templates/core/client/types.ts +187 -187
- package/cli/templates/core/client-modules/appflare.ts +1 -1
- package/cli/templates/core/client-modules/handlers.ts +1 -1
- package/cli/templates/core/client-modules/index.ts +1 -1
- package/cli/templates/core/client-modules/storage.ts +1 -1
- package/cli/templates/core/client-modules/types.ts +1 -1
- package/cli/templates/core/client.artifacts.ts +39 -39
- package/cli/templates/core/client.ts +4 -4
- package/cli/templates/core/drizzle.ts +15 -15
- package/cli/templates/core/export.ts +14 -14
- package/cli/templates/core/handlers.route.ts +24 -24
- package/cli/templates/core/handlers.ts +1 -1
- package/cli/templates/core/imports.ts +9 -9
- package/cli/templates/core/server.ts +38 -38
- package/cli/templates/core/types.ts +6 -6
- package/cli/templates/core/wrangler.ts +109 -109
- package/cli/templates/dashboard/builders/functions/index.ts +17 -17
- package/cli/templates/dashboard/builders/functions/render-page/header.ts +20 -20
- package/cli/templates/dashboard/builders/functions/render-page/index.ts +33 -33
- package/cli/templates/dashboard/builders/functions/render-page/request-panel.ts +271 -271
- package/cli/templates/dashboard/builders/functions/render-page/result-panel.ts +85 -85
- package/cli/templates/dashboard/builders/functions/render-page/scripts.ts +703 -703
- package/cli/templates/dashboard/builders/functions/tree-builder.ts +47 -47
- package/cli/templates/dashboard/builders/navigation.ts +155 -155
- package/cli/templates/dashboard/builders/storage/index.ts +13 -13
- package/cli/templates/dashboard/builders/storage/routes/create-directory-route.ts +29 -29
- package/cli/templates/dashboard/builders/storage/routes/delete-route.ts +18 -18
- package/cli/templates/dashboard/builders/storage/routes/download-route.ts +23 -23
- package/cli/templates/dashboard/builders/storage/routes/index.ts +22 -22
- package/cli/templates/dashboard/builders/storage/routes/list-route.ts +25 -25
- package/cli/templates/dashboard/builders/storage/routes/preview-route.ts +21 -21
- package/cli/templates/dashboard/builders/storage/routes/upload-route.ts +21 -21
- package/cli/templates/dashboard/builders/storage/runtime/helpers.ts +72 -72
- package/cli/templates/dashboard/builders/storage/runtime/storage-page.ts +130 -130
- package/cli/templates/dashboard/builders/table-routes/common/drawer-panel.ts +27 -27
- package/cli/templates/dashboard/builders/table-routes/common/pagination.ts +30 -30
- package/cli/templates/dashboard/builders/table-routes/common/search-bar.ts +23 -23
- package/cli/templates/dashboard/builders/table-routes/fragments.ts +257 -217
- package/cli/templates/dashboard/builders/table-routes/helpers.ts +45 -45
- package/cli/templates/dashboard/builders/table-routes/index.ts +8 -8
- package/cli/templates/dashboard/builders/table-routes/table/actions-cell.ts +71 -71
- package/cli/templates/dashboard/builders/table-routes/table/get-route.ts +291 -291
- package/cli/templates/dashboard/builders/table-routes/table/index.ts +80 -80
- package/cli/templates/dashboard/builders/table-routes/table/post-routes.ts +163 -163
- package/cli/templates/dashboard/builders/table-routes/table-route.ts +7 -7
- package/cli/templates/dashboard/builders/table-routes/users/get-route.ts +69 -69
- package/cli/templates/dashboard/builders/table-routes/users/html/modals.ts +57 -57
- package/cli/templates/dashboard/builders/table-routes/users/html/page.ts +27 -27
- package/cli/templates/dashboard/builders/table-routes/users/html/table.ts +128 -128
- package/cli/templates/dashboard/builders/table-routes/users/index.ts +32 -32
- package/cli/templates/dashboard/builders/table-routes/users/post-routes.ts +150 -150
- package/cli/templates/dashboard/builders/table-routes/users/redirect.ts +14 -14
- package/cli/templates/dashboard/builders/table-routes/users-route.ts +10 -10
- package/cli/templates/dashboard/components/dashboard-home.ts +23 -23
- package/cli/templates/dashboard/components/layout.ts +420 -420
- package/cli/templates/dashboard/components/login-page.ts +65 -65
- package/cli/templates/dashboard/index.ts +61 -61
- package/cli/templates/dashboard/types.ts +9 -9
- package/cli/templates/handlers/README.md +353 -353
- package/cli/templates/handlers/auth.ts +37 -37
- package/cli/templates/handlers/execution.ts +44 -42
- package/cli/templates/handlers/generators/context/context-creation.ts +101 -101
- package/cli/templates/handlers/generators/context/error-helpers.ts +11 -11
- package/cli/templates/handlers/generators/context/scheduler.ts +24 -24
- package/cli/templates/handlers/generators/context/storage-api.ts +82 -82
- package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -59
- package/cli/templates/handlers/generators/context/types.ts +40 -40
- package/cli/templates/handlers/generators/context.ts +43 -43
- package/cli/templates/handlers/generators/execution.ts +15 -15
- package/cli/templates/handlers/generators/handlers.ts +14 -14
- package/cli/templates/handlers/generators/registration/modules/cron.ts +35 -35
- package/cli/templates/handlers/generators/registration/modules/realtime/auth.ts +75 -75
- package/cli/templates/handlers/generators/registration/modules/realtime/durable-object.ts +144 -144
- package/cli/templates/handlers/generators/registration/modules/realtime/index.ts +14 -14
- package/cli/templates/handlers/generators/registration/modules/realtime/publisher.ts +102 -102
- package/cli/templates/handlers/generators/registration/modules/realtime/routes.ts +164 -164
- package/cli/templates/handlers/generators/registration/modules/realtime/types.ts +30 -30
- package/cli/templates/handlers/generators/registration/modules/realtime/utils.ts +510 -510
- package/cli/templates/handlers/generators/registration/modules/scheduler.ts +65 -65
- package/cli/templates/handlers/generators/registration/modules/storage.ts +199 -199
- package/cli/templates/handlers/generators/registration/sections.ts +210 -210
- package/cli/templates/handlers/generators/types/context.ts +121 -121
- package/cli/templates/handlers/generators/types/core.ts +108 -108
- package/cli/templates/handlers/generators/types/operations.ts +135 -135
- package/cli/templates/handlers/generators/types/query-definitions/filter-and-where-types.ts +291 -291
- package/cli/templates/handlers/generators/types/query-definitions/query-api-types.ts +135 -135
- package/cli/templates/handlers/generators/types/query-definitions/query-helper-functions.ts +1382 -1382
- package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +401 -278
- package/cli/templates/handlers/generators/types/query-definitions.ts +13 -13
- package/cli/templates/handlers/generators/types/query-runtime/handled-error.ts +13 -13
- package/cli/templates/handlers/generators/types/query-runtime/runtime-aggregate-and-footer.ts +174 -174
- package/cli/templates/handlers/generators/types/query-runtime/runtime-read.ts +156 -156
- package/cli/templates/handlers/generators/types/query-runtime/runtime-setup.ts +45 -45
- package/cli/templates/handlers/generators/types/query-runtime/runtime-write.ts +958 -958
- package/cli/templates/handlers/generators/types/query-runtime.ts +15 -15
- package/cli/templates/handlers/index.ts +47 -47
- package/cli/templates/handlers/operations.ts +116 -116
- package/cli/templates/handlers/registration.ts +91 -91
- package/cli/templates/handlers/types.ts +17 -17
- package/cli/templates/handlers/utils.ts +48 -48
- package/cli/types.ts +110 -110
- package/cli/utils/handler-discovery.ts +501 -501
- package/cli/utils/json-utils.ts +24 -24
- package/cli/utils/path-utils.ts +19 -19
- package/cli/utils/schema-discovery.ts +402 -399
- package/dist/cli/index.js +369 -219
- package/dist/cli/index.mjs +369 -219
- package/index.ts +18 -18
- package/package.json +58 -58
- package/react/index.ts +5 -5
- package/react/use-infinite-query.ts +255 -255
- package/react/use-mutation.ts +89 -89
- package/react/use-query.ts +210 -210
- package/schema.ts +641 -641
- package/test-better-auth-hash.ts +2 -2
- package/tsconfig.json +6 -6
- package/tsup.config.ts +82 -82
|
@@ -1,278 +1,401 @@
|
|
|
1
|
-
export function generateSchemaAndTableTypesSection(): string {
|
|
2
|
-
return `const mergedSchema = {
|
|
3
|
-
...authSchema,
|
|
4
|
-
...schema,
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
type
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
type
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
> =
|
|
123
|
-
?
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
type
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
type
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
> =
|
|
239
|
-
?
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
1
|
+
export function generateSchemaAndTableTypesSection(): string {
|
|
2
|
+
return `const mergedSchema = {
|
|
3
|
+
...authSchema,
|
|
4
|
+
...schema,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const mergedDbSchema = {
|
|
8
|
+
...authSchema,
|
|
9
|
+
...schema.__appflareDbSchema,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createDb = (database: D1Database) =>
|
|
13
|
+
drizzle(database, { schema: mergedDbSchema });
|
|
14
|
+
|
|
15
|
+
export type AppflareDb = ReturnType<typeof createDb>;
|
|
16
|
+
|
|
17
|
+
type SchemaRelations = ExtractTablesWithRelations<typeof mergedDbSchema>;
|
|
18
|
+
type TableName = Extract<keyof SchemaRelations, string>;
|
|
19
|
+
type TableRelationConfig<TName extends TableName> =
|
|
20
|
+
TName extends keyof SchemaRelations ? SchemaRelations[TName] : never;
|
|
21
|
+
type TableFindManyArgs<TName extends TableName> = DBQueryConfig<
|
|
22
|
+
"many",
|
|
23
|
+
true,
|
|
24
|
+
SchemaRelations,
|
|
25
|
+
TableRelationConfig<TName>
|
|
26
|
+
>;
|
|
27
|
+
type NativeFindManyWith<TName extends TableName> =
|
|
28
|
+
NonNullable<TableFindManyArgs<TName>> extends { with?: infer TWith }
|
|
29
|
+
? TWith
|
|
30
|
+
: never;
|
|
31
|
+
type ResolveNativeFindManyWith<
|
|
32
|
+
TName extends TableName,
|
|
33
|
+
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
34
|
+
> = TArgs extends { with?: infer TWith }
|
|
35
|
+
? NormalizeNativeWithForTable<TName, TWith>
|
|
36
|
+
: never;
|
|
37
|
+
type ResolveTableFindManySelection<
|
|
38
|
+
TName extends TableName,
|
|
39
|
+
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
40
|
+
> = TArgs extends undefined
|
|
41
|
+
? true
|
|
42
|
+
: Omit<TArgs, "where" | "with"> &
|
|
43
|
+
(ResolveNativeFindManyWith<TName, TArgs> extends never
|
|
44
|
+
? {}
|
|
45
|
+
: { with: ResolveNativeFindManyWith<TName, TArgs> });
|
|
46
|
+
type TableModel<TName extends TableName> = InferSelectModel<
|
|
47
|
+
(typeof mergedDbSchema)[TName]
|
|
48
|
+
>;
|
|
49
|
+
type ManyToManySchemaMap = typeof schema extends {
|
|
50
|
+
__appflareManyToMany: infer TMap extends Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
? TMap
|
|
53
|
+
: {};
|
|
54
|
+
type ManyToManySourceTableMap<TSourceTable extends TableName> =
|
|
55
|
+
TSourceTable extends keyof ManyToManySchemaMap
|
|
56
|
+
? ManyToManySchemaMap[TSourceTable] extends Record<string, unknown>
|
|
57
|
+
? ManyToManySchemaMap[TSourceTable]
|
|
58
|
+
: {}
|
|
59
|
+
: {};
|
|
60
|
+
type ManyToManyTargetTableName<
|
|
61
|
+
TSourceTable extends TableName,
|
|
62
|
+
TRelationName extends string,
|
|
63
|
+
> = TRelationName extends keyof ManyToManySourceTableMap<TSourceTable>
|
|
64
|
+
? ManyToManySourceTableMap<TSourceTable>[TRelationName] extends {
|
|
65
|
+
targetTable: infer TTarget extends string;
|
|
66
|
+
}
|
|
67
|
+
? Extract<TTarget, TableName>
|
|
68
|
+
: never
|
|
69
|
+
: never;
|
|
70
|
+
type RuntimeRelationsSchemaMap = typeof schema extends {
|
|
71
|
+
__appflareRelations: infer TMap extends Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
? TMap
|
|
74
|
+
: {};
|
|
75
|
+
type RuntimeRelationsSourceTableMap<TSourceTable extends TableName> =
|
|
76
|
+
TSourceTable extends keyof RuntimeRelationsSchemaMap
|
|
77
|
+
? RuntimeRelationsSchemaMap[TSourceTable] extends Record<string, unknown>
|
|
78
|
+
? RuntimeRelationsSchemaMap[TSourceTable]
|
|
79
|
+
: {}
|
|
80
|
+
: {};
|
|
81
|
+
type RuntimeRelationName<TSourceTable extends TableName> =
|
|
82
|
+
Extract<keyof RuntimeRelationsSourceTableMap<TSourceTable>, string>;
|
|
83
|
+
type RuntimeRelationConfig<
|
|
84
|
+
TSourceTable extends TableName,
|
|
85
|
+
TRelationName extends string,
|
|
86
|
+
> = TRelationName extends keyof RuntimeRelationsSourceTableMap<TSourceTable>
|
|
87
|
+
? RuntimeRelationsSourceTableMap<TSourceTable>[TRelationName]
|
|
88
|
+
: never;
|
|
89
|
+
type RuntimeRelationKind<
|
|
90
|
+
TSourceTable extends TableName,
|
|
91
|
+
TRelationName extends string,
|
|
92
|
+
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
93
|
+
kind: infer TKind extends string;
|
|
94
|
+
}
|
|
95
|
+
? TKind
|
|
96
|
+
: never;
|
|
97
|
+
type RuntimeRelationTargetTable<
|
|
98
|
+
TSourceTable extends TableName,
|
|
99
|
+
TRelationName extends string,
|
|
100
|
+
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
101
|
+
targetTable: infer TTarget extends string;
|
|
102
|
+
}
|
|
103
|
+
? Extract<TTarget, TableName>
|
|
104
|
+
: never;
|
|
105
|
+
type NativeRelationEntry<
|
|
106
|
+
TSourceTable extends TableName,
|
|
107
|
+
TRelationName extends string,
|
|
108
|
+
> = TRelationName extends keyof NativeFindManyWith<TSourceTable>
|
|
109
|
+
? NativeFindManyWith<TSourceTable>[TRelationName]
|
|
110
|
+
: never;
|
|
111
|
+
type NativeRelationWhere<TEntry> = Extract<
|
|
112
|
+
TEntry,
|
|
113
|
+
Record<string, unknown>
|
|
114
|
+
> extends {
|
|
115
|
+
where?: infer TWhere;
|
|
116
|
+
}
|
|
117
|
+
? TWhere
|
|
118
|
+
: never;
|
|
119
|
+
type ManyToManyJunctionTableName<
|
|
120
|
+
TSourceTable extends TableName,
|
|
121
|
+
TRelationName extends string,
|
|
122
|
+
> = TRelationName extends keyof ManyToManySourceTableMap<TSourceTable>
|
|
123
|
+
? ManyToManySourceTableMap<TSourceTable>[TRelationName] extends {
|
|
124
|
+
junctionTable: infer TJunctionTable extends string;
|
|
125
|
+
}
|
|
126
|
+
? Extract<TJunctionTable, TableName>
|
|
127
|
+
: never
|
|
128
|
+
: never;
|
|
129
|
+
type CleanRelationConfig<TEntry> = Omit<
|
|
130
|
+
Extract<TEntry, Record<string, unknown>>,
|
|
131
|
+
"where" | "with" | "_count" | "_avg"
|
|
132
|
+
>;
|
|
133
|
+
type NormalizeNativeRelationConfig<
|
|
134
|
+
TSourceTable extends TableName,
|
|
135
|
+
TRelationName extends string,
|
|
136
|
+
TEntry,
|
|
137
|
+
> = CleanRelationConfig<TEntry> &
|
|
138
|
+
(Extract<TEntry, Record<string, unknown>> extends { where?: unknown }
|
|
139
|
+
? {
|
|
140
|
+
where?: NativeRelationWhere<
|
|
141
|
+
NativeRelationEntry<TSourceTable, TRelationName>
|
|
142
|
+
>;
|
|
143
|
+
}
|
|
144
|
+
: {}) &
|
|
145
|
+
(Extract<TEntry, Record<string, unknown>> extends { with?: infer TNestedWith }
|
|
146
|
+
? RuntimeRelationTargetTable<TSourceTable, TRelationName> extends infer TTargetTable
|
|
147
|
+
? TTargetTable extends TableName
|
|
148
|
+
? {
|
|
149
|
+
with?: NormalizeNativeWithForTable<TTargetTable, TNestedWith>;
|
|
150
|
+
}
|
|
151
|
+
: {}
|
|
152
|
+
: {}
|
|
153
|
+
: {});
|
|
154
|
+
type NormalizeManyToManyTargetConfig<
|
|
155
|
+
TSourceTable extends TableName,
|
|
156
|
+
TRelationName extends string,
|
|
157
|
+
TEntry,
|
|
158
|
+
> = ManyToManyTargetTableName<
|
|
159
|
+
TSourceTable,
|
|
160
|
+
TRelationName
|
|
161
|
+
> extends infer TTargetTable
|
|
162
|
+
? TTargetTable extends TableName
|
|
163
|
+
? CleanRelationConfig<TEntry> &
|
|
164
|
+
(Extract<TEntry, Record<string, unknown>> extends { where?: unknown }
|
|
165
|
+
? ManyToManyJunctionTableName<
|
|
166
|
+
TSourceTable,
|
|
167
|
+
TRelationName
|
|
168
|
+
> extends infer TJunctionTable
|
|
169
|
+
? TJunctionTable extends TableName
|
|
170
|
+
? {
|
|
171
|
+
where?: NativeRelationWhere<
|
|
172
|
+
NativeRelationEntry<TJunctionTable, TTargetTable>
|
|
173
|
+
>;
|
|
174
|
+
}
|
|
175
|
+
: {}
|
|
176
|
+
: {}
|
|
177
|
+
: {}) &
|
|
178
|
+
(Extract<TEntry, Record<string, unknown>> extends {
|
|
179
|
+
with?: infer TNestedWith;
|
|
180
|
+
}
|
|
181
|
+
? {
|
|
182
|
+
with?: NormalizeNativeWithForTable<TTargetTable, TNestedWith>;
|
|
183
|
+
}
|
|
184
|
+
: {})
|
|
185
|
+
: never
|
|
186
|
+
: never;
|
|
187
|
+
type NormalizeRelationInputForTable<
|
|
188
|
+
TSourceTable extends TableName,
|
|
189
|
+
TRelationName extends string,
|
|
190
|
+
TEntry,
|
|
191
|
+
> = [ManyToManyTargetTableName<TSourceTable, TRelationName>] extends [never]
|
|
192
|
+
? (Extract<TEntry, true> extends never ? never : true) |
|
|
193
|
+
(Extract<TEntry, Record<string, unknown>> extends infer TConfig
|
|
194
|
+
? TConfig extends Record<string, unknown>
|
|
195
|
+
? NormalizeNativeRelationConfig<
|
|
196
|
+
TSourceTable,
|
|
197
|
+
TRelationName,
|
|
198
|
+
TConfig
|
|
199
|
+
>
|
|
200
|
+
: never
|
|
201
|
+
: never)
|
|
202
|
+
: ManyToManyTargetTableName<
|
|
203
|
+
TSourceTable,
|
|
204
|
+
TRelationName
|
|
205
|
+
> extends infer TTargetTable
|
|
206
|
+
? TTargetTable extends TableName
|
|
207
|
+
? (Extract<TEntry, true> extends never
|
|
208
|
+
? never
|
|
209
|
+
: {
|
|
210
|
+
with: {
|
|
211
|
+
[K in TTargetTable]: true;
|
|
212
|
+
};
|
|
213
|
+
}) |
|
|
214
|
+
(Extract<TEntry, Record<string, unknown>> extends infer TConfig
|
|
215
|
+
? TConfig extends Record<string, unknown>
|
|
216
|
+
? CleanRelationConfig<TConfig> & {
|
|
217
|
+
with: {
|
|
218
|
+
[K in TTargetTable]: keyof NormalizeManyToManyTargetConfig<
|
|
219
|
+
TSourceTable,
|
|
220
|
+
TRelationName,
|
|
221
|
+
TConfig
|
|
222
|
+
> extends never
|
|
223
|
+
? true
|
|
224
|
+
: NormalizeManyToManyTargetConfig<
|
|
225
|
+
TSourceTable,
|
|
226
|
+
TRelationName,
|
|
227
|
+
TConfig
|
|
228
|
+
>;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
: never
|
|
232
|
+
: never)
|
|
233
|
+
: never
|
|
234
|
+
: never;
|
|
235
|
+
type NormalizeNativeWithForTable<
|
|
236
|
+
TSourceTable extends TableName,
|
|
237
|
+
TWith,
|
|
238
|
+
> = TWith extends Record<string, unknown>
|
|
239
|
+
? {
|
|
240
|
+
[K in keyof TWith]: NormalizeRelationInputForTable<
|
|
241
|
+
TSourceTable,
|
|
242
|
+
Extract<K, string>,
|
|
243
|
+
TWith[K]
|
|
244
|
+
>;
|
|
245
|
+
}
|
|
246
|
+
: TWith;
|
|
247
|
+
|
|
248
|
+
type TargetTableForRelation<
|
|
249
|
+
TSource extends TableName,
|
|
250
|
+
TRelation extends string,
|
|
251
|
+
> = RuntimeRelationTargetTable<TSource, TRelation> extends never
|
|
252
|
+
? ManyToManyTargetTableName<TSource, TRelation> extends never
|
|
253
|
+
? never
|
|
254
|
+
: Extract<ManyToManyTargetTableName<TSource, TRelation>, TableName>
|
|
255
|
+
: RuntimeRelationTargetTable<TSource, TRelation>;
|
|
256
|
+
|
|
257
|
+
type TableInsertScalarModel<TName extends TableName> = TableInsertModel<TName>;
|
|
258
|
+
type FindManyWithFromArgs<TArgs> = TArgs extends { with?: infer TWith }
|
|
259
|
+
? TWith
|
|
260
|
+
: undefined;
|
|
261
|
+
type ManyToManyRelationRows<
|
|
262
|
+
TTargetTable extends TableName,
|
|
263
|
+
TRelationArgs,
|
|
264
|
+
> = TRelationArgs extends true
|
|
265
|
+
? Array<TableModel<TTargetTable>>
|
|
266
|
+
: TRelationArgs extends Record<string, unknown>
|
|
267
|
+
? Awaited<
|
|
268
|
+
TableFindManyResult<
|
|
269
|
+
TTargetTable,
|
|
270
|
+
Extract<
|
|
271
|
+
Omit<TRelationArgs, "_count" | "_avg">,
|
|
272
|
+
QueryFindManyArgs<TTargetTable>
|
|
273
|
+
>
|
|
274
|
+
>
|
|
275
|
+
>
|
|
276
|
+
: Array<TableModel<TTargetTable>>;
|
|
277
|
+
type ReplaceManyToManyRelationsInRow<
|
|
278
|
+
TSourceTable extends string,
|
|
279
|
+
TRow,
|
|
280
|
+
TWith,
|
|
281
|
+
> = TRow extends Record<string, unknown>
|
|
282
|
+
? {
|
|
283
|
+
[K in keyof TRow]: K extends string
|
|
284
|
+
? TWith extends Record<string, unknown>
|
|
285
|
+
? K extends keyof TWith
|
|
286
|
+
? [ManyToManyTargetTableName<Extract<TSourceTable, TableName>, K>] extends [never]
|
|
287
|
+
? ReplaceManyToManyRelationsInRow<
|
|
288
|
+
[RuntimeRelationTargetTable<Extract<TSourceTable, TableName>, K>] extends [never]
|
|
289
|
+
? K
|
|
290
|
+
: RuntimeRelationTargetTable<Extract<TSourceTable, TableName>, K>,
|
|
291
|
+
TRow[K],
|
|
292
|
+
TWith[K] extends { with: infer TNestedWith }
|
|
293
|
+
? TNestedWith
|
|
294
|
+
: undefined
|
|
295
|
+
>
|
|
296
|
+
: ManyToManyRelationRows<
|
|
297
|
+
Extract<ManyToManyTargetTableName<Extract<TSourceTable, TableName>, K>, TableName>,
|
|
298
|
+
TWith[K]
|
|
299
|
+
>
|
|
300
|
+
: TRow[K]
|
|
301
|
+
: TRow[K]
|
|
302
|
+
: TRow[K];
|
|
303
|
+
}
|
|
304
|
+
: TRow extends Array<infer TEntry>
|
|
305
|
+
? Array<ReplaceManyToManyRelationsInRow<TSourceTable, TEntry, TWith>>
|
|
306
|
+
: TRow;
|
|
307
|
+
type ApplyManyToManyFindManyResult<
|
|
308
|
+
TSourceTable extends TableName,
|
|
309
|
+
TArgs extends QueryFindManyArgs<TSourceTable> | undefined,
|
|
310
|
+
TResult,
|
|
311
|
+
> = TResult extends Promise<infer TRows>
|
|
312
|
+
? TRows extends Array<infer TRow>
|
|
313
|
+
? Promise<
|
|
314
|
+
Array<
|
|
315
|
+
ReplaceManyToManyRelationsInRow<
|
|
316
|
+
TSourceTable,
|
|
317
|
+
TRow,
|
|
318
|
+
FindManyWithFromArgs<TArgs>
|
|
319
|
+
>
|
|
320
|
+
>
|
|
321
|
+
>
|
|
322
|
+
: TResult
|
|
323
|
+
: TResult;
|
|
324
|
+
type ApplyManyToManyFindFirstResult<
|
|
325
|
+
TSourceTable extends TableName,
|
|
326
|
+
TArgs extends QueryFindFirstArgs<TSourceTable> | undefined,
|
|
327
|
+
TResult,
|
|
328
|
+
> = TResult extends Promise<infer TRow>
|
|
329
|
+
? Promise<
|
|
330
|
+
TRow extends null
|
|
331
|
+
? null
|
|
332
|
+
: ReplaceManyToManyRelationsInRow<
|
|
333
|
+
TSourceTable,
|
|
334
|
+
TRow,
|
|
335
|
+
FindManyWithFromArgs<TArgs>
|
|
336
|
+
>
|
|
337
|
+
>
|
|
338
|
+
: TResult;
|
|
339
|
+
type TableFindManyResult<
|
|
340
|
+
TName extends TableName,
|
|
341
|
+
TArgs extends QueryFindManyArgs<TName> | undefined =
|
|
342
|
+
| QueryFindManyArgs<TName>
|
|
343
|
+
| undefined,
|
|
344
|
+
> = ApplyManyToManyFindManyResult<
|
|
345
|
+
TName,
|
|
346
|
+
TArgs,
|
|
347
|
+
TArgs extends undefined
|
|
348
|
+
? Promise<Array<TableModel<TName>>>
|
|
349
|
+
: Promise<
|
|
350
|
+
Array<
|
|
351
|
+
BuildQueryResult<
|
|
352
|
+
SchemaRelations,
|
|
353
|
+
TableRelationConfig<TName>,
|
|
354
|
+
ResolveTableFindManySelection<TName, TArgs>
|
|
355
|
+
>
|
|
356
|
+
>
|
|
357
|
+
>
|
|
358
|
+
>;
|
|
359
|
+
type TableFindFirstArgs<TName extends TableName> = Omit<
|
|
360
|
+
TableFindManyArgs<TName>,
|
|
361
|
+
"limit"
|
|
362
|
+
>;
|
|
363
|
+
type NativeFindFirstWith<TName extends TableName> = NativeFindManyWith<TName>;
|
|
364
|
+
type ResolveNativeFindFirstWith<
|
|
365
|
+
TName extends TableName,
|
|
366
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
367
|
+
> = TArgs extends { with?: infer TWith }
|
|
368
|
+
? NormalizeNativeWithForTable<TName, TWith>
|
|
369
|
+
: never;
|
|
370
|
+
type ResolveTableFindFirstSelection<
|
|
371
|
+
TName extends TableName,
|
|
372
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
373
|
+
> = TArgs extends undefined
|
|
374
|
+
? true
|
|
375
|
+
: Omit<TArgs, "where" | "with"> &
|
|
376
|
+
(ResolveNativeFindFirstWith<TName, TArgs> extends never
|
|
377
|
+
? {}
|
|
378
|
+
: { with: ResolveNativeFindFirstWith<TName, TArgs> });
|
|
379
|
+
type TableFindFirstResult<
|
|
380
|
+
TName extends TableName,
|
|
381
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined =
|
|
382
|
+
| QueryFindFirstArgs<TName>
|
|
383
|
+
| undefined,
|
|
384
|
+
> = ApplyManyToManyFindFirstResult<
|
|
385
|
+
TName,
|
|
386
|
+
TArgs,
|
|
387
|
+
TArgs extends undefined
|
|
388
|
+
? Promise<TableModel<TName> | null>
|
|
389
|
+
: Promise<
|
|
390
|
+
BuildQueryResult<
|
|
391
|
+
SchemaRelations,
|
|
392
|
+
TableRelationConfig<TName>,
|
|
393
|
+
ResolveTableFindFirstSelection<TName, TArgs>
|
|
394
|
+
> | null
|
|
395
|
+
>
|
|
396
|
+
>;
|
|
397
|
+
type TableInsertModel<TName extends TableName> = InferInsertModel<
|
|
398
|
+
(typeof mergedDbSchema)[TName]
|
|
399
|
+
>;
|
|
400
|
+
`;
|
|
401
|
+
}
|