@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
185 lines • 6 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
var Fieldset = /** @class */ (function (_super) {
__extends(Fieldset, _super);
function Fieldset() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Create a new fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.create = function (itemTypeId, body) {
return this.rawCreate(Utils.toId(itemTypeId), Utils.serializeRequestBody(body, {
type: 'fieldset',
attributes: [
'title',
'hint',
'position',
'collapsible',
'start_collapsed',
],
relationships: [],
})).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Create a new fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.rawCreate = function (itemTypeId, body) {
return this.client.request({
method: 'POST',
url: "/item-types/".concat(itemTypeId, "/fieldsets"),
body: body,
});
};
/**
* Update a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.update = function (fieldsetId, body) {
return this.rawUpdate(Utils.toId(fieldsetId), Utils.serializeRequestBody(body, {
id: Utils.toId(fieldsetId),
type: 'fieldset',
attributes: [
'title',
'hint',
'position',
'collapsible',
'start_collapsed',
],
relationships: [],
})).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Update a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.rawUpdate = function (fieldsetId, body) {
return this.client.request({
method: 'PUT',
url: "/fieldsets/".concat(fieldsetId),
body: body,
});
};
/**
* List all fieldsets
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.list = function (itemTypeId) {
return this.rawList(Utils.toId(itemTypeId)).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* List all fieldsets
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.rawList = function (itemTypeId) {
return this.client.request({
method: 'GET',
url: "/item-types/".concat(itemTypeId, "/fieldsets"),
});
};
/**
* Retrieve a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.find = function (fieldsetId) {
return this.rawFind(Utils.toId(fieldsetId)).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Retrieve a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.rawFind = function (fieldsetId) {
return this.client.request({
method: 'GET',
url: "/fieldsets/".concat(fieldsetId),
});
};
/**
* Delete a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.destroy = function (fieldsetId) {
return this.rawDestroy(Utils.toId(fieldsetId)).then(function (body) {
return Utils.deserializeResponseBody(body);
});
};
/**
* Delete a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
Fieldset.prototype.rawDestroy = function (fieldsetId) {
return this.client.request({
method: 'DELETE',
url: "/fieldsets/".concat(fieldsetId),
});
};
Fieldset.TYPE = 'fieldset';
return Fieldset;
}(BaseResource));
export default Fieldset;
//# sourceMappingURL=Fieldset.js.map