@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
|
@@ -15,25 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
var _CTR_instances, _CTR_key, _CTR_iv, _CTR_bytesUntilNextBlock, _CTR_promise, _CTR_call, _CTR_encrypt, _CTR_increaseIv;
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
37
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
36
|
exports.CTR = void 0;
|
|
39
37
|
/**
|
|
@@ -60,60 +58,61 @@ const _0_deps_js_1 = require("../0_deps.js");
|
|
|
60
58
|
const _0_bigint_js_1 = require("./0_bigint.js");
|
|
61
59
|
const _0_buffer_js_1 = require("./0_buffer.js");
|
|
62
60
|
class CTR {
|
|
61
|
+
#key;
|
|
62
|
+
#iv;
|
|
63
|
+
#bytesUntilNextBlock = 0;
|
|
64
|
+
#promise;
|
|
63
65
|
get _state() {
|
|
64
|
-
return { iv: new Uint8Array(
|
|
66
|
+
return { iv: new Uint8Array(this.#iv), state: this.#bytesUntilNextBlock };
|
|
65
67
|
}
|
|
66
68
|
constructor(key, iv) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_CTR_iv.set(this, void 0);
|
|
70
|
-
_CTR_bytesUntilNextBlock.set(this, 0);
|
|
71
|
-
_CTR_promise.set(this, void 0);
|
|
72
|
-
__classPrivateFieldSet(this, _CTR_key, key, "f");
|
|
73
|
-
__classPrivateFieldSet(this, _CTR_iv, iv, "f");
|
|
69
|
+
this.#key = key;
|
|
70
|
+
this.#iv = iv;
|
|
74
71
|
}
|
|
75
72
|
static async importKey(key) {
|
|
76
73
|
return await dntShim.crypto.subtle.importKey("raw", key, "AES-CTR", false, ["encrypt"]);
|
|
77
74
|
}
|
|
78
75
|
async call(data) {
|
|
79
|
-
if (
|
|
80
|
-
await Promise.allSettled([
|
|
76
|
+
if (this.#promise) {
|
|
77
|
+
await Promise.allSettled([this.#promise]);
|
|
81
78
|
}
|
|
82
|
-
return await (
|
|
79
|
+
return await (this.#promise = this.#call(data));
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
async #call(data) {
|
|
82
|
+
let header;
|
|
83
|
+
if (this.#bytesUntilNextBlock) {
|
|
84
|
+
const headerLength = Math.min(data.length, this.#iv.length - this.#bytesUntilNextBlock);
|
|
85
|
+
const encrypted = await this.#encrypt((0, _0_deps_js_1.concat)([new Uint8Array(this.#bytesUntilNextBlock), data.subarray(0, headerLength)]));
|
|
86
|
+
header = encrypted.subarray(this.#bytesUntilNextBlock);
|
|
87
|
+
data = data.subarray(headerLength);
|
|
88
|
+
if (encrypted.length === this.#iv.length) {
|
|
89
|
+
this.#increaseIv(1);
|
|
90
|
+
this.#bytesUntilNextBlock = 0;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.#bytesUntilNextBlock += headerLength;
|
|
94
|
+
}
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
if (!data.length && header) {
|
|
97
|
+
return header;
|
|
99
98
|
}
|
|
99
|
+
const encrypted = await this.#encrypt(data);
|
|
100
|
+
this.#bytesUntilNextBlock = encrypted.length % this.#iv.length;
|
|
101
|
+
this.#increaseIv((encrypted.length - this.#bytesUntilNextBlock) / this.#iv.length);
|
|
102
|
+
return header ? (0, _0_deps_js_1.concat)([header, encrypted]) : encrypted;
|
|
100
103
|
}
|
|
101
|
-
|
|
102
|
-
return
|
|
104
|
+
async #encrypt(data) {
|
|
105
|
+
return new Uint8Array(await dntShim.crypto.subtle.encrypt({
|
|
106
|
+
name: "AES-CTR",
|
|
107
|
+
counter: new Uint8Array(this.#iv),
|
|
108
|
+
length: this.#iv.length * 8,
|
|
109
|
+
}, this.#key, data));
|
|
103
110
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return new Uint8Array(await dntShim.crypto.subtle.encrypt({
|
|
110
|
-
name: "AES-CTR",
|
|
111
|
-
counter: new Uint8Array(__classPrivateFieldGet(this, _CTR_iv, "f")),
|
|
112
|
-
length: __classPrivateFieldGet(this, _CTR_iv, "f").length * 8,
|
|
113
|
-
}, __classPrivateFieldGet(this, _CTR_key, "f"), data));
|
|
114
|
-
}, _CTR_increaseIv = function _CTR_increaseIv(amount) {
|
|
115
|
-
if (amount < 1) {
|
|
116
|
-
return;
|
|
111
|
+
#increaseIv(amount) {
|
|
112
|
+
if (amount < 1) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.#iv = (0, _0_buffer_js_1.bufferFromBigInt)((0, _0_bigint_js_1.bigIntFromBuffer)(this.#iv, false, false) + BigInt(amount), this.#iv.length, false, false);
|
|
117
116
|
}
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
}
|
|
118
|
+
exports.CTR = CTR;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_crypto_test.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto_test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"1_crypto_test.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,2BAA2B,CAAC"}
|
|
@@ -37,8 +37,8 @@ export declare const OUT = 10;
|
|
|
37
37
|
export declare const IN_BIN = 20;
|
|
38
38
|
export declare const OUT_BIN = 20;
|
|
39
39
|
export declare function getLogger(scope: string): {
|
|
40
|
-
client(id: number): any;
|
|
41
|
-
branch(name: string): any;
|
|
40
|
+
client(id: number): /*elided*/ any;
|
|
41
|
+
branch(name: string): /*elided*/ any;
|
|
42
42
|
error(...args: any[]): void;
|
|
43
43
|
warning(...args: any[]): void;
|
|
44
44
|
info(...args: any[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_math_test.d.ts","sourceRoot":"","sources":["../../src/utilities/1_math_test.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"1_math_test.d.ts","sourceRoot":"","sources":["../../src/utilities/1_math_test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,2BAA2B,CAAC"}
|
|
@@ -18,63 +18,45 @@
|
|
|
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 _Queue_instances, _Queue_logger, _Queue_throw, _Queue_busy, _Queue_check;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.Queue = void 0;
|
|
35
23
|
const _1_logger_js_1 = require("./1_logger.js");
|
|
36
24
|
class Queue {
|
|
25
|
+
#logger;
|
|
26
|
+
functions = new Array();
|
|
27
|
+
#throw;
|
|
37
28
|
constructor(name, throw_ = false) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Object.defineProperty(this, "functions", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: new Array()
|
|
45
|
-
});
|
|
46
|
-
_Queue_throw.set(this, void 0);
|
|
47
|
-
_Queue_busy.set(this, false);
|
|
48
|
-
__classPrivateFieldSet(this, _Queue_logger, (0, _1_logger_js_1.getLogger)(`q/${name}`), "f");
|
|
49
|
-
__classPrivateFieldSet(this, _Queue_throw, throw_, "f");
|
|
29
|
+
this.#logger = (0, _1_logger_js_1.getLogger)(`q/${name}`);
|
|
30
|
+
this.#throw = throw_;
|
|
50
31
|
}
|
|
51
32
|
add(fn) {
|
|
52
33
|
this.functions.push(fn);
|
|
53
|
-
|
|
34
|
+
this.#check();
|
|
54
35
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
__classPrivateFieldGet(this, _Queue_instances, "m", _Queue_check).call(this);
|
|
70
|
-
});
|
|
71
|
-
if (!__classPrivateFieldGet(this, _Queue_throw, "f")) {
|
|
72
|
-
promise.catch((err) => {
|
|
73
|
-
__classPrivateFieldGet(this, _Queue_logger, "f").error((typeof err === "object" && err != null && "stack" in err) ? err.stack : err);
|
|
36
|
+
#busy = false;
|
|
37
|
+
#check() {
|
|
38
|
+
if (this.#busy) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.#busy = true;
|
|
43
|
+
}
|
|
44
|
+
const fn = this.functions.shift();
|
|
45
|
+
if (fn !== undefined) {
|
|
46
|
+
const promise = fn()
|
|
47
|
+
.finally(() => {
|
|
48
|
+
this.#busy = false;
|
|
49
|
+
this.#check();
|
|
74
50
|
});
|
|
51
|
+
if (!this.#throw) {
|
|
52
|
+
promise.catch((err) => {
|
|
53
|
+
this.#logger.error((typeof err === "object" && err != null && "stack" in err) ? err.stack : err);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.#busy = false;
|
|
75
59
|
}
|
|
76
60
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
};
|
|
61
|
+
}
|
|
62
|
+
exports.Queue = Queue;
|