@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
154 lines • 4.51 kB
JavaScript
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class Fieldset extends BaseResource {
/**
* Create a new fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(itemTypeId, body) {
return this.rawCreate(Utils.toId(itemTypeId), Utils.serializeRequestBody(body, {
type: 'fieldset',
attributes: [
'title',
'hint',
'position',
'collapsible',
'start_collapsed',
],
relationships: [],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(itemTypeId, body) {
return this.client.request({
method: 'POST',
url: `/item-types/${itemTypeId}/fieldsets`,
body,
});
}
/**
* Update a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(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((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(fieldsetId, body) {
return this.client.request({
method: 'PUT',
url: `/fieldsets/${fieldsetId}`,
body,
});
}
/**
* List all fieldsets of a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list(itemTypeId) {
return this.rawList(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all fieldsets of a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList(itemTypeId) {
return this.client.request({
method: 'GET',
url: `/item-types/${itemTypeId}/fieldsets`,
});
}
/**
* Retrieve a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
find(fieldsetId) {
return this.rawFind(Utils.toId(fieldsetId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(fieldsetId) {
return this.client.request({
method: 'GET',
url: `/fieldsets/${fieldsetId}`,
});
}
/**
* Delete a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(fieldsetId) {
return this.rawDestroy(Utils.toId(fieldsetId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a fieldset
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/fieldset/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(fieldsetId) {
return this.client.request({
method: 'DELETE',
url: `/fieldsets/${fieldsetId}`,
});
}
}
Fieldset.TYPE = 'fieldset';
//# sourceMappingURL=Fieldset.js.map