diff --git a/README.md b/README.md index 4b34e08..edce6f8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A port used to communicate with [NATS](https://nats.io/), the cloud native messa ```typescript // src/components.ts -await createNatsComponent({ config, logs } +await createNatsComponent({ config, logs }) ``` ### Start diff --git a/etc/nats-component.api.md b/etc/nats-component.api.md index aa7e225..af7a2d2 100644 --- a/etc/nats-component.api.md +++ b/etc/nats-component.api.md @@ -13,6 +13,9 @@ import { JSONCodec } from 'nats'; // Warning: (ae-forgotten-export) The symbol "natsComponent" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "INatsComponent" needs to be exported by the entry point index.d.ts // +// @public +export function createLocalNatsComponent(components: natsComponent.NeededComponents): Promise; + // @public export function createNatsComponent(components: natsComponent.NeededComponents): Promise; diff --git a/src/index.ts b/src/index.ts index f46e162..05ff25f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { connect, NatsConnection, JSONCodec } from "nats" import mitt from "mitt" import { natsComponent, INatsComponent, NatsEvents, Subscription } from "./types" +export { createLocalNatsComponent } from './test-component' /** * Encode/Decode JSON objects into Uint8Array and viceversa * @public @@ -23,7 +24,6 @@ export async function createNatsComponent( // config const natsUrl = (await config.getString("NATS_URL")) || "localhost:4222" - const natsConfig = { servers: `${natsUrl}` } let natsConnection: NatsConnection const events = mitt() @@ -38,8 +38,8 @@ export async function createNatsComponent( .then(() => { logger.info(`subscription closed for ${topic}`) }) - .catch((err) => { - logger.error(`subscription closed with an error ${err.message}`) + .catch((err: any) => { + logger.error(`subscription closed with an error ${err.toString()}`) }) return { unsubscribe: () => sub.unsubscribe(), @@ -49,7 +49,7 @@ export async function createNatsComponent( async function start() { try { - natsConnection = await connect(natsConfig) + natsConnection = await connect({ servers: `${natsUrl}` }) events.emit("connected") logger.info(`Connected to NATS: ${natsUrl}`) } catch (error) { diff --git a/src/test-component.ts b/src/test-component.ts index 4e037e8..9b7acf1 100644 --- a/src/test-component.ts +++ b/src/test-component.ts @@ -7,6 +7,10 @@ type PushableChannel = { push: (value: NatsMsg, resolve: (err?: any) => void) => void } +/** + * Create a local NATS component, for testing purposes + * @public + */ export async function createLocalNatsComponent( components: natsComponent.NeededComponents ): Promise {