@cero-base/tools 0.8.10 → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/bin/cero-tools.js CHANGED
@@ -13,6 +13,11 @@ const [hostPart, portPart] = arg.includes(':') ? arg.split(':') : [undefined, ar
13
13
  const host = hostPart
14
14
  const port = Number(portPart)
15
15
 
16
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
17
+ console.error(`invalid port '${portPart}' — expected an integer 1–65535`)
18
+ process.exit(1)
19
+ }
20
+
16
21
  const socket = dial({ host, port })
17
22
  socket.on('error', (err) => {
18
23
  console.error(
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@cero-base/tools",
3
- "version": "0.8.10",
3
+ "version": "1.0.1",
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
+ "sideEffects": false,
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/lekinox/cero-base.git",
13
+ "directory": "packages/tools"
14
+ },
6
15
  "main": "./src/index.js",
7
16
  "types": "./types/index.d.ts",
8
17
  "bin": {
@@ -44,17 +53,17 @@
44
53
  "test": "ls test/*.test.js | xargs -P1 -n1 brittle-node"
45
54
  },
46
55
  "dependencies": {
47
- "@cero-base/cero": "^0.8.10",
48
- "@cero-base/core": "^0.8.10",
56
+ "@cero-base/cero": "^1.0.1",
57
+ "@cero-base/core": "^1.0.1",
49
58
  "b4a": "^1.8.1",
50
- "bare-net": "^2.3.1",
51
- "compact-encoding": "^3.1.0",
52
- "streamx": "^2.22.0"
59
+ "bare-net": "^2.3.2",
60
+ "compact-encoding": "^3.2.0",
61
+ "streamx": "^2.28.0"
53
62
  },
54
63
  "devDependencies": {
55
64
  "@hyperswarm/testnet": "^3.1.4",
56
- "brittle": "^4.0.0",
57
- "typescript": "^5.7.0"
65
+ "brittle": "^4.0.2",
66
+ "typescript": "^5.9.3"
58
67
  },
59
68
  "license": "Apache-2.0"
60
69
  }
package/src/connect.js CHANGED
@@ -2,14 +2,22 @@ import { Readable } from 'streamx'
2
2
 
3
3
  import { Framed } from './protocol.js'
4
4
 
5
+ /**
6
+ * @typedef {object} Query Opaque query filter passed to the server.
7
+ */
8
+
9
+ /**
10
+ * @typedef {Record<string, unknown>} Handle A handle descriptor returned by the server.
11
+ */
12
+
5
13
  /**
6
14
  * Consumer SDK for a tap server reached over a local Duplex `stream`. Returns
7
15
  * a session exposing read methods (`handles`/`get`/`count`) and stream methods
8
16
  * (`watch`/`events`/`stats`). Stream methods return a streamx Readable that
9
17
  * cancels its server-side source when destroyed.
10
18
  *
11
- * @param {any} stream A streamx Duplex connected to a tap server.
12
- * @returns {Promise<{ handles(): Promise<any>, get(ref: string, query?: any, handleId?: string): Promise<any>, count(ref: string, query?: any, handleId?: string): Promise<any>, watch(ref: string, query?: any, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
19
+ * @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 }>}
13
21
  */
14
22
  export async function connect(stream) {
15
23
  return new Session(stream)
@@ -22,6 +30,18 @@ export class Session {
22
30
  this.streams = new Map()
23
31
  this.seq = 0
24
32
  this.wire = new Framed(stream, (msg) => this._onMessage(msg))
33
+ stream.on('error', () => {}) // a transport error shouldn't crash the consumer
34
+ stream.on('close', () => this._onClose())
35
+ }
36
+
37
+ // The transport dropped — fail in-flight requests and end live streams instead
38
+ // of leaving them hung and the maps leaking.
39
+ _onClose() {
40
+ for (const { reject } of this.pending.values())
41
+ reject(new TapError('connection closed', 'CLOSED'))
42
+ this.pending.clear()
43
+ for (const r of this.streams.values()) r.push(null)
44
+ this.streams.clear()
25
45
  }
26
46
 
27
47
  _onMessage(msg) {
@@ -69,30 +89,74 @@ export class Session {
69
89
  return r
70
90
  }
71
91
 
92
+ /**
93
+ * Lists the handles exposed by the server.
94
+ *
95
+ * @returns {Promise<Handle[]>} Resolves to the handle descriptors.
96
+ */
72
97
  handles() {
73
98
  return this._request('handles', {})
74
99
  }
75
100
 
101
+ /**
102
+ * Reads the current value for `ref`.
103
+ *
104
+ * @param {string} ref Reference to read.
105
+ * @param {Query} [query] Optional query filter.
106
+ * @param {string} [handleId] Optional handle to scope the read.
107
+ * @returns {Promise<unknown>} Resolves to the value.
108
+ */
76
109
  get(ref, query, handleId) {
77
110
  return this._request('get', { ref, query, handleId })
78
111
  }
79
112
 
113
+ /**
114
+ * Counts entries matching `ref`.
115
+ *
116
+ * @param {string} ref Reference to count.
117
+ * @param {Query} [query] Optional query filter.
118
+ * @param {string} [handleId] Optional handle to scope the count.
119
+ * @returns {Promise<number>} Resolves to the count.
120
+ */
80
121
  count(ref, query, handleId) {
81
122
  return this._request('count', { ref, query, handleId })
82
123
  }
83
124
 
125
+ /**
126
+ * Watches `ref` for changes, emitting frames as they arrive.
127
+ *
128
+ * @param {string} ref Reference to watch.
129
+ * @param {Query} [query] Optional query filter.
130
+ * @param {string} [handleId] Optional handle to scope the watch.
131
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
132
+ */
84
133
  watch(ref, query, handleId) {
85
134
  return this._stream('watch', { ref, query, handleId })
86
135
  }
87
136
 
137
+ /**
138
+ * Streams server events.
139
+ *
140
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
141
+ */
88
142
  events() {
89
143
  return this._stream('events', {})
90
144
  }
91
145
 
146
+ /**
147
+ * Streams server stats.
148
+ *
149
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
150
+ */
92
151
  stats() {
93
152
  return this._stream('stats', {})
94
153
  }
95
154
 
155
+ /**
156
+ * Closes the session by ending the underlying stream.
157
+ *
158
+ * @returns {void}
159
+ */
96
160
  close() {
97
161
  this.stream.end()
98
162
  }
package/src/format.js CHANGED
@@ -23,7 +23,7 @@ function shortRow(row) {
23
23
 
24
24
  function shortKey(key) {
25
25
  if (key == null) return ''
26
- if (b4a.isBuffer(key) || key instanceof Uint8Array) return b4a.toString(key, 'hex').slice(0, 8)
26
+ if (b4a.isBuffer(key)) return b4a.toString(key, 'hex').slice(0, 8)
27
27
  return String(key).slice(0, 8)
28
28
  }
29
29
 
package/src/protocol.js CHANGED
@@ -1,9 +1,12 @@
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).
6
+ const MAX_FRAME = 16 * 1024 * 1024
4
7
 
5
8
  function toWire(v) {
6
- if (b4a.isBuffer(v) || v instanceof Uint8Array) return { [BYTES]: b4a.toString(v, 'hex') }
9
+ if (b4a.isBuffer(v)) return { [BYTES]: b4a.toString(v, 'hex') }
7
10
  if (Array.isArray(v)) return v.map(toWire)
8
11
  if (v && typeof v === 'object') {
9
12
  const o = {}
@@ -40,6 +43,10 @@ export class Framed {
40
43
  this.buf = b4a.concat([this.buf, chunk])
41
44
  while (this.buf.length >= 4) {
42
45
  const len = new DataView(this.buf.buffer, this.buf.byteOffset, 4).getUint32(0, true)
46
+ if (len > MAX_FRAME) {
47
+ this.stream.destroy() // oversized/garbage prefix — drop the connection
48
+ return
49
+ }
43
50
  if (this.buf.length < 4 + len) break
44
51
  const body = b4a.toString(this.buf.subarray(4, 4 + len))
45
52
  this.buf = this.buf.subarray(4 + len)
@@ -53,7 +60,17 @@ export class Framed {
53
60
  }
54
61
  }
55
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
+ */
56
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
+ }
57
74
  const body = b4a.from(JSON.stringify(toWire(obj)))
58
75
  const head = b4a.alloc(4)
59
76
  new DataView(head.buffer, head.byteOffset, 4).setUint32(0, body.length, true)
package/src/redact.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import b4a from 'b4a'
2
2
 
3
3
  // Obvious secret-ish field names, masked by default once redaction is enabled.
4
- const DEFAULT_DENY = /^(seed|secret|secretkey|password|passphrase|token|private|privatekey)$/i
4
+ const DEFAULT_DENY =
5
+ /^(seed|secret|secretkey|password|passphrase|token|private|privatekey|encryptionkey|mnemonic)$/i
5
6
 
6
7
  /**
7
8
  * Build a row masker for devtools. A field is masked when its dotted path is in
@@ -18,7 +19,7 @@ export function redact(config = {}) {
18
19
  const deny = config.deny === false ? null : config.deny || DEFAULT_DENY
19
20
  const match = typeof config.match === 'function' ? config.match : null
20
21
 
21
- const isBytes = (v) => b4a.isBuffer(v) || v instanceof Uint8Array
22
+ const isBytes = (v) => b4a.isBuffer(v)
22
23
  const mask = (v) =>
23
24
  isBytes(v) ? `‹redacted:bytes(${v.length})›` : `‹redacted:${v === null ? 'null' : typeof v}›`
24
25
 
package/src/server.js CHANGED
@@ -2,15 +2,21 @@ import { get, count, watch } from '@cero-base/cero'
2
2
 
3
3
  import { Framed } from './protocol.js'
4
4
 
5
+ /**
6
+ * A decoded request frame. Carries the correlation `id` and `method`, plus the
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
9
+ */
10
+
5
11
  /**
6
12
  * Read-only inspection server over a local Duplex `stream`. Serves the live
7
13
  * handle tree rooted at `me`, exposing only MAIN refs declared in each
8
14
  * handle's `spec.meta.refs` — local secret refs (master/keypair/
9
15
  * handle-keypairs) are never reachable, since they live in `meta.local.refs`.
10
16
  *
11
- * @param {any} stream A streamx Duplex carrying length-prefixed JSON frames.
12
- * @param {any} me The live root cero handle.
13
- * @param {{ events?: { snapshot(): any, subscribe(fn: (e: any) => void): () => void }, stats?: { snapshot(): any, subscribe(fn: (s: any) => void): () => void }, redact?: (ref: string, row: any) => any }} [opts]
17
+ * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
18
+ * @param {object} me The live root cero handle.
19
+ * @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]
14
20
  * @returns {{ close(): void }}
15
21
  */
16
22
  export function serve(stream, me, opts) {
@@ -27,9 +33,18 @@ export class TapServer {
27
33
  this.wire = new Framed(stream, (req) => this.onRequest(req))
28
34
  this._cleanup = () => this._teardown()
29
35
  stream.on('close', this._cleanup)
36
+ // an inbound socket reset (client kill / ECONNRESET) must tear down, not crash the host
37
+ stream.on('error', this._cleanup)
30
38
  }
31
39
 
40
+ /**
41
+ * Dispatch an inbound request frame to its named method handler.
42
+ * @param {ReqFrame} req A decoded request frame, expected to carry `id` and `method`.
43
+ * @returns {Promise<void>}
44
+ */
32
45
  async onRequest(req) {
46
+ // a malformed frame (JSON null / scalar) has no method — ignore it
47
+ if (!req || typeof req !== 'object') return
33
48
  const handler = this[req.method]
34
49
  if (!handler || !METHODS.has(req.method)) {
35
50
  this._send({
@@ -47,6 +62,11 @@ export class TapServer {
47
62
  }
48
63
  }
49
64
 
65
+ /**
66
+ * Reply with the root handle and its direct children as `{ id, type }` rows.
67
+ * @param {ReqFrame} req A request frame carrying `id`.
68
+ * @returns {void}
69
+ */
50
70
  handles(req) {
51
71
  const me = this.me
52
72
  const data = [
@@ -56,6 +76,11 @@ export class TapServer {
56
76
  this._send({ id: req.id, ok: true, data })
57
77
  }
58
78
 
79
+ /**
80
+ * Read a ref once and reply with the redacted result.
81
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
82
+ * @returns {Promise<void>}
83
+ */
59
84
  async get(req) {
60
85
  const ref = this._resolveRef(req)
61
86
  const r = await get(ref, req.query)
@@ -65,11 +90,21 @@ export class TapServer {
65
90
  this._send({ id: req.id, ok: true, data: { ...r, data } })
66
91
  }
67
92
 
93
+ /**
94
+ * Count rows for a ref and reply with the total.
95
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
96
+ * @returns {Promise<void>}
97
+ */
68
98
  async count(req) {
69
99
  const ref = this._resolveRef(req)
70
100
  this._send({ id: req.id, ok: true, data: (await count(ref, req.query)).data })
71
101
  }
72
102
 
103
+ /**
104
+ * Stream redacted live updates for a ref until cancelled or the stream ends.
105
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
106
+ * @returns {void}
107
+ */
73
108
  watch(req) {
74
109
  const ref = this._resolveRef(req)
75
110
  const s = watch(ref, req.query)
@@ -79,16 +114,36 @@ export class TapServer {
79
114
  this._send({ id: req.id, frame: { ...d, data } })
80
115
  })
81
116
  s.on('end', () => this._send({ id: req.id, end: true }))
117
+ // a watch-stream error must not crash the host — end the client stream cleanly
118
+ s.on('error', () => {
119
+ this._drop(req.id)
120
+ this._send({ id: req.id, end: true })
121
+ })
82
122
  }
83
123
 
124
+ /**
125
+ * Stream the events source snapshot then live events.
126
+ * @param {ReqFrame} req A request frame carrying `id`.
127
+ * @returns {void}
128
+ */
84
129
  events(req) {
85
130
  this._source(req, this.opts.events)
86
131
  }
87
132
 
133
+ /**
134
+ * Stream the stats source snapshot then live stats.
135
+ * @param {ReqFrame} req A request frame carrying `id`.
136
+ * @returns {void}
137
+ */
88
138
  stats(req) {
89
139
  this._source(req, this.opts.stats)
90
140
  }
91
141
 
142
+ /**
143
+ * Stop a tracked stream by id and release its resources.
144
+ * @param {ReqFrame} req A request frame carrying `cancelId`.
145
+ * @returns {void}
146
+ */
92
147
  cancel(req) {
93
148
  this._drop(req.cancelId)
94
149
  }
@@ -137,6 +192,10 @@ export class TapServer {
137
192
  this.tracked.clear()
138
193
  }
139
194
 
195
+ /**
196
+ * Tear down all tracked streams and destroy the underlying stream.
197
+ * @returns {void}
198
+ */
140
199
  close() {
141
200
  this._teardown()
142
201
  this.stream.destroy()
package/src/tap.js CHANGED
@@ -3,6 +3,21 @@ import { serve } from './server.js'
3
3
  import { redact } from './redact.js'
4
4
  import { loopback } from './transport.js'
5
5
 
6
+ /**
7
+ * An applied-op event fed into the ring buffer. `op` is the dispatch verb
8
+ * prefix, `name` the ref name, `row` the decoded value, `writerKey` the source
9
+ * writer's key and `seq` a monotonic apply counter. After redaction `row` is
10
+ * replaced with its masked copy; the rest is spread through unchanged.
11
+ *
12
+ * @typedef {{ op: string, name: string, row: Record<string, unknown>, writerKey: Buffer, seq: number }} OpEvent
13
+ */
14
+
15
+ /**
16
+ * A periodic `stats(me)` sample. See `stats()` for the field meanings.
17
+ *
18
+ * @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
19
+ */
20
+
6
21
  /**
7
22
  * `cero.use(devtools())` tap extension. Bound to the root handle's lifecycle,
8
23
  * it feeds every applied op into a bounded ring buffer, samples `stats(me)` on
@@ -10,8 +25,8 @@ import { loopback } from './transport.js'
10
25
  * consumers. By default it serves a loopback TCP server on `port` (9111); pass
11
26
  * a custom `transport` to serve it some other way. Nothing touches the app swarm.
12
27
  *
13
- * @param {{ port?: number, host?: string, bufferSize?: number, sampleInterval?: number, redact?: ((ref: string, row: any) => any) | { fields?: string[], match?: Function, deny?: RegExp | false }, transport?: { accept(handler: (stream: any) => void): void } }} [opts]
14
- * @returns {{ setup(me: any): () => void }}
28
+ * @param {{ port?: number, host?: string, 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]
29
+ * @returns {{ setup(me: object): () => void }}
15
30
  */
16
31
  export function devtools(opts = {}) {
17
32
  return {
@@ -53,8 +68,9 @@ export function devtools(opts = {}) {
53
68
  }
54
69
 
55
70
  function makeRedactor(opt) {
56
- if (!opt) return null
57
- return typeof opt === 'function' ? opt : redact(opt)
71
+ if (opt === false) return null // explicit opt-out only; redaction is on by default
72
+ if (typeof opt === 'function') return opt
73
+ return redact(opt || undefined)
58
74
  }
59
75
 
60
76
  /** Bounded ring buffer with snapshot + live subscription. */
@@ -65,16 +81,30 @@ class Ring {
65
81
  this.subs = new Set()
66
82
  }
67
83
 
84
+ /**
85
+ * Append an event, evicting the oldest if over capacity, then notify subscribers.
86
+ * @param {OpEvent} e
87
+ * @returns {void}
88
+ */
68
89
  push(e) {
69
90
  this.items.push(e)
70
91
  if (this.items.length > this.max) this.items.shift()
71
92
  for (const fn of this.subs) fn(e)
72
93
  }
73
94
 
95
+ /**
96
+ * Copy of the buffered events.
97
+ * @returns {OpEvent[]}
98
+ */
74
99
  snapshot() {
75
100
  return this.items.slice()
76
101
  }
77
102
 
103
+ /**
104
+ * Subscribe to pushed events.
105
+ * @param {(e: OpEvent) => void} fn
106
+ * @returns {() => boolean} unsubscribe
107
+ */
78
108
  subscribe(fn) {
79
109
  this.subs.add(fn)
80
110
  return () => this.subs.delete(fn)
@@ -92,15 +122,28 @@ class Sampler {
92
122
  }, interval)
93
123
  }
94
124
 
125
+ /**
126
+ * Most recent stats sample.
127
+ * @returns {StatsSample}
128
+ */
95
129
  snapshot() {
96
130
  return this.latest
97
131
  }
98
132
 
133
+ /**
134
+ * Subscribe to each new stats sample.
135
+ * @param {(latest: StatsSample) => void} fn
136
+ * @returns {() => boolean} unsubscribe
137
+ */
99
138
  subscribe(fn) {
100
139
  this.subs.add(fn)
101
140
  return () => this.subs.delete(fn)
102
141
  }
103
142
 
143
+ /**
144
+ * Stop the sampling interval.
145
+ * @returns {void}
146
+ */
104
147
  stop() {
105
148
  clearInterval(this.timer)
106
149
  }
package/src/transport.js CHANGED
@@ -12,26 +12,34 @@ export function loopback(opts = {}) {
12
12
  const host = opts.host ?? '127.0.0.1'
13
13
  const base = opts.port ?? 0
14
14
  let server = null
15
+ let ready = null
15
16
  return {
16
17
  accept(handler) {
17
- server = net.createServer((socket) => handler(socket))
18
+ server = net.createServer((socket) => {
19
+ socket.on('error', () => {}) // an inbound reset must not crash the host
20
+ handler(socket)
21
+ })
18
22
  let port = base
19
23
  let tries = 0
20
- // A taken port (e.g. a second app instance) bumps to the next one rather
21
- // than crashing the app devtools is never essential.
22
- server.on('error', (err) => {
23
- if (err.code === 'EADDRINUSE' && base && tries++ < 10) server.listen(++port, host)
24
- else console.error(`[devtools] tap could not start: ${err.message}`)
24
+ // ready() resolves when listening, rejects on a terminal bind failure
25
+ // (so a caller awaiting it can't hang forever).
26
+ ready = new Promise((resolve, reject) => {
27
+ 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.
30
+ server.on('error', (err) => {
31
+ if (err.code === 'EADDRINUSE' && base && tries++ < 10) return server.listen(++port, host)
32
+ console.error(`[devtools] tap could not start: ${err.message}`)
33
+ reject(err)
34
+ })
25
35
  })
36
+ ready.catch(() => {}) // ready() may never be called — don't go unhandled
26
37
  server.on('listening', () => console.log(banner(host, server.address().port)))
27
38
  server.listen(port, host)
28
39
  },
29
40
  ready() {
30
- return new Promise((resolve, reject) => {
31
- if (!server) return reject(new Error('accept() not called'))
32
- if (server.listening) return resolve({ port: server.address().port })
33
- server.once('listening', () => resolve({ port: server.address().port }))
34
- })
41
+ if (!server) return Promise.reject(new Error('accept() not called'))
42
+ return ready
35
43
  },
36
44
  get port() {
37
45
  return server?.listening ? server.address().port : null
@@ -1,19 +1,25 @@
1
+ /**
2
+ * @typedef {object} Query Opaque query filter passed to the server.
3
+ */
4
+ /**
5
+ * @typedef {Record<string, unknown>} Handle A handle descriptor returned by the server.
6
+ */
1
7
  /**
2
8
  * Consumer SDK for a tap server reached over a local Duplex `stream`. Returns
3
9
  * a session exposing read methods (`handles`/`get`/`count`) and stream methods
4
10
  * (`watch`/`events`/`stats`). Stream methods return a streamx Readable that
5
11
  * cancels its server-side source when destroyed.
6
12
  *
7
- * @param {any} stream A streamx Duplex connected to a tap server.
8
- * @returns {Promise<{ handles(): Promise<any>, get(ref: string, query?: any, handleId?: string): Promise<any>, count(ref: string, query?: any, handleId?: string): Promise<any>, watch(ref: string, query?: any, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
13
+ * @param {object} stream A streamx Duplex connected to a tap server.
14
+ * @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 }>}
9
15
  */
10
- export function connect(stream: any): Promise<{
11
- handles(): Promise<any>;
12
- get(ref: string, query?: any, handleId?: string): Promise<any>;
13
- count(ref: string, query?: any, handleId?: string): Promise<any>;
14
- watch(ref: string, query?: any, handleId?: string): any;
15
- events(): any;
16
- stats(): any;
16
+ export function connect(stream: object): Promise<{
17
+ handles(): Promise<Handle[]>;
18
+ get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
19
+ count(ref: string, query?: Query, handleId?: string): Promise<number>;
20
+ watch(ref: string, query?: Query, handleId?: string): import("streamx").Readable;
21
+ events(): import("streamx").Readable;
22
+ stats(): import("streamx").Readable;
17
23
  close(): void;
18
24
  }>;
19
25
  export class Session {
@@ -23,16 +29,70 @@ export class Session {
23
29
  streams: Map<any, any>;
24
30
  seq: number;
25
31
  wire: Framed;
32
+ _onClose(): void;
26
33
  _onMessage(msg: any): void;
27
34
  _newId(): number;
28
35
  _request(method: any, fields: any): Promise<any>;
29
- _stream(method: any, fields: any): any;
30
- handles(): Promise<any>;
31
- get(ref: any, query: any, handleId: any): Promise<any>;
32
- count(ref: any, query: any, handleId: any): Promise<any>;
33
- watch(ref: any, query: any, handleId: any): any;
34
- events(): any;
35
- stats(): any;
36
+ _stream(method: any, fields: any): Readable<import("streamx").ReadableEvents>;
37
+ /**
38
+ * Lists the handles exposed by the server.
39
+ *
40
+ * @returns {Promise<Handle[]>} Resolves to the handle descriptors.
41
+ */
42
+ handles(): Promise<Handle[]>;
43
+ /**
44
+ * Reads the current value for `ref`.
45
+ *
46
+ * @param {string} ref Reference to read.
47
+ * @param {Query} [query] Optional query filter.
48
+ * @param {string} [handleId] Optional handle to scope the read.
49
+ * @returns {Promise<unknown>} Resolves to the value.
50
+ */
51
+ get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
52
+ /**
53
+ * Counts entries matching `ref`.
54
+ *
55
+ * @param {string} ref Reference to count.
56
+ * @param {Query} [query] Optional query filter.
57
+ * @param {string} [handleId] Optional handle to scope the count.
58
+ * @returns {Promise<number>} Resolves to the count.
59
+ */
60
+ count(ref: string, query?: Query, handleId?: string): Promise<number>;
61
+ /**
62
+ * Watches `ref` for changes, emitting frames as they arrive.
63
+ *
64
+ * @param {string} ref Reference to watch.
65
+ * @param {Query} [query] Optional query filter.
66
+ * @param {string} [handleId] Optional handle to scope the watch.
67
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
68
+ */
69
+ watch(ref: string, query?: Query, handleId?: string): import("streamx").Readable;
70
+ /**
71
+ * Streams server events.
72
+ *
73
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
74
+ */
75
+ events(): import("streamx").Readable;
76
+ /**
77
+ * Streams server stats.
78
+ *
79
+ * @returns {import('streamx').Readable} Cancels its server-side source when destroyed.
80
+ */
81
+ stats(): import("streamx").Readable;
82
+ /**
83
+ * Closes the session by ending the underlying stream.
84
+ *
85
+ * @returns {void}
86
+ */
36
87
  close(): void;
37
88
  }
89
+ /**
90
+ * Opaque query filter passed to the server.
91
+ */
92
+ export type Query = object;
93
+ /**
94
+ * A handle descriptor returned by the server.
95
+ */
96
+ export type Handle = Record<string, unknown>;
38
97
  import { Framed } from './protocol.js';
98
+ import { Readable } from 'streamx';
@@ -8,5 +8,10 @@ export class Framed {
8
8
  onMessage: any;
9
9
  buf: any;
10
10
  _onData(chunk: any): void;
11
- send(obj: any): void;
11
+ /**
12
+ * Encode `obj` to wire form and write it as one length-prefixed frame.
13
+ * @param {object} obj - message to send
14
+ * @returns {void}
15
+ */
16
+ send(obj: object): void;
12
17
  }
package/types/server.d.ts CHANGED
@@ -1,24 +1,29 @@
1
+ /**
2
+ * A decoded request frame. Carries the correlation `id` and `method`, plus the
3
+ * per-method fields a handler reads: `ref`, `handleId`, `query`, `cancelId`.
4
+ * @typedef {{ id?: string, method?: string, ref?: string, handleId?: string, query?: object, cancelId?: string }} ReqFrame
5
+ */
1
6
  /**
2
7
  * Read-only inspection server over a local Duplex `stream`. Serves the live
3
8
  * handle tree rooted at `me`, exposing only MAIN refs declared in each
4
9
  * handle's `spec.meta.refs` — local secret refs (master/keypair/
5
10
  * handle-keypairs) are never reachable, since they live in `meta.local.refs`.
6
11
  *
7
- * @param {any} stream A streamx Duplex carrying length-prefixed JSON frames.
8
- * @param {any} me The live root cero handle.
9
- * @param {{ events?: { snapshot(): any, subscribe(fn: (e: any) => void): () => void }, stats?: { snapshot(): any, subscribe(fn: (s: any) => void): () => void }, redact?: (ref: string, row: any) => any }} [opts]
12
+ * @param {object} stream A streamx Duplex carrying length-prefixed JSON frames.
13
+ * @param {object} me The live root cero handle.
14
+ * @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]
10
15
  * @returns {{ close(): void }}
11
16
  */
12
- export function serve(stream: any, me: any, opts?: {
17
+ export function serve(stream: object, me: object, opts?: {
13
18
  events?: {
14
- snapshot(): any;
15
- subscribe(fn: (e: any) => void): () => void;
19
+ snapshot(): unknown;
20
+ subscribe(fn: (e: object) => void): () => void;
16
21
  };
17
22
  stats?: {
18
- snapshot(): any;
19
- subscribe(fn: (s: any) => void): () => void;
23
+ snapshot(): unknown;
24
+ subscribe(fn: (s: object) => void): () => void;
20
25
  };
21
- redact?: (ref: string, row: any) => any;
26
+ redact?: (ref: string, row: Record<string, unknown>) => Record<string, unknown>;
22
27
  }): {
23
28
  close(): void;
24
29
  };
@@ -31,20 +36,76 @@ export class TapServer {
31
36
  tracked: Map<any, any>;
32
37
  wire: Framed;
33
38
  _cleanup: () => void;
34
- onRequest(req: any): Promise<void>;
35
- handles(req: any): void;
36
- get(req: any): Promise<void>;
37
- count(req: any): Promise<void>;
38
- watch(req: any): void;
39
- events(req: any): void;
40
- stats(req: any): void;
41
- cancel(req: any): void;
39
+ /**
40
+ * Dispatch an inbound request frame to its named method handler.
41
+ * @param {ReqFrame} req A decoded request frame, expected to carry `id` and `method`.
42
+ * @returns {Promise<void>}
43
+ */
44
+ onRequest(req: ReqFrame): Promise<void>;
45
+ /**
46
+ * Reply with the root handle and its direct children as `{ id, type }` rows.
47
+ * @param {ReqFrame} req A request frame carrying `id`.
48
+ * @returns {void}
49
+ */
50
+ handles(req: ReqFrame): void;
51
+ /**
52
+ * Read a ref once and reply with the redacted result.
53
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
54
+ * @returns {Promise<void>}
55
+ */
56
+ get(req: ReqFrame): Promise<void>;
57
+ /**
58
+ * Count rows for a ref and reply with the total.
59
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
60
+ * @returns {Promise<void>}
61
+ */
62
+ count(req: ReqFrame): Promise<void>;
63
+ /**
64
+ * Stream redacted live updates for a ref until cancelled or the stream ends.
65
+ * @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
66
+ * @returns {void}
67
+ */
68
+ watch(req: ReqFrame): void;
69
+ /**
70
+ * Stream the events source snapshot then live events.
71
+ * @param {ReqFrame} req A request frame carrying `id`.
72
+ * @returns {void}
73
+ */
74
+ events(req: ReqFrame): void;
75
+ /**
76
+ * Stream the stats source snapshot then live stats.
77
+ * @param {ReqFrame} req A request frame carrying `id`.
78
+ * @returns {void}
79
+ */
80
+ stats(req: ReqFrame): void;
81
+ /**
82
+ * Stop a tracked stream by id and release its resources.
83
+ * @param {ReqFrame} req A request frame carrying `cancelId`.
84
+ * @returns {void}
85
+ */
86
+ cancel(req: ReqFrame): void;
42
87
  _resolveRef(req: any): any;
43
88
  _source(req: any, src: any): void;
44
89
  _track(id: any, off: any): void;
45
90
  _drop(id: any): void;
46
91
  _send(obj: any): void;
47
92
  _teardown(): void;
93
+ /**
94
+ * Tear down all tracked streams and destroy the underlying stream.
95
+ * @returns {void}
96
+ */
48
97
  close(): void;
49
98
  }
99
+ /**
100
+ * A decoded request frame. Carries the correlation `id` and `method`, plus the
101
+ * per-method fields a handler reads: `ref`, `handleId`, `query`, `cancelId`.
102
+ */
103
+ export type ReqFrame = {
104
+ id?: string;
105
+ method?: string;
106
+ ref?: string;
107
+ handleId?: string;
108
+ query?: object;
109
+ cancelId?: string;
110
+ };
50
111
  import { Framed } from './protocol.js';
package/types/tap.d.ts CHANGED
@@ -1,3 +1,16 @@
1
+ /**
2
+ * An applied-op event fed into the ring buffer. `op` is the dispatch verb
3
+ * prefix, `name` the ref name, `row` the decoded value, `writerKey` the source
4
+ * writer's key and `seq` a monotonic apply counter. After redaction `row` is
5
+ * replaced with its masked copy; the rest is spread through unchanged.
6
+ *
7
+ * @typedef {{ op: string, name: string, row: Record<string, unknown>, writerKey: Buffer, seq: number }} OpEvent
8
+ */
9
+ /**
10
+ * A periodic `stats(me)` sample. See `stats()` for the field meanings.
11
+ *
12
+ * @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
13
+ */
1
14
  /**
2
15
  * `cero.use(devtools())` tap extension. Bound to the root handle's lifecycle,
3
16
  * it feeds every applied op into a bounded ring buffer, samples `stats(me)` on
@@ -5,22 +18,55 @@
5
18
  * consumers. By default it serves a loopback TCP server on `port` (9111); pass
6
19
  * a custom `transport` to serve it some other way. Nothing touches the app swarm.
7
20
  *
8
- * @param {{ port?: number, host?: string, bufferSize?: number, sampleInterval?: number, redact?: ((ref: string, row: any) => any) | { fields?: string[], match?: Function, deny?: RegExp | false }, transport?: { accept(handler: (stream: any) => void): void } }} [opts]
9
- * @returns {{ setup(me: any): () => void }}
21
+ * @param {{ port?: number, host?: string, 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]
22
+ * @returns {{ setup(me: object): () => void }}
10
23
  */
11
24
  export function devtools(opts?: {
12
25
  port?: number;
13
26
  host?: string;
14
27
  bufferSize?: number;
15
28
  sampleInterval?: number;
16
- redact?: ((ref: string, row: any) => any) | {
29
+ redact?: ((ref: string, row: Record<string, unknown>) => Record<string, unknown>) | {
17
30
  fields?: string[];
18
- match?: Function;
31
+ match?: (key: string, value: unknown, path: string) => boolean;
19
32
  deny?: RegExp | false;
20
33
  };
21
34
  transport?: {
22
- accept(handler: (stream: any) => void): void;
35
+ accept(handler: (stream: object) => void): void;
23
36
  };
24
37
  }): {
25
- setup(me: any): () => void;
38
+ setup(me: object): () => void;
39
+ };
40
+ /**
41
+ * An applied-op event fed into the ring buffer. `op` is the dispatch verb
42
+ * prefix, `name` the ref name, `row` the decoded value, `writerKey` the source
43
+ * writer's key and `seq` a monotonic apply counter. After redaction `row` is
44
+ * replaced with its masked copy; the rest is spread through unchanged.
45
+ */
46
+ export type OpEvent = {
47
+ op: string;
48
+ name: string;
49
+ row: Record<string, unknown>;
50
+ writerKey: Buffer;
51
+ seq: number;
52
+ };
53
+ /**
54
+ * A periodic `stats(me)` sample. See `stats()` for the field meanings.
55
+ */
56
+ export type StatsSample = {
57
+ handleId: string;
58
+ network: {
59
+ connections: number;
60
+ peers: number;
61
+ dht: object | null;
62
+ };
63
+ bee: {
64
+ local: number;
65
+ };
66
+ cores: Array<{
67
+ length: number;
68
+ byteLength: number;
69
+ peers: number;
70
+ }>;
71
+ at: number;
26
72
  };