iii-sdk 0.22.0-alpha.4 → 0.22.0-alpha.6
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.d.cts +1 -1
- package/dist/channel.d.mts +1 -1
- package/dist/engine.d.cts +1 -1
- package/dist/engine.d.mts +1 -1
- package/dist/helpers.d.cts +1 -1
- package/dist/helpers.d.mts +1 -1
- package/dist/iii-types-BHasLgj1.cjs.map +1 -1
- package/dist/iii-types-Btz-0RpP.mjs.map +1 -1
- package/dist/index.cjs +32 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +16 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -49
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/protocol.d.cts +1 -1
- package/dist/protocol.d.mts +1 -1
- package/dist/runtime.d.cts +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/trigger.d.cts +1 -1
- package/dist/trigger.d.mts +1 -1
- package/dist/{types-cLCLqZrc.d.cts → types-C43VHoZq.d.cts} +9 -52
- package/dist/types-C43VHoZq.d.cts.map +1 -0
- package/dist/{types-D6dInVB5.d.mts → types-CPReRK1z.d.mts} +9 -52
- package/dist/types-CPReRK1z.d.mts.map +1 -0
- package/package.json +2 -2
- package/dist/types-D6dInVB5.d.mts.map +0 -1
- package/dist/types-cLCLqZrc.d.cts.map +0 -1
package/dist/channel.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-
|
|
1
|
+
import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-C43VHoZq.cjs";
|
|
2
2
|
export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
|
package/dist/channel.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-
|
|
1
|
+
import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-CPReRK1z.mjs";
|
|
2
2
|
export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
|
package/dist/engine.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-
|
|
1
|
+
import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-C43VHoZq.cjs";
|
|
2
2
|
export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
|
package/dist/engine.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-
|
|
1
|
+
import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-CPReRK1z.mjs";
|
|
2
2
|
export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-
|
|
1
|
+
import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-C43VHoZq.cjs";
|
|
2
2
|
import { IStream } from "./stream.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils.d.ts
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-
|
|
1
|
+
import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-CPReRK1z.mjs";
|
|
2
2
|
import { IStream } from "./stream.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils.d.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iii-types-BHasLgj1.cjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\n/**\n * A `function_id` accepted wherever a target function is named: a bare string,\n * or a ref (e.g. a `FunctionRef` from `registerFunction`) carrying the namespace\n * where the function was registered. When a ref is passed, its namespace is used\n * for routing unless an explicit `namespace` overrides it.\n */\nexport type FunctionTarget = string | { function_id: string; namespace?: string }\n\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke, or a ref carrying its namespace. */\n function_id: FunctionTarget\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";;AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
|
|
1
|
+
{"version":3,"file":"iii-types-BHasLgj1.cjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";;AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iii-types-Btz-0RpP.mjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\n/**\n * A `function_id` accepted wherever a target function is named: a bare string,\n * or a ref (e.g. a `FunctionRef` from `registerFunction`) carrying the namespace\n * where the function was registered. When a ref is passed, its namespace is used\n * for routing unless an explicit `namespace` overrides it.\n */\nexport type FunctionTarget = string | { function_id: string; namespace?: string }\n\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke, or a ref carrying its namespace. */\n function_id: FunctionTarget\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
|
|
1
|
+
{"version":3,"file":"iii-types-Btz-0RpP.mjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
|
package/dist/index.cjs
CHANGED
|
@@ -34,23 +34,24 @@ function getDefaultWorkerName() {
|
|
|
34
34
|
if (managedName) return managedName;
|
|
35
35
|
return `${node_os.hostname()}:${process.pid}`;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Engine address used when neither an explicit address nor `III_URL` is set.
|
|
39
|
+
* The IPv4 loopback is spelled out on purpose: `localhost` can resolve to `::1`
|
|
40
|
+
* on a host whose engine only listens on IPv4.
|
|
41
|
+
*/
|
|
42
|
+
const DEFAULT_ENGINE_URL = "ws://127.0.0.1:49134";
|
|
43
|
+
function resolveAddress(address) {
|
|
44
|
+
if (address) return address;
|
|
45
|
+
const fromEnv = process.env.III_URL;
|
|
46
|
+
if (fromEnv) return fromEnv;
|
|
47
|
+
return DEFAULT_ENGINE_URL;
|
|
48
|
+
}
|
|
37
49
|
function resolveNamespace(optionNamespace) {
|
|
38
50
|
if (optionNamespace) return optionNamespace;
|
|
39
51
|
const managedNamespace = process.env.III_NAMESPACE;
|
|
40
52
|
if (managedNamespace) return managedNamespace;
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
* Normalizes a `function_id` that may be a bare string or a {@link FunctionRef}.
|
|
44
|
-
* A ref carries the namespace where the function was registered, so triggers and
|
|
45
|
-
* invocations can target it without the caller restating the namespace.
|
|
46
|
-
*/
|
|
47
|
-
function resolveFunctionTarget(fn) {
|
|
48
|
-
return typeof fn === "string" ? { function_id: fn } : {
|
|
49
|
-
function_id: fn.function_id,
|
|
50
|
-
namespace: fn.namespace
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
var Sdk = class Sdk {
|
|
54
|
+
var Sdk = class {
|
|
54
55
|
constructor(address, options) {
|
|
55
56
|
this.address = address;
|
|
56
57
|
this.options = options;
|
|
@@ -62,7 +63,6 @@ var Sdk = class Sdk {
|
|
|
62
63
|
this.reconnectAttempt = 0;
|
|
63
64
|
this.connectionState = "disconnected";
|
|
64
65
|
this.isShuttingDown = false;
|
|
65
|
-
this.namespaceViews = /* @__PURE__ */ new Map();
|
|
66
66
|
this.registerTriggerType = (triggerType, handler) => {
|
|
67
67
|
this.sendMessage(require_iii_types.MessageType.RegisterTriggerType, triggerType, true);
|
|
68
68
|
this.triggerTypes.set(triggerType.id, {
|
|
@@ -79,16 +79,18 @@ var Sdk = class Sdk {
|
|
|
79
79
|
type: triggerType.id,
|
|
80
80
|
function_id: functionId,
|
|
81
81
|
config,
|
|
82
|
-
metadata
|
|
82
|
+
metadata,
|
|
83
|
+
namespace: this.namespace
|
|
83
84
|
});
|
|
84
85
|
},
|
|
85
86
|
registerFunction: (functionId, handler, config, metadata) => {
|
|
86
87
|
const ref = this.registerFunction(functionId, handler);
|
|
87
88
|
this.registerTrigger({
|
|
88
89
|
type: triggerType.id,
|
|
89
|
-
function_id:
|
|
90
|
+
function_id: functionId,
|
|
90
91
|
config,
|
|
91
|
-
metadata
|
|
92
|
+
metadata,
|
|
93
|
+
namespace: this.namespace
|
|
92
94
|
});
|
|
93
95
|
return ref;
|
|
94
96
|
},
|
|
@@ -103,12 +105,8 @@ var Sdk = class Sdk {
|
|
|
103
105
|
};
|
|
104
106
|
this.registerTrigger = (trigger) => {
|
|
105
107
|
const id = crypto.randomUUID();
|
|
106
|
-
const target = resolveFunctionTarget(trigger.function_id);
|
|
107
|
-
const namespace = trigger.namespace ?? target.namespace ?? this.namespace;
|
|
108
108
|
const fullTrigger = {
|
|
109
109
|
...trigger,
|
|
110
|
-
function_id: target.function_id,
|
|
111
|
-
...namespace !== void 0 ? { namespace } : {},
|
|
112
110
|
id,
|
|
113
111
|
message_type: require_iii_types.MessageType.RegisterTrigger
|
|
114
112
|
};
|
|
@@ -199,8 +197,6 @@ var Sdk = class Sdk {
|
|
|
199
197
|
} else this.functions.set(functionId, { message: fullMessage });
|
|
200
198
|
return {
|
|
201
199
|
id: functionId,
|
|
202
|
-
function_id: functionId,
|
|
203
|
-
namespace: this.namespace,
|
|
204
200
|
unregister: () => {
|
|
205
201
|
this.sendMessage(require_iii_types.MessageType.UnregisterFunction, { id: functionId }, true);
|
|
206
202
|
this.functions.delete(functionId);
|
|
@@ -211,7 +207,7 @@ var Sdk = class Sdk {
|
|
|
211
207
|
const result = await this.trigger({
|
|
212
208
|
function_id: "engine::channels::create",
|
|
213
209
|
payload: { buffer_size: bufferSize }
|
|
214
|
-
}
|
|
210
|
+
});
|
|
215
211
|
return {
|
|
216
212
|
writer: new require_channels.ChannelWriter(this.address, result.writer),
|
|
217
213
|
reader: new require_channels.ChannelReader(this.address, result.reader),
|
|
@@ -219,11 +215,8 @@ var Sdk = class Sdk {
|
|
|
219
215
|
readerRef: result.reader
|
|
220
216
|
};
|
|
221
217
|
};
|
|
222
|
-
this.trigger = async (request
|
|
223
|
-
const { function_id
|
|
224
|
-
const target = resolveFunctionTarget(functionTarget);
|
|
225
|
-
const function_id = target.function_id;
|
|
226
|
-
const namespace = opts?.routeToDefault ? explicitNamespace : explicitNamespace ?? target.namespace ?? this.namespace;
|
|
218
|
+
this.trigger = async (request) => {
|
|
219
|
+
const { function_id, payload, action, timeoutMs, metadata, namespace } = request;
|
|
227
220
|
const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
|
|
228
221
|
if (action?.type === "void") {
|
|
229
222
|
const traceparent = (0, _iii_dev_helpers_observability.injectTraceparent)();
|
|
@@ -277,17 +270,6 @@ var Sdk = class Sdk {
|
|
|
277
270
|
});
|
|
278
271
|
});
|
|
279
272
|
};
|
|
280
|
-
this.useNamespace = (namespace) => {
|
|
281
|
-
if (namespace === (this.namespace ?? "default")) return this;
|
|
282
|
-
const cached = this.namespaceViews.get(namespace);
|
|
283
|
-
if (cached) return cached;
|
|
284
|
-
const view = new Sdk(this.address, {
|
|
285
|
-
...this.options,
|
|
286
|
-
namespace
|
|
287
|
-
});
|
|
288
|
-
this.namespaceViews.set(namespace, view);
|
|
289
|
-
return view;
|
|
290
|
-
};
|
|
291
273
|
this.__helpers_create_stream = (streamName, stream) => {
|
|
292
274
|
this.registerFunction(`stream::get(${streamName})`, stream.get.bind(stream));
|
|
293
275
|
this.registerFunction(`stream::set(${streamName})`, stream.set.bind(stream));
|
|
@@ -296,12 +278,10 @@ var Sdk = class Sdk {
|
|
|
296
278
|
this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream));
|
|
297
279
|
};
|
|
298
280
|
this.getConnectionState = () => this.connectionState;
|
|
281
|
+
this.getAddress = () => this.address;
|
|
299
282
|
this.getFatalError = () => this.fatalError;
|
|
300
283
|
this.shutdown = async () => {
|
|
301
284
|
this.isShuttingDown = true;
|
|
302
|
-
const views = [...this.namespaceViews.values()];
|
|
303
|
-
this.namespaceViews.clear();
|
|
304
|
-
await Promise.all(views.map((view) => view.shutdown()));
|
|
305
285
|
this.stopMetricsReporting();
|
|
306
286
|
await (0, _iii_dev_helpers_observability.shutdownOtel)();
|
|
307
287
|
this.clearReconnectTimeout();
|
|
@@ -358,7 +338,7 @@ var Sdk = class Sdk {
|
|
|
358
338
|
}
|
|
359
339
|
},
|
|
360
340
|
action: { type: "void" }
|
|
361
|
-
}
|
|
341
|
+
});
|
|
362
342
|
}
|
|
363
343
|
setConnectionState(state) {
|
|
364
344
|
if (this.connectionState !== state) this.connectionState = state;
|
|
@@ -816,7 +796,8 @@ const TriggerAction = {
|
|
|
816
796
|
* Register the worker with a iii instance, returns a connected worker client.
|
|
817
797
|
* The WebSocket connection is established automatically.
|
|
818
798
|
*
|
|
819
|
-
* @param address - WebSocket URL of the III engine
|
|
799
|
+
* @param address - WebSocket URL of the III engine. Omit to resolve it from
|
|
800
|
+
* `process.env.III_URL`, falling back to {@link DEFAULT_ENGINE_URL}.
|
|
820
801
|
* @param options - Optional {@link InitOptions} for worker name, timeouts, reconnection, and OTel.
|
|
821
802
|
* @returns A connected {@link IIIClient} instance.
|
|
822
803
|
*
|
|
@@ -824,14 +805,17 @@ const TriggerAction = {
|
|
|
824
805
|
* ```typescript
|
|
825
806
|
* import { registerWorker } from 'iii-sdk'
|
|
826
807
|
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
808
|
+
* // Address from III_URL, set by whatever supervisor spawned this worker.
|
|
809
|
+
* const worker = registerWorker()
|
|
810
|
+
*
|
|
811
|
+
* // Or explicitly, which always wins over the environment.
|
|
812
|
+
* const other = registerWorker('ws://localhost:49134', { workerName: 'my-worker' })
|
|
830
813
|
* ```
|
|
831
814
|
*/
|
|
832
|
-
const registerWorker = (address, options) => new Sdk(address, options);
|
|
815
|
+
const registerWorker = (address, options) => new Sdk(resolveAddress(address), options);
|
|
833
816
|
|
|
834
817
|
//#endregion
|
|
818
|
+
exports.DEFAULT_ENGINE_URL = DEFAULT_ENGINE_URL;
|
|
835
819
|
exports.InvocationError = require_errors.InvocationError;
|
|
836
820
|
exports.RegistrationRejectedError = require_errors.RegistrationRejectedError;
|
|
837
821
|
exports.TriggerAction = TriggerAction;
|