@hubspot/api-client
Version:
NodeJS v3 [HubSpot API](https://developers.hubspot.com/docs/api/overview) SDK(Client) files
361 lines • 18.2 kB
JavaScript
;
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/AssociationSpec"), exports);
__exportStar(require("../models/AssociationSpecWithLabel"), exports);
__exportStar(require("../models/BatchInputPublicAssociationMultiArchive"), exports);
__exportStar(require("../models/BatchInputPublicAssociationMultiPost"), exports);
__exportStar(require("../models/BatchInputPublicDefaultAssociationMultiPost"), exports);
__exportStar(require("../models/BatchInputPublicFetchAssociationsBatchRequest"), exports);
__exportStar(require("../models/BatchResponseLabelsBetweenObjectPair"), exports);
__exportStar(require("../models/BatchResponseLabelsBetweenObjectPairWithErrors"), exports);
__exportStar(require("../models/BatchResponsePublicAssociationMultiWithLabel"), exports);
__exportStar(require("../models/BatchResponsePublicAssociationMultiWithLabelWithErrors"), exports);
__exportStar(require("../models/BatchResponsePublicDefaultAssociation"), exports);
__exportStar(require("../models/CollectionResponseMultiAssociatedObjectWithLabelForwardPaging"), exports);
__exportStar(require("../models/DateTime"), exports);
__exportStar(require("../models/ErrorDetail"), exports);
__exportStar(require("../models/ForwardPaging"), exports);
__exportStar(require("../models/LabelsBetweenObjectPair"), exports);
__exportStar(require("../models/ModelError"), exports);
__exportStar(require("../models/MultiAssociatedObjectWithLabel"), exports);
__exportStar(require("../models/NextPage"), exports);
__exportStar(require("../models/Paging"), exports);
__exportStar(require("../models/PreviousPage"), exports);
__exportStar(require("../models/PublicAssociationMultiArchive"), exports);
__exportStar(require("../models/PublicAssociationMultiPost"), exports);
__exportStar(require("../models/PublicAssociationMultiWithLabel"), exports);
__exportStar(require("../models/PublicDefaultAssociation"), exports);
__exportStar(require("../models/PublicDefaultAssociationMultiPost"), exports);
__exportStar(require("../models/PublicFetchAssociationsBatchRequest"), exports);
__exportStar(require("../models/PublicObjectId"), exports);
__exportStar(require("../models/ReportCreationResponse"), exports);
__exportStar(require("../models/StandardError"), exports);
const AssociationSpec_1 = require("../models/AssociationSpec");
const AssociationSpecWithLabel_1 = require("../models/AssociationSpecWithLabel");
const BatchInputPublicAssociationMultiArchive_1 = require("../models/BatchInputPublicAssociationMultiArchive");
const BatchInputPublicAssociationMultiPost_1 = require("../models/BatchInputPublicAssociationMultiPost");
const BatchInputPublicDefaultAssociationMultiPost_1 = require("../models/BatchInputPublicDefaultAssociationMultiPost");
const BatchInputPublicFetchAssociationsBatchRequest_1 = require("../models/BatchInputPublicFetchAssociationsBatchRequest");
const BatchResponseLabelsBetweenObjectPair_1 = require("../models/BatchResponseLabelsBetweenObjectPair");
const BatchResponseLabelsBetweenObjectPairWithErrors_1 = require("../models/BatchResponseLabelsBetweenObjectPairWithErrors");
const BatchResponsePublicAssociationMultiWithLabel_1 = require("../models/BatchResponsePublicAssociationMultiWithLabel");
const BatchResponsePublicAssociationMultiWithLabelWithErrors_1 = require("../models/BatchResponsePublicAssociationMultiWithLabelWithErrors");
const BatchResponsePublicDefaultAssociation_1 = require("../models/BatchResponsePublicDefaultAssociation");
const CollectionResponseMultiAssociatedObjectWithLabelForwardPaging_1 = require("../models/CollectionResponseMultiAssociatedObjectWithLabelForwardPaging");
const DateTime_1 = require("../models/DateTime");
const ErrorDetail_1 = require("../models/ErrorDetail");
const ForwardPaging_1 = require("../models/ForwardPaging");
const LabelsBetweenObjectPair_1 = require("../models/LabelsBetweenObjectPair");
const ModelError_1 = require("../models/ModelError");
const MultiAssociatedObjectWithLabel_1 = require("../models/MultiAssociatedObjectWithLabel");
const NextPage_1 = require("../models/NextPage");
const Paging_1 = require("../models/Paging");
const PreviousPage_1 = require("../models/PreviousPage");
const PublicAssociationMultiArchive_1 = require("../models/PublicAssociationMultiArchive");
const PublicAssociationMultiPost_1 = require("../models/PublicAssociationMultiPost");
const PublicAssociationMultiWithLabel_1 = require("../models/PublicAssociationMultiWithLabel");
const PublicDefaultAssociation_1 = require("../models/PublicDefaultAssociation");
const PublicDefaultAssociationMultiPost_1 = require("../models/PublicDefaultAssociationMultiPost");
const PublicFetchAssociationsBatchRequest_1 = require("../models/PublicFetchAssociationsBatchRequest");
const PublicObjectId_1 = require("../models/PublicObjectId");
const ReportCreationResponse_1 = require("../models/ReportCreationResponse");
const StandardError_1 = require("../models/StandardError");
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap = new Set([
"AssociationSpecAssociationCategoryEnum",
"AssociationSpecWithLabelCategoryEnum",
"BatchResponseLabelsBetweenObjectPairStatusEnum",
"BatchResponseLabelsBetweenObjectPairWithErrorsStatusEnum",
"BatchResponsePublicAssociationMultiWithLabelStatusEnum",
"BatchResponsePublicAssociationMultiWithLabelWithErrorsStatusEnum",
"BatchResponsePublicDefaultAssociationStatusEnum",
]);
let typeMap = {
"AssociationSpec": AssociationSpec_1.AssociationSpec,
"AssociationSpecWithLabel": AssociationSpecWithLabel_1.AssociationSpecWithLabel,
"BatchInputPublicAssociationMultiArchive": BatchInputPublicAssociationMultiArchive_1.BatchInputPublicAssociationMultiArchive,
"BatchInputPublicAssociationMultiPost": BatchInputPublicAssociationMultiPost_1.BatchInputPublicAssociationMultiPost,
"BatchInputPublicDefaultAssociationMultiPost": BatchInputPublicDefaultAssociationMultiPost_1.BatchInputPublicDefaultAssociationMultiPost,
"BatchInputPublicFetchAssociationsBatchRequest": BatchInputPublicFetchAssociationsBatchRequest_1.BatchInputPublicFetchAssociationsBatchRequest,
"BatchResponseLabelsBetweenObjectPair": BatchResponseLabelsBetweenObjectPair_1.BatchResponseLabelsBetweenObjectPair,
"BatchResponseLabelsBetweenObjectPairWithErrors": BatchResponseLabelsBetweenObjectPairWithErrors_1.BatchResponseLabelsBetweenObjectPairWithErrors,
"BatchResponsePublicAssociationMultiWithLabel": BatchResponsePublicAssociationMultiWithLabel_1.BatchResponsePublicAssociationMultiWithLabel,
"BatchResponsePublicAssociationMultiWithLabelWithErrors": BatchResponsePublicAssociationMultiWithLabelWithErrors_1.BatchResponsePublicAssociationMultiWithLabelWithErrors,
"BatchResponsePublicDefaultAssociation": BatchResponsePublicDefaultAssociation_1.BatchResponsePublicDefaultAssociation,
"CollectionResponseMultiAssociatedObjectWithLabelForwardPaging": CollectionResponseMultiAssociatedObjectWithLabelForwardPaging_1.CollectionResponseMultiAssociatedObjectWithLabelForwardPaging,
"DateTime": DateTime_1.DateTime,
"ErrorDetail": ErrorDetail_1.ErrorDetail,
"ForwardPaging": ForwardPaging_1.ForwardPaging,
"LabelsBetweenObjectPair": LabelsBetweenObjectPair_1.LabelsBetweenObjectPair,
"ModelError": ModelError_1.ModelError,
"MultiAssociatedObjectWithLabel": MultiAssociatedObjectWithLabel_1.MultiAssociatedObjectWithLabel,
"NextPage": NextPage_1.NextPage,
"Paging": Paging_1.Paging,
"PreviousPage": PreviousPage_1.PreviousPage,
"PublicAssociationMultiArchive": PublicAssociationMultiArchive_1.PublicAssociationMultiArchive,
"PublicAssociationMultiPost": PublicAssociationMultiPost_1.PublicAssociationMultiPost,
"PublicAssociationMultiWithLabel": PublicAssociationMultiWithLabel_1.PublicAssociationMultiWithLabel,
"PublicDefaultAssociation": PublicDefaultAssociation_1.PublicDefaultAssociation,
"PublicDefaultAssociationMultiPost": PublicDefaultAssociationMultiPost_1.PublicDefaultAssociationMultiPost,
"PublicFetchAssociationsBatchRequest": PublicFetchAssociationsBatchRequest_1.PublicFetchAssociationsBatchRequest,
"PublicObjectId": PublicObjectId_1.PublicObjectId,
"ReportCreationResponse": ReportCreationResponse_1.ReportCreationResponse,
"StandardError": StandardError_1.StandardError,
};
const parseMimeType = (mimeType) => {
const [type = '', subtype = ''] = mimeType.split('/');
return {
type,
subtype,
subtypeTokens: subtype.split('+'),
};
};
const mimeTypePredicateFactory = (predicate) => (mimeType) => predicate(parseMimeType(mimeType));
const mimeTypeSimplePredicateFactory = (type, subtype) => mimeTypePredicateFactory((descriptor) => {
if (descriptor.type !== type)
return false;
if (subtype != null && descriptor.subtype !== subtype)
return false;
return true;
});
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');
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;
}
let discriminatorProperty = typeMap[expectedType].discriminator;
if (discriminatorProperty == null) {
return expectedType;
}
else {
if (data[discriminatorProperty]) {
var discriminatorType = data[discriminatorProperty];
let mapping = typeMap[expectedType].mapping;
if (mapping != undefined && mapping[discriminatorType]) {
return mapping[discriminatorType];
}
else if (typeMap[discriminatorType]) {
return discriminatorType;
}
else {
return expectedType;
}
}
else {
return expectedType;
}
}
}
}
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);
return ObjectSerializer.serialize(data, subType, format);
}
else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length);
return ObjectSerializer.serialize(data, subType, format);
}
else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length);
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);
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]) {
return data;
}
type = this.findCorrectType(data, 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;
}
}
static deserialize(data, type, format) {
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);
return ObjectSerializer.deserialize(data, subType, format);
}
else if (type.endsWith(optionalSuffix)) {
let subType = type.slice(0, -optionalSuffix.length);
return ObjectSerializer.deserialize(data, subType, format);
}
else if (type.startsWith(arrayPrefix)) {
let subType = type.slice(arrayPrefix.length, -arraySuffix.length);
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);
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)) {
return data;
}
if (!typeMap[type]) {
return data;
}
let instance = new typeMap[type]();
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;
}
}
static normalizeMediaType(mediaType) {
var _a;
if (mediaType === undefined) {
return undefined;
}
return ((_a = mediaType.split(";")[0]) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
}
static getPreferredMediaType(mediaTypes) {
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(", "));
}
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.");
}
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