@arts-n-crafts/ts 3.16.0 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,43 +8,36 @@
8
8
  "private": true,
9
9
  "main": "./dist/index.cjs",
10
10
  "module": "./dist/index.js",
11
+ "files": [
12
+ "dist"
13
+ ],
11
14
  "devDependencies": {
12
- "@antfu/eslint-config": "^4.19.0",
15
+ "@antfu/eslint-config": "^6.7.3",
13
16
  "@arethetypeswrong/cli": "^0.18.2",
14
- "@commitlint/cli": "^19.8.1",
15
- "@commitlint/config-conventional": "^19.8.1",
16
- "@eslint/js": "^9.33.0",
17
+ "@commitlint/cli": "^20.2.0",
18
+ "@commitlint/config-conventional": "^20.2.0",
19
+ "@eslint/js": "^9.39.2",
17
20
  "@release-it/bumper": "^7.0.5",
18
- "@stylistic/eslint-plugin": "^5.2.3",
19
- "@types/bun": "^1.2.20",
20
- "@vitest/coverage-istanbul": "^3.2.4",
21
- "@vitest/ui": "^3.2.4",
21
+ "@stylistic/eslint-plugin": "^5.6.1",
22
+ "@types/bun": "^1.3.5",
23
+ "@vitest/coverage-istanbul": "^4.0.16",
24
+ "@vitest/ui": "^4.0.16",
22
25
  "changelogen": "^0.6.2",
23
26
  "commitizen": "^4.3.1",
24
27
  "cz-conventional-changelog": "^3.3.0",
25
- "eslint": "^9.33.0",
26
- "globals": "^16.3.0",
28
+ "eslint": "^9.39.2",
29
+ "globals": "^16.5.0",
27
30
  "husky": "^9.1.7",
28
31
  "oxide.ts": "^1.1.0",
29
- "rimraf": "^6.0.1",
30
- "tsup": "^8.5.0",
31
- "typescript-eslint": "^8.40.0",
32
- "vite-tsconfig-paths": "^5.1.4",
33
- "vitest": "^3.2.4"
32
+ "rimraf": "^6.1.2",
33
+ "tsup": "^8.5.1",
34
+ "typescript-eslint": "^8.50.0",
35
+ "vite-tsconfig-paths": "^6.0.3",
36
+ "vitest": "^4.0.16"
34
37
  },
35
38
  "peerDependencies": {
36
- "typescript": "^5.8.3"
37
- },
38
- "exports": {
39
- "./package.json": "./package.json",
40
- ".": {
41
- "import": "./dist/index.js",
42
- "require": "./dist/index.cjs"
43
- }
39
+ "typescript": "^5.9.3"
44
40
  },
45
- "files": [
46
- "dist"
47
- ],
48
41
  "scripts": {
49
42
  "lint": "eslint src/",
50
43
  "lint:fix": "eslint --fix src/",
@@ -192,6 +192,25 @@ function createDomainEvent(type, aggregateId, aggregateType, payload, metadata =
192
192
  metadata
193
193
  });
194
194
  }
195
+ function createRejection(rejectionSpecifics, metadata = {}) {
196
+ return Object.freeze({
197
+ id: crypto.randomUUID(),
198
+ commandId: rejectionSpecifics.commandId,
199
+ commandType: rejectionSpecifics.commandType,
200
+ reasonCode: rejectionSpecifics.reasonCode,
201
+ reason: rejectionSpecifics.reason,
202
+ aggregateType: rejectionSpecifics.aggregateType,
203
+ aggregateId: rejectionSpecifics.aggregateId,
204
+ classification: rejectionSpecifics.classification,
205
+ retryable: rejectionSpecifics.retryable,
206
+ validationErrors: rejectionSpecifics.validationErrors,
207
+ type: `${rejectionSpecifics.commandType}${rejectionSpecifics.type}`,
208
+ details: rejectionSpecifics.details,
209
+ kind: "rejection",
210
+ timestamp: getTimestamp(),
211
+ metadata
212
+ });
213
+ }
195
214
 
196
215
  // src/domain/utils/isEvent.ts
197
216
  function isEvent(event) {
@@ -550,6 +569,7 @@ exports.createIntegrationEvent = createIntegrationEvent;
550
569
  exports.createOutboxEntry = createOutboxEntry;
551
570
  exports.createQuery = createQuery;
552
571
  exports.createQueryNode = createQueryNode;
572
+ exports.createRejection = createRejection;
553
573
  exports.createStoredEvent = createStoredEvent;
554
574
  exports.fail = fail;
555
575
  exports.getTimestamp = getTimestamp;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/utils/getTimestamp.ts","../src/core/utils/createCommand.ts","../src/core/utils/createQuery.ts","../src/core/utils/isCommand.ts","../src/core/utils/isQuery.ts","../src/domain/Specification/Specification.ts","../src/domain/Specification/utils/createQueryNode.ts","../src/domain/Specification/implementations/FieldEquals.specification.ts","../src/utils/fail/fail.ts","../src/utils/invariant/invariant.ts","../src/domain/Specification/implementations/FieldGreaterThan.specification.ts","../src/domain/utils/createDomainEvent.ts","../src/domain/utils/isEvent.ts","../src/domain/utils/isDomainEvent.ts","../src/infrastructure/CommandBus/implementations/SimpleCommandBus.ts","../src/infrastructure/Database/Database.ts","../src/infrastructure/Database/implementations/SimpleDatabase.exceptions.ts","../src/infrastructure/Database/implementations/SimpleDatabase.ts","../src/infrastructure/EventBus/implementations/SimpleEventBus.ts","../src/infrastructure/EventBus/utils/createIntegrationEvent.ts","../src/infrastructure/EventBus/utils/isIntegrationEvent.ts","../src/utils/streamKey/makeStreamKey.ts","../src/utils/isEqual/isEqual.ts","../src/utils/parseAsError/parseAsError.ts","../src/infrastructure/EventStore/utils/createStoredEvent.ts","../src/infrastructure/EventStore/implementations/SimpleEventStore.exceptions.ts","../src/infrastructure/EventStore/implementations/SimpleEventStore.ts","../src/infrastructure/Outbox/implementations/GenericOutboxWorker.ts","../src/infrastructure/Outbox/implementations/InMemoryOutbox.ts","../src/infrastructure/Outbox/utils/createOutboxEntry.ts","../src/infrastructure/QueryBus/implementations/SimpleQueryBus.ts","../src/infrastructure/Repository/implementations/SimpleRepository.ts"],"names":["randomUUID","Operation","event"],"mappings":";;;;;;;AAAa,IAAA,YAAA,GAAe,CAAC,IAAA,mBAAiB,IAAA,IAAA,EAAmB,KAAA,IAAA,CAAK,KAAM,CAAA,IAAA,CAAK,OAAQ,EAAA,GAAI,GAAI;;;ACI1F,SAAS,cAA8C,IAAa,EAAA,WAAA,EAAqB,eAAuB,OAAmB,EAAA,QAAA,GAAqC,EAA8B,EAAA;AAC3M,EAAA,OAAO,OAAO,MAAO,CAAA;AAAA,IACnB,IAAIA,iBAAW,EAAA;AAAA,IACf,IAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAA,EAAa,OAAO,WAAW,CAAA;AAAA,IAC/B,OAAA;AAAA,I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CAAC,OAAS,EAAA;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAoC,iCAAA,EAAA,MAAA,CAAO,IAAI,CAAE,CAAA,CAAA;AAAA;AAEnE,IAAO,OAAA,OAAA,CAAQ,QAAQ,MAAM,CAAA;AAAA;AAEjC;;;ACnBO,IAAM,mBAAN,MAAmI;AAAA,EACxI,WACmB,CAAA,UAAA,EACR,UACQ,EAAA,QAAA,EACA,YACjB,EAAA;AAJiB,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACR,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACQ,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AAAA;AAEnB,EAEA,MAAM,KAAK,WAAsC,EAAA;AAC/C,IAAA,MAAM,aAAa,MAAM,IAAA,CAAK,WAAW,IAAK,CAAA,IAAA,CAAK,YAAY,WAAW,CAAA;AAC1E,IAAA,OAAO,WACJ,MAAe,CAAA,IAAA,CAAK,UAAU,IAAK,CAAA,YAAA,CAAa,WAAW,CAAC,CAAA;AAAA;AACjE,EAEA,MAAM,MAAM,MAAiC,EAAA;AAC3C,IAAA,MAAM,OAAQ,CAAA,GAAA;AAAA,MACZ,MAAO,CAAA,GAAA;AAAA,QACL,OAAM,KAAS,KAAA,IAAA,CAAK,UAAW,CAAA,MAAA;AAAA,UAC7B,IAAK,CAAA,UAAA;AAAA,UACL,CAAC,KAAK;AAAA;AACR;AACF,KACF;AAAA;AAEJ","file":"index.cjs","sourcesContent":["export const getTimestamp = (date: Date = new Date()): number => Math.floor(date.getTime() / 1000)\n","import type { Command, CommandMetadata } from '@core/Command.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createCommand<TType extends string, TPayload>(type: TType, aggregateId: string, aggregateType: string, payload: TPayload, metadata: Partial<CommandMetadata> = {}): Command<TType, TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n aggregateType,\n aggregateId: String(aggregateId),\n payload,\n kind: 'command',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { Query, QueryMetadata } from '@core/Query.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createQuery<TType extends string, TPayload>(type: TType, payload: TPayload, metadata: QueryMetadata = {}): Query<TType, TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n payload,\n kind: 'query',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { Command } from '@core/Command.ts'\n\nexport function isCommand(candidate: unknown): candidate is Command<string, unknown> {\n if (candidate === null)\n return false\n if (typeof candidate !== 'object')\n return false\n if (!('type' in candidate))\n return false\n return 'kind' in candidate && candidate.kind === 'command'\n}\n","import type { Query } from '@core/Query.ts'\n\nexport function isQuery(candidate: unknown): candidate is Query<unknown> {\n if (candidate === null)\n return false\n if (typeof candidate !== 'object')\n return false\n if (!('type' in candidate))\n return false\n return 'kind' in candidate && candidate.kind === 'query'\n}\n","import type { QueryNode } from './QueryNode.ts'\n\nexport interface Specification<T> {\n isSatisfiedBy(entity: T): boolean\n}\n\nexport abstract class CompositeSpecification<T> implements Specification<T> {\n abstract isSatisfiedBy(entity: T): boolean\n\n abstract toQuery(): QueryNode\n\n and(other: CompositeSpecification<T>): CompositeSpecification<T> {\n return new AndSpecification(this, other)\n }\n\n or(other: CompositeSpecification<T>): CompositeSpecification<T> {\n return new OrSpecification(this, other)\n }\n\n not(): CompositeSpecification<T> {\n return new NotSpecification(this)\n }\n}\n\nexport class AndSpecification<T> extends CompositeSpecification<T> {\n constructor(private left: CompositeSpecification<T>, private right: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return this.left.isSatisfiedBy(entity) && this.right.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'and',\n nodes: [this.left.toQuery(), this.right.toQuery()],\n }\n }\n}\n\nexport class OrSpecification<T> extends CompositeSpecification<T> {\n constructor(private left: CompositeSpecification<T>, private right: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return this.left.isSatisfiedBy(entity) || this.right.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'or',\n nodes: [this.left.toQuery(), this.right.toQuery()],\n }\n }\n}\n\nexport class NotSpecification<T> extends CompositeSpecification<T> {\n constructor(private spec: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return !this.spec.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'not',\n node: this.spec.toQuery(),\n }\n }\n}\n","import type { Primitive } from '@core/types/Primitive.ts'\nimport type { QueryNode } from '../QueryNode.ts'\n\nexport function createQueryNode(type: 'eq' | 'gt' | 'lt', field: string | number | symbol, value: Primitive): QueryNode\nexport function createQueryNode(type: 'and' | 'or', field: undefined, value: QueryNode[]): QueryNode\nexport function createQueryNode(type: 'not', field: undefined, value: QueryNode): QueryNode\nexport function createQueryNode(\n type: QueryNode['type'],\n field: string | number | symbol | undefined,\n value: Primitive | QueryNode | QueryNode[],\n): QueryNode {\n switch (type) {\n case 'eq':\n case 'gt':\n case 'lt':\n return { type, field: field as string, value: value as Primitive }\n case 'and':\n case 'or':\n return { type, nodes: value as QueryNode[] }\n case 'not':\n return { type, node: value as QueryNode }\n }\n}\n","import type { Primitive } from '@core/types/Primitive.ts'\nimport type { QueryNode } from '../QueryNode.ts'\nimport { CompositeSpecification } from '../Specification.ts'\nimport { createQueryNode } from '../utils/createQueryNode.ts'\n\nexport class FieldEquals<T> extends CompositeSpecification<T> {\n constructor(private field: keyof T, private value: Primitive) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return entity[this.field] === this.value\n }\n\n toQuery(): QueryNode {\n return createQueryNode('eq', this.field, this.value)\n }\n}\n","export function fail(anExpression: Error) {\n return () => {\n throw anExpression\n }\n}\n","export function invariant(condition: boolean, onInvalid: () => never): asserts condition {\n if (!condition)\n onInvalid()\n}\n","import type { QueryNode } from '../QueryNode.ts'\nimport { fail } from '@utils/fail/fail.ts'\nimport { invariant } from '@utils/invariant/invariant.ts'\nimport { CompositeSpecification } from '../Specification.ts'\nimport { createQueryNode } from '../utils/createQueryNode.ts'\n\nexport class FieldGreaterThan<T> extends CompositeSpecification<T> {\n constructor(\n private field: keyof T,\n private value: number,\n ) {\n super()\n }\n\n private isNumber(value: unknown): value is number {\n return typeof value === 'number'\n }\n\n isSatisfiedBy(entity: T): boolean {\n const field = entity[this.field]\n invariant(\n this.isNumber(field),\n fail(new TypeError(`Field ${String(this.field)} is not a number`),\n ),\n )\n return field > this.value\n }\n\n toQuery(): QueryNode {\n return createQueryNode('gt', this.field, this.value)\n }\n}\n","import type { DomainEvent, DomainEventMetadata } from '@domain/DomainEvent.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createDomainEvent<TPayload = unknown>(\n type: string,\n aggregateId: string,\n aggregateType: string,\n payload: TPayload,\n metadata: Partial<DomainEventMetadata> = {},\n): DomainEvent<TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n aggregateId,\n aggregateType,\n payload,\n kind: 'domain',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\n\nexport function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent {\n if (typeof event !== 'object')\n return false\n if (event === null)\n return false\n if (!('type' in event))\n return false\n return 'kind' in event\n}\n","import type { DomainEvent } from '../DomainEvent.ts'\nimport { isEvent } from './isEvent.ts'\n\nexport function isDomainEvent(event: unknown): event is DomainEvent {\n return isEvent(event)\n && 'aggregateId' in event\n && event.kind === 'domain'\n}\n","import type { Command } from '@core/Command.ts'\nimport type { CommandHandler } from '@core/CommandHandler.ts'\nimport type { CommandBus } from '../CommandBus.ts'\n\nexport class SimpleCommandBus<TCommand extends Command> implements CommandBus<TCommand> {\n private handlers: Map<TCommand['type'], CommandHandler<TCommand>> = new Map()\n\n register(aTypeOfCommand: TCommand['type'], anHandler: CommandHandler<TCommand>): void {\n if (this.handlers.has(aTypeOfCommand)) {\n throw new Error(`Handler already registered for command type: ${aTypeOfCommand}`)\n }\n this.handlers.set(aTypeOfCommand, anHandler)\n }\n\n async execute(aCommand: TCommand): Promise<void> {\n const handler = this.handlers.get(aCommand.type)\n if (!handler) {\n throw new Error(`No handler found for command type: ${aCommand.type}`)\n }\n return handler.execute(aCommand)\n }\n}\n","import type { CompositeSpecification } from '@domain/Specification/Specification.ts'\nimport type { WithIdentifier } from '../../core/types/WithIdentifier.ts'\n\nexport enum Operation {\n CREATE = 'CREATE',\n PUT = 'PUT',\n PATCH = 'PATCH',\n DELETE = 'DELETE',\n}\n\ninterface Statement<TModel> {\n operation: Operation\n payload: TModel\n}\n\nexport interface CreateStatement<TModel> extends Statement<TModel> {\n operation: Operation.CREATE\n payload: TModel\n}\n\nexport interface PutStatement<TModel> extends Statement<TModel> {\n operation: Operation.PUT\n payload: TModel\n}\n\nexport interface PatchStatement<TModel> extends Statement<Partial<TModel>> {\n operation: Operation.PATCH\n payload: WithIdentifier<Partial<TModel>>\n}\n\nexport interface DeleteStatement extends Statement<WithIdentifier> {\n operation: Operation.DELETE\n payload: WithIdentifier\n}\n\ninterface Executable<TModel, TReturnType = Promise<void>> {\n execute(tableName: string, statement: CreateStatement<TModel>): TReturnType\n execute(tableName: string, statement: PutStatement<TModel>): TReturnType\n execute(tableName: string, statement: PatchStatement<TModel>): TReturnType\n execute(tableName: string, statement: DeleteStatement): TReturnType\n}\n\ninterface QueryAble<TModel, TReturnType = Promise<TModel[]>> {\n query(collectionName: string, specification: CompositeSpecification<TModel>): TReturnType\n}\n\nexport interface Database<TModel, TExecuteReturnType = Promise<void>, TQueryReturnType = Promise<TModel[]>>\n extends\n QueryAble<TModel, TQueryReturnType>,\n Executable<TModel, TExecuteReturnType> { }\n","export class RecordNotFoundException extends Error {\n constructor(id: string) {\n super(`Record not found for id: ${id}`)\n }\n}\n\nexport class DuplicateRecordException extends Error {\n constructor(id: string) {\n super(`Duplicate record found for id: ${id}`)\n }\n}\n\nexport class DatabaseOfflineException extends Error {\n constructor() {\n super(`Database is offline`)\n }\n}\n","import type { CompositeSpecification } from '@domain/Specification/Specification.ts'\nimport type { WithIdentifier } from '../../../core/types/WithIdentifier.ts'\nimport type { CreateStatement, Database, DeleteStatement, PatchStatement, PutStatement } from '../Database.ts'\nimport { Operation } from '../Database.ts'\nimport { DatabaseOfflineException, DuplicateRecordException, RecordNotFoundException } from './SimpleDatabase.exceptions.ts'\n\nexport class SimpleDatabase<TModel extends WithIdentifier> implements Database<TModel, Promise<void>, Promise<TModel[]>> {\n private readonly datasource = new Map<string, TModel[]>()\n private simulateOffline = false\n\n async query(\n tableName: string,\n specification: CompositeSpecification<TModel>,\n ): Promise<TModel[]> {\n if (this.simulateOffline)\n throw new DatabaseOfflineException()\n\n const tableRecords = (this.datasource.get(tableName) || [])\n return tableRecords\n .filter((record: TModel) => specification.isSatisfiedBy(record))\n }\n\n async execute(\n tableName: string,\n statement: CreateStatement<TModel> | PutStatement<TModel> | PatchStatement<TModel> | DeleteStatement,\n ): Promise<void> {\n if (this.simulateOffline)\n throw new DatabaseOfflineException()\n\n if (!this.datasource.has(tableName))\n this.datasource.set(tableName, [])\n const table = this.datasource.get(tableName)!\n\n switch (statement.operation) {\n case Operation.CREATE: {\n const isDuplicate = table.some(item => item.id === statement.payload.id)\n if (isDuplicate)\n throw new DuplicateRecordException(statement.payload.id)\n table.push(statement.payload)\n break\n }\n case Operation.PUT:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table[index] = statement.payload\n break\n }\n case Operation.PATCH:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table[index] = { ...table[index], ...statement.payload }\n break\n }\n case Operation.DELETE:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table.splice(index, 1)\n break\n }\n }\n }\n\n goOffline(): void {\n this.simulateOffline = true\n }\n}\n","import type { EventHandler } from '@core/EventHandler.ts'\nimport type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\nimport type { EventConsumer, EventProducer } from '../EventBus.ts'\n\nexport class SimpleEventBus<TEvent extends DomainEvent | IntegrationEvent | ExternalEvent>\nimplements EventConsumer<TEvent>, EventProducer<TEvent> {\n private handlers = new Map<string, EventHandler<TEvent>[]>()\n\n subscribe(\n stream: string,\n aHandler: EventHandler<TEvent>,\n ): void {\n const handlersForType = this.handlers.get(stream) ?? []\n handlersForType.push(aHandler)\n this.handlers.set(stream, handlersForType)\n }\n\n async consume(stream: string, anEvent: TEvent): Promise<void> {\n if (!this.handlers.has(stream))\n return\n const handlers = this.handlers.get(stream) as EventHandler<TEvent>[]\n await Promise.all(handlers.map(async (handler) => {\n return handler.handle(anEvent)\n }))\n }\n\n async publish(stream: string, anEvent: TEvent): Promise<void> {\n await this.consume(stream, anEvent)\n }\n}\n","import type { IntegrationEvent, IntegrationEventMetadata } from '../IntegrationEvent.ts'\nimport { randomUUID } from 'node:crypto'\n\nexport function createIntegrationEvent<TPayload = unknown>(type: string, payload: TPayload, metadata?: Partial<IntegrationEventMetadata>): IntegrationEvent<TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n payload,\n timestamp: new Date().toISOString(),\n metadata: {\n ...metadata,\n },\n kind: 'integration',\n })\n}\n","import type { IntegrationEvent } from '../IntegrationEvent.ts'\nimport { isEvent } from '@domain/utils/isEvent.ts'\n\nexport function isIntegrationEvent<TPayload>(event: unknown): event is IntegrationEvent<TPayload> {\n return isEvent(event)\n && event.kind === 'integration'\n}\n","import type { StreamKey } from '@utils/streamKey/StreamKey.ts'\n\nexport function makeStreamKey(streamName: string, aggregateId: string): StreamKey {\n return `${streamName}#${aggregateId}`\n}\n","export function isEqual<T>(a: T, b: T): boolean {\n if (a === b) {\n return true\n }\n\n // eslint-disable-next-line ts/strict-boolean-expressions\n const bothAreObjects = a && b && typeof a === 'object' && typeof b === 'object'\n\n return Boolean(\n bothAreObjects\n && Object.keys(a).length === Object.keys(b).length\n && Object.entries(a).every(([k, v]) => isEqual(v, b[k as keyof T])),\n )\n}\n","export function parseAsError(value: unknown): Error {\n if (value instanceof Error)\n return value\n if (typeof value === 'string')\n return new Error(value)\n try {\n const json = JSON.stringify(value)\n return new Error(json ?? String(value))\n }\n catch {\n return new Error('Unknown error')\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { StoredEvent } from '../StoredEvent.ts'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\nimport { makeStreamKey } from '@utils/index.ts'\n\nexport function createStoredEvent<TEvent extends DomainEvent>(\n streamName: string,\n version: number,\n event: TEvent,\n): StoredEvent<TEvent> {\n return Object.freeze({\n id: event.id,\n streamKey: makeStreamKey(streamName, event.aggregateId),\n version,\n timestamp: getTimestamp(),\n event,\n })\n}\n","export class MultipleAggregatesException extends Error {\n constructor() {\n super('EventStore append does not support multiple aggregates to be stored')\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Database } from '@infrastructure/Database/Database.ts'\nimport type { EventStore } from '@infrastructure/EventStore/EventStore.ts'\nimport type { Outbox } from '@infrastructure/Outbox/Outbox.ts'\nimport type { StreamKey } from '@utils/streamKey/StreamKey.ts'\nimport type { StoredEvent } from '../StoredEvent.ts'\nimport { FieldEquals } from '@domain/Specification/implementations/FieldEquals.specification.ts'\nimport { Operation } from '@infrastructure/Database/Database.ts'\nimport { makeStreamKey } from '@utils/streamKey/makeStreamKey.ts'\nimport { createStoredEvent } from '../utils/createStoredEvent.ts'\nimport { MultipleAggregatesException } from './SimpleEventStore.exceptions.ts'\n\nexport class SimpleEventStore<TEvent extends DomainEvent> implements EventStore<TEvent, Promise<void>, Promise<TEvent[]>> {\n private readonly tableName: string = 'event_store'\n\n constructor(\n private readonly database: Database<StoredEvent<TEvent>, Promise<void>, Promise<StoredEvent<TEvent>[]>>,\n private readonly outbox?: Outbox,\n ) { }\n\n async load(streamName: string, aggregateId: string): Promise<TEvent[]> {\n const streamKey: StreamKey = makeStreamKey(streamName, aggregateId)\n const specification = new FieldEquals('streamKey', streamKey)\n const storedEvents = await this.database.query(this.tableName, specification)\n return storedEvents.map(storedEvent => storedEvent.event)\n }\n\n async append(streamName: string, events: TEvent[]): Promise<void> {\n const uniqueAggregateIds = new Set(events.map(event => event.aggregateId))\n if (uniqueAggregateIds.size > 1)\n throw new MultipleAggregatesException()\n\n const event = events[0]\n const currentStream = await this.load(streamName, event.aggregateId)\n const eventsToStore = events\n .map(event => createStoredEvent(streamName, currentStream.length + 1, event))\n await Promise.all(\n eventsToStore.map(async payload => this.database.execute(this.tableName, { operation: Operation.CREATE, payload }),\n ),\n )\n await Promise.all(events.map(async event => this.outbox?.enqueue(event)))\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { EventProducer } from '@infrastructure/EventBus/EventBus.js'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\nimport type { OutboxWorker } from '@infrastructure/Outbox/OutboxWorker.ts'\nimport type { Outbox } from '../Outbox.ts'\n\nexport class GenericOutboxWorker implements OutboxWorker {\n constructor(\n protected outbox: Outbox,\n protected eventBus: EventProducer<DomainEvent | IntegrationEvent | ExternalEvent>,\n protected stream: string,\n ) {}\n\n async runOnce(): Promise<void> {\n const pending = await this.outbox.getPending()\n\n await Promise.all(pending.map(async (entry) => {\n try {\n await this.eventBus.publish(this.stream, entry.event)\n await this.outbox.markAsPublished(entry.id)\n }\n catch {\n await this.outbox.markAsFailed(entry.id)\n }\n }))\n }\n\n async tick(): Promise<void> {\n await this.runOnce()\n }\n\n start(intervalMs: number): void {\n setInterval(() => {\n void this.tick().catch(console.error)\n }, intervalMs)\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Outbox } from '../Outbox.ts'\nimport type { OutboxEntry } from '../OutboxEntry.ts'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport class InMemoryOutbox implements Outbox {\n protected entries: OutboxEntry[] = []\n protected idCounter = 0\n\n async enqueue(event: DomainEvent<unknown>): Promise<void> {\n this.entries.push({\n id: (this.idCounter++).toString(),\n event,\n published: false,\n retryCount: 0,\n })\n }\n\n async getPending(limit = 100): Promise<OutboxEntry[]> {\n return this.entries.filter(e => !e.published).slice(0, limit)\n }\n\n async markAsPublished(id: string): Promise<void> {\n const entry = this.entries.find(e => e.id === id)\n if (entry) {\n entry.published = true\n }\n }\n\n async markAsFailed(id: string): Promise<void> {\n const entry = this.entries.find(e => e.id === id)\n if (entry) {\n entry.retryCount += 1\n entry.lastAttemptAt = getTimestamp()\n }\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { OutboxEntry } from '../OutboxEntry.ts'\nimport { randomUUID } from 'node:crypto'\n\nexport function createOutboxEntry(\n event: DomainEvent<unknown>,\n): OutboxEntry {\n return Object.freeze({\n id: randomUUID(),\n event,\n published: false,\n retryCount: 0,\n lastAttemptAt: undefined,\n })\n}\n","import type { Query } from '@core/Query.ts'\nimport type { QueryHandler } from '@core/QueryHandler.ts'\nimport type { QueryBus } from '../QueryBus.ts'\n\nexport class SimpleQueryBus<TQuery extends Query, TProjection> implements QueryBus<TQuery, Promise<TProjection>> {\n private handlers: Map<TQuery['type'], QueryHandler<TQuery, Promise<TProjection>>> = new Map()\n\n register(\n aTypeOfQuery: TQuery['type'],\n anHandler: QueryHandler<TQuery, Promise<TProjection>>,\n ): void {\n if (this.handlers.has(aTypeOfQuery)) {\n throw new Error(`Handler already registered for query type: ${aTypeOfQuery}`)\n }\n this.handlers.set(aTypeOfQuery, anHandler)\n }\n\n async execute(aQuery: TQuery): Promise<TProjection> {\n const handler = this.handlers.get(aQuery.type)\n if (!handler) {\n throw new Error(`No handler found for query type: ${aQuery.type}`)\n }\n return handler.execute(aQuery)\n }\n}\n","import type { Decider } from '@domain/Decider.ts'\nimport type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Repository } from '@domain/Repository.ts'\nimport type { EventStore } from '@infrastructure/EventStore/EventStore.ts'\n\nexport class SimpleRepository<TState, TCommand, TEvent extends DomainEvent> implements Repository<TEvent, Promise<TState>, Promise<void>> {\n constructor(\n private readonly eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>,\n readonly streamName: string,\n private readonly evolveFn: Decider<TState, TCommand, TEvent>['evolve'],\n private readonly initialState: Decider<TState, TCommand, TEvent>['initialState'],\n ) {\n }\n\n async load(aggregateId: string): Promise<TState> {\n const pastEvents = await this.eventStore.load(this.streamName, aggregateId)\n return pastEvents\n .reduce<TState>(this.evolveFn, this.initialState(aggregateId))\n }\n\n async store(events: TEvent[]): Promise<void> {\n await Promise.all(\n events.map(\n async event => this.eventStore.append(\n this.streamName,\n [event],\n ),\n ),\n )\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/core/utils/getTimestamp.ts","../src/core/utils/createCommand.ts","../src/core/utils/createQuery.ts","../src/core/utils/isCommand.ts","../src/core/utils/isQuery.ts","../src/domain/Specification/Specification.ts","../src/domain/Specification/utils/createQueryNode.ts","../src/domain/Specification/implementations/FieldEquals.specification.ts","../src/utils/fail/fail.ts","../src/utils/invariant/invariant.ts","../src/domain/Specification/implementations/FieldGreaterThan.specification.ts","../src/domain/utils/createDomainEvent.ts","../src/domain/utils/createRejection.ts","../src/domain/utils/isEvent.ts","../src/domain/utils/isDomainEvent.ts","../src/infrastructure/CommandBus/implementations/SimpleCommandBus.ts","../src/infrastructure/Database/Database.ts","../src/infrastructure/Database/implementations/SimpleDatabase.exceptions.ts","../src/infrastructure/Database/implementations/SimpleDatabase.ts","../src/infrastructure/EventBus/implementations/SimpleEventBus.ts","../src/infrastructure/EventBus/utils/createIntegrationEvent.ts","../src/infrastructure/EventBus/utils/isIntegrationEvent.ts","../src/utils/streamKey/makeStreamKey.ts","../src/utils/isEqual/isEqual.ts","../src/utils/parseAsError/parseAsError.ts","../src/infrastructure/EventStore/utils/createStoredEvent.ts","../src/infrastructure/EventStore/implementations/SimpleEventStore.exceptions.ts","../src/infrastructure/EventStore/implementations/SimpleEventStore.ts","../src/infrastructure/Outbox/implementations/GenericOutboxWorker.ts","../src/infrastructure/Outbox/implementations/InMemoryOutbox.ts","../src/infrastructure/Outbox/utils/createOutboxEntry.ts","../src/infrastructure/QueryBus/implementations/SimpleQueryBus.ts","../src/infrastructure/Repository/implementations/SimpleRepository.ts"],"names":["randomUUID","Operation","event"],"mappings":";;;;;;;AAAO,IAAM,YAAA,GAAe,CAAC,IAAA,mBAAa,IAAI,IAAA,EAAK,KAAc,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,OAAA,EAAQ,GAAI,GAAI;;;ACI1F,SAAS,cAA8C,IAAA,EAAa,WAAA,EAAqB,eAAuB,OAAA,EAAmB,QAAA,GAAqC,EAAC,EAA6B;AAC3M,EAAA,OAAO,OAAO,MAAA,CAAO;AAAA,IACnB,IAAIA,iBAAA,EAAW;AAAA,IACf,IAAA;AAAA,IACA,aAAA;AAAA,IACA,WAAA,EAAa,OAAO,WAAW,CAAA;AAAA,IAC/B,OAAA;AAAA,IACA,IAAA,EAAM,SAAA;AAAA,IACN,WAAW,YAAA,EAAa;AAAA,IACxB;AAAA,GACD,CAAA;AACH;ACXO,SAAS,WAAA,CAA4C,IAAA,EAAa,OAAA,EAAmB,QAAA,GAA0B,EAAC,EAA2B;AAChJ,EAAA,OAAO,OAAO,MAAA,CA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AAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AAAA,EAEnB;AAAA,EAEA,MAAM,KAAK,WAAA,EAAsC;AAC/C,IAAA,MAAM,aAAa,MAAM,IAAA,CAAK,WAAW,IAAA,CAAK,IAAA,CAAK,YAAY,WAAW,CAAA;AAC1E,IAAA,OAAO,WACJ,MAAA,CAAe,IAAA,CAAK,UAAU,IAAA,CAAK,YAAA,CAAa,WAAW,CAAC,CAAA;AAAA,EACjE;AAAA,EAEA,MAAM,MAAM,MAAA,EAAiC;AAC3C,IAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,MACZ,MAAA,CAAO,GAAA;AAAA,QACL,OAAM,KAAA,KAAS,IAAA,CAAK,UAAA,CAAW,MAAA;AAAA,UAC7B,IAAA,CAAK,UAAA;AAAA,UACL,CAAC,KAAK;AAAA;AACR;AACF,KACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["export const getTimestamp = (date: Date = new Date()): number => Math.floor(date.getTime() / 1000)\n","import type { Command, CommandMetadata } from '@core/Command.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createCommand<TType extends string, TPayload>(type: TType, aggregateId: string, aggregateType: string, payload: TPayload, metadata: Partial<CommandMetadata> = {}): Command<TType, TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n aggregateType,\n aggregateId: String(aggregateId),\n payload,\n kind: 'command',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { Query, QueryMetadata } from '@core/Query.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createQuery<TType extends string, TPayload>(type: TType, payload: TPayload, metadata: QueryMetadata = {}): Query<TType, TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n payload,\n kind: 'query',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { Command } from '@core/Command.ts'\n\nexport function isCommand(candidate: unknown): candidate is Command<string, unknown> {\n if (candidate === null)\n return false\n if (typeof candidate !== 'object')\n return false\n if (!('type' in candidate))\n return false\n return 'kind' in candidate && candidate.kind === 'command'\n}\n","import type { Query } from '@core/Query.ts'\n\nexport function isQuery(candidate: unknown): candidate is Query<unknown> {\n if (candidate === null)\n return false\n if (typeof candidate !== 'object')\n return false\n if (!('type' in candidate))\n return false\n return 'kind' in candidate && candidate.kind === 'query'\n}\n","import type { QueryNode } from './QueryNode.ts'\n\nexport interface Specification<T> {\n isSatisfiedBy(entity: T): boolean\n}\n\nexport abstract class CompositeSpecification<T> implements Specification<T> {\n abstract isSatisfiedBy(entity: T): boolean\n\n abstract toQuery(): QueryNode\n\n and(other: CompositeSpecification<T>): CompositeSpecification<T> {\n return new AndSpecification(this, other)\n }\n\n or(other: CompositeSpecification<T>): CompositeSpecification<T> {\n return new OrSpecification(this, other)\n }\n\n not(): CompositeSpecification<T> {\n return new NotSpecification(this)\n }\n}\n\nexport class AndSpecification<T> extends CompositeSpecification<T> {\n constructor(private left: CompositeSpecification<T>, private right: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return this.left.isSatisfiedBy(entity) && this.right.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'and',\n nodes: [this.left.toQuery(), this.right.toQuery()],\n }\n }\n}\n\nexport class OrSpecification<T> extends CompositeSpecification<T> {\n constructor(private left: CompositeSpecification<T>, private right: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return this.left.isSatisfiedBy(entity) || this.right.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'or',\n nodes: [this.left.toQuery(), this.right.toQuery()],\n }\n }\n}\n\nexport class NotSpecification<T> extends CompositeSpecification<T> {\n constructor(private spec: CompositeSpecification<T>) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return !this.spec.isSatisfiedBy(entity)\n }\n\n toQuery(): QueryNode {\n return {\n type: 'not',\n node: this.spec.toQuery(),\n }\n }\n}\n","import type { Primitive } from '@core/types/Primitive.ts'\nimport type { QueryNode } from '../QueryNode.ts'\n\nexport function createQueryNode(type: 'eq' | 'gt' | 'lt', field: string | number | symbol, value: Primitive): QueryNode\nexport function createQueryNode(type: 'and' | 'or', field: undefined, value: QueryNode[]): QueryNode\nexport function createQueryNode(type: 'not', field: undefined, value: QueryNode): QueryNode\nexport function createQueryNode(\n type: QueryNode['type'],\n field: string | number | symbol | undefined,\n value: Primitive | QueryNode | QueryNode[],\n): QueryNode {\n switch (type) {\n case 'eq':\n case 'gt':\n case 'lt':\n return { type, field: field as string, value: value as Primitive }\n case 'and':\n case 'or':\n return { type, nodes: value as QueryNode[] }\n case 'not':\n return { type, node: value as QueryNode }\n }\n}\n","import type { Primitive } from '@core/types/Primitive.ts'\nimport type { QueryNode } from '../QueryNode.ts'\nimport { CompositeSpecification } from '../Specification.ts'\nimport { createQueryNode } from '../utils/createQueryNode.ts'\n\nexport class FieldEquals<T> extends CompositeSpecification<T> {\n constructor(private field: keyof T, private value: Primitive) {\n super()\n }\n\n isSatisfiedBy(entity: T): boolean {\n return entity[this.field] === this.value\n }\n\n toQuery(): QueryNode {\n return createQueryNode('eq', this.field, this.value)\n }\n}\n","export function fail(anExpression: Error) {\n return () => {\n throw anExpression\n }\n}\n","export function invariant(condition: boolean, onInvalid: () => never): asserts condition {\n if (!condition)\n onInvalid()\n}\n","import type { QueryNode } from '../QueryNode.ts'\nimport { fail } from '@utils/fail/fail.ts'\nimport { invariant } from '@utils/invariant/invariant.ts'\nimport { CompositeSpecification } from '../Specification.ts'\nimport { createQueryNode } from '../utils/createQueryNode.ts'\n\nexport class FieldGreaterThan<T> extends CompositeSpecification<T> {\n constructor(\n private field: keyof T,\n private value: number,\n ) {\n super()\n }\n\n private isNumber(value: unknown): value is number {\n return typeof value === 'number'\n }\n\n isSatisfiedBy(entity: T): boolean {\n const field = entity[this.field]\n invariant(\n this.isNumber(field),\n fail(new TypeError(`Field ${String(this.field)} is not a number`),\n ),\n )\n return field > this.value\n }\n\n toQuery(): QueryNode {\n return createQueryNode('gt', this.field, this.value)\n }\n}\n","import type { DomainEvent, DomainEventMetadata } from '@domain/DomainEvent.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createDomainEvent<TPayload = unknown>(\n type: string,\n aggregateId: string,\n aggregateType: string,\n payload: TPayload,\n metadata: Partial<DomainEventMetadata> = {},\n): DomainEvent<TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n aggregateId,\n aggregateType,\n payload,\n kind: 'domain',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { Rejection, RejectionMetadata } from '@domain/Rejection.ts'\nimport { randomUUID } from 'node:crypto'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport function createRejection<TDetails = unknown>(\n rejectionSpecifics: {\n commandId: Rejection['commandId']\n commandType: Rejection['commandType']\n reasonCode: Rejection['reasonCode']\n reason?: Rejection['reason']\n aggregateType?: Rejection['aggregateType']\n aggregateId?: Rejection['aggregateId']\n classification: Rejection['classification']\n retryable?: Rejection['retryable']\n validationErrors?: Rejection['validationErrors']\n type: 'Failed' | 'Rejected' | string\n details?: TDetails\n },\n metadata: Partial<RejectionMetadata> = {},\n): Rejection<TDetails> {\n return Object.freeze({\n id: randomUUID(),\n commandId: rejectionSpecifics.commandId,\n commandType: rejectionSpecifics.commandType,\n reasonCode: rejectionSpecifics.reasonCode,\n reason: rejectionSpecifics.reason,\n aggregateType: rejectionSpecifics.aggregateType,\n aggregateId: rejectionSpecifics.aggregateId,\n classification: rejectionSpecifics.classification,\n retryable: rejectionSpecifics.retryable,\n validationErrors: rejectionSpecifics.validationErrors,\n type: `${rejectionSpecifics.commandType}${rejectionSpecifics.type}`,\n details: rejectionSpecifics.details,\n kind: 'rejection',\n timestamp: getTimestamp(),\n metadata,\n })\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Rejection } from '@domain/Rejection.ts'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\n\nexport function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent | Rejection {\n if (typeof event !== 'object')\n return false\n if (event === null)\n return false\n if (!('type' in event))\n return false\n return 'kind' in event\n}\n","import type { DomainEvent } from '../DomainEvent.ts'\nimport { isEvent } from './isEvent.ts'\n\nexport function isDomainEvent(event: unknown): event is DomainEvent {\n return isEvent(event)\n && 'aggregateId' in event\n && event.kind === 'domain'\n}\n","import type { Command } from '@core/Command.ts'\nimport type { CommandHandler } from '@core/CommandHandler.ts'\nimport type { CommandBus } from '../CommandBus.ts'\n\nexport class SimpleCommandBus<TCommand extends Command> implements CommandBus<TCommand> {\n private handlers: Map<TCommand['type'], CommandHandler<TCommand>> = new Map()\n\n register(aTypeOfCommand: TCommand['type'], anHandler: CommandHandler<TCommand>): void {\n if (this.handlers.has(aTypeOfCommand)) {\n throw new Error(`Handler already registered for command type: ${aTypeOfCommand}`)\n }\n this.handlers.set(aTypeOfCommand, anHandler)\n }\n\n async execute(aCommand: TCommand): Promise<void> {\n const handler = this.handlers.get(aCommand.type)\n if (!handler) {\n throw new Error(`No handler found for command type: ${aCommand.type}`)\n }\n return handler.execute(aCommand)\n }\n}\n","import type { CompositeSpecification } from '@domain/Specification/Specification.ts'\nimport type { WithIdentifier } from '../../core/types/WithIdentifier.ts'\n\nexport enum Operation {\n CREATE = 'CREATE',\n PUT = 'PUT',\n PATCH = 'PATCH',\n DELETE = 'DELETE',\n}\n\ninterface Statement<TModel> {\n operation: Operation\n payload: TModel\n}\n\nexport interface CreateStatement<TModel> extends Statement<TModel> {\n operation: Operation.CREATE\n payload: TModel\n}\n\nexport interface PutStatement<TModel> extends Statement<TModel> {\n operation: Operation.PUT\n payload: TModel\n}\n\nexport interface PatchStatement<TModel> extends Statement<Partial<TModel>> {\n operation: Operation.PATCH\n payload: WithIdentifier<Partial<TModel>>\n}\n\nexport interface DeleteStatement extends Statement<WithIdentifier> {\n operation: Operation.DELETE\n payload: WithIdentifier\n}\n\ninterface Executable<TModel, TReturnType = Promise<void>> {\n execute(tableName: string, statement: CreateStatement<TModel>): TReturnType\n execute(tableName: string, statement: PutStatement<TModel>): TReturnType\n execute(tableName: string, statement: PatchStatement<TModel>): TReturnType\n execute(tableName: string, statement: DeleteStatement): TReturnType\n}\n\ninterface QueryAble<TModel, TReturnType = Promise<TModel[]>> {\n query(collectionName: string, specification: CompositeSpecification<TModel>): TReturnType\n}\n\nexport interface Database<TModel, TExecuteReturnType = Promise<void>, TQueryReturnType = Promise<TModel[]>>\n extends\n QueryAble<TModel, TQueryReturnType>,\n Executable<TModel, TExecuteReturnType> { }\n","export class RecordNotFoundException extends Error {\n constructor(id: string) {\n super(`Record not found for id: ${id}`)\n }\n}\n\nexport class DuplicateRecordException extends Error {\n constructor(id: string) {\n super(`Duplicate record found for id: ${id}`)\n }\n}\n\nexport class DatabaseOfflineException extends Error {\n constructor() {\n super(`Database is offline`)\n }\n}\n","import type { CompositeSpecification } from '@domain/Specification/Specification.ts'\nimport type { WithIdentifier } from '../../../core/types/WithIdentifier.ts'\nimport type { CreateStatement, Database, DeleteStatement, PatchStatement, PutStatement } from '../Database.ts'\nimport { Operation } from '../Database.ts'\nimport { DatabaseOfflineException, DuplicateRecordException, RecordNotFoundException } from './SimpleDatabase.exceptions.ts'\n\nexport class SimpleDatabase<TModel extends WithIdentifier> implements Database<TModel, Promise<void>, Promise<TModel[]>> {\n private readonly datasource = new Map<string, TModel[]>()\n private simulateOffline = false\n\n async query(\n tableName: string,\n specification: CompositeSpecification<TModel>,\n ): Promise<TModel[]> {\n if (this.simulateOffline)\n throw new DatabaseOfflineException()\n\n const tableRecords = (this.datasource.get(tableName) || [])\n return tableRecords\n .filter((record: TModel) => specification.isSatisfiedBy(record))\n }\n\n async execute(\n tableName: string,\n statement: CreateStatement<TModel> | PutStatement<TModel> | PatchStatement<TModel> | DeleteStatement,\n ): Promise<void> {\n if (this.simulateOffline)\n throw new DatabaseOfflineException()\n\n if (!this.datasource.has(tableName))\n this.datasource.set(tableName, [])\n const table = this.datasource.get(tableName)!\n\n switch (statement.operation) {\n case Operation.CREATE: {\n const isDuplicate = table.some(item => item.id === statement.payload.id)\n if (isDuplicate)\n throw new DuplicateRecordException(statement.payload.id)\n table.push(statement.payload)\n break\n }\n case Operation.PUT:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table[index] = statement.payload\n break\n }\n case Operation.PATCH:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table[index] = { ...table[index], ...statement.payload }\n break\n }\n case Operation.DELETE:{\n const index = table.findIndex(item => item.id === statement.payload.id)\n if (index === -1)\n throw new RecordNotFoundException(statement.payload.id)\n table.splice(index, 1)\n break\n }\n }\n }\n\n goOffline(): void {\n this.simulateOffline = true\n }\n}\n","import type { EventHandler } from '@core/EventHandler.ts'\nimport type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\nimport type { EventConsumer, EventProducer } from '../EventBus.ts'\n\nexport class SimpleEventBus<TEvent extends DomainEvent | IntegrationEvent | ExternalEvent>\nimplements EventConsumer<TEvent>, EventProducer<TEvent> {\n private handlers = new Map<string, EventHandler<TEvent>[]>()\n\n subscribe(\n stream: string,\n aHandler: EventHandler<TEvent>,\n ): void {\n const handlersForType = this.handlers.get(stream) ?? []\n handlersForType.push(aHandler)\n this.handlers.set(stream, handlersForType)\n }\n\n async consume(stream: string, anEvent: TEvent): Promise<void> {\n if (!this.handlers.has(stream))\n return\n const handlers = this.handlers.get(stream) as EventHandler<TEvent>[]\n await Promise.all(handlers.map(async (handler) => {\n return handler.handle(anEvent)\n }))\n }\n\n async publish(stream: string, anEvent: TEvent): Promise<void> {\n await this.consume(stream, anEvent)\n }\n}\n","import type { IntegrationEvent, IntegrationEventMetadata } from '../IntegrationEvent.ts'\nimport { randomUUID } from 'node:crypto'\n\nexport function createIntegrationEvent<TPayload = unknown>(type: string, payload: TPayload, metadata?: Partial<IntegrationEventMetadata>): IntegrationEvent<TPayload> {\n return Object.freeze({\n id: randomUUID(),\n type,\n payload,\n timestamp: new Date().toISOString(),\n metadata: {\n ...metadata,\n },\n kind: 'integration',\n })\n}\n","import type { IntegrationEvent } from '../IntegrationEvent.ts'\nimport { isEvent } from '@domain/utils/isEvent.ts'\n\nexport function isIntegrationEvent<TPayload>(event: unknown): event is IntegrationEvent<TPayload> {\n return isEvent(event)\n && event.kind === 'integration'\n}\n","import type { StreamKey } from '@utils/streamKey/StreamKey.ts'\n\nexport function makeStreamKey(streamName: string, aggregateId: string): StreamKey {\n return `${streamName}#${aggregateId}`\n}\n","export function isEqual<T>(a: T, b: T): boolean {\n if (a === b) {\n return true\n }\n\n // eslint-disable-next-line ts/strict-boolean-expressions\n const bothAreObjects = a && b && typeof a === 'object' && typeof b === 'object'\n\n return Boolean(\n bothAreObjects\n && Object.keys(a).length === Object.keys(b).length\n && Object.entries(a).every(([k, v]) => isEqual(v, b[k as keyof T])),\n )\n}\n","export function parseAsError(value: unknown): Error {\n if (value instanceof Error)\n return value\n if (typeof value === 'string')\n return new Error(value)\n try {\n const json = JSON.stringify(value)\n return new Error(json ?? String(value))\n }\n catch {\n return new Error('Unknown error')\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { StoredEvent } from '../StoredEvent.ts'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\nimport { makeStreamKey } from '@utils/index.ts'\n\nexport function createStoredEvent<TEvent extends DomainEvent>(\n streamName: string,\n version: number,\n event: TEvent,\n): StoredEvent<TEvent> {\n return Object.freeze({\n id: event.id,\n streamKey: makeStreamKey(streamName, event.aggregateId),\n version,\n timestamp: getTimestamp(),\n event,\n })\n}\n","export class MultipleAggregatesException extends Error {\n constructor() {\n super('EventStore append does not support multiple aggregates to be stored')\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Database } from '@infrastructure/Database/Database.ts'\nimport type { EventStore } from '@infrastructure/EventStore/EventStore.ts'\nimport type { Outbox } from '@infrastructure/Outbox/Outbox.ts'\nimport type { StreamKey } from '@utils/streamKey/StreamKey.ts'\nimport type { StoredEvent } from '../StoredEvent.ts'\nimport { FieldEquals } from '@domain/Specification/implementations/FieldEquals.specification.ts'\nimport { Operation } from '@infrastructure/Database/Database.ts'\nimport { makeStreamKey } from '@utils/streamKey/makeStreamKey.ts'\nimport { createStoredEvent } from '../utils/createStoredEvent.ts'\nimport { MultipleAggregatesException } from './SimpleEventStore.exceptions.ts'\n\nexport class SimpleEventStore<TEvent extends DomainEvent> implements EventStore<TEvent, Promise<void>, Promise<TEvent[]>> {\n private readonly tableName: string = 'event_store'\n\n constructor(\n private readonly database: Database<StoredEvent<TEvent>, Promise<void>, Promise<StoredEvent<TEvent>[]>>,\n private readonly outbox?: Outbox,\n ) { }\n\n async load(streamName: string, aggregateId: string): Promise<TEvent[]> {\n const streamKey: StreamKey = makeStreamKey(streamName, aggregateId)\n const specification = new FieldEquals('streamKey', streamKey)\n const storedEvents = await this.database.query(this.tableName, specification)\n return storedEvents.map(storedEvent => storedEvent.event)\n }\n\n async append(streamName: string, events: TEvent[]): Promise<void> {\n const uniqueAggregateIds = new Set(events.map(event => event.aggregateId))\n if (uniqueAggregateIds.size > 1)\n throw new MultipleAggregatesException()\n\n const event = events[0]\n const currentStream = await this.load(streamName, event.aggregateId)\n const eventsToStore = events\n .map(event => createStoredEvent(streamName, currentStream.length + 1, event))\n await Promise.all(\n eventsToStore.map(async payload => this.database.execute(this.tableName, { operation: Operation.CREATE, payload }),\n ),\n )\n await Promise.all(events.map(async event => this.outbox?.enqueue(event)))\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { EventProducer } from '@infrastructure/EventBus/EventBus.js'\nimport type { ExternalEvent } from '@infrastructure/EventBus/ExternalEvent.ts'\nimport type { IntegrationEvent } from '@infrastructure/EventBus/IntegrationEvent.ts'\nimport type { OutboxWorker } from '@infrastructure/Outbox/OutboxWorker.ts'\nimport type { Outbox } from '../Outbox.ts'\n\nexport class GenericOutboxWorker implements OutboxWorker {\n constructor(\n protected outbox: Outbox,\n protected eventBus: EventProducer<DomainEvent | IntegrationEvent | ExternalEvent>,\n protected stream: string,\n ) {}\n\n async runOnce(): Promise<void> {\n const pending = await this.outbox.getPending()\n\n await Promise.all(pending.map(async (entry) => {\n try {\n await this.eventBus.publish(this.stream, entry.event)\n await this.outbox.markAsPublished(entry.id)\n }\n catch {\n await this.outbox.markAsFailed(entry.id)\n }\n }))\n }\n\n async tick(): Promise<void> {\n await this.runOnce()\n }\n\n start(intervalMs: number): void {\n setInterval(() => {\n void this.tick().catch(console.error)\n }, intervalMs)\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Outbox } from '../Outbox.ts'\nimport type { OutboxEntry } from '../OutboxEntry.ts'\nimport { getTimestamp } from '@core/utils/getTimestamp.ts'\n\nexport class InMemoryOutbox implements Outbox {\n protected entries: OutboxEntry[] = []\n protected idCounter = 0\n\n async enqueue(event: DomainEvent<unknown>): Promise<void> {\n this.entries.push({\n id: (this.idCounter++).toString(),\n event,\n published: false,\n retryCount: 0,\n })\n }\n\n async getPending(limit = 100): Promise<OutboxEntry[]> {\n return this.entries.filter(e => !e.published).slice(0, limit)\n }\n\n async markAsPublished(id: string): Promise<void> {\n const entry = this.entries.find(e => e.id === id)\n if (entry) {\n entry.published = true\n }\n }\n\n async markAsFailed(id: string): Promise<void> {\n const entry = this.entries.find(e => e.id === id)\n if (entry) {\n entry.retryCount += 1\n entry.lastAttemptAt = getTimestamp()\n }\n }\n}\n","import type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { OutboxEntry } from '../OutboxEntry.ts'\nimport { randomUUID } from 'node:crypto'\n\nexport function createOutboxEntry(\n event: DomainEvent<unknown>,\n): OutboxEntry {\n return Object.freeze({\n id: randomUUID(),\n event,\n published: false,\n retryCount: 0,\n lastAttemptAt: undefined,\n })\n}\n","import type { Query } from '@core/Query.ts'\nimport type { QueryHandler } from '@core/QueryHandler.ts'\nimport type { QueryBus } from '../QueryBus.ts'\n\nexport class SimpleQueryBus<TQuery extends Query, TProjection> implements QueryBus<TQuery, Promise<TProjection>> {\n private handlers: Map<TQuery['type'], QueryHandler<TQuery, Promise<TProjection>>> = new Map()\n\n register(\n aTypeOfQuery: TQuery['type'],\n anHandler: QueryHandler<TQuery, Promise<TProjection>>,\n ): void {\n if (this.handlers.has(aTypeOfQuery)) {\n throw new Error(`Handler already registered for query type: ${aTypeOfQuery}`)\n }\n this.handlers.set(aTypeOfQuery, anHandler)\n }\n\n async execute(aQuery: TQuery): Promise<TProjection> {\n const handler = this.handlers.get(aQuery.type)\n if (!handler) {\n throw new Error(`No handler found for query type: ${aQuery.type}`)\n }\n return handler.execute(aQuery)\n }\n}\n","import type { Decider } from '@domain/Decider.ts'\nimport type { DomainEvent } from '@domain/DomainEvent.ts'\nimport type { Rejection } from '@domain/Rejection.ts'\nimport type { Repository } from '@domain/Repository.ts'\nimport type { EventStore } from '@infrastructure/EventStore/EventStore.ts'\n\nexport class SimpleRepository<TState, TCommand, TEvent extends DomainEvent, TRejection extends Rejection> implements Repository<TEvent, Promise<TState>, Promise<void>> {\n constructor(\n private readonly eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>,\n readonly streamName: string,\n private readonly evolveFn: Decider<TState, TCommand, TEvent, TRejection>['evolve'],\n private readonly initialState: Decider<TState, TCommand, TEvent, TRejection>['initialState'],\n ) {\n }\n\n async load(aggregateId: string): Promise<TState> {\n const pastEvents = await this.eventStore.load(this.streamName, aggregateId)\n return pastEvents\n .reduce<TState>(this.evolveFn, this.initialState(aggregateId))\n }\n\n async store(events: TEvent[]): Promise<void> {\n await Promise.all(\n events.map(\n async event => this.eventStore.append(\n this.streamName,\n [event],\n ),\n ),\n )\n }\n}\n"]}
@@ -216,12 +216,6 @@ interface AggregateRoot<TId, TProps extends object, TEvent extends DomainEvent>
216
216
  interface EventBasedAggregateRoot<TId, TProps extends object, TEvent extends DomainEvent> extends AggregateRoot<TId, TProps, TEvent>, EventBased<TEvent> {
217
217
  }
218
218
 
219
- interface Decider<TState, TCommand, TEvent extends DomainEvent> {
220
- decide(this: void, command: TCommand, currentState: TState): TEvent[];
221
- evolve(this: void, currentState: TState, event: TEvent): TState;
222
- initialState(this: void, id: string): TState;
223
- }
224
-
225
219
  /**
226
220
  * Rejection models a failed command decision. It is NOT part of the aggregate
227
221
  * event stream. Persist via an outbox/inbox if you need durability and emit an
@@ -232,6 +226,10 @@ interface RejectionMetadata extends BaseMetadata {
232
226
  interface Rejection<TDetails = unknown> {
233
227
  /** Unique id; derive from commandId if possible for dedupe. */
234
228
  id: string;
229
+ /** Rejection type, format e.g., "{commandType}Rejected", "{commandType}Failed". Example "CreateUserRejected" */
230
+ type: string;
231
+ /** Discriminator for the message intent. */
232
+ kind: 'rejection';
235
233
  /** Aggregate type when known (for correlation). */
236
234
  aggregateType?: string;
237
235
  /** Aggregate id when known (for correlation/partitioning). */
@@ -241,7 +239,7 @@ interface Rejection<TDetails = unknown> {
241
239
  /** The command type, e.g., "CreateOrder". */
242
240
  commandType: string;
243
241
  /** Short machine-readable code, e.g., "VERSION_CONFLICT", "VALIDATION_FAILED". */
244
- reasonCode: string;
242
+ reasonCode: string | 'VERSION_CONFLICT' | 'VALIDATION_FAILED';
245
243
  /** Human-readable summary (avoid PII if externalized). */
246
244
  reason?: string;
247
245
  /** Classification for routing/metrics. */
@@ -264,6 +262,12 @@ interface Rejection<TDetails = unknown> {
264
262
  metadata?: RejectionMetadata;
265
263
  }
266
264
 
265
+ interface Decider<TState, TCommand, TEvent extends DomainEvent, TRejection extends Rejection> {
266
+ decide(this: void, command: TCommand, currentState: TState): (TEvent | TRejection)[];
267
+ evolve(this: void, currentState: TState, event: TEvent): TState;
268
+ initialState(this: void, id: string): TState;
269
+ }
270
+
267
271
  interface Loadable$1<TReturnType> {
268
272
  load(aggregateId: string): TReturnType;
269
273
  }
@@ -340,9 +344,23 @@ declare function createQueryNode(type: 'not', field: undefined, value: QueryNode
340
344
 
341
345
  declare function createDomainEvent<TPayload = unknown>(type: string, aggregateId: string, aggregateType: string, payload: TPayload, metadata?: Partial<DomainEventMetadata>): DomainEvent<TPayload>;
342
346
 
347
+ declare function createRejection<TDetails = unknown>(rejectionSpecifics: {
348
+ commandId: Rejection['commandId'];
349
+ commandType: Rejection['commandType'];
350
+ reasonCode: Rejection['reasonCode'];
351
+ reason?: Rejection['reason'];
352
+ aggregateType?: Rejection['aggregateType'];
353
+ aggregateId?: Rejection['aggregateId'];
354
+ classification: Rejection['classification'];
355
+ retryable?: Rejection['retryable'];
356
+ validationErrors?: Rejection['validationErrors'];
357
+ type: 'Failed' | 'Rejected' | string;
358
+ details?: TDetails;
359
+ }, metadata?: Partial<RejectionMetadata>): Rejection<TDetails>;
360
+
343
361
  declare function isDomainEvent(event: unknown): event is DomainEvent;
344
362
 
345
- declare function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent;
363
+ declare function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent | Rejection;
346
364
 
347
365
  interface Registerable$1<TCommand extends Command, TResult = void> {
348
366
  register(aTypeOfCommand: TCommand['type'], anHandler: CommandHandler<TCommand>): TResult;
@@ -534,12 +552,12 @@ declare class SimpleQueryBus<TQuery extends Query, TProjection> implements Query
534
552
  execute(aQuery: TQuery): Promise<TProjection>;
535
553
  }
536
554
 
537
- declare class SimpleRepository<TState, TCommand, TEvent extends DomainEvent> implements Repository<TEvent, Promise<TState>, Promise<void>> {
555
+ declare class SimpleRepository<TState, TCommand, TEvent extends DomainEvent, TRejection extends Rejection> implements Repository<TEvent, Promise<TState>, Promise<void>> {
538
556
  private readonly eventStore;
539
557
  readonly streamName: string;
540
558
  private readonly evolveFn;
541
559
  private readonly initialState;
542
- constructor(eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>, streamName: string, evolveFn: Decider<TState, TCommand, TEvent>['evolve'], initialState: Decider<TState, TCommand, TEvent>['initialState']);
560
+ constructor(eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>, streamName: string, evolveFn: Decider<TState, TCommand, TEvent, TRejection>['evolve'], initialState: Decider<TState, TCommand, TEvent, TRejection>['initialState']);
543
561
  load(aggregateId: string): Promise<TState>;
544
562
  store(events: TEvent[]): Promise<void>;
545
563
  }
@@ -554,4 +572,4 @@ declare function parseAsError(value: unknown): Error;
554
572
 
555
573
  declare function makeStreamKey(streamName: string, aggregateId: string): StreamKey;
556
574
 
557
- export { type AggregateRoot, AndSpecification, type BaseMetadata, type Command, type CommandBus, type CommandHandler, type CommandMetadata, CompositeSpecification, type CreateStatement, type Database, type Decider, type DeleteStatement, type Directive, type DomainEvent, type DomainEventMetadata, type EventBasedAggregateRoot, type EventConsumer, type EventHandler, type EventProducer, type EventStore, FieldEquals, FieldGreaterThan, type FilledArray, GenericOutboxWorker, type ISODateTime, InMemoryOutbox, type IntegrationEvent, type IntegrationEventMetadata, type Maybe, type Module, NotSpecification, type Nullable, Operation, OrSpecification, type Outbox, type OutboxEntry, type OutboxWorker, type PatchStatement, type Primitive, type PutStatement, type Query, type QueryBus, type QueryHandler, type QueryMetadata, type QueryNode, type Rejection, type RejectionMetadata, type Repository, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, type Specification, type StoredEvent, type StreamKey, type UnixTimestampInSeconds, type WithIdentifier, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
575
+ export { type AggregateRoot, AndSpecification, type BaseMetadata, type Command, type CommandBus, type CommandHandler, type CommandMetadata, CompositeSpecification, type CreateStatement, type Database, type Decider, type DeleteStatement, type Directive, type DomainEvent, type DomainEventMetadata, type EventBasedAggregateRoot, type EventConsumer, type EventHandler, type EventProducer, type EventStore, FieldEquals, FieldGreaterThan, type FilledArray, GenericOutboxWorker, type ISODateTime, InMemoryOutbox, type IntegrationEvent, type IntegrationEventMetadata, type Maybe, type Module, NotSpecification, type Nullable, Operation, OrSpecification, type Outbox, type OutboxEntry, type OutboxWorker, type PatchStatement, type Primitive, type PutStatement, type Query, type QueryBus, type QueryHandler, type QueryMetadata, type QueryNode, type Rejection, type RejectionMetadata, type Repository, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, type Specification, type StoredEvent, type StreamKey, type UnixTimestampInSeconds, type WithIdentifier, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createRejection, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
@@ -216,12 +216,6 @@ interface AggregateRoot<TId, TProps extends object, TEvent extends DomainEvent>
216
216
  interface EventBasedAggregateRoot<TId, TProps extends object, TEvent extends DomainEvent> extends AggregateRoot<TId, TProps, TEvent>, EventBased<TEvent> {
217
217
  }
218
218
 
219
- interface Decider<TState, TCommand, TEvent extends DomainEvent> {
220
- decide(this: void, command: TCommand, currentState: TState): TEvent[];
221
- evolve(this: void, currentState: TState, event: TEvent): TState;
222
- initialState(this: void, id: string): TState;
223
- }
224
-
225
219
  /**
226
220
  * Rejection models a failed command decision. It is NOT part of the aggregate
227
221
  * event stream. Persist via an outbox/inbox if you need durability and emit an
@@ -232,6 +226,10 @@ interface RejectionMetadata extends BaseMetadata {
232
226
  interface Rejection<TDetails = unknown> {
233
227
  /** Unique id; derive from commandId if possible for dedupe. */
234
228
  id: string;
229
+ /** Rejection type, format e.g., "{commandType}Rejected", "{commandType}Failed". Example "CreateUserRejected" */
230
+ type: string;
231
+ /** Discriminator for the message intent. */
232
+ kind: 'rejection';
235
233
  /** Aggregate type when known (for correlation). */
236
234
  aggregateType?: string;
237
235
  /** Aggregate id when known (for correlation/partitioning). */
@@ -241,7 +239,7 @@ interface Rejection<TDetails = unknown> {
241
239
  /** The command type, e.g., "CreateOrder". */
242
240
  commandType: string;
243
241
  /** Short machine-readable code, e.g., "VERSION_CONFLICT", "VALIDATION_FAILED". */
244
- reasonCode: string;
242
+ reasonCode: string | 'VERSION_CONFLICT' | 'VALIDATION_FAILED';
245
243
  /** Human-readable summary (avoid PII if externalized). */
246
244
  reason?: string;
247
245
  /** Classification for routing/metrics. */
@@ -264,6 +262,12 @@ interface Rejection<TDetails = unknown> {
264
262
  metadata?: RejectionMetadata;
265
263
  }
266
264
 
265
+ interface Decider<TState, TCommand, TEvent extends DomainEvent, TRejection extends Rejection> {
266
+ decide(this: void, command: TCommand, currentState: TState): (TEvent | TRejection)[];
267
+ evolve(this: void, currentState: TState, event: TEvent): TState;
268
+ initialState(this: void, id: string): TState;
269
+ }
270
+
267
271
  interface Loadable$1<TReturnType> {
268
272
  load(aggregateId: string): TReturnType;
269
273
  }
@@ -340,9 +344,23 @@ declare function createQueryNode(type: 'not', field: undefined, value: QueryNode
340
344
 
341
345
  declare function createDomainEvent<TPayload = unknown>(type: string, aggregateId: string, aggregateType: string, payload: TPayload, metadata?: Partial<DomainEventMetadata>): DomainEvent<TPayload>;
342
346
 
347
+ declare function createRejection<TDetails = unknown>(rejectionSpecifics: {
348
+ commandId: Rejection['commandId'];
349
+ commandType: Rejection['commandType'];
350
+ reasonCode: Rejection['reasonCode'];
351
+ reason?: Rejection['reason'];
352
+ aggregateType?: Rejection['aggregateType'];
353
+ aggregateId?: Rejection['aggregateId'];
354
+ classification: Rejection['classification'];
355
+ retryable?: Rejection['retryable'];
356
+ validationErrors?: Rejection['validationErrors'];
357
+ type: 'Failed' | 'Rejected' | string;
358
+ details?: TDetails;
359
+ }, metadata?: Partial<RejectionMetadata>): Rejection<TDetails>;
360
+
343
361
  declare function isDomainEvent(event: unknown): event is DomainEvent;
344
362
 
345
- declare function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent;
363
+ declare function isEvent(event: unknown): event is DomainEvent | IntegrationEvent | ExternalEvent | Rejection;
346
364
 
347
365
  interface Registerable$1<TCommand extends Command, TResult = void> {
348
366
  register(aTypeOfCommand: TCommand['type'], anHandler: CommandHandler<TCommand>): TResult;
@@ -534,12 +552,12 @@ declare class SimpleQueryBus<TQuery extends Query, TProjection> implements Query
534
552
  execute(aQuery: TQuery): Promise<TProjection>;
535
553
  }
536
554
 
537
- declare class SimpleRepository<TState, TCommand, TEvent extends DomainEvent> implements Repository<TEvent, Promise<TState>, Promise<void>> {
555
+ declare class SimpleRepository<TState, TCommand, TEvent extends DomainEvent, TRejection extends Rejection> implements Repository<TEvent, Promise<TState>, Promise<void>> {
538
556
  private readonly eventStore;
539
557
  readonly streamName: string;
540
558
  private readonly evolveFn;
541
559
  private readonly initialState;
542
- constructor(eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>, streamName: string, evolveFn: Decider<TState, TCommand, TEvent>['evolve'], initialState: Decider<TState, TCommand, TEvent>['initialState']);
560
+ constructor(eventStore: EventStore<TEvent, Promise<void>, Promise<TEvent[]>>, streamName: string, evolveFn: Decider<TState, TCommand, TEvent, TRejection>['evolve'], initialState: Decider<TState, TCommand, TEvent, TRejection>['initialState']);
543
561
  load(aggregateId: string): Promise<TState>;
544
562
  store(events: TEvent[]): Promise<void>;
545
563
  }
@@ -554,4 +572,4 @@ declare function parseAsError(value: unknown): Error;
554
572
 
555
573
  declare function makeStreamKey(streamName: string, aggregateId: string): StreamKey;
556
574
 
557
- export { type AggregateRoot, AndSpecification, type BaseMetadata, type Command, type CommandBus, type CommandHandler, type CommandMetadata, CompositeSpecification, type CreateStatement, type Database, type Decider, type DeleteStatement, type Directive, type DomainEvent, type DomainEventMetadata, type EventBasedAggregateRoot, type EventConsumer, type EventHandler, type EventProducer, type EventStore, FieldEquals, FieldGreaterThan, type FilledArray, GenericOutboxWorker, type ISODateTime, InMemoryOutbox, type IntegrationEvent, type IntegrationEventMetadata, type Maybe, type Module, NotSpecification, type Nullable, Operation, OrSpecification, type Outbox, type OutboxEntry, type OutboxWorker, type PatchStatement, type Primitive, type PutStatement, type Query, type QueryBus, type QueryHandler, type QueryMetadata, type QueryNode, type Rejection, type RejectionMetadata, type Repository, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, type Specification, type StoredEvent, type StreamKey, type UnixTimestampInSeconds, type WithIdentifier, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
575
+ export { type AggregateRoot, AndSpecification, type BaseMetadata, type Command, type CommandBus, type CommandHandler, type CommandMetadata, CompositeSpecification, type CreateStatement, type Database, type Decider, type DeleteStatement, type Directive, type DomainEvent, type DomainEventMetadata, type EventBasedAggregateRoot, type EventConsumer, type EventHandler, type EventProducer, type EventStore, FieldEquals, FieldGreaterThan, type FilledArray, GenericOutboxWorker, type ISODateTime, InMemoryOutbox, type IntegrationEvent, type IntegrationEventMetadata, type Maybe, type Module, NotSpecification, type Nullable, Operation, OrSpecification, type Outbox, type OutboxEntry, type OutboxWorker, type PatchStatement, type Primitive, type PutStatement, type Query, type QueryBus, type QueryHandler, type QueryMetadata, type QueryNode, type Rejection, type RejectionMetadata, type Repository, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, type Specification, type StoredEvent, type StreamKey, type UnixTimestampInSeconds, type WithIdentifier, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createRejection, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
@@ -190,6 +190,25 @@ function createDomainEvent(type, aggregateId, aggregateType, payload, metadata =
190
190
  metadata
191
191
  });
192
192
  }
193
+ function createRejection(rejectionSpecifics, metadata = {}) {
194
+ return Object.freeze({
195
+ id: randomUUID(),
196
+ commandId: rejectionSpecifics.commandId,
197
+ commandType: rejectionSpecifics.commandType,
198
+ reasonCode: rejectionSpecifics.reasonCode,
199
+ reason: rejectionSpecifics.reason,
200
+ aggregateType: rejectionSpecifics.aggregateType,
201
+ aggregateId: rejectionSpecifics.aggregateId,
202
+ classification: rejectionSpecifics.classification,
203
+ retryable: rejectionSpecifics.retryable,
204
+ validationErrors: rejectionSpecifics.validationErrors,
205
+ type: `${rejectionSpecifics.commandType}${rejectionSpecifics.type}`,
206
+ details: rejectionSpecifics.details,
207
+ kind: "rejection",
208
+ timestamp: getTimestamp(),
209
+ metadata
210
+ });
211
+ }
193
212
 
194
213
  // src/domain/utils/isEvent.ts
195
214
  function isEvent(event) {
@@ -527,6 +546,6 @@ var SimpleRepository = class {
527
546
  }
528
547
  };
529
548
 
530
- export { AndSpecification, CompositeSpecification, FieldEquals, FieldGreaterThan, GenericOutboxWorker, InMemoryOutbox, NotSpecification, Operation, OrSpecification, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
549
+ export { AndSpecification, CompositeSpecification, FieldEquals, FieldGreaterThan, GenericOutboxWorker, InMemoryOutbox, NotSpecification, Operation, OrSpecification, SimpleCommandBus, SimpleDatabase, SimpleEventBus, SimpleEventStore, SimpleQueryBus, SimpleRepository, createCommand, createDomainEvent, createIntegrationEvent, createOutboxEntry, createQuery, createQueryNode, createRejection, createStoredEvent, fail, getTimestamp, invariant, isCommand, isDomainEvent, isEqual, isEvent, isIntegrationEvent, isQuery, makeStreamKey, parseAsError };
531
550
  //# sourceMappingURL=index.js.map
532
551
  //# sourceMappingURL=index.js.map