@fonderie/events 1.0.1 → 1.0.3
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.
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/events — outcomes
|
|
4
|
+
|
|
5
|
+
What this package does to a running app: tables its migrations create,
|
|
6
|
+
rows it seeds, routes it registers. Generated from the migration SQL and
|
|
7
|
+
route tables in source — trust this file instead of reading `dist/` or
|
|
8
|
+
downloading tarballs.
|
|
9
|
+
|
|
10
|
+
## Database tables (after all migrations)
|
|
11
|
+
|
|
12
|
+
### `fonderie_event_consumers`
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
event_id UUID NOT NULL REFERENCES fonderie_events(id) ON DELETE CASCADE
|
|
16
|
+
consumer TEXT NOT NULL
|
|
17
|
+
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed', 'dead'))
|
|
18
|
+
attempts INT NOT NULL DEFAULT 0
|
|
19
|
+
error TEXT
|
|
20
|
+
processed_at TIMESTAMPTZ
|
|
21
|
+
-- PRIMARY KEY (event_id, consumer)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### `fonderie_events`
|
|
25
|
+
|
|
26
|
+
```sql
|
|
27
|
+
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid()
|
|
28
|
+
type TEXT NOT NULL
|
|
29
|
+
payload JSONB NOT NULL DEFAULT '{}'
|
|
30
|
+
meta JSONB NOT NULL DEFAULT '{}'
|
|
31
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Raw SQL ships in `node_modules/@fonderie/events/dist/migrations/sql/` — read it there if you must; never download tarballs.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/events — signatures
|
|
4
|
+
|
|
5
|
+
## @fonderie/events
|
|
6
|
+
|
|
7
|
+
Subpath exports: `@fonderie/events/migrations`
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
new EventBus(transport: IEventTransport): EventBus
|
|
11
|
+
.emit<T = unknown>(type: string, payload: T, opts?: { requestId?: string; } | undefined): Promise<void>
|
|
12
|
+
.on<T = unknown>(type: string, handler: IEventHandler<T>, consumer?: string): void
|
|
13
|
+
.start(): Promise<void>
|
|
14
|
+
.stop(): Promise<void>
|
|
15
|
+
|
|
16
|
+
new EventsModule(config: IEventsConfig): EventsModule
|
|
17
|
+
.name: "@fonderie/events"
|
|
18
|
+
.bus: EventBus
|
|
19
|
+
.install(_app: IFonderieApp): void
|
|
20
|
+
|
|
21
|
+
interface IEventsConfig {
|
|
22
|
+
transport: EventTransportConfig;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type EventTransportConfig = {
|
|
26
|
+
type: 'pg';
|
|
27
|
+
connectionUrl: string;
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
batchSize?: number;
|
|
30
|
+
pollInterval?: number;
|
|
31
|
+
} | IEventTransport;
|
|
32
|
+
|
|
33
|
+
new MemoryTransport(): MemoryTransport
|
|
34
|
+
.publish(type: string, payload: unknown, meta: IEventMeta): Promise<void>
|
|
35
|
+
.subscribe(pattern: string, handler: IEventHandler, _consumer: string): void
|
|
36
|
+
.start(): Promise<void>
|
|
37
|
+
.stop(): Promise<void>
|
|
38
|
+
|
|
39
|
+
new PGTransport(config: IPGTransportConfig): PGTransport
|
|
40
|
+
.subscribe(pattern: string, handler: IEventHandler, consumer: string): void
|
|
41
|
+
.publish(type: string, payload: unknown, meta: IEventMeta): Promise<void>
|
|
42
|
+
.start(): Promise<void>
|
|
43
|
+
.stop(): Promise<void>
|
|
44
|
+
|
|
45
|
+
interface IEventTransport {
|
|
46
|
+
publish(type: string, payload: unknown, meta: IEventMeta): Promise<void>;
|
|
47
|
+
subscribe(type: string, handler: IEventHandler, consumer: string): void;
|
|
48
|
+
start(): Promise<void>;
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface IPGTransportConfig {
|
|
53
|
+
connectionUrl: string;
|
|
54
|
+
maxRetries?: number;
|
|
55
|
+
batchSize?: number;
|
|
56
|
+
pollInterval?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function matchesPattern(pattern: string, eventType: string): boolean
|
|
60
|
+
|
|
61
|
+
interface IEventMeta {
|
|
62
|
+
id: string;
|
|
63
|
+
type: string;
|
|
64
|
+
emittedAt: string;
|
|
65
|
+
attempts: number;
|
|
66
|
+
requestId?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type IEventHandler<T = unknown> = (payload: T, meta: IEventMeta) => Promise<void>;
|
|
70
|
+
|
|
71
|
+
interface IEventRecord {
|
|
72
|
+
id: string;
|
|
73
|
+
type: string;
|
|
74
|
+
payload: Record<string, unknown>;
|
|
75
|
+
meta: IEventMeta;
|
|
76
|
+
created_at: Date;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface IConsumerRecord {
|
|
80
|
+
event_id: string;
|
|
81
|
+
consumer: string;
|
|
82
|
+
status: 'pending' | 'processing' | 'processed' | 'failed' | 'dead';
|
|
83
|
+
attempts: number;
|
|
84
|
+
error: string | null;
|
|
85
|
+
processed_at: Date | null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const NOTIFICATION_EVENT: "fonderie.notification.send"
|
|
89
|
+
|
|
90
|
+
type NotificationEvent = typeof NOTIFICATION_EVENT;
|
|
91
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS fonderie_events (
|
|
2
|
+
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3
|
+
type TEXT NOT NULL,
|
|
4
|
+
payload JSONB NOT NULL DEFAULT '{}',
|
|
5
|
+
meta JSONB NOT NULL DEFAULT '{}',
|
|
6
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
CREATE INDEX IF NOT EXISTS fonderie_events_created_idx
|
|
10
|
+
ON fonderie_events (created_at);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- Drop mutable delivery columns from fonderie_events (no-op on fresh installs)
|
|
2
|
+
ALTER TABLE fonderie_events
|
|
3
|
+
DROP COLUMN IF EXISTS status,
|
|
4
|
+
DROP COLUMN IF EXISTS attempts,
|
|
5
|
+
DROP COLUMN IF EXISTS error,
|
|
6
|
+
DROP COLUMN IF EXISTS processed_at;
|
|
7
|
+
|
|
8
|
+
DROP INDEX IF EXISTS fonderie_events_status_idx;
|
|
9
|
+
|
|
10
|
+
-- Per-consumer delivery tracking
|
|
11
|
+
CREATE TABLE IF NOT EXISTS fonderie_event_consumers (
|
|
12
|
+
event_id UUID NOT NULL REFERENCES fonderie_events(id) ON DELETE CASCADE,
|
|
13
|
+
consumer TEXT NOT NULL,
|
|
14
|
+
status TEXT NOT NULL DEFAULT 'pending'
|
|
15
|
+
CHECK (status IN ('pending', 'processing', 'processed', 'failed', 'dead')),
|
|
16
|
+
attempts INT NOT NULL DEFAULT 0,
|
|
17
|
+
error TEXT,
|
|
18
|
+
processed_at TIMESTAMPTZ,
|
|
19
|
+
PRIMARY KEY (event_id, consumer)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
-- Partial index — each consumer's poll touches only its own pending rows
|
|
23
|
+
CREATE INDEX IF NOT EXISTS fonderie_event_consumers_poll_idx
|
|
24
|
+
ON fonderie_event_consumers (consumer, status, event_id)
|
|
25
|
+
WHERE status IN ('pending', 'failed');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/events",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Event bus for @fonderie-js — memory and PostgreSQL transports built-in, adapter interface for Redis/Kafka/RabbitMQ.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fonderie-js",
|
|
@@ -66,16 +66,17 @@
|
|
|
66
66
|
},
|
|
67
67
|
"files": [
|
|
68
68
|
"dist",
|
|
69
|
+
"brain",
|
|
69
70
|
"LICENSE",
|
|
70
71
|
"README.md"
|
|
71
72
|
],
|
|
72
73
|
"repository": {
|
|
73
74
|
"type": "git",
|
|
74
|
-
"url": "git+https://github.com/
|
|
75
|
+
"url": "git+https://github.com/fonderiejs/sdk.git",
|
|
75
76
|
"directory": "packages/events"
|
|
76
77
|
},
|
|
77
|
-
"homepage": "https://github.com/
|
|
78
|
+
"homepage": "https://github.com/fonderiejs/sdk/tree/main/packages/events#readme",
|
|
78
79
|
"bugs": {
|
|
79
|
-
"url": "https://github.com/
|
|
80
|
+
"url": "https://github.com/fonderiejs/sdk/issues"
|
|
80
81
|
}
|
|
81
82
|
}
|