@prophet-ontology/events-runtime 0.1.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 +85 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +19 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @prophet-ontology/events-runtime
|
|
2
|
+
|
|
3
|
+
`@prophet-ontology/events-runtime` is the shared Node runtime contract used by Prophet-generated action services.
|
|
4
|
+
|
|
5
|
+
It defines:
|
|
6
|
+
- an async `EventPublisher` interface
|
|
7
|
+
- a canonical `EventWireEnvelope` shape
|
|
8
|
+
- utility helpers (`createEventId`, `nowIso`)
|
|
9
|
+
- a `NoOpEventPublisher` for local wiring and tests
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @prophet-ontology/events-runtime
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
export interface EventWireEnvelope {
|
|
21
|
+
event_id: string;
|
|
22
|
+
trace_id: string;
|
|
23
|
+
event_type: string;
|
|
24
|
+
schema_version: string;
|
|
25
|
+
occurred_at: string;
|
|
26
|
+
source: string;
|
|
27
|
+
payload: Record<string, unknown>;
|
|
28
|
+
attributes?: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface EventPublisher {
|
|
32
|
+
publish(envelope: EventWireEnvelope): Promise<void>;
|
|
33
|
+
publishBatch(envelopes: EventWireEnvelope[]): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Exports:
|
|
38
|
+
- `createEventId(): string`
|
|
39
|
+
- `nowIso(): string`
|
|
40
|
+
- `NoOpEventPublisher`
|
|
41
|
+
|
|
42
|
+
## Implement a Platform Publisher
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import type { EventPublisher, EventWireEnvelope } from "@prophet-ontology/events-runtime";
|
|
46
|
+
|
|
47
|
+
type PlatformClient = {
|
|
48
|
+
sendEvent(payload: unknown): Promise<void>;
|
|
49
|
+
sendEvents(payloads: unknown[]): Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export class PlatformEventPublisher implements EventPublisher {
|
|
53
|
+
constructor(private readonly client: PlatformClient) {}
|
|
54
|
+
|
|
55
|
+
async publish(envelope: EventWireEnvelope): Promise<void> {
|
|
56
|
+
await this.client.sendEvent(envelope);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async publishBatch(envelopes: EventWireEnvelope[]): Promise<void> {
|
|
60
|
+
await this.client.sendEvents(envelopes);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## With Prophet-Generated Code
|
|
66
|
+
|
|
67
|
+
Generated Node action services call `publish`/`publishBatch` after successful handler execution.
|
|
68
|
+
If you do not provide an implementation, you can wire `NoOpEventPublisher` for local development.
|
|
69
|
+
|
|
70
|
+
## Local Validation
|
|
71
|
+
|
|
72
|
+
From repository root:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm --prefix prophet-lib/javascript test
|
|
76
|
+
npm --prefix prophet-lib/javascript pack --dry-run
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## More Information
|
|
80
|
+
|
|
81
|
+
- Runtime index: https://github.com/Chainso/prophet/tree/main/prophet-lib
|
|
82
|
+
- Event wire contract: https://github.com/Chainso/prophet/tree/main/prophet-lib/specs/wire-contract.md
|
|
83
|
+
- Event wire JSON schema: https://github.com/Chainso/prophet/tree/main/prophet-lib/specs/wire-event-envelope.schema.json
|
|
84
|
+
- Node/Express reference: https://github.com/Chainso/prophet/tree/main/docs/reference/node-express.md
|
|
85
|
+
- Example app: https://github.com/Chainso/prophet/tree/main/examples/node/prophet_example_express_prisma
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface EventWireEnvelope {
|
|
2
|
+
event_id: string;
|
|
3
|
+
trace_id: string;
|
|
4
|
+
event_type: string;
|
|
5
|
+
schema_version: string;
|
|
6
|
+
occurred_at: string;
|
|
7
|
+
source: string;
|
|
8
|
+
payload: Record<string, unknown>;
|
|
9
|
+
attributes?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface EventPublisher {
|
|
13
|
+
publish(envelope: EventWireEnvelope): Promise<void>;
|
|
14
|
+
publishBatch(envelopes: EventWireEnvelope[]): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare function createEventId(): string;
|
|
18
|
+
export declare function nowIso(): string;
|
|
19
|
+
|
|
20
|
+
export declare class NoOpEventPublisher implements EventPublisher {
|
|
21
|
+
publish(envelope: EventWireEnvelope): Promise<void>;
|
|
22
|
+
publishBatch(envelopes: EventWireEnvelope[]): Promise<void>;
|
|
23
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export function createEventId() {
|
|
4
|
+
return randomUUID();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function nowIso() {
|
|
8
|
+
return new Date().toISOString();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class NoOpEventPublisher {
|
|
12
|
+
async publish(_envelope) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async publishBatch(_envelopes) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prophet-ontology/events-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node --test"
|
|
19
|
+
}
|
|
20
|
+
}
|