feat: optimize datalink metadata display, fix field mapping schema, bill timeout and cli options
This commit is contained in:
1 parent
fbdb38bfb2
commit
a5f685045e
13 files changed
+254
-40
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { FieldMappingSchema, EkuaibaoDatalinkCreateTaskSchema } from "./types.js";
|
||||
|
||||
describe("FieldMappingSchema 字段映射验证与序列化", () => {
|
||||
it("正确解析仅含 key 的映射项", () => {
|
||||
const raw = { key: "E_field_1" };
|
||||
const parsed = FieldMappingSchema.parse(raw);
|
||||
expect(parsed.key).toBe("E_field_1");
|
||||
expect(parsed.value).toBeUndefined();
|
||||
});
|
||||
|
||||
it("正确保留 value 表达式,不被剥离丢失 (防止 Piper 报错金额/必填字段为空)", () => {
|
||||
const raw = {
|
||||
key: "E_e716b9f4b67179b1fbc0_费用金额",
|
||||
value: "control_stssrn.item.amortizationAmount",
|
||||
};
|
||||
const parsed = FieldMappingSchema.parse(raw);
|
||||
expect(parsed.key).toBe("E_e716b9f4b67179b1fbc0_费用金额");
|
||||
expect(parsed.value).toBe("control_stssrn.item.amortizationAmount");
|
||||
});
|
||||
|
||||
it("正确保留复杂对象/数组或数字类型的 value 与扩展属性", () => {
|
||||
const raw = {
|
||||
key: "E_nested_field",
|
||||
value: { subKey: "action_1.output", defaultVal: 100 },
|
||||
type: "relateEntity",
|
||||
required: true,
|
||||
};
|
||||
const parsed = FieldMappingSchema.parse(raw);
|
||||
expect(parsed.key).toBe("E_nested_field");
|
||||
expect(parsed.value).toEqual({ subKey: "action_1.output", defaultVal: 100 });
|
||||
expect((parsed as any).type).toBe("relateEntity");
|
||||
expect((parsed as any).required).toBe(true);
|
||||
});
|
||||
|
||||
it("在 EkuaibaoDatalinkCreateTaskSchema 节点中完整保留所有字段映射的 key 与 value", () => {
|
||||
const node = {
|
||||
name: "action_create_test",
|
||||
label: "创建摊销台账",
|
||||
type: "ekuaibao-datalink-create",
|
||||
groupName: "DEFAULT",
|
||||
orderIndex: 1,
|
||||
levelIndex: [1],
|
||||
status: "NORMAL",
|
||||
mode: "NORMAL",
|
||||
entityId: "e716b9f4b67179b1fbc0",
|
||||
combineFilters: { condition: "AND", filters: [] },
|
||||
filters: [],
|
||||
fields: [
|
||||
{ key: "E_e716b9f4b67179b1fbc0_name", value: "control_stssrn.item.title" },
|
||||
{ key: "E_e716b9f4b67179b1fbc0_费用金额", value: "control_stssrn.item.amortizationAmount" },
|
||||
{ key: "E_e716b9f4b67179b1fbc0_摊销月份", value: "control_stssrn.item.amortizationMonth" },
|
||||
],
|
||||
};
|
||||
|
||||
const parsed = EkuaibaoDatalinkCreateTaskSchema.parse(node);
|
||||
expect(parsed.fields).toHaveLength(3);
|
||||
expect(parsed.fields[0].value).toBe("control_stssrn.item.title");
|
||||
expect(parsed.fields[1].value).toBe("control_stssrn.item.amortizationAmount");
|
||||
expect(parsed.fields[2].value).toBe("control_stssrn.item.amortizationMonth");
|
||||
});
|
||||
});
|
||||
@@ -64,11 +64,11 @@ export const FilterGroupSchema: z.ZodType<any> = z.lazy(() =>
|
||||
})
|
||||
);
|
||||
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射
|
||||
export const FieldMappingSchema = z.union([
|
||||
z.object({ key: z.string() }),
|
||||
z.object({ key: z.string(), value: z.string() }),
|
||||
]);
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射(保留 value 及其余配置项)
|
||||
export const FieldMappingSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 错误处理配置
|
||||
export const OnErrorSchema = z.object({
|
||||
|
||||
@@ -164,6 +164,27 @@ describe("workflow-script - 本地静态语法校验与沙箱仿真引擎", () =
|
||||
expect(res.durationMs).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it("supports accessing variables through inputs namespace as well as top-level globals", async () => {
|
||||
const code = `
|
||||
return {
|
||||
direct: foo,
|
||||
viaNamespace: inputs.foo,
|
||||
nested: inputs.nested.value
|
||||
};
|
||||
`;
|
||||
const inputs = {
|
||||
foo: "bar",
|
||||
nested: { value: 42 }
|
||||
};
|
||||
const res = await executeJavaScriptSandbox(code, inputs);
|
||||
expect(res.success).toBe(true);
|
||||
expect(res.returnValue).toEqual({
|
||||
direct: "bar",
|
||||
viaNamespace: "bar",
|
||||
nested: 42
|
||||
});
|
||||
});
|
||||
|
||||
it("catches runtime errors and reports line number", async () => {
|
||||
const code = `
|
||||
const a = 10;
|
||||
|
||||
@@ -51,6 +51,11 @@ export async function executeJavaScriptSandbox(
|
||||
const value = vm.getProp(parsed.value, key);
|
||||
try { vm.setProp(vm.global, key, value); } finally { value.dispose(); }
|
||||
}
|
||||
// 同时挂载 inputs 命名空间,支持脚本直接通过 inputs.xxx 访问输入对象
|
||||
if (!Object.hasOwn(inputs, "inputs")) {
|
||||
const dup = parsed.value.dup();
|
||||
try { vm.setProp(vm.global, "inputs", dup); } finally { dup.dispose(); }
|
||||
}
|
||||
} finally { parsed.value.dispose(); }
|
||||
|
||||
const recordLog = (args: Parameters<typeof vm.dump>) => {
|
||||
|
||||
Reference in new issue
Block a user