diff --git a/packages/active-record/src/-private/builders/find-record.ts b/packages/active-record/src/-private/builders/find-record.ts index 9a34e7e461..1c3fb1acfb 100644 --- a/packages/active-record/src/-private/builders/find-record.ts +++ b/packages/active-record/src/-private/builders/find-record.ts @@ -56,9 +56,9 @@ export type FindRecordResultDocument = Omit, 'd * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/active-record/src/-private/builders/query.ts b/packages/active-record/src/-private/builders/query.ts index 5770a5ab82..6ff5ba9c51 100644 --- a/packages/active-record/src/-private/builders/query.ts +++ b/packages/active-record/src/-private/builders/query.ts @@ -42,9 +42,9 @@ import { copyForwardUrlOptions, extractCacheOptions } from './-utils'; * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/active-record/src/-private/builders/save-record.ts b/packages/active-record/src/-private/builders/save-record.ts index 3e64613e7e..3265d71eae 100644 --- a/packages/active-record/src/-private/builders/save-record.ts +++ b/packages/active-record/src/-private/builders/save-record.ts @@ -50,9 +50,9 @@ function isExisting(identifier: StableRecordIdentifier): identifier is StableExi * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -128,9 +128,9 @@ export function deleteRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -202,9 +202,9 @@ export function createRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/core-types/src/request.ts b/packages/core-types/src/request.ts index c040412b19..2604534fe2 100644 --- a/packages/core-types/src/request.ts +++ b/packages/core-types/src/request.ts @@ -44,7 +44,7 @@ export type CacheOptions = { /** * Useful for metadata around when to invalidate the cache. Typically used * by strategies that invalidate requests by resource type when a new resource - * of that type has been created. See the LifetimesService implementation + * of that type has been created. See the CachePolicy implementation * provided by `@ember-data/request-utils` for an example. * * It is recommended to only use this for query/queryRecord requests where diff --git a/packages/json-api/src/-private/builders/find-record.ts b/packages/json-api/src/-private/builders/find-record.ts index bc41237d16..fc8d0f9300 100644 --- a/packages/json-api/src/-private/builders/find-record.ts +++ b/packages/json-api/src/-private/builders/find-record.ts @@ -52,9 +52,9 @@ import { ACCEPT_HEADER_VALUE, copyForwardUrlOptions, extractCacheOptions } from * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/json-api/src/-private/builders/query.ts b/packages/json-api/src/-private/builders/query.ts index 736382b3eb..520c69f855 100644 --- a/packages/json-api/src/-private/builders/query.ts +++ b/packages/json-api/src/-private/builders/query.ts @@ -49,9 +49,9 @@ import { ACCEPT_HEADER_VALUE, copyForwardUrlOptions, extractCacheOptions } from * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -137,9 +137,9 @@ export function query( * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/json-api/src/-private/builders/save-record.ts b/packages/json-api/src/-private/builders/save-record.ts index a32b0bbf8f..591b2133be 100644 --- a/packages/json-api/src/-private/builders/save-record.ts +++ b/packages/json-api/src/-private/builders/save-record.ts @@ -48,9 +48,9 @@ function isExisting(identifier: StableRecordIdentifier): identifier is StableExi * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -126,9 +126,9 @@ export function deleteRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -200,9 +200,9 @@ export function createRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/legacy-compat/src/legacy-network-handler/legacy-network-handler.ts b/packages/legacy-compat/src/legacy-network-handler/legacy-network-handler.ts index 2db5a0be8f..82e50aae51 100644 --- a/packages/legacy-compat/src/legacy-network-handler/legacy-network-handler.ts +++ b/packages/legacy-compat/src/legacy-network-handler/legacy-network-handler.ts @@ -207,7 +207,7 @@ function saveRecord(context: StoreRequestContext): Promise { // blatantly lie if we were a createRecord request // to give some semblance of cache-control to the - // lifetimes service while legacy is still around + // CachePolicy while legacy is still around if (store.lifetimes?.didRequest && operation === 'createRecord') { store.lifetimes.didRequest(context.request, { status: 201 } as Response, null, store); } diff --git a/packages/request-utils/src/index.ts b/packages/request-utils/src/index.ts index 0d121ed50e..bfaac328b8 100644 --- a/packages/request-utils/src/index.ts +++ b/packages/request-utils/src/index.ts @@ -644,10 +644,10 @@ function isStale(headers: Headers, expirationTime: number): boolean { return result; } -export type LifetimesConfig = { apiCacheSoftExpires: number; apiCacheHardExpires: number }; +export type PolicyConfig = { apiCacheSoftExpires: number; apiCacheHardExpires: number }; /** - * A basic LifetimesService that can be added to the Store service. + * A basic CachePolicy that can be added to the Store service. * * Determines staleness based on time since the request was last received from the API * using the `date` header. @@ -678,7 +678,7 @@ export type LifetimesConfig = { apiCacheSoftExpires: number; apiCacheHardExpires * Usage: * * ```ts - * import { LifetimesService } from '@ember-data/request-utils'; + * import { CachePolicy } from '@ember-data/request-utils'; * import DataStore from '@ember-data/store'; * * // ... @@ -686,17 +686,17 @@ export type LifetimesConfig = { apiCacheSoftExpires: number; apiCacheHardExpires * export class Store extends DataStore { * constructor(args) { * super(args); - * this.lifetimes = new LifetimesService({ apiCacheSoftExpires: 30_000, apiCacheHardExpires: 60_000 }); + * this.lifetimes = new CachePolicy({ apiCacheSoftExpires: 30_000, apiCacheHardExpires: 60_000 }); * } * } * ``` * - * @class LifetimesService + * @class CachePolicy * @public * @module @ember-data/request-utils */ -export class LifetimesService { - declare config: LifetimesConfig; +export class CachePolicy { + declare config: PolicyConfig; declare _stores: WeakMap; types: Map> }>; _getStore(store: Store): { invalidated: Set; types: Map> } { @@ -708,12 +708,12 @@ export class LifetimesService { return set; } - constructor(config: LifetimesConfig) { + constructor(config: PolicyConfig) { this._stores = new WeakMap(); - const _config = arguments.length === 1 ? config : (arguments[1] as unknown as LifetimesConfig); + const _config = arguments.length === 1 ? config : (arguments[1] as unknown as PolicyConfig); deprecate( - `Passing a Store to the LifetimesService is deprecated, please pass only a config instead.`, + `Passing a Store to the CachePolicy is deprecated, please pass only a config instead.`, arguments.length === 1, { id: 'ember-data:request-utils:lifetimes-service-store-arg', @@ -725,22 +725,16 @@ export class LifetimesService { until: '6.0', } ); - assert(`You must pass a config to the LifetimesService`, _config); - assert( - `You must pass a apiCacheSoftExpires to the LifetimesService`, - typeof _config.apiCacheSoftExpires === 'number' - ); - assert( - `You must pass a apiCacheHardExpires to the LifetimesService`, - typeof _config.apiCacheHardExpires === 'number' - ); + assert(`You must pass a config to the CachePolicy`, _config); + assert(`You must pass a apiCacheSoftExpires to the CachePolicy`, typeof _config.apiCacheSoftExpires === 'number'); + assert(`You must pass a apiCacheHardExpires to the CachePolicy`, typeof _config.apiCacheHardExpires === 'number'); this.config = _config; } /** * Invalidate a request by its identifier for a given store instance. * - * While the store argument may seem redundant, the lifetimes service + * While the store argument may seem redundant, the CachePolicy * is designed to be shared across multiple stores / forks * of the store. * @@ -761,7 +755,7 @@ export class LifetimesService { * Invalidate all requests associated to a specific type * for a given store instance. * - * While the store argument may seem redundant, the lifetimes service + * While the store argument may seem redundant, the CachePolicy * is designed to be shared across multiple stores / forks * of the store. * @@ -892,3 +886,22 @@ export class LifetimesService { return !cached || !cached.response || isStale(cached.response.headers, this.config.apiCacheSoftExpires); } } + +export class LifetimesService extends CachePolicy { + constructor(config: PolicyConfig) { + deprecate( + `\`import { LifetimesService } from '@ember-data/request-utils';\` is deprecated, please use \`import { CachePolicy } from '@ember-data/request-utils';\` instead.`, + false, + { + id: 'ember-data:deprecate-lifetimes-service-import', + since: { + enabled: '5.4', + available: '5.4', + }, + for: 'ember-data', + until: '6.0', + } + ); + super(config); + } +} diff --git a/packages/rest/src/-private/builders/find-record.ts b/packages/rest/src/-private/builders/find-record.ts index c82c882027..c3e1d7c8bf 100644 --- a/packages/rest/src/-private/builders/find-record.ts +++ b/packages/rest/src/-private/builders/find-record.ts @@ -54,9 +54,9 @@ import { copyForwardUrlOptions, extractCacheOptions } from './-utils'; * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/rest/src/-private/builders/query.ts b/packages/rest/src/-private/builders/query.ts index 508cc807ee..243569fe5f 100644 --- a/packages/rest/src/-private/builders/query.ts +++ b/packages/rest/src/-private/builders/query.ts @@ -42,9 +42,9 @@ import { copyForwardUrlOptions, extractCacheOptions } from './-utils'; * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/rest/src/-private/builders/save-record.ts b/packages/rest/src/-private/builders/save-record.ts index f619fb3cfd..dbe45af1c8 100644 --- a/packages/rest/src/-private/builders/save-record.ts +++ b/packages/rest/src/-private/builders/save-record.ts @@ -50,9 +50,9 @@ function isExisting(identifier: StableRecordIdentifier): identifier is StableExi * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -128,9 +128,9 @@ export function deleteRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * @@ -202,9 +202,9 @@ export function createRecord(record: unknown, options: ConstrainedRequestOptions * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`. * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this - * option will delegate to the store's lifetimes service, defaulting to `false` if none is configured. + * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured. * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the - * promise with the cached value, not supplying this option will delegate to the store's lifetimes service, + * promise with the cached value, not supplying this option will delegate to the store's CachePolicy, * defaulting to `false` if none is configured. * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`) * diff --git a/packages/store/src/-private.ts b/packages/store/src/-private.ts index 9584f25621..cf1c6bbc91 100644 --- a/packages/store/src/-private.ts +++ b/packages/store/src/-private.ts @@ -6,7 +6,7 @@ export { Store, storeFor } from './-private/store-service'; export { recordIdentifierFor } from './-private/caches/instance-cache'; -export { CacheHandler, type LifetimesService, type StoreRequestContext } from './-private/cache-handler'; +export { CacheHandler, type CachePolicy, type StoreRequestContext } from './-private/cache-handler'; export { isStableIdentifier } from './-private/caches/identifier-cache'; diff --git a/packages/store/src/-private/cache-handler.ts b/packages/store/src/-private/cache-handler.ts index 14285b6bb8..b116e236b9 100644 --- a/packages/store/src/-private/cache-handler.ts +++ b/packages/store/src/-private/cache-handler.ts @@ -38,10 +38,10 @@ import type { Store } from './store-service'; * Implementing this service allows you to programatically define * when a request should be considered expired. * - * @class LifetimesService + * @class CachePolicy * @public */ -export interface LifetimesService { +export interface CachePolicy { /** * Invoked to determine if the request may be fulfilled from cache * if possible. diff --git a/packages/store/src/-private/store-service.ts b/packages/store/src/-private/store-service.ts index f469e064bd..ba1d099a0f 100644 --- a/packages/store/src/-private/store-service.ts +++ b/packages/store/src/-private/store-service.ts @@ -37,7 +37,7 @@ import type { ModelSchema } from '../-types/q/ds-model'; import type { OpaqueRecordInstance } from '../-types/q/record-instance'; import type { SchemaService } from '../-types/q/schema-service'; import type { FindAllOptions, FindRecordOptions, LegacyResourceQuery, QueryOptions } from '../-types/q/store'; -import type { LifetimesService, StoreRequestInput } from './cache-handler'; +import type { CachePolicy, StoreRequestInput } from './cache-handler'; import { IdentifierCache } from './caches/identifier-cache'; import { InstanceCache, @@ -238,7 +238,7 @@ export class Store extends BaseClass { declare requestManager: RequestManager; /** - * A Property which an App may set to provide a Lifetimes Service + * A Property which an App may set to provide a CachePolicy * to control when a cached request becomes stale. * * Note, when defined, these methods will only be invoked if a @@ -264,9 +264,9 @@ export class Store extends BaseClass { * ``` * * @public - * @property {LivetimesService|undefined} lifetimes + * @property {CachePolicy|undefined} lifetimes */ - declare lifetimes?: LifetimesService; + declare lifetimes?: CachePolicy; // Private declare _graph?: Graph; @@ -434,7 +434,7 @@ export class Store extends BaseClass { * When a cache-key is determined, the request may fulfill * from cache provided the cache is not stale. * - * Cache staleness is determined by the configured LifetimesService + * Cache staleness is determined by the configured CachePolicy * with priority given to the `cacheOptions.reload` and * `cacheOptions.backgroundReload` on the request if present. * diff --git a/packages/store/src/index.ts b/packages/store/src/index.ts index 8df161afb6..57dd5b23a7 100644 --- a/packages/store/src/index.ts +++ b/packages/store/src/index.ts @@ -187,7 +187,7 @@ export { type StoreRequestContext, CacheHandler, type Document, - type LifetimesService, + type CachePolicy, type StoreRequestInput, recordIdentifierFor, storeFor, diff --git a/tests/docs/fixtures/expected.js b/tests/docs/fixtures/expected.js index 2b9e7c421c..4785b53d05 100644 --- a/tests/docs/fixtures/expected.js +++ b/tests/docs/fixtures/expected.js @@ -47,10 +47,10 @@ module.exports = { '(public) @ember-data/store IdentifierCache#getOrCreateDocumentIdentifier', '(public) @ember-data/store Store#registerSchema', '(public) @ember-data/store Store#schema', - '(public) @ember-data/store LifetimesService#didRequest [Optional]', - '(public) @ember-data/store LifetimesService#isHardExpired', - '(public) @ember-data/store LifetimesService#isSoftExpired', - '(public) @ember-data/store LifetimesService#willRequest [Optional]', + '(public) @ember-data/store CachePolicy#didRequest [Optional]', + '(public) @ember-data/store CachePolicy#isHardExpired', + '(public) @ember-data/store CachePolicy#isSoftExpired', + '(public) @ember-data/store CachePolicy#willRequest [Optional]', '(private) @ember-data/adapter BuildURLMixin#_buildURL', '(private) @ember-data/adapter BuildURLMixin#urlPrefix', '(private) @ember-data/adapter/json-api JSONAPIAdapter#ajaxOptions', @@ -400,11 +400,11 @@ module.exports = { '(public) @ember-data/request-utils @ember-data/request-utils#parseCacheControl', '(public) @ember-data/request-utils @ember-data/request-utils#setBuildURLConfig', '(public) @ember-data/request-utils @ember-data/request-utils#sortQueryParams', - '(public) @ember-data/request-utils LifetimesService#didRequest', - '(public) @ember-data/request-utils LifetimesService#invalidateRequest', - '(public) @ember-data/request-utils LifetimesService#invalidateRequestsForType', - '(public) @ember-data/request-utils LifetimesService#isHardExpired', - '(public) @ember-data/request-utils LifetimesService#isSoftExpired', + '(public) @ember-data/request-utils CachePolicy#didRequest', + '(public) @ember-data/request-utils CachePolicy#invalidateRequest', + '(public) @ember-data/request-utils CachePolicy#invalidateRequestsForType', + '(public) @ember-data/request-utils CachePolicy#isHardExpired', + '(public) @ember-data/request-utils CachePolicy#isSoftExpired', '(public) @ember-data/rest/request @ember-data/rest/request#findRecord', '(public) @ember-data/rest/request @ember-data/rest/request#query', '(public) @ember-data/rest/request @ember-data/rest/request#createRecord', diff --git a/tests/example-json-api/app/services/store.ts b/tests/example-json-api/app/services/store.ts index c40420f1e5..beb54bc5fb 100644 --- a/tests/example-json-api/app/services/store.ts +++ b/tests/example-json-api/app/services/store.ts @@ -3,7 +3,7 @@ import { service } from '@ember/service'; import Store from 'ember-data/store'; import type RequestManager from '@ember-data/request'; -import { LifetimesService } from '@ember-data/request-utils'; +import { CachePolicy } from '@ember-data/request-utils'; import CONFIG from '../config/environment'; @@ -16,6 +16,6 @@ export default class MyStore extends Store { constructor(args: Record) { super(args); - this.lifetimes = new LifetimesService(CONFIG); + this.lifetimes = new CachePolicy(CONFIG); } } diff --git a/tests/main/tests/integration/cache-handler/lifetimes-test.ts b/tests/main/tests/integration/cache-handler/lifetimes-test.ts index 18f26b8c0f..1804848b21 100644 --- a/tests/main/tests/integration/cache-handler/lifetimes-test.ts +++ b/tests/main/tests/integration/cache-handler/lifetimes-test.ts @@ -7,7 +7,7 @@ import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; import type { Snapshot } from '@ember-data/legacy-compat/-private'; import type { ImmutableRequestInfo, NextFn, RequestContext, ResponseInfo } from '@ember-data/request'; import RequestManager from '@ember-data/request'; -import { LifetimesService } from '@ember-data/request-utils'; +import { CachePolicy } from '@ember-data/request-utils'; import type { NotificationType } from '@ember-data/store'; import Store, { CacheHandler } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/types'; @@ -208,8 +208,8 @@ module('Store | CacheHandler + Lifetimes', function (hooks) { assert.verifySteps(['isHardExpired', 'isSoftExpired']); }); - test('@ember-data/request-utils LifetimesService handles createRecord requests', async function (assert) { - class InterceptLifetimes extends LifetimesService { + test('@ember-data/request-utils CachePolicy handles createRecord requests', async function (assert) { + class InterceptLifetimes extends CachePolicy { override didRequest( request: ImmutableRequestInfo, response: Response | ResponseInfo | null, @@ -368,7 +368,7 @@ module('Store | CacheHandler + Lifetimes', function (hooks) { ); }); - test('@ember-data/request-utils legacy createRecord operations invalidate the LifetimesService type list', async function (assert) { + test('@ember-data/request-utils legacy createRecord operations invalidate the CachePolicy type list', async function (assert) { class AppAdapter { createRecord( _store: Store, @@ -380,7 +380,7 @@ module('Store | CacheHandler + Lifetimes', function (hooks) { } } const adapter = new AppAdapter(); - class InterceptLifetimes extends LifetimesService { + class InterceptLifetimes extends CachePolicy { override didRequest( request: ImmutableRequestInfo, response: Response | ResponseInfo | null, @@ -540,7 +540,7 @@ module('Store | CacheHandler + Lifetimes', function (hooks) { }); test('An AdHoc createRecord request can invalidate the request cache via records', async function (assert) { - class InterceptLifetimes extends LifetimesService { + class InterceptLifetimes extends CachePolicy { override didRequest( request: ImmutableRequestInfo, response: Response | ResponseInfo | null, @@ -701,7 +701,7 @@ module('Store | CacheHandler + Lifetimes', function (hooks) { }); test('An AdHoc createRecord request can invalidate the request cache via cacheOptions', async function (assert) { - class InterceptLifetimes extends LifetimesService { + class InterceptLifetimes extends CachePolicy { override didRequest( request: ImmutableRequestInfo, response: Response | ResponseInfo | null,