rezo 1.0.42 → 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.
Files changed (89) hide show
  1. package/dist/adapters/curl.cjs +131 -29
  2. package/dist/adapters/curl.js +131 -29
  3. package/dist/adapters/entries/curl.d.ts +65 -0
  4. package/dist/adapters/entries/fetch.d.ts +65 -0
  5. package/dist/adapters/entries/http.d.ts +65 -0
  6. package/dist/adapters/entries/http2.d.ts +65 -0
  7. package/dist/adapters/entries/react-native.d.ts +65 -0
  8. package/dist/adapters/entries/xhr.d.ts +65 -0
  9. package/dist/adapters/http2.cjs +209 -22
  10. package/dist/adapters/http2.js +209 -22
  11. package/dist/adapters/index.cjs +6 -6
  12. package/dist/cache/index.cjs +9 -13
  13. package/dist/cache/index.js +0 -2
  14. package/dist/core/rezo.cjs +7 -0
  15. package/dist/core/rezo.js +7 -0
  16. package/dist/crawler/addon/decodo/index.cjs +1 -0
  17. package/dist/crawler/addon/decodo/index.js +1 -0
  18. package/dist/crawler/crawler-options.cjs +1 -0
  19. package/dist/crawler/crawler-options.js +1 -0
  20. package/dist/crawler/crawler.cjs +1070 -0
  21. package/dist/crawler/crawler.js +1068 -0
  22. package/dist/crawler/index.cjs +40 -0
  23. package/dist/{plugin → crawler}/index.js +4 -2
  24. package/dist/crawler/plugin/file-cacher.cjs +19 -0
  25. package/dist/crawler/plugin/file-cacher.js +19 -0
  26. package/dist/crawler/plugin/index.cjs +1 -0
  27. package/dist/crawler/plugin/index.js +1 -0
  28. package/dist/crawler/plugin/navigation-history.cjs +43 -0
  29. package/dist/crawler/plugin/navigation-history.js +43 -0
  30. package/dist/crawler/plugin/robots-txt.cjs +2 -0
  31. package/dist/crawler/plugin/robots-txt.js +2 -0
  32. package/dist/crawler/plugin/url-store.cjs +18 -0
  33. package/dist/crawler/plugin/url-store.js +18 -0
  34. package/dist/crawler.d.ts +511 -183
  35. package/dist/entries/crawler.cjs +5 -5
  36. package/dist/entries/crawler.js +2 -2
  37. package/dist/index.cjs +27 -24
  38. package/dist/index.d.ts +73 -0
  39. package/dist/index.js +1 -0
  40. package/dist/internal/agents/base.cjs +113 -0
  41. package/dist/internal/agents/base.js +110 -0
  42. package/dist/internal/agents/http-proxy.cjs +89 -0
  43. package/dist/internal/agents/http-proxy.js +86 -0
  44. package/dist/internal/agents/https-proxy.cjs +176 -0
  45. package/dist/internal/agents/https-proxy.js +173 -0
  46. package/dist/internal/agents/index.cjs +10 -0
  47. package/dist/internal/agents/index.js +5 -0
  48. package/dist/internal/agents/socks-client.cjs +571 -0
  49. package/dist/internal/agents/socks-client.js +567 -0
  50. package/dist/internal/agents/socks-proxy.cjs +75 -0
  51. package/dist/internal/agents/socks-proxy.js +72 -0
  52. package/dist/platform/browser.d.ts +65 -0
  53. package/dist/platform/bun.d.ts +65 -0
  54. package/dist/platform/deno.d.ts +65 -0
  55. package/dist/platform/node.d.ts +65 -0
  56. package/dist/platform/react-native.d.ts +65 -0
  57. package/dist/platform/worker.d.ts +65 -0
  58. package/dist/proxy/index.cjs +18 -16
  59. package/dist/proxy/index.js +17 -12
  60. package/dist/queue/index.cjs +8 -8
  61. package/dist/responses/buildError.cjs +11 -2
  62. package/dist/responses/buildError.js +11 -2
  63. package/dist/responses/universal/index.cjs +11 -11
  64. package/dist/utils/curl.cjs +317 -0
  65. package/dist/utils/curl.js +314 -0
  66. package/package.json +2 -6
  67. package/dist/cache/file-cacher.cjs +0 -264
  68. package/dist/cache/file-cacher.js +0 -261
  69. package/dist/cache/url-store.cjs +0 -288
  70. package/dist/cache/url-store.js +0 -285
  71. package/dist/plugin/addon/decodo/index.cjs +0 -1
  72. package/dist/plugin/addon/decodo/index.js +0 -1
  73. package/dist/plugin/crawler-options.cjs +0 -1
  74. package/dist/plugin/crawler-options.js +0 -1
  75. package/dist/plugin/crawler.cjs +0 -519
  76. package/dist/plugin/crawler.js +0 -517
  77. package/dist/plugin/index.cjs +0 -36
  78. /package/dist/{plugin → crawler}/addon/decodo/options.cjs +0 -0
  79. /package/dist/{plugin → crawler}/addon/decodo/options.js +0 -0
  80. /package/dist/{plugin → crawler}/addon/decodo/types.cjs +0 -0
  81. /package/dist/{plugin → crawler}/addon/decodo/types.js +0 -0
  82. /package/dist/{plugin → crawler}/addon/oxylabs/index.cjs +0 -0
  83. /package/dist/{plugin → crawler}/addon/oxylabs/index.js +0 -0
  84. /package/dist/{plugin → crawler}/addon/oxylabs/options.cjs +0 -0
  85. /package/dist/{plugin → crawler}/addon/oxylabs/options.js +0 -0
  86. /package/dist/{plugin → crawler}/addon/oxylabs/types.cjs +0 -0
  87. /package/dist/{plugin → crawler}/addon/oxylabs/types.js +0 -0
  88. /package/dist/{plugin → crawler}/scraper.cjs +0 -0
  89. /package/dist/{plugin → crawler}/scraper.js +0 -0
@@ -1,261 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { createHash } from "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) => db.exec(sql),
49
- get: (sql, ...params) => {
50
- const stmt = db.prepare(sql);
51
- return stmt.get(...params);
52
- },
53
- all: (sql, ...params) => {
54
- const stmt = db.prepare(sql);
55
- return stmt.all(...params);
56
- },
57
- close: () => db.close()
58
- };
59
- }
60
- async function compressData(data) {
61
- try {
62
- const zlib = await import("node:zlib");
63
- if (typeof zlib.zstdCompressSync === "function") {
64
- return zlib.zstdCompressSync(data);
65
- }
66
- return data;
67
- } catch {
68
- return data;
69
- }
70
- }
71
- async function decompressData(data) {
72
- try {
73
- const zlib = await import("node:zlib");
74
- if (typeof zlib.zstdDecompressSync === "function") {
75
- return zlib.zstdDecompressSync(data);
76
- }
77
- return data;
78
- } catch {
79
- return data;
80
- }
81
- }
82
-
83
- export class FileCacher {
84
- databases = new Map;
85
- options;
86
- cacheDir;
87
- closed = false;
88
- constructor(options = {}) {
89
- this.options = {
90
- cacheDir: options.cacheDir || "./cache",
91
- ttl: options.ttl || 604800000,
92
- compression: options.compression ?? false,
93
- softDelete: options.softDelete ?? false,
94
- encryptNamespace: options.encryptNamespace ?? false,
95
- maxEntries: options.maxEntries ?? 0
96
- };
97
- this.cacheDir = path.resolve(this.options.cacheDir);
98
- if (!fs.existsSync(this.cacheDir)) {
99
- fs.mkdirSync(this.cacheDir, { recursive: true });
100
- }
101
- }
102
- static async create(options = {}) {
103
- const cacher = new FileCacher(options);
104
- return cacher;
105
- }
106
- async getDatabase(namespace) {
107
- const nsKey = this.options.encryptNamespace ? createHash("md5").update(namespace).digest("hex") : namespace.replace(/[^a-zA-Z0-9_-]/g, "_");
108
- if (this.databases.has(nsKey)) {
109
- return this.databases.get(nsKey);
110
- }
111
- const dbPath = path.join(this.cacheDir, `${nsKey}.db`);
112
- const db = await createDatabase(dbPath);
113
- db.run(`
114
- CREATE TABLE IF NOT EXISTS cache (
115
- key TEXT PRIMARY KEY,
116
- value TEXT NOT NULL,
117
- expiresAt INTEGER NOT NULL,
118
- createdAt INTEGER NOT NULL,
119
- compressed INTEGER DEFAULT 0,
120
- deleted INTEGER DEFAULT 0
121
- )
122
- `);
123
- db.run("CREATE INDEX IF NOT EXISTS idx_expires ON cache(expiresAt)");
124
- db.run("CREATE INDEX IF NOT EXISTS idx_deleted ON cache(deleted)");
125
- this.databases.set(nsKey, db);
126
- return db;
127
- }
128
- async set(key, value, ttl, namespace = "default") {
129
- if (this.closed)
130
- throw new Error("FileCacher is closed");
131
- const db = await this.getDatabase(namespace);
132
- const now = Date.now();
133
- const expiresAt = now + (ttl ?? this.options.ttl);
134
- let serialized = JSON.stringify(value);
135
- let compressed = 0;
136
- if (this.options.compression) {
137
- try {
138
- const compressedData = await compressData(Buffer.from(serialized, "utf-8"));
139
- serialized = compressedData.toString("base64");
140
- compressed = 1;
141
- } catch {}
142
- }
143
- db.run(`
144
- INSERT OR REPLACE INTO cache (key, value, expiresAt, createdAt, compressed, deleted)
145
- VALUES (?, ?, ?, ?, ?, 0)
146
- `, key, serialized, expiresAt, now, compressed);
147
- if (this.options.maxEntries > 0) {
148
- const count = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 0");
149
- if (count && count.cnt > this.options.maxEntries) {
150
- const excess = count.cnt - this.options.maxEntries;
151
- db.run(`
152
- DELETE FROM cache WHERE key IN (
153
- SELECT key FROM cache WHERE deleted = 0 ORDER BY createdAt ASC LIMIT ?
154
- )
155
- `, excess);
156
- }
157
- }
158
- }
159
- async get(key, namespace = "default") {
160
- if (this.closed)
161
- throw new Error("FileCacher is closed");
162
- const db = await this.getDatabase(namespace);
163
- const entry = db.get("SELECT * FROM cache WHERE key = ? AND deleted = 0", key);
164
- if (!entry)
165
- return null;
166
- if (entry.expiresAt < Date.now()) {
167
- if (this.options.softDelete) {
168
- db.run("UPDATE cache SET deleted = 1 WHERE key = ?", key);
169
- } else {
170
- db.run("DELETE FROM cache WHERE key = ?", key);
171
- }
172
- return null;
173
- }
174
- let value = entry.value;
175
- if (entry.compressed) {
176
- try {
177
- const decompressed = await decompressData(Buffer.from(value, "base64"));
178
- value = decompressed.toString("utf-8");
179
- } catch {
180
- return null;
181
- }
182
- }
183
- try {
184
- return JSON.parse(value);
185
- } catch {
186
- return null;
187
- }
188
- }
189
- async has(key, namespace = "default") {
190
- if (this.closed)
191
- return false;
192
- const db = await this.getDatabase(namespace);
193
- const entry = db.get("SELECT key, expiresAt FROM cache WHERE key = ? AND deleted = 0", key);
194
- if (!entry)
195
- return false;
196
- return entry.expiresAt >= Date.now();
197
- }
198
- async delete(key, namespace = "default") {
199
- if (this.closed)
200
- return false;
201
- const db = await this.getDatabase(namespace);
202
- if (this.options.softDelete) {
203
- db.run("UPDATE cache SET deleted = 1 WHERE key = ?", key);
204
- } else {
205
- db.run("DELETE FROM cache WHERE key = ?", key);
206
- }
207
- return true;
208
- }
209
- async clear(namespace = "default") {
210
- if (this.closed)
211
- return;
212
- const db = await this.getDatabase(namespace);
213
- if (this.options.softDelete) {
214
- db.run("UPDATE cache SET deleted = 1");
215
- } else {
216
- db.run("DELETE FROM cache");
217
- }
218
- }
219
- async cleanup(namespace = "default") {
220
- if (this.closed)
221
- return 0;
222
- const db = await this.getDatabase(namespace);
223
- const now = Date.now();
224
- const countBefore = db.get("SELECT COUNT(*) as cnt FROM cache");
225
- db.run("DELETE FROM cache WHERE expiresAt < ? OR deleted = 1", now);
226
- const countAfter = db.get("SELECT COUNT(*) as cnt FROM cache");
227
- return (countBefore?.cnt || 0) - (countAfter?.cnt || 0);
228
- }
229
- async stats(namespace = "default") {
230
- if (this.closed)
231
- return { count: 0, expired: 0, deleted: 0 };
232
- const db = await this.getDatabase(namespace);
233
- const now = Date.now();
234
- const total = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 0");
235
- const expired = db.get("SELECT COUNT(*) as cnt FROM cache WHERE expiresAt < ? AND deleted = 0", now);
236
- const deleted = db.get("SELECT COUNT(*) as cnt FROM cache WHERE deleted = 1");
237
- return {
238
- count: total?.cnt || 0,
239
- expired: expired?.cnt || 0,
240
- deleted: deleted?.cnt || 0
241
- };
242
- }
243
- async close() {
244
- if (this.closed)
245
- return;
246
- this.closed = true;
247
- for (const db of this.databases.values()) {
248
- try {
249
- db.close();
250
- } catch {}
251
- }
252
- this.databases.clear();
253
- }
254
- get isClosed() {
255
- return this.closed;
256
- }
257
- get directory() {
258
- return this.cacheDir;
259
- }
260
- }
261
- export default FileCacher;
@@ -1,288 +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) => db.exec(sql),
49
- get: (sql, ...params) => {
50
- const stmt = db.prepare(sql);
51
- return stmt.get(...params);
52
- },
53
- all: (sql, ...params) => {
54
- const stmt = db.prepare(sql);
55
- return stmt.all(...params);
56
- },
57
- close: () => db.close()
58
- };
59
- }
60
-
61
- class UrlStore {
62
- db = null;
63
- options;
64
- storeDir;
65
- dbPath;
66
- closed = false;
67
- initPromise = null;
68
- constructor(options = {}) {
69
- this.options = {
70
- storeDir: options.storeDir || "./url-store",
71
- dbFileName: options.dbFileName || "urls.db",
72
- ttl: options.ttl || 604800000,
73
- maxUrls: options.maxUrls ?? 0,
74
- hashUrls: options.hashUrls ?? false
75
- };
76
- this.storeDir = path.resolve(this.options.storeDir);
77
- this.dbPath = path.join(this.storeDir, this.options.dbFileName);
78
- if (!fs.existsSync(this.storeDir)) {
79
- fs.mkdirSync(this.storeDir, { recursive: true });
80
- }
81
- }
82
- static async create(options = {}) {
83
- const store = new UrlStore(options);
84
- await store.initialize();
85
- return store;
86
- }
87
- async initialize() {
88
- if (this.initPromise)
89
- return this.initPromise;
90
- this.initPromise = (async () => {
91
- this.db = await createDatabase(this.dbPath);
92
- this.db.run(`
93
- CREATE TABLE IF NOT EXISTS urls (
94
- url TEXT PRIMARY KEY,
95
- visitedAt INTEGER NOT NULL,
96
- expiresAt INTEGER NOT NULL,
97
- namespace TEXT DEFAULT 'default',
98
- metadata TEXT
99
- )
100
- `);
101
- this.db.run("CREATE INDEX IF NOT EXISTS idx_expires ON urls(expiresAt)");
102
- this.db.run("CREATE INDEX IF NOT EXISTS idx_namespace ON urls(namespace)");
103
- this.db.run("CREATE INDEX IF NOT EXISTS idx_visited ON urls(visitedAt)");
104
- })();
105
- return this.initPromise;
106
- }
107
- getUrlKey(url) {
108
- if (this.options.hashUrls) {
109
- return createHash("sha256").update(url).digest("hex");
110
- }
111
- return url;
112
- }
113
- async set(url, namespace = "default", metadata, ttl) {
114
- if (this.closed)
115
- throw new Error("UrlStore is closed");
116
- await this.initialize();
117
- const key = this.getUrlKey(url);
118
- const now = Date.now();
119
- const expiresAt = now + (ttl ?? this.options.ttl);
120
- const metaStr = metadata ? JSON.stringify(metadata) : null;
121
- this.db.run(`
122
- INSERT OR REPLACE INTO urls (url, visitedAt, expiresAt, namespace, metadata)
123
- VALUES (?, ?, ?, ?, ?)
124
- `, key, now, expiresAt, namespace, metaStr);
125
- if (this.options.maxUrls > 0) {
126
- const count = this.db.get("SELECT COUNT(*) as cnt FROM urls");
127
- if (count && count.cnt > this.options.maxUrls) {
128
- const excess = count.cnt - this.options.maxUrls;
129
- this.db.run(`
130
- DELETE FROM urls WHERE url IN (
131
- SELECT url FROM urls ORDER BY visitedAt ASC LIMIT ?
132
- )
133
- `, excess);
134
- }
135
- }
136
- }
137
- async has(url, namespace) {
138
- if (this.closed)
139
- return false;
140
- await this.initialize();
141
- const key = this.getUrlKey(url);
142
- const now = Date.now();
143
- let entry;
144
- if (namespace) {
145
- entry = this.db.get("SELECT url, expiresAt FROM urls WHERE url = ? AND namespace = ?", key, namespace);
146
- } else {
147
- entry = this.db.get("SELECT url, expiresAt FROM urls WHERE url = ?", key);
148
- }
149
- if (!entry)
150
- return false;
151
- return entry.expiresAt >= now;
152
- }
153
- async hasMany(urls, namespace) {
154
- if (this.closed)
155
- return new Set;
156
- await this.initialize();
157
- const result = new Set;
158
- const now = Date.now();
159
- const batchSize = 100;
160
- for (let i = 0;i < urls.length; i += batchSize) {
161
- const batch = urls.slice(i, i + batchSize);
162
- const keys = batch.map((u) => this.getUrlKey(u));
163
- const placeholders = keys.map(() => "?").join(",");
164
- let entries;
165
- if (namespace) {
166
- entries = this.db.all(`SELECT url, expiresAt FROM urls WHERE url IN (${placeholders}) AND namespace = ?`, ...keys, namespace);
167
- } else {
168
- entries = this.db.all(`SELECT url, expiresAt FROM urls WHERE url IN (${placeholders})`, ...keys);
169
- }
170
- for (const entry of entries) {
171
- if (entry.expiresAt >= now) {
172
- const idx = keys.indexOf(entry.url);
173
- if (idx !== -1) {
174
- result.add(batch[idx]);
175
- }
176
- }
177
- }
178
- }
179
- return result;
180
- }
181
- async getMetadata(url, namespace) {
182
- if (this.closed)
183
- return null;
184
- await this.initialize();
185
- const key = this.getUrlKey(url);
186
- let entry;
187
- if (namespace) {
188
- entry = this.db.get("SELECT metadata FROM urls WHERE url = ? AND namespace = ?", key, namespace);
189
- } else {
190
- entry = this.db.get("SELECT metadata FROM urls WHERE url = ?", key);
191
- }
192
- if (!entry?.metadata)
193
- return null;
194
- try {
195
- return JSON.parse(entry.metadata);
196
- } catch {
197
- return null;
198
- }
199
- }
200
- async delete(url, namespace) {
201
- if (this.closed)
202
- return false;
203
- await this.initialize();
204
- const key = this.getUrlKey(url);
205
- if (namespace) {
206
- this.db.run("DELETE FROM urls WHERE url = ? AND namespace = ?", key, namespace);
207
- } else {
208
- this.db.run("DELETE FROM urls WHERE url = ?", key);
209
- }
210
- return true;
211
- }
212
- async clear(namespace) {
213
- if (this.closed)
214
- return;
215
- await this.initialize();
216
- if (namespace) {
217
- this.db.run("DELETE FROM urls WHERE namespace = ?", namespace);
218
- } else {
219
- this.db.run("DELETE FROM urls");
220
- }
221
- }
222
- async cleanup() {
223
- if (this.closed)
224
- return 0;
225
- await this.initialize();
226
- const now = Date.now();
227
- const countBefore = this.db.get("SELECT COUNT(*) as cnt FROM urls");
228
- this.db.run("DELETE FROM urls WHERE expiresAt < ?", now);
229
- const countAfter = this.db.get("SELECT COUNT(*) as cnt FROM urls");
230
- return (countBefore?.cnt || 0) - (countAfter?.cnt || 0);
231
- }
232
- async getAll(namespace = "default", includeExpired = false) {
233
- if (this.closed)
234
- return [];
235
- await this.initialize();
236
- const now = Date.now();
237
- let entries;
238
- if (includeExpired) {
239
- entries = this.db.all("SELECT url FROM urls WHERE namespace = ?", namespace);
240
- } else {
241
- entries = this.db.all("SELECT url FROM urls WHERE namespace = ? AND expiresAt >= ?", namespace, now);
242
- }
243
- return entries.map((e) => e.url);
244
- }
245
- async stats(namespace) {
246
- if (this.closed)
247
- return { total: 0, expired: 0, namespaces: 0 };
248
- await this.initialize();
249
- const now = Date.now();
250
- let total;
251
- let expired;
252
- if (namespace) {
253
- total = this.db.get("SELECT COUNT(*) as cnt FROM urls WHERE namespace = ?", namespace);
254
- expired = this.db.get("SELECT COUNT(*) as cnt FROM urls WHERE namespace = ? AND expiresAt < ?", namespace, now);
255
- } else {
256
- total = this.db.get("SELECT COUNT(*) as cnt FROM urls");
257
- expired = this.db.get("SELECT COUNT(*) as cnt FROM urls WHERE expiresAt < ?", now);
258
- }
259
- const namespaceCount = this.db.get("SELECT COUNT(DISTINCT namespace) as cnt FROM urls");
260
- return {
261
- total: total?.cnt || 0,
262
- expired: expired?.cnt || 0,
263
- namespaces: namespaceCount?.cnt || 0
264
- };
265
- }
266
- async close() {
267
- if (this.closed)
268
- return;
269
- this.closed = true;
270
- await this.initPromise;
271
- if (this.db) {
272
- try {
273
- this.db.close();
274
- } catch {}
275
- this.db = null;
276
- }
277
- }
278
- get isClosed() {
279
- return this.closed;
280
- }
281
- get path() {
282
- return this.dbPath;
283
- }
284
- }
285
-
286
- exports.UrlStore = UrlStore;
287
- exports.default = UrlStore;
288
- module.exports = Object.assign(UrlStore, exports);