@cero-base/tools 1.19.0 → 2.1.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Passive devtools for [cero](https://www.npmjs.com/package/@cero-base/cero) — observe a running instance's **data**, its **event log**, and its **p2p/replication stats** from another process, without ever touching the swarm it measures.
4
4
 
5
- A `cero.use(devtools())` extension taps the instance over a **local out-of-band pipe** (never the app's hyperswarm), so connection counts, core lengths, and replication numbers stay exactly as they'd be with no devtools attached. Read-only by construction; identity secrets are structurally unreachable.
5
+ A `devtools()` extension taps the instance over a **local out-of-band pipe** (never the app's hyperswarm), so connection counts, core lengths, and replication numbers stay exactly as they'd be with no devtools attached. Read-only by construction; identity secrets are structurally unreachable.
6
6
 
7
7
  ## Install
8
8
 
@@ -16,7 +16,9 @@ npm install @cero-base/tools
16
16
  import { cero } from '@cero-base/cero'
17
17
  import { devtools, loopback } from '@cero-base/tools'
18
18
 
19
- cero.use(devtools({ transport: loopback({ port: 9111 }) }))
19
+ const me = await cero('./data', spec, {
20
+ extensions: [...spec.extensions, devtools({ transport: loopback({ port: 9111 }) })]
21
+ })
20
22
  // ...then create your instance as usual; the tap follows it and every child handle.
21
23
  ```
22
24
 
@@ -46,7 +48,6 @@ const session = await connect(dial({ port: 9111 }))
46
48
 
47
49
  await session.handles() // [{ id, type }, ...] — root + open children
48
50
  await session.get('messages') // { data, total, size } — reuses cero's read operators
49
- await session.count('members') // number
50
51
  session.watch('messages') // Readable of live snapshots
51
52
  session.events() // Readable of { op, name, row, writerKey, seq } — local AND remote
52
53
  session.stats() // Readable of { network, bee, cores }
@@ -82,7 +83,7 @@ Identity credentials (the seed and keypairs) need no redaction: they're `local`
82
83
 
83
84
  ## Status
84
85
 
85
- MVP: local-pipe transport, `get`/`watch`/`count` + events + sampled stats, redaction, a CLI. Deferred to later phases: a whitelisted swarm transport, a read-only replication / time-travel plane, and an MCP/UI consumer.
86
+ MVP: local-pipe transport, `get`/`watch` + events + sampled stats, redaction, a CLI. Deferred to later phases: a whitelisted swarm transport, a read-only replication / time-travel plane, and an MCP/UI consumer.
86
87
 
87
88
  ## License
88
89
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@cero-base/tools",
3
- "version": "1.19.0",
3
+ "version": "2.1.0",
4
4
  "description": "Passive devtools for cero — observe data, events, and p2p/replication stats over a local out-of-band pipe.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "engines": {
8
- "node": ">=20"
8
+ "node": ">=22"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -48,8 +48,7 @@
48
48
  "types",
49
49
  "bin",
50
50
  "README.md",
51
- "LICENSE",
52
- "!**/CLAUDE.md"
51
+ "LICENSE"
53
52
  ],
54
53
  "publishConfig": {
55
54
  "access": "public"
@@ -72,11 +71,11 @@
72
71
  "build:types": "rm -rf types && tsc -p .",
73
72
  "prepublishOnly": "npm run build:types",
74
73
  "test": "npm run test:bare",
75
- "test:bare": "find test -name '*.test.js' | sort | xargs -P1 -n1 brittle-bare test/bare.js",
74
+ "test:bare": "find test -name '*.test.js' | sort | xargs -P1 -n1 brittle-bare",
76
75
  "test:node": "find test -name '*.test.js' | sort | xargs -P1 -n1 brittle-node"
77
76
  },
78
77
  "dependencies": {
79
- "@cero-base/cero": "^1.19.0",
78
+ "@cero-base/cero": "^2.1.0",
80
79
  "b4a": "^1.8.1",
81
80
  "bare-crypto": "^1.15.3",
82
81
  "bare-net": "^2.3.3",
package/src/connect.js CHANGED
@@ -11,13 +11,10 @@ import { Framed } from './protocol.js'
11
11
  */
12
12
 
13
13
  /**
14
- * Consumer SDK for a tap server reached over a local Duplex `stream`. Returns
15
- * a session exposing read methods (`handles`/`get`/`count`) and stream methods
16
- * (`watch`/`events`/`stats`). Stream methods return a streamx Readable that
17
- * cancels its server-side source when destroyed.
14
+ * Consumer SDK for a tap server reached over a local Duplex `stream`.
18
15
  *
19
16
  * @param {object} stream A streamx Duplex connected to a tap server.
20
- * @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>, count(ref: string, query?: Query, handleId?: string): Promise<number>, watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
17
+ * @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>, watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
21
18
  */
22
19
  export async function connect(stream, { token } = {}) {
23
20
  return new Session(stream, { token })
@@ -35,67 +32,6 @@ export class Session {
35
32
  stream.on('close', () => this._onclose())
36
33
  }
37
34
 
38
- // The transport dropped — fail in-flight requests and end live streams instead
39
- // of leaving them hung and the maps leaking.
40
- _onclose() {
41
- for (const { reject } of this.pending.values()) {
42
- reject(new TapError('connection closed', 'CLOSED'))
43
- }
44
- this.pending.clear()
45
- for (const r of this.streams.values()) r.push(null)
46
- this.streams.clear()
47
- }
48
-
49
- _onmessage(msg) {
50
- if ('frame' in msg || msg.end) {
51
- const r = this.streams.get(msg.id)
52
- if (!r) return
53
- if (msg.end) {
54
- this.streams.delete(msg.id)
55
- r.push(null)
56
- } else {
57
- r.push(msg.frame)
58
- }
59
- return
60
- }
61
- const p = this.pending.get(msg.id)
62
- if (!p) return
63
- this.pending.delete(msg.id)
64
- if (msg.ok === false) p.reject(new TapError(msg.error, msg.code))
65
- else p.resolve(msg.data)
66
- }
67
-
68
- _newId() {
69
- return ++this.seq
70
- }
71
-
72
- _send(frame) {
73
- this.wire.send(this.token ? { token: this.token, ...frame } : frame)
74
- }
75
-
76
- _request(method, fields) {
77
- return new Promise((resolve, reject) => {
78
- const id = this._newId()
79
- this.pending.set(id, { resolve, reject })
80
- this._send({ id, method, ...fields })
81
- })
82
- }
83
-
84
- _stream(method, fields) {
85
- const id = this._newId()
86
- const r = new Readable({
87
- destroy: (cb) => {
88
- if (this.streams.delete(id)) {
89
- this._send({ id: this._newId(), method: 'cancel', cancelId: id })
90
- }
91
- cb(null)
92
- }
93
- })
94
- this.streams.set(id, r)
95
- this._send({ id, method, ...fields })
96
- return r
97
- }
98
-
99
35
  /**
100
36
  * Lists the handles exposed by the server.
101
37
  *
@@ -117,18 +53,6 @@ export class Session {
117
53
  return this._request('get', { ref, query, handleId })
118
54
  }
119
55
 
120
- /**
121
- * Counts entries matching `ref`.
122
- *
123
- * @param {string} ref Reference to count.
124
- * @param {Query} [query] Optional query filter.
125
- * @param {string} [handleId] Optional handle to scope the count.
126
- * @returns {Promise<number>} Resolves to the count.
127
- */
128
- count(ref, query, handleId) {
129
- return this._request('count', { ref, query, handleId })
130
- }
131
-
132
56
  /**
133
57
  * Watches `ref` for changes, emitting frames as they arrive.
134
58
  *
@@ -167,6 +91,66 @@ export class Session {
167
91
  close() {
168
92
  this.stream.end()
169
93
  }
94
+
95
+ // fail in-flight requests and end live streams
96
+ _onclose() {
97
+ for (const { reject } of this.pending.values()) {
98
+ reject(new TapError('connection closed', 'CLOSED'))
99
+ }
100
+ this.pending.clear()
101
+ for (const r of this.streams.values()) r.push(null)
102
+ this.streams.clear()
103
+ }
104
+
105
+ _onmessage(msg) {
106
+ if ('frame' in msg || msg.end) {
107
+ const r = this.streams.get(msg.id)
108
+ if (!r) return
109
+ if (msg.end) {
110
+ this.streams.delete(msg.id)
111
+ r.push(null)
112
+ } else {
113
+ r.push(msg.frame)
114
+ }
115
+ return
116
+ }
117
+ const p = this.pending.get(msg.id)
118
+ if (!p) return
119
+ this.pending.delete(msg.id)
120
+ if (msg.ok === false) p.reject(new TapError(msg.error, msg.code))
121
+ else p.resolve(msg.data)
122
+ }
123
+
124
+ _newId() {
125
+ return ++this.seq
126
+ }
127
+
128
+ _send(frame) {
129
+ this.wire.send(this.token ? { token: this.token, ...frame } : frame)
130
+ }
131
+
132
+ _request(method, fields) {
133
+ return new Promise((resolve, reject) => {
134
+ const id = this._newId()
135
+ this.pending.set(id, { resolve, reject })
136
+ this._send({ id, method, ...fields })
137
+ })
138
+ }
139
+
140
+ _stream(method, fields) {
141
+ const id = this._newId()
142
+ const r = new Readable({
143
+ destroy: (cb) => {
144
+ if (this.streams.delete(id)) {
145
+ this._send({ id: this._newId(), method: 'cancel', cancelId: id })
146
+ }
147
+ cb(null)
148
+ }
149
+ })
150
+ this.streams.set(id, r)
151
+ this._send({ id, method, ...fields })
152
+ return r
153
+ }
170
154
  }
171
155
 
172
156
  class TapError extends Error {
package/src/protocol.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import b4a from 'b4a'
2
2
 
3
3
  const BYTES = '$b'
4
- // Cap a single frame and the outbound backlog so a bogus length prefix or a
5
- // stuck consumer can't grow host memory without bound (devtools is never essential).
4
+ // cap a frame and the backlog so a bad length prefix cannot grow memory without bound
6
5
  const MAX_FRAME = 16 * 1024 * 1024
7
6
 
8
7
  function toWire(v) {
@@ -39,6 +38,23 @@ export class Framed {
39
38
  stream.on('data', (chunk) => this._ondata(chunk))
40
39
  }
41
40
 
41
+ /**
42
+ * Encode `obj` to wire form and write it as one length-prefixed frame.
43
+ * @param {object} obj - message to send
44
+ * @returns {void}
45
+ */
46
+ send(obj) {
47
+ // drop a consumer that has stopped reading rather than buffer unbounded
48
+ if ((this.stream.writableLength ?? 0) > MAX_FRAME) {
49
+ this.stream.destroy()
50
+ return
51
+ }
52
+ const body = b4a.from(JSON.stringify(toWire(obj)))
53
+ const head = b4a.alloc(4)
54
+ new DataView(head.buffer, head.byteOffset, 4).setUint32(0, body.length, true)
55
+ this.stream.write(b4a.concat([head, body]))
56
+ }
57
+
42
58
  _ondata(chunk) {
43
59
  this.buf = b4a.concat([this.buf, chunk])
44
60
  while (this.buf.length >= 4) {
@@ -59,21 +75,4 @@ export class Framed {
59
75
  this.onMessage(msg)
60
76
  }
61
77
  }
62
-
63
- /**
64
- * Encode `obj` to wire form and write it as one length-prefixed frame.
65
- * @param {object} obj - message to send
66
- * @returns {void}
67
- */
68
- send(obj) {
69
- // drop a consumer that has stopped reading rather than buffer unbounded
70
- if ((this.stream.writableLength ?? 0) > MAX_FRAME) {
71
- this.stream.destroy()
72
- return
73
- }
74
- const body = b4a.from(JSON.stringify(toWire(obj)))
75
- const head = b4a.alloc(4)
76
- new DataView(head.buffer, head.byteOffset, 4).setUint32(0, body.length, true)
77
- this.stream.write(b4a.concat([head, body]))
78
- }
79
78
  }
package/src/redact.js CHANGED
@@ -1,15 +1,12 @@
1
1
  import b4a from 'b4a'
2
2
 
3
- // Obvious secret-ish field names, masked by default once redaction is enabled.
4
3
  const DEFAULT_DENY =
5
4
  /^(seed|secret|secretkey|password|passphrase|token|private|privatekey|encryptionkey|mnemonic)$/i
6
5
 
7
6
  /**
8
- * Build a row masker for devtools. A field is masked when its dotted path is in
9
- * `fields`, its name matches `deny` (default denylist above), or `match(key,
10
- * value, path)` returns true. Masked values become a typed placeholder —
11
- * `‹redacted:bytes(32)›` / `‹redacted:string›` — so the shape stays visible but
12
- * the content is hidden. Everything else passes through untouched.
7
+ * Build a row masker for devtools. A field is masked when its dotted path is in `fields`,
8
+ * its name matches `deny` (default denylist above), or `match(key, value, path)` returns
9
+ * true.
13
10
  *
14
11
  * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: any, path: string) => boolean }} [config]
15
12
  * @returns {(ref: string, row: any) => any}
package/src/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { get, count, watch } from '@cero-base/cero'
1
+ import { get, watch } from '@cero-base/cero'
2
2
 
3
3
  import { Framed } from './protocol.js'
4
4
 
@@ -9,10 +9,7 @@ import { Framed } from './protocol.js'
9
9
  */
10
10
 
11
11
  /**
12
- * Read-only inspection server over a local Duplex `stream`. Serves the live
13
- * handle tree rooted at `me`, exposing only MAIN refs declared in each
14
- * handle's `spec.meta.refs` — local secret refs (master/keypair/
15
- * handle-keypairs) are never reachable, since they live in `meta.local.refs`.
12
+ * Read-only inspection server over a local Duplex `stream`.
16
13
  *
17
14
  * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
18
15
  * @param {object} me The live root cero handle.
@@ -34,7 +31,7 @@ export class TapServer {
34
31
  this.wire = new Framed(stream, (req) => this.onRequest(req))
35
32
  this._cleanup = () => this._teardown()
36
33
  stream.on('close', this._cleanup)
37
- // an inbound socket reset (client kill / ECONNRESET) must tear down, not crash the host
34
+ // a socket reset must not crash the host
38
35
  stream.on('error', this._cleanup)
39
36
  }
40
37
 
@@ -46,8 +43,7 @@ export class TapServer {
46
43
  async onRequest(req) {
47
44
  // a malformed frame (JSON null / scalar) has no method — ignore it
48
45
  if (!req || typeof req !== 'object') return
49
- // token gate: the first frame must carry the tap token — one shot, a
50
- // mismatch drops the connection (no probing across attempts)
46
+ // the first frame must carry the token, one shot
51
47
  if (!this._authed) {
52
48
  if (req.token !== this.opts.token) return this.stream.destroy()
53
49
  this._authed = true
@@ -97,16 +93,6 @@ export class TapServer {
97
93
  this._send({ id: req.id, ok: true, data: { ...r, data } })
98
94
  }
99
95
 
100
- /**
101
- * Count rows for a ref and reply with the total.
102
- * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
103
- * @returns {Promise<void>}
104
- */
105
- async count(req) {
106
- const ref = this._resolveRef(req)
107
- this._send({ id: req.id, ok: true, data: (await count(ref, req.query)).data })
108
- }
109
-
110
96
  /**
111
97
  * Stream redacted live updates for a ref until cancelled or the stream ends.
112
98
  * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
@@ -155,6 +141,15 @@ export class TapServer {
155
141
  this._drop(req.cancelId)
156
142
  }
157
143
 
144
+ /**
145
+ * Tear down all tracked streams and destroy the underlying stream.
146
+ * @returns {void}
147
+ */
148
+ close() {
149
+ this._teardown()
150
+ this.stream.destroy()
151
+ }
152
+
158
153
  _resolveRef(req) {
159
154
  const me = this.me
160
155
  const handle =
@@ -198,18 +193,9 @@ export class TapServer {
198
193
  for (const off of this.tracked.values()) off()
199
194
  this.tracked.clear()
200
195
  }
201
-
202
- /**
203
- * Tear down all tracked streams and destroy the underlying stream.
204
- * @returns {void}
205
- */
206
- close() {
207
- this._teardown()
208
- this.stream.destroy()
209
- }
210
196
  }
211
197
 
212
- const METHODS = new Set(['handles', 'get', 'count', 'watch', 'events', 'stats', 'cancel'])
198
+ const METHODS = new Set(['handles', 'get', 'watch', 'events', 'stats', 'cancel'])
213
199
 
214
200
  class CodeError extends Error {
215
201
  constructor(code, message) {
package/src/stats.js CHANGED
@@ -1,8 +1,5 @@
1
1
  /**
2
- * Read-only snapshot of a handle's existing p2p/storage counters. Pure: no
3
- * listeners, no mutation, never reads a secret. `dht.stats` and the corestore
4
- * `cores` map are undocumented internals, so they are guarded — a fresh handle
5
- * (pre-ready) yields zeros rather than throwing.
2
+ * Read-only snapshot of a handle's existing p2p/storage counters.
6
3
  *
7
4
  * @param {any} handle A cero root or child handle.
8
5
  * @param {number} [at] Sample timestamp, stamped by the caller.
package/src/tap.js CHANGED
@@ -6,10 +6,7 @@ import { redact } from './redact.js'
6
6
  import { loopback } from './transport.js'
7
7
 
8
8
  /**
9
- * An applied-op event fed into the ring buffer. `op` is the dispatch verb
10
- * prefix, `name` the ref name, `row` the decoded value, `writerKey` the source
11
- * writer's key and `seq` a monotonic apply counter. After redaction `row` is
12
- * replaced with its masked copy; the rest is spread through unchanged.
9
+ * An applied-op event fed into the ring buffer.
13
10
  *
14
11
  * @typedef {{ op: string, name: string, row: Record<string, unknown>, writerKey: Buffer, seq: number }} OpEvent
15
12
  */
@@ -21,11 +18,9 @@ import { loopback } from './transport.js'
21
18
  */
22
19
 
23
20
  /**
24
- * `cero.use(devtools())` tap extension. Bound to the root handle's lifecycle,
25
- * it feeds every applied op into a bounded ring buffer, samples `stats(me)` on
26
- * an interval, and serves a read-only inspection surface to out-of-band
27
- * consumers. By default it serves a loopback TCP server on `port` (9111); pass
28
- * a custom `transport` to serve it some other way. Nothing touches the app swarm.
21
+ * The `devtools()` tap extension. Bound to the root handle's lifecycle, it feeds
22
+ * every applied op into a bounded ring buffer, samples `stats(me)` on an interval, and
23
+ * serves a read-only inspection.
29
24
  *
30
25
  * @param {{ port?: number, host?: string, token?: string | false, bufferSize?: number, sampleInterval?: number, redact?: ((ref: string, row: Record<string, unknown>) => Record<string, unknown>) | { fields?: string[], match?: (key: string, value: unknown, path: string) => boolean, deny?: RegExp | false }, transport?: { accept(handler: (stream: object) => void): void } }} [opts]
31
26
  * @returns {{ setup(me: object): () => void }}
@@ -36,8 +31,7 @@ export function devtools(opts = {}) {
36
31
  const events = new Ring(opts.bufferSize ?? 1000)
37
32
  const sampler = new Sampler(me, opts.sampleInterval ?? 1000)
38
33
  const redactor = makeRedactor(opts.redact)
39
- // any local process can dial the loopback port — a per-run token gates the
40
- // tap so co-tenant processes can't read app data. `token: false` opts out.
34
+ // any local process can dial the port, so a per-run token gates the tap
41
35
  const token =
42
36
  opts.token === false ? null : opts.token || crypto.randomBytes(16).toString('hex')
43
37
  const transport =
@@ -46,9 +40,9 @@ export function devtools(opts = {}) {
46
40
  const servers = new Set()
47
41
 
48
42
  const follow = (handle) => {
49
- const off = handle.store.onApply((e) =>
50
- events.push(redactor ? { ...e, row: redactor(e.name, e.row) } : e)
51
- )
43
+ const push = (e) => events.push(redactor ? { ...e, row: redactor(e.name, e.row) } : e)
44
+ handle.store.on('apply', push)
45
+ const off = () => handle.store.off('apply', push)
52
46
  offs.push(off)
53
47
  if (handle !== me) handle.once('close', off)
54
48
  }
package/src/transport.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import net from 'net'
2
2
 
3
3
  /**
4
- * Loopback TCP transport implementing the tap `{ accept(handler) }` contract
5
- * plus lifecycle. Each inbound connection's socket is a streamx-compatible
6
- * Duplex, ready to pass straight to `serve()`.
4
+ * Loopback TCP transport implementing the tap `{ accept(handler) }` contract plus
5
+ * lifecycle.
7
6
  *
8
7
  * @param {{ port?: number, host?: string, token?: string | null }} [opts]
9
8
  * @returns {{ accept(handler: (socket: any) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}
@@ -21,12 +20,9 @@ export function loopback(opts = {}) {
21
20
  })
22
21
  let port = base
23
22
  let tries = 0
24
- // ready() resolves when listening, rejects on a terminal bind failure
25
- // (so a caller awaiting it can't hang forever).
26
23
  ready = new Promise((resolve, reject) => {
27
24
  server.on('listening', () => resolve({ port: server.address().port }))
28
- // A taken port (e.g. a second app instance) bumps to the next one rather
29
- // than crashing the app — devtools is never essential.
25
+ // a taken port bumps to the next one
30
26
  server.on('error', (err) => {
31
27
  if (err.code === 'EADDRINUSE' && base && tries++ < 10) return server.listen(++port, host)
32
28
  console.error(`[devtools] tap could not start: ${err.message}`)
@@ -61,7 +57,6 @@ export function dial(opts = {}) {
61
57
  return net.connect(opts.port, opts.host ?? '127.0.0.1')
62
58
  }
63
59
 
64
- // VITE-style startup banner printed when the tap starts listening.
65
60
  function banner(host, port, token) {
66
61
  const e = '\x1b['
67
62
  const r = `${e}0m`
@@ -9,18 +9,14 @@ export type Handle = Record<string, unknown>;
9
9
  * @typedef {Record<string, unknown>} Handle A handle descriptor returned by the server.
10
10
  */
11
11
  /**
12
- * Consumer SDK for a tap server reached over a local Duplex `stream`. Returns
13
- * a session exposing read methods (`handles`/`get`/`count`) and stream methods
14
- * (`watch`/`events`/`stats`). Stream methods return a streamx Readable that
15
- * cancels its server-side source when destroyed.
12
+ * Consumer SDK for a tap server reached over a local Duplex `stream`.
16
13
  *
17
14
  * @param {object} stream A streamx Duplex connected to a tap server.
18
- * @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>, count(ref: string, query?: Query, handleId?: string): Promise<number>, watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
15
+ * @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>, watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
19
16
  */
20
17
  export declare function connect(stream: object, { token }?: {}): Promise<{
21
18
  handles(): Promise<Handle[]>;
22
19
  get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
23
- count(ref: string, query?: Query, handleId?: string): Promise<number>;
24
20
  watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable;
25
21
  events(): import('streamx').Readable;
26
22
  stats(): import('streamx').Readable;
@@ -34,12 +30,6 @@ export declare class Session {
34
30
  seq: number;
35
31
  wire: Framed;
36
32
  constructor(stream: any, { token }?: {});
37
- _onclose(): void;
38
- _onmessage(msg: any): void;
39
- _newId(): number;
40
- _send(frame: any): void;
41
- _request(method: any, fields: any): Promise<any>;
42
- _stream(method: any, fields: any): Readable<import("streamx").ReadableEvents>;
43
33
  /**
44
34
  * Lists the handles exposed by the server.
45
35
  *
@@ -55,15 +45,6 @@ export declare class Session {
55
45
  * @returns {Promise<unknown>} Resolves to the value.
56
46
  */
57
47
  get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
58
- /**
59
- * Counts entries matching `ref`.
60
- *
61
- * @param {string} ref Reference to count.
62
- * @param {Query} [query] Optional query filter.
63
- * @param {string} [handleId] Optional handle to scope the count.
64
- * @returns {Promise<number>} Resolves to the count.
65
- */
66
- count(ref: string, query?: Query, handleId?: string): Promise<number>;
67
48
  /**
68
49
  * Watches `ref` for changes, emitting frames as they arrive.
69
50
  *
@@ -91,4 +72,10 @@ export declare class Session {
91
72
  * @returns {void}
92
73
  */
93
74
  close(): void;
75
+ _onclose(): void;
76
+ _onmessage(msg: any): void;
77
+ _newId(): number;
78
+ _send(frame: any): void;
79
+ _request(method: any, fields: any): Promise<any>;
80
+ _stream(method: any, fields: any): Readable<import("streamx").ReadableEvents>;
94
81
  }
@@ -7,11 +7,11 @@ export declare class Framed {
7
7
  onMessage: any;
8
8
  buf: any;
9
9
  constructor(stream: any, onMessage: any);
10
- _ondata(chunk: any): void;
11
10
  /**
12
11
  * Encode `obj` to wire form and write it as one length-prefixed frame.
13
12
  * @param {object} obj - message to send
14
13
  * @returns {void}
15
14
  */
16
15
  send(obj: object): void;
16
+ _ondata(chunk: any): void;
17
17
  }
package/types/redact.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
- * Build a row masker for devtools. A field is masked when its dotted path is in
3
- * `fields`, its name matches `deny` (default denylist above), or `match(key,
4
- * value, path)` returns true. Masked values become a typed placeholder —
5
- * `‹redacted:bytes(32)›` / `‹redacted:string›` — so the shape stays visible but
6
- * the content is hidden. Everything else passes through untouched.
2
+ * Build a row masker for devtools. A field is masked when its dotted path is in `fields`,
3
+ * its name matches `deny` (default denylist above), or `match(key, value, path)` returns
4
+ * true.
7
5
  *
8
6
  * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: any, path: string) => boolean }} [config]
9
7
  * @returns {(ref: string, row: any) => any}
package/types/server.d.ts CHANGED
@@ -13,10 +13,7 @@ export type ReqFrame = {
13
13
  * @typedef {{ id?: string, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: string }} ReqFrame
14
14
  */
15
15
  /**
16
- * Read-only inspection server over a local Duplex `stream`. Serves the live
17
- * handle tree rooted at `me`, exposing only MAIN refs declared in each
18
- * handle's `spec.meta.refs` — local secret refs (master/keypair/
19
- * handle-keypairs) are never reachable, since they live in `meta.local.refs`.
16
+ * Read-only inspection server over a local Duplex `stream`.
20
17
  *
21
18
  * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
22
19
  * @param {object} me The live root cero handle.
@@ -64,12 +61,6 @@ export declare class TapServer {
64
61
  * @returns {Promise<void>}
65
62
  */
66
63
  get(req: ReqFrame): Promise<void>;
67
- /**
68
- * Count rows for a ref and reply with the total.
69
- * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
70
- * @returns {Promise<void>}
71
- */
72
- count(req: ReqFrame): Promise<void>;
73
64
  /**
74
65
  * Stream redacted live updates for a ref until cancelled or the stream ends.
75
66
  * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
@@ -94,15 +85,15 @@ export declare class TapServer {
94
85
  * @returns {void}
95
86
  */
96
87
  cancel(req: ReqFrame): void;
88
+ /**
89
+ * Tear down all tracked streams and destroy the underlying stream.
90
+ * @returns {void}
91
+ */
92
+ close(): void;
97
93
  _resolveRef(req: any): any;
98
94
  _source(req: any, src: any): void;
99
95
  _track(id: any, off: any): void;
100
96
  _drop(id: any): void;
101
97
  _send(obj: any): void;
102
98
  _teardown(): void;
103
- /**
104
- * Tear down all tracked streams and destroy the underlying stream.
105
- * @returns {void}
106
- */
107
- close(): void;
108
99
  }
package/types/stats.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  /**
2
- * Read-only snapshot of a handle's existing p2p/storage counters. Pure: no
3
- * listeners, no mutation, never reads a secret. `dht.stats` and the corestore
4
- * `cores` map are undocumented internals, so they are guarded — a fresh handle
5
- * (pre-ready) yields zeros rather than throwing.
2
+ * Read-only snapshot of a handle's existing p2p/storage counters.
6
3
  *
7
4
  * @param {any} handle A cero root or child handle.
8
5
  * @param {number} [at] Sample timestamp, stamped by the caller.
package/types/tap.d.ts CHANGED
@@ -23,10 +23,7 @@ export type StatsSample = {
23
23
  at: number;
24
24
  };
25
25
  /**
26
- * An applied-op event fed into the ring buffer. `op` is the dispatch verb
27
- * prefix, `name` the ref name, `row` the decoded value, `writerKey` the source
28
- * writer's key and `seq` a monotonic apply counter. After redaction `row` is
29
- * replaced with its masked copy; the rest is spread through unchanged.
26
+ * An applied-op event fed into the ring buffer.
30
27
  *
31
28
  * @typedef {{ op: string, name: string, row: Record<string, unknown>, writerKey: Buffer, seq: number }} OpEvent
32
29
  */
@@ -36,11 +33,9 @@ export type StatsSample = {
36
33
  * @typedef {{ handleId: string, network: { connections: number, peers: number, dht: object | null }, bee: { local: number }, cores: Array<{ length: number, byteLength: number, peers: number }>, at: number }} StatsSample
37
34
  */
38
35
  /**
39
- * `cero.use(devtools())` tap extension. Bound to the root handle's lifecycle,
40
- * it feeds every applied op into a bounded ring buffer, samples `stats(me)` on
41
- * an interval, and serves a read-only inspection surface to out-of-band
42
- * consumers. By default it serves a loopback TCP server on `port` (9111); pass
43
- * a custom `transport` to serve it some other way. Nothing touches the app swarm.
36
+ * The `devtools()` tap extension. Bound to the root handle's lifecycle, it feeds
37
+ * every applied op into a bounded ring buffer, samples `stats(me)` on an interval, and
38
+ * serves a read-only inspection.
44
39
  *
45
40
  * @param {{ port?: number, host?: string, token?: string | false, bufferSize?: number, sampleInterval?: number, redact?: ((ref: string, row: Record<string, unknown>) => Record<string, unknown>) | { fields?: string[], match?: (key: string, value: unknown, path: string) => boolean, deny?: RegExp | false }, transport?: { accept(handler: (stream: object) => void): void } }} [opts]
46
41
  * @returns {{ setup(me: object): () => void }}
@@ -1,7 +1,6 @@
1
1
  /**
2
- * Loopback TCP transport implementing the tap `{ accept(handler) }` contract
3
- * plus lifecycle. Each inbound connection's socket is a streamx-compatible
4
- * Duplex, ready to pass straight to `serve()`.
2
+ * Loopback TCP transport implementing the tap `{ accept(handler) }` contract plus
3
+ * lifecycle.
5
4
  *
6
5
  * @param {{ port?: number, host?: string, token?: string | null }} [opts]
7
6
  * @returns {{ accept(handler: (socket: any) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}