@webqit/webflo 0.20.25 → 0.20.27

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 (57) hide show
  1. package/package.json +8 -5
  2. package/src/build-pi/index.js +7 -5
  3. package/src/init-pi/index.js +0 -1
  4. package/src/runtime-pi/{WebfloRuntime.js → AppRuntime.js} +57 -113
  5. package/src/runtime-pi/webflo-client/DeviceCapabilities.js +1 -1
  6. package/src/runtime-pi/webflo-client/WebfloClient.js +163 -95
  7. package/src/runtime-pi/webflo-client/{WebfloRootClient1.js → WebfloRootClientA.js} +39 -56
  8. package/src/runtime-pi/webflo-client/{WebfloRootClient2.js → WebfloRootClientB.js} +3 -3
  9. package/src/runtime-pi/webflo-client/WebfloSubClient.js +28 -15
  10. package/src/runtime-pi/webflo-client/index.js +3 -3
  11. package/src/runtime-pi/webflo-messaging/ClientPortMixin.js +13 -0
  12. package/src/runtime-pi/{webflo-server/messaging/ClientRequestRealtime.js → webflo-messaging/ClientRequestPort001.js} +13 -9
  13. package/src/runtime-pi/webflo-messaging/ClientRequestPort010.js +4 -0
  14. package/src/runtime-pi/webflo-messaging/ClientRequestPort100.js +17 -0
  15. package/src/runtime-pi/webflo-messaging/WebfloTenancy001.js +27 -0
  16. package/src/runtime-pi/webflo-messaging/WebfloTenant001.js +27 -0
  17. package/src/runtime-pi/webflo-routing/HttpCookies101.js +53 -0
  18. package/src/runtime-pi/webflo-routing/HttpCookies110.js +3 -0
  19. package/src/runtime-pi/webflo-routing/{HttpEvent.js → HttpEvent111.js} +95 -73
  20. package/src/runtime-pi/webflo-routing/HttpKeyvalInterface.js +120 -0
  21. package/src/runtime-pi/webflo-routing/HttpSession001.js +24 -0
  22. package/src/runtime-pi/webflo-routing/HttpSession110.js +3 -0
  23. package/src/runtime-pi/webflo-routing/{HttpThread.js → HttpThread111.js} +54 -13
  24. package/src/runtime-pi/webflo-routing/{HttpUser.js → HttpUser111.js} +10 -23
  25. package/src/runtime-pi/webflo-routing/KeyvalsFactory001.js +53 -0
  26. package/src/runtime-pi/webflo-routing/KeyvalsFactory110.js +48 -0
  27. package/src/runtime-pi/webflo-routing/KeyvalsFactoryInterface.js +56 -0
  28. package/src/runtime-pi/webflo-routing/{WebfloRouter.js → WebfloRouter111.js} +5 -6
  29. package/src/runtime-pi/webflo-server/WebfloServer.js +262 -266
  30. package/src/runtime-pi/webflo-worker/WebfloWorker.js +97 -44
  31. package/src/util.js +3 -2
  32. package/src/runtime-pi/apis.js +0 -9
  33. package/src/runtime-pi/webflo-client/ClientSideCookies.js +0 -18
  34. package/src/runtime-pi/webflo-fetch/LiveResponse.js +0 -476
  35. package/src/runtime-pi/webflo-fetch/index.js +0 -419
  36. package/src/runtime-pi/webflo-fetch/util.js +0 -28
  37. package/src/runtime-pi/webflo-messaging/WQBroadcastChannel.js +0 -10
  38. package/src/runtime-pi/webflo-messaging/WQMessageChannel.js +0 -26
  39. package/src/runtime-pi/webflo-messaging/WQMessageEvent.js +0 -87
  40. package/src/runtime-pi/webflo-messaging/WQMessagePort.js +0 -38
  41. package/src/runtime-pi/webflo-messaging/WQRelayPort.js +0 -47
  42. package/src/runtime-pi/webflo-messaging/WQSockPort.js +0 -111
  43. package/src/runtime-pi/webflo-messaging/WQStarPort.js +0 -112
  44. package/src/runtime-pi/webflo-messaging/wq-message-port.js +0 -413
  45. package/src/runtime-pi/webflo-routing/HttpCookies.js +0 -43
  46. package/src/runtime-pi/webflo-routing/HttpSession.js +0 -11
  47. package/src/runtime-pi/webflo-routing/HttpState.js +0 -182
  48. package/src/runtime-pi/webflo-server/ServerSideCookies.js +0 -22
  49. package/src/runtime-pi/webflo-server/ServerSideSession.js +0 -40
  50. package/src/runtime-pi/webflo-server/messaging/Client.js +0 -27
  51. package/src/runtime-pi/webflo-server/messaging/Clients.js +0 -25
  52. package/src/runtime-pi/webflo-url/Url.js +0 -156
  53. package/src/runtime-pi/webflo-url/index.js +0 -1
  54. package/src/runtime-pi/webflo-url/urlpattern.js +0 -38
  55. package/src/runtime-pi/webflo-url/util.js +0 -109
  56. package/src/runtime-pi/webflo-url/xURL.js +0 -94
  57. package/src/runtime-pi/webflo-worker/WorkerSideCookies.js +0 -21
@@ -1,35 +1,62 @@
1
1
  import { _any } from '@webqit/util/arr/index.js';
2
- import { WebfloRuntime } from '../WebfloRuntime.js';
3
- import { response as responseShim } from '../webflo-fetch/index.js';
4
- import { WQBroadcastChannel } from '../webflo-messaging/WQBroadcastChannel.js';
2
+ import { RequestPlus } from '@webqit/fetch-plus';
3
+ import { URLPatternPlus } from '@webqit/url-plus';
5
4
  import { WorkerSideWorkport } from './WorkerSideWorkport.js';
6
- import { WorkerSideCookies } from './WorkerSideCookies.js';
7
- import '../webflo-fetch/index.js';
8
- import '../webflo-url/index.js';
5
+ import { HttpThread111 } from '../webflo-routing/HttpThread111.js';
6
+ import { HttpCookies110 } from '../webflo-routing/HttpCookies110.js';
7
+ import { HttpSession110 } from '../webflo-routing/HttpSession110.js';
8
+ import { HttpUser111 } from '../webflo-routing/HttpUser111.js';
9
+ import { HttpEvent111 } from '../webflo-routing/HttpEvent111.js';
10
+ import { KeyvalsFactory110 } from '../webflo-routing/KeyvalsFactory110.js';
11
+ import { ClientRequestPort010 } from '../webflo-messaging/ClientRequestPort010.js';
12
+ import { AppRuntime } from '../AppRuntime.js';
9
13
 
10
- export class WebfloWorker extends WebfloRuntime {
11
-
12
- static get HttpCookies() { return WorkerSideCookies; }
14
+ export class WebfloWorker extends AppRuntime {
13
15
 
14
16
  static get Workport() { return WorkerSideWorkport; }
15
17
 
18
+ #keyvals;
19
+ get keyvals() { return this.#keyvals; }
20
+
16
21
  async initialize() {
17
- const instanceController = super.initialize();
22
+ // ----------
23
+ // The keyvals API
24
+ this.#keyvals = new KeyvalsFactory110;
25
+
26
+ // ----------
27
+ // Call default-init
28
+ const instanceController = await super.initialize();
29
+
18
30
  // ONINSTALL
19
31
  const installHandler = (event) => {
20
32
  if (this.config.WORKER.skip_waiting) self.skipWaiting();
21
33
  // Manage CACHE
22
- if (this.config.WORKER.cache_name && (this.config.WORKER.cache_only_urls || []).length) {
34
+ if (this.config.WORKER.cache_name && (
35
+ (this.config.WORKER.cache_first_urls || []).length || (this.config.WORKER.cache_only_urls || []).length
36
+ )) {
23
37
  // Add files to cache
24
38
  event.waitUntil(self.caches.open(this.config.WORKER.cache_name).then(async cache => {
25
39
  if (this.cx.logger) { this.cx.logger.log('[ServiceWorker] Pre-caching resources.'); }
26
- for (const urls of ['cache_first_urls', 'cache_only_urls']) {
27
- const _urls = (this.config.WORKER[urls] || []).map(c => c.trim()).filter(c => c && !(new URLPattern(c, self.origin)).isPattern());
28
- await cache.addAll(_urls);
40
+ const promises = [];
41
+ for (const key of ['cache_first_urls', 'cache_only_urls']) {
42
+ const urls = this.config.WORKER[key];
43
+ if (!urls?.length) continue;
44
+ const _urls = urls.map((c) => c.trim()).filter(c => c && !(new URLPatternPlus(c, self.origin)).isPattern());
45
+ for (let url of _urls) {
46
+ //url = new URL(url, self.origin).href;
47
+ promises.push(fetch(url).then(async (res) => {
48
+ if (!res.ok) return 0;
49
+ await cache.put(url, res);
50
+ return 1;
51
+ }).catch(() => -1));
52
+ }
29
53
  }
54
+ await Promise.all(promises);
30
55
  }));
31
56
  }
32
57
  };
58
+ self.addEventListener('install', installHandler, { signal: instanceController.signal });
59
+
33
60
  // ONACTIVATE
34
61
  const activateHandler = (event) => {
35
62
  event.waitUntil(new Promise(async resolve => {
@@ -49,9 +76,10 @@ export class WebfloWorker extends WebfloRuntime {
49
76
  resolve();
50
77
  }));
51
78
  };
52
- self.addEventListener('install', installHandler, { signal: instanceController.signal });
53
79
  self.addEventListener('activate', activateHandler, { signal: instanceController.signal });
80
+
54
81
  this.control();
82
+
55
83
  return instanceController;
56
84
  }
57
85
 
@@ -77,7 +105,7 @@ export class WebfloWorker extends WebfloRuntime {
77
105
  let data;
78
106
  try {
79
107
  data = event.data?.json() ?? {};
80
- } catch(e) { return; }
108
+ } catch (e) { return; }
81
109
  const { type, title, ...params } = data;
82
110
  if (type !== 'notification') return;
83
111
  self.registration.showNotification(title, params);
@@ -90,48 +118,73 @@ export class WebfloWorker extends WebfloRuntime {
90
118
  }
91
119
 
92
120
  async navigate(url, init = {}, detail = {}) {
93
- // Resolve inputs
94
- const scopeObj = { url, init, detail };
121
+ // Scope object
122
+ const scopeObj = {
123
+ url,
124
+ init,
125
+ detail,
126
+ requestID: (0 | Math.random() * 9e6).toString(36),
127
+ tenantID: 'anon',
128
+ };
95
129
  if (typeof scopeObj.url === 'string') {
96
130
  scopeObj.url = new URL(scopeObj.url, self.location.origin);
97
131
  }
98
- // Create and route request
99
- scopeObj.request = this.createRequest(scopeObj.url, scopeObj.init);
100
- scopeObj.thread = this.createHttpThread({
101
- store: this.createStorage('thread'),
102
- threadId: scopeObj.url.searchParams.get('_thread'),
103
- realm: 2
104
- });
105
- scopeObj.cookies = this.createHttpCookies({
106
- request: scopeObj.request,
107
- thread: scopeObj.thread,
132
+
133
+ // Request
134
+ scopeObj.request = scopeObj.init instanceof Request && scopeObj.init.url === scopeObj.url.href
135
+ ? scopeObj.init
136
+ : this.createRequest(scopeObj.url, scopeObj.init);
137
+ RequestPlus.upgradeInPlace(scopeObj.request);
138
+
139
+ // Origins
140
+ const origins = [scopeObj.requestID];
141
+
142
+ // Thread
143
+ scopeObj.thread = HttpThread111.create({
144
+ context: {},
145
+ store: this.#keyvals.create({ path: ['thread', scopeObj.tenantID], origins }),
146
+ threadID: scopeObj.url.searchParams.get('_thread'),
108
147
  realm: 2
109
148
  });
110
- scopeObj.session = this.createHttpSession({
111
- store: this.createStorage('session'),
112
- request: scopeObj.request,
113
- thread: scopeObj.thread,
149
+
150
+ // Cookies
151
+ const type = typeof cookieStore === 'undefined' ? 'inmemory' : 'cookiestore';
152
+ scopeObj.cookies = HttpCookies110.create({
153
+ context: { handlersRegistry: this.#keyvals.getHandlers('cookies', true) },
154
+ store: this.#keyvals.create({ type, path: ['cookies', scopeObj.tenantID], origins }),
114
155
  realm: 2
115
156
  });
116
- const requestID = crypto.randomUUID();
117
- scopeObj.clientRequestRealtime = new WQBroadcastChannel(requestID);
118
- scopeObj.user = this.createHttpUser({
119
- store: this.createStorage('user'),
120
- request: scopeObj.request,
121
- thread: scopeObj.thread,
122
- client: scopeObj.clientRequestRealtime,
157
+
158
+ // Session
159
+ scopeObj.session = HttpSession110.create({
160
+ context: { handlersRegistry: this.#keyvals.getHandlers('session', true) },
161
+ store: this.#keyvals.create({ path: ['session', scopeObj.tenantID], origins }),
162
+ realm: 2
163
+ });
164
+
165
+ // User
166
+ scopeObj.user = HttpUser111.create({
167
+ context: { handlersRegistry: this.#keyvals.getHandlers('user', true) },
168
+ store: this.#keyvals.create({ path: ['user', scopeObj.tenantID], origins }),
123
169
  realm: 2
124
170
  });
125
- scopeObj.httpEvent = this.createHttpEvent({
171
+
172
+ // Client
173
+ scopeObj.clientRequestRealtime = new ClientRequestPort010(scopeObj.requestID, { handshake: 1, postAwaitsOpen: true, clientServerMode: 'server', autoClose: true });
174
+
175
+ // HttpEvent
176
+ scopeObj.httpEvent = HttpEvent111.create({
177
+ detail: scopeObj.detail,
178
+ signal: init.signal,
126
179
  request: scopeObj.request,
127
180
  thread: scopeObj.thread,
128
- client: scopeObj.clientRequestRealtime,
129
181
  cookies: scopeObj.cookies,
130
182
  session: scopeObj.session,
131
183
  user: scopeObj.user,
132
- detail: scopeObj.detail,
184
+ client: scopeObj.clientRequestRealtime,
133
185
  realm: 2
134
186
  });
187
+
135
188
  // Dispatch for response
136
189
  scopeObj.response = await this.dispatchNavigationEvent({
137
190
  httpEvent: scopeObj.httpEvent,
@@ -142,7 +195,7 @@ export class WebfloWorker extends WebfloRuntime {
142
195
  }
143
196
  return await this.remoteFetch(event.request);
144
197
  },
145
- clientPortB: `br:${scopeObj.httpEvent.client.name}`
198
+ clientPortB: `channel://${scopeObj.httpEvent.client.name}`
146
199
  });
147
200
  return scopeObj.response;
148
201
  }
@@ -209,7 +262,7 @@ export class WebfloWorker extends WebfloRuntime {
209
262
 
210
263
  async refreshCache(request, response) {
211
264
  // Check if we received a valid response
212
- const statusCode = responseShim.prototype.status.get.call(response);
265
+ const statusCode = response.status;
213
266
  if (request.method !== 'GET' || !response || statusCode !== 200 || (response.type !== 'basic' && response.type !== 'cors')) {
214
267
  return response;
215
268
  }
package/src/util.js CHANGED
@@ -1,6 +1,7 @@
1
- import { _wq as __wq } from '@webqit/util/js/index.js';
1
+ import { _wq as $wq } from '@webqit/util/js/index.js';
2
2
 
3
- export const _wq = (target, ...args) => __wq(target, 'webflo', ...args);
3
+ export const _wq = (target, ...args) => $wq(target, 'webflo', ...args);
4
+ export const _meta = (target, ...args) => $wq(target, 'webflo', 'meta', ...args);
4
5
 
5
6
  export const _await = (value, callback) => {
6
7
  if (value instanceof Promise) {
@@ -1,9 +0,0 @@
1
- import { LiveResponse } from './webflo-fetch/LiveResponse.js';
2
- import { Observer } from '@webqit/use-live';
3
- import { shim } from './webflo-fetch/index.js';
4
-
5
- export {
6
- LiveResponse,
7
- Observer,
8
- shim,
9
- }
@@ -1,18 +0,0 @@
1
- import { HttpCookies } from '../webflo-routing/HttpCookies.js';
2
-
3
- export class ClientSideCookies extends HttpCookies {
4
- static create({ request, thread }) {
5
- return new this({
6
- request,
7
- thread,
8
- entries: document.cookie.split(';').map((c) => c.split('=').map((s) => s.trim()))
9
- });
10
- }
11
-
12
- async commit(response) {
13
- for (const cookieStr of await this.render()) {
14
- document.cookie = cookieStr;
15
- }
16
- await super.commit();
17
- }
18
- }