@arcaelas/whatsapp 4.5.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.d.ts +6 -4
- package/build/cjs/index.js +22 -3
- package/build/cjs/lib/bot/decorator.d.ts +2 -0
- package/build/cjs/lib/bot/decorator.js +6 -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 +381 -204
- package/build/cjs/lib/chat/index.js +243 -212
- package/build/cjs/lib/contact/index.d.ts +162 -179
- package/build/cjs/lib/contact/index.js +96 -191
- package/build/cjs/lib/internal.d.ts +40 -0
- package/build/cjs/lib/internal.js +38 -0
- package/build/cjs/lib/message/index.d.ts +468 -289
- package/build/cjs/lib/message/index.js +871 -743
- package/build/cjs/lib/status/index.d.ts +60 -70
- package/build/cjs/lib/status/index.js +106 -112
- package/build/cjs/lib/store/engine/index.d.ts +35 -7
- package/build/cjs/lib/store/engine/index.js +6 -4
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +48 -8
- package/build/cjs/lib/store/engine/lib/file_system/index.js +117 -66
- package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
- package/build/cjs/lib/store/engine/lib/index.js +212 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +44 -15
- package/build/cjs/lib/store/engine/lib/redis/index.js +75 -43
- package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/cjs/lib/store/engine/lib/s3/index.js +112 -65
- package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +110 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js +132 -0
- package/build/cjs/lib/store/index.d.ts +7 -3
- package/build/cjs/lib/store/index.js +14 -5
- package/build/cjs/lib/whatsapp/index.d.ts +106 -68
- package/build/cjs/lib/whatsapp/index.js +393 -167
- package/build/esm/decorators.js +0 -1
- package/build/esm/index.d.ts +6 -4
- package/build/esm/index.js +5 -3
- package/build/esm/lib/bot/decorator.d.ts +2 -0
- package/build/esm/lib/bot/decorator.js +6 -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 +381 -204
- package/build/esm/lib/chat/index.js +243 -212
- package/build/esm/lib/contact/index.d.ts +162 -179
- package/build/esm/lib/contact/index.js +96 -190
- package/build/esm/lib/internal.d.ts +40 -0
- package/build/esm/lib/internal.js +34 -0
- package/build/esm/lib/message/index.d.ts +468 -289
- package/build/esm/lib/message/index.js +866 -738
- package/build/esm/lib/status/index.d.ts +60 -70
- package/build/esm/lib/status/index.js +105 -111
- package/build/esm/lib/store/engine/index.d.ts +35 -7
- package/build/esm/lib/store/engine/index.js +4 -3
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +48 -8
- package/build/esm/lib/store/engine/lib/file_system/index.js +117 -66
- package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
- package/build/esm/lib/store/engine/lib/index.js +205 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +44 -15
- package/build/esm/lib/store/engine/lib/redis/index.js +73 -41
- package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/esm/lib/store/engine/lib/s3/index.js +111 -64
- package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +110 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js +128 -0
- package/build/esm/lib/store/index.d.ts +7 -3
- package/build/esm/lib/store/index.js +13 -5
- package/build/esm/lib/whatsapp/index.d.ts +106 -68
- package/build/esm/lib/whatsapp/index.js +395 -169
- package/package.json +25 -6
- 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/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/redis/index.js.map +0 -1
- package/build/cjs/lib/store/engine/lib/s3/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 -71
- 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/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/redis/index.js.map +0 -1
- package/build/esm/lib/store/engine/lib/s3/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 -66
- package/build/esm/test.js.map +0 -1
|
@@ -1,85 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file status/index.ts
|
|
3
|
-
* @description Entidad
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* lifecycle (24h TTL, no quoting, no editing, no starring/forward).
|
|
3
|
+
* @description Entidad Feed — publicación del status broadcast (`status@broadcast`) como
|
|
4
|
+
* subclase de Message: hereda author/chat/content/stream y anula lo que un status no soporta.
|
|
5
|
+
* Feed entity — status broadcast post as a Message subclass: inherits
|
|
6
|
+
* author/chat/content/stream and voids what a status does not support.
|
|
8
7
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { Contact } from '../../lib/contact/index.js';
|
|
8
|
+
import type { WAMessage } from 'baileys';
|
|
9
|
+
import { Message } from '../../lib/message/index.js';
|
|
12
10
|
import type { WhatsApp } from '../../lib/whatsapp/index.js';
|
|
13
|
-
/** Tipos soportados por un status broadcast. / Status broadcast supported types. */
|
|
14
|
-
export type FeedType = 'text' | 'image' | 'video' | 'audio';
|
|
15
|
-
/**
|
|
16
|
-
* Documento persistido del status.
|
|
17
|
-
* Persisted status document.
|
|
18
|
-
*/
|
|
19
|
-
export interface IFeedRaw {
|
|
20
|
-
id: string;
|
|
21
|
-
author_jid: string;
|
|
22
|
-
type: FeedType;
|
|
23
|
-
caption: string;
|
|
24
|
-
mime: string;
|
|
25
|
-
created_at: number;
|
|
26
|
-
expires_at: number;
|
|
27
|
-
viewed: boolean;
|
|
28
|
-
raw: WAMessage;
|
|
29
|
-
}
|
|
30
11
|
/** Vida útil del status: 24 horas en ms. / Status lifetime: 24h in ms. */
|
|
31
12
|
export declare const TTL_MS: number;
|
|
32
13
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
14
|
+
* Publicación del status broadcast. El documento del status se adapta al shape de
|
|
15
|
+
* Message en el constructor (`cid` fijo a `status@broadcast`, `author` desde
|
|
16
|
+
* `author_jid`, `deleted_at` desde `expires_at`), así los getters heredados aplican
|
|
17
|
+
* tal cual.
|
|
18
|
+
* Status broadcast post. The status document is adapted to the Message shape in the
|
|
19
|
+
* constructor (`cid` pinned to `status@broadcast`, `author` from `author_jid`,
|
|
20
|
+
* `deleted_at` from `expires_at`), so inherited getters apply as-is.
|
|
36
21
|
*/
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
export declare class Feed extends Message {
|
|
23
|
+
constructor(wa: WhatsApp, doc: {
|
|
24
|
+
id: string;
|
|
25
|
+
author_jid: string;
|
|
26
|
+
type: 'text' | 'image' | 'video' | 'audio';
|
|
27
|
+
caption: string;
|
|
28
|
+
mime: string;
|
|
29
|
+
created_at: number;
|
|
30
|
+
expires_at: number;
|
|
31
|
+
viewed: boolean;
|
|
32
|
+
raw: WAMessage;
|
|
47
33
|
});
|
|
48
|
-
/** Identificador del status (mid). / Status id (mid). */
|
|
49
|
-
get id(): string;
|
|
50
|
-
/** Tipo de contenido. / Content type. */
|
|
51
|
-
get type(): FeedType;
|
|
52
34
|
/** true si ya enviamos read receipt sobre este status. / true once a read receipt was sent. */
|
|
53
35
|
get viewed(): boolean;
|
|
54
|
-
/** Texto / caption del status. / Status text or caption. */
|
|
55
|
-
get caption(): string;
|
|
56
|
-
/** Epoch ms de publicación. / Publication epoch ms. */
|
|
57
|
-
get created_at(): number;
|
|
58
|
-
/** Epoch ms de expiración (created_at + 24h). / Expiration epoch ms (created_at + 24h). */
|
|
59
|
-
get expires_at(): number;
|
|
60
|
-
/**
|
|
61
|
-
* Resuelve el autor del status. Memoizado a nivel de instancia: la primera
|
|
62
|
-
* llamada va al engine vía `wa.Contact.get`; las siguientes devuelven la misma
|
|
63
|
-
* instancia sin volver a leer.
|
|
64
|
-
* Resolves the status author. Instance-memoized: first call hits the engine
|
|
65
|
-
* via `wa.Contact.get`; subsequent calls return the cached instance.
|
|
66
|
-
*/
|
|
67
|
-
author(): Promise<Contact>;
|
|
68
|
-
/**
|
|
69
|
-
* Stream progresivo del contenido. Para texto envuelve el caption; para media
|
|
70
|
-
* lee del cache del engine y, si falta, descarga desde baileys.
|
|
71
|
-
* Progressive content stream. For text wraps the caption; for media reads the
|
|
72
|
-
* engine cache and falls back to baileys download.
|
|
73
|
-
*/
|
|
74
|
-
stream(): Promise<Readable>;
|
|
75
|
-
/**
|
|
76
|
-
* Acumula el stream del status en un Buffer.
|
|
77
|
-
* Drains the status stream into a Buffer.
|
|
78
|
-
*/
|
|
79
|
-
content(): Promise<Buffer>;
|
|
80
36
|
/**
|
|
81
|
-
* Marca el status como visto enviando read receipt
|
|
82
|
-
* Marks the status as seen sending a read receipt
|
|
37
|
+
* Marca el status como visto enviando read receipt y persiste `viewed`.
|
|
38
|
+
* Marks the status as seen sending a read receipt and persists `viewed`.
|
|
39
|
+
*
|
|
40
|
+
* @returns true si se envió / true when sent
|
|
83
41
|
*/
|
|
84
42
|
view(): Promise<boolean>;
|
|
43
|
+
/** Un status marca visto con `view()`. / A status marks seen via `view()`. */
|
|
44
|
+
seen(): Promise<boolean>;
|
|
45
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
46
|
+
message(): Promise<never>;
|
|
47
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
48
|
+
react(): Promise<never>;
|
|
49
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
50
|
+
star(): Promise<never>;
|
|
51
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
52
|
+
edit(): Promise<never>;
|
|
53
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
54
|
+
forward(): Promise<never>;
|
|
55
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
56
|
+
delete(): Promise<never>;
|
|
57
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
58
|
+
text(): Promise<never>;
|
|
59
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
60
|
+
image(): Promise<never>;
|
|
61
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
62
|
+
video(): Promise<never>;
|
|
63
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
64
|
+
audio(): Promise<never>;
|
|
65
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
66
|
+
location(): Promise<never>;
|
|
67
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
68
|
+
poll(): Promise<never>;
|
|
69
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
70
|
+
document(): Promise<never>;
|
|
71
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
72
|
+
vcard(): Promise<never>;
|
|
73
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
74
|
+
event(): Promise<never>;
|
|
85
75
|
}
|
|
@@ -1,133 +1,127 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file status/index.ts
|
|
3
|
-
* @description Entidad
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* lifecycle (24h TTL, no quoting, no editing, no starring/forward).
|
|
3
|
+
* @description Entidad Feed — publicación del status broadcast (`status@broadcast`) como
|
|
4
|
+
* subclase de Message: hereda author/chat/content/stream y anula lo que un status no soporta.
|
|
5
|
+
* Feed entity — status broadcast post as a Message subclass: inherits
|
|
6
|
+
* author/chat/content/stream and voids what a status does not support.
|
|
8
7
|
*/
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { internals } from '../../lib/internal.js';
|
|
9
|
+
import { Message } from '../../lib/message/index.js';
|
|
10
|
+
import { serialize } from '../../lib/store/index.js';
|
|
12
11
|
/** Vida útil del status: 24 horas en ms. / Status lifetime: 24h in ms. */
|
|
13
12
|
export const TTL_MS = 24 * 60 * 60 * 1000;
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* Publicación del status broadcast. El documento del status se adapta al shape de
|
|
15
|
+
* Message en el constructor (`cid` fijo a `status@broadcast`, `author` desde
|
|
16
|
+
* `author_jid`, `deleted_at` desde `expires_at`), así los getters heredados aplican
|
|
17
|
+
* tal cual.
|
|
18
|
+
* Status broadcast post. The status document is adapted to the Message shape in the
|
|
19
|
+
* constructor (`cid` pinned to `status@broadcast`, `author` from `author_jid`,
|
|
20
|
+
* `deleted_at` from `expires_at`), so inherited getters apply as-is.
|
|
18
21
|
*/
|
|
19
|
-
export
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
export class Feed extends Message {
|
|
23
|
+
constructor(wa, doc) {
|
|
24
|
+
super(wa, {
|
|
25
|
+
...doc,
|
|
26
|
+
cid: 'status@broadcast',
|
|
27
|
+
mid: null,
|
|
28
|
+
me: false,
|
|
29
|
+
author: doc.author_jid,
|
|
30
|
+
status: 1,
|
|
31
|
+
starred: false,
|
|
32
|
+
forwarded: false,
|
|
33
|
+
deleted_at: doc.expires_at,
|
|
34
|
+
edited: false,
|
|
35
|
+
});
|
|
33
36
|
}
|
|
34
37
|
/** true si ya enviamos read receipt sobre este status. / true once a read receipt was sent. */
|
|
35
38
|
get viewed() {
|
|
36
|
-
return this.
|
|
37
|
-
}
|
|
38
|
-
/** Texto / caption del status. / Status text or caption. */
|
|
39
|
-
get caption() {
|
|
40
|
-
return this._doc.caption;
|
|
41
|
-
}
|
|
42
|
-
/** Epoch ms de publicación. / Publication epoch ms. */
|
|
43
|
-
get created_at() {
|
|
44
|
-
return this._doc.created_at;
|
|
45
|
-
}
|
|
46
|
-
/** Epoch ms de expiración (created_at + 24h). / Expiration epoch ms (created_at + 24h). */
|
|
47
|
-
get expires_at() {
|
|
48
|
-
return this._doc.expires_at;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Resuelve el autor del status. Memoizado a nivel de instancia: la primera
|
|
52
|
-
* llamada va al engine vía `wa.Contact.get`; las siguientes devuelven la misma
|
|
53
|
-
* instancia sin volver a leer.
|
|
54
|
-
* Resolves the status author. Instance-memoized: first call hits the engine
|
|
55
|
-
* via `wa.Contact.get`; subsequent calls return the cached instance.
|
|
56
|
-
*/
|
|
57
|
-
async author() {
|
|
58
|
-
return (this._author_cache ??= (async () => {
|
|
59
|
-
const { _wa, _doc } = this;
|
|
60
|
-
const fetched = await _wa.Contact.get(_doc.author_jid);
|
|
61
|
-
return (fetched ??
|
|
62
|
-
new _wa.Contact({
|
|
63
|
-
id: _doc.author_jid,
|
|
64
|
-
lid: null,
|
|
65
|
-
name: null,
|
|
66
|
-
notify: null,
|
|
67
|
-
verified_name: null,
|
|
68
|
-
img_url: null,
|
|
69
|
-
status: null,
|
|
70
|
-
}, new _wa.Chat({
|
|
71
|
-
id: _doc.author_jid,
|
|
72
|
-
name: _doc.author_jid.split('@')[0],
|
|
73
|
-
})));
|
|
74
|
-
})());
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Stream progresivo del contenido. Para texto envuelve el caption; para media
|
|
78
|
-
* lee del cache del engine y, si falta, descarga desde baileys.
|
|
79
|
-
* Progressive content stream. For text wraps the caption; for media reads the
|
|
80
|
-
* engine cache and falls back to baileys download.
|
|
81
|
-
*/
|
|
82
|
-
async stream() {
|
|
83
|
-
const { _wa, _doc } = this;
|
|
84
|
-
if (_doc.type === 'text') {
|
|
85
|
-
return Readable.from(Buffer.from(_doc.caption, 'utf-8'));
|
|
86
|
-
}
|
|
87
|
-
const cached = deserialize(await _wa.engine.get(`/status/${_doc.id}/content`));
|
|
88
|
-
if (cached?.data) {
|
|
89
|
-
return Readable.from(Buffer.from(cached.data, 'base64'));
|
|
90
|
-
}
|
|
91
|
-
if (_wa._socket) {
|
|
92
|
-
try {
|
|
93
|
-
return (await downloadMediaMessage(_doc.raw, 'stream', {}));
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
/* fallback empty */
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return Readable.from(Buffer.alloc(0));
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Acumula el stream del status en un Buffer.
|
|
103
|
-
* Drains the status stream into a Buffer.
|
|
104
|
-
*/
|
|
105
|
-
async content() {
|
|
106
|
-
const chunks = [];
|
|
107
|
-
for await (const chunk of await this.stream()) {
|
|
108
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
109
|
-
}
|
|
110
|
-
return Buffer.concat(chunks);
|
|
39
|
+
return this._raw.viewed ?? false;
|
|
111
40
|
}
|
|
112
41
|
/**
|
|
113
|
-
* Marca el status como visto enviando read receipt
|
|
114
|
-
* Marks the status as seen sending a read receipt
|
|
42
|
+
* Marca el status como visto enviando read receipt y persiste `viewed`.
|
|
43
|
+
* Marks the status as seen sending a read receipt and persists `viewed`.
|
|
44
|
+
*
|
|
45
|
+
* @returns true si se envió / true when sent
|
|
115
46
|
*/
|
|
116
47
|
async view() {
|
|
117
|
-
const { _wa, _doc } = this;
|
|
118
48
|
let ok = false;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
49
|
+
const socket = internals(this._wa).socket;
|
|
50
|
+
if (socket) {
|
|
51
|
+
if (!this.viewed) {
|
|
52
|
+
await socket.readMessages([
|
|
53
|
+
{ remoteJid: 'status@broadcast', id: this._raw.id, participant: this._raw.author },
|
|
123
54
|
]);
|
|
124
|
-
|
|
125
|
-
await _wa.engine.set(`/status/${
|
|
55
|
+
this._raw.viewed = true;
|
|
56
|
+
await this._wa.engine.set(`/status/${this._raw.id}`, serialize(this._raw));
|
|
126
57
|
}
|
|
127
|
-
_wa.
|
|
58
|
+
this._wa.emit('feed:updated', this, this._wa);
|
|
128
59
|
ok = true;
|
|
129
60
|
}
|
|
130
61
|
return ok;
|
|
131
62
|
}
|
|
63
|
+
/** Un status marca visto con `view()`. / A status marks seen via `view()`. */
|
|
64
|
+
async seen() {
|
|
65
|
+
return this.view();
|
|
66
|
+
}
|
|
67
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
68
|
+
async message() {
|
|
69
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
70
|
+
}
|
|
71
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
72
|
+
async react() {
|
|
73
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
74
|
+
}
|
|
75
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
76
|
+
async star() {
|
|
77
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
78
|
+
}
|
|
79
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
80
|
+
async edit() {
|
|
81
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
82
|
+
}
|
|
83
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
84
|
+
async forward() {
|
|
85
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
86
|
+
}
|
|
87
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
88
|
+
async delete() {
|
|
89
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
90
|
+
}
|
|
91
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
92
|
+
async text() {
|
|
93
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
94
|
+
}
|
|
95
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
96
|
+
async image() {
|
|
97
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
98
|
+
}
|
|
99
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
100
|
+
async video() {
|
|
101
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
102
|
+
}
|
|
103
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
104
|
+
async audio() {
|
|
105
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
106
|
+
}
|
|
107
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
108
|
+
async location() {
|
|
109
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
110
|
+
}
|
|
111
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
112
|
+
async poll() {
|
|
113
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
114
|
+
}
|
|
115
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
116
|
+
async document() {
|
|
117
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
118
|
+
}
|
|
119
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
120
|
+
async vcard() {
|
|
121
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
122
|
+
}
|
|
123
|
+
/** No soportado en un status. / Unsupported on a status. */
|
|
124
|
+
async event() {
|
|
125
|
+
throw new Error('ERR_FEED_UNSUPPORTED');
|
|
126
|
+
}
|
|
132
127
|
}
|
|
133
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file store/engine/index.ts
|
|
3
|
-
* @description Contrato del motor de persistencia (string-based)
|
|
4
|
-
*
|
|
3
|
+
* @description Contrato del motor de persistencia (string-based), utilidades compartidas
|
|
4
|
+
* por los drivers y barrel de implementaciones.
|
|
5
|
+
* Engine contract (string-based), shared driver utilities and implementations barrel.
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* Contrato de persistencia key-value de strings. El engine no conoce JSON; la serialización
|
|
@@ -12,24 +13,51 @@
|
|
|
12
13
|
*
|
|
13
14
|
* Reglas / Rules:
|
|
14
15
|
* - Paths se normalizan quitando slashes redundantes. / Paths strip redundant slashes.
|
|
15
|
-
* - `set`
|
|
16
|
+
* - `set` fija el score de orden: el `score` explícito cuando llega, o la hora de escritura.
|
|
17
|
+
* / `set` fixes the ordering score: the explicit `score` when given, else write time.
|
|
16
18
|
* - `unset` hace cascade sobre el sub-árbol. / `unset` cascades the subtree.
|
|
17
|
-
* - `list` solo devuelve hijos directos ordenados por
|
|
19
|
+
* - `list` solo devuelve hijos directos ordenados por score DESC. / `list` yields direct children, score DESC.
|
|
20
|
+
* - `list` y `count` cuestan O(limit) amortizado: los drivers mantienen un índice ordenado
|
|
21
|
+
* por directorio en vez de recorrer y re-ordenar el padre en cada página (ver `SortedIndex`).
|
|
22
|
+
* / `list` and `count` cost O(limit) amortized: drivers keep a per-directory sorted index
|
|
23
|
+
* instead of scanning and re-sorting the parent on every page.
|
|
18
24
|
*/
|
|
19
25
|
export interface Engine {
|
|
20
26
|
/** Lee un valor por path. Retorna null si no existe. / Reads a value by path; null if missing. */
|
|
21
27
|
get(path: string): Promise<string | null>;
|
|
22
|
-
/**
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Escribe un valor. `score` fija el orden de `list` (epoch ms del documento, ej. `created_at`);
|
|
30
|
+
* sin él se usa la hora de escritura — los re-syncs que reescriben documentos históricos DEBEN
|
|
31
|
+
* pasar el score para no destruir la cronología.
|
|
32
|
+
* Writes a value. `score` drives `list` ordering (document epoch ms, e.g. `created_at`);
|
|
33
|
+
* without it write time is used — re-syncs rewriting historical documents MUST pass the
|
|
34
|
+
* score to preserve chronology.
|
|
35
|
+
*/
|
|
36
|
+
set(path: string, value: string, score?: number): Promise<void>;
|
|
24
37
|
/** Elimina el valor y todos sus descendientes. Idempotente. / Cascade delete. Idempotent. */
|
|
25
38
|
unset(path: string): Promise<boolean>;
|
|
26
|
-
/** Lista valores de los hijos directos, paginados por
|
|
39
|
+
/** Lista valores de los hijos directos, paginados por score DESC. / Lists direct children values, score DESC. */
|
|
27
40
|
list(path: string, offset?: number, limit?: number): Promise<string[]>;
|
|
28
41
|
/** Cuenta hijos directos sin leer los valores. / Counts direct children without loading values. */
|
|
29
42
|
count(path: string): Promise<number>;
|
|
30
43
|
/** Vacía completamente el almacén. / Clears the entire store. */
|
|
31
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>;
|
|
32
59
|
}
|
|
33
60
|
export { FileSystemEngine } from '../../../lib/store/engine/lib/file_system/index.js';
|
|
34
61
|
export { RedisEngine, type RedisClient } from '../../../lib/store/engine/lib/redis/index.js';
|
|
35
62
|
export { S3Engine } from '../../../lib/store/engine/lib/s3/index.js';
|
|
63
|
+
export { SQLiteEngine, type SQLiteDatabase } from '../../../lib/store/engine/lib/sqlite/index.js';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file store/engine/index.ts
|
|
3
|
-
* @description Contrato del motor de persistencia (string-based)
|
|
4
|
-
*
|
|
3
|
+
* @description Contrato del motor de persistencia (string-based), utilidades compartidas
|
|
4
|
+
* por los drivers y barrel de implementaciones.
|
|
5
|
+
* Engine contract (string-based), shared driver utilities and implementations barrel.
|
|
5
6
|
*/
|
|
6
7
|
export { FileSystemEngine } from '../../../lib/store/engine/lib/file_system/index.js';
|
|
7
8
|
export { RedisEngine } from '../../../lib/store/engine/lib/redis/index.js';
|
|
8
9
|
export { S3Engine } from '../../../lib/store/engine/lib/s3/index.js';
|
|
9
|
-
|
|
10
|
+
export { SQLiteEngine } from '../../../lib/store/engine/lib/sqlite/index.js';
|
|
@@ -7,10 +7,22 @@ import type { Engine } from '../../../../../lib/store/engine/index.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* Driver de persistencia en sistema de archivos.
|
|
9
9
|
* Cada documento se almacena como `<base>/<path>/index.json` de modo que un recurso pueda
|
|
10
|
-
* coexistir con sub-recursos anidados.
|
|
10
|
+
* coexistir con sub-recursos anidados. Las escrituras son atómicas (tmp + rename) y el score
|
|
11
|
+
* de orden viaja en el mtime del archivo.
|
|
12
|
+
*
|
|
13
|
+
* Para que `list`/`count` cuesten O(limit) mantiene un índice ordenado por directorio
|
|
14
|
+
* (`SortedIndex`), acotado por LRU y respaldado en `<dir>/.order`: al abrir un directorio
|
|
15
|
+
* carga ese archivo y sólo reconstruye con `readdir` + `stat` cuando el conteo no coincide.
|
|
16
|
+
* Asume un único proceso escritor sobre el directorio base.
|
|
11
17
|
*
|
|
12
18
|
* Filesystem persistence driver. Each document lives at `<base>/<path>/index.json` so a
|
|
13
|
-
* resource can coexist with nested sub-resources.
|
|
19
|
+
* resource can coexist with nested sub-resources. Writes are atomic (tmp + rename) and the
|
|
20
|
+
* ordering score travels in the file mtime.
|
|
21
|
+
*
|
|
22
|
+
* To keep `list`/`count` at O(limit) it maintains a per-directory sorted index
|
|
23
|
+
* (`SortedIndex`), LRU-bounded and backed by `<dir>/.order`: opening a directory loads that
|
|
24
|
+
* file and only rebuilds via `readdir` + `stat` when the count does not match. Assumes a
|
|
25
|
+
* single writer process over the base directory.
|
|
14
26
|
*
|
|
15
27
|
* @example
|
|
16
28
|
* const engine = new FileSystemEngine('/tmp/wa');
|
|
@@ -18,29 +30,47 @@ import type { Engine } from '../../../../../lib/store/engine/index.js';
|
|
|
18
30
|
*/
|
|
19
31
|
export declare class FileSystemEngine implements Engine {
|
|
20
32
|
private readonly _base;
|
|
21
|
-
|
|
33
|
+
/** @internal Índices por directorio, acotados por LRU. / Per-directory indexes, LRU-bounded. */
|
|
34
|
+
private readonly _indexes;
|
|
35
|
+
/**
|
|
36
|
+
* @param _base - Directorio raíz del almacén / Store root directory
|
|
37
|
+
* @param cached - Directorios indexados simultáneamente en memoria / Simultaneously in-memory indexed directories
|
|
38
|
+
*/
|
|
39
|
+
constructor(_base: string, cached?: number);
|
|
22
40
|
/** @internal */
|
|
23
41
|
private _dir;
|
|
24
42
|
/** @internal */
|
|
25
43
|
private _file;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* Índice del directorio: lo toma de la caché, del `.order` persistido (validando el conteo
|
|
47
|
+
* contra `readdir`) o lo reconstruye leyendo el mtime de cada hijo.
|
|
48
|
+
* Directory index: taken from the cache, from the persisted `.order` (validating the count
|
|
49
|
+
* against `readdir`) or rebuilt reading each child's mtime.
|
|
50
|
+
*/
|
|
51
|
+
private _index;
|
|
52
|
+
/** @internal Escritura atómica: archivo temporal y rename sobre el destino. / Atomic write: temp file plus rename onto the target. */
|
|
53
|
+
private _write;
|
|
26
54
|
/**
|
|
27
55
|
* Lee el valor de un documento.
|
|
28
56
|
* Reads a document's value.
|
|
29
57
|
*/
|
|
30
58
|
get(path: string): Promise<string | null>;
|
|
31
59
|
/**
|
|
32
|
-
* Escribe el valor de un documento
|
|
33
|
-
*
|
|
60
|
+
* Escribe el valor de un documento de forma atómica creando los directorios necesarios;
|
|
61
|
+
* con `score` fija el mtime del archivo (y por tanto el orden de `list`).
|
|
62
|
+
* Atomically writes a document's value creating directories as needed; `score` fixes the
|
|
63
|
+
* file mtime (and therefore `list` ordering).
|
|
34
64
|
*/
|
|
35
|
-
set(path: string, value: string): Promise<void>;
|
|
65
|
+
set(path: string, value: string, score?: number): Promise<void>;
|
|
36
66
|
/**
|
|
37
67
|
* Elimina el documento y todos sus descendientes. Idempotente.
|
|
38
68
|
* Deletes the document and every descendant. Idempotent.
|
|
39
69
|
*/
|
|
40
70
|
unset(path: string): Promise<boolean>;
|
|
41
71
|
/**
|
|
42
|
-
* Lista los valores de los hijos directos, ordenados por
|
|
43
|
-
* Lists direct children values ordered by
|
|
72
|
+
* Lista los valores de los hijos directos, ordenados por score DESC.
|
|
73
|
+
* Lists direct children values ordered by score DESC.
|
|
44
74
|
*/
|
|
45
75
|
list(path: string, offset?: number, limit?: number): Promise<string[]>;
|
|
46
76
|
/**
|
|
@@ -48,6 +78,16 @@ export declare class FileSystemEngine implements Engine {
|
|
|
48
78
|
* Counts direct children with a valid document.
|
|
49
79
|
*/
|
|
50
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>;
|
|
51
91
|
/**
|
|
52
92
|
* Vacía completamente el almacén.
|
|
53
93
|
* Clears the entire store.
|