@sveltejs/kit 1.0.0-next.32 → 1.0.0-next.322

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 (72) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1687 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/paths.js +13 -0
  11. package/assets/server/index.js +3413 -0
  12. package/dist/chunks/amp_hook.js +56 -0
  13. package/dist/chunks/cert.js +28154 -0
  14. package/dist/chunks/constants.js +663 -0
  15. package/dist/chunks/filesystem.js +110 -0
  16. package/dist/chunks/index.js +514 -0
  17. package/dist/chunks/index2.js +1334 -0
  18. package/dist/chunks/index3.js +118 -0
  19. package/dist/chunks/index4.js +182 -0
  20. package/dist/chunks/index5.js +240 -0
  21. package/dist/chunks/index6.js +15737 -0
  22. package/dist/chunks/index7.js +4207 -0
  23. package/dist/chunks/misc.js +78 -0
  24. package/dist/chunks/multipart-parser.js +449 -0
  25. package/dist/chunks/sync.js +978 -0
  26. package/dist/chunks/url.js +138 -0
  27. package/dist/cli.js +1024 -65
  28. package/dist/hooks.js +28 -0
  29. package/dist/install-fetch.js +6518 -0
  30. package/dist/node.js +94 -0
  31. package/package.json +95 -62
  32. package/svelte-kit.js +0 -1
  33. package/types/ambient.d.ts +298 -0
  34. package/types/index.d.ts +278 -0
  35. package/types/internal.d.ts +320 -0
  36. package/types/private.d.ts +242 -0
  37. package/CHANGELOG.md +0 -350
  38. package/assets/runtime/app/navigation.js +0 -23
  39. package/assets/runtime/app/navigation.js.map +0 -1
  40. package/assets/runtime/app/paths.js +0 -2
  41. package/assets/runtime/app/paths.js.map +0 -1
  42. package/assets/runtime/app/stores.js +0 -78
  43. package/assets/runtime/app/stores.js.map +0 -1
  44. package/assets/runtime/internal/singletons.js +0 -15
  45. package/assets/runtime/internal/singletons.js.map +0 -1
  46. package/assets/runtime/internal/start.js +0 -591
  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 -32
  51. package/dist/api.js.map +0 -1
  52. package/dist/cli.js.map +0 -1
  53. package/dist/create_app.js +0 -577
  54. package/dist/create_app.js.map +0 -1
  55. package/dist/index.js +0 -329
  56. package/dist/index.js.map +0 -1
  57. package/dist/index2.js +0 -14363
  58. package/dist/index2.js.map +0 -1
  59. package/dist/index3.js +0 -544
  60. package/dist/index3.js.map +0 -1
  61. package/dist/index4.js +0 -71
  62. package/dist/index4.js.map +0 -1
  63. package/dist/index5.js +0 -465
  64. package/dist/index5.js.map +0 -1
  65. package/dist/index6.js +0 -727
  66. package/dist/index6.js.map +0 -1
  67. package/dist/renderer.js +0 -2413
  68. package/dist/renderer.js.map +0 -1
  69. package/dist/standard.js +0 -100
  70. package/dist/standard.js.map +0 -1
  71. package/dist/utils.js +0 -57
  72. package/dist/utils.js.map +0 -1
@@ -0,0 +1,78 @@
1
+ const param_pattern = /^(\.\.\.)?(\w+)(?:=(\w+))?$/;
2
+
3
+ /** @param {string} id */
4
+ function parse_route_id(id) {
5
+ /** @type {string[]} */
6
+ const names = [];
7
+
8
+ /** @type {string[]} */
9
+ const types = [];
10
+
11
+ // `/foo` should get an optional trailing slash, `/foo.json` should not
12
+ // const add_trailing_slash = !/\.[a-z]+$/.test(key);
13
+ let add_trailing_slash = true;
14
+
15
+ const pattern =
16
+ id === ''
17
+ ? /^\/$/
18
+ : new RegExp(
19
+ `^${decodeURIComponent(id)
20
+ .split(/(?:@[a-zA-Z0-9_-]+)?(?:\/|$)/)
21
+ .map((segment, i, segments) => {
22
+ // special case — /[...rest]/ could contain zero segments
23
+ const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
24
+ if (match) {
25
+ names.push(match[1]);
26
+ types.push(match[2]);
27
+ return '(?:/(.*))?';
28
+ }
29
+
30
+ const is_last = i === segments.length - 1;
31
+
32
+ return (
33
+ segment &&
34
+ '/' +
35
+ segment
36
+ .split(/\[(.+?)\]/)
37
+ .map((content, i) => {
38
+ if (i % 2) {
39
+ const [, rest, name, type] = /** @type {RegExpMatchArray} */ (
40
+ param_pattern.exec(content)
41
+ );
42
+ names.push(name);
43
+ types.push(type);
44
+ return rest ? '(.*?)' : '([^/]+?)';
45
+ }
46
+
47
+ if (is_last && content.includes('.')) add_trailing_slash = false;
48
+
49
+ return (
50
+ content // allow users to specify characters on the file system in an encoded manner
51
+ .normalize()
52
+ // We use [ and ] to denote parameters, so users must encode these on the file
53
+ // system to match against them. We don't decode all characters since others
54
+ // can already be epressed and so that '%' can be easily used directly in filenames
55
+ .replace(/%5[Bb]/g, '[')
56
+ .replace(/%5[Dd]/g, ']')
57
+ // '#', '/', and '?' can only appear in URL path segments in an encoded manner.
58
+ // They will not be touched by decodeURI so need to be encoded here, so
59
+ // that we can match against them.
60
+ // We skip '/' since you can't create a file with it on any OS
61
+ .replace(/#/g, '%23')
62
+ .replace(/\?/g, '%3F')
63
+ // escape characters that have special meaning in regex
64
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
65
+ ); // TODO handle encoding
66
+ })
67
+ .join('')
68
+ );
69
+ })
70
+ .join('')}${add_trailing_slash ? '/?' : ''}$`
71
+ );
72
+
73
+ return { pattern, names, types };
74
+ }
75
+
76
+ const s = JSON.stringify;
77
+
78
+ export { parse_route_id as p, 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 };