@nestjs-transactional/outbox 1.0.0 → 2.0.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.
- package/README.md +38 -5
- package/dist/api/completed-event-publications.d.ts +2 -2
- package/dist/api/completed-event-publications.js +6 -9
- package/dist/api/completed-event-publications.js.map +1 -1
- package/dist/api/failed-event-publications.d.ts +3 -3
- package/dist/api/failed-event-publications.js +10 -13
- package/dist/api/failed-event-publications.js.map +1 -1
- package/dist/api/incomplete-event-publications.d.ts +3 -3
- package/dist/api/incomplete-event-publications.js +11 -14
- package/dist/api/incomplete-event-publications.js.map +1 -1
- package/dist/decorators/inject-decorators.js +12 -24
- package/dist/decorators/inject-decorators.js.map +1 -1
- package/dist/decorators/outbox-events-handler.decorator.js +6 -11
- package/dist/decorators/outbox-events-handler.decorator.js.map +1 -1
- package/dist/dispatcher/data-source-outbox-publisher.d.ts +2 -2
- package/dist/dispatcher/data-source-outbox-publisher.js +7 -11
- package/dist/dispatcher/data-source-outbox-publisher.js.map +1 -1
- package/dist/dispatcher/event-publication-processor.d.ts +5 -5
- package/dist/dispatcher/event-publication-processor.js +18 -21
- package/dist/dispatcher/event-publication-processor.js.map +1 -1
- package/dist/dispatcher/outbox-event-publisher.js +16 -19
- package/dist/dispatcher/outbox-event-publisher.js.map +1 -1
- package/dist/dispatcher/processor-options.d.ts +1 -1
- package/dist/dispatcher/processor-options.js +5 -8
- package/dist/dispatcher/processor-options.js.map +1 -1
- package/dist/externalization/describe-thrown.d.ts +20 -0
- package/dist/externalization/describe-thrown.js +46 -0
- package/dist/externalization/describe-thrown.js.map +1 -0
- package/dist/externalization/errors.d.ts +1 -1
- package/dist/externalization/errors.js +2 -6
- package/dist/externalization/errors.js.map +1 -1
- package/dist/externalization/event-externalizer.d.ts +1 -1
- package/dist/externalization/event-externalizer.js +1 -4
- package/dist/externalization/event-externalizer.js.map +1 -1
- package/dist/externalization/externalization-registry.d.ts +3 -3
- package/dist/externalization/externalization-registry.js +10 -13
- package/dist/externalization/externalization-registry.js.map +1 -1
- package/dist/externalization/externalized.decorator.js +6 -11
- package/dist/externalization/externalized.decorator.js.map +1 -1
- package/dist/externalization/types.js +1 -2
- package/dist/index.d.ts +43 -40
- package/dist/index.js +41 -61
- package/dist/index.js.map +1 -1
- package/dist/interfaces/outbox-event-handler.interface.js +1 -2
- package/dist/module/outbox-processing.module.d.ts +1 -1
- package/dist/module/outbox-processing.module.js +12 -9
- package/dist/module/outbox-processing.module.js.map +1 -1
- package/dist/module/outbox.module.d.ts +15 -8
- package/dist/module/outbox.module.js +179 -145
- package/dist/module/outbox.module.js.map +1 -1
- package/dist/recovery/outbox-cleanup-scheduler.d.ts +56 -0
- package/dist/recovery/outbox-cleanup-scheduler.js +136 -0
- package/dist/recovery/outbox-cleanup-scheduler.js.map +1 -0
- package/dist/recovery/outbox-retry-scheduler.d.ts +2 -2
- package/dist/recovery/outbox-retry-scheduler.js +11 -14
- package/dist/recovery/outbox-retry-scheduler.js.map +1 -1
- package/dist/recovery/staleness-monitor.d.ts +2 -2
- package/dist/recovery/staleness-monitor.js +14 -17
- package/dist/recovery/staleness-monitor.js.map +1 -1
- package/dist/recovery/startup-recovery.d.ts +1 -1
- package/dist/recovery/startup-recovery.js +11 -14
- package/dist/recovery/startup-recovery.js.map +1 -1
- package/dist/registry/event-publication-registry.d.ts +4 -4
- package/dist/registry/event-publication-registry.js +17 -20
- package/dist/registry/event-publication-registry.js.map +1 -1
- package/dist/registry/listener-registry.js +6 -9
- package/dist/registry/listener-registry.js.map +1 -1
- package/dist/registry/multi-ds-listener-registrar.d.ts +1 -1
- package/dist/registry/multi-ds-listener-registrar.js +15 -18
- package/dist/registry/multi-ds-listener-registrar.js.map +1 -1
- package/dist/registry/outbox-listener-scanner.d.ts +1 -1
- package/dist/registry/outbox-listener-scanner.js +23 -27
- package/dist/registry/outbox-listener-scanner.js.map +1 -1
- package/dist/repository/event-publication-repository.d.ts +14 -3
- package/dist/repository/event-publication-repository.js +1 -4
- package/dist/repository/event-publication-repository.js.map +1 -1
- package/dist/serialization/event-serializer.js +1 -4
- package/dist/serialization/event-serializer.js.map +1 -1
- package/dist/serialization/event-type-registry.js +5 -8
- package/dist/serialization/event-type-registry.js.map +1 -1
- package/dist/serialization/event-type-resolver.d.ts +1 -1
- package/dist/serialization/event-type-resolver.js +4 -7
- package/dist/serialization/event-type-resolver.js.map +1 -1
- package/dist/serialization/json-event-serializer.d.ts +2 -2
- package/dist/serialization/json-event-serializer.js +10 -13
- package/dist/serialization/json-event-serializer.js.map +1 -1
- package/dist/shutdown/drain.js +2 -6
- package/dist/shutdown/drain.js.map +1 -1
- package/dist/testing/assertable-published-events.d.ts +1 -1
- package/dist/testing/assertable-published-events.js +8 -13
- package/dist/testing/assertable-published-events.js.map +1 -1
- package/dist/testing/in-memory-repository.d.ts +3 -3
- package/dist/testing/in-memory-repository.js +32 -25
- package/dist/testing/in-memory-repository.js.map +1 -1
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +3 -19
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/published-events.d.ts +3 -3
- package/dist/testing/published-events.js +11 -14
- package/dist/testing/published-events.js.map +1 -1
- package/dist/tokens/index.d.ts +1 -1
- package/dist/tokens/index.js +1 -13
- package/dist/tokens/index.js.map +1 -1
- package/dist/tokens/token-utils.js +10 -21
- package/dist/tokens/token-utils.js.map +1 -1
- package/dist/types/cleanup-config.d.ts +59 -0
- package/dist/types/cleanup-config.js +14 -0
- package/dist/types/cleanup-config.js.map +1 -0
- package/dist/types/completion-mode.js +2 -5
- package/dist/types/completion-mode.js.map +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.js +7 -16
- package/dist/types/errors.js.map +1 -1
- package/dist/types/event-publication.d.ts +1 -1
- package/dist/types/event-publication.js +1 -2
- package/dist/types/publication-status.js +2 -5
- package/dist/types/publication-status.js.map +1 -1
- package/dist/types/resubmission-options.d.ts +1 -1
- package/dist/types/resubmission-options.js +1 -5
- package/dist/types/resubmission-options.js.map +1 -1
- package/dist/types/retry-config.js +3 -6
- package/dist/types/retry-config.js.map +1 -1
- package/dist/types/staleness-config.js +3 -6
- package/dist/types/staleness-config.js.map +1 -1
- package/package.json +21 -19
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6,61 +5,64 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
7
|
var OutboxModule_1;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
8
|
+
import { Module, } from '@nestjs/common';
|
|
9
|
+
import { DiscoveryModule, ModuleRef } from '@nestjs/core';
|
|
10
|
+
import { TransactionManager } from '@nestjs-transactional/core';
|
|
11
|
+
import { CompletedEventPublications } from '../api/completed-event-publications.js';
|
|
12
|
+
import { FailedEventPublications } from '../api/failed-event-publications.js';
|
|
13
|
+
import { IncompleteEventPublications } from '../api/incomplete-event-publications.js';
|
|
14
|
+
import { DataSourceOutboxPublisher } from '../dispatcher/data-source-outbox-publisher.js';
|
|
15
|
+
import { EventPublicationProcessor } from '../dispatcher/event-publication-processor.js';
|
|
16
|
+
import { OUTBOX_DATA_SOURCE_NAMES, OutboxEventPublisher, } from '../dispatcher/outbox-event-publisher.js';
|
|
17
|
+
import { DEFAULT_PROCESSOR_OPTIONS, } from '../dispatcher/processor-options.js';
|
|
18
|
+
import { EVENT_EXTERNALIZER, } from '../externalization/event-externalizer.js';
|
|
19
|
+
import { ExternalizationRegistry } from '../externalization/externalization-registry.js';
|
|
20
|
+
import { OutboxCleanupScheduler } from '../recovery/outbox-cleanup-scheduler.js';
|
|
21
|
+
import { OutboxRetryScheduler } from '../recovery/outbox-retry-scheduler.js';
|
|
22
|
+
import { StalenessMonitor } from '../recovery/staleness-monitor.js';
|
|
23
|
+
import { OUTBOX_RECOVERY_OPTIONS, StartupRecoveryService, } from '../recovery/startup-recovery.js';
|
|
24
|
+
import { EventPublicationRegistry } from '../registry/event-publication-registry.js';
|
|
25
|
+
import { OutboxListenerRegistry } from '../registry/listener-registry.js';
|
|
26
|
+
import { MultiDsOutboxListenerRegistrar, OUTBOX_LISTENER_REGISTRAR_TOKEN, } from '../registry/multi-ds-listener-registrar.js';
|
|
27
|
+
import { OutboxListenerScanner } from '../registry/outbox-listener-scanner.js';
|
|
28
|
+
import { EVENT_PUBLICATION_REPOSITORY, } from '../repository/event-publication-repository.js';
|
|
29
|
+
import { EVENT_SERIALIZER } from '../serialization/event-serializer.js';
|
|
30
|
+
import { EVENT_TYPE_REGISTRY, EventTypeRegistry } from '../serialization/event-type-registry.js';
|
|
31
|
+
import { JsonEventSerializer } from '../serialization/json-event-serializer.js';
|
|
32
|
+
import { InMemoryEventPublicationRepository } from '../testing/in-memory-repository.js';
|
|
33
|
+
import { getEventPublicationProcessorToken, getEventPublicationRegistryToken, getEventPublicationRepositoryToken, getEventTypeRegistryToken, getExternalizationRegistryToken, getOutboxEventSerializerToken, getOutboxListenerRegistryToken, getOutboxPublisherToken, } from '../tokens/token-utils.js';
|
|
34
|
+
import { DEFAULT_CLEANUP_CONFIG } from '../types/cleanup-config.js';
|
|
35
|
+
import { DEFAULT_RETRY_CONFIG } from '../types/retry-config.js';
|
|
36
|
+
import { DEFAULT_STALENESS_CONFIG } from '../types/staleness-config.js';
|
|
38
37
|
const DEFAULT_DATA_SOURCE = 'default';
|
|
39
38
|
/** DI token carrying the resolved {@link EventPublicationProcessorOptions}. */
|
|
40
|
-
|
|
39
|
+
export const OUTBOX_PROCESSOR_OPTIONS = Symbol('OUTBOX_PROCESSOR_OPTIONS');
|
|
41
40
|
/** DI token carrying the resolved {@link StalenessConfig}. */
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
export const OUTBOX_STALENESS_CONFIG = Symbol('OUTBOX_STALENESS_CONFIG');
|
|
42
|
+
export const OUTBOX_RETRY_CONFIG = Symbol('OUTBOX_RETRY_CONFIG');
|
|
44
43
|
/**
|
|
45
44
|
* Bundle of per-dataSource processors and monitors that
|
|
46
45
|
* {@link OutboxProcessingModule} reads on bootstrap to start every
|
|
47
46
|
* configured outbox loop. Provided by `forRoot` so the processing
|
|
48
47
|
* module needs no per-dataSource configuration of its own.
|
|
49
48
|
*/
|
|
50
|
-
|
|
49
|
+
export const OUTBOX_PROCESSING_BUNDLE = Symbol('OUTBOX_PROCESSING_BUNDLE');
|
|
51
50
|
const ASYNC_OPTIONS_TOKEN = (ds) => Symbol(`OUTBOX_ASYNC_OPTIONS[${ds}]`);
|
|
52
51
|
function resolveProcessorOptions(processor, completionMode) {
|
|
53
52
|
return {
|
|
54
|
-
...
|
|
53
|
+
...DEFAULT_PROCESSOR_OPTIONS,
|
|
55
54
|
...processor,
|
|
56
|
-
completionMode: completionMode ?? processor?.completionMode ??
|
|
55
|
+
completionMode: completionMode ?? processor?.completionMode ?? DEFAULT_PROCESSOR_OPTIONS.completionMode,
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
58
|
function resolveStalenessConfig(staleness) {
|
|
60
|
-
return { ...
|
|
59
|
+
return { ...DEFAULT_STALENESS_CONFIG, ...staleness };
|
|
61
60
|
}
|
|
62
61
|
function resolveRetryConfig(retry) {
|
|
63
|
-
return { ...
|
|
62
|
+
return { ...DEFAULT_RETRY_CONFIG, ...retry };
|
|
63
|
+
}
|
|
64
|
+
function resolveCleanupConfig(cleanup) {
|
|
65
|
+
return { ...DEFAULT_CLEANUP_CONFIG, ...cleanup };
|
|
64
66
|
}
|
|
65
67
|
function resolveRecoveryOptions(republishOnStartup, startupBatchSize) {
|
|
66
68
|
return {
|
|
@@ -144,22 +146,24 @@ let OutboxModule = class OutboxModule {
|
|
|
144
146
|
const stalenessCfg = resolveStalenessConfig(options.staleness);
|
|
145
147
|
const recoveryOpts = resolveRecoveryOptions(options.republishOnStartup, options.startupBatchSize);
|
|
146
148
|
const retryCfg = resolveRetryConfig(options.retry);
|
|
149
|
+
const cleanupCfg = resolveCleanupConfig(options.cleanup);
|
|
147
150
|
this.registrations.set(ds, {
|
|
148
151
|
dataSource: ds,
|
|
149
152
|
processorOptions: processorOpts,
|
|
150
153
|
stalenessConfig: stalenessCfg,
|
|
151
154
|
recoveryOptions: recoveryOpts,
|
|
152
155
|
retryConfig: retryCfg,
|
|
156
|
+
cleanupConfig: cleanupCfg,
|
|
153
157
|
});
|
|
154
158
|
const providers = [
|
|
155
|
-
...buildPerDataSourceProviders(ds, options.repository, options.serializer, processorOpts, stalenessCfg, recoveryOpts, retryCfg),
|
|
159
|
+
...buildPerDataSourceProviders(ds, options.repository, options.serializer, processorOpts, stalenessCfg, recoveryOpts, retryCfg, cleanupCfg),
|
|
156
160
|
];
|
|
157
161
|
const exportTokens = [...perDataSourceExports(ds)];
|
|
158
162
|
if (ds === DEFAULT_DATA_SOURCE) {
|
|
159
163
|
providers.push(...buildDefaultDataSourceAliases());
|
|
160
|
-
providers.push(
|
|
164
|
+
providers.push(FailedEventPublications, IncompleteEventPublications, CompletedEventPublications, StartupRecoveryService);
|
|
161
165
|
exportTokens.push(...defaultDataSourceAliasTokens());
|
|
162
|
-
exportTokens.push(
|
|
166
|
+
exportTokens.push(FailedEventPublications, IncompleteEventPublications, CompletedEventPublications, StartupRecoveryService);
|
|
163
167
|
}
|
|
164
168
|
if (isFirstRegistration) {
|
|
165
169
|
// Process-wide singletons. Their factories close over this
|
|
@@ -168,17 +172,17 @@ let OutboxModule = class OutboxModule {
|
|
|
168
172
|
// (forRoot bodies run synchronously at module-definition time).
|
|
169
173
|
providers.push(...buildFacadePublisherProvider(OutboxModule_1));
|
|
170
174
|
providers.push(buildProcessingBundleProvider(OutboxModule_1));
|
|
171
|
-
providers.push(
|
|
175
|
+
providers.push(OutboxListenerScanner);
|
|
172
176
|
providers.push(...buildMultiDsRegistrarProviders());
|
|
173
|
-
exportTokens.push(
|
|
174
|
-
exportTokens.push(
|
|
175
|
-
exportTokens.push(
|
|
176
|
-
exportTokens.push(
|
|
177
|
+
exportTokens.push(OutboxEventPublisher);
|
|
178
|
+
exportTokens.push(OUTBOX_PROCESSING_BUNDLE);
|
|
179
|
+
exportTokens.push(MultiDsOutboxListenerRegistrar);
|
|
180
|
+
exportTokens.push(OUTBOX_LISTENER_REGISTRAR_TOKEN);
|
|
177
181
|
}
|
|
178
182
|
return {
|
|
179
183
|
module: OutboxModule_1,
|
|
180
184
|
global: options.isGlobal ?? true,
|
|
181
|
-
imports: [
|
|
185
|
+
imports: [DiscoveryModule],
|
|
182
186
|
providers,
|
|
183
187
|
exports: exportTokens,
|
|
184
188
|
};
|
|
@@ -207,6 +211,7 @@ let OutboxModule = class OutboxModule {
|
|
|
207
211
|
stalenessConfig: resolveStalenessConfig(undefined),
|
|
208
212
|
recoveryOptions: resolveRecoveryOptions(undefined, undefined),
|
|
209
213
|
retryConfig: resolveRetryConfig(undefined),
|
|
214
|
+
cleanupConfig: resolveCleanupConfig(undefined),
|
|
210
215
|
});
|
|
211
216
|
const asyncToken = ASYNC_OPTIONS_TOKEN(ds);
|
|
212
217
|
const asyncOptionsProvider = {
|
|
@@ -214,14 +219,14 @@ let OutboxModule = class OutboxModule {
|
|
|
214
219
|
useFactory: options.useFactory,
|
|
215
220
|
inject: options.inject ? [...options.inject] : undefined,
|
|
216
221
|
};
|
|
217
|
-
const eventTypeRegistryToken =
|
|
218
|
-
const repositoryToken =
|
|
219
|
-
const serializerToken =
|
|
220
|
-
const listenerRegistryToken =
|
|
221
|
-
const publicationRegistryToken =
|
|
222
|
-
const externalizationRegistryToken =
|
|
223
|
-
const processorToken =
|
|
224
|
-
const publisherToken =
|
|
222
|
+
const eventTypeRegistryToken = getEventTypeRegistryToken(ds);
|
|
223
|
+
const repositoryToken = getEventPublicationRepositoryToken(ds);
|
|
224
|
+
const serializerToken = getOutboxEventSerializerToken(ds);
|
|
225
|
+
const listenerRegistryToken = getOutboxListenerRegistryToken(ds);
|
|
226
|
+
const publicationRegistryToken = getEventPublicationRegistryToken(ds);
|
|
227
|
+
const externalizationRegistryToken = getExternalizationRegistryToken(ds);
|
|
228
|
+
const processorToken = getEventPublicationProcessorToken(ds);
|
|
229
|
+
const publisherToken = getOutboxPublisherToken(ds);
|
|
225
230
|
const stalenessToken = perDsStalenessMonitorToken(ds);
|
|
226
231
|
const recoveryToken = perDsStartupRecoveryToken(ds);
|
|
227
232
|
const processorOptionsToken = perDsProcessorOptionsToken(ds);
|
|
@@ -229,34 +234,36 @@ let OutboxModule = class OutboxModule {
|
|
|
229
234
|
const recoveryOptionsToken = perDsRecoveryOptionsToken(ds);
|
|
230
235
|
const retryToken = perDsRetrySchedulerToken(ds);
|
|
231
236
|
const retryConfigToken = perDsRetryConfigToken(ds);
|
|
237
|
+
const cleanupToken = perDsCleanupSchedulerToken(ds);
|
|
238
|
+
const cleanupConfigToken = perDsCleanupConfigToken(ds);
|
|
232
239
|
const providers = [
|
|
233
240
|
asyncOptionsProvider,
|
|
234
241
|
{
|
|
235
242
|
provide: eventTypeRegistryToken,
|
|
236
|
-
useFactory: () => new
|
|
243
|
+
useFactory: () => new EventTypeRegistry(),
|
|
237
244
|
},
|
|
238
245
|
options.repository
|
|
239
246
|
? reBindProvider(options.repository, repositoryToken)
|
|
240
|
-
: { provide: repositoryToken, useClass:
|
|
247
|
+
: { provide: repositoryToken, useClass: InMemoryEventPublicationRepository },
|
|
241
248
|
options.serializer
|
|
242
249
|
? reBindProvider(options.serializer, serializerToken)
|
|
243
250
|
: {
|
|
244
251
|
provide: serializerToken,
|
|
245
|
-
useFactory: (registry) => new
|
|
252
|
+
useFactory: (registry) => new JsonEventSerializer(registry),
|
|
246
253
|
inject: [eventTypeRegistryToken],
|
|
247
254
|
},
|
|
248
255
|
{
|
|
249
256
|
provide: listenerRegistryToken,
|
|
250
|
-
useFactory: () => new
|
|
257
|
+
useFactory: () => new OutboxListenerRegistry(),
|
|
251
258
|
},
|
|
252
259
|
{
|
|
253
260
|
provide: publicationRegistryToken,
|
|
254
|
-
useFactory: (repo, serializer) => new
|
|
261
|
+
useFactory: (repo, serializer) => new EventPublicationRegistry(repo, serializer),
|
|
255
262
|
inject: [repositoryToken, serializerToken],
|
|
256
263
|
},
|
|
257
264
|
{
|
|
258
265
|
provide: externalizationRegistryToken,
|
|
259
|
-
useFactory: (etr) => new
|
|
266
|
+
useFactory: (etr) => new ExternalizationRegistry(etr),
|
|
260
267
|
inject: [eventTypeRegistryToken],
|
|
261
268
|
},
|
|
262
269
|
{
|
|
@@ -266,12 +273,12 @@ let OutboxModule = class OutboxModule {
|
|
|
266
273
|
},
|
|
267
274
|
{
|
|
268
275
|
provide: processorToken,
|
|
269
|
-
useFactory: (registry, listeners, opts, externalizer, externalizationRegistry) => new
|
|
276
|
+
useFactory: (registry, listeners, opts, externalizer, externalizationRegistry) => new EventPublicationProcessor(registry, listeners, opts, externalizer, externalizationRegistry),
|
|
270
277
|
inject: [
|
|
271
278
|
publicationRegistryToken,
|
|
272
279
|
listenerRegistryToken,
|
|
273
280
|
processorOptionsToken,
|
|
274
|
-
{ token:
|
|
281
|
+
{ token: EVENT_EXTERNALIZER, optional: true },
|
|
275
282
|
externalizationRegistryToken,
|
|
276
283
|
],
|
|
277
284
|
},
|
|
@@ -282,7 +289,7 @@ let OutboxModule = class OutboxModule {
|
|
|
282
289
|
},
|
|
283
290
|
{
|
|
284
291
|
provide: stalenessToken,
|
|
285
|
-
useFactory: (repo, cfg) => new
|
|
292
|
+
useFactory: (repo, cfg) => new StalenessMonitor(repo, cfg),
|
|
286
293
|
inject: [repositoryToken, stalenessConfigToken],
|
|
287
294
|
},
|
|
288
295
|
{
|
|
@@ -295,9 +302,19 @@ let OutboxModule = class OutboxModule {
|
|
|
295
302
|
useFactory: (repo, cfg) =>
|
|
296
303
|
// Built on a per-DS `FailedEventPublications` rather than the
|
|
297
304
|
// class-token one, which is bound to the default dataSource.
|
|
298
|
-
new
|
|
305
|
+
new OutboxRetryScheduler(new FailedEventPublications(repo), cfg),
|
|
299
306
|
inject: [repositoryToken, retryConfigToken],
|
|
300
307
|
},
|
|
308
|
+
{
|
|
309
|
+
provide: cleanupConfigToken,
|
|
310
|
+
useFactory: (opts) => resolveCleanupConfig(opts.cleanup),
|
|
311
|
+
inject: [asyncToken],
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
provide: cleanupToken,
|
|
315
|
+
useFactory: (repo, cfg) => new OutboxCleanupScheduler(repo, cfg),
|
|
316
|
+
inject: [repositoryToken, cleanupConfigToken],
|
|
317
|
+
},
|
|
301
318
|
{
|
|
302
319
|
provide: recoveryOptionsToken,
|
|
303
320
|
useFactory: (opts) => resolveRecoveryOptions(opts.republishOnStartup, opts.startupBatchSize),
|
|
@@ -305,30 +322,30 @@ let OutboxModule = class OutboxModule {
|
|
|
305
322
|
},
|
|
306
323
|
{
|
|
307
324
|
provide: publisherToken,
|
|
308
|
-
useFactory: (publicationRegistry, listenerRegistry) => new
|
|
325
|
+
useFactory: (publicationRegistry, listenerRegistry) => new DataSourceOutboxPublisher(ds, publicationRegistry, listenerRegistry),
|
|
309
326
|
inject: [publicationRegistryToken, listenerRegistryToken],
|
|
310
327
|
},
|
|
311
328
|
];
|
|
312
329
|
const exportTokens = [...perDataSourceExports(ds)];
|
|
313
330
|
if (ds === DEFAULT_DATA_SOURCE) {
|
|
314
|
-
providers.push({ provide: recoveryToken, useExisting:
|
|
331
|
+
providers.push({ provide: recoveryToken, useExisting: StartupRecoveryService }, ...buildDefaultDataSourceAliases(), FailedEventPublications, IncompleteEventPublications, CompletedEventPublications, StartupRecoveryService);
|
|
315
332
|
exportTokens.push(...defaultDataSourceAliasTokens());
|
|
316
|
-
exportTokens.push(
|
|
333
|
+
exportTokens.push(FailedEventPublications, IncompleteEventPublications, CompletedEventPublications, StartupRecoveryService);
|
|
317
334
|
}
|
|
318
335
|
if (isFirstRegistration) {
|
|
319
336
|
providers.push(...buildFacadePublisherProvider(OutboxModule_1));
|
|
320
337
|
providers.push(buildProcessingBundleProvider(OutboxModule_1));
|
|
321
|
-
providers.push(
|
|
338
|
+
providers.push(OutboxListenerScanner);
|
|
322
339
|
providers.push(...buildMultiDsRegistrarProviders());
|
|
323
|
-
exportTokens.push(
|
|
324
|
-
exportTokens.push(
|
|
325
|
-
exportTokens.push(
|
|
326
|
-
exportTokens.push(
|
|
340
|
+
exportTokens.push(OutboxEventPublisher);
|
|
341
|
+
exportTokens.push(OUTBOX_PROCESSING_BUNDLE);
|
|
342
|
+
exportTokens.push(MultiDsOutboxListenerRegistrar);
|
|
343
|
+
exportTokens.push(OUTBOX_LISTENER_REGISTRAR_TOKEN);
|
|
327
344
|
}
|
|
328
345
|
return {
|
|
329
346
|
module: OutboxModule_1,
|
|
330
347
|
global: options.isGlobal ?? true,
|
|
331
|
-
imports: [
|
|
348
|
+
imports: [DiscoveryModule, ...(options.imports ?? [])],
|
|
332
349
|
providers,
|
|
333
350
|
exports: exportTokens,
|
|
334
351
|
};
|
|
@@ -379,16 +396,16 @@ let OutboxModule = class OutboxModule {
|
|
|
379
396
|
}
|
|
380
397
|
return true;
|
|
381
398
|
},
|
|
382
|
-
inject: [
|
|
399
|
+
inject: [getEventTypeRegistryToken(dataSource)],
|
|
383
400
|
},
|
|
384
401
|
],
|
|
385
402
|
};
|
|
386
403
|
}
|
|
387
404
|
};
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
(0, common_1.Module)({})
|
|
405
|
+
OutboxModule = OutboxModule_1 = __decorate([
|
|
406
|
+
Module({})
|
|
391
407
|
], OutboxModule);
|
|
408
|
+
export { OutboxModule };
|
|
392
409
|
// ---------------------------------------------------------------------------
|
|
393
410
|
// Per-dataSource provider helpers
|
|
394
411
|
// ---------------------------------------------------------------------------
|
|
@@ -413,15 +430,21 @@ function perDsRetrySchedulerToken(ds) {
|
|
|
413
430
|
function perDsRetryConfigToken(ds) {
|
|
414
431
|
return `${ds}OutboxRetryConfig`;
|
|
415
432
|
}
|
|
416
|
-
function
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
const
|
|
433
|
+
function perDsCleanupSchedulerToken(ds) {
|
|
434
|
+
return `${ds}OutboxCleanupScheduler`;
|
|
435
|
+
}
|
|
436
|
+
function perDsCleanupConfigToken(ds) {
|
|
437
|
+
return `${ds}OutboxCleanupConfig`;
|
|
438
|
+
}
|
|
439
|
+
function buildPerDataSourceProviders(ds, repository, serializer, processorOpts, stalenessCfg, recoveryOpts, retryCfg, cleanupCfg) {
|
|
440
|
+
const eventTypeRegistryToken = getEventTypeRegistryToken(ds);
|
|
441
|
+
const repositoryToken = getEventPublicationRepositoryToken(ds);
|
|
442
|
+
const serializerToken = getOutboxEventSerializerToken(ds);
|
|
443
|
+
const listenerRegistryToken = getOutboxListenerRegistryToken(ds);
|
|
444
|
+
const publicationRegistryToken = getEventPublicationRegistryToken(ds);
|
|
445
|
+
const externalizationRegistryToken = getExternalizationRegistryToken(ds);
|
|
446
|
+
const processorToken = getEventPublicationProcessorToken(ds);
|
|
447
|
+
const publisherToken = getOutboxPublisherToken(ds);
|
|
425
448
|
const stalenessToken = perDsStalenessMonitorToken(ds);
|
|
426
449
|
const recoveryToken = perDsStartupRecoveryToken(ds);
|
|
427
450
|
const processorOptionsToken = perDsProcessorOptionsToken(ds);
|
|
@@ -429,51 +452,53 @@ function buildPerDataSourceProviders(ds, repository, serializer, processorOpts,
|
|
|
429
452
|
const recoveryOptionsToken = perDsRecoveryOptionsToken(ds);
|
|
430
453
|
const retryToken = perDsRetrySchedulerToken(ds);
|
|
431
454
|
const retryConfigToken = perDsRetryConfigToken(ds);
|
|
455
|
+
const cleanupToken = perDsCleanupSchedulerToken(ds);
|
|
456
|
+
const cleanupConfigToken = perDsCleanupConfigToken(ds);
|
|
432
457
|
return [
|
|
433
458
|
{
|
|
434
459
|
provide: eventTypeRegistryToken,
|
|
435
|
-
useFactory: () => new
|
|
460
|
+
useFactory: () => new EventTypeRegistry(),
|
|
436
461
|
},
|
|
437
462
|
repository
|
|
438
463
|
? reBindProvider(repository, repositoryToken)
|
|
439
|
-
: { provide: repositoryToken, useClass:
|
|
464
|
+
: { provide: repositoryToken, useClass: InMemoryEventPublicationRepository },
|
|
440
465
|
serializer
|
|
441
466
|
? reBindProvider(serializer, serializerToken)
|
|
442
467
|
: {
|
|
443
468
|
provide: serializerToken,
|
|
444
|
-
useFactory: (registry) => new
|
|
469
|
+
useFactory: (registry) => new JsonEventSerializer(registry),
|
|
445
470
|
inject: [eventTypeRegistryToken],
|
|
446
471
|
},
|
|
447
472
|
{
|
|
448
473
|
provide: listenerRegistryToken,
|
|
449
|
-
useFactory: () => new
|
|
474
|
+
useFactory: () => new OutboxListenerRegistry(),
|
|
450
475
|
},
|
|
451
476
|
{
|
|
452
477
|
provide: publicationRegistryToken,
|
|
453
|
-
useFactory: (repo, s) => new
|
|
478
|
+
useFactory: (repo, s) => new EventPublicationRegistry(repo, s),
|
|
454
479
|
inject: [repositoryToken, serializerToken],
|
|
455
480
|
},
|
|
456
481
|
{
|
|
457
482
|
provide: externalizationRegistryToken,
|
|
458
|
-
useFactory: (etr) => new
|
|
483
|
+
useFactory: (etr) => new ExternalizationRegistry(etr),
|
|
459
484
|
inject: [eventTypeRegistryToken],
|
|
460
485
|
},
|
|
461
486
|
{ provide: processorOptionsToken, useValue: processorOpts },
|
|
462
487
|
{
|
|
463
488
|
provide: processorToken,
|
|
464
|
-
useFactory: (registry, listeners, opts, externalizer, externalizationRegistry) => new
|
|
489
|
+
useFactory: (registry, listeners, opts, externalizer, externalizationRegistry) => new EventPublicationProcessor(registry, listeners, opts, externalizer, externalizationRegistry),
|
|
465
490
|
inject: [
|
|
466
491
|
publicationRegistryToken,
|
|
467
492
|
listenerRegistryToken,
|
|
468
493
|
processorOptionsToken,
|
|
469
|
-
{ token:
|
|
494
|
+
{ token: EVENT_EXTERNALIZER, optional: true },
|
|
470
495
|
externalizationRegistryToken,
|
|
471
496
|
],
|
|
472
497
|
},
|
|
473
498
|
{ provide: stalenessConfigToken, useValue: stalenessCfg },
|
|
474
499
|
{
|
|
475
500
|
provide: stalenessToken,
|
|
476
|
-
useFactory: (repo, cfg) => new
|
|
501
|
+
useFactory: (repo, cfg) => new StalenessMonitor(repo, cfg),
|
|
477
502
|
inject: [repositoryToken, stalenessConfigToken],
|
|
478
503
|
},
|
|
479
504
|
{ provide: retryConfigToken, useValue: retryCfg },
|
|
@@ -482,9 +507,15 @@ function buildPerDataSourceProviders(ds, repository, serializer, processorOpts,
|
|
|
482
507
|
useFactory: (repo, cfg) =>
|
|
483
508
|
// Built on a per-DS `FailedEventPublications` rather than the
|
|
484
509
|
// class-token one, which is bound to the default dataSource.
|
|
485
|
-
new
|
|
510
|
+
new OutboxRetryScheduler(new FailedEventPublications(repo), cfg),
|
|
486
511
|
inject: [repositoryToken, retryConfigToken],
|
|
487
512
|
},
|
|
513
|
+
{ provide: cleanupConfigToken, useValue: cleanupCfg },
|
|
514
|
+
{
|
|
515
|
+
provide: cleanupToken,
|
|
516
|
+
useFactory: (repo, cfg) => new OutboxCleanupScheduler(repo, cfg),
|
|
517
|
+
inject: [repositoryToken, cleanupConfigToken],
|
|
518
|
+
},
|
|
488
519
|
{ provide: recoveryOptionsToken, useValue: recoveryOpts },
|
|
489
520
|
// StartupRecoveryService for non-default dataSources alias to the
|
|
490
521
|
// class-token instance registered by the default-DS forRoot. The
|
|
@@ -494,24 +525,24 @@ function buildPerDataSourceProviders(ds, repository, serializer, processorOpts,
|
|
|
494
525
|
// need a per-DS StartupRecoveryService class; deferred to a later
|
|
495
526
|
// phase when multi-DS recovery is exercised. Today's behaviour:
|
|
496
527
|
// recovery runs on the default-DS only.
|
|
497
|
-
{ provide: recoveryToken, useExisting:
|
|
528
|
+
{ provide: recoveryToken, useExisting: StartupRecoveryService },
|
|
498
529
|
{
|
|
499
530
|
provide: publisherToken,
|
|
500
|
-
useFactory: (publicationRegistry, listenerRegistry) => new
|
|
531
|
+
useFactory: (publicationRegistry, listenerRegistry) => new DataSourceOutboxPublisher(ds, publicationRegistry, listenerRegistry),
|
|
501
532
|
inject: [publicationRegistryToken, listenerRegistryToken],
|
|
502
533
|
},
|
|
503
534
|
];
|
|
504
535
|
}
|
|
505
536
|
function perDataSourceExports(ds) {
|
|
506
537
|
return [
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
538
|
+
getEventTypeRegistryToken(ds),
|
|
539
|
+
getEventPublicationRepositoryToken(ds),
|
|
540
|
+
getOutboxEventSerializerToken(ds),
|
|
541
|
+
getOutboxListenerRegistryToken(ds),
|
|
542
|
+
getEventPublicationRegistryToken(ds),
|
|
543
|
+
getExternalizationRegistryToken(ds),
|
|
544
|
+
getEventPublicationProcessorToken(ds),
|
|
545
|
+
getOutboxPublisherToken(ds),
|
|
515
546
|
];
|
|
516
547
|
}
|
|
517
548
|
/**
|
|
@@ -525,38 +556,39 @@ function perDataSourceExports(ds) {
|
|
|
525
556
|
function buildDefaultDataSourceAliases() {
|
|
526
557
|
const ds = DEFAULT_DATA_SOURCE;
|
|
527
558
|
return [
|
|
528
|
-
{ provide:
|
|
529
|
-
{ provide:
|
|
530
|
-
{ provide:
|
|
531
|
-
{ provide:
|
|
532
|
-
{ provide:
|
|
533
|
-
{ provide:
|
|
534
|
-
{ provide:
|
|
535
|
-
{ provide:
|
|
536
|
-
{ provide:
|
|
537
|
-
{ provide:
|
|
538
|
-
{ provide:
|
|
539
|
-
{ provide:
|
|
540
|
-
{ provide:
|
|
541
|
-
{ provide:
|
|
559
|
+
{ provide: EVENT_TYPE_REGISTRY, useExisting: getEventTypeRegistryToken(ds) },
|
|
560
|
+
{ provide: EventTypeRegistry, useExisting: getEventTypeRegistryToken(ds) },
|
|
561
|
+
{ provide: EVENT_SERIALIZER, useExisting: getOutboxEventSerializerToken(ds) },
|
|
562
|
+
{ provide: EVENT_PUBLICATION_REPOSITORY, useExisting: getEventPublicationRepositoryToken(ds) },
|
|
563
|
+
{ provide: OutboxListenerRegistry, useExisting: getOutboxListenerRegistryToken(ds) },
|
|
564
|
+
{ provide: EventPublicationRegistry, useExisting: getEventPublicationRegistryToken(ds) },
|
|
565
|
+
{ provide: ExternalizationRegistry, useExisting: getExternalizationRegistryToken(ds) },
|
|
566
|
+
{ provide: EventPublicationProcessor, useExisting: getEventPublicationProcessorToken(ds) },
|
|
567
|
+
{ provide: StalenessMonitor, useExisting: perDsStalenessMonitorToken(ds) },
|
|
568
|
+
{ provide: OutboxRetryScheduler, useExisting: perDsRetrySchedulerToken(ds) },
|
|
569
|
+
{ provide: OutboxCleanupScheduler, useExisting: perDsCleanupSchedulerToken(ds) },
|
|
570
|
+
{ provide: OUTBOX_PROCESSOR_OPTIONS, useExisting: perDsProcessorOptionsToken(ds) },
|
|
571
|
+
{ provide: OUTBOX_STALENESS_CONFIG, useExisting: perDsStalenessConfigToken(ds) },
|
|
572
|
+
{ provide: OUTBOX_RETRY_CONFIG, useExisting: perDsRetryConfigToken(ds) },
|
|
573
|
+
{ provide: OUTBOX_RECOVERY_OPTIONS, useExisting: perDsRecoveryOptionsToken(ds) },
|
|
542
574
|
];
|
|
543
575
|
}
|
|
544
576
|
function defaultDataSourceAliasTokens() {
|
|
545
577
|
return [
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
578
|
+
EVENT_TYPE_REGISTRY,
|
|
579
|
+
EventTypeRegistry,
|
|
580
|
+
EVENT_SERIALIZER,
|
|
581
|
+
EVENT_PUBLICATION_REPOSITORY,
|
|
582
|
+
OutboxListenerRegistry,
|
|
583
|
+
EventPublicationRegistry,
|
|
584
|
+
ExternalizationRegistry,
|
|
585
|
+
EventPublicationProcessor,
|
|
586
|
+
StalenessMonitor,
|
|
587
|
+
OutboxRetryScheduler,
|
|
588
|
+
OUTBOX_PROCESSOR_OPTIONS,
|
|
589
|
+
OUTBOX_STALENESS_CONFIG,
|
|
590
|
+
OUTBOX_RETRY_CONFIG,
|
|
591
|
+
OUTBOX_RECOVERY_OPTIONS,
|
|
560
592
|
];
|
|
561
593
|
}
|
|
562
594
|
/**
|
|
@@ -570,9 +602,9 @@ function defaultDataSourceAliasTokens() {
|
|
|
570
602
|
*/
|
|
571
603
|
function buildFacadePublisherProvider(moduleClass) {
|
|
572
604
|
return [
|
|
573
|
-
|
|
605
|
+
OutboxEventPublisher,
|
|
574
606
|
{
|
|
575
|
-
provide:
|
|
607
|
+
provide: OUTBOX_DATA_SOURCE_NAMES,
|
|
576
608
|
useValue: privateRegistrations(moduleClass),
|
|
577
609
|
},
|
|
578
610
|
];
|
|
@@ -594,10 +626,10 @@ function buildFacadePublisherProvider(moduleClass) {
|
|
|
594
626
|
*/
|
|
595
627
|
function buildMultiDsRegistrarProviders() {
|
|
596
628
|
return [
|
|
597
|
-
|
|
629
|
+
MultiDsOutboxListenerRegistrar,
|
|
598
630
|
{
|
|
599
|
-
provide:
|
|
600
|
-
useExisting:
|
|
631
|
+
provide: OUTBOX_LISTENER_REGISTRAR_TOKEN,
|
|
632
|
+
useExisting: MultiDsOutboxListenerRegistrar,
|
|
601
633
|
},
|
|
602
634
|
];
|
|
603
635
|
}
|
|
@@ -610,7 +642,7 @@ function buildMultiDsRegistrarProviders() {
|
|
|
610
642
|
*/
|
|
611
643
|
function buildProcessingBundleProvider(moduleClass) {
|
|
612
644
|
return {
|
|
613
|
-
provide:
|
|
645
|
+
provide: OUTBOX_PROCESSING_BUNDLE,
|
|
614
646
|
useFactory: (moduleRef) => {
|
|
615
647
|
const dsNames = Array.from(privateRegistrations(moduleClass).keys());
|
|
616
648
|
// Resolve lazily by capturing dsNames + moduleRef in closure. The
|
|
@@ -620,7 +652,7 @@ function buildProcessingBundleProvider(moduleClass) {
|
|
|
620
652
|
const get = (token) => moduleRef.get(token, { strict: false });
|
|
621
653
|
return {
|
|
622
654
|
get processors() {
|
|
623
|
-
return dsNames.map((ds) => get(
|
|
655
|
+
return dsNames.map((ds) => get(getEventPublicationProcessorToken(ds)));
|
|
624
656
|
},
|
|
625
657
|
get monitors() {
|
|
626
658
|
return dsNames.map((ds) => get(perDsStalenessMonitorToken(ds)));
|
|
@@ -628,12 +660,15 @@ function buildProcessingBundleProvider(moduleClass) {
|
|
|
628
660
|
get retrySchedulers() {
|
|
629
661
|
return dsNames.map((ds) => get(perDsRetrySchedulerToken(ds)));
|
|
630
662
|
},
|
|
663
|
+
get cleanupSchedulers() {
|
|
664
|
+
return dsNames.map((ds) => get(perDsCleanupSchedulerToken(ds)));
|
|
665
|
+
},
|
|
631
666
|
get recoveryServices() {
|
|
632
667
|
return dsNames.map((ds) => get(perDsStartupRecoveryToken(ds)));
|
|
633
668
|
},
|
|
634
669
|
};
|
|
635
670
|
},
|
|
636
|
-
inject: [
|
|
671
|
+
inject: [ModuleRef],
|
|
637
672
|
};
|
|
638
673
|
}
|
|
639
674
|
/**
|
|
@@ -653,6 +688,5 @@ function privateRegistrations(moduleClass) {
|
|
|
653
688
|
// no longer used directly in this file (the per-DS
|
|
654
689
|
// publisher pushes hooks directly onto the active-transaction object,
|
|
655
690
|
// bypassing manager.registerBeforeCommit's single-tx assumption).
|
|
656
|
-
|
|
657
|
-
const _txManagerRef = core_2.TransactionManager;
|
|
691
|
+
const _txManagerRef = TransactionManager;
|
|
658
692
|
//# sourceMappingURL=outbox.module.js.map
|