Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to TypeScript #21

Merged
merged 27 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
07b8c68
Fix: Vulnerability in minimist dependency
snatalenko Aug 28, 2022
6737d55
Refactor: Migrate to TS and Jest
snatalenko Sep 6, 2022
8234b49
Restore coveralls dependency
snatalenko Sep 6, 2022
6d9b2e8
Expose _map of InMemoryView as protected property
snatalenko Sep 6, 2022
58ca0b5
Drop unused utility
snatalenko Sep 6, 2022
be09581
Export getMessageHandlerNames utility
snatalenko Sep 6, 2022
eec585d
Decrease command processing failure logging level to "warn"
snatalenko Sep 6, 2022
85acd90
Register default messageBus in DI builder
snatalenko Sep 6, 2022
269fbc9
Drop incorrect argument validation in EventStore constructor
snatalenko Sep 6, 2022
f1a8477
Improve restoring process logging
snatalenko Sep 6, 2022
ba1e6b7
Tweak ts-jest config to improve tests performance
snatalenko Apr 7, 2023
45ddd9d
Change transpiler target to ESNext
snatalenko Apr 7, 2023
ff995ed
Fix scripts for running integration tests
snatalenko Apr 7, 2023
97cef37
Update dependencies
snatalenko Aug 29, 2023
8afd875
Update dependencies
snatalenko Jul 19, 2024
433ce05
Fix getAllEvents interface
snatalenko Jul 21, 2024
67fa908
Make InMemoryEventStorage async
snatalenko Jul 31, 2024
4fb0110
Add pretest and clean scripts
snatalenko Aug 2, 2024
c6ce889
Quick-fix integration tests
snatalenko Aug 2, 2024
88633ba
Remove default type from AbstractProjection view for better compatibi…
snatalenko Aug 2, 2024
1422421
Update dependencies
snatalenko Aug 2, 2024
1133100
Add test github action
snatalenko Aug 2, 2024
85a2d61
Add audit script, fix node versions
snatalenko Aug 2, 2024
0a47737
Separate github workflows for tests and coveralls
snatalenko Aug 2, 2024
98ff29f
Add script badges to readme
snatalenko Aug 2, 2024
cc12970
Fix "Tests" badge
snatalenko Aug 2, 2024
2ee27aa
Delete travis config
snatalenko Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Audit

on: ["push", "pull_request"]

jobs:
audit:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm audit --parseable --production --audit-level=moderate
22 changes: 22 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Coveralls

on: ["push", "pull_request"]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --no-optional
env:
CI: true
- run: npm run test:coverage
- name: Coveralls
uses: coverallsapp/github-action@v2
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Tests

on: ["push", "pull_request"]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --no-optional
env:
CI: true
- run: npm run test
- run: npm run test:integration
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ app/tests/coverage/
.bower-*/
coverage/
.nyc_output/
dist/
*.tgz

# IDE's
# =====
Expand Down
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ tests/
.eslintrc.json
.eslintignore
.gitignore
.travis.yml
book.json
tsconfig.json
jsconfig.json
jest.config.ts
*.tgz
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ node-cqrs
=========

[![NPM Version](https://img.shields.io/npm/v/node-cqrs.svg)](https://www.npmjs.com/package/node-cqrs)
[![Build Status](https://secure.travis-ci.org/snatalenko/node-cqrs.svg?branch=master)](http://travis-ci.org/snatalenko/node-cqrs)
[![Audit Status](https://github.com/snatalenko/node-cqrs/actions/workflows/audit.yml/badge.svg)](https://github.com/snatalenko/node-cqrs/actions/workflows/audit.yml)
[![Tests Status](https://github.com/snatalenko/node-cqrs/actions/workflows/tests.yml/badge.svg)](https://github.com/snatalenko/node-cqrs/actions/workflows/tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/snatalenko/node-cqrs/badge.svg?branch=master)](https://coveralls.io/github/snatalenko/node-cqrs?branch=master)
[![NPM Downloads](https://img.shields.io/npm/dm/node-cqrs.svg)](https://www.npmjs.com/package/node-cqrs)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict';

const { expect } = require('chai');
const { createContainer, createBaseInstances } = require('../../examples/user-domain');
const { createContainer, createBaseInstances } = require('../user-domain');
const { nextCycle } = require('../../src/infrastructure/utils');

describe('user-domain example', () => {

const testEventFlow = async container => {

const { commandBus, eventStore } = container;

// HACK: let projection restoring to start before emitting new events
await nextCycle();

// we send a command to an aggregate that does not exist yet (userAggregateId = undefined),
// a new instance will be created automatically
let userAggregateId;
Expand Down Expand Up @@ -51,7 +55,10 @@ describe('user-domain example', () => {

const { commandBus, eventStore, users } = container;

commandBus.send('createUser', undefined, {
// HACK: let projection restoring to start before emitting new events
await nextCycle();

await commandBus.send('createUser', undefined, {
payload: {
username: 'sherlock',
password: 'test'
Expand Down
10 changes: 4 additions & 6 deletions examples/user-domain/UserAggregate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
'use strict';

const { AbstractAggregate } = require('../../src'); // node-cqrs
const { AbstractAggregate } = require('../..'); // node-cqrs

const crypto = require('crypto');

Expand Down Expand Up @@ -68,12 +68,10 @@ class UserAggregate extends AbstractAggregate {
}

/**
* Aggregate state
*
* @readonly
* Creates an instance of UserAggregate
*/
get state() {
return this._state || (this._state = new UserAggregateState());
constructor({ id, events }) {
super({ id, events, state: new UserAggregateState() });
}

/**
Expand Down
4 changes: 2 additions & 2 deletions examples/user-domain/UsersProjection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
'use strict';

const { AbstractProjection } = require('../../src'); // node-cqrs
const { AbstractProjection } = require('../..'); // node-cqrs

/**
* Users projection listens to events and updates associated view (read model)
Expand Down Expand Up @@ -29,7 +29,7 @@ class UsersProjection extends AbstractProjection {
* userCreated event handler
*
* @param {object} event
* @param {Identifier} event.aggregateId
* @param {import('../../src').Identifier} event.aggregateId
* @param {object} event.payload
* @param {string} event.payload.username
* @param {string} event.payload.passwordHash
Expand Down
10 changes: 6 additions & 4 deletions examples/user-domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const {
InMemoryEventStorage,
CommandBus,
EventStore,
AggregateCommandHandler
} = require('../../src'); // node-cqrs
AggregateCommandHandler,
InMemoryMessageBus
} = require('../..'); // node-cqrs
const UserAggregate = require('./UserAggregate');
const UsersProjection = require('./UsersProjection');

Expand All @@ -32,9 +33,10 @@ exports.createContainer = () => {
*/
exports.createBaseInstances = () => {
// create infrastructure services
const messageBus = new InMemoryMessageBus();
const storage = new InMemoryEventStorage();
const eventStore = new EventStore({ storage });
const commandBus = new CommandBus();
const eventStore = new EventStore({ storage, messageBus });
const commandBus = new CommandBus({ messageBus });

/** @type {IAggregateConstructor} */
const aggregateType = UserAggregate;
Expand Down
Loading
Loading