ave-common
v0.9.0
Published
TypeScript types for the Averiun Ledger API
Maintainers
Readme
ave-common
TypeScript type definitions for the Averiun Ledger API.
Auto-generated from Rust source code using ts-rs, keeping backend types and frontend interfaces aligned from the same source model.
Installation
npm install ave-commonCurrent package version: 0.9.0.
Usage
import type {
BridgeSignedEventRequest,
BridgeEventRequest,
BridgeCreateRequest,
SubjectDB,
RequestState,
LedgerDB
} from "ave-common";
// Example: Create event request
const createRequest: BridgeEventRequest = {
event: "create",
data: {
name: "My Subject",
description: "Subject description",
governance_id: "EqDbWS...",
schema_id: "governance",
namespace: ["example", "namespace"]
}
};
// Example: Signed request
const signedRequest: BridgeSignedEventRequest = {
request: createRequest,
signature: {
signer: "EqCxN...",
timestamp: 1234567890,
value: "EqD8z...",
content_hash: "EqBqK..."
}
};Available Types
Request Types
BridgeSignedEventRequest- Wrapper for signed event requestsBridgeEventRequest- Event request (tagged union)BridgeCreateRequest- Create a new subjectBridgeFactRequest- Add facts to a subjectBridgeTransferRequest- Transfer subject ownershipBridgeConfirmRequest- Confirm a transferBridgeRejectRequest- Reject a transferBridgeEOLRequest- Mark subject as end-of-lifeEventRequestType- Enum of event types:"create" | "fact" | "transfer" | "confirm" | "reject" | "eol"
Response Types
SubjectDB- Subject database recordLedgerDB- Ledger event record with timestampsRequestState- Request processing state enumRequestEventDB- Database event representation (tagged union)RequestInfo- Request state and versionRequestInfoExtend- Request state and version with request IDRequestData- Request ID and subject ID pairSubjsData- Subject metadataGovsData- Governance metadataPaginator- Pagination metadataPaginatorEvents- Paginated ledger eventsPaginatorAborts- Paginated abort eventsAbortDB- Abort event recordEvalResDB- Evaluation resultRequestsInManager- Request manager stateRequestsInManagerSubject- Subject request queue state
Query Types
SubjectQuery- Filter subjects byactiveand/orschema_idGovQuery- Filter governances byactiveEventsQuery- Filter ledger events by time ranges, page, quantity, and event typeFirstEndEvents- Query for first/last events by type and quantityAbortsQuery- Filter abort events by request ID, sn, page, and quantityApprovalQuery- Filter approvals by stateTimeRange- ISO 8601 time range filter
Approval Types
ApprovalEntry- Approval request combined with its current stateApprovalReq- Approval request dataApprovalState- Approval status:"Pending" | "RespondedAccepted" | "RespondedRejected" | "Obsolete"ApprovalStateRes- Approval response state (excludes"Pending")
Other Types
BridgeSignature- Cryptographic signature with timestampTransferSubject- Transfer subject dataMonitorNetworkState- Network connectivity stateDataToSink- Event sink data (tagged union)DataToSinkEvent- Sink event types (create, fact, transfer, etc.)Namespace- Subject namespace (Array<string>)SchemaType- Schema type:"Governance" | { Type: string } | "TrackerSchemas"JsonValue- Recursive JSON value type
Type Notes
Tagged Unions
Event types use TypeScript discriminated unions matching Rust's serde tag/content serialization:
type BridgeEventRequest =
| { event: "create"; data: BridgeCreateRequest }
| { event: "fact"; data: BridgeFactRequest }
| { event: "transfer"; data: BridgeTransferRequest }
// ...Namespace
Namespace is an array of strings representing the hierarchical path of a subject:
const ns: Namespace = ["example", "namespace"]; // Array<string>Number for u64/i64
Rust u64 and i64 fields (timestamps, sequence numbers) map to TypeScript number for JavaScript compatibility:
const timestamp = 1234567890; // number
const sn = 42; // numberNote: The types are generated with TS_RS_LARGE_INT=number to ensure compatibility with JavaScript's number type instead of bigint.
Optional Fields
Rust Option<T> becomes T | null in TypeScript:
signature: BridgeSignature | nullDevelopment
Generating Types
To regenerate the TypeScript bindings from Rust source:
# From common/ts directory
npm run generate
# Or directly
bash generate.shThis will:
- Run cargo tests with the
typescriptfeature enabled - Export types to
src/directory using ts-rs - Generate a barrel
index.tsthat re-exports all types - Use
TS_RS_LARGE_INT=numberto map Rust u64/i64 to TypeScript number
Checking for Drift Without Committing Generated Files
If you do not want to version src/**/*.ts, compare a fresh local generation against the currently published npm package:
npm run check:published
# Optional: print normalized diffs for real API changes
bash check-published.sh --fullThat command:
- Generates bindings in a temporary directory
- Downloads
ave-common@<package.json version>from npm - Groups drift into
API changesvsdocs/comment changes only - Fails if the published package differs from the current Rust type surface
This keeps the repository clean while still telling you when the TypeScript package is stale.
Publishing Updates
When Rust types are modified:
# 1. Regenerate types
npm run generate
# 2. Bump version and publish
npm run release:patch # 0.3.3 -> 0.3.4
npm run release:minor # 0.3.3 -> 0.4.0
npm run release:major # 0.3.3 -> 1.0.0This will automatically:
- Regenerate the types
- Bump the package version
- Publish to npm with public access
License
AGPL-3.0-only
Links
- Averiun Ledger
- GitHub Repository
- API Documentation (coming soon)
Generated from Rust • Built with ts-rs
