@solidjs/start 2.0.0-beta.7 → 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 +17 -0
- package/dist/config/boundary-modules.d.ts +14 -0
- package/dist/config/boundary-modules.js +41 -0
- package/dist/config/env.js +5 -4
- package/dist/config/index.js +24 -0
- package/dist/directives/index.js +39 -7
- package/dist/fns/handler.js +27 -2
- package/dist/fns/registration.d.ts +2 -1
- package/dist/fns/registration.js +4 -1
- package/dist/http/http.d.ts +81 -0
- package/dist/http/http.js +129 -0
- package/dist/http/index.d.ts +2 -81
- package/dist/http/index.js +6 -129
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/shared/HttpHeader.jsx +1 -1
- package/env.d.ts +12 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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
|
+
|
|
13
|
+
## 2.0.0-beta.8
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- ecc02be: fix: resolve server functions in dev when their route was reached through client-side navigation before its module was evaluated on the server
|
|
18
|
+
- 85b24b2: Use per-environment Vite plugin hook APIs for forward compatibility with Vite 9.
|
|
19
|
+
|
|
3
20
|
## 2.0.0-beta.7
|
|
4
21
|
|
|
5
22
|
### 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
|
+
}
|
package/dist/config/env.js
CHANGED
|
@@ -47,9 +47,10 @@ export function envPlugin(options) {
|
|
|
47
47
|
}
|
|
48
48
|
return undefined;
|
|
49
49
|
},
|
|
50
|
-
load(id
|
|
50
|
+
load(id) {
|
|
51
|
+
const isServer = this.environment.config.consumer === "server";
|
|
51
52
|
if (id === SERVER_ENV) {
|
|
52
|
-
if (!
|
|
53
|
+
if (!isServer) {
|
|
53
54
|
return SERVER_ONLY_MODULE;
|
|
54
55
|
}
|
|
55
56
|
const vars = currentOptions.server?.load
|
|
@@ -64,13 +65,13 @@ export function envPlugin(options) {
|
|
|
64
65
|
return convertObjectToModule(vars);
|
|
65
66
|
}
|
|
66
67
|
if (id === SERVER_RUNTIME_LOADER) {
|
|
67
|
-
if (!
|
|
68
|
+
if (!isServer) {
|
|
68
69
|
return SERVER_ONLY_MODULE;
|
|
69
70
|
}
|
|
70
71
|
return runtimeCode;
|
|
71
72
|
}
|
|
72
73
|
if (id === SERVER_RUNTIME_ENV) {
|
|
73
|
-
if (!
|
|
74
|
+
if (!isServer) {
|
|
74
75
|
return SERVER_ONLY_MODULE;
|
|
75
76
|
}
|
|
76
77
|
return SERVER_RUNTIME_CODE;
|
package/dist/config/index.js
CHANGED
|
@@ -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) {
|
package/dist/directives/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { createFilter, } from "vite";
|
|
2
|
+
import fg from "fast-glob";
|
|
2
3
|
import { compile } from "./compile.js";
|
|
4
|
+
import xxHash32 from "./xxhash32.js";
|
|
3
5
|
const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
|
|
4
6
|
const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
|
|
5
7
|
const DIRECTIVE = "use server";
|
|
8
|
+
// Dev-only virtual module used by fns/handler.ts to lazily resolve a server
|
|
9
|
+
// function id back to its owning module when the function was never evaluated
|
|
10
|
+
// in the server environment (e.g. its route was only client-side navigated to).
|
|
11
|
+
const LOOKUP_ID = "solid-start:server-fn-lookup";
|
|
6
12
|
function createManifest() {
|
|
7
13
|
return {
|
|
8
14
|
server: new Set(),
|
|
@@ -63,8 +69,11 @@ function invalidateModule(moduleGraph, path) {
|
|
|
63
69
|
function invalidateModules(server, result, manifest) {
|
|
64
70
|
if (server) {
|
|
65
71
|
if (result.invalidPreload) {
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
// Environments are not limited to "client"/"ssr": plugins like nitro
|
|
73
|
+
// render in their own environment (e.g. "nitro"), so invalidate everywhere.
|
|
74
|
+
for (const environment of Object.values(server.environments)) {
|
|
75
|
+
invalidateModule(environment.moduleGraph, manifest);
|
|
76
|
+
}
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
}
|
|
@@ -125,24 +134,47 @@ export function serverFunctionsPlugin(options) {
|
|
|
125
134
|
if (source === options.manifest) {
|
|
126
135
|
return { id: options.manifest, moduleSideEffects: true };
|
|
127
136
|
}
|
|
137
|
+
if (source.startsWith(LOOKUP_ID)) {
|
|
138
|
+
return { id: source, moduleSideEffects: true };
|
|
139
|
+
}
|
|
128
140
|
return null;
|
|
129
141
|
},
|
|
130
|
-
async load(id
|
|
131
|
-
const mode =
|
|
142
|
+
async load(id) {
|
|
143
|
+
const mode = this.environment.config.consumer;
|
|
132
144
|
if (id === options.manifest) {
|
|
133
145
|
const current = new Debouncer(() => [...manifest[mode]].map(entry => `import "${entry}";`).join("\n"));
|
|
134
146
|
preload[mode] = current;
|
|
135
147
|
const result = await current.promise.reference;
|
|
136
148
|
return result;
|
|
137
149
|
}
|
|
150
|
+
if (id.startsWith(LOOKUP_ID)) {
|
|
151
|
+
if (this.environment.mode !== "dev") {
|
|
152
|
+
throw new Error(`${LOOKUP_ID} is only available in dev`);
|
|
153
|
+
}
|
|
154
|
+
const functionId = new URLSearchParams(id.slice(LOOKUP_ID.length + 1)).get("id");
|
|
155
|
+
// dev function ids are `${xxHash32(file)}-${count}-${name}`
|
|
156
|
+
const hash = functionId?.split("-")[0];
|
|
157
|
+
if (!hash)
|
|
158
|
+
return "export {};";
|
|
159
|
+
// Look through the files already discovered by the transform first;
|
|
160
|
+
// fall back to scanning the project so a function is found even when
|
|
161
|
+
// the browser kept a chunk from before a dev server restart.
|
|
162
|
+
let files = [...manifest.server].filter(file => xxHash32(file).toString(16) === hash);
|
|
163
|
+
if (files.length === 0) {
|
|
164
|
+
files = fg
|
|
165
|
+
.sync(DEFAULT_INCLUDE, { cwd: this.environment.config.root, absolute: true })
|
|
166
|
+
.filter(file => filter(file) && xxHash32(file).toString(16) === hash);
|
|
167
|
+
}
|
|
168
|
+
return files.map(file => `import ${JSON.stringify(file)};`).join("\n") || "export {};";
|
|
169
|
+
}
|
|
138
170
|
return null;
|
|
139
171
|
},
|
|
140
172
|
},
|
|
141
173
|
{
|
|
142
174
|
name: "solid-start:server-functions/compiler",
|
|
143
|
-
enforce:
|
|
144
|
-
async transform(code, fileId
|
|
145
|
-
const mode =
|
|
175
|
+
enforce: "pre",
|
|
176
|
+
async transform(code, fileId) {
|
|
177
|
+
const mode = this.environment.config.consumer;
|
|
146
178
|
const [id] = fileId.split("?");
|
|
147
179
|
if (!filter(id)) {
|
|
148
180
|
return null;
|
package/dist/fns/handler.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
1
9
|
import { parseSetCookie } from "cookie-es";
|
|
2
10
|
import { parseCookies } from "h3";
|
|
3
11
|
import { sharedConfig } from "solid-js";
|
|
@@ -6,9 +14,9 @@ import { provideRequestEvent } from "solid-js/web/storage";
|
|
|
6
14
|
import { getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent.js";
|
|
7
15
|
import { createPageEvent } from "../server/handler.js";
|
|
8
16
|
import { deserializeFromJSONString, serializeToJSONStream, serializeToJSStream, } from "./serialization.js";
|
|
9
|
-
import { BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody
|
|
17
|
+
import { BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody } from "./shared.js";
|
|
10
18
|
import "solid-start:server-fn-manifest";
|
|
11
|
-
import { getServerFunction } from "./registration.js";
|
|
19
|
+
import { getServerFunction, hasServerFunction } from "./registration.js";
|
|
12
20
|
import { getExpectedRedirectStatus } from "../server/util.js";
|
|
13
21
|
export async function handleServerFunction(h3Event) {
|
|
14
22
|
const event = getFetchEvent(h3Event);
|
|
@@ -30,6 +38,23 @@ export async function handleServerFunction(h3Event) {
|
|
|
30
38
|
: new Response(null, { status: 404 });
|
|
31
39
|
}
|
|
32
40
|
}
|
|
41
|
+
if (import.meta.env.DEV && !hasServerFunction(functionId)) {
|
|
42
|
+
// The module that owns this function has not been evaluated in the server
|
|
43
|
+
// environment yet (e.g. the route was reached by client-side navigation, so
|
|
44
|
+
// it was only ever loaded in the browser). Ask the dev server to resolve the
|
|
45
|
+
// function id back to its owning module and import it, which registers it.
|
|
46
|
+
// Resolved by the "solid-start:server-functions/preload" plugin.
|
|
47
|
+
try {
|
|
48
|
+
// the /@id/ prefix routes the request through the plugin container so the
|
|
49
|
+
// virtual module can be resolved (bare ids get node-resolved by the runner)
|
|
50
|
+
await import(__rewriteRelativeImportExtension(
|
|
51
|
+
/* @vite-ignore */ `/@id/solid-start:server-fn-lookup?id=${encodeURIComponent(functionId)}`, true));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// fall through to getServerFunction, which reports the missing function
|
|
55
|
+
console.error("[solid-start] server function lookup failed:", error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
33
58
|
const serverFunction = getServerFunction(functionId);
|
|
34
59
|
let parsed = [];
|
|
35
60
|
// grab bound arguments from url when no JS
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare function registerServerFunction<T extends any[], R>(id: string, callback: (...args: T) => Promise<R>): (...args: T) => Promise<R>;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function hasServerFunction(id: string): boolean;
|
|
3
|
+
export declare function getServerFunction<T extends any[], R>(id: string): (...args: T) => Promise<R>;
|
package/dist/fns/registration.js
CHANGED
|
@@ -3,10 +3,13 @@ export function registerServerFunction(id, callback) {
|
|
|
3
3
|
REGISTRATIONS.set(id, callback);
|
|
4
4
|
return callback;
|
|
5
5
|
}
|
|
6
|
+
export function hasServerFunction(id) {
|
|
7
|
+
return REGISTRATIONS.has(id);
|
|
8
|
+
}
|
|
6
9
|
export function getServerFunction(id) {
|
|
7
10
|
const fn = REGISTRATIONS.get(id);
|
|
8
11
|
if (fn) {
|
|
9
12
|
return fn;
|
|
10
13
|
}
|
|
11
|
-
throw new Error(
|
|
14
|
+
throw new Error("invalid server function: " + id);
|
|
12
15
|
}
|
|
@@ -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
|
+
};
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,81 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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";
|
package/dist/http/index.js
CHANGED
|
@@ -1,129 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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";
|
package/dist/middleware/index.js
CHANGED
|
@@ -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/
|
|
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.
|
|
3
|
+
"version": "2.0.0-beta.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -66,13 +66,14 @@
|
|
|
66
66
|
"vitest": "^4.1.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"vite": "^8"
|
|
69
|
+
"vite": "^8 || ^9"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "pnpm validate-imports && tsc && node scripts/build.js",
|
|
73
73
|
"dev": "tsc --watch",
|
|
74
74
|
"test": "vitest",
|
|
75
75
|
"test:ci": "vitest run",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
76
77
|
"typecheck:dist": "pnpm build && pnpx @arethetypeswrong/cli --pack . --profile esm-only",
|
|
77
78
|
"validate-imports": "node scripts/validate-imports.js"
|
|
78
79
|
}
|