UNPKG

stackexchange-api

Version:
84 lines (83 loc) 4.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); /** * The equivalent of the [Common Wrapper Object](https://api.stackexchange.com/docs/wrapper).<br> * All responses in the API share a common format, so as to make parsing these responses simpler. */ class Wrapper { constructor(wrapper, classType) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y; this.backoff = (_b = (_a = wrapper) === null || _a === void 0 ? void 0 : _a.backoff, (_b !== null && _b !== void 0 ? _b : null)); this.errorId = (_d = (_c = wrapper) === null || _c === void 0 ? void 0 : _c.error_id, (_d !== null && _d !== void 0 ? _d : null)); this.errorMessage = (_f = (_e = wrapper) === null || _e === void 0 ? void 0 : _e.error_message, (_f !== null && _f !== void 0 ? _f : null)); this.errorName = (_h = (_g = wrapper) === null || _g === void 0 ? void 0 : _g.error_name, (_h !== null && _h !== void 0 ? _h : null)); this.hasMore = (_k = (_j = wrapper) === null || _j === void 0 ? void 0 : _j.has_more, (_k !== null && _k !== void 0 ? _k : null)); if (typeof ((_l = wrapper) === null || _l === void 0 ? void 0 : _l.items) === 'undefined' || typeof classType === 'undefined') { this.items = null; } else { switch (classType) { case 'Answer': this.items = [...wrapper.items] .map((item) => new index_1.Answer(item)); break; case 'Badge': this.items = [...wrapper.items] .map((item) => new index_1.Badge(item)); break; case 'Comment': this.items = [...wrapper.items] .map((item) => new index_1.Comment(item)); break; case 'Filter': this.items = [...wrapper.items] .map((item) => new index_1.Filter(item)); break; case 'Info': this.items = [...wrapper.items] .map((item) => new index_1.Info(item)); break; case 'Post': this.items = [...wrapper.items] .map((item) => new index_1.Post(item)); break; case 'Privilege': this.items = [...wrapper.items] .map((item) => new index_1.Privilege(item)); break; case 'Question': this.items = [...wrapper.items] .map((item) => new index_1.Question(item)); break; case 'Site': this.items = [...wrapper.items] .map((item) => new index_1.Site(item)); break; case 'Tag': this.items = [...wrapper.items] .map((item) => new index_1.Tag(item)); break; default: this.items = null; } } this.page = (_o = (_m = wrapper) === null || _m === void 0 ? void 0 : _m.page, (_o !== null && _o !== void 0 ? _o : null)); this.pageSize = (_q = (_p = wrapper) === null || _p === void 0 ? void 0 : _p.page_size, (_q !== null && _q !== void 0 ? _q : null)); this.quotaMax = (_s = (_r = wrapper) === null || _r === void 0 ? void 0 : _r.quota_max, (_s !== null && _s !== void 0 ? _s : null)); this.quotaRemaining = (_u = (_t = wrapper) === null || _t === void 0 ? void 0 : _t.quota_remaining, (_u !== null && _u !== void 0 ? _u : null)); this.total = (_w = (_v = wrapper) === null || _v === void 0 ? void 0 : _v.total, (_w !== null && _w !== void 0 ? _w : null)); this.type = (_y = (_x = wrapper) === null || _x === void 0 ? void 0 : _x.type, (_y !== null && _y !== void 0 ? _y : null)); } } exports.Wrapper = Wrapper;