@lunora/cli 1.0.0-alpha.49 → 1.0.0-alpha.491
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/LICENSE.md +234 -104
- package/README.md +6 -4
- package/dist/bin.mjs +3 -10
- package/dist/cli.d.mts +31 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.mjs +1 -0
- package/dist/index.d.mts +1181 -427
- package/dist/index.d.ts +1181 -427
- package/dist/index.mjs +1 -19
- package/dist/packem_chunks/cli.mjs +2 -0
- package/dist/packem_chunks/dispatch.mjs +1 -0
- package/dist/packem_chunks/handler.mjs +61 -157
- package/dist/packem_chunks/handler10.mjs +1 -16
- package/dist/packem_chunks/handler11.mjs +1 -22
- package/dist/packem_chunks/handler12.mjs +1 -192
- package/dist/packem_chunks/handler13.mjs +3 -131
- package/dist/packem_chunks/handler14.mjs +1 -65
- package/dist/packem_chunks/handler15.mjs +1 -58
- package/dist/packem_chunks/handler16.mjs +1 -80
- package/dist/packem_chunks/handler17.mjs +1 -43
- package/dist/packem_chunks/handler18.mjs +1 -105
- package/dist/packem_chunks/handler19.mjs +1 -170
- package/dist/packem_chunks/handler2.mjs +1 -114
- package/dist/packem_chunks/handler20.mjs +1 -94
- package/dist/packem_chunks/handler21.mjs +7 -94
- package/dist/packem_chunks/handler22.mjs +1 -0
- package/dist/packem_chunks/handler23.mjs +3 -0
- package/dist/packem_chunks/handler24.mjs +3 -0
- package/dist/packem_chunks/handler25.mjs +2 -0
- package/dist/packem_chunks/handler26.mjs +1 -0
- package/dist/packem_chunks/handler27.mjs +2 -0
- package/dist/packem_chunks/handler28.mjs +99 -0
- package/dist/packem_chunks/handler29.mjs +3 -0
- package/dist/packem_chunks/handler3.mjs +1 -204
- package/dist/packem_chunks/handler30.mjs +15 -0
- package/dist/packem_chunks/handler31.mjs +1 -0
- package/dist/packem_chunks/handler32.mjs +1 -0
- package/dist/packem_chunks/handler4.mjs +1 -33
- package/dist/packem_chunks/handler5.mjs +3 -49
- package/dist/packem_chunks/handler6.mjs +1 -91
- package/dist/packem_chunks/handler7.mjs +1 -42
- package/dist/packem_chunks/handler8.mjs +1 -174
- package/dist/packem_chunks/handler9.mjs +2 -315
- package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
- package/dist/packem_chunks/runDevCommand.mjs +8 -0
- package/dist/packem_chunks/runInitCommand.mjs +423 -1452
- package/dist/packem_chunks/runResetCommand.mjs +1 -41
- package/dist/packem_chunks/runRpcCommand.mjs +1 -68
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck9tABfr.mjs +1 -0
- package/dist/packem_shared/EXIT_CODE-DQVhSE-1.mjs +1 -0
- package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
- package/dist/packem_shared/admin-url-DJB8P6Jh.mjs +1 -0
- package/dist/packem_shared/api-spec-lYyq4vL6.mjs +1 -0
- package/dist/packem_shared/binding-manifest-file-BZyQFSTF.mjs +2 -0
- package/dist/packem_shared/buildRegistryIndex-Dc8D8AR6.mjs +1 -0
- package/dist/packem_shared/cap-error-body-YBKO32BF.mjs +1 -0
- package/dist/packem_shared/catalog-CahzmDLV.mjs +1 -0
- package/dist/packem_shared/cli-manifest-DoQ_3bzs.mjs +1 -0
- package/dist/packem_shared/cloudflare-credentials-BVmZnDZk.mjs +1 -0
- package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
- package/dist/packem_shared/command-BpMv2n0o.mjs +1 -0
- package/dist/packem_shared/commands-CkuCMUP_.mjs +13 -0
- package/dist/packem_shared/createLogger-4TujevyB.mjs +2 -0
- package/dist/packem_shared/createRecordingSpawner-DchLi0gR.mjs +1 -0
- package/dist/packem_shared/deploy-target-resolve-BTCW1Iv4.mjs +1 -0
- package/dist/packem_shared/diffSnapshots-DcE-jQUz.mjs +9 -0
- package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
- package/dist/packem_shared/export-rows-EzdNDYpa.mjs +3 -0
- package/dist/packem_shared/free-port-DjbFhaaT.mjs +1 -0
- package/dist/packem_shared/health-probe-By9T5x2y.mjs +13 -0
- package/dist/packem_shared/import-3Y59Ry9F.mjs +13 -0
- package/dist/packem_shared/index-oHZBGBwB.mjs +1 -0
- package/dist/packem_shared/insertSchemaExtension-CbTH3lCQ.mjs +10 -0
- package/dist/packem_shared/js-literal-FWLi94Lh.mjs +1 -0
- package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
- package/dist/packem_shared/mcp-config-file-GR1Y_CVw.mjs +2 -0
- package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
- package/dist/packem_shared/output-format-DWe_tkTR.mjs +2 -0
- package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
- package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
- package/dist/packem_shared/plan-BF2E-dq4.mjs +5 -0
- package/dist/packem_shared/planDevCommand-C8QHZzEJ.mjs +1 -0
- package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
- package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
- package/dist/packem_shared/render-lunora-error-JsLelWwR.mjs +2 -0
- package/dist/packem_shared/resolve-Bdc9KEUv.mjs +5 -0
- package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
- package/dist/packem_shared/runAddCommand-gThKW-ZB.mjs +1 -0
- package/dist/packem_shared/runDeployCommand-DhgZz8Sj.mjs +1 -0
- package/dist/packem_shared/runExportCommand-_PtkJJDT.mjs +5 -0
- package/dist/packem_shared/runMigrateGenerateCommand-DHdSMKbu.mjs +11 -0
- package/dist/packem_shared/schemaIrToSnapshot-CbWOjany.mjs +1 -0
- package/dist/packem_shared/shared-CV7ESvuj.mjs +2 -0
- package/dist/packem_shared/sql-u1MSmopg.mjs +3 -0
- package/dist/packem_shared/storage-3GOIFVZm.mjs +1 -0
- package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
- package/dist/packem_shared/variables-CPYyJtsL.mjs +1 -0
- package/dist/packem_shared/vectorize-metadata-DK61NmVx.mjs +2 -0
- package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
- package/dist/packem_shared/wrangler-secrets-C9siMBwN.mjs +1 -0
- package/package.json +46 -20
- package/skills/README.md +36 -17
- package/skills/lunora/SKILL.md +158 -65
- package/skills/lunora-cloudflare-audit/SKILL.md +164 -0
- package/skills/lunora-create-package/SKILL.md +98 -84
- package/skills/lunora-deploy/SKILL.md +212 -102
- package/skills/lunora-functions/SKILL.md +367 -60
- package/skills/lunora-migration-helper/SKILL.md +194 -149
- package/skills/lunora-performance-audit/SKILL.md +137 -95
- package/skills/lunora-quickstart/SKILL.md +136 -136
- package/skills/lunora-realtime/SKILL.md +219 -97
- package/skills/lunora-setup-auth/SKILL.md +203 -101
- package/skills/lunora-setup-hyperdrive/SKILL.md +153 -110
- package/skills/lunora-setup-hyperdrive-global/SKILL.md +152 -94
- package/skills/lunora-setup-mail/SKILL.md +97 -113
- package/skills/lunora-setup-scheduler/SKILL.md +133 -97
- package/skills/lunora-setup-storage/SKILL.md +189 -95
- package/dist/packem_chunks/planDevCommand.mjs +0 -541
- package/dist/packem_chunks/runDeployCommand.mjs +0 -594
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
- package/dist/packem_shared/COMMANDS-B0ftFD_3.mjs +0 -948
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
- package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
- package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
- package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
- package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +0 -31
- package/dist/packem_shared/command-D3lB_4Az.mjs +0 -19
- package/dist/packem_shared/commands-B-gR09Z_.mjs +0 -845
- package/dist/packem_shared/createLogger-B40gPzQo.mjs +0 -78
- package/dist/packem_shared/createRecordingSpawner-DxI3mebw.mjs +0 -43
- package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
- package/dist/packem_shared/diffSnapshots-BeDvvNiF.mjs +0 -161
- package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
- package/dist/packem_shared/insertSchemaExtension-DAqbfr9Z.mjs +0 -64
- package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
- package/dist/packem_shared/output-format-wUvAN6AL.mjs +0 -17
- package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
- package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
- package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +0 -9
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
- package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +0 -4
- package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
- package/dist/packem_shared/schemaIrToSnapshot-DdsljJT-.mjs +0 -43
- package/dist/packem_shared/storage-BIsph-Vk.mjs +0 -84
- package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +0 -658
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
- package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +0 -47
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import '@
|
|
3
|
-
import { ensureDevVariables, ensureDevVarsExample, fillDevSecrets,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type CommandName = (typeof COMMANDS)[number];
|
|
8
|
-
declare const VERSION: string;
|
|
9
|
-
interface RunCliOptions {
|
|
10
|
-
argv?: ReadonlyArray<string>;
|
|
11
|
-
cwd?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Inject a console-like logger so callers (tests) can capture cerebro's
|
|
14
|
-
* help / version / usage rendering. Omitted in production, where cerebro
|
|
15
|
-
* uses its default stdout/stderr logger.
|
|
16
|
-
*/
|
|
17
|
-
logger?: Console;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Run the CLI and resolve to the process exit code. cerebro handles help,
|
|
21
|
-
* version, usage, and unknown commands (the latter throws, caught here as 1).
|
|
22
|
-
* `shouldExitProcess: false` keeps the process alive so callers/tests read the
|
|
23
|
-
* captured exit code.
|
|
24
|
-
*/
|
|
25
|
-
declare const runCli: (options?: RunCliOptions) => Promise<number>;
|
|
1
|
+
export { COMMANDS, type CommandName, type RunCliOptions, VERSION, runCli } from "./cli.mjs";
|
|
2
|
+
import { CodegenOptions, Finding, FieldSnapshot, SchemaIR } from '@lunora/codegen';
|
|
3
|
+
import { CelldToolchainProbeOptions, CelldToolchainProbe, DiscoveryCache, DevProcessSpawner, ensureDevVariables, ensureDevVarsExample, fillDevSecrets, startCelldDevSession, writeCelldDevProjection, LintTool, LintIgnoreOutcome } from '@lunora/config';
|
|
4
|
+
import { materializeDevWranglerConfig, materializeServiceDevConfigs, startLocalHyperdrive, RemotePlan } from '@lunora/config/cloudflare';
|
|
5
|
+
export { REQUIRED_COMPATIBILITY_DATE, REQUIRED_FLAG, type WranglerProjectValidationOptions as WranglerValidationOptions, type WranglerValidationReport, type WranglerProjectValidationResult as WranglerValidationResult, validateWranglerProject as validateWrangler, validateWranglerConfig } from '@lunora/config/cloudflare';
|
|
6
|
+
import { PackageManager, PackageManagerProbe } from '@lunora/config/cli';
|
|
26
7
|
/**
|
|
27
|
-
* The `--api-spec` flag's accepted values, mirroring `@lunora/codegen`'s
|
|
28
|
-
* `CodegenOptions["apiSpec"]`. `"openapi"` (the default) emits `openapi.json`;
|
|
29
|
-
* `"openrpc"` emits `openrpc.json`; `"both"` emits both; `"none"` emits neither.
|
|
30
|
-
*/
|
|
8
|
+
* The `--api-spec` flag's accepted values, mirroring `@lunora/codegen`'s
|
|
9
|
+
* `CodegenOptions["apiSpec"]`. `"openapi"` (the default) emits `openapi.json`;
|
|
10
|
+
* `"openrpc"` emits `openrpc.json`; `"both"` emits both; `"none"` emits neither.
|
|
11
|
+
*/
|
|
31
12
|
type ApiSpec = NonNullable<CodegenOptions["apiSpec"]>;
|
|
32
13
|
interface Logger {
|
|
33
14
|
debug?: (message: string) => void;
|
|
@@ -37,11 +18,11 @@ interface Logger {
|
|
|
37
18
|
warn: (message: string) => void;
|
|
38
19
|
}
|
|
39
20
|
/**
|
|
40
|
-
* Narrowed view over the pail instance. `createPail` returns an intersection
|
|
41
|
-
* type that includes a constructor signature and `(...args: any[])` logger
|
|
42
|
-
* overloads, which the type-aware linter cannot safely resolve. We only ever
|
|
43
|
-
* call the level methods with a string, so we describe exactly that surface.
|
|
44
|
-
*/
|
|
21
|
+
* Narrowed view over the pail instance. `createPail` returns an intersection
|
|
22
|
+
* type that includes a constructor signature and `(...args: any[])` logger
|
|
23
|
+
* overloads, which the type-aware linter cannot safely resolve. We only ever
|
|
24
|
+
* call the level methods with a string, so we describe exactly that surface.
|
|
25
|
+
*/
|
|
45
26
|
interface PailLogger {
|
|
46
27
|
debug: (message: string) => void;
|
|
47
28
|
error: (message: string) => void;
|
|
@@ -51,59 +32,109 @@ interface PailLogger {
|
|
|
51
32
|
}
|
|
52
33
|
declare const createLogger: () => Logger;
|
|
53
34
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
*/
|
|
60
|
-
/**
|
|
61
|
-
* Direct access to the underlying pail instance for advanced use-cases.
|
|
62
|
-
* A Proxy keeps the public `pail` binding lazy: the real pail is only
|
|
63
|
-
* constructed on first property access, so importing this module (and thus
|
|
64
|
-
* the package barrel) stays side-effect-free.
|
|
65
|
-
*/
|
|
35
|
+
* Direct access to the underlying pail instance for advanced use-cases.
|
|
36
|
+
* A Proxy keeps the public `pail` binding lazy: the real pail is only
|
|
37
|
+
* constructed on first property access, so importing this module (and thus
|
|
38
|
+
* the package barrel) stays side-effect-free.
|
|
39
|
+
*/
|
|
66
40
|
declare const pail: PailLogger;
|
|
67
41
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
42
|
+
* The two renderings every Lunora command speaks. `pretty` is the human-facing
|
|
43
|
+
* default; `json` puts the command's structured result on stdout as a single
|
|
44
|
+
* JSON document and moves every human line to stderr.
|
|
45
|
+
*
|
|
46
|
+
* Resolved ONCE, by `defineHandler`, from the raw `--format` string — a command
|
|
47
|
+
* body receives this narrowed type and never re-validates it.
|
|
48
|
+
*/
|
|
49
|
+
type OutputFormat = "json" | "pretty";
|
|
50
|
+
/**
|
|
51
|
+
* The envelope `--format json` puts on stdout — the same three keys for every
|
|
52
|
+
* command, so a consumer parses one shape and never has to know which command
|
|
53
|
+
* produced it.
|
|
54
|
+
*
|
|
55
|
+
* - `code` is the exit code the process will terminate with.
|
|
56
|
+
* - `data` is the command's own payload, and is absent when the run produced
|
|
57
|
+
* none — which is what a failure before any work looks like.
|
|
58
|
+
* - `error` is the single-line reason for a non-zero `code`. It is the half that
|
|
59
|
+
* makes a FAILURE machine-readable: before the envelope, a failed command wrote
|
|
60
|
+
* nothing at all to stdout and the reason could only be scraped out of English
|
|
61
|
+
* prose on stderr.
|
|
62
|
+
*
|
|
63
|
+
* `defineHandler` serializes exactly these keys, once, after the body returns —
|
|
64
|
+
* so a body may return a richer result for its in-process callers without
|
|
65
|
+
* widening the document, and a failure gets one for free.
|
|
66
|
+
*/
|
|
67
|
+
interface CommandResult<TData> {
|
|
68
|
+
/** Process exit code — one of `EXIT_CODE`. */
|
|
69
|
+
code: number;
|
|
70
|
+
/** The command's structured payload. Absent when the run produced none. */
|
|
71
|
+
data?: TData;
|
|
72
|
+
/**
|
|
73
|
+
* Set by a command that forwards `--format json` to a child process which
|
|
74
|
+
* writes the document itself (`wrangler … --json`, `wrangler tail`). The
|
|
75
|
+
* envelope is suppressed for that run: stdout already carries exactly one
|
|
76
|
+
* document, and appending a second would make the stream unparseable.
|
|
77
|
+
*/
|
|
78
|
+
delegated?: boolean;
|
|
79
|
+
/** Why the run failed. Set whenever `code` is non-zero and a reason is known. */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
73
82
|
interface CodegenCommandOptions {
|
|
74
83
|
/** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
|
|
75
84
|
apiSpec?: ApiSpec;
|
|
76
85
|
cwd?: string;
|
|
77
86
|
/** Output format: `pretty` (default) or `json`. */
|
|
78
|
-
format?:
|
|
87
|
+
format?: OutputFormat;
|
|
88
|
+
/** Opt into per-module lazy function loading; also enabled by LUNORA_LAZY_FUNCTIONS. */
|
|
89
|
+
lazyFunctions?: boolean;
|
|
79
90
|
logger: Logger;
|
|
91
|
+
/**
|
|
92
|
+
* Fail the run when any ERROR-level advisory is reported. Defaults to CI
|
|
93
|
+
* detection so a local `lunora codegen` stays advisory while a pipeline
|
|
94
|
+
* gates on it; `--no-strict-advisories` forces it off either way.
|
|
95
|
+
*/
|
|
96
|
+
strictAdvisories?: boolean;
|
|
97
|
+
/** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
|
|
98
|
+
target?: string;
|
|
80
99
|
}
|
|
81
|
-
|
|
100
|
+
/** The `--format json` payload: what codegen wrote, and what it has to say about it. */
|
|
101
|
+
interface CodegenCommandData {
|
|
82
102
|
advisories: ReadonlyArray<{
|
|
83
103
|
detail: string;
|
|
84
|
-
level:
|
|
104
|
+
level: Finding["level"];
|
|
85
105
|
name: string;
|
|
86
106
|
remediation: string;
|
|
87
107
|
}>;
|
|
88
108
|
cronTriggers: ReadonlyArray<string>;
|
|
89
|
-
/**
|
|
90
|
-
|
|
109
|
+
/** ERROR-level advisories that made the run fail, when strict mode is on. */
|
|
110
|
+
failedAdvisories: number;
|
|
91
111
|
outputDirectory: string;
|
|
92
112
|
}
|
|
113
|
+
interface CodegenCommandResult extends CodegenCommandData {
|
|
114
|
+
/**
|
|
115
|
+
* Exit code, when the run resolved one itself. Only a USAGE refusal does —
|
|
116
|
+
* every other outcome is classified from `error`/`failedAdvisories` by
|
|
117
|
+
* `execute`, which cannot tell a bad `--format` (the invocation is wrong,
|
|
118
|
+
* exit 2) from a failed codegen (exit 1) after the fact.
|
|
119
|
+
*/
|
|
120
|
+
code?: number;
|
|
121
|
+
/** Set when the run failed: an unregistered target, or an error-level platform diagnostic. */
|
|
122
|
+
error?: string;
|
|
123
|
+
}
|
|
93
124
|
declare const runCodegenCommand: (options: CodegenCommandOptions) => CodegenCommandResult;
|
|
94
|
-
/** `lunora codegen` handler (lazy-loaded via the command's `loader`). */
|
|
95
|
-
/** Rows per HTTP request when importing. Convex uses ~500; same here. */
|
|
96
|
-
declare const DEFAULT_IMPORT_BATCH_SIZE = 500;
|
|
97
125
|
/**
|
|
98
|
-
* Minimal projection of `globalThis.fetch` for the
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
|
|
126
|
+
* Minimal projection of `globalThis.fetch` for the transfer commands: `body` is
|
|
127
|
+
* exposed as a stream-iterable (the export path pipes it) and accepts bytes (the
|
|
128
|
+
* blob path uploads them). The JSON-only commands use the narrower `FetchLike`
|
|
129
|
+
* in `../run/handler` instead.
|
|
130
|
+
*/
|
|
102
131
|
type StreamingFetchLike = (input: string, init?: {
|
|
103
|
-
body?: string;
|
|
132
|
+
body?: string | Uint8Array;
|
|
104
133
|
headers?: Record<string, string>;
|
|
105
134
|
method?: string;
|
|
106
135
|
}) => Promise<{
|
|
136
|
+
/** Optional: only the storage transfer reads raw bytes, and only real `fetch` needs to supply it. */
|
|
137
|
+
arrayBuffer?: () => Promise<ArrayBuffer>;
|
|
107
138
|
body: ReadableStream<Uint8Array> | null;
|
|
108
139
|
json: () => Promise<unknown>;
|
|
109
140
|
ok: boolean;
|
|
@@ -113,6 +144,12 @@ type StreamingFetchLike = (input: string, init?: {
|
|
|
113
144
|
interface ExportCommandOptions {
|
|
114
145
|
cwd?: string;
|
|
115
146
|
fetchImpl?: StreamingFetchLike;
|
|
147
|
+
/**
|
|
148
|
+
* Output format: `pretty` (default) or `json`. `json` reports the run as a
|
|
149
|
+
* single document and therefore requires a file destination — with `--out -`
|
|
150
|
+
* (or none) stdout already carries the NDJSON stream.
|
|
151
|
+
*/
|
|
152
|
+
format?: OutputFormat;
|
|
116
153
|
logger: Logger;
|
|
117
154
|
/** Output file path; `undefined`/`-` streams to stdout. */
|
|
118
155
|
out?: string;
|
|
@@ -125,103 +162,382 @@ interface ExportCommandOptions {
|
|
|
125
162
|
/** Worker URL (default `http://localhost:8787`). */
|
|
126
163
|
url?: string;
|
|
127
164
|
}
|
|
128
|
-
|
|
165
|
+
/** The `--format json` payload: what was dumped, from which tables, and where to. */
|
|
166
|
+
interface ExportCommandData {
|
|
167
|
+
bytes: number;
|
|
168
|
+
/** The file the dump landed in. */
|
|
169
|
+
out: string;
|
|
170
|
+
rows: number;
|
|
171
|
+
/** The table allowlist, omitted when the export covered every table. */
|
|
172
|
+
tables?: string[];
|
|
173
|
+
}
|
|
174
|
+
interface ExportCommandResult extends CommandResult<ExportCommandData> {
|
|
129
175
|
bytes: number;
|
|
130
|
-
code: number;
|
|
131
176
|
/** Number of NDJSON lines streamed (0 on error). */
|
|
132
177
|
rows: number;
|
|
133
178
|
}
|
|
134
179
|
/**
|
|
135
|
-
* Stream an export. The worker emits NDJSON; we count newlines as we go and
|
|
136
|
-
* pipe straight to the output sink, so a 10M-row export doesn't materialise
|
|
137
|
-
* the body in memory.
|
|
138
|
-
*/
|
|
180
|
+
* Stream an export. The worker emits NDJSON; we count newlines as we go and
|
|
181
|
+
* pipe straight to the output sink, so a 10M-row export doesn't materialise
|
|
182
|
+
* the body in memory.
|
|
183
|
+
*/
|
|
139
184
|
declare const runExportCommand: (options: ExportCommandOptions) => Promise<ExportCommandResult>;
|
|
185
|
+
/** One row-scoped failure as the admin import endpoint reports it. */
|
|
186
|
+
interface ImportRowError {
|
|
187
|
+
code: string;
|
|
188
|
+
line: number;
|
|
189
|
+
message: string;
|
|
190
|
+
table: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* One SHARD the fan-out never reached, as the admin import endpoint reports it.
|
|
194
|
+
*
|
|
195
|
+
* Distinct from {@link ImportRowError}: the rows a dead shard owned contribute
|
|
196
|
+
* to neither `inserted` nor `errors`, so an unknown slice of the batch is simply
|
|
197
|
+
* missing. The endpoint answers 207 Multi-Status when this array is non-empty.
|
|
198
|
+
*/
|
|
199
|
+
interface ImportShardFailure {
|
|
200
|
+
message: string;
|
|
201
|
+
shardKey: string;
|
|
202
|
+
timedOut: boolean;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* How an import treats the rows a target already holds:
|
|
206
|
+
*
|
|
207
|
+
* - `append` — insert; a row whose `_id` exists is a conflict left unchanged.
|
|
208
|
+
* - `upsert` — insert; a row whose `_id` exists is overwritten.
|
|
209
|
+
* - `replace` — `upsert`, then delete every stored row of the file's tables whose
|
|
210
|
+
* `_id` the file lacks, so each table ends up holding exactly the file's rows.
|
|
211
|
+
* Tables the file does not name are never touched.
|
|
212
|
+
* - `require-empty` — refuse unless the file's tables hold no rows at all.
|
|
213
|
+
*/
|
|
214
|
+
type ImportMode = "append" | "replace" | "require-empty" | "upsert";
|
|
215
|
+
interface TablePlan {
|
|
216
|
+
/** File rows whose `_id` the target does not hold (or that carry none). */
|
|
217
|
+
add: number;
|
|
218
|
+
/** Stored rows the file lacks, which `replace` deletes. Zero for every other mode. */
|
|
219
|
+
delete: number;
|
|
220
|
+
/** File rows whose `_id` the target already holds: conflicts under `append`, overwritten under `upsert`/`replace`. */
|
|
221
|
+
existing: number;
|
|
222
|
+
/** Stored rows an `_id` of the file matches, which an overwrite changes. Repeats within the file are in `existing`, not here. */
|
|
223
|
+
matched: number;
|
|
224
|
+
source: number;
|
|
225
|
+
table: string;
|
|
226
|
+
/** Rows the target holds in this table now. */
|
|
227
|
+
target: number;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The sources `--from` accepts.
|
|
231
|
+
*
|
|
232
|
+
* Only the two that cannot be detected. A Convex snapshot announces itself (a
|
|
233
|
+
* directory of `<table>/documents.jsonl`, or a `.zip` of one) and anything else
|
|
234
|
+
* is NDJSON, so naming those would advertise a control this does not implement:
|
|
235
|
+
* `--from ndjson` against a Convex export would have to either refuse it or
|
|
236
|
+
* silently import it as Convex, and the second is what an unhonoured flag
|
|
237
|
+
* actually did.
|
|
238
|
+
*/
|
|
239
|
+
declare const IMPORT_SOURCE_NAMES: readonly ["firebase", "supabase"];
|
|
240
|
+
type ImportSourceName = (typeof IMPORT_SOURCE_NAMES)[number];
|
|
241
|
+
/**
|
|
242
|
+
* The storage-reference rewrite: turning a Convex storage id into the
|
|
243
|
+
* content-hash R2 key its blob was migrated to.
|
|
244
|
+
*
|
|
245
|
+
* Split out of `./storage-mapping` (which owns the mapping *file*) because it
|
|
246
|
+
* has two callers that must never diverge — the import rewrite and `--scan`,
|
|
247
|
+
* which runs this same walk as a dry run to propose the mapping. A detector
|
|
248
|
+
* that proposed columns the rewrite would not touch, or missed ones it would,
|
|
249
|
+
* is worse than no detector.
|
|
250
|
+
*/
|
|
251
|
+
/** One reference the walk could not rewrite, with where it was found. */
|
|
252
|
+
interface UnresolvedStorageReference {
|
|
253
|
+
column: string;
|
|
254
|
+
storageId: string;
|
|
255
|
+
table: string;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* What a run's storage references resolved to. The two failure buckets are
|
|
259
|
+
* deliberately separate, because they are not the same problem and do not have
|
|
260
|
+
* the same remedy:
|
|
261
|
+
*
|
|
262
|
+
* `unmigrated` is a reference to a blob that does not exist — the export omitted
|
|
263
|
+
* it, or `--include-file-storage` was not passed. Nothing the operator writes in
|
|
264
|
+
* a mapping file can fix it, and the data is broken after import, so it fails
|
|
265
|
+
* `--verify`.
|
|
266
|
+
*
|
|
267
|
+
* `ambiguous` is a string that exactly matches a blob that *did* migrate, sitting
|
|
268
|
+
* in a column the mapping does not name. It may be a storage reference the
|
|
269
|
+
* mapping forgot, or it may be user text that happens to equal an id. Failing the
|
|
270
|
+
* run on a coincidence is not defensible, so it warns and names the column the
|
|
271
|
+
* operator would add to resolve it.
|
|
272
|
+
*/
|
|
273
|
+
interface StorageRemapReport {
|
|
274
|
+
ambiguous: UnresolvedStorageReference[];
|
|
275
|
+
/** Number of references rewritten to a content-hash key. */
|
|
276
|
+
rewritten: number;
|
|
277
|
+
unmigrated: UnresolvedStorageReference[];
|
|
278
|
+
}
|
|
279
|
+
/** Rows per HTTP request when importing. Convex uses ~500; same here. */
|
|
280
|
+
declare const DEFAULT_IMPORT_BATCH_SIZE = 500;
|
|
140
281
|
interface ImportCommandOptions {
|
|
141
282
|
/** Rows per HTTP request. Defaults to {@link DEFAULT_IMPORT_BATCH_SIZE}. */
|
|
142
283
|
batchSize?: number;
|
|
284
|
+
/** Ask before overwriting or deleting stored rows. Defaults to the TUI prompt on a TTY. Returns `true` on confirmation. */
|
|
285
|
+
confirm?: (prompt: string) => Promise<boolean>;
|
|
143
286
|
cwd?: string;
|
|
287
|
+
/** Check the file and print the plan against the target's rows; write nothing. */
|
|
288
|
+
dryRun?: boolean;
|
|
144
289
|
fetchImpl?: StreamingFetchLike;
|
|
145
290
|
/** Source NDJSON file. Required. */
|
|
146
291
|
file: string;
|
|
292
|
+
/** Output format: `pretty` (default) or `json`. */
|
|
293
|
+
format?: OutputFormat;
|
|
294
|
+
/**
|
|
295
|
+
* Which reader to use. Omit to auto-detect between a Convex export snapshot
|
|
296
|
+
* and a plain NDJSON file; `supabase`/`firebase` must be explicit, because a
|
|
297
|
+
* directory of CSV or JSON has no signature that distinguishes it from
|
|
298
|
+
* anything else a user might point at.
|
|
299
|
+
*/
|
|
300
|
+
from?: ImportSourceName;
|
|
147
301
|
logger: Logger;
|
|
302
|
+
/** How the rows the target already holds are treated. Defaults to `append`; see {@link ImportMode}. */
|
|
303
|
+
mode?: ImportMode;
|
|
148
304
|
prod?: boolean;
|
|
149
305
|
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
306
|
+
* Scan the export for columns holding `_storage` ids and write a candidate
|
|
307
|
+
* `lunora/import-convex.json`. Scan-only: nothing is imported.
|
|
308
|
+
*/
|
|
309
|
+
scan?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Local directory of storage objects to migrate alongside the rows — how
|
|
312
|
+
* Firebase Cloud Storage arrives, after `gcloud storage cp -r`.
|
|
313
|
+
*/
|
|
314
|
+
storageDir?: string;
|
|
315
|
+
/**
|
|
316
|
+
* Wrap each line as `{table:<name>,doc:<line>}`. Use when the source NDJSON
|
|
317
|
+
* is bare docs from a single table — Convex's `convex import --table users`
|
|
318
|
+
* shape.
|
|
319
|
+
*/
|
|
154
320
|
table?: string;
|
|
155
321
|
token?: string;
|
|
156
322
|
url?: string;
|
|
323
|
+
/**
|
|
324
|
+
* Verify per-table row parity + dangling-storage after import. Exits non-zero
|
|
325
|
+
* when a table's inserted count differs from its source line count, or when a
|
|
326
|
+
* document references a storage id that was not migrated.
|
|
327
|
+
*/
|
|
328
|
+
verify?: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Also migrate Convex `_storage` blobs: read `_storage/documents.jsonl`, upload
|
|
331
|
+
* each blob with sha256+size verification, and build the `storageId → key` map.
|
|
332
|
+
* Off by default so the plain-document import path is unchanged.
|
|
333
|
+
*/
|
|
334
|
+
withStorage?: boolean;
|
|
335
|
+
/** Confirm bulk-writing production. Required alongside `--prod`. */
|
|
336
|
+
yes?: boolean;
|
|
157
337
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
338
|
+
/**
|
|
339
|
+
* The JSON summary a run prints and returns — the same object either way, so a
|
|
340
|
+
* caller reading `body.conflicts` does not have to cast its way there.
|
|
341
|
+
*
|
|
342
|
+
* `undefined` on every path that imports nothing: a rejected source, a failed
|
|
343
|
+
* storage phase, or `--scan` (whose product is the mapping file it writes, not
|
|
344
|
+
* a return value).
|
|
345
|
+
*/
|
|
346
|
+
interface ImportSummary {
|
|
347
|
+
conflicts: number;
|
|
348
|
+
/** Stored rows `--mode replace` deleted because the file lacks them. */
|
|
349
|
+
deleted: number;
|
|
350
|
+
errors: ImportRowError[];
|
|
351
|
+
/** Shards the endpoint could not reach (it answered 207). Their rows are MISSING, not rejected — present only when non-empty. */
|
|
352
|
+
failed?: ImportShardFailure[];
|
|
353
|
+
inserted: Record<string, number>;
|
|
354
|
+
/** What the run planned against the target's rows, per table. Present for every mode but `append` and for `--dry-run`. */
|
|
355
|
+
plan?: TablePlan[];
|
|
356
|
+
received: number;
|
|
357
|
+
/** Existing rows overwritten under `--mode upsert` / `--mode replace`. */
|
|
358
|
+
replaced: number;
|
|
359
|
+
storage?: {
|
|
360
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `ambiguousTotal`. */
|
|
361
|
+
ambiguous: StorageRemapReport["ambiguous"];
|
|
362
|
+
/** How many DISTINCT `(table, column, storageId)` references were ambiguous. */
|
|
363
|
+
ambiguousTotal: number;
|
|
364
|
+
blobs: number;
|
|
365
|
+
rewritten: number;
|
|
366
|
+
/** Up to {@link UNRESOLVED_REPORT_LIMIT} distinct references — a sample, not the whole set. See `unmigratedTotal`. */
|
|
367
|
+
unmigrated: StorageRemapReport["unmigrated"];
|
|
368
|
+
/** How many DISTINCT `(table, column, storageId)` references resolved to no migrated blob. */
|
|
369
|
+
unmigratedTotal: number;
|
|
370
|
+
};
|
|
371
|
+
warnings?: string[];
|
|
372
|
+
}
|
|
373
|
+
/** The `--format json` payload: which file went in, and what the endpoint made of it. */
|
|
374
|
+
interface ImportCommandData {
|
|
375
|
+
file: string;
|
|
376
|
+
inserted: number;
|
|
377
|
+
/** The batcher's own roll-up: inserted-per-table, conflicts, row errors, unreached shards. */
|
|
378
|
+
summary: ImportSummary;
|
|
379
|
+
}
|
|
380
|
+
interface ImportCommandResult extends CommandResult<ImportCommandData> {
|
|
381
|
+
body: ImportSummary | undefined;
|
|
161
382
|
/** Total inserted rows across batches. */
|
|
162
383
|
inserted: number;
|
|
384
|
+
/** Existing rows overwritten under `--mode upsert` / `--mode replace`; absent when the run wrote nothing. */
|
|
385
|
+
replaced?: number;
|
|
163
386
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Stream an NDJSON file in chunks, POSTing each batch to
|
|
166
|
-
* `/_lunora/admin/import`. We keep the line buffer bounded by `batchSize` so a
|
|
167
|
-
* multi-GiB file imports without buffering everything in memory.
|
|
168
|
-
*/
|
|
169
387
|
declare const runImportCommand: (options: ImportCommandOptions) => Promise<ImportCommandResult>;
|
|
170
388
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*/
|
|
389
|
+
* Every exit code `lunora` can terminate with. Stable — a value never changes
|
|
390
|
+
* meaning, and a new bucket takes the next free number.
|
|
391
|
+
*/
|
|
392
|
+
declare const EXIT_CODE: {
|
|
393
|
+
/** The command did what was asked. */
|
|
394
|
+
readonly SUCCESS: 0;
|
|
395
|
+
/** A failure that fits none of the narrower buckets. */
|
|
396
|
+
readonly FAILURE: 1;
|
|
397
|
+
/** Bad usage, bad input, or a validation failure — the invocation itself, or the project source it read, is wrong. */
|
|
398
|
+
readonly USAGE: 2;
|
|
399
|
+
/** Not authenticated: no credential, or an expired one. */
|
|
400
|
+
readonly AUTH: 3;
|
|
401
|
+
/** Authenticated, but not allowed to do this. */
|
|
402
|
+
readonly PERMISSION: 4;
|
|
403
|
+
/** The named thing does not exist. */
|
|
404
|
+
readonly NOT_FOUND: 5;
|
|
405
|
+
/** The write lost a race, or the name is already taken. */
|
|
406
|
+
readonly CONFLICT: 6;
|
|
407
|
+
/** Rate limited — back off and retry. */
|
|
408
|
+
readonly RATE_LIMITED: 7;
|
|
409
|
+
/** The far side is unavailable or timed out. Retryable. */
|
|
410
|
+
readonly UNAVAILABLE: 8;
|
|
411
|
+
/** A local tool the command shells out to (wrangler, git, docker, …) is missing, or not running. */
|
|
412
|
+
readonly MISSING_DEPENDENCY: 9;
|
|
413
|
+
/** Interactive cancel — the POSIX `128 + SIGINT` convention. */
|
|
414
|
+
readonly CANCELLED: 130;
|
|
415
|
+
};
|
|
416
|
+
/** One of {@link EXIT_CODE}'s values. */
|
|
417
|
+
type ExitCode = (typeof EXIT_CODE)[keyof typeof EXIT_CODE];
|
|
418
|
+
/** The exit code for a transport status; `undefined` and anything unmapped are a general failure. */
|
|
419
|
+
declare const exitCodeForStatus: (status: number | undefined) => ExitCode;
|
|
420
|
+
/**
|
|
421
|
+
* The exit code for a Lunora error `code`, resolved through the catalog. An
|
|
422
|
+
* unregistered code has no status to derive from, so it is a general failure.
|
|
423
|
+
*/
|
|
424
|
+
declare const exitCodeForCode: (code: string) => ExitCode;
|
|
425
|
+
/**
|
|
426
|
+
* The exit code for a thrown value. A Lunora error is classified by its `code`
|
|
427
|
+
* (override table first) and then by the `status` the instance carries — which
|
|
428
|
+
* is the catalog's, unless the throw site passed a more specific one (the
|
|
429
|
+
* upstream-API codes do). Anything else is a general failure.
|
|
430
|
+
*/
|
|
431
|
+
declare const exitCodeForError: (error: unknown) => ExitCode;
|
|
432
|
+
/**
|
|
433
|
+
* Injectable probe for a Docker-compatible container engine. Tests pass a
|
|
434
|
+
* stub; production uses {@link isDockerAvailable}.
|
|
435
|
+
*/
|
|
174
436
|
type DockerProbe = () => boolean;
|
|
175
437
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
|
|
438
|
+
* The shared `/_lunora/health` probe used by `lunora verify --health-url` and
|
|
439
|
+
* `lunora deploy --health-check`.
|
|
440
|
+
*
|
|
441
|
+
* Both commands ask the same question — "does this deployment answer?" — so
|
|
442
|
+
* they ask it through one implementation with one error-message shape. The
|
|
443
|
+
* runtime auto-registers both routes (`packages/runtime/src/health-routes.ts`):
|
|
444
|
+
* `/_lunora/health/ready` is the readiness gate ("can this version serve"), and
|
|
445
|
+
* `/_lunora/health` is the aggregate that also exists on older deployments.
|
|
446
|
+
*
|
|
447
|
+
* The probe is transport-only: it never throws, and reports its verdict as an
|
|
448
|
+
* `{ error }` message the caller decides what to do with.
|
|
449
|
+
*/
|
|
450
|
+
/**
|
|
451
|
+
* The fetch surface the probe needs — a subset of the global `fetch`,
|
|
452
|
+
* injectable so a test can feed a canned response without a network. The
|
|
453
|
+
* response's `headers` are read for a redirect's `location`.
|
|
454
|
+
*/
|
|
455
|
+
type HealthFetch = (url: string, init: {
|
|
456
|
+
headers: Record<string, string>;
|
|
457
|
+
redirect: RequestRedirect;
|
|
458
|
+
}) => Promise<{
|
|
459
|
+
headers: {
|
|
460
|
+
get: (name: string) => string | null;
|
|
461
|
+
};
|
|
462
|
+
ok: boolean;
|
|
463
|
+
status: number;
|
|
464
|
+
}>;
|
|
181
465
|
interface SpawnDescriptor {
|
|
182
466
|
args: ReadonlyArray<string>;
|
|
183
467
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
468
|
+
* Capture the child's stderr (in addition to streaming it to the parent).
|
|
469
|
+
* Needed when a tool reports the *expected* outcome as an error there —
|
|
470
|
+
* `wrangler vectorize create-metadata-index` writes "already exists" to
|
|
471
|
+
* stderr, and without this the caller can only see a bare exit code and
|
|
472
|
+
* would warn on every re-run. Composes with `stdoutToStderr`, so a caller
|
|
473
|
+
* can keep stdout clean for `--format json` and still read the reason.
|
|
474
|
+
*/
|
|
475
|
+
captureStderr?: boolean;
|
|
476
|
+
/**
|
|
477
|
+
* Capture the child's stderr without teeing it to the parent. For a caller that reports its own outcome and must not
|
|
478
|
+
* print the tool's errors when the outcome is a skip.
|
|
479
|
+
*/
|
|
480
|
+
captureStderrSilently?: boolean;
|
|
481
|
+
/**
|
|
482
|
+
* Capture the child's stdout (in addition to streaming it to the parent), so
|
|
483
|
+
* the caller can parse it — used by `deploy` to read the deployed URL from
|
|
484
|
+
* `wrangler deploy` output. Each chunk is still teed to the parent's stdout
|
|
485
|
+
* so the user sees live progress. Mutually exclusive with `stdoutToStderr`
|
|
486
|
+
* and `captureStdoutSilently`.
|
|
487
|
+
*/
|
|
189
488
|
captureStdout?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Capture the child's stdout WITHOUT teeing it to the parent's stdout —
|
|
491
|
+
* for output that is parsed, never displayed (e.g. `wrangler secret list
|
|
492
|
+
* --format json`). Unlike `captureStdout`, nothing is written to
|
|
493
|
+
* `process.stdout`, so it can't interleave with — and corrupt — a
|
|
494
|
+
* caller's own stdout (notably `lunora deploy --format json`, which must
|
|
495
|
+
* emit exactly one JSON document). Mutually exclusive with `captureStdout`
|
|
496
|
+
* and `stdoutToStderr`.
|
|
497
|
+
*/
|
|
498
|
+
captureStdoutSilently?: boolean;
|
|
190
499
|
command: string;
|
|
191
500
|
cwd?: string;
|
|
192
501
|
env?: Readonly<Record<string, string>>;
|
|
193
502
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
503
|
+
* Pipe this string into the child's stdin and close it. Used to feed
|
|
504
|
+
* `wrangler secret put` its value without exposing it on the command
|
|
505
|
+
* line or in env. When absent, stdin is inherited from the parent.
|
|
506
|
+
*/
|
|
198
507
|
input?: string;
|
|
199
508
|
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
509
|
+
* Route the child's stdout to the parent's STDERR instead of stdout. Set in
|
|
510
|
+
* `--format json` mode so a spawned tool's human output (e.g. `wrangler
|
|
511
|
+
* deploy`'s progress + the deployed URL) can't interleave with — and corrupt
|
|
512
|
+
* — the single JSON document the command prints to stdout.
|
|
513
|
+
*/
|
|
205
514
|
stdoutToStderr?: boolean;
|
|
515
|
+
/**
|
|
516
|
+
* Kill the child (SIGKILL) and count the run as failed after this many milliseconds. Without it a stalled
|
|
517
|
+
* child keeps the caller waiting with no way to stop it.
|
|
518
|
+
*/
|
|
519
|
+
timeoutMs?: number;
|
|
206
520
|
}
|
|
207
521
|
interface SpawnResult {
|
|
208
522
|
code: number;
|
|
209
|
-
/** The captured
|
|
523
|
+
/** The captured stderr, present only when the descriptor set `captureStderr`. */
|
|
524
|
+
stderr?: string;
|
|
525
|
+
/** The captured stdout, present only when the descriptor set `captureStdout` or `captureStdoutSilently`. */
|
|
210
526
|
stdout?: string;
|
|
211
527
|
}
|
|
212
528
|
/**
|
|
213
|
-
* Injectable spawner. Tests pass a stub that just records the descriptor
|
|
214
|
-
* instead of executing a real subprocess.
|
|
215
|
-
*/
|
|
529
|
+
* Injectable spawner. Tests pass a stub that just records the descriptor
|
|
530
|
+
* instead of executing a real subprocess.
|
|
531
|
+
*/
|
|
216
532
|
type Spawner = (descriptor: SpawnDescriptor) => Promise<SpawnResult>;
|
|
217
533
|
declare const defaultSpawner: Spawner;
|
|
218
534
|
interface RecordedSpawn {
|
|
219
535
|
descriptor: SpawnDescriptor;
|
|
220
536
|
}
|
|
221
537
|
/**
|
|
222
|
-
* Test helper: returns a spawner that records every invocation and resolves
|
|
223
|
-
* with the configured exit code.
|
|
224
|
-
*/
|
|
538
|
+
* Test helper: returns a spawner that records every invocation and resolves
|
|
539
|
+
* with the configured exit code.
|
|
540
|
+
*/
|
|
225
541
|
declare const createRecordingSpawner: (exitCode?: number) => {
|
|
226
542
|
calls: RecordedSpawn[];
|
|
227
543
|
spawner: Spawner;
|
|
@@ -239,6 +555,8 @@ interface ListRemoteSecretsInputs {
|
|
|
239
555
|
env?: string;
|
|
240
556
|
/** Injected command runner; defaults to a real `wrangler secret list`. */
|
|
241
557
|
runner?: SecretListRunner;
|
|
558
|
+
/** The deploy target the caller resolved (`--target`, else the config's). Defaults to the config's. */
|
|
559
|
+
target?: string;
|
|
242
560
|
/** Target a temporary-account deployment (`--temporary`). */
|
|
243
561
|
temporary?: boolean;
|
|
244
562
|
}
|
|
@@ -250,100 +568,134 @@ interface ListRemoteSecretsResult {
|
|
|
250
568
|
/** False when wrangler failed or its output could not be parsed. */
|
|
251
569
|
ok: boolean;
|
|
252
570
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Parse `wrangler secret list --format json` output into a sorted name list.
|
|
255
|
-
* The payload is an array of `{ name, type }`; anything else yields `undefined`
|
|
256
|
-
* so the caller can report a parse failure rather than silently returning [].
|
|
257
|
-
*/
|
|
258
|
-
type FetchLike = (input: string, init?: {
|
|
259
|
-
body?: string;
|
|
260
|
-
headers?: Record<string, string>;
|
|
261
|
-
method?: string;
|
|
262
|
-
}) => Promise<{
|
|
263
|
-
json: () => Promise<unknown>;
|
|
264
|
-
ok: boolean;
|
|
265
|
-
status: number;
|
|
266
|
-
text: () => Promise<string>;
|
|
267
|
-
}>;
|
|
268
|
-
interface RunCommandOptions {
|
|
269
|
-
args?: string;
|
|
270
|
-
cwd?: string;
|
|
271
|
-
fetchImpl?: FetchLike;
|
|
272
|
-
functionPath: string;
|
|
273
|
-
logger: Logger;
|
|
274
|
-
shard?: string;
|
|
275
|
-
url?: string;
|
|
276
|
-
}
|
|
277
|
-
interface RunCommandResult {
|
|
278
|
-
body: unknown;
|
|
279
|
-
code: number;
|
|
280
|
-
requestUrl: string;
|
|
281
|
-
}
|
|
282
|
-
declare const runRpcCommand: (options: RunCommandOptions) => Promise<RunCommandResult>;
|
|
283
|
-
/** `lunora run <functionPath>` handler (lazy-loaded via the command's `loader`). */
|
|
284
571
|
interface DeployCommandOptions {
|
|
572
|
+
/** Deploy even though the app enables the open-shard option (the `open_shard_access` gate). */
|
|
573
|
+
allowOpenShards?: boolean;
|
|
285
574
|
/** Override the schema-drift gate — deploy even with breaking drift and no new migration. */
|
|
286
575
|
allowSchemaDrift?: boolean;
|
|
287
576
|
/** Which API spec(s) codegen emits. Defaults to codegen's `"openapi"` when omitted. */
|
|
288
577
|
apiSpec?: ApiSpec;
|
|
578
|
+
/** The Vite metafile path this run's client build keeps for `lunora build`'s copy; unset, the build's metafile is discarded. */
|
|
579
|
+
bundleMetaPath?: string;
|
|
580
|
+
/** The celld toolchain check a celld deploy runs before codegen; injected in tests. Defaults to `probeCelldToolchain`. */
|
|
581
|
+
celldToolchain?: (options: CelldToolchainProbeOptions) => Promise<CelldToolchainProbe>;
|
|
582
|
+
/**
|
|
583
|
+
* The `--env` this run's client build was given as `CLOUDFLARE_ENV`. Set only when a client build ran, so the generated config
|
|
584
|
+
* it wrote is for that environment; without it the environment's Hyperdrive id is not written into that config.
|
|
585
|
+
*/
|
|
586
|
+
clientBuildEnvironment?: string;
|
|
587
|
+
/**
|
|
588
|
+
* Set when the caller's stdout must stay a single JSON document but `format` is
|
|
589
|
+
* not `"json"`. `lunora build` sets it, since it hands deploy `format: undefined`.
|
|
590
|
+
*/
|
|
591
|
+
clientBuildOutputJson?: boolean;
|
|
592
|
+
/** Set when this run's client build ran, so the spec it recorded is the one to emit. */
|
|
593
|
+
clientBuildRan?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* The command the operator actually ran. `build` delegates here with
|
|
596
|
+
* `dryRun: true`; without this the gate names the wrong command in its
|
|
597
|
+
* blocked message and offers flags the real caller does not accept.
|
|
598
|
+
*/
|
|
599
|
+
commandName?: PreDeployCommand;
|
|
289
600
|
cwd?: string;
|
|
290
601
|
/** Docker-availability probe injected in tests. Defaults to a real `docker info` check. */
|
|
602
|
+
/** Memoises project discovery for this invocation; `executeDeploy` creates one, and codegen clears it. */
|
|
603
|
+
discoveryCache?: DiscoveryCache;
|
|
291
604
|
dockerAvailable?: DockerProbe;
|
|
292
605
|
/**
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
606
|
+
* Validate, bundle, and run all pre-deploy gates without publishing
|
|
607
|
+
* (`wrangler deploy --dry-run`). Post-deploy steps (data migrations, schema
|
|
608
|
+
* baseline re-bless) are skipped since nothing shipped.
|
|
609
|
+
*/
|
|
297
610
|
dryRun?: boolean;
|
|
611
|
+
/**
|
|
612
|
+
* Write the binding manifest (`build --emit-bindings`) to this path once the
|
|
613
|
+
* bundle exists. Owned here rather than by the caller because it is the last
|
|
614
|
+
* artifact that has to read the PROVISIONED `wrangler.jsonc`, and the dry-run
|
|
615
|
+
* rollback below closes that window as soon as this function returns.
|
|
616
|
+
* Relative paths resolve against the project root.
|
|
617
|
+
*/
|
|
618
|
+
emitBindings?: string;
|
|
298
619
|
env?: string;
|
|
299
|
-
/** Fetch implementation injected in tests for `--migrate` RPC calls. */
|
|
300
|
-
fetchImpl?:
|
|
620
|
+
/** Fetch implementation injected in tests for `--migrate` RPC calls and the drift gate's stored-row read. */
|
|
621
|
+
fetchImpl?: StreamingFetchLike;
|
|
301
622
|
/** Output format: `pretty` (default) or `json`. */
|
|
302
|
-
format?:
|
|
623
|
+
format?: OutputFormat;
|
|
624
|
+
/**
|
|
625
|
+
* `false` (`--no-framework-build`) skips the vite/rsbuild client build that
|
|
626
|
+
* runs before wrangler when wrangler reads its output. `--prebuilt` skips it
|
|
627
|
+
* too: that artifact was built earlier.
|
|
628
|
+
*/
|
|
629
|
+
frameworkBuild?: boolean;
|
|
630
|
+
/**
|
|
631
|
+
* After a successful live deploy, probe the new version's health route
|
|
632
|
+
* (`/_lunora/health/ready`, falling back to `/_lunora/health`) and fail the
|
|
633
|
+
* command when it never answers. Opt-in, not default-on: a worker whose
|
|
634
|
+
* health route is admin-gated or unreachable from CI must still be
|
|
635
|
+
* deployable, and a default network step would turn a successful deploy
|
|
636
|
+
* into a red build for an unrelated reason.
|
|
637
|
+
*/
|
|
638
|
+
healthCheck?: boolean;
|
|
639
|
+
/** Injectable fetch for `--health-check`; defaults to the global `fetch`. */
|
|
640
|
+
healthFetch?: HealthFetch;
|
|
641
|
+
/** Injectable inter-attempt delay for `--health-check`; injected in tests to skip the real wait. */
|
|
642
|
+
healthSleep?: (ms: number) => Promise<void>;
|
|
303
643
|
/** Set to `false` to disable interactive spinners (test injection). */
|
|
304
644
|
interactive?: boolean;
|
|
645
|
+
/**
|
|
646
|
+
* Set by `lunora preview deploy`: this run ships an isolated preview copy under its own `--env`. It leaves
|
|
647
|
+
* production's records alone (the project link, the schema baseline, the architecture baseline) and skips the
|
|
648
|
+
* missing-secret gate, because the preview passes its own secrets in {@link DeployCommandOptions.secretsFile}.
|
|
649
|
+
*/
|
|
650
|
+
isolatedPreview?: boolean;
|
|
651
|
+
/** Opt into per-module lazy function imports. */
|
|
652
|
+
lazyFunctions?: boolean;
|
|
305
653
|
logger: Logger;
|
|
306
654
|
/**
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
655
|
+
* When true, after a successful `wrangler deploy`, discover and run all
|
|
656
|
+
* pending data migrations via the worker's `/_lunora/migrate` admin RPC.
|
|
657
|
+
* The worker must be live (exit 0) before migrations are attempted.
|
|
658
|
+
*
|
|
659
|
+
* Implementation note: the status RPC returns the full shard-level
|
|
660
|
+
* migration state, but there is no single authoritative "list of pending
|
|
661
|
+
* migration ids" that can be read client-side before running the worker.
|
|
662
|
+
* Instead, `--migrate` runs `migrate status` followed by `migrate up` for
|
|
663
|
+
* each migration id discovered locally via `discoverMigrations`. The
|
|
664
|
+
* worker's `MigrationRunner` is idempotent — running `up` on an already-
|
|
665
|
+
* applied migration is a no-op — so this approach is safe.
|
|
666
|
+
*/
|
|
319
667
|
migrate?: boolean;
|
|
668
|
+
/**
|
|
669
|
+
* Confirm a committed SQL file that drops, renames, truncates or replaces data. Separate from `migrateYes`, so a
|
|
670
|
+
* production confirmation never confirms a DROP by itself.
|
|
671
|
+
*/
|
|
672
|
+
migrateAllowDestructive?: boolean;
|
|
320
673
|
/** Admin bearer token for `--migrate` (falls back to `LUNORA_ADMIN_TOKEN`). */
|
|
321
674
|
migrateToken?: string;
|
|
322
675
|
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
676
|
+
* Worker URL for `--migrate`. REQUIRED when `--migrate` is set — the deploy
|
|
677
|
+
* handler never captures the URL `wrangler deploy` published to, so there is
|
|
678
|
+
* no safe default; omitting it would silently target `http://localhost:8787`
|
|
679
|
+
* (the dev worker), applying the migration to local state instead of prod.
|
|
680
|
+
*/
|
|
328
681
|
migrateUrl?: string;
|
|
329
682
|
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
683
|
+
* Confirm a production data migration triggered via `--migrate` (the
|
|
684
|
+
* `migrate up --prod` confirmation the standalone command requires). Without
|
|
685
|
+
* it a `--migrate --migrate-url <prod>` deploy refuses to run the migration.
|
|
686
|
+
*/
|
|
334
687
|
migrateYes?: boolean;
|
|
688
|
+
/** Set once the open-shard gate has run for this deploy, so the pipeline does not run it again. */
|
|
689
|
+
openShardGatePassed?: boolean;
|
|
335
690
|
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
691
|
+
* Emit the bundled worker to this directory via `wrangler deploy --outdir`
|
|
692
|
+
* (paired with `dryRun` by `lunora build`). Also writes esbuild metadata to
|
|
693
|
+
* `<outDir>/bundle-meta.json`. When unset, no artifact is written.
|
|
694
|
+
*/
|
|
340
695
|
outDir?: string;
|
|
341
|
-
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
* the post-deploy finalize (migrations, baseline re-bless, auto-link, the
|
|
345
|
-
* production summary) is skipped — a preview never shifts live traffic.
|
|
346
|
-
*/
|
|
696
|
+
/** Also write the upload form (`wrangler deploy --outfile`) here; `lunora build` profiles its startup. */
|
|
697
|
+
outFile?: string;
|
|
698
|
+
/** Refused on every target (see `PREVIEW_REFUSAL` in the handler); kept as an option so the refusal can say why. */
|
|
347
699
|
preview?: boolean;
|
|
348
700
|
/** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
|
|
349
701
|
railpackAvailable?: DockerProbe;
|
|
@@ -351,25 +703,106 @@ interface DeployCommandOptions {
|
|
|
351
703
|
secretConfirm?: (message: string) => Promise<boolean>;
|
|
352
704
|
/** Remote-secret lister for the missing-secret offer; injected in tests. Defaults to `wrangler secret list`. */
|
|
353
705
|
secretLister?: (inputs: ListRemoteSecretsInputs) => Promise<ListRemoteSecretsResult>;
|
|
706
|
+
/** A JSON file of secrets uploaded with the deployment (`wrangler deploy --secrets-file`). */
|
|
707
|
+
secretsFile?: string;
|
|
354
708
|
skipCodegen?: boolean;
|
|
709
|
+
/** Deploy only the app, leaving the `lunora.config` services it binds as they are (`--skip-services`). */
|
|
710
|
+
skipServices?: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Starts the smoke check's `wrangler dev`. Unset, the check launches a real server; a caller that must
|
|
713
|
+
* not start one (a test, or an embedding that stubs subprocesses) passes its own launcher.
|
|
714
|
+
*/
|
|
715
|
+
smokeLauncher?: DevProcessSpawner;
|
|
716
|
+
/**
|
|
717
|
+
* Evaluate every module the Worker loads on demand in workerd before shipping (lazy function
|
|
718
|
+
* modules, and in any build the auth module and spec documents the generated app loads with
|
|
719
|
+
* `import()`), so a module that throws on load fails the deploy instead of its first request.
|
|
720
|
+
* Nothing to check when there is none; `false` (`--no-smoke-load`) skips it. Default on.
|
|
721
|
+
*/
|
|
722
|
+
smokeLoad?: boolean;
|
|
355
723
|
spawner?: Spawner;
|
|
356
724
|
/**
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
725
|
+
* Fail the deploy when codegen reports an ERROR-level advisory. Same
|
|
726
|
+
* option `lunora codegen` exposes as `--no-strict-advisories`; defaults to
|
|
727
|
+
* CI detection (on in CI, off locally) so a legitimately-partial target
|
|
728
|
+
* can still be shipped interactively. Does NOT gate platform diagnostics
|
|
729
|
+
* (`platform_unsupported_feature` / `platform_unknown_target`), which
|
|
730
|
+
* always block — those mean the emitted `ctx.*` surface does not match
|
|
731
|
+
* what the target can serve, not merely a style nit.
|
|
732
|
+
*/
|
|
733
|
+
strictAdvisories?: boolean;
|
|
734
|
+
/**
|
|
735
|
+
* Deploy target. Falls back to `"target"` in `lunora.config.*`, then
|
|
736
|
+
* `"cloudflare"`, which selects the wrangler
|
|
737
|
+
* toolchain — i.e. today's behavior for every project. An unregistered name
|
|
738
|
+
* throws rather than falling back, so a typo can never ship the app to the
|
|
739
|
+
* wrong provider.
|
|
740
|
+
*/
|
|
741
|
+
target?: string;
|
|
742
|
+
/**
|
|
743
|
+
* Deploy to a temporary Cloudflare account (`wrangler deploy --temporary`).
|
|
744
|
+
* For unauthenticated use only: wrangler provisions a short-lived account +
|
|
745
|
+
* token, deploys, and prints a claim URL; the deployment stays live ~60
|
|
746
|
+
* minutes before the unclaimed account is deleted. Wrangler itself errors
|
|
747
|
+
* if credentials are already present (OAuth / `CLOUDFLARE_API_TOKEN` /
|
|
748
|
+
* global API key), so we pass the flag straight through without guarding.
|
|
749
|
+
*/
|
|
364
750
|
temporary?: boolean;
|
|
365
|
-
|
|
366
|
-
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* What this run put where — the identity of the thing that was just deployed.
|
|
754
|
+
*
|
|
755
|
+
* Present on every run that reached (and completed) the wrangler invocation,
|
|
756
|
+
* including `--dry-run`, so a consumer can tell "nothing went
|
|
757
|
+
* live" from "went live" without inferring it from a missing `url`. A dry run
|
|
758
|
+
* publishes nothing and therefore never carries a `url`.
|
|
759
|
+
*
|
|
760
|
+
* No `versionId`: the pinned wrangler (see the `wrangler` catalog entry in
|
|
761
|
+
* `pnpm-workspace.yaml`) has no structured deploy output
|
|
762
|
+
* and no flag that returns the version id — it only prints it in prose, and
|
|
763
|
+
* scraping a second value out of prose is exactly what this shouldn't do. The
|
|
764
|
+
* id is available from `lunora cloudflare deployments list` after the fact.
|
|
765
|
+
*/
|
|
766
|
+
interface DeployedIdentity {
|
|
767
|
+
/** ISO-8601 stamp taken when the wrangler invocation returned. */
|
|
768
|
+
deployedAt: string;
|
|
769
|
+
/** True when `--dry-run` validated + bundled without publishing. */
|
|
770
|
+
dryRun: boolean;
|
|
771
|
+
/** The Cloudflare environment this run targeted, when `--env` named one. */
|
|
772
|
+
env?: string;
|
|
773
|
+
/** The URL wrangler reported publishing to; absent on a dry run, or when the output carried no URL. */
|
|
774
|
+
url?: string;
|
|
775
|
+
/** The Worker name from the project's wrangler config. */
|
|
776
|
+
workerName?: string;
|
|
367
777
|
}
|
|
368
778
|
interface DeployCommandResult {
|
|
369
779
|
code: number;
|
|
780
|
+
/** What was deployed and where — set once the wrangler invocation completed. */
|
|
781
|
+
deployment?: DeployedIdentity;
|
|
370
782
|
descriptor: SpawnDescriptor | undefined;
|
|
371
783
|
/** Set when the run aborted before reaching the wrangler invocation. */
|
|
372
784
|
error?: string;
|
|
785
|
+
/**
|
|
786
|
+
* The `--health-check` probe's verdict, when the flag was set and the probe
|
|
787
|
+
* ran. A red probe fails the command (`code` is non-zero) — but the deploy
|
|
788
|
+
* itself still succeeded, which is why the reason is reported separately
|
|
789
|
+
* from `error`.
|
|
790
|
+
*/
|
|
791
|
+
healthCheck?: {
|
|
792
|
+
error?: string;
|
|
793
|
+
ok: boolean;
|
|
794
|
+
url: string;
|
|
795
|
+
};
|
|
796
|
+
/** Whether the target a successful deploy shipped to has a log tail for `lunora logs`. */
|
|
797
|
+
logsAvailable?: boolean;
|
|
798
|
+
/**
|
|
799
|
+
* The `.dev.vars`-shaped filename (never a full path, never a value) a
|
|
800
|
+
* secret minted during this run was recorded into, when the missing-
|
|
801
|
+
* secret gate minted one — `.dev.vars` for the default environment, or a
|
|
802
|
+
* `.dev.vars.<env>` sibling for an explicit `--env`. `undefined` when
|
|
803
|
+
* nothing was minted this run.
|
|
804
|
+
*/
|
|
805
|
+
mintedSecretsFile?: string;
|
|
373
806
|
/** The schema-drift gate verdict, when it ran (skipped on `--skip-codegen`). */
|
|
374
807
|
schemaDrift?: {
|
|
375
808
|
blocked: boolean;
|
|
@@ -381,52 +814,115 @@ interface DeployCommandResult {
|
|
|
381
814
|
};
|
|
382
815
|
}
|
|
383
816
|
/**
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
|
|
817
|
+
* The commands that run the pre-deploy pipeline, as the OPERATOR typed them.
|
|
818
|
+
*
|
|
819
|
+
* These checks are reached from `lunora deploy`, `lunora prepare` and
|
|
820
|
+
* `lunora build`, and a blocked run naming a command the operator never ran
|
|
821
|
+
* reads as a bug in the tool rather than a problem in the project.
|
|
822
|
+
*
|
|
823
|
+
* `build` is one of them: it delegates to `runDeployCommand({ dryRun: true })`.
|
|
824
|
+
* The name is threaded through rather than assumed, because the drift gate uses
|
|
825
|
+
* it for two operator-facing decisions — which override flags to offer, and what
|
|
826
|
+
* to call the thing that was blocked. Hardcoding `"deploy"` here meant `lunora
|
|
827
|
+
* build` reported "deploy blocked" for a deploy nobody attempted and recommended
|
|
828
|
+
* a flag `build` rejects with a raw stack trace.
|
|
829
|
+
*/
|
|
830
|
+
type PreDeployCommand = "build" | "deploy" | "prepare";
|
|
831
|
+
/**
|
|
832
|
+
* Run a deploy. In `--format json` mode the human/progress channel is already on
|
|
833
|
+
* stderr (`defineHandler` routed it) and the Vercel-style summary is skipped, so
|
|
834
|
+
* stdout is left to the single result document `execute` returns.
|
|
835
|
+
*/
|
|
388
836
|
declare const runDeployCommand: (options: DeployCommandOptions) => Promise<DeployCommandResult>;
|
|
389
|
-
/** `lunora deploy` handler (lazy-loaded via the command's `loader`). */
|
|
390
837
|
/**
|
|
391
|
-
* Start the codegen watch loop and return a handle to stop it. Regenerates on
|
|
392
|
-
* startup, then on debounced changes under `lunora/` (ignoring writes to the
|
|
393
|
-
* `_generated/` output to avoid a feedback loop). If the platform can't do a
|
|
394
|
-
* recursive watch, it logs once and falls back to startup-only codegen.
|
|
395
|
-
*/
|
|
838
|
+
* Start the codegen watch loop and return a handle to stop it. Regenerates on
|
|
839
|
+
* startup, then on debounced changes under `lunora/` (ignoring writes to the
|
|
840
|
+
* `_generated/` output to avoid a feedback loop). If the platform can't do a
|
|
841
|
+
* recursive watch, it logs once and falls back to startup-only codegen.
|
|
842
|
+
*/
|
|
396
843
|
declare const startCodegenWatch: (options: CodegenWatcherOptions) => CodegenWatcherHandle;
|
|
397
844
|
interface CodegenWatcherOptions {
|
|
398
845
|
/** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
|
|
399
846
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
400
847
|
/** Debounce window for coalescing rapid edits. Defaults to 100ms. */
|
|
401
848
|
debounceMs?: number;
|
|
849
|
+
/**
|
|
850
|
+
* The caller's logs are NDJSON on stdout, so the `postcodegen` hook's own
|
|
851
|
+
* stdout must be routed to stderr or it corrupts the stream. `lunora dev`
|
|
852
|
+
* turns this on for `--json` AND for a detected AI agent.
|
|
853
|
+
*/
|
|
854
|
+
jsonLogs?: boolean;
|
|
855
|
+
/** Opt into per-module lazy function loading; omitted keeps the eager registry. */
|
|
856
|
+
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
402
857
|
logger: Logger;
|
|
403
858
|
/** Override the lunora subdirectory name. Defaults to `"lunora"`. */
|
|
404
859
|
lunoraDirectory?: string;
|
|
405
860
|
/** Project root containing the `lunora/` directory. */
|
|
406
861
|
projectRoot: string;
|
|
862
|
+
/** Process spawner for the `postcodegen` hook. Injectable so tests need no real subprocess. */
|
|
863
|
+
spawner?: Spawner;
|
|
864
|
+
/** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
|
|
865
|
+
target?: string;
|
|
407
866
|
}
|
|
408
867
|
interface CodegenWatcherHandle {
|
|
409
|
-
/**
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
868
|
+
/**
|
|
869
|
+
* Stop watching, drop any queued regeneration, and resolve once the run
|
|
870
|
+
* already in flight has finished.
|
|
871
|
+
*
|
|
872
|
+
* Awaiting the result is what keeps a `postcodegen` child from being
|
|
873
|
+
* orphaned by the caller's `process.exit`; a caller that only needs the
|
|
874
|
+
* watcher detached can ignore it.
|
|
875
|
+
*/
|
|
876
|
+
close: () => Promise<void>;
|
|
877
|
+
/**
|
|
878
|
+
* Resolves once the startup regeneration — codegen AND the project's
|
|
879
|
+
* `postcodegen` — has finished.
|
|
880
|
+
*
|
|
881
|
+
* Await it before starting anything that reads generated output. `runCodegen`
|
|
882
|
+
* is synchronous and has already run by the time `startCodegenWatch` returns,
|
|
883
|
+
* but the hook is the step that FINISHES that output, so a worker spawned
|
|
884
|
+
* without waiting can bundle the unfinished copy. Resolves (never rejects)
|
|
885
|
+
* even when codegen or the hook failed — both report for themselves, and a
|
|
886
|
+
* dev server still has to come up.
|
|
887
|
+
*/
|
|
888
|
+
ready: Promise<void>;
|
|
889
|
+
/**
|
|
890
|
+
* `true` when the platform supports recursive watch and the loop is active.
|
|
891
|
+
* `false` when `fs.watch({ recursive })` threw — startup-only codegen was run
|
|
892
|
+
* but schema edits will NOT auto-regenerate. Callers can surface this in the
|
|
893
|
+
* dev banner so the degraded state is visible beyond the single startup warning.
|
|
894
|
+
*/
|
|
417
895
|
watchAvailable: boolean;
|
|
418
896
|
}
|
|
419
897
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
|
|
898
|
+
* Readiness probe seam — tests swap the real HTTP probe out.
|
|
899
|
+
*
|
|
900
|
+
* The optional `signal` lets a caller cancel an attempt already in flight. Its
|
|
901
|
+
* absence is why a teardown used to leave one request dangling for up to
|
|
902
|
+
* {@link ATTEMPT_TIMEOUT_MS} after the dev server had been told to stop.
|
|
903
|
+
*/
|
|
904
|
+
type ReadinessProbe = (origin: string, signal?: AbortSignal) => Promise<boolean>;
|
|
905
|
+
/**
|
|
906
|
+
* Start the studio server and resolve once it is listening. Loads the static
|
|
907
|
+
* bundle + renders the host HTML once up front; serves them and proxies
|
|
908
|
+
* `/_lunora/*` (HTTP + WS) to the worker.
|
|
909
|
+
*/
|
|
424
910
|
declare const startStudioServer: (options: StudioServerOptions) => Promise<StudioServerHandle>;
|
|
425
911
|
interface StudioServerOptions {
|
|
912
|
+
/**
|
|
913
|
+
* API-spec mode the host runs codegen with, forwarded to the local endpoints
|
|
914
|
+
* so a studio edit regenerates the SAME spec files the host's own codegen run
|
|
915
|
+
* writes. Codegen writes the spec its mode names and deletes the other, so
|
|
916
|
+
* omitting it made every studio edit delete an `apiSpec: "openrpc"` project's
|
|
917
|
+
* `openrpc.json`.
|
|
918
|
+
*/
|
|
919
|
+
apiSpec?: CodegenOptions["apiSpec"];
|
|
426
920
|
/** Project root — `.dev.vars` is read from here for the admin token. */
|
|
427
921
|
cwd: string;
|
|
428
922
|
/** Loopback host to bind. Defaults to `127.0.0.1` (admin tooling stays local). */
|
|
429
923
|
host?: string;
|
|
924
|
+
/** Lazy function mode the host runs codegen with, forwarded to local source-edit endpoints. */
|
|
925
|
+
lazyFunctions?: CodegenOptions["lazyFunctions"];
|
|
430
926
|
/** One-time warning sink for a missing/unbuilt `@lunora/studio`. */
|
|
431
927
|
logger?: {
|
|
432
928
|
warnOnce?: (message: string) => void;
|
|
@@ -442,6 +938,25 @@ interface StudioServerHandle {
|
|
|
442
938
|
/** The URL to open in a browser. */
|
|
443
939
|
url: string;
|
|
444
940
|
}
|
|
941
|
+
/**
|
|
942
|
+
* How the dev child runs. `wrangler` is the classic `lunora dev` stack (wrangler
|
|
943
|
+
* worker + embedded studio + codegen watch) for a standalone class-C project.
|
|
944
|
+
* `vite` is a project whose BUNDLER PLUGIN already runs the worker — `@lunora/vite`
|
|
945
|
+
* inside the Vite dev server, or `@lunora/rspack/rsbuild` alongside an Rsbuild
|
|
946
|
+
* one — together with studio and codegen, so `lunora dev` runs the project's own
|
|
947
|
+
* dev script and gets out of the way — this also covers class-B
|
|
948
|
+
* frameworks whose own dev server runs the worker in `workerd` (Astro 6 +
|
|
949
|
+
* `@astrojs/cloudflare`, which embeds `@cloudflare/vite-plugin` in `astro dev`:
|
|
950
|
+
* SSR + `/_lunora/*` + `ShardDO` in one process, HMR intact). `framework-worker`
|
|
951
|
+
* is a class-B framework whose dev server CANNOT host the `ShardDO` Durable
|
|
952
|
+
* Object (SvelteKit / Nuxt: their adapters use wrangler's `getPlatformProxy()`,
|
|
953
|
+
* which runs an empty-script Miniflare and does not emulate internal DOs); there
|
|
954
|
+
* `lunora dev` runs the framework's own dev server (front door, HMR, and — via
|
|
955
|
+
* its `@lunora/vite` plugin — studio + codegen) AND a second `wrangler dev`
|
|
956
|
+
* sidecar that owns the real `ShardDO` in `workerd`, wired via the committed
|
|
957
|
+
* `wrangler.dev.jsonc`.
|
|
958
|
+
*/
|
|
959
|
+
type DevFlavor = "framework-worker" | "vite" | "wrangler";
|
|
445
960
|
/** A running worker child the orchestrator controls: send signals, await its exit. */
|
|
446
961
|
interface WorkerProcess {
|
|
447
962
|
/** Resolves with the worker's exit code (1 if it failed to start). */
|
|
@@ -452,103 +967,216 @@ interface WorkerProcess {
|
|
|
452
967
|
type WorkerSpawner = (descriptor: SpawnDescriptor & {
|
|
453
968
|
tag: string;
|
|
454
969
|
}, logger: Logger) => WorkerProcess;
|
|
970
|
+
/** What a long-lived child runs: the one-shot descriptor's command/args/cwd/env, plus how to spawn it. */
|
|
971
|
+
interface LongLivedDescriptor {
|
|
972
|
+
args: ReadonlyArray<string>;
|
|
973
|
+
command: string;
|
|
974
|
+
cwd?: string;
|
|
975
|
+
/** A real executable, never a package-manager shim — spawned without a shell, with stdin ignored. */
|
|
976
|
+
direct?: boolean;
|
|
977
|
+
env?: Readonly<Record<string, string>>;
|
|
978
|
+
}
|
|
979
|
+
/** Spawns a long-lived child and streams its output line by line. Injectable for tests. */
|
|
980
|
+
type LongLivedSpawner = (descriptor: LongLivedDescriptor, onLine: (line: string, kind: "stderr" | "stdout") => void, onError?: (error: Error) => void) => WorkerProcess;
|
|
981
|
+
/** A `--tunnel` request, built once from the parsed flags. */
|
|
982
|
+
interface DevTunnelRequest {
|
|
983
|
+
/** Normalized `--allow-mail` entries, passed to cloudflared as `--allowed-mail`; empty opens a PUBLIC tunnel. */
|
|
984
|
+
allowMail: ReadonlyArray<string>;
|
|
985
|
+
/** Injection seam for tests — the one-shot spawner the `cloudflared --version` probe runs through. */
|
|
986
|
+
spawner?: Spawner;
|
|
987
|
+
/** Injection seam for tests — starts the long-lived `cloudflared tunnel` child. */
|
|
988
|
+
startChild?: LongLivedSpawner;
|
|
989
|
+
}
|
|
455
990
|
interface DevCommandOptions {
|
|
456
991
|
/** Which API spec(s) the codegen watcher emits. Defaults to codegen's `"openapi"` when omitted. */
|
|
457
992
|
apiSpec?: ApiSpec;
|
|
458
993
|
/** Disable the codegen watch loop. */
|
|
459
994
|
codegen?: boolean;
|
|
460
995
|
cwd?: string;
|
|
996
|
+
/**
|
|
997
|
+
* Override where the binding manifest is written. One is always produced at
|
|
998
|
+
* `DEV_BINDINGS_FILE`; naming a path also makes a derivation failure
|
|
999
|
+
* fatal, since a named path means something is waiting on it.
|
|
1000
|
+
*/
|
|
1001
|
+
emitBindings?: string;
|
|
461
1002
|
/** Injection seam for tests — defaults to the real `.dev.vars` scaffolder. */
|
|
462
1003
|
ensureEnv?: typeof ensureDevVariables;
|
|
463
1004
|
/** Injection seam for tests — defaults to the real `.dev.vars.example` package-aware scaffolder. */
|
|
464
1005
|
ensureExample?: typeof ensureDevVarsExample;
|
|
465
1006
|
/** Injection seam for tests — defaults to the real empty-secret/admin-token filler. */
|
|
466
1007
|
fillSecrets?: typeof fillDevSecrets;
|
|
1008
|
+
/** Injection seam for tests — defaults to the real free-port probe (`findAvailablePort`). */
|
|
1009
|
+
findFreePort?: (preferred: number) => Promise<number>;
|
|
1010
|
+
/** Dev flavor override (tests / callers that already detected it) — defaults to `detectDevFlavor`. */
|
|
1011
|
+
flavor?: DevFlavor;
|
|
1012
|
+
/** Injection seam for tests — defaults to the real IPv6-loopback probe (`hasIpv6Loopback`). */
|
|
1013
|
+
hasIpv6Loopback?: () => boolean;
|
|
1014
|
+
/** `wrangler dev` devtools inspector port (`--inspector-port`). Wrangler flavor only — see `resolveInspectorPort`. */
|
|
1015
|
+
inspectorPort?: number;
|
|
1016
|
+
/**
|
|
1017
|
+
* Logs are NDJSON on stdout (`--json`, or a detected AI agent). Forwarded to
|
|
1018
|
+
* the codegen watcher so a `postcodegen` script's own stdout is routed to
|
|
1019
|
+
* stderr instead of corrupting the stream.
|
|
1020
|
+
*/
|
|
1021
|
+
jsonLogs?: boolean;
|
|
1022
|
+
/** Opt into per-module lazy function loading for CLI codegen. */
|
|
1023
|
+
lazyFunctions?: boolean;
|
|
1024
|
+
/** Pass `--local` to `wrangler dev`: no remote proxy session, so a binding with no local mode (`ai`) cannot stop the session from starting. */
|
|
1025
|
+
local?: boolean;
|
|
467
1026
|
logger: Logger;
|
|
468
|
-
/** Injection seam for tests — defaults to the real
|
|
469
|
-
|
|
1027
|
+
/** Injection seam for tests — defaults to the real dev-config materializer (remote bindings and the logged-out `ai` withholding). */
|
|
1028
|
+
materializeDev?: typeof materializeDevWranglerConfig;
|
|
1029
|
+
/** Injection seam for tests — defaults to the real per-service dev-config materializer. */
|
|
1030
|
+
materializeServiceConfigs?: typeof materializeServiceDevConfigs;
|
|
470
1031
|
/** Studio server port. */
|
|
471
1032
|
port?: number;
|
|
1033
|
+
/** Injection seam for tests — defaults to the real HTTP readiness probe. Without it the suite issues live GETs to the dev port. */
|
|
1034
|
+
probeReady?: ReadinessProbe;
|
|
472
1035
|
/** Proxy D1/KV/R2 bindings to the deployed worker during dev (`LUNORA_REMOTE=1` / `--remote`); DO shards stay local. */
|
|
473
1036
|
remote?: boolean;
|
|
1037
|
+
/** Starts the celld dev session for the celld target; injected in tests. */
|
|
1038
|
+
startCelldSession?: typeof startCelldDevSession;
|
|
474
1039
|
/** Injection seam for tests — defaults to the real codegen watcher. */
|
|
475
1040
|
startCodegen?: typeof startCodegenWatch;
|
|
1041
|
+
/** Injection seam for tests — defaults to the embedded Postgres behind a Hyperdrive binding. */
|
|
1042
|
+
startHyperdrive?: typeof startLocalHyperdrive;
|
|
476
1043
|
/** Injection seam for tests — defaults to the real studio server. */
|
|
477
1044
|
startStudio?: typeof startStudioServer;
|
|
478
1045
|
/** Injection seam for tests — defaults to spawning a real `wrangler dev`. */
|
|
479
1046
|
startWorker?: WorkerSpawner;
|
|
480
1047
|
/** Disable the embedded studio server. */
|
|
481
1048
|
studio?: boolean;
|
|
1049
|
+
/** Deploy target the emitted `ctx.*` surface is tailored to. Resolved by the caller; falls back to `"target"` in `lunora.config.*`, then `"cloudflare"`. */
|
|
1050
|
+
target?: string;
|
|
1051
|
+
/** `--tunnel`: share the worker's origin through a Cloudflare quick tunnel. Absent means no tunnel. */
|
|
1052
|
+
tunnel?: DevTunnelRequest;
|
|
1053
|
+
/**
|
|
1054
|
+
* Injection seam for tests — defaults to parking until SIGINT.
|
|
1055
|
+
*
|
|
1056
|
+
* Attached mode (`--no-worker`) ends only on a signal, so without this the
|
|
1057
|
+
* whole branch is unreachable from a test. That is how the readiness probe
|
|
1058
|
+
* came to be wired after the early return, reported for a flavor it never
|
|
1059
|
+
* covered, and shipped.
|
|
1060
|
+
*/
|
|
1061
|
+
waitForInterrupt?: (logger: Logger) => Promise<number>;
|
|
1062
|
+
/** Disable the `wrangler dev` spawn — an external task runner owns the worker. */
|
|
1063
|
+
worker?: boolean;
|
|
482
1064
|
/** `wrangler dev` port. */
|
|
483
1065
|
workerPort?: number;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
/** Short binding labels remoted (e.g. `"DB (D1)"`), for the banner. */
|
|
487
|
-
bindings: string[];
|
|
488
|
-
/**
|
|
489
|
-
* Removes the generated temp wrangler config when dev exits. Always present
|
|
490
|
-
* and idempotent — a no-op when remote mode is off or nothing was
|
|
491
|
-
* materialized. The dev loop calls it on every shutdown path.
|
|
492
|
-
*/
|
|
493
|
-
cleanup: () => void;
|
|
494
|
-
/** Whether remote mode was requested. */
|
|
495
|
-
enabled: boolean;
|
|
496
|
-
/** Why remote mode didn't take effect despite being requested, for logging. */
|
|
497
|
-
reason?: string;
|
|
1066
|
+
/** Writes the celld projection for a `--no-worker` run; injected in tests. */
|
|
1067
|
+
writeCelldProjection?: typeof writeCelldDevProjection;
|
|
498
1068
|
}
|
|
499
1069
|
interface DevCommandPlan {
|
|
500
|
-
|
|
1070
|
+
/**
|
|
1071
|
+
* `true` when the worker is a celld dev session (a target running its own
|
|
1072
|
+
* dev server) rather than {@link DevCommandPlan.wrangler}'s process: services
|
|
1073
|
+
* registered first, a service edit re-registering it and restarting the app.
|
|
1074
|
+
*/
|
|
1075
|
+
celldSession?: true;
|
|
1076
|
+
/** Which stack the child runs — see {@link DevFlavor}. */
|
|
1077
|
+
flavor: DevFlavor;
|
|
1078
|
+
/**
|
|
1079
|
+
* One-line redirect hint printed when a meta-framework is detected on the
|
|
1080
|
+
* wrangler flavor: without `@lunora/vite` in the dependencies the worker
|
|
1081
|
+
* still runs *inside* the framework's dev server, so the user should run
|
|
1082
|
+
* their framework dev script for the full app. `undefined` for the vite
|
|
1083
|
+
* flavor (`lunora dev` already runs the project's dev script there) and
|
|
1084
|
+
* for a standalone project. Purely informational: the wrangler spawn runs
|
|
1085
|
+
* regardless.
|
|
1086
|
+
*/
|
|
1087
|
+
frameworkHint?: string;
|
|
1088
|
+
/**
|
|
1089
|
+
* True when `wrangler dev` was given `--ip 127.0.0.1` because the host has no
|
|
1090
|
+
* IPv6 loopback (`::1`) — surfaced so the dev loop can note the rebind.
|
|
1091
|
+
* Always `false` for the vite flavor (the plugin owns its own bind).
|
|
1092
|
+
*/
|
|
1093
|
+
ipv4LoopbackForced: boolean;
|
|
501
1094
|
/** The remote-binding decision: which D1/KV/R2 bindings hit the deployed worker. */
|
|
502
|
-
remote:
|
|
1095
|
+
remote: RemotePlan;
|
|
1096
|
+
runsCodegenWatch: boolean;
|
|
1097
|
+
/**
|
|
1098
|
+
* Unlinks the copies of service configs written so a service's custom build
|
|
1099
|
+
* runs in its own folder (`materializeServiceDevConfigs`). Idempotent; absent
|
|
1100
|
+
* for a flavor that runs no services through a `wrangler dev` of its own.
|
|
1101
|
+
*/
|
|
1102
|
+
serviceConfigCleanup?: () => void;
|
|
1103
|
+
/**
|
|
1104
|
+
* The `wrangler dev` sidecar for the `framework-worker` flavor (SvelteKit /
|
|
1105
|
+
* Nuxt): a second child that owns the real `ShardDO` in `workerd`, wired via
|
|
1106
|
+
* the committed `wrangler.dev.jsonc`. `undefined` for every other flavor —
|
|
1107
|
+
* only the two-process class-B stack has a sidecar. When present, `wrangler`
|
|
1108
|
+
* (above) is the framework's own dev server (the front door / HMR) and this
|
|
1109
|
+
* is the Lunora realtime plane.
|
|
1110
|
+
*/
|
|
1111
|
+
sidecar?: SpawnDescriptor & {
|
|
1112
|
+
tag: string;
|
|
1113
|
+
};
|
|
503
1114
|
studioEnabled: boolean;
|
|
504
1115
|
studioPort: number;
|
|
1116
|
+
/**
|
|
1117
|
+
* Whether this process spawns `wrangler dev`.
|
|
1118
|
+
*
|
|
1119
|
+
* `--no-worker` turns it off so an external task runner (Turbo, Nx, vis, a
|
|
1120
|
+
* Procfile) can own worker supervision while `lunora dev` still provides
|
|
1121
|
+
* codegen-watch and Studio. Without it, `lunora dev` insisted on being the
|
|
1122
|
+
* process root, which is what blocked running the Lunora worker as one node
|
|
1123
|
+
* in a larger dev graph.
|
|
1124
|
+
*/
|
|
1125
|
+
workerEnabled: boolean;
|
|
505
1126
|
workerOrigin: string;
|
|
506
1127
|
workerPort: number;
|
|
507
|
-
/** The
|
|
1128
|
+
/** The primary child `lunora dev` spawns: `wrangler dev` (wrangler flavor) or the framework/`vite dev` server (vite / framework-worker). */
|
|
508
1129
|
wrangler: SpawnDescriptor & {
|
|
509
1130
|
tag: string;
|
|
510
1131
|
};
|
|
511
1132
|
}
|
|
512
1133
|
/**
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
|
|
518
|
-
* to remote, the args stay empty and dev runs fully local.
|
|
519
|
-
*/
|
|
520
|
-
/**
|
|
521
|
-
* Plan `lunora dev`: it runs the worker via `wrangler dev` and nothing else as a
|
|
522
|
-
* child process. Vite is intentionally NOT spawned — a project may not use Vite,
|
|
523
|
-
* and when it does, the `@lunora/vite` plugin already runs the worker inside
|
|
524
|
-
* Vite, so the user runs `vite` themselves. Pure + synchronous so it's unit-testable.
|
|
525
|
-
*/
|
|
526
|
-
declare const planDevCommand: (options: DevCommandOptions) => DevCommandPlan;
|
|
527
|
-
/**
|
|
528
|
-
* Start codegen watch + the studio server, spawn `wrangler dev`, print the
|
|
529
|
-
* banner, and resolve when the worker exits or the user interrupts — tearing
|
|
530
|
-
* down the sibling servers either way. The three side-effecting pieces (worker,
|
|
531
|
-
* studio, codegen) are injectable so this is testable without real I/O.
|
|
532
|
-
*/
|
|
1134
|
+
* Start codegen watch + the studio server, spawn `wrangler dev`, print the
|
|
1135
|
+
* banner, and resolve when the worker exits or the user interrupts — tearing
|
|
1136
|
+
* down the sibling servers either way. The three side-effecting pieces (worker,
|
|
1137
|
+
* studio, codegen) are injectable so this is testable without real I/O.
|
|
1138
|
+
*/
|
|
533
1139
|
declare const runDevCommand: (options: DevCommandOptions) => Promise<{
|
|
534
1140
|
code: number;
|
|
535
1141
|
plan: DevCommandPlan;
|
|
536
1142
|
}>;
|
|
537
|
-
/**
|
|
1143
|
+
/**
|
|
1144
|
+
* Plan `lunora dev`. Wrangler flavor: the worker runs via `wrangler dev` and
|
|
1145
|
+
* nothing else as a child process. Vite flavor (`@lunora/vite` declared): the
|
|
1146
|
+
* plugin already runs the worker inside the Vite dev server, so the one child
|
|
1147
|
+
* is the project's own dev script (`vite dev`, `astro dev`, …) and every CLI
|
|
1148
|
+
* sibling is disabled. Pure + synchronous so it's unit-testable.
|
|
1149
|
+
*/
|
|
1150
|
+
declare const planDevCommand: (options: DevCommandOptions) => DevCommandPlan;
|
|
538
1151
|
/** Supported CI providers. */
|
|
539
1152
|
type CiProvider = "github" | "gitlab";
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
*/
|
|
1153
|
+
/**
|
|
1154
|
+
* The per-framework auth-UI registry items (`auth-ui` resolves to one of these).
|
|
1155
|
+
*
|
|
1156
|
+
* Solid has two because these are copy-in source files, not a compiled package:
|
|
1157
|
+
* the 1.x and 2.0 spellings are mutually exclusive in the source itself, so the
|
|
1158
|
+
* two majors get one item each and {@link detectAuthUiItem} picks.
|
|
1159
|
+
*/
|
|
1160
|
+
type AuthUiItem = "auth-ui-angular" | "auth-ui-react" | "auth-ui-solid" | "auth-ui-solid-v2" | "auth-ui-svelte" | "auth-ui-vue";
|
|
549
1161
|
/** A registry item a feature can install. */
|
|
550
|
-
type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | "mail";
|
|
551
|
-
/**
|
|
1162
|
+
type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | AuthUiItem | "mail";
|
|
1163
|
+
/** One catalog entry as `lunora registry list` reports it. */
|
|
1164
|
+
interface CatalogItem {
|
|
1165
|
+
description?: string;
|
|
1166
|
+
name: string;
|
|
1167
|
+
}
|
|
1168
|
+
/** A built index entry (catalog item plus its short `title`). */
|
|
1169
|
+
interface IndexItem extends CatalogItem {
|
|
1170
|
+
title?: string;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Build the catalog (`index.json` contents) from a local registry root by
|
|
1174
|
+
* reading every item's `registry.json`. Used by both `lunora registry build`
|
|
1175
|
+
* and the registry tests so the committed index can't drift from the item dirs.
|
|
1176
|
+
*/
|
|
1177
|
+
declare const buildRegistryIndex: (root: string) => {
|
|
1178
|
+
items: IndexItem[];
|
|
1179
|
+
};
|
|
552
1180
|
/** A single file the item scaffolds into the project. */
|
|
553
1181
|
interface RegistryFile {
|
|
554
1182
|
/** Source path inside the item dir (e.g. `schema.ts`). */
|
|
@@ -564,10 +1192,10 @@ interface RegistryBinding {
|
|
|
564
1192
|
value: unknown;
|
|
565
1193
|
}
|
|
566
1194
|
/**
|
|
567
|
-
* An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
|
|
568
|
-
* local-secrets file) on add — non-secrets get their `value`; secrets get an
|
|
569
|
-
* empty placeholder and a reminder to run `wrangler secret put` for production.
|
|
570
|
-
*/
|
|
1195
|
+
* An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
|
|
1196
|
+
* local-secrets file) on add — non-secrets get their `value`; secrets get an
|
|
1197
|
+
* empty placeholder and a reminder to run `wrangler secret put` for production.
|
|
1198
|
+
*/
|
|
571
1199
|
interface RegistryEnvVariable {
|
|
572
1200
|
/** Human note on what the variable is for. */
|
|
573
1201
|
description?: string;
|
|
@@ -578,6 +1206,13 @@ interface RegistryEnvVariable {
|
|
|
578
1206
|
/** A default/example value for non-secret vars. */
|
|
579
1207
|
value?: string;
|
|
580
1208
|
}
|
|
1209
|
+
/** A re-export the item needs injected into the worker entry point (class-B/C only). */
|
|
1210
|
+
interface EntrypointReexport {
|
|
1211
|
+
/** Optional JS comment placed above the re-export line. */
|
|
1212
|
+
comment?: string;
|
|
1213
|
+
/** Module specifier (e.g. `"_generated/workflows"` → `export * from "./lunora/_generated/workflows"`). */
|
|
1214
|
+
module: string;
|
|
1215
|
+
}
|
|
581
1216
|
/** The `registry.json` manifest shape. */
|
|
582
1217
|
interface RegistryManifest {
|
|
583
1218
|
/** wrangler.jsonc additions (best-effort structural edits). */
|
|
@@ -589,6 +1224,8 @@ interface RegistryManifest {
|
|
|
589
1224
|
devDependencies?: Readonly<Record<string, string>>;
|
|
590
1225
|
/** Post-install guidance printed after the item is added (per-item next steps). */
|
|
591
1226
|
docs?: string;
|
|
1227
|
+
/** Worker-entry re-exports the item needs (class-B/C only). */
|
|
1228
|
+
entrypointReexports?: ReadonlyArray<EntrypointReexport>;
|
|
592
1229
|
/** Environment variables the item needs; scaffolded into `.dev.vars`. */
|
|
593
1230
|
envVars?: ReadonlyArray<RegistryEnvVariable>;
|
|
594
1231
|
files: ReadonlyArray<RegistryFile>;
|
|
@@ -610,10 +1247,10 @@ interface AddCommandOptions {
|
|
|
610
1247
|
diff?: boolean;
|
|
611
1248
|
/** Print the plan and stop without writing anything. */
|
|
612
1249
|
dryRun?: boolean;
|
|
1250
|
+
/** Output format: `pretty` (default) or `json` — a JSON snapshot of the plan/list. */
|
|
1251
|
+
format?: OutputFormat;
|
|
613
1252
|
/** Local registry root (offline / tests). Expects per-item subdirs, each with a `registry.json`. */
|
|
614
1253
|
from?: string;
|
|
615
|
-
/** Emit a JSON snapshot of the plan/result. */
|
|
616
|
-
json?: boolean;
|
|
617
1254
|
/** `--list`: enumerate available items instead of adding. */
|
|
618
1255
|
list?: boolean;
|
|
619
1256
|
logger: Logger;
|
|
@@ -628,19 +1265,51 @@ interface AddCommandOptions {
|
|
|
628
1265
|
/** Override the remote registry source base (default gh:anolilab/lunora/registry). */
|
|
629
1266
|
source?: string;
|
|
630
1267
|
/**
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
1268
|
+
* Customize each resolved manifest after it is loaded but before the plan is
|
|
1269
|
+
* printed / reconciled — used to inject user-chosen values into otherwise
|
|
1270
|
+
* static manifests (e.g. the R2 `bucket_name` the init storage prompt asks
|
|
1271
|
+
* for). Applied to every item; return the manifest unchanged to leave it as-is.
|
|
1272
|
+
*/
|
|
636
1273
|
transformManifest?: (manifest: RegistryManifest) => RegistryManifest;
|
|
637
1274
|
/** Skip the package.json mutation confirmation prompt. */
|
|
638
1275
|
yes?: boolean;
|
|
639
1276
|
}
|
|
640
|
-
|
|
1277
|
+
/**
|
|
1278
|
+
* One item in the `--format json` plan snapshot. Carries the concrete binding
|
|
1279
|
+
* VALUES, not just the key paths, so a plan consumer can audit the mutation
|
|
1280
|
+
* before it is applied.
|
|
1281
|
+
*/
|
|
1282
|
+
interface RegistryPlanItem {
|
|
1283
|
+
bindings: {
|
|
1284
|
+
path: string;
|
|
1285
|
+
value: unknown;
|
|
1286
|
+
}[];
|
|
1287
|
+
deps: string[];
|
|
1288
|
+
devDependencies: string[];
|
|
1289
|
+
entrypointReexports: {
|
|
1290
|
+
comment?: string;
|
|
1291
|
+
module: string;
|
|
1292
|
+
}[];
|
|
1293
|
+
envVars: {
|
|
1294
|
+
name: string;
|
|
1295
|
+
secret?: boolean;
|
|
1296
|
+
value?: string;
|
|
1297
|
+
}[];
|
|
1298
|
+
files: {
|
|
1299
|
+
merge: RegistryFile["merge"];
|
|
1300
|
+
to: string;
|
|
1301
|
+
}[];
|
|
1302
|
+
name: string;
|
|
1303
|
+
requires: ReadonlyArray<string>;
|
|
1304
|
+
title?: string;
|
|
1305
|
+
}
|
|
1306
|
+
/** The `--format json` payload: the catalog (`list`) or the resolved plan (`add`). */
|
|
1307
|
+
interface RegistryCommandData {
|
|
1308
|
+
items: ReadonlyArray<CatalogItem | RegistryPlanItem>;
|
|
1309
|
+
}
|
|
1310
|
+
interface AddCommandResult extends CommandResult<RegistryCommandData> {
|
|
641
1311
|
/** Bindings written to wrangler.jsonc. */
|
|
642
1312
|
bindings: ReadonlyArray<string>;
|
|
643
|
-
code: number;
|
|
644
1313
|
/** Deps added to package.json. */
|
|
645
1314
|
deps: ReadonlyArray<string>;
|
|
646
1315
|
/** Files skipped because they already existed. */
|
|
@@ -648,34 +1317,40 @@ interface AddCommandResult {
|
|
|
648
1317
|
/** Files written (absolute paths). */
|
|
649
1318
|
written: ReadonlyArray<string>;
|
|
650
1319
|
}
|
|
651
|
-
|
|
1320
|
+
type ExternalAuthProvider = "auth0" | "clerk" | "workos";
|
|
1321
|
+
/** The `--auth` values: Lunora's own auth, an external provider, or none. */
|
|
1322
|
+
type AuthChoice = ExternalAuthProvider | "lunora" | "none";
|
|
652
1323
|
/**
|
|
653
|
-
* A feature offered in the post-scaffold multi-select. `auth`/`email` carry a
|
|
654
|
-
* sub-prompt or alias; every other value IS the registry item name applied
|
|
655
|
-
* directly (`storage` → the `storage` registry item, etc.).
|
|
656
|
-
*/
|
|
657
|
-
type StackFeature = "auth" | "backup" | "crons" | "email" | "presence" | "
|
|
1324
|
+
* A feature offered in the post-scaffold multi-select. `auth`/`email` carry a
|
|
1325
|
+
* sub-prompt or alias; every other value IS the registry item name applied
|
|
1326
|
+
* directly (`storage` → the `storage` registry item, etc.).
|
|
1327
|
+
*/
|
|
1328
|
+
type StackFeature = "ai" | "auth" | "auth-ui" | "backup" | "browser" | "cloudflare-access" | "crons" | "email" | "flags" | "hyperdrive" | "payment" | "presence" | "queue" | "storage" | "workflow";
|
|
658
1329
|
/** Customize a resolved manifest before it is written (e.g. inject the chosen R2 bucket name). */
|
|
659
1330
|
type OfferTransformManifest = (manifest: RegistryManifest) => RegistryManifest;
|
|
660
1331
|
/**
|
|
661
|
-
* One feature ready to apply: the registry item name(s), an optional manifest
|
|
662
|
-
* transform, and a short `label` (the feature value) shown on the combined
|
|
663
|
-
* progress line. Built up-front by the collectors so every prompt is answered
|
|
664
|
-
* before any apply runs.
|
|
665
|
-
*/
|
|
1332
|
+
* One feature ready to apply: the registry item name(s), an optional manifest
|
|
1333
|
+
* transform, and a short `label` (the feature value) shown on the combined
|
|
1334
|
+
* progress line. Built up-front by the collectors so every prompt is answered
|
|
1335
|
+
* before any apply runs.
|
|
1336
|
+
*/
|
|
666
1337
|
interface FeatureApply {
|
|
1338
|
+
/** An external identity provider to wire into the Worker and client once its registry item is applied. */
|
|
1339
|
+
externalAuth?: ExternalAuthProvider;
|
|
667
1340
|
label: string;
|
|
668
1341
|
names: ReadonlyArray<string>;
|
|
669
1342
|
transformManifest?: OfferTransformManifest;
|
|
670
1343
|
}
|
|
671
1344
|
interface OfferDeps {
|
|
672
1345
|
/**
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
1346
|
+
* Apply the collected features into the new project in one batch — resolves
|
|
1347
|
+
* `true` when every item succeeds. The CLI renders this as a single progress
|
|
1348
|
+
* line whose label changes per feature; each plan's `transformManifest`
|
|
1349
|
+
* customizes that item's manifest before it is written.
|
|
1350
|
+
*/
|
|
678
1351
|
applyAll: (plans: ReadonlyArray<FeatureApply>) => Promise<boolean>;
|
|
1352
|
+
/** The auth choice made up front (the `--auth` flag). When set, the interactive auth question is skipped. */
|
|
1353
|
+
auth?: AuthChoice;
|
|
679
1354
|
/** When `false`, skip all prompts and print the later-setup hint. */
|
|
680
1355
|
interactive: boolean;
|
|
681
1356
|
logger: Logger;
|
|
@@ -688,13 +1363,24 @@ interface OfferDeps {
|
|
|
688
1363
|
defaults?: ReadonlyArray<StackFeature>;
|
|
689
1364
|
}) => Promise<StackFeature[]>;
|
|
690
1365
|
/**
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
1366
|
+
* Features chosen non-interactively (the `--add` flag). When set, the
|
|
1367
|
+
* multi-select and every sub-prompt are skipped — each feature is applied with
|
|
1368
|
+
* its shipped defaults (base registry item, placeholder bindings).
|
|
1369
|
+
*/
|
|
695
1370
|
preselected?: ReadonlyArray<StackFeature>;
|
|
696
1371
|
/** The new project's name — seeds smart defaults like the `project-uploads` bucket name. */
|
|
697
1372
|
projectName: string;
|
|
1373
|
+
/**
|
|
1374
|
+
* Resolve which per-framework auth-UI item (`auth-ui-react|vue|…`) fits the
|
|
1375
|
+
* scaffolded project. Injected by the CLI (detected from the template's deps);
|
|
1376
|
+
* defaults to `auth-ui-react` when absent so this module stays pure/testable.
|
|
1377
|
+
*
|
|
1378
|
+
* `undefined` is a REFUSAL, not "unknown": no auth-UI item fits this project
|
|
1379
|
+
* (React Native). `lunora add auth-ui` already refuses there, and this offer
|
|
1380
|
+
* used to `?? "auth-ui-react"` its way past that — copying ~85 DOM files into
|
|
1381
|
+
* an Expo app and exiting 0.
|
|
1382
|
+
*/
|
|
1383
|
+
resolveAuthUiItem?: () => string | undefined;
|
|
698
1384
|
/** Single-select among the auth providers (TTY-backed in production). */
|
|
699
1385
|
select: (message: string, options: ReadonlyArray<{
|
|
700
1386
|
description?: string;
|
|
@@ -703,120 +1389,147 @@ interface OfferDeps {
|
|
|
703
1389
|
}>, settings?: {
|
|
704
1390
|
default?: FeatureItem;
|
|
705
1391
|
}) => Promise<FeatureItem | undefined>;
|
|
1392
|
+
/** Single-select among the auth choices (TTY-backed in production). */
|
|
1393
|
+
selectAuth: (message: string, options: ReadonlyArray<{
|
|
1394
|
+
description?: string;
|
|
1395
|
+
label: string;
|
|
1396
|
+
value: AuthChoice;
|
|
1397
|
+
}>, settings?: {
|
|
1398
|
+
default?: AuthChoice;
|
|
1399
|
+
}) => Promise<AuthChoice | undefined>;
|
|
706
1400
|
/** Single-line text input (TTY-backed in production) — used for the storage bucket-name prompt. */
|
|
707
1401
|
text: (message: string, settings?: {
|
|
708
1402
|
default?: string;
|
|
709
1403
|
placeholder?: string;
|
|
710
1404
|
}) => Promise<string>;
|
|
711
1405
|
}
|
|
712
|
-
/**
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
1406
|
+
/** One choice in the multi-select. */
|
|
1407
|
+
interface LintToolOption {
|
|
1408
|
+
description: string;
|
|
1409
|
+
label: string;
|
|
1410
|
+
value: LintTool;
|
|
1411
|
+
}
|
|
1412
|
+
interface LintToolOfferDeps {
|
|
1413
|
+
/** Write the ignores for the chosen tools — `applyLintIgnores` in production. */
|
|
1414
|
+
apply: (tools: ReadonlyArray<LintTool>) => LintIgnoreOutcome[];
|
|
1415
|
+
/** Tools already detectable in the scaffolded project — pre-selected in the prompt. */
|
|
1416
|
+
detected: ReadonlyArray<LintTool>;
|
|
1417
|
+
/** False in CI / `--yes` / off a TTY: skip the prompt and configure whatever was detected. */
|
|
1418
|
+
interactive: boolean;
|
|
1419
|
+
logger: Logger;
|
|
1420
|
+
multiSelect: (message: string, choices: ReadonlyArray<LintToolOption>, settings?: {
|
|
1421
|
+
defaults?: ReadonlyArray<LintTool>;
|
|
1422
|
+
}) => Promise<LintTool[]>;
|
|
1423
|
+
}
|
|
1424
|
+
type Template = "analog" | "astro" | "expo" | "next" | "nuxt" | "rspack-react" | "saas" | "solid-v2" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-react-rspack" | "tanstack-start-solid" | "vinext" | "vinext-pages";
|
|
724
1425
|
interface InitCommandOptions {
|
|
725
1426
|
/**
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
1427
|
+
* Add features non-interactively after scaffolding (the `--add` flag): a
|
|
1428
|
+
* comma-separated list of `ai | auth | auth-ui | backup | browser | cloudflare-access | crons | email | flags | hyperdrive | payment | presence | queue | storage | workflow`.
|
|
1429
|
+
* Bypasses the interactive multi-select and sub-prompts —
|
|
1430
|
+
* each named feature is applied with its shipped defaults.
|
|
1431
|
+
*/
|
|
731
1432
|
add?: string;
|
|
732
1433
|
/**
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
1434
|
+
* When true, accept `--source` values that don't start with `gh:` /
|
|
1435
|
+
* `github:` / `https://` or that contain `..`. Defaults to false; the CLI
|
|
1436
|
+
* gate exists to stop arbitrary filesystem / scheme sources from being
|
|
1437
|
+
* pulled without the caller opting in.
|
|
1438
|
+
*/
|
|
738
1439
|
allowUnsafeSource?: boolean;
|
|
1440
|
+
/**
|
|
1441
|
+
* The auth choice (the `--auth` flag): `lunora` (better-auth), `clerk`,
|
|
1442
|
+
* `workos`, `auth0` or `none`. Skips the interactive auth question; without a
|
|
1443
|
+
* TTY it is applied with its shipped defaults.
|
|
1444
|
+
*/
|
|
1445
|
+
auth?: string;
|
|
739
1446
|
/** When set, also scaffold a CI deploy pipeline for the given provider. */
|
|
740
1447
|
ci?: CiProvider;
|
|
741
1448
|
cwd?: string;
|
|
742
1449
|
/**
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1450
|
+
* Walk the whole flow — prompts, task list, next-steps, mascot — but make no
|
|
1451
|
+
* changes: skip the template fetch/copy, the feature applies, the dependency
|
|
1452
|
+
* install, and `git init`. Each skipped action logs a `would …` line instead.
|
|
1453
|
+
*/
|
|
747
1454
|
dryRun?: boolean;
|
|
748
1455
|
/**
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1456
|
+
* Local directory containing the template subdirs (e.g. `vite/`,
|
|
1457
|
+
* `standalone/`). When provided, skips the network fetch entirely.
|
|
1458
|
+
* Useful for offline runs, the clean-machine smoke test, and unit tests.
|
|
1459
|
+
*/
|
|
753
1460
|
from?: string;
|
|
754
1461
|
/**
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
1462
|
+
* When true, configure Lunora into the CURRENT project (`cwd`) instead of
|
|
1463
|
+
* scaffolding a new directory. Finds an existing `vite.config.*` and
|
|
1464
|
+
* patches it via `patchViteConfig`, or creates a minimal one when absent.
|
|
1465
|
+
* All other scaffold options (`name`, `templateType`, `source`, `from`)
|
|
1466
|
+
* are ignored in this mode.
|
|
1467
|
+
*/
|
|
761
1468
|
inPlace?: boolean;
|
|
762
1469
|
/**
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1470
|
+
* Inject the post-scaffold install offer's prompts (tests). When set, the
|
|
1471
|
+
* offer runs regardless of TTY: `confirmInstall` drives the yes/no, and
|
|
1472
|
+
* `selectManager` picks among the detected managers.
|
|
1473
|
+
*/
|
|
767
1474
|
installPrompt?: {
|
|
768
1475
|
confirmInstall: () => Promise<boolean>;
|
|
769
1476
|
selectManager: (managers: ReadonlyArray<PackageManager>) => Promise<PackageManager>;
|
|
770
1477
|
};
|
|
771
1478
|
/**
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1479
|
+
* Force the post-scaffold "add auth / email?" offer on (the `--interactive`
|
|
1480
|
+
* flag). When omitted, the offer runs only when stdin is a TTY. `--yes`
|
|
1481
|
+
* suppresses it regardless. Has no effect once {@link prompt} is injected.
|
|
1482
|
+
*/
|
|
776
1483
|
interactive?: boolean;
|
|
1484
|
+
/**
|
|
1485
|
+
* Test seam for the lint/formatter multi-select. Separate from {@link prompt}
|
|
1486
|
+
* because that one is pinned to the feature-offer's value union — reusing it
|
|
1487
|
+
* here would only typecheck through a cast.
|
|
1488
|
+
*/
|
|
1489
|
+
lintPrompt?: LintToolOfferDeps["multiSelect"];
|
|
777
1490
|
logger: Logger;
|
|
778
1491
|
name?: string;
|
|
779
1492
|
/**
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1493
|
+
* Local directory holding create-vite bases (one `template-<id>/` subdir per
|
|
1494
|
+
* framework). When set with `vite`, the overlay copies the base from disk
|
|
1495
|
+
* instead of fetching `create-vite` over the network — offline mode + tests.
|
|
1496
|
+
*/
|
|
784
1497
|
overlayBaseFrom?: string;
|
|
785
|
-
/** Probe for which package managers are installed (tests). Defaults to a real
|
|
1498
|
+
/** Probe for which package managers are installed (tests). Defaults to a real `<pm> --version` check. */
|
|
786
1499
|
packageManagerProbe?: PackageManagerProbe;
|
|
787
1500
|
/**
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
prompt?: Pick<OfferDeps, "multiSelect" | "select" | "text">;
|
|
1501
|
+
* Inject the offer's prompts (tests). When set, the offer is treated as
|
|
1502
|
+
* interactive regardless of TTY, and these drive the feature multi-select,
|
|
1503
|
+
* the auth-provider sub-select, and the storage bucket-name text input.
|
|
1504
|
+
*/
|
|
1505
|
+
prompt?: Partial<Pick<OfferDeps, "selectAuth">> & Pick<OfferDeps, "multiSelect" | "select" | "text">;
|
|
793
1506
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
1507
|
+
* Override the git ref (branch, tag, or commit) the default template source
|
|
1508
|
+
* is fetched from. Takes precedence over the version-derived ref. Ignored
|
|
1509
|
+
* when `source` or `from` is set.
|
|
1510
|
+
*/
|
|
798
1511
|
ref?: string;
|
|
799
1512
|
/** Local registry root for the offer's `runAddCommand` (offline / tests). Mirrors `from` but for registry items. */
|
|
800
1513
|
registryFrom?: string;
|
|
801
1514
|
/** Override the remote registry source base for the offer (default `gh:anolilab/lunora/registry`). */
|
|
802
1515
|
registrySource?: string;
|
|
803
1516
|
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
1517
|
+
* Override the remote source giget downloads from. Default:
|
|
1518
|
+
* `gh:anolilab/lunora/templates/<templateType>#<ref>`, where `<ref>` is
|
|
1519
|
+
* the `ref` option when set, else derived from the CLI version (pre-release
|
|
1520
|
+
* channels → their branch, stable → `main`). Tests typically use `from`
|
|
1521
|
+
* instead to skip the network.
|
|
1522
|
+
*/
|
|
810
1523
|
source?: string;
|
|
811
1524
|
/** Spawner for the post-scaffold dependency install (tests inject a recording stub). Defaults to a real subprocess. */
|
|
812
1525
|
spawner?: Spawner;
|
|
813
1526
|
templateType?: Template;
|
|
814
1527
|
/**
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1528
|
+
* Scaffold via the **create-vite overlay** for this framework (`react`,
|
|
1529
|
+
* `vue`, `solid`, `svelte`, `vanilla`) instead of a bespoke template: fetch
|
|
1530
|
+
* the official create-vite base and apply the Lunora layer on top. Takes
|
|
1531
|
+
* precedence over `templateType`.
|
|
1532
|
+
*/
|
|
820
1533
|
vite?: string;
|
|
821
1534
|
/** Suppress the offer entirely (the `--yes` flag): scaffold only, print the later-setup hint. */
|
|
822
1535
|
yes?: boolean;
|
|
@@ -826,8 +1539,47 @@ interface InitCommandResult {
|
|
|
826
1539
|
files: ReadonlyArray<string>;
|
|
827
1540
|
target: string;
|
|
828
1541
|
}
|
|
1542
|
+
/**
|
|
1543
|
+
* `lunora init` entry: scaffold (in-place or a new directory), then — on success
|
|
1544
|
+
* — offer to add auth + email via the registry. The offer never affects the
|
|
1545
|
+
* scaffold's exit code.
|
|
1546
|
+
*/
|
|
829
1547
|
declare const runInitCommand: (options: InitCommandOptions) => Promise<InitCommandResult>;
|
|
830
|
-
|
|
1548
|
+
type FetchLike = (input: string, init?: {
|
|
1549
|
+
body?: string;
|
|
1550
|
+
headers?: Record<string, string>;
|
|
1551
|
+
method?: string;
|
|
1552
|
+
}) => Promise<{
|
|
1553
|
+
json: () => Promise<unknown>;
|
|
1554
|
+
ok: boolean;
|
|
1555
|
+
status: number;
|
|
1556
|
+
text: () => Promise<string>;
|
|
1557
|
+
}>;
|
|
1558
|
+
interface RunCommandOptions {
|
|
1559
|
+
args?: string;
|
|
1560
|
+
/** Forge this user id for the call (dispatches through the admin-gated `runAs` op). */
|
|
1561
|
+
as?: string;
|
|
1562
|
+
/** JSON-encoded extra identity claims to accompany {@link RunCommandOptions.as}. */
|
|
1563
|
+
claims?: string;
|
|
1564
|
+
cwd?: string;
|
|
1565
|
+
fetchImpl?: FetchLike;
|
|
1566
|
+
/** Output format: `pretty` (default) or `json`. */
|
|
1567
|
+
format?: OutputFormat;
|
|
1568
|
+
functionPath: string;
|
|
1569
|
+
logger: Logger;
|
|
1570
|
+
shard?: string;
|
|
1571
|
+
/** Admin bearer for the `runAs` dispatch; resolved from the environment / `.dev.vars` when absent. */
|
|
1572
|
+
token?: string;
|
|
1573
|
+
url?: string;
|
|
1574
|
+
}
|
|
1575
|
+
interface RunCommandResult {
|
|
1576
|
+
body: unknown;
|
|
1577
|
+
code: number;
|
|
1578
|
+
/** Why the call failed before (or at) the RPC, for the `--format json` envelope. */
|
|
1579
|
+
error?: string;
|
|
1580
|
+
requestUrl: string;
|
|
1581
|
+
}
|
|
1582
|
+
declare const runRpcCommand: (options: RunCommandOptions) => Promise<RunCommandResult>;
|
|
831
1583
|
interface MigrateGenerateCommandOptions {
|
|
832
1584
|
cwd?: string;
|
|
833
1585
|
logger: Logger;
|
|
@@ -840,42 +1592,25 @@ interface MigrateGenerateCommandResult {
|
|
|
840
1592
|
code: number;
|
|
841
1593
|
/** Whether the diff was empty (no changes detected). */
|
|
842
1594
|
empty: boolean;
|
|
1595
|
+
/** Why it failed, when the reason is known — the shared `CommandResult` contract. */
|
|
1596
|
+
error?: string;
|
|
843
1597
|
/** Absolute path to the migration file (empty string when nothing was written). */
|
|
844
1598
|
migrationFile: string;
|
|
845
1599
|
}
|
|
846
1600
|
declare const runMigrateGenerateCommand: (options: MigrateGenerateCommandOptions) => MigrateGenerateCommandResult;
|
|
847
|
-
/** One catalog entry as `lunora registry list` reports it. */
|
|
848
|
-
interface CatalogItem {
|
|
849
|
-
description?: string;
|
|
850
|
-
name: string;
|
|
851
|
-
}
|
|
852
|
-
/** A built index entry (catalog item plus its short `title`). */
|
|
853
|
-
interface IndexItem extends CatalogItem {
|
|
854
|
-
title?: string;
|
|
855
|
-
}
|
|
856
|
-
/** Names of the subdirectories under `root` that ship a `registry.json`. */
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* Build the catalog (`index.json` contents) from a local registry root by
|
|
860
|
-
* reading every item's `registry.json`. Used by both `lunora registry build`
|
|
861
|
-
* and the registry tests so the committed index can't drift from the item dirs.
|
|
862
|
-
*/
|
|
863
|
-
declare const buildRegistryIndex: (root: string) => {
|
|
864
|
-
items: IndexItem[];
|
|
865
|
-
};
|
|
866
1601
|
/** `lunora registry add` (one or more item names): scaffold items into the project. */
|
|
867
1602
|
declare const runAddCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
|
|
868
1603
|
/**
|
|
869
|
-
* `lunora registry view` — inspect a registry item without installing it:
|
|
870
|
-
* print its plan (files / deps / env vars) followed by the full contents of each
|
|
871
|
-
* file it would scaffold. Resolves only the named item — no `requires` expansion.
|
|
872
|
-
*/
|
|
1604
|
+
* `lunora registry view` — inspect a registry item without installing it:
|
|
1605
|
+
* print its plan (files / deps / env vars) followed by the full contents of each
|
|
1606
|
+
* file it would scaffold. Resolves only the named item — no `requires` expansion.
|
|
1607
|
+
*/
|
|
873
1608
|
declare const runRegistryViewCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
|
|
874
1609
|
/**
|
|
875
|
-
* `lunora registry build` — regenerate `index.json` from the item directories
|
|
876
|
-
* (the catalog `list` reads). With `--check`, verify the committed index matches
|
|
877
|
-
* instead of rewriting it (exits non-zero on drift) — a CI guard.
|
|
878
|
-
*/
|
|
1610
|
+
* `lunora registry build` — regenerate `index.json` from the item directories
|
|
1611
|
+
* (the catalog `list` reads). With `--check`, verify the committed index matches
|
|
1612
|
+
* instead of rewriting it (exits non-zero on drift) — a CI guard.
|
|
1613
|
+
*/
|
|
879
1614
|
declare const runBuildIndexCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
|
|
880
1615
|
/** Validate + narrow a parsed JSON value into a {@link RegistryManifest}. */
|
|
881
1616
|
declare const parseManifest: (raw: unknown, itemName: string) => RegistryManifest;
|
|
@@ -893,23 +1628,6 @@ interface ResetCommandResult {
|
|
|
893
1628
|
removed: ReadonlyArray<string>;
|
|
894
1629
|
}
|
|
895
1630
|
declare const runResetCommand: (options: ResetCommandOptions) => Promise<ResetCommandResult>;
|
|
896
|
-
/** `lunora reset` handler (lazy-loaded via the command's `loader`). */
|
|
897
|
-
/**
|
|
898
|
-
* Tiny argv parser.
|
|
899
|
-
*
|
|
900
|
-
* Supports long options (`--name value`, `--name=value`, `--flag`), short
|
|
901
|
-
* options (`-x value`, `-xvalue`), positional arguments (everything else, in
|
|
902
|
-
* order), and a `--` terminator after which everything is positional.
|
|
903
|
-
*
|
|
904
|
-
* Intentionally small — replaces a full CLI library for the handful of
|
|
905
|
-
* subcommands we need.
|
|
906
|
-
*/
|
|
907
|
-
interface ParsedArgs {
|
|
908
|
-
flags: Record<string, boolean>;
|
|
909
|
-
options: Record<string, string>;
|
|
910
|
-
positional: ReadonlyArray<string>;
|
|
911
|
-
}
|
|
912
|
-
declare const parseArgs: (argv: ReadonlyArray<string>, booleanFlags?: ReadonlySet<string>) => ParsedArgs;
|
|
913
1631
|
type InsertSchemaExtensionResult = {
|
|
914
1632
|
ok: true;
|
|
915
1633
|
text: string;
|
|
@@ -918,12 +1636,12 @@ type InsertSchemaExtensionResult = {
|
|
|
918
1636
|
reason: "already-applied" | "invalid-identifier" | "no-define-schema" | "non-object-argument";
|
|
919
1637
|
};
|
|
920
1638
|
/**
|
|
921
|
-
* Append `.extend(
|
|
922
|
-
* `lunora/schema.ts`. Idempotent: a second call for the same `key` returns
|
|
923
|
-
* `already-applied` and leaves the text unchanged.
|
|
924
|
-
* @param source the current `lunora/schema.ts` contents
|
|
925
|
-
* @param key the registry item key (e.g. `"ratelimit"`)
|
|
926
|
-
*/
|
|
1639
|
+
* Append `.extend(<key>.extension)` and a managed import to an existing
|
|
1640
|
+
* `lunora/schema.ts`. Idempotent: a second call for the same `key` returns
|
|
1641
|
+
* `already-applied` and leaves the text unchanged.
|
|
1642
|
+
* @param source the current `lunora/schema.ts` contents
|
|
1643
|
+
* @param key the registry item key (e.g. `"ratelimit"`)
|
|
1644
|
+
*/
|
|
927
1645
|
declare const insertSchemaExtension: (source: string, key: string) => InsertSchemaExtensionResult;
|
|
928
1646
|
/** Compact snapshot of a single global table — what we persist + diff. */
|
|
929
1647
|
interface TableSnapshot {
|
|
@@ -933,6 +1651,20 @@ interface TableSnapshot {
|
|
|
933
1651
|
name: string;
|
|
934
1652
|
}
|
|
935
1653
|
interface ColumnSnapshot {
|
|
1654
|
+
/**
|
|
1655
|
+
* The column's full validator shape — the SAME {@link FieldSnapshot} the
|
|
1656
|
+
* deploy gate diffs (`shared/schema-snapshot.ts`), not a second parallel
|
|
1657
|
+
* format.
|
|
1658
|
+
*
|
|
1659
|
+
* `sqlType` alone is lossy: `bigint`, `array`, `record`, `id`, `literal` and
|
|
1660
|
+
* `string` all map to the TEXT affinity, so `v.string()` → `v.bigint()` was
|
|
1661
|
+
* byte-identical here and `migrate generate` answered "no schema changes
|
|
1662
|
+
* detected" for a change `lunora prepare` blocks as breaking.
|
|
1663
|
+
*
|
|
1664
|
+
* Optional so a `.snapshot.json` written before this existed still parses —
|
|
1665
|
+
* it simply gets no deep check until the next generate rewrites it.
|
|
1666
|
+
*/
|
|
1667
|
+
field?: FieldSnapshot;
|
|
936
1668
|
/** True when the column accepts NULL (validator wrapped in v.optional). */
|
|
937
1669
|
nullable: boolean;
|
|
938
1670
|
/** SQLite type affinity, derived from the validator. */
|
|
@@ -966,26 +1698,48 @@ interface SchemaDiff {
|
|
|
966
1698
|
unsupported: ReadonlyArray<UnsupportedEntry>;
|
|
967
1699
|
}
|
|
968
1700
|
/**
|
|
969
|
-
* Map a Lunora validator kind to a SQLite type affinity — the canonical
|
|
970
|
-
* `@lunora/d1/dialect` mapping. Re-exported under this name because
|
|
971
|
-
* `schema-snapshot.ts` builds the persisted snapshot from it.
|
|
972
|
-
*/
|
|
1701
|
+
* Map a Lunora validator kind to a SQLite type affinity — the canonical
|
|
1702
|
+
* `@lunora/d1/dialect` mapping. Re-exported under this name because
|
|
1703
|
+
* `schema-snapshot.ts` builds the persisted snapshot from it.
|
|
1704
|
+
*/
|
|
973
1705
|
declare const validatorKindToSqlType: (kind: string) => ColumnSnapshot["sqlType"];
|
|
974
|
-
/**
|
|
1706
|
+
/**
|
|
1707
|
+
* Emit `CREATE TABLE` SQL for a new global table.
|
|
1708
|
+
*
|
|
1709
|
+
* Refuses a table past D1's column ceiling rather than writing SQL that
|
|
1710
|
+
* `lunora migrate up` will reject: the runtime auto-provisioner checks the same
|
|
1711
|
+
* number, and a migration file is the worse place to find out — the failure
|
|
1712
|
+
* lands later, against a database, with none of the schema context that names
|
|
1713
|
+
* which table and field to split.
|
|
1714
|
+
*/
|
|
975
1715
|
declare const renderCreateTable: (table: TableSnapshot) => string;
|
|
1716
|
+
/**
|
|
1717
|
+
* `lunora migrate apply` gates a destructive file on `--yes`, not on this marker, so the marker matters only to
|
|
1718
|
+
* `MigrationRunner`, when a user splits the file at each `;` into its entries by hand. On the line before the statement,
|
|
1719
|
+
* so the split keeps it with its `DROP` rather than handing it to the next statement.
|
|
1720
|
+
*/
|
|
976
1721
|
declare const renderDropTable: (tableName: string) => string;
|
|
1722
|
+
/**
|
|
1723
|
+
* `ALTER TABLE … ADD COLUMN`, always nullable. SQLite rejects `ADD COLUMN … NOT NULL` without a default on a table
|
|
1724
|
+
* that already has rows, and D1 is SQLite, so a NOT NULL add fails exactly when it matters. The runtime
|
|
1725
|
+
* auto-provisioner makes the same choice (see `alterGlobalTableDrift` in `@lunora/sql-store`), and the declared
|
|
1726
|
+
* `notNull` is still enforced on write. Existing rows read the new column as NULL until they are written, so for a
|
|
1727
|
+
* required column the statement is followed by a comment that says so and gives the backfill to run. The snapshot
|
|
1728
|
+
* records no default value, so the value is left for the author to fill in rather than guessed.
|
|
1729
|
+
*/
|
|
977
1730
|
declare const renderAddColumn: (tableName: string, columnName: string, column: ColumnSnapshot) => string;
|
|
978
1731
|
declare const renderCreateIndex: (tableName: string, index: IndexSnapshot) => string;
|
|
1732
|
+
/** Confirmed for `MigrationRunner` the same way as {@link renderDropTable}. */
|
|
979
1733
|
declare const renderDropIndex: (tableName: string, indexName: string) => string;
|
|
980
1734
|
/**
|
|
981
|
-
* Compute a {@link SchemaDiff} from two snapshots. Pure function — no I/O.
|
|
982
|
-
*/
|
|
1735
|
+
* Compute a {@link SchemaDiff} from two snapshots. Pure function — no I/O.
|
|
1736
|
+
*/
|
|
983
1737
|
declare const diffSnapshots: (previous: SchemaSnapshot | undefined, next: SchemaSnapshot) => SchemaDiff;
|
|
984
1738
|
/**
|
|
985
|
-
* Render a complete migration file body from a diff. Includes a header,
|
|
986
|
-
* each SQL statement, and (if any) a trailing comment block describing the
|
|
987
|
-
* manual SQL the user needs to fill in for unsupported deltas.
|
|
988
|
-
*/
|
|
1739
|
+
* Render a complete migration file body from a diff. Includes a header,
|
|
1740
|
+
* each SQL statement, and (if any) a trailing comment block describing the
|
|
1741
|
+
* manual SQL the user needs to fill in for unsupported deltas.
|
|
1742
|
+
*/
|
|
989
1743
|
declare const renderMigrationFile: (name: string, diff: SchemaDiff, generatedAt: string) => string;
|
|
990
1744
|
declare const schemaIrToSnapshot: (ir: SchemaIR) => SchemaSnapshot;
|
|
991
|
-
export { type AddCommandOptions, type AddCommandResult,
|
|
1745
|
+
export { type AddCommandOptions, type AddCommandResult, type ColumnSnapshot, DEFAULT_IMPORT_BATCH_SIZE, type DeployCommandOptions, type DeployCommandResult, type DeployedIdentity, type DevCommandOptions, type DevCommandPlan, type DiffEntry, EXIT_CODE, type ExitCode, type ExportCommandOptions, type ExportCommandResult, type FetchLike, type ImportCommandOptions, type ImportCommandResult, type IndexSnapshot, type InitCommandOptions, type InitCommandResult, type InsertSchemaExtensionResult, type Logger, type MigrateGenerateCommandOptions, type MigrateGenerateCommandResult, type RecordedSpawn, type RegistryBinding, type RegistryFile, type RegistryManifest, type ResetCommandOptions, type ResetCommandResult, type RunCommandOptions, type RunCommandResult, type SchemaDiff, type SchemaSnapshot, type SpawnDescriptor, type SpawnResult, type Spawner, type StreamingFetchLike, type TableSnapshot, type Template, type UnsupportedEntry, buildRegistryIndex, createLogger, createRecordingSpawner, defaultSpawner, diffSnapshots, exitCodeForCode, exitCodeForError, exitCodeForStatus, insertSchemaExtension, pail, parseManifest, planDevCommand, renderAddColumn, renderCreateIndex, renderCreateTable, renderDropIndex, renderDropTable, renderMigrationFile, runAddCommand, runBuildIndexCommand, runCodegenCommand, runDeployCommand, runDevCommand, runExportCommand, runImportCommand, runInitCommand, runMigrateGenerateCommand, runRegistryViewCommand, runResetCommand, runRpcCommand, schemaIrToSnapshot, validatorKindToSqlType };
|