UNPKG

@methodus/server

Version:

Server components for @methodus workflow

62 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deserialize = void 0; const tslib_1 = require("tslib"); const commons_1 = tslib_1.__importDefault(require("@methodus/framework-decorators/commons")); const primitiveArray = { 'bool': (val) => val === 'true' || val === true, 'date': (val) => new Date(val), 'string': (val) => val, 'object': (val) => { let returnValue = val; if (typeof returnValue === 'string') { try { returnValue = JSON.parse(val); } catch (error) { } } return returnValue; } }; function deserialize(item) { if (item !== undefined && item !== null && item.type) { if (primitiveArray[item.type]) { return primitiveArray[item.type](item.value); } if (item.type && item.type.deserialize) { try { return item.type.deserialize(item.value); } catch (error) { commons_1.default.logger.warn('error deserializing argument, will try other ways', item); } } else if (item.type && item.type.prototype && item.type.prototype.constructor) { return new item.type(returnJson(item.value)); } else if (typeof (item.value) === 'string' && item.type === 'object') { return returnJson(item.value); } else if (item.value === undefined && typeof (item) === 'object') { return item; } } else if (typeof item.value === 'string') { return returnJson(item.value); } else { return item; } return item.value; } exports.deserialize = deserialize; function returnJson(str) { try { return JSON.parse(str); } catch (error) { } return str; } //# sourceMappingURL=deserialize.js.map