@sveltejs/kit 1.0.0-next.21 → 1.0.0-next.210

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