plasmite 0.2.0 → 0.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/README.md CHANGED
@@ -21,67 +21,71 @@ toolchain or compile step needed.
21
21
  ### Local pools (native, in-process)
22
22
 
23
23
  ```js
24
- const { Client, Durability } = require("plasmite");
24
+ const { Client, Durability, ErrorKind, PlasmiteNativeError } = require("plasmite");
25
25
 
26
- // Open a client pointed at a directory (created if it doesn't exist)
27
26
  const client = new Client("./data");
28
-
29
- // Create a 64 MB pool called "events"
30
- const pool = client.createPool("events", 64 * 1024 * 1024);
31
-
32
- // Append a JSON message with tags
33
- pool.appendJson(
34
- Buffer.from(JSON.stringify({ kind: "signup", user: "alice" })),
35
- ["user-event"],
36
- Durability.Flush,
37
- );
38
-
39
- // Read it back by sequence number
40
- const msg = pool.getJson(1n);
41
- console.log(JSON.parse(msg.toString()));
42
- // => { kind: "signup", user: "alice" }
43
-
44
- // Stream messages as they arrive
45
- const stream = pool.openStream();
46
- let frame;
47
- while ((frame = stream.nextJson()) !== null) {
48
- console.log(JSON.parse(frame.toString()));
27
+ let pool;
28
+ try {
29
+ pool = client.pool("events", 64 * 1024 * 1024);
30
+
31
+ const msg = pool.append({ kind: "signup", user: "alice" }, ["user-event"], Durability.Flush);
32
+ console.log(msg.seq, msg.tags, msg.data);
33
+ // => 1n [ 'user-event' ] { kind: 'signup', user: 'alice' }
34
+
35
+ const fetched = pool.get(msg.seq);
36
+ console.log(fetched.data.user);
37
+ // => "alice"
38
+
39
+ try {
40
+ client.openPool("missing");
41
+ } catch (err) {
42
+ if (err instanceof PlasmiteNativeError && err.kind === ErrorKind.NotFound) {
43
+ console.log("pool not found");
44
+ } else {
45
+ throw err;
46
+ }
47
+ }
48
+ } finally {
49
+ if (pool) pool.close();
50
+ client.close();
49
51
  }
50
- stream.close();
51
-
52
- pool.close();
53
- client.close();
54
52
  ```
55
53
 
54
+ ## Troubleshooting
55
+
56
+ - **Missing pool directory**: pool creation creates parent directories automatically. If you call `openPool(...)` on a missing pool, catch `ErrorKind.NotFound` or use `client.pool(...)` to create-or-open.
57
+ - **Permission denied**: choose a writable pool directory (`new Client("/path/to/pools")`) and verify directory permissions/ownership. Errors include `err.path` when available.
58
+
56
59
  ### Remote pools (HTTP/JSON)
57
60
 
58
- Connect to a plasmite server (`npx plasmite serve` or `pls serve`) to read
61
+ Connect to a Plasmite server (`npx plasmite serve` or `pls serve`) to read
59
62
  and write pools over the network.
60
63
 
61
64
  ```js
62
65
  const { RemoteClient } = require("plasmite");
63
66
 
64
- const client = new RemoteClient("http://127.0.0.1:9700");
65
- // With auth: new RemoteClient("http://...", { token: "secret" })
67
+ (async () => {
68
+ const client = new RemoteClient("http://127.0.0.1:9700");
69
+ // With auth: new RemoteClient("http://...", { token: "secret" })
66
70
 
67
- const pool = await client.openPool("events");
71
+ const pool = await client.openPool("events");
68
72
 
69
- // Append — accepts plain objects, serialized as JSON for you
70
- const message = await pool.append(
71
- { kind: "deploy", sha: "abc123" },
72
- ["ops"],
73
- );
74
- console.log(message.seq); // => 1
73
+ // Append — accepts plain objects, serialized as JSON for you
74
+ const message = await pool.append(
75
+ { kind: "deploy", sha: "abc123" },
76
+ ["ops"],
77
+ );
78
+ console.log(message.seq); // => 1n
75
79
 
76
- // Read by sequence number
77
- const got = await pool.get(1);
78
- console.log(got.data); // => { kind: "deploy", sha: "abc123" }
80
+ // Read by sequence number
81
+ const got = await pool.get(1);
82
+ console.log(got.data); // => { kind: "deploy", sha: "abc123" }
79
83
 
80
- // Tail — live-stream new messages (JSONL under the hood)
81
- const tail = await pool.tail({ sinceSeq: 0, tags: ["ops"] });
82
- const next = await tail.next(); // resolves on next matching message
83
- console.log(next);
84
- tail.cancel();
84
+ // Tail — live-stream new messages (JSONL under the hood)
85
+ for await (const msg of pool.tail({ sinceSeq: 0, tags: ["ops"], maxMessages: 1 })) {
86
+ console.log(msg.seq, msg.tags, msg.data);
87
+ }
88
+ })();
85
89
  ```
86
90
 
87
91
  ## API
@@ -90,19 +94,34 @@ tail.cancel();
90
94
 
91
95
  | Class | Method | Description |
92
96
  |---|---|---|
93
- | `Client(dir)` | | Open a pool directory |
97
+ | `Client(dir?)` | | Open a pool directory (`~/.plasmite/pools` by default) |
94
98
  | | `.createPool(name, sizeBytes)` | Create a new pool (returns `Pool`) |
95
99
  | | `.openPool(name)` | Open an existing pool (returns `Pool`) |
100
+ | | `.pool(name, sizeBytes?)` | Open if present, else create |
96
101
  | | `.close()` | Release resources |
97
- | `Pool` | `.appendJson(buf, tags, durability)` | Append a JSON message; returns the stored envelope as `Buffer` |
98
- | | `.appendLite3(buf, durability)` | Append raw bytes (lite3 framing); returns sequence `bigint` |
102
+ | | `[Symbol.dispose]()` | Alias for `.close()` (used by explicit resource-management syntax when enabled) |
103
+ | `Module` | `.parseMessage(value)` | Normalize a raw envelope or `Message` into a typed `Message` |
104
+ | | `.replay(pool, opts?)` | Backward-compatible replay wrapper (delegates to `pool.replay`) |
105
+ | `Pool` | `.appendJson(payload, tags, durability)` | Append JSON payload (Buffer or JSON-serializable value); returns message envelope as `Buffer` |
106
+ | | `.append(data, tags?, durability?)` | Append any JSON-serializable value; returns typed `Message` |
107
+ | | `.appendLite3(buf, durability?)` | Append raw bytes (lite3 framing); returns sequence `bigint` |
108
+ | | `.get(seq)` | Get message by sequence number; returns typed `Message` |
99
109
  | | `.getJson(seq)` | Get message by sequence number; returns `Buffer` |
100
110
  | | `.getLite3(seq)` | Get lite3 frame by sequence number |
111
+ | | `.tail(opts?)` | Async generator of typed `Message` values with optional tag filter |
112
+ | | `.replay(opts?)` | Async generator of typed `Message` values with speed/timing controls |
101
113
  | | `.openStream(sinceSeq?, max?, timeoutMs?)` | Open a message stream |
102
114
  | | `.openLite3Stream(sinceSeq?, max?, timeoutMs?)` | Open a lite3 frame stream |
103
115
  | | `.close()` | Close the pool |
116
+ | | `[Symbol.dispose]()` | Alias for `.close()` (used by explicit resource-management syntax when enabled) |
104
117
  | `Stream` | `.nextJson()` | Next message as `Buffer`, or `null` at end |
118
+ | | `[Symbol.iterator]()` | Iterate synchronously via `for...of` |
105
119
  | | `.close()` | Close the stream |
120
+ | | `[Symbol.dispose]()` | Alias for `.close()` |
121
+ | `Lite3Stream` | `.next()` | Next lite3 frame, or `null` at end |
122
+ | | `[Symbol.iterator]()` | Iterate synchronously via `for...of` |
123
+ | | `.close()` | Close the stream |
124
+ | | `[Symbol.dispose]()` | Alias for `.close()` |
106
125
 
107
126
  **Durability** controls fsync behavior:
108
127
  - `Durability.Fast` — buffered writes (higher throughput)
@@ -123,19 +142,17 @@ Sequence numbers accept `number` or `bigint`.
123
142
  | | `.deletePool(name)` | Delete a pool |
124
143
  | `RemotePool` | `.append(data, tags?, durability?)` | Append a message (data is any JSON-serializable value) |
125
144
  | | `.get(seq)` | Get a message by sequence number |
126
- | | `.tail(opts?)` | Live-tail messages (returns `RemoteTail`) |
127
- | `RemoteTail` | `.next()` | Await next message (resolves to message or `null`) |
128
- | | `.cancel()` | Stop the tail stream |
145
+ | | `.tail(opts?)` | Live-tail typed messages (`AsyncGenerator<Message>`) |
129
146
 
130
147
  ### Tail options
131
148
 
132
149
  ```js
133
- await pool.tail({
150
+ const options = {
134
151
  sinceSeq: 0, // start after this sequence number
135
152
  maxMessages: 100, // stop after N messages
136
153
  timeoutMs: 5000, // stop after N ms of inactivity
137
154
  tags: ["signup"], // filter by exact tag match (AND across tags)
138
- });
155
+ };
139
156
  ```
140
157
 
141
158
  ### Error handling
@@ -144,10 +161,10 @@ Local operations throw `PlasmiteNativeError` with structured fields:
144
161
 
145
162
  ```js
146
163
  try {
147
- pool.getJson(999n);
164
+ pool.get(999n);
148
165
  } catch (err) {
149
166
  if (err instanceof PlasmiteNativeError) {
150
- console.log(err.kind); // "NotFound"
167
+ console.log(err.kind === ErrorKind.NotFound); // true
151
168
  console.log(err.seq); // 999
152
169
  }
153
170
  }
@@ -162,7 +179,7 @@ The package includes the `plasmite` CLI:
162
179
 
163
180
  ```bash
164
181
  npx plasmite --version
165
- npx plasmite serve ./data --port 9700
182
+ npx plasmite --dir ./data serve --bind 127.0.0.1:9700
166
183
  ```
167
184
 
168
185
  ## TypeScript
@@ -174,11 +191,29 @@ needed.
174
191
  import { Client, Durability, Pool, RemoteClient } from "plasmite";
175
192
  ```
176
193
 
194
+ For repo development, `npm test` runs:
195
+ - native rebuild
196
+ - `npm run check:type-surface` (runtime export ↔ `types.d.ts` drift check)
197
+ - `node --test test/*.test.js` (includes conformance tests)
198
+
199
+ Run the conformance runner directly:
200
+
201
+ ```bash
202
+ cd bindings/node
203
+ npm run build
204
+ PLASMITE_LIB_DIR="$(pwd)/../../target/debug" \
205
+ PLASMITE_BIN="$(pwd)/../../target/debug/plasmite" \
206
+ node cmd/plasmite-conformance.js ../../conformance/sample-v0.json
207
+ ```
208
+
177
209
  ## Platform support
178
210
 
179
- Pre-built binaries are included for Linux x86_64. macOS and Windows users
180
- should install via Homebrew (`brew install sandover/tap/plasmite`) or build
181
- from source.
211
+ Pre-built binaries are included for:
212
+ - Linux: `x64`, `arm64`
213
+ - macOS: `x64`, `arm64`
214
+ - Windows: `x64`
215
+
216
+ If your platform/architecture is not listed, install the SDK (`libplasmite`) and build from source.
182
217
 
183
218
  ## License
184
219