@durable-streams/server 0.1.1 → 0.1.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 +167 -0
- package/dist/index.cjs +1682 -0
- package/dist/index.d.cts +518 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +83 -26
- package/package.json +4 -4
- package/src/file-store.ts +58 -16
- package/src/store.ts +59 -10
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# @durable-streams/server
|
|
2
|
+
|
|
3
|
+
Node.js reference server implementation for the Durable Streams protocol.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @durable-streams/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
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 workloads.
|
|
14
|
+
|
|
15
|
+
For a standalone binary option, see the [Caddy-based server](https://github.com/durable-streams/durable-streams/releases).
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { DurableStreamTestServer } from "@durable-streams/server"
|
|
21
|
+
|
|
22
|
+
const server = new DurableStreamTestServer({
|
|
23
|
+
port: 4437,
|
|
24
|
+
host: "127.0.0.1",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
await server.start()
|
|
28
|
+
console.log("Server running on http://127.0.0.1:4437")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Storage Modes
|
|
32
|
+
|
|
33
|
+
### In-Memory (Default)
|
|
34
|
+
|
|
35
|
+
Fast, ephemeral storage for development and testing:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { DurableStreamTestServer, StreamStore } from "@durable-streams/server"
|
|
39
|
+
|
|
40
|
+
const store = new StreamStore()
|
|
41
|
+
const server = new DurableStreamTestServer({
|
|
42
|
+
port: 4437,
|
|
43
|
+
store,
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### File-Backed
|
|
48
|
+
|
|
49
|
+
Persistent storage with streams stored as log files and LMDB for metadata:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import {
|
|
53
|
+
DurableStreamTestServer,
|
|
54
|
+
FileBackedStreamStore,
|
|
55
|
+
} from "@durable-streams/server"
|
|
56
|
+
|
|
57
|
+
const store = new FileBackedStreamStore({
|
|
58
|
+
path: "./data/streams",
|
|
59
|
+
})
|
|
60
|
+
const server = new DurableStreamTestServer({
|
|
61
|
+
port: 4437,
|
|
62
|
+
store,
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Registry Hooks
|
|
67
|
+
|
|
68
|
+
Track stream lifecycle events (creation, deletion):
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import {
|
|
72
|
+
DurableStreamTestServer,
|
|
73
|
+
createRegistryHooks,
|
|
74
|
+
} from "@durable-streams/server"
|
|
75
|
+
|
|
76
|
+
const server = new DurableStreamTestServer({
|
|
77
|
+
port: 4437,
|
|
78
|
+
hooks: createRegistryHooks({
|
|
79
|
+
registryPath: "__registry__",
|
|
80
|
+
}),
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The registry maintains a system stream that tracks all stream creates and deletes, useful for building admin UIs or monitoring.
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### DurableStreamTestServer
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
interface TestServerOptions {
|
|
92
|
+
port?: number
|
|
93
|
+
host?: string
|
|
94
|
+
store?: StreamStore | FileBackedStreamStore
|
|
95
|
+
hooks?: StreamLifecycleHook[]
|
|
96
|
+
cors?: boolean
|
|
97
|
+
cursorOptions?: CursorOptions
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
class DurableStreamTestServer {
|
|
101
|
+
constructor(options?: TestServerOptions)
|
|
102
|
+
start(): Promise<void>
|
|
103
|
+
stop(): Promise<void>
|
|
104
|
+
readonly port: number
|
|
105
|
+
readonly baseUrl: string
|
|
106
|
+
}
|
|
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
|
+
|
|
127
|
+
## Exports
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
export { DurableStreamTestServer } from "./server"
|
|
131
|
+
export { StreamStore } from "./store"
|
|
132
|
+
export { FileBackedStreamStore } from "./file-store"
|
|
133
|
+
export { encodeStreamPath, decodeStreamPath } from "./path-encoding"
|
|
134
|
+
export { createRegistryHooks } from "./registry-hook"
|
|
135
|
+
export {
|
|
136
|
+
calculateCursor,
|
|
137
|
+
handleCursorCollision,
|
|
138
|
+
generateResponseCursor,
|
|
139
|
+
DEFAULT_CURSOR_EPOCH,
|
|
140
|
+
DEFAULT_CURSOR_INTERVAL_SECONDS,
|
|
141
|
+
type CursorOptions,
|
|
142
|
+
} from "./cursor"
|
|
143
|
+
export type {
|
|
144
|
+
Stream,
|
|
145
|
+
StreamMessage,
|
|
146
|
+
TestServerOptions,
|
|
147
|
+
PendingLongPoll,
|
|
148
|
+
StreamLifecycleEvent,
|
|
149
|
+
StreamLifecycleHook,
|
|
150
|
+
} from "./types"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Testing Your Implementation
|
|
154
|
+
|
|
155
|
+
Use the conformance test suite to validate protocol compliance:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { runConformanceTests } from "@durable-streams/server-conformance-tests"
|
|
159
|
+
|
|
160
|
+
runConformanceTests({
|
|
161
|
+
baseUrl: "http://localhost:4437",
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
Apache-2.0
|