@tshio/query-bus
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Query Bus

npm version

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

license

This project is licensed under the terms of the MIT license.

About us:

The Software House

tsh.png

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.4261latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.4261
1.0.319
1.0.20
1.0.10

Package Sidebar

Install

npm i @tshio/query-bus

Weekly Downloads

55

Version

1.0.4

License

MIT

Unpacked Size

12.3 kB

Total Files

12

Last publish

Collaborators

  • vviktor
  • aherok
  • sethii
  • barograf