@swirls/cli 0.0.11 → 0.0.12

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.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{a as o,b as s}from"./chunk-ZXQO53AU.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(o,t,s(process));try{for(let{completion:p}of await r(o,t,s(process)))process.stdout.write(`${p}
2
+ import{a as o,b as s}from"./chunk-DYXVDG23.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(o,t,s(process));try{for(let{completion:p}of await r(o,t,s(process)))process.stdout.write(`${p}
3
3
  `)}catch{}
@@ -0,0 +1 @@
1
+ import{buildInstallCommand as R,buildUninstallCommand as L}from"@stricli/auto-complete";import{buildApplication as D,buildRouteMap as I}from"@stricli/core";import{buildCommand as r,buildRouteMap as u}from"@stricli/core";var m=r({loader:async()=>{let{login:e}=await import("./implementation-26623XVE.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log in with an existing account"}}),f=r({loader:async()=>{let{logout:e}=await import("./implementation-26623XVE.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log out of an existing account"}}),i=u({routes:{login:m,logout:f},docs:{brief:"Auth commands"}});import{buildCommand as a,buildRouteMap as g}from"@stricli/core";var b=a({loader:async()=>{let{generateCode:e}=await import("./generate-code-OKMZDZXA.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Generate application code and types"}}),h=a({loader:async()=>{let{initializeConfig:e}=await import("./initialize-config-DKTZP3W4.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Initialize Swirls configuration file"}}),s=g({routes:{gen:b,init:h},docs:{brief:"Developer commands"}});import{buildCommand as k,buildRouteMap as C}from"@stricli/core";var w=k({loader:async()=>{let{createProject:e}=await import("./create-project-HOGHQFPY.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project name",parse:String,placeholder:"name"}]}},docs:{brief:"Create a new project"}}),n=C({routes:{create:w},docs:{brief:"Project commands"}});import{buildCommand as t,buildRouteMap as j}from"@stricli/core";var S=t({loader:async()=>{let{list:e}=await import("./list-O3YBIAFJ.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to list (optional)",parse:String,placeholder:"path",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"List files in storage"}}),y=t({loader:async()=>{let{upload:e}=await import("./upload-L5G6SWZJ.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Local file path to upload",parse:String,placeholder:"file"},{brief:"Destination path in storage (optional)",parse:String,placeholder:"dest",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Upload a file to storage"}}),x=t({loader:async()=>{let{download:e}=await import("./download-3FOT4FPQ.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"},{brief:"Local destination path",parse:String,placeholder:"dest"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Download a file from storage"}}),v=t({loader:async()=>{let{deleteFile:e}=await import("./delete-RSC6OYLX.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Delete a file from storage"}}),P=t({loader:async()=>{let{url:e}=await import("./url-LHTDDDUD.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0},expires:{kind:"parsed",brief:"Expiration time in seconds (default: 86400 = 24 hours)",parse:Number,optional:!0}}},docs:{brief:"Get a signed URL for a file"}}),p=j({routes:{list:S,upload:y,download:x,delete:v,url:P},docs:{brief:"Storage commands"}});var l="@swirls/cli",c="0.0.12",d="Swirls command line application";var _=I({routes:{auth:i,dev:s,project:n,storage:p,install:R("cli",{bash:"__cli_bash_complete"}),uninstall:L("cli",{bash:!0})},docs:{brief:d,hideRoute:{install:!0,uninstall:!0}}}),Y=D(_,{name:l,versionInfo:{currentVersion:c}});import z from"fs";import M from"fs/promises";import N from"os";import A from"path";function ie(e){return{fs:z,fsPromise:M,os:N,path:A,process:e}}export{Y as a,ie as b};
@@ -0,0 +1 @@
1
+ import{existsSync as i}from"fs";import{resolve as c}from"path";import{configFileName as t,configSchema as n}from"@swirls/sdk/config";import{createJiti as s}from"jiti";async function g(r){if(r)return r;let o=c(process.cwd(),t);if(!i(o))throw new Error(`No project specified and no ${t} found. Use --project flag or run from a project directory.`);let e=await s(import.meta.url).import(o,{default:!0});return n.parse(e).projectId}export{g as a};
@@ -0,0 +1 @@
1
+ import{Box as t,Text as e}from"ink";import{jsx as o,jsxs as i}from"react/jsx-runtime";function r(s){return i(t,{flexDirection:"column",children:[o(e,{color:"red",children:s.message}),o(e,{children:"If this issue persists, send us an email at help@byteslice.co, and we can help you out."})]})}export{r as a};
@@ -0,0 +1 @@
1
+ import{Text as o}from"ink";import{jsx as r}from"react/jsx-runtime";function t(e){return r(o,{color:"green",children:e.message})}export{t as a};
@@ -0,0 +1 @@
1
+ import r from"fs/promises";import o from"path";async function s(i,t){let e=o.dirname(i);await r.mkdir(e,{recursive:!0}),await r.writeFile(i,t,"utf-8")}export{s as a};
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as r,b as o}from"./chunk-ZXQO53AU.js";import{run as i}from"@stricli/core";await i(r,process.argv.slice(2),o(process));
2
+ import{a as r,b as o}from"./chunk-DYXVDG23.js";import{run as i}from"@stricli/core";await i(r,process.argv.slice(2),o(process));
@@ -0,0 +1 @@
1
+ import{a as i}from"./chunk-RJOLKCKW.js";import{f as o}from"./chunk-R3TGQKBD.js";import{a as c}from"./chunk-OEQFVEK4.js";import{withResult as n}from"@byteslice/result";import{render as s}from"ink";import{jsx as a}from"react/jsx-runtime";async function j(p,t){let m=await o(this),e=await n(()=>m.projects.createProject({name:t}),r=>new Error(`Failed to create project: ${r.message}`,{cause:r}));e.failure&&(s(a(c,{message:e.failure.message})),process.exit(1)),s(a(i,{message:`Success! Created "${t}" project: ${e.data.id}`}))}export{j as createProject};
@@ -0,0 +1 @@
1
+ import{a as m}from"./chunk-RJOLKCKW.js";import{a as c}from"./chunk-N2UFNXNM.js";import{f as l}from"./chunk-R3TGQKBD.js";import{a as r}from"./chunk-OEQFVEK4.js";import{withResult as f}from"@byteslice/result";import{render as o}from"ink";import{jsx as s}from"react/jsx-runtime";async function j(n,i){let t=await f(()=>c(n.project),e=>new Error(e.message));t.failure&&(o(s(r,{message:t.failure.message})),process.exit(1));let p=await l(this),a=await f(()=>p.buckets.deleteFile({projectId:t.data,path:i}),e=>new Error(`Failed to delete file: ${e.message}`,{cause:e}));a.failure&&(o(s(r,{message:a.failure.message})),process.exit(1)),o(s(m,{message:`Deleted ${i}`}))}export{j as deleteFile};
@@ -0,0 +1 @@
1
+ import{a as c}from"./chunk-RJOLKCKW.js";import{a as w}from"./chunk-N2UFNXNM.js";import{f as d}from"./chunk-R3TGQKBD.js";import{a as r}from"./chunk-OEQFVEK4.js";import{writeFile as u}from"fs/promises";import{withResult as a}from"@byteslice/result";import{render as o}from"ink";import{jsx as t}from"react/jsx-runtime";async function D(g,n,f){let s=await a(()=>w(g.project),e=>new Error(e.message));s.failure&&(o(t(r,{message:s.failure.message})),process.exit(1));let p=await d(this),i=await a(()=>p.buckets.createSignedUrl({projectId:s.data,path:n}),e=>new Error(`Failed to get download URL: ${e.message}`,{cause:e}));i.failure&&(o(t(r,{message:i.failure.message})),process.exit(1));let l=await a(async()=>{let e=await fetch(i.data.signedUrl);if(!e.ok)throw new Error(`Download failed: ${e.statusText}`);return e.arrayBuffer()},e=>new Error(`Failed to download file: ${e.message}`,{cause:e}));l.failure&&(o(t(r,{message:l.failure.message})),process.exit(1));let m=await a(()=>u(f,Buffer.from(l.data)),e=>new Error(`Failed to write file: ${e.message}`,{cause:e}));m.failure&&(o(t(r,{message:m.failure.message})),process.exit(1)),o(t(c,{message:`Downloaded ${n} to ${f}`}))}export{D as download};
@@ -0,0 +1 @@
1
+ import{a as g}from"./chunk-Y7H7V3KU.js";import{a as d}from"./chunk-RJOLKCKW.js";import{f as p}from"./chunk-R3TGQKBD.js";import{a as c}from"./chunk-OEQFVEK4.js";import f from"process";import{withResult as l}from"@byteslice/result";import{generateFormsCode as $}from"@swirls/sdk/form/generate";import{render as a}from"ink";import{Box as S,Text as u}from"ink";import L from"ink-spinner";import{jsx as w,jsxs as h}from"react/jsx-runtime";function x(e){return h(S,{children:[w(u,{color:"cyan",children:w(L,{type:"dots"})}),h(u,{children:[" ",e.message]})]})}import{existsSync as E}from"fs";import{resolve as R}from"path";import{configFileName as y,configSchema as T}from"@swirls/sdk/config";import{createJiti as J}from"jiti";async function F(){let e=R(process.cwd(),y);if(!E(e))throw new Error(`Config file not found in project root: ${y}`);let r=await J(import.meta.url).import(e,{default:!0});return T.parse(r)}async function C(e,n){let r=await p(e),{results:i}=await r.forms.listForms({projectId:n});function m(t){return t.schema!=null}return i.filter(m).map(t=>({id:t.id,name:t.name,schema:t.schema}))}import{jsx as s}from"react/jsx-runtime";async function X(){let e=await l(()=>F(),o=>new Error("Failed to load configuration",{cause:o}));e.failure&&(a(s(c,{message:e.failure.message})),f.exit(1));let{projectId:n,genPath:r}=e.data;a(s(x,{message:"Generating form code..."}));let i=await l(async()=>{let o=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],t=await C(this,n);return $(t,o)},o=>new Error(`Failed to generate form code: ${o.message}`,{cause:o}));i.failure&&(a(s(c,{message:i.failure.message})),f.exit(1));let m=await l(()=>g(r,i.data),o=>new Error("Failed to write code file",{cause:o}));m.failure&&(a(s(c,{message:m.failure.message})),f.exit(1)),a(s(d,{message:`Success! Generated code at ${r}`}))}export{X as generateCode};
@@ -1,4 +1,4 @@
1
- import{a as k,b as v,c as C,d as w,e as b,f as m}from"./chunk-R3TGQKBD.js";import{a as p,b as g}from"./chunk-WT3YKOQJ.js";import{withResult as s}from"@byteslice/result";import{render as f}from"ink";import R from"http";import{withResult as P}from"@byteslice/result";import*as l from"zod";var A=8765,y=`http://localhost:${A}`,j=l.object({code:l.string(),state:l.string()}),O=`
1
+ import{a as g}from"./chunk-RJOLKCKW.js";import{a as k,b as v,c as C,d as w,e as b,f as m}from"./chunk-R3TGQKBD.js";import{a as p}from"./chunk-OEQFVEK4.js";import{withResult as s}from"@byteslice/result";import{render as f}from"ink";import R from"http";import{withResult as P}from"@byteslice/result";import*as l from"zod";var A=8765,y=`http://localhost:${A}`,j=l.object({code:l.string(),state:l.string()}),O=`
2
2
  <!DOCTYPE html>
3
3
  <html lang="en">
4
4
  <head>
@@ -0,0 +1 @@
1
+ import{a as p}from"./chunk-Y7H7V3KU.js";import{a as l}from"./chunk-RJOLKCKW.js";import{a as s}from"./chunk-OEQFVEK4.js";import{existsSync as S}from"fs";import{resolve as v}from"path";import m from"process";import{withResult as F}from"@byteslice/result";import{configFileName as D,generateConfig as T}from"@swirls/sdk/config";import{render as c}from"ink";import{Box as d,render as h,Text as g}from"ink";import w from"ink-text-input";import{useState as x}from"react";import{z as C}from"zod";import{jsx as i,jsxs as I}from"react/jsx-runtime";function y(t){let[r,o]=x(""),[e,a]=x(null);return I(d,{flexDirection:"column",children:[I(d,{children:[i(g,{children:"Enter project ID (UUID): "}),i(w,{value:r,onChange:n=>{a(null),o(n)},onSubmit:n=>{if(a(null),n.trim()===""){setImmediate(()=>t.onInput());return}let f=C.uuid().safeParse(n);if(!f.success){a("Invalid UUID. Please try again."),o("");return}setImmediate(()=>t.onInput(f.data))}})]}),e&&i(g,{color:"red",children:e})]})}async function P(){return new Promise(t=>{let r=h(i(y,{onInput:o=>{r.unmount(),t(o)}}))})}import{jsx as u}from"react/jsx-runtime";async function M(){let t=v(m.cwd(),D);S(t)&&(c(u(s,{message:`Configuration already exists at ${t}.`})),m.exit(1));let r=await P(),o=await F(async()=>{let e=T(r);await p(t,e)},e=>new Error("Failed to create configuration",{cause:e}));o.failure&&(c(u(s,{message:o.failure.message})),m.exit(1)),c(u(l,{message:`Success! Created configuration at ${t}`}))}export{M as initializeConfig};
@@ -0,0 +1 @@
1
+ import{a as T}from"./chunk-N2UFNXNM.js";import{f as x}from"./chunk-R3TGQKBD.js";import{a as c}from"./chunk-OEQFVEK4.js";import{withResult as y}from"@byteslice/result";import{render as g}from"ink";import{Box as f,Text as u}from"ink";import{Fragment as B}from"react";import{Fragment as b,jsx as r,jsxs as p}from"react/jsx-runtime";function k(t){return typeof t=="boolean"?t?p(b,{children:[r(u,{color:"green",children:"\u2714"})," yes"]}):"no":String(t)}function C(t,o){return o.map(n=>{let e=n.key in t?k(t[n.key]):null;return{column:n,value:e}})}function D(t,o,n=1){return o.map(e=>{let a=String(e).length,l=t.map(m=>e in m&&(typeof m[e]=="string"||typeof m[e]=="number")?String(m[e]).length:0),s=Math.max(...l,a)+n*2;return{name:String(e),key:e,width:s}})}function d(t){return r(u,{children:Array(t.width).fill("\u2500").join("")})}function w(t){let o=D(t.data,t.keys),n=o.reduce((e,a)=>e+a.width,0);return p(f,{flexDirection:"column",width:n,children:[r(d,{width:n}),r(f,{flexDirection:"row",children:o.map(e=>r(f,{width:e.width,children:r(u,{bold:!0,color:"blue",children:e.name})},e.name))}),r(d,{width:n}),r(f,{flexDirection:"column",children:t.data.map((e,a)=>{let l=C(e,o);return p(B,{children:[r(f,{flexDirection:"row",children:l.map(s=>r(f,{width:s.column.width,children:r(u,{children:s.value})},s.column.name))}),r(d,{width:n})]},`row-${a}`)})})]})}import{jsx as h}from"react/jsx-runtime";async function v(t,o){let n=await y(()=>T(t.project),i=>new Error(i.message));n.failure&&(g(h(c,{message:n.failure.message})),process.exit(1));let e=await x(this),a=await y(()=>e.buckets.listFiles({projectId:n.data,path:o}),i=>new Error(`Failed to list files: ${i.message}`,{cause:i}));a.failure&&(g(h(c,{message:a.failure.message})),process.exit(1));let{files:l,folders:s}=a.data;if(s.length===0&&l.length===0){console.log("No files or folders found.");return}let m=[...s.map(i=>({type:"folder",name:i.name,size:"-"})),...l.map(i=>({type:"file",name:i.name,size:i.size?F(i.size):"-"}))];g(h(w,{keys:["type","name","size"],data:m}))}function F(t){if(t===0)return"0 B";let o=1024,n=["B","KB","MB","GB","TB"],e=Math.floor(Math.log(t)/Math.log(o));return`${parseFloat((t/o**e).toFixed(2))} ${n[e]}`}export{v as list};
@@ -0,0 +1 @@
1
+ import{a as g}from"./chunk-RJOLKCKW.js";import{a as u}from"./chunk-N2UFNXNM.js";import{f}from"./chunk-R3TGQKBD.js";import{a as t}from"./chunk-OEQFVEK4.js";import{readFile as h}from"fs/promises";import{basename as x}from"path";import{withResult as r}from"@byteslice/result";import{render as a}from"ink";import{jsx as o}from"react/jsx-runtime";async function L(w,p,m){let s=await r(()=>u(w.project),e=>new Error(e.message));s.failure&&(a(o(t,{message:s.failure.message})),process.exit(1));let i=await r(()=>h(p),e=>new Error(`Failed to read file: ${e.message}`,{cause:e}));i.failure&&(a(o(t,{message:i.failure.message})),process.exit(1));let l=x(p),d=m?`${m}/${l}`:l,U=await f(this),n=await r(()=>U.buckets.createSignedUploadUrl({projectId:s.data,path:d}),e=>new Error(`Failed to get upload URL: ${e.message}`,{cause:e}));n.failure&&(a(o(t,{message:n.failure.message})),process.exit(1));let c=await r(async()=>{let e=await fetch(n.data.signedUrl,{method:"PUT",headers:{"Content-Type":"application/octet-stream","x-upsert":"true"},body:i.data});if(!e.ok)throw new Error(`Upload failed: ${e.statusText}`);return e},e=>new Error(`Failed to upload file: ${e.message}`,{cause:e}));c.failure&&(a(o(t,{message:c.failure.message})),process.exit(1)),a(o(g,{message:`Uploaded ${l} to ${d}`}))}export{L as upload};
@@ -0,0 +1 @@
1
+ import{a as m}from"./chunk-RJOLKCKW.js";import{a as n}from"./chunk-N2UFNXNM.js";import{f as c}from"./chunk-R3TGQKBD.js";import{a as s}from"./chunk-OEQFVEK4.js";import{withResult as p}from"@byteslice/result";import{render as o}from"ink";import{jsx as i}from"react/jsx-runtime";async function j(a,l){let t=await p(()=>n(a.project),r=>new Error(r.message));t.failure&&(o(i(s,{message:t.failure.message})),process.exit(1));let g=await c(this),e=await p(()=>g.buckets.createSignedUrl({projectId:t.data,path:l,expiresIn:a.expires}),r=>new Error(`Failed to create signed URL: ${r.message}`,{cause:r}));e.failure&&(o(i(s,{message:e.failure.message})),process.exit(1)),console.log(e.data.signedUrl),o(i(m,{message:`URL expires at ${e.data.expiresAt}`}))}export{j as url};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Swirls command line application",
5
5
  "author": {
6
6
  "name": "Swirls",
@@ -21,7 +21,7 @@
21
21
  "postbuild": "chmod +x ./dist/cli.js",
22
22
  "dev": "op run --no-masking --env-file=.env.development -- tsup --watch",
23
23
  "prepublishOnly": "SWIRLS_ENV=production bun run build",
24
- "publish:cli": "bun publish"
24
+ "pkg:publish": "bun publish"
25
25
  },
26
26
  "dependencies": {
27
27
  "@byteslice/result": "0.3.0",
@@ -30,6 +30,7 @@
30
30
  "@orpc/contract": "1.12.2",
31
31
  "@stricli/auto-complete": "1.2.4",
32
32
  "@stricli/core": "1.2.4",
33
+ "@swirls/sdk": "0.0.2",
33
34
  "ink": "6.4.0",
34
35
  "ink-select-input": "6.2.0",
35
36
  "ink-spinner": "5.0.0",
@@ -40,7 +41,6 @@
40
41
  },
41
42
  "devDependencies": {
42
43
  "@swirls/core": "0.0.1",
43
- "@swirls/sdk": "0.0.1",
44
44
  "@types/node": "24.10.0",
45
45
  "@types/react": "19.2.6",
46
46
  "dotenv": "16.4.7",
@@ -1,2 +0,0 @@
1
- import g from"path";import{z as o}from"zod";var a="swirls.config.ts",r="@swirls/sdk/config",s="swirls.gen.ts",d=o.object({projectId:o.uuid(),genPath:o.string().min(1)});function m(t){return[`import { defineConfig } from '${r}'`,"","export default defineConfig({"," // swirls project identifier",` projectId: '${t||""}',`," // path to generated code",` genPath: 'src/${s}',`,"})",""].join(`
2
- `)}import n from"fs/promises";import c from"path";async function l(t,e){let i=c.dirname(t);await n.mkdir(i,{recursive:!0}),await n.writeFile(t,e,"utf-8")}export{a,d as b,m as c,l as d};
@@ -1 +0,0 @@
1
- import{Box as t,Text as o}from"ink";import{jsx as s,jsxs as r}from"react/jsx-runtime";function l(e){return r(t,{flexDirection:"column",children:[s(o,{color:"red",children:e.message}),s(o,{children:"If this issue persists, send us an email at help@byteslice.co, and we can help you out."})]})}import{Text as n}from"ink";import{jsx as i}from"react/jsx-runtime";function x(e){return i(n,{color:"green",children:e.message})}export{l as a,x as b};
@@ -1 +0,0 @@
1
- import{buildInstallCommand as y,buildUninstallCommand as v}from"@stricli/auto-complete";import{buildApplication as w,buildRouteMap as x}from"@stricli/core";import{buildCommand as o,buildRouteMap as p}from"@stricli/core";var u=o({loader:async()=>{let{login:e}=await import("./implementation-LPXYQAMF.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log in with an existing account"}}),m=o({loader:async()=>{let{logout:e}=await import("./implementation-LPXYQAMF.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log out of an existing account"}}),i=p({routes:{login:u,logout:m},docs:{brief:"Auth commands"}});import{buildCommand as r,buildRouteMap as d}from"@stricli/core";var f=r({loader:async()=>{let{generateCode:e}=await import("./generate-code-M57HI5UQ.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Generate application code and types"}}),b=r({loader:async()=>{let{initializeConfig:e}=await import("./initialize-config-CQ27WZUI.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Initialize Swirls configuration file"}}),s=d({routes:{gen:f,init:b},docs:{brief:"Developer commands"}});import{buildCommand as g,buildRouteMap as h}from"@stricli/core";var C=g({loader:async()=>{let{createProject:e}=await import("./create-project-2CO4VDK2.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project name",parse:String,placeholder:"name"}]}},docs:{brief:"Create a new project"}}),n=h({routes:{create:C},docs:{brief:"Project commands"}});var a="@swirls/cli",c="0.0.11",l="Swirls command line application";var k=x({routes:{auth:i,dev:s,project:n,install:y("cli",{bash:"__cli_bash_complete"}),uninstall:v("cli",{bash:!0})},docs:{brief:l,hideRoute:{install:!0,uninstall:!0}}}),O=w(k,{name:a,versionInfo:{currentVersion:c}});import j from"fs";import R from"fs/promises";import S from"os";import _ from"path";function H(e){return{fs:j,fsPromise:R,os:S,path:_,process:e}}export{O as a,H as b};
@@ -1 +0,0 @@
1
- import{f as o}from"./chunk-R3TGQKBD.js";import{a as c,b as i}from"./chunk-WT3YKOQJ.js";import{withResult as n}from"@byteslice/result";import{render as s}from"ink";import{jsx as a}from"react/jsx-runtime";async function j(p,t){let m=await o(this),e=await n(()=>m.projects.createProject({name:t}),r=>new Error(`Failed to create project: ${r.message}`,{cause:r}));e.failure&&(s(a(c,{message:e.failure.message})),process.exit(1)),s(a(i,{message:`Success! Created "${t}" project: ${e.data.id}`}))}export{j as createProject};
@@ -1,73 +0,0 @@
1
- import{a as w,b as F,d as A}from"./chunk-PL5KWBVQ.js";import{f as S}from"./chunk-R3TGQKBD.js";import{a as y,b as P}from"./chunk-WT3YKOQJ.js";import C from"process";import{withResult as j}from"@byteslice/result";var O=(e,r)=>e.anyOf.length?e.anyOf.length===1?a(e.anyOf[0],{...r,path:[...r.path,"anyOf",0]}):`z.union([${e.anyOf.map((t,o)=>a(t,{...r,path:[...r.path,"anyOf",o]})).join(", ")}])`:"z.any()";var N=e=>"z.boolean()";var E=e=>"z.any()";var T=(e,r)=>`z.union([${e.type.map(t=>a({...e,type:t},{...r,withoutDefaults:!0})).join(", ")}])`;var I=(e,r)=>`z.any().refine((value) => !${a(e.not,{...r,path:[...r.path,"not"]})}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;var J=e=>"z.null()";var L=e=>[e.slice(0,e.length/2),e.slice(e.length/2)];var c=Symbol("Original index"),ae=e=>{let r=[];for(let t=0;t<e.length;t++){let o=e[t];if(typeof o=="boolean")r.push(o?{[c]:t}:{[c]:t,not:{}});else{if(c in o)return e;r.push({...o,[c]:t})}}return r};function m(e,r){if(e.allOf.length===0)return"z.never()";if(e.allOf.length===1){let t=e.allOf[0];return a(t,{...r,path:[...r.path,"allOf",t[c]]})}else{let[t,o]=L(ae(e.allOf));return`z.intersection(${m({allOf:t},r)}, ${m({allOf:o},r)})`}}function u(e,r,t){let o=e[r],n="";if(o!==void 0){let s=t({value:o,json:JSON.stringify(o)});if(s){let i=s[0],p=s.length===3?s[1]:"",f=s.length===3?s[2]:s[1];n+=i,e.errorMessage?.[r]!==void 0&&(n+=p+JSON.stringify(e.errorMessage[r])),n+=f}}return n}var M=(e,r)=>{if(Array.isArray(e.items))return`z.tuple([${e.items.map((o,n)=>a(o,{...r,path:[...r.path,"items",n]}))}])`;let t=e.items?`z.array(${a(e.items,{...r,path:[...r.path,"items"]})})`:"z.array(z.any())";return t+=u(e,"minItems",({json:o})=>[`.min(${o}`,", ",")"]),t+=u(e,"maxItems",({json:o})=>[`.max(${o}`,", ",")"]),e.uniqueItems===!0&&(t+=u(e,"uniqueItems",()=>[".unique(","",")"])),t};var R=e=>`z.literal(${JSON.stringify(e.const)})`;var D=e=>e.enum.length===0?"z.never()":e.enum.length===1?`z.literal(${JSON.stringify(e.enum[0])})`:e.enum.every(r=>typeof r=="string")?`z.enum([${e.enum.map(r=>JSON.stringify(r))}])`:`z.union([${e.enum.map(r=>`z.literal(${JSON.stringify(r)})`).join(", ")}])`;var q=(e,r)=>{let t=a(e.if,{...r,path:[...r.path,"if"]}),o=a(e.then,{...r,path:[...r.path,"then"]}),n=a(e.else,{...r,path:[...r.path,"else"]});return`z.union([${o}, ${n}]).superRefine((value,ctx) => {
2
- const result = ${t}.safeParse(value).success
3
- ? ${o}.safeParse(value)
4
- : ${n}.safeParse(value);
5
- if (!result.success) {
6
- result.error.errors.forEach((error) => ctx.addIssue(error))
7
- }
8
- })`};var _=e=>{let r="z.number()";return e.type==="integer"?r+=u(e,"type",()=>[".int(",")"]):r+=u(e,"format",({value:t})=>{if(t==="int64")return[".int(",")"]}),r+=u(e,"multipleOf",({value:t,json:o})=>t===1?r.startsWith("z.number().int(")?void 0:[".int(",")"]:[`.multipleOf(${o}`,", ",")"]),typeof e.minimum=="number"?e.exclusiveMinimum===!0?r+=u(e,"minimum",({json:t})=>[`.gt(${t}`,", ",")"]):r+=u(e,"minimum",({json:t})=>[`.gte(${t}`,", ",")"]):typeof e.exclusiveMinimum=="number"&&(r+=u(e,"exclusiveMinimum",({json:t})=>[`.gt(${t}`,", ",")"])),typeof e.maximum=="number"?e.exclusiveMaximum===!0?r+=u(e,"maximum",({json:t})=>[`.lt(${t}`,", ",")"]):r+=u(e,"maximum",({json:t})=>[`.lte(${t}`,", ",")"]):typeof e.exclusiveMaximum=="number"&&(r+=u(e,"exclusiveMaximum",({json:t})=>[`.lt(${t}`,", ",")"])),r};var $=(e,r)=>e.oneOf.length?e.oneOf.length===1?a(e.oneOf[0],{...r,path:[...r.path,"oneOf",0]}):`z.any().superRefine((x, ctx) => {
9
- const schemas = [${e.oneOf.map((t,o)=>a(t,{...r,path:[...r.path,"oneOf",o]})).join(", ")}];
10
- const errors = schemas.reduce<z.ZodError[]>(
11
- (errors, schema) =>
12
- ((result) =>
13
- result.error ? [...errors, result.error] : errors)(
14
- schema.safeParse(x),
15
- ),
16
- [],
17
- );
18
- if (schemas.length - errors.length !== 1) {
19
- ctx.addIssue({
20
- path: ctx.path,
21
- code: "invalid_union",
22
- unionErrors: errors,
23
- message: "Invalid input: Should pass single schema",
24
- });
25
- }
26
- })`:"z.any()";var v=e=>{let r=e.split(`
27
- `);return`/**${r.length===1?r[0]:`
28
- ${r.map(o=>`* ${o}`).join(`
29
- `)}
30
- `}*/
31
- `},k=(e,r)=>{let t=e.description;return t?`
32
- ${v(t)}${r}`:r};function U(e,r){let t;e.properties&&(Object.keys(e.properties).length?(t="z.object({ ",t+=Object.keys(e.properties).map(i=>{let p=e.properties[i],f=`${JSON.stringify(i)}: ${a(p,{...r,path:[...r.path,"properties",i]})}`;r.withJsdocs&&typeof p=="object"&&(f=k(p,f));let ie=typeof p=="object"&&p.default!==void 0,se=Array.isArray(e.required)?e.required.includes(i):typeof p=="object"&&p.required===!0;return!ie&&!se?`${f}.optional()`:f}).join(", "),t+=" })"):t="z.object({})");let o=e.additionalProperties!==void 0?a(e.additionalProperties,{...r,path:[...r.path,"additionalProperties"]}):void 0,n;if(e.patternProperties){let i=Object.fromEntries(Object.entries(e.patternProperties).map(([p,f])=>[p,a(f,{...r,path:[...r.path,"patternProperties",p]})],{}));n="",t?o?n+=`.catchall(z.union([${[...Object.values(i),o].join(", ")}]))`:Object.keys(i).length>1?n+=`.catchall(z.union([${Object.values(i).join(", ")}]))`:n+=`.catchall(${Object.values(i)})`:o?n+=`z.record(z.union([${[...Object.values(i),o].join(", ")}]))`:Object.keys(i).length>1?n+=`z.record(z.union([${Object.values(i).join(", ")}]))`:n+=`z.record(${Object.values(i)})`,n+=`.superRefine((value, ctx) => {
33
- `,n+=`for (const key in value) {
34
- `,o&&(e.properties?n+=`let evaluated = [${Object.keys(e.properties).map(p=>JSON.stringify(p)).join(", ")}].includes(key)
35
- `:n+=`let evaluated = false
36
- `);for(let p in e.patternProperties)n+="if (key.match(new RegExp("+JSON.stringify(p)+`))) {
37
- `,o&&(n+=`evaluated = true
38
- `),n+="const result = "+i[p]+`.safeParse(value[key])
39
- `,n+=`if (!result.success) {
40
- `,n+=`ctx.addIssue({
41
- path: [...ctx.path, key],
42
- code: 'custom',
43
- message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
44
- params: {
45
- issues: result.error.issues
46
- }
47
- })
48
- `,n+=`}
49
- `,n+=`}
50
- `;o&&(n+=`if (!evaluated) {
51
- `,n+="const result = "+o+`.safeParse(value[key])
52
- `,n+=`if (!result.success) {
53
- `,n+=`ctx.addIssue({
54
- path: [...ctx.path, key],
55
- code: 'custom',
56
- message: \`Invalid input: must match catchall schema\`,
57
- params: {
58
- issues: result.error.issues
59
- }
60
- })
61
- `,n+=`}
62
- `,n+=`}
63
- `),n+=`}
64
- `,n+="})"}let s=t?n?t+n:o?o==="z.never()"?t+".strict()":t+`.catchall(${o})`:t:n||(o?`z.record(${o})`:"z.record(z.any())");return l.an.anyOf(e)&&(s+=`.and(${O({...e,anyOf:e.anyOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),l.a.oneOf(e)&&(s+=`.and(${$({...e,oneOf:e.oneOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),l.an.allOf(e)&&(s+=`.and(${m({...e,allOf:e.allOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),s}var B=e=>{let r="z.string()";r+=u(e,"format",({value:o})=>{switch(o){case"email":return[".email(",")"];case"ip":return[".ip(",")"];case"ipv4":return['.ip({ version: "v4"',", message: "," })"];case"ipv6":return['.ip({ version: "v6"',", message: "," })"];case"uri":return[".url(",")"];case"uuid":return[".uuid(",")"];case"date-time":return[".datetime({ offset: true",", message: "," })"];case"time":return[".time(",")"];case"date":return[".date(",")"];case"binary":return[".base64(",")"];case"duration":return[".duration(",")"]}}),r+=u(e,"pattern",({json:o})=>[`.regex(new RegExp(${o})`,", ",")"]),r+=u(e,"minLength",({json:o})=>[`.min(${o}`,", ",")"]),r+=u(e,"maxLength",({json:o})=>[`.max(${o}`,", ",")"]),r+=u(e,"contentEncoding",({value:o})=>{if(o==="base64")return[".base64(",")"]});let t=u(e,"contentMediaType",({value:o})=>{if(o==="application/json")return['.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',", ",")"]});return t!=""&&(r+=t,r+=u(e,"contentSchema",({value:o})=>{if(o&&o instanceof Object)return[`.pipe(${a(o)}`,", ",")"]})),r};var G=(e,r)=>e.oneOf.length?e.oneOf.length===1?a(e.oneOf[0],{...r,path:[...r.path,"oneOf",0]}):`z.discriminatedUnion("${e.discriminator.propertyName}", [${e.oneOf.map((t,o)=>a(t,{...r,path:[...r.path,"oneOf",o]})).join(", ")}])`:"z.any()";var Z=(e,...r)=>Object.keys(e).reduce((t,o)=>(r.includes(o)||(t[o]=e[o]),t),{});var X=(e,r)=>`${a(Z(e,"nullable"),r,!0)}.nullable()`;var a=(e,r={seen:new Map,path:[]},t)=>{if(typeof e!="object")return e?"z.any()":"z.never()";if(r.parserOverride){let s=r.parserOverride(e,r);if(typeof s=="string")return s}let o=r.seen.get(e);if(o){if(o.r!==void 0)return o.r;if(r.depth===void 0||o.n>=r.depth)return"z.any()";o.n+=1}else o={r:void 0,n:0},r.seen.set(e,o);let n=fe(e,r);return t||(r.withoutDescribes||(n=pe(e,n)),r.withoutDefaults||(n=ue(e,n)),n=le(e,n)),o.r=n,n},pe=(e,r)=>(e.description&&(r+=`.describe(${JSON.stringify(e.description)})`),r),ue=(e,r)=>(e.default!==void 0&&(r+=`.default(${JSON.stringify(e.default)})`),r),le=(e,r)=>(e.readOnly&&(r+=".readonly()"),r),fe=(e,r)=>l.a.nullable(e)?X(e,r):l.an.object(e)?U(e,r):l.an.array(e)?M(e,r):l.an.anyOf(e)?O(e,r):l.an.allOf(e)?m(e,r):l.a.simpleDiscriminatedOneOf(e)?G(e,r):l.a.oneOf(e)?$(e,r):l.a.not(e)?I(e,r):l.an.enum(e)?D(e):l.a.const(e)?R(e):l.a.multipleType(e)?T(e,r):l.a.primitive(e,"string")?B(e):l.a.primitive(e,"number")||l.a.primitive(e,"integer")?_(e):l.a.primitive(e,"boolean")?N(e):l.a.primitive(e,"null")?J(e):l.a.conditional(e)?q(e,r):E(e),l={an:{object:e=>e.type==="object",array:e=>e.type==="array",anyOf:e=>e.anyOf!==void 0,allOf:e=>e.allOf!==void 0,enum:e=>e.enum!==void 0},a:{nullable:e=>e.nullable===!0,multipleType:e=>Array.isArray(e.type),not:e=>e.not!==void 0,const:e=>e.const!==void 0,primitive:(e,r)=>e.type===r,conditional:e=>!!("if"in e&&e.if&&"then"in e&&"else"in e&&e.then&&e.else),simpleDiscriminatedOneOf:e=>{if(!e.oneOf||!Array.isArray(e.oneOf)||e.oneOf.length===0||!e.discriminator||typeof e.discriminator!="object"||!("propertyName"in e.discriminator)||typeof e.discriminator.propertyName!="string")return!1;let r=e.discriminator.propertyName;return e.oneOf.every(t=>{if(!t||typeof t!="object"||t.type!=="object"||!t.properties||typeof t.properties!="object"||!(r in t.properties))return!1;let o=t.properties[r];return o&&typeof o=="object"&&o.type==="string"&&(o.const!==void 0||o.enum&&Array.isArray(o.enum)&&o.enum.length===1)&&Array.isArray(t.required)&&t.required.includes(r)})},oneOf:e=>e.oneOf!==void 0}};var h=(e,{module:r,name:t,type:o,noImport:n,...s}={})=>{if(o&&(!t||r!=="esm"))throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");let i=a(e,{module:r,name:t,path:[],seen:new Map,...s}),p=s.withJsdocs&&typeof e!="boolean"&&e.description?v(e.description):"";if(r==="cjs"?(i=`${p}module.exports = ${t?`{ ${JSON.stringify(t)}: ${i} }`:i}
65
- `,n||(i=`${p}const { z } = require("zod")
66
-
67
- ${i}`)):r==="esm"?(i=`${p}export ${t?`const ${t} =`:"default"} ${i}
68
- `,n||(i=`import { z } from "zod"
69
-
70
- ${i}`)):t&&(i=`${p}const ${t} = ${i}`),o&&t){let f=typeof o=="string"?o:`${t[0].toUpperCase()}${t.substring(1)}`;i+=`export type ${f} = z.infer<typeof ${t}>
71
- `}return i};function K(e){return e?e.toLowerCase():""}var me=[/(\p{Ll}|\p{N})(\p{Lu})/gu,/(\p{Lu})(\p{Lu}\p{Ll})/gu],ce=/[^\p{L}\p{N}]+/gu;function H(e,r={}){if(!e)return"";let{splitRegexp:t=me,stripRegexp:o=ce,transform:n=K,delimiter:s=" "}=r,i=W(W(e,t,"$1\0$2"),o,"\0"),p=0,f=i.length;for(;i.charAt(p)==="\0";)p++;for(;i.charAt(f-1)==="\0";)f--;return i.slice(p,f).split("\0").map(n).join(s)}function W(e,r,t){return r instanceof RegExp?e.replace(r,t):r.reduce((o,n)=>o.replace(n,t),e)}function z(e,r){let t=e.charAt(0),o=e.slice(1).toLowerCase();return r>0&&t>="0"&&t<="9"?`_${t}${o}`:`${t.toUpperCase()}${o}`}function x(e,r={}){return e?H(e,{delimiter:"",transform:z,...r}):""}function de(e,r){return r===0?e.toLowerCase():z(e,r)}function Q(e,r={}){return e?x(e,{transform:de,...r}):""}function V(e,r){let t=["import { registerForm } from '@swirls/sdk/form'","import { z } from 'zod'",""],o=e.flatMap(({name:n,schema:s})=>ge(n,s));return[...r,...t,...o,...ye(e),...Oe(e),...$e(e)].join(`
72
- `)}function ge(e,r){let t=h(r,{module:"esm",name:b(e).camel,noImport:!0,type:!0}),[o,n]=t.split(`
73
- `);if(!o||!n)throw new Error("Failed to generate standard schema");return[`// Form schema: ${e}`,o,"",n,""]}function ye(e){return["// Form registry","export const registry = {",...e.flatMap(({name:r,id:t})=>[` '${r}': {`,` id: '${t}',`,` name: '${r}',`,` schema: ${b(r).camel},`," },"]),"} as const",""]}function Oe(e){return["// Form registration","export function registerForms() {",...e.map(({name:r})=>` registerForm('${r}', registry['${r}'])`),"}",""]}function $e(e){let r="@swirls/sdk/form";return[`// Module augmentation for ${r}`,`declare module '${r}' {`," interface FormRegistry {",...e.flatMap(({name:t,id:o})=>[` '${t}': {`,` id: '${o}'`,` name: '${t}'`,` schema: typeof ${b(t).camel}`," }"])," }","}",""]}function b(e){return{camel:`${Q(e)}Schema`,pascal:`${x(e)}Schema`}}import{render as d}from"ink";import{Box as xe,Text as Y}from"ink";import we from"ink-spinner";import{jsx as ee,jsxs as re}from"react/jsx-runtime";function te(e){return re(xe,{children:[ee(Y,{color:"cyan",children:ee(we,{type:"dots"})}),re(Y,{children:[" ",e.message]})]})}import{existsSync as ve}from"fs";import{resolve as he}from"path";import{createJiti as ze}from"jiti";async function oe(){let e=he(process.cwd(),w);if(!ve(e))throw new Error(`Config file not found in project root: ${w}`);let t=await ze(import.meta.url).import(e,{default:!0});return F.parse(t)}async function ne(e,r){let t=await S(e),{results:o}=await t.forms.listForms({projectId:r});function n(i){return i.schema!=null}return o.filter(n).map(i=>({id:i.id,name:i.name,schema:i.schema}))}import{jsx as g}from"react/jsx-runtime";async function Mt(){let e=await j(()=>oe(),s=>new Error("Failed to load configuration",{cause:s}));e.failure&&(d(g(y,{message:e.failure.message})),C.exit(1));let{projectId:r,genPath:t}=e.data;d(g(te,{message:"Generating form code..."}));let o=await j(async()=>{let s=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],i=await ne(this,r);return V(i,s)},s=>new Error(`Failed to generate form code: ${s.message}`,{cause:s}));o.failure&&(d(g(y,{message:o.failure.message})),C.exit(1));let n=await j(()=>A(t,o.data),s=>new Error("Failed to write code file",{cause:s}));n.failure&&(d(g(y,{message:n.failure.message})),C.exit(1)),d(g(P,{message:`Success! Generated code at ${t}`}))}export{Mt as generateCode};
@@ -1 +0,0 @@
1
- import{a as p,c as d,d as g}from"./chunk-PL5KWBVQ.js";import{a as s,b as l}from"./chunk-WT3YKOQJ.js";import{existsSync as F}from"fs";import{resolve as D}from"path";import m from"process";import{withResult as T}from"@byteslice/result";import{render as c}from"ink";import{Box as x,render as C,Text as I}from"ink";import y from"ink-text-input";import{useState as P}from"react";import{z as S}from"zod";import{jsx as i,jsxs as h}from"react/jsx-runtime";function v(t){let[r,o]=P(""),[e,a]=P(null);return h(x,{flexDirection:"column",children:[h(x,{children:[i(I,{children:"Enter project ID (UUID): "}),i(y,{value:r,onChange:n=>{a(null),o(n)},onSubmit:n=>{if(a(null),n.trim()===""){setImmediate(()=>t.onInput());return}let f=S.uuid().safeParse(n);if(!f.success){a("Invalid UUID. Please try again."),o("");return}setImmediate(()=>t.onInput(f.data))}})]}),e&&i(I,{color:"red",children:e})]})}async function w(){return new Promise(t=>{let r=C(i(v,{onInput:o=>{r.unmount(),t(o)}}))})}import{jsx as u}from"react/jsx-runtime";async function M(){let t=D(m.cwd(),p);F(t)&&(c(u(s,{message:`Configuration already exists at ${t}.`})),m.exit(1));let r=await w(),o=await T(async()=>{let e=d(r);await g(t,e)},e=>new Error("Failed to create configuration",{cause:e}));o.failure&&(c(u(s,{message:o.failure.message})),m.exit(1)),c(u(l,{message:`Success! Created configuration at ${t}`}))}export{M as initializeConfig};