Skip to content

Commit

Permalink
Merge pull request #1352 from NASA-AMMOS/pass_through_null_expansion
Browse files Browse the repository at this point in the history
Handle 'null' values when deserializing for command expansion
  • Loading branch information
mattdailis authored Mar 1, 2024
2 parents 2fc7204 + f388aba commit c137793
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,42 @@ export function mapGraphQLActivityInstance(
function convertType(value: any, schema: Schema): any {
switch (schema.type) {
case SchemaTypes.Int:
if (value === null) {
return value;
}
if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) {
return value.toString();
}
return parseInt(value, 10);
case SchemaTypes.Real:
return value;
case SchemaTypes.Duration:
return Temporal.Duration.from(parse(value).toISOString());
if (value !== null) {
return Temporal.Duration.from(parse(value).toISOString());
}
return value;
case SchemaTypes.Boolean:
return value;
case SchemaTypes.Path:
return value;
case SchemaTypes.String:
return value;
case SchemaTypes.Series:
if (value === null) {
return value;
}
return value.map((value: any) => convertType(value, schema.items));
case SchemaTypes.Struct:
if (value === null) {
return value;
}
const struct: { [attributeName: string]: any } = {};
for (const [attributeKey, attributeSchema] of Object.entries(schema.items)) {
struct[attributeKey] = convertType(value[attributeKey], attributeSchema);
}
return struct;
case SchemaTypes.Variant:
if (schema.variants.length === 1 && schema.variants[0]?.key === 'VOID') {
if (value === null || (schema.variants.length === 1 && schema.variants[0]?.key === 'VOID')) {
return null;
}
return value;
Expand Down

0 comments on commit c137793

Please sign in to comment.