@fragno-dev/telegram-fragment 0.0.1 → 0.0.3

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 (48) hide show
  1. package/dist/browser/client/react.d.ts +129 -3
  2. package/dist/browser/client/react.d.ts.map +1 -1
  3. package/dist/browser/client/react.js +32 -22
  4. package/dist/browser/client/react.js.map +1 -1
  5. package/dist/browser/client/solid.d.ts +129 -3
  6. package/dist/browser/client/solid.d.ts.map +1 -1
  7. package/dist/browser/client/solid.js +2 -2
  8. package/dist/browser/client/solid.js.map +1 -1
  9. package/dist/browser/client/svelte.d.ts +129 -3
  10. package/dist/browser/client/svelte.d.ts.map +1 -1
  11. package/dist/browser/client/svelte.js +1 -1
  12. package/dist/browser/client/vanilla.d.ts +129 -3
  13. package/dist/browser/client/vanilla.d.ts.map +1 -1
  14. package/dist/browser/client/vanilla.js +1 -1
  15. package/dist/browser/client/vue.d.ts +129 -3
  16. package/dist/browser/client/vue.d.ts.map +1 -1
  17. package/dist/browser/client/vue.js +1 -1
  18. package/dist/browser/{client-Bk-J98pf.d.ts → client-BumUy6cu.d.ts} +87 -83
  19. package/dist/browser/client-BumUy6cu.d.ts.map +1 -0
  20. package/dist/browser/index.d.ts +697 -48
  21. package/dist/browser/index.d.ts.map +1 -1
  22. package/dist/browser/index.js +2 -2
  23. package/dist/browser/index.js.map +1 -1
  24. package/dist/browser/{schema-QDMf15Vn.js → schema-IrJsGm4M.js} +264 -41
  25. package/dist/browser/schema-IrJsGm4M.js.map +1 -0
  26. package/dist/node/definition.d.ts.map +1 -1
  27. package/dist/node/index.d.ts +260 -13
  28. package/dist/node/index.d.ts.map +1 -1
  29. package/dist/node/index.js +2 -2
  30. package/dist/node/index.js.map +1 -1
  31. package/dist/node/routes.d.ts +130 -9
  32. package/dist/node/routes.d.ts.map +1 -1
  33. package/dist/node/routes.js +25 -15
  34. package/dist/node/routes.js.map +1 -1
  35. package/dist/node/services.js +56 -53
  36. package/dist/node/services.js.map +1 -1
  37. package/dist/node/telegram-api.js +80 -16
  38. package/dist/node/telegram-api.js.map +1 -1
  39. package/dist/node/telegram-utils.js +284 -9
  40. package/dist/node/telegram-utils.js.map +1 -1
  41. package/dist/node/types.d.ts +308 -27
  42. package/dist/node/types.d.ts.map +1 -1
  43. package/dist/node/types.js +232 -27
  44. package/dist/node/types.js.map +1 -1
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +13 -8
  47. package/dist/browser/client-Bk-J98pf.d.ts.map +0 -1
  48. package/dist/browser/schema-QDMf15Vn.js.map +0 -1
@@ -1,55 +1,260 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/types.ts
4
+ const telegramIntegerSchema = z.number().int();
4
5
  const telegramChatTypeSchema = z.enum([
5
6
  "private",
6
7
  "group",
7
8
  "supergroup",
8
9
  "channel"
9
10
  ]);
11
+ const telegramPhotoSizeSchema = z.object({
12
+ fileId: z.string(),
13
+ fileUniqueId: z.string(),
14
+ width: telegramIntegerSchema,
15
+ height: telegramIntegerSchema,
16
+ fileSize: telegramIntegerSchema.optional()
17
+ });
18
+ const telegramVoiceSchema = z.object({
19
+ fileId: z.string(),
20
+ fileUniqueId: z.string(),
21
+ duration: telegramIntegerSchema,
22
+ mimeType: z.string().optional(),
23
+ fileSize: telegramIntegerSchema.optional()
24
+ });
25
+ const telegramAudioSchema = z.object({
26
+ fileId: z.string(),
27
+ fileUniqueId: z.string(),
28
+ duration: telegramIntegerSchema,
29
+ performer: z.string().optional(),
30
+ title: z.string().optional(),
31
+ fileName: z.string().optional(),
32
+ mimeType: z.string().optional(),
33
+ fileSize: telegramIntegerSchema.optional(),
34
+ thumbnail: telegramPhotoSizeSchema.optional()
35
+ });
36
+ const telegramDocumentSchema = z.object({
37
+ fileId: z.string(),
38
+ fileUniqueId: z.string(),
39
+ fileName: z.string().optional(),
40
+ mimeType: z.string().optional(),
41
+ fileSize: telegramIntegerSchema.optional(),
42
+ thumbnail: telegramPhotoSizeSchema.optional()
43
+ });
44
+ const telegramVideoSchema = z.object({
45
+ fileId: z.string(),
46
+ fileUniqueId: z.string(),
47
+ width: telegramIntegerSchema,
48
+ height: telegramIntegerSchema,
49
+ duration: telegramIntegerSchema,
50
+ fileName: z.string().optional(),
51
+ mimeType: z.string().optional(),
52
+ fileSize: telegramIntegerSchema.optional(),
53
+ thumbnail: telegramPhotoSizeSchema.optional()
54
+ });
55
+ const telegramVideoNoteSchema = z.object({
56
+ fileId: z.string(),
57
+ fileUniqueId: z.string(),
58
+ length: telegramIntegerSchema,
59
+ duration: telegramIntegerSchema,
60
+ fileSize: telegramIntegerSchema.optional(),
61
+ thumbnail: telegramPhotoSizeSchema.optional()
62
+ });
63
+ const telegramStickerTypeSchema = z.enum([
64
+ "regular",
65
+ "mask",
66
+ "custom_emoji"
67
+ ]);
68
+ const telegramStickerSchema = z.object({
69
+ fileId: z.string(),
70
+ fileUniqueId: z.string(),
71
+ type: telegramStickerTypeSchema,
72
+ width: telegramIntegerSchema,
73
+ height: telegramIntegerSchema,
74
+ isAnimated: z.boolean(),
75
+ isVideo: z.boolean(),
76
+ thumbnail: telegramPhotoSizeSchema.optional(),
77
+ emoji: z.string().optional(),
78
+ setName: z.string().optional(),
79
+ fileSize: telegramIntegerSchema.optional()
80
+ });
81
+ const telegramAnimationSchema = z.object({
82
+ fileId: z.string(),
83
+ fileUniqueId: z.string(),
84
+ width: telegramIntegerSchema,
85
+ height: telegramIntegerSchema,
86
+ duration: telegramIntegerSchema,
87
+ fileName: z.string().optional(),
88
+ mimeType: z.string().optional(),
89
+ fileSize: telegramIntegerSchema.optional(),
90
+ thumbnail: telegramPhotoSizeSchema.optional()
91
+ });
92
+ const telegramAttachmentKindSchema = z.enum([
93
+ "photo",
94
+ "voice",
95
+ "audio",
96
+ "document",
97
+ "video",
98
+ "video_note",
99
+ "sticker",
100
+ "animation"
101
+ ]);
102
+ const telegramAttachmentPhotoSizeSchema = z.object({
103
+ fileId: z.string(),
104
+ fileUniqueId: z.string(),
105
+ fileSize: telegramIntegerSchema.optional(),
106
+ width: telegramIntegerSchema,
107
+ height: telegramIntegerSchema
108
+ });
109
+ const telegramPhotoAttachmentSchema = z.object({
110
+ kind: z.literal("photo"),
111
+ fileId: z.string(),
112
+ fileUniqueId: z.string(),
113
+ fileSize: telegramIntegerSchema.optional(),
114
+ width: telegramIntegerSchema,
115
+ height: telegramIntegerSchema,
116
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional(),
117
+ sizes: z.array(telegramAttachmentPhotoSizeSchema).min(1)
118
+ });
119
+ const telegramVoiceAttachmentSchema = z.object({
120
+ kind: z.literal("voice"),
121
+ fileId: z.string(),
122
+ fileUniqueId: z.string(),
123
+ fileSize: telegramIntegerSchema.optional(),
124
+ duration: telegramIntegerSchema,
125
+ mimeType: z.string().optional()
126
+ });
127
+ const telegramAudioAttachmentSchema = z.object({
128
+ kind: z.literal("audio"),
129
+ fileId: z.string(),
130
+ fileUniqueId: z.string(),
131
+ fileSize: telegramIntegerSchema.optional(),
132
+ duration: telegramIntegerSchema,
133
+ performer: z.string().optional(),
134
+ title: z.string().optional(),
135
+ fileName: z.string().optional(),
136
+ mimeType: z.string().optional(),
137
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
138
+ });
139
+ const telegramDocumentAttachmentSchema = z.object({
140
+ kind: z.literal("document"),
141
+ fileId: z.string(),
142
+ fileUniqueId: z.string(),
143
+ fileSize: telegramIntegerSchema.optional(),
144
+ fileName: z.string().optional(),
145
+ mimeType: z.string().optional(),
146
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
147
+ });
148
+ const telegramVideoAttachmentSchema = z.object({
149
+ kind: z.literal("video"),
150
+ fileId: z.string(),
151
+ fileUniqueId: z.string(),
152
+ fileSize: telegramIntegerSchema.optional(),
153
+ width: telegramIntegerSchema,
154
+ height: telegramIntegerSchema,
155
+ duration: telegramIntegerSchema,
156
+ fileName: z.string().optional(),
157
+ mimeType: z.string().optional(),
158
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
159
+ });
160
+ const telegramVideoNoteAttachmentSchema = z.object({
161
+ kind: z.literal("video_note"),
162
+ fileId: z.string(),
163
+ fileUniqueId: z.string(),
164
+ fileSize: telegramIntegerSchema.optional(),
165
+ length: telegramIntegerSchema,
166
+ duration: telegramIntegerSchema,
167
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
168
+ });
169
+ const telegramStickerAttachmentSchema = z.object({
170
+ kind: z.literal("sticker"),
171
+ fileId: z.string(),
172
+ fileUniqueId: z.string(),
173
+ fileSize: telegramIntegerSchema.optional(),
174
+ width: telegramIntegerSchema,
175
+ height: telegramIntegerSchema,
176
+ emoji: z.string().optional(),
177
+ setName: z.string().optional(),
178
+ isAnimated: z.boolean(),
179
+ isVideo: z.boolean(),
180
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
181
+ });
182
+ const telegramAnimationAttachmentSchema = z.object({
183
+ kind: z.literal("animation"),
184
+ fileId: z.string(),
185
+ fileUniqueId: z.string(),
186
+ fileSize: telegramIntegerSchema.optional(),
187
+ width: telegramIntegerSchema,
188
+ height: telegramIntegerSchema,
189
+ duration: telegramIntegerSchema,
190
+ fileName: z.string().optional(),
191
+ mimeType: z.string().optional(),
192
+ thumbnail: telegramAttachmentPhotoSizeSchema.optional()
193
+ });
194
+ const telegramAttachmentSchema = z.discriminatedUnion("kind", [
195
+ telegramPhotoAttachmentSchema,
196
+ telegramVoiceAttachmentSchema,
197
+ telegramAudioAttachmentSchema,
198
+ telegramDocumentAttachmentSchema,
199
+ telegramVideoAttachmentSchema,
200
+ telegramVideoNoteAttachmentSchema,
201
+ telegramStickerAttachmentSchema,
202
+ telegramAnimationAttachmentSchema
203
+ ]);
10
204
  const telegramMessageEntitySchema = z.object({
11
205
  type: z.string(),
12
- offset: z.number(),
13
- length: z.number()
14
- }).loose();
206
+ offset: telegramIntegerSchema,
207
+ length: telegramIntegerSchema
208
+ });
15
209
  const telegramUserSchema = z.object({
16
- id: z.number(),
17
- is_bot: z.boolean().optional(),
18
- first_name: z.string(),
19
- last_name: z.string().optional(),
210
+ id: telegramIntegerSchema,
211
+ isBot: z.boolean(),
212
+ firstName: z.string(),
213
+ lastName: z.string().optional(),
20
214
  username: z.string().optional(),
21
- language_code: z.string().optional()
22
- }).loose();
215
+ languageCode: z.string().optional()
216
+ });
23
217
  const telegramChatSchema = z.object({
24
- id: z.number(),
218
+ id: telegramIntegerSchema,
25
219
  type: telegramChatTypeSchema,
26
220
  title: z.string().optional(),
27
221
  username: z.string().optional(),
28
- is_forum: z.boolean().optional()
29
- }).loose();
222
+ firstName: z.string().optional(),
223
+ lastName: z.string().optional(),
224
+ isForum: z.boolean().optional()
225
+ });
30
226
  const telegramMessageSchema = z.lazy(() => z.object({
31
- message_id: z.number(),
32
- date: z.number(),
33
- edit_date: z.number().optional(),
227
+ messageId: telegramIntegerSchema,
228
+ date: telegramIntegerSchema,
229
+ editDate: telegramIntegerSchema.optional(),
34
230
  text: z.string().optional(),
35
231
  from: telegramUserSchema.optional(),
36
- sender_chat: telegramChatSchema.optional(),
232
+ senderChat: telegramChatSchema.optional(),
37
233
  chat: telegramChatSchema,
38
- reply_to_message: telegramMessageSchema.optional(),
39
- new_chat_members: z.array(telegramUserSchema).optional(),
40
- left_chat_member: telegramUserSchema.optional(),
41
- entities: z.array(telegramMessageEntitySchema).optional()
42
- }).loose());
234
+ replyToMessage: telegramMessageSchema.optional(),
235
+ newChatMembers: z.array(telegramUserSchema).optional(),
236
+ leftChatMember: telegramUserSchema.optional(),
237
+ entities: z.array(telegramMessageEntitySchema).optional(),
238
+ mediaGroupId: z.string().optional(),
239
+ photo: z.array(telegramPhotoSizeSchema).optional(),
240
+ voice: telegramVoiceSchema.optional(),
241
+ audio: telegramAudioSchema.optional(),
242
+ document: telegramDocumentSchema.optional(),
243
+ video: telegramVideoSchema.optional(),
244
+ videoNote: telegramVideoNoteSchema.optional(),
245
+ sticker: telegramStickerSchema.optional(),
246
+ animation: telegramAnimationSchema.optional()
247
+ }));
43
248
  const telegramUpdateSchema = z.object({
44
- update_id: z.number(),
249
+ updateId: telegramIntegerSchema,
45
250
  message: telegramMessageSchema.optional(),
46
- edited_message: telegramMessageSchema.optional(),
47
- channel_post: telegramMessageSchema.optional()
48
- }).loose();
251
+ editedMessage: telegramMessageSchema.optional(),
252
+ channelPost: telegramMessageSchema.optional()
253
+ });
49
254
  const telegramCommandBindingSchema = z.object({
50
255
  enabled: z.boolean().optional(),
51
256
  scopes: z.array(telegramChatTypeSchema).optional()
52
- }).loose();
257
+ });
53
258
  const telegramCommandBindingsSchema = z.record(z.string(), telegramCommandBindingSchema);
54
259
  function defineCommand(name, definition) {
55
260
  return {
@@ -88,5 +293,5 @@ function createTelegram(baseConfig = {}) {
88
293
  }
89
294
 
90
295
  //#endregion
91
- export { createTelegram, defineCommand, telegramChatTypeSchema, telegramCommandBindingsSchema, telegramMessageSchema, telegramUpdateSchema };
296
+ export { createTelegram, defineCommand, telegramAnimationSchema, telegramAttachmentKindSchema, telegramAttachmentSchema, telegramAudioSchema, telegramChatSchema, telegramChatTypeSchema, telegramCommandBindingsSchema, telegramDocumentSchema, telegramMessageEntitySchema, telegramMessageSchema, telegramPhotoSizeSchema, telegramStickerSchema, telegramUpdateSchema, telegramUserSchema, telegramVideoNoteSchema, telegramVideoSchema, telegramVoiceSchema };
92
297
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { HookFn, HookHandlerTx } from \"@fragno-dev/db\";\n\nexport const telegramChatTypeSchema = z.enum([\"private\", \"group\", \"supergroup\", \"channel\"]);\nexport type TelegramChatType = z.infer<typeof telegramChatTypeSchema>;\nexport type TelegramCommandScope = TelegramChatType;\n\nexport const telegramMessageEntitySchema = z\n .object({\n type: z.string(),\n offset: z.number(),\n length: z.number(),\n })\n .loose();\nexport type TelegramMessageEntity = z.infer<typeof telegramMessageEntitySchema>;\n\nexport const telegramUserSchema = z\n .object({\n id: z.number(),\n is_bot: z.boolean().optional(),\n first_name: z.string(),\n last_name: z.string().optional(),\n username: z.string().optional(),\n language_code: z.string().optional(),\n })\n .loose();\nexport type TelegramUser = z.infer<typeof telegramUserSchema>;\n\nexport const telegramChatSchema = z\n .object({\n id: z.number(),\n type: telegramChatTypeSchema,\n title: z.string().optional(),\n username: z.string().optional(),\n is_forum: z.boolean().optional(),\n })\n .loose();\nexport type TelegramChat = z.infer<typeof telegramChatSchema>;\n\nexport interface TelegramMessage {\n message_id: number;\n date: number;\n edit_date?: number;\n text?: string;\n from?: TelegramUser;\n sender_chat?: TelegramChat;\n chat: TelegramChat;\n reply_to_message?: TelegramMessage;\n new_chat_members?: TelegramUser[];\n left_chat_member?: TelegramUser;\n entities?: TelegramMessageEntity[];\n [key: string]: unknown;\n}\n\nexport const telegramMessageSchema: z.ZodType<TelegramMessage> = z.lazy(() =>\n z\n .object({\n message_id: z.number(),\n date: z.number(),\n edit_date: z.number().optional(),\n text: z.string().optional(),\n from: telegramUserSchema.optional(),\n sender_chat: telegramChatSchema.optional(),\n chat: telegramChatSchema,\n reply_to_message: telegramMessageSchema.optional(),\n new_chat_members: z.array(telegramUserSchema).optional(),\n left_chat_member: telegramUserSchema.optional(),\n entities: z.array(telegramMessageEntitySchema).optional(),\n })\n .loose(),\n);\n\nexport const telegramUpdateSchema = z\n .object({\n update_id: z.number(),\n message: telegramMessageSchema.optional(),\n edited_message: telegramMessageSchema.optional(),\n channel_post: telegramMessageSchema.optional(),\n })\n .loose();\nexport type TelegramUpdate = z.infer<typeof telegramUpdateSchema>;\n\nexport type TelegramUpdateType = \"message\" | \"edited_message\" | \"channel_post\";\n\nexport const telegramCommandBindingSchema = z\n .object({\n enabled: z.boolean().optional(),\n scopes: z.array(telegramChatTypeSchema).optional(),\n })\n .loose();\nexport type TelegramCommandBinding = z.infer<typeof telegramCommandBindingSchema>;\n\nexport const telegramCommandBindingsSchema = z.record(z.string(), telegramCommandBindingSchema);\nexport type TelegramCommandBindings = z.infer<typeof telegramCommandBindingsSchema>;\n\nexport interface TelegramUserSummary {\n id: string;\n username: string | null;\n firstName: string;\n lastName: string | null;\n isBot: boolean;\n languageCode: string | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramChatSummary {\n id: string;\n type: TelegramChatType;\n title: string | null;\n username: string | null;\n isForum: boolean;\n commandBindings: TelegramCommandBindings | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramChatMemberSummary {\n id: string;\n chatId: string;\n userId: string;\n status: string;\n joinedAt: Date | null;\n leftAt: Date | null;\n user: TelegramUserSummary | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramMessageSummary {\n id: string;\n chatId: string;\n fromUserId: string | null;\n senderChatId: string | null;\n replyToMessageId: string | null;\n messageType: TelegramUpdateType;\n text: string | null;\n payload: unknown | null;\n sentAt: Date;\n editedAt: Date | null;\n commandName: string | null;\n fromUser: TelegramUserSummary | null;\n}\n\nexport interface TelegramMessageHookPayload {\n updateId: number;\n updateType: TelegramUpdateType;\n messageId: string;\n chatId: string;\n fromUserId: string | null;\n text: string | null;\n commandName: string | null;\n sentAt: Date;\n editedAt: Date | null;\n}\n\nexport interface TelegramCommandHookPayload {\n updateId: number;\n messageId: string;\n chatId: string;\n fromUserId: string | null;\n commandName: string;\n args: string;\n raw: string;\n sentAt: Date;\n}\n\nexport interface TelegramChatMemberHookPayload {\n updateId: number;\n chatId: string;\n userId: string;\n status: string;\n joinedAt: Date | null;\n leftAt: Date | null;\n}\n\nexport type TelegramOutgoingHookAction = \"sendMessage\" | \"editMessageText\";\n\nexport type TelegramOutgoingHookPayload = {\n action: TelegramOutgoingHookAction;\n payload: Record<string, unknown>;\n};\n\nexport type TelegramHooks = {\n onMessageReceived?: (payload: TelegramMessageHookPayload) => Promise<void> | void;\n onCommandMatched?: (payload: TelegramCommandHookPayload) => Promise<void> | void;\n onChatMemberUpdated?: (payload: TelegramChatMemberHookPayload) => Promise<void> | void;\n};\n\nexport type TelegramInternalHookPayload = {\n update: TelegramUpdate;\n};\n\nexport type TelegramHooksMap = {\n internalProcessUpdate: HookFn<TelegramInternalHookPayload>;\n internalOutgoingMessage: HookFn<TelegramOutgoingHookPayload>;\n onMessageReceived: HookFn<TelegramMessageHookPayload>;\n onCommandMatched: HookFn<TelegramCommandHookPayload>;\n onChatMemberUpdated: HookFn<TelegramChatMemberHookPayload>;\n};\n\nexport type TelegramApiResult<T> =\n | { ok: true; result: T }\n | { ok: false; error_code?: number; description?: string };\n\nexport interface TelegramApi {\n call<T>(method: string, payload: Record<string, unknown>): Promise<TelegramApiResult<T>>;\n sendMessage(payload: Record<string, unknown>): Promise<TelegramApiResult<TelegramMessage>>;\n editMessageText(payload: Record<string, unknown>): Promise<TelegramApiResult<TelegramMessage>>;\n sendChatAction(payload: Record<string, unknown>): Promise<TelegramApiResult<boolean>>;\n}\n\nexport type TelegramQueuedResult =\n | { ok: true; queued: true }\n | { ok: false; error_code?: number; description?: string };\n\nexport type TelegramCommandApiResult<T> = TelegramApiResult<T> | TelegramQueuedResult;\n\nexport interface TelegramCommandApi {\n call<T>(method: string, payload: Record<string, unknown>): Promise<TelegramCommandApiResult<T>>;\n sendMessage(payload: Record<string, unknown>): Promise<TelegramQueuedResult>;\n editMessageText(payload: Record<string, unknown>): Promise<TelegramQueuedResult>;\n sendChatAction(payload: Record<string, unknown>): Promise<TelegramApiResult<boolean>>;\n}\n\nexport interface TelegramCommandContext {\n updateId: number;\n idempotencyKey: string;\n update: TelegramUpdate;\n message: TelegramMessage;\n chat: TelegramChatSummary;\n fromUser: TelegramUserSummary | null;\n command: {\n name: string;\n args: string;\n raw: string;\n };\n api: TelegramCommandApi;\n handlerTx: HookHandlerTx;\n}\n\nexport type TelegramCommandHandler = (ctx: TelegramCommandContext) => Promise<void> | void;\n\nexport interface TelegramCommandDefinition {\n name: string;\n description?: string;\n scopes?: TelegramCommandScope[];\n handler: TelegramCommandHandler;\n}\n\nexport type TelegramCommandRegistry = Record<string, TelegramCommandDefinition>;\n\nexport interface TelegramFragmentConfig {\n botToken: string;\n webhookSecretToken: string;\n botUsername?: string;\n apiBaseUrl?: string;\n commands?: TelegramCommandRegistry;\n hooks?: TelegramHooks;\n}\n\nexport type TelegramConfigBuilder = {\n command: (command: TelegramCommandDefinition) => TelegramConfigBuilder;\n build: (overrides?: Partial<TelegramFragmentConfig>) => TelegramFragmentConfig;\n};\n\nexport function defineCommand(\n name: string,\n definition: Omit<TelegramCommandDefinition, \"name\">,\n): TelegramCommandDefinition {\n return {\n name,\n ...definition,\n };\n}\n\nexport function createTelegram(\n baseConfig: Partial<TelegramFragmentConfig> = {},\n): TelegramConfigBuilder {\n const commands = new Map<string, TelegramCommandDefinition>();\n\n if (baseConfig.commands) {\n for (const command of Object.values(baseConfig.commands)) {\n commands.set(command.name, command);\n }\n }\n\n const builder: TelegramConfigBuilder = {\n command(command: TelegramCommandDefinition) {\n commands.set(command.name, command);\n return builder;\n },\n build(overrides: Partial<TelegramFragmentConfig> = {}) {\n const baseCommands = baseConfig.commands ?? {};\n const internalCommands = Object.fromEntries(commands);\n const overrideCommands = overrides.commands ?? {};\n const mergedCommands = {\n ...baseCommands,\n ...internalCommands,\n ...overrideCommands,\n };\n const resolved = {\n ...baseConfig,\n ...overrides,\n commands: mergedCommands,\n } as TelegramFragmentConfig;\n\n if (!resolved.botToken) {\n throw new Error(\"Telegram fragment requires botToken\");\n }\n if (!resolved.webhookSecretToken) {\n throw new Error(\"Telegram fragment requires webhookSecretToken\");\n }\n\n return resolved;\n },\n };\n\n return builder;\n}\n"],"mappings":";;;AAIA,MAAa,yBAAyB,EAAE,KAAK;CAAC;CAAW;CAAS;CAAc;CAAU,CAAC;AAI3F,MAAa,8BAA8B,EACxC,OAAO;CACN,MAAM,EAAE,QAAQ;CAChB,QAAQ,EAAE,QAAQ;CAClB,QAAQ,EAAE,QAAQ;CACnB,CAAC,CACD,OAAO;AAGV,MA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SAAgB,cACd,MACA,YAC2B;AAC3B,QAAO;EACL;EACA,GAAG;EACJ;;AAGH,SAAgB,eACd,aAA8C,EAAE,EACzB;CACvB,MAAM,2BAAW,IAAI,KAAwC;AAE7D,KAAI,WAAW,SACb,MAAK,MAAM,WAAW,OAAO,OAAO,WAAW,SAAS,CACtD,UAAS,IAAI,QAAQ,MAAM,QAAQ;CAIvC,MAAM,UAAiC;EACrC,QAAQ,SAAoC;AAC1C,YAAS,IAAI,QAAQ,MAAM,QAAQ;AACnC,UAAO;;EAET,MAAM,YAA6C,EAAE,EAAE;GACrD,MAAM,eAAe,WAAW,YAAY,EAAE;GAC9C,MAAM,mBAAmB,OAAO,YAAY,SAAS;GACrD,MAAM,mBAAmB,UAAU,YAAY,EAAE;GACjD,MAAM,iBAAiB;IACrB,GAAG;IACH,GAAG;IACH,GAAG;IACJ;GACD,MAAM,WAAW;IACf,GAAG;IACH,GAAG;IACH,UAAU;IACX;AAED,OAAI,CAAC,SAAS,SACZ,OAAM,IAAI,MAAM,sCAAsC;AAExD,OAAI,CAAC,SAAS,mBACZ,OAAM,IAAI,MAAM,gDAAgD;AAGlE,UAAO;;EAEV;AAED,QAAO"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { HookFn, HookHandlerTx } from \"@fragno-dev/db\";\n\nconst telegramIntegerSchema = z.number().int();\n\nexport const telegramChatTypeSchema = z.enum([\"private\", \"group\", \"supergroup\", \"channel\"]);\nexport type TelegramChatType = z.infer<typeof telegramChatTypeSchema>;\nexport type TelegramCommandScope = TelegramChatType;\n\nexport const telegramPhotoSizeSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n fileSize: telegramIntegerSchema.optional(),\n});\nexport type TelegramPhotoSize = z.infer<typeof telegramPhotoSizeSchema>;\n\nexport const telegramVoiceSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n duration: telegramIntegerSchema,\n mimeType: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n});\nexport type TelegramVoice = z.infer<typeof telegramVoiceSchema>;\n\nexport const telegramAudioSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n duration: telegramIntegerSchema,\n performer: z.string().optional(),\n title: z.string().optional(),\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n});\nexport type TelegramAudio = z.infer<typeof telegramAudioSchema>;\n\nexport const telegramDocumentSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n});\nexport type TelegramDocument = z.infer<typeof telegramDocumentSchema>;\n\nexport const telegramVideoSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n});\nexport type TelegramVideo = z.infer<typeof telegramVideoSchema>;\n\nexport const telegramVideoNoteSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n length: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n fileSize: telegramIntegerSchema.optional(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n});\nexport type TelegramVideoNote = z.infer<typeof telegramVideoNoteSchema>;\n\nexport const telegramStickerTypeSchema = z.enum([\"regular\", \"mask\", \"custom_emoji\"]);\nexport type TelegramStickerType = z.infer<typeof telegramStickerTypeSchema>;\n\nexport const telegramStickerSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n type: telegramStickerTypeSchema,\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n isAnimated: z.boolean(),\n isVideo: z.boolean(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n emoji: z.string().optional(),\n setName: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n});\nexport type TelegramSticker = z.infer<typeof telegramStickerSchema>;\n\nexport const telegramAnimationSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n fileSize: telegramIntegerSchema.optional(),\n thumbnail: telegramPhotoSizeSchema.optional(),\n});\nexport type TelegramAnimation = z.infer<typeof telegramAnimationSchema>;\n\nexport const telegramAttachmentKindSchema = z.enum([\n \"photo\",\n \"voice\",\n \"audio\",\n \"document\",\n \"video\",\n \"video_note\",\n \"sticker\",\n \"animation\",\n]);\nexport type TelegramAttachmentKind = z.infer<typeof telegramAttachmentKindSchema>;\n\nexport const telegramAttachmentPhotoSizeSchema = z.object({\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n});\nexport type TelegramAttachmentPhotoSize = z.infer<typeof telegramAttachmentPhotoSizeSchema>;\n\nconst telegramPhotoAttachmentSchema = z.object({\n kind: z.literal(\"photo\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n sizes: z.array(telegramAttachmentPhotoSizeSchema).min(1),\n});\n\nconst telegramVoiceAttachmentSchema = z.object({\n kind: z.literal(\"voice\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n duration: telegramIntegerSchema,\n mimeType: z.string().optional(),\n});\n\nconst telegramAudioAttachmentSchema = z.object({\n kind: z.literal(\"audio\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n duration: telegramIntegerSchema,\n performer: z.string().optional(),\n title: z.string().optional(),\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nconst telegramDocumentAttachmentSchema = z.object({\n kind: z.literal(\"document\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nconst telegramVideoAttachmentSchema = z.object({\n kind: z.literal(\"video\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nconst telegramVideoNoteAttachmentSchema = z.object({\n kind: z.literal(\"video_note\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n length: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nconst telegramStickerAttachmentSchema = z.object({\n kind: z.literal(\"sticker\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n emoji: z.string().optional(),\n setName: z.string().optional(),\n isAnimated: z.boolean(),\n isVideo: z.boolean(),\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nconst telegramAnimationAttachmentSchema = z.object({\n kind: z.literal(\"animation\"),\n fileId: z.string(),\n fileUniqueId: z.string(),\n fileSize: telegramIntegerSchema.optional(),\n width: telegramIntegerSchema,\n height: telegramIntegerSchema,\n duration: telegramIntegerSchema,\n fileName: z.string().optional(),\n mimeType: z.string().optional(),\n thumbnail: telegramAttachmentPhotoSizeSchema.optional(),\n});\n\nexport const telegramAttachmentSchema = z.discriminatedUnion(\"kind\", [\n telegramPhotoAttachmentSchema,\n telegramVoiceAttachmentSchema,\n telegramAudioAttachmentSchema,\n telegramDocumentAttachmentSchema,\n telegramVideoAttachmentSchema,\n telegramVideoNoteAttachmentSchema,\n telegramStickerAttachmentSchema,\n telegramAnimationAttachmentSchema,\n]);\nexport type TelegramAttachment = z.infer<typeof telegramAttachmentSchema>;\n\nexport const telegramMessageEntitySchema = z.object({\n type: z.string(),\n offset: telegramIntegerSchema,\n length: telegramIntegerSchema,\n});\nexport type TelegramMessageEntity = z.infer<typeof telegramMessageEntitySchema>;\n\nexport const telegramUserSchema = z.object({\n id: telegramIntegerSchema,\n isBot: z.boolean(),\n firstName: z.string(),\n lastName: z.string().optional(),\n username: z.string().optional(),\n languageCode: z.string().optional(),\n});\nexport type TelegramUser = z.infer<typeof telegramUserSchema>;\n\nexport const telegramChatSchema = z.object({\n id: telegramIntegerSchema,\n type: telegramChatTypeSchema,\n title: z.string().optional(),\n username: z.string().optional(),\n firstName: z.string().optional(),\n lastName: z.string().optional(),\n isForum: z.boolean().optional(),\n});\nexport type TelegramChat = z.infer<typeof telegramChatSchema>;\n\nexport interface TelegramMessage {\n messageId: number;\n date: number;\n editDate?: number;\n text?: string;\n from?: TelegramUser;\n senderChat?: TelegramChat;\n chat: TelegramChat;\n replyToMessage?: TelegramMessage;\n newChatMembers?: TelegramUser[];\n leftChatMember?: TelegramUser;\n entities?: TelegramMessageEntity[];\n mediaGroupId?: string;\n photo?: TelegramPhotoSize[];\n voice?: TelegramVoice;\n audio?: TelegramAudio;\n document?: TelegramDocument;\n video?: TelegramVideo;\n videoNote?: TelegramVideoNote;\n sticker?: TelegramSticker;\n animation?: TelegramAnimation;\n}\n\nexport const telegramMessageSchema: z.ZodType<TelegramMessage> = z.lazy(() =>\n z.object({\n messageId: telegramIntegerSchema,\n date: telegramIntegerSchema,\n editDate: telegramIntegerSchema.optional(),\n text: z.string().optional(),\n from: telegramUserSchema.optional(),\n senderChat: telegramChatSchema.optional(),\n chat: telegramChatSchema,\n replyToMessage: telegramMessageSchema.optional(),\n newChatMembers: z.array(telegramUserSchema).optional(),\n leftChatMember: telegramUserSchema.optional(),\n entities: z.array(telegramMessageEntitySchema).optional(),\n mediaGroupId: z.string().optional(),\n photo: z.array(telegramPhotoSizeSchema).optional(),\n voice: telegramVoiceSchema.optional(),\n audio: telegramAudioSchema.optional(),\n document: telegramDocumentSchema.optional(),\n video: telegramVideoSchema.optional(),\n videoNote: telegramVideoNoteSchema.optional(),\n sticker: telegramStickerSchema.optional(),\n animation: telegramAnimationSchema.optional(),\n }),\n);\n\nexport interface TelegramUpdate {\n updateId: number;\n message?: TelegramMessage;\n editedMessage?: TelegramMessage;\n channelPost?: TelegramMessage;\n}\n\nexport const telegramUpdateSchema: z.ZodType<TelegramUpdate> = z.object({\n updateId: telegramIntegerSchema,\n message: telegramMessageSchema.optional(),\n editedMessage: telegramMessageSchema.optional(),\n channelPost: telegramMessageSchema.optional(),\n});\nexport type TelegramUpdateType = \"message\" | \"edited_message\" | \"channel_post\";\n\nexport const telegramCommandBindingSchema = z.object({\n enabled: z.boolean().optional(),\n scopes: z.array(telegramChatTypeSchema).optional(),\n});\nexport type TelegramCommandBinding = z.infer<typeof telegramCommandBindingSchema>;\n\nexport const telegramCommandBindingsSchema = z.record(z.string(), telegramCommandBindingSchema);\nexport type TelegramCommandBindings = z.infer<typeof telegramCommandBindingsSchema>;\n\nexport interface TelegramUserSummary {\n id: string;\n username: string | null;\n firstName: string;\n lastName: string | null;\n isBot: boolean;\n languageCode: string | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramChatSummary {\n id: string;\n type: TelegramChatType;\n title: string | null;\n username: string | null;\n isForum: boolean;\n commandBindings: TelegramCommandBindings | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramChatMemberSummary {\n id: string;\n chatId: string;\n userId: string;\n status: string;\n joinedAt: Date | null;\n leftAt: Date | null;\n user: TelegramUserSummary | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface TelegramMessageSummary {\n id: string;\n chatId: string;\n fromUserId: string | null;\n senderChatId: string | null;\n replyToMessageId: string | null;\n messageType: TelegramUpdateType;\n text: string | null;\n attachments: TelegramAttachment[];\n payload: unknown | null;\n sentAt: Date;\n editedAt: Date | null;\n commandName: string | null;\n fromUser: TelegramUserSummary | null;\n}\n\nexport interface TelegramMessageHookPayload {\n updateId: number;\n updateType: TelegramUpdateType;\n messageId: string;\n chatId: string;\n fromUserId: string | null;\n text: string | null;\n attachments: TelegramAttachment[];\n commandName: string | null;\n sentAt: Date;\n editedAt: Date | null;\n}\n\nexport interface TelegramCommandHookPayload {\n updateId: number;\n messageId: string;\n chatId: string;\n fromUserId: string | null;\n commandName: string;\n args: string;\n raw: string;\n sentAt: Date;\n}\n\nexport interface TelegramChatMemberHookPayload {\n updateId: number;\n chatId: string;\n userId: string;\n status: string;\n joinedAt: Date | null;\n leftAt: Date | null;\n}\n\nexport type TelegramOutgoingHookAction = \"sendMessage\" | \"editMessageText\";\n\nexport type TelegramOutgoingHookPayload = {\n action: TelegramOutgoingHookAction;\n payload: Record<string, unknown>;\n};\n\nexport type TelegramHooks = {\n onMessageReceived?: (payload: TelegramMessageHookPayload) => Promise<void> | void;\n onCommandMatched?: (payload: TelegramCommandHookPayload) => Promise<void> | void;\n onChatMemberUpdated?: (payload: TelegramChatMemberHookPayload) => Promise<void> | void;\n};\n\nexport type TelegramInternalHookPayload = {\n update: TelegramUpdate;\n};\n\nexport type TelegramHooksMap = {\n internalProcessUpdate: HookFn<TelegramInternalHookPayload>;\n internalOutgoingMessage: HookFn<TelegramOutgoingHookPayload>;\n onMessageReceived: HookFn<TelegramMessageHookPayload>;\n onCommandMatched: HookFn<TelegramCommandHookPayload>;\n onChatMemberUpdated: HookFn<TelegramChatMemberHookPayload>;\n};\n\nexport type TelegramApiResult<T> =\n | { ok: true; result: T }\n | { ok: false; errorCode?: number; description?: string };\n\nexport interface TelegramApi {\n call<T>(method: string, payload: Record<string, unknown>): Promise<TelegramApiResult<T>>;\n sendMessage(payload: Record<string, unknown>): Promise<TelegramApiResult<TelegramMessage>>;\n editMessageText(payload: Record<string, unknown>): Promise<TelegramApiResult<TelegramMessage>>;\n sendChatAction(payload: Record<string, unknown>): Promise<TelegramApiResult<boolean>>;\n}\n\nexport type TelegramQueuedResult =\n | { ok: true; queued: true }\n | { ok: false; errorCode?: number; description?: string };\n\nexport type TelegramCommandApiResult<T> = TelegramApiResult<T> | TelegramQueuedResult;\n\nexport interface TelegramCommandApi {\n call<T>(method: string, payload: Record<string, unknown>): Promise<TelegramCommandApiResult<T>>;\n sendMessage(payload: Record<string, unknown>): Promise<TelegramQueuedResult>;\n editMessageText(payload: Record<string, unknown>): Promise<TelegramQueuedResult>;\n sendChatAction(payload: Record<string, unknown>): Promise<TelegramApiResult<boolean>>;\n}\n\nexport interface TelegramCommandContext {\n updateId: number;\n idempotencyKey: string;\n update: TelegramUpdate;\n message: TelegramMessage;\n chat: TelegramChatSummary;\n fromUser: TelegramUserSummary | null;\n command: {\n name: string;\n args: string;\n raw: string;\n };\n api: TelegramCommandApi;\n handlerTx: HookHandlerTx;\n}\n\nexport type TelegramCommandHandler = (ctx: TelegramCommandContext) => Promise<void> | void;\n\nexport interface TelegramCommandDefinition {\n name: string;\n description?: string;\n scopes?: TelegramCommandScope[];\n handler: TelegramCommandHandler;\n}\n\nexport type TelegramCommandRegistry = Record<string, TelegramCommandDefinition>;\n\nexport interface TelegramFragmentConfig {\n botToken: string;\n webhookSecretToken: string;\n botUsername?: string;\n apiBaseUrl?: string;\n commands?: TelegramCommandRegistry;\n hooks?: TelegramHooks;\n}\n\nexport type TelegramConfigBuilder = {\n command: (command: TelegramCommandDefinition) => TelegramConfigBuilder;\n build: (overrides?: Partial<TelegramFragmentConfig>) => TelegramFragmentConfig;\n};\n\nexport function defineCommand(\n name: string,\n definition: Omit<TelegramCommandDefinition, \"name\">,\n): TelegramCommandDefinition {\n return {\n name,\n ...definition,\n };\n}\n\nexport function createTelegram(\n baseConfig: Partial<TelegramFragmentConfig> = {},\n): TelegramConfigBuilder {\n const commands = new Map<string, TelegramCommandDefinition>();\n\n if (baseConfig.commands) {\n for (const command of Object.values(baseConfig.commands)) {\n commands.set(command.name, command);\n }\n }\n\n const builder: TelegramConfigBuilder = {\n command(command: TelegramCommandDefinition) {\n commands.set(command.name, command);\n return builder;\n },\n build(overrides: Partial<TelegramFragmentConfig> = {}) {\n const baseCommands = baseConfig.commands ?? {};\n const internalCommands = Object.fromEntries(commands);\n const overrideCommands = overrides.commands ?? {};\n const mergedCommands = {\n ...baseCommands,\n ...internalCommands,\n ...overrideCommands,\n };\n const resolved = {\n ...baseConfig,\n ...overrides,\n commands: mergedCommands,\n } as TelegramFragmentConfig;\n\n if (!resolved.botToken) {\n throw new Error(\"Telegram fragment requires botToken\");\n }\n if (!resolved.webhookSecretToken) {\n throw new Error(\"Telegram fragment requires webhookSecretToken\");\n }\n\n return resolved;\n },\n };\n\n return builder;\n}\n"],"mappings":";;;AAIA,MAAM,wBAAwB,EAAE,QAAQ,CAAC,KAAK;AAE9C,MAAa,yBAAyB,EAAE,KAAK;CAAC;CAAW;CAAS;CAAc;CAAU,CAAC;AAI3F,MAAa,0BAA0B,EAAE,OAAO;CAC9C,QAAQ,EAAE,QAAQ;CAClB,cAAc,EAAE,QAAQ;CACxB,OAAO;CACP,QAAQ;CACR,UAAU,sBAAsB,UAAU;CAC3C,CAAC;AAGF,MAAa,sBAAsB,EAAE,OAAO;CAC1C,QAAQ,EAAE,QAAQ;CAClB,cAAc,EAAE,QAAQ;CACxB,UAAU;CACV,UAAU,EAAE,QAAQ,CAAC,UAAU;CAC/B,UAAU,sBAAsB,UAAU;CAC3C,CAAC;AAGF,MAAa,sBAAsB,EAAE,OAAO;CAC1C,QAAQ,EAAE,QAAQ;CAClB,cAAc,EAAE,QAAQ;CACxB,UAAU;CACV,WAAW,EAAE,QAAQ,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