planetResources.jsonl
Schema
_key(required): integer
Range: 40013180 .. 40328345power: integer
Range: 100 .. 1020-
reagent: objectamount_per_cycle(required): integer
Range: 31 .. 1110cycle_period(required): integer
Range: 3600 .. 3600secured_capacity(required): integer
Range: 45260 .. 1620600type_id(required): integer
Range: 81143 .. 81144unsecured_capacity(required): integer
Range: 45260 .. 1620600
-
workforce: integer
Range: 1000 .. 10200
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var planetResource = PlanetResource.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class PlanetResource
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("power", NullValueHandling = NullValueHandling.Ignore)]
public long? Power { get; set; }
[JsonProperty("reagent", NullValueHandling = NullValueHandling.Ignore)]
public Reagent Reagent { get; set; }
[JsonProperty("workforce", NullValueHandling = NullValueHandling.Ignore)]
public long? Workforce { get; set; }
}
public partial class Reagent
{
[JsonProperty("amount_per_cycle")]
public long AmountPerCycle { get; set; }
[JsonProperty("cycle_period")]
public long CyclePeriod { get; set; }
[JsonProperty("secured_capacity")]
public long SecuredCapacity { get; set; }
[JsonProperty("type_id")]
public long TypeId { get; set; }
[JsonProperty("unsecured_capacity")]
public long UnsecuredCapacity { get; set; }
}
public partial class PlanetResource
{
public static PlanetResource FromJson(string json) => JsonConvert.DeserializeObject<PlanetResource>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this PlanetResource self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
// planetResource, err := UnmarshalPlanetResource(bytes)
// bytes, err = planetResource.Marshal()
package model
import "encoding/json"
func UnmarshalPlanetResource(data []byte) (PlanetResource, error) {
var r PlanetResource
err := json.Unmarshal(data, &r)
return r, err
}
func (r *PlanetResource) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type PlanetResource struct {
Key int64 `json:"_key"`
Power *int64 `json:"power,omitempty"`
Reagent *Reagent `json:"reagent,omitempty"`
Workforce *int64 `json:"workforce,omitempty"`
}
type Reagent struct {
AmountPerCycle int64 `json:"amount_per_cycle"`
CyclePeriod int64 `json:"cycle_period"`
SecuredCapacity int64 `json:"secured_capacity"`
TypeID int64 `json:"type_id"`
UnsecuredCapacity int64 `json:"unsecured_capacity"`
}
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"_key":{"type":"integer","minimum":40013180,"maximum":40328345},"power":{"type":"integer","minimum":100,"maximum":1020},"reagent":{"type":"object","properties":{"amount_per_cycle":{"type":"integer","minimum":31,"maximum":1110},"cycle_period":{"type":"integer","minimum":3600,"maximum":3600},"secured_capacity":{"type":"integer","minimum":45260,"maximum":1620600},"type_id":{"type":"integer","minimum":81143,"maximum":81144},"unsecured_capacity":{"type":"integer","minimum":45260,"maximum":1620600}},"required":["amount_per_cycle","cycle_period","secured_capacity","type_id","unsecured_capacity"]},"workforce":{"type":"integer","minimum":1000,"maximum":10200}},"required":["_key"]}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val planetResource = json.parse(PlanetResource.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class PlanetResource (
@SerialName("_key")
val key: Long,
val power: Long? = null,
val reagent: Reagent? = null,
val workforce: Long? = null
)
@Serializable
data class Reagent (
@SerialName("amount_per_cycle")
val amountPerCycle: Long,
@SerialName("cycle_period")
val cyclePeriod: Long,
@SerialName("secured_capacity")
val securedCapacity: Long,
@SerialName("type_id")
val typeId: Long,
@SerialName("unsecured_capacity")
val unsecuredCapacity: Long
)
<?php
// This is a autogenerated file:PlanetResource
class PlanetResource {
private int $key; // json:_key Required
private ?int $power; // json:power Optional
private ?Reagent $reagent; // json:reagent Optional
private ?int $workforce; // json:workforce Optional
/**
* @param int $key
* @param int|null $power
* @param Reagent|null $reagent
* @param int|null $workforce
*/
public function __construct(int $key, ?int $power, ?Reagent $reagent, ?int $workforce) {
$this->key = $key;
$this->power = $power;
$this->reagent = $reagent;
$this->workforce = $workforce;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromKey(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toKey(): int {
if (PlanetResource::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this PlanetResource::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:PlanetResource::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (PlanetResource::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey PlanetResource::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param ?int $value
* @throws Exception
* @return ?int
*/
public static function fromPower(?int $value): ?int {
if (!is_null($value)) {
return $value; /*int*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?int
*/
public function toPower(): ?int {
if (PlanetResource::validatePower($this->power)) {
if (!is_null($this->power)) {
return $this->power; /*int*/
} else {
return null;
}
}
throw new Exception('never get to this PlanetResource::power');
}
/**
* @param int|null
* @return bool
* @throws Exception
*/
public static function validatePower(?int $value): bool {
if (!is_null($value)) {
if (!is_integer($value)) {
throw new Exception("Attribute Error:PlanetResource::power");
}
}
return true;
}
/**
* @throws Exception
* @return ?int
*/
public function getPower(): ?int {
if (PlanetResource::validatePower($this->power)) {
return $this->power;
}
throw new Exception('never get to getPower PlanetResource::power');
}
/**
* @return ?int
*/
public static function samplePower(): ?int {
return 32; /*32:power*/
}
/**
* @param ?stdClass $value
* @throws Exception
* @return ?Reagent
*/
public static function fromReagent(?stdClass $value): ?Reagent {
if (!is_null($value)) {
return Reagent::from($value); /*class*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?stdClass
*/
public function toReagent(): ?stdClass {
if (PlanetResource::validateReagent($this->reagent)) {
if (!is_null($this->reagent)) {
return $this->reagent->to(); /*class*/
} else {
return null;
}
}
throw new Exception('never get to this PlanetResource::reagent');
}
/**
* @param Reagent|null
* @return bool
* @throws Exception
*/
public static function validateReagent(?Reagent $value): bool {
if (!is_null($value)) {
$value->validate();
}
return true;
}
/**
* @throws Exception
* @return ?Reagent
*/
public function getReagent(): ?Reagent {
if (PlanetResource::validateReagent($this->reagent)) {
return $this->reagent;
}
throw new Exception('never get to getReagent PlanetResource::reagent');
}
/**
* @return ?Reagent
*/
public static function sampleReagent(): ?Reagent {
return Reagent::sample(); /*33:reagent*/
}
/**
* @param ?int $value
* @throws Exception
* @return ?int
*/
public static function fromWorkforce(?int $value): ?int {
if (!is_null($value)) {
return $value; /*int*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?int
*/
public function toWorkforce(): ?int {
if (PlanetResource::validateWorkforce($this->workforce)) {
if (!is_null($this->workforce)) {
return $this->workforce; /*int*/
} else {
return null;
}
}
throw new Exception('never get to this PlanetResource::workforce');
}
/**
* @param int|null
* @return bool
* @throws Exception
*/
public static function validateWorkforce(?int $value): bool {
if (!is_null($value)) {
if (!is_integer($value)) {
throw new Exception("Attribute Error:PlanetResource::workforce");
}
}
return true;
}
/**
* @throws Exception
* @return ?int
*/
public function getWorkforce(): ?int {
if (PlanetResource::validateWorkforce($this->workforce)) {
return $this->workforce;
}
throw new Exception('never get to getWorkforce PlanetResource::workforce');
}
/**
* @return ?int
*/
public static function sampleWorkforce(): ?int {
return 34; /*34:workforce*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return PlanetResource::validateKey($this->key)
|| PlanetResource::validatePower($this->power)
|| PlanetResource::validateReagent($this->reagent)
|| PlanetResource::validateWorkforce($this->workforce);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'power'} = $this->toPower();
$out->{'reagent'} = $this->toReagent();
$out->{'workforce'} = $this->toWorkforce();
return $out;
}
/**
* @param stdClass $obj
* @return PlanetResource
* @throws Exception
*/
public static function from(stdClass $obj): PlanetResource {
return new PlanetResource(
PlanetResource::fromKey($obj->{'_key'})
,PlanetResource::fromPower($obj->{'power'})
,PlanetResource::fromReagent($obj->{'reagent'})
,PlanetResource::fromWorkforce($obj->{'workforce'})
);
}
/**
* @return PlanetResource
*/
public static function sample(): PlanetResource {
return new PlanetResource(
PlanetResource::sampleKey()
,PlanetResource::samplePower()
,PlanetResource::sampleReagent()
,PlanetResource::sampleWorkforce()
);
}
}
// This is a autogenerated file:Reagent
class Reagent {
private int $amountPerCycle; // json:amount_per_cycle Required
private int $cyclePeriod; // json:cycle_period Required
private int $securedCapacity; // json:secured_capacity Required
private int $typeId; // json:type_id Required
private int $unsecuredCapacity; // json:unsecured_capacity Required
/**
* @param int $amountPerCycle
* @param int $cyclePeriod
* @param int $securedCapacity
* @param int $typeId
* @param int $unsecuredCapacity
*/
public function __construct(int $amountPerCycle, int $cyclePeriod, int $securedCapacity, int $typeId, int $unsecuredCapacity) {
$this->amountPerCycle = $amountPerCycle;
$this->cyclePeriod = $cyclePeriod;
$this->securedCapacity = $securedCapacity;
$this->typeId = $typeId;
$this->unsecuredCapacity = $unsecuredCapacity;
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromAmountPerCycle(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toAmountPerCycle(): int {
if (Reagent::validateAmountPerCycle($this->amountPerCycle)) {
return $this->amountPerCycle; /*int*/
}
throw new Exception('never get to this Reagent::amountPerCycle');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateAmountPerCycle(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Reagent::amountPerCycle");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getAmountPerCycle(): int {
if (Reagent::validateAmountPerCycle($this->amountPerCycle)) {
return $this->amountPerCycle;
}
throw new Exception('never get to getAmountPerCycle Reagent::amountPerCycle');
}
/**
* @return int
*/
public static function sampleAmountPerCycle(): int {
return 31; /*31:amountPerCycle*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromCyclePeriod(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toCyclePeriod(): int {
if (Reagent::validateCyclePeriod($this->cyclePeriod)) {
return $this->cyclePeriod; /*int*/
}
throw new Exception('never get to this Reagent::cyclePeriod');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateCyclePeriod(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Reagent::cyclePeriod");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getCyclePeriod(): int {
if (Reagent::validateCyclePeriod($this->cyclePeriod)) {
return $this->cyclePeriod;
}
throw new Exception('never get to getCyclePeriod Reagent::cyclePeriod');
}
/**
* @return int
*/
public static function sampleCyclePeriod(): int {
return 32; /*32:cyclePeriod*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromSecuredCapacity(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toSecuredCapacity(): int {
if (Reagent::validateSecuredCapacity($this->securedCapacity)) {
return $this->securedCapacity; /*int*/
}
throw new Exception('never get to this Reagent::securedCapacity');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateSecuredCapacity(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Reagent::securedCapacity");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getSecuredCapacity(): int {
if (Reagent::validateSecuredCapacity($this->securedCapacity)) {
return $this->securedCapacity;
}
throw new Exception('never get to getSecuredCapacity Reagent::securedCapacity');
}
/**
* @return int
*/
public static function sampleSecuredCapacity(): int {
return 33; /*33:securedCapacity*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromTypeId(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toTypeId(): int {
if (Reagent::validateTypeId($this->typeId)) {
return $this->typeId; /*int*/
}
throw new Exception('never get to this Reagent::typeId');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateTypeId(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Reagent::typeId");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getTypeId(): int {
if (Reagent::validateTypeId($this->typeId)) {
return $this->typeId;
}
throw new Exception('never get to getTypeId Reagent::typeId');
}
/**
* @return int
*/
public static function sampleTypeId(): int {
return 34; /*34:typeId*/
}
/**
* @param int $value
* @throws Exception
* @return int
*/
public static function fromUnsecuredCapacity(int $value): int {
return $value; /*int*/
}
/**
* @throws Exception
* @return int
*/
public function toUnsecuredCapacity(): int {
if (Reagent::validateUnsecuredCapacity($this->unsecuredCapacity)) {
return $this->unsecuredCapacity; /*int*/
}
throw new Exception('never get to this Reagent::unsecuredCapacity');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateUnsecuredCapacity(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Reagent::unsecuredCapacity");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getUnsecuredCapacity(): int {
if (Reagent::validateUnsecuredCapacity($this->unsecuredCapacity)) {
return $this->unsecuredCapacity;
}
throw new Exception('never get to getUnsecuredCapacity Reagent::unsecuredCapacity');
}
/**
* @return int
*/
public static function sampleUnsecuredCapacity(): int {
return 35; /*35:unsecuredCapacity*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Reagent::validateAmountPerCycle($this->amountPerCycle)
|| Reagent::validateCyclePeriod($this->cyclePeriod)
|| Reagent::validateSecuredCapacity($this->securedCapacity)
|| Reagent::validateTypeId($this->typeId)
|| Reagent::validateUnsecuredCapacity($this->unsecuredCapacity);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'amount_per_cycle'} = $this->toAmountPerCycle();
$out->{'cycle_period'} = $this->toCyclePeriod();
$out->{'secured_capacity'} = $this->toSecuredCapacity();
$out->{'type_id'} = $this->toTypeId();
$out->{'unsecured_capacity'} = $this->toUnsecuredCapacity();
return $out;
}
/**
* @param stdClass $obj
* @return Reagent
* @throws Exception
*/
public static function from(stdClass $obj): Reagent {
return new Reagent(
Reagent::fromAmountPerCycle($obj->{'amount_per_cycle'})
,Reagent::fromCyclePeriod($obj->{'cycle_period'})
,Reagent::fromSecuredCapacity($obj->{'secured_capacity'})
,Reagent::fromTypeId($obj->{'type_id'})
,Reagent::fromUnsecuredCapacity($obj->{'unsecured_capacity'})
);
}
/**
* @return Reagent
*/
public static function sample(): Reagent {
return new Reagent(
Reagent::sampleAmountPerCycle()
,Reagent::sampleCyclePeriod()
,Reagent::sampleSecuredCapacity()
,Reagent::sampleTypeId()
,Reagent::sampleUnsecuredCapacity()
);
}
}
from typing import Any, Optional, TypeVar, Type, cast
T = TypeVar("T")
def from_int(x: Any) -> int:
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x: Any) -> Any:
assert x is None
return x
def from_union(fs, x):
for f in fs:
try:
return f(x)
except:
pass
assert False
def to_class(c: Type[T], x: Any) -> dict:
assert isinstance(x, c)
return cast(Any, x).to_dict()
class Reagent:
amount_per_cycle: int
cycle_period: int
secured_capacity: int
type_id: int
unsecured_capacity: int
def __init__(self, amount_per_cycle: int, cycle_period: int, secured_capacity: int, type_id: int, unsecured_capacity: int) -> None:
self.amount_per_cycle = amount_per_cycle
self.cycle_period = cycle_period
self.secured_capacity = secured_capacity
self.type_id = type_id
self.unsecured_capacity = unsecured_capacity
@staticmethod
def from_dict(obj: Any) -> 'Reagent':
assert isinstance(obj, dict)
amount_per_cycle = from_int(obj.get("amount_per_cycle"))
cycle_period = from_int(obj.get("cycle_period"))
secured_capacity = from_int(obj.get("secured_capacity"))
type_id = from_int(obj.get("type_id"))
unsecured_capacity = from_int(obj.get("unsecured_capacity"))
return Reagent(amount_per_cycle, cycle_period, secured_capacity, type_id, unsecured_capacity)
def to_dict(self) -> dict:
result: dict = {}
result["amount_per_cycle"] = from_int(self.amount_per_cycle)
result["cycle_period"] = from_int(self.cycle_period)
result["secured_capacity"] = from_int(self.secured_capacity)
result["type_id"] = from_int(self.type_id)
result["unsecured_capacity"] = from_int(self.unsecured_capacity)
return result
class PlanetResource:
key: int
power: Optional[int]
reagent: Optional[Reagent]
workforce: Optional[int]
def __init__(self, key: int, power: Optional[int], reagent: Optional[Reagent], workforce: Optional[int]) -> None:
self.key = key
self.power = power
self.reagent = reagent
self.workforce = workforce
@staticmethod
def from_dict(obj: Any) -> 'PlanetResource':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
power = from_union([from_int, from_none], obj.get("power"))
reagent = from_union([Reagent.from_dict, from_none], obj.get("reagent"))
workforce = from_union([from_int, from_none], obj.get("workforce"))
return PlanetResource(key, power, reagent, workforce)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
if self.power is not None:
result["power"] = from_union([from_int, from_none], self.power)
if self.reagent is not None:
result["reagent"] = from_union([lambda x: to_class(Reagent, x), from_none], self.reagent)
if self.workforce is not None:
result["workforce"] = from_union([from_int, from_none], self.workforce)
return result
def planet_resource_from_dict(s: Any) -> PlanetResource:
return PlanetResource.from_dict(s)
def planet_resource_to_dict(x: PlanetResource) -> Any:
return to_class(PlanetResource, x)
// To parse this data:
//
// import { Convert, PlanetResource } from "./file";
//
// const planetResource = Convert.toPlanetResource(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface PlanetResource {
_key: number;
power?: number;
reagent?: Reagent;
workforce?: number;
[property: string]: any;
}
export interface Reagent {
amount_per_cycle: number;
cycle_period: number;
secured_capacity: number;
type_id: number;
unsecured_capacity: number;
[property: string]: any;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toPlanetResource(json: string): PlanetResource {
return cast(JSON.parse(json), r("PlanetResource"));
}
public static planetResourceToJson(value: PlanetResource): string {
return JSON.stringify(uncast(value, r("PlanetResource")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"PlanetResource": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "power", js: "power", typ: u(undefined, 0) },
{ json: "reagent", js: "reagent", typ: u(undefined, r("Reagent")) },
{ json: "workforce", js: "workforce", typ: u(undefined, 0) },
], "any"),
"Reagent": o([
{ json: "amount_per_cycle", js: "amount_per_cycle", typ: 0 },
{ json: "cycle_period", js: "cycle_period", typ: 0 },
{ json: "secured_capacity", js: "secured_capacity", typ: 0 },
{ json: "type_id", js: "type_id", typ: 0 },
{ json: "unsecured_capacity", js: "unsecured_capacity", typ: 0 },
], "any"),
};