@solidjs/start 2.0.0-beta.8 → 2.0.0-rc.1

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,81 @@
1
+ import type { H3Event, HTTPEvent, InferEventInput } from "h3";
2
+ import * as h3 from "h3";
3
+ declare function _setContext(event: H3Event, key: string, value: any): void;
4
+ declare function _getContext(event: H3Event, key: string): unknown;
5
+ export declare function getWebRequest(): Request;
6
+ export declare const HTTPEventSymbol: unique symbol;
7
+ export declare function isEvent(obj: any): obj is h3.H3Event | {
8
+ [HTTPEventSymbol]: h3.H3Event;
9
+ };
10
+ type Tail<T> = T extends [any, ...infer U] ? U : never;
11
+ type PrependOverload<TOriginal extends (...args: Array<any>) => any, TOverload extends (...args: Array<any>) => any> = TOverload & TOriginal;
12
+ type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
13
+ type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
14
+ export declare const readBody: PrependOverload<typeof h3.readBody, WrappedReadBody>;
15
+ type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
16
+ export declare const getQuery: PrependOverload<typeof h3.getQuery, WrappedGetQuery>;
17
+ export declare const isMethod: WrapFunction<typeof h3.isMethod>;
18
+ export declare const isPreflightRequest: WrapFunction<typeof h3.isPreflightRequest>;
19
+ type WrappedGetValidatedQuery = <T extends HTTPEvent, TEventInput = InferEventInput<"query", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
20
+ export declare const getValidatedQuery: PrependOverload<typeof h3.getValidatedQuery, WrappedGetValidatedQuery>;
21
+ export declare const getRouterParams: WrapFunction<typeof h3.getRouterParams>;
22
+ export declare const getRouterParam: WrapFunction<typeof h3.getRouterParam>;
23
+ type WrappedGetValidatedRouterParams = <T extends HTTPEvent, TEventInput = InferEventInput<"routerParams", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
24
+ export declare const getValidatedRouterParams: PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
25
+ export declare const assertMethod: WrapFunction<typeof h3.assertMethod>;
26
+ export declare const getRequestHeaders: WrapFunction<typeof h3.getRequestHeaders>;
27
+ export declare const getRequestHeader: WrapFunction<typeof h3.getRequestHeader>;
28
+ export declare const getRequestURL: WrapFunction<typeof h3.getRequestURL>;
29
+ export declare const getRequestHost: WrapFunction<typeof h3.getRequestHost>;
30
+ export declare const getRequestProtocol: WrapFunction<typeof h3.getRequestProtocol>;
31
+ export declare const getRequestIP: WrapFunction<typeof h3.getRequestIP>;
32
+ export declare const setResponseStatus: (code?: number, text?: string) => void;
33
+ export declare const getResponseStatus: () => number | undefined;
34
+ export declare const getResponseStatusText: () => string | undefined;
35
+ export declare const getResponseHeaders: () => {
36
+ [k: string]: string;
37
+ };
38
+ export declare const getResponseHeader: (name: string) => string | null;
39
+ export declare const setResponseHeaders: (values: Record<string, string>) => void;
40
+ export declare const setResponseHeader: (name: string, value: string | string[]) => void;
41
+ export declare const appendResponseHeaders: (values: Record<string, string>) => void;
42
+ export declare const appendResponseHeader: (name: string, value: string | string[]) => void;
43
+ export declare const defaultContentType: (type: string) => void;
44
+ export declare const proxyRequest: WrapFunction<typeof h3.proxyRequest>;
45
+ export declare const fetchWithEvent: WrapFunction<typeof h3.fetchWithEvent>;
46
+ export declare const getProxyRequestHeaders: WrapFunction<typeof h3.getProxyRequestHeaders>;
47
+ export declare const parseCookies: WrapFunction<typeof h3.parseCookies>;
48
+ export declare const getCookie: WrapFunction<typeof h3.getCookie>;
49
+ export declare const setCookie: WrapFunction<typeof h3.setCookie>;
50
+ export declare const deleteCookie: WrapFunction<typeof h3.deleteCookie>;
51
+ type SessionDataT = Record<string, any>;
52
+ type WrappedUseSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.useSession<T>>>) => ReturnType<typeof h3.useSession<T>>;
53
+ export declare const useSession: WrappedUseSession;
54
+ type WrappedGetSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.getSession<T>>>) => ReturnType<typeof h3.getSession<T>>;
55
+ export declare const getSession: WrappedGetSession;
56
+ type WrappedUpdateSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.updateSession<T>>>) => ReturnType<typeof h3.updateSession<T>>;
57
+ export declare const updateSession: WrappedUpdateSession;
58
+ type WrappedSealSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.sealSession<T>>>) => ReturnType<typeof h3.sealSession<T>>;
59
+ export declare const sealSession: WrappedSealSession;
60
+ export declare const unsealSession: WrapFunction<typeof h3.unsealSession>;
61
+ export declare const clearSession: WrapFunction<typeof h3.clearSession>;
62
+ export declare const handleCacheHeaders: WrapFunction<typeof h3.handleCacheHeaders>;
63
+ export declare const handleCors: WrapFunction<typeof h3.handleCors>;
64
+ export declare const appendCorsHeaders: WrapFunction<typeof h3.appendCorsHeaders>;
65
+ export declare const appendCorsPreflightHeaders: WrapFunction<typeof h3.appendCorsPreflightHeaders>;
66
+ export declare const appendHeader: typeof appendResponseHeader;
67
+ export declare const appendHeaders: typeof appendResponseHeaders;
68
+ export declare const setHeader: typeof setResponseHeader;
69
+ export declare const setHeaders: typeof setResponseHeaders;
70
+ export declare const getHeader: WrapFunction<typeof h3.getRequestHeader>;
71
+ export declare const getHeaders: WrapFunction<typeof h3.getRequestHeaders>;
72
+ export declare const getRequestFingerprint: WrapFunction<typeof h3.getRequestFingerprint>;
73
+ export declare const getRequestWebStream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
74
+ export declare const readFormData: () => Promise<FormData>;
75
+ type WrappedReadValidatedBody = <T extends HTTPEvent, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
76
+ export declare const readValidatedBody: PrependOverload<typeof h3.readValidatedBody, WrappedReadValidatedBody>;
77
+ export declare const getContext: WrapFunction<typeof _getContext>;
78
+ export declare const setContext: WrapFunction<typeof _setContext>;
79
+ export declare const removeResponseHeader: (name: string) => void;
80
+ export declare const clearResponseHeaders: (headerNames?: string[]) => void;
81
+ export {};
@@ -0,0 +1,129 @@
1
+ import * as h3 from "h3";
2
+ import { getRequestEvent } from "solid-js/web";
3
+ function _setContext(event, key, value) {
4
+ event.context[key] = value;
5
+ }
6
+ function _getContext(event, key) {
7
+ return event.context[key];
8
+ }
9
+ function getEvent() {
10
+ return getRequestEvent().nativeEvent;
11
+ }
12
+ export function getWebRequest() {
13
+ return getEvent().req;
14
+ }
15
+ export const HTTPEventSymbol = Symbol("$HTTPEvent");
16
+ export function isEvent(obj) {
17
+ return (typeof obj === "object" &&
18
+ (obj instanceof h3.H3Event ||
19
+ obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
20
+ obj?.__is_event__ === true));
21
+ // Implement logic to check if obj is an H3Event
22
+ }
23
+ function createWrapperFunction(h3Function) {
24
+ return ((...args) => {
25
+ const event = args[0];
26
+ if (!isEvent(event)) {
27
+ args.unshift(getEvent());
28
+ }
29
+ else {
30
+ args[0] =
31
+ event instanceof h3.H3Event || event.__is_event__ ? event : event[HTTPEventSymbol];
32
+ }
33
+ return h3Function(...args);
34
+ });
35
+ }
36
+ export const readBody = createWrapperFunction(h3.readBody);
37
+ export const getQuery = createWrapperFunction(h3.getQuery);
38
+ export const isMethod = createWrapperFunction(h3.isMethod);
39
+ export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
40
+ export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery);
41
+ export const getRouterParams = createWrapperFunction(h3.getRouterParams);
42
+ export const getRouterParam = createWrapperFunction(h3.getRouterParam);
43
+ export const getValidatedRouterParams = createWrapperFunction(h3.getValidatedRouterParams);
44
+ export const assertMethod = createWrapperFunction(h3.assertMethod);
45
+ export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
46
+ export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
47
+ export const getRequestURL = createWrapperFunction(h3.getRequestURL);
48
+ export const getRequestHost = createWrapperFunction(h3.getRequestHost);
49
+ export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
50
+ export const getRequestIP = createWrapperFunction(h3.getRequestIP);
51
+ export const setResponseStatus = (code, text) => {
52
+ const e = getEvent();
53
+ if (e.res.status !== undefined)
54
+ e.res.status = code;
55
+ if (e.res.statusText !== undefined)
56
+ e.res.statusText = text;
57
+ };
58
+ export const getResponseStatus = () => getEvent().res.status;
59
+ export const getResponseStatusText = () => getEvent().res.statusText;
60
+ export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
61
+ export const getResponseHeader = (name) => getEvent().res.headers.get(name);
62
+ export const setResponseHeaders = (values) => {
63
+ const headers = getEvent().res.headers;
64
+ for (const [name, value] of Object.entries(values)) {
65
+ headers.set(name, value);
66
+ }
67
+ };
68
+ export const setResponseHeader = (name, value) => {
69
+ const headers = getEvent().res.headers;
70
+ (Array.isArray(value) ? value : [value]).forEach(value => {
71
+ headers.set(name, value);
72
+ });
73
+ };
74
+ export const appendResponseHeaders = (values) => {
75
+ const headers = getEvent().res.headers;
76
+ for (const [name, value] of Object.entries(values)) {
77
+ headers.append(name, value);
78
+ }
79
+ };
80
+ export const appendResponseHeader = (name, value) => {
81
+ const headers = getEvent().res.headers;
82
+ (Array.isArray(value) ? value : [value]).forEach(value => {
83
+ headers.append(name, value);
84
+ });
85
+ };
86
+ export const defaultContentType = (type) => getEvent().res.headers.set("content-type", type);
87
+ export const proxyRequest = createWrapperFunction(h3.proxyRequest);
88
+ export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
89
+ export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
90
+ export const parseCookies = createWrapperFunction(h3.parseCookies);
91
+ export const getCookie = createWrapperFunction(h3.getCookie);
92
+ export const setCookie = createWrapperFunction(h3.setCookie);
93
+ export const deleteCookie = createWrapperFunction(h3.deleteCookie);
94
+ export const useSession = createWrapperFunction(h3.useSession);
95
+ export const getSession = createWrapperFunction(h3.getSession);
96
+ export const updateSession = createWrapperFunction(h3.updateSession);
97
+ export const sealSession = createWrapperFunction(h3.sealSession);
98
+ export const unsealSession = createWrapperFunction(h3.unsealSession);
99
+ export const clearSession = createWrapperFunction(h3.clearSession);
100
+ export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
101
+ export const handleCors = createWrapperFunction(h3.handleCors);
102
+ export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
103
+ export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
104
+ export const appendHeader = appendResponseHeader;
105
+ export const appendHeaders = appendResponseHeaders;
106
+ export const setHeader = setResponseHeader;
107
+ export const setHeaders = setResponseHeaders;
108
+ export const getHeader = getRequestHeader;
109
+ export const getHeaders = getRequestHeaders;
110
+ export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
111
+ export const getRequestWebStream = () => getEvent().req.body;
112
+ export const readFormData = () => getEvent().req.formData();
113
+ export const readValidatedBody = createWrapperFunction(h3.readValidatedBody);
114
+ export const getContext = createWrapperFunction(_getContext);
115
+ export const setContext = createWrapperFunction(_setContext);
116
+ export const removeResponseHeader = (name) => getEvent().res.headers.delete(name);
117
+ export const clearResponseHeaders = (headerNames) => {
118
+ const headers = getEvent().res.headers;
119
+ if (headerNames && headerNames.length > 0) {
120
+ for (const name of headerNames) {
121
+ headers.delete(name);
122
+ }
123
+ }
124
+ else {
125
+ for (const name of headers.keys()) {
126
+ headers.delete(name);
127
+ }
128
+ }
129
+ };
@@ -1,81 +1,2 @@
1
- import type { H3Event, HTTPEvent, InferEventInput } from "h3";
2
- import * as h3 from "h3";
3
- declare function _setContext(event: H3Event, key: string, value: any): void;
4
- declare function _getContext(event: H3Event, key: string): unknown;
5
- export declare function getWebRequest(): Request;
6
- export declare const HTTPEventSymbol: unique symbol;
7
- export declare function isEvent(obj: any): obj is h3.H3Event | {
8
- [HTTPEventSymbol]: h3.H3Event;
9
- };
10
- type Tail<T> = T extends [any, ...infer U] ? U : never;
11
- type PrependOverload<TOriginal extends (...args: Array<any>) => any, TOverload extends (...args: Array<any>) => any> = TOverload & TOriginal;
12
- type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<TFn, (...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs] ? TArgs : Parameters<TFn>) => ReturnType<TFn>>;
13
- type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
14
- export declare const readBody: PrependOverload<typeof h3.readBody, WrappedReadBody>;
15
- type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
16
- export declare const getQuery: PrependOverload<typeof h3.getQuery, WrappedGetQuery>;
17
- export declare const isMethod: WrapFunction<typeof h3.isMethod>;
18
- export declare const isPreflightRequest: WrapFunction<typeof h3.isPreflightRequest>;
19
- type WrappedGetValidatedQuery = <T extends HTTPEvent, TEventInput = InferEventInput<"query", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
20
- export declare const getValidatedQuery: PrependOverload<typeof h3.getValidatedQuery, WrappedGetValidatedQuery>;
21
- export declare const getRouterParams: WrapFunction<typeof h3.getRouterParams>;
22
- export declare const getRouterParam: WrapFunction<typeof h3.getRouterParam>;
23
- type WrappedGetValidatedRouterParams = <T extends HTTPEvent, TEventInput = InferEventInput<"routerParams", H3Event, T>>(...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
24
- export declare const getValidatedRouterParams: PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
25
- export declare const assertMethod: WrapFunction<typeof h3.assertMethod>;
26
- export declare const getRequestHeaders: WrapFunction<typeof h3.getRequestHeaders>;
27
- export declare const getRequestHeader: WrapFunction<typeof h3.getRequestHeader>;
28
- export declare const getRequestURL: WrapFunction<typeof h3.getRequestURL>;
29
- export declare const getRequestHost: WrapFunction<typeof h3.getRequestHost>;
30
- export declare const getRequestProtocol: WrapFunction<typeof h3.getRequestProtocol>;
31
- export declare const getRequestIP: WrapFunction<typeof h3.getRequestIP>;
32
- export declare const setResponseStatus: (code?: number, text?: string) => void;
33
- export declare const getResponseStatus: () => number | undefined;
34
- export declare const getResponseStatusText: () => string | undefined;
35
- export declare const getResponseHeaders: () => {
36
- [k: string]: string;
37
- };
38
- export declare const getResponseHeader: (name: string) => string | null;
39
- export declare const setResponseHeaders: (values: Record<string, string>) => void;
40
- export declare const setResponseHeader: (name: string, value: string | string[]) => void;
41
- export declare const appendResponseHeaders: (values: Record<string, string>) => void;
42
- export declare const appendResponseHeader: (name: string, value: string | string[]) => void;
43
- export declare const defaultContentType: (type: string) => void;
44
- export declare const proxyRequest: WrapFunction<typeof h3.proxyRequest>;
45
- export declare const fetchWithEvent: WrapFunction<typeof h3.fetchWithEvent>;
46
- export declare const getProxyRequestHeaders: WrapFunction<typeof h3.getProxyRequestHeaders>;
47
- export declare const parseCookies: WrapFunction<typeof h3.parseCookies>;
48
- export declare const getCookie: WrapFunction<typeof h3.getCookie>;
49
- export declare const setCookie: WrapFunction<typeof h3.setCookie>;
50
- export declare const deleteCookie: WrapFunction<typeof h3.deleteCookie>;
51
- type SessionDataT = Record<string, any>;
52
- type WrappedUseSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.useSession<T>>>) => ReturnType<typeof h3.useSession<T>>;
53
- export declare const useSession: WrappedUseSession;
54
- type WrappedGetSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.getSession<T>>>) => ReturnType<typeof h3.getSession<T>>;
55
- export declare const getSession: WrappedGetSession;
56
- type WrappedUpdateSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.updateSession<T>>>) => ReturnType<typeof h3.updateSession<T>>;
57
- export declare const updateSession: WrappedUpdateSession;
58
- type WrappedSealSession = <T extends SessionDataT>(...args: Tail<Parameters<typeof h3.sealSession<T>>>) => ReturnType<typeof h3.sealSession<T>>;
59
- export declare const sealSession: WrappedSealSession;
60
- export declare const unsealSession: WrapFunction<typeof h3.unsealSession>;
61
- export declare const clearSession: WrapFunction<typeof h3.clearSession>;
62
- export declare const handleCacheHeaders: WrapFunction<typeof h3.handleCacheHeaders>;
63
- export declare const handleCors: WrapFunction<typeof h3.handleCors>;
64
- export declare const appendCorsHeaders: WrapFunction<typeof h3.appendCorsHeaders>;
65
- export declare const appendCorsPreflightHeaders: WrapFunction<typeof h3.appendCorsPreflightHeaders>;
66
- export declare const appendHeader: typeof appendResponseHeader;
67
- export declare const appendHeaders: typeof appendResponseHeaders;
68
- export declare const setHeader: typeof setResponseHeader;
69
- export declare const setHeaders: typeof setResponseHeaders;
70
- export declare const getHeader: WrapFunction<typeof h3.getRequestHeader>;
71
- export declare const getHeaders: WrapFunction<typeof h3.getRequestHeaders>;
72
- export declare const getRequestFingerprint: WrapFunction<typeof h3.getRequestFingerprint>;
73
- export declare const getRequestWebStream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
74
- export declare const readFormData: () => Promise<FormData>;
75
- type WrappedReadValidatedBody = <T extends HTTPEvent, TEventInput = InferEventInput<"body", H3Event, T>>(...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
76
- export declare const readValidatedBody: PrependOverload<typeof h3.readValidatedBody, WrappedReadValidatedBody>;
77
- export declare const getContext: WrapFunction<typeof _getContext>;
78
- export declare const setContext: WrapFunction<typeof _setContext>;
79
- export declare const removeResponseHeader: (name: string) => void;
80
- export declare const clearResponseHeaders: (headerNames?: string[]) => void;
81
- export {};
1
+ import "server-only";
2
+ export * from "./http.ts";
@@ -1,129 +1,6 @@
1
- import * as h3 from "h3";
2
- import { getRequestEvent } from "solid-js/web";
3
- function _setContext(event, key, value) {
4
- event.context[key] = value;
5
- }
6
- function _getContext(event, key) {
7
- return event.context[key];
8
- }
9
- function getEvent() {
10
- return getRequestEvent().nativeEvent;
11
- }
12
- export function getWebRequest() {
13
- return getEvent().req;
14
- }
15
- export const HTTPEventSymbol = Symbol("$HTTPEvent");
16
- export function isEvent(obj) {
17
- return (typeof obj === "object" &&
18
- (obj instanceof h3.H3Event ||
19
- obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
20
- obj?.__is_event__ === true));
21
- // Implement logic to check if obj is an H3Event
22
- }
23
- function createWrapperFunction(h3Function) {
24
- return ((...args) => {
25
- const event = args[0];
26
- if (!isEvent(event)) {
27
- args.unshift(getEvent());
28
- }
29
- else {
30
- args[0] =
31
- event instanceof h3.H3Event || event.__is_event__ ? event : event[HTTPEventSymbol];
32
- }
33
- return h3Function(...args);
34
- });
35
- }
36
- export const readBody = createWrapperFunction(h3.readBody);
37
- export const getQuery = createWrapperFunction(h3.getQuery);
38
- export const isMethod = createWrapperFunction(h3.isMethod);
39
- export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
40
- export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery);
41
- export const getRouterParams = createWrapperFunction(h3.getRouterParams);
42
- export const getRouterParam = createWrapperFunction(h3.getRouterParam);
43
- export const getValidatedRouterParams = createWrapperFunction(h3.getValidatedRouterParams);
44
- export const assertMethod = createWrapperFunction(h3.assertMethod);
45
- export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
46
- export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
47
- export const getRequestURL = createWrapperFunction(h3.getRequestURL);
48
- export const getRequestHost = createWrapperFunction(h3.getRequestHost);
49
- export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
50
- export const getRequestIP = createWrapperFunction(h3.getRequestIP);
51
- export const setResponseStatus = (code, text) => {
52
- const e = getEvent();
53
- if (e.res.status !== undefined)
54
- e.res.status = code;
55
- if (e.res.statusText !== undefined)
56
- e.res.statusText = text;
57
- };
58
- export const getResponseStatus = () => getEvent().res.status;
59
- export const getResponseStatusText = () => getEvent().res.statusText;
60
- export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
61
- export const getResponseHeader = (name) => getEvent().res.headers.get(name);
62
- export const setResponseHeaders = (values) => {
63
- const headers = getEvent().res.headers;
64
- for (const [name, value] of Object.entries(values)) {
65
- headers.set(name, value);
66
- }
67
- };
68
- export const setResponseHeader = (name, value) => {
69
- const headers = getEvent().res.headers;
70
- (Array.isArray(value) ? value : [value]).forEach(value => {
71
- headers.set(name, value);
72
- });
73
- };
74
- export const appendResponseHeaders = (values) => {
75
- const headers = getEvent().res.headers;
76
- for (const [name, value] of Object.entries(values)) {
77
- headers.append(name, value);
78
- }
79
- };
80
- export const appendResponseHeader = (name, value) => {
81
- const headers = getEvent().res.headers;
82
- (Array.isArray(value) ? value : [value]).forEach(value => {
83
- headers.append(name, value);
84
- });
85
- };
86
- export const defaultContentType = (type) => getEvent().res.headers.set("content-type", type);
87
- export const proxyRequest = createWrapperFunction(h3.proxyRequest);
88
- export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
89
- export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
90
- export const parseCookies = createWrapperFunction(h3.parseCookies);
91
- export const getCookie = createWrapperFunction(h3.getCookie);
92
- export const setCookie = createWrapperFunction(h3.setCookie);
93
- export const deleteCookie = createWrapperFunction(h3.deleteCookie);
94
- export const useSession = createWrapperFunction(h3.useSession);
95
- export const getSession = createWrapperFunction(h3.getSession);
96
- export const updateSession = createWrapperFunction(h3.updateSession);
97
- export const sealSession = createWrapperFunction(h3.sealSession);
98
- export const unsealSession = createWrapperFunction(h3.unsealSession);
99
- export const clearSession = createWrapperFunction(h3.clearSession);
100
- export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
101
- export const handleCors = createWrapperFunction(h3.handleCors);
102
- export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
103
- export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
104
- export const appendHeader = appendResponseHeader;
105
- export const appendHeaders = appendResponseHeaders;
106
- export const setHeader = setResponseHeader;
107
- export const setHeaders = setResponseHeaders;
108
- export const getHeader = getRequestHeader;
109
- export const getHeaders = getRequestHeaders;
110
- export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
111
- export const getRequestWebStream = () => getEvent().req.body;
112
- export const readFormData = () => getEvent().req.formData();
113
- export const readValidatedBody = createWrapperFunction(h3.readValidatedBody);
114
- export const getContext = createWrapperFunction(_getContext);
115
- export const setContext = createWrapperFunction(_setContext);
116
- export const removeResponseHeader = (name) => getEvent().res.headers.delete(name);
117
- export const clearResponseHeaders = (headerNames) => {
118
- const headers = getEvent().res.headers;
119
- if (headerNames && headerNames.length > 0) {
120
- for (const name of headerNames) {
121
- headers.delete(name);
122
- }
123
- }
124
- else {
125
- for (const name of headers.keys()) {
126
- headers.delete(name);
127
- }
128
- }
129
- };
1
+ // The public `@solidjs/start/http` entry is server-only: importing it from
2
+ // client-reachable code fails at resolve time (#2068). Internal isomorphic
3
+ // code (e.g. `<HttpHeader>`) imports `./http.ts` directly, since it only
4
+ // touches these helpers behind an `isServer` check.
5
+ import "server-only";
6
+ export * from "./http.js";
@@ -1,3 +1,4 @@
1
+ import "server-only";
1
2
  import type { Middleware } from "h3";
2
3
  import type { FetchEvent } from "../server/types.ts";
3
4
  /** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
@@ -1,4 +1,5 @@
1
1
  // @refresh skip
2
+ import "server-only";
2
3
  import { getFetchEvent } from "../server/fetchEvent.js";
3
4
  function wrapRequestMiddleware(onRequest) {
4
5
  return async (h3Event) => {
@@ -53,7 +54,10 @@ export function createMiddleware(args) {
53
54
  mw.push(wrapResponseMiddleware(args.onBeforeResponse));
54
55
  }
55
56
  else if (Array.isArray(args.onBeforeResponse)) {
56
- mw.push(...args.onBeforeResponse.map(wrapResponseMiddleware));
57
+ // h3 middleware compose onion-style: logic after `await next()` unwinds
58
+ // innermost-first (reverse registration order). Register the wrappers
59
+ // reversed so onBeforeResponse functions run in their declared order.
60
+ mw.push(...args.onBeforeResponse.map(wrapResponseMiddleware).reverse());
57
61
  }
58
62
  return mw;
59
63
  }
@@ -19,7 +19,7 @@ export function StartServer(props) {
19
19
  <TopErrorBoundary>
20
20
  <props.document assets={<HydrationScript />} scripts={<>
21
21
  <PatchVirtualDevStyles nonce={nonce}/>
22
- <script type="module" nonce={nonce} async src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}/>
22
+ <script type="module" nonce={nonce} async src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY_URL)}/>
23
23
  </>}>
24
24
  {!import.meta.env.START_ISLANDS ? (<Hydration>
25
25
  <ErrorBoundary>
@@ -3,5 +3,15 @@ import type { FetchEvent } from "./types.ts";
3
3
  export declare function createFetchEvent(event: H3Event): FetchEvent;
4
4
  export declare function getFetchEvent(h3Event: H3Event): FetchEvent;
5
5
  export declare function mergeResponseHeaders(h3Event: H3Event, headers: Headers): void;
6
+ /**
7
+ * Wrap an h3 event handler so Solid's request context is available while it runs.
8
+ *
9
+ * @experimental
10
+ */
6
11
  export declare const decorateHandler: <T extends EventHandler>(fn: T) => T;
12
+ /**
13
+ * Wrap h3 middleware so Solid's request context is available while it runs.
14
+ *
15
+ * @experimental
16
+ */
7
17
  export declare const decorateMiddleware: <T extends Middleware>(fn: T) => T;
@@ -22,5 +22,15 @@ export function mergeResponseHeaders(h3Event, headers) {
22
22
  h3Event.res.headers.append(key, value);
23
23
  }
24
24
  }
25
+ /**
26
+ * Wrap an h3 event handler so Solid's request context is available while it runs.
27
+ *
28
+ * @experimental
29
+ */
25
30
  export const decorateHandler = (fn) => (event => provideRequestEvent(getFetchEvent(event), () => fn(event)));
31
+ /**
32
+ * Wrap h3 middleware so Solid's request context is available while it runs.
33
+ *
34
+ * @experimental
35
+ */
26
36
  export const decorateMiddleware = (fn) => ((event, next) => provideRequestEvent(getFetchEvent(event), () => fn(event, next)));
@@ -8,6 +8,8 @@ import { getSsrManifest } from "./manifest/ssr-manifest.js";
8
8
  import { matchAPIRoute } from "./routes.js";
9
9
  import { handleServerFunction } from "../fns/handler.js";
10
10
  import { getExpectedRedirectStatus } from "./util.js";
11
+ import { toWebReadableStream } from "./web-stream.js";
12
+ import { stripPathBase } from "./strip-path-base.js";
11
13
  const SERVER_FN_BASE = "/_server";
12
14
  export function createBaseHandler(createPageEvent, fn, options = {}) {
13
15
  const handler = defineHandler({
@@ -93,14 +95,9 @@ export function createBaseHandler(createPageEvent, fn, options = {}) {
93
95
  if (mode === "async")
94
96
  return await stream;
95
97
  delete stream.then;
96
- // using TransformStream in dev can cause solid-start-dev-server to crash
97
- // when stream is cancelled
98
- if (globalThis.USING_SOLID_START_DEV_SERVER)
99
- return stream;
100
- // returning stream directly breaks cloudflare workers
101
- const { writable, readable } = new TransformStream();
102
- stream.pipeTo(writable);
103
- return readable;
98
+ // h3 expects a standard web ReadableStream across runtimes. The adapter
99
+ // also tolerates cancellation while Solid finishes outstanding work.
100
+ return toWebReadableStream(stream);
104
101
  }),
105
102
  });
106
103
  const app = new H3();
@@ -216,7 +213,6 @@ function produceResponseWithEventHeaders(res) {
216
213
  return ret;
217
214
  }
218
215
  function stripBaseUrl(path) {
219
- if (import.meta.env.BASE_URL === "/" || import.meta.env.BASE_URL === "")
220
- return path;
221
- return path.slice(import.meta.env.BASE_URL.length);
216
+ const base = import.meta.env.SERVER_BASE_URL || import.meta.env.BASE_URL || "/";
217
+ return stripPathBase(path, base);
222
218
  }
@@ -1,6 +1,7 @@
1
1
  export { default as lazy } from "../shared/lazy.ts";
2
2
  export { getServerFunctionMeta } from "../shared/serverFunction.ts";
3
3
  export { StartServer } from "./StartServer.tsx";
4
+ export { decorateHandler, decorateMiddleware } from "./fetchEvent.ts";
4
5
  export { createHandler } from "./handler.ts";
5
6
  export type { APIEvent, APIHandler, Asset, ContextMatches, DocumentComponentProps, FetchEvent, HandlerOptions, PageEvent, ResponseStub, ServerFunctionMeta, } from "./types.ts";
6
7
  /**
@@ -1,6 +1,7 @@
1
1
  export { default as lazy } from "../shared/lazy.js";
2
2
  export { getServerFunctionMeta } from "../shared/serverFunction.js";
3
3
  export { StartServer } from "./StartServer.jsx";
4
+ export { decorateHandler, decorateMiddleware } from "./fetchEvent.js";
4
5
  export { createHandler } from "./handler.js";
5
6
  /**
6
7
  * Checks if user has set a redirect status in the response.
@@ -18,7 +18,7 @@ export function StartServer(props) {
18
18
  <TopErrorBoundary>
19
19
  <props.document scripts={<>
20
20
  <PatchVirtualDevStyles nonce={nonce}/>
21
- <script type="module" src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}/>
21
+ <script type="module" src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY_URL)}/>
22
22
  </>}/>
23
23
  </TopErrorBoundary>
24
24
  </NoHydration>);
@@ -0,0 +1 @@
1
+ export declare function stripPathBase(path: string, base: string): string;
@@ -0,0 +1,10 @@
1
+ export function stripPathBase(path, base) {
2
+ if (!base || base === "/")
3
+ return path;
4
+ const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
5
+ if (path === normalizedBase)
6
+ return "/";
7
+ if (path.startsWith(`${normalizedBase}/`))
8
+ return path.slice(normalizedBase.length);
9
+ return path;
10
+ }
@@ -0,0 +1,9 @@
1
+ type PipeableStream = {
2
+ pipe(writable: {
3
+ write(payload: string): void;
4
+ end(): void;
5
+ }): void;
6
+ };
7
+ /** Convert Solid's streaming SSR result into a cancellation-safe web stream. */
8
+ export declare function toWebReadableStream(stream: PipeableStream): ReadableStream<Uint8Array>;
9
+ export {};
@@ -0,0 +1,26 @@
1
+ /** Convert Solid's streaming SSR result into a cancellation-safe web stream. */
2
+ export function toWebReadableStream(stream) {
3
+ const encoder = new TextEncoder();
4
+ let active = true;
5
+ return new ReadableStream({
6
+ start(controller) {
7
+ stream.pipe({
8
+ write(payload) {
9
+ if (active)
10
+ controller.enqueue(encoder.encode(payload));
11
+ },
12
+ end() {
13
+ if (!active)
14
+ return;
15
+ active = false;
16
+ controller.close();
17
+ },
18
+ });
19
+ },
20
+ cancel() {
21
+ // Solid may still resolve Suspense resources after the response is
22
+ // cancelled. Ignore those writes and let Solid finish its cleanup.
23
+ active = false;
24
+ },
25
+ });
26
+ }
@@ -1,7 +1,7 @@
1
1
  // @refresh skip
2
2
  import { onCleanup } from "solid-js";
3
3
  import { getRequestEvent, isServer } from "solid-js/web";
4
- import { appendHeader, setHeader } from "../http/index.js";
4
+ import { appendHeader, setHeader } from "../http/http.js";
5
5
  /**
6
6
  *
7
7
  * Read more: https://docs.solidjs.com/solid-start/reference/server/http-header