UNPKG

genezio

Version:

Command line utility to interact with Genezio infrastructure.

84 lines (83 loc) 3.04 kB
import { AstNodeType, } from "../models/genezioModels.js"; function castNodeRecursively(node) { let implementation = ""; switch (node.type) { case AstNodeType.StringLiteral: implementation += `e as String`; break; case AstNodeType.DoubleLiteral: implementation += `e as double`; break; case AstNodeType.BooleanLiteral: implementation += `e as bool`; break; case AstNodeType.IntegerLiteral: implementation += `e as int`; break; case AstNodeType.CustomNodeLiteral: implementation += `${node.rawValue}.fromJson(e as Map<String, dynamic>),`; break; case AstNodeType.ArrayType: implementation += castArrayRecursively(node.generic); break; case AstNodeType.MapType: implementation += castMapRecursively(node.genericValue); } return implementation; } export function castMapRecursivelyInitial(mapType, name) { let implementation = ""; implementation += `(${name} as Map<${getParamType(mapType.genericKey)}, dynamic>).map((k, e) => MapEntry(k,`; implementation += castNodeRecursively(mapType.genericValue); implementation += `))`; return implementation; } export function castArrayRecursivelyInitial(arrayType, name) { let implementation = ""; implementation += `(${name} as List<dynamic>).map((e) => `; implementation += castNodeRecursively(arrayType.generic); implementation += `).toList()`; return implementation; } function castArrayRecursively(node) { let implementation = ""; implementation += "(e as List<dynamic>).map((e) =>"; implementation += castNodeRecursively(node); implementation += ").toList()"; return implementation; } function castMapRecursively(node) { let implementation = ""; implementation += "(e as Map<String, dynamic>).map((k, e) => MapEntry(k,"; implementation += castNodeRecursively(node); implementation += "))"; return implementation; } export function getParamType(elem) { switch (elem.type) { case AstNodeType.StringLiteral: return "String"; case AstNodeType.DoubleLiteral: return "double"; case AstNodeType.BooleanLiteral: return "bool"; case AstNodeType.IntegerLiteral: return "int"; case AstNodeType.AnyLiteral: return "Object"; case AstNodeType.VoidLiteral: return "void"; case AstNodeType.ArrayType: return `List<${getParamType(elem.generic)}>`; case AstNodeType.MapType: return `Map<${getParamType(elem.genericKey)}, ${getParamType(elem.genericValue)}>`; case AstNodeType.CustomNodeLiteral: return elem.rawValue; case AstNodeType.PromiseType: return getParamType(elem.generic); case AstNodeType.DateType: return "DateTime"; default: return "Object"; } }