@mtkruto/browser 0.119.0 → 0.119.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 (127) hide show
  1. package/esm/0_errors.d.ts.map +1 -1
  2. package/esm/0_errors.js +9 -31
  3. package/esm/3_errors.js +2 -12
  4. package/esm/4_errors.js +2 -12
  5. package/esm/_dnt.polyfills.d.ts +0 -99
  6. package/esm/_dnt.polyfills.d.ts.map +1 -1
  7. package/esm/_dnt.polyfills.js +1 -127
  8. package/esm/client/0_abortable_loop.js +26 -39
  9. package/esm/client/0_storage_operations.js +179 -218
  10. package/esm/client/1_client_plain.js +4 -22
  11. package/esm/client/2_account_manager.js +140 -149
  12. package/esm/client/2_bot_info_manager.js +26 -38
  13. package/esm/client/2_business_connection_manager.js +10 -23
  14. package/esm/client/2_client_encrypted.js +198 -215
  15. package/esm/client/2_file_manager.js +255 -262
  16. package/esm/client/2_network_statistics_manager.js +31 -44
  17. package/esm/client/2_payment_manager.js +7 -20
  18. package/esm/client/2_reaction_manager.js +7 -20
  19. package/esm/client/2_translations_manager.js +101 -111
  20. package/esm/client/2_update_manager.js +750 -745
  21. package/esm/client/3_client_encrypted_pool.js +10 -26
  22. package/esm/client/3_message_manager.js +503 -508
  23. package/esm/client/3_video_chat_manager.js +57 -68
  24. package/esm/client/4_callback_query_manager.js +18 -30
  25. package/esm/client/4_chat_list_manager.js +140 -146
  26. package/esm/client/4_chat_manager.js +161 -169
  27. package/esm/client/4_checklist_manager.js +26 -39
  28. package/esm/client/4_context.js +244 -259
  29. package/esm/client/4_forum_manager.js +67 -73
  30. package/esm/client/4_gift_manager.js +22 -35
  31. package/esm/client/4_inline_query_manager.js +16 -28
  32. package/esm/client/4_link_preview_manager.js +6 -19
  33. package/esm/client/4_poll_manager.js +44 -57
  34. package/esm/client/4_story_manager.js +41 -53
  35. package/esm/client/5_composer.js +13 -26
  36. package/esm/client/6_client.js +866 -896
  37. package/esm/client/6_client_dispatcher.js +308 -325
  38. package/esm/client/7_client_worker.js +16 -29
  39. package/esm/connection/1_connection_tcp.js +55 -82
  40. package/esm/connection/1_connection_web_socket.js +75 -91
  41. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  42. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  43. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  44. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  45. package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  46. package/esm/session/0_session_state.js +12 -38
  47. package/esm/session/1_session.js +49 -72
  48. package/esm/session/2_session_encrypted.js +422 -420
  49. package/esm/storage/2_storage_indexed_db.js +26 -44
  50. package/esm/storage/2_storage_local_storage.js +3 -16
  51. package/esm/storage/2_storage_memory.js +24 -41
  52. package/esm/storage/2_storage_session_storage.js +3 -16
  53. package/esm/tl/1_tl_reader.d.ts +1 -1
  54. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  55. package/esm/tl/1_tl_reader.js +95 -103
  56. package/esm/tl/1_tl_writer.js +169 -178
  57. package/esm/transport/0_transport.js +1 -8
  58. package/esm/transport/1_transport_abridged.js +11 -24
  59. package/esm/transport/1_transport_intermediate.js +10 -23
  60. package/esm/utilities/0_mutex.js +4 -19
  61. package/esm/utilities/0_part_stream.js +11 -25
  62. package/esm/utilities/1_crypto.js +42 -53
  63. package/esm/utilities/2_queue.js +29 -47
  64. package/package.json +1 -1
  65. package/script/0_errors.d.ts.map +1 -1
  66. package/script/0_errors.js +9 -31
  67. package/script/3_errors.js +2 -12
  68. package/script/4_errors.js +2 -12
  69. package/script/_dnt.polyfills.d.ts +0 -99
  70. package/script/_dnt.polyfills.d.ts.map +1 -1
  71. package/script/_dnt.polyfills.js +0 -128
  72. package/script/client/0_abortable_loop.js +27 -40
  73. package/script/client/0_storage_operations.js +179 -218
  74. package/script/client/1_client_plain.js +4 -22
  75. package/script/client/2_account_manager.js +140 -149
  76. package/script/client/2_bot_info_manager.js +26 -38
  77. package/script/client/2_business_connection_manager.js +10 -23
  78. package/script/client/2_client_encrypted.js +199 -216
  79. package/script/client/2_file_manager.js +255 -262
  80. package/script/client/2_network_statistics_manager.js +32 -45
  81. package/script/client/2_payment_manager.js +7 -20
  82. package/script/client/2_reaction_manager.js +7 -20
  83. package/script/client/2_translations_manager.js +102 -112
  84. package/script/client/2_update_manager.js +750 -745
  85. package/script/client/3_client_encrypted_pool.js +10 -26
  86. package/script/client/3_message_manager.js +503 -508
  87. package/script/client/3_video_chat_manager.js +57 -68
  88. package/script/client/4_callback_query_manager.js +18 -30
  89. package/script/client/4_chat_list_manager.js +140 -146
  90. package/script/client/4_chat_manager.js +161 -169
  91. package/script/client/4_checklist_manager.js +26 -39
  92. package/script/client/4_context.js +244 -259
  93. package/script/client/4_forum_manager.js +67 -73
  94. package/script/client/4_gift_manager.js +22 -35
  95. package/script/client/4_inline_query_manager.js +16 -28
  96. package/script/client/4_link_preview_manager.js +6 -19
  97. package/script/client/4_poll_manager.js +44 -57
  98. package/script/client/4_story_manager.js +41 -53
  99. package/script/client/5_composer.js +13 -26
  100. package/script/client/6_client.js +866 -896
  101. package/script/client/6_client_dispatcher.js +308 -325
  102. package/script/client/7_client_worker.js +16 -29
  103. package/script/connection/1_connection_tcp.js +55 -82
  104. package/script/connection/1_connection_web_socket.js +75 -91
  105. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  106. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  107. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  108. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  109. package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  110. package/script/session/0_session_state.js +12 -38
  111. package/script/session/1_session.js +49 -72
  112. package/script/session/2_session_encrypted.js +423 -421
  113. package/script/storage/2_storage_indexed_db.js +26 -44
  114. package/script/storage/2_storage_local_storage.js +3 -16
  115. package/script/storage/2_storage_memory.js +24 -41
  116. package/script/storage/2_storage_session_storage.js +3 -16
  117. package/script/tl/1_tl_reader.d.ts +1 -1
  118. package/script/tl/1_tl_reader.d.ts.map +1 -1
  119. package/script/tl/1_tl_reader.js +96 -104
  120. package/script/tl/1_tl_writer.js +170 -179
  121. package/script/transport/0_transport.js +1 -8
  122. package/script/transport/1_transport_abridged.js +11 -24
  123. package/script/transport/1_transport_intermediate.js +10 -23
  124. package/script/utilities/0_mutex.js +4 -19
  125. package/script/utilities/0_part_stream.js +11 -25
  126. package/script/utilities/1_crypto.js +43 -54
  127. package/script/utilities/2_queue.js +30 -48
@@ -18,38 +18,26 @@
18
18
  * You should have received a copy of the GNU Lesser General Public License
19
19
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
  */
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
30
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
- };
32
- var _ClientWorker_worker, _ClientWorker_clients, _ClientWorker_L;
33
21
  Object.defineProperty(exports, "__esModule", { value: true });
34
22
  exports.ClientWorker = void 0;
35
23
  const _0_errors_js_1 = require("../0_errors.js");
36
24
  const _1_logger_js_1 = require("../utilities/1_logger.js");
37
25
  const _6_client_dispatcher_js_1 = require("./6_client_dispatcher.js");
38
26
  class ClientWorker {
27
+ #worker;
28
+ #clients = new Map();
29
+ #L = (0, _1_logger_js_1.getLogger)("ClientWorker");
39
30
  constructor(worker) {
40
- _ClientWorker_worker.set(this, void 0);
41
- _ClientWorker_clients.set(this, new Map());
42
- _ClientWorker_L.set(this, (0, _1_logger_js_1.getLogger)("ClientWorker"));
43
- __classPrivateFieldSet(this, _ClientWorker_worker, worker, "f");
44
- __classPrivateFieldGet(this, _ClientWorker_worker, "f").addEventListener("message", async (e) => {
31
+ this.#worker = worker;
32
+ this.#worker.addEventListener("message", async (e) => {
45
33
  const message = e.data;
46
- __classPrivateFieldGet(this, _ClientWorker_L, "f").debug("received message from worker", message);
34
+ this.#L.debug("received message from worker", message);
47
35
  if (message.type === "response") {
48
- __classPrivateFieldGet(this, _ClientWorker_clients, "f").get(message.clientId)?.handleResponse(message);
36
+ this.#clients.get(message.clientId)?.handleResponse(message);
49
37
  }
50
38
  else if (message.type === "request") {
51
39
  if (message.method === "handleInvokeError") {
52
- const client = __classPrivateFieldGet(this, _ClientWorker_clients, "f").get(message.clientId);
40
+ const client = this.#clients.get(message.clientId);
53
41
  if (client) {
54
42
  const result = await client.handleInvokeError(message);
55
43
  const response = {
@@ -59,35 +47,34 @@ class ClientWorker {
59
47
  isError: false,
60
48
  data: result,
61
49
  };
62
- __classPrivateFieldGet(this, _ClientWorker_worker, "f").postMessage(response);
50
+ this.#worker.postMessage(response);
63
51
  }
64
52
  }
65
53
  }
66
54
  });
67
55
  }
68
56
  async createClient(id, params) {
69
- if (__classPrivateFieldGet(this, _ClientWorker_clients, "f").has(id)) {
57
+ if (this.#clients.has(id)) {
70
58
  throw new _0_errors_js_1.InputError("Client already created");
71
59
  }
72
- const client = new _6_client_dispatcher_js_1.ClientDispatcher(__classPrivateFieldGet(this, _ClientWorker_worker, "f"), id);
73
- __classPrivateFieldGet(this, _ClientWorker_clients, "f").set(id, client);
60
+ const client = new _6_client_dispatcher_js_1.ClientDispatcher(this.#worker, id);
61
+ this.#clients.set(id, client);
74
62
  try {
75
63
  await client.init(params);
76
64
  }
77
65
  catch (err) {
78
- __classPrivateFieldGet(this, _ClientWorker_clients, "f").delete(id);
66
+ this.#clients.delete(id);
79
67
  throw err;
80
68
  }
81
69
  return client;
82
70
  }
83
71
  getClient(id) {
84
- let client = __classPrivateFieldGet(this, _ClientWorker_clients, "f").get(id);
72
+ let client = this.#clients.get(id);
85
73
  if (!client) {
86
- client = new _6_client_dispatcher_js_1.ClientDispatcher(__classPrivateFieldGet(this, _ClientWorker_worker, "f"), id);
87
- __classPrivateFieldGet(this, _ClientWorker_clients, "f").set(id, client);
74
+ client = new _6_client_dispatcher_js_1.ClientDispatcher(this.#worker, id);
75
+ this.#clients.set(id, client);
88
76
  }
89
77
  return client;
90
78
  }
91
79
  }
92
80
  exports.ClientWorker = ClientWorker;
93
- _ClientWorker_worker = new WeakMap(), _ClientWorker_clients = new WeakMap(), _ClientWorker_L = new WeakMap();
@@ -18,18 +18,6 @@
18
18
  * You should have received a copy of the GNU Lesser General Public License
19
19
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
  */
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
30
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
- };
32
- var _ConnectionTCP_instances, _ConnectionTCP_hostname, _ConnectionTCP_port, _ConnectionTCP_connection, _ConnectionTCP_rMutex, _ConnectionTCP_wMutex, _ConnectionTCP_buffer, _ConnectionTCP_nextResolve, _ConnectionTCP_canRead, _ConnectionTCP_canWrite, _ConnectionTCP_assertConnected, _ConnectionTCP_rejectRead;
33
21
  Object.defineProperty(exports, "__esModule", { value: true });
34
22
  exports.ConnectionTCP = void 0;
35
23
  const _0_deps_js_1 = require("../0_deps.js");
@@ -37,110 +25,105 @@ const _0_errors_js_1 = require("../0_errors.js");
37
25
  const _1_utilities_js_1 = require("../1_utilities.js");
38
26
  const L = (0, _1_utilities_js_1.getLogger)("ConnectionTCP");
39
27
  class ConnectionTCP {
28
+ #hostname;
29
+ #port;
30
+ #connection;
31
+ #rMutex = new _1_utilities_js_1.Mutex();
32
+ #wMutex = new _1_utilities_js_1.Mutex();
33
+ #buffer = new Uint8Array();
34
+ #nextResolve = null;
35
+ #canRead = false;
36
+ #canWrite = false;
37
+ connect = Deno.connect;
38
+ stateChangeHandler;
39
+ callback;
40
40
  constructor(hostname, port) {
41
- _ConnectionTCP_instances.add(this);
42
- _ConnectionTCP_hostname.set(this, void 0);
43
- _ConnectionTCP_port.set(this, void 0);
44
- _ConnectionTCP_connection.set(this, void 0);
45
- _ConnectionTCP_rMutex.set(this, new _1_utilities_js_1.Mutex());
46
- _ConnectionTCP_wMutex.set(this, new _1_utilities_js_1.Mutex());
47
- _ConnectionTCP_buffer.set(this, new Uint8Array());
48
- _ConnectionTCP_nextResolve.set(this, null);
49
- _ConnectionTCP_canRead.set(this, false);
50
- _ConnectionTCP_canWrite.set(this, false);
51
- Object.defineProperty(this, "connect", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: Deno.connect
56
- });
57
- Object.defineProperty(this, "stateChangeHandler", {
58
- enumerable: true,
59
- configurable: true,
60
- writable: true,
61
- value: void 0
62
- });
63
- Object.defineProperty(this, "callback", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: void 0
68
- });
69
- __classPrivateFieldSet(this, _ConnectionTCP_hostname, hostname, "f");
70
- __classPrivateFieldSet(this, _ConnectionTCP_port, port, "f");
41
+ this.#hostname = hostname;
42
+ this.#port = port;
71
43
  }
72
44
  get isConnected() {
73
- return !!__classPrivateFieldGet(this, _ConnectionTCP_connection, "f") && __classPrivateFieldGet(this, _ConnectionTCP_canRead, "f") && __classPrivateFieldGet(this, _ConnectionTCP_canWrite, "f");
45
+ return !!this.#connection && this.#canRead && this.#canWrite;
46
+ }
47
+ #assertConnected() {
48
+ if (!this.isConnected) {
49
+ throw new _0_errors_js_1.ConnectionError("The connection is not open.");
50
+ }
74
51
  }
75
52
  async open() {
76
53
  if (this.isConnected) {
77
54
  return;
78
55
  }
79
56
  const connection = await this.connect({
80
- hostname: __classPrivateFieldGet(this, _ConnectionTCP_hostname, "f"),
81
- port: __classPrivateFieldGet(this, _ConnectionTCP_port, "f"),
57
+ hostname: this.#hostname,
58
+ port: this.#port,
82
59
  });
83
60
  connection.setNoDelay(true);
84
61
  connection.setKeepAlive(true);
85
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, __classPrivateFieldSet(this, _ConnectionTCP_canWrite, true, "f"), "f");
62
+ this.#canRead = this.#canWrite = true;
86
63
  this.stateChangeHandler?.(true);
87
- L.debug("connected to", __classPrivateFieldGet(this, _ConnectionTCP_hostname, "f"), "port", __classPrivateFieldGet(this, _ConnectionTCP_port, "f"));
64
+ L.debug("connected to", this.#hostname, "port", this.#port);
88
65
  Promise.resolve().then(async () => {
89
66
  do {
90
67
  try {
91
68
  for await (const chunk of (0, _0_deps_js_1.iterateReader)(connection)) {
92
69
  this.callback?.read(chunk.length);
93
- __classPrivateFieldSet(this, _ConnectionTCP_buffer, (0, _0_deps_js_1.concat)([__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f"), chunk]), "f");
94
- if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") !== null && __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[0]) {
95
- __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].resolve();
96
- __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
70
+ this.#buffer = (0, _0_deps_js_1.concat)([this.#buffer, chunk]);
71
+ if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
72
+ this.#nextResolve[1].resolve();
73
+ this.#nextResolve = null;
97
74
  }
98
75
  }
99
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, false, "f");
76
+ this.#canRead = false;
100
77
  break;
101
78
  }
102
79
  catch (err) {
103
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, false, "f");
80
+ this.#canRead = false;
104
81
  this.stateChangeHandler?.(false);
105
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_rejectRead).call(this);
82
+ this.#rejectRead();
106
83
  L.error(err);
107
84
  }
108
85
  } while (this.isConnected);
109
86
  this.stateChangeHandler?.(false);
110
87
  });
111
- __classPrivateFieldSet(this, _ConnectionTCP_connection, connection, "f");
88
+ this.#connection = connection;
89
+ }
90
+ #rejectRead() {
91
+ if (this.#nextResolve !== null) {
92
+ this.#nextResolve[1].reject(new _0_errors_js_1.ConnectionError("The connection was closed."));
93
+ this.#nextResolve = null;
94
+ }
112
95
  }
113
96
  async read(p) {
114
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
115
- const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_rMutex, "f").lock();
97
+ this.#assertConnected();
98
+ const unlock = await this.#rMutex.lock();
116
99
  try {
117
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
118
- if (__classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").length < p.length) {
119
- await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, [p.length, { resolve, reject }], "f"));
100
+ this.#assertConnected();
101
+ if (this.#buffer.length < p.length) {
102
+ await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
120
103
  }
121
- const slice = __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").slice(0, p.length);
104
+ const slice = this.#buffer.slice(0, p.length);
122
105
  p.set(slice);
123
- __classPrivateFieldSet(this, _ConnectionTCP_buffer, __classPrivateFieldGet(this, _ConnectionTCP_buffer, "f").slice(slice.length), "f");
106
+ this.#buffer = this.#buffer.slice(slice.length);
124
107
  }
125
108
  finally {
126
109
  unlock();
127
110
  }
128
111
  }
129
112
  async write(p) {
130
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
131
- const unlock = await __classPrivateFieldGet(this, _ConnectionTCP_wMutex, "f").lock();
113
+ this.#assertConnected();
114
+ const unlock = await this.#wMutex.lock();
132
115
  try {
133
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
116
+ this.#assertConnected();
134
117
  let written = 0;
135
118
  while (written < p.length) {
136
119
  try {
137
- const wrote = await __classPrivateFieldGet(this, _ConnectionTCP_connection, "f").write(p.subarray(written));
120
+ const wrote = await this.#connection.write(p.subarray(written));
138
121
  this.callback?.write(wrote);
139
122
  written += wrote;
140
123
  }
141
124
  catch (err) {
142
125
  if (err instanceof Deno.errors.BrokenPipe || err instanceof Deno.errors.ConnectionReset) {
143
- __classPrivateFieldSet(this, _ConnectionTCP_canWrite, false, "f");
126
+ this.#canWrite = false;
144
127
  }
145
128
  if (!this.isConnected) {
146
129
  this.stateChangeHandler?.(false);
@@ -157,21 +140,11 @@ class ConnectionTCP {
157
140
  }
158
141
  }
159
142
  close() {
160
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_assertConnected).call(this);
161
- __classPrivateFieldGet(this, _ConnectionTCP_connection, "f").close();
162
- __classPrivateFieldSet(this, _ConnectionTCP_canRead, __classPrivateFieldSet(this, _ConnectionTCP_canWrite, false, "f"), "f");
163
- __classPrivateFieldSet(this, _ConnectionTCP_connection, undefined, "f");
164
- __classPrivateFieldGet(this, _ConnectionTCP_instances, "m", _ConnectionTCP_rejectRead).call(this);
143
+ this.#assertConnected();
144
+ this.#connection.close();
145
+ this.#canRead = this.#canWrite = false;
146
+ this.#connection = undefined;
147
+ this.#rejectRead();
165
148
  }
166
149
  }
167
150
  exports.ConnectionTCP = ConnectionTCP;
168
- _ConnectionTCP_hostname = new WeakMap(), _ConnectionTCP_port = new WeakMap(), _ConnectionTCP_connection = new WeakMap(), _ConnectionTCP_rMutex = new WeakMap(), _ConnectionTCP_wMutex = new WeakMap(), _ConnectionTCP_buffer = new WeakMap(), _ConnectionTCP_nextResolve = new WeakMap(), _ConnectionTCP_canRead = new WeakMap(), _ConnectionTCP_canWrite = new WeakMap(), _ConnectionTCP_instances = new WeakSet(), _ConnectionTCP_assertConnected = function _ConnectionTCP_assertConnected() {
169
- if (!this.isConnected) {
170
- throw new _0_errors_js_1.ConnectionError("The connection is not open.");
171
- }
172
- }, _ConnectionTCP_rejectRead = function _ConnectionTCP_rejectRead() {
173
- if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") !== null) {
174
- __classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].reject(new _0_errors_js_1.ConnectionError("The connection was closed."));
175
- __classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
176
- }
177
- };
@@ -18,18 +18,6 @@
18
18
  * You should have received a copy of the GNU Lesser General Public License
19
19
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
  */
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
30
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
- };
32
- var _ConnectionWebSocket_instances, _ConnectionWebSocket_url, _ConnectionWebSocket_webSocket, _ConnectionWebSocket_rMutex, _ConnectionWebSocket_wMutex, _ConnectionWebSocket_buffer, _ConnectionWebSocket_nextResolve, _ConnectionWebSocket_initWs, _ConnectionWebSocket_isConnecting, _ConnectionWebSocket_assertConnected, _ConnectionWebSocket_rejectRead;
33
21
  Object.defineProperty(exports, "__esModule", { value: true });
34
22
  exports.ConnectionWebSocket = void 0;
35
23
  const _0_deps_js_1 = require("../0_deps.js");
@@ -38,115 +26,111 @@ const _1_utilities_js_1 = require("../1_utilities.js");
38
26
  const L = (0, _1_utilities_js_1.getLogger)("ConnectionWebSocket");
39
27
  const errConnectionNotOpen = new _0_errors_js_1.ConnectionError("The connection is not open.");
40
28
  class ConnectionWebSocket {
29
+ #url;
30
+ #webSocket;
31
+ #rMutex = new _1_utilities_js_1.Mutex();
32
+ #wMutex = new _1_utilities_js_1.Mutex();
33
+ #buffer = new Uint8Array();
34
+ #nextResolve = null;
35
+ stateChangeHandler;
41
36
  constructor(url) {
42
- _ConnectionWebSocket_instances.add(this);
43
- _ConnectionWebSocket_url.set(this, void 0);
44
- _ConnectionWebSocket_webSocket.set(this, void 0);
45
- _ConnectionWebSocket_rMutex.set(this, new _1_utilities_js_1.Mutex());
46
- _ConnectionWebSocket_wMutex.set(this, new _1_utilities_js_1.Mutex());
47
- _ConnectionWebSocket_buffer.set(this, new Uint8Array());
48
- _ConnectionWebSocket_nextResolve.set(this, null);
49
- Object.defineProperty(this, "stateChangeHandler", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
37
+ this.#url = url;
38
+ }
39
+ #initWs() {
40
+ return new Promise((resolve, reject) => {
41
+ const webSocket = new WebSocket(this.#url, "binary");
42
+ const mutex = new _1_utilities_js_1.Mutex();
43
+ webSocket.addEventListener("close", () => {
44
+ this.#rejectRead();
45
+ this.stateChangeHandler?.(false);
46
+ });
47
+ webSocket.addEventListener("open", () => {
48
+ this.stateChangeHandler?.(true);
49
+ resolve(webSocket);
50
+ L.debug("connected to", this.#url);
51
+ });
52
+ webSocket.addEventListener("message", async (e) => {
53
+ if (typeof e.data === "string") {
54
+ return;
55
+ }
56
+ const unlock = await mutex.lock();
57
+ const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _0_deps_js_1.unreachable)())).arrayBuffer());
58
+ this.#buffer = (0, _0_deps_js_1.concat)([this.#buffer, data]);
59
+ if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
60
+ this.#nextResolve[1].resolve();
61
+ this.#nextResolve = null;
62
+ }
63
+ unlock();
64
+ });
65
+ webSocket.addEventListener("error", (err) => {
66
+ if (this.#isConnecting) {
67
+ reject("message" in err ? new _0_errors_js_1.ConnectionError(err.message) : new _0_errors_js_1.ConnectionError("Failed to connect."));
68
+ }
69
+ if (this.isConnected) {
70
+ L.error(err);
71
+ }
72
+ });
54
73
  });
55
- _ConnectionWebSocket_isConnecting.set(this, false);
56
- __classPrivateFieldSet(this, _ConnectionWebSocket_url, url, "f");
57
74
  }
58
75
  get isConnected() {
59
- return !!__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f") && __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState === WebSocket.OPEN;
76
+ return !!this.#webSocket && this.#webSocket.readyState === WebSocket.OPEN;
60
77
  }
78
+ #isConnecting = false;
61
79
  async open() {
62
- if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
80
+ if (this.#isConnecting) {
63
81
  return;
64
82
  }
65
- __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, true, "f");
83
+ this.#isConnecting = true;
66
84
  try {
67
- __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, await __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_initWs).call(this), "f");
85
+ this.#webSocket = await this.#initWs();
68
86
  }
69
87
  finally {
70
- __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, false, "f");
88
+ this.#isConnecting = false;
89
+ }
90
+ }
91
+ #assertConnected() {
92
+ if (!this.isConnected) {
93
+ throw errConnectionNotOpen;
71
94
  }
72
95
  }
73
96
  async read(p) {
74
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
75
- const unlock = await __classPrivateFieldGet(this, _ConnectionWebSocket_rMutex, "f").lock();
97
+ this.#assertConnected();
98
+ const unlock = await this.#rMutex.lock();
76
99
  try {
77
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
78
- if (__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length < p.length) {
79
- await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, [p.length, { resolve, reject }], "f"));
100
+ this.#assertConnected();
101
+ if (this.#buffer.length < p.length) {
102
+ await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
80
103
  }
81
- const slice = __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").slice(0, p.length);
104
+ const slice = this.#buffer.slice(0, p.length);
82
105
  p.set(slice);
83
- __classPrivateFieldSet(this, _ConnectionWebSocket_buffer, __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").slice(slice.length), "f");
106
+ this.#buffer = this.#buffer.slice(slice.length);
84
107
  }
85
108
  finally {
86
109
  unlock();
87
110
  }
88
111
  }
89
112
  async write(p) {
90
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
91
- const unlock = await __classPrivateFieldGet(this, _ConnectionWebSocket_wMutex, "f").lock();
113
+ this.#assertConnected();
114
+ const unlock = await this.#wMutex.lock();
92
115
  try {
93
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
94
- __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").send(p);
116
+ this.#assertConnected();
117
+ this.#webSocket.send(p);
95
118
  }
96
119
  finally {
97
120
  unlock();
98
121
  }
99
122
  }
123
+ #rejectRead() {
124
+ if (this.#nextResolve !== null) {
125
+ this.#nextResolve[1].reject(errConnectionNotOpen);
126
+ this.#nextResolve = null;
127
+ }
128
+ }
100
129
  close() {
101
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
102
- __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").close(1000, "method");
103
- __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, undefined, "f");
104
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_rejectRead).call(this);
130
+ this.#assertConnected();
131
+ this.#webSocket.close(1000, "method");
132
+ this.#webSocket = undefined;
133
+ this.#rejectRead();
105
134
  }
106
135
  }
107
136
  exports.ConnectionWebSocket = ConnectionWebSocket;
108
- _ConnectionWebSocket_url = new WeakMap(), _ConnectionWebSocket_webSocket = new WeakMap(), _ConnectionWebSocket_rMutex = new WeakMap(), _ConnectionWebSocket_wMutex = new WeakMap(), _ConnectionWebSocket_buffer = new WeakMap(), _ConnectionWebSocket_nextResolve = new WeakMap(), _ConnectionWebSocket_isConnecting = new WeakMap(), _ConnectionWebSocket_instances = new WeakSet(), _ConnectionWebSocket_initWs = function _ConnectionWebSocket_initWs() {
109
- return new Promise((resolve, reject) => {
110
- const webSocket = new WebSocket(__classPrivateFieldGet(this, _ConnectionWebSocket_url, "f"), "binary");
111
- const mutex = new _1_utilities_js_1.Mutex();
112
- webSocket.addEventListener("close", () => {
113
- __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_rejectRead).call(this);
114
- this.stateChangeHandler?.(false);
115
- });
116
- webSocket.addEventListener("open", () => {
117
- this.stateChangeHandler?.(true);
118
- resolve(webSocket);
119
- L.debug("connected to", __classPrivateFieldGet(this, _ConnectionWebSocket_url, "f"));
120
- });
121
- webSocket.addEventListener("message", async (e) => {
122
- if (typeof e.data === "string") {
123
- return;
124
- }
125
- const unlock = await mutex.lock();
126
- const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _0_deps_js_1.unreachable)())).arrayBuffer());
127
- __classPrivateFieldSet(this, _ConnectionWebSocket_buffer, (0, _0_deps_js_1.concat)([__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f"), data]), "f");
128
- if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") !== null && __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[0]) {
129
- __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].resolve();
130
- __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
131
- }
132
- unlock();
133
- });
134
- webSocket.addEventListener("error", (err) => {
135
- if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
136
- reject("message" in err ? new _0_errors_js_1.ConnectionError(err.message) : new _0_errors_js_1.ConnectionError("Failed to connect."));
137
- }
138
- if (this.isConnected) {
139
- L.error(err);
140
- }
141
- });
142
- });
143
- }, _ConnectionWebSocket_assertConnected = function _ConnectionWebSocket_assertConnected() {
144
- if (!this.isConnected) {
145
- throw errConnectionNotOpen;
146
- }
147
- }, _ConnectionWebSocket_rejectRead = function _ConnectionWebSocket_rejectRead() {
148
- if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") !== null) {
149
- __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].reject(errConnectionNotOpen);
150
- __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
151
- }
152
- };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var Module = (() => {
4
- var _scriptName = globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url;
4
+ var _scriptName = import.meta.url;
5
5
  return (function (moduleArg = {}) {
6
6
  var moduleRtn;
7
7
  var Module = moduleArg;
@@ -119,16 +119,8 @@ var Module = (() => {
119
119
  }
120
120
  } wasmBinaryFile ??= findWasmBinary(); instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject); return {}; }
121
121
  class ExitStatus {
122
- constructor(status) {
123
- Object.defineProperty(this, "name", {
124
- enumerable: true,
125
- configurable: true,
126
- writable: true,
127
- value: "ExitStatus"
128
- });
129
- this.message = `Program terminated with exit(${status})`;
130
- this.status = status;
131
- }
122
+ name = "ExitStatus";
123
+ constructor(status) { this.message = `Program terminated with exit(${status})`; this.status = status; }
132
124
  }
133
125
  var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) {
134
126
  callbacks.shift()(Module);