fix(producer): omit absent render request options

This commit is contained in:
James
2026-07-17 16:22:23 -04:00
parent c251db02d0
commit 25dd4cc8c0
2 changed files with 20 additions and 1 deletions
@@ -146,6 +146,21 @@ describe("RenderRequest", () => {
}
});
it("omits absent optional options while preserving JSON validation for payloads", () => {
const value = createRenderRequest({
projectDir: "/project",
outputPath: "/output/video.mp4",
options: {
fps: { num: 30, den: 1 },
quality: "standard",
format: "mp4",
gifLoop: undefined,
},
});
expect(value.options).not.toHaveProperty("gifLoop");
});
it("rejects malformed optional and distributed fields", () => {
const value = request();
expect(() =>
+5 -1
View File
@@ -204,6 +204,10 @@ function assertNonEmptyPath(value: unknown, field: "projectDir" | "outputPath"):
}
}
function omitUndefinedProperties<T extends object>(value: T): T {
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined)) as T;
}
function assertRenderRequest(value: unknown): asserts value is RenderRequest {
if (!isPlainObject(value) || value.version !== RENDER_REQUEST_VERSION) {
const version = isPlainObject(value) ? value.version : undefined;
@@ -232,7 +236,7 @@ export function createRenderRequest(input: CreateRenderRequestInput): RenderRequ
projectDir: input.projectDir,
outputPath: input.outputPath,
options: {
...input.options,
...omitUndefinedProperties(input.options),
engineConfig: input.engineConfig ?? resolveConfig(input.engineOverrides),
},
} satisfies RenderRequest;