@warp-drive-mirror/core 5.7.0-alpha.9 → 5.7.0
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 +7 -20
- package/declarations/graph/-private/-edge-definition.d.ts +3 -12
- package/declarations/graph/-private/-state.d.ts +0 -87
- package/declarations/graph/-private/-utils.d.ts +5 -11
- package/declarations/graph/-private/coerce-id.d.ts +0 -6
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
- 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 +6 -7
- package/declarations/graph/-private/graph.d.ts +17 -51
- package/declarations/graph/-private/normalize-link.d.ts +0 -6
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +2 -2
- package/declarations/reactive/-private/document.d.ts +11 -27
- package/declarations/reactive/-private/fields/managed-array.d.ts +4 -6
- package/declarations/reactive/-private/fields/managed-object.d.ts +2 -8
- 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 +42 -30
- package/declarations/reactive/-private/schema.d.ts +11 -73
- package/declarations/reactive/-private/symbols.d.ts +2 -33
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +277 -1
- package/declarations/request/-private/context.d.ts +3 -5
- package/declarations/request/-private/fetch.d.ts +2 -2
- package/declarations/request/-private/manager.d.ts +24 -28
- package/declarations/request/-private/types.d.ts +22 -24
- 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 -5
- package/declarations/store/-private/caches/instance-cache.d.ts +21 -20
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -40
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
- package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -25
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
- package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
- package/declarations/store/-private/record-arrays/{many-array.d.ts → legacy-many-array.d.ts} +40 -104
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
- package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
- package/declarations/store/-private/store-service.d.ts +156 -106
- package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
- package/declarations/store/-private.d.ts +11 -13
- 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/record-instance.d.ts +0 -1
- package/declarations/store/-types/q/schema-service.d.ts +9 -9
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -24
- package/declarations/store/deprecated/store.d.ts +11 -16
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +0 -11
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -37
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -7
- package/declarations/types/cache.d.ts +51 -125
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -78
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +66 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +30 -3
- package/declarations/types/spec/document.d.ts +6 -10
- package/declarations/types/spec/json-api-raw.d.ts +6 -9
- package/declarations/types.d.ts +0 -1
- package/declarations/utils/string.d.ts +2 -3
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
- package/dist/graph/-private.js +137 -144
- package/dist/index.js +25 -14
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +144 -1926
- package/dist/{request-state-CeN66aML.js → request-state-C955e0AL.js} +5968 -3033
- package/dist/request.js +1 -1
- package/dist/store/-private.js +2 -3
- 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 +45 -3
- package/dist/types/schema/fields.js +6 -0
- package/dist/utils/string.js +2 -2
- package/package.json +11 -11
- 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-SdXlte1w.js +0 -339
|
@@ -3,14 +3,22 @@ import type { Future } from "../../../request.js";
|
|
|
3
3
|
import type { StructuredErrorDocument } from "../../../types/request.js";
|
|
4
4
|
import type { RequestState } from "../../-private.js";
|
|
5
5
|
export declare const DISPOSE: "(symbol) dispose";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export type AutorefreshBehaviorType = "online" | "interval" | "invalid";
|
|
7
|
+
export type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
|
|
8
|
+
/**
|
|
9
|
+
* Utilities to assist in recovering from the error.
|
|
10
|
+
*/
|
|
11
|
+
export interface RecoveryFeatures {
|
|
8
12
|
isOnline: boolean;
|
|
13
|
+
isHidden: boolean;
|
|
9
14
|
retry: () => Promise<void>;
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
|
|
16
|
+
/** @deprecated use {@link RecoveryFeatures} */
|
|
17
|
+
export type ErrorFeatures = RecoveryFeatures;
|
|
18
|
+
/**
|
|
19
|
+
* Utilities for keeping the request fresh
|
|
20
|
+
*/
|
|
21
|
+
export interface ContentFeatures<RT> {
|
|
14
22
|
isOnline: boolean;
|
|
15
23
|
isHidden: boolean;
|
|
16
24
|
isRefreshing: boolean;
|
|
@@ -18,11 +26,24 @@ type ContentFeatures<RT> = {
|
|
|
18
26
|
reload: () => Promise<void>;
|
|
19
27
|
abort?: () => void;
|
|
20
28
|
latestRequest?: Future<RT>;
|
|
21
|
-
}
|
|
22
|
-
|
|
29
|
+
}
|
|
30
|
+
export interface RequestArgs<
|
|
31
|
+
RT,
|
|
32
|
+
E
|
|
33
|
+
> extends SubscriptionArgs<RT, E> {
|
|
34
|
+
subscription?: RequestSubscription<RT, E>;
|
|
35
|
+
/**
|
|
36
|
+
* The store instance to use for making requests. If contexts are available,
|
|
37
|
+
* the component will default to using the `store` on the context.
|
|
38
|
+
*
|
|
39
|
+
* This is required if the store is not available via context or should be
|
|
40
|
+
* different from the store provided via context.
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
store?: Store | RequestManager;
|
|
44
|
+
}
|
|
23
45
|
export interface SubscriptionArgs<
|
|
24
46
|
RT,
|
|
25
|
-
T,
|
|
26
47
|
E
|
|
27
48
|
> {
|
|
28
49
|
/**
|
|
@@ -30,14 +51,14 @@ export interface SubscriptionArgs<
|
|
|
30
51
|
* by either the `store.request` or `store.requestManager.request` methods.
|
|
31
52
|
*
|
|
32
53
|
*/
|
|
33
|
-
request?: Future<RT
|
|
54
|
+
request?: Future<RT> | undefined | null;
|
|
34
55
|
/**
|
|
35
56
|
* A query to use for the request. This should be an object that can be
|
|
36
57
|
* passed to `store.request`. Use this in place of `@request` if you would
|
|
37
58
|
* like the component to also initiate the request.
|
|
38
59
|
*
|
|
39
60
|
*/
|
|
40
|
-
query?: StoreRequestInput<RT
|
|
61
|
+
query?: StoreRequestInput<RT> | undefined | null;
|
|
41
62
|
/**
|
|
42
63
|
* The autorefresh behavior for the request. This can be a boolean, or any
|
|
43
64
|
* combination of the following values: `'online'`, `'interval'`, `'invalid'`.
|
|
@@ -77,10 +98,22 @@ export interface SubscriptionArgs<
|
|
|
77
98
|
*/
|
|
78
99
|
autorefreshBehavior?: "refresh" | "reload" | "policy";
|
|
79
100
|
}
|
|
80
|
-
|
|
101
|
+
export interface RequestComponentArgs<
|
|
102
|
+
RT,
|
|
103
|
+
E
|
|
104
|
+
> extends SubscriptionArgs<RT, E> {
|
|
105
|
+
/**
|
|
106
|
+
* The store instance to use for making requests. If contexts are available,
|
|
107
|
+
* the component will default to using the `store` on the context.
|
|
108
|
+
*
|
|
109
|
+
* This is required if the store is not available via context or should be
|
|
110
|
+
* different from the store provided via context.
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
store?: Store | RequestManager;
|
|
114
|
+
}
|
|
81
115
|
export interface RequestSubscription<
|
|
82
116
|
RT,
|
|
83
|
-
T,
|
|
84
117
|
E
|
|
85
118
|
> {
|
|
86
119
|
/**
|
|
@@ -96,7 +129,6 @@ export interface RequestSubscription<
|
|
|
96
129
|
*/
|
|
97
130
|
export declare class RequestSubscription<
|
|
98
131
|
RT,
|
|
99
|
-
T,
|
|
100
132
|
E
|
|
101
133
|
> {
|
|
102
134
|
/**
|
|
@@ -112,123 +144,13 @@ export declare class RequestSubscription<
|
|
|
112
144
|
*/
|
|
113
145
|
isRefreshing: boolean;
|
|
114
146
|
/**
|
|
115
|
-
* The
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* This will never be the original request passed as an arg to
|
|
119
|
-
* the component.
|
|
120
|
-
*
|
|
121
|
-
* @internal
|
|
122
|
-
*/
|
|
123
|
-
private _localRequest;
|
|
124
|
-
/**
|
|
125
|
-
* The most recent request that was made, typically due to either a
|
|
126
|
-
* reload or a refresh.
|
|
127
|
-
*
|
|
128
|
-
* This will never be the original request passed as an arg to
|
|
129
|
-
* the component.
|
|
130
|
-
*
|
|
131
|
-
* @internal
|
|
132
|
-
*/
|
|
133
|
-
private _latestRequest;
|
|
134
|
-
/**
|
|
135
|
-
* The time at which the network was reported as offline.
|
|
136
|
-
*
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
private _unavailableStart;
|
|
140
|
-
/** @internal */
|
|
141
|
-
private _intervalStart;
|
|
142
|
-
/** @internal */
|
|
143
|
-
private _nextInterval;
|
|
144
|
-
/** @internal */
|
|
145
|
-
private _invalidated;
|
|
146
|
-
/** @internal */
|
|
147
|
-
private _isUpdating;
|
|
148
|
-
/** @internal */
|
|
149
|
-
private isDestroyed;
|
|
150
|
-
/**
|
|
151
|
-
* The event listener for network status changes,
|
|
152
|
-
* cached to use the reference for removal.
|
|
153
|
-
*
|
|
154
|
-
* @internal
|
|
147
|
+
* The Store this subscription subscribes to or the RequestManager
|
|
148
|
+
* which issues this request.
|
|
155
149
|
*/
|
|
156
|
-
private _onlineChanged;
|
|
157
|
-
/**
|
|
158
|
-
* The event listener for visibility status changes,
|
|
159
|
-
* cached to use the reference for removal.
|
|
160
|
-
*
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
private _backgroundChanged;
|
|
164
|
-
/**
|
|
165
|
-
* The last request passed as an arg to the component,
|
|
166
|
-
* cached for comparison.
|
|
167
|
-
*
|
|
168
|
-
* @internal
|
|
169
|
-
*/
|
|
170
|
-
private _originalRequest;
|
|
171
|
-
/**
|
|
172
|
-
* The last query passed as an arg to the component,
|
|
173
|
-
* cached for comparison.
|
|
174
|
-
*
|
|
175
|
-
* @internal
|
|
176
|
-
*/
|
|
177
|
-
private _originalQuery;
|
|
178
|
-
/** @internal */
|
|
179
|
-
private _subscription;
|
|
180
|
-
/** @internal */
|
|
181
|
-
private _subscribedTo;
|
|
182
|
-
/** @internal */
|
|
183
|
-
private _args;
|
|
184
|
-
/** @internal */
|
|
185
150
|
store: Store | RequestManager;
|
|
186
|
-
constructor(store: Store | RequestManager, args: SubscriptionArgs<RT,
|
|
187
|
-
/**
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
190
|
-
private _beginPolling;
|
|
151
|
+
constructor(store: Store | RequestManager, args: SubscriptionArgs<RT, E>);
|
|
191
152
|
get isIdle(): boolean;
|
|
192
153
|
get autorefreshTypes(): Set<AutorefreshBehaviorType>;
|
|
193
|
-
// we only run this function on component creation
|
|
194
|
-
// and when an update is triggered, so it does not
|
|
195
|
-
// react to changes in the autorefreshThreshold
|
|
196
|
-
// or autorefresh args.
|
|
197
|
-
//
|
|
198
|
-
// if we need to react to those changes, we can
|
|
199
|
-
// use a modifier or internal component or some
|
|
200
|
-
// such to trigger a re-run of this function.
|
|
201
|
-
private _scheduleInterval;
|
|
202
|
-
private _clearInterval;
|
|
203
|
-
/**
|
|
204
|
-
* @internal
|
|
205
|
-
*/
|
|
206
|
-
private _updateSubscriptions;
|
|
207
|
-
/**
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
private _removeSubscriptions;
|
|
211
|
-
/**
|
|
212
|
-
* Install the event listeners for network and visibility changes.
|
|
213
|
-
* This is only done in browser environments with a global `window`.
|
|
214
|
-
*
|
|
215
|
-
* @internal
|
|
216
|
-
*/
|
|
217
|
-
private _installListeners;
|
|
218
|
-
/**
|
|
219
|
-
* If the network is online and the tab is visible, either reload or refresh the request
|
|
220
|
-
* based on the component's configuration and the requested update mode.
|
|
221
|
-
*
|
|
222
|
-
* Valid modes are:
|
|
223
|
-
*
|
|
224
|
-
* - `'reload'`: Force a reload of the request.
|
|
225
|
-
* - `'refresh'`: Refresh the request in the background.
|
|
226
|
-
* - `'policy'`: Make the request, letting the store's configured CachePolicy decide whether to reload, refresh, or do nothing.
|
|
227
|
-
* - `undefined`: Make the request using the component's autorefreshBehavior setting if the autorefreshThreshold has passed.
|
|
228
|
-
*
|
|
229
|
-
* @internal
|
|
230
|
-
*/
|
|
231
|
-
private _maybeUpdate;
|
|
232
154
|
/**
|
|
233
155
|
* Retry the request, reloading it from the server.
|
|
234
156
|
*/
|
|
@@ -240,22 +162,16 @@ export declare class RequestSubscription<
|
|
|
240
162
|
/**
|
|
241
163
|
* features to yield to the error slot of a component
|
|
242
164
|
*/
|
|
243
|
-
get errorFeatures():
|
|
165
|
+
get errorFeatures(): RecoveryFeatures;
|
|
244
166
|
/**
|
|
245
167
|
* features to yield to the content slot of a component
|
|
246
168
|
*/
|
|
247
169
|
get contentFeatures(): ContentFeatures<RT>;
|
|
248
|
-
/**
|
|
249
|
-
* @internal
|
|
250
|
-
*/
|
|
251
|
-
get _request(): Future<RT>;
|
|
252
170
|
get request(): Future<RT>;
|
|
253
|
-
get reqState(): RequestState<RT,
|
|
171
|
+
get reqState(): RequestState<RT, StructuredErrorDocument<E>>;
|
|
254
172
|
get result(): RT;
|
|
255
173
|
}
|
|
256
174
|
export declare function createRequestSubscription<
|
|
257
175
|
RT,
|
|
258
|
-
T,
|
|
259
176
|
E
|
|
260
|
-
>(store: Store | RequestManager, args: SubscriptionArgs<RT,
|
|
261
|
-
export {};
|
|
177
|
+
>(store: Store | RequestManager, args: SubscriptionArgs<RT, E>): RequestSubscription<RT, E>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
/**
|
|
24
|
+
Used to get the latest version of all of the records in this array
|
|
25
|
+
from the adapter.
|
|
26
|
+
|
|
27
|
+
Example
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
let people = store.peekAll('person');
|
|
31
|
+
people.isUpdating; // false
|
|
32
|
+
|
|
33
|
+
people.update().then(function() {
|
|
34
|
+
people.isUpdating; // false
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
people.isUpdating; // true
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
@public
|
|
41
|
+
*/
|
|
42
|
+
update(this: LegacyArray<T>): Promise<LegacyArray<T>>;
|
|
43
|
+
/**
|
|
44
|
+
Saves all of the records in the `RecordArray`.
|
|
45
|
+
|
|
46
|
+
Example
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
let messages = store.peekAll('message');
|
|
50
|
+
messages.forEach(function(message) {
|
|
51
|
+
message.hasBeenSeen = true;
|
|
52
|
+
});
|
|
53
|
+
messages.save();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
@public
|
|
57
|
+
*/
|
|
58
|
+
save(this: LegacyArray<T>): Promise<LegacyArray<T>>;
|
|
59
|
+
}
|
|
60
|
+
export declare function upgradeThis(obj: unknown): asserts obj is LegacyArray;
|
|
61
|
+
export declare function update(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
|
|
62
|
+
export declare function save(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
|
|
63
|
+
export type KeyType = string | symbol | number;
|
|
64
|
+
export declare function isArrayGetter<T>(prop: KeyType): prop is keyof Array<T>;
|
|
65
|
+
export declare function isArraySetter<T>(prop: KeyType): prop is keyof Array<T>;
|
|
66
|
+
export declare function convertToInt(prop: KeyType): number | null;
|
|
67
|
+
export type ForEachCB<T> = (record: T, index: number, context: typeof NativeProxy<ResourceKey[], T[]>) => void;
|
|
68
|
+
export declare function safeForEach<T>(instance: typeof NativeProxy<ResourceKey[], T[]>, arr: ResourceKey[], store: Store, callback: ForEachCB<T>, target: unknown): typeof NativeProxy<ResourceKey[], T[]>;
|
|
69
|
+
type PromiseTo<T> = Omit<Promise<T>, typeof Symbol.toStringTag>;
|
|
70
|
+
type PromiseManyArray<T> = {
|
|
71
|
+
length: number;
|
|
72
|
+
content: ReactiveResourceArray<T> | null;
|
|
73
|
+
promise: Promise<ReactiveResourceArray<T>> | null;
|
|
74
|
+
} & PromiseTo<ReactiveResourceArray<T>>;
|
|
75
|
+
export interface MinimumManager {
|
|
76
|
+
_syncArray(array: ReactiveResourceArray): void;
|
|
77
|
+
mutate?(mutation: LocalRelationshipOperation): void;
|
|
78
|
+
reloadHasMany?<T>(key: string, options?: BaseFinderOptions): Promise<ReactiveResourceArray> | PromiseManyArray<T>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
modelName: TypeFromInstanceOrString<T>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The options for {@link createLegacyLiveArray}
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
export interface LegacyLiveArrayCreateOptions {
|
|
77
|
+
store: Store;
|
|
78
|
+
manager: MinimumManager;
|
|
79
|
+
source: ResourceKey[];
|
|
80
|
+
type: string;
|
|
81
|
+
}
|
package/declarations/store/-private/record-arrays/{many-array.d.ts → legacy-many-array.d.ts}
RENAMED
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import type { BaseFinderOptions,
|
|
2
|
-
import type {
|
|
3
|
-
import type { TypedRecordInstance, TypeFromInstance, TypeFromInstanceOrString } from "../../../types/record.js";
|
|
1
|
+
import type { BaseFinderOptions, ResourceKey } from "../../../types.js";
|
|
2
|
+
import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
|
|
4
3
|
import type { LegacyHasManyField, LinksModeHasManyField } from "../../../types/schema/fields.js";
|
|
5
|
-
import type { Links, PaginationLinks } from "../../../types/spec/json-api-raw.js";
|
|
6
|
-
import type { CreateRecordProperties
|
|
7
|
-
import type {
|
|
8
|
-
import {
|
|
9
|
-
export interface ManyArrayCreateArgs<T> {
|
|
10
|
-
identifiers: StableRecordIdentifier<TypeFromInstanceOrString<T>>[];
|
|
11
|
-
type: TypeFromInstanceOrString<T>;
|
|
12
|
-
store: Store;
|
|
13
|
-
allowMutation: boolean;
|
|
14
|
-
manager: MinimumManager;
|
|
15
|
-
field?: LegacyHasManyField | LinksModeHasManyField;
|
|
16
|
-
identifier: StableRecordIdentifier;
|
|
17
|
-
cache: Cache;
|
|
18
|
-
meta: Record<string, unknown> | null;
|
|
19
|
-
links: Links | PaginationLinks | null;
|
|
20
|
-
key: string;
|
|
21
|
-
isPolymorphic: boolean;
|
|
22
|
-
isAsync: boolean;
|
|
23
|
-
_inverseIsAsync: boolean;
|
|
24
|
-
isLoaded: boolean;
|
|
25
|
-
}
|
|
4
|
+
import type { Links, Meta, PaginationLinks } from "../../../types/spec/json-api-raw.js";
|
|
5
|
+
import type { CreateRecordProperties } from "../store-service.js";
|
|
6
|
+
import type { LegacyLiveArrayCreateOptions } from "./legacy-live-array.js";
|
|
7
|
+
import { type ReactiveResourceArray } from "./resource-array.js";
|
|
26
8
|
/**
|
|
27
9
|
A `ManyArray` is a `MutableArray` that represents the contents of a has-many
|
|
28
10
|
relationship.
|
|
@@ -63,85 +45,21 @@ the has-many.
|
|
|
63
45
|
We call the record to which a relationship belongs-to the
|
|
64
46
|
relationship's _owner_.
|
|
65
47
|
|
|
66
|
-
@class ManyArray
|
|
67
48
|
@public
|
|
68
49
|
*/
|
|
69
|
-
export
|
|
70
|
-
|
|
50
|
+
export interface LegacyManyArray<T = unknown> extends ReactiveResourceArray<T> {
|
|
51
|
+
meta: Meta | null;
|
|
52
|
+
links: Links | PaginationLinks | null;
|
|
53
|
+
/** @private */
|
|
54
|
+
key: string;
|
|
55
|
+
/** @private */
|
|
56
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
71
57
|
/**
|
|
72
58
|
The loading state of this array
|
|
73
|
-
|
|
74
|
-
@property isLoaded
|
|
75
|
-
@type {Boolean}
|
|
76
59
|
@public
|
|
77
60
|
*/
|
|
78
61
|
isLoaded: boolean;
|
|
79
62
|
/**
|
|
80
|
-
`true` if the relationship is polymorphic, `false` otherwise.
|
|
81
|
-
|
|
82
|
-
@property isPolymorphic
|
|
83
|
-
@type {Boolean}
|
|
84
|
-
@private
|
|
85
|
-
*/
|
|
86
|
-
isPolymorphic: boolean;
|
|
87
|
-
_inverseIsAsync: boolean;
|
|
88
|
-
/**
|
|
89
|
-
Metadata associated with the request for async hasMany relationships.
|
|
90
|
-
|
|
91
|
-
Example
|
|
92
|
-
|
|
93
|
-
Given that the server returns the following JSON payload when fetching a
|
|
94
|
-
hasMany relationship:
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
{
|
|
98
|
-
"comments": [{
|
|
99
|
-
"id": 1,
|
|
100
|
-
"comment": "This is the first comment",
|
|
101
|
-
}, {
|
|
102
|
-
// ...
|
|
103
|
-
}],
|
|
104
|
-
|
|
105
|
-
"meta": {
|
|
106
|
-
"page": 1,
|
|
107
|
-
"total": 5
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
You can then access the meta data via the `meta` property:
|
|
113
|
-
|
|
114
|
-
```js
|
|
115
|
-
let comments = await post.comments;
|
|
116
|
-
let meta = comments.meta;
|
|
117
|
-
|
|
118
|
-
// meta.page => 1
|
|
119
|
-
// meta.total => 5
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
@property meta
|
|
123
|
-
@type {Object | null}
|
|
124
|
-
@public
|
|
125
|
-
*/
|
|
126
|
-
meta: Record<string, unknown> | null;
|
|
127
|
-
/**
|
|
128
|
-
* Retrieve the links for this relationship
|
|
129
|
-
*
|
|
130
|
-
@property links
|
|
131
|
-
@type {Object | null}
|
|
132
|
-
@public
|
|
133
|
-
*/
|
|
134
|
-
links: Links | PaginationLinks | null;
|
|
135
|
-
identifier: StableRecordIdentifier;
|
|
136
|
-
cache: Cache;
|
|
137
|
-
_manager: MinimumManager;
|
|
138
|
-
store: Store;
|
|
139
|
-
key: string;
|
|
140
|
-
type: ModelSchema;
|
|
141
|
-
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
142
|
-
constructor(options: ManyArrayCreateArgs<T>);
|
|
143
|
-
notify(): void;
|
|
144
|
-
/**
|
|
145
63
|
Reloads all of the records in the manyArray. If the manyArray
|
|
146
64
|
holds a relationship that was originally fetched using a links url
|
|
147
65
|
WarpDrive will revisit the original links url to repopulate the
|
|
@@ -162,13 +80,11 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
162
80
|
|
|
163
81
|
@public
|
|
164
82
|
*/
|
|
165
|
-
reload(options?: BaseFinderOptions): Promise<
|
|
83
|
+
reload(options?: BaseFinderOptions): Promise<LegacyManyArray<T>>;
|
|
166
84
|
/**
|
|
167
|
-
Create a child record
|
|
85
|
+
Create a child record and associated it to the collection
|
|
168
86
|
|
|
169
87
|
@public
|
|
170
|
-
@param {Object} hash
|
|
171
|
-
@return {Model} record
|
|
172
88
|
*/
|
|
173
89
|
createRecord(hash: CreateRecordProperties<T>): T;
|
|
174
90
|
/**
|
|
@@ -178,7 +94,7 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
178
94
|
|
|
179
95
|
Example
|
|
180
96
|
|
|
181
|
-
```
|
|
97
|
+
```js
|
|
182
98
|
const { content: { data: inbox } } = await store.request(findRecord({ type: 'inbox', id: '1' }));
|
|
183
99
|
|
|
184
100
|
let messages = await inbox.messages;
|
|
@@ -189,9 +105,29 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
189
105
|
```
|
|
190
106
|
|
|
191
107
|
@public
|
|
192
|
-
@return {PromiseArray} promise
|
|
193
108
|
*/
|
|
194
|
-
save: () => Promise<
|
|
195
|
-
/** @
|
|
196
|
-
destroy()
|
|
109
|
+
save: () => Promise<LegacyManyArray<T>>;
|
|
110
|
+
/** @private */
|
|
111
|
+
destroy: () => void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The options for {@link createLegacyManyArray}
|
|
115
|
+
*
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
export interface LegacyManyArrayCreateOptions extends LegacyLiveArrayCreateOptions {
|
|
119
|
+
isLoaded: boolean;
|
|
120
|
+
editable: boolean;
|
|
121
|
+
isAsync: boolean;
|
|
122
|
+
isPolymorphic: boolean;
|
|
123
|
+
field: LegacyHasManyField | LinksModeHasManyField;
|
|
124
|
+
identifier: ResourceKey;
|
|
125
|
+
links: Links | PaginationLinks | null;
|
|
126
|
+
meta: Meta | null;
|
|
197
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates a {@link LegacyManyArray}
|
|
130
|
+
*
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
export declare function createLegacyManyArray<T>(options: LegacyManyArrayCreateOptions): LegacyManyArray<T>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ImmutableRequestInfo } from "../../../types/request.js";
|
|
2
|
+
import type { Links, Meta, PaginationLinks } from "../../../types/spec/json-api-raw.js";
|
|
3
|
+
import type { LegacyLiveArray } from "./legacy-live-array.js";
|
|
4
|
+
/**
|
|
5
|
+
* QueryArrays contain the primary records returned when querying
|
|
6
|
+
* for records by `ResourceType`.
|
|
7
|
+
*
|
|
8
|
+
* ### Basic Example
|
|
9
|
+
*
|
|
10
|
+
* For instance, if an application were to have a `'user'` type:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const users = await store.query('user', { name: 'Chris' });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* ---
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* ### QueryArrays are Arrays
|
|
21
|
+
*
|
|
22
|
+
* QueryArrays have all array APIs, and will report `true`
|
|
23
|
+
* for both `queryArray instanceof Array` and `Array.isArray(queryArray)`
|
|
24
|
+
*
|
|
25
|
+
* However, any mutation of the array will throw an error.
|
|
26
|
+
*
|
|
27
|
+
* ---
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
* ### Reactive
|
|
32
|
+
*
|
|
33
|
+
* If a record in a QueryArray is deleted and unloaded, it will be
|
|
34
|
+
* automatically removed from the array.
|
|
35
|
+
*
|
|
36
|
+
* ---
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* ### Immutable
|
|
41
|
+
*
|
|
42
|
+
* Records cannot be directly added to or removed from a QueryArray.
|
|
43
|
+
*
|
|
44
|
+
* ---
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
*
|
|
48
|
+
* ### Polymorphism
|
|
49
|
+
*
|
|
50
|
+
* QueryArrays are not intended to be polymorphic. If your application has
|
|
51
|
+
* an abstract type "car" with concrete types "ferrari" and "bmw", a query
|
|
52
|
+
* which returns primary data containing both ferraris and bmws will *likely*
|
|
53
|
+
* work, but it is not guaranteed.
|
|
54
|
+
*
|
|
55
|
+
* In contrast, the {@link ReactiveResourceArray} returned when using {@link Store.request}
|
|
56
|
+
* is guaranteed to work with polymorphic responses.
|
|
57
|
+
*
|
|
58
|
+
* ---
|
|
59
|
+
*
|
|
60
|
+
*
|
|
61
|
+
*
|
|
62
|
+
* ### Memory Leaks
|
|
63
|
+
*
|
|
64
|
+
* QueryArrays are meant to be long lived. They can be refreshed using
|
|
65
|
+
* `array.update()`, and destroyed via `array.destroy()`.
|
|
66
|
+
*
|
|
67
|
+
* Unlike most Reactive state in WarpDrive, applications must choose to call
|
|
68
|
+
* `destroy` when the `QueryArray` is no longer needed, else the array instance
|
|
69
|
+
* will be retained until either the application or the store which created it
|
|
70
|
+
* are destroyed. Destroying a QueryArray does not remove its records
|
|
71
|
+
* from the cache, but it does remove the array as well as the overhead it requires
|
|
72
|
+
* from the store for book-keeping.
|
|
73
|
+
*
|
|
74
|
+
* @legacy we recommend againt using QueryArrays. Use {@link Store.request} instead
|
|
75
|
+
*/
|
|
76
|
+
export interface LegacyQueryArray<T = unknown> extends LegacyLiveArray<T> {
|
|
77
|
+
query: ImmutableRequestInfo | Record<string, unknown> | null;
|
|
78
|
+
destroy(): void;
|
|
79
|
+
links: PaginationLinks | Links | null;
|
|
80
|
+
meta: Meta | null;
|
|
81
|
+
}
|