Socket
Socket
Sign inDemoInstall

apollo-cache-inmemory

Package Overview
Dependencies
Maintainers
4
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache-inmemory - npm Package Compare versions

Comparing version 1.6.0-beta.4 to 1.6.0-beta.5

7

lib/bundle.cjs.js

@@ -77,7 +77,4 @@ 'use strict';

var obj = context.store.get(idValue.id);
if (!obj && idValue.id === 'ROOT_QUERY') {
return true;
}
if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -122,3 +119,3 @@ if (!obj.__typename) {

if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -125,0 +122,0 @@ process.env.NODE_ENV === "production" ? tsInvariant.invariant(obj.__typename, 11) : tsInvariant.invariant(obj.__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("apollo-cache"),r=require("apollo-utilities"),a=require("optimism"),i=require("ts-invariant"),n=new Map;if(n.set(1,2)!==n){var o=n.set;Map.prototype.set=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o.apply(this,e),this}}var s=new Set;if(s.add(3)!==s){var c=s.add;Set.prototype.add=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return c.apply(this,e),this}}var u={};"function"==typeof Object.freeze&&Object.freeze(u);try{n.set(u,u).delete(u)}catch(e){var l=function(e){return e&&function(t){try{n.set(t,t).delete(t)}finally{return e.call(Object,t)}}};Object.freeze=l(Object.freeze),Object.seal=l(Object.seal),Object.preventExtensions=l(Object.preventExtensions)}var d=!1;function f(){var e=!d;return r.isTest()||(d=!0),e}var p=function(){function e(){}return e.prototype.ensureReady=function(){return Promise.resolve()},e.prototype.canBypassInit=function(){return!0},e.prototype.match=function(e,t,r){var a=r.store.get(e.id);return!a&&"ROOT_QUERY"===e.id||!!a&&(a.__typename&&a.__typename===t||(f(),"heuristic"))},e}(),h=function(){function e(e){e&&e.introspectionQueryResultData?(this.possibleTypesMap=this.parseIntrospectionResult(e.introspectionQueryResultData),this.isReady=!0):this.isReady=!1,this.match=this.match.bind(this)}return e.prototype.match=function(e,t,r){i.invariant(this.isReady,10);var a=r.store.get(e.id);if(!a)return!1;if(i.invariant(a.__typename,11),a.__typename===t)return!0;var n=this.possibleTypesMap[t];return!!(n&&n.indexOf(a.__typename)>-1)},e.prototype.parseIntrospectionResult=function(e){var t={};return e.__schema.types.forEach(function(e){"UNION"!==e.kind&&"INTERFACE"!==e.kind||(t[e.name]=e.possibleTypes.map(function(e){return e.name}))}),t},e}(),y=Object.prototype.hasOwnProperty,m=function(){function e(e){void 0===e&&(e=Object.create(null));var t=this;this.data=e,this.depend=a.wrap(function(e){return t.data[e]},{disposable:!0,makeCacheKey:function(e){return e}})}return e.prototype.toObject=function(){return this.data},e.prototype.get=function(e){return this.depend(e),this.data[e]},e.prototype.set=function(e,t){t!==this.data[e]&&(this.data[e]=t,this.depend.dirty(e))},e.prototype.delete=function(e){y.call(this.data,e)&&(delete this.data[e],this.depend.dirty(e))},e.prototype.clear=function(){this.replace(null)},e.prototype.replace=function(e){var t=this;e?(Object.keys(e).forEach(function(r){t.set(r,e[r])}),Object.keys(this.data).forEach(function(r){y.call(e,r)||t.delete(r)})):Object.keys(this.data).forEach(function(e){t.delete(e)})},e}();function v(e){return new m(e)}var g=function(){function t(e){var t=void 0===e?{}:e,i=t.cacheKeyRoot,n=void 0===i?new a.KeyTrie(r.canUseWeakMap):i,o=t.freezeResults,s=void 0!==o&&o,c=this,u=this.executeStoreQuery,l=this.executeSelectionSet,d=this.executeSubSelectedArray;this.freezeResults=s,this.executeStoreQuery=a.wrap(function(e){return u.call(c,e)},{makeCacheKey:function(e){var t=e.query,r=e.rootValue,a=e.contextValue,i=e.variableValues,o=e.fragmentMatcher;if(a.store instanceof m)return n.lookup(a.store,t,o,JSON.stringify(i),r.id)}}),this.executeSelectionSet=a.wrap(function(e){return l.call(c,e)},{makeCacheKey:function(e){var t=e.selectionSet,r=e.rootValue,a=e.execContext;if(a.contextValue.store instanceof m)return n.lookup(a.contextValue.store,t,a.fragmentMatcher,JSON.stringify(a.variableValues),r.id)}}),this.executeSubSelectedArray=a.wrap(function(e){return d.call(c,e)},{makeCacheKey:function(e){var t=e.field,r=e.array,a=e.execContext;if(a.contextValue.store instanceof m)return n.lookup(a.contextValue.store,t,r,JSON.stringify(a.variableValues))}})}return t.prototype.readQueryFromStore=function(t){return this.diffQueryAgainstStore(e.__assign({},t,{returnPartialData:!1})).result},t.prototype.diffQueryAgainstStore=function(e){var t=e.store,a=e.query,n=e.variables,o=e.previousResult,s=e.returnPartialData,c=void 0===s||s,u=e.rootId,l=void 0===u?"ROOT_QUERY":u,d=e.fragmentMatcherFunction,f=e.config,p=r.getQueryDefinition(a);n=r.assign({},r.getDefaultValues(p),n);var h={store:t,dataIdFromObject:f&&f.dataIdFromObject||null,cacheRedirects:f&&f.cacheRedirects||{}},y=this.executeStoreQuery({query:a,rootValue:{type:"id",id:l,generated:!0,typename:"Query"},contextValue:h,variableValues:n,fragmentMatcher:d}),m=y.missing&&y.missing.length>0;return m&&!c&&y.missing.forEach(function(e){if(!e.tolerable)throw new i.InvariantError(2)}),o&&r.isEqual(o,y.result)&&(y.result=o),{result:y.result,complete:!m}},t.prototype.executeStoreQuery=function(e){var t=e.query,a=e.rootValue,i=e.contextValue,n=e.variableValues,o=e.fragmentMatcher,s=void 0===o?S:o,c=r.getMainDefinition(t),u=r.getFragmentDefinitions(t),l={query:t,fragmentMap:r.createFragmentMap(u),contextValue:i,variableValues:n,fragmentMatcher:s};return this.executeSelectionSet({selectionSet:c.selectionSet,rootValue:a,execContext:l})},t.prototype.executeSelectionSet=function(t){var a=this,n=t.selectionSet,o=t.rootValue,s=t.execContext,c=s.fragmentMap,u=s.contextValue,l=s.variableValues,d={result:null},f=[],p=u.store.get(o.id),h=p&&p.__typename||"ROOT_QUERY"===o.id&&"Query"||void 0;function y(e){var t;return e.missing&&(d.missing=d.missing||[],(t=d.missing).push.apply(t,e.missing)),e.result}return n.selections.forEach(function(t){var n;if(r.shouldInclude(t,l))if(r.isField(t)){var d=y(a.executeField(p,h,t,s));void 0!==d&&f.push(((n={})[r.resultKeyNameFromField(t)]=d,n))}else{var m=void 0;if(r.isInlineFragment(t))m=t;else if(!(m=c[t.name.value]))throw new i.InvariantError(3);var v=m.typeCondition.name.value,g=s.fragmentMatcher(o,v,u);if(g){var b=a.executeSelectionSet({selectionSet:m.selectionSet,rootValue:o,execContext:s});"heuristic"===g&&b.missing&&(b=e.__assign({},b,{missing:b.missing.map(function(t){return e.__assign({},t,{tolerable:!0})})})),f.push(y(b))}}}),d.result=r.mergeDeepArray(f),this.freezeResults,d},t.prototype.executeField=function(e,t,a,i){var n=i.variableValues,o=i.contextValue,s=O(e,t,a.name.value,r.argumentsObjectFromField(a,n),o,{resultKey:r.resultKeyNameFromField(a),directives:r.getDirectiveInfoFromField(a,n)});return Array.isArray(s.result)?this.combineExecResults(s,this.executeSubSelectedArray({field:a,array:s.result,execContext:i})):a.selectionSet?null==s.result?s:this.combineExecResults(s,this.executeSelectionSet({selectionSet:a.selectionSet,rootValue:s.result,execContext:i})):(b(a,s.result),this.freezeResults,s)},t.prototype.combineExecResults=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=null;return e.forEach(function(e){e.missing&&(r=r||[]).push.apply(r,e.missing)}),{result:e.pop().result,missing:r}},t.prototype.executeSubSelectedArray=function(e){var t=this,r=e.field,a=e.array,i=e.execContext,n=null;function o(e){return e.missing&&(n=n||[]).push.apply(n,e.missing),e.result}return a=a.map(function(e){return null===e?null:Array.isArray(e)?o(t.executeSubSelectedArray({field:r,array:e,execContext:i})):r.selectionSet?o(t.executeSelectionSet({selectionSet:r.selectionSet,rootValue:e,execContext:i})):(b(r,e),e)}),this.freezeResults,{result:a,missing:n}},t}();function b(e,t){if(!e.selectionSet&&r.isIdValue(t))throw new i.InvariantError(4)}function S(){return!0}function x(e){i.invariant(r.isIdValue(e),5)}function O(e,t,a,i,n,o){o.resultKey;var s=o.directives,c=a;(i||s)&&(c=r.getStoreKeyName(c,i,s));var u=void 0;if(e&&void 0===(u=e[c])&&n.cacheRedirects&&"string"==typeof t){var l=n.cacheRedirects[t];if(l){var d=l[a];d&&(u=d(e,i,{getCacheKey:function(e){return r.toIdValue({id:n.dataIdFromObject(e),typename:e.__typename})}}))}}return void 0===u?{result:u,missing:[{object:e,fieldName:c,tolerable:!1}]}:(r.isJsonValue(u)&&(u=u.json),{result:u})}var R=function(){function e(e){void 0===e&&(e=Object.create(null)),this.data=e}return e.prototype.toObject=function(){return this.data},e.prototype.get=function(e){return this.data[e]},e.prototype.set=function(e,t){this.data[e]=t},e.prototype.delete=function(e){this.data[e]=void 0},e.prototype.clear=function(){this.data=Object.create(null)},e.prototype.replace=function(e){this.data=e||Object.create(null)},e}();function I(e){return new R(e)}var F=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="WriteError",e}return e.__extends(r,t),r}(Error);function _(e,t){var r=new F("Error writing result to store for query:\n "+JSON.stringify(t));return r.message+="\n"+e.message,r.stack=e.stack,r}var w=function(){function t(){}return t.prototype.writeQueryToStore=function(e){var t=e.query,r=e.result,a=e.store,i=void 0===a?v():a,n=e.variables,o=e.dataIdFromObject,s=e.fragmentMatcherFunction;return this.writeResultToStore({dataId:"ROOT_QUERY",result:r,document:t,store:i,variables:n,dataIdFromObject:o,fragmentMatcherFunction:s})},t.prototype.writeResultToStore=function(e){var t=e.dataId,a=e.result,i=e.document,n=e.store,o=void 0===n?v():n,s=e.variables,c=e.dataIdFromObject,u=e.fragmentMatcherFunction,l=r.getOperationDefinition(i);try{return this.writeSelectionSetToStore({result:a,dataId:t,selectionSet:l.selectionSet,context:{store:o,processedData:{},variables:r.assign({},r.getDefaultValues(l),s),dataIdFromObject:c,fragmentMap:r.createFragmentMap(r.getFragmentDefinitions(i)),fragmentMatcherFunction:u}})}catch(e){throw _(e,i)}},t.prototype.writeSelectionSetToStore=function(e){var t=this,a=e.result,n=e.dataId,o=e.selectionSet,s=e.context,c=s.variables,u=s.store,l=s.fragmentMap;return o.selections.forEach(function(e){if(r.shouldInclude(e,c))if(r.isField(e)){var o=r.resultKeyNameFromField(e),u=a[o];if(void 0!==u)t.writeFieldToStore({dataId:n,value:u,field:e,context:s});else{var d=!1,f=!1;e.directives&&e.directives.length&&(d=e.directives.some(function(e){return e.name&&"defer"===e.name.value}),f=e.directives.some(function(e){return e.name&&"client"===e.name.value})),!d&&!f&&s.fragmentMatcherFunction}}else{var p=void 0;r.isInlineFragment(e)?p=e:(p=(l||{})[e.name.value],i.invariant(p,6));var h=!0;if(s.fragmentMatcherFunction&&p.typeCondition){var y=r.toIdValue({id:"self",typename:void 0}),m={store:new R({self:a}),cacheRedirects:{}},v=s.fragmentMatcherFunction(y,p.typeCondition.name.value,m);r.isProduction(),h=!!v}h&&t.writeSelectionSetToStore({result:a,selectionSet:p.selectionSet,dataId:n,context:s})}}),u},t.prototype.writeFieldToStore=function(t){var a,n,o,s=t.field,c=t.value,u=t.dataId,l=t.context,d=l.variables,f=l.dataIdFromObject,p=l.store,h=r.storeKeyNameFromField(s,d);if(s.selectionSet&&null!==c)if(Array.isArray(c)){var y=u+"."+h;n=this.processArrayValue(c,y,s.selectionSet,l)}else{var m=u+"."+h,v=!0;if(j(m)||(m="$"+m),f){var g=f(c);i.invariant(!g||!j(g),7),(g||"number"==typeof g&&0===g)&&(m=g,v=!1)}M(m,s,l.processedData)||this.writeSelectionSetToStore({dataId:m,result:c,selectionSet:s.selectionSet,context:l});var b=c.__typename;n=r.toIdValue({id:m,typename:b},v);var S=(o=p.get(u))&&o[h];if(S!==n&&r.isIdValue(S)){var x=void 0!==S.typename,O=void 0!==b,R=x&&O&&S.typename!==b;i.invariant(!v||S.generated||R,8),i.invariant(!x||O,9),S.generated&&(R?v||p.delete(S.id):V(S.id,n.id,p))}}else n=null!=c&&"object"==typeof c?{type:"json",json:c}:c;(o=p.get(u))&&r.isEqual(n,o[h])||p.set(u,e.__assign({},o,((a={})[h]=n,a)))},t.prototype.processArrayValue=function(e,t,a,i){var n=this;return e.map(function(e,o){if(null===e)return null;var s=t+"."+o;if(Array.isArray(e))return n.processArrayValue(e,s,a,i);var c=!0;if(i.dataIdFromObject){var u=i.dataIdFromObject(e);u&&(s=u,c=!1)}return M(s,a,i.processedData)||n.writeSelectionSetToStore({dataId:s,result:e,selectionSet:a,context:i}),r.toIdValue({id:s,typename:e.__typename},c)})},t}();function j(e){return"$"===e[0]}function V(t,a,i){if(t===a)return!1;var n=i.get(t),o=i.get(a),s=!1;Object.keys(n).forEach(function(e){var t=n[e],a=o[e];r.isIdValue(t)&&j(t.id)&&r.isIdValue(a)&&!r.isEqual(t,a)&&V(t.id,a.id,i)&&(s=!0)}),i.delete(t);var c=e.__assign({},n,o);return r.isEqual(c,o)?s:(i.set(a,c),!0)}function M(e,t,r){if(!r)return!1;if(r[e]){if(r[e].indexOf(t)>=0)return!0;r[e].push(t)}else r[e]=[t];return!1}var D={fragmentMatcher:new p,dataIdFromObject:E,addTypename:!0,resultCaching:!0,freezeResults:!1};function E(e){if(e.__typename){if(void 0!==e.id)return e.__typename+":"+e.id;if(void 0!==e._id)return e.__typename+":"+e._id}return null}var T=Object.prototype.hasOwnProperty,C=function(t){function r(e,r,a){var i=t.call(this,Object.create(null))||this;return i.optimisticId=e,i.parent=r,i.transaction=a,i}return e.__extends(r,t),r.prototype.toObject=function(){return e.__assign({},this.parent.toObject(),this.data)},r.prototype.get=function(e){return T.call(this.data,e)?this.data[e]:this.parent.get(e)},r}(R),q=function(t){function n(i){void 0===i&&(i={});var n=t.call(this)||this;n.watches=new Set,n.typenameDocumentCache=new Map,n.cacheKeyRoot=new a.KeyTrie(r.canUseWeakMap),n.silenceBroadcast=!1,n.config=e.__assign({},D,i),n.config.customResolvers&&(n.config.cacheRedirects=n.config.customResolvers),n.config.cacheResolvers&&(n.config.cacheRedirects=n.config.cacheResolvers),n.addTypename=n.config.addTypename,n.data=n.config.resultCaching?new m:new R,n.optimisticData=n.data,n.storeWriter=new w,n.storeReader=new g({cacheKeyRoot:n.cacheKeyRoot,freezeResults:i.freezeResults});var o=n,s=o.maybeBroadcastWatch;return n.maybeBroadcastWatch=a.wrap(function(e){return s.call(n,e)},{makeCacheKey:function(e){if(!e.optimistic&&!e.previousResult)return o.data instanceof m?o.cacheKeyRoot.lookup(e.query,JSON.stringify(e.variables)):void 0}}),n}return e.__extends(n,t),n.prototype.restore=function(e){return e&&this.data.replace(e),this},n.prototype.extract=function(e){return void 0===e&&(e=!1),(e?this.optimisticData:this.data).toObject()},n.prototype.read=function(e){return"string"==typeof e.rootId&&void 0===this.data.get(e.rootId)?null:this.storeReader.readQueryFromStore({store:e.optimistic?this.optimisticData:this.data,query:this.transformDocument(e.query),variables:e.variables,rootId:e.rootId,fragmentMatcherFunction:this.config.fragmentMatcher.match,previousResult:e.previousResult,config:this.config})},n.prototype.write=function(e){this.storeWriter.writeResultToStore({dataId:e.dataId,result:e.result,variables:e.variables,document:this.transformDocument(e.query),store:this.data,dataIdFromObject:this.config.dataIdFromObject,fragmentMatcherFunction:this.config.fragmentMatcher.match}),this.broadcastWatches()},n.prototype.diff=function(e){return this.storeReader.diffQueryAgainstStore({store:e.optimistic?this.optimisticData:this.data,query:this.transformDocument(e.query),variables:e.variables,returnPartialData:e.returnPartialData,previousResult:e.previousResult,fragmentMatcherFunction:this.config.fragmentMatcher.match,config:this.config})},n.prototype.watch=function(e){var t=this;return this.watches.add(e),function(){t.watches.delete(e)}},n.prototype.evict=function(e){throw new i.InvariantError(1)},n.prototype.reset=function(){return this.data.clear(),this.broadcastWatches(),Promise.resolve()},n.prototype.removeOptimistic=function(e){for(var t=[],r=0,a=this.optimisticData;a instanceof C;)a.optimisticId===e?++r:t.push(a),a=a.parent;if(r>0){for(this.optimisticData=a;t.length>0;){var i=t.pop();this.performTransaction(i.transaction,i.optimisticId)}this.broadcastWatches()}},n.prototype.performTransaction=function(e,t){var r=this.data,a=this.silenceBroadcast;this.silenceBroadcast=!0,"string"==typeof t&&(this.data=this.optimisticData=new C(t,this.optimisticData,e));try{e(this)}finally{this.silenceBroadcast=a,this.data=r}this.broadcastWatches()},n.prototype.recordOptimisticTransaction=function(e,t){return this.performTransaction(e,t)},n.prototype.transformDocument=function(e){if(this.addTypename){var t=this.typenameDocumentCache.get(e);return t||(t=r.addTypenameToDocument(e),this.typenameDocumentCache.set(e,t),this.typenameDocumentCache.set(t,t)),t}return e},n.prototype.broadcastWatches=function(){var e=this;this.silenceBroadcast||this.watches.forEach(function(t){return e.maybeBroadcastWatch(t)})},n.prototype.maybeBroadcastWatch=function(e){e.callback(this.diff({query:e.query,variables:e.variables,previousResult:e.previousResult&&e.previousResult(),optimistic:e.optimistic}))},n}(t.ApolloCache);exports.HeuristicFragmentMatcher=p,exports.InMemoryCache=q,exports.IntrospectionFragmentMatcher=h,exports.ObjectCache=R,exports.StoreReader=g,exports.StoreWriter=w,exports.WriteError=F,exports.assertIdValue=x,exports.defaultDataIdFromObject=E,exports.defaultNormalizedCacheFactory=I,exports.enhanceErrorWithDocument=_;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("apollo-cache"),r=require("apollo-utilities"),i=require("optimism"),a=require("ts-invariant"),n=new Map;if(n.set(1,2)!==n){var o=n.set;Map.prototype.set=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return o.apply(this,e),this}}var s=new Set;if(s.add(3)!==s){var c=s.add;Set.prototype.add=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return c.apply(this,e),this}}var u={};"function"==typeof Object.freeze&&Object.freeze(u);try{n.set(u,u).delete(u)}catch(e){var l=function(e){return e&&function(t){try{n.set(t,t).delete(t)}finally{return e.call(Object,t)}}};Object.freeze=l(Object.freeze),Object.seal=l(Object.seal),Object.preventExtensions=l(Object.preventExtensions)}var d=!1;function f(){var e=!d;return r.isTest()||(d=!0),e}var p=function(){function e(){}return e.prototype.ensureReady=function(){return Promise.resolve()},e.prototype.canBypassInit=function(){return!0},e.prototype.match=function(e,t,r){var i=r.store.get(e.id);return i?i.__typename&&i.__typename===t||(f(),"heuristic"):"ROOT_QUERY"===e.id},e}(),h=function(){function e(e){e&&e.introspectionQueryResultData?(this.possibleTypesMap=this.parseIntrospectionResult(e.introspectionQueryResultData),this.isReady=!0):this.isReady=!1,this.match=this.match.bind(this)}return e.prototype.match=function(e,t,r){a.invariant(this.isReady,10);var i=r.store.get(e.id);if(!i)return"ROOT_QUERY"===e.id;if(a.invariant(i.__typename,11),i.__typename===t)return!0;var n=this.possibleTypesMap[t];return!!(n&&n.indexOf(i.__typename)>-1)},e.prototype.parseIntrospectionResult=function(e){var t={};return e.__schema.types.forEach(function(e){"UNION"!==e.kind&&"INTERFACE"!==e.kind||(t[e.name]=e.possibleTypes.map(function(e){return e.name}))}),t},e}(),y=Object.prototype.hasOwnProperty,m=function(){function e(e){void 0===e&&(e=Object.create(null));var t=this;this.data=e,this.depend=i.wrap(function(e){return t.data[e]},{disposable:!0,makeCacheKey:function(e){return e}})}return e.prototype.toObject=function(){return this.data},e.prototype.get=function(e){return this.depend(e),this.data[e]},e.prototype.set=function(e,t){t!==this.data[e]&&(this.data[e]=t,this.depend.dirty(e))},e.prototype.delete=function(e){y.call(this.data,e)&&(delete this.data[e],this.depend.dirty(e))},e.prototype.clear=function(){this.replace(null)},e.prototype.replace=function(e){var t=this;e?(Object.keys(e).forEach(function(r){t.set(r,e[r])}),Object.keys(this.data).forEach(function(r){y.call(e,r)||t.delete(r)})):Object.keys(this.data).forEach(function(e){t.delete(e)})},e}();function v(e){return new m(e)}var g=function(){function t(e){var t=void 0===e?{}:e,a=t.cacheKeyRoot,n=void 0===a?new i.KeyTrie(r.canUseWeakMap):a,o=t.freezeResults,s=void 0!==o&&o,c=this,u=this.executeStoreQuery,l=this.executeSelectionSet,d=this.executeSubSelectedArray;this.freezeResults=s,this.executeStoreQuery=i.wrap(function(e){return u.call(c,e)},{makeCacheKey:function(e){var t=e.query,r=e.rootValue,i=e.contextValue,a=e.variableValues,o=e.fragmentMatcher;if(i.store instanceof m)return n.lookup(i.store,t,o,JSON.stringify(a),r.id)}}),this.executeSelectionSet=i.wrap(function(e){return l.call(c,e)},{makeCacheKey:function(e){var t=e.selectionSet,r=e.rootValue,i=e.execContext;if(i.contextValue.store instanceof m)return n.lookup(i.contextValue.store,t,i.fragmentMatcher,JSON.stringify(i.variableValues),r.id)}}),this.executeSubSelectedArray=i.wrap(function(e){return d.call(c,e)},{makeCacheKey:function(e){var t=e.field,r=e.array,i=e.execContext;if(i.contextValue.store instanceof m)return n.lookup(i.contextValue.store,t,r,JSON.stringify(i.variableValues))}})}return t.prototype.readQueryFromStore=function(t){return this.diffQueryAgainstStore(e.__assign({},t,{returnPartialData:!1})).result},t.prototype.diffQueryAgainstStore=function(e){var t=e.store,i=e.query,n=e.variables,o=e.previousResult,s=e.returnPartialData,c=void 0===s||s,u=e.rootId,l=void 0===u?"ROOT_QUERY":u,d=e.fragmentMatcherFunction,f=e.config,p=r.getQueryDefinition(i);n=r.assign({},r.getDefaultValues(p),n);var h={store:t,dataIdFromObject:f&&f.dataIdFromObject||null,cacheRedirects:f&&f.cacheRedirects||{}},y=this.executeStoreQuery({query:i,rootValue:{type:"id",id:l,generated:!0,typename:"Query"},contextValue:h,variableValues:n,fragmentMatcher:d}),m=y.missing&&y.missing.length>0;return m&&!c&&y.missing.forEach(function(e){if(!e.tolerable)throw new a.InvariantError(2)}),o&&r.isEqual(o,y.result)&&(y.result=o),{result:y.result,complete:!m}},t.prototype.executeStoreQuery=function(e){var t=e.query,i=e.rootValue,a=e.contextValue,n=e.variableValues,o=e.fragmentMatcher,s=void 0===o?S:o,c=r.getMainDefinition(t),u=r.getFragmentDefinitions(t),l={query:t,fragmentMap:r.createFragmentMap(u),contextValue:a,variableValues:n,fragmentMatcher:s};return this.executeSelectionSet({selectionSet:c.selectionSet,rootValue:i,execContext:l})},t.prototype.executeSelectionSet=function(t){var i=this,n=t.selectionSet,o=t.rootValue,s=t.execContext,c=s.fragmentMap,u=s.contextValue,l=s.variableValues,d={result:null},f=[],p=u.store.get(o.id),h=p&&p.__typename||"ROOT_QUERY"===o.id&&"Query"||void 0;function y(e){var t;return e.missing&&(d.missing=d.missing||[],(t=d.missing).push.apply(t,e.missing)),e.result}return n.selections.forEach(function(t){var n;if(r.shouldInclude(t,l))if(r.isField(t)){var d=y(i.executeField(p,h,t,s));void 0!==d&&f.push(((n={})[r.resultKeyNameFromField(t)]=d,n))}else{var m=void 0;if(r.isInlineFragment(t))m=t;else if(!(m=c[t.name.value]))throw new a.InvariantError(3);var v=m.typeCondition.name.value,g=s.fragmentMatcher(o,v,u);if(g){var b=i.executeSelectionSet({selectionSet:m.selectionSet,rootValue:o,execContext:s});"heuristic"===g&&b.missing&&(b=e.__assign({},b,{missing:b.missing.map(function(t){return e.__assign({},t,{tolerable:!0})})})),f.push(y(b))}}}),d.result=r.mergeDeepArray(f),this.freezeResults,d},t.prototype.executeField=function(e,t,i,a){var n=a.variableValues,o=a.contextValue,s=O(e,t,i.name.value,r.argumentsObjectFromField(i,n),o,{resultKey:r.resultKeyNameFromField(i),directives:r.getDirectiveInfoFromField(i,n)});return Array.isArray(s.result)?this.combineExecResults(s,this.executeSubSelectedArray({field:i,array:s.result,execContext:a})):i.selectionSet?null==s.result?s:this.combineExecResults(s,this.executeSelectionSet({selectionSet:i.selectionSet,rootValue:s.result,execContext:a})):(b(i,s.result),this.freezeResults,s)},t.prototype.combineExecResults=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=null;return e.forEach(function(e){e.missing&&(r=r||[]).push.apply(r,e.missing)}),{result:e.pop().result,missing:r}},t.prototype.executeSubSelectedArray=function(e){var t=this,r=e.field,i=e.array,a=e.execContext,n=null;function o(e){return e.missing&&(n=n||[]).push.apply(n,e.missing),e.result}return i=i.map(function(e){return null===e?null:Array.isArray(e)?o(t.executeSubSelectedArray({field:r,array:e,execContext:a})):r.selectionSet?o(t.executeSelectionSet({selectionSet:r.selectionSet,rootValue:e,execContext:a})):(b(r,e),e)}),this.freezeResults,{result:i,missing:n}},t}();function b(e,t){if(!e.selectionSet&&r.isIdValue(t))throw new a.InvariantError(4)}function S(){return!0}function x(e){a.invariant(r.isIdValue(e),5)}function O(e,t,i,a,n,o){o.resultKey;var s=o.directives,c=i;(a||s)&&(c=r.getStoreKeyName(c,a,s));var u=void 0;if(e&&void 0===(u=e[c])&&n.cacheRedirects&&"string"==typeof t){var l=n.cacheRedirects[t];if(l){var d=l[i];d&&(u=d(e,a,{getCacheKey:function(e){return r.toIdValue({id:n.dataIdFromObject(e),typename:e.__typename})}}))}}return void 0===u?{result:u,missing:[{object:e,fieldName:c,tolerable:!1}]}:(r.isJsonValue(u)&&(u=u.json),{result:u})}var R=function(){function e(e){void 0===e&&(e=Object.create(null)),this.data=e}return e.prototype.toObject=function(){return this.data},e.prototype.get=function(e){return this.data[e]},e.prototype.set=function(e,t){this.data[e]=t},e.prototype.delete=function(e){this.data[e]=void 0},e.prototype.clear=function(){this.data=Object.create(null)},e.prototype.replace=function(e){this.data=e||Object.create(null)},e}();function I(e){return new R(e)}var F=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="WriteError",e}return e.__extends(r,t),r}(Error);function _(e,t){var r=new F("Error writing result to store for query:\n "+JSON.stringify(t));return r.message+="\n"+e.message,r.stack=e.stack,r}var w=function(){function t(){}return t.prototype.writeQueryToStore=function(e){var t=e.query,r=e.result,i=e.store,a=void 0===i?v():i,n=e.variables,o=e.dataIdFromObject,s=e.fragmentMatcherFunction;return this.writeResultToStore({dataId:"ROOT_QUERY",result:r,document:t,store:a,variables:n,dataIdFromObject:o,fragmentMatcherFunction:s})},t.prototype.writeResultToStore=function(e){var t=e.dataId,i=e.result,a=e.document,n=e.store,o=void 0===n?v():n,s=e.variables,c=e.dataIdFromObject,u=e.fragmentMatcherFunction,l=r.getOperationDefinition(a);try{return this.writeSelectionSetToStore({result:i,dataId:t,selectionSet:l.selectionSet,context:{store:o,processedData:{},variables:r.assign({},r.getDefaultValues(l),s),dataIdFromObject:c,fragmentMap:r.createFragmentMap(r.getFragmentDefinitions(a)),fragmentMatcherFunction:u}})}catch(e){throw _(e,a)}},t.prototype.writeSelectionSetToStore=function(e){var t=this,i=e.result,n=e.dataId,o=e.selectionSet,s=e.context,c=s.variables,u=s.store,l=s.fragmentMap;return o.selections.forEach(function(e){if(r.shouldInclude(e,c))if(r.isField(e)){var o=r.resultKeyNameFromField(e),u=i[o];if(void 0!==u)t.writeFieldToStore({dataId:n,value:u,field:e,context:s});else{var d=!1,f=!1;e.directives&&e.directives.length&&(d=e.directives.some(function(e){return e.name&&"defer"===e.name.value}),f=e.directives.some(function(e){return e.name&&"client"===e.name.value})),!d&&!f&&s.fragmentMatcherFunction}}else{var p=void 0;r.isInlineFragment(e)?p=e:(p=(l||{})[e.name.value],a.invariant(p,6));var h=!0;if(s.fragmentMatcherFunction&&p.typeCondition){var y=r.toIdValue({id:"self",typename:void 0}),m={store:new R({self:i}),cacheRedirects:{}},v=s.fragmentMatcherFunction(y,p.typeCondition.name.value,m);r.isProduction(),h=!!v}h&&t.writeSelectionSetToStore({result:i,selectionSet:p.selectionSet,dataId:n,context:s})}}),u},t.prototype.writeFieldToStore=function(t){var i,n,o,s=t.field,c=t.value,u=t.dataId,l=t.context,d=l.variables,f=l.dataIdFromObject,p=l.store,h=r.storeKeyNameFromField(s,d);if(s.selectionSet&&null!==c)if(Array.isArray(c)){var y=u+"."+h;n=this.processArrayValue(c,y,s.selectionSet,l)}else{var m=u+"."+h,v=!0;if(j(m)||(m="$"+m),f){var g=f(c);a.invariant(!g||!j(g),7),(g||"number"==typeof g&&0===g)&&(m=g,v=!1)}M(m,s,l.processedData)||this.writeSelectionSetToStore({dataId:m,result:c,selectionSet:s.selectionSet,context:l});var b=c.__typename;n=r.toIdValue({id:m,typename:b},v);var S=(o=p.get(u))&&o[h];if(S!==n&&r.isIdValue(S)){var x=void 0!==S.typename,O=void 0!==b,R=x&&O&&S.typename!==b;a.invariant(!v||S.generated||R,8),a.invariant(!x||O,9),S.generated&&(R?v||p.delete(S.id):V(S.id,n.id,p))}}else n=null!=c&&"object"==typeof c?{type:"json",json:c}:c;(o=p.get(u))&&r.isEqual(n,o[h])||p.set(u,e.__assign({},o,((i={})[h]=n,i)))},t.prototype.processArrayValue=function(e,t,i,a){var n=this;return e.map(function(e,o){if(null===e)return null;var s=t+"."+o;if(Array.isArray(e))return n.processArrayValue(e,s,i,a);var c=!0;if(a.dataIdFromObject){var u=a.dataIdFromObject(e);u&&(s=u,c=!1)}return M(s,i,a.processedData)||n.writeSelectionSetToStore({dataId:s,result:e,selectionSet:i,context:a}),r.toIdValue({id:s,typename:e.__typename},c)})},t}();function j(e){return"$"===e[0]}function V(t,i,a){if(t===i)return!1;var n=a.get(t),o=a.get(i),s=!1;Object.keys(n).forEach(function(e){var t=n[e],i=o[e];r.isIdValue(t)&&j(t.id)&&r.isIdValue(i)&&!r.isEqual(t,i)&&V(t.id,i.id,a)&&(s=!0)}),a.delete(t);var c=e.__assign({},n,o);return r.isEqual(c,o)?s:(a.set(i,c),!0)}function M(e,t,r){if(!r)return!1;if(r[e]){if(r[e].indexOf(t)>=0)return!0;r[e].push(t)}else r[e]=[t];return!1}var D={fragmentMatcher:new p,dataIdFromObject:E,addTypename:!0,resultCaching:!0,freezeResults:!1};function E(e){if(e.__typename){if(void 0!==e.id)return e.__typename+":"+e.id;if(void 0!==e._id)return e.__typename+":"+e._id}return null}var T=Object.prototype.hasOwnProperty,C=function(t){function r(e,r,i){var a=t.call(this,Object.create(null))||this;return a.optimisticId=e,a.parent=r,a.transaction=i,a}return e.__extends(r,t),r.prototype.toObject=function(){return e.__assign({},this.parent.toObject(),this.data)},r.prototype.get=function(e){return T.call(this.data,e)?this.data[e]:this.parent.get(e)},r}(R),q=function(t){function n(a){void 0===a&&(a={});var n=t.call(this)||this;n.watches=new Set,n.typenameDocumentCache=new Map,n.cacheKeyRoot=new i.KeyTrie(r.canUseWeakMap),n.silenceBroadcast=!1,n.config=e.__assign({},D,a),n.config.customResolvers&&(n.config.cacheRedirects=n.config.customResolvers),n.config.cacheResolvers&&(n.config.cacheRedirects=n.config.cacheResolvers),n.addTypename=n.config.addTypename,n.data=n.config.resultCaching?new m:new R,n.optimisticData=n.data,n.storeWriter=new w,n.storeReader=new g({cacheKeyRoot:n.cacheKeyRoot,freezeResults:a.freezeResults});var o=n,s=o.maybeBroadcastWatch;return n.maybeBroadcastWatch=i.wrap(function(e){return s.call(n,e)},{makeCacheKey:function(e){if(!e.optimistic&&!e.previousResult)return o.data instanceof m?o.cacheKeyRoot.lookup(e.query,JSON.stringify(e.variables)):void 0}}),n}return e.__extends(n,t),n.prototype.restore=function(e){return e&&this.data.replace(e),this},n.prototype.extract=function(e){return void 0===e&&(e=!1),(e?this.optimisticData:this.data).toObject()},n.prototype.read=function(e){return"string"==typeof e.rootId&&void 0===this.data.get(e.rootId)?null:this.storeReader.readQueryFromStore({store:e.optimistic?this.optimisticData:this.data,query:this.transformDocument(e.query),variables:e.variables,rootId:e.rootId,fragmentMatcherFunction:this.config.fragmentMatcher.match,previousResult:e.previousResult,config:this.config})},n.prototype.write=function(e){this.storeWriter.writeResultToStore({dataId:e.dataId,result:e.result,variables:e.variables,document:this.transformDocument(e.query),store:this.data,dataIdFromObject:this.config.dataIdFromObject,fragmentMatcherFunction:this.config.fragmentMatcher.match}),this.broadcastWatches()},n.prototype.diff=function(e){return this.storeReader.diffQueryAgainstStore({store:e.optimistic?this.optimisticData:this.data,query:this.transformDocument(e.query),variables:e.variables,returnPartialData:e.returnPartialData,previousResult:e.previousResult,fragmentMatcherFunction:this.config.fragmentMatcher.match,config:this.config})},n.prototype.watch=function(e){var t=this;return this.watches.add(e),function(){t.watches.delete(e)}},n.prototype.evict=function(e){throw new a.InvariantError(1)},n.prototype.reset=function(){return this.data.clear(),this.broadcastWatches(),Promise.resolve()},n.prototype.removeOptimistic=function(e){for(var t=[],r=0,i=this.optimisticData;i instanceof C;)i.optimisticId===e?++r:t.push(i),i=i.parent;if(r>0){for(this.optimisticData=i;t.length>0;){var a=t.pop();this.performTransaction(a.transaction,a.optimisticId)}this.broadcastWatches()}},n.prototype.performTransaction=function(e,t){var r=this.data,i=this.silenceBroadcast;this.silenceBroadcast=!0,"string"==typeof t&&(this.data=this.optimisticData=new C(t,this.optimisticData,e));try{e(this)}finally{this.silenceBroadcast=i,this.data=r}this.broadcastWatches()},n.prototype.recordOptimisticTransaction=function(e,t){return this.performTransaction(e,t)},n.prototype.transformDocument=function(e){if(this.addTypename){var t=this.typenameDocumentCache.get(e);return t||(t=r.addTypenameToDocument(e),this.typenameDocumentCache.set(e,t),this.typenameDocumentCache.set(t,t)),t}return e},n.prototype.broadcastWatches=function(){var e=this;this.silenceBroadcast||this.watches.forEach(function(t){return e.maybeBroadcastWatch(t)})},n.prototype.maybeBroadcastWatch=function(e){e.callback(this.diff({query:e.query,variables:e.variables,previousResult:e.previousResult&&e.previousResult(),optimistic:e.optimistic}))},n}(t.ApolloCache);exports.HeuristicFragmentMatcher=p,exports.InMemoryCache=q,exports.IntrospectionFragmentMatcher=h,exports.ObjectCache=R,exports.StoreReader=g,exports.StoreWriter=w,exports.WriteError=F,exports.assertIdValue=x,exports.defaultDataIdFromObject=E,exports.defaultNormalizedCacheFactory=I,exports.enhanceErrorWithDocument=_;

@@ -73,7 +73,4 @@ import { __assign, __extends } from 'tslib';

var obj = context.store.get(idValue.id);
if (!obj && idValue.id === 'ROOT_QUERY') {
return true;
}
if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -118,3 +115,3 @@ if (!obj.__typename) {

if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -121,0 +118,0 @@ process.env.NODE_ENV === "production" ? invariant(obj.__typename, 11) : invariant(obj.__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));

@@ -73,7 +73,4 @@ (function (global, factory) {

var obj = context.store.get(idValue.id);
if (!obj && idValue.id === 'ROOT_QUERY') {
return true;
}
if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -118,3 +115,3 @@ if (!obj.__typename) {

if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -121,0 +118,0 @@ process.env.NODE_ENV === "production" ? tsInvariant.invariant(obj.__typename, 11) : tsInvariant.invariant(obj.__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));

@@ -24,7 +24,4 @@ "use strict";

var obj = context.store.get(idValue.id);
if (!obj && idValue.id === 'ROOT_QUERY') {
return true;
}
if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -70,3 +67,3 @@ if (!obj.__typename) {

if (!obj) {
return false;
return idValue.id === 'ROOT_QUERY';
}

@@ -73,0 +70,0 @@ ts_invariant_1.invariant(obj.__typename, "Cannot match fragment because __typename property is missing: " + JSON.stringify(obj));

{
"name": "apollo-cache-inmemory",
"version": "1.6.0-beta.4",
"version": "1.6.0-beta.5",
"description": "Core abstract of Caching layer for Apollo Client",

@@ -42,6 +42,6 @@ "author": "James Baxley <james@meteor.com>",

"dependencies": {
"apollo-cache": "^1.3.0-beta.1",
"apollo-utilities": "^1.3.0-beta.1",
"apollo-cache": "^1.3.0-beta.5",
"apollo-utilities": "^1.3.0-beta.5",
"optimism": "^0.9.0",
"ts-invariant": "^0.3.2",
"ts-invariant": "^0.4.0",
"tslib": "^1.9.3"

@@ -52,3 +52,3 @@ },

},
"gitHead": "6c1f06d2e7fbb99790d5837dc4e0458d5e6b443a"
"gitHead": "290dcc3ffd8be2dd8509d8d662287e43a791a933"
}

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

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