iii-sdk 0.19.3-next.1 → 0.19.4-alpha.1

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.
Files changed (85) hide show
  1. package/dist/channel.cjs +5 -0
  2. package/dist/channel.d.cts +2 -0
  3. package/dist/channel.d.mts +2 -0
  4. package/dist/channel.mjs +3 -0
  5. package/dist/{utils-DXL7JI0q.mjs → channels-BFs4n1g6.mjs} +2 -107
  6. package/dist/channels-BFs4n1g6.mjs.map +1 -0
  7. package/dist/{utils-CuS1Knym.cjs → channels-huduKJ-b.cjs} +2 -165
  8. package/dist/channels-huduKJ-b.cjs.map +1 -0
  9. package/dist/engine.cjs +5 -0
  10. package/dist/engine.d.cts +3 -0
  11. package/dist/engine.d.mts +3 -0
  12. package/dist/engine.mjs +3 -0
  13. package/dist/errors.cjs +33 -0
  14. package/dist/errors.cjs.map +1 -0
  15. package/dist/errors.d.cts +52 -0
  16. package/dist/errors.d.cts.map +1 -0
  17. package/dist/errors.d.mts +52 -0
  18. package/dist/errors.d.mts.map +1 -0
  19. package/dist/errors.mjs +29 -0
  20. package/dist/errors.mjs.map +1 -0
  21. package/dist/helpers.cjs +4 -3
  22. package/dist/helpers.cjs.map +1 -1
  23. package/dist/helpers.d.cts +19 -1
  24. package/dist/helpers.d.cts.map +1 -1
  25. package/dist/helpers.d.mts +19 -1
  26. package/dist/helpers.d.mts.map +1 -1
  27. package/dist/helpers.mjs +2 -1
  28. package/dist/helpers.mjs.map +1 -1
  29. package/dist/iii-constants-Baptl8nm.d.mts +47 -0
  30. package/dist/iii-constants-Baptl8nm.d.mts.map +1 -0
  31. package/dist/iii-constants-BqXp8xSN.d.cts +47 -0
  32. package/dist/iii-constants-BqXp8xSN.d.cts.map +1 -0
  33. package/dist/iii-constants-Br94RUNi.cjs +67 -0
  34. package/dist/iii-constants-Br94RUNi.cjs.map +1 -0
  35. package/dist/iii-constants-_k3SoHry.mjs +43 -0
  36. package/dist/iii-constants-_k3SoHry.mjs.map +1 -0
  37. package/dist/iii-types-6aHBgy7l.cjs +24 -0
  38. package/dist/iii-types-6aHBgy7l.cjs.map +1 -0
  39. package/dist/iii-types-CRx2qAjB.mjs +18 -0
  40. package/dist/iii-types-CRx2qAjB.mjs.map +1 -0
  41. package/dist/index.cjs +56 -133
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.cts +8 -76
  44. package/dist/index.d.cts.map +1 -1
  45. package/dist/index.d.mts +8 -76
  46. package/dist/index.d.mts.map +1 -1
  47. package/dist/index.mjs +13 -88
  48. package/dist/index.mjs.map +1 -1
  49. package/dist/internal.cjs +0 -0
  50. package/dist/internal.d.cts +2 -0
  51. package/dist/internal.d.mts +2 -0
  52. package/dist/internal.mjs +1 -0
  53. package/dist/protocol.cjs +4 -0
  54. package/dist/protocol.d.cts +2 -0
  55. package/dist/protocol.d.mts +2 -0
  56. package/dist/protocol.mjs +3 -0
  57. package/dist/runtime.cjs +0 -0
  58. package/dist/runtime.d.cts +3 -0
  59. package/dist/runtime.d.mts +3 -0
  60. package/dist/runtime.mjs +1 -0
  61. package/dist/state.cjs.map +1 -1
  62. package/dist/state.d.cts +1 -1
  63. package/dist/state.d.mts +1 -1
  64. package/dist/state.mjs.map +1 -1
  65. package/dist/stream.d.cts +4 -245
  66. package/dist/stream.d.cts.map +1 -1
  67. package/dist/stream.d.mts +4 -245
  68. package/dist/stream.d.mts.map +1 -1
  69. package/dist/trigger.cjs +0 -0
  70. package/dist/trigger.d.cts +2 -0
  71. package/dist/trigger.d.mts +2 -0
  72. package/dist/trigger.mjs +1 -0
  73. package/dist/{utils-BnRzIUCy.d.cts → types-DduY0ha2.d.mts} +18 -203
  74. package/dist/types-DduY0ha2.d.mts.map +1 -0
  75. package/dist/{utils-e84Qph-9.d.mts → types-gwm9j9oD.d.cts} +18 -203
  76. package/dist/types-gwm9j9oD.d.cts.map +1 -0
  77. package/dist/utils-BtEFReHq.cjs +121 -0
  78. package/dist/utils-BtEFReHq.cjs.map +1 -0
  79. package/dist/utils-Cuv_ksKp.mjs +69 -0
  80. package/dist/utils-Cuv_ksKp.mjs.map +1 -0
  81. package/package.json +38 -2
  82. package/dist/utils-BnRzIUCy.d.cts.map +0 -1
  83. package/dist/utils-CuS1Knym.cjs.map +0 -1
  84. package/dist/utils-DXL7JI0q.mjs.map +0 -1
  85. package/dist/utils-e84Qph-9.d.mts.map +0 -1
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_channels = require('./channels-huduKJ-b.cjs');
3
+
4
+ exports.ChannelReader = require_channels.ChannelReader;
5
+ exports.ChannelWriter = require_channels.ChannelWriter;
@@ -0,0 +1,2 @@
1
+ import { O as StreamChannelRef, b as ChannelWriter, t as Channel, y as ChannelReader } from "./types-gwm9j9oD.cjs";
2
+ export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
@@ -0,0 +1,2 @@
1
+ import { O as StreamChannelRef, b as ChannelWriter, t as Channel, y as ChannelReader } from "./types-DduY0ha2.mjs";
2
+ export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
@@ -0,0 +1,3 @@
1
+ import { i as ChannelWriter, r as ChannelReader } from "./channels-BFs4n1g6.mjs";
2
+
3
+ export { ChannelReader, ChannelWriter };
@@ -1,7 +1,5 @@
1
1
  import { Readable, Writable } from "node:stream";
2
2
  import { WebSocket } from "ws";
3
- import * as fs from "node:fs";
4
- import * as path from "node:path";
5
3
 
6
4
  //#region src/channels.ts
7
5
  /**
@@ -212,108 +210,5 @@ function buildChannelUrl(engineWsBase, channelId, accessKey, direction) {
212
210
  }
213
211
 
214
212
  //#endregion
215
- //#region src/utils.ts
216
- /**
217
- * Returns a project identifier for telemetry, derived from the current working
218
- * directory. Reads `package.json` `name` if present at `cwd`; otherwise falls
219
- * back to the basename of `cwd`. Returns `undefined` only when both signals
220
- * are unavailable (e.g. cwd is the filesystem root).
221
- *
222
- * No directory walking — only inspects `cwd` itself, so the SDK never reads
223
- * files outside the user's explicit working directory.
224
- */
225
- function detectProjectName(cwd = process.cwd()) {
226
- try {
227
- const manifest = path.join(cwd, "package.json");
228
- if (fs.existsSync(manifest)) {
229
- const parsed = JSON.parse(fs.readFileSync(manifest, "utf8"));
230
- if (typeof parsed.name === "string") {
231
- const trimmed = parsed.name.trim();
232
- if (trimmed) return trimmed;
233
- }
234
- }
235
- } catch {}
236
- return path.basename(cwd).trim() || void 0;
237
- }
238
- /**
239
- * Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
240
- * into the function handler format expected by the SDK.
241
- *
242
- * @param callback - Async handler receiving an {@link HttpRequest} and {@link HttpResponse}.
243
- * @returns A function handler compatible with {@link ISdk.registerFunction}.
244
- *
245
- * @example
246
- * ```typescript
247
- * import { http } from 'iii-sdk'
248
- *
249
- * iii.registerFunction(
250
- * 'my-api',
251
- * http(async (req, res) => {
252
- * res.status(200)
253
- * res.headers({ 'content-type': 'application/json' })
254
- * res.stream.end(JSON.stringify({ hello: 'world' }))
255
- * res.close()
256
- * }),
257
- * )
258
- * ```
259
- */
260
- const http = (callback) => {
261
- return async (req) => {
262
- const { response, ...request } = req;
263
- return callback(request, {
264
- status: (status_code) => response.sendMessage(JSON.stringify({
265
- type: "set_status",
266
- status_code
267
- })),
268
- headers: (headers) => response.sendMessage(JSON.stringify({
269
- type: "set_headers",
270
- headers
271
- })),
272
- stream: response.stream,
273
- close: () => response.close()
274
- });
275
- };
276
- };
277
- /**
278
- * Type guard that checks if a value is a {@link StreamChannelRef}.
279
- *
280
- * @param value - Value to check.
281
- * @returns `true` if the value is a valid `StreamChannelRef`.
282
- */
283
- const isChannelRef = (value) => {
284
- if (typeof value !== "object" || value === null) return false;
285
- const maybe = value;
286
- return typeof maybe.channel_id === "string" && typeof maybe.access_key === "string" && (maybe.direction === "read" || maybe.direction === "write");
287
- };
288
- /**
289
- * Recursively extract all {@link StreamChannelRef} values from a JSON-like
290
- * input, returning each match paired with its dotted/bracketed path. Mirrors
291
- * the Rust SDK's `extract_channel_refs`.
292
- *
293
- * @param data - Arbitrary JSON-like value.
294
- * @returns Array of `[path, ref]` tuples. Empty when no refs are found.
295
- */
296
- const extractChannelRefs = (data) => {
297
- const refs = [];
298
- extractRefsRecursive(data, "", refs);
299
- return refs;
300
- };
301
- const extractRefsRecursive = (data, prefix, refs) => {
302
- if (isChannelRef(data)) {
303
- refs.push([prefix, data]);
304
- return;
305
- }
306
- if (Array.isArray(data)) {
307
- for (let i = 0; i < data.length; i++) {
308
- const path = prefix === "" ? `[${i}]` : `${prefix}[${i}]`;
309
- extractRefsRecursive(data[i], path, refs);
310
- }
311
- return;
312
- }
313
- if (typeof data !== "object" || data === null) return;
314
- for (const [key, value] of Object.entries(data)) extractRefsRecursive(value, prefix === "" ? key : `${prefix}.${key}`, refs);
315
- };
316
-
317
- //#endregion
318
- export { ChannelDirection as a, ChannelWriter as c, isChannelRef as i, extractChannelRefs as n, ChannelItem as o, http as r, ChannelReader as s, detectProjectName as t };
319
- //# sourceMappingURL=utils-DXL7JI0q.mjs.map
213
+ export { ChannelWriter as i, ChannelItem as n, ChannelReader as r, ChannelDirection as t };
214
+ //# sourceMappingURL=channels-BFs4n1g6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels-BFs4n1g6.mjs","names":[],"sources":["../src/channels.ts"],"sourcesContent":["import { Readable, Writable } from 'node:stream'\nimport { WebSocket } from 'ws'\nimport type { StreamChannelRef } from './iii-types'\n\n/**\n * Direction of a streaming channel endpoint. Mirrors the Rust SDK's\n * `ChannelDirection` enum and matches the literal values used by\n * {@link StreamChannelRef.direction}.\n */\nexport const ChannelDirection = {\n Read: 'read',\n Write: 'write',\n} as const\nexport type ChannelDirection = (typeof ChannelDirection)[keyof typeof ChannelDirection]\n\n/**\n * Discriminated runtime tag for an item observed on a streaming channel.\n * Mirrors the Rust SDK's `ChannelItem` enum (`Text` / `Binary`). Carrier for\n * factory + type-guard helpers so callers can construct and discriminate\n * channel items without depending on Rust-specific shape.\n */\nexport type ChannelItem =\n | { type: 'text'; value: string }\n | { type: 'binary'; value: Uint8Array }\n\nexport const ChannelItem = {\n /** Construct a text channel item. */\n Text(value: string): ChannelItem {\n return { type: 'text', value }\n },\n /** Construct a binary channel item. */\n Binary(value: Uint8Array): ChannelItem {\n return { type: 'binary', value }\n },\n} as const\n\n/**\n * Write end of a streaming channel. Provides both a Node.js `Writable` stream\n * and a `sendMessage` method for sending structured text messages.\n *\n * @example\n * ```typescript\n * import { createChannel } from 'iii-sdk/helpers'\n * const channel = await createChannel(iii)\n *\n * // Stream binary data\n * channel.writer.stream.write(Buffer.from('hello'))\n * channel.writer.stream.end()\n *\n * // Or send text messages\n * channel.writer.sendMessage(JSON.stringify({ type: 'event', data: 'test' }))\n * channel.writer.close()\n * ```\n */\nexport class ChannelWriter {\n private static readonly FRAME_SIZE = 64 * 1024\n private ws: WebSocket | null = null\n private wsReady = false\n private readonly pendingMessages: {\n data: Buffer | string\n callback: (err?: Error | null) => void\n }[] = []\n /** Node.js Writable stream for binary data. */\n public readonly stream: Writable\n private readonly url: string\n\n constructor(engineWsBase: string, ref: StreamChannelRef) {\n this.url = buildChannelUrl(engineWsBase, ref.channel_id, ref.access_key, 'write')\n\n this.stream = new Writable({\n write: (chunk: Buffer, _encoding, callback) => {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)\n this.sendChunked(buf, callback)\n },\n final: (callback) => {\n if (!this.ws) {\n callback()\n return\n }\n // Delay the close frame slightly to allow the TCP stack to flush\n // all buffered send() data. Without this, the close frame can arrive\n // at the engine before all data frames, causing data truncation.\n const doClose = () => {\n if (this.ws) {\n this.ws.close(1000, 'stream_complete')\n }\n callback()\n }\n if (this.wsReady) {\n setTimeout(doClose, 10)\n } else {\n this.ws.on('open', () => setTimeout(doClose, 10))\n }\n },\n destroy: (err, callback) => {\n if (this.ws) this.ws.terminate()\n callback(err)\n },\n })\n }\n\n private ensureConnected(): void {\n if (this.ws) return\n this.ws = new WebSocket(this.url)\n\n this.ws.on('open', () => {\n this.wsReady = true\n for (const { data, callback } of this.pendingMessages) {\n this.ws?.send(data, callback)\n }\n this.pendingMessages.length = 0\n })\n\n this.ws.on('error', (err) => {\n this.stream.destroy(err)\n })\n\n this.ws.on('close', () => {\n if (!this.stream.destroyed) {\n this.stream.destroy()\n }\n })\n }\n\n /** Send a text message through the channel. */\n sendMessage(msg: string): void {\n this.ensureConnected()\n this.sendRaw(msg, (err) => {\n if (err) this.stream.destroy(err)\n })\n }\n\n /** Close the channel writer. */\n close(): void {\n if (!this.ws) return\n const doClose = () => {\n if (this.ws) {\n this.ws.close(1000, 'channel_close')\n }\n }\n if (this.wsReady) {\n doClose()\n } else {\n this.ws.on('open', () => doClose())\n }\n }\n\n private sendChunked(data: Buffer, callback: (err?: Error | null) => void): void {\n let offset = 0\n const sendNext = (err?: Error | null): void => {\n if (err) {\n callback(err)\n return\n }\n\n if (offset >= data.length) {\n callback(null)\n return\n }\n\n const end = Math.min(offset + ChannelWriter.FRAME_SIZE, data.length)\n const part = data.subarray(offset, end)\n offset = end\n this.sendRaw(part, sendNext)\n }\n sendNext(null)\n }\n\n private sendRaw(data: Buffer | string, callback: (err?: Error | null) => void): void {\n this.ensureConnected()\n if (this.wsReady && this.ws) {\n this.ws.send(data, (err) => callback(err ?? null))\n } else {\n this.pendingMessages.push({ data, callback })\n }\n }\n}\n\n/**\n * Read end of a streaming channel. Provides both a Node.js `Readable` stream\n * for binary data and an `onMessage` callback for structured text messages.\n *\n * @example\n * ```typescript\n * import { createChannel } from 'iii-sdk/helpers'\n * const channel = await createChannel(iii)\n *\n * // Stream binary data\n * channel.reader.stream.on('data', (chunk) => console.log(chunk))\n *\n * // Or receive text messages\n * channel.reader.onMessage((msg) => console.log('Got:', msg))\n * ```\n */\nexport class ChannelReader {\n private ws: WebSocket | null = null\n private connected = false\n private readonly messageCallbacks: Array<(msg: string) => void> = []\n /** Node.js Readable stream for binary data. */\n public readonly stream: Readable\n private readonly url: string\n\n constructor(engineWsBase: string, ref: StreamChannelRef) {\n this.url = buildChannelUrl(engineWsBase, ref.channel_id, ref.access_key, 'read')\n\n const self = this\n this.stream = new Readable({\n read() {\n self.ensureConnected()\n if (self.ws) self.ws.resume()\n },\n destroy(err, callback) {\n if (self.ws && self.ws.readyState !== WebSocket.CLOSED) {\n self.ws.terminate()\n }\n self.ws = null\n callback(err)\n },\n })\n }\n\n private ensureConnected(): void {\n if (this.connected) return\n this.connected = true\n this.ws = new WebSocket(this.url)\n\n this.ws.on('open', () => {\n ;(this.ws as unknown as { binaryType: string }).binaryType = 'nodebuffer'\n })\n\n this.ws.on('message', (data: Buffer, isBinary: boolean) => {\n if (isBinary) {\n if (!this.stream.push(data)) {\n this.ws?.pause()\n }\n } else {\n const msg = data.toString('utf-8')\n for (const cb of this.messageCallbacks) {\n cb(msg)\n }\n }\n })\n\n this.ws.on('close', () => {\n this.ws = null\n if (!this.stream.destroyed) this.stream.push(null)\n })\n\n this.ws.on('error', (err) => {\n this.stream.destroy(err)\n })\n }\n\n /** Register a callback to receive text messages from the channel. */\n onMessage(callback: (msg: string) => void): void {\n this.messageCallbacks.push(callback)\n }\n\n async readAll(): Promise<Buffer> {\n this.ensureConnected()\n const chunks: Buffer[] = []\n\n for await (const chunk of this.stream) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))\n }\n\n return Buffer.concat(chunks)\n }\n\n close(): void {\n if (this.ws && this.ws.readyState !== WebSocket.CLOSED) {\n this.ws.close(1000, 'channel_close')\n }\n }\n}\n\nfunction buildChannelUrl(\n engineWsBase: string,\n channelId: string,\n accessKey: string,\n direction: 'read' | 'write',\n): string {\n const base = engineWsBase.replace(/\\/$/, '')\n return `${base}/ws/channels/${channelId}?key=${encodeURIComponent(accessKey)}&dir=${direction}`\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,mBAAmB;CAC9B,MAAM;CACN,OAAO;CACR;AAaD,MAAa,cAAc;CAEzB,KAAK,OAA4B;AAC/B,SAAO;GAA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wnPropDesc = 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
1
+ const require_utils = require('./utils-BtEFReHq.cjs');
28
2
  let node_stream = require("node:stream");
29
3
  let ws = require("ws");
30
- let node_fs = require("node:fs");
31
- node_fs = __toESM(node_fs);
32
- let node_path = require("node:path");
33
- node_path = __toESM(node_path);
34
4
 
35
5
  //#region src/channels.ts
36
6
  /**
@@ -240,109 +210,6 @@ function buildChannelUrl(engineWsBase, channelId, accessKey, direction) {
240
210
  return `${engineWsBase.replace(/\/$/, "")}/ws/channels/${channelId}?key=${encodeURIComponent(accessKey)}&dir=${direction}`;
241
211
  }
242
212
 
243
- //#endregion
244
- //#region src/utils.ts
245
- /**
246
- * Returns a project identifier for telemetry, derived from the current working
247
- * directory. Reads `package.json` `name` if present at `cwd`; otherwise falls
248
- * back to the basename of `cwd`. Returns `undefined` only when both signals
249
- * are unavailable (e.g. cwd is the filesystem root).
250
- *
251
- * No directory walking — only inspects `cwd` itself, so the SDK never reads
252
- * files outside the user's explicit working directory.
253
- */
254
- function detectProjectName(cwd = process.cwd()) {
255
- try {
256
- const manifest = node_path.join(cwd, "package.json");
257
- if (node_fs.existsSync(manifest)) {
258
- const parsed = JSON.parse(node_fs.readFileSync(manifest, "utf8"));
259
- if (typeof parsed.name === "string") {
260
- const trimmed = parsed.name.trim();
261
- if (trimmed) return trimmed;
262
- }
263
- }
264
- } catch {}
265
- return node_path.basename(cwd).trim() || void 0;
266
- }
267
- /**
268
- * Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
269
- * into the function handler format expected by the SDK.
270
- *
271
- * @param callback - Async handler receiving an {@link HttpRequest} and {@link HttpResponse}.
272
- * @returns A function handler compatible with {@link ISdk.registerFunction}.
273
- *
274
- * @example
275
- * ```typescript
276
- * import { http } from 'iii-sdk'
277
- *
278
- * iii.registerFunction(
279
- * 'my-api',
280
- * http(async (req, res) => {
281
- * res.status(200)
282
- * res.headers({ 'content-type': 'application/json' })
283
- * res.stream.end(JSON.stringify({ hello: 'world' }))
284
- * res.close()
285
- * }),
286
- * )
287
- * ```
288
- */
289
- const http = (callback) => {
290
- return async (req) => {
291
- const { response, ...request } = req;
292
- return callback(request, {
293
- status: (status_code) => response.sendMessage(JSON.stringify({
294
- type: "set_status",
295
- status_code
296
- })),
297
- headers: (headers) => response.sendMessage(JSON.stringify({
298
- type: "set_headers",
299
- headers
300
- })),
301
- stream: response.stream,
302
- close: () => response.close()
303
- });
304
- };
305
- };
306
- /**
307
- * Type guard that checks if a value is a {@link StreamChannelRef}.
308
- *
309
- * @param value - Value to check.
310
- * @returns `true` if the value is a valid `StreamChannelRef`.
311
- */
312
- const isChannelRef = (value) => {
313
- if (typeof value !== "object" || value === null) return false;
314
- const maybe = value;
315
- return typeof maybe.channel_id === "string" && typeof maybe.access_key === "string" && (maybe.direction === "read" || maybe.direction === "write");
316
- };
317
- /**
318
- * Recursively extract all {@link StreamChannelRef} values from a JSON-like
319
- * input, returning each match paired with its dotted/bracketed path. Mirrors
320
- * the Rust SDK's `extract_channel_refs`.
321
- *
322
- * @param data - Arbitrary JSON-like value.
323
- * @returns Array of `[path, ref]` tuples. Empty when no refs are found.
324
- */
325
- const extractChannelRefs = (data) => {
326
- const refs = [];
327
- extractRefsRecursive(data, "", refs);
328
- return refs;
329
- };
330
- const extractRefsRecursive = (data, prefix, refs) => {
331
- if (isChannelRef(data)) {
332
- refs.push([prefix, data]);
333
- return;
334
- }
335
- if (Array.isArray(data)) {
336
- for (let i = 0; i < data.length; i++) {
337
- const path = prefix === "" ? `[${i}]` : `${prefix}[${i}]`;
338
- extractRefsRecursive(data[i], path, refs);
339
- }
340
- return;
341
- }
342
- if (typeof data !== "object" || data === null) return;
343
- for (const [key, value] of Object.entries(data)) extractRefsRecursive(value, prefix === "" ? key : `${prefix}.${key}`, refs);
344
- };
345
-
346
213
  //#endregion
347
214
  Object.defineProperty(exports, 'ChannelDirection', {
348
215
  enumerable: true,
@@ -368,34 +235,4 @@ Object.defineProperty(exports, 'ChannelWriter', {
368
235
  return ChannelWriter;
369
236
  }
370
237
  });
371
- Object.defineProperty(exports, '__toESM', {
372
- enumerable: true,
373
- get: function () {
374
- return __toESM;
375
- }
376
- });
377
- Object.defineProperty(exports, 'detectProjectName', {
378
- enumerable: true,
379
- get: function () {
380
- return detectProjectName;
381
- }
382
- });
383
- Object.defineProperty(exports, 'extractChannelRefs', {
384
- enumerable: true,
385
- get: function () {
386
- return extractChannelRefs;
387
- }
388
- });
389
- Object.defineProperty(exports, 'http', {
390
- enumerable: true,
391
- get: function () {
392
- return http;
393
- }
394
- });
395
- Object.defineProperty(exports, 'isChannelRef', {
396
- enumerable: true,
397
- get: function () {
398
- return isChannelRef;
399
- }
400
- });
401
- //# sourceMappingURL=utils-CuS1Knym.cjs.map
238
+ //# sourceMappingURL=channels-huduKJ-b.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels-huduKJ-b.cjs","names":["Writable","WebSocket","Readable"],"sources":["../src/channels.ts"],"sourcesContent":["import { Readable, Writable } from 'node:stream'\nimport { WebSocket } from 'ws'\nimport type { StreamChannelRef } from './iii-types'\n\n/**\n * Direction of a streaming channel endpoint. Mirrors the Rust SDK's\n * `ChannelDirection` enum and matches the literal values used by\n * {@link StreamChannelRef.direction}.\n */\nexport const ChannelDirection = {\n Read: 'read',\n Write: 'write',\n} as const\nexport type ChannelDirection = (typeof ChannelDirection)[keyof typeof ChannelDirection]\n\n/**\n * Discriminated runtime tag for an item observed on a streaming channel.\n * Mirrors the Rust SDK's `ChannelItem` enum (`Text` / `Binary`). Carrier for\n * factory + type-guard helpers so callers can construct and discriminate\n * channel items without depending on Rust-specific shape.\n */\nexport type ChannelItem =\n | { type: 'text'; value: string }\n | { type: 'binary'; value: Uint8Array }\n\nexport const ChannelItem = {\n /** Construct a text channel item. */\n Text(value: string): ChannelItem {\n return { type: 'text', value }\n },\n /** Construct a binary channel item. */\n Binary(value: Uint8Array): ChannelItem {\n return { type: 'binary', value }\n },\n} as const\n\n/**\n * Write end of a streaming channel. Provides both a Node.js `Writable` stream\n * and a `sendMessage` method for sending structured text messages.\n *\n * @example\n * ```typescript\n * import { createChannel } from 'iii-sdk/helpers'\n * const channel = await createChannel(iii)\n *\n * // Stream binary data\n * channel.writer.stream.write(Buffer.from('hello'))\n * channel.writer.stream.end()\n *\n * // Or send text messages\n * channel.writer.sendMessage(JSON.stringify({ type: 'event', data: 'test' }))\n * channel.writer.close()\n * ```\n */\nexport class ChannelWriter {\n private static readonly FRAME_SIZE = 64 * 1024\n private ws: WebSocket | null = null\n private wsReady = false\n private readonly pendingMessages: {\n data: Buffer | string\n callback: (err?: Error | null) => void\n }[] = []\n /** Node.js Writable stream for binary data. */\n public readonly stream: Writable\n private readonly url: string\n\n constructor(engineWsBase: string, ref: StreamChannelRef) {\n this.url = buildChannelUrl(engineWsBase, ref.channel_id, ref.access_key, 'write')\n\n this.stream = new Writable({\n write: (chunk: Buffer, _encoding, callback) => {\n const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)\n this.sendChunked(buf, callback)\n },\n final: (callback) => {\n if (!this.ws) {\n callback()\n return\n }\n // Delay the close frame slightly to allow the TCP stack to flush\n // all buffered send() data. Without this, the close frame can arrive\n // at the engine before all data frames, causing data truncation.\n const doClose = () => {\n if (this.ws) {\n this.ws.close(1000, 'stream_complete')\n }\n callback()\n }\n if (this.wsReady) {\n setTimeout(doClose, 10)\n } else {\n this.ws.on('open', () => setTimeout(doClose, 10))\n }\n },\n destroy: (err, callback) => {\n if (this.ws) this.ws.terminate()\n callback(err)\n },\n })\n }\n\n private ensureConnected(): void {\n if (this.ws) return\n this.ws = new WebSocket(this.url)\n\n this.ws.on('open', () => {\n this.wsReady = true\n for (const { data, callback } of this.pendingMessages) {\n this.ws?.send(data, callback)\n }\n this.pendingMessages.length = 0\n })\n\n this.ws.on('error', (err) => {\n this.stream.destroy(err)\n })\n\n this.ws.on('close', () => {\n if (!this.stream.destroyed) {\n this.stream.destroy()\n }\n })\n }\n\n /** Send a text message through the channel. */\n sendMessage(msg: string): void {\n this.ensureConnected()\n this.sendRaw(msg, (err) => {\n if (err) this.stream.destroy(err)\n })\n }\n\n /** Close the channel writer. */\n close(): void {\n if (!this.ws) return\n const doClose = () => {\n if (this.ws) {\n this.ws.close(1000, 'channel_close')\n }\n }\n if (this.wsReady) {\n doClose()\n } else {\n this.ws.on('open', () => doClose())\n }\n }\n\n private sendChunked(data: Buffer, callback: (err?: Error | null) => void): void {\n let offset = 0\n const sendNext = (err?: Error | null): void => {\n if (err) {\n callback(err)\n return\n }\n\n if (offset >= data.length) {\n callback(null)\n return\n }\n\n const end = Math.min(offset + ChannelWriter.FRAME_SIZE, data.length)\n const part = data.subarray(offset, end)\n offset = end\n this.sendRaw(part, sendNext)\n }\n sendNext(null)\n }\n\n private sendRaw(data: Buffer | string, callback: (err?: Error | null) => void): void {\n this.ensureConnected()\n if (this.wsReady && this.ws) {\n this.ws.send(data, (err) => callback(err ?? null))\n } else {\n this.pendingMessages.push({ data, callback })\n }\n }\n}\n\n/**\n * Read end of a streaming channel. Provides both a Node.js `Readable` stream\n * for binary data and an `onMessage` callback for structured text messages.\n *\n * @example\n * ```typescript\n * import { createChannel } from 'iii-sdk/helpers'\n * const channel = await createChannel(iii)\n *\n * // Stream binary data\n * channel.reader.stream.on('data', (chunk) => console.log(chunk))\n *\n * // Or receive text messages\n * channel.reader.onMessage((msg) => console.log('Got:', msg))\n * ```\n */\nexport class ChannelReader {\n private ws: WebSocket | null = null\n private connected = false\n private readonly messageCallbacks: Array<(msg: string) => void> = []\n /** Node.js Readable stream for binary data. */\n public readonly stream: Readable\n private readonly url: string\n\n constructor(engineWsBase: string, ref: StreamChannelRef) {\n this.url = buildChannelUrl(engineWsBase, ref.channel_id, ref.access_key, 'read')\n\n const self = this\n this.stream = new Readable({\n read() {\n self.ensureConnected()\n if (self.ws) self.ws.resume()\n },\n destroy(err, callback) {\n if (self.ws && self.ws.readyState !== WebSocket.CLOSED) {\n self.ws.terminate()\n }\n self.ws = null\n callback(err)\n },\n })\n }\n\n private ensureConnected(): void {\n if (this.connected) return\n this.connected = true\n this.ws = new WebSocket(this.url)\n\n this.ws.on('open', () => {\n ;(this.ws as unknown as { binaryType: string }).binaryType = 'nodebuffer'\n })\n\n this.ws.on('message', (data: Buffer, isBinary: boolean) => {\n if (isBinary) {\n if (!this.stream.push(data)) {\n this.ws?.pause()\n }\n } else {\n const msg = data.toString('utf-8')\n for (const cb of this.messageCallbacks) {\n cb(msg)\n }\n }\n })\n\n this.ws.on('close', () => {\n this.ws = null\n if (!this.stream.destroyed) this.stream.push(null)\n })\n\n this.ws.on('error', (err) => {\n this.stream.destroy(err)\n })\n }\n\n /** Register a callback to receive text messages from the channel. */\n onMessage(callback: (msg: string) => void): void {\n this.messageCallbacks.push(callback)\n }\n\n async readAll(): Promise<Buffer> {\n this.ensureConnected()\n const chunks: Buffer[] = []\n\n for await (const chunk of this.stream) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))\n }\n\n return Buffer.concat(chunks)\n }\n\n close(): void {\n if (this.ws && this.ws.readyState !== WebSocket.CLOSED) {\n this.ws.close(1000, 'channel_close')\n }\n }\n}\n\nfunction buildChannelUrl(\n engineWsBase: string,\n channelId: string,\n accessKey: string,\n direction: 'read' | 'write',\n): string {\n const base = engineWsBase.replace(/\\/$/, '')\n return `${base}/ws/channels/${channelId}?key=${encodeURIComponent(accessKey)}&dir=${direction}`\n}\n"],"mappings":";;;;;;;;;;AASA,MAAa,mBAAmB;CAC9B,MAAM;CACN,OAAO;CACR;AAaD,MAAa,cAAc;CAEzB,KAAK,OAA4B;AAC/B,SAAO;GAAE,MAAM;GAAQ;GAAO;;CAGhC,OAAO,OAAgC;AACrC,SAAO;GAAE,MAAM;GAAU;GAAO;;CAEnC;;;;;;;;;;;;;;;;;;;AAoBD,IAAa,gBAAb,MAAa,cAAc;;oBACY,KAAK;;CAW1C,YAAY,cAAsB,KAAuB;YAV1B;iBACb;yBAIZ,EAAE;AAMN,OAAK,MAAM,gBAAgB,cAAc,IAAI,YAAY,IAAI,YAAY,QAAQ;AAEjF,OAAK,SAAS,IAAIA,qBAAS;GACzB,QAAQ,OAAe,WAAW,aAAa;IAC7C,MAAM,MAAM,OAAO,SAAS,MAAM,GAAG,QAAQ,OAAO,KAAK,MAAM;AAC/D,SAAK,YAAY,KAAK,SAAS;;GAEjC,QAAQ,aAAa;AACnB,QAAI,CAAC,KAAK,IAAI;AACZ,eAAU;AACV;;IAKF,MAAM,gBAAgB;AACpB,SAAI,KAAK,GACP,MAAK,GAAG,MAAM,KAAM,kBAAkB;AAExC,eAAU;;AAEZ,QAAI,KAAK,QACP,YAAW,SAAS,GAAG;QAEvB,MAAK,GAAG,GAAG,cAAc,WAAW,SAAS,GAAG,CAAC;;GAGrD,UAAU,KAAK,aAAa;AAC1B,QAAI,KAAK,GAAI,MAAK,GAAG,WAAW;AAChC,aAAS,IAAI;;GAEhB,CAAC;;CAGJ,AAAQ,kBAAwB;AAC9B,MAAI,KAAK,GAAI;AACb,OAAK,KAAK,IAAIC,aAAU,KAAK,IAAI;AAEjC,OAAK,GAAG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AO;;CAG9B,QAAc;AACZ,MAAI,KAAK,MAAM,KAAK,GAAG,eAAeA,aAAU,OAC9C,MAAK,GAAG,MAAM,KAAM,gBAAgB;;;AAK1C,SAAS,gBACP,cACA,WACA,WACA,WACQ;AAER,QAAO,GADM,aAAa,QAAQ,OAAO,GAAG,CAC7B,eAAe,UAAU,OAAO,mBAAmB,UAAU,CAAC,OAAO"}
@@ -0,0 +1,5 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_iii_constants = require('./iii-constants-Br94RUNi.cjs');
3
+
4
+ exports.EngineFunctions = require_iii_constants.EngineFunctions;
5
+ exports.EngineTriggers = require_iii_constants.EngineTriggers;
@@ -0,0 +1,3 @@
1
+ import { u as RemoteFunctionHandler } from "./types-gwm9j9oD.cjs";
2
+ import { n as EngineTriggers, t as EngineFunctions } from "./iii-constants-BqXp8xSN.cjs";
3
+ export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
@@ -0,0 +1,3 @@
1
+ import { u as RemoteFunctionHandler } from "./types-DduY0ha2.mjs";
2
+ import { n as EngineTriggers, t as EngineFunctions } from "./iii-constants-Baptl8nm.mjs";
3
+ export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
@@ -0,0 +1,3 @@
1
+ import { i as EngineTriggers, r as EngineFunctions } from "./iii-constants-_k3SoHry.mjs";
2
+
3
+ export { EngineFunctions, EngineTriggers };
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/errors.ts
4
+ var InvocationError = class extends Error {
5
+ constructor(init) {
6
+ super(`${init.code}: ${init.message}`);
7
+ this.name = "InvocationError";
8
+ this.code = init.code;
9
+ this.function_id = init.function_id;
10
+ this.stacktrace = init.stacktrace;
11
+ }
12
+ };
13
+ /**
14
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
15
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
16
+ * Used to distinguish an engine rejection (which we wrap in
17
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
18
+ */
19
+ function isErrorBody(value) {
20
+ if (typeof value !== "object" || value === null) return false;
21
+ const v = value;
22
+ return typeof v.code === "string" && typeof v.message === "string" && (v.stacktrace === void 0 || typeof v.stacktrace === "string");
23
+ }
24
+ /**
25
+ * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.
26
+ */
27
+ const IIIInvocationError = InvocationError;
28
+
29
+ //#endregion
30
+ exports.IIIInvocationError = IIIInvocationError;
31
+ exports.InvocationError = InvocationError;
32
+ exports.isErrorBody = isErrorBody;
33
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails — RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified — leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n\n/**\n * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.\n */\nexport const IIIInvocationError = InvocationError\n/**\n * @deprecated Renamed to {@link InvocationError}.\n */\nexport type IIIInvocationError = InvocationError\n/**\n * @deprecated Renamed to {@link InvocationErrorInit}.\n */\nexport type IIIInvocationErrorInit = InvocationErrorInit\n"],"mappings":";;;AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;;;;;;;AAU3B,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe;;;;;AAO3D,MAAa,qBAAqB"}
@@ -0,0 +1,52 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Typed error surfaced when an invocation dispatched over the SDK fails — RBAC
4
+ * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
+ * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
+ * that was targeted, so callers get a single error type across all failure
7
+ * modes and can disambiguate via `err.code`.
8
+ *
9
+ * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
+ * which printed as `[object Object]` when stringified — leaving developers to
11
+ * grep through SDK source to figure out what tripped. The class name, `code`
12
+ * prefix in the message, and `function_id` field together make a rejection
13
+ * self-describing.
14
+ */
15
+ type InvocationErrorInit = {
16
+ code: string;
17
+ message: string;
18
+ function_id?: string;
19
+ stacktrace?: string;
20
+ };
21
+ declare class InvocationError extends Error {
22
+ readonly code: string;
23
+ readonly function_id?: string;
24
+ readonly stacktrace?: string;
25
+ constructor(init: InvocationErrorInit);
26
+ }
27
+ /**
28
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
29
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
30
+ * Used to distinguish an engine rejection (which we wrap in
31
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
32
+ */
33
+ declare function isErrorBody(value: unknown): value is {
34
+ code: string;
35
+ message: string;
36
+ stacktrace?: string;
37
+ };
38
+ /**
39
+ * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.
40
+ */
41
+ declare const IIIInvocationError: typeof InvocationError;
42
+ /**
43
+ * @deprecated Renamed to {@link InvocationError}.
44
+ */
45
+ type IIIInvocationError = InvocationError;
46
+ /**
47
+ * @deprecated Renamed to {@link InvocationErrorInit}.
48
+ */
49
+ type IIIInvocationErrorInit = InvocationErrorInit;
50
+ //#endregion
51
+ export { IIIInvocationError, IIIInvocationErrorInit, InvocationError, InvocationErrorInit, isErrorBody };
52
+ //# sourceMappingURL=errors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAaA;;;;;;;;;;AAOA;;KAPY,mBAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAGW,eAAA,SAAwB,KAAA;EAAA,SACnB,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;cAEJ,IAAA,EAAM,mBAAA;AAAA;;;;;;;iBAeJ,WAAA,CAAY,KAAA,YAAiB,KAAA;EAC3C,IAAA;EACA,OAAA;EACA,UAAA;AAAA;;;;cAcW,kBAAA,SAAkB,eAAA;AAI/B;;;AAAA,KAAY,kBAAA,GAAqB,eAAA;;AAIjC;;KAAY,sBAAA,GAAyB,mBAAA"}
@@ -0,0 +1,52 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Typed error surfaced when an invocation dispatched over the SDK fails — RBAC
4
+ * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
+ * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
+ * that was targeted, so callers get a single error type across all failure
7
+ * modes and can disambiguate via `err.code`.
8
+ *
9
+ * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
+ * which printed as `[object Object]` when stringified — leaving developers to
11
+ * grep through SDK source to figure out what tripped. The class name, `code`
12
+ * prefix in the message, and `function_id` field together make a rejection
13
+ * self-describing.
14
+ */
15
+ type InvocationErrorInit = {
16
+ code: string;
17
+ message: string;
18
+ function_id?: string;
19
+ stacktrace?: string;
20
+ };
21
+ declare class InvocationError extends Error {
22
+ readonly code: string;
23
+ readonly function_id?: string;
24
+ readonly stacktrace?: string;
25
+ constructor(init: InvocationErrorInit);
26
+ }
27
+ /**
28
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
29
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
30
+ * Used to distinguish an engine rejection (which we wrap in
31
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
32
+ */
33
+ declare function isErrorBody(value: unknown): value is {
34
+ code: string;
35
+ message: string;
36
+ stacktrace?: string;
37
+ };
38
+ /**
39
+ * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.
40
+ */
41
+ declare const IIIInvocationError: typeof InvocationError;
42
+ /**
43
+ * @deprecated Renamed to {@link InvocationError}.
44
+ */
45
+ type IIIInvocationError = InvocationError;
46
+ /**
47
+ * @deprecated Renamed to {@link InvocationErrorInit}.
48
+ */
49
+ type IIIInvocationErrorInit = InvocationErrorInit;
50
+ //#endregion
51
+ export { IIIInvocationError, IIIInvocationErrorInit, InvocationError, InvocationErrorInit, isErrorBody };
52
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAaA;;;;;;;;;;AAOA;;KAPY,mBAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAGW,eAAA,SAAwB,KAAA;EAAA,SACnB,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;cAEJ,IAAA,EAAM,mBAAA;AAAA;;;;;;;iBAeJ,WAAA,CAAY,KAAA,YAAiB,KAAA;EAC3C,IAAA;EACA,OAAA;EACA,UAAA;AAAA;;;;cAcW,kBAAA,SAAkB,eAAA;AAI/B;;;AAAA,KAAY,kBAAA,GAAqB,eAAA;;AAIjC;;KAAY,sBAAA,GAAyB,mBAAA"}
@@ -0,0 +1,29 @@
1
+ //#region src/errors.ts
2
+ var InvocationError = class extends Error {
3
+ constructor(init) {
4
+ super(`${init.code}: ${init.message}`);
5
+ this.name = "InvocationError";
6
+ this.code = init.code;
7
+ this.function_id = init.function_id;
8
+ this.stacktrace = init.stacktrace;
9
+ }
10
+ };
11
+ /**
12
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
13
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
14
+ * Used to distinguish an engine rejection (which we wrap in
15
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
16
+ */
17
+ function isErrorBody(value) {
18
+ if (typeof value !== "object" || value === null) return false;
19
+ const v = value;
20
+ return typeof v.code === "string" && typeof v.message === "string" && (v.stacktrace === void 0 || typeof v.stacktrace === "string");
21
+ }
22
+ /**
23
+ * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.
24
+ */
25
+ const IIIInvocationError = InvocationError;
26
+
27
+ //#endregion
28
+ export { IIIInvocationError, InvocationError, isErrorBody };
29
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails — RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified — leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n\n/**\n * @deprecated Renamed to {@link InvocationError}; import from `iii-sdk/errors`.\n */\nexport const IIIInvocationError = InvocationError\n/**\n * @deprecated Renamed to {@link InvocationError}.\n */\nexport type IIIInvocationError = InvocationError\n/**\n * @deprecated Renamed to {@link InvocationErrorInit}.\n */\nexport type IIIInvocationErrorInit = InvocationErrorInit\n"],"mappings":";AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;;;;;;;AAU3B,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe;;;;;AAO3D,MAAa,qBAAqB"}
package/dist/helpers.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_utils = require('./utils-CuS1Knym.cjs');
2
+ const require_utils = require('./utils-BtEFReHq.cjs');
3
+ const require_channels = require('./channels-huduKJ-b.cjs');
3
4
 
4
5
  //#region src/helpers.ts
5
6
  /**
@@ -21,8 +22,8 @@ function createStream(iii, streamName, stream) {
21
22
  }
22
23
 
23
24
  //#endregion
24
- exports.ChannelDirection = require_utils.ChannelDirection;
25
- exports.ChannelItem = require_utils.ChannelItem;
25
+ exports.ChannelDirection = require_channels.ChannelDirection;
26
+ exports.ChannelItem = require_channels.ChannelItem;
26
27
  exports.createChannel = createChannel;
27
28
  exports.createStream = createStream;
28
29
  exports.extractChannelRefs = require_utils.extractChannelRefs;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["/**\n * Helper free functions that operate on an {@link ISdk} instance.\n *\n * These were previously instance methods on the SDK. They take the iii\n * instance as the first argument so the public API surface of `ISdk` stays\n * focused on the core lifecycle and registration methods.\n */\nimport type { Channel, ISdk } from './types'\nimport type { IStream } from './stream'\n\nexport { ChannelDirection, ChannelItem } from './channels'\nexport { extractChannelRefs, isChannelRef } from './utils'\n\ntype IIIWithHelperShims = ISdk & {\n __helpers_create_channel(bufferSize?: number): Promise<Channel>\n __helpers_create_stream<T>(name: string, stream: IStream<T>): void\n}\n\n/**\n * Create a streaming channel pair for worker-to-worker data transfer.\n *\n * Free-function form of the previous `ISdk.createChannel` instance method.\n */\nexport function createChannel(iii: ISdk, bufferSize?: number): Promise<Channel> {\n return (iii as IIIWithHelperShims).__helpers_create_channel(bufferSize)\n}\n\n/**\n * Register a custom stream implementation by wiring its 5 callable methods\n * to `stream::get/set/delete/list/list_groups`.\n *\n * Free-function form of the previous `ISdk.createStream` instance method.\n */\nexport function createStream<TData>(iii: ISdk, streamName: string, stream: IStream<TData>): void {\n ;(iii as IIIWithHelperShims).__helpers_create_stream(streamName, stream)\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,cAAc,KAAW,YAAuC;AAC9E,QAAQ,IAA2B,yBAAyB,WAAW;;;;;;;;AASzE,SAAgB,aAAoB,KAAW,YAAoB,QAA8B;AAC9F,CAAC,IAA2B,wBAAwB,YAAY,OAAO"}
1
+ {"version":3,"file":"helpers.cjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["/**\n * Helper free functions that operate on an {@link ISdk} instance.\n *\n * These were previously instance methods on the SDK. They take the iii\n * instance as the first argument so the public API surface of `ISdk` stays\n * focused on the core lifecycle and registration methods.\n */\nimport type { Channel, ISdk } from './types'\nimport type { IStream } from './stream'\n\nexport { ChannelDirection, ChannelItem } from './channels'\nexport { extractChannelRefs, isChannelRef } from './utils'\n\ntype IIIWithHelperShims = ISdk & {\n __helpers_create_channel(bufferSize?: number): Promise<Channel>\n __helpers_create_stream<T>(name: string, stream: IStream<T>): void\n}\n\n/**\n * Create a streaming channel pair for worker-to-worker data transfer.\n *\n * Free-function form of the previous `ISdk.createChannel` instance method.\n */\nexport function createChannel(iii: ISdk, bufferSize?: number): Promise<Channel> {\n return (iii as IIIWithHelperShims).__helpers_create_channel(bufferSize)\n}\n\n/**\n * Register a custom stream implementation by wiring its 5 callable methods\n * to `stream::get/set/delete/list/list_groups`.\n *\n * Free-function form of the previous `ISdk.createStream` instance method.\n */\nexport function createStream<TData>(iii: ISdk, streamName: string, stream: IStream<TData>): void {\n ;(iii as IIIWithHelperShims).__helpers_create_stream(streamName, stream)\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,cAAc,KAAW,YAAuC;AAC9E,QAAQ,IAA2B,yBAAyB,WAAW;;;;;;;;AASzE,SAAgB,aAAoB,KAAW,YAAoB,QAA8B;AAC9F,CAAC,IAA2B,wBAAwB,YAAY,OAAO"}
@@ -1,6 +1,24 @@
1
- import { S as ChannelItem, o as Channel, r as isChannelRef, t as extractChannelRefs, u as ISdk, x as ChannelDirection } from "./utils-BnRzIUCy.cjs";
1
+ import { O as StreamChannelRef, _ as ChannelDirection, i as ISdk, t as Channel, v as ChannelItem } from "./types-gwm9j9oD.cjs";
2
2
  import { IStream } from "./stream.cjs";
3
3
 
4
+ //#region src/utils.d.ts
5
+ /**
6
+ * Type guard that checks if a value is a {@link StreamChannelRef}.
7
+ *
8
+ * @param value - Value to check.
9
+ * @returns `true` if the value is a valid `StreamChannelRef`.
10
+ */
11
+ declare const isChannelRef: (value: unknown) => value is StreamChannelRef;
12
+ /**
13
+ * Recursively extract all {@link StreamChannelRef} values from a JSON-like
14
+ * input, returning each match paired with its dotted/bracketed path. Mirrors
15
+ * the Rust SDK's `extract_channel_refs`.
16
+ *
17
+ * @param data - Arbitrary JSON-like value.
18
+ * @returns Array of `[path, ref]` tuples. Empty when no refs are found.
19
+ */
20
+ declare const extractChannelRefs: (data: unknown) => Array<[string, StreamChannelRef]>;
21
+ //#endregion
4
22
  //#region src/helpers.d.ts
5
23
  /**
6
24
  * Create a streaming channel pair for worker-to-worker data transfer.