@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
package/src/runtime-pi/util.js
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isString, _isObject, _isNumeric, _isArray } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _beforeLast, _afterLast } from '@webqit/util/str/index.js';
|
|
7
|
-
import { _from as _arrFrom } from '@webqit/util/arr/index.js';
|
|
8
|
-
if (typeof URLPattern === 'undefined') {
|
|
9
|
-
await import('urlpattern-polyfill');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* ---------------
|
|
14
|
-
* @wwwFormPathUnserializeCallback
|
|
15
|
-
* ---------------
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export function wwwFormPathUnserializeCallback(form, wwwFormPath, callback, touch = false) {
|
|
19
|
-
if (_isString(wwwFormPath) && wwwFormPath.endsWith(']')) {
|
|
20
|
-
var index = _beforeLast(_afterLast(wwwFormPath, '['), ']') || 0;
|
|
21
|
-
if (_isNumeric(index)) {
|
|
22
|
-
index = parseInt(index);
|
|
23
|
-
}
|
|
24
|
-
wwwFormPath = _beforeLast(wwwFormPath, '[') || 0;
|
|
25
|
-
if (_isNumeric(wwwFormPath)) {
|
|
26
|
-
wwwFormPath = parseInt(wwwFormPath);
|
|
27
|
-
}
|
|
28
|
-
return wwwFormPathUnserializeCallback(form, wwwFormPath, (_form, _wwwFormPath) => {
|
|
29
|
-
if (!_form[_wwwFormPath]) {
|
|
30
|
-
if (!touch) {
|
|
31
|
-
return callback();
|
|
32
|
-
}
|
|
33
|
-
_form[_wwwFormPath] = _isNumeric(index) ? [] : {};
|
|
34
|
-
}
|
|
35
|
-
return callback(_form[_wwwFormPath], index);
|
|
36
|
-
}, touch);
|
|
37
|
-
} else {
|
|
38
|
-
return callback(form, wwwFormPath);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function wwwFormSet(form, wwwFormPath, value, append = true) {
|
|
43
|
-
wwwFormPathUnserializeCallback(form, wwwFormPath, (_form, _key) => {
|
|
44
|
-
if (_isNumeric(_key)) {
|
|
45
|
-
_key = _key || _isArray(_form)
|
|
46
|
-
? _form.length
|
|
47
|
-
: Object.keys(_form).filter(_isNumeric).length;
|
|
48
|
-
_arrFrom(value, false).forEach((_value, i) => {
|
|
49
|
-
_form[_key + i] = _value;
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
_form[_key] = append && (_key in _form) ? _arrFrom(_form[_key], false).concat(value) : value;
|
|
53
|
-
}
|
|
54
|
-
}, true);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function wwwFormGet(form, wwwFormPath) {
|
|
58
|
-
return wwwFormPathUnserializeCallback(form, wwwFormPath, function(_form, _key) {
|
|
59
|
-
if (arguments.length) {
|
|
60
|
-
return _form[_key]
|
|
61
|
-
}
|
|
62
|
-
}, false);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function wwwFormUnserialize(str, target = {}, delim = '&') {
|
|
66
|
-
str = str || '';
|
|
67
|
-
(str.startsWith('?') ? str.substr(1) : str)
|
|
68
|
-
.split(delim).filter(q => q).map(q => q.split('=').map(q => q.trim()))
|
|
69
|
-
.forEach(q => wwwFormSet(target, q[0], decodeURIComponent(q[1])));
|
|
70
|
-
return target;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* ---------------
|
|
75
|
-
* @wwwFormPathSerialize
|
|
76
|
-
* ---------------
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
export function wwwFormPathSerializeCallback(wwwFormPath, value, callback, shouldSerialize = null) {
|
|
80
|
-
if ((_isObject(value) || _isArray(value)) && (!shouldSerialize || shouldSerialize(value, wwwFormPath))) {
|
|
81
|
-
var isArr = _isArray(value);
|
|
82
|
-
Object.keys(value).forEach(key => {
|
|
83
|
-
wwwFormPathSerializeCallback(`${wwwFormPath}[${key}]`, value[key], callback, shouldSerialize);
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
callback(wwwFormPath, !value && value !== 0 ? '' : value);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function wwwFormSerialize(form, delim = '&', shouldSerialize = null) {
|
|
91
|
-
var q = [];
|
|
92
|
-
Object.keys(form).forEach(key => {
|
|
93
|
-
wwwFormPathSerializeCallback(key, form[key], (_wwwFormPath, _value) => {
|
|
94
|
-
q.push(`${_wwwFormPath}=${encodeURIComponent(_value)}`);
|
|
95
|
-
}, shouldSerialize);
|
|
96
|
-
});
|
|
97
|
-
return q.join(delim);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export const path = {
|
|
101
|
-
join(/* path segments */) {
|
|
102
|
-
// Split the inputs into a list of path commands.
|
|
103
|
-
var parts = [], backsteps = 0;
|
|
104
|
-
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
105
|
-
parts = parts.concat(arguments[i].split("/"));
|
|
106
|
-
}
|
|
107
|
-
// Interpret the path commands to get the new resolved path.
|
|
108
|
-
var newParts = [];
|
|
109
|
-
for (i = 0, l = parts.length; i < l; i++) {
|
|
110
|
-
var part = parts[i];
|
|
111
|
-
// Remove leading and trailing slashes
|
|
112
|
-
// Also remove "." segments
|
|
113
|
-
if (!part || part === ".") continue;
|
|
114
|
-
// Interpret ".." to pop the last segment
|
|
115
|
-
if (part === "..") {
|
|
116
|
-
if (!newParts.length) backsteps ++;
|
|
117
|
-
else newParts.pop();
|
|
118
|
-
}
|
|
119
|
-
// Push new path segments.
|
|
120
|
-
else newParts.push(part);
|
|
121
|
-
}
|
|
122
|
-
// Preserve the initial slash if there was one.
|
|
123
|
-
if (parts[0] === "") newParts.unshift("");
|
|
124
|
-
// Turn back into a single string path.
|
|
125
|
-
return '../'.repeat(backsteps) + newParts.join("/") || (newParts.length ? "/" : ".");
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
// A simple function to get the dirname of a path
|
|
129
|
-
// Trailing slashes are ignored. Leading slash is preserved.
|
|
130
|
-
dirname(path) {
|
|
131
|
-
return this.join(path, "..");
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const urlPattern = (pattern, baseUrl = null) => ({
|
|
136
|
-
pattern: new URLPattern(pattern, baseUrl),
|
|
137
|
-
isPattern() {
|
|
138
|
-
return Object.keys(this.pattern.keys || {}).some(compName => this.pattern.keys[compName].length);
|
|
139
|
-
},
|
|
140
|
-
test(...args) { return this.pattern.test(...args) },
|
|
141
|
-
exec(...args) {
|
|
142
|
-
let components = this.pattern.exec(...args);
|
|
143
|
-
if (!components) return;
|
|
144
|
-
components.vars = Object.keys(this.pattern.keys).reduce(({ named, unnamed }, compName) => {
|
|
145
|
-
this.pattern.keys[compName].forEach(key => {
|
|
146
|
-
let value = components[compName].groups[key.name];
|
|
147
|
-
if (typeof key.name === 'number') {
|
|
148
|
-
unnamed.push(value);
|
|
149
|
-
} else {
|
|
150
|
-
named[key.name] = value;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return { named, unnamed };
|
|
154
|
-
}, { named: {}, unnamed: [] });
|
|
155
|
-
components.render = str => {
|
|
156
|
-
return str.replace(/\$(\$|[0-9A-Z]+)/gi, (a, b) => {
|
|
157
|
-
return b === '$' ? '$' : (_isNumeric(b) ? components.vars.unnamed[b - 1] : components.vars.named[b]) || '';
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return components;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _isString, _isObject, _isNumeric, _isArray } from '@webqit/util/js/index.js';
|
|
6
|
+
import { _beforeLast, _afterLast } from '@webqit/util/str/index.js';
|
|
7
|
+
import { _from as _arrFrom } from '@webqit/util/arr/index.js';
|
|
8
|
+
if (typeof URLPattern === 'undefined') {
|
|
9
|
+
await import('urlpattern-polyfill');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* ---------------
|
|
14
|
+
* @wwwFormPathUnserializeCallback
|
|
15
|
+
* ---------------
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function wwwFormPathUnserializeCallback(form, wwwFormPath, callback, touch = false) {
|
|
19
|
+
if (_isString(wwwFormPath) && wwwFormPath.endsWith(']')) {
|
|
20
|
+
var index = _beforeLast(_afterLast(wwwFormPath, '['), ']') || 0;
|
|
21
|
+
if (_isNumeric(index)) {
|
|
22
|
+
index = parseInt(index);
|
|
23
|
+
}
|
|
24
|
+
wwwFormPath = _beforeLast(wwwFormPath, '[') || 0;
|
|
25
|
+
if (_isNumeric(wwwFormPath)) {
|
|
26
|
+
wwwFormPath = parseInt(wwwFormPath);
|
|
27
|
+
}
|
|
28
|
+
return wwwFormPathUnserializeCallback(form, wwwFormPath, (_form, _wwwFormPath) => {
|
|
29
|
+
if (!_form[_wwwFormPath]) {
|
|
30
|
+
if (!touch) {
|
|
31
|
+
return callback();
|
|
32
|
+
}
|
|
33
|
+
_form[_wwwFormPath] = _isNumeric(index) ? [] : {};
|
|
34
|
+
}
|
|
35
|
+
return callback(_form[_wwwFormPath], index);
|
|
36
|
+
}, touch);
|
|
37
|
+
} else {
|
|
38
|
+
return callback(form, wwwFormPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function wwwFormSet(form, wwwFormPath, value, append = true) {
|
|
43
|
+
wwwFormPathUnserializeCallback(form, wwwFormPath, (_form, _key) => {
|
|
44
|
+
if (_isNumeric(_key)) {
|
|
45
|
+
_key = _key || _isArray(_form)
|
|
46
|
+
? _form.length
|
|
47
|
+
: Object.keys(_form).filter(_isNumeric).length;
|
|
48
|
+
_arrFrom(value, false).forEach((_value, i) => {
|
|
49
|
+
_form[_key + i] = _value;
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
_form[_key] = append && (_key in _form) ? _arrFrom(_form[_key], false).concat(value) : value;
|
|
53
|
+
}
|
|
54
|
+
}, true);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function wwwFormGet(form, wwwFormPath) {
|
|
58
|
+
return wwwFormPathUnserializeCallback(form, wwwFormPath, function(_form, _key) {
|
|
59
|
+
if (arguments.length) {
|
|
60
|
+
return _form[_key]
|
|
61
|
+
}
|
|
62
|
+
}, false);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function wwwFormUnserialize(str, target = {}, delim = '&') {
|
|
66
|
+
str = str || '';
|
|
67
|
+
(str.startsWith('?') ? str.substr(1) : str)
|
|
68
|
+
.split(delim).filter(q => q).map(q => q.split('=').map(q => q.trim()))
|
|
69
|
+
.forEach(q => wwwFormSet(target, q[0], decodeURIComponent(q[1])));
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* ---------------
|
|
75
|
+
* @wwwFormPathSerialize
|
|
76
|
+
* ---------------
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
export function wwwFormPathSerializeCallback(wwwFormPath, value, callback, shouldSerialize = null) {
|
|
80
|
+
if ((_isObject(value) || _isArray(value)) && (!shouldSerialize || shouldSerialize(value, wwwFormPath))) {
|
|
81
|
+
var isArr = _isArray(value);
|
|
82
|
+
Object.keys(value).forEach(key => {
|
|
83
|
+
wwwFormPathSerializeCallback(`${wwwFormPath}[${key}]`, value[key], callback, shouldSerialize);
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
callback(wwwFormPath, !value && value !== 0 ? '' : value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function wwwFormSerialize(form, delim = '&', shouldSerialize = null) {
|
|
91
|
+
var q = [];
|
|
92
|
+
Object.keys(form).forEach(key => {
|
|
93
|
+
wwwFormPathSerializeCallback(key, form[key], (_wwwFormPath, _value) => {
|
|
94
|
+
q.push(`${_wwwFormPath}=${encodeURIComponent(_value)}`);
|
|
95
|
+
}, shouldSerialize);
|
|
96
|
+
});
|
|
97
|
+
return q.join(delim);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const path = {
|
|
101
|
+
join(/* path segments */) {
|
|
102
|
+
// Split the inputs into a list of path commands.
|
|
103
|
+
var parts = [], backsteps = 0;
|
|
104
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
105
|
+
parts = parts.concat(arguments[i].split("/"));
|
|
106
|
+
}
|
|
107
|
+
// Interpret the path commands to get the new resolved path.
|
|
108
|
+
var newParts = [];
|
|
109
|
+
for (i = 0, l = parts.length; i < l; i++) {
|
|
110
|
+
var part = parts[i];
|
|
111
|
+
// Remove leading and trailing slashes
|
|
112
|
+
// Also remove "." segments
|
|
113
|
+
if (!part || part === ".") continue;
|
|
114
|
+
// Interpret ".." to pop the last segment
|
|
115
|
+
if (part === "..") {
|
|
116
|
+
if (!newParts.length) backsteps ++;
|
|
117
|
+
else newParts.pop();
|
|
118
|
+
}
|
|
119
|
+
// Push new path segments.
|
|
120
|
+
else newParts.push(part);
|
|
121
|
+
}
|
|
122
|
+
// Preserve the initial slash if there was one.
|
|
123
|
+
if (parts[0] === "") newParts.unshift("");
|
|
124
|
+
// Turn back into a single string path.
|
|
125
|
+
return '../'.repeat(backsteps) + newParts.join("/") || (newParts.length ? "/" : ".");
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
// A simple function to get the dirname of a path
|
|
129
|
+
// Trailing slashes are ignored. Leading slash is preserved.
|
|
130
|
+
dirname(path) {
|
|
131
|
+
return this.join(path, "..");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const urlPattern = (pattern, baseUrl = null) => ({
|
|
136
|
+
pattern: new URLPattern(pattern, baseUrl),
|
|
137
|
+
isPattern() {
|
|
138
|
+
return Object.keys(this.pattern.keys || {}).some(compName => this.pattern.keys[compName].length);
|
|
139
|
+
},
|
|
140
|
+
test(...args) { return this.pattern.test(...args) },
|
|
141
|
+
exec(...args) {
|
|
142
|
+
let components = this.pattern.exec(...args);
|
|
143
|
+
if (!components) return;
|
|
144
|
+
components.vars = Object.keys(this.pattern.keys).reduce(({ named, unnamed }, compName) => {
|
|
145
|
+
this.pattern.keys[compName].forEach(key => {
|
|
146
|
+
let value = components[compName].groups[key.name];
|
|
147
|
+
if (typeof key.name === 'number') {
|
|
148
|
+
unnamed.push(value);
|
|
149
|
+
} else {
|
|
150
|
+
named[key.name] = value;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return { named, unnamed };
|
|
154
|
+
}, { named: {}, unnamed: [] });
|
|
155
|
+
components.render = str => {
|
|
156
|
+
return str.replace(/\$(\$|[0-9A-Z]+)/gi, (a, b) => {
|
|
157
|
+
return b === '$' ? '$' : (_isNumeric(b) ? components.vars.unnamed[b - 1] : components.vars.named[b]) || '';
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return components;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _isTypeObject, _isNumeric } from '@webqit/util/js/index.js';
|
|
6
|
-
import { _before } from '@webqit/util/str/index.js';
|
|
7
|
-
import { wwwFormSet, wwwFormPathSerializeCallback } from './util.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The _Headers Mixin
|
|
11
|
-
*/
|
|
12
|
-
const xFormData = whatwagFormData => class extends whatwagFormData {
|
|
13
|
-
|
|
14
|
-
tee(callback = null) {
|
|
15
|
-
const formData1 = new this.constructor, formData2 = new this.constructor;
|
|
16
|
-
for (var [ name, value ] of this.entries()) {
|
|
17
|
-
const formDataType = formDataType(value);
|
|
18
|
-
if ((callback && callback(value, name, formDataType)) || (!callback && !formDataType)) {
|
|
19
|
-
formData1.append(name, value);
|
|
20
|
-
} else {
|
|
21
|
-
formData2.append(name, value);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return [ formData1, formData2 ];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
json(data = {}, callback = null) {
|
|
28
|
-
if (arguments.length) {
|
|
29
|
-
Object.keys(data).forEach(key => {
|
|
30
|
-
wwwFormPathSerializeCallback(key, data[key], (_wwwFormPath, _value) => {
|
|
31
|
-
if (!callback || callback(_wwwFormPath, _value, _isTypeObject(_value))) {
|
|
32
|
-
this.append(_wwwFormPath, _value);
|
|
33
|
-
}
|
|
34
|
-
}, value => !formDataType(value));
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
var jsonBuild; // We'll dynamically determine if this should be an array or an object
|
|
39
|
-
for (var [ name, value ] of this.entries()) {
|
|
40
|
-
if (!jsonBuild) {
|
|
41
|
-
jsonBuild = _isNumeric(_before(name, '[')) ? [] : {};
|
|
42
|
-
}
|
|
43
|
-
wwwFormSet(jsonBuild, name, value);
|
|
44
|
-
}
|
|
45
|
-
return jsonBuild;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default xFormData;
|
|
51
|
-
|
|
52
|
-
export const formDataType = (value, list = null) => {
|
|
53
|
-
if (!_isTypeObject(value)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const toStringTag = value[Symbol.toStringTag];
|
|
57
|
-
return (list || [
|
|
58
|
-
'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream'
|
|
59
|
-
]).reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _isTypeObject, _isNumeric } from '@webqit/util/js/index.js';
|
|
6
|
+
import { _before } from '@webqit/util/str/index.js';
|
|
7
|
+
import { wwwFormSet, wwwFormPathSerializeCallback } from './util.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The _Headers Mixin
|
|
11
|
+
*/
|
|
12
|
+
const xFormData = whatwagFormData => class extends whatwagFormData {
|
|
13
|
+
|
|
14
|
+
tee(callback = null) {
|
|
15
|
+
const formData1 = new this.constructor, formData2 = new this.constructor;
|
|
16
|
+
for (var [ name, value ] of this.entries()) {
|
|
17
|
+
const formDataType = formDataType(value);
|
|
18
|
+
if ((callback && callback(value, name, formDataType)) || (!callback && !formDataType)) {
|
|
19
|
+
formData1.append(name, value);
|
|
20
|
+
} else {
|
|
21
|
+
formData2.append(name, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [ formData1, formData2 ];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
json(data = {}, callback = null) {
|
|
28
|
+
if (arguments.length) {
|
|
29
|
+
Object.keys(data).forEach(key => {
|
|
30
|
+
wwwFormPathSerializeCallback(key, data[key], (_wwwFormPath, _value) => {
|
|
31
|
+
if (!callback || callback(_wwwFormPath, _value, _isTypeObject(_value))) {
|
|
32
|
+
this.append(_wwwFormPath, _value);
|
|
33
|
+
}
|
|
34
|
+
}, value => !formDataType(value));
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
var jsonBuild; // We'll dynamically determine if this should be an array or an object
|
|
39
|
+
for (var [ name, value ] of this.entries()) {
|
|
40
|
+
if (!jsonBuild) {
|
|
41
|
+
jsonBuild = _isNumeric(_before(name, '[')) ? [] : {};
|
|
42
|
+
}
|
|
43
|
+
wwwFormSet(jsonBuild, name, value);
|
|
44
|
+
}
|
|
45
|
+
return jsonBuild;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default xFormData;
|
|
51
|
+
|
|
52
|
+
export const formDataType = (value, list = null) => {
|
|
53
|
+
if (!_isTypeObject(value)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const toStringTag = value[Symbol.toStringTag];
|
|
57
|
+
return (list || [
|
|
58
|
+
'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream'
|
|
59
|
+
]).reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
|
|
60
60
|
};
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _after, _beforeLast } from "@webqit/util/str/index.js";
|
|
6
|
-
import { _isString, _getType, _isObject, _isFunction } from "@webqit/util/js/index.js";
|
|
7
|
-
import { _isTypeObject } from '@webqit/util/js/index.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The xHeaders Mixin
|
|
11
|
-
*/
|
|
12
|
-
const xHeaders = whatwagHeaders => class extends whatwagHeaders {
|
|
13
|
-
|
|
14
|
-
// construct
|
|
15
|
-
constructor(definition = {}) {
|
|
16
|
-
if (definition instanceof whatwagHeaders) {
|
|
17
|
-
// It's another Headers instance
|
|
18
|
-
super(definition);
|
|
19
|
-
} else {
|
|
20
|
-
super();
|
|
21
|
-
this.json(definition);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
json(headers = {}, replace = true) {
|
|
26
|
-
if (arguments.length) {
|
|
27
|
-
const _setters = getAllPropertyDescriptors(this);
|
|
28
|
-
const setters = Object.keys(_setters).reduce((list, key) => list.concat((typeof key !== 'symbol') && ('set' in _setters[key]) ? key : []), []);
|
|
29
|
-
Object.keys(headers).forEach(name => {
|
|
30
|
-
var nameCs = setters.reduce((prev, curr) => prev || (curr === name || curr.toLocaleLowerCase() === name ? curr : null), null);
|
|
31
|
-
if (nameCs) {
|
|
32
|
-
if (replace || this[nameCs] === undefined) {
|
|
33
|
-
this[nameCs] = headers[name];
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
if (replace || !this.has(name)) {
|
|
37
|
-
this.set(name, headers[name]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const _headers = {};
|
|
44
|
-
for (var [ name, value ] of this) {
|
|
45
|
-
_headers[name] = value;
|
|
46
|
-
}
|
|
47
|
-
return _headers;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
set cacheControl(value) {
|
|
51
|
-
return this.set('Cache-Control', value);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get cacheControl() {
|
|
55
|
-
return this.get('Cache-Control');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
set contentLength(value) {
|
|
59
|
-
return this.set('Content-Length', value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get contentLength() {
|
|
63
|
-
return this.get('Content-Length');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
set contentType(value) {
|
|
67
|
-
return this.set('Content-Type', value);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get contentType() {
|
|
71
|
-
return this.get('Content-Type');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default xHeaders;
|
|
77
|
-
|
|
78
|
-
function getAllPropertyDescriptors(obj) {
|
|
79
|
-
if (!obj) {
|
|
80
|
-
return Object.create(null);
|
|
81
|
-
} else {
|
|
82
|
-
const proto = Object.getPrototypeOf(obj);
|
|
83
|
-
return proto === Object.prototype ? {} : {
|
|
84
|
-
...getAllPropertyDescriptors(proto),
|
|
85
|
-
...Object.getOwnPropertyDescriptors(obj)
|
|
86
|
-
};
|
|
87
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _after, _beforeLast } from "@webqit/util/str/index.js";
|
|
6
|
+
import { _isString, _getType, _isObject, _isFunction } from "@webqit/util/js/index.js";
|
|
7
|
+
import { _isTypeObject } from '@webqit/util/js/index.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The xHeaders Mixin
|
|
11
|
+
*/
|
|
12
|
+
const xHeaders = whatwagHeaders => class extends whatwagHeaders {
|
|
13
|
+
|
|
14
|
+
// construct
|
|
15
|
+
constructor(definition = {}) {
|
|
16
|
+
if (definition instanceof whatwagHeaders) {
|
|
17
|
+
// It's another Headers instance
|
|
18
|
+
super(definition);
|
|
19
|
+
} else {
|
|
20
|
+
super();
|
|
21
|
+
this.json(definition);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
json(headers = {}, replace = true) {
|
|
26
|
+
if (arguments.length) {
|
|
27
|
+
const _setters = getAllPropertyDescriptors(this);
|
|
28
|
+
const setters = Object.keys(_setters).reduce((list, key) => list.concat((typeof key !== 'symbol') && ('set' in _setters[key]) ? key : []), []);
|
|
29
|
+
Object.keys(headers).forEach(name => {
|
|
30
|
+
var nameCs = setters.reduce((prev, curr) => prev || (curr === name || curr.toLocaleLowerCase() === name ? curr : null), null);
|
|
31
|
+
if (nameCs) {
|
|
32
|
+
if (replace || this[nameCs] === undefined) {
|
|
33
|
+
this[nameCs] = headers[name];
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
if (replace || !this.has(name)) {
|
|
37
|
+
this.set(name, headers[name]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const _headers = {};
|
|
44
|
+
for (var [ name, value ] of this) {
|
|
45
|
+
_headers[name] = value;
|
|
46
|
+
}
|
|
47
|
+
return _headers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
set cacheControl(value) {
|
|
51
|
+
return this.set('Cache-Control', value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get cacheControl() {
|
|
55
|
+
return this.get('Cache-Control');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
set contentLength(value) {
|
|
59
|
+
return this.set('Content-Length', value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get contentLength() {
|
|
63
|
+
return this.get('Content-Length');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set contentType(value) {
|
|
67
|
+
return this.set('Content-Type', value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get contentType() {
|
|
71
|
+
return this.get('Content-Type');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default xHeaders;
|
|
77
|
+
|
|
78
|
+
function getAllPropertyDescriptors(obj) {
|
|
79
|
+
if (!obj) {
|
|
80
|
+
return Object.create(null);
|
|
81
|
+
} else {
|
|
82
|
+
const proto = Object.getPrototypeOf(obj);
|
|
83
|
+
return proto === Object.prototype ? {} : {
|
|
84
|
+
...getAllPropertyDescriptors(proto),
|
|
85
|
+
...Object.getOwnPropertyDescriptors(obj)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
88
|
}
|