@arkstack/driver-h3 0.12.20 → 0.12.22
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/dist/index-BJ2iafCy.d.ts +86 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -13
- package/dist/middlewares/index.d.ts +1 -1
- package/dist/types-yX_T9j5I.d.ts +18 -0
- package/dist/types.d.ts +1 -1
- package/package.json +5 -5
|
@@ -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-
|
|
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,8 +65,9 @@ const defaultErrorHandler = async (err, event) => {
|
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
67
|
//#endregion
|
|
68
|
-
//#region ../http/dist/redirect-
|
|
68
|
+
//#region ../http/dist/redirect-CFGcSkzk.js
|
|
69
69
|
const unwrapRequestSource = (source) => {
|
|
70
|
+
if (source.original) return unwrapRequestSource(source.original);
|
|
70
71
|
if (source.headers) return source;
|
|
71
72
|
if (source.req) return source.req;
|
|
72
73
|
if (source.request) return source.request;
|
|
@@ -118,22 +119,48 @@ var Request$1 = class Request$1 extends Request {
|
|
|
118
119
|
headers;
|
|
119
120
|
ip;
|
|
120
121
|
source;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
currentUser;
|
|
123
|
+
currentAuth;
|
|
124
|
+
currentAuthUser;
|
|
125
|
+
currentAuthToken;
|
|
126
|
+
get user() {
|
|
127
|
+
return this.getSourceRequest()?.user ?? this.currentUser;
|
|
128
|
+
}
|
|
129
|
+
set user(user) {
|
|
130
|
+
this.currentUser = user;
|
|
131
|
+
}
|
|
132
|
+
get auth() {
|
|
133
|
+
return this.getSourceRequest()?.auth ?? this.currentAuth;
|
|
134
|
+
}
|
|
135
|
+
set auth(auth) {
|
|
136
|
+
this.currentAuth = auth;
|
|
137
|
+
}
|
|
138
|
+
get authUser() {
|
|
139
|
+
return this.getSourceRequest()?.authUser ?? this.currentAuthUser;
|
|
140
|
+
}
|
|
141
|
+
set authUser(user) {
|
|
142
|
+
this.currentAuthUser = user;
|
|
143
|
+
}
|
|
144
|
+
get authToken() {
|
|
145
|
+
return this.getSourceRequest()?.authToken ?? this.currentAuthToken;
|
|
146
|
+
}
|
|
147
|
+
set authToken(token) {
|
|
148
|
+
this.currentAuthToken = token;
|
|
149
|
+
}
|
|
125
150
|
constructor(options = {}) {
|
|
126
151
|
super(options);
|
|
152
|
+
const source = options.source ?? options.original;
|
|
153
|
+
const sourceRequest = isRecord(source) ? source : void 0;
|
|
127
154
|
this.headers = normalizeHeaders(options.headers);
|
|
128
155
|
if (this.method) this.method = options.method;
|
|
129
156
|
if (this.url) this.url = options.url;
|
|
130
157
|
if (this.path) this.path = options.path;
|
|
131
|
-
this.ip = options.ip ?? null;
|
|
132
|
-
this.user = options.user;
|
|
133
|
-
this.auth = options.auth;
|
|
134
|
-
this.authUser = options.authUser;
|
|
135
|
-
this.authToken = options.authToken;
|
|
136
|
-
this.source =
|
|
158
|
+
this.ip = options.ip ?? sourceRequest?.ip ?? null;
|
|
159
|
+
this.user = options.user ?? sourceRequest?.user;
|
|
160
|
+
this.auth = options.auth ?? sourceRequest?.auth;
|
|
161
|
+
this.authUser = options.authUser ?? sourceRequest?.authUser;
|
|
162
|
+
this.authToken = options.authToken ?? sourceRequest?.authToken;
|
|
163
|
+
this.source = source;
|
|
137
164
|
globalThis.request = (key) => key ? this.input(key) : this;
|
|
138
165
|
}
|
|
139
166
|
static from(source) {
|
|
@@ -150,7 +177,7 @@ var Request$1 = class Request$1 extends Request {
|
|
|
150
177
|
auth: request.auth,
|
|
151
178
|
authUser: request.authUser,
|
|
152
179
|
authToken: request.authToken,
|
|
153
|
-
source
|
|
180
|
+
source: request
|
|
154
181
|
});
|
|
155
182
|
}
|
|
156
183
|
header(name) {
|
|
@@ -178,6 +205,18 @@ var Request$1 = class Request$1 extends Request {
|
|
|
178
205
|
}
|
|
179
206
|
return this;
|
|
180
207
|
}
|
|
208
|
+
syncFromSource() {
|
|
209
|
+
if (!isRecord(this.source)) return this;
|
|
210
|
+
const source = this.source;
|
|
211
|
+
this.user = source.user ?? this.user;
|
|
212
|
+
this.auth = source.auth ?? this.auth;
|
|
213
|
+
this.authUser = source.authUser ?? this.authUser;
|
|
214
|
+
this.authToken = source.authToken ?? this.authToken;
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
getSourceRequest() {
|
|
218
|
+
return isRecord(this.source) ? this.source : void 0;
|
|
219
|
+
}
|
|
181
220
|
clearAuthentication() {
|
|
182
221
|
this.auth = void 0;
|
|
183
222
|
this.authUser = void 0;
|
|
@@ -1211,7 +1250,7 @@ definePlugin({
|
|
|
1211
1250
|
return session;
|
|
1212
1251
|
});
|
|
1213
1252
|
bind(Request$1, ({ request, ctx }) => {
|
|
1214
|
-
return request instanceof Request$1 ? request : Request$1.from(request ?? ctx);
|
|
1253
|
+
return (request instanceof Request$1 ? request : Request$1.from(request ?? ctx)).syncFromSource();
|
|
1215
1254
|
});
|
|
1216
1255
|
useHttpContext((context) => {
|
|
1217
1256
|
const session = getSession(context.ctx);
|
|
@@ -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-
|
|
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.
|
|
3
|
+
"version": "0.12.22",
|
|
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",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"clear-router": "^2.8.6",
|
|
41
41
|
"@resora/plugin-clear-router": "^1.0.48",
|
|
42
42
|
"resora": "^1.3.16",
|
|
43
|
-
"@arkstack/contract": "^0.12.
|
|
43
|
+
"@arkstack/contract": "^0.12.22"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"h3": "2.0.1-rc.22",
|
|
47
|
-
"@arkstack/auth": "^0.12.
|
|
48
|
-
"@arkstack/
|
|
49
|
-
"@arkstack/
|
|
47
|
+
"@arkstack/auth": "^0.12.22",
|
|
48
|
+
"@arkstack/common": "^0.12.22",
|
|
49
|
+
"@arkstack/foundry": "^0.12.22"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"@arkstack/auth": {
|