@warp-drive/core 5.7.0-alpha.2 → 5.7.0-alpha.20
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-BssvpNQv.js} +5136 -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
|
@@ -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
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Future } from "../../../request.js";
|
|
2
2
|
import type { ImmutableRequestInfo, ResponseInfo, StructuredErrorDocument } from "../../../types/request.js";
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
4
|
import type { PendingPromise, RejectedPromise, ResolvedPromise } from "./promise-state.js";
|
|
4
5
|
/**
|
|
5
6
|
* Lazily consumes the stream of a request, providing a number of
|
|
@@ -69,17 +70,14 @@ export interface PendingRequest extends PendingPromise {
|
|
|
69
70
|
* Extends the {@link ResolvedPromise} interface.
|
|
70
71
|
*
|
|
71
72
|
*/
|
|
72
|
-
export interface ResolvedRequest<
|
|
73
|
-
RT,
|
|
74
|
-
T
|
|
75
|
-
> extends ResolvedPromise<RT> {
|
|
73
|
+
export interface ResolvedRequest<RT> extends ResolvedPromise<RT> {
|
|
76
74
|
/**
|
|
77
75
|
* Whether the request is cancelled.
|
|
78
76
|
*
|
|
79
77
|
*/
|
|
80
78
|
isCancelled: false;
|
|
81
79
|
loadingState: RequestLoadingState;
|
|
82
|
-
request: ImmutableRequestInfo<RT
|
|
80
|
+
request: ImmutableRequestInfo<RT> | null;
|
|
83
81
|
response: Response | ResponseInfo | null;
|
|
84
82
|
}
|
|
85
83
|
/**
|
|
@@ -92,7 +90,6 @@ export interface ResolvedRequest<
|
|
|
92
90
|
*/
|
|
93
91
|
export interface RejectedRequest<
|
|
94
92
|
RT,
|
|
95
|
-
T,
|
|
96
93
|
E extends StructuredErrorDocument = StructuredErrorDocument
|
|
97
94
|
> extends RejectedPromise<E> {
|
|
98
95
|
/**
|
|
@@ -101,7 +98,7 @@ export interface RejectedRequest<
|
|
|
101
98
|
*/
|
|
102
99
|
isCancelled: false;
|
|
103
100
|
loadingState: RequestLoadingState;
|
|
104
|
-
request: ImmutableRequestInfo<RT
|
|
101
|
+
request: ImmutableRequestInfo<RT> | null;
|
|
105
102
|
response: Response | ResponseInfo | null;
|
|
106
103
|
}
|
|
107
104
|
/**
|
|
@@ -112,7 +109,6 @@ export interface RejectedRequest<
|
|
|
112
109
|
*/
|
|
113
110
|
export interface CancelledRequest<
|
|
114
111
|
RT,
|
|
115
|
-
T,
|
|
116
112
|
E extends StructuredErrorDocument = StructuredErrorDocument
|
|
117
113
|
> {
|
|
118
114
|
/**
|
|
@@ -175,33 +171,33 @@ export interface CancelledRequest<
|
|
|
175
171
|
*/
|
|
176
172
|
isCancelled: true;
|
|
177
173
|
loadingState: RequestLoadingState;
|
|
178
|
-
request: ImmutableRequestInfo<RT
|
|
174
|
+
request: ImmutableRequestInfo<RT> | null;
|
|
179
175
|
response: Response | ResponseInfo | null;
|
|
180
176
|
}
|
|
181
177
|
/**
|
|
182
|
-
* RequestState extends the concept of PromiseState to provide a reactive
|
|
183
|
-
* wrapper for a request
|
|
178
|
+
* RequestState extends the concept of {@link PromiseState} to provide a reactive
|
|
179
|
+
* wrapper for a request {@link Future} which allows you write declarative code
|
|
184
180
|
* around a Future's control flow.
|
|
185
181
|
*
|
|
186
182
|
* It is useful in both Template and JavaScript contexts, allowing you
|
|
187
183
|
* to quickly derive behaviors and data from pending, error and success
|
|
188
184
|
* states.
|
|
189
185
|
*
|
|
190
|
-
* The key difference between a Promise and a Future is that Futures provide
|
|
191
|
-
* access to a stream of their content, the
|
|
192
|
-
* as well as the ability to attempt to abort the request.
|
|
186
|
+
* The key difference between a {@link Promise} and a Future is that Futures provide
|
|
187
|
+
* access to a {@link ReadableStream | stream} of their content, the {@link RequestKey} of the request (if any)
|
|
188
|
+
* as well as the ability to attempt to {@link Future.abort | abort} the request.
|
|
193
189
|
*
|
|
194
190
|
* ```ts
|
|
195
191
|
* interface Future<T> extends Promise<T>> {
|
|
196
192
|
* getStream(): Promise<ReadableStream>;
|
|
197
193
|
* abort(): void;
|
|
198
|
-
* lid:
|
|
194
|
+
* lid: RequestKey | null;
|
|
199
195
|
* }
|
|
200
196
|
* ```
|
|
201
197
|
*
|
|
202
198
|
* These additional APIs allow us to craft even richer state experiences.
|
|
203
199
|
*
|
|
204
|
-
* To get the state of a request, use
|
|
200
|
+
* To get the state of a request, use {@link getRequestState}.
|
|
205
201
|
*
|
|
206
202
|
* See also:
|
|
207
203
|
* - {@link PendingRequest}
|
|
@@ -212,14 +208,12 @@ export interface CancelledRequest<
|
|
|
212
208
|
*/
|
|
213
209
|
export type RequestCacheRequestState<
|
|
214
210
|
RT = unknown,
|
|
215
|
-
T = unknown,
|
|
216
211
|
E extends StructuredErrorDocument = StructuredErrorDocument
|
|
217
|
-
> = PendingRequest | ResolvedRequest<RT
|
|
212
|
+
> = PendingRequest | ResolvedRequest<RT> | RejectedRequest<RT, E> | CancelledRequest<RT, E>;
|
|
218
213
|
export declare function createRequestState<
|
|
219
214
|
RT,
|
|
220
|
-
T,
|
|
221
215
|
E
|
|
222
|
-
>(future: Future<RT>): Readonly<RequestCacheRequestState<RT,
|
|
216
|
+
>(future: Future<RT>): Readonly<RequestCacheRequestState<RT, StructuredErrorDocument<E>>>;
|
|
223
217
|
/**
|
|
224
218
|
* `getRequestState` can be used in both JavaScript and Template contexts.
|
|
225
219
|
*
|
|
@@ -272,6 +266,5 @@ export declare function createRequestState<
|
|
|
272
266
|
*/
|
|
273
267
|
export declare function getRequestState<
|
|
274
268
|
RT,
|
|
275
|
-
T,
|
|
276
269
|
E
|
|
277
|
-
>(future: Future<RT>): Readonly<RequestCacheRequestState<RT,
|
|
270
|
+
>(future: Future<RT>): Readonly<RequestCacheRequestState<RT, StructuredErrorDocument<E>>>;
|
|
@@ -22,7 +22,6 @@ type ContentFeatures<RT> = {
|
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
23
|
export interface SubscriptionArgs<
|
|
24
24
|
RT,
|
|
25
|
-
T,
|
|
26
25
|
E
|
|
27
26
|
> {
|
|
28
27
|
/**
|
|
@@ -37,7 +36,7 @@ export interface SubscriptionArgs<
|
|
|
37
36
|
* like the component to also initiate the request.
|
|
38
37
|
*
|
|
39
38
|
*/
|
|
40
|
-
query?: StoreRequestInput<RT
|
|
39
|
+
query?: StoreRequestInput<RT>;
|
|
41
40
|
/**
|
|
42
41
|
* The autorefresh behavior for the request. This can be a boolean, or any
|
|
43
42
|
* combination of the following values: `'online'`, `'interval'`, `'invalid'`.
|
|
@@ -80,7 +79,6 @@ export interface SubscriptionArgs<
|
|
|
80
79
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
80
|
export interface RequestSubscription<
|
|
82
81
|
RT,
|
|
83
|
-
T,
|
|
84
82
|
E
|
|
85
83
|
> {
|
|
86
84
|
/**
|
|
@@ -96,7 +94,6 @@ export interface RequestSubscription<
|
|
|
96
94
|
*/
|
|
97
95
|
export declare class RequestSubscription<
|
|
98
96
|
RT,
|
|
99
|
-
T,
|
|
100
97
|
E
|
|
101
98
|
> {
|
|
102
99
|
/**
|
|
@@ -183,7 +180,7 @@ export declare class RequestSubscription<
|
|
|
183
180
|
private _args;
|
|
184
181
|
/** @internal */
|
|
185
182
|
store: Store | RequestManager;
|
|
186
|
-
constructor(store: Store | RequestManager, args: SubscriptionArgs<RT,
|
|
183
|
+
constructor(store: Store | RequestManager, args: SubscriptionArgs<RT, E>);
|
|
187
184
|
/**
|
|
188
185
|
* @internal
|
|
189
186
|
*/
|
|
@@ -250,12 +247,11 @@ export declare class RequestSubscription<
|
|
|
250
247
|
*/
|
|
251
248
|
get _request(): Future<RT>;
|
|
252
249
|
get request(): Future<RT>;
|
|
253
|
-
get reqState(): RequestState<RT,
|
|
250
|
+
get reqState(): RequestState<RT, StructuredErrorDocument<E>>;
|
|
254
251
|
get result(): RT;
|
|
255
252
|
}
|
|
256
253
|
export declare function createRequestSubscription<
|
|
257
254
|
RT,
|
|
258
|
-
T,
|
|
259
255
|
E
|
|
260
|
-
>(store: Store | RequestManager, args: SubscriptionArgs<RT,
|
|
256
|
+
>(store: Store | RequestManager, args: SubscriptionArgs<RT, E>): RequestSubscription<RT, E>;
|
|
261
257
|
export {};
|
|
@@ -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;
|
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,83 +45,25 @@ 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
|
|
50
|
+
export interface LegacyManyArray<T = unknown> extends ReactiveResourceArray<T> {
|
|
51
|
+
meta: Meta | null;
|
|
52
|
+
links: Links | PaginationLinks | null;
|
|
53
|
+
/** @internal */
|
|
54
|
+
isPolymorphic: boolean;
|
|
55
|
+
/** @internal */
|
|
70
56
|
isAsync: boolean;
|
|
57
|
+
/** @internal */
|
|
58
|
+
key: string;
|
|
59
|
+
/** @internal */
|
|
60
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
71
61
|
/**
|
|
72
62
|
The loading state of this array
|
|
73
|
-
|
|
74
|
-
@property isLoaded
|
|
75
|
-
@type {Boolean}
|
|
76
63
|
@public
|
|
77
64
|
*/
|
|
78
65
|
isLoaded: boolean;
|
|
79
|
-
/**
|
|
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>);
|
|
66
|
+
/** @internal */
|
|
143
67
|
notify(): void;
|
|
144
68
|
/**
|
|
145
69
|
Reloads all of the records in the manyArray. If the manyArray
|
|
@@ -162,13 +86,11 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
162
86
|
|
|
163
87
|
@public
|
|
164
88
|
*/
|
|
165
|
-
reload(options?: BaseFinderOptions): Promise<
|
|
89
|
+
reload(options?: BaseFinderOptions): Promise<LegacyManyArray<T>>;
|
|
166
90
|
/**
|
|
167
|
-
Create a child record
|
|
91
|
+
Create a child record and associated it to the collection
|
|
168
92
|
|
|
169
93
|
@public
|
|
170
|
-
@param {Object} hash
|
|
171
|
-
@return {Model} record
|
|
172
94
|
*/
|
|
173
95
|
createRecord(hash: CreateRecordProperties<T>): T;
|
|
174
96
|
/**
|
|
@@ -178,7 +100,7 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
178
100
|
|
|
179
101
|
Example
|
|
180
102
|
|
|
181
|
-
```
|
|
103
|
+
```js
|
|
182
104
|
const { content: { data: inbox } } = await store.request(findRecord({ type: 'inbox', id: '1' }));
|
|
183
105
|
|
|
184
106
|
let messages = await inbox.messages;
|
|
@@ -189,9 +111,29 @@ export declare class RelatedCollection<T = unknown> extends IdentifierArray<T> {
|
|
|
189
111
|
```
|
|
190
112
|
|
|
191
113
|
@public
|
|
192
|
-
@return {PromiseArray} promise
|
|
193
114
|
*/
|
|
194
|
-
save: () => Promise<
|
|
115
|
+
save: () => Promise<LegacyManyArray<T>>;
|
|
195
116
|
/** @internal */
|
|
196
|
-
destroy()
|
|
117
|
+
destroy: () => void;
|
|
197
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The options for {@link createLegacyManyArray}
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export interface LegacyManyArrayCreateOptions extends LegacyLiveArrayCreateOptions {
|
|
125
|
+
isLoaded: boolean;
|
|
126
|
+
editable: boolean;
|
|
127
|
+
isAsync: boolean;
|
|
128
|
+
isPolymorphic: boolean;
|
|
129
|
+
field: LegacyHasManyField | LinksModeHasManyField;
|
|
130
|
+
identifier: ResourceKey;
|
|
131
|
+
links: Links | PaginationLinks | null;
|
|
132
|
+
meta: Meta | null;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a {@link LegacyManyArray}
|
|
136
|
+
*
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
export declare function createLegacyManyArray<T>(options: LegacyManyArrayCreateOptions): LegacyManyArray<T>;
|
|
@@ -0,0 +1,103 @@
|
|
|
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, LegacyLiveArrayCreateOptions } 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
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The options for {@link createLegacyQueryArray}
|
|
84
|
+
*
|
|
85
|
+
* See also {@link LegacyLiveArrayCreateOptions} which
|
|
86
|
+
* this extends.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export interface LegacyQueryArrayCreateOptions extends LegacyLiveArrayCreateOptions {
|
|
91
|
+
query: ImmutableRequestInfo | Record<string, unknown> | null;
|
|
92
|
+
isLoaded: boolean;
|
|
93
|
+
links: PaginationLinks | Links | null;
|
|
94
|
+
meta: Meta | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a {@link LegacyQueryArray}
|
|
98
|
+
*
|
|
99
|
+
* Options: {@link LegacyQueryArrayCreateOptions}
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
export declare function createLegacyQueryArray<T = unknown>(options: LegacyQueryArrayCreateOptions): LegacyQueryArray<T>;
|