iii-sdk 0.19.7 → 0.20.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/channel.cjs +5 -0
- package/dist/channel.d.cts +2 -0
- package/dist/channel.d.mts +2 -0
- package/dist/channel.mjs +3 -0
- package/dist/{utils-DXL7JI0q.mjs → channels-De8fNMyx.mjs} +3 -108
- package/dist/channels-De8fNMyx.mjs.map +1 -0
- package/dist/{utils-CuS1Knym.cjs → channels-ZbQzcwnN.cjs} +3 -166
- package/dist/channels-ZbQzcwnN.cjs.map +1 -0
- package/dist/engine.cjs +5 -0
- package/dist/engine.d.cts +3 -0
- package/dist/engine.d.mts +3 -0
- package/dist/engine.mjs +3 -0
- package/dist/errors.cjs +28 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +40 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +40 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +25 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/helpers.cjs +6 -5
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +23 -5
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +23 -5
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +4 -3
- package/dist/helpers.mjs.map +1 -1
- package/dist/iii-constants-Baptl8nm.d.mts +47 -0
- package/dist/iii-constants-Baptl8nm.d.mts.map +1 -0
- package/dist/iii-constants-BqXp8xSN.d.cts +47 -0
- package/dist/iii-constants-BqXp8xSN.d.cts.map +1 -0
- package/dist/iii-constants-Br94RUNi.cjs +67 -0
- package/dist/iii-constants-Br94RUNi.cjs.map +1 -0
- package/dist/iii-constants-_k3SoHry.mjs +43 -0
- package/dist/iii-constants-_k3SoHry.mjs.map +1 -0
- package/dist/iii-types-6aHBgy7l.cjs +24 -0
- package/dist/iii-types-6aHBgy7l.cjs.map +1 -0
- package/dist/iii-types-CRx2qAjB.mjs +18 -0
- package/dist/iii-types-CRx2qAjB.mjs.map +1 -0
- package/dist/index.cjs +81 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -81
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +14 -81
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +18 -94
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +0 -0
- package/dist/internal.d.cts +2 -0
- package/dist/internal.d.mts +2 -0
- package/dist/internal.mjs +1 -0
- package/dist/protocol.cjs +4 -0
- package/dist/protocol.d.cts +2 -0
- package/dist/protocol.d.mts +2 -0
- package/dist/protocol.mjs +3 -0
- package/dist/runtime.cjs +0 -0
- package/dist/runtime.d.cts +3 -0
- package/dist/runtime.d.mts +3 -0
- package/dist/runtime.mjs +1 -0
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +3 -7
- package/dist/state.d.cts.map +1 -1
- package/dist/state.d.mts +3 -7
- package/dist/state.d.mts.map +1 -1
- package/dist/state.mjs.map +1 -1
- package/dist/stream.d.cts +5 -246
- package/dist/stream.d.cts.map +1 -1
- package/dist/stream.d.mts +5 -246
- package/dist/stream.d.mts.map +1 -1
- package/dist/trigger.cjs +0 -0
- package/dist/trigger.d.cts +2 -0
- package/dist/trigger.d.mts +2 -0
- package/dist/trigger.mjs +1 -0
- package/dist/{utils-BnRzIUCy.d.cts → types-ChnmRit-.d.mts} +30 -217
- package/dist/types-ChnmRit-.d.mts.map +1 -0
- package/dist/{utils-e84Qph-9.d.mts → types-pzKubHk_.d.cts} +30 -217
- package/dist/types-pzKubHk_.d.cts.map +1 -0
- package/dist/utils-63wxBJg-.cjs +121 -0
- package/dist/utils-63wxBJg-.cjs.map +1 -0
- package/dist/utils-8G4hHqvZ.mjs +69 -0
- package/dist/utils-8G4hHqvZ.mjs.map +1 -0
- package/package.json +37 -2
- package/typedoc.json +13 -1
- package/vitest.config.ts +3 -3
- package/dist/utils-BnRzIUCy.d.cts.map +0 -1
- package/dist/utils-CuS1Knym.cjs.map +0 -1
- package/dist/utils-DXL7JI0q.mjs.map +0 -1
- package/dist/utils-e84Qph-9.d.mts.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Readable, Writable } from "node:stream";
|
|
2
|
+
import { HttpInvocationConfig } from "@iii-dev/helpers/http";
|
|
2
3
|
|
|
3
4
|
//#region src/iii-types.d.ts
|
|
4
5
|
declare enum MessageType {
|
|
@@ -18,6 +19,11 @@ type RegisterTriggerTypeMessage = {
|
|
|
18
19
|
id: string;
|
|
19
20
|
description: string;
|
|
20
21
|
};
|
|
22
|
+
type ErrorBody = {
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
stacktrace?: string;
|
|
26
|
+
};
|
|
21
27
|
type RegisterTriggerMessage = {
|
|
22
28
|
message_type: MessageType.RegisterTrigger;
|
|
23
29
|
id: string;
|
|
@@ -26,35 +32,6 @@ type RegisterTriggerMessage = {
|
|
|
26
32
|
config: unknown;
|
|
27
33
|
metadata?: Record<string, unknown>;
|
|
28
34
|
};
|
|
29
|
-
/**
|
|
30
|
-
* Authentication configuration for HTTP-invoked functions.
|
|
31
|
-
*
|
|
32
|
-
* - `hmac` -- HMAC signature verification using a shared secret.
|
|
33
|
-
* - `bearer` -- Bearer token authentication.
|
|
34
|
-
* - `api_key` -- API key sent via a custom header.
|
|
35
|
-
*/
|
|
36
|
-
type HttpAuthConfig = {
|
|
37
|
-
type: 'hmac';
|
|
38
|
-
secret_key: string;
|
|
39
|
-
} | {
|
|
40
|
-
type: 'bearer';
|
|
41
|
-
token_key: string;
|
|
42
|
-
} | {
|
|
43
|
-
type: 'api_key';
|
|
44
|
-
header: string;
|
|
45
|
-
value_key: string;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Configuration for registering an HTTP-invoked function (Lambda, Cloudflare
|
|
49
|
-
* Workers, etc.) instead of a local handler.
|
|
50
|
-
*/
|
|
51
|
-
type HttpInvocationConfig = {
|
|
52
|
-
/** URL to invoke. */url: string; /** HTTP method. Defaults to `POST`. */
|
|
53
|
-
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** Timeout in milliseconds. */
|
|
54
|
-
timeout_ms?: number; /** Custom headers to send with the request. */
|
|
55
|
-
headers?: Record<string, string>; /** Authentication configuration. */
|
|
56
|
-
auth?: HttpAuthConfig;
|
|
57
|
-
};
|
|
58
35
|
type RegisterFunctionFormat = {
|
|
59
36
|
/**
|
|
60
37
|
* The name of the parameter
|
|
@@ -119,30 +96,6 @@ type TriggerAction = {
|
|
|
119
96
|
} | {
|
|
120
97
|
type: 'void';
|
|
121
98
|
};
|
|
122
|
-
/**
|
|
123
|
-
* Input passed to the RBAC auth function during WebSocket upgrade.
|
|
124
|
-
* Contains the HTTP headers, query parameters, and client IP from the
|
|
125
|
-
* connecting worker's upgrade request.
|
|
126
|
-
*/
|
|
127
|
-
type AuthInput = {
|
|
128
|
-
/** 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. */
|
|
129
|
-
query_params: Record<string, string[]>; /** IP address of the connecting client. */
|
|
130
|
-
ip_address: string;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Return value from the RBAC auth function. Controls which functions the
|
|
134
|
-
* authenticated worker can invoke and what context is forwarded to the
|
|
135
|
-
* middleware.
|
|
136
|
-
*/
|
|
137
|
-
type AuthResult = {
|
|
138
|
-
/** 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. */
|
|
139
|
-
forbidden_functions: string[]; /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */
|
|
140
|
-
allowed_trigger_types?: string[]; /** Whether the worker may register new trigger types. */
|
|
141
|
-
allow_trigger_type_registration: boolean; /** Whether the worker may register new functions. Defaults to `true` if omitted. */
|
|
142
|
-
allow_function_registration?: boolean; /** Arbitrary context forwarded to the middleware function on every invocation. */
|
|
143
|
-
context: Record<string, unknown>; /** Optional prefix applied to all function IDs registered by this worker. */
|
|
144
|
-
function_registration_prefix?: string;
|
|
145
|
-
};
|
|
146
99
|
/**
|
|
147
100
|
* Input passed to the RBAC middleware function on every function invocation
|
|
148
101
|
* through the RBAC port. The middleware can inspect, modify, or reject the
|
|
@@ -155,80 +108,7 @@ type MiddlewareFunctionInput = {
|
|
|
155
108
|
context: Record<string, unknown>;
|
|
156
109
|
};
|
|
157
110
|
/**
|
|
158
|
-
*
|
|
159
|
-
* when a worker attempts to register a new trigger type through the RBAC port.
|
|
160
|
-
* Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)
|
|
161
|
-
* fields, or throw to deny the registration.
|
|
162
|
-
*/
|
|
163
|
-
type OnTriggerTypeRegistrationInput = {
|
|
164
|
-
/** ID of the trigger type being registered. */trigger_type_id: string; /** Human-readable description of the trigger type. */
|
|
165
|
-
description: string; /** Auth context from `AuthResult.context` for this session. */
|
|
166
|
-
context: Record<string, unknown>;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Result returned from the `on_trigger_type_registration_function_id` hook.
|
|
170
|
-
* All fields are optional -- omitted fields keep the original value from the
|
|
171
|
-
* registration request.
|
|
172
|
-
*/
|
|
173
|
-
type OnTriggerTypeRegistrationResult = {
|
|
174
|
-
/** Mapped trigger type ID. */trigger_type_id?: string; /** Mapped description. */
|
|
175
|
-
description?: string;
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Input passed to the `on_trigger_registration_function_id` hook
|
|
179
|
-
* when a worker attempts to register a trigger through the RBAC port.
|
|
180
|
-
* Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)
|
|
181
|
-
* fields, or throw to deny the registration.
|
|
182
|
-
*/
|
|
183
|
-
type OnTriggerRegistrationInput = {
|
|
184
|
-
/** ID of the trigger being registered. */trigger_id: string; /** Trigger type identifier. */
|
|
185
|
-
trigger_type: string; /** ID of the function this trigger is bound to. */
|
|
186
|
-
function_id: string; /** Trigger-specific configuration. */
|
|
187
|
-
config: unknown; /** Arbitrary metadata attached to the trigger. */
|
|
188
|
-
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
189
|
-
context: Record<string, unknown>;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Result returned from the `on_trigger_registration_function_id` hook.
|
|
193
|
-
* All fields are optional -- omitted fields keep the original value from the
|
|
194
|
-
* registration request.
|
|
195
|
-
*/
|
|
196
|
-
type OnTriggerRegistrationResult = {
|
|
197
|
-
/** Mapped trigger ID. */trigger_id?: string; /** Mapped trigger type. */
|
|
198
|
-
trigger_type?: string; /** Mapped function ID. */
|
|
199
|
-
function_id?: string; /** Mapped trigger configuration. */
|
|
200
|
-
config?: unknown;
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Input passed to the `on_function_registration_function_id` hook
|
|
204
|
-
* when a worker attempts to register a function through the RBAC port.
|
|
205
|
-
* Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)
|
|
206
|
-
* fields, or throw to deny the registration.
|
|
207
|
-
*/
|
|
208
|
-
type OnFunctionRegistrationInput = {
|
|
209
|
-
/** ID of the function being registered. */function_id: string; /** Human-readable description of the function. */
|
|
210
|
-
description?: string; /** Arbitrary metadata attached to the function. */
|
|
211
|
-
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
212
|
-
context: Record<string, unknown>;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Result returned from the `on_function_registration_function_id` hook.
|
|
216
|
-
* All fields are optional -- omitted fields keep the original value from the
|
|
217
|
-
* registration request.
|
|
218
|
-
*/
|
|
219
|
-
type OnFunctionRegistrationResult = {
|
|
220
|
-
/** Mapped function ID. */function_id?: string; /** Mapped description. */
|
|
221
|
-
description?: string; /** Mapped metadata. */
|
|
222
|
-
metadata?: Record<string, unknown>;
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* Result returned when a function is invoked with `TriggerAction.Enqueue`.
|
|
226
|
-
*/
|
|
227
|
-
type EnqueueResult = {
|
|
228
|
-
/** Unique receipt ID for the enqueued message. */messageReceiptId: string;
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Request object passed to {@link ISdk.trigger}.
|
|
111
|
+
* Request object passed to {@link IIIClient.trigger}.
|
|
232
112
|
*
|
|
233
113
|
* @typeParam TInput - Type of the payload.
|
|
234
114
|
*/
|
|
@@ -357,7 +237,7 @@ type TriggerConfig<TConfig> = {
|
|
|
357
237
|
};
|
|
358
238
|
/**
|
|
359
239
|
* Handler interface for custom trigger types. Passed to
|
|
360
|
-
* `
|
|
240
|
+
* `IIIClient.registerTriggerType`.
|
|
361
241
|
*
|
|
362
242
|
* @typeParam TConfig - Type of the trigger-specific configuration.
|
|
363
243
|
*
|
|
@@ -397,7 +277,7 @@ type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'message_type' | 'id'>;
|
|
|
397
277
|
type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'message_type'>;
|
|
398
278
|
type RegisterFunctionOptions = Omit<RegisterFunctionMessage, 'message_type' | 'id'>;
|
|
399
279
|
type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'message_type'>;
|
|
400
|
-
interface
|
|
280
|
+
interface IIIClient {
|
|
401
281
|
/**
|
|
402
282
|
* Registers a new trigger. A trigger is a way to invoke a function when a certain event occurs.
|
|
403
283
|
* @param trigger - The trigger to register
|
|
@@ -405,7 +285,7 @@ interface ISdk {
|
|
|
405
285
|
*
|
|
406
286
|
* @example
|
|
407
287
|
* ```typescript
|
|
408
|
-
* const trigger =
|
|
288
|
+
* const trigger = worker.registerTrigger({
|
|
409
289
|
* type: 'cron',
|
|
410
290
|
* function_id: 'my-service::process-batch',
|
|
411
291
|
* config: { expression: '0 *\/5 * * * * *' },
|
|
@@ -426,14 +306,14 @@ interface ISdk {
|
|
|
426
306
|
* @example
|
|
427
307
|
* ```typescript
|
|
428
308
|
* // Local handler
|
|
429
|
-
* const ref =
|
|
309
|
+
* const ref = worker.registerFunction(
|
|
430
310
|
* 'greet',
|
|
431
311
|
* async (data: { name: string }) => ({ message: `Hello, ${data.name}!` }),
|
|
432
312
|
* { description: 'Returns a greeting' },
|
|
433
313
|
* )
|
|
434
314
|
*
|
|
435
315
|
* // HTTP invocation
|
|
436
|
-
* const lambdaRef =
|
|
316
|
+
* const lambdaRef = worker.registerFunction(
|
|
437
317
|
* 'external::my-lambda',
|
|
438
318
|
* {
|
|
439
319
|
* url: 'https://abc123.lambda-url.us-east-1.on.aws',
|
|
@@ -458,7 +338,7 @@ interface ISdk {
|
|
|
458
338
|
* @example
|
|
459
339
|
* ```typescript
|
|
460
340
|
* // Synchronous invocation
|
|
461
|
-
* const result = await
|
|
341
|
+
* const result = await worker.trigger<{ name: string }, { message: string }>({
|
|
462
342
|
* function_id: 'greet',
|
|
463
343
|
* payload: { name: 'World' },
|
|
464
344
|
* timeoutMs: 5000,
|
|
@@ -466,14 +346,14 @@ interface ISdk {
|
|
|
466
346
|
* console.log(result.message) // "Hello, World!"
|
|
467
347
|
*
|
|
468
348
|
* // Fire-and-forget
|
|
469
|
-
* await
|
|
349
|
+
* await worker.trigger({
|
|
470
350
|
* function_id: 'send-email',
|
|
471
351
|
* payload: { to: 'user@example.com' },
|
|
472
352
|
* action: TriggerAction.Void(),
|
|
473
353
|
* })
|
|
474
354
|
*
|
|
475
355
|
* // Enqueue for async processing
|
|
476
|
-
* const receipt = await
|
|
356
|
+
* const receipt = await worker.trigger({
|
|
477
357
|
* function_id: 'process-order',
|
|
478
358
|
* payload: { orderId: '123' },
|
|
479
359
|
* action: TriggerAction.Enqueue({ queue: 'orders' }),
|
|
@@ -491,12 +371,12 @@ interface ISdk {
|
|
|
491
371
|
* ```typescript
|
|
492
372
|
* type CronConfig = { expression: string }
|
|
493
373
|
*
|
|
494
|
-
*
|
|
374
|
+
* worker.registerTriggerType<CronConfig>(
|
|
495
375
|
* { id: 'cron', description: 'Fires on a cron schedule' },
|
|
496
376
|
* {
|
|
497
377
|
* async registerTrigger({ id, function_id, config }) {
|
|
498
378
|
* startCronJob(id, config.expression, () =>
|
|
499
|
-
*
|
|
379
|
+
* worker.trigger({ function_id, payload: {} }),
|
|
500
380
|
* )
|
|
501
381
|
* },
|
|
502
382
|
* async unregisterTrigger({ id }) {
|
|
@@ -513,7 +393,7 @@ interface ISdk {
|
|
|
513
393
|
*
|
|
514
394
|
* @example
|
|
515
395
|
* ```typescript
|
|
516
|
-
*
|
|
396
|
+
* worker.unregisterTriggerType({ id: 'cron', description: 'Fires on a cron schedule' })
|
|
517
397
|
* ```
|
|
518
398
|
*/
|
|
519
399
|
unregisterTriggerType(triggerType: RegisterTriggerTypeInput): void;
|
|
@@ -523,7 +403,7 @@ interface ISdk {
|
|
|
523
403
|
* @example
|
|
524
404
|
* ```typescript
|
|
525
405
|
* process.on('SIGTERM', async () => {
|
|
526
|
-
* await
|
|
406
|
+
* await worker.shutdown()
|
|
527
407
|
* process.exit(0)
|
|
528
408
|
* })
|
|
529
409
|
* ```
|
|
@@ -531,14 +411,14 @@ interface ISdk {
|
|
|
531
411
|
shutdown(): Promise<void>;
|
|
532
412
|
}
|
|
533
413
|
/**
|
|
534
|
-
* Handle returned by {@link
|
|
414
|
+
* Handle returned by {@link IIIClient.registerTrigger}. Use `unregister()` to
|
|
535
415
|
* remove the trigger from the engine.
|
|
536
416
|
*/
|
|
537
417
|
type Trigger = {
|
|
538
418
|
/** Removes this trigger from the engine. */unregister(): void;
|
|
539
419
|
};
|
|
540
420
|
/**
|
|
541
|
-
* Handle returned by {@link
|
|
421
|
+
* Handle returned by {@link IIIClient.registerFunction}. Contains the function's
|
|
542
422
|
* `id` and an `unregister()` method.
|
|
543
423
|
*/
|
|
544
424
|
type FunctionRef = {
|
|
@@ -546,7 +426,7 @@ type FunctionRef = {
|
|
|
546
426
|
unregister: () => void;
|
|
547
427
|
};
|
|
548
428
|
/**
|
|
549
|
-
* Typed handle returned by {@link
|
|
429
|
+
* Typed handle returned by {@link IIIClient.registerTriggerType}.
|
|
550
430
|
*
|
|
551
431
|
* Provides convenience methods to register triggers and functions scoped
|
|
552
432
|
* to this trigger type, so callers don't need to repeat the `type` field.
|
|
@@ -557,12 +437,12 @@ type FunctionRef = {
|
|
|
557
437
|
* ```typescript
|
|
558
438
|
* type CronConfig = { expression: string }
|
|
559
439
|
*
|
|
560
|
-
* const cron =
|
|
440
|
+
* const cron = worker.registerTriggerType<CronConfig>(
|
|
561
441
|
* { id: 'cron', description: 'Fires on a cron schedule' },
|
|
562
442
|
* cronHandler,
|
|
563
443
|
* )
|
|
564
444
|
*
|
|
565
|
-
* // Register a trigger
|
|
445
|
+
* // Register a trigger, type is inferred as CronConfig
|
|
566
446
|
* cron.registerTrigger('my::fn', { expression: '0 *\/5 * * * * *' })
|
|
567
447
|
*
|
|
568
448
|
* // Register a function and bind a trigger in one call
|
|
@@ -619,89 +499,22 @@ type InternalHttpRequest<TBody = unknown> = {
|
|
|
619
499
|
request_body: ChannelReader;
|
|
620
500
|
};
|
|
621
501
|
/**
|
|
622
|
-
* Response object passed to
|
|
502
|
+
* Response object passed to streaming function handlers. Use `status()` and
|
|
623
503
|
* `headers()` to set response metadata, write to `stream` for streaming
|
|
624
504
|
* responses, and call `close()` when done.
|
|
625
505
|
*/
|
|
626
|
-
type
|
|
506
|
+
type StreamResponse = {
|
|
627
507
|
/** Set the HTTP status code. */status: (statusCode: number) => void; /** Set response headers. */
|
|
628
508
|
headers: (headers: Record<string, string>) => void; /** Writable stream for the response body. */
|
|
629
509
|
stream: NodeJS.WritableStream; /** Close the response. */
|
|
630
510
|
close: () => void;
|
|
631
511
|
};
|
|
632
512
|
/**
|
|
633
|
-
* Incoming
|
|
634
|
-
*
|
|
635
|
-
* @typeParam TBody - Type of the parsed request body.
|
|
636
|
-
*/
|
|
637
|
-
type HttpRequest<TBody = unknown> = Omit<InternalHttpRequest<TBody>, 'response'>;
|
|
638
|
-
/**
|
|
639
|
-
* Alias for {@link HttpRequest}. Represents an incoming API request.
|
|
513
|
+
* Incoming streaming request received by a function registered with a stream trigger.
|
|
640
514
|
*
|
|
641
515
|
* @typeParam TBody - Type of the parsed request body.
|
|
642
516
|
*/
|
|
643
|
-
type
|
|
644
|
-
/**
|
|
645
|
-
* Structured API response returned from HTTP function handlers.
|
|
646
|
-
*
|
|
647
|
-
* @typeParam TStatus - HTTP status code literal type.
|
|
648
|
-
* @typeParam TBody - Type of the response body.
|
|
649
|
-
*
|
|
650
|
-
* @example
|
|
651
|
-
* ```typescript
|
|
652
|
-
* const response: ApiResponse = {
|
|
653
|
-
* status_code: 200,
|
|
654
|
-
* headers: { 'content-type': 'application/json' },
|
|
655
|
-
* body: { message: 'ok' },
|
|
656
|
-
* }
|
|
657
|
-
* ```
|
|
658
|
-
*/
|
|
659
|
-
type ApiResponse<TStatus extends number = number, TBody = string | Buffer | Record<string, unknown>> = {
|
|
660
|
-
/** HTTP status code. */status_code: TStatus; /** Response headers. */
|
|
661
|
-
headers?: Record<string, string>; /** Response body. */
|
|
662
|
-
body?: TBody;
|
|
663
|
-
};
|
|
664
|
-
//#endregion
|
|
665
|
-
//#region src/utils.d.ts
|
|
666
|
-
/**
|
|
667
|
-
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
668
|
-
* into the function handler format expected by the SDK.
|
|
669
|
-
*
|
|
670
|
-
* @param callback - Async handler receiving an {@link HttpRequest} and {@link HttpResponse}.
|
|
671
|
-
* @returns A function handler compatible with {@link ISdk.registerFunction}.
|
|
672
|
-
*
|
|
673
|
-
* @example
|
|
674
|
-
* ```typescript
|
|
675
|
-
* import { http } from 'iii-sdk'
|
|
676
|
-
*
|
|
677
|
-
* iii.registerFunction(
|
|
678
|
-
* 'my-api',
|
|
679
|
-
* http(async (req, res) => {
|
|
680
|
-
* res.status(200)
|
|
681
|
-
* res.headers({ 'content-type': 'application/json' })
|
|
682
|
-
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
683
|
-
* res.close()
|
|
684
|
-
* }),
|
|
685
|
-
* )
|
|
686
|
-
* ```
|
|
687
|
-
*/
|
|
688
|
-
declare const http: (callback: (req: HttpRequest, res: HttpResponse) => Promise<void | ApiResponse>) => (req: InternalHttpRequest) => Promise<void | ApiResponse>;
|
|
689
|
-
/**
|
|
690
|
-
* Type guard that checks if a value is a {@link StreamChannelRef}.
|
|
691
|
-
*
|
|
692
|
-
* @param value - Value to check.
|
|
693
|
-
* @returns `true` if the value is a valid `StreamChannelRef`.
|
|
694
|
-
*/
|
|
695
|
-
declare const isChannelRef: (value: unknown) => value is StreamChannelRef;
|
|
696
|
-
/**
|
|
697
|
-
* Recursively extract all {@link StreamChannelRef} values from a JSON-like
|
|
698
|
-
* input, returning each match paired with its dotted/bracketed path. Mirrors
|
|
699
|
-
* the Rust SDK's `extract_channel_refs`.
|
|
700
|
-
*
|
|
701
|
-
* @param data - Arbitrary JSON-like value.
|
|
702
|
-
* @returns Array of `[path, ref]` tuples. Empty when no refs are found.
|
|
703
|
-
*/
|
|
704
|
-
declare const extractChannelRefs: (data: unknown) => Array<[string, StreamChannelRef]>;
|
|
517
|
+
type StreamRequest<TBody = unknown> = Omit<InternalHttpRequest<TBody>, 'response'>;
|
|
705
518
|
//#endregion
|
|
706
|
-
export {
|
|
707
|
-
//# sourceMappingURL=
|
|
519
|
+
export { RegisterFunctionFormat as C, StreamChannelRef as D, RegisterTriggerTypeMessage as E, TriggerRequest as O, MiddlewareFunctionInput as S, RegisterTriggerMessage as T, ChannelItem as _, RegisterFunctionInput as a, ErrorBody as b, RegisterTriggerTypeInput as c, StreamResponse as d, Trigger as f, ChannelDirection as g, TriggerHandler as h, InternalHttpRequest as i, RemoteFunctionHandler as l, TriggerConfig as m, FunctionRef as n, RegisterFunctionOptions as o, TriggerTypeRef as p, IIIClient as r, RegisterTriggerInput as s, Channel as t, StreamRequest as u, ChannelReader as v, RegisterFunctionMessage as w, MessageType as x, ChannelWriter as y };
|
|
520
|
+
//# sourceMappingURL=types-pzKubHk_.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-pzKubHk_.d.cts","names":[],"sources":["../src/iii-types.ts","../src/channels.ts","../src/triggers.ts","../src/types.ts"],"mappings":";;;;aAEY,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,KAcU,SAAA;EACV,IAAA;EACA,OAAA;EACA,UAAA;AAAA;AAAA,KAWU,sBAAA;EACV,YAAA,EAAc,WAAA,CAAY,eAAA;EAC1B,EAAA;EACA,IAAA;EACA,WAAA;EACA,MAAA;EACA,QAAA,GAAW,MAAA;AAAA;AAAA,KAGD,sBAAA;EANV;;;EAUA,IAAA;EAPW;;;EAWX,WAAA;EARgC;;;EAYhC,IAAA;EAJA;;;EAQA,UAAA,GAAa,MAAA;EAIb;;;EAAA,KAAA;EAKY;AAGd;;EAJE,QAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGS,uBAAA;EACV,YAAA,EAAc,WAAA,CAAY,gBAAA;EAqBb;;;EAjBb,EAAA;EAJc;;;EAQd,WAAA;EAIA;;;EAAA,cAAA,GAAiB,sBAAA;EAKjB;;;EADA,eAAA,GAAkB,sBAAA;EAClB,QAAA,GAAW,MAAA;EAIsB;AAUnC;;EAVE,UAAA,GAAa,oBAAA;AAAA;;;;;;AAiBf;;KAPY,aAAA;EAAkB,IAAA;EAAiB,KAAA;AAAA;EAAoB,IAAA;AAAA;;;;;;KAOvD,uBAAA;EAQD,wCANT,WAAA,UAMe;EAJf,OAAA,EAAS,MAAA,mBAYe;EAVxB,MAAA,GAAS,aAAA,EAgBa;EAdtB,OAAA,EAAS,MAAA;AAA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uKxB,UAAA;AAAA;;;;;KAOU,WAAA;EFrKc,sCEuKxB,EAAA;EAEA,UAAA;AAAA;;;;;;;;;;AFtCF;;;;;;;;;;;;;;;;;;;KEqEY,cAAA;EFTV,mCEWA,EAAA;EFXU;;;;;;;;EEoBV,eAAA,CAAgB,UAAA,UAAoB,MAAA,EAAQ,OAAA,EAAS,QAAA,GAAW,MAAA,oBAA0B,OAAA;;AD5Q5F;;;;;;;;ECsRE,gBAAA,CACE,UAAA,UACA,OAAA,EAAS,qBAAA,EACT,MAAA,EAAQ,OAAA,EACR,QAAA,GAAW,MAAA,oBACV,WAAA;EDnRH;;;ECuRA,UAAA;AAAA;;;;;KAOU,OAAA;EDrQ8B,iCCuQxC,MAAA,EAAQ,aAAA,EDvQ2C;ECyQnD,MAAA,EAAQ,aAAA,EDzQkD;EC2Q1D,SAAA,EAAW,gBAAA,ED7QX;EC+QA,SAAA,EAAW,gBAAA;AAAA;AAAA,KAGD,mBAAA;EACV,WAAA,EAAa,MAAA;EACb,YAAA,EAAc,MAAA;EACd,IAAA,EAAM,KAAA;EACN,OAAA,EAAS,MAAA;EACT,MAAA;EACA,QAAA,EAAU,aAAA;EACV,YAAA,EAAc,aAAA;AAAA;;;;AArShB;;KA6SY,cAAA;EA7S4D,gCA+StE,MAAA,GAAS,UAAA,mBA/SwE;EAiTjF,OAAA,GAAU,OAAA,EAAS,MAAA,2BAjTqE;EAmTxF,MAAA,EAAQ,MAAA,CAAO,cAAA,EAnT+B;EAqT9C,KAAA;AAAA;;;;;AA9QF;KAsRY,aAAA,oBAAiC,IAAA,CAAK,mBAAA,CAAoB,KAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_fs = require("node:fs");
|
|
29
|
+
node_fs = __toESM(node_fs);
|
|
30
|
+
let node_path = require("node:path");
|
|
31
|
+
node_path = __toESM(node_path);
|
|
32
|
+
|
|
33
|
+
//#region src/utils.ts
|
|
34
|
+
/**
|
|
35
|
+
* Returns a project identifier for telemetry, derived from the current working
|
|
36
|
+
* directory. Reads `package.json` `name` if present at `cwd`; otherwise falls
|
|
37
|
+
* back to the basename of `cwd`. Returns `undefined` only when both signals
|
|
38
|
+
* are unavailable (e.g. cwd is the filesystem root).
|
|
39
|
+
*
|
|
40
|
+
* No directory walking, only inspects `cwd` itself, so the SDK never reads
|
|
41
|
+
* files outside the user's explicit working directory.
|
|
42
|
+
*/
|
|
43
|
+
function detectProjectName(cwd = process.cwd()) {
|
|
44
|
+
try {
|
|
45
|
+
const manifest = node_path.join(cwd, "package.json");
|
|
46
|
+
if (node_fs.existsSync(manifest)) {
|
|
47
|
+
const parsed = JSON.parse(node_fs.readFileSync(manifest, "utf8"));
|
|
48
|
+
if (typeof parsed.name === "string") {
|
|
49
|
+
const trimmed = parsed.name.trim();
|
|
50
|
+
if (trimmed) return trimmed;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch {}
|
|
54
|
+
return node_path.basename(cwd).trim() || void 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Type guard that checks if a value is a {@link StreamChannelRef}.
|
|
58
|
+
*
|
|
59
|
+
* @param value - Value to check.
|
|
60
|
+
* @returns `true` if the value is a valid `StreamChannelRef`.
|
|
61
|
+
*/
|
|
62
|
+
const isChannelRef = (value) => {
|
|
63
|
+
if (typeof value !== "object" || value === null) return false;
|
|
64
|
+
const maybe = value;
|
|
65
|
+
return typeof maybe.channel_id === "string" && typeof maybe.access_key === "string" && (maybe.direction === "read" || maybe.direction === "write");
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Recursively extract all {@link StreamChannelRef} values from a JSON-like
|
|
69
|
+
* input, returning each match paired with its dotted/bracketed path. Mirrors
|
|
70
|
+
* the Rust SDK's `extract_channel_refs`.
|
|
71
|
+
*
|
|
72
|
+
* @param data - Arbitrary JSON-like value.
|
|
73
|
+
* @returns Array of `[path, ref]` tuples. Empty when no refs are found.
|
|
74
|
+
*/
|
|
75
|
+
const extractChannelRefs = (data) => {
|
|
76
|
+
const refs = [];
|
|
77
|
+
extractRefsRecursive(data, "", refs);
|
|
78
|
+
return refs;
|
|
79
|
+
};
|
|
80
|
+
const extractRefsRecursive = (data, prefix, refs) => {
|
|
81
|
+
if (isChannelRef(data)) {
|
|
82
|
+
refs.push([prefix, data]);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(data)) {
|
|
86
|
+
for (let i = 0; i < data.length; i++) {
|
|
87
|
+
const path = prefix === "" ? `[${i}]` : `${prefix}[${i}]`;
|
|
88
|
+
extractRefsRecursive(data[i], path, refs);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof data !== "object" || data === null) return;
|
|
93
|
+
for (const [key, value] of Object.entries(data)) extractRefsRecursive(value, prefix === "" ? key : `${prefix}.${key}`, refs);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
Object.defineProperty(exports, '__toESM', {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return __toESM;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, 'detectProjectName', {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return detectProjectName;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, 'extractChannelRefs', {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return extractChannelRefs;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, 'isChannelRef', {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return isChannelRef;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=utils-63wxBJg-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-63wxBJg-.cjs","names":["path","fs"],"sources":["../src/utils.ts"],"sourcesContent":["import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type { StreamChannelRef } from './iii-types'\n\n/**\n * Returns a project identifier for telemetry, derived from the current working\n * directory. Reads `package.json` `name` if present at `cwd`; otherwise falls\n * back to the basename of `cwd`. Returns `undefined` only when both signals\n * are unavailable (e.g. cwd is the filesystem root).\n *\n * No directory walking, only inspects `cwd` itself, so the SDK never reads\n * files outside the user's explicit working directory.\n */\nexport function detectProjectName(cwd: string = process.cwd()): string | undefined {\n try {\n const manifest = path.join(cwd, 'package.json')\n if (fs.existsSync(manifest)) {\n const parsed = JSON.parse(fs.readFileSync(manifest, 'utf8')) as { name?: unknown }\n if (typeof parsed.name === 'string') {\n const trimmed = parsed.name.trim()\n if (trimmed) return trimmed\n }\n }\n } catch {\n // fall through to directory-name fallback\n }\n\n const base = path.basename(cwd).trim()\n return base || undefined\n}\n\n/**\n * Type guard that checks if a value is a {@link StreamChannelRef}.\n *\n * @param value - Value to check.\n * @returns `true` if the value is a valid `StreamChannelRef`.\n */\nexport const isChannelRef = (value: unknown): value is StreamChannelRef => {\n if (typeof value !== 'object' || value === null) return false\n const maybe = value as Partial<StreamChannelRef>\n return (\n typeof maybe.channel_id === 'string' &&\n typeof maybe.access_key === 'string' &&\n (maybe.direction === 'read' || maybe.direction === 'write')\n )\n}\n\n/**\n * Recursively extract all {@link StreamChannelRef} values from a JSON-like\n * input, returning each match paired with its dotted/bracketed path. Mirrors\n * the Rust SDK's `extract_channel_refs`.\n *\n * @param data - Arbitrary JSON-like value.\n * @returns Array of `[path, ref]` tuples. Empty when no refs are found.\n */\nexport const extractChannelRefs = (data: unknown): Array<[string, StreamChannelRef]> => {\n const refs: Array<[string, StreamChannelRef]> = []\n extractRefsRecursive(data, '', refs)\n return refs\n}\n\nconst extractRefsRecursive = (\n data: unknown,\n prefix: string,\n refs: Array<[string, StreamChannelRef]>,\n): void => {\n if (isChannelRef(data)) {\n refs.push([prefix, data])\n return\n }\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const path = prefix === '' ? `[${i}]` : `${prefix}[${i}]`\n extractRefsRecursive(data[i], path, refs)\n }\n return\n }\n if (typeof data !== 'object' || data === null) return\n\n for (const [key, value] of Object.entries(data as Record<string, unknown>)) {\n const path = prefix === '' ? key : `${prefix}.${key}`\n extractRefsRecursive(value, path, refs)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,SAAgB,kBAAkB,MAAc,QAAQ,KAAK,EAAsB;AACjF,K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**
|
|
6
|
+
* Returns a project identifier for telemetry, derived from the current working
|
|
7
|
+
* directory. Reads `package.json` `name` if present at `cwd`; otherwise falls
|
|
8
|
+
* back to the basename of `cwd`. Returns `undefined` only when both signals
|
|
9
|
+
* are unavailable (e.g. cwd is the filesystem root).
|
|
10
|
+
*
|
|
11
|
+
* No directory walking, only inspects `cwd` itself, so the SDK never reads
|
|
12
|
+
* files outside the user's explicit working directory.
|
|
13
|
+
*/
|
|
14
|
+
function detectProjectName(cwd = process.cwd()) {
|
|
15
|
+
try {
|
|
16
|
+
const manifest = path.join(cwd, "package.json");
|
|
17
|
+
if (fs.existsSync(manifest)) {
|
|
18
|
+
const parsed = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
19
|
+
if (typeof parsed.name === "string") {
|
|
20
|
+
const trimmed = parsed.name.trim();
|
|
21
|
+
if (trimmed) return trimmed;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch {}
|
|
25
|
+
return path.basename(cwd).trim() || void 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Type guard that checks if a value is a {@link StreamChannelRef}.
|
|
29
|
+
*
|
|
30
|
+
* @param value - Value to check.
|
|
31
|
+
* @returns `true` if the value is a valid `StreamChannelRef`.
|
|
32
|
+
*/
|
|
33
|
+
const isChannelRef = (value) => {
|
|
34
|
+
if (typeof value !== "object" || value === null) return false;
|
|
35
|
+
const maybe = value;
|
|
36
|
+
return typeof maybe.channel_id === "string" && typeof maybe.access_key === "string" && (maybe.direction === "read" || maybe.direction === "write");
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Recursively extract all {@link StreamChannelRef} values from a JSON-like
|
|
40
|
+
* input, returning each match paired with its dotted/bracketed path. Mirrors
|
|
41
|
+
* the Rust SDK's `extract_channel_refs`.
|
|
42
|
+
*
|
|
43
|
+
* @param data - Arbitrary JSON-like value.
|
|
44
|
+
* @returns Array of `[path, ref]` tuples. Empty when no refs are found.
|
|
45
|
+
*/
|
|
46
|
+
const extractChannelRefs = (data) => {
|
|
47
|
+
const refs = [];
|
|
48
|
+
extractRefsRecursive(data, "", refs);
|
|
49
|
+
return refs;
|
|
50
|
+
};
|
|
51
|
+
const extractRefsRecursive = (data, prefix, refs) => {
|
|
52
|
+
if (isChannelRef(data)) {
|
|
53
|
+
refs.push([prefix, data]);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(data)) {
|
|
57
|
+
for (let i = 0; i < data.length; i++) {
|
|
58
|
+
const path = prefix === "" ? `[${i}]` : `${prefix}[${i}]`;
|
|
59
|
+
extractRefsRecursive(data[i], path, refs);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof data !== "object" || data === null) return;
|
|
64
|
+
for (const [key, value] of Object.entries(data)) extractRefsRecursive(value, prefix === "" ? key : `${prefix}.${key}`, refs);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { extractChannelRefs as n, isChannelRef as r, detectProjectName as t };
|
|
69
|
+
//# sourceMappingURL=utils-8G4hHqvZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-8G4hHqvZ.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type { StreamChannelRef } from './iii-types'\n\n/**\n * Returns a project identifier for telemetry, derived from the current working\n * directory. Reads `package.json` `name` if present at `cwd`; otherwise falls\n * back to the basename of `cwd`. Returns `undefined` only when both signals\n * are unavailable (e.g. cwd is the filesystem root).\n *\n * No directory walking, only inspects `cwd` itself, so the SDK never reads\n * files outside the user's explicit working directory.\n */\nexport function detectProjectName(cwd: string = process.cwd()): string | undefined {\n try {\n const manifest = path.join(cwd, 'package.json')\n if (fs.existsSync(manifest)) {\n const parsed = JSON.parse(fs.readFileSync(manifest, 'utf8')) as { name?: unknown }\n if (typeof parsed.name === 'string') {\n const trimmed = parsed.name.trim()\n if (trimmed) return trimmed\n }\n }\n } catch {\n // fall through to directory-name fallback\n }\n\n const base = path.basename(cwd).trim()\n return base || undefined\n}\n\n/**\n * Type guard that checks if a value is a {@link StreamChannelRef}.\n *\n * @param value - Value to check.\n * @returns `true` if the value is a valid `StreamChannelRef`.\n */\nexport const isChannelRef = (value: unknown): value is StreamChannelRef => {\n if (typeof value !== 'object' || value === null) return false\n const maybe = value as Partial<StreamChannelRef>\n return (\n typeof maybe.channel_id === 'string' &&\n typeof maybe.access_key === 'string' &&\n (maybe.direction === 'read' || maybe.direction === 'write')\n )\n}\n\n/**\n * Recursively extract all {@link StreamChannelRef} values from a JSON-like\n * input, returning each match paired with its dotted/bracketed path. Mirrors\n * the Rust SDK's `extract_channel_refs`.\n *\n * @param data - Arbitrary JSON-like value.\n * @returns Array of `[path, ref]` tuples. Empty when no refs are found.\n */\nexport const extractChannelRefs = (data: unknown): Array<[string, StreamChannelRef]> => {\n const refs: Array<[string, StreamChannelRef]> = []\n extractRefsRecursive(data, '', refs)\n return refs\n}\n\nconst extractRefsRecursive = (\n data: unknown,\n prefix: string,\n refs: Array<[string, StreamChannelRef]>,\n): void => {\n if (isChannelRef(data)) {\n refs.push([prefix, data])\n return\n }\n if (Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const path = prefix === '' ? `[${i}]` : `${prefix}[${i}]`\n extractRefsRecursive(data[i], path, refs)\n }\n return\n }\n if (typeof data !== 'object' || data === null) return\n\n for (const [key, value] of Object.entries(data as Record<string, unknown>)) {\n const path = prefix === '' ? key : `${prefix}.${key}`\n extractRefsRecursive(value, path, refs)\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,kBAAkB,MAAc,QAAQ,KAAK,EAAsB;AACjF,KAAI;EACF,MAAM,WAAW,KAAK,KAAK,KAAK,eAAe;AAC/C,MAAI,GAAG,WAAW,SAAS,EAAE;GAC3B,MAAM,SAAS,KAAK,MAAM,GAAG,aAAa,UAAU,OAAO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