From f0595f43dcc417d4a010bcb29af0d796a9772d1c Mon Sep 17 00:00:00 2001 From: Michal Debski Date: Sun, 9 Dec 2018 08:27:41 +0100 Subject: [PATCH] Fix deserialization from object --- js/typedjson.js | 22 +++++++-- js/typedjson.js.map | 2 +- js/typedjson.min.js | 2 +- js/typedjson.min.js.map | 2 +- js/typedjson/helpers.d.ts | 1 + spec/just-json.spec.ts | 94 ++++++++++++++++++++++++++++++++++++ spec/parse-to-object.spec.ts | 58 ++++++++++++++++++++++ src/typedjson.ts | 10 ++-- src/typedjson/helpers.ts | 19 ++++++++ 9 files changed, 198 insertions(+), 12 deletions(-) create mode 100644 spec/just-json.spec.ts create mode 100644 spec/parse-to-object.spec.ts diff --git a/js/typedjson.js b/js/typedjson.js index 514933d..d8a4bc4 100644 --- a/js/typedjson.js +++ b/js/typedjson.js @@ -128,6 +128,20 @@ function isPrimitiveValue(obj) { function isObject(value) { return typeof value === "object"; } +function shouldOmitParseString(jsonStr, expectedType) { + var expectsTypesSerializedAsStrings = expectedType === String + || expectedType === ArrayBuffer + || expectedType === DataView; + var hasQuotes = jsonStr.length >= 2 && jsonStr[0] === '"' && jsonStr[jsonStr.length - 1] === '"'; + var isInteger = /^\d+$/.test(jsonStr.trim()); + return (expectsTypesSerializedAsStrings && !hasQuotes) || ((!hasQuotes && !isInteger) && expectedType === Date); +} +function parseToJSObject(json, expectedType) { + if (typeof json !== 'string' || shouldOmitParseString(json, expectedType)) { + return json; + } + return JSON.parse(json); +} /** * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B'). * @param A The supposed derived type. @@ -1435,7 +1449,7 @@ var typedjson_TypedJSON = /** @class */ (function () { */ TypedJSON.prototype.parse = function (object) { var _this = this; - var json = JSON.parse(object); + var json = parseToJSObject(object, this.rootConstructor); var rootMetadata = metadata_JsonObjectMetadata.getFromConstructor(this.rootConstructor); var result; var knownTypes = new Map(); @@ -1460,7 +1474,7 @@ var typedjson_TypedJSON = /** @class */ (function () { }; TypedJSON.prototype.parseAsArray = function (object, dimensions) { if (dimensions === void 0) { dimensions = 1; } - var json = JSON.parse(object); + var json = parseToJSObject(object, Array); if (json instanceof Array) { return this.deserializer.convertAsArray(json, { selfConstructor: Array, @@ -1477,7 +1491,7 @@ var typedjson_TypedJSON = /** @class */ (function () { return []; }; TypedJSON.prototype.parseAsSet = function (object) { - var json = JSON.parse(object); + var json = parseToJSObject(object, Set); // A Set is serialized as T[]. if (json instanceof Array) { return this.deserializer.convertAsSet(json, { @@ -1493,7 +1507,7 @@ var typedjson_TypedJSON = /** @class */ (function () { return new Set(); }; TypedJSON.prototype.parseAsMap = function (object, keyConstructor) { - var json = JSON.parse(object); + var json = parseToJSObject(object, Map); // A Set is serialized as T[]. if (json instanceof Array) { return this.deserializer.convertAsMap(json, { diff --git a/js/typedjson.js.map b/js/typedjson.js.map index d34f203..887ace1 100644 --- a/js/typedjson.js.map +++ b/js/typedjson.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://typedjson/webpack/universalModuleDefinition","webpack://typedjson/webpack/bootstrap","webpack://typedjson/./src/typedjson/helpers.ts","webpack://typedjson/./src/typedjson/metadata.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/typedjson/serializer.ts","webpack://typedjson/./src/typedjson/json-object.ts","webpack://typedjson/./src/typedjson/json-member.ts","webpack://typedjson/./src/typedjson/json-array-member.ts","webpack://typedjson/./src/typedjson/json-set-member.ts","webpack://typedjson/./src/typedjson/json-map-member.ts","webpack://typedjson/./src/typedjson.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA,yDAA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IAC/E,CAAC;IAEM,kCAAc,GAArB,UAAyB,MAAiB,EAAE,cAA8B;QAEtE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/F,CAAC;IAEO,kCAAc,GAAtB,UAAuB,YAAqC;QAA5D,iBAOC;QALG,IAAI,GAAG,GAAG,IAAI,GAAG,EAA4B,CAAC;QAE9C,YAAY,CAAC,MAAM,CAAC,cAAI,IAAI,WAAI,EAAJ,CAAI,CAAC,CAAC,OAAO,CAAC,cAAI,IAAI,UAAG,CAAC,GAAG,CAAC,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAtC,CAAsC,CAAC,CAAC;QAE1F,OAAO,GAAG,CAAC;IACf,CAAC;IACL,gBAAC;AAAD,CAAC;;AAEoD;AACA;AACW;AACJ;AACA","file":"typedjson.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"typedjson\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"typedjson\"] = factory();\n\telse\n\t\troot[\"typedjson\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","declare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport const METADATA_FIELD_KEY = \"__typedJsonJsonObjectMetadataInformation__\";\n\nexport function getDefaultValue(type: { new (): T }): T|undefined\n{\n switch (type as any)\n {\n case Number:\n return 0 as any;\n\n case String:\n return \"\" as any;\n\n case Boolean:\n return false as any;\n\n case Array:\n return [] as any;\n\n default:\n return undefined;\n }\n}\n\n/**\n * Determines whether the specified type is a type that can be passed on \"as-is\" into `JSON.stringify`.\n * Values of these types don't need special conversion.\n * @param ctor The constructor of the type (wrapper constructor for primitive types, e.g. `Number` for `number`).\n */\nexport function isDirectlySerializableNativeType(type: Function): boolean\n{\n return !!(~[Date, Number, String, Boolean].indexOf(type as any));\n}\n\nexport function isTypeTypedArray(type: Function): boolean\n{\n return !!(~[Float32Array, Float64Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array]\n .indexOf(type as any));\n}\n\nexport function isPrimitiveValue(obj: any): boolean\n{\n switch (typeof obj)\n {\n case \"string\":\n case \"number\":\n case \"boolean\":\n return true;\n default:\n return (obj instanceof String || obj instanceof Number || obj instanceof Boolean);\n }\n}\n\nexport function isObject(value: any): value is Object\n{\n return typeof value === \"object\";\n}\n\n/**\n * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B').\n * @param A The supposed derived type.\n * @param B The supposed base type.\n */\nexport function isSubtypeOf(A: Function, B: Function)\n{\n return A === B || A.prototype instanceof B;\n}\n\nexport function logError(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.error === \"function\")\n {\n console.error.apply(console, [message].concat(optionalParams));\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"ERROR: \" + message].concat(optionalParams));\n }\n}\n\nexport function logMessage(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [message].concat(optionalParams));\n }\n}\n\nexport function logWarning(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.warn === \"function\")\n {\n console.warn.apply(console, [message].concat(optionalParams));\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"WARNING: \" + message].concat(optionalParams));\n }\n}\n\n/**\n * Checks if the value is considered defined (not undefined and not null).\n * @param value\n */\nexport function isValueDefined(value: T): value is Exclude\n{\n return !(typeof value === \"undefined\" || value === null);\n}\n\nexport function isInstanceOf(value: any, constructor: Function): boolean\n{\n if (typeof value === \"number\")\n {\n return (constructor === Number);\n }\n else if (typeof value === \"string\")\n {\n return (constructor === String);\n }\n else if (typeof value === \"boolean\")\n {\n return (constructor === Boolean);\n }\n else if (isObject(value))\n {\n return (value instanceof constructor);\n }\n\n return false;\n}\n\nexport const isReflectMetadataSupported =\n (typeof Reflect === \"object\" && typeof Reflect.getMetadata === \"function\");\n\n/**\n * Gets the name of a function.\n * @param fn The function whose name to get.\n */\nexport function nameof(fn: Function & { name?: string })\n{\n if (typeof fn.name === \"string\")\n {\n return fn.name;\n }\n else\n {\n return \"undefined\";\n }\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\n\nexport interface JsonMemberMetadata\n{\n /** If set, a default value will be emitted for uninitialized members. */\n emitDefaultValue?: boolean;\n\n /** Member name as it appears in the serialized JSON. */\n name: string;\n\n /** Property or field key of the json member. */\n key: string;\n\n /** Constuctor (type) reference of the member. */\n ctor?: Function;\n\n /** If set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** If the json member is an array, map or set, sets member options of elements/values. Subsequent values define the types of nested arrays. */\n elementType?: Function[];\n\n /** If the json member is a map, sets member options of array keys. */\n keyType?: Function;\n\n /** Custom deserializer to use. */\n deserializer?: (json: any) => any;\n\n /** Custom serializer to use. */\n serializer?: (value: any) => any;\n}\n\nexport class JsonObjectMetadata\n{\n //#region Static\n /**\n * Gets the name of a class as it appears in a serialized JSON string.\n * @param ctor The constructor of a class (with or without jsonObject).\n */\n public static getJsonObjectName(ctor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(ctor);\n return metadata ? nameof(metadata.classType) : nameof(ctor);\n }\n\n /**\n * Gets jsonObject metadata information from a class.\n * @param ctor The constructor class.\n */\n public static getFromConstructor(ctor: Function): JsonObjectMetadata|undefined\n {\n const prototype = ctor.prototype;\n if (!prototype)\n {\n return;\n }\n\n let metadata: JsonObjectMetadata|undefined;\n if (prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // The class prototype contains own jsonObject metadata\n metadata = prototype[METADATA_FIELD_KEY];\n }\n\n // Ignore implicitly added jsonObject (through jsonMember)\n if (metadata && metadata.isExplicitlyMarked)\n {\n return metadata;\n }\n\n // In the end maybe it is something which we can handle directly\n if (JsonObjectMetadata.doesHandleWithoutAnnotation(ctor))\n {\n const primitiveMeta = new JsonObjectMetadata(ctor);\n primitiveMeta.isExplicitlyMarked = true;\n // we do not store the metadata here to not modify builtin prototype\n return primitiveMeta;\n }\n }\n\n /**\n * Gets the known type name of a jsonObject class for type hint.\n * @param constructor The constructor class.\n */\n public static getKnownTypeNameFromType(constructor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(constructor);\n return metadata ? nameof(metadata.classType) : nameof(constructor);\n }\n\n private static doesHandleWithoutAnnotation(ctor: Function): boolean\n {\n return isDirectlySerializableNativeType(ctor) || isTypeTypedArray(ctor)\n || ctor === DataView || ctor === ArrayBuffer;\n }\n //#endregion\n\n constructor(\n classType: Function,\n ) {\n this.classType = classType;\n }\n\n public dataMembers: Map = new Map();\n\n public knownTypes: Set = new Set();\n\n public knownTypeMethodName?: string;\n\n /** Gets or sets the constructor function for the jsonObject. */\n public classType: Function;\n\n /**\n * Indicates whether this class was explicitly annotated with @jsonObject\n * or implicitly by @jsonMember\n */\n public isExplicitlyMarked: boolean = false;\n\n /**\n * Indicates whether this type is handled without annotation. This is usually\n * used for the builtin types (except for Maps, Sets, and normal Arrays).\n */\n public isHandledWithoutAnnotation: boolean = false;\n\n /** Name used to encode polymorphic type */\n public name?: string;\n\n public onDeserializedMethodName?: string;\n\n public initializerCallback?: (sourceObject: Object, rawSourceObject: Object) => Object;\n}\n\nexport function injectMetadataInformation(constructor: IndexedObject, propKey: string | symbol, metadata: JsonMemberMetadata)\n{\n const decoratorName = `@jsonMember on ${nameof(constructor.constructor)}.${String(propKey)}`; // For error messages.\n let objectMetadata: JsonObjectMetadata;\n\n // When a property decorator is applied to a static member, 'constructor' is a constructor function.\n // See: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Decorators.md#property-decorators\n // ... and static members are not supported here, so abort.\n if (typeof constructor === \"function\")\n {\n logError(`${decoratorName}: cannot use a static property.`);\n return;\n }\n\n // Methods cannot be serialized.\n // @ts-ignore symbol indexing is not supported by ts\n if (typeof constructor[propKey] === \"function\")\n {\n logError(`${decoratorName}: cannot use a method property.`);\n return;\n }\n\n if (!metadata || (!metadata.ctor && !metadata.deserializer))\n {\n logError(`${decoratorName}: JsonMemberMetadata has unknown ctor.`);\n return;\n }\n\n // Add jsonObject metadata to 'constructor' if not yet exists ('constructor' is the prototype).\n // NOTE: this will not fire up custom serialization, as 'constructor' must be explicitly marked with '@jsonObject' as well.\n if (!constructor.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // No *own* metadata, create new.\n objectMetadata = new JsonObjectMetadata(constructor.constructor);\n\n // Inherit @JsonMembers from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = constructor[METADATA_FIELD_KEY];\n if (parentMetadata) // && !constructor.hasOwnProperty(Helpers.METADATA_FIELD_KEY)\n {\n parentMetadata.dataMembers.forEach((_metadata, _propKey) => objectMetadata.dataMembers.set(_propKey, _metadata));\n }\n\n // ('constructor' is the prototype of the involved class, metadata information is added to this class prototype).\n Object.defineProperty(constructor, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // JsonObjectMetadata already exists on 'constructor'.\n objectMetadata = constructor[METADATA_FIELD_KEY];\n }\n\n if (!metadata.deserializer)\n {\n // @ts-ignore above is a check (!deser && !ctor)\n objectMetadata.knownTypes.add(metadata.ctor);\n }\n\n if (metadata.keyType)\n objectMetadata.knownTypes.add(metadata.keyType);\n\n if (metadata.elementType)\n metadata.elementType.forEach(elemCtor => objectMetadata.knownTypes.add(elemCtor));\n\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\n/**\n * Utility class, converts a simple/untyped javascript object-tree to a typed object-tree.\n * It is used after parsing a JSON-string.\n */\nexport class Deserializer\n{\n private _typeResolver: (sourceObject: Object, knownTypes: Map) => Function|undefined;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeResolver = (sourceObject: any, knownTypes: Map) =>\n {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: (sourceObject: Object, knownTypes: Map) => Function)\n {\n if (typeof typeResolverCallback !== \"function\") throw new TypeError(\"'typeResolverCallback' is not a function.\");\n\n this._typeResolver = typeResolverCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n public convertAsObject(\n sourceObject: IndexedObject,\n sourceObjectTypeInfo: IScopeTypeInfo,\n objectName = \"object\",\n ) {\n if (typeof sourceObject !== \"object\" || sourceObject === null)\n {\n this._errorHandler(new TypeError(`Cannot deserialize ${objectName}: 'sourceObject' must be a defined object.`));\n return undefined;\n }\n\n let expectedSelfType = sourceObjectTypeInfo.selfConstructor;\n let sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(expectedSelfType);\n let knownTypeConstructors = sourceObjectTypeInfo.knownTypes;\n\n if (sourceObjectMetadata)\n {\n // Merge known types received from \"above\" with known types defined on the current type.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n\n // Check if a type-hint is available from the source object.\n let typeFromTypeHint = this._typeResolver(sourceObject, knownTypeConstructors);\n\n if (typeFromTypeHint)\n {\n // Check if type hint is a valid subtype of the expected source type.\n if (isSubtypeOf(typeFromTypeHint, expectedSelfType))\n {\n // Hell yes.\n expectedSelfType = typeFromTypeHint;\n sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(typeFromTypeHint);\n\n if (sourceObjectMetadata)\n {\n // Also merge new known types from subtype.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n }\n }\n\n if (sourceObjectMetadata && sourceObjectMetadata.isExplicitlyMarked)\n {\n const sourceMetadata = sourceObjectMetadata;\n // Strong-typed deserialization available, get to it.\n // First deserialize properties into a temporary object.\n const sourceObjectWithDeserializedProperties = {} as IndexedObject;\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((memberMetadata, propKey) =>\n {\n const memberValue = sourceObject[propKey];\n const memberNameForDebug = `${nameof(sourceMetadata.classType)}.${propKey}`;\n\n let revivedValue;\n if (memberMetadata.deserializer) {\n revivedValue = memberMetadata.deserializer(memberValue);\n } else if (memberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n memberValue,\n {\n selfConstructor: memberMetadata.ctor,\n elementConstructor: memberMetadata.elementType,\n keyConstructor: memberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n memberNameForDebug,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${memberNameForDebug} thers is`\n + ` no constructor nor deserlization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue))\n {\n sourceObjectWithDeserializedProperties[memberMetadata.key] = revivedValue;\n }\n else if (memberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${memberNameForDebug}'.`));\n }\n });\n\n // Next, instantiate target object.\n let targetObject: IndexedObject;\n\n if (typeof sourceObjectMetadata.initializerCallback === \"function\")\n {\n try\n {\n targetObject = sourceObjectMetadata.initializerCallback(\n sourceObjectWithDeserializedProperties,\n sourceObject,\n );\n\n // Check the validity of user-defined initializer callback.\n if (!targetObject)\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + ` 'initializer' function returned undefined/null`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected.`,\n );\n }\n else if (!(targetObject instanceof sourceObjectMetadata.classType))\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + `'initializer' returned '${nameof(targetObject.constructor)}'`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected,`\n + `and '${nameof(targetObject.constructor)}' is not a subtype of`\n + ` '${nameof(sourceObjectMetadata.classType)}'`,\n );\n }\n }\n catch (e)\n {\n this._errorHandler(e);\n return undefined;\n }\n }\n else\n {\n targetObject = this._instantiateType(expectedSelfType);\n }\n\n // Finally, assign deserialized properties to target object.\n Object.assign(targetObject, sourceObjectWithDeserializedProperties);\n\n // Call onDeserialized method (if any).\n if (sourceObjectMetadata.onDeserializedMethodName)\n {\n if (typeof (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n else\n {\n this._errorHandler(new TypeError(\n `onDeserialized callback '${nameof(sourceObjectMetadata.classType)}.${sourceObjectMetadata.onDeserializedMethodName}' is not a method.`\n ));\n }\n }\n\n return targetObject;\n }\n else\n {\n // Untyped deserialization into Object instance.\n let targetObject = {} as IndexedObject;\n\n Object.keys(sourceObject).forEach(sourceKey =>\n {\n targetObject[sourceKey] = this.convertSingleValue(sourceObject[sourceKey], {\n selfConstructor: sourceObject[sourceKey].constructor,\n knownTypes: sourceObjectTypeInfo.knownTypes,\n elementConstructor: sourceObjectTypeInfo.elementConstructor,\n keyConstructor: sourceObjectTypeInfo.keyConstructor\n }, sourceKey);\n });\n\n return targetObject;\n }\n }\n\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (!isValueDefined(sourceObject))\n {\n return sourceObject;\n }\n else if (this._isDirectlyDeserializableNativeType(expectedSelfType))\n {\n if (sourceObject.constructor === expectedSelfType)\n {\n return sourceObject;\n }\n else\n {\n throw new TypeError(this._makeTypeErrorMessage(nameof(expectedSelfType), sourceObject.constructor, memberName));\n }\n }\n else if (expectedSelfType === Date)\n {\n // Support for Date with ISO 8601 format, or with numeric timestamp (milliseconds elapsed since the Epoch).\n // ISO 8601 spec.: https://www.w3.org/TR/NOTE-datetime\n\n if (typeof sourceObject === \"string\" || (typeof sourceObject === \"number\" && sourceObject > 0))\n return new Date(sourceObject as any);\n else\n this._throwTypeMismatchError(\"Date\", \"an ISO-8601 string\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float32Array)\n {\n // Deserialize Float32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float32Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float64Array)\n {\n // Deserialize Float64Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float64Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float64Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8Array)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8ClampedArray)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8ClampedArray(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8ClampedArray\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint16Array)\n {\n // Deserialize Uint16Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint16Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint16Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint32Array)\n {\n // Deserialize Uint32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint32Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === ArrayBuffer)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToArrayBuffer(sourceObject);\n else\n this._throwTypeMismatchError(\"ArrayBuffer\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === DataView)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToDataView(sourceObject);\n else\n this._throwTypeMismatchError(\"DataView\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Array)\n {\n if (sourceObject instanceof Array)\n return this.convertAsArray(sourceObject, typeInfo, memberName);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (sourceObject instanceof Array)\n return this.convertAsSet(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (sourceObject instanceof Array)\n return this.convertAsMap(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Map\", \"a source array of key-value-pair objects\", srcTypeNameForDebug, memberName);\n }\n else if (sourceObject && typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n public convertAsArray(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\"): any[]\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return [];\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Array: missing constructor reference of Array elements.`));\n return [];\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n return sourceObject.map(element =>\n {\n // If an array element fails to deserialize, substitute with undefined. This is so that the original ordering is not interrupted by faulty\n // entries, as an Array is ordered.\n try\n {\n return this.convertSingleValue(element, elementTypeInfo);\n }\n catch (e)\n {\n this._errorHandler(e);\n\n // Keep filling the array here with undefined to keep original ordering.\n // Note: this is just aesthetics, not returning anything produces the same result.\n return undefined;\n }\n });\n }\n\n public convertAsSet(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return new Set();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Set: missing constructor reference of Set elements.`));\n return new Set();\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n let resultSet = new Set();\n\n sourceObject.forEach((element, i) =>\n {\n try\n {\n resultSet.add(this.convertSingleValue(element, elementTypeInfo, memberName + `[${i}]`));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n\n if (!typeInfo.keyConstructor)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing key constructor.`));\n return new Map();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing value constructor.`));\n return new Map();\n }\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.keyConstructor,\n knownTypes: typeInfo.knownTypes\n };\n\n let valueTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n let resultMap = new Map();\n\n sourceObject.forEach((element: any) =>\n {\n try\n {\n let key = this.convertSingleValue(element.key, keyTypeInfo);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(key, this.convertSingleValue(\n element.value, valueTypeInfo, `${memberName}[${key}]`,\n ));\n }\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Map is not ordered,\n // and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultMap;\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string = \"object\",\n ) {\n throw new TypeError(\n `Could not deserialize ${memberName} as ${targetType}:`\n + ` expected ${expectedSourceType}, got ${actualSourceType}.`,\n );\n }\n\n private _makeTypeErrorMessage(expectedType: Function | string, actualType: Function | string, memberName = \"object\")\n {\n let expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n let actualTypeName = (typeof actualType === \"function\") ? nameof(actualType) : actualType;\n\n return `Could not deserialize ${memberName}: expected '${expectedTypeName}', got '${actualTypeName}'.`;\n }\n\n private _instantiateType(ctor: any)\n {\n return new ctor();\n }\n\n private _mergeKnownTypes(...knownTypeMaps: Array>)\n {\n let result = new Map();\n\n knownTypeMaps.forEach(knownTypes =>\n {\n knownTypes.forEach((ctor, name) =>\n {\n if (this._nameResolver)\n {\n result.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n result.set(name, ctor);\n }\n });\n });\n\n return result;\n }\n\n private _createKnownTypesMap(knowTypes: Set)\n {\n const map = new Map();\n\n knowTypes.forEach(ctor =>\n {\n if (this._nameResolver)\n {\n map.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n const knownTypeMeta = JsonObjectMetadata.getFromConstructor(ctor);\n const name = knownTypeMeta && knownTypeMeta.isExplicitlyMarked && knownTypeMeta.name\n ? knownTypeMeta.name\n : ctor.name;\n map.set(name, ctor);\n }\n });\n\n return map;\n }\n\n private _isDirectlyDeserializableNativeType(ctor: any)\n {\n return ~([Number, String, Boolean].indexOf(ctor));\n }\n\n public convertNativeObject(sourceObject: any)\n {\n return sourceObject;\n }\n\n private _stringToArrayBuffer(str: string)\n {\n let buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\n let bufView = new Uint16Array(buf);\n\n for (let i = 0, strLen = str.length; i < strLen; i++)\n {\n bufView[i] = str.charCodeAt(i);\n }\n\n return buf;\n }\n\n private _stringToDataView(str: string)\n {\n return new DataView(this._stringToArrayBuffer(str));\n }\n}\n","import { nameof, logError, isValueDefined, isInstanceOf, isTypeTypedArray, isDirectlySerializableNativeType } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfType: Function;\n elementTypes?: Function[];\n keyType?: Function;\n}\n\nexport interface IScopeArrayTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Array;\n elementTypes: Function[];\n}\n\nfunction isArrayTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeArrayTypeInfo {\n return typeInfo.selfType === Array;\n}\n\nexport interface IScopeSetTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Set;\n elementTypes: [Function];\n}\n\nfunction isSetTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeSetTypeInfo {\n return typeInfo.selfType === Set;\n}\n\nexport interface IScopeMapTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Map;\n elementTypes: [Function];\n keyType: Function;\n}\n\nfunction isMapTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeMapTypeInfo {\n return typeInfo.selfType === Map;\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class instances, and so on) to an untyped javascript object (also\n * called \"simple javascript object\"), and emits any necessary type hints in the process (for polymorphism).\n *\n * The converted object tree is what will be given to `JSON.stringify` to convert to string as the last step, the serialization is basically like:\n *\n * (1) typed object-tree -> (2) simple JS object-tree -> (3) JSON-string\n */\nexport class Serializer\n{\n private _typeHintEmitter: (targetObject: IndexedObject, sourceObject: IndexedObject, expectedSourceType: Function, sourceTypeMetadata?: JsonObjectMetadata) => void;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeHintEmitter = (targetObject, sourceObject, expectedSourceType, sourceTypeMetadata?: JsonObjectMetadata) =>\n {\n // By default, we put a \"__type\" property on the output object if the actual object is not the same as the expected one, so that deserialization\n // will know what to deserialize into (given the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n const name = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n // TODO: Perhaps this can work correctly without string-literal access?\n // tslint:disable-next-line:no-string-literal\n targetObject[\"__type\"] = name;\n }\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setTypeHintEmitter(typeEmitterCallback: (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void)\n {\n if (typeof typeEmitterCallback !== \"function\")\n {\n throw new TypeError(\"'typeEmitterCallback' is not a function.\");\n }\n\n this._typeHintEmitter = typeEmitterCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n /**\n * Convert a value of any supported serializable type.\n * The value type will be detected, and the correct serialization method will be called.\n */\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName: string = \"object\"): any\n {\n if (!isValueDefined(sourceObject)) return;\n\n if (!isInstanceOf(sourceObject, typeInfo.selfType))\n {\n let expectedName = nameof(typeInfo.selfType);\n let actualName = nameof(sourceObject.constructor);\n\n this._errorHandler(new TypeError(`Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`));\n return;\n }\n\n if (isDirectlySerializableNativeType(typeInfo.selfType))\n {\n return sourceObject;\n }\n else if (typeInfo.selfType === ArrayBuffer)\n {\n return this.convertAsArrayBuffer(sourceObject);\n }\n else if (typeInfo.selfType === DataView)\n {\n return this.convertAsDataView(sourceObject);\n }\n else if (isArrayTypeInfo(typeInfo))\n {\n return this.convertAsArray(sourceObject, typeInfo.elementTypes, memberName);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName);\n }\n else if (isTypeTypedArray(typeInfo.selfType))\n {\n return this.convertAsTypedArray(sourceObject);\n }\n else if (typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple javascript object for serialization.\n */\n public convertAsObject(sourceObject: IndexedObject, typeInfo: IScopeTypeInfo, memberName?: string)\n {\n let sourceTypeMetadata: JsonObjectMetadata|undefined;\n let targetObject: IndexedObject;\n\n if (sourceObject.constructor !== typeInfo.selfType && sourceObject instanceof typeInfo.selfType)\n {\n // The source object is not of the expected type, but it is a valid subtype.\n // This is OK, and we'll proceed to gather object metadata from the subtype instead.\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(sourceObject.constructor);\n }\n else\n {\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(typeInfo.selfType);\n }\n\n if (sourceTypeMetadata)\n {\n const sourceMeta = sourceTypeMetadata;\n // Strong-typed serialization available.\n // We'll serialize by members that have been marked with @jsonMember (including array/set/map members), and perform recursive conversion on\n // each of them. The converted objects are put on the 'targetObject', which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n sourceTypeMetadata.dataMembers.forEach((memberMetadata) =>\n {\n if (memberMetadata.serializer) {\n targetObject[memberMetadata.name] =\n memberMetadata.serializer(sourceObject[memberMetadata.key]);\n } else if (memberMetadata.ctor) {\n targetObject[memberMetadata.name] = this.convertSingleValue(\n sourceObject[memberMetadata.key],\n {\n selfType: memberMetadata.ctor,\n elementTypes: memberMetadata.elementType,\n keyType: memberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${memberMetadata.key}`,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${memberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n });\n }\n else\n {\n // Untyped serialization, \"as-is\", we'll just pass the object on.\n // We'll clone the source object, because type hints are added to the object itself, and we don't want to modify to the original object.\n targetObject = { ...sourceObject };\n }\n\n // Add type-hint.\n this._typeHintEmitter(targetObject, sourceObject, typeInfo.selfType, sourceTypeMetadata);\n\n return targetObject;\n }\n\n /**\n * Performs the conversion of an array of typed objects (or primitive values) to an array of simple javascript objects (or primitive values) for\n * serialization.\n * @param expectedElementType The expected type of elements. If the array is supposed to be multi-dimensional, subsequent elements define lower dimensions.\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsArray(sourceObject: any[], expectedElementType: Function[], memberName = \"object\"): any[]\n {\n if (expectedElementType.length === 0 || !expectedElementType[0])\n throw new TypeError(`Could not serialize ${memberName} as Array: missing element type definition.`);\n\n // Check the type of each element, individually.\n // If at least one array element type is incorrect, we return undefined, which results in no value emitted during serialization.\n // This is so that invalid element types don't unexpectedly alter the ordering of other, valid elements, and that no unexpected undefined values are in\n // the emitted array.\n sourceObject.forEach((element, i) =>\n {\n if (!isInstanceOf(element, expectedElementType[0]))\n {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]: expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [], // For multidimensional arrays.\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(element => this.convertSingleValue(element, typeInfoForElements, memberName));\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @returns\n */\n public convertAsSet(sourceObject: Set, expectedElementType: Function, memberName = \"object\"): any[]\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Set: missing element type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n };\n\n // For debugging and error tracking.\n if (memberName) memberName += \"[]\";\n\n let resultArray: any[] = [];\n\n // Convert each element of the set, and put it into an output array.\n // The output array is the one serialized, as JSON.stringify does not support Set serialization. (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName);\n\n // Add to output if the source element was undefined, OR the converted element is defined. This will add intentionally undefined values to output,\n // but not values that became undefined DURING serializing (usually because of a type-error).\n if (!isValueDefined(element) || isValueDefined(resultElement))\n {\n resultArray.push(resultElement);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a map of typed objects (or primitive values) into an array of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsMap(sourceObject: Map, expectedKeyType: Function, expectedElementType: Function, memberName = \"object\"): Array<{ key: any, value: any }>\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing value type definition.`);\n\n if (!expectedKeyType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing key type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n elementTypes: [expectedElementType]\n };\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfType: expectedKeyType\n };\n\n if (memberName) memberName += \"[]\";\n\n let resultArray: Array<{ key: any, value: any }> = [];\n\n // Convert each *entry* in the map to a simple javascript object with key and value properties.\n sourceObject.forEach((value, key) =>\n {\n let resultKeyValuePairObj = {\n key: this.convertSingleValue(key, keyTypeInfo, memberName),\n value: this.convertSingleValue(value, elementTypeInfo, memberName)\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n if (isValueDefined(resultKeyValuePairObj.key) && isValueDefined(resultKeyValuePairObj.value))\n {\n resultArray.push(resultKeyValuePairObj);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a typed javascript array to a simple untyped javascript array.\n * This is needed because typed arrays are otherwise serialized as objects, so we'll end up with something like \"{ 0: 0, 1: 1, ... }\".\n *\n * @param sourceObject\n * @returns\n */\n public convertAsTypedArray(sourceObject: ArrayBufferView)\n {\n return Array.from(sourceObject as any);\n }\n\n /**\n * Performs the conversion of a raw ArrayBuffer to a string.\n */\n public convertAsArrayBuffer(buffer: ArrayBuffer)\n {\n // ArrayBuffer -> 16-bit character codes -> character array -> joined string.\n return Array.from(new Uint16Array(buffer)).map(charCode => String.fromCharCode(charCode)).join(\"\");\n }\n\n /**\n * Performs the conversion of DataView, converting its internal ArrayBuffer to a string and returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n}\n","import { Constructor, ParameterlessConstructor } from \"./types\";\nimport { METADATA_FIELD_KEY } from \"./helpers\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IJsonObjectOptionsBase\n{\n /**\n * An array of known types to recognize when encountering type-hints,\n * or the name of a static method used for determining known types.\n */\n knownTypes?: Function[] | string;\n\n /**\n * The name of a static or instance method to call when deserialization\n * of the object is completed.\n */\n onDeserialized?: string;\n\n /**\n * The name used to differentiate between different polymorphic types.\n */\n name?: string;\n}\n\nexport interface IJsonObjectOptionsWithInitializer extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer: (sourceObject: T, rawSourceObject: T) => T;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer?: (sourceObject: T, rawSourceObject: T) => T;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional settings. The 'initializer' setting must be specified.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptionsWithInitializer): (target: Constructor) => void;\n\n/**\n * Marks that a class is serializable using TypedJSON, with additional settings.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptions): (target: ParameterlessConstructor) => void;\n\n/**\n * Marks that a class with a parameterless constructor is serializable using TypedJSON.\n */\nexport function jsonObject(target: ParameterlessConstructor): void;\n\nexport function jsonObject(optionsOrTarget?: IJsonObjectOptions | Constructor\n): ((target: Constructor) => void) | void {\n let options: IJsonObjectOptions;\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n options = {};\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n options = optionsOrTarget || {};\n }\n\n function decorator(\n target: Function\n ): void {\n let objectMetadata: JsonObjectMetadata;\n\n // Create or obtain JsonObjectMetadata object.\n if (!target.prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // Target has no JsonObjectMetadata associated with it yet, create it now.\n objectMetadata = new JsonObjectMetadata(target);\n\n // Inherit json members and known types from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = target.prototype[METADATA_FIELD_KEY];\n if (parentMetadata)\n {\n parentMetadata.dataMembers\n .forEach((memberMetadata, propKey) =>\n objectMetadata.dataMembers.set(propKey, memberMetadata));\n parentMetadata.knownTypes\n .forEach((knownType) => objectMetadata.knownTypes.add(knownType));\n }\n\n Object.defineProperty(target.prototype, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // Target already has JsonObjectMetadata associated with it.\n objectMetadata = target.prototype[METADATA_FIELD_KEY];\n objectMetadata.classType = target;\n }\n\n // Fill JsonObjectMetadata.\n objectMetadata.isExplicitlyMarked = true;\n objectMetadata.onDeserializedMethodName = options.onDeserialized;\n // T extend Object so it is fine\n objectMetadata.initializerCallback = options.initializer as any;\n if (options.name)\n {\n objectMetadata.name = options.name;\n }\n\n // Obtain known-types.\n if (typeof options.knownTypes === \"string\")\n {\n objectMetadata.knownTypeMethodName = options.knownTypes;\n }\n else if (options.knownTypes instanceof Array)\n {\n options.knownTypes\n .filter(knownType => !!knownType)\n .forEach(knownType => objectMetadata.knownTypes.add(knownType));\n }\n }\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n decorator(optionsOrTarget);\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n return decorator;\n }\n}\n","import {\n nameof, logError, isReflectMetadataSupported, isValueDefined, logWarning, isSubtypeOf\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions\n{\n /**\n * Sets the constructor of the property.\n * Optional with ReflectDecorators.\n */\n constructor?: Function;\n\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted if the property is uninitialized/undefined. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name. */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property is part of the object when serializing, with additional options.\n * Omitting the 'constructor' option requires ReflectDecorators and that the property type is always explicitly declared.\n * @param options Additional options.\n */\nexport function jsonMember(options: IJsonMemberOptions): PropertyDecorator;\n\n/**\n * Specifies that a property is part of the object when serializing.\n * This call signature requires ReflectDecorators and that the property type is always explicitly declared.\n */\nexport function jsonMember(target: Object, propertyKey: string | symbol): void;\n\nexport function jsonMember(optionsOrTarget?: IJsonMemberOptions | Object, propKey?: string | symbol): PropertyDecorator | void\n{\n if (optionsOrTarget instanceof Object && (typeof propKey === \"string\" || typeof propKey === \"symbol\"))\n {\n const target = optionsOrTarget;\n // For error messages.\n const decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(propKey)}`;\n\n // jsonMember used directly, no additional information directly available besides target and propKey.\n // Obtain property constructor through ReflectDecorators.\n if (isReflectMetadataSupported)\n {\n const reflectPropCtor = Reflect.getMetadata(\"design:type\", target, propKey) as Function;\n\n if (!reflectPropCtor)\n {\n logError(`${decoratorName}: could not resolve detected property constructor at runtime.`);\n return;\n }\n\n if (isSpecialPropertyType(decoratorName, reflectPropCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: reflectPropCtor,\n key: propKey.toString(),\n name: propKey.toString(),\n });\n }\n else\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n else\n {\n // jsonMember used as a decorator factory.\n return (target: Object, _propKey: string | symbol) =>\n {\n let options: IJsonMemberOptions = optionsOrTarget || {};\n let propCtor: Function|undefined;\n let decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(_propKey)}`; // For error messages.\n\n if (options.hasOwnProperty(\"constructor\"))\n {\n if (!isValueDefined(options.constructor))\n {\n logError(`${decoratorName}: cannot resolve specified property constructor at runtime.`);\n return;\n }\n\n // Property constructor has been specified. Use ReflectDecorators (if available) to check whether that constructor is correct. Warn if not.\n if (isReflectMetadataSupported && !isSubtypeOf(options.constructor, Reflect.getMetadata(\"design:type\", target, _propKey)))\n {\n logWarning(`${decoratorName}: detected property type does not match 'constructor' option.`);\n }\n\n propCtor = options.constructor;\n }\n else\n {\n // Use ReflectDecorators to obtain property constructor.\n if (isReflectMetadataSupported)\n {\n propCtor = Reflect.getMetadata(\"design:type\", target, _propKey) as Function;\n\n if (!propCtor)\n {\n logError(`${decoratorName}: cannot resolve detected property constructor at runtime.`);\n return;\n }\n }\n else if (!options.deserializer)\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n\n if (isSpecialPropertyType(decoratorName, propCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, _propKey, {\n ctor: propCtor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: _propKey.toString(),\n name: options.name || _propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n }\n}\n\nfunction isSpecialPropertyType(decoratorName: string, propCtor?: Function)\n{\n if (propCtor === Array)\n {\n logError(`${decoratorName}: property is an Array. Use the jsonArrayMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Set)\n {\n logError(`${decoratorName}: property is a Set. Use the jsonSetMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Map)\n {\n logError(`${decoratorName}: property is a Map. Use the jsonMapMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n return false;\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, an empty array is emitted if the property is undefined/uninitialized. */\n emitDefaultValue?: boolean;\n\n /** Sets array dimensions (e.g. 1 for 'number[]' or 2 for 'number[][]'). Defaults to 1. */\n dimensions?: number;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property, of type array, is part of an object when serializing.\n * @param elementConstructor Constructor of array elements (e.g. 'Number' for 'number[]', or 'Date' for 'Date[]').\n * @param options Additional options.\n */\nexport function jsonArrayMember(elementConstructor: Function, options: IJsonArrayMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonArrayMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of array elements at runtime.`);\n return;\n }\n\n const dimensions = options.dimensions === undefined ? 1 : options.dimensions;\n if (!isNaN(dimensions) && dimensions < 1)\n {\n logError(`${decoratorName}: 'dimensions' option must be at least 1.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonArrayMember' has been used on an array.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Array)\n {\n logError(`${decoratorName}: property is not an Array.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n\nfunction createArrayElementType(elementCtor: Function, dimensions: number) {\n const elementTypes = new Array(dimensions).fill(Array, 0, -1);\n elementTypes[dimensions-1] = elementCtor;\n return elementTypes;\n}\n","import { nameof } from \"./helpers\";\nimport { IJsonMemberOptions } from \"./json-member\";\nimport { JsonMemberMetadata, JsonObjectMetadata, injectMetadataInformation } from \"./metadata\";\nimport * as Helpers from \"./helpers\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Set.\n * @param elementConstructor Constructor of set elements (e.g. 'Number' for Set or 'Date' for Set).\n * @param options Additional options.\n */\nexport function jsonSetMember(elementConstructor: Function, options: IJsonSetMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n var decoratorName = `@jsonSetMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n Helpers.logError(`${decoratorName}: could not resolve constructor of set elements at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonSetMember' has been used on a set. Warn if not.\n if (Helpers.isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n Helpers.logError(`${decoratorName}: property is not a Set.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Map.\n * @param keyConstructor Constructor of map keys (e.g. 'Number' for 'Map').\n * @param valueConstructor Constructor of map values (e.g. 'Date' for 'Map').\n * @param options Additional options.\n */\nexport function jsonMapMember(keyConstructor: Function, valueConstructor: Function, options: IJsonMapMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonMapMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof keyConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map keys at runtime.`);\n return;\n }\n\n if (typeof valueConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map values at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonMapMember' has been used on a map. Warn if not.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Map)\n {\n logError(`${decoratorName}: property is not a Map.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, logWarning } from './typedjson/helpers';\nimport { Constructor } from \"./typedjson/types\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { Serializer } from \"./typedjson/serializer\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\n\nexport interface ITypedJSONSettings\n{\n /**\n * Sets the handler callback to invoke on errors during serializing and deserializing.\n * Re-throwing errors in this function will halt serialization/deserialization.\n * The default behavior is to log errors to the console.\n */\n errorHandler?: (e: Error) => void;\n\n /**\n * Sets a callback that determines the constructor of the correct sub-type of polymorphic\n * objects while deserializing.\n * The default behavior is to read the type-name from the '__type' property of 'sourceObject',\n * and look it up in 'knownTypes'.\n * The constructor of the sub-type should be returned.\n */\n typeResolver?: (sourceObject: Object, knownTypes: Map) => Function;\n\n nameResolver?: (ctor: Function) => string;\n\n /**\n * Sets a callback that writes type-hints to serialized objects.\n * The default behavior is to write the type-name to the '__type' property, if a derived type\n * is present in place of a base type.\n */\n typeHintEmitter?:\n (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void;\n\n /**\n * Sets the amount of indentation to use in produced JSON strings.\n * Default value is 0, or no indentation.\n */\n indent?: number;\n\n replacer?: (key: string, value: any) => any;\n\n knownTypes?: Array>;\n}\n\nexport class TypedJSON\n{\n //#region Static\n public static parse(\n object: any, rootType: Constructor, settings?: ITypedJSONSettings,\n ): T|undefined {\n return new TypedJSON(rootType, settings).parse(object);\n }\n\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: 1\n ): T[];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 2\n ): T[][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 3\n ): T[][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 4\n ): T[][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 5\n ): T[][][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: number\n ): any[] {\n return new TypedJSON(elementType, settings).parseAsArray(object, dimensions as any);\n }\n\n public static parseAsSet(\n object: any, elementType: Constructor, settings?: ITypedJSONSettings,\n ): Set {\n return new TypedJSON(elementType, settings).parseAsSet(object);\n }\n\n public static parseAsMap(\n object: any,\n keyType: Constructor,\n valueType: Constructor,\n settings?: ITypedJSONSettings,\n ): Map {\n return new TypedJSON(valueType, settings).parseAsMap(object, keyType);\n }\n\n public static toPlainJson(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): JsonTypes {\n return new TypedJSON(rootType, settings).toPlainJson(object);\n }\n\n public static toPlainArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): Object[];\n public static toPlainArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): Object[][];\n public static toPlainArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): Object[][][];\n public static toPlainArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): Object[][][][];\n public static toPlainArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): Object[][][][][];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): any[];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): any[] {\n return new TypedJSON(elementType, settings).toPlainArray(object, dimensions);\n }\n\n public static toPlainSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n public static stringify(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(rootType, settings).stringify(object);\n }\n\n public static stringifyAsArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsArray(object, dimensions);\n }\n\n public static stringifyAsSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static stringifyAsMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n private static _globalConfig: ITypedJSONSettings;\n\n public static setGlobalConfig(config: ITypedJSONSettings)\n {\n if (this._globalConfig)\n {\n Object.assign(this._globalConfig, config);\n }\n else\n {\n this._globalConfig = config;\n }\n }\n\n //#endregion\n\n private serializer: Serializer = new Serializer();\n private deserializer: Deserializer = new Deserializer();\n private globalKnownTypes: Array> = [];\n private indent: number = 0;\n private rootConstructor: Constructor;\n private errorHandler: (e: Error) => void;\n private nameResolver: (ctor: Function) => string;\n private replacer?: (key: string, value: any) => any;\n\n /**\n * Creates a new TypedJSON instance to serialize (stringify) and deserialize (parse) object\n * instances of the specified root class type.\n * @param rootType The constructor of the root class type.\n * @param settings Additional configuration settings.\n */\n constructor(rootConstructor: Constructor, settings?: ITypedJSONSettings)\n {\n let rootMetadata = JsonObjectMetadata.getFromConstructor(rootConstructor);\n\n if (!rootMetadata || (!rootMetadata.isExplicitlyMarked && !rootMetadata.isHandledWithoutAnnotation))\n {\n throw new TypeError(\"The TypedJSON root data type must have the @jsonObject decorator used.\");\n }\n\n this.nameResolver = (ctor) => nameof(ctor);\n this.rootConstructor = rootConstructor;\n this.errorHandler = (error) => logError(error);\n\n if (settings)\n {\n this.config(settings);\n }\n else if (TypedJSON._globalConfig)\n {\n this.config({});\n }\n }\n\n /**\n * Configures TypedJSON through a settings object.\n * @param settings The configuration settings object.\n */\n public config(settings: ITypedJSONSettings)\n {\n if (TypedJSON._globalConfig)\n {\n settings = {\n ...TypedJSON._globalConfig,\n ...settings\n };\n\n if (settings.knownTypes && TypedJSON._globalConfig.knownTypes)\n {\n // Merge known-types (also de-duplicate them, so Array -> Set -> Array).\n settings.knownTypes = Array.from(new Set(\n settings.knownTypes.concat(TypedJSON._globalConfig.knownTypes),\n ));\n }\n }\n\n if (settings.errorHandler)\n {\n this.errorHandler = settings.errorHandler;\n this.deserializer.setErrorHandler(settings.errorHandler);\n this.serializer.setErrorHandler(settings.errorHandler);\n }\n\n if (settings.replacer) this.replacer = settings.replacer;\n if (settings.typeResolver) this.deserializer.setTypeResolver(settings.typeResolver);\n if (settings.typeHintEmitter) this.serializer.setTypeHintEmitter(settings.typeHintEmitter);\n if (settings.indent) this.indent = settings.indent;\n\n if (settings.nameResolver)\n {\n this.nameResolver = settings.nameResolver;\n this.deserializer.setNameResolver(settings.nameResolver);\n // this.serializer.set\n }\n\n if (settings.knownTypes)\n {\n // Type-check knownTypes elements to recognize errors in advance.\n settings.knownTypes.forEach((knownType, i) =>\n {\n // tslint:disable-next-line:no-null-keyword\n if (typeof knownType === \"undefined\" || knownType === null)\n {\n logWarning(\n `TypedJSON.config: 'knownTypes' contains an undefined/null value (element ${i}).`);\n }\n });\n\n this.globalKnownTypes = settings.knownTypes;\n }\n }\n\n /**\n * Converts a JSON string to the root class type.\n * @param object The JSON to parse and convert.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns Deserialized T or undefined if there were errors.\n */\n public parse(object: any): T|undefined\n {\n const json = JSON.parse(object);\n\n let rootMetadata = JsonObjectMetadata.getFromConstructor(this.rootConstructor);\n let result: T|undefined;\n let knownTypes = new Map();\n\n this.globalKnownTypes.filter(ktc => ktc).forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n\n if (rootMetadata)\n {\n rootMetadata.knownTypes.forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n }\n\n try\n {\n result = this.deserializer.convertSingleValue(json, {\n selfConstructor: this.rootConstructor,\n knownTypes: knownTypes,\n }) as T;\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n\n return result;\n }\n\n public parseAsArray(object: any, dimensions?: 1): T[];\n public parseAsArray(object: any, dimensions: 2): T[][];\n public parseAsArray(object: any, dimensions: 3): T[][][];\n public parseAsArray(object: any, dimensions: 4): T[][][][];\n public parseAsArray(object: any, dimensions: 5): T[][][][][];\n public parseAsArray(object: any, dimensions: number): any[];\n public parseAsArray(object: any, dimensions: number = 1): any[]\n {\n const json = JSON.parse(object);\n if (json instanceof Array)\n {\n return this.deserializer.convertAsArray(json, {\n selfConstructor: Array,\n elementConstructor: new Array(dimensions - 1)\n .fill(Array)\n .concat(this.rootConstructor),\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define an Array`\n + `, but got ${typeof json}.`));\n }\n\n return [];\n }\n\n public parseAsSet(object: any): Set\n {\n const json = JSON.parse(object);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsSet(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes)\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Set();\n }\n\n public parseAsMap(object: any, keyConstructor: Constructor): Map\n {\n const json = JSON.parse(object);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsMap(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n keyConstructor: keyConstructor\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Map();\n }\n\n /**\n * Converts an instance of the specified class type to a plain JSON object.\n * @param object The instance to convert to a JSON string.\n * @returns Serialized object or undefined if an error has occured.\n */\n public toPlainJson(object: T): JsonTypes\n {\n try\n {\n return this.serializer.convertSingleValue(object, {\n selfType: this.rootConstructor\n });\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainArray(object: T[], dimensions?: 1): Object[];\n public toPlainArray(object: T[][], dimensions: 2): Object[][];\n public toPlainArray(object: T[][][], dimensions: 3): Object[][][];\n public toPlainArray(object: T[][][][], dimensions: 4): Object[][][][];\n public toPlainArray(object: T[][][][][], dimensions: 5): Object[][][][][];\n public toPlainArray(object: any[], dimensions: 1|2|3|4|5 = 1): Object[]|undefined\n {\n try\n {\n const elementConstructorArray =\n new Array(dimensions - 1).fill(Array).concat(this.rootConstructor);\n return this.serializer.convertAsArray(object, elementConstructorArray);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainSet(object: Set): Object[]|undefined\n {\n try\n {\n return this.serializer.convertAsSet(object, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainMap(object: Map, keyConstructor: Constructor): { key: any, value: any }[]|undefined\n {\n try\n {\n return this.serializer.convertAsMap(object, keyConstructor, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n /**\n * Converts an instance of the specified class type to a JSON string.\n * @param object The instance to convert to a JSON string.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns String with the serialized object or an empty string if an error has occured, but\n * the errorHandler did not throw.\n */\n public stringify(object: T): string\n {\n const result = this.toPlainJson(object);\n if (result === undefined) {\n return '';\n }\n return JSON.stringify(result, this.replacer, this.indent);\n }\n\n public stringifyAsArray(object: T[], dimensions?: 1): string;\n public stringifyAsArray(object: T[][], dimensions: 2): string;\n public stringifyAsArray(object: T[][][], dimensions: 3): string;\n public stringifyAsArray(object: T[][][][], dimensions: 4): string;\n public stringifyAsArray(object: T[][][][][], dimensions: 5): string;\n public stringifyAsArray(object: any[], dimensions: any): string\n {\n return JSON.stringify(this.toPlainArray(object, dimensions), this.replacer, this.indent);\n }\n\n public stringifyAsSet(object: Set): string\n {\n return JSON.stringify(this.toPlainSet(object), this.replacer, this.indent);\n }\n\n public stringifyAsMap(object: Map, keyConstructor: Constructor): string\n {\n return JSON.stringify(this.toPlainMap(object, keyConstructor), this.replacer, this.indent);\n }\n\n private _mapKnownTypes(constructors: Array>)\n {\n let map = new Map>();\n\n constructors.filter(ctor => ctor).forEach(ctor => map.set(this.nameResolver(ctor), ctor));\n\n return map;\n }\n}\n\nexport { jsonObject } from \"./typedjson/json-object\";\nexport { jsonMember } from \"./typedjson/json-member\";\nexport { jsonArrayMember } from \"./typedjson/json-array-member\";\nexport { jsonSetMember } from \"./typedjson/json-set-member\";\nexport { jsonMapMember } from \"./typedjson/json-map-member\";\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://typedjson/webpack/universalModuleDefinition","webpack://typedjson/webpack/bootstrap","webpack://typedjson/./src/typedjson/helpers.ts","webpack://typedjson/./src/typedjson/metadata.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/typedjson/serializer.ts","webpack://typedjson/./src/typedjson/json-object.ts","webpack://typedjson/./src/typedjson/json-member.ts","webpack://typedjson/./src/typedjson/json-array-member.ts","webpack://typedjson/./src/typedjson/json-set-member.ts","webpack://typedjson/./src/typedjson/json-map-member.ts","webpack://typedjson/./src/typedjson.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;AC9DO,IAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAEzE,yBAA6B,IAAmB;IAElD,QAAQ,IAAW,EACnB;QACI,KAAK,MAAM;YACP,OAAO,CAAQ,CAAC;QAEpB,KAAK,MAAM;YACP,OAAO,EAAS,CAAC;QAErB,KAAK,OAAO;YACR,OAAO,KAAY,CAAC;QAExB,KAAK,KA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C9D,CAAC;IAOM,oCAAgB,GAAvB,UAAwB,MAAa,EAAE,UAAe;QAElD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7F,CAAC;IAEM,kCAAc,GAArB,UAAsB,MAAc;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/E,CAAC;IAEM,kCAAc,GAArB,UAAyB,MAAiB,EAAE,cAA8B;QAEtE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/F,CAAC;IAEO,kCAAc,GAAtB,UAAuB,YAAqC;QAA5D,iBAOC;QALG,IAAI,GAAG,GAAG,IAAI,GAAG,EAA4B,CAAC;QAE9C,YAAY,CAAC,MAAM,CAAC,cAAI,IAAI,WAAI,EAAJ,CAAI,CAAC,CAAC,OAAO,CAAC,cAAI,IAAI,UAAG,CAAC,GAAG,CAAC,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAtC,CAAsC,CAAC,CAAC;QAE1F,OAAO,GAAG,CAAC;IACf,CAAC;IACL,gBAAC;AAAD,CAAC;;AAEoD;AACA;AACW;AACJ;AACA","file":"typedjson.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"typedjson\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"typedjson\"] = factory();\n\telse\n\t\troot[\"typedjson\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","declare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport const METADATA_FIELD_KEY = \"__typedJsonJsonObjectMetadataInformation__\";\n\nexport function getDefaultValue(type: { new (): T }): T|undefined\n{\n switch (type as any)\n {\n case Number:\n return 0 as any;\n\n case String:\n return \"\" as any;\n\n case Boolean:\n return false as any;\n\n case Array:\n return [] as any;\n\n default:\n return undefined;\n }\n}\n\n/**\n * Determines whether the specified type is a type that can be passed on \"as-is\" into `JSON.stringify`.\n * Values of these types don't need special conversion.\n * @param ctor The constructor of the type (wrapper constructor for primitive types, e.g. `Number` for `number`).\n */\nexport function isDirectlySerializableNativeType(type: Function): boolean\n{\n return !!(~[Date, Number, String, Boolean].indexOf(type as any));\n}\n\nexport function isTypeTypedArray(type: Function): boolean\n{\n return !!(~[Float32Array, Float64Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array]\n .indexOf(type as any));\n}\n\nexport function isPrimitiveValue(obj: any): boolean\n{\n switch (typeof obj)\n {\n case \"string\":\n case \"number\":\n case \"boolean\":\n return true;\n default:\n return (obj instanceof String || obj instanceof Number || obj instanceof Boolean);\n }\n}\n\nexport function isObject(value: any): value is Object\n{\n return typeof value === \"object\";\n}\n\nfunction shouldOmitParseString(jsonStr: string, expectedType: Function): boolean {\n const expectsTypesSerializedAsStrings = expectedType === String\n || expectedType === ArrayBuffer\n || expectedType === DataView;\n\n const hasQuotes = jsonStr.length >= 2 && jsonStr[0] === '\"' && jsonStr[jsonStr.length-1] === '\"';\n const isInteger = /^\\d+$/.test(jsonStr.trim());\n\n return (expectsTypesSerializedAsStrings && !hasQuotes) || ((!hasQuotes && !isInteger) && expectedType === Date);\n}\n\nexport function parseToJSObject(json: any, expectedType: Function): Object {\n if (typeof json !== 'string' || shouldOmitParseString(json, expectedType))\n {\n return json;\n }\n return JSON.parse(json);\n}\n\n/**\n * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B').\n * @param A The supposed derived type.\n * @param B The supposed base type.\n */\nexport function isSubtypeOf(A: Function, B: Function)\n{\n return A === B || A.prototype instanceof B;\n}\n\nexport function logError(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.error === \"function\")\n {\n console.error.apply(console, [message].concat(optionalParams));\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"ERROR: \" + message].concat(optionalParams));\n }\n}\n\nexport function logMessage(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [message].concat(optionalParams));\n }\n}\n\nexport function logWarning(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.warn === \"function\")\n {\n console.warn.apply(console, [message].concat(optionalParams));\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"WARNING: \" + message].concat(optionalParams));\n }\n}\n\n/**\n * Checks if the value is considered defined (not undefined and not null).\n * @param value\n */\nexport function isValueDefined(value: T): value is Exclude\n{\n return !(typeof value === \"undefined\" || value === null);\n}\n\nexport function isInstanceOf(value: any, constructor: Function): boolean\n{\n if (typeof value === \"number\")\n {\n return (constructor === Number);\n }\n else if (typeof value === \"string\")\n {\n return (constructor === String);\n }\n else if (typeof value === \"boolean\")\n {\n return (constructor === Boolean);\n }\n else if (isObject(value))\n {\n return (value instanceof constructor);\n }\n\n return false;\n}\n\nexport const isReflectMetadataSupported =\n (typeof Reflect === \"object\" && typeof Reflect.getMetadata === \"function\");\n\n/**\n * Gets the name of a function.\n * @param fn The function whose name to get.\n */\nexport function nameof(fn: Function & { name?: string })\n{\n if (typeof fn.name === \"string\")\n {\n return fn.name;\n }\n else\n {\n return \"undefined\";\n }\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\n\nexport interface JsonMemberMetadata\n{\n /** If set, a default value will be emitted for uninitialized members. */\n emitDefaultValue?: boolean;\n\n /** Member name as it appears in the serialized JSON. */\n name: string;\n\n /** Property or field key of the json member. */\n key: string;\n\n /** Constuctor (type) reference of the member. */\n ctor?: Function;\n\n /** If set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** If the json member is an array, map or set, sets member options of elements/values. Subsequent values define the types of nested arrays. */\n elementType?: Function[];\n\n /** If the json member is a map, sets member options of array keys. */\n keyType?: Function;\n\n /** Custom deserializer to use. */\n deserializer?: (json: any) => any;\n\n /** Custom serializer to use. */\n serializer?: (value: any) => any;\n}\n\nexport class JsonObjectMetadata\n{\n //#region Static\n /**\n * Gets the name of a class as it appears in a serialized JSON string.\n * @param ctor The constructor of a class (with or without jsonObject).\n */\n public static getJsonObjectName(ctor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(ctor);\n return metadata ? nameof(metadata.classType) : nameof(ctor);\n }\n\n /**\n * Gets jsonObject metadata information from a class.\n * @param ctor The constructor class.\n */\n public static getFromConstructor(ctor: Function): JsonObjectMetadata|undefined\n {\n const prototype = ctor.prototype;\n if (!prototype)\n {\n return;\n }\n\n let metadata: JsonObjectMetadata|undefined;\n if (prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // The class prototype contains own jsonObject metadata\n metadata = prototype[METADATA_FIELD_KEY];\n }\n\n // Ignore implicitly added jsonObject (through jsonMember)\n if (metadata && metadata.isExplicitlyMarked)\n {\n return metadata;\n }\n\n // In the end maybe it is something which we can handle directly\n if (JsonObjectMetadata.doesHandleWithoutAnnotation(ctor))\n {\n const primitiveMeta = new JsonObjectMetadata(ctor);\n primitiveMeta.isExplicitlyMarked = true;\n // we do not store the metadata here to not modify builtin prototype\n return primitiveMeta;\n }\n }\n\n /**\n * Gets the known type name of a jsonObject class for type hint.\n * @param constructor The constructor class.\n */\n public static getKnownTypeNameFromType(constructor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(constructor);\n return metadata ? nameof(metadata.classType) : nameof(constructor);\n }\n\n private static doesHandleWithoutAnnotation(ctor: Function): boolean\n {\n return isDirectlySerializableNativeType(ctor) || isTypeTypedArray(ctor)\n || ctor === DataView || ctor === ArrayBuffer;\n }\n //#endregion\n\n constructor(\n classType: Function,\n ) {\n this.classType = classType;\n }\n\n public dataMembers: Map = new Map();\n\n public knownTypes: Set = new Set();\n\n public knownTypeMethodName?: string;\n\n /** Gets or sets the constructor function for the jsonObject. */\n public classType: Function;\n\n /**\n * Indicates whether this class was explicitly annotated with @jsonObject\n * or implicitly by @jsonMember\n */\n public isExplicitlyMarked: boolean = false;\n\n /**\n * Indicates whether this type is handled without annotation. This is usually\n * used for the builtin types (except for Maps, Sets, and normal Arrays).\n */\n public isHandledWithoutAnnotation: boolean = false;\n\n /** Name used to encode polymorphic type */\n public name?: string;\n\n public onDeserializedMethodName?: string;\n\n public initializerCallback?: (sourceObject: Object, rawSourceObject: Object) => Object;\n}\n\nexport function injectMetadataInformation(constructor: IndexedObject, propKey: string | symbol, metadata: JsonMemberMetadata)\n{\n const decoratorName = `@jsonMember on ${nameof(constructor.constructor)}.${String(propKey)}`; // For error messages.\n let objectMetadata: JsonObjectMetadata;\n\n // When a property decorator is applied to a static member, 'constructor' is a constructor function.\n // See: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Decorators.md#property-decorators\n // ... and static members are not supported here, so abort.\n if (typeof constructor === \"function\")\n {\n logError(`${decoratorName}: cannot use a static property.`);\n return;\n }\n\n // Methods cannot be serialized.\n // @ts-ignore symbol indexing is not supported by ts\n if (typeof constructor[propKey] === \"function\")\n {\n logError(`${decoratorName}: cannot use a method property.`);\n return;\n }\n\n if (!metadata || (!metadata.ctor && !metadata.deserializer))\n {\n logError(`${decoratorName}: JsonMemberMetadata has unknown ctor.`);\n return;\n }\n\n // Add jsonObject metadata to 'constructor' if not yet exists ('constructor' is the prototype).\n // NOTE: this will not fire up custom serialization, as 'constructor' must be explicitly marked with '@jsonObject' as well.\n if (!constructor.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // No *own* metadata, create new.\n objectMetadata = new JsonObjectMetadata(constructor.constructor);\n\n // Inherit @JsonMembers from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = constructor[METADATA_FIELD_KEY];\n if (parentMetadata) // && !constructor.hasOwnProperty(Helpers.METADATA_FIELD_KEY)\n {\n parentMetadata.dataMembers.forEach((_metadata, _propKey) => objectMetadata.dataMembers.set(_propKey, _metadata));\n }\n\n // ('constructor' is the prototype of the involved class, metadata information is added to this class prototype).\n Object.defineProperty(constructor, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // JsonObjectMetadata already exists on 'constructor'.\n objectMetadata = constructor[METADATA_FIELD_KEY];\n }\n\n if (!metadata.deserializer)\n {\n // @ts-ignore above is a check (!deser && !ctor)\n objectMetadata.knownTypes.add(metadata.ctor);\n }\n\n if (metadata.keyType)\n objectMetadata.knownTypes.add(metadata.keyType);\n\n if (metadata.elementType)\n metadata.elementType.forEach(elemCtor => objectMetadata.knownTypes.add(elemCtor));\n\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\n/**\n * Utility class, converts a simple/untyped javascript object-tree to a typed object-tree.\n * It is used after parsing a JSON-string.\n */\nexport class Deserializer\n{\n private _typeResolver: (sourceObject: Object, knownTypes: Map) => Function|undefined;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeResolver = (sourceObject: any, knownTypes: Map) =>\n {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: (sourceObject: Object, knownTypes: Map) => Function)\n {\n if (typeof typeResolverCallback !== \"function\") throw new TypeError(\"'typeResolverCallback' is not a function.\");\n\n this._typeResolver = typeResolverCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n public convertAsObject(\n sourceObject: IndexedObject,\n sourceObjectTypeInfo: IScopeTypeInfo,\n objectName = \"object\",\n ) {\n if (typeof sourceObject !== \"object\" || sourceObject === null)\n {\n this._errorHandler(new TypeError(`Cannot deserialize ${objectName}: 'sourceObject' must be a defined object.`));\n return undefined;\n }\n\n let expectedSelfType = sourceObjectTypeInfo.selfConstructor;\n let sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(expectedSelfType);\n let knownTypeConstructors = sourceObjectTypeInfo.knownTypes;\n\n if (sourceObjectMetadata)\n {\n // Merge known types received from \"above\" with known types defined on the current type.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n\n // Check if a type-hint is available from the source object.\n let typeFromTypeHint = this._typeResolver(sourceObject, knownTypeConstructors);\n\n if (typeFromTypeHint)\n {\n // Check if type hint is a valid subtype of the expected source type.\n if (isSubtypeOf(typeFromTypeHint, expectedSelfType))\n {\n // Hell yes.\n expectedSelfType = typeFromTypeHint;\n sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(typeFromTypeHint);\n\n if (sourceObjectMetadata)\n {\n // Also merge new known types from subtype.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n }\n }\n\n if (sourceObjectMetadata && sourceObjectMetadata.isExplicitlyMarked)\n {\n const sourceMetadata = sourceObjectMetadata;\n // Strong-typed deserialization available, get to it.\n // First deserialize properties into a temporary object.\n const sourceObjectWithDeserializedProperties = {} as IndexedObject;\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((memberMetadata, propKey) =>\n {\n const memberValue = sourceObject[propKey];\n const memberNameForDebug = `${nameof(sourceMetadata.classType)}.${propKey}`;\n\n let revivedValue;\n if (memberMetadata.deserializer) {\n revivedValue = memberMetadata.deserializer(memberValue);\n } else if (memberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n memberValue,\n {\n selfConstructor: memberMetadata.ctor,\n elementConstructor: memberMetadata.elementType,\n keyConstructor: memberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n memberNameForDebug,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${memberNameForDebug} thers is`\n + ` no constructor nor deserlization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue))\n {\n sourceObjectWithDeserializedProperties[memberMetadata.key] = revivedValue;\n }\n else if (memberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${memberNameForDebug}'.`));\n }\n });\n\n // Next, instantiate target object.\n let targetObject: IndexedObject;\n\n if (typeof sourceObjectMetadata.initializerCallback === \"function\")\n {\n try\n {\n targetObject = sourceObjectMetadata.initializerCallback(\n sourceObjectWithDeserializedProperties,\n sourceObject,\n );\n\n // Check the validity of user-defined initializer callback.\n if (!targetObject)\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + ` 'initializer' function returned undefined/null`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected.`,\n );\n }\n else if (!(targetObject instanceof sourceObjectMetadata.classType))\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + `'initializer' returned '${nameof(targetObject.constructor)}'`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected,`\n + `and '${nameof(targetObject.constructor)}' is not a subtype of`\n + ` '${nameof(sourceObjectMetadata.classType)}'`,\n );\n }\n }\n catch (e)\n {\n this._errorHandler(e);\n return undefined;\n }\n }\n else\n {\n targetObject = this._instantiateType(expectedSelfType);\n }\n\n // Finally, assign deserialized properties to target object.\n Object.assign(targetObject, sourceObjectWithDeserializedProperties);\n\n // Call onDeserialized method (if any).\n if (sourceObjectMetadata.onDeserializedMethodName)\n {\n if (typeof (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n else\n {\n this._errorHandler(new TypeError(\n `onDeserialized callback '${nameof(sourceObjectMetadata.classType)}.${sourceObjectMetadata.onDeserializedMethodName}' is not a method.`\n ));\n }\n }\n\n return targetObject;\n }\n else\n {\n // Untyped deserialization into Object instance.\n let targetObject = {} as IndexedObject;\n\n Object.keys(sourceObject).forEach(sourceKey =>\n {\n targetObject[sourceKey] = this.convertSingleValue(sourceObject[sourceKey], {\n selfConstructor: sourceObject[sourceKey].constructor,\n knownTypes: sourceObjectTypeInfo.knownTypes,\n elementConstructor: sourceObjectTypeInfo.elementConstructor,\n keyConstructor: sourceObjectTypeInfo.keyConstructor\n }, sourceKey);\n });\n\n return targetObject;\n }\n }\n\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (!isValueDefined(sourceObject))\n {\n return sourceObject;\n }\n else if (this._isDirectlyDeserializableNativeType(expectedSelfType))\n {\n if (sourceObject.constructor === expectedSelfType)\n {\n return sourceObject;\n }\n else\n {\n throw new TypeError(this._makeTypeErrorMessage(nameof(expectedSelfType), sourceObject.constructor, memberName));\n }\n }\n else if (expectedSelfType === Date)\n {\n // Support for Date with ISO 8601 format, or with numeric timestamp (milliseconds elapsed since the Epoch).\n // ISO 8601 spec.: https://www.w3.org/TR/NOTE-datetime\n\n if (typeof sourceObject === \"string\" || (typeof sourceObject === \"number\" && sourceObject > 0))\n return new Date(sourceObject as any);\n else\n this._throwTypeMismatchError(\"Date\", \"an ISO-8601 string\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float32Array)\n {\n // Deserialize Float32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float32Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float64Array)\n {\n // Deserialize Float64Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float64Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float64Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8Array)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8ClampedArray)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8ClampedArray(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8ClampedArray\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint16Array)\n {\n // Deserialize Uint16Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint16Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint16Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint32Array)\n {\n // Deserialize Uint32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint32Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === ArrayBuffer)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToArrayBuffer(sourceObject);\n else\n this._throwTypeMismatchError(\"ArrayBuffer\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === DataView)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToDataView(sourceObject);\n else\n this._throwTypeMismatchError(\"DataView\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Array)\n {\n if (sourceObject instanceof Array)\n return this.convertAsArray(sourceObject, typeInfo, memberName);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (sourceObject instanceof Array)\n return this.convertAsSet(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (sourceObject instanceof Array)\n return this.convertAsMap(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Map\", \"a source array of key-value-pair objects\", srcTypeNameForDebug, memberName);\n }\n else if (sourceObject && typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n public convertAsArray(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\"): any[]\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return [];\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Array: missing constructor reference of Array elements.`));\n return [];\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n return sourceObject.map(element =>\n {\n // If an array element fails to deserialize, substitute with undefined. This is so that the original ordering is not interrupted by faulty\n // entries, as an Array is ordered.\n try\n {\n return this.convertSingleValue(element, elementTypeInfo);\n }\n catch (e)\n {\n this._errorHandler(e);\n\n // Keep filling the array here with undefined to keep original ordering.\n // Note: this is just aesthetics, not returning anything produces the same result.\n return undefined;\n }\n });\n }\n\n public convertAsSet(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return new Set();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Set: missing constructor reference of Set elements.`));\n return new Set();\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n let resultSet = new Set();\n\n sourceObject.forEach((element, i) =>\n {\n try\n {\n resultSet.add(this.convertSingleValue(element, elementTypeInfo, memberName + `[${i}]`));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n\n if (!typeInfo.keyConstructor)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing key constructor.`));\n return new Map();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing value constructor.`));\n return new Map();\n }\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.keyConstructor,\n knownTypes: typeInfo.knownTypes\n };\n\n let valueTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n let resultMap = new Map();\n\n sourceObject.forEach((element: any) =>\n {\n try\n {\n let key = this.convertSingleValue(element.key, keyTypeInfo);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(key, this.convertSingleValue(\n element.value, valueTypeInfo, `${memberName}[${key}]`,\n ));\n }\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Map is not ordered,\n // and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultMap;\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string = \"object\",\n ) {\n throw new TypeError(\n `Could not deserialize ${memberName} as ${targetType}:`\n + ` expected ${expectedSourceType}, got ${actualSourceType}.`,\n );\n }\n\n private _makeTypeErrorMessage(expectedType: Function | string, actualType: Function | string, memberName = \"object\")\n {\n let expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n let actualTypeName = (typeof actualType === \"function\") ? nameof(actualType) : actualType;\n\n return `Could not deserialize ${memberName}: expected '${expectedTypeName}', got '${actualTypeName}'.`;\n }\n\n private _instantiateType(ctor: any)\n {\n return new ctor();\n }\n\n private _mergeKnownTypes(...knownTypeMaps: Array>)\n {\n let result = new Map();\n\n knownTypeMaps.forEach(knownTypes =>\n {\n knownTypes.forEach((ctor, name) =>\n {\n if (this._nameResolver)\n {\n result.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n result.set(name, ctor);\n }\n });\n });\n\n return result;\n }\n\n private _createKnownTypesMap(knowTypes: Set)\n {\n const map = new Map();\n\n knowTypes.forEach(ctor =>\n {\n if (this._nameResolver)\n {\n map.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n const knownTypeMeta = JsonObjectMetadata.getFromConstructor(ctor);\n const name = knownTypeMeta && knownTypeMeta.isExplicitlyMarked && knownTypeMeta.name\n ? knownTypeMeta.name\n : ctor.name;\n map.set(name, ctor);\n }\n });\n\n return map;\n }\n\n private _isDirectlyDeserializableNativeType(ctor: any)\n {\n return ~([Number, String, Boolean].indexOf(ctor));\n }\n\n public convertNativeObject(sourceObject: any)\n {\n return sourceObject;\n }\n\n private _stringToArrayBuffer(str: string)\n {\n let buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\n let bufView = new Uint16Array(buf);\n\n for (let i = 0, strLen = str.length; i < strLen; i++)\n {\n bufView[i] = str.charCodeAt(i);\n }\n\n return buf;\n }\n\n private _stringToDataView(str: string)\n {\n return new DataView(this._stringToArrayBuffer(str));\n }\n}\n","import { nameof, logError, isValueDefined, isInstanceOf, isTypeTypedArray, isDirectlySerializableNativeType } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfType: Function;\n elementTypes?: Function[];\n keyType?: Function;\n}\n\nexport interface IScopeArrayTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Array;\n elementTypes: Function[];\n}\n\nfunction isArrayTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeArrayTypeInfo {\n return typeInfo.selfType === Array;\n}\n\nexport interface IScopeSetTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Set;\n elementTypes: [Function];\n}\n\nfunction isSetTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeSetTypeInfo {\n return typeInfo.selfType === Set;\n}\n\nexport interface IScopeMapTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Map;\n elementTypes: [Function];\n keyType: Function;\n}\n\nfunction isMapTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeMapTypeInfo {\n return typeInfo.selfType === Map;\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class instances, and so on) to an untyped javascript object (also\n * called \"simple javascript object\"), and emits any necessary type hints in the process (for polymorphism).\n *\n * The converted object tree is what will be given to `JSON.stringify` to convert to string as the last step, the serialization is basically like:\n *\n * (1) typed object-tree -> (2) simple JS object-tree -> (3) JSON-string\n */\nexport class Serializer\n{\n private _typeHintEmitter: (targetObject: IndexedObject, sourceObject: IndexedObject, expectedSourceType: Function, sourceTypeMetadata?: JsonObjectMetadata) => void;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeHintEmitter = (targetObject, sourceObject, expectedSourceType, sourceTypeMetadata?: JsonObjectMetadata) =>\n {\n // By default, we put a \"__type\" property on the output object if the actual object is not the same as the expected one, so that deserialization\n // will know what to deserialize into (given the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n const name = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n // TODO: Perhaps this can work correctly without string-literal access?\n // tslint:disable-next-line:no-string-literal\n targetObject[\"__type\"] = name;\n }\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setTypeHintEmitter(typeEmitterCallback: (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void)\n {\n if (typeof typeEmitterCallback !== \"function\")\n {\n throw new TypeError(\"'typeEmitterCallback' is not a function.\");\n }\n\n this._typeHintEmitter = typeEmitterCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n /**\n * Convert a value of any supported serializable type.\n * The value type will be detected, and the correct serialization method will be called.\n */\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName: string = \"object\"): any\n {\n if (!isValueDefined(sourceObject)) return;\n\n if (!isInstanceOf(sourceObject, typeInfo.selfType))\n {\n let expectedName = nameof(typeInfo.selfType);\n let actualName = nameof(sourceObject.constructor);\n\n this._errorHandler(new TypeError(`Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`));\n return;\n }\n\n if (isDirectlySerializableNativeType(typeInfo.selfType))\n {\n return sourceObject;\n }\n else if (typeInfo.selfType === ArrayBuffer)\n {\n return this.convertAsArrayBuffer(sourceObject);\n }\n else if (typeInfo.selfType === DataView)\n {\n return this.convertAsDataView(sourceObject);\n }\n else if (isArrayTypeInfo(typeInfo))\n {\n return this.convertAsArray(sourceObject, typeInfo.elementTypes, memberName);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName);\n }\n else if (isTypeTypedArray(typeInfo.selfType))\n {\n return this.convertAsTypedArray(sourceObject);\n }\n else if (typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple javascript object for serialization.\n */\n public convertAsObject(sourceObject: IndexedObject, typeInfo: IScopeTypeInfo, memberName?: string)\n {\n let sourceTypeMetadata: JsonObjectMetadata|undefined;\n let targetObject: IndexedObject;\n\n if (sourceObject.constructor !== typeInfo.selfType && sourceObject instanceof typeInfo.selfType)\n {\n // The source object is not of the expected type, but it is a valid subtype.\n // This is OK, and we'll proceed to gather object metadata from the subtype instead.\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(sourceObject.constructor);\n }\n else\n {\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(typeInfo.selfType);\n }\n\n if (sourceTypeMetadata)\n {\n const sourceMeta = sourceTypeMetadata;\n // Strong-typed serialization available.\n // We'll serialize by members that have been marked with @jsonMember (including array/set/map members), and perform recursive conversion on\n // each of them. The converted objects are put on the 'targetObject', which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n sourceTypeMetadata.dataMembers.forEach((memberMetadata) =>\n {\n if (memberMetadata.serializer) {\n targetObject[memberMetadata.name] =\n memberMetadata.serializer(sourceObject[memberMetadata.key]);\n } else if (memberMetadata.ctor) {\n targetObject[memberMetadata.name] = this.convertSingleValue(\n sourceObject[memberMetadata.key],\n {\n selfType: memberMetadata.ctor,\n elementTypes: memberMetadata.elementType,\n keyType: memberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${memberMetadata.key}`,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${memberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n });\n }\n else\n {\n // Untyped serialization, \"as-is\", we'll just pass the object on.\n // We'll clone the source object, because type hints are added to the object itself, and we don't want to modify to the original object.\n targetObject = { ...sourceObject };\n }\n\n // Add type-hint.\n this._typeHintEmitter(targetObject, sourceObject, typeInfo.selfType, sourceTypeMetadata);\n\n return targetObject;\n }\n\n /**\n * Performs the conversion of an array of typed objects (or primitive values) to an array of simple javascript objects (or primitive values) for\n * serialization.\n * @param expectedElementType The expected type of elements. If the array is supposed to be multi-dimensional, subsequent elements define lower dimensions.\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsArray(sourceObject: any[], expectedElementType: Function[], memberName = \"object\"): any[]\n {\n if (expectedElementType.length === 0 || !expectedElementType[0])\n throw new TypeError(`Could not serialize ${memberName} as Array: missing element type definition.`);\n\n // Check the type of each element, individually.\n // If at least one array element type is incorrect, we return undefined, which results in no value emitted during serialization.\n // This is so that invalid element types don't unexpectedly alter the ordering of other, valid elements, and that no unexpected undefined values are in\n // the emitted array.\n sourceObject.forEach((element, i) =>\n {\n if (!isInstanceOf(element, expectedElementType[0]))\n {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]: expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [], // For multidimensional arrays.\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(element => this.convertSingleValue(element, typeInfoForElements, memberName));\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @returns\n */\n public convertAsSet(sourceObject: Set, expectedElementType: Function, memberName = \"object\"): any[]\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Set: missing element type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n };\n\n // For debugging and error tracking.\n if (memberName) memberName += \"[]\";\n\n let resultArray: any[] = [];\n\n // Convert each element of the set, and put it into an output array.\n // The output array is the one serialized, as JSON.stringify does not support Set serialization. (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName);\n\n // Add to output if the source element was undefined, OR the converted element is defined. This will add intentionally undefined values to output,\n // but not values that became undefined DURING serializing (usually because of a type-error).\n if (!isValueDefined(element) || isValueDefined(resultElement))\n {\n resultArray.push(resultElement);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a map of typed objects (or primitive values) into an array of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsMap(sourceObject: Map, expectedKeyType: Function, expectedElementType: Function, memberName = \"object\"): Array<{ key: any, value: any }>\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing value type definition.`);\n\n if (!expectedKeyType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing key type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n elementTypes: [expectedElementType]\n };\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfType: expectedKeyType\n };\n\n if (memberName) memberName += \"[]\";\n\n let resultArray: Array<{ key: any, value: any }> = [];\n\n // Convert each *entry* in the map to a simple javascript object with key and value properties.\n sourceObject.forEach((value, key) =>\n {\n let resultKeyValuePairObj = {\n key: this.convertSingleValue(key, keyTypeInfo, memberName),\n value: this.convertSingleValue(value, elementTypeInfo, memberName)\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n if (isValueDefined(resultKeyValuePairObj.key) && isValueDefined(resultKeyValuePairObj.value))\n {\n resultArray.push(resultKeyValuePairObj);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a typed javascript array to a simple untyped javascript array.\n * This is needed because typed arrays are otherwise serialized as objects, so we'll end up with something like \"{ 0: 0, 1: 1, ... }\".\n *\n * @param sourceObject\n * @returns\n */\n public convertAsTypedArray(sourceObject: ArrayBufferView)\n {\n return Array.from(sourceObject as any);\n }\n\n /**\n * Performs the conversion of a raw ArrayBuffer to a string.\n */\n public convertAsArrayBuffer(buffer: ArrayBuffer)\n {\n // ArrayBuffer -> 16-bit character codes -> character array -> joined string.\n return Array.from(new Uint16Array(buffer)).map(charCode => String.fromCharCode(charCode)).join(\"\");\n }\n\n /**\n * Performs the conversion of DataView, converting its internal ArrayBuffer to a string and returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n}\n","import { Constructor, ParameterlessConstructor } from \"./types\";\nimport { METADATA_FIELD_KEY } from \"./helpers\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IJsonObjectOptionsBase\n{\n /**\n * An array of known types to recognize when encountering type-hints,\n * or the name of a static method used for determining known types.\n */\n knownTypes?: Function[] | string;\n\n /**\n * The name of a static or instance method to call when deserialization\n * of the object is completed.\n */\n onDeserialized?: string;\n\n /**\n * The name used to differentiate between different polymorphic types.\n */\n name?: string;\n}\n\nexport interface IJsonObjectOptionsWithInitializer extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer: (sourceObject: T, rawSourceObject: T) => T;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer?: (sourceObject: T, rawSourceObject: T) => T;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional settings. The 'initializer' setting must be specified.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptionsWithInitializer): (target: Constructor) => void;\n\n/**\n * Marks that a class is serializable using TypedJSON, with additional settings.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptions): (target: ParameterlessConstructor) => void;\n\n/**\n * Marks that a class with a parameterless constructor is serializable using TypedJSON.\n */\nexport function jsonObject(target: ParameterlessConstructor): void;\n\nexport function jsonObject(optionsOrTarget?: IJsonObjectOptions | Constructor\n): ((target: Constructor) => void) | void {\n let options: IJsonObjectOptions;\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n options = {};\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n options = optionsOrTarget || {};\n }\n\n function decorator(\n target: Function\n ): void {\n let objectMetadata: JsonObjectMetadata;\n\n // Create or obtain JsonObjectMetadata object.\n if (!target.prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // Target has no JsonObjectMetadata associated with it yet, create it now.\n objectMetadata = new JsonObjectMetadata(target);\n\n // Inherit json members and known types from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = target.prototype[METADATA_FIELD_KEY];\n if (parentMetadata)\n {\n parentMetadata.dataMembers\n .forEach((memberMetadata, propKey) =>\n objectMetadata.dataMembers.set(propKey, memberMetadata));\n parentMetadata.knownTypes\n .forEach((knownType) => objectMetadata.knownTypes.add(knownType));\n }\n\n Object.defineProperty(target.prototype, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // Target already has JsonObjectMetadata associated with it.\n objectMetadata = target.prototype[METADATA_FIELD_KEY];\n objectMetadata.classType = target;\n }\n\n // Fill JsonObjectMetadata.\n objectMetadata.isExplicitlyMarked = true;\n objectMetadata.onDeserializedMethodName = options.onDeserialized;\n // T extend Object so it is fine\n objectMetadata.initializerCallback = options.initializer as any;\n if (options.name)\n {\n objectMetadata.name = options.name;\n }\n\n // Obtain known-types.\n if (typeof options.knownTypes === \"string\")\n {\n objectMetadata.knownTypeMethodName = options.knownTypes;\n }\n else if (options.knownTypes instanceof Array)\n {\n options.knownTypes\n .filter(knownType => !!knownType)\n .forEach(knownType => objectMetadata.knownTypes.add(knownType));\n }\n }\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n decorator(optionsOrTarget);\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n return decorator;\n }\n}\n","import {\n nameof, logError, isReflectMetadataSupported, isValueDefined, logWarning, isSubtypeOf\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions\n{\n /**\n * Sets the constructor of the property.\n * Optional with ReflectDecorators.\n */\n constructor?: Function;\n\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted if the property is uninitialized/undefined. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name. */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property is part of the object when serializing, with additional options.\n * Omitting the 'constructor' option requires ReflectDecorators and that the property type is always explicitly declared.\n * @param options Additional options.\n */\nexport function jsonMember(options: IJsonMemberOptions): PropertyDecorator;\n\n/**\n * Specifies that a property is part of the object when serializing.\n * This call signature requires ReflectDecorators and that the property type is always explicitly declared.\n */\nexport function jsonMember(target: Object, propertyKey: string | symbol): void;\n\nexport function jsonMember(optionsOrTarget?: IJsonMemberOptions | Object, propKey?: string | symbol): PropertyDecorator | void\n{\n if (optionsOrTarget instanceof Object && (typeof propKey === \"string\" || typeof propKey === \"symbol\"))\n {\n const target = optionsOrTarget;\n // For error messages.\n const decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(propKey)}`;\n\n // jsonMember used directly, no additional information directly available besides target and propKey.\n // Obtain property constructor through ReflectDecorators.\n if (isReflectMetadataSupported)\n {\n const reflectPropCtor = Reflect.getMetadata(\"design:type\", target, propKey) as Function;\n\n if (!reflectPropCtor)\n {\n logError(`${decoratorName}: could not resolve detected property constructor at runtime.`);\n return;\n }\n\n if (isSpecialPropertyType(decoratorName, reflectPropCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: reflectPropCtor,\n key: propKey.toString(),\n name: propKey.toString(),\n });\n }\n else\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n else\n {\n // jsonMember used as a decorator factory.\n return (target: Object, _propKey: string | symbol) =>\n {\n let options: IJsonMemberOptions = optionsOrTarget || {};\n let propCtor: Function|undefined;\n let decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(_propKey)}`; // For error messages.\n\n if (options.hasOwnProperty(\"constructor\"))\n {\n if (!isValueDefined(options.constructor))\n {\n logError(`${decoratorName}: cannot resolve specified property constructor at runtime.`);\n return;\n }\n\n // Property constructor has been specified. Use ReflectDecorators (if available) to check whether that constructor is correct. Warn if not.\n if (isReflectMetadataSupported && !isSubtypeOf(options.constructor, Reflect.getMetadata(\"design:type\", target, _propKey)))\n {\n logWarning(`${decoratorName}: detected property type does not match 'constructor' option.`);\n }\n\n propCtor = options.constructor;\n }\n else\n {\n // Use ReflectDecorators to obtain property constructor.\n if (isReflectMetadataSupported)\n {\n propCtor = Reflect.getMetadata(\"design:type\", target, _propKey) as Function;\n\n if (!propCtor)\n {\n logError(`${decoratorName}: cannot resolve detected property constructor at runtime.`);\n return;\n }\n }\n else if (!options.deserializer)\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n\n if (isSpecialPropertyType(decoratorName, propCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, _propKey, {\n ctor: propCtor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: _propKey.toString(),\n name: options.name || _propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n }\n}\n\nfunction isSpecialPropertyType(decoratorName: string, propCtor?: Function)\n{\n if (propCtor === Array)\n {\n logError(`${decoratorName}: property is an Array. Use the jsonArrayMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Set)\n {\n logError(`${decoratorName}: property is a Set. Use the jsonSetMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Map)\n {\n logError(`${decoratorName}: property is a Map. Use the jsonMapMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n return false;\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, an empty array is emitted if the property is undefined/uninitialized. */\n emitDefaultValue?: boolean;\n\n /** Sets array dimensions (e.g. 1 for 'number[]' or 2 for 'number[][]'). Defaults to 1. */\n dimensions?: number;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property, of type array, is part of an object when serializing.\n * @param elementConstructor Constructor of array elements (e.g. 'Number' for 'number[]', or 'Date' for 'Date[]').\n * @param options Additional options.\n */\nexport function jsonArrayMember(elementConstructor: Function, options: IJsonArrayMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonArrayMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of array elements at runtime.`);\n return;\n }\n\n const dimensions = options.dimensions === undefined ? 1 : options.dimensions;\n if (!isNaN(dimensions) && dimensions < 1)\n {\n logError(`${decoratorName}: 'dimensions' option must be at least 1.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonArrayMember' has been used on an array.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Array)\n {\n logError(`${decoratorName}: property is not an Array.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n\nfunction createArrayElementType(elementCtor: Function, dimensions: number) {\n const elementTypes = new Array(dimensions).fill(Array, 0, -1);\n elementTypes[dimensions-1] = elementCtor;\n return elementTypes;\n}\n","import { nameof } from \"./helpers\";\nimport { IJsonMemberOptions } from \"./json-member\";\nimport { JsonMemberMetadata, JsonObjectMetadata, injectMetadataInformation } from \"./metadata\";\nimport * as Helpers from \"./helpers\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Set.\n * @param elementConstructor Constructor of set elements (e.g. 'Number' for Set or 'Date' for Set).\n * @param options Additional options.\n */\nexport function jsonSetMember(elementConstructor: Function, options: IJsonSetMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n var decoratorName = `@jsonSetMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n Helpers.logError(`${decoratorName}: could not resolve constructor of set elements at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonSetMember' has been used on a set. Warn if not.\n if (Helpers.isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n Helpers.logError(`${decoratorName}: property is not a Set.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Map.\n * @param keyConstructor Constructor of map keys (e.g. 'Number' for 'Map').\n * @param valueConstructor Constructor of map values (e.g. 'Date' for 'Map').\n * @param options Additional options.\n */\nexport function jsonMapMember(keyConstructor: Function, valueConstructor: Function, options: IJsonMapMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonMapMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof keyConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map keys at runtime.`);\n return;\n }\n\n if (typeof valueConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map values at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonMapMember' has been used on a map. Warn if not.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Map)\n {\n logError(`${decoratorName}: property is not a Map.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, logWarning, parseToJSObject } from './typedjson/helpers';\nimport { Constructor } from \"./typedjson/types\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { Serializer } from \"./typedjson/serializer\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\n\nexport interface ITypedJSONSettings\n{\n /**\n * Sets the handler callback to invoke on errors during serializing and deserializing.\n * Re-throwing errors in this function will halt serialization/deserialization.\n * The default behavior is to log errors to the console.\n */\n errorHandler?: (e: Error) => void;\n\n /**\n * Sets a callback that determines the constructor of the correct sub-type of polymorphic\n * objects while deserializing.\n * The default behavior is to read the type-name from the '__type' property of 'sourceObject',\n * and look it up in 'knownTypes'.\n * The constructor of the sub-type should be returned.\n */\n typeResolver?: (sourceObject: Object, knownTypes: Map) => Function;\n\n nameResolver?: (ctor: Function) => string;\n\n /**\n * Sets a callback that writes type-hints to serialized objects.\n * The default behavior is to write the type-name to the '__type' property, if a derived type\n * is present in place of a base type.\n */\n typeHintEmitter?:\n (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void;\n\n /**\n * Sets the amount of indentation to use in produced JSON strings.\n * Default value is 0, or no indentation.\n */\n indent?: number;\n\n replacer?: (key: string, value: any) => any;\n\n knownTypes?: Array>;\n}\n\nexport class TypedJSON\n{\n //#region Static\n public static parse(\n object: any, rootType: Constructor, settings?: ITypedJSONSettings,\n ): T|undefined {\n return new TypedJSON(rootType, settings).parse(object);\n }\n\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: 1\n ): T[];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 2\n ): T[][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 3\n ): T[][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 4\n ): T[][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 5\n ): T[][][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: number\n ): any[] {\n return new TypedJSON(elementType, settings).parseAsArray(object, dimensions as any);\n }\n\n public static parseAsSet(\n object: any, elementType: Constructor, settings?: ITypedJSONSettings,\n ): Set {\n return new TypedJSON(elementType, settings).parseAsSet(object);\n }\n\n public static parseAsMap(\n object: any,\n keyType: Constructor,\n valueType: Constructor,\n settings?: ITypedJSONSettings,\n ): Map {\n return new TypedJSON(valueType, settings).parseAsMap(object, keyType);\n }\n\n public static toPlainJson(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): JsonTypes {\n return new TypedJSON(rootType, settings).toPlainJson(object);\n }\n\n public static toPlainArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): Object[];\n public static toPlainArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): Object[][];\n public static toPlainArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): Object[][][];\n public static toPlainArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): Object[][][][];\n public static toPlainArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): Object[][][][][];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): any[];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): any[] {\n return new TypedJSON(elementType, settings).toPlainArray(object, dimensions);\n }\n\n public static toPlainSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n public static stringify(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(rootType, settings).stringify(object);\n }\n\n public static stringifyAsArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsArray(object, dimensions);\n }\n\n public static stringifyAsSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static stringifyAsMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n private static _globalConfig: ITypedJSONSettings;\n\n public static setGlobalConfig(config: ITypedJSONSettings)\n {\n if (this._globalConfig)\n {\n Object.assign(this._globalConfig, config);\n }\n else\n {\n this._globalConfig = config;\n }\n }\n\n //#endregion\n\n private serializer: Serializer = new Serializer();\n private deserializer: Deserializer = new Deserializer();\n private globalKnownTypes: Array> = [];\n private indent: number = 0;\n private rootConstructor: Constructor;\n private errorHandler: (e: Error) => void;\n private nameResolver: (ctor: Function) => string;\n private replacer?: (key: string, value: any) => any;\n\n /**\n * Creates a new TypedJSON instance to serialize (stringify) and deserialize (parse) object\n * instances of the specified root class type.\n * @param rootType The constructor of the root class type.\n * @param settings Additional configuration settings.\n */\n constructor(rootConstructor: Constructor, settings?: ITypedJSONSettings)\n {\n let rootMetadata = JsonObjectMetadata.getFromConstructor(rootConstructor);\n\n if (!rootMetadata || (!rootMetadata.isExplicitlyMarked && !rootMetadata.isHandledWithoutAnnotation))\n {\n throw new TypeError(\"The TypedJSON root data type must have the @jsonObject decorator used.\");\n }\n\n this.nameResolver = (ctor) => nameof(ctor);\n this.rootConstructor = rootConstructor;\n this.errorHandler = (error) => logError(error);\n\n if (settings)\n {\n this.config(settings);\n }\n else if (TypedJSON._globalConfig)\n {\n this.config({});\n }\n }\n\n /**\n * Configures TypedJSON through a settings object.\n * @param settings The configuration settings object.\n */\n public config(settings: ITypedJSONSettings)\n {\n if (TypedJSON._globalConfig)\n {\n settings = {\n ...TypedJSON._globalConfig,\n ...settings\n };\n\n if (settings.knownTypes && TypedJSON._globalConfig.knownTypes)\n {\n // Merge known-types (also de-duplicate them, so Array -> Set -> Array).\n settings.knownTypes = Array.from(new Set(\n settings.knownTypes.concat(TypedJSON._globalConfig.knownTypes),\n ));\n }\n }\n\n if (settings.errorHandler)\n {\n this.errorHandler = settings.errorHandler;\n this.deserializer.setErrorHandler(settings.errorHandler);\n this.serializer.setErrorHandler(settings.errorHandler);\n }\n\n if (settings.replacer) this.replacer = settings.replacer;\n if (settings.typeResolver) this.deserializer.setTypeResolver(settings.typeResolver);\n if (settings.typeHintEmitter) this.serializer.setTypeHintEmitter(settings.typeHintEmitter);\n if (settings.indent) this.indent = settings.indent;\n\n if (settings.nameResolver)\n {\n this.nameResolver = settings.nameResolver;\n this.deserializer.setNameResolver(settings.nameResolver);\n // this.serializer.set\n }\n\n if (settings.knownTypes)\n {\n // Type-check knownTypes elements to recognize errors in advance.\n settings.knownTypes.forEach((knownType, i) =>\n {\n // tslint:disable-next-line:no-null-keyword\n if (typeof knownType === \"undefined\" || knownType === null)\n {\n logWarning(\n `TypedJSON.config: 'knownTypes' contains an undefined/null value (element ${i}).`);\n }\n });\n\n this.globalKnownTypes = settings.knownTypes;\n }\n }\n\n /**\n * Converts a JSON string to the root class type.\n * @param object The JSON to parse and convert.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns Deserialized T or undefined if there were errors.\n */\n public parse(object: any): T|undefined\n {\n const json = parseToJSObject(object, this.rootConstructor);\n\n let rootMetadata = JsonObjectMetadata.getFromConstructor(this.rootConstructor);\n let result: T|undefined;\n let knownTypes = new Map();\n\n this.globalKnownTypes.filter(ktc => ktc).forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n\n if (rootMetadata)\n {\n rootMetadata.knownTypes.forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n }\n\n try\n {\n result = this.deserializer.convertSingleValue(json, {\n selfConstructor: this.rootConstructor,\n knownTypes: knownTypes,\n }) as T;\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n\n return result;\n }\n\n public parseAsArray(object: any, dimensions?: 1): T[];\n public parseAsArray(object: any, dimensions: 2): T[][];\n public parseAsArray(object: any, dimensions: 3): T[][][];\n public parseAsArray(object: any, dimensions: 4): T[][][][];\n public parseAsArray(object: any, dimensions: 5): T[][][][][];\n public parseAsArray(object: any, dimensions: number): any[];\n public parseAsArray(object: any, dimensions: number = 1): any[]\n {\n const json = parseToJSObject(object, Array);\n if (json instanceof Array)\n {\n return this.deserializer.convertAsArray(json, {\n selfConstructor: Array,\n elementConstructor: new Array(dimensions - 1)\n .fill(Array)\n .concat(this.rootConstructor),\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define an Array`\n + `, but got ${typeof json}.`));\n }\n\n return [];\n }\n\n public parseAsSet(object: any): Set\n {\n const json = parseToJSObject(object, Set);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsSet(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes)\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Set();\n }\n\n public parseAsMap(object: any, keyConstructor: Constructor): Map\n {\n const json = parseToJSObject(object, Map);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsMap(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n keyConstructor: keyConstructor\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Map();\n }\n\n /**\n * Converts an instance of the specified class type to a plain JSON object.\n * @param object The instance to convert to a JSON string.\n * @returns Serialized object or undefined if an error has occured.\n */\n public toPlainJson(object: T): JsonTypes\n {\n try\n {\n return this.serializer.convertSingleValue(object, {\n selfType: this.rootConstructor\n });\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainArray(object: T[], dimensions?: 1): Object[];\n public toPlainArray(object: T[][], dimensions: 2): Object[][];\n public toPlainArray(object: T[][][], dimensions: 3): Object[][][];\n public toPlainArray(object: T[][][][], dimensions: 4): Object[][][][];\n public toPlainArray(object: T[][][][][], dimensions: 5): Object[][][][][];\n public toPlainArray(object: any[], dimensions: 1|2|3|4|5 = 1): Object[]|undefined\n {\n try\n {\n const elementConstructorArray =\n new Array(dimensions - 1).fill(Array).concat(this.rootConstructor);\n return this.serializer.convertAsArray(object, elementConstructorArray);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainSet(object: Set): Object[]|undefined\n {\n try\n {\n return this.serializer.convertAsSet(object, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainMap(object: Map, keyConstructor: Constructor): { key: any, value: any }[]|undefined\n {\n try\n {\n return this.serializer.convertAsMap(object, keyConstructor, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n /**\n * Converts an instance of the specified class type to a JSON string.\n * @param object The instance to convert to a JSON string.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns String with the serialized object or an empty string if an error has occured, but\n * the errorHandler did not throw.\n */\n public stringify(object: T): string\n {\n const result = this.toPlainJson(object);\n if (result === undefined) {\n return '';\n }\n return JSON.stringify(result, this.replacer, this.indent);\n }\n\n public stringifyAsArray(object: T[], dimensions?: 1): string;\n public stringifyAsArray(object: T[][], dimensions: 2): string;\n public stringifyAsArray(object: T[][][], dimensions: 3): string;\n public stringifyAsArray(object: T[][][][], dimensions: 4): string;\n public stringifyAsArray(object: T[][][][][], dimensions: 5): string;\n public stringifyAsArray(object: any[], dimensions: any): string\n {\n return JSON.stringify(this.toPlainArray(object, dimensions), this.replacer, this.indent);\n }\n\n public stringifyAsSet(object: Set): string\n {\n return JSON.stringify(this.toPlainSet(object), this.replacer, this.indent);\n }\n\n public stringifyAsMap(object: Map, keyConstructor: Constructor): string\n {\n return JSON.stringify(this.toPlainMap(object, keyConstructor), this.replacer, this.indent);\n }\n\n private _mapKnownTypes(constructors: Array>)\n {\n let map = new Map>();\n\n constructors.filter(ctor => ctor).forEach(ctor => map.set(this.nameResolver(ctor), ctor));\n\n return map;\n }\n}\n\nexport { jsonObject } from \"./typedjson/json-object\";\nexport { jsonMember } from \"./typedjson/json-member\";\nexport { jsonArrayMember } from \"./typedjson/json-array-member\";\nexport { jsonSetMember } from \"./typedjson/json-set-member\";\nexport { jsonMapMember } from \"./typedjson/json-map-member\";\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/typedjson.min.js b/js/typedjson.min.js index 767cf4f..3748500 100644 --- a/js/typedjson.min.js +++ b/js/typedjson.min.js @@ -1,3 +1,3 @@ // [typedjson] Version: 1.2.1 - 2018-12-09 - !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("typedjson",[],r):"object"==typeof exports?exports.typedjson=r():e.typedjson=r()}("undefined"!=typeof self?self:this,function(){return function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){"use strict";t.r(r);var n="__typedJsonJsonObjectMetadataInformation__";function o(e){return!!~[Date,Number,String,Boolean].indexOf(e)}function i(e){return!!~[Float32Array,Float64Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array].indexOf(e)}function s(e,r){return e===r||e.prototype instanceof r}function a(e){for(var r=[],t=1;t0)return new Date(e);this._throwTypeMismatchError("Date","an ISO-8601 string",o,t)}else if(n===Float32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float32Array(e);this._throwTypeMismatchError("Float32Array","a numeric source array",o,t)}else if(n===Float64Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float64Array(e);this._throwTypeMismatchError("Float64Array","a numeric source array",o,t)}else if(n===Uint8Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8Array","a numeric source array",o,t)}else if(n===Uint8ClampedArray){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8ClampedArray(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8ClampedArray","a numeric source array",o,t)}else if(n===Uint16Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint16Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint16Array","a numeric source array",o,t)}else if(n===Uint32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint32Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint32Array","a numeric source array",o,t)}else if(n===ArrayBuffer){if("string"==typeof e)return this._stringToArrayBuffer(e);this._throwTypeMismatchError("ArrayBuffer","a string source",o,t)}else if(n===DataView){if("string"==typeof e)return this._stringToDataView(e);this._throwTypeMismatchError("DataView","a string source",o,t)}else{if(n===Array){if(e instanceof Array)return this.convertAsArray(e,r,t);throw new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))}if(n===Set){if(e instanceof Array)return this.convertAsSet(e,r,t);this._throwTypeMismatchError("Set","Array",o,t)}else if(n===Map){if(e instanceof Array)return this.convertAsMap(e,r,t);this._throwTypeMismatchError("Map","a source array of key-value-pair objects",o,t)}else if(e&&"object"==typeof e)return this.convertAsObject(e,r,t)}},e.prototype.convertAsArray=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),[];if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Array: missing constructor reference of Array elements.")),[];var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes};return e.map(function(e){try{return n.convertSingleValue(e,o)}catch(e){return void n._errorHandler(e)}})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),new Set;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Set: missing constructor reference of Set elements.")),new Set;var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},i=new Set;return e.forEach(function(e,r){try{i.add(n.convertSingleValue(e,o,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),i},e.prototype.convertAsMap=function(e,r,t){var n=this;if(void 0===t&&(t="object"),e instanceof Array||this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),!r.keyConstructor)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing key constructor.")),new Map;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing value constructor.")),new Map;var o={selfConstructor:r.keyConstructor,knownTypes:r.knownTypes},i={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},s=new Map;return e.forEach(function(e){try{var r=n.convertSingleValue(e.key,o);u(r)&&s.set(r,n.convertSingleValue(e.value,i,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),s},e.prototype._throwTypeMismatchError=function(e,r,t,n){throw void 0===n&&(n="object"),new TypeError("Could not deserialize "+n+" as "+e+": expected "+r+", got "+t+".")},e.prototype._makeTypeErrorMessage=function(e,r,t){return void 0===t&&(t="object"),"Could not deserialize "+t+": expected '"+("function"==typeof e?y(e):e)+"', got '"+("function"==typeof r?y(r):r)+"'."},e.prototype._instantiateType=function(e){return new e},e.prototype._mergeKnownTypes=function(){for(var e=this,r=[],t=0;t1?r.slice(1):[]};return t&&(t+="[]"),e.map(function(e){return n.convertSingleValue(e,o,t)})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!r)throw new TypeError("Could not serialize "+t+" as Set: missing element type definition.");var o={selfType:r};t&&(t+="[]");var i=[];return e.forEach(function(e){var r=n.convertSingleValue(e,o,t);u(e)&&!u(r)||i.push(r)}),i},e.prototype.convertAsMap=function(e,r,t,n){var o=this;if(void 0===n&&(n="object"),!t)throw new TypeError("Could not serialize "+n+" as Map: missing value type definition.");if(!r)throw new TypeError("Could not serialize "+n+" as Map: missing key type definition.");var i={selfType:t,elementTypes:[t]},s={selfType:r};n&&(n+="[]");var a=[];return e.forEach(function(e,r){var t={key:o.convertSingleValue(r,s,n),value:o.convertSingleValue(e,i,n)};u(t.key)&&u(t.value)&&a.push(t)}),a},e.prototype.convertAsTypedArray=function(e){return Array.from(e)},e.prototype.convertAsArrayBuffer=function(e){return Array.from(new Uint16Array(e)).map(function(e){return String.fromCharCode(e)}).join("")},e.prototype.convertAsDataView=function(e){return this.convertAsArrayBuffer(e.buffer)},e}();function w(e){var r;function t(e){var t;if(e.prototype.hasOwnProperty(n))(t=e.prototype[n]).classType=e;else{t=new f(e);var o=e.prototype[n];o&&(o.dataMembers.forEach(function(e,r){return t.dataMembers.set(r,e)}),o.knownTypes.forEach(function(e){return t.knownTypes.add(e)})),Object.defineProperty(e.prototype,n,{enumerable:!1,configurable:!1,writable:!1,value:t})}t.isExplicitlyMarked=!0,t.onDeserializedMethodName=r.onDeserialized,t.initializerCallback=r.initializer,r.name&&(t.name=r.name),"string"==typeof r.knownTypes?t.knownTypeMethodName=r.knownTypes:r.knownTypes instanceof Array&&r.knownTypes.filter(function(e){return!!e}).forEach(function(e){return t.knownTypes.add(e)})}if(r="function"==typeof e?{}:e||{},"function"!=typeof e)return t;t(e)}function T(e,r){if(!(e instanceof Object)||"string"!=typeof r&&"symbol"!=typeof r)return function(r,t){var n,o=e||{},i="@jsonMember on "+y(r.constructor)+"."+String(t);if(o.hasOwnProperty("constructor")){if(!u(o.constructor))return void a(i+": cannot resolve specified property constructor at runtime.");p&&!s(o.constructor,Reflect.getMetadata("design:type",r,t))&&c(i+": detected property type does not match 'constructor' option."),n=o.constructor}else if(p){if(!(n=Reflect.getMetadata("design:type",r,t)))return void a(i+": cannot resolve detected property constructor at runtime.")}else if(!o.deserializer)return void a(i+": ReflectDecorators is required if no 'constructor' option is specified.");g(i,n)||d(r,t,{ctor:n,emitDefaultValue:o.emitDefaultValue||!1,isRequired:o.isRequired||!1,key:t.toString(),name:o.name||t.toString(),deserializer:o.deserializer,serializer:o.serializer})};var t=e,n="@jsonMember on "+y(t.constructor)+"."+String(r);if(p){var o=Reflect.getMetadata("design:type",t,r);o?g(n,o)||d(t,r,{ctor:o,key:r.toString(),name:r.toString()}):a(n+": could not resolve detected property constructor at runtime.")}else a(n+": ReflectDecorators is required if no 'constructor' option is specified.")}function g(e,r){return r===Array?(a(e+": property is an Array. Use the jsonArrayMember decorator to serialize this property."),!0):r===Set?(a(e+": property is a Set. Use the jsonSetMember decorator to serialize this property."),!0):r===Map&&(a(e+": property is a Map. Use the jsonMapMember decorator to serialize this property."),!0)}function A(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonArrayMember on "+y(t.constructor)+"."+String(n);if("function"==typeof e){var i=void 0===r.dimensions?1:r.dimensions;!isNaN(i)&&i<1?a(o+": 'dimensions' option must be at least 1."):p&&Reflect.getMetadata("design:type",t,n)!==Array?a(o+": property is not an Array."):d(t,n,{ctor:Array,elementType:function(e,r){var t=new Array(r).fill(Array,0,-1);return t[r-1]=e,t}(e,i),emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer})}else a(o+": could not resolve constructor of array elements at runtime.")}}function b(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonSetMember on "+y(t.constructor)+"."+String(n);"function"==typeof e?p&&Reflect.getMetadata("design:type",t,n)!==Set?a(o+": property is not a Set."):d(t,n,{ctor:Set,elementType:[e],emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer}):a(o+": could not resolve constructor of set elements at runtime.")}}function M(e,r,t){return void 0===t&&(t={}),function(n,o){var i="@jsonMapMember on "+y(n.constructor)+"."+String(o);"function"==typeof e?"function"==typeof r?p&&Reflect.getMetadata("design:type",n,o)!==Map?a(i+": property is not a Map."):d(n,o,{ctor:Map,elementType:[r],keyType:e,emitDefaultValue:t.emitDefaultValue||!1,isRequired:t.isRequired||!1,key:o.toString(),name:t.name||o.toString(),deserializer:t.deserializer,serializer:t.serializer}):a(i+": could not resolve constructor of map values at runtime."):a(i+": could not resolve constructor of map keys at runtime.")}}t.d(r,"TypedJSON",function(){return k}),t.d(r,"jsonObject",function(){return w}),t.d(r,"jsonMember",function(){return T}),t.d(r,"jsonArrayMember",function(){return A}),t.d(r,"jsonSetMember",function(){return b}),t.d(r,"jsonMapMember",function(){return M});var C=Object.assign||function(e){for(var r,t=1,n=arguments.length;t=2&&'"'===e[0]&&'"'===e[e.length-1],o=/^\d+$/.test(e.trim());return t&&!n||!n&&!o&&r===Date}(e,r)?e:JSON.parse(e)}function a(e,r){return e===r||e.prototype instanceof r}function c(e){for(var r=[],t=1;t0)return new Date(e);this._throwTypeMismatchError("Date","an ISO-8601 string",o,t)}else if(n===Float32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float32Array(e);this._throwTypeMismatchError("Float32Array","a numeric source array",o,t)}else if(n===Float64Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Float64Array(e);this._throwTypeMismatchError("Float64Array","a numeric source array",o,t)}else if(n===Uint8Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8Array","a numeric source array",o,t)}else if(n===Uint8ClampedArray){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint8ClampedArray(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint8ClampedArray","a numeric source array",o,t)}else if(n===Uint16Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint16Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint16Array","a numeric source array",o,t)}else if(n===Uint32Array){if(e instanceof Array&&e.every(function(e){return!isNaN(e)}))return new Uint32Array(e.map(function(e){return~~e}));this._throwTypeMismatchError("Uint32Array","a numeric source array",o,t)}else if(n===ArrayBuffer){if("string"==typeof e)return this._stringToArrayBuffer(e);this._throwTypeMismatchError("ArrayBuffer","a string source",o,t)}else if(n===DataView){if("string"==typeof e)return this._stringToDataView(e);this._throwTypeMismatchError("DataView","a string source",o,t)}else{if(n===Array){if(e instanceof Array)return this.convertAsArray(e,r,t);throw new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))}if(n===Set){if(e instanceof Array)return this.convertAsSet(e,r,t);this._throwTypeMismatchError("Set","Array",o,t)}else if(n===Map){if(e instanceof Array)return this.convertAsMap(e,r,t);this._throwTypeMismatchError("Map","a source array of key-value-pair objects",o,t)}else if(e&&"object"==typeof e)return this.convertAsObject(e,r,t)}},e.prototype.convertAsArray=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),[];if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Array: missing constructor reference of Array elements.")),[];var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes};return e.map(function(e){try{return n.convertSingleValue(e,o)}catch(e){return void n._errorHandler(e)}})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!(e instanceof Array))return this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),new Set;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Set: missing constructor reference of Set elements.")),new Set;var o={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},i=new Set;return e.forEach(function(e,r){try{i.add(n.convertSingleValue(e,o,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),i},e.prototype.convertAsMap=function(e,r,t){var n=this;if(void 0===t&&(t="object"),e instanceof Array||this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array,e.constructor,t))),!r.keyConstructor)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing key constructor.")),new Map;if(!r.elementConstructor||!r.elementConstructor.length)return this._errorHandler(new TypeError("Could not deserialize "+t+" as Map: missing value constructor.")),new Map;var o={selfConstructor:r.keyConstructor,knownTypes:r.knownTypes},i={selfConstructor:r.elementConstructor[0],elementConstructor:r.elementConstructor.length>1?r.elementConstructor.slice(1):[],knownTypes:r.knownTypes},s=new Map;return e.forEach(function(e){try{var r=n.convertSingleValue(e.key,o);l(r)&&s.set(r,n.convertSingleValue(e.value,i,t+"["+r+"]"))}catch(e){n._errorHandler(e)}}),s},e.prototype._throwTypeMismatchError=function(e,r,t,n){throw void 0===n&&(n="object"),new TypeError("Could not deserialize "+n+" as "+e+": expected "+r+", got "+t+".")},e.prototype._makeTypeErrorMessage=function(e,r,t){return void 0===t&&(t="object"),"Could not deserialize "+t+": expected '"+("function"==typeof e?p(e):e)+"', got '"+("function"==typeof r?p(r):r)+"'."},e.prototype._instantiateType=function(e){return new e},e.prototype._mergeKnownTypes=function(){for(var e=this,r=[],t=0;t1?r.slice(1):[]};return t&&(t+="[]"),e.map(function(e){return n.convertSingleValue(e,o,t)})},e.prototype.convertAsSet=function(e,r,t){var n=this;if(void 0===t&&(t="object"),!r)throw new TypeError("Could not serialize "+t+" as Set: missing element type definition.");var o={selfType:r};t&&(t+="[]");var i=[];return e.forEach(function(e){var r=n.convertSingleValue(e,o,t);l(e)&&!l(r)||i.push(r)}),i},e.prototype.convertAsMap=function(e,r,t,n){var o=this;if(void 0===n&&(n="object"),!t)throw new TypeError("Could not serialize "+n+" as Map: missing value type definition.");if(!r)throw new TypeError("Could not serialize "+n+" as Map: missing key type definition.");var i={selfType:t,elementTypes:[t]},s={selfType:r};n&&(n+="[]");var a=[];return e.forEach(function(e,r){var t={key:o.convertSingleValue(r,s,n),value:o.convertSingleValue(e,i,n)};l(t.key)&&l(t.value)&&a.push(t)}),a},e.prototype.convertAsTypedArray=function(e){return Array.from(e)},e.prototype.convertAsArrayBuffer=function(e){return Array.from(new Uint16Array(e)).map(function(e){return String.fromCharCode(e)}).join("")},e.prototype.convertAsDataView=function(e){return this.convertAsArrayBuffer(e.buffer)},e}();function g(e){var r;function t(e){var t;if(e.prototype.hasOwnProperty(n))(t=e.prototype[n]).classType=e;else{t=new d(e);var o=e.prototype[n];o&&(o.dataMembers.forEach(function(e,r){return t.dataMembers.set(r,e)}),o.knownTypes.forEach(function(e){return t.knownTypes.add(e)})),Object.defineProperty(e.prototype,n,{enumerable:!1,configurable:!1,writable:!1,value:t})}t.isExplicitlyMarked=!0,t.onDeserializedMethodName=r.onDeserialized,t.initializerCallback=r.initializer,r.name&&(t.name=r.name),"string"==typeof r.knownTypes?t.knownTypeMethodName=r.knownTypes:r.knownTypes instanceof Array&&r.knownTypes.filter(function(e){return!!e}).forEach(function(e){return t.knownTypes.add(e)})}if(r="function"==typeof e?{}:e||{},"function"!=typeof e)return t;t(e)}function T(e,r){if(!(e instanceof Object)||"string"!=typeof r&&"symbol"!=typeof r)return function(r,t){var n,o=e||{},i="@jsonMember on "+p(r.constructor)+"."+String(t);if(o.hasOwnProperty("constructor")){if(!l(o.constructor))return void c(i+": cannot resolve specified property constructor at runtime.");f&&!a(o.constructor,Reflect.getMetadata("design:type",r,t))&&u(i+": detected property type does not match 'constructor' option."),n=o.constructor}else if(f){if(!(n=Reflect.getMetadata("design:type",r,t)))return void c(i+": cannot resolve detected property constructor at runtime.")}else if(!o.deserializer)return void c(i+": ReflectDecorators is required if no 'constructor' option is specified.");A(i,n)||h(r,t,{ctor:n,emitDefaultValue:o.emitDefaultValue||!1,isRequired:o.isRequired||!1,key:t.toString(),name:o.name||t.toString(),deserializer:o.deserializer,serializer:o.serializer})};var t=e,n="@jsonMember on "+p(t.constructor)+"."+String(r);if(f){var o=Reflect.getMetadata("design:type",t,r);o?A(n,o)||h(t,r,{ctor:o,key:r.toString(),name:r.toString()}):c(n+": could not resolve detected property constructor at runtime.")}else c(n+": ReflectDecorators is required if no 'constructor' option is specified.")}function A(e,r){return r===Array?(c(e+": property is an Array. Use the jsonArrayMember decorator to serialize this property."),!0):r===Set?(c(e+": property is a Set. Use the jsonSetMember decorator to serialize this property."),!0):r===Map&&(c(e+": property is a Map. Use the jsonMapMember decorator to serialize this property."),!0)}function b(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonArrayMember on "+p(t.constructor)+"."+String(n);if("function"==typeof e){var i=void 0===r.dimensions?1:r.dimensions;!isNaN(i)&&i<1?c(o+": 'dimensions' option must be at least 1."):f&&Reflect.getMetadata("design:type",t,n)!==Array?c(o+": property is not an Array."):h(t,n,{ctor:Array,elementType:function(e,r){var t=new Array(r).fill(Array,0,-1);return t[r-1]=e,t}(e,i),emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer})}else c(o+": could not resolve constructor of array elements at runtime.")}}function M(e,r){return void 0===r&&(r={}),function(t,n){var o="@jsonSetMember on "+p(t.constructor)+"."+String(n);"function"==typeof e?f&&Reflect.getMetadata("design:type",t,n)!==Set?c(o+": property is not a Set."):h(t,n,{ctor:Set,elementType:[e],emitDefaultValue:r.emitDefaultValue||!1,isRequired:r.isRequired||!1,key:n.toString(),name:r.name||n.toString(),deserializer:r.deserializer,serializer:r.serializer}):c(o+": could not resolve constructor of set elements at runtime.")}}function C(e,r,t){return void 0===t&&(t={}),function(n,o){var i="@jsonMapMember on "+p(n.constructor)+"."+String(o);"function"==typeof e?"function"==typeof r?f&&Reflect.getMetadata("design:type",n,o)!==Map?c(i+": property is not a Map."):h(n,o,{ctor:Map,elementType:[r],keyType:e,emitDefaultValue:t.emitDefaultValue||!1,isRequired:t.isRequired||!1,key:o.toString(),name:t.name||o.toString(),deserializer:t.deserializer,serializer:t.serializer}):c(i+": could not resolve constructor of map values at runtime."):c(i+": could not resolve constructor of map keys at runtime.")}}t.d(r,"TypedJSON",function(){return E}),t.d(r,"jsonObject",function(){return g}),t.d(r,"jsonMember",function(){return T}),t.d(r,"jsonArrayMember",function(){return b}),t.d(r,"jsonSetMember",function(){return M}),t.d(r,"jsonMapMember",function(){return C});var k=Object.assign||function(e){for(var r,t=1,n=arguments.length;t(type: { new (): T }): T|undefined\n{\n switch (type as any)\n {\n case Number:\n return 0 as any;\n\n case String:\n return \"\" as any;\n\n case Boolean:\n return false as any;\n\n case Array:\n return [] as any;\n\n default:\n return undefined;\n }\n}\n\n/**\n * Determines whether the specified type is a type that can be passed on \"as-is\" into `JSON.stringify`.\n * Values of these types don't need special conversion.\n * @param ctor The constructor of the type (wrapper constructor for primitive types, e.g. `Number` for `number`).\n */\nexport function isDirectlySerializableNativeType(type: Function): boolean\n{\n return !!(~[Date, Number, String, Boolean].indexOf(type as any));\n}\n\nexport function isTypeTypedArray(type: Function): boolean\n{\n return !!(~[Float32Array, Float64Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array]\n .indexOf(type as any));\n}\n\nexport function isPrimitiveValue(obj: any): boolean\n{\n switch (typeof obj)\n {\n case \"string\":\n case \"number\":\n case \"boolean\":\n return true;\n default:\n return (obj instanceof String || obj instanceof Number || obj instanceof Boolean);\n }\n}\n\nexport function isObject(value: any): value is Object\n{\n return typeof value === \"object\";\n}\n\n/**\n * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B').\n * @param A The supposed derived type.\n * @param B The supposed base type.\n */\nexport function isSubtypeOf(A: Function, B: Function)\n{\n return A === B || A.prototype instanceof B;\n}\n\nexport function logError(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.error === \"function\")\n {\n console.error.apply(console, [message].concat(optionalParams));\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"ERROR: \" + message].concat(optionalParams));\n }\n}\n\nexport function logMessage(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [message].concat(optionalParams));\n }\n}\n\nexport function logWarning(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.warn === \"function\")\n {\n console.warn.apply(console, [message].concat(optionalParams));\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"WARNING: \" + message].concat(optionalParams));\n }\n}\n\n/**\n * Checks if the value is considered defined (not undefined and not null).\n * @param value\n */\nexport function isValueDefined(value: T): value is Exclude\n{\n return !(typeof value === \"undefined\" || value === null);\n}\n\nexport function isInstanceOf(value: any, constructor: Function): boolean\n{\n if (typeof value === \"number\")\n {\n return (constructor === Number);\n }\n else if (typeof value === \"string\")\n {\n return (constructor === String);\n }\n else if (typeof value === \"boolean\")\n {\n return (constructor === Boolean);\n }\n else if (isObject(value))\n {\n return (value instanceof constructor);\n }\n\n return false;\n}\n\nexport const isReflectMetadataSupported =\n (typeof Reflect === \"object\" && typeof Reflect.getMetadata === \"function\");\n\n/**\n * Gets the name of a function.\n * @param fn The function whose name to get.\n */\nexport function nameof(fn: Function & { name?: string })\n{\n if (typeof fn.name === \"string\")\n {\n return fn.name;\n }\n else\n {\n return \"undefined\";\n }\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\n\nexport interface JsonMemberMetadata\n{\n /** If set, a default value will be emitted for uninitialized members. */\n emitDefaultValue?: boolean;\n\n /** Member name as it appears in the serialized JSON. */\n name: string;\n\n /** Property or field key of the json member. */\n key: string;\n\n /** Constuctor (type) reference of the member. */\n ctor?: Function;\n\n /** If set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** If the json member is an array, map or set, sets member options of elements/values. Subsequent values define the types of nested arrays. */\n elementType?: Function[];\n\n /** If the json member is a map, sets member options of array keys. */\n keyType?: Function;\n\n /** Custom deserializer to use. */\n deserializer?: (json: any) => any;\n\n /** Custom serializer to use. */\n serializer?: (value: any) => any;\n}\n\nexport class JsonObjectMetadata\n{\n //#region Static\n /**\n * Gets the name of a class as it appears in a serialized JSON string.\n * @param ctor The constructor of a class (with or without jsonObject).\n */\n public static getJsonObjectName(ctor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(ctor);\n return metadata ? nameof(metadata.classType) : nameof(ctor);\n }\n\n /**\n * Gets jsonObject metadata information from a class.\n * @param ctor The constructor class.\n */\n public static getFromConstructor(ctor: Function): JsonObjectMetadata|undefined\n {\n const prototype = ctor.prototype;\n if (!prototype)\n {\n return;\n }\n\n let metadata: JsonObjectMetadata|undefined;\n if (prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // The class prototype contains own jsonObject metadata\n metadata = prototype[METADATA_FIELD_KEY];\n }\n\n // Ignore implicitly added jsonObject (through jsonMember)\n if (metadata && metadata.isExplicitlyMarked)\n {\n return metadata;\n }\n\n // In the end maybe it is something which we can handle directly\n if (JsonObjectMetadata.doesHandleWithoutAnnotation(ctor))\n {\n const primitiveMeta = new JsonObjectMetadata(ctor);\n primitiveMeta.isExplicitlyMarked = true;\n // we do not store the metadata here to not modify builtin prototype\n return primitiveMeta;\n }\n }\n\n /**\n * Gets the known type name of a jsonObject class for type hint.\n * @param constructor The constructor class.\n */\n public static getKnownTypeNameFromType(constructor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(constructor);\n return metadata ? nameof(metadata.classType) : nameof(constructor);\n }\n\n private static doesHandleWithoutAnnotation(ctor: Function): boolean\n {\n return isDirectlySerializableNativeType(ctor) || isTypeTypedArray(ctor)\n || ctor === DataView || ctor === ArrayBuffer;\n }\n //#endregion\n\n constructor(\n classType: Function,\n ) {\n this.classType = classType;\n }\n\n public dataMembers: Map = new Map();\n\n public knownTypes: Set = new Set();\n\n public knownTypeMethodName?: string;\n\n /** Gets or sets the constructor function for the jsonObject. */\n public classType: Function;\n\n /**\n * Indicates whether this class was explicitly annotated with @jsonObject\n * or implicitly by @jsonMember\n */\n public isExplicitlyMarked: boolean = false;\n\n /**\n * Indicates whether this type is handled without annotation. This is usually\n * used for the builtin types (except for Maps, Sets, and normal Arrays).\n */\n public isHandledWithoutAnnotation: boolean = false;\n\n /** Name used to encode polymorphic type */\n public name?: string;\n\n public onDeserializedMethodName?: string;\n\n public initializerCallback?: (sourceObject: Object, rawSourceObject: Object) => Object;\n}\n\nexport function injectMetadataInformation(constructor: IndexedObject, propKey: string | symbol, metadata: JsonMemberMetadata)\n{\n const decoratorName = `@jsonMember on ${nameof(constructor.constructor)}.${String(propKey)}`; // For error messages.\n let objectMetadata: JsonObjectMetadata;\n\n // When a property decorator is applied to a static member, 'constructor' is a constructor function.\n // See: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Decorators.md#property-decorators\n // ... and static members are not supported here, so abort.\n if (typeof constructor === \"function\")\n {\n logError(`${decoratorName}: cannot use a static property.`);\n return;\n }\n\n // Methods cannot be serialized.\n // @ts-ignore symbol indexing is not supported by ts\n if (typeof constructor[propKey] === \"function\")\n {\n logError(`${decoratorName}: cannot use a method property.`);\n return;\n }\n\n if (!metadata || (!metadata.ctor && !metadata.deserializer))\n {\n logError(`${decoratorName}: JsonMemberMetadata has unknown ctor.`);\n return;\n }\n\n // Add jsonObject metadata to 'constructor' if not yet exists ('constructor' is the prototype).\n // NOTE: this will not fire up custom serialization, as 'constructor' must be explicitly marked with '@jsonObject' as well.\n if (!constructor.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // No *own* metadata, create new.\n objectMetadata = new JsonObjectMetadata(constructor.constructor);\n\n // Inherit @JsonMembers from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = constructor[METADATA_FIELD_KEY];\n if (parentMetadata) // && !constructor.hasOwnProperty(Helpers.METADATA_FIELD_KEY)\n {\n parentMetadata.dataMembers.forEach((_metadata, _propKey) => objectMetadata.dataMembers.set(_propKey, _metadata));\n }\n\n // ('constructor' is the prototype of the involved class, metadata information is added to this class prototype).\n Object.defineProperty(constructor, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // JsonObjectMetadata already exists on 'constructor'.\n objectMetadata = constructor[METADATA_FIELD_KEY];\n }\n\n if (!metadata.deserializer)\n {\n // @ts-ignore above is a check (!deser && !ctor)\n objectMetadata.knownTypes.add(metadata.ctor);\n }\n\n if (metadata.keyType)\n objectMetadata.knownTypes.add(metadata.keyType);\n\n if (metadata.elementType)\n metadata.elementType.forEach(elemCtor => objectMetadata.knownTypes.add(elemCtor));\n\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\n/**\n * Utility class, converts a simple/untyped javascript object-tree to a typed object-tree.\n * It is used after parsing a JSON-string.\n */\nexport class Deserializer\n{\n private _typeResolver: (sourceObject: Object, knownTypes: Map) => Function|undefined;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeResolver = (sourceObject: any, knownTypes: Map) =>\n {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: (sourceObject: Object, knownTypes: Map) => Function)\n {\n if (typeof typeResolverCallback !== \"function\") throw new TypeError(\"'typeResolverCallback' is not a function.\");\n\n this._typeResolver = typeResolverCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n public convertAsObject(\n sourceObject: IndexedObject,\n sourceObjectTypeInfo: IScopeTypeInfo,\n objectName = \"object\",\n ) {\n if (typeof sourceObject !== \"object\" || sourceObject === null)\n {\n this._errorHandler(new TypeError(`Cannot deserialize ${objectName}: 'sourceObject' must be a defined object.`));\n return undefined;\n }\n\n let expectedSelfType = sourceObjectTypeInfo.selfConstructor;\n let sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(expectedSelfType);\n let knownTypeConstructors = sourceObjectTypeInfo.knownTypes;\n\n if (sourceObjectMetadata)\n {\n // Merge known types received from \"above\" with known types defined on the current type.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n\n // Check if a type-hint is available from the source object.\n let typeFromTypeHint = this._typeResolver(sourceObject, knownTypeConstructors);\n\n if (typeFromTypeHint)\n {\n // Check if type hint is a valid subtype of the expected source type.\n if (isSubtypeOf(typeFromTypeHint, expectedSelfType))\n {\n // Hell yes.\n expectedSelfType = typeFromTypeHint;\n sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(typeFromTypeHint);\n\n if (sourceObjectMetadata)\n {\n // Also merge new known types from subtype.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n }\n }\n\n if (sourceObjectMetadata && sourceObjectMetadata.isExplicitlyMarked)\n {\n const sourceMetadata = sourceObjectMetadata;\n // Strong-typed deserialization available, get to it.\n // First deserialize properties into a temporary object.\n const sourceObjectWithDeserializedProperties = {} as IndexedObject;\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((memberMetadata, propKey) =>\n {\n const memberValue = sourceObject[propKey];\n const memberNameForDebug = `${nameof(sourceMetadata.classType)}.${propKey}`;\n\n let revivedValue;\n if (memberMetadata.deserializer) {\n revivedValue = memberMetadata.deserializer(memberValue);\n } else if (memberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n memberValue,\n {\n selfConstructor: memberMetadata.ctor,\n elementConstructor: memberMetadata.elementType,\n keyConstructor: memberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n memberNameForDebug,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${memberNameForDebug} thers is`\n + ` no constructor nor deserlization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue))\n {\n sourceObjectWithDeserializedProperties[memberMetadata.key] = revivedValue;\n }\n else if (memberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${memberNameForDebug}'.`));\n }\n });\n\n // Next, instantiate target object.\n let targetObject: IndexedObject;\n\n if (typeof sourceObjectMetadata.initializerCallback === \"function\")\n {\n try\n {\n targetObject = sourceObjectMetadata.initializerCallback(\n sourceObjectWithDeserializedProperties,\n sourceObject,\n );\n\n // Check the validity of user-defined initializer callback.\n if (!targetObject)\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + ` 'initializer' function returned undefined/null`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected.`,\n );\n }\n else if (!(targetObject instanceof sourceObjectMetadata.classType))\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + `'initializer' returned '${nameof(targetObject.constructor)}'`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected,`\n + `and '${nameof(targetObject.constructor)}' is not a subtype of`\n + ` '${nameof(sourceObjectMetadata.classType)}'`,\n );\n }\n }\n catch (e)\n {\n this._errorHandler(e);\n return undefined;\n }\n }\n else\n {\n targetObject = this._instantiateType(expectedSelfType);\n }\n\n // Finally, assign deserialized properties to target object.\n Object.assign(targetObject, sourceObjectWithDeserializedProperties);\n\n // Call onDeserialized method (if any).\n if (sourceObjectMetadata.onDeserializedMethodName)\n {\n if (typeof (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n else\n {\n this._errorHandler(new TypeError(\n `onDeserialized callback '${nameof(sourceObjectMetadata.classType)}.${sourceObjectMetadata.onDeserializedMethodName}' is not a method.`\n ));\n }\n }\n\n return targetObject;\n }\n else\n {\n // Untyped deserialization into Object instance.\n let targetObject = {} as IndexedObject;\n\n Object.keys(sourceObject).forEach(sourceKey =>\n {\n targetObject[sourceKey] = this.convertSingleValue(sourceObject[sourceKey], {\n selfConstructor: sourceObject[sourceKey].constructor,\n knownTypes: sourceObjectTypeInfo.knownTypes,\n elementConstructor: sourceObjectTypeInfo.elementConstructor,\n keyConstructor: sourceObjectTypeInfo.keyConstructor\n }, sourceKey);\n });\n\n return targetObject;\n }\n }\n\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (!isValueDefined(sourceObject))\n {\n return sourceObject;\n }\n else if (this._isDirectlyDeserializableNativeType(expectedSelfType))\n {\n if (sourceObject.constructor === expectedSelfType)\n {\n return sourceObject;\n }\n else\n {\n throw new TypeError(this._makeTypeErrorMessage(nameof(expectedSelfType), sourceObject.constructor, memberName));\n }\n }\n else if (expectedSelfType === Date)\n {\n // Support for Date with ISO 8601 format, or with numeric timestamp (milliseconds elapsed since the Epoch).\n // ISO 8601 spec.: https://www.w3.org/TR/NOTE-datetime\n\n if (typeof sourceObject === \"string\" || (typeof sourceObject === \"number\" && sourceObject > 0))\n return new Date(sourceObject as any);\n else\n this._throwTypeMismatchError(\"Date\", \"an ISO-8601 string\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float32Array)\n {\n // Deserialize Float32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float32Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float64Array)\n {\n // Deserialize Float64Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float64Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float64Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8Array)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8ClampedArray)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8ClampedArray(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8ClampedArray\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint16Array)\n {\n // Deserialize Uint16Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint16Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint16Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint32Array)\n {\n // Deserialize Uint32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint32Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === ArrayBuffer)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToArrayBuffer(sourceObject);\n else\n this._throwTypeMismatchError(\"ArrayBuffer\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === DataView)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToDataView(sourceObject);\n else\n this._throwTypeMismatchError(\"DataView\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Array)\n {\n if (sourceObject instanceof Array)\n return this.convertAsArray(sourceObject, typeInfo, memberName);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (sourceObject instanceof Array)\n return this.convertAsSet(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (sourceObject instanceof Array)\n return this.convertAsMap(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Map\", \"a source array of key-value-pair objects\", srcTypeNameForDebug, memberName);\n }\n else if (sourceObject && typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n public convertAsArray(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\"): any[]\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return [];\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Array: missing constructor reference of Array elements.`));\n return [];\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n return sourceObject.map(element =>\n {\n // If an array element fails to deserialize, substitute with undefined. This is so that the original ordering is not interrupted by faulty\n // entries, as an Array is ordered.\n try\n {\n return this.convertSingleValue(element, elementTypeInfo);\n }\n catch (e)\n {\n this._errorHandler(e);\n\n // Keep filling the array here with undefined to keep original ordering.\n // Note: this is just aesthetics, not returning anything produces the same result.\n return undefined;\n }\n });\n }\n\n public convertAsSet(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return new Set();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Set: missing constructor reference of Set elements.`));\n return new Set();\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n let resultSet = new Set();\n\n sourceObject.forEach((element, i) =>\n {\n try\n {\n resultSet.add(this.convertSingleValue(element, elementTypeInfo, memberName + `[${i}]`));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n\n if (!typeInfo.keyConstructor)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing key constructor.`));\n return new Map();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing value constructor.`));\n return new Map();\n }\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.keyConstructor,\n knownTypes: typeInfo.knownTypes\n };\n\n let valueTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n let resultMap = new Map();\n\n sourceObject.forEach((element: any) =>\n {\n try\n {\n let key = this.convertSingleValue(element.key, keyTypeInfo);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(key, this.convertSingleValue(\n element.value, valueTypeInfo, `${memberName}[${key}]`,\n ));\n }\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Map is not ordered,\n // and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultMap;\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string = \"object\",\n ) {\n throw new TypeError(\n `Could not deserialize ${memberName} as ${targetType}:`\n + ` expected ${expectedSourceType}, got ${actualSourceType}.`,\n );\n }\n\n private _makeTypeErrorMessage(expectedType: Function | string, actualType: Function | string, memberName = \"object\")\n {\n let expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n let actualTypeName = (typeof actualType === \"function\") ? nameof(actualType) : actualType;\n\n return `Could not deserialize ${memberName}: expected '${expectedTypeName}', got '${actualTypeName}'.`;\n }\n\n private _instantiateType(ctor: any)\n {\n return new ctor();\n }\n\n private _mergeKnownTypes(...knownTypeMaps: Array>)\n {\n let result = new Map();\n\n knownTypeMaps.forEach(knownTypes =>\n {\n knownTypes.forEach((ctor, name) =>\n {\n if (this._nameResolver)\n {\n result.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n result.set(name, ctor);\n }\n });\n });\n\n return result;\n }\n\n private _createKnownTypesMap(knowTypes: Set)\n {\n const map = new Map();\n\n knowTypes.forEach(ctor =>\n {\n if (this._nameResolver)\n {\n map.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n const knownTypeMeta = JsonObjectMetadata.getFromConstructor(ctor);\n const name = knownTypeMeta && knownTypeMeta.isExplicitlyMarked && knownTypeMeta.name\n ? knownTypeMeta.name\n : ctor.name;\n map.set(name, ctor);\n }\n });\n\n return map;\n }\n\n private _isDirectlyDeserializableNativeType(ctor: any)\n {\n return ~([Number, String, Boolean].indexOf(ctor));\n }\n\n public convertNativeObject(sourceObject: any)\n {\n return sourceObject;\n }\n\n private _stringToArrayBuffer(str: string)\n {\n let buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\n let bufView = new Uint16Array(buf);\n\n for (let i = 0, strLen = str.length; i < strLen; i++)\n {\n bufView[i] = str.charCodeAt(i);\n }\n\n return buf;\n }\n\n private _stringToDataView(str: string)\n {\n return new DataView(this._stringToArrayBuffer(str));\n }\n}\n","import { nameof, logError, isValueDefined, isInstanceOf, isTypeTypedArray, isDirectlySerializableNativeType } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfType: Function;\n elementTypes?: Function[];\n keyType?: Function;\n}\n\nexport interface IScopeArrayTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Array;\n elementTypes: Function[];\n}\n\nfunction isArrayTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeArrayTypeInfo {\n return typeInfo.selfType === Array;\n}\n\nexport interface IScopeSetTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Set;\n elementTypes: [Function];\n}\n\nfunction isSetTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeSetTypeInfo {\n return typeInfo.selfType === Set;\n}\n\nexport interface IScopeMapTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Map;\n elementTypes: [Function];\n keyType: Function;\n}\n\nfunction isMapTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeMapTypeInfo {\n return typeInfo.selfType === Map;\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class instances, and so on) to an untyped javascript object (also\n * called \"simple javascript object\"), and emits any necessary type hints in the process (for polymorphism).\n *\n * The converted object tree is what will be given to `JSON.stringify` to convert to string as the last step, the serialization is basically like:\n *\n * (1) typed object-tree -> (2) simple JS object-tree -> (3) JSON-string\n */\nexport class Serializer\n{\n private _typeHintEmitter: (targetObject: IndexedObject, sourceObject: IndexedObject, expectedSourceType: Function, sourceTypeMetadata?: JsonObjectMetadata) => void;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeHintEmitter = (targetObject, sourceObject, expectedSourceType, sourceTypeMetadata?: JsonObjectMetadata) =>\n {\n // By default, we put a \"__type\" property on the output object if the actual object is not the same as the expected one, so that deserialization\n // will know what to deserialize into (given the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n const name = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n // TODO: Perhaps this can work correctly without string-literal access?\n // tslint:disable-next-line:no-string-literal\n targetObject[\"__type\"] = name;\n }\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setTypeHintEmitter(typeEmitterCallback: (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void)\n {\n if (typeof typeEmitterCallback !== \"function\")\n {\n throw new TypeError(\"'typeEmitterCallback' is not a function.\");\n }\n\n this._typeHintEmitter = typeEmitterCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n /**\n * Convert a value of any supported serializable type.\n * The value type will be detected, and the correct serialization method will be called.\n */\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName: string = \"object\"): any\n {\n if (!isValueDefined(sourceObject)) return;\n\n if (!isInstanceOf(sourceObject, typeInfo.selfType))\n {\n let expectedName = nameof(typeInfo.selfType);\n let actualName = nameof(sourceObject.constructor);\n\n this._errorHandler(new TypeError(`Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`));\n return;\n }\n\n if (isDirectlySerializableNativeType(typeInfo.selfType))\n {\n return sourceObject;\n }\n else if (typeInfo.selfType === ArrayBuffer)\n {\n return this.convertAsArrayBuffer(sourceObject);\n }\n else if (typeInfo.selfType === DataView)\n {\n return this.convertAsDataView(sourceObject);\n }\n else if (isArrayTypeInfo(typeInfo))\n {\n return this.convertAsArray(sourceObject, typeInfo.elementTypes, memberName);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName);\n }\n else if (isTypeTypedArray(typeInfo.selfType))\n {\n return this.convertAsTypedArray(sourceObject);\n }\n else if (typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple javascript object for serialization.\n */\n public convertAsObject(sourceObject: IndexedObject, typeInfo: IScopeTypeInfo, memberName?: string)\n {\n let sourceTypeMetadata: JsonObjectMetadata|undefined;\n let targetObject: IndexedObject;\n\n if (sourceObject.constructor !== typeInfo.selfType && sourceObject instanceof typeInfo.selfType)\n {\n // The source object is not of the expected type, but it is a valid subtype.\n // This is OK, and we'll proceed to gather object metadata from the subtype instead.\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(sourceObject.constructor);\n }\n else\n {\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(typeInfo.selfType);\n }\n\n if (sourceTypeMetadata)\n {\n const sourceMeta = sourceTypeMetadata;\n // Strong-typed serialization available.\n // We'll serialize by members that have been marked with @jsonMember (including array/set/map members), and perform recursive conversion on\n // each of them. The converted objects are put on the 'targetObject', which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n sourceTypeMetadata.dataMembers.forEach((memberMetadata) =>\n {\n if (memberMetadata.serializer) {\n targetObject[memberMetadata.name] =\n memberMetadata.serializer(sourceObject[memberMetadata.key]);\n } else if (memberMetadata.ctor) {\n targetObject[memberMetadata.name] = this.convertSingleValue(\n sourceObject[memberMetadata.key],\n {\n selfType: memberMetadata.ctor,\n elementTypes: memberMetadata.elementType,\n keyType: memberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${memberMetadata.key}`,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${memberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n });\n }\n else\n {\n // Untyped serialization, \"as-is\", we'll just pass the object on.\n // We'll clone the source object, because type hints are added to the object itself, and we don't want to modify to the original object.\n targetObject = { ...sourceObject };\n }\n\n // Add type-hint.\n this._typeHintEmitter(targetObject, sourceObject, typeInfo.selfType, sourceTypeMetadata);\n\n return targetObject;\n }\n\n /**\n * Performs the conversion of an array of typed objects (or primitive values) to an array of simple javascript objects (or primitive values) for\n * serialization.\n * @param expectedElementType The expected type of elements. If the array is supposed to be multi-dimensional, subsequent elements define lower dimensions.\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsArray(sourceObject: any[], expectedElementType: Function[], memberName = \"object\"): any[]\n {\n if (expectedElementType.length === 0 || !expectedElementType[0])\n throw new TypeError(`Could not serialize ${memberName} as Array: missing element type definition.`);\n\n // Check the type of each element, individually.\n // If at least one array element type is incorrect, we return undefined, which results in no value emitted during serialization.\n // This is so that invalid element types don't unexpectedly alter the ordering of other, valid elements, and that no unexpected undefined values are in\n // the emitted array.\n sourceObject.forEach((element, i) =>\n {\n if (!isInstanceOf(element, expectedElementType[0]))\n {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]: expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [], // For multidimensional arrays.\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(element => this.convertSingleValue(element, typeInfoForElements, memberName));\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @returns\n */\n public convertAsSet(sourceObject: Set, expectedElementType: Function, memberName = \"object\"): any[]\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Set: missing element type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n };\n\n // For debugging and error tracking.\n if (memberName) memberName += \"[]\";\n\n let resultArray: any[] = [];\n\n // Convert each element of the set, and put it into an output array.\n // The output array is the one serialized, as JSON.stringify does not support Set serialization. (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName);\n\n // Add to output if the source element was undefined, OR the converted element is defined. This will add intentionally undefined values to output,\n // but not values that became undefined DURING serializing (usually because of a type-error).\n if (!isValueDefined(element) || isValueDefined(resultElement))\n {\n resultArray.push(resultElement);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a map of typed objects (or primitive values) into an array of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsMap(sourceObject: Map, expectedKeyType: Function, expectedElementType: Function, memberName = \"object\"): Array<{ key: any, value: any }>\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing value type definition.`);\n\n if (!expectedKeyType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing key type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n elementTypes: [expectedElementType]\n };\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfType: expectedKeyType\n };\n\n if (memberName) memberName += \"[]\";\n\n let resultArray: Array<{ key: any, value: any }> = [];\n\n // Convert each *entry* in the map to a simple javascript object with key and value properties.\n sourceObject.forEach((value, key) =>\n {\n let resultKeyValuePairObj = {\n key: this.convertSingleValue(key, keyTypeInfo, memberName),\n value: this.convertSingleValue(value, elementTypeInfo, memberName)\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n if (isValueDefined(resultKeyValuePairObj.key) && isValueDefined(resultKeyValuePairObj.value))\n {\n resultArray.push(resultKeyValuePairObj);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a typed javascript array to a simple untyped javascript array.\n * This is needed because typed arrays are otherwise serialized as objects, so we'll end up with something like \"{ 0: 0, 1: 1, ... }\".\n *\n * @param sourceObject\n * @returns\n */\n public convertAsTypedArray(sourceObject: ArrayBufferView)\n {\n return Array.from(sourceObject as any);\n }\n\n /**\n * Performs the conversion of a raw ArrayBuffer to a string.\n */\n public convertAsArrayBuffer(buffer: ArrayBuffer)\n {\n // ArrayBuffer -> 16-bit character codes -> character array -> joined string.\n return Array.from(new Uint16Array(buffer)).map(charCode => String.fromCharCode(charCode)).join(\"\");\n }\n\n /**\n * Performs the conversion of DataView, converting its internal ArrayBuffer to a string and returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n}\n","import { Constructor, ParameterlessConstructor } from \"./types\";\nimport { METADATA_FIELD_KEY } from \"./helpers\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IJsonObjectOptionsBase\n{\n /**\n * An array of known types to recognize when encountering type-hints,\n * or the name of a static method used for determining known types.\n */\n knownTypes?: Function[] | string;\n\n /**\n * The name of a static or instance method to call when deserialization\n * of the object is completed.\n */\n onDeserialized?: string;\n\n /**\n * The name used to differentiate between different polymorphic types.\n */\n name?: string;\n}\n\nexport interface IJsonObjectOptionsWithInitializer extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer: (sourceObject: T, rawSourceObject: T) => T;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer?: (sourceObject: T, rawSourceObject: T) => T;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional settings. The 'initializer' setting must be specified.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptionsWithInitializer): (target: Constructor) => void;\n\n/**\n * Marks that a class is serializable using TypedJSON, with additional settings.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptions): (target: ParameterlessConstructor) => void;\n\n/**\n * Marks that a class with a parameterless constructor is serializable using TypedJSON.\n */\nexport function jsonObject(target: ParameterlessConstructor): void;\n\nexport function jsonObject(optionsOrTarget?: IJsonObjectOptions | Constructor\n): ((target: Constructor) => void) | void {\n let options: IJsonObjectOptions;\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n options = {};\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n options = optionsOrTarget || {};\n }\n\n function decorator(\n target: Function\n ): void {\n let objectMetadata: JsonObjectMetadata;\n\n // Create or obtain JsonObjectMetadata object.\n if (!target.prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // Target has no JsonObjectMetadata associated with it yet, create it now.\n objectMetadata = new JsonObjectMetadata(target);\n\n // Inherit json members and known types from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = target.prototype[METADATA_FIELD_KEY];\n if (parentMetadata)\n {\n parentMetadata.dataMembers\n .forEach((memberMetadata, propKey) =>\n objectMetadata.dataMembers.set(propKey, memberMetadata));\n parentMetadata.knownTypes\n .forEach((knownType) => objectMetadata.knownTypes.add(knownType));\n }\n\n Object.defineProperty(target.prototype, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // Target already has JsonObjectMetadata associated with it.\n objectMetadata = target.prototype[METADATA_FIELD_KEY];\n objectMetadata.classType = target;\n }\n\n // Fill JsonObjectMetadata.\n objectMetadata.isExplicitlyMarked = true;\n objectMetadata.onDeserializedMethodName = options.onDeserialized;\n // T extend Object so it is fine\n objectMetadata.initializerCallback = options.initializer as any;\n if (options.name)\n {\n objectMetadata.name = options.name;\n }\n\n // Obtain known-types.\n if (typeof options.knownTypes === \"string\")\n {\n objectMetadata.knownTypeMethodName = options.knownTypes;\n }\n else if (options.knownTypes instanceof Array)\n {\n options.knownTypes\n .filter(knownType => !!knownType)\n .forEach(knownType => objectMetadata.knownTypes.add(knownType));\n }\n }\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n decorator(optionsOrTarget);\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n return decorator;\n }\n}\n","import {\n nameof, logError, isReflectMetadataSupported, isValueDefined, logWarning, isSubtypeOf\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions\n{\n /**\n * Sets the constructor of the property.\n * Optional with ReflectDecorators.\n */\n constructor?: Function;\n\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted if the property is uninitialized/undefined. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name. */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property is part of the object when serializing, with additional options.\n * Omitting the 'constructor' option requires ReflectDecorators and that the property type is always explicitly declared.\n * @param options Additional options.\n */\nexport function jsonMember(options: IJsonMemberOptions): PropertyDecorator;\n\n/**\n * Specifies that a property is part of the object when serializing.\n * This call signature requires ReflectDecorators and that the property type is always explicitly declared.\n */\nexport function jsonMember(target: Object, propertyKey: string | symbol): void;\n\nexport function jsonMember(optionsOrTarget?: IJsonMemberOptions | Object, propKey?: string | symbol): PropertyDecorator | void\n{\n if (optionsOrTarget instanceof Object && (typeof propKey === \"string\" || typeof propKey === \"symbol\"))\n {\n const target = optionsOrTarget;\n // For error messages.\n const decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(propKey)}`;\n\n // jsonMember used directly, no additional information directly available besides target and propKey.\n // Obtain property constructor through ReflectDecorators.\n if (isReflectMetadataSupported)\n {\n const reflectPropCtor = Reflect.getMetadata(\"design:type\", target, propKey) as Function;\n\n if (!reflectPropCtor)\n {\n logError(`${decoratorName}: could not resolve detected property constructor at runtime.`);\n return;\n }\n\n if (isSpecialPropertyType(decoratorName, reflectPropCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: reflectPropCtor,\n key: propKey.toString(),\n name: propKey.toString(),\n });\n }\n else\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n else\n {\n // jsonMember used as a decorator factory.\n return (target: Object, _propKey: string | symbol) =>\n {\n let options: IJsonMemberOptions = optionsOrTarget || {};\n let propCtor: Function|undefined;\n let decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(_propKey)}`; // For error messages.\n\n if (options.hasOwnProperty(\"constructor\"))\n {\n if (!isValueDefined(options.constructor))\n {\n logError(`${decoratorName}: cannot resolve specified property constructor at runtime.`);\n return;\n }\n\n // Property constructor has been specified. Use ReflectDecorators (if available) to check whether that constructor is correct. Warn if not.\n if (isReflectMetadataSupported && !isSubtypeOf(options.constructor, Reflect.getMetadata(\"design:type\", target, _propKey)))\n {\n logWarning(`${decoratorName}: detected property type does not match 'constructor' option.`);\n }\n\n propCtor = options.constructor;\n }\n else\n {\n // Use ReflectDecorators to obtain property constructor.\n if (isReflectMetadataSupported)\n {\n propCtor = Reflect.getMetadata(\"design:type\", target, _propKey) as Function;\n\n if (!propCtor)\n {\n logError(`${decoratorName}: cannot resolve detected property constructor at runtime.`);\n return;\n }\n }\n else if (!options.deserializer)\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n\n if (isSpecialPropertyType(decoratorName, propCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, _propKey, {\n ctor: propCtor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: _propKey.toString(),\n name: options.name || _propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n }\n}\n\nfunction isSpecialPropertyType(decoratorName: string, propCtor?: Function)\n{\n if (propCtor === Array)\n {\n logError(`${decoratorName}: property is an Array. Use the jsonArrayMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Set)\n {\n logError(`${decoratorName}: property is a Set. Use the jsonSetMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Map)\n {\n logError(`${decoratorName}: property is a Map. Use the jsonMapMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n return false;\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, an empty array is emitted if the property is undefined/uninitialized. */\n emitDefaultValue?: boolean;\n\n /** Sets array dimensions (e.g. 1 for 'number[]' or 2 for 'number[][]'). Defaults to 1. */\n dimensions?: number;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property, of type array, is part of an object when serializing.\n * @param elementConstructor Constructor of array elements (e.g. 'Number' for 'number[]', or 'Date' for 'Date[]').\n * @param options Additional options.\n */\nexport function jsonArrayMember(elementConstructor: Function, options: IJsonArrayMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonArrayMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of array elements at runtime.`);\n return;\n }\n\n const dimensions = options.dimensions === undefined ? 1 : options.dimensions;\n if (!isNaN(dimensions) && dimensions < 1)\n {\n logError(`${decoratorName}: 'dimensions' option must be at least 1.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonArrayMember' has been used on an array.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Array)\n {\n logError(`${decoratorName}: property is not an Array.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n\nfunction createArrayElementType(elementCtor: Function, dimensions: number) {\n const elementTypes = new Array(dimensions).fill(Array, 0, -1);\n elementTypes[dimensions-1] = elementCtor;\n return elementTypes;\n}\n","import { nameof } from \"./helpers\";\nimport { IJsonMemberOptions } from \"./json-member\";\nimport { JsonMemberMetadata, JsonObjectMetadata, injectMetadataInformation } from \"./metadata\";\nimport * as Helpers from \"./helpers\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Set.\n * @param elementConstructor Constructor of set elements (e.g. 'Number' for Set or 'Date' for Set).\n * @param options Additional options.\n */\nexport function jsonSetMember(elementConstructor: Function, options: IJsonSetMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n var decoratorName = `@jsonSetMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n Helpers.logError(`${decoratorName}: could not resolve constructor of set elements at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonSetMember' has been used on a set. Warn if not.\n if (Helpers.isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n Helpers.logError(`${decoratorName}: property is not a Set.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Map.\n * @param keyConstructor Constructor of map keys (e.g. 'Number' for 'Map').\n * @param valueConstructor Constructor of map values (e.g. 'Date' for 'Map').\n * @param options Additional options.\n */\nexport function jsonMapMember(keyConstructor: Function, valueConstructor: Function, options: IJsonMapMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonMapMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof keyConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map keys at runtime.`);\n return;\n }\n\n if (typeof valueConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map values at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonMapMember' has been used on a map. Warn if not.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Map)\n {\n logError(`${decoratorName}: property is not a Map.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, logWarning } from './typedjson/helpers';\nimport { Constructor } from \"./typedjson/types\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { Serializer } from \"./typedjson/serializer\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\n\nexport interface ITypedJSONSettings\n{\n /**\n * Sets the handler callback to invoke on errors during serializing and deserializing.\n * Re-throwing errors in this function will halt serialization/deserialization.\n * The default behavior is to log errors to the console.\n */\n errorHandler?: (e: Error) => void;\n\n /**\n * Sets a callback that determines the constructor of the correct sub-type of polymorphic\n * objects while deserializing.\n * The default behavior is to read the type-name from the '__type' property of 'sourceObject',\n * and look it up in 'knownTypes'.\n * The constructor of the sub-type should be returned.\n */\n typeResolver?: (sourceObject: Object, knownTypes: Map) => Function;\n\n nameResolver?: (ctor: Function) => string;\n\n /**\n * Sets a callback that writes type-hints to serialized objects.\n * The default behavior is to write the type-name to the '__type' property, if a derived type\n * is present in place of a base type.\n */\n typeHintEmitter?:\n (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void;\n\n /**\n * Sets the amount of indentation to use in produced JSON strings.\n * Default value is 0, or no indentation.\n */\n indent?: number;\n\n replacer?: (key: string, value: any) => any;\n\n knownTypes?: Array>;\n}\n\nexport class TypedJSON\n{\n //#region Static\n public static parse(\n object: any, rootType: Constructor, settings?: ITypedJSONSettings,\n ): T|undefined {\n return new TypedJSON(rootType, settings).parse(object);\n }\n\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: 1\n ): T[];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 2\n ): T[][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 3\n ): T[][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 4\n ): T[][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 5\n ): T[][][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: number\n ): any[] {\n return new TypedJSON(elementType, settings).parseAsArray(object, dimensions as any);\n }\n\n public static parseAsSet(\n object: any, elementType: Constructor, settings?: ITypedJSONSettings,\n ): Set {\n return new TypedJSON(elementType, settings).parseAsSet(object);\n }\n\n public static parseAsMap(\n object: any,\n keyType: Constructor,\n valueType: Constructor,\n settings?: ITypedJSONSettings,\n ): Map {\n return new TypedJSON(valueType, settings).parseAsMap(object, keyType);\n }\n\n public static toPlainJson(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): JsonTypes {\n return new TypedJSON(rootType, settings).toPlainJson(object);\n }\n\n public static toPlainArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): Object[];\n public static toPlainArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): Object[][];\n public static toPlainArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): Object[][][];\n public static toPlainArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): Object[][][][];\n public static toPlainArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): Object[][][][][];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): any[];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): any[] {\n return new TypedJSON(elementType, settings).toPlainArray(object, dimensions);\n }\n\n public static toPlainSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n public static stringify(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(rootType, settings).stringify(object);\n }\n\n public static stringifyAsArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsArray(object, dimensions);\n }\n\n public static stringifyAsSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static stringifyAsMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n private static _globalConfig: ITypedJSONSettings;\n\n public static setGlobalConfig(config: ITypedJSONSettings)\n {\n if (this._globalConfig)\n {\n Object.assign(this._globalConfig, config);\n }\n else\n {\n this._globalConfig = config;\n }\n }\n\n //#endregion\n\n private serializer: Serializer = new Serializer();\n private deserializer: Deserializer = new Deserializer();\n private globalKnownTypes: Array> = [];\n private indent: number = 0;\n private rootConstructor: Constructor;\n private errorHandler: (e: Error) => void;\n private nameResolver: (ctor: Function) => string;\n private replacer?: (key: string, value: any) => any;\n\n /**\n * Creates a new TypedJSON instance to serialize (stringify) and deserialize (parse) object\n * instances of the specified root class type.\n * @param rootType The constructor of the root class type.\n * @param settings Additional configuration settings.\n */\n constructor(rootConstructor: Constructor, settings?: ITypedJSONSettings)\n {\n let rootMetadata = JsonObjectMetadata.getFromConstructor(rootConstructor);\n\n if (!rootMetadata || (!rootMetadata.isExplicitlyMarked && !rootMetadata.isHandledWithoutAnnotation))\n {\n throw new TypeError(\"The TypedJSON root data type must have the @jsonObject decorator used.\");\n }\n\n this.nameResolver = (ctor) => nameof(ctor);\n this.rootConstructor = rootConstructor;\n this.errorHandler = (error) => logError(error);\n\n if (settings)\n {\n this.config(settings);\n }\n else if (TypedJSON._globalConfig)\n {\n this.config({});\n }\n }\n\n /**\n * Configures TypedJSON through a settings object.\n * @param settings The configuration settings object.\n */\n public config(settings: ITypedJSONSettings)\n {\n if (TypedJSON._globalConfig)\n {\n settings = {\n ...TypedJSON._globalConfig,\n ...settings\n };\n\n if (settings.knownTypes && TypedJSON._globalConfig.knownTypes)\n {\n // Merge known-types (also de-duplicate them, so Array -> Set -> Array).\n settings.knownTypes = Array.from(new Set(\n settings.knownTypes.concat(TypedJSON._globalConfig.knownTypes),\n ));\n }\n }\n\n if (settings.errorHandler)\n {\n this.errorHandler = settings.errorHandler;\n this.deserializer.setErrorHandler(settings.errorHandler);\n this.serializer.setErrorHandler(settings.errorHandler);\n }\n\n if (settings.replacer) this.replacer = settings.replacer;\n if (settings.typeResolver) this.deserializer.setTypeResolver(settings.typeResolver);\n if (settings.typeHintEmitter) this.serializer.setTypeHintEmitter(settings.typeHintEmitter);\n if (settings.indent) this.indent = settings.indent;\n\n if (settings.nameResolver)\n {\n this.nameResolver = settings.nameResolver;\n this.deserializer.setNameResolver(settings.nameResolver);\n // this.serializer.set\n }\n\n if (settings.knownTypes)\n {\n // Type-check knownTypes elements to recognize errors in advance.\n settings.knownTypes.forEach((knownType, i) =>\n {\n // tslint:disable-next-line:no-null-keyword\n if (typeof knownType === \"undefined\" || knownType === null)\n {\n logWarning(\n `TypedJSON.config: 'knownTypes' contains an undefined/null value (element ${i}).`);\n }\n });\n\n this.globalKnownTypes = settings.knownTypes;\n }\n }\n\n /**\n * Converts a JSON string to the root class type.\n * @param object The JSON to parse and convert.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns Deserialized T or undefined if there were errors.\n */\n public parse(object: any): T|undefined\n {\n const json = JSON.parse(object);\n\n let rootMetadata = JsonObjectMetadata.getFromConstructor(this.rootConstructor);\n let result: T|undefined;\n let knownTypes = new Map();\n\n this.globalKnownTypes.filter(ktc => ktc).forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n\n if (rootMetadata)\n {\n rootMetadata.knownTypes.forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n }\n\n try\n {\n result = this.deserializer.convertSingleValue(json, {\n selfConstructor: this.rootConstructor,\n knownTypes: knownTypes,\n }) as T;\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n\n return result;\n }\n\n public parseAsArray(object: any, dimensions?: 1): T[];\n public parseAsArray(object: any, dimensions: 2): T[][];\n public parseAsArray(object: any, dimensions: 3): T[][][];\n public parseAsArray(object: any, dimensions: 4): T[][][][];\n public parseAsArray(object: any, dimensions: 5): T[][][][][];\n public parseAsArray(object: any, dimensions: number): any[];\n public parseAsArray(object: any, dimensions: number = 1): any[]\n {\n const json = JSON.parse(object);\n if (json instanceof Array)\n {\n return this.deserializer.convertAsArray(json, {\n selfConstructor: Array,\n elementConstructor: new Array(dimensions - 1)\n .fill(Array)\n .concat(this.rootConstructor),\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define an Array`\n + `, but got ${typeof json}.`));\n }\n\n return [];\n }\n\n public parseAsSet(object: any): Set\n {\n const json = JSON.parse(object);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsSet(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes)\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Set();\n }\n\n public parseAsMap(object: any, keyConstructor: Constructor): Map\n {\n const json = JSON.parse(object);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsMap(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n keyConstructor: keyConstructor\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Map();\n }\n\n /**\n * Converts an instance of the specified class type to a plain JSON object.\n * @param object The instance to convert to a JSON string.\n * @returns Serialized object or undefined if an error has occured.\n */\n public toPlainJson(object: T): JsonTypes\n {\n try\n {\n return this.serializer.convertSingleValue(object, {\n selfType: this.rootConstructor\n });\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainArray(object: T[], dimensions?: 1): Object[];\n public toPlainArray(object: T[][], dimensions: 2): Object[][];\n public toPlainArray(object: T[][][], dimensions: 3): Object[][][];\n public toPlainArray(object: T[][][][], dimensions: 4): Object[][][][];\n public toPlainArray(object: T[][][][][], dimensions: 5): Object[][][][][];\n public toPlainArray(object: any[], dimensions: 1|2|3|4|5 = 1): Object[]|undefined\n {\n try\n {\n const elementConstructorArray =\n new Array(dimensions - 1).fill(Array).concat(this.rootConstructor);\n return this.serializer.convertAsArray(object, elementConstructorArray);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainSet(object: Set): Object[]|undefined\n {\n try\n {\n return this.serializer.convertAsSet(object, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainMap(object: Map, keyConstructor: Constructor): { key: any, value: any }[]|undefined\n {\n try\n {\n return this.serializer.convertAsMap(object, keyConstructor, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n /**\n * Converts an instance of the specified class type to a JSON string.\n * @param object The instance to convert to a JSON string.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns String with the serialized object or an empty string if an error has occured, but\n * the errorHandler did not throw.\n */\n public stringify(object: T): string\n {\n const result = this.toPlainJson(object);\n if (result === undefined) {\n return '';\n }\n return JSON.stringify(result, this.replacer, this.indent);\n }\n\n public stringifyAsArray(object: T[], dimensions?: 1): string;\n public stringifyAsArray(object: T[][], dimensions: 2): string;\n public stringifyAsArray(object: T[][][], dimensions: 3): string;\n public stringifyAsArray(object: T[][][][], dimensions: 4): string;\n public stringifyAsArray(object: T[][][][][], dimensions: 5): string;\n public stringifyAsArray(object: any[], dimensions: any): string\n {\n return JSON.stringify(this.toPlainArray(object, dimensions), this.replacer, this.indent);\n }\n\n public stringifyAsSet(object: Set): string\n {\n return JSON.stringify(this.toPlainSet(object), this.replacer, this.indent);\n }\n\n public stringifyAsMap(object: Map, keyConstructor: Constructor): string\n {\n return JSON.stringify(this.toPlainMap(object, keyConstructor), this.replacer, this.indent);\n }\n\n private _mapKnownTypes(constructors: Array>)\n {\n let map = new Map>();\n\n constructors.filter(ctor => ctor).forEach(ctor => map.set(this.nameResolver(ctor), ctor));\n\n return map;\n }\n}\n\nexport { jsonObject } from \"./typedjson/json-object\";\nexport { jsonMember } from \"./typedjson/json-member\";\nexport { jsonArrayMember } from \"./typedjson/json-array-member\";\nexport { jsonSetMember } from \"./typedjson/json-set-member\";\nexport { jsonMapMember } from \"./typedjson/json-map-member\";\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://typedjson/webpack/universalModuleDefinition","webpack://typedjson/webpack/bootstrap","webpack://typedjson/./src/typedjson/helpers.ts","webpack://typedjson/./src/typedjson/metadata.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/typedjson/serializer.ts","webpack://typedjson/./src/typedjson/json-object.ts","webpack://typedjson/./src/typedjson/json-member.ts","webpack://typedjson/./src/typedjson/json-array-member.ts","webpack://typedjson/./src/typedjson/json-set-member.ts","webpack://typedjson/./src/typedjson/json-map-member.ts","webpack://typedjson/./src/typedjson.ts"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","r","value","n","__esModule","object","property","prototype","hasOwnProperty","p","s","METADATA_FIELD_KEY","isDirectlySerializableNativeType","type","Date","Number","String","Boolean","indexOf","isTypeTypedArray","Float32Array","Float64Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","parseToJSObject","json","expectedType","jsonStr","expectsTypesSerializedAsStrings","ArrayBuffer","DataView","hasQuotes","length","isInteger","test","trim","shouldOmitParseString","JSON","parse","isSubtypeOf","A","B","logError","message","optionalParams","_i","arguments","console","error","apply","concat","log","logWarning","warn","isValueDefined","isInstanceOf","constructor","isObject","isReflectMetadataSupported","Reflect","getMetadata","nameof","fn","metadata_JsonObjectMetadata","JsonObjectMetadata","classType","dataMembers","Map","knownTypes","Set","isExplicitlyMarked","isHandledWithoutAnnotation","getJsonObjectName","ctor","metadata","getFromConstructor","doesHandleWithoutAnnotation","primitiveMeta","getKnownTypeNameFromType","injectMetadataInformation","propKey","objectMetadata","decoratorName","deserializer","parentMetadata","forEach","_metadata","_propKey","set","writable","add","keyType","elementType","elemCtor","deserializer_Deserializer","Deserializer","_typeResolver","sourceObject","__type","_errorHandler","setNameResolver","nameResolverCallback","_nameResolver","setTypeResolver","typeResolverCallback","TypeError","setErrorHandler","errorHandlerCallback","convertAsObject","sourceObjectTypeInfo","objectName","_this","expectedSelfType","selfConstructor","sourceObjectMetadata","knownTypeConstructors","_mergeKnownTypes","_createKnownTypesMap","typeFromTypeHint","sourceMetadata_1","sourceObjectWithDeserializedProperties_1","memberMetadata","revivedValue","memberValue","memberNameForDebug","convertSingleValue","elementConstructor","keyConstructor","key","isRequired","targetObject","initializerCallback","e","_instantiateType","assign","onDeserializedMethodName","targetObject_1","keys","sourceKey","typeInfo","memberName","srcTypeNameForDebug","_isDirectlyDeserializableNativeType","_makeTypeErrorMessage","_throwTypeMismatchError","Array","every","elem","isNaN","map","_stringToArrayBuffer","_stringToDataView","convertAsArray","convertAsSet","convertAsMap","elementTypeInfo","slice","element","resultSet","keyTypeInfo","valueTypeInfo","resultMap","targetType","expectedSourceType","actualSourceType","actualType","knownTypeMaps","result","knowTypes","knownTypeMeta","name_1","convertNativeObject","str","buf","bufView","strLen","charCodeAt","serializer_Serializer","Serializer","_typeHintEmitter","sourceTypeMetadata","setTypeHintEmitter","typeEmitterCallback","selfType","convertAsArrayBuffer","convertAsDataView","isArrayTypeInfo","elementTypes","isSetTypeInfo","isMapTypeInfo","convertAsTypedArray","expectedName","actualName","sourceMeta_1","serializer","__assign","expectedElementType","expectedTypeName","actualTypeName","typeInfoForElements","resultArray","resultElement","push","expectedKeyType","resultKeyValuePairObj","from","buffer","charCode","fromCharCode","join","dataView","jsonObject","optionsOrTarget","options","decorator","target","knownType","onDeserialized","initializer","knownTypeMethodName","filter","jsonMember","propCtor","isSpecialPropertyType","emitDefaultValue","toString","reflectPropCtor","jsonArrayMember","dimensions","undefined","elementCtor","fill","createArrayElementType","jsonSetMember","jsonMapMember","valueConstructor","typedjson_TypedJSON","TypedJSON","rootConstructor","settings","globalKnownTypes","indent","rootMetadata","nameResolver","errorHandler","config","_globalConfig","rootType","parseAsArray","parseAsSet","parseAsMap","valueType","toPlainJson","toPlainArray","toPlainSet","stringifyAsSet","toPlainMap","keyCtor","valueCtor","stringifyAsMap","stringify","stringifyAsArray","setGlobalConfig","typedjson_assign","replacer","typeResolver","typeHintEmitter","ktc","knownTypeCtor","_mapKnownTypes","elementConstructorArray","constructors"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,eAAAC,IACAD,OAAA,eAAAH,GACA,iBAAAC,QACAA,QAAA,UAAAD,IAEAD,EAAA,UAAAC,IARA,CASC,oBAAAK,UAAAC,KAAA,WACD,mBCTA,IAAAC,KAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAR,QAGA,IAAAC,EAAAK,EAAAE,IACAC,EAAAD,EACAE,GAAA,EACAV,YAUA,OANAW,EAAAH,GAAAI,KAAAX,EAAAD,QAAAC,IAAAD,QAAAO,GAGAN,EAAAS,GAAA,EAGAT,EAAAD,QA2CA,OAtCAO,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAf,EAAAgB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E,GAAvB,IAAAhK,EAAAtI,KAEQ4K,EAAM,IAAIlF,IAId,OAFA4M,EAAanD,OAAO,SAAAnJ,GAAQ,OAAAA,IAAMY,QAAQ,SAAAZ,GAAQ,OAAA4E,EAAI7D,IAAIuB,EAAKoI,aAAa1K,GAAOA,KAE5E4E,GAEfwF,EAteA","file":"typedjson.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"typedjson\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"typedjson\"] = factory();\n\telse\n\t\troot[\"typedjson\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","declare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport const METADATA_FIELD_KEY = \"__typedJsonJsonObjectMetadataInformation__\";\n\nexport function getDefaultValue(type: { new (): T }): T|undefined\n{\n switch (type as any)\n {\n case Number:\n return 0 as any;\n\n case String:\n return \"\" as any;\n\n case Boolean:\n return false as any;\n\n case Array:\n return [] as any;\n\n default:\n return undefined;\n }\n}\n\n/**\n * Determines whether the specified type is a type that can be passed on \"as-is\" into `JSON.stringify`.\n * Values of these types don't need special conversion.\n * @param ctor The constructor of the type (wrapper constructor for primitive types, e.g. `Number` for `number`).\n */\nexport function isDirectlySerializableNativeType(type: Function): boolean\n{\n return !!(~[Date, Number, String, Boolean].indexOf(type as any));\n}\n\nexport function isTypeTypedArray(type: Function): boolean\n{\n return !!(~[Float32Array, Float64Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array]\n .indexOf(type as any));\n}\n\nexport function isPrimitiveValue(obj: any): boolean\n{\n switch (typeof obj)\n {\n case \"string\":\n case \"number\":\n case \"boolean\":\n return true;\n default:\n return (obj instanceof String || obj instanceof Number || obj instanceof Boolean);\n }\n}\n\nexport function isObject(value: any): value is Object\n{\n return typeof value === \"object\";\n}\n\nfunction shouldOmitParseString(jsonStr: string, expectedType: Function): boolean {\n const expectsTypesSerializedAsStrings = expectedType === String\n || expectedType === ArrayBuffer\n || expectedType === DataView;\n\n const hasQuotes = jsonStr.length >= 2 && jsonStr[0] === '\"' && jsonStr[jsonStr.length-1] === '\"';\n const isInteger = /^\\d+$/.test(jsonStr.trim());\n\n return (expectsTypesSerializedAsStrings && !hasQuotes) || ((!hasQuotes && !isInteger) && expectedType === Date);\n}\n\nexport function parseToJSObject(json: any, expectedType: Function): Object {\n if (typeof json !== 'string' || shouldOmitParseString(json, expectedType))\n {\n return json;\n }\n return JSON.parse(json);\n}\n\n/**\n * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B').\n * @param A The supposed derived type.\n * @param B The supposed base type.\n */\nexport function isSubtypeOf(A: Function, B: Function)\n{\n return A === B || A.prototype instanceof B;\n}\n\nexport function logError(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.error === \"function\")\n {\n console.error.apply(console, [message].concat(optionalParams));\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"ERROR: \" + message].concat(optionalParams));\n }\n}\n\nexport function logMessage(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [message].concat(optionalParams));\n }\n}\n\nexport function logWarning(message?: any, ...optionalParams: any[])\n{\n if (typeof console === \"object\" && typeof console.warn === \"function\")\n {\n console.warn.apply(console, [message].concat(optionalParams));\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log.apply(console, [\"WARNING: \" + message].concat(optionalParams));\n }\n}\n\n/**\n * Checks if the value is considered defined (not undefined and not null).\n * @param value\n */\nexport function isValueDefined(value: T): value is Exclude\n{\n return !(typeof value === \"undefined\" || value === null);\n}\n\nexport function isInstanceOf(value: any, constructor: Function): boolean\n{\n if (typeof value === \"number\")\n {\n return (constructor === Number);\n }\n else if (typeof value === \"string\")\n {\n return (constructor === String);\n }\n else if (typeof value === \"boolean\")\n {\n return (constructor === Boolean);\n }\n else if (isObject(value))\n {\n return (value instanceof constructor);\n }\n\n return false;\n}\n\nexport const isReflectMetadataSupported =\n (typeof Reflect === \"object\" && typeof Reflect.getMetadata === \"function\");\n\n/**\n * Gets the name of a function.\n * @param fn The function whose name to get.\n */\nexport function nameof(fn: Function & { name?: string })\n{\n if (typeof fn.name === \"string\")\n {\n return fn.name;\n }\n else\n {\n return \"undefined\";\n }\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\n\nexport interface JsonMemberMetadata\n{\n /** If set, a default value will be emitted for uninitialized members. */\n emitDefaultValue?: boolean;\n\n /** Member name as it appears in the serialized JSON. */\n name: string;\n\n /** Property or field key of the json member. */\n key: string;\n\n /** Constuctor (type) reference of the member. */\n ctor?: Function;\n\n /** If set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** If the json member is an array, map or set, sets member options of elements/values. Subsequent values define the types of nested arrays. */\n elementType?: Function[];\n\n /** If the json member is a map, sets member options of array keys. */\n keyType?: Function;\n\n /** Custom deserializer to use. */\n deserializer?: (json: any) => any;\n\n /** Custom serializer to use. */\n serializer?: (value: any) => any;\n}\n\nexport class JsonObjectMetadata\n{\n //#region Static\n /**\n * Gets the name of a class as it appears in a serialized JSON string.\n * @param ctor The constructor of a class (with or without jsonObject).\n */\n public static getJsonObjectName(ctor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(ctor);\n return metadata ? nameof(metadata.classType) : nameof(ctor);\n }\n\n /**\n * Gets jsonObject metadata information from a class.\n * @param ctor The constructor class.\n */\n public static getFromConstructor(ctor: Function): JsonObjectMetadata|undefined\n {\n const prototype = ctor.prototype;\n if (!prototype)\n {\n return;\n }\n\n let metadata: JsonObjectMetadata|undefined;\n if (prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // The class prototype contains own jsonObject metadata\n metadata = prototype[METADATA_FIELD_KEY];\n }\n\n // Ignore implicitly added jsonObject (through jsonMember)\n if (metadata && metadata.isExplicitlyMarked)\n {\n return metadata;\n }\n\n // In the end maybe it is something which we can handle directly\n if (JsonObjectMetadata.doesHandleWithoutAnnotation(ctor))\n {\n const primitiveMeta = new JsonObjectMetadata(ctor);\n primitiveMeta.isExplicitlyMarked = true;\n // we do not store the metadata here to not modify builtin prototype\n return primitiveMeta;\n }\n }\n\n /**\n * Gets the known type name of a jsonObject class for type hint.\n * @param constructor The constructor class.\n */\n public static getKnownTypeNameFromType(constructor: Function): string\n {\n const metadata = JsonObjectMetadata.getFromConstructor(constructor);\n return metadata ? nameof(metadata.classType) : nameof(constructor);\n }\n\n private static doesHandleWithoutAnnotation(ctor: Function): boolean\n {\n return isDirectlySerializableNativeType(ctor) || isTypeTypedArray(ctor)\n || ctor === DataView || ctor === ArrayBuffer;\n }\n //#endregion\n\n constructor(\n classType: Function,\n ) {\n this.classType = classType;\n }\n\n public dataMembers: Map = new Map();\n\n public knownTypes: Set = new Set();\n\n public knownTypeMethodName?: string;\n\n /** Gets or sets the constructor function for the jsonObject. */\n public classType: Function;\n\n /**\n * Indicates whether this class was explicitly annotated with @jsonObject\n * or implicitly by @jsonMember\n */\n public isExplicitlyMarked: boolean = false;\n\n /**\n * Indicates whether this type is handled without annotation. This is usually\n * used for the builtin types (except for Maps, Sets, and normal Arrays).\n */\n public isHandledWithoutAnnotation: boolean = false;\n\n /** Name used to encode polymorphic type */\n public name?: string;\n\n public onDeserializedMethodName?: string;\n\n public initializerCallback?: (sourceObject: Object, rawSourceObject: Object) => Object;\n}\n\nexport function injectMetadataInformation(constructor: IndexedObject, propKey: string | symbol, metadata: JsonMemberMetadata)\n{\n const decoratorName = `@jsonMember on ${nameof(constructor.constructor)}.${String(propKey)}`; // For error messages.\n let objectMetadata: JsonObjectMetadata;\n\n // When a property decorator is applied to a static member, 'constructor' is a constructor function.\n // See: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Decorators.md#property-decorators\n // ... and static members are not supported here, so abort.\n if (typeof constructor === \"function\")\n {\n logError(`${decoratorName}: cannot use a static property.`);\n return;\n }\n\n // Methods cannot be serialized.\n // @ts-ignore symbol indexing is not supported by ts\n if (typeof constructor[propKey] === \"function\")\n {\n logError(`${decoratorName}: cannot use a method property.`);\n return;\n }\n\n if (!metadata || (!metadata.ctor && !metadata.deserializer))\n {\n logError(`${decoratorName}: JsonMemberMetadata has unknown ctor.`);\n return;\n }\n\n // Add jsonObject metadata to 'constructor' if not yet exists ('constructor' is the prototype).\n // NOTE: this will not fire up custom serialization, as 'constructor' must be explicitly marked with '@jsonObject' as well.\n if (!constructor.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // No *own* metadata, create new.\n objectMetadata = new JsonObjectMetadata(constructor.constructor);\n\n // Inherit @JsonMembers from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = constructor[METADATA_FIELD_KEY];\n if (parentMetadata) // && !constructor.hasOwnProperty(Helpers.METADATA_FIELD_KEY)\n {\n parentMetadata.dataMembers.forEach((_metadata, _propKey) => objectMetadata.dataMembers.set(_propKey, _metadata));\n }\n\n // ('constructor' is the prototype of the involved class, metadata information is added to this class prototype).\n Object.defineProperty(constructor, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // JsonObjectMetadata already exists on 'constructor'.\n objectMetadata = constructor[METADATA_FIELD_KEY];\n }\n\n if (!metadata.deserializer)\n {\n // @ts-ignore above is a check (!deser && !ctor)\n objectMetadata.knownTypes.add(metadata.ctor);\n }\n\n if (metadata.keyType)\n objectMetadata.knownTypes.add(metadata.keyType);\n\n if (metadata.elementType)\n metadata.elementType.forEach(elemCtor => objectMetadata.knownTypes.add(elemCtor));\n\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\n/**\n * Utility class, converts a simple/untyped javascript object-tree to a typed object-tree.\n * It is used after parsing a JSON-string.\n */\nexport class Deserializer\n{\n private _typeResolver: (sourceObject: Object, knownTypes: Map) => Function|undefined;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeResolver = (sourceObject: any, knownTypes: Map) =>\n {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: (sourceObject: Object, knownTypes: Map) => Function)\n {\n if (typeof typeResolverCallback !== \"function\") throw new TypeError(\"'typeResolverCallback' is not a function.\");\n\n this._typeResolver = typeResolverCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n public convertAsObject(\n sourceObject: IndexedObject,\n sourceObjectTypeInfo: IScopeTypeInfo,\n objectName = \"object\",\n ) {\n if (typeof sourceObject !== \"object\" || sourceObject === null)\n {\n this._errorHandler(new TypeError(`Cannot deserialize ${objectName}: 'sourceObject' must be a defined object.`));\n return undefined;\n }\n\n let expectedSelfType = sourceObjectTypeInfo.selfConstructor;\n let sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(expectedSelfType);\n let knownTypeConstructors = sourceObjectTypeInfo.knownTypes;\n\n if (sourceObjectMetadata)\n {\n // Merge known types received from \"above\" with known types defined on the current type.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n\n // Check if a type-hint is available from the source object.\n let typeFromTypeHint = this._typeResolver(sourceObject, knownTypeConstructors);\n\n if (typeFromTypeHint)\n {\n // Check if type hint is a valid subtype of the expected source type.\n if (isSubtypeOf(typeFromTypeHint, expectedSelfType))\n {\n // Hell yes.\n expectedSelfType = typeFromTypeHint;\n sourceObjectMetadata = JsonObjectMetadata.getFromConstructor(typeFromTypeHint);\n\n if (sourceObjectMetadata)\n {\n // Also merge new known types from subtype.\n knownTypeConstructors = this._mergeKnownTypes(\n knownTypeConstructors,\n this._createKnownTypesMap(sourceObjectMetadata.knownTypes),\n );\n }\n }\n }\n\n if (sourceObjectMetadata && sourceObjectMetadata.isExplicitlyMarked)\n {\n const sourceMetadata = sourceObjectMetadata;\n // Strong-typed deserialization available, get to it.\n // First deserialize properties into a temporary object.\n const sourceObjectWithDeserializedProperties = {} as IndexedObject;\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((memberMetadata, propKey) =>\n {\n const memberValue = sourceObject[propKey];\n const memberNameForDebug = `${nameof(sourceMetadata.classType)}.${propKey}`;\n\n let revivedValue;\n if (memberMetadata.deserializer) {\n revivedValue = memberMetadata.deserializer(memberValue);\n } else if (memberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n memberValue,\n {\n selfConstructor: memberMetadata.ctor,\n elementConstructor: memberMetadata.elementType,\n keyConstructor: memberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n memberNameForDebug,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${memberNameForDebug} thers is`\n + ` no constructor nor deserlization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue))\n {\n sourceObjectWithDeserializedProperties[memberMetadata.key] = revivedValue;\n }\n else if (memberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${memberNameForDebug}'.`));\n }\n });\n\n // Next, instantiate target object.\n let targetObject: IndexedObject;\n\n if (typeof sourceObjectMetadata.initializerCallback === \"function\")\n {\n try\n {\n targetObject = sourceObjectMetadata.initializerCallback(\n sourceObjectWithDeserializedProperties,\n sourceObject,\n );\n\n // Check the validity of user-defined initializer callback.\n if (!targetObject)\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + ` 'initializer' function returned undefined/null`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected.`,\n );\n }\n else if (!(targetObject instanceof sourceObjectMetadata.classType))\n {\n throw new TypeError(\n `Cannot deserialize ${objectName}:`\n + `'initializer' returned '${nameof(targetObject.constructor)}'`\n + `, but '${nameof(sourceObjectMetadata.classType)}' was expected,`\n + `and '${nameof(targetObject.constructor)}' is not a subtype of`\n + ` '${nameof(sourceObjectMetadata.classType)}'`,\n );\n }\n }\n catch (e)\n {\n this._errorHandler(e);\n return undefined;\n }\n }\n else\n {\n targetObject = this._instantiateType(expectedSelfType);\n }\n\n // Finally, assign deserialized properties to target object.\n Object.assign(targetObject, sourceObjectWithDeserializedProperties);\n\n // Call onDeserialized method (if any).\n if (sourceObjectMetadata.onDeserializedMethodName)\n {\n if (typeof (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject.constructor as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n else\n {\n this._errorHandler(new TypeError(\n `onDeserialized callback '${nameof(sourceObjectMetadata.classType)}.${sourceObjectMetadata.onDeserializedMethodName}' is not a method.`\n ));\n }\n }\n\n return targetObject;\n }\n else\n {\n // Untyped deserialization into Object instance.\n let targetObject = {} as IndexedObject;\n\n Object.keys(sourceObject).forEach(sourceKey =>\n {\n targetObject[sourceKey] = this.convertSingleValue(sourceObject[sourceKey], {\n selfConstructor: sourceObject[sourceKey].constructor,\n knownTypes: sourceObjectTypeInfo.knownTypes,\n elementConstructor: sourceObjectTypeInfo.elementConstructor,\n keyConstructor: sourceObjectTypeInfo.keyConstructor\n }, sourceKey);\n });\n\n return targetObject;\n }\n }\n\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (!isValueDefined(sourceObject))\n {\n return sourceObject;\n }\n else if (this._isDirectlyDeserializableNativeType(expectedSelfType))\n {\n if (sourceObject.constructor === expectedSelfType)\n {\n return sourceObject;\n }\n else\n {\n throw new TypeError(this._makeTypeErrorMessage(nameof(expectedSelfType), sourceObject.constructor, memberName));\n }\n }\n else if (expectedSelfType === Date)\n {\n // Support for Date with ISO 8601 format, or with numeric timestamp (milliseconds elapsed since the Epoch).\n // ISO 8601 spec.: https://www.w3.org/TR/NOTE-datetime\n\n if (typeof sourceObject === \"string\" || (typeof sourceObject === \"number\" && sourceObject > 0))\n return new Date(sourceObject as any);\n else\n this._throwTypeMismatchError(\"Date\", \"an ISO-8601 string\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float32Array)\n {\n // Deserialize Float32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float32Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Float64Array)\n {\n // Deserialize Float64Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Float64Array(sourceObject);\n else\n this._throwTypeMismatchError(\"Float64Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8Array)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint8ClampedArray)\n {\n // Deserialize Uint8Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint8ClampedArray(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint8ClampedArray\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint16Array)\n {\n // Deserialize Uint16Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint16Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint16Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Uint32Array)\n {\n // Deserialize Uint32Array from number[].\n\n if (sourceObject instanceof Array && sourceObject.every(elem => !isNaN(elem)))\n return new Uint32Array(sourceObject.map(value => ~~value));\n else\n this._throwTypeMismatchError(\"Uint32Array\", \"a numeric source array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === ArrayBuffer)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToArrayBuffer(sourceObject);\n else\n this._throwTypeMismatchError(\"ArrayBuffer\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === DataView)\n {\n if (typeof sourceObject === \"string\")\n return this._stringToDataView(sourceObject);\n else\n this._throwTypeMismatchError(\"DataView\", \"a string source\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Array)\n {\n if (sourceObject instanceof Array)\n return this.convertAsArray(sourceObject, typeInfo, memberName);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (sourceObject instanceof Array)\n return this.convertAsSet(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (sourceObject instanceof Array)\n return this.convertAsMap(sourceObject, typeInfo, memberName);\n else\n this._throwTypeMismatchError(\"Map\", \"a source array of key-value-pair objects\", srcTypeNameForDebug, memberName);\n }\n else if (sourceObject && typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n public convertAsArray(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\"): any[]\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return [];\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Array: missing constructor reference of Array elements.`));\n return [];\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n return sourceObject.map(element =>\n {\n // If an array element fails to deserialize, substitute with undefined. This is so that the original ordering is not interrupted by faulty\n // entries, as an Array is ordered.\n try\n {\n return this.convertSingleValue(element, elementTypeInfo);\n }\n catch (e)\n {\n this._errorHandler(e);\n\n // Keep filling the array here with undefined to keep original ordering.\n // Note: this is just aesthetics, not returning anything produces the same result.\n return undefined;\n }\n });\n }\n\n public convertAsSet(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n {\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n return new Set();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Set: missing constructor reference of Set elements.`));\n return new Set();\n }\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n let resultSet = new Set();\n\n sourceObject.forEach((element, i) =>\n {\n try\n {\n resultSet.add(this.convertSingleValue(element, elementTypeInfo, memberName + `[${i}]`));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(sourceObject: any, typeInfo: IScopeTypeInfo, memberName = \"object\")\n {\n if (!(sourceObject instanceof Array))\n this._errorHandler(new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName)));\n\n if (!typeInfo.keyConstructor)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing key constructor.`));\n return new Map();\n }\n\n if (!typeInfo.elementConstructor || !typeInfo.elementConstructor.length)\n {\n this._errorHandler(new TypeError(`Could not deserialize ${memberName} as Map: missing value constructor.`));\n return new Map();\n }\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.keyConstructor,\n knownTypes: typeInfo.knownTypes\n };\n\n let valueTypeInfo: IScopeTypeInfo = {\n selfConstructor: typeInfo.elementConstructor[0],\n elementConstructor: (typeInfo.elementConstructor.length > 1) ? typeInfo.elementConstructor.slice(1) : [],\n knownTypes: typeInfo.knownTypes\n };\n\n let resultMap = new Map();\n\n sourceObject.forEach((element: any) =>\n {\n try\n {\n let key = this.convertSingleValue(element.key, keyTypeInfo);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(key, this.convertSingleValue(\n element.value, valueTypeInfo, `${memberName}[${key}]`,\n ));\n }\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Map is not ordered,\n // and skipping an entry does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultMap;\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string = \"object\",\n ) {\n throw new TypeError(\n `Could not deserialize ${memberName} as ${targetType}:`\n + ` expected ${expectedSourceType}, got ${actualSourceType}.`,\n );\n }\n\n private _makeTypeErrorMessage(expectedType: Function | string, actualType: Function | string, memberName = \"object\")\n {\n let expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n let actualTypeName = (typeof actualType === \"function\") ? nameof(actualType) : actualType;\n\n return `Could not deserialize ${memberName}: expected '${expectedTypeName}', got '${actualTypeName}'.`;\n }\n\n private _instantiateType(ctor: any)\n {\n return new ctor();\n }\n\n private _mergeKnownTypes(...knownTypeMaps: Array>)\n {\n let result = new Map();\n\n knownTypeMaps.forEach(knownTypes =>\n {\n knownTypes.forEach((ctor, name) =>\n {\n if (this._nameResolver)\n {\n result.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n result.set(name, ctor);\n }\n });\n });\n\n return result;\n }\n\n private _createKnownTypesMap(knowTypes: Set)\n {\n const map = new Map();\n\n knowTypes.forEach(ctor =>\n {\n if (this._nameResolver)\n {\n map.set(this._nameResolver(ctor), ctor);\n }\n else\n {\n const knownTypeMeta = JsonObjectMetadata.getFromConstructor(ctor);\n const name = knownTypeMeta && knownTypeMeta.isExplicitlyMarked && knownTypeMeta.name\n ? knownTypeMeta.name\n : ctor.name;\n map.set(name, ctor);\n }\n });\n\n return map;\n }\n\n private _isDirectlyDeserializableNativeType(ctor: any)\n {\n return ~([Number, String, Boolean].indexOf(ctor));\n }\n\n public convertNativeObject(sourceObject: any)\n {\n return sourceObject;\n }\n\n private _stringToArrayBuffer(str: string)\n {\n let buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char\n let bufView = new Uint16Array(buf);\n\n for (let i = 0, strLen = str.length; i < strLen; i++)\n {\n bufView[i] = str.charCodeAt(i);\n }\n\n return buf;\n }\n\n private _stringToDataView(str: string)\n {\n return new DataView(this._stringToArrayBuffer(str));\n }\n}\n","import { nameof, logError, isValueDefined, isInstanceOf, isTypeTypedArray, isDirectlySerializableNativeType } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IScopeTypeInfo\n{\n selfType: Function;\n elementTypes?: Function[];\n keyType?: Function;\n}\n\nexport interface IScopeArrayTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Array;\n elementTypes: Function[];\n}\n\nfunction isArrayTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeArrayTypeInfo {\n return typeInfo.selfType === Array;\n}\n\nexport interface IScopeSetTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Set;\n elementTypes: [Function];\n}\n\nfunction isSetTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeSetTypeInfo {\n return typeInfo.selfType === Set;\n}\n\nexport interface IScopeMapTypeInfo extends IScopeTypeInfo\n{\n selfType: new () => Map;\n elementTypes: [Function];\n keyType: Function;\n}\n\nfunction isMapTypeInfo(typeInfo: IScopeTypeInfo): typeInfo is IScopeMapTypeInfo {\n return typeInfo.selfType === Map;\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class instances, and so on) to an untyped javascript object (also\n * called \"simple javascript object\"), and emits any necessary type hints in the process (for polymorphism).\n *\n * The converted object tree is what will be given to `JSON.stringify` to convert to string as the last step, the serialization is basically like:\n *\n * (1) typed object-tree -> (2) simple JS object-tree -> (3) JSON-string\n */\nexport class Serializer\n{\n private _typeHintEmitter: (targetObject: IndexedObject, sourceObject: IndexedObject, expectedSourceType: Function, sourceTypeMetadata?: JsonObjectMetadata) => void;\n private _errorHandler: (error: Error) => void;\n\n constructor()\n {\n this._typeHintEmitter = (targetObject, sourceObject, expectedSourceType, sourceTypeMetadata?: JsonObjectMetadata) =>\n {\n // By default, we put a \"__type\" property on the output object if the actual object is not the same as the expected one, so that deserialization\n // will know what to deserialize into (given the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n const name = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n // TODO: Perhaps this can work correctly without string-literal access?\n // tslint:disable-next-line:no-string-literal\n targetObject[\"__type\"] = name;\n }\n };\n\n this._errorHandler = (error) => logError(error);\n }\n\n public setTypeHintEmitter(typeEmitterCallback: (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void)\n {\n if (typeof typeEmitterCallback !== \"function\")\n {\n throw new TypeError(\"'typeEmitterCallback' is not a function.\");\n }\n\n this._typeHintEmitter = typeEmitterCallback;\n }\n\n public setErrorHandler(errorHandlerCallback: (error: Error) => void)\n {\n if (typeof errorHandlerCallback !== \"function\")\n {\n throw new TypeError(\"'errorHandlerCallback' is not a function.\");\n }\n\n this._errorHandler = errorHandlerCallback;\n }\n\n /**\n * Convert a value of any supported serializable type.\n * The value type will be detected, and the correct serialization method will be called.\n */\n public convertSingleValue(sourceObject: any, typeInfo: IScopeTypeInfo, memberName: string = \"object\"): any\n {\n if (!isValueDefined(sourceObject)) return;\n\n if (!isInstanceOf(sourceObject, typeInfo.selfType))\n {\n let expectedName = nameof(typeInfo.selfType);\n let actualName = nameof(sourceObject.constructor);\n\n this._errorHandler(new TypeError(`Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`));\n return;\n }\n\n if (isDirectlySerializableNativeType(typeInfo.selfType))\n {\n return sourceObject;\n }\n else if (typeInfo.selfType === ArrayBuffer)\n {\n return this.convertAsArrayBuffer(sourceObject);\n }\n else if (typeInfo.selfType === DataView)\n {\n return this.convertAsDataView(sourceObject);\n }\n else if (isArrayTypeInfo(typeInfo))\n {\n return this.convertAsArray(sourceObject, typeInfo.elementTypes, memberName);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName);\n }\n else if (isTypeTypedArray(typeInfo.selfType))\n {\n return this.convertAsTypedArray(sourceObject);\n }\n else if (typeof sourceObject === \"object\")\n {\n return this.convertAsObject(sourceObject, typeInfo, memberName);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple javascript object for serialization.\n */\n public convertAsObject(sourceObject: IndexedObject, typeInfo: IScopeTypeInfo, memberName?: string)\n {\n let sourceTypeMetadata: JsonObjectMetadata|undefined;\n let targetObject: IndexedObject;\n\n if (sourceObject.constructor !== typeInfo.selfType && sourceObject instanceof typeInfo.selfType)\n {\n // The source object is not of the expected type, but it is a valid subtype.\n // This is OK, and we'll proceed to gather object metadata from the subtype instead.\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(sourceObject.constructor);\n }\n else\n {\n sourceTypeMetadata = JsonObjectMetadata.getFromConstructor(typeInfo.selfType);\n }\n\n if (sourceTypeMetadata)\n {\n const sourceMeta = sourceTypeMetadata;\n // Strong-typed serialization available.\n // We'll serialize by members that have been marked with @jsonMember (including array/set/map members), and perform recursive conversion on\n // each of them. The converted objects are put on the 'targetObject', which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n sourceTypeMetadata.dataMembers.forEach((memberMetadata) =>\n {\n if (memberMetadata.serializer) {\n targetObject[memberMetadata.name] =\n memberMetadata.serializer(sourceObject[memberMetadata.key]);\n } else if (memberMetadata.ctor) {\n targetObject[memberMetadata.name] = this.convertSingleValue(\n sourceObject[memberMetadata.key],\n {\n selfType: memberMetadata.ctor,\n elementTypes: memberMetadata.elementType,\n keyType: memberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${memberMetadata.key}`,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${memberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n });\n }\n else\n {\n // Untyped serialization, \"as-is\", we'll just pass the object on.\n // We'll clone the source object, because type hints are added to the object itself, and we don't want to modify to the original object.\n targetObject = { ...sourceObject };\n }\n\n // Add type-hint.\n this._typeHintEmitter(targetObject, sourceObject, typeInfo.selfType, sourceTypeMetadata);\n\n return targetObject;\n }\n\n /**\n * Performs the conversion of an array of typed objects (or primitive values) to an array of simple javascript objects (or primitive values) for\n * serialization.\n * @param expectedElementType The expected type of elements. If the array is supposed to be multi-dimensional, subsequent elements define lower dimensions.\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsArray(sourceObject: any[], expectedElementType: Function[], memberName = \"object\"): any[]\n {\n if (expectedElementType.length === 0 || !expectedElementType[0])\n throw new TypeError(`Could not serialize ${memberName} as Array: missing element type definition.`);\n\n // Check the type of each element, individually.\n // If at least one array element type is incorrect, we return undefined, which results in no value emitted during serialization.\n // This is so that invalid element types don't unexpectedly alter the ordering of other, valid elements, and that no unexpected undefined values are in\n // the emitted array.\n sourceObject.forEach((element, i) =>\n {\n if (!isInstanceOf(element, expectedElementType[0]))\n {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]: expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [], // For multidimensional arrays.\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(element => this.convertSingleValue(element, typeInfoForElements, memberName));\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @returns\n */\n public convertAsSet(sourceObject: Set, expectedElementType: Function, memberName = \"object\"): any[]\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Set: missing element type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n };\n\n // For debugging and error tracking.\n if (memberName) memberName += \"[]\";\n\n let resultArray: any[] = [];\n\n // Convert each element of the set, and put it into an output array.\n // The output array is the one serialized, as JSON.stringify does not support Set serialization. (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName);\n\n // Add to output if the source element was undefined, OR the converted element is defined. This will add intentionally undefined values to output,\n // but not values that became undefined DURING serializing (usually because of a type-error).\n if (!isValueDefined(element) || isValueDefined(resultElement))\n {\n resultArray.push(resultElement);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a map of typed objects (or primitive values) into an array of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n */\n public convertAsMap(sourceObject: Map, expectedKeyType: Function, expectedElementType: Function, memberName = \"object\"): Array<{ key: any, value: any }>\n {\n if (!expectedElementType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing value type definition.`);\n\n if (!expectedKeyType)\n throw new TypeError(`Could not serialize ${memberName} as Map: missing key type definition.`);\n\n let elementTypeInfo: IScopeTypeInfo = {\n selfType: expectedElementType,\n elementTypes: [expectedElementType]\n };\n\n let keyTypeInfo: IScopeTypeInfo = {\n selfType: expectedKeyType\n };\n\n if (memberName) memberName += \"[]\";\n\n let resultArray: Array<{ key: any, value: any }> = [];\n\n // Convert each *entry* in the map to a simple javascript object with key and value properties.\n sourceObject.forEach((value, key) =>\n {\n let resultKeyValuePairObj = {\n key: this.convertSingleValue(key, keyTypeInfo, memberName),\n value: this.convertSingleValue(value, elementTypeInfo, memberName)\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n if (isValueDefined(resultKeyValuePairObj.key) && isValueDefined(resultKeyValuePairObj.value))\n {\n resultArray.push(resultKeyValuePairObj);\n }\n });\n\n return resultArray;\n }\n\n /**\n * Performs the conversion of a typed javascript array to a simple untyped javascript array.\n * This is needed because typed arrays are otherwise serialized as objects, so we'll end up with something like \"{ 0: 0, 1: 1, ... }\".\n *\n * @param sourceObject\n * @returns\n */\n public convertAsTypedArray(sourceObject: ArrayBufferView)\n {\n return Array.from(sourceObject as any);\n }\n\n /**\n * Performs the conversion of a raw ArrayBuffer to a string.\n */\n public convertAsArrayBuffer(buffer: ArrayBuffer)\n {\n // ArrayBuffer -> 16-bit character codes -> character array -> joined string.\n return Array.from(new Uint16Array(buffer)).map(charCode => String.fromCharCode(charCode)).join(\"\");\n }\n\n /**\n * Performs the conversion of DataView, converting its internal ArrayBuffer to a string and returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n}\n","import { Constructor, ParameterlessConstructor } from \"./types\";\nimport { METADATA_FIELD_KEY } from \"./helpers\";\nimport { JsonObjectMetadata } from \"./metadata\";\n\nexport interface IJsonObjectOptionsBase\n{\n /**\n * An array of known types to recognize when encountering type-hints,\n * or the name of a static method used for determining known types.\n */\n knownTypes?: Function[] | string;\n\n /**\n * The name of a static or instance method to call when deserialization\n * of the object is completed.\n */\n onDeserialized?: string;\n\n /**\n * The name used to differentiate between different polymorphic types.\n */\n name?: string;\n}\n\nexport interface IJsonObjectOptionsWithInitializer extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer: (sourceObject: T, rawSourceObject: T) => T;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * The name of a static method to call before deserializing and initializing the object, accepting two arguments: (1) sourceObject, an 'Object' instance\n * with all properties already deserialized, and (2) rawSourceObject, a raw 'Object' instance representation of the current object in the serialized JSON\n * (i.e. without deserialized properties).\n */\n initializer?: (sourceObject: T, rawSourceObject: T) => T;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional settings. The 'initializer' setting must be specified.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptionsWithInitializer): (target: Constructor) => void;\n\n/**\n * Marks that a class is serializable using TypedJSON, with additional settings.\n * @param options Configuration settings.\n */\nexport function jsonObject(options?: IJsonObjectOptions): (target: ParameterlessConstructor) => void;\n\n/**\n * Marks that a class with a parameterless constructor is serializable using TypedJSON.\n */\nexport function jsonObject(target: ParameterlessConstructor): void;\n\nexport function jsonObject(optionsOrTarget?: IJsonObjectOptions | Constructor\n): ((target: Constructor) => void) | void {\n let options: IJsonObjectOptions;\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n options = {};\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n options = optionsOrTarget || {};\n }\n\n function decorator(\n target: Function\n ): void {\n let objectMetadata: JsonObjectMetadata;\n\n // Create or obtain JsonObjectMetadata object.\n if (!target.prototype.hasOwnProperty(METADATA_FIELD_KEY))\n {\n // Target has no JsonObjectMetadata associated with it yet, create it now.\n objectMetadata = new JsonObjectMetadata(target);\n\n // Inherit json members and known types from parent @jsonObject (if any).\n const parentMetadata: JsonObjectMetadata = target.prototype[METADATA_FIELD_KEY];\n if (parentMetadata)\n {\n parentMetadata.dataMembers\n .forEach((memberMetadata, propKey) =>\n objectMetadata.dataMembers.set(propKey, memberMetadata));\n parentMetadata.knownTypes\n .forEach((knownType) => objectMetadata.knownTypes.add(knownType));\n }\n\n Object.defineProperty(target.prototype, METADATA_FIELD_KEY, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: objectMetadata\n });\n }\n else\n {\n // Target already has JsonObjectMetadata associated with it.\n objectMetadata = target.prototype[METADATA_FIELD_KEY];\n objectMetadata.classType = target;\n }\n\n // Fill JsonObjectMetadata.\n objectMetadata.isExplicitlyMarked = true;\n objectMetadata.onDeserializedMethodName = options.onDeserialized;\n // T extend Object so it is fine\n objectMetadata.initializerCallback = options.initializer as any;\n if (options.name)\n {\n objectMetadata.name = options.name;\n }\n\n // Obtain known-types.\n if (typeof options.knownTypes === \"string\")\n {\n objectMetadata.knownTypeMethodName = options.knownTypes;\n }\n else if (options.knownTypes instanceof Array)\n {\n options.knownTypes\n .filter(knownType => !!knownType)\n .forEach(knownType => objectMetadata.knownTypes.add(knownType));\n }\n }\n\n if (typeof optionsOrTarget === \"function\")\n {\n // jsonObject is being used as a decorator, directly.\n decorator(optionsOrTarget);\n }\n else\n {\n // jsonObject is being used as a decorator factory.\n return decorator;\n }\n}\n","import {\n nameof, logError, isReflectMetadataSupported, isValueDefined, logWarning, isSubtypeOf\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions\n{\n /**\n * Sets the constructor of the property.\n * Optional with ReflectDecorators.\n */\n constructor?: Function;\n\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted if the property is uninitialized/undefined. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name. */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property is part of the object when serializing, with additional options.\n * Omitting the 'constructor' option requires ReflectDecorators and that the property type is always explicitly declared.\n * @param options Additional options.\n */\nexport function jsonMember(options: IJsonMemberOptions): PropertyDecorator;\n\n/**\n * Specifies that a property is part of the object when serializing.\n * This call signature requires ReflectDecorators and that the property type is always explicitly declared.\n */\nexport function jsonMember(target: Object, propertyKey: string | symbol): void;\n\nexport function jsonMember(optionsOrTarget?: IJsonMemberOptions | Object, propKey?: string | symbol): PropertyDecorator | void\n{\n if (optionsOrTarget instanceof Object && (typeof propKey === \"string\" || typeof propKey === \"symbol\"))\n {\n const target = optionsOrTarget;\n // For error messages.\n const decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(propKey)}`;\n\n // jsonMember used directly, no additional information directly available besides target and propKey.\n // Obtain property constructor through ReflectDecorators.\n if (isReflectMetadataSupported)\n {\n const reflectPropCtor = Reflect.getMetadata(\"design:type\", target, propKey) as Function;\n\n if (!reflectPropCtor)\n {\n logError(`${decoratorName}: could not resolve detected property constructor at runtime.`);\n return;\n }\n\n if (isSpecialPropertyType(decoratorName, reflectPropCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: reflectPropCtor,\n key: propKey.toString(),\n name: propKey.toString(),\n });\n }\n else\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n else\n {\n // jsonMember used as a decorator factory.\n return (target: Object, _propKey: string | symbol) =>\n {\n let options: IJsonMemberOptions = optionsOrTarget || {};\n let propCtor: Function|undefined;\n let decoratorName = `@jsonMember on ${nameof(target.constructor)}.${String(_propKey)}`; // For error messages.\n\n if (options.hasOwnProperty(\"constructor\"))\n {\n if (!isValueDefined(options.constructor))\n {\n logError(`${decoratorName}: cannot resolve specified property constructor at runtime.`);\n return;\n }\n\n // Property constructor has been specified. Use ReflectDecorators (if available) to check whether that constructor is correct. Warn if not.\n if (isReflectMetadataSupported && !isSubtypeOf(options.constructor, Reflect.getMetadata(\"design:type\", target, _propKey)))\n {\n logWarning(`${decoratorName}: detected property type does not match 'constructor' option.`);\n }\n\n propCtor = options.constructor;\n }\n else\n {\n // Use ReflectDecorators to obtain property constructor.\n if (isReflectMetadataSupported)\n {\n propCtor = Reflect.getMetadata(\"design:type\", target, _propKey) as Function;\n\n if (!propCtor)\n {\n logError(`${decoratorName}: cannot resolve detected property constructor at runtime.`);\n return;\n }\n }\n else if (!options.deserializer)\n {\n logError(`${decoratorName}: ReflectDecorators is required if no 'constructor' option is specified.`);\n return;\n }\n }\n\n if (isSpecialPropertyType(decoratorName, propCtor))\n {\n return;\n }\n\n injectMetadataInformation(target, _propKey, {\n ctor: propCtor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: _propKey.toString(),\n name: options.name || _propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n }\n}\n\nfunction isSpecialPropertyType(decoratorName: string, propCtor?: Function)\n{\n if (propCtor === Array)\n {\n logError(`${decoratorName}: property is an Array. Use the jsonArrayMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Set)\n {\n logError(`${decoratorName}: property is a Set. Use the jsonSetMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n if (propCtor === Map)\n {\n logError(`${decoratorName}: property is a Map. Use the jsonMapMember decorator to`\n + ` serialize this property.`);\n return true;\n }\n\n return false;\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, an empty array is emitted if the property is undefined/uninitialized. */\n emitDefaultValue?: boolean;\n\n /** Sets array dimensions (e.g. 1 for 'number[]' or 2 for 'number[][]'). Defaults to 1. */\n dimensions?: number;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that a property, of type array, is part of an object when serializing.\n * @param elementConstructor Constructor of array elements (e.g. 'Number' for 'number[]', or 'Date' for 'Date[]').\n * @param options Additional options.\n */\nexport function jsonArrayMember(elementConstructor: Function, options: IJsonArrayMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonArrayMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of array elements at runtime.`);\n return;\n }\n\n const dimensions = options.dimensions === undefined ? 1 : options.dimensions;\n if (!isNaN(dimensions) && dimensions < 1)\n {\n logError(`${decoratorName}: 'dimensions' option must be at least 1.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonArrayMember' has been used on an array.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Array)\n {\n logError(`${decoratorName}: property is not an Array.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n\nfunction createArrayElementType(elementCtor: Function, dimensions: number) {\n const elementTypes = new Array(dimensions).fill(Array, 0, -1);\n elementTypes[dimensions-1] = elementCtor;\n return elementTypes;\n}\n","import { nameof } from \"./helpers\";\nimport { IJsonMemberOptions } from \"./json-member\";\nimport { JsonMemberMetadata, JsonObjectMetadata, injectMetadataInformation } from \"./metadata\";\nimport * as Helpers from \"./helpers\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Set.\n * @param elementConstructor Constructor of set elements (e.g. 'Number' for Set or 'Date' for Set).\n * @param options Additional options.\n */\nexport function jsonSetMember(elementConstructor: Function, options: IJsonSetMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n var decoratorName = `@jsonSetMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof elementConstructor !== \"function\")\n {\n Helpers.logError(`${decoratorName}: could not resolve constructor of set elements at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonSetMember' has been used on a set. Warn if not.\n if (Helpers.isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n Helpers.logError(`${decoratorName}: property is not a Set.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, isReflectMetadataSupported } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions\n{\n /** When set, indicates that the member must be present when deserializing. */\n isRequired?: boolean;\n\n /** When set, a default value is emitted for each uninitialized json member. */\n emitDefaultValue?: boolean;\n\n /** When set, the key on the JSON that should be used instead of the class property name */\n name?: string;\n\n /** When set, this deserializer will be used to deserialize the member. The callee must assure the correct type. */\n deserializer?: (json: any) => any;\n\n /** When set, this serializer will be used to serialize the member. */\n serializer?: (value: any) => any;\n}\n\n/**\n * Specifies that the property is part of the object when serializing.\n * Use this decorator on properties of type Map.\n * @param keyConstructor Constructor of map keys (e.g. 'Number' for 'Map').\n * @param valueConstructor Constructor of map values (e.g. 'Date' for 'Map').\n * @param options Additional options.\n */\nexport function jsonMapMember(keyConstructor: Function, valueConstructor: Function, options: IJsonMapMemberOptions = {})\n{\n return (target: Object, propKey: string | symbol) =>\n {\n let decoratorName = `@jsonMapMember on ${nameof(target.constructor)}.${String(propKey)}`; // For error messages.\n\n if (typeof keyConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map keys at runtime.`);\n return;\n }\n\n if (typeof valueConstructor !== \"function\")\n {\n logError(`${decoratorName}: could not resolve constructor of map values at runtime.`);\n return;\n }\n\n // If ReflectDecorators is available, use it to check whether 'jsonMapMember' has been used on a map. Warn if not.\n if (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Map)\n {\n logError(`${decoratorName}: property is not a Map.`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue || false,\n isRequired: options.isRequired || false,\n key: propKey.toString(),\n name: options.name || propKey.toString(),\n deserializer: options.deserializer,\n serializer: options.serializer,\n });\n };\n}\n","import { nameof, logError, logWarning, parseToJSObject } from './typedjson/helpers';\nimport { Constructor } from \"./typedjson/types\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { Serializer } from \"./typedjson/serializer\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\n\nexport interface ITypedJSONSettings\n{\n /**\n * Sets the handler callback to invoke on errors during serializing and deserializing.\n * Re-throwing errors in this function will halt serialization/deserialization.\n * The default behavior is to log errors to the console.\n */\n errorHandler?: (e: Error) => void;\n\n /**\n * Sets a callback that determines the constructor of the correct sub-type of polymorphic\n * objects while deserializing.\n * The default behavior is to read the type-name from the '__type' property of 'sourceObject',\n * and look it up in 'knownTypes'.\n * The constructor of the sub-type should be returned.\n */\n typeResolver?: (sourceObject: Object, knownTypes: Map) => Function;\n\n nameResolver?: (ctor: Function) => string;\n\n /**\n * Sets a callback that writes type-hints to serialized objects.\n * The default behavior is to write the type-name to the '__type' property, if a derived type\n * is present in place of a base type.\n */\n typeHintEmitter?:\n (targetObject: Object, sourceObject: Object, expectedSourceType: Function) => void;\n\n /**\n * Sets the amount of indentation to use in produced JSON strings.\n * Default value is 0, or no indentation.\n */\n indent?: number;\n\n replacer?: (key: string, value: any) => any;\n\n knownTypes?: Array>;\n}\n\nexport class TypedJSON\n{\n //#region Static\n public static parse(\n object: any, rootType: Constructor, settings?: ITypedJSONSettings,\n ): T|undefined {\n return new TypedJSON(rootType, settings).parse(object);\n }\n\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: 1\n ): T[];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 2\n ): T[][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 3\n ): T[][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 4\n ): T[][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings: ITypedJSONSettings|undefined,\n dimensions: 5\n ): T[][][][][];\n public static parseAsArray(\n object: any,\n elementType: Constructor,\n settings?: ITypedJSONSettings,\n dimensions?: number\n ): any[] {\n return new TypedJSON(elementType, settings).parseAsArray(object, dimensions as any);\n }\n\n public static parseAsSet(\n object: any, elementType: Constructor, settings?: ITypedJSONSettings,\n ): Set {\n return new TypedJSON(elementType, settings).parseAsSet(object);\n }\n\n public static parseAsMap(\n object: any,\n keyType: Constructor,\n valueType: Constructor,\n settings?: ITypedJSONSettings,\n ): Map {\n return new TypedJSON(valueType, settings).parseAsMap(object, keyType);\n }\n\n public static toPlainJson(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): JsonTypes {\n return new TypedJSON(rootType, settings).toPlainJson(object);\n }\n\n public static toPlainArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): Object[];\n public static toPlainArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): Object[][];\n public static toPlainArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): Object[][][];\n public static toPlainArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): Object[][][][];\n public static toPlainArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): Object[][][][][];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): any[];\n public static toPlainArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): any[] {\n return new TypedJSON(elementType, settings).toPlainArray(object, dimensions);\n }\n\n public static toPlainSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n public static stringify(\n object: T, rootType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(rootType, settings).stringify(object);\n }\n\n public static stringifyAsArray(\n object: T[], elementType: Constructor, dimensions?: 1, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][], elementType: Constructor, dimensions: 2, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][], elementType: Constructor, dimensions: 3, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][], elementType: Constructor, dimensions: 4, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: T[][][][][], elementType: Constructor, dimensions: 5, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions: number, settings?: ITypedJSONSettings,\n ): string;\n public static stringifyAsArray(\n object: any[], elementType: Constructor, dimensions?: any, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsArray(object, dimensions);\n }\n\n public static stringifyAsSet(\n object: Set, elementType: Constructor, settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(elementType, settings).stringifyAsSet(object);\n }\n\n public static stringifyAsMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): string {\n return new TypedJSON(valueCtor, settings).stringifyAsMap(object, keyCtor);\n }\n\n private static _globalConfig: ITypedJSONSettings;\n\n public static setGlobalConfig(config: ITypedJSONSettings)\n {\n if (this._globalConfig)\n {\n Object.assign(this._globalConfig, config);\n }\n else\n {\n this._globalConfig = config;\n }\n }\n\n //#endregion\n\n private serializer: Serializer = new Serializer();\n private deserializer: Deserializer = new Deserializer();\n private globalKnownTypes: Array> = [];\n private indent: number = 0;\n private rootConstructor: Constructor;\n private errorHandler: (e: Error) => void;\n private nameResolver: (ctor: Function) => string;\n private replacer?: (key: string, value: any) => any;\n\n /**\n * Creates a new TypedJSON instance to serialize (stringify) and deserialize (parse) object\n * instances of the specified root class type.\n * @param rootType The constructor of the root class type.\n * @param settings Additional configuration settings.\n */\n constructor(rootConstructor: Constructor, settings?: ITypedJSONSettings)\n {\n let rootMetadata = JsonObjectMetadata.getFromConstructor(rootConstructor);\n\n if (!rootMetadata || (!rootMetadata.isExplicitlyMarked && !rootMetadata.isHandledWithoutAnnotation))\n {\n throw new TypeError(\"The TypedJSON root data type must have the @jsonObject decorator used.\");\n }\n\n this.nameResolver = (ctor) => nameof(ctor);\n this.rootConstructor = rootConstructor;\n this.errorHandler = (error) => logError(error);\n\n if (settings)\n {\n this.config(settings);\n }\n else if (TypedJSON._globalConfig)\n {\n this.config({});\n }\n }\n\n /**\n * Configures TypedJSON through a settings object.\n * @param settings The configuration settings object.\n */\n public config(settings: ITypedJSONSettings)\n {\n if (TypedJSON._globalConfig)\n {\n settings = {\n ...TypedJSON._globalConfig,\n ...settings\n };\n\n if (settings.knownTypes && TypedJSON._globalConfig.knownTypes)\n {\n // Merge known-types (also de-duplicate them, so Array -> Set -> Array).\n settings.knownTypes = Array.from(new Set(\n settings.knownTypes.concat(TypedJSON._globalConfig.knownTypes),\n ));\n }\n }\n\n if (settings.errorHandler)\n {\n this.errorHandler = settings.errorHandler;\n this.deserializer.setErrorHandler(settings.errorHandler);\n this.serializer.setErrorHandler(settings.errorHandler);\n }\n\n if (settings.replacer) this.replacer = settings.replacer;\n if (settings.typeResolver) this.deserializer.setTypeResolver(settings.typeResolver);\n if (settings.typeHintEmitter) this.serializer.setTypeHintEmitter(settings.typeHintEmitter);\n if (settings.indent) this.indent = settings.indent;\n\n if (settings.nameResolver)\n {\n this.nameResolver = settings.nameResolver;\n this.deserializer.setNameResolver(settings.nameResolver);\n // this.serializer.set\n }\n\n if (settings.knownTypes)\n {\n // Type-check knownTypes elements to recognize errors in advance.\n settings.knownTypes.forEach((knownType, i) =>\n {\n // tslint:disable-next-line:no-null-keyword\n if (typeof knownType === \"undefined\" || knownType === null)\n {\n logWarning(\n `TypedJSON.config: 'knownTypes' contains an undefined/null value (element ${i}).`);\n }\n });\n\n this.globalKnownTypes = settings.knownTypes;\n }\n }\n\n /**\n * Converts a JSON string to the root class type.\n * @param object The JSON to parse and convert.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns Deserialized T or undefined if there were errors.\n */\n public parse(object: any): T|undefined\n {\n const json = parseToJSObject(object, this.rootConstructor);\n\n let rootMetadata = JsonObjectMetadata.getFromConstructor(this.rootConstructor);\n let result: T|undefined;\n let knownTypes = new Map();\n\n this.globalKnownTypes.filter(ktc => ktc).forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n\n if (rootMetadata)\n {\n rootMetadata.knownTypes.forEach(knownTypeCtor =>\n {\n knownTypes.set(this.nameResolver(knownTypeCtor), knownTypeCtor);\n });\n }\n\n try\n {\n result = this.deserializer.convertSingleValue(json, {\n selfConstructor: this.rootConstructor,\n knownTypes: knownTypes,\n }) as T;\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n\n return result;\n }\n\n public parseAsArray(object: any, dimensions?: 1): T[];\n public parseAsArray(object: any, dimensions: 2): T[][];\n public parseAsArray(object: any, dimensions: 3): T[][][];\n public parseAsArray(object: any, dimensions: 4): T[][][][];\n public parseAsArray(object: any, dimensions: 5): T[][][][][];\n public parseAsArray(object: any, dimensions: number): any[];\n public parseAsArray(object: any, dimensions: number = 1): any[]\n {\n const json = parseToJSObject(object, Array);\n if (json instanceof Array)\n {\n return this.deserializer.convertAsArray(json, {\n selfConstructor: Array,\n elementConstructor: new Array(dimensions - 1)\n .fill(Array)\n .concat(this.rootConstructor),\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define an Array`\n + `, but got ${typeof json}.`));\n }\n\n return [];\n }\n\n public parseAsSet(object: any): Set\n {\n const json = parseToJSObject(object, Set);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsSet(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes)\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Set();\n }\n\n public parseAsMap(object: any, keyConstructor: Constructor): Map\n {\n const json = parseToJSObject(object, Map);\n // A Set is serialized as T[].\n if (json instanceof Array)\n {\n return this.deserializer.convertAsMap(json, {\n selfConstructor: Array,\n elementConstructor: [this.rootConstructor],\n knownTypes: this._mapKnownTypes(this.globalKnownTypes),\n keyConstructor: keyConstructor\n });\n }\n else\n {\n this.errorHandler(new TypeError(`Expected 'json' to define a Set (using an Array)`\n + `, but got ${typeof json}.`,\n ));\n }\n\n return new Map();\n }\n\n /**\n * Converts an instance of the specified class type to a plain JSON object.\n * @param object The instance to convert to a JSON string.\n * @returns Serialized object or undefined if an error has occured.\n */\n public toPlainJson(object: T): JsonTypes\n {\n try\n {\n return this.serializer.convertSingleValue(object, {\n selfType: this.rootConstructor\n });\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainArray(object: T[], dimensions?: 1): Object[];\n public toPlainArray(object: T[][], dimensions: 2): Object[][];\n public toPlainArray(object: T[][][], dimensions: 3): Object[][][];\n public toPlainArray(object: T[][][][], dimensions: 4): Object[][][][];\n public toPlainArray(object: T[][][][][], dimensions: 5): Object[][][][][];\n public toPlainArray(object: any[], dimensions: 1|2|3|4|5 = 1): Object[]|undefined\n {\n try\n {\n const elementConstructorArray =\n new Array(dimensions - 1).fill(Array).concat(this.rootConstructor);\n return this.serializer.convertAsArray(object, elementConstructorArray);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainSet(object: Set): Object[]|undefined\n {\n try\n {\n return this.serializer.convertAsSet(object, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n public toPlainMap(object: Map, keyConstructor: Constructor): { key: any, value: any }[]|undefined\n {\n try\n {\n return this.serializer.convertAsMap(object, keyConstructor, this.rootConstructor);\n }\n catch (e)\n {\n this.errorHandler(e);\n }\n }\n\n /**\n * Converts an instance of the specified class type to a JSON string.\n * @param object The instance to convert to a JSON string.\n * @throws Error if any errors are thrown in the specified errorHandler callback (re-thrown).\n * @returns String with the serialized object or an empty string if an error has occured, but\n * the errorHandler did not throw.\n */\n public stringify(object: T): string\n {\n const result = this.toPlainJson(object);\n if (result === undefined) {\n return '';\n }\n return JSON.stringify(result, this.replacer, this.indent);\n }\n\n public stringifyAsArray(object: T[], dimensions?: 1): string;\n public stringifyAsArray(object: T[][], dimensions: 2): string;\n public stringifyAsArray(object: T[][][], dimensions: 3): string;\n public stringifyAsArray(object: T[][][][], dimensions: 4): string;\n public stringifyAsArray(object: T[][][][][], dimensions: 5): string;\n public stringifyAsArray(object: any[], dimensions: any): string\n {\n return JSON.stringify(this.toPlainArray(object, dimensions), this.replacer, this.indent);\n }\n\n public stringifyAsSet(object: Set): string\n {\n return JSON.stringify(this.toPlainSet(object), this.replacer, this.indent);\n }\n\n public stringifyAsMap(object: Map, keyConstructor: Constructor): string\n {\n return JSON.stringify(this.toPlainMap(object, keyConstructor), this.replacer, this.indent);\n }\n\n private _mapKnownTypes(constructors: Array>)\n {\n let map = new Map>();\n\n constructors.filter(ctor => ctor).forEach(ctor => map.set(this.nameResolver(ctor), ctor));\n\n return map;\n }\n}\n\nexport { jsonObject } from \"./typedjson/json-object\";\nexport { jsonMember } from \"./typedjson/json-member\";\nexport { jsonArrayMember } from \"./typedjson/json-array-member\";\nexport { jsonSetMember } from \"./typedjson/json-set-member\";\nexport { jsonMapMember } from \"./typedjson/json-map-member\";\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/typedjson/helpers.d.ts b/js/typedjson/helpers.d.ts index 8ab697a..96a95a7 100644 --- a/js/typedjson/helpers.d.ts +++ b/js/typedjson/helpers.d.ts @@ -11,6 +11,7 @@ export declare function isDirectlySerializableNativeType(type: Function): boolea export declare function isTypeTypedArray(type: Function): boolean; export declare function isPrimitiveValue(obj: any): boolean; export declare function isObject(value: any): value is Object; +export declare function parseToJSObject(json: any, expectedType: Function): Object; /** * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B'). * @param A The supposed derived type. diff --git a/spec/just-json.spec.ts b/spec/just-json.spec.ts new file mode 100644 index 0000000..173ae85 --- /dev/null +++ b/spec/just-json.spec.ts @@ -0,0 +1,94 @@ +import { jsonArrayMember, jsonMember, jsonObject, TypedJSON } from "../js/typedjson"; + +describe('json (without automatic stringify)', function () { + describe('string', function () { + it('should deserialize', function () { + // stringified json version cuz "" + expect(TypedJSON.parse('"str"', String)).toEqual('str'); + // already parsed + expect(TypedJSON.parse('str', String)).toEqual('str'); + + // because we detect naively + try { + expect(TypedJSON.parse('"sdfs"fdsf"', String)).toEqual(undefined); + fail(); + } catch(e) {} + }); + + it('should serialize', function () { + expect(TypedJSON.toPlainJson('str', String)).toEqual('str'); + }); + }); + + describe('rest of primitives', function () { + it('should deserialize', function () { + expect(TypedJSON.parse(45834, Number)).toEqual(45834); + expect(TypedJSON.parse(true, Boolean)).toEqual(true); + expect(TypedJSON.parse(1543915254, Date)).toEqual(new Date(1543915254)); + expect(TypedJSON.parse('1970-01-18T20:51:55.254Z', Date)).toEqual(new Date(1543915254)); + + const dataBuffer = Uint8Array.from([100, 117, 112, 97]) as any; + expect(TypedJSON.parse('畤慰', ArrayBuffer)).toEqual(dataBuffer); + expect(TypedJSON.parse('畤慰', DataView)).toEqual(dataBuffer); + expect(TypedJSON.parse([100, 117, 112, 97], Uint8Array)).toEqual(dataBuffer); + }); + + it('should serialize', function () { + expect(TypedJSON.toPlainJson(45834, Number)).toEqual(45834); + expect(TypedJSON.toPlainJson(true, Boolean)).toEqual(true); + const dateMs = new Date(1543915254); + expect(TypedJSON.toPlainJson(dateMs, Date)).toEqual(dateMs); + const dateStr = new Date('2018-12-04T09:20:54'); + expect(TypedJSON.toPlainJson(dateStr, Date)).toEqual(dateStr); + + const buffer = new ArrayBuffer(4); + const view = new DataView(buffer); + view.setInt8(0, 100); + view.setInt8(1, 117); + view.setInt8(2, 112); + view.setInt8(3, 97); + expect(TypedJSON.toPlainJson(buffer, ArrayBuffer)).toEqual('畤慰'); + expect(TypedJSON.toPlainJson(view, DataView)).toEqual('畤慰'); + expect(TypedJSON.toPlainJson(new Uint8Array(buffer), Uint8Array)).toEqual([100, 117, 112, 97]); + }); + }); + + describe('object', function () { + + @jsonObject + class SomeThing { + @jsonMember + propStr: String; + @jsonMember + propNum: number; + @jsonArrayMember(String) + propArr: String[]; + } + + const json = Object.freeze({ + propStr: 'dsgs', + propNum: 653, + propArr: ['dslfks'], + }); + + it('should deserialize', function () { + expect(TypedJSON.parse(json, SomeThing)).toEqual(Object.assign(new SomeThing(), json)); + expect(TypedJSON.parseAsArray([json], SomeThing)).toEqual([Object.assign(new SomeThing(), json)]); + }); + + it('should serialize', function () { + expect(TypedJSON.toPlainJson(Object.assign(new SomeThing(), json), SomeThing)).toEqual(json); + expect(TypedJSON.toPlainArray([Object.assign(new SomeThing(), json)], SomeThing)).toEqual([json]); + }); + }); + + describe('array', function () { + it('should deserialize', function () { + expect(TypedJSON.parseAsArray(['alas', 'dfsd'], String)).toEqual(['alas', 'dfsd']); + }); + + it('should serialize', function () { + expect(TypedJSON.toPlainArray(['alas', 'dfsd'], String)).toEqual(['alas', 'dfsd']); + }); + }); +}); diff --git a/spec/parse-to-object.spec.ts b/spec/parse-to-object.spec.ts new file mode 100644 index 0000000..e16cbc5 --- /dev/null +++ b/spec/parse-to-object.spec.ts @@ -0,0 +1,58 @@ +import { parseToJSObject } from '../src/typedjson/helpers'; + +describe("parse To Object", function () { + it("should passthrough objects", function () { + const obj = { + a: 1, + b: 2, + }; + + const obj2 = parseToJSObject(obj, Object); + expect(obj2).toBe(obj); + }); + + it("should passthrough arrays", function () { + const arr = [{ + a: 1, + b: 2, + }]; + + const arr2 = parseToJSObject(arr, Array); + expect(arr2).toBe(arr); + }); + + it("should parse object string", function () { + const arr = { + a: 1, + b: 2, + }; + + const arr2 = parseToJSObject(JSON.stringify(arr), Object); + expect(arr2).toEqual(arr); + }); + + it("should passthrough primitives", function () { + expect(parseToJSObject(1, Number)).toBe(1); + expect(parseToJSObject(false, Boolean)).toBe(false); + }); + + it("should parse strings with quotes, but passthrough other", function () { + // string is obvious + expect(parseToJSObject('"I am a string"', String)).toEqual('I am a string'); + expect(parseToJSObject('just a string', String)).toBe('just a string'); + // but also the types that are serialized to string + expect(parseToJSObject('"1970-01-18T20:51:55.254Z"', Date)).toEqual('1970-01-18T20:51:55.254Z'); + expect(parseToJSObject('1970-01-18T20:51:55.254Z', Date)).toBe('1970-01-18T20:51:55.254Z'); + expect(parseToJSObject('"畤慰"', ArrayBuffer)).toEqual('畤慰'); + expect(parseToJSObject('畤慰', ArrayBuffer)).toBe('畤慰'); + expect(parseToJSObject('"畤慰"', DataView)).toEqual('畤慰'); + expect(parseToJSObject('畤慰', DataView)).toBe('畤慰'); + }); + + it("should passthrough builtins", function () { + const date = new Date; + expect(parseToJSObject(date, Date)).toBe(date); + const buffer = new ArrayBuffer(3); + expect(parseToJSObject(buffer, ArrayBuffer)).toBe(buffer); + }); +}); diff --git a/src/typedjson.ts b/src/typedjson.ts index 5665dc4..04b7fe7 100644 --- a/src/typedjson.ts +++ b/src/typedjson.ts @@ -1,4 +1,4 @@ -import { nameof, logError, logWarning } from './typedjson/helpers'; +import { nameof, logError, logWarning, parseToJSObject } from './typedjson/helpers'; import { Constructor } from "./typedjson/types"; import { JsonObjectMetadata } from "./typedjson/metadata"; import { Deserializer } from "./typedjson/deserializer"; @@ -318,7 +318,7 @@ export class TypedJSON */ public parse(object: any): T|undefined { - const json = JSON.parse(object); + const json = parseToJSObject(object, this.rootConstructor); let rootMetadata = JsonObjectMetadata.getFromConstructor(this.rootConstructor); let result: T|undefined; @@ -360,7 +360,7 @@ export class TypedJSON public parseAsArray(object: any, dimensions: number): any[]; public parseAsArray(object: any, dimensions: number = 1): any[] { - const json = JSON.parse(object); + const json = parseToJSObject(object, Array); if (json instanceof Array) { return this.deserializer.convertAsArray(json, { @@ -382,7 +382,7 @@ export class TypedJSON public parseAsSet(object: any): Set { - const json = JSON.parse(object); + const json = parseToJSObject(object, Set); // A Set is serialized as T[]. if (json instanceof Array) { @@ -404,7 +404,7 @@ export class TypedJSON public parseAsMap(object: any, keyConstructor: Constructor): Map { - const json = JSON.parse(object); + const json = parseToJSObject(object, Map); // A Set is serialized as T[]. if (json instanceof Array) { diff --git a/src/typedjson/helpers.ts b/src/typedjson/helpers.ts index f409e9f..71c4a24 100644 --- a/src/typedjson/helpers.ts +++ b/src/typedjson/helpers.ts @@ -60,6 +60,25 @@ export function isObject(value: any): value is Object return typeof value === "object"; } +function shouldOmitParseString(jsonStr: string, expectedType: Function): boolean { + const expectsTypesSerializedAsStrings = expectedType === String + || expectedType === ArrayBuffer + || expectedType === DataView; + + const hasQuotes = jsonStr.length >= 2 && jsonStr[0] === '"' && jsonStr[jsonStr.length-1] === '"'; + const isInteger = /^\d+$/.test(jsonStr.trim()); + + return (expectsTypesSerializedAsStrings && !hasQuotes) || ((!hasQuotes && !isInteger) && expectedType === Date); +} + +export function parseToJSObject(json: any, expectedType: Function): Object { + if (typeof json !== 'string' || shouldOmitParseString(json, expectedType)) + { + return json; + } + return JSON.parse(json); +} + /** * Determines if 'A' is a sub-type of 'B' (or if 'A' equals 'B'). * @param A The supposed derived type.