@solidjs/start 2.0.0-beta.0 → 2.0.0-beta.1
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/package.json +5 -4
- package/src/config/dev-server.ts +5 -1
- package/dist/client/StartClient.d.ts +0 -7
- package/dist/client/StartClient.jsx +0 -26
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.jsx +0 -2
- package/dist/client/mount.d.ts +0 -1
- package/dist/client/mount.js +0 -1
- package/dist/client/spa/index.d.ts +0 -4
- package/dist/client/spa/index.jsx +0 -5
- package/dist/config/constants.d.ts +0 -16
- package/dist/config/constants.js +0 -16
- package/dist/config/dev-server.d.ts +0 -2
- package/dist/config/dev-server.js +0 -126
- package/dist/config/env.d.ts +0 -19
- package/dist/config/env.js +0 -81
- package/dist/config/fs-router.d.ts +0 -37
- package/dist/config/fs-router.js +0 -141
- package/dist/config/fs-routes/fs-watcher.d.ts +0 -3
- package/dist/config/fs-routes/fs-watcher.js +0 -53
- package/dist/config/fs-routes/index.d.ts +0 -7
- package/dist/config/fs-routes/index.js +0 -107
- package/dist/config/fs-routes/router.d.ts +0 -42
- package/dist/config/fs-routes/router.js +0 -148
- package/dist/config/fs-routes/tree-shake.d.ts +0 -2
- package/dist/config/fs-routes/tree-shake.js +0 -305
- package/dist/config/index.d.ts +0 -25
- package/dist/config/index.js +0 -217
- package/dist/config/lazy.d.ts +0 -3
- package/dist/config/lazy.js +0 -114
- package/dist/config/manifest.d.ts +0 -3
- package/dist/config/manifest.js +0 -109
- package/dist/config/utils.d.ts +0 -4
- package/dist/config/utils.js +0 -6
- package/dist/config/vite-utils.d.ts +0 -21
- package/dist/config/vite-utils.js +0 -85
- package/dist/directives/bubble-function-declaration.d.ts +0 -3
- package/dist/directives/bubble-function-declaration.js +0 -23
- package/dist/directives/compile.d.ts +0 -9
- package/dist/directives/compile.js +0 -40
- package/dist/directives/generate-unique-name.d.ts +0 -3
- package/dist/directives/generate-unique-name.js +0 -16
- package/dist/directives/get-descriptive-name.d.ts +0 -2
- package/dist/directives/get-descriptive-name.js +0 -37
- package/dist/directives/get-import-identifier.d.ts +0 -4
- package/dist/directives/get-import-identifier.js +0 -19
- package/dist/directives/get-root-statement-path.d.ts +0 -2
- package/dist/directives/get-root-statement-path.js +0 -12
- package/dist/directives/index.d.ts +0 -14
- package/dist/directives/index.js +0 -170
- package/dist/directives/is-statement-top-level.d.ts +0 -3
- package/dist/directives/is-statement-top-level.js +0 -9
- package/dist/directives/paths.d.ts +0 -9
- package/dist/directives/paths.js +0 -36
- package/dist/directives/plugin.d.ts +0 -21
- package/dist/directives/plugin.js +0 -302
- package/dist/directives/remove-unused-variables.d.ts +0 -3
- package/dist/directives/remove-unused-variables.js +0 -66
- package/dist/directives/types.d.ts +0 -10
- package/dist/directives/types.js +0 -1
- package/dist/directives/xxhash32.d.ts +0 -6
- package/dist/directives/xxhash32.js +0 -193
- package/dist/fns/client.d.ts +0 -3
- package/dist/fns/client.js +0 -106
- package/dist/fns/handler.d.ts +0 -5
- package/dist/fns/handler.js +0 -269
- package/dist/fns/registration.d.ts +0 -2
- package/dist/fns/registration.js +0 -12
- package/dist/fns/serialization.d.ts +0 -6
- package/dist/fns/serialization.js +0 -208
- package/dist/fns/server.d.ts +0 -7
- package/dist/fns/server.js +0 -38
- package/dist/fns/shared.d.ts +0 -17
- package/dist/fns/shared.js +0 -105
- package/dist/http/index.d.ts +0 -81
- package/dist/http/index.js +0 -129
- package/dist/index.d.ts +0 -5
- package/dist/index.jsx +0 -6
- package/dist/middleware/index.d.ts +0 -38
- package/dist/middleware/index.js +0 -59
- package/dist/router.d.ts +0 -6
- package/dist/router.jsx +0 -29
- package/dist/server/StartServer.d.ts +0 -9
- package/dist/server/StartServer.jsx +0 -34
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +0 -4
- package/dist/server/assets/PatchVirtualDevStyles.jsx +0 -28
- package/dist/server/assets/index.d.ts +0 -2
- package/dist/server/assets/index.js +0 -52
- package/dist/server/assets/render.d.ts +0 -19
- package/dist/server/assets/render.jsx +0 -14
- package/dist/server/collect-styles.d.ts +0 -3
- package/dist/server/collect-styles.js +0 -57
- package/dist/server/fetchEvent.d.ts +0 -7
- package/dist/server/fetchEvent.js +0 -26
- package/dist/server/handler.d.ts +0 -64
- package/dist/server/handler.js +0 -222
- package/dist/server/index.d.ts +0 -9
- package/dist/server/index.jsx +0 -14
- package/dist/server/manifest/client-manifest.d.ts +0 -9
- package/dist/server/manifest/client-manifest.js +0 -6
- package/dist/server/manifest/dev-client-manifest.d.ts +0 -4
- package/dist/server/manifest/dev-client-manifest.js +0 -24
- package/dist/server/manifest/dev-ssr-manifest.d.ts +0 -5
- package/dist/server/manifest/dev-ssr-manifest.js +0 -23
- package/dist/server/manifest/prod-client-manifest.d.ts +0 -5
- package/dist/server/manifest/prod-client-manifest.js +0 -26
- package/dist/server/manifest/prod-ssr-manifest.d.ts +0 -6
- package/dist/server/manifest/prod-ssr-manifest.js +0 -85
- package/dist/server/manifest/ssr-manifest.d.ts +0 -4
- package/dist/server/manifest/ssr-manifest.js +0 -6
- package/dist/server/routes.d.ts +0 -23
- package/dist/server/routes.js +0 -74
- package/dist/server/spa/StartServer.d.ts +0 -9
- package/dist/server/spa/StartServer.jsx +0 -25
- package/dist/server/spa/handler.d.ts +0 -36
- package/dist/server/spa/handler.js +0 -20
- package/dist/server/spa/index.d.ts +0 -4
- package/dist/server/spa/index.jsx +0 -5
- package/dist/server/types.d.ts +0 -75
- package/dist/server/types.js +0 -1
- package/dist/server/util.d.ts +0 -2
- package/dist/server/util.js +0 -8
- package/dist/shared/ErrorBoundary.d.ts +0 -3
- package/dist/shared/ErrorBoundary.jsx +0 -36
- package/dist/shared/GET.d.ts +0 -5
- package/dist/shared/GET.js +0 -8
- package/dist/shared/HttpHeader.d.ts +0 -10
- package/dist/shared/HttpHeader.jsx +0 -38
- package/dist/shared/HttpStatusCode.d.ts +0 -9
- package/dist/shared/HttpStatusCode.js +0 -18
- package/dist/shared/clientOnly.d.ts +0 -12
- package/dist/shared/clientOnly.js +0 -27
- package/dist/shared/dev-overlay/CodeView.d.ts +0 -7
- package/dist/shared/dev-overlay/CodeView.jsx +0 -62
- package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +0 -9
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +0 -226
- package/dist/shared/dev-overlay/createStackFrame.d.ts +0 -9
- package/dist/shared/dev-overlay/createStackFrame.js +0 -56
- package/dist/shared/dev-overlay/download.d.ts +0 -1
- package/dist/shared/dev-overlay/download.js +0 -6
- package/dist/shared/dev-overlay/get-source-map.d.ts +0 -2
- package/dist/shared/dev-overlay/get-source-map.js +0 -25
- package/dist/shared/dev-overlay/icons.d.ts +0 -28
- package/dist/shared/dev-overlay/icons.jsx +0 -150
- package/dist/shared/dev-overlay/index.d.ts +0 -5
- package/dist/shared/dev-overlay/index.jsx +0 -39
- package/dist/shared/dev-overlay/styles.css +0 -292
- package/dist/shared/lazy.d.ts +0 -3
- package/dist/shared/lazy.js +0 -42
- package/dist/shared/serverFunction.d.ts +0 -6
- package/dist/shared/serverFunction.js +0 -8
- package/dist/utils/debounce.d.ts +0 -4
- package/dist/utils/debounce.js +0 -10
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
import { isPathValid } from "./paths.js";
|
|
3
|
-
function isInvalidForRemoval(path) {
|
|
4
|
-
if (isPathValid(path, t.isCatchClause)) {
|
|
5
|
-
// This case is for `catch (error)` blocks
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
// This one is for destructured variables
|
|
9
|
-
let target = path;
|
|
10
|
-
if (isPathValid(path, t.isVariableDeclarator)) {
|
|
11
|
-
target = path.get('id');
|
|
12
|
-
}
|
|
13
|
-
return isPathValid(target, t.isObjectPattern) || isPathValid(target, t.isArrayPattern);
|
|
14
|
-
}
|
|
15
|
-
export function removeUnusedVariables(program) {
|
|
16
|
-
// TODO(Alexis):
|
|
17
|
-
// This implementation is simple but slow
|
|
18
|
-
// We repeat removing unused variables from each pass
|
|
19
|
-
// until no potential unused variables are left.
|
|
20
|
-
// There might be a simpler implementation.
|
|
21
|
-
let dirty = true;
|
|
22
|
-
while (dirty) {
|
|
23
|
-
dirty = false;
|
|
24
|
-
program.traverse({
|
|
25
|
-
BindingIdentifier(path) {
|
|
26
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
27
|
-
if (binding) {
|
|
28
|
-
switch (binding.kind) {
|
|
29
|
-
case "const":
|
|
30
|
-
case "let":
|
|
31
|
-
case "var":
|
|
32
|
-
case "hoisted":
|
|
33
|
-
case "module":
|
|
34
|
-
if (binding.references === 0 && !binding.path.removed) {
|
|
35
|
-
const parent = binding.path.parentPath;
|
|
36
|
-
if (isPathValid(parent, t.isImportDeclaration)) {
|
|
37
|
-
if (parent.node.specifiers.length === 1) {
|
|
38
|
-
parent.remove();
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
binding.path.remove();
|
|
42
|
-
}
|
|
43
|
-
dirty = true;
|
|
44
|
-
}
|
|
45
|
-
else if (!(isInvalidForRemoval(binding.path))) {
|
|
46
|
-
binding.path.remove();
|
|
47
|
-
dirty = true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
case "local":
|
|
52
|
-
case "param":
|
|
53
|
-
case "unknown":
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
VariableDeclaration(path) {
|
|
59
|
-
if (path.node.declarations.length === 0) {
|
|
60
|
-
path.remove();
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
program.scope.crawl();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface NamedImportDefinition {
|
|
2
|
-
kind: "named";
|
|
3
|
-
name: string;
|
|
4
|
-
source: string;
|
|
5
|
-
}
|
|
6
|
-
export interface DefaultImportDefinition {
|
|
7
|
-
kind: "default";
|
|
8
|
-
source: string;
|
|
9
|
-
}
|
|
10
|
-
export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;
|
package/dist/directives/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2019 Jason Dent
|
|
4
|
-
* https://github.com/Jason3S/xxhash
|
|
5
|
-
*/
|
|
6
|
-
const PRIME32_1 = 2654435761;
|
|
7
|
-
const PRIME32_2 = 2246822519;
|
|
8
|
-
const PRIME32_3 = 3266489917;
|
|
9
|
-
const PRIME32_4 = 668265263;
|
|
10
|
-
const PRIME32_5 = 374761393;
|
|
11
|
-
function toUtf8(text) {
|
|
12
|
-
const bytes = [];
|
|
13
|
-
for (let i = 0, n = text.length; i < n; ++i) {
|
|
14
|
-
const c = text.charCodeAt(i);
|
|
15
|
-
if (c < 0x80) {
|
|
16
|
-
bytes.push(c);
|
|
17
|
-
}
|
|
18
|
-
else if (c < 0x800) {
|
|
19
|
-
bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
|
|
20
|
-
}
|
|
21
|
-
else if (c < 0xd800 || c >= 0xe000) {
|
|
22
|
-
bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
|
|
26
|
-
bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return new Uint8Array(bytes);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param buffer - byte array or string
|
|
34
|
-
* @param seed - optional seed (32-bit unsigned);
|
|
35
|
-
*/
|
|
36
|
-
export default function xxHash32(buffer, seed = 0) {
|
|
37
|
-
buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
|
|
38
|
-
const b = buffer;
|
|
39
|
-
/*
|
|
40
|
-
Step 1. Initialize internal accumulators
|
|
41
|
-
Each accumulator gets an initial value based on optional seed input.
|
|
42
|
-
Since the seed is optional, it can be 0.
|
|
43
|
-
```
|
|
44
|
-
u32 acc1 = seed + PRIME32_1 + PRIME32_2;
|
|
45
|
-
u32 acc2 = seed + PRIME32_2;
|
|
46
|
-
u32 acc3 = seed + 0;
|
|
47
|
-
u32 acc4 = seed - PRIME32_1;
|
|
48
|
-
```
|
|
49
|
-
Special case : input is less than 16 bytes
|
|
50
|
-
When input is too small (< 16 bytes), the algorithm will not process any stripe.
|
|
51
|
-
Consequently, it will not make use of parallel accumulators.
|
|
52
|
-
In which case, a simplified initialization is performed, using a single accumulator :
|
|
53
|
-
u32 acc = seed + PRIME32_5;
|
|
54
|
-
The algorithm then proceeds directly to step 4.
|
|
55
|
-
*/
|
|
56
|
-
let acc = (seed + PRIME32_5) & 0xffffffff;
|
|
57
|
-
let offset = 0;
|
|
58
|
-
if (b.length >= 16) {
|
|
59
|
-
const accN = [
|
|
60
|
-
(seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
|
|
61
|
-
(seed + PRIME32_2) & 0xffffffff,
|
|
62
|
-
(seed + 0) & 0xffffffff,
|
|
63
|
-
(seed - PRIME32_1) & 0xffffffff,
|
|
64
|
-
];
|
|
65
|
-
/*
|
|
66
|
-
Step 2. Process stripes
|
|
67
|
-
A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes,
|
|
68
|
-
of 4 bytes each. The first lane is used to update accumulator 1, the second lane
|
|
69
|
-
is used to update accumulator 2, and so on. Each lane read its associated 32-bit
|
|
70
|
-
value using little-endian convention. For each {lane, accumulator}, the update
|
|
71
|
-
process is called a round, and applies the following formula :
|
|
72
|
-
```
|
|
73
|
-
accN = accN + (laneN * PRIME32_2);
|
|
74
|
-
accN = accN <<< 13;
|
|
75
|
-
accN = accN * PRIME32_1;
|
|
76
|
-
```
|
|
77
|
-
This shuffles the bits so that any bit from input lane impacts several bits in
|
|
78
|
-
output accumulator. All operations are performed modulo 2^32.
|
|
79
|
-
Input is consumed one full stripe at a time. Step 2 is looped as many times as
|
|
80
|
-
necessary to consume the whole input, except the last remaining bytes which cannot
|
|
81
|
-
form a stripe (< 16 bytes). When that happens, move to step 3.
|
|
82
|
-
*/
|
|
83
|
-
const b = buffer;
|
|
84
|
-
const limit = b.length - 16;
|
|
85
|
-
let lane = 0;
|
|
86
|
-
for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
|
|
87
|
-
const i = offset;
|
|
88
|
-
const laneN0 = b[i + 0] + (b[i + 1] << 8);
|
|
89
|
-
const laneN1 = b[i + 2] + (b[i + 3] << 8);
|
|
90
|
-
const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
|
|
91
|
-
let acc = (accN[lane] + laneNP) & 0xffffffff;
|
|
92
|
-
acc = (acc << 13) | (acc >>> 19);
|
|
93
|
-
const acc0 = acc & 0xffff;
|
|
94
|
-
const acc1 = acc >>> 16;
|
|
95
|
-
accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
|
|
96
|
-
lane = (lane + 1) & 0x3;
|
|
97
|
-
}
|
|
98
|
-
/*
|
|
99
|
-
Step 3. Accumulator convergence
|
|
100
|
-
All 4 lane accumulators from previous steps are merged to produce a
|
|
101
|
-
single remaining accumulator
|
|
102
|
-
of same width (32-bit). The associated formula is as follows :
|
|
103
|
-
```
|
|
104
|
-
acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
|
|
105
|
-
```
|
|
106
|
-
*/
|
|
107
|
-
acc =
|
|
108
|
-
(((accN[0] << 1) | (accN[0] >>> 31)) +
|
|
109
|
-
((accN[1] << 7) | (accN[1] >>> 25)) +
|
|
110
|
-
((accN[2] << 12) | (accN[2] >>> 20)) +
|
|
111
|
-
((accN[3] << 18) | (accN[3] >>> 14))) &
|
|
112
|
-
0xffffffff;
|
|
113
|
-
}
|
|
114
|
-
/*
|
|
115
|
-
Step 4. Add input length
|
|
116
|
-
The input total length is presumed known at this stage.
|
|
117
|
-
This step is just about adding the length to
|
|
118
|
-
accumulator, so that it participates to final mixing.
|
|
119
|
-
```
|
|
120
|
-
acc = acc + (u32)inputLength;
|
|
121
|
-
```
|
|
122
|
-
*/
|
|
123
|
-
acc = (acc + buffer.length) & 0xffffffff;
|
|
124
|
-
/*
|
|
125
|
-
Step 5. Consume remaining input
|
|
126
|
-
There may be up to 15 bytes remaining to consume from the input.
|
|
127
|
-
The final stage will digest them according
|
|
128
|
-
to following pseudo-code :
|
|
129
|
-
```
|
|
130
|
-
while (remainingLength >= 4) {
|
|
131
|
-
lane = read_32bit_little_endian(input_ptr);
|
|
132
|
-
acc = acc + lane * PRIME32_3;
|
|
133
|
-
acc = (acc <<< 17) * PRIME32_4;
|
|
134
|
-
input_ptr += 4; remainingLength -= 4;
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
This process ensures that all input bytes are present in the final mix.
|
|
138
|
-
*/
|
|
139
|
-
const limit = buffer.length - 4;
|
|
140
|
-
for (; offset <= limit; offset += 4) {
|
|
141
|
-
const i = offset;
|
|
142
|
-
const laneN0 = b[i + 0] + (b[i + 1] << 8);
|
|
143
|
-
const laneN1 = b[i + 2] + (b[i + 3] << 8);
|
|
144
|
-
const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
|
|
145
|
-
acc = (acc + laneP) & 0xffffffff;
|
|
146
|
-
acc = (acc << 17) | (acc >>> 15);
|
|
147
|
-
acc =
|
|
148
|
-
((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
|
|
149
|
-
0xffffffff;
|
|
150
|
-
}
|
|
151
|
-
/*
|
|
152
|
-
```
|
|
153
|
-
while (remainingLength >= 1) {
|
|
154
|
-
lane = read_byte(input_ptr);
|
|
155
|
-
acc = acc + lane * PRIME32_5;
|
|
156
|
-
acc = (acc <<< 11) * PRIME32_1;
|
|
157
|
-
input_ptr += 1; remainingLength -= 1;
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
*/
|
|
161
|
-
for (; offset < b.length; ++offset) {
|
|
162
|
-
const lane = b[offset];
|
|
163
|
-
acc += lane * PRIME32_5;
|
|
164
|
-
acc = (acc << 11) | (acc >>> 21);
|
|
165
|
-
acc =
|
|
166
|
-
((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
|
|
167
|
-
0xffffffff;
|
|
168
|
-
}
|
|
169
|
-
/*
|
|
170
|
-
Step 6. Final mix (avalanche)
|
|
171
|
-
The final mix ensures that all input bits have a chance to impact any bit in
|
|
172
|
-
the output digest, resulting in an unbiased distribution. This is also called
|
|
173
|
-
avalanche effect.
|
|
174
|
-
```
|
|
175
|
-
acc = acc xor (acc >> 15);
|
|
176
|
-
acc = acc * PRIME32_2;
|
|
177
|
-
acc = acc xor (acc >> 13);
|
|
178
|
-
acc = acc * PRIME32_3;
|
|
179
|
-
acc = acc xor (acc >> 16);
|
|
180
|
-
```
|
|
181
|
-
*/
|
|
182
|
-
acc ^= acc >>> 15;
|
|
183
|
-
acc =
|
|
184
|
-
(((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
|
|
185
|
-
(((acc >>> 16) * PRIME32_2) << 16);
|
|
186
|
-
acc ^= acc >>> 13;
|
|
187
|
-
acc =
|
|
188
|
-
(((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
|
|
189
|
-
(((acc >>> 16) * PRIME32_3) << 16);
|
|
190
|
-
acc ^= acc >>> 16;
|
|
191
|
-
// turn any negatives back into a positive number;
|
|
192
|
-
return acc < 0 ? acc + 4294967296 : acc;
|
|
193
|
-
}
|
package/dist/fns/client.d.ts
DELETED
package/dist/fns/client.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// serializeToJSONStream,
|
|
3
|
-
serializeToJSONString, } from "./serialization.js";
|
|
4
|
-
import { BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody, } from "./shared.js";
|
|
5
|
-
let INSTANCE = 0;
|
|
6
|
-
function createRequest(base, id, instance, options) {
|
|
7
|
-
return fetch(base, {
|
|
8
|
-
method: "POST",
|
|
9
|
-
...options,
|
|
10
|
-
headers: {
|
|
11
|
-
...options.headers,
|
|
12
|
-
"X-Server-Id": id,
|
|
13
|
-
"X-Server-Instance": instance,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async function initializeResponse(base, id, instance, options, args) {
|
|
18
|
-
// No args, skip serialization
|
|
19
|
-
if (args.length === 0) {
|
|
20
|
-
return createRequest(base, id, instance, options);
|
|
21
|
-
}
|
|
22
|
-
// For single arguments, we can directly encode as body
|
|
23
|
-
if (args.length === 1) {
|
|
24
|
-
const body = args[0];
|
|
25
|
-
const result = getHeadersAndBody(body);
|
|
26
|
-
if (result) {
|
|
27
|
-
return createRequest(base, id, instance, {
|
|
28
|
-
...options,
|
|
29
|
-
body: result.body,
|
|
30
|
-
headers: {
|
|
31
|
-
...options.headers,
|
|
32
|
-
...result.headers,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Fallback to seroval
|
|
38
|
-
return createRequest(base, id, instance, {
|
|
39
|
-
...options,
|
|
40
|
-
// TODO(Alexis): move to serializeToJSONStream
|
|
41
|
-
body: await serializeToJSONString(args),
|
|
42
|
-
// duplex: 'half',
|
|
43
|
-
// body: serializeToJSONStream(args),
|
|
44
|
-
headers: {
|
|
45
|
-
...options.headers,
|
|
46
|
-
"Content-Type": "text/plain",
|
|
47
|
-
[BODY_FORMAT_KEY]: BodyFormat.Seroval,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async function fetchServerFunction(base, id, options, args) {
|
|
52
|
-
const instance = `server-fn:${INSTANCE++}`;
|
|
53
|
-
const response = await initializeResponse(base, id, instance, options, args);
|
|
54
|
-
if (response.headers.has("Location") ||
|
|
55
|
-
response.headers.has("X-Revalidate") ||
|
|
56
|
-
response.headers.has("X-Single-Flight")) {
|
|
57
|
-
if (response.body) {
|
|
58
|
-
/* @ts-ignore-next-line */
|
|
59
|
-
response.customBody = async () => {
|
|
60
|
-
return await extractBody(instance, true, response.clone());
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return response;
|
|
64
|
-
}
|
|
65
|
-
const result = await extractBody(instance, true, response.clone());
|
|
66
|
-
if (response.headers.has("X-Error")) {
|
|
67
|
-
throw result;
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
export function cloneServerReference(id) {
|
|
72
|
-
let baseURL = import.meta.env.BASE_URL ?? "/";
|
|
73
|
-
if (!baseURL.endsWith("/"))
|
|
74
|
-
baseURL += "/";
|
|
75
|
-
const fn = (...args) => fetchServerFunction(`${baseURL}_server`, id, {}, args);
|
|
76
|
-
return new Proxy(fn, {
|
|
77
|
-
get(target, prop, receiver) {
|
|
78
|
-
if (prop === "url") {
|
|
79
|
-
return `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
80
|
-
}
|
|
81
|
-
if (prop === "GET") {
|
|
82
|
-
return receiver.withOptions({ method: "GET" });
|
|
83
|
-
}
|
|
84
|
-
if (prop === "withOptions") {
|
|
85
|
-
const url = `${baseURL}_server?id=${encodeURIComponent(id)}`;
|
|
86
|
-
return (options) => {
|
|
87
|
-
const fn = async (...args) => {
|
|
88
|
-
const encodeArgs = options.method && options.method.toUpperCase() === "GET";
|
|
89
|
-
return fetchServerFunction(encodeArgs
|
|
90
|
-
? url +
|
|
91
|
-
(args.length
|
|
92
|
-
? `&args=${encodeURIComponent(await serializeToJSONString(args))}`
|
|
93
|
-
: "")
|
|
94
|
-
: `${baseURL}_server`, id, options, encodeArgs ? [] : args);
|
|
95
|
-
};
|
|
96
|
-
fn.url = url;
|
|
97
|
-
return fn;
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return target[prop];
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export function createClientReference(Component, id) {
|
|
105
|
-
return Component;
|
|
106
|
-
}
|
package/dist/fns/handler.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type H3Event } from "h3";
|
|
2
|
-
import "solid-start:server-fn-manifest";
|
|
3
|
-
import type { FetchEvent } from "../server/types.ts";
|
|
4
|
-
export declare function handleServerFunction(h3Event: H3Event): Promise<unknown>;
|
|
5
|
-
export declare function createSingleFlightHeaders(sourceEvent: FetchEvent): Headers;
|
package/dist/fns/handler.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { parseSetCookie } from "cookie-es";
|
|
2
|
-
import { parseCookies } from "h3";
|
|
3
|
-
import { sharedConfig } from "solid-js";
|
|
4
|
-
import { renderToString } from "solid-js/web";
|
|
5
|
-
import { provideRequestEvent } from "solid-js/web/storage";
|
|
6
|
-
import { getFetchEvent, mergeResponseHeaders } from "../server/fetchEvent.js";
|
|
7
|
-
import { createPageEvent } from "../server/handler.js";
|
|
8
|
-
import { deserializeFromJSONString, serializeToJSONStream, serializeToJSStream, } from "./serialization.js";
|
|
9
|
-
import { BODY_FORMAT_KEY, BodyFormat, extractBody, getHeadersAndBody, } from "./shared.js";
|
|
10
|
-
import "solid-start:server-fn-manifest";
|
|
11
|
-
import { getServerFunction } from "./registration.js";
|
|
12
|
-
import { getExpectedRedirectStatus } from "../server/util.js";
|
|
13
|
-
export async function handleServerFunction(h3Event) {
|
|
14
|
-
const event = getFetchEvent(h3Event);
|
|
15
|
-
const request = event.request;
|
|
16
|
-
const serverReference = request.headers.get("X-Server-Id");
|
|
17
|
-
const instance = request.headers.get("X-Server-Instance");
|
|
18
|
-
const singleFlight = request.headers.has("X-Single-Flight");
|
|
19
|
-
const url = new URL(request.url);
|
|
20
|
-
let functionId;
|
|
21
|
-
if (serverReference) {
|
|
22
|
-
// invariant(typeof serverReference === "string", "Invalid server function");
|
|
23
|
-
[functionId] = serverReference.split("#");
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
functionId = url.searchParams.get("id");
|
|
27
|
-
if (!functionId) {
|
|
28
|
-
return process.env.NODE_ENV === "development"
|
|
29
|
-
? new Response("Server function not found", { status: 404 })
|
|
30
|
-
: new Response(null, { status: 404 });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const serverFunction = getServerFunction(functionId);
|
|
34
|
-
let parsed = [];
|
|
35
|
-
// grab bound arguments from url when no JS
|
|
36
|
-
if (!instance || request.method === "GET") {
|
|
37
|
-
const args = url.searchParams.get("args");
|
|
38
|
-
if (args) {
|
|
39
|
-
const result = (await deserializeFromJSONString(args));
|
|
40
|
-
for (const arg of result) {
|
|
41
|
-
parsed.push(arg);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (request.method === "POST" && request.body !== null) {
|
|
46
|
-
const bodyFormat = request.headers.get(BODY_FORMAT_KEY);
|
|
47
|
-
const decoded = await extractBody("", false, request.clone());
|
|
48
|
-
if (bodyFormat === BodyFormat.Seroval) {
|
|
49
|
-
parsed = decoded;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
parsed.push(decoded);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
let result = await provideRequestEvent(event, async () => {
|
|
57
|
-
/* @ts-expect-error */
|
|
58
|
-
sharedConfig.context = { event };
|
|
59
|
-
event.locals.serverFunctionMeta = {
|
|
60
|
-
id: functionId,
|
|
61
|
-
};
|
|
62
|
-
return serverFunction(...parsed);
|
|
63
|
-
});
|
|
64
|
-
if (singleFlight && instance) {
|
|
65
|
-
result = await handleSingleFlight(event, result);
|
|
66
|
-
}
|
|
67
|
-
// handle responses
|
|
68
|
-
if (result instanceof Response) {
|
|
69
|
-
if (result.headers && result.headers.has("X-Content-Raw"))
|
|
70
|
-
return result;
|
|
71
|
-
if (instance) {
|
|
72
|
-
// forward headers
|
|
73
|
-
if (result.headers)
|
|
74
|
-
mergeResponseHeaders(h3Event, result.headers);
|
|
75
|
-
// forward non-redirect statuses
|
|
76
|
-
if (result.status && (result.status < 300 || result.status >= 400))
|
|
77
|
-
h3Event.res.status = result.status;
|
|
78
|
-
if (result.customBody) {
|
|
79
|
-
result = await result.customBody();
|
|
80
|
-
}
|
|
81
|
-
else if (result.body == null)
|
|
82
|
-
result = null;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// handle no JS success case
|
|
86
|
-
if (!instance)
|
|
87
|
-
return handleNoJS(result, request, parsed);
|
|
88
|
-
const body = getHeadersAndBody(result);
|
|
89
|
-
if (body) {
|
|
90
|
-
return new Response(body.body, {
|
|
91
|
-
headers: body.headers,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
h3Event.res.headers.set(BODY_FORMAT_KEY, BodyFormat.Seroval);
|
|
95
|
-
if (import.meta.env.SEROVAL_MODE === "js") {
|
|
96
|
-
h3Event.res.headers.set("content-type", "text/javascript");
|
|
97
|
-
return serializeToJSStream(instance, result);
|
|
98
|
-
}
|
|
99
|
-
h3Event.res.headers.set("content-type", "text/plain");
|
|
100
|
-
return serializeToJSONStream(result);
|
|
101
|
-
}
|
|
102
|
-
catch (x) {
|
|
103
|
-
if (x instanceof Response) {
|
|
104
|
-
if (singleFlight && instance) {
|
|
105
|
-
x = await handleSingleFlight(event, x);
|
|
106
|
-
}
|
|
107
|
-
// forward headers
|
|
108
|
-
if (x.headers)
|
|
109
|
-
mergeResponseHeaders(h3Event, x.headers);
|
|
110
|
-
// forward non-redirect statuses
|
|
111
|
-
if (x.status && (!instance || x.status < 300 || x.status >= 400))
|
|
112
|
-
h3Event.res.status = x.status;
|
|
113
|
-
if (x.customBody) {
|
|
114
|
-
x = await x.customBody();
|
|
115
|
-
}
|
|
116
|
-
else if (x.body == null)
|
|
117
|
-
x = null;
|
|
118
|
-
h3Event.res.headers.set("X-Error", "true");
|
|
119
|
-
}
|
|
120
|
-
else if (instance) {
|
|
121
|
-
const error = x instanceof Error ? x.message : typeof x === "string" ? x : "true";
|
|
122
|
-
h3Event.res.headers.set("X-Error", error.replace(/[\r\n]+/g, ""));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
x = handleNoJS(x, request, parsed, true);
|
|
126
|
-
}
|
|
127
|
-
if (instance) {
|
|
128
|
-
const body = getHeadersAndBody(x);
|
|
129
|
-
if (body) {
|
|
130
|
-
const headers = new Headers(body.headers);
|
|
131
|
-
const errorHeader = h3Event.res.headers.get("X-Error");
|
|
132
|
-
if (errorHeader !== null) {
|
|
133
|
-
headers.set("X-Error", errorHeader);
|
|
134
|
-
}
|
|
135
|
-
return new Response(body.body, {
|
|
136
|
-
headers: body.headers,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
h3Event.res.headers.set(BODY_FORMAT_KEY, BodyFormat.Seroval);
|
|
140
|
-
if (import.meta.env.SEROVAL_MODE === "js") {
|
|
141
|
-
h3Event.res.headers.set("content-type", "text/javascript");
|
|
142
|
-
return serializeToJSStream(instance, x);
|
|
143
|
-
}
|
|
144
|
-
h3Event.res.headers.set("content-type", "text/plain");
|
|
145
|
-
return serializeToJSONStream(x);
|
|
146
|
-
}
|
|
147
|
-
return x;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function handleNoJS(result, request, parsed, thrown) {
|
|
151
|
-
const url = new URL(request.url);
|
|
152
|
-
const isError = result instanceof Error;
|
|
153
|
-
let statusCode = 302;
|
|
154
|
-
let headers;
|
|
155
|
-
if (result instanceof Response) {
|
|
156
|
-
headers = new Headers(result.headers);
|
|
157
|
-
if (result.headers.has("Location")) {
|
|
158
|
-
headers.set(`Location`, new URL(result.headers.get("Location"), url.origin + import.meta.env.BASE_URL).toString());
|
|
159
|
-
statusCode = getExpectedRedirectStatus(result);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
else
|
|
163
|
-
headers = new Headers({
|
|
164
|
-
Location: new URL(request.headers.get("referer")).toString(),
|
|
165
|
-
});
|
|
166
|
-
if (result) {
|
|
167
|
-
headers.append("Set-Cookie", `flash=${encodeURIComponent(JSON.stringify({
|
|
168
|
-
url: url.pathname + url.search,
|
|
169
|
-
result: isError ? result.message : result,
|
|
170
|
-
thrown: thrown,
|
|
171
|
-
error: isError,
|
|
172
|
-
input: [...parsed.slice(0, -1), [...parsed[parsed.length - 1].entries()]],
|
|
173
|
-
}))}; Secure; HttpOnly;`);
|
|
174
|
-
}
|
|
175
|
-
return new Response(null, {
|
|
176
|
-
status: statusCode,
|
|
177
|
-
headers,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
let App;
|
|
181
|
-
export function createSingleFlightHeaders(sourceEvent) {
|
|
182
|
-
// cookie handling logic is pretty simplistic so this might be imperfect
|
|
183
|
-
// unclear if h3 internals are available on all platforms but we need a way to
|
|
184
|
-
// update request headers on the underlying H3 event.
|
|
185
|
-
const headers = new Headers(sourceEvent.request.headers);
|
|
186
|
-
const cookies = parseCookies(sourceEvent.nativeEvent);
|
|
187
|
-
const SetCookies = sourceEvent.response.headers.getSetCookie();
|
|
188
|
-
headers.delete("cookie");
|
|
189
|
-
// let useH3Internals = false;
|
|
190
|
-
// if (sourceEvent.nativeEvent.node?.req) {
|
|
191
|
-
// useH3Internals = true;
|
|
192
|
-
// sourceEvent.nativeEvent.node.req.headers.cookie = "";
|
|
193
|
-
// }
|
|
194
|
-
SetCookies.forEach(cookie => {
|
|
195
|
-
if (!cookie)
|
|
196
|
-
return;
|
|
197
|
-
const { maxAge, expires, name, value } = parseSetCookie(cookie);
|
|
198
|
-
if (maxAge != null && maxAge <= 0) {
|
|
199
|
-
delete cookies[name];
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (expires != null && expires.getTime() <= Date.now()) {
|
|
203
|
-
delete cookies[name];
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
cookies[name] = value;
|
|
207
|
-
});
|
|
208
|
-
Object.entries(cookies).forEach(([key, value]) => {
|
|
209
|
-
headers.append("cookie", `${key}=${value}`);
|
|
210
|
-
// useH3Internals &&
|
|
211
|
-
// (sourceEvent.nativeEvent.node.req.headers.cookie += `${key}=${value};`);
|
|
212
|
-
});
|
|
213
|
-
return headers;
|
|
214
|
-
}
|
|
215
|
-
async function handleSingleFlight(sourceEvent, result) {
|
|
216
|
-
let revalidate;
|
|
217
|
-
let url = new URL(sourceEvent.request.headers.get("referer")).toString();
|
|
218
|
-
if (result instanceof Response) {
|
|
219
|
-
if (result.headers.has("X-Revalidate"))
|
|
220
|
-
revalidate = result.headers.get("X-Revalidate").split(",");
|
|
221
|
-
if (result.headers.has("Location"))
|
|
222
|
-
url = new URL(result.headers.get("Location"), new URL(sourceEvent.request.url).origin + import.meta.env.BASE_URL).toString();
|
|
223
|
-
}
|
|
224
|
-
const event = { ...sourceEvent };
|
|
225
|
-
event.request = new Request(url, {
|
|
226
|
-
headers: createSingleFlightHeaders(sourceEvent),
|
|
227
|
-
});
|
|
228
|
-
return await provideRequestEvent(event, async () => {
|
|
229
|
-
await createPageEvent(event);
|
|
230
|
-
App || (App = (await import("solid-start:app")).default);
|
|
231
|
-
/* @ts-expect-error */
|
|
232
|
-
event.router.dataOnly = revalidate || true;
|
|
233
|
-
/* @ts-expect-error */
|
|
234
|
-
event.router.previousUrl = sourceEvent.request.headers.get("referer");
|
|
235
|
-
try {
|
|
236
|
-
renderToString(() => {
|
|
237
|
-
/* @ts-expect-error */
|
|
238
|
-
sharedConfig.context.event = event;
|
|
239
|
-
App();
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
catch (e) {
|
|
243
|
-
console.log(e);
|
|
244
|
-
}
|
|
245
|
-
/* @ts-expect-error */
|
|
246
|
-
const body = event.router.data;
|
|
247
|
-
if (!body)
|
|
248
|
-
return result;
|
|
249
|
-
let containsKey = false;
|
|
250
|
-
for (const key in body) {
|
|
251
|
-
if (body[key] === undefined)
|
|
252
|
-
delete body[key];
|
|
253
|
-
else
|
|
254
|
-
containsKey = true;
|
|
255
|
-
}
|
|
256
|
-
if (!containsKey)
|
|
257
|
-
return result;
|
|
258
|
-
if (!(result instanceof Response)) {
|
|
259
|
-
body["_$value"] = result;
|
|
260
|
-
result = new Response(null, { status: 200 });
|
|
261
|
-
}
|
|
262
|
-
else if (result.customBody) {
|
|
263
|
-
body["_$value"] = result.customBody();
|
|
264
|
-
}
|
|
265
|
-
result.customBody = () => body;
|
|
266
|
-
result.headers.set("X-Single-Flight", "true");
|
|
267
|
-
return result;
|
|
268
|
-
});
|
|
269
|
-
}
|
package/dist/fns/registration.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const REGISTRATIONS = new Map();
|
|
2
|
-
export function registerServerFunction(id, callback) {
|
|
3
|
-
REGISTRATIONS.set(id, callback);
|
|
4
|
-
return callback;
|
|
5
|
-
}
|
|
6
|
-
export function getServerFunction(id) {
|
|
7
|
-
const fn = REGISTRATIONS.get(id);
|
|
8
|
-
if (fn) {
|
|
9
|
-
return fn;
|
|
10
|
-
}
|
|
11
|
-
throw new Error('invalid server function: ' + id);
|
|
12
|
-
}
|