UNPKG

@datocms/cma-client

Version:
260 lines 8.02 kB
import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class ItemType extends BaseResource { /** * Create a new model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body, queryParams) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'item_type', attributes: [ 'name', 'api_key', 'singleton', 'all_locales_required', 'sortable', 'modular_block', 'draft_mode_active', 'draft_saving_active', 'tree', 'ordering_direction', 'ordering_meta', 'collection_appeareance', 'collection_appearance', 'hint', 'inverse_relationships_enabled', ], relationships: [ 'ordering_field', 'presentation_title_field', 'presentation_image_field', 'title_field', 'image_preview_field', 'excerpt_field', 'workflow', ], }), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a new model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body, queryParams) { return this.client.request({ method: 'POST', url: '/item-types', body, queryParams, }); } /** * Update a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update * * @throws {ApiError} * @throws {TimeoutError} */ update(itemTypeId, body) { return this.rawUpdate(Utils.toId(itemTypeId), Utils.serializeRequestBody(body, { id: Utils.toId(itemTypeId), type: 'item_type', attributes: [ 'name', 'api_key', 'collection_appeareance', 'collection_appearance', 'singleton', 'all_locales_required', 'sortable', 'modular_block', 'draft_mode_active', 'draft_saving_active', 'tree', 'ordering_direction', 'ordering_meta', 'has_singleton_item', 'hint', 'inverse_relationships_enabled', ], relationships: [ 'ordering_field', 'presentation_title_field', 'presentation_image_field', 'title_field', 'image_preview_field', 'excerpt_field', 'workflow', ], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Update a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(itemTypeId, body) { return this.client.request({ method: 'PUT', url: `/item-types/${itemTypeId}`, body, }); } /** * List all models/block models * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances * * @throws {ApiError} * @throws {TimeoutError} */ list() { return this.rawList().then((body) => Utils.deserializeResponseBody(body)); } /** * List all models/block models * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList() { return this.client.request({ method: 'GET', url: '/item-types', }); } /** * Retrieve a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self * * @throws {ApiError} * @throws {TimeoutError} */ find(itemTypeId) { return this.rawFind(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(itemTypeId) { return this.client.request({ method: 'GET', url: `/item-types/${itemTypeId}`, }); } /** * Duplicate model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ duplicate(itemTypeId) { return this.rawDuplicate(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Duplicate model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ rawDuplicate(itemTypeId) { return this.client.request({ method: 'POST', url: `/item-types/${itemTypeId}/duplicate`, }); } /** * Delete a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(itemTypeId, queryParams) { return this.rawDestroy(Utils.toId(itemTypeId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete a model/block model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(itemTypeId, queryParams) { return this.client.request({ method: 'DELETE', url: `/item-types/${itemTypeId}`, queryParams, }); } /** * List models referencing another model/block * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/referencing * * @throws {ApiError} * @throws {TimeoutError} */ referencing(itemTypeId) { return this.rawReferencing(Utils.toId(itemTypeId)).then((body) => Utils.deserializeResponseBody(body)); } /** * List models referencing another model/block * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/referencing * * @throws {ApiError} * @throws {TimeoutError} */ rawReferencing(itemTypeId) { return this.client.request({ method: 'GET', url: `/item-types/${itemTypeId}/referencing`, }); } /** * Reorders a set of fields and fieldsets within the model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/reorder_fields_and_fieldsets * * @throws {ApiError} * @throws {TimeoutError} * * @deprecated This API call is to be considered private and might change without notice */ rawReorderFieldsAndFieldsets(itemTypeId, body) { return this.client.request({ method: 'POST', url: `/item-types/${itemTypeId}/reorder-fields-and-fieldsets`, body, }); } } ItemType.TYPE = 'item_type'; //# sourceMappingURL=ItemType.js.map