@lunora/vite 1.0.0-alpha.32 → 1.0.0-alpha.321
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 +6 -0
- package/README.md +4 -2
- package/dist/index.d.mts +445 -320
- package/dist/index.d.ts +445 -320
- package/dist/index.mjs +3 -163
- package/dist/packem_shared/CLASS_A_WIRING-DCI5QzA9.mjs +26 -0
- package/dist/packem_shared/LUNORA_API_UPDATED_EVENT-CO2Rv2re.mjs +1 -0
- package/dist/packem_shared/WORKER_STARTUP_HINT-COlRTY32.mjs +5 -0
- package/dist/packem_shared/buildStudioUrl-DMMWpguZ.mjs +1 -0
- package/dist/packem_shared/checkLunoraProxy-BNPgNWtV.mjs +1 -0
- package/dist/packem_shared/codegenPlugin-BIAGgCkK.mjs +3 -0
- package/dist/packem_shared/containerLogsPlugin-67PZ8zmb.mjs +1 -0
- package/dist/packem_shared/devStatePlugin-CF4GDvBn.mjs +1 -0
- package/dist/packem_shared/devVariablesPlugin-DbD6cSF0.mjs +1 -0
- package/dist/packem_shared/logStreamPlugin-EMXiy6pI.mjs +3 -0
- package/dist/packem_shared/lunoraSolutionFinder--J0x2mAM.mjs +1 -0
- package/dist/packem_shared/planViteRemoteBindings-ByOliZuE.mjs +1 -0
- package/dist/packem_shared/server-close-DWiO4Vxb.mjs +1 -0
- package/dist/packem_shared/wranglerValidatorPlugin-BlGHjTXZ.mjs +1 -0
- package/package.json +8 -9
- package/dist/packem_shared/CLASS_A_WIRING-DpX_WcOK.mjs +0 -112
- package/dist/packem_shared/DEV_WORKER_ENV_VALUE-Coo6bgVz.mjs +0 -36
- package/dist/packem_shared/STUDIO_PATH-yREc3Bbm.mjs +0 -221
- package/dist/packem_shared/WORKER_STARTUP_HINT-DhsXUW8k.mjs +0 -81
- package/dist/packem_shared/codegenPlugin-B_ayaObq.mjs +0 -207
- package/dist/packem_shared/containerLogsPlugin-DMssU3wb.mjs +0 -50
- package/dist/packem_shared/devVariablesPlugin-CDNSnvOP.mjs +0 -19
- package/dist/packem_shared/log-BjO9EWah.mjs +0 -8
- package/dist/packem_shared/logStreamPlugin-CqvZ17kd.mjs +0 -61
- package/dist/packem_shared/lunoraSolutionFinder-BKEAiUJP.mjs +0 -17
- package/dist/packem_shared/planViteRemoteBindings-QN5ncUS1.mjs +0 -50
- package/dist/packem_shared/reconcileWranglerCrons-PxGwfCp_.mjs +0 -29
- package/dist/packem_shared/wranglerValidatorPlugin-CEoJEghS.mjs +0 -66
package/dist/index.d.ts
CHANGED
|
@@ -1,200 +1,231 @@
|
|
|
1
1
|
import { CodegenOptions } from '@lunora/codegen';
|
|
2
2
|
import errorOverlayPlugin from '@visulima/vite-overlay';
|
|
3
3
|
import { Plugin } from 'vite';
|
|
4
|
-
import { FrameworkDetection, DetectedFramework,
|
|
5
|
-
export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, detectFramework } from '@lunora/config';
|
|
4
|
+
import { FrameworkDetection, DetectedFramework, GeneratedClassModule, readProjectRemotePreference } from '@lunora/config';
|
|
5
|
+
export { type DetectedFramework, type FrameworkClass, type FrameworkDetection, GENERATED_CLASS_MODULES, type GeneratedClassModule, detectFramework } from '@lunora/config';
|
|
6
|
+
import { materializeRemoteWranglerConfig } from '@lunora/config/cloudflare';
|
|
7
|
+
export { type ReconcileCronsResult as ReconcileResult, reconcileWranglerCrons } from '@lunora/config/cloudflare';
|
|
6
8
|
import { AddressInfo } from 'node:net';
|
|
9
|
+
export { STUDIO_PATH } from '@lunora/config/studio-host';
|
|
7
10
|
/** Options forwarded to `@cloudflare/vite-plugin`'s cloudflare plugin. */
|
|
8
11
|
type CloudflarePluginOptions = Record<string, unknown>;
|
|
9
12
|
/**
|
|
10
|
-
* Options forwarded to `@visulima/vite-overlay`'s error-overlay plugin. Derived
|
|
11
|
-
* from the plugin's own factory signature so it tracks the real shape
|
|
12
|
-
* (`forwardConsole`, `forwardedConsoleMethods`, `reactPluginName`,
|
|
13
|
-
* `solutionFinders`, `showBallonButton`, `vuePluginName`, …).
|
|
14
|
-
*/
|
|
13
|
+
* Options forwarded to `@visulima/vite-overlay`'s error-overlay plugin. Derived
|
|
14
|
+
* from the plugin's own factory signature so it tracks the real shape
|
|
15
|
+
* (`forwardConsole`, `forwardedConsoleMethods`, `reactPluginName`,
|
|
16
|
+
* `solutionFinders`, `showBallonButton`, `vuePluginName`, …).
|
|
17
|
+
*/
|
|
15
18
|
type OverlayPluginOptions = NonNullable<Parameters<typeof errorOverlayPlugin>[0]>;
|
|
19
|
+
/**
|
|
20
|
+
* Shard Durable Object configuration for the AUTO-COMPOSED class-A worker.
|
|
21
|
+
*
|
|
22
|
+
* A class-A app (TanStack Start, vinext, React Router, SolidStart) has no
|
|
23
|
+
* hand-written worker entry — that is what makes it class A — so it never calls
|
|
24
|
+
* the generated `defineApp()` builder and never reaches `createShardDO(config)`.
|
|
25
|
+
* The composed entry emitted `createShardDO()` bare, which left `cdc` and the
|
|
26
|
+
* whole reactive query cache unreachable for every class-A template no matter
|
|
27
|
+
* what the app wanted. `vite.config.ts` is the one place such an app configures
|
|
28
|
+
* Lunora, so it is where these land — the same route
|
|
29
|
+
* {@link LunoraPluginOptions.allowUnauthenticatedShardAccess} already takes into
|
|
30
|
+
* the same emitted entry.
|
|
31
|
+
*
|
|
32
|
+
* Deliberately only the PLAIN-DATA half of the generated `ShardDOConfig`. The
|
|
33
|
+
* rest of that type is `(env) => …` factories (`scheduler`, `storage`,
|
|
34
|
+
* `vectors`, …) which cannot be written in a config object and which a class-A
|
|
35
|
+
* app reaches by writing its own entry instead.
|
|
36
|
+
*
|
|
37
|
+
* Ignored for class B/C: those pass their config to `createShardDO` directly (or
|
|
38
|
+
* through `defineApp`), and an explicit argument there is unaffected by this.
|
|
39
|
+
*/
|
|
40
|
+
interface LunoraShardConfig {
|
|
41
|
+
/** Opt into change-data-capture: every write records a post-image to `__cdc_log`. Backs streaming export, replay-PITR, and shard-local `defineShape` replication. Off by default. */
|
|
42
|
+
cdc?: boolean;
|
|
43
|
+
/** Ceiling on the join keys one relation-crossing `where` predicate may pre-resolve via semijoin before failing closed. Omit for the engine default. */
|
|
44
|
+
maxRelationKeys?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Enable the per-shard reactive query cache: `true` for the defaults, or an
|
|
47
|
+
* options object to tune the caps. Query results are memoized by
|
|
48
|
+
* `(functionPath, args, identity)` and invalidated by the ctx-db write hooks
|
|
49
|
+
* before the subscription broadcast, so a subscriber never observes a
|
|
50
|
+
* pre-write value. Omitted (or `false`) keeps every dispatch re-running its
|
|
51
|
+
* handler.
|
|
52
|
+
*/
|
|
53
|
+
reactiveCache?: boolean | {
|
|
54
|
+
maxBytes?: number;
|
|
55
|
+
maxEntries?: number;
|
|
56
|
+
};
|
|
57
|
+
/** Resolution policy for a relation-crossing `where` whose child is co-located in this shard: `"auto"` (cost-based, the engine default), `"always"` (inline correlated EXISTS) or `"never"` (universal semijoin). All three return identical rows. */
|
|
58
|
+
relationExistsPushDown?: "always" | "auto" | "never";
|
|
59
|
+
}
|
|
16
60
|
interface LunoraPluginOptions {
|
|
17
61
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
* Allow a client-named NON-default shard / cross-shard fan-out WITHOUT an
|
|
63
|
+
* `authorizeShard`/`authorizeFanOut` callback. The auto-composed class-A worker
|
|
64
|
+
* (`virtual:lunora/worker`) default-denies such access (403 `FORBIDDEN_SHARD`);
|
|
65
|
+
* set this `true` to opt into open access — only safe when every table is
|
|
66
|
+
* protected by per-row RLS. A production sharded app should configure
|
|
67
|
+
* `authorizeShard` instead (via a hand-written class-B worker). Defaults to `false`.
|
|
68
|
+
*/
|
|
69
|
+
allowUnauthenticatedShardAccess?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Which machine-readable API spec(s) codegen emits into `_generated/`.
|
|
72
|
+
* `"openapi"` (default) writes `openapi.json` (OpenAPI 3.1; RPC + REST),
|
|
73
|
+
* `"openrpc"` writes `openrpc.json` (OpenRPC 1.x; RPC-only), `"both"` writes
|
|
74
|
+
* both, and `"none"` writes neither. Forwarded to `runCodegen({ apiSpec })`;
|
|
75
|
+
* the value set is derived from `CodegenOptions` so it can't drift.
|
|
76
|
+
*/
|
|
24
77
|
apiSpec?: CodegenOptions["apiSpec"];
|
|
25
78
|
/** Pass through to `@cloudflare/vite-plugin`. Pass `false` to opt out. Defaults to `true`. */
|
|
26
79
|
cloudflare?: boolean | CloudflarePluginOptions;
|
|
27
|
-
/** Directory name (relative to `projectRoot`) where generated files are written. Defaults to `"lunora/_generated"`. */
|
|
28
|
-
generatedDir?: string;
|
|
29
80
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
81
|
+
* Inject `@visulima/vite-overlay` for runtime errors (dev only). Pass
|
|
82
|
+
* `false` to opt out, or an options object to forward to the overlay.
|
|
83
|
+
* Defaults to `true`.
|
|
84
|
+
*/
|
|
34
85
|
overlay?: boolean | OverlayPluginOptions;
|
|
35
86
|
/** Project root containing the `lunora/` directory. Defaults to `process.cwd()`. */
|
|
36
87
|
projectRoot?: string;
|
|
37
88
|
/** Directory name (relative to `projectRoot`) containing `schema.ts` and function files. Defaults to `"lunora"`. */
|
|
38
89
|
schemaDir?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Shard DO configuration baked into the auto-composed class-A worker entry —
|
|
92
|
+
* see {@link LunoraShardConfig}. The ONLY way a class-A app can set `cdc` or
|
|
93
|
+
* enable the reactive query cache, since it has no worker entry to call
|
|
94
|
+
* `createShardDO(config)` from. Ignored for class B/C. Defaults to `{}`
|
|
95
|
+
* (byte-identical composed output).
|
|
96
|
+
*/
|
|
97
|
+
shard?: LunoraShardConfig;
|
|
39
98
|
/** Serve the Lunora studio at `/__lunora` during dev. Pass `false` to opt out. Defaults to `true`. */
|
|
40
99
|
studio?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Deploy target the emitted `ctx.*` surface is tailored to. Defaults to
|
|
102
|
+
* `"target"` in `lunora.config.*`, then `"cloudflare"` — so an existing project
|
|
103
|
+
* emits byte-identical output.
|
|
104
|
+
*
|
|
105
|
+
* Set it here only to override the project config for one build — keeping
|
|
106
|
+
* this and `lunora deploy` on the same target is what the shared resolution
|
|
107
|
+
* in `@lunora/config` exists to guarantee.
|
|
108
|
+
*/
|
|
109
|
+
target?: string;
|
|
41
110
|
/** Validate that `wrangler.jsonc` declares the bindings the schema implies. Defaults to `true`. */
|
|
42
111
|
validateWrangler?: boolean;
|
|
43
112
|
}
|
|
44
113
|
/** Resolved options after merging defaults. */
|
|
45
114
|
interface ResolvedLunoraPluginOptions {
|
|
115
|
+
allowUnauthenticatedShardAccess: boolean;
|
|
46
116
|
apiSpec: NonNullable<CodegenOptions["apiSpec"]>;
|
|
47
117
|
cloudflare: false | CloudflarePluginOptions;
|
|
118
|
+
/**
|
|
119
|
+
* Where codegen writes `_generated/*`, always `<schemaDir>/_generated`.
|
|
120
|
+
*
|
|
121
|
+
* NOT a user option: codegen hardcodes that path (`run-codegen` joins
|
|
122
|
+
* `lunoraDirectory` with `"_generated"`), so a settable override was a no-op
|
|
123
|
+
* everywhere except `frameworkComposePlugin`, which uses it as the composed
|
|
124
|
+
* class-A worker's import base — where a non-default value pointed the
|
|
125
|
+
* emitted imports at a directory nothing writes and broke class-A dev and
|
|
126
|
+
* build. Derived, so the import base cannot disagree with the emitter.
|
|
127
|
+
*/
|
|
48
128
|
generatedDir: string;
|
|
49
129
|
overlay: false | OverlayPluginOptions;
|
|
50
130
|
projectRoot: string;
|
|
51
131
|
schemaDir: string;
|
|
132
|
+
shard: LunoraShardConfig;
|
|
52
133
|
studio: boolean;
|
|
134
|
+
target: string;
|
|
53
135
|
validateWrangler: boolean;
|
|
54
136
|
}
|
|
55
137
|
/**
|
|
56
|
-
* The plugins `lunora()` returns. A mutable `Plugin[]` (not `ReadonlyArray`) so
|
|
57
|
-
* it slots directly into Vite's `plugins` — which recursively flattens nested
|
|
58
|
-
* plugin arrays — without a spread: `plugins: [lunora()]`.
|
|
59
|
-
*/
|
|
138
|
+
* The plugins `lunora()` returns. A mutable `Plugin[]` (not `ReadonlyArray`) so
|
|
139
|
+
* it slots directly into Vite's `plugins` — which recursively flattens nested
|
|
140
|
+
* plugin arrays — without a spread: `plugins: [lunora()]`.
|
|
141
|
+
*/
|
|
60
142
|
type LunoraPlugins = Plugin[];
|
|
61
143
|
/**
|
|
62
|
-
* Vite plugin that runs `@lunora/codegen` on startup and on file changes
|
|
63
|
-
* inside the lunora schema directory.
|
|
64
|
-
*/
|
|
144
|
+
* Vite plugin that runs `@lunora/codegen` on startup and on file changes
|
|
145
|
+
* inside the lunora schema directory.
|
|
146
|
+
*/
|
|
65
147
|
declare const codegenPlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
66
148
|
/**
|
|
67
|
-
* Dev-only plugin that tails the local dev containers' own stdout/stderr in the
|
|
68
|
-
* Vite terminal.
|
|
69
|
-
*
|
|
70
|
-
* `@cloudflare/vite-plugin` builds and runs each declared container locally via
|
|
71
|
-
* Docker (image `cloudflare-dev
|
|
72
|
-
* console — the container process's own output is otherwise invisible. This
|
|
73
|
-
* plugin attaches to those Docker log streams (via `@lunora/config`'s
|
|
74
|
-
* `streamContainerLogs`, which lazy-loads `dockerode`) and prints each line
|
|
75
|
-
* through Vite's logger, branded and tagged `container
|
|
76
|
-
*
|
|
77
|
-
* A no-op when the project declares no containers (the common case): discovery
|
|
78
|
-
* returns an empty list, so `dockerode` is never imported and no Docker work
|
|
79
|
-
* starts. Set `LUNORA_CONTAINER_LOGS=0` to opt out. A missing/stopped Docker
|
|
80
|
-
* engine degrades to a single warning rather than breaking dev.
|
|
81
|
-
*/
|
|
149
|
+
* Dev-only plugin that tails the local dev containers' own stdout/stderr in the
|
|
150
|
+
* Vite terminal.
|
|
151
|
+
*
|
|
152
|
+
* `@cloudflare/vite-plugin` builds and runs each declared container locally via
|
|
153
|
+
* Docker (image `cloudflare-dev/<class>:<id>`) but only forwards the *worker's*
|
|
154
|
+
* console — the container process's own output is otherwise invisible. This
|
|
155
|
+
* plugin attaches to those Docker log streams (via `@lunora/config`'s
|
|
156
|
+
* `streamContainerLogs`, which lazy-loads `dockerode`) and prints each line
|
|
157
|
+
* through Vite's logger, branded and tagged `container:<name>`.
|
|
158
|
+
*
|
|
159
|
+
* A no-op when the project declares no containers (the common case): discovery
|
|
160
|
+
* returns an empty list, so `dockerode` is never imported and no Docker work
|
|
161
|
+
* starts. Set `LUNORA_CONTAINER_LOGS=0` to opt out. A missing/stopped Docker
|
|
162
|
+
* engine degrades to a single warning rather than breaking dev.
|
|
163
|
+
*/
|
|
82
164
|
declare const containerLogsPlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
changed: boolean;
|
|
86
|
-
/** Human-readable reason when reconciliation was skipped (for logging). */
|
|
87
|
-
reason?: string;
|
|
88
|
-
/** Resolved wrangler path, or `undefined` when none was found. */
|
|
89
|
-
wranglerPath?: string;
|
|
90
|
-
}
|
|
165
|
+
/** Vite plugin (serve-only) that writes the dev-server state record on listen and clears it on close. */
|
|
166
|
+
declare const devStatePlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
91
167
|
/**
|
|
92
|
-
*
|
|
93
|
-
* `
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* the
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
* First, {@link ensureDevVariables}: when a `.dev.vars.example` exists, prompt
|
|
114
|
-
* to generate `.dev.vars` from it with secrets auto-filled. Second,
|
|
115
|
-
* {@link fillDevSecrets}: fill any empty/placeholder secret already in
|
|
116
|
-
* `.dev.vars` (a `lunora add`-scaffolded project writes secrets blank) and
|
|
117
|
-
* ensure `LUNORA_ADMIN_TOKEN` is present + generated — so the worker boots with
|
|
118
|
-
* working secrets and the Studio authenticates without its login gate. No
|
|
119
|
-
* prompt: it only generates locally-derivable values and never overwrites a real
|
|
120
|
-
* one.
|
|
121
|
-
*
|
|
122
|
-
* Runs in `configResolved` (awaited by Vite) so it completes before the
|
|
123
|
-
* Cloudflare plugin reads the file. Non-interactive runs decline silently.
|
|
124
|
-
*/
|
|
168
|
+
* Dev-only Vite plugin that prepares `.dev.vars` before the worker boots.
|
|
169
|
+
* `@cloudflare/vite-plugin` loads `.dev.vars` into the worker's `env`, but the
|
|
170
|
+
* file is gitignored — so a fresh clone has none and the worker throws on the
|
|
171
|
+
* first required secret (e.g. `AUTH_SECRET is required`). All three steps live in
|
|
172
|
+
* `@lunora/config`, shared with `lunora dev` and `@lunora/rspack`.
|
|
173
|
+
*
|
|
174
|
+
* First, {@link ensureDevVariables}: when a `.dev.vars.example` exists, prompt
|
|
175
|
+
* to generate `.dev.vars` from it with secrets auto-filled. Second,
|
|
176
|
+
* {@link fillDevSecrets}: fill any empty/placeholder secret already in
|
|
177
|
+
* `.dev.vars` that Lunora can mint locally (a `lunora add`-scaffolded project
|
|
178
|
+
* writes secrets blank) and ensure `LUNORA_ADMIN_TOKEN` is present + generated —
|
|
179
|
+
* so the worker boots with working secrets and the Studio authenticates without
|
|
180
|
+
* its login gate. No prompt: it only generates locally-derivable values and
|
|
181
|
+
* never overwrites a real one. Third, {@link ensureDevWorkerEnv}.
|
|
182
|
+
*
|
|
183
|
+
* Runs in `configResolved` (awaited by Vite) so it completes before the
|
|
184
|
+
* Cloudflare plugin reads the file. Non-interactive runs decline silently.
|
|
185
|
+
* Skipped under `vite preview`, which resolves with `command: "serve"` and so
|
|
186
|
+
* runs `apply: "serve"` plugins too — previewing a built app must not prompt to
|
|
187
|
+
* scaffold, or write, a dev secrets file.
|
|
188
|
+
*/
|
|
125
189
|
declare const devVariablesPlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
126
190
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
* It is injected ONLY during `vite` serve, never a production `vite build`, so
|
|
133
|
-
* it can never leak into a deployed worker. A `WORKER_ENV` the user already
|
|
134
|
-
* declares (in `wrangler.jsonc` `[vars]` or `.dev.vars`) takes precedence, so
|
|
135
|
-
* this only fills the gap when none is set.
|
|
136
|
-
*/
|
|
137
|
-
declare const DEV_WORKER_ENV_VAR = "WORKER_ENV";
|
|
138
|
-
declare const DEV_WORKER_ENV_VALUE = "development";
|
|
139
|
-
/** The structural slice of `@cloudflare/vite-plugin`'s worker config we read/write. */
|
|
140
|
-
/**
|
|
141
|
-
* Wrap the cloudflare-plugin options so the dev worker's `vars` gain a
|
|
142
|
-
* `WORKER_ENV` of `development` when — and only when — `isServe()` reports a
|
|
143
|
-
* `vite` serve. Any `config` customizer the caller already supplied is
|
|
144
|
-
* preserved and applied first; an existing `WORKER_ENV` wins, so a user
|
|
145
|
-
* override is never clobbered.
|
|
146
|
-
*/
|
|
147
|
-
declare const withDevWorkerEnv: (options: CloudflarePluginOptions, isServe: () => boolean) => CloudflarePluginOptions;
|
|
148
|
-
/**
|
|
149
|
-
* A Vite plugin that captures the resolved command (`serve` vs `build`) so
|
|
150
|
-
* {@link withDevWorkerEnv} injects the dev var only during `vite`, plus an
|
|
151
|
-
* `isServe` probe sharing the same closure. `enforce: "pre"` so the command is
|
|
152
|
-
* captured before the cloudflare plugin resolves its worker config.
|
|
153
|
-
*/
|
|
154
|
-
declare const createCommandProbe: () => {
|
|
155
|
-
isServe: () => boolean;
|
|
156
|
-
plugin: Plugin;
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Mutable, plugin-shared context. The `lunora()` factory creates one instance
|
|
160
|
-
* and threads it through every Lunora sub-plugin, so detection runs once and
|
|
161
|
-
* downstream plugins (codegen, composition, the dev hint) read the same result
|
|
162
|
-
* without re-scanning `package.json`. PLAN4 §2.4.
|
|
163
|
-
*/
|
|
191
|
+
* Mutable, plugin-shared context. The `lunora()` factory creates one instance
|
|
192
|
+
* and threads it through every Lunora sub-plugin, so detection runs once and
|
|
193
|
+
* downstream plugins (codegen, composition, the dev hint) read the same result
|
|
194
|
+
* without re-scanning `package.json`. PLAN4 §2.4.
|
|
195
|
+
*/
|
|
164
196
|
interface LunoraPluginContext {
|
|
165
197
|
/** The detected framework + class, populated during `config` / `configResolved`. `undefined` until detection runs. */
|
|
166
198
|
framework?: FrameworkDetection;
|
|
167
199
|
}
|
|
168
|
-
/** Create an empty shared context object for one `lunora()` invocation. */
|
|
169
200
|
/**
|
|
170
|
-
* The virtual module id the Lunora plugin resolves to a generated, class-A
|
|
171
|
-
* worker entry. A class-A template points its wrangler `main` at this id (or
|
|
172
|
-
* re-exports it from a one-line `src/server.ts`) and never hand-writes
|
|
173
|
-
* `createWorker({ httpRouter })` — the plugin composes the framework's SSR
|
|
174
|
-
* handler under `composeWorker`'s `httpRouter` seam for it.
|
|
175
|
-
*
|
|
176
|
-
* Exposed publicly so `@lunora/cli`'s build/deploy path and the templates can
|
|
177
|
-
* reference the same constant rather than re-typing the literal.
|
|
178
|
-
*/
|
|
201
|
+
* The virtual module id the Lunora plugin resolves to a generated, class-A
|
|
202
|
+
* worker entry. A class-A template points its wrangler `main` at this id (or
|
|
203
|
+
* re-exports it from a one-line `src/server.ts`) and never hand-writes
|
|
204
|
+
* `createWorker({ httpRouter })` — the plugin composes the framework's SSR
|
|
205
|
+
* handler under `composeWorker`'s `httpRouter` seam for it.
|
|
206
|
+
*
|
|
207
|
+
* Exposed publicly so `@lunora/cli`'s build/deploy path and the templates can
|
|
208
|
+
* reference the same constant rather than re-typing the literal.
|
|
209
|
+
*/
|
|
179
210
|
declare const LUNORA_WORKER_VIRTUAL_ID: string;
|
|
180
211
|
/**
|
|
181
|
-
* Per-class-A-framework wiring the generated worker entry needs: how to obtain
|
|
182
|
-
* the framework's SSR handler as a `composeWorker`-compatible `httpRouter`.
|
|
183
|
-
*
|
|
184
|
-
* `imports` is the full import statement(s) the generated entry needs (each
|
|
185
|
-
* framework controls its own import shape — a namespace import, or a named one);
|
|
186
|
-
* `handler` is a JS expression (evaluated in the generated module's scope, where
|
|
187
|
-
* `imports`' symbols are in scope) that yields an `HttpRouterLike`
|
|
188
|
-
* (`{ fetch(request, env?, ctx?) }`). Both are data — not codegen branches — so
|
|
189
|
-
* the set of supported class-A frameworks is one readable table and adding a
|
|
190
|
-
* framework is a pure data edit.
|
|
191
|
-
*
|
|
192
|
-
* Honesty note: these handler expressions encode each framework's *documented*
|
|
193
|
-
* Cloudflare SSR-handler shape — the same expressions the hand-wired template
|
|
194
|
-
* entries use today (React Router's `createRequestHandler` over its virtual
|
|
195
|
-
* server build; SolidStart's `cloudflare-module` handler; TanStack Start's
|
|
196
|
-
* server entry). The plugin just emits them so the developer doesn't.
|
|
197
|
-
*/
|
|
212
|
+
* Per-class-A-framework wiring the generated worker entry needs: how to obtain
|
|
213
|
+
* the framework's SSR handler as a `composeWorker`-compatible `httpRouter`.
|
|
214
|
+
*
|
|
215
|
+
* `imports` is the full import statement(s) the generated entry needs (each
|
|
216
|
+
* framework controls its own import shape — a namespace import, or a named one);
|
|
217
|
+
* `handler` is a JS expression (evaluated in the generated module's scope, where
|
|
218
|
+
* `imports`' symbols are in scope) that yields an `HttpRouterLike`
|
|
219
|
+
* (`{ fetch(request, env?, ctx?) }`). Both are data — not codegen branches — so
|
|
220
|
+
* the set of supported class-A frameworks is one readable table and adding a
|
|
221
|
+
* framework is a pure data edit.
|
|
222
|
+
*
|
|
223
|
+
* Honesty note: these handler expressions encode each framework's *documented*
|
|
224
|
+
* Cloudflare SSR-handler shape — the same expressions the hand-wired template
|
|
225
|
+
* entries use today (React Router's `createRequestHandler` over its virtual
|
|
226
|
+
* server build; SolidStart's `cloudflare-module` handler; TanStack Start's
|
|
227
|
+
* server entry). The plugin just emits them so the developer doesn't.
|
|
228
|
+
*/
|
|
198
229
|
interface ClassAWiring {
|
|
199
230
|
/** JS expression yielding the `httpRouter` ({ fetch }), referencing symbols brought in by `imports`. */
|
|
200
231
|
handler: string;
|
|
@@ -203,62 +234,109 @@ interface ClassAWiring {
|
|
|
203
234
|
}
|
|
204
235
|
declare const CLASS_A_WIRING: Readonly<Partial<Record<DetectedFramework, ClassAWiring>>>;
|
|
205
236
|
/**
|
|
206
|
-
* Whether the detected framework is one the plugin can auto-compose. Only
|
|
207
|
-
* class-A frameworks with a known SSR-handler wiring qualify; everything else
|
|
208
|
-
* (class B/C, `none`) falls back to the existing flow.
|
|
209
|
-
*/
|
|
237
|
+
* Whether the detected framework is one the plugin can auto-compose. Only
|
|
238
|
+
* class-A frameworks with a known SSR-handler wiring qualify; everything else
|
|
239
|
+
* (class B/C, `none`) falls back to the existing flow.
|
|
240
|
+
*/
|
|
210
241
|
declare const isAutoComposable: (context: LunoraPluginContext) => boolean;
|
|
242
|
+
/** Trailing `.ts` on the app-config path — the bundler resolves the extension, so the emitted specifier drops it. */
|
|
211
243
|
/**
|
|
212
|
-
* Build the source of the virtual class-A worker entry. Pure (no fs / no Vite),
|
|
213
|
-
* so the emitted composition is unit-testable in isolation.
|
|
214
|
-
*
|
|
215
|
-
* The emitted module imports the framework SSR handler
|
|
216
|
-
* generated
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* `
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
|
|
225
|
-
|
|
244
|
+
* Build the source of the virtual class-A worker entry. Pure (no fs / no Vite),
|
|
245
|
+
* so the emitted composition is unit-testable in isolation.
|
|
246
|
+
*
|
|
247
|
+
* The emitted module imports the framework SSR handler and the project's
|
|
248
|
+
* generated `defineApp()` builder, and mounts the handler as the app's
|
|
249
|
+
* `httpRouter` — reserved `/_lunora/*` paths route to Lunora, everything else
|
|
250
|
+
* falls through to the framework SSR handler. `.build()` yields the whole
|
|
251
|
+
* module worker (`fetch` / `scheduled` / `queue` / `email`) plus `ShardDO`. The
|
|
252
|
+
* `generatedImportBase` MUST be an absolute filesystem path to the `_generated`
|
|
253
|
+
* directory. Virtual modules have no real filesystem path, so relative specifiers
|
|
254
|
+
* like `./lunora/_generated/functions` cannot be resolved by Vite/rolldown from a
|
|
255
|
+
* virtual module id. Absolute paths are resolved correctly in all environments
|
|
256
|
+
* (Vite 8 + rolldown 1.x confirmed).
|
|
257
|
+
*/
|
|
258
|
+
interface WorkerEntryComposition {
|
|
259
|
+
/** Whether to allow unauthenticated shard access — `.extend(...)` on the builder. */
|
|
260
|
+
allowUnauthenticatedShardAccess?: boolean;
|
|
261
|
+
/** Finished specifier for the project's `lunora.config.*`, when it declares an `app` hook. */
|
|
262
|
+
appConfigModule?: string;
|
|
263
|
+
/** The `_generated/` class modules that exist, each star-re-exported. */
|
|
264
|
+
classModules?: ReadonlyArray<GeneratedClassModule>;
|
|
265
|
+
/** Codegen wrote the merge module: export one `LunoraDO` hosting the shard, scheduler and registry (plan 462). */
|
|
266
|
+
mergeDurableObjects?: boolean;
|
|
267
|
+
/** Per-shard knobs, each key named after the builder method that sets it. */
|
|
268
|
+
shard?: LunoraShardConfig;
|
|
269
|
+
}
|
|
270
|
+
declare const buildWorkerEntrySource: (framework: DetectedFramework, generatedImportBase: string, composition?: WorkerEntryComposition) => string;
|
|
226
271
|
/**
|
|
227
|
-
* Vite plugin that auto-composes a detected class-A meta-framework's SSR
|
|
228
|
-
* handler with Lunora into one Cloudflare Worker (PLAN4 §2.4 / §3 class-A row).
|
|
229
|
-
*
|
|
230
|
-
* Mechanism: it resolves the {@link LUNORA_WORKER_VIRTUAL_ID} virtual module to
|
|
231
|
-
* a generated worker entry that wires the framework SSR handler under
|
|
232
|
-
* `composeWorker`'s `httpRouter` seam — so the developer never writes
|
|
233
|
-
* `createWorker({ httpRouter })`. The composed worker is an ordinary module
|
|
234
|
-
* entry, so it HMRs under `@cloudflare/vite-plugin` exactly like a hand-written
|
|
235
|
-
* one (PLAN4 M5 risk #5): the virtual entry only imports the framework handler
|
|
236
|
-
* and the generated artifacts, both of which the framework's plugin + codegen
|
|
237
|
-
* already make HMR-aware.
|
|
238
|
-
*
|
|
239
|
-
* Safety: it is a strict no-op unless `context.framework.class === "A"` with a
|
|
240
|
-
* known wiring. For class-C (SPA) projects and undetected frameworks it
|
|
241
|
-
* resolves/loads nothing. `cloudflare: false` does NOT disable the virtual
|
|
242
|
-
* entry — it only means "don't add the Cloudflare Vite plugin a second time"
|
|
243
|
-
* (the user supplied it themselves); the composed worker must still be
|
|
244
|
-
* resolvable so the user-supplied CF plugin can find the wrangler `main`.
|
|
245
|
-
|
|
272
|
+
* Vite plugin that auto-composes a detected class-A meta-framework's SSR
|
|
273
|
+
* handler with Lunora into one Cloudflare Worker (PLAN4 §2.4 / §3 class-A row).
|
|
274
|
+
*
|
|
275
|
+
* Mechanism: it resolves the {@link LUNORA_WORKER_VIRTUAL_ID} virtual module to
|
|
276
|
+
* a generated worker entry that wires the framework SSR handler under
|
|
277
|
+
* `composeWorker`'s `httpRouter` seam — so the developer never writes
|
|
278
|
+
* `createWorker({ httpRouter })`. The composed worker is an ordinary module
|
|
279
|
+
* entry, so it HMRs under `@cloudflare/vite-plugin` exactly like a hand-written
|
|
280
|
+
* one (PLAN4 M5 risk #5): the virtual entry only imports the framework handler
|
|
281
|
+
* and the generated artifacts, both of which the framework's plugin + codegen
|
|
282
|
+
* already make HMR-aware.
|
|
283
|
+
*
|
|
284
|
+
* Safety: it is a strict no-op unless `context.framework.class === "A"` with a
|
|
285
|
+
* known wiring. For class-C (SPA) projects and undetected frameworks it
|
|
286
|
+
* resolves/loads nothing. `cloudflare: false` does NOT disable the virtual
|
|
287
|
+
* entry — it only means "don't add the Cloudflare Vite plugin a second time"
|
|
288
|
+
* (the user supplied it themselves); the composed worker must still be
|
|
289
|
+
* resolvable so the user-supplied CF plugin can find the wrangler `main`. The
|
|
290
|
+
* vinext template depends on exactly that, so making this plugin honour the
|
|
291
|
+
* option would break it.
|
|
292
|
+
*/
|
|
246
293
|
declare const frameworkComposePlugin: (options: ResolvedLunoraPluginOptions, context: LunoraPluginContext) => Plugin;
|
|
247
294
|
/**
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
|
|
295
|
+
* The custom HMR event the Lunora Vite plugin sends on the client environment's
|
|
296
|
+
* hot channel after a successful codegen run, in place of the old blanket
|
|
297
|
+
* browser `full-reload`. The generated `api`/`server` modules are just
|
|
298
|
+
* `FunctionReference` metadata, so Vite's granular module HMR re-imports the
|
|
299
|
+
* changed `_generated/*` in place; this event is a non-destructive nudge that
|
|
300
|
+
* lets open WebSocket subscriptions, optimistic state, the offline queue, and
|
|
301
|
+
* form state survive a schema save.
|
|
302
|
+
*
|
|
303
|
+
* Kept in its own module (a single source of truth) so the codegen plugin —
|
|
304
|
+
* whose sole export is the plugin factory — can reference it without becoming a
|
|
305
|
+
* mixed default+named module, and so any future client-side listener can agree
|
|
306
|
+
* on the exact string.
|
|
307
|
+
*
|
|
308
|
+
* There is no first-party client listener yet: `@lunora/client` / `@lunora/react`
|
|
309
|
+
* ship as pre-bundled, side-effect-free dependencies where `import.meta.hot` is
|
|
310
|
+
* `undefined` at runtime (Vite's dep optimizer), so a listener there would be
|
|
311
|
+
* dead (and tree-shaken) code. A future app-local or codegen-emitted listener
|
|
312
|
+
* can import this constant to re-validate active queries over the live socket.
|
|
313
|
+
*/
|
|
314
|
+
declare const LUNORA_API_UPDATED_EVENT = "lunora:api-updated";
|
|
315
|
+
/**
|
|
316
|
+
* Vite plugin (serve-only) that formats Lunora worker logs in the terminal.
|
|
317
|
+
* Patches `process.stdout`/`process.stderr` fresh for each dev-server generation
|
|
318
|
+
* and restores them when that server closes.
|
|
319
|
+
*/
|
|
252
320
|
declare const logStreamPlugin: () => Plugin;
|
|
321
|
+
/**
|
|
322
|
+
* Warnings for one proxy table. Pure + exported so the behavior is unit-testable
|
|
323
|
+
* without booting a dev server.
|
|
324
|
+
*/
|
|
325
|
+
declare const checkLunoraProxy: (proxy: Record<string, unknown> | undefined, label: string) => string[];
|
|
326
|
+
/**
|
|
327
|
+
* Warn when a dev/preview proxy routes `/_lunora/*` without `ws: true` (or with an
|
|
328
|
+
* origin-rewriting `changeOrigin`). See the module docs.
|
|
329
|
+
*/
|
|
330
|
+
declare const proxyCheckPlugin: () => Plugin;
|
|
253
331
|
/** The decision a {@link planViteRemoteBindings} call returns. */
|
|
254
332
|
interface ViteRemotePlan {
|
|
255
333
|
/** Idempotent disposer for the temp config; always present + safe to call. */
|
|
256
334
|
cleanup: () => void;
|
|
257
335
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
336
|
+
* Absolute path to the materialized temp wrangler config to hand the
|
|
337
|
+
* cloudflare plugin's `configPath`, or `undefined` when remote mode is off
|
|
338
|
+
* or nothing was materialized (no eligible binding, no wrangler file, …).
|
|
339
|
+
*/
|
|
262
340
|
configPath?: string;
|
|
263
341
|
/** Whether remote mode was requested for this dev session. */
|
|
264
342
|
enabled: boolean;
|
|
@@ -269,170 +347,217 @@ interface ViteRemotePlan {
|
|
|
269
347
|
interface PlanViteRemoteOptions {
|
|
270
348
|
/** Injection seam — defaults to the real materializer. */
|
|
271
349
|
materialize?: typeof materializeRemoteWranglerConfig;
|
|
272
|
-
/** Project root containing `wrangler.jsonc` + the optional `lunora.
|
|
350
|
+
/** Project root containing `wrangler.jsonc` + the optional `lunora.config.*`. */
|
|
273
351
|
projectRoot: string;
|
|
274
|
-
/** Injection seam — defaults to the real `lunora.
|
|
352
|
+
/** Injection seam — defaults to the real `lunora.config.*` reader. */
|
|
275
353
|
readPreference?: typeof readProjectRemotePreference;
|
|
276
354
|
/** The raw `LUNORA_REMOTE` env value; defaults to `process.env.LUNORA_REMOTE`. */
|
|
277
355
|
remoteEnv?: string;
|
|
278
356
|
}
|
|
279
357
|
/**
|
|
280
|
-
* Decide whether the Vite dev worker uses remote bindings and, if so,
|
|
281
|
-
* materialize the temp config. Pure decision + a single fs write via the
|
|
282
|
-
* injected materializer; returns a `cleanup` for the dev server's close hook.
|
|
283
|
-
*
|
|
284
|
-
* There is no `--remote` flag on the Vite path (Vite has no Lunora CLI flags),
|
|
285
|
-
* so the precedence reduces to `LUNORA_REMOTE` env > `lunora.
|
|
286
|
-
|
|
358
|
+
* Decide whether the Vite dev worker uses remote bindings and, if so,
|
|
359
|
+
* materialize the temp config. Pure decision + a single fs write via the
|
|
360
|
+
* injected materializer; returns a `cleanup` for the dev server's close hook.
|
|
361
|
+
*
|
|
362
|
+
* There is no `--remote` flag on the Vite path (Vite has no Lunora CLI flags),
|
|
363
|
+
* so the precedence reduces to `LUNORA_REMOTE` env > `lunora.config.*` `remote`.
|
|
364
|
+
*
|
|
365
|
+
* Call this from a `config` hook, never at plugin-factory time — see
|
|
366
|
+
* {@link remoteBindingsPlugin} for the two defects that timing caused.
|
|
367
|
+
*/
|
|
287
368
|
declare const planViteRemoteBindings: (options: PlanViteRemoteOptions) => ViteRemotePlan;
|
|
288
369
|
/**
|
|
289
|
-
* Wrap the cloudflare-plugin options so the dev worker loads the materialized
|
|
290
|
-
* remote temp config (via `configPath`) when — and only when — remote mode is
|
|
291
|
-
* on
|
|
292
|
-
* explicit choice)
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
*/
|
|
301
|
-
declare const withRemoteBindings: (options: CloudflarePluginOptions, isServe: () => boolean, plan: ViteRemotePlan) => CloudflarePluginOptions;
|
|
370
|
+
* Wrap the cloudflare-plugin options so the dev worker loads the materialized
|
|
371
|
+
* remote temp config (via `configPath`) when — and only when — remote mode is
|
|
372
|
+
* on and a temp config was materialized. A `configPath` the caller already set
|
|
373
|
+
* wins (their explicit choice).
|
|
374
|
+
*
|
|
375
|
+
* Pure decision only — the serve-vs-build gate lives in
|
|
376
|
+
* {@link remoteBindingsPlugin}'s `config` hook, because the resolved Vite
|
|
377
|
+
* `command` is unknown at plugin-factory time. An eager serve check there would
|
|
378
|
+
* always read `command` as undefined and strip `configPath`.
|
|
379
|
+
*/
|
|
380
|
+
declare const withRemoteBindings: (options: CloudflarePluginOptions, plan: ViteRemotePlan) => CloudflarePluginOptions;
|
|
302
381
|
/**
|
|
303
|
-
* A
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
|
|
307
|
-
|
|
382
|
+
* A `enforce: "pre"` plugin that materializes the remote temp wrangler config
|
|
383
|
+
* and injects it into the cloudflare plugin's `configPath` — but only on a
|
|
384
|
+
* `vite` serve, never a production build (so the deployed worker is never
|
|
385
|
+
* affected) — then disposes the temp file when the dev server tears down.
|
|
386
|
+
*
|
|
387
|
+
* Both halves are deferred into the `config` hook, and each deferral closes a
|
|
388
|
+
* defect of its own.
|
|
389
|
+
*
|
|
390
|
+
* The command check: at plugin-factory time Vite has not yet resolved `serve`
|
|
391
|
+
* vs `build`, so it has to run here. An eager factory-time check always read
|
|
392
|
+
* `command` as undefined and stripped `configPath`, so remote bindings never
|
|
393
|
+
* activated on `vite dev` at all.
|
|
394
|
+
*
|
|
395
|
+
* The materialization: the temp config is a COPY of `wrangler.jsonc`, and
|
|
396
|
+
* Lunora provisions the bindings the project's code implies from
|
|
397
|
+
* `bindingsProvisionPlugin`'s own `config` hook — earlier in this same phase,
|
|
398
|
+
* since both are `enforce: "pre"` and that plugin is registered first. (It is a
|
|
399
|
+
* plugin of its own, registered unconditionally, precisely so this copy is not a
|
|
400
|
+
* binding short whenever `validateWrangler` is off — `wranglerValidatorPlugin`
|
|
401
|
+
* only validates, and is registered after this one.) Copying
|
|
402
|
+
* the file at factory time therefore snapshotted it BEFORE that write, and the
|
|
403
|
+
* dev worker booted against a config missing the binding Lunora had just added:
|
|
404
|
+
* a `vite dev` that logged `inferred bindings → AI (Workers AI)`, passed
|
|
405
|
+
* validation, and served a worker with no `env.AI`. That is the remote twin of
|
|
406
|
+
* the local defect the reconcile's move into `config` fixed.
|
|
407
|
+
*
|
|
408
|
+
* The injection mutates the SAME options object handed to `cloudflare()` in
|
|
409
|
+
* place — the cloudflare plugin reads `pluginConfig.configPath` lazily inside
|
|
410
|
+
* its own `config` hook, which runs after this `enforce: "pre"` one, so the
|
|
411
|
+
* injection takes effect.
|
|
412
|
+
*
|
|
413
|
+
* The disposer reads the CURRENT plan rather than a factory-time capture,
|
|
414
|
+
* because no plan exists until `config` has run.
|
|
415
|
+
*
|
|
416
|
+
* When remote mode was requested but nothing materialized (no eligible binding,
|
|
417
|
+
* no wrangler file, …), the plan's `reason` is logged so the degradation isn't
|
|
418
|
+
* silent.
|
|
419
|
+
*
|
|
420
|
+
* `options` is `undefined` on the BYO path (`cloudflare: false`), where the
|
|
421
|
+
* project constructs `cloudflare()` itself and Lunora has no options object to
|
|
422
|
+
* inject into: the materialized path is printed with what to do with it, rather
|
|
423
|
+
* than leaving `LUNORA_REMOTE` looking like it took effect.
|
|
424
|
+
*/
|
|
425
|
+
declare const remoteBindingsPlugin: (options: CloudflarePluginOptions | undefined, planOptions: PlanViteRemoteOptions) => Plugin;
|
|
308
426
|
/**
|
|
309
|
-
* A `@visulima/vite-overlay` solution finder. Derived from the overlay's own
|
|
310
|
-
* options type so the shape can't drift from the installed package. The overlay
|
|
311
|
-
* runs every finder it's given (custom finders first, then its built-ins),
|
|
312
|
-
* sorted by `priority` descending, and shows the first non-`undefined` result.
|
|
313
|
-
*
|
|
314
|
-
* Note: this type (and {@link Solution}) is re-exported from `@lunora/vite` and
|
|
315
|
-
* intentionally tracks the installed `@visulima/vite-overlay` — if a future
|
|
316
|
-
* overlay release changes the finder contract, that surfaces here as a compile
|
|
317
|
-
* error rather than a silent drift.
|
|
318
|
-
*/
|
|
427
|
+
* A `@visulima/vite-overlay` solution finder. Derived from the overlay's own
|
|
428
|
+
* options type so the shape can't drift from the installed package. The overlay
|
|
429
|
+
* runs every finder it's given (custom finders first, then its built-ins),
|
|
430
|
+
* sorted by `priority` descending, and shows the first non-`undefined` result.
|
|
431
|
+
*
|
|
432
|
+
* Note: this type (and {@link Solution}) is re-exported from `@lunora/vite` and
|
|
433
|
+
* intentionally tracks the installed `@visulima/vite-overlay` — if a future
|
|
434
|
+
* overlay release changes the finder contract, that surfaces here as a compile
|
|
435
|
+
* error rather than a silent drift.
|
|
436
|
+
*/
|
|
319
437
|
type SolutionFinder = NonNullable<OverlayPluginOptions["solutionFinders"]>[number];
|
|
320
438
|
/** What a finder may return: a Markdown-rendered `{ header?, body }`, or `undefined` to defer. */
|
|
321
439
|
type Solution = NonNullable<Awaited<ReturnType<SolutionFinder["handle"]>>>;
|
|
322
440
|
/**
|
|
323
|
-
* Lunora's solution finder for the dev error overlay. A single finder that
|
|
324
|
-
* delegates to `@lunora/codegen`'s shared rule table (the same table the
|
|
325
|
-
* standalone `lunora dev` CLI prints to the terminal) and returns the first
|
|
326
|
-
* match — so one `priority` slot covers every Lunora rule and the overlay's
|
|
327
|
-
* built-in finders still run for anything we don't recognize (we return
|
|
328
|
-
* `undefined`).
|
|
329
|
-
*
|
|
330
|
-
* Priority is high so a Lunora-specific hint wins over the overlay's generic
|
|
331
|
-
* finder for the same error; a user's own finder can still outrank it with a
|
|
332
|
-
* higher `priority`.
|
|
333
|
-
*/
|
|
441
|
+
* Lunora's solution finder for the dev error overlay. A single finder that
|
|
442
|
+
* delegates to `@lunora/codegen`'s shared rule table (the same table the
|
|
443
|
+
* standalone `lunora dev` CLI prints to the terminal) and returns the first
|
|
444
|
+
* match — so one `priority` slot covers every Lunora rule and the overlay's
|
|
445
|
+
* built-in finders still run for anything we don't recognize (we return
|
|
446
|
+
* `undefined`).
|
|
447
|
+
*
|
|
448
|
+
* Priority is high so a Lunora-specific hint wins over the overlay's generic
|
|
449
|
+
* finder for the same error; a user's own finder can still outrank it with a
|
|
450
|
+
* higher `priority`.
|
|
451
|
+
*/
|
|
334
452
|
declare const lunoraSolutionFinder: SolutionFinder;
|
|
335
453
|
/** The finders Lunora injects into the overlay by default. */
|
|
336
454
|
declare const lunoraSolutionFinders: ReadonlyArray<SolutionFinder>;
|
|
337
|
-
/** Dev-server path the studio SPA is served from. */
|
|
338
|
-
declare const STUDIO_PATH = "/__lunora";
|
|
339
|
-
/** Static asset routes the studio document references. */
|
|
340
|
-
|
|
341
455
|
/**
|
|
342
|
-
* Build the user-facing studio URL from the dev server's resolved address.
|
|
343
|
-
* Pure so it can be unit-tested without a live server. Prefers Vite's own
|
|
344
|
-
* `resolvedUrls.local` (honours `host` / `base` / https); falls back to the raw
|
|
345
|
-
* socket address, bracketing IPv6 and normalising the wildcard host.
|
|
346
|
-
*/
|
|
456
|
+
* Build the user-facing studio URL from the dev server's resolved address.
|
|
457
|
+
* Pure so it can be unit-tested without a live server. Prefers Vite's own
|
|
458
|
+
* `resolvedUrls.local` (honours `host` / `base` / https); falls back to the raw
|
|
459
|
+
* socket address, bracketing IPv6 and normalising the wildcard host.
|
|
460
|
+
*/
|
|
347
461
|
declare const buildStudioUrl: (input: {
|
|
348
462
|
address?: AddressInfo | string;
|
|
349
463
|
base?: string;
|
|
350
464
|
resolvedLocal?: string;
|
|
351
465
|
}) => string;
|
|
352
466
|
/**
|
|
353
|
-
* Vite plugin that serves the composed Lunora studio at
|
|
354
|
-
* {@link STUDIO_PATH} during dev and prints its URL once the server is
|
|
355
|
-
* listening. Dev-only (`apply: "serve"`); it adds nothing to production builds.
|
|
356
|
-
*
|
|
357
|
-
* Because `lunora dev` spawns Vite, this makes the studio available on
|
|
358
|
-
* `lunora dev` and on a plain `vite` with no per-project files. The studio
|
|
359
|
-
* is served as a prebuilt static bundle, independent of the host app.
|
|
360
|
-
*/
|
|
361
|
-
declare const studioPlugin: () => Plugin;
|
|
467
|
+
* Vite plugin that serves the composed Lunora studio at
|
|
468
|
+
* {@link STUDIO_PATH} during dev and prints its URL once the server is
|
|
469
|
+
* listening. Dev-only (`apply: "serve"`); it adds nothing to production builds.
|
|
470
|
+
*
|
|
471
|
+
* Because `lunora dev` spawns Vite, this makes the studio available on
|
|
472
|
+
* `lunora dev` and on a plain `vite` with no per-project files. The studio
|
|
473
|
+
* is served as a prebuilt static bundle, independent of the host app.
|
|
474
|
+
*/
|
|
475
|
+
declare const studioPlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
362
476
|
/**
|
|
363
|
-
* When a module under `lunora/` throws while the Worker entry is first
|
|
364
|
-
* evaluated, `@cloudflare/vite-plugin` surfaces the failure from deep inside
|
|
365
|
-
* its `runner-worker` running in `workerd`. The real error crosses a workerd
|
|
366
|
-
* RPC boundary on the way out, which drops the user-code stack frames — so all
|
|
367
|
-
* the dev server sees is a bare, file-less message like:
|
|
368
|
-
*
|
|
369
|
-
* ```
|
|
370
|
-
* TypeError: Cannot read properties of undefined (reading 'string')
|
|
371
|
-
* at runInRunnerObject (workers/runner-worker/index.js:107:3)
|
|
372
|
-
* at getWorkerEntryExportTypes (workers/runner-worker/index.js:246:24)
|
|
373
|
-
* ```
|
|
374
|
-
*
|
|
375
|
-
* The classic cause is a **circular import**: a `lunora/` query/mutation/action
|
|
376
|
-
* module runs `mutation({ args: { x: v.string() } })` at the top level while the
|
|
377
|
-
* module it imported `v`/`query`/`mutation` from is still mid-initialization, so
|
|
378
|
-
* those bindings read as `undefined`. The message names a validator method
|
|
379
|
-
* (`'string'`, `'id'`, …) but never the file.
|
|
380
|
-
*
|
|
381
|
-
* We can't recover the dropped frames at this layer, but we can recognise the
|
|
382
|
-
* shape of the failure and append an actionable hint pointing at the likely
|
|
383
|
-
* cause — turning a dead-end stack into something a user can act on.
|
|
384
|
-
*/
|
|
477
|
+
* When a module under `lunora/` throws while the Worker entry is first
|
|
478
|
+
* evaluated, `@cloudflare/vite-plugin` surfaces the failure from deep inside
|
|
479
|
+
* its `runner-worker` running in `workerd`. The real error crosses a workerd
|
|
480
|
+
* RPC boundary on the way out, which drops the user-code stack frames — so all
|
|
481
|
+
* the dev server sees is a bare, file-less message like:
|
|
482
|
+
*
|
|
483
|
+
* ```
|
|
484
|
+
* TypeError: Cannot read properties of undefined (reading 'string')
|
|
485
|
+
* at runInRunnerObject (workers/runner-worker/index.js:107:3)
|
|
486
|
+
* at getWorkerEntryExportTypes (workers/runner-worker/index.js:246:24)
|
|
487
|
+
* ```
|
|
488
|
+
*
|
|
489
|
+
* The classic cause is a **circular import**: a `lunora/` query/mutation/action
|
|
490
|
+
* module runs `mutation({ args: { x: v.string() } })` at the top level while the
|
|
491
|
+
* module it imported `v`/`query`/`mutation` from is still mid-initialization, so
|
|
492
|
+
* those bindings read as `undefined`. The message names a validator method
|
|
493
|
+
* (`'string'`, `'id'`, …) but never the file.
|
|
494
|
+
*
|
|
495
|
+
* We can't recover the dropped frames at this layer, but we can recognise the
|
|
496
|
+
* shape of the failure and append an actionable hint pointing at the likely
|
|
497
|
+
* cause — turning a dead-end stack into something a user can act on.
|
|
498
|
+
*/
|
|
385
499
|
declare const WORKER_STARTUP_HINT: string;
|
|
386
500
|
/**
|
|
387
|
-
* True when `error` looks like a Worker-entry evaluation failure routed through
|
|
388
|
-
* `@cloudflare/vite-plugin`'s runner worker (the stack references the runner
|
|
389
|
-
* worker / export-types probe). Kept narrow so we only annotate this specific
|
|
390
|
-
* class of dev-startup error.
|
|
391
|
-
*/
|
|
501
|
+
* True when `error` looks like a Worker-entry evaluation failure routed through
|
|
502
|
+
* `@cloudflare/vite-plugin`'s runner worker (the stack references the runner
|
|
503
|
+
* worker / export-types probe). Kept narrow so we only annotate this specific
|
|
504
|
+
* class of dev-startup error.
|
|
505
|
+
*/
|
|
392
506
|
declare const isWorkerEntryEvalError: (error: unknown) => boolean;
|
|
393
507
|
/**
|
|
394
|
-
* Append {@link WORKER_STARTUP_HINT} to a recognised Worker-entry eval error
|
|
395
|
-
* (idempotently). Any other value is returned untouched.
|
|
396
|
-
*/
|
|
508
|
+
* Append {@link WORKER_STARTUP_HINT} to a recognised Worker-entry eval error
|
|
509
|
+
* (idempotently). Any other value is returned untouched.
|
|
510
|
+
*/
|
|
397
511
|
declare const augmentWorkerStartupError: (error: unknown) => unknown;
|
|
398
512
|
/**
|
|
399
|
-
* Wrap the startup hooks of `@cloudflare/vite-plugin`'s plugins so a Worker-entry
|
|
400
|
-
* evaluation failure carries the Lunora hint. Returns a new array; the input
|
|
401
|
-
* plugins are shallow-cloned (never mutated in place) so re-using the cloudflare
|
|
402
|
-
* plugin instances elsewhere stays safe.
|
|
403
|
-
*/
|
|
513
|
+
* Wrap the startup hooks of `@cloudflare/vite-plugin`'s plugins so a Worker-entry
|
|
514
|
+
* evaluation failure carries the Lunora hint. Returns a new array; the input
|
|
515
|
+
* plugins are shallow-cloned (never mutated in place) so re-using the cloudflare
|
|
516
|
+
* plugin instances elsewhere stays safe.
|
|
517
|
+
*/
|
|
404
518
|
declare const withWorkerStartupHint: (plugins: ReadonlyArray<Plugin>) => Plugin[];
|
|
405
519
|
/**
|
|
406
|
-
* Vite plugin that validates the project's `wrangler.jsonc` against the
|
|
407
|
-
* bindings implied by `lunora/schema.ts`. Throws (Vite renders nicely) on
|
|
408
|
-
* missing requirements during `configResolved`. Delegates the parsing /
|
|
409
|
-
* validation logic to `@lunora/config` so the rules stay in lockstep with
|
|
410
|
-
* the CLI (`lunora deploy`).
|
|
411
|
-
|
|
520
|
+
* Vite plugin that validates the project's `wrangler.jsonc` against the
|
|
521
|
+
* bindings implied by `lunora/schema.ts`. Throws (Vite renders nicely) on
|
|
522
|
+
* missing requirements during `configResolved`. Delegates the parsing /
|
|
523
|
+
* validation logic to `@lunora/config` so the rules stay in lockstep with
|
|
524
|
+
* the CLI (`lunora deploy`).
|
|
525
|
+
*
|
|
526
|
+
* Provisioning runs BEFORE this, in `bindingsProvisionPlugin`'s `config` hook,
|
|
527
|
+
* which is the order `lunora dev` uses (infer → reconcile, no validation pass):
|
|
528
|
+
* the bindings this check requires are the ones Lunora writes itself, so
|
|
529
|
+
* validating first killed the dev server the first time a project declared a
|
|
530
|
+
* `.global()` table or a container. That plugin is registered unconditionally and
|
|
531
|
+
* ahead of this one — the write is not optional the way the check is, and it must
|
|
532
|
+
* land in `config` to reach the worker at all (see its docblock).
|
|
533
|
+
*
|
|
534
|
+
* Skipped under `vite preview`, which resolves with `command: "serve"` and so
|
|
535
|
+
* runs `apply: "serve"` plugins: previewing a built app must not probe Docker.
|
|
536
|
+
*/
|
|
412
537
|
declare const wranglerValidatorPlugin: (options: ResolvedLunoraPluginOptions) => Plugin;
|
|
413
538
|
/**
|
|
414
|
-
* Resolve the `overlay` toggle into the overlay plugin's options — or `false` to
|
|
415
|
-
* skip it. Lunora's solution finders are **prepended** so they run before the
|
|
416
|
-
* overlay's built-ins; a user's own finders are appended and can still win per
|
|
417
|
-
* error via a strictly higher `priority` (equal priority keeps Lunora first,
|
|
418
|
-
* since the overlay sorts stably). Lunora also forwards both `error` AND `warn`
|
|
419
|
-
* console calls by default (the overlay's own default is `["error"]` only) so
|
|
420
|
-
* Lunora's branded `warn` advisories surface in the browser too — the user can
|
|
421
|
-
* override `forwardedConsoleMethods`.
|
|
422
|
-
*/
|
|
539
|
+
* Resolve the `overlay` toggle into the overlay plugin's options — or `false` to
|
|
540
|
+
* skip it. Lunora's solution finders are **prepended** so they run before the
|
|
541
|
+
* overlay's built-ins; a user's own finders are appended and can still win per
|
|
542
|
+
* error via a strictly higher `priority` (equal priority keeps Lunora first,
|
|
543
|
+
* since the overlay sorts stably). Lunora also forwards both `error` AND `warn`
|
|
544
|
+
* console calls by default (the overlay's own default is `["error"]` only) so
|
|
545
|
+
* Lunora's branded `warn` advisories surface in the browser too — the user can
|
|
546
|
+
* override `forwardedConsoleMethods`.
|
|
547
|
+
*/
|
|
423
548
|
declare const resolveOverlayOption: (overlay: LunoraPluginOptions["overlay"]) => false | OverlayPluginOptions;
|
|
424
549
|
/**
|
|
425
|
-
* Lunora Vite plugin. Returns a flat array of Vite plugins that:
|
|
426
|
-
*
|
|
427
|
-
* 1. Run `@lunora/codegen` on startup + on schema file changes.
|
|
428
|
-
* 2. Validate the project's `wrangler.jsonc` against the schema's implied bindings.
|
|
429
|
-
* 3. Inject `@visulima/vite-overlay` for runtime error overlays (unless `overlay: false`).
|
|
430
|
-
* 4. Include `@cloudflare/vite-plugin` so users get one-import setup (unless `cloudflare: false`).
|
|
431
|
-
*
|
|
432
|
-
* `@cloudflare/vite-plugin` and `@visulima/vite-overlay` are direct dependencies,
|
|
433
|
-
* so they're imported statically — opt out per-feature via the options rather
|
|
434
|
-
* than relying on whether they're installed.
|
|
435
|
-
*/
|
|
550
|
+
* Lunora Vite plugin. Returns a flat array of Vite plugins that:
|
|
551
|
+
*
|
|
552
|
+
* 1. Run `@lunora/codegen` on startup + on schema file changes.
|
|
553
|
+
* 2. Validate the project's `wrangler.jsonc` against the schema's implied bindings.
|
|
554
|
+
* 3. Inject `@visulima/vite-overlay` for runtime error overlays (unless `overlay: false`).
|
|
555
|
+
* 4. Include `@cloudflare/vite-plugin` so users get one-import setup (unless `cloudflare: false`).
|
|
556
|
+
*
|
|
557
|
+
* `@cloudflare/vite-plugin` and `@visulima/vite-overlay` are direct dependencies,
|
|
558
|
+
* so they're imported statically — opt out per-feature via the options rather
|
|
559
|
+
* than relying on whether they're installed.
|
|
560
|
+
*/
|
|
436
561
|
declare const lunora: (options?: LunoraPluginOptions) => LunoraPlugins;
|
|
437
|
-
declare const VERSION
|
|
438
|
-
export { CLASS_A_WIRING, type ClassAWiring, type CloudflarePluginOptions,
|
|
562
|
+
declare const VERSION: string;
|
|
563
|
+
export { CLASS_A_WIRING, type ClassAWiring, type CloudflarePluginOptions, LUNORA_API_UPDATED_EVENT, LUNORA_WORKER_VIRTUAL_ID, type LunoraPluginOptions, type LunoraPlugins, type LunoraShardConfig, type OverlayPluginOptions, type PlanViteRemoteOptions, type ResolvedLunoraPluginOptions, type Solution, type SolutionFinder, VERSION, type ViteRemotePlan, WORKER_STARTUP_HINT, type WorkerEntryComposition, augmentWorkerStartupError, buildStudioUrl, buildWorkerEntrySource, checkLunoraProxy, codegenPlugin, containerLogsPlugin, devStatePlugin, devVariablesPlugin, frameworkComposePlugin, isAutoComposable, isWorkerEntryEvalError, logStreamPlugin, lunora, lunoraSolutionFinder, lunoraSolutionFinders, planViteRemoteBindings, proxyCheckPlugin, remoteBindingsPlugin, resolveOverlayOption, studioPlugin, withRemoteBindings, withWorkerStartupHint, wranglerValidatorPlugin };
|