iii-browser-sdk 0.17.0 → 0.18.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/dist/index.d.cts CHANGED
@@ -1,664 +1,5 @@
1
- import { n as IStream } from "./stream-DUoMZNRq.cjs";
1
+ import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctionInput, E as MessageType, F as RegisterTriggerMessage, I as RegisterTriggerTypeMessage, L as StreamChannelRef, M as OnTriggerTypeRegistrationInput, N as OnTriggerTypeRegistrationResult, O as OnFunctionRegistrationInput, P as RegisterFunctionMessage, R as TriggerAction$1, S as ChannelWriter, T as EnqueueResult, _ as IIIConnectionState, a as ISdk, c as RegisterTriggerInput, d as Trigger, f as TriggerTypeRef, g as EngineTriggers, h as EngineFunctions, i as FunctionRef, j as OnTriggerRegistrationResult, k as OnFunctionRegistrationResult, l as RegisterTriggerTypeInput, m as TriggerHandler, n as ApiResponse, o as RegisterFunctionInput, p as TriggerConfig, r as Channel, s as RegisterFunctionOptions, t as ApiRequest, u as RemoteFunctionHandler, v as IIIReconnectionConfig, w as AuthResult, x as ChannelReader, z as TriggerRequest } from "./types-CP-lPyex.cjs";
2
2
 
3
- //#region src/iii-types.d.ts
4
- declare enum MessageType {
5
- RegisterFunction = "registerfunction",
6
- UnregisterFunction = "unregisterfunction",
7
- InvokeFunction = "invokefunction",
8
- InvocationResult = "invocationresult",
9
- RegisterTriggerType = "registertriggertype",
10
- RegisterTrigger = "registertrigger",
11
- UnregisterTrigger = "unregistertrigger",
12
- UnregisterTriggerType = "unregistertriggertype",
13
- TriggerRegistrationResult = "triggerregistrationresult",
14
- WorkerRegistered = "workerregistered"
15
- }
16
- type RegisterTriggerTypeMessage = {
17
- message_type: MessageType.RegisterTriggerType;
18
- id: string;
19
- description: string;
20
- };
21
- type RegisterTriggerMessage = {
22
- message_type: MessageType.RegisterTrigger;
23
- id: string;
24
- type: string;
25
- function_id: string;
26
- config: unknown;
27
- };
28
- type RegisterFunctionFormat = {
29
- /**
30
- * The name of the parameter
31
- */
32
- name?: string;
33
- /**
34
- * The description of the parameter
35
- */
36
- description?: string;
37
- /**
38
- * The type of the parameter
39
- */
40
- type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer';
41
- /**
42
- * The body of the parameter (for objects)
43
- */
44
- properties?: Record<string, unknown>;
45
- /**
46
- * The items of the parameter (for arrays)
47
- */
48
- items?: unknown;
49
- /**
50
- * Whether the parameter is required
51
- */
52
- required?: string[];
53
- [key: string]: unknown;
54
- };
55
- type RegisterFunctionMessage = {
56
- message_type: MessageType.RegisterFunction;
57
- /**
58
- * The path of the function (use :: for namespacing, e.g. external::my_lambda)
59
- */
60
- id: string;
61
- /**
62
- * The description of the function
63
- */
64
- description?: string;
65
- /**
66
- * The request format of the function
67
- */
68
- request_format?: RegisterFunctionFormat;
69
- /**
70
- * The response format of the function
71
- */
72
- response_format?: RegisterFunctionFormat;
73
- metadata?: Record<string, unknown>;
74
- };
75
- /**
76
- * Routing action for {@link TriggerRequest}. Determines how the engine
77
- * handles the invocation.
78
- *
79
- * - `enqueue` -- Routes through a named queue for async processing.
80
- * - `void` -- Fire-and-forget, no response.
81
- */
82
- type TriggerAction$1 = {
83
- type: 'enqueue';
84
- queue: string;
85
- } | {
86
- type: 'void';
87
- };
88
- /**
89
- * Input passed to the RBAC auth function during WebSocket upgrade.
90
- * Contains the HTTP headers, query parameters, and client IP from the
91
- * connecting worker's upgrade request.
92
- */
93
- type AuthInput = {
94
- /** HTTP headers from the WebSocket upgrade request. */headers: Record<string, string>; /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */
95
- query_params: Record<string, string[]>; /** IP address of the connecting client. */
96
- ip_address: string;
97
- };
98
- /**
99
- * Return value from the RBAC auth function. Controls which functions the
100
- * authenticated worker can invoke and what context is forwarded to the
101
- * middleware.
102
- */
103
- type AuthResult = {
104
- /** Additional function IDs to allow beyond the `expose_functions` config. */allowed_functions: string[]; /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. */
105
- forbidden_functions: string[]; /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */
106
- allowed_trigger_types?: string[]; /** Whether the worker may register new trigger types. */
107
- allow_trigger_type_registration: boolean; /** Whether the worker may register new functions. Defaults to `true` if omitted. */
108
- allow_function_registration?: boolean; /** Arbitrary context forwarded to the middleware function on every invocation. */
109
- context: Record<string, unknown>; /** Optional prefix applied to all function IDs registered by this worker. */
110
- function_registration_prefix?: string;
111
- };
112
- /**
113
- * Input passed to the RBAC middleware function on every function invocation
114
- * through the RBAC port. The middleware can inspect, modify, or reject the
115
- * call before it reaches the target function.
116
- */
117
- type MiddlewareFunctionInput = {
118
- /** ID of the function being invoked. */function_id: string; /** Payload sent by the caller. */
119
- payload: Record<string, unknown>; /** Routing action, if any. */
120
- action?: TriggerAction$1; /** Auth context returned by the auth function for this session. */
121
- context: Record<string, unknown>;
122
- };
123
- /**
124
- * Input passed to the `on_trigger_type_registration_function_id` hook
125
- * when a worker attempts to register a new trigger type through the RBAC port.
126
- * Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)
127
- * fields, or throw to deny the registration.
128
- */
129
- type OnTriggerTypeRegistrationInput = {
130
- /** ID of the trigger type being registered. */trigger_type_id: string; /** Human-readable description of the trigger type. */
131
- description: string; /** Auth context from `AuthResult.context` for this session. */
132
- context: Record<string, unknown>;
133
- };
134
- /**
135
- * Result returned from the `on_trigger_type_registration_function_id` hook.
136
- * All fields are optional -- omitted fields keep the original value from the
137
- * registration request.
138
- */
139
- type OnTriggerTypeRegistrationResult = {
140
- /** Mapped trigger type ID. */trigger_type_id?: string; /** Mapped description. */
141
- description?: string;
142
- };
143
- /**
144
- * Input passed to the `on_trigger_registration_function_id` hook
145
- * when a worker attempts to register a trigger through the RBAC port.
146
- * Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)
147
- * fields, or throw to deny the registration.
148
- */
149
- type OnTriggerRegistrationInput = {
150
- /** ID of the trigger being registered. */trigger_id: string; /** Trigger type identifier. */
151
- trigger_type: string; /** ID of the function this trigger is bound to. */
152
- function_id: string; /** Trigger-specific configuration. */
153
- config: unknown; /** Auth context from `AuthResult.context` for this session. */
154
- context: Record<string, unknown>;
155
- };
156
- /**
157
- * Result returned from the `on_trigger_registration_function_id` hook.
158
- * All fields are optional -- omitted fields keep the original value from the
159
- * registration request.
160
- */
161
- type OnTriggerRegistrationResult = {
162
- /** Mapped trigger ID. */trigger_id?: string; /** Mapped trigger type. */
163
- trigger_type?: string; /** Mapped function ID. */
164
- function_id?: string; /** Mapped trigger configuration. */
165
- config?: unknown;
166
- };
167
- /**
168
- * Input passed to the `on_function_registration_function_id` hook
169
- * when a worker attempts to register a function through the RBAC port.
170
- * Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)
171
- * fields, or throw to deny the registration.
172
- */
173
- type OnFunctionRegistrationInput = {
174
- /** ID of the function being registered. */function_id: string; /** Human-readable description of the function. */
175
- description?: string; /** Arbitrary metadata attached to the function. */
176
- metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
177
- context: Record<string, unknown>;
178
- };
179
- /**
180
- * Result returned from the `on_function_registration_function_id` hook.
181
- * All fields are optional -- omitted fields keep the original value from the
182
- * registration request.
183
- */
184
- type OnFunctionRegistrationResult = {
185
- /** Mapped function ID. */function_id?: string; /** Mapped description. */
186
- description?: string; /** Mapped metadata. */
187
- metadata?: Record<string, unknown>;
188
- };
189
- /**
190
- * Result returned when a function is invoked with `TriggerAction.Enqueue`.
191
- */
192
- type EnqueueResult = {
193
- /** Unique receipt ID for the enqueued message. */messageReceiptId: string;
194
- };
195
- /**
196
- * Request object passed to {@link ISdk.trigger}.
197
- *
198
- * @typeParam TInput - Type of the payload.
199
- */
200
- type TriggerRequest<TInput = unknown> = {
201
- /** ID of the function to invoke. */function_id: string; /** Payload to pass to the function. */
202
- payload: TInput; /** Routing action. Omit for synchronous request/response. */
203
- action?: TriggerAction$1; /** Override the default invocation timeout in milliseconds. */
204
- timeoutMs?: number;
205
- };
206
- /**
207
- * Serializable reference to one end of a streaming channel. Can be included
208
- * in invocation payloads to pass channel endpoints between workers.
209
- */
210
- type StreamChannelRef = {
211
- /** Unique channel identifier. */channel_id: string; /** Access key for authentication. */
212
- access_key: string; /** Whether this ref is for reading or writing. */
213
- direction: 'read' | 'write';
214
- };
215
- //#endregion
216
- //#region src/channels.d.ts
217
- /**
218
- * Write end of a streaming channel. Uses native browser WebSocket.
219
- *
220
- * @example
221
- * ```typescript
222
- * const channel = await iii.createChannel()
223
- *
224
- * channel.writer.sendMessage(JSON.stringify({ type: 'event', data: 'test' }))
225
- * channel.writer.sendBinary(new Uint8Array([1, 2, 3]))
226
- * channel.writer.close()
227
- * ```
228
- */
229
- declare class ChannelWriter {
230
- private static readonly FRAME_SIZE;
231
- private ws;
232
- private wsReady;
233
- private readonly pendingMessages;
234
- private readonly url;
235
- constructor(engineWsBase: string, ref: StreamChannelRef);
236
- private ensureConnected;
237
- /** Send a text message through the channel. */
238
- sendMessage(msg: string): void;
239
- /** Send binary data through the channel. */
240
- sendBinary(data: Uint8Array): void;
241
- /** Close the channel writer. */
242
- close(): void;
243
- private sendRaw;
244
- }
245
- /**
246
- * Read end of a streaming channel. Uses native browser WebSocket.
247
- *
248
- * @example
249
- * ```typescript
250
- * const channel = await iii.createChannel()
251
- *
252
- * channel.reader.onMessage((msg) => console.log('Got:', msg))
253
- * channel.reader.onBinary((data) => console.log('Binary:', data.byteLength))
254
- * ```
255
- */
256
- declare class ChannelReader {
257
- private ws;
258
- private connected;
259
- private readonly messageCallbacks;
260
- private readonly binaryCallbacks;
261
- private readonly url;
262
- constructor(engineWsBase: string, ref: StreamChannelRef);
263
- private ensureConnected;
264
- /** Register a callback to receive text messages from the channel. */
265
- onMessage(callback: (msg: string) => void): void;
266
- /** Register a callback to receive binary data from the channel. */
267
- onBinary(callback: (data: Uint8Array) => void): void;
268
- /** Read all binary data from the channel until it closes. */
269
- readAll(): Promise<Uint8Array>;
270
- /** Close the channel reader. */
271
- close(): void;
272
- }
273
- //#endregion
274
- //#region src/iii-constants.d.ts
275
- /**
276
- * Constants for the III module.
277
- */
278
- /**
279
- * Engine function paths for internal operations.
280
- *
281
- * Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES
282
- * (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`
283
- * cover trigger INSTANCES (subscriber rows). The old
284
- * `engine::trigger-types::list` builtin has been removed and is now
285
- * served by `engine::triggers::list`.
286
- */
287
- declare const EngineFunctions: {
288
- readonly LIST_FUNCTIONS: "engine::functions::list";
289
- readonly INFO_FUNCTIONS: "engine::functions::info";
290
- readonly LIST_WORKERS: "engine::workers::list";
291
- readonly INFO_WORKERS: "engine::workers::info";
292
- readonly LIST_TRIGGERS: "engine::triggers::list";
293
- readonly INFO_TRIGGERS: "engine::triggers::info";
294
- readonly LIST_REGISTERED_TRIGGERS: "engine::registered-triggers::list";
295
- readonly INFO_REGISTERED_TRIGGERS: "engine::registered-triggers::info";
296
- readonly REGISTER_WORKER: "engine::workers::register";
297
- };
298
- /** Engine trigger types */
299
- declare const EngineTriggers: {
300
- readonly FUNCTIONS_AVAILABLE: "engine::functions-available";
301
- };
302
- /** Connection state for the III WebSocket */
303
- type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
304
- /** Configuration for WebSocket reconnection behavior */
305
- interface IIIReconnectionConfig {
306
- /** Starting delay in milliseconds (default: 1000ms) */
307
- initialDelayMs: number;
308
- /** Maximum delay cap in milliseconds (default: 30000ms) */
309
- maxDelayMs: number;
310
- /** Exponential backoff multiplier (default: 2) */
311
- backoffMultiplier: number;
312
- /** Random jitter factor 0-1 (default: 0.3) */
313
- jitterFactor: number;
314
- /** Maximum retry attempts, -1 for infinite (default: -1) */
315
- maxRetries: number;
316
- }
317
- //#endregion
318
- //#region src/triggers.d.ts
319
- /**
320
- * Configuration passed to a trigger handler when a trigger instance is
321
- * registered or unregistered.
322
- *
323
- * @typeParam TConfig - Type of the trigger-specific configuration.
324
- */
325
- type TriggerConfig<TConfig> = {
326
- /** Trigger instance ID. */id: string; /** Function to invoke when the trigger fires. */
327
- function_id: string; /** Trigger-specific configuration. */
328
- config: TConfig;
329
- };
330
- /**
331
- * Handler interface for custom trigger types. Passed to
332
- * `ISdk.registerTriggerType`.
333
- *
334
- * @typeParam TConfig - Type of the trigger-specific configuration.
335
- *
336
- * @example
337
- * ```typescript
338
- * const handler: TriggerHandler<{ interval: number }> = {
339
- * async registerTrigger({ id, function_id, config }) {
340
- * // Set up periodic invocation
341
- * },
342
- * async unregisterTrigger({ id, function_id, config }) {
343
- * // Clean up
344
- * },
345
- * }
346
- * ```
347
- */
348
- type TriggerHandler<TConfig> = {
349
- /** Called when a trigger instance is registered. */registerTrigger(config: TriggerConfig<TConfig>): Promise<void>; /** Called when a trigger instance is unregistered. */
350
- unregisterTrigger(config: TriggerConfig<TConfig>): Promise<void>;
351
- };
352
- //#endregion
353
- //#region src/types.d.ts
354
- /**
355
- * Async function handler for a registered function. Receives the invocation
356
- * payload and returns the result.
357
- *
358
- * @typeParam TInput - Type of the invocation payload.
359
- * @typeParam TOutput - Type of the return value.
360
- *
361
- * @example
362
- * ```typescript
363
- * const handler: RemoteFunctionHandler<{ name: string }, { message: string }> =
364
- * async (data) => ({ message: `Hello, ${data.name}!` })
365
- * ```
366
- */
367
- type RemoteFunctionHandler<TInput = any, TOutput = any> = (data: TInput) => Promise<TOutput>;
368
- type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'message_type' | 'id'>;
369
- type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'message_type'>;
370
- type RegisterFunctionOptions = Omit<RegisterFunctionMessage, 'message_type' | 'id'>;
371
- type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'message_type'>;
372
- interface ISdk {
373
- /**
374
- * Registers a new trigger. A trigger is a way to invoke a function when a certain event occurs.
375
- * @param trigger - The trigger to register
376
- * @returns A trigger object that can be used to unregister the trigger
377
- *
378
- * @example
379
- * ```typescript
380
- * const trigger = iii.registerTrigger({
381
- * type: 'cron',
382
- * function_id: 'my-service::process-batch',
383
- * config: { expression: '0 *\/5 * * * * *' },
384
- * })
385
- *
386
- * // Later, remove the trigger
387
- * trigger.unregister()
388
- * ```
389
- */
390
- registerTrigger(trigger: RegisterTriggerInput): Trigger;
391
- /**
392
- * Registers a new function with a local handler or an HTTP invocation config.
393
- * @param functionId - Unique function identifier
394
- * @param handler - Async handler for local execution, or an HTTP invocation config for external functions (Lambda, Cloudflare Workers, etc.)
395
- * @param options - Optional function registration options (description, request/response formats, metadata)
396
- * @returns A handle that can be used to unregister the function
397
- *
398
- * @example
399
- * ```typescript
400
- * // Local handler
401
- * const ref = iii.registerFunction(
402
- * 'greet',
403
- * async (data: { name: string }) => ({ message: `Hello, ${data.name}!` }),
404
- * { description: 'Returns a greeting' },
405
- * )
406
- *
407
- * // Later, remove the function
408
- * ref.unregister()
409
- * ```
410
- */
411
- registerFunction(functionId: string, handler: RemoteFunctionHandler, options?: RegisterFunctionOptions): FunctionRef;
412
- /**
413
- * Invokes a function using a request object.
414
- *
415
- * @param request - The trigger request containing function_id, payload, and optional action/timeout
416
- * @returns The result of the function
417
- *
418
- * @example
419
- * ```typescript
420
- * // Synchronous invocation
421
- * const result = await iii.trigger<{ name: string }, { message: string }>({
422
- * function_id: 'greet',
423
- * payload: { name: 'World' },
424
- * timeoutMs: 5000,
425
- * })
426
- * console.log(result.message) // "Hello, World!"
427
- *
428
- * // Fire-and-forget
429
- * await iii.trigger({
430
- * function_id: 'send-email',
431
- * payload: { to: 'user@example.com' },
432
- * action: TriggerAction.Void(),
433
- * })
434
- *
435
- * // Enqueue for async processing
436
- * const receipt = await iii.trigger({
437
- * function_id: 'process-order',
438
- * payload: { orderId: '123' },
439
- * action: TriggerAction.Enqueue({ queue: 'orders' }),
440
- * })
441
- * ```
442
- */
443
- trigger<TInput, TOutput>(request: TriggerRequest<TInput>): Promise<TOutput>;
444
- /**
445
- * Registers a new trigger type. A trigger type is a way to invoke a function when a certain event occurs.
446
- * @param triggerType - The trigger type to register
447
- * @param handler - The handler for the trigger type
448
- * @returns A trigger type object that can be used to unregister the trigger type
449
- *
450
- * @example
451
- * ```typescript
452
- * type CronConfig = { expression: string }
453
- *
454
- * iii.registerTriggerType<CronConfig>(
455
- * { id: 'cron', description: 'Fires on a cron schedule' },
456
- * {
457
- * async registerTrigger({ id, function_id, config }) {
458
- * startCronJob(id, config.expression, () =>
459
- * iii.trigger({ function_id, payload: {} }),
460
- * )
461
- * },
462
- * async unregisterTrigger({ id }) {
463
- * stopCronJob(id)
464
- * },
465
- * },
466
- * )
467
- * ```
468
- */
469
- registerTriggerType<TConfig>(triggerType: RegisterTriggerTypeInput, handler: TriggerHandler<TConfig>): TriggerTypeRef<TConfig>;
470
- /**
471
- * Unregisters a trigger type.
472
- * @param triggerType - The trigger type to unregister
473
- *
474
- * @example
475
- * ```typescript
476
- * iii.unregisterTriggerType({ id: 'cron', description: 'Fires on a cron schedule' })
477
- * ```
478
- */
479
- unregisterTriggerType(triggerType: RegisterTriggerTypeInput): void;
480
- /**
481
- * Creates a streaming channel pair for worker-to-worker data transfer.
482
- * Returns a Channel with a local writer/reader and serializable refs that
483
- * can be passed as fields in the invocation data to other functions.
484
- *
485
- * @param bufferSize - Optional buffer size for the channel (default: 64)
486
- * @returns A Channel with writer, reader, and their serializable refs
487
- *
488
- * @example
489
- * ```typescript
490
- * const channel = await iii.createChannel()
491
- *
492
- * // Pass the writer ref to another function
493
- * await iii.trigger({
494
- * function_id: 'stream-producer',
495
- * payload: { outputChannel: channel.writerRef },
496
- * })
497
- *
498
- * // Read data locally
499
- * channel.reader.onMessage((msg) => {
500
- * console.log('Received:', msg)
501
- * })
502
- * ```
503
- */
504
- createChannel(bufferSize?: number): Promise<Channel>;
505
- /**
506
- * Creates a new stream implementation.
507
- *
508
- * This overrides the default stream implementation.
509
- *
510
- * @param streamName - The name of the stream
511
- * @param stream - The stream implementation
512
- *
513
- * @example
514
- * ```typescript
515
- * iii.createStream('sessions', {
516
- * async get({ group_id, item_id }) { return null },
517
- * async set({ group_id, item_id, data }) { return { new_value: data } },
518
- * async delete({ group_id, item_id }) { return {} },
519
- * async list({ group_id }) { return [] },
520
- * async listGroups() { return [] },
521
- * async update() { return null },
522
- * })
523
- * ```
524
- */
525
- createStream<TData>(streamName: string, stream: IStream<TData>): void;
526
- /**
527
- * Gracefully shutdown the iii, cleaning up all resources.
528
- *
529
- * @example
530
- * ```typescript
531
- * await iii.shutdown()
532
- * ```
533
- */
534
- shutdown(): Promise<void>;
535
- /**
536
- * Subscribe to connection-state transitions. The handler is fired immediately
537
- * with the current state, then on every transition. Multiple listeners are
538
- * supported. Returns an unsubscribe function.
539
- *
540
- * @example
541
- * ```typescript
542
- * const unsub = iii.addConnectionStateListener((state) => {
543
- * console.log('connection state:', state)
544
- * })
545
- *
546
- * // Later, stop receiving updates
547
- * unsub()
548
- * ```
549
- */
550
- addConnectionStateListener(handler: (state: IIIConnectionState) => void): () => void;
551
- }
552
- /**
553
- * Handle returned by {@link ISdk.registerTrigger}. Use `unregister()` to
554
- * remove the trigger from the engine.
555
- */
556
- type Trigger = {
557
- /** Removes this trigger from the engine. */unregister(): void;
558
- };
559
- /**
560
- * Handle returned by {@link ISdk.registerFunction}. Contains the function's
561
- * `id` and an `unregister()` method.
562
- */
563
- type FunctionRef = {
564
- /** The unique function identifier. */id: string; /** Removes this function from the engine. */
565
- unregister: () => void;
566
- };
567
- /**
568
- * Typed handle returned by {@link ISdk.registerTriggerType}.
569
- *
570
- * Provides convenience methods to register triggers and functions scoped
571
- * to this trigger type, so callers don't need to repeat the `type` field.
572
- *
573
- * @typeParam TConfig - Trigger-specific configuration type.
574
- *
575
- * @example
576
- * ```typescript
577
- * type CronConfig = { expression: string }
578
- *
579
- * const cron = iii.registerTriggerType<CronConfig>(
580
- * { id: 'cron', description: 'Fires on a cron schedule' },
581
- * cronHandler,
582
- * )
583
- *
584
- * // Register a trigger -- type is inferred as CronConfig
585
- * cron.registerTrigger('my::fn', { expression: '0 *\/5 * * * * *' })
586
- *
587
- * // Register a function and bind a trigger in one call
588
- * cron.registerFunction(
589
- * 'my::fn',
590
- * async (data) => { return { ok: true } },
591
- * { expression: '0 *\/5 * * * * *' },
592
- * )
593
- * ```
594
- */
595
- type TriggerTypeRef<TConfig = unknown> = {
596
- /** The trigger type identifier. */id: string;
597
- /**
598
- * Register a trigger bound to this trigger type.
599
- *
600
- * @param functionId - The function to invoke when the trigger fires.
601
- * @param config - Trigger-specific configuration.
602
- * @returns A {@link Trigger} handle with an `unregister()` method.
603
- */
604
- registerTrigger(functionId: string, config: TConfig): Trigger;
605
- /**
606
- * Register a function and immediately bind it to this trigger type.
607
- *
608
- * @param functionId - Unique function identifier.
609
- * @param handler - Local function handler.
610
- * @param config - Trigger-specific configuration.
611
- * @returns A {@link FunctionRef} handle.
612
- */
613
- registerFunction(functionId: string, handler: RemoteFunctionHandler, config: TConfig): FunctionRef;
614
- /**
615
- * Unregister this trigger type from the engine.
616
- */
617
- unregister(): void;
618
- };
619
- /**
620
- * A streaming channel pair for worker-to-worker data transfer. Created via
621
- * {@link ISdk.createChannel}.
622
- */
623
- type Channel = {
624
- /** Writer end of the channel. */writer: ChannelWriter; /** Reader end of the channel. */
625
- reader: ChannelReader; /** Serializable reference to the writer (can be sent to other workers). */
626
- writerRef: StreamChannelRef; /** Serializable reference to the reader (can be sent to other workers). */
627
- readerRef: StreamChannelRef;
628
- };
629
- /**
630
- * Incoming HTTP request received by a function registered with an HTTP trigger.
631
- *
632
- * @typeParam TBody - Type of the parsed request body.
633
- */
634
- type ApiRequest<TBody = unknown> = {
635
- path_params: Record<string, string>;
636
- query_params: Record<string, string | string[]>;
637
- body: TBody;
638
- headers: Record<string, string | string[]>;
639
- method: string;
640
- };
641
- /**
642
- * Structured API response returned from HTTP function handlers.
643
- *
644
- * @typeParam TStatus - HTTP status code literal type.
645
- * @typeParam TBody - Type of the response body.
646
- *
647
- * @example
648
- * ```typescript
649
- * const response: ApiResponse = {
650
- * status_code: 200,
651
- * headers: { 'content-type': 'application/json' },
652
- * body: { message: 'ok' },
653
- * }
654
- * ```
655
- */
656
- type ApiResponse<TStatus extends number = number, TBody = string | Record<string, unknown>> = {
657
- /** HTTP status code. */status_code: TStatus; /** Response headers. */
658
- headers?: Record<string, string>; /** Response body. */
659
- body?: TBody;
660
- };
661
- //#endregion
662
3
  //#region src/iii.d.ts
663
4
  /**
664
5
  * Configuration options passed to {@link registerWorker}.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/iii-types.ts","../src/channels.ts","../src/iii-constants.ts","../src/triggers.ts","../src/types.ts","../src/iii.ts"],"mappings":";;;aAAY,WAAA;EACV,gBAAA;EACA,kBAAA;EACA,cAAA;EACA,gBAAA;EACA,mBAAA;EACA,eAAA;EACA,iBAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;AAAA;AAAA,KAGU,0BAAA;EACV,YAAA,EAAc,WAAA,CAAY,mBAAA;EAC1B,EAAA;EACA,WAAA;AAAA;AAAA,KAuBU,sBAAA;EACV,YAAA,EAAc,WAAA,CAAY,eAAA;EAC1B,EAAA;EACA,IAAA;EACA,WAAA;EACA,MAAA;AAAA;AAAA,KAGU,sBAAA;EAHJ;AAGR;;EAIE,IAAA;EAYmB;;;EARnB,WAAA;EAQA;;;EAJA,IAAA;EAaC;;;EATD,UAAA,GAAa,MAAA;EAYoB;;;EARjC,KAAA;EAyBkB;;;EArBlB,QAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGS,uBAAA;EACV,YAAA,EAAc,WAAA,CAAY,gBAAA;EAQ1B;;;EAJA,EAAA;EAYkB;;;EARlB,WAAA;EASiB;AAUnB;;EAfE,cAAA,GAAiB,sBAAA;EAeM;;;EAXvB,eAAA,GAAkB,sBAAA;EAClB,QAAA,GAAW,MAAA;AAAA;AAiBb;;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