@mtkruto/browser 0.119.0 → 0.120.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/README.md +1 -1
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- 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 +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- 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 +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- 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 +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- 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_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- 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.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- 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/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- 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 +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- 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 +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- 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 +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- 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_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- 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/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
6
|
-
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");
|
|
7
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
8
|
-
};
|
|
9
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
10
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
12
|
-
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");
|
|
13
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
14
|
-
};
|
|
15
|
-
var _MuxAsyncIterator_instances, _MuxAsyncIterator_iteratorCount, _MuxAsyncIterator_yields, _MuxAsyncIterator_throws, _MuxAsyncIterator_signal, _MuxAsyncIterator_callIteratorNext;
|
|
16
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
5
|
exports.MuxAsyncIterator = void 0;
|
|
18
6
|
/**
|
|
@@ -50,14 +38,11 @@ exports.MuxAsyncIterator = void 0;
|
|
|
50
38
|
* @typeParam T The type of the provided async iterables and generated async iterable.
|
|
51
39
|
*/
|
|
52
40
|
class MuxAsyncIterator {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
_MuxAsyncIterator_throws.set(this, []);
|
|
59
|
-
_MuxAsyncIterator_signal.set(this, Promise.withResolvers());
|
|
60
|
-
}
|
|
41
|
+
#iteratorCount = 0;
|
|
42
|
+
#yields = [];
|
|
43
|
+
// deno-lint-ignore no-explicit-any
|
|
44
|
+
#throws = [];
|
|
45
|
+
#signal = Promise.withResolvers();
|
|
61
46
|
/**
|
|
62
47
|
* Add an async iterable to the stream.
|
|
63
48
|
*
|
|
@@ -83,9 +68,23 @@ class MuxAsyncIterator {
|
|
|
83
68
|
* ```
|
|
84
69
|
*/
|
|
85
70
|
add(iterable) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
++this.#iteratorCount;
|
|
72
|
+
this.#callIteratorNext(iterable[Symbol.asyncIterator]());
|
|
73
|
+
}
|
|
74
|
+
async #callIteratorNext(iterator) {
|
|
75
|
+
try {
|
|
76
|
+
const { value, done } = await iterator.next();
|
|
77
|
+
if (done) {
|
|
78
|
+
--this.#iteratorCount;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.#yields.push({ iterator, value });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
this.#throws.push(e);
|
|
86
|
+
}
|
|
87
|
+
this.#signal.resolve();
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
90
|
* Returns an async iterator of the stream.
|
|
@@ -111,22 +110,22 @@ class MuxAsyncIterator {
|
|
|
111
110
|
* ```
|
|
112
111
|
*/
|
|
113
112
|
async *iterate() {
|
|
114
|
-
while (
|
|
113
|
+
while (this.#iteratorCount > 0) {
|
|
115
114
|
// Sleep until any of the wrapped iterators yields.
|
|
116
|
-
await
|
|
115
|
+
await this.#signal.promise;
|
|
117
116
|
// Note that while we're looping over `yields`, new items may be added.
|
|
118
|
-
for (const { iterator, value } of
|
|
117
|
+
for (const { iterator, value } of this.#yields) {
|
|
119
118
|
yield value;
|
|
120
|
-
|
|
119
|
+
this.#callIteratorNext(iterator);
|
|
121
120
|
}
|
|
122
|
-
if (
|
|
123
|
-
for (const e of
|
|
121
|
+
if (this.#throws.length) {
|
|
122
|
+
for (const e of this.#throws) {
|
|
124
123
|
throw e;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
// Clear the `yields` list and reset the `signal` promise.
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
this.#yields.length = 0;
|
|
128
|
+
this.#signal = Promise.withResolvers();
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
/**
|
|
@@ -152,22 +151,7 @@ class MuxAsyncIterator {
|
|
|
152
151
|
* assertEquals(result, [1, 2, 3]);
|
|
153
152
|
* ```
|
|
154
153
|
*/
|
|
155
|
-
[(
|
|
156
|
-
var _a;
|
|
157
|
-
try {
|
|
158
|
-
const { value, done } = await iterator.next();
|
|
159
|
-
if (done) {
|
|
160
|
-
__classPrivateFieldSet(this, _MuxAsyncIterator_iteratorCount, (_a = __classPrivateFieldGet(this, _MuxAsyncIterator_iteratorCount, "f"), --_a), "f");
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_yields, "f").push({ iterator, value });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_throws, "f").push(e);
|
|
168
|
-
}
|
|
169
|
-
__classPrivateFieldGet(this, _MuxAsyncIterator_signal, "f").resolve();
|
|
170
|
-
}, Symbol.asyncIterator)]() {
|
|
154
|
+
[Symbol.asyncIterator]() {
|
|
171
155
|
return this.iterate();
|
|
172
156
|
}
|
|
173
157
|
}
|
|
@@ -1,60 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
-
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");
|
|
8
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
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");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _Queue_source, _Queue_queue;
|
|
16
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
5
|
exports.tee = tee;
|
|
18
6
|
class Queue {
|
|
7
|
+
#source;
|
|
8
|
+
#queue;
|
|
9
|
+
head;
|
|
10
|
+
done;
|
|
19
11
|
constructor(iterable) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(this, "head", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: void 0
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(this, "done", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: void 0
|
|
33
|
-
});
|
|
34
|
-
__classPrivateFieldSet(this, _Queue_source, iterable[Symbol.asyncIterator](), "f");
|
|
35
|
-
__classPrivateFieldSet(this, _Queue_queue, {
|
|
12
|
+
this.#source = iterable[Symbol.asyncIterator]();
|
|
13
|
+
this.#queue = {
|
|
36
14
|
value: undefined,
|
|
37
15
|
next: undefined,
|
|
38
|
-
}
|
|
39
|
-
this.head =
|
|
16
|
+
};
|
|
17
|
+
this.head = this.#queue;
|
|
40
18
|
this.done = false;
|
|
41
19
|
}
|
|
42
20
|
async next() {
|
|
43
|
-
const result = await
|
|
21
|
+
const result = await this.#source.next();
|
|
44
22
|
if (!result.done) {
|
|
45
23
|
const nextNode = {
|
|
46
24
|
value: result.value,
|
|
47
25
|
next: undefined,
|
|
48
26
|
};
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
this.#queue.next = nextNode;
|
|
28
|
+
this.#queue = nextNode;
|
|
51
29
|
}
|
|
52
30
|
else {
|
|
53
31
|
this.done = true;
|
|
54
32
|
}
|
|
55
33
|
}
|
|
56
34
|
}
|
|
57
|
-
_Queue_source = new WeakMap(), _Queue_queue = new WeakMap();
|
|
58
35
|
/**
|
|
59
36
|
* Branches the given async iterable into the `n` branches.
|
|
60
37
|
*
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
-
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");
|
|
8
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
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");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _LruCache_instances, _LruCache_eject, _LruCache_setMostRecentlyUsed, _LruCache_pruneToMaxSize;
|
|
16
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
5
|
exports.LruCache = void 0;
|
|
18
6
|
/**
|
|
@@ -70,6 +58,20 @@ exports.LruCache = void 0;
|
|
|
70
58
|
* ```
|
|
71
59
|
*/
|
|
72
60
|
class LruCache extends Map {
|
|
61
|
+
/**
|
|
62
|
+
* The maximum number of entries to store in the cache.
|
|
63
|
+
*
|
|
64
|
+
* @example Max size
|
|
65
|
+
* ```ts no-assert
|
|
66
|
+
* import { LruCache } from "@std/cache";
|
|
67
|
+
* import { assertEquals } from "@std/assert";
|
|
68
|
+
*
|
|
69
|
+
* const cache = new LruCache<string, number>(100);
|
|
70
|
+
* assertEquals(cache.maxSize, 100);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
maxSize;
|
|
74
|
+
#eject;
|
|
73
75
|
/**
|
|
74
76
|
* Constructs a new `LruCache`.
|
|
75
77
|
*
|
|
@@ -78,28 +80,18 @@ class LruCache extends Map {
|
|
|
78
80
|
*/
|
|
79
81
|
constructor(maxSize, options) {
|
|
80
82
|
super();
|
|
81
|
-
_LruCache_instances.add(this);
|
|
82
|
-
/**
|
|
83
|
-
* The maximum number of entries to store in the cache.
|
|
84
|
-
*
|
|
85
|
-
* @example Max size
|
|
86
|
-
* ```ts no-assert
|
|
87
|
-
* import { LruCache } from "@std/cache";
|
|
88
|
-
* import { assertEquals } from "@std/assert";
|
|
89
|
-
*
|
|
90
|
-
* const cache = new LruCache<string, number>(100);
|
|
91
|
-
* assertEquals(cache.maxSize, 100);
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
Object.defineProperty(this, "maxSize", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
_LruCache_eject.set(this, void 0);
|
|
101
83
|
this.maxSize = maxSize;
|
|
102
|
-
|
|
84
|
+
this.#eject = options?.onEject ?? (() => { });
|
|
85
|
+
}
|
|
86
|
+
#setMostRecentlyUsed(key, value) {
|
|
87
|
+
// delete then re-add to ensure most recently accessed elements are last
|
|
88
|
+
super.delete(key);
|
|
89
|
+
super.set(key, value);
|
|
90
|
+
}
|
|
91
|
+
#pruneToMaxSize() {
|
|
92
|
+
if (this.size > this.maxSize) {
|
|
93
|
+
this.delete(this.keys().next().value);
|
|
94
|
+
}
|
|
103
95
|
}
|
|
104
96
|
/**
|
|
105
97
|
* Checks whether an element with the specified key exists or not.
|
|
@@ -121,7 +113,7 @@ class LruCache extends Map {
|
|
|
121
113
|
has(key) {
|
|
122
114
|
const exists = super.has(key);
|
|
123
115
|
if (exists) {
|
|
124
|
-
|
|
116
|
+
this.#setMostRecentlyUsed(key, super.get(key));
|
|
125
117
|
}
|
|
126
118
|
return exists;
|
|
127
119
|
}
|
|
@@ -145,7 +137,7 @@ class LruCache extends Map {
|
|
|
145
137
|
get(key) {
|
|
146
138
|
if (super.has(key)) {
|
|
147
139
|
const value = super.get(key);
|
|
148
|
-
|
|
140
|
+
this.#setMostRecentlyUsed(key, value);
|
|
149
141
|
return value;
|
|
150
142
|
}
|
|
151
143
|
return undefined;
|
|
@@ -166,8 +158,8 @@ class LruCache extends Map {
|
|
|
166
158
|
* ```
|
|
167
159
|
*/
|
|
168
160
|
set(key, value) {
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
this.#setMostRecentlyUsed(key, value);
|
|
162
|
+
this.#pruneToMaxSize();
|
|
171
163
|
return this;
|
|
172
164
|
}
|
|
173
165
|
/**
|
|
@@ -192,18 +184,9 @@ class LruCache extends Map {
|
|
|
192
184
|
*/
|
|
193
185
|
delete(key) {
|
|
194
186
|
if (super.has(key)) {
|
|
195
|
-
|
|
187
|
+
this.#eject(key, super.get(key));
|
|
196
188
|
}
|
|
197
189
|
return super.delete(key);
|
|
198
190
|
}
|
|
199
191
|
}
|
|
200
192
|
exports.LruCache = LruCache;
|
|
201
|
-
_LruCache_eject = new WeakMap(), _LruCache_instances = new WeakSet(), _LruCache_setMostRecentlyUsed = function _LruCache_setMostRecentlyUsed(key, value) {
|
|
202
|
-
// delete then re-add to ensure most recently accessed elements are last
|
|
203
|
-
super.delete(key);
|
|
204
|
-
super.set(key, value);
|
|
205
|
-
}, _LruCache_pruneToMaxSize = function _LruCache_pruneToMaxSize() {
|
|
206
|
-
if (this.size > this.maxSize) {
|
|
207
|
-
this.delete(this.keys().next().value);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
-
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");
|
|
8
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
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");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _DateTimeFormatter_formatParts;
|
|
16
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
5
|
exports.DateTimeFormatter = void 0;
|
|
18
6
|
function digits(value, count = 2) {
|
|
@@ -137,14 +125,14 @@ function sortDateTimeFormatParts(parts) {
|
|
|
137
125
|
return result;
|
|
138
126
|
}
|
|
139
127
|
class DateTimeFormatter {
|
|
128
|
+
#formatParts;
|
|
140
129
|
constructor(formatString) {
|
|
141
|
-
|
|
142
|
-
__classPrivateFieldSet(this, _DateTimeFormatter_formatParts, formatToFormatParts(formatString), "f");
|
|
130
|
+
this.#formatParts = formatToFormatParts(formatString);
|
|
143
131
|
}
|
|
144
132
|
format(date, options = {}) {
|
|
145
133
|
let string = "";
|
|
146
134
|
const utc = options.timeZone === "UTC";
|
|
147
|
-
for (const part of
|
|
135
|
+
for (const part of this.#formatParts) {
|
|
148
136
|
const type = part.type;
|
|
149
137
|
switch (type) {
|
|
150
138
|
case "year": {
|
|
@@ -277,7 +265,7 @@ class DateTimeFormatter {
|
|
|
277
265
|
}
|
|
278
266
|
formatToParts(string) {
|
|
279
267
|
const parts = [];
|
|
280
|
-
for (const part of
|
|
268
|
+
for (const part of this.#formatParts) {
|
|
281
269
|
const type = part.type;
|
|
282
270
|
let length = 0;
|
|
283
271
|
let value = "";
|
|
@@ -551,4 +539,3 @@ class DateTimeFormatter {
|
|
|
551
539
|
}
|
|
552
540
|
}
|
|
553
541
|
exports.DateTimeFormatter = DateTimeFormatter;
|
|
554
|
-
_DateTimeFormatter_formatParts = new WeakMap();
|
|
@@ -18,64 +18,38 @@
|
|
|
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
23
|
-
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");
|
|
24
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
27
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
-
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");
|
|
30
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
31
|
-
};
|
|
32
|
-
var _SessionState_seqNo, _SessionState_messageId;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.SessionState = void 0;
|
|
35
23
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
36
24
|
class SessionState {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
writable: true,
|
|
42
|
-
value: 0
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(this, "serverSalt", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: 0n
|
|
49
|
-
});
|
|
50
|
-
_SessionState_seqNo.set(this, 0);
|
|
51
|
-
_SessionState_messageId.set(this, 0n);
|
|
52
|
-
}
|
|
25
|
+
timeDifference = 0;
|
|
26
|
+
serverSalt = 0n;
|
|
27
|
+
#seqNo = 0;
|
|
28
|
+
#messageId = 0n;
|
|
53
29
|
nextMessageId() {
|
|
54
30
|
const now = (0, _1_utilities_js_1.toUnixTimestamp)(new Date()) + this.timeDifference;
|
|
55
31
|
const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
|
|
56
32
|
const newMessageId = (BigInt(Math.floor(now)) << 32n) || (BigInt(nanoseconds) << 2n);
|
|
57
|
-
if (
|
|
58
|
-
|
|
33
|
+
if (this.#messageId >= newMessageId) {
|
|
34
|
+
this.#messageId += 4n;
|
|
59
35
|
}
|
|
60
36
|
else {
|
|
61
|
-
|
|
37
|
+
this.#messageId = newMessageId;
|
|
62
38
|
}
|
|
63
|
-
return
|
|
39
|
+
return this.#messageId;
|
|
64
40
|
}
|
|
65
41
|
nextSeqNo(contentRelated) {
|
|
66
|
-
|
|
67
|
-
let seqNo = __classPrivateFieldGet(this, _SessionState_seqNo, "f") * 2;
|
|
42
|
+
let seqNo = this.#seqNo * 2;
|
|
68
43
|
if (contentRelated) {
|
|
69
44
|
seqNo++;
|
|
70
|
-
|
|
45
|
+
this.#seqNo++;
|
|
71
46
|
}
|
|
72
47
|
return seqNo;
|
|
73
48
|
}
|
|
74
49
|
reset() {
|
|
75
50
|
this.serverSalt = 0n;
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
this.#seqNo = 0;
|
|
52
|
+
this.#messageId = 0n;
|
|
78
53
|
}
|
|
79
54
|
}
|
|
80
55
|
exports.SessionState = SessionState;
|
|
81
|
-
_SessionState_seqNo = new WeakMap(), _SessionState_messageId = 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 _Session_instances, _Session_dc, _Session_isCdn, _Session_lastConnect, _Session_isDisconnected, _Session_L, _Session_onConnectionStateChange, _Session_lastState, _Session_stateChangeHandler, _Session_connectMutex;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.Session = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -41,50 +29,37 @@ let id = 0;
|
|
|
41
29
|
// @ts-ignore: lib
|
|
42
30
|
const defaultTransportProvider = typeof Deno === "undefined" ? _3_transport_js_1.transportProviderWebSocket : _3_transport_js_1.transportProviderTcp;
|
|
43
31
|
class Session {
|
|
32
|
+
#dc;
|
|
33
|
+
#isCdn;
|
|
34
|
+
state = new _0_session_state_js_1.SessionState();
|
|
35
|
+
transport;
|
|
36
|
+
#lastConnect;
|
|
37
|
+
#isDisconnected = true;
|
|
38
|
+
#L;
|
|
39
|
+
#onConnectionStateChange;
|
|
44
40
|
constructor(dc, params) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
_Session_isCdn.set(this, void 0);
|
|
48
|
-
Object.defineProperty(this, "state", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: new _0_session_state_js_1.SessionState()
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "transport", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
_Session_lastConnect.set(this, void 0);
|
|
61
|
-
_Session_isDisconnected.set(this, true);
|
|
62
|
-
_Session_L.set(this, void 0);
|
|
63
|
-
_Session_onConnectionStateChange.set(this, void 0);
|
|
64
|
-
_Session_lastState.set(this, void 0);
|
|
65
|
-
_Session_connectMutex.set(this, new _1_utilities_js_1.Mutex());
|
|
66
|
-
__classPrivateFieldSet(this, _Session_dc, dc, "f");
|
|
67
|
-
__classPrivateFieldSet(this, _Session_isCdn, params?.isCdn ?? false, "f");
|
|
41
|
+
this.#dc = dc;
|
|
42
|
+
this.#isCdn = params?.isCdn ?? false;
|
|
68
43
|
const transportProvider = params?.transportProvider ?? defaultTransportProvider();
|
|
69
|
-
this.transport = transportProvider({ dc:
|
|
44
|
+
this.transport = transportProvider({ dc: this.#dc, isCdn: this.#isCdn });
|
|
70
45
|
this.transport.connection.stateChangeHandler = (connected) => {
|
|
71
46
|
setTimeout(() => {
|
|
72
|
-
(0, _1_utilities_js_1.drop)(
|
|
47
|
+
(0, _1_utilities_js_1.drop)(this.#stateChangeHandler(connected));
|
|
73
48
|
});
|
|
74
49
|
};
|
|
75
|
-
|
|
50
|
+
this.#L = (0, _1_utilities_js_1.getLogger)("Session").client(id++);
|
|
76
51
|
}
|
|
77
52
|
set onConnectionStateChange(onConnectionStateChange) {
|
|
78
|
-
|
|
53
|
+
this.#onConnectionStateChange = onConnectionStateChange;
|
|
79
54
|
}
|
|
80
55
|
set connectionCallback(connectionCallback) {
|
|
81
56
|
this.transport.connection.callback = connectionCallback;
|
|
82
57
|
}
|
|
83
58
|
get dc() {
|
|
84
|
-
return
|
|
59
|
+
return this.#dc;
|
|
85
60
|
}
|
|
86
61
|
get isCdn() {
|
|
87
|
-
return
|
|
62
|
+
return this.#isCdn;
|
|
88
63
|
}
|
|
89
64
|
set serverSalt(serverSalt) {
|
|
90
65
|
this.state.serverSalt = serverSalt;
|
|
@@ -92,60 +67,62 @@ class Session {
|
|
|
92
67
|
get serverSalt() {
|
|
93
68
|
return this.state.serverSalt;
|
|
94
69
|
}
|
|
70
|
+
#lastState;
|
|
71
|
+
async #stateChangeHandler(isConnected) {
|
|
72
|
+
if (this.#lastState !== isConnected) {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
this.#onConnectionStateChange?.(isConnected);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (this.#lastState === isConnected) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.#lastState = isConnected;
|
|
81
|
+
if (isConnected || this.#isDisconnected) {
|
|
82
|
+
if (this.#isDisconnected) {
|
|
83
|
+
this.#L.debug("not reconnecting because explicitly disconnected");
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (this.#lastConnect && Date.now() - this.#lastConnect.getTime() <= 10 * _0_deps_js_1.SECOND) {
|
|
88
|
+
this.#L.debug("reconnecting after a delay");
|
|
89
|
+
await (0, _0_deps_js_1.delay)(3 * _0_deps_js_1.SECOND);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.#L.debug("reconnecting");
|
|
93
|
+
}
|
|
94
|
+
await this.connect();
|
|
95
|
+
}
|
|
95
96
|
get isConnected() {
|
|
96
97
|
return this.transport.connection.isConnected;
|
|
97
98
|
}
|
|
99
|
+
#connectMutex = new _1_utilities_js_1.Mutex();
|
|
98
100
|
async connect() {
|
|
99
|
-
const unlock = await
|
|
101
|
+
const unlock = await this.#connectMutex.lock();
|
|
100
102
|
try {
|
|
101
103
|
if (this.isConnected) {
|
|
102
104
|
return;
|
|
103
105
|
}
|
|
104
106
|
await this.transport.connection.open();
|
|
105
107
|
await this.transport.transport.initialize();
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
this.#lastConnect = new Date();
|
|
109
|
+
this.#isDisconnected = false;
|
|
108
110
|
}
|
|
109
111
|
finally {
|
|
110
112
|
unlock();
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
async waitUntilConnected() {
|
|
114
|
-
(await
|
|
116
|
+
(await this.#connectMutex.lock())();
|
|
115
117
|
}
|
|
116
118
|
get isDisconnected() {
|
|
117
|
-
return
|
|
119
|
+
return this.#isDisconnected;
|
|
118
120
|
}
|
|
119
121
|
disconnect() {
|
|
120
|
-
|
|
122
|
+
this.#isDisconnected = true;
|
|
121
123
|
if (this.transport.connection.isConnected) {
|
|
122
124
|
this.transport.connection.close();
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
exports.Session = Session;
|
|
127
|
-
_Session_dc = new WeakMap(), _Session_isCdn = new WeakMap(), _Session_lastConnect = new WeakMap(), _Session_isDisconnected = new WeakMap(), _Session_L = new WeakMap(), _Session_onConnectionStateChange = new WeakMap(), _Session_lastState = new WeakMap(), _Session_connectMutex = new WeakMap(), _Session_instances = new WeakSet(), _Session_stateChangeHandler = async function _Session_stateChangeHandler(isConnected) {
|
|
128
|
-
if (__classPrivateFieldGet(this, _Session_lastState, "f") !== isConnected) {
|
|
129
|
-
setTimeout(() => {
|
|
130
|
-
__classPrivateFieldGet(this, _Session_onConnectionStateChange, "f")?.call(this, isConnected);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (__classPrivateFieldGet(this, _Session_lastState, "f") === isConnected) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
__classPrivateFieldSet(this, _Session_lastState, isConnected, "f");
|
|
137
|
-
if (isConnected || __classPrivateFieldGet(this, _Session_isDisconnected, "f")) {
|
|
138
|
-
if (__classPrivateFieldGet(this, _Session_isDisconnected, "f")) {
|
|
139
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("not reconnecting because explicitly disconnected");
|
|
140
|
-
}
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (__classPrivateFieldGet(this, _Session_lastConnect, "f") && Date.now() - __classPrivateFieldGet(this, _Session_lastConnect, "f").getTime() <= 10 * _0_deps_js_1.SECOND) {
|
|
144
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("reconnecting after a delay");
|
|
145
|
-
await (0, _0_deps_js_1.delay)(3 * _0_deps_js_1.SECOND);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("reconnecting");
|
|
149
|
-
}
|
|
150
|
-
await this.connect();
|
|
151
|
-
};
|