@warp-drive/core 5.7.0-alpha.23 → 5.7.0-alpha.25
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/reactive/-private/schema.d.ts +6 -0
- package/declarations/request/-private/manager.d.ts +2 -6
- package/declarations/request/-private/types.d.ts +19 -18
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +4 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +17 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +114 -0
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -8
- package/declarations/store/-private/store-service.d.ts +1 -1
- package/declarations/store/-private.d.ts +2 -2
- package/declarations/types/request.d.ts +23 -8
- package/dist/{context-kQXhkeBj.js → context-BNZebmoO.js} +2 -0
- package/dist/index.js +6 -7
- package/dist/reactive.js +9 -2
- package/dist/{request-state-55umD7hP.js → request-state-XxA7ZVps.js} +142 -53
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/types/-private.js +1 -1
- package/dist/types/request.js +18 -3
- package/package.json +3 -3
|
@@ -301,6 +301,12 @@ export declare class SchemaService implements SchemaServiceInterface {
|
|
|
301
301
|
* @internal
|
|
302
302
|
*/
|
|
303
303
|
_kind<T extends keyof KindFns>(mode: string, kind: T): KindFns[T];
|
|
304
|
+
/**
|
|
305
|
+
* Registers a {@link HashFn} for use with a {@link HashField} for
|
|
306
|
+
* either {@link ObjectSchema} identity or polymorphic type calculation.
|
|
307
|
+
*
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
304
310
|
registerHashFn<T extends object>(hashFn: HashFn<T>): void;
|
|
305
311
|
fields({ type }: {
|
|
306
312
|
type: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestKey } from "../../types/identifier.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type RequestInfo } from "../../types/request.js";
|
|
3
3
|
import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from "./types.js";
|
|
4
4
|
import { IS_CACHE_HANDLER } from "./utils.js";
|
|
5
5
|
/**
|
|
@@ -90,7 +90,7 @@ import { IS_CACHE_HANDLER } from "./utils.js";
|
|
|
90
90
|
* type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
|
|
91
91
|
* ```
|
|
92
92
|
*
|
|
93
|
-
* @
|
|
93
|
+
* @hideconstructor
|
|
94
94
|
* @public
|
|
95
95
|
*/
|
|
96
96
|
export declare class RequestManager {
|
|
@@ -132,8 +132,6 @@ export declare class RequestManager {
|
|
|
132
132
|
* curry the request, or pass along a modified request.
|
|
133
133
|
*
|
|
134
134
|
* @public
|
|
135
|
-
* @param {Handler[]} newHandlers
|
|
136
|
-
* @return {ThisType}
|
|
137
135
|
*/
|
|
138
136
|
use(newHandlers: Handler[]): this;
|
|
139
137
|
/**
|
|
@@ -142,8 +140,6 @@ export declare class RequestManager {
|
|
|
142
140
|
* Returns a Future that fulfills with a StructuredDocument
|
|
143
141
|
*
|
|
144
142
|
* @public
|
|
145
|
-
* @param {RequestInfo} request
|
|
146
|
-
* @return {Future}
|
|
147
143
|
*/
|
|
148
144
|
request<RT>(request: RequestInfo<RT>): Future<RT>;
|
|
149
145
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-irregular-whitespace */
|
|
2
|
+
import type { Store } from "../../store/-private.js";
|
|
2
3
|
import type { RequestKey } from "../../types/identifier.js";
|
|
3
4
|
import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
|
|
5
|
+
import type { RequestManager } from "./manager.js";
|
|
4
6
|
export interface GodContext {
|
|
5
7
|
controller: AbortController;
|
|
6
8
|
response: ResponseInfo | null;
|
|
@@ -8,6 +10,7 @@ export interface GodContext {
|
|
|
8
10
|
hasRequestedStream: boolean;
|
|
9
11
|
id: number;
|
|
10
12
|
identifier: RequestKey | null;
|
|
13
|
+
requester: RequestManager | Store;
|
|
11
14
|
}
|
|
12
15
|
export type Deferred<T> = {
|
|
13
16
|
resolve(v: T): void;
|
|
@@ -32,10 +35,14 @@ export type DeferredStream = {
|
|
|
32
35
|
* @public
|
|
33
36
|
*/
|
|
34
37
|
export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
38
|
+
/** @internal */
|
|
35
39
|
[IS_FUTURE]: true;
|
|
36
40
|
/**
|
|
37
41
|
* Cancel this request by firing the {@link AbortController}'s signal.
|
|
38
42
|
*
|
|
43
|
+
* This method can be used as an action or event handler as its
|
|
44
|
+
* context is bound to the Future instance.
|
|
45
|
+
*
|
|
39
46
|
* @privateRemarks
|
|
40
47
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
|
|
41
48
|
*
|
|
@@ -46,8 +53,10 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
|
46
53
|
/**
|
|
47
54
|
* Get the response stream, if any, once made available.
|
|
48
55
|
*
|
|
56
|
+
* This method can be used as an action or event handler as its
|
|
57
|
+
* context is bound to the Future instance.
|
|
58
|
+
*
|
|
49
59
|
* @public
|
|
50
|
-
* @return {Promise<ReadableStream | null>}
|
|
51
60
|
*/
|
|
52
61
|
getStream(): Promise<ReadableStream | null>;
|
|
53
62
|
/**
|
|
@@ -55,28 +64,27 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
|
55
64
|
* mostly useful for instrumentation and infrastructure.
|
|
56
65
|
*
|
|
57
66
|
* @param cb the callback to run
|
|
58
|
-
* @public
|
|
59
|
-
* @return {void}
|
|
60
67
|
*/
|
|
61
68
|
onFinalize(cb: () => void): void;
|
|
62
69
|
/**
|
|
63
70
|
* The identifier of the associated request, if any, as
|
|
64
71
|
* assigned by the CacheHandler.
|
|
65
|
-
*
|
|
66
|
-
* @property lid
|
|
67
|
-
* @type {RequestKey | null}
|
|
68
|
-
* @public
|
|
69
72
|
*/
|
|
70
73
|
lid: RequestKey | null;
|
|
71
74
|
/**
|
|
72
75
|
* The id of the associated request, if any, as assigned
|
|
73
76
|
* by the RequestManager
|
|
74
77
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
78
|
+
* This is not unique across Manager instances and cannot
|
|
79
|
+
* be used to identify or dedupe requests.
|
|
78
80
|
*/
|
|
79
81
|
id: number;
|
|
82
|
+
/**
|
|
83
|
+
* The RequestManager or Store that initiated this request.
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
requester: RequestManager | Store;
|
|
80
88
|
}
|
|
81
89
|
export type DeferredFuture<T> = {
|
|
82
90
|
resolve(v: StructuredDataDocument<T>): void;
|
|
@@ -191,8 +199,6 @@ const manager = new RequestManager()
|
|
|
191
199
|
|
|
192
200
|
Handlers will be invoked in the order they are registered ("fifo", first-in first-out), and may only be registered up until the first request is made. It is recommended but not required to register all handlers at one time in order to ensure explicitly visible handler ordering.
|
|
193
201
|
|
|
194
|
-
|
|
195
|
-
@class (Interface) Handler
|
|
196
202
|
@public
|
|
197
203
|
*/
|
|
198
204
|
export interface Handler {
|
|
@@ -202,20 +208,17 @@ export interface Handler {
|
|
|
202
208
|
* other handlers.
|
|
203
209
|
*
|
|
204
210
|
* @public
|
|
205
|
-
* @param context
|
|
206
|
-
* @param next
|
|
207
211
|
*/
|
|
208
212
|
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
|
|
209
213
|
}
|
|
210
214
|
/**
|
|
211
|
-
* The CacheHandler is identical to other handlers
|
|
215
|
+
* The CacheHandler is identical to other handlers except that it
|
|
212
216
|
* is allowed to return a value synchronously. This is useful for
|
|
213
217
|
* features like reducing microtask queueing when de-duping.
|
|
214
218
|
*
|
|
215
219
|
* A RequestManager may only have one CacheHandler, registered via
|
|
216
220
|
* `manager.useCache(CacheHandler)`.
|
|
217
221
|
*
|
|
218
|
-
* @class (Interface) CacheHandler
|
|
219
222
|
* @public
|
|
220
223
|
*/
|
|
221
224
|
export interface CacheHandler {
|
|
@@ -225,8 +228,6 @@ export interface CacheHandler {
|
|
|
225
228
|
* other handlers.
|
|
226
229
|
*
|
|
227
230
|
* @public
|
|
228
|
-
* @param context
|
|
229
|
-
* @param next
|
|
230
231
|
*/
|
|
231
232
|
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
|
|
232
233
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ARRAY_SIGNAL, OBJECT_SIGNAL, type SignalRef } from "./configure.js";
|
|
2
2
|
export type { SignalRef };
|
|
3
3
|
export { ARRAY_SIGNAL, OBJECT_SIGNAL };
|
|
4
|
+
interface Initializer {
|
|
5
|
+
value: () => unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare function makeInitializer(fn: () => unknown): Initializer;
|
|
4
8
|
/**
|
|
5
9
|
* A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
|
|
6
10
|
* that enables us to store and manage the signal in a universal way.
|
|
@@ -25,12 +25,29 @@ export declare function defineSignal<T extends object>(obj: T, key: string, v?:
|
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
27
|
export declare function defineNonEnumerableSignal<T extends object>(obj: T, key: string, v?: unknown): void;
|
|
28
|
+
interface DecoratorPropertyDescriptor extends PropertyDescriptor {
|
|
29
|
+
initializer?: () => unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decorator version of creating a signal.
|
|
33
|
+
*/
|
|
34
|
+
export declare function signal<
|
|
35
|
+
T extends object,
|
|
36
|
+
K extends keyof T & string
|
|
37
|
+
>(target: T, key: K, descriptor?: DecoratorPropertyDescriptor): void;
|
|
38
|
+
/**
|
|
39
|
+
* Decorator version of creating a memoized getter
|
|
40
|
+
*/
|
|
28
41
|
export declare function memoized<
|
|
29
42
|
T extends object,
|
|
30
43
|
K extends keyof T & string
|
|
31
44
|
>(target: T, key: K, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
45
|
+
/**
|
|
46
|
+
* Decorator version of creating a gate.
|
|
47
|
+
*/
|
|
32
48
|
export declare function gate<
|
|
33
49
|
T extends object,
|
|
34
50
|
K extends keyof T & string
|
|
35
51
|
>(_target: T, key: K, desc: PropertyDescriptor): PropertyDescriptor;
|
|
36
52
|
export declare function defineGate<T extends object>(obj: T, key: string, desc: PropertyDescriptor): void;
|
|
53
|
+
export {};
|
|
@@ -7,6 +7,7 @@ import type { PendingPromise, RejectedPromise, ResolvedPromise } from "./promise
|
|
|
7
7
|
* reactive properties that can be used to build UIs that respond
|
|
8
8
|
* to the progress of a request.
|
|
9
9
|
*
|
|
10
|
+
* @hideconstructor
|
|
10
11
|
*/
|
|
11
12
|
export declare class RequestLoadingState {
|
|
12
13
|
private _sizeHint;
|
|
@@ -71,11 +72,52 @@ export interface PendingRequest extends PendingPromise {
|
|
|
71
72
|
*
|
|
72
73
|
*/
|
|
73
74
|
export interface ResolvedRequest<RT> extends ResolvedPromise<RT> {
|
|
75
|
+
/**
|
|
76
|
+
* Retries the request with high (blocking) priority. This is the
|
|
77
|
+
* same as having passed `cacheOptions.reload = true` on the original
|
|
78
|
+
* request.
|
|
79
|
+
*
|
|
80
|
+
* This will not change the existing request's state. To subscribe
|
|
81
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
82
|
+
* {@link Future}.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const future = state.reload();
|
|
86
|
+
* const state = getRequestState(future);
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
90
|
+
* as its context is bound.
|
|
91
|
+
*/
|
|
92
|
+
reload(): Future<RT>;
|
|
93
|
+
/**
|
|
94
|
+
* Retries the request with low (non-blocking) priority. This is the
|
|
95
|
+
* same as having passed `cacheOptions.backgroundReload = true` on the original
|
|
96
|
+
* request.
|
|
97
|
+
*
|
|
98
|
+
* This will not change the existing request's state. To subscribe
|
|
99
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
100
|
+
* {@link Future}.
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* const future = state.reload();
|
|
104
|
+
* const state = getRequestState(future);
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
108
|
+
* as its context is bound.
|
|
109
|
+
*/
|
|
110
|
+
refresh(usePolicy?: boolean): Future<RT>;
|
|
74
111
|
/**
|
|
75
112
|
* Whether the request is cancelled.
|
|
76
113
|
*
|
|
77
114
|
*/
|
|
78
115
|
isCancelled: false;
|
|
116
|
+
/**
|
|
117
|
+
* A lazily created {@link RequestLoadingState} instance
|
|
118
|
+
* which provides a number of reactive properties that can be used
|
|
119
|
+
* to build UIs that respond to the progress of a request.
|
|
120
|
+
*/
|
|
79
121
|
loadingState: RequestLoadingState;
|
|
80
122
|
request: ImmutableRequestInfo<RT> | null;
|
|
81
123
|
response: Response | ResponseInfo | null;
|
|
@@ -92,6 +134,42 @@ export interface RejectedRequest<
|
|
|
92
134
|
RT,
|
|
93
135
|
E extends StructuredErrorDocument = StructuredErrorDocument
|
|
94
136
|
> extends RejectedPromise<E> {
|
|
137
|
+
/**
|
|
138
|
+
* Retries the request with high (blocking) priority. This is the
|
|
139
|
+
* same as having passed `cacheOptions.reload = true` on the original
|
|
140
|
+
* request.
|
|
141
|
+
*
|
|
142
|
+
* This will not change the existing request's state. To subscribe
|
|
143
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
144
|
+
* {@link Future}.
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* const future = state.reload();
|
|
148
|
+
* const state = getRequestState(future);
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
152
|
+
* as its context is bound.
|
|
153
|
+
*/
|
|
154
|
+
reload(): Future<RT>;
|
|
155
|
+
/**
|
|
156
|
+
* Retries the request with low (non-blocking) priority. This is the
|
|
157
|
+
* same as having passed `cacheOptions.backgroundReload = true` on the original
|
|
158
|
+
* request.
|
|
159
|
+
*
|
|
160
|
+
* This will not change the existing request's state. To subscribe
|
|
161
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
162
|
+
* {@link Future}.
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* const future = state.reload();
|
|
166
|
+
* const state = getRequestState(future);
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
170
|
+
* as its context is bound.
|
|
171
|
+
*/
|
|
172
|
+
refresh(usePolicy?: boolean): Future<RT>;
|
|
95
173
|
/**
|
|
96
174
|
* Whether the request is cancelled.
|
|
97
175
|
*
|
|
@@ -111,6 +189,42 @@ export interface CancelledRequest<
|
|
|
111
189
|
RT,
|
|
112
190
|
E extends StructuredErrorDocument = StructuredErrorDocument
|
|
113
191
|
> {
|
|
192
|
+
/**
|
|
193
|
+
* Retries the request with high (blocking) priority. This is the
|
|
194
|
+
* same as having passed `cacheOptions.reload = true` on the original
|
|
195
|
+
* request.
|
|
196
|
+
*
|
|
197
|
+
* This will not change the existing request's state. To subscribe
|
|
198
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
199
|
+
* {@link Future}.
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* const future = state.reload();
|
|
203
|
+
* const state = getRequestState(future);
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
207
|
+
* as its context is bound.
|
|
208
|
+
*/
|
|
209
|
+
reload(): Future<RT>;
|
|
210
|
+
/**
|
|
211
|
+
* Retries the request with low (non-blocking) priority. This is the
|
|
212
|
+
* same as having passed `cacheOptions.backgroundReload = true` on the original
|
|
213
|
+
* request.
|
|
214
|
+
*
|
|
215
|
+
* This will not change the existing request's state. To subscribe
|
|
216
|
+
* to the new request's state, use `getRequestState` on the returned
|
|
217
|
+
* {@link Future}.
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* const future = state.reload();
|
|
221
|
+
* const state = getRequestState(future);
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* It is safe to pass this around as an "action" or "event" handler
|
|
225
|
+
* as its context is bound.
|
|
226
|
+
*/
|
|
227
|
+
refresh(usePolicy?: boolean): Future<RT>;
|
|
114
228
|
/**
|
|
115
229
|
* The status of the request.
|
|
116
230
|
*
|
|
@@ -3,14 +3,25 @@ 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
|
-
interface ErrorFeatures {
|
|
6
|
+
export interface ErrorFeatures {
|
|
7
7
|
isHidden: boolean;
|
|
8
8
|
isOnline: boolean;
|
|
9
9
|
retry: () => Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
type AutorefreshBehaviorType = "online" | "interval" | "invalid";
|
|
12
|
-
type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
|
|
13
|
-
|
|
11
|
+
export type AutorefreshBehaviorType = "online" | "interval" | "invalid";
|
|
12
|
+
export type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
|
|
13
|
+
/**
|
|
14
|
+
* Utilities to assist in recovering from the error.
|
|
15
|
+
*/
|
|
16
|
+
export interface RecoveryFeatures {
|
|
17
|
+
isOnline: boolean;
|
|
18
|
+
isHidden: boolean;
|
|
19
|
+
retry: () => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Utilities for keeping the request fresh
|
|
23
|
+
*/
|
|
24
|
+
export interface ContentFeatures<RT> {
|
|
14
25
|
isOnline: boolean;
|
|
15
26
|
isHidden: boolean;
|
|
16
27
|
isRefreshing: boolean;
|
|
@@ -18,7 +29,22 @@ type ContentFeatures<RT> = {
|
|
|
18
29
|
reload: () => Promise<void>;
|
|
19
30
|
abort?: () => void;
|
|
20
31
|
latestRequest?: Future<RT>;
|
|
21
|
-
}
|
|
32
|
+
}
|
|
33
|
+
export interface RequestArgs<
|
|
34
|
+
RT,
|
|
35
|
+
E
|
|
36
|
+
> extends SubscriptionArgs<RT, E> {
|
|
37
|
+
subscription?: RequestSubscription<RT, E>;
|
|
38
|
+
/**
|
|
39
|
+
* The store instance to use for making requests. If contexts are available,
|
|
40
|
+
* the component will default to using the `store` on the context.
|
|
41
|
+
*
|
|
42
|
+
* This is required if the store is not available via context or should be
|
|
43
|
+
* different from the store provided via context.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
store?: Store;
|
|
47
|
+
}
|
|
22
48
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
49
|
export interface SubscriptionArgs<
|
|
24
50
|
RT,
|
|
@@ -29,14 +55,14 @@ export interface SubscriptionArgs<
|
|
|
29
55
|
* by either the `store.request` or `store.requestManager.request` methods.
|
|
30
56
|
*
|
|
31
57
|
*/
|
|
32
|
-
request?: Future<RT
|
|
58
|
+
request?: Future<RT> | undefined | null;
|
|
33
59
|
/**
|
|
34
60
|
* A query to use for the request. This should be an object that can be
|
|
35
61
|
* passed to `store.request`. Use this in place of `@request` if you would
|
|
36
62
|
* like the component to also initiate the request.
|
|
37
63
|
*
|
|
38
64
|
*/
|
|
39
|
-
query?: StoreRequestInput<RT
|
|
65
|
+
query?: StoreRequestInput<RT> | undefined | null;
|
|
40
66
|
/**
|
|
41
67
|
* The autorefresh behavior for the request. This can be a boolean, or any
|
|
42
68
|
* combination of the following values: `'online'`, `'interval'`, `'invalid'`.
|
|
@@ -76,6 +102,20 @@ export interface SubscriptionArgs<
|
|
|
76
102
|
*/
|
|
77
103
|
autorefreshBehavior?: "refresh" | "reload" | "policy";
|
|
78
104
|
}
|
|
105
|
+
export interface RequestComponentArgs<
|
|
106
|
+
RT,
|
|
107
|
+
E
|
|
108
|
+
> extends SubscriptionArgs<RT, E> {
|
|
109
|
+
/**
|
|
110
|
+
* The store instance to use for making requests. If contexts are available,
|
|
111
|
+
* the component will default to using the `store` on the context.
|
|
112
|
+
*
|
|
113
|
+
* This is required if the store is not available via context or should be
|
|
114
|
+
* different from the store provided via context.
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
store?: Store | RequestManager;
|
|
118
|
+
}
|
|
79
119
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
120
|
export interface RequestSubscription<
|
|
81
121
|
RT,
|
|
@@ -227,6 +267,10 @@ export declare class RequestSubscription<
|
|
|
227
267
|
*/
|
|
228
268
|
private _maybeUpdate;
|
|
229
269
|
/**
|
|
270
|
+
* @internal
|
|
271
|
+
*/
|
|
272
|
+
private _getRequester;
|
|
273
|
+
/**
|
|
230
274
|
* Retry the request, reloading it from the server.
|
|
231
275
|
*/
|
|
232
276
|
retry: () => Promise<void>;
|
|
@@ -254,4 +298,3 @@ export declare function createRequestSubscription<
|
|
|
254
298
|
RT,
|
|
255
299
|
E
|
|
256
300
|
>(store: Store | RequestManager, args: SubscriptionArgs<RT, E>): RequestSubscription<RT, E>;
|
|
257
|
-
export {};
|
|
@@ -470,7 +470,7 @@ export declare class Store extends BaseClass {
|
|
|
470
470
|
* {@link CacheOptions.key | cache key} will have the request result
|
|
471
471
|
* and document cached.
|
|
472
472
|
*
|
|
473
|
-
* The cache key used is {@link RequestInfo.cacheOptions | RequestInfo.cacheOptions.key}
|
|
473
|
+
* The cache key used is {@link RequestInfo.cacheOptions.key | RequestInfo.cacheOptions.key}
|
|
474
474
|
* if present, falling back to {@link RequestInfo.url}.
|
|
475
475
|
*
|
|
476
476
|
* Params are not serialized as part of the cache-key, so
|
|
@@ -25,8 +25,8 @@ export type { StoreRequestInput } from "./-private/cache-handler/handler.js";
|
|
|
25
25
|
export { type LegacyManyArray, type LegacyManyArray as RelatedCollection, createLegacyManyArray } from "./-private/record-arrays/legacy-many-array.js";
|
|
26
26
|
export { log, logGroup } from "./-private/debug/utils.js";
|
|
27
27
|
export { getPromiseState, type PromiseState } from "./-private/new-core-tmp/promise-state.js";
|
|
28
|
-
export { DISPOSE, createRequestSubscription, type SubscriptionArgs, type RequestSubscription } from "./-private/new-core-tmp/request-subscription.js";
|
|
28
|
+
export { DISPOSE, createRequestSubscription, type RequestArgs, type SubscriptionArgs, type RequestComponentArgs, type RequestSubscription, type ContentFeatures, type RecoveryFeatures, type AutorefreshBehaviorCombos, type AutorefreshBehaviorType } from "./-private/new-core-tmp/request-subscription.js";
|
|
29
29
|
export { getRequestState, type RequestLoadingState, type RequestCacheRequestState as RequestState } from "./-private/new-core-tmp/request-state.js";
|
|
30
30
|
export { createMemo, type SignalHooks, waitFor } from "./-private/new-core-tmp/reactivity/configure.js";
|
|
31
|
-
export { memoized, gate, entangleSignal, defineSignal, defineGate, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
|
|
31
|
+
export { signal, memoized, gate, entangleSignal, defineSignal, defineGate, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
|
|
32
32
|
export { ARRAY_SIGNAL, OBJECT_SIGNAL, Signals, type WarpDriveSignal, peekInternalSignal, withSignalStore, notifyInternalSignal, consumeInternalSignal, getOrCreateInternalSignal } from "./-private/new-core-tmp/reactivity/internal.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { Store } from "../store/-private.js";
|
|
1
2
|
import type { ResourceKey } from "./identifier.js";
|
|
2
3
|
import type { QueryParamsSerializationOptions } from "./params.js";
|
|
3
4
|
import type { TypeFromInstanceOrString } from "./record.js";
|
|
4
5
|
import type { ResourceIdentifierObject } from "./spec/json-api-raw.js";
|
|
5
6
|
import type { RequestSignature } from "./symbols.js";
|
|
6
|
-
type Store = unknown;
|
|
7
7
|
export declare const SkipCache: "___(unique) Symbol(SkipCache)";
|
|
8
8
|
export declare const EnableHydration: "___(unique) Symbol(EnableHydration)";
|
|
9
9
|
export declare const IS_FUTURE: "___(unique) Symbol(IS_FUTURE)";
|
|
@@ -199,12 +199,17 @@ export interface StructuredErrorDocument<T = unknown> extends Error {
|
|
|
199
199
|
*/
|
|
200
200
|
export type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument<T>;
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
202
|
+
* The {@link RequestInit} interface accepted by the native {@link fetch} API.
|
|
203
203
|
*
|
|
204
204
|
* WarpDrive provides our own typings due to incompleteness in the native typings.
|
|
205
205
|
*
|
|
206
|
+
* @privateRemarks
|
|
207
|
+
* - [MDN Reference (fetch)](https://developer.mozilla.org/docs/Web/API/Window/fetch)
|
|
208
|
+
* - [MDN Reference (RequestInit)](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
209
|
+
* - [MDN Reference (Request)](https://developer.mozilla.org/docs/Web/API/Request)
|
|
210
|
+
*
|
|
206
211
|
*/
|
|
207
|
-
interface
|
|
212
|
+
interface NativeRequestInit {
|
|
208
213
|
/** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
|
|
209
214
|
*/
|
|
210
215
|
cache?: RequestCache;
|
|
@@ -264,11 +269,21 @@ export interface ImmutableHeaders extends Headers {
|
|
|
264
269
|
toJSON(): [string, string][];
|
|
265
270
|
}
|
|
266
271
|
/**
|
|
267
|
-
* Extends JavaScript's native {@link
|
|
268
|
-
* properties specific to the RequestManager's capabilities.
|
|
272
|
+
* Extends JavaScript's native {@link fetch} {@link NativeRequestInit | RequestInit} with additional
|
|
273
|
+
* properties specific to the {@link RequestManager | RequestManager's} capabilities.
|
|
274
|
+
*
|
|
275
|
+
* This interface is used to define the shape of a request that can be made via
|
|
276
|
+
* either the {@link RequestManager.request} or {@link Store.request} methods.
|
|
277
|
+
*
|
|
278
|
+
* @privateRemarks
|
|
279
|
+
* - [MDN Reference (fetch)](https://developer.mozilla.org/docs/Web/API/Window/fetch)
|
|
280
|
+
* - [MDN Reference (RequestInit)](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
281
|
+
* - [MDN Reference (Request)](https://developer.mozilla.org/docs/Web/API/Request)
|
|
269
282
|
*
|
|
283
|
+
* @public
|
|
284
|
+
* @since 4.12
|
|
270
285
|
*/
|
|
271
|
-
export interface RequestInfo<RT = unknown> extends
|
|
286
|
+
export interface RequestInfo<RT = unknown> extends NativeRequestInit {
|
|
272
287
|
/**
|
|
273
288
|
* If provided, used instead of the AbortController auto-configured for each request by the RequestManager
|
|
274
289
|
*
|
|
@@ -281,7 +296,7 @@ export interface RequestInfo<RT = unknown> extends Request {
|
|
|
281
296
|
store?: Store;
|
|
282
297
|
op?: string;
|
|
283
298
|
/**
|
|
284
|
-
* The
|
|
299
|
+
* The {@link ResourceKey | ResourceKeys} of the primary resources involved in the request
|
|
285
300
|
* (if any). This may be used by handlers to perform transactional
|
|
286
301
|
* operations on the store.
|
|
287
302
|
*
|
|
@@ -298,7 +313,7 @@ export interface RequestInfo<RT = unknown> extends Request {
|
|
|
298
313
|
*/
|
|
299
314
|
data?: Record<string, unknown>;
|
|
300
315
|
/**
|
|
301
|
-
* options specifically intended for
|
|
316
|
+
* options specifically intended for {@link Handler | Handlers}
|
|
302
317
|
* to utilize to process the request
|
|
303
318
|
*
|
|
304
319
|
*/
|
|
@@ -450,6 +450,7 @@ function upgradePromise(promise, future) {
|
|
|
450
450
|
promise.onFinalize = future.onFinalize;
|
|
451
451
|
promise.id = future.id;
|
|
452
452
|
promise.lid = future.lid;
|
|
453
|
+
promise.requester = future.requester;
|
|
453
454
|
return promise;
|
|
454
455
|
}
|
|
455
456
|
function createFuture(owner) {
|
|
@@ -477,6 +478,7 @@ function createFuture(owner) {
|
|
|
477
478
|
};
|
|
478
479
|
promise.id = owner.requestId;
|
|
479
480
|
promise.lid = owner.god.identifier;
|
|
481
|
+
promise.requester = owner.god.requester;
|
|
480
482
|
deferred.promise = promise;
|
|
481
483
|
return deferred;
|
|
482
484
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { setLogging, getRuntimeConfig } from './types/runtime.js';
|
|
2
|
-
import { a as cloneResponseProperties, I as IS_CACHE_HANDLER, b as assertValidRequest, e as executeNextHandler, d as getRequestResult, u as upgradePromise, s as setPromiseResult, f as clearRequestResult } from "./context-
|
|
2
|
+
import { a as cloneResponseProperties, I as IS_CACHE_HANDLER, b as assertValidRequest, e as executeNextHandler, d as getRequestResult, u as upgradePromise, s as setPromiseResult, f as clearRequestResult } from "./context-BNZebmoO.js";
|
|
3
3
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
4
4
|
import { w as waitFor } from "./configure-B48bFHOl.js";
|
|
5
5
|
import { peekUniversalTransient, setUniversalTransient } from './types/-private.js';
|
|
6
|
-
|
|
6
|
+
import { EnableHydration } from './types/request.js';
|
|
7
|
+
export { C as CacheHandler, S as Store, r as recordIdentifierFor, N as setIdentifierForgetMethod, L as setIdentifierGenerationMethod, O as setIdentifierResetMethod, M as setIdentifierUpdateMethod, P as setKeyInfoForResource, s as storeFor } from "./request-state-XxA7ZVps.js";
|
|
7
8
|
import '@ember/debug';
|
|
8
9
|
import './utils/string.js';
|
|
9
10
|
import "./symbols-sql1_mdx.js";
|
|
@@ -187,6 +188,7 @@ function isDict(v) {
|
|
|
187
188
|
return v !== null && typeof v === 'object';
|
|
188
189
|
}
|
|
189
190
|
class RequestManager {
|
|
191
|
+
/** @internal */
|
|
190
192
|
#handlers = [];
|
|
191
193
|
/** @internal */
|
|
192
194
|
|
|
@@ -239,8 +241,6 @@ class RequestManager {
|
|
|
239
241
|
* curry the request, or pass along a modified request.
|
|
240
242
|
*
|
|
241
243
|
* @public
|
|
242
|
-
* @param {Handler[]} newHandlers
|
|
243
|
-
* @return {ThisType}
|
|
244
244
|
*/
|
|
245
245
|
use(newHandlers) {
|
|
246
246
|
const handlers = this.#handlers;
|
|
@@ -267,8 +267,6 @@ class RequestManager {
|
|
|
267
267
|
* Returns a Future that fulfills with a StructuredDocument
|
|
268
268
|
*
|
|
269
269
|
* @public
|
|
270
|
-
* @param {RequestInfo} request
|
|
271
|
-
* @return {Future}
|
|
272
270
|
*/
|
|
273
271
|
request(request) {
|
|
274
272
|
const handlers = this.#handlers;
|
|
@@ -290,7 +288,8 @@ class RequestManager {
|
|
|
290
288
|
stream: null,
|
|
291
289
|
hasRequestedStream: false,
|
|
292
290
|
id: requestId,
|
|
293
|
-
identifier: null
|
|
291
|
+
identifier: null,
|
|
292
|
+
requester: request[EnableHydration] && request.store ? request.store : this
|
|
294
293
|
};
|
|
295
294
|
const promise = executeNextHandler(handlers, request, 0, context);
|
|
296
295
|
|
package/dist/reactive.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { G as ReactiveResource, H as isNonIdentityCacheableField, I as getFieldCacheKeyStrict, r as recordIdentifierFor, A as withSignalStore } from "./request-state-XxA7ZVps.js";
|
|
2
|
+
export { J as checkout, K as commit } from "./request-state-XxA7ZVps.js";
|
|
3
3
|
import { isResourceSchema } from './types/schema/fields.js';
|
|
4
4
|
import { D as Destroy, C as Context } from "./symbols-sql1_mdx.js";
|
|
5
5
|
export { a as Checkout } from "./symbols-sql1_mdx.js";
|
|
@@ -589,6 +589,13 @@ class SchemaService {
|
|
|
589
589
|
})(kinds[kind]) : {};
|
|
590
590
|
return kinds[kind];
|
|
591
591
|
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Registers a {@link HashFn} for use with a {@link HashField} for
|
|
595
|
+
* either {@link ObjectSchema} identity or polymorphic type calculation.
|
|
596
|
+
*
|
|
597
|
+
* @public
|
|
598
|
+
*/
|
|
592
599
|
registerHashFn(hashFn) {
|
|
593
600
|
this._hashFns.set(hashFn[Type], hashFn);
|
|
594
601
|
}
|
|
@@ -7,8 +7,21 @@ import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_KEY_TYPE, DEBUG_CLIENT_ORIG
|
|
|
7
7
|
import { dasherize } from './utils/string.js';
|
|
8
8
|
import { S as SOURCE, C as Context, D as Destroy, a as Checkout, b as Commit } from "./symbols-sql1_mdx.js";
|
|
9
9
|
import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, d as willSyncFlushWatchers } from "./configure-B48bFHOl.js";
|
|
10
|
-
import { g as getPromiseResult, s as setPromiseResult } from "./context-
|
|
10
|
+
import { g as getPromiseResult, s as setPromiseResult } from "./context-BNZebmoO.js";
|
|
11
11
|
import { RecordStore } from './types/symbols.js';
|
|
12
|
+
const INITIALIZER_PROTO = {
|
|
13
|
+
isInitializer: true
|
|
14
|
+
};
|
|
15
|
+
function makeInitializer(fn) {
|
|
16
|
+
// we use a prototype to ensure that the initializer is not enumerable
|
|
17
|
+
// and does not interfere with the signal's value.
|
|
18
|
+
return Object.assign(Object.create(INITIALIZER_PROTO), {
|
|
19
|
+
value: fn
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function isInitializer(obj) {
|
|
23
|
+
return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === INITIALIZER_PROTO;
|
|
24
|
+
}
|
|
12
25
|
|
|
13
26
|
/**
|
|
14
27
|
* A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
|
|
@@ -95,7 +108,7 @@ function createInternalSignal(signals, obj, key, initialValue) {
|
|
|
95
108
|
key,
|
|
96
109
|
context: obj,
|
|
97
110
|
signal: createSignal(obj, key),
|
|
98
|
-
value: initialValue,
|
|
111
|
+
value: isInitializer(initialValue) ? initialValue.value.call(obj) : initialValue,
|
|
99
112
|
isStale: false
|
|
100
113
|
};
|
|
101
114
|
signals.set(key, warpDriveSignal);
|
|
@@ -121,12 +134,12 @@ function notifyInternalSignal(signal) {
|
|
|
121
134
|
}
|
|
122
135
|
}
|
|
123
136
|
function entangleSignal(signals, obj, key, initialValue) {
|
|
124
|
-
let
|
|
125
|
-
if (!
|
|
126
|
-
|
|
137
|
+
let internalSignal = peekInternalSignal(signals, key);
|
|
138
|
+
if (!internalSignal) {
|
|
139
|
+
internalSignal = createInternalSignal(signals, obj, key, initialValue);
|
|
127
140
|
}
|
|
128
|
-
consumeInternalSignal(
|
|
129
|
-
return
|
|
141
|
+
consumeInternalSignal(internalSignal);
|
|
142
|
+
return internalSignal;
|
|
130
143
|
}
|
|
131
144
|
function createSignalDescriptor(key, intialValue) {
|
|
132
145
|
return {
|
|
@@ -138,10 +151,10 @@ function createSignalDescriptor(key, intialValue) {
|
|
|
138
151
|
},
|
|
139
152
|
set(value) {
|
|
140
153
|
const signals = withSignalStore(this);
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
notifyInternalSignal(
|
|
154
|
+
const internalSignal = getOrCreateInternalSignal(signals, this, key, intialValue);
|
|
155
|
+
if (internalSignal.value !== value) {
|
|
156
|
+
internalSignal.value = value;
|
|
157
|
+
notifyInternalSignal(internalSignal);
|
|
145
158
|
}
|
|
146
159
|
}
|
|
147
160
|
};
|
|
@@ -171,6 +184,27 @@ function defineNonEnumerableSignal(obj, key, v) {
|
|
|
171
184
|
desc.enumerable = false;
|
|
172
185
|
Object.defineProperty(obj, key, desc);
|
|
173
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Decorator version of creating a signal.
|
|
189
|
+
*/
|
|
190
|
+
function signal(target, key, descriptor) {
|
|
191
|
+
// Error on `@signal()`, `@signal(...args)``
|
|
192
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
193
|
+
if (!test) {
|
|
194
|
+
throw new Error('You attempted to use @signal(), which is not necessary nor supported. Remove the parentheses and you will be good to go!');
|
|
195
|
+
}
|
|
196
|
+
})(target !== undefined) : {};
|
|
197
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
198
|
+
if (!test) {
|
|
199
|
+
throw new Error(`You attempted to use @signal on with ${arguments.length > 1 ? 'arguments' : 'an argument'} ( @signal(${Array.from(arguments).map(d => `'${d}'`).join(', ')}) ), which is not supported. Dependencies are automatically tracked, so you can just use ${'`@signal`'}`);
|
|
200
|
+
}
|
|
201
|
+
})(typeof target === 'object' && typeof key === 'string' && typeof descriptor === 'object' && arguments.length === 3) : {};
|
|
202
|
+
return createSignalDescriptor(key, descriptor.initializer ? makeInitializer(descriptor.initializer) : null);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Decorator version of creating a memoized getter
|
|
207
|
+
*/
|
|
174
208
|
function memoized(target, key, descriptor) {
|
|
175
209
|
// Error on `@memoized()`, `@memoized(...args)`, and `@memoized propName = value;`
|
|
176
210
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -202,6 +236,10 @@ function memoized(target, key, descriptor) {
|
|
|
202
236
|
};
|
|
203
237
|
return descriptor;
|
|
204
238
|
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Decorator version of creating a gate.
|
|
242
|
+
*/
|
|
205
243
|
function gate(_target, key, desc) {
|
|
206
244
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
207
245
|
const getter = desc.get;
|
|
@@ -210,34 +248,34 @@ function gate(_target, key, desc) {
|
|
|
210
248
|
const isLocal = desc.isLocal;
|
|
211
249
|
desc.get = function () {
|
|
212
250
|
const signals = withSignalStore(this);
|
|
213
|
-
let
|
|
214
|
-
if (!
|
|
215
|
-
|
|
216
|
-
} else if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
consumeInternalSignal(
|
|
221
|
-
return
|
|
251
|
+
let internalSignal = peekInternalSignal(signals, key);
|
|
252
|
+
if (!internalSignal) {
|
|
253
|
+
internalSignal = createInternalSignal(signals, this, key, getter.call(this));
|
|
254
|
+
} else if (internalSignal.isStale) {
|
|
255
|
+
internalSignal.isStale = false;
|
|
256
|
+
internalSignal.value = getter.call(this);
|
|
257
|
+
}
|
|
258
|
+
consumeInternalSignal(internalSignal);
|
|
259
|
+
return internalSignal.value;
|
|
222
260
|
};
|
|
223
261
|
if (setter) {
|
|
224
262
|
desc.set = function (v) {
|
|
225
263
|
const signals = withSignalStore(this);
|
|
226
|
-
let
|
|
227
|
-
if (!
|
|
264
|
+
let internalSignal = peekInternalSignal(signals, key);
|
|
265
|
+
if (!internalSignal) {
|
|
228
266
|
// we can't use `v` as initialValue here because setters don't
|
|
229
267
|
// return the value and the final value may be different
|
|
230
268
|
// than what the setter was called with.
|
|
231
|
-
|
|
232
|
-
|
|
269
|
+
internalSignal = createInternalSignal(signals, this, key, undefined);
|
|
270
|
+
internalSignal.isStale = true;
|
|
233
271
|
}
|
|
234
272
|
setter.call(this, v);
|
|
235
273
|
// when a gate is set, we do not notify the signal
|
|
236
274
|
// as its update is controlled externally.
|
|
237
275
|
// unless it specifically sets itself to be locally managed
|
|
238
276
|
if (isLocal) {
|
|
239
|
-
|
|
240
|
-
notifyInternalSignal(
|
|
277
|
+
internalSignal.isStale = true;
|
|
278
|
+
notifyInternalSignal(internalSignal);
|
|
241
279
|
}
|
|
242
280
|
};
|
|
243
281
|
}
|
|
@@ -6645,7 +6683,7 @@ class Store extends BaseClass {
|
|
|
6645
6683
|
* {@link CacheOptions.key | cache key} will have the request result
|
|
6646
6684
|
* and document cached.
|
|
6647
6685
|
*
|
|
6648
|
-
* The cache key used is {@link RequestInfo.cacheOptions | RequestInfo.cacheOptions.key}
|
|
6686
|
+
* The cache key used is {@link RequestInfo.cacheOptions.key | RequestInfo.cacheOptions.key}
|
|
6649
6687
|
* if present, falling back to {@link RequestInfo.url}.
|
|
6650
6688
|
*
|
|
6651
6689
|
* Params are not serialized as part of the cache-key, so
|
|
@@ -9048,6 +9086,14 @@ function isNeverString(val) {
|
|
|
9048
9086
|
return val;
|
|
9049
9087
|
}
|
|
9050
9088
|
|
|
9089
|
+
/**
|
|
9090
|
+
* Utilities to assist in recovering from the error.
|
|
9091
|
+
*/
|
|
9092
|
+
|
|
9093
|
+
/**
|
|
9094
|
+
* Utilities for keeping the request fresh
|
|
9095
|
+
*/
|
|
9096
|
+
|
|
9051
9097
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9052
9098
|
|
|
9053
9099
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -9269,14 +9315,12 @@ class RequestSubscription {
|
|
|
9269
9315
|
this._removeSubscriptions();
|
|
9270
9316
|
|
|
9271
9317
|
// if we have a request, we need to subscribe to it
|
|
9272
|
-
const
|
|
9273
|
-
store
|
|
9274
|
-
} = this;
|
|
9318
|
+
const store = this._getRequester();
|
|
9275
9319
|
if (requestId && isStore(store)) {
|
|
9276
9320
|
this._subscribedTo = requestId;
|
|
9277
9321
|
this._subscription = store.notifications.subscribe(requestId, (_id, op) => {
|
|
9278
9322
|
// ignore subscription events that occur while our own component's request
|
|
9279
|
-
// is
|
|
9323
|
+
// is occurring
|
|
9280
9324
|
if (this._isUpdating) {
|
|
9281
9325
|
return;
|
|
9282
9326
|
}
|
|
@@ -9345,8 +9389,9 @@ class RequestSubscription {
|
|
|
9345
9389
|
* @internal
|
|
9346
9390
|
*/
|
|
9347
9391
|
_removeSubscriptions() {
|
|
9348
|
-
|
|
9349
|
-
|
|
9392
|
+
const store = this._getRequester();
|
|
9393
|
+
if (this._subscription && isStore(store)) {
|
|
9394
|
+
store.notifications.unsubscribe(this._subscription);
|
|
9350
9395
|
this._subscribedTo = null;
|
|
9351
9396
|
this._subscription = null;
|
|
9352
9397
|
}
|
|
@@ -9411,6 +9456,12 @@ class RequestSubscription {
|
|
|
9411
9456
|
if (this.isIdle) {
|
|
9412
9457
|
return;
|
|
9413
9458
|
}
|
|
9459
|
+
const {
|
|
9460
|
+
reqState
|
|
9461
|
+
} = this;
|
|
9462
|
+
if (reqState.isPending) {
|
|
9463
|
+
return;
|
|
9464
|
+
}
|
|
9414
9465
|
const canAttempt = Boolean(this.isOnline && !this.isHidden && (mode || this.autorefreshTypes.size));
|
|
9415
9466
|
if (!canAttempt) {
|
|
9416
9467
|
if (!silent && mode && mode !== '_invalidated') {
|
|
@@ -9447,35 +9498,26 @@ class RequestSubscription {
|
|
|
9447
9498
|
this._invalidated = false;
|
|
9448
9499
|
if (shouldAttempt) {
|
|
9449
9500
|
this._clearInterval();
|
|
9450
|
-
|
|
9501
|
+
this._isUpdating = true;
|
|
9451
9502
|
const realMode = mode === '_invalidated' ? null : mode;
|
|
9452
9503
|
const val = realMode ?? this._args.autorefreshBehavior ?? 'policy';
|
|
9453
9504
|
switch (val) {
|
|
9454
9505
|
case 'reload':
|
|
9455
|
-
|
|
9456
|
-
reload: true
|
|
9457
|
-
});
|
|
9506
|
+
this._latestRequest = reqState.reload();
|
|
9458
9507
|
break;
|
|
9459
9508
|
case 'refresh':
|
|
9460
|
-
|
|
9461
|
-
backgroundReload: true
|
|
9462
|
-
});
|
|
9509
|
+
this._latestRequest = reqState.refresh();
|
|
9463
9510
|
break;
|
|
9464
9511
|
case 'policy':
|
|
9512
|
+
this._latestRequest = reqState.refresh(true);
|
|
9465
9513
|
break;
|
|
9466
9514
|
default:
|
|
9467
|
-
|
|
9515
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
9516
|
+
{
|
|
9517
|
+
throw new Error(`Invalid ${mode ? 'update mode' : '@autorefreshBehavior'} for <Request />: ${isNeverString(val)}`);
|
|
9518
|
+
}
|
|
9519
|
+
})() : {};
|
|
9468
9520
|
}
|
|
9469
|
-
const wasStoreRequest = request[EnableHydration] === true;
|
|
9470
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
9471
|
-
if (!test) {
|
|
9472
|
-
throw new Error(`Cannot supply a different store than was used to create the request`);
|
|
9473
|
-
}
|
|
9474
|
-
})(!request.store || request.store === this.store) : {};
|
|
9475
|
-
const store = request.store || this.store;
|
|
9476
|
-
const requester = !wasStoreRequest && 'requestManager' in store ? store.requestManager : store;
|
|
9477
|
-
this._isUpdating = true;
|
|
9478
|
-
this._latestRequest = requester.request(request);
|
|
9479
9521
|
if (val !== 'refresh') {
|
|
9480
9522
|
this._localRequest = this._latestRequest;
|
|
9481
9523
|
}
|
|
@@ -9486,6 +9528,16 @@ class RequestSubscription {
|
|
|
9486
9528
|
}
|
|
9487
9529
|
}
|
|
9488
9530
|
|
|
9531
|
+
/**
|
|
9532
|
+
* @internal
|
|
9533
|
+
*/
|
|
9534
|
+
_getRequester() {
|
|
9535
|
+
if (this._args.request) {
|
|
9536
|
+
return this._args.request.requester;
|
|
9537
|
+
}
|
|
9538
|
+
return this.store;
|
|
9539
|
+
}
|
|
9540
|
+
|
|
9489
9541
|
/**
|
|
9490
9542
|
* Retry the request, reloading it from the server.
|
|
9491
9543
|
*/
|
|
@@ -9573,7 +9625,6 @@ class RequestSubscription {
|
|
|
9573
9625
|
throw new Error(`You must provide either @request or an @query arg with the <Request> component`);
|
|
9574
9626
|
}
|
|
9575
9627
|
})(query) : {};
|
|
9576
|
-
// @ts-expect-error TODO investigate this
|
|
9577
9628
|
return this.store.request(query);
|
|
9578
9629
|
}
|
|
9579
9630
|
static {
|
|
@@ -9710,6 +9761,7 @@ async function watchStream(stream, loadingState) {
|
|
|
9710
9761
|
* reactive properties that can be used to build UIs that respond
|
|
9711
9762
|
* to the progress of a request.
|
|
9712
9763
|
*
|
|
9764
|
+
* @hideconstructor
|
|
9713
9765
|
*/
|
|
9714
9766
|
class RequestLoadingState {
|
|
9715
9767
|
_stream = null;
|
|
@@ -9900,6 +9952,24 @@ defineNonEnumerableSignal(RequestLoadingState.prototype, '_lastPacketTime', 0);
|
|
|
9900
9952
|
*/
|
|
9901
9953
|
|
|
9902
9954
|
const RequestStateProto = {};
|
|
9955
|
+
function performRefresh(requester, request, isReload) {
|
|
9956
|
+
const req = Object.assign({}, request);
|
|
9957
|
+
const cacheOptions = Object.assign({}, req.cacheOptions);
|
|
9958
|
+
if (isReload) {
|
|
9959
|
+
// force direct to network
|
|
9960
|
+
cacheOptions.reload = true;
|
|
9961
|
+
} else if (isReload === false) {
|
|
9962
|
+
// delete reload to ensure we use backgroundReload / policy
|
|
9963
|
+
delete cacheOptions.reload;
|
|
9964
|
+
cacheOptions.backgroundReload = true;
|
|
9965
|
+
} else {
|
|
9966
|
+
// delete props to ensure we use the policy
|
|
9967
|
+
delete cacheOptions.backgroundReload;
|
|
9968
|
+
delete cacheOptions.reload;
|
|
9969
|
+
}
|
|
9970
|
+
req.cacheOptions = cacheOptions;
|
|
9971
|
+
return requester.request(req);
|
|
9972
|
+
}
|
|
9903
9973
|
|
|
9904
9974
|
// TODO introduce a new mechanism for defining multiple properties
|
|
9905
9975
|
// that share a common signal
|
|
@@ -9931,6 +10001,25 @@ function createRequestState(future) {
|
|
|
9931
10001
|
const state = getPromiseResult(future);
|
|
9932
10002
|
const promiseState = Object.create(RequestStateProto);
|
|
9933
10003
|
promiseState._request = future;
|
|
10004
|
+
// @ts-expect-error - we still attach it for PendingState
|
|
10005
|
+
promiseState.reload = () => {
|
|
10006
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
10007
|
+
if (!test) {
|
|
10008
|
+
throw new Error(`Cannot reload a request that is still pending. Await or abort the original request first.`);
|
|
10009
|
+
}
|
|
10010
|
+
})(!promiseState.isPending) : {};
|
|
10011
|
+
return performRefresh(future.requester, promiseState.request, true);
|
|
10012
|
+
};
|
|
10013
|
+
|
|
10014
|
+
// @ts-expect-error - we still attach it for PendingState
|
|
10015
|
+
promiseState.refresh = (usePolicy = false) => {
|
|
10016
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
10017
|
+
if (!test) {
|
|
10018
|
+
throw new Error(`Cannot refresh a request that is still pending. Await or abort the original request first.`);
|
|
10019
|
+
}
|
|
10020
|
+
})(!promiseState.isPending) : {};
|
|
10021
|
+
return performRefresh(future.requester, promiseState.request, usePolicy === true ? null : false);
|
|
10022
|
+
};
|
|
9934
10023
|
if (state) {
|
|
9935
10024
|
if (state.isError) {
|
|
9936
10025
|
promiseState.error = state.result;
|
|
@@ -10041,4 +10130,4 @@ function getRequestState(future) {
|
|
|
10041
10130
|
}
|
|
10042
10131
|
return state;
|
|
10043
10132
|
}
|
|
10044
|
-
export {
|
|
10133
|
+
export { withSignalStore as A, notifyInternalSignal as B, CacheHandler as C, DISPOSE as D, consumeInternalSignal as E, getOrCreateInternalSignal as F, ReactiveResource as G, isNonIdentityCacheableField as H, getFieldCacheKeyStrict as I, checkout as J, commit as K, setIdentifierGenerationMethod as L, setIdentifierUpdateMethod as M, setIdentifierForgetMethod as N, setIdentifierResetMethod as O, setKeyInfoForResource as P, RecordArrayManager as R, Store as S, _clearCaches as _, isRequestKey as a, coerceId as b, constructResource as c, setRecordIdentifier as d, ensureStringId as e, fastPush as f, StoreMap as g, createLegacyManyArray as h, isResourceKey as i, logGroup as j, getPromiseState as k, log as l, createRequestSubscription as m, normalizeModelName as n, getRequestState as o, signal as p, memoized as q, recordIdentifierFor as r, storeFor as s, gate as t, entangleSignal as u, defineSignal as v, defineGate as w, defineNonEnumerableSignal as x, Signals as y, peekInternalSignal as z };
|
package/dist/request.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./context-
|
|
1
|
+
export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./context-BNZebmoO.js";
|
package/dist/store/-private.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager,
|
|
1
|
+
export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager, y as Signals, S as Store, g as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, b as coerceId, c as constructResource, E as consumeInternalSignal, h as createLegacyManyArray, m as createRequestSubscription, w as defineGate, x as defineNonEnumerableSignal, v as defineSignal, e as ensureStringId, u as entangleSignal, f as fastPush, t as gate, F as getOrCreateInternalSignal, k as getPromiseState, o as getRequestState, a as isRequestKey, i as isResourceKey, l as log, j as logGroup, q as memoized, B as notifyInternalSignal, z as peekInternalSignal, r as recordIdentifierFor, d as setRecordIdentifier, p as signal, s as storeFor, A as withSignalStore } from "../request-state-XxA7ZVps.js";
|
|
2
2
|
export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo, w as waitFor } from "../configure-B48bFHOl.js";
|
package/dist/types/-private.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
2
2
|
const name = "@warp-drive/core";
|
|
3
|
-
const version = "5.7.0-alpha.
|
|
3
|
+
const version = "5.7.0-alpha.25";
|
|
4
4
|
|
|
5
5
|
// in testing mode, we utilize globals to ensure only one copy exists of
|
|
6
6
|
// these maps, due to bugs in ember-auto-import
|
package/dist/types/request.js
CHANGED
|
@@ -37,16 +37,31 @@ const STRUCTURED = getOrSetGlobal('DOC', Symbol('DOC'));
|
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* The {@link RequestInit} interface accepted by the native {@link fetch} API.
|
|
41
41
|
*
|
|
42
42
|
* WarpDrive provides our own typings due to incompleteness in the native typings.
|
|
43
43
|
*
|
|
44
|
+
* @privateRemarks
|
|
45
|
+
* - [MDN Reference (fetch)](https://developer.mozilla.org/docs/Web/API/Window/fetch)
|
|
46
|
+
* - [MDN Reference (RequestInit)](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
47
|
+
* - [MDN Reference (Request)](https://developer.mozilla.org/docs/Web/API/Request)
|
|
48
|
+
*
|
|
44
49
|
*/
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
|
-
* Extends JavaScript's native {@link
|
|
48
|
-
* properties specific to the RequestManager's capabilities.
|
|
52
|
+
* Extends JavaScript's native {@link fetch} {@link NativeRequestInit | RequestInit} with additional
|
|
53
|
+
* properties specific to the {@link RequestManager | RequestManager's} capabilities.
|
|
54
|
+
*
|
|
55
|
+
* This interface is used to define the shape of a request that can be made via
|
|
56
|
+
* either the {@link RequestManager.request} or {@link Store.request} methods.
|
|
57
|
+
*
|
|
58
|
+
* @privateRemarks
|
|
59
|
+
* - [MDN Reference (fetch)](https://developer.mozilla.org/docs/Web/API/Window/fetch)
|
|
60
|
+
* - [MDN Reference (RequestInit)](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)
|
|
61
|
+
* - [MDN Reference (Request)](https://developer.mozilla.org/docs/Web/API/Request)
|
|
49
62
|
*
|
|
63
|
+
* @public
|
|
64
|
+
* @since 4.12
|
|
50
65
|
*/
|
|
51
66
|
|
|
52
67
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/core",
|
|
3
|
-
"version": "5.7.0-alpha.
|
|
3
|
+
"version": "5.7.0-alpha.25",
|
|
4
4
|
"description": "Core package for WarpDrive | All the Universal Basics",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@embroider/macros": "^1.16.12",
|
|
40
|
-
"@warp-drive/build-config": "5.7.0-alpha.
|
|
40
|
+
"@warp-drive/build-config": "5.7.0-alpha.25"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/core": "^7.26.10",
|
|
44
44
|
"@babel/plugin-transform-typescript": "^7.27.0",
|
|
45
45
|
"@babel/preset-typescript": "^7.27.0",
|
|
46
|
-
"@warp-drive/internal-config": "5.7.0-alpha.
|
|
46
|
+
"@warp-drive/internal-config": "5.7.0-alpha.25",
|
|
47
47
|
"decorator-transforms": "^2.3.0",
|
|
48
48
|
"ember-source": "~6.3.0",
|
|
49
49
|
"expect-type": "^1.2.1",
|