Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobx-rest

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-rest - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

33

__tests__/Collection.spec.js

@@ -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)
})
})
})
})
})

73

lib/Collection.js

@@ -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;

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc