rezo 1.0.43 → 1.0.44
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/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +9 -15
- package/dist/cache/index.js +0 -3
- package/dist/crawler/addon/decodo/index.cjs +1 -0
- package/dist/crawler/addon/decodo/index.js +1 -0
- package/dist/crawler/crawler-options.cjs +1 -0
- package/dist/crawler/crawler-options.js +1 -0
- package/dist/{plugin → crawler}/crawler.cjs +392 -32
- package/dist/{plugin → crawler}/crawler.js +392 -32
- package/dist/crawler/index.cjs +40 -0
- package/dist/{plugin → crawler}/index.js +4 -2
- package/dist/crawler/plugin/file-cacher.cjs +19 -0
- package/dist/crawler/plugin/file-cacher.js +19 -0
- package/dist/crawler/plugin/index.cjs +1 -0
- package/dist/crawler/plugin/index.js +1 -0
- package/dist/crawler/plugin/navigation-history.cjs +43 -0
- package/dist/crawler/plugin/navigation-history.js +43 -0
- package/dist/crawler/plugin/robots-txt.cjs +2 -0
- package/dist/crawler/plugin/robots-txt.js +2 -0
- package/dist/crawler/plugin/url-store.cjs +18 -0
- package/dist/crawler/plugin/url-store.js +18 -0
- package/dist/crawler.d.ts +315 -172
- package/dist/entries/crawler.cjs +5 -5
- package/dist/entries/crawler.js +2 -2
- package/dist/index.cjs +27 -27
- package/dist/internal/agents/index.cjs +10 -10
- package/dist/proxy/index.cjs +4 -4
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/universal/index.cjs +11 -11
- package/package.json +2 -6
- package/dist/cache/file-cacher.cjs +0 -270
- package/dist/cache/file-cacher.js +0 -267
- package/dist/cache/navigation-history.cjs +0 -298
- package/dist/cache/navigation-history.js +0 -296
- package/dist/cache/url-store.cjs +0 -294
- package/dist/cache/url-store.js +0 -291
- package/dist/plugin/addon/decodo/index.cjs +0 -1
- package/dist/plugin/addon/decodo/index.js +0 -1
- package/dist/plugin/crawler-options.cjs +0 -1
- package/dist/plugin/crawler-options.js +0 -1
- package/dist/plugin/index.cjs +0 -36
- /package/dist/{plugin → crawler}/addon/decodo/options.cjs +0 -0
- /package/dist/{plugin → crawler}/addon/decodo/options.js +0 -0
- /package/dist/{plugin → crawler}/addon/decodo/types.cjs +0 -0
- /package/dist/{plugin → crawler}/addon/decodo/types.js +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/index.cjs +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/index.js +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/options.cjs +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/options.js +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/types.cjs +0 -0
- /package/dist/{plugin → crawler}/addon/oxylabs/types.js +0 -0
- /package/dist/{plugin → crawler}/scraper.cjs +0 -0
- /package/dist/{plugin → crawler}/scraper.js +0 -0
package/dist/entries/crawler.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Crawler } from '../
|
|
2
|
-
export { CrawlerOptions, Domain } from '../
|
|
1
|
+
export { Crawler } from '../crawler/crawler.js';
|
|
2
|
+
export { CrawlerOptions, Domain } from '../crawler/crawler-options.js';
|
package/dist/index.cjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.Rezo =
|
|
3
|
-
exports.createRezoInstance =
|
|
4
|
-
exports.createDefaultInstance =
|
|
5
|
-
const
|
|
6
|
-
exports.RezoError =
|
|
7
|
-
exports.RezoErrorCode =
|
|
8
|
-
const
|
|
9
|
-
exports.RezoHeaders =
|
|
10
|
-
const
|
|
11
|
-
exports.RezoFormData =
|
|
12
|
-
const
|
|
13
|
-
exports.RezoCookieJar =
|
|
14
|
-
exports.Cookie =
|
|
15
|
-
const
|
|
16
|
-
exports.toCurl =
|
|
17
|
-
exports.fromCurl =
|
|
18
|
-
const
|
|
19
|
-
exports.createDefaultHooks =
|
|
20
|
-
exports.mergeHooks =
|
|
21
|
-
const
|
|
22
|
-
exports.ProxyManager =
|
|
23
|
-
const
|
|
24
|
-
exports.RezoQueue =
|
|
25
|
-
exports.HttpQueue =
|
|
26
|
-
exports.Priority =
|
|
27
|
-
exports.HttpMethodPriority =
|
|
1
|
+
const _mod_y77uk1 = require('./core/rezo.cjs');
|
|
2
|
+
exports.Rezo = _mod_y77uk1.Rezo;
|
|
3
|
+
exports.createRezoInstance = _mod_y77uk1.createRezoInstance;
|
|
4
|
+
exports.createDefaultInstance = _mod_y77uk1.createDefaultInstance;;
|
|
5
|
+
const _mod_dc3jgu = require('./errors/rezo-error.cjs');
|
|
6
|
+
exports.RezoError = _mod_dc3jgu.RezoError;
|
|
7
|
+
exports.RezoErrorCode = _mod_dc3jgu.RezoErrorCode;;
|
|
8
|
+
const _mod_o16xti = require('./utils/headers.cjs');
|
|
9
|
+
exports.RezoHeaders = _mod_o16xti.RezoHeaders;;
|
|
10
|
+
const _mod_y43k9y = require('./utils/form-data.cjs');
|
|
11
|
+
exports.RezoFormData = _mod_y43k9y.RezoFormData;;
|
|
12
|
+
const _mod_n8l01e = require('./utils/cookies.cjs');
|
|
13
|
+
exports.RezoCookieJar = _mod_n8l01e.RezoCookieJar;
|
|
14
|
+
exports.Cookie = _mod_n8l01e.Cookie;;
|
|
15
|
+
const _mod_3ypli0 = require('./utils/curl.cjs');
|
|
16
|
+
exports.toCurl = _mod_3ypli0.toCurl;
|
|
17
|
+
exports.fromCurl = _mod_3ypli0.fromCurl;;
|
|
18
|
+
const _mod_1mlx0a = require('./core/hooks.cjs');
|
|
19
|
+
exports.createDefaultHooks = _mod_1mlx0a.createDefaultHooks;
|
|
20
|
+
exports.mergeHooks = _mod_1mlx0a.mergeHooks;;
|
|
21
|
+
const _mod_xo1ifa = require('./proxy/manager.cjs');
|
|
22
|
+
exports.ProxyManager = _mod_xo1ifa.ProxyManager;;
|
|
23
|
+
const _mod_77x7bf = require('./queue/index.cjs');
|
|
24
|
+
exports.RezoQueue = _mod_77x7bf.RezoQueue;
|
|
25
|
+
exports.HttpQueue = _mod_77x7bf.HttpQueue;
|
|
26
|
+
exports.Priority = _mod_77x7bf.Priority;
|
|
27
|
+
exports.HttpMethodPriority = _mod_77x7bf.HttpMethodPriority;;
|
|
28
28
|
const { RezoError } = require('./errors/rezo-error.cjs');
|
|
29
29
|
const isRezoError = exports.isRezoError = RezoError.isRezoError;
|
|
30
30
|
const Cancel = exports.Cancel = RezoError;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.Agent =
|
|
3
|
-
const
|
|
4
|
-
exports.HttpProxyAgent =
|
|
5
|
-
const
|
|
6
|
-
exports.HttpsProxyAgent =
|
|
7
|
-
const
|
|
8
|
-
exports.SocksProxyAgent =
|
|
9
|
-
const
|
|
10
|
-
exports.SocksClient =
|
|
1
|
+
const _mod_ka4e3g = require('./base.cjs');
|
|
2
|
+
exports.Agent = _mod_ka4e3g.Agent;;
|
|
3
|
+
const _mod_nmerdf = require('./http-proxy.cjs');
|
|
4
|
+
exports.HttpProxyAgent = _mod_nmerdf.HttpProxyAgent;;
|
|
5
|
+
const _mod_do1bvj = require('./https-proxy.cjs');
|
|
6
|
+
exports.HttpsProxyAgent = _mod_do1bvj.HttpsProxyAgent;;
|
|
7
|
+
const _mod_1bn8q4 = require('./socks-proxy.cjs');
|
|
8
|
+
exports.SocksProxyAgent = _mod_1bn8q4.SocksProxyAgent;;
|
|
9
|
+
const _mod_wb9id7 = require('./socks-client.cjs');
|
|
10
|
+
exports.SocksClient = _mod_wb9id7.SocksClient;;
|
package/dist/proxy/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const { Agent, HttpProxyAgent, HttpsProxyAgent, SocksProxyAgent } = require('../internal/agents.cjs');
|
|
2
2
|
const { parseProxyString } = require('./parse.cjs');
|
|
3
|
-
const
|
|
4
|
-
exports.ProxyManager =
|
|
5
|
-
const
|
|
6
|
-
exports.parseProxyString =
|
|
3
|
+
const _mod_ecqdmn = require('./manager.cjs');
|
|
4
|
+
exports.ProxyManager = _mod_ecqdmn.ProxyManager;;
|
|
5
|
+
const _mod_4x1jdb = require('./parse.cjs');
|
|
6
|
+
exports.parseProxyString = _mod_4x1jdb.parseProxyString;;
|
|
7
7
|
function createOptions(uri, opts) {
|
|
8
8
|
if (uri instanceof URL || typeof uri === "string") {
|
|
9
9
|
return {
|
package/dist/queue/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.RezoQueue =
|
|
3
|
-
const
|
|
4
|
-
exports.HttpQueue =
|
|
5
|
-
exports.extractDomain =
|
|
6
|
-
const
|
|
7
|
-
exports.Priority =
|
|
8
|
-
exports.HttpMethodPriority =
|
|
1
|
+
const _mod_hijcy5 = require('./queue.cjs');
|
|
2
|
+
exports.RezoQueue = _mod_hijcy5.RezoQueue;;
|
|
3
|
+
const _mod_ccb3p2 = require('./http-queue.cjs');
|
|
4
|
+
exports.HttpQueue = _mod_ccb3p2.HttpQueue;
|
|
5
|
+
exports.extractDomain = _mod_ccb3p2.extractDomain;;
|
|
6
|
+
const _mod_h69bcv = require('./types.cjs');
|
|
7
|
+
exports.Priority = _mod_h69bcv.Priority;
|
|
8
|
+
exports.HttpMethodPriority = _mod_h69bcv.HttpMethodPriority;;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.UniversalEventEmitter =
|
|
3
|
-
const
|
|
4
|
-
exports.UniversalStreamResponse =
|
|
5
|
-
exports.StreamResponse =
|
|
6
|
-
const
|
|
7
|
-
exports.UniversalDownloadResponse =
|
|
8
|
-
exports.DownloadResponse =
|
|
9
|
-
const
|
|
10
|
-
exports.UniversalUploadResponse =
|
|
11
|
-
exports.UploadResponse =
|
|
1
|
+
const _mod_gfdadc = require('./event-emitter.cjs');
|
|
2
|
+
exports.UniversalEventEmitter = _mod_gfdadc.UniversalEventEmitter;;
|
|
3
|
+
const _mod_9z6wit = require('./stream.cjs');
|
|
4
|
+
exports.UniversalStreamResponse = _mod_9z6wit.UniversalStreamResponse;
|
|
5
|
+
exports.StreamResponse = _mod_9z6wit.StreamResponse;;
|
|
6
|
+
const _mod_ybfqy6 = require('./download.cjs');
|
|
7
|
+
exports.UniversalDownloadResponse = _mod_ybfqy6.UniversalDownloadResponse;
|
|
8
|
+
exports.DownloadResponse = _mod_ybfqy6.DownloadResponse;;
|
|
9
|
+
const _mod_48lipr = require('./upload.cjs');
|
|
10
|
+
exports.UniversalUploadResponse = _mod_48lipr.UniversalUploadResponse;
|
|
11
|
+
exports.UploadResponse = _mod_48lipr.UploadResponse;;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rezo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.44",
|
|
4
4
|
"description": "Lightning-fast, enterprise-grade HTTP client for modern JavaScript. Full HTTP/2 support, intelligent cookie management, multiple adapters (HTTP, Fetch, cURL, XHR), streaming, proxy support (HTTP/HTTPS/SOCKS), and cross-environment compatibility.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -62,11 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"tough-cookie": "^5.1.2",
|
|
65
|
-
"
|
|
66
|
-
"https-proxy-agent": "^7.0.6",
|
|
67
|
-
"socks-proxy-agent": "^8.0.5",
|
|
68
|
-
"linkedom": "^0.18.11",
|
|
69
|
-
"agent-base": "^7.1.4"
|
|
65
|
+
"linkedom": "^0.18.11"
|
|
70
66
|
},
|
|
71
67
|
"typesVersions": {
|
|
72
68
|
"*": {
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
const fs = require("node:fs");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
const { createHash } = require("node:crypto");
|
|
4
|
-
function detectRuntime() {
|
|
5
|
-
if (typeof globalThis.Bun !== "undefined") {
|
|
6
|
-
return "bun";
|
|
7
|
-
}
|
|
8
|
-
if (typeof globalThis.Deno !== "undefined") {
|
|
9
|
-
return "deno";
|
|
10
|
-
}
|
|
11
|
-
return "node";
|
|
12
|
-
}
|
|
13
|
-
async function createDatabase(dbPath) {
|
|
14
|
-
const runtime = detectRuntime();
|
|
15
|
-
if (runtime === "bun") {
|
|
16
|
-
const { Database } = await import("bun:sqlite");
|
|
17
|
-
const db = new Database(dbPath);
|
|
18
|
-
return {
|
|
19
|
-
run: (sql, ...params) => db.run(sql, ...params),
|
|
20
|
-
get: (sql, ...params) => db.query(sql).get(...params),
|
|
21
|
-
all: (sql, ...params) => db.query(sql).all(...params),
|
|
22
|
-
close: () => db.close()
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
if (runtime === "deno") {
|
|
26
|
-
try {
|
|
27
|
-
const { Database } = await import("node:sqlite");
|
|
28
|
-
const db = new Database(dbPath);
|
|
29
|
-
return {
|
|
30
|
-
run: (sql, ...params) => db.exec(sql, params),
|
|
31
|
-
get: (sql, ...params) => {
|
|
32
|
-
const stmt = db.prepare(sql);
|
|
33
|
-
return stmt.get(...params);
|
|
34
|
-
},
|
|
35
|
-
all: (sql, ...params) => {
|
|
36
|
-
const stmt = db.prepare(sql);
|
|
37
|
-
return stmt.all(...params);
|
|
38
|
-
},
|
|
39
|
-
close: () => db.close()
|
|
40
|
-
};
|
|
41
|
-
} catch {
|
|
42
|
-
throw new Error("Deno SQLite support requires Node.js compatibility mode");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const { DatabaseSync } = await import("node:sqlite");
|
|
46
|
-
const db = new DatabaseSync(dbPath);
|
|
47
|
-
return {
|
|
48
|
-
run: (sql, ...params) => {
|
|
49
|
-
if (params.length === 0) {
|
|
50
|
-
db.exec(sql);
|
|
51
|
-
} else {
|
|
52
|
-
db.prepare(sql).run(...params);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
get: (sql, ...params) => {
|
|
56
|
-
const stmt = db.prepare(sql);
|
|
57
|
-
return stmt.get(...params);
|
|
58
|
-
},
|
|
59
|
-
all: (sql, ...params) => {
|
|
60
|
-
const stmt = db.prepare(sql);
|
|
61
|
-
return stmt.all(...params);
|
|
62
|
-
},
|
|
63
|
-
close: () => db.close()
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
async function compressData(data) {
|
|
67
|
-
try {
|
|
68
|
-
const zlib = await import("node:zlib");
|
|
69
|
-
if (typeof zlib.zstdCompressSync === "function") {
|
|
70
|
-
return zlib.zstdCompressSync(data);
|
|
71
|
-
}
|
|
72
|
-
return data;
|
|
73
|
-
} catch {
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async function decompressData(data) {
|
|
78
|
-
try {
|
|
79
|
-
const zlib = await import("node:zlib");
|
|
80
|
-
if (typeof zlib.zstdDecompressSync === "function") {
|
|
81
|
-
return zlib.zstdDecompressSync(data);
|
|
82
|
-
}
|
|
83
|
-
return data;
|
|
84
|
-
} catch {
|
|
85
|
-
return data;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
class FileCacher {
|
|
90
|
-
databases = new Map;
|
|
91
|
-
options;
|
|
92
|
-
cacheDir;
|
|
93
|
-
closed = false;
|
|
94
|
-
constructor(options = {}) {
|
|
95
|
-
this.options = {
|
|
96
|
-
cacheDir: options.cacheDir || "./cache",
|
|
97
|
-
ttl: options.ttl || 604800000,
|
|
98
|
-
compression: options.compression ?? false,
|
|
99
|
-
softDelete: options.softDelete ?? false,
|
|
100
|
-
encryptNamespace: options.encryptNamespace ?? false,
|
|
101
|
-
maxEntries: options.maxEntries ?? 0
|
|
102
|
-
};
|
|
103
|
-
this.cacheDir = path.resolve(this.options.cacheDir);
|
|
104
|
-
if (!fs.existsSync(this.cacheDir)) {
|
|
105
|
-
fs.mkdirSync(this.cacheDir, { recursive: true });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
static async create(options = {}) {
|
|
109
|
-
const cacher = new FileCacher(options);
|
|
110
|
-
return cacher;
|
|
111
|
-
}
|
|
112
|
-
async getDatabase(namespace) {
|
|
113
|
-
const nsKey = this.options.encryptNamespace ? createHash("md5").update(namespace).digest("hex") : namespace.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
114
|
-
if (this.databases.has(nsKey)) {
|
|
115
|
-
return this.databases.get(nsKey);
|
|
116
|
-
}
|
|
117
|
-
const dbPath = path.join(this.cacheDir, `${nsKey}.db`);
|
|
118
|
-
const db = await createDatabase(dbPath);
|
|
119
|
-
db.run(`
|
|
120
|
-
CREATE TABLE IF NOT EXISTS cache (
|
|
121
|
-
key TEXT PRIMARY KEY,
|
|
122
|
-
value TEXT NOT NULL,
|
|
123
|
-
expiresAt INTEGER NOT NULL,
|
|
124
|
-
createdAt INTEGER NOT NULL,
|
|
125
|
-
compressed INTEGER DEFAULT 0,
|
|
126
|
-
deleted INTEGER DEFAULT 0
|
|
127
|
-
)
|
|
128
|
-
`);
|
|
129
|
-
db.run("CREATE INDEX IF NOT EXISTS idx_expires ON cache(expiresAt)");
|
|
130
|
-
db.run("CREATE INDEX IF NOT EXISTS idx_deleted ON cache(deleted)");
|
|
131
|
-
this.databases.set(nsKey, db);
|
|
132
|
-
return db;
|
|
133
|
-
}
|
|
134
|
-
async set(key, value, ttl, namespace = "default") {
|
|
135
|
-
if (this.closed)
|
|
136
|
-
throw new Error("FileCacher is closed");
|
|
137
|
-
const db = await this.getDatabase(namespace);
|
|
138
|
-
const now = Date.now();
|
|
139
|
-
const expiresAt = now + (ttl ?? this.options.ttl);
|
|
140
|
-
let serialized = JSON.stringify(value);
|
|
141
|
-
let compressed = 0;
|
|
142
|
-
if (this.options.compression) {
|
|
143
|
-
try {
|
|
144
|
-
const compressedData = await compressData(Buffer.from(serialized, "utf-8"));
|
|
145
|
-
serialized = compressedData.toString("base64");
|
|
146
|
-
compressed = 1;
|
|
147
|
-
} catch {}
|
|
148
|
-
}
|
|
149
|
-
db.run(`
|
|
150
|
-
INSERT OR REPLACE INTO cache (key, value, expiresAt, createdAt, compressed, deleted)
|
|
151
|
-
VALUES (?, ?, ?, ?, ?, 0)
|
|
152
|
-
`, key, serialized, expiresAt, now, compressed);
|
|
153
|
-
if (this.options.maxEntries > 0) {
|
|
154
|
-
const count = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 0");
|
|
155
|
-
if (count && count.cnt > this.options.maxEntries) {
|
|
156
|
-
const excess = count.cnt - this.options.maxEntries;
|
|
157
|
-
db.run(`
|
|
158
|
-
DELETE FROM cache WHERE key IN (
|
|
159
|
-
SELECT key FROM cache WHERE deleted = 0 ORDER BY createdAt ASC LIMIT ?
|
|
160
|
-
)
|
|
161
|
-
`, excess);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async get(key, namespace = "default") {
|
|
166
|
-
if (this.closed)
|
|
167
|
-
throw new Error("FileCacher is closed");
|
|
168
|
-
const db = await this.getDatabase(namespace);
|
|
169
|
-
const entry = db.get("SELECT * FROM cache WHERE key = ? AND deleted = 0", key);
|
|
170
|
-
if (!entry)
|
|
171
|
-
return null;
|
|
172
|
-
if (entry.expiresAt < Date.now()) {
|
|
173
|
-
if (this.options.softDelete) {
|
|
174
|
-
db.run("UPDATE cache SET deleted = 1 WHERE key = ?", key);
|
|
175
|
-
} else {
|
|
176
|
-
db.run("DELETE FROM cache WHERE key = ?", key);
|
|
177
|
-
}
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
let value = entry.value;
|
|
181
|
-
if (entry.compressed) {
|
|
182
|
-
try {
|
|
183
|
-
const decompressed = await decompressData(Buffer.from(value, "base64"));
|
|
184
|
-
value = decompressed.toString("utf-8");
|
|
185
|
-
} catch {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
return JSON.parse(value);
|
|
191
|
-
} catch {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async has(key, namespace = "default") {
|
|
196
|
-
if (this.closed)
|
|
197
|
-
return false;
|
|
198
|
-
const db = await this.getDatabase(namespace);
|
|
199
|
-
const entry = db.get("SELECT key, expiresAt FROM cache WHERE key = ? AND deleted = 0", key);
|
|
200
|
-
if (!entry)
|
|
201
|
-
return false;
|
|
202
|
-
return entry.expiresAt >= Date.now();
|
|
203
|
-
}
|
|
204
|
-
async delete(key, namespace = "default") {
|
|
205
|
-
if (this.closed)
|
|
206
|
-
return false;
|
|
207
|
-
const db = await this.getDatabase(namespace);
|
|
208
|
-
if (this.options.softDelete) {
|
|
209
|
-
db.run("UPDATE cache SET deleted = 1 WHERE key = ?", key);
|
|
210
|
-
} else {
|
|
211
|
-
db.run("DELETE FROM cache WHERE key = ?", key);
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
async clear(namespace = "default") {
|
|
216
|
-
if (this.closed)
|
|
217
|
-
return;
|
|
218
|
-
const db = await this.getDatabase(namespace);
|
|
219
|
-
if (this.options.softDelete) {
|
|
220
|
-
db.run("UPDATE cache SET deleted = 1");
|
|
221
|
-
} else {
|
|
222
|
-
db.run("DELETE FROM cache");
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async cleanup(namespace = "default") {
|
|
226
|
-
if (this.closed)
|
|
227
|
-
return 0;
|
|
228
|
-
const db = await this.getDatabase(namespace);
|
|
229
|
-
const now = Date.now();
|
|
230
|
-
const countBefore = db.get("SELECT COUNT(*) as cnt FROM cache");
|
|
231
|
-
db.run("DELETE FROM cache WHERE expiresAt < ? OR deleted = 1", now);
|
|
232
|
-
const countAfter = db.get("SELECT COUNT(*) as cnt FROM cache");
|
|
233
|
-
return (countBefore?.cnt || 0) - (countAfter?.cnt || 0);
|
|
234
|
-
}
|
|
235
|
-
async stats(namespace = "default") {
|
|
236
|
-
if (this.closed)
|
|
237
|
-
return { count: 0, expired: 0, deleted: 0 };
|
|
238
|
-
const db = await this.getDatabase(namespace);
|
|
239
|
-
const now = Date.now();
|
|
240
|
-
const total = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 0");
|
|
241
|
-
const expired = db.get("SELECT COUNT(*) as cnt FROM cache WHERE expiresAt < ? AND deleted = 0", now);
|
|
242
|
-
const deleted = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 1");
|
|
243
|
-
return {
|
|
244
|
-
count: total?.cnt || 0,
|
|
245
|
-
expired: expired?.cnt || 0,
|
|
246
|
-
deleted: deleted?.cnt || 0
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
async close() {
|
|
250
|
-
if (this.closed)
|
|
251
|
-
return;
|
|
252
|
-
this.closed = true;
|
|
253
|
-
for (const db of this.databases.values()) {
|
|
254
|
-
try {
|
|
255
|
-
db.close();
|
|
256
|
-
} catch {}
|
|
257
|
-
}
|
|
258
|
-
this.databases.clear();
|
|
259
|
-
}
|
|
260
|
-
get isClosed() {
|
|
261
|
-
return this.closed;
|
|
262
|
-
}
|
|
263
|
-
get directory() {
|
|
264
|
-
return this.cacheDir;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
exports.FileCacher = FileCacher;
|
|
269
|
-
exports.default = FileCacher;
|
|
270
|
-
module.exports = Object.assign(FileCacher, exports);
|