Skip to content

Commit 0353847

Browse files
committed
AP-5046 WIP prisma adapter.
1 parent c46d63f commit 0353847

File tree

7 files changed

+179
-0
lines changed

7 files changed

+179
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# outbox-core
2+
3+
Main package that contains the core functionality of the Outbox pattern to provide "at least once" delivery semantics for messages.
4+
5+
## Installation
6+
7+
```bash
8+
npm i -S @message-queue-toolkit/outbox-core
9+
```
10+
11+
## Usage
12+
13+
To process outbox entries and emit them to the message queue, you need to create an instance of the `OutboxPeriodicJob` class:
14+
15+
```typescript
16+
import { OutboxPeriodicJob } from '@message-queue-toolkit/outbox-core';
17+
18+
const job = new OutboxPeriodicJob(
19+
//Implementation of OutboxStorage interface, TODO: Point to other packages in message-queue-toolkit
20+
outboxStorage,
21+
//Default available accumulator for gathering outbox entries as the process job is progressing.
22+
new InMemoryOutboxAccumulator(),
23+
//DomainEventEmitter, it will be used to publish events, see @message-queue-toolkit/core
24+
eventEmitter,
25+
//See PeriodicJobDependencies from @lokalise/background-jobs-common
26+
dependencies,
27+
//Retry count, how many times outbox entries should be retried to be processed
28+
3,
29+
//emitBatchSize - how many outbox entries should be emitted at once
30+
10,
31+
//internalInMs - how often the job should be executed, e.g. below it runs every 1sec
32+
1000
33+
)
34+
```
35+
36+
Job will take care of processing outbox entries emitted by:
37+
```typescript
38+
const emitter = new OutboxEventEmitter(
39+
//Same instance of outbox storage that is used by OutboxPeriodicJob
40+
outboxStorage
41+
)
42+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/outbox-prisma-adapter'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { OutboxAccumulator, OutboxEntry } from '@message-queue-toolkit/outbox-core'
2+
import type { OutboxStorage } from '@message-queue-toolkit/outbox-core/dist/lib/storage'
3+
import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
4+
5+
export class OutboxPrismaAdapter<SupportedEvents extends CommonEventDefinition[]>
6+
implements OutboxStorage<SupportedEvents>
7+
{
8+
createEntry(
9+
outboxEntry: OutboxEntry<SupportedEvents[number]>,
10+
): Promise<OutboxEntry<SupportedEvents[number]>> {
11+
return Promise.resolve(undefined)
12+
}
13+
14+
flush(outboxAccumulator: OutboxAccumulator<SupportedEvents>): Promise<void> {
15+
return Promise.resolve(undefined)
16+
}
17+
18+
getEntries(maxRetryCount: number): Promise<OutboxEntry<SupportedEvents[number]>[]> {
19+
return Promise.resolve([])
20+
}
21+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "@message-queue-toolkit/outbox-prisma-adapter",
3+
"version": "0.1.0",
4+
"private": false,
5+
"license": "MIT",
6+
"description": "OutboxStorage implementation for @message-queue-toolkit/outbox-core package.",
7+
"maintainers": [
8+
{
9+
"name": "Igor Savin",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"main": "dist/index.js",
14+
"types": "dist/index.d.ts",
15+
"scripts": {
16+
"build": "del-cli dist && tsc",
17+
"build:release": "del-cli dist && del-cli coverage && npm run lint && tsc --project tsconfig.release.json",
18+
"test": "vitest",
19+
"test:coverage": "npm test -- --coverage",
20+
"test:ci": "npm run docker:start:dev && npm run test:coverage && npm run docker:stop:dev",
21+
"lint": "biome check . && tsc --project tsconfig.json --noEmit",
22+
"lint:fix": "biome check --write .",
23+
"docker:start:dev": "docker compose up -d",
24+
"docker:stop:dev": "docker compose down",
25+
"prepublishOnly": "npm run build:release"
26+
},
27+
"dependencies": {},
28+
"peerDependencies": {
29+
"@message-queue-toolkit/core": ">=14.0.0",
30+
"@message-queue-toolkit/schemas": ">=4.0.0",
31+
"@message-queue-toolkit/outbox-core": ">=0.1.0"
32+
},
33+
"devDependencies": {
34+
"@biomejs/biome": "1.8.3",
35+
"@kibertoad/biome-config": "^1.2.1",
36+
"@types/node": "^22.0.0",
37+
"@vitest/coverage-v8": "^2.0.4",
38+
"del-cli": "^5.1.0",
39+
"typescript": "^5.5.3",
40+
"vitest": "^2.0.4",
41+
"zod": "^3.23.8"
42+
},
43+
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
44+
"repository": {
45+
"type": "git",
46+
"url": "git://github.com/kibertoad/message-queue-toolkit.git"
47+
},
48+
"keywords": [
49+
"message",
50+
"queue",
51+
"queues",
52+
"abstract",
53+
"common",
54+
"utils",
55+
"notification",
56+
"outbox",
57+
"pattern"
58+
],
59+
"files": ["README.md", "LICENSE", "dist/*"]
60+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"module": "commonjs",
5+
"target": "ES2022",
6+
"lib": ["ES2022", "dom"],
7+
"sourceMap": true,
8+
"declaration": true,
9+
"declarationMap": false,
10+
"types": ["node", "vitest/globals"],
11+
"strict": true,
12+
"moduleResolution": "node",
13+
"noUnusedLocals": false,
14+
"noUnusedParameters": false,
15+
"noFallthroughCasesInSwitch": true,
16+
"strictNullChecks": true,
17+
"importHelpers": true,
18+
"baseUrl": ".",
19+
"skipLibCheck": true,
20+
"allowSyntheticDefaultImports": true,
21+
"esModuleInterop": true,
22+
"forceConsistentCasingInFileNames": true,
23+
"resolveJsonModule": true
24+
},
25+
"include": ["lib/**/*.ts", "test/**/*.ts", "index.ts"],
26+
"exclude": ["node_modules", "dist"]
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["lib/**/*.ts", "index.ts"],
4+
"exclude": ["node_modules", "dist", "lib/**/*.spec.ts"]
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
watch: false,
7+
environment: 'node',
8+
reporters: ['default'],
9+
coverage: {
10+
provider: 'v8',
11+
include: ['lib/**/*.ts'],
12+
exclude: ['lib/**/*.spec.ts', 'lib/**/*.test.ts', 'test/**/*.*'],
13+
reporter: ['text'],
14+
all: true,
15+
thresholds: {
16+
lines: 100,
17+
functions: 100,
18+
branches: 91.66,
19+
statements: 100,
20+
},
21+
},
22+
},
23+
})

0 commit comments

Comments
 (0)