@webqit/webflo 0.8.74 → 0.8.77
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 +1 -1
- package/src/runtime/_Request.js +2 -4
- package/src/runtime/client/Navigator.js +1 -1
- package/src/runtime/client/Storage.js +8 -7
- package/src/runtime/client/Worker.js +8 -2
- package/src/runtime/client/{Cache.js → archive/Cache.js} +0 -0
- package/src/runtime/client/{Http.js → archive/Http.js} +0 -0
- package/src/runtime/client/{StdRequest.js → archive/StdRequest.js} +0 -0
- package/src/runtime/client/{WorkerComm.js → archive/WorkerComm.js} +0 -0
- package/src/runtime/server/Runtime.js +8 -0
package/package.json
CHANGED
package/src/runtime/_Request.js
CHANGED
|
@@ -32,10 +32,8 @@ const _Request = globals => class extends _MessageStream(globals.Request, _Reque
|
|
|
32
32
|
// Init can contain "already-parsed request content"
|
|
33
33
|
if (('body' in init)) {
|
|
34
34
|
init = { ...init };
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
init.body = _typedDataCache.body;
|
|
38
|
-
}
|
|
35
|
+
_typedDataCache = encodeBody(init.body, globals);
|
|
36
|
+
init.body = _typedDataCache.body;
|
|
39
37
|
}
|
|
40
38
|
if (!_isEmpty(init)) {
|
|
41
39
|
super(input, init);
|
|
@@ -157,7 +157,6 @@ export default class Navigator {
|
|
|
157
157
|
...params,
|
|
158
158
|
headers: {
|
|
159
159
|
'Accept': 'application/json',
|
|
160
|
-
'Cache-Control': 'no-store',
|
|
161
160
|
'X-Redirect-Policy': 'manual-when-cross-origin',
|
|
162
161
|
'X-Redirect-Code': xRedirectCode,
|
|
163
162
|
'X-Powered-By': '@webqit/webflo',
|
|
@@ -224,6 +223,7 @@ export default class Navigator {
|
|
|
224
223
|
this._abortController = new AbortController();
|
|
225
224
|
let xRedirectCode = 300;
|
|
226
225
|
|
|
226
|
+
|
|
227
227
|
if (params.srcType === 'init' || !(_before(url.href, '#') === _before(params.referrer, '#') && (params.method || 'GET').toUpperCase() === 'GET')) {
|
|
228
228
|
handleResponse(this.client.call(this, generateRequest(url.href, params), params, remoteRequest), params);
|
|
229
229
|
}
|
|
@@ -6,30 +6,31 @@
|
|
|
6
6
|
import { _isString, _isUndefined } from '@webqit/util/js/index.js';
|
|
7
7
|
import { Observer } from './Runtime.js';
|
|
8
8
|
|
|
9
|
-
export default function(persistent = false) {
|
|
9
|
+
export default function(persistent = false, namespace = null) {
|
|
10
10
|
|
|
11
11
|
const storeType = persistent ? 'localStorage' : 'sessionStorage';
|
|
12
12
|
if (!window[storeType]) {
|
|
13
|
-
throw new Error(`The specified Web Storage API ${storeType} is invalid or not supported`)
|
|
13
|
+
throw new Error(`The specified Web Storage API ${storeType} is invalid or not supported`);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const _storage = {};
|
|
17
17
|
Observer.intercept(_storage, (event, received, next) => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const key = namespace ? `${namespace}.${event.name}` : event.name;
|
|
19
|
+
if (event.type === 'get' && _isString(key)) {
|
|
20
|
+
const value = window[storeType].getItem(key);
|
|
20
21
|
return !_isUndefined(value) ? JSON.parse(value) : value;
|
|
21
22
|
}
|
|
22
23
|
if (event.type === 'set') {
|
|
23
|
-
window[storeType].setItem(
|
|
24
|
+
window[storeType].setItem(key, !_isUndefined(event.value) ? JSON.stringify(event.value) : event.value);
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
26
27
|
if (event.type === 'deleteProperty') {
|
|
27
|
-
window[storeType].removeItem(
|
|
28
|
+
window[storeType].removeItem(key);
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
if (event.type === 'has') {
|
|
31
32
|
for(var i = 0; i < window[storeType].length; i ++){
|
|
32
|
-
if (window[storeType].key(i) ===
|
|
33
|
+
if (window[storeType].key(i) === key) {
|
|
33
34
|
return true;
|
|
34
35
|
}
|
|
35
36
|
};
|
|
@@ -103,10 +103,15 @@ export default function(layout, params) {
|
|
|
103
103
|
|
|
104
104
|
if (evt.request.url.startsWith(self.origin) && (evt.request.mode === 'navigate' || evt.request.headers.get('X-Powered-By') === '@webqit/webflo')) {
|
|
105
105
|
// -----------------
|
|
106
|
+
// We must patch the event object with the new request instance
|
|
107
|
+
// cos the body of the original gets consumed (thus invalidated) by the new instance
|
|
108
|
+
Object.defineProperty(evt, 'request', {
|
|
109
|
+
value: new NavigationEvent.Request(evt.request),
|
|
110
|
+
});
|
|
106
111
|
// Sync session data to cache to be available to service-worker routers
|
|
107
112
|
// Sync only takes for requests that actually do send the "$session" cookie
|
|
108
113
|
const sessionData = Observer.proxy(sessionStores[evt.clientId] || {});
|
|
109
|
-
const clientNavigationEvent = new NavigationEvent(
|
|
114
|
+
const clientNavigationEvent = new NavigationEvent(evt.request, sessionData);
|
|
110
115
|
// -----------------
|
|
111
116
|
// The app router
|
|
112
117
|
const router = new Router(_before(evt.request.url, '?'), layout, { layout });
|
|
@@ -120,7 +125,8 @@ export default function(layout, params) {
|
|
|
120
125
|
|
|
121
126
|
return defaultFetch(evt);
|
|
122
127
|
};
|
|
123
|
-
|
|
128
|
+
let response = handleFetch(evt);
|
|
129
|
+
evt.respondWith(response);
|
|
124
130
|
});
|
|
125
131
|
|
|
126
132
|
const defaultFetch = function(evt) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -459,6 +459,13 @@ export async function run(hostSetup, request, response, Ui, flags = {}, protocol
|
|
|
459
459
|
}
|
|
460
460
|
});
|
|
461
461
|
|
|
462
|
+
// -------------------
|
|
463
|
+
// Important no-caching for non-"get" requests
|
|
464
|
+
// -------------------
|
|
465
|
+
if (httpMethodName !== 'get' && !response.getHeader('Cache-Control')) {
|
|
466
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
467
|
+
}
|
|
468
|
+
|
|
462
469
|
// -------------------
|
|
463
470
|
// Send
|
|
464
471
|
// -------------------
|
|
@@ -469,6 +476,7 @@ export async function run(hostSetup, request, response, Ui, flags = {}, protocol
|
|
|
469
476
|
if (xRedirectPolicy === 'manual' || (!isSameOriginRedirect && xRedirectPolicy === 'manual-when-cross-origin') || (isSameOriginRedirect && xRedirectPolicy === 'manual-when-same-origin')) {
|
|
470
477
|
response.statusCode = xRedirectCode;
|
|
471
478
|
response.setHeader('X-Redirect-Code', $context.response.status);
|
|
479
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
472
480
|
} else {
|
|
473
481
|
response.statusCode = $context.response.status;
|
|
474
482
|
}
|