@solidjs/start 2.0.0-alpha.2 → 2.0.0-beta.0

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/config/constants.d.ts +3 -3
  3. package/dist/config/constants.js +1 -1
  4. package/dist/config/dev-server.js +9 -1
  5. package/dist/config/env.d.ts +19 -0
  6. package/dist/config/env.js +81 -0
  7. package/dist/config/fs-routes/fs-watcher.js +32 -28
  8. package/dist/config/fs-routes/index.js +2 -2
  9. package/dist/config/fs-routes/router.d.ts +8 -3
  10. package/dist/config/fs-routes/router.js +26 -13
  11. package/dist/config/fs-routes/tree-shake.js +0 -43
  12. package/dist/config/index.d.ts +16 -1
  13. package/dist/config/index.js +31 -31
  14. package/dist/config/lazy.js +4 -2
  15. package/dist/config/manifest.js +41 -7
  16. package/dist/config/vite-utils.d.ts +1 -1
  17. package/dist/directives/bubble-function-declaration.d.ts +3 -0
  18. package/dist/directives/bubble-function-declaration.js +23 -0
  19. package/dist/directives/compile.d.ts +9 -0
  20. package/dist/directives/compile.js +40 -0
  21. package/dist/directives/generate-unique-name.d.ts +3 -0
  22. package/dist/directives/generate-unique-name.js +16 -0
  23. package/dist/directives/get-descriptive-name.d.ts +2 -0
  24. package/dist/directives/get-descriptive-name.js +37 -0
  25. package/dist/directives/get-import-identifier.d.ts +4 -0
  26. package/dist/directives/get-import-identifier.js +19 -0
  27. package/dist/directives/get-root-statement-path.d.ts +2 -0
  28. package/dist/directives/get-root-statement-path.js +12 -0
  29. package/dist/directives/index.d.ts +14 -0
  30. package/dist/directives/index.js +170 -0
  31. package/dist/directives/is-statement-top-level.d.ts +3 -0
  32. package/dist/directives/is-statement-top-level.js +9 -0
  33. package/dist/directives/paths.d.ts +9 -0
  34. package/dist/directives/paths.js +36 -0
  35. package/dist/directives/plugin.d.ts +21 -0
  36. package/dist/directives/plugin.js +302 -0
  37. package/dist/directives/remove-unused-variables.d.ts +3 -0
  38. package/dist/directives/remove-unused-variables.js +66 -0
  39. package/dist/directives/types.d.ts +10 -0
  40. package/dist/directives/xxhash32.d.ts +6 -0
  41. package/dist/directives/xxhash32.js +193 -0
  42. package/dist/{server/server-runtime.d.ts → fns/client.d.ts} +1 -1
  43. package/dist/fns/client.js +106 -0
  44. package/dist/fns/handler.d.ts +5 -0
  45. package/dist/{server/server-functions-handler.js → fns/handler.js} +55 -96
  46. package/dist/fns/registration.d.ts +2 -0
  47. package/dist/fns/registration.js +12 -0
  48. package/dist/fns/serialization.d.ts +6 -0
  49. package/dist/fns/serialization.js +208 -0
  50. package/dist/fns/server.d.ts +7 -0
  51. package/dist/{server/server-fns-runtime.js → fns/server.js} +7 -1
  52. package/dist/fns/shared.d.ts +17 -0
  53. package/dist/fns/shared.js +105 -0
  54. package/dist/http/index.d.ts +1 -1
  55. package/dist/middleware/index.d.ts +17 -0
  56. package/dist/middleware/index.js +15 -0
  57. package/dist/server/handler.d.ts +61 -3
  58. package/dist/server/handler.js +18 -16
  59. package/dist/server/spa/handler.d.ts +30 -1
  60. package/dist/server/types.d.ts +1 -1
  61. package/dist/shared/dev-overlay/CodeView.jsx +4 -4
  62. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +34 -34
  63. package/dist/shared/dev-overlay/index.jsx +2 -2
  64. package/dist/shared/dev-overlay/styles.css +40 -40
  65. package/dist/utils/debounce.d.ts +4 -0
  66. package/dist/utils/debounce.js +10 -0
  67. package/package.json +28 -21
  68. package/src/config/constants.ts +3 -3
  69. package/src/config/env.ts +105 -0
  70. package/src/config/fs-routes/fs-watcher.ts +38 -49
  71. package/src/config/fs-routes/index.ts +2 -2
  72. package/src/config/fs-routes/router.ts +29 -13
  73. package/src/config/fs-routes/tree-shake.ts +1 -48
  74. package/src/config/index.ts +45 -41
  75. package/src/config/lazy.ts +3 -2
  76. package/src/config/manifest.ts +45 -10
  77. package/src/config/vite-utils.ts +1 -1
  78. package/src/directives/bubble-function-declaration.ts +33 -0
  79. package/src/directives/compile.ts +54 -0
  80. package/src/directives/generate-unique-name.ts +22 -0
  81. package/src/directives/get-descriptive-name.ts +39 -0
  82. package/src/directives/get-import-identifier.ts +34 -0
  83. package/src/directives/get-root-statement-path.ts +14 -0
  84. package/src/directives/index.ts +233 -0
  85. package/src/directives/is-statement-top-level.ts +13 -0
  86. package/src/directives/paths.ts +63 -0
  87. package/src/directives/plugin.ts +389 -0
  88. package/src/directives/remove-unused-variables.ts +70 -0
  89. package/src/directives/types.ts +12 -0
  90. package/src/directives/xxhash32.ts +214 -0
  91. package/src/env.d.ts +1 -1
  92. package/src/fns/client.ts +141 -0
  93. package/src/fns/handler.spec.ts +85 -0
  94. package/src/{server/server-functions-handler.ts → fns/handler.ts} +65 -117
  95. package/src/fns/registration.ts +19 -0
  96. package/src/fns/serialization.ts +250 -0
  97. package/src/{server/server-fns-runtime.ts → fns/server.ts} +17 -2
  98. package/src/fns/shared.ts +116 -0
  99. package/src/middleware/index.ts +17 -0
  100. package/src/server/handler.ts +19 -17
  101. package/src/server/types.ts +1 -1
  102. package/src/shared/dev-overlay/CodeView.tsx +5 -7
  103. package/src/shared/dev-overlay/DevOverlayDialog.tsx +34 -34
  104. package/src/shared/dev-overlay/get-source-map.ts +1 -1
  105. package/src/shared/dev-overlay/index.tsx +4 -4
  106. package/src/shared/dev-overlay/styles.css +40 -40
  107. package/src/utils/debounce.ts +10 -0
  108. package/tsconfig.json +1 -0
  109. package/dist/server/fetchEvent.spec.js +0 -65
  110. package/dist/server/server-fns-runtime.d.ts +0 -1
  111. package/dist/server/server-functions-handler.d.ts +0 -2
  112. package/dist/server/server-runtime.js +0 -194
  113. package/src/server/server-runtime.ts +0 -240
  114. /package/dist/{server/fetchEvent.spec.d.ts → directives/types.js} +0 -0
@@ -0,0 +1,302 @@
1
+ import * as t from "@babel/types";
2
+ import { bubbleFunctionDeclaration } from "./bubble-function-declaration.js";
3
+ import { generateUniqueName } from "./generate-unique-name.js";
4
+ import { getDescriptiveName } from "./get-descriptive-name.js";
5
+ import { getImportIdentifier } from "./get-import-identifier.js";
6
+ import { getRootStatementPath } from "./get-root-statement-path.js";
7
+ import { isStatementTopLevel } from "./is-statement-top-level.js";
8
+ import { isPathValid, unwrapPath } from "./paths.js";
9
+ import { removeUnusedVariables } from "./remove-unused-variables.js";
10
+ function isValidFunction(node) {
11
+ return t.isArrowFunctionExpression(node) || t.isFunctionExpression(node);
12
+ }
13
+ function isDirectiveValid(ctx, directives) {
14
+ for (let i = 0, len = directives.length; i < len; i++) {
15
+ if (directives[i].value.value === ctx.directive) {
16
+ return true;
17
+ }
18
+ }
19
+ return false;
20
+ }
21
+ function cleanDirectives(path, target) {
22
+ const newDirectives = [];
23
+ for (let i = 0, len = path.node.directives.length; i < len; i++) {
24
+ const current = path.node.directives[i];
25
+ if (current.value.value !== target) {
26
+ newDirectives.push(current);
27
+ }
28
+ }
29
+ path.node.directives = newDirectives;
30
+ }
31
+ function cleanFunctionDirectives(ctx, path) {
32
+ const body = path.get("body");
33
+ if (isPathValid(body, t.isBlockStatement)) {
34
+ cleanDirectives(body, ctx.directive);
35
+ }
36
+ }
37
+ function isFunctionDirectiveValid(ctx, path) {
38
+ const body = path.get("body");
39
+ if (isPathValid(body, t.isBlockStatement)) {
40
+ return isDirectiveValid(ctx, body.node.directives);
41
+ }
42
+ return false;
43
+ }
44
+ function createID(ctx, name) {
45
+ const base = `${ctx.hash}-${ctx.count++}`;
46
+ if (ctx.env === "development") {
47
+ return `${base}-${name}`;
48
+ }
49
+ return base;
50
+ }
51
+ function transformFunction(ctx, path, direct) {
52
+ if (!direct) {
53
+ if (!isFunctionDirectiveValid(ctx, path)) {
54
+ return;
55
+ }
56
+ cleanFunctionDirectives(ctx, path);
57
+ }
58
+ // First, get root statement
59
+ const rootStatement = getRootStatementPath(path);
60
+ // Create a unique ID for the function
61
+ const fnID = createID(ctx, getDescriptiveName(path, "anonymous"));
62
+ if (ctx.mode === "server") {
63
+ // Create a "source" function on the root-level
64
+ const sourceReference = t.callExpression(getImportIdentifier(ctx.imports, path, ctx.definitions.register), [t.stringLiteral(fnID), path.node]);
65
+ const sourceID = generateUniqueName(path, "serverFn");
66
+ rootStatement.insertBefore(t.variableDeclaration("const", [t.variableDeclarator(sourceID, sourceReference)]));
67
+ // Clone the source function to replace the server function
68
+ path.replaceWith(t.callExpression(getImportIdentifier(ctx.imports, path, ctx.definitions.clone), [sourceID]));
69
+ }
70
+ else {
71
+ // Otherwise, clone the function based on its ID
72
+ path.replaceWith(t.callExpression(getImportIdentifier(ctx.imports, path, ctx.definitions.clone), [
73
+ t.stringLiteral(fnID),
74
+ ]));
75
+ }
76
+ path.scope.crawl();
77
+ }
78
+ function traceBinding(path, name) {
79
+ const current = path.scope.getBinding(name);
80
+ if (!current) {
81
+ return undefined;
82
+ }
83
+ switch (current.kind) {
84
+ case "const":
85
+ case "let":
86
+ case "var": {
87
+ if (isPathValid(current.path, t.isVariableDeclarator)) {
88
+ // Check if left is identifier
89
+ const left = unwrapPath(current.path.get("id"), t.isIdentifier);
90
+ if (left) {
91
+ const right = unwrapPath(current.path.get("init"), t.isIdentifier);
92
+ if (right) {
93
+ return traceBinding(path, right.node.name);
94
+ }
95
+ // Only valid for functions
96
+ const func = unwrapPath(current.path.get("init"), isValidFunction);
97
+ if (func) {
98
+ return current;
99
+ }
100
+ }
101
+ }
102
+ return undefined;
103
+ }
104
+ case "hoisted":
105
+ case "local":
106
+ case "module":
107
+ case "param":
108
+ case "unknown":
109
+ return undefined;
110
+ }
111
+ }
112
+ function transformBindingForServer(ctx, binding) {
113
+ if (isPathValid(binding.path, t.isVariableDeclarator)) {
114
+ const right = unwrapPath(binding.path.get("init"), isValidFunction);
115
+ if (right) {
116
+ transformFunction(ctx, right, true);
117
+ }
118
+ }
119
+ }
120
+ function transformModuleLevelDirective(ctx, program) {
121
+ cleanDirectives(program, ctx.directive);
122
+ program.traverse({
123
+ FunctionDeclaration(child) {
124
+ // We only need to move top-level functions
125
+ if (isStatementTopLevel(child)) {
126
+ bubbleFunctionDeclaration(child);
127
+ }
128
+ },
129
+ });
130
+ program.scope.crawl();
131
+ if (ctx.mode === "server") {
132
+ // Trace bindings
133
+ const bindings = new Set();
134
+ program.traverse({
135
+ ExportDefaultDeclaration(path) {
136
+ const id = unwrapPath(path.get("declaration"), t.isIdentifier);
137
+ if (id) {
138
+ const binding = traceBinding(path, id.node.name);
139
+ if (binding) {
140
+ bindings.add(binding);
141
+ }
142
+ }
143
+ },
144
+ ExportNamedDeclaration(path) {
145
+ if (path.node.source || path.node.exportKind === "type") {
146
+ return;
147
+ }
148
+ for (const specifier of path.get("specifiers")) {
149
+ if (isPathValid(specifier, t.isExportSpecifier)) {
150
+ const binding = traceBinding(specifier, specifier.node.local.name);
151
+ if (binding) {
152
+ bindings.add(binding);
153
+ }
154
+ }
155
+ }
156
+ const declarations = path.get("declaration");
157
+ if (isPathValid(declarations, t.isVariableDeclaration)) {
158
+ for (const declaration of declarations.get("declarations")) {
159
+ // Check if left is identifier
160
+ const left = unwrapPath(declaration.get("id"), t.isIdentifier);
161
+ if (left) {
162
+ const binding = traceBinding(left, left.node.name);
163
+ if (binding) {
164
+ bindings.add(binding);
165
+ }
166
+ }
167
+ }
168
+ }
169
+ },
170
+ });
171
+ for (const binding of bindings) {
172
+ transformBindingForServer(ctx, binding);
173
+ }
174
+ }
175
+ else {
176
+ // Trace bindings
177
+ const uniqueBindings = new Set();
178
+ const exportedBindings = new Map();
179
+ program.traverse({
180
+ ExportDefaultDeclaration(path) {
181
+ const id = unwrapPath(path.get("declaration"), t.isIdentifier);
182
+ if (id) {
183
+ const binding = traceBinding(path, id.node.name);
184
+ if (binding) {
185
+ uniqueBindings.add(binding);
186
+ exportedBindings.set("default", binding);
187
+ }
188
+ }
189
+ },
190
+ ExportNamedDeclaration(path) {
191
+ if (path.node.source || path.node.exportKind === "type") {
192
+ return;
193
+ }
194
+ for (const specifier of path.get("specifiers")) {
195
+ if (isPathValid(specifier, t.isExportSpecifier)) {
196
+ const binding = traceBinding(specifier, specifier.node.local.name);
197
+ if (binding) {
198
+ const key = t.isIdentifier(specifier.node.exported)
199
+ ? specifier.node.exported.name
200
+ : specifier.node.exported.value;
201
+ uniqueBindings.add(binding);
202
+ exportedBindings.set(key, binding);
203
+ }
204
+ }
205
+ }
206
+ const declarations = path.get("declaration");
207
+ if (isPathValid(declarations, t.isVariableDeclaration)) {
208
+ for (const declaration of declarations.get("declarations")) {
209
+ // Check if left is identifier
210
+ const left = unwrapPath(declaration.get("id"), t.isIdentifier);
211
+ if (left) {
212
+ const binding = traceBinding(left, left.node.name);
213
+ if (binding) {
214
+ uniqueBindings.add(binding);
215
+ exportedBindings.set(left.node.name, binding);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ },
221
+ });
222
+ // generate ids for each unique binding
223
+ const sourceIDs = new Map();
224
+ for (const binding of uniqueBindings) {
225
+ if (isPathValid(binding.path, t.isVariableDeclarator)) {
226
+ const init = unwrapPath(binding.path.get("init"), isValidFunction);
227
+ if (init) {
228
+ sourceIDs.set(binding, createID(ctx, getDescriptiveName(init, "anonymous")));
229
+ }
230
+ }
231
+ }
232
+ // clear body
233
+ program.node.body = [];
234
+ const declarations = [];
235
+ const specifiers = [];
236
+ const declarationMap = new Map();
237
+ // Declare all client functions
238
+ for (const [exported, binding] of exportedBindings) {
239
+ let currentIdentifier = declarationMap.get(binding);
240
+ if (!currentIdentifier) {
241
+ currentIdentifier = generateUniqueName(program, "fn");
242
+ const fnID = sourceIDs.get(binding);
243
+ if (fnID) {
244
+ declarations.push(t.variableDeclarator(currentIdentifier, t.callExpression(getImportIdentifier(ctx.imports, program, ctx.definitions.clone), [
245
+ t.stringLiteral(fnID),
246
+ ])));
247
+ declarationMap.set(binding, currentIdentifier);
248
+ }
249
+ }
250
+ if (currentIdentifier) {
251
+ specifiers.push(t.exportSpecifier(currentIdentifier, t.stringLiteral(exported)));
252
+ }
253
+ }
254
+ const body = [];
255
+ if (declarations.length > 0) {
256
+ body.push(t.variableDeclaration("const", declarations));
257
+ }
258
+ if (specifiers.length > 0) {
259
+ body.push(t.exportNamedDeclaration(null, specifiers, null));
260
+ }
261
+ program.pushContainer("body", body);
262
+ }
263
+ }
264
+ export function directivesPlugin() {
265
+ return {
266
+ name: "solid-start:directives",
267
+ visitor: {
268
+ Program(program, ctx) {
269
+ const isModuleLevel = isDirectiveValid(ctx.opts, program.node.directives);
270
+ if (isModuleLevel) {
271
+ transformModuleLevelDirective(ctx.opts, program);
272
+ ctx.opts.valid = true;
273
+ }
274
+ else {
275
+ // First, bubble up function declarations
276
+ program.traverse({
277
+ FunctionDeclaration(child) {
278
+ // if (isFunctionDirectiveValid(ctx.opts, child)) {
279
+ bubbleFunctionDeclaration(child);
280
+ // }
281
+ },
282
+ });
283
+ program.scope.crawl();
284
+ // Now we transform each function
285
+ program.traverse({
286
+ ArrowFunctionExpression(path) {
287
+ transformFunction(ctx.opts, path, false);
288
+ },
289
+ FunctionExpression(path) {
290
+ transformFunction(ctx.opts, path, false);
291
+ },
292
+ });
293
+ program.scope.crawl();
294
+ if (ctx.opts.count > 0) {
295
+ ctx.opts.valid = true;
296
+ removeUnusedVariables(program);
297
+ }
298
+ }
299
+ },
300
+ },
301
+ };
302
+ }
@@ -0,0 +1,3 @@
1
+ import type * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ export declare function removeUnusedVariables(program: babel.NodePath<t.Program>): void;
@@ -0,0 +1,66 @@
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
+ }
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,6 @@
1
+ /**
2
+ *
3
+ * @param buffer - byte array or string
4
+ * @param seed - optional seed (32-bit unsigned);
5
+ */
6
+ export default function xxHash32(buffer: Uint8Array | string, seed?: number): number;
@@ -0,0 +1,193 @@
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
+ }
@@ -1,3 +1,3 @@
1
1
  import { type Component } from "solid-js";
2
- export declare function createServerReference(id: string): (...args: any[]) => Promise<any>;
2
+ export declare function cloneServerReference(id: string): (...args: any[]) => Promise<unknown>;
3
3
  export declare function createClientReference(Component: Component<any>, id: string): Component<any>;