apollo-utilities
Advanced tools
Comparing version 1.0.25 to 1.1.0-alpha.1
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fast-json-stable-stringify')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'fast-json-stable-stringify'], factory) : | ||
(factory((global.apollo = global.apollo || {}, global.apollo.utilities = {}),global.stringify)); | ||
}(this, (function (exports,stringify) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fast-json-stable-stringify'), require('fclone')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'fast-json-stable-stringify', 'fclone'], factory) : | ||
(factory((global.apollo = global.apollo || {}, global.apollo.utilities = {}),global.stringify,global.fclone)); | ||
}(this, (function (exports,stringify,fclone) { 'use strict'; | ||
stringify = stringify && stringify.hasOwnProperty('default') ? stringify['default'] : stringify; | ||
fclone = fclone && fclone.hasOwnProperty('default') ? fclone['default'] : fclone; | ||
@@ -183,5 +184,3 @@ var __assign = (undefined && undefined.__assign) || function () { | ||
function isIdValue(idObject) { | ||
return idObject && | ||
idObject.type === 'id' && | ||
typeof idObject.generated === 'boolean'; | ||
return idObject && idObject.type === 'id'; | ||
} | ||
@@ -505,32 +504,5 @@ function toIdValue(idConfig, generated) { | ||
var toString = Object.prototype.toString; | ||
function cloneDeep(value) { | ||
return cloneDeepHelper(value, new Map()); | ||
return fclone(value); | ||
} | ||
function cloneDeepHelper(val, seen) { | ||
switch (toString.call(val)) { | ||
case "[object Array]": { | ||
if (seen.has(val)) | ||
return seen.get(val); | ||
var copy_1 = val.slice(0); | ||
seen.set(val, copy_1); | ||
copy_1.forEach(function (child, i) { | ||
copy_1[i] = cloneDeepHelper(child, seen); | ||
}); | ||
return copy_1; | ||
} | ||
case "[object Object]": { | ||
if (seen.has(val)) | ||
return seen.get(val); | ||
var copy_2 = Object.create(Object.getPrototypeOf(val)); | ||
seen.set(val, copy_2); | ||
Object.keys(val).forEach(function (key) { | ||
copy_2[key] = cloneDeepHelper(val[key], seen); | ||
}); | ||
return copy_2; | ||
} | ||
default: | ||
return val; | ||
} | ||
} | ||
@@ -766,4 +738,3 @@ var TYPENAME_FIELD = { | ||
for (var key in b) { | ||
if (Object.prototype.hasOwnProperty.call(b, key) && | ||
!Object.prototype.hasOwnProperty.call(a, key)) { | ||
if (!Object.prototype.hasOwnProperty.call(a, key)) { | ||
return false; | ||
@@ -822,2 +793,26 @@ } | ||
function isObject(item) { | ||
return item && typeof item === 'object' && !Array.isArray(item); | ||
} | ||
function mergeDeep(target, source) { | ||
var output = Object.assign({}, target); | ||
if (isObject(target) && isObject(source)) { | ||
Object.keys(source).forEach(function (key) { | ||
var _a, _b; | ||
if (isObject(source[key])) { | ||
if (!(key in target)) { | ||
Object.assign(output, (_a = {}, _a[key] = source[key], _a)); | ||
} | ||
else { | ||
output[key] = mergeDeep(target[key], source[key]); | ||
} | ||
} | ||
else { | ||
Object.assign(output, (_b = {}, _b[key] = source[key], _b)); | ||
} | ||
}); | ||
} | ||
return output; | ||
} | ||
exports.getDirectiveInfoFromField = getDirectiveInfoFromField; | ||
@@ -871,2 +866,3 @@ exports.shouldInclude = shouldInclude; | ||
exports.stripSymbols = stripSymbols; | ||
exports.mergeDeep = mergeDeep; | ||
@@ -873,0 +869,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -14,2 +14,3 @@ export * from './directives'; | ||
export * from './util/stripSymbols'; | ||
export * from './util/mergeDeep'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -14,2 +14,3 @@ export * from './directives'; | ||
export * from './util/stripSymbols'; | ||
export * from './util/mergeDeep'; | ||
//# sourceMappingURL=index.js.map |
@@ -176,5 +176,3 @@ var __assign = (this && this.__assign) || function () { | ||
export function isIdValue(idObject) { | ||
return idObject && | ||
idObject.type === 'id' && | ||
typeof idObject.generated === 'boolean'; | ||
return idObject && idObject.type === 'id'; | ||
} | ||
@@ -181,0 +179,0 @@ export function toIdValue(idConfig, generated) { |
@@ -1,31 +0,5 @@ | ||
var toString = Object.prototype.toString; | ||
import fclone from 'fclone'; | ||
export function cloneDeep(value) { | ||
return cloneDeepHelper(value, new Map()); | ||
return fclone(value); | ||
} | ||
function cloneDeepHelper(val, seen) { | ||
switch (toString.call(val)) { | ||
case "[object Array]": { | ||
if (seen.has(val)) | ||
return seen.get(val); | ||
var copy_1 = val.slice(0); | ||
seen.set(val, copy_1); | ||
copy_1.forEach(function (child, i) { | ||
copy_1[i] = cloneDeepHelper(child, seen); | ||
}); | ||
return copy_1; | ||
} | ||
case "[object Object]": { | ||
if (seen.has(val)) | ||
return seen.get(val); | ||
var copy_2 = Object.create(Object.getPrototypeOf(val)); | ||
seen.set(val, copy_2); | ||
Object.keys(val).forEach(function (key) { | ||
copy_2[key] = cloneDeepHelper(val[key], seen); | ||
}); | ||
return copy_2; | ||
} | ||
default: | ||
return val; | ||
} | ||
} | ||
//# sourceMappingURL=cloneDeep.js.map |
@@ -23,4 +23,3 @@ export function isEqual(a, b) { | ||
for (var key in b) { | ||
if (Object.prototype.hasOwnProperty.call(b, key) && | ||
!Object.prototype.hasOwnProperty.call(a, key)) { | ||
if (!Object.prototype.hasOwnProperty.call(a, key)) { | ||
return false; | ||
@@ -27,0 +26,0 @@ } |
{ | ||
"name": "apollo-utilities", | ||
"version": "1.0.25", | ||
"version": "1.1.0-alpha.1", | ||
"description": "Utilities for working with GraphQL ASTs", | ||
@@ -42,3 +42,4 @@ "author": "James Baxley <james@meteor.com>", | ||
"dependencies": { | ||
"fast-json-stable-stringify": "^2.0.0" | ||
"fast-json-stable-stringify": "^2.0.0", | ||
"fclone": "^1.0.11" | ||
}, | ||
@@ -58,3 +59,3 @@ "jest": { | ||
}, | ||
"gitHead": "31b0ee4a027c60394cf9297df8f9eeeda3918272" | ||
"gitHead": "cc787f8f294943fe1f1b8de427ed9a70725744f6" | ||
} |
@@ -14,1 +14,2 @@ export * from './directives'; | ||
export * from './util/stripSymbols'; | ||
export * from './util/mergeDeep'; |
@@ -274,5 +274,3 @@ import { | ||
export function isIdValue(idObject: StoreValue): idObject is IdValue { | ||
return idObject && | ||
(idObject as IdValue | JsonValue).type === 'id' && | ||
typeof (idObject as IdValue).generated === 'boolean'; | ||
return idObject && (idObject as IdValue | JsonValue).type === 'id'; | ||
} | ||
@@ -279,0 +277,0 @@ |
@@ -10,2 +10,3 @@ import { | ||
FragmentDefinitionNode, | ||
ExecutableDefinitionNode, | ||
} from 'graphql'; | ||
@@ -157,7 +158,6 @@ | ||
const docClone = cloneDeep(doc); | ||
docClone.definitions.forEach((definition: DefinitionNode) => { | ||
docClone.definitions.forEach((definition: ExecutableDefinitionNode) => { | ||
removeDirectivesFromSelectionSet( | ||
directives, | ||
(definition as OperationDefinitionNode).selectionSet, | ||
(definition as ExecutableDefinitionNode).selectionSet, | ||
); | ||
@@ -164,0 +164,0 @@ }); |
@@ -86,9 +86,2 @@ import { isEqual } from '../isEqual'; | ||
}); | ||
it('should correctly handle modified prototypes', () => { | ||
Array.prototype.foo = null; | ||
expect(isEqual([1, 2, 3], [1, 2, 3])).toBe(true); | ||
expect(!isEqual([1, 2, 3], [1, 2, 4])).toBe(true); | ||
delete Array.prototype.foo; | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
const { toString } = Object.prototype; | ||
import fclone from 'fclone'; | ||
@@ -7,32 +7,3 @@ /** | ||
export function cloneDeep<T>(value: T): T { | ||
return cloneDeepHelper(value, new Map()); | ||
return fclone(value); | ||
} | ||
function cloneDeepHelper<T>(val: T, seen: Map<any, any>): T { | ||
switch (toString.call(val)) { | ||
case "[object Array]": { | ||
if (seen.has(val)) return seen.get(val); | ||
const copy: T & any[] = (val as any).slice(0); | ||
seen.set(val, copy); | ||
copy.forEach(function (child, i) { | ||
copy[i] = cloneDeepHelper(child, seen); | ||
}); | ||
return copy; | ||
} | ||
case "[object Object]": { | ||
if (seen.has(val)) return seen.get(val); | ||
// High fidelity polyfills of Object.create and Object.getPrototypeOf are | ||
// possible in all JS environments, so we will assume they exist/work. | ||
const copy = Object.create(Object.getPrototypeOf(val)); | ||
seen.set(val, copy); | ||
Object.keys(val).forEach(key => { | ||
copy[key] = cloneDeepHelper((val as any)[key], seen); | ||
}); | ||
return copy; | ||
} | ||
default: | ||
return val; | ||
} | ||
} |
@@ -35,6 +35,3 @@ /** | ||
for (const key in b) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(b, key) && | ||
!Object.prototype.hasOwnProperty.call(a, key) | ||
) { | ||
if (!Object.prototype.hasOwnProperty.call(a, key)) { | ||
return false; | ||
@@ -41,0 +38,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
95
276329
2
5006
1
+ Addedfclone@^1.0.11
+ Addedfclone@1.0.11(transitive)