@webqit/webflo 0.8.77 → 0.9.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.
Files changed (97) hide show
  1. package/package.json +5 -12
  2. package/src/Cli.js +131 -0
  3. package/src/Configurator.js +97 -0
  4. package/src/Context.js +76 -0
  5. package/src/config-pi/deployment/Env.js +69 -0
  6. package/src/config-pi/deployment/Layout.js +65 -0
  7. package/src/config-pi/deployment/Origins.js +133 -0
  8. package/src/config-pi/deployment/Virtualization.js +65 -0
  9. package/src/config-pi/deployment/index.js +18 -0
  10. package/src/config-pi/index.js +16 -0
  11. package/src/config-pi/runtime/Client.js +59 -0
  12. package/src/config-pi/runtime/Server.js +174 -0
  13. package/src/config-pi/runtime/client/Worker.js +117 -0
  14. package/src/config-pi/runtime/client/index.js +12 -0
  15. package/src/config-pi/runtime/index.js +18 -0
  16. package/src/config-pi/runtime/server/Headers.js +90 -0
  17. package/src/config-pi/runtime/server/Redirects.js +108 -0
  18. package/src/config-pi/runtime/server/index.js +14 -0
  19. package/src/config-pi/static/Manifest.js +321 -0
  20. package/src/config-pi/static/Ssg.js +72 -0
  21. package/src/config-pi/static/index.js +14 -0
  22. package/src/deployment-pi/index.js +10 -0
  23. package/src/{services → deployment-pi}/origins/index.js +88 -58
  24. package/src/index.js +14 -147
  25. package/src/{runtime → runtime-pi}/Router.js +19 -19
  26. package/src/runtime-pi/client/Context.js +7 -0
  27. package/src/{runtime → runtime-pi}/client/Router.js +2 -2
  28. package/src/{runtime/client/Navigator.js → runtime-pi/client/Runtime.js} +148 -103
  29. package/src/runtime-pi/client/RuntimeClient.js +114 -0
  30. package/src/{runtime → runtime-pi}/client/Storage.js +1 -1
  31. package/src/{runtime → runtime-pi}/client/Url.js +2 -6
  32. package/src/{runtime/client/WorkerClient.js → runtime-pi/client/WorkerComm.js} +2 -2
  33. package/src/runtime-pi/client/generate.js +242 -0
  34. package/src/runtime-pi/client/generate.oohtml.js +7 -0
  35. package/src/runtime-pi/client/index.js +18 -0
  36. package/src/runtime-pi/client/whatwag.js +27 -0
  37. package/src/runtime-pi/client/worker/Context.js +7 -0
  38. package/src/runtime-pi/client/worker/Worker.js +243 -0
  39. package/src/runtime-pi/client/worker/WorkerClient.js +46 -0
  40. package/src/runtime-pi/client/worker/index.js +18 -0
  41. package/src/runtime-pi/index.js +14 -0
  42. package/src/runtime-pi/server/Context.js +16 -0
  43. package/src/{runtime → runtime-pi}/server/Router.js +6 -6
  44. package/src/runtime-pi/server/Runtime.js +531 -0
  45. package/src/runtime-pi/server/RuntimeClient.js +103 -0
  46. package/src/runtime-pi/server/index.js +41 -0
  47. package/src/runtime-pi/server/whatwag.js +35 -0
  48. package/src/{runtime → runtime-pi}/util.js +0 -0
  49. package/src/{runtime/_FormData.js → runtime-pi/xFormData.js} +2 -2
  50. package/src/{runtime/_Headers.js → runtime-pi/xHeaders.js} +4 -4
  51. package/src/runtime-pi/xHttpEvent.js +93 -0
  52. package/src/runtime-pi/xHttpMessage.js +179 -0
  53. package/src/runtime-pi/xRequest.js +67 -0
  54. package/src/runtime-pi/xRequestHeaders.js +95 -0
  55. package/src/runtime-pi/xResponse.js +62 -0
  56. package/src/{runtime/_ResponseHeaders.js → runtime-pi/xResponseHeaders.js} +38 -18
  57. package/src/{runtime/_URL.js → runtime-pi/xURL.js} +4 -4
  58. package/src/runtime-pi/xfetch.js +7 -0
  59. package/src/{services → services-pi}/certbot/http-auth-hook.js +0 -0
  60. package/src/{services → services-pi}/certbot/http-cleanup-hook.js +0 -0
  61. package/src/{services → services-pi}/certbot/index.js +21 -15
  62. package/src/services-pi/index.js +9 -0
  63. package/src/static-pi/index.js +11 -0
  64. package/src/webflo.js +33 -0
  65. package/test/index.test.js +26 -0
  66. package/src/build/client/index.js +0 -261
  67. package/src/build/index.js +0 -5
  68. package/src/config/client.js +0 -191
  69. package/src/config/headers.js +0 -121
  70. package/src/config/index.js +0 -14
  71. package/src/config/layout.js +0 -83
  72. package/src/config/manifest.js +0 -341
  73. package/src/config/origins.js +0 -165
  74. package/src/config/prerendering.js +0 -100
  75. package/src/config/redirects.js +0 -137
  76. package/src/config/server.js +0 -201
  77. package/src/config/variables.js +0 -102
  78. package/src/config/vhosts.js +0 -93
  79. package/src/runtime/_MessageStream.js +0 -195
  80. package/src/runtime/_NavigationEvent.js +0 -91
  81. package/src/runtime/_Request.js +0 -59
  82. package/src/runtime/_RequestHeaders.js +0 -72
  83. package/src/runtime/_Response.js +0 -56
  84. package/src/runtime/client/NavigationEvent.js +0 -21
  85. package/src/runtime/client/Runtime.js +0 -126
  86. package/src/runtime/client/Worker.js +0 -317
  87. package/src/runtime/client/archive/Cache.js +0 -38
  88. package/src/runtime/client/archive/Http.js +0 -225
  89. package/src/runtime/client/archive/StdRequest.js +0 -74
  90. package/src/runtime/client/archive/WorkerComm.js +0 -183
  91. package/src/runtime/client/effects/sounds.js +0 -64
  92. package/src/runtime/index.js +0 -5
  93. package/src/runtime/server/NavigationEvent.js +0 -39
  94. package/src/runtime/server/Runtime.js +0 -593
  95. package/src/runtime/server/index.js +0 -183
  96. package/src/runtime/server/index.mjs +0 -10
  97. package/src/services/index.js +0 -6
@@ -1,74 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { _isTypeObject, _isFunction } from '@webqit/util/js/index.js';
6
- import { wwwFormUnserialize, wwwFormSet } from '../util.js';
7
-
8
- /**
9
- * The Request class
10
- */
11
- export default class StdRequest extends Request {
12
-
13
- constructor(input, init) {
14
- var src;
15
- if (input instanceof Request) {
16
- src = input.clone();
17
- }
18
- super(...arguments);
19
- this.src = src;
20
- }
21
-
22
- get destination() {
23
- return this.src ? this.src.destination : '';
24
- }
25
-
26
- clone() {
27
- return new this.constructor(this.src || super.clone());
28
- }
29
-
30
- get cookies() {
31
- if (!this._cookies) {
32
- this._cookies = wwwFormUnserialize(this.headers.cookie, {}, ';');
33
- }
34
- return this._cookies;
35
- }
36
-
37
- // Payload
38
- parse(force = false) {
39
- if (!this._submits || force) {
40
- this._submits = new Promise(async resolve => {
41
- var request = this.clone();
42
- var contentType = request.headers['content-type'] || '';
43
- var submits = {
44
- inputs: {},
45
- files: {},
46
- type: contentType === 'application/x-www-form-urlencoded' || contentType.startsWith('multipart/') || (!contentType && !['get'].includes(request.method.toLowerCase())) ? 'form-data'
47
- : (contentType === 'application/json' ? 'json'
48
- : (contentType === 'text/plain' ? 'plain'
49
- : 'other')),
50
- };
51
- if (submits.type === 'form-data') {
52
- try {
53
- const payload = await request.formData();
54
- for(var [ name, value ] of payload.entries()) {
55
- if (value instanceof File) {
56
- wwwFormSet(submits.files, name, value);
57
- } else {
58
- wwwFormSet(submits.inputs, name, value);
59
- }
60
- }
61
- } catch(e) { }
62
- } else {
63
- submits.inputs = await (submits.type === 'json'
64
- ? request.json() : (
65
- submits.type === 'plain' ? request.text() : request.arrayBuffer()
66
- )
67
- )
68
- }
69
- resolve(submits);
70
- });
71
- }
72
- return this._submits;
73
- }
74
- }
@@ -1,183 +0,0 @@
1
-
2
-
3
- /**
4
- * @imports
5
- */
6
-
7
- var _sab;
8
- export function request(context, data = {}) {
9
- var response;
10
- const channel = new MessageChannel();
11
- channel.port1.onmessage = e => (console.log('-----receiving'), response = e.data);
12
- console.log('------waiting 11111', self.crossOriginIsolated);
13
- try {
14
- _sab = _sab || new ArrayBuffer(4); Atomics;
15
- context.postMessage({ _sab, ...data, }, [ channel.port2 ]);
16
- Atomics.wait(new Int32Array(_sab), 0, 0, 400);
17
- return channel;
18
- } catch (e) {
19
- console.error('error1', e);
20
- var x = new XMLHttpRequest();
21
- x.timeout = 400;
22
- x.open('get', '/@sleep@/t.js?t=400', false);
23
- x.setRequestHeader('cache-control', 'no-cache, no-store, max-age=0');
24
- try { x.send() } catch(e) { console.error('error2', e, response) }
25
- }
26
-
27
- return response;
28
- }
29
-
30
- export function listen(context, handler) {
31
- console.log('::::::::::::::::::', crossOriginIsolated)
32
- context.addEventListener('message', e => {
33
- if (e.data._sab instanceof SharedArrayBuffer && e.ports.length) {
34
- console.log('--------handling', e.data)
35
- var response = handler(e.data);
36
- if (response !== undefined) {
37
- e.ports[0].postMessage(response);
38
- console.log('--------sent');
39
- Atomics.notify(new Int32Array(e.data._sab), 0, 1);
40
- console.log('--------notified');
41
- }
42
- }
43
- });
44
- }
45
-
46
- /**
47
- * ------------------
48
- * https://www.sitepen.com/blog/the-return-of-sharedarraybuffers-and-atomics
49
- * ------------------
50
- */
51
-
52
- export function sharedArrayBufferToUtf16String(buf) {
53
- const array = new Uint16Array(buf);
54
- return String.fromCharCode.apply(null, array);
55
- }
56
-
57
- export function utf16StringToSharedArrayBuffer(str) {
58
- // 2 bytes for each char
59
- const bytes = str.length *2;
60
- const buffer = new SharedArrayBuffer(bytes);
61
- const arrayBuffer = new Uint16Array(buffer);
62
- for (let i = 0, strLen = str.length; i < strLen; i++) {
63
- arrayBuffer[i] = str.charCodeAt(i);
64
- }
65
- return { array: arrayBuffer, buffer: buffer };
66
- }
67
-
68
- export function encodeUf8StringToSharedArrayBuffer(string) {
69
- // Calculate the byte size of the UTF-8 string
70
- let bytes = string.length;
71
- for (let i = string.length -1; i <= 0; i--) {
72
- const code = string.charCodeAt(i);
73
- if (code > 0x7f && code <= 0x7ff) {
74
- bytes++;
75
- } else if (code > 0x7ff && code <= 0xffff) {
76
- bytes+=2;
77
- }
78
- if (code >= 0xdc00 && code <= 0xdfff) {
79
- i--; // trail surrogate
80
- }
81
- }
82
- const buffer = new SharedArrayBuffer(bytes);
83
- const arrayBuffer = new Uint8Array(buffer);
84
- const encoded = unescape(encodeURIComponent(string));
85
- for (var i = 0; i < encoded.length; i++) {
86
- arrayBuffer[i] = encoded[i].charCodeAt(0);
87
- }
88
- return { array: arrayBuffer, buffer: buffer };
89
- }
90
-
91
- export function decodeUtf8StringFromSharedArrayBuffer(array) {
92
- var encodedString = String.fromCharCode.apply(null, array);
93
- var decodedString = decodeURIComponent(escape(encodedString));
94
- return decodedString;
95
- }
96
-
97
- /**
98
- * // main.js
99
- worker.postMessage(sharedBuffer);
100
- // worker.js
101
- constsharedArray = new Int32Array(m.data);
102
-
103
- const exampleString = "Hello world, this is an example string!";
104
- const sharedArrayBuffer = utf16StringToSharedArrayBuffer(exampleString).buffer;
105
- const backToString = sharedArrayBufferToUtf16String(sharedArrayBuffer);
106
- */
107
-
108
- // Sync Local Storage
109
- function sharedStore(store, persistent = false, onAvailability = 1) {
110
- const storeData = () => Object.keys(store).reduce((_store, key) => (_store[key] = store[key], _store), {});
111
- this.post.send(() => ({ _type: 'WHOLE_STORAGE_SYNC', _persistent: persistent, store: storeData() }), onAvailability);
112
- window.addEventListener('beforeunload', e => {
113
- this.post.send({ _type: 'WHOLE_STORAGE_SYNC', _persistent: persistent });
114
- });
115
- // --------
116
- Observer.observe(store, changes => {
117
- changes.forEach(change => {
118
- if (change.type === 'set') {
119
- if (!(change.detail || {}).noSync) {
120
- this.post.send({ _type: 'STORAGE_SYNC', _persistent: persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]) });
121
- }
122
- } else if (change.type === 'deletion') {
123
- if (!(change.detail || {}).noSync) {
124
- this.post.send({ _type: 'STORAGE_SYNC', _persistent: persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]) });
125
- }
126
- }
127
- });
128
- });
129
- // --------
130
- this.post.receive(e => {
131
- if (e.data && e.data._type === 'STORAGE_SYNC' && e.data._persistent === persistent) {
132
- if (e.data.type === 'set') {
133
- Observer.set(store, e.data.name, e.data.value, { detail: { noSync: true } });
134
- } else if (e.data.type === 'deletion') {
135
- Observer.deleteProperty(store, e.data.name, { detail: { noSync: true } });
136
- }
137
- }
138
- }, onAvailability);
139
- }
140
-
141
- self.addEventListener('message', evt => {
142
-
143
- // SESSION_SYNC
144
- var clientId = evt.source.id;
145
- if (evt.data && evt.data._type === 'WHOLE_STORAGE_SYNC') {
146
- const storage = evt.data._persistent ? localStores : sessionStores;
147
- if (evt.data.store) {
148
- storage[clientId] = evt.data.store;
149
- // --------------------------
150
- // Get mutations synced TO client
151
- Observer.observe(storage[clientId], changes => {
152
- changes.forEach(change => {
153
- if (!(change.detail || {}).noSync) {
154
- self.clients.get(clientId).then(client => {
155
- client.postMessage({ _type: 'STORAGE_SYNC', _persistent: evt.data._persistent, ..._copy(change, [ 'type', 'name', 'path', 'value', 'oldValue', 'isUpdate', 'related', ]), });
156
- });
157
- }
158
- });
159
- });
160
- // --------------------------
161
- } else {
162
- delete storage[clientId];
163
- }
164
- } else if (evt.data && evt.data._type === 'STORAGE_SYNC') {
165
- // --------------------------
166
- // Get mutations synced FROM client
167
- const storage = evt.data._persistent ? localStores : sessionStores;
168
- if (evt.data.type === 'set') {
169
- if (storage[clientId]) Observer.set(storage[clientId], evt.data.name, evt.data.value, { detail: { noSync: true } });
170
- } else if (evt.data.type === 'deletion') {
171
- if (storage[clientId]) Observer.deleteProperty(storage[clientId], evt.data.name, { detail: { noSync: true } });
172
- }
173
- // --------------------------
174
-
175
- // --------------------------
176
- // Relay to other clients
177
- if (evt.data._persistent) {
178
- relay(evt, evt.data);
179
- }
180
- // --------------------------
181
- return;
182
- }
183
- });
@@ -1,64 +0,0 @@
1
- const context = new window.AudioContext();
2
-
3
- export function playFile(filepath) {
4
- // see https://jakearchibald.com/2016/sounds-fun/
5
- // Fetch the file
6
- fetch(filepath)
7
- // Read it into memory as an arrayBuffer
8
- .then(response => response.arrayBuffer())
9
- // Turn it from mp3/aac/whatever into raw audio data
10
- .then(arrayBuffer => context.decodeAudioData(arrayBuffer))
11
- .then(audioBuffer => {
12
- // Now we're ready to play!
13
- const soundSource = context.createBufferSource();
14
- soundSource.buffer = audioBuffer;
15
- soundSource.connect(context.destination);
16
- soundSource.start();
17
- });
18
- }
19
-
20
- export function playSuccess() {
21
- const successNoise = context.createOscillator();
22
- successNoise.frequency = "600";
23
- successNoise.type = "sine";
24
- successNoise.frequency.exponentialRampToValueAtTime(800, context.currentTime + 0.05);
25
- successNoise.frequency.exponentialRampToValueAtTime(1000, context.currentTime + 0.15);
26
-
27
- successGain = context.createGain();
28
- successGain.gain.exponentialRampToValueAtTime(0.01, context.currentTime + 0.3);
29
-
30
- successFilter = context.createBiquadFilter("bandpass");
31
- successFilter.Q = 0.01;
32
-
33
- successNoise
34
- .connect(successFilter)
35
- .connect(successGain)
36
- .connect(context.destination);
37
- successNoise.start();
38
- successNoise.stop(context.currentTime + 0.2);
39
- }
40
-
41
- export function playError() {
42
- const errorNoise = context.createOscillator();
43
- errorNoise.frequency = "400";
44
- errorNoise.type = "sine";
45
- errorNoise.frequency.exponentialRampToValueAtTime(200, context.currentTime + 0.05);
46
- errorNoise.frequency.exponentialRampToValueAtTime(100, context.currentTime + 0.2);
47
-
48
- errorGain = context.createGain();
49
- errorGain.gain.exponentialRampToValueAtTime(0.01, context.currentTime + 0.3);
50
-
51
- errorNoise.connect(errorGain).connect(context.destination);
52
- errorNoise.start();
53
- errorNoise.stop(context.currentTime + 0.3);
54
- }
55
-
56
- let successButton = document.querySelector("#success");
57
- successButton.addEventListener("click", function() {
58
- playFile('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/success.mp3');
59
- });
60
-
61
- let errorButton = document.querySelector("#error");
62
- errorButton.addEventListener("click", function() {
63
- playFile('https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/error.mp3');
64
- });
@@ -1,5 +0,0 @@
1
-
2
- /**
3
- * exports
4
- */
5
- export * as server from './server/index.js';
@@ -1,39 +0,0 @@
1
-
2
- /**
3
- * @imports
4
- */
5
- import { URL } from 'url';
6
- import { Readable } from "stream";
7
- import { FormData, File, Blob } from 'formdata-node';
8
- import { FormDataEncoder } from 'form-data-encoder';
9
- import fetch, { Request, Response, Headers } from 'node-fetch';
10
- import _NavigationEvent from '../_NavigationEvent.js';
11
- import _FormData from '../_FormData.js';
12
-
13
- /**
14
- * Patch MessageStream with formData()
15
- */
16
- const _streamFormDataPatch = MessageStream => class extends MessageStream {
17
-
18
- // formData() polyfill
19
- async formData() {
20
- return null;
21
- }
22
-
23
- };
24
-
25
- /**
26
- * The NavigationEvent class
27
- */
28
- export default _NavigationEvent({
29
- URL,
30
- Request: _streamFormDataPatch(Request),
31
- Response: _streamFormDataPatch(Response),
32
- Headers,
33
- FormData: _FormData(FormData),
34
- File,
35
- Blob,
36
- ReadableStream: Readable,
37
- FormDataEncoder,
38
- fetch
39
- });