mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
Replaced with lodash cloneDeep and fixed #177
This commit is contained in:
parent
669b954acb
commit
83bf0460d7
15 changed files with 65 additions and 118 deletions
40
.npm/package/npm-shrinkwrap.json
generated
40
.npm/package/npm-shrinkwrap.json
generated
|
@ -2,19 +2,19 @@
|
|||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"balanced-match": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz",
|
||||
"integrity": "sha1-yz8+PHMtwPAe5wtAPzAuYddwmDg="
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.6.tgz",
|
||||
"integrity": "sha1-cZfX6qm4fmSDkOph/GbIRCdCDfk="
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI="
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
|
||||
"integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q="
|
||||
"version": "2.12.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.12.1.tgz",
|
||||
"integrity": "sha512-PCNLExLlI5HiPdaJs4pMXwOTHkSCpNQ1QJH9ykZLKtKEyKu3p9HgmH5l97vM8c0IUz6d54l+xEu2GG9yuYrFzA=="
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
|
@ -32,14 +32,9 @@
|
|||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
|
||||
"integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg="
|
||||
},
|
||||
"graceful-readlink": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
|
||||
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU="
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ=="
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
|
@ -51,10 +46,15 @@
|
|||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.3.tgz",
|
||||
"integrity": "sha1-Kk5AkLlrLbBqnX3wEFWmKnfJt3Q="
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { linkStorage } from '../links/symbols.js';
|
||||
import NamedQueryStore from '../namedQuery/store';
|
||||
import deepClone from '../query/lib/deepClone.js';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
export default function extract() {
|
||||
return {
|
||||
|
|
|
@ -5,7 +5,7 @@ import ExposureConfigSchema from './exposure.config.schema.js';
|
|||
import enforceMaxDepth from './lib/enforceMaxDepth.js';
|
||||
import enforceMaxLimit from './lib/enforceMaxLimit.js';
|
||||
import cleanBody from './lib/cleanBody.js';
|
||||
import deepClone from '../query/lib/deepClone';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
import restrictFieldsFn from './lib/restrictFields.js';
|
||||
import restrictLinks from './lib/restrictLinks.js';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import deepClone from '../../query/lib/deepClone';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
import {cleanFilters, cleanOptions} from './cleanSelectors';
|
||||
import dotize from '../../query/lib/dotize';
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import mergeDeep from './lib/mergeDeep.js';
|
|||
import createGraph from '../../query/lib/createGraph.js';
|
||||
import recursiveCompose from '../../query/lib/recursiveCompose.js';
|
||||
import prepareForProcess from '../../query/lib/prepareForProcess.js';
|
||||
import deepClone from '../../query/lib/deepClone.js';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
_.extend(NamedQuery.prototype, {
|
||||
expose(config = {}) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import deepClone from '../query/lib/deepClone.js';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
export default class NamedQueryBase {
|
||||
constructor(name, collection, body, params = {}) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import prepareForProcess from '../query/lib/prepareForProcess.js';
|
||||
import deepClone from '../query/lib/deepClone.js';
|
||||
import Base from './namedQuery.base';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
export default class extends Base {
|
||||
/**
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
function deepCloneArray(array) {
|
||||
return _.map(array, value => {
|
||||
if (_.isArray(value)) {
|
||||
return deepCloneArray(value);
|
||||
} else if (_.isFunction(value)) {
|
||||
return value;
|
||||
} else if (_.isObject(value)) {
|
||||
return deepClone(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
}
|
||||
|
||||
export default function deepClone(object) {
|
||||
let clone = {};
|
||||
|
||||
_.each(object, (value, key) => {
|
||||
if (_.isArray(value)) {
|
||||
clone[key] = deepCloneArray(value);
|
||||
} else if (_.isFunction(value)) {
|
||||
clone[key] = value;
|
||||
} else if (_.isRegExp(value)) {
|
||||
clone[key] = value;
|
||||
} else if (_.isDate(value)) {
|
||||
clone[key] = value;
|
||||
} else if (_.isObject(value)) {
|
||||
clone[key] = deepClone(value);
|
||||
} else {
|
||||
clone[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return clone;
|
||||
}
|
|
@ -1,6 +1,23 @@
|
|||
import deepClone from './deepClone.js';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
function defaultFilterFunction({
|
||||
filters,
|
||||
options,
|
||||
params
|
||||
}) {
|
||||
if (params.filters) {
|
||||
Object.assign(filters, params.filters);
|
||||
}
|
||||
if (params.options) {
|
||||
Object.assign(options, params.options);
|
||||
}
|
||||
}
|
||||
|
||||
function applyFilterRecursive(data, params = {}, isRoot = false) {
|
||||
if (isRoot && !_.isFunction(data.$filter)) {
|
||||
data.$filter = defaultFilterFunction;
|
||||
}
|
||||
|
||||
function applyFilterRecursive(data, params = {}) {
|
||||
if (_.isFunction(data.$filter)) {
|
||||
data.$filters = data.$filters || {};
|
||||
data.$options = data.$options || {};
|
||||
|
@ -49,7 +66,7 @@ export default (_body, _params = {}) => {
|
|||
let params = deepClone(_params);
|
||||
|
||||
applyPagination(body, params);
|
||||
applyFilterRecursive(body, params);
|
||||
applyFilterRecursive(body, params, true);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import FieldNode from './fieldNode.js';
|
||||
import ReducerNode from './reducerNode.js';
|
||||
import deepClone from '../lib/deepClone';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
export default class CollectionNode {
|
||||
constructor(collection, body = {}, linkName = null) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import deepClone from './lib/deepClone.js';
|
||||
import deepClone from 'lodash.cloneDeep';
|
||||
|
||||
export default class QueryBase {
|
||||
constructor(collection, body, params = {}) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { createQuery } from 'meteor/cultofcoders:grapher';
|
||||
import './units/deepClone';
|
||||
import './reducers.client.test';
|
||||
import './security.client.test';
|
||||
import waitForHandleToBeReady from './lib/waitForHandleToBeReady';
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { createQuery } from 'meteor/cultofcoders:grapher';
|
||||
import Comments from './bootstrap/comments/collection.js';
|
||||
import './units/deepClone';
|
||||
import './metaFilters.server.test';
|
||||
import './reducers.server.test';
|
||||
|
||||
|
@ -465,5 +464,21 @@ describe('Hypernova', function () {
|
|||
assert.isObject(author.profile);
|
||||
assert.isString(author.profile.firstName);
|
||||
assert.isUndefined(author.profile.lastName);
|
||||
});
|
||||
|
||||
it('Should apply a default filter function to first root', function () {
|
||||
let query = createQuery({
|
||||
groups: {
|
||||
authors: {}
|
||||
}
|
||||
}, {
|
||||
options: {limit: 1}
|
||||
});
|
||||
|
||||
const data = query.fetch();
|
||||
assert.lengthOf(data, 1);
|
||||
const group = data[0];
|
||||
assert.isArray(group.authors);
|
||||
assert.isTrue(group.authors.length > 1);
|
||||
})
|
||||
});
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
import deepClone from '../../lib/deepClone';
|
||||
|
||||
describe('Test deepClone function', function () {
|
||||
it('should clone a simple object', function () {
|
||||
let myObject = {
|
||||
a: 1,
|
||||
b: 2,
|
||||
c: {
|
||||
c1: 1,
|
||||
c2: 2,
|
||||
c3: {
|
||||
c31: 1,
|
||||
c32: 2
|
||||
}
|
||||
},
|
||||
d: [
|
||||
{
|
||||
d1: 1,
|
||||
d2: 2
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const runAssertions = (object) => {
|
||||
assert.equal(object.a, 1);
|
||||
assert.equal(object.b, 2);
|
||||
assert.equal(object.c.c1, 1);
|
||||
assert.equal(object.c.c2, 2);
|
||||
assert.equal(object.c.c3.c31, 1);
|
||||
assert.equal(object.c.c3.c32, 2);
|
||||
assert.equal(object.d[0].d1, 1);
|
||||
assert.equal(object.d[0].d2, 2);
|
||||
};
|
||||
|
||||
let clone = deepClone(myObject);
|
||||
|
||||
runAssertions(clone);
|
||||
|
||||
clone.a = 2;
|
||||
clone.b = 3;
|
||||
clone.c.c1 = 2;
|
||||
clone.c.c2 = 3;
|
||||
clone.c.c3.c31 = 2;
|
||||
clone.c.c3.c32 = 3;
|
||||
clone.d[0].d1 = 2;
|
||||
clone.d[0].d2 = 3;
|
||||
|
||||
runAssertions(myObject);
|
||||
})
|
||||
});
|
|
@ -13,6 +13,7 @@ Package.describe({
|
|||
Npm.depends({
|
||||
'sift': '3.2.6',
|
||||
'dot-object': '1.5.4',
|
||||
'lodash.clonedeep': '4.5.0',
|
||||
});
|
||||
|
||||
Package.onUse(function (api) {
|
||||
|
|
Loading…
Add table
Reference in a new issue