@warp-drive/core 5.8.0-alpha.40 → 5.8.0-alpha.41
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/configure.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +1 -1
- package/declarations/reactive/-private/fields/extension.d.ts +1 -1
- package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
- package/declarations/reactive/-private/fields/managed-object.d.ts +1 -1
- package/declarations/reactive.d.ts +2 -3
- package/declarations/signals/-leaked.d.ts +2 -0
- package/declarations/signals/-private.d.ts +6 -0
- package/declarations/{store/-private/new-core-tmp → signals}/promise-state.d.ts +1 -1
- package/declarations/{store/-private/new-core-tmp → signals}/request-state.d.ts +5 -5
- package/declarations/{store/-private/new-core-tmp → signals}/request-subscription.d.ts +4 -4
- package/declarations/store/-private/cache-handler/types.d.ts +2 -16
- package/declarations/store/-private/managers/cache-manager.d.ts +1 -14
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +1 -1
- package/declarations/store/-private/record-arrays/resource-array.d.ts +1 -1
- package/declarations/store/-private.d.ts +0 -5
- package/declarations/store/deprecated/-private.d.ts +1 -1
- package/declarations/types/schema/fields.d.ts +4 -4
- package/dist/configure-DPUFCemT.js +1940 -0
- package/dist/configure.js +2 -1
- package/dist/{request-oqoLC9rz.js → future-BKkJJkj7.js} +1 -48
- package/dist/graph/-private.js +3 -2
- package/dist/{index-BKcD4JZK.js → index-CQP2NSqg.js} +58 -1826
- package/dist/index.js +5 -5
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +4 -129
- package/dist/request.js +49 -1
- package/dist/signals/-leaked.js +1 -0
- package/dist/store/-private.js +1 -2
- package/dist/types/-private.js +1 -1
- package/dist/unpkg/dev/-leaked-Co0EI6Go.js +1939 -0
- package/dist/unpkg/dev/configure.js +1 -1
- package/dist/unpkg/dev/{request-CA9K0gXq.js → future-DFfOzSoe.js} +1 -48
- package/dist/unpkg/dev/graph/-private.js +3 -2
- package/dist/unpkg/dev/{index-DqhXrNZ_.js → index-CepUPZlc.js} +57 -1825
- package/dist/unpkg/dev/index.js +4 -4
- package/dist/unpkg/dev/reactive/-private.js +1 -1
- package/dist/unpkg/dev/reactive.js +3 -127
- package/dist/unpkg/dev/request.js +49 -1
- package/dist/unpkg/dev/signals/-leaked.js +1 -0
- package/dist/unpkg/dev/store/-private.js +2 -3
- package/dist/unpkg/dev/types/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/-leaked-DjMeRqdU.js +1939 -0
- package/dist/unpkg/dev-deprecated/configure.js +1 -1
- package/dist/unpkg/dev-deprecated/{request-CA9K0gXq.js → future-DFfOzSoe.js} +1 -48
- package/dist/unpkg/dev-deprecated/graph/-private.js +3 -2
- package/dist/unpkg/dev-deprecated/{index-BBlq5is_.js → index-C_EEmn_3.js} +56 -1824
- package/dist/unpkg/dev-deprecated/index.js +2 -2
- package/dist/unpkg/dev-deprecated/reactive.js +2 -126
- package/dist/unpkg/dev-deprecated/request.js +49 -1
- package/dist/unpkg/dev-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/dev-deprecated/store/-private.js +1 -2
- package/dist/unpkg/dev-deprecated/types/-private.js +1 -1
- package/dist/unpkg/prod/-leaked-DUONXQDB.js +1676 -0
- package/dist/unpkg/prod/{-private-3C1OkYtZ.js → -private-sql1_mdx.js} +1 -1
- package/dist/unpkg/prod/configure.js +2 -1
- package/dist/unpkg/prod/graph/-private.js +3 -2
- package/dist/unpkg/prod/{handler-LAyD1Y5l.js → handler-EU_8ncB2.js} +2 -2
- package/dist/unpkg/prod/index.js +7 -5
- package/dist/unpkg/prod/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod/reactive/-private.js +1 -1
- package/dist/unpkg/prod/reactive.js +26 -123
- package/dist/unpkg/prod/{request-CN2LxbYX.js → request-BrJSCG6r.js} +3 -19
- package/dist/unpkg/prod/request.js +2 -1
- package/dist/unpkg/prod/{promise-state-ipG60SdD.js → schema-BSkHyoWz.js} +53 -1572
- package/dist/unpkg/prod/signals/-leaked.js +1 -0
- package/dist/unpkg/prod/store/-private.js +3 -4
- package/dist/unpkg/prod/types/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/-leaked-DRNv9VIX.js +1676 -0
- package/dist/unpkg/prod-deprecated/configure.js +2 -1
- package/dist/unpkg/prod-deprecated/graph/-private.js +3 -2
- package/dist/unpkg/prod-deprecated/{handler-D639oFvl.js → handler-CCIu4sQ3.js} +1 -1
- package/dist/unpkg/prod-deprecated/{hooks-DGvi9teJ.js → hooks-Dv4Np0MY.js} +1 -1
- package/dist/unpkg/prod-deprecated/index.js +7 -5
- package/dist/unpkg/prod-deprecated/promise-cache-DIT8Ypjq.js +19 -0
- package/dist/unpkg/prod-deprecated/reactive.js +4 -125
- package/dist/unpkg/prod-deprecated/{request-CN2LxbYX.js → request-BrJSCG6r.js} +3 -19
- package/dist/unpkg/prod-deprecated/request.js +2 -1
- package/dist/unpkg/prod-deprecated/{promise-state-CYvoIPna.js → schema-CJcjHv0E.js} +52 -1571
- package/dist/unpkg/prod-deprecated/signals/-leaked.js +1 -0
- package/dist/unpkg/prod-deprecated/store/-private.js +2 -3
- package/dist/unpkg/prod-deprecated/types/-private.js +1 -1
- package/package.json +3 -3
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +0 -24
- package/dist/configure-C3x8YXzL.js +0 -181
- package/dist/unpkg/dev/configure-BC66sfNO.js +0 -183
- package/dist/unpkg/dev-deprecated/configure-BC66sfNO.js +0 -183
- package/dist/unpkg/prod/configure-C0C1LpG6.js +0 -158
- package/dist/unpkg/prod/hooks-BfiqDg3O.js +0 -26
- package/dist/unpkg/prod-deprecated/configure-BQ8CpIcW.js +0 -158
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/configure.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/internal.d.ts +0 -0
- /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/signal.d.ts +0 -0
- /package/dist/{unpkg/dev/-private-3C1OkYtZ.js → symbols-3C1OkYtZ.js} +0 -0
- /package/dist/{symbols-sql1_mdx.js → unpkg/dev/-private-sql1_mdx.js} +0 -0
|
@@ -1,285 +1,12 @@
|
|
|
1
|
+
import { d as defineGate, a as withSignalStore, n as notifyInternalSignal, p as peekInternalSignal, g as getOrCreateInternalSignal, c as consumeInternalSignal, b as createInternalSignal, A as ARRAY_SIGNAL, S as Signals, e as createSignalDescriptor, f as defineSignal, h as entangleSignal, i as entangleInitiallyStaleSignal, O as OBJECT_SIGNAL, j as createInternalMemo } from "./-leaked-DUONXQDB.js";
|
|
1
2
|
import { EnableHydration, STRUCTURED } from './types/request.js';
|
|
2
|
-
import { D as Destroy,
|
|
3
|
+
import { D as Destroy, C as Context, S as SOURCE, a as Checkout, b as Commit } from "./-private-sql1_mdx.js";
|
|
3
4
|
import { isResourceSchema } from './types/schema/fields.js';
|
|
4
|
-
import {
|
|
5
|
+
import { setTransient, peekTransient, getOrSetGlobal } from './types/-private.js';
|
|
5
6
|
import './types/runtime.js';
|
|
6
|
-
import { w as withBrand
|
|
7
|
+
import { w as withBrand } from "./request-BrJSCG6r.js";
|
|
7
8
|
import { CACHE_OWNER } from './types/identifier.js';
|
|
8
9
|
import { RecordStore, Type } from './types/symbols.js';
|
|
9
|
-
import { c as createSignal, b as consumeSignal, n as notifySignal, d as createMemo, A as ARRAY_SIGNAL, O as OBJECT_SIGNAL } from "./configure-C0C1LpG6.js";
|
|
10
|
-
const INITIALIZER_PROTO = {
|
|
11
|
-
isInitializer: true
|
|
12
|
-
};
|
|
13
|
-
function makeInitializer(fn) {
|
|
14
|
-
// we use a prototype to ensure that the initializer is not enumerable
|
|
15
|
-
// and does not interfere with the signal's value.
|
|
16
|
-
return Object.assign(Object.create(INITIALIZER_PROTO), {
|
|
17
|
-
value: fn
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function isInitializer(obj) {
|
|
21
|
-
return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === INITIALIZER_PROTO;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
|
|
26
|
-
* that enables us to store and manage the signal in a universal way.
|
|
27
|
-
*
|
|
28
|
-
* WarpDrive uses signals to manage three separate concepts:
|
|
29
|
-
*
|
|
30
|
-
* - as a `storage` for a value local to the object that we want to be reactive
|
|
31
|
-
* (see `@local` schema field for an example)
|
|
32
|
-
* - as a `gate` for a memoized getter that we want to act as a reactive property
|
|
33
|
-
* but whose value is computed/pulled from a non-reactive source elsewhere
|
|
34
|
-
* and whose latest value is stored in the signal
|
|
35
|
-
* (see `field` schema field for an example)
|
|
36
|
-
* - as a `gate` with a manually managed value updated on pull when `isStale` is true
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* It offers
|
|
40
|
-
*
|
|
41
|
-
* - a non-reactive way to access/update the current value
|
|
42
|
-
* - a non-reactive way to mark the signal as dirtied
|
|
43
|
-
* - a non-reactive way to store content for why the signal was dirtied
|
|
44
|
-
* - access to the underlying Signal(s) in-use
|
|
45
|
-
*
|
|
46
|
-
* For debugging:
|
|
47
|
-
* - the "key" or "name" of the signal
|
|
48
|
-
* - the "object identity" or "context" to which the signal is attached
|
|
49
|
-
*
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* We attach signals to their context object via
|
|
55
|
-
* a Map attached to the object via this symbol.
|
|
56
|
-
*
|
|
57
|
-
* This allows us to store multiple signals
|
|
58
|
-
* on the same object with smaller memory
|
|
59
|
-
* overhead and no WeakMap lookups.
|
|
60
|
-
*
|
|
61
|
-
* Performance sensitive objects should
|
|
62
|
-
* pre-warm their shape by assigning this
|
|
63
|
-
* during initialization.
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* initializeSignalStore(obj);
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @private
|
|
70
|
-
*/
|
|
71
|
-
const Signals = getOrSetGlobal('Signals', Symbol('Signals'));
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A util that will create a signal store on the object
|
|
75
|
-
* if it does not already exist and returns the associated
|
|
76
|
-
* signal store.
|
|
77
|
-
*
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
function withSignalStore(obj) {
|
|
81
|
-
if (!obj[Signals]) {
|
|
82
|
-
initializeSignalStore(obj);
|
|
83
|
-
}
|
|
84
|
-
return obj[Signals];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* A util that will create a signal store on the object
|
|
89
|
-
* if it does not already exist.
|
|
90
|
-
*
|
|
91
|
-
* Useful for pre-warming the shape of an object to ensure
|
|
92
|
-
* a key-transition to add it is not required later.
|
|
93
|
-
*
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
96
|
-
function initializeSignalStore(obj) {
|
|
97
|
-
obj[Signals] = new Map();
|
|
98
|
-
}
|
|
99
|
-
function createInternalSignal(signals, obj, key, initialValue) {
|
|
100
|
-
const warpDriveSignal = {
|
|
101
|
-
key,
|
|
102
|
-
context: obj,
|
|
103
|
-
signal: createSignal(obj, key),
|
|
104
|
-
value: isInitializer(initialValue) ? initialValue.value.call(obj) : initialValue,
|
|
105
|
-
isStale: false
|
|
106
|
-
};
|
|
107
|
-
signals.set(key, warpDriveSignal);
|
|
108
|
-
return warpDriveSignal;
|
|
109
|
-
}
|
|
110
|
-
function getOrCreateInternalSignal(signals, obj, key, initialValue) {
|
|
111
|
-
let signal = peekInternalSignal(signals, key);
|
|
112
|
-
if (!signal) {
|
|
113
|
-
signal = createInternalSignal(signals, obj, key, initialValue);
|
|
114
|
-
}
|
|
115
|
-
return signal;
|
|
116
|
-
}
|
|
117
|
-
function createInternalMemo(signals, object, key, fn) {
|
|
118
|
-
{
|
|
119
|
-
const memo = createMemo(object, key, fn);
|
|
120
|
-
signals.set(key, memo);
|
|
121
|
-
return memo;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function peekInternalSignal(signals, key) {
|
|
125
|
-
return signals?.get(key);
|
|
126
|
-
}
|
|
127
|
-
function consumeInternalSignal(signal) {
|
|
128
|
-
consumeSignal(signal.signal);
|
|
129
|
-
}
|
|
130
|
-
function notifyInternalSignal(signal) {
|
|
131
|
-
if (signal) {
|
|
132
|
-
signal.isStale = true;
|
|
133
|
-
notifySignal(signal.signal);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Creates a signal for the key/object pairing and subscribes to the signal.
|
|
139
|
-
*
|
|
140
|
-
* Use when you need to ensure a signal exists and is subscribed to.
|
|
141
|
-
*
|
|
142
|
-
* @private
|
|
143
|
-
*/
|
|
144
|
-
function entangleSignal(signals, obj, key, initialValue) {
|
|
145
|
-
let internalSignal = peekInternalSignal(signals, key);
|
|
146
|
-
if (!internalSignal) {
|
|
147
|
-
internalSignal = createInternalSignal(signals, obj, key, initialValue);
|
|
148
|
-
}
|
|
149
|
-
consumeInternalSignal(internalSignal);
|
|
150
|
-
return internalSignal;
|
|
151
|
-
}
|
|
152
|
-
function entangleInitiallyStaleSignal(signals, obj, key, initialValue) {
|
|
153
|
-
let internalSignal = peekInternalSignal(signals, key);
|
|
154
|
-
if (!internalSignal) {
|
|
155
|
-
internalSignal = createInternalSignal(signals, obj, key, initialValue);
|
|
156
|
-
internalSignal.isStale = true; // mark it as stale
|
|
157
|
-
}
|
|
158
|
-
consumeInternalSignal(internalSignal);
|
|
159
|
-
return internalSignal;
|
|
160
|
-
}
|
|
161
|
-
function createSignalDescriptor(key, intialValue) {
|
|
162
|
-
return {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
configurable: false,
|
|
165
|
-
get() {
|
|
166
|
-
const signals = withSignalStore(this);
|
|
167
|
-
const internalSignal = entangleSignal(signals, this, key, intialValue);
|
|
168
|
-
internalSignal.isStale = false; // reset stale state
|
|
169
|
-
return internalSignal.value;
|
|
170
|
-
},
|
|
171
|
-
set(value) {
|
|
172
|
-
const signals = withSignalStore(this);
|
|
173
|
-
const internalSignal = getOrCreateInternalSignal(signals, this, key, intialValue);
|
|
174
|
-
if (internalSignal.value !== value) {
|
|
175
|
-
internalSignal.value = value;
|
|
176
|
-
notifyInternalSignal(internalSignal);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* define an enumerable signal property.
|
|
184
|
-
*
|
|
185
|
-
* Akin to Object.defineProperty.
|
|
186
|
-
*
|
|
187
|
-
* The signal will be lazily created when accessed and scoped to the
|
|
188
|
-
* instance of the object.
|
|
189
|
-
*
|
|
190
|
-
* @private
|
|
191
|
-
*/
|
|
192
|
-
function defineSignal(obj, key, v) {
|
|
193
|
-
Object.defineProperty(obj, key, createSignalDescriptor(key, v));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Define a non-enumerable signal property.
|
|
198
|
-
*
|
|
199
|
-
* @private
|
|
200
|
-
*/
|
|
201
|
-
function defineNonEnumerableSignal(obj, key, v) {
|
|
202
|
-
const desc = createSignalDescriptor(key, v);
|
|
203
|
-
desc.enumerable = false;
|
|
204
|
-
Object.defineProperty(obj, key, desc);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Decorator version of creating a signal.
|
|
208
|
-
*/
|
|
209
|
-
function signal(target, key, descriptor) {
|
|
210
|
-
return createSignalDescriptor(key, descriptor.initializer ? makeInitializer(descriptor.initializer) : null);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Decorator version of creating a memoized getter
|
|
215
|
-
*/
|
|
216
|
-
function memoized(target, key, descriptor) {
|
|
217
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
218
|
-
const getter = descriptor.get;
|
|
219
|
-
descriptor.get = function () {
|
|
220
|
-
const signals = withSignalStore(this);
|
|
221
|
-
let memoSignal = signals.get(key);
|
|
222
|
-
if (!memoSignal) {
|
|
223
|
-
memoSignal = createInternalMemo(signals, this, key, getter.bind(this));
|
|
224
|
-
}
|
|
225
|
-
return memoSignal();
|
|
226
|
-
};
|
|
227
|
-
return descriptor;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Decorator version of creating a gate.
|
|
232
|
-
*
|
|
233
|
-
* @private
|
|
234
|
-
*/
|
|
235
|
-
function gate(_target, key, desc) {
|
|
236
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
237
|
-
const getter = desc.get;
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
239
|
-
const setter = desc.set;
|
|
240
|
-
const isLocal = desc.isLocal;
|
|
241
|
-
desc.get = function () {
|
|
242
|
-
const signals = withSignalStore(this);
|
|
243
|
-
let internalSignal = peekInternalSignal(signals, key);
|
|
244
|
-
if (!internalSignal) {
|
|
245
|
-
internalSignal = createInternalSignal(signals, this, key, getter.call(this));
|
|
246
|
-
} else if (internalSignal.isStale) {
|
|
247
|
-
internalSignal.isStale = false;
|
|
248
|
-
internalSignal.value = getter.call(this);
|
|
249
|
-
}
|
|
250
|
-
consumeInternalSignal(internalSignal);
|
|
251
|
-
return internalSignal.value;
|
|
252
|
-
};
|
|
253
|
-
if (setter) {
|
|
254
|
-
desc.set = function (v) {
|
|
255
|
-
const signals = withSignalStore(this);
|
|
256
|
-
let internalSignal = peekInternalSignal(signals, key);
|
|
257
|
-
if (!internalSignal) {
|
|
258
|
-
// we can't use `v` as initialValue here because setters don't
|
|
259
|
-
// return the value and the final value may be different
|
|
260
|
-
// than what the setter was called with.
|
|
261
|
-
internalSignal = createInternalSignal(signals, this, key, undefined);
|
|
262
|
-
internalSignal.isStale = true;
|
|
263
|
-
}
|
|
264
|
-
setter.call(this, v);
|
|
265
|
-
// when a gate is set, we do not notify the signal
|
|
266
|
-
// as its update is controlled externally.
|
|
267
|
-
// unless it specifically sets itself to be locally managed
|
|
268
|
-
if (isLocal) {
|
|
269
|
-
internalSignal.isStale = true;
|
|
270
|
-
notifyInternalSignal(internalSignal);
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
return desc;
|
|
275
|
-
}
|
|
276
|
-
function defineGate(obj, key, desc) {
|
|
277
|
-
const options = Object.assign({
|
|
278
|
-
enumerable: true,
|
|
279
|
-
configurable: false
|
|
280
|
-
}, gate(obj, key, desc));
|
|
281
|
-
Object.defineProperty(obj, key, options);
|
|
282
|
-
}
|
|
283
10
|
function urlFromLink(link) {
|
|
284
11
|
if (typeof link === 'string') return link;
|
|
285
12
|
return link.href;
|
|
@@ -2810,7 +2537,7 @@ class RecordReference {
|
|
|
2810
2537
|
simplest usage of this API is similar to `store.push`: you provide a
|
|
2811
2538
|
normalized hash of data and the object represented by the reference
|
|
2812
2539
|
will update.
|
|
2813
|
-
If you pass a promise to `push`,
|
|
2540
|
+
If you pass a promise to `push`, WarpDrive will not ask the adapter
|
|
2814
2541
|
for the data if another attempt to fetch it is made in the
|
|
2815
2542
|
interim. When the promise resolves, the underlying object is updated
|
|
2816
2543
|
with the new data, and the promise returned by *this function* is resolved
|
|
@@ -2913,7 +2640,7 @@ defineSignal(RecordReference.prototype, '_ref');
|
|
|
2913
2640
|
|
|
2914
2641
|
### Inverses
|
|
2915
2642
|
|
|
2916
|
-
Often, the relationships in
|
|
2643
|
+
Often, the relationships in WarpDrive applications will have
|
|
2917
2644
|
an inverse. For example, imagine the following models are
|
|
2918
2645
|
defined:
|
|
2919
2646
|
|
|
@@ -3192,1143 +2919,59 @@ function mutate(collection, mutation, _SIGNAL) {
|
|
|
3192
2919
|
manager.mutate(mutation);
|
|
3193
2920
|
notifyInternalSignal(_SIGNAL);
|
|
3194
2921
|
}
|
|
3195
|
-
function
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
2922
|
+
function getAliasField(context) {}
|
|
2923
|
+
function setAliasField(context) {
|
|
2924
|
+
return false;
|
|
2925
|
+
}
|
|
2926
|
+
const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
|
|
2927
|
+
// const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
|
|
2928
|
+
const SYNC_PROPS = new Set(['[]', 'length']);
|
|
2929
|
+
function isArrayGetter(prop) {
|
|
2930
|
+
return ARRAY_GETTER_METHODS.has(prop);
|
|
2931
|
+
}
|
|
2932
|
+
const ARRAY_SETTER_METHODS = new Set(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
|
|
2933
|
+
function isArraySetter(prop) {
|
|
2934
|
+
return ARRAY_SETTER_METHODS.has(prop);
|
|
3208
2935
|
}
|
|
3209
2936
|
|
|
3210
|
-
//
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
/**
|
|
3215
|
-
* Utilities to assist in recovering from the error.
|
|
3216
|
-
*/
|
|
3217
|
-
|
|
3218
|
-
/** @deprecated use {@link RecoveryFeatures} */
|
|
3219
|
-
|
|
3220
|
-
/**
|
|
3221
|
-
* Utilities for keeping the request fresh
|
|
3222
|
-
*/
|
|
3223
|
-
|
|
3224
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3225
|
-
|
|
3226
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3227
|
-
|
|
3228
|
-
/**
|
|
3229
|
-
* A reactive class
|
|
3230
|
-
*
|
|
3231
|
-
* @hideconstructor
|
|
3232
|
-
*/
|
|
3233
|
-
class RequestSubscription {
|
|
3234
|
-
/**
|
|
3235
|
-
* Whether the browser reports that the network is online.
|
|
3236
|
-
*/
|
|
3237
|
-
|
|
3238
|
-
/**
|
|
3239
|
-
* Whether the browser reports that the tab is hidden.
|
|
3240
|
-
*/
|
|
3241
|
-
|
|
3242
|
-
/**
|
|
3243
|
-
* Whether the component is currently refreshing the request.
|
|
3244
|
-
*/
|
|
3245
|
-
|
|
3246
|
-
/**
|
|
3247
|
-
* The most recent blocking request that was made, typically
|
|
3248
|
-
* the result of a reload.
|
|
3249
|
-
*
|
|
3250
|
-
* This will never be the original request passed as an arg to
|
|
3251
|
-
* the component.
|
|
3252
|
-
*
|
|
3253
|
-
* @internal
|
|
3254
|
-
*/
|
|
3255
|
-
|
|
3256
|
-
/**
|
|
3257
|
-
* The most recent request that was made, typically due to either a
|
|
3258
|
-
* reload or a refresh.
|
|
3259
|
-
*
|
|
3260
|
-
* This will never be the original request passed as an arg to
|
|
3261
|
-
* the component.
|
|
3262
|
-
*
|
|
3263
|
-
* @internal
|
|
3264
|
-
*/
|
|
3265
|
-
|
|
3266
|
-
/**
|
|
3267
|
-
* The time at which the network was reported as offline.
|
|
3268
|
-
*
|
|
3269
|
-
* @internal
|
|
3270
|
-
*/
|
|
3271
|
-
|
|
3272
|
-
/** @internal */
|
|
3273
|
-
|
|
3274
|
-
/** @internal */
|
|
3275
|
-
|
|
3276
|
-
/** @internal */
|
|
3277
|
-
|
|
3278
|
-
/** @internal */
|
|
3279
|
-
|
|
3280
|
-
/** @internal */
|
|
3281
|
-
|
|
3282
|
-
/**
|
|
3283
|
-
* The event listener for network status changes,
|
|
3284
|
-
* cached to use the reference for removal.
|
|
3285
|
-
*
|
|
3286
|
-
* @internal
|
|
3287
|
-
*/
|
|
3288
|
-
|
|
3289
|
-
/**
|
|
3290
|
-
* The event listener for visibility status changes,
|
|
3291
|
-
* cached to use the reference for removal.
|
|
3292
|
-
*
|
|
3293
|
-
* @internal
|
|
3294
|
-
*/
|
|
3295
|
-
|
|
3296
|
-
/**
|
|
3297
|
-
* The last request passed as an arg to the component,
|
|
3298
|
-
* cached for comparison.
|
|
3299
|
-
*
|
|
3300
|
-
* @internal
|
|
3301
|
-
*/
|
|
3302
|
-
|
|
3303
|
-
/**
|
|
3304
|
-
* The last query passed as an arg to the component,
|
|
3305
|
-
* cached for comparison.
|
|
3306
|
-
*
|
|
3307
|
-
* @internal
|
|
3308
|
-
*/
|
|
3309
|
-
|
|
3310
|
-
/** @internal */
|
|
3311
|
-
|
|
3312
|
-
/** @internal */
|
|
3313
|
-
|
|
3314
|
-
/** @internal */
|
|
3315
|
-
|
|
3316
|
-
/**
|
|
3317
|
-
* The Store this subscription subscribes to or the RequestManager
|
|
3318
|
-
* which issues this request.
|
|
3319
|
-
*/
|
|
2937
|
+
// function isSelfProp<T extends object>(self: T, prop: KeyType): prop is keyof T {
|
|
2938
|
+
// return prop in self;
|
|
2939
|
+
// }
|
|
3320
2940
|
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
_requester;
|
|
3331
|
-
constructor(store, args) {
|
|
3332
|
-
this._args = args;
|
|
3333
|
-
this.store = store;
|
|
3334
|
-
this._subscribedTo = null;
|
|
3335
|
-
this._subscription = null;
|
|
3336
|
-
this._intervalStart = null;
|
|
3337
|
-
this._invalidated = false;
|
|
3338
|
-
this._nextInterval = null;
|
|
3339
|
-
this._requester = null;
|
|
3340
|
-
this.isDestroyed = false;
|
|
3341
|
-
this[DISPOSE] = _DISPOSE;
|
|
3342
|
-
this._installListeners();
|
|
3343
|
-
void this._beginPolling();
|
|
2941
|
+
function convertToInt(prop) {
|
|
2942
|
+
if (typeof prop === 'symbol') return null;
|
|
2943
|
+
const num = Number(prop);
|
|
2944
|
+
if (isNaN(num)) return null;
|
|
2945
|
+
return num % 1 === 0 ? num : null;
|
|
2946
|
+
}
|
|
2947
|
+
function safeForEach(instance, arr, store, callback, target) {
|
|
2948
|
+
if (target === undefined) {
|
|
2949
|
+
target = null;
|
|
3344
2950
|
}
|
|
2951
|
+
// clone to prevent mutation
|
|
2952
|
+
arr = arr.slice();
|
|
3345
2953
|
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
try {
|
|
3352
|
-
if (!this.isIdle) {
|
|
3353
|
-
await this.request;
|
|
3354
|
-
}
|
|
3355
|
-
} catch {
|
|
3356
|
-
// ignore errors here, we just want to wait for the request to finish
|
|
3357
|
-
} finally {
|
|
3358
|
-
if (!this.isDestroyed) {
|
|
3359
|
-
void this._scheduleInterval();
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
get isIdle() {
|
|
3364
|
-
const {
|
|
3365
|
-
request,
|
|
3366
|
-
query
|
|
3367
|
-
} = this._args;
|
|
3368
|
-
return Boolean(!request && !query);
|
|
3369
|
-
}
|
|
3370
|
-
static {
|
|
3371
|
-
decorateMethodV2(this.prototype, "isIdle", [memoized]);
|
|
3372
|
-
}
|
|
3373
|
-
get autorefreshTypes() {
|
|
3374
|
-
const {
|
|
3375
|
-
autorefresh
|
|
3376
|
-
} = this._args;
|
|
3377
|
-
let types;
|
|
3378
|
-
if (autorefresh === true) {
|
|
3379
|
-
types = ['online', 'invalid'];
|
|
3380
|
-
} else if (typeof autorefresh === 'string') {
|
|
3381
|
-
types = autorefresh.split(',');
|
|
3382
|
-
} else {
|
|
3383
|
-
types = [];
|
|
3384
|
-
}
|
|
3385
|
-
return new Set(types);
|
|
3386
|
-
}
|
|
2954
|
+
// because we retrieveLatest above we need not worry if array is mutated during iteration
|
|
2955
|
+
// by unloadRecord/rollbackAttributes
|
|
2956
|
+
// push/add/removeObject may still be problematic
|
|
2957
|
+
// but this is a more traditionally expected forEach bug.
|
|
2958
|
+
const length = arr.length; // we need to access length to ensure we are consumed
|
|
3387
2959
|
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
// react to changes in the autorefreshThreshold
|
|
3391
|
-
// or autorefresh args.
|
|
3392
|
-
//
|
|
3393
|
-
// if we need to react to those changes, we can
|
|
3394
|
-
// use a modifier or internal component or some
|
|
3395
|
-
// such to trigger a re-run of this function.
|
|
3396
|
-
/** @internal */
|
|
3397
|
-
static {
|
|
3398
|
-
decorateMethodV2(this.prototype, "autorefreshTypes", [memoized]);
|
|
2960
|
+
for (let index = 0; index < length; index++) {
|
|
2961
|
+
callback.call(target, arr[index], index, instance);
|
|
3399
2962
|
}
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
// dont schedule if we're already scheduled
|
|
3413
|
-
this._intervalStart !== null) {
|
|
3414
|
-
return;
|
|
3415
|
-
}
|
|
3416
|
-
|
|
3417
|
-
// if we have a current request, wait for it to finish
|
|
3418
|
-
// before scheduling the next one
|
|
3419
|
-
if (this._latestRequest) {
|
|
3420
|
-
try {
|
|
3421
|
-
await this._latestRequest;
|
|
3422
|
-
} catch {
|
|
3423
|
-
// ignore errors here, we just want to wait for the request to finish
|
|
3424
|
-
}
|
|
3425
|
-
if (this.isDestroyed) {
|
|
3426
|
-
return;
|
|
3427
|
-
}
|
|
3428
|
-
}
|
|
3429
|
-
|
|
3430
|
-
// setup the next interval
|
|
3431
|
-
this._intervalStart = Date.now();
|
|
3432
|
-
this._nextInterval = setTimeout(() => {
|
|
3433
|
-
this._maybeUpdate();
|
|
3434
|
-
}, autorefreshThreshold);
|
|
3435
|
-
}
|
|
3436
|
-
|
|
3437
|
-
/** @internal */
|
|
3438
|
-
_clearInterval() {
|
|
3439
|
-
if (this._nextInterval) {
|
|
3440
|
-
clearTimeout(this._nextInterval);
|
|
3441
|
-
this._intervalStart = null;
|
|
3442
|
-
}
|
|
3443
|
-
}
|
|
3444
|
-
/**
|
|
3445
|
-
* @internal
|
|
3446
|
-
*/
|
|
3447
|
-
_updateSubscriptions() {
|
|
3448
|
-
if (this.isIdle) {
|
|
3449
|
-
return;
|
|
3450
|
-
}
|
|
3451
|
-
const requestId = this._request.lid;
|
|
3452
|
-
|
|
3453
|
-
// if we're already subscribed to this request, we don't need to do anything
|
|
3454
|
-
if (this._subscribedTo === requestId) {
|
|
3455
|
-
return;
|
|
3456
|
-
}
|
|
3457
|
-
|
|
3458
|
-
// if we're subscribed to a different request, we need to unsubscribe
|
|
3459
|
-
this._removeSubscriptions();
|
|
3460
|
-
|
|
3461
|
-
// if we have a request, we need to subscribe to it
|
|
3462
|
-
const store = this._getRequester();
|
|
3463
|
-
this._requester = store;
|
|
3464
|
-
if (requestId && isStore(store)) {
|
|
3465
|
-
this._subscribedTo = requestId;
|
|
3466
|
-
this._subscription = store.notifications.subscribe(requestId, (_id, op) => {
|
|
3467
|
-
// ignore subscription events that occur while our own component's request
|
|
3468
|
-
// is occurring
|
|
3469
|
-
if (this._isUpdating) {
|
|
3470
|
-
return;
|
|
3471
|
-
}
|
|
3472
|
-
switch (op) {
|
|
3473
|
-
case 'invalidated':
|
|
3474
|
-
{
|
|
3475
|
-
// if we're subscribed to invalidations, we need to update
|
|
3476
|
-
if (this.autorefreshTypes.has('invalid')) {
|
|
3477
|
-
this._invalidated = true;
|
|
3478
|
-
this._maybeUpdate();
|
|
3479
|
-
}
|
|
3480
|
-
break;
|
|
3481
|
-
}
|
|
3482
|
-
case 'state':
|
|
3483
|
-
{
|
|
3484
|
-
const latest = store.requestManager._deduped.get(requestId);
|
|
3485
|
-
const priority = latest?.priority;
|
|
3486
|
-
const state = this.reqState;
|
|
3487
|
-
if (!priority) {
|
|
3488
|
-
// if there is no priority, we have completed whatever request
|
|
3489
|
-
// was occurring and so we are no longer refreshing (if we were)
|
|
3490
|
-
this.isRefreshing = false;
|
|
3491
|
-
} else if (priority.blocking && !state.isLoading) {
|
|
3492
|
-
// if we are blocking, there is an active request for this identity
|
|
3493
|
-
// that MUST be fulfilled from network (not cache).
|
|
3494
|
-
// Thus this is not "refreshing" because we should clear out and
|
|
3495
|
-
// block on this request.
|
|
3496
|
-
//
|
|
3497
|
-
// we receive state notifications when either a request initiates
|
|
3498
|
-
// or completes.
|
|
3499
|
-
//
|
|
3500
|
-
// In the completes case: we may receive the state notification
|
|
3501
|
-
// slightly before the request is finalized because the NotificationManager
|
|
3502
|
-
// may sync flush it (and thus deliver it before the microtask completes)
|
|
3503
|
-
//
|
|
3504
|
-
// In the initiates case: we aren't supposed to receive one unless there
|
|
3505
|
-
// is no other request in flight for this identity.
|
|
3506
|
-
//
|
|
3507
|
-
// However, there is a race condition here where the completed
|
|
3508
|
-
// notification can trigger an update that generates a new request
|
|
3509
|
-
// thus giving us an initiated notification before the older request
|
|
3510
|
-
// finalizes.
|
|
3511
|
-
//
|
|
3512
|
-
// When this occurs, if the triggered update happens to have caused
|
|
3513
|
-
// a new request to be made for the same identity AND that request
|
|
3514
|
-
// is the one passed into this component as the @request arg, then
|
|
3515
|
-
// getRequestState will return the state of the new request.
|
|
3516
|
-
// We can detect this by checking if the request state is "loading"
|
|
3517
|
-
// as outside of this case we would have a completed request.
|
|
3518
|
-
//
|
|
3519
|
-
// That is the reason for the `&& !state.isLoading` check above.
|
|
3520
|
-
|
|
3521
|
-
// TODO should we just treat this as refreshing?
|
|
3522
|
-
this.isRefreshing = false;
|
|
3523
|
-
this._maybeUpdate('policy', true);
|
|
3524
|
-
} else {
|
|
3525
|
-
this.isRefreshing = true;
|
|
3526
|
-
}
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
});
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
|
|
3533
|
-
/**
|
|
3534
|
-
* @internal
|
|
3535
|
-
*/
|
|
3536
|
-
_removeSubscriptions() {
|
|
3537
|
-
const store = this._requester;
|
|
3538
|
-
if (this._subscription && store && isStore(store)) {
|
|
3539
|
-
store.notifications.unsubscribe(this._subscription);
|
|
3540
|
-
this._subscribedTo = null;
|
|
3541
|
-
this._subscription = null;
|
|
3542
|
-
this._requester = null;
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
|
|
3546
|
-
/**
|
|
3547
|
-
* Install the event listeners for network and visibility changes.
|
|
3548
|
-
* This is only done in browser environments with a global `window`.
|
|
3549
|
-
*
|
|
3550
|
-
* @internal
|
|
3551
|
-
*/
|
|
3552
|
-
_installListeners() {
|
|
3553
|
-
if (typeof window === 'undefined') {
|
|
3554
|
-
return;
|
|
3555
|
-
}
|
|
3556
|
-
this.isOnline = window.navigator.onLine;
|
|
3557
|
-
this._unavailableStart = this.isOnline ? null : Date.now();
|
|
3558
|
-
this.isHidden = document.visibilityState === 'hidden';
|
|
3559
|
-
this._onlineChanged = event => {
|
|
3560
|
-
this.isOnline = event.type === 'online';
|
|
3561
|
-
if (event.type === 'offline' && this._unavailableStart === null) {
|
|
3562
|
-
this._unavailableStart = Date.now();
|
|
3563
|
-
}
|
|
3564
|
-
this._maybeUpdate();
|
|
3565
|
-
};
|
|
3566
|
-
this._backgroundChanged = () => {
|
|
3567
|
-
const isHidden = document.visibilityState === 'hidden';
|
|
3568
|
-
this.isHidden = isHidden;
|
|
3569
|
-
if (isHidden && this._unavailableStart === null) {
|
|
3570
|
-
this._unavailableStart = Date.now();
|
|
3571
|
-
}
|
|
3572
|
-
this._maybeUpdate();
|
|
3573
|
-
};
|
|
3574
|
-
window.addEventListener('online', this._onlineChanged, {
|
|
3575
|
-
passive: true,
|
|
3576
|
-
capture: true
|
|
3577
|
-
});
|
|
3578
|
-
window.addEventListener('offline', this._onlineChanged, {
|
|
3579
|
-
passive: true,
|
|
3580
|
-
capture: true
|
|
3581
|
-
});
|
|
3582
|
-
document.addEventListener('visibilitychange', this._backgroundChanged, {
|
|
3583
|
-
passive: true,
|
|
3584
|
-
capture: true
|
|
3585
|
-
});
|
|
3586
|
-
}
|
|
3587
|
-
|
|
3588
|
-
/**
|
|
3589
|
-
* If the network is online and the tab is visible, either reload or refresh the request
|
|
3590
|
-
* based on the component's configuration and the requested update mode.
|
|
3591
|
-
*
|
|
3592
|
-
* Valid modes are:
|
|
3593
|
-
*
|
|
3594
|
-
* - `'reload'`: Force a reload of the request.
|
|
3595
|
-
* - `'refresh'`: Refresh the request in the background.
|
|
3596
|
-
* - `'policy'`: Make the request, letting the store's configured CachePolicy decide whether to reload, refresh, or do nothing.
|
|
3597
|
-
* - `undefined`: Make the request using the component's autorefreshBehavior setting if the autorefreshThreshold has passed.
|
|
3598
|
-
*
|
|
3599
|
-
* @internal
|
|
3600
|
-
*/
|
|
3601
|
-
_maybeUpdate(mode, silent) {
|
|
3602
|
-
if (this.isIdle) {
|
|
3603
|
-
return;
|
|
3604
|
-
}
|
|
3605
|
-
const {
|
|
3606
|
-
reqState
|
|
3607
|
-
} = this;
|
|
3608
|
-
if (reqState.isPending) {
|
|
3609
|
-
return;
|
|
3610
|
-
}
|
|
3611
|
-
const canAttempt = Boolean(this.isOnline && !this.isHidden && (mode || this.autorefreshTypes.size));
|
|
3612
|
-
if (!canAttempt) {
|
|
3613
|
-
if (!silent && mode && mode !== '_invalidated') {
|
|
3614
|
-
throw new Error(`Reload not available: the network is not online or the tab is hidden`);
|
|
3615
|
-
}
|
|
3616
|
-
return;
|
|
3617
|
-
}
|
|
3618
|
-
const {
|
|
3619
|
-
autorefreshTypes
|
|
3620
|
-
} = this;
|
|
3621
|
-
let shouldAttempt = this._invalidated || Boolean(mode);
|
|
3622
|
-
if (!shouldAttempt && autorefreshTypes.has('online')) {
|
|
3623
|
-
const {
|
|
3624
|
-
_unavailableStart
|
|
3625
|
-
} = this;
|
|
3626
|
-
const {
|
|
3627
|
-
autorefreshThreshold
|
|
3628
|
-
} = this._args;
|
|
3629
|
-
const deadline = typeof autorefreshThreshold === 'number' ? autorefreshThreshold : DEFAULT_DEADLINE;
|
|
3630
|
-
shouldAttempt = Boolean(_unavailableStart && Date.now() - _unavailableStart > deadline);
|
|
3631
|
-
}
|
|
3632
|
-
if (!shouldAttempt && autorefreshTypes.has('interval')) {
|
|
3633
|
-
const {
|
|
3634
|
-
_intervalStart
|
|
3635
|
-
} = this;
|
|
3636
|
-
const {
|
|
3637
|
-
autorefreshThreshold
|
|
3638
|
-
} = this._args;
|
|
3639
|
-
if (_intervalStart && typeof autorefreshThreshold === 'number' && autorefreshThreshold > 0) {
|
|
3640
|
-
shouldAttempt = Boolean(Date.now() - _intervalStart >= autorefreshThreshold);
|
|
3641
|
-
}
|
|
3642
|
-
}
|
|
3643
|
-
this._unavailableStart = null;
|
|
3644
|
-
this._invalidated = false;
|
|
3645
|
-
if (shouldAttempt) {
|
|
3646
|
-
this._clearInterval();
|
|
3647
|
-
this._isUpdating = true;
|
|
3648
|
-
const realMode = mode === '_invalidated' ? null : mode;
|
|
3649
|
-
const val = realMode ?? this._args.autorefreshBehavior ?? 'policy';
|
|
3650
|
-
|
|
3651
|
-
// if the future was generated by an older store version, it may not have
|
|
3652
|
-
// a requester set. In this case we append it to ensure that reload and
|
|
3653
|
-
// refresh will work appropriately.
|
|
3654
|
-
const requester = this._getRequester();
|
|
3655
|
-
if (!reqState._request.requester) {
|
|
3656
|
-
reqState._request.requester = requester;
|
|
3657
|
-
}
|
|
3658
|
-
switch (val) {
|
|
3659
|
-
case 'reload':
|
|
3660
|
-
this._latestRequest = reqState.reload();
|
|
3661
|
-
break;
|
|
3662
|
-
case 'refresh':
|
|
3663
|
-
this._latestRequest = reqState.refresh();
|
|
3664
|
-
break;
|
|
3665
|
-
case 'policy':
|
|
3666
|
-
this._latestRequest = reqState.refresh(true);
|
|
3667
|
-
break;
|
|
3668
|
-
}
|
|
3669
|
-
if (val !== 'refresh') {
|
|
3670
|
-
this._localRequest = this._latestRequest;
|
|
3671
|
-
}
|
|
3672
|
-
void this._scheduleInterval();
|
|
3673
|
-
void this._latestRequest.finally(() => {
|
|
3674
|
-
this._isUpdating = false;
|
|
3675
|
-
});
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
|
|
3679
|
-
/**
|
|
3680
|
-
* @internal
|
|
3681
|
-
*/
|
|
3682
|
-
_getRequester() {
|
|
3683
|
-
// Note: we check for the requester's presence
|
|
3684
|
-
// as well as the request's presence because we may
|
|
3685
|
-
// be subscribed to a request issued by a store from an older
|
|
3686
|
-
// version of the library that didn't yet set requester.
|
|
3687
|
-
if (this._args.request?.requester) {
|
|
3688
|
-
return this._args.request.requester;
|
|
3689
|
-
}
|
|
3690
|
-
return this.store;
|
|
3691
|
-
}
|
|
3692
|
-
|
|
3693
|
-
/**
|
|
3694
|
-
* Retry the request, reloading it from the server.
|
|
3695
|
-
*/
|
|
3696
|
-
retry = async () => {
|
|
3697
|
-
this._maybeUpdate('reload');
|
|
3698
|
-
await this._localRequest;
|
|
3699
|
-
};
|
|
3700
|
-
|
|
3701
|
-
/**
|
|
3702
|
-
* Refresh the request, updating it in the background.
|
|
3703
|
-
*/
|
|
3704
|
-
refresh = async () => {
|
|
3705
|
-
this._maybeUpdate('refresh');
|
|
3706
|
-
await this._latestRequest;
|
|
3707
|
-
};
|
|
3708
|
-
|
|
3709
|
-
/**
|
|
3710
|
-
* features to yield to the error slot of a component
|
|
3711
|
-
*/
|
|
3712
|
-
get errorFeatures() {
|
|
3713
|
-
return {
|
|
3714
|
-
isHidden: this.isHidden,
|
|
3715
|
-
isOnline: this.isOnline,
|
|
3716
|
-
retry: this.retry
|
|
3717
|
-
};
|
|
3718
|
-
}
|
|
3719
|
-
|
|
3720
|
-
/**
|
|
3721
|
-
* features to yield to the content slot of a component
|
|
3722
|
-
*/
|
|
3723
|
-
static {
|
|
3724
|
-
decorateMethodV2(this.prototype, "errorFeatures", [memoized]);
|
|
3725
|
-
}
|
|
3726
|
-
get contentFeatures() {
|
|
3727
|
-
const feat = {
|
|
3728
|
-
isHidden: this.isHidden,
|
|
3729
|
-
isOnline: this.isOnline,
|
|
3730
|
-
reload: this.retry,
|
|
3731
|
-
refresh: this.refresh,
|
|
3732
|
-
isRefreshing: this.isRefreshing,
|
|
3733
|
-
latestRequest: this._latestRequest
|
|
3734
|
-
};
|
|
3735
|
-
if (feat.isRefreshing) {
|
|
3736
|
-
feat.abort = () => {
|
|
3737
|
-
this._latestRequest?.abort();
|
|
3738
|
-
};
|
|
3739
|
-
}
|
|
3740
|
-
return feat;
|
|
3741
|
-
}
|
|
3742
|
-
|
|
3743
|
-
/**
|
|
3744
|
-
* @internal
|
|
3745
|
-
*/
|
|
3746
|
-
static {
|
|
3747
|
-
decorateMethodV2(this.prototype, "contentFeatures", [memoized]);
|
|
3748
|
-
}
|
|
3749
|
-
get _request() {
|
|
3750
|
-
const {
|
|
3751
|
-
request,
|
|
3752
|
-
query
|
|
3753
|
-
} = this._args;
|
|
3754
|
-
const {
|
|
3755
|
-
_localRequest,
|
|
3756
|
-
_originalRequest,
|
|
3757
|
-
_originalQuery
|
|
3758
|
-
} = this;
|
|
3759
|
-
const isOriginalRequest = request === _originalRequest && query === _originalQuery;
|
|
3760
|
-
if (_localRequest && isOriginalRequest) {
|
|
3761
|
-
return _localRequest;
|
|
3762
|
-
}
|
|
3763
|
-
|
|
3764
|
-
// update state checks for the next time
|
|
3765
|
-
this._originalQuery = query;
|
|
3766
|
-
this._originalRequest = request;
|
|
3767
|
-
if (request) {
|
|
3768
|
-
return request;
|
|
3769
|
-
}
|
|
3770
|
-
return this.store.request(query);
|
|
3771
|
-
}
|
|
3772
|
-
static {
|
|
3773
|
-
decorateMethodV2(this.prototype, "_request", [memoized]);
|
|
3774
|
-
}
|
|
3775
|
-
get request() {
|
|
3776
|
-
{
|
|
3777
|
-
const request = this._request;
|
|
3778
|
-
this._updateSubscriptions();
|
|
3779
|
-
return request;
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
static {
|
|
3783
|
-
decorateMethodV2(this.prototype, "request", [memoized]);
|
|
3784
|
-
}
|
|
3785
|
-
get reqState() {
|
|
3786
|
-
return getRequestState(this.request);
|
|
3787
|
-
}
|
|
3788
|
-
get result() {
|
|
3789
|
-
return this.reqState.result;
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
defineSignal(RequestSubscription.prototype, 'isOnline', true);
|
|
3793
|
-
defineSignal(RequestSubscription.prototype, 'isHidden', false);
|
|
3794
|
-
defineSignal(RequestSubscription.prototype, 'isRefreshing', false);
|
|
3795
|
-
defineSignal(RequestSubscription.prototype, '_localRequest', undefined);
|
|
3796
|
-
defineSignal(RequestSubscription.prototype, '_latestRequest', undefined);
|
|
3797
|
-
function isStore(store) {
|
|
3798
|
-
return 'requestManager' in store;
|
|
3799
|
-
}
|
|
3800
|
-
function createRequestSubscription(store, args) {
|
|
3801
|
-
return new RequestSubscription(store, args);
|
|
3802
|
-
}
|
|
3803
|
-
function upgradeSubscription(sub) {
|
|
3804
|
-
return sub;
|
|
3805
|
-
}
|
|
3806
|
-
function _DISPOSE() {
|
|
3807
|
-
const self = upgradeSubscription(this);
|
|
3808
|
-
self.isDestroyed = true;
|
|
3809
|
-
self._removeSubscriptions();
|
|
3810
|
-
if (typeof window === 'undefined') {
|
|
3811
|
-
return;
|
|
3812
|
-
}
|
|
3813
|
-
self._clearInterval();
|
|
3814
|
-
window.removeEventListener('online', self._onlineChanged, {
|
|
3815
|
-
passive: true,
|
|
3816
|
-
capture: true
|
|
3817
|
-
});
|
|
3818
|
-
window.removeEventListener('offline', self._onlineChanged, {
|
|
3819
|
-
passive: true,
|
|
3820
|
-
capture: true
|
|
3821
|
-
});
|
|
3822
|
-
document.removeEventListener('visibilitychange', self._backgroundChanged, {
|
|
3823
|
-
passive: true,
|
|
3824
|
-
capture: true
|
|
3825
|
-
});
|
|
3826
|
-
}
|
|
3827
|
-
const RequestCache = new WeakMap();
|
|
3828
|
-
function isAbortError(error) {
|
|
3829
|
-
return error instanceof DOMException && error.name === 'AbortError';
|
|
3830
|
-
}
|
|
3831
|
-
function upgradeLoadingState(state) {
|
|
3832
|
-
return state;
|
|
3833
|
-
}
|
|
3834
|
-
async function watchStream(stream, loadingState) {
|
|
3835
|
-
const state = upgradeLoadingState(loadingState);
|
|
3836
|
-
const reader = stream.getReader();
|
|
3837
|
-
let bytesLoaded = 0;
|
|
3838
|
-
let shouldForward = state._stream !== null && state._stream.readable.locked;
|
|
3839
|
-
let isForwarding = shouldForward;
|
|
3840
|
-
let writer = state._stream?.writable.getWriter();
|
|
3841
|
-
const buffer = [];
|
|
3842
|
-
state._isPending = false;
|
|
3843
|
-
state._isStarted = true;
|
|
3844
|
-
state._startTime = performance.now();
|
|
3845
|
-
while (true) {
|
|
3846
|
-
const {
|
|
3847
|
-
value,
|
|
3848
|
-
done
|
|
3849
|
-
} = await reader.read();
|
|
3850
|
-
if (done) {
|
|
3851
|
-
break;
|
|
3852
|
-
}
|
|
3853
|
-
bytesLoaded += value.byteLength;
|
|
3854
|
-
state._bytesLoaded = bytesLoaded;
|
|
3855
|
-
state._lastPacketTime = performance.now();
|
|
3856
|
-
shouldForward = shouldForward || state._stream !== null && state._stream.readable.locked;
|
|
3857
|
-
if (shouldForward) {
|
|
3858
|
-
if (!isForwarding) {
|
|
3859
|
-
isForwarding = true;
|
|
3860
|
-
writer = state._stream.writable.getWriter();
|
|
3861
|
-
for (const item of buffer) {
|
|
3862
|
-
await writer.ready;
|
|
3863
|
-
await writer.write(item);
|
|
3864
|
-
}
|
|
3865
|
-
buffer.length = 0;
|
|
3866
|
-
}
|
|
3867
|
-
await writer.ready;
|
|
3868
|
-
await writer.write(value);
|
|
3869
|
-
} else {
|
|
3870
|
-
buffer.push(value);
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
|
|
3874
|
-
// if we are still forwarding, we need to close the writer
|
|
3875
|
-
if (isForwarding) {
|
|
3876
|
-
await writer.ready;
|
|
3877
|
-
await writer.close();
|
|
3878
|
-
} else if (state._stream) {
|
|
3879
|
-
// if we are not forwarding, we need to cancel the stream
|
|
3880
|
-
await state._stream.readable.cancel('The Stream Has Already Ended');
|
|
3881
|
-
state._stream = null;
|
|
3882
|
-
}
|
|
3883
|
-
const endTime = performance.now();
|
|
3884
|
-
state._endTime = endTime;
|
|
3885
|
-
state._isComplete = true;
|
|
3886
|
-
state._isStarted = false;
|
|
3887
|
-
}
|
|
3888
|
-
|
|
3889
|
-
/**
|
|
3890
|
-
* Lazily consumes the stream of a request, providing a number of
|
|
3891
|
-
* reactive properties that can be used to build UIs that respond
|
|
3892
|
-
* to the progress of a request.
|
|
3893
|
-
*
|
|
3894
|
-
* @hideconstructor
|
|
3895
|
-
*/
|
|
3896
|
-
class RequestLoadingState {
|
|
3897
|
-
/** @internal */
|
|
3898
|
-
|
|
3899
|
-
/** @internal */
|
|
3900
|
-
|
|
3901
|
-
/** @internal */
|
|
3902
|
-
|
|
3903
|
-
/** @internal */
|
|
3904
|
-
|
|
3905
|
-
/** @internal */
|
|
3906
|
-
|
|
3907
|
-
/** @internal */
|
|
3908
|
-
|
|
3909
|
-
/** @internal */
|
|
3910
|
-
|
|
3911
|
-
/** @internal */
|
|
3912
|
-
|
|
3913
|
-
/** @internal */
|
|
3914
|
-
|
|
3915
|
-
/** @internal */
|
|
3916
|
-
|
|
3917
|
-
/** @internal */
|
|
3918
|
-
|
|
3919
|
-
/** @internal */
|
|
3920
|
-
_stream = null;
|
|
3921
|
-
/** @internal */
|
|
3922
|
-
_future;
|
|
3923
|
-
/** @internal */
|
|
3924
|
-
_triggered = false;
|
|
3925
|
-
/** @internal */
|
|
3926
|
-
_trigger() {
|
|
3927
|
-
if (this._triggered) {
|
|
3928
|
-
return;
|
|
3929
|
-
}
|
|
3930
|
-
this._triggered = true;
|
|
3931
|
-
const future = this._future;
|
|
3932
|
-
const promise = future.getStream();
|
|
3933
|
-
if (promise.sizeHint) {
|
|
3934
|
-
this._sizeHint = promise.sizeHint;
|
|
3935
|
-
}
|
|
3936
|
-
this.promise = promise.then(stream => {
|
|
3937
|
-
if (!stream) {
|
|
3938
|
-
this._isPending = false;
|
|
3939
|
-
this._isComplete = true;
|
|
3940
|
-
return;
|
|
3941
|
-
}
|
|
3942
|
-
return watchStream(stream, this);
|
|
3943
|
-
}, error => {
|
|
3944
|
-
this._isPending = false;
|
|
3945
|
-
this._isStarted = false;
|
|
3946
|
-
if (isAbortError(error)) {
|
|
3947
|
-
this._isCancelled = true;
|
|
3948
|
-
this._isComplete = true;
|
|
3949
|
-
}
|
|
3950
|
-
this._isErrored = true;
|
|
3951
|
-
this._error = error;
|
|
3952
|
-
});
|
|
3953
|
-
}
|
|
3954
|
-
promise = null;
|
|
3955
|
-
get isPending() {
|
|
3956
|
-
this._trigger();
|
|
3957
|
-
return this._isPending;
|
|
3958
|
-
}
|
|
3959
|
-
get sizeHint() {
|
|
3960
|
-
this._trigger();
|
|
3961
|
-
return this._sizeHint;
|
|
3962
|
-
}
|
|
3963
|
-
get stream() {
|
|
3964
|
-
this._trigger();
|
|
3965
|
-
if (!this._stream) {
|
|
3966
|
-
if (this._isComplete || this._isCancelled || this._isErrored) {
|
|
3967
|
-
return null;
|
|
3968
|
-
}
|
|
3969
|
-
this._stream = new TransformStream();
|
|
3970
|
-
}
|
|
3971
|
-
return this._stream.readable;
|
|
3972
|
-
}
|
|
3973
|
-
get isStarted() {
|
|
3974
|
-
this._trigger();
|
|
3975
|
-
return this._isStarted;
|
|
3976
|
-
}
|
|
3977
|
-
get bytesLoaded() {
|
|
3978
|
-
this._trigger();
|
|
3979
|
-
return this._bytesLoaded;
|
|
3980
|
-
}
|
|
3981
|
-
get startTime() {
|
|
3982
|
-
this._trigger();
|
|
3983
|
-
return this._startTime;
|
|
3984
|
-
}
|
|
3985
|
-
get endTime() {
|
|
3986
|
-
this._trigger();
|
|
3987
|
-
return this._endTime;
|
|
3988
|
-
}
|
|
3989
|
-
get lastPacketTime() {
|
|
3990
|
-
this._trigger();
|
|
3991
|
-
return this._lastPacketTime;
|
|
3992
|
-
}
|
|
3993
|
-
get isComplete() {
|
|
3994
|
-
this._trigger();
|
|
3995
|
-
return this._isComplete;
|
|
3996
|
-
}
|
|
3997
|
-
get isCancelled() {
|
|
3998
|
-
this._trigger();
|
|
3999
|
-
return this._isCancelled;
|
|
4000
|
-
}
|
|
4001
|
-
get isErrored() {
|
|
4002
|
-
this._trigger();
|
|
4003
|
-
return this._isErrored;
|
|
4004
|
-
}
|
|
4005
|
-
get error() {
|
|
4006
|
-
this._trigger();
|
|
4007
|
-
return this._error;
|
|
4008
|
-
}
|
|
4009
|
-
get elapsedTime() {
|
|
4010
|
-
return (this.endTime || this.lastPacketTime) - this.startTime;
|
|
4011
|
-
}
|
|
4012
|
-
get completedRatio() {
|
|
4013
|
-
return this.sizeHint ? this.bytesLoaded / this.sizeHint : 0;
|
|
4014
|
-
}
|
|
4015
|
-
get remainingRatio() {
|
|
4016
|
-
return 1 - this.completedRatio;
|
|
4017
|
-
}
|
|
4018
|
-
get duration() {
|
|
4019
|
-
return this.endTime - this.startTime;
|
|
4020
|
-
}
|
|
4021
|
-
get speed() {
|
|
4022
|
-
// bytes per second
|
|
4023
|
-
return this.bytesLoaded / (this.elapsedTime / 1000);
|
|
4024
|
-
}
|
|
4025
|
-
constructor(future) {
|
|
4026
|
-
this._future = future;
|
|
4027
|
-
}
|
|
4028
|
-
abort = () => {
|
|
4029
|
-
this._future.abort();
|
|
4030
|
-
};
|
|
4031
|
-
}
|
|
4032
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isPending', true);
|
|
4033
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isStarted', false);
|
|
4034
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isComplete', false);
|
|
4035
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isCancelled', false);
|
|
4036
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_isErrored', false);
|
|
4037
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_error', null);
|
|
4038
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_sizeHint', 0);
|
|
4039
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_bytesLoaded', 0);
|
|
4040
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_startTime', 0);
|
|
4041
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_endTime', 0);
|
|
4042
|
-
defineNonEnumerableSignal(RequestLoadingState.prototype, '_lastPacketTime', 0);
|
|
4043
|
-
|
|
4044
|
-
/**
|
|
4045
|
-
* The state of a request in the "pending"
|
|
4046
|
-
* state. This is the default initial state.
|
|
4047
|
-
*
|
|
4048
|
-
* Extends the {@link PendingPromise} interface.
|
|
4049
|
-
*
|
|
4050
|
-
*/
|
|
4051
|
-
|
|
4052
|
-
/**
|
|
4053
|
-
* The state of a request in the "fulfilled" state.
|
|
4054
|
-
* This is the state of a request that has resolved
|
|
4055
|
-
* successfully.
|
|
4056
|
-
*
|
|
4057
|
-
* Extends the {@link ResolvedPromise} interface.
|
|
4058
|
-
*
|
|
4059
|
-
*/
|
|
4060
|
-
|
|
4061
|
-
/**
|
|
4062
|
-
* The state of a request in the "rejected" state.
|
|
4063
|
-
* This is the state of a request that has rejected
|
|
4064
|
-
* with an error.
|
|
4065
|
-
*
|
|
4066
|
-
* Extends the {@link RejectedPromise} interface.
|
|
4067
|
-
*
|
|
4068
|
-
*/
|
|
4069
|
-
|
|
4070
|
-
/**
|
|
4071
|
-
* The state of a request in the "cancelled" state.
|
|
4072
|
-
* This is the state of a promise that has been
|
|
4073
|
-
* cancelled.
|
|
4074
|
-
*
|
|
4075
|
-
*/
|
|
4076
|
-
|
|
4077
|
-
/**
|
|
4078
|
-
* RequestState extends the concept of {@link PromiseState} to provide a reactive
|
|
4079
|
-
* wrapper for a request {@link Future} which allows you write declarative code
|
|
4080
|
-
* around a Future's control flow.
|
|
4081
|
-
*
|
|
4082
|
-
* It is useful in both Template and JavaScript contexts, allowing you
|
|
4083
|
-
* to quickly derive behaviors and data from pending, error and success
|
|
4084
|
-
* states.
|
|
4085
|
-
*
|
|
4086
|
-
* The key difference between a {@link Promise} and a Future is that Futures provide
|
|
4087
|
-
* access to a {@link ReadableStream | stream} of their content, the {@link RequestKey} of the request (if any)
|
|
4088
|
-
* as well as the ability to attempt to {@link Future.abort | abort} the request.
|
|
4089
|
-
*
|
|
4090
|
-
* ```ts
|
|
4091
|
-
* interface Future<T> extends Promise<T>> {
|
|
4092
|
-
* getStream(): Promise<ReadableStream>;
|
|
4093
|
-
* abort(): void;
|
|
4094
|
-
* lid: RequestKey | null;
|
|
4095
|
-
* }
|
|
4096
|
-
* ```
|
|
4097
|
-
*
|
|
4098
|
-
* These additional APIs allow us to craft even richer state experiences.
|
|
4099
|
-
*
|
|
4100
|
-
* To get the state of a request, use {@link getRequestState}.
|
|
4101
|
-
*
|
|
4102
|
-
* See also:
|
|
4103
|
-
* - {@link PendingRequest}
|
|
4104
|
-
* - {@link ResolvedRequest}
|
|
4105
|
-
* - {@link RejectedRequest}
|
|
4106
|
-
* - {@link CancelledRequest}
|
|
4107
|
-
*
|
|
4108
|
-
*/
|
|
4109
|
-
|
|
4110
|
-
const RequestStateProto = {};
|
|
4111
|
-
function performRefresh(requester, request, isReload) {
|
|
4112
|
-
const req = Object.assign({}, request);
|
|
4113
|
-
const cacheOptions = Object.assign({}, req.cacheOptions);
|
|
4114
|
-
if (isReload) {
|
|
4115
|
-
// force direct to network
|
|
4116
|
-
cacheOptions.reload = true;
|
|
4117
|
-
} else if (isReload === false) {
|
|
4118
|
-
// delete reload to ensure we use backgroundReload / policy
|
|
4119
|
-
delete cacheOptions.reload;
|
|
4120
|
-
cacheOptions.backgroundReload = true;
|
|
4121
|
-
} else {
|
|
4122
|
-
// delete props to ensure we use the policy
|
|
4123
|
-
delete cacheOptions.backgroundReload;
|
|
4124
|
-
delete cacheOptions.reload;
|
|
4125
|
-
}
|
|
4126
|
-
req.cacheOptions = cacheOptions;
|
|
4127
|
-
return requester.request(req);
|
|
4128
|
-
}
|
|
4129
|
-
|
|
4130
|
-
// TODO introduce a new mechanism for defining multiple properties
|
|
4131
|
-
// that share a common signal
|
|
4132
|
-
defineSignal(RequestStateProto, 'reason', null);
|
|
4133
|
-
defineSignal(RequestStateProto, 'value', null);
|
|
4134
|
-
defineSignal(RequestStateProto, 'result', null);
|
|
4135
|
-
defineSignal(RequestStateProto, 'error', null);
|
|
4136
|
-
defineSignal(RequestStateProto, 'status', 'pending');
|
|
4137
|
-
defineSignal(RequestStateProto, 'isPending', true);
|
|
4138
|
-
defineSignal(RequestStateProto, 'isLoading', true);
|
|
4139
|
-
defineSignal(RequestStateProto, 'isSuccess', false);
|
|
4140
|
-
defineSignal(RequestStateProto, 'isError', false);
|
|
4141
|
-
defineSignal(RequestStateProto, 'request', null);
|
|
4142
|
-
defineSignal(RequestStateProto, 'response', null);
|
|
4143
|
-
Object.defineProperty(RequestStateProto, 'isCancelled', {
|
|
4144
|
-
get() {
|
|
4145
|
-
return this.isError && isAbortError(this.reason);
|
|
4146
|
-
}
|
|
4147
|
-
});
|
|
4148
|
-
Object.defineProperty(RequestStateProto, 'loadingState', {
|
|
4149
|
-
get() {
|
|
4150
|
-
if (!this._loadingState) {
|
|
4151
|
-
this._loadingState = new RequestLoadingState(this._request);
|
|
4152
|
-
}
|
|
4153
|
-
return this._loadingState;
|
|
4154
|
-
}
|
|
4155
|
-
});
|
|
4156
|
-
function createRequestState(future) {
|
|
4157
|
-
const state = getPromiseResult(future);
|
|
4158
|
-
const promiseState = Object.create(RequestStateProto);
|
|
4159
|
-
promiseState._request = future;
|
|
4160
|
-
// @ts-expect-error - we still attach it for PendingState
|
|
4161
|
-
promiseState.reload = () => {
|
|
4162
|
-
return performRefresh(future.requester, promiseState.request, true);
|
|
4163
|
-
};
|
|
4164
|
-
|
|
4165
|
-
// @ts-expect-error - we still attach it for PendingState
|
|
4166
|
-
promiseState.refresh = (usePolicy = false) => {
|
|
4167
|
-
return performRefresh(future.requester, promiseState.request, usePolicy === true ? null : false);
|
|
4168
|
-
};
|
|
4169
|
-
if (state) {
|
|
4170
|
-
if (state.isError) {
|
|
4171
|
-
promiseState.error = state.result;
|
|
4172
|
-
promiseState.reason = state.result;
|
|
4173
|
-
promiseState.status = 'rejected';
|
|
4174
|
-
promiseState.isError = true;
|
|
4175
|
-
promiseState.isPending = false;
|
|
4176
|
-
promiseState.isLoading = false;
|
|
4177
|
-
promiseState.request = state.result.request;
|
|
4178
|
-
promiseState.response = state.result.response;
|
|
4179
|
-
} else {
|
|
4180
|
-
promiseState.result = state.result.content;
|
|
4181
|
-
promiseState.value = state.result.content;
|
|
4182
|
-
promiseState.status = 'fulfilled';
|
|
4183
|
-
promiseState.isSuccess = true;
|
|
4184
|
-
promiseState.isPending = false;
|
|
4185
|
-
promiseState.isLoading = false;
|
|
4186
|
-
promiseState.request = state.result.request;
|
|
4187
|
-
promiseState.response = state.result.response;
|
|
4188
|
-
}
|
|
4189
|
-
} else {
|
|
4190
|
-
void future.then(result => {
|
|
4191
|
-
setPromiseResult(future, {
|
|
4192
|
-
isError: false,
|
|
4193
|
-
result
|
|
4194
|
-
});
|
|
4195
|
-
promiseState.result = result.content;
|
|
4196
|
-
promiseState.value = result.content;
|
|
4197
|
-
promiseState.status = 'fulfilled';
|
|
4198
|
-
promiseState.isSuccess = true;
|
|
4199
|
-
promiseState.isPending = false;
|
|
4200
|
-
promiseState.isLoading = false;
|
|
4201
|
-
promiseState.request = result.request;
|
|
4202
|
-
promiseState.response = result.response;
|
|
4203
|
-
}, error => {
|
|
4204
|
-
setPromiseResult(future, {
|
|
4205
|
-
isError: true,
|
|
4206
|
-
result: error
|
|
4207
|
-
});
|
|
4208
|
-
promiseState.error = error;
|
|
4209
|
-
promiseState.reason = error;
|
|
4210
|
-
promiseState.status = 'rejected';
|
|
4211
|
-
promiseState.isError = true;
|
|
4212
|
-
promiseState.isPending = false;
|
|
4213
|
-
promiseState.isLoading = false;
|
|
4214
|
-
promiseState.request = error.request;
|
|
4215
|
-
promiseState.response = error.response;
|
|
4216
|
-
});
|
|
4217
|
-
}
|
|
4218
|
-
return promiseState;
|
|
4219
|
-
}
|
|
4220
|
-
|
|
4221
|
-
/**
|
|
4222
|
-
* `getRequestState` can be used in both JavaScript and Template contexts.
|
|
4223
|
-
*
|
|
4224
|
-
* ```ts
|
|
4225
|
-
* import { getRequestState } from '@warp-drive/ember';
|
|
4226
|
-
*
|
|
4227
|
-
* const state = getRequestState(future);
|
|
4228
|
-
* ```
|
|
4229
|
-
*
|
|
4230
|
-
* For instance, we could write a getter on a component that updates whenever
|
|
4231
|
-
* the request state advances or the future changes, by combining the function
|
|
4232
|
-
* with the use of `@cached`
|
|
4233
|
-
*
|
|
4234
|
-
* ```ts
|
|
4235
|
-
* class Component {
|
|
4236
|
-
* @cached
|
|
4237
|
-
* get title() {
|
|
4238
|
-
* const state = getRequestState(this.args.request);
|
|
4239
|
-
* if (state.isPending) {
|
|
4240
|
-
* return 'loading...';
|
|
4241
|
-
* }
|
|
4242
|
-
* if (state.isError) { return null; }
|
|
4243
|
-
* return state.result.title;
|
|
4244
|
-
* }
|
|
4245
|
-
* }
|
|
4246
|
-
* ```
|
|
4247
|
-
*
|
|
4248
|
-
* Or in a template as a helper:
|
|
4249
|
-
*
|
|
4250
|
-
* ```gjs
|
|
4251
|
-
* import { getRequestState } from '@warp-drive/ember';
|
|
4252
|
-
*
|
|
4253
|
-
* <template>
|
|
4254
|
-
* {{#let (getRequestState @request) as |state|}}
|
|
4255
|
-
* {{#if state.isPending}}
|
|
4256
|
-
* <Spinner />
|
|
4257
|
-
* {{else if state.isError}}
|
|
4258
|
-
* <ErrorForm @error={{state.error}} />
|
|
4259
|
-
* {{else}}
|
|
4260
|
-
* <h1>{{state.result.title}}</h1>
|
|
4261
|
-
* {{/if}}
|
|
4262
|
-
* {{/let}}
|
|
4263
|
-
* </template>
|
|
4264
|
-
* ```
|
|
4265
|
-
*
|
|
4266
|
-
* If looking to use in a template, consider also the `<Request />` component
|
|
4267
|
-
* which offers a number of additional capabilities for requests *beyond* what
|
|
4268
|
-
* `RequestState` provides.
|
|
4269
|
-
*
|
|
4270
|
-
*/
|
|
4271
|
-
function getRequestState(future) {
|
|
4272
|
-
let state = RequestCache.get(future);
|
|
4273
|
-
if (!state) {
|
|
4274
|
-
state = createRequestState(future);
|
|
4275
|
-
RequestCache.set(future, state);
|
|
4276
|
-
}
|
|
4277
|
-
return state;
|
|
4278
|
-
}
|
|
4279
|
-
function getAliasField(context) {}
|
|
4280
|
-
function setAliasField(context) {
|
|
4281
|
-
return false;
|
|
4282
|
-
}
|
|
4283
|
-
const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
|
|
4284
|
-
// const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
|
|
4285
|
-
const SYNC_PROPS = new Set(['[]', 'length']);
|
|
4286
|
-
function isArrayGetter(prop) {
|
|
4287
|
-
return ARRAY_GETTER_METHODS.has(prop);
|
|
4288
|
-
}
|
|
4289
|
-
const ARRAY_SETTER_METHODS = new Set(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
|
|
4290
|
-
function isArraySetter(prop) {
|
|
4291
|
-
return ARRAY_SETTER_METHODS.has(prop);
|
|
4292
|
-
}
|
|
4293
|
-
|
|
4294
|
-
// function isSelfProp<T extends object>(self: T, prop: KeyType): prop is keyof T {
|
|
4295
|
-
// return prop in self;
|
|
4296
|
-
// }
|
|
4297
|
-
|
|
4298
|
-
function convertToInt(prop) {
|
|
4299
|
-
if (typeof prop === 'symbol') return null;
|
|
4300
|
-
const num = Number(prop);
|
|
4301
|
-
if (isNaN(num)) return null;
|
|
4302
|
-
return num % 1 === 0 ? num : null;
|
|
4303
|
-
}
|
|
4304
|
-
function safeForEach(instance, arr, store, callback, target) {
|
|
4305
|
-
if (target === undefined) {
|
|
4306
|
-
target = null;
|
|
4307
|
-
}
|
|
4308
|
-
// clone to prevent mutation
|
|
4309
|
-
arr = arr.slice();
|
|
4310
|
-
|
|
4311
|
-
// because we retrieveLatest above we need not worry if array is mutated during iteration
|
|
4312
|
-
// by unloadRecord/rollbackAttributes
|
|
4313
|
-
// push/add/removeObject may still be problematic
|
|
4314
|
-
// but this is a more traditionally expected forEach bug.
|
|
4315
|
-
const length = arr.length; // we need to access length to ensure we are consumed
|
|
4316
|
-
|
|
4317
|
-
for (let index = 0; index < length; index++) {
|
|
4318
|
-
callback.call(target, arr[index], index, instance);
|
|
4319
|
-
}
|
|
4320
|
-
return instance;
|
|
4321
|
-
}
|
|
4322
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
4323
|
-
class ManagedArray {
|
|
4324
|
-
constructor(context, owner, data) {
|
|
4325
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
4326
|
-
const self = this;
|
|
4327
|
-
this[SOURCE] = data?.slice();
|
|
4328
|
-
const IS_EDITABLE = context.editable ?? false;
|
|
4329
|
-
this[Context] = context;
|
|
4330
|
-
const schema = context.store.schema;
|
|
4331
|
-
const cache = context.store.cache;
|
|
2963
|
+
return instance;
|
|
2964
|
+
}
|
|
2965
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
2966
|
+
class ManagedArray {
|
|
2967
|
+
constructor(context, owner, data) {
|
|
2968
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
2969
|
+
const self = this;
|
|
2970
|
+
this[SOURCE] = data?.slice();
|
|
2971
|
+
const IS_EDITABLE = context.editable ?? false;
|
|
2972
|
+
this[Context] = context;
|
|
2973
|
+
const schema = context.store.schema;
|
|
2974
|
+
const cache = context.store.cache;
|
|
4332
2975
|
const {
|
|
4333
2976
|
field
|
|
4334
2977
|
} = context;
|
|
@@ -6573,166 +5216,4 @@ function mergeMap(base, toApply) {
|
|
|
6573
5216
|
base.set(key, value);
|
|
6574
5217
|
}
|
|
6575
5218
|
}
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
/**
|
|
6579
|
-
* The state of a promise in the "pending"
|
|
6580
|
-
* state. This is the default initial state.
|
|
6581
|
-
*
|
|
6582
|
-
*/
|
|
6583
|
-
|
|
6584
|
-
/**
|
|
6585
|
-
* The state of a promise in the "fulfilled" state.
|
|
6586
|
-
* This is the state of a promise that has resolved
|
|
6587
|
-
* successfully.
|
|
6588
|
-
*
|
|
6589
|
-
*/
|
|
6590
|
-
|
|
6591
|
-
/**
|
|
6592
|
-
* The state of a promise in the "rejected" state.
|
|
6593
|
-
* This is the state of a promise that has rejected
|
|
6594
|
-
* with an error.
|
|
6595
|
-
*
|
|
6596
|
-
*/
|
|
6597
|
-
|
|
6598
|
-
/**
|
|
6599
|
-
* The state of a promise. This is the type that is returned
|
|
6600
|
-
* from `getPromiseState`.
|
|
6601
|
-
*
|
|
6602
|
-
* See also:
|
|
6603
|
-
* - {@link PendingPromise}
|
|
6604
|
-
* - {@link ResolvedPromise}
|
|
6605
|
-
* - {@link RejectedPromise}
|
|
6606
|
-
*
|
|
6607
|
-
*/
|
|
6608
|
-
|
|
6609
|
-
const PromiseStateProto = {};
|
|
6610
|
-
|
|
6611
|
-
// TODO introduce a new mechanism for defining multiple properties
|
|
6612
|
-
// that share a common signal
|
|
6613
|
-
defineSignal(PromiseStateProto, 'reason', null);
|
|
6614
|
-
defineSignal(PromiseStateProto, 'value', null);
|
|
6615
|
-
defineSignal(PromiseStateProto, 'result', null);
|
|
6616
|
-
defineSignal(PromiseStateProto, 'error', null);
|
|
6617
|
-
defineSignal(PromiseStateProto, 'status', 'pending');
|
|
6618
|
-
defineSignal(PromiseStateProto, 'isPending', true);
|
|
6619
|
-
defineSignal(PromiseStateProto, 'isLoading', true);
|
|
6620
|
-
defineSignal(PromiseStateProto, 'isSuccess', false);
|
|
6621
|
-
defineSignal(PromiseStateProto, 'isError', false);
|
|
6622
|
-
function createPromiseState(promise) {
|
|
6623
|
-
const state = getPromiseResult(promise);
|
|
6624
|
-
const promiseState = Object.create(PromiseStateProto);
|
|
6625
|
-
if (state) {
|
|
6626
|
-
if (state.isError) {
|
|
6627
|
-
promiseState.error = state.result;
|
|
6628
|
-
promiseState.reason = state.result;
|
|
6629
|
-
promiseState.status = 'rejected';
|
|
6630
|
-
promiseState.isError = true;
|
|
6631
|
-
promiseState.isPending = false;
|
|
6632
|
-
promiseState.isLoading = false;
|
|
6633
|
-
} else {
|
|
6634
|
-
promiseState.result = state.result;
|
|
6635
|
-
promiseState.value = state.result;
|
|
6636
|
-
promiseState.status = 'fulfilled';
|
|
6637
|
-
promiseState.isSuccess = true;
|
|
6638
|
-
promiseState.isPending = false;
|
|
6639
|
-
promiseState.isLoading = false;
|
|
6640
|
-
}
|
|
6641
|
-
} else {
|
|
6642
|
-
void promise.then(result => {
|
|
6643
|
-
setPromiseResult(promise, {
|
|
6644
|
-
isError: false,
|
|
6645
|
-
result
|
|
6646
|
-
});
|
|
6647
|
-
promiseState.result = result;
|
|
6648
|
-
promiseState.value = result;
|
|
6649
|
-
promiseState.status = 'fulfilled';
|
|
6650
|
-
promiseState.isSuccess = true;
|
|
6651
|
-
promiseState.isPending = false;
|
|
6652
|
-
promiseState.isLoading = false;
|
|
6653
|
-
}, error => {
|
|
6654
|
-
setPromiseResult(promise, {
|
|
6655
|
-
isError: true,
|
|
6656
|
-
result: error
|
|
6657
|
-
});
|
|
6658
|
-
promiseState.error = error;
|
|
6659
|
-
promiseState.reason = error;
|
|
6660
|
-
promiseState.status = 'rejected';
|
|
6661
|
-
promiseState.isError = true;
|
|
6662
|
-
promiseState.isPending = false;
|
|
6663
|
-
promiseState.isLoading = false;
|
|
6664
|
-
});
|
|
6665
|
-
}
|
|
6666
|
-
return promiseState;
|
|
6667
|
-
}
|
|
6668
|
-
const LegacyPromiseProxy = Symbol.for('LegacyPromiseProxy');
|
|
6669
|
-
function isLegacyAwaitable(promise) {
|
|
6670
|
-
return LegacyPromiseProxy in promise && 'promise' in promise && promise[LegacyPromiseProxy] === true;
|
|
6671
|
-
}
|
|
6672
|
-
function getPromise(promise) {
|
|
6673
|
-
return isLegacyAwaitable(promise) ? promise.promise : promise;
|
|
6674
|
-
}
|
|
6675
|
-
|
|
6676
|
-
/**
|
|
6677
|
-
* Returns a reactive state-machine for the provided promise or awaitable.
|
|
6678
|
-
*
|
|
6679
|
-
* Repeat calls to `getPromiseState` with the same promise will return the same state object
|
|
6680
|
-
* making is safe and easy to use in templates and JavaScript code to produce reactive
|
|
6681
|
-
* behaviors around promises.
|
|
6682
|
-
*
|
|
6683
|
-
* `getPromiseState` can be used in both JavaScript and Template contexts.
|
|
6684
|
-
*
|
|
6685
|
-
* ```ts
|
|
6686
|
-
* import { getPromiseState } from '@warp-drive/ember';
|
|
6687
|
-
*
|
|
6688
|
-
* const state = getPromiseState(promise);
|
|
6689
|
-
* ```
|
|
6690
|
-
*
|
|
6691
|
-
* For instance, we could write a getter on a component that updates whenever
|
|
6692
|
-
* the promise state advances or the promise changes, by combining the function
|
|
6693
|
-
* with the use of `@cached`
|
|
6694
|
-
*
|
|
6695
|
-
* ```ts
|
|
6696
|
-
* class Component {
|
|
6697
|
-
* @cached
|
|
6698
|
-
* get title() {
|
|
6699
|
-
* const state = getPromiseState(this.args.request);
|
|
6700
|
-
* if (state.isPending) {
|
|
6701
|
-
* return 'loading...';
|
|
6702
|
-
* }
|
|
6703
|
-
* if (state.isError) { return null; }
|
|
6704
|
-
* return state.result.title;
|
|
6705
|
-
* }
|
|
6706
|
-
* }
|
|
6707
|
-
* ```
|
|
6708
|
-
*
|
|
6709
|
-
* Or in a template as a helper:
|
|
6710
|
-
*
|
|
6711
|
-
* ```gjs
|
|
6712
|
-
* import { getPromiseState } from '@warp-drive/ember';
|
|
6713
|
-
*
|
|
6714
|
-
* <template>
|
|
6715
|
-
* {{#let (getPromiseState @request) as |state|}}
|
|
6716
|
-
* {{#if state.isPending}} <Spinner />
|
|
6717
|
-
* {{else if state.isError}} <ErrorForm @error={{state.error}} />
|
|
6718
|
-
* {{else}}
|
|
6719
|
-
* <h1>{{state.result.title}}</h1>
|
|
6720
|
-
* {{/if}}
|
|
6721
|
-
* {{/let}}
|
|
6722
|
-
* </template>
|
|
6723
|
-
* ```
|
|
6724
|
-
*
|
|
6725
|
-
* If looking to use in a template, consider also the `<Await />` component.
|
|
6726
|
-
*
|
|
6727
|
-
* See also {@link PromiseState}
|
|
6728
|
-
*/
|
|
6729
|
-
function getPromiseState(promise) {
|
|
6730
|
-
const _promise = getPromise(promise);
|
|
6731
|
-
let state = PromiseCache.get(_promise);
|
|
6732
|
-
if (!state) {
|
|
6733
|
-
state = createPromiseState(_promise);
|
|
6734
|
-
PromiseCache.set(_promise, state);
|
|
6735
|
-
}
|
|
6736
|
-
return state;
|
|
6737
|
-
}
|
|
6738
|
-
export { signal as A, memoized as B, gate as C, DISPOSE as D, entangleSignal as E, entangleInitiallyStaleSignal as F, defineSignal as G, defineGate as H, defineNonEnumerableSignal as I, Signals as J, peekInternalSignal as K, createInternalMemo as L, withSignalStore as M, notifyInternalSignal as N, consumeInternalSignal as O, getOrCreateInternalSignal as P, CacheKeyManager as Q, ReactiveResource as R, SchemaService as S, InstanceCache as T, getNewRecord as U, peekResourceKey as V, createReactiveDocument as W, _clearCaches as _, commit as a, createRequestSubscription as b, checkout as c, getPromiseState as d, recordIdentifierFor as e, fromIdentity as f, getRequestState as g, setIdentifierGenerationMethod as h, setIdentifierUpdateMethod as i, setIdentifierForgetMethod as j, setIdentifierResetMethod as k, setKeyInfoForResource as l, isResourceKey as m, coerceId as n, isRequestKey as o, ensureStringId as p, RecordArrayManager as q, registerDerivations as r, storeFor as s, fastPush as t, assertPrivateCapabilities as u, setRecordIdentifier as v, withDefaults as w, StoreMap as x, normalizeModelName as y, createLegacyManyArray as z };
|
|
5219
|
+
export { CacheKeyManager as C, InstanceCache as I, RecordArrayManager as R, SchemaService as S, _clearCaches as _, recordIdentifierFor as a, setIdentifierGenerationMethod as b, setIdentifierUpdateMethod as c, setIdentifierForgetMethod as d, setIdentifierResetMethod as e, setKeyInfoForResource as f, coerceId as g, isRequestKey as h, isResourceKey as i, ensureStringId as j, fastPush as k, assertPrivateCapabilities as l, setRecordIdentifier as m, StoreMap as n, normalizeModelName as o, createLegacyManyArray as p, getNewRecord as q, registerDerivations as r, storeFor as s, peekResourceKey as t, createReactiveDocument as u, ReactiveResource as v, checkout as w, withDefaults as x, fromIdentity as y, commit as z };
|