@vaiftech/cli 1.3.2 → 1.5.0
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 +17 -16
- package/dist/{chunk-7XA2HKEQ.js → chunk-JRB5YVG7.js} +1592 -26
- package/dist/cli.cjs +1626 -60
- package/dist/cli.js +2 -2
- package/dist/index.cjs +1605 -39
- 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';var commander=require('commander'),
|
|
2
|
+
'use strict';var commander=require('commander'),R=require('fs'),I=require('path'),Ke=require('pg'),K=require('ora'),p=require('chalk'),qe=require('prettier'),ze=require('dotenv'),ae=require('readline'),et=require('os'),child_process=require('child_process');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var R__default=/*#__PURE__*/_interopDefault(R);var I__default=/*#__PURE__*/_interopDefault(I);var Ke__default=/*#__PURE__*/_interopDefault(Ke);var K__default=/*#__PURE__*/_interopDefault(K);var p__default=/*#__PURE__*/_interopDefault(p);var qe__default=/*#__PURE__*/_interopDefault(qe);var ze__default=/*#__PURE__*/_interopDefault(ze);var ae__default=/*#__PURE__*/_interopDefault(ae);var et__default=/*#__PURE__*/_interopDefault(et);ze__default.default.config();async function A(t){let e=I__default.default.resolve(t);if(!R__default.default.existsSync(e))return null;try{let o=R__default.default.readFileSync(e,"utf-8"),n=JSON.parse(o);return n.database?.url&&(n.database.url=te(n.database.url)),n.api?.apiKey&&(n.api.apiKey=te(n.api.apiKey)),n}catch{throw new Error(`Failed to parse config file: ${t}`)}}function te(t){return t.replace(/\$\{([^}]+)\}/g,(e,o)=>process.env[o]||e)}async function Ye(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]),r=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]),s=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]),
|
|
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 s.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:r.rows}}var G={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 Ge(t,e){let{data_type:o,udt_name:n,is_nullable:r}=t;if(e.has(n)){let a=e.get(n).map(l=>`"${l}"`).join(" | ");return r==="YES"?`(${a}) | null`:a}if(o==="ARRAY"){let i=n.replace(/^_/,"");if(e.has(i)){let c=e.get(i).map(u=>`"${u}"`).join(" | ");return r==="YES"?`(${c})[] | null`:`(${c})[]`}let a=G[i]||"unknown";return r==="YES"?`${a}[] | null`:`${a}[]`}let s=G[o]||G[n]||"unknown";return r==="YES"&&(s=`${s} | null`),s}function J(t){return t.split(/[_\-\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function Je(t,e){let o=J(t),n=e.map(r=>` | "${r}"`).join(`
|
|
49
49
|
`);return `export type ${o} =
|
|
50
|
-
${n};`}function
|
|
51
|
-
${
|
|
50
|
+
${n};`}function He(t,e,o){let n=J(t),r=[],s=[],i=[];for(let u of e){let f=Ge(u,o),d=u.column_name,m=u.column_default!==null||u.is_identity==="YES",b=u.is_nullable==="YES";r.push(` ${d}: ${f};`),m||u.column_name==="id"?s.push(` ${d}?: ${f.replace(" | null","")} | null;`):b?s.push(` ${d}?: ${f};`):s.push(` ${d}: ${f.replace(" | null","")};`),i.push(` ${d}?: ${f.replace(" | null","")} | null;`);}let a=`export interface ${n} {
|
|
51
|
+
${r.join(`
|
|
52
52
|
`)}
|
|
53
|
-
}`,
|
|
54
|
-
${
|
|
53
|
+
}`,l=`export interface ${n}Insert {
|
|
54
|
+
${s.join(`
|
|
55
55
|
`)}
|
|
56
56
|
}`,c=`export interface ${n}Update {
|
|
57
|
-
${
|
|
57
|
+
${i.join(`
|
|
58
58
|
`)}
|
|
59
|
-
}`;return {base:
|
|
60
|
-
`)}async function
|
|
61
|
-
Provide a connection string via:`)),console.log(
|
|
62
|
-
Error: ${o.message}`)),o.message.includes("ECONNREFUSED")&&console.log(
|
|
63
|
-
Make sure your database is running and accessible.`))),process.exit(1);}}var
|
|
59
|
+
}`;return {base:a,insert:l,update:c}}function We(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[s,i]of e)n.push(Je(s,i)),n.push("");}n.push("// ============ TABLES ============"),n.push("");let r=[];for(let[s,i]of t){let{base:a,insert:l,update:c}=He(s,i,e);r.push(s),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 s of r){let i=J(s);n.push(` ${s}: {`),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 ne(t){let e=K__default.default("Loading configuration...").start();try{let o=await A(t.config),n=t.connection||o?.database?.url||process.env.DATABASE_URL;n||(e.fail("No database connection string provided"),console.log(p__default.default.yellow(`
|
|
61
|
+
Provide a connection string via:`)),console.log(p__default.default.gray(" --connection <url>")),console.log(p__default.default.gray(" DATABASE_URL environment variable")),console.log(p__default.default.gray(" vaif.config.json database.url")),process.exit(1)),e.text="Connecting to database...";let r=new Ke__default.default.Client({connectionString:n});await r.connect(),e.text="Introspecting schema...";let{tables:s,enums:i,foreignKeys:a}=await Ye(r,t.schema);if(await r.end(),s.size===0){e.warn(`No tables found in schema "${t.schema}"`);return}e.text=`Generating types for ${s.size} tables...`;let l=We(s,i,a),c=await qe__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(p__default.default.gray("\u2500".repeat(60))),console.log(c),console.log(p__default.default.gray("\u2500".repeat(60)));return}let u=I__default.default.resolve(t.output),f=I__default.default.dirname(u);R__default.default.existsSync(f)||R__default.default.mkdirSync(f,{recursive:!0}),R__default.default.writeFileSync(u,c,"utf-8"),e.succeed(`Generated types for ${s.size} tables \u2192 ${p__default.default.cyan(t.output)}`),console.log(""),console.log(p__default.default.green("Generated:")),console.log(p__default.default.gray(` Tables: ${s.size}`)),console.log(p__default.default.gray(` Enums: ${i.size}`)),console.log(""),console.log(p__default.default.gray("Import in your code:")),console.log(p__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(p__default.default.red(`
|
|
62
|
+
Error: ${o.message}`)),o.message.includes("ECONNREFUSED")&&console.log(p__default.default.yellow(`
|
|
63
|
+
Make sure your database is running and accessible.`))),process.exit(1);}}var k=[{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"}],ie={"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",
|
|
@@ -179,6 +179,101 @@ out
|
|
|
179
179
|
.env
|
|
180
180
|
.env.local
|
|
181
181
|
*.local
|
|
182
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 Next.js Full-Stack
|
|
183
|
+
|
|
184
|
+
A full-stack Next.js application powered by [VAIF Studio](https://vaif.studio), with server and client VAIF clients, auth middleware, and React hooks.
|
|
185
|
+
|
|
186
|
+
## Prerequisites
|
|
187
|
+
|
|
188
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
189
|
+
- npm (included with Node.js)
|
|
190
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
191
|
+
|
|
192
|
+
## Setup
|
|
193
|
+
|
|
194
|
+
1. **Install dependencies**
|
|
195
|
+
|
|
196
|
+
\\\`\\\`\\\`bash
|
|
197
|
+
npm install
|
|
198
|
+
\\\`\\\`\\\`
|
|
199
|
+
|
|
200
|
+
2. **Configure credentials**
|
|
201
|
+
|
|
202
|
+
Copy the example environment file and fill in your project values:
|
|
203
|
+
|
|
204
|
+
\\\`\\\`\\\`bash
|
|
205
|
+
cp .env.local.example .env.local
|
|
206
|
+
\\\`\\\`\\\`
|
|
207
|
+
|
|
208
|
+
Get your Project ID, API Key, and Secret Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
209
|
+
|
|
210
|
+
3. **Install and log in to the VAIF CLI**
|
|
211
|
+
|
|
212
|
+
\\\`\\\`\\\`bash
|
|
213
|
+
npm install -g @vaiftech/cli
|
|
214
|
+
vaif login
|
|
215
|
+
\\\`\\\`\\\`
|
|
216
|
+
|
|
217
|
+
4. **Pull your database schema**
|
|
218
|
+
|
|
219
|
+
\\\`\\\`\\\`bash
|
|
220
|
+
vaif pull
|
|
221
|
+
\\\`\\\`\\\`
|
|
222
|
+
|
|
223
|
+
5. **Push database migrations** (if using the database feature)
|
|
224
|
+
|
|
225
|
+
\\\`\\\`\\\`bash
|
|
226
|
+
vaif db push
|
|
227
|
+
\\\`\\\`\\\`
|
|
228
|
+
|
|
229
|
+
6. **Deploy serverless functions** (if using the functions feature)
|
|
230
|
+
|
|
231
|
+
\\\`\\\`\\\`bash
|
|
232
|
+
vaif functions deploy
|
|
233
|
+
\\\`\\\`\\\`
|
|
234
|
+
|
|
235
|
+
7. **Generate TypeScript types**
|
|
236
|
+
|
|
237
|
+
\\\`\\\`\\\`bash
|
|
238
|
+
vaif generate
|
|
239
|
+
\\\`\\\`\\\`
|
|
240
|
+
|
|
241
|
+
8. **Run the development server**
|
|
242
|
+
|
|
243
|
+
\\\`\\\`\\\`bash
|
|
244
|
+
npm run dev
|
|
245
|
+
\\\`\\\`\\\`
|
|
246
|
+
|
|
247
|
+
Open [http://localhost:3000](http://localhost:3000) in your browser.
|
|
248
|
+
|
|
249
|
+
## Project Structure
|
|
250
|
+
|
|
251
|
+
\\\`\\\`\\\`
|
|
252
|
+
.
|
|
253
|
+
\u251C\u2500\u2500 app/
|
|
254
|
+
\u2502 \u251C\u2500\u2500 layout.tsx # Root layout with VaifProvider
|
|
255
|
+
\u2502 \u251C\u2500\u2500 page.tsx # Home page
|
|
256
|
+
\u2502 \u2514\u2500\u2500 globals.css # Global styles
|
|
257
|
+
\u251C\u2500\u2500 lib/
|
|
258
|
+
\u2502 \u2514\u2500\u2500 vaif.ts # Browser + server VAIF client setup
|
|
259
|
+
\u251C\u2500\u2500 .env.local.example # Environment variable template
|
|
260
|
+
\u251C\u2500\u2500 next.config.ts # Next.js configuration
|
|
261
|
+
\u251C\u2500\u2500 tsconfig.json # TypeScript configuration
|
|
262
|
+
\u2514\u2500\u2500 package.json
|
|
263
|
+
\\\`\\\`\\\`
|
|
264
|
+
|
|
265
|
+
## Available Scripts
|
|
266
|
+
|
|
267
|
+
| Command | Description |
|
|
268
|
+
| ---------------- | --------------------------- |
|
|
269
|
+
| \\\`npm run dev\\\` | Start development server |
|
|
270
|
+
| \\\`npm run build\\\` | Create production build |
|
|
271
|
+
| \\\`npm run start\\\` | Start production server |
|
|
272
|
+
| \\\`npm run lint\\\` | Run ESLint |
|
|
273
|
+
|
|
274
|
+
## Documentation
|
|
275
|
+
|
|
276
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
182
277
|
`}],featureFiles:{auth:[{path:"middleware.ts",content:`import { NextResponse, type NextRequest } from "next/server";
|
|
183
278
|
import { createServerClient } from "@vaiftech/client/server";
|
|
184
279
|
import { authMiddleware } from "@vaiftech/auth/nextjs";
|
|
@@ -386,6 +481,55 @@ export function useRealtime<T extends { id: string }>({
|
|
|
386
481
|
|
|
387
482
|
return { data, refresh };
|
|
388
483
|
}
|
|
484
|
+
`}],database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
485
|
+
-- Customize this schema for your project
|
|
486
|
+
|
|
487
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
488
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
489
|
+
"email" text NOT NULL UNIQUE,
|
|
490
|
+
"name" text,
|
|
491
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
495
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
496
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
497
|
+
"title" text NOT NULL,
|
|
498
|
+
"content" text,
|
|
499
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
500
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
501
|
+
);
|
|
502
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
503
|
+
|
|
504
|
+
export default defineConfig({
|
|
505
|
+
schema: "./src/db/schema.ts",
|
|
506
|
+
out: "./drizzle",
|
|
507
|
+
dialect: "postgresql",
|
|
508
|
+
dbCredentials: {
|
|
509
|
+
url: process.env.DATABASE_URL!,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
513
|
+
|
|
514
|
+
export const users = pgTable("users", {
|
|
515
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
516
|
+
email: text("email").notNull().unique(),
|
|
517
|
+
name: text("name"),
|
|
518
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
export const posts = pgTable("posts", {
|
|
522
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
523
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
524
|
+
title: text("title").notNull(),
|
|
525
|
+
content: text("content"),
|
|
526
|
+
published: boolean("published").notNull().default(false),
|
|
527
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
528
|
+
});
|
|
529
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
530
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
531
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
532
|
+
}
|
|
389
533
|
`}]},dependencies:["@vaiftech/client","@vaiftech/auth","@vaiftech/react","next","react","react-dom"],devDependencies:["@types/node","@types/react","@types/react-dom","typescript"],postInstructions:["cd my-vaif-app","npm install","# Copy .env.local.example to .env.local and add your VAIF credentials","npm run dev"]},"react-spa":{name:"React SPA",description:"Single-page React app with Vite, VAIF client, and provider wrapper",tag:"React + Vite",defaultFeatures:["database","auth"],files:[{path:"package.json",content:`{
|
|
390
534
|
"name": "my-vaif-app",
|
|
391
535
|
"private": true,
|
|
@@ -520,6 +664,99 @@ dist
|
|
|
520
664
|
.env
|
|
521
665
|
.env.local
|
|
522
666
|
*.local
|
|
667
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 React SPA
|
|
668
|
+
|
|
669
|
+
A single-page React application built with [Vite](https://vite.dev/) and powered by [VAIF Studio](https://vaif.studio).
|
|
670
|
+
|
|
671
|
+
## Prerequisites
|
|
672
|
+
|
|
673
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
674
|
+
- npm (included with Node.js)
|
|
675
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
676
|
+
|
|
677
|
+
## Setup
|
|
678
|
+
|
|
679
|
+
1. **Install dependencies**
|
|
680
|
+
|
|
681
|
+
\\\`\\\`\\\`bash
|
|
682
|
+
npm install
|
|
683
|
+
\\\`\\\`\\\`
|
|
684
|
+
|
|
685
|
+
2. **Configure credentials**
|
|
686
|
+
|
|
687
|
+
\\\`\\\`\\\`bash
|
|
688
|
+
cp .env.example .env
|
|
689
|
+
\\\`\\\`\\\`
|
|
690
|
+
|
|
691
|
+
Get your Project ID and API Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
692
|
+
|
|
693
|
+
3. **Install and log in to the VAIF CLI**
|
|
694
|
+
|
|
695
|
+
\\\`\\\`\\\`bash
|
|
696
|
+
npm install -g @vaiftech/cli
|
|
697
|
+
vaif login
|
|
698
|
+
\\\`\\\`\\\`
|
|
699
|
+
|
|
700
|
+
4. **Pull your database schema**
|
|
701
|
+
|
|
702
|
+
\\\`\\\`\\\`bash
|
|
703
|
+
vaif pull
|
|
704
|
+
\\\`\\\`\\\`
|
|
705
|
+
|
|
706
|
+
5. **Push database migrations** (if using the database feature)
|
|
707
|
+
|
|
708
|
+
\\\`\\\`\\\`bash
|
|
709
|
+
vaif db push
|
|
710
|
+
\\\`\\\`\\\`
|
|
711
|
+
|
|
712
|
+
6. **Deploy serverless functions** (if using the functions feature)
|
|
713
|
+
|
|
714
|
+
\\\`\\\`\\\`bash
|
|
715
|
+
vaif functions deploy
|
|
716
|
+
\\\`\\\`\\\`
|
|
717
|
+
|
|
718
|
+
7. **Generate TypeScript types**
|
|
719
|
+
|
|
720
|
+
\\\`\\\`\\\`bash
|
|
721
|
+
vaif generate
|
|
722
|
+
\\\`\\\`\\\`
|
|
723
|
+
|
|
724
|
+
8. **Run the development server**
|
|
725
|
+
|
|
726
|
+
\\\`\\\`\\\`bash
|
|
727
|
+
npm run dev
|
|
728
|
+
\\\`\\\`\\\`
|
|
729
|
+
|
|
730
|
+
Open the URL shown in your terminal (usually [http://localhost:5173](http://localhost:5173)).
|
|
731
|
+
|
|
732
|
+
## Project Structure
|
|
733
|
+
|
|
734
|
+
\\\`\\\`\\\`
|
|
735
|
+
.
|
|
736
|
+
\u251C\u2500\u2500 src/
|
|
737
|
+
\u2502 \u251C\u2500\u2500 App.tsx # Root component with routes
|
|
738
|
+
\u2502 \u251C\u2500\u2500 main.tsx # Entry point with VaifProvider
|
|
739
|
+
\u2502 \u251C\u2500\u2500 lib/
|
|
740
|
+
\u2502 \u2502 \u2514\u2500\u2500 vaif.ts # VAIF client setup
|
|
741
|
+
\u2502 \u2514\u2500\u2500 vite-env.d.ts # Vite environment types
|
|
742
|
+
\u251C\u2500\u2500 index.html # HTML entry point
|
|
743
|
+
\u251C\u2500\u2500 vite.config.ts # Vite configuration
|
|
744
|
+
\u251C\u2500\u2500 tsconfig.json # TypeScript configuration
|
|
745
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
746
|
+
\u2514\u2500\u2500 package.json
|
|
747
|
+
\\\`\\\`\\\`
|
|
748
|
+
|
|
749
|
+
## Available Scripts
|
|
750
|
+
|
|
751
|
+
| Command | Description |
|
|
752
|
+
| -------------------- | ------------------------------ |
|
|
753
|
+
| \\\`npm run dev\\\` | Start development server |
|
|
754
|
+
| \\\`npm run build\\\` | Create production build |
|
|
755
|
+
| \\\`npm run preview\\\` | Preview production build |
|
|
756
|
+
|
|
757
|
+
## Documentation
|
|
758
|
+
|
|
759
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
523
760
|
`}],featureFiles:{auth:[{path:"src/pages/Login.tsx",content:`import { useState } from "react";
|
|
524
761
|
import { useNavigate } from "react-router-dom";
|
|
525
762
|
import { vaif } from "../lib/vaif";
|
|
@@ -753,6 +990,55 @@ export function useRealtimeSubscription<T extends { id: string }>({
|
|
|
753
990
|
|
|
754
991
|
return { data, refresh };
|
|
755
992
|
}
|
|
993
|
+
`}],database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
994
|
+
-- Customize this schema for your project
|
|
995
|
+
|
|
996
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
997
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
998
|
+
"email" text NOT NULL UNIQUE,
|
|
999
|
+
"name" text,
|
|
1000
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
1001
|
+
);
|
|
1002
|
+
|
|
1003
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
1004
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1005
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
1006
|
+
"title" text NOT NULL,
|
|
1007
|
+
"content" text,
|
|
1008
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
1009
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
1010
|
+
);
|
|
1011
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
1012
|
+
|
|
1013
|
+
export default defineConfig({
|
|
1014
|
+
schema: "./src/db/schema.ts",
|
|
1015
|
+
out: "./drizzle",
|
|
1016
|
+
dialect: "postgresql",
|
|
1017
|
+
dbCredentials: {
|
|
1018
|
+
url: process.env.DATABASE_URL!,
|
|
1019
|
+
},
|
|
1020
|
+
});
|
|
1021
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
1022
|
+
|
|
1023
|
+
export const users = pgTable("users", {
|
|
1024
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
1025
|
+
email: text("email").notNull().unique(),
|
|
1026
|
+
name: text("name"),
|
|
1027
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
export const posts = pgTable("posts", {
|
|
1031
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
1032
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
1033
|
+
title: text("title").notNull(),
|
|
1034
|
+
content: text("content"),
|
|
1035
|
+
published: boolean("published").notNull().default(false),
|
|
1036
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1037
|
+
});
|
|
1038
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
1039
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
1040
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
1041
|
+
}
|
|
756
1042
|
`}]},dependencies:["@vaiftech/client","@vaiftech/react","react","react-dom","react-router-dom"],devDependencies:["@types/react","@types/react-dom","@vitejs/plugin-react","typescript","vite"],postInstructions:["cd my-vaif-app","npm install","# Copy .env.example to .env and add your VAIF credentials","npm run dev"]},"ios-swift-app":{name:"iOS Swift App",description:"Swift client manager for iOS/macOS apps using Swift Package Manager",tag:"Swift / iOS",defaultFeatures:["database","auth"],files:[{path:"VaifManager.swift",content:`import Foundation
|
|
757
1043
|
import VaifClient
|
|
758
1044
|
|
|
@@ -859,6 +1145,102 @@ Run the VAIF CLI to generate Swift models from your schema:
|
|
|
859
1145
|
\`\`\`bash
|
|
860
1146
|
npx @vaiftech/cli generate --output ./Models/Database.swift --lang swift
|
|
861
1147
|
\`\`\`
|
|
1148
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 iOS Swift
|
|
1149
|
+
|
|
1150
|
+
An iOS/macOS application powered by [VAIF Studio](https://vaif.studio), using the VaifClient Swift package.
|
|
1151
|
+
|
|
1152
|
+
## Prerequisites
|
|
1153
|
+
|
|
1154
|
+
- Xcode 15 or later
|
|
1155
|
+
- iOS 17+ / macOS 14+ deployment target
|
|
1156
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
1157
|
+
- (Optional) VAIF CLI for type generation: \\\`npm install -g @vaiftech/cli\\\`
|
|
1158
|
+
|
|
1159
|
+
## Setup
|
|
1160
|
+
|
|
1161
|
+
1. **Add the Swift Package**
|
|
1162
|
+
|
|
1163
|
+
In Xcode: **File > Add Package Dependencies...**
|
|
1164
|
+
|
|
1165
|
+
Enter the repository URL:
|
|
1166
|
+
|
|
1167
|
+
\\\`\\\`\\\`
|
|
1168
|
+
https://github.com/vaif-technologies/vaif-swift
|
|
1169
|
+
\\\`\\\`\\\`
|
|
1170
|
+
|
|
1171
|
+
Select the **VaifClient** library and add it to your target.
|
|
1172
|
+
|
|
1173
|
+
2. **Configure credentials**
|
|
1174
|
+
|
|
1175
|
+
Add your project credentials to your Xcode scheme:
|
|
1176
|
+
|
|
1177
|
+
- **Edit Scheme > Run > Arguments > Environment Variables**
|
|
1178
|
+
- Add \\\`VAIF_PROJECT_ID\\\` and \\\`VAIF_API_KEY\\\`
|
|
1179
|
+
|
|
1180
|
+
Alternatively, add them to **Info.plist**:
|
|
1181
|
+
|
|
1182
|
+
\\\`\\\`\\\`xml
|
|
1183
|
+
<key>VAIF_PROJECT_ID</key>
|
|
1184
|
+
<string>your-project-id</string>
|
|
1185
|
+
<key>VAIF_API_KEY</key>
|
|
1186
|
+
<string>your-anon-key</string>
|
|
1187
|
+
\\\`\\\`\\\`
|
|
1188
|
+
|
|
1189
|
+
Get your credentials from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
1190
|
+
|
|
1191
|
+
3. **Install and log in to the VAIF CLI** (for type generation)
|
|
1192
|
+
|
|
1193
|
+
\\\`\\\`\\\`bash
|
|
1194
|
+
npm install -g @vaiftech/cli
|
|
1195
|
+
vaif login
|
|
1196
|
+
\\\`\\\`\\\`
|
|
1197
|
+
|
|
1198
|
+
4. **Pull your database schema**
|
|
1199
|
+
|
|
1200
|
+
\\\`\\\`\\\`bash
|
|
1201
|
+
vaif pull
|
|
1202
|
+
\\\`\\\`\\\`
|
|
1203
|
+
|
|
1204
|
+
5. **Generate Swift models**
|
|
1205
|
+
|
|
1206
|
+
\\\`\\\`\\\`bash
|
|
1207
|
+
vaif generate --output ./Models/Database.swift --lang swift
|
|
1208
|
+
\\\`\\\`\\\`
|
|
1209
|
+
|
|
1210
|
+
6. **Build and run**
|
|
1211
|
+
|
|
1212
|
+
Press **Cmd+R** in Xcode or run from the command line:
|
|
1213
|
+
|
|
1214
|
+
\\\`\\\`\\\`bash
|
|
1215
|
+
xcodebuild -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 16'
|
|
1216
|
+
\\\`\\\`\\\`
|
|
1217
|
+
|
|
1218
|
+
## Project Structure
|
|
1219
|
+
|
|
1220
|
+
\\\`\\\`\\\`
|
|
1221
|
+
.
|
|
1222
|
+
\u251C\u2500\u2500 VaifManager.swift # Singleton VAIF client manager
|
|
1223
|
+
\u251C\u2500\u2500 .env.example # Environment variable reference
|
|
1224
|
+
\u2514\u2500\u2500 README-VAIF.md # Additional VAIF setup notes
|
|
1225
|
+
\\\`\\\`\\\`
|
|
1226
|
+
|
|
1227
|
+
## Usage
|
|
1228
|
+
|
|
1229
|
+
\\\`\\\`\\\`swift
|
|
1230
|
+
import SwiftUI
|
|
1231
|
+
|
|
1232
|
+
struct ContentView: View {
|
|
1233
|
+
@StateObject private var vaif = VaifManager.shared
|
|
1234
|
+
|
|
1235
|
+
var body: some View {
|
|
1236
|
+
Text("Connected to VAIF")
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
\\\`\\\`\\\`
|
|
1240
|
+
|
|
1241
|
+
## Documentation
|
|
1242
|
+
|
|
1243
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
862
1244
|
`}],postInstructions:["Add the VaifClient Swift package from https://github.com/vaif-technologies/vaif-swift","Add VAIF_PROJECT_ID and VAIF_API_KEY to your Xcode scheme environment","See README-VAIF.md for full setup instructions"]},"expo-mobile-app":{name:"Expo Mobile App",description:"React Native / Expo app with VAIF client configured for mobile",tag:"Expo / React Native",defaultFeatures:["database","auth"],files:[{path:"package.json",content:`{
|
|
863
1245
|
"name": "my-vaif-app",
|
|
864
1246
|
"version": "0.1.0",
|
|
@@ -939,6 +1321,99 @@ EXPO_PUBLIC_VAIF_API_KEY=your-anon-key
|
|
|
939
1321
|
.expo
|
|
940
1322
|
dist
|
|
941
1323
|
.env
|
|
1324
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 Expo Mobile
|
|
1325
|
+
|
|
1326
|
+
A React Native / Expo mobile application powered by [VAIF Studio](https://vaif.studio), with Expo Router and native async storage.
|
|
1327
|
+
|
|
1328
|
+
## Prerequisites
|
|
1329
|
+
|
|
1330
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
1331
|
+
- npm (included with Node.js)
|
|
1332
|
+
- [Expo CLI](https://docs.expo.dev/get-started/installation/) (\\\`npx expo\\\`)
|
|
1333
|
+
- iOS Simulator (macOS) or Android Emulator, or the Expo Go app on your device
|
|
1334
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
1335
|
+
|
|
1336
|
+
## Setup
|
|
1337
|
+
|
|
1338
|
+
1. **Install dependencies**
|
|
1339
|
+
|
|
1340
|
+
\\\`\\\`\\\`bash
|
|
1341
|
+
npm install
|
|
1342
|
+
\\\`\\\`\\\`
|
|
1343
|
+
|
|
1344
|
+
2. **Configure credentials**
|
|
1345
|
+
|
|
1346
|
+
\\\`\\\`\\\`bash
|
|
1347
|
+
cp .env.example .env
|
|
1348
|
+
\\\`\\\`\\\`
|
|
1349
|
+
|
|
1350
|
+
Get your Project ID and API Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
1351
|
+
|
|
1352
|
+
3. **Install and log in to the VAIF CLI**
|
|
1353
|
+
|
|
1354
|
+
\\\`\\\`\\\`bash
|
|
1355
|
+
npm install -g @vaiftech/cli
|
|
1356
|
+
vaif login
|
|
1357
|
+
\\\`\\\`\\\`
|
|
1358
|
+
|
|
1359
|
+
4. **Pull your database schema**
|
|
1360
|
+
|
|
1361
|
+
\\\`\\\`\\\`bash
|
|
1362
|
+
vaif pull
|
|
1363
|
+
\\\`\\\`\\\`
|
|
1364
|
+
|
|
1365
|
+
5. **Push database migrations** (if using the database feature)
|
|
1366
|
+
|
|
1367
|
+
\\\`\\\`\\\`bash
|
|
1368
|
+
vaif db push
|
|
1369
|
+
\\\`\\\`\\\`
|
|
1370
|
+
|
|
1371
|
+
6. **Deploy serverless functions** (if using the functions feature)
|
|
1372
|
+
|
|
1373
|
+
\\\`\\\`\\\`bash
|
|
1374
|
+
vaif functions deploy
|
|
1375
|
+
\\\`\\\`\\\`
|
|
1376
|
+
|
|
1377
|
+
7. **Generate TypeScript types**
|
|
1378
|
+
|
|
1379
|
+
\\\`\\\`\\\`bash
|
|
1380
|
+
vaif generate
|
|
1381
|
+
\\\`\\\`\\\`
|
|
1382
|
+
|
|
1383
|
+
8. **Start the development server**
|
|
1384
|
+
|
|
1385
|
+
\\\`\\\`\\\`bash
|
|
1386
|
+
npx expo start
|
|
1387
|
+
\\\`\\\`\\\`
|
|
1388
|
+
|
|
1389
|
+
Scan the QR code with Expo Go, or press \\\`i\\\` for iOS Simulator / \\\`a\\\` for Android Emulator.
|
|
1390
|
+
|
|
1391
|
+
## Project Structure
|
|
1392
|
+
|
|
1393
|
+
\\\`\\\`\\\`
|
|
1394
|
+
.
|
|
1395
|
+
\u251C\u2500\u2500 app/
|
|
1396
|
+
\u2502 \u251C\u2500\u2500 _layout.tsx # Root layout with VaifProvider
|
|
1397
|
+
\u2502 \u2514\u2500\u2500 index.tsx # Home screen
|
|
1398
|
+
\u251C\u2500\u2500 lib/
|
|
1399
|
+
\u2502 \u2514\u2500\u2500 vaif.ts # Expo VAIF client setup
|
|
1400
|
+
\u251C\u2500\u2500 app.json # Expo configuration
|
|
1401
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
1402
|
+
\u2514\u2500\u2500 package.json
|
|
1403
|
+
\\\`\\\`\\\`
|
|
1404
|
+
|
|
1405
|
+
## Available Scripts
|
|
1406
|
+
|
|
1407
|
+
| Command | Description |
|
|
1408
|
+
| -------------------------- | --------------------------------- |
|
|
1409
|
+
| \\\`npx expo start\\\` | Start Expo development server |
|
|
1410
|
+
| \\\`npx expo start --ios\\\` | Start on iOS Simulator |
|
|
1411
|
+
| \\\`npx expo start --android\\\`| Start on Android Emulator |
|
|
1412
|
+
| \\\`npx expo start --web\\\` | Start in web browser |
|
|
1413
|
+
|
|
1414
|
+
## Documentation
|
|
1415
|
+
|
|
1416
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
942
1417
|
`}],featureFiles:{auth:[{path:"app/(auth)/login.tsx",content:`import { useState } from "react";
|
|
943
1418
|
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert } from "react-native";
|
|
944
1419
|
import { useRouter } from "expo-router";
|
|
@@ -1104,6 +1579,55 @@ export function useRealtimeMessages(channelId: string) {
|
|
|
1104
1579
|
|
|
1105
1580
|
return { messages, loading, refresh };
|
|
1106
1581
|
}
|
|
1582
|
+
`}],database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
1583
|
+
-- Customize this schema for your project
|
|
1584
|
+
|
|
1585
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
1586
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1587
|
+
"email" text NOT NULL UNIQUE,
|
|
1588
|
+
"name" text,
|
|
1589
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
1590
|
+
);
|
|
1591
|
+
|
|
1592
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
1593
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1594
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
1595
|
+
"title" text NOT NULL,
|
|
1596
|
+
"content" text,
|
|
1597
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
1598
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
1599
|
+
);
|
|
1600
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
1601
|
+
|
|
1602
|
+
export default defineConfig({
|
|
1603
|
+
schema: "./src/db/schema.ts",
|
|
1604
|
+
out: "./drizzle",
|
|
1605
|
+
dialect: "postgresql",
|
|
1606
|
+
dbCredentials: {
|
|
1607
|
+
url: process.env.DATABASE_URL!,
|
|
1608
|
+
},
|
|
1609
|
+
});
|
|
1610
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
1611
|
+
|
|
1612
|
+
export const users = pgTable("users", {
|
|
1613
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
1614
|
+
email: text("email").notNull().unique(),
|
|
1615
|
+
name: text("name"),
|
|
1616
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1617
|
+
});
|
|
1618
|
+
|
|
1619
|
+
export const posts = pgTable("posts", {
|
|
1620
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
1621
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
1622
|
+
title: text("title").notNull(),
|
|
1623
|
+
content: text("content"),
|
|
1624
|
+
published: boolean("published").notNull().default(false),
|
|
1625
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1626
|
+
});
|
|
1627
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
1628
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
1629
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
1630
|
+
}
|
|
1107
1631
|
`}]},dependencies:["@vaiftech/sdk-expo","@react-native-async-storage/async-storage","expo","expo-router","react","react-native"],postInstructions:["cd my-vaif-app","npm install","# Copy .env.example to .env and add your VAIF credentials","npx expo start"]},"flutter-app":{name:"Flutter App",description:"Dart/Flutter client setup with environment configuration",tag:"Flutter / Dart",defaultFeatures:["database","auth"],files:[{path:"lib/main.dart",content:`import 'package:flutter/material.dart';
|
|
1108
1632
|
import 'vaif_client.dart';
|
|
1109
1633
|
|
|
@@ -1188,6 +1712,84 @@ VAIF_API_KEY=your-anon-key
|
|
|
1188
1712
|
.packages
|
|
1189
1713
|
.env
|
|
1190
1714
|
*.iml
|
|
1715
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 Flutter
|
|
1716
|
+
|
|
1717
|
+
A Flutter application powered by [VAIF Studio](https://vaif.studio), with Dart client and environment configuration.
|
|
1718
|
+
|
|
1719
|
+
## Prerequisites
|
|
1720
|
+
|
|
1721
|
+
- [Flutter SDK](https://flutter.dev/docs/get-started/install) 3.5 or later
|
|
1722
|
+
- Dart SDK (included with Flutter)
|
|
1723
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
1724
|
+
- (Optional) VAIF CLI for type generation: \\\`npm install -g @vaiftech/cli\\\`
|
|
1725
|
+
|
|
1726
|
+
## Setup
|
|
1727
|
+
|
|
1728
|
+
1. **Install dependencies**
|
|
1729
|
+
|
|
1730
|
+
\\\`\\\`\\\`bash
|
|
1731
|
+
flutter pub get
|
|
1732
|
+
\\\`\\\`\\\`
|
|
1733
|
+
|
|
1734
|
+
2. **Configure credentials**
|
|
1735
|
+
|
|
1736
|
+
\\\`\\\`\\\`bash
|
|
1737
|
+
cp .env.example .env
|
|
1738
|
+
\\\`\\\`\\\`
|
|
1739
|
+
|
|
1740
|
+
Get your Project ID and API Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
1741
|
+
|
|
1742
|
+
3. **Install and log in to the VAIF CLI** (for schema and type generation)
|
|
1743
|
+
|
|
1744
|
+
\\\`\\\`\\\`bash
|
|
1745
|
+
npm install -g @vaiftech/cli
|
|
1746
|
+
vaif login
|
|
1747
|
+
\\\`\\\`\\\`
|
|
1748
|
+
|
|
1749
|
+
4. **Pull your database schema**
|
|
1750
|
+
|
|
1751
|
+
\\\`\\\`\\\`bash
|
|
1752
|
+
vaif pull
|
|
1753
|
+
\\\`\\\`\\\`
|
|
1754
|
+
|
|
1755
|
+
5. **Generate Dart models**
|
|
1756
|
+
|
|
1757
|
+
\\\`\\\`\\\`bash
|
|
1758
|
+
vaif generate --output ./lib/models/database.dart --lang dart
|
|
1759
|
+
\\\`\\\`\\\`
|
|
1760
|
+
|
|
1761
|
+
6. **Run the app**
|
|
1762
|
+
|
|
1763
|
+
\\\`\\\`\\\`bash
|
|
1764
|
+
flutter run
|
|
1765
|
+
\\\`\\\`\\\`
|
|
1766
|
+
|
|
1767
|
+
## Project Structure
|
|
1768
|
+
|
|
1769
|
+
\\\`\\\`\\\`
|
|
1770
|
+
.
|
|
1771
|
+
\u251C\u2500\u2500 lib/
|
|
1772
|
+
\u2502 \u251C\u2500\u2500 main.dart # App entry point
|
|
1773
|
+
\u2502 \u251C\u2500\u2500 vaif_client.dart # VAIF client setup
|
|
1774
|
+
\u2502 \u2514\u2500\u2500 screens/ # Screen widgets (added by features)
|
|
1775
|
+
\u251C\u2500\u2500 pubspec.yaml # Dart dependencies
|
|
1776
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
1777
|
+
\u2514\u2500\u2500 .gitignore
|
|
1778
|
+
\\\`\\\`\\\`
|
|
1779
|
+
|
|
1780
|
+
## Available Commands
|
|
1781
|
+
|
|
1782
|
+
| Command | Description |
|
|
1783
|
+
| ------------------------ | ---------------------------------- |
|
|
1784
|
+
| \\\`flutter pub get\\\` | Install dependencies |
|
|
1785
|
+
| \\\`flutter run\\\` | Run on connected device/emulator |
|
|
1786
|
+
| \\\`flutter build apk\\\` | Build Android APK |
|
|
1787
|
+
| \\\`flutter build ios\\\` | Build iOS app |
|
|
1788
|
+
| \\\`flutter test\\\` | Run tests |
|
|
1789
|
+
|
|
1790
|
+
## Documentation
|
|
1791
|
+
|
|
1792
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
1191
1793
|
`}],featureFiles:{auth:[{path:"lib/screens/login_screen.dart",content:`import 'package:flutter/material.dart';
|
|
1192
1794
|
import '../vaif_client.dart';
|
|
1193
1795
|
|
|
@@ -1245,6 +1847,92 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
1245
1847
|
);
|
|
1246
1848
|
}
|
|
1247
1849
|
}
|
|
1850
|
+
`}],database:[{path:"lib/models/database.dart",content:`/// Database models for VAIF.
|
|
1851
|
+
/// Run \`vaif generate --output ./lib/models/database.dart --lang dart\` to regenerate.
|
|
1852
|
+
|
|
1853
|
+
class User {
|
|
1854
|
+
final String id;
|
|
1855
|
+
final String email;
|
|
1856
|
+
final String? name;
|
|
1857
|
+
final DateTime createdAt;
|
|
1858
|
+
|
|
1859
|
+
User({required this.id, required this.email, this.name, required this.createdAt});
|
|
1860
|
+
|
|
1861
|
+
factory User.fromJson(Map<String, dynamic> json) => User(
|
|
1862
|
+
id: json['id'] as String,
|
|
1863
|
+
email: json['email'] as String,
|
|
1864
|
+
name: json['name'] as String?,
|
|
1865
|
+
createdAt: DateTime.parse(json['created_at'] as String),
|
|
1866
|
+
);
|
|
1867
|
+
|
|
1868
|
+
Map<String, dynamic> toJson() => {
|
|
1869
|
+
'id': id,
|
|
1870
|
+
'email': email,
|
|
1871
|
+
'name': name,
|
|
1872
|
+
'created_at': createdAt.toIso8601String(),
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
class Post {
|
|
1877
|
+
final String id;
|
|
1878
|
+
final String userId;
|
|
1879
|
+
final String title;
|
|
1880
|
+
final String? content;
|
|
1881
|
+
final bool published;
|
|
1882
|
+
final DateTime createdAt;
|
|
1883
|
+
|
|
1884
|
+
Post({
|
|
1885
|
+
required this.id,
|
|
1886
|
+
required this.userId,
|
|
1887
|
+
required this.title,
|
|
1888
|
+
this.content,
|
|
1889
|
+
required this.published,
|
|
1890
|
+
required this.createdAt,
|
|
1891
|
+
});
|
|
1892
|
+
|
|
1893
|
+
factory Post.fromJson(Map<String, dynamic> json) => Post(
|
|
1894
|
+
id: json['id'] as String,
|
|
1895
|
+
userId: json['user_id'] as String,
|
|
1896
|
+
title: json['title'] as String,
|
|
1897
|
+
content: json['content'] as String?,
|
|
1898
|
+
published: json['published'] as bool,
|
|
1899
|
+
createdAt: DateTime.parse(json['created_at'] as String),
|
|
1900
|
+
);
|
|
1901
|
+
|
|
1902
|
+
Map<String, dynamic> toJson() => {
|
|
1903
|
+
'id': id,
|
|
1904
|
+
'user_id': userId,
|
|
1905
|
+
'title': title,
|
|
1906
|
+
'content': content,
|
|
1907
|
+
'published': published,
|
|
1908
|
+
'created_at': createdAt.toIso8601String(),
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
`}],functions:[{path:"lib/services/functions_service.dart",content:`import '../vaif_client.dart';
|
|
1912
|
+
|
|
1913
|
+
/// Service for invoking VAIF serverless functions.
|
|
1914
|
+
class FunctionsService {
|
|
1915
|
+
/// Invoke the "hello" function with an optional name parameter.
|
|
1916
|
+
static Future<Map<String, dynamic>> hello({String name = 'World'}) async {
|
|
1917
|
+
final result = await vaif.functions.invoke(
|
|
1918
|
+
'hello',
|
|
1919
|
+
body: {'name': name},
|
|
1920
|
+
);
|
|
1921
|
+
return result.data as Map<String, dynamic>;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
/// Invoke any VAIF function by name.
|
|
1925
|
+
static Future<Map<String, dynamic>> invoke(
|
|
1926
|
+
String functionName, {
|
|
1927
|
+
Map<String, dynamic>? body,
|
|
1928
|
+
}) async {
|
|
1929
|
+
final result = await vaif.functions.invoke(
|
|
1930
|
+
functionName,
|
|
1931
|
+
body: body ?? {},
|
|
1932
|
+
);
|
|
1933
|
+
return result.data as Map<String, dynamic>;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1248
1936
|
`}]},postInstructions:["flutter pub get","# Copy .env.example to .env and add your VAIF credentials","flutter run"]},"python-fastapi-backend":{name:"Python FastAPI Backend",description:"FastAPI backend with VAIF client, auth middleware, and type-safe queries",tag:"Python / FastAPI",defaultFeatures:["database","auth"],files:[{path:"main.py",content:`"""VAIF FastAPI application."""
|
|
1249
1937
|
|
|
1250
1938
|
from fastapi import FastAPI
|
|
@@ -1317,6 +2005,106 @@ VAIF_SECRET_KEY=your-secret-key
|
|
|
1317
2005
|
.env
|
|
1318
2006
|
.venv
|
|
1319
2007
|
venv
|
|
2008
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 Python FastAPI Backend
|
|
2009
|
+
|
|
2010
|
+
A FastAPI backend application powered by [VAIF Studio](https://vaif.studio), with auth middleware and type-safe queries.
|
|
2011
|
+
|
|
2012
|
+
## Prerequisites
|
|
2013
|
+
|
|
2014
|
+
- [Python](https://www.python.org/) 3.10 or later
|
|
2015
|
+
- pip (included with Python)
|
|
2016
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
2017
|
+
- (Optional) VAIF CLI for schema management: \\\`npm install -g @vaiftech/cli\\\`
|
|
2018
|
+
|
|
2019
|
+
## Setup
|
|
2020
|
+
|
|
2021
|
+
1. **Create a virtual environment** (recommended)
|
|
2022
|
+
|
|
2023
|
+
\\\`\\\`\\\`bash
|
|
2024
|
+
python -m venv .venv
|
|
2025
|
+
source .venv/bin/activate # On Windows: .venv\\\\Scripts\\\\activate
|
|
2026
|
+
\\\`\\\`\\\`
|
|
2027
|
+
|
|
2028
|
+
2. **Install dependencies**
|
|
2029
|
+
|
|
2030
|
+
\\\`\\\`\\\`bash
|
|
2031
|
+
pip install -r requirements.txt
|
|
2032
|
+
\\\`\\\`\\\`
|
|
2033
|
+
|
|
2034
|
+
3. **Configure credentials**
|
|
2035
|
+
|
|
2036
|
+
\\\`\\\`\\\`bash
|
|
2037
|
+
cp .env.example .env
|
|
2038
|
+
\\\`\\\`\\\`
|
|
2039
|
+
|
|
2040
|
+
Get your Project ID, API Key, and Secret Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
2041
|
+
|
|
2042
|
+
4. **Install and log in to the VAIF CLI**
|
|
2043
|
+
|
|
2044
|
+
\\\`\\\`\\\`bash
|
|
2045
|
+
npm install -g @vaiftech/cli
|
|
2046
|
+
vaif login
|
|
2047
|
+
\\\`\\\`\\\`
|
|
2048
|
+
|
|
2049
|
+
5. **Pull your database schema**
|
|
2050
|
+
|
|
2051
|
+
\\\`\\\`\\\`bash
|
|
2052
|
+
vaif pull
|
|
2053
|
+
\\\`\\\`\\\`
|
|
2054
|
+
|
|
2055
|
+
6. **Push database migrations** (if using the database feature)
|
|
2056
|
+
|
|
2057
|
+
\\\`\\\`\\\`bash
|
|
2058
|
+
vaif db push
|
|
2059
|
+
\\\`\\\`\\\`
|
|
2060
|
+
|
|
2061
|
+
7. **Deploy serverless functions** (if using the functions feature)
|
|
2062
|
+
|
|
2063
|
+
\\\`\\\`\\\`bash
|
|
2064
|
+
vaif functions deploy
|
|
2065
|
+
\\\`\\\`\\\`
|
|
2066
|
+
|
|
2067
|
+
8. **Generate Python types**
|
|
2068
|
+
|
|
2069
|
+
\\\`\\\`\\\`bash
|
|
2070
|
+
vaif generate --lang python
|
|
2071
|
+
\\\`\\\`\\\`
|
|
2072
|
+
|
|
2073
|
+
9. **Run the development server**
|
|
2074
|
+
|
|
2075
|
+
\\\`\\\`\\\`bash
|
|
2076
|
+
uvicorn main:app --reload
|
|
2077
|
+
\\\`\\\`\\\`
|
|
2078
|
+
|
|
2079
|
+
The API will be available at [http://localhost:8000](http://localhost:8000). Interactive docs at [http://localhost:8000/docs](http://localhost:8000/docs).
|
|
2080
|
+
|
|
2081
|
+
## Project Structure
|
|
2082
|
+
|
|
2083
|
+
\\\`\\\`\\\`
|
|
2084
|
+
.
|
|
2085
|
+
\u251C\u2500\u2500 main.py # FastAPI application entry point
|
|
2086
|
+
\u251C\u2500\u2500 vaif_client.py # VAIF client setup (public + admin)
|
|
2087
|
+
\u251C\u2500\u2500 middleware/
|
|
2088
|
+
\u2502 \u2514\u2500\u2500 auth.py # Auth middleware (added by auth feature)
|
|
2089
|
+
\u251C\u2500\u2500 routes/
|
|
2090
|
+
\u2502 \u251C\u2500\u2500 storage.py # Storage routes (added by storage feature)
|
|
2091
|
+
\u2502 \u2514\u2500\u2500 functions.py # Functions routes (added by functions feature)
|
|
2092
|
+
\u251C\u2500\u2500 requirements.txt # Python dependencies
|
|
2093
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
2094
|
+
\u2514\u2500\u2500 .gitignore
|
|
2095
|
+
\\\`\\\`\\\`
|
|
2096
|
+
|
|
2097
|
+
## Available Endpoints
|
|
2098
|
+
|
|
2099
|
+
| Method | Path | Description |
|
|
2100
|
+
| ------ | -------------------------------- | ------------------------ |
|
|
2101
|
+
| GET | \\\`/\\\` | Health check |
|
|
2102
|
+
| GET | \\\`/health\\\` | Health status |
|
|
2103
|
+
| GET | \\\`/items\\\` | List items from database |
|
|
2104
|
+
|
|
2105
|
+
## Documentation
|
|
2106
|
+
|
|
2107
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
1320
2108
|
`}],featureFiles:{auth:[{path:"middleware/auth.py",content:`"""VAIF auth middleware for FastAPI."""
|
|
1321
2109
|
|
|
1322
2110
|
from typing import Optional
|
|
@@ -1380,7 +2168,60 @@ async def upload_file(file: UploadFile = File(...)):
|
|
|
1380
2168
|
url_data = client.storage.from_(BUCKET).get_public_url(result.path)
|
|
1381
2169
|
|
|
1382
2170
|
return {"path": result.path, "public_url": url_data}
|
|
1383
|
-
`},{path:"routes/__init__.py",content:""}],
|
|
2171
|
+
`},{path:"routes/__init__.py",content:""}],database:[{path:"migrations/0001_initial.sql",content:`-- Initial migration
|
|
2172
|
+
-- Customize this schema for your project
|
|
2173
|
+
|
|
2174
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
2175
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2176
|
+
"email" text NOT NULL UNIQUE,
|
|
2177
|
+
"name" text,
|
|
2178
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2179
|
+
);
|
|
2180
|
+
|
|
2181
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
2182
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2183
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
2184
|
+
"title" text NOT NULL,
|
|
2185
|
+
"content" text,
|
|
2186
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
2187
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2188
|
+
);
|
|
2189
|
+
`},{path:"models.py",content:`"""Pydantic models matching the database schema."""
|
|
2190
|
+
|
|
2191
|
+
from datetime import datetime
|
|
2192
|
+
from typing import Optional
|
|
2193
|
+
from uuid import UUID
|
|
2194
|
+
|
|
2195
|
+
from pydantic import BaseModel, EmailStr
|
|
2196
|
+
|
|
2197
|
+
|
|
2198
|
+
class UserBase(BaseModel):
|
|
2199
|
+
email: str
|
|
2200
|
+
name: Optional[str] = None
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
class User(UserBase):
|
|
2204
|
+
id: UUID
|
|
2205
|
+
created_at: datetime
|
|
2206
|
+
|
|
2207
|
+
class Config:
|
|
2208
|
+
from_attributes = True
|
|
2209
|
+
|
|
2210
|
+
|
|
2211
|
+
class PostBase(BaseModel):
|
|
2212
|
+
title: str
|
|
2213
|
+
content: Optional[str] = None
|
|
2214
|
+
published: bool = False
|
|
2215
|
+
|
|
2216
|
+
|
|
2217
|
+
class Post(PostBase):
|
|
2218
|
+
id: UUID
|
|
2219
|
+
user_id: UUID
|
|
2220
|
+
created_at: datetime
|
|
2221
|
+
|
|
2222
|
+
class Config:
|
|
2223
|
+
from_attributes = True
|
|
2224
|
+
`}],functions:[{path:"routes/functions.py",content:`"""Invoke VAIF serverless functions."""
|
|
1384
2225
|
|
|
1385
2226
|
from fastapi import APIRouter
|
|
1386
2227
|
from vaif_client import get_vaif_client
|
|
@@ -1393,6 +2234,26 @@ async def invoke_function(function_name: str, payload: dict = {}):
|
|
|
1393
2234
|
client = get_vaif_client()
|
|
1394
2235
|
result = await client.functions.invoke(function_name, body=payload)
|
|
1395
2236
|
return {"data": result}
|
|
2237
|
+
`},{path:"functions/hello.py",content:`"""Example VAIF serverless function."""
|
|
2238
|
+
|
|
2239
|
+
import json
|
|
2240
|
+
|
|
2241
|
+
|
|
2242
|
+
def handler(request):
|
|
2243
|
+
"""Simple hello function.
|
|
2244
|
+
|
|
2245
|
+
Deploy with: vaif functions deploy
|
|
2246
|
+
"""
|
|
2247
|
+
try:
|
|
2248
|
+
body = json.loads(request.body) if request.body else {}
|
|
2249
|
+
name = body.get("name", "World")
|
|
2250
|
+
except (json.JSONDecodeError, AttributeError):
|
|
2251
|
+
name = "World"
|
|
2252
|
+
|
|
2253
|
+
return {
|
|
2254
|
+
"statusCode": 200,
|
|
2255
|
+
"body": json.dumps({"message": f"Hello, {name}!"}),
|
|
2256
|
+
}
|
|
1396
2257
|
`}]},postInstructions:["pip install -r requirements.txt","# Copy .env.example to .env and add your VAIF credentials","uvicorn main:app --reload"]},"go-backend-api":{name:"Go Backend API",description:"Go backend with VAIF client initialisation and HTTP middleware",tag:"Go",defaultFeatures:["database","auth"],files:[{path:"main.go",content:`package main
|
|
1397
2258
|
|
|
1398
2259
|
import (
|
|
@@ -1470,6 +2331,96 @@ VAIF_SECRET_KEY=your-secret-key
|
|
|
1470
2331
|
*.so
|
|
1471
2332
|
*.dylib
|
|
1472
2333
|
.env
|
|
2334
|
+
`},{path:"README.md",content:`# My VAIF App \u2014 Go Backend API
|
|
2335
|
+
|
|
2336
|
+
A Go backend API powered by [VAIF Studio](https://vaif.studio), with HTTP handlers and auth middleware.
|
|
2337
|
+
|
|
2338
|
+
## Prerequisites
|
|
2339
|
+
|
|
2340
|
+
- [Go](https://go.dev/dl/) 1.22 or later
|
|
2341
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
2342
|
+
- (Optional) VAIF CLI for schema management: \\\`npm install -g @vaiftech/cli\\\`
|
|
2343
|
+
|
|
2344
|
+
## Setup
|
|
2345
|
+
|
|
2346
|
+
1. **Install dependencies**
|
|
2347
|
+
|
|
2348
|
+
\\\`\\\`\\\`bash
|
|
2349
|
+
go mod tidy
|
|
2350
|
+
\\\`\\\`\\\`
|
|
2351
|
+
|
|
2352
|
+
2. **Configure credentials**
|
|
2353
|
+
|
|
2354
|
+
\\\`\\\`\\\`bash
|
|
2355
|
+
cp .env.example .env
|
|
2356
|
+
\\\`\\\`\\\`
|
|
2357
|
+
|
|
2358
|
+
Get your Project ID, API Key, and Secret Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
2359
|
+
|
|
2360
|
+
3. **Install and log in to the VAIF CLI**
|
|
2361
|
+
|
|
2362
|
+
\\\`\\\`\\\`bash
|
|
2363
|
+
npm install -g @vaiftech/cli
|
|
2364
|
+
vaif login
|
|
2365
|
+
\\\`\\\`\\\`
|
|
2366
|
+
|
|
2367
|
+
4. **Pull your database schema**
|
|
2368
|
+
|
|
2369
|
+
\\\`\\\`\\\`bash
|
|
2370
|
+
vaif pull
|
|
2371
|
+
\\\`\\\`\\\`
|
|
2372
|
+
|
|
2373
|
+
5. **Push database migrations** (if using the database feature)
|
|
2374
|
+
|
|
2375
|
+
\\\`\\\`\\\`bash
|
|
2376
|
+
vaif db push
|
|
2377
|
+
\\\`\\\`\\\`
|
|
2378
|
+
|
|
2379
|
+
6. **Deploy serverless functions** (if using the functions feature)
|
|
2380
|
+
|
|
2381
|
+
\\\`\\\`\\\`bash
|
|
2382
|
+
vaif functions deploy
|
|
2383
|
+
\\\`\\\`\\\`
|
|
2384
|
+
|
|
2385
|
+
7. **Generate Go types**
|
|
2386
|
+
|
|
2387
|
+
\\\`\\\`\\\`bash
|
|
2388
|
+
vaif generate --lang go
|
|
2389
|
+
\\\`\\\`\\\`
|
|
2390
|
+
|
|
2391
|
+
8. **Run the server**
|
|
2392
|
+
|
|
2393
|
+
\\\`\\\`\\\`bash
|
|
2394
|
+
go run main.go
|
|
2395
|
+
\\\`\\\`\\\`
|
|
2396
|
+
|
|
2397
|
+
The API will be available at [http://localhost:8080](http://localhost:8080).
|
|
2398
|
+
|
|
2399
|
+
## Project Structure
|
|
2400
|
+
|
|
2401
|
+
\\\`\\\`\\\`
|
|
2402
|
+
.
|
|
2403
|
+
\u251C\u2500\u2500 main.go # Application entry point
|
|
2404
|
+
\u251C\u2500\u2500 vaif/
|
|
2405
|
+
\u2502 \u2514\u2500\u2500 client.go # VAIF client initialisation
|
|
2406
|
+
\u251C\u2500\u2500 middleware/
|
|
2407
|
+
\u2502 \u2514\u2500\u2500 auth.go # Auth middleware (added by auth feature)
|
|
2408
|
+
\u251C\u2500\u2500 handlers/
|
|
2409
|
+
\u2502 \u2514\u2500\u2500 storage.go # Storage handlers (added by storage feature)
|
|
2410
|
+
\u251C\u2500\u2500 go.mod # Go module definition
|
|
2411
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
2412
|
+
\u2514\u2500\u2500 .gitignore
|
|
2413
|
+
\\\`\\\`\\\`
|
|
2414
|
+
|
|
2415
|
+
## Available Endpoints
|
|
2416
|
+
|
|
2417
|
+
| Method | Path | Description |
|
|
2418
|
+
| ------ | ---------- | -------------- |
|
|
2419
|
+
| GET | \\\`/health\\\` | Health check |
|
|
2420
|
+
|
|
2421
|
+
## Documentation
|
|
2422
|
+
|
|
2423
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
1473
2424
|
`}],featureFiles:{auth:[{path:"middleware/auth.go",content:`package middleware
|
|
1474
2425
|
|
|
1475
2426
|
import (
|
|
@@ -1545,6 +2496,79 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
1545
2496
|
w.Header().Set("Content-Type", "application/json")
|
|
1546
2497
|
json.NewEncoder(w).Encode(result)
|
|
1547
2498
|
}
|
|
2499
|
+
`}],database:[{path:"migrations/0001_initial.sql",content:`-- Initial migration
|
|
2500
|
+
-- Customize this schema for your project
|
|
2501
|
+
-- Use goose or another Go migration tool to apply:
|
|
2502
|
+
-- goose postgres "$DATABASE_URL" up
|
|
2503
|
+
|
|
2504
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
2505
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2506
|
+
"email" text NOT NULL UNIQUE,
|
|
2507
|
+
"name" text,
|
|
2508
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2509
|
+
);
|
|
2510
|
+
|
|
2511
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
2512
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2513
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
2514
|
+
"title" text NOT NULL,
|
|
2515
|
+
"content" text,
|
|
2516
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
2517
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2518
|
+
);
|
|
2519
|
+
`},{path:"models/models.go",content:`package models
|
|
2520
|
+
|
|
2521
|
+
import (
|
|
2522
|
+
"time"
|
|
2523
|
+
|
|
2524
|
+
"github.com/google/uuid"
|
|
2525
|
+
)
|
|
2526
|
+
|
|
2527
|
+
type User struct {
|
|
2528
|
+
ID uuid.UUID \`json:"id"\`
|
|
2529
|
+
Email string \`json:"email"\`
|
|
2530
|
+
Name *string \`json:"name,omitempty"\`
|
|
2531
|
+
CreatedAt time.Time \`json:"created_at"\`
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
type Post struct {
|
|
2535
|
+
ID uuid.UUID \`json:"id"\`
|
|
2536
|
+
UserID uuid.UUID \`json:"user_id"\`
|
|
2537
|
+
Title string \`json:"title"\`
|
|
2538
|
+
Content *string \`json:"content,omitempty"\`
|
|
2539
|
+
Published bool \`json:"published"\`
|
|
2540
|
+
CreatedAt time.Time \`json:"created_at"\`
|
|
2541
|
+
}
|
|
2542
|
+
`}],functions:[{path:"functions/hello.go",content:`package functions
|
|
2543
|
+
|
|
2544
|
+
import (
|
|
2545
|
+
"encoding/json"
|
|
2546
|
+
"fmt"
|
|
2547
|
+
"net/http"
|
|
2548
|
+
)
|
|
2549
|
+
|
|
2550
|
+
// HelloRequest is the expected request body.
|
|
2551
|
+
type HelloRequest struct {
|
|
2552
|
+
Name string \`json:"name"\`
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// HelloResponse is the response body.
|
|
2556
|
+
type HelloResponse struct {
|
|
2557
|
+
Message string \`json:"message"\`
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
// HelloHandler is an example VAIF serverless function.
|
|
2561
|
+
func HelloHandler(w http.ResponseWriter, r *http.Request) {
|
|
2562
|
+
var req HelloRequest
|
|
2563
|
+
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || req.Name == "" {
|
|
2564
|
+
req.Name = "World"
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
w.Header().Set("Content-Type", "application/json")
|
|
2568
|
+
json.NewEncoder(w).Encode(HelloResponse{
|
|
2569
|
+
Message: fmt.Sprintf("Hello, %s!", req.Name),
|
|
2570
|
+
})
|
|
2571
|
+
}
|
|
1548
2572
|
`}]},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 { createClient } from "@vaiftech/client";
|
|
1549
2573
|
|
|
1550
2574
|
export const vaif = createClient({
|
|
@@ -1604,7 +2628,134 @@ export async function deleteTodo(id: string): Promise<void> {
|
|
|
1604
2628
|
|
|
1605
2629
|
VITE_VAIF_PROJECT_ID=your-project-id
|
|
1606
2630
|
VITE_VAIF_API_KEY=your-anon-key
|
|
1607
|
-
`}
|
|
2631
|
+
`},{path:"README.md",content:`# Todo App \u2014 VAIF Starter
|
|
2632
|
+
|
|
2633
|
+
A simple React todo application for learning [VAIF Studio](https://vaif.studio) basics, including typed database queries and CRUD operations.
|
|
2634
|
+
|
|
2635
|
+
## Prerequisites
|
|
2636
|
+
|
|
2637
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
2638
|
+
- npm (included with Node.js)
|
|
2639
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
2640
|
+
|
|
2641
|
+
## Setup
|
|
2642
|
+
|
|
2643
|
+
1. **Install dependencies**
|
|
2644
|
+
|
|
2645
|
+
\\\`\\\`\\\`bash
|
|
2646
|
+
npm install
|
|
2647
|
+
\\\`\\\`\\\`
|
|
2648
|
+
|
|
2649
|
+
2. **Configure credentials**
|
|
2650
|
+
|
|
2651
|
+
\\\`\\\`\\\`bash
|
|
2652
|
+
cp .env.example .env
|
|
2653
|
+
\\\`\\\`\\\`
|
|
2654
|
+
|
|
2655
|
+
Get your Project ID and API Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
2656
|
+
|
|
2657
|
+
3. **Install and log in to the VAIF CLI**
|
|
2658
|
+
|
|
2659
|
+
\\\`\\\`\\\`bash
|
|
2660
|
+
npm install -g @vaiftech/cli
|
|
2661
|
+
vaif login
|
|
2662
|
+
\\\`\\\`\\\`
|
|
2663
|
+
|
|
2664
|
+
4. **Create the todos table**
|
|
2665
|
+
|
|
2666
|
+
Create a \\\`todos\\\` table in your VAIF dashboard with columns:
|
|
2667
|
+
- \\\`id\\\` (uuid, primary key)
|
|
2668
|
+
- \\\`title\\\` (text)
|
|
2669
|
+
- \\\`done\\\` (boolean)
|
|
2670
|
+
- \\\`created_at\\\` (timestamptz)
|
|
2671
|
+
- \\\`user_id\\\` (uuid, optional)
|
|
2672
|
+
|
|
2673
|
+
5. **Pull your database schema**
|
|
2674
|
+
|
|
2675
|
+
\\\`\\\`\\\`bash
|
|
2676
|
+
vaif pull
|
|
2677
|
+
\\\`\\\`\\\`
|
|
2678
|
+
|
|
2679
|
+
6. **Generate TypeScript types**
|
|
2680
|
+
|
|
2681
|
+
\\\`\\\`\\\`bash
|
|
2682
|
+
vaif generate
|
|
2683
|
+
\\\`\\\`\\\`
|
|
2684
|
+
|
|
2685
|
+
7. **Run the development server**
|
|
2686
|
+
|
|
2687
|
+
\\\`\\\`\\\`bash
|
|
2688
|
+
npm run dev
|
|
2689
|
+
\\\`\\\`\\\`
|
|
2690
|
+
|
|
2691
|
+
## Project Structure
|
|
2692
|
+
|
|
2693
|
+
\\\`\\\`\\\`
|
|
2694
|
+
.
|
|
2695
|
+
\u251C\u2500\u2500 src/
|
|
2696
|
+
\u2502 \u2514\u2500\u2500 lib/
|
|
2697
|
+
\u2502 \u2514\u2500\u2500 vaif.ts # VAIF client + typed todo helpers
|
|
2698
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
2699
|
+
\u2514\u2500\u2500 package.json
|
|
2700
|
+
\\\`\\\`\\\`
|
|
2701
|
+
|
|
2702
|
+
## Key Files
|
|
2703
|
+
|
|
2704
|
+
- **\\\`src/lib/vaif.ts\\\`** \u2014 VAIF client setup plus typed helpers for \\\`getTodos\\\`, \\\`addTodo\\\`, \\\`toggleTodo\\\`, and \\\`deleteTodo\\\`.
|
|
2705
|
+
|
|
2706
|
+
## Documentation
|
|
2707
|
+
|
|
2708
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
2709
|
+
`}],featureFiles:{database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
2710
|
+
-- Customize this schema for your project
|
|
2711
|
+
|
|
2712
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
2713
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2714
|
+
"email" text NOT NULL UNIQUE,
|
|
2715
|
+
"name" text,
|
|
2716
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2717
|
+
);
|
|
2718
|
+
|
|
2719
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
2720
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2721
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
2722
|
+
"title" text NOT NULL,
|
|
2723
|
+
"content" text,
|
|
2724
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
2725
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
2726
|
+
);
|
|
2727
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
2728
|
+
|
|
2729
|
+
export default defineConfig({
|
|
2730
|
+
schema: "./src/db/schema.ts",
|
|
2731
|
+
out: "./drizzle",
|
|
2732
|
+
dialect: "postgresql",
|
|
2733
|
+
dbCredentials: {
|
|
2734
|
+
url: process.env.DATABASE_URL!,
|
|
2735
|
+
},
|
|
2736
|
+
});
|
|
2737
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
2738
|
+
|
|
2739
|
+
export const users = pgTable("users", {
|
|
2740
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
2741
|
+
email: text("email").notNull().unique(),
|
|
2742
|
+
name: text("name"),
|
|
2743
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2744
|
+
});
|
|
2745
|
+
|
|
2746
|
+
export const posts = pgTable("posts", {
|
|
2747
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
2748
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
2749
|
+
title: text("title").notNull(),
|
|
2750
|
+
content: text("content"),
|
|
2751
|
+
published: boolean("published").notNull().default(false),
|
|
2752
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2753
|
+
});
|
|
2754
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
2755
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
2756
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
2757
|
+
}
|
|
2758
|
+
`}]},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 { createClient } from "@vaiftech/client";
|
|
1608
2759
|
|
|
1609
2760
|
export const vaif = createClient({
|
|
1610
2761
|
projectId: import.meta.env.VITE_VAIF_PROJECT_ID,
|
|
@@ -1757,7 +2908,148 @@ export function useRealtimeMessages({
|
|
|
1757
2908
|
|
|
1758
2909
|
VITE_VAIF_PROJECT_ID=your-project-id
|
|
1759
2910
|
VITE_VAIF_API_KEY=your-anon-key
|
|
1760
|
-
`}
|
|
2911
|
+
`},{path:"README.md",content:`# Realtime Chat \u2014 VAIF Starter
|
|
2912
|
+
|
|
2913
|
+
A React chat application with live messaging powered by [VAIF Studio](https://vaif.studio) realtime subscriptions.
|
|
2914
|
+
|
|
2915
|
+
## Prerequisites
|
|
2916
|
+
|
|
2917
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
2918
|
+
- npm (included with Node.js)
|
|
2919
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
2920
|
+
|
|
2921
|
+
## Setup
|
|
2922
|
+
|
|
2923
|
+
1. **Install dependencies**
|
|
2924
|
+
|
|
2925
|
+
\\\`\\\`\\\`bash
|
|
2926
|
+
npm install
|
|
2927
|
+
\\\`\\\`\\\`
|
|
2928
|
+
|
|
2929
|
+
2. **Configure credentials**
|
|
2930
|
+
|
|
2931
|
+
\\\`\\\`\\\`bash
|
|
2932
|
+
cp .env.example .env
|
|
2933
|
+
\\\`\\\`\\\`
|
|
2934
|
+
|
|
2935
|
+
Get your Project ID and API Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
2936
|
+
|
|
2937
|
+
3. **Install and log in to the VAIF CLI**
|
|
2938
|
+
|
|
2939
|
+
\\\`\\\`\\\`bash
|
|
2940
|
+
npm install -g @vaiftech/cli
|
|
2941
|
+
vaif login
|
|
2942
|
+
\\\`\\\`\\\`
|
|
2943
|
+
|
|
2944
|
+
4. **Create the messages table**
|
|
2945
|
+
|
|
2946
|
+
Create a \\\`messages\\\` table in your VAIF dashboard with columns:
|
|
2947
|
+
- \\\`id\\\` (uuid, primary key)
|
|
2948
|
+
- \\\`content\\\` (text)
|
|
2949
|
+
- \\\`user_id\\\` (text)
|
|
2950
|
+
- \\\`username\\\` (text)
|
|
2951
|
+
- \\\`channel_id\\\` (text)
|
|
2952
|
+
- \\\`created_at\\\` (timestamptz)
|
|
2953
|
+
|
|
2954
|
+
5. **Enable Realtime**
|
|
2955
|
+
|
|
2956
|
+
In your VAIF dashboard, enable Realtime on the \\\`messages\\\` table.
|
|
2957
|
+
|
|
2958
|
+
6. **Pull your database schema**
|
|
2959
|
+
|
|
2960
|
+
\\\`\\\`\\\`bash
|
|
2961
|
+
vaif pull
|
|
2962
|
+
\\\`\\\`\\\`
|
|
2963
|
+
|
|
2964
|
+
7. **Push database migrations** (if using the database feature)
|
|
2965
|
+
|
|
2966
|
+
\\\`\\\`\\\`bash
|
|
2967
|
+
vaif db push
|
|
2968
|
+
\\\`\\\`\\\`
|
|
2969
|
+
|
|
2970
|
+
8. **Generate TypeScript types**
|
|
2971
|
+
|
|
2972
|
+
\\\`\\\`\\\`bash
|
|
2973
|
+
vaif generate
|
|
2974
|
+
\\\`\\\`\\\`
|
|
2975
|
+
|
|
2976
|
+
9. **Run the development server**
|
|
2977
|
+
|
|
2978
|
+
\\\`\\\`\\\`bash
|
|
2979
|
+
npm run dev
|
|
2980
|
+
\\\`\\\`\\\`
|
|
2981
|
+
|
|
2982
|
+
## Project Structure
|
|
2983
|
+
|
|
2984
|
+
\\\`\\\`\\\`
|
|
2985
|
+
.
|
|
2986
|
+
\u251C\u2500\u2500 src/
|
|
2987
|
+
\u2502 \u251C\u2500\u2500 lib/
|
|
2988
|
+
\u2502 \u2502 \u2514\u2500\u2500 vaif.ts # VAIF client + message helpers
|
|
2989
|
+
\u2502 \u2514\u2500\u2500 hooks/
|
|
2990
|
+
\u2502 \u2514\u2500\u2500 useRealtimeMessages.ts # Realtime subscription hook
|
|
2991
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
2992
|
+
\u2514\u2500\u2500 package.json
|
|
2993
|
+
\\\`\\\`\\\`
|
|
2994
|
+
|
|
2995
|
+
## Key Files
|
|
2996
|
+
|
|
2997
|
+
- **\\\`src/lib/vaif.ts\\\`** \u2014 VAIF client setup with realtime enabled, plus \\\`sendMessage\\\` and \\\`getMessages\\\` helpers.
|
|
2998
|
+
- **\\\`src/hooks/useRealtimeMessages.ts\\\`** \u2014 React hook that subscribes to live message updates on a channel.
|
|
2999
|
+
|
|
3000
|
+
## Documentation
|
|
3001
|
+
|
|
3002
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
3003
|
+
`}],featureFiles:{database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
3004
|
+
-- Customize this schema for your project
|
|
3005
|
+
|
|
3006
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
3007
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3008
|
+
"email" text NOT NULL UNIQUE,
|
|
3009
|
+
"name" text,
|
|
3010
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3011
|
+
);
|
|
3012
|
+
|
|
3013
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
3014
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3015
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
3016
|
+
"title" text NOT NULL,
|
|
3017
|
+
"content" text,
|
|
3018
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
3019
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3020
|
+
);
|
|
3021
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
3022
|
+
|
|
3023
|
+
export default defineConfig({
|
|
3024
|
+
schema: "./src/db/schema.ts",
|
|
3025
|
+
out: "./drizzle",
|
|
3026
|
+
dialect: "postgresql",
|
|
3027
|
+
dbCredentials: {
|
|
3028
|
+
url: process.env.DATABASE_URL!,
|
|
3029
|
+
},
|
|
3030
|
+
});
|
|
3031
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
3032
|
+
|
|
3033
|
+
export const users = pgTable("users", {
|
|
3034
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3035
|
+
email: text("email").notNull().unique(),
|
|
3036
|
+
name: text("name"),
|
|
3037
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3038
|
+
});
|
|
3039
|
+
|
|
3040
|
+
export const posts = pgTable("posts", {
|
|
3041
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3042
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
3043
|
+
title: text("title").notNull(),
|
|
3044
|
+
content: text("content"),
|
|
3045
|
+
published: boolean("published").notNull().default(false),
|
|
3046
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3047
|
+
});
|
|
3048
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
3049
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
3050
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3051
|
+
}
|
|
3052
|
+
`}]},dependencies:["@vaiftech/client","@vaiftech/react"],postInstructions:["Copy .env.example to .env and fill in your project credentials","Create a 'messages' table with columns: id (uuid), content (text), user_id (text), username (text), channel_id (text), created_at (timestamptz)","Enable Realtime on the messages table in your VAIF dashboard","Use the useRealtimeMessages hook in your components","Run: npx vaif generate to generate TypeScript types"]},"saas-starter":{name:"SaaS Starter",description:"Full SaaS starter with VAIF auth, team/org support, and server-side helpers",tag:"Next.js SaaS",defaultFeatures:["database","auth","functions"],files:[{path:"lib/vaif.ts",content:`import { createClient } from "@vaiftech/client";
|
|
1761
3053
|
import { createServerClient } from "@vaiftech/client/server";
|
|
1762
3054
|
|
|
1763
3055
|
// Browser client \u2013 use in Client Components
|
|
@@ -1926,7 +3218,144 @@ export async function requireTeamRole(
|
|
|
1926
3218
|
NEXT_PUBLIC_VAIF_PROJECT_ID=your-project-id
|
|
1927
3219
|
NEXT_PUBLIC_VAIF_API_KEY=your-anon-key
|
|
1928
3220
|
VAIF_SECRET_KEY=your-secret-key
|
|
1929
|
-
`}
|
|
3221
|
+
`},{path:"README.md",content:`# SaaS Starter \u2014 VAIF Studio
|
|
3222
|
+
|
|
3223
|
+
A full SaaS starter kit powered by [VAIF Studio](https://vaif.studio) with authentication, team/organization support, role-based access control, and server-side helpers.
|
|
3224
|
+
|
|
3225
|
+
## Prerequisites
|
|
3226
|
+
|
|
3227
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
3228
|
+
- npm (included with Node.js)
|
|
3229
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
3230
|
+
|
|
3231
|
+
## Setup
|
|
3232
|
+
|
|
3233
|
+
1. **Install dependencies**
|
|
3234
|
+
|
|
3235
|
+
\\\`\\\`\\\`bash
|
|
3236
|
+
npm install
|
|
3237
|
+
\\\`\\\`\\\`
|
|
3238
|
+
|
|
3239
|
+
2. **Configure credentials**
|
|
3240
|
+
|
|
3241
|
+
\\\`\\\`\\\`bash
|
|
3242
|
+
cp .env.example .env.local
|
|
3243
|
+
\\\`\\\`\\\`
|
|
3244
|
+
|
|
3245
|
+
Get your Project ID, API Key, and Secret Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
3246
|
+
|
|
3247
|
+
3. **Install and log in to the VAIF CLI**
|
|
3248
|
+
|
|
3249
|
+
\\\`\\\`\\\`bash
|
|
3250
|
+
npm install -g @vaiftech/cli
|
|
3251
|
+
vaif login
|
|
3252
|
+
\\\`\\\`\\\`
|
|
3253
|
+
|
|
3254
|
+
4. **Create required tables**
|
|
3255
|
+
|
|
3256
|
+
Create the following tables in your VAIF dashboard:
|
|
3257
|
+
- \\\`teams\\\` \u2014 id (uuid), name (text), slug (text), owner_id (uuid), created_at (timestamptz)
|
|
3258
|
+
- \\\`team_members\\\` \u2014 id (uuid), team_id (uuid), user_id (uuid), role (text), joined_at (timestamptz)
|
|
3259
|
+
|
|
3260
|
+
5. **Pull your database schema**
|
|
3261
|
+
|
|
3262
|
+
\\\`\\\`\\\`bash
|
|
3263
|
+
vaif pull
|
|
3264
|
+
\\\`\\\`\\\`
|
|
3265
|
+
|
|
3266
|
+
6. **Push database migrations** (if using the database feature)
|
|
3267
|
+
|
|
3268
|
+
\\\`\\\`\\\`bash
|
|
3269
|
+
vaif db push
|
|
3270
|
+
\\\`\\\`\\\`
|
|
3271
|
+
|
|
3272
|
+
7. **Deploy serverless functions** (if using the functions feature)
|
|
3273
|
+
|
|
3274
|
+
\\\`\\\`\\\`bash
|
|
3275
|
+
vaif functions deploy
|
|
3276
|
+
\\\`\\\`\\\`
|
|
3277
|
+
|
|
3278
|
+
8. **Generate TypeScript types**
|
|
3279
|
+
|
|
3280
|
+
\\\`\\\`\\\`bash
|
|
3281
|
+
vaif generate
|
|
3282
|
+
\\\`\\\`\\\`
|
|
3283
|
+
|
|
3284
|
+
9. **Run the development server**
|
|
3285
|
+
|
|
3286
|
+
\\\`\\\`\\\`bash
|
|
3287
|
+
npm run dev
|
|
3288
|
+
\\\`\\\`\\\`
|
|
3289
|
+
|
|
3290
|
+
## Project Structure
|
|
3291
|
+
|
|
3292
|
+
\\\`\\\`\\\`
|
|
3293
|
+
.
|
|
3294
|
+
\u251C\u2500\u2500 lib/
|
|
3295
|
+
\u2502 \u251C\u2500\u2500 vaif.ts # Browser + server VAIF client setup
|
|
3296
|
+
\u2502 \u2514\u2500\u2500 auth.ts # User, team, and role-based auth helpers
|
|
3297
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
3298
|
+
\u2514\u2500\u2500 package.json
|
|
3299
|
+
\\\`\\\`\\\`
|
|
3300
|
+
|
|
3301
|
+
## Key Files
|
|
3302
|
+
|
|
3303
|
+
- **\\\`lib/vaif.ts\\\`** \u2014 Browser and server VAIF client setup.
|
|
3304
|
+
- **\\\`lib/auth.ts\\\`** \u2014 Helpers for \\\`getCurrentUser\\\`, \\\`requireUser\\\`, \\\`getUserTeams\\\`, \\\`createTeam\\\`, \\\`inviteToTeam\\\`, and \\\`requireTeamRole\\\`.
|
|
3305
|
+
|
|
3306
|
+
## Documentation
|
|
3307
|
+
|
|
3308
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
3309
|
+
`}],featureFiles:{database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
3310
|
+
-- Customize this schema for your project
|
|
3311
|
+
|
|
3312
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
3313
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3314
|
+
"email" text NOT NULL UNIQUE,
|
|
3315
|
+
"name" text,
|
|
3316
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3317
|
+
);
|
|
3318
|
+
|
|
3319
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
3320
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3321
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
3322
|
+
"title" text NOT NULL,
|
|
3323
|
+
"content" text,
|
|
3324
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
3325
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3326
|
+
);
|
|
3327
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
3328
|
+
|
|
3329
|
+
export default defineConfig({
|
|
3330
|
+
schema: "./src/db/schema.ts",
|
|
3331
|
+
out: "./drizzle",
|
|
3332
|
+
dialect: "postgresql",
|
|
3333
|
+
dbCredentials: {
|
|
3334
|
+
url: process.env.DATABASE_URL!,
|
|
3335
|
+
},
|
|
3336
|
+
});
|
|
3337
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
3338
|
+
|
|
3339
|
+
export const users = pgTable("users", {
|
|
3340
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3341
|
+
email: text("email").notNull().unique(),
|
|
3342
|
+
name: text("name"),
|
|
3343
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3344
|
+
});
|
|
3345
|
+
|
|
3346
|
+
export const posts = pgTable("posts", {
|
|
3347
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3348
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
3349
|
+
title: text("title").notNull(),
|
|
3350
|
+
content: text("content"),
|
|
3351
|
+
published: boolean("published").notNull().default(false),
|
|
3352
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3353
|
+
});
|
|
3354
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
3355
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
3356
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3357
|
+
}
|
|
3358
|
+
`}]},dependencies:["@vaiftech/client","@vaiftech/auth","@vaiftech/react"],postInstructions:["Copy .env.example to .env.local and fill in your project credentials","Create 'teams' and 'team_members' tables in your VAIF dashboard","Import auth helpers from '@/lib/auth' in your Server Components/Actions","Use requireUser() for authenticated routes and requireTeamRole() for role checks","Run: npx vaif generate to generate TypeScript types"]},"ecommerce-api":{name:"E-commerce API",description:"API-first e-commerce setup with VAIF storage for product images",tag:"Next.js E-commerce",defaultFeatures:["database","auth","storage"],files:[{path:"lib/vaif.ts",content:`import { createClient } from "@vaiftech/client";
|
|
1930
3359
|
import { createServerClient } from "@vaiftech/client/server";
|
|
1931
3360
|
|
|
1932
3361
|
// Browser client
|
|
@@ -2057,47 +3486,184 @@ function getContentType(fileName: string): string {
|
|
|
2057
3486
|
NEXT_PUBLIC_VAIF_PROJECT_ID=your-project-id
|
|
2058
3487
|
NEXT_PUBLIC_VAIF_API_KEY=your-anon-key
|
|
2059
3488
|
VAIF_SECRET_KEY=your-secret-key
|
|
2060
|
-
`}
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
3489
|
+
`},{path:"README.md",content:`# E-commerce API \u2014 VAIF Studio
|
|
3490
|
+
|
|
3491
|
+
An API-first e-commerce setup powered by [VAIF Studio](https://vaif.studio) with product image storage, signed URLs, and server-side helpers.
|
|
3492
|
+
|
|
3493
|
+
## Prerequisites
|
|
3494
|
+
|
|
3495
|
+
- [Node.js](https://nodejs.org/) v18 or later
|
|
3496
|
+
- npm (included with Node.js)
|
|
3497
|
+
- A VAIF Studio account \u2014 sign up at <https://vaif.studio>
|
|
3498
|
+
|
|
3499
|
+
## Setup
|
|
3500
|
+
|
|
3501
|
+
1. **Install dependencies**
|
|
3502
|
+
|
|
3503
|
+
\\\`\\\`\\\`bash
|
|
3504
|
+
npm install
|
|
3505
|
+
\\\`\\\`\\\`
|
|
3506
|
+
|
|
3507
|
+
2. **Configure credentials**
|
|
3508
|
+
|
|
3509
|
+
\\\`\\\`\\\`bash
|
|
3510
|
+
cp .env.example .env.local
|
|
3511
|
+
\\\`\\\`\\\`
|
|
3512
|
+
|
|
3513
|
+
Get your Project ID, API Key, and Secret Key from <https://vaif.studio/dashboard> under **Project Settings > API Keys**.
|
|
3514
|
+
|
|
3515
|
+
3. **Install and log in to the VAIF CLI**
|
|
3516
|
+
|
|
3517
|
+
\\\`\\\`\\\`bash
|
|
3518
|
+
npm install -g @vaiftech/cli
|
|
3519
|
+
vaif login
|
|
3520
|
+
\\\`\\\`\\\`
|
|
3521
|
+
|
|
3522
|
+
4. **Create a storage bucket**
|
|
3523
|
+
|
|
3524
|
+
In your VAIF dashboard, create a \\\`product-images\\\` storage bucket.
|
|
3525
|
+
|
|
3526
|
+
5. **Pull your database schema**
|
|
3527
|
+
|
|
3528
|
+
\\\`\\\`\\\`bash
|
|
3529
|
+
vaif pull
|
|
3530
|
+
\\\`\\\`\\\`
|
|
3531
|
+
|
|
3532
|
+
6. **Push database migrations** (if using the database feature)
|
|
3533
|
+
|
|
3534
|
+
\\\`\\\`\\\`bash
|
|
3535
|
+
vaif db push
|
|
3536
|
+
\\\`\\\`\\\`
|
|
3537
|
+
|
|
3538
|
+
7. **Deploy serverless functions** (if using the functions feature)
|
|
3539
|
+
|
|
3540
|
+
\\\`\\\`\\\`bash
|
|
3541
|
+
vaif functions deploy
|
|
3542
|
+
\\\`\\\`\\\`
|
|
3543
|
+
|
|
3544
|
+
8. **Generate TypeScript types**
|
|
3545
|
+
|
|
3546
|
+
\\\`\\\`\\\`bash
|
|
3547
|
+
vaif generate
|
|
3548
|
+
\\\`\\\`\\\`
|
|
3549
|
+
|
|
3550
|
+
9. **Run the development server**
|
|
3551
|
+
|
|
3552
|
+
\\\`\\\`\\\`bash
|
|
3553
|
+
npm run dev
|
|
3554
|
+
\\\`\\\`\\\`
|
|
3555
|
+
|
|
3556
|
+
## Project Structure
|
|
3557
|
+
|
|
3558
|
+
\\\`\\\`\\\`
|
|
3559
|
+
.
|
|
3560
|
+
\u251C\u2500\u2500 lib/
|
|
3561
|
+
\u2502 \u251C\u2500\u2500 vaif.ts # Browser + server VAIF client setup
|
|
3562
|
+
\u2502 \u2514\u2500\u2500 storage.ts # Product image upload, delete, signed URLs
|
|
3563
|
+
\u251C\u2500\u2500 .env.example # Environment variable template
|
|
3564
|
+
\u2514\u2500\u2500 package.json
|
|
3565
|
+
\\\`\\\`\\\`
|
|
3566
|
+
|
|
3567
|
+
## Key Files
|
|
3568
|
+
|
|
3569
|
+
- **\\\`lib/vaif.ts\\\`** \u2014 Browser and server VAIF client setup.
|
|
3570
|
+
- **\\\`lib/storage.ts\\\`** \u2014 Helpers for \\\`uploadProductImage\\\`, \\\`deleteProductImage\\\`, \\\`getSignedImageUrl\\\`, and \\\`listProductImages\\\`.
|
|
3571
|
+
|
|
3572
|
+
## Documentation
|
|
3573
|
+
|
|
3574
|
+
Full documentation is available at <https://docs.vaif.studio>.
|
|
3575
|
+
`}],featureFiles:{database:[{path:"drizzle/0001_initial.sql",content:`-- Initial migration
|
|
3576
|
+
-- Customize this schema for your project
|
|
3577
|
+
|
|
3578
|
+
CREATE TABLE IF NOT EXISTS "users" (
|
|
3579
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3580
|
+
"email" text NOT NULL UNIQUE,
|
|
3581
|
+
"name" text,
|
|
3582
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3583
|
+
);
|
|
3584
|
+
|
|
3585
|
+
CREATE TABLE IF NOT EXISTS "posts" (
|
|
3586
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3587
|
+
"user_id" uuid NOT NULL REFERENCES "users"("id"),
|
|
3588
|
+
"title" text NOT NULL,
|
|
3589
|
+
"content" text,
|
|
3590
|
+
"published" boolean NOT NULL DEFAULT false,
|
|
3591
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT now()
|
|
3592
|
+
);
|
|
3593
|
+
`},{path:"drizzle.config.ts",content:`import { defineConfig } from "drizzle-kit";
|
|
3594
|
+
|
|
3595
|
+
export default defineConfig({
|
|
3596
|
+
schema: "./src/db/schema.ts",
|
|
3597
|
+
out: "./drizzle",
|
|
3598
|
+
dialect: "postgresql",
|
|
3599
|
+
dbCredentials: {
|
|
3600
|
+
url: process.env.DATABASE_URL!,
|
|
3601
|
+
},
|
|
3602
|
+
});
|
|
3603
|
+
`},{path:"src/db/schema.ts",content:`import { pgTable, uuid, text, boolean, timestamp } from "drizzle-orm/pg-core";
|
|
3604
|
+
|
|
3605
|
+
export const users = pgTable("users", {
|
|
3606
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3607
|
+
email: text("email").notNull().unique(),
|
|
3608
|
+
name: text("name"),
|
|
3609
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3610
|
+
});
|
|
3611
|
+
|
|
3612
|
+
export const posts = pgTable("posts", {
|
|
3613
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
3614
|
+
userId: uuid("user_id").notNull().references(() => users.id),
|
|
3615
|
+
title: text("title").notNull(),
|
|
3616
|
+
content: text("content"),
|
|
3617
|
+
published: boolean("published").notNull().default(false),
|
|
3618
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3619
|
+
});
|
|
3620
|
+
`}],functions:[{path:"functions/hello.ts",content:`export default async function handler(req: Request): Promise<Response> {
|
|
3621
|
+
const { name } = await req.json().catch(() => ({ name: "World" }));
|
|
3622
|
+
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3623
|
+
}
|
|
3624
|
+
`}]},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 re(){console.log(""),console.log(p__default.default.bold("Available project templates")),console.log("");let t=26,e=22;console.log(` ${p__default.default.gray("Template".padEnd(t))}${p__default.default.gray("Stack".padEnd(e))}${p__default.default.gray("Description")}`),console.log(p__default.default.gray(" "+"-".repeat(t+e+40)));for(let[o,n]of Object.entries(ie))console.log(` ${p__default.default.cyan(o.padEnd(t))}${p__default.default.yellow(n.tag.padEnd(e))}${p__default.default.white(n.description)}`);console.log(""),console.log(p__default.default.gray("Usage:")),console.log(p__default.default.gray(" npx @vaiftech/cli init --template <name>")),console.log(p__default.default.gray(" npx @vaiftech/cli init -t nextjs-fullstack")),console.log(p__default.default.gray(" npx @vaiftech/cli init -t react-spa --features auth,database,realtime")),console.log(""),console.log(p__default.default.gray("Available features: auth, database, realtime, storage, functions")),console.log("");}async function Xe(t){if(!process.stdin.isTTY||!process.stdout.isTTY)return t;let e=new Set(t.map(n=>k.findIndex(r=>r.name===n)).filter(n=>n>=0)),o=0;return new Promise(n=>{let r=ae__default.default.createInterface({input:process.stdin,output:process.stdout});ae__default.default.emitKeypressEvents(process.stdin,r),process.stdin.setRawMode&&process.stdin.setRawMode(true);function s(){let a=k.length+2;process.stdout.write(`\x1B[${a}A`),i();}function i(){console.log(p__default.default.bold(`
|
|
3625
|
+
? Which VAIF features do you want to include?`)),k.forEach((a,l)=>{let c=e.has(l)?p__default.default.green("[x]"):"[ ]",u=l===o?p__default.default.cyan("> "):" ";console.log(`${u}${c} ${a.label} ${p__default.default.gray(`(${a.description})`)}`);}),console.log(p__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--,s();else if(l.name==="down"&&o<k.length-1)o++,s();else if(l.name==="space")e.has(o)?e.delete(o):e.add(o),s();else if(l.name==="return"){process.stdin.setRawMode&&process.stdin.setRawMode(false),r.close();let c=[...e].sort().map(u=>k[u].name);n(c.length>0?c:t);}else l.name==="c"&&l.ctrl&&(process.stdin.setRawMode&&process.stdin.setRawMode(false),r.close(),process.exit(0));});})}async function se(t,e={}){let o=ie[t];o||(console.log(p__default.default.red(`
|
|
3626
|
+
Unknown template: ${t}`)),console.log(p__default.default.yellow(`Run 'vaif templates' to see available templates.
|
|
3627
|
+
`)),process.exit(1));let n;e.features&&e.features.length>0?n=e.features.filter(c=>k.some(u=>u.name===c)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await Xe(o.defaultFeatures??["database","auth"]):n=o.defaultFeatures??[],console.log(""),console.log(p__default.default.bold(`Scaffolding ${p__default.default.cyan(o.name)} template...`)),n.length>0&&console.log(p__default.default.gray(` Features: ${n.join(", ")}`)),console.log("");let r=[...o.files];if(o.featureFiles)for(let c of n){let u=o.featureFiles[c];u&&r.push(...u);}let s=0,i=0;for(let c of r){let u=I__default.default.resolve(c.path),f=I__default.default.dirname(u);if(R__default.default.existsSync(f)||R__default.default.mkdirSync(f,{recursive:true}),c.path==="package.json"&&R__default.default.existsSync(u)&&!e.force)try{let d=JSON.parse(R__default.default.readFileSync(u,"utf-8")),m=JSON.parse(c.content),b=C=>{if(!C)return {};let U={};for(let[$e,$]of Object.entries(C))!$.startsWith("workspace:")&&!$.startsWith("link:")&&!$.startsWith("file:")&&(U[$e]=$);return U};d.dependencies={...b(d.dependencies),...m.dependencies||{}},d.devDependencies={...b(d.devDependencies),...m.devDependencies||{}},m.scripts&&(d.scripts={...d.scripts||{},...m.scripts}),R__default.default.writeFileSync(u,JSON.stringify(d,null,2)+`
|
|
3628
|
+
`,"utf-8"),console.log(p__default.default.green(` merge ${c.path} (added dependencies)`)),s++;continue}catch{}if(R__default.default.existsSync(u)&&!e.force){console.log(p__default.default.yellow(` skip ${c.path} (already exists)`)),i++;continue}R__default.default.writeFileSync(u,c.content,"utf-8"),console.log(p__default.default.green(` create ${c.path}`)),s++;}console.log(""),s>0&&console.log(p__default.default.green(`Created ${s} file${s!==1?"s":""}.`)),i>0&&console.log(p__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=I__default.default.resolve("package.json");if(R__default.default.existsSync(l)&&n.length>0)try{let c=JSON.parse(R__default.default.readFileSync(l,"utf-8")),u=!1;for(let f of n){let d=a[f];if(d)for(let[m,b]of Object.entries(d))c.dependencies?.[m]||(c.dependencies=c.dependencies||{},c.dependencies[m]=b,u=!0);}u&&R__default.default.writeFileSync(l,JSON.stringify(c,null,2)+`
|
|
3629
|
+
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(p__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(p__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(p__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(p__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(p__default.default.bold(" Next steps:")),o.postInstructions.forEach(c=>{console.log(p__default.default.gray(` ${c}`));}),console.log(""),console.log(p__default.default.gray(" Get your project credentials at https://vaif.studio")),console.log("");}var Ze={$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 le(t){let e=K__default.default("Initializing VAIF configuration...").start(),o=I__default.default.resolve("vaif.config.json");R__default.default.existsSync(o)&&!t.force&&(e.fail("vaif.config.json already exists"),console.log(p__default.default.yellow(`
|
|
3630
|
+
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(R__default.default.writeFileSync(o,JSON.stringify(Ze,null,2),"utf-8"),e.succeed("Created vaif.config.json"),t.template){let n=t.features?t.features.split(",").map(r=>r.trim()):void 0;await se(t.template,{force:t.force,features:n});}else {let n=I__default.default.resolve(".env.example");if(R__default.default.existsSync(n)||(R__default.default.writeFileSync(n,`# VAIF Configuration
|
|
2065
3631
|
DATABASE_URL=postgresql://user:password@localhost:5432/database
|
|
2066
3632
|
VAIF_API_KEY=your-api-key
|
|
2067
|
-
`,"utf-8"),console.log(
|
|
2068
|
-
Error: ${n.message}`)),process.exit(1);}}var
|
|
2069
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let
|
|
2070
|
-
Could not connect to VAIF API.`)),console.log(
|
|
2071
|
-
The authentication session expired. Please try again.`)),process.exit(1));continue}let
|
|
2072
|
-
Timed out waiting for browser authentication.`)),console.log(
|
|
2073
|
-
No email provided. Login cancelled.`)),process.exit(1));let o=await
|
|
2074
|
-
No password provided. Login cancelled.`)),process.exit(1));let n=K__default.default("Authenticating...").start();try{let
|
|
2075
|
-
${
|
|
2076
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function pe(t){console.log(""),console.log(
|
|
2077
|
-
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(
|
|
2078
|
-
Error: ${
|
|
2079
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let
|
|
2080
|
-
Error: ${
|
|
2081
|
-
Error: ${
|
|
2082
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let
|
|
2083
|
-
Expected schema file at: ${
|
|
2084
|
-
Error: ${
|
|
2085
|
-
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let
|
|
2086
|
-
Error: ${
|
|
2087
|
-
Place your functions in:`)),console.log(
|
|
2088
|
-
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${
|
|
2089
|
-
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(
|
|
2090
|
-
No functions found`)),console.log(
|
|
2091
|
-
Error: ${
|
|
2092
|
-
Place your seed files in one of these directories:`)),console.log(
|
|
2093
|
-
Or specify a file with --file`)),console.log(
|
|
2094
|
-
Example seed file (seeds/users.json):`)),console.log(
|
|
2095
|
-
Expected one of:`)),console.log(
|
|
2096
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let
|
|
2097
|
-
Error: ${
|
|
2098
|
-
Error: ${
|
|
2099
|
-
Error: ${
|
|
2100
|
-
Generate one with: vaif keys generate`));return}let c=Math.max(8,...
|
|
2101
|
-
Error: ${
|
|
2102
|
-
Error: ${
|
|
2103
|
-
Error: ${
|
|
3633
|
+
`,"utf-8"),console.log(p__default.default.gray("Created .env.example"))),t.typescript){let r=I__default.default.resolve("src/types");R__default.default.existsSync(r)||(R__default.default.mkdirSync(r,{recursive:!0}),console.log(p__default.default.gray("Created src/types directory")));}console.log(""),console.log(p__default.default.green("VAIF initialized successfully!")),console.log(""),console.log(p__default.default.gray("Next steps:")),console.log(p__default.default.gray(" 1. Update vaif.config.json with your project ID")),console.log(p__default.default.gray(" 2. Set DATABASE_URL in your environment")),console.log(p__default.default.gray(" 3. Run: npx vaif generate")),console.log("");}}catch(n){e.fail("Failed to initialize"),n instanceof Error&&console.error(p__default.default.red(`
|
|
3634
|
+
Error: ${n.message}`)),process.exit(1);}}var X=I__default.default.join(et__default.default.homedir(),".vaif"),V=I__default.default.join(X,"auth.json"),M=process.env.VAIF_API_URL||"https://api.vaif.studio";function ot(){R__default.default.existsSync(X)||R__default.default.mkdirSync(X,{recursive:true});}function ue(t){ot(),R__default.default.writeFileSync(V,JSON.stringify(t,null,2),"utf-8"),R__default.default.chmodSync(V,384);}function w(){if(!R__default.default.existsSync(V))return null;try{let t=R__default.default.readFileSync(V,"utf-8");return JSON.parse(t)}catch{return null}}function nt(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 at(t){return new Promise(e=>{let o=ae__default.default.createInterface({input:process.stdin,output:process.stdout});process.stdin;let r=process.stdout.write.bind(process.stdout),s=false;process.stdout.write=((...i)=>s?true:r(...i)),o.question(t,i=>{s=false,process.stdout.write=r,console.log(""),o.close(),e(i);}),s=true;})}function it(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 rt(t){return new Promise(e=>setTimeout(e,t))}async function st(t){try{let e=await fetch(`${M}/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 lt(t){let e=K__default.default();e.start("Setting up authentication...");let o,n;try{let a=await fetch(`${M}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});a.ok||(e.fail("Failed to initiate authentication"),console.log(p__default.default.red(`
|
|
3635
|
+
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(p__default.default.red(`
|
|
3636
|
+
Could not connect to VAIF API.`)),console.log(p__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(p__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(p__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(p__default.default.white(` ${n}`)),console.log(""),it(n),e.start("Waiting for browser authentication...");let r=12e4,s=2e3,i=Date.now();for(;Date.now()-i<r;){await rt(s);try{let a=await fetch(`${M}/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(p__default.default.red(`
|
|
3637
|
+
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()};ue(c),e.succeed("Logged in successfully"),console.log(""),l.user?.email&&console.log(p__default.default.green(` Authenticated as: ${l.user.email}`)),console.log(p__default.default.gray(` Config saved to: ${V}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(p__default.default.red(`
|
|
3638
|
+
Timed out waiting for browser authentication.`)),console.log(p__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function ct(t){console.log(""),console.log(p__default.default.bold("VAIF CLI Login")),console.log(p__default.default.gray("Enter your VAIF account credentials")),console.log("");let e=await nt(p__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(p__default.default.red(`
|
|
3639
|
+
No email provided. Login cancelled.`)),process.exit(1));let o=await at(p__default.default.cyan(" Password: "));(!o||o.trim()==="")&&(console.log(p__default.default.red(`
|
|
3640
|
+
No password provided. Login cancelled.`)),process.exit(1));let n=K__default.default("Authenticating...").start();try{let r=await fetch(`${M}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:o})}),s=await r.json();(!r.ok||!s.ok)&&(n.fail("Login failed"),console.log(p__default.default.red(`
|
|
3641
|
+
${s.message||"Invalid email or password."}`)),process.exit(1));let i={token:s.accessToken,email:s.user?.email,projectId:t,expiresAt:new Date(Date.now()+s.expiresIn*1e3).toISOString()};ue(i),n.succeed("Logged in successfully"),console.log(""),s.user?.email&&console.log(p__default.default.green(` Authenticated as: ${s.user.email}`)),console.log(p__default.default.gray(` Config saved to: ${V}`)),console.log("");}catch{n.fail("Failed to connect to VAIF API"),console.log(p__default.default.red(`
|
|
3642
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function pe(t){console.log(""),console.log(p__default.default.bold("Welcome to VAIF CLI")),console.log(p__default.default.gray("Authenticate to access your VAIF projects")),console.log(""),t.email?await ct(t.projectId):await lt(t.projectId),console.log(p__default.default.gray("You can now use VAIF CLI commands like:")),console.log(p__default.default.gray(" vaif pull - Pull remote schema")),console.log(p__default.default.gray(" vaif push - Push schema changes")),console.log(p__default.default.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function fe(){R__default.default.existsSync(V)?(R__default.default.unlinkSync(V),console.log(p__default.default.green("Logged out successfully"))):console.log(p__default.default.yellow("Not currently logged in"));}async function me(){let t=w();(!t||!t.token)&&(console.log(p__default.default.yellow("Not logged in")),console.log(p__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=K__default.default("Checking authentication...").start(),{valid:o,email:n}=await st(t.token);o||(e.fail("Session expired"),console.log(p__default.default.yellow(`
|
|
3643
|
+
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(p__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(p__default.default.green(` Project: ${t.projectId}`)),console.log("");}var ft=process.env.VAIF_API_URL||"https://api.vaif.studio";async function mt(t,e,o="public"){let n=await fetch(`${ft}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let r=await n.text();throw new Error(`Failed to fetch schema: ${r}`)}return n.json()}async function ge(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(i){e.fail("Failed to load config"),console.log(p__default.default.red(`
|
|
3644
|
+
Error: ${i}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(p__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||o.projectId;s||(e.fail("No project ID specified"),console.log(p__default.default.yellow(`
|
|
3645
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||r.database?.schema||"public",a=await mt(o.token,s,i);e.succeed("Schema fetched successfully");let l=t.output||I__default.default.resolve("vaif.schema.json"),c={$schema:"https://vaif.studio/schemas/schema.json",projectId:s,schema:i,pulledAt:new Date().toISOString(),...a};R__default.default.writeFileSync(l,JSON.stringify(c,null,2),"utf-8"),console.log(""),console.log(p__default.default.green(`Schema saved to: ${l}`)),console.log(""),console.log(p__default.default.gray("Schema summary:")),console.log(p__default.default.gray(` Tables: ${(a.tables||[]).length}`)),console.log(p__default.default.gray(` Enums: ${(a.enums||[]).length}`)),console.log(p__default.default.gray(` Functions: ${(a.functions||[]).length}`)),console.log(""),console.log(p__default.default.gray("Next steps:")),console.log(p__default.default.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(p__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(p__default.default.red(`
|
|
3646
|
+
Error: ${i.message}`)),process.exit(1);}}var ye=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 bt(t,e,o){let n=await fetch(`${ye}/v1/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to preview changes: ${r}`)}return n.json()}async function It(t,e,o){let n=await fetch(`${ye}/v1/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to apply changes: ${r}`)}return n.json()}function At(t){if(console.log(""),console.log(p__default.default.bold("Schema Changes:")),console.log(""),t.added.length===0&&t.modified.length===0&&t.removed.length===0){console.log(p__default.default.gray(" No changes detected. Schema is up to date."));return}if(t.added.length>0){console.log(p__default.default.green.bold(" + Added:"));for(let e of t.added)console.log(p__default.default.green(` + ${e.type}: ${e.name}`));console.log("");}if(t.modified.length>0){console.log(p__default.default.yellow.bold(" ~ Modified:"));for(let e of t.modified){console.log(p__default.default.yellow(` ~ ${e.type}: ${e.name}`));for(let o of e.changes)console.log(p__default.default.gray(` ${o}`));}console.log("");}if(t.removed.length>0){console.log(p__default.default.red.bold(" - Removed:"));for(let e of t.removed)console.log(p__default.default.red(` - ${e.type}: ${e.name}`));console.log("");}}async function ve(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(l){e.fail("Failed to load config"),console.log(p__default.default.red(`
|
|
3647
|
+
Error: ${l}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(p__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||o.projectId;s||(e.fail("No project ID specified"),console.log(p__default.default.yellow(`
|
|
3648
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||I__default.default.resolve("vaif.schema.json");R__default.default.existsSync(i)||(e.fail("No local schema found"),console.log(p__default.default.yellow(`
|
|
3649
|
+
Expected schema file at: ${i}`)),console.log(p__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let l=R__default.default.readFileSync(i,"utf-8");a=JSON.parse(l);}catch(l){e.fail("Failed to parse schema file"),l instanceof Error&&console.log(p__default.default.red(`
|
|
3650
|
+
Error: ${l.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:l,sql:c}=await bt(o.token,s,a);if(e.stop(),At(l),l.added.length===0&&l.modified.length===0&&l.removed.length===0){console.log("");return}if(c.length>0){console.log(p__default.default.bold("SQL Migrations:")),console.log("");for(let f of c)console.log(p__default.default.gray(` ${f}`));console.log("");}if(t.dryRun){console.log(p__default.default.yellow("Dry run mode - no changes applied.")),console.log(p__default.default.gray("Remove --dry-run to apply these changes."));return}if(!t.force){l.removed.length>0&&(console.log(p__default.default.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(p__default.default.red(" This action cannot be undone!")),console.log(""));let d=await vt(p__default.default.cyan("Apply these changes? [y/N] "));if(d.toLowerCase()!=="y"&&d.toLowerCase()!=="yes"){console.log(p__default.default.yellow(`
|
|
3651
|
+
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let u=await It(o.token,s,a);if(u.success){if(e.succeed("Schema changes applied successfully"),console.log(""),u.migrations.length>0){console.log(p__default.default.gray("Migrations applied:"));for(let f of u.migrations)console.log(p__default.default.gray(` - ${f}`));console.log("");}console.log(p__default.default.green("Your database schema is now up to date.")),console.log(p__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(p__default.default.red(`
|
|
3652
|
+
Error: ${l.message}`)),process.exit(1);}}var we=process.env.VAIF_API_URL||"https://api.vaif.studio";async function wt(t,e,o){let n=await fetch(`${we}/v1/projects/${e}/functions`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({name:o.name,runtime:o.runtime,entrypoint:o.entrypoint,code:o.code,envId:o.envId})});if(!n.ok){let r=await n.text();throw new Error(`Failed to deploy function: ${r}`)}return n.json()}async function St(t,e,o){let n=new URL(`${we}/v1/projects/${e}/functions`);o&&n.searchParams.set("envId",o);let r=await fetch(n.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!r.ok){let s=await r.text();throw new Error(`Failed to list functions: ${s}`)}return r.json()}function be(t){switch(I__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 Ie(t){let e=[],o=[".ts",".js",".mjs",".py",".go",".rs"];function n(r){if(!R__default.default.existsSync(r))return;let s=R__default.default.readdirSync(r,{withFileTypes:true});for(let i of s){let a=I__default.default.join(r,i.name);if(i.isDirectory())i.name!=="node_modules"&&!i.name.startsWith(".")&&n(a);else if(i.isFile()){let l=I__default.default.extname(i.name).toLowerCase();o.includes(l)&&(i.name==="index.ts"||i.name==="index.js"||i.name.includes("function")||i.name.includes("handler"))&&e.push(a);}}}return n(t),e}async function Se(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(p__default.default.bold("VAIF Functions Deploy")),console.log(""),e.start("Scanning for function files...");let i=I__default.default.resolve("functions"),a=I__default.default.resolve("src/functions"),l=[];if(t.entrypoint){let d=I__default.default.resolve(t.entrypoint);R__default.default.existsSync(d)||(e.fail(`File not found: ${t.entrypoint}`),process.exit(1)),l=[d];}else l=[...Ie(i),...Ie(a)];l.length===0&&(e.fail("No function files found"),console.log(p__default.default.yellow(`
|
|
3653
|
+
Place your functions in:`)),console.log(p__default.default.gray(" - ./functions/")),console.log(p__default.default.gray(" - ./src/functions/")),console.log(p__default.default.gray(`
|
|
3654
|
+
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${l.length} function(s)`),t.name&&(l=l.filter(d=>I__default.default.basename(d,I__default.default.extname(d)).includes(t.name)),l.length===0&&(console.log(p__default.default.yellow(`
|
|
3655
|
+
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(p__default.default.gray("Functions to deploy:"));for(let d of l){let m=I__default.default.basename(I__default.default.dirname(d))||I__default.default.basename(d,I__default.default.extname(d)),b=t.runtime||be(d);console.log(p__default.default.gray(` - ${m} (${b})`));}if(console.log(""),t.dryRun){console.log(p__default.default.yellow("Dry run mode - no functions deployed."));return}let c=[];for(let d of l){let m=I__default.default.basename(I__default.default.dirname(d))||I__default.default.basename(d,I__default.default.extname(d)),b=t.runtime||be(d);e.start(`Deploying ${m}...`);try{let C=R__default.default.readFileSync(d,"utf-8"),U=await wt(o.token,s,{name:m,runtime:b,entrypoint:I__default.default.basename(d),code:C,envId:t.envId});e.succeed(`Deployed ${m} (v${U.version})`),c.push({name:m,success:!0,version:U.version});}catch(C){let U=C instanceof Error?C.message:"Unknown error";e.fail(`Failed to deploy ${m}`),c.push({name:m,success:false,error:U});}}console.log("");let u=c.filter(d=>d.success).length;if(c.filter(d=>!d.success).length===0)console.log(p__default.default.green(`\u2713 Successfully deployed ${u} function(s)`));else {console.log(p__default.default.yellow(`Deployed ${u}/${c.length} function(s)`)),console.log(""),console.log(p__default.default.red("Failed deployments:"));for(let d of c.filter(m=>!m.success))console.log(p__default.default.red(` - ${d.name}: ${d.error}`));}console.log("");}async function Ee(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let i=await St(o.token,s,t.envId);if(e.stop(),i.length===0){console.log(p__default.default.yellow(`
|
|
3656
|
+
No functions found`)),console.log(p__default.default.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(p__default.default.bold(`Functions (${i.length}):`)),console.log(""),console.log(p__default.default.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"VERSION".padEnd(10)+"STATUS".padEnd(12)+"LAST DEPLOYED")),console.log(p__default.default.gray(" "+"-".repeat(80)));for(let a of i){let l=a.status==="active"?p__default.default.green:a.status==="deploying"?p__default.default.yellow:p__default.default.red;console.log(" "+a.name.padEnd(25)+a.runtime.padEnd(15)+`v${a.version}`.padEnd(10)+l(a.status.padEnd(12))+(a.lastDeployed?new Date(a.lastDeployed).toLocaleDateString():"-"));}console.log("");}catch(i){e.fail("Failed to fetch functions"),i instanceof Error&&console.log(p__default.default.red(`
|
|
3657
|
+
Error: ${i.message}`)),process.exit(1);}}var B=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Et(t,e,o,n,r){let s=await fetch(`${B}/v1/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:o,records:n,truncate:r?.truncate??false})});if(!s.ok){let i=await s.text();throw new Error(`Failed to seed ${o}: ${i}`)}return s.json()}async function xt(t,e){let o=await fetch(`${B}/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 Z(t){let e=[];if(!R__default.default.existsSync(t))return e;let o=R__default.default.readdirSync(t,{withFileTypes:true});for(let n of o)if(n.isFile()){let r=I__default.default.extname(n.name).toLowerCase();(r===".json"||r===".ts"||r===".js")&&e.push(I__default.default.join(t,n.name));}return e.sort()}async function xe(t){let e=I__default.default.extname(t).toLowerCase();if(e===".json"){let o=R__default.default.readFileSync(t,"utf-8"),n=JSON.parse(o);return Array.isArray(n)?[{table:I__default.default.basename(t,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([r,s])=>({table:r,data:s}))}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 _e(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(p__default.default.bold("VAIF Database Seed")),console.log("");let i=[];if(t.file){let u=I__default.default.resolve(t.file);R__default.default.existsSync(u)||(console.log(p__default.default.red(`File not found: ${t.file}`)),process.exit(1)),i=[u];}else {let u=I__default.default.resolve("seeds"),f=I__default.default.resolve("prisma/seed"),d=I__default.default.resolve("db/seeds");i=[...Z(u),...Z(f),...Z(d)];}i.length===0&&(console.log(p__default.default.yellow("No seed files found")),console.log(p__default.default.gray(`
|
|
3658
|
+
Place your seed files in one of these directories:`)),console.log(p__default.default.gray(" - ./seeds/")),console.log(p__default.default.gray(" - ./prisma/seed/")),console.log(p__default.default.gray(" - ./db/seeds/")),console.log(p__default.default.gray(`
|
|
3659
|
+
Or specify a file with --file`)),console.log(p__default.default.gray(`
|
|
3660
|
+
Example seed file (seeds/users.json):`)),console.log(p__default.default.gray(" [")),console.log(p__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(p__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(p__default.default.gray(" ]")),process.exit(1)),console.log(p__default.default.gray("Seed files found:"));for(let u of i)console.log(p__default.default.gray(` - ${I__default.default.relative(process.cwd(),u)}`));if(console.log(""),t.truncate&&(console.log(p__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(p__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let u of i){e.start(`Loading ${I__default.default.basename(u)}...`);try{let f=await xe(u);e.stop();for(let d of f)t.table&&d.table!==t.table||(console.log(p__default.default.cyan(`Table: ${d.table}`)),console.log(p__default.default.gray(` Records: ${d.data.length}`)),d.data.length>0&&console.log(p__default.default.gray(` Sample: ${JSON.stringify(d.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(f){e.fail(`Failed to load ${I__default.default.basename(u)}`),f instanceof Error&&console.log(p__default.default.red(` Error: ${f.message}`));}}return}let a=[];for(let u of i){e.start(`Processing ${I__default.default.basename(u)}...`);try{let f=await xe(u);e.stop();for(let d of f)if(!(t.table&&d.table!==t.table)){if(d.data.length===0){console.log(p__default.default.gray(` Skipping ${d.table} (no records)`));continue}e.start(`Seeding ${d.table} (${d.data.length} records)...`);try{let m=await Et(o.token,s,d.table,d.data,{truncate:t.truncate});e.succeed(`Seeded ${d.table}: ${m.inserted} records`),a.push({table:d.table,inserted:m.inserted});}catch(m){let b=m instanceof Error?m.message:"Unknown error";e.fail(`Failed to seed ${d.table}`),a.push({table:d.table,inserted:0,error:b});}}}catch(f){e.fail(`Failed to load ${I__default.default.basename(u)}`),f instanceof Error&&console.log(p__default.default.red(` Error: ${f.message}`));}}console.log("");let l=a.reduce((u,f)=>u+f.inserted,0),c=a.filter(u=>u.error).length;if(c===0)console.log(p__default.default.green(`\u2713 Successfully seeded ${l} records across ${a.length} table(s)`));else {console.log(p__default.default.yellow(`Seeded ${l} records with ${c} error(s)`)),console.log(""),console.log(p__default.default.red("Errors:"));for(let u of a.filter(f=>f.error))console.log(p__default.default.red(` - ${u.table}: ${u.error}`));}console.log("");}async function Te(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=I__default.default.resolve(t.dir||"./drizzle");if(console.log(""),console.log(p__default.default.bold("VAIF Database Push")),console.log(""),!R__default.default.existsSync(i)){let f=I__default.default.resolve("./migrations");R__default.default.existsSync(f)?console.log(p__default.default.gray(`Using migrations from: ${f}`)):(console.log(p__default.default.red(`Migrations directory not found: ${i}`)),console.log(p__default.default.gray(`
|
|
3661
|
+
Expected one of:`)),console.log(p__default.default.gray(" - ./drizzle/")),console.log(p__default.default.gray(" - ./migrations/")),console.log(p__default.default.gray(`
|
|
3662
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],l=R__default.default.readdirSync(i,{withFileTypes:true});for(let f of l)if(f.isFile()&&f.name.endsWith(".sql"))a.push(I__default.default.join(i,f.name));else if(f.isDirectory()){let d=R__default.default.readdirSync(I__default.default.join(i,f.name),{withFileTypes:true});for(let m of d)m.isFile()&&m.name.endsWith(".sql")&&a.push(I__default.default.join(i,f.name,m.name));}a.sort(),a.length===0&&(console.log(p__default.default.yellow("No SQL migration files found")),process.exit(1)),console.log(p__default.default.gray(`Found ${a.length} migration(s):`));for(let f of a)console.log(p__default.default.gray(` - ${I__default.default.relative(process.cwd(),f)}`));if(console.log(""),t.dryRun){console.log(p__default.default.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let f of a){let d=R__default.default.readFileSync(f,"utf-8");console.log(p__default.default.cyan(`--- ${I__default.default.basename(f)} ---`)),console.log(p__default.default.gray(d.slice(0,500))),d.length>500&&console.log(p__default.default.gray("...")),console.log("");}return}let c=0,u=0;for(let f of a){let d=R__default.default.readFileSync(f,"utf-8"),m=I__default.default.relative(process.cwd(),f);e.start(`Applying ${m}...`);try{let b=await fetch(`${B}/v1/projects/${s}/schema/execute`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:d})});if(!b.ok){let C=await b.text();throw new Error(C)}e.succeed(`Applied ${m}`),c++;}catch(b){let C=b instanceof Error?b.message:"Unknown error";e.fail(`Failed ${m}: ${C}`),u++;}}console.log(""),console.log(u===0?p__default.default.green(`Successfully applied ${c} migration(s)`):p__default.default.yellow(`Applied ${c}, failed ${u} migration(s)`)),console.log("");}async function Fe(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=I__default.default.resolve(t.output||"vaif.schema.json");console.log(""),console.log(p__default.default.bold("VAIF Database Pull")),console.log(""),e.start("Pulling schema from remote...");try{let a=await fetch(`${B}/v1/projects/${s}/schema`,{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok){let u=await a.text();throw new Error(`Failed to pull schema: ${u}`)}let l=await a.json();R__default.default.writeFileSync(i,JSON.stringify(l,null,2),"utf-8"),e.succeed(`Schema written to ${I__default.default.relative(process.cwd(),i)}`);let c=l.tables?.length??Object.keys(l).length;console.log(p__default.default.gray(` ${c} table(s) pulled`)),console.log("");}catch(a){e.fail("Failed to pull schema"),a instanceof Error&&console.log(p__default.default.red(`
|
|
3663
|
+
Error: ${a.message}`)),process.exit(1);}}async function Pe(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),process.exit(1)),console.log(""),console.log(p__default.default.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(p__default.default.red("This will:")),console.log(p__default.default.red(" - Drop all tables")),console.log(p__default.default.red(" - Delete all data")),console.log(p__default.default.red(" - Reset migrations")),console.log(""),console.log(p__default.default.red.bold("This action cannot be undone!")),console.log(""),t.force||(console.log(p__default.default.yellow("Use --force to confirm this action.")),process.exit(1)),e.start("Resetting database...");try{await xt(o.token,s),e.succeed("Database reset complete"),console.log(""),console.log(p__default.default.gray("Your database is now empty.")),console.log(p__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(p__default.default.red(`
|
|
3664
|
+
Error: ${i.message}`)),process.exit(1);}}var je=process.env.VAIF_API_URL||"https://api.vaif.studio";function Re(t,e,o){return t.projectId||e?.projectId||o.projectId||null}async function Ne(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Re(t,r,o);s||(console.log(p__default.default.red("No project ID specified")),console.log(p__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(p__default.default.bold("VAIF Generate API Key")),console.log(""),e.start("Generating API key...");try{let a=await fetch(`${je}/v1/projects/${s}/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(p__default.default.green(` Name: ${l.name}`)),console.log(p__default.default.green(` Key: ${l.key}`)),console.log(""),console.log(p__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(p__default.default.red(`
|
|
3665
|
+
Error: ${a.message}`)),process.exit(1);}}async function Le(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Re(t,r,o);s||(console.log(p__default.default.red("No project ID specified")),console.log(p__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(p__default.default.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let i=await fetch(`${je}/v1/projects/${s}/api-keys`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let f=await i.text();throw new Error(`Failed to list keys: ${f}`)}let a=await i.json(),l=a.keys||a;if(e.stop(),!Array.isArray(l)||l.length===0){console.log(p__default.default.yellow("No API keys found")),console.log(p__default.default.gray(`
|
|
3666
|
+
Generate one with: vaif keys generate`));return}let c=Math.max(8,...l.map(f=>(f.name||"").length)),u=` ${"Name".padEnd(c)} ${"Key".padEnd(24)} Created`;console.log(p__default.default.gray(u)),console.log(p__default.default.gray(" "+"-".repeat(u.length-2)));for(let f of l){let d=(f.name||"unnamed").padEnd(c),m=f.maskedKey||f.prefix||`${(f.key||"").slice(0,12)}...`,b=f.createdAt?new Date(f.createdAt).toLocaleDateString():"N/A";console.log(` ${d} ${m.padEnd(24)} ${b}`);}console.log(""),console.log(p__default.default.gray(` ${l.length} key(s) total`)),console.log("");}catch(i){e.fail("Failed to list API keys"),i instanceof Error&&console.log(p__default.default.red(`
|
|
3667
|
+
Error: ${i.message}`)),process.exit(1);}}var De=process.env.VAIF_API_URL||"https://api.vaif.studio";function Tt(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function Ve(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__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(`${De}/v1/projects/${s}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let u=await i.text();throw new Error(`Failed to fetch project: ${u}`)}let a=await i.json();e.stop(),console.log(""),console.log(p__default.default.bold("VAIF Project Info")),console.log("");let l=16,c=(u,f)=>{console.log(` ${p__default.default.gray(u.padEnd(l))} ${f}`);};c("Name:",p__default.default.white(a.name||"N/A")),c("Project ID:",p__default.default.white(s)),c("Region:",p__default.default.white(a.region||"us-east-1")),c("Plan:",p__default.default.white(a.plan||a.tier||"free")),c("Created:",p__default.default.white(a.createdAt?new Date(a.createdAt).toLocaleDateString():"N/A")),console.log(""),c("API URL:",p__default.default.cyan(a.apiUrl||`${De}/v1`)),c("WS URL:",p__default.default.cyan(a.wsUrl||a.realtimeUrl||"N/A")),c("DB URL:",p__default.default.cyan(a.databaseUrl?Tt(a.databaseUrl):"N/A")),c("Storage URL:",p__default.default.cyan(a.storageUrl||"N/A")),console.log("");}catch(i){e.fail("Failed to fetch project info"),i instanceof Error&&console.log(p__default.default.red(`
|
|
3668
|
+
Error: ${i.message}`)),process.exit(1);}}var Pt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Ue(t){let e=K__default.default(),o=w();(!o||!o.token)&&(console.log(p__default.default.red("Not logged in")),console.log(p__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||o.projectId;s||(console.log(p__default.default.red("No project ID specified")),console.log(p__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(`${Pt}/v1/projects/${s}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let b=await i.text();throw new Error(`Failed to fetch project status: ${b}`)}let a=await i.json();e.stop(),console.log(""),console.log(p__default.default.bold("VAIF Project Status")),console.log("");let l=22,c=(b,C)=>{console.log(` ${p__default.default.gray(b.padEnd(l))} ${C}`);};c("Project:",p__default.default.white(a.name||s)),c("Plan:",p__default.default.white(a.plan||a.tier||"free")),console.log(""),console.log(p__default.default.gray(" --- Resources ---")),console.log("");let u=a.tableCount??a.tables?.length??"N/A",f=a.functionCount??a.functions?.length??"N/A",d=a.bucketCount??a.storage?.buckets?.length??"N/A",m=a.activeConnections??a.connections??"N/A";c("Tables:",p__default.default.white(String(u))),c("Functions:",p__default.default.white(String(f))),c("Storage Buckets:",p__default.default.white(String(d))),c("Active Connections:",p__default.default.white(String(m))),a.usage&&(console.log(""),console.log(p__default.default.gray(" --- Usage ---")),console.log(""),a.usage.dbSize&&c("Database Size:",p__default.default.white(a.usage.dbSize)),a.usage.storageSize&&c("Storage Size:",p__default.default.white(a.usage.storageSize)),a.usage.bandwidth&&c("Bandwidth:",p__default.default.white(a.usage.bandwidth)),a.usage.functionInvocations!=null&&c("Function Invocations:",p__default.default.white(String(a.usage.functionInvocations)))),console.log("");}catch(i){e.fail("Failed to fetch project status"),i instanceof Error&&console.log(p__default.default.red(`
|
|
3669
|
+
Error: ${i.message}`)),process.exit(1);}}commander.program.name("vaif").description("VAIF CLI - Type generation and development tools").version("1.5.0");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(pe);commander.program.command("logout").description("Log out and remove stored credentials").action(fe);commander.program.command("whoami").description("Show current authenticated user").action(me);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").action(le);commander.program.command("templates").alias("tpl").description("List available project templates").action(re);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(Ve);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(Ue);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(ge);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(ve);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(ne);var ke=commander.program.command("functions").alias("fn").description("Manage serverless functions");ke.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(Se);ke.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(Ee);var q=commander.program.command("db").description("Database management commands");q.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(Te);q.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(Fe);q.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(_e);q.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(Pe);var Oe=commander.program.command("keys").description("Manage API keys");Oe.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(Ne);Oe.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(Le);commander.program.parse(process.argv);process.argv.slice(2).length||commander.program.outputHelp();
|