@webqit/webflo 0.20.4-next.2 → 0.20.4-next.3
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 +5 -20
- package/site/docs/concepts/realtime.md +45 -44
- package/site/docs/getting-started.md +40 -40
- package/src/{Context.js → CLIContext.js} +9 -8
- package/src/build-pi/esbuild-plugin-livejs-transform.js +35 -0
- package/src/{runtime-pi/webflo-client/webflo-codegen.js → build-pi/index.js} +145 -141
- package/src/index.js +3 -1
- package/src/init-pi/index.js +6 -3
- package/src/init-pi/templates/pwa/package.json +2 -2
- package/src/init-pi/templates/web/package.json +2 -2
- package/src/runtime-pi/AppBootstrap.js +38 -0
- package/src/runtime-pi/WebfloRuntime.js +50 -47
- package/src/runtime-pi/apis.js +9 -0
- package/src/runtime-pi/index.js +2 -4
- package/src/runtime-pi/webflo-client/WebfloClient.js +31 -35
- package/src/runtime-pi/webflo-client/WebfloRootClient1.js +16 -14
- package/src/runtime-pi/webflo-client/WebfloSubClient.js +13 -13
- package/src/runtime-pi/webflo-client/bootstrap.js +37 -0
- package/src/runtime-pi/webflo-client/index.js +2 -8
- package/src/runtime-pi/webflo-client/webflo-devmode.js +3 -3
- package/src/runtime-pi/webflo-fetch/LiveResponse.js +127 -96
- package/src/runtime-pi/webflo-fetch/index.js +435 -5
- package/src/runtime-pi/webflo-routing/HttpCookies.js +1 -1
- package/src/runtime-pi/webflo-routing/HttpEvent.js +5 -6
- package/src/runtime-pi/webflo-routing/HttpUser.js +7 -7
- package/src/runtime-pi/webflo-server/ServerSideCookies.js +3 -1
- package/src/runtime-pi/webflo-server/ServerSideSession.js +2 -1
- package/src/runtime-pi/webflo-server/WebfloServer.js +98 -195
- package/src/runtime-pi/webflo-server/bootstrap.js +59 -0
- package/src/runtime-pi/webflo-server/index.js +2 -6
- package/src/runtime-pi/webflo-server/webflo-devmode.js +13 -24
- package/src/runtime-pi/webflo-worker/WebfloWorker.js +11 -15
- package/src/runtime-pi/webflo-worker/WorkerSideCookies.js +2 -1
- package/src/runtime-pi/webflo-worker/bootstrap.js +38 -0
- package/src/runtime-pi/webflo-worker/index.js +3 -7
- package/src/webflo-cli.js +1 -2
- package/src/runtime-pi/webflo-fetch/cookies.js +0 -10
- package/src/runtime-pi/webflo-fetch/fetch.js +0 -16
- package/src/runtime-pi/webflo-fetch/formdata.js +0 -54
- package/src/runtime-pi/webflo-fetch/headers.js +0 -151
- package/src/runtime-pi/webflo-fetch/message.js +0 -49
- package/src/runtime-pi/webflo-fetch/request.js +0 -62
- package/src/runtime-pi/webflo-fetch/response.js +0 -110
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { _isObject } from '@webqit/util/js/index.js';
|
|
3
|
-
import { parseHttpMessage, renderHttpMessageInit } from './message.js';
|
|
4
|
-
import { WQBroadcastChannel } from '../webflo-messaging/WQBroadcastChannel.js';
|
|
5
|
-
import { WQSockPort } from '../webflo-messaging/WQSockPort.js';
|
|
6
|
-
import { _wq } from '../../util.js';
|
|
7
|
-
|
|
8
|
-
export function responseRealtimeConnect(url) {
|
|
9
|
-
const [proto, portID] = url.split(':');
|
|
10
|
-
if (proto === 'br') {
|
|
11
|
-
return new WQBroadcastChannel(portID);
|
|
12
|
-
}
|
|
13
|
-
if (proto !== 'ws') {
|
|
14
|
-
throw new Error(`Unknown background messaging protocol: ${proto}`);
|
|
15
|
-
}
|
|
16
|
-
return new WQSockPort(portID);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function responseRealtime() {
|
|
20
|
-
const responseMeta = _wq(this, 'meta');
|
|
21
|
-
if (!responseMeta.has('wqRealtime')) {
|
|
22
|
-
const value = this.headers.get('X-Background-Messaging-Port')?.trim();
|
|
23
|
-
if (value) {
|
|
24
|
-
responseMeta.set('wqRealtime', responseRealtimeConnect(value));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return responseMeta.get('wqRealtime');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const staticOriginals = { json: Response.json };
|
|
31
|
-
const staticExtensions = {
|
|
32
|
-
from: {
|
|
33
|
-
value: function (body, init = {}) {
|
|
34
|
-
if (body instanceof Response) return body;
|
|
35
|
-
let $type, $body = body;
|
|
36
|
-
if (body || body === 0) {
|
|
37
|
-
let headers;
|
|
38
|
-
({ body, headers, $type } = renderHttpMessageInit({ body, headers: init.headers }));
|
|
39
|
-
init = { ...init, headers };
|
|
40
|
-
}
|
|
41
|
-
const instance = new Response(body, init);
|
|
42
|
-
const responseMeta = _wq(instance, 'meta');
|
|
43
|
-
responseMeta.set('body', $body);
|
|
44
|
-
responseMeta.set('type', $type);
|
|
45
|
-
return instance;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
json: {
|
|
49
|
-
value: function (data, options = {}) {
|
|
50
|
-
const instance = staticOriginals.json(data, options);
|
|
51
|
-
const responseMeta = _wq(instance, 'meta');
|
|
52
|
-
responseMeta.set('body', data);
|
|
53
|
-
responseMeta.set('type', 'json');
|
|
54
|
-
return instance;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
redirectWith: {
|
|
58
|
-
value: function (url, { status = 302, request = null, response = null }) {
|
|
59
|
-
if (typeof status !== 'string') {
|
|
60
|
-
throw new Error('Redirect code must be an object!');
|
|
61
|
-
}
|
|
62
|
-
if (request && !_isObject(request) || response && !_isObject(response)) {
|
|
63
|
-
throw new Error('Carries (redirect requests and responses) must be an object!');
|
|
64
|
-
}
|
|
65
|
-
const responseInstance = this.redirect(url, status);
|
|
66
|
-
if (request || response) {
|
|
67
|
-
const responseMeta = _wq(responseInstance, 'meta');
|
|
68
|
-
responseMeta.set('carry', { request, response });
|
|
69
|
-
}
|
|
70
|
-
return responseInstance;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const prototypeOriginals = {
|
|
76
|
-
clone: Response.prototype.clone,
|
|
77
|
-
status: Object.getOwnPropertyDescriptor(Response.prototype, 'status'),
|
|
78
|
-
};
|
|
79
|
-
const prototypeExtensions = {
|
|
80
|
-
status: { get: function () { return _wq(this, 'meta').get('status') || prototypeOriginals.status.get.call(this); } },
|
|
81
|
-
carry: { get: function () { return _wq(this, 'meta').get('carry'); } },
|
|
82
|
-
clone: {
|
|
83
|
-
value: function (init = {}) {
|
|
84
|
-
const clone = prototypeOriginals.clone.call(this, init);
|
|
85
|
-
const responseMeta = _wq(this, 'meta');
|
|
86
|
-
_wq(clone).set('meta', responseMeta);
|
|
87
|
-
return clone;
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
isLive: {
|
|
91
|
-
value: function () {
|
|
92
|
-
let liveLevel = (this.headers.get('X-Background-Messaging-Port')?.trim() || _wq(this, 'meta').has('wqRealtime')) && 1 || 0;
|
|
93
|
-
liveLevel += this.headers.get('X-Live-Response-Message-ID')?.trim() && 1 || 0;
|
|
94
|
-
return liveLevel;
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
wqRealtime: {
|
|
98
|
-
get: function () {
|
|
99
|
-
return responseRealtime.call(this);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
parse: {
|
|
103
|
-
value: async function () {
|
|
104
|
-
return await parseHttpMessage(this);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
Object.defineProperties(Response.prototype, prototypeExtensions);
|
|
110
|
-
Object.defineProperties(Response, staticExtensions);
|