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

mobx-rest

Package Overview
Dependencies
Maintainers
4
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 7.1.1 to 8.0.0

4

CHANGELOG.md
# Changelog
## `8.0.0``
- Migrated to mobx 6
## `7.1.1``

@@ -4,0 +8,0 @@

153

lib/index.js

@@ -5,31 +5,44 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var mobx = require('mobx');
var includes = _interopDefault(require('lodash/includes'));
var isObject = _interopDefault(require('lodash/isObject'));
var debounce = _interopDefault(require('lodash/debounce'));
var isEqual = _interopDefault(require('lodash/isEqual'));
var isPlainObject = _interopDefault(require('lodash/isPlainObject'));
var union = _interopDefault(require('lodash/union'));
var uniqueId = _interopDefault(require('lodash/uniqueId'));
var deepmerge = _interopDefault(require('deepmerge'));
var difference = _interopDefault(require('lodash/difference'));
var intersection = _interopDefault(require('lodash/intersection'));
var entries = _interopDefault(require('lodash/entries'));
var compact = _interopDefault(require('lodash/compact'));
var includes = require('lodash/includes');
var isObject = require('lodash/isObject');
var debounce = require('lodash/debounce');
var isEqual = require('lodash/isEqual');
var isPlainObject = require('lodash/isPlainObject');
var union = require('lodash/union');
var uniqueId = require('lodash/uniqueId');
var deepmerge = require('deepmerge');
var difference = require('lodash/difference');
var intersection = require('lodash/intersection');
var entries = require('lodash/entries');
var compact = require('lodash/compact');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var includes__default = /*#__PURE__*/_interopDefaultLegacy(includes);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
var uniqueId__default = /*#__PURE__*/_interopDefaultLegacy(uniqueId);
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
var difference__default = /*#__PURE__*/_interopDefaultLegacy(difference);
var intersection__default = /*#__PURE__*/_interopDefaultLegacy(intersection);
var entries__default = /*#__PURE__*/_interopDefaultLegacy(entries);
var compact__default = /*#__PURE__*/_interopDefaultLegacy(compact);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

@@ -41,3 +54,3 @@ /* global Reflect, Promise */

({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);

@@ -68,4 +81,6 @@ };

if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;

@@ -168,11 +183,11 @@ }

_this.request = null;
mobx.runInAction('remove request', function () {
mobx.runInAction(mobx.action('remove request', function () {
_this.requests.remove(request);
});
}));
return response;
})
.catch(function (error) {
mobx.runInAction('remove request', function () {
mobx.runInAction(mobx.action('remove request', function () {
_this.requests.remove(request);
});
}));
throw new ErrorObject(error);

@@ -189,6 +204,6 @@ });

Base.prototype.getRequest = function (label) {
return this.requests.find(function (request) { return includes(request.labels, label); });
return this.requests.find(function (request) { return includes__default['default'](request.labels, label); });
};
Base.prototype.getAllRequests = function (label) {
return this.requests.filter(function (request) { return includes(request.labels, label); });
return this.requests.filter(function (request) { return includes__default['default'](request.labels, label); });
};

@@ -209,3 +224,3 @@ /**

if (label === void 0) { label = 'calling'; }
var url = isObject(endpoint) ? endpoint.rootUrl : this.url() + "/" + endpoint;
var url = isObject__default['default'](endpoint) ? endpoint.rootUrl : this.url() + "/" + endpoint;
var _a = apiClient().post(url, options), promise = _a.promise, abort = _a.abort;

@@ -235,6 +250,6 @@ return this.withRequest(label, promise, abort);

_this.defaultAttributes = {};
_this.optimisticId = uniqueId('i_');
_this.optimisticId = uniqueId__default['default']('i_');
_this.collection = null;
_this.defaultAttributes = defaultAttributes;
var mergedAttributes = __assign({}, _this.defaultAttributes, attributes);
var mergedAttributes = __assign(__assign({}, _this.defaultAttributes), attributes);
_this.attributes = mobx.observable.map(mergedAttributes);

@@ -249,3 +264,3 @@ _this.committedAttributes = mobx.observable.map(mergedAttributes);

Model.prototype.toJS = function () {
return mobx.toJS(this.attributes, { exportMapsAsObjects: true });
return Object.fromEntries(this.attributes);
};

@@ -262,3 +277,3 @@ Object.defineProperty(Model.prototype, "primaryKey", {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -303,3 +318,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -342,3 +357,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -351,5 +366,5 @@ });

get: function () {
return getChangedAttributesBetween(mobx.toJS(this.committedAttributes), mobx.toJS(this.attributes));
return getChangedAttributesBetween(Object.fromEntries(this.committedAttributes), Object.fromEntries(this.attributes));
},
enumerable: true,
enumerable: false,
configurable: true

@@ -362,5 +377,5 @@ });

get: function () {
return getChangesBetween(mobx.toJS(this.committedAttributes), mobx.toJS(this.attributes));
return getChangesBetween(Object.fromEntries(this.committedAttributes), Object.fromEntries(this.attributes));
},
enumerable: true,
enumerable: false,
configurable: true

@@ -374,3 +389,3 @@ });

if (attribute) {
return includes(this.changedAttributes, attribute);
return includes__default['default'](this.changedAttributes, attribute);
}

@@ -380,6 +395,6 @@ return this.changedAttributes.length > 0;

Model.prototype.commitChanges = function () {
this.committedAttributes.replace(mobx.toJS(this.attributes));
this.committedAttributes.replace(Object.fromEntries(this.attributes));
};
Model.prototype.discardChanges = function () {
this.attributes.replace(mobx.toJS(this.committedAttributes));
this.attributes.replace(Object.fromEntries(this.committedAttributes));
};

@@ -391,3 +406,3 @@ /**

this.attributes.replace(data
? __assign({}, this.defaultAttributes, data) : this.defaultAttributes);
? __assign(__assign({}, this.defaultAttributes), data) : this.defaultAttributes);
};

@@ -442,3 +457,3 @@ /**

else {
data = __assign({}, currentAttributes, attributes);
data = __assign(__assign({}, currentAttributes), attributes);
}

@@ -462,3 +477,3 @@ var method;

collection.add([this]);
var onProgress = debounce(function (progress) {
var onProgress = debounce__default['default'](function (progress) {
if (optimistic && _this.request)

@@ -472,4 +487,4 @@ _this.request.progress = progress;

return;
var changes = getChangesBetween(currentAttributes, mobx.toJS(_this.attributes));
mobx.runInAction('save success', function () {
var changes = getChangesBetween(currentAttributes, Object.fromEntries(_this.attributes));
mobx.runInAction(mobx.action('save success', function () {
_this.set(data);

@@ -482,3 +497,3 @@ _this.commitChanges();

}
});
}));
})

@@ -562,3 +577,3 @@ .catch(function (error) {

var applyPatchChanges = function (oldAttributes, changes) {
return deepmerge(oldAttributes, changes, {
return deepmerge__default['default'](oldAttributes, changes, {
arrayMerge: dontMergeArrays

@@ -568,4 +583,4 @@ });

var getChangedAttributesBetween = function (source, target) {
var keys = union(Object.keys(source), Object.keys(target));
return keys.filter(function (key) { return !isEqual(source[key], target[key]); });
var keys = union__default['default'](Object.keys(source), Object.keys(target));
return keys.filter(function (key) { return !isEqual__default['default'](source[key], target[key]); });
};

@@ -575,3 +590,3 @@ var getChangesBetween = function (source, target) {

getChangedAttributesBetween(source, target).forEach(function (key) {
changes[key] = isPlainObject(source[key]) && isPlainObject(target[key])
changes[key] = isPlainObject__default['default'](source[key]) && isPlainObject__default['default'](target[key])
? getChangesBetween(source[key], target[key])

@@ -608,3 +623,3 @@ : target[key];

},
enumerable: true,
enumerable: false,
configurable: true

@@ -628,3 +643,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -655,3 +670,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -666,3 +681,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -709,3 +724,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -718,5 +733,5 @@ });

get: function () {
return compact(Array.from(this.index.get(this.primaryKey).keys()));
return compact__default['default'](Array.from(this.index.get(this.primaryKey).keys()));
},
enumerable: true,
enumerable: false,
configurable: true

@@ -755,3 +770,3 @@ });

// Sort the query to hit the indexes first
var optimizedQuery = entries(query).sort(function (A, B) {
var optimizedQuery = entries__default['default'](query).sort(function (A, B) {
return Number(_this.index.has(B[0])) - Number(_this.index.has(A[0]));

@@ -764,3 +779,3 @@ });

var newValues = _this.index.get(attr).get(value) || [];
return values ? intersection(values, newValues) : newValues;
return values ? intersection__default['default'](values, newValues) : newValues;
}

@@ -803,7 +818,7 @@ else {

Collection.prototype.add = function (data) {
var _a;
var _this = this;
var _a;
if (!Array.isArray(data))
data = [data];
var models = difference(data.map(function (m) { return _this.build(m); }), this.models);
var models = difference__default['default'](data.map(function (m) { return _this.build(m); }), this.models);
(_a = this.models).push.apply(_a, models);

@@ -851,3 +866,3 @@ return models;

var getPrimaryKey = function (resource) { return getAttribute(resource, _this.primaryKey); };
var idsToRemove = difference(this._ids, resources.map(getPrimaryKey));
var idsToRemove = difference__default['default'](this._ids, resources.map(getPrimaryKey));
var resourcesToAdd = [];

@@ -854,0 +869,0 @@ resources.forEach(function (resource) {

{
"name": "mobx-rest",
"version": "7.1.1",
"version": "8.0.0",
"description": "REST conventions for mobx.",

@@ -20,20 +20,20 @@ "jest": {

"peerDependencies": {
"mobx": "5.9.4"
"mobx": "^6.0.2"
},
"devDependencies": {
"@types/jest": "24.0.13",
"@typescript-eslint/eslint-plugin": "1.9.0",
"@typescript-eslint/parser": "1.9.0",
"@types/jest": "26.0.15",
"@typescript-eslint/eslint-plugin": "4.6.1",
"@typescript-eslint/parser": "4.6.1",
"benchmark": "2.1.4",
"eslint": "5.16.0",
"husky": "0.13.4",
"jest": "24.8.0",
"lint-staged": "3.6.0",
"rimraf": "2.6.1",
"rollup": "1.12.1",
"eslint": "7.12.1",
"husky": "4.3.0",
"jest": "26.6.2",
"lint-staged": "10.5.1",
"rimraf": "3.0.2",
"rollup": "2.33.1",
"rollup-plugin-node-resolve": "5.0.0",
"rollup-plugin-typescript2": "^0.21.1",
"ts-jest": "24.0.2",
"tslib": "1.9.3",
"typescript": "3.4.5"
"rollup-plugin-typescript2": "^0.29.0",
"ts-jest": "26.4.3",
"tslib": "2.0.3",
"typescript": "4.0.5"
},

@@ -60,7 +60,7 @@ "main": "lib",

"dependencies": {
"@types/lodash": "4.14.136",
"deepmerge": "3.2.0",
"lodash": "4.17.19",
"mobx": "5.9.4"
"@types/lodash": "4.14.164",
"deepmerge": "4.2.2",
"lodash": "4.17.20",
"mobx": "^6.0.2"
}
}
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