appflare 0.2.24 → 0.2.26
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 +758 -758
- package/cli/commands/index.ts +238 -238
- package/cli/generate.ts +178 -178
- package/cli/index.ts +120 -120
- package/cli/load-config.ts +184 -184
- package/cli/schema-compiler.ts +1183 -1183
- 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 +748 -749
- 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 +180 -180
- package/cli/templates/core/client/types.ts +184 -184
- 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 +171 -171
- package/cli/templates/dashboard/builders/functions/render-page/result-panel.ts +85 -85
- package/cli/templates/dashboard/builders/functions/render-page/scripts.ts +554 -554
- package/cli/templates/dashboard/builders/navigation.ts +122 -122
- 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 +217 -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 +388 -388
- 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 +42 -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 +134 -112
- package/cli/templates/handlers/generators/context/storage-helpers.ts +59 -59
- package/cli/templates/handlers/generators/context/types.ts +18 -18
- 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 +13 -13
- package/cli/templates/handlers/generators/registration/modules/cron.ts +26 -26
- 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 +516 -516
- package/cli/templates/handlers/generators/registration/modules/scheduler.ts +56 -56
- package/cli/templates/handlers/generators/registration/modules/storage.ts +196 -194
- package/cli/templates/handlers/generators/registration/sections.ts +210 -210
- package/cli/templates/handlers/generators/types/context.ts +68 -66
- package/cli/templates/handlers/generators/types/core.ts +106 -106
- package/cli/templates/handlers/generators/types/operations.ts +135 -135
- package/cli/templates/handlers/generators/types/query-definitions/filter-and-where-types.ts +259 -259
- 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 +1031 -1031
- package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +246 -246
- 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 +121 -121
- package/cli/templates/handlers/generators/types/query-runtime/runtime-setup.ts +45 -45
- package/cli/templates/handlers/generators/types/query-runtime/runtime-write.ts +676 -676
- package/cli/templates/handlers/generators/types/query-runtime.ts +15 -15
- package/cli/templates/handlers/index.ts +43 -43
- package/cli/templates/handlers/operations.ts +116 -116
- package/cli/templates/handlers/registration.ts +91 -83
- package/cli/templates/handlers/types.ts +15 -15
- package/cli/templates/handlers/utils.ts +48 -48
- package/cli/types.ts +110 -110
- package/cli/utils/handler-discovery.ts +466 -466
- package/cli/utils/json-utils.ts +24 -24
- package/cli/utils/path-utils.ts +19 -19
- package/cli/utils/schema-discovery.ts +399 -399
- package/dist/cli/index.js +61 -28
- package/dist/cli/index.mjs +61 -28
- package/index.ts +18 -18
- package/package.json +58 -58
- package/react/index.ts +5 -5
- package/react/use-infinite-query.ts +252 -252
- package/react/use-mutation.ts +89 -89
- package/react/use-query.ts +207 -207
- package/schema.ts +415 -415
- package/test-better-auth-hash.ts +2 -2
- package/tsconfig.json +6 -6
- package/tsup.config.ts +82 -82
|
@@ -1,246 +1,246 @@
|
|
|
1
|
-
export function generateSchemaAndTableTypesSection(): string {
|
|
2
|
-
return `const mergedSchema = {
|
|
3
|
-
...authSchema,
|
|
4
|
-
...schema,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const createDb = (database: D1Database) =>
|
|
8
|
-
drizzle(database, { schema: mergedSchema });
|
|
9
|
-
|
|
10
|
-
export type AppflareDb = ReturnType<typeof createDb>;
|
|
11
|
-
|
|
12
|
-
type SchemaRelations = ExtractTablesWithRelations<typeof mergedSchema>;
|
|
13
|
-
type TableName = Extract<keyof SchemaRelations, string>;
|
|
14
|
-
type TableRelationConfig<TName extends TableName> =
|
|
15
|
-
TName extends keyof SchemaRelations ? SchemaRelations[TName] : never;
|
|
16
|
-
type TableFindManyArgs<TName extends TableName> = DBQueryConfig<
|
|
17
|
-
"many",
|
|
18
|
-
true,
|
|
19
|
-
SchemaRelations,
|
|
20
|
-
TableRelationConfig<TName>
|
|
21
|
-
>;
|
|
22
|
-
type NativeFindManyWith<TName extends TableName> =
|
|
23
|
-
NonNullable<TableFindManyArgs<TName>> extends { with?: infer TWith }
|
|
24
|
-
? TWith
|
|
25
|
-
: never;
|
|
26
|
-
type ResolveNativeFindManyWith<
|
|
27
|
-
TName extends TableName,
|
|
28
|
-
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
29
|
-
> = TArgs extends { with?: infer TWith }
|
|
30
|
-
? Extract<TWith, NativeFindManyWith<TName>> extends infer TResolved
|
|
31
|
-
? [TResolved] extends [never]
|
|
32
|
-
? TWith extends Record<string, unknown>
|
|
33
|
-
? NativeFindManyWith<TName>
|
|
34
|
-
: never
|
|
35
|
-
: TResolved
|
|
36
|
-
: never
|
|
37
|
-
: never;
|
|
38
|
-
type ResolveTableFindManySelection<
|
|
39
|
-
TName extends TableName,
|
|
40
|
-
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
41
|
-
> = TArgs extends undefined
|
|
42
|
-
? true
|
|
43
|
-
: Omit<TArgs, "where" | "with"> &
|
|
44
|
-
(ResolveNativeFindManyWith<TName, TArgs> extends never
|
|
45
|
-
? {}
|
|
46
|
-
: { with: ResolveNativeFindManyWith<TName, TArgs> });
|
|
47
|
-
type TableModel<TName extends TableName> = InferSelectModel<
|
|
48
|
-
(typeof mergedSchema)[TName]
|
|
49
|
-
>;
|
|
50
|
-
type ManyToManySchemaMap = typeof schema extends {
|
|
51
|
-
__appflareManyToMany: infer TMap extends Record<string, unknown>;
|
|
52
|
-
}
|
|
53
|
-
? TMap
|
|
54
|
-
: {};
|
|
55
|
-
type ManyToManySourceTableMap<TSourceTable extends TableName> =
|
|
56
|
-
TSourceTable extends keyof ManyToManySchemaMap
|
|
57
|
-
? ManyToManySchemaMap[TSourceTable] extends Record<string, unknown>
|
|
58
|
-
? ManyToManySchemaMap[TSourceTable]
|
|
59
|
-
: {}
|
|
60
|
-
: {};
|
|
61
|
-
type ManyToManyTargetTableName<
|
|
62
|
-
TSourceTable extends TableName,
|
|
63
|
-
TRelationName extends string,
|
|
64
|
-
> = TRelationName extends keyof ManyToManySourceTableMap<TSourceTable>
|
|
65
|
-
? ManyToManySourceTableMap<TSourceTable>[TRelationName] extends {
|
|
66
|
-
targetTable: infer TTarget extends string;
|
|
67
|
-
}
|
|
68
|
-
? Extract<TTarget, TableName>
|
|
69
|
-
: never
|
|
70
|
-
: never;
|
|
71
|
-
type RuntimeRelationsSchemaMap = typeof schema extends {
|
|
72
|
-
__appflareRelations: infer TMap extends Record<string, unknown>;
|
|
73
|
-
}
|
|
74
|
-
? TMap
|
|
75
|
-
: {};
|
|
76
|
-
type RuntimeRelationsSourceTableMap<TSourceTable extends TableName> =
|
|
77
|
-
TSourceTable extends keyof RuntimeRelationsSchemaMap
|
|
78
|
-
? RuntimeRelationsSchemaMap[TSourceTable] extends Record<string, unknown>
|
|
79
|
-
? RuntimeRelationsSchemaMap[TSourceTable]
|
|
80
|
-
: {}
|
|
81
|
-
: {};
|
|
82
|
-
type RuntimeRelationName<TSourceTable extends TableName> =
|
|
83
|
-
Extract<keyof RuntimeRelationsSourceTableMap<TSourceTable>, string>;
|
|
84
|
-
type RuntimeRelationConfig<
|
|
85
|
-
TSourceTable extends TableName,
|
|
86
|
-
TRelationName extends string,
|
|
87
|
-
> = TRelationName extends keyof RuntimeRelationsSourceTableMap<TSourceTable>
|
|
88
|
-
? RuntimeRelationsSourceTableMap<TSourceTable>[TRelationName]
|
|
89
|
-
: never;
|
|
90
|
-
type RuntimeRelationKind<
|
|
91
|
-
TSourceTable extends TableName,
|
|
92
|
-
TRelationName extends string,
|
|
93
|
-
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
94
|
-
kind: infer TKind extends string;
|
|
95
|
-
}
|
|
96
|
-
? TKind
|
|
97
|
-
: never;
|
|
98
|
-
type RuntimeRelationTargetTable<
|
|
99
|
-
TSourceTable extends TableName,
|
|
100
|
-
TRelationName extends string,
|
|
101
|
-
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
102
|
-
targetTable: infer TTarget extends string;
|
|
103
|
-
}
|
|
104
|
-
? Extract<TTarget, TableName>
|
|
105
|
-
: never;
|
|
106
|
-
type TableInsertScalarModel<TName extends TableName> = TableInsertModel<TName>;
|
|
107
|
-
type FindManyWithFromArgs<TArgs> = TArgs extends { with?: infer TWith }
|
|
108
|
-
? TWith
|
|
109
|
-
: undefined;
|
|
110
|
-
type ManyToManyRelationRows<
|
|
111
|
-
TTargetTable extends TableName,
|
|
112
|
-
TRelationArgs,
|
|
113
|
-
> = TRelationArgs extends true
|
|
114
|
-
? Array<TableModel<TTargetTable>>
|
|
115
|
-
: TRelationArgs extends Record<string, unknown>
|
|
116
|
-
? Awaited<
|
|
117
|
-
TableFindManyResult<
|
|
118
|
-
TTargetTable,
|
|
119
|
-
Extract<
|
|
120
|
-
Omit<TRelationArgs, "_count" | "_avg">,
|
|
121
|
-
QueryFindManyArgs<TTargetTable>
|
|
122
|
-
>
|
|
123
|
-
>
|
|
124
|
-
>
|
|
125
|
-
: Array<TableModel<TTargetTable>>;
|
|
126
|
-
type ReplaceManyToManyRelationsInRow<
|
|
127
|
-
TSourceTable extends TableName,
|
|
128
|
-
TRow,
|
|
129
|
-
TWith,
|
|
130
|
-
> = TRow extends Record<string, unknown>
|
|
131
|
-
? {
|
|
132
|
-
[K in keyof TRow]: K extends string
|
|
133
|
-
? TWith extends Record<string, unknown>
|
|
134
|
-
? K extends keyof TWith
|
|
135
|
-
? [ManyToManyTargetTableName<TSourceTable, K>] extends [never]
|
|
136
|
-
? TRow[K]
|
|
137
|
-
: ManyToManyRelationRows<
|
|
138
|
-
Extract<ManyToManyTargetTableName<TSourceTable, K>, TableName>,
|
|
139
|
-
TWith[K]
|
|
140
|
-
>
|
|
141
|
-
: TRow[K]
|
|
142
|
-
: TRow[K]
|
|
143
|
-
: TRow[K];
|
|
144
|
-
}
|
|
145
|
-
: TRow;
|
|
146
|
-
type ApplyManyToManyFindManyResult<
|
|
147
|
-
TSourceTable extends TableName,
|
|
148
|
-
TArgs extends QueryFindManyArgs<TSourceTable> | undefined,
|
|
149
|
-
TResult,
|
|
150
|
-
> = TResult extends Promise<infer TRows>
|
|
151
|
-
? TRows extends Array<infer TRow>
|
|
152
|
-
? Promise<
|
|
153
|
-
Array<
|
|
154
|
-
ReplaceManyToManyRelationsInRow<
|
|
155
|
-
TSourceTable,
|
|
156
|
-
TRow,
|
|
157
|
-
FindManyWithFromArgs<TArgs>
|
|
158
|
-
>
|
|
159
|
-
>
|
|
160
|
-
>
|
|
161
|
-
: TResult
|
|
162
|
-
: TResult;
|
|
163
|
-
type ApplyManyToManyFindFirstResult<
|
|
164
|
-
TSourceTable extends TableName,
|
|
165
|
-
TArgs extends QueryFindFirstArgs<TSourceTable> | undefined,
|
|
166
|
-
TResult,
|
|
167
|
-
> = TResult extends Promise<infer TRow>
|
|
168
|
-
? Promise<
|
|
169
|
-
TRow extends null
|
|
170
|
-
? null
|
|
171
|
-
: ReplaceManyToManyRelationsInRow<
|
|
172
|
-
TSourceTable,
|
|
173
|
-
TRow,
|
|
174
|
-
FindManyWithFromArgs<TArgs>
|
|
175
|
-
>
|
|
176
|
-
>
|
|
177
|
-
: TResult;
|
|
178
|
-
type TableFindManyResult<
|
|
179
|
-
TName extends TableName,
|
|
180
|
-
TArgs extends QueryFindManyArgs<TName> | undefined =
|
|
181
|
-
| QueryFindManyArgs<TName>
|
|
182
|
-
| undefined,
|
|
183
|
-
> = ApplyManyToManyFindManyResult<
|
|
184
|
-
TName,
|
|
185
|
-
TArgs,
|
|
186
|
-
TArgs extends undefined
|
|
187
|
-
? Promise<Array<TableModel<TName>>>
|
|
188
|
-
: Promise<
|
|
189
|
-
Array<
|
|
190
|
-
BuildQueryResult<
|
|
191
|
-
SchemaRelations,
|
|
192
|
-
TableRelationConfig<TName>,
|
|
193
|
-
ResolveTableFindManySelection<TName, TArgs>
|
|
194
|
-
>
|
|
195
|
-
>
|
|
196
|
-
>
|
|
197
|
-
>;
|
|
198
|
-
type TableFindFirstArgs<TName extends TableName> = Omit<
|
|
199
|
-
TableFindManyArgs<TName>,
|
|
200
|
-
"limit"
|
|
201
|
-
>;
|
|
202
|
-
type NativeFindFirstWith<TName extends TableName> = NativeFindManyWith<TName>;
|
|
203
|
-
type ResolveNativeFindFirstWith<
|
|
204
|
-
TName extends TableName,
|
|
205
|
-
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
206
|
-
> = TArgs extends { with?: infer TWith }
|
|
207
|
-
? Extract<TWith, NativeFindFirstWith<TName>> extends infer TResolved
|
|
208
|
-
? [TResolved] extends [never]
|
|
209
|
-
? TWith extends Record<string, unknown>
|
|
210
|
-
? NativeFindFirstWith<TName>
|
|
211
|
-
: never
|
|
212
|
-
: TResolved
|
|
213
|
-
: never
|
|
214
|
-
: never;
|
|
215
|
-
type ResolveTableFindFirstSelection<
|
|
216
|
-
TName extends TableName,
|
|
217
|
-
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
218
|
-
> = TArgs extends undefined
|
|
219
|
-
? true
|
|
220
|
-
: Omit<TArgs, "where" | "with"> &
|
|
221
|
-
(ResolveNativeFindFirstWith<TName, TArgs> extends never
|
|
222
|
-
? {}
|
|
223
|
-
: { with: ResolveNativeFindFirstWith<TName, TArgs> });
|
|
224
|
-
type TableFindFirstResult<
|
|
225
|
-
TName extends TableName,
|
|
226
|
-
TArgs extends QueryFindFirstArgs<TName> | undefined =
|
|
227
|
-
| QueryFindFirstArgs<TName>
|
|
228
|
-
| undefined,
|
|
229
|
-
> = ApplyManyToManyFindFirstResult<
|
|
230
|
-
TName,
|
|
231
|
-
TArgs,
|
|
232
|
-
TArgs extends undefined
|
|
233
|
-
? Promise<TableModel<TName> | null>
|
|
234
|
-
: Promise<
|
|
235
|
-
BuildQueryResult<
|
|
236
|
-
SchemaRelations,
|
|
237
|
-
TableRelationConfig<TName>,
|
|
238
|
-
ResolveTableFindFirstSelection<TName, TArgs>
|
|
239
|
-
> | null
|
|
240
|
-
>
|
|
241
|
-
>;
|
|
242
|
-
type TableInsertModel<TName extends TableName> = InferInsertModel<
|
|
243
|
-
(typeof mergedSchema)[TName]
|
|
244
|
-
>;
|
|
245
|
-
`;
|
|
246
|
-
}
|
|
1
|
+
export function generateSchemaAndTableTypesSection(): string {
|
|
2
|
+
return `const mergedSchema = {
|
|
3
|
+
...authSchema,
|
|
4
|
+
...schema,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const createDb = (database: D1Database) =>
|
|
8
|
+
drizzle(database, { schema: mergedSchema });
|
|
9
|
+
|
|
10
|
+
export type AppflareDb = ReturnType<typeof createDb>;
|
|
11
|
+
|
|
12
|
+
type SchemaRelations = ExtractTablesWithRelations<typeof mergedSchema>;
|
|
13
|
+
type TableName = Extract<keyof SchemaRelations, string>;
|
|
14
|
+
type TableRelationConfig<TName extends TableName> =
|
|
15
|
+
TName extends keyof SchemaRelations ? SchemaRelations[TName] : never;
|
|
16
|
+
type TableFindManyArgs<TName extends TableName> = DBQueryConfig<
|
|
17
|
+
"many",
|
|
18
|
+
true,
|
|
19
|
+
SchemaRelations,
|
|
20
|
+
TableRelationConfig<TName>
|
|
21
|
+
>;
|
|
22
|
+
type NativeFindManyWith<TName extends TableName> =
|
|
23
|
+
NonNullable<TableFindManyArgs<TName>> extends { with?: infer TWith }
|
|
24
|
+
? TWith
|
|
25
|
+
: never;
|
|
26
|
+
type ResolveNativeFindManyWith<
|
|
27
|
+
TName extends TableName,
|
|
28
|
+
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
29
|
+
> = TArgs extends { with?: infer TWith }
|
|
30
|
+
? Extract<TWith, NativeFindManyWith<TName>> extends infer TResolved
|
|
31
|
+
? [TResolved] extends [never]
|
|
32
|
+
? TWith extends Record<string, unknown>
|
|
33
|
+
? NativeFindManyWith<TName>
|
|
34
|
+
: never
|
|
35
|
+
: TResolved
|
|
36
|
+
: never
|
|
37
|
+
: never;
|
|
38
|
+
type ResolveTableFindManySelection<
|
|
39
|
+
TName extends TableName,
|
|
40
|
+
TArgs extends QueryFindManyArgs<TName> | undefined,
|
|
41
|
+
> = TArgs extends undefined
|
|
42
|
+
? true
|
|
43
|
+
: Omit<TArgs, "where" | "with"> &
|
|
44
|
+
(ResolveNativeFindManyWith<TName, TArgs> extends never
|
|
45
|
+
? {}
|
|
46
|
+
: { with: ResolveNativeFindManyWith<TName, TArgs> });
|
|
47
|
+
type TableModel<TName extends TableName> = InferSelectModel<
|
|
48
|
+
(typeof mergedSchema)[TName]
|
|
49
|
+
>;
|
|
50
|
+
type ManyToManySchemaMap = typeof schema extends {
|
|
51
|
+
__appflareManyToMany: infer TMap extends Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
? TMap
|
|
54
|
+
: {};
|
|
55
|
+
type ManyToManySourceTableMap<TSourceTable extends TableName> =
|
|
56
|
+
TSourceTable extends keyof ManyToManySchemaMap
|
|
57
|
+
? ManyToManySchemaMap[TSourceTable] extends Record<string, unknown>
|
|
58
|
+
? ManyToManySchemaMap[TSourceTable]
|
|
59
|
+
: {}
|
|
60
|
+
: {};
|
|
61
|
+
type ManyToManyTargetTableName<
|
|
62
|
+
TSourceTable extends TableName,
|
|
63
|
+
TRelationName extends string,
|
|
64
|
+
> = TRelationName extends keyof ManyToManySourceTableMap<TSourceTable>
|
|
65
|
+
? ManyToManySourceTableMap<TSourceTable>[TRelationName] extends {
|
|
66
|
+
targetTable: infer TTarget extends string;
|
|
67
|
+
}
|
|
68
|
+
? Extract<TTarget, TableName>
|
|
69
|
+
: never
|
|
70
|
+
: never;
|
|
71
|
+
type RuntimeRelationsSchemaMap = typeof schema extends {
|
|
72
|
+
__appflareRelations: infer TMap extends Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
? TMap
|
|
75
|
+
: {};
|
|
76
|
+
type RuntimeRelationsSourceTableMap<TSourceTable extends TableName> =
|
|
77
|
+
TSourceTable extends keyof RuntimeRelationsSchemaMap
|
|
78
|
+
? RuntimeRelationsSchemaMap[TSourceTable] extends Record<string, unknown>
|
|
79
|
+
? RuntimeRelationsSchemaMap[TSourceTable]
|
|
80
|
+
: {}
|
|
81
|
+
: {};
|
|
82
|
+
type RuntimeRelationName<TSourceTable extends TableName> =
|
|
83
|
+
Extract<keyof RuntimeRelationsSourceTableMap<TSourceTable>, string>;
|
|
84
|
+
type RuntimeRelationConfig<
|
|
85
|
+
TSourceTable extends TableName,
|
|
86
|
+
TRelationName extends string,
|
|
87
|
+
> = TRelationName extends keyof RuntimeRelationsSourceTableMap<TSourceTable>
|
|
88
|
+
? RuntimeRelationsSourceTableMap<TSourceTable>[TRelationName]
|
|
89
|
+
: never;
|
|
90
|
+
type RuntimeRelationKind<
|
|
91
|
+
TSourceTable extends TableName,
|
|
92
|
+
TRelationName extends string,
|
|
93
|
+
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
94
|
+
kind: infer TKind extends string;
|
|
95
|
+
}
|
|
96
|
+
? TKind
|
|
97
|
+
: never;
|
|
98
|
+
type RuntimeRelationTargetTable<
|
|
99
|
+
TSourceTable extends TableName,
|
|
100
|
+
TRelationName extends string,
|
|
101
|
+
> = RuntimeRelationConfig<TSourceTable, TRelationName> extends {
|
|
102
|
+
targetTable: infer TTarget extends string;
|
|
103
|
+
}
|
|
104
|
+
? Extract<TTarget, TableName>
|
|
105
|
+
: never;
|
|
106
|
+
type TableInsertScalarModel<TName extends TableName> = TableInsertModel<TName>;
|
|
107
|
+
type FindManyWithFromArgs<TArgs> = TArgs extends { with?: infer TWith }
|
|
108
|
+
? TWith
|
|
109
|
+
: undefined;
|
|
110
|
+
type ManyToManyRelationRows<
|
|
111
|
+
TTargetTable extends TableName,
|
|
112
|
+
TRelationArgs,
|
|
113
|
+
> = TRelationArgs extends true
|
|
114
|
+
? Array<TableModel<TTargetTable>>
|
|
115
|
+
: TRelationArgs extends Record<string, unknown>
|
|
116
|
+
? Awaited<
|
|
117
|
+
TableFindManyResult<
|
|
118
|
+
TTargetTable,
|
|
119
|
+
Extract<
|
|
120
|
+
Omit<TRelationArgs, "_count" | "_avg">,
|
|
121
|
+
QueryFindManyArgs<TTargetTable>
|
|
122
|
+
>
|
|
123
|
+
>
|
|
124
|
+
>
|
|
125
|
+
: Array<TableModel<TTargetTable>>;
|
|
126
|
+
type ReplaceManyToManyRelationsInRow<
|
|
127
|
+
TSourceTable extends TableName,
|
|
128
|
+
TRow,
|
|
129
|
+
TWith,
|
|
130
|
+
> = TRow extends Record<string, unknown>
|
|
131
|
+
? {
|
|
132
|
+
[K in keyof TRow]: K extends string
|
|
133
|
+
? TWith extends Record<string, unknown>
|
|
134
|
+
? K extends keyof TWith
|
|
135
|
+
? [ManyToManyTargetTableName<TSourceTable, K>] extends [never]
|
|
136
|
+
? TRow[K]
|
|
137
|
+
: ManyToManyRelationRows<
|
|
138
|
+
Extract<ManyToManyTargetTableName<TSourceTable, K>, TableName>,
|
|
139
|
+
TWith[K]
|
|
140
|
+
>
|
|
141
|
+
: TRow[K]
|
|
142
|
+
: TRow[K]
|
|
143
|
+
: TRow[K];
|
|
144
|
+
}
|
|
145
|
+
: TRow;
|
|
146
|
+
type ApplyManyToManyFindManyResult<
|
|
147
|
+
TSourceTable extends TableName,
|
|
148
|
+
TArgs extends QueryFindManyArgs<TSourceTable> | undefined,
|
|
149
|
+
TResult,
|
|
150
|
+
> = TResult extends Promise<infer TRows>
|
|
151
|
+
? TRows extends Array<infer TRow>
|
|
152
|
+
? Promise<
|
|
153
|
+
Array<
|
|
154
|
+
ReplaceManyToManyRelationsInRow<
|
|
155
|
+
TSourceTable,
|
|
156
|
+
TRow,
|
|
157
|
+
FindManyWithFromArgs<TArgs>
|
|
158
|
+
>
|
|
159
|
+
>
|
|
160
|
+
>
|
|
161
|
+
: TResult
|
|
162
|
+
: TResult;
|
|
163
|
+
type ApplyManyToManyFindFirstResult<
|
|
164
|
+
TSourceTable extends TableName,
|
|
165
|
+
TArgs extends QueryFindFirstArgs<TSourceTable> | undefined,
|
|
166
|
+
TResult,
|
|
167
|
+
> = TResult extends Promise<infer TRow>
|
|
168
|
+
? Promise<
|
|
169
|
+
TRow extends null
|
|
170
|
+
? null
|
|
171
|
+
: ReplaceManyToManyRelationsInRow<
|
|
172
|
+
TSourceTable,
|
|
173
|
+
TRow,
|
|
174
|
+
FindManyWithFromArgs<TArgs>
|
|
175
|
+
>
|
|
176
|
+
>
|
|
177
|
+
: TResult;
|
|
178
|
+
type TableFindManyResult<
|
|
179
|
+
TName extends TableName,
|
|
180
|
+
TArgs extends QueryFindManyArgs<TName> | undefined =
|
|
181
|
+
| QueryFindManyArgs<TName>
|
|
182
|
+
| undefined,
|
|
183
|
+
> = ApplyManyToManyFindManyResult<
|
|
184
|
+
TName,
|
|
185
|
+
TArgs,
|
|
186
|
+
TArgs extends undefined
|
|
187
|
+
? Promise<Array<TableModel<TName>>>
|
|
188
|
+
: Promise<
|
|
189
|
+
Array<
|
|
190
|
+
BuildQueryResult<
|
|
191
|
+
SchemaRelations,
|
|
192
|
+
TableRelationConfig<TName>,
|
|
193
|
+
ResolveTableFindManySelection<TName, TArgs>
|
|
194
|
+
>
|
|
195
|
+
>
|
|
196
|
+
>
|
|
197
|
+
>;
|
|
198
|
+
type TableFindFirstArgs<TName extends TableName> = Omit<
|
|
199
|
+
TableFindManyArgs<TName>,
|
|
200
|
+
"limit"
|
|
201
|
+
>;
|
|
202
|
+
type NativeFindFirstWith<TName extends TableName> = NativeFindManyWith<TName>;
|
|
203
|
+
type ResolveNativeFindFirstWith<
|
|
204
|
+
TName extends TableName,
|
|
205
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
206
|
+
> = TArgs extends { with?: infer TWith }
|
|
207
|
+
? Extract<TWith, NativeFindFirstWith<TName>> extends infer TResolved
|
|
208
|
+
? [TResolved] extends [never]
|
|
209
|
+
? TWith extends Record<string, unknown>
|
|
210
|
+
? NativeFindFirstWith<TName>
|
|
211
|
+
: never
|
|
212
|
+
: TResolved
|
|
213
|
+
: never
|
|
214
|
+
: never;
|
|
215
|
+
type ResolveTableFindFirstSelection<
|
|
216
|
+
TName extends TableName,
|
|
217
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined,
|
|
218
|
+
> = TArgs extends undefined
|
|
219
|
+
? true
|
|
220
|
+
: Omit<TArgs, "where" | "with"> &
|
|
221
|
+
(ResolveNativeFindFirstWith<TName, TArgs> extends never
|
|
222
|
+
? {}
|
|
223
|
+
: { with: ResolveNativeFindFirstWith<TName, TArgs> });
|
|
224
|
+
type TableFindFirstResult<
|
|
225
|
+
TName extends TableName,
|
|
226
|
+
TArgs extends QueryFindFirstArgs<TName> | undefined =
|
|
227
|
+
| QueryFindFirstArgs<TName>
|
|
228
|
+
| undefined,
|
|
229
|
+
> = ApplyManyToManyFindFirstResult<
|
|
230
|
+
TName,
|
|
231
|
+
TArgs,
|
|
232
|
+
TArgs extends undefined
|
|
233
|
+
? Promise<TableModel<TName> | null>
|
|
234
|
+
: Promise<
|
|
235
|
+
BuildQueryResult<
|
|
236
|
+
SchemaRelations,
|
|
237
|
+
TableRelationConfig<TName>,
|
|
238
|
+
ResolveTableFindFirstSelection<TName, TArgs>
|
|
239
|
+
> | null
|
|
240
|
+
>
|
|
241
|
+
>;
|
|
242
|
+
type TableInsertModel<TName extends TableName> = InferInsertModel<
|
|
243
|
+
(typeof mergedSchema)[TName]
|
|
244
|
+
>;
|
|
245
|
+
`;
|
|
246
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { generateFilterAndWhereTypesSection } from "./query-definitions/filter-and-where-types";
|
|
2
|
-
import { generateQueryApiTypesSection } from "./query-definitions/query-api-types";
|
|
3
|
-
import { generateQueryHelperFunctionsSection } from "./query-definitions/query-helper-functions";
|
|
4
|
-
import { generateSchemaAndTableTypesSection } from "./query-definitions/schema-and-table-types";
|
|
5
|
-
|
|
6
|
-
export function generateTypesQueryDefinitionsSection(): string {
|
|
7
|
-
return [
|
|
8
|
-
generateSchemaAndTableTypesSection(),
|
|
9
|
-
generateFilterAndWhereTypesSection(),
|
|
10
|
-
generateQueryApiTypesSection(),
|
|
11
|
-
generateQueryHelperFunctionsSection(),
|
|
12
|
-
].join("\n\n");
|
|
13
|
-
}
|
|
1
|
+
import { generateFilterAndWhereTypesSection } from "./query-definitions/filter-and-where-types";
|
|
2
|
+
import { generateQueryApiTypesSection } from "./query-definitions/query-api-types";
|
|
3
|
+
import { generateQueryHelperFunctionsSection } from "./query-definitions/query-helper-functions";
|
|
4
|
+
import { generateSchemaAndTableTypesSection } from "./query-definitions/schema-and-table-types";
|
|
5
|
+
|
|
6
|
+
export function generateTypesQueryDefinitionsSection(): string {
|
|
7
|
+
return [
|
|
8
|
+
generateSchemaAndTableTypesSection(),
|
|
9
|
+
generateFilterAndWhereTypesSection(),
|
|
10
|
+
generateQueryApiTypesSection(),
|
|
11
|
+
generateQueryHelperFunctionsSection(),
|
|
12
|
+
].join("\n\n");
|
|
13
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export function generateQueryRuntimeHandledErrorSection(): string {
|
|
2
|
-
return `export class AppflareHandledError extends Error {
|
|
3
|
-
public readonly status: number;
|
|
4
|
-
public readonly payload: unknown;
|
|
5
|
-
|
|
6
|
-
public constructor(status: number, payload: unknown) {
|
|
7
|
-
super(typeof payload === "object" ? "Handled error" : String(payload));
|
|
8
|
-
this.status = status;
|
|
9
|
-
this.payload = payload;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
`;
|
|
13
|
-
}
|
|
1
|
+
export function generateQueryRuntimeHandledErrorSection(): string {
|
|
2
|
+
return `export class AppflareHandledError extends Error {
|
|
3
|
+
public readonly status: number;
|
|
4
|
+
public readonly payload: unknown;
|
|
5
|
+
|
|
6
|
+
public constructor(status: number, payload: unknown) {
|
|
7
|
+
super(typeof payload === "object" ? "Handled error" : String(payload));
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.payload = payload;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
}
|