@webqit/webflo 1.0.37 → 1.0.38

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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "1.0.37",
15
+ "version": "1.0.38",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -22,7 +22,7 @@ export class MessagingOverSocket extends WebfloMessagingAPI {
22
22
  this.dispatchEvent(new SocketMessageEvent(
23
23
  this,
24
24
  json.messageType,
25
- json.message,
25
+ json.messageUndefined ? undefined : json.message,
26
26
  json.messageID,
27
27
  json.numPorts
28
28
  ));
@@ -61,7 +61,8 @@ export class MessagingOverSocket extends WebfloMessagingAPI {
61
61
  const messageID = (0 | Math.random() * 9e6).toString(36);
62
62
  this.#socket.send(JSON.stringify({
63
63
  messageType,
64
- message,
64
+ message: message === undefined ? null : message,
65
+ messageUndefined: message === undefined,
65
66
  messageID,
66
67
  numPorts: messagePorts.length
67
68
  }), options);
@@ -9,6 +9,8 @@ export class WebfloMessagingAPI extends WebfloEventTarget {
9
9
  isMessaging() { return this.#isSending || !!this.length; }
10
10
 
11
11
  #hooks = new Set;
12
+ get $hooks() { return this.#hooks; }
13
+
12
14
  on(eventName, callback, { once = false } = {}) {
13
15
  if (eventName === 'connected' && this.#isConnected) {
14
16
  callback();
@@ -282,7 +282,9 @@ export class WebfloClient extends WebfloRuntime {
282
282
  location = typeof location === 'string' ? new URL(location, this.location.origin) : location;
283
283
  if (this.isSpaRoute(location)) {
284
284
  await this.navigate(location, {}, { navigationType: 'rdr' });
285
- } else this.hardRedirect(location, backgroundMessaging);
285
+ } else {
286
+ this.hardRedirect(location, backgroundMessaging);
287
+ }
286
288
  }
287
289
 
288
290
  hardRedirect(location, backgroundMessaging) {
@@ -94,6 +94,44 @@ export class WebfloRootClient1 extends WebfloClient {
94
94
  };
95
95
  cleanups.push(this.backgroundMessaging.handleMessages('confirm', promptsHandler));
96
96
  cleanups.push(this.backgroundMessaging.handleMessages('prompt', promptsHandler));
97
+ cleanups.push(this.backgroundMessaging.handleRequests('ua:query', async (e) => {
98
+ e.stopPropagation();
99
+ if (e.data?.query === 'push_registration') {
100
+ const pushManager = (await navigator.serviceWorker.getRegistration()).pushManager;
101
+ const r = await pushManager.getSubscription();
102
+ return r;
103
+ }
104
+ }));
105
+ cleanups.push(this.backgroundMessaging.handleRequests('storage:query', (e) => {
106
+ e.stopPropagation();
107
+ const { source, namespace, query, key, value } = e.data;
108
+ const storage = source === 'session' ? sessionStorage : (source === 'local' ? localStorage : null);
109
+ if (!storage) return;
110
+ const data = JSON.parse(storage.getItem(namespace) || (query === 'set' ? '{}' : 'null'));
111
+ switch (query) {
112
+ case 'has':
113
+ return !!data && Reflect.has(data, key);
114
+ case 'get':
115
+ return data && Reflect.get(data, key);
116
+ case 'set':
117
+ Reflect.set(data, key, value);
118
+ return storage.setItem(namespace, JSON.stringify(data))
119
+ case 'delete':
120
+ if (!data) return;
121
+ Reflect.deleteProperty(data, key);
122
+ return storage.setItem(namespace, JSON.stringify(data));
123
+ case 'clear':
124
+ return storage.removeItem(namespace);
125
+ case 'keys':
126
+ return data && Reflect.ownKeys(data) || [];
127
+ case 'values':
128
+ return data && Object.values(data) || [];
129
+ case 'entries':
130
+ return data && Object.entries(data) || [];
131
+ case 'size':
132
+ return data && Object.keys(data).length || 0;
133
+ }
134
+ }));
97
135
  // --------
98
136
  // HYDRATION
99
137
  const scope = {};
@@ -239,8 +239,8 @@ export class WebfloServer extends WebfloRuntime {
239
239
  async delete(key) { return await redis.hdel(namespace, key); },
240
240
  async clear() { return await redis.del(namespace); },
241
241
  async keys() { return await redis.hkeys(namespace); },
242
- async values() { return (await redis.hvals(namespace) || []).map((value) => JSON.parse(value)); },
243
- async entries() { return Object.entries(await redis.hgetall(namespace) || {}).map(([key, value]) => [key, JSON.parse(value)]); },
242
+ async values() { return (await redis.hvals(namespace) || []).map((value) => typeof value === 'undefined' ? value : JSON.parse(value)); },
243
+ async entries() { return Object.entries(await redis.hgetall(namespace) || {}).map(([key, value]) => [key, typeof value === 'undefined' ? value : JSON.parse(value)]); },
244
244
  get size() { return redis.hlen(namespace); },
245
245
  });
246
246
  } else {