@lunora/nuxt 1.0.0-alpha.14 → 1.0.0-alpha.140
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 +25 -14
- package/dist/module.d.mts +76 -7
- package/dist/module.d.ts +78 -0
- package/dist/module.json +2 -6
- package/dist/module.mjs +1 -29
- package/dist/runtime/cloudflare.d.mts +36 -0
- package/dist/runtime/cloudflare.d.ts +28 -16
- package/dist/runtime/cloudflare.mjs +1 -0
- package/dist/runtime/h3-request.d.mts +18 -0
- package/dist/runtime/h3-request.d.ts +15 -3
- package/dist/runtime/h3-request.mjs +1 -0
- package/dist/runtime/handler.d.mts +19 -0
- package/dist/runtime/handler.d.ts +16 -5
- package/dist/runtime/handler.mjs +1 -0
- package/dist/runtime/server/lunora.d.mts +92 -0
- package/dist/runtime/server/lunora.d.ts +92 -3
- package/dist/runtime/server/lunora.mjs +1 -0
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.mjs +1 -1
- package/package.json +9 -8
- package/dist/runtime/cloudflare.js +0 -12
- package/dist/runtime/h3-request.js +0 -2
- package/dist/runtime/handler.js +0 -17
- package/dist/runtime/server/lunora.js +0 -10
- package/dist/types.d.mts +0 -7
package/LICENSE.md
CHANGED
|
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
|
103
103
|
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
104
|
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
105
|
specific language governing permissions and limitations under the License.
|
|
106
|
+
|
|
107
|
+
<!-- DEPENDENCIES -->
|
|
108
|
+
<!-- /DEPENDENCIES -->
|
|
109
|
+
|
|
110
|
+
<!-- TYPE_DEPENDENCIES -->
|
|
111
|
+
<!-- /TYPE_DEPENDENCIES -->
|
package/README.md
CHANGED
|
@@ -59,37 +59,47 @@ export default defineNuxtConfig({
|
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Add `
|
|
63
|
-
class is exported from the
|
|
62
|
+
Add a `worker.ts` wrapper at the project root and point `wrangler.jsonc`'s `main`
|
|
63
|
+
at it, so the `ShardDO` Durable Object class is exported from the deployed worker.
|
|
64
|
+
Nitro's `cloudflare_module` output exports only the SSR handler, so `main` must
|
|
65
|
+
point at the wrapper — not the raw `.output/server/index.mjs` — or `wrangler deploy`
|
|
66
|
+
fails on the missing DO class:
|
|
64
67
|
|
|
65
68
|
```ts
|
|
66
|
-
//
|
|
69
|
+
// worker.ts
|
|
70
|
+
export { default } from "./.output/server/index.mjs";
|
|
67
71
|
export { ShardDO } from "./lunora/server";
|
|
68
72
|
```
|
|
69
73
|
|
|
74
|
+
```jsonc
|
|
75
|
+
// wrangler.jsonc
|
|
76
|
+
{ "main": "worker.ts" }
|
|
77
|
+
```
|
|
78
|
+
|
|
70
79
|
`lunora/server.ts` is your built Lunora app (`defineApp().build()`) — its default
|
|
71
80
|
export is the worker (a `fetch` entrypoint), and it re-exports `ShardDO`. The
|
|
72
81
|
module aliases the `#lunora/app` virtual to it (configurable via the `lunora.appEntry`
|
|
73
|
-
option, default `~/lunora/server`) and serves it at the `/_lunora/**` route
|
|
74
|
-
(prefix configurable via `lunora.prefix`).
|
|
82
|
+
option, default `~/lunora/server`) and serves it at the `/_lunora/**` route.
|
|
75
83
|
|
|
76
84
|
## Options
|
|
77
85
|
|
|
78
86
|
| Option | Default | Description |
|
|
79
87
|
| ---------- | ----------------- | --------------------------------------------------------- |
|
|
80
88
|
| `appEntry` | `~/lunora/server` | Module specifier of the Lunora app entry (`#lunora/app`). |
|
|
81
|
-
|
|
89
|
+
|
|
90
|
+
The `/_lunora/**` mount is fixed: the worker routes on those exact paths and the
|
|
91
|
+
generated client calls them.
|
|
82
92
|
|
|
83
93
|
## How it works
|
|
84
94
|
|
|
85
|
-
- **The route** (`addServerHandler` at
|
|
95
|
+
- **The route** (`addServerHandler` at `/_lunora/**`): reconstructs a Web `Request`
|
|
86
96
|
from the H3 event, resolves the Cloudflare `env`/`ExecutionContext` off it
|
|
87
97
|
(tolerating both `event.context.cloudflare` and `event.req.runtime.cloudflare`),
|
|
88
98
|
and forwards to your app's `fetch`. A missing Cloudflare runtime answers a clear 500.
|
|
89
99
|
- **`#lunora/app` alias**: points the route's worker import at your app entry,
|
|
90
100
|
forwarded into the Nitro server bundle via `nuxt.options.alias`.
|
|
91
|
-
- **`ShardDO`** rides to the worker
|
|
92
|
-
(
|
|
101
|
+
- **`ShardDO`** rides to the deployed worker through your root `worker.ts` wrapper
|
|
102
|
+
(`wrangler.jsonc`'s `main`), which re-exports Nitro's SSR handler and `ShardDO`.
|
|
93
103
|
|
|
94
104
|
## Verify before deploy
|
|
95
105
|
|
|
@@ -102,11 +112,12 @@ Single-worker composition rides on two Nitro behaviours that vary across version
|
|
|
102
112
|
subscriptions never connect while RPC does, Nitro is normalising the upgrade
|
|
103
113
|
response and `/_lunora/ws` needs a deploy-boundary handoff instead of the H3
|
|
104
114
|
route return.
|
|
105
|
-
2. **`
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
module `warn()`s when
|
|
115
|
+
2. **`worker.ts` wrapper.** `wrangler.jsonc`'s `main` must point at a root
|
|
116
|
+
`worker.ts` that re-exports Nitro's SSR handler _and_ `ShardDO` — Nitro's
|
|
117
|
+
`cloudflare_module` output exports only the SSR handler. If `wrangler deploy`
|
|
118
|
+
fails with "ShardDO class not exported", check that `main` points at the
|
|
119
|
+
wrapper and that it re-exports `ShardDO`. The module `warn()`s when
|
|
120
|
+
`worker.ts` is missing but can't verify wrangler's `main` points at it.
|
|
110
121
|
|
|
111
122
|
## Server data-loading
|
|
112
123
|
|
package/dist/module.d.mts
CHANGED
|
@@ -1,9 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { defineNuxtModule } from '@nuxt/kit';
|
|
2
|
+
/**
|
|
3
|
+
* Check that `worker.ts` at the project root actually re-exports `ShardDO` —
|
|
4
|
+
* not just that the file exists. Extracted from `setup()` so it is testable
|
|
5
|
+
* without booting Nuxt (`defineNuxtModule`'s `setup` needs full Nuxt Kit
|
|
6
|
+
* scaffolding to invoke; this plain function does not).
|
|
7
|
+
*
|
|
8
|
+
* All three outcomes — missing file, unreadable file, present-but-no-`ShardDO`-
|
|
9
|
+
* export — WARN and return; none of them throws. Matches the module's existing
|
|
10
|
+
* stance ("we can't write the user's file, so warn... rather than fail an
|
|
11
|
+
* otherwise-valid build") and the `@lunora/astro` precedent this mirrors.
|
|
12
|
+
*/
|
|
13
|
+
declare const checkWorkerEntry: (rootDirectory: string, warn: (message: string) => void) => void;
|
|
14
|
+
/**
|
|
15
|
+
* One entry of Nuxt's resolved plugin list (`app.plugins` at `app:resolve`):
|
|
16
|
+
* an absolute `src` plus the `mode` Nuxt derived for it. Declared structurally
|
|
17
|
+
* for the same reason as {@link LunoraNuxtModule} — `@nuxt/schema`, which owns
|
|
18
|
+
* `NuxtPlugin`, is not a resolvable dependency here — and `NuxtPlugin[]`
|
|
19
|
+
* satisfies it.
|
|
20
|
+
*/
|
|
21
|
+
interface ResolvedNuxtPlugin {
|
|
22
|
+
mode?: "all" | "client" | "server";
|
|
23
|
+
src: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Warn when the project's ONLY `LunoraClient` provider is a client-only plugin.
|
|
27
|
+
*
|
|
28
|
+
* `@lunora/vue`'s composables call `useLunora()` unconditionally — ahead of
|
|
29
|
+
* their own browser guard — and it throws when nothing is injected. A
|
|
30
|
+
* `plugins/lunora.client.ts` by definition never runs on the server, so the
|
|
31
|
+
* first server-rendered page touching Lunora answers 500 with
|
|
32
|
+
* `useLunora(): no LunoraClient provided`. The fix is dropping `.client` from
|
|
33
|
+
* the filename plus a universal way to read the origin, which the warning says.
|
|
34
|
+
*
|
|
35
|
+
* Takes Nuxt's own resolved plugin list (`app.plugins`, from the `app:resolve`
|
|
36
|
+
* hook) rather than scanning `plugins/` itself. That is the whole point: Nuxt
|
|
37
|
+
* loads plugins with a two-pattern, ONE-level glob — top-level entries plus a
|
|
38
|
+
* subdirectory's `index` file — over every layer's configured plugins dir, so
|
|
39
|
+
* a filesystem scan of its own has to mirror the glob, the extension list,
|
|
40
|
+
* `dir.plugins` and every layer — and gets the answer WRONG in both directions
|
|
41
|
+
* when it doesn't. A recursive scan counts `plugins/lib/make-client.ts` (an
|
|
42
|
+
* ordinary colocated helper Nuxt never loads) as a universal provider and goes
|
|
43
|
+
* silent on a genuinely broken app. Reading `mode` off the resolved entry also
|
|
44
|
+
* drops the `.client` filename rule, since that is what Nuxt derived it from.
|
|
45
|
+
*
|
|
46
|
+
* Detection of the provider itself is the same shape as
|
|
47
|
+
* {@link looksLikeShardDoExport}: a documented keyword test, not a TS parse,
|
|
48
|
+
* because the outcome is a build-time warning. Its imprecision is a
|
|
49
|
+
* `createLunora` mention inside a comment, whose only cost is a warning
|
|
50
|
+
* pointing at a file that is already about the client.
|
|
51
|
+
*
|
|
52
|
+
* Silence requires a provider Nuxt loads on the server — `mode` `"all"` or
|
|
53
|
+
* `"server"` — not merely a working app: an app that confines every Lunora
|
|
54
|
+
* usage to `<ClientOnly>` is correct with a client-only provider and still
|
|
55
|
+
* warns, which is why the message names that case as a reason to ignore it.
|
|
56
|
+
*/
|
|
57
|
+
declare const checkClientOnlyProvider: (plugins: ReadonlyArray<ResolvedNuxtPlugin>, warn: (message: string) => void) => void;
|
|
58
|
+
/** Options for the `@lunora/nuxt` module (configurable under the `lunora` key in `nuxt.config`). */
|
|
3
59
|
interface ModuleOptions {
|
|
4
|
-
|
|
5
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Module specifier of the Lunora app entry — its default export is the built
|
|
62
|
+
* worker (`defineApp().build()` / `createWorker(...)`) and it re-exports
|
|
63
|
+
* `ShardDO`. Aliased to the `#lunora/app` virtual the server route imports.
|
|
64
|
+
*/
|
|
65
|
+
appEntry: string;
|
|
6
66
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Return type of `defineNuxtModule<ModuleOptions>({...})` — the value overload of
|
|
69
|
+
* `defineNuxtModule` (the one taking a definition), extracted structurally so the
|
|
70
|
+
* default export has a locally-nameable type under `isolatedDeclarations` without
|
|
71
|
+
* importing `NuxtModule` from `@nuxt/schema` (not a resolvable dependency here).
|
|
72
|
+
*/
|
|
73
|
+
type LunoraNuxtModule = typeof defineNuxtModule<ModuleOptions> extends {
|
|
74
|
+
(definition: infer _Definition): infer Result;
|
|
75
|
+
(): unknown;
|
|
76
|
+
} ? Result : never;
|
|
77
|
+
declare const lunoraNuxtModule: LunoraNuxtModule;
|
|
78
|
+
export { ModuleOptions, ResolvedNuxtPlugin, checkClientOnlyProvider, checkWorkerEntry, lunoraNuxtModule as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineNuxtModule } from '@nuxt/kit';
|
|
2
|
+
/**
|
|
3
|
+
* Check that `worker.ts` at the project root actually re-exports `ShardDO` —
|
|
4
|
+
* not just that the file exists. Extracted from `setup()` so it is testable
|
|
5
|
+
* without booting Nuxt (`defineNuxtModule`'s `setup` needs full Nuxt Kit
|
|
6
|
+
* scaffolding to invoke; this plain function does not).
|
|
7
|
+
*
|
|
8
|
+
* All three outcomes — missing file, unreadable file, present-but-no-`ShardDO`-
|
|
9
|
+
* export — WARN and return; none of them throws. Matches the module's existing
|
|
10
|
+
* stance ("we can't write the user's file, so warn... rather than fail an
|
|
11
|
+
* otherwise-valid build") and the `@lunora/astro` precedent this mirrors.
|
|
12
|
+
*/
|
|
13
|
+
declare const checkWorkerEntry: (rootDirectory: string, warn: (message: string) => void) => void;
|
|
14
|
+
/**
|
|
15
|
+
* One entry of Nuxt's resolved plugin list (`app.plugins` at `app:resolve`):
|
|
16
|
+
* an absolute `src` plus the `mode` Nuxt derived for it. Declared structurally
|
|
17
|
+
* for the same reason as {@link LunoraNuxtModule} — `@nuxt/schema`, which owns
|
|
18
|
+
* `NuxtPlugin`, is not a resolvable dependency here — and `NuxtPlugin[]`
|
|
19
|
+
* satisfies it.
|
|
20
|
+
*/
|
|
21
|
+
interface ResolvedNuxtPlugin {
|
|
22
|
+
mode?: "all" | "client" | "server";
|
|
23
|
+
src: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Warn when the project's ONLY `LunoraClient` provider is a client-only plugin.
|
|
27
|
+
*
|
|
28
|
+
* `@lunora/vue`'s composables call `useLunora()` unconditionally — ahead of
|
|
29
|
+
* their own browser guard — and it throws when nothing is injected. A
|
|
30
|
+
* `plugins/lunora.client.ts` by definition never runs on the server, so the
|
|
31
|
+
* first server-rendered page touching Lunora answers 500 with
|
|
32
|
+
* `useLunora(): no LunoraClient provided`. The fix is dropping `.client` from
|
|
33
|
+
* the filename plus a universal way to read the origin, which the warning says.
|
|
34
|
+
*
|
|
35
|
+
* Takes Nuxt's own resolved plugin list (`app.plugins`, from the `app:resolve`
|
|
36
|
+
* hook) rather than scanning `plugins/` itself. That is the whole point: Nuxt
|
|
37
|
+
* loads plugins with a two-pattern, ONE-level glob — top-level entries plus a
|
|
38
|
+
* subdirectory's `index` file — over every layer's configured plugins dir, so
|
|
39
|
+
* a filesystem scan of its own has to mirror the glob, the extension list,
|
|
40
|
+
* `dir.plugins` and every layer — and gets the answer WRONG in both directions
|
|
41
|
+
* when it doesn't. A recursive scan counts `plugins/lib/make-client.ts` (an
|
|
42
|
+
* ordinary colocated helper Nuxt never loads) as a universal provider and goes
|
|
43
|
+
* silent on a genuinely broken app. Reading `mode` off the resolved entry also
|
|
44
|
+
* drops the `.client` filename rule, since that is what Nuxt derived it from.
|
|
45
|
+
*
|
|
46
|
+
* Detection of the provider itself is the same shape as
|
|
47
|
+
* {@link looksLikeShardDoExport}: a documented keyword test, not a TS parse,
|
|
48
|
+
* because the outcome is a build-time warning. Its imprecision is a
|
|
49
|
+
* `createLunora` mention inside a comment, whose only cost is a warning
|
|
50
|
+
* pointing at a file that is already about the client.
|
|
51
|
+
*
|
|
52
|
+
* Silence requires a provider Nuxt loads on the server — `mode` `"all"` or
|
|
53
|
+
* `"server"` — not merely a working app: an app that confines every Lunora
|
|
54
|
+
* usage to `<ClientOnly>` is correct with a client-only provider and still
|
|
55
|
+
* warns, which is why the message names that case as a reason to ignore it.
|
|
56
|
+
*/
|
|
57
|
+
declare const checkClientOnlyProvider: (plugins: ReadonlyArray<ResolvedNuxtPlugin>, warn: (message: string) => void) => void;
|
|
58
|
+
/** Options for the `@lunora/nuxt` module (configurable under the `lunora` key in `nuxt.config`). */
|
|
59
|
+
interface ModuleOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Module specifier of the Lunora app entry — its default export is the built
|
|
62
|
+
* worker (`defineApp().build()` / `createWorker(...)`) and it re-exports
|
|
63
|
+
* `ShardDO`. Aliased to the `#lunora/app` virtual the server route imports.
|
|
64
|
+
*/
|
|
65
|
+
appEntry: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Return type of `defineNuxtModule<ModuleOptions>({...})` — the value overload of
|
|
69
|
+
* `defineNuxtModule` (the one taking a definition), extracted structurally so the
|
|
70
|
+
* default export has a locally-nameable type under `isolatedDeclarations` without
|
|
71
|
+
* importing `NuxtModule` from `@nuxt/schema` (not a resolvable dependency here).
|
|
72
|
+
*/
|
|
73
|
+
type LunoraNuxtModule = typeof defineNuxtModule<ModuleOptions> extends {
|
|
74
|
+
(definition: infer _Definition): infer Result;
|
|
75
|
+
(): unknown;
|
|
76
|
+
} ? Result : never;
|
|
77
|
+
declare const lunoraNuxtModule: LunoraNuxtModule;
|
|
78
|
+
export { ModuleOptions, ResolvedNuxtPlugin, checkClientOnlyProvider, checkWorkerEntry, lunoraNuxtModule as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { defineNuxtModule, createResolver, addServerHandler, useLogger } from '@nuxt/kit';
|
|
4
|
-
|
|
5
|
-
const module$1 = defineNuxtModule({
|
|
6
|
-
defaults: {
|
|
7
|
-
appEntry: "~/lunora/server",
|
|
8
|
-
prefix: "/_lunora"
|
|
9
|
-
},
|
|
10
|
-
meta: {
|
|
11
|
-
configKey: "lunora",
|
|
12
|
-
name: "@lunora/nuxt"
|
|
13
|
-
},
|
|
14
|
-
setup(options, nuxt) {
|
|
15
|
-
const resolver = createResolver(import.meta.url);
|
|
16
|
-
nuxt.options.alias["#lunora/app"] = options.appEntry;
|
|
17
|
-
addServerHandler({
|
|
18
|
-
handler: resolver.resolve("./runtime/server/lunora"),
|
|
19
|
-
route: `${options.prefix}/**`
|
|
20
|
-
});
|
|
21
|
-
if (!existsSync(join(nuxt.options.rootDir, "exports.cloudflare.ts"))) {
|
|
22
|
-
useLogger("@lunora/nuxt").warn(
|
|
23
|
-
'missing exports.cloudflare.ts at the project root \u2014 add `export { ShardDO } from "./lunora/server";` so the SHARD Durable Object is exported from the worker.'
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export { module$1 as default };
|
|
1
|
+
import{existsSync as d,readFileSync as c}from"node:fs";import{join as s,resolve as m,dirname as E}from"node:path";import{defineNuxtModule as f,createResolver as g,addServerHandler as v,useLogger as u}from"@nuxt/kit";const S=String.raw`\/\*[\s\S]*?\*\/`,w=String.raw`\/\/[^\n]*`,R=String.raw`"(?:[^"\\\n]|\\.)*"`,O=String.raw`'(?:[^'\\\n]|\\.)*'`,T=String.raw`\x60(?:[^\x60\\$]|\\.|\$(?!\{))*\x60`,h=new RegExp([S,w,R,O,T].join("|"),"gu"),D=/[^\n]/gu,p=e=>e.replaceAll(D," "),i=e=>e.replaceAll(h,p),N=e=>e.replaceAll(h,r=>r.startsWith("//")||r.startsWith("/*")?p(r):r),_=(e,r,o)=>e.startsWith("~~/")?s(r,e.slice(3)):e.startsWith("~/")?s(o,e.slice(2)):e.startsWith("./")||e.startsWith("../")?s(r,e):e,x=/\.js$/,L=e=>{const r=s(e,"lunora");return{name:"lunora:nitro-ts-source-resolve",resolveId:{handler(o,t){if(!o.endsWith(".js"))return;let n;if(o.startsWith("#lunora/")?n=s(r,o.slice(8)):o.startsWith(".")&&t!==void 0&&(n=m(E(t),o)),n===void 0)return;const a=n.replace(x,".ts");return d(a)?a:void 0},order:"pre"}}},l='import nitro from "./.output/server/index.mjs"; import app, { ShardDO } from "./lunora/server"; export { ShardDO }; export default { ...nitro, email: (m, e, x) => app.email?.(m, e, x), queue: (b, e, x) => app.queue?.(b, e, x), scheduled: (c, e, x) => app.scheduled(c, e, x) };',k=/\bexport\b/u,y=/\bShardDO\b/u,A=/\bexport\s*\*\s*from\s*["'][^"']*lunora[^"']*["']/gu,b=e=>{const r=i(e);return[...N(e).matchAll(A)].some(({index:o})=>r[o]===e[o])},I=/\bscheduled\b/u,P=e=>{const r=i(e);return k.test(r)?y.test(r)||b(e):!1},C=(e,r)=>{const o=s(e,"worker.ts");if(!d(o)){r(`missing worker.ts at the project root — add a wrapper that re-exports Nitro's handler and \`ShardDO\` (\`${l}\`) and point wrangler's \`main\` at it, so the SHARD Durable Object is exported from the deployed worker.`);return}let t;try{t=c(o,"utf8")}catch(n){const a=n instanceof Error?n.message:String(n);r(`could not read worker.ts at the project root (${a}) — skipping the \`ShardDO\` export check.`);return}P(t)||r(`worker.ts at the project root does not appear to export \`ShardDO\` — add \`export { ShardDO } from "./lunora/server";\` (e.g. \`${l}\`) and point wrangler's \`main\` at it, so the SHARD Durable Object is exported from the deployed worker.`),I.test(i(t))||r(`worker.ts at the project root does not forward \`scheduled\` — re-exporting Nitro's \`default\` gives Cloudflare a \`scheduled\` entrypoint that only fires an empty \`cloudflare:scheduled\` hook, so a cron declared in \`lunora/crons.ts\` is provisioned and then runs nothing. Compose the two instead (\`${l}\`), which forwards \`queue\` and \`email\` too — Nitro's exports for those fire empty hooks the same way, and a queue consumer that returns without throwing ACKS its batch.`)},W=/\bcreateLunora\b/u,j=e=>{try{return W.test(i(c(e,"utf8")))}catch{return!1}},U=(e,r)=>{const o=e.filter(t=>j(t.src));o.length===0||o.some(t=>t.mode!=="client")||r(`the only plugin providing a \`LunoraClient\` is client-only (${o.map(t=>t.src).join(", ")}) — \`@lunora/vue\`'s composables resolve the client during SSR too and throw \`useLunora(): no LunoraClient provided\` without one, so the first server-rendered page that touches Lunora answers 500. Drop the \`.client\` from the filename to make the plugin universal, and read the origin with \`useRequestURL().origin\`, which resolves from the incoming request on the server and from \`window.location\` in the browser. Ignore this if every Lunora usage is confined to \`<ClientOnly>\`, which never renders on the server.`)},$="/_lunora",K=f({defaults:{appEntry:"~/lunora/server"},meta:{configKey:"lunora",name:"@lunora/nuxt"},setup(e,r){const o=g(import.meta.url);r.options.alias["#lunora/app"]=_(e.appEntry,r.options.rootDir,r.options.srcDir),r.hook("nitro:config",t=>{const n=[...t.rollupConfig?.plugins??[],L(r.options.rootDir)];t.rollupConfig={...t.rollupConfig,plugins:n}}),v({handler:o.resolve("./runtime/server/lunora"),route:`${$}/**`}),C(r.options.rootDir,t=>{u("@lunora/nuxt").warn(t)}),r.hook("app:resolve",t=>{U(t.plugins,n=>{u("@lunora/nuxt").warn(n)})})}});export{U as checkClientOnlyProvider,C as checkWorkerEntry,K as default};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ExecutionContextLike } from '@lunora/runtime';
|
|
2
|
+
export type { ExecutionContextLike } from '@lunora/runtime';
|
|
3
|
+
/** The `{ env, context|ctx }` payload Nitro attaches for the Cloudflare runtime. */
|
|
4
|
+
interface CloudflareEventBag {
|
|
5
|
+
context?: ExecutionContextLike;
|
|
6
|
+
ctx?: ExecutionContextLike;
|
|
7
|
+
env?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Structural view of the bits of an H3 event the resolver reads. Both legacy
|
|
11
|
+
* (`context.cloudflare`) and current (`req.runtime.cloudflare`) shapes are
|
|
12
|
+
* optional so a real H3 `H3Event` is assignable here.
|
|
13
|
+
*/
|
|
14
|
+
interface H3EventLike {
|
|
15
|
+
context?: {
|
|
16
|
+
cloudflare?: CloudflareEventBag;
|
|
17
|
+
};
|
|
18
|
+
req?: {
|
|
19
|
+
runtime?: {
|
|
20
|
+
cloudflare?: CloudflareEventBag;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Resolved Cloudflare runtime for one request: the bindings `env` and the optional `ExecutionContext`. */
|
|
25
|
+
interface ResolvedCloudflare {
|
|
26
|
+
ctx?: ExecutionContextLike;
|
|
27
|
+
env?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Pull the Cloudflare `env` + `ExecutionContext` off a Nitro/H3 event, checking
|
|
31
|
+
* the legacy `event.context.cloudflare` shape first (present under
|
|
32
|
+
* `nitro-cloudflare-dev` in dev) and the newer `event.req.runtime.cloudflare`
|
|
33
|
+
* shape second. Returns `{}` when neither is present.
|
|
34
|
+
*/
|
|
35
|
+
declare const resolveCloudflare: (event: H3EventLike) => ResolvedCloudflare;
|
|
36
|
+
export { type H3EventLike, type ResolvedCloudflare, resolveCloudflare };
|
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExecutionContextLike } from '@lunora/runtime';
|
|
2
|
+
export type { ExecutionContextLike } from '@lunora/runtime';
|
|
3
|
+
/** The `{ env, context|ctx }` payload Nitro attaches for the Cloudflare runtime. */
|
|
2
4
|
interface CloudflareEventBag {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
context?: ExecutionContextLike;
|
|
6
|
+
ctx?: ExecutionContextLike;
|
|
7
|
+
env?: Record<string, unknown>;
|
|
6
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Structural view of the bits of an H3 event the resolver reads. Both legacy
|
|
11
|
+
* (`context.cloudflare`) and current (`req.runtime.cloudflare`) shapes are
|
|
12
|
+
* optional so a real H3 `H3Event` is assignable here.
|
|
13
|
+
*/
|
|
7
14
|
interface H3EventLike {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
+
context?: {
|
|
16
|
+
cloudflare?: CloudflareEventBag;
|
|
17
|
+
};
|
|
18
|
+
req?: {
|
|
19
|
+
runtime?: {
|
|
20
|
+
cloudflare?: CloudflareEventBag;
|
|
15
21
|
};
|
|
22
|
+
};
|
|
16
23
|
}
|
|
24
|
+
/** Resolved Cloudflare runtime for one request: the bindings `env` and the optional `ExecutionContext`. */
|
|
17
25
|
interface ResolvedCloudflare {
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
ctx?: ExecutionContextLike;
|
|
27
|
+
env?: Record<string, unknown>;
|
|
20
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Pull the Cloudflare `env` + `ExecutionContext` off a Nitro/H3 event, checking
|
|
31
|
+
* the legacy `event.context.cloudflare` shape first (present under
|
|
32
|
+
* `nitro-cloudflare-dev` in dev) and the newer `event.req.runtime.cloudflare`
|
|
33
|
+
* shape second. Returns `{}` when neither is present.
|
|
34
|
+
*/
|
|
21
35
|
declare const resolveCloudflare: (event: H3EventLike) => ResolvedCloudflare;
|
|
22
|
-
export type
|
|
23
|
-
export { resolveCloudflare };
|
|
24
|
-
export { type ExecutionContextLike } from "../../../../shared/execution-context.js";
|
|
36
|
+
export { type H3EventLike, type ResolvedCloudflare, resolveCloudflare };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=n=>{const e=n.context?.cloudflare;if(e?.env)return{ctx:e.context??e.ctx,env:e.env};const t=n.req?.runtime?.cloudflare;return t?.env?{ctx:t.ctx??t.context,env:t.env}:{}};export{r as resolveCloudflare};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the inbound web `Request` from an H3 event across the h3 v1 → v2 break.
|
|
3
|
+
*
|
|
4
|
+
* v1 exposes `toWebRequest(event)`; the v2 web-standards rewrite removed it and
|
|
5
|
+
* carries the web `Request` directly as `event.req`. The `@lunora/nuxt` peer is
|
|
6
|
+
* `h3: "^1.15.0"` (v1 — what Nuxt 4 / Nitro 2 run today); the v2 `event.req`
|
|
7
|
+
* branch is forward-compat for when a stable h3 v2 ships and the peer widens. We
|
|
8
|
+
* feature-detect `toWebRequest` at runtime rather than importing it statically —
|
|
9
|
+
* a named `import { toWebRequest }` would throw at module-eval under v2 (missing export).
|
|
10
|
+
*
|
|
11
|
+
* Kept as a pure helper (the `h3` namespace + event in, a `Request` out) so both
|
|
12
|
+
* branches are unit-tested without booting Nitro or installing a second h3 major.
|
|
13
|
+
*/
|
|
14
|
+
interface H3RequestNamespace {
|
|
15
|
+
toWebRequest?: unknown;
|
|
16
|
+
}
|
|
17
|
+
declare const resolveWebRequest: (h3: H3RequestNamespace, event: unknown) => Request;
|
|
18
|
+
export { type H3RequestNamespace, resolveWebRequest };
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the inbound web `Request` from an H3 event across the h3 v1 → v2 break.
|
|
3
|
+
*
|
|
4
|
+
* v1 exposes `toWebRequest(event)`; the v2 web-standards rewrite removed it and
|
|
5
|
+
* carries the web `Request` directly as `event.req`. The `@lunora/nuxt` peer is
|
|
6
|
+
* `h3: "^1.15.0"` (v1 — what Nuxt 4 / Nitro 2 run today); the v2 `event.req`
|
|
7
|
+
* branch is forward-compat for when a stable h3 v2 ships and the peer widens. We
|
|
8
|
+
* feature-detect `toWebRequest` at runtime rather than importing it statically —
|
|
9
|
+
* a named `import { toWebRequest }` would throw at module-eval under v2 (missing export).
|
|
10
|
+
*
|
|
11
|
+
* Kept as a pure helper (the `h3` namespace + event in, a `Request` out) so both
|
|
12
|
+
* branches are unit-tested without booting Nitro or installing a second h3 major.
|
|
13
|
+
*/
|
|
1
14
|
interface H3RequestNamespace {
|
|
2
|
-
|
|
15
|
+
toWebRequest?: unknown;
|
|
3
16
|
}
|
|
4
17
|
declare const resolveWebRequest: (h3: H3RequestNamespace, event: unknown) => Request;
|
|
5
|
-
export type
|
|
6
|
-
export { resolveWebRequest };
|
|
18
|
+
export { type H3RequestNamespace, resolveWebRequest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=(e,t)=>typeof e.toWebRequest=="function"?e.toWebRequest(t):t.req;export{o as resolveWebRequest};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExecutionContextLike } from '@lunora/runtime';
|
|
2
|
+
export { NOOP_EXECUTION_CONTEXT } from '@lunora/runtime';
|
|
3
|
+
/**
|
|
4
|
+
* Structural view of the Lunora worker the route delegates to — just the
|
|
5
|
+
* `fetch` entrypoint. Both `createWorker(...)` and the generated
|
|
6
|
+
* `defineApp().build()` app satisfy it (a `ComposedApp` is a superset). Declared
|
|
7
|
+
* locally so `@lunora/nuxt` doesn't hard-depend on `@lunora/runtime`'s worker type.
|
|
8
|
+
*/
|
|
9
|
+
interface LunoraWorkerLike {
|
|
10
|
+
fetch: (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Forward one inbound request to the Lunora worker. `env` must be the Cloudflare
|
|
14
|
+
* bindings (carrying the `SHARD` Durable Object namespace); when it is missing
|
|
15
|
+
* the Cloudflare runtime wasn't available (e.g. a non-CF preview), so we answer
|
|
16
|
+
* a clear 500 rather than handing the worker an `undefined` env.
|
|
17
|
+
*/
|
|
18
|
+
declare const delegateToLunora: (worker: LunoraWorkerLike, request: Request, env: Record<string, unknown> | undefined, context?: ExecutionContextLike) => Promise<Response>;
|
|
19
|
+
export { type LunoraWorkerLike, delegateToLunora };
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExecutionContextLike } from '@lunora/runtime';
|
|
2
|
+
export { NOOP_EXECUTION_CONTEXT } from '@lunora/runtime';
|
|
3
|
+
/**
|
|
4
|
+
* Structural view of the Lunora worker the route delegates to — just the
|
|
5
|
+
* `fetch` entrypoint. Both `createWorker(...)` and the generated
|
|
6
|
+
* `defineApp().build()` app satisfy it (a `ComposedApp` is a superset). Declared
|
|
7
|
+
* locally so `@lunora/nuxt` doesn't hard-depend on `@lunora/runtime`'s worker type.
|
|
8
|
+
*/
|
|
2
9
|
interface LunoraWorkerLike {
|
|
3
|
-
|
|
10
|
+
fetch: (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
|
|
4
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Forward one inbound request to the Lunora worker. `env` must be the Cloudflare
|
|
14
|
+
* bindings (carrying the `SHARD` Durable Object namespace); when it is missing
|
|
15
|
+
* the Cloudflare runtime wasn't available (e.g. a non-CF preview), so we answer
|
|
16
|
+
* a clear 500 rather than handing the worker an `undefined` env.
|
|
17
|
+
*/
|
|
5
18
|
declare const delegateToLunora: (worker: LunoraWorkerLike, request: Request, env: Record<string, unknown> | undefined, context?: ExecutionContextLike) => Promise<Response>;
|
|
6
|
-
export type
|
|
7
|
-
export { delegateToLunora };
|
|
8
|
-
export { NOOP_EXECUTION_CONTEXT } from "../../../../shared/execution-context.js";
|
|
19
|
+
export { type LunoraWorkerLike, delegateToLunora };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{NOOP_EXECUTION_CONTEXT as n}from"@lunora/runtime";import{NOOP_EXECUTION_CONTEXT as l}from"@lunora/runtime";const s=async(o,r,e,t)=>e?o.fetch(r,e,t??n):Response.json({error:{code:"LUNORA_RUNTIME_UNAVAILABLE",message:"Lunora could not read the Cloudflare bindings from the request. The `/_lunora/**` route only works on the Cloudflare Workers runtime (deployed, or `nuxt dev` with `nitro-cloudflare-dev`)."}},{status:500});export{l as NOOP_EXECUTION_CONTEXT,s as delegateToLunora};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { QueryObject } from 'ufo';
|
|
2
|
+
import { Hooks } from 'crossws';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
interface NodeEventContext {
|
|
5
|
+
req: IncomingMessage & {
|
|
6
|
+
originalUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
res: ServerResponse;
|
|
9
|
+
}
|
|
10
|
+
interface WebEventContext {
|
|
11
|
+
request?: Request;
|
|
12
|
+
url?: URL;
|
|
13
|
+
}
|
|
14
|
+
declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> {
|
|
15
|
+
"__is_event__": boolean;
|
|
16
|
+
node: NodeEventContext;
|
|
17
|
+
web?: WebEventContext;
|
|
18
|
+
context: H3EventContext;
|
|
19
|
+
_method?: HTTPMethod;
|
|
20
|
+
_path?: string;
|
|
21
|
+
_headers?: Headers;
|
|
22
|
+
_requestBody?: BodyInit;
|
|
23
|
+
_handled: boolean;
|
|
24
|
+
_onBeforeResponseCalled: boolean | undefined;
|
|
25
|
+
_onAfterResponseCalled: boolean | undefined;
|
|
26
|
+
constructor(req: IncomingMessage, res: ServerResponse);
|
|
27
|
+
get method(): HTTPMethod;
|
|
28
|
+
get path(): string;
|
|
29
|
+
get headers(): Headers;
|
|
30
|
+
get handled(): boolean;
|
|
31
|
+
respondWith(response: Response | PromiseLike<Response>): Promise<void>;
|
|
32
|
+
toString(): string;
|
|
33
|
+
toJSON(): string;
|
|
34
|
+
/** @deprecated Please use `event.node.req` instead. */
|
|
35
|
+
get req(): IncomingMessage & {
|
|
36
|
+
originalUrl?: string;
|
|
37
|
+
};
|
|
38
|
+
/** @deprecated Please use `event.node.res` instead. */
|
|
39
|
+
get res(): ServerResponse<IncomingMessage>;
|
|
40
|
+
}
|
|
41
|
+
type SessionDataT = Record<string, any>;
|
|
42
|
+
type SessionData<T extends SessionDataT = SessionDataT> = T;
|
|
43
|
+
declare const getSessionPromise: unique symbol;
|
|
44
|
+
interface Session<T extends SessionDataT = SessionDataT> {
|
|
45
|
+
id: string;
|
|
46
|
+
createdAt: number;
|
|
47
|
+
data: SessionData<T>;
|
|
48
|
+
[getSessionPromise]?: Promise<Session<T>>;
|
|
49
|
+
}
|
|
50
|
+
type RouterMethod = Lowercase<HTTPMethod>;
|
|
51
|
+
interface RouteNode {
|
|
52
|
+
handlers: Partial<Record<RouterMethod | "all", EventHandler>>;
|
|
53
|
+
path: string;
|
|
54
|
+
}
|
|
55
|
+
type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
|
|
56
|
+
interface H3EventContext extends Record<string, any> {
|
|
57
|
+
params?: Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* Matched router Node
|
|
60
|
+
*
|
|
61
|
+
* @experimental The object structure may change in non-major version.
|
|
62
|
+
*/
|
|
63
|
+
matchedRoute?: RouteNode;
|
|
64
|
+
sessions?: Record<string, Session>;
|
|
65
|
+
clientAddress?: string;
|
|
66
|
+
}
|
|
67
|
+
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
68
|
+
interface EventHandlerRequest {
|
|
69
|
+
body?: any;
|
|
70
|
+
query?: QueryObject;
|
|
71
|
+
routerParams?: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
74
|
+
type EventHandlerResolver = (path: string) => MaybePromise<undefined | {
|
|
75
|
+
route?: string;
|
|
76
|
+
handler: EventHandler;
|
|
77
|
+
}>;
|
|
78
|
+
interface EventHandler<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> {
|
|
79
|
+
__is_handler__?: true;
|
|
80
|
+
__resolve__?: EventHandlerResolver;
|
|
81
|
+
__websocket__?: Partial<Hooks>;
|
|
82
|
+
(event: H3Event<Request>): Response;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Forward `/_lunora/**` to the Lunora worker. We reconstruct a Web `Request`
|
|
86
|
+
* from the H3 event (Lunora speaks the Web Fetch contract — RPC bodies and the
|
|
87
|
+
* WebSocket `Upgrade` handshake), resolve the Cloudflare `env`/`ExecutionContext`
|
|
88
|
+
* off the event, and return the worker's `Response` verbatim (H3 streams it,
|
|
89
|
+
* including a `101 Switching Protocols` upgrade with its `webSocket`).
|
|
90
|
+
*/
|
|
91
|
+
declare const lunoraEventHandler: EventHandler;
|
|
92
|
+
export { lunoraEventHandler as default };
|
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { QueryObject } from 'ufo';
|
|
2
|
+
import { Hooks } from 'crossws';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
interface NodeEventContext {
|
|
5
|
+
req: IncomingMessage & {
|
|
6
|
+
originalUrl?: string;
|
|
7
|
+
};
|
|
8
|
+
res: ServerResponse;
|
|
9
|
+
}
|
|
10
|
+
interface WebEventContext {
|
|
11
|
+
request?: Request;
|
|
12
|
+
url?: URL;
|
|
13
|
+
}
|
|
14
|
+
declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> {
|
|
15
|
+
"__is_event__": boolean;
|
|
16
|
+
node: NodeEventContext;
|
|
17
|
+
web?: WebEventContext;
|
|
18
|
+
context: H3EventContext;
|
|
19
|
+
_method?: HTTPMethod;
|
|
20
|
+
_path?: string;
|
|
21
|
+
_headers?: Headers;
|
|
22
|
+
_requestBody?: BodyInit;
|
|
23
|
+
_handled: boolean;
|
|
24
|
+
_onBeforeResponseCalled: boolean | undefined;
|
|
25
|
+
_onAfterResponseCalled: boolean | undefined;
|
|
26
|
+
constructor(req: IncomingMessage, res: ServerResponse);
|
|
27
|
+
get method(): HTTPMethod;
|
|
28
|
+
get path(): string;
|
|
29
|
+
get headers(): Headers;
|
|
30
|
+
get handled(): boolean;
|
|
31
|
+
respondWith(response: Response | PromiseLike<Response>): Promise<void>;
|
|
32
|
+
toString(): string;
|
|
33
|
+
toJSON(): string;
|
|
34
|
+
/** @deprecated Please use `event.node.req` instead. */
|
|
35
|
+
get req(): IncomingMessage & {
|
|
36
|
+
originalUrl?: string;
|
|
37
|
+
};
|
|
38
|
+
/** @deprecated Please use `event.node.res` instead. */
|
|
39
|
+
get res(): ServerResponse<IncomingMessage>;
|
|
40
|
+
}
|
|
41
|
+
type SessionDataT = Record<string, any>;
|
|
42
|
+
type SessionData<T extends SessionDataT = SessionDataT> = T;
|
|
43
|
+
declare const getSessionPromise: unique symbol;
|
|
44
|
+
interface Session<T extends SessionDataT = SessionDataT> {
|
|
45
|
+
id: string;
|
|
46
|
+
createdAt: number;
|
|
47
|
+
data: SessionData<T>;
|
|
48
|
+
[getSessionPromise]?: Promise<Session<T>>;
|
|
49
|
+
}
|
|
50
|
+
type RouterMethod = Lowercase<HTTPMethod>;
|
|
51
|
+
interface RouteNode {
|
|
52
|
+
handlers: Partial<Record<RouterMethod | "all", EventHandler>>;
|
|
53
|
+
path: string;
|
|
54
|
+
}
|
|
55
|
+
type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
|
|
56
|
+
interface H3EventContext extends Record<string, any> {
|
|
57
|
+
params?: Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* Matched router Node
|
|
60
|
+
*
|
|
61
|
+
* @experimental The object structure may change in non-major version.
|
|
62
|
+
*/
|
|
63
|
+
matchedRoute?: RouteNode;
|
|
64
|
+
sessions?: Record<string, Session>;
|
|
65
|
+
clientAddress?: string;
|
|
66
|
+
}
|
|
67
|
+
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
68
|
+
interface EventHandlerRequest {
|
|
69
|
+
body?: any;
|
|
70
|
+
query?: QueryObject;
|
|
71
|
+
routerParams?: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
74
|
+
type EventHandlerResolver = (path: string) => MaybePromise<undefined | {
|
|
75
|
+
route?: string;
|
|
76
|
+
handler: EventHandler;
|
|
77
|
+
}>;
|
|
78
|
+
interface EventHandler<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> {
|
|
79
|
+
__is_handler__?: true;
|
|
80
|
+
__resolve__?: EventHandlerResolver;
|
|
81
|
+
__websocket__?: Partial<Hooks>;
|
|
82
|
+
(event: H3Event<Request>): Response;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Forward `/_lunora/**` to the Lunora worker. We reconstruct a Web `Request`
|
|
86
|
+
* from the H3 event (Lunora speaks the Web Fetch contract — RPC bodies and the
|
|
87
|
+
* WebSocket `Upgrade` handshake), resolve the Cloudflare `env`/`ExecutionContext`
|
|
88
|
+
* off the event, and return the worker's `Response` verbatim (H3 streams it,
|
|
89
|
+
* including a `101 Switching Protocols` upgrade with its `webSocket`).
|
|
90
|
+
*/
|
|
91
|
+
declare const lunoraEventHandler: EventHandler;
|
|
92
|
+
export { lunoraEventHandler as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"h3";import a from"#lunora/app";import{resolveCloudflare as l}from"../cloudflare.mjs";import{resolveWebRequest as m}from"../h3-request.mjs";import{delegateToLunora as s}from"../handler.mjs";const i=e.defineEventHandler(async r=>{const{ctx:o,env:t}=l(r),n=m(e,r);return s(a,n,t,o)});export{i as default};
|
package/dist/server.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ArgsOf, AuthLike, FunctionReference, HeadersSource, Preloaded, ReturnOf, ServerClientOptions, ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
|
|
1
|
+
export { type ArgsOf, type AuthLike, type FunctionReference, type HeadersSource, type Preloaded, type ReturnOf, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type ArgsOf, type AuthLike, type FunctionReference, type HeadersSource, type Preloaded, type ReturnOf, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createServerClient as d,deserializePreloaded as l,getServerSession as a,preloadQuery as o,preloadedQueryResult as i,serializePreloaded as s}from"@lunora/client/ssr";export{d as createServerClient,l as deserializePreloaded,a as getServerSession,o as preloadQuery,i as preloadedQueryResult,s as serializePreloaded};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/nuxt",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.140",
|
|
4
4
|
"description": "Nuxt module for Lunora — single-worker composition (mounts /_lunora/* into Nitro) plus reactive-loader server helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"sideEffects": false,
|
|
36
36
|
"main": "./dist/module.mjs",
|
|
37
37
|
"module": "./dist/module.mjs",
|
|
38
|
-
"types": "./dist/
|
|
38
|
+
"types": "./dist/module.d.ts",
|
|
39
39
|
"exports": {
|
|
40
40
|
".": {
|
|
41
|
-
"types": "./dist/
|
|
41
|
+
"types": "./dist/module.d.ts",
|
|
42
42
|
"import": "./dist/module.mjs"
|
|
43
43
|
},
|
|
44
44
|
"./server": {
|
|
45
|
-
"types": "./dist/server.d.
|
|
45
|
+
"types": "./dist/server.d.ts",
|
|
46
46
|
"import": "./dist/server.mjs"
|
|
47
47
|
},
|
|
48
48
|
"./package.json": "./package.json"
|
|
@@ -51,12 +51,13 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@lunora/client": "1.0.0-alpha.
|
|
55
|
-
"@
|
|
54
|
+
"@lunora/client": "1.0.0-alpha.114",
|
|
55
|
+
"@lunora/runtime": "1.0.0-alpha.128",
|
|
56
|
+
"@nuxt/kit": "^4.5.2"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"h3": "^1.
|
|
59
|
-
"nuxt": "^4.0.
|
|
59
|
+
"h3": "^1.15.0",
|
|
60
|
+
"nuxt": "^4.0.3"
|
|
60
61
|
},
|
|
61
62
|
"peerDependenciesMeta": {
|
|
62
63
|
"h3": {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const resolveCloudflare = (event) => {
|
|
2
|
-
const fromContext = event.context?.cloudflare;
|
|
3
|
-
if (fromContext?.env) {
|
|
4
|
-
return { ctx: fromContext.context ?? fromContext.ctx, env: fromContext.env };
|
|
5
|
-
}
|
|
6
|
-
const fromRuntime = event.req?.runtime?.cloudflare;
|
|
7
|
-
if (fromRuntime?.env) {
|
|
8
|
-
return { ctx: fromRuntime.ctx ?? fromRuntime.context, env: fromRuntime.env };
|
|
9
|
-
}
|
|
10
|
-
return {};
|
|
11
|
-
};
|
|
12
|
-
export { resolveCloudflare };
|
package/dist/runtime/handler.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NOOP_EXECUTION_CONTEXT } from "../../../../shared/execution-context";
|
|
2
|
-
const delegateToLunora = async (worker, request, env, context) => {
|
|
3
|
-
if (!env) {
|
|
4
|
-
return Response.json(
|
|
5
|
-
{
|
|
6
|
-
error: {
|
|
7
|
-
code: "LUNORA_RUNTIME_UNAVAILABLE",
|
|
8
|
-
message: "Lunora could not read the Cloudflare bindings from the request. The `/_lunora/**` route only works on the Cloudflare Workers runtime (deployed, or `nuxt dev` with `nitro-cloudflare-dev`)."
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
{ status: 500 }
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return worker.fetch(request, env, context ?? NOOP_EXECUTION_CONTEXT);
|
|
15
|
-
};
|
|
16
|
-
export { delegateToLunora };
|
|
17
|
-
export { NOOP_EXECUTION_CONTEXT } from "../../../../shared/execution-context";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as h3 from "h3";
|
|
2
|
-
import lunoraApp from "#lunora/app";
|
|
3
|
-
import { resolveCloudflare } from "../cloudflare.js";
|
|
4
|
-
import { resolveWebRequest } from "../h3-request.js";
|
|
5
|
-
import { delegateToLunora } from "../handler.js";
|
|
6
|
-
export default h3.defineEventHandler(async (event) => {
|
|
7
|
-
const { ctx, env } = resolveCloudflare(event);
|
|
8
|
-
const request = resolveWebRequest(h3, event);
|
|
9
|
-
return delegateToLunora(lunoraApp, request, env, ctx);
|
|
10
|
-
});
|
package/dist/types.d.mts
DELETED