iii-sdk 0.0.2-alpha
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/README.md +100 -0
- package/dist/iii-dNb0FMyR.d.mts +418 -0
- package/dist/iii-dNb0FMyR.d.mts.map +1 -0
- package/dist/iii-wiV77JNv.d.cts +418 -0
- package/dist/iii-wiV77JNv.d.cts.map +1 -0
- package/dist/index.cjs +642 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +51 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +610 -0
- package/dist/index.mjs.map +1 -0
- package/dist/otel-worker-gauges-ELciXZRg.mjs +908 -0
- package/dist/otel-worker-gauges-ELciXZRg.mjs.map +1 -0
- package/dist/otel-worker-gauges-bAp_yKcU.cjs +1064 -0
- package/dist/otel-worker-gauges-bAp_yKcU.cjs.map +1 -0
- package/dist/stream-BB7BoxzH.d.mts +97 -0
- package/dist/stream-BB7BoxzH.d.mts.map +1 -0
- package/dist/stream-BBAV0zc7.d.cts +97 -0
- package/dist/stream-BBAV0zc7.d.cts.map +1 -0
- package/dist/stream.cjs +0 -0
- package/dist/stream.d.cts +2 -0
- package/dist/stream.d.mts +2 -0
- package/dist/stream.mjs +1 -0
- package/dist/telemetry.cjs +33 -0
- package/dist/telemetry.d.cts +112 -0
- package/dist/telemetry.d.cts.map +1 -0
- package/dist/telemetry.d.mts +112 -0
- package/dist/telemetry.d.mts.map +1 -0
- package/dist/telemetry.mjs +3 -0
- package/package.json +59 -0
- package/tests/healthcheck.test.ts +53 -0
- package/tests/setup.ts +48 -0
- package/tests/state.test.ts +149 -0
- package/tests/stream.test.ts +217 -0
- package/tests/types.ts +54 -0
- package/tests/utils.ts +83 -0
- package/vitest.config.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# III SDK for Node.js
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install iii-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
import { III } from 'iii-sdk'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Make sure the III Core Instance is up and Running on the given URL.
|
|
16
|
+
*/
|
|
17
|
+
const iii = new III(process.env.III_BRIDGE_URL ?? 'ws://localhost:49134')
|
|
18
|
+
|
|
19
|
+
iii.registerFunction({ id: 'myFunction' }, (req) => {
|
|
20
|
+
return { status_code: 200, body: { message: 'Hello, world!' } }
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
iii.registerTrigger({
|
|
24
|
+
trigger_type: 'api',
|
|
25
|
+
function_id: 'myFunction',
|
|
26
|
+
config: { api_path: 'myApiPath', http_method: 'POST' },
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Registering Functions
|
|
31
|
+
|
|
32
|
+
III Allows you to register functions that can be invoked by other services.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
iii.registerFunction({ id: 'myFunction' }, (req) => {
|
|
36
|
+
// ... do something
|
|
37
|
+
return { status_code: 200, body: { message: 'Hello, world!' } }
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Registering Triggers
|
|
42
|
+
|
|
43
|
+
III Allows you to register triggers that can be invoked by other services.
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
iii.registerTrigger({
|
|
47
|
+
trigger_type: 'api',
|
|
48
|
+
function_id: 'myFunction',
|
|
49
|
+
config: { api_path: 'myApiPath', http_method: 'POST' },
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Registering Trigger Types
|
|
54
|
+
|
|
55
|
+
Triggers are mostly created by III Core Modules, but you can also create your own triggers
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
iii.registerTrigger_type(
|
|
59
|
+
{
|
|
60
|
+
/**
|
|
61
|
+
* This is the id of the trigger type, it's unique.
|
|
62
|
+
* Then, you can register a trigger by calling the registerTrigger method.
|
|
63
|
+
*/
|
|
64
|
+
id: 'myTrigger_type',
|
|
65
|
+
description: 'My trigger type',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
/**
|
|
69
|
+
* Trigger config has: id, function_id, and config.
|
|
70
|
+
* Your logic should know what to do with the config.
|
|
71
|
+
*/
|
|
72
|
+
registerTrigger: async (config) => {
|
|
73
|
+
// ... do something
|
|
74
|
+
},
|
|
75
|
+
unregisterTrigger: async (config) => {
|
|
76
|
+
// ... do something
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Invoking Functions
|
|
83
|
+
|
|
84
|
+
III Allows you to invoke functions, they can be functions from the Core Modules or
|
|
85
|
+
functions registered by workers.
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const result = await iii.call('myFunction', { param1: 'value1' })
|
|
89
|
+
console.log(result)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Invoking Functions Async
|
|
93
|
+
|
|
94
|
+
III Allows you to invoke functions asynchronously, they can be functions from the Core Modules or functions registered by workers.
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
iii.callVoid('myFunction', { param1: 'value1' })
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This means the Engine won't hold the execution of the function, it will return immediately. Which means the function will be executed in the background.
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { n as IStream } from "./stream-BB7BoxzH.mjs";
|
|
2
|
+
import { Context, Meter as Meter$1, Span as Span$1, SpanKind, SpanStatusCode, Tracer } from "@opentelemetry/api";
|
|
3
|
+
import { Logger, SeverityNumber as SeverityNumber$1 } from "@opentelemetry/api-logs";
|
|
4
|
+
import { Instrumentation } from "@opentelemetry/instrumentation";
|
|
5
|
+
|
|
6
|
+
//#region src/iii-constants.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Constants for the III module.
|
|
9
|
+
*/
|
|
10
|
+
/** Engine function paths for internal operations */
|
|
11
|
+
declare const EngineFunctions: {
|
|
12
|
+
readonly LIST_FUNCTIONS: "engine.functions.list";
|
|
13
|
+
readonly LIST_WORKERS: "engine.workers.list";
|
|
14
|
+
readonly REGISTER_WORKER: "engine.workers.register";
|
|
15
|
+
};
|
|
16
|
+
/** Engine trigger types */
|
|
17
|
+
declare const EngineTriggers: {
|
|
18
|
+
readonly FUNCTIONS_AVAILABLE: "engine::functions-available";
|
|
19
|
+
readonly LOG: "log";
|
|
20
|
+
};
|
|
21
|
+
/** Log function paths */
|
|
22
|
+
declare const LogFunctions: {
|
|
23
|
+
readonly INFO: "log.info";
|
|
24
|
+
readonly WARN: "log.warn";
|
|
25
|
+
readonly ERROR: "log.error";
|
|
26
|
+
readonly DEBUG: "log.debug";
|
|
27
|
+
};
|
|
28
|
+
/** Connection state for the III WebSocket */
|
|
29
|
+
type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
|
|
30
|
+
/** Configuration for WebSocket reconnection behavior */
|
|
31
|
+
interface IIIReconnectionConfig {
|
|
32
|
+
/** Starting delay in milliseconds (default: 1000ms) */
|
|
33
|
+
initialDelayMs: number;
|
|
34
|
+
/** Maximum delay cap in milliseconds (default: 30000ms) */
|
|
35
|
+
maxDelayMs: number;
|
|
36
|
+
/** Exponential backoff multiplier (default: 2) */
|
|
37
|
+
backoffMultiplier: number;
|
|
38
|
+
/** Random jitter factor 0-1 (default: 0.3) */
|
|
39
|
+
jitterFactor: number;
|
|
40
|
+
/** Maximum retry attempts, -1 for infinite (default: -1) */
|
|
41
|
+
maxRetries: number;
|
|
42
|
+
}
|
|
43
|
+
/** Default reconnection configuration */
|
|
44
|
+
declare const DEFAULT_BRIDGE_RECONNECTION_CONFIG: IIIReconnectionConfig;
|
|
45
|
+
/** Default invocation timeout in milliseconds */
|
|
46
|
+
declare const DEFAULT_INVOCATION_TIMEOUT_MS = 30000;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/telemetry-system/types.d.ts
|
|
49
|
+
/** Configuration for WebSocket reconnection behavior */
|
|
50
|
+
interface ReconnectionConfig {
|
|
51
|
+
/** Starting delay in milliseconds (default: 1000ms) */
|
|
52
|
+
initialDelayMs: number;
|
|
53
|
+
/** Maximum delay cap in milliseconds (default: 30000ms) */
|
|
54
|
+
maxDelayMs: number;
|
|
55
|
+
/** Exponential backoff multiplier (default: 2) */
|
|
56
|
+
backoffMultiplier: number;
|
|
57
|
+
/** Random jitter factor 0-1 (default: 0.3) */
|
|
58
|
+
jitterFactor: number;
|
|
59
|
+
/** Maximum retry attempts, -1 for infinite (default: -1) */
|
|
60
|
+
maxRetries: number;
|
|
61
|
+
}
|
|
62
|
+
/** Configuration for OpenTelemetry initialization. */
|
|
63
|
+
interface OtelConfig {
|
|
64
|
+
/** Whether OpenTelemetry export is enabled. Defaults to OTEL_ENABLED env var. */
|
|
65
|
+
enabled?: boolean;
|
|
66
|
+
/** The service name to report. Defaults to OTEL_SERVICE_NAME or "iii-node". */
|
|
67
|
+
serviceName?: string;
|
|
68
|
+
/** The service version to report. Defaults to SERVICE_VERSION env var or "unknown". */
|
|
69
|
+
serviceVersion?: string;
|
|
70
|
+
/** The service namespace to report. Defaults to SERVICE_NAMESPACE env var. */
|
|
71
|
+
serviceNamespace?: string;
|
|
72
|
+
/** The service instance ID to report. Defaults to SERVICE_INSTANCE_ID env var or auto-generated UUID. */
|
|
73
|
+
serviceInstanceId?: string;
|
|
74
|
+
/** III Engine WebSocket URL. Defaults to III_BRIDGE_URL or "ws://localhost:49134". */
|
|
75
|
+
engineWsUrl?: string;
|
|
76
|
+
/** OpenTelemetry instrumentations to register (e.g., PrismaInstrumentation). */
|
|
77
|
+
instrumentations?: Instrumentation[];
|
|
78
|
+
/** Whether OpenTelemetry metrics export is enabled. Defaults to OTEL_METRICS_ENABLED env var. */
|
|
79
|
+
metricsEnabled?: boolean;
|
|
80
|
+
/** Metrics export interval in milliseconds. Defaults to 60000 (60 seconds). */
|
|
81
|
+
metricsExportIntervalMs?: number;
|
|
82
|
+
/** Optional reconnection configuration for the WebSocket connection. */
|
|
83
|
+
reconnectionConfig?: Partial<ReconnectionConfig>;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/telemetry-system/context.d.ts
|
|
87
|
+
/**
|
|
88
|
+
* Extract the current trace ID from the active span context.
|
|
89
|
+
*/
|
|
90
|
+
declare function currentTraceId(): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Extract the current span ID from the active span context.
|
|
93
|
+
*/
|
|
94
|
+
declare function currentSpanId(): string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Inject the current trace context into a W3C traceparent header string.
|
|
97
|
+
*/
|
|
98
|
+
declare function injectTraceparent(): string | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Extract a trace context from a W3C traceparent header string.
|
|
101
|
+
*/
|
|
102
|
+
declare function extractTraceparent(traceparent: string): Context;
|
|
103
|
+
/**
|
|
104
|
+
* Inject the current baggage into a W3C baggage header string.
|
|
105
|
+
*/
|
|
106
|
+
declare function injectBaggage(): string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Extract baggage from a W3C baggage header string.
|
|
109
|
+
*/
|
|
110
|
+
declare function extractBaggage(baggage: string): Context;
|
|
111
|
+
/**
|
|
112
|
+
* Extract both trace context and baggage from their respective headers.
|
|
113
|
+
*/
|
|
114
|
+
declare function extractContext(traceparent?: string, baggage?: string): Context;
|
|
115
|
+
/**
|
|
116
|
+
* Get a baggage entry from the current context.
|
|
117
|
+
*/
|
|
118
|
+
declare function getBaggageEntry(key: string): string | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Set a baggage entry in the current context.
|
|
121
|
+
*/
|
|
122
|
+
declare function setBaggageEntry(key: string, value: string): Context;
|
|
123
|
+
/**
|
|
124
|
+
* Remove a baggage entry from the current context.
|
|
125
|
+
*/
|
|
126
|
+
declare function removeBaggageEntry(key: string): Context;
|
|
127
|
+
/**
|
|
128
|
+
* Get all baggage entries from the current context.
|
|
129
|
+
*/
|
|
130
|
+
declare function getAllBaggage(): Record<string, string>;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/telemetry-system/index.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* Initialize OpenTelemetry with the given configuration.
|
|
135
|
+
* This should be called once at application startup.
|
|
136
|
+
*/
|
|
137
|
+
declare function initOtel(config?: OtelConfig): void;
|
|
138
|
+
/**
|
|
139
|
+
* Shutdown OpenTelemetry, flushing any pending data.
|
|
140
|
+
*/
|
|
141
|
+
declare function shutdownOtel(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the OpenTelemetry tracer instance.
|
|
144
|
+
*/
|
|
145
|
+
declare function getTracer(): Tracer | null;
|
|
146
|
+
/**
|
|
147
|
+
* Get the OpenTelemetry meter instance.
|
|
148
|
+
*/
|
|
149
|
+
declare function getMeter(): Meter$1 | null;
|
|
150
|
+
/**
|
|
151
|
+
* Get the OpenTelemetry logger instance.
|
|
152
|
+
*/
|
|
153
|
+
declare function getLogger(): Logger | null;
|
|
154
|
+
/**
|
|
155
|
+
* Start a new span with the given name and run the callback within it.
|
|
156
|
+
*/
|
|
157
|
+
declare function withSpan<T>(name: string, options: {
|
|
158
|
+
kind?: SpanKind;
|
|
159
|
+
traceparent?: string;
|
|
160
|
+
}, fn: (span: Span$1) => Promise<T>): Promise<T>;
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/iii-types.d.ts
|
|
163
|
+
declare enum MessageType {
|
|
164
|
+
RegisterFunction = "registerfunction",
|
|
165
|
+
UnregisterFunction = "unregisterfunction",
|
|
166
|
+
RegisterService = "registerservice",
|
|
167
|
+
InvokeFunction = "invokefunction",
|
|
168
|
+
InvocationResult = "invocationresult",
|
|
169
|
+
RegisterTriggerType = "registertriggertype",
|
|
170
|
+
RegisterTrigger = "registertrigger",
|
|
171
|
+
UnregisterTrigger = "unregistertrigger",
|
|
172
|
+
UnregisterTriggerType = "unregistertriggertype",
|
|
173
|
+
TriggerRegistrationResult = "triggerregistrationresult",
|
|
174
|
+
WorkerRegistered = "workerregistered",
|
|
175
|
+
}
|
|
176
|
+
type RegisterTriggerTypeMessage = {
|
|
177
|
+
type: MessageType.RegisterTriggerType;
|
|
178
|
+
id: string;
|
|
179
|
+
description: string;
|
|
180
|
+
};
|
|
181
|
+
type RegisterTriggerMessage = {
|
|
182
|
+
type: MessageType.RegisterTrigger;
|
|
183
|
+
id: string;
|
|
184
|
+
/**
|
|
185
|
+
* The type of trigger. Can be 'cron', 'event', 'http', etc.
|
|
186
|
+
*/
|
|
187
|
+
trigger_type: string;
|
|
188
|
+
/**
|
|
189
|
+
* Engine path for the function, including the service and function name
|
|
190
|
+
* Example: software.engineering.code.rust
|
|
191
|
+
* Where software, engineering, and code are the service ids
|
|
192
|
+
*/
|
|
193
|
+
function_id: string;
|
|
194
|
+
config: any;
|
|
195
|
+
};
|
|
196
|
+
type RegisterFunctionFormat = {
|
|
197
|
+
name: string;
|
|
198
|
+
/**
|
|
199
|
+
* The description of the parameter
|
|
200
|
+
*/
|
|
201
|
+
description?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The type of the parameter
|
|
204
|
+
*/
|
|
205
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map';
|
|
206
|
+
/**
|
|
207
|
+
* The body of the parameter
|
|
208
|
+
*/
|
|
209
|
+
body?: RegisterFunctionFormat[];
|
|
210
|
+
/**
|
|
211
|
+
* The items of the parameter
|
|
212
|
+
*/
|
|
213
|
+
items?: RegisterFunctionFormat;
|
|
214
|
+
/**
|
|
215
|
+
* Whether the parameter is required
|
|
216
|
+
*/
|
|
217
|
+
required?: boolean;
|
|
218
|
+
};
|
|
219
|
+
type RegisterFunctionMessage = {
|
|
220
|
+
type: MessageType.RegisterFunction;
|
|
221
|
+
/**
|
|
222
|
+
* The path of the function
|
|
223
|
+
*/
|
|
224
|
+
id: string;
|
|
225
|
+
/**
|
|
226
|
+
* The description of the function
|
|
227
|
+
*/
|
|
228
|
+
description?: string;
|
|
229
|
+
/**
|
|
230
|
+
* The request format of the function
|
|
231
|
+
*/
|
|
232
|
+
request_format?: RegisterFunctionFormat;
|
|
233
|
+
/**
|
|
234
|
+
* The response format of the function
|
|
235
|
+
*/
|
|
236
|
+
response_format?: RegisterFunctionFormat;
|
|
237
|
+
metadata?: Record<string, unknown>;
|
|
238
|
+
};
|
|
239
|
+
type FunctionInfo = {
|
|
240
|
+
function_id: string;
|
|
241
|
+
description?: string;
|
|
242
|
+
request_format?: RegisterFunctionFormat;
|
|
243
|
+
response_format?: RegisterFunctionFormat;
|
|
244
|
+
metadata?: Record<string, unknown>;
|
|
245
|
+
};
|
|
246
|
+
type WorkerStatus = 'connected' | 'available' | 'busy' | 'disconnected';
|
|
247
|
+
type WorkerInfo = {
|
|
248
|
+
id: string;
|
|
249
|
+
name?: string;
|
|
250
|
+
runtime?: string;
|
|
251
|
+
version?: string;
|
|
252
|
+
os?: string;
|
|
253
|
+
ip_address?: string;
|
|
254
|
+
status: WorkerStatus;
|
|
255
|
+
connected_at_ms: number;
|
|
256
|
+
function_count: number;
|
|
257
|
+
functions: string[];
|
|
258
|
+
active_invocations: number;
|
|
259
|
+
};
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/triggers.d.ts
|
|
262
|
+
type TriggerConfig<TConfig> = {
|
|
263
|
+
id: string;
|
|
264
|
+
function_id: string;
|
|
265
|
+
config: TConfig;
|
|
266
|
+
};
|
|
267
|
+
type TriggerHandler<TConfig> = {
|
|
268
|
+
registerTrigger(config: TriggerConfig<TConfig>): Promise<void>;
|
|
269
|
+
unregisterTrigger(config: TriggerConfig<TConfig>): Promise<void>;
|
|
270
|
+
};
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/types.d.ts
|
|
273
|
+
type RemoteFunctionHandler<TInput = any, TOutput = any> = (data: TInput) => Promise<TOutput>;
|
|
274
|
+
/** OTEL Log Event from the engine */
|
|
275
|
+
type OtelLogEvent = {
|
|
276
|
+
/** Timestamp in Unix nanoseconds */
|
|
277
|
+
timestamp_unix_nano: number;
|
|
278
|
+
/** Observed timestamp in Unix nanoseconds */
|
|
279
|
+
observed_timestamp_unix_nano: number;
|
|
280
|
+
/** OTEL severity number (1-24): TRACE=1-4, DEBUG=5-8, INFO=9-12, WARN=13-16, ERROR=17-20, FATAL=21-24 */
|
|
281
|
+
severity_number: number;
|
|
282
|
+
/** Severity text (e.g., "INFO", "WARN", "ERROR") */
|
|
283
|
+
severity_text: string;
|
|
284
|
+
/** Log message body */
|
|
285
|
+
body: string;
|
|
286
|
+
/** Structured attributes */
|
|
287
|
+
attributes: Record<string, unknown>;
|
|
288
|
+
/** Trace ID for correlation (if available) */
|
|
289
|
+
trace_id?: string;
|
|
290
|
+
/** Span ID for correlation (if available) */
|
|
291
|
+
span_id?: string;
|
|
292
|
+
/** Resource attributes from the emitting service */
|
|
293
|
+
resource: Record<string, string>;
|
|
294
|
+
/** Service name that emitted the log */
|
|
295
|
+
service_name: string;
|
|
296
|
+
/** Instrumentation scope name (if available) */
|
|
297
|
+
instrumentation_scope_name?: string;
|
|
298
|
+
/** Instrumentation scope version (if available) */
|
|
299
|
+
instrumentation_scope_version?: string;
|
|
300
|
+
};
|
|
301
|
+
/** Severity levels for log filtering */
|
|
302
|
+
type LogSeverityLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'all';
|
|
303
|
+
/** Optional configuration for onLog */
|
|
304
|
+
type LogConfig = {
|
|
305
|
+
/** Minimum severity level to receive (default: 'all') */
|
|
306
|
+
level?: LogSeverityLevel;
|
|
307
|
+
};
|
|
308
|
+
/** Callback type for log events */
|
|
309
|
+
type LogCallback = (log: OtelLogEvent) => void;
|
|
310
|
+
type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'type' | 'id'>;
|
|
311
|
+
type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'type'>;
|
|
312
|
+
type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'type'>;
|
|
313
|
+
type FunctionsAvailableCallback = (functions: FunctionInfo[]) => void;
|
|
314
|
+
interface ISdk {
|
|
315
|
+
/**
|
|
316
|
+
* Registers a new trigger. A trigger is a way to invoke a function when a certain event occurs.
|
|
317
|
+
* @param trigger - The trigger to register
|
|
318
|
+
* @returns A trigger object that can be used to unregister the trigger
|
|
319
|
+
*/
|
|
320
|
+
registerTrigger(trigger: RegisterTriggerInput): Trigger;
|
|
321
|
+
/**
|
|
322
|
+
* Registers a new function. A function is a unit of work that can be invoked by other services.
|
|
323
|
+
* @param func - The function to register
|
|
324
|
+
* @param handler - The handler for the function
|
|
325
|
+
* @returns A function object that can be used to invoke the function
|
|
326
|
+
*/
|
|
327
|
+
registerFunction(func: RegisterFunctionInput, handler: RemoteFunctionHandler): FunctionRef;
|
|
328
|
+
/**
|
|
329
|
+
* Invokes a function.
|
|
330
|
+
* @param function_id - The path to the function
|
|
331
|
+
* @param data - The data to pass to the function
|
|
332
|
+
* @returns The result of the function
|
|
333
|
+
*/
|
|
334
|
+
call<TInput, TOutput>(function_id: string, data: TInput): Promise<TOutput>;
|
|
335
|
+
/**
|
|
336
|
+
* Invokes a function asynchronously.
|
|
337
|
+
* @param function_id - The path to the function
|
|
338
|
+
* @param data - The data to pass to the function
|
|
339
|
+
*/
|
|
340
|
+
callVoid<TInput>(function_id: string, data: TInput): void;
|
|
341
|
+
/**
|
|
342
|
+
* Registers a new trigger type. A trigger type is a way to invoke a function when a certain event occurs.
|
|
343
|
+
* @param triggerType - The trigger type to register
|
|
344
|
+
* @param handler - The handler for the trigger type
|
|
345
|
+
* @returns A trigger type object that can be used to unregister the trigger type
|
|
346
|
+
*/
|
|
347
|
+
registerTriggerType<TConfig>(triggerType: RegisterTriggerTypeInput, handler: TriggerHandler<TConfig>): void;
|
|
348
|
+
/**
|
|
349
|
+
* Unregisters a trigger type.
|
|
350
|
+
* @param triggerType - The trigger type to unregister
|
|
351
|
+
*/
|
|
352
|
+
unregisterTriggerType(triggerType: RegisterTriggerTypeInput): void;
|
|
353
|
+
/**
|
|
354
|
+
* Registers a callback for a specific event.
|
|
355
|
+
* @param event - The event to register the callback for
|
|
356
|
+
* @param callback - The callback to register
|
|
357
|
+
*/
|
|
358
|
+
on(event: string, callback: (arg?: unknown) => void): void;
|
|
359
|
+
/**
|
|
360
|
+
* Creates a new stream implementation.
|
|
361
|
+
*
|
|
362
|
+
* This overrides the default stream implementation.
|
|
363
|
+
*
|
|
364
|
+
* @param streamName - The name of the stream
|
|
365
|
+
* @param stream - The stream implementation
|
|
366
|
+
*/
|
|
367
|
+
createStream<TData>(streamName: string, stream: IStream<TData>): void;
|
|
368
|
+
/**
|
|
369
|
+
* Registers a callback to receive the current functions list
|
|
370
|
+
* when the engine announces changes.
|
|
371
|
+
*/
|
|
372
|
+
onFunctionsAvailable(callback: FunctionsAvailableCallback): () => void;
|
|
373
|
+
/**
|
|
374
|
+
* Registers a callback to receive OTEL log events from the engine.
|
|
375
|
+
* @param callback - The callback to invoke when a log event is received
|
|
376
|
+
* @param config - Optional configuration for filtering logs by severity level
|
|
377
|
+
* @returns A function to unregister the callback
|
|
378
|
+
*/
|
|
379
|
+
onLog(callback: LogCallback, config?: LogConfig): () => void;
|
|
380
|
+
}
|
|
381
|
+
type Trigger = {
|
|
382
|
+
unregister(): void;
|
|
383
|
+
};
|
|
384
|
+
type FunctionRef = {
|
|
385
|
+
id: string;
|
|
386
|
+
unregister: () => void;
|
|
387
|
+
};
|
|
388
|
+
type ApiRequest<TBody = unknown> = {
|
|
389
|
+
path_params: Record<string, string>;
|
|
390
|
+
query_params: Record<string, string | string[]>;
|
|
391
|
+
body: TBody;
|
|
392
|
+
headers: Record<string, string | string[]>;
|
|
393
|
+
method: string;
|
|
394
|
+
};
|
|
395
|
+
type ApiResponse<TStatus extends number = number, TBody = string | Buffer | Record<string, unknown>> = {
|
|
396
|
+
status_code: TStatus;
|
|
397
|
+
headers?: Record<string, string>;
|
|
398
|
+
body: TBody;
|
|
399
|
+
};
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/iii.d.ts
|
|
402
|
+
/** Callback type for connection state changes */
|
|
403
|
+
type ConnectionStateCallback = (state: IIIConnectionState) => void;
|
|
404
|
+
type InitOptions = {
|
|
405
|
+
workerName?: string;
|
|
406
|
+
enableMetricsReporting?: boolean;
|
|
407
|
+
/** Default timeout for function invocations in milliseconds */
|
|
408
|
+
invocationTimeoutMs?: number;
|
|
409
|
+
/** Configuration for WebSocket reconnection behavior */
|
|
410
|
+
reconnectionConfig?: Partial<IIIReconnectionConfig>;
|
|
411
|
+
/** OpenTelemetry configuration. If provided, OTEL will be initialized automatically.
|
|
412
|
+
* The engineWsUrl is set automatically from the III address. */
|
|
413
|
+
otel?: Omit<OtelConfig, 'engineWsUrl'>;
|
|
414
|
+
};
|
|
415
|
+
declare const init: (address: string, options?: InitOptions) => ISdk;
|
|
416
|
+
//#endregion
|
|
417
|
+
export { extractTraceparent as A, EngineFunctions as B, initOtel as C, currentTraceId as D, currentSpanId as E, removeBaggageEntry as F, IIIConnectionState as H, setBaggageEntry as I, OtelConfig as L, getBaggageEntry as M, injectBaggage as N, extractBaggage as O, injectTraceparent as P, DEFAULT_BRIDGE_RECONNECTION_CONFIG as R, getTracer as S, withSpan as T, IIIReconnectionConfig as U, EngineTriggers as V, LogFunctions as W, SeverityNumber$1 as _, ApiResponse as a, getLogger as b, LogCallback as c, OtelLogEvent as d, FunctionInfo as f, Meter$1 as g, Logger as h, ApiRequest as i, getAllBaggage as j, extractContext as k, LogConfig as l, WorkerStatus as m, InitOptions as n, FunctionsAvailableCallback as o, WorkerInfo as p, init as r, ISdk as s, ConnectionStateCallback as t, LogSeverityLevel as u, Span$1 as v, shutdownOtel as w, getMeter as x, SpanStatusCode as y, DEFAULT_INVOCATION_TIMEOUT_MS as z };
|
|
418
|
+
//# sourceMappingURL=iii-dNb0FMyR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iii-dNb0FMyR.d.mts","names":[],"sources":["../src/iii-constants.ts","../src/telemetry-system/types.ts","../src/telemetry-system/context.ts","../src/telemetry-system/index.ts","../src/iii-types.ts","../src/triggers.ts","../src/types.ts","../src/iii.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAKa;;EAAA,SAAA,YAIH,EAAA,qBAAA;EAGG,SAAA,eAGH,EAAA,yBAAA;AAGV,CAAA;AAQA;AAQiB,cAtBJ,cAsByB,EAAA;EAczB,SAAA,mBAAA,EAAA,6BAAoC;EASpC,SAAA,GAAA,EAAA,KAAA;;;cAvCA;ECOI,SAAA,IAAA,EAAA,UAAkB;EAuBlB,SAAA,IAAU,EAAA,UAAA;EAcN,SAAA,KAAA,EAAA,WAAA;EAMU,SAAA,KAAA,EAAA,WAAA;CAAR;;KD1CX,kBAAA;;UAQK,qBAAA;EEzBD;EAcA,cAAA,EAAa,MAAA;EAcb;EASA,UAAA,EAAA,MAAA;EAQA;EASA,iBAAc,EAAA,MAAA;EAQd;EAcA,YAAA,EAAA,MAAe;EAQf;EASA,UAAA,EAAA,MAAA;AAYhB;;cFlEa,oCAAoC;;AGcjC,cHLH,6BAAA,GGKmC,KAAA;;;;UFrC/B,kBAAA;;EAAA,cAAA,EAAA,MAAkB;EAuBlB;EAcI,UAAA,EAAA,MAAA;EAMU;EAAR,iBAAA,EAAA,MAAA;EAAO;;;;AC3D9B;AAqCA;AAQgB,UDNC,UAAA,CCMY;EASb;EAQA,OAAA,CAAA,EAAA,OAAc;EAcd;EAQA,WAAA,CAAA,EAAA,MAAe;EASf;EAYA,cAAA,CAAA,EAAa,MAAA;;;;ECpDb,iBAAQ,CAAA,EAAA,MAAS;EA4FX;EA6BN,WAAA,CAAS,EAAA,MAAA;EAOT;EAOA,gBAAS,CAAA,EFvIJ,eEuIc,EAAA;EAOb;EAEF,cAAA,CAA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