@arcaelas/whatsapp 4.5.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 +462 -289
- package/build/cjs/lib/message/index.js +825 -741
- 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 +106 -68
- package/build/cjs/lib/whatsapp/index.js +380 -170
- package/build/cjs/lib/whatsapp/index.js.map +1 -1
- package/build/cjs/test.js +5 -4
- package/build/cjs/test.js.map +1 -1
- 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 +462 -289
- package/build/esm/lib/message/index.js +820 -736
- 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 +106 -68
- package/build/esm/lib/whatsapp/index.js +382 -172
- package/build/esm/lib/whatsapp/index.js.map +1 -1
- package/build/esm/test.js +5 -4
- package/build/esm/test.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @file store/engine/index.ts
|
|
4
|
-
* @description Contrato del motor de persistencia (string-based)
|
|
5
|
-
*
|
|
4
|
+
* @description Contrato del motor de persistencia (string-based), utilidades compartidas
|
|
5
|
+
* por los drivers y barrel de implementaciones.
|
|
6
|
+
* Engine contract (string-based), shared driver utilities and implementations barrel.
|
|
6
7
|
*/
|
|
7
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.S3Engine = exports.RedisEngine = exports.FileSystemEngine = void 0;
|
|
9
|
+
exports.SQLiteEngine = exports.S3Engine = exports.RedisEngine = exports.FileSystemEngine = void 0;
|
|
9
10
|
var file_system_1 = require("../../../lib/store/engine/lib/file_system");
|
|
10
11
|
Object.defineProperty(exports, "FileSystemEngine", { enumerable: true, get: function () { return file_system_1.FileSystemEngine; } });
|
|
11
12
|
var redis_1 = require("../../../lib/store/engine/lib/redis");
|
|
12
13
|
Object.defineProperty(exports, "RedisEngine", { enumerable: true, get: function () { return redis_1.RedisEngine; } });
|
|
13
14
|
var s3_1 = require("../../../lib/store/engine/lib/s3");
|
|
14
15
|
Object.defineProperty(exports, "S3Engine", { enumerable: true, get: function () { return s3_1.S3Engine; } });
|
|
16
|
+
var sqlite_1 = require("../../../lib/store/engine/lib/sqlite");
|
|
17
|
+
Object.defineProperty(exports, "SQLiteEngine", { enumerable: true, get: function () { return sqlite_1.SQLiteEngine; } });
|
|
15
18
|
//# 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,kEAAsE;AAA7D,+GAAA,gBAAgB,OAAA;AACzB,sDAA6E;AAApE,oGAAA,WAAW,OAAA;AACpB,gDAAqD;AAA5C,8FAAA,QAAQ,OAAA;AACjB,wDAAkF;AAAzE,sGAAA,YAAY,OAAA"}
|
|
@@ -7,10 +7,22 @@ import type { Engine } from '../../../../../lib/store/engine';
|
|
|
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';
|
|
|
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
|
/**
|
|
@@ -6,40 +6,98 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.FileSystemEngine = void 0;
|
|
9
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
10
|
const promises_1 = require("node:fs/promises");
|
|
10
11
|
const node_path_1 = require("node:path");
|
|
12
|
+
const lib_1 = require("../../../../../lib/store/engine/lib");
|
|
11
13
|
const INDEX_FILE = 'index.json';
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
* Normalizes a path by collapsing redundant slashes.
|
|
15
|
-
*/
|
|
16
|
-
function normalize_path(path) {
|
|
17
|
-
return path.replace(/\/+/g, '/').replace(/^\/|\/$/g, '');
|
|
18
|
-
}
|
|
14
|
+
/** Índice de orden persistido junto a los hijos del directorio. / Ordering index persisted next to the directory children. */
|
|
15
|
+
const ORDER_FILE = '.order';
|
|
19
16
|
/**
|
|
20
17
|
* Driver de persistencia en sistema de archivos.
|
|
21
18
|
* Cada documento se almacena como `<base>/<path>/index.json` de modo que un recurso pueda
|
|
22
|
-
* coexistir con sub-recursos anidados.
|
|
19
|
+
* coexistir con sub-recursos anidados. Las escrituras son atómicas (tmp + rename) y el score
|
|
20
|
+
* de orden viaja en el mtime del archivo.
|
|
21
|
+
*
|
|
22
|
+
* Para que `list`/`count` cuesten O(limit) mantiene un índice ordenado por directorio
|
|
23
|
+
* (`SortedIndex`), acotado por LRU y respaldado en `<dir>/.order`: al abrir un directorio
|
|
24
|
+
* carga ese archivo y sólo reconstruye con `readdir` + `stat` cuando el conteo no coincide.
|
|
25
|
+
* Asume un único proceso escritor sobre el directorio base.
|
|
23
26
|
*
|
|
24
27
|
* Filesystem persistence driver. Each document lives at `<base>/<path>/index.json` so a
|
|
25
|
-
* resource can coexist with nested sub-resources.
|
|
28
|
+
* resource can coexist with nested sub-resources. Writes are atomic (tmp + rename) and the
|
|
29
|
+
* ordering score travels in the file mtime.
|
|
30
|
+
*
|
|
31
|
+
* To keep `list`/`count` at O(limit) it maintains a per-directory sorted index
|
|
32
|
+
* (`SortedIndex`), LRU-bounded and backed by `<dir>/.order`: opening a directory loads that
|
|
33
|
+
* file and only rebuilds via `readdir` + `stat` when the count does not match. Assumes a
|
|
34
|
+
* single writer process over the base directory.
|
|
26
35
|
*
|
|
27
36
|
* @example
|
|
28
37
|
* const engine = new FileSystemEngine('/tmp/wa');
|
|
29
38
|
* await engine.set('/chat/123', JSON.stringify({ name: 'John' }));
|
|
30
39
|
*/
|
|
31
40
|
class FileSystemEngine {
|
|
32
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @param _base - Directorio raíz del almacén / Store root directory
|
|
43
|
+
* @param cached - Directorios indexados simultáneamente en memoria / Simultaneously in-memory indexed directories
|
|
44
|
+
*/
|
|
45
|
+
constructor(_base, cached = 12) {
|
|
33
46
|
this._base = _base;
|
|
47
|
+
this._indexes = new lib_1.IndexCache(cached);
|
|
34
48
|
}
|
|
35
49
|
/** @internal */
|
|
36
50
|
_dir(path) {
|
|
37
|
-
return (0, node_path_1.join)(this._base, normalize_path(path));
|
|
51
|
+
return (0, node_path_1.join)(this._base, (0, lib_1.normalize_path)(path));
|
|
38
52
|
}
|
|
39
53
|
/** @internal */
|
|
40
54
|
_file(path) {
|
|
41
55
|
return (0, node_path_1.join)(this._dir(path), INDEX_FILE);
|
|
42
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
* Índice del directorio: lo toma de la caché, del `.order` persistido (validando el conteo
|
|
60
|
+
* contra `readdir`) o lo reconstruye leyendo el mtime de cada hijo.
|
|
61
|
+
* Directory index: taken from the cache, from the persisted `.order` (validating the count
|
|
62
|
+
* against `readdir`) or rebuilt reading each child's mtime.
|
|
63
|
+
*/
|
|
64
|
+
async _index(path) {
|
|
65
|
+
const key = (0, lib_1.normalize_path)(path);
|
|
66
|
+
const cached = this._indexes.get(key);
|
|
67
|
+
if (cached) {
|
|
68
|
+
return cached;
|
|
69
|
+
}
|
|
70
|
+
const dir = (0, node_path_1.join)(this._base, key);
|
|
71
|
+
const index = new lib_1.SortedIndex(async (entries) => {
|
|
72
|
+
await this._write((0, node_path_1.join)(dir, ORDER_FILE), entries.map(([name, score]) => `${score}\t${name}`).join('\n')).catch(() => { });
|
|
73
|
+
});
|
|
74
|
+
const children = (await (0, promises_1.readdir)(dir, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory());
|
|
75
|
+
const persisted = (await (0, promises_1.readFile)((0, node_path_1.join)(dir, ORDER_FILE), 'utf-8').catch(() => null))
|
|
76
|
+
?.split('\n')
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.map((line) => {
|
|
79
|
+
const cut = line.indexOf('\t');
|
|
80
|
+
return [line.slice(cut + 1), Number(line.slice(0, cut))];
|
|
81
|
+
});
|
|
82
|
+
if (persisted?.length === children.length) {
|
|
83
|
+
index.load(persisted);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const scanned = await Promise.all(children.map(async (entry) => {
|
|
87
|
+
const found = await (0, promises_1.stat)((0, node_path_1.join)(dir, entry.name, INDEX_FILE)).catch(() => null);
|
|
88
|
+
return found ? [entry.name, found.mtimeMs] : null;
|
|
89
|
+
}));
|
|
90
|
+
index.load(scanned.filter((entry) => entry !== null));
|
|
91
|
+
}
|
|
92
|
+
this._indexes.set(key, index);
|
|
93
|
+
return index;
|
|
94
|
+
}
|
|
95
|
+
/** @internal Escritura atómica: archivo temporal y rename sobre el destino. / Atomic write: temp file plus rename onto the target. */
|
|
96
|
+
async _write(file, value) {
|
|
97
|
+
const tmp = `${file}.${(0, node_crypto_1.randomBytes)(6).toString('hex')}.tmp`;
|
|
98
|
+
await (0, promises_1.writeFile)(tmp, value, 'utf-8');
|
|
99
|
+
await (0, promises_1.rename)(tmp, file);
|
|
100
|
+
}
|
|
43
101
|
/**
|
|
44
102
|
* Lee el valor de un documento.
|
|
45
103
|
* Reads a document's value.
|
|
@@ -53,13 +111,22 @@ class FileSystemEngine {
|
|
|
53
111
|
}
|
|
54
112
|
}
|
|
55
113
|
/**
|
|
56
|
-
* Escribe el valor de un documento
|
|
57
|
-
*
|
|
114
|
+
* Escribe el valor de un documento de forma atómica creando los directorios necesarios;
|
|
115
|
+
* con `score` fija el mtime del archivo (y por tanto el orden de `list`).
|
|
116
|
+
* Atomically writes a document's value creating directories as needed; `score` fixes the
|
|
117
|
+
* file mtime (and therefore `list` ordering).
|
|
58
118
|
*/
|
|
59
|
-
async set(path, value) {
|
|
119
|
+
async set(path, value, score) {
|
|
60
120
|
const dir = this._dir(path);
|
|
61
121
|
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
62
|
-
|
|
122
|
+
const file = (0, node_path_1.join)(dir, INDEX_FILE);
|
|
123
|
+
await this._write(file, value);
|
|
124
|
+
const when = score ?? Date.now();
|
|
125
|
+
if (score !== undefined) {
|
|
126
|
+
await (0, promises_1.utimes)(file, new Date(score), new Date(score)).catch(() => { });
|
|
127
|
+
}
|
|
128
|
+
const { parent, name } = (0, lib_1.split_path)(path);
|
|
129
|
+
this._indexes.get(parent)?.set(name, when);
|
|
63
130
|
}
|
|
64
131
|
/**
|
|
65
132
|
* Elimina el documento y todos sus descendientes. Idempotente.
|
|
@@ -72,70 +139,27 @@ class FileSystemEngine {
|
|
|
72
139
|
catch {
|
|
73
140
|
/* idempotent */
|
|
74
141
|
}
|
|
142
|
+
const { parent, name } = (0, lib_1.split_path)(path);
|
|
143
|
+
this._indexes.get(parent)?.delete(name);
|
|
144
|
+
this._indexes.drop((0, lib_1.normalize_path)(path));
|
|
75
145
|
return true;
|
|
76
146
|
}
|
|
77
147
|
/**
|
|
78
|
-
* Lista los valores de los hijos directos, ordenados por
|
|
79
|
-
* Lists direct children values ordered by
|
|
148
|
+
* Lista los valores de los hijos directos, ordenados por score DESC.
|
|
149
|
+
* Lists direct children values ordered by score DESC.
|
|
80
150
|
*/
|
|
81
151
|
async list(path, offset = 0, limit = 50) {
|
|
82
152
|
const dir = this._dir(path);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.filter((e) => e.isDirectory())
|
|
87
|
-
.map(async (entry) => {
|
|
88
|
-
const file = (0, node_path_1.join)(dir, entry.name, INDEX_FILE);
|
|
89
|
-
try {
|
|
90
|
-
const st = await (0, promises_1.stat)(file);
|
|
91
|
-
return { file, mtime: st.mtimeMs };
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
97
|
-
const valid = stats.filter((x) => x !== null);
|
|
98
|
-
valid.sort((a, b) => b.mtime - a.mtime);
|
|
99
|
-
const page = valid.slice(offset, offset + limit);
|
|
100
|
-
const values = await Promise.all(page.map(async ({ file }) => {
|
|
101
|
-
try {
|
|
102
|
-
return await (0, promises_1.readFile)(file, 'utf-8');
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
}));
|
|
108
|
-
return values.filter((value) => value !== null);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
153
|
+
const page = (await this._index(path)).page(offset, limit);
|
|
154
|
+
const values = await Promise.all(page.map((name) => (0, promises_1.readFile)((0, node_path_1.join)(dir, name, INDEX_FILE), 'utf-8').catch(() => null)));
|
|
155
|
+
return values.filter((value) => value !== null);
|
|
113
156
|
}
|
|
114
157
|
/**
|
|
115
158
|
* Cuenta los hijos directos que tienen un documento válido.
|
|
116
159
|
* Counts direct children with a valid document.
|
|
117
160
|
*/
|
|
118
161
|
async count(path) {
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
122
|
-
let total = 0;
|
|
123
|
-
await Promise.all(entries
|
|
124
|
-
.filter((e) => e.isDirectory())
|
|
125
|
-
.map(async (entry) => {
|
|
126
|
-
try {
|
|
127
|
-
await (0, promises_1.stat)((0, node_path_1.join)(dir, entry.name, INDEX_FILE));
|
|
128
|
-
total++;
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
/* not a valid child doc */
|
|
132
|
-
}
|
|
133
|
-
}));
|
|
134
|
-
return total;
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
return 0;
|
|
138
|
-
}
|
|
162
|
+
return (await this._index(path)).size;
|
|
139
163
|
}
|
|
140
164
|
/**
|
|
141
165
|
* Vacía completamente el almacén.
|
|
@@ -148,6 +172,7 @@ class FileSystemEngine {
|
|
|
148
172
|
catch {
|
|
149
173
|
/* idempotent */
|
|
150
174
|
}
|
|
175
|
+
this._indexes.clear();
|
|
151
176
|
}
|
|
152
177
|
}
|
|
153
178
|
exports.FileSystemEngine = FileSystemEngine;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/store/engine/lib/file_system/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/store/engine/lib/file_system/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,6CAA0C;AAC1C,+CAAiG;AACjG,yCAAiC;AAEjC,gDAA6F;AAE7F,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,8HAA8H;AAC9H,MAAM,UAAU,GAAG,QAAQ,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,gBAAgB;IAI3B;;;OAGG;IACH,YAA6B,KAAa,EAAE,MAAM,GAAG,EAAE;QAA1B,UAAK,GAAL,KAAK,CAAQ;QACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,gBAAU,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,gBAAgB;IACR,IAAI,CAAC,IAAY;QACvB,OAAO,IAAA,gBAAI,EAAC,IAAI,CAAC,KAAK,EAAE,IAAA,oBAAc,EAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;IACR,KAAK,CAAC,IAAY;QACxB,OAAO,IAAA,gBAAI,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,MAAM,CAAC,IAAY;QAC/B,MAAM,GAAG,GAAG,IAAA,oBAAc,E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AAY;QACtB,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,CAAC;YACH,MAAM,IAAA,aAAE,EAAC,IAAI,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,gBAAgB;QAClB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AArJD,4CAqJC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file store/engine/lib/index.ts
|
|
3
|
+
* @description Utilidades compartidas 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
|
+
};
|