@lunora/nuxt 1.0.0-alpha.3 → 1.0.0-alpha.300
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 +123 -15
- package/__assets__/package-og.svg +1 -1
- 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 +56 -0
- package/dist/runtime/cloudflare.d.ts +56 -0
- package/dist/runtime/cloudflare.mjs +1 -0
- package/dist/runtime/h3-request.d.mts +18 -0
- package/dist/runtime/h3-request.d.ts +18 -0
- package/dist/runtime/h3-request.mjs +1 -0
- package/dist/runtime/handler.d.mts +36 -0
- package/dist/runtime/handler.d.ts +36 -0
- package/dist/runtime/handler.mjs +1 -0
- package/dist/runtime/server/lunora.d.mts +113 -0
- package/dist/runtime/server/lunora.d.ts +113 -0
- 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 +10 -9
- package/dist/runtime/cloudflare.js +0 -12
- package/dist/runtime/handler.js +0 -21
- package/dist/runtime/server/lunora.js +0 -9
- package/dist/types.d.mts +0 -7
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro server handler mounted at `/_lunora/**` by the `@lunora/nuxt` module
|
|
3
|
+
* (`addServerHandler`). It is the single-worker seam: every Lunora RPC,
|
|
4
|
+
* WebSocket upgrade, and admin request is forwarded to the project's Lunora
|
|
5
|
+
* worker, which runs *inside* the same Nitro/Cloudflare worker the rest of the
|
|
6
|
+
* Nuxt app deploys as.
|
|
7
|
+
*
|
|
8
|
+
* The worker instance is the project's composed app, imported through the
|
|
9
|
+
* `#lunora/app` virtual the module registers (it points at the app entry — by
|
|
10
|
+
* default `~/lunora/server`, where `defineApp().build()` lives and re-exports
|
|
11
|
+
* `ShardDO`). The same `ShardDO` is re-exported to the Cloudflare worker
|
|
12
|
+
* entrypoint via the project's root `worker.ts` wrapper (`wrangler.jsonc`'s
|
|
13
|
+
* `main`), so one deploy carries both the SSR handler and the Durable Object class.
|
|
14
|
+
*
|
|
15
|
+
* This file is only ever bundled by Nitro; `h3`'s `defineEventHandler` is its
|
|
16
|
+
* sole framework entry. We use a namespace import so the seam spans the h3
|
|
17
|
+
* v1 → v2 break: v1 exposes `toWebRequest(event)`, while the v2 web-standards
|
|
18
|
+
* rewrite removed it and carries the web `Request` directly as `event.req`. A
|
|
19
|
+
* static `import { toWebRequest }` would throw at module-eval under v2 (missing
|
|
20
|
+
* named export), so `resolveWebRequest` feature-detects it at runtime instead.
|
|
21
|
+
*/
|
|
22
|
+
import { QueryObject } from 'ufo';
|
|
23
|
+
import { Hooks } from 'crossws';
|
|
24
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
25
|
+
interface NodeEventContext {
|
|
26
|
+
req: IncomingMessage & {
|
|
27
|
+
originalUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
res: ServerResponse;
|
|
30
|
+
}
|
|
31
|
+
interface WebEventContext {
|
|
32
|
+
request?: Request;
|
|
33
|
+
url?: URL;
|
|
34
|
+
}
|
|
35
|
+
declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> {
|
|
36
|
+
"__is_event__": boolean;
|
|
37
|
+
node: NodeEventContext;
|
|
38
|
+
web?: WebEventContext;
|
|
39
|
+
context: H3EventContext;
|
|
40
|
+
_method?: HTTPMethod;
|
|
41
|
+
_path?: string;
|
|
42
|
+
_headers?: Headers;
|
|
43
|
+
_requestBody?: BodyInit;
|
|
44
|
+
_handled: boolean;
|
|
45
|
+
_onBeforeResponseCalled: boolean | undefined;
|
|
46
|
+
_onAfterResponseCalled: boolean | undefined;
|
|
47
|
+
constructor(req: IncomingMessage, res: ServerResponse);
|
|
48
|
+
get method(): HTTPMethod;
|
|
49
|
+
get path(): string;
|
|
50
|
+
get headers(): Headers;
|
|
51
|
+
get handled(): boolean;
|
|
52
|
+
respondWith(response: Response | PromiseLike<Response>): Promise<void>;
|
|
53
|
+
toString(): string;
|
|
54
|
+
toJSON(): string;
|
|
55
|
+
/** @deprecated Please use `event.node.req` instead. */
|
|
56
|
+
get req(): IncomingMessage & {
|
|
57
|
+
originalUrl?: string;
|
|
58
|
+
};
|
|
59
|
+
/** @deprecated Please use `event.node.res` instead. */
|
|
60
|
+
get res(): ServerResponse<IncomingMessage>;
|
|
61
|
+
}
|
|
62
|
+
type SessionDataT = Record<string, any>;
|
|
63
|
+
type SessionData<T extends SessionDataT = SessionDataT> = T;
|
|
64
|
+
declare const getSessionPromise: unique symbol;
|
|
65
|
+
interface Session<T extends SessionDataT = SessionDataT> {
|
|
66
|
+
id: string;
|
|
67
|
+
createdAt: number;
|
|
68
|
+
data: SessionData<T>;
|
|
69
|
+
[getSessionPromise]?: Promise<Session<T>>;
|
|
70
|
+
}
|
|
71
|
+
type RouterMethod = Lowercase<HTTPMethod>;
|
|
72
|
+
interface RouteNode {
|
|
73
|
+
handlers: Partial<Record<RouterMethod | "all", EventHandler>>;
|
|
74
|
+
path: string;
|
|
75
|
+
}
|
|
76
|
+
type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
|
|
77
|
+
interface H3EventContext extends Record<string, any> {
|
|
78
|
+
params?: Record<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* Matched router Node
|
|
81
|
+
*
|
|
82
|
+
* @experimental The object structure may change in non-major version.
|
|
83
|
+
*/
|
|
84
|
+
matchedRoute?: RouteNode;
|
|
85
|
+
sessions?: Record<string, Session>;
|
|
86
|
+
clientAddress?: string;
|
|
87
|
+
}
|
|
88
|
+
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
89
|
+
interface EventHandlerRequest {
|
|
90
|
+
body?: any;
|
|
91
|
+
query?: QueryObject;
|
|
92
|
+
routerParams?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
95
|
+
type EventHandlerResolver = (path: string) => MaybePromise<undefined | {
|
|
96
|
+
route?: string;
|
|
97
|
+
handler: EventHandler;
|
|
98
|
+
}>;
|
|
99
|
+
interface EventHandler<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> {
|
|
100
|
+
__is_handler__?: true;
|
|
101
|
+
__resolve__?: EventHandlerResolver;
|
|
102
|
+
__websocket__?: Partial<Hooks>;
|
|
103
|
+
(event: H3Event<Request>): Response;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Forward `/_lunora/**` to the Lunora worker. We reconstruct a Web `Request`
|
|
107
|
+
* from the H3 event (Lunora speaks the Web Fetch contract — RPC bodies and the
|
|
108
|
+
* WebSocket `Upgrade` handshake), resolve the Cloudflare `env`/`ExecutionContext`
|
|
109
|
+
* off the event, and return the worker's `Response` verbatim (H3 streams it,
|
|
110
|
+
* including a `101 Switching Protocols` upgrade with its `webSocket`).
|
|
111
|
+
*/
|
|
112
|
+
declare const lunoraEventHandler: EventHandler;
|
|
113
|
+
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.300",
|
|
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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"directory": "packages/nuxt"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"dist",
|
|
29
|
+
"./dist",
|
|
30
30
|
"README.md",
|
|
31
31
|
"LICENSE.md",
|
|
32
32
|
"__assets__"
|
|
@@ -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.283",
|
|
55
|
+
"@lunora/runtime": "1.0.0-alpha.273",
|
|
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,21 +0,0 @@
|
|
|
1
|
-
const NOOP_EXECUTION_CONTEXT = {
|
|
2
|
-
passThroughOnException: () => {
|
|
3
|
-
},
|
|
4
|
-
waitUntil: () => {
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
const delegateToLunora = async (worker, request, env, context) => {
|
|
8
|
-
if (!env) {
|
|
9
|
-
return Response.json(
|
|
10
|
-
{
|
|
11
|
-
error: {
|
|
12
|
-
code: "LUNORA_RUNTIME_UNAVAILABLE",
|
|
13
|
-
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`)."
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
{ status: 500 }
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
return worker.fetch(request, env, context ?? NOOP_EXECUTION_CONTEXT);
|
|
20
|
-
};
|
|
21
|
-
export { delegateToLunora, NOOP_EXECUTION_CONTEXT };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { defineEventHandler, toWebRequest } from "h3";
|
|
2
|
-
import lunoraApp from "#lunora/app";
|
|
3
|
-
import { resolveCloudflare } from "../cloudflare.js";
|
|
4
|
-
import { delegateToLunora } from "../handler.js";
|
|
5
|
-
export default defineEventHandler(async (event) => {
|
|
6
|
-
const { ctx, env } = resolveCloudflare(event);
|
|
7
|
-
const request = toWebRequest(event);
|
|
8
|
-
return delegateToLunora(lunoraApp, request, env, ctx);
|
|
9
|
-
});
|
package/dist/types.d.mts
DELETED