{"id":26095313,"url":"https://github.com/thenativeweb/node-cqrs-eventdenormalizer","last_synced_at":"2026-03-17T23:07:40.322Z","repository":{"id":3316684,"uuid":"4359484","full_name":"thenativeweb/node-cqrs-eventdenormalizer","owner":"thenativeweb","description":"Node-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern. It can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.","archived":false,"fork":false,"pushed_at":"2020-09-04T03:29:29.000Z","size":999,"stargazers_count":39,"open_issues_count":10,"forks_count":27,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-24T00:26:13.959Z","etag":null,"topics":["cqrs","domain-driven-design","events","javascript","replay"],"latest_commit_sha":null,"homepage":"http://cqrs.js.org/pages/eventdenormalizer.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thenativeweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-17T14:46:40.000Z","updated_at":"2024-12-21T08:44:15.000Z","dependencies_parsed_at":"2022-08-28T05:40:17.649Z","dependency_job_id":null,"html_url":"https://github.com/thenativeweb/node-cqrs-eventdenormalizer","commit_stats":null,"previous_names":["adrai/node-cqrs-eventdenormalizer"],"tags_count":165,"template":false,"template_full_name":null,"purl":"pkg:github/thenativeweb/node-cqrs-eventdenormalizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-cqrs-eventdenormalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-cqrs-eventdenormalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-cqrs-eventdenormalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-cqrs-eventdenormalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thenativeweb","download_url":"https://codeload.github.com/thenativeweb/node-cqrs-eventdenormalizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thenativeweb%2Fnode-cqrs-eventdenormalizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30635156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T22:38:22.569Z","status":"ssl_error","status_checked_at":"2026-03-17T22:38:11.804Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cqrs","domain-driven-design","events","javascript","replay"],"created_at":"2025-03-09T13:15:39.096Z","updated_at":"2026-03-17T23:07:40.303Z","avatar_url":"https://github.com/thenativeweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚠️ IMPORTANT NEWS! 📰\n\nI’ve been dealing with CQRS, event-sourcing and DDD long enough now that I don’t need working with it anymore unfortunately, so at least for now this my formal farewell!\n\nI want to thank everyone who has contributed in one way or another.\nEspecially...\n\n- [Jan](https://github.com/jamuhl), who introduced me to this topic.\n- [Dimitar](https://github.com/nanov), one of the last bigger contributors and maintainer.\n- My last employer, who gave me the possibility to use all these CQRS modules in a big Cloud-System.\n- My family and friends, who very often came up short.\n\nFinally, I would like to thank [Golo Roden](https://github.com/goloroden), who was there very early at the beginning of my CQRS/ES/DDD journey and is now here again to take over these modules.\n\nGolo Roden is the founder, CTO and managing director of [the native web](https://www.thenativeweb.io/), a company specializing in native web technologies. Among other things, he also teaches CQRS/ES/DDD etc. and based on his vast knowledge, he brought wolkenkit to life.\n[wolkenkit](https://wolkenkit.io) is a CQRS and event-sourcing framework based on Node.js. It empowers you to build and run scalable distributed web and cloud services that process and store streams of domain events.\n\nWith this step, I can focus more on [i18next](https://www.i18next.com), [locize](https://locize.com) and [localistars](https://localistars.com). I'm happy about that. 😊\n\nSo, there is no end, but the start of a new phase for my CQRS modules. 😉\n\nI wish you all good luck on your journey.\n\nWho knows, maybe we'll meet again in a github issue or PR at [i18next](https://github.com/i18next/i18next) 😉\n\n\n[Adriano Raiano](https://twitter.com/adrirai)\n\n---\n\n# Introduction\n\n[![travis](https://img.shields.io/travis/adrai/node-cqrs-eventdenormalizer.svg)](https://travis-ci.org/adrai/node-cqrs-eventdenormalizer) [![npm](https://img.shields.io/npm/v/cqrs-eventdenormalizer.svg)](https://npmjs.org/package/cqrs-eventdenormalizer)\n\nNode-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern.\nIt can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Catch connect ad disconnect events](#catch-connect-ad-disconnect-events)\n  - [Define the event structure](#define-the-event-structure)\n  - [Define the notification structure](#define-the-notification-structure)\n  - [Define the id generator function [optional]](#define-the-id-generator-function-optional)\n    - [you can define a synchronous function](#you-can-define-a-synchronous-function)\n    - [or you can define an asynchronous function](#or-you-can-define-an-asynchronous-function)\n  - [Wire up events [optional]](#wire-up-events-optional)\n    - [you can define a synchronous function](#you-can-define-a-synchronous-function-1)\n    - [or you can define an asynchronous function](#or-you-can-define-an-asynchronous-function-1)\n  - [Wire up notifications [optional]](#wire-up-notifications-optional)\n    - [you can define a synchronous function](#you-can-define-a-synchronous-function-2)\n    - [or you can define an asynchronous function](#or-you-can-define-an-asynchronous-function-2)\n  - [Wire up event missing [optional]](#wire-up-event-missing-optional)\n    - [you can define a synchronous function](#you-can-define-a-synchronous-function-3)\n  - [Define default event extension [optional]](#define-default-event-extension-optional)\n    - [you can define a synchronous function](#you-can-define-a-synchronous-function-4)\n    - [or you can define an asynchronous function](#or-you-can-define-an-asynchronous-function-3)\n  - [Initialization](#initialization)\n  - [Handling an event](#handling-an-event)\n    - [or](#or)\n  - [Request denormalizer information](#request-denormalizer-information)\n- [Components definition](#components-definition)\n  - [Collection](#collection)\n  - [ViewBuilder](#viewbuilder)\n    - [ViewBuilder for multiple viewmodels in a collection](#viewbuilder-for-multiple-viewmodels-in-a-collection)\n  - [EventExtender](#eventextender)\n    - [for a collection (in a collection folder)](#for-a-collection-in-a-collection-folder)\n    - [not for a collection](#not-for-a-collection)\n  - [Replay events](#replay-events)\n    - [streamed](#streamed)\n    - [if you want to clear the readModel before replaying...](#if-you-want-to-clear-the-readmodel-before-replaying)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n# Installation\n\n    npm install cqrs-eventdenormalizer\n\n# Usage\n\n\tvar denormalizer = require('cqrs-eventdenormalizer')({\n\t  // the path to the \"working directory\"\n\t  // can be structured like\n\t  // [set 1](https://github.com/adrai/node-cqrs-eventdenormalizer/tree/master/test/integration/fixture/set1) or\n\t  // [set 2](https://github.com/adrai/node-cqrs-eventdenormalizer/tree/master/test/integration/fixture/set2)\n\t  denormalizerPath: '/path/to/my/files',\n\n\t  // optional, default is 'commandRejected'\n\t  // will be used to catch AggregateDestroyedError from cqrs-domain\n\t  commandRejectedEventName: 'rejectedCommand',\n\n\t  // optional, default is 800\n\t  // if using in scaled systems, this module tries to catch the concurrency issues and\n\t  // retries to handle the event after a timeout between 0 and the defined value\n\t  retryOnConcurrencyTimeout: 1000,\n\n\t  // optional, default is in-memory\n\t  // currently supports: mongodb, redis, tingodb, couchdb, azuretable, dynamodb and inmemory\n\t  // hint: [viewmodel](https://github.com/adrai/node-viewmodel#connecting-to-any-repository-mongodb-in-the-example--modewrite)\n\t  // hint settings like: [eventstore](https://github.com/adrai/node-eventstore#provide-implementation-for-storage)\n\t  repository: {\n\t    type: 'mongodb',\n\t    host: 'localhost',                          // optional\n\t    port: 27017,                                // optional\n\t    dbName: 'readmodel',                        // optional\n\t    timeout: 10000                              // optional\n      // authSource: 'authedicationDatabase',        // optional\n\t    // username: 'technicalDbUser',                // optional\n\t    // password: 'secret'                          // optional\n      // url: 'mongodb://user:pass@host:port/db?opts // optional\n\t  },\n\n\t  // optional, default is in-memory\n\t  // currently supports: mongodb, redis, tingodb, dynamodb and inmemory\n\t  // hint settings like: [eventstore](https://github.com/adrai/node-eventstore#provide-implementation-for-storage)\n\t  revisionGuard: {\n\t    queueTimeout: 1000,                         // optional, timeout for non-handled events in the internal in-memory queue\n\t    queueTimeoutMaxLoops: 3,                    // optional, maximal loop count for non-handled event in the internal in-memory queue\n\t    startRevisionNumber: 1,\t\t\t// optional, if defined the denormaizer waits for an event with that revision to be used as first event\n\n\t    type: 'redis',\n\t    host: 'localhost',                          // optional\n\t    port: 6379,                                 // optional\n\t    db: 0,                                      // optional\n\t    prefix: 'readmodel_revision',               // optional\n\t    timeout: 10000                              // optional\n\t    // password: 'secret'                          // optional\n\t  },\n\t  skipExtendEvent: false,\t\t\t\t\t\t// optional\n\t  skipOnEventMissing: false,\t\t\t\t\t// optional\n\t  skipOnEvent: false,\t\t\t\t\t\t\t// optional\n\t  skipOnNotification: false,\t\t\t\t\t// optional\n\t});\n\n\n## Catch connect ad disconnect events\n\n\t// repository\n\tdenormalizer.repository.on('connect', function() {\n\t  console.log('repository connected');\n\t});\n\n\tdenormalizer.repository.on('disconnect', function() {\n\t  console.log('repository disconnected');\n\t});\n\n\t// revisionGuardStore\n\tdenormalizer.revisionGuardStore.on('connect', function() {\n\t  console.log('revisionGuardStore connected');\n\t});\n\n\tdenormalizer.revisionGuardStore.on('disconnect', function() {\n\t  console.log('revisionGuardStore disconnected');\n\t});\n\n\n\t// anything (repository or revisionGuardStore)\n\tdenormalizer.on('connect', function() {\n\t  console.log('something connected');\n\t});\n\n\tdenormalizer.on('disconnect', function() {\n\t  console.log('something disconnected');\n\t});\n\n\n## Define the event structure\nThe values describes the path to that property in the event message.\n\n\tdenormalizer.defineEvent({\n\t  // optional, default is 'correlationId'\n\t  // will use the command id as correlationId, so you can match it in the sender\n\t  // will be used to copy the correlationId to the notification\n\t  correlationId: 'correlationId',\n\n\t  // optional, default is 'id'\n\t  id: 'id',\n\n\t  // optional, default is 'name'\n\t  name: 'name',\n\n\t  // optional, default is 'aggregate.id'\n\t  aggregateId: 'aggregate.id',\n\n\t  // optional\n\t  context: 'context.name',\n\n\t  // optional\n\t  aggregate: 'aggregate.name',\n\n\t  // optional, default is 'payload'\n\t  payload: 'payload',\n\n\t  // optional, default is 'revision'\n\t  // will represent the aggregate revision, can be used in next command\n\t  revision: 'revision',\n\n\t  // optional\n\t  version: 'version',\n\n\t  // optional, if defined the values of the command will be copied to the event (can be used to transport information like userId, etc..)\n\t  meta: 'meta'\n\t});\n\n\n## Define the notification structure\nThe values describes the path to that property in the notification message.\n\n\tdenormalizer.defineNotification({\n\t  // optional, default is 'correlationId'\n\t  // will use the command id as correlationId, so you can match it in the sender\n\t  // will be used to copy the correlationId from the event\n\t  correlationId: 'correlationId',\n\n\t  // optional, default is 'id'\n\t  id: 'id',\n\n\t  // optional, default is 'name'\n\t  action: 'name',\n\n\t  // optional, default is 'collection'\n\t  collection: 'collection',\n\n\t  // optional, default is 'payload'\n\t  payload: 'payload',\n\n\t  // optional, will be copied from event\n\t  aggregateId: 'meta.aggregate.id',\n\n\t  // optional, will be copied from event\n\t  context: 'meta.context.name',\n\n\t  // optional, will be copied from event\n\t  aggregate: 'meta.aggregate.name',\n\n\t  // optional, will be copied from event\n\t  // will represent the aggregate revision, can be used in next command\n\t  revision: 'meta.aggregate.revision',\n\n\t  // optional, will be copied from event\n\t  eventId: 'meta.event.id',\n\n\t  // optional, will be copied from event\n\t  event: 'meta.event.name',\n\n\t  // optional, if defined the values of the event will be copied to the notification (can be used to transport information like userId, etc..)\n\t  meta: 'meta'\n\t});\n\n\n## Define the id generator function [optional]\n### you can define a synchronous function\n\n\tdenormalizer.idGenerator(function () {\n\t  var id = require('uuid').v4().toString();\n\t  return id;\n\t});\n\n### or you can define an asynchronous function\n\n\tdenormalizer.idGenerator(function (callback) {\n\t  setTimeout(function () {\n\t    var id = require('uuid').v4().toString();\n\t    callback(null, id);\n\t  }, 50);\n\t});\n\n\n## Wire up events [optional]\n### you can define a synchronous function\n\n\t// pass events to bus\n\tdenormalizer.onEvent(function (evt) {\n\t  bus.emit('event', evt);\n\t});\n\n\n### or you can define an asynchronous function\n\n\t// pass events to bus\n\tdenormalizer.onEvent(function (evt, callback) {\n\t  bus.emit('event', evt, function ack () {\n\t    callback();\n\t  });\n\t});\n\n### skip onEvent if provided\n\tYou can skip onEvent from being called, by adding the `skipOnEvent` option to the denormalizer. Checkout the usage section for more information.\n\n\n## Wire up notifications [optional]\n### you can define a synchronous function\n\n\t// pass notifications to bus\n\tdenormalizer.onNotification(function (noti) {\n\t  bus.emit('event', evt);\n\t});\n\n### or you can define an asynchronous function\n\n\t// pass notifications to bus\n\tdenormalizer.onNotification(function (noti, callback) {\n\t  bus.emit('notification', noti, function ack () {\n\t    callback();\n\t  });\n\t});\n\n### skip onNotification if provided\n\n\tYou can skip onNotification from being called, by addding the `skipOnNotification` option to the denormalizer. Checkout the usage section for more information.\n\n\n\n## Wire up event missing [optional]\n### you can define a synchronous function\n\n\tdenormalizer.onEventMissing(function (info, evt) {\n\t  console.log(info);\n\t  console.log(evt);\n\t});\n\n### skip onEventMissing if provided\n\tYou can skip onEventMissing from being called, by adding the `skipOnEventMissing` option to the denormalizer. Checkout the usage section more information.\n\n\n## Define default event extension [optional]\n### you can define a synchronous function\n\n\tdenormalizer.defaultEventExtension(function (evt) {\n\t  evt.receiver = [evt.meta.userId];\n\t  return evt;\n\t});\n\n### or you can define an asynchronous function\n\n\tdenormalizer.defaultEventExtension(function (evt, callback) {\n\t  evt.receiver = [evt.meta.userId];\n\t  callback(null, evt);\n\t});\n\n### skip default event extensions \n\tYou can skip all event extenders and the default extensions from being executed by adding the option `skipExtendEvent` to the denormalizer. Checkout the usage section for more information.\n\n\n\n\n## Using custom structure loader function\nThe built-in structure loader can be replaced with one adapted to your needs.\nTo do that, you need to include a loading method in the options object passed to the domain constructor.\n\n\t// options will contain denormalizerPath as well as the as well as a definition object containing all the constructors of the denormalizer components  ( Collection, ViewBuilder etc. )\n\tfunction structureLoader(options) {\n\t\tconst collection = new options.definitions.Collection({\n\t\t\tname: 'col'\n\t\t});\n\t\tcollection.addViewBuilder(new options.definitions.ViewBuilder({\n\t\t\tname: 'evt',\n\t\t\taggregate: 'agg',\n\t\t\tcontext: 'ctx'              \n\t\t}, function() {}));\n\t\treturn {\n\t\t\tcollections: [\n\t\t\t\tcollection\n\t\t\t]\n\t\t};\n\t\t// or more probably\n\t\treturn myExternalLoader(options.denormalizerPath, options.definitions);\n\t}\n\n\trequire('cqrs-eventdenormalizer')({\n\t\t\tdenormalizerPath: '/path/to/my/files',\n\t\t\tstructureLoader: structureLoader\n\t});\n\n## Initialization\n\n\tdenormalizer.init(function (err, warnings) {\n\t  // this callback is called when all is ready...\n\t  // warnings: if no warnings warnings is null, else it's an array containing errors during require of files\n\t});\n\n\t// or\n\n\tdenormalizer.init(); // callback is optional\n\n\n## Handling an event\n\n\tdenormalizer.handle({\n\t  id: 'b80ade36-dd05-4340-8a8b-846eea6e286f',\n\t  correlationId: 'c80ada33-dd05-4340-8a8b-846eea6e151d',\n\t  name: 'enteredNewPerson',\n\t  aggregate: {\n\t    id: '3b4d44b0-34fb-4ceb-b212-68fe7a7c2f70',\n\t    name: 'person'\n\t  },\n\t  context: {\n\t    name: 'hr'\n\t  },\n\t  payload: {\n\t    firstname: 'Jack',\n\t    lastname: 'Huston'\n\t  },\n\t  revision: 1,\n\t  version: 0,\n\t  meta: {\n\t    userId: 'ccd65819-4da4-4df9-9f24-5b10bf89ef89'\n\t  }\n\t}); // callback is optional\n\n### or\n\n\tdenormalizer.handle({\n\t  id: 'b80ade36-dd05-4340-8a8b-846eea6e286f',\n\t  correlationId: 'c80ada33-dd05-4340-8a8b-846eea6e151d',\n\t  name: 'enteredNewPerson',\n\t  aggregate: {\n\t    id: '3b4d44b0-34fb-4ceb-b212-68fe7a7c2f70',\n\t    name: 'person'\n\t  },\n\t  context: {\n\t    name: 'hr'\n\t  },\n\t  payload: {\n\t    firstname: 'Jack',\n\t    lastname: 'Huston'\n\t  },\n\t  revision: 1,\n\t  version: 0,\n\t  meta: {\n\t    userId: 'ccd65819-4da4-4df9-9f24-5b10bf89ef89'\n\t  }\n\t}, function (errs, evt, notifications) {\n\t  // this callback is called when event is handled successfully or unsuccessfully\n\t  // errs can be of type:\n\t  // - null\n\t  // - Array of Errors\n\t  //\n\t  // evt: same as passed in 'onEvent' function\n\t  //\n\t  // notifications: Array of viewmodel changes\n\t});\n\n\n## Request denormalizer information\n\nAfter the initialization you can request the denormalizer information:\n\n\tdenorm.init(function (err) {\n\t  denorm.getInfo();\n\t  // ==\u003e\n\t  // {\n\t  //   \"collections\": [\n\t  //     {\n\t  //       \"name\": \"person\",\n\t  //       \"viewBuilders\": [\n\t  //         {\n\t  //           \"name\": \"enteredNewPerson\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2,\n      //           \"priority\": 223\n\t  //         },\n\t  //         {\n\t  //           \"name\": \"registeredEMailAddress\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2,\n      //           \"priority\": 312\n\t  //         }\n\t  //       ],\n\t  //       \"eventExtenders\": [\n\t  //         {\n\t  //           \"name\": \"enteredNewPerson\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2\n\t  //         }\n\t  //       ],\n\t  //       \"preEventExtenders\": [\n\t  //         {\n\t  //           \"name\": \"enteredNewPerson\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2\n\t  //         }\n\t  //       ]\n\t  //     },\n\t  //     {\n\t  //       \"name\": \"personDetail\",\n\t  //       \"viewBuilders\": [\n\t  //         {\n\t  //           \"name\": \"enteredNewPerson\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2,\n      //           \"priority\": 110\n\t  //         },\n\t  //         {\n\t  //           \"name\": \"registeredEMailAddress\",\n\t  //           \"aggregate\": \"person\",\n\t  //           \"context\": \"hr\",\n\t  //           \"version\": 2,\n      //           \"priority\": Infinity\n\t  //         }\n\t  //       ],\n\t  //       \"eventExtenders\": [],\n\t  //       \"preEventExtenders\": []\n\t  //     }\n\t  //   ],\n\t  //   \"generalEventExtenders\": [\n\t  //     {\n\t  //       \"name\": \"\",\n\t  //       \"aggregate\": null,\n\t  //       \"context\": null,\n\t  //       \"version\": -1\n\t  //     }\n\t  //   ],\n\t  //   \"generalPreEventExtenders\": []\n\t  // }\n\t});\n\n\n# Components definition\n\n## Collection\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineCollection({\n\t  // optional, default is folder name\n\t  name: 'personDetail',\n\n\t  // optional, default ''\n\t  defaultPayload: 'payload',\n\n\t  // optional, default false\n\t  noReplay: false,\n\n\t  // indexes: [ // for mongodb\n\t  //   'profileId',\n\t  //   // or:\n\t  //   { profileId: 1 },\n\t  //   // or:\n\t  //   { index: { profileId: 1 }, options: {} },\n\t  // ],\n\n\t  // repositorySettings: { // optional\n\t  //   mongodb: { // for mongo db\n\t  //     indexes: [ // same as above\n\t  //       'profileId',\n\t  //       // or:\n\t  //       { profileId: 1 },\n\t  //       // or:\n\t  //       { index: { profileId: 1 }, options: {} },\n\t  //     ],\n\t  //   },\n\t  //   elasticsearch6: { // for elasticsearch 5.x and 6.x ( elasticsearch6 type / implementation / driver )\n\t  //     refresh: 'wait_for', // refresh behaviour on index, default is true ( ie. force index refresh ) https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html\n\t  //     waitForActiveShards: 2, // optional, defaults to 1 ( ie. wait only for primary ) https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#create-index-wait-for-active-shards\n\t  //     index: { // optional applied on index create, https://www.elastic.co/guide/en/elasticsearch/reference/6.x/indices-create-index.html\n\t  //       settings: { // will be merged with the default ones,\n\t  //         number_of_shards: 3, // optional, otherwise taken from type settings, defaults to 1,\n\t  //         number_of_replicas: 1, // optional otherwise taken from type settings, defaults to 0,\n\t  //       },\n\t  //       mappings: { // optiona will be merged with the default ones,\n\t  //         properties: { // specific properties to not be handled by dynamic mapper\n\t  //           title: {\n\t  //             type: 'text',\n\t  //           },\n\t  //         },\n\t  //       },\n\t  //     },\n\t  //   },\n\t  // },\n\t},\n\n\t  // optionally, define some initialization data for new view models...\n\t{\n\t  emails: ['default@mycomp.org'],\n\t  phoneNumbers: [],\n\t});\n\n\nIf you need an information from an other collection while denormalizing an event, you can require such a collection and make some lookups.\nfor example\n\n\tcol.findViewModels({ my: 'value' }, function (err, vms) {});\n\nor\n\n\tcol.loadViewModel('id', function (err, vm) {});\n\nor\n\n\tcol.loadViewModelIfExists('id', function (err, vm) {});\n\nBut be careful with this!\n\n## ViewBuilder\nEach viewBuilder is dedicated to a specific event. It reacts on an event and denormalizes that event in an appropriate collection.\n\nViewbuilders are structured by collection (not by context).\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineViewBuilder({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  version: 2,\n\n\t  // optional, if not defined or not found it will generate a new viewmodel with new id\n\t  id: 'aggregate.id',\n\n\t  // optional, suppresses auto-creation of new view model if none matching the id can be found, default is true\n      autoCreate: true,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  payload: 'payload',\n\n\t  // optional, default Infinity, all view-builders will be sorted by this value\n      priority: 1\n\t}, function (data, vm) { // instead of function you can define\n\t                         // a string with default handling ('create', 'update', 'delete')\n\t                         // or function that expects a callback (i.e. function (data, vm, callback) {})\n\n\t  // if you have multiple concurrent events that targets the same vm, you can catch it like this:\n\t  // during a replay the denormalization finishes and the retry does not happen\n\t  if (vm.actionOnCommit === 'create') {\n\t  \treturn this.retry(); // hint: do not use arrow function in this scope when using this.retry()\n\t  \t// or\n\t  \t//return this.retry(100); // retries to denormalize again in 0-100ms\n\t  \t// or\n\t  \t//return this.retry({ from: 500, to: 8000 }); // retries to denormalize again in 500-8000ms\n\t  }\n\n\t  vm.set('firstname', data.firstname);\n\t  vm.set('lastname', data.lastname);\n\t});\n\n### ViewBuilder for multiple viewmodels in a collection\n\nBe careful with the query!\n\nA lot of viewmodels can slow down the denormalization process!\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineViewBuilder({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  version: 2,\n\n\t  // optional, if not defined or not found it will generate a new viewmodel with new id\n\t  query: { group: 'admins' },\n\n\t  // optional, if not defined it will pass the whole event...\n\t  payload: 'payload',\n\n\t  // optional, default Infinity, all view-builders will be sorted by this value\n\t  priority: 1\n\t}, function (data, vm) { // instead of function you can define\n\t                         // a string with default handling ('create', 'update', 'delete')\n\t                         // or function that expects a callback (i.e. function (data, vm, callback) {})handling ('create', 'update', 'delete')\n\t  vm.set('firstname', data.firstname);\n\t  vm.set('lastname', data.lastname);\n\t  //this.remindMe({ that: 'important value' });\n\t  //this.retry();\n\t});\n\t// optional define a function to that returns an id that will be used as viewmodel id when id not specified in options or found\n\t//.useAsId(function (evt) {\n\t//  return 'newId';\n\t//});\n\t// or\n\t//.useAsId(function (evt, callback) {\n\t//  callback(null, 'newId');\n\t//});\t\n\t// optional define a function that returns a query that will be used as query to find the viewmodels (but do not define the query in the options)\n\t//.useAsQuery(function (evt) {\n\t//  return { my: evt.payload.my };\n\t//});\n\t// or async\n\t//.useAsQuery(function (evt, callback) {\n\t//  callback(null, { my: evt.payload.my });\n\t//});\n\t// optional define a function that returns a list of items, for each the viewbuilder will run.\n\t//.executeForEach(function (evt) {\n\t//  return [{ init: 'value1' }, { init: 'value2' }];\n\t//});\n\t// or async\n\t//.executeForEach(function (evt, callback) {\n\t//  callback(null, [{ init: 'value1' }, { init: 'value2' }]);\n\t//});\n\t//\n\t// optional define a function that checks if an event should be handled ( before vm is loaded )\n\t//.defineShouldHandleEvent(function (evt) {\n\t//  return true;\n\t//});\n\t// or\n\t//.defineShouldHandleEvent(function (evt, callback) {\n\t//  callback(null, true');\n\t//});\n\t//\n\t// optional define a function that checks if an event should be handled ( after vm is loaded )\n\t//.defineShouldHandle(function (evt, vm) {\n\t//  return true;\n\t//});\n\t// or\n\t//.defineShouldHandle(function (evt, vm, callback) {\n\t//  callback(null, true');\n\t//});\n\t//\n\t// optional define a function that checks if an event should be handled\n\t//.onAfterCommit(function (evt, vm) {\n\t//  //var memories = this.getReminder();\n\t//  //console.log(memories.that); // 'important value'\n\t//  //doSomethingStrange()\n\t//});\n\t// or\n\t//.onAfterCommit(function (evt, vm, callback) {\n\t//  var memories = this.getReminder();\n\t//  //console.log(memories.that); // 'important value'\n\t//  // doSomethingStrange(callback)\n\t//  callback(memories.that === 'important value' ? null : new Error('important value not set'));\n\t//});\n\n## EventExtender\n\n### for a collection (in a collection folder)\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineEventExtender({\n  // module.exports = require('cqrs-eventdenormalizer').definePreEventExtender({ // same api as normal EventExtenders but executed before viewBuilder so the extended event can be used\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  // if set to -1, it will ignore the version\n\t  version: 2//,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  // payload: 'payload'\n\t}, function (evt, col, callback) {\n\t  // col.loadViewModel()... or from somewhere else... (col.findViewModels( /* see https://github.com/adrai/node-viewmodel#find */ ))\n\t  evt.extended = true;\n\t  callback(null, evt);\n\t});\n\n\t// or\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineEventExtender({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  // if set to -1, it will ignore the version\n\t  version: 2,\n\n\t  // if defined it will load the viewmodel\n\t  id: 'payload.id'//,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  // payload: 'payload'\n\t},\n\tfunction (evt, vm) {\n\t  evt.extended = vm.get('myValue');\n\t  return evt;\n\t});\n\n\t// or\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineEventExtender({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  // if set to -1, it will ignore the version\n\t  version: 2,\n\n\t  // if defined it will load the viewmodel\n\t  id: 'payload.id'//,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  // payload: 'payload'\n\t},\n\tfunction (evt, vm, callback) {\n\t  evt.extended = vm.get('myValue');\n\t  callback(null, evt);\n\t});\n\t// optional define a function to that returns an id that will be used as viewmodel id when id not specified in options or found\n\t//.useAsId(function (evt) {\n\t//  return 'newId';\n\t//});\n\t// or\n\t//.useAsId(function (evt, callback) {\n\t//  callback(null, 'newId');\n\t//});\t\n\t\n\n### not for a collection\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineEventExtender({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  // if set to -1, it will ignore the version\n\t  version: 2//,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  // payload: 'payload'\n\t}, function (evt) {\n\t  evt.extended = true;\n\t  return evt;\n\t});\n\n\t// or\n\n\tmodule.exports = require('cqrs-eventdenormalizer').defineEventExtender({\n\t  // optional, default is file name without extension,\n\t  // if name is '' it will handle all events that matches\n\t  name: 'enteredNewPerson',\n\n\t  // optional\n\t  aggregate: 'person',\n\n\t  // optional\n\t  context: 'hr',\n\n\t  // optional, default is 0\n\t  // if set to -1, it will ignore the version\n\t  version: 2//,\n\n\t  // optional, if not defined it will pass the whole event...\n\t  // payload: 'payload'\n\t}, function (evt, callback) {\n\t  evt.extended = true;\n\t  callback(null, evt);\n\t});\n\n\n## Replay events\n\nReplay whenever you want...\n\n\tdenormalizer.replay([/* ordered array of events */], function (err) {\n\t  if (err) { console.log(err); }\n\t});\n\nor when catching some events:\n\n\tdenormalizer.onEventMissing(function (info, evt) {\n\n\t  // grab the missing events, depending from info values...\n\t  // info.aggregateId\n\t  // info.aggregateRevision\n\t  // info.aggregate\n\t  // info.context\n\t  // info.guardRevision\n\t  // and call handle...\n\t  denormalizer.handle(missingEvent, function (err) {\n\t    if (err) { console.log(err); }\n\t  });\n\n\t});\n\n\tyou can skip onEventMissing from being called, if provided, by adding the option `skipOnEventMissing` to the denormalizer. Checkout the usage section for more information.\n\nor depending on the last guarded event:\n\n\tdenormalizer.getLastEvent(function (err, evt) {\n\n\t  if (event.occurredAt \u003c Date.now()) {\n\t  \t// ...\n\t  }\n\n\t});\n\n### streamed\n\n\tdenormalizer.replayStreamed(function (replay, done) {\n\n\t  replay(evt1);\n\t  replay(evt2);\n\t  replay(evt3);\n\n\t  done(function (err) {\n\t    if (err) { console.log(err); }\n\t  });\n\n\t});\n\n### if you want to clear the readModel before replaying...\n\n\tdenormalizer.clear(function (err) {\n\t});\n\n## ES6 default exports\nImporting ES6 style default exports is supported for all definitions where you also use `module.exports`:\n```\nmodule.exports = defineCollection({...});\n```\nworks as well as \n```\nexports.default = defineCollection({...});\n```\nas well as (must be transpiled by babel or tsc to be runnable in node)\n```\nexport default defineCollection({...});\n```\n\nAlso: \n```\nexports.default = defineViewBuilder({...});\nexports.default = defineEventExtender({...});\n// etc...\n```\nExports other than the default export are then ignored by this package's structure loader.\n\n[Release notes](https://github.com/adrai/node-cqrs-eventdenormalizer/blob/master/releasenotes.md)\n\n\n# License\n\nCopyright (c) 2019 Adriano Raiano\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fnode-cqrs-eventdenormalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenativeweb%2Fnode-cqrs-eventdenormalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenativeweb%2Fnode-cqrs-eventdenormalizer/lists"}