Skip to content

Commit e93bdad

Browse files
committed
WIP
1 parent d55405e commit e93bdad

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

packages/outbox-prisma-adapter/lib/outbox-prisma-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OutboxAccumulator, OutboxEntry } from '@message-queue-toolkit/outbox-core'
22
import type { OutboxStorage } from '@message-queue-toolkit/outbox-core/dist/lib/storage'
3-
import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
3+
import { type CommonEventDefinition, getMessageType } from '@message-queue-toolkit/schemas'
44
import type { PrismaClient } from '@prisma/client'
55

66
export class OutboxPrismaAdapter<SupportedEvents extends CommonEventDefinition[]>
@@ -17,7 +17,7 @@ export class OutboxPrismaAdapter<SupportedEvents extends CommonEventDefinition[]
1717
const prismaModel: PrismaClient[typeof this.modelName] = this.prisma[this.modelName]
1818

1919
return prismaModel.create({
20-
data: outboxEntry,
20+
data: getMessageType(outboxEntry.event),
2121
})
2222
}
2323

packages/outbox-prisma-adapter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"del-cli": "^5.1.0",
3939
"prisma": "^5.19.1",
4040
"typescript": "^5.5.3",
41+
"uuidv7": "^1.0.2",
4142
"vitest": "^2.0.4",
4243
"zod": "^3.23.8"
4344
},

packages/outbox-prisma-adapter/test/outbox-prisma-adapter.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1+
import type { OutboxEntry } from '@message-queue-toolkit/outbox-core'
2+
import {
3+
type CommonEventDefinition,
4+
enrichMessageSchemaWithBase,
5+
} from '@message-queue-toolkit/schemas'
16
import { PrismaClient } from '@prisma/client'
7+
import { uuidv7 } from 'uuidv7'
28
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
9+
import { z } from 'zod'
10+
import { OutboxPrismaAdapter } from '../lib/outbox-prisma-adapter'
11+
12+
const events = {
13+
created: {
14+
...enrichMessageSchemaWithBase(
15+
'entity.created',
16+
z.object({
17+
message: z.string(),
18+
}),
19+
),
20+
},
21+
} satisfies Record<string, CommonEventDefinition>
22+
23+
type SupportedEvents = (typeof events)[keyof typeof events][]
324

425
describe('outbox-prisma-adapter', () => {
526
let prisma: PrismaClient
27+
let outboxPrismaAdapter: OutboxPrismaAdapter<SupportedEvents>
628

729
beforeAll(async () => {
830
prisma = new PrismaClient()
931

32+
outboxPrismaAdapter = new OutboxPrismaAdapter<SupportedEvents>(prisma, 'OutboxEntry')
33+
1034
await prisma.$queryRaw`create schema if not exists prisma;`
1135
await prisma.$queryRaw`
1236
CREATE TABLE prisma.outbox_entry (
@@ -39,4 +63,20 @@ describe('outbox-prisma-adapter', () => {
3963
},
4064
])
4165
})
66+
67+
it('creates entry in DB via outbox storage implementation', async () => {
68+
await outboxPrismaAdapter.createEntry({
69+
id: uuidv7(),
70+
event: events.created,
71+
status: 'CREATED',
72+
data: {
73+
id: uuidv7(),
74+
payload: {
75+
message: 'TEST EVENT',
76+
},
77+
metadata: {},
78+
timestamp: new Date().toISOString(),
79+
},
80+
} satisfies OutboxEntry<SupportedEvents[number]>)
81+
})
4282
})

0 commit comments

Comments
 (0)