diff --git a/js/typedjson.js b/js/typedjson.js index c3430af..aae822d 100644 --- a/js/typedjson.js +++ b/js/typedjson.js @@ -364,17 +364,12 @@ function injectMetadataInformation(constructor, propKey, metadata) { } // CONCATENATED MODULE: ./src/typedjson/options-base.ts -/** - * This options cascade through the annotations. Options set - * in the more specific place override the previous option. - * Ex. @jsonMember overrides TypedJson options. - */ var kAllOptions = [ 'preserveNull', ]; function extractOptionBase(from) { var options = Object.keys(from) - .filter(function (key) { return kAllOptions.includes(key); }) + .filter(function (key) { return kAllOptions.indexOf(key) > -1; }) .reduce(function (obj, key) { obj[key] = from[key]; return obj; diff --git a/js/typedjson.js.map b/js/typedjson.js.map index 008b63d..9dc9ab3 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/options-base.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;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QA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AAC,CAAC;AACN,CAAC;;;ACxEqC;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;AAAmG;AAC9C;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 const MISSING_REFLECT_CONF_MSG = 'Are you sure, that you have both \"experimentalDecorators\"' +\n ' and \"emitDecoratorMetadata\" in your tsconfig.json?';\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 isDirectlyDeserializableNativeType(type: Function): boolean\n{\n return !!(~[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 }\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 return \"undefined\";\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { OptionsBase } from \"./options-base\";\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 options?: OptionsBase;\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 options?: OptionsBase;\n\n public onDeserializedMethodName?: string;\n\n public beforeSerializationMethodName?: 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 // clear metadata of undefined properties to save memory\n (Object.keys(metadata) as [keyof JsonMemberMetadata])\n .forEach((key) => (metadata[key] === undefined) && delete metadata[key]);\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","/**\n * This options cascade through the annotations. Options set\n * in the more specific place override the previous option.\n * Ex. @jsonMember overrides TypedJson options.\n */\n\nexport interface OptionsBase {\n /**\n * Whether to preserve null in the JSON output. When false it\n * will not emit nor store the property if its value is null.\n * Default: false.\n */\n preserveNull?: boolean;\n}\n\nconst kAllOptions: (keyof OptionsBase)[] = [\n 'preserveNull',\n];\n\nexport function extractOptionBase(from: any): OptionsBase|undefined {\n const options = Object.keys(from)\n .filter(key => (kAllOptions as string[]).includes(key))\n .reduce((obj, key) => {\n obj[key] = from[key];\n return obj;\n }, {} as any);\n return Object.keys(options).length > 0 ? options : undefined;\n}\n\nexport function getDefaultOptionOf(key: K): Required[K] {\n switch (key) {\n case \"preserveNull\":\n return false;\n }\n // never reached\n return null as any;\n}\n\nexport function getOptionValue(\n key: K,\n options?: OptionsBase,\n): Required[K] {\n if (options && options[key] != null) return options[key]!;\n return getDefaultOptionOf(key);\n}\n\nexport function mergeOptions(\n existing?: OptionsBase,\n moreSpecific?: OptionsBase,\n): OptionsBase|undefined {\n return !moreSpecific\n ? existing\n : Object.assign(\n {},\n existing,\n moreSpecific,\n );\n}\n","import {\n isDirectlySerializableNativeType,\n isInstanceOf,\n isTypeTypedArray,\n isValueDefined,\n logError,\n nameof,\n} from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\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\nexport type TypeHintEmitter\n = (\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n ) => void;\n\nfunction defaultTypeEmitter(\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n) {\n // By default, we put a \"__type\" property on the output object if the actual object is not the\n // same as the expected one, so that deserialization will know what to deserialize into (given\n // the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n targetObject.__type = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n }\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class\n * instances, and so on) to an untyped javascript object (also called \"simple javascript object\"),\n * 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\n * 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 public options?: OptionsBase;\n private _typeHintEmitter: TypeHintEmitter = defaultTypeEmitter;\n private _errorHandler: (error: Error) => void = logError;\n\n public setTypeHintEmitter(typeEmitterCallback: TypeHintEmitter)\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName: string = \"object\",\n memberOptions?: OptionsBase,\n ): any {\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null) return null;\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(\n `Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`),\n );\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, memberOptions);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName, memberOptions);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName, memberOptions);\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, memberOptions);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple\n * javascript object for serialization.\n */\n public convertAsObject(\n sourceObject: IndexedObject,\n typeInfo: IScopeTypeInfo,\n memberName?: string,\n memberOptions?: OptionsBase,\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\n if (sourceTypeMetadata.beforeSerializationMethodName) {\n // check for member first\n if (typeof (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n // check for static\n else if (typeof (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n else \n {\n this._errorHandler(new TypeError(\n `beforeSerialization callback '${nameof(sourceTypeMetadata.classType)}.${sourceTypeMetadata.beforeSerializationMethodName}' is not a method.`\n ));\n }\n }\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),\n // and perform recursive conversion on each of them. The converted objects are put on the 'targetObject',\n // which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n const classOptions = mergeOptions(this.options, sourceMeta.options);\n\n sourceMeta.dataMembers.forEach((objMemberMetadata) =>\n {\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n let serialized;\n if (objMemberMetadata.serializer) {\n serialized = objMemberMetadata.serializer(sourceObject[objMemberMetadata.key]);\n } else if (objMemberMetadata.ctor) {\n serialized = this.convertSingleValue(\n sourceObject[objMemberMetadata.key],\n {\n selfType: objMemberMetadata.ctor,\n elementTypes: objMemberMetadata.elementType,\n keyType: objMemberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${objMemberMetadata.key}`,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${objMemberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n\n if (isValueDefined(serialized)\n || (this.retrievePreserveNull(objMemberOptions) && serialized === null)\n ) {\n targetObject[objMemberMetadata.name] = serialized;\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 * @param memberOptions If converted as a member, the member options.\n */\n public convertAsArray(\n sourceObject: any[],\n expectedElementType: Function[],\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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\n // value emitted during serialization. This is so that invalid element types don't unexpectedly\n // 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 (!(this.retrievePreserveNull(memberOptions) && element === null)\n && !isInstanceOf(element, expectedElementType[0])\n ) {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = element && nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]:` +\n ` expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n // For multidimensional arrays.\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [],\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(\n element => this.convertSingleValue(\n element, typeInfoForElements, memberName, memberOptions\n ),\n );\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array\n * of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements\n * (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n * @returns\n */\n public convertAsSet(\n sourceObject: Set,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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.\n // (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName, memberOptions);\n\n // Add to output if the source element was undefined, OR the converted element is defined.\n // This will add intentionally undefined values to output, but not values that became undefined\n // 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\n * of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n */\n public convertAsMap(\n sourceObject: Map,\n expectedKeyType: Function,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Array<{ key: any, value: any }> {\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 const resultArray: Array<{ key: any, value: any }> = [];\n const preserveNull = this.retrievePreserveNull(memberOptions);\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, memberOptions),\n value: this.convertSingleValue(value, elementTypeInfo, memberName, memberOptions),\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n const keyDefined = isValueDefined(resultKeyValuePairObj.key);\n const valueDefined = isValueDefined(resultKeyValuePairObj.value)\n || (resultKeyValuePairObj.value === null && preserveNull);\n if (keyDefined && valueDefined)\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\n * 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\n * returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n\n private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined, isDirectlyDeserializableNativeType } from \"./helpers\";\nimport { Constructor, IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\nexport type TypeResolver = (sourceObject: Object, knownTypes: Map) => Function|undefined|null;\n\nfunction defaultTypeResolver(sourceObject: any, knownTypes: Map): Function|undefined {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\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 public options?: OptionsBase;\n\n private _typeResolver: TypeResolver = defaultTypeResolver;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void = logError;\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: TypeResolver)\n {\n if (typeof typeResolverCallback !== \"function\")\n {\n throw new TypeError(\"'typeResolverCallback' is not a function.\");\n }\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 memberOptions?: OptionsBase,\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 const 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 const classOptions = mergeOptions(this.options, sourceMetadata.options);\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((objMemberMetadata, propKey) =>\n {\n const objMemberValue = sourceObject[propKey];\n const objMemberDebugName = `${nameof(sourceMetadata.classType)}.${propKey}`;\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n\n let revivedValue;\n if (objMemberMetadata.deserializer) {\n revivedValue = objMemberMetadata.deserializer(objMemberValue);\n } else if (objMemberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n objMemberValue,\n {\n selfConstructor: objMemberMetadata.ctor,\n elementConstructor: objMemberMetadata.elementType,\n keyConstructor: objMemberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n objMemberDebugName,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${objMemberDebugName} there is`\n + ` no constructor nor deserialization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue)\n || (this.retrievePreserveNull(objMemberOptions) && revivedValue === null)\n ) {\n sourceObjectWithDeserializedProperties[objMemberMetadata.key] = revivedValue;\n }\n else if (objMemberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${objMemberDebugName}'.`));\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 // check for member first\n if (typeof (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n // check for static\n else 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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ) {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null)\n {\n return null;\n }\n else if (!isValueDefined(sourceObject))\n {\n return;\n }\n else if (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 || expectedSelfType === Float64Array)\n {\n // Deserialize Float Array from number[].\n return this._convertAsFloatArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\n }\n else if (\n expectedSelfType === Uint8Array\n || expectedSelfType === Uint8ClampedArray\n || expectedSelfType === Uint16Array\n || expectedSelfType === Uint32Array\n ) {\n // Deserialize Uint array from number[].\n return this._convertAsUintArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\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 (Array.isArray(sourceObject))\n return this.convertAsArray(sourceObject, typeInfo, memberName, memberOptions);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsSet(sourceObject, typeInfo, memberName, memberOptions);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsMap(sourceObject, typeInfo, memberName, memberOptions);\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, memberOptions);\n }\n }\n\n public convertAsArray(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\n if (!(Array.isArray(sourceObject)))\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, `${memberName}[]`, memberOptions);\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Set {\n if (!(Array.isArray(sourceObject)))\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(\n element,\n elementTypeInfo,\n `${memberName}[${i}]`,\n memberOptions,\n ));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry\n // does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Map {\n if (!(Array.isArray(sourceObject)))\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, memberName, memberOptions);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(\n key,\n this.convertSingleValue(\n element.value,\n valueTypeInfo,\n `${memberName}[${key}]`,\n memberOptions,\n ),\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 _convertAsFloatArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject);\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _convertAsUintArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject.map(value => ~~value));\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string,\n ): never {\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: string)\n {\n const expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n const 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 _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 private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { Constructor } from \"./typedjson/types\";\nimport { Serializer, TypeHintEmitter } from \"./typedjson/serializer\";\nimport { Deserializer, TypeResolver } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\nimport { extractOptionBase, OptionsBase } from \"./typedjson/options-base\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\nexport { TypeResolver, TypeHintEmitter };\n\nexport interface ITypedJSONSettings extends OptionsBase\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?: TypeResolver;\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?: TypeHintEmitter;\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 ): Object[]|undefined {\n return new TypedJSON(elementType, settings).toPlainSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): { key: any, value: any }[]|undefined {\n return new TypedJSON(valueCtor, settings).toPlainMap(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 const options = extractOptionBase(settings);\n this.serializer.options = options;\n this.deserializer.options = options;\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(\n 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\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\nexport type InitializerCallback = (sourceObject: T, rawSourceObject: T) => T;\n\nexport interface IJsonObjectOptionsBase extends OptionsBase\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 of a static or instance method to call before the serialization\n * of the typed object is started.\n */\n beforeSerialization?: 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 * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer: InitializerCallback;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer?: InitializerCallback;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional\n * 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 objectMetadata.beforeSerializationMethodName = options.beforeSerialization;\n \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 const optionsBase = extractOptionBase(options);\n if (optionsBase)\n {\n objectMetadata.options = optionsBase;\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, MISSING_REFLECT_CONF_MSG,\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\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,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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 { isReflectMetadataSupported, logError, MISSING_REFLECT_CONF_MSG, nameof } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions extends OptionsBase\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 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 (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n logError(`${decoratorName}: property is not a Set. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, TypeResolver, TypeHintEmitter } 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 +{"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/options-base.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;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B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;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;AAAmG;AAC9C;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 const MISSING_REFLECT_CONF_MSG = 'Are you sure, that you have both \"experimentalDecorators\"' +\n ' and \"emitDecoratorMetadata\" in your tsconfig.json?';\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 isDirectlyDeserializableNativeType(type: Function): boolean\n{\n return !!(~[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 }\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 return \"undefined\";\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { OptionsBase } from \"./options-base\";\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 options?: OptionsBase;\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 options?: OptionsBase;\n\n public onDeserializedMethodName?: string;\n\n public beforeSerializationMethodName?: 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 // clear metadata of undefined properties to save memory\n (Object.keys(metadata) as [keyof JsonMemberMetadata])\n .forEach((key) => (metadata[key] === undefined) && delete metadata[key]);\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","/**\n * This options cascade through the annotations. Options set\n * in the more specific place override the previous option.\n * Ex. @jsonMember overrides TypedJson options.\n */\nexport interface OptionsBase {\n /**\n * Whether to preserve null in the JSON output. When false it\n * will not emit nor store the property if its value is null.\n * Default: false.\n */\n preserveNull?: boolean;\n}\n\nconst kAllOptions: (keyof OptionsBase)[] = [\n 'preserveNull',\n];\n\nexport function extractOptionBase(from: {[key: string]: any} & OptionsBase): OptionsBase|undefined {\n const options = Object.keys(from)\n .filter(key => (kAllOptions as string[]).indexOf(key) > -1)\n .reduce((obj, key) => {\n obj[key] = from[key];\n return obj;\n }, {} as any);\n return Object.keys(options).length > 0 ? options : undefined;\n}\n\nexport function getDefaultOptionOf(key: K): Required[K] {\n switch (key) {\n case \"preserveNull\":\n return false;\n }\n // never reached\n return null as any;\n}\n\nexport function getOptionValue(\n key: K,\n options?: OptionsBase,\n): Required[K] {\n if (options && options[key] != null) return options[key]!;\n return getDefaultOptionOf(key);\n}\n\nexport function mergeOptions(\n existing?: OptionsBase,\n moreSpecific?: OptionsBase,\n): OptionsBase|undefined {\n return !moreSpecific\n ? existing\n : Object.assign(\n {},\n existing,\n moreSpecific,\n );\n}\n","import {\n isDirectlySerializableNativeType,\n isInstanceOf,\n isTypeTypedArray,\n isValueDefined,\n logError,\n nameof,\n} from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\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\nexport type TypeHintEmitter\n = (\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n ) => void;\n\nfunction defaultTypeEmitter(\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n) {\n // By default, we put a \"__type\" property on the output object if the actual object is not the\n // same as the expected one, so that deserialization will know what to deserialize into (given\n // the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n targetObject.__type = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n }\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class\n * instances, and so on) to an untyped javascript object (also called \"simple javascript object\"),\n * 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\n * 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 public options?: OptionsBase;\n private _typeHintEmitter: TypeHintEmitter = defaultTypeEmitter;\n private _errorHandler: (error: Error) => void = logError;\n\n public setTypeHintEmitter(typeEmitterCallback: TypeHintEmitter)\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName: string = \"object\",\n memberOptions?: OptionsBase,\n ): any {\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null) return null;\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(\n `Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`),\n );\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, memberOptions);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName, memberOptions);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName, memberOptions);\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, memberOptions);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple\n * javascript object for serialization.\n */\n public convertAsObject(\n sourceObject: IndexedObject,\n typeInfo: IScopeTypeInfo,\n memberName?: string,\n memberOptions?: OptionsBase,\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\n if (sourceTypeMetadata.beforeSerializationMethodName) {\n // check for member first\n if (typeof (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n // check for static\n else if (typeof (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n else \n {\n this._errorHandler(new TypeError(\n `beforeSerialization callback '${nameof(sourceTypeMetadata.classType)}.${sourceTypeMetadata.beforeSerializationMethodName}' is not a method.`\n ));\n }\n }\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),\n // and perform recursive conversion on each of them. The converted objects are put on the 'targetObject',\n // which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n const classOptions = mergeOptions(this.options, sourceMeta.options);\n\n sourceMeta.dataMembers.forEach((objMemberMetadata) =>\n {\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n let serialized;\n if (objMemberMetadata.serializer) {\n serialized = objMemberMetadata.serializer(sourceObject[objMemberMetadata.key]);\n } else if (objMemberMetadata.ctor) {\n serialized = this.convertSingleValue(\n sourceObject[objMemberMetadata.key],\n {\n selfType: objMemberMetadata.ctor,\n elementTypes: objMemberMetadata.elementType,\n keyType: objMemberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${objMemberMetadata.key}`,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${objMemberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n\n if (isValueDefined(serialized)\n || (this.retrievePreserveNull(objMemberOptions) && serialized === null)\n ) {\n targetObject[objMemberMetadata.name] = serialized;\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 * @param memberOptions If converted as a member, the member options.\n */\n public convertAsArray(\n sourceObject: any[],\n expectedElementType: Function[],\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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\n // value emitted during serialization. This is so that invalid element types don't unexpectedly\n // 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 (!(this.retrievePreserveNull(memberOptions) && element === null)\n && !isInstanceOf(element, expectedElementType[0])\n ) {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = element && nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]:` +\n ` expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n // For multidimensional arrays.\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [],\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(\n element => this.convertSingleValue(\n element, typeInfoForElements, memberName, memberOptions\n ),\n );\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array\n * of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements\n * (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n * @returns\n */\n public convertAsSet(\n sourceObject: Set,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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.\n // (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName, memberOptions);\n\n // Add to output if the source element was undefined, OR the converted element is defined.\n // This will add intentionally undefined values to output, but not values that became undefined\n // 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\n * of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n */\n public convertAsMap(\n sourceObject: Map,\n expectedKeyType: Function,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Array<{ key: any, value: any }> {\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 const resultArray: Array<{ key: any, value: any }> = [];\n const preserveNull = this.retrievePreserveNull(memberOptions);\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, memberOptions),\n value: this.convertSingleValue(value, elementTypeInfo, memberName, memberOptions),\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n const keyDefined = isValueDefined(resultKeyValuePairObj.key);\n const valueDefined = isValueDefined(resultKeyValuePairObj.value)\n || (resultKeyValuePairObj.value === null && preserveNull);\n if (keyDefined && valueDefined)\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\n * 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\n * returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n\n private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined, isDirectlyDeserializableNativeType } from \"./helpers\";\nimport { Constructor, IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\nexport type TypeResolver = (sourceObject: Object, knownTypes: Map) => Function|undefined|null;\n\nfunction defaultTypeResolver(sourceObject: any, knownTypes: Map): Function|undefined {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\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 public options?: OptionsBase;\n\n private _typeResolver: TypeResolver = defaultTypeResolver;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void = logError;\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: TypeResolver)\n {\n if (typeof typeResolverCallback !== \"function\")\n {\n throw new TypeError(\"'typeResolverCallback' is not a function.\");\n }\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 memberOptions?: OptionsBase,\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 const 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 const classOptions = mergeOptions(this.options, sourceMetadata.options);\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((objMemberMetadata, propKey) =>\n {\n const objMemberValue = sourceObject[propKey];\n const objMemberDebugName = `${nameof(sourceMetadata.classType)}.${propKey}`;\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n\n let revivedValue;\n if (objMemberMetadata.deserializer) {\n revivedValue = objMemberMetadata.deserializer(objMemberValue);\n } else if (objMemberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n objMemberValue,\n {\n selfConstructor: objMemberMetadata.ctor,\n elementConstructor: objMemberMetadata.elementType,\n keyConstructor: objMemberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n objMemberDebugName,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${objMemberDebugName} there is`\n + ` no constructor nor deserialization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue)\n || (this.retrievePreserveNull(objMemberOptions) && revivedValue === null)\n ) {\n sourceObjectWithDeserializedProperties[objMemberMetadata.key] = revivedValue;\n }\n else if (objMemberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${objMemberDebugName}'.`));\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 // check for member first\n if (typeof (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n // check for static\n else 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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ) {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null)\n {\n return null;\n }\n else if (!isValueDefined(sourceObject))\n {\n return;\n }\n else if (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 || expectedSelfType === Float64Array)\n {\n // Deserialize Float Array from number[].\n return this._convertAsFloatArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\n }\n else if (\n expectedSelfType === Uint8Array\n || expectedSelfType === Uint8ClampedArray\n || expectedSelfType === Uint16Array\n || expectedSelfType === Uint32Array\n ) {\n // Deserialize Uint array from number[].\n return this._convertAsUintArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\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 (Array.isArray(sourceObject))\n return this.convertAsArray(sourceObject, typeInfo, memberName, memberOptions);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsSet(sourceObject, typeInfo, memberName, memberOptions);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsMap(sourceObject, typeInfo, memberName, memberOptions);\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, memberOptions);\n }\n }\n\n public convertAsArray(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\n if (!(Array.isArray(sourceObject)))\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, `${memberName}[]`, memberOptions);\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Set {\n if (!(Array.isArray(sourceObject)))\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(\n element,\n elementTypeInfo,\n `${memberName}[${i}]`,\n memberOptions,\n ));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry\n // does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Map {\n if (!(Array.isArray(sourceObject)))\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, memberName, memberOptions);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(\n key,\n this.convertSingleValue(\n element.value,\n valueTypeInfo,\n `${memberName}[${key}]`,\n memberOptions,\n ),\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 _convertAsFloatArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject);\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _convertAsUintArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject.map(value => ~~value));\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string,\n ): never {\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: string)\n {\n const expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n const 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 _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 private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { Constructor } from \"./typedjson/types\";\nimport { Serializer, TypeHintEmitter } from \"./typedjson/serializer\";\nimport { Deserializer, TypeResolver } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\nimport { extractOptionBase, OptionsBase } from \"./typedjson/options-base\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\nexport { TypeResolver, TypeHintEmitter };\n\nexport interface ITypedJSONSettings extends OptionsBase\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?: TypeResolver;\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?: TypeHintEmitter;\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 ): Object[]|undefined {\n return new TypedJSON(elementType, settings).toPlainSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): { key: any, value: any }[]|undefined {\n return new TypedJSON(valueCtor, settings).toPlainMap(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 const options = extractOptionBase(settings);\n this.serializer.options = options;\n this.deserializer.options = options;\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(\n 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\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\nexport type InitializerCallback = (sourceObject: T, rawSourceObject: T) => T;\n\nexport interface IJsonObjectOptionsBase extends OptionsBase\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 of a static or instance method to call before the serialization\n * of the typed object is started.\n */\n beforeSerialization?: 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 * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer: InitializerCallback;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer?: InitializerCallback;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional\n * 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 objectMetadata.beforeSerializationMethodName = options.beforeSerialization;\n \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 const optionsBase = extractOptionBase(options);\n if (optionsBase)\n {\n objectMetadata.options = optionsBase;\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, MISSING_REFLECT_CONF_MSG,\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\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,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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 { isReflectMetadataSupported, logError, MISSING_REFLECT_CONF_MSG, nameof } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions extends OptionsBase\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 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 (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n logError(`${decoratorName}: property is not a Set. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, TypeResolver, TypeHintEmitter } 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 298b604..58e1c93 100644 --- a/js/typedjson.min.js +++ b/js/typedjson.min.js @@ -1,3 +1,3 @@ // [typedjson] Version: 1.5.0 - 2019-10-29 - !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__",u='Are you sure, that you have both "experimentalDecorators" and "emitDecoratorMetadata" in your tsconfig.json?';function a(e){return!!~[Date,Number,String,Boolean].indexOf(e)}function c(e){return!!~[Float32Array,Float64Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array].indexOf(e)}function l(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 d(e,r){return e===r||e.prototype instanceof r}function p(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 isDirectlyDeserializableNativeType(type: Function): boolean\n{\n return !!(~[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 }\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 return \"undefined\";\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { OptionsBase } from \"./options-base\";\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 options?: OptionsBase;\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 options?: OptionsBase;\n\n public onDeserializedMethodName?: string;\n\n public beforeSerializationMethodName?: 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 // clear metadata of undefined properties to save memory\n (Object.keys(metadata) as [keyof JsonMemberMetadata])\n .forEach((key) => (metadata[key] === undefined) && delete metadata[key]);\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","/**\n * This options cascade through the annotations. Options set\n * in the more specific place override the previous option.\n * Ex. @jsonMember overrides TypedJson options.\n */\n\nexport interface OptionsBase {\n /**\n * Whether to preserve null in the JSON output. When false it\n * will not emit nor store the property if its value is null.\n * Default: false.\n */\n preserveNull?: boolean;\n}\n\nconst kAllOptions: (keyof OptionsBase)[] = [\n 'preserveNull',\n];\n\nexport function extractOptionBase(from: any): OptionsBase|undefined {\n const options = Object.keys(from)\n .filter(key => (kAllOptions as string[]).includes(key))\n .reduce((obj, key) => {\n obj[key] = from[key];\n return obj;\n }, {} as any);\n return Object.keys(options).length > 0 ? options : undefined;\n}\n\nexport function getDefaultOptionOf(key: K): Required[K] {\n switch (key) {\n case \"preserveNull\":\n return false;\n }\n // never reached\n return null as any;\n}\n\nexport function getOptionValue(\n key: K,\n options?: OptionsBase,\n): Required[K] {\n if (options && options[key] != null) return options[key]!;\n return getDefaultOptionOf(key);\n}\n\nexport function mergeOptions(\n existing?: OptionsBase,\n moreSpecific?: OptionsBase,\n): OptionsBase|undefined {\n return !moreSpecific\n ? existing\n : Object.assign(\n {},\n existing,\n moreSpecific,\n );\n}\n","import {\n isDirectlySerializableNativeType,\n isInstanceOf,\n isTypeTypedArray,\n isValueDefined,\n logError,\n nameof,\n} from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\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\nexport type TypeHintEmitter\n = (\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n ) => void;\n\nfunction defaultTypeEmitter(\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n) {\n // By default, we put a \"__type\" property on the output object if the actual object is not the\n // same as the expected one, so that deserialization will know what to deserialize into (given\n // the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n targetObject.__type = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n }\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class\n * instances, and so on) to an untyped javascript object (also called \"simple javascript object\"),\n * 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\n * 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 public options?: OptionsBase;\n private _typeHintEmitter: TypeHintEmitter = defaultTypeEmitter;\n private _errorHandler: (error: Error) => void = logError;\n\n public setTypeHintEmitter(typeEmitterCallback: TypeHintEmitter)\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName: string = \"object\",\n memberOptions?: OptionsBase,\n ): any {\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null) return null;\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(\n `Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`),\n );\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, memberOptions);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName, memberOptions);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName, memberOptions);\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, memberOptions);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple\n * javascript object for serialization.\n */\n public convertAsObject(\n sourceObject: IndexedObject,\n typeInfo: IScopeTypeInfo,\n memberName?: string,\n memberOptions?: OptionsBase,\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\n if (sourceTypeMetadata.beforeSerializationMethodName) {\n // check for member first\n if (typeof (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n // check for static\n else if (typeof (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n else \n {\n this._errorHandler(new TypeError(\n `beforeSerialization callback '${nameof(sourceTypeMetadata.classType)}.${sourceTypeMetadata.beforeSerializationMethodName}' is not a method.`\n ));\n }\n }\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),\n // and perform recursive conversion on each of them. The converted objects are put on the 'targetObject',\n // which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n const classOptions = mergeOptions(this.options, sourceMeta.options);\n\n sourceMeta.dataMembers.forEach((objMemberMetadata) =>\n {\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n let serialized;\n if (objMemberMetadata.serializer) {\n serialized = objMemberMetadata.serializer(sourceObject[objMemberMetadata.key]);\n } else if (objMemberMetadata.ctor) {\n serialized = this.convertSingleValue(\n sourceObject[objMemberMetadata.key],\n {\n selfType: objMemberMetadata.ctor,\n elementTypes: objMemberMetadata.elementType,\n keyType: objMemberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${objMemberMetadata.key}`,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${objMemberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n\n if (isValueDefined(serialized)\n || (this.retrievePreserveNull(objMemberOptions) && serialized === null)\n ) {\n targetObject[objMemberMetadata.name] = serialized;\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 * @param memberOptions If converted as a member, the member options.\n */\n public convertAsArray(\n sourceObject: any[],\n expectedElementType: Function[],\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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\n // value emitted during serialization. This is so that invalid element types don't unexpectedly\n // 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 (!(this.retrievePreserveNull(memberOptions) && element === null)\n && !isInstanceOf(element, expectedElementType[0])\n ) {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = element && nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]:` +\n ` expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n // For multidimensional arrays.\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [],\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(\n element => this.convertSingleValue(\n element, typeInfoForElements, memberName, memberOptions\n ),\n );\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array\n * of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements\n * (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n * @returns\n */\n public convertAsSet(\n sourceObject: Set,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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.\n // (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName, memberOptions);\n\n // Add to output if the source element was undefined, OR the converted element is defined.\n // This will add intentionally undefined values to output, but not values that became undefined\n // 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\n * of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n */\n public convertAsMap(\n sourceObject: Map,\n expectedKeyType: Function,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Array<{ key: any, value: any }> {\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 const resultArray: Array<{ key: any, value: any }> = [];\n const preserveNull = this.retrievePreserveNull(memberOptions);\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, memberOptions),\n value: this.convertSingleValue(value, elementTypeInfo, memberName, memberOptions),\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n const keyDefined = isValueDefined(resultKeyValuePairObj.key);\n const valueDefined = isValueDefined(resultKeyValuePairObj.value)\n || (resultKeyValuePairObj.value === null && preserveNull);\n if (keyDefined && valueDefined)\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\n * 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\n * returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n\n private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined, isDirectlyDeserializableNativeType } from \"./helpers\";\nimport { Constructor, IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\nexport type TypeResolver = (sourceObject: Object, knownTypes: Map) => Function|undefined|null;\n\nfunction defaultTypeResolver(sourceObject: any, knownTypes: Map): Function|undefined {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\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 public options?: OptionsBase;\n\n private _typeResolver: TypeResolver = defaultTypeResolver;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void = logError;\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: TypeResolver)\n {\n if (typeof typeResolverCallback !== \"function\")\n {\n throw new TypeError(\"'typeResolverCallback' is not a function.\");\n }\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 memberOptions?: OptionsBase,\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 const 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 const classOptions = mergeOptions(this.options, sourceMetadata.options);\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((objMemberMetadata, propKey) =>\n {\n const objMemberValue = sourceObject[propKey];\n const objMemberDebugName = `${nameof(sourceMetadata.classType)}.${propKey}`;\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n\n let revivedValue;\n if (objMemberMetadata.deserializer) {\n revivedValue = objMemberMetadata.deserializer(objMemberValue);\n } else if (objMemberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n objMemberValue,\n {\n selfConstructor: objMemberMetadata.ctor,\n elementConstructor: objMemberMetadata.elementType,\n keyConstructor: objMemberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n objMemberDebugName,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${objMemberDebugName} there is`\n + ` no constructor nor deserialization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue)\n || (this.retrievePreserveNull(objMemberOptions) && revivedValue === null)\n ) {\n sourceObjectWithDeserializedProperties[objMemberMetadata.key] = revivedValue;\n }\n else if (objMemberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${objMemberDebugName}'.`));\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 // check for member first\n if (typeof (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n // check for static\n else 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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ) {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null)\n {\n return null;\n }\n else if (!isValueDefined(sourceObject))\n {\n return;\n }\n else if (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 || expectedSelfType === Float64Array)\n {\n // Deserialize Float Array from number[].\n return this._convertAsFloatArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\n }\n else if (\n expectedSelfType === Uint8Array\n || expectedSelfType === Uint8ClampedArray\n || expectedSelfType === Uint16Array\n || expectedSelfType === Uint32Array\n ) {\n // Deserialize Uint array from number[].\n return this._convertAsUintArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\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 (Array.isArray(sourceObject))\n return this.convertAsArray(sourceObject, typeInfo, memberName, memberOptions);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsSet(sourceObject, typeInfo, memberName, memberOptions);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsMap(sourceObject, typeInfo, memberName, memberOptions);\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, memberOptions);\n }\n }\n\n public convertAsArray(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\n if (!(Array.isArray(sourceObject)))\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, `${memberName}[]`, memberOptions);\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Set {\n if (!(Array.isArray(sourceObject)))\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(\n element,\n elementTypeInfo,\n `${memberName}[${i}]`,\n memberOptions,\n ));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry\n // does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Map {\n if (!(Array.isArray(sourceObject)))\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, memberName, memberOptions);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(\n key,\n this.convertSingleValue(\n element.value,\n valueTypeInfo,\n `${memberName}[${key}]`,\n memberOptions,\n ),\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 _convertAsFloatArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject);\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _convertAsUintArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject.map(value => ~~value));\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string,\n ): never {\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: string)\n {\n const expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n const 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 _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 private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { Constructor } from \"./typedjson/types\";\nimport { Serializer, TypeHintEmitter } from \"./typedjson/serializer\";\nimport { Deserializer, TypeResolver } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\nimport { extractOptionBase, OptionsBase } from \"./typedjson/options-base\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\nexport { TypeResolver, TypeHintEmitter };\n\nexport interface ITypedJSONSettings extends OptionsBase\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?: TypeResolver;\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?: TypeHintEmitter;\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 ): Object[]|undefined {\n return new TypedJSON(elementType, settings).toPlainSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): { key: any, value: any }[]|undefined {\n return new TypedJSON(valueCtor, settings).toPlainMap(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 const options = extractOptionBase(settings);\n this.serializer.options = options;\n this.deserializer.options = options;\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(\n 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\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\nexport type InitializerCallback = (sourceObject: T, rawSourceObject: T) => T;\n\nexport interface IJsonObjectOptionsBase extends OptionsBase\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 of a static or instance method to call before the serialization\n * of the typed object is started.\n */\n beforeSerialization?: 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 * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer: InitializerCallback;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer?: InitializerCallback;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional\n * 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 objectMetadata.beforeSerializationMethodName = options.beforeSerialization;\n \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 const optionsBase = extractOptionBase(options);\n if (optionsBase)\n {\n objectMetadata.options = optionsBase;\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, MISSING_REFLECT_CONF_MSG,\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\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,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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 { isReflectMetadataSupported, logError, MISSING_REFLECT_CONF_MSG, nameof } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions extends OptionsBase\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 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 (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n logError(`${decoratorName}: property is not a Set. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, TypeResolver, TypeHintEmitter } 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 +{"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/options-base.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","MISSING_REFLECT_CONF_MSG","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","keys","undefined","kAllOptions","extractOptionBase","from","options","filter","reduce","obj","getOptionValue","getDefaultOptionOf","mergeOptions","existing","moreSpecific","assign","defaultTypeEmitter","targetObject","sourceObject","expectedSourceType","sourceTypeMetadata","__type","serializer_Serializer","Serializer","_typeHintEmitter","_errorHandler","setTypeHintEmitter","typeEmitterCallback","TypeError","setErrorHandler","errorHandlerCallback","convertSingleValue","typeInfo","memberName","memberOptions","retrievePreserveNull","selfType","convertAsArrayBuffer","convertAsDataView","Array","convertAsArray","elementTypes","convertAsSet","convertAsMap","convertAsTypedArray","convertAsObject","expectedName","actualName","_this","beforeSerializationMethodName","sourceMeta_1","classOptions_1","objMemberMetadata","serialized","objMemberOptions","serializer","__assign","expectedElementType","element","expectedTypeName","actualTypeName","typeInfoForElements","slice","map","elementTypeInfo","resultArray","resultElement","push","expectedKeyType","keyTypeInfo","preserveNull","resultKeyValuePairObj","keyDefined","valueDefined","buffer","charCode","fromCharCode","join","dataView","defaultTypeResolver","deserializer_Deserializer","Deserializer","_typeResolver","setNameResolver","nameResolverCallback","_nameResolver","setTypeResolver","typeResolverCallback","sourceObjectTypeInfo","objectName","expectedSelfType","selfConstructor","sourceObjectMetadata","knownTypeConstructors","_mergeKnownTypes","_createKnownTypesMap","typeFromTypeHint","sourceMetadata_1","sourceObjectWithDeserializedProperties_1","revivedValue","objMemberValue","objMemberDebugName","elementConstructor","keyConstructor","isRequired","initializerCallback","e","_instantiateType","onDeserializedMethodName","targetObject_1","sourceKey","srcTypeNameForDebug","_makeTypeErrorMessage","_throwTypeMismatchError","_convertAsFloatArray","_convertAsUintArray","_stringToArrayBuffer","_stringToDataView","isArray","resultSet","valueTypeInfo","resultMap","arrayType","every","elem","isNaN","targetType","actualSourceType","actualType","knownTypeMaps","result","knowTypes","knownTypeMeta","name_1","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","toPlainMap","keyCtor","valueCtor","stringify","stringifyAsArray","stringifyAsSet","stringifyAsMap","setGlobalConfig","parser_assign","replacer","typeResolver","typeHintEmitter","knownType","ktc","knownTypeCtor","fill","_mapKnownTypes","elementConstructorArray","constructors","jsonObject","optionsOrTarget","decorator","target","memberMetadata","onDeserialized","beforeSerialization","initializer","optionsBase","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,GAAA,EAGAT,EAAAD,QA0DA,OArDAO,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAf,EAAAgB,EAAAC,GACAV,EAAAW,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,EAAA,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AapB,EAAOhR,UAAUqS,OACvC,MAAM,IAAIC,MAAStB,EAAOrS,KAAI,gCAElCqS,EAAOhR,UAAUqS,OAAS,WACtB,OAAO/D,EAAUiB,YAAYvR,KAAMc,OAAOyT,eAAevU,MAAMsF,cC3CvEpF,EAAAQ,EAAA8T,EAAA,8BAAAlE,IAAApQ,EAAAQ,EAAA8T,EAAA,+BAAA3B,IAAA3S,EAAAQ,EAAA8T,EAAA,+BAAAjB,IAAArT,EAAAQ,EAAA8T,EAAA,oCAAAX,IAAA3T,EAAAQ,EAAA8T,EAAA,kCAAAT,IAAA7T,EAAAQ,EAAA8T,EAAA,kCAAAR,IAAA9T,EAAAQ,EAAA8T,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 const MISSING_REFLECT_CONF_MSG = 'Are you sure, that you have both \"experimentalDecorators\"' +\n ' and \"emitDecoratorMetadata\" in your tsconfig.json?';\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 isDirectlyDeserializableNativeType(type: Function): boolean\n{\n return !!(~[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 }\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 return \"undefined\";\n}\n","import { nameof, logError, METADATA_FIELD_KEY, isDirectlySerializableNativeType, isTypeTypedArray } from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { OptionsBase } from \"./options-base\";\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 options?: OptionsBase;\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 options?: OptionsBase;\n\n public onDeserializedMethodName?: string;\n\n public beforeSerializationMethodName?: 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 // clear metadata of undefined properties to save memory\n (Object.keys(metadata) as [keyof JsonMemberMetadata])\n .forEach((key) => (metadata[key] === undefined) && delete metadata[key]);\n objectMetadata.dataMembers.set(metadata.name, metadata);\n}\n","/**\n * This options cascade through the annotations. Options set\n * in the more specific place override the previous option.\n * Ex. @jsonMember overrides TypedJson options.\n */\nexport interface OptionsBase {\n /**\n * Whether to preserve null in the JSON output. When false it\n * will not emit nor store the property if its value is null.\n * Default: false.\n */\n preserveNull?: boolean;\n}\n\nconst kAllOptions: (keyof OptionsBase)[] = [\n 'preserveNull',\n];\n\nexport function extractOptionBase(from: {[key: string]: any} & OptionsBase): OptionsBase|undefined {\n const options = Object.keys(from)\n .filter(key => (kAllOptions as string[]).indexOf(key) > -1)\n .reduce((obj, key) => {\n obj[key] = from[key];\n return obj;\n }, {} as any);\n return Object.keys(options).length > 0 ? options : undefined;\n}\n\nexport function getDefaultOptionOf(key: K): Required[K] {\n switch (key) {\n case \"preserveNull\":\n return false;\n }\n // never reached\n return null as any;\n}\n\nexport function getOptionValue(\n key: K,\n options?: OptionsBase,\n): Required[K] {\n if (options && options[key] != null) return options[key]!;\n return getDefaultOptionOf(key);\n}\n\nexport function mergeOptions(\n existing?: OptionsBase,\n moreSpecific?: OptionsBase,\n): OptionsBase|undefined {\n return !moreSpecific\n ? existing\n : Object.assign(\n {},\n existing,\n moreSpecific,\n );\n}\n","import {\n isDirectlySerializableNativeType,\n isInstanceOf,\n isTypeTypedArray,\n isValueDefined,\n logError,\n nameof,\n} from \"./helpers\";\nimport { IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\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\nexport type TypeHintEmitter\n = (\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n ) => void;\n\nfunction defaultTypeEmitter(\n targetObject: IndexedObject,\n sourceObject: IndexedObject,\n expectedSourceType: Function,\n sourceTypeMetadata?: JsonObjectMetadata,\n) {\n // By default, we put a \"__type\" property on the output object if the actual object is not the\n // same as the expected one, so that deserialization will know what to deserialize into (given\n // the required known-types are defined, and the object is a valid subtype of the expected type).\n if (sourceObject.constructor !== expectedSourceType)\n {\n targetObject.__type = sourceTypeMetadata && sourceTypeMetadata.name\n ? sourceTypeMetadata.name\n : nameof(sourceObject.constructor);\n }\n}\n\n/**\n * Utility class, converts a typed object tree (i.e. a tree of class instances, arrays of class\n * instances, and so on) to an untyped javascript object (also called \"simple javascript object\"),\n * 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\n * 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 public options?: OptionsBase;\n private _typeHintEmitter: TypeHintEmitter = defaultTypeEmitter;\n private _errorHandler: (error: Error) => void = logError;\n\n public setTypeHintEmitter(typeEmitterCallback: TypeHintEmitter)\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName: string = \"object\",\n memberOptions?: OptionsBase,\n ): any {\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null) return null;\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(\n `Could not serialize '${memberName}': expected '${expectedName}', got '${actualName}'.`),\n );\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, memberOptions);\n }\n else if (isSetTypeInfo(typeInfo))\n {\n return this.convertAsSet(sourceObject, typeInfo.elementTypes[0], memberName, memberOptions);\n }\n else if (isMapTypeInfo(typeInfo))\n {\n return this.convertAsMap(sourceObject, typeInfo.keyType, typeInfo.elementTypes[0], memberName, memberOptions);\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, memberOptions);\n }\n }\n\n /**\n * Performs the conversion of a typed object (usually a class instance) to a simple\n * javascript object for serialization.\n */\n public convertAsObject(\n sourceObject: IndexedObject,\n typeInfo: IScopeTypeInfo,\n memberName?: string,\n memberOptions?: OptionsBase,\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\n if (sourceTypeMetadata.beforeSerializationMethodName) {\n // check for member first\n if (typeof (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n // check for static\n else if (typeof (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName] === \"function\")\n {\n (sourceObject.constructor as any)[sourceTypeMetadata.beforeSerializationMethodName]();\n }\n else \n {\n this._errorHandler(new TypeError(\n `beforeSerialization callback '${nameof(sourceTypeMetadata.classType)}.${sourceTypeMetadata.beforeSerializationMethodName}' is not a method.`\n ));\n }\n }\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),\n // and perform recursive conversion on each of them. The converted objects are put on the 'targetObject',\n // which is what will be put into 'JSON.stringify' finally.\n targetObject = {};\n\n const classOptions = mergeOptions(this.options, sourceMeta.options);\n\n sourceMeta.dataMembers.forEach((objMemberMetadata) =>\n {\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n let serialized;\n if (objMemberMetadata.serializer) {\n serialized = objMemberMetadata.serializer(sourceObject[objMemberMetadata.key]);\n } else if (objMemberMetadata.ctor) {\n serialized = this.convertSingleValue(\n sourceObject[objMemberMetadata.key],\n {\n selfType: objMemberMetadata.ctor,\n elementTypes: objMemberMetadata.elementType,\n keyType: objMemberMetadata.keyType,\n },\n `${nameof(sourceMeta.classType)}.${objMemberMetadata.key}`,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Could not serialize ${objMemberMetadata.name}, there is`\n + ` no constructor nor serialization function to use.`,\n );\n }\n\n if (isValueDefined(serialized)\n || (this.retrievePreserveNull(objMemberOptions) && serialized === null)\n ) {\n targetObject[objMemberMetadata.name] = serialized;\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 * @param memberOptions If converted as a member, the member options.\n */\n public convertAsArray(\n sourceObject: any[],\n expectedElementType: Function[],\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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\n // value emitted during serialization. This is so that invalid element types don't unexpectedly\n // 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 (!(this.retrievePreserveNull(memberOptions) && element === null)\n && !isInstanceOf(element, expectedElementType[0])\n ) {\n const expectedTypeName = nameof(expectedElementType[0]);\n const actualTypeName = element && nameof(element.constructor);\n throw new TypeError(`Could not serialize ${memberName}[${i}]:` +\n ` expected '${expectedTypeName}', got '${actualTypeName}'.`);\n }\n });\n\n const typeInfoForElements: IScopeTypeInfo = {\n selfType: expectedElementType[0],\n // For multidimensional arrays.\n elementTypes: expectedElementType.length > 1 ? expectedElementType.slice(1) : [],\n };\n\n if (memberName)\n {\n // Just for debugging purposes.\n memberName += \"[]\";\n }\n\n return sourceObject.map(\n element => this.convertSingleValue(\n element, typeInfoForElements, memberName, memberOptions\n ),\n );\n }\n\n /**\n * Performs the conversion of a set of typed objects (or primitive values) into an array\n * of simple javascript objects.\n *\n * @param sourceObject\n * @param expectedElementType The constructor of the expected Set elements\n * (e.g. `Number` for `Set`, or `MyClass` for `Set`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n * @returns\n */\n public convertAsSet(\n sourceObject: Set,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\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.\n // (TODO: clarification needed)\n sourceObject.forEach(element =>\n {\n let resultElement = this.convertSingleValue(element, elementTypeInfo, memberName, memberOptions);\n\n // Add to output if the source element was undefined, OR the converted element is defined.\n // This will add intentionally undefined values to output, but not values that became undefined\n // 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\n * of simple javascript objects with `key` and `value` properties.\n *\n * @param sourceObject\n * @param expectedKeyType The constructor of the expected Map keys\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param expectedElementType The constructor of the expected Map values\n * (e.g. `Number` for `Map`, or `MyClass` for `Map`).\n * @param memberName Name of the object being serialized, used for debugging purposes.\n * @param memberOptions If converted as a member, the member options.\n */\n public convertAsMap(\n sourceObject: Map,\n expectedKeyType: Function,\n expectedElementType: Function,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Array<{ key: any, value: any }> {\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 const resultArray: Array<{ key: any, value: any }> = [];\n const preserveNull = this.retrievePreserveNull(memberOptions);\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, memberOptions),\n value: this.convertSingleValue(value, elementTypeInfo, memberName, memberOptions),\n };\n\n // We are not going to emit entries with undefined keys OR undefined values.\n const keyDefined = isValueDefined(resultKeyValuePairObj.key);\n const valueDefined = isValueDefined(resultKeyValuePairObj.value)\n || (resultKeyValuePairObj.value === null && preserveNull);\n if (keyDefined && valueDefined)\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\n * 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\n * returning that string.\n */\n public convertAsDataView(dataView: DataView)\n {\n return this.convertAsArrayBuffer(dataView.buffer);\n }\n\n private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { nameof, logError, isSubtypeOf, isValueDefined, isDirectlyDeserializableNativeType } from \"./helpers\";\nimport { Constructor, IndexedObject } from \"./types\";\nimport { JsonObjectMetadata } from \"./metadata\";\nimport { getOptionValue, mergeOptions, OptionsBase } from \"./options-base\";\n\nexport interface IScopeTypeInfo\n{\n selfConstructor: Function;\n elementConstructor?: Function[];\n keyConstructor?: Function;\n knownTypes: Map;\n}\n\nexport type TypeResolver = (sourceObject: Object, knownTypes: Map) => Function|undefined|null;\n\nfunction defaultTypeResolver(sourceObject: any, knownTypes: Map): Function|undefined {\n if (sourceObject.__type) return knownTypes.get(sourceObject.__type);\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 public options?: OptionsBase;\n\n private _typeResolver: TypeResolver = defaultTypeResolver;\n private _nameResolver?: (ctor: Function) => string;\n private _errorHandler: (error: Error) => void = logError;\n\n public setNameResolver(nameResolverCallback: (ctor: Function) => string)\n {\n this._nameResolver = nameResolverCallback;\n }\n\n public setTypeResolver(typeResolverCallback: TypeResolver)\n {\n if (typeof typeResolverCallback !== \"function\")\n {\n throw new TypeError(\"'typeResolverCallback' is not a function.\");\n }\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 memberOptions?: OptionsBase,\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 const 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 const classOptions = mergeOptions(this.options, sourceMetadata.options);\n\n // Deserialize by expected properties.\n sourceMetadata.dataMembers.forEach((objMemberMetadata, propKey) =>\n {\n const objMemberValue = sourceObject[propKey];\n const objMemberDebugName = `${nameof(sourceMetadata.classType)}.${propKey}`;\n const objMemberOptions = mergeOptions(classOptions, objMemberMetadata.options);\n\n let revivedValue;\n if (objMemberMetadata.deserializer) {\n revivedValue = objMemberMetadata.deserializer(objMemberValue);\n } else if (objMemberMetadata.ctor) {\n revivedValue = this.convertSingleValue(\n objMemberValue,\n {\n selfConstructor: objMemberMetadata.ctor,\n elementConstructor: objMemberMetadata.elementType,\n keyConstructor: objMemberMetadata.keyType,\n knownTypes: knownTypeConstructors\n },\n objMemberDebugName,\n objMemberOptions,\n );\n } else {\n throw new TypeError(\n `Cannot deserialize ${objMemberDebugName} there is`\n + ` no constructor nor deserialization function to use.`,\n );\n }\n\n if (isValueDefined(revivedValue)\n || (this.retrievePreserveNull(objMemberOptions) && revivedValue === null)\n ) {\n sourceObjectWithDeserializedProperties[objMemberMetadata.key] = revivedValue;\n }\n else if (objMemberMetadata.isRequired)\n {\n this._errorHandler(new TypeError(`Missing required member '${objMemberDebugName}'.`));\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 // check for member first\n if (typeof (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName] === \"function\")\n {\n (targetObject as any)[sourceObjectMetadata.onDeserializedMethodName]();\n }\n // check for static\n else 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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ) {\n let expectedSelfType = typeInfo.selfConstructor;\n let srcTypeNameForDebug = sourceObject ? nameof(sourceObject.constructor) : \"undefined\";\n\n if (this.retrievePreserveNull(memberOptions) && sourceObject === null)\n {\n return null;\n }\n else if (!isValueDefined(sourceObject))\n {\n return;\n }\n else if (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 || expectedSelfType === Float64Array)\n {\n // Deserialize Float Array from number[].\n return this._convertAsFloatArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\n }\n else if (\n expectedSelfType === Uint8Array\n || expectedSelfType === Uint8ClampedArray\n || expectedSelfType === Uint16Array\n || expectedSelfType === Uint32Array\n ) {\n // Deserialize Uint array from number[].\n return this._convertAsUintArray(\n sourceObject,\n expectedSelfType as any,\n srcTypeNameForDebug,\n memberName,\n );\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 (Array.isArray(sourceObject))\n return this.convertAsArray(sourceObject, typeInfo, memberName, memberOptions);\n else\n throw new TypeError(this._makeTypeErrorMessage(Array, sourceObject.constructor, memberName));\n }\n else if (expectedSelfType === Set)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsSet(sourceObject, typeInfo, memberName, memberOptions);\n else\n this._throwTypeMismatchError(\"Set\", \"Array\", srcTypeNameForDebug, memberName);\n }\n else if (expectedSelfType === Map)\n {\n if (Array.isArray(sourceObject))\n return this.convertAsMap(sourceObject, typeInfo, memberName, memberOptions);\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, memberOptions);\n }\n }\n\n public convertAsArray(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): any[] {\n if (!(Array.isArray(sourceObject)))\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, `${memberName}[]`, memberOptions);\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(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Set {\n if (!(Array.isArray(sourceObject)))\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(\n element,\n elementTypeInfo,\n `${memberName}[${i}]`,\n memberOptions,\n ));\n }\n catch (e)\n {\n // Faulty entries are skipped, because a Set is not ordered, and skipping an entry\n // does not affect others.\n this._errorHandler(e);\n }\n });\n\n return resultSet;\n }\n\n public convertAsMap(\n sourceObject: any,\n typeInfo: IScopeTypeInfo,\n memberName = \"object\",\n memberOptions?: OptionsBase,\n ): Map {\n if (!(Array.isArray(sourceObject)))\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, memberName, memberOptions);\n\n // Undefined/null keys not supported, skip if so.\n if (isValueDefined(key))\n {\n resultMap.set(\n key,\n this.convertSingleValue(\n element.value,\n valueTypeInfo,\n `${memberName}[${key}]`,\n memberOptions,\n ),\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 _convertAsFloatArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject);\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _convertAsUintArray(\n sourceObject: any,\n arrayType: Constructor,\n srcTypeNameForDebug: string,\n memberName: string,\n ): T {\n if (Array.isArray(sourceObject) && sourceObject.every(elem => !isNaN(elem)))\n return new arrayType(sourceObject.map(value => ~~value));\n return this._throwTypeMismatchError(\n arrayType.name,\n \"a numeric source array\",\n srcTypeNameForDebug,\n memberName,\n );\n }\n\n private _throwTypeMismatchError(\n targetType: string,\n expectedSourceType: string,\n actualSourceType: string,\n memberName: string,\n ): never {\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: string)\n {\n const expectedTypeName = (typeof expectedType === \"function\") ? nameof(expectedType) : expectedType;\n const 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 _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 private retrievePreserveNull(memberOptions?: OptionsBase): boolean {\n return getOptionValue('preserveNull', mergeOptions(this.options, memberOptions));\n }\n}\n","import { Constructor } from \"./typedjson/types\";\nimport { Serializer, TypeHintEmitter } from \"./typedjson/serializer\";\nimport { Deserializer, TypeResolver } from \"./typedjson/deserializer\";\nimport { JsonObjectMetadata } from \"./typedjson/metadata\";\nimport { logError, logWarning, nameof, parseToJSObject } from \"./typedjson/helpers\";\nimport { extractOptionBase, OptionsBase } from \"./typedjson/options-base\";\n\nexport type JsonTypes = Object|boolean|string|number|null|undefined;\nexport { TypeResolver, TypeHintEmitter };\n\nexport interface ITypedJSONSettings extends OptionsBase\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?: TypeResolver;\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?: TypeHintEmitter;\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 ): Object[]|undefined {\n return new TypedJSON(elementType, settings).toPlainSet(object);\n }\n\n public static toPlainMap(\n object: Map,\n keyCtor: Constructor,\n valueCtor: Constructor,\n settings?: ITypedJSONSettings,\n ): { key: any, value: any }[]|undefined {\n return new TypedJSON(valueCtor, settings).toPlainMap(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 const options = extractOptionBase(settings);\n this.serializer.options = options;\n this.deserializer.options = options;\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(\n 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\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\nexport type InitializerCallback = (sourceObject: T, rawSourceObject: T) => T;\n\nexport interface IJsonObjectOptionsBase extends OptionsBase\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 of a static or instance method to call before the serialization\n * of the typed object is started.\n */\n beforeSerialization?: 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 * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer: InitializerCallback;\n}\n\nexport interface IJsonObjectOptions extends IJsonObjectOptionsBase\n{\n /**\n * Function to call before deserializing and initializing the object, accepting two arguments:\n * (1) sourceObject, an 'Object' instance with all properties already deserialized, and\n * (2) rawSourceObject, a raw 'Object' instance representation of the current object in\n * the serialized JSON (i.e. without deserialized properties).\n */\n initializer?: InitializerCallback;\n}\n\n/**\n * Marks that a class with a parameterized constructor is serializable using TypedJSON, with additional\n * 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 objectMetadata.beforeSerializationMethodName = options.beforeSerialization;\n \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 const optionsBase = extractOptionBase(options);\n if (optionsBase)\n {\n objectMetadata.options = optionsBase;\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, MISSING_REFLECT_CONF_MSG,\n} from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\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,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonArrayMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Array,\n elementType: createArrayElementType(elementConstructor, dimensions),\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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 { isReflectMetadataSupported, logError, MISSING_REFLECT_CONF_MSG, nameof } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonSetMemberOptions extends OptionsBase\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 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 (isReflectMetadataSupported && Reflect.getMetadata(\"design:type\", target, propKey) !== Set)\n {\n logError(`${decoratorName}: property is not a Set. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Set,\n elementType: [elementConstructor],\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, MISSING_REFLECT_CONF_MSG } from \"./helpers\";\nimport { injectMetadataInformation } from \"./metadata\";\nimport { extractOptionBase, OptionsBase } from \"./options-base\";\n\ndeclare abstract class Reflect\n{\n public static getMetadata(metadataKey: string, target: any, targetKey: string | symbol): any;\n}\n\nexport interface IJsonMapMemberOptions extends OptionsBase\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. ${MISSING_REFLECT_CONF_MSG}`);\n return;\n }\n\n injectMetadataInformation(target, propKey, {\n ctor: Map,\n elementType: [valueConstructor],\n keyType: keyConstructor,\n emitDefaultValue: options.emitDefaultValue,\n isRequired: options.isRequired,\n options: extractOptionBase(options),\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, TypeResolver, TypeHintEmitter } 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/options-base.d.ts b/js/typedjson/options-base.d.ts index 8797c29..159cf53 100644 --- a/js/typedjson/options-base.d.ts +++ b/js/typedjson/options-base.d.ts @@ -11,7 +11,9 @@ export interface OptionsBase { */ preserveNull?: boolean; } -export declare function extractOptionBase(from: any): OptionsBase | undefined; +export declare function extractOptionBase(from: { + [key: string]: any; +} & OptionsBase): OptionsBase | undefined; export declare function getDefaultOptionOf(key: K): Required[K]; export declare function getOptionValue(key: K, options?: OptionsBase): Required[K]; export declare function mergeOptions(existing?: OptionsBase, moreSpecific?: OptionsBase): OptionsBase | undefined; diff --git a/src/typedjson/options-base.ts b/src/typedjson/options-base.ts index 089b043..b0b5b26 100644 --- a/src/typedjson/options-base.ts +++ b/src/typedjson/options-base.ts @@ -3,7 +3,6 @@ * in the more specific place override the previous option. * Ex. @jsonMember overrides TypedJson options. */ - export interface OptionsBase { /** * Whether to preserve null in the JSON output. When false it @@ -17,9 +16,9 @@ const kAllOptions: (keyof OptionsBase)[] = [ 'preserveNull', ]; -export function extractOptionBase(from: any): OptionsBase|undefined { +export function extractOptionBase(from: {[key: string]: any} & OptionsBase): OptionsBase|undefined { const options = Object.keys(from) - .filter(key => (kAllOptions as string[]).includes(key)) + .filter(key => (kAllOptions as string[]).indexOf(key) > -1) .reduce((obj, key) => { obj[key] = from[key]; return obj;