contrabandTypes.jsonl
Schema
_key
(required): integer
Range: 3713 .. 17796factions
(required): array of object_key
(required): integer
Range: 500001 .. 500018attackMinSec
(required): number
Range: 1.1 .. 1.1confiscateMinSec
(required): number
Range: -1 .. 1.1fineByValue
(required): number
Range: 0 .. 10standingLoss
(required): number
Range: 0 .. 0.5
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var contrabandType = ContrabandType.FromJson(jsonString);
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class ContrabandType
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("factions")]
public Faction[] Factions { get; set; }
}
public partial class Faction
{
[JsonProperty("_key")]
public long Key { get; set; }
[JsonProperty("attackMinSec")]
[JsonConverter(typeof(PurpleMinMaxValueCheckConverter))]
public double AttackMinSec { get; set; }
[JsonProperty("confiscateMinSec")]
[JsonConverter(typeof(FluffyMinMaxValueCheckConverter))]
public double ConfiscateMinSec { get; set; }
[JsonProperty("fineByValue")]
[JsonConverter(typeof(TentacledMinMaxValueCheckConverter))]
public double FineByValue { get; set; }
[JsonProperty("standingLoss")]
[JsonConverter(typeof(StickyMinMaxValueCheckConverter))]
public double StandingLoss { get; set; }
}
public partial class ContrabandType
{
public static ContrabandType FromJson(string json) => JsonConvert.DeserializeObject<ContrabandType>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this ContrabandType 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 PurpleMinMaxValueCheckConverter : 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 >= 1.1 && value <= 1.1)
{
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 >= 1.1 && value <= 1.1)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly PurpleMinMaxValueCheckConverter Singleton = new PurpleMinMaxValueCheckConverter();
}
internal class FluffyMinMaxValueCheckConverter : 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 >= -1 && value <= 1.1)
{
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 >= -1 && value <= 1.1)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly FluffyMinMaxValueCheckConverter Singleton = new FluffyMinMaxValueCheckConverter();
}
internal class TentacledMinMaxValueCheckConverter : 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 && value <= 10)
{
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 && value <= 10)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly TentacledMinMaxValueCheckConverter Singleton = new TentacledMinMaxValueCheckConverter();
}
internal class StickyMinMaxValueCheckConverter : 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 && value <= 0.5)
{
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 && value <= 0.5)
{
serializer.Serialize(writer, value);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly StickyMinMaxValueCheckConverter Singleton = new StickyMinMaxValueCheckConverter();
}
}
// 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:
//
// contrabandType, err := UnmarshalContrabandType(bytes)
// bytes, err = contrabandType.Marshal()
package model
import "encoding/json"
func UnmarshalContrabandType(data []byte) (ContrabandType, error) {
var r ContrabandType
err := json.Unmarshal(data, &r)
return r, err
}
func (r *ContrabandType) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type ContrabandType struct {
Key int64 `json:"_key"`
Factions []Faction `json:"factions"`
}
type Faction struct {
Key int64 `json:"_key"`
AttackMinSEC float64 `json:"attackMinSec"`
ConfiscateMinSEC float64 `json:"confiscateMinSec"`
FineByValue float64 `json:"fineByValue"`
StandingLoss float64 `json:"standingLoss"`
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 3713,
"maximum": 17796
},
"factions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"_key": {
"type": "integer",
"minimum": 500001,
"maximum": 500018
},
"attackMinSec": {
"type": "number",
"minimum": 1.1,
"maximum": 1.1
},
"confiscateMinSec": {
"type": "number",
"minimum": -1.0,
"maximum": 1.1
},
"fineByValue": {
"type": "number",
"minimum": 0.0,
"maximum": 10.0
},
"standingLoss": {
"type": "number",
"minimum": 0.0,
"maximum": 0.5
}
},
"required": [
"_key",
"attackMinSec",
"confiscateMinSec",
"fineByValue",
"standingLoss"
]
},
"minItems": 2,
"maxItems": 11
}
},
"required": [
"_key",
"factions"
]
}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val contrabandType = json.parse(ContrabandType.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class ContrabandType (
@SerialName("_key")
val key: Long,
val factions: List<Faction>
)
@Serializable
data class Faction (
@SerialName("_key")
val key: Long,
val attackMinSec: Double,
val confiscateMinSec: Double,
val fineByValue: Double,
val standingLoss: Double
)
<?php
// This is a autogenerated file:ContrabandType
class ContrabandType {
private int $key; // json:_key Required
private array $factions; // json:factions Required
/**
* @param int $key
* @param array $factions
*/
public function __construct(int $key, array $factions) {
$this->key = $key;
$this->factions = $factions;
}
/**
* @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 (ContrabandType::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this ContrabandType::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:ContrabandType::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (ContrabandType::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey ContrabandType::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param array $value
* @throws Exception
* @return array
*/
public static function fromFactions(array $value): array {
return array_map(function ($value) {
return Faction::from($value); /*class*/
}, $value);
}
/**
* @throws Exception
* @return array
*/
public function toFactions(): array {
if (ContrabandType::validateFactions($this->factions)) {
return array_map(function ($value) {
return $value->to(); /*class*/
}, $this->factions);
}
throw new Exception('never get to this ContrabandType::factions');
}
/**
* @param array
* @return bool
* @throws Exception
*/
public static function validateFactions(array $value): bool {
if (!is_array($value)) {
throw new Exception("Attribute Error:ContrabandType::factions");
}
array_walk($value, function($value_v) {
$value_v->validate();
});
return true;
}
/**
* @throws Exception
* @return array
*/
public function getFactions(): array {
if (ContrabandType::validateFactions($this->factions)) {
return $this->factions;
}
throw new Exception('never get to getFactions ContrabandType::factions');
}
/**
* @return array
*/
public static function sampleFactions(): array {
return array(
Faction::sample() /*32:*/
); /* 32:factions*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return ContrabandType::validateKey($this->key)
|| ContrabandType::validateFactions($this->factions);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'factions'} = $this->toFactions();
return $out;
}
/**
* @param stdClass $obj
* @return ContrabandType
* @throws Exception
*/
public static function from(stdClass $obj): ContrabandType {
return new ContrabandType(
ContrabandType::fromKey($obj->{'_key'})
,ContrabandType::fromFactions($obj->{'factions'})
);
}
/**
* @return ContrabandType
*/
public static function sample(): ContrabandType {
return new ContrabandType(
ContrabandType::sampleKey()
,ContrabandType::sampleFactions()
);
}
}
// This is a autogenerated file:Faction
class Faction {
private int $key; // json:_key Required
private float $attackMinSec; // json:attackMinSec Required
private float $confiscateMinSec; // json:confiscateMinSec Required
private float $fineByValue; // json:fineByValue Required
private float $standingLoss; // json:standingLoss Required
/**
* @param int $key
* @param float $attackMinSec
* @param float $confiscateMinSec
* @param float $fineByValue
* @param float $standingLoss
*/
public function __construct(int $key, float $attackMinSec, float $confiscateMinSec, float $fineByValue, float $standingLoss) {
$this->key = $key;
$this->attackMinSec = $attackMinSec;
$this->confiscateMinSec = $confiscateMinSec;
$this->fineByValue = $fineByValue;
$this->standingLoss = $standingLoss;
}
/**
* @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 (Faction::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this Faction::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Faction::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (Faction::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey Faction::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromAttackMinSec(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toAttackMinSec(): float {
if (Faction::validateAttackMinSec($this->attackMinSec)) {
return $this->attackMinSec; /*float*/
}
throw new Exception('never get to this Faction::attackMinSec');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateAttackMinSec(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Faction::attackMinSec");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getAttackMinSec(): float {
if (Faction::validateAttackMinSec($this->attackMinSec)) {
return $this->attackMinSec;
}
throw new Exception('never get to getAttackMinSec Faction::attackMinSec');
}
/**
* @return float
*/
public static function sampleAttackMinSec(): float {
return 32.032; /*32:attackMinSec*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromConfiscateMinSec(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toConfiscateMinSec(): float {
if (Faction::validateConfiscateMinSec($this->confiscateMinSec)) {
return $this->confiscateMinSec; /*float*/
}
throw new Exception('never get to this Faction::confiscateMinSec');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateConfiscateMinSec(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Faction::confiscateMinSec");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getConfiscateMinSec(): float {
if (Faction::validateConfiscateMinSec($this->confiscateMinSec)) {
return $this->confiscateMinSec;
}
throw new Exception('never get to getConfiscateMinSec Faction::confiscateMinSec');
}
/**
* @return float
*/
public static function sampleConfiscateMinSec(): float {
return 33.033; /*33:confiscateMinSec*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromFineByValue(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toFineByValue(): float {
if (Faction::validateFineByValue($this->fineByValue)) {
return $this->fineByValue; /*float*/
}
throw new Exception('never get to this Faction::fineByValue');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateFineByValue(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Faction::fineByValue");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getFineByValue(): float {
if (Faction::validateFineByValue($this->fineByValue)) {
return $this->fineByValue;
}
throw new Exception('never get to getFineByValue Faction::fineByValue');
}
/**
* @return float
*/
public static function sampleFineByValue(): float {
return 34.034; /*34:fineByValue*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromStandingLoss(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toStandingLoss(): float {
if (Faction::validateStandingLoss($this->standingLoss)) {
return $this->standingLoss; /*float*/
}
throw new Exception('never get to this Faction::standingLoss');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateStandingLoss(float $value): bool {
if (!is_float($value)) {
throw new Exception("Attribute Error:Faction::standingLoss");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getStandingLoss(): float {
if (Faction::validateStandingLoss($this->standingLoss)) {
return $this->standingLoss;
}
throw new Exception('never get to getStandingLoss Faction::standingLoss');
}
/**
* @return float
*/
public static function sampleStandingLoss(): float {
return 35.035; /*35:standingLoss*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Faction::validateKey($this->key)
|| Faction::validateAttackMinSec($this->attackMinSec)
|| Faction::validateConfiscateMinSec($this->confiscateMinSec)
|| Faction::validateFineByValue($this->fineByValue)
|| Faction::validateStandingLoss($this->standingLoss);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'attackMinSec'} = $this->toAttackMinSec();
$out->{'confiscateMinSec'} = $this->toConfiscateMinSec();
$out->{'fineByValue'} = $this->toFineByValue();
$out->{'standingLoss'} = $this->toStandingLoss();
return $out;
}
/**
* @param stdClass $obj
* @return Faction
* @throws Exception
*/
public static function from(stdClass $obj): Faction {
return new Faction(
Faction::fromKey($obj->{'_key'})
,Faction::fromAttackMinSec($obj->{'attackMinSec'})
,Faction::fromConfiscateMinSec($obj->{'confiscateMinSec'})
,Faction::fromFineByValue($obj->{'fineByValue'})
,Faction::fromStandingLoss($obj->{'standingLoss'})
);
}
/**
* @return Faction
*/
public static function sample(): Faction {
return new Faction(
Faction::sampleKey()
,Faction::sampleAttackMinSec()
,Faction::sampleConfiscateMinSec()
,Faction::sampleFineByValue()
,Faction::sampleStandingLoss()
);
}
}
from typing import 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_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 Faction:
key: int
attack_min_sec: float
confiscate_min_sec: float
fine_by_value: float
standing_loss: float
def __init__(self, key: int, attack_min_sec: float, confiscate_min_sec: float, fine_by_value: float, standing_loss: float) -> None:
self.key = key
self.attack_min_sec = attack_min_sec
self.confiscate_min_sec = confiscate_min_sec
self.fine_by_value = fine_by_value
self.standing_loss = standing_loss
@staticmethod
def from_dict(obj: Any) -> 'Faction':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
attack_min_sec = from_float(obj.get("attackMinSec"))
confiscate_min_sec = from_float(obj.get("confiscateMinSec"))
fine_by_value = from_float(obj.get("fineByValue"))
standing_loss = from_float(obj.get("standingLoss"))
return Faction(key, attack_min_sec, confiscate_min_sec, fine_by_value, standing_loss)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["attackMinSec"] = to_float(self.attack_min_sec)
result["confiscateMinSec"] = to_float(self.confiscate_min_sec)
result["fineByValue"] = to_float(self.fine_by_value)
result["standingLoss"] = to_float(self.standing_loss)
return result
class ContrabandType:
key: int
factions: List[Faction]
def __init__(self, key: int, factions: List[Faction]) -> None:
self.key = key
self.factions = factions
@staticmethod
def from_dict(obj: Any) -> 'ContrabandType':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
factions = from_list(Faction.from_dict, obj.get("factions"))
return ContrabandType(key, factions)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["factions"] = from_list(lambda x: to_class(Faction, x), self.factions)
return result
def contraband_type_from_dict(s: Any) -> ContrabandType:
return ContrabandType.from_dict(s)
def contraband_type_to_dict(x: ContrabandType) -> Any:
return to_class(ContrabandType, x)
// To parse this data:
//
// import { Convert, ContrabandType } from "./file";
//
// const contrabandType = Convert.toContrabandType(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface ContrabandType {
_key: number;
factions: Faction[];
[property: string]: any;
}
export interface Faction {
_key: number;
attackMinSec: number;
confiscateMinSec: number;
fineByValue: number;
standingLoss: 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 toContrabandType(json: string): ContrabandType {
return cast(JSON.parse(json), r("ContrabandType"));
}
public static contrabandTypeToJson(value: ContrabandType): string {
return JSON.stringify(uncast(value, r("ContrabandType")), 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 = {
"ContrabandType": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "factions", js: "factions", typ: a(r("Faction")) },
], "any"),
"Faction": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "attackMinSec", js: "attackMinSec", typ: 3.14 },
{ json: "confiscateMinSec", js: "confiscateMinSec", typ: 3.14 },
{ json: "fineByValue", js: "fineByValue", typ: 3.14 },
{ json: "standingLoss", js: "standingLoss", typ: 3.14 },
], "any"),
};