diff --git a/js/typedjson.d.ts b/js/typedjson.d.ts index 3a20c19..02e2f3c 100644 --- a/js/typedjson.d.ts +++ b/js/typedjson.d.ts @@ -4,3 +4,4 @@ export { jsonMember } from "./typedjson/json-member"; export { jsonArrayMember } from "./typedjson/json-array-member"; export { jsonSetMember } from "./typedjson/json-set-member"; export { jsonMapMember } from "./typedjson/json-map-member"; +export { toJson } from "./typedjson/to-json"; diff --git a/js/typedjson.js b/js/typedjson.js index a64259a..405f770 100644 --- a/js/typedjson.js +++ b/js/typedjson.js @@ -1612,6 +1612,28 @@ function jsonMapMember(keyConstructor, valueConstructor, options) { }; } +// CONCATENATED MODULE: ./src/typedjson/to-json.ts + +function toJson(optionsOrTarget) { + if (typeof optionsOrTarget === 'function') { + // used directly + toJsonDecorator(optionsOrTarget, {}); + return; + } + // used as a factory + return function (target) { + toJsonDecorator(target, optionsOrTarget); + }; +} +function toJsonDecorator(target, options) { + if (!options.overwrite && target.prototype.toJSON) { + throw new Error(target.name + " already has toJSON defined!"); + } + target.prototype.toJSON = function () { + return parser_TypedJSON.toPlainJson(this, Object.getPrototypeOf(this).constructor); + }; +} + // CONCATENATED MODULE: ./src/typedjson.ts /* concated harmony reexport TypedJSON */__webpack_require__.d(__webpack_exports__, "TypedJSON", function() { return parser_TypedJSON; }); /* concated harmony reexport jsonObject */__webpack_require__.d(__webpack_exports__, "jsonObject", function() { return jsonObject; }); @@ -1619,6 +1641,8 @@ function jsonMapMember(keyConstructor, valueConstructor, options) { /* concated harmony reexport jsonArrayMember */__webpack_require__.d(__webpack_exports__, "jsonArrayMember", function() { return jsonArrayMember; }); /* concated harmony reexport jsonSetMember */__webpack_require__.d(__webpack_exports__, "jsonSetMember", function() { return jsonSetMember; }); /* concated harmony reexport jsonMapMember */__webpack_require__.d(__webpack_exports__, "jsonMapMember", function() { return jsonMapMember; }); +/* concated harmony reexport toJson */__webpack_require__.d(__webpack_exports__, "toJson", function() { return toJson; }); + diff --git a/js/typedjson.js.map b/js/typedjson.js.map index 626d996..089afe2 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/serializer.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/parser.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,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;AC7EO,IAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAExE,SAAS,eAAe,CAAI,IAAmB;IAElD,QAAQ,IAAW,EACnB;QACI,KAAK,MAAM;YACP,OAAO,CAAQ,CAAC;QAEpB,KAAK,MAAM;YACP,OAAO,EAAS,CAAC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0B,EAAE,OAAmC;IAAnC,sCAAmC;IAEnH,OAAO,UAAC,MAAc,EAAE,OAAwB;QAE5C,IAAI,aAAa,GAAG,uBAAqB,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAI,MAAM,CAAC,OAAO,CAAG,CAAC,CAAC,sBAAsB;QAEhH,IAAI,OAAO,cAAc,KAAK,UAAU,EACxC;YACI,QAAQ,CAAI,aAAa,4DAAyD,CAAC,CAAC;YACpF,OAAO;SACV;QAED,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAC1C;YACI,QAAQ,CAAI,aAAa,8DAA2D,CAAC,CAAC;YACtF,OAAO;SACV;QAED,kHAAkH;QAClH,IAAI,0BAA0B,IAAI,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,EAC7F;YACI,QAAQ,CAAI,aAAa,6BAA0B,CAAC,CAAC;YACrD,OAAO;SACV;QAED,yBAAyB,CAAC,MAAM,EAAE,OAAO,EAAE;YACvC,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,CAAC,gBAAgB,CAAC;YAC/B,OAAO,EAAE,cAAc;YACvB,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;YACnD,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,KAAK;YACvC,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE;YACvB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE;YACxC,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;SACjC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;;;ACtED;AAAA;AAAA;AAAA;AAAA;AAAA;AAAoE;AACf;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, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\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 type 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(message, ...optionalParams);\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`ERROR: ${message}`, ...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(message, ...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(message, ...optionalParams);\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`WARNING: ${message}`, ...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, 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 { 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 { Constructor } from \"./typedjson/types\";\nimport { Serializer } from \"./typedjson/serializer\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\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","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 as Object;\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","export { TypedJSON, ITypedJSONSettings, JsonTypes } from \"./parser\";\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/serializer.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/parser.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/to-json.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,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AAC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AAE;YACxC,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;SACjC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;;;ACtEqC;AAyB/B,SAAS,MAAM,CAAmB,eAA0C;IAE/E,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;QACvC,gBAAgB;QAChB,eAAe,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QACrC,OAAO;KACV;IACD,oBAAoB;IACpB,OAAO,UAAC,MAAgB;QACpB,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAmB,MAAgB,EAAE,OAAuB;IAChF,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE;QAC/C,MAAM,IAAI,KAAK,CAAI,MAAM,CAAC,IAAI,iCAA8B,CAAC,CAAC;KACjE;IACD,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;QACtB,OAAO,gBAAS,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC;IAChF,CAAC;AACL,CAAC;;;AC7CD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAoE;AACf;AACA;AACW;AACJ;AACA;AACf","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, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\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 type 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(message, ...optionalParams);\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`ERROR: ${message}`, ...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(message, ...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(message, ...optionalParams);\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`WARNING: ${message}`, ...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, 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 { 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 { Constructor } from \"./typedjson/types\";\nimport { Serializer } from \"./typedjson/serializer\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\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","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 as Object;\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 { TypedJSON } from \"../parser\";\n\n/**\n * Options for the @toJson decorator.\n */\nexport interface IToJsonOptions {\n /**\n * When set to true it will overwrite any toJSON already existing on the prototype.\n */\n overwrite?: boolean;\n}\n\n/**\n * Decorator that will generate toJSON function on the class prototype that allows\n * JSON.stringify to be used instead of TypedJSON.stringify. Under the hood it will\n * simply delegate to TypedJSON.\n * By default it will throw if the prototype already has a toJSON function defined.\n * @param target the class which prototype should be modified.\n */\nexport function toJson(target: Function): void;\n/**\n * Decorator factory that accepts the options interface.\n * @param options for configuring the toJSON creation.\n */\nexport function toJson(options: IToJsonOptions): ((target: Function) => void);\nexport function toJson(optionsOrTarget: IToJsonOptions | Function\n): ((target: Function) => void) | void {\n if (typeof optionsOrTarget === 'function') {\n // used directly\n toJsonDecorator(optionsOrTarget, {});\n return;\n }\n // used as a factory\n return (target: Function) => {\n toJsonDecorator(target, optionsOrTarget);\n }\n}\n\nfunction toJsonDecorator(target: Function, options: IToJsonOptions): void {\n if (!options.overwrite && target.prototype.toJSON) {\n throw new Error(`${target.name} already has toJSON defined!`);\n }\n target.prototype.toJSON = function () {\n return TypedJSON.toPlainJson(this, Object.getPrototypeOf(this).constructor);\n }\n}\n","export { TypedJSON, ITypedJSONSettings, JsonTypes } from \"./parser\";\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\";\nexport { toJson } from \"./typedjson/to-json\";\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/typedjson.min.js b/js/typedjson.min.js index 2adbbd5..1650874 100644 --- a/js/typedjson.min.js +++ b/js/typedjson.min.js @@ -1,3 +1,3 @@ // [typedjson] Version: 1.2.3 - 2019-03-14 - !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(t){var n={};function o(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=t,o.c=n,o.d=function(e,r,t){o.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(r,e){if(1&e&&(r=o(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(o.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)o.d(t,n,function(e){return r[e]}.bind(null,n));return t},o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,"a",r),r},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.p="",o(o.s=0)}([function(e,r,t){"use strict";t.r(r);var s="__typedJsonJsonObjectMetadataInformation__";function i(e){return!!~[Date,Number,String,Boolean].indexOf(e)}function a(e){return!!~[Float32Array,Float64Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array].indexOf(e)}function c(e,r){return"string"!=typeof e||(t=e,o=(n=r)===String||n===ArrayBuffer||n===DataView,i=2<=t.length&&'"'===t[0]&&'"'===t[t.length-1],s=/^\d+$/.test(t.trim()),o&&!i||!i&&!s&&n===Date)?e:JSON.parse(e);var t,n,o,i,s}function f(e,r){return e===r||e.prototype instanceof r}function u(e){for(var r=[],t=1;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 type 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(message, ...optionalParams);\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`ERROR: ${message}`, ...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(message, ...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(message, ...optionalParams);\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`WARNING: ${message}`, ...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, 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 { 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 { Constructor } from \"./typedjson/types\";\nimport { Serializer } from \"./typedjson/serializer\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\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","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 as Object;\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","export { TypedJSON, ITypedJSONSettings, JsonTypes } from \"./parser\";\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/serializer.ts","webpack://typedjson/./src/typedjson/deserializer.ts","webpack://typedjson/./src/parser.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/to-json.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","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","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","JSON","parse","isSubtypeOf","A","B","logError","message","optionalParams","_i","arguments","console","error","apply","concat","log","logWarning","warn","isValueDefined","isInstanceOf","constructor","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","configurable","writable","add","keyType","elementType","elemCtor","serializer_Serializer","Serializer","_typeHintEmitter","targetObject","sourceObject","expectedSourceType","sourceTypeMetadata","name_1","_errorHandler","setTypeHintEmitter","typeEmitterCallback","TypeError","setErrorHandler","errorHandlerCallback","convertSingleValue","typeInfo","memberName","selfType","convertAsArrayBuffer","convertAsDataView","Array","convertAsArray","elementTypes","convertAsSet","convertAsMap","convertAsTypedArray","convertAsObject","expectedName","actualName","_this","sourceMeta_1","memberMetadata","serializer","__assign","expectedElementType","element","expectedTypeName","actualTypeName","typeInfoForElements","slice","map","elementTypeInfo","resultArray","resultElement","push","expectedKeyType","keyTypeInfo","resultKeyValuePairObj","from","buffer","charCode","fromCharCode","join","dataView","deserializer_Deserializer","Deserializer","_typeResolver","__type","setNameResolver","nameResolverCallback","_nameResolver","setTypeResolver","typeResolverCallback","sourceObjectTypeInfo","objectName","expectedSelfType","selfConstructor","sourceObjectMetadata","knownTypeConstructors","_mergeKnownTypes","_createKnownTypesMap","typeFromTypeHint","sourceMetadata_1","sourceObjectWithDeserializedProperties_1","revivedValue","memberValue","memberNameForDebug","elementConstructor","keyConstructor","isRequired","initializerCallback","e","_instantiateType","assign","onDeserializedMethodName","targetObject_1","keys","sourceKey","srcTypeNameForDebug","_isDirectlyDeserializableNativeType","_makeTypeErrorMessage","_throwTypeMismatchError","every","elem","isNaN","_stringToArrayBuffer","_stringToDataView","resultSet","valueTypeInfo","resultMap","targetType","actualSourceType","actualType","knownTypeMaps","result","knowTypes","knownTypeMeta","convertNativeObject","str","buf","bufView","strLen","charCodeAt","parser_TypedJSON","TypedJSON","rootConstructor","settings","globalKnownTypes","indent","rootMetadata","nameResolver","errorHandler","config","_globalConfig","rootType","parseAsArray","dimensions","parseAsSet","parseAsMap","valueType","toPlainJson","toPlainArray","toPlainSet","stringifyAsSet","toPlainMap","keyCtor","valueCtor","stringifyAsMap","stringify","stringifyAsArray","setGlobalConfig","parser_assign","replacer","typeResolver","typeHintEmitter","knownType","filter","ktc","knownTypeCtor","fill","_mapKnownTypes","elementConstructorArray","undefined","constructors","jsonObject","optionsOrTarget","options","decorator","target","onDeserialized","initializer","knownTypeMethodName","jsonMember","propCtor","isSpecialPropertyType","emitDefaultValue","toString","reflectPropCtor","jsonArrayMember","elementCtor","jsonSetMember","jsonMapMember","valueConstructor","toJson","toJsonDecorator","overwrite","toJSON","Error","getPrototypeOf","__webpack_exports__"],"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,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAR,QAGA,IAAAC,EAAAK,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAV,QAAA,IAUA,OANAW,EAAAH,GAAAI,KAAAX,EAAAD,QAAAC,IAAAD,QAAAO,GAGAN,EAAAS,GAA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/D,EAAUiB,YAAY7P,KAAMc,OAAO+R,eAAe7S,MAAMqF,cC3CvEnF,EAAAQ,EAAAoS,EAAA,8BAAAlE,IAAA1O,EAAAQ,EAAAoS,EAAA,+BAAAzB,IAAAnR,EAAAQ,EAAAoS,EAAA,+BAAAjB,IAAA3R,EAAAQ,EAAAoS,EAAA,oCAAAX,IAAAjS,EAAAQ,EAAAoS,EAAA,kCAAAT,IAAAnS,EAAAQ,EAAAoS,EAAA,kCAAAR,IAAApS,EAAAQ,EAAAoS,EAAA,2BAAAN","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, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\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 type 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(message, ...optionalParams);\n }\n else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`ERROR: ${message}`, ...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(message, ...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(message, ...optionalParams);\n } else if (typeof console === \"object\" && typeof console.log === \"function\")\n {\n console.log(`WARNING: ${message}`, ...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, 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 { 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 { Constructor } from \"./typedjson/types\";\nimport { Serializer } from \"./typedjson/serializer\";\nimport { Deserializer } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\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","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 as Object;\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 { TypedJSON } from \"../parser\";\n\n/**\n * Options for the @toJson decorator.\n */\nexport interface IToJsonOptions {\n /**\n * When set to true it will overwrite any toJSON already existing on the prototype.\n */\n overwrite?: boolean;\n}\n\n/**\n * Decorator that will generate toJSON function on the class prototype that allows\n * JSON.stringify to be used instead of TypedJSON.stringify. Under the hood it will\n * simply delegate to TypedJSON.\n * By default it will throw if the prototype already has a toJSON function defined.\n * @param target the class which prototype should be modified.\n */\nexport function toJson(target: Function): void;\n/**\n * Decorator factory that accepts the options interface.\n * @param options for configuring the toJSON creation.\n */\nexport function toJson(options: IToJsonOptions): ((target: Function) => void);\nexport function toJson(optionsOrTarget: IToJsonOptions | Function\n): ((target: Function) => void) | void {\n if (typeof optionsOrTarget === 'function') {\n // used directly\n toJsonDecorator(optionsOrTarget, {});\n return;\n }\n // used as a factory\n return (target: Function) => {\n toJsonDecorator(target, optionsOrTarget);\n }\n}\n\nfunction toJsonDecorator(target: Function, options: IToJsonOptions): void {\n if (!options.overwrite && target.prototype.toJSON) {\n throw new Error(`${target.name} already has toJSON defined!`);\n }\n target.prototype.toJSON = function () {\n return TypedJSON.toPlainJson(this, Object.getPrototypeOf(this).constructor);\n }\n}\n","export { TypedJSON, ITypedJSONSettings, JsonTypes } from \"./parser\";\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\";\nexport { toJson } from \"./typedjson/to-json\";\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/typedjson/to-json.d.ts b/js/typedjson/to-json.d.ts new file mode 100644 index 0000000..e989a8d --- /dev/null +++ b/js/typedjson/to-json.d.ts @@ -0,0 +1,22 @@ +/** + * Options for the @toJson decorator. + */ +export interface IToJsonOptions { + /** + * When set to true it will overwrite any toJSON already existing on the prototype. + */ + overwrite?: boolean; +} +/** + * Decorator that will generate toJSON function on the class prototype that allows + * JSON.stringify to be used instead of TypedJSON.stringify. Under the hood it will + * simply delegate to TypedJSON. + * By default it will throw if the prototype already has a toJSON function defined. + * @param target the class which prototype should be modified. + */ +export declare function toJson(target: Function): void; +/** + * Decorator factory that accepts the options interface. + * @param options for configuring the toJSON creation. + */ +export declare function toJson(options: IToJsonOptions): ((target: Function) => void); diff --git a/readme.md b/readme.md index d3d4fc8..a0ca71c 100644 --- a/readme.md +++ b/readme.md @@ -132,6 +132,10 @@ class MyDataClass This is not needed for `@jsonArrayMember`, `@jsonMapMember`, and `@jsonSetMember`, as those types already know the property type itself, as well as element/key types (although using ReflectDecorators adds runtime-type checking to these decorators, to help you spot errors). +### Using `JSON.stringify` + +If you want to use `JSON.stringify` to serialize the objects using TypedJSON you can annotate a class with `@toJson` and it will create `toJSON` function on the class prototype. By default it will throw an error if such function is already defined, but you can override this behavior by setting `overwrite` to `true` in the decorator's options. + ## Limitations ### Type-definitions diff --git a/spec/to-json.spec.ts b/spec/to-json.spec.ts new file mode 100644 index 0000000..7ab209f --- /dev/null +++ b/spec/to-json.spec.ts @@ -0,0 +1,97 @@ +import {jsonObject, jsonMember, toJson} from "../js/typedjson"; + +describe('toJson decorator', function () { + it('should work with JSON.stringify', function () { + @toJson + @jsonObject + class Person { + firstName?: string; + + @jsonMember({name: 'surname'}) + lastName?: string; + + public getFullName() { + return this.firstName + " " + this.lastName; + } + } + + const person = new Person; + person.firstName = 'John'; + person.lastName = 'Doe'; + expect(JSON.stringify(person)).toBe('{"surname":"Doe"}'); + }); + + it('should work on the abstract class', function () { + @toJson + abstract class Base { + @jsonMember({name: 'renamed'}) + prop?: string; + } + + @jsonObject + class Sub extends Base { + @jsonMember({name: 'numeric'}) + num?: number; + } + + @jsonObject + class OtherSub extends Base { + @jsonMember + decimal?: number; + ignored?: string; + } + + + const sub = new Sub; + sub.prop = 'value'; + sub.num = 20; + expect(JSON.stringify(sub)).toBe('{"renamed":"value","numeric":20}'); + + const otherSub = new OtherSub; + otherSub.prop = 'value'; + otherSub.decimal = 123; + otherSub.ignored = 'assigned'; + expect(JSON.stringify(otherSub)).toBe('{"renamed":"value","decimal":123}'); + }); + + it("should throw an error when toJSON already exists", function () { + try { + @toJson + @jsonObject + class Some { + @jsonMember + prop?: string; + + toJSON() { + return {}; + } + } + + const some = new Some; + some.prop = 'value'; + expect(JSON.stringify(some)).toBe('{}'); + + fail('Should not succeed'); + } catch (error) { + // ok + } + }); + + + it("should overwrite toJSON when overwrite is true", function () { + @toJson({overwrite: true}) + @jsonObject + class Some { + @jsonMember + prop?: string; + + toJSON() { + return {}; + } + } + + const some = new Some; + some.prop = 'value'; + expect(JSON.stringify(some)).toBe('{"prop":"value"}'); + }); +}); diff --git a/src/typedjson.ts b/src/typedjson.ts index 3a20c19..02e2f3c 100644 --- a/src/typedjson.ts +++ b/src/typedjson.ts @@ -4,3 +4,4 @@ export { jsonMember } from "./typedjson/json-member"; export { jsonArrayMember } from "./typedjson/json-array-member"; export { jsonSetMember } from "./typedjson/json-set-member"; export { jsonMapMember } from "./typedjson/json-map-member"; +export { toJson } from "./typedjson/to-json"; diff --git a/src/typedjson/to-json.ts b/src/typedjson/to-json.ts new file mode 100644 index 0000000..905c2bc --- /dev/null +++ b/src/typedjson/to-json.ts @@ -0,0 +1,46 @@ +import { TypedJSON } from "../parser"; + +/** + * Options for the @toJson decorator. + */ +export interface IToJsonOptions { + /** + * When set to true it will overwrite any toJSON already existing on the prototype. + */ + overwrite?: boolean; +} + +/** + * Decorator that will generate toJSON function on the class prototype that allows + * JSON.stringify to be used instead of TypedJSON.stringify. Under the hood it will + * simply delegate to TypedJSON. + * By default it will throw if the prototype already has a toJSON function defined. + * @param target the class which prototype should be modified. + */ +export function toJson(target: Function): void; +/** + * Decorator factory that accepts the options interface. + * @param options for configuring the toJSON creation. + */ +export function toJson(options: IToJsonOptions): ((target: Function) => void); +export function toJson(optionsOrTarget: IToJsonOptions | Function +): ((target: Function) => void) | void { + if (typeof optionsOrTarget === 'function') { + // used directly + toJsonDecorator(optionsOrTarget, {}); + return; + } + // used as a factory + return (target: Function) => { + toJsonDecorator(target, optionsOrTarget); + } +} + +function toJsonDecorator(target: Function, options: IToJsonOptions): void { + if (!options.overwrite && target.prototype.toJSON) { + throw new Error(`${target.name} already has toJSON defined!`); + } + target.prototype.toJSON = function () { + return TypedJSON.toPlainJson(this, Object.getPrototypeOf(this).constructor); + } +}