0.1.4 • Published 4 years ago

axon-client v0.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

axon-client

NPM TYPESCRIPT Weekly downloads

Unofficial NodeJS client for Axon Server written in TypeScript. Note: This library has a peer-dependency on rxjs >= 6.

Installation

Via npm

npm install axon-client

or yarn

yarn add axon-client

Getting started

In order to setup a connection:

import { AxonClient } from 'axon-client';

async function app() {
  const client = await new AxonClient({
    componentName: 'My-App',
    clientId: '123@hostname', // optional, defaults to process-id + hostname
    host: '0.0.0.0',
    port: 8124, // optional , defaults to 8124
    token: 'my-secret-token', // optional
    certificate: fs.readFileSync('path-to-certificate'), // optional
  }).connect();

  console.log(`Connected to Axon Server on ${client.endpoint}`);

  // do stuff with the client here...

  // optionally disconnect when done
  client.disconnect();
}

Methods

The following methods are available.

eventBus

queryEvents(query: string, numberOfPermits?: number): Observable<QueryEvents>;
getFirstToken(): Promise<number>;
getLastToken(): Promise<number>;
getTokenAt(instant: number): Promise<number>;
listAggregateEvents(options: ListAggregateEventsOptions): Promise<AggregateEvent[]>;
listAggregateSnapshots(options: ListAggregateSnapshotsOptions): Promise<any[]>;
listEvents(options: ListEventOptions): Observable<Event>;
appendEvents(event: AggregateEvent | AggregateEvent[]): Promise<Confirmation>;

commandBus

getPermits(): number;
setPermits(permits: number): void;
subscribe(commandName: string, operation: AnyFunction): Unsubscriber;
unsubscribe(commandName: string): void;
dispatch({ name, payload }: DispatchOptions): Promise<DispatchResponse>;

queryBus

Unfortunately, query-subscription are not (yet) possible.

getPermits(): number;
setPermits(permits: number): void;
subscribe(queryName: string, operation: AnyFunction): Unsubscriber;
unsubscribe(queryName: string): void;
query(options: QueryOptions): Promise<QueryResult>;