UNPKG

@datocms/cma-client

Version:
289 lines 9.33 kB
"use strict"; 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 ItemType extends BaseResource_1.default { /** * 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, }); } } exports.default = ItemType; ItemType.TYPE = 'item_type'; //# sourceMappingURL=ItemType.js.map