swarm-mail 1.4.0 → 1.5.0
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/adapter.d.ts.map +1 -1
- package/dist/analytics.d.ts +46 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/db/retry.d.ts +24 -0
- package/dist/db/retry.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90412 -90234
- package/dist/libsql.d.ts.map +1 -1
- package/dist/streams/durable-adapter.d.ts +85 -0
- package/dist/streams/durable-adapter.d.ts.map +1 -0
- package/dist/streams/durable-server.d.ts +55 -0
- package/dist/streams/durable-server.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/libsql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../src/libsql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GAChB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;CAAE,CAuFhD;AAmGD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"libsql.d.ts","sourceRoot":"","sources":["../src/libsql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,qBAAqB,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GAChB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;CAAE,CAuFhD;AAmGD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,eAAe,CAAC,CA8B1B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable Streams Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts swarm-mail event store to the Durable Streams protocol.
|
|
5
|
+
*
|
|
6
|
+
* Protocol: https://github.com/durable-streams/durable-streams
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Offset-based resumability (refresh-safe, multi-device, multi-tab)
|
|
10
|
+
* - Long-poll and SSE modes for live tailing
|
|
11
|
+
* - Catch-up reads from any offset
|
|
12
|
+
* - CDN-friendly design for massive fan-out
|
|
13
|
+
*
|
|
14
|
+
* @see .hive/analysis/hive-cell-visualizer.md for full architecture
|
|
15
|
+
*/
|
|
16
|
+
import type { SwarmMailAdapter } from "../types/adapter.js";
|
|
17
|
+
/**
|
|
18
|
+
* StreamEvent format for Durable Streams protocol
|
|
19
|
+
*/
|
|
20
|
+
export interface StreamEvent {
|
|
21
|
+
/** Event sequence number (serves as offset for resumability) */
|
|
22
|
+
offset: number;
|
|
23
|
+
/** JSON-encoded AgentEvent */
|
|
24
|
+
data: string;
|
|
25
|
+
/** Unix timestamp in milliseconds */
|
|
26
|
+
timestamp: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* DurableStreamAdapter interface
|
|
30
|
+
*
|
|
31
|
+
* Provides offset-based access to the swarm-mail event store.
|
|
32
|
+
* Compatible with Durable Streams protocol.
|
|
33
|
+
*/
|
|
34
|
+
export interface DurableStreamAdapter {
|
|
35
|
+
/**
|
|
36
|
+
* Read events starting from offset
|
|
37
|
+
*
|
|
38
|
+
* @param offset - Start reading AFTER this sequence number (0 = from beginning)
|
|
39
|
+
* @param limit - Maximum number of events to return
|
|
40
|
+
* @returns Array of StreamEvents
|
|
41
|
+
*/
|
|
42
|
+
read(offset: number, limit: number): Promise<StreamEvent[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the latest sequence number
|
|
45
|
+
*
|
|
46
|
+
* @returns Latest sequence number (0 if no events)
|
|
47
|
+
*/
|
|
48
|
+
head(): Promise<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Subscribe to new events (polling-based)
|
|
51
|
+
*
|
|
52
|
+
* Polls every 100ms for new events and calls callback.
|
|
53
|
+
* Only delivers events that arrive AFTER subscription starts.
|
|
54
|
+
*
|
|
55
|
+
* @param callback - Called with each new event
|
|
56
|
+
* @returns Unsubscribe function
|
|
57
|
+
*/
|
|
58
|
+
subscribe(callback: (event: StreamEvent) => void): () => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a DurableStreamAdapter for a specific project
|
|
62
|
+
*
|
|
63
|
+
* @param swarmMail - SwarmMailAdapter instance
|
|
64
|
+
* @param projectKey - Project key to filter events by
|
|
65
|
+
* @returns DurableStreamAdapter instance
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const swarmMail = await createInMemorySwarmMailLibSQL("test");
|
|
70
|
+
* const adapter = createDurableStreamAdapter(swarmMail, "/path/to/project");
|
|
71
|
+
*
|
|
72
|
+
* // Read events from beginning
|
|
73
|
+
* const events = await adapter.read(0, 100);
|
|
74
|
+
*
|
|
75
|
+
* // Get latest sequence
|
|
76
|
+
* const head = await adapter.head();
|
|
77
|
+
*
|
|
78
|
+
* // Subscribe to new events
|
|
79
|
+
* const unsubscribe = adapter.subscribe((event) => {
|
|
80
|
+
* console.log("New event:", event);
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function createDurableStreamAdapter(swarmMail: SwarmMailAdapter, projectKey: string): DurableStreamAdapter;
|
|
85
|
+
//# sourceMappingURL=durable-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-adapter.d.ts","sourceRoot":"","sources":["../../src/streams/durable-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAE5D;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExB;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC/D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,gBAAgB,EAC3B,UAAU,EAAE,MAAM,GACjB,oBAAoB,CAqEtB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable Streams HTTP Server
|
|
3
|
+
*
|
|
4
|
+
* Exposes the Durable Streams protocol via Server-Sent Events (SSE).
|
|
5
|
+
* Built with Bun.serve() for HTTP server.
|
|
6
|
+
*
|
|
7
|
+
* Port 4483 = HIVE on phone keypad
|
|
8
|
+
*
|
|
9
|
+
* ## Endpoints
|
|
10
|
+
*
|
|
11
|
+
* GET /streams/:projectKey?offset=N&live=true
|
|
12
|
+
* - offset: Start reading from this sequence (default 0)
|
|
13
|
+
* - live: If true, keep connection open and stream new events via SSE
|
|
14
|
+
*
|
|
15
|
+
* ## SSE Format
|
|
16
|
+
*
|
|
17
|
+
* data: {json}\n\n
|
|
18
|
+
*
|
|
19
|
+
* Each event is sent as a JSON-encoded StreamEvent:
|
|
20
|
+
* { offset: number, data: string, timestamp: number }
|
|
21
|
+
*/
|
|
22
|
+
import type { DurableStreamAdapter } from "./durable-adapter.js";
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for the Durable Stream HTTP server
|
|
25
|
+
*/
|
|
26
|
+
export interface DurableStreamServerConfig {
|
|
27
|
+
/** Adapter for reading events */
|
|
28
|
+
adapter: DurableStreamAdapter;
|
|
29
|
+
/** Port to listen on (default 4483 - HIVE on phone keypad) */
|
|
30
|
+
port?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Durable Stream HTTP server interface
|
|
34
|
+
*/
|
|
35
|
+
export interface DurableStreamServer {
|
|
36
|
+
/** Start the HTTP server */
|
|
37
|
+
start(): Promise<void>;
|
|
38
|
+
/** Stop the HTTP server and clean up subscriptions */
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
/** Base URL of the server */
|
|
41
|
+
url: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Durable Streams HTTP server exposing events via SSE
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const adapter = createDurableStreamAdapter(swarmMail, "/my/project");
|
|
49
|
+
* const server = createDurableStreamServer({ adapter });
|
|
50
|
+
* await server.start();
|
|
51
|
+
* console.log(`Streaming at ${server.url}/streams/my-project`);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createDurableStreamServer(config: DurableStreamServerConfig): DurableStreamServer;
|
|
55
|
+
//# sourceMappingURL=durable-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-server.d.ts","sourceRoot":"","sources":["../../src/streams/durable-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAe,MAAM,sBAAsB,CAAC;AAK9E;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,iCAAiC;IACjC,OAAO,EAAE,oBAAoB,CAAC;IAC9B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,sDAAsD;IACtD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,GAChC,mBAAmB,CAmJrB"}
|