@nerdwallet/apollo-cache-policies
Advanced tools
Comparing version 2.9.1 to 2.10.0
@@ -0,1 +1,5 @@ | ||
2.10.0 (Dan Reynolds) | ||
Bump Apollo version and ensure compatibility. | ||
2.9.1 (Dan Reynolds) | ||
@@ -2,0 +6,0 @@ |
@@ -22,3 +22,3 @@ "use strict"; | ||
getLog(filter) { | ||
return filter_1.default(this._log, filter); | ||
return (0, filter_1.default)(this._log, filter); | ||
} | ||
@@ -25,0 +25,0 @@ printLog(filter) { |
@@ -13,3 +13,3 @@ "use strict"; | ||
AuditType["Evict"] = "Evict"; | ||
})(AuditType = exports.AuditType || (exports.AuditType = {})); | ||
})(AuditType || (exports.AuditType = AuditType = {})); | ||
class InvalidationPolicyManagerAuditor extends InvalidationPolicyManager_1.default { | ||
@@ -16,0 +16,0 @@ constructor(config) { |
@@ -18,3 +18,3 @@ "use strict"; | ||
ReadResultStatus[ReadResultStatus["Complete"] = 2] = "Complete"; | ||
})(ReadResultStatus = exports.ReadResultStatus || (exports.ReadResultStatus = {})); | ||
})(ReadResultStatus || (exports.ReadResultStatus = ReadResultStatus = {})); | ||
/** | ||
@@ -28,11 +28,11 @@ * Processes the result of a cache read/write to run cache policies on the deeply nested objects. | ||
getFieldsForQuery(options) { | ||
const operationDefinition = utilities_1.getOperationDefinition(options.query); | ||
const fragmentMap = utilities_1.createFragmentMap(utilities_1.getFragmentDefinitions(options.query)); | ||
const operationDefinition = (0, utilities_1.getOperationDefinition)(options.query); | ||
const fragmentMap = (0, utilities_1.createFragmentMap)((0, utilities_1.getFragmentDefinitions)(options.query)); | ||
return operationDefinition.selectionSet.selections.reduce((acc, selection) => { | ||
var _a, _b; | ||
if (utilities_1.isField(selection)) { | ||
if ((0, utilities_1.isField)(selection)) { | ||
acc.push(selection); | ||
return acc; | ||
} | ||
const selections = (_b = (_a = utilities_1.getFragmentFromSelection(selection, fragmentMap)) === null || _a === void 0 ? void 0 : _a.selectionSet) === null || _b === void 0 ? void 0 : _b.selections; | ||
const selections = (_b = (_a = (0, utilities_1.getFragmentFromSelection)(selection, fragmentMap)) === null || _a === void 0 ? void 0 : _a.selectionSet) === null || _b === void 0 ? void 0 : _b.selections; | ||
if (selections) { | ||
@@ -49,3 +49,3 @@ acc.push(...selections); | ||
: parentResult[fieldNameOrIndex]; | ||
if (isPlainObject_1.default(result)) { | ||
if ((0, isPlainObject_1.default)(result)) { | ||
const { __typename } = result; | ||
@@ -67,3 +67,3 @@ const aggregateResultComplete = Object.keys(result).reduce((_acc, fieldName) => this.processReadSubResult(result, fieldName) === | ||
if (evicted) { | ||
if (isPlainObject_1.default(parentResult) && fieldNameOrIndex) { | ||
if ((0, isPlainObject_1.default)(parentResult) && fieldNameOrIndex) { | ||
delete parentResult[fieldNameOrIndex]; | ||
@@ -79,3 +79,3 @@ } | ||
} | ||
else if (isArray_1.default(result)) { | ||
else if ((0, isArray_1.default)(result)) { | ||
let aggregateSubResultStatus = ReadResultStatus.Complete; | ||
@@ -102,4 +102,4 @@ const subResultStatuses = result.map((_subResult, index) => { | ||
const { rootId: dataId = "ROOT_QUERY" } = options; | ||
if (isPlainObject_1.default(result)) { | ||
if (helpers_1.isQuery(dataId)) { | ||
if ((0, isPlainObject_1.default)(result)) { | ||
if ((0, helpers_1.isQuery)(dataId)) { | ||
const { variables } = options; | ||
@@ -112,5 +112,5 @@ const aggregateResultComplete = this.getFieldsForQuery(options).reduce((acc, field) => { | ||
// result key name in case it needs to be removed from the response due to an evicted TTL | ||
const resultKeyName = utilities_1.resultKeyNameFromField(field); | ||
const resultKeyName = (0, utilities_1.resultKeyNameFromField)(field); | ||
const subResultStatus = this.processReadSubResult(result, fieldName); | ||
const typename = (_a = entityTypeMap.readEntityById(helpers_1.makeEntityId(dataId, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
const typename = (_a = entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(dataId, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
if (typename) { | ||
@@ -155,3 +155,3 @@ const storeFieldNameForEntity = cache.policies.getStoreFieldName({ | ||
}, true); | ||
utilities_1.maybeDeepFreeze(result); | ||
(0, utilities_1.maybeDeepFreeze)(result); | ||
return aggregateResultComplete | ||
@@ -161,3 +161,3 @@ ? ReadResultStatus.Complete | ||
} | ||
utilities_1.maybeDeepFreeze(result); | ||
(0, utilities_1.maybeDeepFreeze)(result); | ||
return this.processReadSubResult(result); | ||
@@ -169,3 +169,3 @@ } | ||
const { cache, invalidationPolicyManager, entityTypeMap } = this.config; | ||
if (isPlainObject_1.default(result)) { | ||
if ((0, isPlainObject_1.default)(result)) { | ||
const { __typename } = result; | ||
@@ -184,3 +184,3 @@ Object.keys(result).forEach((resultField) => this.processWriteSubResult(result[resultField])); | ||
id, | ||
ref: core_1.makeReference(id), | ||
ref: (0, core_1.makeReference)(id), | ||
}, | ||
@@ -191,3 +191,3 @@ }); | ||
} | ||
else if (isArray_1.default(result)) { | ||
else if ((0, isArray_1.default)(result)) { | ||
result.forEach((resultListItem) => this.processWriteSubResult(resultListItem)); | ||
@@ -200,10 +200,10 @@ } | ||
const { entityTypeMap, cache, invalidationPolicyManager } = this.config; | ||
if (isPlainObject_1.default(result)) { | ||
if ((0, isPlainObject_1.default)(result)) { | ||
this.processWriteSubResult(result); | ||
} | ||
if (dataId && helpers_1.isQuery(dataId) && isPlainObject_1.default(result)) { | ||
if (dataId && (0, helpers_1.isQuery)(dataId) && (0, isPlainObject_1.default)(result)) { | ||
this.getFieldsForQuery(options).forEach((field) => { | ||
var _a; | ||
const fieldName = field.name.value; | ||
const typename = (_a = entityTypeMap.readEntityById(helpers_1.makeEntityId(dataId, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
const typename = (_a = entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(dataId, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
if (typename) { | ||
@@ -216,3 +216,3 @@ const storeFieldName = cache.policies.getStoreFieldName({ | ||
}); | ||
const fieldArgs = utilities_1.argumentsObjectFromField(field, variables); | ||
const fieldArgs = (0, utilities_1.argumentsObjectFromField)(field, variables); | ||
const fieldVariables = variables !== null && variables !== void 0 ? variables : (fieldArgs !== null ? {} : undefined); | ||
@@ -240,3 +240,3 @@ const queryTypename = cache.policies.rootTypenamesById[dataId]; | ||
storeFieldName, | ||
ref: core_1.makeReference(dataId), | ||
ref: (0, core_1.makeReference)(dataId), | ||
variables: fieldVariables, | ||
@@ -250,3 +250,3 @@ args: fieldArgs, | ||
else if (dataId) { | ||
const typename = (_a = entityTypeMap.readEntityById(helpers_1.makeEntityId(dataId))) === null || _a === void 0 ? void 0 : _a.typename; | ||
const typename = (_a = entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(dataId))) === null || _a === void 0 ? void 0 : _a.typename; | ||
if (typename) { | ||
@@ -261,3 +261,3 @@ const renewalPolicy = invalidationPolicyManager.getRenewalPolicyForType(typename); | ||
id: dataId, | ||
ref: core_1.makeReference(dataId), | ||
ref: (0, core_1.makeReference)(dataId), | ||
variables, | ||
@@ -264,0 +264,0 @@ }, |
@@ -28,3 +28,3 @@ import { InMemoryCache, Cache, NormalizedCacheObject, Reference, StoreObject } from "@apollo/client/core"; | ||
isOperatingOnRootData(): boolean; | ||
modify(options: Cache.ModifyOptions): boolean; | ||
modify<Entity extends Record<string, any> = Record<string, any>>(options: Cache.ModifyOptions<Entity>): boolean; | ||
write(options: Cache.WriteOptions<any, any>): Reference | undefined; | ||
@@ -31,0 +31,0 @@ evictWhere<EntityType>(filters: { |
@@ -41,3 +41,3 @@ "use strict"; | ||
this.isInitialized = true; | ||
this.reactiveVarsCache = ReactiveVarsCache_1.initReactiveVarsCache(this); | ||
this.reactiveVarsCache = (0, ReactiveVarsCache_1.initReactiveVarsCache)(this); | ||
// Once the InMemoryCache has called `init()` in the super constructor, we initialize | ||
@@ -123,7 +123,7 @@ // the InvalidationPolicyCache objects. | ||
const { id = "ROOT_QUERY", fields } = options; | ||
if (helpers_1.isQuery(id)) { | ||
if ((0, helpers_1.isQuery)(id)) { | ||
Object.keys(fields).forEach((storeFieldName) => { | ||
var _a; | ||
const fieldName = helpers_1.fieldNameFromStoreName(storeFieldName); | ||
const typename = (_a = this.entityTypeMap.readEntityById(helpers_1.makeEntityId(id, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
const fieldName = (0, helpers_1.fieldNameFromStoreName)(storeFieldName); | ||
const typename = (_a = this.entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(id, fieldName))) === null || _a === void 0 ? void 0 : _a.typename; | ||
if (!typename) { | ||
@@ -137,3 +137,3 @@ return; | ||
storeFieldName, | ||
ref: core_1.makeReference(id), | ||
ref: (0, core_1.makeReference)(id), | ||
}, | ||
@@ -151,3 +151,3 @@ }); | ||
id, | ||
ref: core_1.makeReference(id), | ||
ref: (0, core_1.makeReference)(id), | ||
}, | ||
@@ -199,5 +199,5 @@ }); | ||
if (this.invalidationPolicyManager.isPolicyEventActive(types_1.InvalidationPolicyEvent.Evict)) { | ||
const { typename } = (_a = this.entityTypeMap.readEntityById(helpers_1.makeEntityId(id, fieldName))) !== null && _a !== void 0 ? _a : {}; | ||
const { typename } = (_a = this.entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(id, fieldName))) !== null && _a !== void 0 ? _a : {}; | ||
if (typename) { | ||
const storeFieldName = helpers_1.isQuery(id) && fieldName | ||
const storeFieldName = (0, helpers_1.isQuery)(id) && fieldName | ||
? this.policies.getStoreFieldName({ | ||
@@ -215,3 +215,3 @@ typename, | ||
variables: args, | ||
ref: core_1.makeReference(id), | ||
ref: (0, core_1.makeReference)(id), | ||
}, | ||
@@ -228,4 +228,4 @@ }); | ||
} | ||
const collectionEntityId = utils_1.collectionEntityIdForType(typename); | ||
const collectionFieldExists = !!this.readField('id', core_1.makeReference(collectionEntityId)); | ||
const collectionEntityId = (0, utils_1.collectionEntityIdForType)(typename); | ||
const collectionFieldExists = !!this.readField('id', (0, core_1.makeReference)(collectionEntityId)); | ||
// If the collection field for the type does not exist in the cache, then initialize it as | ||
@@ -236,3 +236,3 @@ // an empty array. | ||
id: collectionEntityId, | ||
fragment: core_1.gql ` | ||
fragment: (0, core_1.gql) ` | ||
fragment InitializeCollectionEntity on CacheExtensionsCollectionEntity { | ||
@@ -259,3 +259,3 @@ data | ||
...existing.filter((ref) => canRead(ref)), | ||
core_1.makeReference(dataId), | ||
(0, core_1.makeReference)(dataId), | ||
]; | ||
@@ -276,3 +276,3 @@ } | ||
const { storeFieldNames, dataId, fieldName, typename } = entity; | ||
if (helpers_1.isQuery(dataId) && storeFieldNames) { | ||
if ((0, helpers_1.isQuery)(dataId) && storeFieldNames) { | ||
Object.keys(storeFieldNames.entries).forEach((storeFieldName) => { | ||
@@ -287,3 +287,3 @@ const isExpired = this.invalidationPolicyManager.runReadPolicy({ | ||
if (isExpired) { | ||
expiredEntityIds.push(helpers_1.makeEntityId(dataId, storeFieldName)); | ||
expiredEntityIds.push((0, helpers_1.makeEntityId)(dataId, storeFieldName)); | ||
} | ||
@@ -300,3 +300,3 @@ }); | ||
if (isExpired) { | ||
expiredEntityIds.push(helpers_1.makeEntityId(dataId)); | ||
expiredEntityIds.push((0, helpers_1.makeEntityId)(dataId)); | ||
} | ||
@@ -350,3 +350,3 @@ } | ||
} | ||
const processedResult = helpers_1.maybeDeepClone(result); | ||
const processedResult = (0, helpers_1.maybeDeepClone)(result); | ||
const processedResultStatus = this.cacheResultProcessor.processReadResult(processedResult, options); | ||
@@ -372,3 +372,3 @@ if (processedResultStatus === CacheResultProcessor_1.ReadResultStatus.Complete) { | ||
const { result } = cacheDiff; | ||
const processedResult = helpers_1.maybeDeepClone(result); | ||
const processedResult = (0, helpers_1.maybeDeepClone)(result); | ||
const processedResultStatus = this.cacheResultProcessor.processReadResult(processedResult, options); | ||
@@ -391,3 +391,3 @@ if (processedResultStatus === CacheResultProcessor_1.ReadResultStatus.Complete) { | ||
// minimize payload size only inject the entitiesById object into the extracted cache | ||
extractedCache.invalidation = pick_1.default(this.entityTypeMap.extract(), "entitiesById"); | ||
extractedCache.invalidation = (0, pick_1.default)(this.entityTypeMap.extract(), "entitiesById"); | ||
} | ||
@@ -407,3 +407,3 @@ return extractedCache; | ||
const matchingFragments = matchingRefs.map(ref => this.readFragment(Object.assign(Object.assign({}, restOptions), { fragment, id: ref.__ref }))); | ||
return compact_1.default(matchingFragments); | ||
return (0, compact_1.default)(matchingFragments); | ||
} | ||
@@ -414,4 +414,4 @@ // Supports reading a collection of references by type from the cache and filtering them by the given fields. Returns a | ||
const { __typename, filter } = options; | ||
const collectionEntityName = utils_1.collectionEntityIdForType(__typename); | ||
const entityReferences = this.readField('data', core_1.makeReference(collectionEntityName)); | ||
const collectionEntityName = (0, utils_1.collectionEntityIdForType)(__typename); | ||
const entityReferences = this.readField('data', (0, core_1.makeReference)(collectionEntityName)); | ||
if (!entityReferences) { | ||
@@ -424,3 +424,3 @@ return []; | ||
return entityReferences.filter(ref => { | ||
if (isFunction_1.default(filter)) { | ||
if ((0, isFunction_1.default)(filter)) { | ||
return filter(ref, this.readField.bind(this)); | ||
@@ -434,3 +434,3 @@ } | ||
}); | ||
return every_1.default(entityFilterResults, Boolean); | ||
return (0, every_1.default)(entityFilterResults, Boolean); | ||
}); | ||
@@ -437,0 +437,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
exports.initReactiveVarsCache = initReactiveVarsCache; | ||
const cachedReactiveVarFragment = client_1.gql ` | ||
const cachedReactiveVarFragment = (0, client_1.gql) ` | ||
fragment ReadCachedReactiveVarFragment on CachedReactiveVar { | ||
@@ -42,3 +42,3 @@ id | ||
const cachedValue = this.readCachedVar(id); | ||
const rv = client_1.makeVar(cachedValue !== null && cachedValue !== void 0 ? cachedValue : defaultValue); | ||
const rv = (0, client_1.makeVar)(cachedValue !== null && cachedValue !== void 0 ? cachedValue : defaultValue); | ||
if (this.registeredVars[id]) { | ||
@@ -45,0 +45,0 @@ console.warn(`Duplicate cached reactive variable with ID ${id} detected. Multiple cached reactive variables should not share the same ID.`); |
@@ -18,3 +18,3 @@ import { Cache, InMemoryCacheConfig, Reference } from "@apollo/client/core"; | ||
} | ||
export declare type FragmentWhereFilter<T> = Partial<Record<keyof T, any>> | ((__ref: Reference, readField: InvalidationPolicyCache['readField']) => boolean); | ||
export type FragmentWhereFilter<T> = Partial<Record<keyof T, any>> | ((__ref: Reference, readField: InvalidationPolicyCache['readField']) => boolean); | ||
//# sourceMappingURL=types.d.ts.map |
@@ -55,4 +55,4 @@ "use strict"; | ||
watchFragment(options) { | ||
const fieldName = helpers_1.generateFragmentFieldName(); | ||
const query = utils_1.buildWatchFragmentQuery(Object.assign(Object.assign({}, options), { fieldName, policies: this.policies })); | ||
const fieldName = (0, helpers_1.generateFragmentFieldName)(); | ||
const query = (0, utils_1.buildWatchFragmentQuery)(Object.assign(Object.assign({}, options), { fieldName, policies: this.policies })); | ||
return this.watchQueryForField(query, fieldName); | ||
@@ -63,5 +63,5 @@ } | ||
watchFragmentWhere(options) { | ||
const fieldName = helpers_1.generateFragmentFieldName(); | ||
const filterVar = core_1.makeVar(options.filter); | ||
const query = utils_1.buildWatchFragmentWhereQuery(Object.assign(Object.assign({}, options), { fieldName, | ||
const fieldName = (0, helpers_1.generateFragmentFieldName)(); | ||
const filterVar = (0, core_1.makeVar)(options.filter); | ||
const query = (0, utils_1.buildWatchFragmentWhereQuery)(Object.assign(Object.assign({}, options), { fieldName, | ||
filterVar, cache: this.cache, policies: this.policies })); | ||
@@ -68,0 +68,0 @@ return this.watchQueryForField(query, fieldName); |
import { DocumentNode } from 'graphql'; | ||
import { FragmentWhereFilter } from '../cache/types'; | ||
export declare type WatchFragmentOptions = { | ||
export type WatchFragmentOptions = { | ||
fragment: DocumentNode; | ||
id: string; | ||
}; | ||
export declare type WatchFragmentWhereOptions<FragmentType> = { | ||
export type WatchFragmentWhereOptions<FragmentType> = { | ||
fragment: DocumentNode; | ||
@@ -9,0 +9,0 @@ filter?: FragmentWhereFilter<FragmentType>; |
@@ -54,3 +54,3 @@ "use strict"; | ||
read(_existing) { | ||
return core_1.makeReference(id); | ||
return (0, core_1.makeReference)(id); | ||
} | ||
@@ -57,0 +57,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
const result = this.storeFunctions.delete.call(entityStore, dataId, fieldName, args); | ||
const entity = entityTypeMap.readEntityById(helpers_1.makeEntityId(dataId, fieldName)); | ||
const entity = entityTypeMap.readEntityById((0, helpers_1.makeEntityId)(dataId, fieldName)); | ||
const storeFieldName = fieldName && args | ||
@@ -28,3 +28,3 @@ ? policies.getStoreFieldName({ | ||
const { entityStore, entityTypeMap } = this.config; | ||
if (helpers_1.isQuery(dataId)) { | ||
if ((0, helpers_1.isQuery)(dataId)) { | ||
Object.keys(incomingStoreObject) | ||
@@ -31,0 +31,0 @@ .filter((storeFieldName) => { |
@@ -104,8 +104,8 @@ "use strict"; | ||
const fieldName = storeFieldName | ||
? helpers_1.fieldNameFromStoreName(storeFieldName) | ||
? (0, helpers_1.fieldNameFromStoreName)(storeFieldName) | ||
: undefined; | ||
const entityId = helpers_1.makeEntityId(dataId, fieldName); | ||
const entityId = (0, helpers_1.makeEntityId)(dataId, fieldName); | ||
const existingTypeMapEntity = this.readEntityById(entityId); | ||
if (existingTypeMapEntity) { | ||
if (helpers_1.isQuery(dataId) && storeFieldName) { | ||
if ((0, helpers_1.isQuery)(dataId) && storeFieldName) { | ||
const storeFieldNameEntry = existingTypeMapEntity.storeFieldNames | ||
@@ -129,3 +129,3 @@ .entries[storeFieldName]; | ||
const cacheTime = Date.now(); | ||
if (helpers_1.isQuery(dataId) && storeFieldName) { | ||
if ((0, helpers_1.isQuery)(dataId) && storeFieldName) { | ||
newEntity = { | ||
@@ -150,3 +150,3 @@ dataId, | ||
} | ||
set_1.default(this.entitiesByType, [typename, entityId], newEntity); | ||
(0, set_1.default)(this.entitiesByType, [typename, entityId], newEntity); | ||
this.entitiesById[entityId] = newEntity; | ||
@@ -158,5 +158,5 @@ } | ||
const fieldName = storeFieldName | ||
? helpers_1.fieldNameFromStoreName(storeFieldName) | ||
? (0, helpers_1.fieldNameFromStoreName)(storeFieldName) | ||
: null; | ||
const entityId = helpers_1.makeEntityId(dataId, fieldName); | ||
const entityId = (0, helpers_1.makeEntityId)(dataId, fieldName); | ||
const entity = this.readEntityById(entityId); | ||
@@ -194,8 +194,8 @@ if (!entity) { | ||
const fieldName = storeFieldName | ||
? helpers_1.fieldNameFromStoreName(storeFieldName) | ||
? (0, helpers_1.fieldNameFromStoreName)(storeFieldName) | ||
: undefined; | ||
const entity = this.entitiesById[helpers_1.makeEntityId(dataId, fieldName)]; | ||
const entity = this.entitiesById[(0, helpers_1.makeEntityId)(dataId, fieldName)]; | ||
if (entity) { | ||
const cacheTime = Date.now(); | ||
if (helpers_1.isQuery(dataId) && storeFieldName) { | ||
if ((0, helpers_1.isQuery)(dataId) && storeFieldName) { | ||
const storeFieldNameEntry = entity.storeFieldNames.entries[storeFieldName]; | ||
@@ -202,0 +202,0 @@ if (storeFieldNameEntry) { |
@@ -24,3 +24,3 @@ "use strict"; | ||
if (isQuery(dataId)) { | ||
return compact_1.default([dataId, fieldName]).join("."); | ||
return (0, compact_1.default)([dataId, fieldName]).join("."); | ||
} | ||
@@ -33,3 +33,3 @@ return dataId; | ||
// https://github.com/apollographql/apollo-client/blob/master/src/utilities/common/maybeDeepFreeze.ts#L20:L20 | ||
const maybeDeepClone = (obj) => isPlainObject_1.default(obj) && Object.isFrozen(obj) ? cloneDeep_1.default(obj) : obj; | ||
const maybeDeepClone = (obj) => (0, isPlainObject_1.default)(obj) && Object.isFrozen(obj) ? (0, cloneDeep_1.default)(obj) : obj; | ||
exports.maybeDeepClone = maybeDeepClone; | ||
@@ -47,5 +47,5 @@ exports.TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i; | ||
function generateFragmentFieldName() { | ||
return `-fragment-${uuid_1.v4()}`; | ||
return `-fragment-${(0, uuid_1.v4)()}`; | ||
} | ||
exports.generateFragmentFieldName = generateFragmentFieldName; | ||
//# sourceMappingURL=helpers.js.map |
@@ -17,7 +17,7 @@ import { DocumentNode } from 'graphql'; | ||
stopPolling: () => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FragmentType | null>, TSubscriptionVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FragmentType | null>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FragmentType | null>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FragmentType | null>>, "variables">) => Record<string, FragmentType | null>) => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FragmentType | null>, TSubscriptionVariables extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FragmentType | null>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FragmentType | null>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FragmentType | null>>, "variables">) => Record<string, FragmentType | null>) => void; | ||
refetch: (variables?: Partial<import("@apollo/client").OperationVariables> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FragmentType | null>>>; | ||
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, Record<string, FragmentType | null>>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FragmentType | null>>>; | ||
fetchMore: <TFetchData = Record<string, FragmentType | null>, TFetchVars = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
fetchMore: <TFetchData = Record<string, FragmentType | null>, TFetchVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
updateQuery?: ((previousQueryResult: Record<string, FragmentType | null>, options: { | ||
@@ -24,0 +24,0 @@ fetchMoreResult: TFetchData; |
@@ -11,7 +11,7 @@ "use strict"; | ||
function useFragment(fragment, options) { | ||
const context = react_1.useContext(client_1.getApolloContext()); | ||
const context = (0, react_1.useContext)((0, client_1.getApolloContext)()); | ||
const client = context.client; | ||
const cache = client === null || client === void 0 ? void 0 : client.cache; | ||
const fieldName = useFragmentTypePolicyFieldName_1.useFragmentTypePolicyFieldName(); | ||
const queryForFragment = utils_1.useOnce(() => utils_2.buildWatchFragmentQuery({ | ||
const fieldName = (0, useFragmentTypePolicyFieldName_1.useFragmentTypePolicyFieldName)(); | ||
const queryForFragment = (0, utils_1.useOnce)(() => (0, utils_2.buildWatchFragmentQuery)({ | ||
fragment, | ||
@@ -22,5 +22,5 @@ fieldName, | ||
})); | ||
return useGetQueryDataByFieldName_1.useGetQueryDataByFieldName(queryForFragment, fieldName); | ||
return (0, useGetQueryDataByFieldName_1.useGetQueryDataByFieldName)(queryForFragment, fieldName); | ||
} | ||
exports.default = useFragment; | ||
//# sourceMappingURL=useFragment.js.map |
@@ -9,5 +9,5 @@ "use strict"; | ||
const useFragmentTypePolicyFieldName = () => { | ||
const { current: fieldName } = react_1.useRef(helpers_1.generateFragmentFieldName()); | ||
const client = client_1.useApolloClient(); | ||
react_1.useEffect(() => | ||
const { current: fieldName } = (0, react_1.useRef)((0, helpers_1.generateFragmentFieldName)()); | ||
const client = (0, client_1.useApolloClient)(); | ||
(0, react_1.useEffect)(() => | ||
// @ts-ignore After the component using the hook is torn down, remove the dynamically added type policy | ||
@@ -14,0 +14,0 @@ // for this hook from the type policies list. |
@@ -15,7 +15,7 @@ import { DocumentNode } from 'graphql'; | ||
stopPolling: () => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FragmentType[]>, TSubscriptionVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FragmentType[]>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FragmentType[]>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FragmentType[]>>, "variables">) => Record<string, FragmentType[]>) => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FragmentType[]>, TSubscriptionVariables extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FragmentType[]>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FragmentType[]>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FragmentType[]>>, "variables">) => Record<string, FragmentType[]>) => void; | ||
refetch: (variables?: Partial<import("@apollo/client").OperationVariables> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FragmentType[]>>>; | ||
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, Record<string, FragmentType[]>>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FragmentType[]>>>; | ||
fetchMore: <TFetchData = Record<string, FragmentType[]>, TFetchVars = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
fetchMore: <TFetchData = Record<string, FragmentType[]>, TFetchVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
updateQuery?: ((previousQueryResult: Record<string, FragmentType[]>, options: { | ||
@@ -22,0 +22,0 @@ fetchMoreResult: TFetchData; |
@@ -13,14 +13,14 @@ "use strict"; | ||
function useFragmentWhere(fragment, filter) { | ||
const context = react_1.useContext(client_1.getApolloContext()); | ||
const context = (0, react_1.useContext)((0, client_1.getApolloContext)()); | ||
const client = context.client; | ||
const cache = client === null || client === void 0 ? void 0 : client.cache; | ||
const fieldName = useFragmentTypePolicyFieldName_1.useFragmentTypePolicyFieldName(); | ||
const filterVarRef = react_1.useRef(client_2.makeVar(filter)); | ||
const fieldName = (0, useFragmentTypePolicyFieldName_1.useFragmentTypePolicyFieldName)(); | ||
const filterVarRef = (0, react_1.useRef)((0, client_2.makeVar)(filter)); | ||
const filterVar = filterVarRef.current; | ||
react_1.useEffect(() => { | ||
if (typeof filter === 'function' && filter !== filterVar() || !equality_1.equal(filter, filterVar())) { | ||
(0, react_1.useEffect)(() => { | ||
if (typeof filter === 'function' && filter !== filterVar() || !(0, equality_1.equal)(filter, filterVar())) { | ||
filterVar(filter); | ||
} | ||
}, [filter]); | ||
const query = utils_2.useOnce(() => utils_1.buildWatchFragmentWhereQuery({ | ||
const query = (0, utils_2.useOnce)(() => (0, utils_1.buildWatchFragmentWhereQuery)({ | ||
filter, | ||
@@ -33,5 +33,5 @@ filterVar, | ||
})); | ||
return useGetQueryDataByFieldName_1.useGetQueryDataByFieldName(query, fieldName); | ||
return (0, useGetQueryDataByFieldName_1.useGetQueryDataByFieldName)(query, fieldName); | ||
} | ||
exports.default = useFragmentWhere; | ||
//# sourceMappingURL=useFragmentWhere.js.map |
@@ -14,7 +14,7 @@ import { DocumentNode } from "graphql"; | ||
stopPolling: () => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FieldType>, TSubscriptionVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FieldType>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FieldType>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FieldType>>, "variables">) => Record<string, FieldType>) => void; | ||
subscribeToMore: <TSubscriptionData = Record<string, FieldType>, TSubscriptionVariables extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(options: import("@apollo/client").SubscribeToMoreOptions<Record<string, FieldType>, TSubscriptionVariables, TSubscriptionData>) => () => void; | ||
updateQuery: <TVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(mapFn: (previousQueryResult: Record<string, FieldType>, options: Pick<import("@apollo/client").WatchQueryOptions<TVars, Record<string, FieldType>>, "variables">) => Record<string, FieldType>) => void; | ||
refetch: (variables?: Partial<import("@apollo/client").OperationVariables> | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FieldType>>>; | ||
reobserve: (newOptions?: Partial<import("@apollo/client").WatchQueryOptions<import("@apollo/client").OperationVariables, Record<string, FieldType>>> | undefined, newNetworkStatus?: import("@apollo/client").NetworkStatus | undefined) => Promise<import("@apollo/client").ApolloQueryResult<Record<string, FieldType>>>; | ||
fetchMore: <TFetchData = Record<string, FieldType>, TFetchVars = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
fetchMore: <TFetchData = Record<string, FieldType>, TFetchVars extends import("@apollo/client").OperationVariables = import("@apollo/client").OperationVariables>(fetchMoreOptions: import("@apollo/client").FetchMoreQueryOptions<TFetchVars, TFetchData> & { | ||
updateQuery?: ((previousQueryResult: Record<string, FieldType>, options: { | ||
@@ -21,0 +21,0 @@ fetchMoreResult: TFetchData; |
@@ -9,3 +9,3 @@ "use strict"; | ||
var _a; | ||
const result = client_1.useQuery(query, { | ||
const result = (0, client_1.useQuery)(query, { | ||
fetchPolicy: 'cache-only', | ||
@@ -12,0 +12,0 @@ }); |
@@ -10,6 +10,6 @@ "use strict"; | ||
function useOnce(value) { | ||
const valueRef = react_1.useRef(); | ||
const hasCachedValueRef = react_1.useRef(false); | ||
const valueRef = (0, react_1.useRef)(); | ||
const hasCachedValueRef = (0, react_1.useRef)(false); | ||
if (!hasCachedValueRef.current) { | ||
if (isFunction_1.default(value)) { | ||
if ((0, isFunction_1.default)(value)) { | ||
valueRef.current = value(); | ||
@@ -16,0 +16,0 @@ } |
@@ -106,7 +106,7 @@ "use strict"; | ||
policyAction(mutedCacheOperations, Object.assign({ id: dataId, fieldName, | ||
storeFieldName, variables: storeFieldNames.entries[storeFieldName].variables, args: storeFieldNames.entries[storeFieldName].args, ref: core_1.makeReference(dataId), storage: this.getPolicyActionStorage(storeFieldName) }, policyMeta)); | ||
storeFieldName, variables: storeFieldNames.entries[storeFieldName].variables, args: storeFieldNames.entries[storeFieldName].args, ref: (0, core_1.makeReference)(dataId), storage: this.getPolicyActionStorage(storeFieldName) }, policyMeta)); | ||
}); | ||
} | ||
else { | ||
policyAction(mutedCacheOperations, Object.assign({ id: dataId, storage: this.getPolicyActionStorage(dataId), ref: core_1.makeReference(dataId) }, policyMeta)); | ||
policyAction(mutedCacheOperations, Object.assign({ id: dataId, storage: this.getPolicyActionStorage(dataId), ref: (0, core_1.makeReference)(dataId) }, policyMeta)); | ||
} | ||
@@ -131,3 +131,3 @@ }); | ||
const { cacheOperations, entityTypeMap, policies } = this.config; | ||
const entityId = helpers_1.makeEntityId(dataId, fieldName); | ||
const entityId = (0, helpers_1.makeEntityId)(dataId, fieldName); | ||
const typeMapEntity = entityTypeMap.readEntityById(entityId); | ||
@@ -153,3 +153,3 @@ if (!typeMapEntity) { | ||
const timeToLive = ((_a = this.getPolicy(typename)) === null || _a === void 0 ? void 0 : _a.timeToLive) || policies.timeToLive; | ||
if (isNumber_1.default(entityCacheTime) && | ||
if ((0, isNumber_1.default)(entityCacheTime) && | ||
timeToLive && | ||
@@ -156,0 +156,0 @@ Date.now() > entityCacheTime + timeToLive) { |
@@ -36,3 +36,3 @@ import EntityTypeMap from "../entity-store/EntityTypeMap"; | ||
} | ||
export declare type PolicyActionStorage = Record<string, Record<string, any>>; | ||
export type PolicyActionStorage = Record<string, Record<string, any>>; | ||
export interface PolicyActionFields { | ||
@@ -47,9 +47,9 @@ id: string; | ||
} | ||
export declare type PolicyActionEntity = PolicyActionFields & PolicyActionMeta; | ||
export type PolicyActionEntity = PolicyActionFields & PolicyActionMeta; | ||
export interface PolicyActionMeta { | ||
parent: Omit<PolicyActionFields, 'storage'>; | ||
} | ||
export declare type PolicyAction = (cacheOperations: PolicyActionCacheOperations, entity: PolicyActionEntity) => void; | ||
export declare type DefaultPolicyAction = (cacheOperations: PolicyActionCacheOperations, entity: Pick<PolicyActionEntity, 'storage' | 'parent'>) => void; | ||
export declare type InvalidationPolicy = { | ||
export type PolicyAction = (cacheOperations: PolicyActionCacheOperations, entity: PolicyActionEntity) => void; | ||
export type DefaultPolicyAction = (cacheOperations: PolicyActionCacheOperations, entity: Pick<PolicyActionEntity, 'storage' | 'parent'>) => void; | ||
export type InvalidationPolicy = { | ||
[lifecycleEvent in InvalidationPolicyLifecycleEvent]?: Record<string, PolicyAction> & { | ||
@@ -62,3 +62,3 @@ __default?: DefaultPolicyAction; | ||
}; | ||
export declare type CacheOperations = { | ||
export type CacheOperations = { | ||
evict: (options: Cache.EvictOptions) => boolean; | ||
@@ -68,3 +68,3 @@ modify: (options: Cache.ModifyOptions) => boolean; | ||
}; | ||
export declare type PolicyActionCacheOperations = { | ||
export type PolicyActionCacheOperations = { | ||
evict: (options: Omit<Cache.EvictOptions, "broadcast">) => boolean; | ||
@@ -79,5 +79,5 @@ modify: (options: Omit<Cache.ModifyOptions, "broadcast">) => boolean; | ||
} | ||
export declare type InvalidationPolicyEventActivation = { | ||
export type InvalidationPolicyEventActivation = { | ||
[key in InvalidationPolicyEvent]: boolean; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
InvalidationPolicyEvent["Read"] = "Read"; | ||
})(InvalidationPolicyEvent = exports.InvalidationPolicyEvent || (exports.InvalidationPolicyEvent = {})); | ||
})(InvalidationPolicyEvent || (exports.InvalidationPolicyEvent = InvalidationPolicyEvent = {})); | ||
var InvalidationPolicyLifecycleEvent; | ||
@@ -15,3 +15,3 @@ (function (InvalidationPolicyLifecycleEvent) { | ||
InvalidationPolicyLifecycleEvent["Evict"] = "onEvict"; | ||
})(InvalidationPolicyLifecycleEvent = exports.InvalidationPolicyLifecycleEvent || (exports.InvalidationPolicyLifecycleEvent = {})); | ||
})(InvalidationPolicyLifecycleEvent || (exports.InvalidationPolicyLifecycleEvent = InvalidationPolicyLifecycleEvent = {})); | ||
var RenewalPolicy; | ||
@@ -23,3 +23,3 @@ (function (RenewalPolicy) { | ||
RenewalPolicy["None"] = "none"; | ||
})(RenewalPolicy = exports.RenewalPolicy || (exports.RenewalPolicy = {})); | ||
})(RenewalPolicy || (exports.RenewalPolicy = RenewalPolicy = {})); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@nerdwallet/apollo-cache-policies", | ||
"version": "2.9.1", | ||
"version": "2.10.0", | ||
"description": "An extension to the InMemoryCache from Apollo that adds additional cache policies.", | ||
@@ -30,3 +30,3 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@apollo/client": "^3.7.0", | ||
"@apollo/client": "^3.8.1", | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" | ||
@@ -40,3 +40,3 @@ }, | ||
"devDependencies": { | ||
"@apollo/client": "^3.7.0", | ||
"@apollo/client": "^3.8.1", | ||
"@types/graphql": "^14.5.0", | ||
@@ -53,4 +53,4 @@ "@types/jest": "^28.1.6", | ||
"ts-jest": "^28.0.7", | ||
"typescript": "^4.3.2" | ||
"typescript": "^5.1.6" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
333902
2477