@http-client-toolkit/store-sqlite 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025, Ally Murray
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @http-client-toolkit/store-sqlite
2
+
3
+ SQLite-backed store implementations for [@http-client-toolkit/core](https://www.npmjs.com/package/@http-client-toolkit/core) using [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) and [Drizzle ORM](https://orm.drizzle.team/). Suitable for production use where data should survive process restarts.
4
+
5
+ Part of the [http-client-toolkit](https://github.com/AllyMurray/http-client-toolkit) monorepo.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @http-client-toolkit/core @http-client-toolkit/store-sqlite
11
+ ```
12
+
13
+ Requires Node.js >= 20.
14
+
15
+ ## Usage
16
+
17
+ All stores accept either a file path or an existing `better-sqlite3` Database instance. Passing a shared instance lets multiple stores operate on the same database file:
18
+
19
+ ```typescript
20
+ import { HttpClient } from '@http-client-toolkit/core';
21
+ import Database from 'better-sqlite3';
22
+ import {
23
+ SQLiteCacheStore,
24
+ SQLiteDedupeStore,
25
+ SQLiteRateLimitStore,
26
+ } from '@http-client-toolkit/store-sqlite';
27
+
28
+ const db = new Database('./app.db');
29
+
30
+ const client = new HttpClient({
31
+ cache: new SQLiteCacheStore({ database: db }),
32
+ dedupe: new SQLiteDedupeStore({ database: db }),
33
+ rateLimit: new SQLiteRateLimitStore({ database: db }),
34
+ });
35
+
36
+ const data = await client.get<{ name: string }>(
37
+ 'https://api.example.com/user/1',
38
+ );
39
+ ```
40
+
41
+ By default, stores use `':memory:'` (non-persistent). When a file path is passed instead of a Database instance, the store manages its own connection and will close it when `close()` is called.
42
+
43
+ ## Stores
44
+
45
+ ### SQLiteCacheStore
46
+
47
+ ```typescript
48
+ new SQLiteCacheStore({
49
+ database: './cache.db', // Default: ':memory:'
50
+ cleanupIntervalMs: 60_000, // Set to 0 to disable automatic cleanup
51
+ maxEntrySizeBytes: 5_242_880, // Default: 5 MiB
52
+ });
53
+ ```
54
+
55
+ ### SQLiteDedupeStore
56
+
57
+ ```typescript
58
+ new SQLiteDedupeStore({
59
+ database: './dedupe.db',
60
+ jobTimeoutMs: 300_000,
61
+ cleanupIntervalMs: 60_000,
62
+ pollIntervalMs: 100, // Poll DB state for cross-instance waiters
63
+ });
64
+ ```
65
+
66
+ Pending waiters are settled when the store is closed/destroyed, preventing hanging promises during shutdown.
67
+
68
+ ### SQLiteRateLimitStore
69
+
70
+ ```typescript
71
+ new SQLiteRateLimitStore({
72
+ database: './ratelimit.db',
73
+ defaultConfig: { limit: 60, windowMs: 60_000 },
74
+ resourceConfigs: new Map([['slow-api', { limit: 10, windowMs: 60_000 }]]),
75
+ });
76
+ ```
77
+
78
+ ### SqliteAdaptiveRateLimitStore
79
+
80
+ Priority-aware rate limiter with the same adaptive strategies as the in-memory variant, backed by SQLite for persistence.
81
+
82
+ ```typescript
83
+ new SqliteAdaptiveRateLimitStore({
84
+ database: './ratelimit.db',
85
+ defaultConfig: { limit: 200, windowMs: 3_600_000 },
86
+ resourceConfigs: new Map([['search', { limit: 50, windowMs: 60_000 }]]),
87
+ adaptiveConfig: { highActivityThreshold: 10 },
88
+ });
89
+ ```
90
+
91
+ ## License
92
+
93
+ ISC