@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
129 lines • 5.44 kB
JavaScript
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class UploadTag extends BaseResource {
/**
* List all manually created upload tags
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list(queryParams) {
return this.rawList(queryParams).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all manually created upload tags
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList(queryParams) {
return this.client.request({
method: 'GET',
url: '/upload-tags',
queryParams,
});
}
/**
* Async iterator to auto-paginate over elements returned by list()
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
listPagedIterator(queryParams, iteratorOptions) {
return __asyncGenerator(this, arguments, function* listPagedIterator_1() {
var _a, e_1, _b, _c;
try {
for (var _d = true, _e = __asyncValues(this.rawListPagedIterator(queryParams, iteratorOptions)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a;) {
_c = _f.value;
_d = false;
try {
const element = _c;
yield yield __await(Utils.deserializeJsonEntity(element));
}
finally {
_d = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
}
finally { if (e_1) throw e_1.error; }
}
});
}
/**
* Async iterator to auto-paginate over elements returned by rawList()
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawListPagedIterator(queryParams, iteratorOptions) {
Utils.warnOnPageQueryParam(queryParams);
return Utils.rawPageIterator({
defaultLimit: 50,
maxLimit: 500,
}, (page) => this.rawList(Object.assign(Object.assign({}, queryParams), { page })), iteratorOptions);
}
/**
* Create a new upload tag
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(body) {
return this.rawCreate(Utils.serializeRequestBody(body, {
type: 'upload_tag',
attributes: ['name'],
relationships: [],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new upload tag
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload-tag/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(body) {
return this.client.request({
method: 'POST',
url: '/upload-tags',
body,
});
}
}
UploadTag.TYPE = 'upload_tag';
//# sourceMappingURL=UploadTag.js.map