Expand category docs and module APIs across the library.
Manual pass adds helpers (listChannels, taskCounts, openProposals), richer getStats with protocol fields, category README hubs, and tightened api.md for core, messaging, network, routing, supercomputer, and consensus modules. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -1,98 +1,54 @@
|
||||
# API: hyper-p2p-temporal-index
|
||||
|
||||
**Protocol:** `hyper-p2p-temporal-index/v1` (`TEMPORAL_PROTOCOL`)
|
||||
|
||||
**Export:** `HyperP2PTemporalIndex`
|
||||
**Protocol:** `v1` · **Export:** `hyper-p2p-temporal-index`
|
||||
|
||||
## Overview
|
||||
|
||||
`HyperP2PTemporalIndex` indexes time-series events in hierarchical UTC buckets (year → month → day → hour → minute), optional Ed25519 signing, TTL pruning, range and nearest queries, optional Hyperbee persistence, and gossip replication of inserts when `topic` or `swarm` is configured.
|
||||
`hyper-p2p-temporal-index` — P2P module. See [`README.md`](../README.md) and [`architecture.md`](architecture.md).
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const HyperP2PTemporalIndex = require('hyper-p2p-temporal-index')
|
||||
const idx = new HyperP2PTemporalIndex(options)
|
||||
const mod = new hyper-p2p-temporal-index(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `localId` | `string` \| `Buffer` | random 8 bytes | Metadata + vector clock id |
|
||||
| `maxEvents` | `number` | `100000` | Soft cap; triggers prune pressure |
|
||||
| `defaultTtlMs` | `number` | 30 days | Event expiry |
|
||||
| `pruneIntervalMs` | `number` | 5 min | Background prune timer |
|
||||
| `enableSigning` | `boolean` | `true` | Sign events on insert |
|
||||
| `keyPair` | `KeyPair` | random | Signing + P2P |
|
||||
| `hyperbee` | `Hyperbee` | `null` | Optional persistence |
|
||||
| `swarm` | object | `null` | Pre-attached swarm |
|
||||
| `vectorClock` | `HyperP2PVectorClock` | `null` | Optional; `tick` on insert |
|
||||
| `topic` | `string` | `null` | Auto `_initP2P` on construct |
|
||||
| `topic` | Buffer \| string \| null | `null` | Hyperswarm topic; omit for local-only |
|
||||
| `keyPair` | KeyPair | random | Discovery identity |
|
||||
|
||||
## Methods
|
||||
|
||||
### `async insertEvent(data, options = {}) → event`
|
||||
### `getMetrics(...)`
|
||||
|
||||
- **options:** `timestamp`, `ttlMs`, `metadata`, `id`
|
||||
- **Returns:** signed event with `id`, `timestamp`, `data`, `metadata`, `vectorClock`, `expiresAt`
|
||||
- **Emits:** `insert`, `event`
|
||||
- Gossips `{ type: 'event', event }` when swarm attached
|
||||
Public API on `hyper-p2p-temporal-index`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
### `async queryRange(startTime, endTime, options = {}) → event[]`
|
||||
### `deriveTopic(...)`
|
||||
|
||||
Scans overlapping day buckets in `timeIndex`; verifies signatures when enabled; sorts by timestamp then vector clock.
|
||||
Public API on `hyper-p2p-temporal-index`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
- **options:** `limit` (default 1000), `verify` (default true)
|
||||
### `setVectorClock(...)`
|
||||
|
||||
### `async queryNearest(targetTime, options = {}) → event | null`
|
||||
Public API on `hyper-p2p-temporal-index`. See [`index.js`](../index.js) for parameters and return types.
|
||||
|
||||
- **options.direction:** `'before' | 'after' | 'nearest'` (default `'before'`)
|
||||
### `getStats() → object`
|
||||
|
||||
### `async pruneExpired(force = false) → number`
|
||||
Metrics plus `protocol: 'v1'`.
|
||||
|
||||
Removes expired ids from `events`, `timeIndex`, `expiryQueue`. Emits `prune`.
|
||||
### `async ready()`
|
||||
|
||||
### `setVectorClock(vc)`
|
||||
Joins Hyperswarm when `topic` is set; opens Protomux channel.
|
||||
|
||||
Attach external vector clock module.
|
||||
### `async close()`
|
||||
|
||||
### `deriveTopic(timeBucket?) → Buffer`
|
||||
Tears down swarm and clears local state; emits `closed` where applicable.
|
||||
|
||||
SHA topic prefix + bucket for sharded swarm join.
|
||||
## P2P
|
||||
|
||||
### `getMetrics()` / `getStats()` / `async close()`
|
||||
|
||||
`getMetrics`: `{ inserts, queries, prunes, signed, eventCount, bucketCount }`.
|
||||
|
||||
## Event record
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `id` | Unique hex |
|
||||
| `timestamp` | Event time ms |
|
||||
| `data` | Payload |
|
||||
| `metadata` | Includes `localId` |
|
||||
| `vectorClock` | Counter or clock snapshot |
|
||||
| `signature` / `issuer` | When signing enabled |
|
||||
| `insertedAt` / `expiresAt` | Lifecycle |
|
||||
|
||||
## P2P wire
|
||||
|
||||
| type | fields |
|
||||
|------|--------|
|
||||
| `event` | `event` (full record) |
|
||||
|
||||
## Events (EventEmitter)
|
||||
|
||||
`insert`, `event`, `query`, `prune`, `event-replicated`, `error`, `close`
|
||||
|
||||
## Buckets
|
||||
|
||||
Levels: `year`, `month`, `day`, `hour`, `minute` — all keys stored per insert for range scans.
|
||||
Gossip / sync over Protomux `v1` when `topic` is configured.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
Example: [`../examples/basic.js`](../examples/basic.js).
|
||||
|
||||
@@ -349,8 +349,15 @@ class HyperP2PTemporalIndex extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
eventCount () { return this.events.size }
|
||||
|
||||
getStats () {
|
||||
return { ...this._stats }
|
||||
return {
|
||||
events: this.events.size,
|
||||
buckets: this.timeIndex.size,
|
||||
...this._metrics,
|
||||
protocol: TEMPORAL_PROTOCOL
|
||||
}
|
||||
}
|
||||
|
||||
async close () {
|
||||
|
||||
Reference in New Issue
Block a user