@@ -12,10 +12,9 @@ import {
12
12
import pino , { type Logger } from 'pino'
13
13
import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
14
14
import { z } from 'zod'
15
- import { InMemoryOutboxAccumulator , type OutboxAccumulator } from './accumulators'
16
- import type { OutboxEntry } from './objects'
17
- import { type OutboxDependencies , OutboxEventEmitter , OutboxProcessor } from './outbox'
18
- import type { OutboxStorage } from './storage'
15
+ import { InMemoryOutboxAccumulator } from '../lib/accumulators'
16
+ import { type OutboxDependencies , OutboxEventEmitter , OutboxProcessor } from '../lib/outbox'
17
+ import { InMemoryOutboxStorage } from './InMemoryOutboxStorage'
19
18
20
19
const TestEvents = {
21
20
created : {
@@ -54,76 +53,6 @@ const createdEventPayload: CommonEventDefinitionPublisherSchemaType<typeof TestE
54
53
55
54
const TestLogger : Logger = pino ( )
56
55
57
- class InMemoryOutboxStorage < SupportedEvents extends CommonEventDefinition [ ] >
58
- implements OutboxStorage < SupportedEvents >
59
- {
60
- public entries : OutboxEntry < SupportedEvents [ number ] > [ ] = [ ]
61
-
62
- createEntry (
63
- outboxEntry : OutboxEntry < SupportedEvents [ number ] > ,
64
- ) : Promise < OutboxEntry < SupportedEvents [ number ] > > {
65
- this . entries = [ ...this . entries , outboxEntry ]
66
-
67
- return Promise . resolve ( outboxEntry )
68
- }
69
-
70
- getEntries ( maxRetryCount : number ) : Promise < OutboxEntry < SupportedEvents [ number ] > [ ] > {
71
- const entries = this . entries . filter ( ( entry ) => {
72
- return entry . status !== 'SUCCESS' && entry . retryCount <= maxRetryCount
73
- } )
74
-
75
- return Promise . resolve ( entries )
76
- }
77
-
78
- update (
79
- outboxEntry : OutboxEntry < SupportedEvents [ number ] > ,
80
- ) : Promise < OutboxEntry < SupportedEvents [ number ] > > {
81
- this . entries = this . entries . map ( ( entry ) => {
82
- if ( entry . id === outboxEntry . id ) {
83
- return outboxEntry
84
- }
85
- return entry
86
- } )
87
-
88
- return Promise . resolve ( outboxEntry )
89
- }
90
-
91
- public async flush ( outboxAccumulator : OutboxAccumulator < SupportedEvents > ) : Promise < void > {
92
- let successEntries = await outboxAccumulator . getEntries ( )
93
- successEntries = successEntries . map ( ( entry ) => {
94
- return {
95
- ...entry ,
96
- status : 'SUCCESS' ,
97
- updateAt : new Date ( ) ,
98
- }
99
- } )
100
- this . entries = this . entries . map ( ( entry ) => {
101
- const foundEntry = successEntries . find ( ( successEntry ) => successEntry . id === entry . id )
102
- if ( foundEntry ) {
103
- return foundEntry
104
- }
105
- return entry
106
- } )
107
-
108
- let failedEntries = await outboxAccumulator . getFailedEntries ( )
109
- failedEntries = failedEntries . map ( ( entry ) => {
110
- return {
111
- ...entry ,
112
- status : 'FAILED' ,
113
- updateAt : new Date ( ) ,
114
- retryCount : entry . retryCount + 1 ,
115
- }
116
- } )
117
- this . entries = this . entries . map ( ( entry ) => {
118
- const foundEntry = failedEntries . find ( ( failedEntry ) => failedEntry . id === entry . id )
119
- if ( foundEntry ) {
120
- return foundEntry
121
- }
122
- return entry
123
- } )
124
- }
125
- }
126
-
127
56
const MAX_RETRY_COUNT = 2
128
57
129
58
describe ( 'outbox' , ( ) => {
0 commit comments