@cero-base/tools 2.2.1 → 2.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cero-base/tools",
3
- "version": "2.2.1",
3
+ "version": "2.3.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,
@@ -76,7 +76,7 @@
76
76
  "test:node": "find test -name '*.test.js' | sort | xargs -P1 -n1 brittle-node"
77
77
  },
78
78
  "dependencies": {
79
- "@cero-base/cero": "^2.2.1",
79
+ "@cero-base/cero": "^2.3.0",
80
80
  "b4a": "^1.9.0",
81
81
  "bare-crypto": "^1.15.3",
82
82
  "bare-net": "^2.3.3",
package/src/connect.js CHANGED
@@ -13,7 +13,8 @@ import { Framed } from './protocol.js'
13
13
  /**
14
14
  * Consumer SDK for a tap server reached over a local Duplex `stream`.
15
15
  *
16
- * @param {object} stream A streamx Duplex connected to a tap server.
16
+ * @param {import('streamx').Duplex} stream A streamx Duplex connected to a tap server.
17
+ * @param {{ token?: string }} [opts]
17
18
  * @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 }>}
18
19
  */
19
20
  export async function connect(stream, { token } = {}) {
@@ -21,10 +22,16 @@ export async function connect(stream, { token } = {}) {
21
22
  }
22
23
 
23
24
  export class Session {
25
+ /**
26
+ * @param {import('streamx').Duplex} stream
27
+ * @param {{ token?: string }} [opts]
28
+ */
24
29
  constructor(stream, { token } = {}) {
25
30
  this.stream = stream
26
31
  this.token = token || null
32
+ /** @type {Map<number, { resolve: (value: unknown) => void, reject: (err: Error) => void }>} */
27
33
  this.pending = new Map()
34
+ /** @type {Map<number, import('streamx').Readable>} */
28
35
  this.streams = new Map()
29
36
  this.seq = 0
30
37
  this.wire = new Framed(stream, (msg) => this._onmessage(msg))
@@ -93,6 +100,7 @@ export class Session {
93
100
  }
94
101
 
95
102
  // fail in-flight requests and end live streams
103
+ /** @private */
96
104
  _onclose() {
97
105
  for (const { reject } of this.pending.values()) {
98
106
  reject(new TapError('connection closed', 'CLOSED'))
@@ -102,6 +110,7 @@ export class Session {
102
110
  this.streams.clear()
103
111
  }
104
112
 
113
+ /** @private */
105
114
  _onmessage(msg) {
106
115
  if ('frame' in msg || msg.end) {
107
116
  const r = this.streams.get(msg.id)
@@ -121,14 +130,17 @@ export class Session {
121
130
  else p.resolve(msg.data)
122
131
  }
123
132
 
133
+ /** @private */
124
134
  _newId() {
125
135
  return ++this.seq
126
136
  }
127
137
 
138
+ /** @private */
128
139
  _send(frame) {
129
140
  this.wire.send(this.token ? { token: this.token, ...frame } : frame)
130
141
  }
131
142
 
143
+ /** @private */
132
144
  _request(method, fields) {
133
145
  return new Promise((resolve, reject) => {
134
146
  const id = this._newId()
@@ -137,6 +149,7 @@ export class Session {
137
149
  })
138
150
  }
139
151
 
152
+ /** @private */
140
153
  _stream(method, fields) {
141
154
  const id = this._newId()
142
155
  const r = new Readable({
package/src/format.js CHANGED
@@ -24,7 +24,7 @@ function shortRow(row) {
24
24
 
25
25
  function shortKey(key) {
26
26
  if (key == null) return ''
27
- if (b4a.isBuffer(key)) return b4a.toString(key, 'hex').slice(0, 8)
27
+ if (b4a.isBuffer(key)) return b4a.toHex(key).slice(0, 8)
28
28
  return String(key).slice(0, 8)
29
29
  }
30
30
 
@@ -45,7 +45,7 @@ export function formatHandles(tree) {
45
45
  * `{ data }` for single refs — as a compact summary.
46
46
  *
47
47
  * @param {string} ref
48
- * @param {{ data: any, total?: number, size?: number }} result
48
+ * @param {{ data: unknown, total?: number, size?: number }} result
49
49
  * @returns {string}
50
50
  */
51
51
  export function formatState(ref, result) {
@@ -74,7 +74,7 @@ const OP_COLOR = { add: c.green, set: c.yellow, del: c.red, claim: c.magenta }
74
74
  /**
75
75
  * Render one applied-op event as a single colored line.
76
76
  *
77
- * @param {{ op: string, name: string, row: any, writerKey?: any, seq?: number }} e
77
+ * @param {{ op: string, name: string, row: Record<string, unknown>, writerKey?: Uint8Array, seq?: number }} e
78
78
  * @returns {string}
79
79
  */
80
80
  export function formatEvent(e) {
@@ -87,7 +87,7 @@ export function formatEvent(e) {
87
87
  /**
88
88
  * Render a stats snapshot as a single colored line.
89
89
  *
90
- * @param {{ network?: { connections: number, peers: number }, bee?: { local: number }, cores?: any[] }} s
90
+ * @param {{ network?: { connections: number, peers: number }, bee?: { local: number }, cores?: Array<{ length: number, byteLength: number, peers: number }> }} s
91
91
  * @returns {string}
92
92
  */
93
93
  export function formatStats(s) {
package/src/protocol.js CHANGED
@@ -5,7 +5,7 @@ const BYTES = '$b'
5
5
  const MAX_FRAME = 16 * 1024 * 1024
6
6
 
7
7
  function toWire(v) {
8
- if (b4a.isBuffer(v)) return { [BYTES]: b4a.toString(v, 'hex') }
8
+ if (b4a.isBuffer(v)) return { [BYTES]: b4a.toHex(v) }
9
9
  if (Array.isArray(v)) return v.map(toWire)
10
10
  if (v && typeof v === 'object') {
11
11
  const o = {}
@@ -31,6 +31,10 @@ function fromWire(v) {
31
31
  * and delivers each decoded frame to `onMessage`; `send` writes a framed frame.
32
32
  */
33
33
  export class Framed {
34
+ /**
35
+ * @param {import('streamx').Duplex} stream
36
+ * @param {(msg: unknown) => void} onMessage
37
+ */
34
38
  constructor(stream, onMessage) {
35
39
  this.stream = stream
36
40
  this.onMessage = onMessage
@@ -55,6 +59,7 @@ export class Framed {
55
59
  this.stream.write(b4a.concat([head, body]))
56
60
  }
57
61
 
62
+ /** @private */
58
63
  _ondata(chunk) {
59
64
  this.buf = b4a.concat([this.buf, chunk])
60
65
  while (this.buf.length >= 4) {
package/src/redact.js CHANGED
@@ -8,8 +8,8 @@ const DEFAULT_DENY =
8
8
  * its name matches `deny` (default denylist above), or `match(key, value, path)` returns
9
9
  * true.
10
10
  *
11
- * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: any, path: string) => boolean }} [config]
12
- * @returns {(ref: string, row: any) => any}
11
+ * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: unknown, path: string) => boolean }} [config]
12
+ * @returns {(ref: string, row: Record<string, unknown>) => Record<string, unknown>}
13
13
  */
14
14
  export function redact(config = {}) {
15
15
  const fields = new Set(config.fields || [])
package/src/server.js CHANGED
@@ -5,15 +5,17 @@ import { Framed } from './protocol.js'
5
5
  /**
6
6
  * A decoded request frame. Carries the correlation `id` and `method`, plus the
7
7
  * per-method fields a handler reads: `ref`, `handleId`, `query`, `cancelId`.
8
- * @typedef {{ id?: string, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: string }} ReqFrame
8
+ * @typedef {{ id?: number, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: number }} ReqFrame
9
+ *
10
+ * @typedef {{ events?: { snapshot(): unknown, subscribe(fn: (e: object) => void): () => void }, stats?: { snapshot(): unknown, subscribe(fn: (s: object) => void): () => void }, redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown>, token?: string | null }} ServeOpts
9
11
  */
10
12
 
11
13
  /**
12
14
  * Read-only inspection server over a local Duplex `stream`.
13
15
  *
14
- * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
15
- * @param {object} me The live root cero handle.
16
- * @param {{ events?: { snapshot(): unknown, subscribe(fn: (e: object) => void): () => void }, stats?: { snapshot(): unknown, subscribe(fn: (s: object) => void): () => void }, redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown> }} [opts]
16
+ * @param {import('streamx').Duplex} stream A streamx Duplex carrying length-prefixed JSON frames.
17
+ * @param {import('@cero-base/cero').Context} me The live root cero handle.
18
+ * @param {ServeOpts} [opts]
17
19
  * @returns {{ close(): void }}
18
20
  */
19
21
  export function serve(stream, me, opts) {
@@ -21,14 +23,24 @@ export function serve(stream, me, opts) {
21
23
  }
22
24
 
23
25
  export class TapServer {
26
+ /**
27
+ * @param {import('streamx').Duplex} stream
28
+ * @param {import('@cero-base/cero').Context} me
29
+ * @param {ServeOpts} [opts]
30
+ */
24
31
  constructor(stream, me, opts = {}) {
25
32
  this.stream = stream
33
+ /** @type {import('@cero-base/cero').Context} */
26
34
  this.me = me
35
+ /** @type {(ref: string, row: Record<string, unknown>) => Record<string, unknown>} */
27
36
  this.redact = opts.redact || ((ref, row) => row)
28
37
  this.opts = opts
38
+ /** @type {Map<number, () => void>} */
29
39
  this.tracked = new Map()
40
+ /** @private */
30
41
  this._authed = !opts.token
31
42
  this.wire = new Framed(stream, (req) => this.onRequest(req))
43
+ /** @private */
32
44
  this._cleanup = () => this._teardown()
33
45
  stream.on('close', this._cleanup)
34
46
  // a socket reset must not crash the host
@@ -150,6 +162,7 @@ export class TapServer {
150
162
  this.stream.destroy()
151
163
  }
152
164
 
165
+ /** @private */
153
166
  _resolveRef(req) {
154
167
  const me = this.me
155
168
  const handle =
@@ -161,6 +174,7 @@ export class TapServer {
161
174
  return handle[req.ref]
162
175
  }
163
176
 
177
+ /** @private */
164
178
  _source(req, src) {
165
179
  if (!src) {
166
180
  this._send({ id: req.id, end: true })
@@ -173,10 +187,12 @@ export class TapServer {
173
187
  this._track(req.id, off)
174
188
  }
175
189
 
190
+ /** @private */
176
191
  _track(id, off) {
177
192
  this.tracked.set(id, off)
178
193
  }
179
194
 
195
+ /** @private */
180
196
  _drop(id) {
181
197
  const off = this.tracked.get(id)
182
198
  if (off) {
@@ -185,10 +201,12 @@ export class TapServer {
185
201
  }
186
202
  }
187
203
 
204
+ /** @private */
188
205
  _send(obj) {
189
206
  this.wire.send(obj)
190
207
  }
191
208
 
209
+ /** @private */
192
210
  _teardown() {
193
211
  for (const off of this.tracked.values()) off()
194
212
  this.tracked.clear()
package/src/stats.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Read-only snapshot of a handle's existing p2p/storage counters.
3
3
  *
4
- * @param {any} handle A cero root or child handle.
4
+ * @param {import('@cero-base/cero').Handle} handle A cero root or child handle.
5
5
  * @param {number} [at] Sample timestamp, stamped by the caller.
6
- * @returns {{ handleId: string, network: { connections: number, peers: number, dht: any }, bee: { local: number, stats: any }, cores: Array<{ length: number, byteLength: number, peers: number }>, at: number }}
6
+ * @returns {{ handleId: string, network: { connections: number, peers: number, dht: object | null }, bee: { local: number, stats: Record<string, number> | null }, cores: Array<{ length: number, byteLength: number, peers: number }>, at: number }}
7
7
  */
8
8
  export function stats(handle, at = 0) {
9
9
  const net = handle.network
package/src/tap.js CHANGED
@@ -1,3 +1,4 @@
1
+ import b4a from 'b4a'
1
2
  import crypto from 'crypto'
2
3
 
3
4
  import { stats } from './stats.js'
@@ -32,8 +33,7 @@ export function devtools(opts = {}) {
32
33
  const sampler = new Sampler(me, opts.sampleInterval ?? 1000)
33
34
  const redactor = makeRedactor(opts.redact)
34
35
  // any local process can dial the port, so a per-run token gates the tap
35
- const token =
36
- opts.token === false ? null : opts.token || crypto.randomBytes(16).toString('hex')
36
+ const token = opts.token === false ? null : opts.token || b4a.toHex(crypto.randomBytes(16))
37
37
  const transport =
38
38
  opts.transport || loopback({ port: opts.port ?? 9111, host: opts.host, token })
39
39
  const offs = []
package/src/transport.js CHANGED
@@ -5,7 +5,7 @@ import net from 'net'
5
5
  * lifecycle.
6
6
  *
7
7
  * @param {{ port?: number, host?: string, token?: string | null }} [opts]
8
- * @returns {{ accept(handler: (socket: any) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}
8
+ * @returns {{ accept(handler: (socket: import('streamx').Duplex) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}
9
9
  */
10
10
  export function loopback(opts = {}) {
11
11
  const host = opts.host ?? '127.0.0.1'
@@ -51,7 +51,7 @@ export function loopback(opts = {}) {
51
51
  * `connect()`.
52
52
  *
53
53
  * @param {{ port: number, host?: string }} [opts]
54
- * @returns {any} A streamx-compatible Duplex socket.
54
+ * @returns {import('streamx').Duplex} A streamx-compatible Duplex socket.
55
55
  */
56
56
  export function dial(opts = {}) {
57
57
  return net.connect(opts.port, opts.host ?? '127.0.0.1')
@@ -1,4 +1,3 @@
1
- import { Readable } from 'streamx';
2
1
  import { Framed } from './protocol.js';
3
2
  export type Query = object;
4
3
  export type Handle = Record<string, unknown>;
@@ -11,10 +10,13 @@ export type Handle = Record<string, unknown>;
11
10
  /**
12
11
  * Consumer SDK for a tap server reached over a local Duplex `stream`.
13
12
  *
14
- * @param {object} stream A streamx Duplex connected to a tap server.
13
+ * @param {import('streamx').Duplex} stream A streamx Duplex connected to a tap server.
14
+ * @param {{ token?: string }} [opts]
15
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 }>}
16
16
  */
17
- export declare function connect(stream: object, { token }?: {}): Promise<{
17
+ export declare function connect(stream: import('streamx').Duplex, { token }?: {
18
+ token?: string;
19
+ }): Promise<{
18
20
  handles(): Promise<Handle[]>;
19
21
  get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
20
22
  watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable;
@@ -23,13 +25,24 @@ export declare function connect(stream: object, { token }?: {}): Promise<{
23
25
  close(): void;
24
26
  }>;
25
27
  export declare class Session {
26
- stream: any;
27
- token: any;
28
- pending: Map<any, any>;
29
- streams: Map<any, any>;
28
+ stream: import("streamx").Duplex<import("streamx").DuplexEvents>;
29
+ token: string;
30
+ /** @type {Map<number, { resolve: (value: unknown) => void, reject: (err: Error) => void }>} */
31
+ pending: Map<number, {
32
+ resolve: (value: unknown) => void;
33
+ reject: (err: Error) => void;
34
+ }>;
35
+ /** @type {Map<number, import('streamx').Readable>} */
36
+ streams: Map<number, import('streamx').Readable>;
30
37
  seq: number;
31
38
  wire: Framed;
32
- constructor(stream: any, { token }?: {});
39
+ /**
40
+ * @param {import('streamx').Duplex} stream
41
+ * @param {{ token?: string }} [opts]
42
+ */
43
+ constructor(stream: import('streamx').Duplex, { token }?: {
44
+ token?: string;
45
+ });
33
46
  /**
34
47
  * Lists the handles exposed by the server.
35
48
  *
@@ -72,10 +85,16 @@ export declare class Session {
72
85
  * @returns {void}
73
86
  */
74
87
  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>;
88
+ /** @private */
89
+ private _onclose;
90
+ /** @private */
91
+ private _onmessage;
92
+ /** @private */
93
+ private _newId;
94
+ /** @private */
95
+ private _send;
96
+ /** @private */
97
+ private _request;
98
+ /** @private */
99
+ private _stream;
81
100
  }
package/types/format.d.ts CHANGED
@@ -13,11 +13,11 @@ export declare function formatHandles(tree: Array<{
13
13
  * `{ data }` for single refs — as a compact summary.
14
14
  *
15
15
  * @param {string} ref
16
- * @param {{ data: any, total?: number, size?: number }} result
16
+ * @param {{ data: unknown, total?: number, size?: number }} result
17
17
  * @returns {string}
18
18
  */
19
19
  export declare function formatState(ref: string, result: {
20
- data: any;
20
+ data: unknown;
21
21
  total?: number;
22
22
  size?: number;
23
23
  }): string;
@@ -34,20 +34,20 @@ export declare function formatError(ref: string, err: {
34
34
  /**
35
35
  * Render one applied-op event as a single colored line.
36
36
  *
37
- * @param {{ op: string, name: string, row: any, writerKey?: any, seq?: number }} e
37
+ * @param {{ op: string, name: string, row: Record<string, unknown>, writerKey?: Uint8Array, seq?: number }} e
38
38
  * @returns {string}
39
39
  */
40
40
  export declare function formatEvent(e: {
41
41
  op: string;
42
42
  name: string;
43
- row: any;
44
- writerKey?: any;
43
+ row: Record<string, unknown>;
44
+ writerKey?: Uint8Array;
45
45
  seq?: number;
46
46
  }): string;
47
47
  /**
48
48
  * Render a stats snapshot as a single colored line.
49
49
  *
50
- * @param {{ network?: { connections: number, peers: number }, bee?: { local: number }, cores?: any[] }} s
50
+ * @param {{ network?: { connections: number, peers: number }, bee?: { local: number }, cores?: Array<{ length: number, byteLength: number, peers: number }> }} s
51
51
  * @returns {string}
52
52
  */
53
53
  export declare function formatStats(s: {
@@ -58,5 +58,9 @@ export declare function formatStats(s: {
58
58
  bee?: {
59
59
  local: number;
60
60
  };
61
- cores?: any[];
61
+ cores?: Array<{
62
+ length: number;
63
+ byteLength: number;
64
+ peers: number;
65
+ }>;
62
66
  }): string;
@@ -3,15 +3,20 @@
3
3
  * and delivers each decoded frame to `onMessage`; `send` writes a framed frame.
4
4
  */
5
5
  export declare class Framed {
6
- stream: any;
7
- onMessage: any;
6
+ stream: import("streamx").Duplex<import("streamx").DuplexEvents>;
7
+ onMessage: (msg: unknown) => void;
8
8
  buf: Uint8Array<ArrayBufferLike>;
9
- constructor(stream: any, onMessage: any);
9
+ /**
10
+ * @param {import('streamx').Duplex} stream
11
+ * @param {(msg: unknown) => void} onMessage
12
+ */
13
+ constructor(stream: import('streamx').Duplex, onMessage: (msg: unknown) => void);
10
14
  /**
11
15
  * Encode `obj` to wire form and write it as one length-prefixed frame.
12
16
  * @param {object} obj - message to send
13
17
  * @returns {void}
14
18
  */
15
19
  send(obj: object): void;
16
- _ondata(chunk: any): void;
20
+ /** @private */
21
+ private _ondata;
17
22
  }
package/types/redact.d.ts CHANGED
@@ -3,11 +3,11 @@
3
3
  * its name matches `deny` (default denylist above), or `match(key, value, path)` returns
4
4
  * true.
5
5
  *
6
- * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: any, path: string) => boolean }} [config]
7
- * @returns {(ref: string, row: any) => any}
6
+ * @param {{ fields?: string[], deny?: RegExp | false, match?: (key: string, value: unknown, path: string) => boolean }} [config]
7
+ * @returns {(ref: string, row: Record<string, unknown>) => Record<string, unknown>}
8
8
  */
9
9
  export declare function redact(config?: {
10
10
  fields?: string[];
11
11
  deny?: RegExp | false;
12
- match?: (key: string, value: any, path: string) => boolean;
13
- }): (ref: string, row: any) => any;
12
+ match?: (key: string, value: unknown, path: string) => boolean;
13
+ }): (ref: string, row: Record<string, unknown>) => Record<string, unknown>;
package/types/server.d.ts CHANGED
@@ -1,26 +1,13 @@
1
1
  import { Framed } from './protocol.js';
2
2
  export type ReqFrame = {
3
- id?: string;
3
+ id?: number;
4
4
  method?: string;
5
5
  ref?: string;
6
6
  handleId?: string;
7
7
  query?: object;
8
- cancelId?: string;
8
+ cancelId?: number;
9
9
  };
10
- /**
11
- * A decoded request frame. Carries the correlation `id` and `method`, plus the
12
- * per-method fields a handler reads: `ref`, `handleId`, `query`, `cancelId`.
13
- * @typedef {{ id?: string, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: string }} ReqFrame
14
- */
15
- /**
16
- * Read-only inspection server over a local Duplex `stream`.
17
- *
18
- * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
19
- * @param {object} me The live root cero handle.
20
- * @param {{ events?: { snapshot(): unknown, subscribe(fn: (e: object) => void): () => void }, stats?: { snapshot(): unknown, subscribe(fn: (s: object) => void): () => void }, redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown> }} [opts]
21
- * @returns {{ close(): void }}
22
- */
23
- export declare function serve(stream: object, me: object, opts?: {
10
+ export type ServeOpts = {
24
11
  events?: {
25
12
  snapshot(): unknown;
26
13
  subscribe(fn: (e: object) => void): () => void;
@@ -30,19 +17,46 @@ export declare function serve(stream: object, me: object, opts?: {
30
17
  subscribe(fn: (s: object) => void): () => void;
31
18
  };
32
19
  redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown>;
33
- }): {
20
+ token?: string | null;
21
+ };
22
+ /**
23
+ * A decoded request frame. Carries the correlation `id` and `method`, plus the
24
+ * per-method fields a handler reads: `ref`, `handleId`, `query`, `cancelId`.
25
+ * @typedef {{ id?: number, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: number }} ReqFrame
26
+ *
27
+ * @typedef {{ events?: { snapshot(): unknown, subscribe(fn: (e: object) => void): () => void }, stats?: { snapshot(): unknown, subscribe(fn: (s: object) => void): () => void }, redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown>, token?: string | null }} ServeOpts
28
+ */
29
+ /**
30
+ * Read-only inspection server over a local Duplex `stream`.
31
+ *
32
+ * @param {import('streamx').Duplex} stream A streamx Duplex carrying length-prefixed JSON frames.
33
+ * @param {import('@cero-base/cero').Context} me The live root cero handle.
34
+ * @param {ServeOpts} [opts]
35
+ * @returns {{ close(): void }}
36
+ */
37
+ export declare function serve(stream: import('streamx').Duplex, me: import('@cero-base/cero').Context, opts?: ServeOpts): {
34
38
  close(): void;
35
39
  };
36
40
  export declare class TapServer {
37
- stream: any;
38
- me: any;
39
- redact: any;
40
- opts: {};
41
- tracked: Map<any, any>;
42
- _authed: boolean;
41
+ stream: import("streamx").Duplex<import("streamx").DuplexEvents>;
42
+ /** @type {import('@cero-base/cero').Context} */
43
+ me: import('@cero-base/cero').Context;
44
+ /** @type {(ref: string, row: Record<string, unknown>) => Record<string, unknown>} */
45
+ redact: (ref: string, row: Record<string, unknown>) => Record<string, unknown>;
46
+ opts: ServeOpts;
47
+ /** @type {Map<number, () => void>} */
48
+ tracked: Map<number, () => void>;
49
+ /** @private */
50
+ _authed;
43
51
  wire: Framed;
44
- _cleanup: () => void;
45
- constructor(stream: any, me: any, opts?: {});
52
+ /** @private */
53
+ _cleanup;
54
+ /**
55
+ * @param {import('streamx').Duplex} stream
56
+ * @param {import('@cero-base/cero').Context} me
57
+ * @param {ServeOpts} [opts]
58
+ */
59
+ constructor(stream: import('streamx').Duplex, me: import('@cero-base/cero').Context, opts?: ServeOpts);
46
60
  /**
47
61
  * Dispatch an inbound request frame to its named method handler.
48
62
  * @param {ReqFrame} req A decoded request frame, expected to carry `id` and `method`.
@@ -90,10 +104,16 @@ export declare class TapServer {
90
104
  * @returns {void}
91
105
  */
92
106
  close(): void;
93
- _resolveRef(req: any): any;
94
- _source(req: any, src: any): void;
95
- _track(id: any, off: any): void;
96
- _drop(id: any): void;
97
- _send(obj: any): void;
98
- _teardown(): void;
107
+ /** @private */
108
+ private _resolveRef;
109
+ /** @private */
110
+ private _source;
111
+ /** @private */
112
+ private _track;
113
+ /** @private */
114
+ private _drop;
115
+ /** @private */
116
+ private _send;
117
+ /** @private */
118
+ private _teardown;
99
119
  }
package/types/stats.d.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  /**
2
2
  * Read-only snapshot of a handle's existing p2p/storage counters.
3
3
  *
4
- * @param {any} handle A cero root or child handle.
4
+ * @param {import('@cero-base/cero').Handle} handle A cero root or child handle.
5
5
  * @param {number} [at] Sample timestamp, stamped by the caller.
6
- * @returns {{ handleId: string, network: { connections: number, peers: number, dht: any }, bee: { local: number, stats: any }, cores: Array<{ length: number, byteLength: number, peers: number }>, at: number }}
6
+ * @returns {{ handleId: string, network: { connections: number, peers: number, dht: object | null }, bee: { local: number, stats: Record<string, number> | null }, cores: Array<{ length: number, byteLength: number, peers: number }>, at: number }}
7
7
  */
8
- export declare function stats(handle: any, at?: number): {
8
+ export declare function stats(handle: import('@cero-base/cero').Handle, at?: number): {
9
9
  handleId: string;
10
10
  network: {
11
11
  connections: number;
12
12
  peers: number;
13
- dht: any;
13
+ dht: object | null;
14
14
  };
15
15
  bee: {
16
16
  local: number;
17
- stats: any;
17
+ stats: Record<string, number> | null;
18
18
  };
19
19
  cores: Array<{
20
20
  length: number;
@@ -3,14 +3,14 @@
3
3
  * lifecycle.
4
4
  *
5
5
  * @param {{ port?: number, host?: string, token?: string | null }} [opts]
6
- * @returns {{ accept(handler: (socket: any) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}
6
+ * @returns {{ accept(handler: (socket: import('streamx').Duplex) => void): void, ready(): Promise<{ port: number }>, port: number | null, close(): void }}
7
7
  */
8
8
  export declare function loopback(opts?: {
9
9
  port?: number;
10
10
  host?: string;
11
11
  token?: string | null;
12
12
  }): {
13
- accept(handler: (socket: any) => void): void;
13
+ accept(handler: (socket: import('streamx').Duplex) => void): void;
14
14
  ready(): Promise<{
15
15
  port: number;
16
16
  }>;
@@ -22,9 +22,9 @@ export declare function loopback(opts?: {
22
22
  * `connect()`.
23
23
  *
24
24
  * @param {{ port: number, host?: string }} [opts]
25
- * @returns {any} A streamx-compatible Duplex socket.
25
+ * @returns {import('streamx').Duplex} A streamx-compatible Duplex socket.
26
26
  */
27
27
  export declare function dial(opts?: {
28
28
  port: number;
29
29
  host?: string;
30
- }): any;
30
+ }): import('streamx').Duplex;