tthr 0.0.47 → 0.0.48
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/dist/chunk-EIJEC3SG.js +468 -0
- package/dist/generate-56PV7NJX.js +8 -0
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
// src/commands/generate.ts
|
|
2
|
+
import chalk2 from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import fs3 from "fs-extra";
|
|
5
|
+
import path3 from "path";
|
|
6
|
+
|
|
7
|
+
// src/utils/auth.ts
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import path from "path";
|
|
11
|
+
var CONFIG_DIR = path.join(process.env.HOME || process.env.USERPROFILE || "", ".tether");
|
|
12
|
+
var CREDENTIALS_FILE = path.join(CONFIG_DIR, "credentials.json");
|
|
13
|
+
async function getCredentials() {
|
|
14
|
+
try {
|
|
15
|
+
if (await fs.pathExists(CREDENTIALS_FILE)) {
|
|
16
|
+
return await fs.readJSON(CREDENTIALS_FILE);
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
async function requireAuth() {
|
|
23
|
+
const credentials = await getCredentials();
|
|
24
|
+
if (!credentials) {
|
|
25
|
+
console.error(chalk.red("\n\u2717 Not logged in\n"));
|
|
26
|
+
console.log(chalk.dim("Run `tthr login` to authenticate\n"));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
if (credentials.expiresAt) {
|
|
30
|
+
const expiresAt = new Date(credentials.expiresAt);
|
|
31
|
+
if (/* @__PURE__ */ new Date() > expiresAt) {
|
|
32
|
+
console.error(chalk.red("\n\u2717 Session expired\n"));
|
|
33
|
+
console.log(chalk.dim("Run `tthr login` to authenticate\n"));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return credentials;
|
|
38
|
+
}
|
|
39
|
+
async function saveCredentials(credentials) {
|
|
40
|
+
await fs.ensureDir(CONFIG_DIR);
|
|
41
|
+
await fs.writeJSON(CREDENTIALS_FILE, credentials, { spaces: 2, mode: 384 });
|
|
42
|
+
}
|
|
43
|
+
async function clearCredentials() {
|
|
44
|
+
try {
|
|
45
|
+
await fs.remove(CREDENTIALS_FILE);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/utils/config.ts
|
|
51
|
+
import fs2 from "fs-extra";
|
|
52
|
+
import path2 from "path";
|
|
53
|
+
var DEFAULT_CONFIG = {
|
|
54
|
+
schema: "./tether/schema.ts",
|
|
55
|
+
functions: "./tether/functions",
|
|
56
|
+
output: "./tether/_generated",
|
|
57
|
+
dev: {
|
|
58
|
+
port: 3001,
|
|
59
|
+
host: "localhost"
|
|
60
|
+
},
|
|
61
|
+
database: {
|
|
62
|
+
walMode: true
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
async function loadConfig(cwd = process.cwd()) {
|
|
66
|
+
const configPath = path2.resolve(cwd, "tether.config.ts");
|
|
67
|
+
if (!await fs2.pathExists(configPath)) {
|
|
68
|
+
return DEFAULT_CONFIG;
|
|
69
|
+
}
|
|
70
|
+
const configSource = await fs2.readFile(configPath, "utf-8");
|
|
71
|
+
const config = {};
|
|
72
|
+
const schemaMatch = configSource.match(/schema\s*:\s*['"]([^'"]+)['"]/);
|
|
73
|
+
if (schemaMatch) {
|
|
74
|
+
config.schema = schemaMatch[1];
|
|
75
|
+
}
|
|
76
|
+
const functionsMatch = configSource.match(/functions\s*:\s*['"]([^'"]+)['"]/);
|
|
77
|
+
if (functionsMatch) {
|
|
78
|
+
config.functions = functionsMatch[1];
|
|
79
|
+
}
|
|
80
|
+
const outputMatch = configSource.match(/output\s*:\s*['"]([^'"]+)['"]/);
|
|
81
|
+
if (outputMatch) {
|
|
82
|
+
config.output = outputMatch[1];
|
|
83
|
+
}
|
|
84
|
+
const envMatch = configSource.match(/environment\s*:\s*['"]([^'"]+)['"]/);
|
|
85
|
+
if (envMatch) {
|
|
86
|
+
config.environment = envMatch[1];
|
|
87
|
+
}
|
|
88
|
+
const portMatch = configSource.match(/port\s*:\s*(\d+)/);
|
|
89
|
+
if (portMatch) {
|
|
90
|
+
config.dev = { ...config.dev, port: parseInt(portMatch[1], 10) };
|
|
91
|
+
}
|
|
92
|
+
const hostMatch = configSource.match(/host\s*:\s*['"]([^'"]+)['"]/);
|
|
93
|
+
if (hostMatch) {
|
|
94
|
+
config.dev = { ...config.dev, host: hostMatch[1] };
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
...DEFAULT_CONFIG,
|
|
98
|
+
...config,
|
|
99
|
+
dev: { ...DEFAULT_CONFIG.dev, ...config.dev },
|
|
100
|
+
database: { ...DEFAULT_CONFIG.database, ...config.database }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function resolvePath(configPath, cwd = process.cwd()) {
|
|
104
|
+
const normalised = configPath.replace(/^\.\//, "");
|
|
105
|
+
return path2.resolve(cwd, normalised);
|
|
106
|
+
}
|
|
107
|
+
async function detectFramework(cwd = process.cwd()) {
|
|
108
|
+
const packageJsonPath = path2.resolve(cwd, "package.json");
|
|
109
|
+
if (!await fs2.pathExists(packageJsonPath)) {
|
|
110
|
+
return "unknown";
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const packageJson = await fs2.readJson(packageJsonPath);
|
|
114
|
+
const deps = {
|
|
115
|
+
...packageJson.dependencies,
|
|
116
|
+
...packageJson.devDependencies
|
|
117
|
+
};
|
|
118
|
+
if (deps.nuxt || deps["@nuxt/kit"]) {
|
|
119
|
+
return "nuxt";
|
|
120
|
+
}
|
|
121
|
+
if (deps.next) {
|
|
122
|
+
return "next";
|
|
123
|
+
}
|
|
124
|
+
if (deps["@sveltejs/kit"]) {
|
|
125
|
+
return "sveltekit";
|
|
126
|
+
}
|
|
127
|
+
if (deps.vite && !deps.nuxt && !deps.next && !deps["@sveltejs/kit"]) {
|
|
128
|
+
return "vite";
|
|
129
|
+
}
|
|
130
|
+
return "vanilla";
|
|
131
|
+
} catch {
|
|
132
|
+
return "unknown";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getFrameworkDevCommand(framework) {
|
|
136
|
+
switch (framework) {
|
|
137
|
+
case "nuxt":
|
|
138
|
+
return "nuxt dev";
|
|
139
|
+
case "next":
|
|
140
|
+
return "next dev";
|
|
141
|
+
case "sveltekit":
|
|
142
|
+
return "vite dev";
|
|
143
|
+
case "vite":
|
|
144
|
+
return "vite dev";
|
|
145
|
+
case "vanilla":
|
|
146
|
+
return null;
|
|
147
|
+
// No default dev server for vanilla
|
|
148
|
+
default:
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/commands/generate.ts
|
|
154
|
+
function parseSchemaFile(source) {
|
|
155
|
+
const tables = [];
|
|
156
|
+
const schemaMatch = source.match(/defineSchema\s*\(\s*\{([\s\S]*)\}\s*\)/);
|
|
157
|
+
if (!schemaMatch) return tables;
|
|
158
|
+
const schemaContent = schemaMatch[1];
|
|
159
|
+
const tableStartRegex = /(\w+)\s*:\s*\{/g;
|
|
160
|
+
let match;
|
|
161
|
+
while ((match = tableStartRegex.exec(schemaContent)) !== null) {
|
|
162
|
+
const tableName = match[1];
|
|
163
|
+
const startOffset = match.index + match[0].length;
|
|
164
|
+
let braceCount = 1;
|
|
165
|
+
let endOffset = startOffset;
|
|
166
|
+
for (let i = startOffset; i < schemaContent.length && braceCount > 0; i++) {
|
|
167
|
+
const char = schemaContent[i];
|
|
168
|
+
if (char === "{") braceCount++;
|
|
169
|
+
else if (char === "}") braceCount--;
|
|
170
|
+
endOffset = i;
|
|
171
|
+
}
|
|
172
|
+
const columnsContent = schemaContent.slice(startOffset, endOffset);
|
|
173
|
+
const columns = parseColumns(columnsContent);
|
|
174
|
+
tables.push({ name: tableName, columns });
|
|
175
|
+
}
|
|
176
|
+
return tables;
|
|
177
|
+
}
|
|
178
|
+
function parseColumns(content) {
|
|
179
|
+
const columns = [];
|
|
180
|
+
const columnRegex = /(\w+)\s*:\s*(\w+)\s*\(\s*\)([^,\n}]*)/g;
|
|
181
|
+
let match;
|
|
182
|
+
while ((match = columnRegex.exec(content)) !== null) {
|
|
183
|
+
const name = match[1];
|
|
184
|
+
const schemaType = match[2];
|
|
185
|
+
const modifiers = match[3] || "";
|
|
186
|
+
const nullable = !modifiers.includes(".notNull()");
|
|
187
|
+
columns.push({
|
|
188
|
+
name,
|
|
189
|
+
type: schemaTypeToTS(schemaType),
|
|
190
|
+
nullable
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return columns;
|
|
194
|
+
}
|
|
195
|
+
function schemaTypeToTS(schemaType) {
|
|
196
|
+
switch (schemaType) {
|
|
197
|
+
case "text":
|
|
198
|
+
return "string";
|
|
199
|
+
case "integer":
|
|
200
|
+
return "number";
|
|
201
|
+
case "real":
|
|
202
|
+
return "number";
|
|
203
|
+
case "boolean":
|
|
204
|
+
return "boolean";
|
|
205
|
+
case "timestamp":
|
|
206
|
+
return "string";
|
|
207
|
+
case "json":
|
|
208
|
+
return "unknown";
|
|
209
|
+
case "blob":
|
|
210
|
+
return "Uint8Array";
|
|
211
|
+
default:
|
|
212
|
+
return "unknown";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function tableNameToInterface(tableName) {
|
|
216
|
+
let name = tableName;
|
|
217
|
+
if (name.endsWith("ies")) {
|
|
218
|
+
name = name.slice(0, -3) + "y";
|
|
219
|
+
} else if (name.endsWith("s") && !name.endsWith("ss")) {
|
|
220
|
+
name = name.slice(0, -1);
|
|
221
|
+
}
|
|
222
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
223
|
+
}
|
|
224
|
+
function generateDbFile(tables) {
|
|
225
|
+
const lines = [
|
|
226
|
+
"// Auto-generated by Tether CLI - do not edit manually",
|
|
227
|
+
`// Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
228
|
+
"",
|
|
229
|
+
"import { createDatabaseProxy, type TetherDatabase } from '@tthr/client';",
|
|
230
|
+
"import {",
|
|
231
|
+
" query as baseQuery,",
|
|
232
|
+
" mutation as baseMutation,",
|
|
233
|
+
" action as baseAction,",
|
|
234
|
+
" type QueryDefinition,",
|
|
235
|
+
" type MutationDefinition,",
|
|
236
|
+
" type ActionDefinition,",
|
|
237
|
+
" z,",
|
|
238
|
+
"} from '@tthr/server';",
|
|
239
|
+
""
|
|
240
|
+
];
|
|
241
|
+
for (const table of tables) {
|
|
242
|
+
const interfaceName = tableNameToInterface(table.name);
|
|
243
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
244
|
+
lines.push(" _id: string;");
|
|
245
|
+
for (const col of table.columns) {
|
|
246
|
+
const typeStr = col.nullable ? `${col.type} | null` : col.type;
|
|
247
|
+
const optional = col.nullable ? "?" : "";
|
|
248
|
+
lines.push(` ${col.name}${optional}: ${typeStr};`);
|
|
249
|
+
}
|
|
250
|
+
lines.push(" _createdAt: string;");
|
|
251
|
+
lines.push(" _updatedAt?: string | null;");
|
|
252
|
+
lines.push(" _deletedAt?: string | null;");
|
|
253
|
+
lines.push("}");
|
|
254
|
+
lines.push("");
|
|
255
|
+
}
|
|
256
|
+
lines.push("export interface Schema {");
|
|
257
|
+
for (const table of tables) {
|
|
258
|
+
const interfaceName = tableNameToInterface(table.name);
|
|
259
|
+
lines.push(` ${table.name}: ${interfaceName};`);
|
|
260
|
+
}
|
|
261
|
+
lines.push("}");
|
|
262
|
+
lines.push("");
|
|
263
|
+
lines.push("// Database client with typed tables");
|
|
264
|
+
lines.push("// This is a proxy that will be populated by the Tether runtime");
|
|
265
|
+
lines.push("export const db: TetherDatabase<Schema> = createDatabaseProxy<Schema>();");
|
|
266
|
+
lines.push("");
|
|
267
|
+
lines.push("// ============================================================================");
|
|
268
|
+
lines.push("// Typed function wrappers - use these instead of importing from @tthr/server");
|
|
269
|
+
lines.push("// This ensures the `db` parameter in handlers is properly typed with Schema");
|
|
270
|
+
lines.push("// ============================================================================");
|
|
271
|
+
lines.push("");
|
|
272
|
+
lines.push("/**");
|
|
273
|
+
lines.push(" * Define a query function with typed database access.");
|
|
274
|
+
lines.push(" * The `db` parameter in the handler will have full type safety for your schema.");
|
|
275
|
+
lines.push(" */");
|
|
276
|
+
lines.push("export function query<TArgs = void, TResult = unknown>(");
|
|
277
|
+
lines.push(" definition: QueryDefinition<TArgs, TResult, Schema>");
|
|
278
|
+
lines.push("): QueryDefinition<TArgs, TResult, Schema> {");
|
|
279
|
+
lines.push(" return baseQuery(definition);");
|
|
280
|
+
lines.push("}");
|
|
281
|
+
lines.push("");
|
|
282
|
+
lines.push("/**");
|
|
283
|
+
lines.push(" * Define a mutation function with typed database access.");
|
|
284
|
+
lines.push(" * The `db` parameter in the handler will have full type safety for your schema.");
|
|
285
|
+
lines.push(" */");
|
|
286
|
+
lines.push("export function mutation<TArgs = void, TResult = unknown>(");
|
|
287
|
+
lines.push(" definition: MutationDefinition<TArgs, TResult, Schema>");
|
|
288
|
+
lines.push("): MutationDefinition<TArgs, TResult, Schema> {");
|
|
289
|
+
lines.push(" return baseMutation(definition);");
|
|
290
|
+
lines.push("}");
|
|
291
|
+
lines.push("");
|
|
292
|
+
lines.push("/**");
|
|
293
|
+
lines.push(" * Define an action function with typed database access.");
|
|
294
|
+
lines.push(" * The `db` parameter in the handler will have full type safety for your schema.");
|
|
295
|
+
lines.push(" */");
|
|
296
|
+
lines.push("export function action<TArgs = void, TResult = unknown>(");
|
|
297
|
+
lines.push(" definition: ActionDefinition<TArgs, TResult, Schema>");
|
|
298
|
+
lines.push("): ActionDefinition<TArgs, TResult, Schema> {");
|
|
299
|
+
lines.push(" return baseAction(definition);");
|
|
300
|
+
lines.push("}");
|
|
301
|
+
lines.push("");
|
|
302
|
+
lines.push("// Re-export z for convenience");
|
|
303
|
+
lines.push("export { z };");
|
|
304
|
+
lines.push("");
|
|
305
|
+
return lines.join("\n");
|
|
306
|
+
}
|
|
307
|
+
async function parseFunctionsDir(functionsDir) {
|
|
308
|
+
const functions = [];
|
|
309
|
+
if (!await fs3.pathExists(functionsDir)) {
|
|
310
|
+
return functions;
|
|
311
|
+
}
|
|
312
|
+
const files = await fs3.readdir(functionsDir);
|
|
313
|
+
for (const file of files) {
|
|
314
|
+
if (!file.endsWith(".ts") && !file.endsWith(".js")) continue;
|
|
315
|
+
const filePath = path3.join(functionsDir, file);
|
|
316
|
+
const stat = await fs3.stat(filePath);
|
|
317
|
+
if (!stat.isFile()) continue;
|
|
318
|
+
const moduleName = file.replace(/\.(ts|js)$/, "");
|
|
319
|
+
const source = await fs3.readFile(filePath, "utf-8");
|
|
320
|
+
const exportRegex = /export\s+const\s+(\w+)\s*=\s*(query|mutation|action)\s*\(/g;
|
|
321
|
+
let match;
|
|
322
|
+
while ((match = exportRegex.exec(source)) !== null) {
|
|
323
|
+
functions.push({
|
|
324
|
+
name: match[1],
|
|
325
|
+
moduleName
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return functions;
|
|
330
|
+
}
|
|
331
|
+
async function generateApiFile(functionsDir) {
|
|
332
|
+
const functions = await parseFunctionsDir(functionsDir);
|
|
333
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
334
|
+
for (const fn of functions) {
|
|
335
|
+
if (!moduleMap.has(fn.moduleName)) {
|
|
336
|
+
moduleMap.set(fn.moduleName, []);
|
|
337
|
+
}
|
|
338
|
+
moduleMap.get(fn.moduleName).push(fn.name);
|
|
339
|
+
}
|
|
340
|
+
const lines = [
|
|
341
|
+
"// Auto-generated by Tether CLI - do not edit manually",
|
|
342
|
+
`// Generated at: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
343
|
+
"",
|
|
344
|
+
"import { createApiProxy } from '@tthr/client';",
|
|
345
|
+
"",
|
|
346
|
+
"/**",
|
|
347
|
+
" * API function reference type for useQuery/useMutation.",
|
|
348
|
+
' * The _name property contains the function path (e.g., "users.list").',
|
|
349
|
+
" */",
|
|
350
|
+
"export interface ApiFunction<TArgs = unknown, TResult = unknown> {",
|
|
351
|
+
" _name: string;",
|
|
352
|
+
" _args?: TArgs;",
|
|
353
|
+
" _result?: TResult;",
|
|
354
|
+
"}",
|
|
355
|
+
""
|
|
356
|
+
];
|
|
357
|
+
if (moduleMap.size > 0) {
|
|
358
|
+
for (const [moduleName, fnNames] of moduleMap) {
|
|
359
|
+
const interfaceName = moduleName.charAt(0).toUpperCase() + moduleName.slice(1) + "Api";
|
|
360
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
361
|
+
for (const fnName of fnNames) {
|
|
362
|
+
lines.push(` ${fnName}: ApiFunction;`);
|
|
363
|
+
}
|
|
364
|
+
lines.push("}");
|
|
365
|
+
lines.push("");
|
|
366
|
+
}
|
|
367
|
+
lines.push("export interface Api {");
|
|
368
|
+
for (const moduleName of moduleMap.keys()) {
|
|
369
|
+
const interfaceName = moduleName.charAt(0).toUpperCase() + moduleName.slice(1) + "Api";
|
|
370
|
+
lines.push(` ${moduleName}: ${interfaceName};`);
|
|
371
|
+
}
|
|
372
|
+
lines.push("}");
|
|
373
|
+
} else {
|
|
374
|
+
lines.push("/**");
|
|
375
|
+
lines.push(" * Flexible API type that allows access to any function path.");
|
|
376
|
+
lines.push(" * Functions are accessed as api.moduleName.functionName");
|
|
377
|
+
lines.push(" * The actual types depend on your function definitions.");
|
|
378
|
+
lines.push(" */");
|
|
379
|
+
lines.push("export type Api = {");
|
|
380
|
+
lines.push(" [module: string]: {");
|
|
381
|
+
lines.push(" [fn: string]: ApiFunction;");
|
|
382
|
+
lines.push(" };");
|
|
383
|
+
lines.push("};");
|
|
384
|
+
}
|
|
385
|
+
lines.push("");
|
|
386
|
+
lines.push("// API client proxy - provides typed access to your functions");
|
|
387
|
+
lines.push("// On the client: returns { _name } references for useQuery/useMutation");
|
|
388
|
+
lines.push("// In Tether functions: calls the actual function implementation");
|
|
389
|
+
lines.push("export const api = createApiProxy<Api>();");
|
|
390
|
+
lines.push("");
|
|
391
|
+
return lines.join("\n");
|
|
392
|
+
}
|
|
393
|
+
async function generateTypes(options = {}) {
|
|
394
|
+
const config = await loadConfig();
|
|
395
|
+
const schemaPath = resolvePath(config.schema);
|
|
396
|
+
const outputDir = resolvePath(config.output);
|
|
397
|
+
const functionsDir = resolvePath(config.functions);
|
|
398
|
+
if (!await fs3.pathExists(schemaPath)) {
|
|
399
|
+
throw new Error(`Schema file not found: ${schemaPath}`);
|
|
400
|
+
}
|
|
401
|
+
const schemaSource = await fs3.readFile(schemaPath, "utf-8");
|
|
402
|
+
const tables = parseSchemaFile(schemaSource);
|
|
403
|
+
await fs3.ensureDir(outputDir);
|
|
404
|
+
await fs3.writeFile(
|
|
405
|
+
path3.join(outputDir, "db.ts"),
|
|
406
|
+
generateDbFile(tables)
|
|
407
|
+
);
|
|
408
|
+
await fs3.writeFile(
|
|
409
|
+
path3.join(outputDir, "api.ts"),
|
|
410
|
+
await generateApiFile(functionsDir)
|
|
411
|
+
);
|
|
412
|
+
await fs3.writeFile(
|
|
413
|
+
path3.join(outputDir, "index.ts"),
|
|
414
|
+
`// Auto-generated by Tether CLI - do not edit manually
|
|
415
|
+
export * from './db';
|
|
416
|
+
export * from './api';
|
|
417
|
+
`
|
|
418
|
+
);
|
|
419
|
+
return { tables, outputDir };
|
|
420
|
+
}
|
|
421
|
+
async function generateCommand() {
|
|
422
|
+
await requireAuth();
|
|
423
|
+
const configPath = path3.resolve(process.cwd(), "tether.config.ts");
|
|
424
|
+
if (!await fs3.pathExists(configPath)) {
|
|
425
|
+
console.log(chalk2.red("\nError: Not a Tether project"));
|
|
426
|
+
console.log(chalk2.dim("Run `tthr init` to create a new project\n"));
|
|
427
|
+
process.exit(1);
|
|
428
|
+
}
|
|
429
|
+
console.log(chalk2.bold("\n\u26A1 Generating types from schema\n"));
|
|
430
|
+
const spinner = ora("Reading schema...").start();
|
|
431
|
+
try {
|
|
432
|
+
spinner.text = "Generating types...";
|
|
433
|
+
const { tables, outputDir } = await generateTypes();
|
|
434
|
+
if (tables.length === 0) {
|
|
435
|
+
spinner.warn("No tables found in schema");
|
|
436
|
+
console.log(chalk2.dim(" Make sure your schema uses defineSchema({ ... })\n"));
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
spinner.succeed(`Types generated for ${tables.length} table(s)`);
|
|
440
|
+
console.log("\n" + chalk2.green("\u2713") + " Tables:");
|
|
441
|
+
for (const table of tables) {
|
|
442
|
+
console.log(chalk2.dim(` - ${table.name} (${table.columns.length} columns)`));
|
|
443
|
+
}
|
|
444
|
+
const relativeOutput = path3.relative(process.cwd(), outputDir);
|
|
445
|
+
console.log("\n" + chalk2.green("\u2713") + " Generated files:");
|
|
446
|
+
console.log(chalk2.dim(` ${relativeOutput}/db.ts`));
|
|
447
|
+
console.log(chalk2.dim(` ${relativeOutput}/api.ts`));
|
|
448
|
+
console.log(chalk2.dim(` ${relativeOutput}/index.ts
|
|
449
|
+
`));
|
|
450
|
+
} catch (error) {
|
|
451
|
+
spinner.fail("Failed to generate types");
|
|
452
|
+
console.error(chalk2.red(error instanceof Error ? error.message : "Unknown error"));
|
|
453
|
+
process.exit(1);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export {
|
|
458
|
+
getCredentials,
|
|
459
|
+
requireAuth,
|
|
460
|
+
saveCredentials,
|
|
461
|
+
clearCredentials,
|
|
462
|
+
loadConfig,
|
|
463
|
+
resolvePath,
|
|
464
|
+
detectFramework,
|
|
465
|
+
getFrameworkDevCommand,
|
|
466
|
+
generateTypes,
|
|
467
|
+
generateCommand
|
|
468
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
requireAuth,
|
|
10
10
|
resolvePath,
|
|
11
11
|
saveCredentials
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-EIJEC3SG.js";
|
|
13
13
|
|
|
14
14
|
// src/index.ts
|
|
15
15
|
import { Command } from "commander";
|
|
@@ -1510,7 +1510,7 @@ async function runGenerate(spinner) {
|
|
|
1510
1510
|
}
|
|
1511
1511
|
isGenerating = true;
|
|
1512
1512
|
try {
|
|
1513
|
-
const { generateTypes } = await import("./generate-
|
|
1513
|
+
const { generateTypes } = await import("./generate-56PV7NJX.js");
|
|
1514
1514
|
spinner.text = "Regenerating types...";
|
|
1515
1515
|
await generateTypes({ silent: true });
|
|
1516
1516
|
spinner.succeed("Types regenerated");
|
|
@@ -1695,7 +1695,7 @@ async function devCommand(options) {
|
|
|
1695
1695
|
}
|
|
1696
1696
|
}
|
|
1697
1697
|
spinner.text = "Generating types...";
|
|
1698
|
-
const { generateTypes } = await import("./generate-
|
|
1698
|
+
const { generateTypes } = await import("./generate-56PV7NJX.js");
|
|
1699
1699
|
await generateTypes({ silent: true });
|
|
1700
1700
|
spinner.succeed("Types generated");
|
|
1701
1701
|
spinner.start("Setting up file watchers...");
|