@mtkruto/node 0.0.995 → 0.0.997
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.js +1 -0
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +1 -2
- package/esm/5_client.js +1 -2
- package/esm/client/3_types.d.ts +3 -5
- package/{script/client/5_client.d.ts → esm/client/4_client.d.ts} +17 -4
- package/esm/client/{5_client.js → 4_client.js} +108 -17
- package/esm/types/0_chat_action.d.ts +1 -0
- package/esm/types/0_chat_action.js +1 -0
- package/package.json +1 -1
- package/script/3_types.d.ts +1 -0
- package/script/3_types.js +1 -0
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +1 -2
- package/script/5_client.js +1 -4
- package/script/client/3_types.d.ts +3 -5
- package/{esm/client/5_client.d.ts → script/client/4_client.d.ts} +17 -4
- package/script/client/{5_client.js → 4_client.js} +108 -17
- package/script/types/0_chat_action.d.ts +1 -0
- package/script/types/0_chat_action.js +2 -0
- package/esm/client/4_composer.d.ts +0 -13
- package/esm/client/4_composer.js +0 -83
- package/script/client/4_composer.d.ts +0 -13
- package/script/client/4_composer.js +0 -88
package/esm/3_types.d.ts
CHANGED
package/esm/3_types.js
CHANGED
package/esm/4_constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
|
|
|
5
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
6
6
|
export declare const INITIAL_DC: DC;
|
|
7
7
|
export declare const LAYER = 161;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.0.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.997";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
54
54
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
55
55
|
export const INITIAL_DC = "2-test";
|
|
56
56
|
export const LAYER = 161;
|
|
57
|
-
export const APP_VERSION = "MTKruto 0.0.
|
|
57
|
+
export const APP_VERSION = "MTKruto 0.0.997";
|
|
58
58
|
// @ts-ignore: lib
|
|
59
59
|
export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
60
60
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/5_client.d.ts
CHANGED
package/esm/5_client.js
CHANGED
package/esm/client/3_types.d.ts
CHANGED
|
@@ -196,7 +196,7 @@ export interface SendPollParams {
|
|
|
196
196
|
*/
|
|
197
197
|
protectContent?: boolean;
|
|
198
198
|
}
|
|
199
|
-
export type ConnectionState = "
|
|
199
|
+
export type ConnectionState = "notConnected" | "updating" | "ready";
|
|
200
200
|
export type AuthorizationState = {
|
|
201
201
|
authorized: boolean;
|
|
202
202
|
};
|
|
@@ -211,11 +211,9 @@ export interface Update {
|
|
|
211
211
|
inlineQuery?: InlineQuery;
|
|
212
212
|
}
|
|
213
213
|
export type NextFn = () => Promise<void>;
|
|
214
|
-
export interface
|
|
215
|
-
|
|
214
|
+
export interface Handler<U extends Partial<Update> = Partial<Update>> {
|
|
215
|
+
(update: U, next: NextFn): MaybePromise<void>;
|
|
216
216
|
}
|
|
217
|
-
export type HandlerFn<U extends Partial<Update> = Partial<Update>> = HandlerObj<U>["handle"];
|
|
218
|
-
export type Handler<U extends Partial<Update> = Partial<Update>> = HandlerObj<U> | HandlerFn<U>;
|
|
219
217
|
export type FilterUpdate<U extends Update, T extends keyof U, F extends keyof NonNullable<U[T]>> = With<U, T> & Pick<{
|
|
220
218
|
[P in T]-?: With<NonNullable<U[T]>, F>;
|
|
221
219
|
}, T>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { MaybePromise } from "../1_utilities.js";
|
|
1
2
|
import { functions, ReadObject, types } from "../2_tl.js";
|
|
2
3
|
import { Storage } from "../3_storage.js";
|
|
3
4
|
import { DC } from "../3_transport.js";
|
|
4
|
-
import { Message } from "../3_types.js";
|
|
5
|
+
import { ChatAction, Message } from "../3_types.js";
|
|
5
6
|
import { With } from "./0_utilities.js";
|
|
6
7
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
7
|
-
import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams } from "./3_types.js";
|
|
8
|
+
import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams, Update } from "./3_types.js";
|
|
8
9
|
export declare const getEntity: unique symbol;
|
|
9
10
|
export declare const getStickerSetName: unique symbol;
|
|
10
11
|
export declare const handleMigrationError: unique symbol;
|
|
@@ -186,8 +187,6 @@ export declare class Client extends ClientAbstract {
|
|
|
186
187
|
*/
|
|
187
188
|
getMe(): Promise<import("../3_types.js").User>;
|
|
188
189
|
private handleUpdate;
|
|
189
|
-
private _handler;
|
|
190
|
-
set handler(handler: Handler);
|
|
191
190
|
/**
|
|
192
191
|
* Answer a callback query. Bot-only.
|
|
193
192
|
*
|
|
@@ -204,4 +203,18 @@ export declare class Client extends ClientAbstract {
|
|
|
204
203
|
* @param options The poll's options.
|
|
205
204
|
*/
|
|
206
205
|
sendPoll(chatId: ChatID, question: string, options: [string, string, ...string[]], params?: SendPollParams): Promise<With<Message, "poll">>;
|
|
206
|
+
/**
|
|
207
|
+
* Send a chat action.
|
|
208
|
+
*
|
|
209
|
+
* @param chatId The chat to send the chat action to.
|
|
210
|
+
* @param action The chat action.
|
|
211
|
+
* @param messageThreadId The thread to send the chat action to.
|
|
212
|
+
*/
|
|
213
|
+
sendChatAction(chatId: ChatID, action_: ChatAction, messageThreadId?: number): Promise<void>;
|
|
214
|
+
private handle;
|
|
215
|
+
use(handler: Handler): void;
|
|
216
|
+
branch(predicate: (upd: Update) => MaybePromise<boolean>, trueHandler: Handler, falseHandler: Handler): void;
|
|
217
|
+
filter<D extends Update>(predicate: (ctx: Update) => ctx is D, handler: Handler<D>): void;
|
|
218
|
+
filter(predicate: (ctx: Update) => MaybePromise<boolean>, handler: Handler): void;
|
|
219
|
+
on<T extends keyof Update, F extends keyof NonNullable<Update[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, handler: Handler<FilterUpdate<Update, T, F>>): void;
|
|
207
220
|
}
|
|
@@ -10,7 +10,6 @@ import { checkPassword } from "./0_password.js";
|
|
|
10
10
|
import { parseHtml } from "./0_html.js";
|
|
11
11
|
import { ClientPlain } from "./2_client_plain.js";
|
|
12
12
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
13
|
-
import { call } from "./4_composer.js";
|
|
14
13
|
const d = debug("Client");
|
|
15
14
|
const dGap = debug("Client/recoverUpdateGap");
|
|
16
15
|
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
@@ -153,7 +152,7 @@ export class Client extends ClientAbstract {
|
|
|
153
152
|
value: ((connected) => {
|
|
154
153
|
this.connectMutex.acquire().then(async (release) => {
|
|
155
154
|
try {
|
|
156
|
-
const connectionState = connected ? "ready" : "
|
|
155
|
+
const connectionState = connected ? "ready" : "notConnected";
|
|
157
156
|
if (this.connected == connected && this.lastPropagatedConnectionState != connectionState) {
|
|
158
157
|
await this.propagateConnectionState(connectionState);
|
|
159
158
|
this.lastPropagatedConnectionState = connectionState;
|
|
@@ -213,12 +212,12 @@ export class Client extends ClientAbstract {
|
|
|
213
212
|
writable: true,
|
|
214
213
|
value: new Queue("processUpdates")
|
|
215
214
|
});
|
|
216
|
-
Object.defineProperty(this, "
|
|
215
|
+
Object.defineProperty(this, "handle", {
|
|
217
216
|
enumerable: true,
|
|
218
217
|
configurable: true,
|
|
219
218
|
writable: true,
|
|
220
|
-
value: (
|
|
221
|
-
|
|
219
|
+
value: (_, n) => {
|
|
220
|
+
return n();
|
|
222
221
|
}
|
|
223
222
|
});
|
|
224
223
|
this.parseMode = params?.parseMode ?? "none";
|
|
@@ -232,7 +231,7 @@ export class Client extends ClientAbstract {
|
|
|
232
231
|
this.autoStart = params?.autoStart ?? true;
|
|
233
232
|
}
|
|
234
233
|
propagateConnectionState(connectionState) {
|
|
235
|
-
return this.
|
|
234
|
+
return this.handle({ connectionState }, resolve);
|
|
236
235
|
}
|
|
237
236
|
/**
|
|
238
237
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -359,7 +358,7 @@ export class Client extends ClientAbstract {
|
|
|
359
358
|
}
|
|
360
359
|
async propagateAuthorizationState(authorized) {
|
|
361
360
|
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
362
|
-
await this.
|
|
361
|
+
await this.handle({ authorizationState: { authorized } }, resolve);
|
|
363
362
|
this.lastPropagatedAuthorizationState = authorized;
|
|
364
363
|
}
|
|
365
364
|
}
|
|
@@ -1180,8 +1179,11 @@ export class Client extends ClientAbstract {
|
|
|
1180
1179
|
return messages;
|
|
1181
1180
|
}
|
|
1182
1181
|
async resolveSendAs(params) {
|
|
1183
|
-
|
|
1184
|
-
|
|
1182
|
+
const sendAs = params?.sendAs;
|
|
1183
|
+
if (sendAs !== undefined) {
|
|
1184
|
+
await this.assertUser("sendAs");
|
|
1185
|
+
return sendAs ? await this.getInputPeer(sendAs) : undefined;
|
|
1186
|
+
}
|
|
1185
1187
|
}
|
|
1186
1188
|
/**
|
|
1187
1189
|
* Send a text message.
|
|
@@ -1450,7 +1452,7 @@ export class Client extends ClientAbstract {
|
|
|
1450
1452
|
update instanceof types.UpdateEditChannelMessage) {
|
|
1451
1453
|
const key = update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1452
1454
|
const message = await constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1453
|
-
await this.
|
|
1455
|
+
await this.handle({ [key]: message }, resolve);
|
|
1454
1456
|
}
|
|
1455
1457
|
if (update instanceof types.UpdateDeleteMessages) {
|
|
1456
1458
|
const deletedMessages = new Array();
|
|
@@ -1465,7 +1467,7 @@ export class Client extends ClientAbstract {
|
|
|
1465
1467
|
}
|
|
1466
1468
|
}
|
|
1467
1469
|
if (deletedMessages.length > 0) {
|
|
1468
|
-
await this.
|
|
1470
|
+
await this.handle({ deletedMessages: deletedMessages }, resolve);
|
|
1469
1471
|
}
|
|
1470
1472
|
}
|
|
1471
1473
|
else if (update instanceof types.UpdateDeleteChannelMessages) {
|
|
@@ -1479,19 +1481,16 @@ export class Client extends ClientAbstract {
|
|
|
1479
1481
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1480
1482
|
}
|
|
1481
1483
|
if (deletedMessages.length > 0) {
|
|
1482
|
-
await this.
|
|
1484
|
+
await this.handle({ deletedMessages: deletedMessages }, resolve);
|
|
1483
1485
|
}
|
|
1484
1486
|
}
|
|
1485
1487
|
if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
|
|
1486
|
-
await this.
|
|
1488
|
+
await this.handle({ callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }, resolve);
|
|
1487
1489
|
}
|
|
1488
1490
|
else if (update instanceof types.UpdateBotInlineQuery) {
|
|
1489
|
-
await this.
|
|
1491
|
+
await this.handle({ inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }, resolve);
|
|
1490
1492
|
}
|
|
1491
1493
|
}
|
|
1492
|
-
set handler(handler) {
|
|
1493
|
-
this._handler = call(handler);
|
|
1494
|
-
}
|
|
1495
1494
|
/**
|
|
1496
1495
|
* Answer a callback query. Bot-only.
|
|
1497
1496
|
*
|
|
@@ -1589,4 +1588,96 @@ export class Client extends ClientAbstract {
|
|
|
1589
1588
|
const message = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1590
1589
|
return Client.assertMsgHas(message, "poll");
|
|
1591
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Send a chat action.
|
|
1593
|
+
*
|
|
1594
|
+
* @param chatId The chat to send the chat action to.
|
|
1595
|
+
* @param action The chat action.
|
|
1596
|
+
* @param messageThreadId The thread to send the chat action to.
|
|
1597
|
+
*/
|
|
1598
|
+
async sendChatAction(chatId, action_, messageThreadId) {
|
|
1599
|
+
let action;
|
|
1600
|
+
switch (action_) {
|
|
1601
|
+
case "typing":
|
|
1602
|
+
action = new types.SendMessageTypingAction();
|
|
1603
|
+
break;
|
|
1604
|
+
case "upload_photo":
|
|
1605
|
+
action = new types.SendMessageUploadPhotoAction({ progress: 0 });
|
|
1606
|
+
break;
|
|
1607
|
+
case "record_video":
|
|
1608
|
+
action = new types.SendMessageRecordVideoAction();
|
|
1609
|
+
break;
|
|
1610
|
+
case "upload_video":
|
|
1611
|
+
action = new types.SendMessageRecordVideoAction();
|
|
1612
|
+
break;
|
|
1613
|
+
case "record_voice":
|
|
1614
|
+
action = new types.SendMessageRecordAudioAction();
|
|
1615
|
+
break;
|
|
1616
|
+
case "upload_audio":
|
|
1617
|
+
action = new types.SendMessageUploadAudioAction({ progress: 0 });
|
|
1618
|
+
break;
|
|
1619
|
+
case "upload_document":
|
|
1620
|
+
action = new types.SendMessageUploadDocumentAction({ progress: 0 });
|
|
1621
|
+
break;
|
|
1622
|
+
case "choose_sticker":
|
|
1623
|
+
action = new types.SendMessageChooseStickerAction();
|
|
1624
|
+
break;
|
|
1625
|
+
case "find_location":
|
|
1626
|
+
action = new types.SendMessageGeoLocationAction();
|
|
1627
|
+
break;
|
|
1628
|
+
case "record_video_note":
|
|
1629
|
+
action = new types.SendMessageRecordRoundAction();
|
|
1630
|
+
break;
|
|
1631
|
+
case "upload_video_note":
|
|
1632
|
+
action = new types.SendMessageUploadRoundAction({ progress: 0 });
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
await this.invoke(new functions.MessagesSetTyping({ peer: await this.getInputPeer(chatId), action, topMsgId: messageThreadId }));
|
|
1636
|
+
}
|
|
1637
|
+
use(handler) {
|
|
1638
|
+
const handle = this.handle;
|
|
1639
|
+
this.handle = async (upd, next) => {
|
|
1640
|
+
let called = false;
|
|
1641
|
+
await handle(upd, async () => {
|
|
1642
|
+
if (called)
|
|
1643
|
+
return;
|
|
1644
|
+
called = true;
|
|
1645
|
+
await handler(upd, next);
|
|
1646
|
+
});
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
branch(predicate, trueHandler, falseHandler) {
|
|
1650
|
+
this.use(async (upd, next) => {
|
|
1651
|
+
if (await predicate(upd)) {
|
|
1652
|
+
await trueHandler(upd, next);
|
|
1653
|
+
}
|
|
1654
|
+
else {
|
|
1655
|
+
await falseHandler(upd, next);
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
filter(predicate, handler) {
|
|
1660
|
+
this.branch(predicate, handler, (_, n) => n());
|
|
1661
|
+
}
|
|
1662
|
+
on(filter, handler) {
|
|
1663
|
+
const type = typeof filter === "string" ? filter : filter[0];
|
|
1664
|
+
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
1665
|
+
this.filter((update) => {
|
|
1666
|
+
if (type in update) {
|
|
1667
|
+
if (keys.length > 0) {
|
|
1668
|
+
for (const key of keys) {
|
|
1669
|
+
// deno-lint-ignore ban-ts-comment
|
|
1670
|
+
// @ts-ignore
|
|
1671
|
+
if (!(key in update[type])) {
|
|
1672
|
+
return false;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return true;
|
|
1677
|
+
}
|
|
1678
|
+
else {
|
|
1679
|
+
return false;
|
|
1680
|
+
}
|
|
1681
|
+
}, handler);
|
|
1682
|
+
}
|
|
1592
1683
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ChatAction = "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_audio" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/script/3_types.d.ts
CHANGED
package/script/3_types.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types/!0_file_id.js"), exports);
|
|
18
18
|
__exportStar(require("./types/0_audio.js"), exports);
|
|
19
|
+
__exportStar(require("./types/0_chat_action.js"), exports);
|
|
19
20
|
__exportStar(require("./types/0_chat_administrator_rights.js"), exports);
|
|
20
21
|
__exportStar(require("./types/0_chat_photo.js"), exports);
|
|
21
22
|
__exportStar(require("./types/0_contact.js"), exports);
|
package/script/4_constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
|
|
|
5
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
6
6
|
export declare const INITIAL_DC: DC;
|
|
7
7
|
export declare const LAYER = 161;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.0.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.997";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/script/4_constants.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
80
80
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
81
81
|
exports.INITIAL_DC = "2-test";
|
|
82
82
|
exports.LAYER = 161;
|
|
83
|
-
exports.APP_VERSION = "MTKruto 0.0.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.0.997";
|
|
84
84
|
// @ts-ignore: lib
|
|
85
85
|
exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
86
86
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/script/5_client.d.ts
CHANGED
package/script/5_client.js
CHANGED
|
@@ -14,8 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Composer = void 0;
|
|
18
17
|
__exportStar(require("./client/2_client_plain.js"), exports);
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return _4_composer_js_1.Composer; } });
|
|
21
|
-
__exportStar(require("./client/5_client.js"), exports);
|
|
18
|
+
__exportStar(require("./client/4_client.js"), exports);
|
|
@@ -196,7 +196,7 @@ export interface SendPollParams {
|
|
|
196
196
|
*/
|
|
197
197
|
protectContent?: boolean;
|
|
198
198
|
}
|
|
199
|
-
export type ConnectionState = "
|
|
199
|
+
export type ConnectionState = "notConnected" | "updating" | "ready";
|
|
200
200
|
export type AuthorizationState = {
|
|
201
201
|
authorized: boolean;
|
|
202
202
|
};
|
|
@@ -211,11 +211,9 @@ export interface Update {
|
|
|
211
211
|
inlineQuery?: InlineQuery;
|
|
212
212
|
}
|
|
213
213
|
export type NextFn = () => Promise<void>;
|
|
214
|
-
export interface
|
|
215
|
-
|
|
214
|
+
export interface Handler<U extends Partial<Update> = Partial<Update>> {
|
|
215
|
+
(update: U, next: NextFn): MaybePromise<void>;
|
|
216
216
|
}
|
|
217
|
-
export type HandlerFn<U extends Partial<Update> = Partial<Update>> = HandlerObj<U>["handle"];
|
|
218
|
-
export type Handler<U extends Partial<Update> = Partial<Update>> = HandlerObj<U> | HandlerFn<U>;
|
|
219
217
|
export type FilterUpdate<U extends Update, T extends keyof U, F extends keyof NonNullable<U[T]>> = With<U, T> & Pick<{
|
|
220
218
|
[P in T]-?: With<NonNullable<U[T]>, F>;
|
|
221
219
|
}, T>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { MaybePromise } from "../1_utilities.js";
|
|
1
2
|
import { functions, ReadObject, types } from "../2_tl.js";
|
|
2
3
|
import { Storage } from "../3_storage.js";
|
|
3
4
|
import { DC } from "../3_transport.js";
|
|
4
|
-
import { Message } from "../3_types.js";
|
|
5
|
+
import { ChatAction, Message } from "../3_types.js";
|
|
5
6
|
import { With } from "./0_utilities.js";
|
|
6
7
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
7
|
-
import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams } from "./3_types.js";
|
|
8
|
+
import { AnswerCallbackQueryParams, AuthorizeUserParams, ChatID, ClientParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams, Update } from "./3_types.js";
|
|
8
9
|
export declare const getEntity: unique symbol;
|
|
9
10
|
export declare const getStickerSetName: unique symbol;
|
|
10
11
|
export declare const handleMigrationError: unique symbol;
|
|
@@ -186,8 +187,6 @@ export declare class Client extends ClientAbstract {
|
|
|
186
187
|
*/
|
|
187
188
|
getMe(): Promise<import("../3_types.js").User>;
|
|
188
189
|
private handleUpdate;
|
|
189
|
-
private _handler;
|
|
190
|
-
set handler(handler: Handler);
|
|
191
190
|
/**
|
|
192
191
|
* Answer a callback query. Bot-only.
|
|
193
192
|
*
|
|
@@ -204,4 +203,18 @@ export declare class Client extends ClientAbstract {
|
|
|
204
203
|
* @param options The poll's options.
|
|
205
204
|
*/
|
|
206
205
|
sendPoll(chatId: ChatID, question: string, options: [string, string, ...string[]], params?: SendPollParams): Promise<With<Message, "poll">>;
|
|
206
|
+
/**
|
|
207
|
+
* Send a chat action.
|
|
208
|
+
*
|
|
209
|
+
* @param chatId The chat to send the chat action to.
|
|
210
|
+
* @param action The chat action.
|
|
211
|
+
* @param messageThreadId The thread to send the chat action to.
|
|
212
|
+
*/
|
|
213
|
+
sendChatAction(chatId: ChatID, action_: ChatAction, messageThreadId?: number): Promise<void>;
|
|
214
|
+
private handle;
|
|
215
|
+
use(handler: Handler): void;
|
|
216
|
+
branch(predicate: (upd: Update) => MaybePromise<boolean>, trueHandler: Handler, falseHandler: Handler): void;
|
|
217
|
+
filter<D extends Update>(predicate: (ctx: Update) => ctx is D, handler: Handler<D>): void;
|
|
218
|
+
filter(predicate: (ctx: Update) => MaybePromise<boolean>, handler: Handler): void;
|
|
219
|
+
on<T extends keyof Update, F extends keyof NonNullable<Update[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, handler: Handler<FilterUpdate<Update, T, F>>): void;
|
|
207
220
|
}
|
|
@@ -13,7 +13,6 @@ const _0_password_js_1 = require("./0_password.js");
|
|
|
13
13
|
const _0_html_js_1 = require("./0_html.js");
|
|
14
14
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
15
15
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
16
|
-
const _4_composer_js_1 = require("./4_composer.js");
|
|
17
16
|
const d = (0, _0_deps_js_1.debug)("Client");
|
|
18
17
|
const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
|
|
19
18
|
const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
@@ -156,7 +155,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
156
155
|
value: ((connected) => {
|
|
157
156
|
this.connectMutex.acquire().then(async (release) => {
|
|
158
157
|
try {
|
|
159
|
-
const connectionState = connected ? "ready" : "
|
|
158
|
+
const connectionState = connected ? "ready" : "notConnected";
|
|
160
159
|
if (this.connected == connected && this.lastPropagatedConnectionState != connectionState) {
|
|
161
160
|
await this.propagateConnectionState(connectionState);
|
|
162
161
|
this.lastPropagatedConnectionState = connectionState;
|
|
@@ -216,12 +215,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
216
215
|
writable: true,
|
|
217
216
|
value: new _1_utilities_js_1.Queue("processUpdates")
|
|
218
217
|
});
|
|
219
|
-
Object.defineProperty(this, "
|
|
218
|
+
Object.defineProperty(this, "handle", {
|
|
220
219
|
enumerable: true,
|
|
221
220
|
configurable: true,
|
|
222
221
|
writable: true,
|
|
223
|
-
value: (
|
|
224
|
-
|
|
222
|
+
value: (_, n) => {
|
|
223
|
+
return n();
|
|
225
224
|
}
|
|
226
225
|
});
|
|
227
226
|
this.parseMode = params?.parseMode ?? "none";
|
|
@@ -235,7 +234,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
235
234
|
this.autoStart = params?.autoStart ?? true;
|
|
236
235
|
}
|
|
237
236
|
propagateConnectionState(connectionState) {
|
|
238
|
-
return this.
|
|
237
|
+
return this.handle({ connectionState }, _0_utilities_js_1.resolve);
|
|
239
238
|
}
|
|
240
239
|
/**
|
|
241
240
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -362,7 +361,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
362
361
|
}
|
|
363
362
|
async propagateAuthorizationState(authorized) {
|
|
364
363
|
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
365
|
-
await this.
|
|
364
|
+
await this.handle({ authorizationState: { authorized } }, _0_utilities_js_1.resolve);
|
|
366
365
|
this.lastPropagatedAuthorizationState = authorized;
|
|
367
366
|
}
|
|
368
367
|
}
|
|
@@ -1183,8 +1182,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1183
1182
|
return messages;
|
|
1184
1183
|
}
|
|
1185
1184
|
async resolveSendAs(params) {
|
|
1186
|
-
|
|
1187
|
-
|
|
1185
|
+
const sendAs = params?.sendAs;
|
|
1186
|
+
if (sendAs !== undefined) {
|
|
1187
|
+
await this.assertUser("sendAs");
|
|
1188
|
+
return sendAs ? await this.getInputPeer(sendAs) : undefined;
|
|
1189
|
+
}
|
|
1188
1190
|
}
|
|
1189
1191
|
/**
|
|
1190
1192
|
* Send a text message.
|
|
@@ -1453,7 +1455,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1453
1455
|
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1454
1456
|
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1455
1457
|
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1456
|
-
await this.
|
|
1458
|
+
await this.handle({ [key]: message }, _0_utilities_js_1.resolve);
|
|
1457
1459
|
}
|
|
1458
1460
|
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
1459
1461
|
const deletedMessages = new Array();
|
|
@@ -1468,7 +1470,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1468
1470
|
}
|
|
1469
1471
|
}
|
|
1470
1472
|
if (deletedMessages.length > 0) {
|
|
1471
|
-
await this.
|
|
1473
|
+
await this.handle({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1472
1474
|
}
|
|
1473
1475
|
}
|
|
1474
1476
|
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
@@ -1482,19 +1484,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1482
1484
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1483
1485
|
}
|
|
1484
1486
|
if (deletedMessages.length > 0) {
|
|
1485
|
-
await this.
|
|
1487
|
+
await this.handle({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1486
1488
|
}
|
|
1487
1489
|
}
|
|
1488
1490
|
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
1489
|
-
await this.
|
|
1491
|
+
await this.handle({ callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[exports.getEntity].bind(this), this[exports.getMessageWithReply].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1490
1492
|
}
|
|
1491
1493
|
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
1492
|
-
await this.
|
|
1494
|
+
await this.handle({ inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[exports.getEntity].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1493
1495
|
}
|
|
1494
1496
|
}
|
|
1495
|
-
set handler(handler) {
|
|
1496
|
-
this._handler = (0, _4_composer_js_1.call)(handler);
|
|
1497
|
-
}
|
|
1498
1497
|
/**
|
|
1499
1498
|
* Answer a callback query. Bot-only.
|
|
1500
1499
|
*
|
|
@@ -1592,5 +1591,97 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1592
1591
|
const message = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1593
1592
|
return Client.assertMsgHas(message, "poll");
|
|
1594
1593
|
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Send a chat action.
|
|
1596
|
+
*
|
|
1597
|
+
* @param chatId The chat to send the chat action to.
|
|
1598
|
+
* @param action The chat action.
|
|
1599
|
+
* @param messageThreadId The thread to send the chat action to.
|
|
1600
|
+
*/
|
|
1601
|
+
async sendChatAction(chatId, action_, messageThreadId) {
|
|
1602
|
+
let action;
|
|
1603
|
+
switch (action_) {
|
|
1604
|
+
case "typing":
|
|
1605
|
+
action = new _2_tl_js_1.types.SendMessageTypingAction();
|
|
1606
|
+
break;
|
|
1607
|
+
case "upload_photo":
|
|
1608
|
+
action = new _2_tl_js_1.types.SendMessageUploadPhotoAction({ progress: 0 });
|
|
1609
|
+
break;
|
|
1610
|
+
case "record_video":
|
|
1611
|
+
action = new _2_tl_js_1.types.SendMessageRecordVideoAction();
|
|
1612
|
+
break;
|
|
1613
|
+
case "upload_video":
|
|
1614
|
+
action = new _2_tl_js_1.types.SendMessageRecordVideoAction();
|
|
1615
|
+
break;
|
|
1616
|
+
case "record_voice":
|
|
1617
|
+
action = new _2_tl_js_1.types.SendMessageRecordAudioAction();
|
|
1618
|
+
break;
|
|
1619
|
+
case "upload_audio":
|
|
1620
|
+
action = new _2_tl_js_1.types.SendMessageUploadAudioAction({ progress: 0 });
|
|
1621
|
+
break;
|
|
1622
|
+
case "upload_document":
|
|
1623
|
+
action = new _2_tl_js_1.types.SendMessageUploadDocumentAction({ progress: 0 });
|
|
1624
|
+
break;
|
|
1625
|
+
case "choose_sticker":
|
|
1626
|
+
action = new _2_tl_js_1.types.SendMessageChooseStickerAction();
|
|
1627
|
+
break;
|
|
1628
|
+
case "find_location":
|
|
1629
|
+
action = new _2_tl_js_1.types.SendMessageGeoLocationAction();
|
|
1630
|
+
break;
|
|
1631
|
+
case "record_video_note":
|
|
1632
|
+
action = new _2_tl_js_1.types.SendMessageRecordRoundAction();
|
|
1633
|
+
break;
|
|
1634
|
+
case "upload_video_note":
|
|
1635
|
+
action = new _2_tl_js_1.types.SendMessageUploadRoundAction({ progress: 0 });
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
await this.invoke(new _2_tl_js_1.functions.MessagesSetTyping({ peer: await this.getInputPeer(chatId), action, topMsgId: messageThreadId }));
|
|
1639
|
+
}
|
|
1640
|
+
use(handler) {
|
|
1641
|
+
const handle = this.handle;
|
|
1642
|
+
this.handle = async (upd, next) => {
|
|
1643
|
+
let called = false;
|
|
1644
|
+
await handle(upd, async () => {
|
|
1645
|
+
if (called)
|
|
1646
|
+
return;
|
|
1647
|
+
called = true;
|
|
1648
|
+
await handler(upd, next);
|
|
1649
|
+
});
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
branch(predicate, trueHandler, falseHandler) {
|
|
1653
|
+
this.use(async (upd, next) => {
|
|
1654
|
+
if (await predicate(upd)) {
|
|
1655
|
+
await trueHandler(upd, next);
|
|
1656
|
+
}
|
|
1657
|
+
else {
|
|
1658
|
+
await falseHandler(upd, next);
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
filter(predicate, handler) {
|
|
1663
|
+
this.branch(predicate, handler, (_, n) => n());
|
|
1664
|
+
}
|
|
1665
|
+
on(filter, handler) {
|
|
1666
|
+
const type = typeof filter === "string" ? filter : filter[0];
|
|
1667
|
+
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
1668
|
+
this.filter((update) => {
|
|
1669
|
+
if (type in update) {
|
|
1670
|
+
if (keys.length > 0) {
|
|
1671
|
+
for (const key of keys) {
|
|
1672
|
+
// deno-lint-ignore ban-ts-comment
|
|
1673
|
+
// @ts-ignore
|
|
1674
|
+
if (!(key in update[type])) {
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return true;
|
|
1680
|
+
}
|
|
1681
|
+
else {
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
}, handler);
|
|
1685
|
+
}
|
|
1595
1686
|
}
|
|
1596
1687
|
exports.Client = Client;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ChatAction = "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_audio" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MaybePromise } from "../1_utilities.js";
|
|
2
|
-
import { FilterableUpdates, FilterUpdate, Handler, HandlerFn, HandlerObj, Update } from "./3_types.js";
|
|
3
|
-
export declare function call(handler: Handler): HandlerFn;
|
|
4
|
-
export declare class Composer<U extends Update = Update> implements HandlerObj<U> {
|
|
5
|
-
constructor(...handlers: Handler<U>[]);
|
|
6
|
-
get handle(): HandlerFn;
|
|
7
|
-
private _handle;
|
|
8
|
-
use(...handlers: Handler<U>[]): this;
|
|
9
|
-
branch(predicate: (upd: U) => MaybePromise<boolean>, trueHandler: Handler<U>, falseHandler: Handler<U>): this;
|
|
10
|
-
filter<D extends U>(predicate: (ctx: U) => ctx is D, ...middleware: Handler<D>[]): Composer<D>;
|
|
11
|
-
filter(predicate: (ctx: U) => MaybePromise<boolean>, ...middleware: Handler<U>[]): Composer<U>;
|
|
12
|
-
on<T extends keyof U, F extends keyof NonNullable<U[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...handlers: Handler<FilterUpdate<U, T, F>>[]): Composer<FilterUpdate<U, T, F>>;
|
|
13
|
-
}
|
package/esm/client/4_composer.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { resolve } from "./0_utilities.js";
|
|
2
|
-
export function call(handler) {
|
|
3
|
-
if ("handle" in handler) {
|
|
4
|
-
return handler.handle;
|
|
5
|
-
}
|
|
6
|
-
else {
|
|
7
|
-
return handler;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function concat(what, with_) {
|
|
11
|
-
return async (upd, next) => {
|
|
12
|
-
let called = false;
|
|
13
|
-
await call(what)(upd, async () => {
|
|
14
|
-
if (called)
|
|
15
|
-
return;
|
|
16
|
-
called = true;
|
|
17
|
-
await call(with_)(upd, next);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function reduce(...handlers) {
|
|
22
|
-
if (handlers.length == 0) {
|
|
23
|
-
return resolve;
|
|
24
|
-
}
|
|
25
|
-
return handlers.reduce((a, b) => concat(a, b));
|
|
26
|
-
}
|
|
27
|
-
export class Composer {
|
|
28
|
-
constructor(...handlers) {
|
|
29
|
-
Object.defineProperty(this, "_handle", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: resolve
|
|
34
|
-
});
|
|
35
|
-
this.use(...handlers);
|
|
36
|
-
}
|
|
37
|
-
get handle() {
|
|
38
|
-
return this._handle;
|
|
39
|
-
}
|
|
40
|
-
use(...handlers) {
|
|
41
|
-
const handle = this.handle;
|
|
42
|
-
this._handle = concat(handle, reduce(...handlers));
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
branch(predicate, trueHandler, falseHandler) {
|
|
46
|
-
return this.use(async (upd, next) => {
|
|
47
|
-
if (await predicate(upd)) {
|
|
48
|
-
await call(trueHandler)(upd, next);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
await call(falseHandler)(upd, next);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
filter(predicate, ...middleware) {
|
|
56
|
-
const composer = new Composer(...middleware);
|
|
57
|
-
this.branch(predicate, composer, resolve);
|
|
58
|
-
return composer;
|
|
59
|
-
}
|
|
60
|
-
on(filter, ...handlers) {
|
|
61
|
-
// deno-lint-ignore ban-ts-comment
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
const type = typeof filter === "string" ? filter : filter[0];
|
|
64
|
-
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
65
|
-
return this.filter((update) => {
|
|
66
|
-
if (type in update) {
|
|
67
|
-
if (keys.length > 0) {
|
|
68
|
-
for (const key of keys) {
|
|
69
|
-
// deno-lint-ignore ban-ts-comment
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
if (!(key in update[type])) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}, ...handlers);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MaybePromise } from "../1_utilities.js";
|
|
2
|
-
import { FilterableUpdates, FilterUpdate, Handler, HandlerFn, HandlerObj, Update } from "./3_types.js";
|
|
3
|
-
export declare function call(handler: Handler): HandlerFn;
|
|
4
|
-
export declare class Composer<U extends Update = Update> implements HandlerObj<U> {
|
|
5
|
-
constructor(...handlers: Handler<U>[]);
|
|
6
|
-
get handle(): HandlerFn;
|
|
7
|
-
private _handle;
|
|
8
|
-
use(...handlers: Handler<U>[]): this;
|
|
9
|
-
branch(predicate: (upd: U) => MaybePromise<boolean>, trueHandler: Handler<U>, falseHandler: Handler<U>): this;
|
|
10
|
-
filter<D extends U>(predicate: (ctx: U) => ctx is D, ...middleware: Handler<D>[]): Composer<D>;
|
|
11
|
-
filter(predicate: (ctx: U) => MaybePromise<boolean>, ...middleware: Handler<U>[]): Composer<U>;
|
|
12
|
-
on<T extends keyof U, F extends keyof NonNullable<U[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...handlers: Handler<FilterUpdate<U, T, F>>[]): Composer<FilterUpdate<U, T, F>>;
|
|
13
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Composer = exports.call = void 0;
|
|
4
|
-
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
5
|
-
function call(handler) {
|
|
6
|
-
if ("handle" in handler) {
|
|
7
|
-
return handler.handle;
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return handler;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.call = call;
|
|
14
|
-
function concat(what, with_) {
|
|
15
|
-
return async (upd, next) => {
|
|
16
|
-
let called = false;
|
|
17
|
-
await call(what)(upd, async () => {
|
|
18
|
-
if (called)
|
|
19
|
-
return;
|
|
20
|
-
called = true;
|
|
21
|
-
await call(with_)(upd, next);
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function reduce(...handlers) {
|
|
26
|
-
if (handlers.length == 0) {
|
|
27
|
-
return _0_utilities_js_1.resolve;
|
|
28
|
-
}
|
|
29
|
-
return handlers.reduce((a, b) => concat(a, b));
|
|
30
|
-
}
|
|
31
|
-
class Composer {
|
|
32
|
-
constructor(...handlers) {
|
|
33
|
-
Object.defineProperty(this, "_handle", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: _0_utilities_js_1.resolve
|
|
38
|
-
});
|
|
39
|
-
this.use(...handlers);
|
|
40
|
-
}
|
|
41
|
-
get handle() {
|
|
42
|
-
return this._handle;
|
|
43
|
-
}
|
|
44
|
-
use(...handlers) {
|
|
45
|
-
const handle = this.handle;
|
|
46
|
-
this._handle = concat(handle, reduce(...handlers));
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
branch(predicate, trueHandler, falseHandler) {
|
|
50
|
-
return this.use(async (upd, next) => {
|
|
51
|
-
if (await predicate(upd)) {
|
|
52
|
-
await call(trueHandler)(upd, next);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
await call(falseHandler)(upd, next);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
filter(predicate, ...middleware) {
|
|
60
|
-
const composer = new Composer(...middleware);
|
|
61
|
-
this.branch(predicate, composer, _0_utilities_js_1.resolve);
|
|
62
|
-
return composer;
|
|
63
|
-
}
|
|
64
|
-
on(filter, ...handlers) {
|
|
65
|
-
// deno-lint-ignore ban-ts-comment
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
const type = typeof filter === "string" ? filter : filter[0];
|
|
68
|
-
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
69
|
-
return this.filter((update) => {
|
|
70
|
-
if (type in update) {
|
|
71
|
-
if (keys.length > 0) {
|
|
72
|
-
for (const key of keys) {
|
|
73
|
-
// deno-lint-ignore ban-ts-comment
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
if (!(key in update[type])) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}, ...handlers);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.Composer = Composer;
|