@bcts/hubert 1.0.0-alpha.17
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 +48 -0
- package/README.md +18 -0
- package/dist/arid-derivation-1CJuU-kZ.cjs +150 -0
- package/dist/arid-derivation-1CJuU-kZ.cjs.map +1 -0
- package/dist/arid-derivation-CbqACjdg.mjs +126 -0
- package/dist/arid-derivation-CbqACjdg.mjs.map +1 -0
- package/dist/bin/hubert.cjs +384 -0
- package/dist/bin/hubert.cjs.map +1 -0
- package/dist/bin/hubert.d.cts +1 -0
- package/dist/bin/hubert.d.mts +1 -0
- package/dist/bin/hubert.mjs +383 -0
- package/dist/bin/hubert.mjs.map +1 -0
- package/dist/chunk-CbDLau6x.cjs +34 -0
- package/dist/hybrid/index.cjs +14 -0
- package/dist/hybrid/index.d.cts +3 -0
- package/dist/hybrid/index.d.mts +3 -0
- package/dist/hybrid/index.mjs +6 -0
- package/dist/hybrid-BZhumygj.mjs +356 -0
- package/dist/hybrid-BZhumygj.mjs.map +1 -0
- package/dist/hybrid-dX5JLumO.cjs +410 -0
- package/dist/hybrid-dX5JLumO.cjs.map +1 -0
- package/dist/index-BEzpUC7r.d.mts +380 -0
- package/dist/index-BEzpUC7r.d.mts.map +1 -0
- package/dist/index-C2F6ugLL.d.mts +210 -0
- package/dist/index-C2F6ugLL.d.mts.map +1 -0
- package/dist/index-CUnDouMb.d.mts +215 -0
- package/dist/index-CUnDouMb.d.mts.map +1 -0
- package/dist/index-CV6lZJqY.d.cts +380 -0
- package/dist/index-CV6lZJqY.d.cts.map +1 -0
- package/dist/index-CY3TCzIm.d.cts +217 -0
- package/dist/index-CY3TCzIm.d.cts.map +1 -0
- package/dist/index-DEr4SR1J.d.cts +215 -0
- package/dist/index-DEr4SR1J.d.cts.map +1 -0
- package/dist/index-T1LHanIb.d.mts +217 -0
- package/dist/index-T1LHanIb.d.mts.map +1 -0
- package/dist/index-jyzuOhFB.d.cts +210 -0
- package/dist/index-jyzuOhFB.d.cts.map +1 -0
- package/dist/index.cjs +60 -0
- package/dist/index.d.cts +161 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +161 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/ipfs/index.cjs +13 -0
- package/dist/ipfs/index.d.cts +3 -0
- package/dist/ipfs/index.d.mts +3 -0
- package/dist/ipfs/index.mjs +5 -0
- package/dist/ipfs-BRMMCBjv.mjs +1 -0
- package/dist/ipfs-CetOVQcO.cjs +0 -0
- package/dist/kv-BAmhmMOo.cjs +425 -0
- package/dist/kv-BAmhmMOo.cjs.map +1 -0
- package/dist/kv-C-emxv0w.mjs +375 -0
- package/dist/kv-C-emxv0w.mjs.map +1 -0
- package/dist/kv-DJiKvypY.mjs +403 -0
- package/dist/kv-DJiKvypY.mjs.map +1 -0
- package/dist/kv-store-DmngWWuw.d.mts +183 -0
- package/dist/kv-store-DmngWWuw.d.mts.map +1 -0
- package/dist/kv-store-ww-AUyLd.d.cts +183 -0
- package/dist/kv-store-ww-AUyLd.d.cts.map +1 -0
- package/dist/kv-yjvQa_LH.cjs +457 -0
- package/dist/kv-yjvQa_LH.cjs.map +1 -0
- package/dist/logging-hmzNzifq.mjs +158 -0
- package/dist/logging-hmzNzifq.mjs.map +1 -0
- package/dist/logging-qc9uMgil.cjs +212 -0
- package/dist/logging-qc9uMgil.cjs.map +1 -0
- package/dist/mainline/index.cjs +12 -0
- package/dist/mainline/index.d.cts +3 -0
- package/dist/mainline/index.d.mts +3 -0
- package/dist/mainline/index.mjs +5 -0
- package/dist/mainline-D_jfeFMh.cjs +0 -0
- package/dist/mainline-cFIuXbo-.mjs +1 -0
- package/dist/server/index.cjs +14 -0
- package/dist/server/index.d.cts +3 -0
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.mjs +3 -0
- package/dist/server-BBNRZ30D.cjs +912 -0
- package/dist/server-BBNRZ30D.cjs.map +1 -0
- package/dist/server-DVyk9gqU.mjs +836 -0
- package/dist/server-DVyk9gqU.mjs.map +1 -0
- package/package.json +125 -0
- package/src/arid-derivation.ts +155 -0
- package/src/bin/hubert.ts +667 -0
- package/src/error.ts +89 -0
- package/src/hybrid/error.ts +77 -0
- package/src/hybrid/index.ts +24 -0
- package/src/hybrid/kv.ts +236 -0
- package/src/hybrid/reference.ts +176 -0
- package/src/index.ts +145 -0
- package/src/ipfs/error.ts +83 -0
- package/src/ipfs/index.ts +24 -0
- package/src/ipfs/kv.ts +476 -0
- package/src/ipfs/value.ts +85 -0
- package/src/kv-store.ts +128 -0
- package/src/logging.ts +88 -0
- package/src/mainline/error.ts +108 -0
- package/src/mainline/index.ts +23 -0
- package/src/mainline/kv.ts +411 -0
- package/src/server/error.ts +83 -0
- package/src/server/index.ts +29 -0
- package/src/server/kv.ts +211 -0
- package/src/server/memory-kv.ts +191 -0
- package/src/server/server-kv.ts +92 -0
- package/src/server/server.ts +369 -0
- package/src/server/sqlite-kv.ts +295 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { r as HubertError, t as KvStore } from "./kv-store-DmngWWuw.mjs";
|
|
2
|
+
import { ARID } from "@bcts/components";
|
|
3
|
+
import { Envelope } from "@bcts/envelope";
|
|
4
|
+
|
|
5
|
+
//#region src/server/error.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Base error class for server errors.
|
|
8
|
+
*
|
|
9
|
+
* @category Server Errors
|
|
10
|
+
*/
|
|
11
|
+
declare class ServerError extends HubertError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* General server error.
|
|
16
|
+
*
|
|
17
|
+
* Port of `Error::General(String)` from server/error.rs line 4.
|
|
18
|
+
*
|
|
19
|
+
* @category Server Errors
|
|
20
|
+
*/
|
|
21
|
+
declare class ServerGeneralError extends ServerError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Network error during server communication.
|
|
26
|
+
*
|
|
27
|
+
* Port of `Error::NetworkError(String)` from server/error.rs line 7.
|
|
28
|
+
*
|
|
29
|
+
* @category Server Errors
|
|
30
|
+
*/
|
|
31
|
+
declare class ServerNetworkError extends ServerError {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse error during data handling.
|
|
36
|
+
*
|
|
37
|
+
* Port of `Error::ParseError(String)` from server/error.rs line 10.
|
|
38
|
+
*
|
|
39
|
+
* @category Server Errors
|
|
40
|
+
*/
|
|
41
|
+
declare class ServerParseError extends ServerError {
|
|
42
|
+
constructor(message: string);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* SQLite database error.
|
|
46
|
+
*
|
|
47
|
+
* Port of `Error::Sqlite(e)` from server/error.rs line 19.
|
|
48
|
+
*
|
|
49
|
+
* @category Server Errors
|
|
50
|
+
*/
|
|
51
|
+
declare class SqliteError extends ServerError {
|
|
52
|
+
/** The underlying error */
|
|
53
|
+
readonly cause?: Error;
|
|
54
|
+
constructor(message: string, cause?: Error);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/server/memory-kv.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* In-memory key-value store for Gordian Envelopes.
|
|
60
|
+
*
|
|
61
|
+
* Provides volatile storage with TTL support and automatic cleanup of
|
|
62
|
+
* expired entries.
|
|
63
|
+
*
|
|
64
|
+
* Port of `struct MemoryKv` from server/memory_kv.rs lines 14-21.
|
|
65
|
+
*
|
|
66
|
+
* @category Server Backend
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const store = new MemoryKv();
|
|
71
|
+
* const arid = ARID.new();
|
|
72
|
+
* const envelope = Envelope.new("Hello, Memory!");
|
|
73
|
+
*
|
|
74
|
+
* await store.put(arid, envelope, 3600); // 1 hour TTL
|
|
75
|
+
* const result = await store.get(arid);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare class MemoryKv implements KvStore {
|
|
79
|
+
private readonly storage;
|
|
80
|
+
/**
|
|
81
|
+
* Create a new in-memory key-value store.
|
|
82
|
+
*
|
|
83
|
+
* Port of `MemoryKv::new()` from server/memory_kv.rs lines 29-33.
|
|
84
|
+
*/
|
|
85
|
+
constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Check if an ARID exists and is not expired.
|
|
88
|
+
*
|
|
89
|
+
* Port of `check_exists()` from server/memory_kv.rs lines 36-53.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
private checkExists;
|
|
94
|
+
/**
|
|
95
|
+
* Store an envelope at the given ARID.
|
|
96
|
+
*
|
|
97
|
+
* Port of `KvStore::put()` implementation from server/memory_kv.rs lines 62-102.
|
|
98
|
+
*/
|
|
99
|
+
put(arid: ARID, envelope: Envelope, ttlSeconds?: number, verbose?: boolean): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Retrieve an envelope for the given ARID.
|
|
102
|
+
*
|
|
103
|
+
* Port of `KvStore::get()` implementation from server/memory_kv.rs lines 104-181.
|
|
104
|
+
*/
|
|
105
|
+
get(arid: ARID, timeoutSeconds?: number, verbose?: boolean): Promise<Envelope | null>;
|
|
106
|
+
/**
|
|
107
|
+
* Check if an envelope exists at the given ARID.
|
|
108
|
+
*
|
|
109
|
+
* Port of `KvStore::exists()` implementation from server/memory_kv.rs lines 183-186.
|
|
110
|
+
*/
|
|
111
|
+
exists(arid: ARID): Promise<boolean>;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/server/sqlite-kv.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* SQLite-backed key-value store for Gordian Envelopes.
|
|
117
|
+
*
|
|
118
|
+
* Provides persistent storage with TTL support and automatic cleanup of
|
|
119
|
+
* expired entries.
|
|
120
|
+
*
|
|
121
|
+
* Port of `struct SqliteKv` from server/sqlite_kv.rs lines 16-24.
|
|
122
|
+
*
|
|
123
|
+
* @category Server Backend
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const store = new SqliteKv("./hubert.db");
|
|
128
|
+
* const arid = ARID.new();
|
|
129
|
+
* const envelope = Envelope.new("Hello, SQLite!");
|
|
130
|
+
*
|
|
131
|
+
* await store.put(arid, envelope, 3600); // 1 hour TTL
|
|
132
|
+
* const result = await store.get(arid);
|
|
133
|
+
*
|
|
134
|
+
* // Cleanup when done
|
|
135
|
+
* store.close();
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare class SqliteKv implements KvStore {
|
|
139
|
+
private readonly db;
|
|
140
|
+
private readonly dbPath;
|
|
141
|
+
private cleanupInterval;
|
|
142
|
+
/**
|
|
143
|
+
* Create a new SQLite-backed key-value store.
|
|
144
|
+
*
|
|
145
|
+
* Port of `SqliteKv::new()` from server/sqlite_kv.rs lines 26-67.
|
|
146
|
+
*
|
|
147
|
+
* @param dbPath - Path to the SQLite database file. Will be created if it doesn't exist.
|
|
148
|
+
* @throws {SqliteError} If database initialization fails
|
|
149
|
+
*/
|
|
150
|
+
constructor(dbPath: string);
|
|
151
|
+
/**
|
|
152
|
+
* Start a background task that prunes expired entries every minute.
|
|
153
|
+
*
|
|
154
|
+
* Port of `start_cleanup_task()` from server/sqlite_kv.rs lines 70-126.
|
|
155
|
+
*
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
private startCleanupTask;
|
|
159
|
+
/**
|
|
160
|
+
* Check if an ARID exists and is not expired.
|
|
161
|
+
*
|
|
162
|
+
* Port of `check_exists()` from server/sqlite_kv.rs lines 129-170.
|
|
163
|
+
*
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
private checkExists;
|
|
167
|
+
/**
|
|
168
|
+
* Store an envelope at the given ARID.
|
|
169
|
+
*
|
|
170
|
+
* Port of `KvStore::put()` implementation from server/sqlite_kv.rs lines 175-236.
|
|
171
|
+
*/
|
|
172
|
+
put(arid: ARID, envelope: Envelope, ttlSeconds?: number, verbose?: boolean): Promise<string>;
|
|
173
|
+
/**
|
|
174
|
+
* Retrieve an envelope for the given ARID.
|
|
175
|
+
*
|
|
176
|
+
* Port of `KvStore::get()` implementation from server/sqlite_kv.rs lines 238-354.
|
|
177
|
+
*/
|
|
178
|
+
get(arid: ARID, timeoutSeconds?: number, verbose?: boolean): Promise<Envelope | null>;
|
|
179
|
+
/**
|
|
180
|
+
* Check if an envelope exists at the given ARID.
|
|
181
|
+
*
|
|
182
|
+
* Port of `KvStore::exists()` implementation from server/sqlite_kv.rs lines 356-359.
|
|
183
|
+
*/
|
|
184
|
+
exists(arid: ARID): Promise<boolean>;
|
|
185
|
+
/**
|
|
186
|
+
* Close the database connection and stop the cleanup task.
|
|
187
|
+
*/
|
|
188
|
+
close(): void;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/server/server-kv.d.ts
|
|
192
|
+
/**
|
|
193
|
+
* Server-side key-value storage backend.
|
|
194
|
+
*
|
|
195
|
+
* This type allows selecting between in-memory and SQLite storage
|
|
196
|
+
* at server setup time.
|
|
197
|
+
*
|
|
198
|
+
* Port of `enum ServerKv` from server/server_kv.rs lines 7-15.
|
|
199
|
+
*
|
|
200
|
+
* @category Server Backend
|
|
201
|
+
*/
|
|
202
|
+
type ServerKv = MemoryKv | SqliteKv;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new in-memory server KV store.
|
|
205
|
+
*
|
|
206
|
+
* Port of `ServerKv::memory()` from server/server_kv.rs line 19.
|
|
207
|
+
*
|
|
208
|
+
* @returns A new MemoryKv instance
|
|
209
|
+
* @category Server Backend
|
|
210
|
+
*/
|
|
211
|
+
declare function createMemoryKv(): MemoryKv;
|
|
212
|
+
/**
|
|
213
|
+
* Create a new SQLite-backed server KV store.
|
|
214
|
+
*
|
|
215
|
+
* Port of `ServerKv::sqlite()` from server/server_kv.rs line 22.
|
|
216
|
+
*
|
|
217
|
+
* @param store - The SqliteKv instance to use
|
|
218
|
+
* @returns The same SqliteKv instance
|
|
219
|
+
* @category Server Backend
|
|
220
|
+
*/
|
|
221
|
+
declare function createSqliteKv(store: SqliteKv): SqliteKv;
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/server/server.d.ts
|
|
224
|
+
/**
|
|
225
|
+
* Configuration for the Hubert server.
|
|
226
|
+
*
|
|
227
|
+
* Port of `struct ServerConfig` from server/server.rs lines 19-30.
|
|
228
|
+
*
|
|
229
|
+
* @category Server
|
|
230
|
+
*/
|
|
231
|
+
interface ServerConfig {
|
|
232
|
+
/** Port to listen on */
|
|
233
|
+
port: number;
|
|
234
|
+
/**
|
|
235
|
+
* Maximum TTL in seconds allowed.
|
|
236
|
+
* If a put() specifies a TTL higher than this, it will be clamped.
|
|
237
|
+
* If put() specifies None, this value will be used.
|
|
238
|
+
* Hubert is intended for coordination, not long-term storage.
|
|
239
|
+
*/
|
|
240
|
+
maxTtl: number;
|
|
241
|
+
/** Enable verbose logging with timestamps */
|
|
242
|
+
verbose: boolean;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Default server configuration.
|
|
246
|
+
*
|
|
247
|
+
* Port of `impl Default for ServerConfig` from server/server.rs lines 32-40.
|
|
248
|
+
*/
|
|
249
|
+
declare const defaultServerConfig: ServerConfig;
|
|
250
|
+
/**
|
|
251
|
+
* Hubert HTTP server.
|
|
252
|
+
*
|
|
253
|
+
* Port of `struct Server` from server/server.rs lines 128-133.
|
|
254
|
+
*
|
|
255
|
+
* @category Server
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const server = Server.newMemory({ port: 8080, maxTtl: 3600, verbose: true });
|
|
260
|
+
* await server.run();
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
declare class Server {
|
|
264
|
+
private readonly config;
|
|
265
|
+
private readonly state;
|
|
266
|
+
private readonly fastify;
|
|
267
|
+
/**
|
|
268
|
+
* Create a new server with the given configuration and storage backend.
|
|
269
|
+
*
|
|
270
|
+
* Port of `Server::new()` from server/server.rs lines 135-139.
|
|
271
|
+
*/
|
|
272
|
+
constructor(config: ServerConfig, storage: ServerKv);
|
|
273
|
+
/**
|
|
274
|
+
* Create a new server with in-memory storage.
|
|
275
|
+
*
|
|
276
|
+
* Port of `Server::new_memory()` from server/server.rs lines 142-144.
|
|
277
|
+
*/
|
|
278
|
+
static newMemory(config?: Partial<ServerConfig>): Server;
|
|
279
|
+
/**
|
|
280
|
+
* Create a new server with SQLite storage.
|
|
281
|
+
*
|
|
282
|
+
* Port of `Server::new_sqlite()` from server/server.rs lines 147-149.
|
|
283
|
+
*/
|
|
284
|
+
static newSqlite(config: Partial<ServerConfig> | undefined, storage: SqliteKv): Server;
|
|
285
|
+
/**
|
|
286
|
+
* Setup HTTP routes.
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
private setupRoutes;
|
|
290
|
+
/**
|
|
291
|
+
* Handle health check requests.
|
|
292
|
+
*
|
|
293
|
+
* Port of `handle_health()` from server/server.rs lines 179-187.
|
|
294
|
+
*/
|
|
295
|
+
private handleHealth;
|
|
296
|
+
/**
|
|
297
|
+
* Handle PUT requests.
|
|
298
|
+
*
|
|
299
|
+
* Port of `handle_put()` from server/server.rs lines 195-238.
|
|
300
|
+
*/
|
|
301
|
+
private handlePut;
|
|
302
|
+
/**
|
|
303
|
+
* Handle GET requests.
|
|
304
|
+
*
|
|
305
|
+
* Port of `handle_get()` from server/server.rs lines 244-269.
|
|
306
|
+
*/
|
|
307
|
+
private handleGet;
|
|
308
|
+
/**
|
|
309
|
+
* Run the server.
|
|
310
|
+
*
|
|
311
|
+
* Port of `Server::run()` from server/server.rs lines 152-170.
|
|
312
|
+
*/
|
|
313
|
+
run(): Promise<void>;
|
|
314
|
+
/**
|
|
315
|
+
* Get the port the server is configured to listen on.
|
|
316
|
+
*
|
|
317
|
+
* Port of `Server::port()` from server/server.rs line 173.
|
|
318
|
+
*/
|
|
319
|
+
port(): number;
|
|
320
|
+
/**
|
|
321
|
+
* Stop the server.
|
|
322
|
+
*/
|
|
323
|
+
close(): Promise<void>;
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/server/kv.d.ts
|
|
327
|
+
/**
|
|
328
|
+
* Server-backed key-value store using HTTP API.
|
|
329
|
+
*
|
|
330
|
+
* This implementation communicates with a Hubert server via HTTP POST requests.
|
|
331
|
+
*
|
|
332
|
+
* Port of `struct ServerKvClient` from server/kv.rs lines 6-37.
|
|
333
|
+
*
|
|
334
|
+
* @category Server Backend
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const store = new ServerKvClient("http://127.0.0.1:45678");
|
|
339
|
+
* const arid = ARID.new();
|
|
340
|
+
* const envelope = Envelope.new("Hello, Server!");
|
|
341
|
+
*
|
|
342
|
+
* // Put envelope (write-once)
|
|
343
|
+
* await store.put(arid, envelope);
|
|
344
|
+
*
|
|
345
|
+
* // Get envelope with verbose logging
|
|
346
|
+
* const retrieved = await store.get(arid, undefined, true);
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare class ServerKvClient implements KvStore {
|
|
350
|
+
private readonly baseUrl;
|
|
351
|
+
/**
|
|
352
|
+
* Create a new server KV store client.
|
|
353
|
+
*
|
|
354
|
+
* Port of `ServerKvClient::new()` from server/kv.rs lines 39-46.
|
|
355
|
+
*
|
|
356
|
+
* @param baseUrl - Base URL of the Hubert server (e.g., "http://127.0.0.1:45678")
|
|
357
|
+
*/
|
|
358
|
+
constructor(baseUrl: string);
|
|
359
|
+
/**
|
|
360
|
+
* Store an envelope at the given ARID.
|
|
361
|
+
*
|
|
362
|
+
* Port of `KvStore::put()` implementation from server/kv.rs lines 67-122.
|
|
363
|
+
*/
|
|
364
|
+
put(arid: ARID, envelope: Envelope, ttlSeconds?: number, verbose?: boolean): Promise<string>;
|
|
365
|
+
/**
|
|
366
|
+
* Retrieve an envelope for the given ARID.
|
|
367
|
+
*
|
|
368
|
+
* Port of `KvStore::get()` implementation from server/kv.rs lines 124-212.
|
|
369
|
+
*/
|
|
370
|
+
get(arid: ARID, timeoutSeconds?: number, verbose?: boolean): Promise<Envelope | null>;
|
|
371
|
+
/**
|
|
372
|
+
* Check if an envelope exists at the given ARID.
|
|
373
|
+
*
|
|
374
|
+
* Port of `KvStore::exists()` implementation from server/kv.rs lines 214-218.
|
|
375
|
+
*/
|
|
376
|
+
exists(arid: ARID): Promise<boolean>;
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
export { ServerKv as a, SqliteKv as c, ServerGeneralError as d, ServerNetworkError as f, defaultServerConfig as i, MemoryKv as l, SqliteError as m, Server as n, createMemoryKv as o, ServerParseError as p, ServerConfig as r, createSqliteKv as s, ServerKvClient as t, ServerError as u };
|
|
380
|
+
//# sourceMappingURL=index-BEzpUC7r.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BEzpUC7r.d.mts","names":[],"sources":["../src/server/error.ts","../src/server/memory-kv.ts","../src/server/sqlite-kv.ts","../src/server/server-kv.ts","../src/server/server.ts","../src/server/kv.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { r as HubertError, t as KvStore } from "./kv-store-DmngWWuw.mjs";
|
|
2
|
+
import { ARID } from "@bcts/components";
|
|
3
|
+
import { Envelope } from "@bcts/envelope";
|
|
4
|
+
|
|
5
|
+
//#region src/mainline/error.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Base class for Mainline DHT-specific errors.
|
|
8
|
+
*
|
|
9
|
+
* @category Mainline
|
|
10
|
+
*/
|
|
11
|
+
declare class MainlineError extends HubertError {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Value size exceeds DHT limit.
|
|
16
|
+
*
|
|
17
|
+
* Port of `Error::ValueTooLarge { size }` from mainline/error.rs line 4-5.
|
|
18
|
+
*
|
|
19
|
+
* @category Mainline
|
|
20
|
+
*/
|
|
21
|
+
declare class ValueTooLargeError extends MainlineError {
|
|
22
|
+
readonly size: number;
|
|
23
|
+
constructor(size: number);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* DHT operation error.
|
|
27
|
+
*
|
|
28
|
+
* Port of `Error::DhtError` from mainline/error.rs line 7-8.
|
|
29
|
+
*
|
|
30
|
+
* @category Mainline
|
|
31
|
+
*/
|
|
32
|
+
declare class DhtError extends MainlineError {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Put query error.
|
|
37
|
+
*
|
|
38
|
+
* Port of `Error::PutQueryError` from mainline/error.rs line 10-11.
|
|
39
|
+
*
|
|
40
|
+
* @category Mainline
|
|
41
|
+
*/
|
|
42
|
+
declare class PutQueryError extends MainlineError {
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Decode ID error.
|
|
47
|
+
*
|
|
48
|
+
* Port of `Error::DecodeIdError` from mainline/error.rs line 13-14.
|
|
49
|
+
*
|
|
50
|
+
* @category Mainline
|
|
51
|
+
*/
|
|
52
|
+
declare class DecodeIdError extends MainlineError {
|
|
53
|
+
constructor(message: string);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Put mutable error.
|
|
57
|
+
*
|
|
58
|
+
* Port of `Error::PutMutableError` from mainline/error.rs line 16-17.
|
|
59
|
+
*
|
|
60
|
+
* @category Mainline
|
|
61
|
+
*/
|
|
62
|
+
declare class PutMutableError extends MainlineError {
|
|
63
|
+
constructor(message: string);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* I/O error.
|
|
67
|
+
*
|
|
68
|
+
* Port of `Error::Io` from mainline/error.rs line 19-20.
|
|
69
|
+
*
|
|
70
|
+
* @category Mainline
|
|
71
|
+
*/
|
|
72
|
+
declare class MainlineIoError extends MainlineError {
|
|
73
|
+
constructor(message: string);
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/mainline/kv.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Mainline DHT-backed key-value store using ARID-based addressing.
|
|
79
|
+
*
|
|
80
|
+
* This implementation uses:
|
|
81
|
+
* - ARID → ed25519 signing key derivation (deterministic)
|
|
82
|
+
* - BEP-44 mutable storage (fixed location based on pubkey)
|
|
83
|
+
* - Mainline DHT (BitTorrent DHT) for decentralized storage
|
|
84
|
+
* - Write-once semantics (seq=1, put fails if already exists)
|
|
85
|
+
* - Maximum value size: 1000 bytes (DHT protocol limit)
|
|
86
|
+
*
|
|
87
|
+
* Port of `struct MainlineDhtKv` from mainline/kv.rs lines 60-64.
|
|
88
|
+
*
|
|
89
|
+
* # Storage Model
|
|
90
|
+
*
|
|
91
|
+
* Uses BEP-44 mutable items where:
|
|
92
|
+
* - Public key derived from ARID (deterministic ed25519)
|
|
93
|
+
* - Sequence number starts at 1 (write-once)
|
|
94
|
+
* - Optional salt for namespace separation
|
|
95
|
+
* - Location fixed by pubkey (not content hash)
|
|
96
|
+
*
|
|
97
|
+
* # Requirements
|
|
98
|
+
*
|
|
99
|
+
* No external daemon required - the DHT client runs embedded.
|
|
100
|
+
*
|
|
101
|
+
* # Size Limits
|
|
102
|
+
*
|
|
103
|
+
* The Mainline DHT has a practical limit of ~1KB per value. For larger
|
|
104
|
+
* envelopes, use `IpfsKv` or `HybridKv` instead.
|
|
105
|
+
*
|
|
106
|
+
* @category Mainline Backend
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const store = await MainlineDhtKv.create();
|
|
111
|
+
* const arid = ARID.new();
|
|
112
|
+
* const envelope = Envelope.new("Small message");
|
|
113
|
+
*
|
|
114
|
+
* // Put envelope (write-once)
|
|
115
|
+
* await store.put(arid, envelope);
|
|
116
|
+
*
|
|
117
|
+
* // Get envelope with verbose logging
|
|
118
|
+
* const retrieved = await store.get(arid, undefined, true);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare class MainlineDhtKv implements KvStore {
|
|
122
|
+
private readonly dht;
|
|
123
|
+
private maxValueSize;
|
|
124
|
+
private salt;
|
|
125
|
+
private _isBootstrapped;
|
|
126
|
+
/**
|
|
127
|
+
* Private constructor - use `create()` factory method.
|
|
128
|
+
*/
|
|
129
|
+
private constructor();
|
|
130
|
+
/**
|
|
131
|
+
* Check if the DHT is bootstrapped.
|
|
132
|
+
*/
|
|
133
|
+
get isBootstrapped(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Create a new Mainline DHT KV store with default settings.
|
|
136
|
+
*
|
|
137
|
+
* Port of `MainlineDhtKv::new()` from mainline/kv.rs lines 68-79.
|
|
138
|
+
*/
|
|
139
|
+
static create(): Promise<MainlineDhtKv>;
|
|
140
|
+
/**
|
|
141
|
+
* Set the maximum value size (default: 1000 bytes).
|
|
142
|
+
*
|
|
143
|
+
* Note: Values larger than ~1KB may not be reliably stored in the DHT.
|
|
144
|
+
*
|
|
145
|
+
* Port of `MainlineDhtKv::with_max_size()` from mainline/kv.rs lines 84-87.
|
|
146
|
+
*/
|
|
147
|
+
withMaxSize(size: number): this;
|
|
148
|
+
/**
|
|
149
|
+
* Set a salt for namespace separation.
|
|
150
|
+
*
|
|
151
|
+
* Different salts will create separate namespaces for the same ARID.
|
|
152
|
+
*
|
|
153
|
+
* Port of `MainlineDhtKv::with_salt()` from mainline/kv.rs lines 92-95.
|
|
154
|
+
*/
|
|
155
|
+
withSalt(salt: Uint8Array): this;
|
|
156
|
+
/**
|
|
157
|
+
* Derive an ed25519 signing key from an ARID.
|
|
158
|
+
*
|
|
159
|
+
* Uses the ARID-derived key material extended to 32 bytes for ed25519.
|
|
160
|
+
*
|
|
161
|
+
* Port of `MainlineDhtKv::derive_signing_key()` from mainline/kv.rs lines 100-112.
|
|
162
|
+
*
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
private static deriveSigningKey;
|
|
166
|
+
/**
|
|
167
|
+
* Get mutable item from DHT.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
private getMutable;
|
|
172
|
+
/**
|
|
173
|
+
* Put mutable item to DHT.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
private putMutable;
|
|
178
|
+
/**
|
|
179
|
+
* Compute DHT target hash from public key and optional salt.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
private computeTarget;
|
|
184
|
+
/**
|
|
185
|
+
* Store an envelope at the given ARID.
|
|
186
|
+
*
|
|
187
|
+
* Port of `KvStore::put()` implementation from mainline/kv.rs lines 144-220.
|
|
188
|
+
*/
|
|
189
|
+
put(arid: ARID, envelope: Envelope, _ttlSeconds?: number, // Ignored - DHT has no TTL support
|
|
190
|
+
verbose?: boolean): Promise<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Retrieve an envelope for the given ARID.
|
|
193
|
+
*
|
|
194
|
+
* Port of `KvStore::get()` implementation from mainline/kv.rs lines 223-303.
|
|
195
|
+
*/
|
|
196
|
+
get(arid: ARID, timeoutSeconds?: number, verbose?: boolean): Promise<Envelope | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Check if an envelope exists at the given ARID.
|
|
199
|
+
*
|
|
200
|
+
* Port of `KvStore::exists()` implementation from mainline/kv.rs lines 306-314.
|
|
201
|
+
*/
|
|
202
|
+
exists(arid: ARID): Promise<boolean>;
|
|
203
|
+
/**
|
|
204
|
+
* Destroy the DHT client and release resources.
|
|
205
|
+
*/
|
|
206
|
+
destroy(): Promise<void>;
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
export { MainlineIoError as a, ValueTooLargeError as c, MainlineError as i, DecodeIdError as n, PutMutableError as o, DhtError as r, PutQueryError as s, MainlineDhtKv as t };
|
|
210
|
+
//# sourceMappingURL=index-C2F6ugLL.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-C2F6ugLL.d.mts","names":[],"sources":["../src/mainline/error.ts","../src/mainline/kv.ts"],"mappings":";;;;;;;;;;cAea,aAAA,SAAsB,WAAA;cACrB,OAAA;AAAA;;;;;;;;cAaD,kBAAA,SAA2B,aAAA;EAAA,SAC7B,IAAA;cAEG,IAAA;AAAA;;;;;;;AA4Bd;cAda,QAAA,SAAiB,aAAA;cAChB,OAAA;AAAA;;;;;;AA2Bd;;cAda,aAAA,SAAsB,aAAA;cACrB,OAAA;AAAA;;;;;AA2Bd;;;cAda,aAAA,SAAsB,aAAA;cACrB,OAAA;AAAA;;;;AA2Bd;;;;cAda,eAAA,SAAwB,aAAA;cACvB,OAAA;AAAA;;;;;;ACxBd;;cDqCa,eAAA,SAAwB,aAAA;cACvB,OAAA;AAAA;;;;;;;AA1Ed;;;;;;;;;;AAiBA;;;;;;;;;AAcA;;;;;;;;;AAcA;;;;;;;;;AAcA;;;cCvBa,aAAA,YAAyB,OAAA;EAAA,iBACnB,GAAA;EAAA,QACT,YAAA;EAAA,QACA,IAAA;EAAA,QACA,eAAA;EDoBmB;AAa7B;;EAb6B,QCfpB,WAAA,CAAA;ED4ByC;;;EAAA,IClB5C,cAAA,CAAA;EDmBuB;;;;;EAAA,OCVd,MAAA,CAAA,GAAU,OAAA,CAAQ,aAAA;EA5BN;;;;;;;EA6DzB,WAAA,CAAY,IAAA;EAiMI;;;;;;;EArLhB,QAAA,CAAS,IAAA,EAAM,UAAA;EAzE4B;;;;;;;;;EAAA,eAuF5B,gBAAA;EA3DgB;;;;;EAAA,QAiFvB,UAAA;EAtBO;;;;;EAAA,QAyCP,UAAA;EA4DN;;;;;EAAA,QAlBM,aAAA;EAoFF;;;;;EAnEA,GAAA,CACJ,IAAA,EAAM,IAAA,EACN,QAAA,EAAU,QAAA,EACV,WAAA;EACA,OAAA,aACC,OAAA;EAuIG;;;;;EAzEA,GAAA,CAAI,IAAA,EAAM,IAAA,EAAM,cAAA,WAAyB,OAAA,aAAoB,OAAA,CAAQ,QAAA;EAoFzD;;;;;EAXZ,MAAA,CAAO,IAAA,EAAM,IAAA,GAAO,OAAA;;;;EAW1B,OAAA,CAAA,GAAW,OAAA;AAAA"}
|