UNPKG

@kintone/kintone-js-sdk

Version:

The SDK of kintone REST API client on node and browser

238 lines (208 loc) 6.57 kB
import "core-js/modules/es.array.concat"; import "core-js/modules/es.object.to-string"; import "core-js/modules/es.promise"; import "core-js/modules/es.promise.finally"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import "regenerator-runtime/runtime"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import KintoneAPIException from '../../exception/KintoneAPIException'; import CursorModel from '../../model/cursor/CursorModels'; import common from '../../utils/Common'; import Connection from '../../connection/Connection'; /* eslint-disable no-loop-func */ /* eslint-disable no-async-promise-executor, require-atomic-updates */ /** * RecordCursor module */ var RecordCursor = /*#__PURE__*/function () { /** * The constructor for RecordCursor module * @param {Object} params * @param {Connection} params.connection */ function RecordCursor() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, connection = _ref.connection; _classCallCheck(this, RecordCursor); if (!(connection instanceof Connection)) { throw new KintoneAPIException("".concat(connection, " is not an instance of Connection")); } this.connection = connection; Promise.resolve().finally(); } /** * @param {Object} params * @param {String} params.method * @param {String} params.url * @param {RecordModel} params.model * @return {Promise} Promise */ _createClass(RecordCursor, [{ key: "sendRequest", value: function sendRequest(_ref2) { var method = _ref2.method, url = _ref2.url, model = _ref2.model; return common.sendRequest(method, url, model, this.connection); } /** * check required arguments * * @param {Object} params * @returns {Boolean} */ }, { key: "_validateRequiredArgs", value: function _validateRequiredArgs(params) { return new Promise(function (resolve, reject) { try { common.validateRequiredArgs(params); resolve(); } catch (error) { reject(error); } }); } /** * Create a new record cursor * @param {Object} params * @param {Integer} params.app * @param {Array<String>} fields * @param {String} params.query * @param {Integer} params.size * @return {Promise} */ }, { key: "createCursor", value: function createCursor() { var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, app = _ref3.app, fields = _ref3.fields, query = _ref3.query, size = _ref3.size; var createCursorRequest = new CursorModel.CreateRecordCursorRequest({ app: app, fields: fields, query: query, size: size }); return this.sendRequest({ method: 'POST', url: 'RECORD_CURSOR', model: createCursorRequest }); } /** * Get 1 block of records * @param {Object} params * @param {String} params.id cursor id * @return {Promise} */ }, { key: "getRecords", value: function getRecords(_ref4) { var id = _ref4.id; var getRecordCursorRequest = new CursorModel.GetRecordCursorRequest(id); return this.sendRequest({ method: 'GET', url: 'RECORD_CURSOR', model: getRecordCursorRequest }); } /** * Get all records * @param {Object} params * @param {String} params.id cursor id * @return {Promise} */ }, { key: "getAllRecords", value: function () { var _getAllRecords = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _ref5, id, next, allRecords, recordBlockResponse, _args = arguments; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _ref5 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, id = _ref5.id; _context.next = 3; return this._validateRequiredArgs({ id: id }); case 3: next = true; allRecords = []; case 5: if (!next) { _context.next = 19; break; } _context.prev = 6; _context.next = 9; return this.getRecords({ id: id }); case 9: recordBlockResponse = _context.sent; if (!(recordBlockResponse instanceof KintoneAPIException)) { allRecords = allRecords.concat(recordBlockResponse.records); next = recordBlockResponse.next; } else { next = false; } _context.next = 17; break; case 13: _context.prev = 13; _context.t0 = _context["catch"](6); next = false; throw _context.t0; case 17: _context.next = 5; break; case 19: return _context.abrupt("return", { records: allRecords, totalCount: allRecords.length }); case 20: case "end": return _context.stop(); } } }, _callee, this, [[6, 13]]); })); function getAllRecords() { return _getAllRecords.apply(this, arguments); } return getAllRecords; }() /** * Delete cursor * @param {Object} params * @param {String} params.id * @return {Promise} */ }, { key: "deleteCursor", value: function deleteCursor() { var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, id = _ref6.id; var deleteRecordCursorRequest = new CursorModel.DeleteRecordCursorRequest(id); return this.sendRequest({ method: 'DELETE', url: 'RECORD_CURSOR', model: deleteRecordCursorRequest }); } }]); return RecordCursor; }(); export default RecordCursor;