@adyen/api-library
Version:
The Adyen API Library for NodeJS enables you to work with Adyen APIs.
594 lines • 29.2 kB
JavaScript
"use strict";
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("./models"), exports);
const aULocalAccountIdentification_1 = require("./aULocalAccountIdentification");
const additionalBankIdentification_1 = require("./additionalBankIdentification");
const address_1 = require("./address");
const airline_1 = require("./airline");
const amount_1 = require("./amount");
const amountAdjustment_1 = require("./amountAdjustment");
const approveTransfersRequest_1 = require("./approveTransfersRequest");
const bRLocalAccountIdentification_1 = require("./bRLocalAccountIdentification");
const balanceMutation_1 = require("./balanceMutation");
const bankAccountV3_1 = require("./bankAccountV3");
const bankAccountV3AccountIdentification_1 = require("./bankAccountV3AccountIdentification");
const bankCategoryData_1 = require("./bankCategoryData");
const cALocalAccountIdentification_1 = require("./cALocalAccountIdentification");
const cZLocalAccountIdentification_1 = require("./cZLocalAccountIdentification");
const cancelTransfersRequest_1 = require("./cancelTransfersRequest");
const capitalBalance_1 = require("./capitalBalance");
const capitalGrant_1 = require("./capitalGrant");
const capitalGrantInfo_1 = require("./capitalGrantInfo");
const capitalGrants_1 = require("./capitalGrants");
const card_1 = require("./card");
const cardIdentification_1 = require("./cardIdentification");
const confirmationTrackingData_1 = require("./confirmationTrackingData");
const counterparty_1 = require("./counterparty");
const counterpartyInfoV3_1 = require("./counterpartyInfoV3");
const counterpartyV3_1 = require("./counterpartyV3");
const dKLocalAccountIdentification_1 = require("./dKLocalAccountIdentification");
const directDebitInformation_1 = require("./directDebitInformation");
const estimationTrackingData_1 = require("./estimationTrackingData");
const executionDate_1 = require("./executionDate");
const externalReason_1 = require("./externalReason");
const fee_1 = require("./fee");
const findTransfersResponse_1 = require("./findTransfersResponse");
const hKLocalAccountIdentification_1 = require("./hKLocalAccountIdentification");
const hULocalAccountIdentification_1 = require("./hULocalAccountIdentification");
const ibanAccountIdentification_1 = require("./ibanAccountIdentification");
const internalCategoryData_1 = require("./internalCategoryData");
const internalReviewTrackingData_1 = require("./internalReviewTrackingData");
const invalidField_1 = require("./invalidField");
const issuedCard_1 = require("./issuedCard");
const issuingTransactionData_1 = require("./issuingTransactionData");
const leg_1 = require("./leg");
const link_1 = require("./link");
const links_1 = require("./links");
const lodging_1 = require("./lodging");
const merchantData_1 = require("./merchantData");
const merchantPurchaseData_1 = require("./merchantPurchaseData");
const modification_1 = require("./modification");
const nOLocalAccountIdentification_1 = require("./nOLocalAccountIdentification");
const nZLocalAccountIdentification_1 = require("./nZLocalAccountIdentification");
const nameLocation_1 = require("./nameLocation");
const numberAndBicAccountIdentification_1 = require("./numberAndBicAccountIdentification");
const pLLocalAccountIdentification_1 = require("./pLLocalAccountIdentification");
const partyIdentification_1 = require("./partyIdentification");
const paymentInstrument_1 = require("./paymentInstrument");
const platformPayment_1 = require("./platformPayment");
const relayedAuthorisationData_1 = require("./relayedAuthorisationData");
const repayment_1 = require("./repayment");
const repaymentTerm_1 = require("./repaymentTerm");
const resourceReference_1 = require("./resourceReference");
const restServiceError_1 = require("./restServiceError");
const returnTransferRequest_1 = require("./returnTransferRequest");
const returnTransferResponse_1 = require("./returnTransferResponse");
const routingDetails_1 = require("./routingDetails");
const sELocalAccountIdentification_1 = require("./sELocalAccountIdentification");
const sGLocalAccountIdentification_1 = require("./sGLocalAccountIdentification");
const serviceError_1 = require("./serviceError");
const threeDSecure_1 = require("./threeDSecure");
const thresholdRepayment_1 = require("./thresholdRepayment");
const transaction_1 = require("./transaction");
const transactionEventViolation_1 = require("./transactionEventViolation");
const transactionRuleReference_1 = require("./transactionRuleReference");
const transactionRuleSource_1 = require("./transactionRuleSource");
const transactionRulesResult_1 = require("./transactionRulesResult");
const transactionSearchResponse_1 = require("./transactionSearchResponse");
const transfer_1 = require("./transfer");
const transferCategoryData_1 = require("./transferCategoryData");
const transferData_1 = require("./transferData");
const transferDataTracking_1 = require("./transferDataTracking");
const transferEvent_1 = require("./transferEvent");
const transferEventEventsDataInner_1 = require("./transferEventEventsDataInner");
const transferEventTrackingData_1 = require("./transferEventTrackingData");
const transferInfo_1 = require("./transferInfo");
const transferNotificationCounterParty_1 = require("./transferNotificationCounterParty");
const transferNotificationMerchantData_1 = require("./transferNotificationMerchantData");
const transferNotificationValidationFact_1 = require("./transferNotificationValidationFact");
const transferRequestReview_1 = require("./transferRequestReview");
const transferReview_1 = require("./transferReview");
const transferServiceRestServiceError_1 = require("./transferServiceRestServiceError");
const transferView_1 = require("./transferView");
const uKLocalAccountIdentification_1 = require("./uKLocalAccountIdentification");
const uSLocalAccountIdentification_1 = require("./uSLocalAccountIdentification");
const ultimatePartyIdentification_1 = require("./ultimatePartyIdentification");
/* tslint:disable:no-unused-variable */
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap = new Set([
"AULocalAccountIdentification.TypeEnum",
"AdditionalBankIdentification.TypeEnum",
"AmountAdjustment.AmountAdjustmentTypeEnum",
"BRLocalAccountIdentification.TypeEnum",
"BankAccountV3AccountIdentification.TypeEnum",
"BankAccountV3AccountIdentification.AccountTypeEnum",
"BankCategoryData.PriorityEnum",
"BankCategoryData.TypeEnum",
"CALocalAccountIdentification.AccountTypeEnum",
"CALocalAccountIdentification.TypeEnum",
"CZLocalAccountIdentification.TypeEnum",
"CapitalGrant.StatusEnum",
"ConfirmationTrackingData.StatusEnum",
"ConfirmationTrackingData.TypeEnum",
"DKLocalAccountIdentification.TypeEnum",
"EstimationTrackingData.TypeEnum",
"HKLocalAccountIdentification.TypeEnum",
"HULocalAccountIdentification.TypeEnum",
"IbanAccountIdentification.TypeEnum",
"InternalCategoryData.TypeEnum",
"InternalReviewTrackingData.ReasonEnum",
"InternalReviewTrackingData.StatusEnum",
"InternalReviewTrackingData.TypeEnum",
"IssuedCard.PanEntryModeEnum",
"IssuedCard.ProcessingTypeEnum",
"IssuedCard.TypeEnum",
"IssuingTransactionData.TypeEnum",
"MerchantPurchaseData.TypeEnum",
"Modification.StatusEnum",
"NOLocalAccountIdentification.TypeEnum",
"NZLocalAccountIdentification.TypeEnum",
"NumberAndBicAccountIdentification.TypeEnum",
"PLLocalAccountIdentification.TypeEnum",
"PartyIdentification.TypeEnum",
"PlatformPayment.PlatformPaymentTypeEnum",
"PlatformPayment.TypeEnum",
"ReturnTransferResponse.StatusEnum",
"RoutingDetails.PriorityEnum",
"SELocalAccountIdentification.TypeEnum",
"SGLocalAccountIdentification.TypeEnum",
"Transaction.StatusEnum",
"Transfer.CategoryEnum",
"Transfer.DirectionEnum",
"Transfer.ReasonEnum",
"Transfer.StatusEnum",
"Transfer.TypeEnum",
"TransferCategoryData.PriorityEnum",
"TransferCategoryData.TypeEnum",
"TransferCategoryData.PanEntryModeEnum",
"TransferCategoryData.ProcessingTypeEnum",
"TransferCategoryData.PlatformPaymentTypeEnum",
"TransferData.CategoryEnum",
"TransferData.DirectionEnum",
"TransferData.ReasonEnum",
"TransferData.StatusEnum",
"TransferData.TypeEnum",
"TransferDataTracking.StatusEnum",
"TransferDataTracking.TypeEnum",
"TransferDataTracking.ReasonEnum",
"TransferEvent.ReasonEnum",
"TransferEvent.StatusEnum",
"TransferEvent.TypeEnum",
"TransferEventEventsDataInner.TypeEnum",
"TransferEventTrackingData.StatusEnum",
"TransferEventTrackingData.TypeEnum",
"TransferEventTrackingData.ReasonEnum",
"TransferInfo.CategoryEnum",
"TransferInfo.PrioritiesEnum",
"TransferInfo.PriorityEnum",
"TransferInfo.TypeEnum",
"TransferReview.ScaOnApprovalEnum",
"UKLocalAccountIdentification.TypeEnum",
"USLocalAccountIdentification.AccountTypeEnum",
"USLocalAccountIdentification.TypeEnum",
"UltimatePartyIdentification.TypeEnum",
]);
let typeMap = {
"AULocalAccountIdentification": aULocalAccountIdentification_1.AULocalAccountIdentification,
"AdditionalBankIdentification": additionalBankIdentification_1.AdditionalBankIdentification,
"Address": address_1.Address,
"Airline": airline_1.Airline,
"Amount": amount_1.Amount,
"AmountAdjustment": amountAdjustment_1.AmountAdjustment,
"ApproveTransfersRequest": approveTransfersRequest_1.ApproveTransfersRequest,
"BRLocalAccountIdentification": bRLocalAccountIdentification_1.BRLocalAccountIdentification,
"BalanceMutation": balanceMutation_1.BalanceMutation,
"BankAccountV3": bankAccountV3_1.BankAccountV3,
"BankAccountV3AccountIdentification": bankAccountV3AccountIdentification_1.BankAccountV3AccountIdentificationClass,
"BankCategoryData": bankCategoryData_1.BankCategoryData,
"CALocalAccountIdentification": cALocalAccountIdentification_1.CALocalAccountIdentification,
"CZLocalAccountIdentification": cZLocalAccountIdentification_1.CZLocalAccountIdentification,
"CancelTransfersRequest": cancelTransfersRequest_1.CancelTransfersRequest,
"CapitalBalance": capitalBalance_1.CapitalBalance,
"CapitalGrant": capitalGrant_1.CapitalGrant,
"CapitalGrantInfo": capitalGrantInfo_1.CapitalGrantInfo,
"CapitalGrants": capitalGrants_1.CapitalGrants,
"Card": card_1.Card,
"CardIdentification": cardIdentification_1.CardIdentification,
"ConfirmationTrackingData": confirmationTrackingData_1.ConfirmationTrackingData,
"Counterparty": counterparty_1.Counterparty,
"CounterpartyInfoV3": counterpartyInfoV3_1.CounterpartyInfoV3,
"CounterpartyV3": counterpartyV3_1.CounterpartyV3,
"DKLocalAccountIdentification": dKLocalAccountIdentification_1.DKLocalAccountIdentification,
"DirectDebitInformation": directDebitInformation_1.DirectDebitInformation,
"EstimationTrackingData": estimationTrackingData_1.EstimationTrackingData,
"ExecutionDate": executionDate_1.ExecutionDate,
"ExternalReason": externalReason_1.ExternalReason,
"Fee": fee_1.Fee,
"FindTransfersResponse": findTransfersResponse_1.FindTransfersResponse,
"HKLocalAccountIdentification": hKLocalAccountIdentification_1.HKLocalAccountIdentification,
"HULocalAccountIdentification": hULocalAccountIdentification_1.HULocalAccountIdentification,
"IbanAccountIdentification": ibanAccountIdentification_1.IbanAccountIdentification,
"InternalCategoryData": internalCategoryData_1.InternalCategoryData,
"InternalReviewTrackingData": internalReviewTrackingData_1.InternalReviewTrackingData,
"InvalidField": invalidField_1.InvalidField,
"IssuedCard": issuedCard_1.IssuedCard,
"IssuingTransactionData": issuingTransactionData_1.IssuingTransactionData,
"Leg": leg_1.Leg,
"Link": link_1.Link,
"Links": links_1.Links,
"Lodging": lodging_1.Lodging,
"MerchantData": merchantData_1.MerchantData,
"MerchantPurchaseData": merchantPurchaseData_1.MerchantPurchaseData,
"Modification": modification_1.Modification,
"NOLocalAccountIdentification": nOLocalAccountIdentification_1.NOLocalAccountIdentification,
"NZLocalAccountIdentification": nZLocalAccountIdentification_1.NZLocalAccountIdentification,
"NameLocation": nameLocation_1.NameLocation,
"NumberAndBicAccountIdentification": numberAndBicAccountIdentification_1.NumberAndBicAccountIdentification,
"PLLocalAccountIdentification": pLLocalAccountIdentification_1.PLLocalAccountIdentification,
"PartyIdentification": partyIdentification_1.PartyIdentification,
"PaymentInstrument": paymentInstrument_1.PaymentInstrument,
"PlatformPayment": platformPayment_1.PlatformPayment,
"RelayedAuthorisationData": relayedAuthorisationData_1.RelayedAuthorisationData,
"Repayment": repayment_1.Repayment,
"RepaymentTerm": repaymentTerm_1.RepaymentTerm,
"ResourceReference": resourceReference_1.ResourceReference,
"RestServiceError": restServiceError_1.RestServiceError,
"ReturnTransferRequest": returnTransferRequest_1.ReturnTransferRequest,
"ReturnTransferResponse": returnTransferResponse_1.ReturnTransferResponse,
"RoutingDetails": routingDetails_1.RoutingDetails,
"SELocalAccountIdentification": sELocalAccountIdentification_1.SELocalAccountIdentification,
"SGLocalAccountIdentification": sGLocalAccountIdentification_1.SGLocalAccountIdentification,
"ServiceError": serviceError_1.ServiceError,
"ThreeDSecure": threeDSecure_1.ThreeDSecure,
"ThresholdRepayment": thresholdRepayment_1.ThresholdRepayment,
"Transaction": transaction_1.Transaction,
"TransactionEventViolation": transactionEventViolation_1.TransactionEventViolation,
"TransactionRuleReference": transactionRuleReference_1.TransactionRuleReference,
"TransactionRuleSource": transactionRuleSource_1.TransactionRuleSource,
"TransactionRulesResult": transactionRulesResult_1.TransactionRulesResult,
"TransactionSearchResponse": transactionSearchResponse_1.TransactionSearchResponse,
"Transfer": transfer_1.Transfer,
"TransferCategoryData": transferCategoryData_1.TransferCategoryDataClass,
"TransferData": transferData_1.TransferData,
"TransferDataTracking": transferDataTracking_1.TransferDataTrackingClass,
"TransferEvent": transferEvent_1.TransferEvent,
"TransferEventEventsDataInner": transferEventEventsDataInner_1.TransferEventEventsDataInnerClass,
"TransferEventTrackingData": transferEventTrackingData_1.TransferEventTrackingDataClass,
"TransferInfo": transferInfo_1.TransferInfo,
"TransferNotificationCounterParty": transferNotificationCounterParty_1.TransferNotificationCounterParty,
"TransferNotificationMerchantData": transferNotificationMerchantData_1.TransferNotificationMerchantData,
"TransferNotificationValidationFact": transferNotificationValidationFact_1.TransferNotificationValidationFact,
"TransferRequestReview": transferRequestReview_1.TransferRequestReview,
"TransferReview": transferReview_1.TransferReview,
"TransferServiceRestServiceError": transferServiceRestServiceError_1.TransferServiceRestServiceError,
"TransferView": transferView_1.TransferView,
"UKLocalAccountIdentification": uKLocalAccountIdentification_1.UKLocalAccountIdentification,
"USLocalAccountIdentification": uSLocalAccountIdentification_1.USLocalAccountIdentification,
"UltimatePartyIdentification": ultimatePartyIdentification_1.UltimatePartyIdentification,
};
/**
* Every mime-type consists of a type, subtype, and optional parameters.
* The subtype can be composite, including information about the content format.
* For example: `application/json-patch+json`, `application/merge-patch+json`.
*
* This helper transforms a string mime-type into an internal representation.
* This simplifies the implementation of predicates that in turn define common rules for parsing or stringifying
* the payload.
*/
const parseMimeType = (mimeType) => {
const [type = '', subtype = ''] = mimeType.split('/');
return {
type,
subtype,
subtypeTokens: subtype.split('+'),
};
};
// This factory creates a predicate function that checks a string mime-type against defined rules.
const mimeTypePredicateFactory = (predicate) => (mimeType) => predicate(parseMimeType(mimeType));
// Use this factory when you need to define a simple predicate based only on type and, if applicable, subtype.
const mimeTypeSimplePredicateFactory = (type, subtype) => mimeTypePredicateFactory((descriptor) => {
if (descriptor.type !== type)
return false;
if (subtype != null && descriptor.subtype !== subtype)
return false;
return true;
});
// Creating a set of named predicates that will help us determine how to handle different mime-types
const isTextLikeMimeType = mimeTypeSimplePredicateFactory('text');
const isJsonMimeType = mimeTypeSimplePredicateFactory('application', 'json');
const isJsonLikeMimeType = mimeTypePredicateFactory((descriptor) => descriptor.type === 'application' && descriptor.subtypeTokens.some((item) => item === 'json'));
const isOctetStreamMimeType = mimeTypeSimplePredicateFactory('application', 'octet-stream');
const isFormUrlencodedMimeType = mimeTypeSimplePredicateFactory('application', 'x-www-form-urlencoded');
// Defining a list of mime-types in the order of prioritization for handling.
const supportedMimeTypePredicatesWithPriority = [
isJsonMimeType,
isJsonLikeMimeType,
isTextLikeMimeType,
isOctetStreamMimeType,
isFormUrlencodedMimeType,
];
const nullableSuffix = " | null";
const optionalSuffix = " | undefined";
const arrayPrefix = "Array<";
const arraySuffix = ">";
const mapPrefix = "{ [key: string]: ";
const mapSuffix = "; }";
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.has(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];
let mapping = typeMap[expectedType].mapping;
if (mapping != undefined && mapping[discriminatorType]) {
return mapping[discriminatorType]; // use the type given in the discriminator
}
else if (typeMap[discriminatorType]) {
return discriminatorType;
}
else {
return expectedType; // discriminator did not map to a type
}
}
else {
return expectedType; // discriminator was not present (or an empty string)
}
}
}
}
/**
* Serializes a value into a plain JSON-compatible object based on its type.
*
* Supports primitives, arrays, maps, dates, enums, and classes defined in `typeMap`.
* Falls back to raw data if type is unknown or lacks `getAttributeTypeMap()`.
*
* @param data - The value to serialize.
* @param type - The expected type name as a string.
* @param format - Format hint (e.g. "date" or "date-time"). Default is an empty string.
* @returns A JSON-compatible representation of `data`.
*/
static serialize(data, type, format = "") {
if (data == undefined) {
return data;
}
else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
}
else if (type.endsWith(nullableSuffix)) {
let subType = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.serialize(data, subType, format);
}
else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.serialize(data, subType, format);
}
else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData = [];
for (let date of data) {
transformedData.push(ObjectSerializer.serialize(date, subType, format));
}
return transformedData;
}
else if (type.startsWith(mapPrefix)) {
let subType = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.serialize(data[key], subType, format);
}
return transformedData;
}
else if (type === "Date") {
if (format == "date") {
let month = data.getMonth() + 1;
month = month < 10 ? "0" + month.toString() : month.toString();
let day = data.getDate();
day = day < 10 ? "0" + day.toString() : day.toString();
return data.getFullYear() + "-" + month + "-" + day;
}
else {
return data.toISOString();
}
}
else {
if (enumsMap.has(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);
const clazz = typeMap[type];
// Safe check for getAttributeTypeMap
if (typeof clazz.getAttributeTypeMap !== "function") {
return { ...data }; // fallback: shallow copy
}
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
for (let attributeType of attributeTypes) {
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format);
}
return instance;
}
}
/**
* Deserializes a plain JSON-compatible object into a typed instance.
*
* Handles primitives, arrays, maps, dates, enums, and known classes from `typeMap`.
* Uses discriminators when available to resolve polymorphic types.
* Falls back to raw data if the type is unknown or lacks `getAttributeTypeMap()`.
*
* @param data - The raw input to deserialize.
* @param type - The expected type name as a string.
* @param format - Format hint (e.g. "date" or "date-time"). Default is an empty string.
* @returns A deserialized instance or value of `data`.
*/
static deserialize(data, type, format = "") {
// 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.endsWith(nullableSuffix)) {
let subType = type.slice(0, -nullableSuffix.length); // Type | null => Type
return ObjectSerializer.deserialize(data, subType, format);
}
else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length); // Type | undefined => Type
return ObjectSerializer.deserialize(data, subType, format);
}
else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length); // Array<Type> => Type
let transformedData = [];
for (let date of data) {
transformedData.push(ObjectSerializer.deserialize(date, subType, format));
}
return transformedData;
}
else if (type.startsWith(mapPrefix)) {
let subType = type.slice(mapPrefix.length, -mapSuffix.length); // { [key: string]: Type; } => Type
let transformedData = {};
for (let key in data) {
transformedData[key] = ObjectSerializer.deserialize(data[key], subType, format);
}
return transformedData;
}
else if (type === "Date") {
return new Date(data);
}
else {
if (enumsMap.has(type)) { // is Enum
return data;
}
if (!typeMap[type]) { // dont know the type
return data;
}
let instance = new typeMap[type]();
// Safe check for getAttributeTypeMap
if (typeof typeMap[type].getAttributeTypeMap !== "function") {
Object.assign(instance, data); // fallback: shallow copy
return instance;
}
let attributeTypes = typeMap[type].getAttributeTypeMap();
for (let attributeType of attributeTypes) {
let value = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format);
if (value !== undefined) {
instance[attributeType.name] = value;
}
}
return instance;
}
}
/**
* Normalize media type
*
* We currently do not handle any media types attributes, i.e. anything
* after a semicolon. All content is assumed to be UTF-8 compatible.
*/
static normalizeMediaType(mediaType) {
var _a;
if (mediaType === undefined) {
return undefined;
}
return ((_a = mediaType.split(";")[0]) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
}
/**
* From a list of possible media types, choose the one we can handle best.
*
* The order of the given media types does not have any impact on the choice
* made.
*/
static getPreferredMediaType(mediaTypes) {
/** According to OAS 3 we should default to json */
if (mediaTypes.length === 0) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(ObjectSerializer.normalizeMediaType);
for (const predicate of supportedMimeTypePredicatesWithPriority) {
for (const mediaType of normalMediaTypes) {
if (mediaType != null && predicate(mediaType)) {
return mediaType;
}
}
}
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
/**
* Convert data to a string according the given media type
*/
static stringify(data, mediaType) {
if (isTextLikeMimeType(mediaType)) {
return String(data);
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
/**
* Parse data from a string according to the given media type
*/
static parse(rawData, mediaType) {
if (mediaType === undefined) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (isTextLikeMimeType(mediaType)) {
return rawData;
}
if (isJsonLikeMimeType(mediaType)) {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
}
exports.ObjectSerializer = ObjectSerializer;
//# sourceMappingURL=objectSerializer.js.map