@solidjs/start 2.0.0-alpha.1 → 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 +33 -0
- package/dist/config/constants.d.ts +1 -1
- package/dist/config/constants.js +1 -1
- package/dist/config/dev-server.js +18 -0
- 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 +7 -8
- package/dist/config/index.d.ts +16 -1
- package/dist/config/index.js +30 -29
- package/dist/config/lazy.js +35 -5
- package/dist/config/manifest.js +40 -6
- package/dist/config/vite-utils.d.ts +6 -1
- package/dist/config/vite-utils.js +7 -3
- 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 +20 -0
- package/dist/middleware/index.js +21 -1
- package/dist/server/StartServer.jsx +2 -0
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
- package/dist/server/assets/PatchVirtualDevStyles.jsx +28 -0
- package/dist/server/collect-styles.js +9 -21
- package/dist/server/handler.d.ts +61 -3
- package/dist/server/handler.js +18 -15
- package/dist/server/spa/StartServer.jsx +2 -0
- 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/dev-server.ts +12 -0
- 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 +7 -8
- package/src/config/index.ts +44 -40
- package/src/config/lazy.ts +36 -5
- package/src/config/manifest.ts +40 -9
- package/src/config/vite-utils.ts +8 -4
- 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 +21 -1
- package/src/server/StartServer.tsx +2 -0
- package/src/server/assets/PatchVirtualDevStyles.tsx +31 -0
- package/src/server/collect-styles.ts +9 -26
- package/src/server/handler.ts +20 -16
- package/src/server/spa/StartServer.tsx +2 -0
- 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
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// @ts-ignore - seroval exports issue with NodeNext
|
|
2
|
-
import { join } from "pathe";
|
|
3
|
-
import { deserialize, toJSONAsync } from "seroval";
|
|
4
|
-
import {
|
|
5
|
-
CustomEventPlugin,
|
|
6
|
-
DOMExceptionPlugin,
|
|
7
|
-
EventPlugin,
|
|
8
|
-
FormDataPlugin,
|
|
9
|
-
HeadersPlugin,
|
|
10
|
-
ReadableStreamPlugin,
|
|
11
|
-
RequestPlugin,
|
|
12
|
-
ResponsePlugin,
|
|
13
|
-
URLPlugin,
|
|
14
|
-
URLSearchParamsPlugin,
|
|
15
|
-
} from "seroval-plugins/web";
|
|
16
|
-
import { type Component } from "solid-js";
|
|
17
|
-
|
|
18
|
-
class SerovalChunkReader {
|
|
19
|
-
reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
20
|
-
buffer: Uint8Array;
|
|
21
|
-
done: boolean;
|
|
22
|
-
constructor(stream: ReadableStream<Uint8Array>) {
|
|
23
|
-
this.reader = stream.getReader();
|
|
24
|
-
this.buffer = new Uint8Array(0);
|
|
25
|
-
this.done = false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async readChunk() {
|
|
29
|
-
// if there's no chunk, read again
|
|
30
|
-
const chunk = await this.reader.read();
|
|
31
|
-
if (!chunk.done) {
|
|
32
|
-
// repopulate the buffer
|
|
33
|
-
let newBuffer = new Uint8Array(this.buffer.length + chunk.value.length);
|
|
34
|
-
newBuffer.set(this.buffer);
|
|
35
|
-
newBuffer.set(chunk.value, this.buffer.length);
|
|
36
|
-
this.buffer = newBuffer;
|
|
37
|
-
} else {
|
|
38
|
-
this.done = true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async next(): Promise<any> {
|
|
43
|
-
// Check if the buffer is empty
|
|
44
|
-
if (this.buffer.length === 0) {
|
|
45
|
-
// if we are already done...
|
|
46
|
-
if (this.done) {
|
|
47
|
-
return {
|
|
48
|
-
done: true,
|
|
49
|
-
value: undefined,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// Otherwise, read a new chunk
|
|
53
|
-
await this.readChunk();
|
|
54
|
-
return await this.next();
|
|
55
|
-
}
|
|
56
|
-
// Read the "byte header"
|
|
57
|
-
// The byte header tells us how big the expected data is
|
|
58
|
-
// so we know how much data we should wait before we
|
|
59
|
-
// deserialize the data
|
|
60
|
-
const head = new TextDecoder().decode(this.buffer.subarray(1, 11));
|
|
61
|
-
const bytes = Number.parseInt(head, 16); // ;0x00000000;
|
|
62
|
-
// Check if the buffer has enough bytes to be parsed
|
|
63
|
-
while (bytes > this.buffer.length - 12) {
|
|
64
|
-
// If it's not enough, and the reader is done
|
|
65
|
-
// then the chunk is invalid.
|
|
66
|
-
if (this.done) {
|
|
67
|
-
throw new Error("Malformed server function stream.");
|
|
68
|
-
}
|
|
69
|
-
// Otherwise, we read more chunks
|
|
70
|
-
await this.readChunk();
|
|
71
|
-
}
|
|
72
|
-
// Extract the exact chunk as defined by the byte header
|
|
73
|
-
const partial = new TextDecoder().decode(this.buffer.subarray(12, 12 + bytes));
|
|
74
|
-
// The rest goes to the buffer
|
|
75
|
-
this.buffer = this.buffer.subarray(12 + bytes);
|
|
76
|
-
|
|
77
|
-
// Deserialize the chunk
|
|
78
|
-
return {
|
|
79
|
-
done: false,
|
|
80
|
-
value: deserialize(partial),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async drain() {
|
|
85
|
-
while (true) {
|
|
86
|
-
const result = await this.next();
|
|
87
|
-
if (result.done) {
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function deserializeStream(id: string, response: Response) {
|
|
95
|
-
if (!response.body) {
|
|
96
|
-
throw new Error("missing body");
|
|
97
|
-
}
|
|
98
|
-
const reader = new SerovalChunkReader(response.body);
|
|
99
|
-
|
|
100
|
-
const result = await reader.next();
|
|
101
|
-
|
|
102
|
-
if (!result.done) {
|
|
103
|
-
reader.drain().then(
|
|
104
|
-
() => {
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
delete $R[id];
|
|
107
|
-
},
|
|
108
|
-
() => {
|
|
109
|
-
// no-op
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return result.value;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let INSTANCE = 0;
|
|
118
|
-
|
|
119
|
-
function createRequest(base: string, id: string, instance: string, options: RequestInit) {
|
|
120
|
-
return fetch(base, {
|
|
121
|
-
method: "POST",
|
|
122
|
-
...options,
|
|
123
|
-
headers: {
|
|
124
|
-
...options.headers,
|
|
125
|
-
"X-Server-Id": id,
|
|
126
|
-
"X-Server-Instance": instance,
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const plugins = [
|
|
132
|
-
CustomEventPlugin,
|
|
133
|
-
DOMExceptionPlugin,
|
|
134
|
-
EventPlugin,
|
|
135
|
-
FormDataPlugin,
|
|
136
|
-
HeadersPlugin,
|
|
137
|
-
ReadableStreamPlugin,
|
|
138
|
-
RequestPlugin,
|
|
139
|
-
ResponsePlugin,
|
|
140
|
-
URLSearchParamsPlugin,
|
|
141
|
-
URLPlugin,
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
async function fetchServerFunction(
|
|
145
|
-
base: string,
|
|
146
|
-
id: string,
|
|
147
|
-
options: Omit<RequestInit, "body">,
|
|
148
|
-
args: any[],
|
|
149
|
-
) {
|
|
150
|
-
const instance = `server-fn:${INSTANCE++}`;
|
|
151
|
-
const response = await (args.length === 0
|
|
152
|
-
? createRequest(base, id, instance, options)
|
|
153
|
-
: args.length === 1 && args[0] instanceof FormData
|
|
154
|
-
? createRequest(base, id, instance, { ...options, body: args[0] })
|
|
155
|
-
: args.length === 1 && args[0] instanceof URLSearchParams
|
|
156
|
-
? createRequest(base, id, instance, {
|
|
157
|
-
...options,
|
|
158
|
-
body: args[0],
|
|
159
|
-
headers: { ...options.headers, "Content-Type": "application/x-www-form-urlencoded" },
|
|
160
|
-
})
|
|
161
|
-
: createRequest(base, id, instance, {
|
|
162
|
-
...options,
|
|
163
|
-
body: JSON.stringify(await Promise.resolve(toJSONAsync(args, { plugins }))),
|
|
164
|
-
headers: { ...options.headers, "Content-Type": "application/json" },
|
|
165
|
-
}));
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
response.headers.has("Location") ||
|
|
169
|
-
response.headers.has("X-Revalidate") ||
|
|
170
|
-
response.headers.has("X-Single-Flight")
|
|
171
|
-
) {
|
|
172
|
-
if (response.body) {
|
|
173
|
-
/* @ts-ignore-next-line */
|
|
174
|
-
response.customBody = () => {
|
|
175
|
-
return deserializeStream(instance, response);
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return response;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const contentType = response.headers.get("Content-Type");
|
|
182
|
-
let result;
|
|
183
|
-
if (contentType && contentType.startsWith("text/plain")) {
|
|
184
|
-
result = await response.text();
|
|
185
|
-
} else if (contentType && contentType.startsWith("application/json")) {
|
|
186
|
-
result = await response.json();
|
|
187
|
-
} else {
|
|
188
|
-
result = await deserializeStream(instance, response);
|
|
189
|
-
}
|
|
190
|
-
if (response.headers.has("X-Error")) {
|
|
191
|
-
throw result;
|
|
192
|
-
}
|
|
193
|
-
return result;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function createServerReference(id: string) {
|
|
197
|
-
let baseURL = import.meta.env.BASE_URL ?? "/";
|
|
198
|
-
if (!baseURL.endsWith("/")) baseURL += "/";
|
|
199
|
-
|
|
200
|
-
const fn = (...args: any[]) => fetchServerFunction(`${baseURL}_server`, id, {}, args);
|
|
201
|
-
|
|
202
|
-
return new Proxy(fn, {
|
|
203
|
-
get(target, prop, receiver) {
|
|
204
|
-
if (prop === "url") {
|
|
205
|
-
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
206
|
-
}
|
|
207
|
-
if (prop === "GET") {
|
|
208
|
-
return receiver.withOptions({ method: "GET" });
|
|
209
|
-
}
|
|
210
|
-
if (prop === "withOptions") {
|
|
211
|
-
const url = `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
212
|
-
return (options: RequestInit) => {
|
|
213
|
-
const fn = async (...args: any[]) => {
|
|
214
|
-
const encodeArgs = options.method && options.method.toUpperCase() === "GET";
|
|
215
|
-
return fetchServerFunction(
|
|
216
|
-
encodeArgs
|
|
217
|
-
? url +
|
|
218
|
-
(args.length
|
|
219
|
-
? `&args=${encodeURIComponent(
|
|
220
|
-
JSON.stringify(await Promise.resolve(toJSONAsync(args, { plugins }))),
|
|
221
|
-
)}`
|
|
222
|
-
: "")
|
|
223
|
-
: `${baseURL}_server`,
|
|
224
|
-
id,
|
|
225
|
-
options,
|
|
226
|
-
encodeArgs ? [] : args,
|
|
227
|
-
);
|
|
228
|
-
};
|
|
229
|
-
fn.url = url;
|
|
230
|
-
return fn;
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
return (target as any)[prop];
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function createClientReference(Component: Component<any>, id: string) {
|
|
239
|
-
return Component;
|
|
240
|
-
}
|
|
File without changes
|