@cero-base/tools 2.0.0 → 2.1.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/README.md +5 -4
- package/package.json +2 -2
- package/src/connect.js +1 -13
- package/src/server.js +2 -12
- package/src/tap.js +4 -4
- package/types/connect.d.ts +1 -11
- package/types/server.d.ts +0 -6
- package/types/tap.d.ts +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Passive devtools for [cero](https://www.npmjs.com/package/@cero-base/cero) — observe a running instance's **data**, its **event log**, and its **p2p/replication stats** from another process, without ever touching the swarm it measures.
|
|
4
4
|
|
|
5
|
-
A `
|
|
5
|
+
A `devtools()` extension taps the instance over a **local out-of-band pipe** (never the app's hyperswarm), so connection counts, core lengths, and replication numbers stay exactly as they'd be with no devtools attached. Read-only by construction; identity secrets are structurally unreachable.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -16,7 +16,9 @@ npm install @cero-base/tools
|
|
|
16
16
|
import { cero } from '@cero-base/cero'
|
|
17
17
|
import { devtools, loopback } from '@cero-base/tools'
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const me = await cero('./data', spec, {
|
|
20
|
+
extensions: [...spec.extensions, devtools({ transport: loopback({ port: 9111 }) })]
|
|
21
|
+
})
|
|
20
22
|
// ...then create your instance as usual; the tap follows it and every child handle.
|
|
21
23
|
```
|
|
22
24
|
|
|
@@ -46,7 +48,6 @@ const session = await connect(dial({ port: 9111 }))
|
|
|
46
48
|
|
|
47
49
|
await session.handles() // [{ id, type }, ...] — root + open children
|
|
48
50
|
await session.get('messages') // { data, total, size } — reuses cero's read operators
|
|
49
|
-
await session.count('members') // number
|
|
50
51
|
session.watch('messages') // Readable of live snapshots
|
|
51
52
|
session.events() // Readable of { op, name, row, writerKey, seq } — local AND remote
|
|
52
53
|
session.stats() // Readable of { network, bee, cores }
|
|
@@ -82,7 +83,7 @@ Identity credentials (the seed and keypairs) need no redaction: they're `local`
|
|
|
82
83
|
|
|
83
84
|
## Status
|
|
84
85
|
|
|
85
|
-
MVP: local-pipe transport, `get`/`watch
|
|
86
|
+
MVP: local-pipe transport, `get`/`watch` + events + sampled stats, redaction, a CLI. Deferred to later phases: a whitelisted swarm transport, a read-only replication / time-travel plane, and an MCP/UI consumer.
|
|
86
87
|
|
|
87
88
|
## License
|
|
88
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cero-base/tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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
6
|
"sideEffects": false,
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"test:node": "find test -name '*.test.js' | sort | xargs -P1 -n1 brittle-node"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@cero-base/cero": "^2.
|
|
78
|
+
"@cero-base/cero": "^2.1.1",
|
|
79
79
|
"b4a": "^1.8.1",
|
|
80
80
|
"bare-crypto": "^1.15.3",
|
|
81
81
|
"bare-net": "^2.3.3",
|
package/src/connect.js
CHANGED
|
@@ -14,7 +14,7 @@ import { Framed } from './protocol.js'
|
|
|
14
14
|
* Consumer SDK for a tap server reached over a local Duplex `stream`.
|
|
15
15
|
*
|
|
16
16
|
* @param {object} stream A streamx Duplex connected to a tap server.
|
|
17
|
-
* @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>,
|
|
17
|
+
* @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>, watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable, events(): import('streamx').Readable, stats(): import('streamx').Readable, close(): void }>}
|
|
18
18
|
*/
|
|
19
19
|
export async function connect(stream, { token } = {}) {
|
|
20
20
|
return new Session(stream, { token })
|
|
@@ -53,18 +53,6 @@ export class Session {
|
|
|
53
53
|
return this._request('get', { ref, query, handleId })
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* Counts entries matching `ref`.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} ref Reference to count.
|
|
60
|
-
* @param {Query} [query] Optional query filter.
|
|
61
|
-
* @param {string} [handleId] Optional handle to scope the count.
|
|
62
|
-
* @returns {Promise<number>} Resolves to the count.
|
|
63
|
-
*/
|
|
64
|
-
count(ref, query, handleId) {
|
|
65
|
-
return this._request('count', { ref, query, handleId })
|
|
66
|
-
}
|
|
67
|
-
|
|
68
56
|
/**
|
|
69
57
|
* Watches `ref` for changes, emitting frames as they arrive.
|
|
70
58
|
*
|
package/src/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { get,
|
|
1
|
+
import { get, watch } from '@cero-base/cero'
|
|
2
2
|
|
|
3
3
|
import { Framed } from './protocol.js'
|
|
4
4
|
|
|
@@ -93,16 +93,6 @@ export class TapServer {
|
|
|
93
93
|
this._send({ id: req.id, ok: true, data: { ...r, data } })
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
/**
|
|
97
|
-
* Count rows for a ref and reply with the total.
|
|
98
|
-
* @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
|
-
*/
|
|
101
|
-
async count(req) {
|
|
102
|
-
const ref = this._resolveRef(req)
|
|
103
|
-
this._send({ id: req.id, ok: true, data: (await count(ref, req.query)).data })
|
|
104
|
-
}
|
|
105
|
-
|
|
106
96
|
/**
|
|
107
97
|
* Stream redacted live updates for a ref until cancelled or the stream ends.
|
|
108
98
|
* @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
|
|
@@ -205,7 +195,7 @@ export class TapServer {
|
|
|
205
195
|
}
|
|
206
196
|
}
|
|
207
197
|
|
|
208
|
-
const METHODS = new Set(['handles', 'get', '
|
|
198
|
+
const METHODS = new Set(['handles', 'get', 'watch', 'events', 'stats', 'cancel'])
|
|
209
199
|
|
|
210
200
|
class CodeError extends Error {
|
|
211
201
|
constructor(code, message) {
|
package/src/tap.js
CHANGED
|
@@ -18,7 +18,7 @@ import { loopback } from './transport.js'
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* `
|
|
21
|
+
* The `devtools()` tap extension. Bound to the root handle's lifecycle, it feeds
|
|
22
22
|
* every applied op into a bounded ring buffer, samples `stats(me)` on an interval, and
|
|
23
23
|
* serves a read-only inspection.
|
|
24
24
|
*
|
|
@@ -40,9 +40,9 @@ export function devtools(opts = {}) {
|
|
|
40
40
|
const servers = new Set()
|
|
41
41
|
|
|
42
42
|
const follow = (handle) => {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
)
|
|
43
|
+
const push = (e) => events.push(redactor ? { ...e, row: redactor(e.name, e.row) } : e)
|
|
44
|
+
handle.store.on('apply', push)
|
|
45
|
+
const off = () => handle.store.off('apply', push)
|
|
46
46
|
offs.push(off)
|
|
47
47
|
if (handle !== me) handle.once('close', off)
|
|
48
48
|
}
|
package/types/connect.d.ts
CHANGED
|
@@ -12,12 +12,11 @@ export type Handle = Record<string, unknown>;
|
|
|
12
12
|
* Consumer SDK for a tap server reached over a local Duplex `stream`.
|
|
13
13
|
*
|
|
14
14
|
* @param {object} stream A streamx Duplex connected to a tap server.
|
|
15
|
-
* @returns {Promise<{ handles(): Promise<Handle[]>, get(ref: string, query?: Query, handleId?: string): Promise<unknown>,
|
|
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
17
|
export declare function connect(stream: object, { token }?: {}): Promise<{
|
|
18
18
|
handles(): Promise<Handle[]>;
|
|
19
19
|
get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
|
|
20
|
-
count(ref: string, query?: Query, handleId?: string): Promise<number>;
|
|
21
20
|
watch(ref: string, query?: Query, handleId?: string): import('streamx').Readable;
|
|
22
21
|
events(): import('streamx').Readable;
|
|
23
22
|
stats(): import('streamx').Readable;
|
|
@@ -46,15 +45,6 @@ export declare class Session {
|
|
|
46
45
|
* @returns {Promise<unknown>} Resolves to the value.
|
|
47
46
|
*/
|
|
48
47
|
get(ref: string, query?: Query, handleId?: string): Promise<unknown>;
|
|
49
|
-
/**
|
|
50
|
-
* Counts entries matching `ref`.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} ref Reference to count.
|
|
53
|
-
* @param {Query} [query] Optional query filter.
|
|
54
|
-
* @param {string} [handleId] Optional handle to scope the count.
|
|
55
|
-
* @returns {Promise<number>} Resolves to the count.
|
|
56
|
-
*/
|
|
57
|
-
count(ref: string, query?: Query, handleId?: string): Promise<number>;
|
|
58
48
|
/**
|
|
59
49
|
* Watches `ref` for changes, emitting frames as they arrive.
|
|
60
50
|
*
|
package/types/server.d.ts
CHANGED
|
@@ -61,12 +61,6 @@ export declare class TapServer {
|
|
|
61
61
|
* @returns {Promise<void>}
|
|
62
62
|
*/
|
|
63
63
|
get(req: ReqFrame): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Count rows for a ref and reply with the total.
|
|
66
|
-
* @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
|
|
67
|
-
* @returns {Promise<void>}
|
|
68
|
-
*/
|
|
69
|
-
count(req: ReqFrame): Promise<void>;
|
|
70
64
|
/**
|
|
71
65
|
* Stream redacted live updates for a ref until cancelled or the stream ends.
|
|
72
66
|
* @param {ReqFrame} req A request frame carrying `id`, `ref`, `handleId` and `query`.
|
package/types/tap.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type StatsSample = {
|
|
|
33
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
|
|
34
34
|
*/
|
|
35
35
|
/**
|
|
36
|
-
* `
|
|
36
|
+
* The `devtools()` tap extension. Bound to the root handle's lifecycle, it feeds
|
|
37
37
|
* every applied op into a bounded ring buffer, samples `stats(me)` on an interval, and
|
|
38
38
|
* serves a read-only inspection.
|
|
39
39
|
*
|