UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

1 lines 138 kB
{"version":3,"file":"entityStore.cjs","sources":["../../../../src/cache/inmemory/entityStore.ts"],"sourcesContent":["import { equal } from \"@wry/equality\";\nimport { Trie } from \"@wry/trie\";\nimport type { DocumentNode, FieldNode, SelectionSetNode } from \"graphql\";\nimport type { OptimisticDependencyFunction } from \"optimism\";\nimport { dep } from \"optimism\";\n\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n} from \"@apollo/client/utilities\";\nimport { isReference } from \"@apollo/client/utilities\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport {\n DeepMerger,\n isNonNullObject,\n makeReference,\n maybeDeepFreeze,\n} from \"@apollo/client/utilities/internal\";\nimport { invariant } from \"@apollo/client/utilities/invariant\";\n\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n CanReadFunction,\n DeleteModifier,\n InvalidateModifier,\n Modifier,\n ModifierDetails,\n Modifiers,\n ReadFieldOptions,\n SafeReadonly,\n ToReferenceFunction,\n} from \"../core/types/common.js\";\n\nimport { fieldNameFromStoreName, hasOwn } from \"./helpers.js\";\nimport type { Policies, StorageType } from \"./policies.js\";\nimport type { NormalizedCache, NormalizedCacheObject } from \"./types.js\";\n\nconst DELETE = {} as DeleteModifier;\nconst delModifier: Modifier<any> = () => DELETE;\nconst INVALIDATE = {} as InvalidateModifier;\n\nexport abstract class EntityStore implements NormalizedCache {\n public declare static Root: typeof Root;\n\n protected data: NormalizedCacheObject = {};\n\n constructor(\n public readonly policies: Policies,\n public readonly group: CacheGroup\n ) {}\n\n public abstract addLayer(\n layerId: string,\n replay: (layer: EntityStore) => any\n ): Layer;\n\n public abstract removeLayer(layerId: string): EntityStore;\n\n // Although the EntityStore class is abstract, it contains concrete\n // implementations of the various NormalizedCache interface methods that\n // are inherited by the Root and Layer subclasses.\n\n public toObject(): NormalizedCacheObject {\n return { ...this.data };\n }\n\n public has(dataId: string): boolean {\n return this.lookup(dataId, true) !== void 0;\n }\n\n public get(dataId: string, fieldName: string): StoreValue {\n this.group.depend(dataId, fieldName);\n if (hasOwn.call(this.data, dataId)) {\n const storeObject = this.data[dataId];\n if (storeObject && hasOwn.call(storeObject, fieldName)) {\n return storeObject[fieldName];\n }\n }\n if (\n fieldName === \"__typename\" &&\n hasOwn.call(this.policies.rootTypenamesById, dataId)\n ) {\n return this.policies.rootTypenamesById[dataId];\n }\n if (this instanceof Layer) {\n return this.parent.get(dataId, fieldName);\n }\n }\n\n protected lookup(\n dataId: string,\n dependOnExistence?: boolean\n ): StoreObject | undefined {\n // The has method (above) calls lookup with dependOnExistence = true, so\n // that it can later be invalidated when we add or remove a StoreObject for\n // this dataId. Any consumer who cares about the contents of the StoreObject\n // should not rely on this dependency, since the contents could change\n // without the object being added or removed.\n if (dependOnExistence) this.group.depend(dataId, \"__exists\");\n\n if (hasOwn.call(this.data, dataId)) {\n return this.data[dataId];\n }\n\n if (this instanceof Layer) {\n return this.parent.lookup(dataId, dependOnExistence);\n }\n\n if (this.policies.rootTypenamesById[dataId]) {\n return {};\n }\n }\n\n public merge(older: string | StoreObject, newer: StoreObject | string): void {\n let dataId: string | undefined;\n\n // Convert unexpected references to ID strings.\n if (isReference(older)) older = older.__ref;\n if (isReference(newer)) newer = newer.__ref;\n\n const existing: StoreObject | undefined =\n typeof older === \"string\" ? this.lookup((dataId = older)) : older;\n\n const incoming: StoreObject | undefined =\n typeof newer === \"string\" ? this.lookup((dataId = newer)) : newer;\n\n // If newer was a string ID, but that ID was not defined in this store,\n // then there are no fields to be merged, so we're done.\n if (!incoming) return;\n\n invariant(typeof dataId === \"string\", \"store.merge expects a string ID\");\n\n const merged: StoreObject = new DeepMerger(storeObjectReconciler).merge(\n existing,\n incoming\n );\n\n // Even if merged === existing, existing may have come from a lower\n // layer, so we always need to set this.data[dataId] on this level.\n this.data[dataId] = merged;\n\n if (merged !== existing) {\n delete this.refs[dataId];\n if (this.group.caching) {\n const fieldsToDirty: Record<string, 1> = {};\n\n // If we added a new StoreObject where there was previously none, dirty\n // anything that depended on the existence of this dataId, such as the\n // EntityStore#has method.\n if (!existing) fieldsToDirty.__exists = 1;\n\n // Now invalidate dependents who called getFieldValue for any fields\n // that are changing as a result of this merge.\n Object.keys(incoming).forEach((storeFieldName) => {\n if (\n !existing ||\n existing[storeFieldName] !== merged[storeFieldName]\n ) {\n // Always dirty the full storeFieldName, which may include\n // serialized arguments following the fieldName prefix.\n fieldsToDirty[storeFieldName] = 1;\n\n // Also dirty fieldNameFromStoreName(storeFieldName) if it's\n // different from storeFieldName and this field does not have\n // keyArgs configured, because that means the cache can't make\n // any assumptions about how field values with the same field\n // name but different arguments might be interrelated, so it\n // must err on the side of invalidating all field values that\n // share the same short fieldName, regardless of arguments.\n const fieldName = fieldNameFromStoreName(storeFieldName);\n if (\n fieldName !== storeFieldName &&\n !this.policies.hasKeyArgs(merged.__typename, fieldName)\n ) {\n fieldsToDirty[fieldName] = 1;\n }\n\n // If merged[storeFieldName] has become undefined, and this is the\n // Root layer, actually delete the property from the merged object,\n // which is guaranteed to have been created fresh in this method.\n if (merged[storeFieldName] === void 0 && !(this instanceof Layer)) {\n delete merged[storeFieldName];\n }\n }\n });\n\n if (\n fieldsToDirty.__typename &&\n !(existing && existing.__typename) &&\n // Since we return default root __typename strings\n // automatically from store.get, we don't need to dirty the\n // ROOT_QUERY.__typename field if merged.__typename is equal\n // to the default string (usually \"Query\").\n this.policies.rootTypenamesById[dataId] === merged.__typename\n ) {\n delete fieldsToDirty.__typename;\n }\n\n Object.keys(fieldsToDirty).forEach((fieldName) =>\n this.group.dirty(dataId as string, fieldName)\n );\n }\n }\n }\n\n public modify(\n dataId: string,\n fields: Modifier<any> | Modifiers<Record<string, any>>,\n exact: boolean\n ): boolean {\n const storeObject = this.lookup(dataId);\n\n if (storeObject) {\n const changedFields: Record<string, any> = {};\n let needToMerge = false;\n let allDeleted = true;\n\n const sharedDetails = {\n DELETE,\n INVALIDATE,\n isReference,\n toReference: this.toReference,\n canRead: this.canRead,\n readField: <V = StoreValue>(\n fieldNameOrOptions: string | ReadFieldOptions,\n from?: StoreObject | Reference\n ) =>\n this.policies.readField<V>(\n typeof fieldNameOrOptions === \"string\" ?\n {\n fieldName: fieldNameOrOptions,\n from: from || makeReference(dataId),\n }\n : fieldNameOrOptions,\n { store: this }\n ),\n } satisfies Partial<ModifierDetails>;\n\n Object.keys(storeObject).forEach((storeFieldName) => {\n const fieldName = fieldNameFromStoreName(storeFieldName);\n let fieldValue = storeObject[storeFieldName];\n if (fieldValue === void 0) return;\n const modify: Modifier<StoreValue> | undefined =\n typeof fields === \"function\" ? fields : (\n fields[storeFieldName] || (exact ? undefined : fields[fieldName])\n );\n if (modify) {\n let newValue =\n modify === delModifier ? DELETE : (\n modify(maybeDeepFreeze(fieldValue), {\n ...sharedDetails,\n fieldName,\n storeFieldName,\n storage: this.getStorage(dataId, storeFieldName),\n })\n );\n if (newValue === INVALIDATE) {\n this.group.dirty(dataId, storeFieldName);\n } else {\n if (newValue === DELETE) newValue = void 0;\n if (newValue !== fieldValue) {\n changedFields[storeFieldName] = newValue;\n needToMerge = true;\n fieldValue = newValue as StoreValue;\n\n if (__DEV__) {\n const checkReference = (ref: Reference) => {\n if (this.lookup(ref.__ref) === undefined) {\n invariant.warn(\n \"cache.modify: You are trying to write a Reference that is not part of the store: %o\\n\" +\n \"Please make sure to set the `mergeIntoStore` parameter to `true` when creating a Reference that is not part of the store yet:\\n\" +\n \"`toReference(object, true)`\",\n ref\n );\n return true;\n }\n };\n if (isReference(newValue)) {\n checkReference(newValue);\n } else if (Array.isArray(newValue)) {\n // Warn about writing \"mixed\" arrays of Reference and non-Reference objects\n let seenReference: boolean = false;\n let someNonReference: unknown;\n for (const value of newValue) {\n if (isReference(value)) {\n seenReference = true;\n if (checkReference(value)) break;\n } else {\n // Do not warn on primitive values, since those could never be represented\n // by a reference. This is a valid (albeit uncommon) use case.\n if (typeof value === \"object\" && !!value) {\n const [id] = this.policies.identify(value);\n // check if object could even be referenced, otherwise we are not interested in it for this warning\n if (id) {\n someNonReference = value;\n }\n }\n }\n if (seenReference && someNonReference !== undefined) {\n invariant.warn(\n \"cache.modify: Writing an array with a mix of both References and Objects will not result in the Objects being normalized correctly.\\n\" +\n \"Please convert the object instance %o to a Reference before writing it to the cache by calling `toReference(object, true)`.\",\n someNonReference\n );\n break;\n }\n }\n }\n }\n }\n }\n }\n if (fieldValue !== void 0) {\n allDeleted = false;\n }\n });\n\n if (needToMerge) {\n this.merge(dataId, changedFields);\n\n if (allDeleted) {\n if (this instanceof Layer) {\n this.data[dataId] = void 0;\n } else {\n delete this.data[dataId];\n }\n this.group.dirty(dataId, \"__exists\");\n }\n\n return true;\n }\n }\n\n return false;\n }\n\n // If called with only one argument, removes the entire entity\n // identified by dataId. If called with a fieldName as well, removes all\n // fields of that entity whose names match fieldName according to the\n // fieldNameFromStoreName helper function. If called with a fieldName\n // and variables, removes all fields of that entity whose names match fieldName\n // and whose arguments when cached exactly match the variables passed.\n public delete(\n dataId: string,\n fieldName?: string,\n args?: Record<string, any>\n ) {\n const storeObject = this.lookup(dataId);\n if (storeObject) {\n const typename = this.getFieldValue<string>(storeObject, \"__typename\");\n const storeFieldName =\n fieldName && args ?\n this.policies.getStoreFieldName({ typename, fieldName, args })\n : fieldName;\n return this.modify(\n dataId,\n storeFieldName ?\n {\n [storeFieldName]: delModifier,\n }\n : delModifier,\n !!args\n );\n }\n return false;\n }\n\n public evict(options: Cache.EvictOptions, limit: EntityStore): boolean {\n let evicted = false;\n if (options.id) {\n if (hasOwn.call(this.data, options.id)) {\n evicted = this.delete(options.id, options.fieldName, options.args);\n }\n if (this instanceof Layer && this !== limit) {\n evicted = this.parent.evict(options, limit) || evicted;\n }\n // Always invalidate the field to trigger rereading of watched\n // queries, even if no cache data was modified by the eviction,\n // because queries may depend on computed fields with custom read\n // functions, whose values are not stored in the EntityStore.\n if (options.fieldName || evicted) {\n this.group.dirty(options.id, options.fieldName || \"__exists\");\n }\n }\n return evicted;\n }\n\n public clear(): void {\n this.replace(null);\n }\n\n public extract(): NormalizedCacheObject {\n const obj = this.toObject();\n const extraRootIds: string[] = [];\n this.getRootIdSet().forEach((id) => {\n if (!hasOwn.call(this.policies.rootTypenamesById, id)) {\n extraRootIds.push(id);\n }\n });\n if (extraRootIds.length) {\n obj.__META = { extraRootIds: extraRootIds.sort() };\n }\n return obj;\n }\n\n public replace(newData: NormalizedCacheObject | null): void {\n Object.keys(this.data).forEach((dataId) => {\n if (!(newData && hasOwn.call(newData, dataId))) {\n this.delete(dataId);\n }\n });\n if (newData) {\n const { __META, ...rest } = newData;\n Object.keys(rest).forEach((dataId) => {\n this.merge(dataId, rest[dataId] as StoreObject);\n });\n if (__META) {\n __META.extraRootIds.forEach(this.retain, this);\n }\n }\n }\n\n public abstract getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n\n // Maps root entity IDs to the number of times they have been retained, minus\n // the number of times they have been released. Retained entities keep other\n // entities they reference (even indirectly) from being garbage collected.\n private rootIds: {\n [rootId: string]: number;\n } = {};\n\n public retain(rootId: string): number {\n return (this.rootIds[rootId] = (this.rootIds[rootId] || 0) + 1);\n }\n\n public release(rootId: string): number {\n if (this.rootIds[rootId] > 0) {\n const count = --this.rootIds[rootId];\n if (!count) delete this.rootIds[rootId];\n return count;\n }\n return 0;\n }\n\n // Return a Set<string> of all the ID strings that have been retained by\n // this layer/root *and* any layers/roots beneath it.\n public getRootIdSet(ids = new Set<string>()) {\n Object.keys(this.rootIds).forEach(ids.add, ids);\n if (this instanceof Layer) {\n this.parent.getRootIdSet(ids);\n } else {\n // Official singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered roots for garbage collection, regardless of\n // their retainment counts in this.rootIds.\n Object.keys(this.policies.rootTypenamesById).forEach(ids.add, ids);\n }\n return ids;\n }\n\n // The goal of garbage collection is to remove IDs from the Root layer of the\n // store that are no longer reachable starting from any IDs that have been\n // explicitly retained (see retain and release, above). Returns an array of\n // dataId strings that were removed from the store.\n public gc() {\n const ids = this.getRootIdSet();\n const snapshot = this.toObject();\n ids.forEach((id) => {\n if (hasOwn.call(snapshot, id)) {\n // Because we are iterating over an ECMAScript Set, the IDs we add here\n // will be visited in later iterations of the forEach loop only if they\n // were not previously contained by the Set.\n Object.keys(this.findChildRefIds(id)).forEach(ids.add, ids);\n // By removing IDs from the snapshot object here, we protect them from\n // getting removed from the root store layer below.\n delete snapshot[id];\n }\n });\n const idsToRemove = Object.keys(snapshot);\n if (idsToRemove.length) {\n let root: EntityStore = this;\n while (root instanceof Layer) root = root.parent;\n idsToRemove.forEach((id) => root.delete(id));\n }\n return idsToRemove;\n }\n\n // Lazily tracks { __ref: <dataId> } strings contained by this.data[dataId].\n private refs: {\n [dataId: string]: Record<string, true>;\n } = {};\n\n public findChildRefIds(dataId: string): Record<string, true> {\n if (!hasOwn.call(this.refs, dataId)) {\n const found = (this.refs[dataId] = {} as Record<string, true>);\n const root = this.data[dataId];\n if (!root) return found;\n\n const workSet = new Set<Record<string | number, any>>([root]);\n // Within the store, only arrays and objects can contain child entity\n // references, so we can prune the traversal using this predicate:\n workSet.forEach((obj) => {\n if (isReference(obj)) {\n found[obj.__ref] = true;\n // In rare cases, a { __ref } Reference object may have other fields.\n // This often indicates a mismerging of References with StoreObjects,\n // but garbage collection should not be fooled by a stray __ref\n // property in a StoreObject (ignoring all the other fields just\n // because the StoreObject looks like a Reference). To avoid this\n // premature termination of findChildRefIds recursion, we fall through\n // to the code below, which will handle any other properties of obj.\n }\n if (isNonNullObject(obj)) {\n Object.keys(obj).forEach((key) => {\n const child = obj[key];\n // No need to add primitive values to the workSet, since they cannot\n // contain reference objects.\n if (isNonNullObject(child)) {\n workSet.add(child);\n }\n });\n }\n });\n }\n return this.refs[dataId];\n }\n\n // Used to compute cache keys specific to this.group.\n /** overload for `InMemoryCache.maybeBroadcastWatch` */\n public makeCacheKey(\n document: DocumentNode,\n callback: Cache.WatchCallback<any>,\n details: string\n ): object;\n /** overload for `StoreReader.executeSelectionSet` */\n public makeCacheKey(\n selectionSet: SelectionSetNode,\n parent: string /* = ( Reference.__ref ) */ | StoreObject,\n varString: string | undefined\n ): object;\n /** overload for `StoreReader.executeSubSelectedArray` */\n public makeCacheKey(\n field: FieldNode,\n array: readonly any[],\n varString: string | undefined\n ): object;\n /**\n * @deprecated This is only meant for internal usage,\n * in your own code please use a `Trie` instance instead.\n */\n public makeCacheKey(...args: any[]): object;\n public makeCacheKey() {\n return this.group.keyMaker.lookupArray(arguments);\n }\n\n // Bound function that can be passed around to provide easy access to fields\n // of Reference objects as well as ordinary objects.\n public getFieldValue = <T = StoreValue>(\n objectOrReference: StoreObject | Reference | undefined,\n storeFieldName: string\n ) =>\n maybeDeepFreeze(\n isReference(objectOrReference) ?\n this.get(objectOrReference.__ref, storeFieldName)\n : objectOrReference && objectOrReference[storeFieldName]\n ) as SafeReadonly<T>;\n\n // Returns true for non-normalized StoreObjects and non-dangling\n // References, indicating that readField(name, objOrRef) has a chance of\n // working. Useful for filtering out dangling references from lists.\n public canRead: CanReadFunction = (objOrRef) => {\n return isReference(objOrRef) ?\n this.has(objOrRef.__ref)\n : typeof objOrRef === \"object\";\n };\n\n // Bound function that converts an id or an object with a __typename and\n // primary key fields to a Reference object. If called with a Reference object,\n // that same Reference object is returned. Pass true for mergeIntoStore to persist\n // an object into the store.\n public toReference: ToReferenceFunction = (objOrIdOrRef, mergeIntoStore) => {\n if (typeof objOrIdOrRef === \"string\") {\n return makeReference(objOrIdOrRef);\n }\n\n if (isReference(objOrIdOrRef)) {\n return objOrIdOrRef;\n }\n\n const [id] = this.policies.identify(objOrIdOrRef);\n\n if (id) {\n const ref = makeReference(id);\n if (mergeIntoStore) {\n this.merge(id, objOrIdOrRef);\n }\n return ref;\n }\n };\n\n public get supportsResultCaching(): boolean {\n return this.group.caching;\n }\n}\n\nexport type FieldValueGetter = EntityStore[\"getFieldValue\"];\n\n// A single CacheGroup represents a set of one or more EntityStore objects,\n// typically the Root store in a CacheGroup by itself, and all active Layer\n// stores in a group together. A single EntityStore object belongs to only\n// one CacheGroup, store.group. The CacheGroup is responsible for tracking\n// dependencies, so store.group is helpful for generating unique keys for\n// cached results that need to be invalidated when/if those dependencies\n// change. If we used the EntityStore objects themselves as cache keys (that\n// is, store rather than store.group), the cache would become unnecessarily\n// fragmented by all the different Layer objects. Instead, the CacheGroup\n// approach allows all optimistic Layer objects in the same linked list to\n// belong to one CacheGroup, with the non-optimistic Root object belonging\n// to another CacheGroup, allowing resultCaching dependencies to be tracked\n// separately for optimistic and non-optimistic entity data.\nclass CacheGroup {\n private d: OptimisticDependencyFunction<string> | null = null;\n\n // Used by the EntityStore#makeCacheKey method to compute cache keys\n // specific to this CacheGroup.\n public keyMaker!: Trie<object>;\n\n constructor(\n public readonly caching: boolean,\n private parent: CacheGroup | null = null\n ) {\n this.resetCaching();\n }\n\n public resetCaching() {\n this.d = this.caching ? dep<string>() : null;\n this.keyMaker = new Trie();\n }\n\n public depend(dataId: string, storeFieldName: string) {\n if (this.d) {\n this.d(makeDepKey(dataId, storeFieldName));\n const fieldName = fieldNameFromStoreName(storeFieldName);\n if (fieldName !== storeFieldName) {\n // Fields with arguments that contribute extra identifying\n // information to the fieldName (thus forming the storeFieldName)\n // depend not only on the full storeFieldName but also on the\n // short fieldName, so the field can be invalidated using either\n // level of specificity.\n this.d(makeDepKey(dataId, fieldName));\n }\n if (this.parent) {\n this.parent.depend(dataId, storeFieldName);\n }\n }\n }\n\n public dirty(dataId: string, storeFieldName: string) {\n if (this.d) {\n this.d.dirty(\n makeDepKey(dataId, storeFieldName),\n // When storeFieldName === \"__exists\", that means the entity identified\n // by dataId has either disappeared from the cache or was newly added,\n // so the result caching system would do well to \"forget everything it\n // knows\" about that object. To achieve that kind of invalidation, we\n // not only dirty the associated result cache entry, but also remove it\n // completely from the dependency graph. For the optimism implementation\n // details, see https://github.com/benjamn/optimism/pull/195.\n storeFieldName === \"__exists\" ? \"forget\" : \"setDirty\"\n );\n }\n }\n}\n\nfunction makeDepKey(dataId: string, storeFieldName: string) {\n // Since field names cannot have '#' characters in them, this method\n // of joining the field name and the ID should be unambiguous, and much\n // cheaper than JSON.stringify([dataId, fieldName]).\n return storeFieldName + \"#\" + dataId;\n}\n\nexport function maybeDependOnExistenceOfEntity(\n store: NormalizedCache,\n entityId: string\n) {\n if (supportsResultCaching(store)) {\n // We use this pseudo-field __exists elsewhere in the EntityStore code to\n // represent changes in the existence of the entity object identified by\n // entityId. This dependency gets reliably dirtied whenever an object with\n // this ID is deleted (or newly created) within this group, so any result\n // cache entries (for example, StoreReader#executeSelectionSet results) that\n // depend on __exists for this entityId will get dirtied as well, leading to\n // the eventual recomputation (instead of reuse) of those result objects the\n // next time someone reads them from the cache.\n store.group.depend(entityId, \"__exists\");\n }\n}\n\nclass Root extends EntityStore {\n constructor({\n policies,\n resultCaching = true,\n seed,\n }: {\n policies: Policies;\n resultCaching?: boolean;\n seed?: NormalizedCacheObject;\n }) {\n super(policies, new CacheGroup(resultCaching));\n if (seed) this.replace(seed);\n }\n\n public readonly stump = new Stump(this);\n\n public addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer {\n // Adding an optimistic Layer on top of the Root actually adds the Layer\n // on top of the Stump, so the Stump always comes between the Root and\n // any Layer objects that we've added.\n return this.stump.addLayer(layerId, replay);\n }\n\n public removeLayer(): Root {\n // Never remove the root layer.\n return this;\n }\n\n public readonly storageTrie = new Trie<StorageType>();\n public getStorage(): StorageType {\n return this.storageTrie.lookupArray(arguments);\n }\n}\nEntityStore.Root = Root;\n\n// Not exported, since all Layer instances are created by the addLayer method\n// of the EntityStore.Root class.\nclass Layer extends EntityStore {\n constructor(\n public readonly id: string,\n public readonly parent: EntityStore,\n public readonly replay: (layer: EntityStore) => any,\n public readonly group: CacheGroup\n ) {\n super(parent.policies, group);\n replay(this);\n }\n\n public addLayer(layerId: string, replay: (layer: EntityStore) => any): Layer {\n return new Layer(layerId, this, replay, this.group);\n }\n\n public removeLayer(layerId: string): EntityStore {\n // Remove all instances of the given id, not just the first one.\n const parent = this.parent.removeLayer(layerId);\n\n if (layerId === this.id) {\n if (this.group.caching) {\n // Dirty every ID we're removing. Technically we might be able to avoid\n // dirtying fields that have values in higher layers, but we don't have\n // easy access to higher layers here, and we're about to recreate those\n // layers anyway (see parent.addLayer below).\n Object.keys(this.data).forEach((dataId) => {\n const ownStoreObject = this.data[dataId];\n const parentStoreObject = parent[\"lookup\"](dataId);\n if (!parentStoreObject) {\n // The StoreObject identified by dataId was defined in this layer\n // but will be undefined in the parent layer, so we can delete the\n // whole entity using this.delete(dataId). Since we're about to\n // throw this layer away, the only goal of this deletion is to dirty\n // the removed fields.\n this.delete(dataId);\n } else if (!ownStoreObject) {\n // This layer had an entry for dataId but it was undefined, which\n // means the entity was deleted in this layer, and it's about to\n // become undeleted when we remove this layer, so we need to dirty\n // all fields that are about to be reexposed.\n this.group.dirty(dataId, \"__exists\");\n Object.keys(parentStoreObject).forEach((storeFieldName) => {\n this.group.dirty(dataId, storeFieldName);\n });\n } else if (ownStoreObject !== parentStoreObject) {\n // If ownStoreObject is not exactly the same as parentStoreObject,\n // dirty any fields whose values will change as a result of this\n // removal.\n Object.keys(ownStoreObject).forEach((storeFieldName) => {\n if (\n !equal(\n ownStoreObject[storeFieldName],\n parentStoreObject[storeFieldName]\n )\n ) {\n this.group.dirty(dataId, storeFieldName);\n }\n });\n }\n });\n }\n\n return parent;\n }\n\n // No changes are necessary if the parent chain remains identical.\n if (parent === this.parent) return this;\n\n // Recreate this layer on top of the new parent.\n return parent.addLayer(this.id, this.replay);\n }\n\n public toObject(): NormalizedCacheObject {\n return {\n ...this.parent.toObject(),\n ...this.data,\n };\n }\n\n public findChildRefIds(dataId: string): Record<string, true> {\n const fromParent = this.parent.findChildRefIds(dataId);\n return hasOwn.call(this.data, dataId) ?\n {\n ...fromParent,\n ...super.findChildRefIds(dataId),\n }\n : fromParent;\n }\n\n public getStorage(\n ...args: Parameters<EntityStore[\"getStorage\"]>\n ): StorageType {\n let p: EntityStore = this.parent;\n while ((p as Layer).parent) p = (p as Layer).parent;\n return p.getStorage(...args);\n }\n}\n\n// Represents a Layer permanently installed just above the Root, which allows\n// reading optimistically (and registering optimistic dependencies) even when\n// no optimistic layers are currently active. The stump.group CacheGroup object\n// is shared by any/all Layer objects added on top of the Stump.\nclass Stump extends Layer {\n constructor(root: Root) {\n super(\n \"EntityStore.Stump\",\n root,\n () => {},\n new CacheGroup(root.group.caching, root.group)\n );\n }\n\n public removeLayer() {\n // Never remove the Stump layer.\n return this;\n }\n\n public merge(older: string | StoreObject, newer: string | StoreObject) {\n // We never want to write any data into the Stump, so we forward any merge\n // calls to the Root instead. Another option here would be to throw an\n // exception, but the toReference(object, true) function can sometimes\n // trigger Stump writes (which used to be Root writes, before the Stump\n // concept was introduced).\n return this.parent.merge(older, newer);\n }\n}\n\nfunction storeObjectReconciler(\n existingObject: StoreObject,\n incomingObject: StoreObject,\n property: string | number\n): StoreValue {\n const existingValue = existingObject[property];\n const incomingValue = incomingObject[property];\n // Wherever there is a key collision, prefer the incoming value, unless\n // it is deeply equal to the existing value. It's worth checking deep\n // equality here (even though blindly returning incoming would be\n // logically correct) because preserving the referential identity of\n // existing data can prevent needless rereading and rerendering.\n return equal(existingValue, incomingValue) ? existingValue : incomingValue;\n}\n\nexport function supportsResultCaching(store: any): store is EntityStore {\n // When result caching is disabled, store.depend will be null.\n return !!(store && store.supportsResultCaching);\n}\n"],"names":[],"mappings":";;;;;;;AA4qBA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA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