@base44-preview/cli 0.1.32-pr.664.478a865 → 0.1.32-pr.664.89779c9

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/dist/cli/index.js CHANGED
@@ -253402,8 +253402,12 @@ var deno2 = Object.freeze({
253402
253402
  });
253403
253403
  globalThis.Deno = deno2;
253404
253404
  globalThis.Buffer = Buffer2;
253405
- AsyncLocalStorage.prototype.enterWith = () => {
253406
- };
253405
+ try {
253406
+ new AsyncLocalStorage().enterWith(void 0);
253407
+ } catch {
253408
+ AsyncLocalStorage.prototype.enterWith = () => {
253409
+ };
253410
+ }
253407
253411
  function getRegisteredHandler() {
253408
253412
  return registeredHandler;
253409
253413
  }
@@ -260998,27 +261002,38 @@ var NAMESPACE4 = "base44-ws-native";
260998
261002
  var WS_SPECIFIER = /^(npm:)?ws(@[^/]+)?$/;
260999
261003
  var ADAPTER = `"use strict";
261000
261004
  const toBuffer = (value) => (globalThis.Buffer ? globalThis.Buffer.from(value) : value);
261005
+ const READY_STATES = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
261006
+ const upgradeHeaders = (options) => {
261007
+ const headers = new Headers(options?.headers);
261008
+ for (const name of headers.keys()) if (name !== "user-agent") return headers;
261009
+ return null;
261010
+ };
261001
261011
  class WebSocket {
261002
261012
  static CONNECTING = 0;
261003
261013
  static OPEN = 1;
261004
261014
  static CLOSING = 2;
261005
261015
  static CLOSED = 3;
261006
- #socket;
261016
+ #socket = null;
261017
+ #state = 0;
261018
+ #url;
261019
+ #closeRequested = null;
261007
261020
  #listeners = new Map();
261008
- constructor(address, protocols) {
261009
- this.#socket = new globalThis.WebSocket(String(address), typeof protocols === "string" || Array.isArray(protocols) ? protocols : undefined);
261010
- try { this.#socket.binaryType = "arraybuffer"; } catch {}
261011
- this.#socket.addEventListener("open", () => this.emit("open"));
261012
- this.#socket.addEventListener("message", (event) => {
261013
- const isBinary = typeof event.data !== "string";
261014
- this.emit("message", toBuffer(isBinary ? new Uint8Array(event.data) : event.data), isBinary);
261015
- });
261016
- this.#socket.addEventListener("error", (event) => this.emit("error", event.error ?? new Error(event.message || "WebSocket error")));
261017
- this.#socket.addEventListener("close", (event) => this.emit("close", event.code, toBuffer(event.reason ?? "")));
261021
+ constructor(address, protocols, options) {
261022
+ if (protocols && typeof protocols === "object" && !Array.isArray(protocols)) {
261023
+ options = protocols;
261024
+ protocols = undefined;
261025
+ }
261026
+ this.#url = String(address);
261027
+ const headers = upgradeHeaders(options);
261028
+ if (headers) {
261029
+ this.#upgrade(headers, protocols);
261030
+ } else {
261031
+ this.#attach(new globalThis.WebSocket(this.#url, protocols));
261032
+ }
261018
261033
  }
261019
- get readyState() { return this.#socket.readyState; }
261020
- get url() { return this.#socket.url; }
261021
- get protocol() { return this.#socket.protocol; }
261034
+ get readyState() { return this.#socket ? this.#socket.readyState : this.#state; }
261035
+ get url() { return this.#url; }
261036
+ get protocol() { return this.#socket ? this.#socket.protocol ?? "" : ""; }
261022
261037
  on(name, listener) { return this.#add(name, listener, false); }
261023
261038
  addListener(name, listener) { return this.#add(name, listener, false); }
261024
261039
  once(name, listener) { return this.#add(name, listener, true); }
@@ -261042,6 +261057,9 @@ class WebSocket {
261042
261057
  send(data, options, callback) {
261043
261058
  const done = typeof options === "function" ? options : callback;
261044
261059
  try {
261060
+ if (!this.#socket) {
261061
+ throw new Error("WebSocket is not open: readyState " + this.#state + " (" + READY_STATES[this.#state] + ")");
261062
+ }
261045
261063
  this.#socket.send(data);
261046
261064
  done?.();
261047
261065
  } catch (error) {
@@ -261049,8 +261067,50 @@ class WebSocket {
261049
261067
  done(error);
261050
261068
  }
261051
261069
  }
261052
- close(code, reason) { this.#socket.close(code, reason); }
261053
- terminate() { this.#socket.close(); }
261070
+ close(code, reason) {
261071
+ if (this.#socket) this.#socket.close(code, reason);
261072
+ else if (this.#state === 0) {
261073
+ // Upgrade still in flight: close as soon as it lands.
261074
+ this.#closeRequested = [code, reason];
261075
+ this.#state = 2;
261076
+ }
261077
+ }
261078
+ terminate() { this.close(); }
261079
+ #attach(socket) {
261080
+ this.#socket = socket;
261081
+ try { socket.binaryType = "arraybuffer"; } catch {}
261082
+ socket.addEventListener("open", () => this.emit("open"));
261083
+ socket.addEventListener("message", (event) => {
261084
+ const isBinary = typeof event.data !== "string";
261085
+ this.emit("message", toBuffer(isBinary ? new Uint8Array(event.data) : event.data), isBinary);
261086
+ });
261087
+ socket.addEventListener("error", (event) => this.emit("error", event.error ?? new Error(event.message || "WebSocket error")));
261088
+ socket.addEventListener("close", (event) => this.emit("close", event.code, toBuffer(event.reason ?? "")));
261089
+ }
261090
+ #upgrade(headers, protocols) {
261091
+ headers.set("Upgrade", "websocket");
261092
+ if (protocols) headers.set("Sec-WebSocket-Protocol", [].concat(protocols).join(", "));
261093
+ const httpUrl = this.#url.replace(/^ws(s?):/i, "http$1:");
261094
+ const fail = (error) => {
261095
+ this.#state = 3;
261096
+ this.emit("error", error);
261097
+ this.emit("close", 1006, toBuffer(""));
261098
+ };
261099
+ // Two-argument then(): an exception from an "open" listener must not be
261100
+ // reported as a failed upgrade.
261101
+ fetch(httpUrl, { headers }).then((response) => {
261102
+ const socket = response.webSocket;
261103
+ if (!socket) {
261104
+ response.body?.cancel();
261105
+ return fail(new Error("Unexpected server response: " + response.status));
261106
+ }
261107
+ socket.accept();
261108
+ this.#attach(socket);
261109
+ if (this.#closeRequested) return socket.close(...this.#closeRequested);
261110
+ // accept() opens the socket without dispatching an "open" event.
261111
+ this.emit("open");
261112
+ }, fail);
261113
+ }
261054
261114
  #add(name, listener, once) {
261055
261115
  const listeners = this.#listeners.get(name) ?? [];
261056
261116
  listeners.push({ listener, once });
@@ -271496,4 +271556,4 @@ export {
271496
271556
  runCLI
271497
271557
  };
271498
271558
 
271499
- //# debugId=F78FCF622784F43164756E2164756E21
271559
+ //# debugId=B28345EB77F07FBF64756E2164756E21