@sveltejs/kit 1.0.0-next.2 → 1.0.0-next.202

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 (65) hide show
  1. package/README.md +12 -9
  2. package/assets/components/error.svelte +19 -3
  3. package/assets/runtime/app/env.js +20 -0
  4. package/assets/runtime/app/navigation.js +42 -34
  5. package/assets/runtime/app/paths.js +1 -0
  6. package/assets/runtime/app/stores.js +15 -9
  7. package/assets/runtime/chunks/utils.js +13 -0
  8. package/assets/runtime/env.js +8 -0
  9. package/assets/runtime/internal/singletons.js +5 -6
  10. package/assets/runtime/internal/start.js +1020 -320
  11. package/assets/runtime/paths.js +13 -0
  12. package/dist/chunks/cert.js +29255 -0
  13. package/dist/chunks/constants.js +8 -0
  14. package/dist/chunks/error.js +21 -0
  15. package/dist/chunks/index.js +4746 -0
  16. package/dist/chunks/index2.js +797 -0
  17. package/dist/chunks/index3.js +1042 -0
  18. package/dist/chunks/index4.js +398 -0
  19. package/dist/chunks/index5.js +827 -0
  20. package/dist/chunks/index6.js +15575 -0
  21. package/dist/chunks/multipart-parser.js +449 -0
  22. package/dist/chunks/url.js +62 -0
  23. package/dist/cli.js +958 -59
  24. package/dist/hooks.js +28 -0
  25. package/dist/install-fetch.js +6514 -0
  26. package/dist/node.js +51 -0
  27. package/dist/ssr.js +1771 -0
  28. package/package.json +90 -52
  29. package/svelte-kit.js +2 -0
  30. package/types/ambient-modules.d.ts +173 -0
  31. package/types/app.d.ts +21 -0
  32. package/types/config.d.ts +96 -0
  33. package/types/endpoint.d.ts +18 -0
  34. package/types/helper.d.ts +41 -0
  35. package/types/hooks.d.ts +36 -0
  36. package/types/index.d.ts +17 -0
  37. package/types/internal.d.ts +219 -0
  38. package/types/page.d.ts +77 -0
  39. package/CHANGELOG.md +0 -159
  40. package/assets/renderer/index.js +0 -2492
  41. package/assets/renderer/index.js.map +0 -1
  42. package/assets/runtime/app/navigation.js.map +0 -1
  43. package/assets/runtime/app/stores.js.map +0 -1
  44. package/assets/runtime/internal/singletons.js.map +0 -1
  45. package/assets/runtime/internal/start.js.map +0 -1
  46. package/dist/api.js +0 -38
  47. package/dist/api.js.map +0 -1
  48. package/dist/cli.js.map +0 -1
  49. package/dist/create_app.js +0 -550
  50. package/dist/create_app.js.map +0 -1
  51. package/dist/index.js +0 -10708
  52. package/dist/index.js.map +0 -1
  53. package/dist/index2.js +0 -506
  54. package/dist/index2.js.map +0 -1
  55. package/dist/index3.js +0 -62
  56. package/dist/index3.js.map +0 -1
  57. package/dist/index4.js +0 -563
  58. package/dist/index4.js.map +0 -1
  59. package/dist/index5.js +0 -276
  60. package/dist/index5.js.map +0 -1
  61. package/dist/package.js +0 -235
  62. package/dist/package.js.map +0 -1
  63. package/dist/utils.js +0 -58
  64. package/dist/utils.js.map +0 -1
  65. package/svelte-kit +0 -3
@@ -1,2492 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var crypto = require('crypto');
6
- var fs = require('fs');
7
- var Stream = require('stream');
8
- var http = require('http');
9
- var Url = require('url');
10
- var https = require('https');
11
- var zlib = require('zlib');
12
-
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var Stream__default = /*#__PURE__*/_interopDefaultLegacy(Stream);
16
- var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
17
- var Url__default = /*#__PURE__*/_interopDefaultLegacy(Url);
18
- var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
19
- var zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
20
-
21
- var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
22
- var unsafeChars = /[<>\b\f\n\r\t\0\u2028\u2029]/g;
23
- var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
24
- var escaped = {
25
- '<': '\\u003C',
26
- '>': '\\u003E',
27
- '/': '\\u002F',
28
- '\\': '\\\\',
29
- '\b': '\\b',
30
- '\f': '\\f',
31
- '\n': '\\n',
32
- '\r': '\\r',
33
- '\t': '\\t',
34
- '\0': '\\0',
35
- '\u2028': '\\u2028',
36
- '\u2029': '\\u2029'
37
- };
38
- var objectProtoOwnPropertyNames = Object.getOwnPropertyNames(Object.prototype).sort().join('\0');
39
- function devalue(value) {
40
- var counts = new Map();
41
- function walk(thing) {
42
- if (typeof thing === 'function') {
43
- throw new Error("Cannot stringify a function");
44
- }
45
- if (counts.has(thing)) {
46
- counts.set(thing, counts.get(thing) + 1);
47
- return;
48
- }
49
- counts.set(thing, 1);
50
- if (!isPrimitive(thing)) {
51
- var type = getType(thing);
52
- switch (type) {
53
- case 'Number':
54
- case 'String':
55
- case 'Boolean':
56
- case 'Date':
57
- case 'RegExp':
58
- return;
59
- case 'Array':
60
- thing.forEach(walk);
61
- break;
62
- case 'Set':
63
- case 'Map':
64
- Array.from(thing).forEach(walk);
65
- break;
66
- default:
67
- var proto = Object.getPrototypeOf(thing);
68
- if (proto !== Object.prototype &&
69
- proto !== null &&
70
- Object.getOwnPropertyNames(proto).sort().join('\0') !== objectProtoOwnPropertyNames) {
71
- throw new Error("Cannot stringify arbitrary non-POJOs");
72
- }
73
- if (Object.getOwnPropertySymbols(thing).length > 0) {
74
- throw new Error("Cannot stringify POJOs with symbolic keys");
75
- }
76
- Object.keys(thing).forEach(function (key) { return walk(thing[key]); });
77
- }
78
- }
79
- }
80
- walk(value);
81
- var names = new Map();
82
- Array.from(counts)
83
- .filter(function (entry) { return entry[1] > 1; })
84
- .sort(function (a, b) { return b[1] - a[1]; })
85
- .forEach(function (entry, i) {
86
- names.set(entry[0], getName(i));
87
- });
88
- function stringify(thing) {
89
- if (names.has(thing)) {
90
- return names.get(thing);
91
- }
92
- if (isPrimitive(thing)) {
93
- return stringifyPrimitive(thing);
94
- }
95
- var type = getType(thing);
96
- switch (type) {
97
- case 'Number':
98
- case 'String':
99
- case 'Boolean':
100
- return "Object(" + stringify(thing.valueOf()) + ")";
101
- case 'RegExp':
102
- return "new RegExp(" + stringifyString(thing.source) + ", \"" + thing.flags + "\")";
103
- case 'Date':
104
- return "new Date(" + thing.getTime() + ")";
105
- case 'Array':
106
- var members = thing.map(function (v, i) { return i in thing ? stringify(v) : ''; });
107
- var tail = thing.length === 0 || (thing.length - 1 in thing) ? '' : ',';
108
- return "[" + members.join(',') + tail + "]";
109
- case 'Set':
110
- case 'Map':
111
- return "new " + type + "([" + Array.from(thing).map(stringify).join(',') + "])";
112
- default:
113
- var obj = "{" + Object.keys(thing).map(function (key) { return safeKey(key) + ":" + stringify(thing[key]); }).join(',') + "}";
114
- var proto = Object.getPrototypeOf(thing);
115
- if (proto === null) {
116
- return Object.keys(thing).length > 0
117
- ? "Object.assign(Object.create(null)," + obj + ")"
118
- : "Object.create(null)";
119
- }
120
- return obj;
121
- }
122
- }
123
- var str = stringify(value);
124
- if (names.size) {
125
- var params_1 = [];
126
- var statements_1 = [];
127
- var values_1 = [];
128
- names.forEach(function (name, thing) {
129
- params_1.push(name);
130
- if (isPrimitive(thing)) {
131
- values_1.push(stringifyPrimitive(thing));
132
- return;
133
- }
134
- var type = getType(thing);
135
- switch (type) {
136
- case 'Number':
137
- case 'String':
138
- case 'Boolean':
139
- values_1.push("Object(" + stringify(thing.valueOf()) + ")");
140
- break;
141
- case 'RegExp':
142
- values_1.push(thing.toString());
143
- break;
144
- case 'Date':
145
- values_1.push("new Date(" + thing.getTime() + ")");
146
- break;
147
- case 'Array':
148
- values_1.push("Array(" + thing.length + ")");
149
- thing.forEach(function (v, i) {
150
- statements_1.push(name + "[" + i + "]=" + stringify(v));
151
- });
152
- break;
153
- case 'Set':
154
- values_1.push("new Set");
155
- statements_1.push(name + "." + Array.from(thing).map(function (v) { return "add(" + stringify(v) + ")"; }).join('.'));
156
- break;
157
- case 'Map':
158
- values_1.push("new Map");
159
- statements_1.push(name + "." + Array.from(thing).map(function (_a) {
160
- var k = _a[0], v = _a[1];
161
- return "set(" + stringify(k) + ", " + stringify(v) + ")";
162
- }).join('.'));
163
- break;
164
- default:
165
- values_1.push(Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}');
166
- Object.keys(thing).forEach(function (key) {
167
- statements_1.push("" + name + safeProp(key) + "=" + stringify(thing[key]));
168
- });
169
- }
170
- });
171
- statements_1.push("return " + str);
172
- return "(function(" + params_1.join(',') + "){" + statements_1.join(';') + "}(" + values_1.join(',') + "))";
173
- }
174
- else {
175
- return str;
176
- }
177
- }
178
- function getName(num) {
179
- var name = '';
180
- do {
181
- name = chars[num % chars.length] + name;
182
- num = ~~(num / chars.length) - 1;
183
- } while (num >= 0);
184
- return reserved.test(name) ? name + "_" : name;
185
- }
186
- function isPrimitive(thing) {
187
- return Object(thing) !== thing;
188
- }
189
- function stringifyPrimitive(thing) {
190
- if (typeof thing === 'string')
191
- return stringifyString(thing);
192
- if (thing === void 0)
193
- return 'void 0';
194
- if (thing === 0 && 1 / thing < 0)
195
- return '-0';
196
- var str = String(thing);
197
- if (typeof thing === 'number')
198
- return str.replace(/^(-)?0\./, '$1.');
199
- return str;
200
- }
201
- function getType(thing) {
202
- return Object.prototype.toString.call(thing).slice(8, -1);
203
- }
204
- function escapeUnsafeChar(c) {
205
- return escaped[c] || c;
206
- }
207
- function escapeUnsafeChars(str) {
208
- return str.replace(unsafeChars, escapeUnsafeChar);
209
- }
210
- function safeKey(key) {
211
- return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escapeUnsafeChars(JSON.stringify(key));
212
- }
213
- function safeProp(key) {
214
- return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? "." + key : "[" + escapeUnsafeChars(JSON.stringify(key)) + "]";
215
- }
216
- function stringifyString(str) {
217
- var result = '"';
218
- for (var i = 0; i < str.length; i += 1) {
219
- var char = str.charAt(i);
220
- var code = char.charCodeAt(0);
221
- if (char === '"') {
222
- result += '\\"';
223
- }
224
- else if (char in escaped) {
225
- result += escaped[char];
226
- }
227
- else if (code >= 0xd800 && code <= 0xdfff) {
228
- var next = str.charCodeAt(i + 1);
229
- // If this is the beginning of a [high, low] surrogate pair,
230
- // add the next two characters, otherwise escape
231
- if (code <= 0xdbff && (next >= 0xdc00 && next <= 0xdfff)) {
232
- result += char + str[++i];
233
- }
234
- else {
235
- result += "\\u" + code.toString(16).toUpperCase();
236
- }
237
- }
238
- else {
239
- result += char;
240
- }
241
- }
242
- result += '"';
243
- return result;
244
- }
245
-
246
- /**
247
- * @param typeMap [Object] Map of MIME type -> Array[extensions]
248
- * @param ...
249
- */
250
- function Mime() {
251
- this._types = Object.create(null);
252
- this._extensions = Object.create(null);
253
-
254
- for (var i = 0; i < arguments.length; i++) {
255
- this.define(arguments[i]);
256
- }
257
-
258
- this.define = this.define.bind(this);
259
- this.getType = this.getType.bind(this);
260
- this.getExtension = this.getExtension.bind(this);
261
- }
262
-
263
- /**
264
- * Define mimetype -> extension mappings. Each key is a mime-type that maps
265
- * to an array of extensions associated with the type. The first extension is
266
- * used as the default extension for the type.
267
- *
268
- * e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
269
- *
270
- * If a type declares an extension that has already been defined, an error will
271
- * be thrown. To suppress this error and force the extension to be associated
272
- * with the new type, pass `force`=true. Alternatively, you may prefix the
273
- * extension with "*" to map the type to extension, without mapping the
274
- * extension to the type.
275
- *
276
- * e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
277
- *
278
- *
279
- * @param map (Object) type definitions
280
- * @param force (Boolean) if true, force overriding of existing definitions
281
- */
282
- Mime.prototype.define = function(typeMap, force) {
283
- for (var type in typeMap) {
284
- var extensions = typeMap[type].map(function(t) {return t.toLowerCase()});
285
- type = type.toLowerCase();
286
-
287
- for (var i = 0; i < extensions.length; i++) {
288
- var ext = extensions[i];
289
-
290
- // '*' prefix = not the preferred type for this extension. So fixup the
291
- // extension, and skip it.
292
- if (ext[0] == '*') {
293
- continue;
294
- }
295
-
296
- if (!force && (ext in this._types)) {
297
- throw new Error(
298
- 'Attempt to change mapping for "' + ext +
299
- '" extension from "' + this._types[ext] + '" to "' + type +
300
- '". Pass `force=true` to allow this, otherwise remove "' + ext +
301
- '" from the list of extensions for "' + type + '".'
302
- );
303
- }
304
-
305
- this._types[ext] = type;
306
- }
307
-
308
- // Use first extension as default
309
- if (force || !this._extensions[type]) {
310
- var ext = extensions[0];
311
- this._extensions[type] = (ext[0] != '*') ? ext : ext.substr(1);
312
- }
313
- }
314
- };
315
-
316
- /**
317
- * Lookup a mime type based on extension
318
- */
319
- Mime.prototype.getType = function(path) {
320
- path = String(path);
321
- var last = path.replace(/^.*[/\\]/, '').toLowerCase();
322
- var ext = last.replace(/^.*\./, '').toLowerCase();
323
-
324
- var hasPath = last.length < path.length;
325
- var hasDot = ext.length < last.length - 1;
326
-
327
- return (hasDot || !hasPath) && this._types[ext] || null;
328
- };
329
-
330
- /**
331
- * Return file extension associated with a mime type
332
- */
333
- Mime.prototype.getExtension = function(type) {
334
- type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
335
- return type && this._extensions[type.toLowerCase()] || null;
336
- };
337
-
338
- var Mime_1 = Mime;
339
-
340
- var standard = {"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma","es"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js","mjs"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/mrb-consumer+xml":["*xdf"],"application/mrb-publish+xml":["*xdf"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["*xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/ttml+xml":["ttml"],"application/urc-ressheet+xml":["rsheet"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-error+xml":["xer"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/adpcm":["adp"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/stl":["stl"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};
341
-
342
- var other = {"application/prs.cww":["cww"],"application/vnd.1000minds.decision-model+xml":["1km"],"application/vnd.3gpp.pic-bw-large":["plb"],"application/vnd.3gpp.pic-bw-small":["psb"],"application/vnd.3gpp.pic-bw-var":["pvb"],"application/vnd.3gpp2.tcap":["tcap"],"application/vnd.3m.post-it-notes":["pwn"],"application/vnd.accpac.simply.aso":["aso"],"application/vnd.accpac.simply.imp":["imp"],"application/vnd.acucobol":["acu"],"application/vnd.acucorp":["atc","acutc"],"application/vnd.adobe.air-application-installer-package+zip":["air"],"application/vnd.adobe.formscentral.fcdt":["fcdt"],"application/vnd.adobe.fxp":["fxp","fxpl"],"application/vnd.adobe.xdp+xml":["xdp"],"application/vnd.adobe.xfdf":["xfdf"],"application/vnd.ahead.space":["ahead"],"application/vnd.airzip.filesecure.azf":["azf"],"application/vnd.airzip.filesecure.azs":["azs"],"application/vnd.amazon.ebook":["azw"],"application/vnd.americandynamics.acc":["acc"],"application/vnd.amiga.ami":["ami"],"application/vnd.android.package-archive":["apk"],"application/vnd.anser-web-certificate-issue-initiation":["cii"],"application/vnd.anser-web-funds-transfer-initiation":["fti"],"application/vnd.antix.game-component":["atx"],"application/vnd.apple.installer+xml":["mpkg"],"application/vnd.apple.keynote":["keynote"],"application/vnd.apple.mpegurl":["m3u8"],"application/vnd.apple.numbers":["numbers"],"application/vnd.apple.pages":["pages"],"application/vnd.apple.pkpass":["pkpass"],"application/vnd.aristanetworks.swi":["swi"],"application/vnd.astraea-software.iota":["iota"],"application/vnd.audiograph":["aep"],"application/vnd.balsamiq.bmml+xml":["bmml"],"application/vnd.blueice.multipass":["mpm"],"application/vnd.bmi":["bmi"],"application/vnd.businessobjects":["rep"],"application/vnd.chemdraw+xml":["cdxml"],"application/vnd.chipnuts.karaoke-mmd":["mmd"],"application/vnd.cinderella":["cdy"],"application/vnd.citationstyles.style+xml":["csl"],"application/vnd.claymore":["cla"],"application/vnd.cloanto.rp9":["rp9"],"application/vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"application/vnd.cluetrust.cartomobile-config":["c11amc"],"application/vnd.cluetrust.cartomobile-config-pkg":["c11amz"],"application/vnd.commonspace":["csp"],"application/vnd.contact.cmsg":["cdbcmsg"],"application/vnd.cosmocaller":["cmc"],"application/vnd.crick.clicker":["clkx"],"application/vnd.crick.clicker.keyboard":["clkk"],"application/vnd.crick.clicker.palette":["clkp"],"application/vnd.crick.clicker.template":["clkt"],"application/vnd.crick.clicker.wordbank":["clkw"],"application/vnd.criticaltools.wbs+xml":["wbs"],"application/vnd.ctc-posml":["pml"],"application/vnd.cups-ppd":["ppd"],"application/vnd.curl.car":["car"],"application/vnd.curl.pcurl":["pcurl"],"application/vnd.dart":["dart"],"application/vnd.data-vision.rdz":["rdz"],"application/vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"application/vnd.dece.ttml+xml":["uvt","uvvt"],"application/vnd.dece.unspecified":["uvx","uvvx"],"application/vnd.dece.zip":["uvz","uvvz"],"application/vnd.denovo.fcselayout-link":["fe_launch"],"application/vnd.dna":["dna"],"application/vnd.dolby.mlp":["mlp"],"application/vnd.dpgraph":["dpg"],"application/vnd.dreamfactory":["dfac"],"application/vnd.ds-keypoint":["kpxx"],"application/vnd.dvb.ait":["ait"],"application/vnd.dvb.service":["svc"],"application/vnd.dynageo":["geo"],"application/vnd.ecowin.chart":["mag"],"application/vnd.enliven":["nml"],"application/vnd.epson.esf":["esf"],"application/vnd.epson.msf":["msf"],"application/vnd.epson.quickanime":["qam"],"application/vnd.epson.salt":["slt"],"application/vnd.epson.ssf":["ssf"],"application/vnd.eszigno3+xml":["es3","et3"],"application/vnd.ezpix-album":["ez2"],"application/vnd.ezpix-package":["ez3"],"application/vnd.fdf":["fdf"],"application/vnd.fdsn.mseed":["mseed"],"application/vnd.fdsn.seed":["seed","dataless"],"application/vnd.flographit":["gph"],"application/vnd.fluxtime.clip":["ftc"],"application/vnd.framemaker":["fm","frame","maker","book"],"application/vnd.frogans.fnc":["fnc"],"application/vnd.frogans.ltf":["ltf"],"application/vnd.fsc.weblaunch":["fsc"],"application/vnd.fujitsu.oasys":["oas"],"application/vnd.fujitsu.oasys2":["oa2"],"application/vnd.fujitsu.oasys3":["oa3"],"application/vnd.fujitsu.oasysgp":["fg5"],"application/vnd.fujitsu.oasysprs":["bh2"],"application/vnd.fujixerox.ddd":["ddd"],"application/vnd.fujixerox.docuworks":["xdw"],"application/vnd.fujixerox.docuworks.binder":["xbd"],"application/vnd.fuzzysheet":["fzs"],"application/vnd.genomatix.tuxedo":["txd"],"application/vnd.geogebra.file":["ggb"],"application/vnd.geogebra.tool":["ggt"],"application/vnd.geometry-explorer":["gex","gre"],"application/vnd.geonext":["gxt"],"application/vnd.geoplan":["g2w"],"application/vnd.geospace":["g3w"],"application/vnd.gmx":["gmx"],"application/vnd.google-apps.document":["gdoc"],"application/vnd.google-apps.presentation":["gslides"],"application/vnd.google-apps.spreadsheet":["gsheet"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/vnd.grafeq":["gqf","gqs"],"application/vnd.groove-account":["gac"],"application/vnd.groove-help":["ghf"],"application/vnd.groove-identity-message":["gim"],"application/vnd.groove-injector":["grv"],"application/vnd.groove-tool-message":["gtm"],"application/vnd.groove-tool-template":["tpl"],"application/vnd.groove-vcard":["vcg"],"application/vnd.hal+xml":["hal"],"application/vnd.handheld-entertainment+xml":["zmm"],"application/vnd.hbci":["hbci"],"application/vnd.hhe.lesson-player":["les"],"application/vnd.hp-hpgl":["hpgl"],"application/vnd.hp-hpid":["hpid"],"application/vnd.hp-hps":["hps"],"application/vnd.hp-jlyt":["jlt"],"application/vnd.hp-pcl":["pcl"],"application/vnd.hp-pclxl":["pclxl"],"application/vnd.hydrostatix.sof-data":["sfd-hdstx"],"application/vnd.ibm.minipay":["mpy"],"application/vnd.ibm.modcap":["afp","listafp","list3820"],"application/vnd.ibm.rights-management":["irm"],"application/vnd.ibm.secure-container":["sc"],"application/vnd.iccprofile":["icc","icm"],"application/vnd.igloader":["igl"],"application/vnd.immervision-ivp":["ivp"],"application/vnd.immervision-ivu":["ivu"],"application/vnd.insors.igm":["igm"],"application/vnd.intercon.formnet":["xpw","xpx"],"application/vnd.intergeo":["i2g"],"application/vnd.intu.qbo":["qbo"],"application/vnd.intu.qfx":["qfx"],"application/vnd.ipunplugged.rcprofile":["rcprofile"],"application/vnd.irepository.package+xml":["irp"],"application/vnd.is-xpr":["xpr"],"application/vnd.isac.fcs":["fcs"],"application/vnd.jam":["jam"],"application/vnd.jcp.javame.midlet-rms":["rms"],"application/vnd.jisp":["jisp"],"application/vnd.joost.joda-archive":["joda"],"application/vnd.kahootz":["ktz","ktr"],"application/vnd.kde.karbon":["karbon"],"application/vnd.kde.kchart":["chrt"],"application/vnd.kde.kformula":["kfo"],"application/vnd.kde.kivio":["flw"],"application/vnd.kde.kontour":["kon"],"application/vnd.kde.kpresenter":["kpr","kpt"],"application/vnd.kde.kspread":["ksp"],"application/vnd.kde.kword":["kwd","kwt"],"application/vnd.kenameaapp":["htke"],"application/vnd.kidspiration":["kia"],"application/vnd.kinar":["kne","knp"],"application/vnd.koan":["skp","skd","skt","skm"],"application/vnd.kodak-descriptor":["sse"],"application/vnd.las.las+xml":["lasxml"],"application/vnd.llamagraphics.life-balance.desktop":["lbd"],"application/vnd.llamagraphics.life-balance.exchange+xml":["lbe"],"application/vnd.lotus-1-2-3":["123"],"application/vnd.lotus-approach":["apr"],"application/vnd.lotus-freelance":["pre"],"application/vnd.lotus-notes":["nsf"],"application/vnd.lotus-organizer":["org"],"application/vnd.lotus-screencam":["scm"],"application/vnd.lotus-wordpro":["lwp"],"application/vnd.macports.portpkg":["portpkg"],"application/vnd.mcd":["mcd"],"application/vnd.medcalcdata":["mc1"],"application/vnd.mediastation.cdkey":["cdkey"],"application/vnd.mfer":["mwf"],"application/vnd.mfmp":["mfm"],"application/vnd.micrografx.flo":["flo"],"application/vnd.micrografx.igx":["igx"],"application/vnd.mif":["mif"],"application/vnd.mobius.daf":["daf"],"application/vnd.mobius.dis":["dis"],"application/vnd.mobius.mbk":["mbk"],"application/vnd.mobius.mqy":["mqy"],"application/vnd.mobius.msl":["msl"],"application/vnd.mobius.plc":["plc"],"application/vnd.mobius.txf":["txf"],"application/vnd.mophun.application":["mpn"],"application/vnd.mophun.certificate":["mpc"],"application/vnd.mozilla.xul+xml":["xul"],"application/vnd.ms-artgalry":["cil"],"application/vnd.ms-cab-compressed":["cab"],"application/vnd.ms-excel":["xls","xlm","xla","xlc","xlt","xlw"],"application/vnd.ms-excel.addin.macroenabled.12":["xlam"],"application/vnd.ms-excel.sheet.binary.macroenabled.12":["xlsb"],"application/vnd.ms-excel.sheet.macroenabled.12":["xlsm"],"application/vnd.ms-excel.template.macroenabled.12":["xltm"],"application/vnd.ms-fontobject":["eot"],"application/vnd.ms-htmlhelp":["chm"],"application/vnd.ms-ims":["ims"],"application/vnd.ms-lrm":["lrm"],"application/vnd.ms-officetheme":["thmx"],"application/vnd.ms-outlook":["msg"],"application/vnd.ms-pki.seccat":["cat"],"application/vnd.ms-pki.stl":["*stl"],"application/vnd.ms-powerpoint":["ppt","pps","pot"],"application/vnd.ms-powerpoint.addin.macroenabled.12":["ppam"],"application/vnd.ms-powerpoint.presentation.macroenabled.12":["pptm"],"application/vnd.ms-powerpoint.slide.macroenabled.12":["sldm"],"application/vnd.ms-powerpoint.slideshow.macroenabled.12":["ppsm"],"application/vnd.ms-powerpoint.template.macroenabled.12":["potm"],"application/vnd.ms-project":["mpp","mpt"],"application/vnd.ms-word.document.macroenabled.12":["docm"],"application/vnd.ms-word.template.macroenabled.12":["dotm"],"application/vnd.ms-works":["wps","wks","wcm","wdb"],"application/vnd.ms-wpl":["wpl"],"application/vnd.ms-xpsdocument":["xps"],"application/vnd.mseq":["mseq"],"application/vnd.musician":["mus"],"application/vnd.muvee.style":["msty"],"application/vnd.mynfc":["taglet"],"application/vnd.neurolanguage.nlu":["nlu"],"application/vnd.nitf":["ntf","nitf"],"application/vnd.noblenet-directory":["nnd"],"application/vnd.noblenet-sealer":["nns"],"application/vnd.noblenet-web":["nnw"],"application/vnd.nokia.n-gage.ac+xml":["*ac"],"application/vnd.nokia.n-gage.data":["ngdat"],"application/vnd.nokia.n-gage.symbian.install":["n-gage"],"application/vnd.nokia.radio-preset":["rpst"],"application/vnd.nokia.radio-presets":["rpss"],"application/vnd.novadigm.edm":["edm"],"application/vnd.novadigm.edx":["edx"],"application/vnd.novadigm.ext":["ext"],"application/vnd.oasis.opendocument.chart":["odc"],"application/vnd.oasis.opendocument.chart-template":["otc"],"application/vnd.oasis.opendocument.database":["odb"],"application/vnd.oasis.opendocument.formula":["odf"],"application/vnd.oasis.opendocument.formula-template":["odft"],"application/vnd.oasis.opendocument.graphics":["odg"],"application/vnd.oasis.opendocument.graphics-template":["otg"],"application/vnd.oasis.opendocument.image":["odi"],"application/vnd.oasis.opendocument.image-template":["oti"],"application/vnd.oasis.opendocument.presentation":["odp"],"application/vnd.oasis.opendocument.presentation-template":["otp"],"application/vnd.oasis.opendocument.spreadsheet":["ods"],"application/vnd.oasis.opendocument.spreadsheet-template":["ots"],"application/vnd.oasis.opendocument.text":["odt"],"application/vnd.oasis.opendocument.text-master":["odm"],"application/vnd.oasis.opendocument.text-template":["ott"],"application/vnd.oasis.opendocument.text-web":["oth"],"application/vnd.olpc-sugar":["xo"],"application/vnd.oma.dd2+xml":["dd2"],"application/vnd.openblox.game+xml":["obgx"],"application/vnd.openofficeorg.extension":["oxt"],"application/vnd.openstreetmap.data+xml":["osm"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":["pptx"],"application/vnd.openxmlformats-officedocument.presentationml.slide":["sldx"],"application/vnd.openxmlformats-officedocument.presentationml.slideshow":["ppsx"],"application/vnd.openxmlformats-officedocument.presentationml.template":["potx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":["xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.template":["xltx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":["docx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.template":["dotx"],"application/vnd.osgeo.mapguide.package":["mgp"],"application/vnd.osgi.dp":["dp"],"application/vnd.osgi.subsystem":["esa"],"application/vnd.palm":["pdb","pqa","oprc"],"application/vnd.pawaafile":["paw"],"application/vnd.pg.format":["str"],"application/vnd.pg.osasli":["ei6"],"application/vnd.picsel":["efif"],"application/vnd.pmi.widget":["wg"],"application/vnd.pocketlearn":["plf"],"application/vnd.powerbuilder6":["pbd"],"application/vnd.previewsystems.box":["box"],"application/vnd.proteus.magazine":["mgz"],"application/vnd.publishare-delta-tree":["qps"],"application/vnd.pvi.ptid1":["ptid"],"application/vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"application/vnd.realvnc.bed":["bed"],"application/vnd.recordare.musicxml":["mxl"],"application/vnd.recordare.musicxml+xml":["musicxml"],"application/vnd.rig.cryptonote":["cryptonote"],"application/vnd.rim.cod":["cod"],"application/vnd.rn-realmedia":["rm"],"application/vnd.rn-realmedia-vbr":["rmvb"],"application/vnd.route66.link66+xml":["link66"],"application/vnd.sailingtracker.track":["st"],"application/vnd.seemail":["see"],"application/vnd.sema":["sema"],"application/vnd.semd":["semd"],"application/vnd.semf":["semf"],"application/vnd.shana.informed.formdata":["ifm"],"application/vnd.shana.informed.formtemplate":["itp"],"application/vnd.shana.informed.interchange":["iif"],"application/vnd.shana.informed.package":["ipk"],"application/vnd.simtech-mindmapper":["twd","twds"],"application/vnd.smaf":["mmf"],"application/vnd.smart.teacher":["teacher"],"application/vnd.software602.filler.form+xml":["fo"],"application/vnd.solent.sdkm+xml":["sdkm","sdkd"],"application/vnd.spotfire.dxp":["dxp"],"application/vnd.spotfire.sfs":["sfs"],"application/vnd.stardivision.calc":["sdc"],"application/vnd.stardivision.draw":["sda"],"application/vnd.stardivision.impress":["sdd"],"application/vnd.stardivision.math":["smf"],"application/vnd.stardivision.writer":["sdw","vor"],"application/vnd.stardivision.writer-global":["sgl"],"application/vnd.stepmania.package":["smzip"],"application/vnd.stepmania.stepchart":["sm"],"application/vnd.sun.wadl+xml":["wadl"],"application/vnd.sun.xml.calc":["sxc"],"application/vnd.sun.xml.calc.template":["stc"],"application/vnd.sun.xml.draw":["sxd"],"application/vnd.sun.xml.draw.template":["std"],"application/vnd.sun.xml.impress":["sxi"],"application/vnd.sun.xml.impress.template":["sti"],"application/vnd.sun.xml.math":["sxm"],"application/vnd.sun.xml.writer":["sxw"],"application/vnd.sun.xml.writer.global":["sxg"],"application/vnd.sun.xml.writer.template":["stw"],"application/vnd.sus-calendar":["sus","susp"],"application/vnd.svd":["svd"],"application/vnd.symbian.install":["sis","sisx"],"application/vnd.syncml+xml":["xsm"],"application/vnd.syncml.dm+wbxml":["bdm"],"application/vnd.syncml.dm+xml":["xdm"],"application/vnd.syncml.dmddf+xml":["ddf"],"application/vnd.tao.intent-module-archive":["tao"],"application/vnd.tcpdump.pcap":["pcap","cap","dmp"],"application/vnd.tmobile-livetv":["tmo"],"application/vnd.trid.tpt":["tpt"],"application/vnd.triscape.mxs":["mxs"],"application/vnd.trueapp":["tra"],"application/vnd.ufdl":["ufd","ufdl"],"application/vnd.uiq.theme":["utz"],"application/vnd.umajin":["umj"],"application/vnd.unity":["unityweb"],"application/vnd.uoml+xml":["uoml"],"application/vnd.vcx":["vcx"],"application/vnd.visio":["vsd","vst","vss","vsw"],"application/vnd.visionary":["vis"],"application/vnd.vsf":["vsf"],"application/vnd.wap.wbxml":["wbxml"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.wap.wmlscriptc":["wmlsc"],"application/vnd.webturbo":["wtb"],"application/vnd.wolfram.player":["nbp"],"application/vnd.wordperfect":["wpd"],"application/vnd.wqd":["wqd"],"application/vnd.wt.stf":["stf"],"application/vnd.xara":["xar"],"application/vnd.xfdl":["xfdl"],"application/vnd.yamaha.hv-dic":["hvd"],"application/vnd.yamaha.hv-script":["hvs"],"application/vnd.yamaha.hv-voice":["hvp"],"application/vnd.yamaha.openscoreformat":["osf"],"application/vnd.yamaha.openscoreformat.osfpvg+xml":["osfpvg"],"application/vnd.yamaha.smaf-audio":["saf"],"application/vnd.yamaha.smaf-phrase":["spf"],"application/vnd.yellowriver-custom-menu":["cmp"],"application/vnd.zul":["zir","zirz"],"application/vnd.zzazz.deck+xml":["zaz"],"application/x-7z-compressed":["7z"],"application/x-abiword":["abw"],"application/x-ace-compressed":["ace"],"application/x-apple-diskimage":["*dmg"],"application/x-arj":["arj"],"application/x-authorware-bin":["aab","x32","u32","vox"],"application/x-authorware-map":["aam"],"application/x-authorware-seg":["aas"],"application/x-bcpio":["bcpio"],"application/x-bdoc":["*bdoc"],"application/x-bittorrent":["torrent"],"application/x-blorb":["blb","blorb"],"application/x-bzip":["bz"],"application/x-bzip2":["bz2","boz"],"application/x-cbr":["cbr","cba","cbt","cbz","cb7"],"application/x-cdlink":["vcd"],"application/x-cfs-compressed":["cfs"],"application/x-chat":["chat"],"application/x-chess-pgn":["pgn"],"application/x-chrome-extension":["crx"],"application/x-cocoa":["cco"],"application/x-conference":["nsc"],"application/x-cpio":["cpio"],"application/x-csh":["csh"],"application/x-debian-package":["*deb","udeb"],"application/x-dgc-compressed":["dgc"],"application/x-director":["dir","dcr","dxr","cst","cct","cxt","w3d","fgd","swa"],"application/x-doom":["wad"],"application/x-dtbncx+xml":["ncx"],"application/x-dtbook+xml":["dtb"],"application/x-dtbresource+xml":["res"],"application/x-dvi":["dvi"],"application/x-envoy":["evy"],"application/x-eva":["eva"],"application/x-font-bdf":["bdf"],"application/x-font-ghostscript":["gsf"],"application/x-font-linux-psf":["psf"],"application/x-font-pcf":["pcf"],"application/x-font-snf":["snf"],"application/x-font-type1":["pfa","pfb","pfm","afm"],"application/x-freearc":["arc"],"application/x-futuresplash":["spl"],"application/x-gca-compressed":["gca"],"application/x-glulx":["ulx"],"application/x-gnumeric":["gnumeric"],"application/x-gramps-xml":["gramps"],"application/x-gtar":["gtar"],"application/x-hdf":["hdf"],"application/x-httpd-php":["php"],"application/x-install-instructions":["install"],"application/x-iso9660-image":["*iso"],"application/x-java-archive-diff":["jardiff"],"application/x-java-jnlp-file":["jnlp"],"application/x-keepass2":["kdbx"],"application/x-latex":["latex"],"application/x-lua-bytecode":["luac"],"application/x-lzh-compressed":["lzh","lha"],"application/x-makeself":["run"],"application/x-mie":["mie"],"application/x-mobipocket-ebook":["prc","mobi"],"application/x-ms-application":["application"],"application/x-ms-shortcut":["lnk"],"application/x-ms-wmd":["wmd"],"application/x-ms-wmz":["wmz"],"application/x-ms-xbap":["xbap"],"application/x-msaccess":["mdb"],"application/x-msbinder":["obd"],"application/x-mscardfile":["crd"],"application/x-msclip":["clp"],"application/x-msdos-program":["*exe"],"application/x-msdownload":["*exe","*dll","com","bat","*msi"],"application/x-msmediaview":["mvb","m13","m14"],"application/x-msmetafile":["*wmf","*wmz","*emf","emz"],"application/x-msmoney":["mny"],"application/x-mspublisher":["pub"],"application/x-msschedule":["scd"],"application/x-msterminal":["trm"],"application/x-mswrite":["wri"],"application/x-netcdf":["nc","cdf"],"application/x-ns-proxy-autoconfig":["pac"],"application/x-nzb":["nzb"],"application/x-perl":["pl","pm"],"application/x-pilot":["*prc","*pdb"],"application/x-pkcs12":["p12","pfx"],"application/x-pkcs7-certificates":["p7b","spc"],"application/x-pkcs7-certreqresp":["p7r"],"application/x-rar-compressed":["rar"],"application/x-redhat-package-manager":["rpm"],"application/x-research-info-systems":["ris"],"application/x-sea":["sea"],"application/x-sh":["sh"],"application/x-shar":["shar"],"application/x-shockwave-flash":["swf"],"application/x-silverlight-app":["xap"],"application/x-sql":["sql"],"application/x-stuffit":["sit"],"application/x-stuffitx":["sitx"],"application/x-subrip":["srt"],"application/x-sv4cpio":["sv4cpio"],"application/x-sv4crc":["sv4crc"],"application/x-t3vm-image":["t3"],"application/x-tads":["gam"],"application/x-tar":["tar"],"application/x-tcl":["tcl","tk"],"application/x-tex":["tex"],"application/x-tex-tfm":["tfm"],"application/x-texinfo":["texinfo","texi"],"application/x-tgif":["*obj"],"application/x-ustar":["ustar"],"application/x-virtualbox-hdd":["hdd"],"application/x-virtualbox-ova":["ova"],"application/x-virtualbox-ovf":["ovf"],"application/x-virtualbox-vbox":["vbox"],"application/x-virtualbox-vbox-extpack":["vbox-extpack"],"application/x-virtualbox-vdi":["vdi"],"application/x-virtualbox-vhd":["vhd"],"application/x-virtualbox-vmdk":["vmdk"],"application/x-wais-source":["src"],"application/x-web-app-manifest+json":["webapp"],"application/x-x509-ca-cert":["der","crt","pem"],"application/x-xfig":["fig"],"application/x-xliff+xml":["*xlf"],"application/x-xpinstall":["xpi"],"application/x-xz":["xz"],"application/x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"audio/vnd.dece.audio":["uva","uvva"],"audio/vnd.digital-winds":["eol"],"audio/vnd.dra":["dra"],"audio/vnd.dts":["dts"],"audio/vnd.dts.hd":["dtshd"],"audio/vnd.lucent.voice":["lvp"],"audio/vnd.ms-playready.media.pya":["pya"],"audio/vnd.nuera.ecelp4800":["ecelp4800"],"audio/vnd.nuera.ecelp7470":["ecelp7470"],"audio/vnd.nuera.ecelp9600":["ecelp9600"],"audio/vnd.rip":["rip"],"audio/x-aac":["aac"],"audio/x-aiff":["aif","aiff","aifc"],"audio/x-caf":["caf"],"audio/x-flac":["flac"],"audio/x-m4a":["*m4a"],"audio/x-matroska":["mka"],"audio/x-mpegurl":["m3u"],"audio/x-ms-wax":["wax"],"audio/x-ms-wma":["wma"],"audio/x-pn-realaudio":["ram","ra"],"audio/x-pn-realaudio-plugin":["rmp"],"audio/x-realaudio":["*ra"],"audio/x-wav":["*wav"],"chemical/x-cdx":["cdx"],"chemical/x-cif":["cif"],"chemical/x-cmdf":["cmdf"],"chemical/x-cml":["cml"],"chemical/x-csml":["csml"],"chemical/x-xyz":["xyz"],"image/prs.btif":["btif"],"image/prs.pti":["pti"],"image/vnd.adobe.photoshop":["psd"],"image/vnd.airzip.accelerator.azv":["azv"],"image/vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"image/vnd.djvu":["djvu","djv"],"image/vnd.dvb.subtitle":["*sub"],"image/vnd.dwg":["dwg"],"image/vnd.dxf":["dxf"],"image/vnd.fastbidsheet":["fbs"],"image/vnd.fpx":["fpx"],"image/vnd.fst":["fst"],"image/vnd.fujixerox.edmics-mmr":["mmr"],"image/vnd.fujixerox.edmics-rlc":["rlc"],"image/vnd.microsoft.icon":["ico"],"image/vnd.ms-dds":["dds"],"image/vnd.ms-modi":["mdi"],"image/vnd.ms-photo":["wdp"],"image/vnd.net-fpx":["npx"],"image/vnd.tencent.tap":["tap"],"image/vnd.valve.source.texture":["vtf"],"image/vnd.wap.wbmp":["wbmp"],"image/vnd.xiff":["xif"],"image/vnd.zbrush.pcx":["pcx"],"image/x-3ds":["3ds"],"image/x-cmu-raster":["ras"],"image/x-cmx":["cmx"],"image/x-freehand":["fh","fhc","fh4","fh5","fh7"],"image/x-icon":["*ico"],"image/x-jng":["jng"],"image/x-mrsid-image":["sid"],"image/x-ms-bmp":["*bmp"],"image/x-pcx":["*pcx"],"image/x-pict":["pic","pct"],"image/x-portable-anymap":["pnm"],"image/x-portable-bitmap":["pbm"],"image/x-portable-graymap":["pgm"],"image/x-portable-pixmap":["ppm"],"image/x-rgb":["rgb"],"image/x-tga":["tga"],"image/x-xbitmap":["xbm"],"image/x-xpixmap":["xpm"],"image/x-xwindowdump":["xwd"],"message/vnd.wfa.wsc":["wsc"],"model/vnd.collada+xml":["dae"],"model/vnd.dwf":["dwf"],"model/vnd.gdl":["gdl"],"model/vnd.gtw":["gtw"],"model/vnd.mts":["mts"],"model/vnd.opengex":["ogex"],"model/vnd.parasolid.transmit.binary":["x_b"],"model/vnd.parasolid.transmit.text":["x_t"],"model/vnd.usdz+zip":["usdz"],"model/vnd.valve.source.compiled-map":["bsp"],"model/vnd.vtu":["vtu"],"text/prs.lines.tag":["dsc"],"text/vnd.curl":["curl"],"text/vnd.curl.dcurl":["dcurl"],"text/vnd.curl.mcurl":["mcurl"],"text/vnd.curl.scurl":["scurl"],"text/vnd.dvb.subtitle":["sub"],"text/vnd.fly":["fly"],"text/vnd.fmi.flexstor":["flx"],"text/vnd.graphviz":["gv"],"text/vnd.in3d.3dml":["3dml"],"text/vnd.in3d.spot":["spot"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/vnd.wap.wmlscript":["wmls"],"text/x-asm":["s","asm"],"text/x-c":["c","cc","cxx","cpp","h","hh","dic"],"text/x-component":["htc"],"text/x-fortran":["f","for","f77","f90"],"text/x-handlebars-template":["hbs"],"text/x-java-source":["java"],"text/x-lua":["lua"],"text/x-markdown":["mkd"],"text/x-nfo":["nfo"],"text/x-opml":["opml"],"text/x-org":["*org"],"text/x-pascal":["p","pas"],"text/x-processing":["pde"],"text/x-sass":["sass"],"text/x-scss":["scss"],"text/x-setext":["etx"],"text/x-sfv":["sfv"],"text/x-suse-ymp":["ymp"],"text/x-uuencode":["uu"],"text/x-vcalendar":["vcs"],"text/x-vcard":["vcf"],"video/vnd.dece.hd":["uvh","uvvh"],"video/vnd.dece.mobile":["uvm","uvvm"],"video/vnd.dece.pd":["uvp","uvvp"],"video/vnd.dece.sd":["uvs","uvvs"],"video/vnd.dece.video":["uvv","uvvv"],"video/vnd.dvb.file":["dvb"],"video/vnd.fvt":["fvt"],"video/vnd.mpegurl":["mxu","m4u"],"video/vnd.ms-playready.media.pyv":["pyv"],"video/vnd.uvvu.mp4":["uvu","uvvu"],"video/vnd.vivo":["viv"],"video/x-f4v":["f4v"],"video/x-fli":["fli"],"video/x-flv":["flv"],"video/x-m4v":["m4v"],"video/x-matroska":["mkv","mk3d","mks"],"video/x-mng":["mng"],"video/x-ms-asf":["asf","asx"],"video/x-ms-vob":["vob"],"video/x-ms-wm":["wm"],"video/x-ms-wmv":["wmv"],"video/x-ms-wmx":["wmx"],"video/x-ms-wvx":["wvx"],"video/x-msvideo":["avi"],"video/x-sgi-movie":["movie"],"video/x-smv":["smv"],"x-conference/x-cooltalk":["ice"]};
343
-
344
- var mime = new Mime_1(standard, other);
345
-
346
- // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
347
-
348
- // fix for "Readable" isn't a named export issue
349
- const Readable = Stream__default['default'].Readable;
350
-
351
- const BUFFER = Symbol('buffer');
352
- const TYPE = Symbol('type');
353
-
354
- class Blob {
355
- constructor() {
356
- this[TYPE] = '';
357
-
358
- const blobParts = arguments[0];
359
- const options = arguments[1];
360
-
361
- const buffers = [];
362
- let size = 0;
363
-
364
- if (blobParts) {
365
- const a = blobParts;
366
- const length = Number(a.length);
367
- for (let i = 0; i < length; i++) {
368
- const element = a[i];
369
- let buffer;
370
- if (element instanceof Buffer) {
371
- buffer = element;
372
- } else if (ArrayBuffer.isView(element)) {
373
- buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
374
- } else if (element instanceof ArrayBuffer) {
375
- buffer = Buffer.from(element);
376
- } else if (element instanceof Blob) {
377
- buffer = element[BUFFER];
378
- } else {
379
- buffer = Buffer.from(typeof element === 'string' ? element : String(element));
380
- }
381
- size += buffer.length;
382
- buffers.push(buffer);
383
- }
384
- }
385
-
386
- this[BUFFER] = Buffer.concat(buffers);
387
-
388
- let type = options && options.type !== undefined && String(options.type).toLowerCase();
389
- if (type && !/[^\u0020-\u007E]/.test(type)) {
390
- this[TYPE] = type;
391
- }
392
- }
393
- get size() {
394
- return this[BUFFER].length;
395
- }
396
- get type() {
397
- return this[TYPE];
398
- }
399
- text() {
400
- return Promise.resolve(this[BUFFER].toString());
401
- }
402
- arrayBuffer() {
403
- const buf = this[BUFFER];
404
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
405
- return Promise.resolve(ab);
406
- }
407
- stream() {
408
- const readable = new Readable();
409
- readable._read = function () {};
410
- readable.push(this[BUFFER]);
411
- readable.push(null);
412
- return readable;
413
- }
414
- toString() {
415
- return '[object Blob]';
416
- }
417
- slice() {
418
- const size = this.size;
419
-
420
- const start = arguments[0];
421
- const end = arguments[1];
422
- let relativeStart, relativeEnd;
423
- if (start === undefined) {
424
- relativeStart = 0;
425
- } else if (start < 0) {
426
- relativeStart = Math.max(size + start, 0);
427
- } else {
428
- relativeStart = Math.min(start, size);
429
- }
430
- if (end === undefined) {
431
- relativeEnd = size;
432
- } else if (end < 0) {
433
- relativeEnd = Math.max(size + end, 0);
434
- } else {
435
- relativeEnd = Math.min(end, size);
436
- }
437
- const span = Math.max(relativeEnd - relativeStart, 0);
438
-
439
- const buffer = this[BUFFER];
440
- const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
441
- const blob = new Blob([], { type: arguments[2] });
442
- blob[BUFFER] = slicedBuffer;
443
- return blob;
444
- }
445
- }
446
-
447
- Object.defineProperties(Blob.prototype, {
448
- size: { enumerable: true },
449
- type: { enumerable: true },
450
- slice: { enumerable: true }
451
- });
452
-
453
- Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
454
- value: 'Blob',
455
- writable: false,
456
- enumerable: false,
457
- configurable: true
458
- });
459
-
460
- /**
461
- * fetch-error.js
462
- *
463
- * FetchError interface for operational errors
464
- */
465
-
466
- /**
467
- * Create FetchError instance
468
- *
469
- * @param String message Error message for human
470
- * @param String type Error type for machine
471
- * @param String systemError For Node.js system error
472
- * @return FetchError
473
- */
474
- function FetchError(message, type, systemError) {
475
- Error.call(this, message);
476
-
477
- this.message = message;
478
- this.type = type;
479
-
480
- // when err.type is `system`, err.code contains system error code
481
- if (systemError) {
482
- this.code = this.errno = systemError.code;
483
- }
484
-
485
- // hide custom error implementation details from end-users
486
- Error.captureStackTrace(this, this.constructor);
487
- }
488
-
489
- FetchError.prototype = Object.create(Error.prototype);
490
- FetchError.prototype.constructor = FetchError;
491
- FetchError.prototype.name = 'FetchError';
492
-
493
- let convert;
494
- try {
495
- convert = require('encoding').convert;
496
- } catch (e) {}
497
-
498
- const INTERNALS = Symbol('Body internals');
499
-
500
- // fix an issue where "PassThrough" isn't a named export for node <10
501
- const PassThrough = Stream__default['default'].PassThrough;
502
-
503
- /**
504
- * Body mixin
505
- *
506
- * Ref: https://fetch.spec.whatwg.org/#body
507
- *
508
- * @param Stream body Readable stream
509
- * @param Object opts Response options
510
- * @return Void
511
- */
512
- function Body(body) {
513
- var _this = this;
514
-
515
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
516
- _ref$size = _ref.size;
517
-
518
- let size = _ref$size === undefined ? 0 : _ref$size;
519
- var _ref$timeout = _ref.timeout;
520
- let timeout = _ref$timeout === undefined ? 0 : _ref$timeout;
521
-
522
- if (body == null) {
523
- // body is undefined or null
524
- body = null;
525
- } else if (isURLSearchParams(body)) {
526
- // body is a URLSearchParams
527
- body = Buffer.from(body.toString());
528
- } else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
529
- // body is ArrayBuffer
530
- body = Buffer.from(body);
531
- } else if (ArrayBuffer.isView(body)) {
532
- // body is ArrayBufferView
533
- body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
534
- } else if (body instanceof Stream__default['default']) ; else {
535
- // none of the above
536
- // coerce to string then buffer
537
- body = Buffer.from(String(body));
538
- }
539
- this[INTERNALS] = {
540
- body,
541
- disturbed: false,
542
- error: null
543
- };
544
- this.size = size;
545
- this.timeout = timeout;
546
-
547
- if (body instanceof Stream__default['default']) {
548
- body.on('error', function (err) {
549
- const error = err.name === 'AbortError' ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, 'system', err);
550
- _this[INTERNALS].error = error;
551
- });
552
- }
553
- }
554
-
555
- Body.prototype = {
556
- get body() {
557
- return this[INTERNALS].body;
558
- },
559
-
560
- get bodyUsed() {
561
- return this[INTERNALS].disturbed;
562
- },
563
-
564
- /**
565
- * Decode response as ArrayBuffer
566
- *
567
- * @return Promise
568
- */
569
- arrayBuffer() {
570
- return consumeBody.call(this).then(function (buf) {
571
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
572
- });
573
- },
574
-
575
- /**
576
- * Return raw response as Blob
577
- *
578
- * @return Promise
579
- */
580
- blob() {
581
- let ct = this.headers && this.headers.get('content-type') || '';
582
- return consumeBody.call(this).then(function (buf) {
583
- return Object.assign(
584
- // Prevent copying
585
- new Blob([], {
586
- type: ct.toLowerCase()
587
- }), {
588
- [BUFFER]: buf
589
- });
590
- });
591
- },
592
-
593
- /**
594
- * Decode response as json
595
- *
596
- * @return Promise
597
- */
598
- json() {
599
- var _this2 = this;
600
-
601
- return consumeBody.call(this).then(function (buffer) {
602
- try {
603
- return JSON.parse(buffer.toString());
604
- } catch (err) {
605
- return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
606
- }
607
- });
608
- },
609
-
610
- /**
611
- * Decode response as text
612
- *
613
- * @return Promise
614
- */
615
- text() {
616
- return consumeBody.call(this).then(function (buffer) {
617
- return buffer.toString();
618
- });
619
- },
620
-
621
- /**
622
- * Decode response as buffer (non-spec api)
623
- *
624
- * @return Promise
625
- */
626
- buffer() {
627
- return consumeBody.call(this);
628
- },
629
-
630
- /**
631
- * Decode response as text, while automatically detecting the encoding and
632
- * trying to decode to UTF-8 (non-spec api)
633
- *
634
- * @return Promise
635
- */
636
- textConverted() {
637
- var _this3 = this;
638
-
639
- return consumeBody.call(this).then(function (buffer) {
640
- return convertBody(buffer, _this3.headers);
641
- });
642
- }
643
- };
644
-
645
- // In browsers, all properties are enumerable.
646
- Object.defineProperties(Body.prototype, {
647
- body: { enumerable: true },
648
- bodyUsed: { enumerable: true },
649
- arrayBuffer: { enumerable: true },
650
- blob: { enumerable: true },
651
- json: { enumerable: true },
652
- text: { enumerable: true }
653
- });
654
-
655
- Body.mixIn = function (proto) {
656
- for (const name of Object.getOwnPropertyNames(Body.prototype)) {
657
- // istanbul ignore else: future proof
658
- if (!(name in proto)) {
659
- const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
660
- Object.defineProperty(proto, name, desc);
661
- }
662
- }
663
- };
664
-
665
- /**
666
- * Consume and convert an entire Body to a Buffer.
667
- *
668
- * Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
669
- *
670
- * @return Promise
671
- */
672
- function consumeBody() {
673
- var _this4 = this;
674
-
675
- if (this[INTERNALS].disturbed) {
676
- return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
677
- }
678
-
679
- this[INTERNALS].disturbed = true;
680
-
681
- if (this[INTERNALS].error) {
682
- return Body.Promise.reject(this[INTERNALS].error);
683
- }
684
-
685
- let body = this.body;
686
-
687
- // body is null
688
- if (body === null) {
689
- return Body.Promise.resolve(Buffer.alloc(0));
690
- }
691
-
692
- // body is blob
693
- if (isBlob(body)) {
694
- body = body.stream();
695
- }
696
-
697
- // body is buffer
698
- if (Buffer.isBuffer(body)) {
699
- return Body.Promise.resolve(body);
700
- }
701
-
702
- // istanbul ignore if: should never happen
703
- if (!(body instanceof Stream__default['default'])) {
704
- return Body.Promise.resolve(Buffer.alloc(0));
705
- }
706
-
707
- // body is stream
708
- // get ready to actually consume the body
709
- let accum = [];
710
- let accumBytes = 0;
711
- let abort = false;
712
-
713
- return new Body.Promise(function (resolve, reject) {
714
- let resTimeout;
715
-
716
- // allow timeout on slow response body
717
- if (_this4.timeout) {
718
- resTimeout = setTimeout(function () {
719
- abort = true;
720
- reject(new FetchError(`Response timeout while trying to fetch ${_this4.url} (over ${_this4.timeout}ms)`, 'body-timeout'));
721
- }, _this4.timeout);
722
- }
723
-
724
- // handle stream errors
725
- body.on('error', function (err) {
726
- if (err.name === 'AbortError') {
727
- // if the request was aborted, reject with this Error
728
- abort = true;
729
- reject(err);
730
- } else {
731
- // other errors, such as incorrect content-encoding
732
- reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, 'system', err));
733
- }
734
- });
735
-
736
- body.on('data', function (chunk) {
737
- if (abort || chunk === null) {
738
- return;
739
- }
740
-
741
- if (_this4.size && accumBytes + chunk.length > _this4.size) {
742
- abort = true;
743
- reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, 'max-size'));
744
- return;
745
- }
746
-
747
- accumBytes += chunk.length;
748
- accum.push(chunk);
749
- });
750
-
751
- body.on('end', function () {
752
- if (abort) {
753
- return;
754
- }
755
-
756
- clearTimeout(resTimeout);
757
-
758
- try {
759
- resolve(Buffer.concat(accum, accumBytes));
760
- } catch (err) {
761
- // handle streams that have accumulated too much data (issue #414)
762
- reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, 'system', err));
763
- }
764
- });
765
- });
766
- }
767
-
768
- /**
769
- * Detect buffer encoding and convert to target encoding
770
- * ref: http://www.w3.org/TR/2011/WD-html5-20110113/parsing.html#determining-the-character-encoding
771
- *
772
- * @param Buffer buffer Incoming buffer
773
- * @param String encoding Target encoding
774
- * @return String
775
- */
776
- function convertBody(buffer, headers) {
777
- if (typeof convert !== 'function') {
778
- throw new Error('The package `encoding` must be installed to use the textConverted() function');
779
- }
780
-
781
- const ct = headers.get('content-type');
782
- let charset = 'utf-8';
783
- let res, str;
784
-
785
- // header
786
- if (ct) {
787
- res = /charset=([^;]*)/i.exec(ct);
788
- }
789
-
790
- // no charset in content type, peek at response body for at most 1024 bytes
791
- str = buffer.slice(0, 1024).toString();
792
-
793
- // html5
794
- if (!res && str) {
795
- res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str);
796
- }
797
-
798
- // html4
799
- if (!res && str) {
800
- res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
801
- if (!res) {
802
- res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str);
803
- if (res) {
804
- res.pop(); // drop last quote
805
- }
806
- }
807
-
808
- if (res) {
809
- res = /charset=(.*)/i.exec(res.pop());
810
- }
811
- }
812
-
813
- // xml
814
- if (!res && str) {
815
- res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
816
- }
817
-
818
- // found charset
819
- if (res) {
820
- charset = res.pop();
821
-
822
- // prevent decode issues when sites use incorrect encoding
823
- // ref: https://hsivonen.fi/encoding-menu/
824
- if (charset === 'gb2312' || charset === 'gbk') {
825
- charset = 'gb18030';
826
- }
827
- }
828
-
829
- // turn raw buffers into a single utf-8 buffer
830
- return convert(buffer, 'UTF-8', charset).toString();
831
- }
832
-
833
- /**
834
- * Detect a URLSearchParams object
835
- * ref: https://github.com/bitinn/node-fetch/issues/296#issuecomment-307598143
836
- *
837
- * @param Object obj Object to detect by type or brand
838
- * @return String
839
- */
840
- function isURLSearchParams(obj) {
841
- // Duck-typing as a necessary condition.
842
- if (typeof obj !== 'object' || typeof obj.append !== 'function' || typeof obj.delete !== 'function' || typeof obj.get !== 'function' || typeof obj.getAll !== 'function' || typeof obj.has !== 'function' || typeof obj.set !== 'function') {
843
- return false;
844
- }
845
-
846
- // Brand-checking and more duck-typing as optional condition.
847
- return obj.constructor.name === 'URLSearchParams' || Object.prototype.toString.call(obj) === '[object URLSearchParams]' || typeof obj.sort === 'function';
848
- }
849
-
850
- /**
851
- * Check if `obj` is a W3C `Blob` object (which `File` inherits from)
852
- * @param {*} obj
853
- * @return {boolean}
854
- */
855
- function isBlob(obj) {
856
- return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
857
- }
858
-
859
- /**
860
- * Clone body given Res/Req instance
861
- *
862
- * @param Mixed instance Response or Request instance
863
- * @return Mixed
864
- */
865
- function clone(instance) {
866
- let p1, p2;
867
- let body = instance.body;
868
-
869
- // don't allow cloning a used body
870
- if (instance.bodyUsed) {
871
- throw new Error('cannot clone body after it is used');
872
- }
873
-
874
- // check that body is a stream and not form-data object
875
- // note: we can't clone the form-data object without having it as a dependency
876
- if (body instanceof Stream__default['default'] && typeof body.getBoundary !== 'function') {
877
- // tee instance body
878
- p1 = new PassThrough();
879
- p2 = new PassThrough();
880
- body.pipe(p1);
881
- body.pipe(p2);
882
- // set instance body to teed body and return the other teed body
883
- instance[INTERNALS].body = p1;
884
- body = p2;
885
- }
886
-
887
- return body;
888
- }
889
-
890
- /**
891
- * Performs the operation "extract a `Content-Type` value from |object|" as
892
- * specified in the specification:
893
- * https://fetch.spec.whatwg.org/#concept-bodyinit-extract
894
- *
895
- * This function assumes that instance.body is present.
896
- *
897
- * @param Mixed instance Any options.body input
898
- */
899
- function extractContentType(body) {
900
- if (body === null) {
901
- // body is null
902
- return null;
903
- } else if (typeof body === 'string') {
904
- // body is string
905
- return 'text/plain;charset=UTF-8';
906
- } else if (isURLSearchParams(body)) {
907
- // body is a URLSearchParams
908
- return 'application/x-www-form-urlencoded;charset=UTF-8';
909
- } else if (isBlob(body)) {
910
- // body is blob
911
- return body.type || null;
912
- } else if (Buffer.isBuffer(body)) {
913
- // body is buffer
914
- return null;
915
- } else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
916
- // body is ArrayBuffer
917
- return null;
918
- } else if (ArrayBuffer.isView(body)) {
919
- // body is ArrayBufferView
920
- return null;
921
- } else if (typeof body.getBoundary === 'function') {
922
- // detect form data input from form-data module
923
- return `multipart/form-data;boundary=${body.getBoundary()}`;
924
- } else if (body instanceof Stream__default['default']) {
925
- // body is stream
926
- // can't really do much about this
927
- return null;
928
- } else {
929
- // Body constructor defaults other things to string
930
- return 'text/plain;charset=UTF-8';
931
- }
932
- }
933
-
934
- /**
935
- * The Fetch Standard treats this as if "total bytes" is a property on the body.
936
- * For us, we have to explicitly get it with a function.
937
- *
938
- * ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
939
- *
940
- * @param Body instance Instance of Body
941
- * @return Number? Number of bytes, or null if not possible
942
- */
943
- function getTotalBytes(instance) {
944
- const body = instance.body;
945
-
946
-
947
- if (body === null) {
948
- // body is null
949
- return 0;
950
- } else if (isBlob(body)) {
951
- return body.size;
952
- } else if (Buffer.isBuffer(body)) {
953
- // body is buffer
954
- return body.length;
955
- } else if (body && typeof body.getLengthSync === 'function') {
956
- // detect form data input from form-data module
957
- if (body._lengthRetrievers && body._lengthRetrievers.length == 0 || // 1.x
958
- body.hasKnownLength && body.hasKnownLength()) {
959
- // 2.x
960
- return body.getLengthSync();
961
- }
962
- return null;
963
- } else {
964
- // body is stream
965
- return null;
966
- }
967
- }
968
-
969
- /**
970
- * Write a Body to a Node.js WritableStream (e.g. http.Request) object.
971
- *
972
- * @param Body instance Instance of Body
973
- * @return Void
974
- */
975
- function writeToStream(dest, instance) {
976
- const body = instance.body;
977
-
978
-
979
- if (body === null) {
980
- // body is null
981
- dest.end();
982
- } else if (isBlob(body)) {
983
- body.stream().pipe(dest);
984
- } else if (Buffer.isBuffer(body)) {
985
- // body is buffer
986
- dest.write(body);
987
- dest.end();
988
- } else {
989
- // body is stream
990
- body.pipe(dest);
991
- }
992
- }
993
-
994
- // expose Promise
995
- Body.Promise = global.Promise;
996
-
997
- /**
998
- * headers.js
999
- *
1000
- * Headers class offers convenient helpers
1001
- */
1002
-
1003
- const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
1004
- const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
1005
-
1006
- function validateName(name) {
1007
- name = `${name}`;
1008
- if (invalidTokenRegex.test(name) || name === '') {
1009
- throw new TypeError(`${name} is not a legal HTTP header name`);
1010
- }
1011
- }
1012
-
1013
- function validateValue(value) {
1014
- value = `${value}`;
1015
- if (invalidHeaderCharRegex.test(value)) {
1016
- throw new TypeError(`${value} is not a legal HTTP header value`);
1017
- }
1018
- }
1019
-
1020
- /**
1021
- * Find the key in the map object given a header name.
1022
- *
1023
- * Returns undefined if not found.
1024
- *
1025
- * @param String name Header name
1026
- * @return String|Undefined
1027
- */
1028
- function find(map, name) {
1029
- name = name.toLowerCase();
1030
- for (const key in map) {
1031
- if (key.toLowerCase() === name) {
1032
- return key;
1033
- }
1034
- }
1035
- return undefined;
1036
- }
1037
-
1038
- const MAP = Symbol('map');
1039
- class Headers {
1040
- /**
1041
- * Headers class
1042
- *
1043
- * @param Object headers Response headers
1044
- * @return Void
1045
- */
1046
- constructor() {
1047
- let init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
1048
-
1049
- this[MAP] = Object.create(null);
1050
-
1051
- if (init instanceof Headers) {
1052
- const rawHeaders = init.raw();
1053
- const headerNames = Object.keys(rawHeaders);
1054
-
1055
- for (const headerName of headerNames) {
1056
- for (const value of rawHeaders[headerName]) {
1057
- this.append(headerName, value);
1058
- }
1059
- }
1060
-
1061
- return;
1062
- }
1063
-
1064
- // We don't worry about converting prop to ByteString here as append()
1065
- // will handle it.
1066
- if (init == null) ; else if (typeof init === 'object') {
1067
- const method = init[Symbol.iterator];
1068
- if (method != null) {
1069
- if (typeof method !== 'function') {
1070
- throw new TypeError('Header pairs must be iterable');
1071
- }
1072
-
1073
- // sequence<sequence<ByteString>>
1074
- // Note: per spec we have to first exhaust the lists then process them
1075
- const pairs = [];
1076
- for (const pair of init) {
1077
- if (typeof pair !== 'object' || typeof pair[Symbol.iterator] !== 'function') {
1078
- throw new TypeError('Each header pair must be iterable');
1079
- }
1080
- pairs.push(Array.from(pair));
1081
- }
1082
-
1083
- for (const pair of pairs) {
1084
- if (pair.length !== 2) {
1085
- throw new TypeError('Each header pair must be a name/value tuple');
1086
- }
1087
- this.append(pair[0], pair[1]);
1088
- }
1089
- } else {
1090
- // record<ByteString, ByteString>
1091
- for (const key of Object.keys(init)) {
1092
- const value = init[key];
1093
- this.append(key, value);
1094
- }
1095
- }
1096
- } else {
1097
- throw new TypeError('Provided initializer must be an object');
1098
- }
1099
- }
1100
-
1101
- /**
1102
- * Return combined header value given name
1103
- *
1104
- * @param String name Header name
1105
- * @return Mixed
1106
- */
1107
- get(name) {
1108
- name = `${name}`;
1109
- validateName(name);
1110
- const key = find(this[MAP], name);
1111
- if (key === undefined) {
1112
- return null;
1113
- }
1114
-
1115
- return this[MAP][key].join(', ');
1116
- }
1117
-
1118
- /**
1119
- * Iterate over all headers
1120
- *
1121
- * @param Function callback Executed for each item with parameters (value, name, thisArg)
1122
- * @param Boolean thisArg `this` context for callback function
1123
- * @return Void
1124
- */
1125
- forEach(callback) {
1126
- let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
1127
-
1128
- let pairs = getHeaders(this);
1129
- let i = 0;
1130
- while (i < pairs.length) {
1131
- var _pairs$i = pairs[i];
1132
- const name = _pairs$i[0],
1133
- value = _pairs$i[1];
1134
-
1135
- callback.call(thisArg, value, name, this);
1136
- pairs = getHeaders(this);
1137
- i++;
1138
- }
1139
- }
1140
-
1141
- /**
1142
- * Overwrite header values given name
1143
- *
1144
- * @param String name Header name
1145
- * @param String value Header value
1146
- * @return Void
1147
- */
1148
- set(name, value) {
1149
- name = `${name}`;
1150
- value = `${value}`;
1151
- validateName(name);
1152
- validateValue(value);
1153
- const key = find(this[MAP], name);
1154
- this[MAP][key !== undefined ? key : name] = [value];
1155
- }
1156
-
1157
- /**
1158
- * Append a value onto existing header
1159
- *
1160
- * @param String name Header name
1161
- * @param String value Header value
1162
- * @return Void
1163
- */
1164
- append(name, value) {
1165
- name = `${name}`;
1166
- value = `${value}`;
1167
- validateName(name);
1168
- validateValue(value);
1169
- const key = find(this[MAP], name);
1170
- if (key !== undefined) {
1171
- this[MAP][key].push(value);
1172
- } else {
1173
- this[MAP][name] = [value];
1174
- }
1175
- }
1176
-
1177
- /**
1178
- * Check for header name existence
1179
- *
1180
- * @param String name Header name
1181
- * @return Boolean
1182
- */
1183
- has(name) {
1184
- name = `${name}`;
1185
- validateName(name);
1186
- return find(this[MAP], name) !== undefined;
1187
- }
1188
-
1189
- /**
1190
- * Delete all header values given name
1191
- *
1192
- * @param String name Header name
1193
- * @return Void
1194
- */
1195
- delete(name) {
1196
- name = `${name}`;
1197
- validateName(name);
1198
- const key = find(this[MAP], name);
1199
- if (key !== undefined) {
1200
- delete this[MAP][key];
1201
- }
1202
- }
1203
-
1204
- /**
1205
- * Return raw headers (non-spec api)
1206
- *
1207
- * @return Object
1208
- */
1209
- raw() {
1210
- return this[MAP];
1211
- }
1212
-
1213
- /**
1214
- * Get an iterator on keys.
1215
- *
1216
- * @return Iterator
1217
- */
1218
- keys() {
1219
- return createHeadersIterator(this, 'key');
1220
- }
1221
-
1222
- /**
1223
- * Get an iterator on values.
1224
- *
1225
- * @return Iterator
1226
- */
1227
- values() {
1228
- return createHeadersIterator(this, 'value');
1229
- }
1230
-
1231
- /**
1232
- * Get an iterator on entries.
1233
- *
1234
- * This is the default iterator of the Headers object.
1235
- *
1236
- * @return Iterator
1237
- */
1238
- [Symbol.iterator]() {
1239
- return createHeadersIterator(this, 'key+value');
1240
- }
1241
- }
1242
- Headers.prototype.entries = Headers.prototype[Symbol.iterator];
1243
-
1244
- Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
1245
- value: 'Headers',
1246
- writable: false,
1247
- enumerable: false,
1248
- configurable: true
1249
- });
1250
-
1251
- Object.defineProperties(Headers.prototype, {
1252
- get: { enumerable: true },
1253
- forEach: { enumerable: true },
1254
- set: { enumerable: true },
1255
- append: { enumerable: true },
1256
- has: { enumerable: true },
1257
- delete: { enumerable: true },
1258
- keys: { enumerable: true },
1259
- values: { enumerable: true },
1260
- entries: { enumerable: true }
1261
- });
1262
-
1263
- function getHeaders(headers) {
1264
- let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'key+value';
1265
-
1266
- const keys = Object.keys(headers[MAP]).sort();
1267
- return keys.map(kind === 'key' ? function (k) {
1268
- return k.toLowerCase();
1269
- } : kind === 'value' ? function (k) {
1270
- return headers[MAP][k].join(', ');
1271
- } : function (k) {
1272
- return [k.toLowerCase(), headers[MAP][k].join(', ')];
1273
- });
1274
- }
1275
-
1276
- const INTERNAL = Symbol('internal');
1277
-
1278
- function createHeadersIterator(target, kind) {
1279
- const iterator = Object.create(HeadersIteratorPrototype);
1280
- iterator[INTERNAL] = {
1281
- target,
1282
- kind,
1283
- index: 0
1284
- };
1285
- return iterator;
1286
- }
1287
-
1288
- const HeadersIteratorPrototype = Object.setPrototypeOf({
1289
- next() {
1290
- // istanbul ignore if
1291
- if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
1292
- throw new TypeError('Value of `this` is not a HeadersIterator');
1293
- }
1294
-
1295
- var _INTERNAL = this[INTERNAL];
1296
- const target = _INTERNAL.target,
1297
- kind = _INTERNAL.kind,
1298
- index = _INTERNAL.index;
1299
-
1300
- const values = getHeaders(target, kind);
1301
- const len = values.length;
1302
- if (index >= len) {
1303
- return {
1304
- value: undefined,
1305
- done: true
1306
- };
1307
- }
1308
-
1309
- this[INTERNAL].index = index + 1;
1310
-
1311
- return {
1312
- value: values[index],
1313
- done: false
1314
- };
1315
- }
1316
- }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
1317
-
1318
- Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
1319
- value: 'HeadersIterator',
1320
- writable: false,
1321
- enumerable: false,
1322
- configurable: true
1323
- });
1324
-
1325
- /**
1326
- * Export the Headers object in a form that Node.js can consume.
1327
- *
1328
- * @param Headers headers
1329
- * @return Object
1330
- */
1331
- function exportNodeCompatibleHeaders(headers) {
1332
- const obj = Object.assign({ __proto__: null }, headers[MAP]);
1333
-
1334
- // http.request() only supports string as Host header. This hack makes
1335
- // specifying custom Host header possible.
1336
- const hostHeaderKey = find(headers[MAP], 'Host');
1337
- if (hostHeaderKey !== undefined) {
1338
- obj[hostHeaderKey] = obj[hostHeaderKey][0];
1339
- }
1340
-
1341
- return obj;
1342
- }
1343
-
1344
- /**
1345
- * Create a Headers object from an object of headers, ignoring those that do
1346
- * not conform to HTTP grammar productions.
1347
- *
1348
- * @param Object obj Object of headers
1349
- * @return Headers
1350
- */
1351
- function createHeadersLenient(obj) {
1352
- const headers = new Headers();
1353
- for (const name of Object.keys(obj)) {
1354
- if (invalidTokenRegex.test(name)) {
1355
- continue;
1356
- }
1357
- if (Array.isArray(obj[name])) {
1358
- for (const val of obj[name]) {
1359
- if (invalidHeaderCharRegex.test(val)) {
1360
- continue;
1361
- }
1362
- if (headers[MAP][name] === undefined) {
1363
- headers[MAP][name] = [val];
1364
- } else {
1365
- headers[MAP][name].push(val);
1366
- }
1367
- }
1368
- } else if (!invalidHeaderCharRegex.test(obj[name])) {
1369
- headers[MAP][name] = [obj[name]];
1370
- }
1371
- }
1372
- return headers;
1373
- }
1374
-
1375
- const INTERNALS$1 = Symbol('Response internals');
1376
-
1377
- // fix an issue where "STATUS_CODES" aren't a named export for node <10
1378
- const STATUS_CODES = http__default['default'].STATUS_CODES;
1379
-
1380
- /**
1381
- * Response class
1382
- *
1383
- * @param Stream body Readable stream
1384
- * @param Object opts Response options
1385
- * @return Void
1386
- */
1387
- class Response {
1388
- constructor() {
1389
- let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1390
- let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1391
-
1392
- Body.call(this, body, opts);
1393
-
1394
- const status = opts.status || 200;
1395
- const headers = new Headers(opts.headers);
1396
-
1397
- if (body != null && !headers.has('Content-Type')) {
1398
- const contentType = extractContentType(body);
1399
- if (contentType) {
1400
- headers.append('Content-Type', contentType);
1401
- }
1402
- }
1403
-
1404
- this[INTERNALS$1] = {
1405
- url: opts.url,
1406
- status,
1407
- statusText: opts.statusText || STATUS_CODES[status],
1408
- headers,
1409
- counter: opts.counter
1410
- };
1411
- }
1412
-
1413
- get url() {
1414
- return this[INTERNALS$1].url || '';
1415
- }
1416
-
1417
- get status() {
1418
- return this[INTERNALS$1].status;
1419
- }
1420
-
1421
- /**
1422
- * Convenience property representing if the request ended normally
1423
- */
1424
- get ok() {
1425
- return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
1426
- }
1427
-
1428
- get redirected() {
1429
- return this[INTERNALS$1].counter > 0;
1430
- }
1431
-
1432
- get statusText() {
1433
- return this[INTERNALS$1].statusText;
1434
- }
1435
-
1436
- get headers() {
1437
- return this[INTERNALS$1].headers;
1438
- }
1439
-
1440
- /**
1441
- * Clone this response
1442
- *
1443
- * @return Response
1444
- */
1445
- clone() {
1446
- return new Response(clone(this), {
1447
- url: this.url,
1448
- status: this.status,
1449
- statusText: this.statusText,
1450
- headers: this.headers,
1451
- ok: this.ok,
1452
- redirected: this.redirected
1453
- });
1454
- }
1455
- }
1456
-
1457
- Body.mixIn(Response.prototype);
1458
-
1459
- Object.defineProperties(Response.prototype, {
1460
- url: { enumerable: true },
1461
- status: { enumerable: true },
1462
- ok: { enumerable: true },
1463
- redirected: { enumerable: true },
1464
- statusText: { enumerable: true },
1465
- headers: { enumerable: true },
1466
- clone: { enumerable: true }
1467
- });
1468
-
1469
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
1470
- value: 'Response',
1471
- writable: false,
1472
- enumerable: false,
1473
- configurable: true
1474
- });
1475
-
1476
- const INTERNALS$2 = Symbol('Request internals');
1477
-
1478
- // fix an issue where "format", "parse" aren't a named export for node <10
1479
- const parse_url = Url__default['default'].parse;
1480
- const format_url = Url__default['default'].format;
1481
-
1482
- const streamDestructionSupported = 'destroy' in Stream__default['default'].Readable.prototype;
1483
-
1484
- /**
1485
- * Check if a value is an instance of Request.
1486
- *
1487
- * @param Mixed input
1488
- * @return Boolean
1489
- */
1490
- function isRequest(input) {
1491
- return typeof input === 'object' && typeof input[INTERNALS$2] === 'object';
1492
- }
1493
-
1494
- function isAbortSignal(signal) {
1495
- const proto = signal && typeof signal === 'object' && Object.getPrototypeOf(signal);
1496
- return !!(proto && proto.constructor.name === 'AbortSignal');
1497
- }
1498
-
1499
- /**
1500
- * Request class
1501
- *
1502
- * @param Mixed input Url or Request instance
1503
- * @param Object init Custom options
1504
- * @return Void
1505
- */
1506
- class Request {
1507
- constructor(input) {
1508
- let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1509
-
1510
- let parsedURL;
1511
-
1512
- // normalize input
1513
- if (!isRequest(input)) {
1514
- if (input && input.href) {
1515
- // in order to support Node.js' Url objects; though WHATWG's URL objects
1516
- // will fall into this branch also (since their `toString()` will return
1517
- // `href` property anyway)
1518
- parsedURL = parse_url(input.href);
1519
- } else {
1520
- // coerce input to a string before attempting to parse
1521
- parsedURL = parse_url(`${input}`);
1522
- }
1523
- input = {};
1524
- } else {
1525
- parsedURL = parse_url(input.url);
1526
- }
1527
-
1528
- let method = init.method || input.method || 'GET';
1529
- method = method.toUpperCase();
1530
-
1531
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
1532
- throw new TypeError('Request with GET/HEAD method cannot have body');
1533
- }
1534
-
1535
- let inputBody = init.body != null ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
1536
-
1537
- Body.call(this, inputBody, {
1538
- timeout: init.timeout || input.timeout || 0,
1539
- size: init.size || input.size || 0
1540
- });
1541
-
1542
- const headers = new Headers(init.headers || input.headers || {});
1543
-
1544
- if (inputBody != null && !headers.has('Content-Type')) {
1545
- const contentType = extractContentType(inputBody);
1546
- if (contentType) {
1547
- headers.append('Content-Type', contentType);
1548
- }
1549
- }
1550
-
1551
- let signal = isRequest(input) ? input.signal : null;
1552
- if ('signal' in init) signal = init.signal;
1553
-
1554
- if (signal != null && !isAbortSignal(signal)) {
1555
- throw new TypeError('Expected signal to be an instanceof AbortSignal');
1556
- }
1557
-
1558
- this[INTERNALS$2] = {
1559
- method,
1560
- redirect: init.redirect || input.redirect || 'follow',
1561
- headers,
1562
- parsedURL,
1563
- signal
1564
- };
1565
-
1566
- // node-fetch-only options
1567
- this.follow = init.follow !== undefined ? init.follow : input.follow !== undefined ? input.follow : 20;
1568
- this.compress = init.compress !== undefined ? init.compress : input.compress !== undefined ? input.compress : true;
1569
- this.counter = init.counter || input.counter || 0;
1570
- this.agent = init.agent || input.agent;
1571
- }
1572
-
1573
- get method() {
1574
- return this[INTERNALS$2].method;
1575
- }
1576
-
1577
- get url() {
1578
- return format_url(this[INTERNALS$2].parsedURL);
1579
- }
1580
-
1581
- get headers() {
1582
- return this[INTERNALS$2].headers;
1583
- }
1584
-
1585
- get redirect() {
1586
- return this[INTERNALS$2].redirect;
1587
- }
1588
-
1589
- get signal() {
1590
- return this[INTERNALS$2].signal;
1591
- }
1592
-
1593
- /**
1594
- * Clone this request
1595
- *
1596
- * @return Request
1597
- */
1598
- clone() {
1599
- return new Request(this);
1600
- }
1601
- }
1602
-
1603
- Body.mixIn(Request.prototype);
1604
-
1605
- Object.defineProperty(Request.prototype, Symbol.toStringTag, {
1606
- value: 'Request',
1607
- writable: false,
1608
- enumerable: false,
1609
- configurable: true
1610
- });
1611
-
1612
- Object.defineProperties(Request.prototype, {
1613
- method: { enumerable: true },
1614
- url: { enumerable: true },
1615
- headers: { enumerable: true },
1616
- redirect: { enumerable: true },
1617
- clone: { enumerable: true },
1618
- signal: { enumerable: true }
1619
- });
1620
-
1621
- /**
1622
- * Convert a Request to Node.js http request options.
1623
- *
1624
- * @param Request A Request instance
1625
- * @return Object The options object to be passed to http.request
1626
- */
1627
- function getNodeRequestOptions(request) {
1628
- const parsedURL = request[INTERNALS$2].parsedURL;
1629
- const headers = new Headers(request[INTERNALS$2].headers);
1630
-
1631
- // fetch step 1.3
1632
- if (!headers.has('Accept')) {
1633
- headers.set('Accept', '*/*');
1634
- }
1635
-
1636
- // Basic fetch
1637
- if (!parsedURL.protocol || !parsedURL.hostname) {
1638
- throw new TypeError('Only absolute URLs are supported');
1639
- }
1640
-
1641
- if (!/^https?:$/.test(parsedURL.protocol)) {
1642
- throw new TypeError('Only HTTP(S) protocols are supported');
1643
- }
1644
-
1645
- if (request.signal && request.body instanceof Stream__default['default'].Readable && !streamDestructionSupported) {
1646
- throw new Error('Cancellation of streamed requests with AbortSignal is not supported in node < 8');
1647
- }
1648
-
1649
- // HTTP-network-or-cache fetch steps 2.4-2.7
1650
- let contentLengthValue = null;
1651
- if (request.body == null && /^(POST|PUT)$/i.test(request.method)) {
1652
- contentLengthValue = '0';
1653
- }
1654
- if (request.body != null) {
1655
- const totalBytes = getTotalBytes(request);
1656
- if (typeof totalBytes === 'number') {
1657
- contentLengthValue = String(totalBytes);
1658
- }
1659
- }
1660
- if (contentLengthValue) {
1661
- headers.set('Content-Length', contentLengthValue);
1662
- }
1663
-
1664
- // HTTP-network-or-cache fetch step 2.11
1665
- if (!headers.has('User-Agent')) {
1666
- headers.set('User-Agent', 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)');
1667
- }
1668
-
1669
- // HTTP-network-or-cache fetch step 2.15
1670
- if (request.compress && !headers.has('Accept-Encoding')) {
1671
- headers.set('Accept-Encoding', 'gzip,deflate');
1672
- }
1673
-
1674
- let agent = request.agent;
1675
- if (typeof agent === 'function') {
1676
- agent = agent(parsedURL);
1677
- }
1678
-
1679
- if (!headers.has('Connection') && !agent) {
1680
- headers.set('Connection', 'close');
1681
- }
1682
-
1683
- // HTTP-network fetch step 4.2
1684
- // chunked encoding is handled by Node.js
1685
-
1686
- return Object.assign({}, parsedURL, {
1687
- method: request.method,
1688
- headers: exportNodeCompatibleHeaders(headers),
1689
- agent
1690
- });
1691
- }
1692
-
1693
- /**
1694
- * abort-error.js
1695
- *
1696
- * AbortError interface for cancelled requests
1697
- */
1698
-
1699
- /**
1700
- * Create AbortError instance
1701
- *
1702
- * @param String message Error message for human
1703
- * @return AbortError
1704
- */
1705
- function AbortError(message) {
1706
- Error.call(this, message);
1707
-
1708
- this.type = 'aborted';
1709
- this.message = message;
1710
-
1711
- // hide custom error implementation details from end-users
1712
- Error.captureStackTrace(this, this.constructor);
1713
- }
1714
-
1715
- AbortError.prototype = Object.create(Error.prototype);
1716
- AbortError.prototype.constructor = AbortError;
1717
- AbortError.prototype.name = 'AbortError';
1718
-
1719
- // fix an issue where "PassThrough", "resolve" aren't a named export for node <10
1720
- const PassThrough$1 = Stream__default['default'].PassThrough;
1721
- const resolve_url = Url__default['default'].resolve;
1722
-
1723
- /**
1724
- * Fetch function
1725
- *
1726
- * @param Mixed url Absolute url or Request instance
1727
- * @param Object opts Fetch options
1728
- * @return Promise
1729
- */
1730
- function fetch(url, opts) {
1731
-
1732
- // allow custom promise
1733
- if (!fetch.Promise) {
1734
- throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
1735
- }
1736
-
1737
- Body.Promise = fetch.Promise;
1738
-
1739
- // wrap http.request into fetch
1740
- return new fetch.Promise(function (resolve, reject) {
1741
- // build request object
1742
- const request = new Request(url, opts);
1743
- const options = getNodeRequestOptions(request);
1744
-
1745
- const send = (options.protocol === 'https:' ? https__default['default'] : http__default['default']).request;
1746
- const signal = request.signal;
1747
-
1748
- let response = null;
1749
-
1750
- const abort = function abort() {
1751
- let error = new AbortError('The user aborted a request.');
1752
- reject(error);
1753
- if (request.body && request.body instanceof Stream__default['default'].Readable) {
1754
- request.body.destroy(error);
1755
- }
1756
- if (!response || !response.body) return;
1757
- response.body.emit('error', error);
1758
- };
1759
-
1760
- if (signal && signal.aborted) {
1761
- abort();
1762
- return;
1763
- }
1764
-
1765
- const abortAndFinalize = function abortAndFinalize() {
1766
- abort();
1767
- finalize();
1768
- };
1769
-
1770
- // send request
1771
- const req = send(options);
1772
- let reqTimeout;
1773
-
1774
- if (signal) {
1775
- signal.addEventListener('abort', abortAndFinalize);
1776
- }
1777
-
1778
- function finalize() {
1779
- req.abort();
1780
- if (signal) signal.removeEventListener('abort', abortAndFinalize);
1781
- clearTimeout(reqTimeout);
1782
- }
1783
-
1784
- if (request.timeout) {
1785
- req.once('socket', function (socket) {
1786
- reqTimeout = setTimeout(function () {
1787
- reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
1788
- finalize();
1789
- }, request.timeout);
1790
- });
1791
- }
1792
-
1793
- req.on('error', function (err) {
1794
- reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
1795
- finalize();
1796
- });
1797
-
1798
- req.on('response', function (res) {
1799
- clearTimeout(reqTimeout);
1800
-
1801
- const headers = createHeadersLenient(res.headers);
1802
-
1803
- // HTTP fetch step 5
1804
- if (fetch.isRedirect(res.statusCode)) {
1805
- // HTTP fetch step 5.2
1806
- const location = headers.get('Location');
1807
-
1808
- // HTTP fetch step 5.3
1809
- const locationURL = location === null ? null : resolve_url(request.url, location);
1810
-
1811
- // HTTP fetch step 5.5
1812
- switch (request.redirect) {
1813
- case 'error':
1814
- reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));
1815
- finalize();
1816
- return;
1817
- case 'manual':
1818
- // node-fetch-specific step: make manual redirect a bit easier to use by setting the Location header value to the resolved URL.
1819
- if (locationURL !== null) {
1820
- // handle corrupted header
1821
- try {
1822
- headers.set('Location', locationURL);
1823
- } catch (err) {
1824
- // istanbul ignore next: nodejs server prevent invalid response headers, we can't test this through normal request
1825
- reject(err);
1826
- }
1827
- }
1828
- break;
1829
- case 'follow':
1830
- // HTTP-redirect fetch step 2
1831
- if (locationURL === null) {
1832
- break;
1833
- }
1834
-
1835
- // HTTP-redirect fetch step 5
1836
- if (request.counter >= request.follow) {
1837
- reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));
1838
- finalize();
1839
- return;
1840
- }
1841
-
1842
- // HTTP-redirect fetch step 6 (counter increment)
1843
- // Create a new Request object.
1844
- const requestOpts = {
1845
- headers: new Headers(request.headers),
1846
- follow: request.follow,
1847
- counter: request.counter + 1,
1848
- agent: request.agent,
1849
- compress: request.compress,
1850
- method: request.method,
1851
- body: request.body,
1852
- signal: request.signal,
1853
- timeout: request.timeout,
1854
- size: request.size
1855
- };
1856
-
1857
- // HTTP-redirect fetch step 9
1858
- if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
1859
- reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
1860
- finalize();
1861
- return;
1862
- }
1863
-
1864
- // HTTP-redirect fetch step 11
1865
- if (res.statusCode === 303 || (res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST') {
1866
- requestOpts.method = 'GET';
1867
- requestOpts.body = undefined;
1868
- requestOpts.headers.delete('content-length');
1869
- }
1870
-
1871
- // HTTP-redirect fetch step 15
1872
- resolve(fetch(new Request(locationURL, requestOpts)));
1873
- finalize();
1874
- return;
1875
- }
1876
- }
1877
-
1878
- // prepare response
1879
- res.once('end', function () {
1880
- if (signal) signal.removeEventListener('abort', abortAndFinalize);
1881
- });
1882
- let body = res.pipe(new PassThrough$1());
1883
-
1884
- const response_options = {
1885
- url: request.url,
1886
- status: res.statusCode,
1887
- statusText: res.statusMessage,
1888
- headers: headers,
1889
- size: request.size,
1890
- timeout: request.timeout,
1891
- counter: request.counter
1892
- };
1893
-
1894
- // HTTP-network fetch step 12.1.1.3
1895
- const codings = headers.get('Content-Encoding');
1896
-
1897
- // HTTP-network fetch step 12.1.1.4: handle content codings
1898
-
1899
- // in following scenarios we ignore compression support
1900
- // 1. compression support is disabled
1901
- // 2. HEAD request
1902
- // 3. no Content-Encoding header
1903
- // 4. no content response (204)
1904
- // 5. content not modified response (304)
1905
- if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
1906
- response = new Response(body, response_options);
1907
- resolve(response);
1908
- return;
1909
- }
1910
-
1911
- // For Node v6+
1912
- // Be less strict when decoding compressed responses, since sometimes
1913
- // servers send slightly invalid responses that are still accepted
1914
- // by common browsers.
1915
- // Always using Z_SYNC_FLUSH is what cURL does.
1916
- const zlibOptions = {
1917
- flush: zlib__default['default'].Z_SYNC_FLUSH,
1918
- finishFlush: zlib__default['default'].Z_SYNC_FLUSH
1919
- };
1920
-
1921
- // for gzip
1922
- if (codings == 'gzip' || codings == 'x-gzip') {
1923
- body = body.pipe(zlib__default['default'].createGunzip(zlibOptions));
1924
- response = new Response(body, response_options);
1925
- resolve(response);
1926
- return;
1927
- }
1928
-
1929
- // for deflate
1930
- if (codings == 'deflate' || codings == 'x-deflate') {
1931
- // handle the infamous raw deflate response from old servers
1932
- // a hack for old IIS and Apache servers
1933
- const raw = res.pipe(new PassThrough$1());
1934
- raw.once('data', function (chunk) {
1935
- // see http://stackoverflow.com/questions/37519828
1936
- if ((chunk[0] & 0x0F) === 0x08) {
1937
- body = body.pipe(zlib__default['default'].createInflate());
1938
- } else {
1939
- body = body.pipe(zlib__default['default'].createInflateRaw());
1940
- }
1941
- response = new Response(body, response_options);
1942
- resolve(response);
1943
- });
1944
- return;
1945
- }
1946
-
1947
- // for br
1948
- if (codings == 'br' && typeof zlib__default['default'].createBrotliDecompress === 'function') {
1949
- body = body.pipe(zlib__default['default'].createBrotliDecompress());
1950
- response = new Response(body, response_options);
1951
- resolve(response);
1952
- return;
1953
- }
1954
-
1955
- // otherwise, use response as-is
1956
- response = new Response(body, response_options);
1957
- resolve(response);
1958
- });
1959
-
1960
- writeToStream(req, request);
1961
- });
1962
- }
1963
- /**
1964
- * Redirect code matching
1965
- *
1966
- * @param Number code Status code
1967
- * @return Boolean
1968
- */
1969
- fetch.isRedirect = function (code) {
1970
- return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
1971
- };
1972
-
1973
- // expose Promise
1974
- fetch.Promise = global.Promise;
1975
-
1976
- function noop() { }
1977
- function safe_not_equal(a, b) {
1978
- return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
1979
- }
1980
-
1981
- const subscriber_queue = [];
1982
- /**
1983
- * Create a `Writable` store that allows both updating and reading by subscription.
1984
- * @param {*=}value initial value
1985
- * @param {StartStopNotifier=}start start and stop notifications for subscriptions
1986
- */
1987
- function writable(value, start = noop) {
1988
- let stop;
1989
- const subscribers = [];
1990
- function set(new_value) {
1991
- if (safe_not_equal(value, new_value)) {
1992
- value = new_value;
1993
- if (stop) { // store is ready
1994
- const run_queue = !subscriber_queue.length;
1995
- for (let i = 0; i < subscribers.length; i += 1) {
1996
- const s = subscribers[i];
1997
- s[1]();
1998
- subscriber_queue.push(s, value);
1999
- }
2000
- if (run_queue) {
2001
- for (let i = 0; i < subscriber_queue.length; i += 2) {
2002
- subscriber_queue[i][0](subscriber_queue[i + 1]);
2003
- }
2004
- subscriber_queue.length = 0;
2005
- }
2006
- }
2007
- }
2008
- }
2009
- function update(fn) {
2010
- set(fn(value));
2011
- }
2012
- function subscribe(run, invalidate = noop) {
2013
- const subscriber = [run, invalidate];
2014
- subscribers.push(subscriber);
2015
- if (subscribers.length === 1) {
2016
- stop = start(set) || noop;
2017
- }
2018
- run(value);
2019
- return () => {
2020
- const index = subscribers.indexOf(subscriber);
2021
- if (index !== -1) {
2022
- subscribers.splice(index, 1);
2023
- }
2024
- if (subscribers.length === 0) {
2025
- stop();
2026
- stop = null;
2027
- }
2028
- };
2029
- }
2030
- return { set, update, subscribe };
2031
- }
2032
-
2033
- async function get_response({
2034
- request,
2035
- options,
2036
- session,
2037
- page,
2038
- status = 200,
2039
- error
2040
- }) {
2041
- let redirected;
2042
-
2043
- const base = ''; // TODO
2044
-
2045
- const dependencies = {};
2046
-
2047
- const serialized_session = try_serialize(session, (err) => {
2048
- throw new Error(`Failed to serialize session data: ${err.message}`);
2049
- });
2050
-
2051
- const preload_context = {
2052
- redirect: (status, location) => {
2053
- if (
2054
- redirected &&
2055
- (redirected.status !== status || redirected.headers.location !== location)
2056
- ) {
2057
- throw new Error('Conflicting redirects');
2058
- }
2059
- location = location.replace(/^\//g, ''); // leading slash (only)
2060
- redirected = {
2061
- status,
2062
- headers: { location },
2063
- body: null,
2064
- dependencies: {}
2065
- };
2066
- },
2067
- error: (status, error) => {
2068
- if (typeof error === 'string') {
2069
- error = new Error(error);
2070
- }
2071
- error.status = status;
2072
- throw error;
2073
- },
2074
- fetch: async (url, opts = {}) => {
2075
- const parsed = Url.parse(url);
2076
-
2077
- if (parsed.protocol) {
2078
- // external fetch
2079
- return fetch(parsed.href, opts);
2080
- }
2081
-
2082
- // otherwise we're dealing with an internal fetch. TODO there's
2083
- // probably no advantage to using fetch here — we should replace
2084
- // `this.fetch` with `this.load` or whatever
2085
-
2086
- const resolved = Url.resolve(request.path, parsed.pathname);
2087
-
2088
- // edge case — fetching a static file
2089
- const candidates = [
2090
- `${options.static_dir}${resolved}`,
2091
- `${options.static_dir}${resolved}/index.html`
2092
- ];
2093
- for (const file of candidates) {
2094
- if (fs.existsSync(file)) {
2095
- return new Response(fs.createReadStream(file), {
2096
- headers: {
2097
- 'content-type': mime.getType(file)
2098
- }
2099
- });
2100
- }
2101
- }
2102
-
2103
- // TODO this doesn't take account of opts.body
2104
- const rendered = await render(
2105
- {
2106
- host: request.host,
2107
- method: opts.method || 'GET',
2108
- headers: opts.headers || {}, // TODO inject credentials...
2109
- path: resolved,
2110
- body: opts.body,
2111
- query: new Url.URLSearchParams(parsed.query || '')
2112
- },
2113
- options
2114
- );
2115
-
2116
- if (rendered) {
2117
- // TODO this is primarily for the benefit of the static case,
2118
- // but could it be used elsewhere?
2119
- dependencies[resolved] = rendered;
2120
-
2121
- return new Response(rendered.body, {
2122
- status: rendered.status,
2123
- headers: rendered.headers
2124
- });
2125
- } else {
2126
- return new Response('Not found', {
2127
- status: 404
2128
- });
2129
- }
2130
- }
2131
- };
2132
-
2133
- const match = page && page.pattern.exec(request.path);
2134
-
2135
- // the last part has all parameters from any segment in the URL
2136
- const params = page ? parts_to_params(match, page.parts[page.parts.length - 1] ) : {};
2137
-
2138
- const preloaded = [];
2139
- let can_prerender = true;
2140
-
2141
- const page_parts = error
2142
- ? [{ component: options.manifest.error, params: [] }]
2143
- : page.parts;
2144
-
2145
- const parts = await Promise.all(
2146
- [{ component: options.manifest.layout, params: [] }, ...page_parts].map(async (part, i) => {
2147
- if (!part) return null;
2148
-
2149
- const mod = await options.load(part.component);
2150
-
2151
- if (options.only_prerender && !mod.prerender) {
2152
- can_prerender = false;
2153
- return;
2154
- }
2155
-
2156
- // these are only the parameters up to the current URL segment
2157
- const params = parts_to_params(match, part);
2158
-
2159
- const props = mod.preload ? await mod.preload.call(
2160
- preload_context,
2161
- {
2162
- host: request.host,
2163
- path: request.path,
2164
- query: request.query,
2165
- params
2166
- },
2167
- session
2168
- ) : {};
2169
-
2170
- preloaded[i] = props;
2171
- return { component: mod.default, props };
2172
- })
2173
- );
2174
-
2175
- if (options.only_prerender && !can_prerender) return;
2176
-
2177
- if (redirected) return redirected;
2178
-
2179
- const props = {
2180
- status,
2181
- error,
2182
- stores: {
2183
- page: writable(null),
2184
- navigating: writable(false),
2185
- session: writable(session)
2186
- },
2187
- page: {
2188
- host: request.host,
2189
- path: request.path,
2190
- query: request.query,
2191
- params,
2192
- error
2193
- },
2194
- components: parts.map(part => part.component)
2195
- };
2196
-
2197
- // leveln (instead of levels[n]) makes it easy to avoid
2198
- // unnecessary updates for layout components
2199
- parts.forEach((part, i) => {
2200
- props[`props_${i}`] = part.props;
2201
- });
2202
-
2203
- const serialized_preloads = `[${preloaded
2204
- .map((data) =>
2205
- try_serialize(data, (err) => {
2206
- console.error(
2207
- `Failed to serialize preloaded data to transmit to the client at the ${request.path} route: ${err.message}`
2208
- );
2209
- console.warn(
2210
- 'The client will re-render over the server-rendered page fresh instead of continuing where it left off. See https://sapper.svelte.dev/docs#Return_value for more information'
2211
- );
2212
- })
2213
- )
2214
- .join(',')}]`;
2215
-
2216
- const rendered = options.root.render(props);
2217
-
2218
- const deps = options.client.deps;
2219
- const js_deps = new Set(deps.__entry__ ? [...deps.__entry__.js] : []);
2220
- const css_deps = new Set(deps.__entry__ ? [...deps.__entry__.css] : []);
2221
-
2222
- if (page) {
2223
- // TODO handle error page deps
2224
- (page.parts.filter(Boolean) ).forEach((part) => {
2225
- const page_deps = deps[part.component.name];
2226
-
2227
- if (!page_deps) return; // we don't have this info during dev
2228
-
2229
- page_deps.js.forEach((dep) => js_deps.add(dep));
2230
- page_deps.css.forEach((dep) => css_deps.add(dep));
2231
- });
2232
- }
2233
-
2234
- const head = `${rendered.head}
2235
-
2236
- ${Array.from(js_deps)
2237
- .map((dep) => `<link rel="modulepreload" href="/_app/${dep}">`)
2238
- .join('\n\t\t\t')}
2239
- ${Array.from(css_deps)
2240
- .map((dep) => `<link rel="stylesheet" href="/_app/${dep}">`)
2241
- .join('\n\t\t\t')}
2242
- ${options.dev ? `<style>${rendered.css.code}</style>` : ''}
2243
- `.replace(/^\t{2}/gm, '');
2244
-
2245
- const body = `${rendered.html}
2246
- <script type="module">
2247
- import { start } from '/_app/${options.client.entry}';
2248
- ${options.start_global ? `window.${options.start_global} = () => ` : ''}start({
2249
- target: ${options.target ? `document.querySelector(${JSON.stringify(options.target)})` : 'document.body'},
2250
- base: "${base}",
2251
- status: ${status},
2252
- error: ${serialize_error(error)},
2253
- preloaded: ${serialized_preloads},
2254
- session: ${serialized_session}
2255
- });
2256
- </script>`.replace(/^\t{3}/gm, '');
2257
-
2258
- return {
2259
- status,
2260
- headers: {
2261
- 'content-type': 'text/html'
2262
- },
2263
- body: options.template({ head, body }),
2264
- dependencies
2265
- };
2266
- }
2267
-
2268
- async function render_page(
2269
- request,
2270
- context,
2271
- options
2272
- ) {
2273
- const page = options.manifest.pages.find((page) =>
2274
- page.pattern.test(request.path)
2275
- );
2276
-
2277
- const session = await (options.setup.getSession && options.setup.getSession(context));
2278
-
2279
- try {
2280
- if (!page) {
2281
- const error = new Error(`Not found: ${request.path}`);
2282
- error.status = 404;
2283
- throw error;
2284
- }
2285
-
2286
- return await get_response({
2287
- request,
2288
- options,
2289
- session,
2290
- page,
2291
- status: 200,
2292
- error: null
2293
- });
2294
- } catch (error) {
2295
- try {
2296
- const status = error.status || 500;
2297
-
2298
- return await get_response({
2299
- request,
2300
- options,
2301
- session,
2302
- page,
2303
- status,
2304
- error
2305
- });
2306
- } catch (error) {
2307
- // oh lawd now you've done it
2308
- return {
2309
- status: 500,
2310
- headers: {},
2311
- body: error.stack, // TODO probably not in prod?
2312
- dependencies: {}
2313
- };
2314
- }
2315
- }
2316
- }
2317
-
2318
- function parts_to_params(match, part) {
2319
- const params = {};
2320
-
2321
- part.params.forEach((name, i) => {
2322
- const is_spread = /^\.{3}.+$/.test(name);
2323
-
2324
- if (is_spread) {
2325
- params[name.slice(3)] = match[i + 1].split('/');
2326
- } else {
2327
- params[name] = match[i + 1];
2328
- }
2329
- });
2330
-
2331
- return params;
2332
- }
2333
-
2334
- function try_serialize(data, fail) {
2335
- try {
2336
- return devalue(data);
2337
- } catch (err) {
2338
- if (fail) fail(err);
2339
- return null;
2340
- }
2341
- }
2342
-
2343
- // Ensure we return something truthy so the client will not re-render the page over the error
2344
- function serialize_error(error) {
2345
- if (!error) return null;
2346
- let serialized = try_serialize(error);
2347
- if (!serialized) {
2348
- const { name, message, stack } = error;
2349
- serialized = try_serialize({ name, message, stack });
2350
- }
2351
- if (!serialized) {
2352
- serialized = '{}';
2353
- }
2354
- return serialized;
2355
- }
2356
-
2357
- function render_route(
2358
- request,
2359
- context,
2360
- options
2361
- ) {
2362
- const route = options.manifest.endpoints.find((route) =>
2363
- route.pattern.test(request.path)
2364
- );
2365
- if (!route) return null;
2366
-
2367
- return Promise.resolve(options.load(route)).then(async (mod) => {
2368
- const handler = mod[request.method.toLowerCase().replace('delete', 'del')]; // 'delete' is a reserved word
2369
-
2370
- if (handler) {
2371
- const params = {};
2372
- const match = route.pattern.exec(request.path);
2373
- route.params.forEach((name, i) => {
2374
- if (name.startsWith('...')) {
2375
- params[name.slice(3)] = match[i + 1].split('/');
2376
- } else {
2377
- params[name] = match[i + 1];
2378
- }
2379
- });
2380
-
2381
- try {
2382
- const response = await handler(
2383
- {
2384
- host: request.host,
2385
- path: request.path,
2386
- headers: request.headers,
2387
- query: request.query,
2388
- body: request.body,
2389
- params
2390
- },
2391
- context
2392
- );
2393
-
2394
- if (typeof response !== 'object' || response.body == null) {
2395
- return {
2396
- status: 500,
2397
- body: `Invalid response from route ${request.path}; ${
2398
- response.body == null
2399
- ? 'body is missing'
2400
- : `expected an object, got ${typeof response}`
2401
- }`,
2402
- headers: {}
2403
- };
2404
- }
2405
-
2406
- let { status = 200, body, headers = {} } = response;
2407
-
2408
- headers = lowercase_keys(headers);
2409
-
2410
- if (
2411
- (typeof body === 'object' && !('content-type' in headers)) ||
2412
- headers['content-type'] === 'application/json'
2413
- ) {
2414
- headers = { ...headers, 'content-type': 'application/json' };
2415
- body = JSON.stringify(body);
2416
- }
2417
-
2418
- return { status, body, headers };
2419
- } catch (err) {
2420
- return {
2421
- status: 500,
2422
- body: err.message,
2423
- headers: {}
2424
- };
2425
- }
2426
- } else {
2427
- return {
2428
- status: 501,
2429
- body: `${request.method} is not implemented for ${request.path}`,
2430
- headers: {}
2431
- };
2432
- }
2433
- });
2434
- }
2435
-
2436
- function lowercase_keys(obj) {
2437
- const clone = {};
2438
- for (const key in obj) {
2439
- clone[key.toLowerCase()] = obj[key];
2440
- }
2441
- return clone;
2442
- }
2443
-
2444
- function md5(body) {
2445
- return crypto.createHash('md5').update(body).digest('hex');
2446
- }
2447
-
2448
- async function render(
2449
- request,
2450
- options
2451
- ) {
2452
- const { context, headers = {} } = (await (options.setup.prepare && options.setup.prepare(request.headers))) || {};
2453
-
2454
- try {
2455
- const response = await (render_route(request, context, options) ||
2456
- render_page(request, context, options));
2457
-
2458
- if (response) {
2459
- // inject ETags for 200 responses
2460
- if (response.status === 200) {
2461
- if (!/(no-store|immutable)/.test(response.headers['cache-control'])) {
2462
- const etag = `"${md5(response.body)}"`;
2463
-
2464
- if (request.headers['if-none-match'] === etag) {
2465
- return {
2466
- status: 304,
2467
- headers: {},
2468
- body: null
2469
- };
2470
- }
2471
-
2472
- response.headers['etag'] = etag;
2473
- }
2474
- }
2475
-
2476
- return {
2477
- status: response.status,
2478
- headers: { ...headers, ...response.headers },
2479
- body: response.body
2480
- };
2481
- }
2482
- } catch (err) {
2483
- return {
2484
- status: 500,
2485
- headers: {},
2486
- body: options.dev ? err.stack : err.message
2487
- };
2488
- }
2489
- }
2490
-
2491
- exports.render = render;
2492
- //# sourceMappingURL=index.js.map