1.1.5 • Published 12 months ago

jerni v1.1.5

Weekly downloads
60
License
MIT
Repository
github
Last release
12 months ago

jerni

jerni is a nodejs library and a command-line tool to build an opinionated event-sourcing system.

Resouces

  1. API documentation
  2. List of Examples

Usage

// journey.js
const createJourney = require("jerni");
const { makeStore } = require("@jerni/store-mongo");
const people = require("./models/people");

// this file needs to export an async initializer function that return a Promise of a journey
module.exports = async function() {
  const mongoStore = await makeStore({
    url: "mongodb://localhost:27017",
    dbName: "examples",
    models: [people],
  });

  const journey = createJourney({
    writeTo: "http://localhost:6181",
    stores: [mongoStore],
  });

  /* a journey provides
   * - journey.commit(): to publish an event
   * - journey.waitFor(): to get notified when an event is fully persisted from stores (destinations)
   * - journey.getReader(): to return a native driver for querying database, drivers are provided by the corresponding store
   * for more API documentations, please visit https://docs.jerni.dev
   */

  return journey;
};

// api.js
const journey = require("./journey.js");
const people = require("./models/people");
const { registerNewBorn, registerNewPerson } = require("./commands");

app.get("/api/people", async () => {
  const PeopleCollection = await journey.getReader(people);
  return People.find({});
});

app.post("/api/people", req => {
  // registerNewPerson will validate the request and commit approriate event to event queue
  return registerNewPerson(journey, req.body);
});

app.post("/api/births", req => {
  // registerNewBorn will validate the request and commit approriate event to event queue
  return registerNewBorn(journey, req.body);
});

Subscription

To start a synchronization

{
  "scripts": {
    "jerni-dev": "jerni-dev start ./journey.js",
    "jerni": "NODE_ENV=production jerni start ./journey.js"
  }
}

jerni and jerni-dev require node 10+ to run, while @jerni/store-mongo requires node 12. Therefore unless you're running node 12, you need to use these scripts:

{
  "scripts": {
    "jerni-dev": "npx -p node@12 jerni-dev start ./journey.js",
    "jerni": "NODE_ENV=production npx -p node@12 jerni start ./journey.js"
  }
}

adding npx -p node@12 will run the following command in node 12 (-p is short for --platform)

1.1.5

12 months ago

1.1.4

2 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago

1.0.0-rc.0

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.1

4 years ago

1.0.0-alpha.0

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.3

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.16

6 years ago

0.4.15

6 years ago

0.4.14

6 years ago

0.4.13

6 years ago

0.4.12

6 years ago

0.4.11

6 years ago

0.4.10

6 years ago

0.4.9

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago