@solidjs/start 2.0.0-beta.8 → 2.0.0-beta.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @solidjs/start
2
2
 
3
+ ## 2.0.0-beta.9
4
+
5
+ ### Minor Changes
6
+
7
+ - f3e84ec: Add support for `server-only` and `client-only` modules
8
+
9
+ ### Patch Changes
10
+
11
+ - a8a2328: fix: mark `@solidjs/start/http` and `@solidjs/start/middleware` as `server-only` so importing them from client-reachable code fails loudly at dev/build time, instead of silently shipping them to the browser where they crashed hydration and broke unrelated actions/forms with no diagnostic (#2068)
12
+
3
13
  ## 2.0.0-beta.8
4
14
 
5
15
  ### Patch Changes
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Supports `server-only` and `client-only` marker modules (#2162): importing
4
+ * `server-only` from a client module (or `client-only` from a server module)
5
+ * fails at resolve time; in the allowed environment the marker resolves to an
6
+ * empty module.
7
+ *
8
+ * Start's own server-only entry points (`@solidjs/start/http`,
9
+ * `@solidjs/start/middleware`) import `server-only` themselves, so pulling
10
+ * them into the client bundle fails loudly instead of shipping server code to
11
+ * the browser, where it crashed hydration and broke unrelated actions/forms
12
+ * with no diagnostic (https://github.com/solidjs/solid-start/issues/2068).
13
+ */
14
+ export declare function boundaryModules(): Plugin;
@@ -0,0 +1,41 @@
1
+ const VIRTUAL_ID = "\0solid-start:boundary-modules:id";
2
+ /**
3
+ * Supports `server-only` and `client-only` marker modules (#2162): importing
4
+ * `server-only` from a client module (or `client-only` from a server module)
5
+ * fails at resolve time; in the allowed environment the marker resolves to an
6
+ * empty module.
7
+ *
8
+ * Start's own server-only entry points (`@solidjs/start/http`,
9
+ * `@solidjs/start/middleware`) import `server-only` themselves, so pulling
10
+ * them into the client bundle fails loudly instead of shipping server code to
11
+ * the browser, where it crashed hydration and broke unrelated actions/forms
12
+ * with no diagnostic (https://github.com/solidjs/solid-start/issues/2068).
13
+ */
14
+ export function boundaryModules() {
15
+ return {
16
+ name: "solid-start:boundary-modules",
17
+ enforce: "pre",
18
+ resolveId(id, importer, { ssr }) {
19
+ if (id === "server-only") {
20
+ if (!ssr)
21
+ this.error(`Attempt to import 'server-only' in a client module: ${importer}. ` +
22
+ `Code that uses this module must run only on the server: mark it with ` +
23
+ `"use server", or make sure it is only imported by server code.`);
24
+ }
25
+ else if (id === "client-only") {
26
+ if (ssr)
27
+ this.error(`Attempt to import 'client-only' in a server module: ${importer}. ` +
28
+ `Code that uses this module must run only in the browser: make sure it ` +
29
+ `is only imported by client code (e.g. wrap components with clientOnly()).`);
30
+ }
31
+ else {
32
+ return null;
33
+ }
34
+ return VIRTUAL_ID;
35
+ },
36
+ load(id) {
37
+ if (id === VIRTUAL_ID)
38
+ return "export {}";
39
+ },
40
+ };
41
+ }
@@ -3,6 +3,7 @@ import { globSync } from "node:fs";
3
3
  import { extname, isAbsolute, join } from "node:path";
4
4
  import solid from "vite-plugin-solid";
5
5
  import { serverFunctionsPlugin } from "../directives/index.js";
6
+ import { boundaryModules } from "./boundary-modules.js";
6
7
  import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.js";
7
8
  import { devServer } from "./dev-server.js";
8
9
  import { envPlugin } from "./env.js";
@@ -185,6 +186,29 @@ export function solidStart(options) {
185
186
  }),
186
187
  lazy(),
187
188
  envPlugin(options?.env),
189
+ boundaryModules(),
190
+ {
191
+ name: "solid-start:boundary-modules",
192
+ enforce: "pre",
193
+ resolveId(id, importer, { ssr }) {
194
+ if (id === "server-only") {
195
+ if (!ssr)
196
+ this.error(`Attempt to import 'server-only' in a client module: ${importer}`);
197
+ }
198
+ else if (id === "client-only") {
199
+ if (ssr)
200
+ this.error(`Attempt to import 'client-only' in a server module: ${importer}`);
201
+ }
202
+ else {
203
+ return null;
204
+ }
205
+ return "\0solid-start:boundary-modules:id";
206
+ },
207
+ load(id) {
208
+ if (id === "\0solid-start:boundary-modules:id")
209
+ return "export {}";
210
+ },
211
+ },
188
212
  {
189
213
  name: "solid-start:virtual-modules",
190
214
  async resolveId(id) {
@@ -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) => {
@@ -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
package/env.d.ts CHANGED
@@ -7,3 +7,15 @@ declare namespace App {
7
7
  [key: string | symbol]: any;
8
8
  }
9
9
  }
10
+
11
+ /**
12
+ * Import `server-only` to ensure this module is never bundled for the client.
13
+ * Importing it in a client module will throw a build error.
14
+ */
15
+ declare module "server-only" {}
16
+
17
+ /**
18
+ * Import `client-only` to ensure this module is never bundled for the server.
19
+ * Importing it in a server module will throw a build error.
20
+ */
21
+ declare module "client-only" {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/start",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-beta.9",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",