@cero-base/tools 1.19.0 → 2.0.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 +5 -6
- package/src/connect.js +61 -65
- package/src/protocol.js +18 -19
- package/src/redact.js +3 -6
- package/src/server.js +12 -16
- package/src/stats.js +1 -4
- package/src/tap.js +5 -11
- package/src/transport.js +3 -8
- package/types/connect.d.ts +7 -10
- package/types/protocol.d.ts +1 -1
- package/types/redact.d.ts +3 -5
- package/types/server.d.ts +6 -9
- package/types/stats.d.ts +1 -4
- package/types/tap.d.ts +4 -9
- package/types/transport.d.ts +2 -3
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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": ">=
|
|
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
|
|
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": "^
|
|
78
|
+
"@cero-base/cero": "^2.0.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,10 +11,7 @@ import { Framed } from './protocol.js'
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Consumer SDK for a tap server reached over a local Duplex `stream`.
|
|
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
17
|
* @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 }>}
|
|
@@ -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
|
*
|
|
@@ -167,6 +103,66 @@ export class Session {
|
|
|
167
103
|
close() {
|
|
168
104
|
this.stream.end()
|
|
169
105
|
}
|
|
106
|
+
|
|
107
|
+
// fail in-flight requests and end live streams
|
|
108
|
+
_onclose() {
|
|
109
|
+
for (const { reject } of this.pending.values()) {
|
|
110
|
+
reject(new TapError('connection closed', 'CLOSED'))
|
|
111
|
+
}
|
|
112
|
+
this.pending.clear()
|
|
113
|
+
for (const r of this.streams.values()) r.push(null)
|
|
114
|
+
this.streams.clear()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_onmessage(msg) {
|
|
118
|
+
if ('frame' in msg || msg.end) {
|
|
119
|
+
const r = this.streams.get(msg.id)
|
|
120
|
+
if (!r) return
|
|
121
|
+
if (msg.end) {
|
|
122
|
+
this.streams.delete(msg.id)
|
|
123
|
+
r.push(null)
|
|
124
|
+
} else {
|
|
125
|
+
r.push(msg.frame)
|
|
126
|
+
}
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
const p = this.pending.get(msg.id)
|
|
130
|
+
if (!p) return
|
|
131
|
+
this.pending.delete(msg.id)
|
|
132
|
+
if (msg.ok === false) p.reject(new TapError(msg.error, msg.code))
|
|
133
|
+
else p.resolve(msg.data)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_newId() {
|
|
137
|
+
return ++this.seq
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_send(frame) {
|
|
141
|
+
this.wire.send(this.token ? { token: this.token, ...frame } : frame)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_request(method, fields) {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const id = this._newId()
|
|
147
|
+
this.pending.set(id, { resolve, reject })
|
|
148
|
+
this._send({ id, method, ...fields })
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_stream(method, fields) {
|
|
153
|
+
const id = this._newId()
|
|
154
|
+
const r = new Readable({
|
|
155
|
+
destroy: (cb) => {
|
|
156
|
+
if (this.streams.delete(id)) {
|
|
157
|
+
this._send({ id: this._newId(), method: 'cancel', cancelId: id })
|
|
158
|
+
}
|
|
159
|
+
cb(null)
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
this.streams.set(id, r)
|
|
163
|
+
this._send({ id, method, ...fields })
|
|
164
|
+
return r
|
|
165
|
+
}
|
|
170
166
|
}
|
|
171
167
|
|
|
172
168
|
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
|
-
//
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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
|
@@ -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`.
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
@@ -155,6 +151,15 @@ export class TapServer {
|
|
|
155
151
|
this._drop(req.cancelId)
|
|
156
152
|
}
|
|
157
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Tear down all tracked streams and destroy the underlying stream.
|
|
156
|
+
* @returns {void}
|
|
157
|
+
*/
|
|
158
|
+
close() {
|
|
159
|
+
this._teardown()
|
|
160
|
+
this.stream.destroy()
|
|
161
|
+
}
|
|
162
|
+
|
|
158
163
|
_resolveRef(req) {
|
|
159
164
|
const me = this.me
|
|
160
165
|
const handle =
|
|
@@ -198,15 +203,6 @@ export class TapServer {
|
|
|
198
203
|
for (const off of this.tracked.values()) off()
|
|
199
204
|
this.tracked.clear()
|
|
200
205
|
}
|
|
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
206
|
}
|
|
211
207
|
|
|
212
208
|
const METHODS = new Set(['handles', 'get', 'count', 'watch', 'events', 'stats', 'cancel'])
|
package/src/stats.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Read-only snapshot of a handle's existing p2p/storage counters.
|
|
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.
|
|
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
|
-
*
|
|
26
|
-
*
|
|
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
|
+
* `cero.use(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
|
|
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 =
|
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
|
-
*
|
|
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
|
-
//
|
|
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`
|
package/types/connect.d.ts
CHANGED
|
@@ -9,10 +9,7 @@ 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`.
|
|
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
15
|
* @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 }>}
|
|
@@ -34,12 +31,6 @@ export declare class Session {
|
|
|
34
31
|
seq: number;
|
|
35
32
|
wire: Framed;
|
|
36
33
|
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
34
|
/**
|
|
44
35
|
* Lists the handles exposed by the server.
|
|
45
36
|
*
|
|
@@ -91,4 +82,10 @@ export declare class Session {
|
|
|
91
82
|
* @returns {void}
|
|
92
83
|
*/
|
|
93
84
|
close(): void;
|
|
85
|
+
_onclose(): void;
|
|
86
|
+
_onmessage(msg: any): void;
|
|
87
|
+
_newId(): number;
|
|
88
|
+
_send(frame: any): void;
|
|
89
|
+
_request(method: any, fields: any): Promise<any>;
|
|
90
|
+
_stream(method: any, fields: any): Readable<import("streamx").ReadableEvents>;
|
|
94
91
|
}
|
package/types/protocol.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
4
|
-
*
|
|
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`.
|
|
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.
|
|
@@ -94,15 +91,15 @@ export declare class TapServer {
|
|
|
94
91
|
* @returns {void}
|
|
95
92
|
*/
|
|
96
93
|
cancel(req: ReqFrame): void;
|
|
94
|
+
/**
|
|
95
|
+
* Tear down all tracked streams and destroy the underlying stream.
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
close(): void;
|
|
97
99
|
_resolveRef(req: any): any;
|
|
98
100
|
_source(req: any, src: any): void;
|
|
99
101
|
_track(id: any, off: any): void;
|
|
100
102
|
_drop(id: any): void;
|
|
101
103
|
_send(obj: any): void;
|
|
102
104
|
_teardown(): void;
|
|
103
|
-
/**
|
|
104
|
-
* Tear down all tracked streams and destroy the underlying stream.
|
|
105
|
-
* @returns {void}
|
|
106
|
-
*/
|
|
107
|
-
close(): void;
|
|
108
105
|
}
|
package/types/stats.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Read-only snapshot of a handle's existing p2p/storage counters.
|
|
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.
|
|
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
|
-
*
|
|
41
|
-
*
|
|
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
|
+
* `cero.use(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 }}
|
package/types/transport.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Loopback TCP transport implementing the tap `{ accept(handler) }` contract
|
|
3
|
-
*
|
|
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 }}
|