npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fraym/streams

v0.10.2

Published

nodejs client implementation for our event streaming service

Downloads

408

Readme

streams-nodejs

Client implementation in javascript for the event streaming service streams.

Installation

npm i @fraym/streams

Usage

Create the client

const client = await newClient({
    serverAddress: "127.0.0.1:9000",
    groupId: "your-services-group-identifier",
});

Publish events

Events are published in a transactional manner:

  • you can publish a set of events in a transaction
  • if one event in your set cannot be published no event will be published
  • as soon as all events are published they appear in their streams

You can only publish events of one topic per transaction. Most of the fields of an event are optional. You do not have to use or specify them, but you can use them if you want to.

await client.publish("topic", [
    {
        id: uuid(),
        tenantId: "tenantId",
        payload: {
            key: "value",
			object: {
				key: "objectKeyValue"
			},
        },
        // set `broadcast` to true if you want all subscribers of a group to process the event.
        // set to false (or remove) if you want this event to be handled only once by a group of subscribers.
        broadcast: false,
        type: "event-type",
        stream: "stream-name",
        correlationId: uuid(),
        causationId: uuid(),
        reason: "the reason why this event was triggered",
    },
]);

Get events of a stream

If you want to get all events that belong to a given stream you can do this by calling `getStream``:

const streamEvents = await client.getStream("tenantId", "stream");

Register event handlers for event subscriptions

// this handler is called for events of all types
client.useEventHandlerForAllEventTypes(async (event: SubscriptionEvent) => {
    // @todo: handle the event in this callback
});

// this handler is only called for events of the given type "event-type"
client.useEventHandler("event-type", async (event: SubscriptionEvent) => {
    // @todo: handle the event in this callback
});

Subscribe to events

You can subscribe to events of all topics by not providing any parameters to the subscribe function:

await client.subscribe();

You can subscribe to events of a given set of topics by specifying the includedTopics list:

await client.subscribe(["topic-1", "topic-2"]);

You can subscribe to all events except of a given set of topics by specifying the excludedTopics list:

await client.subscribe([], ["topic-1", "topic-2"]);

One client instance is only able to subscribe once. If you try to subscribe twice you will get an error.

Get all events for a given topic filter

The getAllEvents function uses the same topic filter parameters as described for the subscribe function

await client.getAllEvents(async (event: SubscriptionEvent) => {
    // @todo: handle the event in this callback
});

Invalidate gdpr data

You will not need to use this if you use our GDPR service.

await client.invalidateGdprData("tenantId", "topic-1", "grprId");

Create a snapshot of a topic

A snapshot moves events from the "fast access" database to a "long time storage". The long time storage will have slower access time. Use this if you have topics that have a lot of old events which are not queried regularly.

Creating a snapshot will only affect performance. You will not lose any of your events.

Snapshots can be used to clean up your "fast access" event database and therefore increase performance on new events.

await client.createSnapshot("topic-1", new Date());

The second parameter is a date. All events that are older than that date will be moved to the snapshot.

Gracefully close the client

You won't lose any data if you don't. Use it for your peace of mind.

client.close();