@parsrun/service 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 +375 -0
- package/dist/client.d.ts +55 -0
- package/dist/client.js +1474 -0
- package/dist/client.js.map +1 -0
- package/dist/define.d.ts +82 -0
- package/dist/define.js +120 -0
- package/dist/define.js.map +1 -0
- package/dist/events/index.d.ts +285 -0
- package/dist/events/index.js +853 -0
- package/dist/events/index.js.map +1 -0
- package/dist/handler-CmiDUWZv.d.ts +204 -0
- package/dist/index-CVOAoJjZ.d.ts +268 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +3589 -0
- package/dist/index.js.map +1 -0
- package/dist/resilience/index.d.ts +197 -0
- package/dist/resilience/index.js +387 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/rpc/index.d.ts +5 -0
- package/dist/rpc/index.js +1175 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/serialization/index.d.ts +37 -0
- package/dist/serialization/index.js +320 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/server-DFE8n2Sx.d.ts +106 -0
- package/dist/tracing/index.d.ts +406 -0
- package/dist/tracing/index.js +820 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/transports/cloudflare/index.d.ts +237 -0
- package/dist/transports/cloudflare/index.js +746 -0
- package/dist/transports/cloudflare/index.js.map +1 -0
- package/dist/types-n4LLSPQU.d.ts +473 -0
- package/package.json +91 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { m as TraceContext, P as ParsEvent, C as CompactEvent, b as ServiceDefinition, t as EventTransport, e as EventHandlerOptions, j as EventHandler, U as Unsubscribe } from '../types-n4LLSPQU.js';
|
|
2
|
+
import { Logger } from '@parsrun/core';
|
|
3
|
+
export { A as AddEntryOptions, d as DeadLetterEntry, D as DeadLetterQueue, e as DeadLetterQueueOptions, E as EventHandlerRegistry, a as EventHandlerRegistryOptions, H as HandlerRegistration, b as createDeadLetterQueue, c as createEventHandlerRegistry } from '../handler-CmiDUWZv.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @parsrun/service - Event Format
|
|
7
|
+
* CloudEvents and compact event format utilities
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
interface CreateEventOptions<T = unknown> {
|
|
11
|
+
/** Event type (e.g., "subscription.created") */
|
|
12
|
+
type: string;
|
|
13
|
+
/** Source service */
|
|
14
|
+
source: string;
|
|
15
|
+
/** Event data */
|
|
16
|
+
data: T;
|
|
17
|
+
/** Optional event ID (auto-generated if not provided) */
|
|
18
|
+
id?: string;
|
|
19
|
+
/** Optional subject */
|
|
20
|
+
subject?: string;
|
|
21
|
+
/** Tenant ID */
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
/** Request ID for correlation */
|
|
24
|
+
requestId?: string;
|
|
25
|
+
/** Trace context */
|
|
26
|
+
traceContext?: TraceContext;
|
|
27
|
+
/** Delivery guarantee */
|
|
28
|
+
delivery?: "at-most-once" | "at-least-once";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a CloudEvents-compatible event
|
|
32
|
+
*/
|
|
33
|
+
declare function createEvent<T = unknown>(options: CreateEventOptions<T>): ParsEvent<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Convert to full CloudEvents format
|
|
36
|
+
*/
|
|
37
|
+
declare function toCloudEvent<T>(event: ParsEvent<T>): ParsEvent<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Convert to compact internal format
|
|
40
|
+
*/
|
|
41
|
+
declare function toCompactEvent<T>(event: ParsEvent<T>): CompactEvent<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Convert from compact format to CloudEvents
|
|
44
|
+
*/
|
|
45
|
+
declare function fromCompactEvent<T>(compact: CompactEvent<T>, source?: string): ParsEvent<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Format full event type with source prefix
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* formatEventType('payments', 'subscription.created')
|
|
51
|
+
* // Returns: 'com.pars.payments.subscription.created'
|
|
52
|
+
*/
|
|
53
|
+
declare function formatEventType(source: string, type: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Parse event type to extract source and type
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* parseEventType('com.pars.payments.subscription.created')
|
|
59
|
+
* // Returns: { source: 'payments', type: 'subscription.created' }
|
|
60
|
+
*/
|
|
61
|
+
declare function parseEventType(fullType: string): {
|
|
62
|
+
source: string;
|
|
63
|
+
type: string;
|
|
64
|
+
} | null;
|
|
65
|
+
/**
|
|
66
|
+
* Check if event type matches a pattern
|
|
67
|
+
* Supports wildcards: * matches one segment, ** matches multiple segments
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* matchEventType('subscription.created', 'subscription.*') // true
|
|
71
|
+
* matchEventType('payment.invoice.paid', 'payment.**') // true
|
|
72
|
+
* matchEventType('subscription.created', 'payment.*') // false
|
|
73
|
+
*/
|
|
74
|
+
declare function matchEventType(type: string, pattern: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Validate CloudEvents structure
|
|
77
|
+
*/
|
|
78
|
+
declare function validateEvent(event: unknown): event is ParsEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Validate compact event structure
|
|
81
|
+
*/
|
|
82
|
+
declare function validateCompactEvent(event: unknown): event is CompactEvent;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @parsrun/service - Event Emitter
|
|
86
|
+
* Service-level event emission
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
interface EventEmitterOptions {
|
|
90
|
+
/** Service name (source) */
|
|
91
|
+
service: string;
|
|
92
|
+
/** Service definition (for validation) */
|
|
93
|
+
definition?: ServiceDefinition;
|
|
94
|
+
/** Event transport */
|
|
95
|
+
transport: EventTransport;
|
|
96
|
+
/** Logger */
|
|
97
|
+
logger?: Logger;
|
|
98
|
+
/** Default tenant ID */
|
|
99
|
+
defaultTenantId?: string;
|
|
100
|
+
/** Validate events against definition */
|
|
101
|
+
validateEvents?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Event emitter for service events
|
|
105
|
+
*/
|
|
106
|
+
declare class EventEmitter {
|
|
107
|
+
private readonly service;
|
|
108
|
+
private readonly definition?;
|
|
109
|
+
private readonly transport;
|
|
110
|
+
private readonly logger;
|
|
111
|
+
private readonly defaultTenantId?;
|
|
112
|
+
private readonly validateEvents;
|
|
113
|
+
constructor(options: EventEmitterOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Emit an event
|
|
116
|
+
*/
|
|
117
|
+
emit<T = unknown>(type: string, data: T, options?: EmitOptions): Promise<string>;
|
|
118
|
+
/**
|
|
119
|
+
* Emit multiple events
|
|
120
|
+
*/
|
|
121
|
+
emitBatch<T = unknown>(events: Array<{
|
|
122
|
+
type: string;
|
|
123
|
+
data: T;
|
|
124
|
+
options?: EmitOptions;
|
|
125
|
+
}>): Promise<string[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Create a scoped emitter with preset options
|
|
128
|
+
*/
|
|
129
|
+
scoped(options: Partial<EmitOptions>): ScopedEmitter;
|
|
130
|
+
/**
|
|
131
|
+
* Get service name
|
|
132
|
+
*/
|
|
133
|
+
get serviceName(): string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Emit options
|
|
137
|
+
*/
|
|
138
|
+
interface EmitOptions {
|
|
139
|
+
/** Custom event ID */
|
|
140
|
+
eventId?: string;
|
|
141
|
+
/** Event subject */
|
|
142
|
+
subject?: string;
|
|
143
|
+
/** Tenant ID */
|
|
144
|
+
tenantId?: string;
|
|
145
|
+
/** Request ID for correlation */
|
|
146
|
+
requestId?: string;
|
|
147
|
+
/** Trace context */
|
|
148
|
+
traceContext?: TraceContext;
|
|
149
|
+
/** Override delivery guarantee */
|
|
150
|
+
delivery?: "at-most-once" | "at-least-once";
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Scoped emitter with preset options
|
|
154
|
+
*/
|
|
155
|
+
declare class ScopedEmitter {
|
|
156
|
+
private readonly emitter;
|
|
157
|
+
private readonly defaultOptions;
|
|
158
|
+
constructor(emitter: EventEmitter, defaultOptions: Partial<EmitOptions>);
|
|
159
|
+
emit<T = unknown>(type: string, data: T, options?: EmitOptions): Promise<string>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create an event emitter
|
|
163
|
+
*/
|
|
164
|
+
declare function createEventEmitter(options: EventEmitterOptions): EventEmitter;
|
|
165
|
+
/**
|
|
166
|
+
* Create a typed event emitter from service definition
|
|
167
|
+
* Provides type-safe event emission
|
|
168
|
+
*/
|
|
169
|
+
declare function createTypedEmitter<TDef extends ServiceDefinition>(definition: TDef, options: Omit<EventEmitterOptions, "service" | "definition">): TypedEventEmitter<TDef>;
|
|
170
|
+
/**
|
|
171
|
+
* Typed event emitter type
|
|
172
|
+
* Provides type-safe event emission with specific event types
|
|
173
|
+
*/
|
|
174
|
+
type TypedEventEmitter<TDef extends ServiceDefinition> = EventEmitter & {
|
|
175
|
+
emit<K extends keyof NonNullable<TDef["events"]>["emits"]>(type: K, data: NonNullable<TDef["events"]>["emits"][K] extends {
|
|
176
|
+
data?: infer D;
|
|
177
|
+
} ? D : unknown, options?: EmitOptions): Promise<string>;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @parsrun/service - Memory Event Transport
|
|
182
|
+
* In-memory event transport for embedded mode and testing
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
interface MemoryEventTransportOptions {
|
|
186
|
+
/** Logger */
|
|
187
|
+
logger?: Logger;
|
|
188
|
+
/** Process events synchronously (default: false) */
|
|
189
|
+
sync?: boolean;
|
|
190
|
+
/** Default handler options */
|
|
191
|
+
defaultHandlerOptions?: EventHandlerOptions;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* In-memory event transport
|
|
195
|
+
* Events are processed immediately without persistence
|
|
196
|
+
*/
|
|
197
|
+
declare class MemoryEventTransport implements EventTransport {
|
|
198
|
+
readonly name = "memory";
|
|
199
|
+
private readonly registry;
|
|
200
|
+
private readonly logger;
|
|
201
|
+
private readonly sync;
|
|
202
|
+
private readonly pendingEvents;
|
|
203
|
+
private processing;
|
|
204
|
+
constructor(options?: MemoryEventTransportOptions);
|
|
205
|
+
/**
|
|
206
|
+
* Emit an event
|
|
207
|
+
*/
|
|
208
|
+
emit<T>(event: ParsEvent<T>): Promise<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Subscribe to events
|
|
211
|
+
*/
|
|
212
|
+
subscribe(eventType: string, handler: EventHandler, options?: EventHandlerOptions): Unsubscribe;
|
|
213
|
+
/**
|
|
214
|
+
* Process pending events asynchronously
|
|
215
|
+
*/
|
|
216
|
+
private processQueue;
|
|
217
|
+
/**
|
|
218
|
+
* Wait for all pending events to be processed
|
|
219
|
+
*/
|
|
220
|
+
flush(): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Get pending event count
|
|
223
|
+
*/
|
|
224
|
+
get pendingCount(): number;
|
|
225
|
+
/**
|
|
226
|
+
* Get registered patterns
|
|
227
|
+
*/
|
|
228
|
+
getPatterns(): string[];
|
|
229
|
+
/**
|
|
230
|
+
* Clear all subscriptions
|
|
231
|
+
*/
|
|
232
|
+
clear(): void;
|
|
233
|
+
/**
|
|
234
|
+
* Close the transport
|
|
235
|
+
*/
|
|
236
|
+
close(): Promise<void>;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Create a memory event transport
|
|
240
|
+
*/
|
|
241
|
+
declare function createMemoryEventTransport(options?: MemoryEventTransportOptions): MemoryEventTransport;
|
|
242
|
+
/**
|
|
243
|
+
* Global event bus for communication between embedded services
|
|
244
|
+
*/
|
|
245
|
+
declare class GlobalEventBus {
|
|
246
|
+
private static instance;
|
|
247
|
+
private readonly transports;
|
|
248
|
+
private readonly logger;
|
|
249
|
+
private constructor();
|
|
250
|
+
static getInstance(): GlobalEventBus;
|
|
251
|
+
/**
|
|
252
|
+
* Register a service's event transport
|
|
253
|
+
*/
|
|
254
|
+
register(serviceName: string, transport: MemoryEventTransport): void;
|
|
255
|
+
/**
|
|
256
|
+
* Unregister a service
|
|
257
|
+
*/
|
|
258
|
+
unregister(serviceName: string): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Broadcast an event to all services (except source)
|
|
261
|
+
*/
|
|
262
|
+
broadcast(event: ParsEvent, excludeSource?: string): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Send an event to a specific service
|
|
265
|
+
*/
|
|
266
|
+
send(serviceName: string, event: ParsEvent): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Get all registered service names
|
|
269
|
+
*/
|
|
270
|
+
getServices(): string[];
|
|
271
|
+
/**
|
|
272
|
+
* Clear all registrations
|
|
273
|
+
*/
|
|
274
|
+
clear(): void;
|
|
275
|
+
/**
|
|
276
|
+
* Reset singleton (for testing)
|
|
277
|
+
*/
|
|
278
|
+
static reset(): void;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Get the global event bus
|
|
282
|
+
*/
|
|
283
|
+
declare function getGlobalEventBus(): GlobalEventBus;
|
|
284
|
+
|
|
285
|
+
export { type EmitOptions, EventEmitter, type EventEmitterOptions, GlobalEventBus, MemoryEventTransport, type MemoryEventTransportOptions, ScopedEmitter, type TypedEventEmitter, createEvent, createEventEmitter, createMemoryEventTransport, createTypedEmitter, formatEventType, fromCompactEvent, getGlobalEventBus, matchEventType, parseEventType, toCloudEvent, toCompactEvent, validateCompactEvent, validateEvent };
|