@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,206 +1,206 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @imports
|
|
4
|
-
*/
|
|
5
|
-
import { _with } from '@webqit/util/obj/index.js';
|
|
6
|
-
import { _isArray, _isObject, _isTypeObject, _isString, _isEmpty } from '@webqit/util/js/index.js';
|
|
7
|
-
import { wwwFormUnserialize, wwwFormSerialize } from '../util.js';
|
|
8
|
-
import { Observer } from './Runtime.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* ---------------------------
|
|
12
|
-
* The Url class
|
|
13
|
-
* ---------------------------
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export default class Url {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Constructs a new Url instance.
|
|
20
|
-
*
|
|
21
|
-
* @param object input
|
|
22
|
-
* @param object pathMappingScheme
|
|
23
|
-
*
|
|
24
|
-
* @return void
|
|
25
|
-
*/
|
|
26
|
-
constructor(input) {
|
|
27
|
-
const Self = this.constructor;
|
|
28
|
-
// -----------------------
|
|
29
|
-
// Helpers
|
|
30
|
-
var _strictEven = (a, b) => {
|
|
31
|
-
if (_isObject(a) && _isObject(b)) {
|
|
32
|
-
return _strictEven(Object.keys(a), Object.keys(b))
|
|
33
|
-
&& _strictEven(Object.values(a), Object.values(b));
|
|
34
|
-
}
|
|
35
|
-
if (_isArray(a) && _isArray(b)) {
|
|
36
|
-
return a.length === b.length
|
|
37
|
-
&& a.reduce((recieved, item, i) => recieved && item === b[i], true);
|
|
38
|
-
}
|
|
39
|
-
return a === b;
|
|
40
|
-
};
|
|
41
|
-
Observer.intercept(this, 'set', (e, prev, next) => {
|
|
42
|
-
if (e.name === 'hash' && e.value && !e.value.startsWith('#')) {
|
|
43
|
-
return next('#' + e.value);
|
|
44
|
-
}
|
|
45
|
-
if (e.name === 'search' && e.value && !e.value.startsWith('?')) {
|
|
46
|
-
return next('?' + e.value);
|
|
47
|
-
}
|
|
48
|
-
return next();
|
|
49
|
-
});
|
|
50
|
-
// -----------------------
|
|
51
|
-
// When any one of these properties change,
|
|
52
|
-
// the others are automatically derived
|
|
53
|
-
Observer.observe(this, changes => {
|
|
54
|
-
var urlObj = {};
|
|
55
|
-
var onlyHrefChanged;
|
|
56
|
-
for (var e of changes) {
|
|
57
|
-
// ----------
|
|
58
|
-
if (e.name === 'href' && e.related.length === 1) {
|
|
59
|
-
var urlObj = Self.parseUrl(e.value);
|
|
60
|
-
delete urlObj.query;
|
|
61
|
-
delete urlObj.href;
|
|
62
|
-
onlyHrefChanged = true;
|
|
63
|
-
}
|
|
64
|
-
// ----------
|
|
65
|
-
if (e.name === 'query' && (e.path.length > 1 || !e.related.includes('search'))) {
|
|
66
|
-
// "query" was updated. So we update "search"
|
|
67
|
-
var search = Self.toSearch(this.query); // Not e.value, as that might be a subtree value
|
|
68
|
-
if (search !== this.search) {
|
|
69
|
-
urlObj.search = search;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (e.name === 'search') {
|
|
73
|
-
// "search" was updated. So we update "query"
|
|
74
|
-
var query = Self.toQuery(urlObj.search || this.search); // Not e.value, as that might be a href value
|
|
75
|
-
if (!_strictEven(query, this.query)) {
|
|
76
|
-
urlObj.query = query;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (!onlyHrefChanged) {
|
|
81
|
-
var fullOrigin = this.origin,
|
|
82
|
-
usernamePassword = [ this.username, this.password ].filter(a => a);
|
|
83
|
-
if (usernamePassword.length === 2) {
|
|
84
|
-
fullOrigin = `${this.protocol}//${usernamePassword.join(':')}@${this.hostname}${(this.port ? `:${this.port}` : '')}`;
|
|
85
|
-
}
|
|
86
|
-
var href = [ fullOrigin, urlObj.pathname || this.pathname, urlObj.search || this.search, this.hash ].join('');
|
|
87
|
-
if (href !== this.href) {
|
|
88
|
-
urlObj.href = href;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!_isEmpty(urlObj)) {
|
|
92
|
-
return Observer.set(this, urlObj);
|
|
93
|
-
}
|
|
94
|
-
}, { subtree:true/*for pathmap/pathsplit/query updates*/, diff: true });
|
|
95
|
-
// -----------------------
|
|
96
|
-
// Validate e.detail
|
|
97
|
-
Observer.observe(this, changes => {
|
|
98
|
-
changes.forEach(e => {
|
|
99
|
-
if (e && e.detail) {
|
|
100
|
-
if (!_isTypeObject(e.detail)) {
|
|
101
|
-
throw new Error('"e.detail" can only be of type object.');
|
|
102
|
-
}
|
|
103
|
-
if (e.detail.request && !_isObject(e.detail.request)) {
|
|
104
|
-
throw new Error('"e.detail.request" can only be of type object.');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}, {diff: true});
|
|
109
|
-
// -----------------------
|
|
110
|
-
// Startup properties
|
|
111
|
-
Observer.set(this, _isString(input) ? Self.parseUrl(input) : Url.copy(input));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Converts the instance to string.
|
|
116
|
-
*
|
|
117
|
-
* @return string
|
|
118
|
-
*/
|
|
119
|
-
toString() {
|
|
120
|
-
return this.href;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Creates an instance from parsing an URL string
|
|
125
|
-
* or from a regular object.
|
|
126
|
-
*
|
|
127
|
-
* @param string|object href
|
|
128
|
-
*
|
|
129
|
-
* @return Url
|
|
130
|
-
*/
|
|
131
|
-
static from(href) {
|
|
132
|
-
return new this(_isObject(href) ? href : this.parseUrl(href));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Copies URL properties off
|
|
137
|
-
* the given object.
|
|
138
|
-
*
|
|
139
|
-
* @param object urlObj
|
|
140
|
-
*
|
|
141
|
-
* @return object
|
|
142
|
-
*/
|
|
143
|
-
static copy(urlObj) {
|
|
144
|
-
var url = urlProperties.reduce((obj, prop) => _with(obj, prop, urlObj[prop]), {});
|
|
145
|
-
if (!('query' in urlObj)) {
|
|
146
|
-
delete url.query;
|
|
147
|
-
}
|
|
148
|
-
return url;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Parses an URL and returns its properties
|
|
153
|
-
*
|
|
154
|
-
* @param string href
|
|
155
|
-
*
|
|
156
|
-
* @return object
|
|
157
|
-
*/
|
|
158
|
-
static parseUrl(href) {
|
|
159
|
-
var a = document.createElement('a');
|
|
160
|
-
a.href = href;
|
|
161
|
-
return this.copy(a);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Parses the input search string into a named map
|
|
166
|
-
*
|
|
167
|
-
* @param string search
|
|
168
|
-
*
|
|
169
|
-
* @return object
|
|
170
|
-
*/
|
|
171
|
-
static toQuery(search) {
|
|
172
|
-
return wwwFormUnserialize(search);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Stringifies the input query to search string.
|
|
177
|
-
*
|
|
178
|
-
* @param object query
|
|
179
|
-
*
|
|
180
|
-
* @return string
|
|
181
|
-
*/
|
|
182
|
-
static toSearch(query) {
|
|
183
|
-
var search = wwwFormSerialize(query);
|
|
184
|
-
return search ? '?' + search : '';
|
|
185
|
-
}}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* These are standard
|
|
189
|
-
* and shouldnt'/can't be modified
|
|
190
|
-
*
|
|
191
|
-
* @array
|
|
192
|
-
*/
|
|
193
|
-
const urlProperties = [
|
|
194
|
-
'protocol',
|
|
195
|
-
'username',
|
|
196
|
-
'password',
|
|
197
|
-
'host',
|
|
198
|
-
'hostname',
|
|
199
|
-
'port',
|
|
200
|
-
'origin',
|
|
201
|
-
'pathname',
|
|
202
|
-
'search',
|
|
203
|
-
'query',
|
|
204
|
-
'hash',
|
|
205
|
-
'href',
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { _with } from '@webqit/util/obj/index.js';
|
|
6
|
+
import { _isArray, _isObject, _isTypeObject, _isString, _isEmpty } from '@webqit/util/js/index.js';
|
|
7
|
+
import { wwwFormUnserialize, wwwFormSerialize } from '../util.js';
|
|
8
|
+
import { Observer } from './Runtime.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ---------------------------
|
|
12
|
+
* The Url class
|
|
13
|
+
* ---------------------------
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export default class Url {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new Url instance.
|
|
20
|
+
*
|
|
21
|
+
* @param object input
|
|
22
|
+
* @param object pathMappingScheme
|
|
23
|
+
*
|
|
24
|
+
* @return void
|
|
25
|
+
*/
|
|
26
|
+
constructor(input) {
|
|
27
|
+
const Self = this.constructor;
|
|
28
|
+
// -----------------------
|
|
29
|
+
// Helpers
|
|
30
|
+
var _strictEven = (a, b) => {
|
|
31
|
+
if (_isObject(a) && _isObject(b)) {
|
|
32
|
+
return _strictEven(Object.keys(a), Object.keys(b))
|
|
33
|
+
&& _strictEven(Object.values(a), Object.values(b));
|
|
34
|
+
}
|
|
35
|
+
if (_isArray(a) && _isArray(b)) {
|
|
36
|
+
return a.length === b.length
|
|
37
|
+
&& a.reduce((recieved, item, i) => recieved && item === b[i], true);
|
|
38
|
+
}
|
|
39
|
+
return a === b;
|
|
40
|
+
};
|
|
41
|
+
Observer.intercept(this, 'set', (e, prev, next) => {
|
|
42
|
+
if (e.name === 'hash' && e.value && !e.value.startsWith('#')) {
|
|
43
|
+
return next('#' + e.value);
|
|
44
|
+
}
|
|
45
|
+
if (e.name === 'search' && e.value && !e.value.startsWith('?')) {
|
|
46
|
+
return next('?' + e.value);
|
|
47
|
+
}
|
|
48
|
+
return next();
|
|
49
|
+
});
|
|
50
|
+
// -----------------------
|
|
51
|
+
// When any one of these properties change,
|
|
52
|
+
// the others are automatically derived
|
|
53
|
+
Observer.observe(this, changes => {
|
|
54
|
+
var urlObj = {};
|
|
55
|
+
var onlyHrefChanged;
|
|
56
|
+
for (var e of changes) {
|
|
57
|
+
// ----------
|
|
58
|
+
if (e.name === 'href' && e.related.length === 1) {
|
|
59
|
+
var urlObj = Self.parseUrl(e.value);
|
|
60
|
+
delete urlObj.query;
|
|
61
|
+
delete urlObj.href;
|
|
62
|
+
onlyHrefChanged = true;
|
|
63
|
+
}
|
|
64
|
+
// ----------
|
|
65
|
+
if (e.name === 'query' && (e.path.length > 1 || !e.related.includes('search'))) {
|
|
66
|
+
// "query" was updated. So we update "search"
|
|
67
|
+
var search = Self.toSearch(this.query); // Not e.value, as that might be a subtree value
|
|
68
|
+
if (search !== this.search) {
|
|
69
|
+
urlObj.search = search;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (e.name === 'search') {
|
|
73
|
+
// "search" was updated. So we update "query"
|
|
74
|
+
var query = Self.toQuery(urlObj.search || this.search); // Not e.value, as that might be a href value
|
|
75
|
+
if (!_strictEven(query, this.query)) {
|
|
76
|
+
urlObj.query = query;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!onlyHrefChanged) {
|
|
81
|
+
var fullOrigin = this.origin,
|
|
82
|
+
usernamePassword = [ this.username, this.password ].filter(a => a);
|
|
83
|
+
if (usernamePassword.length === 2) {
|
|
84
|
+
fullOrigin = `${this.protocol}//${usernamePassword.join(':')}@${this.hostname}${(this.port ? `:${this.port}` : '')}`;
|
|
85
|
+
}
|
|
86
|
+
var href = [ fullOrigin, urlObj.pathname || this.pathname, urlObj.search || this.search, this.hash ].join('');
|
|
87
|
+
if (href !== this.href) {
|
|
88
|
+
urlObj.href = href;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!_isEmpty(urlObj)) {
|
|
92
|
+
return Observer.set(this, urlObj);
|
|
93
|
+
}
|
|
94
|
+
}, { subtree:true/*for pathmap/pathsplit/query updates*/, diff: true });
|
|
95
|
+
// -----------------------
|
|
96
|
+
// Validate e.detail
|
|
97
|
+
Observer.observe(this, changes => {
|
|
98
|
+
changes.forEach(e => {
|
|
99
|
+
if (e && e.detail) {
|
|
100
|
+
if (!_isTypeObject(e.detail)) {
|
|
101
|
+
throw new Error('"e.detail" can only be of type object.');
|
|
102
|
+
}
|
|
103
|
+
if (e.detail.request && !_isObject(e.detail.request)) {
|
|
104
|
+
throw new Error('"e.detail.request" can only be of type object.');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}, {diff: true});
|
|
109
|
+
// -----------------------
|
|
110
|
+
// Startup properties
|
|
111
|
+
Observer.set(this, _isString(input) ? Self.parseUrl(input) : Url.copy(input));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Converts the instance to string.
|
|
116
|
+
*
|
|
117
|
+
* @return string
|
|
118
|
+
*/
|
|
119
|
+
toString() {
|
|
120
|
+
return this.href;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates an instance from parsing an URL string
|
|
125
|
+
* or from a regular object.
|
|
126
|
+
*
|
|
127
|
+
* @param string|object href
|
|
128
|
+
*
|
|
129
|
+
* @return Url
|
|
130
|
+
*/
|
|
131
|
+
static from(href) {
|
|
132
|
+
return new this(_isObject(href) ? href : this.parseUrl(href));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Copies URL properties off
|
|
137
|
+
* the given object.
|
|
138
|
+
*
|
|
139
|
+
* @param object urlObj
|
|
140
|
+
*
|
|
141
|
+
* @return object
|
|
142
|
+
*/
|
|
143
|
+
static copy(urlObj) {
|
|
144
|
+
var url = urlProperties.reduce((obj, prop) => _with(obj, prop, urlObj[prop]), {});
|
|
145
|
+
if (!('query' in urlObj)) {
|
|
146
|
+
delete url.query;
|
|
147
|
+
}
|
|
148
|
+
return url;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Parses an URL and returns its properties
|
|
153
|
+
*
|
|
154
|
+
* @param string href
|
|
155
|
+
*
|
|
156
|
+
* @return object
|
|
157
|
+
*/
|
|
158
|
+
static parseUrl(href) {
|
|
159
|
+
var a = document.createElement('a');
|
|
160
|
+
a.href = href;
|
|
161
|
+
return this.copy(a);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Parses the input search string into a named map
|
|
166
|
+
*
|
|
167
|
+
* @param string search
|
|
168
|
+
*
|
|
169
|
+
* @return object
|
|
170
|
+
*/
|
|
171
|
+
static toQuery(search) {
|
|
172
|
+
return wwwFormUnserialize(search);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Stringifies the input query to search string.
|
|
177
|
+
*
|
|
178
|
+
* @param object query
|
|
179
|
+
*
|
|
180
|
+
* @return string
|
|
181
|
+
*/
|
|
182
|
+
static toSearch(query) {
|
|
183
|
+
var search = wwwFormSerialize(query);
|
|
184
|
+
return search ? '?' + search : '';
|
|
185
|
+
}}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* These are standard
|
|
189
|
+
* and shouldnt'/can't be modified
|
|
190
|
+
*
|
|
191
|
+
* @array
|
|
192
|
+
*/
|
|
193
|
+
const urlProperties = [
|
|
194
|
+
'protocol',
|
|
195
|
+
'username',
|
|
196
|
+
'password',
|
|
197
|
+
'host',
|
|
198
|
+
'hostname',
|
|
199
|
+
'port',
|
|
200
|
+
'origin',
|
|
201
|
+
'pathname',
|
|
202
|
+
'search',
|
|
203
|
+
'query',
|
|
204
|
+
'hash',
|
|
205
|
+
'href',
|
|
206
206
|
];
|