@sveltejs/kit 1.0.0-next.38 → 1.0.0-next.382

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 (42) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +28 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/{runtime/app → app}/stores.js +33 -29
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1803 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/{runtime/chunks/paths.js → paths.js} +4 -3
  11. package/assets/server/index.js +3563 -0
  12. package/dist/chunks/_commonjsHelpers.js +3 -0
  13. package/dist/chunks/error.js +664 -0
  14. package/dist/chunks/index.js +15292 -3067
  15. package/dist/chunks/index2.js +186 -555
  16. package/dist/chunks/multipart-parser.js +445 -0
  17. package/dist/chunks/sync.js +1007 -0
  18. package/dist/chunks/write_tsconfig.js +274 -0
  19. package/dist/cli.js +66 -514
  20. package/dist/hooks.js +28 -0
  21. package/dist/node/polyfills.js +12240 -0
  22. package/dist/node.js +5893 -0
  23. package/dist/vite.js +3243 -0
  24. package/package.json +97 -64
  25. package/types/ambient.d.ts +345 -0
  26. package/types/index.d.ts +289 -0
  27. package/types/internal.d.ts +326 -0
  28. package/types/private.d.ts +235 -0
  29. package/CHANGELOG.md +0 -399
  30. package/assets/runtime/app/env.js +0 -5
  31. package/assets/runtime/app/navigation.js +0 -41
  32. package/assets/runtime/app/paths.js +0 -1
  33. package/assets/runtime/chunks/utils.js +0 -19
  34. package/assets/runtime/internal/singletons.js +0 -23
  35. package/assets/runtime/internal/start.js +0 -770
  36. package/dist/chunks/index3.js +0 -246
  37. package/dist/chunks/index4.js +0 -511
  38. package/dist/chunks/index5.js +0 -761
  39. package/dist/chunks/index6.js +0 -322
  40. package/dist/chunks/standard.js +0 -99
  41. package/dist/chunks/utils.js +0 -83
  42. package/dist/ssr.js +0 -2523
@@ -0,0 +1,445 @@
1
+ import 'node:fs';
2
+ import 'node:path';
3
+ import { F as FormData, a as File } from '../node.js';
4
+ import 'node:http';
5
+ import 'node:https';
6
+ import 'node:zlib';
7
+ import 'node:stream';
8
+ import 'node:buffer';
9
+ import 'node:util';
10
+ import './_commonjsHelpers.js';
11
+ import 'node:url';
12
+ import 'node:net';
13
+ import 'stream';
14
+
15
+ let s = 0;
16
+ const S = {
17
+ START_BOUNDARY: s++,
18
+ HEADER_FIELD_START: s++,
19
+ HEADER_FIELD: s++,
20
+ HEADER_VALUE_START: s++,
21
+ HEADER_VALUE: s++,
22
+ HEADER_VALUE_ALMOST_DONE: s++,
23
+ HEADERS_ALMOST_DONE: s++,
24
+ PART_DATA_START: s++,
25
+ PART_DATA: s++,
26
+ END: s++
27
+ };
28
+
29
+ let f = 1;
30
+ const F = {
31
+ PART_BOUNDARY: f,
32
+ LAST_BOUNDARY: f *= 2
33
+ };
34
+
35
+ const LF = 10;
36
+ const CR = 13;
37
+ const SPACE = 32;
38
+ const HYPHEN = 45;
39
+ const COLON = 58;
40
+ const A = 97;
41
+ const Z = 122;
42
+
43
+ const lower = c => c | 0x20;
44
+
45
+ const noop = () => {};
46
+
47
+ class MultipartParser {
48
+ /**
49
+ * @param {string} boundary
50
+ */
51
+ constructor(boundary) {
52
+ this.index = 0;
53
+ this.flags = 0;
54
+
55
+ this.onHeaderEnd = noop;
56
+ this.onHeaderField = noop;
57
+ this.onHeadersEnd = noop;
58
+ this.onHeaderValue = noop;
59
+ this.onPartBegin = noop;
60
+ this.onPartData = noop;
61
+ this.onPartEnd = noop;
62
+
63
+ this.boundaryChars = {};
64
+
65
+ boundary = '\r\n--' + boundary;
66
+ const ui8a = new Uint8Array(boundary.length);
67
+ for (let i = 0; i < boundary.length; i++) {
68
+ ui8a[i] = boundary.charCodeAt(i);
69
+ this.boundaryChars[ui8a[i]] = true;
70
+ }
71
+
72
+ this.boundary = ui8a;
73
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
74
+ this.state = S.START_BOUNDARY;
75
+ }
76
+
77
+ /**
78
+ * @param {Uint8Array} data
79
+ */
80
+ write(data) {
81
+ let i = 0;
82
+ const length_ = data.length;
83
+ let previousIndex = this.index;
84
+ let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
85
+ const boundaryLength = this.boundary.length;
86
+ const boundaryEnd = boundaryLength - 1;
87
+ const bufferLength = data.length;
88
+ let c;
89
+ let cl;
90
+
91
+ const mark = name => {
92
+ this[name + 'Mark'] = i;
93
+ };
94
+
95
+ const clear = name => {
96
+ delete this[name + 'Mark'];
97
+ };
98
+
99
+ const callback = (callbackSymbol, start, end, ui8a) => {
100
+ if (start === undefined || start !== end) {
101
+ this[callbackSymbol](ui8a && ui8a.subarray(start, end));
102
+ }
103
+ };
104
+
105
+ const dataCallback = (name, clear) => {
106
+ const markSymbol = name + 'Mark';
107
+ if (!(markSymbol in this)) {
108
+ return;
109
+ }
110
+
111
+ if (clear) {
112
+ callback(name, this[markSymbol], i, data);
113
+ delete this[markSymbol];
114
+ } else {
115
+ callback(name, this[markSymbol], data.length, data);
116
+ this[markSymbol] = 0;
117
+ }
118
+ };
119
+
120
+ for (i = 0; i < length_; i++) {
121
+ c = data[i];
122
+
123
+ switch (state) {
124
+ case S.START_BOUNDARY:
125
+ if (index === boundary.length - 2) {
126
+ if (c === HYPHEN) {
127
+ flags |= F.LAST_BOUNDARY;
128
+ } else if (c !== CR) {
129
+ return;
130
+ }
131
+
132
+ index++;
133
+ break;
134
+ } else if (index - 1 === boundary.length - 2) {
135
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
136
+ state = S.END;
137
+ flags = 0;
138
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
139
+ index = 0;
140
+ callback('onPartBegin');
141
+ state = S.HEADER_FIELD_START;
142
+ } else {
143
+ return;
144
+ }
145
+
146
+ break;
147
+ }
148
+
149
+ if (c !== boundary[index + 2]) {
150
+ index = -2;
151
+ }
152
+
153
+ if (c === boundary[index + 2]) {
154
+ index++;
155
+ }
156
+
157
+ break;
158
+ case S.HEADER_FIELD_START:
159
+ state = S.HEADER_FIELD;
160
+ mark('onHeaderField');
161
+ index = 0;
162
+ // falls through
163
+ case S.HEADER_FIELD:
164
+ if (c === CR) {
165
+ clear('onHeaderField');
166
+ state = S.HEADERS_ALMOST_DONE;
167
+ break;
168
+ }
169
+
170
+ index++;
171
+ if (c === HYPHEN) {
172
+ break;
173
+ }
174
+
175
+ if (c === COLON) {
176
+ if (index === 1) {
177
+ // empty header field
178
+ return;
179
+ }
180
+
181
+ dataCallback('onHeaderField', true);
182
+ state = S.HEADER_VALUE_START;
183
+ break;
184
+ }
185
+
186
+ cl = lower(c);
187
+ if (cl < A || cl > Z) {
188
+ return;
189
+ }
190
+
191
+ break;
192
+ case S.HEADER_VALUE_START:
193
+ if (c === SPACE) {
194
+ break;
195
+ }
196
+
197
+ mark('onHeaderValue');
198
+ state = S.HEADER_VALUE;
199
+ // falls through
200
+ case S.HEADER_VALUE:
201
+ if (c === CR) {
202
+ dataCallback('onHeaderValue', true);
203
+ callback('onHeaderEnd');
204
+ state = S.HEADER_VALUE_ALMOST_DONE;
205
+ }
206
+
207
+ break;
208
+ case S.HEADER_VALUE_ALMOST_DONE:
209
+ if (c !== LF) {
210
+ return;
211
+ }
212
+
213
+ state = S.HEADER_FIELD_START;
214
+ break;
215
+ case S.HEADERS_ALMOST_DONE:
216
+ if (c !== LF) {
217
+ return;
218
+ }
219
+
220
+ callback('onHeadersEnd');
221
+ state = S.PART_DATA_START;
222
+ break;
223
+ case S.PART_DATA_START:
224
+ state = S.PART_DATA;
225
+ mark('onPartData');
226
+ // falls through
227
+ case S.PART_DATA:
228
+ previousIndex = index;
229
+
230
+ if (index === 0) {
231
+ // boyer-moore derrived algorithm to safely skip non-boundary data
232
+ i += boundaryEnd;
233
+ while (i < bufferLength && !(data[i] in boundaryChars)) {
234
+ i += boundaryLength;
235
+ }
236
+
237
+ i -= boundaryEnd;
238
+ c = data[i];
239
+ }
240
+
241
+ if (index < boundary.length) {
242
+ if (boundary[index] === c) {
243
+ if (index === 0) {
244
+ dataCallback('onPartData', true);
245
+ }
246
+
247
+ index++;
248
+ } else {
249
+ index = 0;
250
+ }
251
+ } else if (index === boundary.length) {
252
+ index++;
253
+ if (c === CR) {
254
+ // CR = part boundary
255
+ flags |= F.PART_BOUNDARY;
256
+ } else if (c === HYPHEN) {
257
+ // HYPHEN = end boundary
258
+ flags |= F.LAST_BOUNDARY;
259
+ } else {
260
+ index = 0;
261
+ }
262
+ } else if (index - 1 === boundary.length) {
263
+ if (flags & F.PART_BOUNDARY) {
264
+ index = 0;
265
+ if (c === LF) {
266
+ // unset the PART_BOUNDARY flag
267
+ flags &= ~F.PART_BOUNDARY;
268
+ callback('onPartEnd');
269
+ callback('onPartBegin');
270
+ state = S.HEADER_FIELD_START;
271
+ break;
272
+ }
273
+ } else if (flags & F.LAST_BOUNDARY) {
274
+ if (c === HYPHEN) {
275
+ callback('onPartEnd');
276
+ state = S.END;
277
+ flags = 0;
278
+ } else {
279
+ index = 0;
280
+ }
281
+ } else {
282
+ index = 0;
283
+ }
284
+ }
285
+
286
+ if (index > 0) {
287
+ // when matching a possible boundary, keep a lookbehind reference
288
+ // in case it turns out to be a false lead
289
+ lookbehind[index - 1] = c;
290
+ } else if (previousIndex > 0) {
291
+ // if our boundary turned out to be rubbish, the captured lookbehind
292
+ // belongs to partData
293
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
294
+ callback('onPartData', 0, previousIndex, _lookbehind);
295
+ previousIndex = 0;
296
+ mark('onPartData');
297
+
298
+ // reconsider the current character even so it interrupted the sequence
299
+ // it could be the beginning of a new sequence
300
+ i--;
301
+ }
302
+
303
+ break;
304
+ case S.END:
305
+ break;
306
+ default:
307
+ throw new Error(`Unexpected state entered: ${state}`);
308
+ }
309
+ }
310
+
311
+ dataCallback('onHeaderField');
312
+ dataCallback('onHeaderValue');
313
+ dataCallback('onPartData');
314
+
315
+ // Update properties for the next call
316
+ this.index = index;
317
+ this.state = state;
318
+ this.flags = flags;
319
+ }
320
+
321
+ end() {
322
+ if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
323
+ (this.state === S.PART_DATA && this.index === this.boundary.length)) {
324
+ this.onPartEnd();
325
+ } else if (this.state !== S.END) {
326
+ throw new Error('MultipartParser.end(): stream ended unexpectedly');
327
+ }
328
+ }
329
+ }
330
+
331
+ function _fileName(headerValue) {
332
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
333
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
334
+ if (!m) {
335
+ return;
336
+ }
337
+
338
+ const match = m[2] || m[3] || '';
339
+ let filename = match.slice(match.lastIndexOf('\\') + 1);
340
+ filename = filename.replace(/%22/g, '"');
341
+ filename = filename.replace(/&#(\d{4});/g, (m, code) => {
342
+ return String.fromCharCode(code);
343
+ });
344
+ return filename;
345
+ }
346
+
347
+ async function toFormData(Body, ct) {
348
+ if (!/multipart/i.test(ct)) {
349
+ throw new TypeError('Failed to fetch');
350
+ }
351
+
352
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
353
+
354
+ if (!m) {
355
+ throw new TypeError('no or bad content-type header, no multipart boundary');
356
+ }
357
+
358
+ const parser = new MultipartParser(m[1] || m[2]);
359
+
360
+ let headerField;
361
+ let headerValue;
362
+ let entryValue;
363
+ let entryName;
364
+ let contentType;
365
+ let filename;
366
+ const entryChunks = [];
367
+ const formData = new FormData();
368
+
369
+ const onPartData = ui8a => {
370
+ entryValue += decoder.decode(ui8a, {stream: true});
371
+ };
372
+
373
+ const appendToFile = ui8a => {
374
+ entryChunks.push(ui8a);
375
+ };
376
+
377
+ const appendFileToFormData = () => {
378
+ const file = new File(entryChunks, filename, {type: contentType});
379
+ formData.append(entryName, file);
380
+ };
381
+
382
+ const appendEntryToFormData = () => {
383
+ formData.append(entryName, entryValue);
384
+ };
385
+
386
+ const decoder = new TextDecoder('utf-8');
387
+ decoder.decode();
388
+
389
+ parser.onPartBegin = function () {
390
+ parser.onPartData = onPartData;
391
+ parser.onPartEnd = appendEntryToFormData;
392
+
393
+ headerField = '';
394
+ headerValue = '';
395
+ entryValue = '';
396
+ entryName = '';
397
+ contentType = '';
398
+ filename = null;
399
+ entryChunks.length = 0;
400
+ };
401
+
402
+ parser.onHeaderField = function (ui8a) {
403
+ headerField += decoder.decode(ui8a, {stream: true});
404
+ };
405
+
406
+ parser.onHeaderValue = function (ui8a) {
407
+ headerValue += decoder.decode(ui8a, {stream: true});
408
+ };
409
+
410
+ parser.onHeaderEnd = function () {
411
+ headerValue += decoder.decode();
412
+ headerField = headerField.toLowerCase();
413
+
414
+ if (headerField === 'content-disposition') {
415
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
416
+ const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
417
+
418
+ if (m) {
419
+ entryName = m[2] || m[3] || '';
420
+ }
421
+
422
+ filename = _fileName(headerValue);
423
+
424
+ if (filename) {
425
+ parser.onPartData = appendToFile;
426
+ parser.onPartEnd = appendFileToFormData;
427
+ }
428
+ } else if (headerField === 'content-type') {
429
+ contentType = headerValue;
430
+ }
431
+
432
+ headerValue = '';
433
+ headerField = '';
434
+ };
435
+
436
+ for await (const chunk of Body) {
437
+ parser.write(chunk);
438
+ }
439
+
440
+ parser.end();
441
+
442
+ return formData;
443
+ }
444
+
445
+ export { toFormData };