@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.
Files changed (86) hide show
  1. package/.gitignore +7 -7
  2. package/LICENSE +20 -20
  3. package/README.md +2074 -2071
  4. package/package.json +82 -82
  5. package/src/Context.js +79 -79
  6. package/src/config-pi/deployment/Env.js +69 -69
  7. package/src/config-pi/deployment/Layout.js +65 -65
  8. package/src/config-pi/deployment/Origins.js +133 -133
  9. package/src/config-pi/deployment/Virtualization.js +65 -65
  10. package/src/config-pi/deployment/index.js +17 -17
  11. package/src/config-pi/index.js +15 -15
  12. package/src/config-pi/runtime/Client.js +101 -101
  13. package/src/config-pi/runtime/Server.js +128 -128
  14. package/src/config-pi/runtime/client/Worker.js +135 -135
  15. package/src/config-pi/runtime/client/index.js +11 -11
  16. package/src/config-pi/runtime/index.js +17 -17
  17. package/src/config-pi/runtime/server/Headers.js +77 -77
  18. package/src/config-pi/runtime/server/Redirects.js +73 -73
  19. package/src/config-pi/runtime/server/index.js +13 -13
  20. package/src/config-pi/static/Manifest.js +321 -321
  21. package/src/config-pi/static/Ssg.js +51 -51
  22. package/src/config-pi/static/index.js +13 -13
  23. package/src/deployment-pi/index.js +10 -10
  24. package/src/deployment-pi/origins/index.js +215 -215
  25. package/src/index.js +19 -19
  26. package/src/runtime-pi/Router.js +131 -131
  27. package/src/runtime-pi/client/Context.js +6 -6
  28. package/src/runtime-pi/client/Router.js +47 -47
  29. package/src/runtime-pi/client/Runtime.js +357 -341
  30. package/src/runtime-pi/client/RuntimeClient.js +98 -98
  31. package/src/runtime-pi/client/Storage.js +56 -56
  32. package/src/runtime-pi/client/Url.js +205 -205
  33. package/src/runtime-pi/client/Workport.js +163 -163
  34. package/src/runtime-pi/client/generate.js +467 -467
  35. package/src/runtime-pi/client/index.js +23 -23
  36. package/src/runtime-pi/client/oohtml/full.js +6 -6
  37. package/src/runtime-pi/client/oohtml/namespacing.js +6 -6
  38. package/src/runtime-pi/client/oohtml/scripting.js +7 -7
  39. package/src/runtime-pi/client/oohtml/templating.js +7 -7
  40. package/src/runtime-pi/client/whatwag.js +27 -27
  41. package/src/runtime-pi/client/worker/Context.js +6 -6
  42. package/src/runtime-pi/client/worker/Worker.js +291 -291
  43. package/src/runtime-pi/client/worker/WorkerClient.js +46 -46
  44. package/src/runtime-pi/client/worker/Workport.js +79 -79
  45. package/src/runtime-pi/client/worker/index.js +23 -23
  46. package/src/runtime-pi/index.js +13 -13
  47. package/src/runtime-pi/server/Context.js +15 -15
  48. package/src/runtime-pi/server/Router.js +157 -157
  49. package/src/runtime-pi/server/Runtime.js +547 -547
  50. package/src/runtime-pi/server/RuntimeClient.js +112 -112
  51. package/src/runtime-pi/server/index.js +23 -23
  52. package/src/runtime-pi/server/whatwag.js +35 -35
  53. package/src/runtime-pi/util.js +162 -162
  54. package/src/runtime-pi/xFormData.js +59 -59
  55. package/src/runtime-pi/xHeaders.js +87 -87
  56. package/src/runtime-pi/xHttpEvent.js +92 -92
  57. package/src/runtime-pi/xHttpMessage.js +179 -179
  58. package/src/runtime-pi/xRequest.js +73 -73
  59. package/src/runtime-pi/xRequestHeaders.js +94 -94
  60. package/src/runtime-pi/xResponse.js +68 -68
  61. package/src/runtime-pi/xResponseHeaders.js +109 -109
  62. package/src/runtime-pi/xURL.js +110 -110
  63. package/src/runtime-pi/xfetch.js +6 -6
  64. package/src/services-pi/certbot/http-auth-hook.js +22 -22
  65. package/src/services-pi/certbot/http-cleanup-hook.js +22 -22
  66. package/src/services-pi/certbot/index.js +79 -79
  67. package/src/services-pi/index.js +8 -8
  68. package/src/static-pi/index.js +10 -10
  69. package/src/webflo.js +31 -31
  70. package/test/index.test.js +26 -25
  71. package/test/site/package.json +9 -9
  72. package/test/site/public/bundle.html +5 -5
  73. package/test/site/public/bundle.html.json +3 -3
  74. package/test/site/public/bundle.js +2 -2
  75. package/test/site/public/bundle.webflo.js +15 -15
  76. package/test/site/public/index.html +29 -29
  77. package/test/site/public/index1.html +34 -34
  78. package/test/site/public/page-2/bundle.html +4 -4
  79. package/test/site/public/page-2/bundle.js +2 -2
  80. package/test/site/public/page-2/index.html +45 -45
  81. package/test/site/public/page-2/main.html +2 -2
  82. package/test/site/public/page-4/subpage/bundle.js +2 -2
  83. package/test/site/public/page-4/subpage/index.html +30 -30
  84. package/test/site/public/sparoots.json +4 -4
  85. package/test/site/public/worker.js +3 -3
  86. package/test/site/server/index.js +15 -15
@@ -1,131 +1,131 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _isString, _isFunction, _isArray } from '@webqit/util/js/index.js';
6
- import { _from as _arrFrom } from '@webqit/util/arr/index.js';
7
-
8
- /**
9
- * ---------------------------
10
- * The Router class
11
- * ---------------------------
12
- */
13
-
14
- export default class Router {
15
-
16
- /**
17
- * Constructs a new Router instance
18
- * over route definitions.
19
- *
20
- * @param Context cx
21
- * @param String|Array path
22
- *
23
- * @return void
24
- */
25
- constructor(cx, path) {
26
- this.cx = cx;
27
- this.path = _isArray(path) ? path : (path + '').split('/').filter(a => a);
28
- }
29
-
30
- /**
31
- * Performs dynamic routing.
32
- *
33
- * @param array|string method
34
- * @param Object event
35
- * @param any arg
36
- * @param function _default
37
- * @param function remoteFetch
38
- *
39
- * @return object
40
- */
41
- async route(method, event, arg, _default, remoteFetch = null) {
42
-
43
- const $this = this;
44
- const $runtime = this.cx.runtime;
45
-
46
- // ----------------
47
- // The loop
48
- // ----------------
49
- const next = async function(thisTick) {
50
- const thisContext = { runtime: $runtime };
51
- if (!thisTick.trail || thisTick.trail.length < thisTick.destination.length) {
52
- thisTick = await $this.readTick(thisTick);
53
- // -------------
54
- thisContext.pathname = `/${thisTick.trail.join('/')}`;
55
- thisContext.stepname = thisTick.trail[thisTick.trail.length - 1];
56
- $this.finalizeHandlerContext(thisContext, thisTick);
57
- // -------------
58
- if (thisTick.exports) {
59
- // Broadcast any hints exported by handler
60
- if (thisTick.exports.hints) { await event.port.post({ ...thisTick.exports.hints, $type: 'handler:hints' }); }
61
- const methods = _arrFrom(thisTick.method);
62
- const handler = _isFunction(thisTick.exports) && methods.includes('default') ? thisTick.exports : methods.reduce((_handler, name) => _handler || thisTick.exports[name.toLowerCase()], null);
63
- if (handler) {
64
- // -------------
65
- // Dynamic response
66
- // -------------
67
- const _next = async (..._args) => {
68
- const nextTick = { ...thisTick, arg: _args[0] };
69
- if (_args.length > 1) {
70
- var _url = _args[1], _request, requestInit = { ...(_args[2] || {}) };
71
- if (_args[1] instanceof nextTick.event.Request) {
72
- _request = _args[1];
73
- _url = _request.url;
74
- } else if (!_isString(_url)) {
75
- throw new Error('Router redirect url must be a string!');
76
- }
77
- var newDestination = _url.startsWith('/') ? _url : $this.pathJoin(`/${thisTick.trail.join('/')}`, _url);
78
- if (newDestination.startsWith('../')) {
79
- throw new Error('Router redirect cannot traverse beyond the routing directory! (' + _url + ' >> ' + newDestination + ')');
80
- }
81
- if (requestInit.method) {
82
- nextTick.method = requestInit.method;
83
- if (_isArray(requestInit.method)) {
84
- requestInit.method = requestInit.method[0];
85
- }
86
- }
87
- if (_request) {
88
- nextTick.event = thisTick.event.retarget(_request, { ...requestInit, _proxy: { url: newDestination/** non-standard but works */ } });
89
- } else {
90
- nextTick.event = thisTick.event.retarget(newDestination, requestInit);
91
- }
92
-
93
- nextTick.source = thisTick.destination.join('/');
94
- nextTick.destination = newDestination.split('?').shift().split('/').map(a => a.trim()).filter(a => a);
95
- nextTick.trail = _args[1].startsWith('/') ? [] : thisTick.trail.reduce((_commonRoot, _seg, i) => _commonRoot.length === i && _seg === nextTick.destination[i] ? _commonRoot.concat(_seg) : _commonRoot, []);
96
- nextTick.trailOnFile = thisTick.trailOnFile.slice(0, nextTick.trail.length);
97
- }
98
- return next(nextTick);
99
- };
100
- // -------------
101
- const nextPathname = thisTick.destination.slice(thisTick.trail.length);
102
- _next.pathname = nextPathname.join('/');
103
- _next.stepname = nextPathname[0];
104
- // -------------
105
- return await handler.call(thisContext, thisTick.event, thisTick.arg, _next/*next*/, remoteFetch);
106
- }
107
- // Handler not found but exports found
108
- return next(thisTick);
109
- } else if ((thisTick.currentSegmentOnFile || {}).dirExists) {
110
- // Exports not found but directory found
111
- return next(thisTick);
112
- }
113
- }
114
- // -------------
115
- // Local file
116
- // -------------
117
- if (_default) {
118
- return await _default.call(thisContext, thisTick.event, thisTick.arg, remoteFetch);
119
- }
120
- };
121
-
122
- return next({
123
- destination: this.path,
124
- event,
125
- method,
126
- arg,
127
- });
128
-
129
- }
130
-
131
- }
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { _isString, _isFunction, _isArray } from '@webqit/util/js/index.js';
6
+ import { _from as _arrFrom } from '@webqit/util/arr/index.js';
7
+
8
+ /**
9
+ * ---------------------------
10
+ * The Router class
11
+ * ---------------------------
12
+ */
13
+
14
+ export default class Router {
15
+
16
+ /**
17
+ * Constructs a new Router instance
18
+ * over route definitions.
19
+ *
20
+ * @param Context cx
21
+ * @param String|Array path
22
+ *
23
+ * @return void
24
+ */
25
+ constructor(cx, path) {
26
+ this.cx = cx;
27
+ this.path = _isArray(path) ? path : (path + '').split('/').filter(a => a);
28
+ }
29
+
30
+ /**
31
+ * Performs dynamic routing.
32
+ *
33
+ * @param array|string method
34
+ * @param Object event
35
+ * @param any arg
36
+ * @param function _default
37
+ * @param function remoteFetch
38
+ *
39
+ * @return object
40
+ */
41
+ async route(method, event, arg, _default, remoteFetch = null) {
42
+
43
+ const $this = this;
44
+ const $runtime = this.cx.runtime;
45
+
46
+ // ----------------
47
+ // The loop
48
+ // ----------------
49
+ const next = async function(thisTick) {
50
+ const thisContext = { runtime: $runtime };
51
+ if (!thisTick.trail || thisTick.trail.length < thisTick.destination.length) {
52
+ thisTick = await $this.readTick(thisTick);
53
+ // -------------
54
+ thisContext.pathname = `/${thisTick.trail.join('/')}`;
55
+ thisContext.stepname = thisTick.trail[thisTick.trail.length - 1];
56
+ $this.finalizeHandlerContext(thisContext, thisTick);
57
+ // -------------
58
+ if (thisTick.exports) {
59
+ // Broadcast any hints exported by handler
60
+ if (thisTick.exports.hints) { await event.port.post({ ...thisTick.exports.hints, $type: 'handler:hints' }); }
61
+ const methods = _arrFrom(thisTick.method);
62
+ const handler = _isFunction(thisTick.exports) && methods.includes('default') ? thisTick.exports : methods.reduce((_handler, name) => _handler || thisTick.exports[name.toLowerCase()], null);
63
+ if (handler) {
64
+ // -------------
65
+ // Dynamic response
66
+ // -------------
67
+ const _next = async (..._args) => {
68
+ const nextTick = { ...thisTick, arg: _args[0] };
69
+ if (_args.length > 1) {
70
+ var _url = _args[1], _request, requestInit = { ...(_args[2] || {}) };
71
+ if (_args[1] instanceof nextTick.event.Request) {
72
+ _request = _args[1];
73
+ _url = _request.url;
74
+ } else if (!_isString(_url)) {
75
+ throw new Error('Router redirect url must be a string!');
76
+ }
77
+ var newDestination = _url.startsWith('/') ? _url : $this.pathJoin(`/${thisTick.trail.join('/')}`, _url);
78
+ if (newDestination.startsWith('../')) {
79
+ throw new Error('Router redirect cannot traverse beyond the routing directory! (' + _url + ' >> ' + newDestination + ')');
80
+ }
81
+ if (requestInit.method) {
82
+ nextTick.method = requestInit.method;
83
+ if (_isArray(requestInit.method)) {
84
+ requestInit.method = requestInit.method[0];
85
+ }
86
+ }
87
+ if (_request) {
88
+ nextTick.event = thisTick.event.retarget(_request, { ...requestInit, _proxy: { url: newDestination/** non-standard but works */ } });
89
+ } else {
90
+ nextTick.event = thisTick.event.retarget(newDestination, requestInit);
91
+ }
92
+
93
+ nextTick.source = thisTick.destination.join('/');
94
+ nextTick.destination = newDestination.split('?').shift().split('/').map(a => a.trim()).filter(a => a);
95
+ nextTick.trail = _args[1].startsWith('/') ? [] : thisTick.trail.reduce((_commonRoot, _seg, i) => _commonRoot.length === i && _seg === nextTick.destination[i] ? _commonRoot.concat(_seg) : _commonRoot, []);
96
+ nextTick.trailOnFile = thisTick.trailOnFile.slice(0, nextTick.trail.length);
97
+ }
98
+ return next(nextTick);
99
+ };
100
+ // -------------
101
+ const nextPathname = thisTick.destination.slice(thisTick.trail.length);
102
+ _next.pathname = nextPathname.join('/');
103
+ _next.stepname = nextPathname[0];
104
+ // -------------
105
+ return await handler.call(thisContext, thisTick.event, thisTick.arg, _next/*next*/, remoteFetch);
106
+ }
107
+ // Handler not found but exports found
108
+ return next(thisTick);
109
+ } else if ((thisTick.currentSegmentOnFile || {}).dirExists) {
110
+ // Exports not found but directory found
111
+ return next(thisTick);
112
+ }
113
+ }
114
+ // -------------
115
+ // Local file
116
+ // -------------
117
+ if (_default) {
118
+ return await _default.call(thisContext, thisTick.event, thisTick.arg, remoteFetch);
119
+ }
120
+ };
121
+
122
+ return next({
123
+ destination: this.path,
124
+ event,
125
+ method,
126
+ arg,
127
+ });
128
+
129
+ }
130
+
131
+ }
@@ -1,7 +1,7 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import _Contex from '../../Context.js';
6
-
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import _Contex from '../../Context.js';
6
+
7
7
  export default class Context extends _Contex {}
@@ -1,47 +1,47 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { path as Path } from '../util.js';
6
- import _Router from '../Router.js';
7
-
8
- /**
9
- * ---------------------------
10
- * The Router class
11
- * ---------------------------
12
- */
13
-
14
- export default class Router extends _Router {
15
-
16
- async readTick(thisTick) {
17
- var routeTree = this.cx.layout;
18
- var routePaths = Object.keys(this.cx.layout);
19
- if (thisTick.trail) {
20
- thisTick.currentSegment = thisTick.destination[thisTick.trail.length];
21
- thisTick.currentSegmentOnFile = [ thisTick.currentSegment, '-' ].reduce((_segmentOnFile, _seg) => {
22
- if (_segmentOnFile.index) return _segmentOnFile;
23
- var _currentPath = `/${thisTick.trailOnFile.concat(_seg).join('/')}`;
24
- return routeTree[_currentPath] ? { seg: _seg, index: _currentPath } : (
25
- routePaths.filter(p => p.startsWith(`${_currentPath}/`)).length ? { seg: _seg, dirExists: true } : _segmentOnFile
26
- );
27
- }, { seg: null });
28
- thisTick.trail.push(thisTick.currentSegment);
29
- thisTick.trailOnFile.push(thisTick.currentSegmentOnFile.seg);
30
- thisTick.exports = routeTree[thisTick.currentSegmentOnFile.index];
31
- } else {
32
- thisTick.trail = [];
33
- thisTick.trailOnFile = [];
34
- thisTick.currentSegmentOnFile = { index: '/' };
35
- thisTick.exports = routeTree['/'];
36
- }
37
- return thisTick;
38
- }
39
-
40
- finalizeHandlerContext(context, thisTick) {
41
- return context.dirname = thisTick.currentSegmentOnFile.index;
42
- }
43
-
44
- pathJoin(...args) {
45
- return Path.join(...args);
46
- }
47
- };
1
+
2
+ /**
3
+ * @imports
4
+ */
5
+ import { path as Path } from '../util.js';
6
+ import _Router from '../Router.js';
7
+
8
+ /**
9
+ * ---------------------------
10
+ * The Router class
11
+ * ---------------------------
12
+ */
13
+
14
+ export default class Router extends _Router {
15
+
16
+ async readTick(thisTick) {
17
+ var routeTree = this.cx.layout;
18
+ var routePaths = Object.keys(this.cx.layout);
19
+ if (thisTick.trail) {
20
+ thisTick.currentSegment = thisTick.destination[thisTick.trail.length];
21
+ thisTick.currentSegmentOnFile = [ thisTick.currentSegment, '-' ].reduce((_segmentOnFile, _seg) => {
22
+ if (_segmentOnFile.index) return _segmentOnFile;
23
+ var _currentPath = `/${thisTick.trailOnFile.concat(_seg).join('/')}`;
24
+ return routeTree[_currentPath] ? { seg: _seg, index: _currentPath } : (
25
+ routePaths.filter(p => p.startsWith(`${_currentPath}/`)).length ? { seg: _seg, dirExists: true } : _segmentOnFile
26
+ );
27
+ }, { seg: null });
28
+ thisTick.trail.push(thisTick.currentSegment);
29
+ thisTick.trailOnFile.push(thisTick.currentSegmentOnFile.seg);
30
+ thisTick.exports = routeTree[thisTick.currentSegmentOnFile.index];
31
+ } else {
32
+ thisTick.trail = [];
33
+ thisTick.trailOnFile = [];
34
+ thisTick.currentSegmentOnFile = { index: '/' };
35
+ thisTick.exports = routeTree['/'];
36
+ }
37
+ return thisTick;
38
+ }
39
+
40
+ finalizeHandlerContext(context, thisTick) {
41
+ return context.dirname = thisTick.currentSegmentOnFile.index;
42
+ }
43
+
44
+ pathJoin(...args) {
45
+ return Path.join(...args);
46
+ }
47
+ };