UNPKG

@datocms/cma-client

Version:
344 lines 11.8 kB
var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } }; import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource'; export default class Upload extends BaseResource { /** * Create a new upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/create * * @throws {ApiError} * @throws {TimeoutError} */ create(body) { return this.rawCreate(Utils.serializeRequestBody(body, { type: 'upload', attributes: [ 'path', 'copyright', 'author', 'notes', 'default_field_metadata', 'tags', ], relationships: ['upload_collection'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Create a new upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/create * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate(body) { return this.client.request({ method: 'POST', url: '/uploads', body, }); } /** * List all uploads * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances * * @throws {ApiError} * @throws {TimeoutError} */ list(queryParams) { return this.rawList(queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * List all uploads * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawList(queryParams) { return this.client.request({ method: 'GET', url: '/uploads', queryParams, }); } /** * Async iterator to auto-paginate over elements returned by list() * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances * * @throws {ApiError} * @throws {TimeoutError} */ listPagedIterator(queryParams, iteratorOptions) { return __asyncGenerator(this, arguments, function* listPagedIterator_1() { var _a, e_1, _b, _c; try { for (var _d = true, _e = __asyncValues(this.rawListPagedIterator(queryParams, iteratorOptions)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a;) { _c = _f.value; _d = false; try { const element = _c; yield yield __await(Utils.deserializeJsonEntity(element)); } finally { _d = true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e)); } finally { if (e_1) throw e_1.error; } } }); } /** * Async iterator to auto-paginate over elements returned by rawList() * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances * * @throws {ApiError} * @throws {TimeoutError} */ rawListPagedIterator(queryParams, iteratorOptions) { Utils.warnOnPageQueryParam(queryParams); return Utils.rawPageIterator({ defaultLimit: 30, maxLimit: 500, }, (page) => this.rawList(Object.assign(Object.assign({}, queryParams), { page })), iteratorOptions); } /** * Retrieve an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/self * * @throws {ApiError} * @throws {TimeoutError} */ find(uploadId) { return this.rawFind(Utils.toId(uploadId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Retrieve an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/self * * @throws {ApiError} * @throws {TimeoutError} */ rawFind(uploadId) { return this.client.request({ method: 'GET', url: `/uploads/${uploadId}`, }); } /** * Delete an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/destroy * * @throws {ApiError} * @throws {TimeoutError} */ destroy(uploadId) { return this.rawDestroy(Utils.toId(uploadId)).then((body) => Utils.deserializeResponseBody(body)); } /** * Delete an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy(uploadId) { return this.client.request({ method: 'DELETE', url: `/uploads/${uploadId}`, }); } /** * Update an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/update * * @throws {ApiError} * @throws {TimeoutError} */ update(uploadId, body, queryParams) { return this.rawUpdate(Utils.toId(uploadId), Utils.serializeRequestBody(body, { id: Utils.toId(uploadId), type: 'upload', attributes: [ 'path', 'basename', 'copyright', 'author', 'notes', 'tags', 'default_field_metadata', ], relationships: ['creator', 'upload_collection'], }), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Update an upload * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/update * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate(uploadId, body, queryParams) { return this.client.request({ method: 'PUT', url: `/uploads/${uploadId}`, body, queryParams, }); } /** * Referenced records * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/references * * @throws {ApiError} * @throws {TimeoutError} */ references(uploadId, queryParams) { return this.rawReferences(Utils.toId(uploadId), queryParams).then((body) => Utils.deserializeResponseBody(body)); } /** * Referenced records * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/references * * @throws {ApiError} * @throws {TimeoutError} */ rawReferences(uploadId, queryParams) { return this.client .request({ method: 'GET', url: `/uploads/${uploadId}/references`, queryParams, }) .then(Utils.deserializeRawResponseBodyWithItems); } /** * Add tags to assets in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_tag * * @throws {ApiError} * @throws {TimeoutError} */ bulkTag(body) { return this.rawBulkTag(Utils.serializeRequestBody(body, { type: 'upload_bulk_tag_operation', attributes: ['tags'], relationships: ['uploads'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Add tags to assets in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_tag * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkTag(body) { return this.client.request({ method: 'POST', url: '/uploads/bulk/tag', body, }); } /** * Put assets into a collection in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_set_upload_collection * * @throws {ApiError} * @throws {TimeoutError} */ bulkSetUploadCollection(body) { return this.rawBulkSetUploadCollection(Utils.serializeRequestBody(body, { type: 'upload_bulk_set_upload_collection_operation', attributes: [], relationships: ['upload_collection', 'uploads'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Put assets into a collection in bulk * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_set_upload_collection * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkSetUploadCollection(body) { return this.client.request({ method: 'POST', url: '/uploads/bulk/set-upload-collection', body, }); } /** * Destroy uploads * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_destroy * * @throws {ApiError} * @throws {TimeoutError} */ bulkDestroy(body) { return this.rawBulkDestroy(Utils.serializeRequestBody(body, { type: 'upload_bulk_destroy_operation', attributes: [], relationships: ['uploads'], })).then((body) => Utils.deserializeResponseBody(body)); } /** * Destroy uploads * * Read more: https://www.datocms.com/docs/content-management-api/resources/upload/bulk_destroy * * @throws {ApiError} * @throws {TimeoutError} */ rawBulkDestroy(body) { return this.client.request({ method: 'POST', url: '/uploads/bulk/destroy', body, }); } } Upload.TYPE = 'upload'; //# sourceMappingURL=Upload.js.map