fullstacked 0.11.2-1098 → 0.11.3-1111

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/index.js CHANGED
@@ -199,10 +199,12 @@ async function createWebView(instance, onClose, onFirstConnection) {
199
199
  server.close();
200
200
  }
201
201
  };
202
- let closeTimeout, connectedOnce = false;
202
+ let closeTimeout, connectedOnce = false, messagesQueue = [];
203
203
  const onSocketOpen = () => {
204
204
  if (!connectedOnce) {
205
205
  connectedOnce = true;
206
+ messagesQueue.forEach(send);
207
+ messagesQueue = [];
206
208
  onFirstConnection?.();
207
209
  }
208
210
  if (!closeTimeout) return;
@@ -217,14 +219,21 @@ async function createWebView(instance, onClose, onFirstConnection) {
217
219
  onSocketOpen,
218
220
  onSocketClose
219
221
  });
222
+ const send = (m) => {
223
+ const jsonStr = JSON.stringify(m);
224
+ webSockets.forEach((ws2) => ws2.send(jsonStr));
225
+ };
220
226
  server.listen(port);
221
227
  if (!process.env.NO_OPEN) {
222
228
  open(`http://localhost:${port}`);
223
229
  }
224
230
  return {
225
231
  message: (type, message) => {
226
- const jsonStr = JSON.stringify([type, message]);
227
- webSockets.forEach((ws2) => ws2.send(jsonStr));
232
+ if (!connectedOnce) {
233
+ messagesQueue.push([type, message]);
234
+ } else {
235
+ send([type, message]);
236
+ }
228
237
  }
229
238
  };
230
239
  }
@@ -1,11 +1,13 @@
1
1
  import { Bridge } from "..";
2
2
  import { deserializeArgs } from "../serialization";
3
3
 
4
+ const bridge = globalThis.fetch;
5
+
4
6
  export const BridgeNode: Bridge = async (
5
7
  payload: Uint8Array,
6
8
  transformer?: (responseArgs: any[]) => any
7
9
  ) => {
8
- const response = await fetch("/call", {
10
+ const response = await bridge("/call", {
9
11
  method: "POST",
10
12
  body: payload
11
13
  });
@@ -152,20 +152,16 @@ function receivedResponse2(base64Data: string) {
152
152
  return { done: false, value: chunk };
153
153
  };
154
154
 
155
+ const it = {
156
+ next: read
157
+ } as AsyncIterator<Uint8Array>
158
+
155
159
  const responseIterator = {
156
160
  [Symbol.asyncIterator]() {
157
- return {
158
- next: read
159
- } as any;
161
+ return it
160
162
  }
161
163
  };
162
164
 
163
- const getReader = () =>
164
- ({
165
- read,
166
- releaseLock() {}
167
- }) as any;
168
-
169
165
  const readBody = async () => {
170
166
  if (!ok) {
171
167
  return te.encode(statusText);
@@ -190,30 +186,7 @@ function receivedResponse2(base64Data: string) {
190
186
  statusText,
191
187
  headers: objectToHeaders(JSON.parse(headersStr || "{}")),
192
188
 
193
- body: {
194
- getReader,
195
- tee() {
196
- return [{ getReader }, { getReader }] as any;
197
- },
198
-
199
- ...responseIterator,
200
- async cancel() {
201
- console.log("cancel not implemented");
202
- },
203
- locked: false,
204
- pipeThrough(transform, options) {
205
- console.log("pipeThrough not implemented");
206
- return null;
207
- },
208
- pipeTo(destination, options) {
209
- console.log("pipeTo not implemented");
210
- return null;
211
- },
212
- values(options) {
213
- console.log("values");
214
- return null;
215
- }
216
- },
189
+ body: iteratorToStream(it),
217
190
 
218
191
  bytes: readBody,
219
192
  arrayBuffer: async () => {
@@ -327,3 +300,19 @@ const headersToObject = (h: Headers) => {
327
300
  }
328
301
  return obj;
329
302
  };
303
+
304
+ // https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#convert_an_iterator_or_async_iterator_to_a_stream
305
+ function iteratorToStream(iterator: AsyncIterator<Uint8Array>) {
306
+ return new ReadableStream({
307
+ async pull(controller) {
308
+ const { value, done } = await iterator.next();
309
+
310
+ if (value) {
311
+ controller.enqueue(value);
312
+ }
313
+ if (done) {
314
+ controller.close();
315
+ }
316
+ },
317
+ });
318
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fullstacked",
3
- "version": "0.11.2-1098",
3
+ "version": "0.11.3-1111",
4
4
  "scripts": {
5
5
  "build": "node build.js",
6
6
  "start": "npm run build && node index.js --lib ../../core/bin --root ~/FullStacked --config ~/.config/fullstacked --editor ../../out/editor",