@mtcute/core 0.1.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/LICENSE +8 -0
- package/README.md +26 -0
- package/cjs/base-client.d.ts +297 -0
- package/cjs/base-client.js +324 -0
- package/cjs/base-client.js.map +1 -0
- package/cjs/index.d.ts +10 -0
- package/cjs/index.js +30 -0
- package/cjs/index.js.map +1 -0
- package/cjs/network/auth-key.d.ts +21 -0
- package/cjs/network/auth-key.js +101 -0
- package/cjs/network/auth-key.js.map +1 -0
- package/cjs/network/authorization.d.ts +9 -0
- package/cjs/network/authorization.js +332 -0
- package/cjs/network/authorization.js.map +1 -0
- package/cjs/network/config-manager.d.ts +33 -0
- package/cjs/network/config-manager.js +93 -0
- package/cjs/network/config-manager.js.map +1 -0
- package/cjs/network/index.d.ts +4 -0
- package/cjs/network/index.js +20 -0
- package/cjs/network/index.js.map +1 -0
- package/cjs/network/mtproto-session.d.ts +116 -0
- package/cjs/network/mtproto-session.js +209 -0
- package/cjs/network/mtproto-session.js.map +1 -0
- package/cjs/network/multi-session-connection.d.ts +33 -0
- package/cjs/network/multi-session-connection.js +243 -0
- package/cjs/network/multi-session-connection.js.map +1 -0
- package/cjs/network/network-manager.d.ts +190 -0
- package/cjs/network/network-manager.js +547 -0
- package/cjs/network/network-manager.js.map +1 -0
- package/cjs/network/persistent-connection.d.ts +51 -0
- package/cjs/network/persistent-connection.js +173 -0
- package/cjs/network/persistent-connection.js.map +1 -0
- package/cjs/network/reconnection.d.ts +11 -0
- package/cjs/network/reconnection.js +18 -0
- package/cjs/network/reconnection.js.map +1 -0
- package/cjs/network/session-connection.d.ts +72 -0
- package/cjs/network/session-connection.js +1363 -0
- package/cjs/network/session-connection.js.map +1 -0
- package/cjs/network/transports/abstract.d.ts +99 -0
- package/cjs/network/transports/abstract.js +38 -0
- package/cjs/network/transports/abstract.js.map +1 -0
- package/cjs/network/transports/index.d.ts +8 -0
- package/cjs/network/transports/index.js +26 -0
- package/cjs/network/transports/index.js.map +1 -0
- package/cjs/network/transports/intermediate.d.ts +20 -0
- package/cjs/network/transports/intermediate.js +67 -0
- package/cjs/network/transports/intermediate.js.map +1 -0
- package/cjs/network/transports/obfuscated.d.ts +18 -0
- package/cjs/network/transports/obfuscated.js +83 -0
- package/cjs/network/transports/obfuscated.js.map +1 -0
- package/cjs/network/transports/streamed.d.ts +24 -0
- package/cjs/network/transports/streamed.js +32 -0
- package/cjs/network/transports/streamed.js.map +1 -0
- package/cjs/network/transports/tcp.d.ts +33 -0
- package/cjs/network/transports/tcp.js +130 -0
- package/cjs/network/transports/tcp.js.map +1 -0
- package/cjs/network/transports/websocket.d.ts +47 -0
- package/cjs/network/transports/websocket.js +124 -0
- package/cjs/network/transports/websocket.js.map +1 -0
- package/cjs/network/transports/wrapped.d.ts +11 -0
- package/cjs/network/transports/wrapped.js +26 -0
- package/cjs/network/transports/wrapped.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/storage/abstract.d.ts +174 -0
- package/cjs/storage/abstract.js +3 -0
- package/cjs/storage/abstract.js.map +1 -0
- package/cjs/storage/index.d.ts +5 -0
- package/cjs/storage/index.js +22 -0
- package/cjs/storage/index.js.map +1 -0
- package/cjs/storage/json-file.d.ts +31 -0
- package/cjs/storage/json-file.js +90 -0
- package/cjs/storage/json-file.js.map +1 -0
- package/cjs/storage/json.d.ts +9 -0
- package/cjs/storage/json.js +65 -0
- package/cjs/storage/json.js.map +1 -0
- package/cjs/storage/localstorage.d.ts +7 -0
- package/cjs/storage/localstorage.js +25 -0
- package/cjs/storage/localstorage.js.map +1 -0
- package/cjs/storage/memory.d.ts +98 -0
- package/cjs/storage/memory.js +299 -0
- package/cjs/storage/memory.js.map +1 -0
- package/cjs/types/errors.d.ts +53 -0
- package/cjs/types/errors.js +58 -0
- package/cjs/types/errors.js.map +1 -0
- package/cjs/types/index.d.ts +3 -0
- package/cjs/types/index.js +20 -0
- package/cjs/types/index.js.map +1 -0
- package/cjs/types/peers.d.ts +4 -0
- package/cjs/types/peers.js +3 -0
- package/cjs/types/peers.js.map +1 -0
- package/cjs/types/utils.d.ts +6 -0
- package/cjs/types/utils.js +9 -0
- package/cjs/types/utils.js.map +1 -0
- package/cjs/utils/async-lock.d.ts +10 -0
- package/cjs/utils/async-lock.js +43 -0
- package/cjs/utils/async-lock.js.map +1 -0
- package/cjs/utils/bigint-utils.d.ts +40 -0
- package/cjs/utils/bigint-utils.js +104 -0
- package/cjs/utils/bigint-utils.js.map +1 -0
- package/cjs/utils/binary/asn1-parser.d.ts +17 -0
- package/cjs/utils/binary/asn1-parser.js +121 -0
- package/cjs/utils/binary/asn1-parser.js.map +1 -0
- package/cjs/utils/buffer-utils.d.ts +21 -0
- package/cjs/utils/buffer-utils.js +63 -0
- package/cjs/utils/buffer-utils.js.map +1 -0
- package/cjs/utils/condition-variable.d.ts +9 -0
- package/cjs/utils/condition-variable.js +28 -0
- package/cjs/utils/condition-variable.js.map +1 -0
- package/cjs/utils/controllable-promise.d.ts +16 -0
- package/cjs/utils/controllable-promise.js +25 -0
- package/cjs/utils/controllable-promise.js.map +1 -0
- package/cjs/utils/crypto/abstract.d.ts +23 -0
- package/cjs/utils/crypto/abstract.js +19 -0
- package/cjs/utils/crypto/abstract.js.map +1 -0
- package/cjs/utils/crypto/common.d.ts +12 -0
- package/cjs/utils/crypto/common.js +54 -0
- package/cjs/utils/crypto/common.js.map +1 -0
- package/cjs/utils/crypto/factorization.d.ts +5 -0
- package/cjs/utils/crypto/factorization.js +69 -0
- package/cjs/utils/crypto/factorization.js.map +1 -0
- package/cjs/utils/crypto/index.d.ts +5 -0
- package/cjs/utils/crypto/index.js +23 -0
- package/cjs/utils/crypto/index.js.map +1 -0
- package/cjs/utils/crypto/keys.d.ts +27 -0
- package/cjs/utils/crypto/keys.js +70 -0
- package/cjs/utils/crypto/keys.js.map +1 -0
- package/cjs/utils/crypto/miller-rabin.d.ts +2 -0
- package/cjs/utils/crypto/miller-rabin.js +44 -0
- package/cjs/utils/crypto/miller-rabin.js.map +1 -0
- package/cjs/utils/crypto/mtproto.d.ts +31 -0
- package/cjs/utils/crypto/mtproto.js +66 -0
- package/cjs/utils/crypto/mtproto.js.map +1 -0
- package/cjs/utils/crypto/node-crypto.d.ts +10 -0
- package/cjs/utils/crypto/node-crypto.js +46 -0
- package/cjs/utils/crypto/node-crypto.js.map +1 -0
- package/cjs/utils/crypto/password.d.ts +29 -0
- package/cjs/utils/crypto/password.js +106 -0
- package/cjs/utils/crypto/password.js.map +1 -0
- package/cjs/utils/crypto/subtle.d.ts +12 -0
- package/cjs/utils/crypto/subtle.js +86 -0
- package/cjs/utils/crypto/subtle.js.map +1 -0
- package/cjs/utils/crypto/utils.d.ts +14 -0
- package/cjs/utils/crypto/utils.js +30 -0
- package/cjs/utils/crypto/utils.js.map +1 -0
- package/cjs/utils/default-dcs.d.ts +7 -0
- package/cjs/utils/default-dcs.js +76 -0
- package/cjs/utils/default-dcs.js.map +1 -0
- package/cjs/utils/deque.d.ts +29 -0
- package/cjs/utils/deque.js +210 -0
- package/cjs/utils/deque.js.map +1 -0
- package/cjs/utils/early-timer.d.ts +42 -0
- package/cjs/utils/early-timer.js +79 -0
- package/cjs/utils/early-timer.js.map +1 -0
- package/cjs/utils/flood-control.d.ts +14 -0
- package/cjs/utils/flood-control.js +65 -0
- package/cjs/utils/flood-control.js.map +1 -0
- package/cjs/utils/function-utils.d.ts +13 -0
- package/cjs/utils/function-utils.js +30 -0
- package/cjs/utils/function-utils.js.map +1 -0
- package/cjs/utils/index.d.ts +24 -0
- package/cjs/utils/index.js +41 -0
- package/cjs/utils/index.js.map +1 -0
- package/cjs/utils/linked-list.d.ts +21 -0
- package/cjs/utils/linked-list.js +73 -0
- package/cjs/utils/linked-list.js.map +1 -0
- package/cjs/utils/links/bots.d.ts +71 -0
- package/cjs/utils/links/bots.js +259 -0
- package/cjs/utils/links/bots.js.map +1 -0
- package/cjs/utils/links/bundle.d.ts +7 -0
- package/cjs/utils/links/bundle.js +24 -0
- package/cjs/utils/links/bundle.js.map +1 -0
- package/cjs/utils/links/calls.d.ts +16 -0
- package/cjs/utils/links/calls.js +59 -0
- package/cjs/utils/links/calls.js.map +1 -0
- package/cjs/utils/links/chat.d.ts +46 -0
- package/cjs/utils/links/chat.js +160 -0
- package/cjs/utils/links/chat.js.map +1 -0
- package/cjs/utils/links/common.d.ts +31 -0
- package/cjs/utils/links/common.js +60 -0
- package/cjs/utils/links/common.js.map +1 -0
- package/cjs/utils/links/index.d.ts +2 -0
- package/cjs/utils/links/index.js +29 -0
- package/cjs/utils/links/index.js.map +1 -0
- package/cjs/utils/links/misc.d.ts +19 -0
- package/cjs/utils/links/misc.js +77 -0
- package/cjs/utils/links/misc.js.map +1 -0
- package/cjs/utils/links/proxy.d.ts +17 -0
- package/cjs/utils/links/proxy.js +61 -0
- package/cjs/utils/links/proxy.js.map +1 -0
- package/cjs/utils/links/stickers.d.ts +9 -0
- package/cjs/utils/links/stickers.js +28 -0
- package/cjs/utils/links/stickers.js.map +1 -0
- package/cjs/utils/links/user.d.ts +27 -0
- package/cjs/utils/links/user.js +81 -0
- package/cjs/utils/links/user.js.map +1 -0
- package/cjs/utils/logger.d.ts +54 -0
- package/cjs/utils/logger.js +158 -0
- package/cjs/utils/logger.js.map +1 -0
- package/cjs/utils/long-utils.d.ts +75 -0
- package/cjs/utils/long-utils.js +161 -0
- package/cjs/utils/long-utils.js.map +1 -0
- package/cjs/utils/lru-map.d.ts +21 -0
- package/cjs/utils/lru-map.js +107 -0
- package/cjs/utils/lru-map.js.map +1 -0
- package/cjs/utils/lru-set.d.ts +22 -0
- package/cjs/utils/lru-set.js +48 -0
- package/cjs/utils/lru-set.js.map +1 -0
- package/cjs/utils/misc-utils.d.ts +7 -0
- package/cjs/utils/misc-utils.js +15 -0
- package/cjs/utils/misc-utils.js.map +1 -0
- package/cjs/utils/peer-utils.d.ts +35 -0
- package/cjs/utils/peer-utils.js +188 -0
- package/cjs/utils/peer-utils.js.map +1 -0
- package/cjs/utils/platform/crypto.d.ts +1 -0
- package/cjs/utils/platform/crypto.js +8 -0
- package/cjs/utils/platform/crypto.js.map +1 -0
- package/cjs/utils/platform/crypto.web.d.ts +1 -0
- package/cjs/utils/platform/crypto.web.js +14 -0
- package/cjs/utils/platform/crypto.web.js.map +1 -0
- package/cjs/utils/platform/error-reporting.d.ts +3 -0
- package/cjs/utils/platform/error-reporting.js +22 -0
- package/cjs/utils/platform/error-reporting.js.map +1 -0
- package/cjs/utils/platform/logging.d.ts +1 -0
- package/cjs/utils/platform/logging.js +35 -0
- package/cjs/utils/platform/logging.js.map +1 -0
- package/cjs/utils/platform/logging.web.d.ts +1 -0
- package/cjs/utils/platform/logging.web.js +35 -0
- package/cjs/utils/platform/logging.web.js.map +1 -0
- package/cjs/utils/platform/random.d.ts +1 -0
- package/cjs/utils/platform/random.js +7 -0
- package/cjs/utils/platform/random.js.map +1 -0
- package/cjs/utils/platform/random.web.d.ts +1 -0
- package/cjs/utils/platform/random.web.js +10 -0
- package/cjs/utils/platform/random.web.js.map +1 -0
- package/cjs/utils/platform/transport.d.ts +1 -0
- package/cjs/utils/platform/transport.js +8 -0
- package/cjs/utils/platform/transport.js.map +1 -0
- package/cjs/utils/platform/transport.web.d.ts +1 -0
- package/cjs/utils/platform/transport.web.js +15 -0
- package/cjs/utils/platform/transport.web.js.map +1 -0
- package/cjs/utils/sorted-array.d.ts +17 -0
- package/cjs/utils/sorted-array.js +83 -0
- package/cjs/utils/sorted-array.js.map +1 -0
- package/cjs/utils/string-session.d.ts +11 -0
- package/cjs/utils/string-session.js +73 -0
- package/cjs/utils/string-session.js.map +1 -0
- package/cjs/utils/tl-json.d.ts +13 -0
- package/cjs/utils/tl-json.js +62 -0
- package/cjs/utils/tl-json.js.map +1 -0
- package/cjs/utils/type-assertions.d.ts +37 -0
- package/cjs/utils/type-assertions.js +70 -0
- package/cjs/utils/type-assertions.js.map +1 -0
- package/esm/base-client.d.ts +297 -0
- package/esm/base-client.js +317 -0
- package/esm/base-client.js.map +1 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.js +11 -0
- package/esm/index.js.map +1 -0
- package/esm/network/auth-key.d.ts +21 -0
- package/esm/network/auth-key.js +97 -0
- package/esm/network/auth-key.js.map +1 -0
- package/esm/network/authorization.d.ts +9 -0
- package/esm/network/authorization.js +325 -0
- package/esm/network/authorization.js.map +1 -0
- package/esm/network/config-manager.d.ts +33 -0
- package/esm/network/config-manager.js +89 -0
- package/esm/network/config-manager.js.map +1 -0
- package/esm/network/index.d.ts +4 -0
- package/esm/network/index.js +4 -0
- package/esm/network/index.js.map +1 -0
- package/esm/network/mtproto-session.d.ts +116 -0
- package/esm/network/mtproto-session.js +202 -0
- package/esm/network/mtproto-session.js.map +1 -0
- package/esm/network/multi-session-connection.d.ts +33 -0
- package/esm/network/multi-session-connection.js +236 -0
- package/esm/network/multi-session-connection.js.map +1 -0
- package/esm/network/network-manager.d.ts +190 -0
- package/esm/network/network-manager.js +542 -0
- package/esm/network/network-manager.js.map +1 -0
- package/esm/network/persistent-connection.d.ts +51 -0
- package/esm/network/persistent-connection.js +166 -0
- package/esm/network/persistent-connection.js.map +1 -0
- package/esm/network/reconnection.d.ts +11 -0
- package/esm/network/reconnection.js +14 -0
- package/esm/network/reconnection.js.map +1 -0
- package/esm/network/session-connection.d.ts +72 -0
- package/esm/network/session-connection.js +1356 -0
- package/esm/network/session-connection.js.map +1 -0
- package/esm/network/transports/abstract.d.ts +99 -0
- package/esm/network/transports/abstract.js +34 -0
- package/esm/network/transports/abstract.js.map +1 -0
- package/esm/network/transports/index.d.ts +8 -0
- package/esm/network/transports/index.js +9 -0
- package/esm/network/transports/index.js.map +1 -0
- package/esm/network/transports/intermediate.d.ts +20 -0
- package/esm/network/transports/intermediate.js +62 -0
- package/esm/network/transports/intermediate.js.map +1 -0
- package/esm/network/transports/obfuscated.d.ts +18 -0
- package/esm/network/transports/obfuscated.js +79 -0
- package/esm/network/transports/obfuscated.js.map +1 -0
- package/esm/network/transports/streamed.d.ts +24 -0
- package/esm/network/transports/streamed.js +25 -0
- package/esm/network/transports/streamed.js.map +1 -0
- package/esm/network/transports/tcp.d.ts +33 -0
- package/esm/network/transports/tcp.js +122 -0
- package/esm/network/transports/tcp.js.map +1 -0
- package/esm/network/transports/websocket.d.ts +47 -0
- package/esm/network/transports/websocket.js +116 -0
- package/esm/network/transports/websocket.js.map +1 -0
- package/esm/network/transports/wrapped.d.ts +11 -0
- package/esm/network/transports/wrapped.js +19 -0
- package/esm/network/transports/wrapped.js.map +1 -0
- package/esm/storage/abstract.d.ts +174 -0
- package/esm/storage/abstract.js +2 -0
- package/esm/storage/abstract.js.map +1 -0
- package/esm/storage/index.d.ts +5 -0
- package/esm/storage/index.js +6 -0
- package/esm/storage/index.js.map +1 -0
- package/esm/storage/json-file.d.ts +31 -0
- package/esm/storage/json-file.js +63 -0
- package/esm/storage/json-file.js.map +1 -0
- package/esm/storage/json.d.ts +9 -0
- package/esm/storage/json.js +61 -0
- package/esm/storage/json.js.map +1 -0
- package/esm/storage/localstorage.d.ts +7 -0
- package/esm/storage/localstorage.js +21 -0
- package/esm/storage/localstorage.js.map +1 -0
- package/esm/storage/memory.d.ts +98 -0
- package/esm/storage/memory.js +295 -0
- package/esm/storage/memory.js.map +1 -0
- package/esm/types/errors.d.ts +53 -0
- package/esm/types/errors.js +49 -0
- package/esm/types/errors.js.map +1 -0
- package/esm/types/index.d.ts +3 -0
- package/esm/types/index.js +4 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/peers.d.ts +4 -0
- package/esm/types/peers.js +2 -0
- package/esm/types/peers.js.map +1 -0
- package/esm/types/utils.d.ts +6 -0
- package/esm/types/utils.js +5 -0
- package/esm/types/utils.js.map +1 -0
- package/esm/utils/async-lock.d.ts +10 -0
- package/esm/utils/async-lock.js +39 -0
- package/esm/utils/async-lock.js.map +1 -0
- package/esm/utils/bigint-utils.d.ts +40 -0
- package/esm/utils/bigint-utils.js +92 -0
- package/esm/utils/bigint-utils.js.map +1 -0
- package/esm/utils/binary/asn1-parser.d.ts +17 -0
- package/esm/utils/binary/asn1-parser.js +116 -0
- package/esm/utils/binary/asn1-parser.js.map +1 -0
- package/esm/utils/buffer-utils.d.ts +21 -0
- package/esm/utils/buffer-utils.js +55 -0
- package/esm/utils/buffer-utils.js.map +1 -0
- package/esm/utils/condition-variable.d.ts +9 -0
- package/esm/utils/condition-variable.js +24 -0
- package/esm/utils/condition-variable.js.map +1 -0
- package/esm/utils/controllable-promise.d.ts +16 -0
- package/esm/utils/controllable-promise.js +20 -0
- package/esm/utils/controllable-promise.js.map +1 -0
- package/esm/utils/crypto/abstract.d.ts +23 -0
- package/esm/utils/crypto/abstract.js +15 -0
- package/esm/utils/crypto/abstract.js.map +1 -0
- package/esm/utils/crypto/common.d.ts +12 -0
- package/esm/utils/crypto/common.js +50 -0
- package/esm/utils/crypto/common.js.map +1 -0
- package/esm/utils/crypto/factorization.d.ts +5 -0
- package/esm/utils/crypto/factorization.js +62 -0
- package/esm/utils/crypto/factorization.js.map +1 -0
- package/esm/utils/crypto/index.d.ts +5 -0
- package/esm/utils/crypto/index.js +6 -0
- package/esm/utils/crypto/index.js.map +1 -0
- package/esm/utils/crypto/keys.d.ts +27 -0
- package/esm/utils/crypto/keys.js +64 -0
- package/esm/utils/crypto/keys.js.map +1 -0
- package/esm/utils/crypto/miller-rabin.d.ts +2 -0
- package/esm/utils/crypto/miller-rabin.js +37 -0
- package/esm/utils/crypto/miller-rabin.js.map +1 -0
- package/esm/utils/crypto/mtproto.d.ts +31 -0
- package/esm/utils/crypto/mtproto.js +60 -0
- package/esm/utils/crypto/mtproto.js.map +1 -0
- package/esm/utils/crypto/node-crypto.d.ts +10 -0
- package/esm/utils/crypto/node-crypto.js +42 -0
- package/esm/utils/crypto/node-crypto.js.map +1 -0
- package/esm/utils/crypto/password.d.ts +29 -0
- package/esm/utils/crypto/password.js +97 -0
- package/esm/utils/crypto/password.js.map +1 -0
- package/esm/utils/crypto/subtle.d.ts +12 -0
- package/esm/utils/crypto/subtle.js +59 -0
- package/esm/utils/crypto/subtle.js.map +1 -0
- package/esm/utils/crypto/utils.d.ts +14 -0
- package/esm/utils/crypto/utils.js +25 -0
- package/esm/utils/crypto/utils.js.map +1 -0
- package/esm/utils/default-dcs.d.ts +7 -0
- package/esm/utils/default-dcs.js +73 -0
- package/esm/utils/default-dcs.js.map +1 -0
- package/esm/utils/deque.d.ts +29 -0
- package/esm/utils/deque.js +206 -0
- package/esm/utils/deque.js.map +1 -0
- package/esm/utils/early-timer.d.ts +42 -0
- package/esm/utils/early-timer.js +75 -0
- package/esm/utils/early-timer.js.map +1 -0
- package/esm/utils/flood-control.d.ts +14 -0
- package/esm/utils/flood-control.js +61 -0
- package/esm/utils/flood-control.js.map +1 -0
- package/esm/utils/function-utils.d.ts +13 -0
- package/esm/utils/function-utils.js +26 -0
- package/esm/utils/function-utils.js.map +1 -0
- package/esm/utils/index.d.ts +24 -0
- package/esm/utils/index.js +25 -0
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/linked-list.d.ts +21 -0
- package/esm/utils/linked-list.js +69 -0
- package/esm/utils/linked-list.js.map +1 -0
- package/esm/utils/links/bots.d.ts +71 -0
- package/esm/utils/links/bots.js +256 -0
- package/esm/utils/links/bots.js.map +1 -0
- package/esm/utils/links/bundle.d.ts +7 -0
- package/esm/utils/links/bundle.js +8 -0
- package/esm/utils/links/bundle.js.map +1 -0
- package/esm/utils/links/calls.d.ts +16 -0
- package/esm/utils/links/calls.js +56 -0
- package/esm/utils/links/calls.js.map +1 -0
- package/esm/utils/links/chat.d.ts +46 -0
- package/esm/utils/links/chat.js +157 -0
- package/esm/utils/links/chat.js.map +1 -0
- package/esm/utils/links/common.d.ts +31 -0
- package/esm/utils/links/common.js +56 -0
- package/esm/utils/links/common.js.map +1 -0
- package/esm/utils/links/index.d.ts +2 -0
- package/esm/utils/links/index.js +3 -0
- package/esm/utils/links/index.js.map +1 -0
- package/esm/utils/links/misc.d.ts +19 -0
- package/esm/utils/links/misc.js +74 -0
- package/esm/utils/links/misc.js.map +1 -0
- package/esm/utils/links/proxy.d.ts +17 -0
- package/esm/utils/links/proxy.js +58 -0
- package/esm/utils/links/proxy.js.map +1 -0
- package/esm/utils/links/stickers.d.ts +9 -0
- package/esm/utils/links/stickers.js +25 -0
- package/esm/utils/links/stickers.js.map +1 -0
- package/esm/utils/links/user.d.ts +27 -0
- package/esm/utils/links/user.js +78 -0
- package/esm/utils/links/user.js.map +1 -0
- package/esm/utils/logger.d.ts +54 -0
- package/esm/utils/logger.js +154 -0
- package/esm/utils/logger.js.map +1 -0
- package/esm/utils/long-utils.d.ts +75 -0
- package/esm/utils/long-utils.js +148 -0
- package/esm/utils/long-utils.js.map +1 -0
- package/esm/utils/lru-map.d.ts +21 -0
- package/esm/utils/lru-map.js +103 -0
- package/esm/utils/lru-map.js.map +1 -0
- package/esm/utils/lru-set.d.ts +22 -0
- package/esm/utils/lru-set.js +44 -0
- package/esm/utils/lru-set.js.map +1 -0
- package/esm/utils/misc-utils.d.ts +7 -0
- package/esm/utils/misc-utils.js +10 -0
- package/esm/utils/misc-utils.js.map +1 -0
- package/esm/utils/peer-utils.d.ts +35 -0
- package/esm/utils/peer-utils.js +179 -0
- package/esm/utils/peer-utils.js.map +1 -0
- package/esm/utils/platform/crypto.d.ts +1 -0
- package/esm/utils/platform/crypto.js +4 -0
- package/esm/utils/platform/crypto.js.map +1 -0
- package/esm/utils/platform/crypto.web.d.ts +1 -0
- package/esm/utils/platform/crypto.web.js +10 -0
- package/esm/utils/platform/crypto.web.js.map +1 -0
- package/esm/utils/platform/error-reporting.d.ts +3 -0
- package/esm/utils/platform/error-reporting.js +18 -0
- package/esm/utils/platform/error-reporting.js.map +1 -0
- package/esm/utils/platform/logging.d.ts +1 -0
- package/esm/utils/platform/logging.js +32 -0
- package/esm/utils/platform/logging.js.map +1 -0
- package/esm/utils/platform/logging.web.d.ts +1 -0
- package/esm/utils/platform/logging.web.js +31 -0
- package/esm/utils/platform/logging.web.js.map +1 -0
- package/esm/utils/platform/random.d.ts +1 -0
- package/esm/utils/platform/random.js +4 -0
- package/esm/utils/platform/random.js.map +1 -0
- package/esm/utils/platform/random.web.d.ts +1 -0
- package/esm/utils/platform/random.web.js +6 -0
- package/esm/utils/platform/random.web.js.map +1 -0
- package/esm/utils/platform/transport.d.ts +1 -0
- package/esm/utils/platform/transport.js +4 -0
- package/esm/utils/platform/transport.js.map +1 -0
- package/esm/utils/platform/transport.web.d.ts +1 -0
- package/esm/utils/platform/transport.web.js +12 -0
- package/esm/utils/platform/transport.web.js.map +1 -0
- package/esm/utils/sorted-array.d.ts +17 -0
- package/esm/utils/sorted-array.js +79 -0
- package/esm/utils/sorted-array.js.map +1 -0
- package/esm/utils/string-session.d.ts +11 -0
- package/esm/utils/string-session.js +68 -0
- package/esm/utils/string-session.js.map +1 -0
- package/esm/utils/tl-json.d.ts +13 -0
- package/esm/utils/tl-json.js +57 -0
- package/esm/utils/tl-json.js.map +1 -0
- package/esm/utils/type-assertions.d.ts +37 -0
- package/esm/utils/type-assertions.js +61 -0
- package/esm/utils/type-assertions.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LongSet = exports.LongMap = exports.longFromFastString = exports.longToFastString = exports.removeFromLongArray = exports.longFromBuffer = exports.randomLong = void 0;
|
|
7
|
+
const long_1 = __importDefault(require("long"));
|
|
8
|
+
const buffer_utils_js_1 = require("./buffer-utils.js");
|
|
9
|
+
const misc_utils_js_1 = require("./misc-utils.js");
|
|
10
|
+
/**
|
|
11
|
+
* Get a random Long
|
|
12
|
+
*
|
|
13
|
+
* @param unsigned Whether the number should be unsigned
|
|
14
|
+
*/
|
|
15
|
+
function randomLong(unsigned = false) {
|
|
16
|
+
const lo = (0, misc_utils_js_1.getRandomInt)(0xffffffff);
|
|
17
|
+
const hi = (0, misc_utils_js_1.getRandomInt)(0xffffffff);
|
|
18
|
+
return new long_1.default(lo, hi, unsigned);
|
|
19
|
+
}
|
|
20
|
+
exports.randomLong = randomLong;
|
|
21
|
+
/**
|
|
22
|
+
* Read a Long from a buffer
|
|
23
|
+
*
|
|
24
|
+
* @param buf Buffer to read from
|
|
25
|
+
* @param unsigned Whether the number should be unsigned
|
|
26
|
+
* @param le Whether the number is little-endian
|
|
27
|
+
*/
|
|
28
|
+
function longFromBuffer(buf, unsigned = false, le = true) {
|
|
29
|
+
const dv = (0, buffer_utils_js_1.dataViewFromBuffer)(buf);
|
|
30
|
+
if (le) {
|
|
31
|
+
return new long_1.default(dv.getInt32(0, true), dv.getInt32(4, true), unsigned);
|
|
32
|
+
}
|
|
33
|
+
return new long_1.default(dv.getInt32(4, false), dv.getInt32(0, false), unsigned);
|
|
34
|
+
}
|
|
35
|
+
exports.longFromBuffer = longFromBuffer;
|
|
36
|
+
/**
|
|
37
|
+
* Remove a Long from an array
|
|
38
|
+
*
|
|
39
|
+
* @param arr Array to remove from
|
|
40
|
+
* @param val Value to remove
|
|
41
|
+
*/
|
|
42
|
+
function removeFromLongArray(arr, val) {
|
|
43
|
+
for (let i = 0; i < arr.length; i++) {
|
|
44
|
+
const v = arr[i];
|
|
45
|
+
// v === val for the case when the exact same object was passed
|
|
46
|
+
if (v === val || v.eq(val)) {
|
|
47
|
+
arr.splice(i, 1);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
exports.removeFromLongArray = removeFromLongArray;
|
|
54
|
+
/**
|
|
55
|
+
* Serialize a Long (int64) to its fast string representation:
|
|
56
|
+
* `$high|$low`.
|
|
57
|
+
*
|
|
58
|
+
* This method is about 500* times faster than using `Long.toString()`,
|
|
59
|
+
* and very useful when the string will only ever be used internally
|
|
60
|
+
* (e.g. for keying a map)
|
|
61
|
+
*
|
|
62
|
+
* _\* benchmark result, YMMV_
|
|
63
|
+
*
|
|
64
|
+
* @param val
|
|
65
|
+
*/
|
|
66
|
+
function longToFastString(val) {
|
|
67
|
+
return `${val.low}|${val.high}`;
|
|
68
|
+
}
|
|
69
|
+
exports.longToFastString = longToFastString;
|
|
70
|
+
/**
|
|
71
|
+
* Parse a Long (int64) from its fast string representation:
|
|
72
|
+
* `$high|$low`.
|
|
73
|
+
*
|
|
74
|
+
* This method is about 2 times faster than using Long.fromString.
|
|
75
|
+
*
|
|
76
|
+
* @param val
|
|
77
|
+
* @param unsigned
|
|
78
|
+
*/
|
|
79
|
+
function longFromFastString(val, unsigned = false) {
|
|
80
|
+
const parts = val.split('|');
|
|
81
|
+
if (parts.length !== 2)
|
|
82
|
+
throw new Error(`Invalid long fast string: ${val}`);
|
|
83
|
+
const low = parseInt(parts[0]);
|
|
84
|
+
const high = parseInt(parts[1]);
|
|
85
|
+
if (isNaN(low) || isNaN(high)) {
|
|
86
|
+
throw new Error(`Invalid long fast string: ${val}`);
|
|
87
|
+
}
|
|
88
|
+
return new long_1.default(low, high, unsigned);
|
|
89
|
+
}
|
|
90
|
+
exports.longFromFastString = longFromFastString;
|
|
91
|
+
/**
|
|
92
|
+
* Map with Longs as key.
|
|
93
|
+
*
|
|
94
|
+
* Uses fast string representation internally.
|
|
95
|
+
*/
|
|
96
|
+
class LongMap {
|
|
97
|
+
constructor() {
|
|
98
|
+
this._map = new Map();
|
|
99
|
+
}
|
|
100
|
+
set(key, value) {
|
|
101
|
+
this._map.set(longToFastString(key), value);
|
|
102
|
+
}
|
|
103
|
+
has(key) {
|
|
104
|
+
return this._map.has(longToFastString(key));
|
|
105
|
+
}
|
|
106
|
+
get(key) {
|
|
107
|
+
return this._map.get(longToFastString(key));
|
|
108
|
+
}
|
|
109
|
+
delete(key) {
|
|
110
|
+
this._map.delete(longToFastString(key));
|
|
111
|
+
}
|
|
112
|
+
*keys(unsigned) {
|
|
113
|
+
for (const v of this._map.keys()) {
|
|
114
|
+
yield longFromFastString(v, unsigned);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
values() {
|
|
118
|
+
return this._map.values();
|
|
119
|
+
}
|
|
120
|
+
clear() {
|
|
121
|
+
this._map.clear();
|
|
122
|
+
}
|
|
123
|
+
size() {
|
|
124
|
+
return this._map.size;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.LongMap = LongMap;
|
|
128
|
+
/**
|
|
129
|
+
* Set for Longs.
|
|
130
|
+
*
|
|
131
|
+
* Uses fast string representation internally
|
|
132
|
+
*/
|
|
133
|
+
class LongSet {
|
|
134
|
+
constructor() {
|
|
135
|
+
this._set = new Set();
|
|
136
|
+
}
|
|
137
|
+
get size() {
|
|
138
|
+
return this._set.size;
|
|
139
|
+
}
|
|
140
|
+
add(val) {
|
|
141
|
+
this._set.add(longToFastString(val));
|
|
142
|
+
}
|
|
143
|
+
delete(val) {
|
|
144
|
+
this._set.delete(longToFastString(val));
|
|
145
|
+
}
|
|
146
|
+
has(val) {
|
|
147
|
+
return this._set.has(longToFastString(val));
|
|
148
|
+
}
|
|
149
|
+
clear() {
|
|
150
|
+
this._set.clear();
|
|
151
|
+
}
|
|
152
|
+
toArray() {
|
|
153
|
+
const arr = [];
|
|
154
|
+
for (const v of this._set) {
|
|
155
|
+
arr.push(longFromFastString(v));
|
|
156
|
+
}
|
|
157
|
+
return arr;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.LongSet = LongSet;
|
|
161
|
+
//# sourceMappingURL=long-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"long-utils.js","sourceRoot":"","sources":["../../../src/utils/long-utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAEvB,uDAAsD;AACtD,mDAA8C;AAE9C;;;;GAIG;AACH,SAAgB,UAAU,CAAC,QAAQ,GAAG,KAAK;IACvC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AE;YACvB,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;SAClC;QAED,OAAO,GAAG,CAAA;IACd,CAAC;CACJ;AAhCD,0BAgCC","sourcesContent":["import Long from 'long'\n\nimport { dataViewFromBuffer } from './buffer-utils.js'\nimport { getRandomInt } from './misc-utils.js'\n\n/**\n * Get a random Long\n *\n * @param unsigned Whether the number should be unsigned\n */\nexport function randomLong(unsigned = false): Long {\n const lo = getRandomInt(0xffffffff)\n const hi = getRandomInt(0xffffffff)\n\n return new Long(lo, hi, unsigned)\n}\n\n/**\n * Read a Long from a buffer\n *\n * @param buf Buffer to read from\n * @param unsigned Whether the number should be unsigned\n * @param le Whether the number is little-endian\n */\nexport function longFromBuffer(buf: Uint8Array, unsigned = false, le = true): Long {\n const dv = dataViewFromBuffer(buf)\n\n if (le) {\n return new Long(dv.getInt32(0, true), dv.getInt32(4, true), unsigned)\n }\n\n return new Long(dv.getInt32(4, false), dv.getInt32(0, false), unsigned)\n}\n\n/**\n * Remove a Long from an array\n *\n * @param arr Array to remove from\n * @param val Value to remove\n */\nexport function removeFromLongArray(arr: Long[], val: Long): boolean {\n for (let i = 0; i < arr.length; i++) {\n const v = arr[i]\n\n // v === val for the case when the exact same object was passed\n if (v === val || v.eq(val)) {\n arr.splice(i, 1)\n\n return true\n }\n }\n\n return false\n}\n\n/**\n * Serialize a Long (int64) to its fast string representation:\n * `$high|$low`.\n *\n * This method is about 500* times faster than using `Long.toString()`,\n * and very useful when the string will only ever be used internally\n * (e.g. for keying a map)\n *\n * _\\* benchmark result, YMMV_\n *\n * @param val\n */\nexport function longToFastString(val: Long): string {\n return `${val.low}|${val.high}`\n}\n\n/**\n * Parse a Long (int64) from its fast string representation:\n * `$high|$low`.\n *\n * This method is about 2 times faster than using Long.fromString.\n *\n * @param val\n * @param unsigned\n */\nexport function longFromFastString(val: string, unsigned = false): Long {\n const parts = val.split('|')\n\n if (parts.length !== 2) throw new Error(`Invalid long fast string: ${val}`)\n const low = parseInt(parts[0])\n const high = parseInt(parts[1])\n\n if (isNaN(low) || isNaN(high)) {\n throw new Error(`Invalid long fast string: ${val}`)\n }\n\n return new Long(low, high, unsigned)\n}\n\n/**\n * Map with Longs as key.\n *\n * Uses fast string representation internally.\n */\nexport class LongMap<V> {\n private _map = new Map<string, V>()\n\n set(key: Long, value: V): void {\n this._map.set(longToFastString(key), value)\n }\n\n has(key: Long): boolean {\n return this._map.has(longToFastString(key))\n }\n\n get(key: Long): V | undefined {\n return this._map.get(longToFastString(key))\n }\n\n delete(key: Long): void {\n this._map.delete(longToFastString(key))\n }\n\n *keys(unsigned?: boolean): IterableIterator<Long> {\n for (const v of this._map.keys()) {\n yield longFromFastString(v, unsigned)\n }\n }\n\n values(): IterableIterator<V> {\n return this._map.values()\n }\n\n clear(): void {\n this._map.clear()\n }\n\n size(): number {\n return this._map.size\n }\n}\n\n/**\n * Set for Longs.\n *\n * Uses fast string representation internally\n */\nexport class LongSet {\n private _set = new Set<string>()\n\n get size(): number {\n return this._set.size\n }\n\n add(val: Long) {\n this._set.add(longToFastString(val))\n }\n\n delete(val: Long) {\n this._set.delete(longToFastString(val))\n }\n\n has(val: Long) {\n return this._set.has(longToFastString(val))\n }\n\n clear() {\n this._set.clear()\n }\n\n toArray() {\n const arr: Long[] = []\n\n for (const v of this._set) {\n arr.push(longFromFastString(v))\n }\n\n return arr\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple class implementing LRU-like behaviour for a Map
|
|
3
|
+
*
|
|
4
|
+
* Can be used to handle local cache of *something*
|
|
5
|
+
*
|
|
6
|
+
* Uses two-way linked list internally to keep track of insertion/access order
|
|
7
|
+
*/
|
|
8
|
+
export declare class LruMap<K extends string | number, V> {
|
|
9
|
+
private _capacity;
|
|
10
|
+
private _first?;
|
|
11
|
+
private _last?;
|
|
12
|
+
private _map;
|
|
13
|
+
private _size;
|
|
14
|
+
constructor(capacity: number, forLong?: boolean);
|
|
15
|
+
private _markUsed;
|
|
16
|
+
get(key: K): V | undefined;
|
|
17
|
+
has(key: K): boolean;
|
|
18
|
+
private _remove;
|
|
19
|
+
set(key: K, value: V): void;
|
|
20
|
+
delete(key: K): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LruMap = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
6
|
+
// ^^ because of performance reasons
|
|
7
|
+
const long_utils_js_1 = require("./long-utils.js");
|
|
8
|
+
/**
|
|
9
|
+
* Simple class implementing LRU-like behaviour for a Map
|
|
10
|
+
*
|
|
11
|
+
* Can be used to handle local cache of *something*
|
|
12
|
+
*
|
|
13
|
+
* Uses two-way linked list internally to keep track of insertion/access order
|
|
14
|
+
*/
|
|
15
|
+
class LruMap {
|
|
16
|
+
constructor(capacity, forLong = false) {
|
|
17
|
+
this._size = 0;
|
|
18
|
+
this._capacity = capacity;
|
|
19
|
+
this._map = forLong ? new long_utils_js_1.LongMap() : new Map();
|
|
20
|
+
}
|
|
21
|
+
_markUsed(item) {
|
|
22
|
+
if (item === this._first) {
|
|
23
|
+
return; // already the most recently used
|
|
24
|
+
}
|
|
25
|
+
if (item.p) {
|
|
26
|
+
if (item === this._last) {
|
|
27
|
+
this._last = item.p;
|
|
28
|
+
}
|
|
29
|
+
item.p.n = item.n;
|
|
30
|
+
}
|
|
31
|
+
if (item.n) {
|
|
32
|
+
item.n.p = item.p;
|
|
33
|
+
}
|
|
34
|
+
item.p = undefined;
|
|
35
|
+
item.n = this._first;
|
|
36
|
+
if (this._first) {
|
|
37
|
+
this._first.p = item;
|
|
38
|
+
}
|
|
39
|
+
this._first = item;
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
const item = this._map.get(key);
|
|
43
|
+
if (!item)
|
|
44
|
+
return undefined;
|
|
45
|
+
this._markUsed(item);
|
|
46
|
+
return item.v;
|
|
47
|
+
}
|
|
48
|
+
has(key) {
|
|
49
|
+
return this._map.has(key);
|
|
50
|
+
}
|
|
51
|
+
_remove(item) {
|
|
52
|
+
if (item.p) {
|
|
53
|
+
this._last = item.p;
|
|
54
|
+
this._last.n = undefined;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// exhausted
|
|
58
|
+
this._last = undefined;
|
|
59
|
+
this._first = undefined;
|
|
60
|
+
}
|
|
61
|
+
// remove strong refs to and from the item
|
|
62
|
+
item.p = item.n = undefined;
|
|
63
|
+
this._map.delete(item.k);
|
|
64
|
+
this._size -= 1;
|
|
65
|
+
}
|
|
66
|
+
set(key, value) {
|
|
67
|
+
let item = this._map.get(key);
|
|
68
|
+
if (item) {
|
|
69
|
+
// already in cache, update
|
|
70
|
+
item.v = value;
|
|
71
|
+
this._markUsed(item);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
item = {
|
|
75
|
+
k: key,
|
|
76
|
+
v: value,
|
|
77
|
+
// for jit to optimize stuff
|
|
78
|
+
n: undefined,
|
|
79
|
+
p: undefined,
|
|
80
|
+
};
|
|
81
|
+
this._map.set(key, item);
|
|
82
|
+
if (this._first) {
|
|
83
|
+
this._first.p = item;
|
|
84
|
+
item.n = this._first;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// first item ever
|
|
88
|
+
this._last = item;
|
|
89
|
+
}
|
|
90
|
+
this._first = item;
|
|
91
|
+
this._size += 1;
|
|
92
|
+
if (this._size > this._capacity) {
|
|
93
|
+
// remove the last item
|
|
94
|
+
const oldest = this._last;
|
|
95
|
+
if (oldest) {
|
|
96
|
+
this._remove(oldest);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
delete(key) {
|
|
101
|
+
const item = this._map.get(key);
|
|
102
|
+
if (item)
|
|
103
|
+
this._remove(item);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.LruMap = LruMap;
|
|
107
|
+
//# sourceMappingURL=lru-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-map.js","sourceRoot":"","sources":["../../../src/utils/lru-map.ts"],"names":[],"mappings":";;;AAAA,+FAA+F;AAC/F,0DAA0D;AAC1D,oCAAoC;AACpC,mDAAyC;AAazC;;;;;;GAMG;AACH,MAAa,MAAM;IASf,YAAY,QAAgB,EAAE,OAAO,GAAG,KAAK;QAFrC,UAAK,GAAG,CAAC,CAAA;QAGb,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QAEzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,IAAI,uBAAO,EAAU,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IAC5D,CAAC;IAEO,SAAS,CAAC,IAA4B;QAC1C,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE;YACtB,OAAM,CAAC,iCAAiC;SAC3C;QAED,IAAI,IAAI,CAAC,CAAC,EAAE;YACR,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE;gBACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;aACtB;YACD,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;SACpB;QAED,IAAI,IAAI,CAAC,CAAC,EAAE;YACR,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;SACpB;QAED,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;QAClB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;QAEpB,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAA;SACvB;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;I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SAAS;SACf,CAAA;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAW,CAAC,CAAA;QAE/B,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAA;YACpB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;SACvB;aAAM;YACH,kBAAkB;YAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;SACpB;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,KAAK,IAAI,CAAC,CAAA;QAEf,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE;YAC7B,uBAAuB;YACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAA;YAEzB,IAAI,MAAM,EAAE;gBACR,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;aACvB;SACJ;IACL,CAAC;IAED,MAAM,CAAC,GAAM;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,IAAI;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACJ;AAlHD,wBAkHC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n// ^^ because of performance reasons\nimport { LongMap } from './long-utils.js'\n\ninterface TwoWayLinkedList<K, T> {\n // k = key\n k: K\n // v = value\n v: T\n // p = previous\n p?: TwoWayLinkedList<K, T>\n // n = next\n n?: TwoWayLinkedList<K, T>\n}\n\n/**\n * Simple class implementing LRU-like behaviour for a Map\n *\n * Can be used to handle local cache of *something*\n *\n * Uses two-way linked list internally to keep track of insertion/access order\n */\nexport class LruMap<K extends string | number, V> {\n private _capacity: number\n private _first?: TwoWayLinkedList<K, V>\n private _last?: TwoWayLinkedList<K, V>\n\n private _map: Map<K, TwoWayLinkedList<K, V>>\n\n private _size = 0\n\n constructor(capacity: number, forLong = false) {\n this._capacity = capacity\n\n this._map = forLong ? (new LongMap() as any) : new Map()\n }\n\n private _markUsed(item: TwoWayLinkedList<K, V>): void {\n if (item === this._first) {\n return // already the most recently used\n }\n\n if (item.p) {\n if (item === this._last) {\n this._last = item.p\n }\n item.p.n = item.n\n }\n\n if (item.n) {\n item.n.p = item.p\n }\n\n item.p = undefined\n item.n = this._first\n\n if (this._first) {\n this._first.p = item\n }\n this._first = item\n }\n\n get(key: K): V | undefined {\n const item = this._map.get(key)\n if (!item) return undefined\n\n this._markUsed(item)\n\n return item.v\n }\n\n has(key: K): boolean {\n return this._map.has(key)\n }\n\n private _remove(item: TwoWayLinkedList<K, V>): void {\n if (item.p) {\n this._last = item.p\n this._last.n = undefined\n } else {\n // exhausted\n this._last = undefined\n this._first = undefined\n }\n\n // remove strong refs to and from the item\n item.p = item.n = undefined\n this._map.delete(item.k)\n this._size -= 1\n }\n\n set(key: K, value: V): void {\n let item = this._map.get(key)\n\n if (item) {\n // already in cache, update\n item.v = value\n this._markUsed(item)\n\n return\n }\n\n item = {\n k: key,\n v: value,\n // for jit to optimize stuff\n n: undefined,\n p: undefined,\n }\n this._map.set(key, item as any)\n\n if (this._first) {\n this._first.p = item\n item.n = this._first\n } else {\n // first item ever\n this._last = item\n }\n\n this._first = item\n this._size += 1\n\n if (this._size > this._capacity) {\n // remove the last item\n const oldest = this._last\n\n if (oldest) {\n this._remove(oldest)\n }\n }\n }\n\n delete(key: K): void {\n const item = this._map.get(key)\n if (item) this._remove(item)\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Long from 'long';
|
|
2
|
+
/**
|
|
3
|
+
* Simple class implementing LRU-like behaviour for a Set.
|
|
4
|
+
*
|
|
5
|
+
* Note: this is not exactly LRU, but rather "least recently added"
|
|
6
|
+
* and doesn't mark items as recently added if they are already in the set.
|
|
7
|
+
* This is enough for our use case, so we don't bother with more complex implementation.
|
|
8
|
+
*
|
|
9
|
+
* Used to store recently received message IDs in {@link SessionConnection}
|
|
10
|
+
*
|
|
11
|
+
* Uses one-way linked list internally to keep track of insertion order
|
|
12
|
+
*/
|
|
13
|
+
export declare class LruSet<T extends string | number | Long> {
|
|
14
|
+
private _capacity;
|
|
15
|
+
private _first?;
|
|
16
|
+
private _last?;
|
|
17
|
+
private _set;
|
|
18
|
+
constructor(capacity: number, forLong?: boolean);
|
|
19
|
+
clear(): void;
|
|
20
|
+
add(val: T): void;
|
|
21
|
+
has(val: T): boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LruSet = void 0;
|
|
4
|
+
const long_utils_js_1 = require("./long-utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Simple class implementing LRU-like behaviour for a Set.
|
|
7
|
+
*
|
|
8
|
+
* Note: this is not exactly LRU, but rather "least recently added"
|
|
9
|
+
* and doesn't mark items as recently added if they are already in the set.
|
|
10
|
+
* This is enough for our use case, so we don't bother with more complex implementation.
|
|
11
|
+
*
|
|
12
|
+
* Used to store recently received message IDs in {@link SessionConnection}
|
|
13
|
+
*
|
|
14
|
+
* Uses one-way linked list internally to keep track of insertion order
|
|
15
|
+
*/
|
|
16
|
+
class LruSet {
|
|
17
|
+
constructor(capacity, forLong = false) {
|
|
18
|
+
this._capacity = capacity;
|
|
19
|
+
this._set = forLong ? new long_utils_js_1.LongSet() : new Set();
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this._first = this._last = undefined;
|
|
23
|
+
this._set.clear();
|
|
24
|
+
}
|
|
25
|
+
add(val) {
|
|
26
|
+
if (this._set.has(val))
|
|
27
|
+
return;
|
|
28
|
+
if (!this._first)
|
|
29
|
+
this._first = { v: val };
|
|
30
|
+
if (!this._last)
|
|
31
|
+
this._last = this._first;
|
|
32
|
+
else {
|
|
33
|
+
this._last.n = { v: val };
|
|
34
|
+
this._last = this._last.n;
|
|
35
|
+
}
|
|
36
|
+
this._set.add(val);
|
|
37
|
+
if (this._set.size > this._capacity && this._first) {
|
|
38
|
+
// remove least recently used
|
|
39
|
+
this._set.delete(this._first.v);
|
|
40
|
+
this._first = this._first.n;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
has(val) {
|
|
44
|
+
return this._set.has(val);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.LruSet = LruSet;
|
|
48
|
+
//# sourceMappingURL=lru-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-set.js","sourceRoot":"","sources":["../../../src/utils/lru-set.ts"],"names":[],"mappings":";;;AAKA,mDAAyC;AAOzC;;;;;;;;;;GAUG;AACH,MAAa,MAAM;IAOf,YAAY,QAAgB,EAAE,OAAO,GAAG,KAAK;QACzC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QAEzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,uBAAO,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACnD,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACpC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED,GAAG,CAAC,GAAM;QACN,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC;YAAE,OAAM;QAErC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAA;QAE1C,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAA;aACpC;YACD,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAA;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;SAC5B;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC,CAAA;QAEzB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE;YAChD,6BAA6B;YAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAQ,CAAC,CAAA;YACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;SAC9B;IACL,CAAC;IAED,GAAG,CAAC,GAAM;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAU,CAAC,CAAA;IACpC,CAAC;CACJ;AAzCD,wBAyCC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n// ^^ because of performance reasons\nimport Long from 'long'\n\nimport { LongSet } from './long-utils.js'\n\ninterface OneWayLinkedList<T> {\n v: T\n n?: OneWayLinkedList<T>\n}\n\n/**\n * Simple class implementing LRU-like behaviour for a Set.\n *\n * Note: this is not exactly LRU, but rather \"least recently added\"\n * and doesn't mark items as recently added if they are already in the set.\n * This is enough for our use case, so we don't bother with more complex implementation.\n *\n * Used to store recently received message IDs in {@link SessionConnection}\n *\n * Uses one-way linked list internally to keep track of insertion order\n */\nexport class LruSet<T extends string | number | Long> {\n private _capacity: number\n private _first?: OneWayLinkedList<T>\n private _last?: OneWayLinkedList<T>\n\n private _set: Set<T> | LongSet\n\n constructor(capacity: number, forLong = false) {\n this._capacity = capacity\n\n this._set = forLong ? new LongSet() : new Set()\n }\n\n clear() {\n this._first = this._last = undefined\n this._set.clear()\n }\n\n add(val: T) {\n if (this._set.has(val as any)) return\n\n if (!this._first) this._first = { v: val }\n\n if (!this._last) this._last = this._first\n else {\n this._last.n = { v: val }\n this._last = this._last.n\n }\n\n this._set.add(val as any)\n\n if (this._set.size > this._capacity && this._first) {\n // remove least recently used\n this._set.delete(this._first.v as any)\n this._first = this._first.n\n }\n }\n\n has(val: T) {\n return this._set.has(val as any)\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomInt = exports.sleep = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sleep for the given number of ms
|
|
6
|
+
*
|
|
7
|
+
* @param ms Number of ms to sleep
|
|
8
|
+
*/
|
|
9
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
exports.sleep = sleep;
|
|
11
|
+
function getRandomInt(top) {
|
|
12
|
+
return Math.floor(Math.random() * top);
|
|
13
|
+
}
|
|
14
|
+
exports.getRandomInt = getRandomInt;
|
|
15
|
+
//# sourceMappingURL=misc-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc-utils.js","sourceRoot":"","sources":["../../../src/utils/misc-utils.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AAAxF,QAAA,KAAK,SAAmF;AAErG,SAAgB,YAAY,CAAC,GAAW;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAA;AAC1C,CAAC;AAFD,oCAEC","sourcesContent":["/**\n * Sleep for the given number of ms\n *\n * @param ms Number of ms to sleep\n */\nexport const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))\n\nexport function getRandomInt(top: number): number {\n return Math.floor(Math.random() * top)\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { BasicPeerType } from '../types/peers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Add or remove channel marker from ID
|
|
5
|
+
*/
|
|
6
|
+
export declare function toggleChannelIdMark(id: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Get the bare (non-marked) ID from a {@link tl.TypePeer}
|
|
9
|
+
*/
|
|
10
|
+
export declare function getBarePeerId(peer: tl.TypePeer): number;
|
|
11
|
+
/**
|
|
12
|
+
* Get the marked (non-bare) ID from a {@link tl.TypePeer}
|
|
13
|
+
*
|
|
14
|
+
* *Mark* is bot API compatible, which is:
|
|
15
|
+
* - ID stays the same for users
|
|
16
|
+
* - ID is negated for chats
|
|
17
|
+
* - ID is negated and `-1e12` is subtracted for channels
|
|
18
|
+
*/
|
|
19
|
+
export declare function getMarkedPeerId(peerId: number, peerType: BasicPeerType): number;
|
|
20
|
+
export declare function getMarkedPeerId(peer: tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): number;
|
|
21
|
+
/**
|
|
22
|
+
* Extract basic peer type from {@link tl.TypePeer} or its marked ID.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getBasicPeerType(peer: tl.TypePeer | number): BasicPeerType;
|
|
25
|
+
/**
|
|
26
|
+
* Extract bare peer ID from marked ID.
|
|
27
|
+
*
|
|
28
|
+
* @param peerId Marked peer ID
|
|
29
|
+
*/
|
|
30
|
+
export declare function markedPeerIdToBare(peerId: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts all (cacheable) entities from a TlObject or a list of them.
|
|
33
|
+
* Only checks `.user`, `.chat`, `.channel`, `.users` and `.chats` properties
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAllPeersFrom(obj: tl.TlObject | tl.TlObject[]): Iterable<tl.TypeUser | tl.TypeChat>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllPeersFrom = exports.markedPeerIdToBare = exports.getBasicPeerType = exports.getMarkedPeerId = exports.getBarePeerId = exports.toggleChannelIdMark = void 0;
|
|
4
|
+
const errors_js_1 = require("../types/errors.js");
|
|
5
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/DialogId.h
|
|
6
|
+
const ZERO_CHANNEL_ID = -1000000000000;
|
|
7
|
+
const ZERO_SECRET_CHAT_ID = -2000000000000;
|
|
8
|
+
const MAX_SECRET_CHAT_ID = -1997852516353; // ZERO_SECRET_CHAT_ID + 0x7fffffff
|
|
9
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/ChatId.h
|
|
10
|
+
// const MAX_CHAT_ID = 999999999999
|
|
11
|
+
const MIN_MARKED_CHAT_ID = -999999999999; // -MAX_CHAT_ID
|
|
12
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/UserId.h
|
|
13
|
+
// MAX_USER_ID = (1ll << 40) - 1
|
|
14
|
+
const MAX_USER_ID = 1099511627775;
|
|
15
|
+
// src: https://github.com/tdlib/td/blob/master/td/telegram/ChannelId.h
|
|
16
|
+
// the last (1 << 31) - 1 identifiers will be used for secret chat dialog identifiers
|
|
17
|
+
// MAX_CHANNEL_ID = 1000000000000ll - (1ll << 31)
|
|
18
|
+
// const MAX_CHANNEL_ID = 997852516352
|
|
19
|
+
const MIN_MARKED_CHANNEL_ID = -1997852516352; // ZERO_CHANNEL_ID - MAX_CHANNEL_ID
|
|
20
|
+
/**
|
|
21
|
+
* Add or remove channel marker from ID
|
|
22
|
+
*/
|
|
23
|
+
function toggleChannelIdMark(id) {
|
|
24
|
+
return ZERO_CHANNEL_ID - id;
|
|
25
|
+
}
|
|
26
|
+
exports.toggleChannelIdMark = toggleChannelIdMark;
|
|
27
|
+
/**
|
|
28
|
+
* Get the bare (non-marked) ID from a {@link tl.TypePeer}
|
|
29
|
+
*/
|
|
30
|
+
function getBarePeerId(peer) {
|
|
31
|
+
switch (peer._) {
|
|
32
|
+
case 'peerUser':
|
|
33
|
+
return peer.userId;
|
|
34
|
+
case 'peerChat':
|
|
35
|
+
return peer.chatId;
|
|
36
|
+
case 'peerChannel':
|
|
37
|
+
return peer.channelId;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getBarePeerId = getBarePeerId;
|
|
41
|
+
function getMarkedPeerId(peer, peerType) {
|
|
42
|
+
if (typeof peer === 'number') {
|
|
43
|
+
switch (peerType) {
|
|
44
|
+
case 'user':
|
|
45
|
+
return peer;
|
|
46
|
+
case 'chat':
|
|
47
|
+
return -peer;
|
|
48
|
+
case 'channel':
|
|
49
|
+
return ZERO_CHANNEL_ID - peer;
|
|
50
|
+
}
|
|
51
|
+
throw new errors_js_1.MtArgumentError('Invalid peer type');
|
|
52
|
+
}
|
|
53
|
+
switch (peer._) {
|
|
54
|
+
case 'peerUser':
|
|
55
|
+
case 'inputPeerUser':
|
|
56
|
+
case 'inputUser':
|
|
57
|
+
return peer.userId;
|
|
58
|
+
case 'peerChat':
|
|
59
|
+
case 'inputPeerChat':
|
|
60
|
+
return -peer.chatId;
|
|
61
|
+
case 'peerChannel':
|
|
62
|
+
case 'inputPeerChannel':
|
|
63
|
+
case 'inputChannel':
|
|
64
|
+
return ZERO_CHANNEL_ID - peer.channelId;
|
|
65
|
+
}
|
|
66
|
+
throw new errors_js_1.MtArgumentError('Invalid peer');
|
|
67
|
+
}
|
|
68
|
+
exports.getMarkedPeerId = getMarkedPeerId;
|
|
69
|
+
/**
|
|
70
|
+
* Extract basic peer type from {@link tl.TypePeer} or its marked ID.
|
|
71
|
+
*/
|
|
72
|
+
function getBasicPeerType(peer) {
|
|
73
|
+
if (typeof peer !== 'number') {
|
|
74
|
+
switch (peer._) {
|
|
75
|
+
case 'peerUser':
|
|
76
|
+
return 'user';
|
|
77
|
+
case 'peerChat':
|
|
78
|
+
return 'chat';
|
|
79
|
+
case 'peerChannel':
|
|
80
|
+
return 'channel';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (peer < 0) {
|
|
84
|
+
if (MIN_MARKED_CHAT_ID <= peer) {
|
|
85
|
+
return 'chat';
|
|
86
|
+
}
|
|
87
|
+
if (MIN_MARKED_CHANNEL_ID <= peer && peer !== ZERO_CHANNEL_ID) {
|
|
88
|
+
return 'channel';
|
|
89
|
+
}
|
|
90
|
+
if (MAX_SECRET_CHAT_ID <= peer && peer !== ZERO_SECRET_CHAT_ID) {
|
|
91
|
+
// return 'secret'
|
|
92
|
+
throw new errors_js_1.MtUnsupportedError('Secret chats are not supported');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (peer > 0 && peer <= MAX_USER_ID) {
|
|
96
|
+
return 'user';
|
|
97
|
+
}
|
|
98
|
+
throw new errors_js_1.MtArgumentError(`Invalid marked peer id: ${peer}`);
|
|
99
|
+
}
|
|
100
|
+
exports.getBasicPeerType = getBasicPeerType;
|
|
101
|
+
/**
|
|
102
|
+
* Extract bare peer ID from marked ID.
|
|
103
|
+
*
|
|
104
|
+
* @param peerId Marked peer ID
|
|
105
|
+
*/
|
|
106
|
+
function markedPeerIdToBare(peerId) {
|
|
107
|
+
const type = getBasicPeerType(peerId);
|
|
108
|
+
switch (type) {
|
|
109
|
+
case 'user':
|
|
110
|
+
return peerId;
|
|
111
|
+
case 'chat':
|
|
112
|
+
return -peerId;
|
|
113
|
+
case 'channel':
|
|
114
|
+
return toggleChannelIdMark(peerId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.markedPeerIdToBare = markedPeerIdToBare;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts all (cacheable) entities from a TlObject or a list of them.
|
|
120
|
+
* Only checks `.user`, `.chat`, `.channel`, `.users` and `.chats` properties
|
|
121
|
+
*/
|
|
122
|
+
function* getAllPeersFrom(obj) {
|
|
123
|
+
if (typeof obj !== 'object')
|
|
124
|
+
return;
|
|
125
|
+
if (Array.isArray(obj)) {
|
|
126
|
+
for (const it of obj) {
|
|
127
|
+
yield* getAllPeersFrom(it);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
switch (obj._) {
|
|
132
|
+
case 'user':
|
|
133
|
+
case 'chat':
|
|
134
|
+
case 'channel':
|
|
135
|
+
case 'chatForbidden':
|
|
136
|
+
case 'channelForbidden':
|
|
137
|
+
yield obj;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if ('user' in obj && typeof obj.user === 'object' && obj.user._ === 'user') {
|
|
141
|
+
yield obj.user;
|
|
142
|
+
}
|
|
143
|
+
if ('chat' in obj && typeof obj.chat === 'object') {
|
|
144
|
+
switch (obj.chat._) {
|
|
145
|
+
case 'chat':
|
|
146
|
+
case 'channel':
|
|
147
|
+
case 'chatForbidden':
|
|
148
|
+
case 'channelForbidden':
|
|
149
|
+
yield obj.chat;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ('channel' in obj && typeof obj.channel === 'object') {
|
|
154
|
+
switch (obj.channel._) {
|
|
155
|
+
case 'chat':
|
|
156
|
+
case 'channel':
|
|
157
|
+
case 'chatForbidden':
|
|
158
|
+
case 'channelForbidden':
|
|
159
|
+
yield obj.channel;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if ('users' in obj && Array.isArray(obj.users) && obj.users.length) {
|
|
164
|
+
for (const user of obj.users) {
|
|
165
|
+
// .users is sometimes number[]
|
|
166
|
+
if (typeof user === 'object' && user._ === 'user') {
|
|
167
|
+
yield user;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if ('chats' in obj && Array.isArray(obj.chats) && obj.chats.length) {
|
|
172
|
+
for (const chat of obj.chats) {
|
|
173
|
+
// .chats is sometimes number[]
|
|
174
|
+
if (typeof chat === 'object') {
|
|
175
|
+
switch (chat._) {
|
|
176
|
+
case 'chat':
|
|
177
|
+
case 'channel':
|
|
178
|
+
case 'chatForbidden':
|
|
179
|
+
case 'channelForbidden':
|
|
180
|
+
yield chat;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.getAllPeersFrom = getAllPeersFrom;
|
|
188
|
+
//# sourceMappingURL=peer-utils.js.map
|