@enc-protocol/dataview — API Reference
@enc-protocol/dataview is the server-side projection of app state for clients. It provides a push receiver and HTTP client interface to query materialized views across enclaves, backed by protocol-layer state snapshots.
Installation
npm install @enc-protocol/dataviewDepends on @enc-protocol/core.
Package Structure
receiver.js — Push Receiver
The push receiver subscribes to app events from enclaves and materializes them into queryable views.
DataViewReceiver
import { DataViewReceiver } from '@enc-protocol/dataview/receiver.js'
const receiver = new DataViewReceiver(opts)Parameters:
| Parameter | Type | Description |
|---|---|---|
opts.appId | string | App identifier |
opts.enclaves | string[] | Enclave IDs to subscribe to |
opts.nodeUrl | string | Node URL for subscriptions |
opts.identity | Object | Identity for authentication |
.subscribe()
await receiver.subscribe() → Promise<void>Open subscriptions to all configured enclaves.
.on(event, handler)
receiver.on('event', (event) => { /* … */ })
receiver.on('error', (err) => { /* … */ })Register handlers for 'event' and 'error' events.
.ingest(event)
receiver.ingest(event: Object) → voidProcess an event and update materialized views.
.close()
receiver.close() → voidClose all subscriptions.
client.js — HTTP Client
Query dataviews over HTTP.
DataViewClient
import { DataViewClient } from '@enc-protocol/dataview/client.js'
const client = new DataViewClient(baseUrl)| Parameter | Type | Description |
|---|---|---|
baseUrl | string | Dataview HTTP endpoint |
.query(viewName, opts?)
client.query(viewName: string, opts?: Object) → Promise<Object[]>Query a materialized view.
Parameters:
| Parameter | Type | Description |
|---|---|---|
viewName | string | Name of the view (e.g., 'profiles', 'feed') |
opts.limit | number | Max rows to return |
opts.reverse | boolean | Reverse order |
opts.filter | Object | Optional key-value filters |
Returns: Array of view rows (each row includes from, _enclave, _event_id, _timestamp).
const profiles = await client.query('profiles', { limit: 100 })
for (const row of profiles) {
console.log(row.id_pub, row.name, row._enclave)
}.getStatus()
client.getStatus() → Promise<Object>Get dataview health and sync status.
Returns:
{
status: 'healthy' | 'syncing' | 'error',
synced_enclave_count: number,
total_enclaves: number,
last_event_timestamp: number,
}base-dataview.js — Base Class
Abstract base for implementing custom dataviews.
BaseDataView
import { BaseDataView } from '@enc-protocol/dataview/base-dataview.js'
class MyDataView extends BaseDataView {
async ingest(event) {
// Process event and update views
}
async query(viewName, opts) {
// Return materialized rows
}
}Methods to override
async ingest(event)
Called when a new event arrives.
async ingest(event: Object) → voidUpdate internal materialized views based on the event type and content.
async query(viewName, opts)
Query a view.
async query(viewName: string, opts?: Object) → Object[]Example: Personal SDK with DataView
import { DataViewClient } from '@enc-protocol/dataview/client.js'
import { createIdentity } from '@enc-protocol/client'
// Query profiles materialized from Personal enclaves
const dataview = new DataViewClient('https://dv.example.com')
// List all profiles
const profiles = await dataview.query('profiles', { limit: 50 })
for (const p of profiles) {
console.log(p.name, p.id_pub)
}
// Check dataview sync status
const status = await dataview.getStatus()
console.log(`Synced ${status.synced_enclave_count}/${status.total_enclaves} enclaves`)See also
@enc-protocol/core— protocol primitives@enc-protocol/app-sdk-base— app SDK base classes- App SDKs — per-app dataview bindings