@webqit/webflo 0.11.21 → 0.11.24
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.
- package/.gitignore +7 -7
- package/LICENSE +20 -20
- package/README.md +2074 -2071
- package/package.json +82 -82
- package/src/Context.js +79 -79
- package/src/config-pi/deployment/Env.js +69 -69
- package/src/config-pi/deployment/Layout.js +65 -65
- package/src/config-pi/deployment/Origins.js +133 -133
- package/src/config-pi/deployment/Virtualization.js +65 -65
- package/src/config-pi/deployment/index.js +17 -17
- package/src/config-pi/index.js +15 -15
- package/src/config-pi/runtime/Client.js +101 -101
- package/src/config-pi/runtime/Server.js +128 -128
- package/src/config-pi/runtime/client/Worker.js +135 -135
- package/src/config-pi/runtime/client/index.js +11 -11
- package/src/config-pi/runtime/index.js +17 -17
- package/src/config-pi/runtime/server/Headers.js +77 -77
- package/src/config-pi/runtime/server/Redirects.js +73 -73
- package/src/config-pi/runtime/server/index.js +13 -13
- package/src/config-pi/static/Manifest.js +321 -321
- package/src/config-pi/static/Ssg.js +51 -51
- package/src/config-pi/static/index.js +13 -13
- package/src/deployment-pi/index.js +10 -10
- package/src/deployment-pi/origins/index.js +215 -215
- package/src/index.js +19 -19
- package/src/runtime-pi/Router.js +131 -131
- package/src/runtime-pi/client/Context.js +6 -6
- package/src/runtime-pi/client/Router.js +47 -47
- package/src/runtime-pi/client/Runtime.js +357 -341
- package/src/runtime-pi/client/RuntimeClient.js +98 -98
- package/src/runtime-pi/client/Storage.js +56 -56
- package/src/runtime-pi/client/Url.js +205 -205
- package/src/runtime-pi/client/Workport.js +163 -163
- package/src/runtime-pi/client/generate.js +467 -467
- package/src/runtime-pi/client/index.js +23 -23
- package/src/runtime-pi/client/oohtml/full.js +6 -6
- package/src/runtime-pi/client/oohtml/namespacing.js +6 -6
- package/src/runtime-pi/client/oohtml/scripting.js +7 -7
- package/src/runtime-pi/client/oohtml/templating.js +7 -7
- package/src/runtime-pi/client/whatwag.js +27 -27
- package/src/runtime-pi/client/worker/Context.js +6 -6
- package/src/runtime-pi/client/worker/Worker.js +291 -291
- package/src/runtime-pi/client/worker/WorkerClient.js +46 -46
- package/src/runtime-pi/client/worker/Workport.js +79 -79
- package/src/runtime-pi/client/worker/index.js +23 -23
- package/src/runtime-pi/index.js +13 -13
- package/src/runtime-pi/server/Context.js +15 -15
- package/src/runtime-pi/server/Router.js +157 -157
- package/src/runtime-pi/server/Runtime.js +547 -547
- package/src/runtime-pi/server/RuntimeClient.js +112 -112
- package/src/runtime-pi/server/index.js +23 -23
- package/src/runtime-pi/server/whatwag.js +35 -35
- package/src/runtime-pi/util.js +162 -162
- package/src/runtime-pi/xFormData.js +59 -59
- package/src/runtime-pi/xHeaders.js +87 -87
- package/src/runtime-pi/xHttpEvent.js +92 -92
- package/src/runtime-pi/xHttpMessage.js +179 -179
- package/src/runtime-pi/xRequest.js +73 -73
- package/src/runtime-pi/xRequestHeaders.js +94 -94
- package/src/runtime-pi/xResponse.js +68 -68
- package/src/runtime-pi/xResponseHeaders.js +109 -109
- package/src/runtime-pi/xURL.js +110 -110
- package/src/runtime-pi/xfetch.js +6 -6
- package/src/services-pi/certbot/http-auth-hook.js +22 -22
- package/src/services-pi/certbot/http-cleanup-hook.js +22 -22
- package/src/services-pi/certbot/index.js +79 -79
- package/src/services-pi/index.js +8 -8
- package/src/static-pi/index.js +10 -10
- package/src/webflo.js +31 -31
- package/test/index.test.js +26 -25
- package/test/site/package.json +9 -9
- package/test/site/public/bundle.html +5 -5
- package/test/site/public/bundle.html.json +3 -3
- package/test/site/public/bundle.js +2 -2
- package/test/site/public/bundle.webflo.js +15 -15
- package/test/site/public/index.html +29 -29
- package/test/site/public/index1.html +34 -34
- package/test/site/public/page-2/bundle.html +4 -4
- package/test/site/public/page-2/bundle.js +2 -2
- package/test/site/public/page-2/index.html +45 -45
- package/test/site/public/page-2/main.html +2 -2
- package/test/site/public/page-4/subpage/bundle.js +2 -2
- package/test/site/public/page-4/subpage/index.html +30 -30
- package/test/site/public/sparoots.json +4 -4
- package/test/site/public/worker.js +3 -3
- package/test/site/server/index.js +15 -15
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The xRequest Mixin
|
|
9
|
-
*/
|
|
10
|
-
const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHttpMessage(whatwagRequest, Headers, FormData) {
|
|
11
|
-
|
|
12
|
-
constructor(input, init = {}) {
|
|
13
|
-
init = { ...init };
|
|
14
|
-
let bodyAttrs = {};
|
|
15
|
-
if ((input instanceof whatwagRequest)) {
|
|
16
|
-
// On method change...
|
|
17
|
-
if (init.method && input.method !== init.method.toUpperCase() && [ 'GET', 'HEAD' ].includes(init.method.toUpperCase())) {
|
|
18
|
-
// Body must not be inherited.
|
|
19
|
-
input = input.url;
|
|
20
|
-
// We should now simply copy attributes
|
|
21
|
-
[ 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity' ].forEach(attr => {
|
|
22
|
-
if (!(attr in init)) {
|
|
23
|
-
init[attr] = input[attr];
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
// Inherit bodyAttrs
|
|
28
|
-
bodyAttrs = input.bodyAttrs || {};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
// Init can contain "already-parsed request content"
|
|
32
|
-
if (('body' in init)) {
|
|
33
|
-
bodyAttrs = encodeBody(init.body, FormData, Blob);
|
|
34
|
-
init.body = bodyAttrs.body;
|
|
35
|
-
}
|
|
36
|
-
let isNavigateMode;
|
|
37
|
-
if (init.mode === 'navigate') {
|
|
38
|
-
isNavigateMode = true;
|
|
39
|
-
init = { ...init };
|
|
40
|
-
delete init.mode;
|
|
41
|
-
}
|
|
42
|
-
super(input, init, bodyAttrs);
|
|
43
|
-
if (isNavigateMode) {
|
|
44
|
-
// Through the backdoor
|
|
45
|
-
this.attrs.mode = 'navigate';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get mode() {
|
|
50
|
-
return 'mode' in this.attrs ? this.attrs.mode : super.mode;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get cache() {
|
|
54
|
-
return 'cache' in this.attrs ? this.attrs.cache : super.cache;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get destination() {
|
|
58
|
-
return 'destination' in this.attrs ? this.attrs.destination : super.destination;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get referrer() {
|
|
62
|
-
return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static compat(request, url = null) {
|
|
66
|
-
if (request instanceof whatwagRequest) {
|
|
67
|
-
return Object.setPrototypeOf(request, new this);
|
|
68
|
-
}
|
|
69
|
-
return new this(url, request);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The xRequest Mixin
|
|
9
|
+
*/
|
|
10
|
+
const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHttpMessage(whatwagRequest, Headers, FormData) {
|
|
11
|
+
|
|
12
|
+
constructor(input, init = {}) {
|
|
13
|
+
init = { ...init };
|
|
14
|
+
let bodyAttrs = {};
|
|
15
|
+
if ((input instanceof whatwagRequest)) {
|
|
16
|
+
// On method change...
|
|
17
|
+
if (init.method && input.method !== init.method.toUpperCase() && [ 'GET', 'HEAD' ].includes(init.method.toUpperCase())) {
|
|
18
|
+
// Body must not be inherited.
|
|
19
|
+
input = input.url;
|
|
20
|
+
// We should now simply copy attributes
|
|
21
|
+
[ 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity' ].forEach(attr => {
|
|
22
|
+
if (!(attr in init)) {
|
|
23
|
+
init[attr] = input[attr];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
// Inherit bodyAttrs
|
|
28
|
+
bodyAttrs = input.bodyAttrs || {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Init can contain "already-parsed request content"
|
|
32
|
+
if (('body' in init)) {
|
|
33
|
+
bodyAttrs = encodeBody(init.body, FormData, Blob);
|
|
34
|
+
init.body = bodyAttrs.body;
|
|
35
|
+
}
|
|
36
|
+
let isNavigateMode;
|
|
37
|
+
if (init.mode === 'navigate') {
|
|
38
|
+
isNavigateMode = true;
|
|
39
|
+
init = { ...init };
|
|
40
|
+
delete init.mode;
|
|
41
|
+
}
|
|
42
|
+
super(input, init, bodyAttrs);
|
|
43
|
+
if (isNavigateMode) {
|
|
44
|
+
// Through the backdoor
|
|
45
|
+
this.attrs.mode = 'navigate';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get mode() {
|
|
50
|
+
return 'mode' in this.attrs ? this.attrs.mode : super.mode;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get cache() {
|
|
54
|
+
return 'cache' in this.attrs ? this.attrs.cache : super.cache;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get destination() {
|
|
58
|
+
return 'destination' in this.attrs ? this.attrs.destination : super.destination;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get referrer() {
|
|
62
|
+
return 'referrer' in this.attrs ? this.attrs.referrer : super.referrer;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static compat(request, url = null) {
|
|
66
|
+
if (request instanceof whatwagRequest) {
|
|
67
|
+
return Object.setPrototypeOf(request, new this);
|
|
68
|
+
}
|
|
69
|
+
return new this(url, request);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
};
|
|
73
|
+
|
|
74
74
|
export default xRequest;
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _after } from "@webqit/util/str/index.js";
|
|
6
|
-
import { _from as _arrFrom } from "@webqit/util/arr/index.js";
|
|
7
|
-
import { _getType, _isObject } from "@webqit/util/js/index.js";
|
|
8
|
-
import { wwwFormUnserialize, wwwFormSerialize } from './util.js';
|
|
9
|
-
import xHeaders from './xHeaders.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The xHeaders Mixin
|
|
13
|
-
*/
|
|
14
|
-
const xRequestHeaders = NativeHeaders => class extends xHeaders(NativeHeaders) {
|
|
15
|
-
|
|
16
|
-
set accept(value) {
|
|
17
|
-
return this.set('Accept', value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get accept() {
|
|
21
|
-
const accept = this.get('Accept');
|
|
22
|
-
const list = accept && accept.split(',').map(a => (a = a.trim().split(';').map(a => a.trim()), [a.shift(), parseFloat((a.pop() || '1').replace('q=', ''))]))
|
|
23
|
-
.sort((a, b) => a[1] > b[1] ? -1 : 1) || [];
|
|
24
|
-
return {
|
|
25
|
-
match(mime) {
|
|
26
|
-
mime = (mime + '').split('/');
|
|
27
|
-
return list.reduce((prev, entry) => prev || (
|
|
28
|
-
(entry = entry[0].split('/')) && [0, 1].every(i => ((mime[i] === entry[i]) || mime[i] === '*' || entry[i] === '*'))
|
|
29
|
-
), false);
|
|
30
|
-
},
|
|
31
|
-
toString() {
|
|
32
|
-
return accept;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set cookies(cookieJar) {
|
|
38
|
-
if (!_isObject(cookieJar)) {
|
|
39
|
-
throw new Error(`Cookies must be of type object. Received type: ${_getType(cookieJar)}.`);
|
|
40
|
-
}
|
|
41
|
-
this.set('Cookie', wwwFormSerialize(cookieJar, ';'));
|
|
42
|
-
this._cookies = null;
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get cookies() {
|
|
47
|
-
if (!this._cookies) {
|
|
48
|
-
this._cookies = wwwFormUnserialize(this.get('cookie'), {}, ';');
|
|
49
|
-
}
|
|
50
|
-
return this._cookies;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set range(value) {
|
|
54
|
-
let rangeArr = [];
|
|
55
|
-
_arrFrom(value).forEach((range, i) => {
|
|
56
|
-
let rangeStr = Array.isArray(range) ? range.join('-') : range + '';
|
|
57
|
-
if (i === 0 && !rangeStr.includes('bytes=')) {
|
|
58
|
-
rangeStr = `bytes=${rangeStr}`;
|
|
59
|
-
}
|
|
60
|
-
rangeArr.push(rangeStr);
|
|
61
|
-
});
|
|
62
|
-
return this.set('Range', rangeArr.join(', '));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get range() {
|
|
66
|
-
const value = this.get('Range');
|
|
67
|
-
if (!value) return;
|
|
68
|
-
const rangeArr = _after(value, 'bytes=').split(',').map(rangeStr => {
|
|
69
|
-
let range = rangeStr.trim().split('-');
|
|
70
|
-
range[0] = range[0] ? parseInt(range[0], 10) : undefined;
|
|
71
|
-
if (range[1]) {
|
|
72
|
-
range[1] = parseInt(range[1], 10);
|
|
73
|
-
}
|
|
74
|
-
range.clamp = max => {
|
|
75
|
-
if (range[1] > max - 1 || range[1] === undefined) {
|
|
76
|
-
range[1] = max - 1;
|
|
77
|
-
}
|
|
78
|
-
if (range[0] === undefined) range[0] = range[1] ? max - range[1] - 1 : 0;
|
|
79
|
-
};
|
|
80
|
-
return range;
|
|
81
|
-
});
|
|
82
|
-
return rangeArr;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
set cors(value) {
|
|
86
|
-
return this.set('Access-Control-Allow-Origin', value === true ? '*' : (value === false ? '' : value));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get cors() {
|
|
90
|
-
return this.get('Access-Control-Allow-Origin');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _after } from "@webqit/util/str/index.js";
|
|
6
|
+
import { _from as _arrFrom } from "@webqit/util/arr/index.js";
|
|
7
|
+
import { _getType, _isObject } from "@webqit/util/js/index.js";
|
|
8
|
+
import { wwwFormUnserialize, wwwFormSerialize } from './util.js';
|
|
9
|
+
import xHeaders from './xHeaders.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The xHeaders Mixin
|
|
13
|
+
*/
|
|
14
|
+
const xRequestHeaders = NativeHeaders => class extends xHeaders(NativeHeaders) {
|
|
15
|
+
|
|
16
|
+
set accept(value) {
|
|
17
|
+
return this.set('Accept', value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get accept() {
|
|
21
|
+
const accept = this.get('Accept');
|
|
22
|
+
const list = accept && accept.split(',').map(a => (a = a.trim().split(';').map(a => a.trim()), [a.shift(), parseFloat((a.pop() || '1').replace('q=', ''))]))
|
|
23
|
+
.sort((a, b) => a[1] > b[1] ? -1 : 1) || [];
|
|
24
|
+
return {
|
|
25
|
+
match(mime) {
|
|
26
|
+
mime = (mime + '').split('/');
|
|
27
|
+
return list.reduce((prev, entry) => prev || (
|
|
28
|
+
(entry = entry[0].split('/')) && [0, 1].every(i => ((mime[i] === entry[i]) || mime[i] === '*' || entry[i] === '*'))
|
|
29
|
+
), false);
|
|
30
|
+
},
|
|
31
|
+
toString() {
|
|
32
|
+
return accept;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set cookies(cookieJar) {
|
|
38
|
+
if (!_isObject(cookieJar)) {
|
|
39
|
+
throw new Error(`Cookies must be of type object. Received type: ${_getType(cookieJar)}.`);
|
|
40
|
+
}
|
|
41
|
+
this.set('Cookie', wwwFormSerialize(cookieJar, ';'));
|
|
42
|
+
this._cookies = null;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get cookies() {
|
|
47
|
+
if (!this._cookies) {
|
|
48
|
+
this._cookies = wwwFormUnserialize(this.get('cookie'), {}, ';');
|
|
49
|
+
}
|
|
50
|
+
return this._cookies;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set range(value) {
|
|
54
|
+
let rangeArr = [];
|
|
55
|
+
_arrFrom(value).forEach((range, i) => {
|
|
56
|
+
let rangeStr = Array.isArray(range) ? range.join('-') : range + '';
|
|
57
|
+
if (i === 0 && !rangeStr.includes('bytes=')) {
|
|
58
|
+
rangeStr = `bytes=${rangeStr}`;
|
|
59
|
+
}
|
|
60
|
+
rangeArr.push(rangeStr);
|
|
61
|
+
});
|
|
62
|
+
return this.set('Range', rangeArr.join(', '));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get range() {
|
|
66
|
+
const value = this.get('Range');
|
|
67
|
+
if (!value) return;
|
|
68
|
+
const rangeArr = _after(value, 'bytes=').split(',').map(rangeStr => {
|
|
69
|
+
let range = rangeStr.trim().split('-');
|
|
70
|
+
range[0] = range[0] ? parseInt(range[0], 10) : undefined;
|
|
71
|
+
if (range[1]) {
|
|
72
|
+
range[1] = parseInt(range[1], 10);
|
|
73
|
+
}
|
|
74
|
+
range.clamp = max => {
|
|
75
|
+
if (range[1] > max - 1 || range[1] === undefined) {
|
|
76
|
+
range[1] = max - 1;
|
|
77
|
+
}
|
|
78
|
+
if (range[0] === undefined) range[0] = range[1] ? max - range[1] - 1 : 0;
|
|
79
|
+
};
|
|
80
|
+
return range;
|
|
81
|
+
});
|
|
82
|
+
return rangeArr;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
set cors(value) {
|
|
86
|
+
return this.set('Access-Control-Allow-Origin', value === true ? '*' : (value === false ? '' : value));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get cors() {
|
|
90
|
+
return this.get('Access-Control-Allow-Origin');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
95
|
export default xRequestHeaders;
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The xResponse Mixin
|
|
9
|
-
*/
|
|
10
|
-
const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xHttpMessage(whatwagResponse, Headers, FormData) {
|
|
11
|
-
|
|
12
|
-
// construct
|
|
13
|
-
constructor(body = null, init = {}) {
|
|
14
|
-
let bodyAttrs = {}, isResponseInput;
|
|
15
|
-
if (arguments.length) {
|
|
16
|
-
if (body instanceof whatwagResponse) {
|
|
17
|
-
isResponseInput = body;
|
|
18
|
-
// Inherit init
|
|
19
|
-
init = { status: body.status, statusText: body.statusText, headers: body.headers, ...init };
|
|
20
|
-
if (body.status === 0) delete init.status;
|
|
21
|
-
// Inherit bodyAttrs and body
|
|
22
|
-
bodyAttrs = body.bodyAttrs || {};
|
|
23
|
-
body = body.body;
|
|
24
|
-
} else {
|
|
25
|
-
bodyAttrs = encodeBody(body, FormData, Blob);
|
|
26
|
-
body = bodyAttrs.body;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
super(body, init, bodyAttrs);
|
|
30
|
-
if (isResponseInput) {
|
|
31
|
-
// Through the backdoor
|
|
32
|
-
this.attrs.url = isResponseInput.url;
|
|
33
|
-
this.attrs.ok = isResponseInput.ok;
|
|
34
|
-
this.attrs.status = isResponseInput.status; // In case it was earlier deleted
|
|
35
|
-
this.attrs.type = isResponseInput.type;
|
|
36
|
-
this.attrs.redirected = isResponseInput.redirected;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get ok() {
|
|
41
|
-
return 'ok' in this.attrs ? this.attrs.ok : super.ok;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get status() {
|
|
45
|
-
return 'status' in this.attrs ? this.attrs.status : super.status;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get statusText() {
|
|
49
|
-
return 'statusText' in this.attrs ? this.attrs.statusText : super.statusText;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get type() {
|
|
53
|
-
return 'type' in this.attrs ? this.attrs.type : super.type;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get redirected() {
|
|
57
|
-
return 'redirected' in this.attrs ? this.attrs.redirected : super.redirected;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static compat(response) {
|
|
61
|
-
if (response instanceof whatwagResponse) {
|
|
62
|
-
return Object.setPrototypeOf(response, new this);
|
|
63
|
-
}
|
|
64
|
-
return new this(response);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The xResponse Mixin
|
|
9
|
+
*/
|
|
10
|
+
const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xHttpMessage(whatwagResponse, Headers, FormData) {
|
|
11
|
+
|
|
12
|
+
// construct
|
|
13
|
+
constructor(body = null, init = {}) {
|
|
14
|
+
let bodyAttrs = {}, isResponseInput;
|
|
15
|
+
if (arguments.length) {
|
|
16
|
+
if (body instanceof whatwagResponse) {
|
|
17
|
+
isResponseInput = body;
|
|
18
|
+
// Inherit init
|
|
19
|
+
init = { status: body.status, statusText: body.statusText, headers: body.headers, ...init };
|
|
20
|
+
if (body.status === 0) delete init.status;
|
|
21
|
+
// Inherit bodyAttrs and body
|
|
22
|
+
bodyAttrs = body.bodyAttrs || {};
|
|
23
|
+
body = body.body;
|
|
24
|
+
} else {
|
|
25
|
+
bodyAttrs = encodeBody(body, FormData, Blob);
|
|
26
|
+
body = bodyAttrs.body;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
super(body, init, bodyAttrs);
|
|
30
|
+
if (isResponseInput) {
|
|
31
|
+
// Through the backdoor
|
|
32
|
+
this.attrs.url = isResponseInput.url;
|
|
33
|
+
this.attrs.ok = isResponseInput.ok;
|
|
34
|
+
this.attrs.status = isResponseInput.status; // In case it was earlier deleted
|
|
35
|
+
this.attrs.type = isResponseInput.type;
|
|
36
|
+
this.attrs.redirected = isResponseInput.redirected;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get ok() {
|
|
41
|
+
return 'ok' in this.attrs ? this.attrs.ok : super.ok;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get status() {
|
|
45
|
+
return 'status' in this.attrs ? this.attrs.status : super.status;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get statusText() {
|
|
49
|
+
return 'statusText' in this.attrs ? this.attrs.statusText : super.statusText;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get type() {
|
|
53
|
+
return 'type' in this.attrs ? this.attrs.type : super.type;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get redirected() {
|
|
57
|
+
return 'redirected' in this.attrs ? this.attrs.redirected : super.redirected;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static compat(response) {
|
|
61
|
+
if (response instanceof whatwagResponse) {
|
|
62
|
+
return Object.setPrototypeOf(response, new this);
|
|
63
|
+
}
|
|
64
|
+
return new this(response);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
};
|
|
68
|
+
|
|
69
69
|
export default xResponse;
|