@ddd-ts-kit/kernel 0.99.0 → 0.100.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.
Files changed (47) hide show
  1. package/README.fr.md +59 -8
  2. package/README.md +57 -7
  3. package/dist/application/background/background-job-payload-schema.d.ts +14 -0
  4. package/dist/application/background/background-job-payload-schema.d.ts.map +1 -0
  5. package/dist/application/background/background-job-payload-schema.js +2 -0
  6. package/dist/application/background/background-job-payload-schema.js.map +1 -0
  7. package/dist/application/background/background-job-type.d.ts +5 -2
  8. package/dist/application/background/background-job-type.d.ts.map +1 -1
  9. package/dist/application/background/background-job.d.ts +3 -1
  10. package/dist/application/background/background-job.d.ts.map +1 -1
  11. package/dist/application/background/index.d.ts +1 -0
  12. package/dist/application/background/index.d.ts.map +1 -1
  13. package/dist/application/background/index.js +1 -0
  14. package/dist/application/background/index.js.map +1 -1
  15. package/dist/application/process/index.d.ts +1 -0
  16. package/dist/application/process/index.d.ts.map +1 -1
  17. package/dist/application/process/index.js +1 -0
  18. package/dist/application/process/index.js.map +1 -1
  19. package/dist/application/process/process-timeout-due-payload.d.ts +9 -0
  20. package/dist/application/process/process-timeout-due-payload.d.ts.map +1 -0
  21. package/dist/application/process/process-timeout-due-payload.js +25 -0
  22. package/dist/application/process/process-timeout-due-payload.js.map +1 -0
  23. package/dist/declarations/decorators/background.d.ts +9 -2
  24. package/dist/declarations/decorators/background.d.ts.map +1 -1
  25. package/dist/declarations/decorators/background.js +14 -2
  26. package/dist/declarations/decorators/background.js.map +1 -1
  27. package/dist/declarations/dependencies/class-declarator.d.ts +2 -2
  28. package/dist/declarations/dependencies/class-declarator.d.ts.map +1 -1
  29. package/dist/declarations/model/background-job-declaration.d.ts +3 -0
  30. package/dist/declarations/model/background-job-declaration.d.ts.map +1 -1
  31. package/dist/testing/recorded-messages.d.ts +17 -0
  32. package/dist/testing/recorded-messages.d.ts.map +1 -0
  33. package/dist/testing/recorded-messages.js +29 -0
  34. package/dist/testing/recorded-messages.js.map +1 -0
  35. package/dist/testing/recording-command-bus.d.ts +30 -0
  36. package/dist/testing/recording-command-bus.d.ts.map +1 -0
  37. package/dist/testing/recording-command-bus.js +35 -0
  38. package/dist/testing/recording-command-bus.js.map +1 -0
  39. package/dist/testing/recording-query-bus.d.ts +26 -0
  40. package/dist/testing/recording-query-bus.d.ts.map +1 -0
  41. package/dist/testing/recording-query-bus.js +31 -0
  42. package/dist/testing/recording-query-bus.js.map +1 -0
  43. package/dist/testing.d.ts +3 -0
  44. package/dist/testing.d.ts.map +1 -0
  45. package/dist/testing.js +3 -0
  46. package/dist/testing.js.map +1 -0
  47. package/package.json +5 -1
package/README.fr.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [English](README.md) · **Français**
2
- <!-- translation-of: README.md sha256:1a8e41caf665b63c -->
2
+ <!-- translation-of: README.md sha256:d2ada085467f288d -->
3
3
 
4
4
  # @ddd-ts-kit/kernel
5
5
 
@@ -12,9 +12,10 @@ politiques.
12
12
  npm i @ddd-ts-kit/kernel
13
13
  ```
14
14
 
15
- Deux points d'entrée : `@ddd-ts-kit/kernel` (les blocs de base, les ports, les interfaces
16
- standard et leurs doubles) et `@ddd-ts-kit/kernel/declarations` (les décorateurs par lesquels une
17
- classe dit ce qu'elle est, voir « Déclarations »).
15
+ Trois points d'entrée : `@ddd-ts-kit/kernel` (les blocs de base, les ports, les interfaces
16
+ standard et leurs doubles), `@ddd-ts-kit/kernel/declarations` (les décorateurs par lesquels une
17
+ classe dit ce qu'elle est, voir « Déclarations ») et `@ddd-ts-kit/kernel/testing` (les bus
18
+ enregistreurs d'une *spec*, voir « La *spec* d'une réaction »).
18
19
 
19
20
  ![Le domaine et l'application d'un contexte délimité importent le noyau ; le noyau déclare les ports sous forme de classes abstraites ; ses propres doubles, les packages d'adaptateurs du kit et l'infrastructure du contexte les implémentent ; la plateforme lie une implémentation à chaque port au démarrage](https://raw.githubusercontent.com/gbourgeat/ddd-ts-kit/main/docs/assets/diagrams/kernel-ports-and-implementations.fr.svg)
20
21
 
@@ -40,7 +41,7 @@ avec une bibliothèque.
40
41
  | Acteur | `Actor`, `AuthorizedCommand`, `AuthorizedQuery`, `ActorContext`, `systemActor` |
41
42
  | Interfaces standard | `Session`, `ExecutionContext` et `ExecutionScope`, `Logger`, `Metrics`, `ErrorReporter`, `Cache`, `CacheInvalidation` et `CachePurger` (avec `cacheTag`, `tenantCacheTags`, `CachePurgeRequest`, `PublishedCacheInvalidation`, `PurgingPublisher`, `RepeatedCachePurger` : voir « Purger les caches HTTP »), `Lock`, `RateLimiter`, `Page` et `PageRequest`, `AuditStamp`, `TenantScoped`, `AuditTrail`, `AuditReader` et `AuditEntry` |
42
43
  | *Jobs* planifiés | `JobScheduler`, `ScheduledJob`, `JobExecution`, `JobSchedule`, `JobOptions`, `JobDefinition`, `JobRun`, `JobDescription`, `parseJobSchedule`, `describeJobSchedule`, `jobPolicy`, `executionContextOfJob` |
43
- | *Jobs* en arrière-plan | `JobQueue`, `BackgroundJob`, `BackgroundJobExecution`, `EnqueueOptions`, `QueuedJob`, `QueuedJobStatus`, `backgroundJobPolicy`, `retryDelayMs`, `executionContextOfBackgroundJob`, `whenCommitted` (voir « JobQueue ») |
44
+ | *Jobs* en arrière-plan | `JobQueue`, `BackgroundJob`, `BackgroundJobExecution`, `BackgroundJobPayloadSchema`, `processTimeoutDuePayload`, `EnqueueOptions`, `QueuedJob`, `QueuedJobStatus`, `backgroundJobPolicy`, `retryDelayMs`, `executionContextOfBackgroundJob`, `whenCommitted` (voir « JobQueue ») |
44
45
  | Gestionnaires de processus | `ProcessManager`, `ProcessDecision`, `ProcessRunner`, `ProcessStore`, `InMemoryProcessStore`, `UnreadableProcessStateError` (voir « ProcessRunner et ProcessStore ») |
45
46
  | Fichiers | `FileStorage`, `StoredFile`, `FileScanner`, `FileKeys`, `TenantFileKeys`, `FileStaging`, `FileUpload`, `fileUploadsMiddleware`, `FileInspection`, `FileError`, `InMemoryFileStorage`, `LocalFileStorage`, `PurgeStagedFiles` (voir « FileStorage, StoredFile, FileScanner ») |
46
47
  | Multitenance | `tenantScopeOf`, `tenantReachOf`, `acrossTenants`, `tenantKey`, `tenantCacheKey`, `isTenantId`, `TenantDirectory`, `InMemoryTenantDirectory` (voir « Multitenance ») |
@@ -50,6 +51,7 @@ avec une bibliothèque.
50
51
  | Aides à la persistance | `optimisticUpdate`, `expectVersion` (la version qu'un appelant a lue, `If-Match` en HTTP, est toujours la version courante, sinon `PreconditionFailedError` : 412), `schemaNameOf`, `stampCreation`, `stampUpdate`, `tenantScopeOf`, `encodeCursor`, `decodeCursor` |
51
52
  | Remontée des erreurs | `ErrorReporter`, `ErrorReport`, `errorReportOf`, `reportOnce`, `isUnexpectedError`, `errorReportingMiddleware`, `DeadLetterReports`, `reportProcessFailures`, `NoopErrorReporter` |
52
53
  | Doubles | `FixedClock`, `SequentialIdGenerator`, `InMemoryUnitOfWork`, `FixedActorContext`, `FixedExecutionScope`, `InMemoryLogger`, `InMemoryMetrics`, `InMemoryErrorReporter`, `InMemoryCache`, `InMemoryCacheInvalidation`, `InMemoryCachePurger`, `InMemoryLock`, `InMemoryRateLimiter` |
54
+ | Tests (`@ddd-ts-kit/kernel/testing`) | `RecordingCommandBus`, `RecordingQueryBus` : des bus qui gardent chaque message qu'on leur confie, dans l'ordre (`executed`), et répondent ce que la *spec* leur a dit (`answering(type, answer)`), rien sinon (voir « La *spec* d'une réaction ») |
53
55
  | Déclarations (`@ddd-ts-kit/kernel/declarations`) | `Requires`, `Public`, `CommandHandler`, `QueryHandler`, `IntegrationEventHandler`, `DomainEventHandler`, `Scheduled`, `Background`, `Projection`, `On`, `applyingProjection`, `Repository`, `Gateway`, `Adapter`, `Policy`, `Edge` (pour les décorateurs d'un *package* de transport, comme `@Controller`), `injected`, `injectedDependencies`, `declarationOf`, `listDeclarations`, `DeclarationError`, `Token`, `describeToken`, `tokenIdentity`, `portDefect` |
54
56
 
55
57
  Les règles que servent ces blocs sont dans `docs/ARCHITECTURE.md`.
@@ -595,6 +597,48 @@ l'unité de travail est terminée. Il envoie une commande par le `CommandBus`, q
595
597
  unité de travail. `unitOfWorkStage()` répond `'outside'`, `'open'`, `'before-commit'` ou
596
598
  `'after-commit'`.
597
599
 
600
+ ### La *spec* d'une réaction
601
+
602
+ Qu'un gestionnaire `before-commit` s'exécute dans la transaction et qu'un gestionnaire
603
+ `after-commit` s'exécute une fois celle-ci validée est une garantie du noyau, prouvée une fois
604
+ par sa propre suite : la *spec* d'une réaction ne la prouve pas de nouveau. Elle donne le fait à
605
+ la réaction et vérifie ce que la réaction a envoyé. Un gestionnaire d'événement de domaine, un
606
+ gestionnaire d'événement d'intégration et un contrôleur envoient des commandes par le
607
+ `CommandBus` qu'ils reçoivent : `RecordingCommandBus` de `@ddd-ts-kit/kernel/testing` garde
608
+ chacune de celles qu'on lui confie, dans l'ordre, dans `executed`, et répond ce que la *spec* lui
609
+ a dit avec `answering(type, answer)` (un identifiant, ou un refus que la fonction lève), pour les
610
+ commandes de `type` et de ses sous-classes, rien sinon. Aucun gestionnaire ne s'exécute : ce que fait la commande est la *spec* de son propre
611
+ gestionnaire. `RecordingQueryBus` fait de même pour les requêtes. Les *specs* que
612
+ `ddd-ts-kit generate` écrit pour ces rôles partent de là :
613
+
614
+ <!-- checked sample -->
615
+ ```ts
616
+ import { Command, type CommandBus, type DomainEvent } from '@ddd-ts-kit/kernel';
617
+ import { RecordingCommandBus } from '@ddd-ts-kit/kernel/testing';
618
+
619
+ class ScheduleReminderCommand extends Command {
620
+ constructor(readonly invoiceId: string) {
621
+ super();
622
+ }
623
+ }
624
+
625
+ /** Quand une facture est émise, un rappel est planifié pour elle. */
626
+ class InvoiceIssuedEventHandler {
627
+ constructor(private readonly commands: CommandBus) {}
628
+
629
+ async handle(event: DomainEvent): Promise<void> {
630
+ await this.commands.execute(new ScheduleReminderCommand(event.aggregateId));
631
+ }
632
+ }
633
+
634
+ const issued: DomainEvent = { name: 'billing.invoice.issued', aggregateId: 'invoice-1', occurredAt: new Date(0) };
635
+ const commands = new RecordingCommandBus();
636
+
637
+ await new InvoiceIssuedEventHandler(commands).handle(issued);
638
+
639
+ export const sent = commands.executed; // [new ScheduleReminderCommand('invoice-1')]
640
+ ```
641
+
598
642
  ### Une unité de travail à vous
599
643
 
600
644
  La file vit dans une portée `AsyncLocalStorage` ouverte par `withinUnitOfWork(work, transaction)`.
@@ -1041,6 +1085,9 @@ comment tester un *job* sont dans le README de `@ddd-ts-kit/scheduling`.
1041
1085
  export class CompileStatementsBackgroundJob implements BackgroundJob<CompileStatementsPayload> {
1042
1086
  static readonly jobName = 'billing.compile-statements';
1043
1087
 
1088
+ // le schéma de sa charge utile, `zodSchema(z.object({ month: z.string() }))` ou toute bibliothèque de validation
1089
+ static readonly payload = compileStatementsPayload;
1090
+
1044
1091
  constructor(private readonly commands: CommandBus) {}
1045
1092
 
1046
1093
  async run(payload: CompileStatementsPayload, execution: BackgroundJobExecution): Promise<void> {
@@ -1051,10 +1098,14 @@ export class CompileStatementsBackgroundJob implements BackgroundJob<CompileStat
1051
1098
 
1052
1099
  Un *job* en arrière-plan est nommé par son `jobName` statique, par lequel un cas d'usage le met
1053
1100
  en file (`jobs.enqueue(CompileStatementsBackgroundJob, { month })`, la charge utile typée par
1054
- `run`). Le décorateur prend les options, toutes facultatives : `maxAttempts` (5), `backoff`
1101
+ `run`). Son `payload` statique est le schéma de cette charge utile, un `BackgroundJobPayloadSchema`
1102
+ (`parse(input)` qui répond un `Result`, ce qu'est le `Schema` de `@ddd-ts-kit/validation`, quelle
1103
+ que soit la bibliothèque qu'il adapte) : le *worker* lit la charge utile stockée avec lui avant
1104
+ chaque exécution et n'en exécute jamais une qu'il refuse (`INVALID_JOB_PAYLOAD`) ; le *job* des
1105
+ délais d'un processus utilise `processTimeoutDuePayload`. Le décorateur prend les options, toutes facultatives : `maxAttempts` (5), `backoff`
1055
1106
  (`{ baseMs: 1000, factor: 2, maxMs: 300000 }`), `timeout` et `lease` (30 s), en millisecondes
1056
- ou `'10m'`. Un nom qui n'est pas `<context>.<job-name>` et des options illisibles lèvent une
1057
- `DeclarationError` au chargement du fichier. `BackgroundJobExecution` est ce que reçoit `run` :
1107
+ ou `'10m'`. Un nom qui n'est pas `<context>.<job-name>`, une classe sans `payload` statique et des options
1108
+ illisibles lèvent une `DeclarationError` au chargement du fichier. `BackgroundJobExecution` est ce que reçoit `run` :
1058
1109
  `jobId`, `attempt`, `enqueuedAt`, `startedAt`, le `checkpoint` qu'une tentative précédente a
1059
1110
  enregistré, un `signal` d'interruption, `saveCheckpoint(value)` et
1060
1111
  `reportProgress({ done, total })`.
package/README.md CHANGED
@@ -10,9 +10,10 @@ logger, no dependency at all. It is the only package of the kit `domain/` may im
10
10
  npm i @ddd-ts-kit/kernel
11
11
  ```
12
12
 
13
- Two entries: `@ddd-ts-kit/kernel` (the building blocks, the ports, the standard interfaces and
14
- their doubles) and `@ddd-ts-kit/kernel/declarations` (the decorators with which a class says
15
- what it is, see "Declarations").
13
+ Three entries: `@ddd-ts-kit/kernel` (the building blocks, the ports, the standard interfaces and
14
+ their doubles), `@ddd-ts-kit/kernel/declarations` (the decorators with which a class says
15
+ what it is, see "Declarations") and `@ddd-ts-kit/kernel/testing` (the recording buses of a
16
+ spec, see "The spec of a reaction").
16
17
 
17
18
  ![The domain and the application of a bounded context import the kernel; the kernel declares the ports as abstract classes; its own doubles, the adapter packages of the kit and the infrastructure of the context implement them; the platform binds one implementation to each port at start-up](https://raw.githubusercontent.com/gbourgeat/ddd-ts-kit/main/docs/assets/diagrams/kernel-ports-and-implementations.svg)
18
19
 
@@ -37,7 +38,7 @@ starts, so a business rule never changes with a library.
37
38
  | Actor | `Actor`, `AuthorizedCommand`, `AuthorizedQuery`, `ActorContext`, `systemActor` |
38
39
  | Standard interfaces | `Session`, `ExecutionContext` and `ExecutionScope`, `Logger`, `Metrics`, `ErrorReporter`, `Cache`, `CacheInvalidation` and `CachePurger` (with `cacheTag`, `tenantCacheTags`, `CachePurgeRequest`, `PublishedCacheInvalidation`, `PurgingPublisher`, `RepeatedCachePurger`: see "Purging the HTTP caches"), `Lock`, `RateLimiter`, `Page` and `PageRequest`, `AuditStamp`, `TenantScoped`, `AuditTrail`, `AuditReader` and `AuditEntry` |
39
40
  | Scheduled jobs | `JobScheduler`, `ScheduledJob`, `JobExecution`, `JobSchedule`, `JobOptions`, `JobDefinition`, `JobRun`, `JobDescription`, `parseJobSchedule`, `describeJobSchedule`, `jobPolicy`, `executionContextOfJob` |
40
- | Background jobs | `JobQueue`, `BackgroundJob`, `BackgroundJobExecution`, `EnqueueOptions`, `QueuedJob`, `QueuedJobStatus`, `backgroundJobPolicy`, `retryDelayMs`, `executionContextOfBackgroundJob`, `whenCommitted` (see "JobQueue") |
41
+ | Background jobs | `JobQueue`, `BackgroundJob`, `BackgroundJobExecution`, `BackgroundJobPayloadSchema`, `processTimeoutDuePayload`, `EnqueueOptions`, `QueuedJob`, `QueuedJobStatus`, `backgroundJobPolicy`, `retryDelayMs`, `executionContextOfBackgroundJob`, `whenCommitted` (see "JobQueue") |
41
42
  | Process managers | `ProcessManager`, `ProcessDecision`, `ProcessRunner`, `ProcessStore`, `InMemoryProcessStore`, `UnreadableProcessStateError` (see "ProcessRunner and ProcessStore") |
42
43
  | Files | `FileStorage`, `StoredFile`, `FileScanner`, `FileKeys`, `TenantFileKeys`, `FileStaging`, `FileUpload`, `fileUploadsMiddleware`, `FileInspection`, `FileError`, `InMemoryFileStorage`, `LocalFileStorage`, `PurgeStagedFiles` (see "FileStorage, StoredFile, FileScanner") |
43
44
  | Tenancy | `tenantScopeOf`, `tenantReachOf`, `acrossTenants`, `tenantKey`, `tenantCacheKey`, `isTenantId`, `TenantDirectory`, `InMemoryTenantDirectory` (see "Tenancy") |
@@ -47,6 +48,7 @@ starts, so a business rule never changes with a library.
47
48
  | Persistence helpers | `optimisticUpdate`, `expectVersion` (the version a caller read, `If-Match` over HTTP, still the current one, else `PreconditionFailedError`: 412), `schemaNameOf`, `stampCreation`, `stampUpdate`, `tenantScopeOf`, `encodeCursor`, `decodeCursor` |
48
49
  | Error reporting | `ErrorReporter`, `ErrorReport`, `errorReportOf`, `reportOnce`, `isUnexpectedError`, `errorReportingMiddleware`, `DeadLetterReports`, `reportProcessFailures`, `NoopErrorReporter` |
49
50
  | Doubles | `FixedClock`, `SequentialIdGenerator`, `InMemoryUnitOfWork`, `FixedActorContext`, `FixedExecutionScope`, `InMemoryLogger`, `InMemoryMetrics`, `InMemoryErrorReporter`, `InMemoryCache`, `InMemoryCacheInvalidation`, `InMemoryCachePurger`, `InMemoryLock`, `InMemoryRateLimiter` |
51
+ | Testing (`@ddd-ts-kit/kernel/testing`) | `RecordingCommandBus`, `RecordingQueryBus`: buses that keep every message they are handed, in order (`executed`), and answer what the spec told them (`answering(type, answer)`), nothing otherwise (see "The spec of a reaction") |
50
52
  | Declarations (`@ddd-ts-kit/kernel/declarations`) | `Requires`, `Public`, `CommandHandler`, `QueryHandler`, `IntegrationEventHandler`, `DomainEventHandler`, `Scheduled`, `Background`, `Projection`, `On`, `applyingProjection`, `Repository`, `Gateway`, `Adapter`, `Policy`, `Edge` (for the decorators of a transport package, such as `@Controller`), `injected`, `injectedDependencies`, `declarationOf`, `listDeclarations`, `DeclarationError`, `Token`, `describeToken`, `tokenIdentity`, `portDefect` |
51
53
 
52
54
  The rules these blocks serve are in `docs/ARCHITECTURE.md`.
@@ -581,6 +583,47 @@ An `after-commit` handler that hands an aggregate to a wrapped repository (`save
581
583
  is over. It sends a command through the `CommandBus`, which opens a unit of work of its own.
582
584
  `unitOfWorkStage()` answers `'outside'`, `'open'`, `'before-commit'` or `'after-commit'`.
583
585
 
586
+ ### The spec of a reaction
587
+
588
+ That a `before-commit` handler runs inside the transaction and an `after-commit` one once it has
589
+ committed is a guarantee of the kernel, proven once by its own suite: the spec of a reaction
590
+ does not prove it again. It gives the reaction the fact and asserts what the reaction sent. An
591
+ event handler, an integration event handler and a controller send commands through the
592
+ `CommandBus` they receive: `RecordingCommandBus` of `@ddd-ts-kit/kernel/testing` keeps each one
593
+ it is handed, in order, in `executed`, and answers what the spec told it with
594
+ `answering(type, answer)` (an identifier, or a refusal the function throws), for the commands of
595
+ `type` and of its subclasses, nothing otherwise.
596
+ No handler runs: what the command does is the spec of its own handler. `RecordingQueryBus` does
597
+ the same for queries. The specs `ddd-ts-kit generate` writes for these roles start from them:
598
+
599
+ <!-- checked sample -->
600
+ ```ts
601
+ import { Command, type CommandBus, type DomainEvent } from '@ddd-ts-kit/kernel';
602
+ import { RecordingCommandBus } from '@ddd-ts-kit/kernel/testing';
603
+
604
+ class ScheduleReminderCommand extends Command {
605
+ constructor(readonly invoiceId: string) {
606
+ super();
607
+ }
608
+ }
609
+
610
+ /** When an invoice is issued, a reminder is scheduled for it. */
611
+ class InvoiceIssuedEventHandler {
612
+ constructor(private readonly commands: CommandBus) {}
613
+
614
+ async handle(event: DomainEvent): Promise<void> {
615
+ await this.commands.execute(new ScheduleReminderCommand(event.aggregateId));
616
+ }
617
+ }
618
+
619
+ const issued: DomainEvent = { name: 'billing.invoice.issued', aggregateId: 'invoice-1', occurredAt: new Date(0) };
620
+ const commands = new RecordingCommandBus();
621
+
622
+ await new InvoiceIssuedEventHandler(commands).handle(issued);
623
+
624
+ export const sent = commands.executed; // [new ScheduleReminderCommand('invoice-1')]
625
+ ```
626
+
584
627
  ### A unit of work of your own
585
628
 
586
629
  The queue lives in an `AsyncLocalStorage` scope opened by `withinUnitOfWork(work, transaction)`.
@@ -1008,6 +1051,9 @@ are in the README of `@ddd-ts-kit/scheduling`.
1008
1051
  export class CompileStatementsBackgroundJob implements BackgroundJob<CompileStatementsPayload> {
1009
1052
  static readonly jobName = 'billing.compile-statements';
1010
1053
 
1054
+ // the schema of its payload, `zodSchema(z.object({ month: z.string() }))` or any validation library
1055
+ static readonly payload = compileStatementsPayload;
1056
+
1011
1057
  constructor(private readonly commands: CommandBus) {}
1012
1058
 
1013
1059
  async run(payload: CompileStatementsPayload, execution: BackgroundJobExecution): Promise<void> {
@@ -1017,11 +1063,15 @@ export class CompileStatementsBackgroundJob implements BackgroundJob<CompileStat
1017
1063
  ```
1018
1064
 
1019
1065
  A background job is named by its static `jobName`, which is how a use case enqueues it
1020
- (`jobs.enqueue(CompileStatementsBackgroundJob, { month })`, the payload typed by `run`). The decorator
1066
+ (`jobs.enqueue(CompileStatementsBackgroundJob, { month })`, the payload typed by `run`). Its static
1067
+ `payload` is the schema of that payload, a `BackgroundJobPayloadSchema` (`parse(input)` answering a
1068
+ `Result`, which the `Schema` of `@ddd-ts-kit/validation` is, whatever library it adapts): the worker
1069
+ reads the stored payload with it before each run and never runs one it refuses
1070
+ (`INVALID_JOB_PAYLOAD`); the timeout job of a process uses `processTimeoutDuePayload`. The decorator
1021
1071
  takes the options, all optional: `maxAttempts` (5), `backoff` (`{ baseMs: 1000, factor: 2,
1022
1072
  maxMs: 300000 }`), `timeout` and `lease` (30 s), as milliseconds or `'10m'`. A name that is not
1023
- `<context>.<job-name>` and options it cannot read throw a `DeclarationError` when the file
1024
- loads. `BackgroundJobExecution` is what `run` receives: `jobId`, `attempt`, `enqueuedAt`,
1073
+ `<context>.<job-name>`, a class without a static `payload` and options it cannot read throw a
1074
+ `DeclarationError` when the file loads. `BackgroundJobExecution` is what `run` receives: `jobId`, `attempt`, `enqueuedAt`,
1025
1075
  `startedAt`, the `checkpoint` an earlier attempt saved, an abort `signal`, `saveCheckpoint(value)`
1026
1076
  and `reportProgress({ done, total })`.
1027
1077
 
@@ -0,0 +1,14 @@
1
+ import type { Result } from '../../domain/result/result.js';
2
+ import type { PayloadIssue } from '../personal-data/payload-issue.js';
3
+ /**
4
+ * How the worker reads the payload a queue kept for a background job, before each run: the
5
+ * static `payload` of the class, next to its `jobName`. A payload enqueued before a deploy that
6
+ * changed its shape is refused there, never run as the new type. The `Schema` of
7
+ * `@ddd-ts-kit/validation` is one, whatever library it adapts (zod, class-validator, TypeBox,
8
+ * Standard Schema); a project without a validation library writes `parse` by hand.
9
+ */
10
+ export interface BackgroundJobPayloadSchema<Payload> {
11
+ /** The payload as the job reads it, or what does not fit, field by field. */
12
+ parse(input: unknown): Result<Payload, PayloadIssue[]>;
13
+ }
14
+ //# sourceMappingURL=background-job-payload-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-job-payload-schema.d.ts","sourceRoot":"","sources":["../../../src/application/background/background-job-payload-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B,CAAC,OAAO;IACjD,6EAA6E;IAC7E,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;CACxD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=background-job-payload-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-job-payload-schema.js","sourceRoot":"","sources":["../../../src/application/background/background-job-payload-schema.ts"],"names":[],"mappings":""}
@@ -1,10 +1,13 @@
1
1
  import type { BackgroundJob } from './background-job.js';
2
+ import type { BackgroundJobPayloadSchema } from './background-job-payload-schema.js';
2
3
  /**
3
- * The class of a background job, as `enqueue` takes it: its static `jobName` names it, and its
4
- * `run` gives the type of the payload.
4
+ * The class of a background job, as `enqueue` takes it: its static `jobName` names it, its
5
+ * static `payload` is the schema the worker reads the stored payload with before each run, and
6
+ * its `run` gives the type of the payload.
5
7
  */
6
8
  export interface BackgroundJobType<Payload> {
7
9
  readonly jobName: string;
10
+ readonly payload: BackgroundJobPayloadSchema<Payload>;
8
11
  readonly prototype: BackgroundJob<Payload>;
9
12
  }
10
13
  //# sourceMappingURL=background-job-type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"background-job-type.d.ts","sourceRoot":"","sources":["../../../src/application/background/background-job-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC5C"}
1
+ {"version":3,"file":"background-job-type.d.ts","sourceRoot":"","sources":["../../../src/application/background/background-job-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAElF;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACtD,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC5C"}
@@ -3,7 +3,9 @@ import type { BackgroundJobExecution } from './background-job-execution.js';
3
3
  * A class of `application/background/`: work a use case hands to a worker, to run later and
4
4
  * outside of its request. Like a scheduled job it decides nothing: it triggers use cases. Its
5
5
  * name is a static `jobName`, `<context>.<job-name>`, which is also how a use case enqueues it:
6
- * `jobs.enqueue(CompileMonthlyReportJob, { practiceId, month })`.
6
+ * `jobs.enqueue(CompileMonthlyReportJob, { practiceId, month })`. Its static `payload` is the
7
+ * schema of what it works on: the worker reads the stored payload with it before each run, and a
8
+ * payload that does not fit is never run.
7
9
  *
8
10
  * Delivery is at least once: a run may be repeated after a crash, an expired lease or a retry,
9
11
  * so the work is idempotent, and a long one saves a checkpoint to resume from.
@@ -1 +1 @@
1
- {"version":3,"file":"background-job.d.ts","sourceRoot":"","sources":["../../../src/application/background/background-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa,CAAC,OAAO;IACpC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE"}
1
+ {"version":3,"file":"background-job.d.ts","sourceRoot":"","sources":["../../../src/application/background/background-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa,CAAC,OAAO;IACpC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE"}
@@ -1,5 +1,6 @@
1
1
  export * from './background-job-execution.js';
2
2
  export * from './background-job-options.js';
3
+ export * from './background-job-payload-schema.js';
3
4
  export * from './background-job-policy.js';
4
5
  export * from './background-job-type.js';
5
6
  export * from './background-job.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './background-job-execution.js';
2
2
  export * from './background-job-options.js';
3
+ export * from './background-job-payload-schema.js';
3
4
  export * from './background-job-policy.js';
4
5
  export * from './background-job-type.js';
5
6
  export * from './background-job.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './process-decision.js';
2
2
  export * from './process-manager.js';
3
+ export * from './process-timeout-due-payload.js';
3
4
  export * from './process-timeout-due.js';
4
5
  export * from './process-timeout.js';
5
6
  export * from './process-type.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './process-decision.js';
2
2
  export * from './process-manager.js';
3
+ export * from './process-timeout-due-payload.js';
3
4
  export * from './process-timeout-due.js';
4
5
  export * from './process-timeout.js';
5
6
  export * from './process-type.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/application/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { BackgroundJobPayloadSchema } from '../background/background-job-payload-schema.js';
2
+ import type { ProcessTimeoutDue } from './process-timeout-due.js';
3
+ /**
4
+ * The schema of the payload of the timeout job of a process, the static `payload` of that job:
5
+ * `static readonly payload = processTimeoutDuePayload`. Written in the kernel, which every
6
+ * context reads, whatever validation library the project has.
7
+ */
8
+ export declare const processTimeoutDuePayload: BackgroundJobPayloadSchema<ProcessTimeoutDue>;
9
+ //# sourceMappingURL=process-timeout-due-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout-due-payload.d.ts","sourceRoot":"","sources":["../../../src/application/process/process-timeout-due-payload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AAE9F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,0BAA0B,CAAC,iBAAiB,CAWlF,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { err } from '../../domain/result/err.js';
2
+ import { ok } from '../../domain/result/ok.js';
3
+ /**
4
+ * The schema of the payload of the timeout job of a process, the static `payload` of that job:
5
+ * `static readonly payload = processTimeoutDuePayload`. Written in the kernel, which every
6
+ * context reads, whatever validation library the project has.
7
+ */
8
+ export const processTimeoutDuePayload = {
9
+ parse(input) {
10
+ const id = textOf(input, 'id');
11
+ const timeout = textOf(input, 'timeout');
12
+ if (id === undefined || timeout === undefined) {
13
+ return err([...(id === undefined ? [issue('id')] : []), ...(timeout === undefined ? [issue('timeout')] : [])]);
14
+ }
15
+ return ok({ id, timeout });
16
+ },
17
+ };
18
+ function textOf(input, name) {
19
+ const value = typeof input === 'object' && input !== null ? Reflect.get(input, name) : undefined;
20
+ return typeof value === 'string' && value !== '' ? value : undefined;
21
+ }
22
+ function issue(path) {
23
+ return { path, code: 'invalid_type', message: `${path} is not a text.` };
24
+ }
25
+ //# sourceMappingURL=process-timeout-due-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-timeout-due-payload.js","sourceRoot":"","sources":["../../../src/application/process/process-timeout-due-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAK5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkD;IACrF,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAEzC,IAAI,EAAE,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC9C,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACjH,CAAC;QAED,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7B,CAAC;CACF,CAAC;AAEF,SAAS,MAAM,CAAC,KAAc,EAAE,IAAY;IAC1C,MAAM,KAAK,GAAY,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1G,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC;AAED,SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAC3E,CAAC"}
@@ -1,13 +1,20 @@
1
1
  import type { BackgroundJobOptions } from '../../application/background/background-job-options.js';
2
+ import type { BackgroundJobPayloadSchema } from '../../application/background/background-job-payload-schema.js';
2
3
  import type { BackgroundJob } from '../../application/background/background-job.js';
3
4
  import type { ClassDeclarator } from '../dependencies/class-declarator.js';
4
5
  import type { DeclaredDependencies } from '../dependencies/declared-dependencies.js';
5
6
  import type { DependenciesFromSignature } from '../dependencies/dependencies-from-signature.js';
7
+ /** What a background job class carries next to its constructor: the schema of its payload. */
8
+ interface PayloadDeclared {
9
+ readonly payload: BackgroundJobPayloadSchema<unknown>;
10
+ }
6
11
  /**
7
12
  * A background job, run by a worker after a use case enqueued it, named by the static `jobName`
8
- * of the class: `@Background({ maxAttempts: 3, timeout: '10m' })`. The name and the options are
13
+ * of the class and reading its stored payload with its static `payload` schema:
14
+ * `@Background({ maxAttempts: 3, timeout: '10m' })`. The name, the schema and the options are
9
15
  * checked when the file loads. Under standard decorators a class decorator runs before the
10
16
  * static fields exist: the job is then recorded once the class is defined.
11
17
  */
12
- export declare function Background<const D extends DeclaredDependencies = DependenciesFromSignature>(options?: BackgroundJobOptions, dependencies?: D): ClassDeclarator<BackgroundJob<unknown>, D>;
18
+ export declare function Background<const D extends DeclaredDependencies = DependenciesFromSignature>(options?: BackgroundJobOptions, dependencies?: D): ClassDeclarator<BackgroundJob<unknown>, D, PayloadDeclared>;
19
+ export {};
13
20
  //# sourceMappingURL=background.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/declarations/decorators/background.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAEhG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAGjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAI7F;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,yBAAyB,EACzF,OAAO,GAAE,oBAAyB,EAClC,YAAY,CAAC,EAAE,CAAC,GACf,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAsB5C"}
1
+ {"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/declarations/decorators/background.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAEhG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAGjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAI7F,8FAA8F;AAC9F,UAAU,eAAe;IACvB,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;CACvD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,oBAAoB,GAAG,yBAAyB,EACzF,OAAO,GAAE,oBAAyB,EAClC,YAAY,CAAC,EAAE,CAAC,GACf,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,eAAe,CAAC,CAuB7D"}
@@ -5,7 +5,8 @@ import { DeclarationError } from '../registry/declaration-error.js';
5
5
  import { record } from '../registry/record.js';
6
6
  /**
7
7
  * A background job, run by a worker after a use case enqueued it, named by the static `jobName`
8
- * of the class: `@Background({ maxAttempts: 3, timeout: '10m' })`. The name and the options are
8
+ * of the class and reading its stored payload with its static `payload` schema:
9
+ * `@Background({ maxAttempts: 3, timeout: '10m' })`. The name, the schema and the options are
9
10
  * checked when the file loads. Under standard decorators a class decorator runs before the
10
11
  * static fields exist: the job is then recorded once the class is defined.
11
12
  */
@@ -13,6 +14,7 @@ export function Background(options = {}, dependencies) {
13
14
  return (target, context) => {
14
15
  const declare = () => {
15
16
  const name = nameOf(target);
17
+ const payload = payloadOf(target, name);
16
18
  try {
17
19
  backgroundJobPolicy(options);
18
20
  }
@@ -21,7 +23,7 @@ export function Background(options = {}, dependencies) {
21
23
  ? new DeclarationError(`Job "${name}": ${error.message}`)
22
24
  : error;
23
25
  }
24
- record(target, { role: 'background-job', name, options, implementation: target, dependencies });
26
+ record(target, { role: 'background-job', name, options, payload, implementation: target, dependencies });
25
27
  };
26
28
  if (context === undefined) {
27
29
  declare();
@@ -38,4 +40,14 @@ function nameOf(target) {
38
40
  }
39
41
  throw new DeclarationError(`${target.name} has no static jobName of the form <context>.<job-name>: write static readonly jobName = 'billing.compile-statements'.`);
40
42
  }
43
+ function payloadOf(target, name) {
44
+ const payload = Reflect.get(target, 'payload');
45
+ if (isPayloadSchema(payload)) {
46
+ return payload;
47
+ }
48
+ throw new DeclarationError(`Job "${name}" has no static payload schema: write static readonly payload = <the schema of its payload>, which the worker reads the stored payload with before each run.`);
49
+ }
50
+ function isPayloadSchema(value) {
51
+ return typeof value === 'object' && value !== null && typeof Reflect.get(value, 'parse') === 'function';
52
+ }
41
53
  //# sourceMappingURL=background.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"background.js","sourceRoot":"","sources":["../../../src/declarations/decorators/background.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAEzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yDAAyD,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,OAAO,GAAyB,EAAE,EAClC,YAAgB;IAEhB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAE5B,IAAI,CAAC;gBACH,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,KAAK,YAAY,uBAAuB;oBAC5C,CAAC,CAAC,IAAI,gBAAgB,CAAC,QAAQ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;oBACzD,CAAC,CAAC,KAAK,CAAC;YACZ,CAAC;YAED,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QAClG,CAAC,CAAC;QAEF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,MAAiC;IAC/C,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAErD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,IAAI,gBAAgB,CACxB,GAAG,MAAM,CAAC,IAAI,wHAAwH,CACvI,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"background.js","sourceRoot":"","sources":["../../../src/declarations/decorators/background.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AAGzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yDAAyD,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAO5C;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACxB,OAAO,GAAyB,EAAE,EAClC,YAAgB;IAEhB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAExC,IAAI,CAAC;gBACH,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,KAAK,YAAY,uBAAuB;oBAC5C,CAAC,CAAC,IAAI,gBAAgB,CAAC,QAAQ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;oBACzD,CAAC,CAAC,KAAK,CAAC;YACZ,CAAC;YAED,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QAC3G,CAAC,CAAC;QAEF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,MAAiC;IAC/C,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAErD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,IAAI,gBAAgB,CACxB,GAAG,MAAM,CAAC,IAAI,wHAAwH,CACvI,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,IAAY;IAC7C,MAAM,OAAO,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAExD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,gBAAgB,CACxB,QAAQ,IAAI,8JAA8J,CAC3K,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,UAAU,CAAC;AAC1G,CAAC"}
@@ -2,9 +2,9 @@ import type { MatchingDependencies } from './matching-dependencies.js';
2
2
  /**
3
3
  * A class decorator that accepts only a class whose instances are `Instance` and whose
4
4
  * constructor parameters are the ones `List` names, in order; without a list, any constructor,
5
- * whose signature then states the dependencies. It serves both decorator
5
+ * whose signature then states the dependencies, and whose static members are `Statics`. It serves both decorator
6
6
  * modes of the compiler: the standard (TC39) call hands it a context, the legacy
7
7
  * `experimentalDecorators` call does not, and it reads nothing but the class.
8
8
  */
9
- export type ClassDeclarator<Instance, List> = <Args extends readonly unknown[]>(target: (new (...args: Args) => Instance) & MatchingDependencies<Args, List>, context?: ClassDecoratorContext) => void;
9
+ export type ClassDeclarator<Instance, List, Statics = unknown> = <Args extends readonly unknown[]>(target: (new (...args: Args) => Instance) & MatchingDependencies<Args, List> & Statics, context?: ClassDecoratorContext) => void;
10
10
  //# sourceMappingURL=class-declarator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"class-declarator.d.ts","sourceRoot":"","sources":["../../../src/declarations/dependencies/class-declarator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EAC5E,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,EAC5E,OAAO,CAAC,EAAE,qBAAqB,KAC5B,IAAI,CAAC"}
1
+ {"version":3,"file":"class-declarator.d.ts","sourceRoot":"","sources":["../../../src/declarations/dependencies/class-declarator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EAC/F,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,OAAO,EACtF,OAAO,CAAC,EAAE,qBAAqB,KAC5B,IAAI,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { BackgroundJobOptions } from '../../application/background/background-job-options.js';
2
+ import type { BackgroundJobPayloadSchema } from '../../application/background/background-job-payload-schema.js';
2
3
  import type { BackgroundJob } from '../../application/background/background-job.js';
3
4
  import type { Token } from '../token/token.js';
4
5
  export interface BackgroundJobDeclaration {
@@ -7,6 +8,8 @@ export interface BackgroundJobDeclaration {
7
8
  readonly name: string;
8
9
  /** As written: the defaults are filled in where the job is registered. */
9
10
  readonly options: BackgroundJobOptions;
11
+ /** The static `payload` of the class: the schema the worker reads the stored payload with. */
12
+ readonly payload: BackgroundJobPayloadSchema<unknown>;
10
13
  readonly implementation: new (...args: never) => BackgroundJob<unknown>;
11
14
  /** The list the decorator wrote; `undefined` when the constructor states the dependencies. */
12
15
  readonly dependencies: readonly Token<unknown>[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"background-job-declaration.d.ts","sourceRoot":"","sources":["../../../src/declarations/model/background-job-declaration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAChG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,2FAA2F;IAC3F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC;IACxE,8FAA8F;IAC9F,QAAQ,CAAC,YAAY,EAAE,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;CAC9D"}
1
+ {"version":3,"file":"background-job-declaration.d.ts","sourceRoot":"","sources":["../../../src/declarations/model/background-job-declaration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qDAAqD,CAAC;AAChG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,2FAA2F;IAC3F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACvC,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACtD,QAAQ,CAAC,cAAc,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC;IACxE,8FAA8F;IAC9F,QAAQ,CAAC,YAAY,EAAE,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;CAC9D"}
@@ -0,0 +1,17 @@
1
+ import type { Message } from '../application/messaging/message.js';
2
+ import type { MessageType } from '../application/messaging/message-type.js';
3
+ import type { ResultOf } from '../application/messaging/result-of.js';
4
+ /**
5
+ * The messages a recording bus was handed, in order, and what it answers for each type: the
6
+ * answer told for the class of a message, else for the nearest class above it; a message no
7
+ * answer covers is recorded all the same and answered `undefined`.
8
+ */
9
+ export declare class RecordedMessages<M extends Message> {
10
+ readonly list: M[];
11
+ private readonly answers;
12
+ answer<T extends M>(type: MessageType<T>, answer: (message: T) => ResultOf<T> | Promise<ResultOf<T>>): void;
13
+ received<T extends M>(message: T): Promise<ResultOf<T>>;
14
+ /** The answer told for the class of the message or, failing that, for the nearest class above it. */
15
+ private answerOf;
16
+ }
17
+ //# sourceMappingURL=recorded-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorded-messages.d.ts","sourceRoot":"","sources":["../../src/testing/recorded-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAOnE;;;;GAIG;AACH,qBAAa,gBAAgB,CAAC,CAAC,SAAS,OAAO;IAC7C,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAM;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IAEtD,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAE1G;IAEK,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAO5D;IAED,qGAAqG;IACrG,OAAO,CAAC,QAAQ;CAWjB"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The messages a recording bus was handed, in order, and what it answers for each type: the
3
+ * answer told for the class of a message, else for the nearest class above it; a message no
4
+ * answer covers is recorded all the same and answered `undefined`.
5
+ */
6
+ export class RecordedMessages {
7
+ list = [];
8
+ answers = new Map();
9
+ answer(type, answer) {
10
+ this.answers.set(type, { answer });
11
+ }
12
+ async received(message) {
13
+ this.list.push(message);
14
+ const answered = await this.answerOf(message)?.answer(message);
15
+ // eslint-disable-next-line ddd-ts-kit/clean-no-escape-hatch -- answers of every message type share one map: the link between a type and its result is only known to answer()
16
+ return answered;
17
+ }
18
+ /** The answer told for the class of the message or, failing that, for the nearest class above it. */
19
+ answerOf(message) {
20
+ for (let type = message.constructor; typeof type === 'function'; type = Object.getPrototypeOf(type)) {
21
+ const answer = this.answers.get(type);
22
+ if (answer !== undefined) {
23
+ return answer;
24
+ }
25
+ }
26
+ return undefined;
27
+ }
28
+ }
29
+ //# sourceMappingURL=recorded-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorded-messages.js","sourceRoot":"","sources":["../../src/testing/recorded-messages.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,IAAI,GAAQ,EAAE,CAAC;IAEP,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IAEtD,MAAM,CAAc,IAAoB,EAAE,MAA0D;QAClG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAc,OAAU;QACpC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAExB,MAAM,QAAQ,GAAY,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAExE,6KAA6K;QAC7K,OAAO,QAAuB,CAAC;IACjC,CAAC;IAED,qGAAqG;IAC7F,QAAQ,CAAC,OAAgB;QAC/B,KAAK,IAAI,IAAI,GAAY,OAAO,CAAC,WAAW,EAAE,OAAO,IAAI,KAAK,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7G,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAEtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ import type { Command } from '../application/messaging/command.js';
2
+ import type { MessageType } from '../application/messaging/message-type.js';
3
+ import type { ResultOf } from '../application/messaging/result-of.js';
4
+ import { CommandBus } from '../application/ports/command-bus.js';
5
+ /**
6
+ * The command bus of a spec that asserts what a class sends, a reaction or a controller: it
7
+ * keeps every command it is handed, in order, and answers what the spec told it to, `undefined`
8
+ * for a type it was told nothing about. The fact given, the command recorded asserted:
9
+ *
10
+ * const commands = new RecordingCommandBus();
11
+ *
12
+ * await new InvoiceIssuedEventHandler(commands).handle(issued);
13
+ *
14
+ * expect(commands.executed).toEqual([new ScheduleReminderCommand(reminder, 'invoice-1')]);
15
+ *
16
+ * No handler runs: what the command does is the spec of its own handler.
17
+ */
18
+ export declare class RecordingCommandBus extends CommandBus {
19
+ private readonly recorded;
20
+ /** Every command executed so far, in order. */
21
+ get executed(): readonly Command<unknown>[];
22
+ /**
23
+ * What the bus answers for each command of `type` from now on: an identifier, nothing, or a
24
+ * refusal the function throws. Told twice, the last answer holds. A subclass of `type` is
25
+ * answered the same, unless told an answer of its own.
26
+ */
27
+ answering<C extends Command<unknown>>(type: MessageType<C>, answer: (command: C) => ResultOf<C> | Promise<ResultOf<C>>): this;
28
+ execute<C extends Command<unknown>>(command: C): Promise<ResultOf<C>>;
29
+ }
30
+ //# sourceMappingURL=recording-command-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-command-bus.d.ts","sourceRoot":"","sources":["../../src/testing/recording-command-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAG9D;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4C;IAErE,+CAA+C;IAC/C,IAAI,QAAQ,IAAI,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,CAE1C;IAED;;;;OAIG;IACH,SAAS,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GACzD,IAAI,CAIN;IAED,OAAO,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEpE;CACF"}
@@ -0,0 +1,35 @@
1
+ import { CommandBus } from '../application/ports/command-bus.js';
2
+ import { RecordedMessages } from './recorded-messages.js';
3
+ /**
4
+ * The command bus of a spec that asserts what a class sends, a reaction or a controller: it
5
+ * keeps every command it is handed, in order, and answers what the spec told it to, `undefined`
6
+ * for a type it was told nothing about. The fact given, the command recorded asserted:
7
+ *
8
+ * const commands = new RecordingCommandBus();
9
+ *
10
+ * await new InvoiceIssuedEventHandler(commands).handle(issued);
11
+ *
12
+ * expect(commands.executed).toEqual([new ScheduleReminderCommand(reminder, 'invoice-1')]);
13
+ *
14
+ * No handler runs: what the command does is the spec of its own handler.
15
+ */
16
+ export class RecordingCommandBus extends CommandBus {
17
+ recorded = new RecordedMessages();
18
+ /** Every command executed so far, in order. */
19
+ get executed() {
20
+ return this.recorded.list;
21
+ }
22
+ /**
23
+ * What the bus answers for each command of `type` from now on: an identifier, nothing, or a
24
+ * refusal the function throws. Told twice, the last answer holds. A subclass of `type` is
25
+ * answered the same, unless told an answer of its own.
26
+ */
27
+ answering(type, answer) {
28
+ this.recorded.answer(type, answer);
29
+ return this;
30
+ }
31
+ execute(command) {
32
+ return this.recorded.received(command);
33
+ }
34
+ }
35
+ //# sourceMappingURL=recording-command-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-command-bus.js","sourceRoot":"","sources":["../../src/testing/recording-command-bus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IAChC,QAAQ,GAAG,IAAI,gBAAgB,EAAoB,CAAC;IAErE,+CAA+C;IAC/C,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,SAAS,CACP,IAAoB,EACpB,MAA0D;QAE1D,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAA6B,OAAU;QAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import type { MessageType } from '../application/messaging/message-type.js';
2
+ import type { Query } from '../application/messaging/query.js';
3
+ import type { ResultOf } from '../application/messaging/result-of.js';
4
+ import { QueryBus } from '../application/ports/query-bus.js';
5
+ /**
6
+ * The query bus of a spec that asserts what a class asks, a controller most often: it keeps
7
+ * every query it is handed, in order, and answers what the spec told it to, `undefined` for a
8
+ * type it was told nothing about.
9
+ *
10
+ * const queries = new RecordingQueryBus().answering(GetInvoiceQuery, () => invoice);
11
+ *
12
+ * No handler runs: what the query reads is the spec of its own handler.
13
+ */
14
+ export declare class RecordingQueryBus extends QueryBus {
15
+ private readonly recorded;
16
+ /** Every query executed so far, in order. */
17
+ get executed(): readonly Query<unknown>[];
18
+ /**
19
+ * What the bus answers for each query of `type` from now on, or the refusal the function throws.
20
+ * Told twice, the last answer holds. A subclass of `type` is answered the same, unless told an
21
+ * answer of its own.
22
+ */
23
+ answering<Q extends Query<unknown>>(type: MessageType<Q>, answer: (query: Q) => ResultOf<Q> | Promise<ResultOf<Q>>): this;
24
+ execute<Q extends Query<unknown>>(query: Q): Promise<ResultOf<Q>>;
25
+ }
26
+ //# sourceMappingURL=recording-query-bus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-query-bus.d.ts","sourceRoot":"","sources":["../../src/testing/recording-query-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAG1D;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IAEnE,6CAA6C;IAC7C,IAAI,QAAQ,IAAI,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,CAExC;IAED;;;;OAIG;IACH,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,EAChC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GACvD,IAAI,CAIN;IAED,OAAO,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAEhE;CACF"}
@@ -0,0 +1,31 @@
1
+ import { QueryBus } from '../application/ports/query-bus.js';
2
+ import { RecordedMessages } from './recorded-messages.js';
3
+ /**
4
+ * The query bus of a spec that asserts what a class asks, a controller most often: it keeps
5
+ * every query it is handed, in order, and answers what the spec told it to, `undefined` for a
6
+ * type it was told nothing about.
7
+ *
8
+ * const queries = new RecordingQueryBus().answering(GetInvoiceQuery, () => invoice);
9
+ *
10
+ * No handler runs: what the query reads is the spec of its own handler.
11
+ */
12
+ export class RecordingQueryBus extends QueryBus {
13
+ recorded = new RecordedMessages();
14
+ /** Every query executed so far, in order. */
15
+ get executed() {
16
+ return this.recorded.list;
17
+ }
18
+ /**
19
+ * What the bus answers for each query of `type` from now on, or the refusal the function throws.
20
+ * Told twice, the last answer holds. A subclass of `type` is answered the same, unless told an
21
+ * answer of its own.
22
+ */
23
+ answering(type, answer) {
24
+ this.recorded.answer(type, answer);
25
+ return this;
26
+ }
27
+ execute(query) {
28
+ return this.recorded.received(query);
29
+ }
30
+ }
31
+ //# sourceMappingURL=recording-query-bus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-query-bus.js","sourceRoot":"","sources":["../../src/testing/recording-query-bus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAC5B,QAAQ,GAAG,IAAI,gBAAgB,EAAkB,CAAC;IAEnE,6CAA6C;IAC7C,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,SAAS,CACP,IAAoB,EACpB,MAAwD;QAExD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAEnC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAA2B,KAAQ;QACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { RecordingCommandBus } from './testing/recording-command-bus.js';
2
+ export { RecordingQueryBus } from './testing/recording-query-bus.js';
3
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { RecordingCommandBus } from './testing/recording-command-bus.js';
2
+ export { RecordingQueryBus } from './testing/recording-query-bus.js';
3
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/kernel",
3
- "version": "0.99.0",
3
+ "version": "0.100.0",
4
4
  "description": "Framework-agnostic Domain-Driven Design (DDD) building blocks for TypeScript: aggregates, entities, value objects, domain events, CQRS command and query buses, unit of work and application ports, with an in-memory event bus.",
5
5
  "keywords": [
6
6
  "ddd",
@@ -37,6 +37,10 @@
37
37
  "./declarations": {
38
38
  "types": "./dist/declarations.d.ts",
39
39
  "default": "./dist/declarations.js"
40
+ },
41
+ "./testing": {
42
+ "types": "./dist/testing.d.ts",
43
+ "default": "./dist/testing.js"
40
44
  }
41
45
  },
42
46
  "files": [