@cratis/chronicle 6.52.1 → 6.53.1

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 (41) hide show
  1. package/dist/projections/ProjectionDefinitionCompiler.d.ts.map +1 -1
  2. package/dist/projections/ProjectionDefinitionCompiler.js +22 -18
  3. package/dist/projections/ProjectionDefinitionCompiler.js.map +1 -1
  4. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +6 -4
  5. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -1
  6. package/dist/projections/modelBound/childrenAndNestedBuilder.js +14 -12
  7. package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -1
  8. package/dist/reactors/Reactors.d.ts.map +1 -1
  9. package/dist/reactors/Reactors.js +2 -0
  10. package/dist/reactors/Reactors.js.map +1 -1
  11. package/dist/reactors/index.d.ts +1 -0
  12. package/dist/reactors/index.d.ts.map +1 -1
  13. package/dist/reactors/index.js +1 -0
  14. package/dist/reactors/index.js.map +1 -1
  15. package/dist/reactors/startAtTail.d.ts +18 -0
  16. package/dist/reactors/startAtTail.d.ts.map +1 -0
  17. package/dist/reactors/startAtTail.js +30 -0
  18. package/dist/reactors/startAtTail.js.map +1 -0
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/dist/webhooks/WebhookDefinitionBuilder.d.ts +1 -1
  21. package/dist/webhooks/WebhookDefinitionBuilder.d.ts.map +1 -1
  22. package/dist/webhooks/WebhookDefinitionBuilder.js +3 -1
  23. package/dist/webhooks/WebhookDefinitionBuilder.js.map +1 -1
  24. package/dist/webhooks/Webhooks.d.ts.map +1 -1
  25. package/dist/webhooks/Webhooks.js +2 -1
  26. package/dist/webhooks/Webhooks.js.map +1 -1
  27. package/jobs/for_Jobs/against_a_kernel/when_managing_a_replay_job.integration.spec.ts +25 -15
  28. package/package.json +2 -2
  29. package/projections/ProjectionDefinitionCompiler.ts +21 -18
  30. package/projections/for_ProjectionDefinitionCompiler/against_a_kernel/when_subscribing_with_from_all_events.integration.spec.ts +52 -48
  31. package/projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.spec.ts +52 -25
  32. package/projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.standard.spec.ts +49 -9
  33. package/projections/modelBound/childrenAndNestedBuilder.ts +17 -12
  34. package/reactors/Reactors.startAtTail.spec.ts +60 -0
  35. package/reactors/Reactors.ts +2 -0
  36. package/reactors/for_Reactors/against_a_kernel/when_starting_at_the_tail.integration.spec.ts +107 -0
  37. package/reactors/index.ts +1 -0
  38. package/reactors/startAtTail.spec.ts +31 -0
  39. package/reactors/startAtTail.ts +33 -0
  40. package/webhooks/WebhookDefinitionBuilder.ts +9 -7
  41. package/webhooks/Webhooks.ts +2 -1
package/reactors/index.ts CHANGED
@@ -6,6 +6,7 @@ export { ReactorDelivery } from './ReactorDelivery.js';
6
6
  export { reactor, getReactorMetadata, isReactor } from './reactor.js';
7
7
  export { handles } from '../events/handles.js';
8
8
  export { onceOnly } from './onceOnly.js';
9
+ export { startAtTail } from './startAtTail.js';
9
10
  export { replay } from './replay.js';
10
11
  export type { ReactorMetadata } from './reactor.js';
11
12
  export type { IReactors } from './IReactors.js';
@@ -0,0 +1,31 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { describe, expect, it } from 'vitest';
5
+ import { isStartAtTail, startAtTail } from './startAtTail.js';
6
+
7
+ @startAtTail()
8
+ class MarkedReactor {}
9
+
10
+ class OrdinaryReactor {}
11
+
12
+ class InheritedReactor extends MarkedReactor {}
13
+
14
+ describe('the start-at-tail decorator', () => {
15
+ it('marks the reactor class', () => {
16
+ expect(isStartAtTail(MarkedReactor)).toBe(true);
17
+ });
18
+
19
+ it('leaves an unmarked class alone', () => {
20
+ expect(isStartAtTail(OrdinaryReactor)).toBe(false);
21
+ });
22
+
23
+ it('is not inherited by a subclass', () => {
24
+ expect(isStartAtTail(InheritedReactor)).toBe(false);
25
+ });
26
+
27
+ it('refuses to decorate anything but a class', () => {
28
+ const decorate = startAtTail() as unknown as (target: object, context: { kind: string }) => void;
29
+ expect(() => decorate(() => {}, { kind: 'method' })).toThrow(TypeError);
30
+ });
31
+ });
@@ -0,0 +1,33 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import 'reflect-metadata';
5
+
6
+ const METADATA_KEY = 'chronicle:reactor:startAtTail';
7
+
8
+ /**
9
+ * A new reactor normally catches up from the beginning of the event sequence, so one whose handlers have side
10
+ * effects acts on every historical event the moment it is deployed. `@onceOnly()` does not prevent that, because it
11
+ * only excludes replay.
12
+ *
13
+ * Marks a reactor class so that the first time Chronicle sees it, it begins at the tail of the event sequence and
14
+ * observes only what is appended from then on. A reactor that already has a position keeps it, so the marker is safe
15
+ * to leave in place. Renaming the reactor or moving it changes its default id and makes it a new reactor, which
16
+ * starts at the tail again, unless an explicit id is given to `@reactor()`. An explicit replay still replays from the
17
+ * beginning. Both the Chronicle server and the client must support it; a server that predates it ignores the request.
18
+ * The marker is not inherited by subclasses.
19
+ * @returns A class decorator for legacy and standard TypeScript decorators.
20
+ */
21
+ export function startAtTail(): ClassDecorator & ((value: Function, context: ClassDecoratorContext) => void) {
22
+ return (target: object, context?: ClassDecoratorContext) => {
23
+ if (typeof context === 'object' && context.kind !== 'class') {
24
+ throw new TypeError('Start-at-tail can only decorate a reactor class.');
25
+ }
26
+ Reflect.defineMetadata(METADATA_KEY, true, target);
27
+ };
28
+ }
29
+
30
+ /** Whether this reactor class is marked to start at the tail (without inheriting the marker). */
31
+ export function isStartAtTail(target: Function): boolean {
32
+ return Reflect.getOwnMetadata(METADATA_KEY, target) === true;
33
+ }
@@ -1,12 +1,13 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
- import type {
5
- BasicAuthorization,
6
- BearerTokenAuthorization,
7
- OAuthAuthorization,
8
- OneOfBasicAuthorizationBearerTokenAuthorizationOAuthAuthorization,
9
- WebhookDefinition
4
+ import {
5
+ EventGenerationDelivery,
6
+ type BasicAuthorization,
7
+ type BearerTokenAuthorization,
8
+ type OAuthAuthorization,
9
+ type OneOfBasicAuthorizationBearerTokenAuthorizationOAuthAuthorization,
10
+ type WebhookDefinition
10
11
  } from '@cratis/chronicle.contracts';
11
12
  import { Constructor } from '@cratis/fundamentals';
12
13
  import { IEventTypes } from '../events/IEventTypes.js';
@@ -140,7 +141,8 @@ export class WebhookDefinitionBuilder implements IWebhookDefinitionBuilder {
140
141
  IsReplayable: this._isReplayable,
141
142
  IsActive: this._isActive,
142
143
  IsNotReplayable: !this._isReplayable,
143
- IsInactive: !this._isActive
144
+ IsInactive: !this._isActive,
145
+ GenerationDelivery: EventGenerationDelivery.Compatibility
144
146
  };
145
147
  }
146
148
  }
@@ -104,7 +104,8 @@ export class Webhooks implements IWebhooks {
104
104
  IsReplayable: webhook.IsReplayable,
105
105
  IsActive: webhook.IsActive,
106
106
  IsNotReplayable: !webhook.IsReplayable,
107
- IsInactive: !webhook.IsActive
107
+ IsInactive: !webhook.IsActive,
108
+ GenerationDelivery: webhook.GenerationDelivery
108
109
  }));
109
110
  }
110
111