@warp-drive/core 5.7.0-alpha.2 → 5.7.0-alpha.21
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/declarations/graph/-private/-diff.d.ts +8 -8
- package/declarations/graph/-private/-edge-definition.d.ts +2 -2
- package/declarations/graph/-private/-state.d.ts +2 -2
- package/declarations/graph/-private/-utils.d.ts +5 -5
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +5 -5
- package/declarations/graph/-private/graph.d.ts +17 -15
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -21
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +50 -25
- package/declarations/reactive/-private/schema.d.ts +18 -14
- package/declarations/reactive/-private/symbols.d.ts +2 -7
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +2 -2
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +3 -6
- package/declarations/request/-private/types.d.ts +4 -4
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
- package/declarations/store/-private/caches/instance-cache.d.ts +20 -18
- package/declarations/store/-private/default-cache-policy.d.ts +25 -38
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +13 -11
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +22 -19
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -94
- package/declarations/store/-private/managers/notification-manager.d.ts +21 -25
- package/declarations/store/-private/managers/record-array-manager.d.ts +78 -27
- package/declarations/store/-private/network/request-cache.d.ts +11 -11
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +1 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +15 -22
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +4 -8
- package/declarations/store/-private/record-arrays/-utils.d.ts +82 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +89 -0
- package/declarations/store/-private/record-arrays/{many-array.d.ts → legacy-many-array.d.ts} +43 -101
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +103 -0
- package/declarations/store/-private/record-arrays/resource-array.d.ts +82 -0
- package/declarations/store/-private/store-service.d.ts +78 -35
- package/declarations/store/-private.d.ts +5 -5
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/schema-service.d.ts +28 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -12
- package/declarations/store/deprecated/store.d.ts +11 -12
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +2 -2
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -13
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -4
- package/declarations/types/cache.d.ts +51 -113
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +60 -76
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +47 -35
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +378 -14
- package/declarations/types/spec/document.d.ts +6 -6
- package/dist/{context-COmAnXUQ.js → context-kQXhkeBj.js} +13 -0
- package/dist/graph/-private.js +135 -139
- package/dist/index.js +6 -3
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +193 -1409
- package/dist/{request-state-CejVJgdj.js → request-state-glkInb2R.js} +5139 -2758
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -2
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +27 -0
- package/dist/types/schema/fields.js +23 -2
- package/package.json +3 -3
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/dist/handler-D2jjnIA-.js +0 -339
|
@@ -3,12 +3,54 @@ import { ContextOwner } from "./context.js";
|
|
|
3
3
|
import type { DeferredFuture, Future, GodContext, Handler } from "./types.js";
|
|
4
4
|
export declare const IS_CACHE_HANDLER: "___(unique) Symbol(IS_CACHE_HANDLER)";
|
|
5
5
|
export declare function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T>;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Additional properties exposed on errors thrown by the
|
|
8
|
+
* {@link Fetch | Fetch Handler}.
|
|
9
|
+
*
|
|
10
|
+
* In the case of an Abort or system/browser level issue,
|
|
11
|
+
* this extends {@link DOMException}.
|
|
12
|
+
*
|
|
13
|
+
* Else it extends from {@link AggregateError} if the
|
|
14
|
+
* response includes an array of errors, falling back
|
|
15
|
+
* to {@link Error} as its base.
|
|
16
|
+
*/
|
|
17
|
+
export interface FetchError extends DOMException {
|
|
18
|
+
/**
|
|
19
|
+
* Alias for {@link FetchError.status | status}.
|
|
20
|
+
*
|
|
21
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status)
|
|
22
|
+
*/
|
|
7
23
|
code: number;
|
|
24
|
+
/**
|
|
25
|
+
* The name associated to the {@link FetchError.status | status code}.
|
|
26
|
+
*
|
|
27
|
+
* Typically this will be of the formula `StatusTextError` for instance
|
|
28
|
+
* a 404 status with status text of `Not Found` would have the name
|
|
29
|
+
* `NotFoundError`.
|
|
30
|
+
*/
|
|
8
31
|
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* The http status code associated to the returned error.
|
|
34
|
+
*
|
|
35
|
+
* Browser/System level network errors will often have an error code of `0` or `5`.
|
|
36
|
+
* Aborted requests will have an error code of `20`.
|
|
37
|
+
*
|
|
38
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status)
|
|
39
|
+
*/
|
|
9
40
|
status: number;
|
|
41
|
+
/**
|
|
42
|
+
* The Status Text associated to the {@link FetchError.status | status code}
|
|
43
|
+
* for the error.
|
|
44
|
+
*
|
|
45
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText)
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
10
48
|
statusText: string;
|
|
11
|
-
|
|
49
|
+
/**
|
|
50
|
+
* A property signifying that an Error uses the {@link FetchError}
|
|
51
|
+
* interface.
|
|
52
|
+
*/
|
|
53
|
+
isRequestError: true;
|
|
12
54
|
}
|
|
13
55
|
export declare function enhanceReason(reason?: string): DOMException;
|
|
14
56
|
export declare function handleOutcome<T>(owner: ContextOwner, inbound: Promise<T | StructuredDataDocument<T>>, outbound: DeferredFuture<T>): Future<T>;
|
|
@@ -3,17 +3,11 @@ import type { ImmutableRequestInfo, RequestContext } from "../../../types/reques
|
|
|
3
3
|
import type { ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
|
|
4
4
|
import type { RequestSignature } from "../../../types/symbols.js";
|
|
5
5
|
import type { Store } from "../store-service.js";
|
|
6
|
-
export type LooseStoreRequestInfo<
|
|
7
|
-
RT = unknown,
|
|
8
|
-
T = unknown
|
|
9
|
-
> = Omit<ImmutableRequestInfo<RT, T>, "records" | "headers" | typeof RequestSignature> & {
|
|
6
|
+
export type LooseStoreRequestInfo<RT = unknown> = Omit<ImmutableRequestInfo<RT>, "records" | "headers" | typeof RequestSignature> & {
|
|
10
7
|
records?: ResourceIdentifierObject[];
|
|
11
8
|
headers?: Headers;
|
|
12
9
|
};
|
|
13
|
-
export type StoreRequestInput<
|
|
14
|
-
RT = unknown,
|
|
15
|
-
T = unknown
|
|
16
|
-
> = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;
|
|
10
|
+
export type StoreRequestInput<RT = unknown> = ImmutableRequestInfo<RT> | LooseStoreRequestInfo<RT>;
|
|
17
11
|
export interface StoreRequestContext extends RequestContext {
|
|
18
12
|
request: ImmutableRequestInfo & {
|
|
19
13
|
store: Store;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { ImmutableRequestInfo, ResponseInfo } from "../../../types/request.js";
|
|
3
3
|
import type { Store } from "../store-service.js";
|
|
4
4
|
/**
|
|
@@ -27,11 +27,11 @@ export interface CachePolicy {
|
|
|
27
27
|
* and the cache will be updated before returning the response.
|
|
28
28
|
*
|
|
29
29
|
* @public
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {RequestKey} identifier
|
|
31
31
|
* @param {Store} store
|
|
32
32
|
* @return {Boolean} true if the request is considered hard expired
|
|
33
33
|
*/
|
|
34
|
-
isHardExpired(identifier:
|
|
34
|
+
isHardExpired(identifier: RequestKey, store: Store): boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Invoked if `isHardExpired` is false to determine if the request
|
|
37
37
|
* should be update behind the scenes if cache data is already available.
|
|
@@ -42,11 +42,11 @@ export interface CachePolicy {
|
|
|
42
42
|
* request is made to update the cache via the configured request handlers.
|
|
43
43
|
*
|
|
44
44
|
* @public
|
|
45
|
-
* @param {
|
|
45
|
+
* @param {RequestKey} identifier
|
|
46
46
|
* @param {Store} store
|
|
47
47
|
* @return {Boolean} true if the request is considered soft expired
|
|
48
48
|
*/
|
|
49
|
-
isSoftExpired(identifier:
|
|
49
|
+
isSoftExpired(identifier: RequestKey, store: Store): boolean;
|
|
50
50
|
/**
|
|
51
51
|
* Invoked when a request will be sent to the configured request handlers.
|
|
52
52
|
* This is invoked for both foreground and background requests.
|
|
@@ -55,11 +55,11 @@ export interface CachePolicy {
|
|
|
55
55
|
*
|
|
56
56
|
* @public
|
|
57
57
|
* @param {ImmutableRequestInfo} request
|
|
58
|
-
* @param {
|
|
58
|
+
* @param {RequestKey | null} identifier
|
|
59
59
|
* @param {Store} store
|
|
60
60
|
* @return {void}
|
|
61
61
|
*/
|
|
62
|
-
willRequest?(request: ImmutableRequestInfo, identifier:
|
|
62
|
+
willRequest?(request: ImmutableRequestInfo, identifier: RequestKey | null, store: Store): void;
|
|
63
63
|
/**
|
|
64
64
|
* Invoked when a request has been fulfilled from the configured request handlers.
|
|
65
65
|
* This is invoked for both foreground and background requests once the cache has
|
|
@@ -71,7 +71,7 @@ export interface CachePolicy {
|
|
|
71
71
|
* so that request subscriptions can reload when needed.
|
|
72
72
|
*
|
|
73
73
|
* ```ts
|
|
74
|
-
* store.notifications.notify(identifier, 'invalidated');
|
|
74
|
+
* store.notifications.notify(identifier, 'invalidated', null);
|
|
75
75
|
* ```
|
|
76
76
|
*
|
|
77
77
|
* This allows anything subscribed to the request to be notified of the change
|
|
@@ -90,9 +90,9 @@ export interface CachePolicy {
|
|
|
90
90
|
* @public
|
|
91
91
|
* @param {ImmutableRequestInfo} request
|
|
92
92
|
* @param {ImmutableResponse} response
|
|
93
|
-
* @param {
|
|
93
|
+
* @param {RequestKey | null} identifier
|
|
94
94
|
* @param {Store} store
|
|
95
95
|
* @return {void}
|
|
96
96
|
*/
|
|
97
|
-
didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier:
|
|
97
|
+
didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: RequestKey | null, store: Store): void;
|
|
98
98
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from "../../../types/request.js";
|
|
3
3
|
import type { ResourceDataDocument, ResourceErrorDocument } from "../../../types/spec/document.js";
|
|
4
4
|
import type { ApiError } from "../../../types/spec/error.js";
|
|
5
5
|
import type { Store } from "../store-service.js";
|
|
6
6
|
export declare const MUTATION_OPS: Set<string>;
|
|
7
|
-
export declare function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier:
|
|
8
|
-
export declare function calcShouldBackgroundFetch(store: Store, request: ImmutableRequestInfo, willFetch: boolean, identifier:
|
|
7
|
+
export declare function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier: RequestKey | null): boolean;
|
|
8
|
+
export declare function calcShouldBackgroundFetch(store: Store, request: ImmutableRequestInfo, willFetch: boolean, identifier: RequestKey | null): boolean;
|
|
9
9
|
export declare function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
|
|
10
10
|
export declare function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
|
|
11
11
|
export declare function isAggregateError(error: Error & {
|
|
@@ -21,7 +21,7 @@ export type RobustError = Error & {
|
|
|
21
21
|
// TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
|
|
22
22
|
export declare function cloneError(error: RobustError): RobustError;
|
|
23
23
|
export declare function isErrorDocument(document: ResourceDataDocument | ResourceErrorDocument): document is ResourceErrorDocument;
|
|
24
|
-
export declare function getPriority(identifier:
|
|
24
|
+
export declare function getPriority(identifier: RequestKey | null, deduped: Map<RequestKey, {
|
|
25
25
|
priority: {
|
|
26
26
|
blocking: boolean;
|
|
27
27
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { ReactiveDocument } from "../../../reactive/-private/document.js";
|
|
2
2
|
import type { Cache } from "../../../types/cache.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
4
4
|
import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
|
|
5
5
|
import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
|
|
6
6
|
import { CacheCapabilitiesManager } from "../managers/cache-capabilities-manager.js";
|
|
7
7
|
import type { CacheManager } from "../managers/cache-manager.js";
|
|
8
8
|
import type { CreateRecordProperties, Store } from "../store-service.js";
|
|
9
|
-
export declare function peekRecordIdentifier(record: OpaqueRecordInstance):
|
|
9
|
+
export declare function peekRecordIdentifier(record: OpaqueRecordInstance): ResourceKey | undefined;
|
|
10
10
|
/**
|
|
11
|
-
Retrieves the unique referentially-stable [RecordIdentifier](/ember-data/release/classes/
|
|
11
|
+
Retrieves the unique referentially-stable [RecordIdentifier](/ember-data/release/classes/ResourceKey)
|
|
12
12
|
assigned to the given record instance.
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
15
|
import { recordIdentifierFor } from "@ember-data/store";
|
|
16
16
|
// ... gain access to a record, for instance with peekRecord or findRecord
|
|
17
17
|
const record = store.peekRecord("user", "1");
|
|
18
|
-
// get the identifier for the record (see docs for
|
|
18
|
+
// get the identifier for the record (see docs for ResourceKey)
|
|
19
19
|
const identifier = recordIdentifierFor(record);
|
|
20
20
|
// access the identifier's properties.
|
|
21
21
|
const { id, type, lid } = identifier;
|
|
@@ -23,20 +23,21 @@ const { id, type, lid } = identifier;
|
|
|
23
23
|
|
|
24
24
|
@public
|
|
25
25
|
@param {Object} record a record instance previously obstained from the store.
|
|
26
|
-
@return {
|
|
26
|
+
@return {ResourceKey}
|
|
27
27
|
*/
|
|
28
|
-
export declare function recordIdentifierFor<T extends TypedRecordInstance>(record: T):
|
|
29
|
-
export declare function recordIdentifierFor(record: OpaqueRecordInstance):
|
|
30
|
-
export declare function setRecordIdentifier(record: OpaqueRecordInstance, identifier:
|
|
28
|
+
export declare function recordIdentifierFor<T extends TypedRecordInstance>(record: T): ResourceKey<TypeFromInstance<T>>;
|
|
29
|
+
export declare function recordIdentifierFor(record: OpaqueRecordInstance): ResourceKey;
|
|
30
|
+
export declare function setRecordIdentifier(record: OpaqueRecordInstance, identifier: ResourceKey): void;
|
|
31
|
+
export declare function removeRecordIdentifier(record: OpaqueRecordInstance): void;
|
|
31
32
|
export declare const StoreMap: Map<unknown, Store>;
|
|
32
33
|
/**
|
|
33
34
|
* We may eventually make this public, but its likely better for this to be killed off
|
|
34
35
|
* @internal
|
|
35
36
|
*/
|
|
36
|
-
export declare function storeFor(record: OpaqueRecordInstance): Store |
|
|
37
|
+
export declare function storeFor(record: OpaqueRecordInstance, ignoreMissing: boolean): Store | null;
|
|
37
38
|
export type Caches = {
|
|
38
|
-
record: Map<
|
|
39
|
-
document: Map<
|
|
39
|
+
record: Map<ResourceKey, OpaqueRecordInstance>;
|
|
40
|
+
document: Map<RequestKey, ReactiveDocument<OpaqueRecordInstance | OpaqueRecordInstance[] | null | undefined>>;
|
|
40
41
|
};
|
|
41
42
|
export declare class InstanceCache {
|
|
42
43
|
store: Store;
|
|
@@ -45,14 +46,15 @@ export declare class InstanceCache {
|
|
|
45
46
|
__cacheManager: CacheManager;
|
|
46
47
|
__instances: Caches;
|
|
47
48
|
constructor(store: Store);
|
|
48
|
-
peek(identifier:
|
|
49
|
-
getDocument<T>(identifier:
|
|
50
|
-
getRecord(identifier:
|
|
51
|
-
recordIsLoaded(identifier:
|
|
52
|
-
disconnect(identifier:
|
|
53
|
-
unloadRecord(identifier:
|
|
49
|
+
peek(identifier: ResourceKey): Cache | OpaqueRecordInstance | undefined;
|
|
50
|
+
getDocument<T>(identifier: RequestKey): ReactiveDocument<T>;
|
|
51
|
+
getRecord(identifier: ResourceKey): OpaqueRecordInstance;
|
|
52
|
+
recordIsLoaded(identifier: ResourceKey, filterDeleted?: boolean): boolean;
|
|
53
|
+
disconnect(identifier: ResourceKey): void;
|
|
54
|
+
unloadRecord(identifier: ResourceKey): void;
|
|
54
55
|
clear(type?: string): void;
|
|
55
56
|
// TODO this should move into something coordinating operations
|
|
56
|
-
setRecordId(identifier:
|
|
57
|
+
setRecordId(identifier: ResourceKey, id: string): void;
|
|
57
58
|
}
|
|
59
|
+
export declare function getNewRecord(instances: InstanceCache, identifier: ResourceKey, properties: CreateRecordProperties): OpaqueRecordInstance;
|
|
58
60
|
export declare function _clearCaches(): void;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import type { Cache } from "@warp-drive/core/types/cache";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RequestKey, ResourceKey } from "@warp-drive/core/types/identifier";
|
|
3
3
|
import type { ImmutableRequestInfo, ResponseInfo, StructuredDocument } from "@warp-drive/core/types/request";
|
|
4
4
|
import type { ResourceDocument } from "@warp-drive/core/types/spec/document";
|
|
5
5
|
type UnsubscribeToken = object;
|
|
6
6
|
type CacheOperation = "added" | "removed" | "updated" | "state";
|
|
7
7
|
type DocumentCacheOperation = "invalidated" | "added" | "removed" | "updated" | "state";
|
|
8
8
|
export interface NotificationCallback {
|
|
9
|
-
(
|
|
10
|
-
(
|
|
9
|
+
(resourceKey: ResourceKey, notificationType: "attributes" | "relationships", key?: string): void;
|
|
10
|
+
(resourceKey: ResourceKey, notificationType: "errors" | "meta" | "identity" | "state"): void;
|
|
11
11
|
}
|
|
12
12
|
interface ResourceOperationCallback {
|
|
13
13
|
// resource updates
|
|
14
|
-
(
|
|
14
|
+
(resourceKey: ResourceKey, notificationType: CacheOperation): void;
|
|
15
15
|
}
|
|
16
16
|
interface DocumentOperationCallback {
|
|
17
17
|
// document updates
|
|
18
|
-
(
|
|
18
|
+
(cacheKey: RequestKey, notificationType: DocumentCacheOperation): void;
|
|
19
19
|
}
|
|
20
20
|
type NotificationManager = {
|
|
21
|
-
subscribe(
|
|
22
|
-
subscribe(
|
|
23
|
-
subscribe(
|
|
24
|
-
notify(
|
|
25
|
-
notify(
|
|
26
|
-
notify(
|
|
27
|
-
notify(
|
|
21
|
+
subscribe(resourceKey: ResourceKey, callback: NotificationCallback): UnsubscribeToken;
|
|
22
|
+
subscribe(cacheKey: "resource", callback: ResourceOperationCallback): UnsubscribeToken;
|
|
23
|
+
subscribe(cacheKey: "document" | RequestKey, callback: DocumentOperationCallback): UnsubscribeToken;
|
|
24
|
+
notify(cacheKey: ResourceKey, value: "attributes" | "relationships", key?: string): boolean;
|
|
25
|
+
notify(cacheKey: ResourceKey, value: "errors" | "meta" | "identity" | "state"): boolean;
|
|
26
|
+
notify(cacheKey: ResourceKey, value: CacheOperation): boolean;
|
|
27
|
+
notify(cacheKey: RequestKey, value: DocumentCacheOperation): boolean;
|
|
28
28
|
};
|
|
29
29
|
type Store = {
|
|
30
30
|
cache: Cache;
|
|
@@ -236,7 +236,7 @@ export type PolicyConfig = {
|
|
|
236
236
|
* request for that type is successful.
|
|
237
237
|
*
|
|
238
238
|
* For this to work, the `createRecord` request must include the `cacheOptions.types` array
|
|
239
|
-
* with the types that should be invalidated, or its request should specify the
|
|
239
|
+
* with the types that should be invalidated, or its request should specify the ResourceKeys
|
|
240
240
|
* of the records that are being created via `records`. Providing both is valid.
|
|
241
241
|
*
|
|
242
242
|
* > [!NOTE]
|
|
@@ -285,30 +285,28 @@ export type PolicyConfig = {
|
|
|
285
285
|
export declare class DefaultCachePolicy {
|
|
286
286
|
config: PolicyConfig;
|
|
287
287
|
_stores: WeakMap<Store, {
|
|
288
|
-
invalidated: Set<
|
|
289
|
-
types: Map<string, Set<
|
|
288
|
+
invalidated: Set<RequestKey>;
|
|
289
|
+
types: Map<string, Set<RequestKey>>;
|
|
290
290
|
}>;
|
|
291
291
|
_getStore(store: Store): {
|
|
292
|
-
invalidated: Set<
|
|
293
|
-
types: Map<string, Set<
|
|
292
|
+
invalidated: Set<RequestKey>;
|
|
293
|
+
types: Map<string, Set<RequestKey>>;
|
|
294
294
|
};
|
|
295
295
|
constructor(config: PolicyConfig);
|
|
296
296
|
/**
|
|
297
|
-
* Invalidate a request by its
|
|
297
|
+
* Invalidate a request by its CacheKey for the given store instance.
|
|
298
298
|
*
|
|
299
299
|
* While the store argument may seem redundant, the CachePolicy
|
|
300
300
|
* is designed to be shared across multiple stores / forks
|
|
301
301
|
* of the store.
|
|
302
302
|
*
|
|
303
303
|
* ```ts
|
|
304
|
-
* store.lifetimes.invalidateRequest(store,
|
|
304
|
+
* store.lifetimes.invalidateRequest(store, cacheKey);
|
|
305
305
|
* ```
|
|
306
306
|
*
|
|
307
307
|
* @public
|
|
308
|
-
* @param {StableDocumentIdentifier} identifier
|
|
309
|
-
* @param {Store} store
|
|
310
308
|
*/
|
|
311
|
-
invalidateRequest(
|
|
309
|
+
invalidateRequest(cacheKey: RequestKey, store: Store): void;
|
|
312
310
|
/**
|
|
313
311
|
* Invalidate all requests associated to a specific type
|
|
314
312
|
* for a given store instance.
|
|
@@ -325,8 +323,6 @@ export declare class DefaultCachePolicy {
|
|
|
325
323
|
* ```
|
|
326
324
|
*
|
|
327
325
|
* @public
|
|
328
|
-
* @param {String} type
|
|
329
|
-
* @param {Store} store
|
|
330
326
|
*/
|
|
331
327
|
invalidateRequestsForType(type: string, store: Store): void;
|
|
332
328
|
/**
|
|
@@ -340,13 +336,8 @@ export declare class DefaultCachePolicy {
|
|
|
340
336
|
* This method should not be invoked directly by consumers.
|
|
341
337
|
*
|
|
342
338
|
* @public
|
|
343
|
-
* @param {ImmutableRequestInfo} request
|
|
344
|
-
* @param {ImmutableResponse} response
|
|
345
|
-
* @param {Store} store
|
|
346
|
-
* @param {StableDocumentIdentifier | null} identifier
|
|
347
|
-
* @return {void}
|
|
348
339
|
*/
|
|
349
|
-
didRequest(request: ImmutableRequestInfo, response: Response | ResponseInfo | null,
|
|
340
|
+
didRequest(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, cacheKey: RequestKey | null, store: Store): void;
|
|
350
341
|
/**
|
|
351
342
|
* Invoked to determine if the request may be fulfilled from cache
|
|
352
343
|
* if possible.
|
|
@@ -359,11 +350,9 @@ export declare class DefaultCachePolicy {
|
|
|
359
350
|
* and the cache will be updated before returning the response.
|
|
360
351
|
*
|
|
361
352
|
* @public
|
|
362
|
-
* @
|
|
363
|
-
* @param {Store} store
|
|
364
|
-
* @return {Boolean} true if the request is considered hard expired
|
|
353
|
+
* @return true if the request is considered hard expired
|
|
365
354
|
*/
|
|
366
|
-
isHardExpired(
|
|
355
|
+
isHardExpired(cacheKey: RequestKey, store: Store): boolean;
|
|
367
356
|
/**
|
|
368
357
|
* Invoked if `isHardExpired` is false to determine if the request
|
|
369
358
|
* should be update behind the scenes if cache data is already available.
|
|
@@ -375,10 +364,8 @@ export declare class DefaultCachePolicy {
|
|
|
375
364
|
* request is made to update the cache via the configured request handlers.
|
|
376
365
|
*
|
|
377
366
|
* @public
|
|
378
|
-
* @
|
|
379
|
-
* @param {Store} store
|
|
380
|
-
* @return {Boolean} true if the request is considered soft expired
|
|
367
|
+
* @return true if the request is considered soft expired
|
|
381
368
|
*/
|
|
382
|
-
isSoftExpired(
|
|
369
|
+
isSoftExpired(cacheKey: RequestKey, store: Store): boolean;
|
|
383
370
|
}
|
|
384
371
|
export {};
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { CacheCapabilitiesManager as StoreWrapper } from "../../-types/q/cache-capabilities-manager.js";
|
|
3
3
|
import type { SchemaService } from "../../-types/q/schema-service.js";
|
|
4
|
-
import type { IdentifierCache } from "../caches/identifier-cache.js";
|
|
5
4
|
import type { Store } from "../store-service.js";
|
|
5
|
+
import type { CacheKeyManager } from "./cache-key-manager.js";
|
|
6
6
|
import type { NotificationType } from "./notification-manager.js";
|
|
7
7
|
export interface CacheCapabilitiesManager {
|
|
8
8
|
getSchemaDefinitionService(): SchemaService;
|
|
9
9
|
}
|
|
10
10
|
export declare class CacheCapabilitiesManager implements StoreWrapper {
|
|
11
11
|
_willNotify: boolean;
|
|
12
|
-
_pendingNotifies: Map<
|
|
12
|
+
_pendingNotifies: Map<ResourceKey, Set<string>>;
|
|
13
13
|
_store: Store;
|
|
14
14
|
constructor(_store: Store);
|
|
15
|
-
get
|
|
16
|
-
|
|
15
|
+
get cacheKeyManager(): CacheKeyManager;
|
|
16
|
+
/** @deprecated use {@link CacheCapabilitiesManager.cacheKeyManager} */
|
|
17
|
+
get identifierCache(): CacheKeyManager;
|
|
18
|
+
_scheduleNotification(identifier: ResourceKey, key: string): void;
|
|
17
19
|
_flushNotifications(): void;
|
|
18
|
-
notifyChange(identifier:
|
|
19
|
-
notifyChange(identifier:
|
|
20
|
-
notifyChange(identifier:
|
|
20
|
+
notifyChange(identifier: ResourceKey, namespace: "added" | "removed", key: null): void;
|
|
21
|
+
notifyChange(identifier: RequestKey, namespace: "added" | "updated" | "removed", key: null): void;
|
|
22
|
+
notifyChange(identifier: ResourceKey, namespace: NotificationType, key: string | null): void;
|
|
21
23
|
get schema(): SchemaService;
|
|
22
|
-
setRecordId(identifier:
|
|
23
|
-
hasRecord(identifier:
|
|
24
|
-
disconnectRecord(identifier:
|
|
24
|
+
setRecordId(identifier: ResourceKey, id: string): void;
|
|
25
|
+
hasRecord(identifier: ResourceKey): boolean;
|
|
26
|
+
disconnectRecord(identifier: ResourceKey): void;
|
|
25
27
|
}
|
package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PersistedResourceKey, type RequestKey, type ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { ImmutableRequestInfo } from "../../../types/request.js";
|
|
3
3
|
import type { ExistingResourceIdentifierObject, ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
|
|
4
4
|
import type { ForgetMethod, GenerationMethod, KeyInfo, KeyInfoMethod, ResetMethod, UpdateMethod } from "../../-types/q/identifier.js";
|
|
5
5
|
type TypeFromIdentifier<T> = T extends {
|
|
6
6
|
type: infer U;
|
|
7
7
|
} ? U : string;
|
|
8
|
-
type NarrowIdentifierIfPossible<T> = T extends ExistingResourceIdentifierObject ?
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
8
|
+
type NarrowIdentifierIfPossible<T> = T extends ExistingResourceIdentifierObject ? PersistedResourceKey<TypeFromIdentifier<T>> : ResourceKey;
|
|
9
|
+
export declare function isResourceKey(identifier: unknown): identifier is ResourceKey;
|
|
10
|
+
export declare function isRequestKey(identifier: unknown): identifier is RequestKey;
|
|
11
11
|
interface KeyOptions {
|
|
12
12
|
lid: IdentifierMap;
|
|
13
13
|
id: IdentifierMap;
|
|
@@ -15,16 +15,16 @@ interface KeyOptions {
|
|
|
15
15
|
type TypeMap = {
|
|
16
16
|
[key: string]: KeyOptions;
|
|
17
17
|
};
|
|
18
|
-
// type IdentifierTypeLookup = { all: Set<
|
|
18
|
+
// type IdentifierTypeLookup = { all: Set<ResourceKey>; id: Map<string, ResourceKey> };
|
|
19
19
|
// type IdentifiersByType = Map<string, IdentifierTypeLookup>;
|
|
20
|
-
type IdentifierMap = Map<string,
|
|
20
|
+
type IdentifierMap = Map<string, ResourceKey>;
|
|
21
21
|
type StableCache = {
|
|
22
22
|
resources: IdentifierMap;
|
|
23
|
-
documents: Map<string,
|
|
23
|
+
documents: Map<string, RequestKey>;
|
|
24
24
|
resourcesByType: TypeMap;
|
|
25
25
|
polymorphicLidBackMap: Map<string, string[]>;
|
|
26
26
|
};
|
|
27
|
-
export type MergeMethod = (targetIdentifier:
|
|
27
|
+
export type MergeMethod = (targetIdentifier: ResourceKey, matchedIdentifier: ResourceKey, resourceData: unknown) => ResourceKey;
|
|
28
28
|
/**
|
|
29
29
|
Configures how unique identifier lid strings are generated by @ember-data/store.
|
|
30
30
|
|
|
@@ -163,10 +163,10 @@ to the application instance, you may not need to implement the `resetMethod`.
|
|
|
163
163
|
export declare function setIdentifierResetMethod(method: ResetMethod | null): void;
|
|
164
164
|
/**
|
|
165
165
|
Configure a callback for when the identifier cache is generating a new
|
|
166
|
-
|
|
166
|
+
ResourceKey for a resource.
|
|
167
167
|
|
|
168
168
|
This method controls the `type` and `id` that will be assigned to the
|
|
169
|
-
`
|
|
169
|
+
`ResourceKey` that is created.
|
|
170
170
|
|
|
171
171
|
This configuration MUST occur prior to the store instance being created.
|
|
172
172
|
|
|
@@ -178,7 +178,7 @@ import { setKeyInfoForResource } from '@warp-drive/core';
|
|
|
178
178
|
*/
|
|
179
179
|
export declare function setKeyInfoForResource(method: KeyInfoMethod | null): void;
|
|
180
180
|
/**
|
|
181
|
-
* Each instance of {@link Store} receives a unique instance of a
|
|
181
|
+
* Each instance of {@link Store} receives a unique instance of a CacheKeyManager.
|
|
182
182
|
*
|
|
183
183
|
* This cache is responsible for assigning or retrieving the unique identify
|
|
184
184
|
* for arbitrary resource data encountered by the store. Data representing
|
|
@@ -190,7 +190,7 @@ export declare function setKeyInfoForResource(method: KeyInfoMethod | null): voi
|
|
|
190
190
|
* @hideconstructor
|
|
191
191
|
* @public
|
|
192
192
|
*/
|
|
193
|
-
export declare class
|
|
193
|
+
export declare class CacheKeyManager {
|
|
194
194
|
/** @internal */
|
|
195
195
|
_cache: StableCache;
|
|
196
196
|
private _generate;
|
|
@@ -215,7 +215,7 @@ export declare class IdentifierCache {
|
|
|
215
215
|
type: string;
|
|
216
216
|
id: string | null;
|
|
217
217
|
lid?: string;
|
|
218
|
-
}):
|
|
218
|
+
}): ResourceKey;
|
|
219
219
|
/**
|
|
220
220
|
* @private
|
|
221
221
|
*/
|
|
@@ -229,14 +229,14 @@ export declare class IdentifierCache {
|
|
|
229
229
|
*
|
|
230
230
|
* @private
|
|
231
231
|
*/
|
|
232
|
-
peekRecordIdentifier(resource: ResourceIdentifierObject
|
|
232
|
+
peekRecordIdentifier(resource: ResourceIdentifierObject): ResourceKey | undefined;
|
|
233
233
|
/**
|
|
234
234
|
Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
|
|
235
235
|
Returns `null` if the request does not have a `cacheKey` or `url`.
|
|
236
236
|
|
|
237
237
|
@public
|
|
238
238
|
*/
|
|
239
|
-
getOrCreateDocumentIdentifier(request: ImmutableRequestInfo):
|
|
239
|
+
getOrCreateDocumentIdentifier(request: ImmutableRequestInfo): RequestKey | null;
|
|
240
240
|
/**
|
|
241
241
|
Returns the Identifier for the given Resource, creates one if it does not yet exist.
|
|
242
242
|
|
|
@@ -263,7 +263,8 @@ export declare class IdentifierCache {
|
|
|
263
263
|
createIdentifierForNewRecord(data: {
|
|
264
264
|
type: string;
|
|
265
265
|
id?: string | null;
|
|
266
|
-
|
|
266
|
+
lid?: string;
|
|
267
|
+
}): ResourceKey;
|
|
267
268
|
/**
|
|
268
269
|
Provides the opportunity to update secondary lookup tables for existing identifiers
|
|
269
270
|
Called after an identifier created with `createIdentifierForNewRecord` has been
|
|
@@ -282,11 +283,12 @@ export declare class IdentifierCache {
|
|
|
282
283
|
|
|
283
284
|
@public
|
|
284
285
|
*/
|
|
285
|
-
|
|
286
|
+
// FIXME audit usage
|
|
287
|
+
updateRecordIdentifier(identifierObject: ResourceKey, data: unknown): ResourceKey;
|
|
286
288
|
/**
|
|
287
289
|
* @private
|
|
288
290
|
*/
|
|
289
|
-
_mergeRecordIdentifiers(keyInfo: KeyInfo, identifier:
|
|
291
|
+
_mergeRecordIdentifiers(keyInfo: KeyInfo, identifier: ResourceKey, existingIdentifier: ResourceKey, data: unknown): ResourceKey;
|
|
290
292
|
/**
|
|
291
293
|
Provides the opportunity to eliminate an identifier from secondary lookup tables
|
|
292
294
|
as well as eliminates it from ember-data's own lookup tables and book keeping.
|
|
@@ -297,7 +299,8 @@ export declare class IdentifierCache {
|
|
|
297
299
|
|
|
298
300
|
@public
|
|
299
301
|
*/
|
|
300
|
-
|
|
302
|
+
// FIXME audit usage
|
|
303
|
+
forgetRecordIdentifier(identifierObject: ResourceKey): void;
|
|
301
304
|
/** @internal */
|
|
302
305
|
destroy(): void;
|
|
303
306
|
}
|