Skip to content

EVE SDE Schema

Documentation for third-party developers

controlTowerResources.jsonl

Schema

  • _key (required): integer
    Range: 4361 .. 27790
  • resources (required): array of object
    • factionID: integer
      Range: 500001 .. 500008
    • minSecurityLevel: number
      Range: 0.45 .. 0.45
    • purpose (required): integer
      Range: 1 .. 4
    • quantity (required): integer
      Range: 1 .. 400
    • resourceTypeID (required): integer
      Range: 4051 .. 24597

Code snippets

// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var controlTowerResource = ControlTowerResource.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class ControlTowerResource
    {
        [JsonProperty("_key")]
        public long Key { get; set; }

        [JsonProperty("resources")]
        public Resource[] Resources { get; set; }
    }

    public partial class Resource
    {
        [JsonProperty("factionID", NullValueHandling = NullValueHandling.Ignore)]
        public long? FactionId { get; set; }

        [JsonProperty("minSecurityLevel", NullValueHandling = NullValueHandling.Ignore)]
        [JsonConverter(typeof(MinMaxValueCheckConverter))]
        public double? MinSecurityLevel { get; set; }

        [JsonProperty("purpose")]
        public long Purpose { get; set; }

        [JsonProperty("quantity")]
        public long Quantity { get; set; }

        [JsonProperty("resourceTypeID")]
        public long ResourceTypeId { get; set; }
    }

    public partial class ControlTowerResource
    {
        public static ControlTowerResource FromJson(string json) => JsonConvert.DeserializeObject<ControlTowerResource>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this ControlTowerResource 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 }
            },
        };
    }

    internal class MinMaxValueCheckConverter : JsonConverter
    {
        public override bool CanConvert(Type t) => t == typeof(double) || t == typeof(double?);

        public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null) return null;
            var value = serializer.Deserialize<double>(reader);
            if (value >= 0.45 && value <= 0.45)
            {
                return value;
            }
            throw new Exception("Cannot unmarshal type double");
        }

        public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer, null);
                return;
            }
            var value = (double)untypedValue;
            if (value >= 0.45 && value <= 0.45)
            {
                serializer.Serialize(writer, value);
                return;
            }
            throw new Exception("Cannot marshal type double");
        }

        public static readonly MinMaxValueCheckConverter Singleton = new MinMaxValueCheckConverter();
    }
}
// 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:
//
//    controlTowerResource, err := UnmarshalControlTowerResource(bytes)
//    bytes, err = controlTowerResource.Marshal()

package model

import "encoding/json"

func UnmarshalControlTowerResource(data []byte) (ControlTowerResource, error) {
    var r ControlTowerResource
    err := json.Unmarshal(data, &r)
    return r, err
}

func (r *ControlTowerResource) Marshal() ([]byte, error) {
    return json.Marshal(r)
}

type ControlTowerResource struct {
    Key       int64      `json:"_key"`
    Resources []Resource `json:"resources"`
}

type Resource struct {
    FactionID        *int64   `json:"factionID,omitempty"`
    MinSecurityLevel *float64 `json:"minSecurityLevel,omitempty"`
    Purpose          int64    `json:"purpose"`
    Quantity         int64    `json:"quantity"`
    ResourceTypeID   int64    `json:"resourceTypeID"`
}
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "_key": {
            "type": "integer",
            "minimum": 4361,
            "maximum": 27790
        },
        "resources": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "factionID": {
                        "type": "integer",
                        "minimum": 500001,
                        "maximum": 500008
                    },
                    "minSecurityLevel": {
                        "type": "number",
                        "minimum": 0.45,
                        "maximum": 0.45
                    },
                    "purpose": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 4
                    },
                    "quantity": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 400
                    },
                    "resourceTypeID": {
                        "type": "integer",
                        "minimum": 4051,
                        "maximum": 24597
                    }
                },
                "required": [
                    "purpose",
                    "quantity",
                    "resourceTypeID"
                ]
            },
            "minItems": 1,
            "maxItems": 8
        }
    },
    "required": [
        "_key",
        "resources"
    ]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json                 = Json { allowStructuredMapKeys = true }
// val controlTowerResource = json.parse(ControlTowerResource.serializer(), jsonString)

package model

import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*

@Serializable
data class ControlTowerResource (
    @SerialName("_key")
    val key: Long,

    val resources: List<Resource>
)

@Serializable
data class Resource (
    @SerialName("factionID")
    val factionId: Long? = null,

    val minSecurityLevel: Double? = null,
    val purpose: Long,
    val quantity: Long,

    @SerialName("resourceTypeID")
    val resourceTypeId: Long
)
<?php

// This is a autogenerated file:ControlTowerResource

class ControlTowerResource {
    private int $key; // json:_key Required
    private array $resources; // json:resources Required

    /**
     * @param int $key
     * @param array $resources
     */
    public function __construct(int $key, array $resources) {
        $this->key = $key;
        $this->resources = $resources;
    }

    /**
     * @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 (ControlTowerResource::validateKey($this->key))  {
            return $this->key; /*int*/
        }
        throw new Exception('never get to this ControlTowerResource::key');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validateKey(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:ControlTowerResource::key");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getKey(): int {
        if (ControlTowerResource::validateKey($this->key))  {
            return $this->key;
        }
        throw new Exception('never get to getKey ControlTowerResource::key');
    }

    /**
     * @return int
     */
    public static function sampleKey(): int {
        return 31; /*31:key*/
    }

    /**
     * @param array $value
     * @throws Exception
     * @return array
     */
    public static function fromResources(array $value): array {
        return  array_map(function ($value) {
            return Resource::from($value); /*class*/
        }, $value);
    }

    /**
     * @throws Exception
     * @return array
     */
    public function toResources(): array {
        if (ControlTowerResource::validateResources($this->resources))  {
            return array_map(function ($value) {
                return $value->to(); /*class*/
            }, $this->resources);
        }
        throw new Exception('never get to this ControlTowerResource::resources');
    }

    /**
     * @param array
     * @return bool
     * @throws Exception
     */
    public static function validateResources(array $value): bool {
        if (!is_array($value)) {
            throw new Exception("Attribute Error:ControlTowerResource::resources");
        }
        array_walk($value, function($value_v) {
            $value_v->validate();
        });
        return true;
    }

    /**
     * @throws Exception
     * @return array
     */
    public function getResources(): array {
        if (ControlTowerResource::validateResources($this->resources))  {
            return $this->resources;
        }
        throw new Exception('never get to getResources ControlTowerResource::resources');
    }

    /**
     * @return array
     */
    public static function sampleResources(): array {
        return  array(
            Resource::sample() /*32:*/
        ); /* 32:resources*/
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function validate(): bool {
        return ControlTowerResource::validateKey($this->key)
        || ControlTowerResource::validateResources($this->resources);
    }

    /**
     * @return stdClass
     * @throws Exception
     */
    public function to(): stdClass  {
        $out = new stdClass();
        $out->{'_key'} = $this->toKey();
        $out->{'resources'} = $this->toResources();
        return $out;
    }

    /**
     * @param stdClass $obj
     * @return ControlTowerResource
     * @throws Exception
     */
    public static function from(stdClass $obj): ControlTowerResource {
        return new ControlTowerResource(
         ControlTowerResource::fromKey($obj->{'_key'})
        ,ControlTowerResource::fromResources($obj->{'resources'})
        );
    }

    /**
     * @return ControlTowerResource
     */
    public static function sample(): ControlTowerResource {
        return new ControlTowerResource(
         ControlTowerResource::sampleKey()
        ,ControlTowerResource::sampleResources()
        );
    }
}

// This is a autogenerated file:Resource

class Resource {
    private ?int $factionId; // json:factionID Optional
    private ?float $minSecurityLevel; // json:minSecurityLevel Optional
    private int $purpose; // json:purpose Required
    private int $quantity; // json:quantity Required
    private int $resourceTypeId; // json:resourceTypeID Required

    /**
     * @param int|null $factionId
     * @param float|null $minSecurityLevel
     * @param int $purpose
     * @param int $quantity
     * @param int $resourceTypeId
     */
    public function __construct(?int $factionId, ?float $minSecurityLevel, int $purpose, int $quantity, int $resourceTypeId) {
        $this->factionId = $factionId;
        $this->minSecurityLevel = $minSecurityLevel;
        $this->purpose = $purpose;
        $this->quantity = $quantity;
        $this->resourceTypeId = $resourceTypeId;
    }

    /**
     * @param ?int $value
     * @throws Exception
     * @return ?int
     */
    public static function fromFactionId(?int $value): ?int {
        if (!is_null($value)) {
            return $value; /*int*/
        } else {
            return null;
        }
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function toFactionId(): ?int {
        if (Resource::validateFactionId($this->factionId))  {
            if (!is_null($this->factionId)) {
                return $this->factionId; /*int*/
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this Resource::factionId');
    }

    /**
     * @param int|null
     * @return bool
     * @throws Exception
     */
    public static function validateFactionId(?int $value): bool {
        if (!is_null($value)) {
            if (!is_integer($value)) {
                throw new Exception("Attribute Error:Resource::factionId");
            }
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?int
     */
    public function getFactionId(): ?int {
        if (Resource::validateFactionId($this->factionId))  {
            return $this->factionId;
        }
        throw new Exception('never get to getFactionId Resource::factionId');
    }

    /**
     * @return ?int
     */
    public static function sampleFactionId(): ?int {
        return 31; /*31:factionId*/
    }

    /**
     * @param ?float $value
     * @throws Exception
     * @return ?float
     */
    public static function fromMinSecurityLevel(?float $value): ?float {
        if (!is_null($value)) {
            return $value; /*float*/
        } else {
            return null;
        }
    }

    /**
     * @throws Exception
     * @return ?float
     */
    public function toMinSecurityLevel(): ?float {
        if (Resource::validateMinSecurityLevel($this->minSecurityLevel))  {
            if (!is_null($this->minSecurityLevel)) {
                return $this->minSecurityLevel; /*float*/
            } else {
                return  null;
            }
        }
        throw new Exception('never get to this Resource::minSecurityLevel');
    }

    /**
     * @param float|null
     * @return bool
     * @throws Exception
     */
    public static function validateMinSecurityLevel(?float $value): bool {
        if (!is_null($value)) {
            if (!is_float($value)) {
                throw new Exception("Attribute Error:Resource::minSecurityLevel");
            }
        }
        return true;
    }

    /**
     * @throws Exception
     * @return ?float
     */
    public function getMinSecurityLevel(): ?float {
        if (Resource::validateMinSecurityLevel($this->minSecurityLevel))  {
            return $this->minSecurityLevel;
        }
        throw new Exception('never get to getMinSecurityLevel Resource::minSecurityLevel');
    }

    /**
     * @return ?float
     */
    public static function sampleMinSecurityLevel(): ?float {
        return 32.032; /*32:minSecurityLevel*/
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromPurpose(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toPurpose(): int {
        if (Resource::validatePurpose($this->purpose))  {
            return $this->purpose; /*int*/
        }
        throw new Exception('never get to this Resource::purpose');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validatePurpose(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:Resource::purpose");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getPurpose(): int {
        if (Resource::validatePurpose($this->purpose))  {
            return $this->purpose;
        }
        throw new Exception('never get to getPurpose Resource::purpose');
    }

    /**
     * @return int
     */
    public static function samplePurpose(): int {
        return 33; /*33:purpose*/
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromQuantity(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toQuantity(): int {
        if (Resource::validateQuantity($this->quantity))  {
            return $this->quantity; /*int*/
        }
        throw new Exception('never get to this Resource::quantity');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validateQuantity(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:Resource::quantity");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getQuantity(): int {
        if (Resource::validateQuantity($this->quantity))  {
            return $this->quantity;
        }
        throw new Exception('never get to getQuantity Resource::quantity');
    }

    /**
     * @return int
     */
    public static function sampleQuantity(): int {
        return 34; /*34:quantity*/
    }

    /**
     * @param int $value
     * @throws Exception
     * @return int
     */
    public static function fromResourceTypeId(int $value): int {
        return $value; /*int*/
    }

    /**
     * @throws Exception
     * @return int
     */
    public function toResourceTypeId(): int {
        if (Resource::validateResourceTypeId($this->resourceTypeId))  {
            return $this->resourceTypeId; /*int*/
        }
        throw new Exception('never get to this Resource::resourceTypeId');
    }

    /**
     * @param int
     * @return bool
     * @throws Exception
     */
    public static function validateResourceTypeId(int $value): bool {
        if (!is_integer($value)) {
            throw new Exception("Attribute Error:Resource::resourceTypeId");
        }
        return true;
    }

    /**
     * @throws Exception
     * @return int
     */
    public function getResourceTypeId(): int {
        if (Resource::validateResourceTypeId($this->resourceTypeId))  {
            return $this->resourceTypeId;
        }
        throw new Exception('never get to getResourceTypeId Resource::resourceTypeId');
    }

    /**
     * @return int
     */
    public static function sampleResourceTypeId(): int {
        return 35; /*35:resourceTypeId*/
    }

    /**
     * @throws Exception
     * @return bool
     */
    public function validate(): bool {
        return Resource::validateFactionId($this->factionId)
        || Resource::validateMinSecurityLevel($this->minSecurityLevel)
        || Resource::validatePurpose($this->purpose)
        || Resource::validateQuantity($this->quantity)
        || Resource::validateResourceTypeId($this->resourceTypeId);
    }

    /**
     * @return stdClass
     * @throws Exception
     */
    public function to(): stdClass  {
        $out = new stdClass();
        $out->{'factionID'} = $this->toFactionId();
        $out->{'minSecurityLevel'} = $this->toMinSecurityLevel();
        $out->{'purpose'} = $this->toPurpose();
        $out->{'quantity'} = $this->toQuantity();
        $out->{'resourceTypeID'} = $this->toResourceTypeId();
        return $out;
    }

    /**
     * @param stdClass $obj
     * @return Resource
     * @throws Exception
     */
    public static function from(stdClass $obj): Resource {
        return new Resource(
         Resource::fromFactionId($obj->{'factionID'})
        ,Resource::fromMinSecurityLevel($obj->{'minSecurityLevel'})
        ,Resource::fromPurpose($obj->{'purpose'})
        ,Resource::fromQuantity($obj->{'quantity'})
        ,Resource::fromResourceTypeId($obj->{'resourceTypeID'})
        );
    }

    /**
     * @return Resource
     */
    public static function sample(): Resource {
        return new Resource(
         Resource::sampleFactionId()
        ,Resource::sampleMinSecurityLevel()
        ,Resource::samplePurpose()
        ,Resource::sampleQuantity()
        ,Resource::sampleResourceTypeId()
        );
    }
}
from typing import Optional, Any, List, TypeVar, Callable, 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 from_float(x: Any) -> float:
    assert isinstance(x, (float, int)) and not isinstance(x, bool)
    return float(x)


def to_float(x: Any) -> float:
    assert isinstance(x, (int, float))
    return x


def from_list(f: Callable[[Any], T], x: Any) -> List[T]:
    assert isinstance(x, list)
    return [f(y) for y in x]


def to_class(c: Type[T], x: Any) -> dict:
    assert isinstance(x, c)
    return cast(Any, x).to_dict()


class Resource:
    faction_id: Optional[int]
    min_security_level: Optional[float]
    purpose: int
    quantity: int
    resource_type_id: int

    def __init__(self, faction_id: Optional[int], min_security_level: Optional[float], purpose: int, quantity: int, resource_type_id: int) -> None:
        self.faction_id = faction_id
        self.min_security_level = min_security_level
        self.purpose = purpose
        self.quantity = quantity
        self.resource_type_id = resource_type_id

    @staticmethod
    def from_dict(obj: Any) -> 'Resource':
        assert isinstance(obj, dict)
        faction_id = from_union([from_int, from_none], obj.get("factionID"))
        min_security_level = from_union([from_float, from_none], obj.get("minSecurityLevel"))
        purpose = from_int(obj.get("purpose"))
        quantity = from_int(obj.get("quantity"))
        resource_type_id = from_int(obj.get("resourceTypeID"))
        return Resource(faction_id, min_security_level, purpose, quantity, resource_type_id)

    def to_dict(self) -> dict:
        result: dict = {}
        if self.faction_id is not None:
            result["factionID"] = from_union([from_int, from_none], self.faction_id)
        if self.min_security_level is not None:
            result["minSecurityLevel"] = from_union([to_float, from_none], self.min_security_level)
        result["purpose"] = from_int(self.purpose)
        result["quantity"] = from_int(self.quantity)
        result["resourceTypeID"] = from_int(self.resource_type_id)
        return result


class ControlTowerResource:
    key: int
    resources: List[Resource]

    def __init__(self, key: int, resources: List[Resource]) -> None:
        self.key = key
        self.resources = resources

    @staticmethod
    def from_dict(obj: Any) -> 'ControlTowerResource':
        assert isinstance(obj, dict)
        key = from_int(obj.get("_key"))
        resources = from_list(Resource.from_dict, obj.get("resources"))
        return ControlTowerResource(key, resources)

    def to_dict(self) -> dict:
        result: dict = {}
        result["_key"] = from_int(self.key)
        result["resources"] = from_list(lambda x: to_class(Resource, x), self.resources)
        return result


def control_tower_resource_from_dict(s: Any) -> ControlTowerResource:
    return ControlTowerResource.from_dict(s)


def control_tower_resource_to_dict(x: ControlTowerResource) -> Any:
    return to_class(ControlTowerResource, x)
// To parse this data:
//
//   import { Convert, ControlTowerResource } from "./file";
//
//   const controlTowerResource = Convert.toControlTowerResource(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

export interface ControlTowerResource {
    _key:      number;
    resources: Resource[];
    [property: string]: any;
}

export interface Resource {
    factionID?:        number;
    minSecurityLevel?: number;
    purpose:           number;
    quantity:          number;
    resourceTypeID:    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 toControlTowerResource(json: string): ControlTowerResource {
        return cast(JSON.parse(json), r("ControlTowerResource"));
    }

    public static controlTowerResourceToJson(value: ControlTowerResource): string {
        return JSON.stringify(uncast(value, r("ControlTowerResource")), 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 = {
    "ControlTowerResource": o([
        { json: "_key", js: "_key", typ: 0 },
        { json: "resources", js: "resources", typ: a(r("Resource")) },
    ], "any"),
    "Resource": o([
        { json: "factionID", js: "factionID", typ: u(undefined, 0) },
        { json: "minSecurityLevel", js: "minSecurityLevel", typ: u(undefined, 3.14) },
        { json: "purpose", js: "purpose", typ: 0 },
        { json: "quantity", js: "quantity", typ: 0 },
        { json: "resourceTypeID", js: "resourceTypeID", typ: 0 },
    ], "any"),
};