@warp-drive/core 5.7.0-alpha.13 → 5.7.0-alpha.15
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 +15 -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 +2 -2
- package/declarations/reactive/-private/document.d.ts +6 -16
- package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
- 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/record.d.ts +44 -5
- package/declarations/reactive/-private/schema.d.ts +12 -12
- package/declarations/reactive/-private/symbols.d.ts +1 -1
- package/declarations/reactive.d.ts +277 -1
- package/declarations/request/-private/context.d.ts +2 -2
- package/declarations/request/-private/fetch.d.ts +2 -2
- package/declarations/request/-private/manager.d.ts +2 -2
- package/declarations/request/-private/types.d.ts +4 -4
- package/declarations/request/-private/utils.d.ts +44 -2
- 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 +18 -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} +21 -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 +1 -1
- 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 +22 -19
- package/declarations/store/-private.d.ts +5 -3
- 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 +9 -9
- package/declarations/store/deprecated/-private.d.ts +5 -5
- package/declarations/store/deprecated/store.d.ts +8 -9
- 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/request.d.ts +27 -6
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +1 -1
- package/declarations/types/spec/document.d.ts +6 -6
- package/dist/{context-COmAnXUQ.js → context-kQXhkeBj.js} +13 -0
- package/dist/graph/-private.js +129 -129
- package/dist/index.js +6 -2
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +126 -4
- package/dist/{request-state-BWYju5O9.js → request-state-CQ0Q6d1V.js} +4290 -4218
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/store.js +32 -44
- package/dist/{symbols-BoONANuz.js → symbols-sql1_mdx.js} +2 -2
- 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 +2 -0
- package/package.json +3 -3
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestKey, ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { Store } from "../store-service.js";
|
|
3
3
|
export type UnsubscribeToken = object;
|
|
4
4
|
export type CacheOperation = "added" | "removed" | "updated" | "state";
|
|
5
5
|
export type DocumentCacheOperation = "invalidated" | "added" | "removed" | "updated" | "state";
|
|
6
6
|
export type NotificationType = "attributes" | "relationships" | "identity" | "errors" | "meta" | CacheOperation;
|
|
7
7
|
export interface NotificationCallback {
|
|
8
|
-
(
|
|
9
|
-
(
|
|
10
|
-
(
|
|
8
|
+
(cacheKey: ResourceKey, notificationType: "attributes" | "relationships", key?: string): void;
|
|
9
|
+
(cacheKey: ResourceKey, notificationType: "errors" | "meta" | "identity" | "state"): void;
|
|
10
|
+
(cacheKey: ResourceKey, notificationType: CacheOperation): void;
|
|
11
11
|
}
|
|
12
12
|
export interface ResourceOperationCallback {
|
|
13
13
|
// resource updates
|
|
14
|
-
(
|
|
14
|
+
(cacheKey: ResourceKey, notificationType: CacheOperation): void;
|
|
15
15
|
}
|
|
16
16
|
export interface DocumentOperationCallback {
|
|
17
17
|
// document updates
|
|
18
|
-
(
|
|
18
|
+
(cacheKey: RequestKey, notificationType: DocumentCacheOperation): void;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* The NotificationManager provides the ability to subscribe to
|
|
@@ -42,34 +42,33 @@ export default class NotificationManager {
|
|
|
42
42
|
private _onFlushCB?;
|
|
43
43
|
constructor(store: Store);
|
|
44
44
|
/**
|
|
45
|
-
* Subscribe to changes for a given
|
|
45
|
+
* Subscribe to changes for a given ResourceKey, RequestKey, or addition/removal of any resource
|
|
46
|
+
* or document.
|
|
46
47
|
*
|
|
47
48
|
* ```ts
|
|
48
49
|
* export type CacheOperation = 'added' | 'removed' | 'updated' | 'state';
|
|
49
50
|
*
|
|
50
51
|
* export interface NotificationCallback {
|
|
51
|
-
* (
|
|
52
|
-
* (
|
|
53
|
-
* (
|
|
52
|
+
* (cacheKey: ResourceKey, notificationType: 'attributes' | 'relationships', key?: string): void;
|
|
53
|
+
* (cacheKey: ResourceKey, notificationType: 'errors' | 'meta' | 'identity' | 'state'): void;
|
|
54
|
+
* (cacheKey: ResourceKey, notificationType: NotificationType, key?: string): void;
|
|
54
55
|
* }
|
|
55
56
|
* export interface ResourceOperationCallback {
|
|
56
57
|
* // resource updates
|
|
57
|
-
* (
|
|
58
|
+
* (cacheKey: ResourceKey, notificationType: CacheOperation): void;
|
|
58
59
|
* }
|
|
59
60
|
* export interface DocumentOperationCallback {
|
|
60
61
|
* // document updates
|
|
61
|
-
* (
|
|
62
|
+
* (cacheKey: RequestKey, notificationType: CacheOperation): void;
|
|
62
63
|
* }
|
|
63
64
|
* ```
|
|
64
65
|
*
|
|
65
66
|
* @public
|
|
66
|
-
* @
|
|
67
|
-
* @param {NotificationCallback | ResourceOperationCallback | DocumentOperationCallback} callback
|
|
68
|
-
* @return {UnsubscribeToken} an opaque token to be used with unsubscribe
|
|
67
|
+
* @return an opaque token to be used with unsubscribe
|
|
69
68
|
*/
|
|
70
|
-
subscribe(
|
|
71
|
-
subscribe(
|
|
72
|
-
subscribe(
|
|
69
|
+
subscribe(cacheKey: ResourceKey, callback: NotificationCallback): UnsubscribeToken;
|
|
70
|
+
subscribe(cacheKey: "resource", callback: ResourceOperationCallback): UnsubscribeToken;
|
|
71
|
+
subscribe(cacheKey: "document" | RequestKey, callback: DocumentOperationCallback): UnsubscribeToken;
|
|
73
72
|
/**
|
|
74
73
|
* remove a previous subscription
|
|
75
74
|
*
|
|
@@ -81,18 +80,15 @@ export default class NotificationManager {
|
|
|
81
80
|
*
|
|
82
81
|
* @private
|
|
83
82
|
*/
|
|
84
|
-
notify(
|
|
85
|
-
notify(
|
|
86
|
-
notify(
|
|
87
|
-
notify(
|
|
83
|
+
notify(cacheKey: ResourceKey, value: "attributes" | "relationships", key?: string | null): boolean;
|
|
84
|
+
notify(cacheKey: ResourceKey, value: "errors" | "meta" | "identity" | "state", key?: null): boolean;
|
|
85
|
+
notify(cacheKey: ResourceKey, value: CacheOperation, key?: null): boolean;
|
|
86
|
+
notify(cacheKey: RequestKey, value: DocumentCacheOperation, key?: null): boolean;
|
|
88
87
|
/** @internal */
|
|
89
88
|
_onNextFlush(cb: () => void): void;
|
|
90
89
|
private _scheduleNotify;
|
|
91
90
|
/** @internal */
|
|
92
91
|
_flush(): void;
|
|
93
|
-
private _flushNotification;
|
|
94
|
-
private _flushNotification;
|
|
95
|
-
private _flushNotification;
|
|
96
92
|
/** @internal */
|
|
97
93
|
destroy(): void;
|
|
98
94
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { LocalRelationshipOperation } from "../../../types/graph.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ResourceKey, RequestKey } from "../../../types/identifier.js";
|
|
3
3
|
import type { ImmutableRequestInfo } from "../../../types/request.js";
|
|
4
4
|
import type { CollectionResourceDocument } from "../../../types/spec/json-api-raw.js";
|
|
5
|
-
import {
|
|
5
|
+
import type { LegacyLiveArray } from "../record-arrays/legacy-live-array.js";
|
|
6
|
+
import { type LegacyQueryArray } from "../record-arrays/legacy-query.js";
|
|
7
|
+
import { type ReactiveResourceArray } from "../record-arrays/resource-array.js";
|
|
6
8
|
import type { Store } from "../store-service.js";
|
|
7
9
|
import type { UnsubscribeToken } from "./notification-manager.js";
|
|
8
10
|
/**
|
|
@@ -38,13 +40,23 @@ import type { UnsubscribeToken } from "./notification-manager.js";
|
|
|
38
40
|
* Sincerely,
|
|
39
41
|
* - runspired (Chris Thoburn) 08/21/2022
|
|
40
42
|
*
|
|
41
|
-
* @function fastPush
|
|
42
43
|
* @internal
|
|
43
44
|
* @param target the array to push into
|
|
44
45
|
* @param source the items to push into target
|
|
45
46
|
*/
|
|
46
47
|
export declare function fastPush<T>(target: T[], source: T[]): void;
|
|
47
|
-
|
|
48
|
+
interface LegacyQueryInit {
|
|
49
|
+
type: string;
|
|
50
|
+
query: ImmutableRequestInfo | Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
interface AnonymousRequestCollectionInit {
|
|
53
|
+
source: ResourceKey[];
|
|
54
|
+
}
|
|
55
|
+
interface RequestCollectionInit {
|
|
56
|
+
source: ResourceKey[];
|
|
57
|
+
requestKey: RequestKey;
|
|
58
|
+
}
|
|
59
|
+
type ChangeSet = Map<ResourceKey, "add" | "del">;
|
|
48
60
|
/**
|
|
49
61
|
@class RecordArrayManager
|
|
50
62
|
@internal
|
|
@@ -53,20 +65,61 @@ export declare class RecordArrayManager {
|
|
|
53
65
|
store: Store;
|
|
54
66
|
isDestroying: boolean;
|
|
55
67
|
isDestroyed: boolean;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
_set: Map<ReactiveResourceArray, Set<ResourceKey>>;
|
|
72
|
+
/**
|
|
73
|
+
* LiveArray (peekAll/findAll) array instances
|
|
74
|
+
* keyed by their ResourceType.
|
|
75
|
+
*/
|
|
76
|
+
_live: Map<string, LegacyLiveArray>;
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
_managed: Set<ReactiveResourceArray>;
|
|
81
|
+
/**
|
|
82
|
+
* Buffered changes to apply keyed by the array to
|
|
83
|
+
* which to apply them to.
|
|
84
|
+
*/
|
|
85
|
+
_pending: Map<ReactiveResourceArray, ChangeSet>;
|
|
86
|
+
/**
|
|
87
|
+
* An inverse map from ResourceKey to the list
|
|
88
|
+
* of arrays it can be found in, useful for fast updates
|
|
89
|
+
* when state changes to a resource occur.
|
|
90
|
+
*/
|
|
91
|
+
_identifiers: Map<ResourceKey, Set<ReactiveResourceArray>>;
|
|
92
|
+
/**
|
|
93
|
+
* When we do not yet have a LiveArray, this keeps track of
|
|
94
|
+
* the added/removed identifiers to enable us to more efficiently
|
|
95
|
+
* produce the LiveArray later.
|
|
96
|
+
*
|
|
97
|
+
* It's possible that using a Set and only storing additions instead of
|
|
98
|
+
* additions and deletes would be more efficient.
|
|
99
|
+
*/
|
|
61
100
|
_staged: Map<string, ChangeSet>;
|
|
62
101
|
_subscription: UnsubscribeToken;
|
|
63
102
|
_documentSubscription: UnsubscribeToken;
|
|
64
|
-
|
|
65
|
-
|
|
103
|
+
/**
|
|
104
|
+
* KeyedArrays are arrays associated to a specific RequestKey.
|
|
105
|
+
*/
|
|
106
|
+
_keyedArrays: Map<string, ReactiveResourceArray>;
|
|
107
|
+
/**
|
|
108
|
+
* The visibility set tracks whether a given identifier should
|
|
109
|
+
* be shown in RecordArrays. It is used to dedupe added/removed
|
|
110
|
+
* and state change events.
|
|
111
|
+
*
|
|
112
|
+
* As a Map, it grows to be very large - there may be ways to
|
|
113
|
+
* reduce its size by instead migrating to it functioning as
|
|
114
|
+
* an exclusion list. Any entry not in the list would be considered
|
|
115
|
+
* visible.
|
|
116
|
+
*/
|
|
117
|
+
_visibilitySet: Map<ResourceKey, boolean>;
|
|
66
118
|
constructor(options: {
|
|
67
119
|
store: Store;
|
|
68
120
|
});
|
|
69
|
-
|
|
121
|
+
private _subscribeToResourceChanges;
|
|
122
|
+
_syncArray(array: ReactiveResourceArray): void;
|
|
70
123
|
mutate(mutation: LocalRelationshipOperation): void;
|
|
71
124
|
/**
|
|
72
125
|
Get the `RecordArray` for a modelName, which contains all loaded records of
|
|
@@ -76,22 +129,20 @@ export declare class RecordArrayManager {
|
|
|
76
129
|
@param {String} modelName
|
|
77
130
|
@return {RecordArray}
|
|
78
131
|
*/
|
|
79
|
-
liveArrayFor(type: string):
|
|
80
|
-
getCollection(config:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
identifierRemoved(identifier: StableRecordIdentifier): void;
|
|
92
|
-
identifierChanged(identifier: StableRecordIdentifier): void;
|
|
132
|
+
liveArrayFor(type: string): LegacyLiveArray;
|
|
133
|
+
getCollection(config: LegacyQueryInit): LegacyQueryArray;
|
|
134
|
+
getCollection(config: AnonymousRequestCollectionInit): ReactiveResourceArray;
|
|
135
|
+
getCollection(config: RequestCollectionInit): ReactiveResourceArray;
|
|
136
|
+
dirtyArray(array: ReactiveResourceArray, delta: number, shouldSyncFromCache: boolean): void;
|
|
137
|
+
_getPendingFor(identifier: ResourceKey, includeManaged: boolean, isRemove?: boolean): Map<ReactiveResourceArray, ChangeSet> | void;
|
|
138
|
+
populateManagedArray(array: ReactiveResourceArray, identifiers: ResourceKey[], payload: CollectionResourceDocument | null): void;
|
|
139
|
+
identifierAdded(identifier: ResourceKey): void;
|
|
140
|
+
identifierRemoved(identifier: ResourceKey): void;
|
|
141
|
+
identifierChanged(identifier: ResourceKey): void;
|
|
142
|
+
pause(): void;
|
|
143
|
+
resume(): void;
|
|
93
144
|
clear(isClear?: boolean): void;
|
|
94
145
|
destroy(): void;
|
|
95
146
|
}
|
|
96
|
-
export declare function disassociateIdentifier(ArraysCache: Map<
|
|
147
|
+
export declare function disassociateIdentifier(ArraysCache: Map<ResourceKey, Set<ReactiveResourceArray>>, array: ReactiveResourceArray, identifier: ResourceKey): void;
|
|
97
148
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResourceKey } from "../../../types/identifier.js";
|
|
2
2
|
import type { FindRecordOptions } from "../../-types/q/store.js";
|
|
3
3
|
import type { Store } from "../store-service.js";
|
|
4
4
|
declare const Touching: "___(unique) Symbol(Touching)";
|
|
@@ -6,7 +6,7 @@ export declare const RequestPromise: "___(unique) Symbol(RequestPromise)";
|
|
|
6
6
|
export interface Operation {
|
|
7
7
|
op: string;
|
|
8
8
|
options: FindRecordOptions | undefined;
|
|
9
|
-
recordIdentifier:
|
|
9
|
+
recordIdentifier: ResourceKey;
|
|
10
10
|
}
|
|
11
11
|
export interface FindRecordQuery extends Operation {
|
|
12
12
|
op: "findRecord";
|
|
@@ -30,7 +30,7 @@ export interface Response {
|
|
|
30
30
|
data: unknown;
|
|
31
31
|
}
|
|
32
32
|
interface InternalRequest extends RequestCacheRequestState {
|
|
33
|
-
[Touching]:
|
|
33
|
+
[Touching]: ResourceKey[];
|
|
34
34
|
[RequestPromise]?: Promise<unknown>;
|
|
35
35
|
}
|
|
36
36
|
export type RequestSubscription = (requestState: RequestCacheRequestState) => void;
|
|
@@ -43,14 +43,14 @@ export type RequestSubscription = (requestState: RequestCacheRequestState) => vo
|
|
|
43
43
|
*/
|
|
44
44
|
export declare class RequestStateService {
|
|
45
45
|
/** @internal */
|
|
46
|
-
_pending: Map<
|
|
46
|
+
_pending: Map<ResourceKey, InternalRequest[]>;
|
|
47
47
|
private _done;
|
|
48
48
|
private _subscriptions;
|
|
49
49
|
private _toFlush;
|
|
50
50
|
private _store;
|
|
51
51
|
constructor(store: Store);
|
|
52
52
|
/** @internal */
|
|
53
|
-
_clearEntries(identifier:
|
|
53
|
+
_clearEntries(identifier: ResourceKey): void;
|
|
54
54
|
/** @internal */
|
|
55
55
|
_enqueue<T>(promise: Promise<T>, queryRequest: Request): Promise<T>;
|
|
56
56
|
private _triggerSubscriptions;
|
|
@@ -83,25 +83,25 @@ export declare class RequestStateService {
|
|
|
83
83
|
* design.
|
|
84
84
|
*
|
|
85
85
|
* @public
|
|
86
|
-
* @param {
|
|
86
|
+
* @param {ResourceKey} identifier
|
|
87
87
|
* @param {(state: RequestCacheRequestState) => void} callback
|
|
88
88
|
*/
|
|
89
|
-
subscribeForRecord(identifier:
|
|
89
|
+
subscribeForRecord(identifier: ResourceKey, callback: RequestSubscription): void;
|
|
90
90
|
/**
|
|
91
91
|
* Retrieve all active requests for a given resource identity.
|
|
92
92
|
*
|
|
93
93
|
* @public
|
|
94
|
-
* @param {
|
|
94
|
+
* @param {ResourceKey} identifier
|
|
95
95
|
* @return {RequestCacheRequestState[]} an array of request states for any pending requests for the given identifier
|
|
96
96
|
*/
|
|
97
|
-
getPendingRequestsForRecord(identifier:
|
|
97
|
+
getPendingRequestsForRecord(identifier: ResourceKey): RequestCacheRequestState[];
|
|
98
98
|
/**
|
|
99
99
|
* Retrieve the last completed request for a given resource identity.
|
|
100
100
|
*
|
|
101
101
|
* @public
|
|
102
|
-
* @param {
|
|
102
|
+
* @param {ResourceKey} identifier
|
|
103
103
|
* @return {RequestCacheRequestState | null} the state of the most recent request for the given identifier
|
|
104
104
|
*/
|
|
105
|
-
getLastRequestForRecord(identifier:
|
|
105
|
+
getLastRequestForRecord(identifier: ResourceKey): RequestCacheRequestState | null;
|
|
106
106
|
}
|
|
107
107
|
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RequestKey } from "../../../types/identifier.js";
|
|
2
|
+
import type { Store } from "../store-service.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates an {@link ExpensiveSubscription} for the {@link RequestKey}
|
|
5
|
+
* if one does not already exist and adds a watcher to it.
|
|
6
|
+
*
|
|
7
|
+
* Returns a cleanup function. This should be called on-mount by a component
|
|
8
|
+
* that wants to subscribe to a request and cleanup should be called on dismount.
|
|
9
|
+
*
|
|
10
|
+
* ::: warning ⚠️ Avoid Using If Your App Supports Fine-grained Reactivity
|
|
11
|
+
* This mechanism should never be used by frameworks or libraries
|
|
12
|
+
* that support fine-grained reactivity.
|
|
13
|
+
* :::
|
|
14
|
+
*
|
|
15
|
+
* `ExpensiveSubscription` is a mechanism for non-reactive
|
|
16
|
+
* frameworks such as `react` to integrate with WarpDrive, for instance
|
|
17
|
+
* by treating a request as an [external store](https://react.dev/reference/react/useSyncExternalStore)
|
|
18
|
+
*
|
|
19
|
+
* `ExpensiveSubscription` is expensive *because* it doubles the number
|
|
20
|
+
* of notification callbacks required for each resource contained in
|
|
21
|
+
* the request being subscribed to. The more requests in-use, the more
|
|
22
|
+
* this cost adds up.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getExpensiveRequestSubscription(store: Store, requestKey: RequestKey, callback: () => void): () => void;
|
|
@@ -7,6 +7,7 @@ import type { SignalStore, WarpDriveSignal } from "./internal.js";
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export declare function entangleSignal<T extends object>(signals: SignalStore, obj: T, key: string | symbol, initialValue: unknown): WarpDriveSignal;
|
|
10
|
+
export declare function createSignalDescriptor(key: string | symbol, intialValue: unknown): PropertyDescriptor;
|
|
10
11
|
/**
|
|
11
12
|
* define an enumerable signal property.
|
|
12
13
|
*
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { BaseFinderOptions } from "../../../types.js";
|
|
2
|
+
import type { LocalRelationshipOperation } from "../../../types/graph.js";
|
|
3
|
+
import type { ResourceKey } from "../../../types/identifier.js";
|
|
4
|
+
import type { Store } from "../store-service.js";
|
|
5
|
+
import type { NativeProxy } from "./native-proxy-type-fix.js";
|
|
6
|
+
import type { ReactiveResourceArray } from "./resource-array.js";
|
|
7
|
+
/**
|
|
8
|
+
* LegacyArrays have the capability of updating via `array.update()`
|
|
9
|
+
* and saving each contained record individually via `array.save()`
|
|
10
|
+
*/
|
|
11
|
+
export interface LegacyArray<T = unknown> extends ReactiveResourceArray<T> {
|
|
12
|
+
/**
|
|
13
|
+
The flag to signal a `RecordArray` is currently loading data.
|
|
14
|
+
Example
|
|
15
|
+
```javascript
|
|
16
|
+
let people = store.peekAll('person');
|
|
17
|
+
people.isUpdating; // false
|
|
18
|
+
people.update();
|
|
19
|
+
people.isUpdating; // true
|
|
20
|
+
```
|
|
21
|
+
*/
|
|
22
|
+
isUpdating: boolean;
|
|
23
|
+
/** @internal */
|
|
24
|
+
_updatingPromise: Promise<LegacyArray<T>> | null;
|
|
25
|
+
/**
|
|
26
|
+
Used to get the latest version of all of the records in this array
|
|
27
|
+
from the adapter.
|
|
28
|
+
|
|
29
|
+
Example
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
let people = store.peekAll('person');
|
|
33
|
+
people.isUpdating; // false
|
|
34
|
+
|
|
35
|
+
people.update().then(function() {
|
|
36
|
+
people.isUpdating; // false
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
people.isUpdating; // true
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@public
|
|
43
|
+
*/
|
|
44
|
+
update(this: LegacyArray<T>): Promise<LegacyArray<T>>;
|
|
45
|
+
/**
|
|
46
|
+
Saves all of the records in the `RecordArray`.
|
|
47
|
+
|
|
48
|
+
Example
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
let messages = store.peekAll('message');
|
|
52
|
+
messages.forEach(function(message) {
|
|
53
|
+
message.hasBeenSeen = true;
|
|
54
|
+
});
|
|
55
|
+
messages.save();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
@public
|
|
59
|
+
*/
|
|
60
|
+
save(this: LegacyArray<T>): Promise<LegacyArray<T>>;
|
|
61
|
+
}
|
|
62
|
+
export declare function upgradeThis(obj: unknown): asserts obj is LegacyArray;
|
|
63
|
+
export declare function update(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
|
|
64
|
+
export declare function save(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
|
|
65
|
+
export type KeyType = string | symbol | number;
|
|
66
|
+
export declare function isArrayGetter<T>(prop: KeyType): prop is keyof Array<T>;
|
|
67
|
+
export declare function isArraySetter<T>(prop: KeyType): prop is keyof Array<T>;
|
|
68
|
+
export declare function convertToInt(prop: KeyType): number | null;
|
|
69
|
+
export type ForEachCB<T> = (record: T, index: number, context: typeof NativeProxy<ResourceKey[], T[]>) => void;
|
|
70
|
+
export declare function safeForEach<T>(instance: typeof NativeProxy<ResourceKey[], T[]>, arr: ResourceKey[], store: Store, callback: ForEachCB<T>, target: unknown): typeof NativeProxy<ResourceKey[], T[]>;
|
|
71
|
+
type PromiseTo<T> = Omit<Promise<T>, typeof Symbol.toStringTag>;
|
|
72
|
+
type PromiseManyArray<T> = {
|
|
73
|
+
length: number;
|
|
74
|
+
content: ReactiveResourceArray<T> | null;
|
|
75
|
+
promise: Promise<ReactiveResourceArray<T>> | null;
|
|
76
|
+
} & PromiseTo<ReactiveResourceArray<T>>;
|
|
77
|
+
export interface MinimumManager {
|
|
78
|
+
_syncArray(array: ReactiveResourceArray): void;
|
|
79
|
+
mutate?(mutation: LocalRelationshipOperation): void;
|
|
80
|
+
reloadHasMany?<T>(key: string, options?: BaseFinderOptions): Promise<ReactiveResourceArray> | PromiseManyArray<T>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ResourceKey } from "../../../types/identifier.js";
|
|
2
|
+
import type { TypeFromInstanceOrString } from "../../../types/record.js";
|
|
3
|
+
import type { Store } from "../store-service.js";
|
|
4
|
+
import type { LegacyArray, MinimumManager } from "./-utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* LiveArrays contain all the known records for a given `ResourceType`.
|
|
7
|
+
*
|
|
8
|
+
* ### Basic Example
|
|
9
|
+
*
|
|
10
|
+
* For instance, if an application were to have a `'user'` type:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const usersLiveArray = store.peekAll('user');
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* ---
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* ### LiveArrays are Arrays
|
|
21
|
+
*
|
|
22
|
+
* LiveArrays have all array APIs, and will report `true`
|
|
23
|
+
* for both `liveArray instanceof Array` and `Array.isArray(liveArray)`
|
|
24
|
+
*
|
|
25
|
+
* ---
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
*
|
|
29
|
+
* ### Reactive
|
|
30
|
+
*
|
|
31
|
+
* The array is "live" as it will reactively update any time new
|
|
32
|
+
* users are added to the store's cache.
|
|
33
|
+
*
|
|
34
|
+
* There is only one LiveArray instance per ResourceType, and it
|
|
35
|
+
* can be accessed either via {@link Store.peekAll} or {@link Store.findAll}
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* const users = await store.findAll('user');
|
|
39
|
+
* const peekedUsers = store.peekAll('user');
|
|
40
|
+
* peekedUsers === users; // true
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* ---
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
* ### New Records
|
|
48
|
+
*
|
|
49
|
+
* Records in the `"new"` state (created locally on the client
|
|
50
|
+
* but not yet saved) appear in LiveArrays if they are in LegacyMode.
|
|
51
|
+
*
|
|
52
|
+
* PolarisMode records in the `"new"` state do not appear in LiveArrays.
|
|
53
|
+
*
|
|
54
|
+
* ---
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
*
|
|
58
|
+
* ### Polymorphism
|
|
59
|
+
*
|
|
60
|
+
* LiveArrays are not polymorphic. If your application has an abstract
|
|
61
|
+
* type "car" with concrete types "ferrari" and "bmw", then "ferrari"
|
|
62
|
+
* and "bmw" will have populated LiveArrays, but the LiveArray for "car"
|
|
63
|
+
* would be empty.
|
|
64
|
+
*
|
|
65
|
+
* @legacy we recommend againt using LiveArrays. Use {@link Store.request} instead
|
|
66
|
+
*/
|
|
67
|
+
export interface LegacyLiveArray<T = unknown> extends LegacyArray<T> {
|
|
68
|
+
isLoaded: boolean;
|
|
69
|
+
/** @internal */
|
|
70
|
+
DEPRECATED_CLASS_NAME: string;
|
|
71
|
+
modelName: TypeFromInstanceOrString<T>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The options for {@link createLegacyLiveArray}
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
export interface LegacyLiveArrayCreateOptions {
|
|
79
|
+
store: Store;
|
|
80
|
+
manager: MinimumManager;
|
|
81
|
+
source: ResourceKey[];
|
|
82
|
+
type: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a {@link LegacyLiveArray}
|
|
86
|
+
*
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export declare function createLegacyLiveArray(options: LegacyLiveArrayCreateOptions): LegacyLiveArray;
|