UNPKG

chargebee-typescript

Version:

A library in typescript for integrating with Chargebee.

87 lines (86 loc) 4.29 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _Model__values, _Model__sub_types, _Model__dependant_types; Object.defineProperty(exports, "__esModule", { value: true }); exports.Model = void 0; const resources = require("../resources"); const util_1 = require("../util"); class Model { get values() { return __classPrivateFieldGet(this, _Model__values, "f"); } get sub_types() { return __classPrivateFieldGet(this, _Model__sub_types, "f"); } get dependant_types() { return __classPrivateFieldGet(this, _Model__dependant_types, "f"); } constructor(_values, _sub_types = {}, _dependant_types = {}) { _Model__values.set(this, void 0); _Model__sub_types.set(this, void 0); _Model__dependant_types.set(this, void 0); __classPrivateFieldSet(this, _Model__values, _values, "f"); __classPrivateFieldSet(this, _Model__sub_types, _sub_types, "f"); __classPrivateFieldSet(this, _Model__dependant_types, _dependant_types, "f"); this.load(this.values); } load(values) { for (const k in values) { let v = values[k]; let set_val = v; if (util_1.Util.isObject(v) && this.dependant_types[k]) { continue; } else if (util_1.Util.isObject(v)) { set_val = this.sub_types[k] ? new (resources)[this.sub_types[k]](v) : v; } else if (util_1.Util.isArray(v)) { if (!util_1.Util.isEmptyObject(this.sub_types[k])) { let set_vals = []; for (let item of v) { set_vals.push(new (resources)[this.sub_types[k]](item)); } set_val = set_vals; } else { set_val = v; } } this[k] = set_val; } } init_dependant(obj, type, sub_types = {}) { if (!util_1.Util.isEmptyObject(obj) && util_1.Util.isObject(obj) && !util_1.Util.isEmptyObject(this.dependant_types[type])) { this[type] = new (resources)[this.dependant_types[type]](obj[type], sub_types); } } init_dependant_extended(obj, type, sub_types = {}) { if (!util_1.Util.isEmptyObject(obj) && !util_1.Util.isEmptyObject(obj[type]) && util_1.Util.isObject(obj) && !util_1.Util.isEmptyObject(this.dependant_types[type])) { this[type] = new (resources)[this.dependant_types[type]](obj[type], sub_types); } } init_dependant_list(obj, type, sub_types = {}) { if (!util_1.Util.isEmptyObject(obj) && !util_1.Util.isEmptyObject(obj[type]) && util_1.Util.isArray(obj[type]) && !util_1.Util.isEmptyObject(this.dependant_types[type])) { let dependant_objs = []; for (let dt of obj[type]) { dependant_objs.push(new (resources)[this.dependant_types[type]](dt, sub_types)); } this[type] = dependant_objs; } } toString(...args) { return JSON.stringify(this.values, null, 2); } } exports.Model = Model; _Model__values = new WeakMap(), _Model__sub_types = new WeakMap(), _Model__dependant_types = new WeakMap();