Skip to content

Commit b3c25b9

Browse files
authored
refactor: rename call methods to trigger for consistency across SDKs (#26)
- Updated method names from `call` to `trigger` and `callVoid` to `triggerVoid` in TypeScript, Python, and Rust implementations to standardize terminology. - Adjusted related type definitions and method implementations to reflect the new naming convention. - Ensured that the original `call` and `callVoid` methods now delegate to the new `trigger` and `triggerVoid` methods, maintaining backward compatibility.
1 parent 5bdf87d commit b3c25b9

File tree

6 files changed

+74
-26
lines changed

6 files changed

+74
-26
lines changed

packages/node/iii/src/iii.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,12 @@ class Sdk implements ISdk {
224224
this.services.set(message.id, { ...message, message_type: MessageType.RegisterService })
225225
}
226226

227-
call = async <TInput, TOutput>(
227+
trigger = async <TInput, TOutput>(
228228
function_id: string,
229229
data: TInput,
230230
timeoutMs?: number,
231231
): Promise<TOutput> => {
232232
const invocation_id = crypto.randomUUID()
233-
// Inject trace context and baggage if available
234233
const traceparent = injectTraceparent()
235234
const baggage = injectBaggage()
236235
const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs
@@ -266,31 +265,39 @@ class Sdk implements ISdk {
266265
})
267266
}
268267

269-
callVoid = <TInput>(function_id: string, data: TInput): void => {
270-
// Inject trace context and baggage if available
268+
triggerVoid = <TInput>(function_id: string, data: TInput): void => {
271269
const traceparent = injectTraceparent()
272270
const baggage = injectBaggage()
273271
this.sendMessage(MessageType.InvokeFunction, { function_id, data, traceparent, baggage })
274272
}
275273

274+
call = async <TInput, TOutput>(
275+
function_id: string,
276+
data: TInput,
277+
timeoutMs?: number,
278+
): Promise<TOutput> => this.trigger<TInput, TOutput>(function_id, data, timeoutMs)
279+
280+
callVoid = <TInput>(function_id: string, data: TInput): void =>
281+
this.triggerVoid(function_id, data)
282+
276283
listFunctions = async (): Promise<FunctionInfo[]> => {
277-
const result = await this.call<Record<string, never>, { functions: FunctionInfo[] }>(
284+
const result = await this.trigger<Record<string, never>, { functions: FunctionInfo[] }>(
278285
EngineFunctions.LIST_FUNCTIONS,
279286
{},
280287
)
281288
return result.functions
282289
}
283290

284291
listWorkers = async (): Promise<WorkerInfo[]> => {
285-
const result = await this.call<Record<string, never>, { workers: WorkerInfo[] }>(
292+
const result = await this.trigger<Record<string, never>, { workers: WorkerInfo[] }>(
286293
EngineFunctions.LIST_WORKERS,
287294
{},
288295
)
289296
return result.workers
290297
}
291298

292299
private registerWorkerMetadata(): void {
293-
this.callVoid(EngineFunctions.REGISTER_WORKER, {
300+
this.triggerVoid(EngineFunctions.REGISTER_WORKER, {
294301
runtime: 'node',
295302
version: SDK_VERSION,
296303
name: this.workerName,

packages/node/iii/src/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface ISdk {
110110
* @param timeoutMs - Optional timeout in milliseconds
111111
* @returns The result of the function
112112
*/
113-
call<TInput, TOutput>(function_id: string, data: TInput, timeoutMs?: number): Promise<TOutput>
113+
trigger<TInput, TOutput>(function_id: string, data: TInput, timeoutMs?: number): Promise<TOutput>
114114

115115
/**
116116
* Lists all registered functions.
@@ -122,6 +122,15 @@ export interface ISdk {
122122
* @param function_id - The path to the function
123123
* @param data - The data to pass to the function
124124
*/
125+
triggerVoid<TInput>(function_id: string, data: TInput): void
126+
127+
/**
128+
* Lists all registered functions.
129+
*/
130+
listFunctions(): Promise<FunctionInfo[]>
131+
132+
call<TInput, TOutput>(function_id: string, data: TInput, timeoutMs?: number): Promise<TOutput>
133+
125134
callVoid<TInput>(function_id: string, data: TInput): void
126135

127136
/**

packages/python/iii/src/iii/iii.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ def register_service(self, id: str, description: str | None = None, parent_id: s
532532
self._services[id] = msg
533533
self._send_if_connected(msg)
534534

535-
async def call(self, path: str, data: Any, timeout: float = 30.0) -> Any:
536-
"""Invoke a remote function and wait for the result."""
535+
async def trigger(self, path: str, data: Any, timeout: float = 30.0) -> Any:
537536
invocation_id = str(uuid.uuid4())
538537
future: asyncio.Future[Any] = asyncio.get_running_loop().create_future()
539538

@@ -555,8 +554,7 @@ async def call(self, path: str, data: Any, timeout: float = 30.0) -> Any:
555554
self._pending.pop(invocation_id, None)
556555
raise TimeoutError(f"Invocation of '{path}' timed out after {timeout}s")
557556

558-
def call_void(self, path: str, data: Any) -> None:
559-
"""Fire-and-forget invocation (no response expected)."""
557+
def trigger_void(self, path: str, data: Any) -> None:
560558
msg = InvokeFunctionMessage(
561559
function_id=path,
562560
data=data,
@@ -568,15 +566,21 @@ def call_void(self, path: str, data: Any) -> None:
568566
except RuntimeError:
569567
self._enqueue(msg)
570568

569+
async def call(self, path: str, data: Any, timeout: float = 30.0) -> Any:
570+
return await self.trigger(path, data, timeout)
571+
572+
def call_void(self, path: str, data: Any) -> None:
573+
self.trigger_void(path, data)
574+
571575
async def list_functions(self) -> list[FunctionInfo]:
572576
"""List all registered functions from the engine."""
573-
result = await self.call("engine::functions::list", {})
577+
result = await self.trigger("engine::functions::list", {})
574578
functions_data = result.get("functions", [])
575579
return [FunctionInfo(**f) for f in functions_data]
576580

577581
async def list_workers(self) -> list[WorkerInfo]:
578582
"""List all connected workers from the engine."""
579-
result = await self.call("engine::workers::list", {})
583+
result = await self.trigger("engine::workers::list", {})
580584
workers_data = result.get("workers", [])
581585
return [WorkerInfo(**w) for w in workers_data]
582586

@@ -598,7 +602,7 @@ def _get_worker_metadata(self) -> dict[str, Any]:
598602

599603
def _register_worker_metadata(self) -> None:
600604
"""Register this worker's metadata with the engine."""
601-
self.call_void("engine::workers::register", self._get_worker_metadata())
605+
self.trigger_void("engine::workers::register", self._get_worker_metadata())
602606

603607
def on_functions_available(self, callback: Callable[[list[FunctionInfo]], None]) -> Callable[[], None]:
604608
"""Subscribe to function availability events.

packages/python/iii/src/iii/types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def register_function(
8686
description: str | None = None,
8787
) -> Any: ...
8888

89-
async def call(self, function_id: str, data: Any) -> Any: ...
89+
async def trigger(self, function_id: str, data: Any, timeout: float = 30.0) -> Any: ...
90+
91+
def trigger_void(self, function_id: str, data: Any) -> None: ...
92+
93+
async def call(self, function_id: str, data: Any, timeout: float = 30.0) -> Any: ...
9094

9195
def call_void(self, function_id: str, data: Any) -> None: ...
9296

packages/rust/iii/src/iii.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,17 @@ impl III {
483483
Ok(Trigger::new(unregister_fn))
484484
}
485485

486-
pub async fn call(
486+
pub async fn trigger(
487487
&self,
488488
function_id: &str,
489489
data: impl serde::Serialize,
490490
) -> Result<Value, IIIError> {
491491
let value = serde_json::to_value(data)?;
492-
self.call_with_timeout(function_id, value, DEFAULT_TIMEOUT)
492+
self.trigger_with_timeout(function_id, value, DEFAULT_TIMEOUT)
493493
.await
494494
}
495495

496-
pub async fn call_with_timeout(
496+
pub async fn trigger_with_timeout(
497497
&self,
498498
function_id: &str,
499499
data: Value,
@@ -527,7 +527,7 @@ impl III {
527527
}
528528
}
529529

530-
pub fn call_void<TInput>(&self, function_id: &str, data: TInput) -> Result<(), IIIError>
530+
pub fn trigger_void<TInput>(&self, function_id: &str, data: TInput) -> Result<(), IIIError>
531531
where
532532
TInput: Serialize,
533533
{
@@ -544,10 +544,34 @@ impl III {
544544
})
545545
}
546546

547+
pub async fn call(
548+
&self,
549+
function_id: &str,
550+
data: impl serde::Serialize,
551+
) -> Result<Value, IIIError> {
552+
self.trigger(function_id, data).await
553+
}
554+
555+
pub fn call_void<TInput>(&self, function_id: &str, data: TInput) -> Result<(), IIIError>
556+
where
557+
TInput: Serialize,
558+
{
559+
self.trigger_void(function_id, data)
560+
}
561+
562+
pub async fn call_with_timeout(
563+
&self,
564+
function_id: &str,
565+
data: Value,
566+
timeout: Duration,
567+
) -> Result<Value, IIIError> {
568+
self.trigger_with_timeout(function_id, data, timeout).await
569+
}
570+
547571
/// List all registered functions from the engine
548572
pub async fn list_functions(&self) -> Result<Vec<FunctionInfo>, IIIError> {
549573
let result = self
550-
.call("engine::functions::list", serde_json::json!({}))
574+
.trigger("engine::functions::list", serde_json::json!({}))
551575
.await?;
552576

553577
let functions = result
@@ -642,7 +666,7 @@ impl III {
642666
/// List all connected workers from the engine
643667
pub async fn list_workers(&self) -> Result<Vec<WorkerInfo>, IIIError> {
644668
let result = self
645-
.call("engine::workers::list", serde_json::json!({}))
669+
.trigger("engine::workers::list", serde_json::json!({}))
646670
.await?;
647671

648672
let workers = result
@@ -656,7 +680,7 @@ impl III {
656680
/// List all registered triggers from the engine
657681
pub async fn list_triggers(&self) -> Result<Vec<TriggerInfo>, IIIError> {
658682
let result = self
659-
.call("engine::triggers::list", serde_json::json!({}))
683+
.trigger("engine::triggers::list", serde_json::json!({}))
660684
.await?;
661685

662686
let triggers = result
@@ -670,7 +694,7 @@ impl III {
670694
/// Register this worker's metadata with the engine (called automatically on connect)
671695
fn register_worker_metadata(&self) {
672696
if let Some(metadata) = self.inner.worker_metadata.lock_or_recover().clone() {
673-
let _ = self.call_void("engine::workers::register", metadata);
697+
let _ = self.trigger_void("engine::workers::register", metadata);
674698
}
675699
}
676700

@@ -1112,7 +1136,7 @@ mod tests {
11121136
async fn invoke_function_times_out_and_clears_pending() {
11131137
let iii = III::new("ws://localhost:1234");
11141138
let result = iii
1115-
.call_with_timeout(
1139+
.trigger_with_timeout(
11161140
"functions.echo",
11171141
json!({ "a": 1 }),
11181142
Duration::from_millis(10),

packages/rust/iii/src/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Streams {
9191
ops,
9292
};
9393

94-
let result = self.iii.call("stream::update", input).await?;
94+
let result = self.iii.trigger("stream::update", input).await?;
9595

9696
serde_json::from_value(result).map_err(|e| IIIError::Serde(e.to_string()))
9797
}

0 commit comments

Comments
 (0)