@arkstack/driver-h3 0.12.11 → 0.12.13

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,86 @@
1
+ import { n as MiddlewareConfig, t as Middleware$2 } from "./types-yX_T9j5I.js";
2
+ import { ArkstackKitDriver, ArkstackRouteListOptions, PromiseOrValue } from "@arkstack/contract";
3
+ import { H3, H3Event, HTTPError, HTTPResponse } from "h3";
4
+ import { Route } from "clear-router";
5
+ import { Router } from "clear-router/h3";
6
+ import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "clear-router/types/h3";
7
+
8
+ //#region src/error-handler.d.ts
9
+ declare const defaultErrorHandler: (err: HTTPError | Error | string, event: H3Event) => Promise<HTTPResponse | {
10
+ error: boolean;
11
+ message: string;
12
+ status: "error";
13
+ code: number;
14
+ errors?: unknown;
15
+ stack?: string;
16
+ }>;
17
+ //#endregion
18
+ //#region src/Router.d.ts
19
+ declare class Router$1 extends Router {
20
+ static bind(app: H3): Promise<H3App>;
21
+ static list(_options: ArkstackRouteListOptions | undefined, app: H3): Promise<Route<HttpContext, Middleware$1, Handler>[]>;
22
+ }
23
+ //#endregion
24
+ //#region src/index.d.ts
25
+ type H3Middleware = Middleware$1 | [Middleware$1, Record<string, any>];
26
+ interface H3DriverOptions {
27
+ bindRouter: (app: H3) => PromiseOrValue<void>;
28
+ mountPublicAssets?: (app: H3, publicPath: string) => PromiseOrValue<void>;
29
+ createApp?: () => H3;
30
+ onError?: (err: Error | string, event: H3Event) => unknown;
31
+ }
32
+ declare class H3EventResponse {
33
+ response: Response;
34
+ status: number;
35
+ statusText?: string;
36
+ constructor(response: Response);
37
+ get headers(): Headers;
38
+ }
39
+ /**
40
+ * The H3Driver class implements the ArkstackKitDriver contract for the H3 framework.
41
+ */
42
+ declare class H3Driver extends ArkstackKitDriver<H3, H3Middleware> {
43
+ readonly name = "h3";
44
+ private readonly options;
45
+ /**
46
+ * Creates an instance of H3Driver.
47
+ *
48
+ * @param options
49
+ */
50
+ constructor(options: H3DriverOptions);
51
+ /**
52
+ * Creates an H3 application instance.
53
+ *
54
+ * @returns
55
+ */
56
+ createApp(): H3;
57
+ /**
58
+ * Mounts static assets from the specified public path to the H3 application.
59
+ *
60
+ * @param app
61
+ * @param publicPath
62
+ */
63
+ mountPublicAssets(app: H3, publicPath: string): PromiseOrValue<void>;
64
+ /**
65
+ * Binds the router to the H3 application using the provided bindRouter function.
66
+ *
67
+ * @param app
68
+ */
69
+ bindRouter(app: H3): PromiseOrValue<void>;
70
+ /**
71
+ * Applies middleware to the H3 application.
72
+ *
73
+ * @param app
74
+ * @param middleware
75
+ */
76
+ applyMiddleware(app: H3, middleware: H3Middleware | Middleware$2 | MiddlewareConfig): void;
77
+ /**
78
+ * Starts the H3 server on the specified port.
79
+ *
80
+ * @param app
81
+ * @param port
82
+ */
83
+ start(app: H3, port: number): void;
84
+ }
85
+ //#endregion
86
+ export { Router$1 as a, H3Middleware as i, H3DriverOptions as n, defaultErrorHandler as o, H3EventResponse as r, H3Driver as t };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="./app.d.ts" />
2
- import { a as Router, i as H3Middleware, n as H3DriverOptions, o as defaultErrorHandler, r as H3EventResponse, t as H3Driver } from "./index-DIJtwwZP.js";
2
+ import { a as Router, i as H3Middleware, n as H3DriverOptions, o as defaultErrorHandler, r as H3EventResponse, t as H3Driver } from "./index-BJ2iafCy.js";
3
3
  export { H3Driver, H3DriverOptions, H3EventResponse, H3Middleware, Router, defaultErrorHandler };
package/dist/index.js CHANGED
@@ -65,7 +65,7 @@ const defaultErrorHandler = async (err, event) => {
65
65
  });
66
66
  };
67
67
  //#endregion
68
- //#region ../http/dist/redirect-Bwrh6IHq.js
68
+ //#region ../http/dist/redirect-C1kZMywY.js
69
69
  const unwrapRequestSource = (source) => {
70
70
  if (source.headers) return source;
71
71
  if (source.req) return source.req;
@@ -733,7 +733,7 @@ const ensureSession = (ctx, initial, persistent) => {
733
733
  */
734
734
  const getSession = (ctx) => {
735
735
  if (!isRecord(ctx)) return;
736
- const session = ctx[sessionKey] ?? ctx.session;
736
+ const session = ctx[sessionKey] ?? (ctx.httpSession instanceof Session ? ctx.httpSession : void 0) ?? (ctx.session instanceof Session ? ctx.session : void 0) ?? (isRecord(ctx.req) && ctx.req.httpSession instanceof Session ? ctx.req.httpSession : void 0) ?? (isRecord(ctx.context) && ctx.context.httpSession instanceof Session ? ctx.context.httpSession : void 0);
737
737
  return session instanceof Session ? session : void 0;
738
738
  };
739
739
  const generateSessionId = () => randomBytes(32).toString("base64url");
@@ -1170,16 +1170,26 @@ const getSessionDriver = () => {
1170
1170
  definePlugin({
1171
1171
  name: "arkstack-http",
1172
1172
  setup: ({ bind, useHttpContext }) => {
1173
- bind(Session, ({ ctx }) => ensureSession(ctx));
1174
- useHttpContext(async (context) => {
1173
+ bind(Session, async ({ ctx }) => {
1174
+ const existing = getSession(ctx);
1175
+ if (existing) return existing;
1176
+ const persistent = await getSessionDriver().start(ctx);
1177
+ const session = ensureSession(ctx, persistent.state, persistent);
1178
+ attachViewState(ctx, session);
1179
+ registerResponseFlashSweep(ctx, session);
1180
+ return session;
1181
+ });
1182
+ useHttpContext((context) => {
1183
+ const session = getSession(context.ctx);
1184
+ if (session) {
1185
+ context.httpSession = session;
1186
+ if (!("session" in context) || context.session instanceof Session) context.session = session;
1187
+ context.errors = session.errors;
1188
+ attachViewState(context.ctx, session);
1189
+ attachViewState(context, session);
1190
+ registerResponseFlashSweep(context, session);
1191
+ } else delete globalThis.session;
1175
1192
  globalThis.request = (key) => key ? context.request.input(key) : context.request;
1176
- const persistent = await getSessionDriver().start(context);
1177
- const session = ensureSession(context.ctx, persistent.state, persistent);
1178
- context.httpSession = session;
1179
- if (!("session" in context) || context.session instanceof Session) context.session = session;
1180
- context.errors = session.errors;
1181
- attachViewState(context, session);
1182
- registerResponseFlashSweep(context, session);
1183
1193
  });
1184
1194
  }
1185
1195
  });
@@ -1,4 +1,4 @@
1
- import { i as H3Middleware } from "../index-DIJtwwZP.js";
1
+ import { i as H3Middleware } from "../index-BJ2iafCy.js";
2
2
  import * as _$h3 from "h3";
3
3
  import { EventHandlerRequest, H3Event } from "h3";
4
4
  import { NextFunction } from "clear-router/types/h3";
@@ -0,0 +1,18 @@
1
+ /// <reference path="./app.d.ts" />
2
+ import { ArkstackKitDriver, ArkstackMiddlewareConfig, ArkstackRouteListOptions, PromiseOrValue } from "@arkstack/contract";
3
+ import { H3, H3Event, HTTPError, HTTPResponse, Middleware } from "h3";
4
+ import { Route } from "clear-router";
5
+ import { Router } from "clear-router/h3";
6
+ import { ClassMiddleware } from "clear-router/types/basic";
7
+ import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "clear-router/types/h3";
8
+
9
+ //#region dist/index-DIJtwwZP.d.ts
10
+ //#endregion
11
+ //#region src/index.d.ts
12
+ type H3Middleware = Middleware$1 | [Middleware$1, Record<string, any>];
13
+ //#endregion
14
+ //#region src/types.d.ts
15
+ type Middleware$2 = Middleware | ClassMiddleware<Middleware>;
16
+ type MiddlewareConfig = ArkstackMiddlewareConfig<Middleware$2> | ArkstackMiddlewareConfig<H3Middleware>;
17
+ //#endregion
18
+ export { MiddlewareConfig as n, Middleware$2 as t };
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as MiddlewareConfig, t as Middleware } from "./types-DWUchLdg.js";
1
+ import { n as MiddlewareConfig, t as Middleware } from "./types-yX_T9j5I.js";
2
2
  export { Middleware, MiddlewareConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/driver-h3",
3
- "version": "0.12.11",
3
+ "version": "0.12.13",
4
4
  "type": "module",
5
5
  "description": "H3 driver for Arkstack, providing H3-based runtime integration for the framework.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -38,15 +38,15 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "clear-router": "^2.8.6",
41
- "@resora/plugin-clear-router": "^1.0.37",
42
- "resora": "^1.3.6",
43
- "@arkstack/contract": "^0.12.11"
41
+ "@resora/plugin-clear-router": "^1.0.38",
42
+ "resora": "^1.3.7",
43
+ "@arkstack/contract": "^0.12.13"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "h3": "2.0.1-rc.22",
47
- "@arkstack/auth": "^0.12.11",
48
- "@arkstack/foundry": "^0.12.11",
49
- "@arkstack/common": "^0.12.11"
47
+ "@arkstack/foundry": "^0.12.13",
48
+ "@arkstack/auth": "^0.12.13",
49
+ "@arkstack/common": "^0.12.13"
50
50
  },
51
51
  "peerDependenciesMeta": {
52
52
  "@arkstack/auth": {