@adyen/api-library
Version:
The Adyen API Library for NodeJS enables you to work with Adyen APIs.
184 lines • 7.61 kB
JavaScript
;
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2021 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectSerializer = void 0;
__exportStar(require("./amount"), exports);
__exportStar(require("./notification"), exports);
__exportStar(require("./notificationItem"), exports);
__exportStar(require("./notificationRequestItem"), exports);
const amount_1 = require("./amount");
const notification_1 = require("./notification");
const notificationItem_1 = require("./notificationItem");
const notificationRequestItem_1 = require("./notificationRequestItem");
/* tslint:disable:no-unused-variable */
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap = {
"NotificationRequestItem.EventCodeEnum": notificationRequestItem_1.NotificationRequestItem.EventCodeEnum,
"NotificationRequestItem.OperationsEnum": notificationRequestItem_1.NotificationRequestItem.OperationsEnum,
"NotificationRequestItem.SuccessEnum": notificationRequestItem_1.NotificationRequestItem.SuccessEnum,
};
let typeMap = {
"Amount": amount_1.Amount,
"Notification": notification_1.Notification,
"NotificationItem": notificationItem_1.NotificationItem,
"NotificationRequestItem": notificationRequestItem_1.NotificationRequestItem,
};
class ObjectSerializer {
static findCorrectType(data, expectedType) {
if (data == undefined) {
return expectedType;
}
else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) {
return expectedType;
}
else if (expectedType === "Date") {
return expectedType;
}
else {
if (enumsMap[expectedType]) {
return expectedType;
}
if (!typeMap[expectedType]) {
return expectedType; // w/e we don't know the type
}
// Check the discriminator
let discriminatorProperty = typeMap[expectedType].discriminator;
if (discriminatorProperty == null) {
return expectedType; // the type does not have a discriminator. use it.
}
else {
if (data[discriminatorProperty]) {
var discriminatorType = data[discriminatorProperty];
if (typeMap[discriminatorType]) {
return discriminatorType; // use the type given in the discriminator
}
else {
return expectedType; // discriminator did not map to a type
}
}
else {
return expectedType; // discriminator was not present (or an empty string)
}
}
}
}
static serialize(data, type) {
if (data == undefined) {
return data;
}
else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
}
else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.serialize(datum, subType));
}
return transformedData;
}
else if (type === "Date") {
return data.toISOString();
}
else {
if (enumsMap[type]) {
return data;
}
if (!typeMap[type]) { // in case we dont know the type
return data;
}
// Get the actual type of this object
type = this.findCorrectType(data, type);
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
for (let index = 0; index < attributeTypes.length; index++) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
}
return instance;
}
}
static deserialize(data, type) {
// polymorphism may change the actual type.
type = ObjectSerializer.findCorrectType(data, type);
if (data == undefined) {
return data;
}
else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
}
else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
for (let index = 0; index < data.length; index++) {
let datum = data[index];
transformedData.push(ObjectSerializer.deserialize(datum, subType));
}
return transformedData;
}
else if (type === "Date") {
return new Date(data);
}
else {
if (enumsMap[type]) { // is Enum
return data;
}
if (!typeMap[type]) { // dont know the type
return data;
}
let instance = new typeMap[type]();
let attributeTypes = typeMap[type].getAttributeTypeMap();
for (let index = 0; index < attributeTypes.length; index++) {
let attributeType = attributeTypes[index];
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
}
return instance;
}
}
}
exports.ObjectSerializer = ObjectSerializer;
//# sourceMappingURL=models.js.map