@mtkruto/node 0.67.2 → 0.68.0
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/esm/0_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1269 -1288
- package/esm/connection/1_connection_tcp.node.js +48 -65
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1269 -1288
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.js +17 -7
- package/script/transport/0_obfuscation.js +17 -7
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
|
@@ -17,97 +17,90 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
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");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
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");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _ConnectionTCP_instances, _ConnectionTCP_hostname, _ConnectionTCP_port, _ConnectionTCP_socket, _ConnectionTCP_rMutex, _ConnectionTCP_wMutex, _ConnectionTCP_buffer, _ConnectionTCP_nextResolve, _ConnectionTCP_rejectRead, _ConnectionTCP_assertConnected;
|
|
32
20
|
import { Socket } from "node:net";
|
|
33
21
|
import { ConnectionError } from "../0_errors.js";
|
|
34
22
|
import { getLogger, Mutex } from "../1_utilities.js";
|
|
35
23
|
const L = getLogger("ConnectionTCP");
|
|
36
24
|
const errConnectionNotOpen = new ConnectionError("Connection not open");
|
|
37
25
|
export class ConnectionTCP {
|
|
26
|
+
#hostname;
|
|
27
|
+
#port;
|
|
28
|
+
#socket;
|
|
29
|
+
#rMutex = new Mutex();
|
|
30
|
+
#wMutex = new Mutex();
|
|
31
|
+
#buffer = new Array();
|
|
32
|
+
#nextResolve = null;
|
|
33
|
+
stateChangeHandler;
|
|
38
34
|
constructor(hostname, port) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Object.defineProperty(this, "stateChangeHandler", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
__classPrivateFieldSet(this, _ConnectionTCP_hostname, hostname, "f");
|
|
54
|
-
__classPrivateFieldSet(this, _ConnectionTCP_port, port, "f");
|
|
35
|
+
this.#hostname = hostname;
|
|
36
|
+
this.#port = port;
|
|
37
|
+
}
|
|
38
|
+
#rejectRead() {
|
|
39
|
+
if (this.#nextResolve != null) {
|
|
40
|
+
this.#nextResolve[1].reject(errConnectionNotOpen);
|
|
41
|
+
this.#nextResolve = null;
|
|
42
|
+
}
|
|
55
43
|
}
|
|
56
44
|
open() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
this.#socket = new Socket();
|
|
46
|
+
this.#socket.on("close", () => {
|
|
47
|
+
this.#rejectRead();
|
|
60
48
|
this.stateChangeHandler?.(false);
|
|
61
49
|
});
|
|
62
50
|
const mutex = new Mutex();
|
|
63
|
-
|
|
51
|
+
this.#socket.on("data", async (data) => {
|
|
64
52
|
const unlock = await mutex.lock();
|
|
65
53
|
for (const byte of data) {
|
|
66
|
-
|
|
54
|
+
this.#buffer.push(byte);
|
|
67
55
|
}
|
|
68
|
-
if (
|
|
69
|
-
const resolve =
|
|
70
|
-
|
|
56
|
+
if (this.#nextResolve != null && this.#buffer.length >= this.#nextResolve[0]) {
|
|
57
|
+
const resolve = this.#nextResolve[1].resolve;
|
|
58
|
+
this.#nextResolve = null;
|
|
71
59
|
resolve();
|
|
72
60
|
}
|
|
73
61
|
unlock();
|
|
74
62
|
});
|
|
75
63
|
return new Promise((resolve, reject) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
this.#socket.connect(this.#port, this.#hostname);
|
|
65
|
+
this.#socket.once("error", reject);
|
|
66
|
+
this.#socket.once("connect", () => {
|
|
67
|
+
this.#socket.off("error", reject);
|
|
80
68
|
resolve();
|
|
81
69
|
this.stateChangeHandler?.(true);
|
|
82
|
-
L.debug("connected to",
|
|
70
|
+
L.debug("connected to", this.#hostname, "port", this.#port);
|
|
83
71
|
});
|
|
84
72
|
});
|
|
85
73
|
}
|
|
86
74
|
get connected() {
|
|
87
|
-
return
|
|
75
|
+
return this.#socket?.readyState == "open";
|
|
76
|
+
}
|
|
77
|
+
#assertConnected() {
|
|
78
|
+
if (!this.connected) {
|
|
79
|
+
throw errConnectionNotOpen;
|
|
80
|
+
}
|
|
88
81
|
}
|
|
89
82
|
async read(p) {
|
|
90
|
-
|
|
91
|
-
const unlock = await
|
|
83
|
+
this.#assertConnected();
|
|
84
|
+
const unlock = await this.#rMutex.lock();
|
|
92
85
|
try {
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
await new Promise((resolve, reject) =>
|
|
86
|
+
this.#assertConnected();
|
|
87
|
+
if (this.#buffer.length < p.length) {
|
|
88
|
+
await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
|
|
96
89
|
}
|
|
97
|
-
p.set(
|
|
90
|
+
p.set(this.#buffer.splice(0, p.length));
|
|
98
91
|
}
|
|
99
92
|
finally {
|
|
100
93
|
unlock();
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
async write(p) {
|
|
104
|
-
|
|
105
|
-
const unlock = await
|
|
97
|
+
this.#assertConnected();
|
|
98
|
+
const unlock = await this.#wMutex.lock();
|
|
106
99
|
try {
|
|
107
|
-
|
|
100
|
+
this.#assertConnected();
|
|
108
101
|
try {
|
|
109
102
|
await new Promise((resolve, reject) => {
|
|
110
|
-
|
|
103
|
+
this.#socket.write(p, (err) => {
|
|
111
104
|
(err === undefined || err == null) ? resolve() : reject(err);
|
|
112
105
|
});
|
|
113
106
|
});
|
|
@@ -126,18 +119,8 @@ export class ConnectionTCP {
|
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
121
|
close() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
this.#assertConnected();
|
|
123
|
+
this.#socket.destroy();
|
|
124
|
+
this.#socket = undefined;
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
|
-
_ConnectionTCP_hostname = new WeakMap(), _ConnectionTCP_port = new WeakMap(), _ConnectionTCP_socket = new WeakMap(), _ConnectionTCP_rMutex = new WeakMap(), _ConnectionTCP_wMutex = new WeakMap(), _ConnectionTCP_buffer = new WeakMap(), _ConnectionTCP_nextResolve = new WeakMap(), _ConnectionTCP_instances = new WeakSet(), _ConnectionTCP_rejectRead = function _ConnectionTCP_rejectRead() {
|
|
135
|
-
if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") != null) {
|
|
136
|
-
__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].reject(errConnectionNotOpen);
|
|
137
|
-
__classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
|
|
138
|
-
}
|
|
139
|
-
}, _ConnectionTCP_assertConnected = function _ConnectionTCP_assertConnected() {
|
|
140
|
-
if (!this.connected) {
|
|
141
|
-
throw errConnectionNotOpen;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
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");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
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");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _ConnectionWebSocket_instances, _ConnectionWebSocket_url, _ConnectionWebSocket_webSocket, _ConnectionWebSocket_rMutex, _ConnectionWebSocket_wMutex, _ConnectionWebSocket_buffer, _ConnectionWebSocket_nextResolve, _ConnectionWebSocket_initWs, _ConnectionWebSocket_isConnecting, _ConnectionWebSocket_assertConnected, _ConnectionWebSocket_rejectRead;
|
|
13
1
|
/**
|
|
14
2
|
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
15
3
|
* Copyright (C) 2023-2025 Roj <https://roj.im/>
|
|
@@ -36,117 +24,113 @@ import { getLogger, Mutex } from "../1_utilities.js";
|
|
|
36
24
|
const L = getLogger("ConnectionWebSocket");
|
|
37
25
|
const errConnectionNotOpen = new ConnectionError("Connection not open");
|
|
38
26
|
export class ConnectionWebSocket {
|
|
27
|
+
#url;
|
|
28
|
+
#webSocket;
|
|
29
|
+
#rMutex = new Mutex();
|
|
30
|
+
#wMutex = new Mutex();
|
|
31
|
+
#buffer = new Uint8Array();
|
|
32
|
+
#nextResolve = null;
|
|
33
|
+
stateChangeHandler;
|
|
39
34
|
constructor(url) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
this.#url = url;
|
|
36
|
+
}
|
|
37
|
+
#initWs() {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const webSocket = new dntShim.WebSocket(this.#url, "binary");
|
|
40
|
+
const mutex = new Mutex();
|
|
41
|
+
webSocket.addEventListener("close", () => {
|
|
42
|
+
this.#rejectRead();
|
|
43
|
+
this.stateChangeHandler?.(false);
|
|
44
|
+
});
|
|
45
|
+
webSocket.addEventListener("open", () => {
|
|
46
|
+
this.stateChangeHandler?.(true);
|
|
47
|
+
resolve(webSocket);
|
|
48
|
+
L.debug("connected to", this.#url);
|
|
49
|
+
});
|
|
50
|
+
webSocket.addEventListener("message", async (e) => {
|
|
51
|
+
if (typeof e.data === "string") {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const unlock = await mutex.lock();
|
|
55
|
+
const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : unreachable())).arrayBuffer());
|
|
56
|
+
this.#buffer = concat([this.#buffer, data]);
|
|
57
|
+
if (this.#nextResolve != null && this.#buffer.length >= this.#nextResolve[0]) {
|
|
58
|
+
this.#nextResolve[1].resolve();
|
|
59
|
+
this.#nextResolve = null;
|
|
60
|
+
}
|
|
61
|
+
unlock();
|
|
62
|
+
});
|
|
63
|
+
webSocket.addEventListener("error", (err) => {
|
|
64
|
+
if (this.#isConnecting) {
|
|
65
|
+
reject("message" in err ? new ConnectionError(err.message) : new ConnectionError("Connection failed"));
|
|
66
|
+
}
|
|
67
|
+
if (this.connected) {
|
|
68
|
+
L.error(err);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
52
71
|
});
|
|
53
|
-
_ConnectionWebSocket_isConnecting.set(this, false);
|
|
54
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_url, url, "f");
|
|
55
72
|
}
|
|
56
73
|
get connected() {
|
|
57
|
-
return !!
|
|
74
|
+
return !!this.#webSocket && this.#webSocket.readyState == dntShim.WebSocket.OPEN;
|
|
58
75
|
}
|
|
76
|
+
#isConnecting = false;
|
|
59
77
|
async open() {
|
|
60
|
-
if (
|
|
78
|
+
if (this.#isConnecting) {
|
|
61
79
|
throw new ConnectionError("Already connecting");
|
|
62
80
|
}
|
|
63
|
-
|
|
81
|
+
this.#isConnecting = true;
|
|
64
82
|
if (this.connected) {
|
|
65
83
|
throw new ConnectionError("Already connected");
|
|
66
84
|
}
|
|
67
85
|
try {
|
|
68
|
-
|
|
86
|
+
this.#webSocket = await this.#initWs();
|
|
69
87
|
}
|
|
70
88
|
finally {
|
|
71
|
-
|
|
89
|
+
this.#isConnecting = false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
#assertConnected() {
|
|
93
|
+
if (!this.connected) {
|
|
94
|
+
throw errConnectionNotOpen;
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
async read(p) {
|
|
75
|
-
|
|
76
|
-
const unlock = await
|
|
98
|
+
this.#assertConnected();
|
|
99
|
+
const unlock = await this.#rMutex.lock();
|
|
77
100
|
try {
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
await new Promise((resolve, reject) =>
|
|
101
|
+
this.#assertConnected();
|
|
102
|
+
if (this.#buffer.length < p.length) {
|
|
103
|
+
await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
|
|
81
104
|
}
|
|
82
|
-
const slice =
|
|
105
|
+
const slice = this.#buffer.slice(0, p.length);
|
|
83
106
|
p.set(slice);
|
|
84
|
-
|
|
107
|
+
this.#buffer = this.#buffer.slice(slice.length);
|
|
85
108
|
}
|
|
86
109
|
finally {
|
|
87
110
|
unlock();
|
|
88
111
|
}
|
|
89
112
|
}
|
|
90
113
|
async write(p) {
|
|
91
|
-
|
|
92
|
-
const unlock = await
|
|
114
|
+
this.#assertConnected();
|
|
115
|
+
const unlock = await this.#wMutex.lock();
|
|
93
116
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
117
|
+
this.#assertConnected();
|
|
118
|
+
this.#webSocket.send(p);
|
|
96
119
|
}
|
|
97
120
|
finally {
|
|
98
121
|
unlock();
|
|
99
122
|
}
|
|
100
123
|
}
|
|
124
|
+
#rejectRead() {
|
|
125
|
+
if (this.#nextResolve != null) {
|
|
126
|
+
this.#nextResolve[1].reject(errConnectionNotOpen);
|
|
127
|
+
this.#nextResolve = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
101
130
|
close() {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
this.#assertConnected();
|
|
132
|
+
this.#webSocket.close(1000, "method");
|
|
133
|
+
this.#webSocket = undefined;
|
|
134
|
+
this.#rejectRead();
|
|
106
135
|
}
|
|
107
136
|
}
|
|
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 dntShim.WebSocket(__classPrivateFieldGet(this, _ConnectionWebSocket_url, "f"), "binary");
|
|
111
|
-
const mutex = new 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 : unreachable())).arrayBuffer());
|
|
127
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_buffer, 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 ConnectionError(err.message) : new ConnectionError("Connection failed"));
|
|
137
|
-
}
|
|
138
|
-
if (this.connected) {
|
|
139
|
-
L.error(err);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}, _ConnectionWebSocket_assertConnected = function _ConnectionWebSocket_assertConnected() {
|
|
144
|
-
if (!this.connected) {
|
|
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,5 +1,5 @@
|
|
|
1
1
|
var Module = (() => {
|
|
2
|
-
var _scriptName = import.meta.url;
|
|
2
|
+
var _scriptName = globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url;
|
|
3
3
|
return (function (moduleArg = {}) {
|
|
4
4
|
var moduleRtn;
|
|
5
5
|
var Module = moduleArg;
|
|
@@ -117,16 +117,8 @@ var Module = (() => {
|
|
|
117
117
|
}
|
|
118
118
|
} wasmBinaryFile ??= findWasmBinary(); instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject); return {}; }
|
|
119
119
|
class ExitStatus {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
enumerable: true,
|
|
123
|
-
configurable: true,
|
|
124
|
-
writable: true,
|
|
125
|
-
value: "ExitStatus"
|
|
126
|
-
});
|
|
127
|
-
this.message = `Program terminated with exit(${status})`;
|
|
128
|
-
this.status = status;
|
|
129
|
-
}
|
|
120
|
+
name = "ExitStatus";
|
|
121
|
+
constructor(status) { this.message = `Program terminated with exit(${status})`; this.status = status; }
|
|
130
122
|
}
|
|
131
123
|
var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) {
|
|
132
124
|
callbacks.shift()(Module);
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
5
|
-
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");
|
|
6
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
9
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
10
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
11
|
-
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");
|
|
12
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
13
|
-
};
|
|
14
|
-
var _MuxAsyncIterator_instances, _MuxAsyncIterator_iteratorCount, _MuxAsyncIterator_yields, _MuxAsyncIterator_throws, _MuxAsyncIterator_signal, _MuxAsyncIterator_callIteratorNext;
|
|
15
3
|
/**
|
|
16
4
|
* Multiplexes multiple async iterators into a single stream. It currently
|
|
17
5
|
* makes an assumption that the final result (the value returned and not
|
|
@@ -47,14 +35,11 @@ var _MuxAsyncIterator_instances, _MuxAsyncIterator_iteratorCount, _MuxAsyncItera
|
|
|
47
35
|
* @typeParam T The type of the provided async iterables and generated async iterable.
|
|
48
36
|
*/
|
|
49
37
|
export class MuxAsyncIterator {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_MuxAsyncIterator_throws.set(this, []);
|
|
56
|
-
_MuxAsyncIterator_signal.set(this, Promise.withResolvers());
|
|
57
|
-
}
|
|
38
|
+
#iteratorCount = 0;
|
|
39
|
+
#yields = [];
|
|
40
|
+
// deno-lint-ignore no-explicit-any
|
|
41
|
+
#throws = [];
|
|
42
|
+
#signal = Promise.withResolvers();
|
|
58
43
|
/**
|
|
59
44
|
* Add an async iterable to the stream.
|
|
60
45
|
*
|
|
@@ -80,9 +65,23 @@ export class MuxAsyncIterator {
|
|
|
80
65
|
* ```
|
|
81
66
|
*/
|
|
82
67
|
add(iterable) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
++this.#iteratorCount;
|
|
69
|
+
this.#callIteratorNext(iterable[Symbol.asyncIterator]());
|
|
70
|
+
}
|
|
71
|
+
async #callIteratorNext(iterator) {
|
|
72
|
+
try {
|
|
73
|
+
const { value, done } = await iterator.next();
|
|
74
|
+
if (done) {
|
|
75
|
+
--this.#iteratorCount;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.#yields.push({ iterator, value });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
this.#throws.push(e);
|
|
83
|
+
}
|
|
84
|
+
this.#signal.resolve();
|
|
86
85
|
}
|
|
87
86
|
/**
|
|
88
87
|
* Returns an async iterator of the stream.
|
|
@@ -108,22 +107,22 @@ export class MuxAsyncIterator {
|
|
|
108
107
|
* ```
|
|
109
108
|
*/
|
|
110
109
|
async *iterate() {
|
|
111
|
-
while (
|
|
110
|
+
while (this.#iteratorCount > 0) {
|
|
112
111
|
// Sleep until any of the wrapped iterators yields.
|
|
113
|
-
await
|
|
112
|
+
await this.#signal.promise;
|
|
114
113
|
// Note that while we're looping over `yields`, new items may be added.
|
|
115
|
-
for (const { iterator, value } of
|
|
114
|
+
for (const { iterator, value } of this.#yields) {
|
|
116
115
|
yield value;
|
|
117
|
-
|
|
116
|
+
this.#callIteratorNext(iterator);
|
|
118
117
|
}
|
|
119
|
-
if (
|
|
120
|
-
for (const e of
|
|
118
|
+
if (this.#throws.length) {
|
|
119
|
+
for (const e of this.#throws) {
|
|
121
120
|
throw e;
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
// Clear the `yields` list and reset the `signal` promise.
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
this.#yields.length = 0;
|
|
125
|
+
this.#signal = Promise.withResolvers();
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
/**
|
|
@@ -149,22 +148,7 @@ export class MuxAsyncIterator {
|
|
|
149
148
|
* assertEquals(result, [1, 2, 3]);
|
|
150
149
|
* ```
|
|
151
150
|
*/
|
|
152
|
-
[(
|
|
153
|
-
var _a;
|
|
154
|
-
try {
|
|
155
|
-
const { value, done } = await iterator.next();
|
|
156
|
-
if (done) {
|
|
157
|
-
__classPrivateFieldSet(this, _MuxAsyncIterator_iteratorCount, (_a = __classPrivateFieldGet(this, _MuxAsyncIterator_iteratorCount, "f"), --_a), "f");
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_yields, "f").push({ iterator, value });
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e) {
|
|
164
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_throws, "f").push(e);
|
|
165
|
-
}
|
|
166
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_signal, "f").resolve();
|
|
167
|
-
}, Symbol.asyncIterator)]() {
|
|
151
|
+
[Symbol.asyncIterator]() {
|
|
168
152
|
return this.iterate();
|
|
169
153
|
}
|
|
170
154
|
}
|
|
@@ -1,57 +1,34 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
6
|
-
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");
|
|
7
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8
|
-
};
|
|
9
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
11
|
-
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");
|
|
12
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
|
-
};
|
|
14
|
-
var _Queue_source, _Queue_queue;
|
|
15
3
|
class Queue {
|
|
4
|
+
#source;
|
|
5
|
+
#queue;
|
|
6
|
+
head;
|
|
7
|
+
done;
|
|
16
8
|
constructor(iterable) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(this, "head", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: void 0
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "done", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: void 0
|
|
30
|
-
});
|
|
31
|
-
__classPrivateFieldSet(this, _Queue_source, iterable[Symbol.asyncIterator](), "f");
|
|
32
|
-
__classPrivateFieldSet(this, _Queue_queue, {
|
|
9
|
+
this.#source = iterable[Symbol.asyncIterator]();
|
|
10
|
+
this.#queue = {
|
|
33
11
|
value: undefined,
|
|
34
12
|
next: undefined,
|
|
35
|
-
}
|
|
36
|
-
this.head =
|
|
13
|
+
};
|
|
14
|
+
this.head = this.#queue;
|
|
37
15
|
this.done = false;
|
|
38
16
|
}
|
|
39
17
|
async next() {
|
|
40
|
-
const result = await
|
|
18
|
+
const result = await this.#source.next();
|
|
41
19
|
if (!result.done) {
|
|
42
20
|
const nextNode = {
|
|
43
21
|
value: result.value,
|
|
44
22
|
next: undefined,
|
|
45
23
|
};
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
this.#queue.next = nextNode;
|
|
25
|
+
this.#queue = nextNode;
|
|
48
26
|
}
|
|
49
27
|
else {
|
|
50
28
|
this.done = true;
|
|
51
29
|
}
|
|
52
30
|
}
|
|
53
31
|
}
|
|
54
|
-
_Queue_source = new WeakMap(), _Queue_queue = new WeakMap();
|
|
55
32
|
/**
|
|
56
33
|
* Branches the given async iterable into the `n` branches.
|
|
57
34
|
*
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
6
|
-
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");
|
|
7
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8
|
-
};
|
|
9
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
11
|
-
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");
|
|
12
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
|
-
};
|
|
14
|
-
var _DateTimeFormatter_formatParts;
|
|
15
3
|
function digits(value, count = 2) {
|
|
16
4
|
return String(value).padStart(count, "0");
|
|
17
5
|
}
|
|
@@ -134,14 +122,14 @@ function sortDateTimeFormatParts(parts) {
|
|
|
134
122
|
return result;
|
|
135
123
|
}
|
|
136
124
|
export class DateTimeFormatter {
|
|
125
|
+
#formatParts;
|
|
137
126
|
constructor(formatString) {
|
|
138
|
-
|
|
139
|
-
__classPrivateFieldSet(this, _DateTimeFormatter_formatParts, formatToFormatParts(formatString), "f");
|
|
127
|
+
this.#formatParts = formatToFormatParts(formatString);
|
|
140
128
|
}
|
|
141
129
|
format(date, options = {}) {
|
|
142
130
|
let string = "";
|
|
143
131
|
const utc = options.timeZone === "UTC";
|
|
144
|
-
for (const part of
|
|
132
|
+
for (const part of this.#formatParts) {
|
|
145
133
|
const type = part.type;
|
|
146
134
|
switch (type) {
|
|
147
135
|
case "year": {
|
|
@@ -274,7 +262,7 @@ export class DateTimeFormatter {
|
|
|
274
262
|
}
|
|
275
263
|
formatToParts(string) {
|
|
276
264
|
const parts = [];
|
|
277
|
-
for (const part of
|
|
265
|
+
for (const part of this.#formatParts) {
|
|
278
266
|
const type = part.type;
|
|
279
267
|
let length = 0;
|
|
280
268
|
let value = "";
|
|
@@ -547,4 +535,3 @@ export class DateTimeFormatter {
|
|
|
547
535
|
return this.partsToDate(parts);
|
|
548
536
|
}
|
|
549
537
|
}
|
|
550
|
-
_DateTimeFormatter_formatParts = new WeakMap();
|