@lunora/cli 1.0.0-alpha.225 → 1.0.0-alpha.226
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 +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/handler.mjs +1 -1
- package/dist/packem_chunks/handler10.mjs +3 -4
- 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/handler19.mjs +1 -1
- package/dist/packem_chunks/handler20.mjs +1 -1
- package/dist/packem_chunks/handler22.mjs +3 -3
- package/dist/packem_chunks/handler26.mjs +1 -1
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +1 -1
- package/dist/packem_chunks/planDevCommand.mjs +5 -5
- package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
- package/dist/packem_chunks/runDeployCommand.mjs +2 -2
- package/dist/packem_chunks/runInitCommand.mjs +47 -45
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +7 -7
- package/dist/packem_chunks/runResetCommand.mjs +1 -1
- package/dist/packem_shared/{COMMANDS-BbQ3-hLn.mjs → COMMANDS-rRB9TbDL.mjs} +1 -1
- package/dist/packem_shared/{DEFAULT_IMPORT_BATCH_SIZE-BPQYMEmV.mjs → DEFAULT_IMPORT_BATCH_SIZE-BMH-ZXl5.mjs} +1 -1
- package/dist/packem_shared/cli-DIb5Ay4K.mjs +3 -0
- package/dist/packem_shared/{commands-BadIgWaM.mjs → commands-I18aR_DJ.mjs} +1 -1
- package/dist/packem_shared/{import-DuHtoh4_.mjs → import-Dqd1MOOv.mjs} +10 -10
- package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
- package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
- package/dist/packem_shared/{runAddCommand-DE1b920I.mjs → runAddCommand-BXea8slz.mjs} +1 -1
- package/dist/packem_shared/{storage-B08EcdWm.mjs → storage-B0ixDDxG.mjs} +1 -1
- package/package.json +11 -11
- package/dist/packem_shared/advisory-gate-Cl8IEFIj.mjs +0 -1
- package/dist/packem_shared/cli-DOBnG22n.mjs +0 -3
- package/dist/packem_shared/insertSchemaExtension-DY4pA8wE.mjs +0 -8
- package/dist/packem_shared/platform-diagnostics-D0YzAdXm.mjs +0 -4
package/dist/bin.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{r as e}from"./packem_shared/cli-
|
|
2
|
+
import{r as e}from"./packem_shared/cli-DIb5Ay4K.mjs";try{const r=await e();process.exit(r)}catch(r){process.stderr.write(`${r instanceof Error?r.message:String(r)}
|
|
3
3
|
`),process.exit(1)}
|
package/dist/index.d.mts
CHANGED
|
@@ -270,10 +270,16 @@ interface ImportSummary {
|
|
|
270
270
|
inserted: Record<string, number>;
|
|
271
271
|
received: number;
|
|
272
272
|
storage?: {
|
|
273
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `ambiguousTotal`. */
|
|
273
274
|
ambiguous: StorageRemapReport["ambiguous"];
|
|
275
|
+
/** How many DISTINCT `(table, column, storageId)` references were ambiguous. */
|
|
276
|
+
ambiguousTotal: number;
|
|
274
277
|
blobs: number;
|
|
275
278
|
rewritten: number;
|
|
279
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `unmigratedTotal`. */
|
|
276
280
|
unmigrated: StorageRemapReport["unmigrated"];
|
|
281
|
+
/** How many DISTINCT `(table, column, storageId)` references resolved to no migrated blob. */
|
|
282
|
+
unmigratedTotal: number;
|
|
277
283
|
};
|
|
278
284
|
warnings?: string[];
|
|
279
285
|
}
|
|
@@ -722,6 +728,14 @@ type ReadinessProbe = (origin: string, signal?: AbortSignal) => Promise<boolean>
|
|
|
722
728
|
*/
|
|
723
729
|
declare const startStudioServer: (options: StudioServerOptions) => Promise<StudioServerHandle>;
|
|
724
730
|
interface StudioServerOptions {
|
|
731
|
+
/**
|
|
732
|
+
* API-spec mode the host runs codegen with, forwarded to the local endpoints
|
|
733
|
+
* so a studio edit regenerates the SAME spec files the host's own codegen run
|
|
734
|
+
* writes. Codegen writes the spec its mode names and deletes the other, so
|
|
735
|
+
* omitting it made every studio edit delete an `apiSpec: "openrpc"` project's
|
|
736
|
+
* `openrpc.json`.
|
|
737
|
+
*/
|
|
738
|
+
apiSpec?: CodegenOptions["apiSpec"];
|
|
725
739
|
/** Project root — `.dev.vars` is read from here for the admin token. */
|
|
726
740
|
cwd: string;
|
|
727
741
|
/** Loopback host to bind. Defaults to `127.0.0.1` (admin tooling stays local). */
|
|
@@ -1086,8 +1100,13 @@ interface OfferDeps {
|
|
|
1086
1100
|
* Resolve which per-framework auth-UI item (`auth-ui-react|vue|…`) fits the
|
|
1087
1101
|
* scaffolded project. Injected by the CLI (detected from the template's deps);
|
|
1088
1102
|
* defaults to `auth-ui-react` when absent so this module stays pure/testable.
|
|
1103
|
+
*
|
|
1104
|
+
* `undefined` is a REFUSAL, not "unknown": no auth-UI item fits this project
|
|
1105
|
+
* (React Native). `lunora add auth-ui` already refuses there, and this offer
|
|
1106
|
+
* used to `?? "auth-ui-react"` its way past that — copying ~85 DOM files into
|
|
1107
|
+
* an Expo app and exiting 0.
|
|
1089
1108
|
*/
|
|
1090
|
-
resolveAuthUiItem?: () => string;
|
|
1109
|
+
resolveAuthUiItem?: () => string | undefined;
|
|
1091
1110
|
/** Single-select among the auth providers (TTY-backed in production). */
|
|
1092
1111
|
select: (message: string, options: ReadonlyArray<{
|
|
1093
1112
|
description?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -270,10 +270,16 @@ interface ImportSummary {
|
|
|
270
270
|
inserted: Record<string, number>;
|
|
271
271
|
received: number;
|
|
272
272
|
storage?: {
|
|
273
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `ambiguousTotal`. */
|
|
273
274
|
ambiguous: StorageRemapReport["ambiguous"];
|
|
275
|
+
/** How many DISTINCT `(table, column, storageId)` references were ambiguous. */
|
|
276
|
+
ambiguousTotal: number;
|
|
274
277
|
blobs: number;
|
|
275
278
|
rewritten: number;
|
|
279
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `unmigratedTotal`. */
|
|
276
280
|
unmigrated: StorageRemapReport["unmigrated"];
|
|
281
|
+
/** How many DISTINCT `(table, column, storageId)` references resolved to no migrated blob. */
|
|
282
|
+
unmigratedTotal: number;
|
|
277
283
|
};
|
|
278
284
|
warnings?: string[];
|
|
279
285
|
}
|
|
@@ -722,6 +728,14 @@ type ReadinessProbe = (origin: string, signal?: AbortSignal) => Promise<boolean>
|
|
|
722
728
|
*/
|
|
723
729
|
declare const startStudioServer: (options: StudioServerOptions) => Promise<StudioServerHandle>;
|
|
724
730
|
interface StudioServerOptions {
|
|
731
|
+
/**
|
|
732
|
+
* API-spec mode the host runs codegen with, forwarded to the local endpoints
|
|
733
|
+
* so a studio edit regenerates the SAME spec files the host's own codegen run
|
|
734
|
+
* writes. Codegen writes the spec its mode names and deletes the other, so
|
|
735
|
+
* omitting it made every studio edit delete an `apiSpec: "openrpc"` project's
|
|
736
|
+
* `openrpc.json`.
|
|
737
|
+
*/
|
|
738
|
+
apiSpec?: CodegenOptions["apiSpec"];
|
|
725
739
|
/** Project root — `.dev.vars` is read from here for the admin token. */
|
|
726
740
|
cwd: string;
|
|
727
741
|
/** Loopback host to bind. Defaults to `127.0.0.1` (admin tooling stays local). */
|
|
@@ -1086,8 +1100,13 @@ interface OfferDeps {
|
|
|
1086
1100
|
* Resolve which per-framework auth-UI item (`auth-ui-react|vue|…`) fits the
|
|
1087
1101
|
* scaffolded project. Injected by the CLI (detected from the template's deps);
|
|
1088
1102
|
* defaults to `auth-ui-react` when absent so this module stays pure/testable.
|
|
1103
|
+
*
|
|
1104
|
+
* `undefined` is a REFUSAL, not "unknown": no auth-UI item fits this project
|
|
1105
|
+
* (React Native). `lunora add auth-ui` already refuses there, and this offer
|
|
1106
|
+
* used to `?? "auth-ui-react"` its way past that — copying ~85 DOM files into
|
|
1107
|
+
* an Expo app and exiting 0.
|
|
1089
1108
|
*/
|
|
1090
|
-
resolveAuthUiItem?: () => string;
|
|
1109
|
+
resolveAuthUiItem?: () => string | undefined;
|
|
1091
1110
|
/** Single-select among the auth providers (TTY-backed in production). */
|
|
1092
1111
|
select: (message: string, options: ReadonlyArray<{
|
|
1093
1112
|
description?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as o,V as a,r as n}from"./packem_shared/cli-
|
|
1
|
+
import{C as o,V as a,r as n}from"./packem_shared/cli-DIb5Ay4K.mjs";import{runCodegenCommand as t}from"./packem_chunks/runCodegenCommand.mjs";import{runDeployCommand as p}from"./packem_chunks/runDeployCommand.mjs";import{planDevCommand as x,runDevCommand as i}from"./packem_chunks/planDevCommand.mjs";import{runInitCommand as C}from"./packem_chunks/runInitCommand.mjs";import{runMigrateGenerateCommand as u}from"./packem_chunks/runMigrateGenerateCommand.mjs";import{runResetCommand as g}from"./packem_chunks/runResetCommand.mjs";import{runRpcCommand as R}from"./packem_chunks/runRpcCommand.mjs";import{insertSchemaExtension as E}from"./packem_shared/insertSchemaExtension-DuiV6cba.mjs";import{createLogger as A,pail as c}from"./packem_shared/createLogger-hGafwf-3.mjs";import{diffSnapshots as v,renderAddColumn as _,renderCreateIndex as b,renderCreateTable as h,renderDropIndex as y,renderDropTable as L,renderMigrationFile as O,validatorKindToSqlType as w}from"./packem_shared/diffSnapshots-DtC5Cs4Z.mjs";import{default as F}from"./packem_shared/schemaIrToSnapshot-VpPguG3W.mjs";import{createRecordingSpawner as U,defaultSpawner as V}from"./packem_shared/createRecordingSpawner-DJlNacZ6.mjs";import{default as G}from"./packem_shared/parseManifest-CwPTKdtS.mjs";import{D as Q,r as j}from"./packem_shared/import-Dqd1MOOv.mjs";import{REQUIRED_COMPATIBILITY_DATE as H,REQUIRED_FLAG as K,validateWranglerProject as Y,validateWranglerConfig as Z}from"@lunora/config/cloudflare";import{b as z}from"./packem_shared/catalog-Cbzph90w.mjs";import{r as X,a as $,b as rr}from"./packem_shared/commands-I18aR_DJ.mjs";import{runExportCommand as or}from"./packem_shared/runExportCommand-Dq-SpjAe.mjs";export{o as COMMANDS,Q as DEFAULT_IMPORT_BATCH_SIZE,H as REQUIRED_COMPATIBILITY_DATE,K as REQUIRED_FLAG,a as VERSION,z as buildRegistryIndex,A as createLogger,U as createRecordingSpawner,V as defaultSpawner,v as diffSnapshots,E as insertSchemaExtension,c as pail,G as parseManifest,x as planDevCommand,_ as renderAddColumn,b as renderCreateIndex,h as renderCreateTable,y as renderDropIndex,L as renderDropTable,O as renderMigrationFile,X as runAddCommand,$ as runBuildIndexCommand,n as runCli,t as runCodegenCommand,p as runDeployCommand,i as runDevCommand,or as runExportCommand,j as runImportCommand,C as runInitCommand,u as runMigrateGenerateCommand,rr as runRegistryViewCommand,g as runResetCommand,R as runRpcCommand,F as schemaIrToSnapshot,Y as validateWrangler,Z as validateWranglerConfig,w as validatorKindToSqlType};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as k,readFileSync as T}from"node:fs";import{applyLintIgnores as
|
|
1
|
+
import{existsSync as k,readFileSync as T}from"node:fs";import{applyLintIgnores as A,detectLintTools as I}from"@lunora/config";import{findWranglerFile as N}from"@lunora/config/cloudflare";import{join as v,basename as w}from"@visulima/path";import{d as U}from"../packem_shared/command-DwC11Cwe.mjs";import{r as S}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import{v as D,l as _,i as E,p as L}from"../packem_shared/output-format-DfogXx0p.mjs";import{t as h,a as F}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";import{i as M}from"../packem_shared/resolve-B9ReA3FV.mjs";import{n as O,i as P,A as R,E as j,s as $,d as l,p,r as f,M as x,a as C,b as g,c as H,D as o,e as z,f as B,g as n,h as J,j as W,w as V,k as q,l as G}from"../packem_shared/storage-B0ixDDxG.mjs";import{r as K}from"../packem_shared/commands-I18aR_DJ.mjs";const Q=e=>{const r=e.trim().toLowerCase();return W.find(a=>a.value===r||a.label.toLowerCase()===r||r==="auth0"&&a.value==="auth-auth0"||r==="clerk"&&a.value==="auth-clerk")?.value},y=e=>{try{const r=JSON.parse(T(v(e,"package.json"),"utf8"));return{...r.dependencies,...r.devDependencies}}catch{return{}}},X=async e=>{const r=e.cwd??process.cwd(),t=B(y(r));return t!==void 0?t:e.yes===!0?(e.logger.warn(`add: couldn't detect your framework — using "${n}". Pass a specific item (e.g. \`lunora add auth-ui-vue\`) to override.`),n):await(e.promptSelect??((c,i,d)=>h(c,i,d)))("Which framework is your app?",J,{default:n})??n},Y=async e=>{if(e.provider!==void 0&&e.provider!==""){const t=Q(e.provider);return t===void 0?(e.logger.warn(`add: unknown --provider "${e.provider}" — using "${o}" (email & password).`),o):t}if(e.yes===!0)return o;const r=e.promptSelect??((t,a,c)=>h(t,a,c));return z(r)},m=e=>e.promptText??((r,t)=>F(r,t)),Z=async e=>{const r=w(e.cwd??process.cwd());if(e.bucket!==void 0&&e.bucket!==""){const t=$(e.bucket);if(t!==void 0)return t;const a=l(r);return e.logger.warn(`add: "${e.bucket}" isn't a valid R2 bucket name (lowercase alphanumeric + hyphens, 3–63 chars) — using "${a}".`),a}return e.yes===!0?l(r):p(m(e),r)},ee=async e=>{const r=t=>{e.logger.warn(`add: ${t}`)};if(e.mailTo!==void 0&&e.mailTo!=="")return f(e.mailTo,r);if(e.yes!==!0)return f(await m(e)(x,{placeholder:"you@yourdomain.com"}),r)},re=async e=>{const r=w(e.cwd??process.cwd());if(e.db!==void 0&&e.db!==""){const t=C(e.db);if(t!==void 0)return t;const a=g(r);return e.logger.warn(`add: "${e.db}" isn't a usable D1 database name — using "${a}".`),a}return e.yes===!0?g(r):H(m(e),r)},ae=async(e,r)=>e.kind==="auth"?[await Y(r)]:e.kind==="auth-ui"?[await X(r)]:e.kind==="email"?[j]:[e.item],te=(e,r)=>{S(A(e,I(e)),r)},ce=e=>!M(e)||e.yes===!0,se=async e=>{const r=e.cwd??process.cwd(),t=e.feature===void 0?void 0:O(e.feature);if(t===void 0)return e.logger.error("add requires a feature or registry item. Usage: lunora add <auth|email|storage|crons|presence|…>"),{code:1,items:[]};if(!k(v(r,"lunora"))||N(r)===void 0)return e.logger.error("add: not a Lunora project here (need a lunora/ directory and a wrangler.jsonc). Run `lunora init` first."),{code:1,items:[]};if(t.kind==="auth-ui"&&P(y(r)))return e.logger.error(`add: ${R}`),{code:1,items:[]};const a=await ae(t,e),c=[];if(a.includes("storage")){const s=await Z(e);c.push(u=>V(u,s))}if(a.includes("mail")){const s=await ee(e);s!==void 0&&c.push(u=>q(u,s))}if(a.some(s=>s==="auth"||s.startsWith("auth-"))){const s=await re(e);c.push(u=>G(u,s))}const i=c.length>0?s=>{let u=s;for(const b of c)u=b(u);return u}:void 0,d=await K({allowUnsafeSource:e.allowUnsafeSource,confirm:e.confirm,cwd:r,from:e.from,logger:e.logger,names:[...a],ref:e.ref,source:e.source,transformManifest:i,yes:ce(e)});return d.code===0&&te(r,e.logger),{code:d.code,items:a}},he=U(async({argument:e,cwd:r,logger:t,options:a})=>{const c=D("add",a.format);if(c!==void 0)return t.error(c),{code:1};const i=_(a.format,t),d=await se({allowUnsafeSource:a.allowUnsafeSource===!0,bucket:a.bucket,cwd:r,db:a.db,feature:e[0],from:a.from,logger:i,mailTo:a.mailTo,provider:a.provider,ref:a.ref,source:a.source,yes:a.yes===!0});return E(a.format)&&L({code:d.code,items:d.items}),{code:d.code}});export{he as execute,se as runAddFeature};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
`),{code:0}
|
|
4
|
-
`):E(i,n.logger),{code:0,snapshot:i}},q=F(({cwd:n,logger:e,options:i})=>A({bindings:i.bindings===!0,cwd:n,json:i.json===!0,logger:e,out:i.out}));export{D as collectInfo,q as execute,A as runInfoCommand};
|
|
1
|
+
import{readFileSync as l,existsSync as m}from"node:fs";import{join as u}from"node:path";import{discoverSchema as y}from"@lunora/codegen";import{readLinkedProject as h}from"@lunora/config";import{findWranglerFile as v}from"@lunora/config/cloudflare";import{parse as p}from"jsonc-parser";import{Project as $}from"ts-morph";import{w as k,d as g}from"../packem_shared/binding-manifest-file-CQ1eQYy1.mjs";import{d as w}from"../packem_shared/command-DwC11Cwe.mjs";const d=(n,e)=>{if(n===null||typeof n!="object")return;const i=n[e];return typeof i=="string"&&i.length>0?i:void 0},j=(n,e)=>{if(n===null||typeof n!="object")return[];const i=n[e];return Array.isArray(i)?i:[]},S=(n,e)=>{const{manifest:i}=g(e);return{bindings:(i?.bindings??[]).map(t=>`${t.type}:${t.binding}`),compatibilityDate:d(n,"compatibility_date"),compatibilityFlags:j(n,"compatibility_flags").filter(t=>typeof t=="string"),main:d(n,"main"),name:d(n,"name")}},x=n=>({tables:n.tables.map(e=>{let i="root";return e.shardMode==="global"?i="global":typeof e.shardMode=="object"&&(i=`shardBy(${e.shardMode.field})`),{indexes:e.indexes.length,name:e.name,shard:i}}),vectorIndexes:n.vectorIndexes.length}),F=n=>{const e=u(n,"package.json");if(!m(e))return[];let i;try{i=JSON.parse(l(e,"utf8"))}catch{return[]}if(i===null||typeof i!="object")return[];const t=["dependencies","devDependencies","peerDependencies","optionalDependencies"],c=new Map;for(const s of t){const r=i[s];if(!(r===null||typeof r!="object"))for(const[o,a]of Object.entries(r))o.startsWith("@lunora/")&&typeof a=="string"&&!c.has(o)&&c.set(o,a)}return[...c.entries()].toSorted(([s],[r])=>s.localeCompare(r)).map(([s,r])=>({name:s,version:r}))},P=n=>{const e=F(n),i=v(n);let t;if(i)try{t=S(p(l(i,"utf8")),n)}catch{t=void 0}const c=u(n,"lunora","schema.ts");let s,r;if(m(c))try{const o=new $({skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!1});s=x(y(o,c))}catch(o){r=o instanceof Error?o.message:String(o)}return{link:h(n),lunoraPackages:e,projectRoot:n,schema:s,schemaError:r,wrangler:t,wranglerPath:i}},M=(n,e)=>{if(e.info(`project: ${n.projectRoot}`),e.info(""),e.info("@lunora/* packages:"),n.lunoraPackages.length===0)e.info(" (none found in package.json)");else for(const i of n.lunoraPackages)e.info(` ${i.name}@${i.version}`);if(e.info(""),n.wrangler?(e.info(`wrangler: ${n.wranglerPath??""}`),e.info(` name: ${n.wrangler.name??"<unset>"}`),e.info(` main: ${n.wrangler.main??"<unset>"}`),e.info(` compatibility_date: ${n.wrangler.compatibilityDate??"<unset>"}`),e.info(` compatibility_flags: ${n.wrangler.compatibilityFlags.join(", ")||"<none>"}`),e.info(` bindings: ${n.wrangler.bindings.join(", ")||"<none>"}`)):e.info("wrangler: (not found)"),e.info(""),n.link?(e.info(`link: ${n.link.workerName??"(unnamed)"} -> ${n.link.workerUrl??"<no url>"}`),n.link.env!==void 0&&e.info(` env: ${n.link.env}`)):e.info("link: (not linked — run `lunora link --url <https://your-worker>`)"),e.info(""),n.schemaError!==void 0)e.warn(`schema: parse error — ${n.schemaError}`);else if(n.schema){e.info(`schema: ${String(n.schema.tables.length)} table(s), ${String(n.schema.vectorIndexes)} vector index(es)`);for(const i of n.schema.tables)e.info(` ${i.name} [${i.shard}, ${String(i.indexes)} index(es)]`)}else e.info("schema: (no lunora/schema.ts)")},I=n=>{const{cwd:e,json:i,logger:t,out:c}=n;if(c!==void 0){const{error:o}=k({destination:c,logger:t,projectRoot:e});return o!==void 0?(t.error(o),{code:1}):{code:0}}const{error:s,manifest:r}=g(e);if(r===void 0)return t.error(s??"could not derive the binding manifest"),{code:1};if(i)return process.stdout.write(`${JSON.stringify(r,void 0,2)}
|
|
2
|
+
`),{code:0};if(r.bindings.length===0)t.info("No bindings declared.");else{const o=Math.max(...r.bindings.map(a=>a.type.length));t.info(`${String(r.bindings.length)} binding(s):`);for(const a of r.bindings){const f=[a.resource,a.className,a.resourceId].filter(b=>b!==void 0).join(" ");t.info(` ${a.type.padEnd(o)} ${a.binding}${f===""?"":` ${f}`}`)}}return r.crons.length>0&&t.info(`${String(r.crons.length)} cron trigger(s): ${r.crons.join(", ")}`),r.vars.length>0&&t.info(`${String(r.vars.length)} var(s): ${r.vars.join(", ")}`),r.unknown.length>0&&t.warn(`not modelled by the manifest: ${r.unknown.join(", ")} — anything they bind must be provisioned by hand.`),{code:0}},N=n=>{const e=n.cwd??process.cwd();if(n.bindings===!0)return{...I({cwd:e,json:n.json===!0,logger:n.logger,out:n.out}),snapshot:void 0};if(n.out!==void 0)return n.logger.error("--out only applies with --bindings; the full info snapshot prints to stdout under --json."),{code:1,snapshot:void 0};const i=P(e);return n.json?process.stdout.write(`${JSON.stringify(i,void 0,2)}
|
|
3
|
+
`):M(i,n.logger),{code:0,snapshot:i}},L=w(({cwd:n,logger:e,options:i})=>N({bindings:i.bindings===!0,cwd:n,json:i.json===!0,logger:e,out:i.out}));export{P as collectInfo,L as execute,N as runInfoCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d
|
|
1
|
+
import{d}from"../packem_shared/command-DwC11Cwe.mjs";import{r as c,b as s,a as n}from"../packem_shared/commands-I18aR_DJ.mjs";const w=d(({argument:a,cwd:u,logger:e,options:r})=>{const f=a[0],m=a.slice(1);return f==="add"?c({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,diff:r.diff===!0,dryRun:r.dryRun===!0,from:r.from,json:r.json===!0,logger:e,names:m,overwrite:r.overwrite===!0,ref:r.ref,source:r.source,yes:r.yes===!0}):f==="list"?c({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,from:r.from,json:r.json===!0,list:!0,logger:e,names:[],ref:r.ref,source:r.source}):f==="view"?s({allowUnsafeSource:r.allowUnsafeSource===!0,cwd:u,from:r.from,logger:e,names:m,ref:r.ref,source:r.source}):f==="build"?n({check:r.check===!0,cwd:u,from:r.from,logger:e,names:[],out:r.out}):(e.error("registry: unknown subcommand. Usage: lunora registry <add|list|view|build> [names…]"),{code:1})});export{w as execute};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as c,readFileSync as g,readdirSync as f,statSync as k,mkdirSync as w,writeFileSync as y}from"node:fs";import{fileURLToPath as R}from"node:url";import{AGENT_RULES_DIR as u,detectAgentRules as v,LUNORA_SKILL_NAMES as L}from"@lunora/config";import{join as i,relative as A,resolve as $,dirname as d}from"@visulima/path";import{d as b}from"../packem_shared/command-DwC11Cwe.mjs";const I=(e=d(R(import.meta.url)))=>{let r=e;for(let n=0;n<6;n+=1){const t=i(r,"package.json");if(c(t))try{if(JSON.parse(g(t,"utf8")).name==="@lunora/cli"){const l=i(r,"skills");return c(l)?l:void 0}}catch{}const s=d(r);if(s===r)break;r=s}},j=e=>f(e).filter(r=>{const n=i(e,r);return k(n).isDirectory()&&c(i(n,"SKILL.md"))}),m=(e,r,n)=>{w(r,{recursive:!0});let t=!1;for(const s of f(e)){const o=i(e,s),l=i(r,s);if(k(o).isDirectory()){t=m(o,l,n)||t;continue}c(l)&&!n||(y(l,g(o)),t=!0)}return t},_=["pnpm-workspace.yaml","pnpm-lock.yaml","yarn.lock","package-lock.json","bun.lock","bun.lockb",".git"],x=e=>{let r=e;for(;;){if(_.some(t=>c(i(r,t))))return r;const n=d(r);if(n===r)return e;r=n}},p=(e,r)=>r===void 0?x(e):$(e,r),E=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=e.overwrite===!0,s=I();if(s===void 0)return e.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?)."),{code:1,installed:[],skipped:[]};const o=[],l=[];for(const a of j(s)){const S=i(n,u,a);m(i(s,a),S,t)?o.push(a):l.push(a)}const h=A(r,i(n,u))||u;return o.length>0&&e.logger.success(`Installed ${String(o.length)} Lunora skill(s) into ${h}/: ${o.join(", ")}.`),l.length>0&&e.logger.info(`Skipped ${String(l.length)} existing skill(s) (re-run with --overwrite to replace): ${l.join(", ")}.`),e.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill."),{code:0,installed:o,skipped:l}},O=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=v(n);return t.installed?(e.logger.success(`Lunora agent rules are installed (${String(t.present.length)}/${String(L.length)} skills).`),t.missing.length>0&&e.logger.info(`Missing: ${t.missing.join(", ")}. Run \`lunora rules install\` to add them.`),{code:0,installed:t.present,skipped:[]}):(e.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora."),{code:e.strict===!0?1:0,installed:t.present,skipped:[]})},T=b(({argument:e,cwd:r,logger:n,options:t})=>{const s=e[0]??"check";return s==="install"?E({cwd:r,dir:t.dir,logger:n,overwrite:t.overwrite===!0}):s==="check"?O({cwd:r,dir:t.dir,logger:n,strict:t.strict===!0}):(n.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:1})});export{T as execute,I as resolveBundledSkillsDirectory,O as runRulesCheck,E as runRulesInstall};
|
|
1
|
+
import{existsSync as c,readFileSync as g,readdirSync as f,statSync as k,mkdirSync as w,writeFileSync as y}from"node:fs";import{fileURLToPath as R}from"node:url";import{AGENT_RULES_DIR as u,detectAgentRules as v,LUNORA_SKILL_NAMES as L}from"@lunora/config";import{join as i,relative as A,resolve as $,dirname as d}from"@visulima/path";import{d as b}from"../packem_shared/command-DwC11Cwe.mjs";const I=(e=d(R(import.meta.url)))=>{let r=e;for(let n=0;n<6;n+=1){const t=i(r,"package.json");if(c(t))try{if(JSON.parse(g(t,"utf8")).name==="@lunora/cli"){const l=i(r,"skills");return c(l)?l:void 0}}catch{}const s=d(r);if(s===r)break;r=s}},j=e=>f(e).filter(r=>{const n=i(e,r);return k(n).isDirectory()&&c(i(n,"SKILL.md"))}),m=(e,r,n)=>{w(r,{recursive:!0});let t=!1;for(const s of f(e)){const o=i(e,s),l=i(r,s);if(k(o).isDirectory()){t=m(o,l,n)||t;continue}c(l)&&!n||(y(l,g(o)),t=!0)}return t},_=["pnpm-workspace.yaml","pnpm-lock.yaml","yarn.lock","package-lock.json","bun.lock","bun.lockb",".git"],x=e=>{let r=e;for(;;){if(_.some(t=>c(i(r,t))))return r;const n=d(r);if(n===r)return e;r=n}},p=(e,r)=>r===void 0?x(e):$(e,r),E=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=e.overwrite===!0,s=I();if(s===void 0)return e.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?)."),{code:1,installed:[],skipped:[]};const o=[],l=[];for(const a of j(s)){const S=i(n,u,a);m(i(s,a),S,t)?o.push(a):l.push(a)}const h=A(r,i(n,u))||u;return o.length>0&&e.logger.success(`Installed ${String(o.length)} Lunora skill(s) into ${h}/: ${o.join(", ")}.`),l.length>0&&e.logger.info(`Skipped ${String(l.length)} existing skill(s) (re-run with --overwrite to replace): ${l.join(", ")}.`),e.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill."),{code:0,installed:o,skipped:l}},O=e=>{const r=e.cwd??process.cwd(),n=p(r,e.dir),t=v(n);return t.installed?(e.logger.success(`Lunora agent rules are installed (${String(t.present.length)}/${String(L.length)} skills).`),t.missing.length>0&&e.logger.info(`Missing: ${t.missing.join(", ")}. Run \`lunora rules install\` to add them.`),{code:0,installed:t.present,skipped:[]}):(e.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora."),{code:e.strict===!0?1:0,installed:t.present,skipped:[]})},T=b(({argument:e,cwd:r,logger:n,options:t})=>{const s=e[0]??"check";return s==="install"?E({cwd:r,dir:t.dir,logger:n,overwrite:t.overwrite===!0}):s==="check"?O({cwd:r,dir:t.dir,logger:n,strict:t.strict===!0}):(n.error("rules: unknown subcommand. Usage: lunora rules <install|check>"),{code:1})});export{T as execute,j as listBundledSkills,I as resolveBundledSkillsDirectory,O as runRulesCheck,E as runRulesInstall};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{existsSync as S}from"node:fs";import{mkdtemp as k,writeFile as v,rm as R}from"node:fs/promises";import{tmpdir as $}from"node:os";import{discoverSchema as j,schemaFromIr as T}from"@lunora/codegen";import{seedPlan as C}from"@lunora/seed";import{join as m}from"@visulima/path";import{Project as F}from"ts-morph";import{t as b}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{d as x}from"../packem_shared/command-DwC11Cwe.mjs";import{r as z}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{b as I}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";import{runResetCommand as A}from"./runResetCommand.mjs";import{r as P}from"../packem_shared/import-
|
|
1
|
+
import{existsSync as S}from"node:fs";import{mkdtemp as k,writeFile as v,rm as R}from"node:fs/promises";import{tmpdir as $}from"node:os";import{discoverSchema as j,schemaFromIr as T}from"@lunora/codegen";import{seedPlan as C}from"@lunora/seed";import{join as m}from"@visulima/path";import{Project as F}from"ts-morph";import{t as b}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{d as x}from"../packem_shared/command-DwC11Cwe.mjs";import{r as z}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{b as I}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";import{runResetCommand as A}from"./runResetCommand.mjs";import{r as P}from"../packem_shared/import-Dqd1MOOv.mjs";const N=(e,r)=>typeof r=="bigint"?Number(r):r instanceof ArrayBuffer?[...new Uint8Array(r)]:r,l=e=>({code:e,conflicts:0,generated:0,inserted:0,ndjson:""}),U=(e,r)=>{if(!S(r))return e.logger.error(`schema not found: ${r} — run \`vis generate lunora-table --name=<name>\` to create one`),l(1);if(e.reset===!0&&b({prod:e.prod,url:e.url}))return e.logger.error("--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url"),l(1)},W=async(e,r,t,n)=>{const d=await k(m($(),"lunora-seed-")),i=m(d,"rows.ndjson");await v(i,e,"utf8");try{const o=await P({batchSize:n.batchSize,cwd:t,fetchImpl:n.fetchImpl,file:i,logger:n.logger,prod:n.prod,token:n.token,url:n.url,yes:!0}),s=o.body?.conflicts??0;return s>0&&n.logger.warn(`${String(s)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`),{code:o.code,conflicts:s,generated:r,inserted:o.inserted,ndjson:e}}finally{await R(d,{force:!0,recursive:!0}).catch(()=>{})}},_=(e,r)=>{if(e.table===void 0||r.tables.some(n=>n.name===e.table))return;const t=r.tables.map(n=>n.name).join(", ");return e.logger.error(`unknown table "${e.table}" — schema defines: ${t||"(no tables)"}`),l(1)},B=async(e,r)=>{if(!b({prod:e.prod,url:e.url})||e.yes===!0)return;if(!process.stdin.isTTY&&e.confirm===void 0)return e.logger.error("seed: refusing to insert into a non-local target without confirmation — re-run with --yes"),l(1);if(!await(e.confirm??I)(`This will insert ${String(r)} generated row(s) into ${e.url??"the production worker"}. Continue?`))return e.logger.info("seed: aborted"),l(1)},D=async e=>{const r=e.cwd??process.cwd(),t=m(r,"lunora","schema.ts"),n=U(e,t);if(n!==void 0)return n;const d=new F({skipAddingFilesFromTsConfig:!0}),i=j(d,t),o=_(e,i);if(o!==void 0)return o;const s=T(i),g=C(s,{defaultCount:e.count??10,now:e.now,only:e.table===void 0?void 0:[e.table],seed:e.seed??0}),u=[];for(const{rows:f,table:h}of g)for(const y of f)u.push(JSON.stringify({doc:y,table:h},N));const c=u.length>0?`${u.join(`
|
|
2
2
|
`)}
|
|
3
3
|
`:"",a=u.length;if(e.dryRun===!0)return c.length>0&&process.stdout.write(c),e.logger.info(`generated ${String(a)} row(s) across ${String(g.length)} table(s) — dry run, nothing inserted`),{code:0,conflicts:0,generated:a,inserted:0,ndjson:c};if(a===0)return e.logger.warn("no rows generated — nothing to insert"),{code:0,conflicts:0,generated:0,inserted:0,ndjson:c};if(e.reset===!0){const f=await A({confirm:e.confirm,cwd:r,logger:e.logger,yes:e.yes});if(f.code!==0)return{code:f.code,conflicts:0,generated:a,inserted:0,ndjson:c}}const w=await B(e,a);return w!==void 0?w:W(c,a,r,e)},Z=x(async({cwd:e,logger:r,options:t})=>({code:(await D({batchSize:t.batchSize,count:t.count,cwd:e,dryRun:t.dryRun===!0,logger:r,prod:t.prod===!0,reset:t.reset===!0,now:t.now,seed:t.seed,table:t.table,token:t.token,url:z({cwd:e,prod:t.prod===!0,url:t.url}),yes:t.yes===!0})).code}));export{Z as execute,D as runSeedCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as p}from"node:fs";import{join as g}from"node:path";import{runCodegen as v}from"@lunora/codegen";import{a as y,e as w,r as S}from"../packem_shared/platform-diagnostics-Cn2g6Jh-.mjs";import{p as k,r as j}from"../packem_shared/deploy-target-B0Xcb2jV.mjs";import{r as E}from"../packem_shared/codegen-error-AmH54ofi.mjs";import{d as A}from"../packem_shared/command-DwC11Cwe.mjs";import{r as R,p as $}from"../packem_shared/schema-drift-gate-BDCkQ1S6.mjs";import{v as b,i as D,p as x,l as F}from"../packem_shared/output-format-DfogXx0p.mjs";import{defaultSpawner as U}from"../packem_shared/createRecordingSpawner-DJlNacZ6.mjs";import{validateWranglerProject as P}from"@lunora/config/cloudflare";import{execArgsFor as H,detectPackageManager as O}from"@lunora/config";const T=async(r,t)=>{if(!p(g(r,"tsconfig.json")))return{warning:"no tsconfig.json found — skipping TypeScript type-check"};const e=H(O(r),"tsc",["--noEmit","-p","tsconfig.json"]),o=await t({args:e.args,command:e.command,cwd:r});return o.code===0?{}:{error:`type errors: tsc --noEmit exited ${String(o.code)}`}},C=async(r,t)=>{if(r.healthUrl===void 0||r.healthUrl==="")return;const e=await $({baseUrl:r.healthUrl,fetchImpl:r.healthFetch});if(e.error===void 0){t.success(`verify: health probe ok (${e.url})`);return}return e.error},G=(r,t)=>{const{errorAdvisories:e,names:o,shouldBlock:s}=w(r,S(t));if(s)return`${e.length.toString()} ERROR-level ${e.length===1?"advisory":"advisories"} (${o.join(", ")}). Pass --no-strict-advisories to downgrade this to a warning and continue.`},I=(r,t,e,o)=>{if(t.length===0&&e.length===0)return r.success("verify: project is valid"),{code:0,errors:[],warnings:[],wranglerPath:o};if(e.length>0){r.warn("verify: warnings:");for(const s of e)r.warn(` - ${s}`)}if(t.length>0){r.error("verify: errors:");for(const s of t){r.error(` - ${s}`);const i=E(s);i!==void 0&&r.error(i)}return{code:1,errors:t,warnings:e,wranglerPath:o}}return r.success("verify: project is valid (with warnings)"),{code:0,errors:[],warnings:e,wranglerPath:o}},J=async r=>{const t=r.cwd??process.cwd(),e=F(r.format,r.logger),o=b("verify",r.format);if(o!==void 0)return r.logger.error(o),{code:1,error:o,errors:[],warnings:[],wranglerPath:void 0};const s=P({projectRoot:t}),i=[...s.report.errors],c=[...s.report.warnings];try{const a=j(t,r.target);if(a.target===void 0){const f=a.error??"unknown deploy target";return e.error(f),{code:1,error:f,errors:[f],warnings:[],wranglerPath:void 0}}const n=v({apiSpec:r.apiSpec,dryRun:!0,projectRoot:t,target:a.target}),m=y(n.platformDiagnostics,e);i.push(...m.errors),c.push(...m.warnings);const h=G(n.advisories,r);h!==void 0&&i.push(h);const u=R({allowDrift:r.allowSchemaDrift===!0,codegen:n,command:"verify",logger:e,readOnly:!0});u.blocked&&i.push(u.reason)}catch(a){const n=a instanceof Error?a.message:String(a);i.push(`codegen failed: ${n}`)}if(r.typecheck!==!1){const a=await T(t,r.spawner??U);a.error!==void 0&&i.push(a.error),a.warning!==void 0&&c.push(a.warning)}const d=await C(r,e);d!==void 0&&i.push(d);const l=I(e,i,c,s.wranglerPath);return D(r.format)&&x(l),l},Z=A(async({cwd:r,logger:t,options:e})=>({code:(await J({allowSchemaDrift:e.allowSchemaDrift===!0,apiSpec:k(e.apiSpec),cwd:r,format:e.format,healthUrl:e.healthUrl,logger:t,strictAdvisories:e.strictAdvisories,target:e.target,typecheck:e.typecheck===!1?!1:void 0})).code}));export{Z as execute,J as runVerifyCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{writeFileSync as v,existsSync as S,readFileSync as b}from"node:fs";import{isAbsolute as p,join as w}from"node:path";import{byCodepoint as y,scoreAdvisor as x,parseAdvisorMap as j,compareToBaseline as A}from"@lunora/advisor";import{runCodegen as F}from"@lunora/codegen";import{d as M}from"../packem_shared/command-DwC11Cwe.mjs";import{v as R,p as D,l as k,i as E}from"../packem_shared/output-format-DfogXx0p.mjs";import{D as u}from"../packem_shared/cli-
|
|
1
|
+
import{writeFileSync as v,existsSync as S,readFileSync as b}from"node:fs";import{isAbsolute as p,join as w}from"node:path";import{byCodepoint as y,scoreAdvisor as x,parseAdvisorMap as j,compareToBaseline as A}from"@lunora/advisor";import{runCodegen as F}from"@lunora/codegen";import{d as M}from"../packem_shared/command-DwC11Cwe.mjs";import{v as R,p as D,l as k,i as E}from"../packem_shared/output-format-DfogXx0p.mjs";import{D as u}from"../packem_shared/cli-DIb5Ay4K.mjs";const l={clean:"·",exempt:"–",failing:"✗",warned:"!"},d=(e,r)=>e.length>=r?e:e+" ".repeat(r-e.length),B=e=>`${e.id} (${e.visibility} ${e.kind})`,f=e=>{let r=0;for(const n of e)r=Math.max(r,n.id.length);return r},g=(e,r)=>` ${d(String(e.score),3)} ${l[e.coverage]} ${d(e.id,r)} ${e.visibility} ${e.kind}`,T=e=>{if(!e.comparable)return[` baseline not comparable (${e.reason}) — regenerate it; this run cannot verify anything`];if(!e.regressed)return[` no regression against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];const r=[` REGRESSED against baseline (score ${e.scoreDelta>=0?"+":""}${String(e.scoreDelta)})`];for(const n of e.dropped)r.push(` ${n.id}: ${String(n.before)} → ${String(n.after)}`);for(const n of e.newFailing)r.push(` ${n}: now failing`);for(const n of e.worsened)r.push(` ${n}: more findings than the baseline`);return e.projectRegressed&&r.push(" project: new schema/config rules fired"),r},C=(e,r)=>{const n=e.procedures.filter(i=>i.coverage!=="clean"&&i.coverage!=="exempt"),o=f(n),t=[`advisor health ${String(e.score)}/100 — ${e.grade}`,` ${String(e.summary.clean)} clean · ${String(e.summary.warned)} warned · ${String(e.summary.failing)} failing · ${String(e.summary.exempt)} exempt (${String(e.summary.procedures)} procedures, ${String(e.summary.rulesFired)} rules fired)`];return e.project.checks.length>0&&t.push("",` project ${String(e.project.score)}/100 — ${e.project.checks.map(i=>i.name).join(", ")}`),n.length>0&&t.push("",...n.map(i=>g(i,o)),""," run with --all for every procedure, or --entry <file#export> for one"),r!==void 0&&t.push("",...T(r)),t.join(`
|
|
2
2
|
`)},J=e=>e.coverage==="exempt"?[` exempt: ${e.exemptReason===void 0||e.exemptReason===""?"no reason given":e.exemptReason}`]:e.checks.map(r=>{const n=r.occurrences>1?`, ×${String(r.occurrences)}`:"";return` ${r.name} (−${String(r.weight)}${n})`}),L=e=>{const r=new Map;for(const n of e){const o=r.get(n.file);o===void 0?r.set(n.file,[n]):o.push(n)}return[...r].toSorted(([n],[o])=>y(n,o))},N=e=>{const r=f(e.procedures),n=[`advisor health ${String(e.score)}/100 — ${e.grade}`,"",` legend: ${l.clean} clean ${l.warned} warned ${l.failing} failing ${l.exempt} exempt`];for(const[o,t]of L(e.procedures)){n.push("",` ${o}`);for(const i of t)n.push(g(i,r),...J(i))}return n.join(`
|
|
3
3
|
`)},P=(e,r)=>{const n=e.procedures.find(t=>t.id===r);if(n===void 0){const t=e.procedures.slice(0,10).map(i=>` ${i.id}`);return[`no procedure ${r} in the map. Known ids:`,...t,e.procedures.length>10?" …":""].filter(Boolean).join(`
|
|
4
4
|
`)}const o=[`${B(n)} — ${String(n.score)}/100, ${n.coverage}`,` weight in the global mean: ${String(n.weight)}`];if(n.checks.length===0)return o.push(""," no rule fired"),o.join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as
|
|
1
|
+
import{join as l,resolve as m}from"node:path";import{p as u}from"../packem_shared/deploy-target-B0Xcb2jV.mjs";import{d as f}from"../packem_shared/command-DwC11Cwe.mjs";import{v as p,l as g,i as w,p as y}from"../packem_shared/output-format-DfogXx0p.mjs";import{defaultSpawner as v}from"../packem_shared/createRecordingSpawner-DJlNacZ6.mjs";import{runDeployCommand as b}from"./runDeployCommand.mjs";import{readdirSync as S,readFileSync as h}from"node:fs";import{gzipSync as B}from"node:zlib";const D=e=>!e.endsWith(".map")&&e!=="bundle-meta.json"&&e!=="README.md",F=e=>{let t;try{t=S(e,{recursive:!0,withFileTypes:!0})}catch{return}let r=0,i=0,d=0;for(const a of t){if(!a.isFile()||!D(a.name))continue;const o=h(l(a.parentPath,a.name));r+=1,d+=o.byteLength,i+=B(o).byteLength}return r===0?void 0:{files:r,gzipBytes:i,rawBytes:d}},A=".lunora/build",z=async e=>v({...e,stdoutToStderr:!0}),c=e=>`${(e/1024).toFixed(1)} KiB`,$=async e=>{const t=e.outDir??A,r=w(e.format),i=g(e.format,e.logger),d=s=>(r&&y(s),s),a=p("build",e.format);if(a!==void 0)return e.logger.error(a),{code:1,descriptor:void 0,error:a,validation:{problems:[],wranglerPath:void 0}};const o=await b({allowSchemaDrift:e.allowSchemaDrift,apiSpec:e.apiSpec,commandName:"build",cwd:e.cwd,dryRun:!0,emitBindings:e.emitBindings,format:void 0,interactive:r?!1:void 0,logger:i,outDir:t,spawner:e.spawner??(r?z:void 0),strictAdvisories:e.strictAdvisories,target:e.target});if(o.code!==0)return d(o);i.success(`build complete — bundle written to ${t}`);const n=F(m(e.cwd??process.cwd(),t));return n===void 0?i.warn(`could not weigh the bundle — nothing uploadable was found in ${t}`):i.info(`bundle: ${c(n.rawBytes)} raw, ${c(n.gzipBytes)} gzipped across ${String(n.files)} file(s) — Cloudflare's Worker size limit (3 MB Free, 10 MB Paid) applies to the gzipped number`),d({...o,bundle:n})},P=f(async({cwd:e,logger:t,options:r})=>({code:(await $({allowSchemaDrift:r.allowSchemaDrift===!0,apiSpec:u(r.apiSpec),cwd:e,emitBindings:r.emitBindings,format:r.format,logger:t,outDir:r.outDir,strictAdvisories:r.strictAdvisories,target:r.target})).code}));export{P as execute,$ as runBuildCommand};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import F,{join as l,resolve as N}from"node:path";import{isInteractive as K,promptYesNo as z}from"@lunora/config";import{backupObjectKey as p,isBackupManifestEntry as O,normalizeBackupPrefix as H,BACKUP_KEY_PREFIX as J,backupManifestKey as G,isBackupManifestKey as W,backupObjectKeyOfManifest as A}from"@lunora/runtime";import{r as v,t as Y}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{r as $}from"../packem_shared/admin-url-BhF5ufg1.mjs";import{d as X}from"../packem_shared/command-DwC11Cwe.mjs";import{r as Q}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{readAndLogBody as b}from"./runRpcCommand.mjs";import{randomUUID as B,createHash as V}from"node:crypto";import{existsSync as T,createReadStream as Z,createWriteStream as ee}from"node:fs";import{mkdir as re,rm as w,rename as U,readFile as D,writeFile as te,realpath as S,mkdtemp as E}from"node:fs/promises";import{LunoraError as h}from"@lunora/errors";import{i as I}from"../packem_shared/path-containment-CgxYZggb.mjs";import{tmpdir as _}from"node:os";import{Readable as ae}from"node:stream";import{pipeline as oe}from"node:stream/promises";import{b as ne,l as ie,M as
|
|
2
|
-
`,"utf8"),await U(a,l(e,y))}catch(t){throw await w(a,{force:!0}),t}},le=async(e,r)=>{const a=N(e),t=N(a,r.file),o=()=>{throw new h("INTERNAL",`backup: entry ${r.id} points outside ${a} (${r.file}) — refusing to read it`)};if(I(a,t)||o(),!!T(t))return I(await S(a),await S(t))||o(),t},fe=e=>{const r=a=>p("",a);return{commit:async(a,t)=>{await U(t,l(e,a))},label:e,list:async()=>R(e),locate:r,materialize:async(a,t)=>{const o=i=>i===void 0?void 0:{path:i,release:()=>Promise.resolve()};return o(a===void 0?T(t)?t:void 0:await le(e,a))},record:async a=>{const t=await R(e);t.push(a),await ue(e,t)},stage:async a=>{await re(e,{recursive:!0});const t=l(e,`${r(a)}.${B()}.partial`);return{path:t,release:()=>w(t,{force:!0})}}}},
|
|
3
|
-
`,headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"PUT"});if(!u.ok){const s=await u.text().catch(()=>"<no body>");throw new h("INTERNAL",`backup: snapshot ${c.file} was written but its manifest was not (HTTP ${String(u.status)}): ${s}`)}},stage:async c=>{const n=await E(l(_(),"lunora-backup-"));return{path:l(n,p("",c)),release:async()=>w(n,{force:!0,recursive:!0})}}}},be=".lunora-backups",q="/_lunora/admin/backup/retention",ke="/_lunora/admin/backup/prune",pe="/_lunora/admin/pitr",ye="__lunora_admin__:getPitrBookmark",ve="__lunora_admin__:pitrRestore",$e=async(e,r)=>{const a=(e.now??(()=>new Date))().toISOString(),t=await r.stage(a);try{const o=await de({cwd:e.cwd,fetchImpl:e.fetchImpl,logger:e.logger,out:t.path,prod:e.prod,tables:e.tables,token:e.token,url:e.url});if(o.code!==0)return{code:o.code};const i=r.locate(a),d=await j(t.path);await r.commit(i,t.path,d);const f={bytes:d.bytes,createdAt:a,file:i,id:a,rows:o.rows,sha256:d.sha256,tables:e.tables};return await r.record(f),e.logger.success(`backup created: ${i} (${o.rows.toString()} rows, ${d.bytes.toString()} bytes)`),{code:0,entry:f}}finally{await t.release().catch(o=>{e.logger.warn(`backup: could not clean up staging (${o instanceof Error?o.message:String(o)})`)})}},Te=async(e,r,a)=>{if(r?.sha256===void 0)return a.error(r===void 0?"--verify needs a recorded checksum, and a snapshot restored by path/key has no manifest entry — restore it by its backup id instead":`--verify: backup ${r.id} carries no recorded checksum — it was taken by a release before checksums existed`),{code:1};const t=await j(e);if(t.sha256!==r.sha256)return a.error(`--verify: ${r.file} does not match its recorded checksum (expected ${r.sha256}, got ${t.sha256}) — nothing was imported`),{code:1};a.success(`verified ${r.file} against its recorded sha256`)},Ne=async(e,r)=>{const a=await r.list();if(a.length===0)return e.logger.info(`no backups found in ${r.label}`),{code:0};for(const t of a)e.logger.info(`${t.id} ${t.rows.toString()} rows ${t.bytes.toString()} bytes ${t.file}`);return{code:0}},Se=async(e,r)=>{const{target:a}=e;if(a===void 0||a.length===0)return e.logger.error("restore requires a backup id or file path. Usage: lunora backup restore <id|file>"),{code:1};const o=(await r.list()).find(d=>d.id===a),i=await r.materialize(o,a);if(i===void 0)return e.logger.error(`backup not found: ${a}`),{code:1};try{if(e.verify===!0){const f=await Te(i.path,o,e.logger);if(f!==void 0)return f}return{code:(await se({cwd:e.cwd,fetchImpl:e.fetchImpl,file:i.path,logger:e.logger,prod:e.prod,token:e.token,url:e.url,yes:e.yes})).code}}finally{await i.release().catch(d=>{e.logger.warn(`backup: could not clean up the downloaded snapshot (${d instanceof Error?d.message:String(d)})`)})}},Ee=e=>{if(e.prod&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}if(e.restore===!0&&e.at===void 0&&e.bookmark===void 0){e.logger.error("pitr --restore requires --at <time> or --bookmark <bookmark>");return}const r=$(e.url,e.logger,e.cwd);if(r===void 0)return;if(e.restore===!0&&Y({prod:e.prod,url:r})&&e.yes!==!0){e.logger.error(`pitr --restore restores data in place at ${r}, which is not local. Re-run with --yes to confirm.`);return}const{token:a}=v({cwd:e.cwd??process.cwd(),token:e.token,url:r});if(!a){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const t=e.adminFetch??globalThis.fetch;if(typeof t!="function")throw new TypeError("no fetch implementation available — pass pitrFetch or run on Node >= 18");return{fetchImpl:t,requestUrl:`${r}${pe}`,token:a}},Ie=(e,r)=>{const a={};return e.at!==void 0&&(a.time=e.at),r&&e.bookmark!==void 0&&(a.bookmark=e.bookmark),r&&e.restart===!0&&(a.restart=!0),a},_e=async e=>{const r=Ee(e);if(r===void 0)return{code:1};const a=e.restore===!0,t=a?ve:ye,o=Ie(e,a),i=a?"restore":"bookmark";e.logger.info(`POST ${r.requestUrl} -> pitr ${i}${e.shard===void 0?"":` (shard "${e.shard}")`}`);const d=await r.fetchImpl(r.requestUrl,{body:JSON.stringify({args:o,functionPath:t,shardKey:e.shard}),headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"POST"});return await b(d,e.logger),{code:d.ok?0:1}},Pe=(e,r)=>{if(e.bucket===void 0)return fe(l(r,e.dir??be));if(e.prod===!0&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}const a=$(e.url,e.logger,e.cwd);if(a===void 0)return;const{token:t}=v({cwd:r,token:e.token,url:a});if(!t){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const o=e.fetchImpl??globalThis.fetch;if(typeof o!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return we({context:{baseUrl:a,bucket:e.bucket==="default"?void 0:e.bucket,fetchImpl:o,token:t},logger:e.logger,prefix:e.prefix})},L=e=>{const r=[e.bucket===void 0?void 0:"--bucket",e.prefix===void 0?void 0:"--prefix",e.dir===void 0?void 0:"--dir"].filter(i=>i!==void 0);if(r.length>0){e.logger.error(`${r.join(" / ")} ${r.length===1?"does":"do"} not apply here — retention and prune act on the store the worker itself is configured with (\`backupStore\`), not a destination you name.`);return}if(e.prod===!0&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}const a=$(e.url,e.logger,e.cwd);if(a===void 0)return;const{token:t}=v({cwd:e.cwd??process.cwd(),token:e.token,url:a});if(!t){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const o=e.adminFetch??globalThis.fetch;if(typeof o!="function")throw new TypeError("no fetch implementation available — pass pitrFetch or run on Node >= 18");return{baseUrl:a,fetchImpl:o,token:t}},C=(e,r)=>{e.logger.info(`backup retention would keep the newest ${r.keep.toString()} of ${r.eligible.toString()} under ${r.prefix} and delete ${r.wouldDelete.length.toString()}`);for(const a of r.wouldDelete)e.logger.info(` ${A(a)}`)},Re=async e=>{const r=L(e);if(r===void 0)return{code:1};const a=await r.fetchImpl(`${r.baseUrl}${q}`,{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(!a.ok)return await b(a,e.logger),{code:1};const t=await a.json();return t.cron===void 0?(e.logger.info("no scheduled backup is configured (`backupCron`), so retention would delete nothing"),{code:0,preview:t}):t.keep<=0?(e.logger.info(`retention is off for cron "${t.cron}" (\`backupRetain\` unset) — every snapshot under ${t.prefix} is kept`),{code:0,preview:t}):(C(e,t),t.eligible===0&&e.logger.info(`no snapshot under ${t.prefix} was written by this cron, so retention has nothing of its own to remove`),{code:0,preview:t})},xe=(e,r)=>{e.logger.success(`deleted ${r.deleted.length.toString()} backup(s)`);for(const a of r.deleted)e.logger.info(` ${A(a)}`);r.failed.length>0&&e.logger.warn(`${r.failed.length.toString()} could not be removed — the snapshot may be gone with its manifest left behind; run again to retry`),r.ignored>0&&e.logger.info(`${r.ignored.toString()} were already gone by the time the delete ran`),r.remaining>0&&e.logger.info(`${r.remaining.toString()} more are past the window — run \`lunora backup prune\` again`)},Oe=async e=>{const r=L(e);if(r===void 0)return{code:1};const a=await r.fetchImpl(`${r.baseUrl}${q}`,{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(!a.ok)return await b(a,e.logger),{code:1};const t=await a.json();if(t.keep<=0||t.cron===void 0)return e.logger.error("backup prune needs a retention window: set `backupRetain` (and `backupCron`) on the worker. Without one there is nothing past the window to remove."),{code:1,preview:t};if(t.wouldDelete.length===0)return e.logger.info(`nothing to prune — ${t.eligible.toString()} snapshot(s) under ${t.prefix} and retention keeps the newest ${t.keep.toString()}`),{code:0,preview:t};if(C(e,t),e.yes!==!0){const d=e.confirm??(K()?z:void 0);if(d===void 0)return e.logger.error("refusing to delete backups without confirmation — re-run with --yes (there is no undo for an object-store delete)"),{code:1,preview:t};if(!await d(`delete ${t.wouldDelete.length.toString()} backup(s)? This cannot be undone. [y/N] `))return e.logger.info("nothing was deleted"),{code:0,preview:t}}const o=await r.fetchImpl(`${r.baseUrl}${ke}`,{body:JSON.stringify({confirm:t.wouldDelete}),headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"POST"});if(!o.ok)return await b(o,e.logger),{code:1,preview:t};const i=await o.json();return xe(e,i),{code:i.failed.length>0?1:0,deleted:i.deleted,preview:t}},Ae=async e=>{const r=e.cwd??process.cwd();try{if(e.subcommand==="pitr")return await _e(e);if(e.subcommand==="retention")return await Re(e);if(e.subcommand==="prune")return await Oe(e);const a=Pe(e,r);return a===void 0?{code:1}:e.subcommand==="create"?await $e(e,a):e.subcommand==="list"?await Ne(e,a):await Se(e,a)}catch(a){return e.logger.error(a instanceof Error?a.message:String(a)),{code:1}}},Be=e=>e==="create"||e==="list"||e==="pitr"||e==="prune"||e==="restore"||e==="retention",Ze=X(({argument:e,cwd:r,logger:a,options:t})=>{const o=e[0];return Be(o)?Ae({at:t.at,bookmark:t.bookmark,bucket:t.bucket,cwd:r,dir:t.dir,logger:a,prefix:t.prefix,prod:t.prod===!0,restart:t.restart===!0,restore:t.restore===!0,shard:t.shard,subcommand:o,tables:t.tables,target:e[1],token:t.token,url:Q({cwd:r,prod:t.prod===!0,url:t.url}),verify:t.verify===!0,yes:t.yes===!0}):(a.error(`backup: unknown subcommand "${o??""}" — expected create | list | restore | retention | prune | pitr`),{code:1})});export{Ze as execute,Ae as runBackupCommand};
|
|
1
|
+
import F,{join as l,resolve as N}from"node:path";import{isInteractive as K,promptYesNo as z}from"@lunora/config";import{backupObjectKey as p,isBackupManifestEntry as O,normalizeBackupPrefix as H,BACKUP_KEY_PREFIX as J,backupManifestKey as G,isBackupManifestKey as W,backupObjectKeyOfManifest as A}from"@lunora/runtime";import{r as v,t as Y}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{r as $}from"../packem_shared/admin-url-BhF5ufg1.mjs";import{d as X}from"../packem_shared/command-DwC11Cwe.mjs";import{r as Q}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{readAndLogBody as b}from"./runRpcCommand.mjs";import{randomUUID as B,createHash as V}from"node:crypto";import{existsSync as T,createReadStream as Z,createWriteStream as ee}from"node:fs";import{mkdir as re,rm as w,rename as U,readFile as D,writeFile as te,realpath as S,mkdtemp as E}from"node:fs/promises";import{LunoraError as h}from"@lunora/errors";import{i as I}from"../packem_shared/path-containment-CgxYZggb.mjs";import{tmpdir as _}from"node:os";import{Readable as ae}from"node:stream";import{pipeline as oe}from"node:stream/promises";import{b as ne,l as ie,M as x,u as ce,r as se}from"../packem_shared/import-Dqd1MOOv.mjs";import{runExportCommand as de}from"../packem_shared/runExportCommand-Dq-SpjAe.mjs";const y="manifest.json",j=async e=>{const r=V("sha256");let a=0;for await(const t of Z(e)){const o=t;a+=o.byteLength,r.update(o)}return{bytes:a,sha256:r.digest("hex")}},R=async e=>{const r=l(e,y);if(!T(r))return[];let a;try{a=JSON.parse(await D(r,"utf8"))}catch(t){const o=t instanceof Error?t.message:String(t);throw new h("INTERNAL",`backup: ${r} exists but is not valid JSON (${o}) — refusing to overwrite it; fix or remove it manually`,{cause:t})}if(!Array.isArray(a))throw new TypeError(`backup: ${r} exists but is not a JSON array — refusing to overwrite it; fix or remove it manually`);return a.filter(t=>O(t))},ue=async(e,r)=>{const a=l(e,`${y}.${B()}.tmp`);try{await te(a,`${JSON.stringify(r,void 0,2)}
|
|
2
|
+
`,"utf8"),await U(a,l(e,y))}catch(t){throw await w(a,{force:!0}),t}},le=async(e,r)=>{const a=N(e),t=N(a,r.file),o=()=>{throw new h("INTERNAL",`backup: entry ${r.id} points outside ${a} (${r.file}) — refusing to read it`)};if(I(a,t)||o(),!!T(t))return I(await S(a),await S(t))||o(),t},fe=e=>{const r=a=>p("",a);return{commit:async(a,t)=>{await U(t,l(e,a))},label:e,list:async()=>R(e),locate:r,materialize:async(a,t)=>{const o=i=>i===void 0?void 0:{path:i,release:()=>Promise.resolve()};return o(a===void 0?T(t)?t:void 0:await le(e,a))},record:async a=>{const t=await R(e);t.push(a),await ue(e,t)},stage:async a=>{await re(e,{recursive:!0});const t=l(e,`${r(a)}.${B()}.partial`);return{path:t,release:()=>w(t,{force:!0})}}}},ge="/_lunora/admin/storage/object",me="/_lunora/admin/storage",P=8,he=(e,r=F)=>{const a=r.basename(e);return a===""||a==="."||a===".."?"snapshot.ndjson":a},we=e=>{const{context:r,logger:a}=e,t=H(e.prefix??J),o=`bucket ${r.bucket??"(default)"} under ${t}`,i=ne(r),d=c=>`${r.baseUrl}${ge}?key=${encodeURIComponent(c)}${i}`,f=async c=>{const n=await r.fetchImpl(d(c),{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(!n.ok){const u=await n.text().catch(()=>"<no body>");throw new h("INTERNAL",`backup: could not read ${c} (HTTP ${String(n.status)}): ${u}`)}return n.text()},M=async c=>{try{const n=JSON.parse(await f(c));if(O(n))return n;a.warn(`backup: ignoring ${c} — not a backup manifest`)}catch(n){a.warn(`backup: ignoring ${c} — ${n instanceof Error?n.message:String(n)}`)}};return{commit:async(c,n,u)=>{if(u.bytes>x)throw new h("INTERNAL",`backup: the snapshot is ${String(u.bytes)} bytes, above the ${String(x)}-byte limit for a checksum-verified upload — nothing was written. Narrow it with \`--tables\`, or write it to a directory with \`--dir\` and move the file yourself (\`wrangler r2 object put\`).`);const s=await D(n);await ce(r,c,s,{contentType:"application/x-ndjson",id:c,sha256:u.sha256,size:u.bytes},a)},label:o,list:async()=>{const n=(await ie(r,t)).map(s=>s.key).filter(s=>W(s)),u=[];for(let s=0;s<n.length;s+=P){const g=await Promise.all(n.slice(s,s+P).map(async m=>M(m)));u.push(...g.filter(m=>m!==void 0))}return u.toSorted((s,g)=>s.id.localeCompare(g.id))},locate:c=>p(t,c),materialize:async(c,n)=>{const u=c?.file??n,s=await r.fetchImpl(d(u),{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(s.status===404)return;if(!s.ok||s.body===null){const k=await s.text().catch(()=>"<no body>");throw new h("INTERNAL",`backup: could not download ${u} (HTTP ${String(s.status)}): ${k}`)}const g=await E(l(_(),"lunora-backup-")),m=l(g,he(u));try{await oe(ae.from(s.body),ee(m))}catch(k){throw await w(g,{force:!0,recursive:!0}),k}return{path:m,release:async()=>w(g,{force:!0,recursive:!0})}},record:async c=>{const n=G(c.file),u=await r.fetchImpl(`${r.baseUrl}${me}?key=${encodeURIComponent(n)}${i}`,{body:`${JSON.stringify(c,void 0,2)}
|
|
3
|
+
`,headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"PUT"});if(!u.ok){const s=await u.text().catch(()=>"<no body>");throw new h("INTERNAL",`backup: snapshot ${c.file} was written but its manifest was not (HTTP ${String(u.status)}): ${s}`)}},stage:async c=>{const n=await E(l(_(),"lunora-backup-"));return{path:l(n,p("",c)),release:async()=>w(n,{force:!0,recursive:!0})}}}},be=".lunora-backups",q="/_lunora/admin/backup/retention",ke="/_lunora/admin/backup/prune",pe="/_lunora/admin/pitr",ye="__lunora_admin__:getPitrBookmark",ve="__lunora_admin__:pitrRestore",$e=async(e,r)=>{const a=(e.now??(()=>new Date))().toISOString(),t=await r.stage(a);try{const o=await de({cwd:e.cwd,fetchImpl:e.fetchImpl,logger:e.logger,out:t.path,prod:e.prod,tables:e.tables,token:e.token,url:e.url});if(o.code!==0)return{code:o.code};const i=r.locate(a),d=await j(t.path);await r.commit(i,t.path,d);const f={bytes:d.bytes,createdAt:a,file:i,id:a,rows:o.rows,sha256:d.sha256,tables:e.tables};return await r.record(f),e.logger.success(`backup created: ${i} (${o.rows.toString()} rows, ${d.bytes.toString()} bytes)`),{code:0,entry:f}}finally{await t.release().catch(o=>{e.logger.warn(`backup: could not clean up staging (${o instanceof Error?o.message:String(o)})`)})}},Te=async(e,r,a)=>{if(r?.sha256===void 0)return a.error(r===void 0?"--verify needs a recorded checksum, and a snapshot restored by path/key has no manifest entry — restore it by its backup id instead":`--verify: backup ${r.id} carries no recorded checksum — it was taken by a release before checksums existed`),{code:1};const t=await j(e);if(t.sha256!==r.sha256)return a.error(`--verify: ${r.file} does not match its recorded checksum (expected ${r.sha256}, got ${t.sha256}) — nothing was imported`),{code:1};a.success(`verified ${r.file} against its recorded sha256`)},Ne=async(e,r)=>{const a=await r.list();if(a.length===0)return e.logger.info(`no backups found in ${r.label}`),{code:0};for(const t of a)e.logger.info(`${t.id} ${t.rows.toString()} rows ${t.bytes.toString()} bytes ${t.file}`);return{code:0}},Se=async(e,r)=>{const{target:a}=e;if(a===void 0||a.length===0)return e.logger.error("restore requires a backup id or file path. Usage: lunora backup restore <id|file>"),{code:1};const o=(await r.list()).find(d=>d.id===a),i=await r.materialize(o,a);if(i===void 0)return e.logger.error(`backup not found: ${a}`),{code:1};try{if(e.verify===!0){const f=await Te(i.path,o,e.logger);if(f!==void 0)return f}return{code:(await se({cwd:e.cwd,fetchImpl:e.fetchImpl,file:i.path,logger:e.logger,prod:e.prod,token:e.token,url:e.url,yes:e.yes})).code}}finally{await i.release().catch(d=>{e.logger.warn(`backup: could not clean up the downloaded snapshot (${d instanceof Error?d.message:String(d)})`)})}},Ee=e=>{if(e.prod&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}if(e.restore===!0&&e.at===void 0&&e.bookmark===void 0){e.logger.error("pitr --restore requires --at <time> or --bookmark <bookmark>");return}const r=$(e.url,e.logger,e.cwd);if(r===void 0)return;if(e.restore===!0&&Y({prod:e.prod,url:r})&&e.yes!==!0){e.logger.error(`pitr --restore restores data in place at ${r}, which is not local. Re-run with --yes to confirm.`);return}const{token:a}=v({cwd:e.cwd??process.cwd(),token:e.token,url:r});if(!a){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const t=e.adminFetch??globalThis.fetch;if(typeof t!="function")throw new TypeError("no fetch implementation available — pass pitrFetch or run on Node >= 18");return{fetchImpl:t,requestUrl:`${r}${pe}`,token:a}},Ie=(e,r)=>{const a={};return e.at!==void 0&&(a.time=e.at),r&&e.bookmark!==void 0&&(a.bookmark=e.bookmark),r&&e.restart===!0&&(a.restart=!0),a},_e=async e=>{const r=Ee(e);if(r===void 0)return{code:1};const a=e.restore===!0,t=a?ve:ye,o=Ie(e,a),i=a?"restore":"bookmark";e.logger.info(`POST ${r.requestUrl} -> pitr ${i}${e.shard===void 0?"":` (shard "${e.shard}")`}`);const d=await r.fetchImpl(r.requestUrl,{body:JSON.stringify({args:o,functionPath:t,shardKey:e.shard}),headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"POST"});return await b(d,e.logger),{code:d.ok?0:1}},xe=(e,r)=>{if(e.bucket===void 0){if(e.prefix!==void 0){e.logger.error("--prefix applies only to an R2 destination — pass --bucket alongside it, or use --dir to point at a local directory.");return}return fe(l(r,e.dir??be))}if(e.dir!==void 0){e.logger.error("--dir applies only to a local destination and does not apply alongside --bucket — drop one.");return}if(e.prod===!0&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}const a=$(e.url,e.logger,e.cwd);if(a===void 0)return;const{token:t}=v({cwd:r,token:e.token,url:a});if(!t){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const o=e.fetchImpl??globalThis.fetch;if(typeof o!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return we({context:{baseUrl:a,bucket:e.bucket==="default"?void 0:e.bucket,fetchImpl:o,token:t},logger:e.logger,prefix:e.prefix})},L=e=>{const r=[e.bucket===void 0?void 0:"--bucket",e.prefix===void 0?void 0:"--prefix",e.dir===void 0?void 0:"--dir"].filter(i=>i!==void 0);if(r.length>0){e.logger.error(`${r.join(" / ")} ${r.length===1?"does":"do"} not apply here — retention and prune act on the store the worker itself is configured with (\`backupStore\`), not a destination you name.`);return}if(e.prod===!0&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to target the implicit localhost worker)");return}const a=$(e.url,e.logger,e.cwd);if(a===void 0)return;const{token:t}=v({cwd:e.cwd??process.cwd(),token:e.token,url:a});if(!t){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}const o=e.adminFetch??globalThis.fetch;if(typeof o!="function")throw new TypeError("no fetch implementation available — pass pitrFetch or run on Node >= 18");return{baseUrl:a,fetchImpl:o,token:t}},C=(e,r)=>{e.logger.info(`backup retention would keep the newest ${r.keep.toString()} of ${r.eligible.toString()} under ${r.prefix} and delete ${r.wouldDelete.length.toString()}`);for(const a of r.wouldDelete)e.logger.info(` ${A(a)}`)},Re=async e=>{const r=L(e);if(r===void 0)return{code:1};const a=await r.fetchImpl(`${r.baseUrl}${q}`,{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(!a.ok)return await b(a,e.logger),{code:1};const t=await a.json();return t.cron===void 0?(e.logger.info("no scheduled backup is configured (`backupCron`), so retention would delete nothing"),{code:0,preview:t}):t.keep<=0?(e.logger.info(`retention is off for cron "${t.cron}" (\`backupRetain\` unset) — every snapshot under ${t.prefix} is kept`),{code:0,preview:t}):(C(e,t),t.eligible===0&&e.logger.info(`no snapshot under ${t.prefix} was written by this cron, so retention has nothing of its own to remove`),{code:0,preview:t})},Pe=(e,r)=>{e.logger.success(`deleted ${r.deleted.length.toString()} backup(s)`);for(const a of r.deleted)e.logger.info(` ${A(a)}`);r.failed.length>0&&e.logger.warn(`${r.failed.length.toString()} could not be removed — the snapshot may be gone with its manifest left behind; run again to retry`),r.ignored>0&&e.logger.info(`${r.ignored.toString()} were already gone by the time the delete ran`),r.remaining>0&&e.logger.info(`${r.remaining.toString()} more are past the window — run \`lunora backup prune\` again`)},Oe=async e=>{const r=L(e);if(r===void 0)return{code:1};const a=await r.fetchImpl(`${r.baseUrl}${q}`,{headers:{authorization:`Bearer ${r.token}`},method:"GET"});if(!a.ok)return await b(a,e.logger),{code:1};const t=await a.json();if(t.keep<=0||t.cron===void 0)return e.logger.error("backup prune needs a retention window: set `backupRetain` (and `backupCron`) on the worker. Without one there is nothing past the window to remove."),{code:1,preview:t};if(t.wouldDelete.length===0)return e.logger.info(`nothing to prune — ${t.eligible.toString()} snapshot(s) under ${t.prefix} and retention keeps the newest ${t.keep.toString()}`),{code:0,preview:t};if(C(e,t),e.yes!==!0){const d=e.confirm??(K()?z:void 0);if(d===void 0)return e.logger.error("refusing to delete backups without confirmation — re-run with --yes (there is no undo for an object-store delete)"),{code:1,preview:t};if(!await d(`delete ${t.wouldDelete.length.toString()} backup(s)? This cannot be undone. [y/N] `))return e.logger.info("nothing was deleted"),{code:0,preview:t}}const o=await r.fetchImpl(`${r.baseUrl}${ke}`,{body:JSON.stringify({confirm:t.wouldDelete}),headers:{authorization:`Bearer ${r.token}`,"content-type":"application/json"},method:"POST"});if(!o.ok)return await b(o,e.logger),{code:1,preview:t};const i=await o.json();return Pe(e,i),{code:i.failed.length>0?1:0,deleted:i.deleted,preview:t}},Ae=async e=>{const r=e.cwd??process.cwd();try{if(e.subcommand==="pitr")return await _e(e);if(e.subcommand==="retention")return await Re(e);if(e.subcommand==="prune")return await Oe(e);const a=xe(e,r);return a===void 0?{code:1}:e.subcommand==="create"?await $e(e,a):e.subcommand==="list"?await Ne(e,a):await Se(e,a)}catch(a){return e.logger.error(a instanceof Error?a.message:String(a)),{code:1}}},Be=e=>e==="create"||e==="list"||e==="pitr"||e==="prune"||e==="restore"||e==="retention",Ze=X(({argument:e,cwd:r,logger:a,options:t})=>{const o=e[0];return Be(o)?Ae({at:t.at,bookmark:t.bookmark,bucket:t.bucket,cwd:r,dir:t.dir,logger:a,prefix:t.prefix,prod:t.prod===!0,restart:t.restart===!0,restore:t.restore===!0,shard:t.shard,subcommand:o,tables:t.tables,target:e[1],token:t.token,url:Q({cwd:r,prod:t.prod===!0,url:t.url}),verify:t.verify===!0,yes:t.yes===!0}):(a.error(`backup: unknown subcommand "${o??""}" — expected create | list | restore | retention | prune | pitr`),{code:1})});export{Ze as execute,Ae as runBackupCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{V as I}from"../packem_shared/cli-
|
|
1
|
+
import{V as I}from"../packem_shared/cli-DIb5Ay4K.mjs";import{d as R}from"../packem_shared/command-DwC11Cwe.mjs";import{existsSync as u,readFileSync as v,mkdirSync as J,realpathSync as W,statSync as V,writeFileSync as z,chmodSync as G,renameSync as H,unlinkSync as K}from"node:fs";import{homedir as w}from"node:os";import{findWranglerFile as q}from"@lunora/config/cloudflare";import{join as s,dirname as B,relative as X}from"@visulima/path";import{stringify as Z}from"smol-toml";import{parse as Q,modify as Y,applyEdits as ee}from"jsonc-parser";import{detectPackageManager as re,execArgsFor as te,readLiveDevServerState as b,DEV_STATE_DIR as ne}from"@lunora/config";import{resolveAdminToken as oe}from"@lunora/config/studio-host";import{connectLocalStdio as ae}from"@lunora/mcp";import{resolve as h}from"node:path";import{i as le}from"../packem_shared/path-containment-CgxYZggb.mjs";const f=e=>({args:[...e.args],command:e.command,...e.env===void 0?{}:{env:e.env}}),y=e=>e.transport==="http"?{type:"http",url:e.url}:f(e),ce=e=>e.transport==="http"?{httpUrl:e.url}:f(e),se=e=>e.transport==="http"?{serverUrl:e.url}:f(e),ie=e=>({args:["-y","mcp-remote",e],command:"npx"}),de=e=>e.transport==="http"?ie(e.url):f(e),ue=e=>e.transport==="http"?{url:e.url}:f(e),fe=e=>e.transport==="http"?{enabled:!0,type:"remote",url:e.url}:{command:[e.command,...e.args],enabled:!0,type:"local",...e.env===void 0?{}:{environment:e.env}},me=e=>e.transport==="http"?{disabled:!1,type:"streamableHttp",url:e.url}:{disabled:!1,...f(e)},pe=({home:e,platform:r})=>{if(r==="darwin")return{global:s(e,"Library","Application Support","Claude","claude_desktop_config.json")};if(r==="win32"){const t=process.env.APPDATA;return t===void 0||t===""?{}:{global:s(t,"Claude","claude_desktop_config.json")}}return r==="linux"?{global:s(e,".config","Claude","claude_desktop_config.json")}:{}},ge=(e,r)=>Z({mcp_servers:{[e]:r.transport==="http"?{url:r.url}:{args:[...r.args],command:r.command,...r.env===void 0?{}:{env:r.env}}}}),g=[{buildEntry:y,paths:({projectRoot:e})=>({project:s(e,".mcp.json")}),format:"json",id:"claude-code",key:"mcpServers",label:"Claude Code"},{buildEntry:y,paths:({home:e,projectRoot:r})=>({global:s(e,".cursor","mcp.json"),project:s(r,".cursor","mcp.json")}),format:"json",id:"cursor",key:"mcpServers",label:"Cursor"},{buildEntry:y,paths:({projectRoot:e})=>({project:s(e,".vscode","mcp.json")}),format:"json",id:"vscode",key:"servers",label:"VS Code (GitHub Copilot)"},{buildEntry:ce,paths:({home:e,projectRoot:r})=>({global:s(e,".gemini","settings.json"),project:s(r,".gemini","settings.json")}),format:"json",id:"gemini",key:"mcpServers",label:"Gemini CLI"},{buildEntry:de,paths:pe,format:"json",id:"claude-desktop",key:"mcpServers",label:"Claude Desktop"},{buildEntry:se,paths:({home:e})=>({global:s(e,".codeium","windsurf","mcp_config.json")}),format:"json",id:"windsurf",key:"mcpServers",label:"Windsurf"},{buildEntry:fe,paths:({home:e,projectRoot:r})=>({global:s(e,".config","opencode","opencode.json"),project:s(r,"opencode.json")}),format:"json",id:"opencode",key:"mcp",label:"OpenCode"},{buildEntry:me,paths:({home:e})=>({global:s(e,".cline","mcp.json")}),format:"json",id:"cline",key:"mcpServers",label:"Cline"},{buildEntry:ue,paths:({home:e})=>({global:s(e,".config","zed","settings.json")}),format:"json",id:"zed",key:"context_servers",label:"Zed"},{paths:({home:e,projectRoot:r})=>({global:s(e,".codex","config.toml"),project:s(r,".codex","config.toml")}),format:"manual",id:"codex",label:"Codex CLI",renderSnippet:ge}],x=g.map(e=>e.id),ve=e=>g.find(r=>r.id===e.toLowerCase()),_=(e,r)=>{let t=e,n;try{t=W(e),n=V(t).mode}catch{}const a=`${t}.lunora-${Math.random().toString(36).slice(2,10)}.tmp`;try{z(a,r,"utf8"),n!==void 0&&G(a,n),H(a,t)}catch(o){try{K(a)}catch{}throw o}},he={formattingOptions:{insertSpaces:!0,tabSize:4}},S=e=>{const r=[],t=Q(e,r,{allowTrailingComma:!0});return{errors:r,value:t}},p=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),k=(e,r,t)=>{if(!p(e))return;const n=e[r];return p(n)?n[t]:void 0},M=e=>{if(!u(e.path))return"absent";let r;try{r=v(e.path,"utf8")}catch{return"invalid"}if(r.trim().length===0)return"absent";const{errors:t,value:n}=S(r);return t.length>0||!p(n)?"invalid":k(n,e.key,e.name)===void 0?"absent":"present"},ye=e=>M(e)==="present",L=(e,r,t,n,a)=>{try{const o=Y(e,[t,n],a,he);o.length>0&&_(r,ee(e,o));return}catch(o){return o instanceof Error?o.message:String(o)}},be=e=>{const{entry:r,force:t=!1,key:n,name:a,path:o}=e,l=u(o)?v(o,"utf8"):"";if(l.trim().length===0)return J(B(o),{recursive:!0}),_(o,`${JSON.stringify({[n]:{[a]:r}},void 0,4)}
|
|
2
2
|
`),{action:"created",path:o};const{errors:c,value:i}=S(l);if(c.length>0)return{action:"invalid",error:`parse error at offset ${String(c[0]?.offset??0)}`,path:o};if(!p(i))return{action:"invalid",error:"the file's root is not a JSON object",path:o};const m=i[n];if(m!==void 0&&!p(m))return{action:"invalid",error:`"${n}" is not an object`,path:o};if(k(i,n,a)!==void 0&&!t)return{action:"skipped",path:o};const $=L(l,o,n,a,r);return $===void 0?{action:"updated",path:o}:{action:"invalid",error:$,path:o}},we=e=>{const{key:r,name:t,path:n}=e;if(!u(n))return{action:"absent",path:n};let a;try{a=v(n,"utf8")}catch(i){return{action:"invalid",error:i instanceof Error?i.message:String(i),path:n}}const{errors:o,value:l}=S(a);if(o.length>0)return{action:"invalid",error:`parse error at offset ${String(o[0]?.offset??0)}`,path:n};if(k(l,r,t)===void 0)return{action:"absent",path:n};const c=L(a,n,r,t,void 0);return c===void 0?{action:"removed",path:n}:{action:"invalid",error:c,path:n}},Se=["global","project"],d=(e,r)=>{const t=X(r,e);return t.length>0&&!t.startsWith("..")?t:e},ke=(e,r)=>{const t=e.paths(r);return Se.flatMap(n=>{const a=t[n];return a===void 0?[]:[{client:e,path:a,scope:n}]})},$e=(e,r,t,n)=>{const a=e.paths(r),o=t==="global"?"project":"global",l=a[t]??(n?void 0:a[o]);if(l!==void 0)return{client:e,path:l,scope:a[t]===void 0?o:t}},Ee=e=>g.filter(r=>Object.values(r.paths(e)).some(t=>u(t))),N=(e,r,t,n)=>{if(e.length===0)return r();const a=[];for(const o of e){const l=ve(o);if(l===void 0){t.error(`mcp ${n}: unknown client "${o}". Known clients: ${x.join(", ")}.`);return}a.push(l)}return a},je=e=>e.client.format==="json",Oe="https://lunora.sh/mcp",A="lunora-docs",U="lunora",Ce=e=>u(s(e,"lunora"))&&q(e)!==void 0,xe=e=>{const{args:r,command:t}=te(e,"lunora",["mcp","serve"]);return{args:r,command:t,transport:"stdio"}},_e=e=>({transport:"http",url:e}),Me=e=>({home:e.home,platform:e.platform,projectRoot:e.cwd}),D=(e,r,t)=>$e(e,Me(t),t.scope??r.preferredScope,t.scope!==void 0||!r.allowScopeFallback),Le=(e,r,t)=>{const n=D(e,r,t);if(n===void 0){t.logger.warn(`${e.label}: has no ${t.scope??r.preferredScope}-scoped config — skipped "${r.name}".`);return}const{path:a}=n,o=e.buildEntry(r.spec);if(t.print===!0){const i=d(a,t.cwd);return t.force!==!0&&ye({key:e.key,name:r.name,path:a})?(t.logger.info(`${e.label}: "${r.name}" already configured in ${i} — a real install would skip it (re-run with --force to replace).`),{action:"printed",path:a}):(t.logger.info(`${e.label} → ${i}
|
|
3
3
|
${JSON.stringify({[e.key]:{[r.name]:o}},void 0,4)}`),{action:"printed",path:a})}const l=be({entry:o,force:t.force===!0,key:e.key,name:r.name,path:a}),c=d(a,t.cwd);return l.action==="invalid"?t.logger.error(`${e.label}: ${c} is not valid JSON (${l.error??"unknown error"}) — left untouched.`):l.action==="skipped"?t.logger.info(`${e.label}: "${r.name}" already configured in ${c} — re-run with --force to replace it.`):t.logger.success(`${e.label}: ${l.action==="created"?"created":"updated"} ${c} with "${r.name}".`),{action:l.action,path:a}},Ne=(e,r,t)=>{const n=D(e,r,t)?.path;if(n===void 0){t.logger.warn(`${e.label}: no known config location on ${t.platform} — skipped.`);return}return t.logger.info(`${e.label}: add this to ${d(n,t.cwd)}
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as p,readFileSync as v,realpathSync as h}from"node:fs";import{join as u}from"node:path";import{isPlaceholderValue as w,DEV_VARS_FILE as g,parseDevVariableEntries as k,discoverSchemaInfo as x,inferLunoraBindings as b}from"@lunora/config";import{findWranglerFile as y,readWranglerJsonc as $,validateWranglerConfig as S,collectExportGaps as _}from"@lunora/config/cloudflare";import{i as A,m as N,c as R}from"../packem_shared/vectorize-metadata-dXpl2_Ar.mjs";import{r as
|
|
1
|
+
import{existsSync as p,readFileSync as v,realpathSync as h}from"node:fs";import{join as u}from"node:path";import{isPlaceholderValue as w,DEV_VARS_FILE as g,parseDevVariableEntries as k,discoverSchemaInfo as x,inferLunoraBindings as b}from"@lunora/config";import{findWranglerFile as y,readWranglerJsonc as $,validateWranglerConfig as S,collectExportGaps as _}from"@lunora/config/cloudflare";import{i as A,m as N,c as R}from"../packem_shared/vectorize-metadata-dXpl2_Ar.mjs";import{r as E,d as L}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{d as I}from"../packem_shared/command-DwC11Cwe.mjs";import{v as j,i as D,p as O,l as V}from"../packem_shared/output-format-DfogXx0p.mjs";import{i as C}from"../packem_shared/path-containment-CgxYZggb.mjs";const F=o=>{const e=o.trim();if(e==="")return!0;const n=e.toLowerCase();return n.includes("replace")||n.startsWith("<")&&n.endsWith(">")},P=o=>{const e=y(o);if(e===void 0)return{parsed:void 0,path:void 0};const{parsed:n}=$(e);return{parsed:n,path:e}},M=(o,e,n)=>{if(e===void 0){n.push({code:"wrangler-missing",fix:"Run `lunora init` (or `lunora dev`) to scaffold and reconcile wrangler.jsonc.",level:"fail",message:"wrangler.jsonc not found."});return}if(o===void 0){n.push({code:"wrangler-unparseable",fix:`Check ${e} is valid JSONC.`,level:"fail",message:`Could not parse ${e}.`});return}const t=S(o).errors.find(r=>r.includes("SHARD"));t===void 0?n.push({code:"wrangler-shard-binding-ok",level:"pass",message:"wrangler.jsonc present with a SHARD durable-object binding."}):n.push({code:"wrangler-shard-binding-missing",fix:"Run `lunora dev` to auto-reconcile, or add the binding manually.",level:"fail",message:t})},W=(o,e)=>{const{error:n,info:a}=x(o,"lunora");if(n!==void 0){e.push({code:"schema-unreadable",fix:"Fix the parse error, then re-run `lunora doctor`. `lunora codegen` reports the same failure with the offending source.",level:"fail",message:`lunora/schema.ts could not be parsed, so every schema-derived check was skipped: ${n}`});return}for(const t of a?.vectorMetadata??[]){const r=N(t.kind);if(r===void 0){e.push({code:"vector-metadata-unfilterable",fix:"Filter on a string, number or boolean column, or drop it from `metadata`.",level:"warn",message:`vector index "${t.index}" declares metadata "${t.property}", whose type Vectorize cannot filter on.`});continue}e.push({code:"vector-metadata-index-required",fix:`wrangler ${R({index:t.index,property:t.property,type:r}).join(" ")}`,level:"info",message:`vector index "${t.index}" filters on metadata "${t.property}" — that needs a Vectorize metadata index (\`lunora deploy\` creates it).`})}},T=(o,e)=>{if(o===void 0)return;const n=(o.d1_databases??[]).filter(Boolean);for(const a of n){const t=typeof a.database_id=="string"?a.database_id:"";if(F(t)){const r=typeof a.binding=="string"&&a.binding.length>0?a.binding:"<unnamed>";e.push({code:"d1-placeholder-id",fix:"Run `wrangler d1 create <name>` and paste the returned database_id into wrangler.jsonc.",level:"fail",message:`D1 binding "${r}" has a placeholder database_id ("${t||"<empty>"}").`})}}},z=(o,e)=>{if(o===void 0)return;const n=(o.send_email??[]).filter(Boolean);for(const a of n){const t=typeof a.destination_address=="string"?a.destination_address:"";if(t!==""&&w(t)){const r=typeof a.name=="string"&&a.name.length>0?a.name:"send_email";e.push({code:"email-destination-placeholder",fix:"Set destination_address to a verified Cloudflare Email Routing address.",level:"warn",message:`send_email binding "${r}" has a placeholder destination_address ("${t}").`})}}},B=(o,e)=>{const n=u(o,g);if(!p(n))return;let a;try{a=v(n,"utf8")}catch{return}const t=k(a).filter(r=>A(r.key)&&w(r.value)).map(r=>r.key);t.length>0&&e.push({code:"dev-vars-missing-secret",fix:"Run `lunora dev` to auto-generate secrets, or fill them in by hand.",level:"warn",message:`${g} has unfilled secret value(s): ${t.join(", ")}.`})},J=(o,e)=>{const{source:n}=E({cwd:o});n===void 0?e.push({code:"admin-token-missing",fix:"Set LUNORA_ADMIN_TOKEN (env or `.dev.vars`) to enable admin RPCs / studio.",level:"info",message:"LUNORA_ADMIN_TOKEN is not set."}):e.push({code:"admin-token-set",level:"pass",message:`LUNORA_ADMIN_TOKEN is set (${L(n)}).`})},K=async(o,e)=>{let n;try{n=await b({projectRoot:o})}catch(r){e.push({code:"declared-export-unchecked",fix:"Make sure the worker entry resolves (see `lunora codegen`), then re-run.",level:"warn",message:`could not check whether declared containers/workflows/agents are re-exported by the worker entry: ${r instanceof Error?r.message:String(r)}`});return}const a=_(n),t=[...n.containers.map(r=>({...r,kind:"container"})),...n.workflows.map(r=>({...r,kind:"workflow"})),...n.agents.map(r=>({...r,kind:"agent"}))];for(const r of t.filter(i=>i.exported))e.push({code:"declared-export-ok",level:"pass",message:`${r.kind} "${r.exportName}" is exported by the worker entry.`});for(const r of a)e.push({code:"declared-export-missing",fix:`Add \`export * from "./lunora/_generated/${r.module}"\` to your worker entry (or re-run \`vis generate lunora-${r.kind}\`).`,level:"fail",message:`${r.kind} "${r.exportName}" is declared but ${r.className} is not exported by the worker entry.`})},U=/^[\^~><= ]+/u,G=/^(?<core>\d+\.\d+\.\d+)(?:-(?<channel>[a-z]+)\.(?<counter>\d+))?$/u,H=o=>{const e=o.replace(U,"").trim(),n=G.exec(e);if(!n?.groups)return;const{channel:a,core:t,counter:r}=n.groups;return{channel:a??"",core:t??"",counter:r===void 0?void 0:Number.parseInt(r,10),raw:e}},q=(o,e)=>{const n=u(o,"package.json");if(!p(n))return;let a;try{a=JSON.parse(v(n,"utf8"))}catch{return}const t={...a.devDependencies,...a.dependencies},r=[];for(const[s,c]of Object.entries(t)){if(s!=="lunorash"&&!s.startsWith("@lunora/"))continue;const m=H(c);m&&r.push({name:s,version:m})}if(r.length<2)return;const i=s=>s.map(c=>`${c.name}@${c.version.raw}`).join(", "),l=new Set(r.map(s=>s.version.core)),f=new Set(r.map(s=>s.version.channel));if(l.size>1){e.push({code:"version-skew-cores",fix:'Run `pnpm update "@lunora/*" lunorash` (or `npm`/`yarn` equivalent) so every Lunora package moves to the same release.',level:"warn",message:`Lunora packages span ${String(l.size)} different versions: ${i(r)}.`});return}if(f.size>1){e.push({code:"version-skew-channels",fix:"Pick one channel (all stable, or all alpha/beta) and update the odd package out.",level:"warn",message:`Lunora packages mix release channels (${[...f].map(s=>s===""?"stable":s).join(" + ")}): ${i(r)}.`});return}const d=r.map(s=>s.version.counter).filter(s=>s!==void 0);if(d.length>1){const s=Math.min(...d),c=Math.max(...d);e.push({code:"version-counter-spread",level:"info",message:d.length===r.length&&s===c?`Lunora packages are all at ${[...f][0]??""}.${String(c)}.`:`Lunora pre-release counters span ${String(s)}–${String(c)}: ${i(r)}.`})}},X=[u("@lunora","cli"),"lunorash"],Q=(o,e,n)=>{if(e===void 0)return;const a=[];for(const r of X){const i=u(o,"node_modules",r);if(p(i))try{a.push(h(i))}catch{}}if(a.length===0)return;let t;try{t=h(e)}catch{return}a.some(r=>C(r,t))||n.push({code:"cli-shadowed",fix:"Run the project's own CLI: `pnpm exec lunora …` (or `npx lunora …`).",level:"warn",message:`the running lunora (${t}) is not the project's own install (${a.join(", ")}).`})},Y=async o=>{const e=o.cwd??process.cwd(),n=[],{parsed:a,path:t}=P(e);M(a,t,n),T(a,n),z(a,n),B(e,n),J(e,n),q(e,n),W(e,n),Q(e,o.executablePath??process.argv[1],n),await K(e,n);const r={fail:0,info:0,pass:0,warn:0};for(const l of n)r[l.level]+=1;const i=r.fail>0?1:0;return{code:i,findings:n,ok:i===0,summary:r}},Z={fail:"FAIL",info:"INFO",pass:"PASS",warn:"WARN"},ee=(o,e)=>{e.info("lunora doctor — project preflight");for(const t of o.findings){const r=`[${Z[t.level]}] ${t.message}`;t.level==="fail"?e.error(r):t.level==="warn"?e.warn(r):e.info(r),t.fix!==void 0&&t.level!=="pass"&&e.info(` fix: ${t.fix}`)}const{fail:n,warn:a}=o.summary;n>0?e.error(`${String(n)} failure(s), ${String(a)} warning(s).`):a>0?e.warn(`0 failures, ${String(a)} warning(s).`):e.success("all checks passed.")},re=async o=>{const e=j("doctor",o.format);if(e!==void 0)return o.logger.error(e),{code:1,findings:[],ok:!1,summary:{fail:0,info:0,pass:0,warn:0}};const n=V(o.format,o.logger),a=await Y({...o});return ee(a,n),D(o.format)&&O(a),a},ue=I(async({cwd:o,logger:e,options:n})=>({code:(await re({cwd:o,format:n.format,logger:e})).code}));export{ue as execute,Y as runDoctor,re as runDoctorCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as o}from"../packem_shared/command-DwC11Cwe.mjs";import{r as f}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{I as u,r as d}from"../packem_shared/import-
|
|
1
|
+
import{d as o}from"../packem_shared/command-DwC11Cwe.mjs";import{r as f}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import{I as u,r as d}from"../packem_shared/import-Dqd1MOOv.mjs";const n=o(({argument:m,cwd:a,logger:e,options:r})=>{const t=m[0];return t?r.from!==void 0&&!u.includes(r.from)?(e.error(`--from ${r.from} is not a known source. Expected one of: ${u.join(", ")}.`),{code:1}):d({batchSize:r.batchSize,cwd:a,file:t,from:r.from,logger:e,prod:r.prod===!0,scan:r.scan===!0,storageDir:r.storageDir,table:r.table,token:r.token,url:f({cwd:a,prod:r.prod===!0,url:r.url}),verify:r.verify===!0,withStorage:r.withStorage===!0,yes:r.yes===!0}):(e.error("import requires a path. Usage: lunora import <file.ndjson | convex-export-dir> [--table <name>]"),{code:1})});export{n as execute};
|