@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
274 lines • 8.49 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Utils = __importStar(require("@datocms/rest-client-utils"));
const BaseResource_1 = __importDefault(require("../../BaseResource"));
class Field extends BaseResource_1.default {
/**
* Create a new field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(itemTypeId, body) {
return this.rawCreate(Utils.toId(itemTypeId), Utils.serializeRequestBody(body, {
type: 'field',
attributes: [
'label',
'field_type',
'api_key',
'localized',
'validators',
'appeareance',
'appearance',
'position',
'hint',
'default_value',
'deep_filtering_enabled',
],
relationships: ['fieldset'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(itemTypeId, body) {
return this.client.request({
method: 'POST',
url: `/item-types/${itemTypeId}/fields`,
body,
});
}
/**
* Update a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(fieldId, body) {
return this.rawUpdate(Utils.toId(fieldId), Utils.serializeRequestBody(body, {
id: Utils.toId(fieldId),
type: 'field',
attributes: [
'default_value',
'label',
'api_key',
'localized',
'validators',
'appeareance',
'appearance',
'position',
'field_type',
'hint',
'deep_filtering_enabled',
],
relationships: ['fieldset'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(fieldId, body) {
return this.client.request({
method: 'PUT',
url: `/fields/${fieldId}`,
body,
});
}
/**
* List all fields of a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list(itemTypeId) {
return this.rawList(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all fields of a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList(itemTypeId) {
return this.client.request({
method: 'GET',
url: `/item-types/${itemTypeId}/fields`,
});
}
/**
* List fields referencing a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/referencing
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
referencing(itemTypeId) {
return this.rawReferencing(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List fields referencing a model/block
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/referencing
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawReferencing(itemTypeId) {
return this.client.request({
method: 'GET',
url: `/item-types/${itemTypeId}/fields/referencing`,
});
}
/**
* List related fields
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/related
*
* @throws {ApiError}
* @throws {TimeoutError}
*
* @deprecated This API call is to be considered private and might change without notice
*/
related(itemTypeId) {
return this.rawRelated(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List related fields
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/related
*
* @throws {ApiError}
* @throws {TimeoutError}
*
* @deprecated This API call is to be considered private and might change without notice
*/
rawRelated(itemTypeId) {
return this.client.request({
method: 'GET',
url: `/item-types/${itemTypeId}/fields/related`,
});
}
/**
* Retrieve a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
find(fieldId) {
return this.rawFind(Utils.toId(fieldId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(fieldId) {
return this.client.request({
method: 'GET',
url: `/fields/${fieldId}`,
});
}
/**
* Delete a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(fieldId) {
return this.rawDestroy(Utils.toId(fieldId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(fieldId) {
return this.client.request({
method: 'DELETE',
url: `/fields/${fieldId}`,
});
}
/**
* Duplicate a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
duplicate(fieldId) {
return this.rawDuplicate(Utils.toId(fieldId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Duplicate a field
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/field/duplicate
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDuplicate(fieldId) {
return this.client.request({
method: 'POST',
url: `/fields/${fieldId}/duplicate`,
});
}
}
exports.default = Field;
Field.TYPE = 'field';
//# sourceMappingURL=Field.js.map