@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,215 @@
|
|
|
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
|
+
import { KuboRPCClient } from "kubo-rpc-client";
|
|
5
|
+
|
|
6
|
+
//#region src/ipfs/error.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Base class for IPFS-specific errors.
|
|
9
|
+
*
|
|
10
|
+
* @category IPFS
|
|
11
|
+
*/
|
|
12
|
+
declare class IpfsError extends HubertError {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Envelope size exceeds practical limit.
|
|
17
|
+
*
|
|
18
|
+
* Port of `Error::EnvelopeTooLarge { size }` from ipfs/error.rs line 5.
|
|
19
|
+
*
|
|
20
|
+
* @category IPFS
|
|
21
|
+
*/
|
|
22
|
+
declare class EnvelopeTooLargeError extends IpfsError {
|
|
23
|
+
readonly size: number;
|
|
24
|
+
constructor(size: number);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* IPFS daemon error.
|
|
28
|
+
*
|
|
29
|
+
* Port of `Error::DaemonError` from ipfs/error.rs line 8.
|
|
30
|
+
*
|
|
31
|
+
* @category IPFS
|
|
32
|
+
*/
|
|
33
|
+
declare class IpfsDaemonError extends IpfsError {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Operation timed out.
|
|
38
|
+
*
|
|
39
|
+
* Port of `Error::Timeout` from ipfs/error.rs line 11.
|
|
40
|
+
*
|
|
41
|
+
* @category IPFS
|
|
42
|
+
*/
|
|
43
|
+
declare class IpfsTimeoutError extends IpfsError {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Unexpected IPNS path format.
|
|
48
|
+
*
|
|
49
|
+
* Port of `Error::UnexpectedIpnsPathFormat` from ipfs/error.rs line 14.
|
|
50
|
+
*
|
|
51
|
+
* @category IPFS
|
|
52
|
+
*/
|
|
53
|
+
declare class UnexpectedIpnsPathFormatError extends IpfsError {
|
|
54
|
+
readonly path: string;
|
|
55
|
+
constructor(path: string);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/ipfs/value.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* Add (upload) bytes to IPFS and return the CID.
|
|
61
|
+
*
|
|
62
|
+
* Port of `add_bytes()` from ipfs/value.rs lines 9-15.
|
|
63
|
+
*
|
|
64
|
+
* @param client - Kubo RPC client
|
|
65
|
+
* @param bytes - Data to add
|
|
66
|
+
* @returns CID of the added content
|
|
67
|
+
*
|
|
68
|
+
* @category IPFS
|
|
69
|
+
*/
|
|
70
|
+
declare function addBytes(client: KuboRPCClient, bytes: Uint8Array): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Cat (download) bytes from IPFS by CID.
|
|
73
|
+
*
|
|
74
|
+
* Port of `cat_bytes()` from ipfs/value.rs lines 18-28.
|
|
75
|
+
*
|
|
76
|
+
* @param client - Kubo RPC client
|
|
77
|
+
* @param cid - Content identifier
|
|
78
|
+
* @returns Content bytes
|
|
79
|
+
*
|
|
80
|
+
* @category IPFS
|
|
81
|
+
*/
|
|
82
|
+
declare function catBytes(client: KuboRPCClient, cid: string): Promise<Uint8Array>;
|
|
83
|
+
/**
|
|
84
|
+
* Pin a CID to ensure it persists in local IPFS storage.
|
|
85
|
+
*
|
|
86
|
+
* Port of `pin_cid()` from ipfs/value.rs lines 31-38.
|
|
87
|
+
*
|
|
88
|
+
* @param client - Kubo RPC client
|
|
89
|
+
* @param cid - Content identifier to pin
|
|
90
|
+
* @param recursive - Whether to recursively pin linked content
|
|
91
|
+
*
|
|
92
|
+
* @category IPFS
|
|
93
|
+
*/
|
|
94
|
+
declare function pinCid(client: KuboRPCClient, cid: string, recursive: boolean): Promise<void>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/ipfs/kv.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* IPFS-backed key-value store using IPNS for ARID-based addressing.
|
|
99
|
+
*
|
|
100
|
+
* This implementation uses:
|
|
101
|
+
* - ARID → IPNS key name derivation (deterministic)
|
|
102
|
+
* - IPFS content addressing (CID) for immutable storage
|
|
103
|
+
* - IPNS for publish-once mutable names
|
|
104
|
+
* - Write-once semantics (publish fails if name already exists)
|
|
105
|
+
*
|
|
106
|
+
* Port of `struct IpfsKv` from ipfs/kv.rs lines 54-60.
|
|
107
|
+
*
|
|
108
|
+
* # Requirements
|
|
109
|
+
*
|
|
110
|
+
* Requires a running Kubo daemon (or compatible IPFS node) with RPC API
|
|
111
|
+
* available at the configured endpoint (default: http://127.0.0.1:5001).
|
|
112
|
+
*
|
|
113
|
+
* @category IPFS Backend
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const store = new IpfsKv("http://127.0.0.1:5001");
|
|
118
|
+
* const arid = ARID.new();
|
|
119
|
+
* const envelope = Envelope.new("Hello, IPFS!");
|
|
120
|
+
*
|
|
121
|
+
* // Put envelope (write-once)
|
|
122
|
+
* await store.put(arid, envelope);
|
|
123
|
+
*
|
|
124
|
+
* // Get envelope with verbose logging
|
|
125
|
+
* const retrieved = await store.get(arid, undefined, true);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare class IpfsKv implements KvStore {
|
|
129
|
+
private readonly client;
|
|
130
|
+
private readonly keyCache;
|
|
131
|
+
private maxEnvelopeSize;
|
|
132
|
+
private resolveTimeoutMs;
|
|
133
|
+
private pinContent;
|
|
134
|
+
/**
|
|
135
|
+
* Create a new IPFS KV store with default settings.
|
|
136
|
+
*
|
|
137
|
+
* Port of `IpfsKv::new()` from ipfs/kv.rs lines 73-81.
|
|
138
|
+
*
|
|
139
|
+
* @param rpcUrl - IPFS RPC endpoint (e.g., "http://127.0.0.1:5001")
|
|
140
|
+
*/
|
|
141
|
+
constructor(rpcUrl: string);
|
|
142
|
+
/**
|
|
143
|
+
* Set the maximum envelope size (default: 10 MB).
|
|
144
|
+
*
|
|
145
|
+
* Port of `IpfsKv::with_max_size()` from ipfs/kv.rs lines 84-87.
|
|
146
|
+
*/
|
|
147
|
+
withMaxSize(size: number): this;
|
|
148
|
+
/**
|
|
149
|
+
* Set the IPNS resolve timeout (default: 30 seconds).
|
|
150
|
+
*
|
|
151
|
+
* Port of `IpfsKv::with_resolve_timeout()` from ipfs/kv.rs lines 90-93.
|
|
152
|
+
*
|
|
153
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
154
|
+
*/
|
|
155
|
+
withResolveTimeout(timeoutMs: number): this;
|
|
156
|
+
/**
|
|
157
|
+
* Set whether to pin content (default: false).
|
|
158
|
+
*
|
|
159
|
+
* Port of `IpfsKv::with_pin_content()` from ipfs/kv.rs lines 96-99.
|
|
160
|
+
*/
|
|
161
|
+
withPinContent(pin: boolean): this;
|
|
162
|
+
/**
|
|
163
|
+
* Get or create an IPNS key for the given ARID.
|
|
164
|
+
*
|
|
165
|
+
* Port of `IpfsKv::get_or_create_key()` from ipfs/kv.rs lines 102-142.
|
|
166
|
+
*
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
169
|
+
private getOrCreateKey;
|
|
170
|
+
/**
|
|
171
|
+
* Check if an IPNS name is already published.
|
|
172
|
+
*
|
|
173
|
+
* Port of `IpfsKv::is_published()` from ipfs/kv.rs lines 145-161.
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
private isPublished;
|
|
178
|
+
/**
|
|
179
|
+
* Publish a CID to an IPNS name (write-once).
|
|
180
|
+
*
|
|
181
|
+
* Port of `IpfsKv::publish_once()` from ipfs/kv.rs lines 164-204.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
private publishOnce;
|
|
186
|
+
/**
|
|
187
|
+
* Resolve an IPNS name to a CID with polling and custom timeout.
|
|
188
|
+
*
|
|
189
|
+
* Port of `IpfsKv::resolve_with_retry_timeout()` from ipfs/kv.rs lines 207-258.
|
|
190
|
+
*
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
private resolveWithRetryTimeout;
|
|
194
|
+
/**
|
|
195
|
+
* Store an envelope at the given ARID.
|
|
196
|
+
*
|
|
197
|
+
* Port of `KvStore::put()` implementation from ipfs/kv.rs lines 289-367.
|
|
198
|
+
*/
|
|
199
|
+
put(arid: ARID, envelope: Envelope, ttlSeconds?: number, verbose?: boolean): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Retrieve an envelope for the given ARID.
|
|
202
|
+
*
|
|
203
|
+
* Port of `KvStore::get()` implementation from ipfs/kv.rs lines 370-450.
|
|
204
|
+
*/
|
|
205
|
+
get(arid: ARID, timeoutSeconds?: number, verbose?: boolean): Promise<Envelope | null>;
|
|
206
|
+
/**
|
|
207
|
+
* Check if an envelope exists at the given ARID.
|
|
208
|
+
*
|
|
209
|
+
* Port of `KvStore::exists()` implementation from ipfs/kv.rs lines 453-481.
|
|
210
|
+
*/
|
|
211
|
+
exists(arid: ARID): Promise<boolean>;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { EnvelopeTooLargeError as a, IpfsTimeoutError as c, pinCid as i, UnexpectedIpnsPathFormatError as l, addBytes as n, IpfsDaemonError as o, catBytes as r, IpfsError as s, IpfsKv as t };
|
|
215
|
+
//# sourceMappingURL=index-CUnDouMb.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-CUnDouMb.d.mts","names":[],"sources":["../src/ipfs/error.ts","../src/ipfs/value.ts","../src/ipfs/kv.ts"],"mappings":";;;;;;;;;;;cAea,SAAA,SAAkB,WAAA;cACjB,OAAA;AAAA;;;;;;;;cAaD,qBAAA,SAA8B,SAAA;EAAA,SAChC,IAAA;cAEG,IAAA;AAAA;;;;;;;;cAcD,eAAA,SAAwB,SAAA;cACvB,OAAA;AAAA;;;AA2Bd;;;;;cAda,gBAAA,SAAyB,SAAA;EAAA,WAAA,CAAA;AAAA;;;;;;ACrCtC;;cDmDa,6BAAA,SAAsC,SAAA;EAAA,SACxC,IAAA;cAEG,IAAA;AAAA;;;;;;;;;;AAhDd;;;;iBCNsB,QAAA,CAAS,MAAA,EAAQ,aAAA,EAAe,KAAA,EAAO,UAAA,GAAa,OAAA;;;;;;ADuB1E;;;;;;iBCHsB,QAAA,CAAS,MAAA,EAAQ,aAAA,EAAe,GAAA,WAAc,OAAA,CAAQ,UAAA;;;ADiB5E;;;;;AAcA;;;;iBCAsB,MAAA,CACpB,MAAA,EAAQ,aAAA,EACR,GAAA,UACA,SAAA,YACC,OAAA;;;;;;;;ADjDH;;;;;;;;;;AAiBA;;;;;;;;;AAcA;;;;;AAcA;;cEVa,MAAA,YAAkB,OAAA;EAAA,iBACZ,MAAA;EAAA,iBACA,QAAA;EAAA,QACT,eAAA;EAAA,QACA,gBAAA;EAAA,QACA,UAAA;EFQgB;;;;;ACtD1B;;cCuDc,MAAA;EDvDyB;;;;;ECoErC,WAAA,CAAY,IAAA;EDpEiB;;;;;;AAoB/B;EC4DE,kBAAA,CAAmB,SAAA;;;;;;EAUnB,cAAA,CAAe,GAAA;EDtEsB;;;;;;;EAAA,QCkFvB,cAAA;EDnDY;;;;;;;EAAA,QCwFZ,WAAA;EDpFN;;;;;ACdV;;EDcU,QCiHM,WAAA;EAqGN;;;;;;;EAAA,QAvDM,uBAAA;EA7Ke;;;;;EAmOvB,GAAA,CACJ,IAAA,EAAM,IAAA,EACN,QAAA,EAAU,QAAA,EACV,UAAA,WACA,OAAA,aACC,OAAA;EArOK;;;;;EAySF,GAAA,CAAI,IAAA,EAAM,IAAA,EAAM,cAAA,WAAyB,OAAA,aAAoB,OAAA,CAAQ,QAAA;EAjR/D;;;;;EAyWN,MAAA,CAAO,IAAA,EAAM,IAAA,GAAO,OAAA;AAAA"}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { r as HubertError, t as KvStore } from "./kv-store-ww-AUyLd.cjs";
|
|
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-CV6lZJqY.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-CV6lZJqY.d.cts","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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"}
|