# journaly

> A simple pub-sub library project

Latest version **4.0.10** (published 2022-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install journaly
pnpm add journaly
yarn add journaly
bun add journaly
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.10 |
| Published | 2022-12-06 |
| First published | 2019-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 44.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Judah Holanda Correia Lima |
| Maintainers | judahh |
| Keywords | message-broker, pubsub, pubsubplatform, publisher-subscriber-pattern, publisher-subscriber, observer-pattern, observer, nodejs, typescript, javascript |

## Links

- npm: https://www.npmjs.com/package/journaly
- Repository: https://github.com/Judahh/journaly
- Homepage: https://github.com/Judahh/journaly#readme
- Issues: https://github.com/Judahh/journaly/issues
- npm.io page: https://npm.io/package/journaly

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.0.10 (latest) — 2022-12-06
- 4.0.9 — 2022-05-10
- 4.0.8 — 2022-04-04
- 4.0.7 — 2022-01-28
- 4.0.6 — 2022-01-28
- 4.0.5 — 2022-01-09
- 4.0.4 — 2021-12-11
- 4.0.3 — 2021-11-29
- 4.0.2 — 2021-11-19
- 4.0.1 — 2021-09-29
- 4.0.0 — 2021-09-27
- 3.0.4 — 2021-05-06
- 3.0.3 — 2021-05-06
- 3.0.2 — 2021-03-19
- 3.0.1 — 2021-03-12
- … 21 more at https://npm.io/package/journaly/versions

## README

# Journaly

![Publish](https://github.com/Judahh/journaly/workflows/Publish/badge.svg)
[![npm version](https://badge.fury.io/js/journaly.svg)](https://badge.fury.io/js/journaly)
[![npm downloads](https://img.shields.io/npm/dt/journaly.svg)](https://img.shields.io/npm/dt/journaly.svg)

A simple message-broker/Pub-sub library

```js
const function1 = async (object0, string0): Promise<string> => {
  await timeout(100);
  return new Promise((resolve) => resolve({string0: string0 + ' executed!', object0}));
};

const journaly = Journaly.newJournaly<string>({
      multiple: true, // setting to use pub-sub pattern
      hasTopic: true,
    }) as PublisherSubscriber<string>;

const subscribe1 = journaly.subscribe(function1, 'test');// Connects function1 to subject test

const subscribes = await Promise.all([subscribe1]);

// Publishes to subject test args: { someObject: 'something' }, 'test 0'
const publish1 = await journaly.publish('test', { someObject: 'something' }, 'test 0');
// Prints all responses to publish 1 from functions which subscribe to subject test
// Each response is an element of the returned array
console.log(publish1);
```

```js
const function1 = async (object0, string0): Promise<string> => {
  await timeout(100);
  return new Promise((resolve) => resolve({string0: string0 + ' executed!', object0}));
};

const journaly = Journaly.newJournaly<string>({
      multiple: true, // setting to use observer pattern
    }) as ObserverSubject<string>;

const subscribe1 = journaly.subscribe(function1, 'test');// Connects function1 to subject test

const subscribes = await subscribe1;

// Publishes to subject test args: { someObject: 'something' }, 'test 0'
const publish1 = await journaly.publish('test', { someObject: 'something' }, 'test 0');
// Prints the response to publish 1 from function 1 which subscribes to subject test
console.log(publish1);
```

## Installation

This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/).

Before installing,
[download and install Node.js](https://nodejs.org/en/download/).

If this is a brand new project, make sure to create a `package.json` first with
the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file) or
[`yarn init` command](https://classic.yarnpkg.com/en/docs/cli/init/).

Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally)
or [`yarn add` command](https://classic.yarnpkg.com/en/docs/cli/add):

```bash
$ npm install journaly
```

or

```bash
$ yarn add journaly
```

## Features

- Ready to use Pub-sub design pattern
- Promises oriented
- Simple implementation

## Object Example

```js
class ObjectClass {
  public async method1(object0, string0): Promise<string> {
    await timeout(100);
    return new Promise((resolve) => resolve({string0: string0 + ' executed!', object0}));
  }
}

const object = new ObjectClass();

const journaly = Journaly.newJournaly<string>({
      multiple: true,// setting to use pub-sub pattern
      hasTopic: true,
    }) as PublisherSubscriber<string>;

const subscribe1 = journaly.subscribe(object.method1.bind(object), 'test');// Connects method1 to subject test

const subscribes = await Promise.all([subscribe1]);

// Publishes to subject test args: { someObject: 'something' }, 'test 0'
const publish1 = await journaly.publish('test', { someObject: 'something' }, 'test 0');
// Prints all responses to publish 1 from functions which subscribe to subject test
console.log(publish1);
```

## Settings

```js
const journaly = Journaly.newJournaly<string>({
      multiple: true,// setting to use pub-sub pattern
      hasTopic: true,
    }) as PublisherSubscriber<string>;

const journaly = Journaly.newJournaly<string>({
      multiple: true,// setting to use observer pattern
    }) as ObserverSubject<string>;

const journaly = Journaly.newJournaly<string>({// setting to use sender-receiver pattern
    }) as SenderReceiver<string>;

const journaly = Journaly.newJournaly<string>({
      multiple: true,// setting to use pub-sub pattern
      hasTopic: true,
      hasMemory: true,// setting to store every event,
      // to send all received events to new subscribers
    }) as PublisherSubscriberWithMemory<string>;

const journaly = Journaly.newJournaly<string>({
      multiple: true,// setting to use observer pattern
      hasMemory: true,// setting to store every event,
      // to send all received events to new subscribers
    }) as ObserverSubjectWithMemory<string>;

const journaly = Journaly.newJournaly<string>({// setting to use sender-receiver pattern
      hasMemory: true,// setting to store every event,
      // to send all received events to new subscribers
    }) as SenderReceiverWithMemory<string>;
```

## Tests

To run the test suite, first install the dependencies, then run `npm test`:

```bash
$ npm install
$ npm test
```

or

```bash
$ yarn
$ yarn test
```

## Methods

```js
// Returns an array with current topics
getTopics(): string[];

// Subscribe a function to a topic (if applicable) and returns an array
// with a result corresponding with all the data received before
subscribe(
    subscriber: SubjectPromise<Result>,
    topic?: string
  ): Promise<Result[]>;

// Unsubscribe a function of a topic (if applicable) and returns an boolean
// corresponding if it's succedd
unsubscribe(subscriber: SubjectPromise<Result>, topic?: string): boolean;

// Publish to a topic (if applicable) and returns all the results of
// subscribbed functions
publish(topic?: string, ...params: any[]): Promise<Result[] | Result>;
```

## People

The original author of Journaly is [Judah Lima](https://github.com/Judahh)

[List of all contributors](https://github.com/Judahh/journaly/graphs/contributors)

---
_Source: https://npm.io/package/journaly · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
