@apollo/client 3.4.11 → 3.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs.js +88 -53
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -0
- package/cache/cache.cjs.js +52 -37
- package/cache/cache.cjs.js.map +1 -1
- package/cache/core/cache.d.ts +1 -1
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +3 -0
- package/cache/core/types/Cache.d.ts.map +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/index.d.ts +3 -3
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js +2 -2
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +10 -1
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js +31 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +3 -9
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +16 -17
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.d.ts +1 -2
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +1 -18
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +1 -0
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +7 -4
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +8 -1
- package/cache/inmemory/types.d.ts.map +1 -1
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +2 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +2 -1
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs.js +5 -4
- package/core/core.cjs.js.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +10 -10
- package/react/context/ApolloContext.d.ts +2 -1
- package/react/context/ApolloContext.d.ts.map +1 -1
- package/react/context/ApolloContext.js +11 -5
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/context.cjs.js +10 -4
- package/react/context/context.cjs.js.map +1 -1
- package/react/hoc/hoc.cjs.js +8 -5
- package/react/hoc/hoc.cjs.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts.map +1 -1
- package/react/hoc/subscription-hoc.js +8 -5
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/parser/index.js.map +1 -1
- package/utilities/common/canUse.d.ts +1 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +2 -0
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.d.ts.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +14 -3
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/observables/subclassing.d.ts.map +1 -1
- package/utilities/observables/subclassing.js +2 -1
- package/utilities/observables/subclassing.js.map +1 -1
- package/utilities/policies/pagination.d.ts +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +7 -2
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/testing/mocking/mockFetch.js.map +1 -1
- package/utilities/utilities.cjs.js +29 -10
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
- package/apollo-core.cjs.js +0 -5782
- package/apollo-core.cjs.js.map +0 -1
- package/apollo-core.cjs.min.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAEL,WAAW,EACX,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,
|
|
1
|
+
{"version":3,"file":"inMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAEL,WAAW,EACX,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIrE,OAAO,EAAE,OAAO,EAA4B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,aAAK,gBAAgB,GAAG,IAAI,CAC1B,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,EAC/B,YAAY,GACZ,gBAAgB,CACnB,CAAA;AAED,qBAAa,aAAc,SAAQ,WAAW,CAAC,qBAAqB,CAAC;IACnE,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,cAAc,CAAc;IAEpC,SAAS,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACtC,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,WAAW,CAAU;IAE7B,OAAO,CAAC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,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBlD,gBAAgB,CAAC,UAAU,EAAE,MAAM;IAQ1C,OAAO,CAAC,OAAO,CAAK;IAEb,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC;IAgGhD,kBAAkB,CACvB,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,GAAG,EACrC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAQvB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY;IAgB9D,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB;IAYrD,OAAO,CAAC,cAAc;CAgCvB"}
|
|
@@ -9,15 +9,9 @@ import { StoreReader } from "./readFromStore.js";
|
|
|
9
9
|
import { StoreWriter } from "./writeToStore.js";
|
|
10
10
|
import { EntityStore, supportsResultCaching } from "./entityStore.js";
|
|
11
11
|
import { makeVar, forgetCache, recallCache } from "./reactiveVars.js";
|
|
12
|
-
import {
|
|
13
|
-
import { hasOwn } from "./helpers.js";
|
|
12
|
+
import { Policies } from "./policies.js";
|
|
13
|
+
import { hasOwn, normalizeConfig, shouldCanonizeResults } from "./helpers.js";
|
|
14
14
|
import { canonicalStringify } from "./object-canon.js";
|
|
15
|
-
var defaultConfig = {
|
|
16
|
-
dataIdFromObject: defaultDataIdFromObject,
|
|
17
|
-
addTypename: true,
|
|
18
|
-
resultCaching: true,
|
|
19
|
-
typePolicies: {},
|
|
20
|
-
};
|
|
21
15
|
var InMemoryCache = (function (_super) {
|
|
22
16
|
__extends(InMemoryCache, _super);
|
|
23
17
|
function InMemoryCache(config) {
|
|
@@ -27,7 +21,7 @@ var InMemoryCache = (function (_super) {
|
|
|
27
21
|
_this.typenameDocumentCache = new Map();
|
|
28
22
|
_this.makeVar = makeVar;
|
|
29
23
|
_this.txCount = 0;
|
|
30
|
-
_this.config =
|
|
24
|
+
_this.config = normalizeConfig(config);
|
|
31
25
|
_this.addTypename = !!_this.config.addTypename;
|
|
32
26
|
_this.policies = new Policies({
|
|
33
27
|
cache: _this,
|
|
@@ -53,6 +47,7 @@ var InMemoryCache = (function (_super) {
|
|
|
53
47
|
cache: this,
|
|
54
48
|
addTypename: this.addTypename,
|
|
55
49
|
resultCacheMaxSize: this.config.resultCacheMaxSize,
|
|
50
|
+
canonizeResults: shouldCanonizeResults(this.config),
|
|
56
51
|
canon: resetResultIdentities
|
|
57
52
|
? void 0
|
|
58
53
|
: previousReader && previousReader.canon,
|
|
@@ -175,7 +170,7 @@ var InMemoryCache = (function (_super) {
|
|
|
175
170
|
}
|
|
176
171
|
try {
|
|
177
172
|
++this.txCount;
|
|
178
|
-
return this.optimisticData.evict(options);
|
|
173
|
+
return this.optimisticData.evict(options, this.data);
|
|
179
174
|
}
|
|
180
175
|
finally {
|
|
181
176
|
if (!--this.txCount && options.broadcast !== false) {
|
|
@@ -183,10 +178,18 @@ var InMemoryCache = (function (_super) {
|
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
180
|
};
|
|
186
|
-
InMemoryCache.prototype.reset = function () {
|
|
181
|
+
InMemoryCache.prototype.reset = function (options) {
|
|
182
|
+
var _this = this;
|
|
187
183
|
this.init();
|
|
188
|
-
this.broadcastWatches();
|
|
189
184
|
canonicalStringify.reset();
|
|
185
|
+
if (options && options.discardWatches) {
|
|
186
|
+
this.watches.forEach(function (watch) { return _this.maybeBroadcastWatch.forget(watch); });
|
|
187
|
+
this.watches.clear();
|
|
188
|
+
forgetCache(this);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
this.broadcastWatches();
|
|
192
|
+
}
|
|
190
193
|
return Promise.resolve();
|
|
191
194
|
};
|
|
192
195
|
InMemoryCache.prototype.removeOptimistic = function (idToRemove) {
|
|
@@ -275,11 +278,7 @@ var InMemoryCache = (function (_super) {
|
|
|
275
278
|
};
|
|
276
279
|
InMemoryCache.prototype.broadcastWatch = function (c, options) {
|
|
277
280
|
var lastDiff = c.lastDiff;
|
|
278
|
-
var diff = this.diff(
|
|
279
|
-
query: c.query,
|
|
280
|
-
variables: c.variables,
|
|
281
|
-
optimistic: c.optimistic,
|
|
282
|
-
});
|
|
281
|
+
var diff = this.diff(c);
|
|
283
282
|
if (options) {
|
|
284
283
|
if (c.optimistic &&
|
|
285
284
|
typeof options.optimistic === "string") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inMemoryCache.js","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":";AACA,OAAO,gBAAgB,CAAC;AAGxB,OAAO,EAA6B,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAGrB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EACL,uBAAuB,EAEvB,QAAQ,GAET,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAepD,IAAM,aAAa,GAAwB;IACzC,gBAAgB,EAAE,uBAAuB;IACzC,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF;IAAmC,iCAAkC;IAwBnE,uBAAY,MAAgC;QAAhC,uBAAA,EAAA,WAA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tB,UACE,CAAqB,EACrB,OAA0B;QAElB,IAAA,QAAQ,GAAK,CAAC,SAAN,CAAO;QACvB,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAM;YAC1B,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,UAAU,EAAE,CAAC,CAAC,UAAU;SACzB,CAAC,CAAC;QAEH,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,CAAC,UAAU;gBACZ,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;gBAC1C,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;aACvC;YAED,IAAI,OAAO,CAAC,cAAc;gBACtB,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,KAAK,EAAE;gBAGlE,OAAO;aACR;SACF;QAED,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;YACrD,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AA1eD,CAAmC,WAAW,GA0e7C","sourcesContent":["// Make builtins like Map and Set safe to use with non-extensible objects.\nimport './fixPolyfills';\n\nimport { DocumentNode } from 'graphql';\nimport { OptimisticWrapperFunction, wrap } from 'optimism';\nimport { equal } from '@wry/equality';\n\nimport { ApolloCache } from '../core/cache';\nimport { Cache } from '../core/types/Cache';\nimport { MissingFieldError } from '../core/types/common';\nimport {\n addTypenameToDocument,\n StoreObject,\n Reference,\n isReference,\n} from '../../utilities';\nimport {\n ApolloReducerConfig,\n NormalizedCacheObject,\n} from './types';\nimport { StoreReader } from './readFromStore';\nimport { StoreWriter } from './writeToStore';\nimport { EntityStore, supportsResultCaching } from './entityStore';\nimport { makeVar, forgetCache, recallCache } from './reactiveVars';\nimport {\n defaultDataIdFromObject,\n PossibleTypesMap,\n Policies,\n TypePolicies,\n} from './policies';\nimport { hasOwn } from './helpers';\nimport { canonicalStringify } from './object-canon';\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n resultCacheMaxSize?: number;\n}\n\ntype BroadcastOptions = Pick<\n Cache.BatchOptions<InMemoryCache>,\n | \"optimistic\"\n | \"onWatchUpdated\"\n>\n\nconst defaultConfig: InMemoryCacheConfig = {\n dataIdFromObject: defaultDataIdFromObject,\n addTypename: true,\n resultCaching: true,\n typePolicies: {},\n};\n\nexport class InMemoryCache extends ApolloCache<NormalizedCacheObject> {\n private data: EntityStore;\n private optimisticData: EntityStore;\n\n protected config: InMemoryCacheConfig;\n private watches = new Set<Cache.WatchOptions>();\n private addTypename: boolean;\n\n private typenameDocumentCache = new Map<DocumentNode, DocumentNode>();\n private storeReader: StoreReader;\n private storeWriter: StoreWriter;\n\n private maybeBroadcastWatch: OptimisticWrapperFunction<\n [Cache.WatchOptions, BroadcastOptions?],\n any,\n [Cache.WatchOptions]>;\n\n // Dynamically imported code can augment existing typePolicies or\n // possibleTypes by calling cache.policies.addTypePolicies or\n // cache.policies.addPossibletypes.\n public readonly policies: Policies;\n\n public readonly makeVar = makeVar;\n\n constructor(config: InMemoryCacheConfig = {}) {\n super();\n this.config = { ...defaultConfig, ...config };\n this.addTypename = !!this.config.addTypename;\n\n this.policies = new Policies({\n cache: this,\n dataIdFromObject: this.config.dataIdFromObject,\n possibleTypes: this.config.possibleTypes,\n typePolicies: this.config.typePolicies,\n });\n\n this.init();\n }\n\n private init() {\n // Passing { resultCaching: false } in the InMemoryCache constructor options\n // will completely disable dependency tracking, which will improve memory\n // usage but worsen the performance of repeated reads.\n const rootStore = this.data = new EntityStore.Root({\n policies: this.policies,\n resultCaching: this.config.resultCaching,\n });\n\n // When no optimistic writes are currently active, cache.optimisticData ===\n // cache.data, so there are no additional layers on top of the actual data.\n // When an optimistic update happens, this.optimisticData will become a\n // linked list of EntityStore Layer objects that terminates with the\n // original this.data cache object.\n this.optimisticData = rootStore.stump;\n\n this.resetResultCache();\n }\n\n private resetResultCache(resetResultIdentities?: boolean) {\n const previousReader = this.storeReader;\n\n // The StoreWriter is mostly stateless and so doesn't really need to be\n // reset, but it does need to have its writer.storeReader reference updated,\n // so it's simpler to update this.storeWriter as well.\n this.storeWriter = new StoreWriter(\n this,\n this.storeReader = new StoreReader({\n cache: this,\n addTypename: this.addTypename,\n resultCacheMaxSize: this.config.resultCacheMaxSize,\n canon: resetResultIdentities\n ? void 0\n : previousReader && previousReader.canon,\n }),\n );\n\n this.maybeBroadcastWatch = wrap((\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) => {\n return this.broadcastWatch(c, options);\n }, {\n max: this.config.resultCacheMaxSize,\n makeCacheKey: (c: Cache.WatchOptions) => {\n // Return a cache key (thus enabling result caching) only if we're\n // currently using a data store that can track cache dependencies.\n const store = c.optimistic ? this.optimisticData : this.data;\n if (supportsResultCaching(store)) {\n const { optimistic, rootId, variables } = c;\n return store.makeCacheKey(\n c.query,\n // Different watches can have the same query, optimistic\n // status, rootId, and variables, but if their callbacks are\n // different, the (identical) result needs to be delivered to\n // each distinct callback. The easiest way to achieve that\n // separation is to include c.callback in the cache key for\n // maybeBroadcastWatch calls. See issue #5733.\n c.callback,\n canonicalStringify({ optimistic, rootId, variables }),\n );\n }\n }\n });\n\n // Since we have thrown away all the cached functions that depend on the\n // CacheGroup dependencies maintained by EntityStore, we should also reset\n // all CacheGroup dependency information.\n new Set([\n this.data.group,\n this.optimisticData.group,\n ]).forEach(group => group.resetCaching());\n }\n\n public restore(data: NormalizedCacheObject): this {\n this.init();\n // Since calling this.init() discards/replaces the entire StoreReader, along\n // with the result caches it maintains, this.data.replace(data) won't have\n // to bother deleting the old data.\n if (data) this.data.replace(data);\n return this;\n }\n\n public extract(optimistic: boolean = false): NormalizedCacheObject {\n return (optimistic ? this.optimisticData : this.data).extract();\n }\n\n public read<T>(options: Cache.ReadOptions): T | null {\n const {\n // Since read returns data or null, without any additional metadata\n // about whether/where there might have been missing fields, the\n // default behavior cannot be returnPartialData = true (like it is\n // for the diff method), since defaulting to true would violate the\n // integrity of the T in the return type. However, partial data may\n // be useful in some cases, so returnPartialData:true may be\n // specified explicitly.\n returnPartialData = false,\n } = options;\n try {\n return this.storeReader.diffQueryAgainstStore<T>({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n config: this.config,\n returnPartialData,\n }).result || null;\n } catch (e) {\n if (e instanceof MissingFieldError) {\n // Swallow MissingFieldError and return null, so callers do not\n // need to worry about catching \"normal\" exceptions resulting from\n // incomplete cache data. Unexpected errors will be re-thrown. If\n // you need more information about which fields were missing, use\n // cache.diff instead, and examine diffResult.missing.\n return null;\n }\n throw e;\n }\n }\n\n public write(options: Cache.WriteOptions): Reference | undefined {\n try {\n ++this.txCount;\n return this.storeWriter.writeToStore(this.data, options);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n if (hasOwn.call(options, \"id\") && !options.id) {\n // To my knowledge, TypeScript does not currently provide a way to\n // enforce that an optional property?:type must *not* be undefined\n // when present. That ability would be useful here, because we want\n // options.id to default to ROOT_QUERY only when no options.id was\n // provided. If the caller attempts to pass options.id with a\n // falsy/undefined value (perhaps because cache.identify failed), we\n // should not assume the goal was to modify the ROOT_QUERY object.\n // We could throw, but it seems natural to return false to indicate\n // that nothing was modified.\n return false;\n }\n const store = options.optimistic // Defaults to false.\n ? this.optimisticData\n : this.data;\n try {\n ++this.txCount;\n return store.modify(options.id || \"ROOT_QUERY\", options.fields);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public diff<T>(options: Cache.DiffOptions): Cache.DiffResult<T> {\n return this.storeReader.diffQueryAgainstStore({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n rootId: options.id || \"ROOT_QUERY\",\n config: this.config,\n });\n }\n\n public watch(watch: Cache.WatchOptions): () => void {\n if (!this.watches.size) {\n // In case we previously called forgetCache(this) because\n // this.watches became empty (see below), reattach this cache to any\n // reactive variables on which it previously depended. It might seem\n // paradoxical that we're able to recall something we supposedly\n // forgot, but the point of calling forgetCache(this) is to silence\n // useless broadcasts while this.watches is empty, and to allow the\n // cache to be garbage collected. If, however, we manage to call\n // recallCache(this) here, this cache object must not have been\n // garbage collected yet, and should resume receiving updates from\n // reactive variables, now that it has a watcher to notify.\n recallCache(this);\n }\n this.watches.add(watch);\n if (watch.immediate) {\n this.maybeBroadcastWatch(watch);\n }\n return () => {\n // Once we remove the last watch from this.watches, cache.broadcastWatches\n // no longer does anything, so we preemptively tell the reactive variable\n // system to exclude this cache from future broadcasts.\n if (this.watches.delete(watch) && !this.watches.size) {\n forgetCache(this);\n }\n // Remove this watch from the LRU cache managed by the\n // maybeBroadcastWatch OptimisticWrapperFunction, to prevent memory\n // leaks involving the closure of watch.callback.\n this.maybeBroadcastWatch.forget(watch);\n };\n }\n\n public gc(options?: {\n // If true, also free non-essential result cache memory by bulk-releasing\n // this.{store{Reader,Writer},maybeBroadcastWatch}. Defaults to false.\n resetResultCache?: boolean;\n // If resetResultCache is true, this.storeReader.canon will be preserved by\n // default, but can also be discarded by passing resetResultIdentities:true.\n // Defaults to false.\n resetResultIdentities?: boolean;\n }) {\n canonicalStringify.reset();\n const ids = this.optimisticData.gc();\n if (options && !this.txCount) {\n if (options.resetResultCache) {\n this.resetResultCache(options.resetResultIdentities);\n } else if (options.resetResultIdentities) {\n this.storeReader.resetCanon();\n }\n }\n return ids;\n }\n\n // Call this method to ensure the given root ID remains in the cache after\n // garbage collection, along with its transitive child entities. Note that\n // the cache automatically retains all directly written entities. By default,\n // the retainment persists after optimistic updates are removed. Pass true\n // for the optimistic argument if you would prefer for the retainment to be\n // discarded when the top-most optimistic layer is removed. Returns the\n // resulting (non-negative) retainment count.\n public retain(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).retain(rootId);\n }\n\n // Call this method to undo the effect of the retain method, above. Once the\n // retainment count falls to zero, the given ID will no longer be preserved\n // during garbage collection, though it may still be preserved by other safe\n // entities that refer to it. Returns the resulting (non-negative) retainment\n // count, in case that's useful.\n public release(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).release(rootId);\n }\n\n // Returns the canonical ID for a given StoreObject, obeying typePolicies\n // and keyFields (and dataIdFromObject, if you still use that). At minimum,\n // the object must contain a __typename and any primary key fields required\n // to identify entities of that type. If you pass a query result object, be\n // sure that none of the primary key fields have been renamed by aliasing.\n // If you pass a Reference object, its __ref ID string will be returned.\n public identify(object: StoreObject | Reference): string | undefined {\n return isReference(object) ? object.__ref :\n this.policies.identify(object)[0];\n }\n\n public evict(options: Cache.EvictOptions): boolean {\n if (!options.id) {\n if (hasOwn.call(options, \"id\")) {\n // See comment in modify method about why we return false when\n // options.id exists but is falsy/undefined.\n return false;\n }\n options = { ...options, id: \"ROOT_QUERY\" };\n }\n try {\n // It's unlikely that the eviction will end up invoking any other\n // cache update operations while it's running, but {in,de}crementing\n // this.txCount still seems like a good idea, for uniformity with\n // the other update methods.\n ++this.txCount;\n return this.optimisticData.evict(options);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public reset(): Promise<void> {\n this.init();\n this.broadcastWatches();\n canonicalStringify.reset();\n return Promise.resolve();\n }\n\n public removeOptimistic(idToRemove: string) {\n const newOptimisticData = this.optimisticData.removeLayer(idToRemove);\n if (newOptimisticData !== this.optimisticData) {\n this.optimisticData = newOptimisticData;\n this.broadcastWatches();\n }\n }\n\n private txCount = 0;\n\n public batch(options: Cache.BatchOptions<InMemoryCache>) {\n const {\n update,\n optimistic = true,\n removeOptimistic,\n onWatchUpdated,\n } = options;\n\n const perform = (layer?: EntityStore) => {\n const { data, optimisticData } = this;\n ++this.txCount;\n if (layer) {\n this.data = this.optimisticData = layer;\n }\n try {\n update(this);\n } finally {\n --this.txCount;\n this.data = data;\n this.optimisticData = optimisticData;\n }\n };\n\n const alreadyDirty = new Set<Cache.WatchOptions>();\n\n if (onWatchUpdated && !this.txCount) {\n // If an options.onWatchUpdated callback is provided, we want to call it\n // with only the Cache.WatchOptions objects affected by options.update,\n // but there might be dirty watchers already waiting to be broadcast that\n // have nothing to do with the update. To prevent including those watchers\n // in the post-update broadcast, we perform this initial broadcast to\n // collect the dirty watchers, so we can re-dirty them later, after the\n // post-update broadcast, allowing them to receive their pending\n // broadcasts the next time broadcastWatches is called, just as they would\n // if we never called cache.batch.\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch) {\n alreadyDirty.add(watch);\n return false;\n },\n });\n }\n\n if (typeof optimistic === 'string') {\n // Note that there can be multiple layers with the same optimistic ID.\n // When removeOptimistic(id) is called for that id, all matching layers\n // will be removed, and the remaining layers will be reapplied.\n this.optimisticData = this.optimisticData.addLayer(optimistic, perform);\n } else if (optimistic === false) {\n // Ensure both this.data and this.optimisticData refer to the root\n // (non-optimistic) layer of the cache during the update. Note that\n // this.data could be a Layer if we are currently executing an optimistic\n // update function, but otherwise will always be an EntityStore.Root\n // instance.\n perform(this.data);\n } else {\n // Otherwise, leave this.data and this.optimisticData unchanged and run\n // the update with broadcast batching.\n perform();\n }\n\n if (typeof removeOptimistic === \"string\") {\n this.optimisticData = this.optimisticData.removeLayer(removeOptimistic);\n }\n\n // Note: if this.txCount > 0, then alreadyDirty.size === 0, so this code\n // takes the else branch and calls this.broadcastWatches(options), which\n // does nothing when this.txCount > 0.\n if (onWatchUpdated && alreadyDirty.size) {\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch, diff) {\n const result = onWatchUpdated.call(this, watch, diff);\n if (result !== false) {\n // Since onWatchUpdated did not return false, this diff is\n // about to be broadcast to watch.callback, so we don't need\n // to re-dirty it with the other alreadyDirty watches below.\n alreadyDirty.delete(watch);\n }\n return result;\n }\n });\n // Silently re-dirty any watches that were already dirty before the update\n // was performed, and were not broadcast just now.\n if (alreadyDirty.size) {\n alreadyDirty.forEach(watch => this.maybeBroadcastWatch.dirty(watch));\n }\n } else {\n // If alreadyDirty is empty or we don't have an onWatchUpdated\n // function, we don't need to go to the trouble of wrapping\n // options.onWatchUpdated.\n this.broadcastWatches(options);\n }\n }\n\n public performTransaction(\n update: (cache: InMemoryCache) => any,\n optimisticId?: string | null,\n ) {\n return this.batch({\n update,\n optimistic: optimisticId || (optimisticId !== null),\n });\n }\n\n public transformDocument(document: DocumentNode): DocumentNode {\n if (this.addTypename) {\n let result = this.typenameDocumentCache.get(document);\n if (!result) {\n result = addTypenameToDocument(document);\n this.typenameDocumentCache.set(document, result);\n // If someone calls transformDocument and then mistakenly passes the\n // result back into an API that also calls transformDocument, make sure\n // we don't keep creating new query documents.\n this.typenameDocumentCache.set(result, result);\n }\n return result;\n }\n return document;\n }\n\n protected broadcastWatches(options?: BroadcastOptions) {\n if (!this.txCount) {\n this.watches.forEach(c => this.maybeBroadcastWatch(c, options));\n }\n }\n\n // This method is wrapped by maybeBroadcastWatch, which is called by\n // broadcastWatches, so that we compute and broadcast results only when\n // the data that would be broadcast might have changed. It would be\n // simpler to check for changes after recomputing a result but before\n // broadcasting it, but this wrapping approach allows us to skip both\n // the recomputation and the broadcast, in most cases.\n private broadcastWatch(\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) {\n const { lastDiff } = c;\n const diff = this.diff<any>({\n query: c.query,\n variables: c.variables,\n optimistic: c.optimistic,\n });\n\n if (options) {\n if (c.optimistic &&\n typeof options.optimistic === \"string\") {\n diff.fromOptimisticTransaction = true;\n }\n\n if (options.onWatchUpdated &&\n options.onWatchUpdated.call(this, c, diff, lastDiff) === false) {\n // Returning false from the onWatchUpdated callback will prevent\n // calling c.callback(diff) for this watcher.\n return;\n }\n }\n\n if (!lastDiff || !equal(lastDiff.result, diff.result)) {\n c.callback(c.lastDiff = diff, lastDiff);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inMemoryCache.js","sourceRoot":"","sources":["../../../src/cache/inmemory/inMemoryCache.ts"],"names":[],"mappings":";AACA,OAAO,gBAAgB,CAAC;AAGxB,OAAO,EAA6B,IAAI,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAGrB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAQpD;IAAmC,iCAAkC;IAwBnE,uBAAY,MAAgC;QAAhC,uBAAA,EAAA,WAAgC;QAA5C,YACE,iBAAO,SAYR;QAhCO,aAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;QAGxC,2BAAqB,GAAG,IAAI,GAAG,EAA8B,CAAC;QActD,aAAO,GAAG,OAAO,CAAC;QAoU1B,aAAO,GAAG,CAAC,CAAC;QAhUlB,KAAI,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;QACtC,KAAI,CAAC,WAAW,GAAG,CAAC,CAAC,KAAI,CAAC,MA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AC,mBAAmB,CAAC,CAAC,EAAE,OAAO,CAAC,EAApC,CAAoC,CAAC,CAAC;SACjE;IACH,CAAC;IAQO,sCAAc,GAAtB,UACE,CAAqB,EACrB,OAA0B;QAElB,IAAA,QAAQ,GAAK,CAAC,SAAN,CAAO;QAQvB,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAM,CAAC,CAAC,CAAC;QAE/B,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,CAAC,UAAU;gBACZ,OAAO,OAAO,CAAC,UAAU,KAAK,QAAQ,EAAE;gBAC1C,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;aACvC;YAED,IAAI,OAAO,CAAC,cAAc;gBACtB,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,KAAK,EAAE;gBAGlE,OAAO;aACR;SACF;QAED,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;YACrD,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC;SACzC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAlgBD,CAAmC,WAAW,GAkgB7C","sourcesContent":["// Make builtins like Map and Set safe to use with non-extensible objects.\nimport './fixPolyfills';\n\nimport { DocumentNode } from 'graphql';\nimport { OptimisticWrapperFunction, wrap } from 'optimism';\nimport { equal } from '@wry/equality';\n\nimport { ApolloCache } from '../core/cache';\nimport { Cache } from '../core/types/Cache';\nimport { MissingFieldError } from '../core/types/common';\nimport {\n addTypenameToDocument,\n StoreObject,\n Reference,\n isReference,\n} from '../../utilities';\nimport { InMemoryCacheConfig, NormalizedCacheObject } from './types';\nimport { StoreReader } from './readFromStore';\nimport { StoreWriter } from './writeToStore';\nimport { EntityStore, supportsResultCaching } from './entityStore';\nimport { makeVar, forgetCache, recallCache } from './reactiveVars';\nimport { Policies } from './policies';\nimport { hasOwn, normalizeConfig, shouldCanonizeResults } from './helpers';\nimport { canonicalStringify } from './object-canon';\n\ntype BroadcastOptions = Pick<\n Cache.BatchOptions<InMemoryCache>,\n | \"optimistic\"\n | \"onWatchUpdated\"\n>\n\nexport class InMemoryCache extends ApolloCache<NormalizedCacheObject> {\n private data: EntityStore;\n private optimisticData: EntityStore;\n\n protected config: InMemoryCacheConfig;\n private watches = new Set<Cache.WatchOptions>();\n private addTypename: boolean;\n\n private typenameDocumentCache = new Map<DocumentNode, DocumentNode>();\n private storeReader: StoreReader;\n private storeWriter: StoreWriter;\n\n private maybeBroadcastWatch: OptimisticWrapperFunction<\n [Cache.WatchOptions, BroadcastOptions?],\n any,\n [Cache.WatchOptions]>;\n\n // Dynamically imported code can augment existing typePolicies or\n // possibleTypes by calling cache.policies.addTypePolicies or\n // cache.policies.addPossibletypes.\n public readonly policies: Policies;\n\n public readonly makeVar = makeVar;\n\n constructor(config: InMemoryCacheConfig = {}) {\n super();\n this.config = normalizeConfig(config);\n this.addTypename = !!this.config.addTypename;\n\n this.policies = new Policies({\n cache: this,\n dataIdFromObject: this.config.dataIdFromObject,\n possibleTypes: this.config.possibleTypes,\n typePolicies: this.config.typePolicies,\n });\n\n this.init();\n }\n\n private init() {\n // Passing { resultCaching: false } in the InMemoryCache constructor options\n // will completely disable dependency tracking, which will improve memory\n // usage but worsen the performance of repeated reads.\n const rootStore = this.data = new EntityStore.Root({\n policies: this.policies,\n resultCaching: this.config.resultCaching,\n });\n\n // When no optimistic writes are currently active, cache.optimisticData ===\n // cache.data, so there are no additional layers on top of the actual data.\n // When an optimistic update happens, this.optimisticData will become a\n // linked list of EntityStore Layer objects that terminates with the\n // original this.data cache object.\n this.optimisticData = rootStore.stump;\n\n this.resetResultCache();\n }\n\n private resetResultCache(resetResultIdentities?: boolean) {\n const previousReader = this.storeReader;\n\n // The StoreWriter is mostly stateless and so doesn't really need to be\n // reset, but it does need to have its writer.storeReader reference updated,\n // so it's simpler to update this.storeWriter as well.\n this.storeWriter = new StoreWriter(\n this,\n this.storeReader = new StoreReader({\n cache: this,\n addTypename: this.addTypename,\n resultCacheMaxSize: this.config.resultCacheMaxSize,\n canonizeResults: shouldCanonizeResults(this.config),\n canon: resetResultIdentities\n ? void 0\n : previousReader && previousReader.canon,\n }),\n );\n\n this.maybeBroadcastWatch = wrap((\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) => {\n return this.broadcastWatch(c, options);\n }, {\n max: this.config.resultCacheMaxSize,\n makeCacheKey: (c: Cache.WatchOptions) => {\n // Return a cache key (thus enabling result caching) only if we're\n // currently using a data store that can track cache dependencies.\n const store = c.optimistic ? this.optimisticData : this.data;\n if (supportsResultCaching(store)) {\n const { optimistic, rootId, variables } = c;\n return store.makeCacheKey(\n c.query,\n // Different watches can have the same query, optimistic\n // status, rootId, and variables, but if their callbacks are\n // different, the (identical) result needs to be delivered to\n // each distinct callback. The easiest way to achieve that\n // separation is to include c.callback in the cache key for\n // maybeBroadcastWatch calls. See issue #5733.\n c.callback,\n canonicalStringify({ optimistic, rootId, variables }),\n );\n }\n }\n });\n\n // Since we have thrown away all the cached functions that depend on the\n // CacheGroup dependencies maintained by EntityStore, we should also reset\n // all CacheGroup dependency information.\n new Set([\n this.data.group,\n this.optimisticData.group,\n ]).forEach(group => group.resetCaching());\n }\n\n public restore(data: NormalizedCacheObject): this {\n this.init();\n // Since calling this.init() discards/replaces the entire StoreReader, along\n // with the result caches it maintains, this.data.replace(data) won't have\n // to bother deleting the old data.\n if (data) this.data.replace(data);\n return this;\n }\n\n public extract(optimistic: boolean = false): NormalizedCacheObject {\n return (optimistic ? this.optimisticData : this.data).extract();\n }\n\n public read<T>(options: Cache.ReadOptions): T | null {\n const {\n // Since read returns data or null, without any additional metadata\n // about whether/where there might have been missing fields, the\n // default behavior cannot be returnPartialData = true (like it is\n // for the diff method), since defaulting to true would violate the\n // integrity of the T in the return type. However, partial data may\n // be useful in some cases, so returnPartialData:true may be\n // specified explicitly.\n returnPartialData = false,\n } = options;\n try {\n return this.storeReader.diffQueryAgainstStore<T>({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n config: this.config,\n returnPartialData,\n }).result || null;\n } catch (e) {\n if (e instanceof MissingFieldError) {\n // Swallow MissingFieldError and return null, so callers do not\n // need to worry about catching \"normal\" exceptions resulting from\n // incomplete cache data. Unexpected errors will be re-thrown. If\n // you need more information about which fields were missing, use\n // cache.diff instead, and examine diffResult.missing.\n return null;\n }\n throw e;\n }\n }\n\n public write(options: Cache.WriteOptions): Reference | undefined {\n try {\n ++this.txCount;\n return this.storeWriter.writeToStore(this.data, options);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public modify(options: Cache.ModifyOptions): boolean {\n if (hasOwn.call(options, \"id\") && !options.id) {\n // To my knowledge, TypeScript does not currently provide a way to\n // enforce that an optional property?:type must *not* be undefined\n // when present. That ability would be useful here, because we want\n // options.id to default to ROOT_QUERY only when no options.id was\n // provided. If the caller attempts to pass options.id with a\n // falsy/undefined value (perhaps because cache.identify failed), we\n // should not assume the goal was to modify the ROOT_QUERY object.\n // We could throw, but it seems natural to return false to indicate\n // that nothing was modified.\n return false;\n }\n const store = options.optimistic // Defaults to false.\n ? this.optimisticData\n : this.data;\n try {\n ++this.txCount;\n return store.modify(options.id || \"ROOT_QUERY\", options.fields);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public diff<T>(options: Cache.DiffOptions): Cache.DiffResult<T> {\n return this.storeReader.diffQueryAgainstStore({\n ...options,\n store: options.optimistic ? this.optimisticData : this.data,\n rootId: options.id || \"ROOT_QUERY\",\n config: this.config,\n });\n }\n\n public watch(watch: Cache.WatchOptions): () => void {\n if (!this.watches.size) {\n // In case we previously called forgetCache(this) because\n // this.watches became empty (see below), reattach this cache to any\n // reactive variables on which it previously depended. It might seem\n // paradoxical that we're able to recall something we supposedly\n // forgot, but the point of calling forgetCache(this) is to silence\n // useless broadcasts while this.watches is empty, and to allow the\n // cache to be garbage collected. If, however, we manage to call\n // recallCache(this) here, this cache object must not have been\n // garbage collected yet, and should resume receiving updates from\n // reactive variables, now that it has a watcher to notify.\n recallCache(this);\n }\n this.watches.add(watch);\n if (watch.immediate) {\n this.maybeBroadcastWatch(watch);\n }\n return () => {\n // Once we remove the last watch from this.watches, cache.broadcastWatches\n // no longer does anything, so we preemptively tell the reactive variable\n // system to exclude this cache from future broadcasts.\n if (this.watches.delete(watch) && !this.watches.size) {\n forgetCache(this);\n }\n // Remove this watch from the LRU cache managed by the\n // maybeBroadcastWatch OptimisticWrapperFunction, to prevent memory\n // leaks involving the closure of watch.callback.\n this.maybeBroadcastWatch.forget(watch);\n };\n }\n\n public gc(options?: {\n // If true, also free non-essential result cache memory by bulk-releasing\n // this.{store{Reader,Writer},maybeBroadcastWatch}. Defaults to false.\n resetResultCache?: boolean;\n // If resetResultCache is true, this.storeReader.canon will be preserved by\n // default, but can also be discarded by passing resetResultIdentities:true.\n // Defaults to false.\n resetResultIdentities?: boolean;\n }) {\n canonicalStringify.reset();\n const ids = this.optimisticData.gc();\n if (options && !this.txCount) {\n if (options.resetResultCache) {\n this.resetResultCache(options.resetResultIdentities);\n } else if (options.resetResultIdentities) {\n this.storeReader.resetCanon();\n }\n }\n return ids;\n }\n\n // Call this method to ensure the given root ID remains in the cache after\n // garbage collection, along with its transitive child entities. Note that\n // the cache automatically retains all directly written entities. By default,\n // the retainment persists after optimistic updates are removed. Pass true\n // for the optimistic argument if you would prefer for the retainment to be\n // discarded when the top-most optimistic layer is removed. Returns the\n // resulting (non-negative) retainment count.\n public retain(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).retain(rootId);\n }\n\n // Call this method to undo the effect of the retain method, above. Once the\n // retainment count falls to zero, the given ID will no longer be preserved\n // during garbage collection, though it may still be preserved by other safe\n // entities that refer to it. Returns the resulting (non-negative) retainment\n // count, in case that's useful.\n public release(rootId: string, optimistic?: boolean): number {\n return (optimistic ? this.optimisticData : this.data).release(rootId);\n }\n\n // Returns the canonical ID for a given StoreObject, obeying typePolicies\n // and keyFields (and dataIdFromObject, if you still use that). At minimum,\n // the object must contain a __typename and any primary key fields required\n // to identify entities of that type. If you pass a query result object, be\n // sure that none of the primary key fields have been renamed by aliasing.\n // If you pass a Reference object, its __ref ID string will be returned.\n public identify(object: StoreObject | Reference): string | undefined {\n return isReference(object) ? object.__ref :\n this.policies.identify(object)[0];\n }\n\n public evict(options: Cache.EvictOptions): boolean {\n if (!options.id) {\n if (hasOwn.call(options, \"id\")) {\n // See comment in modify method about why we return false when\n // options.id exists but is falsy/undefined.\n return false;\n }\n options = { ...options, id: \"ROOT_QUERY\" };\n }\n try {\n // It's unlikely that the eviction will end up invoking any other\n // cache update operations while it's running, but {in,de}crementing\n // this.txCount still seems like a good idea, for uniformity with\n // the other update methods.\n ++this.txCount;\n // Pass this.data as a limit on the depth of the eviction, so evictions\n // during optimistic updates (when this.data is temporarily set equal to\n // this.optimisticData) do not escape their optimistic Layer.\n return this.optimisticData.evict(options, this.data);\n } finally {\n if (!--this.txCount && options.broadcast !== false) {\n this.broadcastWatches();\n }\n }\n }\n\n public reset(options?: Cache.ResetOptions): Promise<void> {\n this.init();\n\n canonicalStringify.reset();\n\n if (options && options.discardWatches) {\n // Similar to what happens in the unsubscribe function returned by\n // cache.watch, applied to all current watches.\n this.watches.forEach(watch => this.maybeBroadcastWatch.forget(watch));\n this.watches.clear();\n forgetCache(this);\n } else {\n // Calling this.init() above unblocks all maybeBroadcastWatch caching, so\n // this.broadcastWatches() triggers a broadcast to every current watcher\n // (letting them know their data is now missing). This default behavior is\n // convenient because it means the watches do not have to be manually\n // reestablished after resetting the cache. To prevent this broadcast and\n // cancel all watches, pass true for options.discardWatches.\n this.broadcastWatches();\n }\n\n return Promise.resolve();\n }\n\n public removeOptimistic(idToRemove: string) {\n const newOptimisticData = this.optimisticData.removeLayer(idToRemove);\n if (newOptimisticData !== this.optimisticData) {\n this.optimisticData = newOptimisticData;\n this.broadcastWatches();\n }\n }\n\n private txCount = 0;\n\n public batch(options: Cache.BatchOptions<InMemoryCache>) {\n const {\n update,\n optimistic = true,\n removeOptimistic,\n onWatchUpdated,\n } = options;\n\n const perform = (layer?: EntityStore) => {\n const { data, optimisticData } = this;\n ++this.txCount;\n if (layer) {\n this.data = this.optimisticData = layer;\n }\n try {\n update(this);\n } finally {\n --this.txCount;\n this.data = data;\n this.optimisticData = optimisticData;\n }\n };\n\n const alreadyDirty = new Set<Cache.WatchOptions>();\n\n if (onWatchUpdated && !this.txCount) {\n // If an options.onWatchUpdated callback is provided, we want to call it\n // with only the Cache.WatchOptions objects affected by options.update,\n // but there might be dirty watchers already waiting to be broadcast that\n // have nothing to do with the update. To prevent including those watchers\n // in the post-update broadcast, we perform this initial broadcast to\n // collect the dirty watchers, so we can re-dirty them later, after the\n // post-update broadcast, allowing them to receive their pending\n // broadcasts the next time broadcastWatches is called, just as they would\n // if we never called cache.batch.\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch) {\n alreadyDirty.add(watch);\n return false;\n },\n });\n }\n\n if (typeof optimistic === 'string') {\n // Note that there can be multiple layers with the same optimistic ID.\n // When removeOptimistic(id) is called for that id, all matching layers\n // will be removed, and the remaining layers will be reapplied.\n this.optimisticData = this.optimisticData.addLayer(optimistic, perform);\n } else if (optimistic === false) {\n // Ensure both this.data and this.optimisticData refer to the root\n // (non-optimistic) layer of the cache during the update. Note that\n // this.data could be a Layer if we are currently executing an optimistic\n // update function, but otherwise will always be an EntityStore.Root\n // instance.\n perform(this.data);\n } else {\n // Otherwise, leave this.data and this.optimisticData unchanged and run\n // the update with broadcast batching.\n perform();\n }\n\n if (typeof removeOptimistic === \"string\") {\n this.optimisticData = this.optimisticData.removeLayer(removeOptimistic);\n }\n\n // Note: if this.txCount > 0, then alreadyDirty.size === 0, so this code\n // takes the else branch and calls this.broadcastWatches(options), which\n // does nothing when this.txCount > 0.\n if (onWatchUpdated && alreadyDirty.size) {\n this.broadcastWatches({\n ...options,\n onWatchUpdated(watch, diff) {\n const result = onWatchUpdated.call(this, watch, diff);\n if (result !== false) {\n // Since onWatchUpdated did not return false, this diff is\n // about to be broadcast to watch.callback, so we don't need\n // to re-dirty it with the other alreadyDirty watches below.\n alreadyDirty.delete(watch);\n }\n return result;\n }\n });\n // Silently re-dirty any watches that were already dirty before the update\n // was performed, and were not broadcast just now.\n if (alreadyDirty.size) {\n alreadyDirty.forEach(watch => this.maybeBroadcastWatch.dirty(watch));\n }\n } else {\n // If alreadyDirty is empty or we don't have an onWatchUpdated\n // function, we don't need to go to the trouble of wrapping\n // options.onWatchUpdated.\n this.broadcastWatches(options);\n }\n }\n\n public performTransaction(\n update: (cache: InMemoryCache) => any,\n optimisticId?: string | null,\n ) {\n return this.batch({\n update,\n optimistic: optimisticId || (optimisticId !== null),\n });\n }\n\n public transformDocument(document: DocumentNode): DocumentNode {\n if (this.addTypename) {\n let result = this.typenameDocumentCache.get(document);\n if (!result) {\n result = addTypenameToDocument(document);\n this.typenameDocumentCache.set(document, result);\n // If someone calls transformDocument and then mistakenly passes the\n // result back into an API that also calls transformDocument, make sure\n // we don't keep creating new query documents.\n this.typenameDocumentCache.set(result, result);\n }\n return result;\n }\n return document;\n }\n\n protected broadcastWatches(options?: BroadcastOptions) {\n if (!this.txCount) {\n this.watches.forEach(c => this.maybeBroadcastWatch(c, options));\n }\n }\n\n // This method is wrapped by maybeBroadcastWatch, which is called by\n // broadcastWatches, so that we compute and broadcast results only when\n // the data that would be broadcast might have changed. It would be\n // simpler to check for changes after recomputing a result but before\n // broadcasting it, but this wrapping approach allows us to skip both\n // the recomputation and the broadcast, in most cases.\n private broadcastWatch(\n c: Cache.WatchOptions,\n options?: BroadcastOptions,\n ) {\n const { lastDiff } = c;\n\n // Both WatchOptions and DiffOptions extend ReadOptions, and DiffOptions\n // currently requires no additional properties, so we can use c (a\n // WatchOptions object) as DiffOptions, without having to allocate a new\n // object, and without having to enumerate the relevant properties (query,\n // variables, etc.) explicitly. There will be some additional properties\n // (lastDiff, callback, etc.), but cache.diff ignores them.\n const diff = this.diff<any>(c);\n\n if (options) {\n if (c.optimistic &&\n typeof options.optimistic === \"string\") {\n diff.fromOptimisticTransaction = true;\n }\n\n if (options.onWatchUpdated &&\n options.onWatchUpdated.call(this, c, diff, lastDiff) === false) {\n // Returning false from the onWatchUpdated callback will prevent\n // calling c.callback(diff) for this watcher.\n return;\n }\n }\n\n if (!lastDiff || !equal(lastDiff.result, diff.result)) {\n c.callback(c.lastDiff = diff, lastDiff);\n }\n }\n}\n"]}
|
|
@@ -8,7 +8,7 @@ export declare type TypePolicies = {
|
|
|
8
8
|
[__typename: string]: TypePolicy;
|
|
9
9
|
};
|
|
10
10
|
declare type KeySpecifier = (string | any[])[];
|
|
11
|
-
declare type KeyFieldsContext = {
|
|
11
|
+
export declare type KeyFieldsContext = {
|
|
12
12
|
typename?: string;
|
|
13
13
|
selectionSet?: SelectionSetNode;
|
|
14
14
|
fragmentMap?: FragmentMap;
|
|
@@ -54,7 +54,6 @@ export interface FieldFunctionOptions<TArgs = Record<string, any>, TVars = Recor
|
|
|
54
54
|
declare type MergeObjectsFunction = <T extends StoreObject | Reference>(existing: T, incoming: T) => T;
|
|
55
55
|
export declare type FieldReadFunction<TExisting = any, TReadResult = TExisting> = (existing: SafeReadonly<TExisting> | undefined, options: FieldFunctionOptions) => TReadResult | undefined;
|
|
56
56
|
export declare type FieldMergeFunction<TExisting = any, TIncoming = TExisting> = (existing: SafeReadonly<TExisting> | undefined, incoming: SafeReadonly<TIncoming>, options: FieldFunctionOptions) => SafeReadonly<TExisting>;
|
|
57
|
-
export declare const defaultDataIdFromObject: ({ __typename, id, _id }: Readonly<StoreObject>, context?: KeyFieldsContext | undefined) => string | undefined;
|
|
58
57
|
export declare type PossibleTypesMap = {
|
|
59
58
|
[supertype: string]: string[];
|
|
60
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACV,MAAM,SAAS,CAAC;AAIjB,OAAO,EACL,WAAW,EAKX,UAAU,EACV,WAAW,EAEX,SAAS,EACT,WAAW,EAKZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,SAAS,EAET,sBAAsB,EACvB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/policies.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACV,MAAM,SAAS,CAAC;AAIjB,OAAO,EACL,WAAW,EAKX,UAAU,EACV,WAAW,EAEX,SAAS,EACT,WAAW,EAKZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,SAAS,EAET,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAUjB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS9C,oBAAY,YAAY,GAAG;IACzB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;CAClC,CAAA;AAID,aAAK,YAAY,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;AAEvC,oBAAY,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAG1B,SAAS,CAAC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AG,CAAC,GAC9B,OAAO;IAsFH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM;IAK1D,iBAAiB,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM;IA+CpD,SAAS,CAAC,CAAC,GAAG,UAAU,EAC7B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,sBAAsB,GAC9B,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IA2CvB,gBAAgB,CACrB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,kBAAkB,GAAG,SAAS;IAc1B,gBAAgB,CACrB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,UAAU,EACpB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,SAAS,EACrC,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,WAAW;CA+CxB"}
|
|
@@ -2,7 +2,7 @@ import { __assign, __rest } from "tslib";
|
|
|
2
2
|
import { invariant, InvariantError } from "../../utilities/globals/index.js";
|
|
3
3
|
import { Trie } from '@wry/trie';
|
|
4
4
|
import { getFragmentFromSelection, isField, getTypenameFromResult, storeKeyNameFromField, argumentsObjectFromField, isReference, getStoreKeyName, canUseWeakMap, isNonNullObject, stringifyForDisplay, } from "../../utilities/index.js";
|
|
5
|
-
import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, } from "./helpers.js";
|
|
5
|
+
import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMatchesResult, TypeOrFieldNameRegExp, defaultDataIdFromObject, } from "./helpers.js";
|
|
6
6
|
import { cacheSlot } from "./reactiveVars.js";
|
|
7
7
|
import { canonicalStringify } from "./object-canon.js";
|
|
8
8
|
getStoreKeyName.setStringify(canonicalStringify);
|
|
@@ -10,23 +10,6 @@ function argsFromFieldSpecifier(spec) {
|
|
|
10
10
|
return spec.args !== void 0 ? spec.args :
|
|
11
11
|
spec.field ? argumentsObjectFromField(spec.field, spec.variables) : null;
|
|
12
12
|
}
|
|
13
|
-
export var defaultDataIdFromObject = function (_a, context) {
|
|
14
|
-
var __typename = _a.__typename, id = _a.id, _id = _a._id;
|
|
15
|
-
if (typeof __typename === "string") {
|
|
16
|
-
if (context) {
|
|
17
|
-
context.keyObject =
|
|
18
|
-
id !== void 0 ? { id: id } :
|
|
19
|
-
_id !== void 0 ? { _id: _id } :
|
|
20
|
-
void 0;
|
|
21
|
-
}
|
|
22
|
-
if (id === void 0)
|
|
23
|
-
id = _id;
|
|
24
|
-
if (id !== void 0) {
|
|
25
|
-
return __typename + ":" + ((typeof id === "number" ||
|
|
26
|
-
typeof id === "string") ? id : JSON.stringify(id));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
13
|
var nullKeyFieldsFn = function () { return void 0; };
|
|
31
14
|
var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
|
|
32
15
|
var mergeTrueFn = function (existing, incoming, _a) {
|