@vaiftech/cli 1.6.6 → 1.7.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/README.md +1 -1
- package/dist/{chunk-OB2QEQ2L.js → chunk-N7OY2COL.js} +65 -63
- package/dist/cli.cjs +100 -98
- package/dist/cli.js +30 -30
- package/dist/index.cjs +58 -56
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';require('dotenv/config');var commander=require('commander'),
|
|
2
|
+
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),U=require('fs'),A=require('path'),lt=require('pg'),H=require('ora'),dt=require('prettier'),rt=require('dotenv'),Ae=require('readline'),bt=require('os'),child_process=require('child_process');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var f__default=/*#__PURE__*/_interopDefault(f);var U__default=/*#__PURE__*/_interopDefault(U);var A__default=/*#__PURE__*/_interopDefault(A);var lt__default=/*#__PURE__*/_interopDefault(lt);var H__default=/*#__PURE__*/_interopDefault(H);var dt__default=/*#__PURE__*/_interopDefault(dt);var rt__default=/*#__PURE__*/_interopDefault(rt);var Ae__default=/*#__PURE__*/_interopDefault(Ae);var bt__default=/*#__PURE__*/_interopDefault(bt);rt__default.default.config();async function I(t){let e=A__default.default.resolve(t);if(!U__default.default.existsSync(e))return null;try{let o=U__default.default.readFileSync(e,"utf-8"),n=JSON.parse(o);return n.database?.url&&(n.database.url=ve(n.database.url)),n.api?.apiKey&&(n.api.apiKey=ve(n.api.apiKey)),n}catch{throw new Error(`Failed to parse config file: ${t}`)}}function ve(t){return t.replace(/\$\{([^}]+)\}/g,(e,o)=>process.env[o]||e)}async function pt(t,e){let o=await t.query(`
|
|
3
3
|
SELECT table_name, table_type
|
|
4
4
|
FROM information_schema.tables
|
|
5
5
|
WHERE table_schema = $1
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
FROM information_schema.columns
|
|
21
21
|
WHERE table_schema = $1
|
|
22
22
|
ORDER BY table_name, ordinal_position
|
|
23
|
-
`,[e]),
|
|
23
|
+
`,[e]),s=await t.query(`
|
|
24
24
|
SELECT
|
|
25
25
|
tc.constraint_name,
|
|
26
26
|
tc.table_name,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
AND ccu.table_schema = tc.table_schema
|
|
37
37
|
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
38
38
|
AND tc.table_schema = $1
|
|
39
|
-
`,[e]),
|
|
39
|
+
`,[e]),r=await t.query(`
|
|
40
40
|
SELECT
|
|
41
41
|
t.typname as enum_name,
|
|
42
42
|
e.enumlabel as enum_value
|
|
@@ -45,22 +45,22 @@
|
|
|
45
45
|
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
46
46
|
WHERE n.nspname = $1
|
|
47
47
|
ORDER BY t.typname, e.enumsortorder
|
|
48
|
-
`,[e]),i=new Map;for(let l of o.rows)i.set(l.table_name,[]);for(let l of n.rows){let c=i.get(l.table_name);c&&c.push(l);}let a=new Map;for(let l of
|
|
48
|
+
`,[e]),i=new Map;for(let l of o.rows)i.set(l.table_name,[]);for(let l of n.rows){let c=i.get(l.table_name);c&&c.push(l);}let a=new Map;for(let l of r.rows){let c=a.get(l.enum_name)||[];c.push(l.enum_value),a.set(l.enum_name,c);}return {tables:i,enums:a,foreignKeys:s.rows}}var ie={smallint:"number",integer:"number",bigint:"string",int2:"number",int4:"number",int8:"string",decimal:"string",numeric:"string",real:"number",float4:"number",float8:"number","double precision":"number",money:"string",boolean:"boolean",bool:"boolean",text:"string",varchar:"string",char:"string",character:"string","character varying":"string",name:"string",citext:"string",date:"string",time:"string",timetz:"string","time without time zone":"string","time with time zone":"string",timestamp:"string",timestamptz:"string","timestamp without time zone":"string","timestamp with time zone":"string",interval:"string",bytea:"Buffer",uuid:"string",json:"unknown",jsonb:"unknown",inet:"string",cidr:"string",macaddr:"string",macaddr8:"string",point:"{ x: number; y: number }",line:"string",lseg:"string",box:"string",path:"string",polygon:"string",circle:"string",ARRAY:"unknown[]"};function ut(t,e){let{data_type:o,udt_name:n,is_nullable:s}=t;if(e.has(n)){let a=e.get(n).map(l=>`"${l}"`).join(" | ");return s==="YES"?`(${a}) | null`:a}if(o==="ARRAY"){let i=n.replace(/^_/,"");if(e.has(i)){let c=e.get(i).map(d=>`"${d}"`).join(" | ");return s==="YES"?`(${c})[] | null`:`(${c})[]`}let a=ie[i]||"unknown";return s==="YES"?`${a}[] | null`:`${a}[]`}let r=ie[o]||ie[n]||"unknown";return s==="YES"&&(r=`${r} | null`),r}function se(t){return t.split(/[_\-\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function ft(t,e){let o=se(t),n=e.map(s=>` | "${s}"`).join(`
|
|
49
49
|
`);return `export type ${o} =
|
|
50
|
-
${n};`}function
|
|
51
|
-
${
|
|
50
|
+
${n};`}function gt(t,e,o){let n=se(t),s=[],r=[],i=[];for(let d of e){let u=ut(d,o),p=d.column_name,m=d.column_default!==null||d.is_identity==="YES",y=d.is_nullable==="YES";s.push(` ${p}: ${u};`),m||d.column_name==="id"?r.push(` ${p}?: ${u.replace(" | null","")} | null;`):y?r.push(` ${p}?: ${u};`):r.push(` ${p}: ${u.replace(" | null","")};`),i.push(` ${p}?: ${u.replace(" | null","")} | null;`);}let a=`export interface ${n} {
|
|
51
|
+
${s.join(`
|
|
52
52
|
`)}
|
|
53
53
|
}`,l=`export interface ${n}Insert {
|
|
54
|
-
${
|
|
54
|
+
${r.join(`
|
|
55
55
|
`)}
|
|
56
56
|
}`,c=`export interface ${n}Update {
|
|
57
57
|
${i.join(`
|
|
58
58
|
`)}
|
|
59
|
-
}`;return {base:a,insert:l,update:c}}function
|
|
60
|
-
`)}async function
|
|
61
|
-
Provide a connection string via:`)),console.log(f__default.default.gray(" --connection
|
|
59
|
+
}`;return {base:a,insert:l,update:c}}function mt(t,e,o){let n=["/**"," * Auto-generated TypeScript types from database schema"," * Generated by @vaiftech/cli",` * Generated at: ${new Date().toISOString()}`," * "," * DO NOT EDIT MANUALLY - changes will be overwritten"," */",""];if(e.size>0){n.push("// ============ ENUMS ============"),n.push("");for(let[r,i]of e)n.push(ft(r,i)),n.push("");}n.push("// ============ TABLES ============"),n.push("");let s=[];for(let[r,i]of t){let{base:a,insert:l,update:c}=gt(r,i,e);s.push(r),n.push(a),n.push(""),n.push(l),n.push(""),n.push(c),n.push("");}n.push("// ============ DATABASE SCHEMA ============"),n.push(""),n.push("export interface Database {");for(let r of s){let i=se(r);n.push(` ${r}: {`),n.push(` Row: ${i};`),n.push(` Insert: ${i}Insert;`),n.push(` Update: ${i}Update;`),n.push(" };");}return n.push("}"),n.push(""),n.push("export type TableName = keyof Database;"),n.push(""),n.push("// ============ HELPER TYPES ============"),n.push(""),n.push('export type Row<T extends TableName> = Database[T]["Row"];'),n.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),n.push('export type Update<T extends TableName> = Database[T]["Update"];'),n.push(""),n.join(`
|
|
60
|
+
`)}async function Ie(t){let e=H__default.default("Loading configuration...").start();try{let o=await I(t.config),n=t.connection||o?.database?.url||process.env.DATABASE_URL;(!n||n.includes("${"))&&(e.fail("No database connection string provided"),console.log(f__default.default.yellow(`
|
|
61
|
+
Provide a connection string via:`)),console.log(f__default.default.gray(" --connection postgresql://user:pass@host:5432/db")),console.log(f__default.default.gray(" DATABASE_URL environment variable in .env")),console.log(f__default.default.gray(" database.url in vaif.config.json")),n?.includes("${")&&(console.log(f__default.default.yellow("\nYour vaif.config.json references ${DATABASE_URL} but the env var is not set.")),console.log(f__default.default.gray(" Add DATABASE_URL to your .env file or pass --connection directly."))),process.exit(1)),e.text="Connecting to database...";let s=new lt__default.default.Client({connectionString:n});await s.connect(),e.text="Introspecting schema...";let{tables:r,enums:i,foreignKeys:a}=await pt(s,t.schema);if(await s.end(),r.size===0){e.warn(`No tables found in schema "${t.schema}"`);return}e.text=`Generating types for ${r.size} tables...`;let l=mt(r,i,a),c=await dt__default.default.format(l,{parser:"typescript",semi:!0,singleQuote:!1,trailingComma:"es5",printWidth:100});if(t.dryRun){e.succeed("Generated types (dry run):"),console.log(""),console.log(f__default.default.gray("\u2500".repeat(60))),console.log(c),console.log(f__default.default.gray("\u2500".repeat(60)));return}let d=A__default.default.resolve(t.output),u=A__default.default.dirname(d);U__default.default.existsSync(u)||U__default.default.mkdirSync(u,{recursive:!0}),U__default.default.writeFileSync(d,c,"utf-8"),e.succeed(`Generated types for ${r.size} tables \u2192 ${f__default.default.cyan(t.output)}`),console.log(""),console.log(f__default.default.green("Generated:")),console.log(f__default.default.gray(` Tables: ${r.size}`)),console.log(f__default.default.gray(` Enums: ${i.size}`)),console.log(""),console.log(f__default.default.gray("Import in your code:")),console.log(f__default.default.cyan(` import type { Database, Row, Insert, Update } from "${t.output.replace(/\.ts$/,"")}";`));}catch(o){e.fail("Failed to generate types"),o instanceof Error&&(console.error(f__default.default.red(`
|
|
62
62
|
Error: ${o.message}`)),o.message.includes("ECONNREFUSED")&&console.log(f__default.default.yellow(`
|
|
63
|
-
Make sure your database is running and accessible.`))),process.exit(1);}}var
|
|
63
|
+
Make sure your database is running and accessible.`))),process.exit(1);}}var B=[{name:"database",label:"Database",description:"CRUD queries, type-safe operations"},{name:"auth",label:"Authentication",description:"login, signup, OAuth, sessions"},{name:"realtime",label:"Realtime",description:"live subscriptions, presence"},{name:"storage",label:"Storage",description:"file uploads, signed URLs"},{name:"functions",label:"Functions",description:"serverless function calls"}],we={"nextjs-fullstack":{name:"Next.js Full-Stack",description:"Next.js app with server/client VAIF client, auth middleware, and React hooks",tag:"Next.js",defaultFeatures:["database","auth"],files:[{path:"package.json",content:`{
|
|
64
64
|
"name": "my-vaif-app",
|
|
65
65
|
"private": true,
|
|
66
66
|
"version": "0.1.0",
|
|
@@ -156,24 +156,27 @@ body {
|
|
|
156
156
|
|
|
157
157
|
// Browser client \u2013 safe to use in Client Components
|
|
158
158
|
export const vaif = createVaifClient({
|
|
159
|
-
|
|
159
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
160
160
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
// Server client \u2013 use in Server Components, Route Handlers, Server Actions
|
|
164
164
|
export function createVaifServer() {
|
|
165
165
|
return createVaifClient({
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
167
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
`},{path:".env.local.example",content:`# VAIF Configuration
|
|
171
171
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
173
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
174
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
175
175
|
VAIF_SECRET_KEY=your-secret-key
|
|
176
176
|
|
|
177
|
+
# Database connection (for vaif generate, vaif db push)
|
|
178
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
179
|
+
|
|
177
180
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
178
181
|
VAIF_PROJECT_ID=your-project-id
|
|
179
182
|
`},{path:".gitignore",content:`node_modules
|
|
@@ -289,8 +292,8 @@ export async function middleware(request: NextRequest) {
|
|
|
289
292
|
if (!isProtected) return NextResponse.next();
|
|
290
293
|
|
|
291
294
|
const vaif = createVaifClient({
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
296
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
294
297
|
});
|
|
295
298
|
|
|
296
299
|
return authMiddleware(vaif, request, {
|
|
@@ -651,13 +654,13 @@ function Home() {
|
|
|
651
654
|
`},{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
652
655
|
|
|
653
656
|
export const vaif = createVaifClient({
|
|
654
|
-
|
|
657
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
655
658
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
656
659
|
});
|
|
657
660
|
`},{path:"src/vite-env.d.ts",content:`/// <reference types="vite/client" />
|
|
658
661
|
|
|
659
662
|
interface ImportMetaEnv {
|
|
660
|
-
readonly
|
|
663
|
+
readonly VITE_VAIF_API_URL: string;
|
|
661
664
|
readonly VITE_VAIF_API_KEY: string;
|
|
662
665
|
}
|
|
663
666
|
|
|
@@ -665,13 +668,13 @@ interface ImportMeta {
|
|
|
665
668
|
readonly env: ImportMetaEnv;
|
|
666
669
|
}
|
|
667
670
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
668
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
671
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
669
672
|
|
|
670
|
-
|
|
671
|
-
VITE_VAIF_API_KEY=your-
|
|
673
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
674
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
672
675
|
|
|
673
|
-
#
|
|
674
|
-
|
|
676
|
+
# Database connection (for vaif generate, vaif db push)
|
|
677
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
675
678
|
`},{path:".gitignore",content:`node_modules
|
|
676
679
|
dist
|
|
677
680
|
.env
|
|
@@ -2610,7 +2613,7 @@ func HelloHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
2610
2613
|
`}]},postInstructions:["go mod tidy","# Copy .env.example to .env and add your VAIF credentials","go run main.go"]},"todo-app":{name:"Todo App",description:"Simple React todo app \u2013 great for learning VAIF basics",tag:"React Starter",defaultFeatures:["database"],files:[{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
2611
2614
|
|
|
2612
2615
|
export const vaif = createVaifClient({
|
|
2613
|
-
|
|
2616
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
2614
2617
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
2615
2618
|
});
|
|
2616
2619
|
|
|
@@ -2662,13 +2665,13 @@ export async function deleteTodo(id: string): Promise<void> {
|
|
|
2662
2665
|
if (error) throw error;
|
|
2663
2666
|
}
|
|
2664
2667
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
2665
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2668
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2666
2669
|
|
|
2667
|
-
|
|
2668
|
-
VITE_VAIF_API_KEY=your-
|
|
2670
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2671
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
2669
2672
|
|
|
2670
|
-
#
|
|
2671
|
-
|
|
2673
|
+
# Database connection (for vaif generate, vaif db push)
|
|
2674
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2672
2675
|
`},{path:"README.md",content:`# Todo App \u2014 VAIF Starter
|
|
2673
2676
|
|
|
2674
2677
|
A simple React todo application for learning [VAIF Studio](https://vaif.studio) basics, including typed database queries and CRUD operations.
|
|
@@ -2804,15 +2807,8 @@ export const posts = pgTable("posts", {
|
|
|
2804
2807
|
`}]},dependencies:["@vaiftech/client","@vaiftech/react"],postInstructions:["Copy .env.example to .env and fill in your project credentials","Create a 'todos' table in your VAIF dashboard with columns: id (uuid), title (text), done (boolean), created_at (timestamptz)","Import helpers from './lib/vaif' in your components","Run: npx vaif generate to generate TypeScript types"]},"realtime-chat":{name:"Realtime Chat",description:"React chat app with VAIF realtime subscriptions for live messaging",tag:"React + Realtime",defaultFeatures:["database","realtime","auth"],files:[{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
2805
2808
|
|
|
2806
2809
|
export const vaif = createVaifClient({
|
|
2807
|
-
|
|
2810
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
2808
2811
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
2809
|
-
realtime: {
|
|
2810
|
-
enabled: true,
|
|
2811
|
-
// Automatically reconnect on connection loss
|
|
2812
|
-
reconnect: true,
|
|
2813
|
-
reconnectInterval: 1000,
|
|
2814
|
-
maxReconnectAttempts: 10,
|
|
2815
|
-
},
|
|
2816
2812
|
});
|
|
2817
2813
|
|
|
2818
2814
|
export interface Message {
|
|
@@ -2950,13 +2946,13 @@ export function useRealtimeMessages({
|
|
|
2950
2946
|
return { messages, isLoading, error, refresh };
|
|
2951
2947
|
}
|
|
2952
2948
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
2953
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2949
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2954
2950
|
|
|
2955
|
-
|
|
2956
|
-
VITE_VAIF_API_KEY=your-
|
|
2951
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2952
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
2957
2953
|
|
|
2958
|
-
#
|
|
2959
|
-
|
|
2954
|
+
# Database connection (for vaif generate, vaif db push)
|
|
2955
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2960
2956
|
`},{path:"README.md",content:`# Realtime Chat \u2014 VAIF Starter
|
|
2961
2957
|
|
|
2962
2958
|
A React chat application with live messaging powered by [VAIF Studio](https://vaif.studio) realtime subscriptions.
|
|
@@ -3107,15 +3103,15 @@ export const posts = pgTable("posts", {
|
|
|
3107
3103
|
|
|
3108
3104
|
// Browser client \u2013 use in Client Components
|
|
3109
3105
|
export const vaif = createVaifClient({
|
|
3110
|
-
|
|
3106
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3111
3107
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
3112
3108
|
});
|
|
3113
3109
|
|
|
3114
3110
|
// Server client \u2013 use in Server Components, Route Handlers, Server Actions
|
|
3115
3111
|
export function createVaifServer() {
|
|
3116
3112
|
return createVaifClient({
|
|
3117
|
-
|
|
3118
|
-
|
|
3113
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3114
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
3119
3115
|
});
|
|
3120
3116
|
}
|
|
3121
3117
|
`},{path:"lib/auth.ts",content:`import { createVaifServer } from "./vaif";
|
|
@@ -3268,10 +3264,13 @@ export async function requireTeamRole(
|
|
|
3268
3264
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
3269
3265
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
3270
3266
|
|
|
3271
|
-
|
|
3272
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
3267
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
3268
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3273
3269
|
VAIF_SECRET_KEY=your-secret-key
|
|
3274
3270
|
|
|
3271
|
+
# Database connection (for vaif generate, vaif db push)
|
|
3272
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3273
|
+
|
|
3275
3274
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3276
3275
|
VAIF_PROJECT_ID=your-project-id
|
|
3277
3276
|
`},{path:"README.md",content:`# SaaS Starter \u2014 VAIF Studio
|
|
@@ -3420,15 +3419,15 @@ export const posts = pgTable("posts", {
|
|
|
3420
3419
|
|
|
3421
3420
|
// Browser client
|
|
3422
3421
|
export const vaif = createVaifClient({
|
|
3423
|
-
|
|
3422
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3424
3423
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
3425
3424
|
});
|
|
3426
3425
|
|
|
3427
3426
|
// Server client
|
|
3428
3427
|
export function createVaifServer() {
|
|
3429
3428
|
return createVaifClient({
|
|
3430
|
-
|
|
3431
|
-
|
|
3429
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3430
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
3432
3431
|
});
|
|
3433
3432
|
}
|
|
3434
3433
|
`},{path:"lib/storage.ts",content:`import { createVaifServer } from "./vaif";
|
|
@@ -3543,10 +3542,13 @@ function getContentType(fileName: string): string {
|
|
|
3543
3542
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
3544
3543
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
3545
3544
|
|
|
3546
|
-
|
|
3547
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
3545
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
3546
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3548
3547
|
VAIF_SECRET_KEY=your-secret-key
|
|
3549
3548
|
|
|
3549
|
+
# Database connection (for vaif generate, vaif db push)
|
|
3550
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3551
|
+
|
|
3550
3552
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3551
3553
|
VAIF_PROJECT_ID=your-project-id
|
|
3552
3554
|
`},{path:"README.md",content:`# E-commerce API \u2014 VAIF Studio
|
|
@@ -3689,56 +3691,56 @@ export const posts = pgTable("posts", {
|
|
|
3689
3691
|
|
|
3690
3692
|
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3691
3693
|
}
|
|
3692
|
-
`}]},dependencies:["@vaiftech/client","@vaiftech/auth"],postInstructions:["Copy .env.example to .env.local and fill in your project credentials","Create a 'product-images' storage bucket in your VAIF dashboard","Import storage helpers from '@/lib/storage' in your API routes","Use uploadProductImage() in your product creation flow","Run: npx vaif generate to generate TypeScript types"]}};function
|
|
3693
|
-
? Which VAIF features do you want to include?`)),
|
|
3694
|
+
`}]},dependencies:["@vaiftech/client","@vaiftech/auth"],postInstructions:["Copy .env.example to .env.local and fill in your project credentials","Create a 'product-images' storage bucket in your VAIF dashboard","Import storage helpers from '@/lib/storage' in your API routes","Use uploadProductImage() in your product creation flow","Run: npx vaif generate to generate TypeScript types"]}};function Se(){console.log(""),console.log(f__default.default.bold("Available project templates")),console.log("");let t=26,e=22;console.log(` ${f__default.default.gray("Template".padEnd(t))}${f__default.default.gray("Stack".padEnd(e))}${f__default.default.gray("Description")}`),console.log(f__default.default.gray(" "+"-".repeat(t+e+40)));for(let[o,n]of Object.entries(we))console.log(` ${f__default.default.cyan(o.padEnd(t))}${f__default.default.yellow(n.tag.padEnd(e))}${f__default.default.white(n.description)}`);console.log(""),console.log(f__default.default.gray("Usage:")),console.log(f__default.default.gray(" npx @vaiftech/cli init --template <name>")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t nextjs-fullstack")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t react-spa --features auth,database,realtime")),console.log(""),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),console.log("");}async function ht(t){if(!process.stdin.isTTY||!process.stdout.isTTY)return t;let e=new Set(t.map(n=>B.findIndex(s=>s.name===n)).filter(n=>n>=0)),o=0;return new Promise(n=>{let s=Ae__default.default.createInterface({input:process.stdin,output:process.stdout});Ae__default.default.emitKeypressEvents(process.stdin,s),process.stdin.setRawMode&&process.stdin.setRawMode(true);function r(){let a=B.length+2;process.stdout.write(`\x1B[${a}A`),i();}function i(){console.log(f__default.default.bold(`
|
|
3695
|
+
? Which VAIF features do you want to include?`)),B.forEach((a,l)=>{let c=e.has(l)?f__default.default.green("[x]"):"[ ]",d=l===o?f__default.default.cyan("> "):" ";console.log(`${d}${c} ${a.label} ${f__default.default.gray(`(${a.description})`)}`);}),console.log(f__default.default.gray(" (up/down to move, space to toggle, enter to confirm)"));}i(),process.stdin.on("keypress",(a,l)=>{if(l.name==="up"&&o>0)o--,r();else if(l.name==="down"&&o<B.length-1)o++,r();else if(l.name==="space")e.has(o)?e.delete(o):e.add(o),r();else if(l.name==="return"){process.stdin.setRawMode&&process.stdin.setRawMode(false),s.close();let c=[...e].sort().map(d=>B[d].name);n(c.length>0?c:t);}else l.name==="c"&&l.ctrl&&(process.stdin.setRawMode&&process.stdin.setRawMode(false),s.close(),process.exit(0));});})}async function le(t,e={}){let o=we[t];o||(console.log(f__default.default.red(`
|
|
3694
3696
|
Unknown template: ${t}`)),console.log(f__default.default.yellow(`Run 'vaif templates' to see available templates.
|
|
3695
|
-
`)),process.exit(1));let n;e.features&&e.features.length>0?n=e.features.filter(c=>
|
|
3696
|
-
No features specified.`)),console.log(f__default.default.yellow("Usage: vaif init --template <name> --add-features <features>")),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),process.exit(1)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await
|
|
3697
|
-
`,"utf-8"),console.log(f__default.default.green(` merge ${c.path} (added dependencies)`)),
|
|
3698
|
-
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),o.postInstructions.forEach(c=>{console.log(f__default.default.gray(` ${c}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var
|
|
3699
|
-
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(
|
|
3700
|
-
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(
|
|
3697
|
+
`)),process.exit(1));let n;e.features&&e.features.length>0?n=e.features.filter(c=>B.some(d=>d.name===c)):e.addOnly?(console.log(f__default.default.red(`
|
|
3698
|
+
No features specified.`)),console.log(f__default.default.yellow("Usage: vaif init --template <name> --add-features <features>")),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),process.exit(1)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await ht(o.defaultFeatures??["database","auth"]):n=o.defaultFeatures??[],e.addOnly?(console.log(""),console.log(f__default.default.bold(`Adding features to ${f__default.default.cyan(o.name)} project...`)),console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log("")):(console.log(""),console.log(f__default.default.bold(`Scaffolding ${f__default.default.cyan(o.name)} template...`)),n.length>0&&console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log(""));let s=e.addOnly?[]:[...o.files];if(o.featureFiles)for(let c of n){let d=o.featureFiles[c];d&&s.push(...d);}let r=0,i=0;for(let c of s){let d=A__default.default.resolve(c.path),u=A__default.default.dirname(d);if(U__default.default.existsSync(u)||U__default.default.mkdirSync(u,{recursive:true}),c.path==="package.json"&&U__default.default.existsSync(d)&&!e.force)try{let p=JSON.parse(U__default.default.readFileSync(d,"utf-8")),m=JSON.parse(c.content),y=L=>{if(!L)return {};let M={};for(let[z,G]of Object.entries(L))!G.startsWith("workspace:")&&!G.startsWith("link:")&&!G.startsWith("file:")&&(M[z]=G);return M};p.dependencies={...y(p.dependencies),...m.dependencies||{}},p.devDependencies={...y(p.devDependencies),...m.devDependencies||{}},m.scripts&&(p.scripts={...p.scripts||{},...m.scripts}),U__default.default.writeFileSync(d,JSON.stringify(p,null,2)+`
|
|
3699
|
+
`,"utf-8"),console.log(f__default.default.green(` merge ${c.path} (added dependencies)`)),r++;continue}catch{}if(U__default.default.existsSync(d)&&!e.force){console.log(f__default.default.yellow(` skip ${c.path} (already exists)`)),i++;continue}U__default.default.writeFileSync(d,c.content,"utf-8"),console.log(f__default.default.green(` create ${c.path}`)),r++;}console.log(""),r>0&&console.log(f__default.default.green(`Created ${r} file${r!==1?"s":""}.`)),i>0&&console.log(f__default.default.yellow(`Skipped ${i} file${i!==1?"s":""} (use --force to overwrite).`));let a={auth:{"@vaiftech/auth":"^1.0.0"},database:{},realtime:{},storage:{},functions:{}},l=A__default.default.resolve("package.json");if(U__default.default.existsSync(l)&&n.length>0)try{let c=JSON.parse(U__default.default.readFileSync(l,"utf-8")),d=!1;for(let u of n){let p=a[u];if(p)for(let[m,y]of Object.entries(p))c.dependencies?.[m]||(c.dependencies=c.dependencies||{},c.dependencies[m]=y,d=!0);}d&&U__default.default.writeFileSync(l,JSON.stringify(c,null,2)+`
|
|
3700
|
+
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),o.postInstructions.forEach(c=>{console.log(f__default.default.gray(` ${c}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var vt={$schema:"https://vaif.studio/schemas/config.json",projectId:"",database:{url:"${DATABASE_URL}",schema:"public"},types:{output:"./src/types/database.ts"},api:{baseUrl:"https://api.vaif.studio"}};async function Ee(t){if(t.addFeatures){t.template||(console.log(f__default.default.red(`
|
|
3701
|
+
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(s=>s.trim());await le(t.template,{force:t.force,features:n,addOnly:true});return}let e=H__default.default("Initializing VAIF configuration...").start(),o=A__default.default.resolve("vaif.config.json");U__default.default.existsSync(o)&&!t.force&&(e.fail("vaif.config.json already exists"),console.log(f__default.default.yellow(`
|
|
3702
|
+
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(U__default.default.writeFileSync(o,JSON.stringify(vt,null,2),"utf-8"),e.succeed("Created vaif.config.json"),t.template){let n=t.features?t.features.split(",").map(s=>s.trim()):void 0;await le(t.template,{force:t.force,features:n});}else {let n=A__default.default.resolve(".env.example");if(U__default.default.existsSync(n)||(U__default.default.writeFileSync(n,`# VAIF Configuration
|
|
3701
3703
|
DATABASE_URL=postgresql://user:password@localhost:5432/database
|
|
3702
3704
|
VAIF_API_KEY=your-api-key
|
|
3703
|
-
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let
|
|
3704
|
-
Error: ${n.message}`)),process.exit(1);}}var
|
|
3705
|
+
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let s=A__default.default.resolve("src/types");U__default.default.existsSync(s)||(U__default.default.mkdirSync(s,{recursive:!0}),console.log(f__default.default.gray("Created src/types directory")));}console.log(""),console.log(f__default.default.green("VAIF initialized successfully!")),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" 1. Update vaif.config.json with your project ID")),console.log(f__default.default.gray(" 2. Set DATABASE_URL in your environment")),console.log(f__default.default.gray(" 3. Run: npx vaif generate")),console.log("");}}catch(n){e.fail("Failed to initialize"),n instanceof Error&&console.error(f__default.default.red(`
|
|
3706
|
+
Error: ${n.message}`)),process.exit(1);}}var de=A__default.default.join(bt__default.default.homedir(),".vaif"),$=A__default.default.join(de,"auth.json"),J=process.env.VAIF_API_URL||"https://api.vaif.studio";function At(){U__default.default.existsSync(de)||U__default.default.mkdirSync(de,{recursive:true});}function Te(t){At(),U__default.default.writeFileSync($,JSON.stringify(t,null,2),"utf-8"),U__default.default.chmodSync($,384);}function S(){if(!U__default.default.existsSync($))return null;try{let t=U__default.default.readFileSync($,"utf-8");return JSON.parse(t)}catch{return null}}function wt(t){let e=Ae__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}function St(t){return new Promise(e=>{let o=Ae__default.default.createInterface({input:process.stdin,output:process.stdout});process.stdin;let s=process.stdout.write.bind(process.stdout),r=false;process.stdout.write=((...i)=>r?true:s(...i)),o.question(t,i=>{r=false,process.stdout.write=s,console.log(""),o.close(),e(i);}),r=true;})}function Et(t){let e=process.platform,o;e==="darwin"?o=`open "${t}"`:e==="win32"?o=`start "" "${t}"`:o=`xdg-open "${t}"`,child_process.exec(o,n=>{});}function xt(t){return new Promise(e=>setTimeout(e,t))}async function _t(t){try{let e=await fetch(`${J}/auth/me`,{headers:{Authorization:`Bearer ${t}`}});if(e.ok){let o=await e.json();return {valid:!0,email:o.user?.email||o.email}}return {valid:!1}}catch{return {valid:false}}}async function Tt(t){let e=H__default.default();e.start("Setting up authentication...");let o,n;try{let a=await fetch(`${J}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});a.ok||(e.fail("Failed to initiate authentication"),console.log(f__default.default.red(`
|
|
3705
3707
|
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let l=await a.json();o=l.code,n=l.url;}catch{e.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
3706
|
-
Could not connect to VAIF API.`)),console.log(f__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(f__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(f__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(f__default.default.white(` ${n}`)),console.log(""),
|
|
3707
|
-
The authentication session expired. Please try again.`)),process.exit(1));continue}let l=await a.json();if(l.ok&&l.accessToken){let c={token:l.accessToken,email:l.user?.email,projectId:t,expiresAt:new Date(Date.now()+l.expiresIn*1e3).toISOString()};
|
|
3708
|
-
Timed out waiting for browser authentication.`)),console.log(f__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function
|
|
3709
|
-
No email provided. Login cancelled.`)),process.exit(1));let o=await
|
|
3710
|
-
No password provided. Login cancelled.`)),process.exit(1));let n=
|
|
3711
|
-
${
|
|
3712
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function
|
|
3713
|
-
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var
|
|
3714
|
-
Error: ${i}`)),process.exit(1);}
|
|
3715
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||
|
|
3716
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3717
|
-
Error: ${l}`)),process.exit(1);}
|
|
3718
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||A__default.default.resolve("vaif.schema.json");
|
|
3719
|
-
Expected schema file at: ${i}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let l=
|
|
3720
|
-
Error: ${l.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:l,sql:c}=await
|
|
3721
|
-
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let d=await
|
|
3722
|
-
Error: ${l.message}`)),process.exit(1);}}var
|
|
3708
|
+
Could not connect to VAIF API.`)),console.log(f__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(f__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(f__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(f__default.default.white(` ${n}`)),console.log(""),Et(n),e.start("Waiting for browser authentication...");let s=12e4,r=2e3,i=Date.now();for(;Date.now()-i<s;){await xt(r);try{let a=await fetch(`${J}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});if(!a.ok){let c=await a.json();(c.error==="ExpiredCode"||c.error==="InvalidCode")&&(e.fail("Authentication expired"),console.log(f__default.default.red(`
|
|
3709
|
+
The authentication session expired. Please try again.`)),process.exit(1));continue}let l=await a.json();if(l.ok&&l.accessToken){let c={token:l.accessToken,email:l.user?.email,projectId:t,expiresAt:new Date(Date.now()+l.expiresIn*1e3).toISOString()};Te(c),e.succeed("Logged in successfully"),console.log(""),l.user?.email&&console.log(f__default.default.green(` Authenticated as: ${l.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(f__default.default.red(`
|
|
3710
|
+
Timed out waiting for browser authentication.`)),console.log(f__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function Ft(t){console.log(""),console.log(f__default.default.bold("VAIF CLI Login")),console.log(f__default.default.gray("Enter your VAIF account credentials")),console.log("");let e=await wt(f__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(f__default.default.red(`
|
|
3711
|
+
No email provided. Login cancelled.`)),process.exit(1));let o=await St(f__default.default.cyan(" Password: "));(!o||o.trim()==="")&&(console.log(f__default.default.red(`
|
|
3712
|
+
No password provided. Login cancelled.`)),process.exit(1));let n=H__default.default("Authenticating...").start();try{let s=await fetch(`${J}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:o})}),r=await s.json();(!s.ok||!r.ok)&&(n.fail("Login failed"),console.log(f__default.default.red(`
|
|
3713
|
+
${r.message||"Invalid email or password."}`)),process.exit(1));let i={token:r.accessToken,email:r.user?.email,projectId:t,expiresAt:new Date(Date.now()+r.expiresIn*1e3).toISOString()};Te(i),n.succeed("Logged in successfully"),console.log(""),r.user?.email&&console.log(f__default.default.green(` Authenticated as: ${r.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");}catch{n.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
3714
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function Fe(t){console.log(""),console.log(f__default.default.bold("Welcome to VAIF CLI")),console.log(f__default.default.gray("Authenticate to access your VAIF projects")),console.log(""),t.email?await Ft(t.projectId):await Tt(t.projectId),console.log(f__default.default.gray("You can now use VAIF CLI commands like:")),console.log(f__default.default.gray(" vaif pull - Pull remote schema")),console.log(f__default.default.gray(" vaif push - Push schema changes")),console.log(f__default.default.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Pe(){U__default.default.existsSync($)?(U__default.default.unlinkSync($),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function je(){let t=S();(!t||!t.token)&&(console.log(f__default.default.yellow("Not logged in")),console.log(f__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=H__default.default("Checking authentication...").start(),{valid:o,email:n}=await _t(t.token);o||(e.fail("Session expired"),console.log(f__default.default.yellow(`
|
|
3715
|
+
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var Ct=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Nt(t,e,o="public"){let n=await fetch(`${Ct}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let s=await n.text();throw new Error(`Failed to fetch schema: ${s}`)}return n.json()}async function Re(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;e.start("Loading configuration...");try{s=await I(n);}catch(i){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3716
|
+
Error: ${i}`)),process.exit(1);}s||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let r=t.projectId||s.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3717
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||s.database?.schema||"public",a=await Nt(o.token,r,i);e.succeed("Schema fetched successfully");let l=t.output||A__default.default.resolve("vaif.schema.json"),c={$schema:"https://vaif.studio/schemas/schema.json",projectId:r,schema:i,pulledAt:new Date().toISOString(),...a};U__default.default.writeFileSync(l,JSON.stringify(c,null,2),"utf-8"),console.log(""),console.log(f__default.default.green(`Schema saved to: ${l}`)),console.log(""),console.log(f__default.default.gray("Schema summary:")),console.log(f__default.default.gray(` Tables: ${(a.tables||[]).length}`)),console.log(f__default.default.gray(` Enums: ${(a.enums||[]).length}`)),console.log(f__default.default.gray(` Functions: ${(a.functions||[]).length}`)),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(f__default.default.gray(" - Edit the schema and run `vaif push` to deploy changes")),console.log("");}catch(i){e.fail("Failed to fetch schema"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3718
|
+
Error: ${i.message}`)),process.exit(1);}}var Ne=process.env.VAIF_API_URL||"https://api.vaif.studio";function Vt(t){let e=Ae__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}async function kt(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let s=await n.text();throw new Error(`Failed to preview changes: ${s}`)}return n.json()}async function $t(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let s=await n.text();throw new Error(`Failed to apply changes: ${s}`)}return n.json()}function Ot(t){if(console.log(""),console.log(f__default.default.bold("Schema Changes:")),console.log(""),t.added.length===0&&t.modified.length===0&&t.removed.length===0){console.log(f__default.default.gray(" No changes detected. Schema is up to date."));return}if(t.added.length>0){console.log(f__default.default.green.bold(" + Added:"));for(let e of t.added)console.log(f__default.default.green(` + ${e.type}: ${e.name}`));console.log("");}if(t.modified.length>0){console.log(f__default.default.yellow.bold(" ~ Modified:"));for(let e of t.modified){console.log(f__default.default.yellow(` ~ ${e.type}: ${e.name}`));for(let o of e.changes)console.log(f__default.default.gray(` ${o}`));}console.log("");}if(t.removed.length>0){console.log(f__default.default.red.bold(" - Removed:"));for(let e of t.removed)console.log(f__default.default.red(` - ${e.type}: ${e.name}`));console.log("");}}async function Le(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;e.start("Loading configuration...");try{s=await I(n);}catch(l){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3719
|
+
Error: ${l}`)),process.exit(1);}s||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let r=t.projectId||s.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3720
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||A__default.default.resolve("vaif.schema.json");U__default.default.existsSync(i)||(e.fail("No local schema found"),console.log(f__default.default.yellow(`
|
|
3721
|
+
Expected schema file at: ${i}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let l=U__default.default.readFileSync(i,"utf-8");a=JSON.parse(l);}catch(l){e.fail("Failed to parse schema file"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3722
|
+
Error: ${l.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:l,sql:c}=await kt(o.token,r,a);if(e.stop(),Ot(l),l.added.length===0&&l.modified.length===0&&l.removed.length===0){console.log("");return}if(c.length>0){console.log(f__default.default.bold("SQL Migrations:")),console.log("");for(let u of c)console.log(f__default.default.gray(` ${u}`));console.log("");}if(t.dryRun){console.log(f__default.default.yellow("Dry run mode - no changes applied.")),console.log(f__default.default.gray("Remove --dry-run to apply these changes."));return}if(!t.force){l.removed.length>0&&(console.log(f__default.default.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(f__default.default.red(" This action cannot be undone!")),console.log(""));let p=await Vt(f__default.default.cyan("Apply these changes? [y/N] "));if(p.toLowerCase()!=="y"&&p.toLowerCase()!=="yes"){console.log(f__default.default.yellow(`
|
|
3723
|
+
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let d=await $t(o.token,r,a);if(d.success){if(e.succeed("Schema changes applied successfully"),console.log(""),d.migrations.length>0){console.log(f__default.default.gray("Migrations applied:"));for(let u of d.migrations)console.log(f__default.default.gray(` - ${u}`));console.log("");}console.log(f__default.default.green("Your database schema is now up to date.")),console.log(f__default.default.gray("Run `vaif generate` to update your TypeScript types.")),console.log("");}else e.fail("Failed to apply some changes");}catch(l){e.fail("Failed to push schema changes"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3724
|
+
Error: ${l.message}`)),process.exit(1);}}var W=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Mt(t,e,o,n){let s=new URL(`${W}/functions/project/${e}`);n&&s.searchParams.set("envId",n);let r=await fetch(s.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!r.ok)return null;let i=await r.json(),a=i.functions||i;return Array.isArray(a)&&a.find(l=>l.name===o)||null}async function zt(t,e,o){let n=await fetch(`${W}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:o.name,runtime:o.runtime,entrypoint:o.entrypoint,envId:o.envId})});if(!n.ok){let s=await n.text();throw new Error(`Failed to create function: ${s}`)}return n.json()}async function Kt(t,e,o){let n=await fetch(`${W}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:o})});if(!n.ok){let s=await n.text();throw new Error(`Failed to deploy source: ${s}`)}}async function Bt(t,e,o){let n=new URL(`${W}/functions/project/${e}`);o&&n.searchParams.set("envId",o);let s=await fetch(n.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!s.ok){let i=await s.text();throw new Error(`Failed to list functions: ${i}`)}let r=await s.json();return r.functions||r}function De(t){switch(A__default.default.extname(t).toLowerCase()){case ".ts":return "typescript";case ".js":case ".mjs":return "nodejs";case ".py":return "python";case ".go":return "go";case ".rs":return "rust";default:return "nodejs"}}function Ue(t){let e=[],o=[".ts",".js",".mjs",".py",".go",".rs"],n=["drizzle.config.ts","tsconfig.json","package.json"];if(!U__default.default.existsSync(t))return e;let s=U__default.default.readdirSync(t,{withFileTypes:true});for(let r of s){let i=A__default.default.join(t,r.name);if(r.isDirectory()){if(r.name!=="node_modules"&&!r.name.startsWith(".")){let a=U__default.default.readdirSync(i,{withFileTypes:true});for(let l of a)if(l.isFile()){let c=A__default.default.extname(l.name).toLowerCase();if(o.includes(c)){e.push(A__default.default.join(i,l.name));break}}}}else if(r.isFile()){let a=A__default.default.extname(r.name).toLowerCase();o.includes(a)&&!n.includes(r.name)&&e.push(i);}}return e}async function ke(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Functions Deploy")),console.log(""),e.start("Scanning for function files...");let i=A__default.default.resolve("functions"),a=A__default.default.resolve("src/functions"),l=[];if(t.entrypoint){let p=A__default.default.resolve(t.entrypoint);U__default.default.existsSync(p)||(e.fail(`File not found: ${t.entrypoint}`),process.exit(1)),l=[p];}else l=[...Ue(i),...Ue(a)];l.length===0&&(e.fail("No function files found"),console.log(f__default.default.yellow(`
|
|
3723
3725
|
Place your functions in:`)),console.log(f__default.default.gray(" - ./functions/")),console.log(f__default.default.gray(" - ./src/functions/")),console.log(f__default.default.gray(`
|
|
3724
|
-
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${l.length} function(s)`),t.name&&(l=l.filter(
|
|
3725
|
-
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let
|
|
3726
|
+
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${l.length} function(s)`),t.name&&(l=l.filter(p=>A__default.default.basename(p,A__default.default.extname(p)).includes(t.name)),l.length===0&&(console.log(f__default.default.yellow(`
|
|
3727
|
+
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let p of l){let m=A__default.default.basename(A__default.default.dirname(p)),y=m==="functions"||m==="src"?A__default.default.basename(p,A__default.default.extname(p)):m,L=t.runtime||De(p);console.log(f__default.default.gray(` - ${y} (${L})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let c=[];for(let p of l){let m=A__default.default.basename(A__default.default.dirname(p)),y=m==="functions"||m==="src"?A__default.default.basename(p,A__default.default.extname(p)):m,L=t.runtime||De(p);e.start(`Deploying ${y}...`);try{let M=U__default.default.readFileSync(p,"utf-8"),z=await Mt(o.token,r,y,t.envId);z||(e.text=`Creating ${y}...`,z=await zt(o.token,r,{name:y,runtime:L,entrypoint:A__default.default.basename(p),envId:t.envId})),e.text=`Deploying ${y}...`,await Kt(o.token,z.id,M),e.succeed(`Deployed ${y}`),c.push({name:y,success:!0});}catch(M){let z=M instanceof Error?M.message:"Unknown error";e.fail(`Failed to deploy ${y}`),c.push({name:y,success:false,error:z});}}console.log("");let d=c.filter(p=>p.success).length;if(c.filter(p=>!p.success).length===0)console.log(f__default.default.green(`\u2713 Successfully deployed ${d} function(s)`));else {console.log(f__default.default.yellow(`Deployed ${d}/${c.length} function(s)`)),console.log(""),console.log(f__default.default.red("Failed deployments:"));for(let p of c.filter(m=>!m.success))console.log(f__default.default.red(` - ${p.name}: ${p.error}`));}console.log("");}async function $e(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let i=await Bt(o.token,r,t.envId);if(e.stop(),i.length===0){console.log(f__default.default.yellow(`
|
|
3726
3728
|
No functions found`)),console.log(f__default.default.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(f__default.default.bold(`Functions (${i.length}):`)),console.log(""),console.log(f__default.default.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(f__default.default.gray(" "+"-".repeat(80)));for(let a of i){let l=a.deployStatus==="deployed"?f__default.default.green:a.deployStatus==="deploying"?f__default.default.yellow:a.deployStatus==="failed"?f__default.default.red:f__default.default.gray;console.log(" "+a.name.padEnd(25)+a.runtime.padEnd(15)+l(a.deployStatus.padEnd(12))+String(a.invocationCount??0).padEnd(14)+(a.deployedAt?new Date(a.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(i){e.fail("Failed to fetch functions"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3727
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3729
|
+
Error: ${i.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function qt(t,e,o,n,s){let r=await fetch(`${X}/v1/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:o,records:n,truncate:s?.truncate??false})});if(!r.ok){let i=await r.text();throw new Error(`Failed to seed ${o}: ${i}`)}return r.json()}async function Yt(t,e){let o=await fetch(`${X}/v1/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let n=await o.text();throw new Error(`Failed to reset database: ${n}`)}return o.json()}function ue(t){let e=[];if(!U__default.default.existsSync(t))return e;let o=U__default.default.readdirSync(t,{withFileTypes:true});for(let n of o)if(n.isFile()){let s=A__default.default.extname(n.name).toLowerCase();(s===".json"||s===".ts"||s===".js")&&e.push(A__default.default.join(t,n.name));}return e.sort()}async function Oe(t){let e=A__default.default.extname(t).toLowerCase();if(e===".json"){let o=U__default.default.readFileSync(t,"utf-8"),n=JSON.parse(o);return Array.isArray(n)?[{table:A__default.default.basename(t,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([s,r])=>({table:s,data:r}))}else if(e===".ts"||e===".js"){let o=await import(t),n=o.default||o;return typeof n=="function"?n():n}throw new Error(`Unsupported file format: ${e}`)}async function Me(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Database Seed")),console.log("");let i=[];if(t.file){let d=A__default.default.resolve(t.file);U__default.default.existsSync(d)||(console.log(f__default.default.red(`File not found: ${t.file}`)),process.exit(1)),i=[d];}else {let d=A__default.default.resolve("seeds"),u=A__default.default.resolve("prisma/seed"),p=A__default.default.resolve("db/seeds");i=[...ue(d),...ue(u),...ue(p)];}i.length===0&&(console.log(f__default.default.yellow("No seed files found")),console.log(f__default.default.gray(`
|
|
3728
3730
|
Place your seed files in one of these directories:`)),console.log(f__default.default.gray(" - ./seeds/")),console.log(f__default.default.gray(" - ./prisma/seed/")),console.log(f__default.default.gray(" - ./db/seeds/")),console.log(f__default.default.gray(`
|
|
3729
3731
|
Or specify a file with --file`)),console.log(f__default.default.gray(`
|
|
3730
|
-
Example seed file (seeds/users.json):`)),console.log(f__default.default.gray(" [")),console.log(f__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f__default.default.gray(" ]")),process.exit(1)),console.log(f__default.default.gray("Seed files found:"));for(let d of i)console.log(f__default.default.gray(` - ${A__default.default.relative(process.cwd(),d)}`));if(console.log(""),t.truncate&&(console.log(f__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let d of i){e.start(`Loading ${A__default.default.basename(d)}...`);try{let
|
|
3732
|
+
Example seed file (seeds/users.json):`)),console.log(f__default.default.gray(" [")),console.log(f__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f__default.default.gray(" ]")),process.exit(1)),console.log(f__default.default.gray("Seed files found:"));for(let d of i)console.log(f__default.default.gray(` - ${A__default.default.relative(process.cwd(),d)}`));if(console.log(""),t.truncate&&(console.log(f__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let d of i){e.start(`Loading ${A__default.default.basename(d)}...`);try{let u=await Oe(d);e.stop();for(let p of u)t.table&&p.table!==t.table||(console.log(f__default.default.cyan(`Table: ${p.table}`)),console.log(f__default.default.gray(` Records: ${p.data.length}`)),p.data.length>0&&console.log(f__default.default.gray(` Sample: ${JSON.stringify(p.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(u){e.fail(`Failed to load ${A__default.default.basename(d)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}return}let a=[];for(let d of i){e.start(`Processing ${A__default.default.basename(d)}...`);try{let u=await Oe(d);e.stop();for(let p of u)if(!(t.table&&p.table!==t.table)){if(p.data.length===0){console.log(f__default.default.gray(` Skipping ${p.table} (no records)`));continue}e.start(`Seeding ${p.table} (${p.data.length} records)...`);try{let m=await qt(o.token,r,p.table,p.data,{truncate:t.truncate});e.succeed(`Seeded ${p.table}: ${m.inserted} records`),a.push({table:p.table,inserted:m.inserted});}catch(m){let y=m instanceof Error?m.message:"Unknown error";e.fail(`Failed to seed ${p.table}`),a.push({table:p.table,inserted:0,error:y});}}}catch(u){e.fail(`Failed to load ${A__default.default.basename(d)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}console.log("");let l=a.reduce((d,u)=>d+u.inserted,0),c=a.filter(d=>d.error).length;if(c===0)console.log(f__default.default.green(`\u2713 Successfully seeded ${l} records across ${a.length} table(s)`));else {console.log(f__default.default.yellow(`Seeded ${l} records with ${c} error(s)`)),console.log(""),console.log(f__default.default.red("Errors:"));for(let d of a.filter(u=>u.error))console.log(f__default.default.red(` - ${d.table}: ${d.error}`));}console.log("");}async function ze(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=A__default.default.resolve(t.dir||"./drizzle");if(console.log(""),console.log(f__default.default.bold("VAIF Database Push")),console.log(""),!U__default.default.existsSync(i)){let u=A__default.default.resolve("./migrations");U__default.default.existsSync(u)?console.log(f__default.default.gray(`Using migrations from: ${u}`)):(console.log(f__default.default.red(`Migrations directory not found: ${i}`)),console.log(f__default.default.gray(`
|
|
3731
3733
|
Expected one of:`)),console.log(f__default.default.gray(" - ./drizzle/")),console.log(f__default.default.gray(" - ./migrations/")),console.log(f__default.default.gray(`
|
|
3732
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],l=
|
|
3733
|
-
Error: ${a.message}`)),process.exit(1);}}async function
|
|
3734
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3735
|
-
Error: ${a.message}`)),process.exit(1);}}async function
|
|
3736
|
-
Generate one with: vaif keys generate`));return}let c=Math.max(8,...l.map(
|
|
3737
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3738
|
-
Error: ${l.message}`)),process.exit(1);}}async function
|
|
3739
|
-
Create one with: vaif secrets set <name> <value>`));return}let l=Math.max(8,...a.map(d=>d.key.length)),c=` ${"Name".padEnd(l)} Created`;console.log(f__default.default.gray(c)),console.log(f__default.default.gray(" "+"-".repeat(c.length-2)));for(let d of a){let
|
|
3740
|
-
Error: ${
|
|
3741
|
-
Error: ${i.message}`)),process.exit(1);}}async function
|
|
3742
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3743
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3744
|
-
Error: ${i.message}`)),process.exit(1);}}commander.program.name("vaif").description("VAIF CLI - Type generation and development tools").version(
|
|
3734
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],l=U__default.default.readdirSync(i,{withFileTypes:true});for(let u of l)if(u.isFile()&&u.name.endsWith(".sql"))a.push(A__default.default.join(i,u.name));else if(u.isDirectory()){let p=U__default.default.readdirSync(A__default.default.join(i,u.name),{withFileTypes:true});for(let m of p)m.isFile()&&m.name.endsWith(".sql")&&a.push(A__default.default.join(i,u.name,m.name));}a.sort(),a.length===0&&(console.log(f__default.default.yellow("No SQL migration files found")),process.exit(1)),console.log(f__default.default.gray(`Found ${a.length} migration(s):`));for(let u of a)console.log(f__default.default.gray(` - ${A__default.default.relative(process.cwd(),u)}`));if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let u of a){let p=U__default.default.readFileSync(u,"utf-8");console.log(f__default.default.cyan(`--- ${A__default.default.basename(u)} ---`)),console.log(f__default.default.gray(p.slice(0,500))),p.length>500&&console.log(f__default.default.gray("...")),console.log("");}return}let c=0,d=0;for(let u of a){let p=U__default.default.readFileSync(u,"utf-8"),m=A__default.default.relative(process.cwd(),u);e.start(`Applying ${m}...`);try{let y=await fetch(`${X}/schema-engine/query/${r}`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:p})});if(!y.ok){let L=await y.text();throw new Error(L)}e.succeed(`Applied ${m}`),c++;}catch(y){let L=y instanceof Error?y.message:"Unknown error";e.fail(`Failed ${m}: ${L}`),d++;}}console.log(""),console.log(d===0?f__default.default.green(`Successfully applied ${c} migration(s)`):f__default.default.yellow(`Applied ${c}, failed ${d} migration(s)`)),console.log("");}async function Ke(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=A__default.default.resolve(t.output||"vaif.schema.json");console.log(""),console.log(f__default.default.bold("VAIF Database Pull")),console.log(""),e.start("Pulling schema from remote...");try{let a=await fetch(`${X}/schema-engine/introspect/${r}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok){let d=await a.text();throw new Error(`Failed to pull schema: ${d}`)}let l=await a.json();U__default.default.writeFileSync(i,JSON.stringify(l,null,2),"utf-8"),e.succeed(`Schema written to ${A__default.default.relative(process.cwd(),i)}`);let c=l.tables?.length??Object.keys(l).length;console.log(f__default.default.gray(` ${c} table(s) pulled`)),console.log("");}catch(a){e.fail("Failed to pull schema"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3735
|
+
Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),console.log(""),console.log(f__default.default.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(f__default.default.red("This will:")),console.log(f__default.default.red(" - Drop all tables")),console.log(f__default.default.red(" - Delete all data")),console.log(f__default.default.red(" - Reset migrations")),console.log(""),console.log(f__default.default.red.bold("This action cannot be undone!")),console.log(""),t.force||(console.log(f__default.default.yellow("Use --force to confirm this action.")),process.exit(1)),e.start("Resetting database...");try{await Yt(o.token,r),e.succeed("Database reset complete"),console.log(""),console.log(f__default.default.gray("Your database is now empty.")),console.log(f__default.default.gray("Run `vaif push` to apply your schema, then `vaif db seed` to seed data.")),console.log("");}catch(i){e.fail("Failed to reset database"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3736
|
+
Error: ${i.message}`)),process.exit(1);}}var Ye=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}async function Je(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=Ge(t,s,o);r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=t.name||`cli-key-${Date.now()}`;console.log(""),console.log(f__default.default.bold("VAIF Generate API Key")),console.log(""),e.start("Generating API key...");try{let a=await fetch(`${Ye}/v1/projects/${r}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:i})});if(!a.ok){let c=await a.text();throw new Error(`Failed to generate key: ${c}`)}let l=await a.json();e.succeed("API key generated"),console.log(""),console.log(f__default.default.green(` Name: ${l.name}`)),console.log(f__default.default.green(` Key: ${l.key}`)),console.log(""),console.log(f__default.default.yellow.bold(" Save this key now - it will not be shown again!")),console.log("");}catch(a){e.fail("Failed to generate API key"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3737
|
+
Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=Ge(t,s,o);r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let i=await fetch(`${Ye}/v1/projects/${r}/api-keys`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let u=await i.text();throw new Error(`Failed to list keys: ${u}`)}let a=await i.json(),l=a.keys||a;if(e.stop(),!Array.isArray(l)||l.length===0){console.log(f__default.default.yellow("No API keys found")),console.log(f__default.default.gray(`
|
|
3738
|
+
Generate one with: vaif keys generate`));return}let c=Math.max(8,...l.map(u=>(u.name||"").length)),d=` ${"Name".padEnd(c)} ${"Key".padEnd(24)} Created`;console.log(f__default.default.gray(d)),console.log(f__default.default.gray(" "+"-".repeat(d.length-2)));for(let u of l){let p=(u.name||"unnamed").padEnd(c),m=u.maskedKey||u.prefix||`${(u.key||"").slice(0,12)}...`,y=u.createdAt?new Date(u.createdAt).toLocaleDateString():"N/A";console.log(` ${p} ${m.padEnd(24)} ${y}`);}console.log(""),console.log(f__default.default.gray(` ${l.length} key(s) total`)),console.log("");}catch(i){e.fail("Failed to list API keys"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3739
|
+
Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function Jt(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}function Z(){let t=S();return (!t||!t.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1)),t}async function ee(t){try{return await I(t||"vaif.config.json")}catch{return null}}function te(t,e,o){let n=Jt(t,e,o);return n||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),n}async function He(t,e,o){let n=H__default.default(),s=Z(),r=await ee(o.config),i=te(o,r,s),a=e;if(o.fromFile)try{a=U__default.default.readFileSync(o.fromFile,"utf-8");}catch(l){console.log(f__default.default.red(`Failed to read file: ${o.fromFile}`)),l instanceof Error&&console.log(f__default.default.gray(l.message)),process.exit(1);}a||(console.log(f__default.default.red("No value provided")),console.log(f__default.default.gray("Provide a value as argument or use --from-file <path>")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Set Secret")),console.log(""),n.start("Checking for existing secret...");try{let l=new URL(`${O}/functions/secrets/project/${i}`);o.envId&&l.searchParams.set("envId",o.envId);let c=await fetch(l.toString(),{headers:{Authorization:`Bearer ${s.token}`}});if(!c.ok)throw new Error(`Failed to check existing secrets: ${await c.text()}`);let u=(await c.json()).find(p=>p.key===t);if(u){n.text=`Updating secret "${t}"...`;let p=await fetch(`${O}/functions/secrets/${u.id}`,{method:"PUT",headers:{Authorization:`Bearer ${s.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:a})});if(!p.ok)throw new Error(`Failed to update secret: ${await p.text()}`);n.succeed(`Updated secret "${t}"`);}else {n.text=`Creating secret "${t}"...`;let p=await fetch(`${O}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${s.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:i,envId:o.envId,key:t,value:a})});if(!p.ok)throw new Error(`Failed to create secret: ${await p.text()}`);n.succeed(`Created secret "${t}"`);}console.log("");}catch(l){n.fail("Failed to set secret"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3740
|
+
Error: ${l.message}`)),process.exit(1);}}async function Xe(t){let e=H__default.default(),o=Z(),n=await ee(t.config),s=te(t,n,o);console.log(""),console.log(f__default.default.bold("VAIF Secrets")),console.log(""),e.start("Fetching secrets...");try{let r=new URL(`${O}/functions/secrets/project/${s}`);t.envId&&r.searchParams.set("envId",t.envId);let i=await fetch(r.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok)throw new Error(`Failed to list secrets: ${await i.text()}`);let a=await i.json();if(e.stop(),a.length===0){console.log(f__default.default.yellow("No secrets found")),console.log(f__default.default.gray(`
|
|
3741
|
+
Create one with: vaif secrets set <name> <value>`));return}let l=Math.max(8,...a.map(d=>d.key.length)),c=` ${"Name".padEnd(l)} Created`;console.log(f__default.default.gray(c)),console.log(f__default.default.gray(" "+"-".repeat(c.length-2)));for(let d of a){let u=d.key.padEnd(l),p=d.createdAt?new Date(d.createdAt).toLocaleDateString():"N/A";console.log(` ${u} ${p}`);}console.log(""),console.log(f__default.default.gray(` ${a.length} secret(s) total`)),console.log(f__default.default.gray(" Values are hidden. Use `vaif secrets get <name>` to reveal.")),console.log("");}catch(r){e.fail("Failed to list secrets"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3742
|
+
Error: ${r.message}`)),process.exit(1);}}async function Qe(t,e){let o=H__default.default(),n=Z(),s=await ee(e.config),r=te(e,s,n);console.log(""),o.start("Fetching secret...");try{let i=new URL(`${O}/functions/secrets/project/${r}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let c=(await a.json()).find(p=>p.key===t);c||(o.fail(`Secret "${t}" not found`),process.exit(1));let d=await fetch(`${O}/functions/secrets/${c.id}/value`,{headers:{Authorization:`Bearer ${n.token}`}});if(!d.ok)throw new Error(`Failed to get secret value: ${await d.text()}`);let u=await d.json();o.stop(),console.log(u.value);}catch(i){o.fail("Failed to get secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3743
|
+
Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=H__default.default(),n=Z(),s=await ee(e.config),r=te(e,s,n);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),o.start("Finding secret...");try{let i=new URL(`${O}/functions/secrets/project/${r}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let c=(await a.json()).find(u=>u.key===t);c||(o.fail(`Secret "${t}" not found`),process.exit(1)),o.text=`Deleting secret "${t}"...`;let d=await fetch(`${O}/functions/secrets/${c.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${n.token}`}});if(!d.ok)throw new Error(`Failed to delete secret: ${await d.text()}`);o.succeed(`Deleted secret "${t}"`),console.log("");}catch(i){o.fail("Failed to delete secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3744
|
+
Error: ${i.message}`)),process.exit(1);}}var et=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ht(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function tt(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project info...");try{let i=await fetch(`${et}/v1/projects/${r}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let d=await i.text();throw new Error(`Failed to fetch project: ${d}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Info")),console.log("");let l=16,c=(d,u)=>{console.log(` ${f__default.default.gray(d.padEnd(l))} ${u}`);};c("Name:",f__default.default.white(a.name||"N/A")),c("Project ID:",f__default.default.white(r)),c("Region:",f__default.default.white(a.region||"us-east-1")),c("Plan:",f__default.default.white(a.plan||a.tier||"free")),c("Created:",f__default.default.white(a.createdAt?new Date(a.createdAt).toLocaleDateString():"N/A")),console.log(""),c("API URL:",f__default.default.cyan(a.apiUrl||`${et}/v1`)),c("WS URL:",f__default.default.cyan(a.wsUrl||a.realtimeUrl||"N/A")),c("DB URL:",f__default.default.cyan(a.databaseUrl?Ht(a.databaseUrl):"N/A")),c("Storage URL:",f__default.default.cyan(a.storageUrl||"N/A")),console.log("");}catch(i){e.fail("Failed to fetch project info"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3745
|
+
Error: ${i.message}`)),process.exit(1);}}var Qt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ot(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",s=null;try{s=await I(n);}catch{}let r=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;r||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project status...");try{let i=await fetch(`${Qt}/v1/projects/${r}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let y=await i.text();throw new Error(`Failed to fetch project status: ${y}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Status")),console.log("");let l=22,c=(y,L)=>{console.log(` ${f__default.default.gray(y.padEnd(l))} ${L}`);};c("Project:",f__default.default.white(a.name||r)),c("Plan:",f__default.default.white(a.plan||a.tier||"free")),console.log(""),console.log(f__default.default.gray(" --- Resources ---")),console.log("");let d=a.tableCount??a.tables?.length??"N/A",u=a.functionCount??a.functions?.length??"N/A",p=a.bucketCount??a.storage?.buckets?.length??"N/A",m=a.activeConnections??a.connections??"N/A";c("Tables:",f__default.default.white(String(d))),c("Functions:",f__default.default.white(String(u))),c("Storage Buckets:",f__default.default.white(String(p))),c("Active Connections:",f__default.default.white(String(m))),a.usage&&(console.log(""),console.log(f__default.default.gray(" --- Usage ---")),console.log(""),a.usage.dbSize&&c("Database Size:",f__default.default.white(a.usage.dbSize)),a.usage.storageSize&&c("Storage Size:",f__default.default.white(a.usage.storageSize)),a.usage.bandwidth&&c("Bandwidth:",f__default.default.white(a.usage.bandwidth)),a.usage.functionInvocations!=null&&c("Function Invocations:",f__default.default.white(String(a.usage.functionInvocations)))),console.log("");}catch(i){e.fail("Failed to fetch project status"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3746
|
+
Error: ${i.message}`)),process.exit(1);}}var nt="1.7.1",fe=f__default.default.hex("#00f0ff"),ge=f__default.default.hex("#7b61ff"),me=f__default.default.hex("#ff3dff"),he=f__default.default.hex("#00ff9d"),w=f__default.default.hex("#555570"),K=f__default.default.hex("#00f0ff");function Zt(){console.log(""),console.log(fe(" \u2566 \u2566")+ge("\u2554\u2550\u2557\u2566")+me("\u2554\u2550\u2557 ")+he("\u2554\u2550\u2557\u2566 \u2566")),console.log(fe(" \u255A\u2557\u2554\u255D")+ge("\u2560\u2550\u2563\u2551")+me("\u2560\u2563 ")+he("\u2551 \u2551 \u2551")),console.log(fe(" \u255A\u255D ")+ge("\u2569 \u2569\u2569")+me("\u255A ")+he("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(w(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(K(" VAIF Studio CLI")+w(` v${nt}`)),console.log(w(" Build full-stack apps at lightning speed")),console.log(w(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(""),console.log(f__default.default.bold(" Quick Start")),console.log(w(" $ ")+K("vaif login")+w(" Authenticate")),console.log(w(" $ ")+K("vaif init -t react-spa")+w(" Scaffold project")),console.log(w(" $ ")+K("vaif db push")+w(" Push migrations")),console.log(w(" $ ")+K("vaif generate")+w(" Generate types")),console.log(w(" $ ")+K("vaif functions deploy")+w(" Deploy functions")),console.log(""),console.log(f__default.default.bold(" Categories")),console.log(w(" auth ")+f__default.default.white("login, logout, whoami")),console.log(w(" project ")+f__default.default.white("init, templates, info, status")),console.log(w(" schema ")+f__default.default.white("pull, push, generate")),console.log(w(" database ")+f__default.default.white("db push, db pull, db seed, db reset")),console.log(w(" deploy ")+f__default.default.white("functions deploy, functions list")),console.log(w(" security ")+f__default.default.white("keys, secrets")),console.log(""),console.log(w(" Run ")+K("vaif <command> --help")+w(" for details")),console.log(w(" Docs: ")+f__default.default.underline("https://docs.vaif.studio")),console.log("");}commander.program.name("vaif").description("VAIF CLI - Type generation and development tools").version(nt);commander.program.command("login").description("Authenticate with VAIF (opens browser)").option("-e, --email","Login with email/password instead of browser").option("-p, --project-id <id>","Default project ID").action(Fe);commander.program.command("logout").description("Log out and remove stored credentials").action(Pe);commander.program.command("whoami").description("Show current authenticated user").action(je);commander.program.command("init").description("Initialize VAIF configuration in your project").option("--typescript","Setup for TypeScript project").option("-f, --force","Overwrite existing config").option("-t, --template <name>","Scaffold from a template (run vaif templates for list)").option("--features <features>","Comma-separated features to include: auth,database,realtime,storage,functions").option("--add-features <features>","Add features to an existing project (requires --template)").action(Ee);commander.program.command("templates").alias("tpl").description("List available project templates").action(Se);commander.program.command("info").description("Show project information (name, region, URLs)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(tt);commander.program.command("status").description("Show project status (tables, functions, storage, connections)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(ot);commander.program.command("pull").description("Pull database schema from your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-o, --output <path>","Output file path","vaif.schema.json").option("-s, --schema <name>","Schema name","public").option("-p, --project-id <id>","Project ID (overrides config)").action(Re);commander.program.command("push").description("Push local schema changes to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-s, --schema <path>","Schema file path","vaif.schema.json").option("-p, --project-id <id>","Project ID (overrides config)").option("--dry-run","Preview changes without applying").option("-f, --force","Apply changes without confirmation").action(Le);commander.program.command("generate").alias("gen").description("Generate TypeScript types from your database schema").option("-c, --connection <url>","Database connection string").option("-o, --output <path>","Output file path","./src/types/database.ts").option("--schema <name>","Schema name","public").option("--config <path>","Config file path","vaif.config.json").option("--dry-run","Preview generated types without writing").action(Ie);var at=commander.program.command("functions").alias("fn").description("Manage serverless functions");at.command("deploy").description("Deploy functions to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").option("-n, --name <name>","Function name filter").option("-r, --runtime <runtime>","Runtime (nodejs, typescript, python)").option("--entrypoint <file>","Specific entrypoint file").option("--dry-run","Preview deployment without deploying").action(ke);at.command("list").alias("ls").description("List deployed functions").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").action($e);var oe=commander.program.command("db").description("Database management commands");oe.command("push").description("Push local Drizzle migrations to VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-d, --dir <path>","Migrations directory","./drizzle").option("--dry-run","Preview without applying").action(ze);oe.command("pull").description("Pull schema from VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-o, --output <path>","Output file","vaif.schema.json").action(Ke);oe.command("seed").description("Seed your database with test data").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --file <path>","Specific seed file").option("-t, --table <name>","Seed specific table only").option("--truncate","Truncate tables before seeding").option("--dry-run","Preview seeding without inserting data").action(Me);oe.command("reset").description("Reset database (drop all tables and data)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --force","Confirm reset (required)").action(Be);var it=commander.program.command("keys").description("Manage API keys");it.command("generate").description("Generate a new API key").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-n, --name <name>","Key name").action(Je);it.command("list").alias("ls").description("List API keys").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(We);var ne=commander.program.command("secrets").alias("sec").description("Manage function secrets");ne.command("set <name> [value]").description("Create or update a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").option("--from-file <path>","Read secret value from a file").action(He);ne.command("list").alias("ls").description("List all secrets (names only)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Xe);ne.command("get <name>").description("Reveal a secret value").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Qe);ne.command("delete <name>").description("Delete a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Ze);process.argv.slice(2).length||(Zt(),process.exit(0));commander.program.parse(process.argv);
|