@webqit/webflo 0.11.61 → 0.20.2-next.0

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 (235) hide show
  1. package/.github/FUNDING.yml +12 -0
  2. package/.github/workflows/publish.yml +48 -0
  3. package/.gitignore +2 -0
  4. package/LICENSE +2 -2
  5. package/README.md +71 -2050
  6. package/package.json +28 -13
  7. package/site/-/_.md +139 -0
  8. package/site/-/docs.old.md +2010 -0
  9. package/site/.vitepress/cache/deps/@braintree_sanitize-url 2.js +93 -0
  10. package/site/.vitepress/cache/deps/@braintree_sanitize-url.js +93 -0
  11. package/site/.vitepress/cache/deps/@braintree_sanitize-url.js 2.map +7 -0
  12. package/site/.vitepress/cache/deps/@braintree_sanitize-url.js.map +7 -0
  13. package/site/.vitepress/cache/deps/_metadata 2.json +85 -0
  14. package/site/.vitepress/cache/deps/_metadata.json +85 -0
  15. package/site/.vitepress/cache/deps/chunk-BUSYA2B4 2.js +9 -0
  16. package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js +9 -0
  17. package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js 2.map +7 -0
  18. package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js.map +7 -0
  19. package/site/.vitepress/cache/deps/chunk-Q2AYPHVK 2.js +9719 -0
  20. package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js +9719 -0
  21. package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js 2.map +7 -0
  22. package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js.map +7 -0
  23. package/site/.vitepress/cache/deps/chunk-QAXAIFA7 2.js +12705 -0
  24. package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js +12705 -0
  25. package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js 2.map +7 -0
  26. package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js.map +7 -0
  27. package/site/.vitepress/cache/deps/cytoscape 2.js +30278 -0
  28. package/site/.vitepress/cache/deps/cytoscape-cose-bilkent 2.js +4710 -0
  29. package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js +4710 -0
  30. package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js 2.map +7 -0
  31. package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js.map +7 -0
  32. package/site/.vitepress/cache/deps/cytoscape.js +30278 -0
  33. package/site/.vitepress/cache/deps/cytoscape.js 2.map +7 -0
  34. package/site/.vitepress/cache/deps/cytoscape.js.map +7 -0
  35. package/site/.vitepress/cache/deps/dayjs 2.js +285 -0
  36. package/site/.vitepress/cache/deps/dayjs.js +285 -0
  37. package/site/.vitepress/cache/deps/dayjs.js 2.map +7 -0
  38. package/site/.vitepress/cache/deps/dayjs.js.map +7 -0
  39. package/site/.vitepress/cache/deps/debug 2.js +453 -0
  40. package/site/.vitepress/cache/deps/debug.js +453 -0
  41. package/site/.vitepress/cache/deps/debug.js 2.map +7 -0
  42. package/site/.vitepress/cache/deps/debug.js.map +7 -0
  43. package/site/.vitepress/cache/deps/package 2.json +3 -0
  44. package/site/.vitepress/cache/deps/package.json +3 -0
  45. package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api 2.js +4507 -0
  46. package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4507 -0
  47. package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js 2.map +7 -0
  48. package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  49. package/site/.vitepress/cache/deps/vitepress___@vueuse_core 2.js +584 -0
  50. package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js +584 -0
  51. package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js 2.map +7 -0
  52. package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  53. package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap 2.js +1166 -0
  54. package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1166 -0
  55. package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js 2.map +7 -0
  56. package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  57. package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js 2.js +1667 -0
  58. package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1667 -0
  59. package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js 2.map +7 -0
  60. package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  61. package/site/.vitepress/cache/deps/vitepress___minisearch 2.js +1815 -0
  62. package/site/.vitepress/cache/deps/vitepress___minisearch.js +1815 -0
  63. package/site/.vitepress/cache/deps/vitepress___minisearch.js 2.map +7 -0
  64. package/site/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
  65. package/site/.vitepress/cache/deps/vue 2.js +344 -0
  66. package/site/.vitepress/cache/deps/vue.js +344 -0
  67. package/site/.vitepress/cache/deps/vue.js 2.map +7 -0
  68. package/site/.vitepress/cache/deps/vue.js.map +7 -0
  69. package/site/.vitepress/config.ts +147 -0
  70. package/site/.vitepress/theme/custom.css +50 -0
  71. package/site/.vitepress/theme/index.ts +6 -0
  72. package/site/api/webflo-fetch/FormData.md +0 -0
  73. package/site/api/webflo-fetch/Headers.md +0 -0
  74. package/site/api/webflo-fetch/LiveResponse.md +0 -0
  75. package/site/api/webflo-fetch/Request.md +0 -0
  76. package/site/api/webflo-fetch/Response.md +0 -0
  77. package/site/api/webflo-fetch/fetch.md +0 -0
  78. package/site/api/webflo-routing/HttpCookies.md +0 -0
  79. package/site/api/webflo-routing/HttpEvent/respondWith.md +1 -0
  80. package/site/api/webflo-routing/HttpEvent/waitUntil.md +1 -0
  81. package/site/api/webflo-routing/HttpEvent/waitUntilNavigate.md +1 -0
  82. package/site/api/webflo-routing/HttpEvent.md +30 -0
  83. package/site/api/webflo-routing/HttpSession.md +0 -0
  84. package/site/api/webflo-routing/HttpState.md +0 -0
  85. package/site/api/webflo-routing/HttpUser.md +0 -0
  86. package/site/api/webflo-routing/handler/fetch.md +42 -0
  87. package/site/api/webflo-routing/handler/next.md +54 -0
  88. package/site/api/webflo-routing/handler.md +119 -0
  89. package/site/api.md +26 -0
  90. package/site/contributing.md +16 -0
  91. package/site/docs/advanced/lifecycles.md +20 -0
  92. package/site/docs/advanced/redirects.md +0 -0
  93. package/site/docs/advanced/routing.md +1 -0
  94. package/site/docs/advanced.md +9 -0
  95. package/site/docs/concepts/realtime.md +637 -0
  96. package/site/docs/concepts/rendering.md +60 -0
  97. package/site/docs/concepts/request-response.md +47 -0
  98. package/site/docs/concepts/routing.md +656 -0
  99. package/site/docs/concepts/state.md +44 -0
  100. package/site/docs/concepts/templates.md +48 -0
  101. package/site/docs/concepts.md +97 -0
  102. package/site/docs/getting-started.md +378 -0
  103. package/site/docs/tech-stack.md +56 -0
  104. package/site/docs.md +100 -0
  105. package/site/examples/pwa.md +10 -0
  106. package/site/examples/web.md +11 -0
  107. package/site/examples.md +10 -0
  108. package/site/faq.md +13 -0
  109. package/site/guides/guide-auth.md +13 -0
  110. package/site/guides/guide-file-upload.md +11 -0
  111. package/site/guides/guide-service-worker.md +10 -0
  112. package/site/guides/tutorial-1-todo.md +24 -0
  113. package/site/guides.md +15 -0
  114. package/site/index.md +39 -0
  115. package/site/public/img/brand/logo-670x670.png +0 -0
  116. package/site/recipes/realtime.md +11 -0
  117. package/site/recipes/streaming.md +15 -0
  118. package/site/reference/cli.md +11 -0
  119. package/site/reference/config.md +13 -0
  120. package/site/reference/tools.md +9 -0
  121. package/src/Context.js +3 -11
  122. package/src/config-pi/deployment/Env.js +6 -19
  123. package/src/config-pi/deployment/Layout.js +11 -3
  124. package/src/config-pi/runtime/Client.js +40 -48
  125. package/src/config-pi/runtime/Server.js +52 -20
  126. package/src/config-pi/runtime/client/Worker.js +22 -20
  127. package/src/config-pi/static/Init.js +57 -0
  128. package/src/config-pi/static/index.js +2 -0
  129. package/src/deployment-pi/origins/index.js +1 -1
  130. package/src/deployment-pi/util.js +161 -0
  131. package/src/index.js +3 -9
  132. package/src/init-pi/index.js +117 -0
  133. package/src/init-pi/templates/pwa/app/handler.server.js +8 -0
  134. package/src/init-pi/templates/pwa/app/page.html +7 -0
  135. package/src/init-pi/templates/pwa/package.json +19 -0
  136. package/src/init-pi/templates/pwa/public/assets/app.css +16 -0
  137. package/src/init-pi/templates/pwa/public/index.html +39 -0
  138. package/src/init-pi/templates/pwa/public/manifest.json +29 -0
  139. package/src/init-pi/templates/web/app/handler.server.js +8 -0
  140. package/src/init-pi/templates/web/app/page.html +7 -0
  141. package/src/init-pi/templates/web/package.json +19 -0
  142. package/src/init-pi/templates/web/public/assets/app.css +16 -0
  143. package/src/init-pi/templates/web/public/index.html +39 -0
  144. package/src/runtime-pi/WebfloRuntime.js +350 -0
  145. package/src/runtime-pi/index.js +3 -10
  146. package/src/runtime-pi/webflo-client/ClientSideCookies.js +17 -0
  147. package/src/runtime-pi/webflo-client/ClientSideWorkport.js +63 -0
  148. package/src/runtime-pi/webflo-client/DeviceCapabilities.js +213 -0
  149. package/src/runtime-pi/webflo-client/WebfloClient.js +500 -0
  150. package/src/runtime-pi/webflo-client/WebfloRootClient1.js +206 -0
  151. package/src/runtime-pi/webflo-client/WebfloRootClient2.js +113 -0
  152. package/src/runtime-pi/webflo-client/WebfloSubClient.js +118 -0
  153. package/src/runtime-pi/webflo-client/index.js +17 -0
  154. package/src/runtime-pi/webflo-client/webflo-codegen.js +469 -0
  155. package/src/runtime-pi/webflo-client/webflo-devmode.js +243 -0
  156. package/src/runtime-pi/webflo-client/webflo-embedded.js +50 -0
  157. package/src/runtime-pi/webflo-fetch/LiveResponse.js +437 -0
  158. package/src/runtime-pi/webflo-fetch/cookies.js +10 -0
  159. package/src/runtime-pi/webflo-fetch/fetch.js +16 -0
  160. package/src/runtime-pi/webflo-fetch/formdata.js +54 -0
  161. package/src/runtime-pi/webflo-fetch/headers.js +151 -0
  162. package/src/runtime-pi/webflo-fetch/index.js +5 -0
  163. package/src/runtime-pi/webflo-fetch/message.js +49 -0
  164. package/src/runtime-pi/webflo-fetch/request.js +62 -0
  165. package/src/runtime-pi/webflo-fetch/response.js +110 -0
  166. package/src/runtime-pi/webflo-fetch/util.js +28 -0
  167. package/src/runtime-pi/webflo-messaging/WQBroadcastChannel.js +10 -0
  168. package/src/runtime-pi/webflo-messaging/WQMessageChannel.js +26 -0
  169. package/src/runtime-pi/webflo-messaging/WQMessageEvent.js +87 -0
  170. package/src/runtime-pi/webflo-messaging/WQMessagePort.js +38 -0
  171. package/src/runtime-pi/webflo-messaging/WQRelayPort.js +47 -0
  172. package/src/runtime-pi/webflo-messaging/WQSockPort.js +113 -0
  173. package/src/runtime-pi/webflo-messaging/WQStarPort.js +104 -0
  174. package/src/runtime-pi/webflo-messaging/wq-message-port.js +404 -0
  175. package/src/runtime-pi/webflo-routing/HttpCookies.js +42 -0
  176. package/src/runtime-pi/webflo-routing/HttpEvent.js +112 -0
  177. package/src/runtime-pi/webflo-routing/HttpSession.js +11 -0
  178. package/src/runtime-pi/webflo-routing/HttpState.js +153 -0
  179. package/src/runtime-pi/webflo-routing/HttpUser.js +54 -0
  180. package/src/runtime-pi/webflo-routing/WebfloRouter.js +245 -0
  181. package/src/runtime-pi/webflo-server/ServerSideCookies.js +19 -0
  182. package/src/runtime-pi/webflo-server/ServerSideSession.js +38 -0
  183. package/src/runtime-pi/webflo-server/WebfloServer.js +937 -0
  184. package/src/runtime-pi/webflo-server/index.js +11 -0
  185. package/src/runtime-pi/webflo-server/messaging/Client.js +27 -0
  186. package/src/runtime-pi/webflo-server/messaging/ClientRequestRealtime.js +50 -0
  187. package/src/runtime-pi/webflo-server/messaging/Clients.js +25 -0
  188. package/src/runtime-pi/webflo-server/webflo-devmode.js +326 -0
  189. package/src/runtime-pi/{client → webflo-url}/Url.js +27 -76
  190. package/src/runtime-pi/webflo-url/index.js +1 -0
  191. package/src/runtime-pi/webflo-url/urlpattern.js +38 -0
  192. package/src/runtime-pi/{util-url.js → webflo-url/util.js} +5 -43
  193. package/src/runtime-pi/webflo-url/xURL.js +94 -0
  194. package/src/runtime-pi/webflo-worker/WebfloWorker.js +234 -0
  195. package/src/runtime-pi/webflo-worker/WorkerSideCookies.js +19 -0
  196. package/src/runtime-pi/webflo-worker/WorkerSideWorkport.js +18 -0
  197. package/src/runtime-pi/webflo-worker/index.js +11 -0
  198. package/src/services-pi/index.js +2 -0
  199. package/src/services-pi/push/index.js +23 -0
  200. package/src/util.js +10 -0
  201. package/src/{webflo.js → webflo-cli.js} +4 -4
  202. package/src/runtime-pi/Application.js +0 -29
  203. package/src/runtime-pi/Cookies.js +0 -82
  204. package/src/runtime-pi/HttpEvent.js +0 -107
  205. package/src/runtime-pi/Router.js +0 -130
  206. package/src/runtime-pi/Runtime.js +0 -21
  207. package/src/runtime-pi/client/Application.js +0 -76
  208. package/src/runtime-pi/client/Context.js +0 -7
  209. package/src/runtime-pi/client/Router.js +0 -48
  210. package/src/runtime-pi/client/Runtime.js +0 -525
  211. package/src/runtime-pi/client/Workport.js +0 -190
  212. package/src/runtime-pi/client/createStorage.js +0 -58
  213. package/src/runtime-pi/client/generate.js +0 -481
  214. package/src/runtime-pi/client/index.js +0 -21
  215. package/src/runtime-pi/client/worker/Application.js +0 -44
  216. package/src/runtime-pi/client/worker/Context.js +0 -7
  217. package/src/runtime-pi/client/worker/Runtime.js +0 -275
  218. package/src/runtime-pi/client/worker/Workport.js +0 -78
  219. package/src/runtime-pi/client/worker/index.js +0 -21
  220. package/src/runtime-pi/server/Application.js +0 -101
  221. package/src/runtime-pi/server/Context.js +0 -16
  222. package/src/runtime-pi/server/Router.js +0 -159
  223. package/src/runtime-pi/server/Runtime.js +0 -558
  224. package/src/runtime-pi/server/index.js +0 -21
  225. package/src/runtime-pi/util-http.js +0 -86
  226. package/src/runtime-pi/xFormData.js +0 -24
  227. package/src/runtime-pi/xHeaders.js +0 -146
  228. package/src/runtime-pi/xRequest.js +0 -46
  229. package/src/runtime-pi/xRequestHeaders.js +0 -109
  230. package/src/runtime-pi/xResponse.js +0 -33
  231. package/src/runtime-pi/xResponseHeaders.js +0 -117
  232. package/src/runtime-pi/xURL.js +0 -105
  233. package/src/runtime-pi/xfetch.js +0 -23
  234. package/src/runtime-pi/xxHttpMessage.js +0 -102
  235. package/src/static-pi/index.js +0 -11
@@ -1,107 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _isEmpty } from '@webqit/util/js/index.js';
6
- import xRequest from "./xRequest.js";
7
- import xResponse from "./xResponse.js";
8
- import xURL from "./xURL.js";
9
-
10
- /**
11
- * The xHttpEvent Mixin
12
- */
13
- export default class HttpEvent {
14
-
15
- /**
16
- * Initializes a new HttpEvent instance.
17
- *
18
- * @param Request _request
19
- * @param Object _detail
20
- * @param Function _sessionFactory
21
- * @param Function _storageFactory
22
- */
23
- constructor(_request, _detail, _sessionFactory, _storageFactory) {
24
- this._request = _request;
25
- this._detail = _detail || {};
26
- this._sessionFactory = _sessionFactory;
27
- this._storageFactory = _storageFactory;
28
- // -------
29
- this.Request = xRequest;
30
- this.Response = xResponse;
31
- this.URL = xURL;
32
- // -------
33
- this.port = {
34
- listeners: [],
35
- post(message) {
36
- const promises = this.listeners.map(listener => listener(message))
37
- .filter(returnValue => returnValue instanceof Promise);
38
- if (process.length) return Promise.all(promises);
39
- },
40
- listen(listener) { this.listeners.push(listener); },
41
- }
42
- }
43
-
44
- // url
45
- get url() {
46
- if (!this._url) {
47
- this._url = new this.URL(this._request.url);
48
- }
49
- return this._url;
50
- }
51
-
52
- // request
53
- get request() {
54
- return this._request;
55
- }
56
-
57
- // detail
58
- get detail() {
59
- return this._detail;
60
- }
61
-
62
- // Session
63
- get session() {
64
- if (!this._session) {
65
- this._session = this.sessionFactory();
66
- }
67
- return this._session;
68
- }
69
-
70
- // Storage
71
- get storage() {
72
- if (!this._storage) {
73
- this._storage = this.storageFactory();
74
- }
75
- return this._storage;
76
- }
77
-
78
- // Session factory
79
- sessionFactory(...args) {
80
- return this._sessionFactory(...args);
81
- }
82
-
83
- // storage factory
84
- storageFactory(...args) {
85
- return this._storageFactory(...args);
86
- }
87
-
88
- // Redirect Response
89
- redirect(url, code = 302) {
90
- return new this.Response(null, { status: code, headers: { Location: url } });
91
- }
92
-
93
- // "with()"
94
- async with(url, init = {}) {
95
- let request;
96
- if (url instanceof Request) {
97
- if (init instanceof Request) { [ /*url*/, init ] = await xRequest.rip(init); }
98
- request = !_isEmpty(init) ? new xRequest(url, init) : url;
99
- } else {
100
- url = new this.URL(url, this.url.origin);
101
- [ /*url*/, init ] = await xRequest.rip(this._request);
102
- request = new xRequest(url, { ...init, referrer: this.request.url });
103
- }
104
- return new HttpEvent(request, this.detail, this._sessionFactory, this.storageFactory);
105
- }
106
-
107
- }
@@ -1,130 +0,0 @@
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).map(m => m === 'default' ? m : m.toUpperCase());
62
- const handler = _isFunction(thisTick.exports) && methods.includes('default') ? thisTick.exports : methods.reduce((_handler, name) => _handler || thisTick.exports[name], 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
- let _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
- let 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 = await thisTick.event.with(newDestination, _request, requestInit);
89
- } else {
90
- nextTick.event = await thisTick.event.with(newDestination, requestInit);
91
- }
92
- nextTick.source = thisTick.destination.join('/');
93
- nextTick.destination = newDestination.split('?').shift().split('/').map(a => a.trim()).filter(a => a);
94
- nextTick.trail = _args[1].startsWith('/') ? [] : thisTick.trail.reduce((_commonRoot, _seg, i) => _commonRoot.length === i && _seg === nextTick.destination[i] ? _commonRoot.concat(_seg) : _commonRoot, []);
95
- nextTick.trailOnFile = thisTick.trailOnFile.slice(0, nextTick.trail.length);
96
- }
97
- return next(nextTick);
98
- };
99
- // -------------
100
- const nextPathname = thisTick.destination.slice(thisTick.trail.length);
101
- _next.pathname = nextPathname.join('/');
102
- _next.stepname = nextPathname[0];
103
- // -------------
104
- return await handler.call(thisContext, thisTick.event, thisTick.arg, _next/*next*/, remoteFetch);
105
- }
106
- // Handler not found but exports found
107
- return next(thisTick);
108
- } else if ((thisTick.currentSegmentOnFile || {}).dirExists) {
109
- // Exports not found but directory found
110
- return next(thisTick);
111
- }
112
- }
113
- // -------------
114
- // Local file
115
- // -------------
116
- if (_default) {
117
- return await _default.call(thisContext, thisTick.event, thisTick.arg, remoteFetch);
118
- }
119
- };
120
-
121
- return next({
122
- destination: this.path,
123
- event,
124
- method,
125
- arg,
126
- });
127
-
128
- }
129
-
130
- }
@@ -1,21 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
-
6
- import { _isFunction } from "@webqit/util/js/index.js";
7
-
8
- /**
9
- * ---------------------------
10
- * The base Runtime class
11
- * ---------------------------
12
- */
13
-
14
- export default class Runtime {
15
- constructor(cx, applicationInstance) {
16
- this.cx = cx;
17
- this.cx.runtime = this;
18
- this.app = _isFunction(applicationInstance) ? applicationInstance(this.cx) : applicationInstance;
19
- if (!this.app || !this.app.handle) throw new Error(`Application instance must define a ".handle()" method.`);
20
- }
21
- }
@@ -1,76 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import Router from './Router.js';
6
- import _Application from '../Application.js';
7
-
8
- export default class Application extends _Application {
9
-
10
- // Returns router class
11
- get Router() {
12
- return Router;
13
- }
14
-
15
- /**
16
- * Handles HTTP events.
17
- *
18
- * @param HttpEvent httpEvent
19
- * @param Function remoteFetch
20
- *
21
- * @return Response
22
- */
23
- async handle(httpEvent, remoteFetch) {
24
- // The app router
25
- const router = new this.Router(this.cx, httpEvent.url.pathname);
26
- const handle = async () => {
27
- let bindingsConfig;
28
- if (window.webqit?.oohtml?.configs) { ( { BINDINGS_API: { api: bindingsConfig } = {}, } = window.webqit.oohtml.configs ); }
29
- return router.route([httpEvent.request.method, 'default'], httpEvent, { ...( ( bindingsConfig && document[bindingsConfig.bindings] ) || {} ) }, async event => {
30
- if (event !== httpEvent) {
31
- // This was nexted()
32
- if (!event.request.headers.has('Accept')) {
33
- event.request.headers.set('Accept', 'application/json');
34
- }
35
- }
36
- return remoteFetch(event.request);
37
- }, remoteFetch);
38
- };
39
- return await (this.cx.middlewares || []).concat(handle).reverse().reduce((next, fn) => {
40
- return () => fn.call(this.cx, httpEvent, router, next);
41
- }, null)();
42
- }
43
-
44
- // Renderer
45
- async render(httpEvent, response) {
46
- let data = await response.jsonfy();
47
- const router = new this.Router(this.cx, httpEvent.url.pathname);
48
- return await router.route('render', httpEvent, data, async (httpEvent, data) => {
49
- if (window.webqit?.dom) { await new Promise(res => window.webqit.dom.ready(res)); }
50
- if (window.webqit?.oohtml?.configs) {
51
- const {
52
- CONTEXT_API: { attr: contextConfig } = {},
53
- BINDINGS_API: { api: bindingsConfig } = {},
54
- HTML_IMPORTS: { attr: modulesContextAttrs } = {},
55
- } = window.webqit.oohtml.configs;
56
- if ( bindingsConfig ) {
57
- window.document[ bindingsConfig.bind ]({
58
- env: 'client', state: this.cx.runtime, ...(data || {})
59
- }, { diff: true });
60
- }
61
- let routingContext;
62
- if ( modulesContextAttrs ) {
63
- routingContext = window.document.body.querySelector(`[${ window.CSS.escape( contextConfig.contextname ) }="app"]`) || window.document.body;
64
- const prevRoute = routingContext.getAttribute( modulesContextAttrs.importscontext );
65
- const newRoute = '/' + `routes/${ httpEvent.url.pathname }`.split('/').map(a => a.trim()).filter(a => a).join('/');
66
- const rel = prevRoute === newRoute ? 'same' : ( `${ prevRoute }/`.startsWith( `${ newRoute }/` ) ? 'parent' : ( `${ newRoute }/`.startsWith( `${ prevRoute }/` ) ? 'child' : 'unrelated' ) );
67
- routingContext.setAttribute( modulesContextAttrs.importscontext, newRoute);
68
- routingContext.setAttribute( `prev-${ modulesContextAttrs.importscontext }`, prevRoute );
69
- routingContext.setAttribute( 'importscontext-transition-type', rel );
70
- }
71
- }
72
- return window;
73
- });
74
- }
75
- }
76
-
@@ -1,7 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import _Context from '../../Context.js';
6
-
7
- export default class Context extends _Context {}
@@ -1,48 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { path as Path } from '../util-url.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
- thisTick = { ...thisTick };
18
- var routeTree = this.cx.layout;
19
- var routePaths = Object.keys(this.cx.layout);
20
- if (thisTick.trail) {
21
- thisTick.currentSegment = thisTick.destination[thisTick.trail.length];
22
- thisTick.currentSegmentOnFile = [ thisTick.currentSegment, '-' ].reduce((_segmentOnFile, _seg) => {
23
- if (_segmentOnFile.index) return _segmentOnFile;
24
- var _currentPath = `/${thisTick.trailOnFile.concat(_seg).join('/')}`;
25
- return routeTree[_currentPath] ? { seg: _seg, index: _currentPath } : (
26
- routePaths.filter(p => p.startsWith(`${_currentPath}/`)).length ? { seg: _seg, dirExists: true } : _segmentOnFile
27
- );
28
- }, { seg: null });
29
- thisTick.trail = thisTick.trail.concat(thisTick.currentSegment);
30
- thisTick.trailOnFile = thisTick.trailOnFile.concat(thisTick.currentSegmentOnFile.seg);
31
- thisTick.exports = routeTree[thisTick.currentSegmentOnFile.index];
32
- } else {
33
- thisTick.trail = [];
34
- thisTick.trailOnFile = [];
35
- thisTick.currentSegmentOnFile = { index: '/' };
36
- thisTick.exports = routeTree['/'];
37
- }
38
- return thisTick;
39
- }
40
-
41
- finalizeHandlerContext(context, thisTick) {
42
- return context.dirname = thisTick.currentSegmentOnFile.index;
43
- }
44
-
45
- pathJoin(...args) {
46
- return Path.join(...args);
47
- }
48
- };