@parsrun/service 0.1.28 → 0.1.30

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.
@@ -1,11 +1,15 @@
1
1
  import { Logger } from '@parsrun/core';
2
- import { P as ParsEvent, e as EventHandlerOptions, j as EventHandler, U as Unsubscribe } from './types-n4LLSPQU.js';
2
+ import { P as ParsEvent, e as EventHandlerOptions, j as EventHandler, U as Unsubscribe } from './types-DHZaZwAt.js';
3
3
 
4
4
  /**
5
5
  * @parsrun/service - Dead Letter Queue
6
6
  * Storage for failed events
7
7
  */
8
8
 
9
+ /**
10
+ * Entry stored in the dead letter queue.
11
+ * Contains the failed event and metadata about the failure.
12
+ */
9
13
  interface DeadLetterEntry {
10
14
  /** Unique ID */
11
15
  id: string;
@@ -22,6 +26,9 @@ interface DeadLetterEntry {
22
26
  /** Optional metadata */
23
27
  metadata?: Record<string, unknown>;
24
28
  }
29
+ /**
30
+ * Options for creating a dead letter queue.
31
+ */
25
32
  interface DeadLetterQueueOptions {
26
33
  /** Maximum entries to keep */
27
34
  maxSize?: number;
@@ -36,6 +43,9 @@ interface DeadLetterQueueOptions {
36
43
  /** Logger */
37
44
  logger?: Logger;
38
45
  }
46
+ /**
47
+ * Options for adding an entry to the dead letter queue.
48
+ */
39
49
  interface AddEntryOptions {
40
50
  /** Original event */
41
51
  event: ParsEvent;
@@ -115,7 +125,19 @@ declare class DeadLetterQueue {
115
125
  import(entries: DeadLetterEntry[]): void;
116
126
  }
117
127
  /**
118
- * Create a dead letter queue
128
+ * Create a dead letter queue for storing failed events.
129
+ *
130
+ * @param options - DLQ configuration options
131
+ * @returns A new dead letter queue instance
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const dlq = createDeadLetterQueue({
136
+ * maxSize: 1000,
137
+ * alertThreshold: 50,
138
+ * onThreshold: (count) => alert(`DLQ has ${count} entries`),
139
+ * });
140
+ * ```
119
141
  */
120
142
  declare function createDeadLetterQueue(options?: DeadLetterQueueOptions): DeadLetterQueue;
121
143
 
@@ -134,6 +156,9 @@ interface ResolvedHandlerOptions {
134
156
  onExhausted: "alert" | "log" | "discard";
135
157
  deadLetter?: string;
136
158
  }
159
+ /**
160
+ * Registration entry for an event handler.
161
+ */
137
162
  interface HandlerRegistration {
138
163
  /** Event type pattern (supports wildcards) */
139
164
  pattern: string;
@@ -142,6 +167,9 @@ interface HandlerRegistration {
142
167
  /** Handler options */
143
168
  options: ResolvedHandlerOptions;
144
169
  }
170
+ /**
171
+ * Options for creating an event handler registry.
172
+ */
145
173
  interface EventHandlerRegistryOptions {
146
174
  /** Logger */
147
175
  logger?: Logger;
@@ -197,7 +225,21 @@ declare class EventHandlerRegistry {
197
225
  clear(): void;
198
226
  }
199
227
  /**
200
- * Create an event handler registry
228
+ * Create an event handler registry for managing event subscriptions.
229
+ *
230
+ * @param options - Registry configuration options
231
+ * @returns A new event handler registry instance
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const registry = createEventHandlerRegistry({
236
+ * deadLetterQueue: dlq,
237
+ * defaultOptions: { retries: 3 },
238
+ * });
239
+ * registry.register('subscription.*', async (event, ctx) => {
240
+ * console.log('Received event:', event.type);
241
+ * });
242
+ * ```
201
243
  */
202
244
  declare function createEventHandlerRegistry(options?: EventHandlerRegistryOptions): EventHandlerRegistry;
203
245
 
@@ -1,5 +1,5 @@
1
- import { s as RpcTransport, S as ServiceConfig, i as RpcMetadata, m as TraceContext, f as RpcRequest, g as RpcResponse } from './types-n4LLSPQU.js';
2
- import { R as RpcServer } from './server-DFE8n2Sx.js';
1
+ import { s as RpcTransport, S as ServiceConfig, i as RpcMetadata, m as TraceContext, f as RpcRequest, g as RpcResponse } from './types-DHZaZwAt.js';
2
+ import { R as RpcServer } from './server-BB9AbnkP.js';
3
3
  import { Serializer } from './serialization/index.js';
4
4
  import { ParsError } from '@parsrun/core';
5
5
 
@@ -8,6 +8,9 @@ import { ParsError } from '@parsrun/core';
8
8
  * Client for making RPC calls to services
9
9
  */
10
10
 
11
+ /**
12
+ * Options for creating an RPC client.
13
+ */
11
14
  interface RpcClientOptions {
12
15
  /** Service name */
13
16
  service: string;
@@ -58,7 +61,8 @@ declare class RpcClient {
58
61
  close(): Promise<void>;
59
62
  }
60
63
  /**
61
- * Call options
64
+ * Options for individual RPC calls.
65
+ * Allows overriding default client settings per-call.
62
66
  */
63
67
  interface CallOptions {
64
68
  /** Timeout in ms */
@@ -78,7 +82,20 @@ interface CallOptions {
78
82
  };
79
83
  }
80
84
  /**
81
- * Create an RPC client
85
+ * Create an RPC client for making service calls.
86
+ *
87
+ * @param options - Client configuration options
88
+ * @returns A new RPC client instance
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const client = createRpcClient({
93
+ * service: 'payments',
94
+ * transport: httpTransport,
95
+ * config: { resilience: { timeout: 5000 } },
96
+ * });
97
+ * const result = await client.query('getSubscription', { id: '123' });
98
+ * ```
82
99
  */
83
100
  declare function createRpcClient(options: RpcClientOptions): RpcClient;
84
101
 
@@ -99,7 +116,17 @@ declare class EmbeddedTransport implements RpcTransport {
99
116
  close(): Promise<void>;
100
117
  }
101
118
  /**
102
- * Create an embedded transport
119
+ * Create an embedded transport for direct function calls.
120
+ * Used when the service is in the same process.
121
+ *
122
+ * @param server - The RPC server to call directly
123
+ * @returns A new embedded transport instance
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const transport = createEmbeddedTransport(rpcServer);
128
+ * const client = createRpcClient({ service: 'payments', transport });
129
+ * ```
103
130
  */
104
131
  declare function createEmbeddedTransport(server: RpcServer): EmbeddedTransport;
105
132
  /**
@@ -145,7 +172,17 @@ declare class EmbeddedRegistry {
145
172
  static reset(): void;
146
173
  }
147
174
  /**
148
- * Get the global embedded registry
175
+ * Get the global embedded registry singleton.
176
+ * Provides access to the shared registry for service discovery.
177
+ *
178
+ * @returns The global embedded registry instance
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const registry = getEmbeddedRegistry();
183
+ * registry.register('payments', paymentsServer);
184
+ * const transport = registry.createTransport('payments');
185
+ * ```
149
186
  */
150
187
  declare function getEmbeddedRegistry(): EmbeddedRegistry;
151
188
 
@@ -154,6 +191,9 @@ declare function getEmbeddedRegistry(): EmbeddedRegistry;
154
191
  * HTTP-based transport for distributed services
155
192
  */
156
193
 
194
+ /**
195
+ * Options for creating an HTTP transport.
196
+ */
157
197
  interface HttpTransportOptions {
158
198
  /** Base URL of the service */
159
199
  baseUrl: string;
@@ -167,7 +207,8 @@ interface HttpTransportOptions {
167
207
  timeout?: number;
168
208
  }
169
209
  /**
170
- * HTTP transport for RPC calls
210
+ * HTTP transport for RPC calls over HTTP/HTTPS.
211
+ * Makes POST requests to /rpc endpoint with serialized request body.
171
212
  */
172
213
  declare class HttpTransport implements RpcTransport {
173
214
  readonly name = "http";
@@ -181,18 +222,48 @@ declare class HttpTransport implements RpcTransport {
181
222
  close(): Promise<void>;
182
223
  }
183
224
  /**
184
- * Create an HTTP transport
225
+ * Create an HTTP transport for RPC calls.
226
+ *
227
+ * @param options - Transport configuration options
228
+ * @returns A new HTTP transport instance
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const transport = createHttpTransport({
233
+ * baseUrl: 'https://api.example.com',
234
+ * timeout: 5000,
235
+ * });
236
+ * ```
185
237
  */
186
238
  declare function createHttpTransport(options: HttpTransportOptions): HttpTransport;
187
239
 
188
240
  /**
189
- * Parse W3C traceparent header
241
+ * Parse W3C traceparent header to extract trace context.
242
+ *
243
+ * @param header - The traceparent header value
244
+ * @returns Parsed trace context or null if invalid
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const ctx = parseTraceparent('00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01');
249
+ * // { traceId: '0af7651916cd43dd8448eb211c80319c', spanId: 'b7ad6b7169203331', traceFlags: 1 }
250
+ * ```
190
251
  */
191
252
  declare function parseTraceparent(header: string): TraceContext | null;
192
253
 
193
254
  /**
194
- * Create HTTP request handler for RPC server
195
- * Can be used with Hono, Express, or any HTTP framework
255
+ * Create HTTP request handler for RPC server.
256
+ * Can be used with Hono, Express, or any HTTP framework.
257
+ *
258
+ * @param server - The RPC server to handle requests
259
+ * @returns Request handler function for HTTP frameworks
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const handler = createHttpHandler(rpcServer);
264
+ * // With Hono
265
+ * app.post('/rpc', (c) => handler(c.req.raw));
266
+ * ```
196
267
  */
197
268
  declare function createHttpHandler(server: RpcServer): (request: Request) => Promise<Response>;
198
269
 
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { S as ServiceConfig, E as EventFormatConfig, a as SerializationConfig, T as TracingConfig, V as VersioningConfig, R as ResilienceConfig, D as DeadLetterConfig } from './types-n4LLSPQU.js';
2
- export { B as BulkheadConfig, u as CircuitBreakerConfig, C as CompactEvent, I as EventData, c as EventDefinition, j as EventHandler, k as EventHandlerContext, d as EventHandlerDefinition, e as EventHandlerOptions, l as EventLogger, t as EventTransport, F as Fetcher, M as MutationDefinition, G as MutationInput, H as MutationOutput, P as ParsEvent, Q as QueryDefinition, z as QueryInput, A as QueryOutput, v as RetryConfig, h as RpcErrorData, i as RpcMetadata, f as RpcRequest, g as RpcResponse, s as RpcTransport, x as ServiceClient, w as ServiceClientOptions, b as ServiceDefinition, y as ServiceInstance, n as Span, q as SpanAttributeValue, r as SpanEvent, o as SpanKind, p as SpanStatus, m as TraceContext, U as Unsubscribe } from './types-n4LLSPQU.js';
1
+ import { S as ServiceConfig, E as EventFormatConfig, a as SerializationConfig, T as TracingConfig, V as VersioningConfig, R as ResilienceConfig, D as DeadLetterConfig } from './types-DHZaZwAt.js';
2
+ export { B as BulkheadConfig, u as CircuitBreakerConfig, C as CompactEvent, I as EventData, c as EventDefinition, j as EventHandler, k as EventHandlerContext, d as EventHandlerDefinition, e as EventHandlerOptions, l as EventLogger, t as EventTransport, F as Fetcher, M as MutationDefinition, G as MutationInput, H as MutationOutput, P as ParsEvent, Q as QueryDefinition, z as QueryInput, A as QueryOutput, v as RetryConfig, h as RpcErrorData, i as RpcMetadata, f as RpcRequest, g as RpcResponse, s as RpcTransport, x as ServiceClient, w as ServiceClientOptions, b as ServiceDefinition, y as ServiceInstance, n as Span, q as SpanAttributeValue, r as SpanEvent, o as SpanKind, p as SpanStatus, m as TraceContext, U as Unsubscribe } from './types-DHZaZwAt.js';
3
3
  export { defineService, getMethodTimeout, getServiceEvents, getServiceMethods, isMethodDeprecated, satisfiesVersion } from './define.js';
4
4
  export { ServiceRegistry, createServiceRegistry, useService, useTypedService } from './client.js';
5
- export { B as BulkheadRejectedError, C as CallOptions, i as CircuitOpenError, b as EmbeddedRegistry, E as EmbeddedTransport, H as HttpTransport, f as HttpTransportOptions, M as MethodNotFoundError, R as RpcClient, h as RpcError, k as SerializationError, S as ServiceNotFoundError, T as TimeoutError, j as TransportError, V as VersionMismatchError, a as createEmbeddedTransport, e as createHttpHandler, d as createHttpTransport, c as createRpcClient, g as getEmbeddedRegistry, p as parseTraceparent, t as toRpcError } from './index-CVOAoJjZ.js';
6
- export { a as RpcHandler, e as RpcHandlerContext, b as RpcHandlers, d as RpcMiddleware, R as RpcServer, c as createRpcServer, l as loggingMiddleware, t as tenantMiddleware, v as validationMiddleware } from './server-DFE8n2Sx.js';
5
+ export { B as BulkheadRejectedError, C as CallOptions, i as CircuitOpenError, b as EmbeddedRegistry, E as EmbeddedTransport, H as HttpTransport, f as HttpTransportOptions, M as MethodNotFoundError, R as RpcClient, h as RpcError, k as SerializationError, S as ServiceNotFoundError, T as TimeoutError, j as TransportError, V as VersionMismatchError, a as createEmbeddedTransport, e as createHttpHandler, d as createHttpTransport, c as createRpcClient, g as getEmbeddedRegistry, p as parseTraceparent, t as toRpcError } from './index-reEpIe1R.js';
6
+ export { a as RpcHandler, e as RpcHandlerContext, b as RpcHandlers, d as RpcMiddleware, R as RpcServer, c as createRpcServer, l as loggingMiddleware, t as tenantMiddleware, v as validationMiddleware } from './server-BB9AbnkP.js';
7
7
  export { EmitOptions, EventEmitter, EventEmitterOptions, GlobalEventBus, MemoryEventTransport, MemoryEventTransportOptions, ScopedEmitter, TypedEventEmitter, createEvent, createEventEmitter, createMemoryEventTransport, createTypedEmitter, formatEventType, fromCompactEvent, getGlobalEventBus, matchEventType, parseEventType, toCloudEvent, toCompactEvent, validateCompactEvent, validateEvent } from './events/index.js';
8
- 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';
8
+ 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-eCIZLODd.js';
9
9
  export { Bulkhead, BulkheadOptions, CircuitBreaker, CircuitBreakerOptions, CircuitState, RetryOptions, TimeoutExceededError, createRetryWrapper, createTimeoutWrapper, executeWithDeadline, executeWithRetry, executeWithTimeout, raceWithTimeout, withRetry, withTimeout } from './resilience/index.js';
10
10
  export { ConsoleExporter, ConsoleExporterOptions, ExporterOptions, OtlpExporter, OtlpExporterOptions, Sampler, SpanAttributes, SpanExporter, SpanManager, SpanOptions, TraceContextManager, Tracer, TracerOptions, createChildContext, createConsoleExporter, createOtlpExporter, createRpcTracing, createSpan, createTraceContext, createTracer, createTracingMiddleware, formatTraceparent, formatTracestate, generateSpanId, generateTraceId, getGlobalTracer, getSpanDuration, isSpanCompleted, parseTracestate, resetGlobalTracer, setGlobalTracer, shouldSample, spanToLogObject } from './tracing/index.js';
11
11
  export { Serializer, createSerializer, getSerializer, jsonSerializer, msgpackSerializer } from './serialization/index.js';
@@ -16,27 +16,71 @@ import '@parsrun/core';
16
16
  * Default configuration and config utilities
17
17
  */
18
18
 
19
+ /**
20
+ * Default event format configuration.
21
+ * Uses CloudEvents format with compact internal communication.
22
+ */
19
23
  declare const DEFAULT_EVENT_CONFIG: Required<EventFormatConfig>;
24
+ /**
25
+ * Default serialization configuration.
26
+ * Uses JSON format for data encoding.
27
+ */
20
28
  declare const DEFAULT_SERIALIZATION_CONFIG: Required<SerializationConfig>;
29
+ /**
30
+ * Default tracing configuration.
31
+ * Enables tracing with 10% sampling ratio and console exporter.
32
+ */
21
33
  declare const DEFAULT_TRACING_CONFIG: Required<TracingConfig>;
34
+ /**
35
+ * Default versioning configuration.
36
+ * Uses header-based versioning with "1.x" as the default version.
37
+ */
22
38
  declare const DEFAULT_VERSIONING_CONFIG: Required<VersioningConfig>;
39
+ /**
40
+ * Default resilience configuration.
41
+ * Configures circuit breaker, bulkhead, timeout, and retry settings.
42
+ */
23
43
  declare const DEFAULT_RESILIENCE_CONFIG: Required<ResilienceConfig>;
44
+ /**
45
+ * Default dead letter queue configuration.
46
+ * Enables DLQ with 30-day retention and alerting at 10 messages.
47
+ */
24
48
  declare const DEFAULT_DEAD_LETTER_CONFIG: Required<DeadLetterConfig>;
49
+ /**
50
+ * Default complete service configuration.
51
+ * Combines all default sub-configurations.
52
+ */
25
53
  declare const DEFAULT_SERVICE_CONFIG: Required<ServiceConfig>;
26
54
  /**
27
- * Merge user config with defaults
55
+ * Merge user config with defaults.
56
+ * Deep merges the user configuration with default values.
57
+ *
58
+ * @param userConfig - Optional partial service configuration
59
+ * @returns Complete service configuration with all required fields
28
60
  */
29
61
  declare function mergeConfig(userConfig?: Partial<ServiceConfig>): Required<ServiceConfig>;
30
62
  /**
31
- * Create config for development
63
+ * Create configuration optimized for development.
64
+ * Enables full tracing, disables circuit breaker, and uses longer timeouts.
65
+ *
66
+ * @param overrides - Optional configuration overrides
67
+ * @returns Complete service configuration for development
32
68
  */
33
69
  declare function createDevConfig(overrides?: Partial<ServiceConfig>): Required<ServiceConfig>;
34
70
  /**
35
- * Create config for production
71
+ * Create configuration optimized for production.
72
+ * Uses 10% sampling ratio, OTLP exporter, and enables circuit breaker.
73
+ *
74
+ * @param overrides - Optional configuration overrides
75
+ * @returns Complete service configuration for production
36
76
  */
37
77
  declare function createProdConfig(overrides?: Partial<ServiceConfig>): Required<ServiceConfig>;
38
78
  /**
39
- * Validate config
79
+ * Validate service configuration.
80
+ * Checks for valid ranges and values in the configuration.
81
+ *
82
+ * @param config - Service configuration to validate
83
+ * @returns Object containing validation result and any error messages
40
84
  */
41
85
  declare function validateConfig(config: ServiceConfig): {
42
86
  valid: boolean;
package/dist/index.js CHANGED
@@ -669,6 +669,7 @@ function createRetryWrapper(defaultOptions) {
669
669
 
670
670
  // src/resilience/timeout.ts
671
671
  var TimeoutExceededError = class extends Error {
672
+ /** The timeout value in milliseconds that was exceeded */
672
673
  timeout;
673
674
  constructor(timeout) {
674
675
  super(`Operation timed out after ${timeout}ms`);