@triggerlink/sdk 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/function.d.ts +6 -0
- package/dist/serve.js +8 -1
- package/dist/step.d.ts +2 -0
- package/dist/step.js +2 -2
- package/package.json +1 -1
package/dist/function.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export interface FunctionOpts {
|
|
|
43
43
|
retries?: number;
|
|
44
44
|
/** 取消规则,随 manifest 上报为 cancel_on */
|
|
45
45
|
cancelOn?: CancelOnRule[];
|
|
46
|
+
/**
|
|
47
|
+
* run 级超时(FR-4.3),随 manifest 上报为 timeout(Go duration 字符串或毫秒数,
|
|
48
|
+
* 如 "5m" 或 300000)。run 从创建起超过该时长仍在 Queued/Running,平台置 Failed
|
|
49
|
+
* 并发 triggerlink/run.failed 事件——配置了 onFailure 的函数会因此触发。缺省 = 不限时。
|
|
50
|
+
*/
|
|
51
|
+
timeout?: string | number;
|
|
46
52
|
/**
|
|
47
53
|
* run 进入 Failed 终态时的处理器(FR-2.11)。serve 时注册隐式函数 <id>/on-failure,
|
|
48
54
|
* 订阅内部事件 triggerlink/run.failed(match 按 function_id 过滤),handler 内可用全部 step 原语。
|
package/dist/serve.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExecCtx, StepInterrupt } from "./execx.js";
|
|
2
|
-
import { createStepTool, errMessage } from "./step.js";
|
|
2
|
+
import { createStepTool, errMessage, msToGoDuration } from "./step.js";
|
|
3
3
|
import { verifySignature } from "./sign.js";
|
|
4
4
|
export const sdkVersion = "triggerlink-ts/0.4.6";
|
|
5
5
|
export const SIGNATURE_HEADER = "x-triggerlink-signature";
|
|
@@ -40,6 +40,13 @@ export function serve(opts) {
|
|
|
40
40
|
...(f.opts.cancelOn?.length
|
|
41
41
|
? { cancel_on: f.opts.cancelOn.map((c) => ({ event: c.event, match: c.match })) }
|
|
42
42
|
: {}),
|
|
43
|
+
...(f.opts.timeout
|
|
44
|
+
? {
|
|
45
|
+
timeout: typeof f.opts.timeout === "number"
|
|
46
|
+
? msToGoDuration(f.opts.timeout, "createFunction")
|
|
47
|
+
: f.opts.timeout,
|
|
48
|
+
}
|
|
49
|
+
: {}),
|
|
43
50
|
})),
|
|
44
51
|
});
|
|
45
52
|
}
|
package/dist/step.d.ts
CHANGED
|
@@ -39,4 +39,6 @@ export interface StepTool {
|
|
|
39
39
|
}
|
|
40
40
|
/** 为一次函数调用构造 step 工具。 */
|
|
41
41
|
export declare function createStepTool(ec: ExecCtx): StepTool;
|
|
42
|
+
/** 毫秒 → Go duration 字符串(协议要求 timeout 为 Go duration,如 1500 → "1.5s")。 */
|
|
43
|
+
export declare function msToGoDuration(ms: number, what?: string): string;
|
|
42
44
|
export declare function errMessage(err: unknown): string;
|
package/dist/step.js
CHANGED
|
@@ -67,9 +67,9 @@ export function createStepTool(ec) {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
/** 毫秒 → Go duration 字符串(协议要求 timeout 为 Go duration,如 1500 → "1.5s")。 */
|
|
70
|
-
function msToGoDuration(ms) {
|
|
70
|
+
export function msToGoDuration(ms, what = "step.waitForEvent") {
|
|
71
71
|
if (!Number.isFinite(ms) || ms <= 0) {
|
|
72
|
-
throw new Error(
|
|
72
|
+
throw new Error(`${what}: invalid timeout ${ms}`);
|
|
73
73
|
}
|
|
74
74
|
return `${ms / 1000}s`;
|
|
75
75
|
}
|