UNPKG

@datocms/cma-client

Version:
268 lines 8.77 kB
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 ItemType = /** @class */ (function (_super) { __extends(ItemType, _super); function ItemType() { return _super !== null && _super.apply(this, arguments) || this; } /** * Create a new model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.create = function (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(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Create a new model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/create * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawCreate = function (body, queryParams) { return this.client.request({ method: 'POST', url: '/item-types', body: body, queryParams: queryParams, }); }; /** * Update a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.update = function (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(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Update a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/update * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawUpdate = function (itemTypeId, body) { return this.client.request({ method: 'PUT', url: "/item-types/".concat(itemTypeId), body: body, }); }; /** * List all models * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.list = function () { return this.rawList().then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * List all models * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/instances * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawList = function () { return this.client.request({ method: 'GET', url: '/item-types', }); }; /** * Retrieve a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.find = function (itemTypeId) { return this.rawFind(Utils.toId(itemTypeId)).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Retrieve a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/self * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawFind = function (itemTypeId) { return this.client.request({ method: 'GET', url: "/item-types/".concat(itemTypeId), }); }; /** * Duplicate model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.duplicate = function (itemTypeId) { return this.rawDuplicate(Utils.toId(itemTypeId)).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Duplicate model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/duplicate * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawDuplicate = function (itemTypeId) { return this.client.request({ method: 'POST', url: "/item-types/".concat(itemTypeId, "/duplicate"), }); }; /** * Delete a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.destroy = function (itemTypeId, queryParams) { return this.rawDestroy(Utils.toId(itemTypeId), queryParams).then(function (body) { return Utils.deserializeResponseBody(body); }); }; /** * Delete a model * * Read more: https://www.datocms.com/docs/content-management-api/resources/item-type/destroy * * @throws {ApiError} * @throws {TimeoutError} */ ItemType.prototype.rawDestroy = function (itemTypeId, queryParams) { return this.client.request({ method: 'DELETE', url: "/item-types/".concat(itemTypeId), queryParams: queryParams, }); }; /** * 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 */ ItemType.prototype.rawReorderFieldsAndFieldsets = function (itemTypeId, body) { return this.client.request({ method: 'POST', url: "/item-types/".concat(itemTypeId, "/reorder-fields-and-fieldsets"), body: body, }); }; ItemType.TYPE = 'item_type'; return ItemType; }(BaseResource)); export default ItemType; //# sourceMappingURL=ItemType.js.map