@durable-streams/server 0.2.2 → 0.2.3
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/README.md +23 -57
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @durable-streams/server
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
This package provides a reference implementation of the Durable Streams protocol for Node.js. It supports both in-memory and file-backed storage modes, making it suitable for development, testing, and production
|
|
13
|
+
This package provides a reference implementation of the Durable Streams protocol for Node.js. It supports both in-memory and file-backed storage modes, making it suitable for development, testing, and prototyping. For production deployments, use the [Caddy plugin](../caddy-plugin/README.md) or [Electric Cloud](https://dashboard.electric-sql.cloud).
|
|
14
14
|
|
|
15
15
|
For a standalone binary option, see the [Caddy-based server](https://github.com/durable-streams/durable-streams/releases).
|
|
16
16
|
|
|
@@ -32,16 +32,10 @@ console.log("Server running on http://127.0.0.1:4437")
|
|
|
32
32
|
|
|
33
33
|
### In-Memory (Default)
|
|
34
34
|
|
|
35
|
-
Fast, ephemeral storage for development and testing:
|
|
35
|
+
Fast, ephemeral storage for development and testing. Omit `dataDir` to use in-memory:
|
|
36
36
|
|
|
37
37
|
```typescript
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const store = new StreamStore()
|
|
41
|
-
const server = new DurableStreamTestServer({
|
|
42
|
-
port: 4437,
|
|
43
|
-
store,
|
|
44
|
-
})
|
|
38
|
+
const server = new DurableStreamTestServer({ port: 4437 })
|
|
45
39
|
```
|
|
46
40
|
|
|
47
41
|
### File-Backed
|
|
@@ -49,52 +43,43 @@ const server = new DurableStreamTestServer({
|
|
|
49
43
|
Persistent storage with streams stored as log files and LMDB for metadata:
|
|
50
44
|
|
|
51
45
|
```typescript
|
|
52
|
-
import {
|
|
53
|
-
DurableStreamTestServer,
|
|
54
|
-
FileBackedStreamStore,
|
|
55
|
-
} from "@durable-streams/server"
|
|
56
|
-
|
|
57
|
-
const store = new FileBackedStreamStore({
|
|
58
|
-
path: "./data/streams",
|
|
59
|
-
})
|
|
60
46
|
const server = new DurableStreamTestServer({
|
|
61
47
|
port: 4437,
|
|
62
|
-
|
|
48
|
+
dataDir: "./data/streams",
|
|
63
49
|
})
|
|
64
50
|
```
|
|
65
51
|
|
|
66
|
-
##
|
|
52
|
+
## Lifecycle Hooks
|
|
67
53
|
|
|
68
|
-
Track stream
|
|
54
|
+
Track stream creation and deletion events:
|
|
69
55
|
|
|
70
56
|
```typescript
|
|
71
|
-
import {
|
|
72
|
-
DurableStreamTestServer,
|
|
73
|
-
createRegistryHooks,
|
|
74
|
-
} from "@durable-streams/server"
|
|
75
|
-
|
|
76
57
|
const server = new DurableStreamTestServer({
|
|
77
58
|
port: 4437,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
59
|
+
onStreamCreated: (event) => {
|
|
60
|
+
console.log(`Stream created: ${event.path} (${event.contentType})`)
|
|
61
|
+
},
|
|
62
|
+
onStreamDeleted: (event) => {
|
|
63
|
+
console.log(`Stream deleted: ${event.path}`)
|
|
64
|
+
},
|
|
81
65
|
})
|
|
82
66
|
```
|
|
83
67
|
|
|
84
|
-
The registry maintains a system stream that tracks all stream creates and deletes, useful for building admin UIs or monitoring.
|
|
85
|
-
|
|
86
68
|
## API
|
|
87
69
|
|
|
88
70
|
### DurableStreamTestServer
|
|
89
71
|
|
|
90
|
-
|
|
72
|
+
````typescript
|
|
91
73
|
interface TestServerOptions {
|
|
92
|
-
port?: number
|
|
93
|
-
host?: string
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
port?: number // Default: 4437
|
|
75
|
+
host?: string // Default: "127.0.0.1"
|
|
76
|
+
longPollTimeout?: number // Default: 30000 (ms)
|
|
77
|
+
dataDir?: string // File-backed storage; omit for in-memory
|
|
78
|
+
onStreamCreated?: StreamLifecycleHook // Hook for stream creation
|
|
79
|
+
onStreamDeleted?: StreamLifecycleHook // Hook for stream deletion
|
|
80
|
+
compression?: boolean // Default: true
|
|
81
|
+
cursorIntervalSeconds?: number // Default: 20
|
|
82
|
+
cursorEpoch?: Date // Epoch for cursor calculation
|
|
98
83
|
}
|
|
99
84
|
|
|
100
85
|
class DurableStreamTestServer {
|
|
@@ -104,25 +89,6 @@ class DurableStreamTestServer {
|
|
|
104
89
|
readonly port: number
|
|
105
90
|
readonly baseUrl: string
|
|
106
91
|
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### StreamStore
|
|
110
|
-
|
|
111
|
-
In-memory stream storage:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
class StreamStore {
|
|
115
|
-
create(path: string, contentType: string, options?: CreateOptions): Stream
|
|
116
|
-
get(path: string): Stream | undefined
|
|
117
|
-
delete(path: string): boolean
|
|
118
|
-
append(path: string, data: Uint8Array, seq?: string): void
|
|
119
|
-
read(path: string, offset: string): ReadResult
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### FileBackedStreamStore
|
|
124
|
-
|
|
125
|
-
File-backed persistent storage (log files for streams, LMDB for metadata) with the same interface as `StreamStore`.
|
|
126
92
|
|
|
127
93
|
## Exports
|
|
128
94
|
|
|
@@ -148,7 +114,7 @@ export type {
|
|
|
148
114
|
StreamLifecycleEvent,
|
|
149
115
|
StreamLifecycleHook,
|
|
150
116
|
} from "./types"
|
|
151
|
-
|
|
117
|
+
````
|
|
152
118
|
|
|
153
119
|
## Testing Your Implementation
|
|
154
120
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@durable-streams/server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Node.js reference server implementation for Durable Streams",
|
|
5
5
|
"author": "Durable Stream contributors",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@neophi/sieve-cache": "^1.0.0",
|
|
41
41
|
"lmdb": "^3.3.0",
|
|
42
|
-
"@durable-streams/client": "0.2.
|
|
43
|
-
"@durable-streams/state": "0.2.
|
|
42
|
+
"@durable-streams/client": "0.2.3",
|
|
43
|
+
"@durable-streams/state": "0.2.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^22.0.0",
|
|
47
47
|
"tsdown": "^0.9.0",
|
|
48
48
|
"typescript": "^5.0.0",
|
|
49
49
|
"vitest": "^4.0.0",
|
|
50
|
-
"@durable-streams/server-conformance-tests": "0.2.
|
|
50
|
+
"@durable-streams/server-conformance-tests": "0.2.3"
|
|
51
51
|
},
|
|
52
52
|
"files": [
|
|
53
53
|
"dist",
|