@relaybus/core 0.3.0 → 0.4.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 +6 -1
- package/dist/{chunk-3OHMEMZA.cjs → chunk-J76M7XTS.cjs} +127 -9
- package/dist/chunk-J76M7XTS.cjs.map +1 -0
- package/dist/{chunk-WS274DL3.js → chunk-NOR5JHVN.js} +121 -9
- package/dist/chunk-NOR5JHVN.js.map +1 -0
- package/dist/index.cjs +2301 -1903
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -475
- package/dist/index.d.ts +88 -475
- package/dist/index.js +2316 -1924
- package/dist/index.js.map +1 -1
- package/dist/internal/index.cjs +492 -140
- package/dist/internal/index.cjs.map +1 -1
- package/dist/internal/index.d.cts +321 -9
- package/dist/internal/index.d.ts +321 -9
- package/dist/internal/index.js +450 -124
- package/dist/internal/index.js.map +1 -1
- package/dist/transport-DIFdeXQY.d.cts +536 -0
- package/dist/transport-DIFdeXQY.d.ts +536 -0
- package/package.json +1 -1
- package/dist/chunk-3OHMEMZA.cjs.map +0 -1
- package/dist/chunk-WS274DL3.js.map +0 -1
- package/dist/event-DCRTuYKI.d.cts +0 -142
- package/dist/event-DCRTuYKI.d.ts +0 -142
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/** Source of the current time. Replace it in tests to control retries and leases. */
|
|
2
|
-
interface Clock {
|
|
3
|
-
now(): Date;
|
|
4
|
-
/**
|
|
5
|
-
* Runs `task.run` after `task.delayMs` milliseconds, again every `delayMs` when `repeat` is set, and
|
|
6
|
-
* returns a function that cancels it. `unref` marks a timer that must not keep the process alive.
|
|
7
|
-
* Optional: without it relaybus uses the platform timers. Implement it to control timers in tests
|
|
8
|
-
* (`FakeClock` does with `controlTimers: true`).
|
|
9
|
-
*/
|
|
10
|
-
schedule?(task: {
|
|
11
|
-
readonly run: () => void;
|
|
12
|
-
readonly delayMs: number;
|
|
13
|
-
readonly repeat?: boolean;
|
|
14
|
-
readonly unref?: boolean;
|
|
15
|
-
}): () => void;
|
|
16
|
-
}
|
|
17
|
-
declare const systemClock: Clock;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The Standard Schema interface (https://standardschema.dev), copied as the
|
|
21
|
-
* specification recommends so relaybus needs no runtime dependency. Zod,
|
|
22
|
-
* Valibot, ArkType and other libraries implement it.
|
|
23
|
-
*/
|
|
24
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
25
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
26
|
-
}
|
|
27
|
-
declare namespace StandardSchemaV1 {
|
|
28
|
-
interface Props<Input = unknown, Output = Input> {
|
|
29
|
-
readonly version: 1;
|
|
30
|
-
readonly vendor: string;
|
|
31
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
32
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
33
|
-
}
|
|
34
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
35
|
-
interface SuccessResult<Output> {
|
|
36
|
-
readonly value: Output;
|
|
37
|
-
readonly issues?: undefined;
|
|
38
|
-
}
|
|
39
|
-
interface FailureResult {
|
|
40
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
41
|
-
}
|
|
42
|
-
interface Issue {
|
|
43
|
-
readonly message: string;
|
|
44
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
45
|
-
}
|
|
46
|
-
interface PathSegment {
|
|
47
|
-
readonly key: PropertyKey;
|
|
48
|
-
}
|
|
49
|
-
interface Types<Input = unknown, Output = Input> {
|
|
50
|
-
readonly input: Input;
|
|
51
|
-
readonly output: Output;
|
|
52
|
-
}
|
|
53
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
54
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** String metadata carried with an event, such as `traceparent`. */
|
|
58
|
-
type EventHeaders = Readonly<Record<string, string>>;
|
|
59
|
-
/**
|
|
60
|
-
* An event as stored and delivered. Field names follow CloudEvents where they
|
|
61
|
-
* overlap (`id`, `type`, `source`, `time` as `occurredAt`, `subject` as `key`).
|
|
62
|
-
*/
|
|
63
|
-
interface EventEnvelope<TPayload = unknown> {
|
|
64
|
-
/** Globally unique id. Handlers and transports deduplicate on it. */
|
|
65
|
-
readonly id: string;
|
|
66
|
-
/** Event type, for example `order.created.v1`. */
|
|
67
|
-
readonly type: string;
|
|
68
|
-
/** Logical name of the publishing service. */
|
|
69
|
-
readonly source: string;
|
|
70
|
-
/** Ordering and partition key. Events sharing a key are handled in publish order. */
|
|
71
|
-
readonly key: string | null;
|
|
72
|
-
readonly payload: TPayload;
|
|
73
|
-
readonly headers: EventHeaders;
|
|
74
|
-
/** Id shared by every event of one business flow. */
|
|
75
|
-
readonly correlationId: string | null;
|
|
76
|
-
/** Id of the event whose handler published this one. */
|
|
77
|
-
readonly causationId: string | null;
|
|
78
|
-
readonly occurredAt: Date;
|
|
79
|
-
}
|
|
80
|
-
/** An instance of a class created with {@link defineEvent}. */
|
|
81
|
-
interface DomainEvent<TPayload = unknown> {
|
|
82
|
-
readonly type: string;
|
|
83
|
-
readonly payload: TPayload;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Derives the ordering key of an event from its validated payload. Declared bivariantly so an
|
|
87
|
-
* event class stays assignable wherever its payload type is widened.
|
|
88
|
-
*/
|
|
89
|
-
type EventKeyFunction<TPayload> = {
|
|
90
|
-
bivarianceHack(payload: TPayload): string;
|
|
91
|
-
}['bivarianceHack'];
|
|
92
|
-
/** A class created with {@link defineEvent}. */
|
|
93
|
-
interface EventClass<TPayload = unknown> {
|
|
94
|
-
new (payload: TPayload): DomainEvent<TPayload>;
|
|
95
|
-
readonly type: string;
|
|
96
|
-
readonly schema: StandardSchemaV1<unknown, TPayload> | undefined;
|
|
97
|
-
/** The `key` given to {@link defineEvent}; undefined for events without one. */
|
|
98
|
-
readonly key?: EventKeyFunction<TPayload> | undefined;
|
|
99
|
-
}
|
|
100
|
-
/** Payload type of an event class: `PayloadOf<typeof OrderPlaced>`. */
|
|
101
|
-
type PayloadOf<TEvent> = TEvent extends EventClass<infer TPayload> ? TPayload : never;
|
|
102
|
-
/** Anything that names an event type: an event class or the type string itself. */
|
|
103
|
-
type EventReference = {
|
|
104
|
-
readonly type: string;
|
|
105
|
-
} | string;
|
|
106
|
-
interface DefineEventOptions<TSchema extends StandardSchemaV1> {
|
|
107
|
-
/** Validates the payload on publish and before every handler call. */
|
|
108
|
-
readonly schema: TSchema;
|
|
109
|
-
/** Ordering key of every event of this type, from its validated payload. See {@link DefineEventKeyOptions}. */
|
|
110
|
-
readonly key?: (payload: StandardSchemaV1.InferOutput<TSchema>) => string;
|
|
111
|
-
}
|
|
112
|
-
interface DefineEventKeyOptions<TPayload> {
|
|
113
|
-
/**
|
|
114
|
-
* Ordering key of every event of this type, from its payload: `(payload) => payload.orderId`.
|
|
115
|
-
* Typed from the payload, so a missing field or a non-string fails to compile. `publish` uses it
|
|
116
|
-
* when it is given no `key`; an explicit `key` option wins (for `publishAll`, the one key of the
|
|
117
|
-
* call applies to every event). It must return a non-empty string.
|
|
118
|
-
*/
|
|
119
|
-
readonly key: (payload: TPayload) => string;
|
|
120
|
-
}
|
|
121
|
-
declare function assertEventType(type: string): void;
|
|
122
|
-
/**
|
|
123
|
-
* Defines an event type. Extend the returned class to name it:
|
|
124
|
-
*
|
|
125
|
-
* ```ts
|
|
126
|
-
* export class OrderPlaced extends defineEvent<{ orderId: string }>('order.placed.v1') {}
|
|
127
|
-
* export class OrderShipped extends defineEvent('order.shipped.v1', { schema: orderShippedSchema }) {}
|
|
128
|
-
* export class OrderPaid extends defineEvent('order.paid.v1', {
|
|
129
|
-
* schema: orderPaidSchema,
|
|
130
|
-
* key: (payload) => payload.orderId,
|
|
131
|
-
* }) {}
|
|
132
|
-
* export class OrderCancelled extends defineEvent<{ orderId: string }>('order.cancelled.v1', {
|
|
133
|
-
* key: (payload) => payload.orderId,
|
|
134
|
-
* }) {}
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
declare function defineEvent<TSchema extends StandardSchemaV1>(type: string, options: DefineEventOptions<TSchema>): EventClass<StandardSchemaV1.InferOutput<TSchema>>;
|
|
138
|
-
declare function defineEvent<TPayload>(type: string, options?: DefineEventKeyOptions<TPayload>): EventClass<TPayload>;
|
|
139
|
-
/** Runs a Standard Schema and returns its output, or throws {@link EventValidationError}. */
|
|
140
|
-
declare function validatePayload<TPayload>(type: string, schema: StandardSchemaV1<unknown, TPayload> | undefined, payload: unknown): Promise<TPayload>;
|
|
141
|
-
|
|
142
|
-
export { type Clock as C, type DomainEvent as D, type EventEnvelope as E, type PayloadOf as P, StandardSchemaV1 as S, type EventHeaders as a, type EventReference as b, type EventClass as c, type DefineEventKeyOptions as d, type DefineEventOptions as e, type EventKeyFunction as f, assertEventType as g, defineEvent as h, systemClock as s, validatePayload as v };
|
package/dist/event-DCRTuYKI.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/** Source of the current time. Replace it in tests to control retries and leases. */
|
|
2
|
-
interface Clock {
|
|
3
|
-
now(): Date;
|
|
4
|
-
/**
|
|
5
|
-
* Runs `task.run` after `task.delayMs` milliseconds, again every `delayMs` when `repeat` is set, and
|
|
6
|
-
* returns a function that cancels it. `unref` marks a timer that must not keep the process alive.
|
|
7
|
-
* Optional: without it relaybus uses the platform timers. Implement it to control timers in tests
|
|
8
|
-
* (`FakeClock` does with `controlTimers: true`).
|
|
9
|
-
*/
|
|
10
|
-
schedule?(task: {
|
|
11
|
-
readonly run: () => void;
|
|
12
|
-
readonly delayMs: number;
|
|
13
|
-
readonly repeat?: boolean;
|
|
14
|
-
readonly unref?: boolean;
|
|
15
|
-
}): () => void;
|
|
16
|
-
}
|
|
17
|
-
declare const systemClock: Clock;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The Standard Schema interface (https://standardschema.dev), copied as the
|
|
21
|
-
* specification recommends so relaybus needs no runtime dependency. Zod,
|
|
22
|
-
* Valibot, ArkType and other libraries implement it.
|
|
23
|
-
*/
|
|
24
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
25
|
-
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
26
|
-
}
|
|
27
|
-
declare namespace StandardSchemaV1 {
|
|
28
|
-
interface Props<Input = unknown, Output = Input> {
|
|
29
|
-
readonly version: 1;
|
|
30
|
-
readonly vendor: string;
|
|
31
|
-
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
32
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
33
|
-
}
|
|
34
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
35
|
-
interface SuccessResult<Output> {
|
|
36
|
-
readonly value: Output;
|
|
37
|
-
readonly issues?: undefined;
|
|
38
|
-
}
|
|
39
|
-
interface FailureResult {
|
|
40
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
41
|
-
}
|
|
42
|
-
interface Issue {
|
|
43
|
-
readonly message: string;
|
|
44
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
45
|
-
}
|
|
46
|
-
interface PathSegment {
|
|
47
|
-
readonly key: PropertyKey;
|
|
48
|
-
}
|
|
49
|
-
interface Types<Input = unknown, Output = Input> {
|
|
50
|
-
readonly input: Input;
|
|
51
|
-
readonly output: Output;
|
|
52
|
-
}
|
|
53
|
-
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
54
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** String metadata carried with an event, such as `traceparent`. */
|
|
58
|
-
type EventHeaders = Readonly<Record<string, string>>;
|
|
59
|
-
/**
|
|
60
|
-
* An event as stored and delivered. Field names follow CloudEvents where they
|
|
61
|
-
* overlap (`id`, `type`, `source`, `time` as `occurredAt`, `subject` as `key`).
|
|
62
|
-
*/
|
|
63
|
-
interface EventEnvelope<TPayload = unknown> {
|
|
64
|
-
/** Globally unique id. Handlers and transports deduplicate on it. */
|
|
65
|
-
readonly id: string;
|
|
66
|
-
/** Event type, for example `order.created.v1`. */
|
|
67
|
-
readonly type: string;
|
|
68
|
-
/** Logical name of the publishing service. */
|
|
69
|
-
readonly source: string;
|
|
70
|
-
/** Ordering and partition key. Events sharing a key are handled in publish order. */
|
|
71
|
-
readonly key: string | null;
|
|
72
|
-
readonly payload: TPayload;
|
|
73
|
-
readonly headers: EventHeaders;
|
|
74
|
-
/** Id shared by every event of one business flow. */
|
|
75
|
-
readonly correlationId: string | null;
|
|
76
|
-
/** Id of the event whose handler published this one. */
|
|
77
|
-
readonly causationId: string | null;
|
|
78
|
-
readonly occurredAt: Date;
|
|
79
|
-
}
|
|
80
|
-
/** An instance of a class created with {@link defineEvent}. */
|
|
81
|
-
interface DomainEvent<TPayload = unknown> {
|
|
82
|
-
readonly type: string;
|
|
83
|
-
readonly payload: TPayload;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Derives the ordering key of an event from its validated payload. Declared bivariantly so an
|
|
87
|
-
* event class stays assignable wherever its payload type is widened.
|
|
88
|
-
*/
|
|
89
|
-
type EventKeyFunction<TPayload> = {
|
|
90
|
-
bivarianceHack(payload: TPayload): string;
|
|
91
|
-
}['bivarianceHack'];
|
|
92
|
-
/** A class created with {@link defineEvent}. */
|
|
93
|
-
interface EventClass<TPayload = unknown> {
|
|
94
|
-
new (payload: TPayload): DomainEvent<TPayload>;
|
|
95
|
-
readonly type: string;
|
|
96
|
-
readonly schema: StandardSchemaV1<unknown, TPayload> | undefined;
|
|
97
|
-
/** The `key` given to {@link defineEvent}; undefined for events without one. */
|
|
98
|
-
readonly key?: EventKeyFunction<TPayload> | undefined;
|
|
99
|
-
}
|
|
100
|
-
/** Payload type of an event class: `PayloadOf<typeof OrderPlaced>`. */
|
|
101
|
-
type PayloadOf<TEvent> = TEvent extends EventClass<infer TPayload> ? TPayload : never;
|
|
102
|
-
/** Anything that names an event type: an event class or the type string itself. */
|
|
103
|
-
type EventReference = {
|
|
104
|
-
readonly type: string;
|
|
105
|
-
} | string;
|
|
106
|
-
interface DefineEventOptions<TSchema extends StandardSchemaV1> {
|
|
107
|
-
/** Validates the payload on publish and before every handler call. */
|
|
108
|
-
readonly schema: TSchema;
|
|
109
|
-
/** Ordering key of every event of this type, from its validated payload. See {@link DefineEventKeyOptions}. */
|
|
110
|
-
readonly key?: (payload: StandardSchemaV1.InferOutput<TSchema>) => string;
|
|
111
|
-
}
|
|
112
|
-
interface DefineEventKeyOptions<TPayload> {
|
|
113
|
-
/**
|
|
114
|
-
* Ordering key of every event of this type, from its payload: `(payload) => payload.orderId`.
|
|
115
|
-
* Typed from the payload, so a missing field or a non-string fails to compile. `publish` uses it
|
|
116
|
-
* when it is given no `key`; an explicit `key` option wins (for `publishAll`, the one key of the
|
|
117
|
-
* call applies to every event). It must return a non-empty string.
|
|
118
|
-
*/
|
|
119
|
-
readonly key: (payload: TPayload) => string;
|
|
120
|
-
}
|
|
121
|
-
declare function assertEventType(type: string): void;
|
|
122
|
-
/**
|
|
123
|
-
* Defines an event type. Extend the returned class to name it:
|
|
124
|
-
*
|
|
125
|
-
* ```ts
|
|
126
|
-
* export class OrderPlaced extends defineEvent<{ orderId: string }>('order.placed.v1') {}
|
|
127
|
-
* export class OrderShipped extends defineEvent('order.shipped.v1', { schema: orderShippedSchema }) {}
|
|
128
|
-
* export class OrderPaid extends defineEvent('order.paid.v1', {
|
|
129
|
-
* schema: orderPaidSchema,
|
|
130
|
-
* key: (payload) => payload.orderId,
|
|
131
|
-
* }) {}
|
|
132
|
-
* export class OrderCancelled extends defineEvent<{ orderId: string }>('order.cancelled.v1', {
|
|
133
|
-
* key: (payload) => payload.orderId,
|
|
134
|
-
* }) {}
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
declare function defineEvent<TSchema extends StandardSchemaV1>(type: string, options: DefineEventOptions<TSchema>): EventClass<StandardSchemaV1.InferOutput<TSchema>>;
|
|
138
|
-
declare function defineEvent<TPayload>(type: string, options?: DefineEventKeyOptions<TPayload>): EventClass<TPayload>;
|
|
139
|
-
/** Runs a Standard Schema and returns its output, or throws {@link EventValidationError}. */
|
|
140
|
-
declare function validatePayload<TPayload>(type: string, schema: StandardSchemaV1<unknown, TPayload> | undefined, payload: unknown): Promise<TPayload>;
|
|
141
|
-
|
|
142
|
-
export { type Clock as C, type DomainEvent as D, type EventEnvelope as E, type PayloadOf as P, StandardSchemaV1 as S, type EventHeaders as a, type EventReference as b, type EventClass as c, type DefineEventKeyOptions as d, type DefineEventOptions as e, type EventKeyFunction as f, assertEventType as g, defineEvent as h, systemClock as s, validatePayload as v };
|