@hubspot/api-client
Version:
NodeJS v3 [HubSpot API](https://developers.hubspot.com/docs/api/overview) SDK(Client) files
378 lines • 19.4 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/AssociatedId"), exports);
__exportStar(require("../models/AssociationSpec"), exports);
__exportStar(require("../models/BatchInputSimplePublicObjectBatchInput"), exports);
__exportStar(require("../models/BatchInputSimplePublicObjectBatchInputForCreate"), exports);
__exportStar(require("../models/BatchInputSimplePublicObjectBatchInputUpsert"), exports);
__exportStar(require("../models/BatchInputSimplePublicObjectId"), exports);
__exportStar(require("../models/BatchReadInputSimplePublicObjectId"), exports);
__exportStar(require("../models/BatchResponseSimplePublicObject"), exports);
__exportStar(require("../models/BatchResponseSimplePublicObjectWithErrors"), exports);
__exportStar(require("../models/BatchResponseSimplePublicUpsertObject"), exports);
__exportStar(require("../models/BatchResponseSimplePublicUpsertObjectWithErrors"), exports);
__exportStar(require("../models/CollectionResponseAssociatedId"), exports);
__exportStar(require("../models/CollectionResponseSimplePublicObjectWithAssociationsForwardPaging"), exports);
__exportStar(require("../models/CollectionResponseWithTotalSimplePublicObjectForwardPaging"), exports);
__exportStar(require("../models/ErrorDetail"), exports);
__exportStar(require("../models/Filter"), exports);
__exportStar(require("../models/FilterGroup"), exports);
__exportStar(require("../models/ForwardPaging"), exports);
__exportStar(require("../models/ModelError"), exports);
__exportStar(require("../models/NextPage"), exports);
__exportStar(require("../models/Paging"), exports);
__exportStar(require("../models/PreviousPage"), exports);
__exportStar(require("../models/PublicAssociationsForObject"), exports);
__exportStar(require("../models/PublicObjectId"), exports);
__exportStar(require("../models/PublicObjectSearchRequest"), exports);
__exportStar(require("../models/SimplePublicObject"), exports);
__exportStar(require("../models/SimplePublicObjectBatchInput"), exports);
__exportStar(require("../models/SimplePublicObjectBatchInputForCreate"), exports);
__exportStar(require("../models/SimplePublicObjectBatchInputUpsert"), exports);
__exportStar(require("../models/SimplePublicObjectId"), exports);
__exportStar(require("../models/SimplePublicObjectInput"), exports);
__exportStar(require("../models/SimplePublicObjectInputForCreate"), exports);
__exportStar(require("../models/SimplePublicObjectWithAssociations"), exports);
__exportStar(require("../models/SimplePublicUpsertObject"), exports);
__exportStar(require("../models/StandardError"), exports);
__exportStar(require("../models/ValueWithTimestamp"), exports);
const AssociatedId_1 = require("../models/AssociatedId");
const AssociationSpec_1 = require("../models/AssociationSpec");
const BatchInputSimplePublicObjectBatchInput_1 = require("../models/BatchInputSimplePublicObjectBatchInput");
const BatchInputSimplePublicObjectBatchInputForCreate_1 = require("../models/BatchInputSimplePublicObjectBatchInputForCreate");
const BatchInputSimplePublicObjectBatchInputUpsert_1 = require("../models/BatchInputSimplePublicObjectBatchInputUpsert");
const BatchInputSimplePublicObjectId_1 = require("../models/BatchInputSimplePublicObjectId");
const BatchReadInputSimplePublicObjectId_1 = require("../models/BatchReadInputSimplePublicObjectId");
const BatchResponseSimplePublicObject_1 = require("../models/BatchResponseSimplePublicObject");
const BatchResponseSimplePublicObjectWithErrors_1 = require("../models/BatchResponseSimplePublicObjectWithErrors");
const BatchResponseSimplePublicUpsertObject_1 = require("../models/BatchResponseSimplePublicUpsertObject");
const BatchResponseSimplePublicUpsertObjectWithErrors_1 = require("../models/BatchResponseSimplePublicUpsertObjectWithErrors");
const CollectionResponseAssociatedId_1 = require("../models/CollectionResponseAssociatedId");
const CollectionResponseSimplePublicObjectWithAssociationsForwardPaging_1 = require("../models/CollectionResponseSimplePublicObjectWithAssociationsForwardPaging");
const CollectionResponseWithTotalSimplePublicObjectForwardPaging_1 = require("../models/CollectionResponseWithTotalSimplePublicObjectForwardPaging");
const ErrorDetail_1 = require("../models/ErrorDetail");
const Filter_1 = require("../models/Filter");
const FilterGroup_1 = require("../models/FilterGroup");
const ForwardPaging_1 = require("../models/ForwardPaging");
const ModelError_1 = require("../models/ModelError");
const NextPage_1 = require("../models/NextPage");
const Paging_1 = require("../models/Paging");
const PreviousPage_1 = require("../models/PreviousPage");
const PublicAssociationsForObject_1 = require("../models/PublicAssociationsForObject");
const PublicObjectId_1 = require("../models/PublicObjectId");
const PublicObjectSearchRequest_1 = require("../models/PublicObjectSearchRequest");
const SimplePublicObject_1 = require("../models/SimplePublicObject");
const SimplePublicObjectBatchInput_1 = require("../models/SimplePublicObjectBatchInput");
const SimplePublicObjectBatchInputForCreate_1 = require("../models/SimplePublicObjectBatchInputForCreate");
const SimplePublicObjectBatchInputUpsert_1 = require("../models/SimplePublicObjectBatchInputUpsert");
const SimplePublicObjectId_1 = require("../models/SimplePublicObjectId");
const SimplePublicObjectInput_1 = require("../models/SimplePublicObjectInput");
const SimplePublicObjectInputForCreate_1 = require("../models/SimplePublicObjectInputForCreate");
const SimplePublicObjectWithAssociations_1 = require("../models/SimplePublicObjectWithAssociations");
const SimplePublicUpsertObject_1 = require("../models/SimplePublicUpsertObject");
const StandardError_1 = require("../models/StandardError");
const ValueWithTimestamp_1 = require("../models/ValueWithTimestamp");
let primitives = [
"string",
"boolean",
"double",
"integer",
"long",
"float",
"number",
"any"
];
let enumsMap = new Set([
"AssociationSpecAssociationCategoryEnum",
"BatchResponseSimplePublicObjectStatusEnum",
"BatchResponseSimplePublicObjectWithErrorsStatusEnum",
"BatchResponseSimplePublicUpsertObjectStatusEnum",
"BatchResponseSimplePublicUpsertObjectWithErrorsStatusEnum",
"FilterOperatorEnum",
]);
let typeMap = {
"AssociatedId": AssociatedId_1.AssociatedId,
"AssociationSpec": AssociationSpec_1.AssociationSpec,
"BatchInputSimplePublicObjectBatchInput": BatchInputSimplePublicObjectBatchInput_1.BatchInputSimplePublicObjectBatchInput,
"BatchInputSimplePublicObjectBatchInputForCreate": BatchInputSimplePublicObjectBatchInputForCreate_1.BatchInputSimplePublicObjectBatchInputForCreate,
"BatchInputSimplePublicObjectBatchInputUpsert": BatchInputSimplePublicObjectBatchInputUpsert_1.BatchInputSimplePublicObjectBatchInputUpsert,
"BatchInputSimplePublicObjectId": BatchInputSimplePublicObjectId_1.BatchInputSimplePublicObjectId,
"BatchReadInputSimplePublicObjectId": BatchReadInputSimplePublicObjectId_1.BatchReadInputSimplePublicObjectId,
"BatchResponseSimplePublicObject": BatchResponseSimplePublicObject_1.BatchResponseSimplePublicObject,
"BatchResponseSimplePublicObjectWithErrors": BatchResponseSimplePublicObjectWithErrors_1.BatchResponseSimplePublicObjectWithErrors,
"BatchResponseSimplePublicUpsertObject": BatchResponseSimplePublicUpsertObject_1.BatchResponseSimplePublicUpsertObject,
"BatchResponseSimplePublicUpsertObjectWithErrors": BatchResponseSimplePublicUpsertObjectWithErrors_1.BatchResponseSimplePublicUpsertObjectWithErrors,
"CollectionResponseAssociatedId": CollectionResponseAssociatedId_1.CollectionResponseAssociatedId,
"CollectionResponseSimplePublicObjectWithAssociationsForwardPaging": CollectionResponseSimplePublicObjectWithAssociationsForwardPaging_1.CollectionResponseSimplePublicObjectWithAssociationsForwardPaging,
"CollectionResponseWithTotalSimplePublicObjectForwardPaging": CollectionResponseWithTotalSimplePublicObjectForwardPaging_1.CollectionResponseWithTotalSimplePublicObjectForwardPaging,
"ErrorDetail": ErrorDetail_1.ErrorDetail,
"Filter": Filter_1.Filter,
"FilterGroup": FilterGroup_1.FilterGroup,
"ForwardPaging": ForwardPaging_1.ForwardPaging,
"ModelError": ModelError_1.ModelError,
"NextPage": NextPage_1.NextPage,
"Paging": Paging_1.Paging,
"PreviousPage": PreviousPage_1.PreviousPage,
"PublicAssociationsForObject": PublicAssociationsForObject_1.PublicAssociationsForObject,
"PublicObjectId": PublicObjectId_1.PublicObjectId,
"PublicObjectSearchRequest": PublicObjectSearchRequest_1.PublicObjectSearchRequest,
"SimplePublicObject": SimplePublicObject_1.SimplePublicObject,
"SimplePublicObjectBatchInput": SimplePublicObjectBatchInput_1.SimplePublicObjectBatchInput,
"SimplePublicObjectBatchInputForCreate": SimplePublicObjectBatchInputForCreate_1.SimplePublicObjectBatchInputForCreate,
"SimplePublicObjectBatchInputUpsert": SimplePublicObjectBatchInputUpsert_1.SimplePublicObjectBatchInputUpsert,
"SimplePublicObjectId": SimplePublicObjectId_1.SimplePublicObjectId,
"SimplePublicObjectInput": SimplePublicObjectInput_1.SimplePublicObjectInput,
"SimplePublicObjectInputForCreate": SimplePublicObjectInputForCreate_1.SimplePublicObjectInputForCreate,
"SimplePublicObjectWithAssociations": SimplePublicObjectWithAssociations_1.SimplePublicObjectWithAssociations,
"SimplePublicUpsertObject": SimplePublicUpsertObject_1.SimplePublicUpsertObject,
"StandardError": StandardError_1.StandardError,
"ValueWithTimestamp": ValueWithTimestamp_1.ValueWithTimestamp,
};
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