Giter VIP home page Giter VIP logo

equinox-js's Introduction

Equinox JS

This is a JS port of jet's Equinox.

Equinox is a set of low dependency libraries that allow for event-sourced processing against stream-based stores handling:

Reading the Equinox documentation and related materials is considered a requirement to use this library.

Running the sample

First clone this repository and enter the directory

$ pnpm i
$ pnpm exec turbo build
$ docker-compose up -d
$ cd ./packages/dynamo-store-tf
$ terraform init
$ terraform apply
$ cd ../../apps/sample
$ pnpm dev

Differences from Equinox

TypeScript doesn't have DU's

Well, that's technically not true, we can approximate them as such:

type Data = {hello: 'world'}
type Event = {type: 'Something', data: Data}

TypeScript doesn't have modules

We can replace them with namespaces, but people will look at you funny for using them for some reason ๐Ÿคท.

export namespace Events {
  type Data = {hello: 'world'}
  export type Event = {type: 'Something', data: Data}
}

Codecs

Because we represent DU's with a {type, data} object there's no need for a bespoke codec solution. We can just JSON.stringify(data) and be done with it.

Of course, in some cases you'll need to encode/decode so we do provide a way to achieve this.

const codec: Codec<Event> = {
  tryDecode(event: TimelineEvent<Record<string, any>>) : Event | undefined {
    switch (event.type) {
      case 'MyEvent': 
        return {type: event.type, data: {...event.data, timestamp: new Date(event.data.timestamp)}}
    }
  },
  encode(event: Event) {
    switch (event.type) {
      case 'MyEvent': 
        return {
          type: event.type, 
          data: {
            ...event.data, 
            timestamp: event.data.timestamp.toISOString()
          }
        }
    }
  }
}

DynamoStore needs some extra processing, so we provide AsyncCodec.deflate for this purpose. It'll stringify your body and then attempt to compress it. It'll choose the smaller of the compressed or the uncompressed bodies.

Logging

Equinox is quite heavily coupled to Serilog. There is no Serilog equivalent in JS. Even if there were, we'd likely not use it anyway. In this library we provide OpenTelemetry out of the box.

equinox-js's People

Contributors

nordfjord avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.