@arcaelas/whatsapp 5.1.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +282 -239
- package/build/cjs/decorators.js +0 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/lib/bot/decorator.js +0 -1
- package/build/cjs/lib/bot/decorators.d.ts +2 -2
- package/build/cjs/lib/bot/decorators.js +4 -4
- package/build/cjs/lib/bot/index.js +0 -1
- package/build/cjs/lib/chat/index.d.ts +41 -0
- package/build/cjs/lib/chat/index.js +27 -8
- package/build/cjs/lib/contact/index.js +0 -1
- package/build/cjs/lib/internal.js +0 -1
- package/build/cjs/lib/message/index.d.ts +6 -0
- package/build/cjs/lib/message/index.js +53 -9
- package/build/cjs/lib/status/index.js +0 -1
- package/build/cjs/lib/store/engine/index.d.ts +14 -0
- package/build/cjs/lib/store/engine/index.js +0 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +10 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.js +27 -1
- package/build/cjs/lib/store/engine/lib/index.js +0 -1
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +18 -4
- package/build/cjs/lib/store/engine/lib/redis/index.js +21 -3
- package/build/cjs/lib/store/engine/lib/s3/index.js +0 -1
- package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +14 -2
- package/build/cjs/lib/store/engine/lib/sqlite/index.js +22 -4
- package/build/cjs/lib/store/index.js +0 -1
- package/build/cjs/lib/whatsapp/index.js +20 -4
- package/build/esm/decorators.js +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/lib/bot/decorator.js +0 -1
- package/build/esm/lib/bot/decorators.d.ts +2 -2
- package/build/esm/lib/bot/decorators.js +4 -4
- package/build/esm/lib/bot/index.js +0 -1
- package/build/esm/lib/chat/index.d.ts +41 -0
- package/build/esm/lib/chat/index.js +27 -8
- package/build/esm/lib/contact/index.js +0 -1
- package/build/esm/lib/internal.js +0 -1
- package/build/esm/lib/message/index.d.ts +6 -0
- package/build/esm/lib/message/index.js +53 -9
- package/build/esm/lib/status/index.js +0 -1
- package/build/esm/lib/store/engine/index.d.ts +14 -0
- package/build/esm/lib/store/engine/index.js +0 -1
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +10 -0
- package/build/esm/lib/store/engine/lib/file_system/index.js +27 -1
- package/build/esm/lib/store/engine/lib/index.js +0 -1
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +18 -4
- package/build/esm/lib/store/engine/lib/redis/index.js +21 -3
- package/build/esm/lib/store/engine/lib/s3/index.js +0 -1
- package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +14 -2
- package/build/esm/lib/store/engine/lib/sqlite/index.js +22 -4
- package/build/esm/lib/store/index.js +0 -1
- package/build/esm/lib/whatsapp/index.js +20 -4
- package/package.json +24 -5
- package/build/cjs/decorators.js.map +0 -1
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/lib/bot/decorator.js.map +0 -1
- package/build/cjs/lib/bot/decorators.js.map +0 -1
- package/build/cjs/lib/bot/index.js.map +0 -1
- package/build/cjs/lib/chat/index.js.map +0 -1
- package/build/cjs/lib/contact/index.js.map +0 -1
- package/build/cjs/lib/internal.js.map +0 -1
- package/build/cjs/lib/message/index.js.map +0 -1
- package/build/cjs/lib/status/index.js.map +0 -1
- package/build/cjs/lib/store/engine/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/s3/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/sqlite/index.js.map +0 -1
- package/build/cjs/lib/store/index.js.map +0 -1
- package/build/cjs/lib/whatsapp/index.js.map +0 -1
- package/build/cjs/test.d.ts +0 -1
- package/build/cjs/test.js +0 -72
- package/build/cjs/test.js.map +0 -1
- package/build/esm/decorators.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/lib/bot/decorator.js.map +0 -1
- package/build/esm/lib/bot/decorators.js.map +0 -1
- package/build/esm/lib/bot/index.js.map +0 -1
- package/build/esm/lib/chat/index.js.map +0 -1
- package/build/esm/lib/contact/index.js.map +0 -1
- package/build/esm/lib/internal.js.map +0 -1
- package/build/esm/lib/message/index.js.map +0 -1
- package/build/esm/lib/status/index.js.map +0 -1
- package/build/esm/lib/store/engine/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/redis/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/s3/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/sqlite/index.js.map +0 -1
- package/build/esm/lib/store/index.js.map +0 -1
- package/build/esm/lib/whatsapp/index.js.map +0 -1
- package/build/esm/test.d.ts +0 -1
- package/build/esm/test.js +0 -67
- package/build/esm/test.js.map +0 -1
|
@@ -82,9 +82,9 @@ export declare function delay(ms: number): (_value: unknown, context: ClassMetho
|
|
|
82
82
|
export declare const pair: () => (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
83
83
|
/**
|
|
84
84
|
* Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
|
|
85
|
-
* se normaliza
|
|
85
|
+
* se normaliza con la resolución interna del cliente y cache lazy. Un array produce match OR.
|
|
86
86
|
* Filters by message author. Accepts JID, LID or numeric phone; the string is
|
|
87
|
-
* normalized
|
|
87
|
+
* normalized through the client's internal resolution with lazy cache. An array yields OR matching.
|
|
88
88
|
*
|
|
89
89
|
* @param source - Identificador(es) permitidos o predicate sobre `msg.from` / Allowed identifier(s) or predicate on `msg.from`
|
|
90
90
|
*/
|
|
@@ -15,6 +15,7 @@ exports.from = from;
|
|
|
15
15
|
exports.Bot = Bot;
|
|
16
16
|
exports.pipe = pipe;
|
|
17
17
|
exports.command = command;
|
|
18
|
+
const internal_1 = require("../../lib/internal");
|
|
18
19
|
const decorator_1 = require("./decorator");
|
|
19
20
|
/**
|
|
20
21
|
* Registra el método como listener del evento indicado. Apilable: varios `@on`
|
|
@@ -126,9 +127,9 @@ exports.pair = (0, decorator_1.decorator)((_meta, h) => {
|
|
|
126
127
|
});
|
|
127
128
|
/**
|
|
128
129
|
* Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
|
|
129
|
-
* se normaliza
|
|
130
|
+
* se normaliza con la resolución interna del cliente y cache lazy. Un array produce match OR.
|
|
130
131
|
* Filters by message author. Accepts JID, LID or numeric phone; the string is
|
|
131
|
-
* normalized
|
|
132
|
+
* normalized through the client's internal resolution with lazy cache. An array yields OR matching.
|
|
132
133
|
*
|
|
133
134
|
* @param source - Identificador(es) permitidos o predicate sobre `msg.from` / Allowed identifier(s) or predicate on `msg.from`
|
|
134
135
|
*/
|
|
@@ -146,7 +147,7 @@ function from(source) {
|
|
|
146
147
|
if (resolved === null) {
|
|
147
148
|
resolved = new Set();
|
|
148
149
|
for (const raw of list) {
|
|
149
|
-
const r = await wa.
|
|
150
|
+
const r = await (0, internal_1.internals)(wa).resolve_jid(raw);
|
|
150
151
|
if (r) {
|
|
151
152
|
resolved.add(r);
|
|
152
153
|
}
|
|
@@ -259,4 +260,3 @@ function command(pattern) {
|
|
|
259
260
|
});
|
|
260
261
|
};
|
|
261
262
|
}
|
|
262
|
-
//# sourceMappingURL=decorators.js.map
|
|
@@ -18,4 +18,3 @@ Object.defineProperty(exports, "delay", { enumerable: true, get: function () { r
|
|
|
18
18
|
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return decorators_1.pipe; } });
|
|
19
19
|
Object.defineProperty(exports, "pair", { enumerable: true, get: function () { return decorators_1.pair; } });
|
|
20
20
|
Object.defineProperty(exports, "Bot", { enumerable: true, get: function () { return decorators_1.Bot; } });
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -16,6 +16,7 @@ export declare class Chat {
|
|
|
16
16
|
archived?: boolean | null;
|
|
17
17
|
pinned?: number | null;
|
|
18
18
|
mute_end_time?: number | null;
|
|
19
|
+
unread_count?: number | null;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* @internal Documento crudo del chat. `id` es el identificador del engine (JID, LID o
|
|
@@ -29,6 +30,7 @@ export declare class Chat {
|
|
|
29
30
|
archived?: boolean | null;
|
|
30
31
|
pinned?: number | null;
|
|
31
32
|
mute_end_time?: number | null;
|
|
33
|
+
unread_count?: number | null;
|
|
32
34
|
});
|
|
33
35
|
/** Teléfono del contacto, o el identificador crudo en grupos y LIDs. / Contact phone, or the raw identifier for groups and LIDs. */
|
|
34
36
|
get id(): string;
|
|
@@ -40,6 +42,8 @@ export declare class Chat {
|
|
|
40
42
|
get archived(): boolean;
|
|
41
43
|
/** true si el chat está fijado. / true when the chat is pinned. */
|
|
42
44
|
get pinned(): boolean;
|
|
45
|
+
/** Mensajes sin leer del chat. / Chat's unread messages. */
|
|
46
|
+
get count(): number;
|
|
43
47
|
/** Fecha ISO UTC hasta la que el chat está silenciado, o null. / ISO UTC date until the chat stays muted, or null. */
|
|
44
48
|
get muted(): string | null;
|
|
45
49
|
}
|
|
@@ -56,6 +60,7 @@ export declare function chat(wa: WhatsApp): {
|
|
|
56
60
|
archived?: boolean | null;
|
|
57
61
|
pinned?: number | null;
|
|
58
62
|
mute_end_time?: number | null;
|
|
63
|
+
unread_count?: number | null;
|
|
59
64
|
}): {
|
|
60
65
|
/**
|
|
61
66
|
* Participantes del chat: los integrantes en grupos, el contacto y yo en 1:1.
|
|
@@ -66,6 +71,15 @@ export declare function chat(wa: WhatsApp): {
|
|
|
66
71
|
* @returns Página de contactos / Contact page
|
|
67
72
|
*/
|
|
68
73
|
members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Descripción del chat: el asunto del grupo o, en un 1:1, la bio del contacto.
|
|
76
|
+
* Es asíncrono porque ninguno de los dos vive en el documento del chat.
|
|
77
|
+
* Chat description: the group's subject or, on a 1:1, the contact's bio. It is async
|
|
78
|
+
* because neither of them lives in the chat document.
|
|
79
|
+
*
|
|
80
|
+
* @returns Descripción, o cadena vacía si no hay / Description, or an empty string when absent
|
|
81
|
+
*/
|
|
82
|
+
content(): Promise<string>;
|
|
69
83
|
/**
|
|
70
84
|
* Mensajes del chat paginados desde el más reciente.
|
|
71
85
|
* Chat messages paginated from the most recent one.
|
|
@@ -146,6 +160,7 @@ export declare function chat(wa: WhatsApp): {
|
|
|
146
160
|
archived?: boolean | null;
|
|
147
161
|
pinned?: number | null;
|
|
148
162
|
mute_end_time?: number | null;
|
|
163
|
+
unread_count?: number | null;
|
|
149
164
|
};
|
|
150
165
|
/** Teléfono del contacto, o el identificador crudo en grupos y LIDs. / Contact phone, or the raw identifier for groups and LIDs. */
|
|
151
166
|
get id(): string;
|
|
@@ -157,6 +172,8 @@ export declare function chat(wa: WhatsApp): {
|
|
|
157
172
|
get archived(): boolean;
|
|
158
173
|
/** true si el chat está fijado. / true when the chat is pinned. */
|
|
159
174
|
get pinned(): boolean;
|
|
175
|
+
/** Mensajes sin leer del chat. / Chat's unread messages. */
|
|
176
|
+
get count(): number;
|
|
160
177
|
/** Fecha ISO UTC hasta la que el chat está silenciado, o null. / ISO UTC date until the chat stays muted, or null. */
|
|
161
178
|
get muted(): string | null;
|
|
162
179
|
};
|
|
@@ -179,6 +196,15 @@ export declare function chat(wa: WhatsApp): {
|
|
|
179
196
|
* @returns Página de contactos / Contact page
|
|
180
197
|
*/
|
|
181
198
|
members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
|
|
199
|
+
/**
|
|
200
|
+
* Descripción del chat: el asunto del grupo o, en un 1:1, la bio del contacto.
|
|
201
|
+
* Es asíncrono porque ninguno de los dos vive en el documento del chat.
|
|
202
|
+
* Chat description: the group's subject or, on a 1:1, the contact's bio. It is async
|
|
203
|
+
* because neither of them lives in the chat document.
|
|
204
|
+
*
|
|
205
|
+
* @returns Descripción, o cadena vacía si no hay / Description, or an empty string when absent
|
|
206
|
+
*/
|
|
207
|
+
content(): Promise<string>;
|
|
182
208
|
/**
|
|
183
209
|
* Mensajes del chat paginados desde el más reciente.
|
|
184
210
|
* Chat messages paginated from the most recent one.
|
|
@@ -259,6 +285,7 @@ export declare function chat(wa: WhatsApp): {
|
|
|
259
285
|
archived?: boolean | null;
|
|
260
286
|
pinned?: number | null;
|
|
261
287
|
mute_end_time?: number | null;
|
|
288
|
+
unread_count?: number | null;
|
|
262
289
|
};
|
|
263
290
|
/** Teléfono del contacto, o el identificador crudo en grupos y LIDs. / Contact phone, or the raw identifier for groups and LIDs. */
|
|
264
291
|
get id(): string;
|
|
@@ -270,6 +297,8 @@ export declare function chat(wa: WhatsApp): {
|
|
|
270
297
|
get archived(): boolean;
|
|
271
298
|
/** true si el chat está fijado. / true when the chat is pinned. */
|
|
272
299
|
get pinned(): boolean;
|
|
300
|
+
/** Mensajes sin leer del chat. / Chat's unread messages. */
|
|
301
|
+
get count(): number;
|
|
273
302
|
/** Fecha ISO UTC hasta la que el chat está silenciado, o null. / ISO UTC date until the chat stays muted, or null. */
|
|
274
303
|
get muted(): string | null;
|
|
275
304
|
} | null>;
|
|
@@ -291,6 +320,15 @@ export declare function chat(wa: WhatsApp): {
|
|
|
291
320
|
* @returns Página de contactos / Contact page
|
|
292
321
|
*/
|
|
293
322
|
members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
|
|
323
|
+
/**
|
|
324
|
+
* Descripción del chat: el asunto del grupo o, en un 1:1, la bio del contacto.
|
|
325
|
+
* Es asíncrono porque ninguno de los dos vive en el documento del chat.
|
|
326
|
+
* Chat description: the group's subject or, on a 1:1, the contact's bio. It is async
|
|
327
|
+
* because neither of them lives in the chat document.
|
|
328
|
+
*
|
|
329
|
+
* @returns Descripción, o cadena vacía si no hay / Description, or an empty string when absent
|
|
330
|
+
*/
|
|
331
|
+
content(): Promise<string>;
|
|
294
332
|
/**
|
|
295
333
|
* Mensajes del chat paginados desde el más reciente.
|
|
296
334
|
* Chat messages paginated from the most recent one.
|
|
@@ -371,6 +409,7 @@ export declare function chat(wa: WhatsApp): {
|
|
|
371
409
|
archived?: boolean | null;
|
|
372
410
|
pinned?: number | null;
|
|
373
411
|
mute_end_time?: number | null;
|
|
412
|
+
unread_count?: number | null;
|
|
374
413
|
};
|
|
375
414
|
/** Teléfono del contacto, o el identificador crudo en grupos y LIDs. / Contact phone, or the raw identifier for groups and LIDs. */
|
|
376
415
|
get id(): string;
|
|
@@ -382,6 +421,8 @@ export declare function chat(wa: WhatsApp): {
|
|
|
382
421
|
get archived(): boolean;
|
|
383
422
|
/** true si el chat está fijado. / true when the chat is pinned. */
|
|
384
423
|
get pinned(): boolean;
|
|
424
|
+
/** Mensajes sin leer del chat. / Chat's unread messages. */
|
|
425
|
+
get count(): number;
|
|
385
426
|
/** Fecha ISO UTC hasta la que el chat está silenciado, o null. / ISO UTC date until the chat stays muted, or null. */
|
|
386
427
|
get muted(): string | null;
|
|
387
428
|
}[]>;
|
|
@@ -44,6 +44,10 @@ class Chat {
|
|
|
44
44
|
get pinned() {
|
|
45
45
|
return this._raw.pinned != null;
|
|
46
46
|
}
|
|
47
|
+
/** Mensajes sin leer del chat. / Chat's unread messages. */
|
|
48
|
+
get count() {
|
|
49
|
+
return this._raw.unread_count ?? 0;
|
|
50
|
+
}
|
|
47
51
|
/** Fecha ISO UTC hasta la que el chat está silenciado, o null. / ISO UTC date until the chat stays muted, or null. */
|
|
48
52
|
get muted() {
|
|
49
53
|
const end = this._raw.mute_end_time;
|
|
@@ -95,14 +99,14 @@ function chat(wa) {
|
|
|
95
99
|
* Participantes del grupo memoizados 15s, para no repetir `groupMetadata` en cada página.
|
|
96
100
|
* Group participants memoized for 15s, avoiding a `groupMetadata` round-trip per page.
|
|
97
101
|
*/
|
|
98
|
-
const
|
|
99
|
-
function
|
|
100
|
-
if (!
|
|
102
|
+
const groups_cache = new Map();
|
|
103
|
+
function group_meta(jid) {
|
|
104
|
+
if (!groups_cache.has(jid)) {
|
|
101
105
|
const socket = (0, internal_1.internals)(wa).socket;
|
|
102
|
-
|
|
103
|
-
setTimeout(() =>
|
|
106
|
+
groups_cache.set(jid, socket ? socket.groupMetadata(jid).catch(() => ({ participants: [] })) : Promise.resolve({ participants: [] }));
|
|
107
|
+
setTimeout(() => groups_cache.delete(jid), 15_000);
|
|
104
108
|
}
|
|
105
|
-
return
|
|
109
|
+
return groups_cache.get(jid);
|
|
106
110
|
}
|
|
107
111
|
/**
|
|
108
112
|
* Contacto desde el engine, o ficha mínima local cuando no está persistido (sin red).
|
|
@@ -123,10 +127,24 @@ function chat(wa) {
|
|
|
123
127
|
*/
|
|
124
128
|
async members(offset = 0, limit = 50) {
|
|
125
129
|
const ids = this.type === 'group'
|
|
126
|
-
? (await
|
|
130
|
+
? (await group_meta(this._raw.id)).participants.map((participant) => participant.id)
|
|
127
131
|
: [this._raw.id, (0, internal_1.internals)(wa).socket?.user?.id].filter((id) => Boolean(id));
|
|
128
132
|
return Promise.all(ids.slice(offset, offset + limit).map(load_contact));
|
|
129
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Descripción del chat: el asunto del grupo o, en un 1:1, la bio del contacto.
|
|
136
|
+
* Es asíncrono porque ninguno de los dos vive en el documento del chat.
|
|
137
|
+
* Chat description: the group's subject or, on a 1:1, the contact's bio. It is async
|
|
138
|
+
* because neither of them lives in the chat document.
|
|
139
|
+
*
|
|
140
|
+
* @returns Descripción, o cadena vacía si no hay / Description, or an empty string when absent
|
|
141
|
+
*/
|
|
142
|
+
async content() {
|
|
143
|
+
if (this.type === 'group') {
|
|
144
|
+
return (await group_meta(this._raw.id)).desc ?? '';
|
|
145
|
+
}
|
|
146
|
+
return (0, store_1.deserialize)(await wa.engine.get(`/contact/${this._raw.id}`))?.status ?? '';
|
|
147
|
+
}
|
|
130
148
|
/**
|
|
131
149
|
* Mensajes del chat paginados desde el más reciente.
|
|
132
150
|
* Chat messages paginated from the most recent one.
|
|
@@ -242,6 +260,8 @@ function chat(wa) {
|
|
|
242
260
|
const socket = (0, internal_1.internals)(wa).socket;
|
|
243
261
|
if (socket) {
|
|
244
262
|
await socket.chatModify({ markRead: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id);
|
|
263
|
+
this._raw.unread_count = 0;
|
|
264
|
+
await wa.engine.set(`/chat/${this._raw.id}`, (0, store_1.serialize)(this._raw));
|
|
245
265
|
ok = true;
|
|
246
266
|
}
|
|
247
267
|
return ok;
|
|
@@ -323,4 +343,3 @@ function chat(wa) {
|
|
|
323
343
|
}
|
|
324
344
|
};
|
|
325
345
|
}
|
|
326
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -451,6 +451,12 @@ export declare class Sticker extends Message {
|
|
|
451
451
|
* Document message; the actual MIME lives in the base `mime`.
|
|
452
452
|
*/
|
|
453
453
|
export declare class Document extends Message {
|
|
454
|
+
/** @internal */
|
|
455
|
+
private get _media();
|
|
456
|
+
/** Nombre del archivo. / File name. */
|
|
457
|
+
get name(): string;
|
|
458
|
+
/** Número de páginas (PDF); 0 cuando no aplica. / Page count (PDF); 0 when not applicable. */
|
|
459
|
+
get pages(): number;
|
|
454
460
|
/** Peso en bytes. / Size in bytes. */
|
|
455
461
|
get size(): number;
|
|
456
462
|
content(): Promise<Buffer>;
|
|
@@ -92,21 +92,56 @@ async function send(wa, cid, content, binary, extra = {}, doc_overrides) {
|
|
|
92
92
|
}
|
|
93
93
|
await wa.engine.set(`/chat/${jid}/message/${sent_id}`, (0, store_1.serialize)(instance._raw), instance._raw.created_at);
|
|
94
94
|
if (binary) {
|
|
95
|
-
await wa
|
|
95
|
+
await write_content(wa, `/chat/${jid}/message/${sent_id}/content`, binary);
|
|
96
96
|
}
|
|
97
97
|
result = instance;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
return result;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Binario persistido de un documento: primero el crudo del engine y, si el driver no soporta
|
|
104
|
+
* binarios o el dato viene de una sesión anterior, el documento JSON con base64.
|
|
105
|
+
* A document's persisted binary: the engine's raw one first and, when the driver lacks binary
|
|
106
|
+
* support or the data comes from an older session, the base64 JSON document.
|
|
107
|
+
*
|
|
108
|
+
* @param wa - Cliente dueño / Owner client
|
|
109
|
+
* @param path - Ruta del contenido / Content path
|
|
110
|
+
* @returns Binario o null / Binary or null
|
|
111
|
+
*/
|
|
112
|
+
async function read_content(wa, path) {
|
|
113
|
+
const raw = await wa.engine.get_buffer?.(path);
|
|
114
|
+
if (raw?.length) {
|
|
115
|
+
return raw;
|
|
116
|
+
}
|
|
117
|
+
const legacy = (0, store_1.deserialize)(await wa.engine.get(path));
|
|
118
|
+
return legacy?.data ? Buffer.from(legacy.data, 'base64') : null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Persiste el binario de un documento: crudo cuando el driver lo soporta, JSON con base64
|
|
122
|
+
* en caso contrario.
|
|
123
|
+
* Persists a document's binary: raw when the driver supports it, base64 JSON otherwise.
|
|
124
|
+
*
|
|
125
|
+
* @param wa - Cliente dueño / Owner client
|
|
126
|
+
* @param path - Ruta del contenido / Content path
|
|
127
|
+
* @param data - Binario a guardar / Binary to store
|
|
128
|
+
*/
|
|
129
|
+
async function write_content(wa, path, data) {
|
|
130
|
+
if (wa.engine.set_buffer) {
|
|
131
|
+
await wa.engine.set_buffer(path, data);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
await wa.engine.set(path, (0, store_1.serialize)({ data: data.toString('base64') }));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
102
137
|
/**
|
|
103
138
|
* Stream del binario del mensaje: cache del engine o descarga de baileys.
|
|
104
139
|
* Message binary stream: engine cache or baileys download.
|
|
105
140
|
*/
|
|
106
141
|
async function media_stream(wa, doc) {
|
|
107
|
-
const cached = (
|
|
108
|
-
if (cached
|
|
109
|
-
return node_stream_1.Readable.from(
|
|
142
|
+
const cached = await read_content(wa, `/chat/${doc.cid}/message/${doc.id}/content`);
|
|
143
|
+
if (cached) {
|
|
144
|
+
return node_stream_1.Readable.from(cached);
|
|
110
145
|
}
|
|
111
146
|
const socket = (0, internal_1.internals)(wa).socket;
|
|
112
147
|
if (socket) {
|
|
@@ -259,8 +294,7 @@ class Message {
|
|
|
259
294
|
* @returns Buffer del contenido / Content buffer
|
|
260
295
|
*/
|
|
261
296
|
async content() {
|
|
262
|
-
|
|
263
|
-
return cached?.data ? Buffer.from(cached.data, 'base64') : Buffer.alloc(0);
|
|
297
|
+
return (await read_content(this._wa, `/chat/${this._raw.cid}/message/${this._raw.id}/content`)) ?? Buffer.alloc(0);
|
|
264
298
|
}
|
|
265
299
|
/**
|
|
266
300
|
* Stream del contenido; para media descarga de baileys si el cache falta.
|
|
@@ -789,10 +823,21 @@ exports.Sticker = Sticker;
|
|
|
789
823
|
* Document message; the actual MIME lives in the base `mime`.
|
|
790
824
|
*/
|
|
791
825
|
class Document extends Message {
|
|
826
|
+
/** @internal */
|
|
827
|
+
get _media() {
|
|
828
|
+
return unwrap(this._raw.raw.message ?? {}).documentMessage;
|
|
829
|
+
}
|
|
830
|
+
/** Nombre del archivo. / File name. */
|
|
831
|
+
get name() {
|
|
832
|
+
return this._media?.fileName ?? '';
|
|
833
|
+
}
|
|
834
|
+
/** Número de páginas (PDF); 0 cuando no aplica. / Page count (PDF); 0 when not applicable. */
|
|
835
|
+
get pages() {
|
|
836
|
+
return this._media?.pageCount ?? 0;
|
|
837
|
+
}
|
|
792
838
|
/** Peso en bytes. / Size in bytes. */
|
|
793
839
|
get size() {
|
|
794
|
-
|
|
795
|
-
return to_number(media?.fileLength);
|
|
840
|
+
return to_number(this._media?.fileLength);
|
|
796
841
|
}
|
|
797
842
|
async content() {
|
|
798
843
|
return drain(await this.stream());
|
|
@@ -1079,4 +1124,3 @@ function message(wa, raw) {
|
|
|
1079
1124
|
};
|
|
1080
1125
|
return new (types[doc.type] ?? Message)(wa, doc);
|
|
1081
1126
|
}
|
|
1082
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -42,6 +42,20 @@ export interface Engine {
|
|
|
42
42
|
count(path: string): Promise<number>;
|
|
43
43
|
/** Vacía completamente el almacén. / Clears the entire store. */
|
|
44
44
|
clear(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Lee un binario por path. Opcional: un driver que no lo implemente sigue siendo válido y
|
|
47
|
+
* la librería cae al documento serializado.
|
|
48
|
+
* Reads a binary by path. Optional: a driver that does not implement it stays valid and the
|
|
49
|
+
* library falls back to the serialized document.
|
|
50
|
+
*/
|
|
51
|
+
get_buffer?(path: string): Promise<Buffer | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Escribe un binario sin pasar por JSON ni base64 (un 33% menos de peso y sin parseo para
|
|
54
|
+
* leerlo). Opcional, igual que `get_buffer`.
|
|
55
|
+
* Writes a binary without JSON nor base64 (33% less weight and no parsing to read it back).
|
|
56
|
+
* Optional, just like `get_buffer`.
|
|
57
|
+
*/
|
|
58
|
+
set_buffer?(path: string, data: Buffer, score?: number): Promise<void>;
|
|
45
59
|
}
|
|
46
60
|
export { FileSystemEngine } from '../../../lib/store/engine/lib/file_system';
|
|
47
61
|
export { RedisEngine, type RedisClient } from '../../../lib/store/engine/lib/redis';
|
|
@@ -15,4 +15,3 @@ var s3_1 = require("../../../lib/store/engine/lib/s3");
|
|
|
15
15
|
Object.defineProperty(exports, "S3Engine", { enumerable: true, get: function () { return s3_1.S3Engine; } });
|
|
16
16
|
var sqlite_1 = require("../../../lib/store/engine/lib/sqlite");
|
|
17
17
|
Object.defineProperty(exports, "SQLiteEngine", { enumerable: true, get: function () { return sqlite_1.SQLiteEngine; } });
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -78,6 +78,16 @@ export declare class FileSystemEngine implements Engine {
|
|
|
78
78
|
* Counts direct children with a valid document.
|
|
79
79
|
*/
|
|
80
80
|
count(path: string): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Lee el binario del documento, o null si no existe.
|
|
83
|
+
* Reads the document binary, or null when missing.
|
|
84
|
+
*/
|
|
85
|
+
get_buffer(path: string): Promise<Buffer | null>;
|
|
86
|
+
/**
|
|
87
|
+
* Escribe el binario del documento como archivo crudo, sin JSON ni base64.
|
|
88
|
+
* Writes the document binary as a raw file, with no JSON nor base64.
|
|
89
|
+
*/
|
|
90
|
+
set_buffer(path: string, data: Buffer, score?: number): Promise<void>;
|
|
81
91
|
/**
|
|
82
92
|
* Vacía completamente el almacén.
|
|
83
93
|
* Clears the entire store.
|
|
@@ -13,6 +13,8 @@ const lib_1 = require("../../../../../lib/store/engine/lib");
|
|
|
13
13
|
const INDEX_FILE = 'index.json';
|
|
14
14
|
/** Índice de orden persistido junto a los hijos del directorio. / Ordering index persisted next to the directory children. */
|
|
15
15
|
const ORDER_FILE = '.order';
|
|
16
|
+
/** Binario del documento, guardado crudo junto a su JSON. / Document binary, stored raw next to its JSON. */
|
|
17
|
+
const BINARY_FILE = 'content.bin';
|
|
16
18
|
/**
|
|
17
19
|
* Driver de persistencia en sistema de archivos.
|
|
18
20
|
* Cada documento se almacena como `<base>/<path>/index.json` de modo que un recurso pueda
|
|
@@ -161,6 +163,31 @@ class FileSystemEngine {
|
|
|
161
163
|
async count(path) {
|
|
162
164
|
return (await this._index(path)).size;
|
|
163
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Lee el binario del documento, o null si no existe.
|
|
168
|
+
* Reads the document binary, or null when missing.
|
|
169
|
+
*/
|
|
170
|
+
async get_buffer(path) {
|
|
171
|
+
return (0, promises_1.readFile)((0, node_path_1.join)(this._dir(path), BINARY_FILE)).catch(() => null);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Escribe el binario del documento como archivo crudo, sin JSON ni base64.
|
|
175
|
+
* Writes the document binary as a raw file, with no JSON nor base64.
|
|
176
|
+
*/
|
|
177
|
+
async set_buffer(path, data, score) {
|
|
178
|
+
const dir = this._dir(path);
|
|
179
|
+
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
180
|
+
const file = (0, node_path_1.join)(dir, BINARY_FILE);
|
|
181
|
+
const tmp = `${file}.${(0, node_crypto_1.randomBytes)(6).toString('hex')}.tmp`;
|
|
182
|
+
await (0, promises_1.writeFile)(tmp, data);
|
|
183
|
+
await (0, promises_1.rename)(tmp, file);
|
|
184
|
+
const when = score ?? Date.now();
|
|
185
|
+
if (score !== undefined) {
|
|
186
|
+
await (0, promises_1.utimes)(file, new Date(score), new Date(score)).catch(() => { });
|
|
187
|
+
}
|
|
188
|
+
const { parent, name } = (0, lib_1.split_path)(path);
|
|
189
|
+
this._indexes.get(parent)?.set(name, when);
|
|
190
|
+
}
|
|
164
191
|
/**
|
|
165
192
|
* Vacía completamente el almacén.
|
|
166
193
|
* Clears the entire store.
|
|
@@ -176,4 +203,3 @@ class FileSystemEngine {
|
|
|
176
203
|
}
|
|
177
204
|
}
|
|
178
205
|
exports.FileSystemEngine = FileSystemEngine;
|
|
179
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -13,18 +13,20 @@ import type { Engine } from '../../../../../lib/store/engine';
|
|
|
13
13
|
export interface RedisClient {
|
|
14
14
|
get(key: string): Promise<string | null>;
|
|
15
15
|
set(key: string, value: string): Promise<unknown>;
|
|
16
|
-
del(keys:
|
|
16
|
+
del(...keys: unknown[]): Promise<unknown>;
|
|
17
17
|
mget(keys: string[]): Promise<(string | null)[]>;
|
|
18
18
|
scan(cursor: number | string, ...args: unknown[]): Promise<[string, string[]]>;
|
|
19
19
|
zadd(key: string, score: number, member: string): Promise<unknown>;
|
|
20
|
-
zrem(
|
|
20
|
+
zrem(...args: unknown[]): Promise<unknown>;
|
|
21
21
|
zrevrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
22
22
|
zcard(key: string): Promise<number>;
|
|
23
|
+
getBuffer?(...args: unknown[]): Promise<Buffer | null>;
|
|
24
|
+
setBuffer?(...args: unknown[]): Promise<unknown>;
|
|
23
25
|
pipeline?(): {
|
|
24
26
|
set(key: string, value: string): unknown;
|
|
25
|
-
del(keys:
|
|
27
|
+
del(...keys: unknown[]): unknown;
|
|
26
28
|
zadd(key: string, score: number, member: string): unknown;
|
|
27
|
-
zrem(
|
|
29
|
+
zrem(...args: unknown[]): unknown;
|
|
28
30
|
exec(): Promise<unknown>;
|
|
29
31
|
};
|
|
30
32
|
}
|
|
@@ -82,6 +84,18 @@ export declare class RedisEngine implements Engine {
|
|
|
82
84
|
* Counts direct children in O(1) via ZCARD.
|
|
83
85
|
*/
|
|
84
86
|
count(path: string): Promise<number>;
|
|
87
|
+
/**
|
|
88
|
+
* Lee el binario del documento. Requiere un cliente con soporte de buffers (ioredis lo
|
|
89
|
+
* trae con `getBuffer`); sin él la librería cae al documento serializado.
|
|
90
|
+
* Reads the document binary. Requires a buffer-capable client (ioredis ships `getBuffer`);
|
|
91
|
+
* without it the library falls back to the serialized document.
|
|
92
|
+
*/
|
|
93
|
+
get_buffer(path: string): Promise<Buffer | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Escribe el binario del documento en su propia key, sin JSON ni base64.
|
|
96
|
+
* Writes the document binary in its own key, with no JSON nor base64.
|
|
97
|
+
*/
|
|
98
|
+
set_buffer(path: string, data: Buffer, score?: number): Promise<void>;
|
|
85
99
|
/**
|
|
86
100
|
* Vacía todo el prefix del cliente.
|
|
87
101
|
* Clears the entire client prefix.
|
|
@@ -78,12 +78,12 @@ class RedisEngine {
|
|
|
78
78
|
const full = (0, lib_1.normalize_path)(path);
|
|
79
79
|
const pipeline = this._client.pipeline?.();
|
|
80
80
|
if (pipeline) {
|
|
81
|
-
pipeline.del(this._doc_key(full));
|
|
81
|
+
pipeline.del([this._doc_key(full), `${this._doc_key(full)}:bin`]);
|
|
82
82
|
pipeline.zrem(this._idx_key(parent), full);
|
|
83
83
|
await pipeline.exec();
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
await this._client.del(this._doc_key(full));
|
|
86
|
+
await this._client.del([this._doc_key(full), `${this._doc_key(full)}:bin`]);
|
|
87
87
|
await this._client.zrem(this._idx_key(parent), full);
|
|
88
88
|
}
|
|
89
89
|
await Promise.all([
|
|
@@ -112,6 +112,25 @@ class RedisEngine {
|
|
|
112
112
|
async count(path) {
|
|
113
113
|
return this._client.zcard(this._idx_key(path));
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Lee el binario del documento. Requiere un cliente con soporte de buffers (ioredis lo
|
|
117
|
+
* trae con `getBuffer`); sin él la librería cae al documento serializado.
|
|
118
|
+
* Reads the document binary. Requires a buffer-capable client (ioredis ships `getBuffer`);
|
|
119
|
+
* without it the library falls back to the serialized document.
|
|
120
|
+
*/
|
|
121
|
+
async get_buffer(path) {
|
|
122
|
+
return (await this._client.getBuffer?.(`${this._doc_key(path)}:bin`)) ?? null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Escribe el binario del documento en su propia key, sin JSON ni base64.
|
|
126
|
+
* Writes the document binary in its own key, with no JSON nor base64.
|
|
127
|
+
*/
|
|
128
|
+
async set_buffer(path, data, score) {
|
|
129
|
+
const { parent } = (0, lib_1.split_path)(path);
|
|
130
|
+
const full = (0, lib_1.normalize_path)(path);
|
|
131
|
+
await this._client.setBuffer?.(`${this._doc_key(full)}:bin`, data);
|
|
132
|
+
await this._client.zadd(this._idx_key(parent), score ?? Date.now(), full);
|
|
133
|
+
}
|
|
115
134
|
/**
|
|
116
135
|
* Vacía todo el prefix del cliente.
|
|
117
136
|
* Clears the entire client prefix.
|
|
@@ -137,4 +156,3 @@ class RedisEngine {
|
|
|
137
156
|
}
|
|
138
157
|
}
|
|
139
158
|
exports.RedisEngine = RedisEngine;
|
|
140
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -33,14 +33,14 @@ export interface SQLiteDatabase {
|
|
|
33
33
|
* resuelven a mano: `list` es un `ORDER BY score DESC LIMIT/OFFSET` sobre el índice (sin
|
|
34
34
|
* índice en memoria ni archivo de orden), `count` un `COUNT(*)` y el `unset` en cascada una
|
|
35
35
|
* sola sentencia por rango de `path`. Medido sobre un chat real de 55.146 mensajes frente al
|
|
36
|
-
* filesystem: 220 MB →
|
|
36
|
+
* filesystem: 220 MB → 64 MB en disco, primer `list` 115 ms → 0,6 ms y dos archivos en total.
|
|
37
37
|
*
|
|
38
38
|
* SQLite persistence driver: a single `(path, parent, score, value)` table with a
|
|
39
39
|
* `(parent, score DESC)` index. The most efficient built-in driver, since it delegates to the
|
|
40
40
|
* engine what the others hand-roll: `list` is an indexed `ORDER BY score DESC LIMIT/OFFSET`
|
|
41
41
|
* (no in-memory index, no order file), `count` a `COUNT(*)` and cascading `unset` a single
|
|
42
42
|
* range statement. Measured on a real 55,146-message chat against the filesystem: 220 MB →
|
|
43
|
-
*
|
|
43
|
+
* 64 MB on disk, first `list` 115 ms → 0.6 ms and two files in total.
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* import Database from 'better-sqlite3';
|
|
@@ -58,6 +58,8 @@ export declare class SQLiteEngine implements Engine {
|
|
|
58
58
|
private readonly _page;
|
|
59
59
|
private readonly _total;
|
|
60
60
|
private readonly _wipe;
|
|
61
|
+
private readonly _read_blob;
|
|
62
|
+
private readonly _write_blob;
|
|
61
63
|
/**
|
|
62
64
|
* @param _db - Base SQLite ya abierta / Already open SQLite database
|
|
63
65
|
* @param table - Tabla donde viven los documentos / Table holding the documents
|
|
@@ -89,6 +91,16 @@ export declare class SQLiteEngine implements Engine {
|
|
|
89
91
|
* Counts direct children.
|
|
90
92
|
*/
|
|
91
93
|
count(path: string): Promise<number>;
|
|
94
|
+
/**
|
|
95
|
+
* Lee el binario del documento, o null si la fila no lo tiene.
|
|
96
|
+
* Reads the document binary, or null when the row has none.
|
|
97
|
+
*/
|
|
98
|
+
get_buffer(path: string): Promise<Buffer | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Escribe el binario del documento como BLOB, sin JSON ni base64.
|
|
101
|
+
* Writes the document binary as a BLOB, with no JSON nor base64.
|
|
102
|
+
*/
|
|
103
|
+
set_buffer(path: string, data: Buffer, score?: number): Promise<void>;
|
|
92
104
|
/**
|
|
93
105
|
* Vacía la tabla completa.
|
|
94
106
|
* Clears the entire table.
|