mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
fix(js-client): Handle null as user input value (#431)
Handle null as user input value
This commit is contained in:
parent
0417ba410a
commit
d7070fd71e
@ -179,6 +179,7 @@ describe("Conversion from aqua to typescript", () => {
|
|||||||
test.each`
|
test.each`
|
||||||
aqua | ts | type
|
aqua | ts | type
|
||||||
${1} | ${1} | ${i32}
|
${1} | ${1} | ${i32}
|
||||||
|
${null} | ${null} | ${opt_i32}
|
||||||
${[]} | ${null} | ${opt_i32}
|
${[]} | ${null} | ${opt_i32}
|
||||||
${[1]} | ${1} | ${opt_i32}
|
${[1]} | ${1} | ${opt_i32}
|
||||||
${[1, 2, 3]} | ${[1, 2, 3]} | ${array_i32}
|
${[1, 2, 3]} | ${[1, 2, 3]} | ${array_i32}
|
||||||
@ -205,7 +206,11 @@ describe("Conversion from aqua to typescript", () => {
|
|||||||
|
|
||||||
// assert
|
// assert
|
||||||
expect(tsFromAqua).toStrictEqual(ts);
|
expect(tsFromAqua).toStrictEqual(ts);
|
||||||
expect(aquaFromTs).toStrictEqual(aqua);
|
|
||||||
|
// 'null' -> 'null' -> [] ; 'null' not equal []
|
||||||
|
if (aqua !== null || ts !== null) {
|
||||||
|
expect(aquaFromTs).toStrictEqual(aqua);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -102,11 +102,11 @@ export function aqua2js(
|
|||||||
if (schema.tag === "nil") {
|
if (schema.tag === "nil") {
|
||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
} else if (schema.tag === "option") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value) && value !== null) {
|
||||||
throw new SchemaValidationError(path, schema, "array", value);
|
throw new SchemaValidationError(path, schema, "array or null", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("0" in value) {
|
if (value !== null && "0" in value) {
|
||||||
return aqua2js(value[0], schema.type, { path: [...path, "?"] });
|
return aqua2js(value[0], schema.type, { path: [...path, "?"] });
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user