@tshio/query-bus
v1.0.4
Published
Query Bus
Downloads
443
Readme
Query Bus
Non-blocking Query Bus library for Node.js.
This is a 100% JavaScript library, with TypeScript definition, with the Promise API.
Installing
$ npm install @tshio/query-bus
or
yarn add @tshio/query-bus
Usage
// CommonJS
const { Query, QueryBus, QueryHandler, QueryResult } = require('@tshio/query-bus');
// ES Module
import { Query, QueryBus, QueryHandler, QueryResult } from '@tshio/query-bus';
const QUERY_TYPE = "query-type";
class TestQueryResult implements QueryResult<string> {
result: string;
constructor(payload: string) {
this.result = payload;
}
}
class TestQueryHandler implements QueryHandler<Query<string>, QueryResult<string>> {
public queryType: string = QUERY_TYPE;
public execute(query: Query<string>): Promise<QueryResult<string>> {
return Promise.resolve(new TestQueryResult(query.payload));
}
}
const bus = new QueryBus([new TestQueryHandler()]);
const query: Query<string> = {
payload: "test",
type: "query-type",
};
bus.execute(query).then((result) => {
console.log(result);
// => "{ result: "test" }";
});
License
This project is licensed under the terms of the MIT license.
About us:
The Software House