@solidjs/start 2.0.0-alpha.2 → 2.0.0-alpha.3
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 +19 -0
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.js +1 -1
- package/dist/config/dev-server.js +9 -1
- package/dist/config/env.d.ts +19 -0
- package/dist/config/env.js +81 -0
- package/dist/config/fs-routes/fs-watcher.js +14 -20
- package/dist/config/fs-routes/index.js +2 -2
- package/dist/config/fs-routes/router.js +2 -2
- package/dist/config/index.d.ts +16 -1
- package/dist/config/index.js +25 -27
- package/dist/config/lazy.js +2 -2
- package/dist/config/manifest.js +37 -4
- package/dist/config/vite-utils.d.ts +1 -1
- package/dist/directives/bubble-function-declaration.d.ts +3 -0
- package/dist/directives/bubble-function-declaration.js +23 -0
- package/dist/directives/compile.d.ts +9 -0
- package/dist/directives/compile.js +40 -0
- package/dist/directives/generate-unique-name.d.ts +3 -0
- package/dist/directives/generate-unique-name.js +16 -0
- package/dist/directives/get-descriptive-name.d.ts +2 -0
- package/dist/directives/get-descriptive-name.js +37 -0
- package/dist/directives/get-import-identifier.d.ts +4 -0
- package/dist/directives/get-import-identifier.js +19 -0
- package/dist/directives/get-root-statement-path.d.ts +2 -0
- package/dist/directives/get-root-statement-path.js +12 -0
- package/dist/directives/index.d.ts +14 -0
- package/dist/directives/index.js +169 -0
- package/dist/directives/is-statement-top-level.d.ts +3 -0
- package/dist/directives/is-statement-top-level.js +9 -0
- package/dist/directives/paths.d.ts +9 -0
- package/dist/directives/paths.js +36 -0
- package/dist/directives/plugin.d.ts +21 -0
- package/dist/directives/plugin.js +302 -0
- package/dist/directives/remove-unused-variables.d.ts +3 -0
- package/dist/directives/remove-unused-variables.js +53 -0
- package/dist/directives/types.d.ts +10 -0
- package/dist/directives/xxhash32.d.ts +6 -0
- package/dist/directives/xxhash32.js +193 -0
- package/dist/{server/server-runtime.d.ts → fns/client.d.ts} +1 -1
- package/dist/fns/client.js +106 -0
- package/dist/fns/handler.d.ts +5 -0
- package/dist/{server/server-functions-handler.js → fns/handler.js} +55 -96
- package/dist/fns/registration.d.ts +2 -0
- package/dist/fns/registration.js +12 -0
- package/dist/fns/serialization.d.ts +6 -0
- package/dist/fns/serialization.js +208 -0
- package/dist/fns/server.d.ts +7 -0
- package/dist/{server/server-fns-runtime.js → fns/server.js} +7 -1
- package/dist/fns/shared.d.ts +17 -0
- package/dist/fns/shared.js +105 -0
- package/dist/http/index.d.ts +1 -1
- package/dist/middleware/index.d.ts +17 -0
- package/dist/middleware/index.js +15 -0
- package/dist/server/handler.d.ts +61 -3
- package/dist/server/handler.js +17 -15
- package/dist/server/spa/handler.d.ts +30 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/shared/dev-overlay/CodeView.jsx +4 -4
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +34 -34
- package/dist/shared/dev-overlay/index.jsx +2 -2
- package/dist/shared/dev-overlay/styles.css +40 -40
- package/package.json +27 -20
- package/src/config/constants.ts +1 -1
- package/src/config/env.ts +105 -0
- package/src/config/fs-routes/fs-watcher.ts +17 -24
- package/src/config/fs-routes/index.ts +2 -2
- package/src/config/fs-routes/router.ts +2 -2
- package/src/config/index.ts +39 -37
- package/src/config/lazy.ts +2 -2
- package/src/config/manifest.ts +37 -7
- package/src/config/vite-utils.ts +1 -1
- package/src/directives/bubble-function-declaration.ts +33 -0
- package/src/directives/compile.ts +54 -0
- package/src/directives/generate-unique-name.ts +22 -0
- package/src/directives/get-descriptive-name.ts +39 -0
- package/src/directives/get-import-identifier.ts +34 -0
- package/src/directives/get-root-statement-path.ts +14 -0
- package/src/directives/index.ts +232 -0
- package/src/directives/is-statement-top-level.ts +13 -0
- package/src/directives/paths.ts +63 -0
- package/src/directives/plugin.ts +389 -0
- package/src/directives/remove-unused-variables.ts +55 -0
- package/src/directives/types.ts +12 -0
- package/src/directives/xxhash32.ts +214 -0
- package/src/env.d.ts +1 -1
- package/src/fns/client.ts +141 -0
- package/src/fns/handler.spec.ts +85 -0
- package/src/{server/server-functions-handler.ts → fns/handler.ts} +65 -117
- package/src/fns/registration.ts +19 -0
- package/src/fns/serialization.ts +250 -0
- package/src/{server/server-fns-runtime.ts → fns/server.ts} +17 -2
- package/src/fns/shared.ts +116 -0
- package/src/middleware/index.ts +17 -0
- package/src/server/handler.ts +18 -16
- package/src/server/types.ts +1 -1
- package/src/shared/dev-overlay/CodeView.tsx +5 -7
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +34 -34
- package/src/shared/dev-overlay/get-source-map.ts +1 -1
- package/src/shared/dev-overlay/index.tsx +4 -4
- package/src/shared/dev-overlay/styles.css +40 -40
- package/tsconfig.json +1 -0
- package/dist/server/fetchEvent.spec.js +0 -65
- package/dist/server/server-fns-runtime.d.ts +0 -1
- package/dist/server/server-functions-handler.d.ts +0 -2
- package/dist/server/server-runtime.js +0 -194
- package/src/server/server-runtime.ts +0 -240
- /package/dist/{server/fetchEvent.spec.d.ts → directives/types.js} +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { crossSerializeStream, deserialize, Feature, fromCrossJSON, getCrossReferenceHeader, toCrossJSONStream, } from "seroval";
|
|
2
|
+
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLPlugin, URLSearchParamsPlugin, } from "seroval-plugins/web";
|
|
3
|
+
// TODO(Alexis): if we can, allow providing an option to extend these.
|
|
4
|
+
const DEFAULT_PLUGINS = [
|
|
5
|
+
AbortSignalPlugin,
|
|
6
|
+
CustomEventPlugin,
|
|
7
|
+
DOMExceptionPlugin,
|
|
8
|
+
EventPlugin,
|
|
9
|
+
FormDataPlugin,
|
|
10
|
+
HeadersPlugin,
|
|
11
|
+
ReadableStreamPlugin,
|
|
12
|
+
RequestPlugin,
|
|
13
|
+
ResponsePlugin,
|
|
14
|
+
URLSearchParamsPlugin,
|
|
15
|
+
URLPlugin,
|
|
16
|
+
];
|
|
17
|
+
const MAX_SERIALIZATION_DEPTH_LIMIT = 64;
|
|
18
|
+
const DISABLED_FEATURES = Feature.RegExp;
|
|
19
|
+
/**
|
|
20
|
+
* Alexis:
|
|
21
|
+
*
|
|
22
|
+
* A "chunk" is a piece of data emitted by the streaming serializer.
|
|
23
|
+
* Each chunk is represented by a 32-bit value (encoded in hexadecimal),
|
|
24
|
+
* followed by the encoded string (8-bit representation). This format
|
|
25
|
+
* is important so we know how much of the chunk being streamed we
|
|
26
|
+
* are expecting before parsing the entire string data.
|
|
27
|
+
*
|
|
28
|
+
* This is sort of a bootleg "multipart/form-data" except it's bad at
|
|
29
|
+
* handling File/Blob LOL
|
|
30
|
+
*
|
|
31
|
+
* The format is as follows:
|
|
32
|
+
* ;0xFFFFFFFF;<string data>
|
|
33
|
+
*/
|
|
34
|
+
function createChunk(data) {
|
|
35
|
+
const encodeData = new TextEncoder().encode(data);
|
|
36
|
+
const bytes = encodeData.length;
|
|
37
|
+
const baseHex = bytes.toString(16);
|
|
38
|
+
const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex; // 32-bit
|
|
39
|
+
const head = new TextEncoder().encode(`;0x${totalHex};`);
|
|
40
|
+
const chunk = new Uint8Array(12 + bytes);
|
|
41
|
+
chunk.set(head);
|
|
42
|
+
chunk.set(encodeData, 12);
|
|
43
|
+
return chunk;
|
|
44
|
+
}
|
|
45
|
+
export function serializeToJSStream(id, value) {
|
|
46
|
+
return new ReadableStream({
|
|
47
|
+
start(controller) {
|
|
48
|
+
crossSerializeStream(value, {
|
|
49
|
+
scopeId: id,
|
|
50
|
+
plugins: DEFAULT_PLUGINS,
|
|
51
|
+
onSerialize(data, initial) {
|
|
52
|
+
controller.enqueue(createChunk(initial ? `(${getCrossReferenceHeader(id)},${data})` : data));
|
|
53
|
+
},
|
|
54
|
+
onDone() {
|
|
55
|
+
controller.close();
|
|
56
|
+
},
|
|
57
|
+
onError(error) {
|
|
58
|
+
controller.error(error);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function serializeToJSONStream(value) {
|
|
65
|
+
return new ReadableStream({
|
|
66
|
+
start(controller) {
|
|
67
|
+
toCrossJSONStream(value, {
|
|
68
|
+
disabledFeatures: DISABLED_FEATURES,
|
|
69
|
+
depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
|
|
70
|
+
plugins: DEFAULT_PLUGINS,
|
|
71
|
+
onParse(node) {
|
|
72
|
+
controller.enqueue(createChunk(JSON.stringify(node)));
|
|
73
|
+
},
|
|
74
|
+
onDone() {
|
|
75
|
+
controller.close();
|
|
76
|
+
},
|
|
77
|
+
onError(error) {
|
|
78
|
+
controller.error(error);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
class SerovalChunkReader {
|
|
85
|
+
reader;
|
|
86
|
+
buffer;
|
|
87
|
+
done;
|
|
88
|
+
constructor(stream) {
|
|
89
|
+
this.reader = stream.getReader();
|
|
90
|
+
this.buffer = new Uint8Array(0);
|
|
91
|
+
this.done = false;
|
|
92
|
+
}
|
|
93
|
+
async readChunk() {
|
|
94
|
+
// if there's no chunk, read again
|
|
95
|
+
const chunk = await this.reader.read();
|
|
96
|
+
if (!chunk.done) {
|
|
97
|
+
// repopulate the buffer
|
|
98
|
+
const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
|
|
99
|
+
newBuffer.set(this.buffer);
|
|
100
|
+
newBuffer.set(chunk.value, this.buffer.length);
|
|
101
|
+
this.buffer = newBuffer;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.done = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async next() {
|
|
108
|
+
// Check if the buffer is empty
|
|
109
|
+
if (this.buffer.length === 0) {
|
|
110
|
+
// if we are already done...
|
|
111
|
+
if (this.done) {
|
|
112
|
+
return {
|
|
113
|
+
done: true,
|
|
114
|
+
value: undefined,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Otherwise, read a new chunk
|
|
118
|
+
await this.readChunk();
|
|
119
|
+
return await this.next();
|
|
120
|
+
}
|
|
121
|
+
// Read the "byte header"
|
|
122
|
+
// The byte header tells us how big the expected data is
|
|
123
|
+
// so we know how much data we should wait before we
|
|
124
|
+
// deserialize the data
|
|
125
|
+
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
126
|
+
const bytes = Number.parseInt(head, 16); // ;0x00000000;
|
|
127
|
+
if (Number.isNaN(bytes)) {
|
|
128
|
+
throw new Error("Malformed server function stream.");
|
|
129
|
+
}
|
|
130
|
+
// Check if the buffer has enough bytes to be parsed
|
|
131
|
+
while (bytes > this.buffer.length - 12) {
|
|
132
|
+
// If it's not enough, and the reader is done
|
|
133
|
+
// then the chunk is invalid.
|
|
134
|
+
if (this.done) {
|
|
135
|
+
throw new Error("Malformed server function stream.");
|
|
136
|
+
}
|
|
137
|
+
// Otherwise, we read more chunks
|
|
138
|
+
await this.readChunk();
|
|
139
|
+
}
|
|
140
|
+
// Extract the exact chunk as defined by the byte header
|
|
141
|
+
const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
|
|
142
|
+
// The rest goes to the buffer
|
|
143
|
+
this.buffer = this.buffer.subarray(12 + bytes);
|
|
144
|
+
// Deserialize the chunk
|
|
145
|
+
return {
|
|
146
|
+
done: false,
|
|
147
|
+
value: partial,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async drain(interpret) {
|
|
151
|
+
while (true) {
|
|
152
|
+
const result = await this.next();
|
|
153
|
+
if (result.done) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
interpret(result.value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export async function serializeToJSONString(value) {
|
|
163
|
+
const response = new Response(serializeToJSONStream(value));
|
|
164
|
+
return await response.text();
|
|
165
|
+
}
|
|
166
|
+
export async function deserializeFromJSONString(json) {
|
|
167
|
+
const blob = new Response(json);
|
|
168
|
+
return await deserializeJSONStream(blob);
|
|
169
|
+
}
|
|
170
|
+
export async function deserializeJSONStream(response) {
|
|
171
|
+
if (!response.body) {
|
|
172
|
+
throw new Error("missing body");
|
|
173
|
+
}
|
|
174
|
+
const reader = new SerovalChunkReader(response.body);
|
|
175
|
+
const result = await reader.next();
|
|
176
|
+
if (!result.done) {
|
|
177
|
+
const refs = new Map();
|
|
178
|
+
function interpretChunk(chunk) {
|
|
179
|
+
const value = fromCrossJSON(JSON.parse(chunk), {
|
|
180
|
+
refs,
|
|
181
|
+
disabledFeatures: DISABLED_FEATURES,
|
|
182
|
+
depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
|
|
183
|
+
plugins: DEFAULT_PLUGINS,
|
|
184
|
+
});
|
|
185
|
+
return value;
|
|
186
|
+
}
|
|
187
|
+
void reader.drain(interpretChunk);
|
|
188
|
+
return interpretChunk(result.value);
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
export async function deserializeJSStream(id, response) {
|
|
193
|
+
if (!response.body) {
|
|
194
|
+
throw new Error("missing body");
|
|
195
|
+
}
|
|
196
|
+
const reader = new SerovalChunkReader(response.body);
|
|
197
|
+
const result = await reader.next();
|
|
198
|
+
if (!result.done) {
|
|
199
|
+
reader.drain(deserialize).then(() => {
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
delete $R[id];
|
|
202
|
+
}, () => {
|
|
203
|
+
// no-op
|
|
204
|
+
});
|
|
205
|
+
return deserialize(result.value);
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface Registration<T extends any[], R> {
|
|
2
|
+
id: string;
|
|
3
|
+
fn: (...args: T) => Promise<R>;
|
|
4
|
+
}
|
|
5
|
+
export declare function createServerReference<T extends any[], R>(id: string, fn: (...args: T) => Promise<R>): Registration<T, R>;
|
|
6
|
+
export declare function cloneServerReference<T extends any[], R>({ id, fn }: Registration<T, R>): (...args: T) => Promise<R>;
|
|
7
|
+
export {};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { getRequestEvent } from "solid-js/web";
|
|
2
2
|
import { provideRequestEvent } from "solid-js/web/storage";
|
|
3
|
-
|
|
3
|
+
import { registerServerFunction } from "./registration.js";
|
|
4
|
+
export function createServerReference(id, fn) {
|
|
5
|
+
const registration = { id, fn };
|
|
6
|
+
registerServerFunction(id, fn);
|
|
7
|
+
return registration;
|
|
8
|
+
}
|
|
9
|
+
export function cloneServerReference({ id, fn }) {
|
|
4
10
|
if (typeof fn !== "function")
|
|
5
11
|
throw new Error("Export from a 'use server' module must be a function");
|
|
6
12
|
let baseURL = import.meta.env.BASE_URL ?? "/";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const BODY_FORMAT_KEY = "X-Start-Type";
|
|
2
|
+
export declare const BODY_FORMAL_FILE = "__START__";
|
|
3
|
+
export declare const enum BodyFormat {
|
|
4
|
+
Seroval = "0",
|
|
5
|
+
String = "1",
|
|
6
|
+
FormData = "2",
|
|
7
|
+
URLSearchParams = "3",
|
|
8
|
+
Blob = "4",
|
|
9
|
+
File = "5",
|
|
10
|
+
ArrayBuffer = "6",
|
|
11
|
+
Uint8Array = "7"
|
|
12
|
+
}
|
|
13
|
+
export declare function getHeadersAndBody(body: any): {
|
|
14
|
+
headers?: HeadersInit;
|
|
15
|
+
body: BodyInit;
|
|
16
|
+
} | undefined;
|
|
17
|
+
export declare function extractBody(instance: string, client: boolean, source: Request | Response): Promise<unknown>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { deserializeJSONStream, deserializeJSStream } from "./serialization.js";
|
|
2
|
+
export const BODY_FORMAT_KEY = "X-Start-Type";
|
|
3
|
+
export const BODY_FORMAL_FILE = "__START__";
|
|
4
|
+
export var BodyFormat;
|
|
5
|
+
(function (BodyFormat) {
|
|
6
|
+
BodyFormat["Seroval"] = "0";
|
|
7
|
+
BodyFormat["String"] = "1";
|
|
8
|
+
BodyFormat["FormData"] = "2";
|
|
9
|
+
BodyFormat["URLSearchParams"] = "3";
|
|
10
|
+
BodyFormat["Blob"] = "4";
|
|
11
|
+
BodyFormat["File"] = "5";
|
|
12
|
+
BodyFormat["ArrayBuffer"] = "6";
|
|
13
|
+
BodyFormat["Uint8Array"] = "7";
|
|
14
|
+
})(BodyFormat || (BodyFormat = {}));
|
|
15
|
+
export function getHeadersAndBody(body) {
|
|
16
|
+
switch (true) {
|
|
17
|
+
case typeof body === "string":
|
|
18
|
+
return {
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "text/plain",
|
|
21
|
+
[BODY_FORMAT_KEY]: BodyFormat.String,
|
|
22
|
+
},
|
|
23
|
+
body,
|
|
24
|
+
};
|
|
25
|
+
case body instanceof FormData:
|
|
26
|
+
return {
|
|
27
|
+
headers: {
|
|
28
|
+
[BODY_FORMAT_KEY]: BodyFormat.FormData,
|
|
29
|
+
},
|
|
30
|
+
body,
|
|
31
|
+
};
|
|
32
|
+
case body instanceof URLSearchParams:
|
|
33
|
+
return {
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
36
|
+
[BODY_FORMAT_KEY]: BodyFormat.URLSearchParams,
|
|
37
|
+
},
|
|
38
|
+
body,
|
|
39
|
+
};
|
|
40
|
+
case body instanceof File: {
|
|
41
|
+
const formData = new FormData();
|
|
42
|
+
formData.append(BODY_FORMAL_FILE, body, body.name);
|
|
43
|
+
return {
|
|
44
|
+
headers: {
|
|
45
|
+
[BODY_FORMAT_KEY]: BodyFormat.File,
|
|
46
|
+
},
|
|
47
|
+
body: formData,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case body instanceof Blob:
|
|
51
|
+
return {
|
|
52
|
+
headers: {
|
|
53
|
+
[BODY_FORMAT_KEY]: BodyFormat.Blob,
|
|
54
|
+
},
|
|
55
|
+
body,
|
|
56
|
+
};
|
|
57
|
+
case body instanceof ArrayBuffer:
|
|
58
|
+
return {
|
|
59
|
+
headers: {
|
|
60
|
+
[BODY_FORMAT_KEY]: BodyFormat.ArrayBuffer,
|
|
61
|
+
},
|
|
62
|
+
body,
|
|
63
|
+
};
|
|
64
|
+
case body instanceof Uint8Array:
|
|
65
|
+
return {
|
|
66
|
+
headers: {
|
|
67
|
+
[BODY_FORMAT_KEY]: BodyFormat.Uint8Array,
|
|
68
|
+
},
|
|
69
|
+
body: new Uint8Array(body),
|
|
70
|
+
};
|
|
71
|
+
default:
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function extractBody(instance, client, source) {
|
|
76
|
+
const contentType = source.headers.get("content-type");
|
|
77
|
+
const startType = source.headers.get(BODY_FORMAT_KEY);
|
|
78
|
+
const clone = source.clone();
|
|
79
|
+
switch (true) {
|
|
80
|
+
case startType === BodyFormat.Seroval:
|
|
81
|
+
if (client && import.meta.env.SEROVAL_MODE === "js") {
|
|
82
|
+
return await deserializeJSStream(instance, clone);
|
|
83
|
+
}
|
|
84
|
+
return await deserializeJSONStream(clone);
|
|
85
|
+
case startType === BodyFormat.String:
|
|
86
|
+
return await clone.text();
|
|
87
|
+
case startType === BodyFormat.File: {
|
|
88
|
+
const formData = await clone.formData();
|
|
89
|
+
return formData.get(BODY_FORMAL_FILE);
|
|
90
|
+
}
|
|
91
|
+
case startType === BodyFormat.FormData:
|
|
92
|
+
case contentType?.startsWith("multipart/form-data"):
|
|
93
|
+
return await clone.formData();
|
|
94
|
+
case startType === BodyFormat.URLSearchParams:
|
|
95
|
+
case contentType?.startsWith("application/x-www-form-urlencoded"):
|
|
96
|
+
return new URLSearchParams(await clone.text());
|
|
97
|
+
case startType === BodyFormat.Blob:
|
|
98
|
+
return await clone.blob();
|
|
99
|
+
case startType === BodyFormat.ArrayBuffer:
|
|
100
|
+
return await clone.arrayBuffer();
|
|
101
|
+
case startType === BodyFormat.Uint8Array:
|
|
102
|
+
return new Uint8Array(await clone.arrayBuffer());
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare const setHeaders: (values: Record<string, string>) => void;
|
|
|
70
70
|
export declare const getHeader: WrapFunction<typeof h3.getRequestHeader>;
|
|
71
71
|
export declare const getHeaders: WrapFunction<typeof h3.getRequestHeaders>;
|
|
72
72
|
export declare const getRequestFingerprint: WrapFunction<typeof h3.getRequestFingerprint>;
|
|
73
|
-
export declare const getRequestWebStream: () => ReadableStream<Uint8Array<
|
|
73
|
+
export declare const getRequestWebStream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
|
74
74
|
export declare const readFormData: () => Promise<FormData>;
|
|
75
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
76
|
export declare const readValidatedBody: PrependOverload<typeof h3.readValidatedBody, WrappedReadValidatedBody>;
|
|
@@ -13,9 +13,26 @@ export type ResponseMiddleware = (event: FetchEvent, response: ResponseMiddlewar
|
|
|
13
13
|
* Creates middleware for handling requests and responses.
|
|
14
14
|
*
|
|
15
15
|
* @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
|
|
16
|
+
/**
|
|
17
|
+
* Creates request/response middlewares via H3.
|
|
18
|
+
*
|
|
19
|
+
* Accepts an array of H3 {@link Middleware}
|
|
20
|
+
*
|
|
21
|
+
* @tip To run your middleware before response, `await next()` in your function block.
|
|
22
|
+
*@example
|
|
23
|
+
* const middleware = createMiddleware([
|
|
24
|
+
* async (event, next) => {
|
|
25
|
+
* const resp = await next();
|
|
26
|
+
* if (resp instanceof Response) return resp;
|
|
27
|
+
* return new Response("Not found", { status: 404 });
|
|
28
|
+
* },
|
|
29
|
+
* ]);
|
|
30
|
+
*
|
|
16
31
|
*/
|
|
17
32
|
export declare function createMiddleware(args: {
|
|
33
|
+
/** @deprecated Use H3 `Middleware` */
|
|
18
34
|
onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
|
|
35
|
+
/** @deprecated Use H3 `Middleware` */
|
|
19
36
|
onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
|
|
20
37
|
} | Middleware[]): Middleware[];
|
|
21
38
|
export {};
|
package/dist/middleware/index.js
CHANGED
|
@@ -23,6 +23,21 @@ function wrapResponseMiddleware(onBeforeResponse) {
|
|
|
23
23
|
* Creates middleware for handling requests and responses.
|
|
24
24
|
*
|
|
25
25
|
* @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
|
|
26
|
+
/**
|
|
27
|
+
* Creates request/response middlewares via H3.
|
|
28
|
+
*
|
|
29
|
+
* Accepts an array of H3 {@link Middleware}
|
|
30
|
+
*
|
|
31
|
+
* @tip To run your middleware before response, `await next()` in your function block.
|
|
32
|
+
*@example
|
|
33
|
+
* const middleware = createMiddleware([
|
|
34
|
+
* async (event, next) => {
|
|
35
|
+
* const resp = await next();
|
|
36
|
+
* if (resp instanceof Response) return resp;
|
|
37
|
+
* return new Response("Not found", { status: 404 });
|
|
38
|
+
* },
|
|
39
|
+
* ]);
|
|
40
|
+
*
|
|
26
41
|
*/
|
|
27
42
|
export function createMiddleware(args) {
|
|
28
43
|
if (Array.isArray(args))
|
package/dist/server/handler.d.ts
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type H3Event } from "h3";
|
|
2
2
|
import type { JSX } from "solid-js";
|
|
3
3
|
import type { FetchEvent, HandlerOptions, PageEvent } from "./types.ts";
|
|
4
|
-
export declare function createBaseHandler(createPageEvent: (e: FetchEvent) => Promise<PageEvent>, fn: (context: PageEvent) => JSX.Element, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>)):
|
|
5
|
-
|
|
4
|
+
export declare function createBaseHandler(createPageEvent: (e: FetchEvent) => Promise<PageEvent>, fn: (context: PageEvent) => JSX.Element, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>)): {
|
|
5
|
+
"~rou3": import("h3").RouterContext;
|
|
6
|
+
request(request: import("srvx").ServerRequest | URL | string, options?: RequestInit, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
7
|
+
use(route: string, handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
8
|
+
use(handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
9
|
+
on(method: import("h3").HTTPMethod | Lowercase<import("h3").HTTPMethod> | "", route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
10
|
+
register(plugin: import("h3").H3Plugin): /*elided*/ any;
|
|
11
|
+
mount(base: string, input: import("srvx").FetchHandler | {
|
|
12
|
+
fetch: import("srvx").FetchHandler;
|
|
13
|
+
} | /*elided*/ any): /*elided*/ any;
|
|
14
|
+
all(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
15
|
+
get(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
16
|
+
post(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
17
|
+
put(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
18
|
+
delete(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
19
|
+
patch(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
20
|
+
head(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
21
|
+
options(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
22
|
+
connect(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
23
|
+
trace(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
24
|
+
readonly config: import("h3").H3Config;
|
|
25
|
+
"~middleware": import("h3").Middleware[];
|
|
26
|
+
"~routes": import("h3").H3Route[];
|
|
27
|
+
fetch(_request: import("srvx").ServerRequest): Response | Promise<Response>;
|
|
28
|
+
handler(event: H3Event): unknown | Promise<unknown>;
|
|
29
|
+
"~request"(request: import("srvx").ServerRequest, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
30
|
+
"~findRoute"(_event: H3Event): import("h3").MatchedRoute<import("h3").H3Route> | void;
|
|
31
|
+
"~getMiddleware"(event: H3Event, route: import("h3").MatchedRoute<import("h3").H3Route> | undefined): import("h3").Middleware[];
|
|
32
|
+
"~addRoute"(_route: import("h3").H3Route): void;
|
|
33
|
+
};
|
|
34
|
+
export declare function createHandler(fn: (context: PageEvent) => JSX.Element, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions | Promise<HandlerOptions>)): {
|
|
35
|
+
"~rou3": import("h3").RouterContext;
|
|
36
|
+
request(request: import("srvx").ServerRequest | URL | string, options?: RequestInit, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
37
|
+
use(route: string, handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
38
|
+
use(handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
39
|
+
on(method: import("h3").HTTPMethod | Lowercase<import("h3").HTTPMethod> | "", route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
40
|
+
register(plugin: import("h3").H3Plugin): /*elided*/ any;
|
|
41
|
+
mount(base: string, input: import("srvx").FetchHandler | {
|
|
42
|
+
fetch: import("srvx").FetchHandler;
|
|
43
|
+
} | /*elided*/ any): /*elided*/ any;
|
|
44
|
+
all(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
45
|
+
get(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
46
|
+
post(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
47
|
+
put(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
48
|
+
delete(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
49
|
+
patch(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
50
|
+
head(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
51
|
+
options(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
52
|
+
connect(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
53
|
+
trace(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
54
|
+
readonly config: import("h3").H3Config;
|
|
55
|
+
"~middleware": import("h3").Middleware[];
|
|
56
|
+
"~routes": import("h3").H3Route[];
|
|
57
|
+
fetch(_request: import("srvx").ServerRequest): Response | Promise<Response>;
|
|
58
|
+
handler(event: H3Event): unknown | Promise<unknown>;
|
|
59
|
+
"~request"(request: import("srvx").ServerRequest, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
60
|
+
"~findRoute"(_event: H3Event): import("h3").MatchedRoute<import("h3").H3Route> | void;
|
|
61
|
+
"~getMiddleware"(event: H3Event, route: import("h3").MatchedRoute<import("h3").H3Route> | undefined): import("h3").Middleware[];
|
|
62
|
+
"~addRoute"(_route: import("h3").H3Route): void;
|
|
63
|
+
};
|
|
6
64
|
export declare function createPageEvent(ctx: FetchEvent): Promise<PageEvent>;
|
package/dist/server/handler.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createRoutes } from "../router.jsx";
|
|
|
6
6
|
import { decorateHandler, decorateMiddleware } from "./fetchEvent.js";
|
|
7
7
|
import { getSsrManifest } from "./manifest/ssr-manifest.js";
|
|
8
8
|
import { matchAPIRoute } from "./routes.js";
|
|
9
|
-
import { handleServerFunction } from "
|
|
9
|
+
import { handleServerFunction } from "../fns/handler.js";
|
|
10
10
|
import { getExpectedRedirectStatus } from "./util.js";
|
|
11
11
|
const SERVER_FN_BASE = "/_server";
|
|
12
12
|
export function createBaseHandler(createPageEvent, fn, options = {}) {
|
|
@@ -28,20 +28,22 @@ export function createBaseHandler(createPageEvent, fn, options = {}) {
|
|
|
28
28
|
if (match) {
|
|
29
29
|
const mod = await match.handler.import();
|
|
30
30
|
const fn = event.request.method === "HEAD" ? mod["HEAD"] || mod["GET"] : mod[event.request.method];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (res
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
if (typeof fn === "function") {
|
|
32
|
+
event.params = match.params || {};
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
sharedConfig.context = { event };
|
|
35
|
+
const res = await fn(event);
|
|
36
|
+
if (res !== undefined) {
|
|
37
|
+
if (res instanceof Response)
|
|
38
|
+
return produceResponseWithEventHeaders(res);
|
|
39
|
+
return res;
|
|
40
|
+
}
|
|
41
|
+
if (event.request.method !== "GET") {
|
|
42
|
+
throw new Error(`API handler for ${event.request.method} "${event.request.url}" did not return a response.`);
|
|
43
|
+
}
|
|
44
|
+
if (!match.isPage)
|
|
45
|
+
return;
|
|
39
46
|
}
|
|
40
|
-
if (event.request.method !== "GET") {
|
|
41
|
-
throw new Error(`API handler for ${event.request.method} "${event.request.url}" did not return a response.`);
|
|
42
|
-
}
|
|
43
|
-
if (!match.isPage)
|
|
44
|
-
return;
|
|
45
47
|
}
|
|
46
48
|
const context = await createPageEvent(event);
|
|
47
49
|
const resolvedOptions = typeof options === "function" ? await options(context) : { ...options };
|
|
@@ -178,7 +180,7 @@ function handleStreamCompleteRedirect(context) {
|
|
|
178
180
|
return ({ write }) => {
|
|
179
181
|
context.complete = true;
|
|
180
182
|
const to = context.response && context.response.headers.get("Location");
|
|
181
|
-
to && write(`<script>window.location
|
|
183
|
+
to && write(`<script>window.location=${JSON.stringify(to).replace(/</g, "\\u003c")}</script>`);
|
|
182
184
|
};
|
|
183
185
|
}
|
|
184
186
|
function produceResponseWithEventHeaders(res) {
|
|
@@ -4,4 +4,33 @@ import type { HandlerOptions, PageEvent } from "../types.ts";
|
|
|
4
4
|
*
|
|
5
5
|
* Read more: https://docs.solidjs.com/solid-start/reference/server/create-handler
|
|
6
6
|
*/
|
|
7
|
-
export declare function createHandler(fn: (context: PageEvent) => JSX.Element, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions)):
|
|
7
|
+
export declare function createHandler(fn: (context: PageEvent) => JSX.Element, options?: HandlerOptions | ((context: PageEvent) => HandlerOptions)): {
|
|
8
|
+
"~rou3": import("h3").RouterContext;
|
|
9
|
+
request(request: import("srvx").ServerRequest | URL | string, options?: RequestInit, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
10
|
+
use(route: string, handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
11
|
+
use(handler: import("h3").Middleware, opts?: import("h3").MiddlewareOptions): /*elided*/ any;
|
|
12
|
+
on(method: import("h3").HTTPMethod | Lowercase<import("h3").HTTPMethod> | "", route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
13
|
+
register(plugin: import("h3").H3Plugin): /*elided*/ any;
|
|
14
|
+
mount(base: string, input: import("srvx").FetchHandler | {
|
|
15
|
+
fetch: import("srvx").FetchHandler;
|
|
16
|
+
} | /*elided*/ any): /*elided*/ any;
|
|
17
|
+
all(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
18
|
+
get(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
19
|
+
post(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
20
|
+
put(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
21
|
+
delete(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
22
|
+
patch(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
23
|
+
head(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
24
|
+
options(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
25
|
+
connect(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
26
|
+
trace(route: string, handler: import("h3").HTTPHandler, opts?: import("h3").RouteOptions): /*elided*/ any;
|
|
27
|
+
readonly config: import("h3").H3Config;
|
|
28
|
+
"~middleware": import("h3").Middleware[];
|
|
29
|
+
"~routes": import("h3").H3Route[];
|
|
30
|
+
fetch(_request: import("srvx").ServerRequest): Response | Promise<Response>;
|
|
31
|
+
handler(event: import("h3").H3Event): unknown | Promise<unknown>;
|
|
32
|
+
"~request"(request: import("srvx").ServerRequest, context?: import("h3").H3EventContext): Response | Promise<Response>;
|
|
33
|
+
"~findRoute"(_event: import("h3").H3Event): import("h3").MatchedRoute<import("h3").H3Route> | void;
|
|
34
|
+
"~getMiddleware"(event: import("h3").H3Event, route: import("h3").MatchedRoute<import("h3").H3Route> | undefined): import("h3").Middleware[];
|
|
35
|
+
"~addRoute"(_route: import("h3").H3Route): void;
|
|
36
|
+
};
|
package/dist/server/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface APIEvent extends FetchEvent {
|
|
|
64
64
|
[key: string]: string;
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
export type APIHandler = (event: APIEvent) =>
|
|
67
|
+
export type APIHandler = (event: APIEvent) => any;
|
|
68
68
|
export interface ServerFunctionMeta {
|
|
69
69
|
id: string;
|
|
70
70
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @refresh skip
|
|
2
2
|
import { getSingletonHighlighter } from "shiki";
|
|
3
3
|
import { loadWasm } from "shiki/engine/oniguruma";
|
|
4
|
-
import { createEffect, createResource } from "solid-js";
|
|
5
|
-
import url from "shiki/onig.wasm?url";
|
|
6
4
|
import langJS from "shiki/langs/javascript.mjs";
|
|
7
5
|
import langJSX from "shiki/langs/jsx.mjs";
|
|
8
6
|
import langTSX from "shiki/langs/tsx.mjs";
|
|
9
7
|
import langTS from "shiki/langs/typescript.mjs";
|
|
8
|
+
import url from "shiki/onig.wasm?url";
|
|
10
9
|
import darkPlus from "shiki/themes/dark-plus.mjs";
|
|
10
|
+
import { createEffect, createResource } from "solid-js";
|
|
11
11
|
let HIGHLIGHTER;
|
|
12
12
|
async function loadHighlighter() {
|
|
13
13
|
if (!HIGHLIGHTER) {
|
|
@@ -51,12 +51,12 @@ export function CodeView(props) {
|
|
|
51
51
|
for (let i = 0, len = lines.length; i < len; i++) {
|
|
52
52
|
const el = lines[i];
|
|
53
53
|
if (props.line - minLine() - 1 === i) {
|
|
54
|
-
el.
|
|
54
|
+
el.dataset.startDevOverlayErrorLine = '';
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
-
return (<div ref={ref}
|
|
59
|
+
return (<div ref={ref} data-start-dev-overlay-code-view style={{
|
|
60
60
|
"--dev-overlay-code-view-start": minLine() + 1,
|
|
61
61
|
}}/>);
|
|
62
62
|
}
|