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