Pure TypeScript SDK for the Hyperstack Solana streaming platform
npm install hyperstack-typescriptPure TypeScript SDK for the Hyperstack Solana streaming platform. Framework-agnostic core with AsyncIterable-based streaming.
``bash`
npm install hyperstack-typescript
`typescript
import { HyperStack } from 'hyperstack-typescript';
import { SETTLEMENT_GAME_STACK } from './generated/settlement-game-stack';
const hs = await HyperStack.connect('wss://mainnet.hyperstack.xyz', {
stack: SETTLEMENT_GAME_STACK,
});
`
`typescript
for await (const update of hs.views.settlementGame.list.watch()) {
if (update.type === 'upsert') {
console.log('Game updated:', update.key, update.data);
} else if (update.type === 'delete') {
console.log('Game deleted:', update.key);
}
}
for await (const update of hs.views.settlementGame.state.watch('game-123')) {
console.log('Game 123 updated:', update.data);
}
for await (const update of hs.views.settlementGame.list.watchRich()) {
if (update.type === 'updated') {
console.log('Changed from:', update.before);
console.log('Changed to:', update.after);
}
}
`
`typescript
const games = await hs.views.settlementGame.list.get();
const game = await hs.views.settlementGame.state.get('game-123');
`
`typescript
console.log(hs.connectionState);
const unsubscribe = hs.onConnectionStateChange((state) => {
console.log('Connection state:', state);
});
await hs.disconnect();
`
Main client class with typed view accessors.
- HyperStack.connect(url, options) - Connect to a HyperStack serverviews
- - Typed view accessors based on your stack definitionconnectionState
- - Current connection stateonConnectionStateChange(callback)
- - Listen for connection changesdisconnect()
- - Disconnect from the server
Each view provides:
StateView (keyed entities)
- watch(key) - AsyncIterable of updates for a specific keywatchRich(key)
- - AsyncIterable with before/after diffsget(key)
- - Get entity by keygetSync(key)
- - Get entity synchronously (if available)
ListView (collections)
- watch() - AsyncIterable of all updateswatchRich()
- - AsyncIterable with before/after diffsget()
- - Get all entitiesgetSync()
- - Get all entities synchronously (if available)
`typescript
type Update
| { type: 'upsert'; key: string; data: T }
| { type: 'patch'; key: string; data: Partial
| { type: 'delete'; key: string };
type RichUpdate
| { type: 'created'; key: string; data: T }
| { type: 'updated'; key: string; before: T; after: T; patch?: unknown }
| { type: 'deleted'; key: string; lastKnown?: T };
``
MIT