@lunora/nuxt 1.0.0-alpha.32 → 1.0.0-alpha.34

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.
@@ -0,0 +1,24 @@
1
+ import { defineNuxtModule } from '@nuxt/kit';
2
+ /** Options for the `@lunora/nuxt` module (configurable under the `lunora` key in `nuxt.config`). */
3
+ interface ModuleOptions {
4
+ /**
5
+ * Module specifier of the Lunora app entry — its default export is the built
6
+ * worker (`defineApp().build()` / `createWorker(...)`) and it re-exports
7
+ * `ShardDO`. Aliased to the `#lunora/app` virtual the server route imports.
8
+ */
9
+ appEntry: string;
10
+ /** URL prefix Lunora realtime is mounted at. */
11
+ prefix: string;
12
+ }
13
+ /**
14
+ * Return type of `defineNuxtModule<ModuleOptions>({...})` — the value overload of
15
+ * `defineNuxtModule` (the one taking a definition), extracted structurally so the
16
+ * default export has a locally-nameable type under `isolatedDeclarations` without
17
+ * importing `NuxtModule` from `@nuxt/schema` (not a resolvable dependency here).
18
+ */
19
+ type LunoraNuxtModule = typeof defineNuxtModule<ModuleOptions> extends {
20
+ (definition: infer _Definition): infer Result;
21
+ (): unknown;
22
+ } ? Result : never;
23
+ declare const lunoraNuxtModule: LunoraNuxtModule;
24
+ export { ModuleOptions, lunoraNuxtModule as default };
@@ -41,7 +41,7 @@ const lunoraTsSourceResolver = (rootDirectory) => {
41
41
  }
42
42
  };
43
43
  };
44
- const module$1 = defineNuxtModule({
44
+ const lunoraNuxtModule = defineNuxtModule({
45
45
  defaults: {
46
46
  appEntry: "~/lunora/server",
47
47
  prefix: "/_lunora"
@@ -63,10 +63,10 @@ const module$1 = defineNuxtModule({
63
63
  });
64
64
  if (!existsSync(join(nuxt.options.rootDir, "worker.ts"))) {
65
65
  useLogger("@lunora/nuxt").warn(
66
- 'missing worker.ts at the project root \u2014 add a wrapper that re-exports Nitro\'s handler and `ShardDO` (`export { default } from "./.output/server/index.mjs"; export { ShardDO } from "./lunora/server";`) and point wrangler\'s `main` at it, so the SHARD Durable Object is exported from the deployed worker.'
66
+ 'missing worker.ts at the project root add a wrapper that re-exports Nitro\'s handler and `ShardDO` (`export { default } from "./.output/server/index.mjs"; export { ShardDO } from "./lunora/server";`) and point wrangler\'s `main` at it, so the SHARD Durable Object is exported from the deployed worker.'
67
67
  );
68
68
  }
69
69
  }
70
70
  });
71
71
 
72
- export { module$1 as default };
72
+ export { lunoraNuxtModule as default };
package/dist/module.json CHANGED
@@ -1,9 +1,5 @@
1
1
  {
2
2
  "configKey": "lunora",
3
3
  "name": "@lunora/nuxt",
4
- "version": "1.0.0-alpha.31",
5
- "builder": {
6
- "@nuxt/module-builder": "1.0.2",
7
- "unbuild": "unknown"
8
- }
9
- }
4
+ "version": "1.0.0-alpha.33"
5
+ }
@@ -1,24 +1,36 @@
1
- import type { ExecutionContextLike } from "@lunora/runtime";
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
- context?: ExecutionContextLike;
4
- ctx?: ExecutionContextLike;
5
- env?: Record<string, unknown>;
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
- context?: {
9
- cloudflare?: CloudflareEventBag;
10
- };
11
- req?: {
12
- runtime?: {
13
- cloudflare?: CloudflareEventBag;
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
- ctx?: ExecutionContextLike;
19
- env?: Record<string, unknown>;
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 { H3EventLike, ResolvedCloudflare };
23
- export { resolveCloudflare };
24
- export { type ExecutionContextLike } from "@lunora/runtime";
36
+ export { type H3EventLike, type ResolvedCloudflare, resolveCloudflare };
@@ -1,3 +1,5 @@
1
+ import '@lunora/runtime';
2
+
1
3
  const resolveCloudflare = (event) => {
2
4
  const fromContext = event.context?.cloudflare;
3
5
  if (fromContext?.env) {
@@ -9,4 +11,5 @@ const resolveCloudflare = (event) => {
9
11
  }
10
12
  return {};
11
13
  };
14
+
12
15
  export { resolveCloudflare };
@@ -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
- toWebRequest?: unknown;
15
+ toWebRequest?: unknown;
3
16
  }
4
17
  declare const resolveWebRequest: (h3: H3RequestNamespace, event: unknown) => Request;
5
- export type { H3RequestNamespace };
6
- export { resolveWebRequest };
18
+ export { type H3RequestNamespace, resolveWebRequest };
@@ -1,2 +1,3 @@
1
1
  const resolveWebRequest = (h3, event) => typeof h3.toWebRequest === "function" ? h3.toWebRequest(event) : event.req;
2
+
2
3
  export { resolveWebRequest };
@@ -1,8 +1,19 @@
1
- import type { ExecutionContextLike } from "@lunora/runtime";
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
- fetch: (request: Request, env: unknown, context: ExecutionContextLike) => Promise<Response> | Response;
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 { LunoraWorkerLike };
7
- export { delegateToLunora };
8
- export { NOOP_EXECUTION_CONTEXT } from "@lunora/runtime";
19
+ export { type LunoraWorkerLike, delegateToLunora };
@@ -1,4 +1,6 @@
1
- import { NOOP_EXECUTION_CONTEXT } from "@lunora/runtime";
1
+ import { NOOP_EXECUTION_CONTEXT } from '@lunora/runtime';
2
+ export { NOOP_EXECUTION_CONTEXT } from '@lunora/runtime';
3
+
2
4
  const delegateToLunora = async (worker, request, env, context) => {
3
5
  if (!env) {
4
6
  return Response.json(
@@ -13,5 +15,5 @@ const delegateToLunora = async (worker, request, env, context) => {
13
15
  }
14
16
  return worker.fetch(request, env, context ?? NOOP_EXECUTION_CONTEXT);
15
17
  };
18
+
16
19
  export { delegateToLunora };
17
- export { NOOP_EXECUTION_CONTEXT } from "@lunora/runtime";
@@ -1,3 +1,93 @@
1
- import * as h3 from "h3";
2
- declare const _default: h3.EventHandler<h3.EventHandlerRequest, Promise<Response>>;
3
- export default _default;
1
+ import { QueryObject } from 'ufo';
2
+ import { Hooks } from 'crossws';
3
+ import { IncomingMessage, ServerResponse } from 'node:http';
4
+ import 'node:stream';
5
+ interface NodeEventContext {
6
+ req: IncomingMessage & {
7
+ originalUrl?: string;
8
+ };
9
+ res: ServerResponse;
10
+ }
11
+ interface WebEventContext {
12
+ request?: Request;
13
+ url?: URL;
14
+ }
15
+ declare class H3Event<_RequestT extends EventHandlerRequest = EventHandlerRequest> implements Pick<FetchEvent, "respondWith"> {
16
+ "__is_event__": boolean;
17
+ node: NodeEventContext;
18
+ web?: WebEventContext;
19
+ context: H3EventContext;
20
+ _method?: HTTPMethod;
21
+ _path?: string;
22
+ _headers?: Headers;
23
+ _requestBody?: BodyInit;
24
+ _handled: boolean;
25
+ _onBeforeResponseCalled: boolean | undefined;
26
+ _onAfterResponseCalled: boolean | undefined;
27
+ constructor(req: IncomingMessage, res: ServerResponse);
28
+ get method(): HTTPMethod;
29
+ get path(): string;
30
+ get headers(): Headers;
31
+ get handled(): boolean;
32
+ respondWith(response: Response | PromiseLike<Response>): Promise<void>;
33
+ toString(): string;
34
+ toJSON(): string;
35
+ /** @deprecated Please use `event.node.req` instead. */
36
+ get req(): IncomingMessage & {
37
+ originalUrl?: string;
38
+ };
39
+ /** @deprecated Please use `event.node.res` instead. */
40
+ get res(): ServerResponse<IncomingMessage>;
41
+ }
42
+ type SessionDataT = Record<string, any>;
43
+ type SessionData<T extends SessionDataT = SessionDataT> = T;
44
+ declare const getSessionPromise: unique symbol;
45
+ interface Session<T extends SessionDataT = SessionDataT> {
46
+ id: string;
47
+ createdAt: number;
48
+ data: SessionData<T>;
49
+ [getSessionPromise]?: Promise<Session<T>>;
50
+ }
51
+ type RouterMethod = Lowercase<HTTPMethod>;
52
+ interface RouteNode {
53
+ handlers: Partial<Record<RouterMethod | "all", EventHandler>>;
54
+ path: string;
55
+ }
56
+ type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
57
+ interface H3EventContext extends Record<string, any> {
58
+ params?: Record<string, string>;
59
+ /**
60
+ * Matched router Node
61
+ *
62
+ * @experimental The object structure may change in non-major version.
63
+ */
64
+ matchedRoute?: RouteNode;
65
+ sessions?: Record<string, Session>;
66
+ clientAddress?: string;
67
+ }
68
+ type EventHandlerResponse<T = any> = T | Promise<T>;
69
+ interface EventHandlerRequest {
70
+ body?: any;
71
+ query?: QueryObject;
72
+ routerParams?: Record<string, string>;
73
+ }
74
+ type MaybePromise<T> = T | Promise<T>;
75
+ type EventHandlerResolver = (path: string) => MaybePromise<undefined | {
76
+ route?: string;
77
+ handler: EventHandler;
78
+ }>;
79
+ interface EventHandler<Request extends EventHandlerRequest = EventHandlerRequest, Response extends EventHandlerResponse = EventHandlerResponse> {
80
+ __is_handler__?: true;
81
+ __resolve__?: EventHandlerResolver;
82
+ __websocket__?: Partial<Hooks>;
83
+ (event: H3Event<Request>): Response;
84
+ }
85
+ /**
86
+ * Forward `/_lunora/**` to the Lunora worker. We reconstruct a Web `Request`
87
+ * from the H3 event (Lunora speaks the Web Fetch contract — RPC bodies and the
88
+ * WebSocket `Upgrade` handshake), resolve the Cloudflare `env`/`ExecutionContext`
89
+ * off the event, and return the worker's `Response` verbatim (H3 streams it,
90
+ * including a `101 Switching Protocols` upgrade with its `webSocket`).
91
+ */
92
+ declare const lunoraEventHandler: EventHandler;
93
+ export { lunoraEventHandler as default };
@@ -1,10 +1,13 @@
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) => {
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
+
7
+ const lunoraEventHandler = h3.defineEventHandler(async (event) => {
7
8
  const { ctx, env } = resolveCloudflare(event);
8
9
  const request = resolveWebRequest(h3, event);
9
10
  return delegateToLunora(lunoraApp, request, env, ctx);
10
11
  });
12
+
13
+ export { lunoraEventHandler as default };
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/nuxt",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.34",
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",
@@ -33,17 +33,17 @@
33
33
  ],
34
34
  "type": "module",
35
35
  "sideEffects": false,
36
- "main": "./dist/module.mjs",
37
- "module": "./dist/module.mjs",
38
- "types": "./dist/types.d.mts",
36
+ "main": "./dist/module.js",
37
+ "module": "./dist/module.js",
38
+ "types": "./dist/module.d.ts",
39
39
  "exports": {
40
40
  ".": {
41
- "types": "./dist/types.d.mts",
42
- "import": "./dist/module.mjs"
41
+ "types": "./dist/module.d.ts",
42
+ "import": "./dist/module.js"
43
43
  },
44
44
  "./server": {
45
- "types": "./dist/server.d.mts",
46
- "import": "./dist/server.mjs"
45
+ "types": "./dist/server.d.ts",
46
+ "import": "./dist/server.js"
47
47
  },
48
48
  "./package.json": "./package.json"
49
49
  },
@@ -51,8 +51,8 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@lunora/client": "1.0.0-alpha.23",
55
- "@lunora/runtime": "1.0.0-alpha.28",
54
+ "@lunora/client": "1.0.0-alpha.25",
55
+ "@lunora/runtime": "1.0.0-alpha.29",
56
56
  "@nuxt/kit": "^4.4.8"
57
57
  },
58
58
  "peerDependencies": {
package/dist/module.d.mts DELETED
@@ -1,9 +0,0 @@
1
- import * as nuxt_schema from 'nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- appEntry: string;
5
- prefix: string;
6
- }
7
- declare const _default: nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
-
9
- export { _default as default };
package/dist/server.d.mts DELETED
@@ -1 +0,0 @@
1
- export { ArgsOf, AuthLike, FunctionReference, HeadersSource, Preloaded, ReturnOf, ServerClientOptions, ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
package/dist/types.d.mts DELETED
@@ -1,7 +0,0 @@
1
- import type { NuxtModule } from '@nuxt/schema'
2
-
3
- import type { default as Module } from './module.mjs'
4
-
5
- export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
-
7
- export { default } from './module.mjs'
File without changes