appflare 0.2.50 → 0.2.52
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/cli/commands/index.ts +33 -25
- package/cli/generate.ts +13 -8
- package/cli/templates/handlers/generators/types/query-definitions/schema-and-table-types.ts +69 -9
- package/cli/utils/resolve-package.ts +59 -0
- package/dist/cli/index.js +253 -193
- package/dist/cli/index.mjs +253 -193
- package/package.json +68 -23
- package/tsconfig.json +3 -1
- package/tsup.config.ts +0 -2
package/cli/commands/index.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import chokidar from "chokidar";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { generateArtifacts } from "../generate";
|
|
5
5
|
import { loadConfig } from "../load-config";
|
|
6
|
+
import {
|
|
7
|
+
findNearestPackageDir,
|
|
8
|
+
packageSearchDirs,
|
|
9
|
+
resolvePackageBin,
|
|
10
|
+
} from "../utils/resolve-package";
|
|
6
11
|
|
|
7
12
|
type MigrateOptions = {
|
|
8
13
|
local?: boolean;
|
|
@@ -10,23 +15,6 @@ type MigrateOptions = {
|
|
|
10
15
|
preview?: boolean;
|
|
11
16
|
};
|
|
12
17
|
|
|
13
|
-
function findNearestPackageDir(startDir: string): string {
|
|
14
|
-
let currentDir = startDir;
|
|
15
|
-
|
|
16
|
-
while (true) {
|
|
17
|
-
if (existsSync(resolve(currentDir, "package.json"))) {
|
|
18
|
-
return currentDir;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const parentDir = dirname(currentDir);
|
|
22
|
-
if (parentDir === currentDir) {
|
|
23
|
-
return startDir;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
currentDir = parentDir;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
18
|
export async function runBuild(
|
|
31
19
|
configPath?: string,
|
|
32
20
|
options: { build?: boolean } = {},
|
|
@@ -123,9 +111,18 @@ export async function runMigrate(
|
|
|
123
111
|
loadedConfig.outDirAbs,
|
|
124
112
|
"drizzle.config.js",
|
|
125
113
|
);
|
|
126
|
-
const
|
|
114
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
115
|
+
const searchDirs = packageSearchDirs(moduleDir, [
|
|
116
|
+
loadedConfig.configDir,
|
|
117
|
+
packageDir,
|
|
118
|
+
]);
|
|
119
|
+
const drizzleKitBin = resolvePackageBin(
|
|
120
|
+
"drizzle-kit",
|
|
121
|
+
"bin.cjs",
|
|
122
|
+
searchDirs,
|
|
123
|
+
);
|
|
127
124
|
const drizzleGenerate = Bun.spawn(
|
|
128
|
-
[
|
|
125
|
+
[process.execPath, drizzleKitBin, "generate", "--config", drizzleConfigPath],
|
|
129
126
|
{
|
|
130
127
|
cwd: packageDir,
|
|
131
128
|
stdin: "inherit",
|
|
@@ -142,9 +139,14 @@ export async function runMigrate(
|
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
const databaseName = loadedConfig.config.database[0].databaseName;
|
|
145
|
-
const
|
|
146
|
-
npxCmd,
|
|
142
|
+
const wranglerBin = resolvePackageBin(
|
|
147
143
|
"wrangler",
|
|
144
|
+
"bin/wrangler.js",
|
|
145
|
+
searchDirs,
|
|
146
|
+
);
|
|
147
|
+
const wranglerArgs = [
|
|
148
|
+
process.execPath,
|
|
149
|
+
wranglerBin,
|
|
148
150
|
"d1",
|
|
149
151
|
"migrations",
|
|
150
152
|
"apply",
|
|
@@ -213,10 +215,16 @@ export async function runAddAdmin(
|
|
|
213
215
|
].join(" ");
|
|
214
216
|
|
|
215
217
|
const databaseName = loadedConfig.config.database[0].databaseName;
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
|
|
218
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
219
|
+
const searchDirs = packageSearchDirs(moduleDir, [loadedConfig.configDir]);
|
|
220
|
+
const wranglerBin = resolvePackageBin(
|
|
219
221
|
"wrangler",
|
|
222
|
+
"bin/wrangler.js",
|
|
223
|
+
searchDirs,
|
|
224
|
+
);
|
|
225
|
+
const wranglerArgs = [
|
|
226
|
+
process.execPath,
|
|
227
|
+
wranglerBin,
|
|
220
228
|
"d1",
|
|
221
229
|
"execute",
|
|
222
230
|
databaseName,
|
package/cli/generate.ts
CHANGED
|
@@ -14,6 +14,10 @@ import type { LoadedAppflareConfig } from "./types";
|
|
|
14
14
|
import { discoverHandlerOperations } from "./utils/handler-discovery";
|
|
15
15
|
import { discoverSchema } from "./utils/schema-discovery";
|
|
16
16
|
import { ensureRelativeImportPath } from "./utils/path-utils";
|
|
17
|
+
import {
|
|
18
|
+
packageSearchDirs,
|
|
19
|
+
resolvePackageBin,
|
|
20
|
+
} from "./utils/resolve-package";
|
|
17
21
|
|
|
18
22
|
function extractRolesFromConfig(config: LoadedAppflareConfig["config"]): string[] {
|
|
19
23
|
const plugins = (config.auth.options as Record<string, unknown>).plugins;
|
|
@@ -103,15 +107,16 @@ export async function generateArtifacts(
|
|
|
103
107
|
process.stdout.write(`📁 Directories (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
104
108
|
|
|
105
109
|
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
"
|
|
109
|
-
"tsc",
|
|
110
|
+
const searchDirs = packageSearchDirs(moduleDir, [configDir]);
|
|
111
|
+
const tscBin = resolvePackageBin(
|
|
112
|
+
"typescript",
|
|
113
|
+
"bin/tsc",
|
|
114
|
+
searchDirs,
|
|
110
115
|
);
|
|
111
|
-
const betterAuthBin =
|
|
112
|
-
|
|
113
|
-
"dist",
|
|
114
|
-
|
|
116
|
+
const betterAuthBin = resolvePackageBin(
|
|
117
|
+
"@better-auth/cli",
|
|
118
|
+
"dist/index.mjs",
|
|
119
|
+
searchDirs,
|
|
115
120
|
);
|
|
116
121
|
|
|
117
122
|
const serverPath = resolve(outDirAbs, "server.ts");
|
|
@@ -274,6 +274,48 @@ type ManyToManyRelationRows<
|
|
|
274
274
|
>
|
|
275
275
|
>
|
|
276
276
|
: Array<TableModel<TTargetTable>>;
|
|
277
|
+
type NativeManyRelationRows<
|
|
278
|
+
TSourceTable extends TableName,
|
|
279
|
+
TRelationName extends string,
|
|
280
|
+
TRelationArgs,
|
|
281
|
+
> = RuntimeRelationTargetTable<TSourceTable, TRelationName> extends infer TTarget
|
|
282
|
+
? TTarget extends TableName
|
|
283
|
+
? TRelationArgs extends true
|
|
284
|
+
? Array<TableModel<TTarget>>
|
|
285
|
+
: TRelationArgs extends Record<string, unknown>
|
|
286
|
+
? Awaited<
|
|
287
|
+
TableFindManyResult<
|
|
288
|
+
TTarget,
|
|
289
|
+
Extract<
|
|
290
|
+
Omit<TRelationArgs, "_count" | "_avg">,
|
|
291
|
+
QueryFindManyArgs<TTarget>
|
|
292
|
+
>
|
|
293
|
+
>
|
|
294
|
+
>
|
|
295
|
+
: Array<TableModel<TTarget>>
|
|
296
|
+
: never
|
|
297
|
+
: never;
|
|
298
|
+
type NativeOneRelationValue<
|
|
299
|
+
TSourceTable extends TableName,
|
|
300
|
+
TRelationName extends string,
|
|
301
|
+
TRelationArgs,
|
|
302
|
+
> = RuntimeRelationTargetTable<TSourceTable, TRelationName> extends infer TTarget
|
|
303
|
+
? TTarget extends TableName
|
|
304
|
+
? TRelationArgs extends true
|
|
305
|
+
? TableModel<TTarget> | null
|
|
306
|
+
: TRelationArgs extends Record<string, unknown>
|
|
307
|
+
? Awaited<
|
|
308
|
+
TableFindFirstResult<
|
|
309
|
+
TTarget,
|
|
310
|
+
Extract<
|
|
311
|
+
Omit<TRelationArgs, "_count" | "_avg">,
|
|
312
|
+
QueryFindFirstArgs<TTarget>
|
|
313
|
+
>
|
|
314
|
+
>
|
|
315
|
+
>
|
|
316
|
+
: TableModel<TTarget> | null
|
|
317
|
+
: never
|
|
318
|
+
: never;
|
|
277
319
|
type ReplaceManyToManyRelationsInRow<
|
|
278
320
|
TSourceTable extends string,
|
|
279
321
|
TRow,
|
|
@@ -284,15 +326,33 @@ type ReplaceManyToManyRelationsInRow<
|
|
|
284
326
|
? TWith extends Record<string, unknown>
|
|
285
327
|
? K extends keyof TWith
|
|
286
328
|
? [ManyToManyTargetTableName<Extract<TSourceTable, TableName>, K>] extends [never]
|
|
287
|
-
?
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
329
|
+
? RuntimeRelationKind<Extract<TSourceTable, TableName>, K> extends "many"
|
|
330
|
+
? NativeManyRelationRows<
|
|
331
|
+
Extract<TSourceTable, TableName>,
|
|
332
|
+
K,
|
|
333
|
+
TWith[K]
|
|
334
|
+
>
|
|
335
|
+
: RuntimeRelationKind<Extract<TSourceTable, TableName>, K> extends "one"
|
|
336
|
+
? NativeOneRelationValue<
|
|
337
|
+
Extract<TSourceTable, TableName>,
|
|
338
|
+
K,
|
|
339
|
+
TWith[K]
|
|
340
|
+
>
|
|
341
|
+
: ReplaceManyToManyRelationsInRow<
|
|
342
|
+
[RuntimeRelationTargetTable<
|
|
343
|
+
Extract<TSourceTable, TableName>,
|
|
344
|
+
K
|
|
345
|
+
>] extends [never]
|
|
346
|
+
? K
|
|
347
|
+
: RuntimeRelationTargetTable<
|
|
348
|
+
Extract<TSourceTable, TableName>,
|
|
349
|
+
K
|
|
350
|
+
>,
|
|
351
|
+
TRow[K],
|
|
352
|
+
TWith[K] extends { with: infer TNestedWith }
|
|
353
|
+
? TNestedWith
|
|
354
|
+
: undefined
|
|
355
|
+
>
|
|
296
356
|
: ManyToManyRelationRows<
|
|
297
357
|
Extract<ManyToManyTargetTableName<Extract<TSourceTable, TableName>, K>, TableName>,
|
|
298
358
|
TWith[K]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
export function findNearestPackageDir(startDir: string): string {
|
|
5
|
+
let currentDir = startDir;
|
|
6
|
+
|
|
7
|
+
while (true) {
|
|
8
|
+
if (existsSync(resolve(currentDir, "package.json"))) {
|
|
9
|
+
return currentDir;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const parentDir = dirname(currentDir);
|
|
13
|
+
if (parentDir === currentDir) {
|
|
14
|
+
return startDir;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
currentDir = parentDir;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolvePackageRoot(
|
|
22
|
+
packageName: string,
|
|
23
|
+
searchDirs: string[],
|
|
24
|
+
): string {
|
|
25
|
+
for (const dir of searchDirs) {
|
|
26
|
+
try {
|
|
27
|
+
return dirname(Bun.resolveSync(`${packageName}/package.json`, dir));
|
|
28
|
+
} catch {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Could not resolve "${packageName}". Install it in your project (see appflare peerDependencies).`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function resolvePackageBin(
|
|
39
|
+
packageName: string,
|
|
40
|
+
binRelativePath: string,
|
|
41
|
+
searchDirs: string[],
|
|
42
|
+
): string {
|
|
43
|
+
return resolve(
|
|
44
|
+
resolvePackageRoot(packageName, searchDirs),
|
|
45
|
+
binRelativePath,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function packageSearchDirs(
|
|
50
|
+
moduleDir: string,
|
|
51
|
+
extraDirs: string[] = [],
|
|
52
|
+
): string[] {
|
|
53
|
+
const dirs = [
|
|
54
|
+
moduleDir,
|
|
55
|
+
findNearestPackageDir(process.cwd()),
|
|
56
|
+
...extraDirs,
|
|
57
|
+
];
|
|
58
|
+
return [...new Set(dirs)];
|
|
59
|
+
}
|