@lunora/cli 1.0.0-alpha.327 → 1.0.0-alpha.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/dispatch.mjs +1 -1
- package/dist/packem_chunks/handler.mjs +1 -1
- package/dist/packem_chunks/handler10.mjs +2 -2
- package/dist/packem_chunks/handler11.mjs +1 -1
- package/dist/packem_chunks/handler12.mjs +1 -1
- package/dist/packem_chunks/handler13.mjs +1 -1
- package/dist/packem_chunks/handler14.mjs +1 -1
- package/dist/packem_chunks/handler15.mjs +1 -1
- package/dist/packem_chunks/handler16.mjs +1 -1
- package/dist/packem_chunks/handler17.mjs +1 -1
- package/dist/packem_chunks/handler18.mjs +1 -7
- package/dist/packem_chunks/handler19.mjs +7 -1
- package/dist/packem_chunks/handler2.mjs +1 -1
- package/dist/packem_chunks/handler20.mjs +1 -1
- package/dist/packem_chunks/handler21.mjs +1 -1
- package/dist/packem_chunks/handler22.mjs +1 -3
- package/dist/packem_chunks/handler23.mjs +3 -3
- package/dist/packem_chunks/handler24.mjs +3 -1
- package/dist/packem_chunks/handler25.mjs +1 -2
- package/dist/packem_chunks/handler26.mjs +2 -99
- package/dist/packem_chunks/handler27.mjs +99 -10
- package/dist/packem_chunks/handler28.mjs +10 -0
- package/dist/packem_chunks/handler3.mjs +1 -1
- package/dist/packem_chunks/handler4.mjs +1 -1
- package/dist/packem_chunks/handler5.mjs +1 -1
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/handler8.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +1 -1
- package/dist/packem_chunks/runCodegenCommand.mjs +1 -1
- package/dist/packem_chunks/runDeployCommand.mjs +3 -3
- package/dist/packem_chunks/runDevCommand.mjs +1 -1
- package/dist/packem_chunks/runInitCommand.mjs +2 -2
- package/dist/packem_chunks/runResetCommand.mjs +1 -1
- package/dist/packem_chunks/runRpcCommand.mjs +1 -1
- package/dist/packem_shared/COMMANDS-u8aPCKxf.mjs +1 -0
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CyIsI3S1.mjs +1 -0
- package/dist/packem_shared/EXIT_CODE-D_XCixv8.mjs +1 -0
- package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
- package/dist/packem_shared/{cli-BzOfNDAr.mjs → cli-BQ3AyV_K.mjs} +2 -2
- package/dist/packem_shared/{command-B--jgXSc.mjs → command-CAXl2A1S.mjs} +1 -1
- package/dist/packem_shared/{commands-CNqednoX.mjs → commands-Cg06JNO2.mjs} +1 -1
- package/dist/packem_shared/{import-D7qdpSmJ.mjs → import-BRM1hs7j.mjs} +10 -10
- package/dist/packem_shared/{plan-B-KsxVne.mjs → plan-CtBB0rrT.mjs} +1 -1
- package/dist/packem_shared/{planDevCommand-BuJZzy-L.mjs → planDevCommand-tVTRd2QE.mjs} +1 -1
- package/dist/packem_shared/{render-lunora-error-DgaSmNLc.mjs → render-lunora-error-C3OJY5wk.mjs} +1 -1
- package/dist/packem_shared/runAddCommand-BsOrlyfD.mjs +1 -0
- package/dist/packem_shared/runExportCommand-slAq5BCF.mjs +5 -0
- package/dist/packem_shared/runMigrateGenerateCommand-Ii_WMZEA.mjs +11 -0
- package/dist/packem_shared/{storage-J4xhM4FU.mjs → storage-iyNnV-2G.mjs} +1 -1
- package/package.json +11 -11
- package/dist/packem_shared/COMMANDS-CP6waB2N.mjs +0 -1
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-BgMPHEoe.mjs +0 -1
- package/dist/packem_shared/EXIT_CODE-08cwt3MK.mjs +0 -1
- package/dist/packem_shared/admin-url-BhF5ufg1.mjs +0 -1
- package/dist/packem_shared/runAddCommand-Cf2q2y27.mjs +0 -1
- package/dist/packem_shared/runExportCommand-DxsJHYZt.mjs +0 -5
- package/dist/packem_shared/runMigrateGenerateCommand-CDHswpMU.mjs +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.329",
|
|
4
4
|
"description": "The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@bomb.sh/tab": "0.0.22",
|
|
55
|
-
"@lunora/advisor": "1.0.0-alpha.
|
|
56
|
-
"@lunora/bindings": "1.0.0-alpha.
|
|
57
|
-
"@lunora/codegen": "1.0.0-alpha.
|
|
58
|
-
"@lunora/config": "1.0.0-alpha.
|
|
59
|
-
"@lunora/container": "1.0.0-alpha.
|
|
60
|
-
"@lunora/d1": "1.0.0-alpha.
|
|
61
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
62
|
-
"@lunora/mcp": "1.0.0-alpha.
|
|
63
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
64
|
-
"@lunora/seed": "1.0.0-alpha.
|
|
55
|
+
"@lunora/advisor": "1.0.0-alpha.174",
|
|
56
|
+
"@lunora/bindings": "1.0.0-alpha.87",
|
|
57
|
+
"@lunora/codegen": "1.0.0-alpha.242",
|
|
58
|
+
"@lunora/config": "1.0.0-alpha.287",
|
|
59
|
+
"@lunora/container": "1.0.0-alpha.64",
|
|
60
|
+
"@lunora/d1": "1.0.0-alpha.154",
|
|
61
|
+
"@lunora/errors": "1.0.0-alpha.48",
|
|
62
|
+
"@lunora/mcp": "1.0.0-alpha.200",
|
|
63
|
+
"@lunora/runtime": "1.0.0-alpha.166",
|
|
64
|
+
"@lunora/seed": "1.0.0-alpha.172",
|
|
65
65
|
"@visulima/cerebro": "3.1.1",
|
|
66
66
|
"@visulima/error": "6.1.0",
|
|
67
67
|
"@visulima/fs": "6.0.7",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as i,R as m,V as p,r as s}from"./cli-BzOfNDAr.mjs";import"./EXIT_CODE-08cwt3MK.mjs";import"./createLogger-Cl18I8AX.mjs";import"./render-lunora-error-DgaSmNLc.mjs";export{i as COMMANDS,m as REGISTERED_COMMAND_NAMES,p as VERSION,s as runCli};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./admin-token-VdUnvnKW.mjs";import"./admin-url-BhF5ufg1.mjs";import"./EXIT_CODE-08cwt3MK.mjs";import{D as a,r as I}from"./import-D7qdpSmJ.mjs";import"./shared-D-zCOmgY.mjs";export{a as DEFAULT_IMPORT_BATCH_SIZE,I as runImportCommand};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isLunoraError as S,getCatalogEntry as _}from"@lunora/errors";const E={SUCCESS:0,FAILURE:1,USAGE:2,AUTH:3,PERMISSION:4,NOT_FOUND:5,CONFLICT:6,RATE_LIMITED:7,UNAVAILABLE:8,MISSING_DEPENDENCY:9,CANCELLED:130},U=new Map([[400,E.USAGE],[401,E.AUTH],[403,E.PERMISSION],[404,E.NOT_FOUND],[405,E.USAGE],[409,E.CONFLICT],[413,E.USAGE],[421,E.UNAVAILABLE],[422,E.USAGE],[429,E.RATE_LIMITED],[502,E.UNAVAILABLE],[503,E.UNAVAILABLE],[504,E.UNAVAILABLE],[507,E.USAGE]]),I=new Map([["CODEGEN_DIAGNOSTIC",E.USAGE],["CRON_EXPR_INVALID",E.USAGE],["CRON_EXPR_NOT_STATIC",E.USAGE],["CRON_NAME_NOT_STATIC",E.USAGE],["CRON_NON_STATIC_FN",E.USAGE],["CRON_NON_STATIC_VALUE",E.USAGE],["CRON_SCHEDULE_INVALID",E.USAGE],["CRON_SCHEDULE_NOT_STATIC",E.USAGE],["DUPLICATE_AGENT_BINDING",E.USAGE],["DUPLICATE_AGENT_CLASS",E.USAGE],["DUPLICATE_AGENT_NAME",E.USAGE],["DUPLICATE_CRON_NAME",E.USAGE],["DUPLICATE_MIGRATION_ID",E.USAGE],["DUPLICATE_QUEUE_BINDING",E.USAGE],["DUPLICATE_QUEUE_NAME",E.USAGE],["DUPLICATE_WORKFLOW_CLASS",E.USAGE],["LOCAL_DEPENDENCY_MISSING",E.MISSING_DEPENDENCY],["MIGRATION_ID_NOT_STATIC",E.USAGE],["NAMESPACE_COLLISION",E.USAGE],["SCHEMA_SNAPSHOT_PARSE",E.USAGE]]),N=A=>A===void 0?E.FAILURE:U.get(A)??E.FAILURE,T=A=>I.get(A)??N(_(A)?.status),L=A=>S(A)?I.get(A.code)??N(A.status):E.FAILURE,G=A=>"refused"in A;export{E as EXIT_CODE,T as exitCodeForCode,L as exitCodeForError,N as exitCodeForStatus,G as isRefusal};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readLiveDevServerState as a}from"@lunora/config";const l=new Set(["127.0.0.1","::1","[::1]","localhost"]),i=/\/$/u,n="http://localhost:8787",c=r=>r===void 0?n:a(r)?.url??n,d=r=>r.replace(i,""),u=(r,o,s)=>{const e=r??c(s);let t;try{t=new URL(e)}catch{o.error(`invalid --url: ${e}`);return}if(!l.has(t.hostname)&&t.protocol!=="https:"){o.error(`refusing to send the admin bearer over ${t.protocol}// to ${t.hostname} — use https for non-localhost targets`);return}return d(e)};export{c as a,d as n,u as r};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./EXIT_CODE-08cwt3MK.mjs";import"./resolve-DUCSc7jQ.mjs";import"./catalog-CahzmDLV.mjs";import{r as n,a as i,b as t}from"./commands-CNqednoX.mjs";export{n as runAddCommand,i as runBuildIndexCommand,t as runRegistryViewCommand};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{randomUUID as b}from"node:crypto";import{createWriteStream as x}from"node:fs";import{unlink as E,rename as S}from"node:fs/promises";import{r as T}from"./admin-token-VdUnvnKW.mjs";import{r as O}from"./admin-url-BhF5ufg1.mjs";import{EXIT_CODE as w,isRefusal as $,exitCodeForStatus as N}from"./EXIT_CODE-08cwt3MK.mjs";import{E as U}from"./shared-D-zCOmgY.mjs";const k=e=>{if(e===void 0)return;const r=e.split(",").map(t=>t.trim()).filter(t=>t.length>0);return r.length>0?r:void 0},p=async(e,r)=>{e.write(r)||await new Promise((t,a)=>{let d=o=>{};const n=()=>{e.removeListener("error",d),t()};d=o=>{e.removeListener("drain",n),a(o)},e.once("drain",n),e.once("error",d)})},I=async(e,r)=>{const t=e.getReader(),a=new TextDecoder;let d=0,n=0,o="",c=!1;try{for(;!c;){const i=await t.read();if(c=i.done,i.value===void 0)continue;d+=i.value.length,o+=a.decode(i.value,{stream:!0});let s=o.indexOf(`
|
|
2
|
-
`);for(;s!==-1;){n+=1;const l=`${o.slice(0,s)}
|
|
3
|
-
`;await p(r,l),o=o.slice(s+1),s=o.indexOf(`
|
|
4
|
-
`)}}return o.length>0&&(n+=1,await p(r,`${o}
|
|
5
|
-
`)),{bytes:d,rows:n}}finally{t.releaseLock()}},v=async(e,r)=>{if(r===void 0)return;const t=e;await new Promise(a=>{if(t.closed){a();return}t.once("close",()=>{a()}),t.destroy()});try{await E(r)}catch{}},P=async(e,r,t)=>{await new Promise((d,n)=>{e.end(o=>{const c=o??t();c===void 0?d():n(c)})});const a=t();if(a!==void 0)throw await v(e,r),a},A=async(e,r,t)=>{await P(e,r.stage,t);try{await S(r.stage,r.path)}catch(a){throw await v(e,r.stage),a}},y="export --format json needs a file destination (--out <file>) — with --out - the NDJSON stream already owns stdout.",_=e=>{const r=e.out===void 0||e.out==="-"?void 0:e.out;if(e.format==="json"&&r===void 0){e.logger.error(y);return}return{destination:r}},D=e=>{if(e.prod&&e.url===void 0)return e.logger.error("--prod requires an explicit --url (refusing to export from the implicit localhost worker)"),{refused:w.USAGE};const r=O(e.url,e.logger,e.cwd);if(r===void 0)return{refused:w.USAGE};const{token:t}=T({cwd:e.cwd??process.cwd(),token:e.token,url:r});if(!t)return e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)"),{refused:w.AUTH};const a=e.fetchImpl??globalThis.fetch;if(typeof a!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return{fetchImpl:a,requestUrl:`${r}${U}`,tables:k(e.tables),token:t}},G=async e=>{const r=_(e);if(r===void 0)return{bytes:0,code:w.USAGE,error:y,rows:0};const{destination:t}=r,a=D(e);if($(a))return{bytes:0,code:a.refused,error:"export: could not resolve the worker URL and admin token",rows:0};const{fetchImpl:d,requestUrl:n,tables:o,token:c}=a;e.logger.info(`POST ${n} -> export${o?` (tables: ${o.join(",")})`:""}`);const i=await d(n,{body:JSON.stringify(o?{tables:o}:{}),headers:{authorization:`Bearer ${c}`,"content-type":"application/json"},method:"POST"});if(!i.ok){const u=await i.text(),h=`export failed: HTTP ${String(i.status)}: ${u}`;return e.logger.error(h),{bytes:0,code:N(i.status),error:h,rows:0}}if(!i.body)return e.logger.error("export response carried no body"),{bytes:0,code:1,error:"export response carried no body",rows:0};const s=t===void 0?void 0:{path:t,stage:`${t}.${b()}.partial`},l=s===void 0?process.stdout:x(s.stage,{encoding:"utf8",mode:384});let g;s!==void 0&&l.on("error",u=>{g??=u});let f,m;try{({bytes:f,rows:m}=await I(i.body,l))}catch(u){throw await v(l,s?.stage),u}return s!==void 0&&(await A(l,s,()=>g),e.logger.success(`wrote ${String(m)} rows to ${s.path} (${String(f)} bytes)`)),{bytes:f,code:0,data:t===void 0?void 0:{bytes:f,out:t,rows:m,tables:o},rows:m}};export{G as runExportCommand};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{existsSync as p,mkdirSync as _,writeFileSync as v,mkdtempSync as x,rmSync as F,readFileSync as U}from"node:fs";import{tmpdir as O}from"node:os";import{discoverMigrations as k,discoverSchema as N,readPackageDependencies as D}from"@lunora/codegen";import{isInteractive as P,promptSelect as G,promptText as j}from"@lunora/config";import{LunoraError as T}from"@lunora/errors";import{join as l}from"@visulima/path";import{Project as w}from"ts-morph";import{r as z,t as L}from"./admin-token-VdUnvnKW.mjs";import{r as q,n as H}from"./admin-url-BhF5ufg1.mjs";import{isRefusal as B,exitCodeForStatus as W,EXIT_CODE as c}from"./EXIT_CODE-08cwt3MK.mjs";import{diffSnapshots as J,renderMigrationFile as V}from"./diffSnapshots-WWwx-KvZ.mjs";import X from"./schemaIrToSnapshot-BjK-0IRo.mjs";import{runExportCommand as Z}from"./runExportCommand-DxsJHYZt.mjs";import{r as K}from"./import-D7qdpSmJ.mjs";import{readAndLogBody as Q}from"../packem_chunks/runRpcCommand.mjs";const h="__lunora_reproject__",Y=e=>{if(!e.startsWith(h))return;const r=e.slice(h.length);return r===""?void 0:r},ee=".snapshot.json",R=/[^\da-z]+/gu,M=(e,r)=>{let t=0,o=e.length;for(;t<o&&e[t]===r;)t+=1;for(;o>t&&e[o-1]===r;)o-=1;return e.slice(t,o)},re=e=>{const r=M(e.toLowerCase().replaceAll(R,"_"),"_");return r===""?"auto":r},te=e=>{const r=(t,o=2)=>t.toString().padStart(o,"0");return`${String(e.getUTCFullYear())}${r(e.getUTCMonth()+1)}${r(e.getUTCDate())}${r(e.getUTCHours())}${r(e.getUTCMinutes())}${r(e.getUTCSeconds())}`},oe=e=>{if(p(e))try{const r=U(e,"utf8"),t=JSON.parse(r);if(t.version!==1)throw new T("INTERNAL",`unsupported snapshot version: ${t.version}`);return t}catch(r){const t=r instanceof Error?r.message:String(r);throw new T("INTERNAL",`failed to read ${e}: ${t}`,{cause:r})}},ke=e=>{const r=e.cwd??process.cwd(),t=l(r,"lunora","schema.ts");if(!p(t)){const m=`schema not found: ${t} — run \`vis generate lunora-table --name=<name>\` to create one`;return e.logger.error(m),{code:c.NOT_FOUND,empty:!0,error:m,migrationFile:""}}const o=new w({skipAddingFilesFromTsConfig:!0}),a=N(o,t),s=X(a),n=l(r,"lunora","migrations"),i=l(n,ee);let d;try{d=oe(i)}catch(m){const S=m instanceof Error?m.message:String(m);return e.logger.error(S),{code:c.USAGE,empty:!0,error:S,migrationFile:""}}const u=J(d,s);if(u.empty)return e.logger.info("no schema changes detected — snapshot is already up to date"),{code:0,empty:!0,migrationFile:""};const f=(e.now??(()=>new Date))(),y=re(e.name??"auto"),$=`${te(f)}_${y}.sql`,b=l(n,$);_(n,{recursive:!0});const C=V(y,u,f.toISOString());return v(b,C,"utf8"),v(i,`${JSON.stringify(s,void 0,4)}
|
|
2
|
-
`,"utf8"),e.logger.success(`wrote ${b}`),u.unsupported.length>0&&e.logger.warn(`${String(u.unsupported.length)} unsupported diff(s) — see the comment block in ${$} and write the SQL manually`),{code:0,empty:!1,migrationFile:b}},ne="migrations.ts",I=/^[A-Za-z_]\w*$/u,ae=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),A=/^import\s*\{\s*defineMigration\s*\}\s*from\s*["'](?:@lunora\/server|lunorash\/server)["'][^\n]*$/mu,ie=e=>`import { defineMigration } from "${D(e)?.has("lunorash")??!1?"lunorash/server":"@lunora/server"}";`,se="__lunora_admin__:runMigration",ce="__lunora_admin__:migrationStatus",de="/_lunora/migrate",le=e=>M(e.trim().toLowerCase().replaceAll(R,"-"),"-"),ue=e=>e.split("-").filter(r=>r.length>0).map((r,t)=>t===0?r:r.charAt(0).toUpperCase()+r.slice(1)).join(""),me=e=>{const r=l(e,"lunora","schema.ts");if(!p(r))return[];try{const t=new w({skipAddingFilesFromTsConfig:!0});return N(t,r).tables.map(o=>o.name)}catch{return[]}},ge=async e=>e.length>0?G("Which table does this migration iterate?",e.map(r=>({label:r,value:r}))):j("Target table for the migration: "),fe=async(e,r)=>{if(r.table!==void 0)return r.table;const t=r.promptTable??(P()?ge:void 0);if(t===void 0){r.logger.error("migrate create requires a target table when not running interactively — re-run with --table <table>");return}const a=(await t(me(e)))?.trim();if(a===void 0||a===""){r.logger.error("no table selected — re-run with --table <table>");return}return a},De=async e=>{const r=e.cwd??process.cwd(),t=le(e.name);if(t==="")return e.logger.error(`invalid migration name: "${e.name}" — must contain at least one alphanumeric character`),{code:c.USAGE,file:""};const o=ue(t);if(!I.test(o)||ae.has(o))return e.logger.error(`invalid migration name: "${e.name}" derives the export \`${o}\`, which is not a valid identifier — pick a name that starts with a letter and isn't a reserved word`),{code:c.USAGE,file:""};const a=await fe(r,e);if(a===void 0)return{code:c.USAGE,file:""};if(!I.test(a))return e.logger.error(`invalid table: "${a}" — must be a valid identifier ([A-Za-z_][A-Za-z0-9_]*)`),{code:c.USAGE,file:""};const s=l(r,"lunora"),n=l(s,ne);let i=p(n)?U(n,"utf8"):"";if(i.includes(`id: "${t}"`)||new RegExp(String.raw`\bexport const ${o}\b`,"u").test(i))return e.logger.error(`a migration with id "${t}" (export \`${o}\`) already exists in ${n}`),{code:c.CONFLICT,file:""};const d=ie(r);i.trim()===""?i=`${d}
|
|
3
|
-
`:A.test(i)?i=i.replace(A,d):i=`${d}
|
|
4
|
-
${i}`;const u=`export const ${o} = defineMigration({
|
|
5
|
-
id: "${t}",
|
|
6
|
-
table: "${a}",
|
|
7
|
-
up: (document) => document,
|
|
8
|
-
});`;return _(s,{recursive:!0}),v(n,`${i.trimEnd()}
|
|
9
|
-
|
|
10
|
-
${u}
|
|
11
|
-
`,"utf8"),e.logger.success(`scaffolded migration "${t}" in ${n}`),{code:0,file:n}},he=(e,r)=>{const t=new w({skipAddingFilesFromTsConfig:!0});return k(t,l(e,"lunora")).find(a=>a.id===r)?.table},pe=(e,r)=>{const t=Y(r.id);if(t!==void 0)return t;if(r.id.startsWith(h)){r.logger.error(`"${r.id}" names no table — use ${h}<table>`);return}let o;try{o=he(e,r.id)}catch(a){r.logger.error(a instanceof Error?a.message:String(a));return}if(o===void 0){r.logger.error(`migration "${r.id}" not found under lunora/ — declare it with defineMigration({ id: "${r.id}", ... })`);return}if(o===""){r.logger.error(`migration "${r.id}" must declare \`table\` as a static string literal`);return}return o},be=e=>{const r=e.cwd??process.cwd();if(e.prod&&e.url===void 0)return e.logger.error("--prod requires an explicit --url (refusing to migrate the implicit localhost worker)"),{refused:c.USAGE};const t=pe(r,e);if(t===void 0)return{refused:c.USAGE};const o=q(e.url,e.logger,e.cwd);if(o===void 0)return{refused:c.USAGE};const{token:a}=z({cwd:r,token:e.token,url:o});if(!a)return e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)"),{refused:c.AUTH};if((e.subcommand==="up"||e.subcommand==="down")&&L({prod:e.prod,url:o})&&!e.yes)return e.logger.error(`migrate ${e.subcommand} runs the migration against ${o}, which is not local. Re-run with --yes to confirm.`),{refused:c.USAGE};const s=e.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return{fetchImpl:s,requestUrl:`${o}${de}`,table:t,token:a}},ve=e=>{if(e===null||typeof e!="object")return;const r=e,t=typeof r.failed=="number"&&r.failed>0?r.failed:0;if(t>0)return`${String(t)} shard(s) could not be reached — their rows were NOT migrated (see the per-shard errors above)`;if(r.status==="failed")return"the migration reported `failed` on at least one shard — see the per-shard results above"},we=e=>{const r={id:e.id};return e.subcommand==="status"||(r.direction=e.subcommand,e.dryRun&&(r.dryRun=!0),e.batchSize!==void 0&&(r.batchSize=e.batchSize),e.maxBatches!==void 0&&(r.maxBatches=e.maxBatches)),r},Pe=async e=>{const r=be(e);if(B(r))return{body:void 0,code:r.refused,requestUrl:""};const{fetchImpl:t,requestUrl:o,table:a,token:s}=r,n=e.subcommand==="status"?ce:se,i=we(e);e.logger.info(`POST ${o} -> ${e.subcommand} ${e.id} (table "${a}")`);const d=await t(o,{body:JSON.stringify({args:i,functionPath:n,table:a}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST"}),u=await Q(d,e.logger),g=ve(u);g!==void 0&&e.logger.error(`migrate ${e.subcommand} "${e.id}": ${g}`);const f=g===void 0?0:1;return{body:u,code:d.ok?f:W(d.status),requestUrl:o}},E=e=>e===void 0?void 0:H(e),Ge=async e=>{const{logger:r}=e,t=E(e.fromUrl??e.toUrl),o=E(e.toUrl??e.fromUrl);if(t===o){const n="source and target are the same deployment — pass distinct --from-url and --to-url so the D1 export and Hyperdrive import don't run against one database";return r.error(n),{bytes:0,code:c.USAGE,error:n,exported:0,imported:0}}const a=e.out===void 0?x(l(O(),"lunora-d1ps-")):void 0,s=e.out??l(a,"dump.ndjson");try{r.info(`Exporting .global() data from the D1 source (${t??"http://localhost:8787"}) …`);const n=await Z({fetchImpl:e.fetchImpl,logger:r,out:s,prod:e.prod,tables:e.tables,token:e.fromToken,url:t});if(n.code!==0)return{bytes:n.bytes,code:n.code,exported:n.rows,imported:0,...n.error===void 0?{}:{error:n.error}};r.info(`Exported ${String(n.rows)} row(s) (${String(n.bytes)} bytes).`),r.info(`Importing into the Hyperdrive target (${o??"http://localhost:8787"}) …`);const i=await K({batchSize:e.batchSize,fetchImpl:e.fetchImpl,file:s,logger:r,prod:e.prod,token:e.toToken,url:o,yes:e.yes});return i.code!==0?{bytes:n.bytes,code:i.code,exported:n.rows,imported:i.inserted,...i.error===void 0?{}:{error:i.error}}:(i.inserted===n.rows?r.info(`✓ Migrated ${String(n.rows)} row(s) — counts match. Verify your app reads from Hyperdrive, then decommission the D1 binding.`):r.warn(`Imported ${String(i.inserted)} of ${String(n.rows)} exported row(s) — the remainder likely already existed in the target (see conflicts above). Re-run after resolving, or inspect the dump with --out.`),{bytes:n.bytes,code:0,exported:n.rows,imported:i.inserted})}finally{a!==void 0&&F(a,{force:!0,recursive:!0})}};export{De as runMigrateCreateCommand,Pe as runMigrateDataCommand,ke as runMigrateGenerateCommand,Ge as runMigrateToHyperdriveCommand};
|