@apollo/client 3.8.5 → 3.8.6
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 +114 -74
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +46 -11
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +46 -11
- package/cache/core/types/common.d.ts +2 -2
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +35 -0
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.js +4 -4
- package/core/ApolloClient.js +3 -3
- package/core/LocalState.js +2 -2
- package/core/ObservableQuery.js +5 -5
- package/core/QueryManager.js +9 -9
- package/core/core.cjs +20 -20
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +20 -20
- package/dev/dev.cjs +97 -82
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +97 -82
- package/dev/loadErrorMessageHandler.js +1 -1
- package/dev/loadErrorMessageHandler.js.map +1 -1
- package/invariantErrorCodes.js +95 -80
- package/link/core/ApolloLink.js +2 -2
- package/link/core/core.cjs +2 -2
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -2
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/http.cjs +3 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +3 -3
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs +2 -2
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +2 -2
- package/link/utils/toPromise.js +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js +1 -1
- package/package.json +21 -21
- package/react/cache/QueryReference.d.ts.map +1 -1
- package/react/cache/QueryReference.js +7 -2
- package/react/cache/QueryReference.js.map +1 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs +3 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +3 -3
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs +2 -2
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -2
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs +15 -10
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +15 -10
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useQuery.js +1 -1
- package/react/hooks/useReadQuery.js +1 -1
- package/react/hooks/useSubscription.js +2 -2
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/parser/index.js +5 -5
- package/react/parser/parser.cjs +5 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +5 -5
- package/testing/core/core.cjs +1 -1
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +1 -1
- package/testing/core/mocking/mockLink.js +1 -1
- package/testing/react/MockedProvider.d.ts +1 -0
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +2 -1
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +2 -1
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +2 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.d.ts +5 -0
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/index.d.ts +1 -1
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +19 -19
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +19 -19
- package/version.js +1 -1
|
@@ -370,6 +370,41 @@ exports.EntityStore = (function () {
|
|
|
370
370
|
changedFields_1[storeFieldName] = newValue;
|
|
371
371
|
needToMerge_1 = true;
|
|
372
372
|
fieldValue = newValue;
|
|
373
|
+
if (globalThis.__DEV__ !== false) {
|
|
374
|
+
var checkReference = function (ref) {
|
|
375
|
+
if (_this.lookup(ref.__ref) === undefined) {
|
|
376
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(2, ref);
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
if (utilities.isReference(newValue)) {
|
|
381
|
+
checkReference(newValue);
|
|
382
|
+
}
|
|
383
|
+
else if (Array.isArray(newValue)) {
|
|
384
|
+
var seenReference = false;
|
|
385
|
+
var someNonReference = void 0;
|
|
386
|
+
for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
|
|
387
|
+
var value = newValue_1[_i];
|
|
388
|
+
if (utilities.isReference(value)) {
|
|
389
|
+
seenReference = true;
|
|
390
|
+
if (checkReference(value))
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
if (typeof value === "object" && !!value) {
|
|
395
|
+
var id = _this.policies.identify(value)[0];
|
|
396
|
+
if (id) {
|
|
397
|
+
someNonReference = value;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (seenReference && someNonReference !== undefined) {
|
|
402
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(3, someNonReference);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
373
408
|
}
|
|
374
409
|
}
|
|
375
410
|
}
|
|
@@ -961,7 +996,7 @@ var StoreReader = (function () {
|
|
|
961
996
|
else {
|
|
962
997
|
var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
|
|
963
998
|
if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
964
|
-
throw globals.newInvariantError(
|
|
999
|
+
throw globals.newInvariantError(9, selection.name.value);
|
|
965
1000
|
}
|
|
966
1001
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
967
1002
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -1045,7 +1080,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
1045
1080
|
if (utilities.isNonNullObject(value)) {
|
|
1046
1081
|
globals.invariant(
|
|
1047
1082
|
!utilities.isReference(value),
|
|
1048
|
-
|
|
1083
|
+
10,
|
|
1049
1084
|
getTypenameFromStoreObject(store, value),
|
|
1050
1085
|
field.name.value
|
|
1051
1086
|
);
|
|
@@ -1137,7 +1172,7 @@ function keyFieldsFnFromSpecifier(specifier) {
|
|
|
1137
1172
|
hasOwn.call(object, schemaKeyPath[0])) {
|
|
1138
1173
|
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
1139
1174
|
}
|
|
1140
|
-
globals.invariant(extracted !== void 0,
|
|
1175
|
+
globals.invariant(extracted !== void 0, 4, schemaKeyPath.join("."), object);
|
|
1141
1176
|
return extracted;
|
|
1142
1177
|
}));
|
|
1143
1178
|
return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
|
|
@@ -1392,7 +1427,7 @@ var Policies = (function () {
|
|
|
1392
1427
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
1393
1428
|
var old = this.rootTypenamesById[rootId];
|
|
1394
1429
|
if (typename !== old) {
|
|
1395
|
-
globals.invariant(!old || old === which,
|
|
1430
|
+
globals.invariant(!old || old === which, 5, which);
|
|
1396
1431
|
if (old)
|
|
1397
1432
|
delete this.rootIdsByTypename[old];
|
|
1398
1433
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -1489,7 +1524,7 @@ var Policies = (function () {
|
|
|
1489
1524
|
if (supertypeSet.has(supertype)) {
|
|
1490
1525
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
1491
1526
|
if (checkingFuzzySubtypes) {
|
|
1492
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1527
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(6, typename, supertype);
|
|
1493
1528
|
}
|
|
1494
1529
|
typenameSupertypeSet.add(supertype);
|
|
1495
1530
|
}
|
|
@@ -1651,7 +1686,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
1651
1686
|
}
|
|
1652
1687
|
}
|
|
1653
1688
|
if (globalThis.__DEV__ !== false && options.from === void 0) {
|
|
1654
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1689
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(7, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
|
|
1655
1690
|
}
|
|
1656
1691
|
if (void 0 === options.variables) {
|
|
1657
1692
|
options.variables = variables;
|
|
@@ -1661,7 +1696,7 @@ function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables)
|
|
|
1661
1696
|
function makeMergeObjectsFunction(store) {
|
|
1662
1697
|
return function mergeObjects(existing, incoming) {
|
|
1663
1698
|
if (utilities.isArray(existing) || utilities.isArray(incoming)) {
|
|
1664
|
-
throw globals.newInvariantError(
|
|
1699
|
+
throw globals.newInvariantError(8);
|
|
1665
1700
|
}
|
|
1666
1701
|
if (utilities.isNonNullObject(existing) && utilities.isNonNullObject(incoming)) {
|
|
1667
1702
|
var eType = store.getFieldValue(existing, "__typename");
|
|
@@ -1721,7 +1756,7 @@ var StoreWriter = (function () {
|
|
|
1721
1756
|
context: context,
|
|
1722
1757
|
});
|
|
1723
1758
|
if (!utilities.isReference(ref)) {
|
|
1724
|
-
throw globals.newInvariantError(
|
|
1759
|
+
throw globals.newInvariantError(11, result);
|
|
1725
1760
|
}
|
|
1726
1761
|
context.incomingById.forEach(function (_a, dataId) {
|
|
1727
1762
|
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
@@ -1826,7 +1861,7 @@ var StoreWriter = (function () {
|
|
|
1826
1861
|
!context.deferred &&
|
|
1827
1862
|
!utilities.addTypenameToDocument.added(field) &&
|
|
1828
1863
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
1829
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
1864
|
+
globalThis.__DEV__ !== false && globals.invariant.error(12, utilities.resultKeyNameFromField(field), result);
|
|
1830
1865
|
}
|
|
1831
1866
|
});
|
|
1832
1867
|
try {
|
|
@@ -1931,7 +1966,7 @@ var StoreWriter = (function () {
|
|
|
1931
1966
|
else {
|
|
1932
1967
|
var fragment = utilities.getFragmentFromSelection(selection, context.lookupFragment);
|
|
1933
1968
|
if (!fragment && selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
1934
|
-
throw globals.newInvariantError(
|
|
1969
|
+
throw globals.newInvariantError(13, selection.name.value);
|
|
1935
1970
|
}
|
|
1936
1971
|
if (fragment &&
|
|
1937
1972
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -2073,7 +2108,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
2073
2108
|
}
|
|
2074
2109
|
});
|
|
2075
2110
|
}
|
|
2076
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
2111
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(14, fieldName, parentType, childTypenames.length
|
|
2077
2112
|
? "either ensure all objects of type " +
|
|
2078
2113
|
childTypenames.join(" and ") +
|
|
2079
2114
|
" have an ID or a custom merge function, or "
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, FieldNode } from "graphql";
|
|
2
|
-
import type { Reference, StoreObject, StoreValue, isReference } from "../../../utilities/index.js";
|
|
2
|
+
import type { Reference, StoreObject, StoreValue, isReference, AsStoreObject } from "../../../utilities/index.js";
|
|
3
3
|
import type { StorageType } from "../../inmemory/policies.js";
|
|
4
4
|
export type SafeReadonly<T> = T extends object ? Readonly<T> : T;
|
|
5
5
|
export type MissingTree = string | {
|
|
@@ -49,7 +49,7 @@ export type ModifierDetails = {
|
|
|
49
49
|
storage: StorageType;
|
|
50
50
|
};
|
|
51
51
|
export type Modifier<T> = (value: T, details: ModifierDetails) => T | DeleteModifier | InvalidateModifier;
|
|
52
|
-
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Record<string, any
|
|
52
|
+
type StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Array<infer Item extends Record<string, any>> ? ReadonlyArray<AsStoreObject<Item> | Reference> : StoreVal extends Record<string, any> ? AsStoreObject<StoreVal> | Reference : StoreVal;
|
|
53
53
|
export type AllFieldsModifier<Entity extends Record<string, any>> = Modifier<Entity[keyof Entity] extends infer Value ? StoreObjectValueMaybeReference<Exclude<Value, undefined>> : never>;
|
|
54
54
|
export type Modifiers<T extends Record<string, any> = Record<string, unknown>> = Partial<{
|
|
55
55
|
[FieldName in keyof T]: Modifier<StoreObjectValueMaybeReference<Exclude<T[FieldName], undefined>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,KA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KACrB,CAAC,GAAG,cAAc,GAAG,kBAAkB,CAAC;AAE7C,KAAK,8BAA8B,CAAC,QAAQ,IAAI,QAAQ,SAAS,KAAK,CACpE,MAAM,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACvC,GACG,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,GAC9C,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACpC,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,GACnC,QAAQ,CAAC;AAEb,MAAM,MAAM,iBAAiB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,QAAQ,CAC1E,MAAM,CAAC,MAAM,MAAM,CAAC,SAAS,MAAM,KAAK,GACpC,8BAA8B,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,GACzD,KAAK,CACV,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC3E,OAAO,CAAC;KACL,SAAS,IAAI,MAAM,CAAC,GAAG,QAAQ,CAC9B,8BAA8B,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC,CACjE;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/cache/core/types/common.ts"],"names":[],"mappings":";AA2BA;IAAuC,qCAAK;IAC1C,2BACkB,OAAe,EACf,IAA0C,EAC1C,KAAmB,EACnB,SAA+B;;QAJjD,YAOE,kBAAM,OAAO,CAAC,SAcf;QApBiB,aAAO,GAAP,OAAO,CAAQ;QACf,UAAI,GAAJ,IAAI,CAAsC;QAC1C,WAAK,GAAL,KAAK,CAAc;QACnB,eAAS,GAAT,SAAS,CAAsB;QAK/C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAI,CAAC,IAAI,CAAC,EAAE;YAC5B,KAAI,CAAC,OAAO,GAAG,KAAI,CAAC,OAAO,CAAC;YAC5B,KAAK,IAAI,CAAC,GAAG,KAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE;gBAC9C,KAAI,CAAC,OAAO,aAAK,GAAC,KAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAG,KAAI,CAAC,OAAO,KAAE,CAAC;aACjD;SACF;aAAM;YACL,KAAI,CAAC,OAAO,GAAG,KAAI,CAAC,IAAI,CAAC;SAC1B;QAIA,KAAY,CAAC,SAAS,GAAG,iBAAiB,CAAC,SAAS,CAAC;;IACxD,CAAC;IAGH,wBAAC;AAAD,CAAC,AAzBD,CAAuC,KAAK,GAyB3C","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type {\n Reference,\n StoreObject,\n StoreValue,\n isReference,\n AsStoreObject,\n} from \"../../../utilities/index.js\";\n\nimport type { StorageType } from \"../../inmemory/policies.js\";\n\n// The Readonly<T> type only really works for object types, since it marks\n// all of the object's properties as readonly, but there are many cases when\n// a generic type parameter like TExisting might be a string or some other\n// primitive type, in which case we need to avoid wrapping it with Readonly.\n// SafeReadonly<string> collapses to just string, which makes string\n// assignable to SafeReadonly<any>, whereas string is not assignable to\n// Readonly<any>, somewhat surprisingly.\nexport type SafeReadonly<T> = T extends object ? Readonly<T> : T;\n\nexport type MissingTree =\n | string\n | {\n readonly [key: string]: MissingTree;\n };\n\nexport class MissingFieldError extends Error {\n constructor(\n public readonly message: string,\n public readonly path: MissingTree | Array<string | number>,\n public readonly query: DocumentNode,\n public readonly variables?: Record<string, any>\n ) {\n // 'Error' breaks prototype chain here\n super(message);\n\n if (Array.isArray(this.path)) {\n this.missing = this.message;\n for (let i = this.path.length - 1; i >= 0; --i) {\n this.missing = { [this.path[i]]: this.missing };\n }\n } else {\n this.missing = this.path;\n }\n\n // We're not using `Object.setPrototypeOf` here as it isn't fully supported\n // on Android (see issue #3236).\n (this as any).__proto__ = MissingFieldError.prototype;\n }\n\n public readonly missing: MissingTree;\n}\n\nexport interface FieldSpecifier {\n typename?: string;\n fieldName: string;\n field?: FieldNode;\n args?: Record<string, any>;\n variables?: Record<string, any>;\n}\n\nexport interface ReadFieldOptions extends FieldSpecifier {\n from?: StoreObject | Reference;\n}\n\nexport interface ReadFieldFunction {\n <V = StoreValue>(options: ReadFieldOptions): SafeReadonly<V> | undefined;\n <V = StoreValue>(\n fieldName: string,\n from?: StoreObject | Reference\n ): SafeReadonly<V> | undefined;\n}\n\nexport type ToReferenceFunction = (\n objOrIdOrRef: StoreObject | string | Reference,\n mergeIntoStore?: boolean\n) => Reference | undefined;\n\nexport type CanReadFunction = (value: StoreValue) => boolean;\n\ndeclare const _deleteModifier: unique symbol;\nexport interface DeleteModifier {\n [_deleteModifier]: true;\n}\ndeclare const _invalidateModifier: unique symbol;\nexport interface InvalidateModifier {\n [_invalidateModifier]: true;\n}\n\nexport type ModifierDetails = {\n DELETE: DeleteModifier;\n INVALIDATE: InvalidateModifier;\n fieldName: string;\n storeFieldName: string;\n readField: ReadFieldFunction;\n canRead: CanReadFunction;\n isReference: typeof isReference;\n toReference: ToReferenceFunction;\n storage: StorageType;\n};\n\nexport type Modifier<T> = (\n value: T,\n details: ModifierDetails\n) => T | DeleteModifier | InvalidateModifier;\n\ntype StoreObjectValueMaybeReference<StoreVal> = StoreVal extends Array<\n infer Item extends Record<string, any>\n>\n ? ReadonlyArray<AsStoreObject<Item> | Reference>\n : StoreVal extends Record<string, any>\n ? AsStoreObject<StoreVal> | Reference\n : StoreVal;\n\nexport type AllFieldsModifier<Entity extends Record<string, any>> = Modifier<\n Entity[keyof Entity] extends infer Value\n ? StoreObjectValueMaybeReference<Exclude<Value, undefined>>\n : never\n>;\n\nexport type Modifiers<T extends Record<string, any> = Record<string, unknown>> =\n Partial<{\n [FieldName in keyof T]: Modifier<\n StoreObjectValueMaybeReference<Exclude<T[FieldName], undefined>>\n >;\n }>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStore.d.ts","sourceRoot":"","sources":["../../../src/cache/inmemory/entityStore.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACV,MAAM,0BAA0B,CAAC;AASlC,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,SAAS,EAET,mBAAmB,EACnB,eAAe,EAIhB,MAAM,yBAAyB,CAAC;AAMjC,8BAAsB,WAAY,YAAW,eAAe;aAIxC,QAAQ,EAAE,QAAQ;aAClB,KAAK,EAAE,UAAU;IAJnC,SAAS,CAAC,IAAI,EAAE,qBAAqB,CAAuB;gBAG1C,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,UAAU;aAGnB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,GAAG,GAClC,KAAK;aAEQ,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;IAMlD,QAAQ,IAAI,qBAAqB;IAIjC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU;IAmBzD,SAAS,CAAC,MAAM,CACd,MAAM,EAAE,MAA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EAAE,UAAU;gBAHjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,GAAG,EACnC,KAAK,EAAE,UAAU;IAM5B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,GAAG,GAAG,KAAK;IAIrE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;IAyDzC,QAAQ,IAAI,qBAAqB;IAOjC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;IAUrD,UAAU,IAAI,WAAW;CAKjC;AAMD,cAAM,KAAM,SAAQ,KAAK;gBACX,IAAI,EAAE,WAAW,CAAC,IAAI;IAS3B,WAAW;IAKX,KAAK;CAQb;AAiBD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,WAAW,CAGtE"}
|
|
@@ -167,6 +167,41 @@ var EntityStore = (function () {
|
|
|
167
167
|
changedFields_1[storeFieldName] = newValue;
|
|
168
168
|
needToMerge_1 = true;
|
|
169
169
|
fieldValue = newValue;
|
|
170
|
+
if (globalThis.__DEV__ !== false) {
|
|
171
|
+
var checkReference = function (ref) {
|
|
172
|
+
if (_this.lookup(ref.__ref) === undefined) {
|
|
173
|
+
globalThis.__DEV__ !== false && invariant.warn(2, ref);
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
if (isReference(newValue)) {
|
|
178
|
+
checkReference(newValue);
|
|
179
|
+
}
|
|
180
|
+
else if (Array.isArray(newValue)) {
|
|
181
|
+
var seenReference = false;
|
|
182
|
+
var someNonReference = void 0;
|
|
183
|
+
for (var _i = 0, newValue_1 = newValue; _i < newValue_1.length; _i++) {
|
|
184
|
+
var value = newValue_1[_i];
|
|
185
|
+
if (isReference(value)) {
|
|
186
|
+
seenReference = true;
|
|
187
|
+
if (checkReference(value))
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if (typeof value === "object" && !!value) {
|
|
192
|
+
var id = _this.policies.identify(value)[0];
|
|
193
|
+
if (id) {
|
|
194
|
+
someNonReference = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (seenReference && someNonReference !== undefined) {
|
|
199
|
+
globalThis.__DEV__ !== false && invariant.warn(3, someNonReference);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
170
205
|
}
|
|
171
206
|
}
|
|
172
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/entityStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC,OAAO,EACL,WAAW,EACX,aAAa,EACb,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAe9D,IAAM,MAAM,GAAmB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnD,IAAM,WAAW,GAAkB,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;AAChD,IAAM,UAAU,GAAuB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAE3D;IAGE,qBACkB,QAAkB,EAClB,KAAiB;QAFnC,iBAGI;QAFc,aAAQ,GAAR,QAAQ,CAAU;QAClB,UAAK,GAAL,KAAK,CAAY;QAJzB,SAAI,GAA0B,MAAM,CAAC,M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/index.js\";\nimport type { OptimisticDependencyFunction } from \"optimism\";\nimport { dep } from \"optimism\";\nimport { equal } from \"@wry/equality\";\nimport { Trie } from \"@wry/trie\";\n\nimport type {\n StoreValue,\n StoreObject,\n Reference,\n} from \"../../utilities/index.js\";\nimport {\n isReference,\n makeReference,\n DeepMerger,\n maybeDeepFreeze,\n canUseWeakMap,\n isNonNullObject,\n} from \"../../utilities/index.js\";\nimport type { NormalizedCache, NormalizedCacheObject } from \"./types.js\";\nimport { hasOwn, fieldNameFromStoreName } from \"./helpers.js\";\nimport type { Policies, StorageType } from \"./policies.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n SafeReadonly,\n Modifier,\n Modifiers,\n ReadFieldOptions,\n ToReferenceFunction,\n CanReadFunction,\n InvalidateModifier,\n DeleteModifier,\n ModifierDetails,\n} from \"../core/types/common.js\";\n\nconst DELETE: DeleteModifier = Object.create(null);\nconst delModifier: Modifier<any> = () => DELETE;\nconst INVALIDATE: InvalidateModifier = Object.create(null);\n\nexport abstract class EntityStore implements NormalizedCache {\n protected data: NormalizedCacheObject = Object.create(null);\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 Object.create(null);\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> = Object.create(null);\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 ): boolean {\n const storeObject = this.lookup(dataId);\n\n if (storeObject) {\n const changedFields: Record<string, any> = Object.create(null);\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\"\n ? fields\n : fields[storeFieldName] || fields[fieldName];\n if (modify) {\n let newValue =\n modify === delModifier\n ? DELETE\n : modify(maybeDeepFreeze(fieldValue), {\n ...sharedDetails,\n fieldName,\n storeFieldName,\n storage: this.getStorage(dataId, storeFieldName),\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;\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 );\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 } = Object.create(null);\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 } = Object.create(null);\n\n public findChildRefIds(dataId: string): Record<string, true> {\n if (!hasOwn.call(this.refs, dataId)) {\n const found = (this.refs[dataId] = Object.create(null));\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 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\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(canUseWeakMap);\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\nexport namespace EntityStore {\n // Refer to this class as EntityStore.Root outside this namespace.\n export class 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(\n layerId: string,\n replay: (layer: EntityStore) => any\n ): 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>(canUseWeakMap);\n public getStorage(): StorageType {\n return this.storageTrie.lookupArray(arguments);\n }\n }\n}\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(): StorageType {\n let p: EntityStore = this.parent;\n while ((p as Layer).parent) p = (p as Layer).parent;\n return p.getStorage.apply(p, arguments);\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: EntityStore.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() {\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.apply(this.parent, arguments);\n }\n}\n\nfunction storeObjectReconciler(\n existingObject: StoreObject,\n incomingObject: StoreObject,\n property: string\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 instanceof EntityStore && store.group.caching);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/entityStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC,OAAO,EACL,WAAW,EACX,aAAa,EACb,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAe9D,IAAM,MAAM,GAAmB,MAAM,CAAC,M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,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAU;IAE9C,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\nimport type { OptimisticDependencyFunction } from \"optimism\";\nimport { dep } from \"optimism\";\nimport { equal } from \"@wry/equality\";\nimport { Trie } from \"@wry/trie\";\n\nimport type {\n StoreValue,\n StoreObject,\n Reference,\n} from \"../../utilities/index.js\";\nimport {\n isReference,\n makeReference,\n DeepMerger,\n maybeDeepFreeze,\n canUseWeakMap,\n isNonNullObject,\n} from \"../../utilities/index.js\";\nimport type { NormalizedCache, NormalizedCacheObject } from \"./types.js\";\nimport { hasOwn, fieldNameFromStoreName } from \"./helpers.js\";\nimport type { Policies, StorageType } from \"./policies.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n SafeReadonly,\n Modifier,\n Modifiers,\n ReadFieldOptions,\n ToReferenceFunction,\n CanReadFunction,\n InvalidateModifier,\n DeleteModifier,\n ModifierDetails,\n} from \"../core/types/common.js\";\n\nconst DELETE: DeleteModifier = Object.create(null);\nconst delModifier: Modifier<any> = () => DELETE;\nconst INVALIDATE: InvalidateModifier = Object.create(null);\n\nexport abstract class EntityStore implements NormalizedCache {\n protected data: NormalizedCacheObject = Object.create(null);\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 Object.create(null);\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> = Object.create(null);\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 ): boolean {\n const storeObject = this.lookup(dataId);\n\n if (storeObject) {\n const changedFields: Record<string, any> = Object.create(null);\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\"\n ? fields\n : fields[storeFieldName] || fields[fieldName];\n if (modify) {\n let newValue =\n modify === delModifier\n ? DELETE\n : modify(maybeDeepFreeze(fieldValue), {\n ...sharedDetails,\n fieldName,\n storeFieldName,\n storage: this.getStorage(dataId, storeFieldName),\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;\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 );\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 } = Object.create(null);\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 } = Object.create(null);\n\n public findChildRefIds(dataId: string): Record<string, true> {\n if (!hasOwn.call(this.refs, dataId)) {\n const found = (this.refs[dataId] = Object.create(null));\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 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\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(canUseWeakMap);\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\nexport namespace EntityStore {\n // Refer to this class as EntityStore.Root outside this namespace.\n export class 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(\n layerId: string,\n replay: (layer: EntityStore) => any\n ): 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>(canUseWeakMap);\n public getStorage(): StorageType {\n return this.storageTrie.lookupArray(arguments);\n }\n }\n}\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(): StorageType {\n let p: EntityStore = this.parent;\n while ((p as Layer).parent) p = (p as Layer).parent;\n return p.getStorage.apply(p, arguments);\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: EntityStore.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() {\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.apply(this.parent, arguments);\n }\n}\n\nfunction storeObjectReconciler(\n existingObject: StoreObject,\n incomingObject: StoreObject,\n property: string\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 instanceof EntityStore && store.group.caching);\n}\n"]}
|
|
@@ -20,7 +20,7 @@ export function keyFieldsFnFromSpecifier(specifier) {
|
|
|
20
20
|
hasOwn.call(object, schemaKeyPath[0])) {
|
|
21
21
|
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
22
22
|
}
|
|
23
|
-
invariant(extracted !== void 0,
|
|
23
|
+
invariant(extracted !== void 0, 4, schemaKeyPath.join("."), object);
|
|
24
24
|
return extracted;
|
|
25
25
|
}));
|
|
26
26
|
return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
|
|
@@ -158,7 +158,7 @@ var Policies = (function () {
|
|
|
158
158
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
159
159
|
var old = this.rootTypenamesById[rootId];
|
|
160
160
|
if (typename !== old) {
|
|
161
|
-
invariant(!old || old === which,
|
|
161
|
+
invariant(!old || old === which, 5, which);
|
|
162
162
|
if (old)
|
|
163
163
|
delete this.rootIdsByTypename[old];
|
|
164
164
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -255,7 +255,7 @@ var Policies = (function () {
|
|
|
255
255
|
if (supertypeSet.has(supertype)) {
|
|
256
256
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
257
257
|
if (checkingFuzzySubtypes) {
|
|
258
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
258
|
+
globalThis.__DEV__ !== false && invariant.warn(6, typename, supertype);
|
|
259
259
|
}
|
|
260
260
|
typenameSupertypeSet.add(supertype);
|
|
261
261
|
}
|
|
@@ -418,7 +418,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
420
|
if (globalThis.__DEV__ !== false && options.from === void 0) {
|
|
421
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
421
|
+
globalThis.__DEV__ !== false && invariant.warn(7, stringifyForDisplay(Array.from(readFieldArgs)));
|
|
422
422
|
}
|
|
423
423
|
if (void 0 === options.variables) {
|
|
424
424
|
options.variables = variables;
|
|
@@ -428,7 +428,7 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
428
428
|
function makeMergeObjectsFunction(store) {
|
|
429
429
|
return function mergeObjects(existing, incoming) {
|
|
430
430
|
if (isArray(existing) || isArray(incoming)) {
|
|
431
|
-
throw newInvariantError(
|
|
431
|
+
throw newInvariantError(8);
|
|
432
432
|
}
|
|
433
433
|
if (isNonNullObject(existing) && isNonNullObject(incoming)) {
|
|
434
434
|
var eType = store.getFieldValue(existing, "__typename");
|
|
@@ -179,7 +179,7 @@ var StoreReader = (function () {
|
|
|
179
179
|
else {
|
|
180
180
|
var fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
181
181
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
182
|
-
throw newInvariantError(
|
|
182
|
+
throw newInvariantError(9, selection.name.value);
|
|
183
183
|
}
|
|
184
184
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
185
185
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
@@ -264,7 +264,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
264
264
|
if (isNonNullObject(value)) {
|
|
265
265
|
invariant(
|
|
266
266
|
!isReference(value),
|
|
267
|
-
|
|
267
|
+
10,
|
|
268
268
|
getTypenameFromStoreObject(store, value),
|
|
269
269
|
field.name.value
|
|
270
270
|
);
|
|
@@ -41,7 +41,7 @@ var StoreWriter = (function () {
|
|
|
41
41
|
context: context,
|
|
42
42
|
});
|
|
43
43
|
if (!isReference(ref)) {
|
|
44
|
-
throw newInvariantError(
|
|
44
|
+
throw newInvariantError(11, result);
|
|
45
45
|
}
|
|
46
46
|
context.incomingById.forEach(function (_a, dataId) {
|
|
47
47
|
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
@@ -146,7 +146,7 @@ var StoreWriter = (function () {
|
|
|
146
146
|
!context.deferred &&
|
|
147
147
|
!addTypenameToDocument.added(field) &&
|
|
148
148
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
149
|
-
globalThis.__DEV__ !== false && invariant.error(
|
|
149
|
+
globalThis.__DEV__ !== false && invariant.error(12, resultKeyNameFromField(field), result);
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
try {
|
|
@@ -251,7 +251,7 @@ var StoreWriter = (function () {
|
|
|
251
251
|
else {
|
|
252
252
|
var fragment = getFragmentFromSelection(selection, context.lookupFragment);
|
|
253
253
|
if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
254
|
-
throw newInvariantError(
|
|
254
|
+
throw newInvariantError(13, selection.name.value);
|
|
255
255
|
}
|
|
256
256
|
if (fragment &&
|
|
257
257
|
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
@@ -394,7 +394,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
394
394
|
}
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
397
|
+
globalThis.__DEV__ !== false && invariant.warn(14, fieldName, parentType, childTypenames.length
|
|
398
398
|
? "either ensure all objects of type " +
|
|
399
399
|
childTypenames.join(" and ") +
|
|
400
400
|
" have an ID or a custom merge function, or "
|