Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit d7070fd

Browse files
author
Akim
authored
fix(js-client): Handle null as user input value (#431)
Handle null as user input value
1 parent 0417ba4 commit d7070fd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/core/js-client/src/compilerSupport/__test__/conversion.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ describe("Conversion from aqua to typescript", () => {
179179
test.each`
180180
aqua | ts | type
181181
${1} | ${1} | ${i32}
182+
${null} | ${null} | ${opt_i32}
182183
${[]} | ${null} | ${opt_i32}
183184
${[1]} | ${1} | ${opt_i32}
184185
${[1, 2, 3]} | ${[1, 2, 3]} | ${array_i32}
@@ -205,7 +206,11 @@ describe("Conversion from aqua to typescript", () => {
205206

206207
// assert
207208
expect(tsFromAqua).toStrictEqual(ts);
208-
expect(aquaFromTs).toStrictEqual(aqua);
209+
210+
// 'null' -> 'null' -> [] ; 'null' not equal []
211+
if (aqua !== null || ts !== null) {
212+
expect(aquaFromTs).toStrictEqual(aqua);
213+
}
209214
},
210215
);
211216
});

packages/core/js-client/src/compilerSupport/conversions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export function aqua2js(
102102
if (schema.tag === "nil") {
103103
return null;
104104
} else if (schema.tag === "option") {
105-
if (!Array.isArray(value)) {
106-
throw new SchemaValidationError(path, schema, "array", value);
105+
if (!Array.isArray(value) && value !== null) {
106+
throw new SchemaValidationError(path, schema, "array or null", value);
107107
}
108108

109-
if ("0" in value) {
109+
if (value !== null && "0" in value) {
110110
return aqua2js(value[0], schema.type, { path: [...path, "?"] });
111111
} else {
112112
return null;

0 commit comments

Comments
 (0)