@webqit/webflo 0.8.77 → 0.9.1
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/package.json +5 -12
- package/src/Cli.js +131 -0
- package/src/Configurator.js +97 -0
- package/src/Context.js +76 -0
- package/src/config-pi/deployment/Env.js +69 -0
- package/src/config-pi/deployment/Layout.js +65 -0
- package/src/config-pi/deployment/Origins.js +133 -0
- package/src/config-pi/deployment/Virtualization.js +65 -0
- package/src/config-pi/deployment/index.js +18 -0
- package/src/config-pi/index.js +16 -0
- package/src/config-pi/runtime/Client.js +59 -0
- package/src/config-pi/runtime/Server.js +174 -0
- package/src/config-pi/runtime/client/Worker.js +117 -0
- package/src/config-pi/runtime/client/index.js +12 -0
- package/src/config-pi/runtime/index.js +18 -0
- package/src/config-pi/runtime/server/Headers.js +90 -0
- package/src/config-pi/runtime/server/Redirects.js +108 -0
- package/src/config-pi/runtime/server/index.js +14 -0
- package/src/config-pi/static/Manifest.js +321 -0
- package/src/config-pi/static/Ssg.js +72 -0
- package/src/config-pi/static/index.js +14 -0
- package/src/deployment-pi/index.js +10 -0
- package/src/{services → deployment-pi}/origins/index.js +88 -58
- package/src/index.js +14 -147
- package/src/{runtime → runtime-pi}/Router.js +19 -19
- package/src/runtime-pi/client/Context.js +7 -0
- package/src/{runtime → runtime-pi}/client/Router.js +2 -2
- package/src/{runtime/client/Navigator.js → runtime-pi/client/Runtime.js} +148 -103
- package/src/runtime-pi/client/RuntimeClient.js +114 -0
- package/src/{runtime → runtime-pi}/client/Storage.js +1 -1
- package/src/{runtime → runtime-pi}/client/Url.js +2 -6
- package/src/{runtime/client/WorkerClient.js → runtime-pi/client/WorkerComm.js} +2 -2
- package/src/runtime-pi/client/generate.js +242 -0
- package/src/runtime-pi/client/generate.oohtml.js +7 -0
- package/src/runtime-pi/client/index.js +18 -0
- package/src/runtime-pi/client/whatwag.js +27 -0
- package/src/runtime-pi/client/worker/Context.js +7 -0
- package/src/runtime-pi/client/worker/Worker.js +243 -0
- package/src/runtime-pi/client/worker/WorkerClient.js +46 -0
- package/src/runtime-pi/client/worker/index.js +18 -0
- package/src/runtime-pi/index.js +14 -0
- package/src/runtime-pi/server/Context.js +16 -0
- package/src/{runtime → runtime-pi}/server/Router.js +6 -6
- package/src/runtime-pi/server/Runtime.js +531 -0
- package/src/runtime-pi/server/RuntimeClient.js +103 -0
- package/src/runtime-pi/server/index.js +41 -0
- package/src/runtime-pi/server/whatwag.js +35 -0
- package/src/{runtime → runtime-pi}/util.js +0 -0
- package/src/{runtime/_FormData.js → runtime-pi/xFormData.js} +2 -2
- package/src/{runtime/_Headers.js → runtime-pi/xHeaders.js} +4 -4
- package/src/runtime-pi/xHttpEvent.js +93 -0
- package/src/runtime-pi/xHttpMessage.js +179 -0
- package/src/runtime-pi/xRequest.js +67 -0
- package/src/runtime-pi/xRequestHeaders.js +95 -0
- package/src/runtime-pi/xResponse.js +62 -0
- package/src/{runtime/_ResponseHeaders.js → runtime-pi/xResponseHeaders.js} +38 -18
- package/src/{runtime/_URL.js → runtime-pi/xURL.js} +4 -4
- package/src/runtime-pi/xfetch.js +7 -0
- package/src/{services → services-pi}/certbot/http-auth-hook.js +0 -0
- package/src/{services → services-pi}/certbot/http-cleanup-hook.js +0 -0
- package/src/{services → services-pi}/certbot/index.js +21 -15
- package/src/services-pi/index.js +9 -0
- package/src/static-pi/index.js +11 -0
- package/src/webflo.js +33 -0
- package/test/index.test.js +26 -0
- package/src/build/client/index.js +0 -261
- package/src/build/index.js +0 -5
- package/src/config/client.js +0 -191
- package/src/config/headers.js +0 -121
- package/src/config/index.js +0 -14
- package/src/config/layout.js +0 -83
- package/src/config/manifest.js +0 -341
- package/src/config/origins.js +0 -165
- package/src/config/prerendering.js +0 -100
- package/src/config/redirects.js +0 -137
- package/src/config/server.js +0 -201
- package/src/config/variables.js +0 -102
- package/src/config/vhosts.js +0 -93
- package/src/runtime/_MessageStream.js +0 -195
- package/src/runtime/_NavigationEvent.js +0 -91
- package/src/runtime/_Request.js +0 -59
- package/src/runtime/_RequestHeaders.js +0 -72
- package/src/runtime/_Response.js +0 -56
- package/src/runtime/client/NavigationEvent.js +0 -21
- package/src/runtime/client/Runtime.js +0 -126
- package/src/runtime/client/Worker.js +0 -317
- package/src/runtime/client/archive/Cache.js +0 -38
- package/src/runtime/client/archive/Http.js +0 -225
- package/src/runtime/client/archive/StdRequest.js +0 -74
- package/src/runtime/client/archive/WorkerComm.js +0 -183
- package/src/runtime/client/effects/sounds.js +0 -64
- package/src/runtime/index.js +0 -5
- package/src/runtime/server/NavigationEvent.js +0 -39
- package/src/runtime/server/Runtime.js +0 -593
- package/src/runtime/server/index.js +0 -183
- package/src/runtime/server/index.mjs +0 -10
- package/src/services/index.js +0 -6
package/src/config/vhosts.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* imports
|
|
4
|
-
*/
|
|
5
|
-
import Fs from 'fs';
|
|
6
|
-
import Path from 'path';
|
|
7
|
-
import _merge from '@webqit/util/obj/merge.js';
|
|
8
|
-
import _isObject from '@webqit/util/js/isObject.js';
|
|
9
|
-
import { DotJson, anyExists } from '@webqit/backpack/src/dotfiles/index.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Reads entries from file.
|
|
13
|
-
*
|
|
14
|
-
* @param object flags
|
|
15
|
-
* @param object layout
|
|
16
|
-
*
|
|
17
|
-
* @return object
|
|
18
|
-
*/
|
|
19
|
-
export async function read(flags = {}, layout = {}) {
|
|
20
|
-
const ext = flags.env ? `.${flags.env}` : '';
|
|
21
|
-
const configDir = Path.join(layout.ROOT || ``, `./.webqit/webflo/config/`);
|
|
22
|
-
const fileName = ext => `${configDir}/vhosts${ext}.json`;
|
|
23
|
-
const availableExt = anyExists([ext, '', '.example'], fileName);
|
|
24
|
-
const config = DotJson.read(fileName(availableExt));
|
|
25
|
-
return _merge({
|
|
26
|
-
entries: [],
|
|
27
|
-
}, config);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Writes entries to file.
|
|
32
|
-
*
|
|
33
|
-
* @param object config
|
|
34
|
-
* @param object flags
|
|
35
|
-
* @param object layout
|
|
36
|
-
*
|
|
37
|
-
* @return void
|
|
38
|
-
*/
|
|
39
|
-
export async function write(config, flags = {}, layout = {}) {
|
|
40
|
-
const ext = flags.env ? `.${flags.env}` : '';
|
|
41
|
-
const configDir = Path.join(layout.ROOT || ``, `./.webqit/webflo/config/`);
|
|
42
|
-
const fileName = ext => `${configDir}/vhosts${ext}.json`;
|
|
43
|
-
DotJson.write(config, fileName(ext));
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @match
|
|
48
|
-
*/
|
|
49
|
-
export async function match(hostname, flags = {}, layout = {}) {
|
|
50
|
-
if (_isObject(hostname)) {
|
|
51
|
-
hostname = hostname.hostname;
|
|
52
|
-
}
|
|
53
|
-
return ((await read(flags, layout)).entries || []).filter(vh => vh.host === hostname);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configures entries.
|
|
58
|
-
*
|
|
59
|
-
* @param object config
|
|
60
|
-
* @param object choices
|
|
61
|
-
* @param object layout
|
|
62
|
-
*
|
|
63
|
-
* @return Array
|
|
64
|
-
*/
|
|
65
|
-
export async function questions(config, choices = {}, layout = {}) {
|
|
66
|
-
|
|
67
|
-
// Questions
|
|
68
|
-
return [
|
|
69
|
-
{
|
|
70
|
-
name: 'entries',
|
|
71
|
-
type: 'recursive',
|
|
72
|
-
controls: {
|
|
73
|
-
name: 'vhost',
|
|
74
|
-
},
|
|
75
|
-
initial: config.entries,
|
|
76
|
-
questions: [
|
|
77
|
-
{
|
|
78
|
-
name: 'host',
|
|
79
|
-
type: 'text',
|
|
80
|
-
message: 'Enter Host name',
|
|
81
|
-
validation: ['important'],
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: 'path',
|
|
85
|
-
type: 'text',
|
|
86
|
-
message: 'Enter local path',
|
|
87
|
-
validation: ['important'],
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
];
|
|
93
|
-
};
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isArray, _isEmpty, _isNumber, _isObject, _isPlainArray, _isPlainObject, _isString } from '@webqit/util/js/index.js';
|
|
6
|
-
import { formDataType } from './_FormData.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The _Request Mixin
|
|
10
|
-
*/
|
|
11
|
-
const _MessageStream = (NativeMessageStream, Headers, FormData) => {
|
|
12
|
-
const MessageStream = class extends NativeMessageStream {
|
|
13
|
-
|
|
14
|
-
constructor(input, init = {}) {
|
|
15
|
-
var _proxy = {}, _meta = {};
|
|
16
|
-
if ((('headers' in init) && !(init instanceof Headers)) || ('_proxy' in init) || ('meta' in init)) {
|
|
17
|
-
init = { ...init };
|
|
18
|
-
if (('headers' in init) && !(init instanceof Headers)) {
|
|
19
|
-
init.headers = new Headers(init.headers);
|
|
20
|
-
}
|
|
21
|
-
if (('_proxy' in init)) {
|
|
22
|
-
_proxy = init._proxy;
|
|
23
|
-
delete init._proxy;
|
|
24
|
-
}
|
|
25
|
-
if (('meta' in init)) {
|
|
26
|
-
_meta = init.meta;
|
|
27
|
-
delete init.meta;
|
|
28
|
-
}
|
|
29
|
-
arguments[1] = init;
|
|
30
|
-
}
|
|
31
|
-
super(...arguments);
|
|
32
|
-
this._proxy = _proxy;
|
|
33
|
-
this._meta = _meta;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
clone() {
|
|
37
|
-
const clone = new this.constructor(super.clone());
|
|
38
|
-
clone._proxy = this._proxy;
|
|
39
|
-
clone._headers = this._headers;
|
|
40
|
-
clone._typedDataCache = this._typedDataCache;
|
|
41
|
-
clone._meta = this._meta;
|
|
42
|
-
return clone;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get url() {
|
|
46
|
-
return 'url' in this._proxy ? this._proxy.url : super.url;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get headers() {
|
|
50
|
-
if (!this._headers) {
|
|
51
|
-
this._headers = new Headers(super.headers);
|
|
52
|
-
}
|
|
53
|
-
return this._headers;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get original() {
|
|
57
|
-
return this._typedDataCache.original;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get originalType() {
|
|
61
|
-
return this._typedDataCache.originalType;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get meta() {
|
|
65
|
-
return this._meta || {};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async arrayBuffer() {
|
|
69
|
-
if (this._typedDataCache.arrayBuffer) {
|
|
70
|
-
return this._typedDataCache.arrayBuffer;
|
|
71
|
-
}
|
|
72
|
-
return super.arrayBuffer();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async blob() {
|
|
76
|
-
if (this._typedDataCache.blob) {
|
|
77
|
-
return this._typedDataCache.blob;
|
|
78
|
-
}
|
|
79
|
-
return super.blob();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async formData() {
|
|
83
|
-
if (this._typedDataCache.formData) {
|
|
84
|
-
return this._typedDataCache.formData;
|
|
85
|
-
}
|
|
86
|
-
const formData = await super.formData();
|
|
87
|
-
formData.tee = FormData.prototype.tee.bind(formData);
|
|
88
|
-
formData.json = FormData.prototype.json.bind(formData);
|
|
89
|
-
return formData;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async json() {
|
|
93
|
-
if (this._typedDataCache.json) {
|
|
94
|
-
return this._typedDataCache.json;
|
|
95
|
-
}
|
|
96
|
-
return super.json();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async text() {
|
|
100
|
-
if (this._typedDataCache.text) {
|
|
101
|
-
return this._typedDataCache.text;
|
|
102
|
-
}
|
|
103
|
-
return super.text();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Payload
|
|
107
|
-
data(force = false) {
|
|
108
|
-
if (!this._typedDataCache.data || force) {
|
|
109
|
-
this._typedDataCache.data = new Promise(async (resolve, reject) => {
|
|
110
|
-
var messageInstance = this, data, contentType = messageInstance.headers.get('content-type') || '';
|
|
111
|
-
var type = contentType === 'application/json' || this._typedDataCache.json ? 'json' : (
|
|
112
|
-
contentType === 'application/x-www-form-urlencoded' || contentType.startsWith('multipart/') || this._typedDataCache.formData ? 'formData' : (
|
|
113
|
-
contentType === 'text/plain' ? 'plain' : 'other'
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
try {
|
|
117
|
-
if (type === 'formData') {
|
|
118
|
-
data = (await messageInstance.formData()).json();
|
|
119
|
-
} else {
|
|
120
|
-
data = type === 'json' ? await messageInstance.json() : (
|
|
121
|
-
type === 'plain' ? await messageInstance.text() : messageInstance.body
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
resolve(data);
|
|
125
|
-
} catch(e) {
|
|
126
|
-
reject(e);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return this._typedDataCache.data;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
// ----------
|
|
135
|
-
MessageStream.Headers = Headers;
|
|
136
|
-
// ----------
|
|
137
|
-
return MessageStream;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default _MessageStream;
|
|
141
|
-
|
|
142
|
-
export function encodeBody(body, globals) {
|
|
143
|
-
const detailsObj = { body, original: body };
|
|
144
|
-
if (_isString(body) || _isNumber(body)) {
|
|
145
|
-
detailsObj.originalType = 'text';
|
|
146
|
-
detailsObj.text = body;
|
|
147
|
-
detailsObj.headers = {
|
|
148
|
-
contentLength: (body + '').length,
|
|
149
|
-
};
|
|
150
|
-
return detailsObj;
|
|
151
|
-
}
|
|
152
|
-
detailsObj.originalType = formDataType(body);
|
|
153
|
-
if ([ 'Blob', 'File' ].includes(detailsObj.originalType)) {
|
|
154
|
-
detailsObj.blob = body;
|
|
155
|
-
detailsObj.headers = {
|
|
156
|
-
contentType: body.type,
|
|
157
|
-
contentLength: body.size,
|
|
158
|
-
};
|
|
159
|
-
} else if ([ 'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer' ].includes(detailsObj.originalType)) {
|
|
160
|
-
detailsObj.arrayBuffer = body;
|
|
161
|
-
detailsObj.headers = {
|
|
162
|
-
contentLength: body.byteLength,
|
|
163
|
-
};
|
|
164
|
-
} else if (detailsObj.originalType === 'FormData') {
|
|
165
|
-
detailsObj.formData = body;
|
|
166
|
-
encodeFormData(detailsObj, body, globals);
|
|
167
|
-
} else if ((_isObject(body) && _isPlainObject(body)) || (_isArray(body) && _isPlainArray(body))) {
|
|
168
|
-
// Deserialize object while detecting if multipart
|
|
169
|
-
var hasBlobs, formData = new globals.FormData;
|
|
170
|
-
formData.json(body, (path, value, objectType) => {
|
|
171
|
-
hasBlobs = hasBlobs || objectType;
|
|
172
|
-
return true;
|
|
173
|
-
});
|
|
174
|
-
if (hasBlobs) {
|
|
175
|
-
detailsObj.formData = formData;
|
|
176
|
-
encodeFormData(detailsObj, formData, globals);
|
|
177
|
-
} else {
|
|
178
|
-
detailsObj.json = body;
|
|
179
|
-
detailsObj.body = JSON.stringify(body);
|
|
180
|
-
detailsObj.headers = {
|
|
181
|
-
contentType: 'application/json',
|
|
182
|
-
contentLength: Buffer.byteLength(detailsObj.body, 'utf8'), // Buffer.from(string).length
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
detailsObj.data = body;
|
|
186
|
-
}
|
|
187
|
-
return detailsObj;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const encodeFormData = (detailsObj, formData, globals) => {
|
|
191
|
-
if (!globals.FormDataEncoder || !globals.ReadableStream) return;
|
|
192
|
-
const encoder = new globals.FormDataEncoder(formData);
|
|
193
|
-
detailsObj.body = globals.ReadableStream.from(encoder.encode());
|
|
194
|
-
detailsObj.headers = encoder.headers;
|
|
195
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import _URL from './_URL.js';
|
|
6
|
-
import _Request from "./_Request.js";
|
|
7
|
-
import _Response from "./_Response.js";
|
|
8
|
-
import _FormData from "./_FormData.js";
|
|
9
|
-
import { _isEmpty } from '@webqit/util/js/index.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The _NavigationEvent Mixin
|
|
13
|
-
*/
|
|
14
|
-
const _NavigationEvent = globals => {
|
|
15
|
-
// ----------
|
|
16
|
-
const URL = _URL(globals.URL);
|
|
17
|
-
const Request = _Request(globals);
|
|
18
|
-
const Response = _Response(globals);
|
|
19
|
-
// ----------
|
|
20
|
-
const NavigationEvent = class {
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Initializes a new NavigationEvent instance.
|
|
24
|
-
*
|
|
25
|
-
* @param Request _request
|
|
26
|
-
* @param Object _session
|
|
27
|
-
* @param Function _sessionFactory
|
|
28
|
-
*/
|
|
29
|
-
constructor(_request, _session = {}, _sessionFactory = null) {
|
|
30
|
-
this._request = _request;
|
|
31
|
-
this._session = _session;
|
|
32
|
-
this.sessionFactory = _sessionFactory;
|
|
33
|
-
// -------
|
|
34
|
-
this.URL = URL;
|
|
35
|
-
// -------
|
|
36
|
-
this.Request = Request;
|
|
37
|
-
this.Request.sourceEvent = this;
|
|
38
|
-
// -------
|
|
39
|
-
this.Response = Response;
|
|
40
|
-
this.Response.sourceEvent = this;
|
|
41
|
-
// -------
|
|
42
|
-
this.globals = globals;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// url
|
|
46
|
-
get url() {
|
|
47
|
-
if (!this._url) {
|
|
48
|
-
this._url = new URL(this._request.url);
|
|
49
|
-
}
|
|
50
|
-
return this._url;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// request
|
|
54
|
-
get request() {
|
|
55
|
-
return this._request;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// session
|
|
59
|
-
get session() {
|
|
60
|
-
return this._session;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// RDR
|
|
64
|
-
retarget(url, init = {}) {
|
|
65
|
-
var request;
|
|
66
|
-
if (url instanceof NavigationEvent.Request) {
|
|
67
|
-
if (!_isEmpty(init)) {
|
|
68
|
-
request = new NavigationEvent.Request(url, init);
|
|
69
|
-
} else {
|
|
70
|
-
request = url;
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
init = { _proxy: {}, ...init };
|
|
74
|
-
init._proxy.url = `${this.url.origin}${url}`;
|
|
75
|
-
init._proxy.referrer = this.request.url;
|
|
76
|
-
request = new NavigationEvent.Request(this._request, init);
|
|
77
|
-
}
|
|
78
|
-
return new NavigationEvent(request, this._session, this.sessionFactory);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
// ----------
|
|
83
|
-
NavigationEvent.URL = URL;
|
|
84
|
-
NavigationEvent.Request = Request;
|
|
85
|
-
NavigationEvent.Response = Response;
|
|
86
|
-
NavigationEvent.globals = globals;
|
|
87
|
-
// ----------
|
|
88
|
-
return NavigationEvent;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default _NavigationEvent;
|
package/src/runtime/_Request.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isEmpty } from '@webqit/util/js/index.js';
|
|
6
|
-
import _MessageStream, { encodeBody } from './_MessageStream.js';
|
|
7
|
-
import _RequestHeaders from './_RequestHeaders.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The _Request Mixin
|
|
11
|
-
*/
|
|
12
|
-
const _Request = globals => class extends _MessageStream(globals.Request, _RequestHeaders(globals.Headers), globals.FormData) {
|
|
13
|
-
|
|
14
|
-
constructor(input, init = {}) {
|
|
15
|
-
var _typedDataCache = {};
|
|
16
|
-
if (input instanceof globals.Request) {
|
|
17
|
-
init = { ...init };
|
|
18
|
-
init._proxy = { ...(input._proxy || {}), ...(init._proxy || {}) };
|
|
19
|
-
if (input._typedDataCache) {
|
|
20
|
-
_typedDataCache = input._typedDataCache;
|
|
21
|
-
}
|
|
22
|
-
if (init.method && input.method !== init.method.toUpperCase() && [ 'GET', 'HEAD' ].includes(init.method.toUpperCase())) {
|
|
23
|
-
// Body must not inherited. We should now simply copy attributes
|
|
24
|
-
input = input.url;
|
|
25
|
-
[ 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity' ].forEach(attr => {
|
|
26
|
-
if (!(attr in init)) {
|
|
27
|
-
init[attr] = input[attr];
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// Init can contain "already-parsed request content"
|
|
33
|
-
if (('body' in init)) {
|
|
34
|
-
init = { ...init };
|
|
35
|
-
_typedDataCache = encodeBody(init.body, globals);
|
|
36
|
-
init.body = _typedDataCache.body;
|
|
37
|
-
}
|
|
38
|
-
if (!_isEmpty(init)) {
|
|
39
|
-
super(input, init);
|
|
40
|
-
} else {
|
|
41
|
-
super(input);
|
|
42
|
-
}
|
|
43
|
-
this._typedDataCache = _typedDataCache;
|
|
44
|
-
if (this._typedDataCache.headers) {
|
|
45
|
-
this.headers.json(this._typedDataCache.headers);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get destination() {
|
|
50
|
-
return 'destination' in this._proxy ? this._proxy.destination : super.destination;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get referrer() {
|
|
54
|
-
return 'referrer' in this._proxy ? this._proxy.referrer : super.referrer;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default _Request;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _after } from "@webqit/util/str/index.js";
|
|
6
|
-
import _Headers from './_Headers.js';
|
|
7
|
-
import { wwwFormUnserialize } from './util.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The _Headers Mixin
|
|
11
|
-
*/
|
|
12
|
-
const _RequestHeaders = NativeHeaders => class extends _Headers(NativeHeaders) {
|
|
13
|
-
|
|
14
|
-
set accept(value) {
|
|
15
|
-
return this.set('Accept', value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get accept() {
|
|
19
|
-
const list = (this.get('Accept') || '')
|
|
20
|
-
.split(',').map(a => (a = a.trim().split(';').map(a => a.trim()), [a.shift(), parseFloat((a.pop() || '1').replace('q=', ''))]))
|
|
21
|
-
.sort((a, b) => a[1] > b[1] ? -1 : 1);
|
|
22
|
-
return {
|
|
23
|
-
match(mime) {
|
|
24
|
-
mime = (mime + '').split('/');
|
|
25
|
-
return list.reduce((prev, entry) => prev || (
|
|
26
|
-
(entry = entry[0].split('/')) && [0, 1].every(i => ((mime[i] === entry[i]) || mime[i] === '*' || entry[i] === '*'))
|
|
27
|
-
), false);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set cookies(cookies) {
|
|
33
|
-
this.set('Cookie', cookies);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get cookies() {
|
|
38
|
-
if (!this._cookies) {
|
|
39
|
-
this._cookies = wwwFormUnserialize(this.get('cookie'), {}, ';');
|
|
40
|
-
}
|
|
41
|
-
return this._cookies;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
set cors(value) {
|
|
45
|
-
return this.set('Access-Control-Allow-Origin', value === true ? '*' : (value === false ? '' : value));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get cors() {
|
|
49
|
-
return this.get('Access-Control-Allow-Origin');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
set range(value) {
|
|
53
|
-
return this.set('Range', Array.isArray(value) ? `bytes=${value.join('-')}` : value);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get range() {
|
|
57
|
-
const value = this.get('Range');
|
|
58
|
-
if (!value) return;
|
|
59
|
-
const range = _after(value, 'bytes=').split('-');
|
|
60
|
-
range[0] = range[0] ? parseInt(range[0], 10) : 0;
|
|
61
|
-
range[1] = range[1] ? parseInt(range[1], 10) : 0;
|
|
62
|
-
range.clamp = max => {
|
|
63
|
-
if (range[1] > max - 1) {
|
|
64
|
-
range[1] = max - 1;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
return range;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export default _RequestHeaders;
|
package/src/runtime/_Response.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isEmpty, _isUndefined } from '@webqit/util/js/index.js';
|
|
6
|
-
import _MessageStream, { encodeBody } from './_MessageStream.js';
|
|
7
|
-
import _ResponseHeaders from './_ResponseHeaders.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The _Response Mixin
|
|
11
|
-
*/
|
|
12
|
-
const _Response = globals => class extends _MessageStream(globals.Response, _ResponseHeaders(globals.Headers), globals.FormData) {
|
|
13
|
-
|
|
14
|
-
// construct
|
|
15
|
-
constructor(body = null, init = {}) {
|
|
16
|
-
var _proxy = {}, _meta = {}, _typedDataCache = {};
|
|
17
|
-
if (arguments.length) {
|
|
18
|
-
_typedDataCache = encodeBody(body, globals);
|
|
19
|
-
body = _typedDataCache.body;
|
|
20
|
-
}
|
|
21
|
-
// Init can contain "already-parsed request content"
|
|
22
|
-
if (('_proxy' in init) || ('meta' in init)) {
|
|
23
|
-
init = { ...init };
|
|
24
|
-
if (('_proxy' in init)) {
|
|
25
|
-
_proxy = init._proxy;
|
|
26
|
-
delete init._proxy;
|
|
27
|
-
}
|
|
28
|
-
if (('meta' in init)) {
|
|
29
|
-
_meta = init.meta;
|
|
30
|
-
delete init.meta;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (!_isEmpty(init)) {
|
|
34
|
-
super(body, init);
|
|
35
|
-
} else {
|
|
36
|
-
super(body);
|
|
37
|
-
}
|
|
38
|
-
this._proxy = _proxy;
|
|
39
|
-
this._meta = _meta;
|
|
40
|
-
this._typedDataCache = _typedDataCache;
|
|
41
|
-
if (this._typedDataCache.headers) {
|
|
42
|
-
this.headers.json(this._typedDataCache.headers);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get ok() {
|
|
47
|
-
return 'ok' in this._proxy ? this._proxy.ok : super.ok;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get redirected() {
|
|
51
|
-
return 'redirected' in this._proxy ? this._proxy.redirected : super.redirected;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default _Response;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import _NavigationEvent from '../_NavigationEvent.js';
|
|
6
|
-
import _FormData from '../_FormData.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The ClientNavigationEvent class
|
|
10
|
-
*/
|
|
11
|
-
export default _NavigationEvent({
|
|
12
|
-
URL,
|
|
13
|
-
Request,
|
|
14
|
-
Response,
|
|
15
|
-
Headers,
|
|
16
|
-
FormData: _FormData(FormData),
|
|
17
|
-
File,
|
|
18
|
-
Blob,
|
|
19
|
-
ReadableStream,
|
|
20
|
-
fetch,
|
|
21
|
-
});
|