1.1.5 • Published 2 years ago

jerni v1.1.5

Weekly downloads
60
License
MIT
Repository
github
Last release
2 years 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

2 years ago

1.1.4

3 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-rc.4

5 years ago

1.0.0-rc.3

5 years ago

1.0.0-rc.2

5 years ago

1.0.0-rc.1

5 years ago

1.0.0-rc.0

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha.0

6 years ago

0.9.8

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.3

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.2

6 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.16

7 years ago

0.4.15

7 years ago

0.4.14

7 years ago

0.4.13

7 years ago

0.4.12

7 years ago

0.4.11

7 years ago

0.4.10

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago