Skip to content

Commit

Permalink
chore: expose Subscription type, remove unneeded dependencies from te…
Browse files Browse the repository at this point in the history
…sting component (#19)

* expose subscription
* local nats component requires no other components
  • Loading branch information
Hugo Arregui authored Aug 4, 2022
1 parent 34395ec commit 4a4c90e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
15 changes: 13 additions & 2 deletions etc/nats-component.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ import { IConfigComponent } from '@well-known-components/interfaces';
import { ILoggerComponent } from '@well-known-components/interfaces';
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<INatsComponent & IBaseComponent>;
export function createLocalNatsComponent(): Promise<INatsComponent & IBaseComponent>;

// Warning: (ae-forgotten-export) The symbol "natsComponent" needs to be exported by the entry point index.d.ts
//
// @public
export function createNatsComponent(components: natsComponent.NeededComponents): Promise<INatsComponent & IBaseComponent>;

export { JSONCodec }

// @public
export type Subscription = {
generator: AsyncIterable<NatsMsg>;
unsubscribe: () => void;
};

// Warnings were encountered during analysis:
//
// src/types.ts:21:3 - (ae-forgotten-export) The symbol "NatsMsg" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

```
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { connect, NatsConnection, JSONCodec } from "nats"
import mitt from "mitt"
import { natsComponent, INatsComponent, NatsEvents, Subscription } from "./types"

export { createLocalNatsComponent } from './test-component'
export { createLocalNatsComponent } from "./test-component"
/**
* Encode/Decode JSON objects into Uint8Array and viceversa
* @public
*/
export { JSONCodec }

export { Subscription }

/**
* Create a NATS component (https://nats.io/)
* Connect to a NATS node on start(), via the env variable "NATS_URL" or to "localhost:4222" by default
Expand Down
6 changes: 2 additions & 4 deletions src/test-component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IBaseComponent } from "@well-known-components/interfaces"
import { pushableChannel } from "@dcl/rpc/dist/push-channel"
import mitt from "mitt"
import { natsComponent, INatsComponent, Subscription, NatsEvents, NatsMsg } from "./types"
import { INatsComponent, Subscription, NatsEvents, NatsMsg } from "./types"

type PushableChannel = {
push: (value: NatsMsg, resolve: (err?: any) => void) => void
Expand All @@ -11,9 +11,7 @@ type PushableChannel = {
* Create a local NATS component, for testing purposes
* @public
*/
export async function createLocalNatsComponent(
components: natsComponent.NeededComponents
): Promise<INatsComponent & IBaseComponent> {
export async function createLocalNatsComponent(): Promise<INatsComponent & IBaseComponent> {
const channels = new Map<string, PushableChannel>()
const events = mitt<NatsEvents>()

Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export type NatsMsg = {
data: Uint8Array
}

/**
* A Nats subscription
* @public
*/
export type Subscription = {
generator: AsyncIterable<NatsMsg>
unsubscribe: () => void
Expand Down
2 changes: 1 addition & 1 deletion test/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const test = createRunner<TestComponents>({

const logs = createTestConsoleLogComponent()

const nats = await createLocalNatsComponent({ config, logs })
const nats = await createLocalNatsComponent()

return {
config,
Expand Down

0 comments on commit 4a4c90e

Please sign in to comment.