@mtkruto/node 0.1.129 → 0.1.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/esm/0_deps.d.ts +1 -0
  2. package/esm/0_deps.js +9 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/3_types.d.ts +363 -3
  6. package/esm/client/5_client.d.ts +113 -5
  7. package/esm/client/5_client.js +561 -103
  8. package/esm/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  9. package/esm/deps/deno.land/std@0.209.0/media_types/extension.js +26 -0
  10. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  11. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +31 -0
  12. package/esm/storage/0_storage.d.ts +3 -1
  13. package/esm/storage/0_storage.js +18 -5
  14. package/esm/tl/0_tl_raw_reader.js +1 -1
  15. package/esm/tl/3_utilities.d.ts +1 -0
  16. package/esm/tl/3_utilities.js +11 -0
  17. package/esm/types/1__getters.d.ts +1 -0
  18. package/esm/types/1_sticker.js +5 -4
  19. package/esm/types/4_chat.d.ts +3 -2
  20. package/esm/types/4_chat.js +16 -27
  21. package/package.json +1 -1
  22. package/script/0_deps.d.ts +1 -0
  23. package/script/0_deps.js +11 -1
  24. package/script/4_constants.d.ts +1 -1
  25. package/script/4_constants.js +1 -1
  26. package/script/client/3_types.d.ts +363 -3
  27. package/script/client/5_client.d.ts +113 -5
  28. package/script/client/5_client.js +558 -100
  29. package/script/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  30. package/script/deps/deno.land/std@0.209.0/media_types/extension.js +30 -0
  31. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  32. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +35 -0
  33. package/script/storage/0_storage.d.ts +3 -1
  34. package/script/storage/0_storage.js +18 -5
  35. package/script/tl/0_tl_raw_reader.js +1 -1
  36. package/script/tl/3_utilities.d.ts +1 -0
  37. package/script/tl/3_utilities.js +13 -1
  38. package/script/types/1__getters.d.ts +1 -0
  39. package/script/types/1_sticker.js +4 -3
  40. package/script/types/4_chat.d.ts +3 -2
  41. package/script/types/4_chat.js +17 -27
@@ -0,0 +1,17 @@
1
+ /**
2
+ * For a given media type, return the most relevant extension, or `undefined`
3
+ * if no extension can be found.
4
+ *
5
+ * Extensions are returned without a leading `.`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
10
+ *
11
+ * extension("text/plain"); // `txt`
12
+ * extension("application/json"); // `json`
13
+ * extension("text/html; charset=UTF-8"); // `html`
14
+ * extension("application/foo"); // undefined
15
+ * ```
16
+ */
17
+ export declare function extension(type: string): string | undefined;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.extension = void 0;
6
+ const extensions_by_type_js_1 = require("./extensions_by_type.js");
7
+ /**
8
+ * For a given media type, return the most relevant extension, or `undefined`
9
+ * if no extension can be found.
10
+ *
11
+ * Extensions are returned without a leading `.`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
16
+ *
17
+ * extension("text/plain"); // `txt`
18
+ * extension("application/json"); // `json`
19
+ * extension("text/html; charset=UTF-8"); // `html`
20
+ * extension("application/foo"); // undefined
21
+ * ```
22
+ */
23
+ function extension(type) {
24
+ const exts = (0, extensions_by_type_js_1.extensionsByType)(type);
25
+ if (exts) {
26
+ return exts[0];
27
+ }
28
+ return undefined;
29
+ }
30
+ exports.extension = extension;
@@ -0,0 +1,20 @@
1
+ import { extensions } from "./_util.js";
2
+ export { extensions };
3
+ /**
4
+ * Returns the extensions known to be associated with the media type `type`.
5
+ * The returned extensions will each begin with a leading dot, as in `.html`.
6
+ *
7
+ * When `type` has no associated extensions, the function returns `undefined`.
8
+ *
9
+ * Extensions are returned without a leading `.`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
14
+ *
15
+ * extensionsByType("application/json"); // ["json", "map"]
16
+ * extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
17
+ * extensionsByType("application/foo"); // undefined
18
+ * ```
19
+ */
20
+ export declare function extensionsByType(type: string): string[] | undefined;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.extensionsByType = exports.extensions = void 0;
6
+ const parse_media_type_js_1 = require("./parse_media_type.js");
7
+ const _util_js_1 = require("./_util.js");
8
+ Object.defineProperty(exports, "extensions", { enumerable: true, get: function () { return _util_js_1.extensions; } });
9
+ /**
10
+ * Returns the extensions known to be associated with the media type `type`.
11
+ * The returned extensions will each begin with a leading dot, as in `.html`.
12
+ *
13
+ * When `type` has no associated extensions, the function returns `undefined`.
14
+ *
15
+ * Extensions are returned without a leading `.`.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
20
+ *
21
+ * extensionsByType("application/json"); // ["json", "map"]
22
+ * extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
23
+ * extensionsByType("application/foo"); // undefined
24
+ * ```
25
+ */
26
+ function extensionsByType(type) {
27
+ try {
28
+ const [mediaType] = (0, parse_media_type_js_1.parseMediaType)(type);
29
+ return _util_js_1.extensions.get(mediaType);
30
+ }
31
+ catch {
32
+ // just swallow errors, returning undefined
33
+ }
34
+ }
35
+ exports.extensionsByType = extensionsByType;
@@ -32,7 +32,7 @@ export declare abstract class Storage {
32
32
  updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
33
33
  getUsername(username: string): Promise<["channel" | "user", bigint, Date] | null>;
34
34
  setTlObject(key: readonly StorageKeyPart[], value: TLObject | null): Promise<void>;
35
- getTLObject(keyOrBuffer: Uint8Array | readonly StorageKeyPart[]): Promise<import("../2_tl.js").ReadObject | null>;
35
+ getTlObject(keyOrBuffer: Uint8Array | readonly StorageKeyPart[]): Promise<import("../2_tl.js").ReadObject | null>;
36
36
  setState(state: enums.updates.State): Promise<void>;
37
37
  getState(): Promise<import("../tl/2_types.js").updates_State_ | null>;
38
38
  setMessage(chatId: number, messageId: number, message: enums.Message | null): Promise<void>;
@@ -71,4 +71,6 @@ export declare abstract class Storage {
71
71
  iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
72
72
  saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
73
73
  setFilePartCount(id: bigint, partCount: number): Promise<void>;
74
+ setCustomEmojiDocument(id: bigint, document: types.Document): Promise<void>;
75
+ getCustomEmojiDocument(id: bigint): Promise<[import("../tl/2_types.js").Document_, Date] | null>;
74
76
  }
@@ -35,6 +35,7 @@ const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
35
35
  const KPARTS_SERVER_SALT = ["serverSalt"];
36
36
  const KPARTS_FILE = (fileId) => ["files", fileId];
37
37
  const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
38
+ const KPARTS_CEMOJI = (id) => ["customEmojiDocuments", id];
38
39
  class Storage {
39
40
  constructor() {
40
41
  _Storage_instances.add(this);
@@ -88,7 +89,7 @@ class Storage {
88
89
  await this.set(key, (0, _1_utilities_js_1.rleEncode)(value[_2_tl_js_1.serialize]()));
89
90
  }
90
91
  }
91
- async getTLObject(keyOrBuffer) {
92
+ async getTlObject(keyOrBuffer) {
92
93
  const buffer = keyOrBuffer instanceof Uint8Array ? keyOrBuffer : await this.get(keyOrBuffer);
93
94
  if (buffer != null) {
94
95
  return new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)(buffer)).readObject();
@@ -101,7 +102,7 @@ class Storage {
101
102
  await this.setTlObject(KPARTS__STATE, state);
102
103
  }
103
104
  async getState() {
104
- return await this.getTLObject(KPARTS__STATE);
105
+ return await this.getTlObject(KPARTS__STATE);
105
106
  }
106
107
  async setMessage(chatId, messageId, message) {
107
108
  if (chatId > _1_utilities_js_1.ZERO_CHANNEL_ID) {
@@ -120,11 +121,11 @@ class Storage {
120
121
  return this.get(KPARTS_MESSAGE_REF(messageId));
121
122
  }
122
123
  async getMessage(chatId, messageId) {
123
- return await this.getTLObject(KPARTS_MESSAGE(chatId, messageId));
124
+ return await this.getTlObject(KPARTS_MESSAGE(chatId, messageId));
124
125
  }
125
126
  async getLastMessage(chatId) {
126
127
  for await (const [_, buffer] of await this.getMany({ prefix: KPARTS_MESSAGES(chatId) }, { limit: 1, reverse: true })) {
127
- return await this.getTLObject(buffer);
128
+ return await this.getTlObject(buffer);
128
129
  }
129
130
  return null;
130
131
  }
@@ -220,7 +221,7 @@ class Storage {
220
221
  ++limit;
221
222
  const messages = new Array();
222
223
  for await (const [_, buffer] of await this.getMany({ start: KPARTS_MESSAGE(chatId, 0), end: KPARTS_MESSAGE(chatId, offsetId) }, { limit, reverse: true })) {
223
- const message = await this.getTLObject(buffer);
224
+ const message = await this.getTlObject(buffer);
224
225
  if ("id" in message && message.id == offsetId) {
225
226
  continue;
226
227
  }
@@ -258,6 +259,18 @@ class Storage {
258
259
  }
259
260
  await this.set(KPARTS_FILE(id), partCount);
260
261
  }
262
+ async setCustomEmojiDocument(id, document) {
263
+ await this.set(KPARTS_CEMOJI(id), [(0, _1_utilities_js_1.rleEncode)(document[_2_tl_js_1.serialize]()), new Date()]);
264
+ }
265
+ async getCustomEmojiDocument(id) {
266
+ const v = await this.get(KPARTS_CEMOJI(id));
267
+ if (v != null) {
268
+ return [await this.getTlObject([0]), v[1]];
269
+ }
270
+ else {
271
+ return null;
272
+ }
273
+ }
261
274
  }
262
275
  exports.Storage = Storage;
263
276
  _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
@@ -38,7 +38,7 @@ class TLRawReader {
38
38
  return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
39
39
  }
40
40
  readDouble() {
41
- return new DataView(this.read(8).buffer).getFloat64(0, true); // TODO: cover in tests
41
+ return new DataView(this.read(8).buffer).getFloat64(0, true);
42
42
  }
43
43
  readInt128(signed = true) {
44
44
  const buffer = this.read(128 / 8);
@@ -1,3 +1,4 @@
1
1
  import { enums } from "./2_types.js";
2
2
  export declare function getChannelChatId(channelId: bigint): number;
3
3
  export declare function peerToChatId(peer: enums.Peer | enums.InputPeer): number;
4
+ export declare function chatIdToPeer(chatId: number): import("./2_types.js").PeerUser_ | import("./2_types.js").PeerChat_ | import("./2_types.js").PeerChannel_;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.peerToChatId = exports.getChannelChatId = void 0;
3
+ exports.chatIdToPeer = exports.peerToChatId = exports.getChannelChatId = void 0;
4
4
  const _1_utilities_js_1 = require("../1_utilities.js");
5
5
  const _2_types_js_1 = require("./2_types.js");
6
6
  function getChannelChatId(channelId) {
@@ -22,3 +22,15 @@ function peerToChatId(peer) {
22
22
  }
23
23
  }
24
24
  exports.peerToChatId = peerToChatId;
25
+ function chatIdToPeer(chatId) {
26
+ if (chatId > 0) {
27
+ return new _2_types_js_1.types.PeerUser({ user_id: BigInt(chatId) });
28
+ }
29
+ else if (chatId > _1_utilities_js_1.ZERO_CHANNEL_ID) {
30
+ return new _2_types_js_1.types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) });
31
+ }
32
+ else {
33
+ return new _2_types_js_1.types.PeerChannel({ channel_id: BigInt(_1_utilities_js_1.ZERO_CHANNEL_ID - chatId) });
34
+ }
35
+ }
36
+ exports.chatIdToPeer = chatIdToPeer;
@@ -5,6 +5,7 @@ export interface EntityGetter {
5
5
  (peer: types.PeerUser): MaybePromise<types.User | null>;
6
6
  (peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
7
7
  (peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
8
+ (peer: types.PeerUser | types.PeerChat | types.PeerChannel): MaybePromise<types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden | null>;
8
9
  }
9
10
  export interface InputPeerGetter {
10
11
  (id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constructSticker = void 0;
4
+ const _1_utilities_js_1 = require("../1_utilities.js");
4
5
  const _2_tl_js_1 = require("../2_tl.js");
5
6
  const _0_mask_position_js_1 = require("./0_mask_position.js");
6
7
  const _0_thumbnail_js_1 = require("./0_thumbnail.js");
@@ -8,8 +9,8 @@ async function constructSticker(document, fileId, fileUniqueId, getStickerSetNam
8
9
  const stickerAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeSticker);
9
10
  const imageSizeAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeImageSize);
10
11
  const videoAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeVideo);
11
- const setName = await getStickerSetName(stickerAttribute.stickerset[_2_tl_js_1.as](_2_tl_js_1.types.InputStickerSetID));
12
- return {
12
+ const setName = stickerAttribute.stickerset instanceof _2_tl_js_1.types.InputStickerSetID ? await getStickerSetName(stickerAttribute.stickerset) : undefined;
13
+ return (0, _1_utilities_js_1.cleanObject)({
13
14
  fileId,
14
15
  fileUniqueId,
15
16
  // TODO: custom emoji type?
@@ -26,6 +27,6 @@ async function constructSticker(document, fileId, fileUniqueId, getStickerSetNam
26
27
  customEmojiId: undefined,
27
28
  needsRepainting: undefined,
28
29
  fileSize: Number(document.size),
29
- };
30
+ });
30
31
  }
31
32
  exports.constructSticker = constructSticker;
@@ -29,5 +29,6 @@ export declare namespace Chat {
29
29
  export type Chat = Chat.Channel | Chat.Supergroup | Chat.Group | Chat.Private;
30
30
  export declare function getChatOrder(lastMessage: Message | undefined, pinned: number): string;
31
31
  export declare function constructChat(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">, getStickerSetName: StickerSetNameGetter): Promise<Chat>;
32
- export declare function constructChat2(chatId: number, pinned: number, lastMessage: Message | undefined, getEntity: EntityGetter): Promise<Chat | null>;
33
- export declare function constructChat3(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">): Promise<Chat | null>;
32
+ export declare function constructChat2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Message | undefined): Chat;
33
+ export declare function constructChat3(chatId: number, pinned: number, lastMessage: Message | undefined, getEntity: EntityGetter): Promise<Chat | null>;
34
+ export declare function constructChat4(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">): Promise<Chat | null>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constructChat3 = exports.constructChat2 = exports.constructChat = exports.getChatOrder = void 0;
3
+ exports.constructChat4 = exports.constructChat3 = exports.constructChat2 = exports.constructChat = exports.getChatOrder = void 0;
4
4
  const _1_utilities_js_1 = require("../1_utilities.js");
5
5
  const _2_tl_js_1 = require("../2_tl.js");
6
6
  const _1_chat_p_js_1 = require("./1_chat_p.js");
@@ -74,29 +74,8 @@ async function constructChat(dialog, dialogs, pinnedChats, getEntity, getMessage
74
74
  }
75
75
  }
76
76
  exports.constructChat = constructChat;
77
- async function constructChat2(chatId, pinned, lastMessage, getEntity) {
78
- let chatPAlsoPhoto = null;
79
- if (chatId < _1_utilities_js_1.ZERO_CHANNEL_ID) {
80
- const entity = await getEntity(new _2_tl_js_1.types.PeerChannel({ channel_id: BigInt(Math.abs(chatId - _1_utilities_js_1.ZERO_CHANNEL_ID)) }));
81
- if (entity != null) {
82
- chatPAlsoPhoto = getChatPAlsoPhoto(entity);
83
- }
84
- }
85
- else if (chatId < 0) {
86
- const entity = await getEntity(new _2_tl_js_1.types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) }));
87
- if (entity != null) {
88
- chatPAlsoPhoto = getChatPAlsoPhoto(entity);
89
- }
90
- }
91
- else {
92
- const entity = await getEntity(new _2_tl_js_1.types.PeerUser({ user_id: BigInt(chatId) }));
93
- if (entity != null) {
94
- chatPAlsoPhoto = getChatPAlsoPhoto(entity);
95
- }
96
- }
97
- if (chatPAlsoPhoto == null) {
98
- return null;
99
- }
77
+ function constructChat2(entity, pinned, lastMessage) {
78
+ const chatPAlsoPhoto = getChatPAlsoPhoto(entity);
100
79
  const order = getChatOrder(lastMessage, pinned);
101
80
  const { also, photo, chatP } = chatPAlsoPhoto;
102
81
  if (chatP.type == "group") {
@@ -116,9 +95,20 @@ async function constructChat2(chatId, pinned, lastMessage, getEntity) {
116
95
  }
117
96
  }
118
97
  exports.constructChat2 = constructChat2;
119
- async function constructChat3(chatId, pinned, lastMessageId, getEntity, getMessage) {
98
+ async function constructChat3(chatId, pinned, lastMessage, getEntity) {
99
+ const peer = (0, _2_tl_js_1.chatIdToPeer)(chatId);
100
+ const entity = await getEntity(peer);
101
+ if (entity == null) {
102
+ return null;
103
+ }
104
+ else {
105
+ return constructChat2(entity, pinned, lastMessage);
106
+ }
107
+ }
108
+ exports.constructChat3 = constructChat3;
109
+ async function constructChat4(chatId, pinned, lastMessageId, getEntity, getMessage) {
120
110
  const lastMessage_ = lastMessageId > 0 ? await getMessage(chatId, lastMessageId) : null;
121
111
  const lastMessage = lastMessage_ == null ? undefined : lastMessage_;
122
- return await constructChat2(chatId, pinned, lastMessage, getEntity);
112
+ return await constructChat3(chatId, pinned, lastMessage, getEntity);
123
113
  }
124
- exports.constructChat3 = constructChat3;
114
+ exports.constructChat4 = constructChat4;