@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,24 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { jsonfyFormData } from './util-http.js';
6
-
7
- /**
8
- * The _Headers Mixin
9
- */
10
- export default class xFormData extends FormData {
11
-
12
- async json(data = {}) {
13
- const result = await jsonfyFormData(this, ...arguments);
14
- return result[0];
15
- }
16
-
17
- static compat(formData) {
18
- if (formData instanceof this) return formData;
19
- if (formData instanceof FormData) {
20
- return Object.setPrototypeOf(formData, new this);
21
- }
22
- }
23
-
24
- }
@@ -1,146 +0,0 @@
1
-
2
- /**
3
- * The xHeaders Mixin
4
- */
5
- export default class xHeaders extends Headers {
6
-
7
- // construct
8
- constructor(definition = {}) {
9
- const cookies = definition.cookies;
10
- delete definition.cookies;
11
- // -----------------
12
- if (definition instanceof Headers) {
13
- // It's another Headers instance
14
- super(definition);
15
- } else {
16
- super();
17
- this.json(definition);
18
- }
19
- // -----------------
20
- this.cookies = cookies;
21
- }
22
-
23
- set(name, value) {
24
- // Will sync forth to this._cookies if is cookie
25
- this.catchCookies(name, value);
26
- return super.set(name, value);
27
- }
28
-
29
- append(name, value) {
30
- // Will sync forth to this._cookies if is cookie
31
- this.catchCookies(name, value, true);
32
- return super.append(name, value);
33
- }
34
-
35
- delete(name) {
36
- // Will sync forth to this._cookies if is cookie
37
- this.catchCookies(name);
38
- return super.delete(name);
39
- }
40
-
41
- set cookies(cookies) {
42
- if (cookies instanceof Map) {
43
- this.cookies.clear();
44
- for (let [ name, value ] of cookies) {
45
- this.cookies.set(name, value);
46
- }
47
- } else if (cookies) { this.set(this.cookieHeaderName, cookies); }
48
- return true;
49
- }
50
-
51
- get cookies() {
52
- if (!this._cookies) {
53
- this._cookies = new this.Cookies;
54
- Object.defineProperty(this._cookies, 'headers', { value: this });
55
- }
56
- return this._cookies;
57
- }
58
-
59
- catchCookies(name, value, append = false) {
60
- if (!this.cookies || name.toLowerCase() !== this.cookieHeaderName.toLowerCase()) return;
61
- this.cookies.outLock = true;
62
- // -----------------
63
- if (arguments.length > 1) {
64
- if (!append) { this.cookies.clear(); }
65
- const cookiesObj = this.cookies.parse(value);
66
- for (let name in cookiesObj) {
67
- this.cookies.set(name, cookiesObj[name]);
68
- }
69
- } else { this.cookies.clear(); }
70
- // -----------------
71
- this.cookies.outLock = false;
72
- }
73
-
74
- json(headers = {}, replace = true) {
75
- if (arguments.length) {
76
- const _setters = getAllPropertyDescriptors(this);
77
- const setters = Object.keys(_setters).reduce((list, key) => list.concat((typeof key !== 'symbol') && ('set' in _setters[key]) ? key : []), []);
78
- Object.keys(headers).forEach(name => {
79
- var nameCs = setters.reduce((prev, curr) => prev || (curr === name || curr.toLocaleLowerCase() === name ? curr : null), null);
80
- if (nameCs) {
81
- if (replace || this[nameCs] === undefined) {
82
- this[nameCs] = headers[name];
83
- }
84
- } else {
85
- if (replace || !this.has(name)) {
86
- this.set(name, headers[name]);
87
- }
88
- }
89
- });
90
- return;
91
- }
92
- const _headers = {};
93
- for (var [ name, value ] of this) {
94
- _headers[name] = value;
95
- }
96
- return _headers;
97
- }
98
-
99
- set cacheControl(value) {
100
- return this.set('Cache-Control', value);
101
- }
102
-
103
- get cacheControl() {
104
- return this.get('Cache-Control');
105
- }
106
-
107
- set contentLength(value) {
108
- return this.set('Content-Length', value);
109
- }
110
-
111
- get contentLength() {
112
- return this.get('Content-Length');
113
- }
114
-
115
- set contentType(value) {
116
- return this.set('Content-Type', value);
117
- }
118
-
119
- get contentType() {
120
- return this.get('Content-Type');
121
- }
122
-
123
- static compat(headers) {
124
- if (!(headers instanceof this) && !headers.json) {
125
- const descs = getAllPropertyDescriptors(new this);
126
- Object.keys(descs).forEach(key => {
127
- if (typeof key === 'symbol' || (key in headers)) return;
128
- Object.defineProperty(headers, key, descs[key]);
129
- });
130
- }
131
- return headers;
132
- }
133
-
134
- }
135
-
136
- function getAllPropertyDescriptors(obj) {
137
- if (!obj) {
138
- return Object.create(null);
139
- } else {
140
- const proto = Object.getPrototypeOf(obj);
141
- return proto === Object.prototype ? {} : {
142
- ...getAllPropertyDescriptors(proto),
143
- ...Object.getOwnPropertyDescriptors(obj)
144
- };
145
- }
146
- }
@@ -1,46 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import mxHttpMessage from './xxHttpMessage.js';
6
- import xRequestHeaders from './xRequestHeaders.js';
7
- import { formatMessage } from './util-http.js';
8
-
9
- /**
10
- * The xRequest Mixin
11
- */
12
- export default class xRequest extends mxHttpMessage(Request, xRequestHeaders) {
13
-
14
- constructor(input, init = {}, meta = {}) {
15
- if (init instanceof Request) {
16
-
17
- } else if ('body' in init) {
18
- const [ body, headers, type ] = formatMessage(init);
19
- meta = { ...meta, type, body: init.body };
20
- init = { ...init, body, headers };
21
- }
22
- super(input, init, meta);
23
- }
24
-
25
- static compat(request) {
26
- if (request instanceof this) return request;
27
- if (request instanceof Request) {
28
- return Object.setPrototypeOf(request, new this);
29
- }
30
- return new this(request);
31
- }
32
-
33
- static async rip(request) {
34
- const requestInit = [
35
- 'method', 'headers', 'mode', 'credentials', 'cache', 'redirect', 'referrer', 'integrity',
36
- ].reduce((init, prop) => ({ [prop]: request[prop], ...init }), {});
37
- if (!['GET', 'HEAD'].includes(request.method)) {
38
- requestInit.body = await request.clone().arrayBuffer();
39
- }
40
- if (requestInit.mode === 'navigate') {
41
- requestInit.mode = 'cors';
42
- }
43
- return [ request.url, requestInit ];
44
- }
45
-
46
- }
@@ -1,109 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _after } from "@webqit/util/str/index.js";
6
- import { _from as _arrFrom } from "@webqit/util/arr/index.js";
7
- import { params } from './util-url.js';
8
- import xHeaders from './xHeaders.js';
9
- import xCookies from './Cookies.js';
10
-
11
- /**
12
- * The xHeaders Mixin
13
- */
14
- export default class xRequestHeaders extends xHeaders {
15
-
16
- get cookieHeaderName() {
17
- return 'Cookie';
18
- }
19
-
20
- get cookieHeaderSeparator() {
21
- return ';';
22
- }
23
-
24
- get Cookies() {
25
- return Cookies;
26
- }
27
-
28
- set accept(value) {
29
- return this.set('Accept', value);
30
- }
31
-
32
- get accept() {
33
- const accept = this.get('Accept');
34
- const list = accept && accept.split(',').map(a => (a = a.trim().split(';').map(a => a.trim()), [a.shift(), parseFloat((a.pop() || '1').replace('q=', ''))]))
35
- .sort((a, b) => a[1] > b[1] ? -1 : 1) || [];
36
- return {
37
- match(mime) {
38
- mime = (mime + '').split('/');
39
- return list.reduce((prev, entry) => prev || (
40
- (entry = entry[0].split('/')) && [0, 1].every(i => ((mime[i] === entry[i]) || mime[i] === '*' || entry[i] === '*'))
41
- ), false);
42
- },
43
- toString() {
44
- return accept;
45
- }
46
- };
47
- }
48
-
49
- set range(value) {
50
- let rangeArr = [];
51
- _arrFrom(value).forEach((range, i) => {
52
- let rangeStr = Array.isArray(range) ? range.join('-') : range + '';
53
- if (i === 0 && !rangeStr.includes('bytes=')) {
54
- rangeStr = `bytes=${rangeStr}`;
55
- }
56
- rangeArr.push(rangeStr);
57
- });
58
- return this.set('Range', rangeArr.join(', '));
59
- }
60
-
61
- get range() {
62
- const value = this.get('Range');
63
- if (!value) return;
64
- const rangeArr = _after(value, 'bytes=').split(',').map(rangeStr => {
65
- let range = rangeStr.trim().split('-');
66
- range[0] = range[0] ? parseInt(range[0], 10) : undefined;
67
- if (range[1]) {
68
- range[1] = parseInt(range[1], 10);
69
- }
70
- range.clamp = max => {
71
- if (range[1] > max - 1 || range[1] === undefined) {
72
- range[1] = max - 1;
73
- }
74
- if (range[0] === undefined) range[0] = range[1] ? max - range[1] - 1 : 0;
75
- };
76
- return range;
77
- });
78
- return rangeArr;
79
- }
80
-
81
- set cors(value) {
82
- return this.set('Access-Control-Allow-Origin', value === true ? '*' : (value === false ? '' : value));
83
- }
84
-
85
- get cors() {
86
- return this.get('Access-Control-Allow-Origin');
87
- }
88
-
89
-
90
- }
91
-
92
- /**
93
- * Cookies
94
- */
95
- class Cookies extends xCookies {
96
-
97
- parse(str) {
98
- return params.parse(str, ';');
99
- }
100
-
101
- parseEntry(str) {
102
- return str.trim().split('=');
103
- }
104
-
105
- stringifyEntry(cookieBody) {
106
- return cookieBody;
107
- }
108
-
109
- }
@@ -1,33 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import mxHttpMessage from './xxHttpMessage.js';
6
- import xResponseHeaders from './xResponseHeaders.js';
7
- import { formatMessage } from './util-http.js';
8
-
9
- /**
10
- * The xResponse Mixin
11
- */
12
- export default class xResponse extends mxHttpMessage(Response, xResponseHeaders) {
13
-
14
- // construct
15
- constructor(body = null, init = {}, meta = {}) {
16
- if (body || body === 0) {
17
- let headers, type, _body = body;
18
- [ body, headers, type ] = formatMessage({ body, headers: init.headers });
19
- meta = { ...init, type, body: _body };
20
- init = { ...init, headers };
21
- }
22
- super(body, init, meta);
23
- }
24
-
25
- static compat(response) {
26
- if (response instanceof this) return response;
27
- if (response instanceof Response) {
28
- return Object.setPrototypeOf(response, new this);
29
- }
30
- return new this(response);
31
- }
32
-
33
- }
@@ -1,117 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _after, _beforeLast } from "@webqit/util/str/index.js";
6
- import { _isString, _getType, _isObject } from "@webqit/util/js/index.js";
7
- import xHeaders from './xHeaders.js';
8
- import xCookies from './Cookies.js';
9
-
10
- /**
11
- * The _Headers Mixin
12
- */
13
- export default class xResponseHeaders extends xHeaders {
14
-
15
- get cookieHeaderName() {
16
- return 'Set-Cookie';
17
- }
18
-
19
- get cookieHeaderSeparator() {
20
- return ',';
21
- }
22
-
23
- get Cookies() {
24
- return Cookies;
25
- }
26
-
27
- set contentRange(value) {
28
- if (Array.isArray(value)) {
29
- if ((value.length === 2 && !value[0].includes('-')) || value.length < 2) {
30
- throw new Error(`A Content-Range array must be in the format: [ 'start-end', 'total' ]`);
31
- }
32
- return this.set('Content-Range', `bytes ${value.join('/')}`);
33
- }
34
- return this.set('Content-Range', value);
35
- }
36
-
37
- get contentRange() {
38
- const value = this.get('Content-Range');
39
- return value && _after(value, 'bytes ').split('/');
40
- }
41
-
42
- set cors(value) {
43
- return this.set('Access-Control-Allow-Origin', value === true ? '*' : (value === false ? '' : value));
44
- }
45
-
46
- get cors() {
47
- return this.get('Access-Control-Allow-Origin');
48
- }
49
-
50
- set attachment(value) {
51
- value = value === true ? 'attachment' : (value === false ? 'inline' : value);
52
- if (!_isString(value)) {
53
- throw new Error(`The "download" response directive does not support the type: ${_getType(value)}`);
54
- }
55
- if (![ 'attachment', 'inline' ].includes(value)) {
56
- value = `attachment; filename="${value}"`;
57
- }
58
- return this.set('Content-Disposition', value);
59
- }
60
-
61
- get attachment() {
62
- var value = (this.get('Content-Disposition') || '').trim();
63
- value = value === 'attachment' ? true : (
64
- value === 'inline' ? false : _after(_beforeLast(value, '"'), 'filename="')
65
- );
66
- return value;
67
- }
68
-
69
- get location() {
70
- return this.get('Location');
71
- }
72
-
73
- set location(value) {
74
- return this.set('Location', value);
75
- }
76
-
77
- }
78
-
79
- /**
80
- * Cookies
81
- */
82
- class Cookies extends xCookies {
83
-
84
- parse(cookieStr) {
85
- const obj = {};
86
- cookieStr && cookieStr.split(',').forEach(str => {
87
- let [ cookieName, definition ] = this.parseEntry(str);
88
- obj[cookieName] = definition;
89
- });
90
- return obj;
91
- }
92
-
93
- parseEntry(str) {
94
- let [ cookieDefinition, attrsStr ] = str.split(';');
95
- let [ cookieName, cookieValue ] = cookieDefinition.trim().split('=');
96
- let attrs = { value: cookieValue, };
97
- attrsStr && (attrsStr || '').split(/\;/g).map(attrStr => attrStr.trim().split('=')).forEach(attrsArr => {
98
- attrs[attrsArr[0][0].toLowerCase() + attrsArr[0].substring(1).replace('-', '')] = attrsArr.length === 1 ? true : attrsArr[1];
99
- });
100
- return [ cookieName, attrs ];
101
- }
102
-
103
- stringifyEntry(cookieBody) {
104
- if (_isObject(cookieBody)) {
105
- let attrsArr = [ cookieBody.value ];
106
- for (let attrName in cookieBody) {
107
- if (attrName === 'value') continue;
108
- let _attrName = attrName[0].toUpperCase() + attrName.substring(1);
109
- if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
110
- attrsArr.push(cookieBody[attrName] === true ? _attrName : `${_attrName}=${cookieBody[attrName]}`);
111
- }
112
- cookieBody = attrsArr.join(';');
113
- }
114
- return cookieBody;
115
- }
116
-
117
- }
@@ -1,105 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _isObject, _isArray } from '@webqit/util/js/index.js';
6
- import { params } from './util-url.js';
7
-
8
- /**
9
- * ---------------------------
10
- * The xURL Mixin
11
- * ---------------------------
12
- */
13
- export default class xURL extends URL {
14
-
15
- // constructor
16
- constructor(...args) {
17
- super(...args);
18
- var query = params.parse(this.search);
19
- const updateSearch = query => {
20
- // "query" was updated. So we update "search"
21
- var search = params.stringify(query);
22
- search = search ? '?' + search : '';
23
- if (search !== this.search) {
24
- this.search = search;
25
- }
26
- };
27
- this.__query = {
28
- value: query,
29
- proxy: new Proxy(this, {
30
- set(t, n, v) {
31
- t.__query.value[n] = v;
32
- updateSearch(t.__query.value);
33
- return true;
34
- },
35
- deleteProperty(t, n) {
36
- delete t.__query.value[n];
37
- updateSearch(t.__query.value);
38
- return true;
39
- }
40
- })
41
- };
42
- }
43
-
44
- // Set search
45
- set search(value) {
46
- super.search = value;
47
- // "search" was updated. So we update "query"
48
- var query = params.parse(value);
49
- if (!_strictEven(query, this.query)) {
50
- this.__query.value = query;
51
- }
52
- }
53
-
54
- // Get search
55
- get search() {
56
- return super.search;
57
- }
58
-
59
- // Get query
60
- get query() {
61
- return this.__query.proxy;
62
- }
63
-
64
- };
65
- // ----------
66
- xURL.Observable = class extends xURL {
67
-
68
- constructor() {
69
- super(...arguments);
70
- const { Observer } = webqit;
71
- Observer.accessorize(this, [
72
- 'protocol',
73
- 'username',
74
- 'password',
75
- 'host',
76
- 'hostname',
77
- 'port',
78
- 'origin',
79
- 'pathname',
80
- 'search',
81
- 'query',
82
- 'hash',
83
- 'href',
84
- ]);
85
- }
86
-
87
- };
88
-
89
- /**
90
- * ---------------------------
91
- * Helpers
92
- * ---------------------------
93
- */
94
- var _strictEven = (a, b) => {
95
- if (_isObject(a) && _isObject(b)) {
96
- return _strictEven(Object.keys(a), Object.keys(b))
97
- && _strictEven(Object.values(a), Object.values(b));
98
- }
99
- if (_isArray(a) && _isArray(b)) {
100
- return a.length === b.length
101
- && a.reduce((recieved, item, i) => recieved && item === b[i], true);
102
- }
103
- return a === b;
104
- };
105
-
@@ -1,23 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { formatMessage } from './util-http.js';
6
-
7
- /**
8
- * The xfetch Mixin
9
- */
10
- const xfetch = async (url, init = {}) => {
11
- if (init.body) {
12
- const [ body, headers ] = formatMessage(init);
13
- init = { ...init, body, headers, };
14
- }
15
- let response = await fetch(url, init), encoding;
16
- if (init.decompress === false && (encoding = response.headers.get('Content-Encoding'))) {
17
- let recompressedBody = response.body.pipeThrough(new CompressionStream(encoding));
18
- response = new Response(recompressedBody, response);
19
- }
20
- return response;
21
- };
22
-
23
- export default xfetch;