talizen 0.2.10 → 0.2.11
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/func.d.ts +3 -1
- package/func.js +12 -1
- package/package.json +1 -1
package/func.d.ts
CHANGED
|
@@ -15,9 +15,11 @@ export declare class TalizenFuncError extends Error {
|
|
|
15
15
|
readonly logs: FuncLogEntry[];
|
|
16
16
|
constructor(key: string, method: string, message: string, logs?: FuncLogEntry[]);
|
|
17
17
|
}
|
|
18
|
-
export declare function invoke<T = unknown>(name: string, input?: unknown, options?:
|
|
18
|
+
export declare function invoke<T = unknown>(name: string, input?: unknown, options?: RunFuncOptions): Promise<T>;
|
|
19
19
|
export interface RunFuncOptions extends TalizenRequestOptions {
|
|
20
20
|
method?: string;
|
|
21
|
+
timeoutMS?: number;
|
|
22
|
+
timeoutMs?: number;
|
|
21
23
|
}
|
|
22
24
|
export declare function runFunc<T = unknown>(key: string, input?: unknown, options?: RunFuncOptions): Promise<T>;
|
|
23
25
|
export declare function parseInvokeName(name: string): {
|
package/func.js
CHANGED
|
@@ -21,7 +21,9 @@ export async function invoke(name, input, options) {
|
|
|
21
21
|
export async function runFunc(key, input, options) {
|
|
22
22
|
const normalizedKey = normalizeFuncKey(key);
|
|
23
23
|
const method = normalizeFuncMethod(options?.method);
|
|
24
|
-
const
|
|
24
|
+
const timeoutMS = normalizeTimeoutMS(options?.timeoutMS ?? options?.timeoutMs);
|
|
25
|
+
const path = `/func/${encodeFuncKey(normalizedKey)}${method === "main" ? "" : `.${encodeURIComponent(method)}`}${timeoutMS ? `?timeout_ms=${timeoutMS}` : ""}`;
|
|
26
|
+
const response = await requestJson(path, {
|
|
25
27
|
method: "POST",
|
|
26
28
|
body: JSON.stringify(input ?? {}),
|
|
27
29
|
}, options);
|
|
@@ -67,3 +69,12 @@ function normalizeFuncMethod(method) {
|
|
|
67
69
|
function encodeFuncKey(key) {
|
|
68
70
|
return key.split("/").map(encodeURIComponent).join("/");
|
|
69
71
|
}
|
|
72
|
+
function normalizeTimeoutMS(timeoutMS) {
|
|
73
|
+
if (timeoutMS == null) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isFinite(timeoutMS) || timeoutMS <= 0) {
|
|
77
|
+
throw new Error(`Invalid Talizen func timeoutMS: ${timeoutMS}`);
|
|
78
|
+
}
|
|
79
|
+
return Math.floor(timeoutMS);
|
|
80
|
+
}
|