{"id":23397515,"url":"https://github.com/leocode/sequential-events","last_synced_at":"2026-02-10T12:34:02.753Z","repository":{"id":46248174,"uuid":"344817924","full_name":"leocode/sequential-events","owner":"leocode","description":"Synchronous NestJS application events","archived":false,"fork":false,"pushed_at":"2022-08-22T13:18:42.000Z","size":127,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-16T22:36:47.431Z","etag":null,"topics":["events","nest","nestjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocode.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":"2021-03-05T13:23:16.000Z","updated_at":"2024-12-23T15:53:35.000Z","dependencies_parsed_at":"2022-08-31T02:50:43.670Z","dependency_job_id":null,"html_url":"https://github.com/leocode/sequential-events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fsequential-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fsequential-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fsequential-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fsequential-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocode","download_url":"https://codeload.github.com/leocode/sequential-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247898519,"owners_count":21014722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["events","nest","nestjs"],"created_at":"2024-12-22T08:19:05.011Z","updated_at":"2026-02-10T12:34:02.747Z","avatar_url":"https://github.com/leocode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sequential-events\n\n**Library for NestJS**\n\nSequential events allows to separate contexts with events,\nthat (in opposite to https://docs.nestjs.com/recipes/cqrs) are evaluated sequentially (with optional transaction object passed around).\n\nIt is used to call actions from many domains, that together form one transaction.\nIf implementing process manager is overkill for you, `sequential-events` may be enough.\n\n## Use cases\n\n1. Process management (creating new tenant in application requiring creating entities in various domains)\n\n## Requirements\n\nInstall peer dependencies (or not, if you already have them - if you are using Nest.js you probably already have them)\n\n`yarn add @nestjs/common @nestjs/core reflect-metadata`\n\n`npm install --save @nestjs/common @nestjs/core reflect-metadata`\n\n## Installation\n\n`yarn add @leocode/sequential-events`\n\n`npm install --save @leocode/sequential-events`\n\n## Usage\n\n1. Import `SequentialEventsModule` into core application module\n2. Import `SequentialEventBus` into module, that is going to publish event\n3. Create event (see below)\n4. Create listener (see below)\n5. Publish event (see below)\n\n### Creating event\n\nEvent needs to implement interface `IEvent` and it should be a class:\n\n```ts\nimport { IEvent } from '@leocode/sequential-events';\n\nexport class TenantCreated implements IEvent {\n\n  constructor (public tenantId: string) {};\n}\n```\n\n### Creating listener\n\n1. Create class which serves as a handler:\n\n```ts\nimport { SequentialEventListener } from '@leocode/sequential-events';\nimport { ISequentialEventListener } from '@leocode/sequential-events';\n\n@SequentialEventListener(TenantCreated)\nexport class CreateOnboarding implements ISequentialEventListener\u003cTenantCreated, Transaction\u003e {\n  public constructor(\n    private onboardingFacade: OnboardingFacade,\n  ) {}\n\n  public async handle(event: TenantCreated, tx: Transaction | null): Promise\u003cvoid\u003e {\n    const tenantId = event.tenantId;\n\n    await this.onboardingFacade.createAdminOnboarding({\n      tenantId,\n    }, tx);\n  }\n}\n```\n\n2. Add handler as module's provider\n\n### Publish event\n\n```ts\nimport { SequentialEventBus } from '@leocode/sequential-events';\n\n@Injectable()\nexport class TenantService {\n  public constructor (\n    private sequentialEventBus: SequentialEventBus,\n  ) {}\n\n  public async createTenant(...) {\n    const transaction = ...;\n\n    const tenantId = ...;\n    const user = await this.createUser(..., transaction);\n\n    await this.sequentialEventBus.publishAll([\n      new TenantCreated(tenantId)\n    ], transaction);\n\n    return user;\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocode%2Fsequential-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocode%2Fsequential-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocode%2Fsequential-events/lists"}