@solidjs/start 2.0.0-beta.1 → 2.0.0-beta.2
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 +7 -0
- package/dist/client/StartClient.d.ts +7 -0
- package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
- package/dist/client/index.jsx +2 -0
- package/dist/client/mount.d.ts +1 -0
- package/dist/client/mount.js +1 -0
- package/dist/client/spa/index.d.ts +4 -0
- package/dist/client/spa/index.jsx +5 -0
- package/dist/config/constants.d.ts +16 -0
- package/dist/config/constants.js +16 -0
- package/dist/config/dev-server.d.ts +2 -0
- package/dist/config/dev-server.js +128 -0
- package/dist/config/env.d.ts +19 -0
- package/dist/config/env.js +81 -0
- package/dist/config/fs-router.d.ts +37 -0
- package/dist/config/fs-router.js +141 -0
- package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
- package/dist/config/fs-routes/fs-watcher.js +53 -0
- package/dist/config/fs-routes/index.d.ts +7 -0
- package/dist/config/fs-routes/index.js +107 -0
- package/dist/config/fs-routes/router.d.ts +42 -0
- package/dist/config/fs-routes/router.js +148 -0
- package/dist/config/fs-routes/tree-shake.d.ts +2 -0
- package/dist/config/fs-routes/tree-shake.js +305 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.js +217 -0
- package/dist/config/lazy.d.ts +3 -0
- package/dist/config/lazy.js +114 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +109 -0
- package/dist/config/utils.d.ts +4 -0
- package/dist/config/utils.js +6 -0
- package/dist/config/vite-utils.d.ts +21 -0
- package/dist/config/vite-utils.js +85 -0
- 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 +170 -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 +66 -0
- package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
- package/dist/directives/types.js +1 -0
- package/dist/directives/xxhash32.d.ts +6 -0
- package/dist/directives/xxhash32.js +193 -0
- package/dist/fns/client.d.ts +3 -0
- package/dist/fns/client.js +106 -0
- package/dist/fns/handler.d.ts +5 -0
- package/dist/fns/handler.js +269 -0
- 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/fns/server.js +38 -0
- package/dist/fns/shared.d.ts +17 -0
- package/dist/fns/shared.js +105 -0
- package/dist/http/index.d.ts +81 -0
- package/dist/http/index.js +129 -0
- package/{src/index.tsx → dist/index.d.ts} +0 -2
- package/dist/index.jsx +6 -0
- package/dist/middleware/index.d.ts +38 -0
- package/dist/middleware/index.js +59 -0
- package/dist/router.d.ts +6 -0
- package/dist/router.jsx +29 -0
- package/dist/server/StartServer.d.ts +9 -0
- package/dist/server/StartServer.jsx +34 -0
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
- package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
- package/dist/server/assets/index.d.ts +2 -0
- package/dist/server/assets/index.js +52 -0
- package/dist/server/assets/render.d.ts +19 -0
- package/dist/server/assets/render.jsx +14 -0
- package/dist/server/collect-styles.d.ts +3 -0
- package/dist/server/collect-styles.js +57 -0
- package/dist/server/fetchEvent.d.ts +7 -0
- package/dist/server/fetchEvent.js +26 -0
- package/dist/server/handler.d.ts +64 -0
- package/dist/server/handler.js +222 -0
- package/dist/server/index.d.ts +9 -0
- package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
- package/dist/server/manifest/client-manifest.d.ts +9 -0
- package/dist/server/manifest/client-manifest.js +6 -0
- package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
- package/dist/server/manifest/dev-client-manifest.js +24 -0
- package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
- package/dist/server/manifest/dev-ssr-manifest.js +23 -0
- package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
- package/dist/server/manifest/prod-client-manifest.js +26 -0
- package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
- package/dist/server/manifest/prod-ssr-manifest.js +85 -0
- package/dist/server/manifest/ssr-manifest.d.ts +4 -0
- package/dist/server/manifest/ssr-manifest.js +6 -0
- package/dist/server/routes.d.ts +23 -0
- package/dist/server/routes.js +74 -0
- package/dist/server/spa/StartServer.d.ts +9 -0
- package/dist/server/spa/StartServer.jsx +25 -0
- package/dist/server/spa/handler.d.ts +36 -0
- package/dist/server/spa/handler.js +20 -0
- package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
- package/dist/server/spa/index.jsx +5 -0
- package/dist/server/types.d.ts +75 -0
- package/dist/server/types.js +1 -0
- package/dist/server/util.d.ts +2 -0
- package/dist/server/util.js +8 -0
- package/dist/shared/ErrorBoundary.d.ts +3 -0
- package/dist/shared/ErrorBoundary.jsx +36 -0
- package/dist/shared/GET.d.ts +5 -0
- package/dist/shared/GET.js +8 -0
- package/dist/shared/HttpHeader.d.ts +10 -0
- package/dist/shared/HttpHeader.jsx +38 -0
- package/dist/shared/HttpStatusCode.d.ts +9 -0
- package/dist/shared/HttpStatusCode.js +18 -0
- package/dist/shared/clientOnly.d.ts +12 -0
- package/dist/shared/clientOnly.js +27 -0
- package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
- package/dist/shared/dev-overlay/CodeView.jsx +62 -0
- package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
- package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
- package/dist/shared/dev-overlay/createStackFrame.js +56 -0
- package/dist/shared/dev-overlay/download.d.ts +1 -0
- package/dist/shared/dev-overlay/download.js +6 -0
- package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
- package/dist/shared/dev-overlay/get-source-map.js +25 -0
- package/dist/shared/dev-overlay/icons.d.ts +28 -0
- package/dist/shared/dev-overlay/icons.jsx +150 -0
- package/dist/shared/dev-overlay/index.d.ts +5 -0
- package/dist/shared/dev-overlay/index.jsx +39 -0
- package/dist/shared/lazy.d.ts +3 -0
- package/dist/shared/lazy.js +42 -0
- package/dist/shared/serverFunction.d.ts +6 -0
- package/dist/shared/serverFunction.js +8 -0
- package/dist/utils/debounce.d.ts +4 -0
- package/dist/utils/debounce.js +10 -0
- package/package.json +7 -2
- package/scripts/build.js +0 -15
- package/scripts/validate-imports.js +0 -316
- package/src/client/mount.ts +0 -1
- package/src/client/spa/index.tsx +0 -9
- package/src/config/constants.ts +0 -19
- package/src/config/dev-server.ts +0 -161
- package/src/config/env.ts +0 -105
- package/src/config/fs-router.ts +0 -162
- package/src/config/fs-routes/fs-watcher.ts +0 -66
- package/src/config/fs-routes/index.ts +0 -136
- package/src/config/fs-routes/router.ts +0 -184
- package/src/config/fs-routes/tree-shake.ts +0 -324
- package/src/config/index.ts +0 -239
- package/src/config/lazy.ts +0 -132
- package/src/config/manifest.ts +0 -120
- package/src/config/utils.ts +0 -5
- package/src/config/vite-utils.ts +0 -113
- package/src/directives/bubble-function-declaration.ts +0 -33
- package/src/directives/compile.ts +0 -54
- package/src/directives/generate-unique-name.ts +0 -22
- package/src/directives/get-descriptive-name.ts +0 -39
- package/src/directives/get-import-identifier.ts +0 -34
- package/src/directives/get-root-statement-path.ts +0 -14
- package/src/directives/index.ts +0 -233
- package/src/directives/is-statement-top-level.ts +0 -13
- package/src/directives/paths.ts +0 -63
- package/src/directives/plugin.ts +0 -389
- package/src/directives/remove-unused-variables.ts +0 -70
- package/src/directives/xxhash32.ts +0 -214
- package/src/env.d.ts +0 -17
- package/src/fns/client.ts +0 -141
- package/src/fns/handler.spec.ts +0 -85
- package/src/fns/handler.ts +0 -287
- package/src/fns/registration.ts +0 -19
- package/src/fns/serialization.ts +0 -250
- package/src/fns/server.ts +0 -46
- package/src/fns/shared.ts +0 -116
- package/src/http/index.ts +0 -216
- package/src/internal.d.ts +0 -14
- package/src/middleware/index.ts +0 -92
- package/src/router.tsx +0 -37
- package/src/server/StartServer.tsx +0 -58
- package/src/server/assets/index.ts +0 -70
- package/src/server/assets/render.tsx +0 -46
- package/src/server/collect-styles.ts +0 -70
- package/src/server/fetchEvent.spec.ts +0 -85
- package/src/server/fetchEvent.ts +0 -36
- package/src/server/handler.ts +0 -261
- package/src/server/manifest/client-manifest.ts +0 -8
- package/src/server/manifest/dev-client-manifest.ts +0 -21
- package/src/server/manifest/dev-ssr-manifest.ts +0 -23
- package/src/server/manifest/prod-client-manifest.ts +0 -21
- package/src/server/manifest/prod-ssr-manifest.ts +0 -109
- package/src/server/manifest/ssr-manifest.ts +0 -10
- package/src/server/routes.ts +0 -126
- package/src/server/spa/StartServer.tsx +0 -42
- package/src/server/spa/handler.ts +0 -29
- package/src/server/types.ts +0 -82
- package/src/server/util.ts +0 -12
- package/src/shared/ErrorBoundary.tsx +0 -52
- package/src/shared/GET.ts +0 -8
- package/src/shared/HttpHeader.tsx +0 -42
- package/src/shared/HttpStatusCode.ts +0 -27
- package/src/shared/clientOnly.ts +0 -44
- package/src/shared/dev-overlay/CodeView.tsx +0 -90
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
- package/src/shared/dev-overlay/createStackFrame.ts +0 -74
- package/src/shared/dev-overlay/download.ts +0 -6
- package/src/shared/dev-overlay/env.d.ts +0 -4
- package/src/shared/dev-overlay/get-source-map.ts +0 -33
- package/src/shared/dev-overlay/icons.tsx +0 -456
- package/src/shared/dev-overlay/index.tsx +0 -63
- package/src/shared/lazy.ts +0 -52
- package/src/shared/serverFunction.ts +0 -10
- package/src/utils/debounce.ts +0 -10
- package/src/virtual.d.ts +0 -27
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -9
- /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
- /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
package/src/fns/serialization.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
crossSerializeStream,
|
|
3
|
-
deserialize,
|
|
4
|
-
Feature,
|
|
5
|
-
fromCrossJSON,
|
|
6
|
-
getCrossReferenceHeader,
|
|
7
|
-
type SerovalNode,
|
|
8
|
-
toCrossJSONStream,
|
|
9
|
-
} from "seroval";
|
|
10
|
-
import {
|
|
11
|
-
AbortSignalPlugin,
|
|
12
|
-
CustomEventPlugin,
|
|
13
|
-
DOMExceptionPlugin,
|
|
14
|
-
EventPlugin,
|
|
15
|
-
FormDataPlugin,
|
|
16
|
-
HeadersPlugin,
|
|
17
|
-
ReadableStreamPlugin,
|
|
18
|
-
RequestPlugin,
|
|
19
|
-
ResponsePlugin,
|
|
20
|
-
URLPlugin,
|
|
21
|
-
URLSearchParamsPlugin,
|
|
22
|
-
} from "seroval-plugins/web";
|
|
23
|
-
|
|
24
|
-
// TODO(Alexis): if we can, allow providing an option to extend these.
|
|
25
|
-
const DEFAULT_PLUGINS = [
|
|
26
|
-
AbortSignalPlugin,
|
|
27
|
-
CustomEventPlugin,
|
|
28
|
-
DOMExceptionPlugin,
|
|
29
|
-
EventPlugin,
|
|
30
|
-
FormDataPlugin,
|
|
31
|
-
HeadersPlugin,
|
|
32
|
-
ReadableStreamPlugin,
|
|
33
|
-
RequestPlugin,
|
|
34
|
-
ResponsePlugin,
|
|
35
|
-
URLSearchParamsPlugin,
|
|
36
|
-
URLPlugin,
|
|
37
|
-
];
|
|
38
|
-
const MAX_SERIALIZATION_DEPTH_LIMIT = 64;
|
|
39
|
-
const DISABLED_FEATURES = Feature.RegExp;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Alexis:
|
|
43
|
-
*
|
|
44
|
-
* A "chunk" is a piece of data emitted by the streaming serializer.
|
|
45
|
-
* Each chunk is represented by a 32-bit value (encoded in hexadecimal),
|
|
46
|
-
* followed by the encoded string (8-bit representation). This format
|
|
47
|
-
* is important so we know how much of the chunk being streamed we
|
|
48
|
-
* are expecting before parsing the entire string data.
|
|
49
|
-
*
|
|
50
|
-
* This is sort of a bootleg "multipart/form-data" except it's bad at
|
|
51
|
-
* handling File/Blob LOL
|
|
52
|
-
*
|
|
53
|
-
* The format is as follows:
|
|
54
|
-
* ;0xFFFFFFFF;<string data>
|
|
55
|
-
*/
|
|
56
|
-
function createChunk(data: string): Uint8Array {
|
|
57
|
-
const encodeData = new TextEncoder().encode(data);
|
|
58
|
-
const bytes = encodeData.length;
|
|
59
|
-
const baseHex = bytes.toString(16);
|
|
60
|
-
const totalHex = "00000000".substring(0, 8 - baseHex.length) + baseHex; // 32-bit
|
|
61
|
-
const head = new TextEncoder().encode(`;0x${totalHex};`);
|
|
62
|
-
|
|
63
|
-
const chunk = new Uint8Array(12 + bytes);
|
|
64
|
-
chunk.set(head);
|
|
65
|
-
chunk.set(encodeData, 12);
|
|
66
|
-
return chunk;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function serializeToJSStream(id: string, value: any) {
|
|
70
|
-
return new ReadableStream({
|
|
71
|
-
start(controller) {
|
|
72
|
-
crossSerializeStream(value, {
|
|
73
|
-
scopeId: id,
|
|
74
|
-
plugins: DEFAULT_PLUGINS,
|
|
75
|
-
onSerialize(data: string, initial: boolean) {
|
|
76
|
-
controller.enqueue(
|
|
77
|
-
createChunk(initial ? `(${getCrossReferenceHeader(id)},${data})` : data),
|
|
78
|
-
);
|
|
79
|
-
},
|
|
80
|
-
onDone() {
|
|
81
|
-
controller.close();
|
|
82
|
-
},
|
|
83
|
-
onError(error: any) {
|
|
84
|
-
controller.error(error);
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function serializeToJSONStream(value: any) {
|
|
92
|
-
return new ReadableStream({
|
|
93
|
-
start(controller) {
|
|
94
|
-
toCrossJSONStream(value, {
|
|
95
|
-
disabledFeatures: DISABLED_FEATURES,
|
|
96
|
-
depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
|
|
97
|
-
plugins: DEFAULT_PLUGINS,
|
|
98
|
-
onParse(node) {
|
|
99
|
-
controller.enqueue(createChunk(JSON.stringify(node)));
|
|
100
|
-
},
|
|
101
|
-
onDone() {
|
|
102
|
-
controller.close();
|
|
103
|
-
},
|
|
104
|
-
onError(error) {
|
|
105
|
-
controller.error(error);
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
class SerovalChunkReader {
|
|
113
|
-
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
114
|
-
buffer: Uint8Array;
|
|
115
|
-
done: boolean;
|
|
116
|
-
constructor(stream: ReadableStream<Uint8Array>) {
|
|
117
|
-
this.reader = stream.getReader();
|
|
118
|
-
this.buffer = new Uint8Array(0);
|
|
119
|
-
this.done = false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async readChunk() {
|
|
123
|
-
// if there's no chunk, read again
|
|
124
|
-
const chunk = await this.reader.read();
|
|
125
|
-
if (!chunk.done) {
|
|
126
|
-
// repopulate the buffer
|
|
127
|
-
const newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
|
|
128
|
-
newBuffer.set(this.buffer);
|
|
129
|
-
newBuffer.set(chunk.value, this.buffer.length);
|
|
130
|
-
this.buffer = newBuffer;
|
|
131
|
-
} else {
|
|
132
|
-
this.done = true;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async next(): Promise<{ done: true; value: undefined } | { done: false; value: string }> {
|
|
137
|
-
// Check if the buffer is empty
|
|
138
|
-
if (this.buffer.length === 0) {
|
|
139
|
-
// if we are already done...
|
|
140
|
-
if (this.done) {
|
|
141
|
-
return {
|
|
142
|
-
done: true,
|
|
143
|
-
value: undefined,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
// Otherwise, read a new chunk
|
|
147
|
-
await this.readChunk();
|
|
148
|
-
return await this.next();
|
|
149
|
-
}
|
|
150
|
-
// Read the "byte header"
|
|
151
|
-
// The byte header tells us how big the expected data is
|
|
152
|
-
// so we know how much data we should wait before we
|
|
153
|
-
// deserialize the data
|
|
154
|
-
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
155
|
-
const bytes = Number.parseInt(head, 16); // ;0x00000000;
|
|
156
|
-
if (Number.isNaN(bytes)) {
|
|
157
|
-
throw new Error("Malformed server function stream.");
|
|
158
|
-
}
|
|
159
|
-
// Check if the buffer has enough bytes to be parsed
|
|
160
|
-
while (bytes > this.buffer.length - 12) {
|
|
161
|
-
// If it's not enough, and the reader is done
|
|
162
|
-
// then the chunk is invalid.
|
|
163
|
-
if (this.done) {
|
|
164
|
-
throw new Error("Malformed server function stream.");
|
|
165
|
-
}
|
|
166
|
-
// Otherwise, we read more chunks
|
|
167
|
-
await this.readChunk();
|
|
168
|
-
}
|
|
169
|
-
// Extract the exact chunk as defined by the byte header
|
|
170
|
-
const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
|
|
171
|
-
// The rest goes to the buffer
|
|
172
|
-
this.buffer = this.buffer.subarray(12 + bytes);
|
|
173
|
-
|
|
174
|
-
// Deserialize the chunk
|
|
175
|
-
return {
|
|
176
|
-
done: false,
|
|
177
|
-
value: partial,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async drain(interpret: (chunk: string) => void) {
|
|
182
|
-
while (true) {
|
|
183
|
-
const result = await this.next();
|
|
184
|
-
if (result.done) {
|
|
185
|
-
break;
|
|
186
|
-
} else {
|
|
187
|
-
interpret(result.value);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export async function serializeToJSONString(value: any) {
|
|
194
|
-
const response = new Response(serializeToJSONStream(value));
|
|
195
|
-
return await response.text();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export async function deserializeFromJSONString(json: string) {
|
|
199
|
-
const blob = new Response(json);
|
|
200
|
-
return await deserializeJSONStream(blob);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function deserializeJSONStream(response: Response | Request) {
|
|
204
|
-
if (!response.body) {
|
|
205
|
-
throw new Error("missing body");
|
|
206
|
-
}
|
|
207
|
-
const reader = new SerovalChunkReader(response.body);
|
|
208
|
-
const result = await reader.next();
|
|
209
|
-
if (!result.done) {
|
|
210
|
-
const refs = new Map();
|
|
211
|
-
|
|
212
|
-
function interpretChunk(chunk: string): unknown {
|
|
213
|
-
const value = fromCrossJSON(JSON.parse(chunk) as SerovalNode, {
|
|
214
|
-
refs,
|
|
215
|
-
disabledFeatures: DISABLED_FEATURES,
|
|
216
|
-
depthLimit: MAX_SERIALIZATION_DEPTH_LIMIT,
|
|
217
|
-
plugins: DEFAULT_PLUGINS,
|
|
218
|
-
});
|
|
219
|
-
return value;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
void reader.drain(interpretChunk);
|
|
223
|
-
|
|
224
|
-
return interpretChunk(result.value);
|
|
225
|
-
}
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export async function deserializeJSStream(id: string, response: Request | Response) {
|
|
230
|
-
if (!response.body) {
|
|
231
|
-
throw new Error("missing body");
|
|
232
|
-
}
|
|
233
|
-
const reader = new SerovalChunkReader(response.body);
|
|
234
|
-
|
|
235
|
-
const result = await reader.next();
|
|
236
|
-
|
|
237
|
-
if (!result.done) {
|
|
238
|
-
reader.drain(deserialize).then(
|
|
239
|
-
() => {
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
delete $R[id];
|
|
242
|
-
},
|
|
243
|
-
() => {
|
|
244
|
-
// no-op
|
|
245
|
-
},
|
|
246
|
-
);
|
|
247
|
-
return deserialize(result.value);
|
|
248
|
-
}
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
package/src/fns/server.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getRequestEvent } from "solid-js/web";
|
|
2
|
-
import { provideRequestEvent } from "solid-js/web/storage";
|
|
3
|
-
import { registerServerFunction } from "./registration.ts";
|
|
4
|
-
|
|
5
|
-
interface Registration<T extends any[], R> {
|
|
6
|
-
id: string;
|
|
7
|
-
fn: (...args: T) => Promise<R>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function createServerReference<T extends any[], R>(
|
|
11
|
-
id: string,
|
|
12
|
-
fn: (...args: T) => Promise<R>,
|
|
13
|
-
) {
|
|
14
|
-
const registration: Registration<T, R> = { id, fn };
|
|
15
|
-
registerServerFunction(id, fn);
|
|
16
|
-
return registration;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function cloneServerReference<T extends any[], R>({ id, fn }: Registration<T, R>) {
|
|
20
|
-
if (typeof fn !== "function")
|
|
21
|
-
throw new Error("Export from a 'use server' module must be a function");
|
|
22
|
-
let baseURL = import.meta.env.BASE_URL ?? "/";
|
|
23
|
-
if (!baseURL.endsWith("/")) baseURL += "/";
|
|
24
|
-
|
|
25
|
-
return new Proxy(fn, {
|
|
26
|
-
get(target, prop, receiver) {
|
|
27
|
-
if (prop === "url") {
|
|
28
|
-
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
29
|
-
}
|
|
30
|
-
if (prop === "GET") return receiver;
|
|
31
|
-
return (target as any)[prop];
|
|
32
|
-
},
|
|
33
|
-
apply(target, thisArg, args) {
|
|
34
|
-
const ogEvt = getRequestEvent();
|
|
35
|
-
if (!ogEvt) throw new Error("Cannot call server function outside of a request");
|
|
36
|
-
const evt = { ...ogEvt };
|
|
37
|
-
evt.locals.serverFunctionMeta = {
|
|
38
|
-
id,
|
|
39
|
-
};
|
|
40
|
-
evt.serverOnly = true;
|
|
41
|
-
return provideRequestEvent(evt, () => {
|
|
42
|
-
return fn.apply(thisArg, args as T);
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
package/src/fns/shared.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { deserializeJSONStream, deserializeJSStream } from "./serialization.ts";
|
|
2
|
-
|
|
3
|
-
export const BODY_FORMAT_KEY = "X-Start-Type";
|
|
4
|
-
|
|
5
|
-
export const BODY_FORMAL_FILE = "__START__";
|
|
6
|
-
|
|
7
|
-
export const enum BodyFormat {
|
|
8
|
-
Seroval = "0",
|
|
9
|
-
String = "1",
|
|
10
|
-
FormData = "2",
|
|
11
|
-
URLSearchParams = "3",
|
|
12
|
-
Blob = "4",
|
|
13
|
-
File = "5",
|
|
14
|
-
ArrayBuffer = "6",
|
|
15
|
-
Uint8Array = "7",
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getHeadersAndBody(body: any):
|
|
19
|
-
| {
|
|
20
|
-
headers?: HeadersInit;
|
|
21
|
-
body: BodyInit;
|
|
22
|
-
}
|
|
23
|
-
| undefined {
|
|
24
|
-
switch (true) {
|
|
25
|
-
case typeof body === "string":
|
|
26
|
-
return {
|
|
27
|
-
headers: {
|
|
28
|
-
"Content-Type": "text/plain",
|
|
29
|
-
[BODY_FORMAT_KEY]: BodyFormat.String,
|
|
30
|
-
},
|
|
31
|
-
body,
|
|
32
|
-
};
|
|
33
|
-
case body instanceof FormData:
|
|
34
|
-
return {
|
|
35
|
-
headers: {
|
|
36
|
-
[BODY_FORMAT_KEY]: BodyFormat.FormData,
|
|
37
|
-
},
|
|
38
|
-
body,
|
|
39
|
-
};
|
|
40
|
-
case body instanceof URLSearchParams:
|
|
41
|
-
return {
|
|
42
|
-
headers: {
|
|
43
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
44
|
-
[BODY_FORMAT_KEY]: BodyFormat.URLSearchParams,
|
|
45
|
-
},
|
|
46
|
-
body,
|
|
47
|
-
};
|
|
48
|
-
case body instanceof File: {
|
|
49
|
-
const formData = new FormData();
|
|
50
|
-
formData.append(BODY_FORMAL_FILE, body, body.name);
|
|
51
|
-
return {
|
|
52
|
-
headers: {
|
|
53
|
-
[BODY_FORMAT_KEY]: BodyFormat.File,
|
|
54
|
-
},
|
|
55
|
-
body: formData,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
case body instanceof Blob:
|
|
59
|
-
return {
|
|
60
|
-
headers: {
|
|
61
|
-
[BODY_FORMAT_KEY]: BodyFormat.Blob,
|
|
62
|
-
},
|
|
63
|
-
body,
|
|
64
|
-
};
|
|
65
|
-
case body instanceof ArrayBuffer:
|
|
66
|
-
return {
|
|
67
|
-
headers: {
|
|
68
|
-
[BODY_FORMAT_KEY]: BodyFormat.ArrayBuffer,
|
|
69
|
-
},
|
|
70
|
-
body,
|
|
71
|
-
};
|
|
72
|
-
case body instanceof Uint8Array:
|
|
73
|
-
return {
|
|
74
|
-
headers: {
|
|
75
|
-
[BODY_FORMAT_KEY]: BodyFormat.Uint8Array,
|
|
76
|
-
},
|
|
77
|
-
body: new Uint8Array(body),
|
|
78
|
-
};
|
|
79
|
-
default:
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function extractBody(instance: string, client: boolean, source: Request | Response) {
|
|
85
|
-
const contentType = source.headers.get("content-type");
|
|
86
|
-
const startType = source.headers.get(BODY_FORMAT_KEY);
|
|
87
|
-
const clone = source.clone();
|
|
88
|
-
|
|
89
|
-
switch (true) {
|
|
90
|
-
case startType === BodyFormat.Seroval:
|
|
91
|
-
if (client && import.meta.env.SEROVAL_MODE === "js") {
|
|
92
|
-
return await deserializeJSStream(instance, clone);
|
|
93
|
-
}
|
|
94
|
-
return await deserializeJSONStream(clone);
|
|
95
|
-
case startType === BodyFormat.String:
|
|
96
|
-
return await clone.text();
|
|
97
|
-
case startType === BodyFormat.File: {
|
|
98
|
-
const formData = await clone.formData();
|
|
99
|
-
return formData.get(BODY_FORMAL_FILE);
|
|
100
|
-
}
|
|
101
|
-
case startType === BodyFormat.FormData:
|
|
102
|
-
case contentType?.startsWith("multipart/form-data"):
|
|
103
|
-
return await clone.formData();
|
|
104
|
-
case startType === BodyFormat.URLSearchParams:
|
|
105
|
-
case contentType?.startsWith("application/x-www-form-urlencoded"):
|
|
106
|
-
return new URLSearchParams(await clone.text());
|
|
107
|
-
case startType === BodyFormat.Blob:
|
|
108
|
-
return await clone.blob();
|
|
109
|
-
case startType === BodyFormat.ArrayBuffer:
|
|
110
|
-
return await clone.arrayBuffer();
|
|
111
|
-
case startType === BodyFormat.Uint8Array:
|
|
112
|
-
return new Uint8Array(await clone.arrayBuffer());
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
package/src/http/index.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import type { H3Event, HTTPEvent, InferEventInput } from "h3";
|
|
2
|
-
import * as h3 from "h3";
|
|
3
|
-
import { getRequestEvent } from "solid-js/web";
|
|
4
|
-
|
|
5
|
-
function _setContext(event: H3Event, key: string, value: any) {
|
|
6
|
-
event.context[key] = value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function _getContext(event: H3Event, key: string) {
|
|
10
|
-
return event.context[key];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function getEvent() {
|
|
14
|
-
return getRequestEvent()!.nativeEvent;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getWebRequest(): Request {
|
|
18
|
-
return getEvent().req;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const HTTPEventSymbol = Symbol("$HTTPEvent");
|
|
22
|
-
|
|
23
|
-
export function isEvent(obj: any): obj is h3.H3Event | { [HTTPEventSymbol]: h3.H3Event } {
|
|
24
|
-
return (
|
|
25
|
-
typeof obj === "object" &&
|
|
26
|
-
(obj instanceof h3.H3Event ||
|
|
27
|
-
obj?.[HTTPEventSymbol] instanceof h3.H3Event ||
|
|
28
|
-
obj?.__is_event__ === true)
|
|
29
|
-
);
|
|
30
|
-
// Implement logic to check if obj is an H3Event
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type Tail<T> = T extends [any, ...infer U] ? U : never;
|
|
34
|
-
|
|
35
|
-
type PrependOverload<
|
|
36
|
-
TOriginal extends (...args: Array<any>) => any,
|
|
37
|
-
TOverload extends (...args: Array<any>) => any,
|
|
38
|
-
> = TOverload & TOriginal;
|
|
39
|
-
|
|
40
|
-
// add an overload to the function without the event argument
|
|
41
|
-
type WrapFunction<TFn extends (...args: Array<any>) => any> = PrependOverload<
|
|
42
|
-
TFn,
|
|
43
|
-
(
|
|
44
|
-
...args: Parameters<TFn> extends [h3.HTTPEvent<any> | h3.H3Event<any>, ...infer TArgs]
|
|
45
|
-
? TArgs
|
|
46
|
-
: Parameters<TFn>
|
|
47
|
-
) => ReturnType<TFn>
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
function createWrapperFunction<TFn extends (...args: Array<any>) => any>(
|
|
51
|
-
h3Function: TFn,
|
|
52
|
-
): WrapFunction<TFn> {
|
|
53
|
-
return ((...args: Array<any>) => {
|
|
54
|
-
const event = args[0];
|
|
55
|
-
if (!isEvent(event)) {
|
|
56
|
-
args.unshift(getEvent());
|
|
57
|
-
} else {
|
|
58
|
-
args[0] =
|
|
59
|
-
event instanceof h3.H3Event || (event as any).__is_event__ ? event : event[HTTPEventSymbol];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (h3Function as any)(...args);
|
|
63
|
-
}) as any;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Creating wrappers for each utility and exporting them with their original names
|
|
67
|
-
// readRawBody => getWebRequest().text()/.arrayBuffer()
|
|
68
|
-
type WrappedReadBody = <T, TEventInput = InferEventInput<"body", H3Event, T>>(
|
|
69
|
-
...args: Tail<Parameters<typeof h3.readBody<T, H3Event, TEventInput>>>
|
|
70
|
-
) => ReturnType<typeof h3.readBody<T, h3.H3Event, TEventInput>>;
|
|
71
|
-
export const readBody = createWrapperFunction(h3.readBody) as PrependOverload<
|
|
72
|
-
typeof h3.readBody,
|
|
73
|
-
WrappedReadBody
|
|
74
|
-
>;
|
|
75
|
-
type WrappedGetQuery = <T, TEventInput = Exclude<InferEventInput<"query", H3Event, T>, undefined>>(
|
|
76
|
-
...args: Tail<Parameters<typeof h3.getQuery<T, H3Event, TEventInput>>>
|
|
77
|
-
) => ReturnType<typeof h3.getQuery<T, H3Event, TEventInput>>;
|
|
78
|
-
export const getQuery = createWrapperFunction(h3.getQuery) as PrependOverload<
|
|
79
|
-
typeof h3.getQuery,
|
|
80
|
-
WrappedGetQuery
|
|
81
|
-
>;
|
|
82
|
-
export const isMethod = createWrapperFunction(h3.isMethod);
|
|
83
|
-
export const isPreflightRequest = createWrapperFunction(h3.isPreflightRequest);
|
|
84
|
-
type WrappedGetValidatedQuery = <
|
|
85
|
-
T extends HTTPEvent,
|
|
86
|
-
TEventInput = InferEventInput<"query", H3Event, T>,
|
|
87
|
-
>(
|
|
88
|
-
...args: Tail<Parameters<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>>
|
|
89
|
-
) => ReturnType<typeof h3.getValidatedQuery<T, H3Event, TEventInput>>;
|
|
90
|
-
export const getValidatedQuery = createWrapperFunction(h3.getValidatedQuery) as PrependOverload<
|
|
91
|
-
typeof h3.getValidatedQuery,
|
|
92
|
-
WrappedGetValidatedQuery
|
|
93
|
-
>;
|
|
94
|
-
export const getRouterParams = createWrapperFunction(h3.getRouterParams);
|
|
95
|
-
export const getRouterParam = createWrapperFunction(h3.getRouterParam);
|
|
96
|
-
type WrappedGetValidatedRouterParams = <
|
|
97
|
-
T extends HTTPEvent,
|
|
98
|
-
TEventInput = InferEventInput<"routerParams", H3Event, T>,
|
|
99
|
-
>(
|
|
100
|
-
...args: Tail<Parameters<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>>
|
|
101
|
-
) => ReturnType<typeof h3.getValidatedRouterParams<T, H3Event, TEventInput>>;
|
|
102
|
-
export const getValidatedRouterParams = createWrapperFunction(
|
|
103
|
-
h3.getValidatedRouterParams,
|
|
104
|
-
) as PrependOverload<typeof h3.getValidatedRouterParams, WrappedGetValidatedRouterParams>;
|
|
105
|
-
export const assertMethod = createWrapperFunction(h3.assertMethod);
|
|
106
|
-
export const getRequestHeaders = createWrapperFunction(h3.getRequestHeaders);
|
|
107
|
-
export const getRequestHeader = createWrapperFunction(h3.getRequestHeader);
|
|
108
|
-
export const getRequestURL = createWrapperFunction(h3.getRequestURL);
|
|
109
|
-
export const getRequestHost = createWrapperFunction(h3.getRequestHost);
|
|
110
|
-
export const getRequestProtocol = createWrapperFunction(h3.getRequestProtocol);
|
|
111
|
-
export const getRequestIP = createWrapperFunction(h3.getRequestIP);
|
|
112
|
-
export const setResponseStatus = (code?: number, text?: string) => {
|
|
113
|
-
const e = getEvent();
|
|
114
|
-
|
|
115
|
-
if (e.res.status !== undefined) e.res.status = code;
|
|
116
|
-
if (e.res.statusText !== undefined) e.res.statusText = text;
|
|
117
|
-
};
|
|
118
|
-
export const getResponseStatus = () => getEvent().res.status;
|
|
119
|
-
export const getResponseStatusText = () => getEvent().res.statusText;
|
|
120
|
-
export const getResponseHeaders = () => Object.fromEntries(getEvent().res.headers.entries());
|
|
121
|
-
export const getResponseHeader = (name: string) => getEvent().res.headers.get(name);
|
|
122
|
-
export const setResponseHeaders = (values: Record<string, string>) => {
|
|
123
|
-
const headers = getEvent().res.headers;
|
|
124
|
-
for (const [name, value] of Object.entries(values)) {
|
|
125
|
-
headers.set(name, value);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
export const setResponseHeader = (name: string, value: string | string[]) => {
|
|
129
|
-
const headers = getEvent().res.headers;
|
|
130
|
-
|
|
131
|
-
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
132
|
-
headers.set(name, value);
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
export const appendResponseHeaders = (values: Record<string, string>) => {
|
|
136
|
-
const headers = getEvent().res.headers;
|
|
137
|
-
for (const [name, value] of Object.entries(values)) {
|
|
138
|
-
headers.append(name, value);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
export const appendResponseHeader = (name: string, value: string | string[]) => {
|
|
142
|
-
const headers = getEvent().res.headers;
|
|
143
|
-
|
|
144
|
-
(Array.isArray(value) ? value : [value]).forEach(value => {
|
|
145
|
-
headers.append(name, value);
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
export const defaultContentType = (type: string) =>
|
|
149
|
-
getEvent().res.headers.set("content-type", type);
|
|
150
|
-
export const proxyRequest = createWrapperFunction(h3.proxyRequest);
|
|
151
|
-
export const fetchWithEvent = createWrapperFunction(h3.fetchWithEvent);
|
|
152
|
-
export const getProxyRequestHeaders = createWrapperFunction(h3.getProxyRequestHeaders);
|
|
153
|
-
|
|
154
|
-
export const parseCookies = createWrapperFunction(h3.parseCookies);
|
|
155
|
-
export const getCookie = createWrapperFunction(h3.getCookie);
|
|
156
|
-
export const setCookie = createWrapperFunction(h3.setCookie);
|
|
157
|
-
export const deleteCookie = createWrapperFunction(h3.deleteCookie);
|
|
158
|
-
// not exported :(
|
|
159
|
-
type SessionDataT = Record<string, any>;
|
|
160
|
-
type WrappedUseSession = <T extends SessionDataT>(
|
|
161
|
-
...args: Tail<Parameters<typeof h3.useSession<T>>>
|
|
162
|
-
) => ReturnType<typeof h3.useSession<T>>;
|
|
163
|
-
export const useSession: WrappedUseSession = createWrapperFunction(h3.useSession);
|
|
164
|
-
type WrappedGetSession = <T extends SessionDataT>(
|
|
165
|
-
...args: Tail<Parameters<typeof h3.getSession<T>>>
|
|
166
|
-
) => ReturnType<typeof h3.getSession<T>>;
|
|
167
|
-
export const getSession: WrappedGetSession = createWrapperFunction(h3.getSession);
|
|
168
|
-
type WrappedUpdateSession = <T extends SessionDataT>(
|
|
169
|
-
...args: Tail<Parameters<typeof h3.updateSession<T>>>
|
|
170
|
-
) => ReturnType<typeof h3.updateSession<T>>;
|
|
171
|
-
export const updateSession: WrappedUpdateSession = createWrapperFunction(h3.updateSession);
|
|
172
|
-
type WrappedSealSession = <T extends SessionDataT>(
|
|
173
|
-
...args: Tail<Parameters<typeof h3.sealSession<T>>>
|
|
174
|
-
) => ReturnType<typeof h3.sealSession<T>>;
|
|
175
|
-
export const sealSession: WrappedSealSession = createWrapperFunction(h3.sealSession);
|
|
176
|
-
export const unsealSession = createWrapperFunction(h3.unsealSession);
|
|
177
|
-
export const clearSession = createWrapperFunction(h3.clearSession);
|
|
178
|
-
export const handleCacheHeaders = createWrapperFunction(h3.handleCacheHeaders);
|
|
179
|
-
export const handleCors = createWrapperFunction(h3.handleCors);
|
|
180
|
-
export const appendCorsHeaders = createWrapperFunction(h3.appendCorsHeaders);
|
|
181
|
-
export const appendCorsPreflightHeaders = createWrapperFunction(h3.appendCorsPreflightHeaders);
|
|
182
|
-
export const appendHeader = appendResponseHeader;
|
|
183
|
-
export const appendHeaders = appendResponseHeaders;
|
|
184
|
-
export const setHeader = setResponseHeader;
|
|
185
|
-
export const setHeaders = setResponseHeaders;
|
|
186
|
-
export const getHeader = getRequestHeader;
|
|
187
|
-
export const getHeaders = getRequestHeaders;
|
|
188
|
-
export const getRequestFingerprint = createWrapperFunction(h3.getRequestFingerprint);
|
|
189
|
-
export const getRequestWebStream = () => getEvent().req.body;
|
|
190
|
-
export const readFormData = () => getEvent().req.formData();
|
|
191
|
-
type WrappedReadValidatedBody = <
|
|
192
|
-
T extends HTTPEvent,
|
|
193
|
-
TEventInput = InferEventInput<"body", H3Event, T>,
|
|
194
|
-
>(
|
|
195
|
-
...args: Tail<Parameters<typeof h3.readValidatedBody<T, H3Event, TEventInput>>>
|
|
196
|
-
) => ReturnType<typeof h3.readValidatedBody<T, H3Event, TEventInput>>;
|
|
197
|
-
export const readValidatedBody = createWrapperFunction(h3.readValidatedBody) as PrependOverload<
|
|
198
|
-
typeof h3.readValidatedBody,
|
|
199
|
-
WrappedReadValidatedBody
|
|
200
|
-
>;
|
|
201
|
-
export const getContext = createWrapperFunction(_getContext);
|
|
202
|
-
export const setContext = createWrapperFunction(_setContext);
|
|
203
|
-
export const removeResponseHeader = (name: string) => getEvent().res.headers.delete(name);
|
|
204
|
-
export const clearResponseHeaders = (headerNames?: string[]) => {
|
|
205
|
-
const headers = getEvent().res.headers;
|
|
206
|
-
|
|
207
|
-
if (headerNames && headerNames.length > 0) {
|
|
208
|
-
for (const name of headerNames) {
|
|
209
|
-
headers.delete(name);
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
for (const name of headers.keys()) {
|
|
213
|
-
headers.delete(name);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
package/src/internal.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "h3";
|
|
2
|
-
declare module "h3" {
|
|
3
|
-
import { ViteDevServer } from "vite";
|
|
4
|
-
|
|
5
|
-
export interface H3EventContext {
|
|
6
|
-
viteDevServer?: ViteDevServer;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
import type { Rollup } from "vite";
|
|
11
|
-
declare global {
|
|
12
|
-
var START_CLIENT_BUNDLE: Rollup.OutputBundle;
|
|
13
|
-
var USING_SOLID_START_DEV_SERVER: boolean | undefined;
|
|
14
|
-
}
|