Comparing version 1.0.0 to 1.0.1
@@ -290,3 +290,36 @@ import { Collection, apiClient } from '../src' | ||
}) | ||
describe('rpc', () => { | ||
it('sets the request', () => { | ||
collection.rpc('foo') | ||
expect(collection.request.label).toBe('updating') | ||
}) | ||
describe('when it fails', () => { | ||
beforeEach(reject) | ||
it('sets the error', async () => { | ||
try { | ||
await collection.rpc('foo') | ||
} catch (_error) { | ||
expect(collection.error.label).toBe('updating') | ||
expect(collection.error.body).toBe(error) | ||
} | ||
}) | ||
}) | ||
describe('when it succeeds', () => { | ||
const mockResponse = [item, { id: 2, name: 'bob' }] | ||
beforeEach(() => { | ||
resolve(mockResponse)() | ||
}) | ||
it('return the data', async () => { | ||
const data = await collection.rpc('foo') | ||
expect(data).toBe(mockResponse) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -465,2 +465,73 @@ 'use strict'; | ||
}() | ||
/** | ||
* Call an RPC action for all those | ||
* non-REST endpoints that you may have in | ||
* your API. | ||
*/ | ||
}, { | ||
key: 'rpc', | ||
value: function () { | ||
var _ref7 = _asyncToGenerator(regeneratorRuntime.mark(function _callee3(method, body) { | ||
var _this6 = this; | ||
var label, _apiClient$post2, promise, abort, response; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
label = 'updating'; // TODO: Maybe differentiate? | ||
_apiClient$post2 = (0, _apiClient2.default)().post(this.url() + '/' + method, body || {}), promise = _apiClient$post2.promise, abort = _apiClient$post2.abort; | ||
this.request = { | ||
label: label, | ||
abort: (0, _mobx.asReference)(abort), | ||
progress: 0 | ||
}; | ||
response = void 0; | ||
_context3.prev = 4; | ||
_context3.next = 7; | ||
return promise; | ||
case 7: | ||
response = _context3.sent; | ||
_context3.next = 14; | ||
break; | ||
case 10: | ||
_context3.prev = 10; | ||
_context3.t0 = _context3['catch'](4); | ||
(0, _mobx.runInAction)('accept-fail', function () { | ||
_this6.request = null; | ||
_this6.error = { label: label, body: _context3.t0 }; | ||
}); | ||
throw _context3.t0; | ||
case 14: | ||
this.request = null; | ||
return _context3.abrupt('return', response); | ||
case 16: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this, [[4, 10]]); | ||
})); | ||
function rpc(_x8, _x9) { | ||
return _ref7.apply(this, arguments); | ||
} | ||
return rpc; | ||
}() | ||
}]); | ||
@@ -484,3 +555,3 @@ | ||
} | ||
}), _applyDecoratedDescriptor(_class.prototype, 'add', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'remove', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'remove'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'create', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'create'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype)), _class); | ||
}), _applyDecoratedDescriptor(_class.prototype, 'add', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'remove', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'remove'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'create', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'create'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rpc', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'rpc'), _class.prototype)), _class); | ||
exports.default = Collection; |
{ | ||
"name": "mobx-rest", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "REST conventions for mobx.", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
60215
1476
2
15