@webqit/webflo 0.11.61-0 → 0.20.1
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/.github/FUNDING.yml +12 -0
- package/.github/workflows/publish.yml +48 -0
- package/.gitignore +9 -7
- package/LICENSE +21 -21
- package/README.md +100 -2074
- package/docker/Dockerfile +42 -42
- package/docker/README.md +91 -91
- package/docker/package.json +2 -2
- package/package.json +95 -81
- package/site/-/_.md +139 -0
- package/site/-/docs.old.md +2010 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url 2.js +93 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js +93 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js 2.map +7 -0
- package/site/.vitepress/cache/deps/@braintree_sanitize-url.js.map +7 -0
- package/site/.vitepress/cache/deps/_metadata 2.json +85 -0
- package/site/.vitepress/cache/deps/_metadata.json +85 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4 2.js +9 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js +9 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-BUSYA2B4.js.map +7 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK 2.js +9719 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js +9719 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-Q2AYPHVK.js.map +7 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7 2.js +12705 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js +12705 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js 2.map +7 -0
- package/site/.vitepress/cache/deps/chunk-QAXAIFA7.js.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape 2.js +30278 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent 2.js +4710 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js +4710 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js 2.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape-cose-bilkent.js.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape.js +30278 -0
- package/site/.vitepress/cache/deps/cytoscape.js 2.map +7 -0
- package/site/.vitepress/cache/deps/cytoscape.js.map +7 -0
- package/site/.vitepress/cache/deps/dayjs 2.js +285 -0
- package/site/.vitepress/cache/deps/dayjs.js +285 -0
- package/site/.vitepress/cache/deps/dayjs.js 2.map +7 -0
- package/site/.vitepress/cache/deps/dayjs.js.map +7 -0
- package/site/.vitepress/cache/deps/debug 2.js +453 -0
- package/site/.vitepress/cache/deps/debug.js +453 -0
- package/site/.vitepress/cache/deps/debug.js 2.map +7 -0
- package/site/.vitepress/cache/deps/debug.js.map +7 -0
- package/site/.vitepress/cache/deps/package 2.json +3 -0
- package/site/.vitepress/cache/deps/package.json +3 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api 2.js +4507 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4507 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core 2.js +584 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js +584 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap 2.js +1166 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1166 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js 2.js +1667 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1667 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch 2.js +1815 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js +1815 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
- package/site/.vitepress/cache/deps/vue 2.js +344 -0
- package/site/.vitepress/cache/deps/vue.js +344 -0
- package/site/.vitepress/cache/deps/vue.js 2.map +7 -0
- package/site/.vitepress/cache/deps/vue.js.map +7 -0
- package/site/.vitepress/config.ts +147 -0
- package/site/.vitepress/theme/custom.css +50 -0
- package/site/.vitepress/theme/index.ts +6 -0
- package/site/api/webflo-fetch/FormData.md +0 -0
- package/site/api/webflo-fetch/Headers.md +0 -0
- package/site/api/webflo-fetch/LiveResponse.md +0 -0
- package/site/api/webflo-fetch/Request.md +0 -0
- package/site/api/webflo-fetch/Response.md +0 -0
- package/site/api/webflo-fetch/fetch.md +0 -0
- package/site/api/webflo-routing/HttpCookies.md +0 -0
- package/site/api/webflo-routing/HttpEvent/respondWith.md +1 -0
- package/site/api/webflo-routing/HttpEvent/waitUntil.md +1 -0
- package/site/api/webflo-routing/HttpEvent/waitUntilNavigate.md +1 -0
- package/site/api/webflo-routing/HttpEvent.md +30 -0
- package/site/api/webflo-routing/HttpSession.md +0 -0
- package/site/api/webflo-routing/HttpState.md +0 -0
- package/site/api/webflo-routing/HttpUser.md +0 -0
- package/site/api/webflo-routing/handler/fetch.md +42 -0
- package/site/api/webflo-routing/handler/next.md +54 -0
- package/site/api/webflo-routing/handler.md +119 -0
- package/site/api.md +26 -0
- package/site/contributing.md +16 -0
- package/site/docs/advanced/lifecycles.md +20 -0
- package/site/docs/advanced/redirects.md +0 -0
- package/site/docs/advanced/routing.md +1 -0
- package/site/docs/advanced.md +9 -0
- package/site/docs/concepts/realtime.md +637 -0
- package/site/docs/concepts/rendering.md +60 -0
- package/site/docs/concepts/request-response.md +47 -0
- package/site/docs/concepts/routing.md +656 -0
- package/site/docs/concepts/state.md +44 -0
- package/site/docs/concepts/templates.md +48 -0
- package/site/docs/concepts.md +97 -0
- package/site/docs/getting-started.md +378 -0
- package/site/docs/tech-stack.md +56 -0
- package/site/docs.md +100 -0
- package/site/examples/pwa.md +10 -0
- package/site/examples/web.md +11 -0
- package/site/examples.md +10 -0
- package/site/faq.md +13 -0
- package/site/guides/guide-auth.md +13 -0
- package/site/guides/guide-file-upload.md +11 -0
- package/site/guides/guide-service-worker.md +10 -0
- package/site/guides/tutorial-1-todo.md +24 -0
- package/site/guides.md +15 -0
- package/site/index.md +39 -0
- package/site/public/img/brand/logo-670x670.png +0 -0
- package/site/recipes/realtime.md +11 -0
- package/site/recipes/streaming.md +15 -0
- package/site/reference/cli.md +11 -0
- package/site/reference/config.md +13 -0
- package/site/reference/tools.md +9 -0
- package/src/Context.js +71 -79
- package/src/config-pi/deployment/Env.js +55 -68
- package/src/config-pi/deployment/Layout.js +71 -63
- package/src/config-pi/deployment/Origins.js +139 -139
- package/src/config-pi/deployment/Proxy.js +74 -74
- package/src/config-pi/deployment/index.js +17 -17
- package/src/config-pi/index.js +15 -15
- package/src/config-pi/runtime/Client.js +108 -98
- package/src/config-pi/runtime/Server.js +157 -125
- package/src/config-pi/runtime/client/Worker.js +111 -134
- package/src/config-pi/runtime/client/index.js +11 -11
- package/src/config-pi/runtime/index.js +17 -17
- package/src/config-pi/runtime/server/Headers.js +74 -74
- package/src/config-pi/runtime/server/Redirects.js +69 -69
- package/src/config-pi/runtime/server/index.js +13 -13
- package/src/config-pi/static/Init.js +57 -0
- package/src/config-pi/static/Manifest.js +319 -319
- package/src/config-pi/static/Ssg.js +49 -49
- package/src/config-pi/static/index.js +15 -13
- package/src/deployment-pi/index.js +10 -10
- package/src/deployment-pi/origins/index.js +216 -216
- package/src/deployment-pi/util.js +161 -0
- package/src/index.js +13 -19
- package/src/init-pi/index.js +117 -0
- package/src/init-pi/templates/pwa/app/handler.server.js +8 -0
- package/src/init-pi/templates/pwa/app/page.html +7 -0
- package/src/init-pi/templates/pwa/package.json +19 -0
- package/src/init-pi/templates/pwa/public/assets/app.css +16 -0
- package/src/init-pi/templates/pwa/public/index.html +39 -0
- package/src/init-pi/templates/pwa/public/manifest.json +29 -0
- package/src/init-pi/templates/web/app/handler.server.js +8 -0
- package/src/init-pi/templates/web/app/page.html +7 -0
- package/src/init-pi/templates/web/package.json +19 -0
- package/src/init-pi/templates/web/public/assets/app.css +16 -0
- package/src/init-pi/templates/web/public/index.html +39 -0
- package/src/runtime-pi/WebfloRuntime.js +350 -0
- package/src/runtime-pi/index.js +6 -13
- package/src/runtime-pi/webflo-client/ClientSideCookies.js +17 -0
- package/src/runtime-pi/webflo-client/ClientSideWorkport.js +63 -0
- package/src/runtime-pi/webflo-client/DeviceCapabilities.js +213 -0
- package/src/runtime-pi/webflo-client/WebfloClient.js +500 -0
- package/src/runtime-pi/webflo-client/WebfloRootClient1.js +206 -0
- package/src/runtime-pi/webflo-client/WebfloRootClient2.js +113 -0
- package/src/runtime-pi/webflo-client/WebfloSubClient.js +118 -0
- package/src/runtime-pi/webflo-client/index.js +17 -0
- package/src/runtime-pi/webflo-client/webflo-codegen.js +469 -0
- package/src/runtime-pi/webflo-client/webflo-devmode.js +243 -0
- package/src/runtime-pi/webflo-client/webflo-embedded.js +50 -0
- package/src/runtime-pi/webflo-fetch/LiveResponse.js +437 -0
- package/src/runtime-pi/webflo-fetch/cookies.js +10 -0
- package/src/runtime-pi/webflo-fetch/fetch.js +16 -0
- package/src/runtime-pi/webflo-fetch/formdata.js +54 -0
- package/src/runtime-pi/webflo-fetch/headers.js +151 -0
- package/src/runtime-pi/webflo-fetch/index.js +5 -0
- package/src/runtime-pi/webflo-fetch/message.js +49 -0
- package/src/runtime-pi/webflo-fetch/request.js +62 -0
- package/src/runtime-pi/webflo-fetch/response.js +110 -0
- package/src/runtime-pi/webflo-fetch/util.js +28 -0
- package/src/runtime-pi/webflo-messaging/WQBroadcastChannel.js +10 -0
- package/src/runtime-pi/webflo-messaging/WQMessageChannel.js +26 -0
- package/src/runtime-pi/webflo-messaging/WQMessageEvent.js +87 -0
- package/src/runtime-pi/webflo-messaging/WQMessagePort.js +38 -0
- package/src/runtime-pi/webflo-messaging/WQRelayPort.js +47 -0
- package/src/runtime-pi/webflo-messaging/WQSockPort.js +113 -0
- package/src/runtime-pi/webflo-messaging/WQStarPort.js +104 -0
- package/src/runtime-pi/webflo-messaging/wq-message-port.js +404 -0
- package/src/runtime-pi/webflo-routing/HttpCookies.js +42 -0
- package/src/runtime-pi/webflo-routing/HttpEvent.js +112 -0
- package/src/runtime-pi/webflo-routing/HttpSession.js +11 -0
- package/src/runtime-pi/webflo-routing/HttpState.js +153 -0
- package/src/runtime-pi/webflo-routing/HttpUser.js +54 -0
- package/src/runtime-pi/webflo-routing/WebfloRouter.js +245 -0
- package/src/runtime-pi/webflo-server/ServerSideCookies.js +19 -0
- package/src/runtime-pi/webflo-server/ServerSideSession.js +38 -0
- package/src/runtime-pi/webflo-server/WebfloServer.js +937 -0
- package/src/runtime-pi/webflo-server/index.js +11 -0
- package/src/runtime-pi/webflo-server/messaging/Client.js +27 -0
- package/src/runtime-pi/webflo-server/messaging/ClientRequestRealtime.js +50 -0
- package/src/runtime-pi/webflo-server/messaging/Clients.js +25 -0
- package/src/runtime-pi/webflo-server/webflo-devmode.js +326 -0
- package/src/runtime-pi/{client → webflo-url}/Url.js +155 -205
- package/src/runtime-pi/webflo-url/index.js +1 -0
- package/src/runtime-pi/webflo-url/urlpattern.js +38 -0
- package/src/runtime-pi/{util-url.js → webflo-url/util.js} +109 -147
- package/src/runtime-pi/webflo-url/xURL.js +94 -0
- package/src/runtime-pi/webflo-worker/WebfloWorker.js +234 -0
- package/src/runtime-pi/webflo-worker/WorkerSideCookies.js +19 -0
- package/src/runtime-pi/webflo-worker/WorkerSideWorkport.js +18 -0
- package/src/runtime-pi/webflo-worker/index.js +11 -0
- package/src/services-pi/cert/http-auth-hook.js +22 -22
- package/src/services-pi/cert/http-cleanup-hook.js +22 -22
- package/src/services-pi/cert/index.js +79 -79
- package/src/services-pi/index.js +10 -8
- package/src/services-pi/push/index.js +23 -0
- package/src/util.js +10 -0
- package/src/{webflo.js → webflo-cli.js} +30 -30
- package/test/index.test.js +26 -26
- package/test/site/package.json +9 -9
- package/test/site/public/bundle.html +5 -5
- package/test/site/public/bundle.html.json +3 -3
- package/test/site/public/bundle.js +2 -2
- package/test/site/public/bundle.webflo.js +15 -15
- package/test/site/public/index.html +29 -29
- package/test/site/public/index1.html +34 -34
- package/test/site/public/page-2/bundle.html +4 -4
- package/test/site/public/page-2/bundle.js +2 -2
- package/test/site/public/page-2/index.html +45 -45
- package/test/site/public/page-2/main.html +2 -2
- package/test/site/public/page-4/subpage/bundle.js +2 -2
- package/test/site/public/page-4/subpage/index.html +30 -30
- package/test/site/public/sparoots.json +4 -4
- package/test/site/public/worker.js +3 -3
- package/test/site/server/index.js +15 -15
- package/src/runtime-pi/Application.js +0 -29
- package/src/runtime-pi/Cookies.js +0 -82
- package/src/runtime-pi/HttpEvent.js +0 -107
- package/src/runtime-pi/Router.js +0 -130
- package/src/runtime-pi/Runtime.js +0 -21
- package/src/runtime-pi/client/Application.js +0 -100
- package/src/runtime-pi/client/Context.js +0 -7
- package/src/runtime-pi/client/Router.js +0 -48
- package/src/runtime-pi/client/Runtime.js +0 -332
- package/src/runtime-pi/client/Workport.js +0 -178
- package/src/runtime-pi/client/createStorage.js +0 -57
- package/src/runtime-pi/client/generate.js +0 -472
- package/src/runtime-pi/client/index.js +0 -21
- package/src/runtime-pi/client/oohtml/full.js +0 -7
- package/src/runtime-pi/client/oohtml/namespacing.js +0 -7
- package/src/runtime-pi/client/oohtml/scripting.js +0 -8
- package/src/runtime-pi/client/oohtml/templating.js +0 -8
- package/src/runtime-pi/client/worker/Application.js +0 -44
- package/src/runtime-pi/client/worker/Context.js +0 -7
- package/src/runtime-pi/client/worker/Runtime.js +0 -269
- package/src/runtime-pi/client/worker/Workport.js +0 -86
- package/src/runtime-pi/client/worker/index.js +0 -21
- package/src/runtime-pi/server/Application.js +0 -116
- package/src/runtime-pi/server/Context.js +0 -16
- package/src/runtime-pi/server/Router.js +0 -159
- package/src/runtime-pi/server/Runtime.js +0 -557
- package/src/runtime-pi/server/index.js +0 -21
- package/src/runtime-pi/util-http.js +0 -86
- package/src/runtime-pi/xFormData.js +0 -24
- package/src/runtime-pi/xHeaders.js +0 -146
- package/src/runtime-pi/xRequest.js +0 -46
- package/src/runtime-pi/xRequestHeaders.js +0 -109
- package/src/runtime-pi/xResponse.js +0 -33
- package/src/runtime-pi/xResponseHeaders.js +0 -117
- package/src/runtime-pi/xURL.js +0 -105
- package/src/runtime-pi/xfetch.js +0 -23
- package/src/runtime-pi/xxHttpMessage.js +0 -102
- package/src/static-pi/index.js +0 -11
|
@@ -1,147 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// Turn back into a single string path.
|
|
111
|
-
return '../'.repeat(backsteps) + newParts.join("/") || (newParts.length ? "/" : ".");
|
|
112
|
-
},
|
|
113
|
-
// A simple function to get the dirname of a path
|
|
114
|
-
// Trailing slashes are ignored. Leading slash is preserved.
|
|
115
|
-
dirname(path) {
|
|
116
|
-
return this.join(path, "..");
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const pattern = (pattern, baseUrl = null) => ({
|
|
121
|
-
pattern: new URLPattern(pattern, baseUrl),
|
|
122
|
-
isPattern() {
|
|
123
|
-
return Object.keys(this.pattern.keys || {}).some(compName => this.pattern.keys[compName].length);
|
|
124
|
-
},
|
|
125
|
-
test(...args) { return this.pattern.test(...args) },
|
|
126
|
-
exec(...args) {
|
|
127
|
-
let components = this.pattern.exec(...args);
|
|
128
|
-
if (!components) return;
|
|
129
|
-
components.vars = Object.keys(this.pattern.keys).reduce(({ named, unnamed }, compName) => {
|
|
130
|
-
this.pattern.keys[compName].forEach(key => {
|
|
131
|
-
let value = components[compName].groups[key.name];
|
|
132
|
-
if (typeof key.name === 'number') {
|
|
133
|
-
unnamed.push(value);
|
|
134
|
-
} else {
|
|
135
|
-
named[key.name] = value;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
return { named, unnamed };
|
|
139
|
-
}, { named: {}, unnamed: [] });
|
|
140
|
-
components.render = str => {
|
|
141
|
-
return str.replace(/\$(\$|[0-9A-Z]+)/gi, (a, b) => {
|
|
142
|
-
return b === '$' ? '$' : (_isNumeric(b) ? components.vars.unnamed[b - 1] : components.vars.named[b]) || '';
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return components;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
1
|
+
import { _isString, _isNumeric, _isArray, _isTypeObject } from '@webqit/util/js/index.js';
|
|
2
|
+
|
|
3
|
+
export const DeepURLSearchParams = {
|
|
4
|
+
// Parse a search params string into an object
|
|
5
|
+
eval(targetObject, str, delim = '&') {
|
|
6
|
+
str = str || '';
|
|
7
|
+
(str.startsWith('?') ? str.substr(1) : str)
|
|
8
|
+
.split(delim).filter(q => q).map(q => q.split('=').map(q => q.trim()))
|
|
9
|
+
.forEach(q => this.set(targetObject, q[0], decodeURIComponent(q[1])));
|
|
10
|
+
return targetObject;
|
|
11
|
+
},
|
|
12
|
+
// Stringify an object into a search params string
|
|
13
|
+
stringify(targetObject, delim = '&') {
|
|
14
|
+
const q = [];
|
|
15
|
+
Object.keys(targetObject).forEach(key => {
|
|
16
|
+
this.reduceValue(targetObject[key], key, (_value, _pathNotation, suggestedKeys = undefined) => {
|
|
17
|
+
if (suggestedKeys) return suggestedKeys;
|
|
18
|
+
q.push(`${_pathNotation}=${encodeURIComponent(_value)}`);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
return q.join(delim);
|
|
22
|
+
},
|
|
23
|
+
// Get value by path notation
|
|
24
|
+
get(targetObject, pathNotation) {
|
|
25
|
+
return this.reducePath(pathNotation, targetObject, (key, _targetObject) => {
|
|
26
|
+
if (!_targetObject && _targetObject !== 0) return;
|
|
27
|
+
return _targetObject[key];
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
// Set value by path notation
|
|
31
|
+
set(targetObject, pathNotation, value) {
|
|
32
|
+
this.reducePath(pathNotation, targetObject, function(_key, _targetObject, suggestedBranch = undefined) {
|
|
33
|
+
let _value = value;
|
|
34
|
+
if (suggestedBranch) { _value = suggestedBranch; }
|
|
35
|
+
if (_key === '' && _isArray(_targetObject)) {
|
|
36
|
+
_targetObject.push(_value);
|
|
37
|
+
} else {
|
|
38
|
+
_targetObject[_key] = _value;
|
|
39
|
+
}
|
|
40
|
+
return _value;
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// Resolve a value to its leaf nodes
|
|
45
|
+
reduceValue(value, contextPath, callback) {
|
|
46
|
+
if (_isTypeObject(value)) {
|
|
47
|
+
let suggestedKeys = Object.keys(value);
|
|
48
|
+
let keys = callback(value, contextPath, suggestedKeys);
|
|
49
|
+
if (_isArray(keys)) {
|
|
50
|
+
return keys.forEach(key => {
|
|
51
|
+
this.reduceValue(value[key], contextPath ? `${contextPath}[${key}]` : key, callback);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
callback(value, contextPath);
|
|
56
|
+
},
|
|
57
|
+
// Resolve a path to its leaf index
|
|
58
|
+
reducePath(pathNotation, contextObject, callback) {
|
|
59
|
+
if (_isString(pathNotation) && pathNotation.endsWith(']') && _isTypeObject(contextObject)) {
|
|
60
|
+
let [ key, ...rest ] = pathNotation.split('[');
|
|
61
|
+
if (_isNumeric(key)) { key = parseInt(key); }
|
|
62
|
+
rest = rest.join('[').replace(']', '');
|
|
63
|
+
let branch;
|
|
64
|
+
if (key in contextObject) {
|
|
65
|
+
branch = contextObject[key];
|
|
66
|
+
} else {
|
|
67
|
+
let suggestedBranch = rest === '' || _isNumeric(rest.split('[')[0]) ? [] : {};
|
|
68
|
+
branch = callback(key, contextObject, suggestedBranch);
|
|
69
|
+
}
|
|
70
|
+
return this.reducePath(rest, branch, callback);
|
|
71
|
+
}
|
|
72
|
+
if (_isNumeric(pathNotation)) { pathNotation = parseInt(pathNotation); }
|
|
73
|
+
return callback(pathNotation, contextObject);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const path = {
|
|
78
|
+
join(/* path segments */) {
|
|
79
|
+
// Split the inputs into a list of path commands.
|
|
80
|
+
let parts = [], backsteps = 0;
|
|
81
|
+
for ( let i = 0, l = arguments.length; i < l; i++ ) {
|
|
82
|
+
parts = parts.concat( arguments[ i ].split( '/' ) );
|
|
83
|
+
}
|
|
84
|
+
// Interpret the path commands to get the new resolved path.
|
|
85
|
+
let newParts = [];
|
|
86
|
+
for ( let i = 0, l = parts.length; i < l; i++ ) {
|
|
87
|
+
let part = parts[ i ];
|
|
88
|
+
// Remove leading and trailing slashes
|
|
89
|
+
// Also remove "." segments
|
|
90
|
+
if ( !part || part === '.' ) continue;
|
|
91
|
+
// Interpret ".." to pop the last segment
|
|
92
|
+
if ( part === '..' ) {
|
|
93
|
+
if ( !newParts.length ) backsteps ++;
|
|
94
|
+
else newParts.pop();
|
|
95
|
+
}
|
|
96
|
+
// Push new path segments.
|
|
97
|
+
else newParts.push( part );
|
|
98
|
+
}
|
|
99
|
+
// Preserve the initial slash if there was one.
|
|
100
|
+
if ( parts[ 0 ] === '' ) newParts.unshift( '' );
|
|
101
|
+
// Turn back into a single string path.
|
|
102
|
+
return '../'.repeat( backsteps ) + newParts.join( '/' ) || ( newParts.length ? '/' : '.' );
|
|
103
|
+
},
|
|
104
|
+
// A simple function to get the dirname of a path
|
|
105
|
+
// Trailing slashes are ignored. Leading slash is preserved.
|
|
106
|
+
dirname( path ) {
|
|
107
|
+
return this.join( path, '..' );
|
|
108
|
+
}
|
|
109
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { _isObject } from '@webqit/util/js/index.js';
|
|
2
|
+
import { Observer } from '@webqit/quantum-js';
|
|
3
|
+
import { DeepURLSearchParams } from './util.js';
|
|
4
|
+
|
|
5
|
+
export class xURL extends URL {
|
|
6
|
+
|
|
7
|
+
// constructor
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
super(...args);
|
|
10
|
+
const query = DeepURLSearchParams.eval({}, this.search);
|
|
11
|
+
const updateSearch = () => {
|
|
12
|
+
// "query" was updated. So we update "search"
|
|
13
|
+
let search = DeepURLSearchParams.stringify(query);
|
|
14
|
+
search = search ? '?' + search : '';
|
|
15
|
+
if (search !== this.search) {
|
|
16
|
+
this.search = search;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const $this = this;
|
|
20
|
+
this._query = new Proxy(query, {
|
|
21
|
+
set(t, k, v) {
|
|
22
|
+
t[k] = v;
|
|
23
|
+
if (!$this._updatingSearch) updateSearch();
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
deleteProperty(t, k) {
|
|
27
|
+
delete t[k];
|
|
28
|
+
if (!$this._updatingSearch) updateSearch();
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Set search
|
|
35
|
+
set search(value) {
|
|
36
|
+
super.search = value;
|
|
37
|
+
// "search" was updated. So we update "query"
|
|
38
|
+
this._updatingSearch = true;
|
|
39
|
+
const query = DeepURLSearchParams.eval({}, value);
|
|
40
|
+
const keys_a = Object.keys(query);
|
|
41
|
+
const keys_b = Object.keys(this._query);
|
|
42
|
+
for (const k of new Set([...keys_a,...keys_b])) {
|
|
43
|
+
if (!keys_a.includes(k)) delete this.query[k];
|
|
44
|
+
if (!keys_b.includes(k)) this.query[k] = query[k];
|
|
45
|
+
}
|
|
46
|
+
this._updatingSearch = false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Get search
|
|
50
|
+
get search() {
|
|
51
|
+
return super.search;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Get query
|
|
55
|
+
get query() {
|
|
56
|
+
return this._query;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
xURL.Observable = class extends xURL {
|
|
62
|
+
|
|
63
|
+
constructor() {
|
|
64
|
+
super(...arguments);
|
|
65
|
+
Observer.accessorize(this, [
|
|
66
|
+
'protocol',
|
|
67
|
+
'username',
|
|
68
|
+
'password',
|
|
69
|
+
'host',
|
|
70
|
+
'hostname',
|
|
71
|
+
'port',
|
|
72
|
+
'origin',
|
|
73
|
+
'pathname',
|
|
74
|
+
'search',
|
|
75
|
+
'query',
|
|
76
|
+
'hash',
|
|
77
|
+
'href',
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const _strictEven = (a, b) => {
|
|
84
|
+
if (_isObject(a) && _isObject(b)) {
|
|
85
|
+
return _strictEven(Object.keys(a), Object.keys(b))
|
|
86
|
+
&& _strictEven(Object.values(a), Object.values(b));
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
89
|
+
return a.length === b.length
|
|
90
|
+
&& a.reduce((recieved, item, i) => recieved && item === b[i], true);
|
|
91
|
+
}
|
|
92
|
+
return a === b;
|
|
93
|
+
};
|
|
94
|
+
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { _any } from '@webqit/util/arr/index.js';
|
|
2
|
+
import { WebfloRuntime } from '../WebfloRuntime.js';
|
|
3
|
+
import { WQBroadcastChannel } from '../webflo-messaging/WQBroadcastChannel.js';
|
|
4
|
+
import { WorkerSideWorkport } from './WorkerSideWorkport.js';
|
|
5
|
+
import { WorkerSideCookies } from './WorkerSideCookies.js';
|
|
6
|
+
import { HttpSession } from '../webflo-routing/HttpSession.js';
|
|
7
|
+
import { HttpEvent } from '../webflo-routing/HttpEvent.js';
|
|
8
|
+
import { HttpUser } from '../webflo-routing/HttpUser.js';
|
|
9
|
+
import '../webflo-fetch/index.js';
|
|
10
|
+
import '../webflo-url/index.js';
|
|
11
|
+
|
|
12
|
+
export class WebfloWorker extends WebfloRuntime {
|
|
13
|
+
|
|
14
|
+
static get HttpEvent() { return HttpEvent; }
|
|
15
|
+
|
|
16
|
+
static get HttpCookies() { return WorkerSideCookies; }
|
|
17
|
+
|
|
18
|
+
static get HttpSession() { return HttpSession; }
|
|
19
|
+
|
|
20
|
+
static get HttpUser() { return HttpUser; }
|
|
21
|
+
|
|
22
|
+
static get Workport() { return WorkerSideWorkport; }
|
|
23
|
+
|
|
24
|
+
static create(cx) {
|
|
25
|
+
return new this(this.Context.create(cx));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#sdk = {};
|
|
29
|
+
get sdk() { return this.#sdk; }
|
|
30
|
+
|
|
31
|
+
async initialize() {
|
|
32
|
+
const instanceController = super.initialize();
|
|
33
|
+
// ONINSTALL
|
|
34
|
+
const installHandler = (event) => {
|
|
35
|
+
if (this.config.WORKER.skip_waiting) self.skipWaiting();
|
|
36
|
+
// Manage CACHE
|
|
37
|
+
if (this.config.WORKER.cache_name && (this.config.WORKER.cache_only_urls || []).length) {
|
|
38
|
+
// Add files to cache
|
|
39
|
+
event.waitUntil(self.caches.open(this.config.WORKER.cache_name).then(async cache => {
|
|
40
|
+
if (this.cx.logger) { this.cx.logger.log('[ServiceWorker] Pre-caching resources.'); }
|
|
41
|
+
for (const urls of ['cache_first_urls', 'cache_only_urls']) {
|
|
42
|
+
const _urls = (this.config.WORKER[urls] || []).map(c => c.trim()).filter(c => c && !(new URLPattern(c, self.origin)).isPattern());
|
|
43
|
+
await cache.addAll(_urls);
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// ONACTIVATE
|
|
49
|
+
const activateHandler = (event) => {
|
|
50
|
+
event.waitUntil(new Promise(async resolve => {
|
|
51
|
+
if (this.config.WORKER.skip_waiting) { await self.clients.claim(); }
|
|
52
|
+
// Manage CACHE
|
|
53
|
+
if (this.config.WORKER.cache_name) {
|
|
54
|
+
// Clear outdated CACHES
|
|
55
|
+
await self.caches.keys().then(keyList => {
|
|
56
|
+
return Promise.all(keyList.map(key => {
|
|
57
|
+
if (key !== this.config.WORKER.cache_name && key !== this.config.WORKER.cache_name + '_json') {
|
|
58
|
+
if (this.cx.logger) { this.cx.logger.log('[ServiceWorker] Removing old cache:', key); }
|
|
59
|
+
return self.caches.delete(key);
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
resolve();
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
self.addEventListener('install', installHandler, { signal: instanceController.signal });
|
|
68
|
+
self.addEventListener('activate', activateHandler, { signal: instanceController.signal });
|
|
69
|
+
this.control();
|
|
70
|
+
return instanceController;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
control() {
|
|
74
|
+
const instanceController = super.control();
|
|
75
|
+
// ONFETCH
|
|
76
|
+
const fetchHandler = (event) => {
|
|
77
|
+
// Handle special requests
|
|
78
|
+
if (!event.request.url.startsWith('http') || event.request.mode === 'navigate') {
|
|
79
|
+
return event.respondWith(fetch(event.request));
|
|
80
|
+
}
|
|
81
|
+
// Handle external requests
|
|
82
|
+
if (!event.request.url.startsWith(self.origin)) {
|
|
83
|
+
return event.respondWith(this.remoteFetch(event.request));
|
|
84
|
+
}
|
|
85
|
+
event.respondWith((async (event) => {
|
|
86
|
+
const response = await this.navigate(event.request.url, event.request, { event });
|
|
87
|
+
return response;
|
|
88
|
+
})(event));
|
|
89
|
+
};
|
|
90
|
+
const webpushHandler = (event) => {
|
|
91
|
+
if (!(self.Notification && self.Notification.permission === 'granted')) return;
|
|
92
|
+
let data;
|
|
93
|
+
try {
|
|
94
|
+
data = event.data?.json() ?? {};
|
|
95
|
+
} catch(e) { return; }
|
|
96
|
+
const { type, title, ...params } = data;
|
|
97
|
+
if (type !== 'notification') return;
|
|
98
|
+
self.registration.showNotification(title, params);
|
|
99
|
+
};
|
|
100
|
+
self.addEventListener('fetch', fetchHandler, { signal: instanceController.signal });
|
|
101
|
+
self.addEventListener('push', webpushHandler, { signal: instanceController.signal });
|
|
102
|
+
return instanceController;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async navigate(url, init = {}, detail = {}) {
|
|
106
|
+
// Resolve inputs
|
|
107
|
+
const scopeObj = { url, init, detail };
|
|
108
|
+
if (typeof scopeObj.url === 'string') {
|
|
109
|
+
scopeObj.url = new URL(scopeObj.url, self.location.origin);
|
|
110
|
+
}
|
|
111
|
+
// Create and route request
|
|
112
|
+
scopeObj.request = this.createRequest(scopeObj.url, scopeObj.init);
|
|
113
|
+
scopeObj.cookies = this.createHttpCookies({
|
|
114
|
+
request: scopeObj.request
|
|
115
|
+
});
|
|
116
|
+
scopeObj.session = this.createHttpSession({
|
|
117
|
+
store: this.#sdk.storage?.('session'),
|
|
118
|
+
request: scopeObj.request
|
|
119
|
+
});
|
|
120
|
+
const requestID = crypto.randomUUID();
|
|
121
|
+
scopeObj.clientRequestRealtime = new WQBroadcastChannel(requestID);
|
|
122
|
+
scopeObj.user = this.createHttpUser({
|
|
123
|
+
store: this.#sdk.storage?.('user'),
|
|
124
|
+
request: scopeObj.request,
|
|
125
|
+
realtime: scopeObj.clientRequestRealtime,
|
|
126
|
+
session: scopeObj.session,
|
|
127
|
+
});
|
|
128
|
+
scopeObj.httpEvent = this.createHttpEvent({
|
|
129
|
+
request: scopeObj.request,
|
|
130
|
+
realtime: scopeObj.clientRequestRealtime,
|
|
131
|
+
cookies: scopeObj.cookies,
|
|
132
|
+
session: scopeObj.session,
|
|
133
|
+
user: scopeObj.user,
|
|
134
|
+
detail: scopeObj.detail,
|
|
135
|
+
sdk: {}
|
|
136
|
+
});
|
|
137
|
+
// Dispatch for response
|
|
138
|
+
scopeObj.response = await this.dispatchNavigationEvent({
|
|
139
|
+
httpEvent: scopeObj.httpEvent,
|
|
140
|
+
crossLayerFetch: async (event) => {
|
|
141
|
+
// Was this nexted()? Tell the next layer we're in JSON mode by default
|
|
142
|
+
if (event !== scopeObj.httpEvent && !event.request.headers.has('Accept')) {
|
|
143
|
+
event.request.headers.set('Accept', 'application/json');
|
|
144
|
+
}
|
|
145
|
+
return await this.remoteFetch(event.request);
|
|
146
|
+
},
|
|
147
|
+
responseRealtime: `br:${scopeObj.httpEvent.realtime.name}`
|
|
148
|
+
});
|
|
149
|
+
return scopeObj.response;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async remoteFetch(request, ...args) {
|
|
153
|
+
if (arguments.length > 1) {
|
|
154
|
+
request = this.createRequest(request, ...args);
|
|
155
|
+
}
|
|
156
|
+
const scopeObj = {};
|
|
157
|
+
const matchUrl = (patterns, url) => _any((patterns || []).map(p => p.trim()).filter(p => p), p => (new URLPattern(p, self.origin)).test(url));
|
|
158
|
+
if (matchUrl(this.config.WORKER.cache_only_urls, request.url)) {
|
|
159
|
+
scopeObj.strategy = 'cache-only';
|
|
160
|
+
scopeObj.response = this.cacheFetch(request, { networkFallback: false, cacheRefresh: false });
|
|
161
|
+
} else if (matchUrl(this.config.WORKER.network_only_urls, request.url)) {
|
|
162
|
+
scopeObj.strategy = 'network-only';
|
|
163
|
+
scopeObj.response = this.networkFetch(request, { cacheFallback: false, cacheRefresh: false });
|
|
164
|
+
} else if (matchUrl(this.config.WORKER.cache_first_urls, request.url)) {
|
|
165
|
+
scopeObj.strategy = 'cache-first';
|
|
166
|
+
scopeObj.response = this.cacheFetch(request, { networkFallback: true, cacheRefresh: true });
|
|
167
|
+
} else if (matchUrl(this.config.WORKER.network_first_urls, request.url) || !this.config.WORKER.default_fetching_strategy) {
|
|
168
|
+
scopeObj.strategy = 'network-first';
|
|
169
|
+
scopeObj.response = this.networkFetch(request, { cacheFallback: true, cacheRefresh: true });
|
|
170
|
+
} else {
|
|
171
|
+
scopeObj.strategy = this.config.WORKER.default_fetching_strategy;
|
|
172
|
+
switch (this.config.WORKER.default_fetching_strategy) {
|
|
173
|
+
case 'cache-only':
|
|
174
|
+
scopeObj.response = this.cacheFetch(request, { networkFallback: false, cacheRefresh: false });
|
|
175
|
+
break;
|
|
176
|
+
case 'network-only':
|
|
177
|
+
scopeObj.response = this.networkFetch(request, { cacheFallback: false, cacheRefresh: false });
|
|
178
|
+
break;
|
|
179
|
+
case 'cache-first':
|
|
180
|
+
scopeObj.response = this.cacheFetch(request, { networkFallback: true, cacheRefresh: true });
|
|
181
|
+
break;
|
|
182
|
+
case 'network-first':
|
|
183
|
+
scopeObj.response = this.networkFetch(request, { cacheFallback: true, cacheRefresh: true });
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return await scopeObj.response;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async networkFetch(request, params = {}) {
|
|
191
|
+
if (!params.cacheFallback) {
|
|
192
|
+
return fetch(request);
|
|
193
|
+
}
|
|
194
|
+
return fetch(request).then((response) => {
|
|
195
|
+
if (params.cacheRefresh) this.refreshCache(request, response);
|
|
196
|
+
return response;
|
|
197
|
+
}).catch((e) => this.getRequestCache(request).then(cache => {
|
|
198
|
+
return cache.match(request);
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async cacheFetch(request, params = {}) {
|
|
203
|
+
return this.getRequestCache(request).then(cache => cache.match(request).then((response) => {
|
|
204
|
+
// Nothing cache, use network
|
|
205
|
+
if (!response && params.networkFallback) return this.networkFetch(request, { ...params, cacheFallback: false });
|
|
206
|
+
// Note: fetch, but for refreshing purposes only... not the returned response
|
|
207
|
+
if (response && params.cacheRefresh) this.networkFetch(request, { ...params, justRefreshing: true });
|
|
208
|
+
return response;
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async refreshCache(request, response) {
|
|
213
|
+
// Check if we received a valid response
|
|
214
|
+
if (request.method !== 'GET' || !response || response.status !== 200 || (response.type !== 'basic' && response.type !== 'cors')) {
|
|
215
|
+
return response;
|
|
216
|
+
}
|
|
217
|
+
// IMPORTANT: Clone the response. A response is a stream
|
|
218
|
+
// and because we want the browser to consume the response
|
|
219
|
+
// as well as the cache consuming the response, we need
|
|
220
|
+
// to clone it so we have two streams.
|
|
221
|
+
var responseToCache = response.clone();
|
|
222
|
+
await this.getRequestCache(request).then(cache => {
|
|
223
|
+
cache.put(request, responseToCache);
|
|
224
|
+
});
|
|
225
|
+
return response;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async getRequestCache(request) {
|
|
229
|
+
const cacheName = request.headers.get('X-Powered-By') === '@webqit/webflo'
|
|
230
|
+
? this.config.WORKER.cache_name + '_csr'
|
|
231
|
+
: this.config.WORKER.cache_name;
|
|
232
|
+
return self.caches.open(cacheName);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HttpCookies } from '../webflo-routing/HttpCookies.js';
|
|
2
|
+
|
|
3
|
+
export class WorkerSideCookies extends HttpCookies {
|
|
4
|
+
static create({ request }) {
|
|
5
|
+
return new this({
|
|
6
|
+
request,
|
|
7
|
+
entries: request.headers.get('Cookie', true).map((c) => [c.name, c])
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async commit(response = null) {
|
|
12
|
+
if (response) {
|
|
13
|
+
for (const cookieStr of await this.render()) {
|
|
14
|
+
response.headers.append('Set-Cookie', cookieStr);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
await super.commit();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class WorkerSideWorkport {
|
|
2
|
+
|
|
3
|
+
showNotification(title, params = {}) {
|
|
4
|
+
return self.registration.showNotification(title, params);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
handleNotificationClick(callback) {
|
|
8
|
+
const handler = (e) => e.waitUntil(callback(e));
|
|
9
|
+
self.addEventListener('notificationclick', handler);
|
|
10
|
+
return () => self.removeEventListener('notificationclick', handler);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
handlePush(callback) {
|
|
14
|
+
const handler = (e) => e.waitUntil(callback(e));
|
|
15
|
+
self.addEventListener('push', handler);
|
|
16
|
+
return () => self.removeEventListener('notificationclick', handler);
|
|
17
|
+
}
|
|
18
|
+
}
|