systemWideEffects.jsonl
Schema
_key(required): integer
Range: 30844 .. 93255-
dbuffs: array of object_key(required): integer
Range: 2482 .. 2591_value(required): number
Range: -50 .. 30
-
eligibleTypeListID: integer
Range: 832 .. 966 environmentTypeID: integer
Range: 56049 .. 87725
Code snippets
// <auto-generated />
//
// To parse this JSON data, add NuGet 'System.Text.Json' then do:
//
// using QuickType;
//
// var systemWideEffect = SystemWideEffect.FromJson(jsonString);
#nullable enable
#pragma warning disable CS8618
#pragma warning disable CS8601
#pragma warning disable CS8602
#pragma warning disable CS8603
namespace QuickType
{
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
public partial class SystemWideEffect
{
[JsonPropertyName("_key")]
public long Key { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("dbuffs")]
public Dbuff[]? Dbuffs { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("eligibleTypeListID")]
public long? EligibleTypeListId { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("environmentTypeID")]
public long? EnvironmentTypeId { get; set; }
}
public partial class Dbuff
{
[JsonPropertyName("_key")]
public long Key { get; set; }
[JsonPropertyName("_value")]
[JsonConverter(typeof(MinMaxValueCheckConverter))]
public double Value { get; set; }
}
public partial class SystemWideEffect
{
public static SystemWideEffect FromJson(string json) => JsonSerializer.Deserialize<SystemWideEffect>(json, QuickType.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this SystemWideEffect self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
{
Converters =
{
new DateOnlyConverter(),
new TimeOnlyConverter(),
IsoDateTimeOffsetConverter.Singleton
},
};
}
internal class MinMaxValueCheckConverter : JsonConverter<double>
{
public override bool CanConvert(Type t) => t == typeof(double);
public override double Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetDouble();
if (value >= -50 && value <= 30)
{
return value;
}
throw new Exception("Cannot unmarshal type double");
}
public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options)
{
if (value >= -50 && value <= 30)
{
JsonSerializer.Serialize(writer, value, options);
return;
}
throw new Exception("Cannot marshal type double");
}
public static readonly MinMaxValueCheckConverter Singleton = new MinMaxValueCheckConverter();
}
public class DateOnlyConverter : JsonConverter<DateOnly>
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null) { }
public DateOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
}
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return DateOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
public class TimeOnlyConverter : JsonConverter<TimeOnly>
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null) { }
public TimeOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
}
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return TimeOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private string? _dateTimeFormat;
private CultureInfo? _culture;
public DateTimeStyles DateTimeStyles
{
get => _dateTimeStyles;
set => _dateTimeStyles = value;
}
public string? DateTimeFormat
{
get => _dateTimeFormat ?? string.Empty;
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
}
public CultureInfo Culture
{
get => _culture ?? CultureInfo.CurrentCulture;
set => _culture = value;
}
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
string text;
if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
{
value = value.ToUniversalTime();
}
text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
writer.WriteStringValue(text);
}
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string? dateText = reader.GetString();
if (string.IsNullOrEmpty(dateText) == false)
{
if (!string.IsNullOrEmpty(_dateTimeFormat))
{
return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
else
{
return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
}
}
else
{
return default(DateTimeOffset);
}
}
public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
}
}
#pragma warning restore CS8618
#pragma warning restore CS8601
#pragma warning restore CS8602
#pragma warning restore CS8603
// 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:
//
// systemWideEffect, err := UnmarshalSystemWideEffect(bytes)
// bytes, err = systemWideEffect.Marshal()
package model
import "encoding/json"
func UnmarshalSystemWideEffect(data []byte) (SystemWideEffect, error) {
var r SystemWideEffect
err := json.Unmarshal(data, &r)
return r, err
}
func (r *SystemWideEffect) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type SystemWideEffect struct {
Key int64 `json:"_key"`
Dbuffs []Dbuff `json:"dbuffs,omitempty"`
EligibleTypeListID *int64 `json:"eligibleTypeListID,omitempty"`
EnvironmentTypeID *int64 `json:"environmentTypeID,omitempty"`
}
type Dbuff struct {
Key int64 `json:"_key"`
Value float64 `json:"_value"`
}
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"_key":{"type":"integer","minimum":30844,"maximum":93255},"dbuffs":{"type":"array","items":{"type":"object","properties":{"_key":{"type":"integer","minimum":2482,"maximum":2591},"_value":{"type":"number","minimum":-50.0,"maximum":30.0}},"required":["_key","_value"]},"minItems":1,"maxItems":3},"eligibleTypeListID":{"type":"integer","minimum":832,"maximum":966},"environmentTypeID":{"type":"integer","minimum":56049,"maximum":87725}},"required":["_key"]}
// To parse the JSON, install kotlin's serialization plugin and do:
//
// val json = Json { allowStructuredMapKeys = true }
// val systemWideEffect = json.parse(SystemWideEffect.serializer(), jsonString)
package model
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@Serializable
data class SystemWideEffect (
@SerialName("_key")
val key: Long,
val dbuffs: List<Dbuff>? = null,
@SerialName("eligibleTypeListID")
val eligibleTypeListId: Long? = null,
@SerialName("environmentTypeID")
val environmentTypeId: Long? = null
)
@Serializable
data class Dbuff (
@SerialName("_key")
val key: Long,
@SerialName("_value")
val value: Double
)
<?php
// This is an autogenerated file:SystemWideEffect
class SystemWideEffect {
private int $key; // json:_key Required
private ?array $dbuffs; // json:dbuffs Optional
private ?int $eligibleTypeListId; // json:eligibleTypeListID Optional
private ?int $environmentTypeId; // json:environmentTypeID Optional
/**
* @param int $key
* @param array|null $dbuffs
* @param int|null $eligibleTypeListId
* @param int|null $environmentTypeId
*/
public function __construct(int $key, ?array $dbuffs, ?int $eligibleTypeListId, ?int $environmentTypeId) {
$this->key = $key;
$this->dbuffs = $dbuffs;
$this->eligibleTypeListId = $eligibleTypeListId;
$this->environmentTypeId = $environmentTypeId;
}
/**
* @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 (SystemWideEffect::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this SystemWideEffect::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:SystemWideEffect::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (SystemWideEffect::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey SystemWideEffect::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param ?array $value
* @throws Exception
* @return ?array
*/
public static function fromDbuffs(?array $value): ?array {
if (!is_null($value)) {
return array_map(function ($value) {
return Dbuff::from($value); /*class*/
}, $value);
} else {
return null;
}
}
/**
* @throws Exception
* @return ?array
*/
public function toDbuffs(): ?array {
if (SystemWideEffect::validateDbuffs($this->dbuffs)) {
if (!is_null($this->dbuffs)) {
return array_map(function ($value) {
return $value->to(); /*class*/
}, $this->dbuffs);
} else {
return null;
}
}
throw new Exception('never get to this SystemWideEffect::dbuffs');
}
/**
* @param array|null
* @return bool
* @throws Exception
*/
public static function validateDbuffs(?array $value): bool {
if (!is_null($value)) {
if (!is_array($value)) {
throw new Exception("Attribute Error:SystemWideEffect::dbuffs");
}
array_walk($value, function($value_v) {
$value_v->validate();
});
}
return true;
}
/**
* @throws Exception
* @return ?array
*/
public function getDbuffs(): ?array {
if (SystemWideEffect::validateDbuffs($this->dbuffs)) {
return $this->dbuffs;
}
throw new Exception('never get to getDbuffs SystemWideEffect::dbuffs');
}
/**
* @return ?array
*/
public static function sampleDbuffs(): ?array {
return array(
Dbuff::sample() /*32:*/
); /* 32:dbuffs*/
}
/**
* @param ?int $value
* @throws Exception
* @return ?int
*/
public static function fromEligibleTypeListId(?int $value): ?int {
if (!is_null($value)) {
return $value; /*int*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?int
*/
public function toEligibleTypeListId(): ?int {
if (SystemWideEffect::validateEligibleTypeListId($this->eligibleTypeListId)) {
if (!is_null($this->eligibleTypeListId)) {
return $this->eligibleTypeListId; /*int*/
} else {
return null;
}
}
throw new Exception('never get to this SystemWideEffect::eligibleTypeListId');
}
/**
* @param int|null
* @return bool
* @throws Exception
*/
public static function validateEligibleTypeListId(?int $value): bool {
if (!is_null($value)) {
if (!is_integer($value)) {
throw new Exception("Attribute Error:SystemWideEffect::eligibleTypeListId");
}
}
return true;
}
/**
* @throws Exception
* @return ?int
*/
public function getEligibleTypeListId(): ?int {
if (SystemWideEffect::validateEligibleTypeListId($this->eligibleTypeListId)) {
return $this->eligibleTypeListId;
}
throw new Exception('never get to getEligibleTypeListId SystemWideEffect::eligibleTypeListId');
}
/**
* @return ?int
*/
public static function sampleEligibleTypeListId(): ?int {
return 33; /*33:eligibleTypeListId*/
}
/**
* @param ?int $value
* @throws Exception
* @return ?int
*/
public static function fromEnvironmentTypeId(?int $value): ?int {
if (!is_null($value)) {
return $value; /*int*/
} else {
return null;
}
}
/**
* @throws Exception
* @return ?int
*/
public function toEnvironmentTypeId(): ?int {
if (SystemWideEffect::validateEnvironmentTypeId($this->environmentTypeId)) {
if (!is_null($this->environmentTypeId)) {
return $this->environmentTypeId; /*int*/
} else {
return null;
}
}
throw new Exception('never get to this SystemWideEffect::environmentTypeId');
}
/**
* @param int|null
* @return bool
* @throws Exception
*/
public static function validateEnvironmentTypeId(?int $value): bool {
if (!is_null($value)) {
if (!is_integer($value)) {
throw new Exception("Attribute Error:SystemWideEffect::environmentTypeId");
}
}
return true;
}
/**
* @throws Exception
* @return ?int
*/
public function getEnvironmentTypeId(): ?int {
if (SystemWideEffect::validateEnvironmentTypeId($this->environmentTypeId)) {
return $this->environmentTypeId;
}
throw new Exception('never get to getEnvironmentTypeId SystemWideEffect::environmentTypeId');
}
/**
* @return ?int
*/
public static function sampleEnvironmentTypeId(): ?int {
return 34; /*34:environmentTypeId*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return SystemWideEffect::validateKey($this->key)
|| SystemWideEffect::validateDbuffs($this->dbuffs)
|| SystemWideEffect::validateEligibleTypeListId($this->eligibleTypeListId)
|| SystemWideEffect::validateEnvironmentTypeId($this->environmentTypeId);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'dbuffs'} = $this->toDbuffs();
$out->{'eligibleTypeListID'} = $this->toEligibleTypeListId();
$out->{'environmentTypeID'} = $this->toEnvironmentTypeId();
return $out;
}
/**
* @param stdClass $obj
* @return SystemWideEffect
* @throws Exception
*/
public static function from(stdClass $obj): SystemWideEffect {
return new SystemWideEffect(
SystemWideEffect::fromKey($obj->{'_key'})
,SystemWideEffect::fromDbuffs($obj->{'dbuffs'})
,SystemWideEffect::fromEligibleTypeListId($obj->{'eligibleTypeListID'})
,SystemWideEffect::fromEnvironmentTypeId($obj->{'environmentTypeID'})
);
}
/**
* @return SystemWideEffect
*/
public static function sample(): SystemWideEffect {
return new SystemWideEffect(
SystemWideEffect::sampleKey()
,SystemWideEffect::sampleDbuffs()
,SystemWideEffect::sampleEligibleTypeListId()
,SystemWideEffect::sampleEnvironmentTypeId()
);
}
}
// This is an autogenerated file:Dbuff
class Dbuff {
private int $key; // json:_key Required
private float $value; // json:_value Required
/**
* @param int $key
* @param float $value
*/
public function __construct(int $key, float $value) {
$this->key = $key;
$this->value = $value;
}
/**
* @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 (Dbuff::validateKey($this->key)) {
return $this->key; /*int*/
}
throw new Exception('never get to this Dbuff::key');
}
/**
* @param int
* @return bool
* @throws Exception
*/
public static function validateKey(int $value): bool {
if (!is_integer($value)) {
throw new Exception("Attribute Error:Dbuff::key");
}
return true;
}
/**
* @throws Exception
* @return int
*/
public function getKey(): int {
if (Dbuff::validateKey($this->key)) {
return $this->key;
}
throw new Exception('never get to getKey Dbuff::key');
}
/**
* @return int
*/
public static function sampleKey(): int {
return 31; /*31:key*/
}
/**
* @param float $value
* @throws Exception
* @return float
*/
public static function fromValue(float $value): float {
return $value; /*float*/
}
/**
* @throws Exception
* @return float
*/
public function toValue(): float {
if (Dbuff::validateValue($this->value)) {
return $this->value; /*float*/
}
throw new Exception('never get to this Dbuff::value');
}
/**
* @param float
* @return bool
* @throws Exception
*/
public static function validateValue(float $value): bool {
if (!is_float($value) && !is_int($value)) {
throw new Exception("Attribute Error:Dbuff::value");
}
return true;
}
/**
* @throws Exception
* @return float
*/
public function getValue(): float {
if (Dbuff::validateValue($this->value)) {
return $this->value;
}
throw new Exception('never get to getValue Dbuff::value');
}
/**
* @return float
*/
public static function sampleValue(): float {
return 32.032; /*32:value*/
}
/**
* @throws Exception
* @return bool
*/
public function validate(): bool {
return Dbuff::validateKey($this->key)
|| Dbuff::validateValue($this->value);
}
/**
* @return stdClass
* @throws Exception
*/
public function to(): stdClass {
$out = new stdClass();
$out->{'_key'} = $this->toKey();
$out->{'_value'} = $this->toValue();
return $out;
}
/**
* @param stdClass $obj
* @return Dbuff
* @throws Exception
*/
public static function from(stdClass $obj): Dbuff {
return new Dbuff(
Dbuff::fromKey($obj->{'_key'})
,Dbuff::fromValue($obj->{'_value'})
);
}
/**
* @return Dbuff
*/
public static function sample(): Dbuff {
return new Dbuff(
Dbuff::sampleKey()
,Dbuff::sampleValue()
);
}
}
from dataclasses import dataclass
from typing import Any, 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 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()
@dataclass
class Dbuff:
key: int
value: float
@staticmethod
def from_dict(obj: Any) -> 'Dbuff':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
value = from_float(obj.get("_value"))
return Dbuff(key, value)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
result["_value"] = to_float(self.value)
return result
@dataclass
class SystemWideEffect:
key: int
dbuffs: list[Dbuff] | None = None
eligible_type_list_id: int | None = None
environment_type_id: int | None = None
@staticmethod
def from_dict(obj: Any) -> 'SystemWideEffect':
assert isinstance(obj, dict)
key = from_int(obj.get("_key"))
dbuffs = from_union([lambda x: from_list(Dbuff.from_dict, x), from_none], obj.get("dbuffs"))
eligible_type_list_id = from_union([from_int, from_none], obj.get("eligibleTypeListID"))
environment_type_id = from_union([from_int, from_none], obj.get("environmentTypeID"))
return SystemWideEffect(key, dbuffs, eligible_type_list_id, environment_type_id)
def to_dict(self) -> dict:
result: dict = {}
result["_key"] = from_int(self.key)
if self.dbuffs is not None:
result["dbuffs"] = from_union([lambda x: from_list(lambda x: to_class(Dbuff, x), x), from_none], self.dbuffs)
if self.eligible_type_list_id is not None:
result["eligibleTypeListID"] = from_union([from_int, from_none], self.eligible_type_list_id)
if self.environment_type_id is not None:
result["environmentTypeID"] = from_union([from_int, from_none], self.environment_type_id)
return result
def system_wide_effect_from_dict(s: Any) -> SystemWideEffect:
return SystemWideEffect.from_dict(s)
def system_wide_effect_to_dict(x: SystemWideEffect) -> Any:
return to_class(SystemWideEffect, x)
// To parse this data:
//
// import { Convert, SystemWideEffect } from "./SystemWideEffect";
//
// const systemWideEffect = Convert.toSystemWideEffect(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface SystemWideEffect {
_key: number;
dbuffs?: [Dbuff, ...Dbuff[]];
eligibleTypeListID?: number;
environmentTypeID?: number;
[property: string]: unknown;
}
export interface Dbuff {
_key: number;
_value: number;
[property: string]: unknown;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toSystemWideEffect(json: string): SystemWideEffect {
return cast(JSON.parse(json), r("SystemWideEffect"));
}
public static systemWideEffectToJson(value: SystemWideEffect): string {
return JSON.stringify(uncast(value, r("SystemWideEffect")), 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 = {
"SystemWideEffect": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "dbuffs", js: "dbuffs", typ: u(undefined, a(r("Dbuff"))) },
{ json: "eligibleTypeListID", js: "eligibleTypeListID", typ: u(undefined, 0) },
{ json: "environmentTypeID", js: "environmentTypeID", typ: u(undefined, 0) },
], "any"),
"Dbuff": o([
{ json: "_key", js: "_key", typ: 0 },
{ json: "_value", js: "_value", typ: 3.14 },
], "any"),
};