From e83018f3a9eb247db31ca447c2157bcf2ff71497 Mon Sep 17 00:00:00 2001 From: Stanislav Natalenko Date: Thu, 29 Jan 2026 18:56:47 +0000 Subject: [PATCH 1/2] Build: Add ESM, CJS, and Browser builds --- README.md | 4 + examples/browser-smoke-test/README.md | 17 +++ examples/browser-smoke-test/index.html | 40 +++++++ examples/browser-smoke-test/main.js | 111 ++++++++++++++++++ examples/jsconfig.json | 32 +++++ examples/tsconfig.json | 13 ++ examples/user-domain-ts/UserAggregate.ts | 11 +- examples/user-domain-ts/UsersProjection.ts | 4 +- examples/user-domain-ts/index.ts | 8 +- examples/user-domain-ts/messages.ts | 3 +- examples/user-domain/UserAggregate.js | 2 +- examples/user-domain/UsersProjection.js | 4 +- examples/user-domain/index.js | 12 +- examples/user-domain/tests/index.test.js | 2 +- .../worker-projection/CounterProjection.cjs | 2 +- jsconfig.json | 20 +++- package.json | 26 ++-- scripts/etc/cjs-package.json | 3 + src/AbstractAggregate.ts | 4 +- src/AbstractProjection.ts | 8 +- src/AbstractSaga.ts | 4 +- src/AggregateCommandHandler.ts | 26 ++-- src/CommandBus.ts | 6 +- src/CqrsContainerBuilder.ts | 32 ++--- src/Event.ts | 2 +- src/EventDispatchPipeline.ts | 23 ++-- src/EventDispatcher.ts | 18 +-- src/EventStore.ts | 6 +- src/SagaEventHandler.ts | 8 +- src/in-memory/InMemoryEventStorage.ts | 6 +- src/in-memory/InMemoryLock.ts | 2 +- src/in-memory/InMemoryMessageBus.ts | 2 +- src/in-memory/InMemorySnapshotStorage.ts | 18 +-- src/in-memory/InMemoryView.ts | 6 +- src/in-memory/index.ts | 10 +- src/in-memory/utils/index.ts | 2 +- src/in-memory/utils/nextCycle.ts | 2 +- src/index.ts | 26 ++-- src/interfaces/IAggregate.ts | 8 +- src/interfaces/IAggregateSnapshotStorage.ts | 4 +- src/interfaces/ICommand.ts | 2 +- src/interfaces/ICommandBus.ts | 8 +- src/interfaces/IContainer.ts | 20 ++-- src/interfaces/IDispatchPipelineProcessor.ts | 4 +- src/interfaces/IEvent.ts | 4 +- src/interfaces/IEventBus.ts | 4 +- src/interfaces/IEventDispatcher.ts | 4 +- src/interfaces/IEventLocker.ts | 4 +- src/interfaces/IEventReceptor.ts | 4 +- src/interfaces/IEventSet.ts | 2 +- src/interfaces/IEventStorageReader.ts | 8 +- src/interfaces/IEventStorageWriter.ts | 2 +- src/interfaces/IEventStore.ts | 12 +- src/interfaces/IEventStream.ts | 2 +- src/interfaces/IIdentifierProvider.ts | 4 +- src/interfaces/IMessage.ts | 4 +- src/interfaces/IMessageBus.ts | 6 +- src/interfaces/IObjectStorage.ts | 2 +- src/interfaces/IObservable.ts | 4 +- src/interfaces/IObservableQueueProvider.ts | 4 +- src/interfaces/IObserver.ts | 2 +- src/interfaces/IProjection.ts | 8 +- src/interfaces/ISaga.ts | 8 +- src/interfaces/ISnapshotEvent.ts | 2 +- src/interfaces/IViewLocker.ts | 2 +- src/interfaces/index.ts | 58 ++++----- src/rabbitmq/IContainer.ts | 2 +- src/rabbitmq/RabbitMqEventBus.ts | 4 +- src/rabbitmq/RabbitMqGateway.ts | 8 +- src/rabbitmq/index.ts | 4 +- src/rabbitmq/utils/index.ts | 2 +- src/sqlite/AbstractSqliteAccessor.ts | 4 +- src/sqlite/AbstractSqliteObjectProjection.ts | 6 +- src/sqlite/AbstractSqliteView.ts | 8 +- src/sqlite/SqliteEventLocker.ts | 12 +- src/sqlite/SqliteObjectStorage.ts | 6 +- src/sqlite/SqliteObjectView.ts | 6 +- src/sqlite/SqliteViewLocker.ts | 10 +- src/sqlite/index.ts | 16 +-- src/sqlite/queries/index.ts | 4 +- src/sqlite/utils/getEventId.ts | 6 +- src/sqlite/utils/index.ts | 4 +- src/utils/Lock.ts | 14 ++- src/utils/getHandler.ts | 2 +- src/utils/index.ts | 26 ++-- src/utils/setupOneTimeEmitterSubscription.ts | 2 +- src/utils/subscribe.ts | 6 +- src/utils/validateHandlers.ts | 2 +- src/workers/AbstractWorkerProjection.ts | 10 +- src/workers/index.ts | 2 +- src/workers/utils/createWorker.ts | 2 +- src/workers/utils/index.ts | 4 +- tests/integration/sqlite/SqliteView.test.ts | 2 +- tests/unit/EventStore.test.ts | 2 +- tests/unit/dispatch-pipeline.test.ts | 2 +- tests/unit/sqlite/SqliteEventLocker.test.ts | 2 +- tests/unit/sqlite/SqliteObjectStorage.test.ts | 2 +- tests/unit/sqlite/SqliteObjectView.test.ts | 2 +- tests/unit/sqlite/SqliteViewLocker.test.ts | 2 +- .../workers/fixtures/ProjectionFixture.cjs | 4 +- .../workers/fixtures/ProjectionFixture.ts | 37 ------ tests/unit/workers/fixtures/jsconfig.json | 32 +++++ tsconfig.browser.json | 11 ++ tsconfig.cjs.json | 10 ++ tsconfig.esm.json | 13 ++ tsconfig.json | 57 +++++---- 106 files changed, 677 insertions(+), 394 deletions(-) create mode 100644 examples/browser-smoke-test/README.md create mode 100644 examples/browser-smoke-test/index.html create mode 100644 examples/browser-smoke-test/main.js create mode 100644 examples/jsconfig.json create mode 100644 examples/tsconfig.json create mode 100644 scripts/etc/cjs-package.json delete mode 100644 tests/unit/workers/fixtures/ProjectionFixture.ts create mode 100644 tests/unit/workers/fixtures/jsconfig.json create mode 100644 tsconfig.browser.json create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json diff --git a/README.md b/README.md index e8b19eb..384bec7 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ Message delivery is handled by the following components (in order of appearance) - [examples/worker-projection](examples/worker-projection) projection in a worker thread - [examples/user-domain-own-implementation](examples/user-domain-own-implementation/index.ts) minimal, framework-free CQRS/ES example in 1 file +TS examples can be run with `node` without transpiling + ## Installation ```bash @@ -76,9 +78,11 @@ npm i node-cqrs ``` Tested under + - Node 18 - Node 20 - Node 22 +- Browser (through [browserify](https://browserify.org)) ### Peer Dependencies diff --git a/examples/browser-smoke-test/README.md b/examples/browser-smoke-test/README.md new file mode 100644 index 0000000..c488ff0 --- /dev/null +++ b/examples/browser-smoke-test/README.md @@ -0,0 +1,17 @@ +# Browser smoke test + +This example is meant to quickly verify that the core `node-cqrs` APIs work in a browser environment. + +## Run + +From the repo root: + +```bash +npm run build:browser +``` + +Then open `examples/browser-smoke-test/index.html` directly (e.g. double-click it). + +Notes: +- The bundle is written to `dist/browser/node-cqrs.iife.js`. +- If you don’t have Browserify installed locally, run `npm i -D browserify`. diff --git a/examples/browser-smoke-test/index.html b/examples/browser-smoke-test/index.html new file mode 100644 index 0000000..231e1cf --- /dev/null +++ b/examples/browser-smoke-test/index.html @@ -0,0 +1,40 @@ + + + + + + + node-cqrs browser smoke test + + + + +

node-cqrs browser smoke test

+

Open DevTools console for details.

+
Running…
+ + + + + diff --git a/examples/browser-smoke-test/main.js b/examples/browser-smoke-test/main.js new file mode 100644 index 0000000..9bd93c6 --- /dev/null +++ b/examples/browser-smoke-test/main.js @@ -0,0 +1,111 @@ +(function () { + const out = document.getElementById('out'); + + function write(line) { + out.textContent = `${out.textContent}\n${line}`; + } + + function setStatusOk() { + out.classList.remove('fail'); + out.classList.add('ok'); + } + + function setStatusFail() { + out.classList.remove('ok'); + out.classList.add('fail'); + } + + if (!globalThis.Cqrs) + throw new Error('Cqrs bundle is not loaded. Run `npm run build:browser` first.'); + + const { + AbstractAggregate, + AbstractProjection, + ContainerBuilder, + InMemoryEventStorage + } = globalThis.Cqrs; + + class UserAggregateState { + userCreated(event) { + this.password = event.payload.password; + } + + passwordChanged(event) { + this.password = event.payload.newPassword; + } + } + + class UserAggregate extends AbstractAggregate { + constructor(params) { + super(params); + this.state = new UserAggregateState(); + } + + createUser(payload) { + this.emit('userCreated', { + username: payload.username, + password: payload.password + }); + } + + changePassword(payload) { + if (payload.oldPassword !== this.state.password) + throw new Error('Invalid password'); + + this.emit('passwordChanged', { + newPassword: payload.newPassword + }); + } + } + + class UsersProjection extends AbstractProjection { + constructor() { + super(); + this.view = new Map(); + } + + userCreated(event) { + this.view.set(event.aggregateId, { username: event.payload.username }); + } + } + + async function main() { + out.textContent = ''; + write('Building container…'); + + const builder = new ContainerBuilder(); + builder.register(InMemoryEventStorage) + .as('eventStorageReader') + .as('eventStorageWriter'); + builder.registerAggregate(UserAggregate); + builder.registerProjection(UsersProjection, 'users'); + + const container = builder.container(); + const { users, commandBus } = container; + + write('Sending commands…'); + const [userCreated] = await commandBus.send('createUser', undefined, { + payload: { username: 'john', password: 'magic' }, + context: {} + }); + + await commandBus.send('changePassword', userCreated.aggregateId, { + payload: { oldPassword: 'magic', newPassword: 'no magic' }, + context: {} + }); + + const user = users.get(userCreated.aggregateId); + if (!user || user.username !== 'john') + throw new Error(`Unexpected user view value: ${JSON.stringify(user)}`); + + write(`OK: ${JSON.stringify(user)}`); + setStatusOk(); + } + + main().catch(err => { + console.error(err); + out.textContent = `FAILED: ${err?.message ?? String(err)}`; + setStatusFail(); + }); +}()); + diff --git a/examples/jsconfig.json b/examples/jsconfig.json new file mode 100644 index 0000000..6653e49 --- /dev/null +++ b/examples/jsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "es2022", + "module": "commonjs", + "moduleResolution": "node", + "checkJs": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "lib": [ + "es2022", + "dom" + ], + "baseUrl": "..", + "paths": { + "node-cqrs": [ + "types/index.d.ts" + ], + "node-cqrs/*": [ + "types/*/index.d.ts" + ] + } + }, + "include": [ + "**/*" + ], + "exclude": [ + "../node_modules", + "../dist", + "**/bundle.js", + "browser-smoke-test/**" + ] +} diff --git a/examples/tsconfig.json b/examples/tsconfig.json new file mode 100644 index 0000000..875f1f5 --- /dev/null +++ b/examples/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "lib": [ + "ES2022" + ], + "strict": true, + "noEmit": true, + "allowImportingTsExtensions": true + } +} diff --git a/examples/user-domain-ts/UserAggregate.ts b/examples/user-domain-ts/UserAggregate.ts index 328b15e..b0b9f9d 100644 --- a/examples/user-domain-ts/UserAggregate.ts +++ b/examples/user-domain-ts/UserAggregate.ts @@ -1,6 +1,11 @@ -import type { ChangePasswordCommandPayload, CreateUserCommandPayload, PasswordChangedEvent, UserCreatedEvent } from './messages'; -import { AbstractAggregate } from '../..'; -import { md5 } from './utils'; +import { AbstractAggregate } from 'node-cqrs'; +import { md5 } from './utils.ts'; +import type { + ChangePasswordCommandPayload, + CreateUserCommandPayload, + PasswordChangedEvent, + UserCreatedEvent +} from './messages.ts'; class UserAggregateState { passwordHash!: string; diff --git a/examples/user-domain-ts/UsersProjection.ts b/examples/user-domain-ts/UsersProjection.ts index 49aeb21..4f9755a 100644 --- a/examples/user-domain-ts/UsersProjection.ts +++ b/examples/user-domain-ts/UsersProjection.ts @@ -1,5 +1,5 @@ -import type { UserCreatedEvent } from './messages'; -import { AbstractProjection } from '../..'; +import { AbstractProjection } from 'node-cqrs'; +import type { UserCreatedEvent } from './messages.ts'; export type UsersView = Map; diff --git a/examples/user-domain-ts/index.ts b/examples/user-domain-ts/index.ts index 9166bcb..c6545e7 100644 --- a/examples/user-domain-ts/index.ts +++ b/examples/user-domain-ts/index.ts @@ -1,7 +1,7 @@ -import { ContainerBuilder, IContainer, InMemoryEventStorage } from '../..'; -import type { ChangePasswordCommandPayload, CreateUserCommandPayload } from './messages'; -import { UserAggregate } from './UserAggregate'; -import { UsersProjection, UsersView } from './UsersProjection'; +import { ContainerBuilder, type IContainer, InMemoryEventStorage } from 'node-cqrs'; +import type { ChangePasswordCommandPayload, CreateUserCommandPayload } from './messages.ts'; +import { UserAggregate } from './UserAggregate.ts'; +import { UsersProjection, type UsersView } from './UsersProjection.ts'; interface MyDiContainer extends IContainer { users: UsersView; diff --git a/examples/user-domain-ts/messages.ts b/examples/user-domain-ts/messages.ts index 8084058..f721677 100644 --- a/examples/user-domain-ts/messages.ts +++ b/examples/user-domain-ts/messages.ts @@ -1,4 +1,4 @@ -import type { IEvent } from '../../types'; +import type { IEvent } from 'node-cqrs'; export type CreateUserCommandPayload = { username: string, password: string }; export type UserCreatedEventPayload = { username: string, passwordHash: string }; @@ -7,4 +7,3 @@ export type UserCreatedEvent = IEvent; export type ChangePasswordCommandPayload = { oldPassword: string, newPassword: string }; export type PasswordChangedEventPayload = { passwordHash: string }; export type PasswordChangedEvent = IEvent; - diff --git a/examples/user-domain/UserAggregate.js b/examples/user-domain/UserAggregate.js index 13d2299..abe0bb1 100644 --- a/examples/user-domain/UserAggregate.js +++ b/examples/user-domain/UserAggregate.js @@ -1,7 +1,7 @@ // @ts-check 'use strict'; -const { AbstractAggregate } = require('../..'); // node-cqrs +const { AbstractAggregate } = require('node-cqrs'); const crypto = require('crypto'); diff --git a/examples/user-domain/UsersProjection.js b/examples/user-domain/UsersProjection.js index 6e21124..3c1cf1b 100644 --- a/examples/user-domain/UsersProjection.js +++ b/examples/user-domain/UsersProjection.js @@ -1,7 +1,7 @@ // @ts-check 'use strict'; -const { AbstractProjection } = require('../..'); // node-cqrs +const { AbstractProjection } = require('node-cqrs'); /** * Users projection listens to events and updates associated view (read model) @@ -29,7 +29,7 @@ class UsersProjection extends AbstractProjection { * userCreated event handler * * @param {object} event - * @param {import('../../src').Identifier} event.aggregateId + * @param {import('node-cqrs').Identifier} event.aggregateId * @param {object} event.payload * @param {string} event.payload.username * @param {string} event.payload.passwordHash diff --git a/examples/user-domain/index.js b/examples/user-domain/index.js index e276a54..f0b02ea 100644 --- a/examples/user-domain/index.js +++ b/examples/user-domain/index.js @@ -7,9 +7,9 @@ const { EventStore, AggregateCommandHandler, InMemoryMessageBus, - EventDispatcher -} = require('../..'); // node-cqrs -const { InMemorySnapshotStorage } = require('../..'); + EventDispatcher, + InMemorySnapshotStorage +} = require('node-cqrs'); const UserAggregate = require('./UserAggregate'); const UsersProjection = require('./UsersProjection'); @@ -47,14 +47,14 @@ exports.createBaseInstances = () => { const eventStore = new EventStore({ eventStorageReader: storage, eventBus, eventDispatcher }); const commandBus = new CommandBus(); - /** @type {import('../..').IAggregateConstructor} */ + /** @type {import('node-cqrs').IAggregateConstructor} */ const aggregateType = UserAggregate; - /** @type {import('../..').ICommandHandler} */ + /** @type {import('node-cqrs').ICommandHandler} */ const userCommandHandler = new AggregateCommandHandler({ eventStore, aggregateType }); userCommandHandler.subscribe(commandBus); - /** @type {import('../..').IProjection} */ + /** @type {import('node-cqrs').IProjection} */ const usersProjection = new UsersProjection(); usersProjection.subscribe(eventStore); diff --git a/examples/user-domain/tests/index.test.js b/examples/user-domain/tests/index.test.js index 00f293e..a5367ac 100644 --- a/examples/user-domain/tests/index.test.js +++ b/examples/user-domain/tests/index.test.js @@ -1,7 +1,7 @@ 'use strict'; const { expect } = require('chai'); -const { createContainer, createBaseInstances } = require('..'); +const { createContainer, createBaseInstances } = require('../index.js'); describe('user-domain example', () => { diff --git a/examples/worker-projection/CounterProjection.cjs b/examples/worker-projection/CounterProjection.cjs index f2aadd0..3247bcf 100644 --- a/examples/worker-projection/CounterProjection.cjs +++ b/examples/worker-projection/CounterProjection.cjs @@ -1,4 +1,4 @@ -const { AbstractWorkerProjection } = require('../../dist/workers'); +const { AbstractWorkerProjection } = require('node-cqrs/workers'); class CounterView { counter = 0; diff --git a/jsconfig.json b/jsconfig.json index 1d876e5..b15664f 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,15 +1,29 @@ { "compilerOptions": { - "target": "es6", + "target": "es2022", "module": "commonjs", + "moduleResolution": "node", + "baseUrl": ".", + "paths": { + "node-cqrs": [ + "./types/index.d.ts" + ], + "node-cqrs/*": [ + "./types/*/index.d.ts" + ] + }, "allowSyntheticDefaultImports": true, "checkJs": true, "resolveJsonModule": true, "lib": [ - "es2018" + "es2022", + "dom" ] }, "exclude": [ - "node_modules" + "node_modules", + "dist", + "dist/**", + "examples/**/bundle.js" ] } diff --git a/package.json b/package.json index 15b407c..0fab651 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "node-cqrs", "version": "1.0.0-rc.33", "description": "Basic ES6 backbone for CQRS app development", + "type": "module", "keywords": [ "cqrs", "eventsourcing" @@ -10,7 +11,7 @@ "type": "git", "url": "https://github.com/snatalenko/node-cqrs.git" }, - "main": "./dist/index.js", + "main": "./dist/cjs/index.js", "types": "./types/index.d.ts", "typesVersions": { "*": { @@ -27,23 +28,23 @@ }, "exports": { ".": { - "require": "./dist/index.js", - "import": "./dist/index.js", + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js", "types": "./types/index.d.ts" }, "./workers": { - "require": "./dist/workers/index.js", - "import": "./dist/workers/index.js", + "require": "./dist/cjs/workers/index.js", + "import": "./dist/esm/workers/index.js", "types": "./types/workers/index.d.ts" }, "./rabbitmq": { - "require": "./dist/rabbitmq/index.js", - "import": "./dist/rabbitmq/index.js", + "require": "./dist/cjs/rabbitmq/index.js", + "import": "./dist/esm/rabbitmq/index.js", "types": "./types/rabbitmq/index.d.ts" }, "./sqlite": { - "require": "./dist/sqlite/index.js", - "import": "./dist/sqlite/index.js", + "require": "./dist/cjs/sqlite/index.js", + "import": "./dist/esm/sqlite/index.js", "types": "./types/sqlite/index.d.ts" } }, @@ -56,14 +57,17 @@ "node": ">=18.0.0" }, "scripts": { - "cleanup": "rm -rf ./dist ./types ./coverage && tsc --build --clean", + "cleanup": "rm -rf ./dist ./types ./coverage", "pretest": "npm run build", "test": "jest tests/unit examples/user-domain/tests", "test:coverage": "npm t -- --collect-coverage", "test:rabbitmq": "jest --verbose tests/integration/rabbitmq", "test:sqlite": "jest --verbose tests/integration/sqlite", "changelog": "conventional-changelog -n ./scripts/changelog -r 0 > CHANGELOG.md", - "build": "tsc --build", + "build:cjs": "tsc -p ./tsconfig.cjs.json && cp ./scripts/etc/cjs-package.json ./dist/cjs/package.json", + "build:esm": "tsc -p ./tsconfig.esm.json", + "build:browser": "tsc -p ./tsconfig.browser.json && npx browserify dist/browser/cjs/index.js --standalone Cqrs --outfile ./dist/browser/bundle.iife.js", + "build": "npm run build:esm && npm run build:cjs", "prepare": "npm run build", "preversion": "npm test", "version": "./scripts/cleanup_obsolete_tags.sh v$npm_package_version && npm run changelog && git add CHANGELOG.md", diff --git a/scripts/etc/cjs-package.json b/scripts/etc/cjs-package.json new file mode 100644 index 0000000..5bbefff --- /dev/null +++ b/scripts/etc/cjs-package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/src/AbstractAggregate.ts b/src/AbstractAggregate.ts index 4c672d6..1b8d450 100644 --- a/src/AbstractAggregate.ts +++ b/src/AbstractAggregate.ts @@ -7,9 +7,9 @@ import { type IEventSet, type IAggregateConstructorParams, SNAPSHOT_EVENT_TYPE -} from './interfaces'; +} from './interfaces/index.ts'; -import { getClassName, validateHandlers, getHandler, getMessageHandlerNames } from './utils'; +import { getClassName, validateHandlers, getHandler, getMessageHandlerNames } from './utils/index.ts'; /** * Base class for Aggregate definition diff --git a/src/AbstractProjection.ts b/src/AbstractProjection.ts index b48b780..d6c98ec 100644 --- a/src/AbstractProjection.ts +++ b/src/AbstractProjection.ts @@ -1,5 +1,5 @@ -import { describe } from './Event'; -import { InMemoryView } from './in-memory/InMemoryView'; +import { describe } from './Event.ts'; +import { InMemoryView } from './in-memory/InMemoryView.ts'; import { type IViewLocker, type IEventLocker, @@ -11,7 +11,7 @@ import { type IEventStorageReader, isViewLocker, isEventLocker -} from './interfaces'; +} from './interfaces/index.ts'; import { getClassName, @@ -19,7 +19,7 @@ import { getHandler, subscribe, getMessageHandlerNames -} from './utils'; +} from './utils/index.ts'; export type AbstractProjectionParams = { diff --git a/src/AbstractSaga.ts b/src/AbstractSaga.ts index fa08b72..484f50e 100644 --- a/src/AbstractSaga.ts +++ b/src/AbstractSaga.ts @@ -1,6 +1,6 @@ -import { ICommand, Identifier, IEvent, ISaga, ISagaConstructorParams } from './interfaces'; +import type { ICommand, Identifier, IEvent, ISaga, ISagaConstructorParams } from './interfaces/index.ts'; -import { getClassName, validateHandlers, getHandler } from './utils'; +import { getClassName, validateHandlers, getHandler } from './utils/index.ts'; /** * Base class for Saga definition diff --git a/src/AggregateCommandHandler.ts b/src/AggregateCommandHandler.ts index 9c8c415..c8d86c8 100644 --- a/src/AggregateCommandHandler.ts +++ b/src/AggregateCommandHandler.ts @@ -1,18 +1,18 @@ -import { getClassName, Lock, MapAssertable } from './utils'; +import { getClassName, Lock, MapAssertable } from './utils/index.ts'; import { - IAggregate, - IAggregateConstructor, - IAggregateFactory, - ICommand, - ICommandHandler, - IContainer, - Identifier, - IEventSet, - IEventStore, - ILogger, - IObservable, + type IAggregate, + type IAggregateConstructor, + type IAggregateFactory, + type ICommand, + type ICommandHandler, + type IContainer, + type Identifier, + type IEventSet, + type IEventStore, + type ILogger, + type IObservable, isIObservable -} from './interfaces'; +} from './interfaces/index.ts'; /** * Aggregate command handler. diff --git a/src/CommandBus.ts b/src/CommandBus.ts index 0a2104d..57a86eb 100644 --- a/src/CommandBus.ts +++ b/src/CommandBus.ts @@ -1,5 +1,5 @@ -import { InMemoryMessageBus } from './in-memory'; -import { +import { InMemoryMessageBus } from './in-memory/index.ts'; +import type { ICommand, ICommandBus, IEventSet, @@ -7,7 +7,7 @@ import { ILogger, IMessageBus, IMessageHandler -} from './interfaces'; +} from './interfaces/index.ts'; export class CommandBus implements ICommandBus { diff --git a/src/CqrsContainerBuilder.ts b/src/CqrsContainerBuilder.ts index 8d7f0c7..158ba88 100644 --- a/src/CqrsContainerBuilder.ts +++ b/src/CqrsContainerBuilder.ts @@ -1,21 +1,21 @@ -import { ContainerBuilder, TypeConfig, TClassOrFactory } from 'di0'; -import { AggregateCommandHandler } from './AggregateCommandHandler'; -import { CommandBus } from './CommandBus'; -import { EventStore } from './EventStore'; -import { SagaEventHandler } from './SagaEventHandler'; -import { EventDispatcher } from './EventDispatcher'; -import { InMemoryMessageBus } from './in-memory'; -import { isClass } from './utils'; +import { ContainerBuilder, type TypeConfig, type TClassOrFactory } from 'di0'; +import { AggregateCommandHandler } from './AggregateCommandHandler.ts'; +import { CommandBus } from './CommandBus.ts'; +import { EventStore } from './EventStore.ts'; +import { SagaEventHandler } from './SagaEventHandler.ts'; +import { EventDispatcher } from './EventDispatcher.ts'; +import { InMemoryMessageBus } from './in-memory/index.ts'; +import { isClass } from './utils/isClass.ts'; import { - IAggregateConstructor, - ICommandHandler, - IContainer, - IEventReceptor, - IProjection, - IProjectionConstructor, - ISagaConstructor, + type IAggregateConstructor, + type ICommandHandler, + type IContainer, + type IEventReceptor, + type IProjection, + type IProjectionConstructor, + type ISagaConstructor, isDispatchPipelineProcessor -} from './interfaces'; +} from './interfaces/index.ts'; export class CqrsContainerBuilder extends ContainerBuilder { diff --git a/src/Event.ts b/src/Event.ts index fecaf16..86318e7 100644 --- a/src/Event.ts +++ b/src/Event.ts @@ -1,4 +1,4 @@ -import { IEvent } from './interfaces'; +import type { IEvent } from './interfaces/IEvent.ts'; /** * Get text description of an event for logging purposes diff --git a/src/EventDispatchPipeline.ts b/src/EventDispatchPipeline.ts index 340612d..bd32315 100644 --- a/src/EventDispatchPipeline.ts +++ b/src/EventDispatchPipeline.ts @@ -1,15 +1,15 @@ import { - DispatchPipelineBatch, - IEvent, - IDispatchPipelineProcessor, - IEventBus, + type DispatchPipelineBatch, + type IEvent, + type IDispatchPipelineProcessor, + type IEventBus, isDispatchPipelineProcessor, isSnapshotEvent -} from './interfaces'; +} from './interfaces/index.ts'; import { parallelPipe } from 'async-parallel-pipe'; import { AsyncIterableBuffer } from 'async-iterable-buffer'; -import { getClassName } from './utils'; +import { getClassName } from './utils/index.ts'; export type EventBatchEnvelope = { data: DispatchPipelineBatch<{ event?: IEvent }>; @@ -25,7 +25,12 @@ export class EventDispatchPipeline { #pipeline: AsyncIterableIterator | IterableIterator = this.#pipelineInput; #processing = false; - constructor(private readonly eventBus: IEventBus, private readonly concurrentLimit: number) { + readonly #eventBus; + readonly #concurrentLimit: number; + + constructor(eventBus: IEventBus, concurrentLimit: number) { + this.#eventBus = eventBus; + this.#concurrentLimit = concurrentLimit; } addProcessor(preprocessor: IDispatchPipelineProcessor) { @@ -37,7 +42,7 @@ export class EventDispatchPipeline { this.#processors.push(preprocessor); // Build a processing pipeline that runs preprocessors concurrently, preserving FIFO ordering - this.#pipeline = parallelPipe(this.#pipeline, this.concurrentLimit, async envelope => { + this.#pipeline = parallelPipe(this.#pipeline, this.#concurrentLimit, async envelope => { if (envelope.error) return envelope; @@ -79,7 +84,7 @@ export class EventDispatchPipeline { if (isSnapshotEvent(event)) continue; - await this.eventBus.publish(event, meta); + await this.#eventBus.publish(event, meta); events.push(event); } diff --git a/src/EventDispatcher.ts b/src/EventDispatcher.ts index ab11cbe..f8de8a1 100644 --- a/src/EventDispatcher.ts +++ b/src/EventDispatcher.ts @@ -1,13 +1,13 @@ import { - IEventDispatcher, - IDispatchPipelineProcessor, - IEventSet, - IEventBus, - isEventSet, - IContainer -} from './interfaces'; -import { InMemoryMessageBus } from './in-memory'; -import { EventBatchEnvelope, EventDispatchPipeline } from './EventDispatchPipeline'; + type IEventDispatcher, + type IDispatchPipelineProcessor, + type IEventSet, + type IEventBus, + type IContainer, + isEventSet +} from './interfaces/index.ts'; +import { InMemoryMessageBus } from './in-memory/index.ts'; +import { type EventBatchEnvelope, EventDispatchPipeline } from './EventDispatchPipeline.ts'; export class EventDispatcher implements IEventDispatcher { diff --git a/src/EventStore.ts b/src/EventStore.ts index d98efc6..a086fd1 100644 --- a/src/EventStore.ts +++ b/src/EventStore.ts @@ -20,12 +20,12 @@ import { isIEventStorageReader, isEventSet, isIObservableQueueProvider -} from './interfaces'; +} from './interfaces/index.ts'; import { getClassName, setupOneTimeEmitterSubscription -} from './utils'; -import { EventDispatcher } from './EventDispatcher'; +} from './utils/index.ts'; +import { EventDispatcher } from './EventDispatcher.ts'; export class EventStore implements IEventStore { diff --git a/src/SagaEventHandler.ts b/src/SagaEventHandler.ts index 6e784ff..b758191 100644 --- a/src/SagaEventHandler.ts +++ b/src/SagaEventHandler.ts @@ -1,5 +1,5 @@ -import * as Event from './Event'; -import { +import * as Event from './Event.ts'; +import type { ICommandBus, IContainer, IEvent, @@ -10,13 +10,13 @@ import { ISaga, ISagaConstructor, ISagaFactory -} from './interfaces'; +} from './interfaces/index.ts'; import { subscribe, getClassName, iteratorToArray -} from './utils'; +} from './utils/index.ts'; /** * Listens to Saga events, diff --git a/src/in-memory/InMemoryEventStorage.ts b/src/in-memory/InMemoryEventStorage.ts index d0b8d95..d3071d1 100644 --- a/src/in-memory/InMemoryEventStorage.ts +++ b/src/in-memory/InMemoryEventStorage.ts @@ -1,4 +1,4 @@ -import { +import type { IIdentifierProvider, IEvent, IEventSet, @@ -9,8 +9,8 @@ import { Identifier, IDispatchPipelineProcessor, DispatchPipelineBatch -} from '../interfaces'; -import { nextCycle } from './utils'; +} from '../interfaces/index.ts'; +import { nextCycle } from './utils/index.ts'; /** * A simple event storage implementation intended to use for tests only. diff --git a/src/in-memory/InMemoryLock.ts b/src/in-memory/InMemoryLock.ts index 8b853d1..ce6ac25 100644 --- a/src/in-memory/InMemoryLock.ts +++ b/src/in-memory/InMemoryLock.ts @@ -1,4 +1,4 @@ -import { Deferred } from '../utils'; +import { Deferred } from '../utils/index.ts'; export class InMemoryLock { diff --git a/src/in-memory/InMemoryMessageBus.ts b/src/in-memory/InMemoryMessageBus.ts index e424abf..73b02dd 100644 --- a/src/in-memory/InMemoryMessageBus.ts +++ b/src/in-memory/InMemoryMessageBus.ts @@ -5,7 +5,7 @@ import type { IMessageHandler, IObservable, IObservableQueueProvider -} from '../interfaces'; +} from '../interfaces/index.ts'; /** * Default implementation of the message bus. diff --git a/src/in-memory/InMemorySnapshotStorage.ts b/src/in-memory/InMemorySnapshotStorage.ts index 879dcb2..51ebaaa 100644 --- a/src/in-memory/InMemorySnapshotStorage.ts +++ b/src/in-memory/InMemorySnapshotStorage.ts @@ -1,14 +1,14 @@ import { - DispatchPipelineBatch, - IAggregateSnapshotStorage, - IContainer, - Identifier, - IDispatchPipelineProcessor, - IEvent, - ILogger, + type DispatchPipelineBatch, + type IAggregateSnapshotStorage, + type IContainer, + type Identifier, + type IDispatchPipelineProcessor, + type IEvent, + type ILogger, isSnapshotEvent -} from '../interfaces'; -import * as Event from '../Event'; +} from '../interfaces/index.ts'; +import * as Event from '../Event.ts'; /** * In-memory storage for aggregate snapshots. diff --git a/src/in-memory/InMemoryView.ts b/src/in-memory/InMemoryView.ts index 6e2f429..b76e49f 100644 --- a/src/in-memory/InMemoryView.ts +++ b/src/in-memory/InMemoryView.ts @@ -1,6 +1,6 @@ -import { InMemoryLock } from './InMemoryLock'; -import { IViewLocker, Identifier, IObjectStorage } from '../interfaces'; -import { nextCycle } from './utils'; +import { InMemoryLock } from './InMemoryLock.ts'; +import type { IViewLocker, Identifier, IObjectStorage } from '../interfaces/index.ts'; +import { nextCycle } from './utils/index.ts'; /** * Update given value with an update Cb and return updated value. diff --git a/src/in-memory/index.ts b/src/in-memory/index.ts index 3ef457a..74b00c7 100644 --- a/src/in-memory/index.ts +++ b/src/in-memory/index.ts @@ -1,5 +1,5 @@ -export * from './InMemoryEventStorage'; -export * from './InMemoryLock'; -export * from './InMemoryMessageBus'; -export * from './InMemorySnapshotStorage'; -export * from './InMemoryView'; +export * from './InMemoryEventStorage.ts'; +export * from './InMemoryLock.ts'; +export * from './InMemoryMessageBus.ts'; +export * from './InMemorySnapshotStorage.ts'; +export * from './InMemoryView.ts'; diff --git a/src/in-memory/utils/index.ts b/src/in-memory/utils/index.ts index d504dca..408a24b 100644 --- a/src/in-memory/utils/index.ts +++ b/src/in-memory/utils/index.ts @@ -1 +1 @@ -export * from './nextCycle'; +export * from './nextCycle.ts'; diff --git a/src/in-memory/utils/nextCycle.ts b/src/in-memory/utils/nextCycle.ts index 69c01a4..346ac96 100644 --- a/src/in-memory/utils/nextCycle.ts +++ b/src/in-memory/utils/nextCycle.ts @@ -1,4 +1,4 @@ /** * @returns Promise that resolves on next event loop cycle */ -export const nextCycle = (): Promise => new Promise(rs => setImmediate(rs)); +export const nextCycle = (): Promise => new Promise(rs => setTimeout(rs, 0)); diff --git a/src/index.ts b/src/index.ts index 27d5d0b..a802aff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,21 +1,21 @@ -export { CqrsContainerBuilder as ContainerBuilder } from './CqrsContainerBuilder'; +export { CqrsContainerBuilder as ContainerBuilder } from './CqrsContainerBuilder.ts'; -export * from './CommandBus'; -export * from './EventStore'; +export * from './CommandBus.ts'; +export * from './EventStore.ts'; -export * from './AbstractAggregate'; -export * from './AggregateCommandHandler'; -export * from './AbstractSaga'; -export * from './SagaEventHandler'; -export * from './AbstractProjection'; -export * from './EventDispatcher'; +export * from './AbstractAggregate.ts'; +export * from './AggregateCommandHandler.ts'; +export * from './AbstractSaga.ts'; +export * from './SagaEventHandler.ts'; +export * from './AbstractProjection.ts'; +export * from './EventDispatcher.ts'; -export * from './in-memory'; +export * from './in-memory/index.ts'; -export * as Event from './Event'; +export * as Event from './Event.ts'; export { getMessageHandlerNames, subscribe -} from './utils'; +} from './utils/index.ts'; -export * from './interfaces'; +export * from './interfaces/index.ts'; diff --git a/src/interfaces/IAggregate.ts b/src/interfaces/IAggregate.ts index 5316773..528ee9c 100644 --- a/src/interfaces/IAggregate.ts +++ b/src/interfaces/IAggregate.ts @@ -1,7 +1,7 @@ -import { ICommand } from './ICommand'; -import { Identifier } from './Identifier'; -import { IEvent } from './IEvent'; -import { IEventSet } from './IEventSet'; +import type { ICommand } from './ICommand.ts'; +import type { Identifier } from './Identifier.ts'; +import type { IEvent } from './IEvent.ts'; +import type { IEventSet } from './IEventSet.ts'; /** * Core interface representing an Aggregate in a CQRS architecture. diff --git a/src/interfaces/IAggregateSnapshotStorage.ts b/src/interfaces/IAggregateSnapshotStorage.ts index 1fb937a..9dae771 100644 --- a/src/interfaces/IAggregateSnapshotStorage.ts +++ b/src/interfaces/IAggregateSnapshotStorage.ts @@ -1,5 +1,5 @@ -import { Identifier } from './Identifier'; -import { IEvent } from './IEvent'; +import type { Identifier } from './Identifier.ts'; +import type { IEvent } from './IEvent.ts'; export interface IAggregateSnapshotStorage { getAggregateSnapshot(aggregateId: Identifier): diff --git a/src/interfaces/ICommand.ts b/src/interfaces/ICommand.ts index 94efa95..ca36031 100644 --- a/src/interfaces/ICommand.ts +++ b/src/interfaces/ICommand.ts @@ -1,3 +1,3 @@ -import { IMessage } from './IMessage'; +import type { IMessage } from './IMessage.ts'; export type ICommand = IMessage; diff --git a/src/interfaces/ICommandBus.ts b/src/interfaces/ICommandBus.ts index 53c4a7d..2a5e6a6 100644 --- a/src/interfaces/ICommandBus.ts +++ b/src/interfaces/ICommandBus.ts @@ -1,7 +1,7 @@ -import { ICommand } from './ICommand'; -import { IEventSet } from './IEventSet'; -import { IObservable } from './IObservable'; -import { IObserver } from './IObserver'; +import type { ICommand } from './ICommand.ts'; +import type { IEventSet } from './IEventSet.ts'; +import type { IObservable } from './IObservable.ts'; +import type { IObserver } from './IObserver.ts'; export interface ICommandBus extends IObservable { send(commandType: string, aggregateId: string | undefined, options: { payload?: object, context?: object }): diff --git a/src/interfaces/IContainer.ts b/src/interfaces/IContainer.ts index 1d6bebb..f7ecfa7 100644 --- a/src/interfaces/IContainer.ts +++ b/src/interfaces/IContainer.ts @@ -1,14 +1,14 @@ import { Container } from 'di0'; -import { ICommandBus } from './ICommandBus'; -import { IEventDispatcher } from './IEventDispatcher'; -import { IEventStore } from './IEventStore'; -import { IEventBus } from './IEventBus'; -import { IDispatchPipelineProcessor } from './IDispatchPipelineProcessor'; -import { IEventStorageReader } from './IEventStorageReader'; -import { IAggregateSnapshotStorage } from './IAggregateSnapshotStorage'; -import { IIdentifierProvider } from './IIdentifierProvider'; -import { IExtendableLogger, ILogger } from './ILogger'; -import { IEventStorageWriter } from './IEventStorageWriter'; +import type { ICommandBus } from './ICommandBus.ts'; +import type { IEventDispatcher } from './IEventDispatcher.ts'; +import type { IEventStore } from './IEventStore.ts'; +import type { IEventBus } from './IEventBus.ts'; +import type { IDispatchPipelineProcessor } from './IDispatchPipelineProcessor.ts'; +import type { IEventStorageReader } from './IEventStorageReader.ts'; +import type { IAggregateSnapshotStorage } from './IAggregateSnapshotStorage.ts'; +import type { IIdentifierProvider } from './IIdentifierProvider.ts'; +import type { IExtendableLogger, ILogger } from './ILogger.ts'; +import type { IEventStorageWriter } from './IEventStorageWriter.ts'; export interface IContainer extends Container { eventBus: IEventBus; diff --git a/src/interfaces/IDispatchPipelineProcessor.ts b/src/interfaces/IDispatchPipelineProcessor.ts index 958412f..924313c 100644 --- a/src/interfaces/IDispatchPipelineProcessor.ts +++ b/src/interfaces/IDispatchPipelineProcessor.ts @@ -1,5 +1,5 @@ -import { IEvent } from './IEvent'; -import { isObject } from './isObject'; +import type { IEvent } from './IEvent.ts'; +import { isObject } from './isObject.ts'; /** * Represents a wrapper for an event that can optionally contain additional metadata. diff --git a/src/interfaces/IEvent.ts b/src/interfaces/IEvent.ts index 0b007c9..eabc728 100644 --- a/src/interfaces/IEvent.ts +++ b/src/interfaces/IEvent.ts @@ -1,5 +1,5 @@ -import { IMessage } from './IMessage'; -import { isObject } from './isObject'; +import type { IMessage } from './IMessage.ts'; +import { isObject } from './isObject.ts'; export type IEvent = IMessage & { diff --git a/src/interfaces/IEventBus.ts b/src/interfaces/IEventBus.ts index 69406fb..10bd236 100644 --- a/src/interfaces/IEventBus.ts +++ b/src/interfaces/IEventBus.ts @@ -1,5 +1,5 @@ -import type { IEvent } from './IEvent'; -import { type IObservable, isIObservable } from './IObservable'; +import type { IEvent } from './IEvent.ts'; +import { type IObservable, isIObservable } from './IObservable.ts'; export interface IEventBus extends IObservable { publish(event: IEvent, meta?: Record): Promise; diff --git a/src/interfaces/IEventDispatcher.ts b/src/interfaces/IEventDispatcher.ts index 60a1ce8..a8c3d1d 100644 --- a/src/interfaces/IEventDispatcher.ts +++ b/src/interfaces/IEventDispatcher.ts @@ -1,5 +1,5 @@ -import { IEventSet } from './IEventSet'; -import { IEventBus } from './IEventBus'; +import type { IEventSet } from './IEventSet.ts'; +import type { IEventBus } from './IEventBus.ts'; export interface IEventDispatcher { readonly eventBus: IEventBus; diff --git a/src/interfaces/IEventLocker.ts b/src/interfaces/IEventLocker.ts index c2d0541..0731d7a 100644 --- a/src/interfaces/IEventLocker.ts +++ b/src/interfaces/IEventLocker.ts @@ -1,5 +1,5 @@ -import { IEvent } from './IEvent'; -import { isObject } from './isObject'; +import type { IEvent } from './IEvent.ts'; +import { isObject } from './isObject.ts'; /** * Interface for tracking event processing state to prevent concurrent processing diff --git a/src/interfaces/IEventReceptor.ts b/src/interfaces/IEventReceptor.ts index 722cbde..af34913 100644 --- a/src/interfaces/IEventReceptor.ts +++ b/src/interfaces/IEventReceptor.ts @@ -1,5 +1,5 @@ -import { IEventStore } from './IEventStore'; -import { IObserver } from './IObserver'; +import type { IEventStore } from './IEventStore.ts'; +import type { IObserver } from './IObserver.ts'; export interface IEventReceptor extends IObserver { subscribe(eventStore: IEventStore): void; diff --git a/src/interfaces/IEventSet.ts b/src/interfaces/IEventSet.ts index c06ac83..3d95808 100644 --- a/src/interfaces/IEventSet.ts +++ b/src/interfaces/IEventSet.ts @@ -1,4 +1,4 @@ -import { IEvent, isEvent } from './IEvent'; +import { type IEvent, isEvent } from './IEvent.ts'; export type IEventSet = ReadonlyArray>; diff --git a/src/interfaces/IEventStorageReader.ts b/src/interfaces/IEventStorageReader.ts index ba124b3..9329ae7 100644 --- a/src/interfaces/IEventStorageReader.ts +++ b/src/interfaces/IEventStorageReader.ts @@ -1,7 +1,7 @@ -import { Identifier } from './Identifier'; -import { IEvent } from './IEvent'; -import { IEventStream } from './IEventStream'; -import { isObject } from './isObject'; +import type { Identifier } from './Identifier.ts'; +import type { IEvent } from './IEvent.ts'; +import type { IEventStream } from './IEventStream.ts'; +import { isObject } from './isObject.ts'; export type EventQueryAfter = { diff --git a/src/interfaces/IEventStorageWriter.ts b/src/interfaces/IEventStorageWriter.ts index 03521bc..f5330b5 100644 --- a/src/interfaces/IEventStorageWriter.ts +++ b/src/interfaces/IEventStorageWriter.ts @@ -1,4 +1,4 @@ -import { IEventSet } from './IEventSet'; +import type { IEventSet } from './IEventSet.ts'; export interface IEventStorageWriter { diff --git a/src/interfaces/IEventStore.ts b/src/interfaces/IEventStore.ts index fae2816..07a7b2a 100644 --- a/src/interfaces/IEventStore.ts +++ b/src/interfaces/IEventStore.ts @@ -1,9 +1,9 @@ -import type { IEventDispatcher } from './IEventDispatcher'; -import type { IEvent } from './IEvent'; -import type { IEventStorageReader } from './IEventStorageReader'; -import type { IIdentifierProvider } from './IIdentifierProvider'; -import type { IMessageHandler, IObservable } from './IObservable'; -import type { IObservableQueueProvider } from './IObservableQueueProvider'; +import type { IEventDispatcher } from './IEventDispatcher.ts'; +import type { IEvent } from './IEvent.ts'; +import type { IEventStorageReader } from './IEventStorageReader.ts'; +import type { IIdentifierProvider } from './IIdentifierProvider.ts'; +import type { IMessageHandler, IObservable } from './IObservable.ts'; +import type { IObservableQueueProvider } from './IObservableQueueProvider.ts'; export interface IEventStore extends IObservable, IObservableQueueProvider, IEventDispatcher, IEventStorageReader, IIdentifierProvider { diff --git a/src/interfaces/IEventStream.ts b/src/interfaces/IEventStream.ts index 1f11e35..0739242 100644 --- a/src/interfaces/IEventStream.ts +++ b/src/interfaces/IEventStream.ts @@ -1,3 +1,3 @@ -import { IEvent } from './IEvent'; +import type { IEvent } from './IEvent.ts'; export type IEventStream = AsyncIterableIterator>; diff --git a/src/interfaces/IIdentifierProvider.ts b/src/interfaces/IIdentifierProvider.ts index 2c73090..b168580 100644 --- a/src/interfaces/IIdentifierProvider.ts +++ b/src/interfaces/IIdentifierProvider.ts @@ -1,5 +1,5 @@ -import { Identifier } from './Identifier'; -import { isObject } from './isObject'; +import type { Identifier } from './Identifier.ts'; +import { isObject } from './isObject.ts'; export interface IIdentifierProvider { diff --git a/src/interfaces/IMessage.ts b/src/interfaces/IMessage.ts index e5fda28..0fbb4c3 100644 --- a/src/interfaces/IMessage.ts +++ b/src/interfaces/IMessage.ts @@ -1,5 +1,5 @@ -import { Identifier } from './Identifier'; -import { isObject } from './isObject'; +import type { Identifier } from './Identifier.ts'; +import { isObject } from './isObject.ts'; export interface IMessage { diff --git a/src/interfaces/IMessageBus.ts b/src/interfaces/IMessageBus.ts index 44a7ea2..a42e343 100644 --- a/src/interfaces/IMessageBus.ts +++ b/src/interfaces/IMessageBus.ts @@ -1,6 +1,6 @@ -import type { ICommand } from './ICommand'; -import type { IEvent } from './IEvent'; -import type { IObservable } from './IObservable'; +import type { ICommand } from './ICommand.ts'; +import type { IEvent } from './IEvent.ts'; +import type { IObservable } from './IObservable.ts'; export interface IMessageBus extends IObservable { send(command: ICommand): Promise; diff --git a/src/interfaces/IObjectStorage.ts b/src/interfaces/IObjectStorage.ts index e4b651a..3b28bca 100644 --- a/src/interfaces/IObjectStorage.ts +++ b/src/interfaces/IObjectStorage.ts @@ -1,4 +1,4 @@ -import { Identifier } from './Identifier'; +import type { Identifier } from './Identifier.ts'; export interface IObjectStorage { get(id: Identifier): Promise | TRecord | undefined; diff --git a/src/interfaces/IObservable.ts b/src/interfaces/IObservable.ts index f7bdab9..4c62d00 100644 --- a/src/interfaces/IObservable.ts +++ b/src/interfaces/IObservable.ts @@ -1,5 +1,5 @@ -import { IMessage } from './IMessage'; -import { isObject } from './isObject'; +import type { IMessage } from './IMessage.ts'; +import { isObject } from './isObject.ts'; export interface IMessageHandler { (message: IMessage, meta?: Record): any | Promise diff --git a/src/interfaces/IObservableQueueProvider.ts b/src/interfaces/IObservableQueueProvider.ts index 2b32573..437d301 100644 --- a/src/interfaces/IObservableQueueProvider.ts +++ b/src/interfaces/IObservableQueueProvider.ts @@ -1,5 +1,5 @@ -import type { IObservable } from './IObservable'; -import { isObject } from './isObject'; +import type { IObservable } from './IObservable.ts'; +import { isObject } from './isObject.ts'; export interface IObservableQueueProvider { diff --git a/src/interfaces/IObserver.ts b/src/interfaces/IObserver.ts index d822cea..f94bc5e 100644 --- a/src/interfaces/IObserver.ts +++ b/src/interfaces/IObserver.ts @@ -1,4 +1,4 @@ -import { IObservable } from './IObservable'; +import type { IObservable } from './IObservable.ts'; export interface IObserver { subscribe(observable: IObservable): void; diff --git a/src/interfaces/IProjection.ts b/src/interfaces/IProjection.ts index a5d17bb..b6a749d 100644 --- a/src/interfaces/IProjection.ts +++ b/src/interfaces/IProjection.ts @@ -1,7 +1,7 @@ -import type { IObserver } from './IObserver'; -import type { IObservable } from './IObservable'; -import type { IEventStorageReader } from './IEventStorageReader'; -import type { IEvent } from './IEvent'; +import type { IObserver } from './IObserver.ts'; +import type { IObservable } from './IObservable.ts'; +import type { IEventStorageReader } from './IEventStorageReader.ts'; +import type { IEvent } from './IEvent.ts'; export interface IProjection extends IObserver { readonly view: TView; diff --git a/src/interfaces/ISaga.ts b/src/interfaces/ISaga.ts index f4920ba..104f7b3 100644 --- a/src/interfaces/ISaga.ts +++ b/src/interfaces/ISaga.ts @@ -1,7 +1,7 @@ -import { ICommand } from './ICommand'; -import { Identifier } from './Identifier'; -import { IEvent } from './IEvent'; -import { IEventSet } from './IEventSet'; +import type { ICommand } from './ICommand.ts'; +import type { Identifier } from './Identifier.ts'; +import type { IEvent } from './IEvent.ts'; +import type { IEventSet } from './IEventSet.ts'; export interface ISaga { diff --git a/src/interfaces/ISnapshotEvent.ts b/src/interfaces/ISnapshotEvent.ts index 81b61e6..8ca2afe 100644 --- a/src/interfaces/ISnapshotEvent.ts +++ b/src/interfaces/ISnapshotEvent.ts @@ -1,4 +1,4 @@ -import { IEvent, isEvent } from './IEvent'; +import { type IEvent, isEvent } from './IEvent.ts'; export const SNAPSHOT_EVENT_TYPE: 'snapshot' = 'snapshot'; diff --git a/src/interfaces/IViewLocker.ts b/src/interfaces/IViewLocker.ts index 1dd517c..90b3e1b 100644 --- a/src/interfaces/IViewLocker.ts +++ b/src/interfaces/IViewLocker.ts @@ -1,4 +1,4 @@ -import { isObject } from './isObject'; +import { isObject } from './isObject.ts'; /** * Interface for managing view restoration state to prevent early access to an inconsistent view diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 424070c..05b5e7a 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -1,29 +1,29 @@ -export * from './IAggregate'; -export * from './IAggregateSnapshotStorage'; -export * from './ICommand'; -export * from './ICommandBus'; -export * from './IContainer'; -export * from './Identifier'; -export * from './IDispatchPipelineProcessor'; -export * from './IEvent'; -export * from './IEventBus'; -export * from './IEventDispatcher'; -export * from './IEventLocker'; -export * from './IEventReceptor'; -export * from './IEventSet'; -export * from './IEventStorageReader'; -export * from './IEventStorageWriter'; -export * from './IEventStore'; -export * from './IEventStream'; -export * from './IIdentifierProvider'; -export * from './ILogger'; -export * from './IMessage'; -export * from './IMessageBus'; -export * from './IObjectStorage'; -export * from './IObservable'; -export * from './IObservableQueueProvider'; -export * from './IObserver'; -export * from './IProjection'; -export * from './ISaga'; -export * from './ISnapshotEvent'; -export * from './IViewLocker'; +export * from './IAggregate.ts'; +export * from './IAggregateSnapshotStorage.ts'; +export * from './ICommand.ts'; +export * from './ICommandBus.ts'; +export * from './IContainer.ts'; +export * from './Identifier.ts'; +export * from './IDispatchPipelineProcessor.ts'; +export * from './IEvent.ts'; +export * from './IEventBus.ts'; +export * from './IEventDispatcher.ts'; +export * from './IEventLocker.ts'; +export * from './IEventReceptor.ts'; +export * from './IEventSet.ts'; +export * from './IEventStorageReader.ts'; +export * from './IEventStorageWriter.ts'; +export * from './IEventStore.ts'; +export * from './IEventStream.ts'; +export * from './IIdentifierProvider.ts'; +export * from './ILogger.ts'; +export * from './IMessage.ts'; +export * from './IMessageBus.ts'; +export * from './IObjectStorage.ts'; +export * from './IObservable.ts'; +export * from './IObservableQueueProvider.ts'; +export * from './IObserver.ts'; +export * from './IProjection.ts'; +export * from './ISaga.ts'; +export * from './ISnapshotEvent.ts'; +export * from './IViewLocker.ts'; diff --git a/src/rabbitmq/IContainer.ts b/src/rabbitmq/IContainer.ts index ceac5c4..936850d 100644 --- a/src/rabbitmq/IContainer.ts +++ b/src/rabbitmq/IContainer.ts @@ -1,4 +1,4 @@ -import { RabbitMqGateway } from './RabbitMqGateway'; +import { RabbitMqGateway } from './RabbitMqGateway.ts'; declare module '../interfaces/IContainer' { interface IContainer { diff --git a/src/rabbitmq/RabbitMqEventBus.ts b/src/rabbitmq/RabbitMqEventBus.ts index 290febb..7a40ce1 100644 --- a/src/rabbitmq/RabbitMqEventBus.ts +++ b/src/rabbitmq/RabbitMqEventBus.ts @@ -1,5 +1,5 @@ -import type { IEvent, IEventBus, IMessageHandler, IObservable, IObservableQueueProvider } from '../interfaces'; -import { RabbitMqGateway } from './RabbitMqGateway'; +import type { IEvent, IEventBus, IMessageHandler, IObservable, IObservableQueueProvider } from '../interfaces/index.ts'; +import { RabbitMqGateway } from './RabbitMqGateway.ts'; /** * RabbitMQ-backed `IEventBus` with named queues support diff --git a/src/rabbitmq/RabbitMqGateway.ts b/src/rabbitmq/RabbitMqGateway.ts index eb3dea5..cbaa6b1 100644 --- a/src/rabbitmq/RabbitMqGateway.ts +++ b/src/rabbitmq/RabbitMqGateway.ts @@ -1,8 +1,8 @@ import type { Channel, ChannelModel, ConfirmChannel, ConsumeMessage } from 'amqplib'; -import { type IContainer, type ILogger, type IMessage, isMessage } from '../interfaces'; -import * as Event from '../Event'; -import { extractErrorDetails, Lock } from '../utils'; -import { registerExitCleanup } from './utils'; +import { type IContainer, type ILogger, type IMessage, isMessage } from '../interfaces/index.ts'; +import * as Event from '../Event.ts'; +import { extractErrorDetails, Lock } from '../utils/index.ts'; +import { registerExitCleanup } from './utils/index.ts'; import { EventEmitter } from 'events'; /** Generate a short pseudo-unique identifier using a truncated timestamp and random component */ diff --git a/src/rabbitmq/index.ts b/src/rabbitmq/index.ts index 79404df..20d12c6 100644 --- a/src/rabbitmq/index.ts +++ b/src/rabbitmq/index.ts @@ -1,2 +1,2 @@ -export * from './RabbitMqEventBus'; -export * from './RabbitMqGateway'; +export * from './RabbitMqEventBus.ts'; +export * from './RabbitMqGateway.ts'; diff --git a/src/rabbitmq/utils/index.ts b/src/rabbitmq/utils/index.ts index 807ea15..61dbe19 100644 --- a/src/rabbitmq/utils/index.ts +++ b/src/rabbitmq/utils/index.ts @@ -1 +1 @@ -export * from './registerExitCleanup'; +export * from './registerExitCleanup.ts'; diff --git a/src/sqlite/AbstractSqliteAccessor.ts b/src/sqlite/AbstractSqliteAccessor.ts index 9a474cc..8bb0b1f 100644 --- a/src/sqlite/AbstractSqliteAccessor.ts +++ b/src/sqlite/AbstractSqliteAccessor.ts @@ -1,5 +1,5 @@ -import type { IContainer } from '../interfaces'; -import { Lock } from '../utils'; +import type { IContainer } from '../interfaces/index.ts'; +import { Lock } from '../utils/index.ts'; import type { Database } from 'better-sqlite3'; /** diff --git a/src/sqlite/AbstractSqliteObjectProjection.ts b/src/sqlite/AbstractSqliteObjectProjection.ts index acc3c2b..12ef42a 100644 --- a/src/sqlite/AbstractSqliteObjectProjection.ts +++ b/src/sqlite/AbstractSqliteObjectProjection.ts @@ -1,6 +1,6 @@ -import { AbstractProjection } from '../AbstractProjection'; -import { IContainer } from '../interfaces'; -import { SqliteObjectView } from './SqliteObjectView'; +import { AbstractProjection } from '../AbstractProjection.ts'; +import { IContainer } from '../interfaces/index.ts'; +import { SqliteObjectView } from './SqliteObjectView.ts'; export abstract class AbstractSqliteObjectProjection extends AbstractProjection> { diff --git a/src/sqlite/AbstractSqliteView.ts b/src/sqlite/AbstractSqliteView.ts index 55927ba..350abe3 100644 --- a/src/sqlite/AbstractSqliteView.ts +++ b/src/sqlite/AbstractSqliteView.ts @@ -1,7 +1,7 @@ -import { IContainer, IEvent, IEventLocker, ILogger, IViewLocker } from '../interfaces'; -import { SqliteViewLocker, SqliteViewLockerParams } from './SqliteViewLocker'; -import { SqliteEventLocker, SqliteEventLockerParams } from './SqliteEventLocker'; -import { AbstractSqliteAccessor } from './AbstractSqliteAccessor'; +import { IContainer, IEvent, IEventLocker, ILogger, IViewLocker } from '../interfaces/index.ts'; +import { SqliteViewLocker, SqliteViewLockerParams } from './SqliteViewLocker.ts'; +import { SqliteEventLocker, SqliteEventLockerParams } from './SqliteEventLocker.ts'; +import { AbstractSqliteAccessor } from './AbstractSqliteAccessor.ts'; /** * Base class for SQLite-backed projection views with restore locking and last-processed-event tracking diff --git a/src/sqlite/SqliteEventLocker.ts b/src/sqlite/SqliteEventLocker.ts index a202060..8df600e 100644 --- a/src/sqlite/SqliteEventLocker.ts +++ b/src/sqlite/SqliteEventLocker.ts @@ -1,10 +1,10 @@ import type { Database, Statement } from 'better-sqlite3'; -import type { IContainer, IEvent, IEventLocker } from '../interfaces'; -import { getEventId } from './utils'; -import { viewLockTableInit, eventLockTableInit } from './queries'; -import type { SqliteViewLockerParams } from './SqliteViewLocker'; -import type { SqliteProjectionDataParams } from './SqliteProjectionDataParams'; -import { AbstractSqliteAccessor } from './AbstractSqliteAccessor'; +import type { IContainer, IEvent, IEventLocker } from '../interfaces/index.ts'; +import { getEventId } from './utils/index.ts'; +import { viewLockTableInit, eventLockTableInit } from './queries/index.ts'; +import type { SqliteViewLockerParams } from './SqliteViewLocker.ts'; +import type { SqliteProjectionDataParams } from './SqliteProjectionDataParams.ts'; +import { AbstractSqliteAccessor } from './AbstractSqliteAccessor.ts'; export type SqliteEventLockerParams = SqliteProjectionDataParams diff --git a/src/sqlite/SqliteObjectStorage.ts b/src/sqlite/SqliteObjectStorage.ts index 9ab3149..262aa97 100644 --- a/src/sqlite/SqliteObjectStorage.ts +++ b/src/sqlite/SqliteObjectStorage.ts @@ -1,7 +1,7 @@ import type { Statement, Database } from 'better-sqlite3'; -import { guid } from './utils'; -import type { IContainer, IObjectStorage } from '../interfaces'; -import { AbstractSqliteAccessor } from './AbstractSqliteAccessor'; +import { guid } from './utils/index.ts'; +import type { IContainer, IObjectStorage } from '../interfaces/index.ts'; +import { AbstractSqliteAccessor } from './AbstractSqliteAccessor.ts'; export class SqliteObjectStorage extends AbstractSqliteAccessor implements IObjectStorage { diff --git a/src/sqlite/SqliteObjectView.ts b/src/sqlite/SqliteObjectView.ts index a110701..47f0c93 100644 --- a/src/sqlite/SqliteObjectView.ts +++ b/src/sqlite/SqliteObjectView.ts @@ -1,6 +1,6 @@ -import { AbstractSqliteView } from './AbstractSqliteView'; -import type { IObjectStorage, IEventLocker } from '../interfaces'; -import { SqliteObjectStorage } from './SqliteObjectStorage'; +import { AbstractSqliteView } from './AbstractSqliteView.ts'; +import type { IObjectStorage, IEventLocker } from '../interfaces/index.ts'; +import { SqliteObjectStorage } from './SqliteObjectStorage.ts'; import type { Database } from 'better-sqlite3'; /** diff --git a/src/sqlite/SqliteViewLocker.ts b/src/sqlite/SqliteViewLocker.ts index 43fd5f1..ad3dee7 100644 --- a/src/sqlite/SqliteViewLocker.ts +++ b/src/sqlite/SqliteViewLocker.ts @@ -1,10 +1,10 @@ import type { Database, Statement } from 'better-sqlite3'; -import type { IContainer, ILogger, IViewLocker } from '../interfaces'; -import { Deferred } from '../utils'; +import type { IContainer, ILogger, IViewLocker } from '../interfaces/index.ts'; +import { Deferred } from '../utils/index.ts'; import { promisify } from 'util'; -import { viewLockTableInit } from './queries'; -import type { SqliteProjectionDataParams } from './SqliteProjectionDataParams'; -import { AbstractSqliteAccessor } from './AbstractSqliteAccessor'; +import { viewLockTableInit } from './queries/index.ts'; +import type { SqliteProjectionDataParams } from './SqliteProjectionDataParams.ts'; +import { AbstractSqliteAccessor } from './AbstractSqliteAccessor.ts'; const delay = promisify(setTimeout); export type SqliteViewLockerParams = SqliteProjectionDataParams & { diff --git a/src/sqlite/index.ts b/src/sqlite/index.ts index 068463a..d90c4c8 100644 --- a/src/sqlite/index.ts +++ b/src/sqlite/index.ts @@ -1,8 +1,8 @@ -export * from './AbstractSqliteAccessor'; -export * from './AbstractSqliteObjectProjection'; -export * from './AbstractSqliteView'; -export * from './SqliteEventLocker'; -export * from './SqliteObjectStorage'; -export * from './SqliteObjectView'; -export * from './SqliteViewLocker'; -export * from './utils'; +export * from './AbstractSqliteAccessor.ts'; +export * from './AbstractSqliteObjectProjection.ts'; +export * from './AbstractSqliteView.ts'; +export * from './SqliteEventLocker.ts'; +export * from './SqliteObjectStorage.ts'; +export * from './SqliteObjectView.ts'; +export * from './SqliteViewLocker.ts'; +export * from './utils/index.ts'; diff --git a/src/sqlite/queries/index.ts b/src/sqlite/queries/index.ts index 7edbb02..93f0de6 100644 --- a/src/sqlite/queries/index.ts +++ b/src/sqlite/queries/index.ts @@ -1,2 +1,2 @@ -export * from './eventLockTableInit'; -export * from './viewLockTableInit'; +export * from './eventLockTableInit.ts'; +export * from './viewLockTableInit.ts'; diff --git a/src/sqlite/utils/getEventId.ts b/src/sqlite/utils/getEventId.ts index 2a99f75..2860279 100644 --- a/src/sqlite/utils/getEventId.ts +++ b/src/sqlite/utils/getEventId.ts @@ -1,6 +1,6 @@ -import { IEvent } from '../../interfaces'; -import { guid } from './guid'; -import md5 = require('md5'); +import { IEvent } from '../../interfaces/index.ts'; +import { guid } from './guid.ts'; +import md5 from 'md5'; /** * Get assigned or generate new event ID from event content diff --git a/src/sqlite/utils/index.ts b/src/sqlite/utils/index.ts index f27b49b..989235a 100644 --- a/src/sqlite/utils/index.ts +++ b/src/sqlite/utils/index.ts @@ -1,2 +1,2 @@ -export * from './guid'; -export * from './getEventId'; +export * from './guid.ts'; +export * from './getEventId.ts'; diff --git a/src/utils/Lock.ts b/src/utils/Lock.ts index 2db3489..5fdf105 100644 --- a/src/utils/Lock.ts +++ b/src/utils/Lock.ts @@ -1,10 +1,14 @@ -import { Deferred } from './Deferred'; +import { Deferred } from './Deferred.ts'; export class LockLease { - constructor( - readonly lock: Lock, - readonly name?: string - ) { } + + readonly lock: Lock; + readonly name?: string; + + constructor(lock: Lock, name?: string) { + this.lock = lock; + this.name = name; + } release() { this.lock.release(this.name); diff --git a/src/utils/getHandler.ts b/src/utils/getHandler.ts index f2de2be..c46b7f0 100644 --- a/src/utils/getHandler.ts +++ b/src/utils/getHandler.ts @@ -1,4 +1,4 @@ -import { IMessageHandler } from '../interfaces'; +import type { IMessageHandler } from '../interfaces/index.ts'; /** * Gets a handler for a specific message type, prefers a public (w\o _ prefix) method, if available diff --git a/src/utils/index.ts b/src/utils/index.ts index 8e8a8da..0ea5231 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,13 +1,13 @@ -export * from './Deferred'; -export * from './getClassName'; -export * from './getHandler'; -export * from './getMessageHandlerNames'; -export * from './isClass'; -export * from './iteratorToArray'; -export * from './Lock'; -export * from './MapAssertable'; -export * from './notEmpty'; -export * from './setupOneTimeEmitterSubscription'; -export * from './subscribe'; -export * from './validateHandlers'; -export * from './extractErrorDetails'; +export * from './Deferred.ts'; +export * from './getClassName.ts'; +export * from './getHandler.ts'; +export * from './getMessageHandlerNames.ts'; +export * from './isClass.ts'; +export * from './iteratorToArray.ts'; +export * from './Lock.ts'; +export * from './MapAssertable.ts'; +export * from './notEmpty.ts'; +export * from './setupOneTimeEmitterSubscription.ts'; +export * from './subscribe.ts'; +export * from './validateHandlers.ts'; +export * from './extractErrorDetails.ts'; diff --git a/src/utils/setupOneTimeEmitterSubscription.ts b/src/utils/setupOneTimeEmitterSubscription.ts index 554d8bf..e39566e 100644 --- a/src/utils/setupOneTimeEmitterSubscription.ts +++ b/src/utils/setupOneTimeEmitterSubscription.ts @@ -1,4 +1,4 @@ -import { IEvent, ILogger, IObservable } from '../interfaces'; +import type { IEvent, ILogger, IObservable } from '../interfaces/index.ts'; /** * Create one-time eventEmitter subscription for one or multiple events that match a filter diff --git a/src/utils/subscribe.ts b/src/utils/subscribe.ts index 9c21664..331b752 100644 --- a/src/utils/subscribe.ts +++ b/src/utils/subscribe.ts @@ -1,6 +1,6 @@ -import { type IMessageHandler, type IObservable, isIObservableQueueProvider } from '../interfaces'; -import { getHandler } from './getHandler'; -import { getMessageHandlerNames } from './getMessageHandlerNames'; +import { type IMessageHandler, type IObservable, isIObservableQueueProvider } from '../interfaces/index.ts'; +import { getHandler } from './getHandler.ts'; +import { getMessageHandlerNames } from './getMessageHandlerNames.ts'; const unique = (arr: T[]): T[] => [...new Set(arr)]; diff --git a/src/utils/validateHandlers.ts b/src/utils/validateHandlers.ts index 7061c34..96ec344 100644 --- a/src/utils/validateHandlers.ts +++ b/src/utils/validateHandlers.ts @@ -1,4 +1,4 @@ -import { getHandler } from './getHandler'; +import { getHandler } from './getHandler.ts'; /** * Ensure instance has handlers declared for all handled message types diff --git a/src/workers/AbstractWorkerProjection.ts b/src/workers/AbstractWorkerProjection.ts index c7f66af..ae39bd1 100644 --- a/src/workers/AbstractWorkerProjection.ts +++ b/src/workers/AbstractWorkerProjection.ts @@ -1,10 +1,10 @@ import { isMainThread, Worker, MessageChannel, parentPort, workerData } from 'node:worker_threads'; -import { AbstractProjection, type AbstractProjectionParams } from '../AbstractProjection'; -import type { IEvent } from '../interfaces'; +import { AbstractProjection, type AbstractProjectionParams } from '../AbstractProjection.ts'; +import type { IEvent } from '../interfaces/index.ts'; import * as Comlink from 'comlink'; -import { nodeEndpoint, createWorker } from './utils'; -import { extractErrorDetails } from '../utils'; -import { isWorkerData, type IWorkerData, type WorkerInitMessage } from './protocol'; +import { nodeEndpoint, createWorker } from './utils/index.ts'; +import { extractErrorDetails } from '../utils/index.ts'; +import { isWorkerData, type IWorkerData, type WorkerInitMessage } from './protocol.ts'; export type AbstractWorkerProjectionParams = AbstractProjectionParams & { diff --git a/src/workers/index.ts b/src/workers/index.ts index f5e88b1..e646338 100644 --- a/src/workers/index.ts +++ b/src/workers/index.ts @@ -1 +1 @@ -export * from './AbstractWorkerProjection'; +export * from './AbstractWorkerProjection.ts'; diff --git a/src/workers/utils/createWorker.ts b/src/workers/utils/createWorker.ts index a31c8d8..7e90eda 100644 --- a/src/workers/utils/createWorker.ts +++ b/src/workers/utils/createWorker.ts @@ -1,6 +1,6 @@ import { Worker } from 'node:worker_threads'; import * as path from 'node:path'; -import { isWorkerInitMessage, type IWorkerData } from '../protocol'; +import { isWorkerInitMessage, type IWorkerData } from '../protocol.ts'; /** * Create a worker instance, await a handshake or a failure diff --git a/src/workers/utils/index.ts b/src/workers/utils/index.ts index d336324..f4cec7a 100644 --- a/src/workers/utils/index.ts +++ b/src/workers/utils/index.ts @@ -1,2 +1,2 @@ -export * from './createWorker'; -export * from './nodeEndpoint'; +export * from './createWorker.ts'; +export * from './nodeEndpoint.ts'; diff --git a/tests/integration/sqlite/SqliteView.test.ts b/tests/integration/sqlite/SqliteView.test.ts index eaf116c..841b709 100644 --- a/tests/integration/sqlite/SqliteView.test.ts +++ b/tests/integration/sqlite/SqliteView.test.ts @@ -1,7 +1,7 @@ import { existsSync, unlinkSync } from 'fs'; import { AbstractProjection, IEvent } from '../../../src'; import { SqliteObjectView } from '../../../src/sqlite'; -import * as createDb from 'better-sqlite3'; +import createDb from 'better-sqlite3'; type UserPayload = { name: string; diff --git a/tests/unit/EventStore.test.ts b/tests/unit/EventStore.test.ts index 59f65a0..2f60713 100644 --- a/tests/unit/EventStore.test.ts +++ b/tests/unit/EventStore.test.ts @@ -1,4 +1,4 @@ -import { EventDispatcher } from '../../dist/EventDispatcher'; +import { EventDispatcher } from '../../dist/cjs/EventDispatcher'; import { IEventDispatcher, InMemoryMessageBus } from '../../src'; import { EventStore } from '../../src/EventStore'; import { diff --git a/tests/unit/dispatch-pipeline.test.ts b/tests/unit/dispatch-pipeline.test.ts index 05dc35b..faa821e 100644 --- a/tests/unit/dispatch-pipeline.test.ts +++ b/tests/unit/dispatch-pipeline.test.ts @@ -1,4 +1,4 @@ -import { InMemorySnapshotStorage } from '../../dist/in-memory/InMemorySnapshotStorage'; +import { InMemorySnapshotStorage } from '../../dist/cjs/in-memory/InMemorySnapshotStorage'; import { ContainerBuilder, IContainer, diff --git a/tests/unit/sqlite/SqliteEventLocker.test.ts b/tests/unit/sqlite/SqliteEventLocker.test.ts index 243e773..7ee7f47 100644 --- a/tests/unit/sqlite/SqliteEventLocker.test.ts +++ b/tests/unit/sqlite/SqliteEventLocker.test.ts @@ -1,4 +1,4 @@ -import * as createDb from 'better-sqlite3'; +import createDb from 'better-sqlite3'; import { SqliteEventLocker } from '../../../src/sqlite/SqliteEventLocker'; import { IEvent } from '../../../src/interfaces'; import { guid } from '../../../src/sqlite'; diff --git a/tests/unit/sqlite/SqliteObjectStorage.test.ts b/tests/unit/sqlite/SqliteObjectStorage.test.ts index cd4bcff..2f6691b 100644 --- a/tests/unit/sqlite/SqliteObjectStorage.test.ts +++ b/tests/unit/sqlite/SqliteObjectStorage.test.ts @@ -1,4 +1,4 @@ -import * as createDb from 'better-sqlite3'; +import createDb from 'better-sqlite3'; import { guid, SqliteObjectStorage } from '../../../src/sqlite'; describe('SqliteObjectStorage', function () { diff --git a/tests/unit/sqlite/SqliteObjectView.test.ts b/tests/unit/sqlite/SqliteObjectView.test.ts index 3aa5de4..685b69f 100644 --- a/tests/unit/sqlite/SqliteObjectView.test.ts +++ b/tests/unit/sqlite/SqliteObjectView.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as createDb from 'better-sqlite3'; +import createDb from 'better-sqlite3'; import { SqliteObjectView } from '../../../src/sqlite'; import { promisify } from 'util'; const delay = promisify(setTimeout); diff --git a/tests/unit/sqlite/SqliteViewLocker.test.ts b/tests/unit/sqlite/SqliteViewLocker.test.ts index fd0f8c5..107c4bd 100644 --- a/tests/unit/sqlite/SqliteViewLocker.test.ts +++ b/tests/unit/sqlite/SqliteViewLocker.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as createDb from 'better-sqlite3'; +import createDb from 'better-sqlite3'; import { SqliteViewLocker } from '../../../src/sqlite'; describe('SqliteViewLocker', function () { diff --git a/tests/unit/workers/fixtures/ProjectionFixture.cjs b/tests/unit/workers/fixtures/ProjectionFixture.cjs index 28e8e48..2b690f4 100644 --- a/tests/unit/workers/fixtures/ProjectionFixture.cjs +++ b/tests/unit/workers/fixtures/ProjectionFixture.cjs @@ -1,6 +1,4 @@ -/** @type {typeof import('../../../../src/workers')} */ -// @ts-ignore -const workers = require('../../../../dist/workers'); +const workers = require('node-cqrs/workers'); const { AbstractWorkerProjection } = workers; diff --git a/tests/unit/workers/fixtures/ProjectionFixture.ts b/tests/unit/workers/fixtures/ProjectionFixture.ts deleted file mode 100644 index 1cebcfe..0000000 --- a/tests/unit/workers/fixtures/ProjectionFixture.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { AbstractWorkerProjection } from '../../../../src/workers'; - -class ViewFixture { - counter = 0; - - increment() { - this.counter += 1; - } - - getCounter() { - return this.counter; - } -} - -export class ProjectionFixture extends AbstractWorkerProjection { - - get view() { - return super.view; - } - - constructor({ workerModulePath = __filename } = {}) { - super({ - workerModulePath, - view: new ViewFixture() - }); - } - - async somethingHappened() { - this.view.increment(); - } - - async somethingBadHappened() { - throw new Error('boom'); - } -} - -ProjectionFixture.createInstanceIfWorkerThread(); diff --git a/tests/unit/workers/fixtures/jsconfig.json b/tests/unit/workers/fixtures/jsconfig.json new file mode 100644 index 0000000..6653e49 --- /dev/null +++ b/tests/unit/workers/fixtures/jsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "es2022", + "module": "commonjs", + "moduleResolution": "node", + "checkJs": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "lib": [ + "es2022", + "dom" + ], + "baseUrl": "..", + "paths": { + "node-cqrs": [ + "types/index.d.ts" + ], + "node-cqrs/*": [ + "types/*/index.d.ts" + ] + } + }, + "include": [ + "**/*" + ], + "exclude": [ + "../node_modules", + "../dist", + "**/bundle.js", + "browser-smoke-test/**" + ] +} diff --git a/tsconfig.browser.json b/tsconfig.browser.json new file mode 100644 index 0000000..b36159d --- /dev/null +++ b/tsconfig.browser.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "target": "ES2019", + "outDir": "./dist/browser/cjs", + "noEmit": false, + "declaration": false + } +} + diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..62ca15a --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "target": "ES2022", + "outDir": "./dist/cjs", + "noEmit": false, + "declaration": false + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..23392f1 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2022", + "target": "ES2022", + "declaration": true, + "declarationDir": "./types", + "declarationMap": false, + "outDir": "./dist/esm", + "noEmit": false, + "noEmitOnError": true + } +} diff --git a/tsconfig.json b/tsconfig.json index 2ac6347..b7330f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,28 +1,33 @@ { - "compileOnSave": true, - "compilerOptions": { - "module": "CommonJS", - "removeComments": false, - "sourceMap": true, - "alwaysStrict": false, - "outDir": "./dist", - "target": "ES2022", - "declaration": true, - "declarationDir": "./types", - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "strict": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "strictPropertyInitialization": true, - "isolatedModules": true - }, - "include": [ - "src/**/*" + "compilerOptions": { + "module": "CommonJS", + "target": "ES2022", + "lib": [ + "ES2022", + "WebWorker" ], - "exclude": [ - "node_modules", - "**/*.spec.ts" - ] -} \ No newline at end of file + "moduleResolution": "node", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "isolatedModules": true, + "removeComments": false, + "sourceMap": true, + "alwaysStrict": false, + "noEmit": true, + "allowImportingTsExtensions": true, + "rewriteRelativeImportExtensions": true + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "node_modules", + "**/*.spec.ts" + ] +} From f5a492e55f7e00863182b31b096e735704c0822e Mon Sep 17 00:00:00 2001 From: Stanislav Natalenko Date: Thu, 29 Jan 2026 22:06:03 +0000 Subject: [PATCH 2/2] Fix user-domain file extensions --- examples/user-domain/{UserAggregate.js => UserAggregate.cjs} | 0 .../user-domain/{UsersProjection.js => UsersProjection.cjs} | 0 examples/user-domain/{index.js => index.cjs} | 4 ++-- examples/user-domain/tests/{index.test.js => index.test.cjs} | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename examples/user-domain/{UserAggregate.js => UserAggregate.cjs} (100%) rename examples/user-domain/{UsersProjection.js => UsersProjection.cjs} (100%) rename examples/user-domain/{index.js => index.cjs} (94%) rename examples/user-domain/tests/{index.test.js => index.test.cjs} (99%) diff --git a/examples/user-domain/UserAggregate.js b/examples/user-domain/UserAggregate.cjs similarity index 100% rename from examples/user-domain/UserAggregate.js rename to examples/user-domain/UserAggregate.cjs diff --git a/examples/user-domain/UsersProjection.js b/examples/user-domain/UsersProjection.cjs similarity index 100% rename from examples/user-domain/UsersProjection.js rename to examples/user-domain/UsersProjection.cjs diff --git a/examples/user-domain/index.js b/examples/user-domain/index.cjs similarity index 94% rename from examples/user-domain/index.js rename to examples/user-domain/index.cjs index f0b02ea..2e9f4f4 100644 --- a/examples/user-domain/index.js +++ b/examples/user-domain/index.cjs @@ -10,8 +10,8 @@ const { EventDispatcher, InMemorySnapshotStorage } = require('node-cqrs'); -const UserAggregate = require('./UserAggregate'); -const UsersProjection = require('./UsersProjection'); +const UserAggregate = require('./UserAggregate.cjs'); +const UsersProjection = require('./UsersProjection.cjs'); /** * DI container factory diff --git a/examples/user-domain/tests/index.test.js b/examples/user-domain/tests/index.test.cjs similarity index 99% rename from examples/user-domain/tests/index.test.js rename to examples/user-domain/tests/index.test.cjs index a5367ac..482e6e7 100644 --- a/examples/user-domain/tests/index.test.js +++ b/examples/user-domain/tests/index.test.cjs @@ -1,7 +1,7 @@ 'use strict'; const { expect } = require('chai'); -const { createContainer, createBaseInstances } = require('../index.js'); +const { createContainer, createBaseInstances } = require('../index.cjs'); describe('user-domain example', () => {