@arcaelas/whatsapp 4.4.0 → 5.1.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/build/cjs/index.d.ts +6 -4
- package/build/cjs/index.js +22 -2
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/lib/bot/decorator.d.ts +2 -0
- package/build/cjs/lib/bot/decorator.js +6 -0
- package/build/cjs/lib/bot/decorator.js.map +1 -1
- package/build/cjs/lib/chat/index.d.ts +340 -204
- package/build/cjs/lib/chat/index.js +225 -213
- package/build/cjs/lib/chat/index.js.map +1 -1
- package/build/cjs/lib/contact/index.d.ts +162 -179
- package/build/cjs/lib/contact/index.js +96 -190
- package/build/cjs/lib/contact/index.js.map +1 -1
- package/build/cjs/lib/internal.d.ts +40 -0
- package/build/cjs/lib/internal.js +39 -0
- package/build/cjs/lib/internal.js.map +1 -0
- package/build/cjs/lib/message/index.d.ts +463 -278
- package/build/cjs/lib/message/index.js +830 -710
- package/build/cjs/lib/message/index.js.map +1 -1
- package/build/cjs/lib/status/index.d.ts +60 -70
- package/build/cjs/lib/status/index.js +106 -111
- package/build/cjs/lib/status/index.js.map +1 -1
- package/build/cjs/lib/store/engine/index.d.ts +21 -7
- package/build/cjs/lib/store/engine/index.js +6 -3
- package/build/cjs/lib/store/engine/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/cjs/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
- package/build/cjs/lib/store/engine/lib/index.js +213 -0
- package/build/cjs/lib/store/engine/lib/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/cjs/lib/store/engine/lib/redis/index.js +56 -42
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/cjs/lib/store/engine/lib/s3/index.js +112 -64
- package/build/cjs/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js +114 -0
- package/build/cjs/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +7 -3
- package/build/cjs/lib/store/index.js +14 -4
- package/build/cjs/lib/store/index.js.map +1 -1
- package/build/cjs/lib/whatsapp/index.d.ts +117 -63
- package/build/cjs/lib/whatsapp/index.js +404 -184
- package/build/cjs/lib/whatsapp/index.js.map +1 -1
- package/build/cjs/test.d.ts +1 -0
- package/build/cjs/test.js +72 -0
- package/build/cjs/test.js.map +1 -0
- package/build/esm/index.d.ts +6 -4
- package/build/esm/index.js +5 -2
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/bot/decorator.d.ts +2 -0
- package/build/esm/lib/bot/decorator.js +6 -0
- package/build/esm/lib/bot/decorator.js.map +1 -1
- package/build/esm/lib/chat/index.d.ts +340 -204
- package/build/esm/lib/chat/index.js +225 -213
- package/build/esm/lib/chat/index.js.map +1 -1
- package/build/esm/lib/contact/index.d.ts +162 -179
- package/build/esm/lib/contact/index.js +96 -189
- package/build/esm/lib/contact/index.js.map +1 -1
- package/build/esm/lib/internal.d.ts +40 -0
- package/build/esm/lib/internal.js +35 -0
- package/build/esm/lib/internal.js.map +1 -0
- package/build/esm/lib/message/index.d.ts +463 -278
- package/build/esm/lib/message/index.js +825 -705
- package/build/esm/lib/message/index.js.map +1 -1
- package/build/esm/lib/status/index.d.ts +60 -70
- package/build/esm/lib/status/index.js +105 -110
- package/build/esm/lib/status/index.js.map +1 -1
- package/build/esm/lib/store/engine/index.d.ts +21 -7
- package/build/esm/lib/store/engine/index.js +4 -2
- package/build/esm/lib/store/engine/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +38 -8
- package/build/esm/lib/store/engine/lib/file_system/index.js +92 -67
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
- package/build/esm/lib/store/engine/lib/index.js +206 -0
- package/build/esm/lib/store/engine/lib/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +28 -13
- package/build/esm/lib/store/engine/lib/redis/index.js +54 -40
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
- package/build/esm/lib/store/engine/lib/s3/index.js +111 -63
- package/build/esm/lib/store/engine/lib/s3/index.js.map +1 -1
- package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +98 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js +110 -0
- package/build/esm/lib/store/engine/lib/sqlite/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +7 -3
- package/build/esm/lib/store/index.js +13 -4
- package/build/esm/lib/store/index.js.map +1 -1
- package/build/esm/lib/whatsapp/index.d.ts +117 -63
- package/build/esm/lib/whatsapp/index.js +406 -186
- package/build/esm/lib/whatsapp/index.js.map +1 -1
- package/build/esm/test.d.ts +1 -0
- package/build/esm/test.js +67 -0
- package/build/esm/test.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,9 +1,11 @@
|
|
|
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';
|
|
10
|
+
export { SQLiteEngine } from '../../../lib/store/engine/lib/sqlite/index.js';
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/store/engine/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/store/engine/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+CH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAoB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAuB,MAAM,+BAA+B,CAAC"}
|
|
@@ -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
|
/**
|
|
@@ -3,31 +3,45 @@
|
|
|
3
3
|
* @description Driver de persistencia en sistema de archivos local.
|
|
4
4
|
* Local filesystem persistence driver.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { randomBytes } from 'node:crypto';
|
|
7
|
+
import { mkdir, readdir, readFile, rename, rm, stat, utimes, writeFile } from 'node:fs/promises';
|
|
7
8
|
import { join } from 'node:path';
|
|
9
|
+
import { IndexCache, normalize_path, SortedIndex, split_path } from '../../../../../lib/store/engine/lib/index.js';
|
|
8
10
|
const INDEX_FILE = 'index.json';
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
* Normalizes a path by collapsing redundant slashes.
|
|
12
|
-
*/
|
|
13
|
-
function normalize_path(path) {
|
|
14
|
-
return path.replace(/\/+/g, '/').replace(/^\/|\/$/g, '');
|
|
15
|
-
}
|
|
11
|
+
/** Índice de orden persistido junto a los hijos del directorio. / Ordering index persisted next to the directory children. */
|
|
12
|
+
const ORDER_FILE = '.order';
|
|
16
13
|
/**
|
|
17
14
|
* Driver de persistencia en sistema de archivos.
|
|
18
15
|
* Cada documento se almacena como `<base>/<path>/index.json` de modo que un recurso pueda
|
|
19
|
-
* coexistir con sub-recursos anidados.
|
|
16
|
+
* coexistir con sub-recursos anidados. Las escrituras son atómicas (tmp + rename) y el score
|
|
17
|
+
* de orden viaja en el mtime del archivo.
|
|
18
|
+
*
|
|
19
|
+
* Para que `list`/`count` cuesten O(limit) mantiene un índice ordenado por directorio
|
|
20
|
+
* (`SortedIndex`), acotado por LRU y respaldado en `<dir>/.order`: al abrir un directorio
|
|
21
|
+
* carga ese archivo y sólo reconstruye con `readdir` + `stat` cuando el conteo no coincide.
|
|
22
|
+
* Asume un único proceso escritor sobre el directorio base.
|
|
20
23
|
*
|
|
21
24
|
* Filesystem persistence driver. Each document lives at `<base>/<path>/index.json` so a
|
|
22
|
-
* resource can coexist with nested sub-resources.
|
|
25
|
+
* resource can coexist with nested sub-resources. Writes are atomic (tmp + rename) and the
|
|
26
|
+
* ordering score travels in the file mtime.
|
|
27
|
+
*
|
|
28
|
+
* To keep `list`/`count` at O(limit) it maintains a per-directory sorted index
|
|
29
|
+
* (`SortedIndex`), LRU-bounded and backed by `<dir>/.order`: opening a directory loads that
|
|
30
|
+
* file and only rebuilds via `readdir` + `stat` when the count does not match. Assumes a
|
|
31
|
+
* single writer process over the base directory.
|
|
23
32
|
*
|
|
24
33
|
* @example
|
|
25
34
|
* const engine = new FileSystemEngine('/tmp/wa');
|
|
26
35
|
* await engine.set('/chat/123', JSON.stringify({ name: 'John' }));
|
|
27
36
|
*/
|
|
28
37
|
export class FileSystemEngine {
|
|
29
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param _base - Directorio raíz del almacén / Store root directory
|
|
40
|
+
* @param cached - Directorios indexados simultáneamente en memoria / Simultaneously in-memory indexed directories
|
|
41
|
+
*/
|
|
42
|
+
constructor(_base, cached = 12) {
|
|
30
43
|
this._base = _base;
|
|
44
|
+
this._indexes = new IndexCache(cached);
|
|
31
45
|
}
|
|
32
46
|
/** @internal */
|
|
33
47
|
_dir(path) {
|
|
@@ -37,6 +51,50 @@ export class FileSystemEngine {
|
|
|
37
51
|
_file(path) {
|
|
38
52
|
return join(this._dir(path), INDEX_FILE);
|
|
39
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* Índice del directorio: lo toma de la caché, del `.order` persistido (validando el conteo
|
|
57
|
+
* contra `readdir`) o lo reconstruye leyendo el mtime de cada hijo.
|
|
58
|
+
* Directory index: taken from the cache, from the persisted `.order` (validating the count
|
|
59
|
+
* against `readdir`) or rebuilt reading each child's mtime.
|
|
60
|
+
*/
|
|
61
|
+
async _index(path) {
|
|
62
|
+
const key = normalize_path(path);
|
|
63
|
+
const cached = this._indexes.get(key);
|
|
64
|
+
if (cached) {
|
|
65
|
+
return cached;
|
|
66
|
+
}
|
|
67
|
+
const dir = join(this._base, key);
|
|
68
|
+
const index = new SortedIndex(async (entries) => {
|
|
69
|
+
await this._write(join(dir, ORDER_FILE), entries.map(([name, score]) => `${score}\t${name}`).join('\n')).catch(() => { });
|
|
70
|
+
});
|
|
71
|
+
const children = (await readdir(dir, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory());
|
|
72
|
+
const persisted = (await readFile(join(dir, ORDER_FILE), 'utf-8').catch(() => null))
|
|
73
|
+
?.split('\n')
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.map((line) => {
|
|
76
|
+
const cut = line.indexOf('\t');
|
|
77
|
+
return [line.slice(cut + 1), Number(line.slice(0, cut))];
|
|
78
|
+
});
|
|
79
|
+
if (persisted?.length === children.length) {
|
|
80
|
+
index.load(persisted);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const scanned = await Promise.all(children.map(async (entry) => {
|
|
84
|
+
const found = await stat(join(dir, entry.name, INDEX_FILE)).catch(() => null);
|
|
85
|
+
return found ? [entry.name, found.mtimeMs] : null;
|
|
86
|
+
}));
|
|
87
|
+
index.load(scanned.filter((entry) => entry !== null));
|
|
88
|
+
}
|
|
89
|
+
this._indexes.set(key, index);
|
|
90
|
+
return index;
|
|
91
|
+
}
|
|
92
|
+
/** @internal Escritura atómica: archivo temporal y rename sobre el destino. / Atomic write: temp file plus rename onto the target. */
|
|
93
|
+
async _write(file, value) {
|
|
94
|
+
const tmp = `${file}.${randomBytes(6).toString('hex')}.tmp`;
|
|
95
|
+
await writeFile(tmp, value, 'utf-8');
|
|
96
|
+
await rename(tmp, file);
|
|
97
|
+
}
|
|
40
98
|
/**
|
|
41
99
|
* Lee el valor de un documento.
|
|
42
100
|
* Reads a document's value.
|
|
@@ -50,13 +108,22 @@ export class FileSystemEngine {
|
|
|
50
108
|
}
|
|
51
109
|
}
|
|
52
110
|
/**
|
|
53
|
-
* Escribe el valor de un documento
|
|
54
|
-
*
|
|
111
|
+
* Escribe el valor de un documento de forma atómica creando los directorios necesarios;
|
|
112
|
+
* con `score` fija el mtime del archivo (y por tanto el orden de `list`).
|
|
113
|
+
* Atomically writes a document's value creating directories as needed; `score` fixes the
|
|
114
|
+
* file mtime (and therefore `list` ordering).
|
|
55
115
|
*/
|
|
56
|
-
async set(path, value) {
|
|
116
|
+
async set(path, value, score) {
|
|
57
117
|
const dir = this._dir(path);
|
|
58
118
|
await mkdir(dir, { recursive: true });
|
|
59
|
-
|
|
119
|
+
const file = join(dir, INDEX_FILE);
|
|
120
|
+
await this._write(file, value);
|
|
121
|
+
const when = score ?? Date.now();
|
|
122
|
+
if (score !== undefined) {
|
|
123
|
+
await utimes(file, new Date(score), new Date(score)).catch(() => { });
|
|
124
|
+
}
|
|
125
|
+
const { parent, name } = split_path(path);
|
|
126
|
+
this._indexes.get(parent)?.set(name, when);
|
|
60
127
|
}
|
|
61
128
|
/**
|
|
62
129
|
* Elimina el documento y todos sus descendientes. Idempotente.
|
|
@@ -69,70 +136,27 @@ export class FileSystemEngine {
|
|
|
69
136
|
catch {
|
|
70
137
|
/* idempotent */
|
|
71
138
|
}
|
|
139
|
+
const { parent, name } = split_path(path);
|
|
140
|
+
this._indexes.get(parent)?.delete(name);
|
|
141
|
+
this._indexes.drop(normalize_path(path));
|
|
72
142
|
return true;
|
|
73
143
|
}
|
|
74
144
|
/**
|
|
75
|
-
* Lista los valores de los hijos directos, ordenados por
|
|
76
|
-
* Lists direct children values ordered by
|
|
145
|
+
* Lista los valores de los hijos directos, ordenados por score DESC.
|
|
146
|
+
* Lists direct children values ordered by score DESC.
|
|
77
147
|
*/
|
|
78
148
|
async list(path, offset = 0, limit = 50) {
|
|
79
149
|
const dir = this._dir(path);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.filter((e) => e.isDirectory())
|
|
84
|
-
.map(async (entry) => {
|
|
85
|
-
const file = join(dir, entry.name, INDEX_FILE);
|
|
86
|
-
try {
|
|
87
|
-
const st = await stat(file);
|
|
88
|
-
return { file, mtime: st.mtimeMs };
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
}));
|
|
94
|
-
const valid = stats.filter((x) => x !== null);
|
|
95
|
-
valid.sort((a, b) => b.mtime - a.mtime);
|
|
96
|
-
const page = valid.slice(offset, offset + limit);
|
|
97
|
-
const values = await Promise.all(page.map(async ({ file }) => {
|
|
98
|
-
try {
|
|
99
|
-
return await readFile(file, 'utf-8');
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
}));
|
|
105
|
-
return values.filter((value) => value !== null);
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
150
|
+
const page = (await this._index(path)).page(offset, limit);
|
|
151
|
+
const values = await Promise.all(page.map((name) => readFile(join(dir, name, INDEX_FILE), 'utf-8').catch(() => null)));
|
|
152
|
+
return values.filter((value) => value !== null);
|
|
110
153
|
}
|
|
111
154
|
/**
|
|
112
155
|
* Cuenta los hijos directos que tienen un documento válido.
|
|
113
156
|
* Counts direct children with a valid document.
|
|
114
157
|
*/
|
|
115
158
|
async count(path) {
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
119
|
-
let total = 0;
|
|
120
|
-
await Promise.all(entries
|
|
121
|
-
.filter((e) => e.isDirectory())
|
|
122
|
-
.map(async (entry) => {
|
|
123
|
-
try {
|
|
124
|
-
await stat(join(dir, entry.name, INDEX_FILE));
|
|
125
|
-
total++;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
/* not a valid child doc */
|
|
129
|
-
}
|
|
130
|
-
}));
|
|
131
|
-
return total;
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
return 0;
|
|
135
|
-
}
|
|
159
|
+
return (await this._index(path)).size;
|
|
136
160
|
}
|
|
137
161
|
/**
|
|
138
162
|
* Vacía completamente el almacén.
|
|
@@ -145,6 +169,7 @@ export class FileSystemEngine {
|
|
|
145
169
|
catch {
|
|
146
170
|
/* idempotent */
|
|
147
171
|
}
|
|
172
|
+
this._indexes.clear();
|
|
148
173
|
}
|
|
149
174
|
}
|
|
150
175
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/store/engine/lib/file_system/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/store/engine/lib/file_system/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,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idas por los drivers: índice ordenado por directorio,
|
|
4
|
+
* caché LRU de índices y normalización de rutas.
|
|
5
|
+
* Shared driver utilities: per-directory sorted index, LRU index cache and path normalization.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Índice ordenado por score DESC de los hijos de un directorio, mantenido incrementalmente:
|
|
10
|
+
* `page()` recorta sin re-ordenar y `set`/`delete` reubican una sola entrada por búsqueda
|
|
11
|
+
* binaria. Persiste su contenido con el callback `_flush`, agrupando ráfagas de escritura.
|
|
12
|
+
*
|
|
13
|
+
* Score-DESC sorted index of a directory's children, kept incrementally: `page()` slices
|
|
14
|
+
* without re-sorting and `set`/`delete` relocate a single entry via binary search. Persists
|
|
15
|
+
* through the `_flush` callback, coalescing write bursts.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SortedIndex {
|
|
18
|
+
private readonly _flush;
|
|
19
|
+
private readonly _delay;
|
|
20
|
+
/** @internal Nombres ordenados por score DESC. / Names ordered by score DESC. */
|
|
21
|
+
private _order;
|
|
22
|
+
/** @internal Score vigente de cada nombre. / Current score per name. */
|
|
23
|
+
private _scores;
|
|
24
|
+
private _dirty;
|
|
25
|
+
private _timer;
|
|
26
|
+
/**
|
|
27
|
+
* @param _flush - Persiste el índice; recibe los pares ordenados / Persists the index; receives the ordered pairs
|
|
28
|
+
* @param _delay - Espera antes de persistir, agrupando ráfagas / Wait before persisting, coalescing bursts
|
|
29
|
+
*/
|
|
30
|
+
constructor(_flush: (entries: [string, number][]) => Promise<void>, _delay?: number);
|
|
31
|
+
/** Cantidad de hijos indexados. / Indexed children count. */
|
|
32
|
+
get size(): number;
|
|
33
|
+
/** Pares `[nombre, score]` en orden DESC. / `[name, score]` pairs in DESC order. */
|
|
34
|
+
get entries(): [string, number][];
|
|
35
|
+
/**
|
|
36
|
+
* Reemplaza el índice completo con las entradas dadas, ordenándolas una sola vez.
|
|
37
|
+
* Replaces the whole index with the given entries, sorting them once.
|
|
38
|
+
*/
|
|
39
|
+
load(entries: Iterable<[string, number]>): void;
|
|
40
|
+
/** Página de nombres en orden DESC, sin re-ordenar. / Page of names in DESC order, no re-sorting. */
|
|
41
|
+
page(offset: number, limit: number): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Inserta o reubica un hijo con su score, manteniendo el orden.
|
|
44
|
+
* Inserts or relocates a child with its score, keeping the order.
|
|
45
|
+
*/
|
|
46
|
+
set(name: string, score: number): void;
|
|
47
|
+
/**
|
|
48
|
+
* Quita un hijo del índice.
|
|
49
|
+
* Removes a child from the index.
|
|
50
|
+
*/
|
|
51
|
+
delete(name: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Cancela la persistencia pendiente; se usa al descartar el índice de la caché.
|
|
54
|
+
* Cancels the pending persistence; used when dropping the index from the cache.
|
|
55
|
+
*/
|
|
56
|
+
dispose(): void;
|
|
57
|
+
/** @internal Saca el nombre de la lista ordenada si estaba presente. / Detaches the name from the ordered list when present. */
|
|
58
|
+
private _detach;
|
|
59
|
+
/** @internal Primera posición cuyo score es menor o igual al dado (orden DESC). / First position whose score is lower or equal to the given one (DESC order). */
|
|
60
|
+
private _locate;
|
|
61
|
+
/** @internal Programa la persistencia diferida. / Schedules the deferred persistence. */
|
|
62
|
+
private _schedule;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
* Caché LRU de índices por directorio: mantiene acotada la memoria del driver descartando
|
|
67
|
+
* el directorio menos usado cuando se supera el límite.
|
|
68
|
+
* Per-directory LRU cache of indexes: keeps driver memory bounded by dropping the
|
|
69
|
+
* least-recently-used directory once the limit is exceeded.
|
|
70
|
+
*/
|
|
71
|
+
export declare class IndexCache {
|
|
72
|
+
private readonly _limit;
|
|
73
|
+
private readonly _cache;
|
|
74
|
+
/** @param _limit - Directorios indexados simultáneamente / Simultaneously indexed directories */
|
|
75
|
+
constructor(_limit?: number);
|
|
76
|
+
/**
|
|
77
|
+
* Índice ya cargado del directorio, marcándolo como recién usado.
|
|
78
|
+
* Already loaded index for the directory, marking it as recently used.
|
|
79
|
+
*/
|
|
80
|
+
get(key: string): SortedIndex | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Registra el índice del directorio, descartando el menos usado si se supera el límite.
|
|
83
|
+
* Registers the directory index, dropping the least used one when over the limit.
|
|
84
|
+
*/
|
|
85
|
+
set(key: string, index: SortedIndex): void;
|
|
86
|
+
/**
|
|
87
|
+
* Descarta el índice del directorio y de todo su sub-árbol.
|
|
88
|
+
* Drops the directory index and its whole subtree.
|
|
89
|
+
*/
|
|
90
|
+
drop(key: string): void;
|
|
91
|
+
/** Vacía la caché completa. / Clears the whole cache. */
|
|
92
|
+
clear(): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Normaliza un path colapsando slashes redundantes y recortando los extremos.
|
|
96
|
+
* Normalizes a path collapsing redundant slashes and trimming both ends.
|
|
97
|
+
*
|
|
98
|
+
* @param path - Ruta cruda / Raw path
|
|
99
|
+
* @returns Ruta normalizada / Normalized path
|
|
100
|
+
*/
|
|
101
|
+
export declare function normalize_path(path: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Separa una ruta normalizada en directorio padre y nombre del hijo.
|
|
104
|
+
* Splits a normalized path into parent directory and child name.
|
|
105
|
+
*
|
|
106
|
+
* @param path - Ruta a separar / Path to split
|
|
107
|
+
* @returns `{ parent, name }` / `{ parent, name }`
|
|
108
|
+
*/
|
|
109
|
+
export declare function split_path(path: string): {
|
|
110
|
+
parent: string;
|
|
111
|
+
name: string;
|
|
112
|
+
};
|