@warp-drive/core 5.7.0-alpha.30 → 5.7.0-alpha.32

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.
@@ -16,7 +16,6 @@ import type { Meta, PaginationLinks } from "../../types/spec/json-api-raw.js";
16
16
  * @hideconstructor
17
17
  */
18
18
  export declare class ReactiveDocument<T> {
19
- #private;
20
19
  /**
21
20
  * The links object for this document, if any
22
21
  *
@@ -61,11 +60,6 @@ export declare class ReactiveDocument<T> {
61
60
  * @public
62
61
  */
63
62
  readonly identifier: RequestKey | null;
64
- protected readonly _store: Store;
65
- protected readonly _localCache: {
66
- document: ResourceDocument;
67
- request: ImmutableRequestInfo;
68
- } | null;
69
63
  constructor(store: Store, cacheKey: RequestKey | null, localCache: {
70
64
  document: ResourceDocument;
71
65
  request: ImmutableRequestInfo;
@@ -26,16 +26,14 @@ export declare class ContextOwner {
26
26
  setResponse(response: ResponseInfo | Response | null): void;
27
27
  }
28
28
  export declare class Context {
29
- private ___owner;
30
29
  request: ImmutableRequestInfo;
31
30
  id: number;
32
- private _isCacheHandler;
33
- private _finalized;
34
31
  constructor(owner: ContextOwner, isCacheHandler: boolean);
35
32
  setStream(stream: ReadableStream | Promise<ReadableStream | null>): void;
36
33
  setResponse(response: ResponseInfo | Response | null): void;
37
34
  setIdentifier(identifier: RequestKey): void;
38
35
  get hasRequestedStream(): boolean;
36
+ /** @private */
39
37
  _finalize(): void;
40
38
  }
41
39
  export type HandlerRequestContext = Context;
@@ -1,6 +1,7 @@
1
1
  export declare function logGroup(scope: "cache", prefix: string, type: string, lid: string, bucket: string, key: string): void;
2
2
  export declare function logGroup(scope: "reactive-ui", prefix: string, type: string, lid: string, bucket: string, key: ""): void;
3
3
  export declare function logGroup(scope: "notify", prefix: string, type: string, lid: string, bucket: string, key: string): void;
4
+ export declare function log(scope: "request", prefix: string, type: string, lid: string, bucket: string, key: string): void;
4
5
  export declare function log(scope: "cache", prefix: string, type: string, lid: string, bucket: string, key: string): void;
5
6
  export declare function log(scope: "reactive-ui", prefix: string, type: string, lid: string, bucket: string, key: ""): void;
6
7
  export declare function log(scope: "notify", prefix: string, type: string, lid: string, bucket: string, key: string): void;
@@ -29,7 +29,6 @@ import type { StoreRequestContext } from "../cache-handler/handler.js";
29
29
  */
30
30
  export declare class CacheManager implements Cache {
31
31
  version: "2";
32
- private ___cache;
33
32
  constructor(cache: Cache);
34
33
  // Cache Management
35
34
  // ================
@@ -72,7 +72,6 @@ export default class NotificationManager {
72
72
  notify(cacheKey: ResourceKey, value: "errors" | "meta" | "identity" | "state", key?: null): boolean;
73
73
  notify(cacheKey: ResourceKey, value: CacheOperation, key?: null): boolean;
74
74
  notify(cacheKey: RequestKey, value: DocumentCacheOperation, key?: null): boolean;
75
- private _scheduleNotify;
76
75
  }
77
76
  /**
78
77
  * This type exists for internal use only for
@@ -75,7 +75,6 @@ export declare class RecordArrayManager {
75
75
  getCollection(config: LegacyQueryInit): LegacyQueryArray;
76
76
  getCollection(config: AnonymousRequestCollectionInit): ReactiveResourceArray;
77
77
  getCollection(config: RequestCollectionInit): ReactiveResourceArray;
78
- private dirtyArray;
79
78
  /**
80
79
  * @private
81
80
  */
@@ -43,9 +43,6 @@ export type RequestSubscription = (requestState: RequestCacheRequestState) => vo
43
43
  */
44
44
  export declare class RequestStateService {
45
45
  constructor(store: Store);
46
- private _flushRequest;
47
- private _dequeue;
48
- private _addDone;
49
46
  /**
50
47
  * Subscribe to requests for a given resource identity.
51
48
  *
@@ -147,6 +147,8 @@ export declare function initializeSignalStore<T extends object>(obj: T): asserts
147
147
  };
148
148
  export declare function createInternalSignal(signals: SignalStore, obj: object, key: string | symbol, initialValue: unknown): WarpDriveSignal;
149
149
  export declare function getOrCreateInternalSignal(signals: SignalStore, obj: object, key: string | symbol, initialValue: unknown): WarpDriveSignal;
150
+ export declare function createInternalMemo<T>(signals: SignalStore, object: object, key: string | symbol, fn: () => T): () => T;
151
+ export declare function consumeInternalMemo<T>(fn: () => T): T;
150
152
  export declare function peekInternalSignal(signals: SignalStore | undefined, key: string | symbol): WarpDriveSignal | undefined;
151
153
  export declare function consumeInternalSignal(signal: WarpDriveSignal): void;
152
154
  export declare function notifyInternalSignal(signal: WarpDriveSignal | undefined): void;
@@ -7,6 +7,7 @@ import type { SignalStore, WarpDriveSignal } from "./internal.js";
7
7
  * @private
8
8
  */
9
9
  export declare function entangleSignal<T extends object>(signals: SignalStore, obj: T, key: string | symbol, initialValue: unknown): WarpDriveSignal;
10
+ export declare function entangleInitiallyStaleSignal<T extends object>(signals: SignalStore, obj: T, key: string | symbol, initialValue: unknown): WarpDriveSignal;
10
11
  export declare function createSignalDescriptor(key: string | symbol, intialValue: unknown): PropertyDescriptor;
11
12
  /**
12
13
  * define an enumerable signal property.
@@ -10,21 +10,6 @@ import type { PendingPromise, RejectedPromise, ResolvedPromise } from "./promise
10
10
  * @hideconstructor
11
11
  */
12
12
  export declare class RequestLoadingState {
13
- private _sizeHint;
14
- private _bytesLoaded;
15
- private _startTime;
16
- private _endTime;
17
- private _lastPacketTime;
18
- private _isPending;
19
- private _isStarted;
20
- private _isComplete;
21
- private _isCancelled;
22
- private _isErrored;
23
- private _error;
24
- private _stream;
25
- private _future;
26
- private _triggered;
27
- private _trigger;
28
13
  promise: Promise<void> | null;
29
14
  get isPending(): boolean;
30
15
  get sizeHint(): number;
@@ -3,11 +3,6 @@ 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
- export interface ErrorFeatures {
7
- isHidden: boolean;
8
- isOnline: boolean;
9
- retry: () => Promise<void>;
10
- }
11
6
  export type AutorefreshBehaviorType = "online" | "interval" | "invalid";
12
7
  export type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
13
8
  /**
@@ -18,6 +13,8 @@ export interface RecoveryFeatures {
18
13
  isHidden: boolean;
19
14
  retry: () => Promise<void>;
20
15
  }
16
+ /** @deprecated use {@link RecoveryFeatures} */
17
+ export type ErrorFeatures = RecoveryFeatures;
21
18
  /**
22
19
  * Utilities for keeping the request fresh
23
20
  */
@@ -156,16 +153,6 @@ export declare class RequestSubscription<
156
153
  constructor(store: Store | RequestManager, args: SubscriptionArgs<RT, E>);
157
154
  get isIdle(): boolean;
158
155
  get autorefreshTypes(): Set<AutorefreshBehaviorType>;
159
- // we only run this function on component creation
160
- // and when an update is triggered, so it does not
161
- // react to changes in the autorefreshThreshold
162
- // or autorefresh args.
163
- //
164
- // if we need to react to those changes, we can
165
- // use a modifier or internal component or some
166
- // such to trigger a re-run of this function.
167
- private _scheduleInterval;
168
- private _clearInterval;
169
156
  /**
170
157
  * Retry the request, reloading it from the server.
171
158
  */
@@ -177,7 +164,7 @@ export declare class RequestSubscription<
177
164
  /**
178
165
  * features to yield to the error slot of a component
179
166
  */
180
- get errorFeatures(): ErrorFeatures;
167
+ get errorFeatures(): RecoveryFeatures;
181
168
  /**
182
169
  * features to yield to the content slot of a component
183
170
  */
@@ -30,6 +30,6 @@ export { log, logGroup } from "./-private/debug/utils.js";
30
30
  export { getPromiseState, type PromiseState } from "./-private/new-core-tmp/promise-state.js";
31
31
  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";
32
32
  export { getRequestState, type RequestLoadingState, type RequestCacheRequestState as RequestState } from "./-private/new-core-tmp/request-state.js";
33
- export { createMemo, type SignalHooks, waitFor } from "./-private/new-core-tmp/reactivity/configure.js";
34
- export { signal, memoized, gate, entangleSignal, defineSignal, defineGate, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
35
- export { ARRAY_SIGNAL, OBJECT_SIGNAL, Signals, type WarpDriveSignal, peekInternalSignal, withSignalStore, notifyInternalSignal, consumeInternalSignal, getOrCreateInternalSignal } from "./-private/new-core-tmp/reactivity/internal.js";
33
+ export { type SignalHooks, waitFor } from "./-private/new-core-tmp/reactivity/configure.js";
34
+ export { signal, memoized, gate, entangleSignal, entangleInitiallyStaleSignal, defineSignal, defineGate, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
35
+ export { ARRAY_SIGNAL, OBJECT_SIGNAL, Signals, type WarpDriveSignal, peekInternalSignal, createInternalMemo, withSignalStore, notifyInternalSignal, consumeInternalSignal, getOrCreateInternalSignal } from "./-private/new-core-tmp/reactivity/internal.js";
@@ -178,4 +178,4 @@ function waitFor(promise) {
178
178
  }
179
179
  return promise;
180
180
  }
181
- export { ARRAY_SIGNAL as A, OBJECT_SIGNAL as O, createSignal as a, consumeSignal as b, createMemo as c, willSyncFlushWatchers as d, notifySignal as n, setupSignals as s, waitFor as w };
181
+ export { ARRAY_SIGNAL as A, OBJECT_SIGNAL as O, consumeSignal as a, createMemo as b, createSignal as c, willSyncFlushWatchers as d, notifySignal as n, setupSignals as s, waitFor as w };
package/dist/configure.js CHANGED
@@ -1 +1 @@
1
- export { s as setupSignals } from "./configure-CiFDHArV.js";
1
+ export { s as setupSignals } from "./configure-C3x8YXzL.js";
@@ -639,6 +639,12 @@ class ContextOwner {
639
639
  }
640
640
  }
641
641
  class Context {
642
+ /** @internal */
643
+
644
+ /** @internal */
645
+
646
+ /** @internal */
647
+
642
648
  constructor(owner, isCacheHandler) {
643
649
  this.id = owner.requestId;
644
650
  this.___owner = owner;
@@ -663,6 +669,8 @@ class Context {
663
669
  get hasRequestedStream() {
664
670
  return this.___owner.hasRequestedStream;
665
671
  }
672
+
673
+ /** @private */
666
674
  _finalize() {
667
675
  this._finalized = true;
668
676
  }
package/dist/index.js CHANGED
@@ -1,10 +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-Bh-MA_tH.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-C_7OLieY.js";
3
3
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
- import { w as waitFor } from "./configure-CiFDHArV.js";
4
+ import { w as waitFor } from "./configure-C3x8YXzL.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, Q as setIdentifierForgetMethod, O as setIdentifierGenerationMethod, T as setIdentifierResetMethod, P as setIdentifierUpdateMethod, U as setKeyInfoForResource, s as storeFor } from "./request-state-B908BvPK.js";
7
+ export { C as CacheHandler, S as Store, r as recordIdentifierFor, U as setIdentifierForgetMethod, Q as setIdentifierGenerationMethod, V as setIdentifierResetMethod, T as setIdentifierUpdateMethod, W as setKeyInfoForResource, s as storeFor } from "./request-state-CxDzTjFX.js";
8
8
  import '@ember/debug';
9
9
  import './utils/string.js';
10
10
  import "./symbols-sql1_mdx.js";
package/dist/reactive.js CHANGED
@@ -1,5 +1,5 @@
1
- import { J as ReactiveResource, K as isNonIdentityCacheableField, L as getFieldCacheKeyStrict, r as recordIdentifierFor, F as withSignalStore } from "./request-state-B908BvPK.js";
2
- export { M as checkout, N as commit } from "./request-state-B908BvPK.js";
1
+ import { L as ReactiveResource, M as isNonIdentityCacheableField, N as getFieldCacheKeyStrict, r as recordIdentifierFor, H as withSignalStore, G as createInternalMemo } from "./request-state-CxDzTjFX.js";
2
+ export { O as checkout, P as commit } from "./request-state-CxDzTjFX.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";
@@ -8,7 +8,7 @@ import { warn, deprecate } from '@ember/debug';
8
8
  import './index.js';
9
9
  import './types/request.js';
10
10
  import './utils/string.js';
11
- import { c as createMemo } from "./configure-CiFDHArV.js";
11
+ import "./configure-C3x8YXzL.js";
12
12
  import { getOrSetGlobal } from './types/-private.js';
13
13
  import { Type } from './types/symbols.js';
14
14
  function instantiateRecord(store, identifier, createArgs) {
@@ -311,10 +311,9 @@ function makeCachedDerivation(derivation) {
311
311
  const signals = withSignalStore(record);
312
312
  let signal = signals.get(prop);
313
313
  if (!signal) {
314
- signal = createMemo(record, prop, () => {
314
+ signal = createInternalMemo(signals, record, prop, () => {
315
315
  return derivation(record, options, prop);
316
316
  }); // a total lie, for convenience of reusing the storage
317
- signals.set(prop, signal);
318
317
  }
319
318
  return signal();
320
319
  };
@@ -6,8 +6,8 @@ import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js
6
6
  import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_KEY_TYPE, DEBUG_CLIENT_ORIGINATED } from './types/identifier.js';
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
- 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-CiFDHArV.js";
10
- import { g as getPromiseResult, s as setPromiseResult } from "./context-Bh-MA_tH.js";
9
+ import { c as createSignal, a as consumeSignal, n as notifySignal, b as createMemo, A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, d as willSyncFlushWatchers } from "./configure-C3x8YXzL.js";
10
+ import { g as getPromiseResult, s as setPromiseResult } from "./context-C_7OLieY.js";
11
11
  import { RecordStore } from './types/symbols.js';
12
12
  const INITIALIZER_PROTO = {
13
13
  isInitializer: true
@@ -121,10 +121,25 @@ function getOrCreateInternalSignal(signals, obj, key, initialValue) {
121
121
  }
122
122
  return signal;
123
123
  }
124
+ function createInternalMemo(signals, object, key, fn) {
125
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
126
+ if (!test) {
127
+ throw new Error(`Expected no signal/memo to exist for key "${String(key)}"`);
128
+ }
129
+ })(!peekInternalSignal(signals, key)) : {};
130
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
131
+ return withFrame(signals, object, key, fn);
132
+ } else {
133
+ const memo = createMemo(object, key, fn);
134
+ signals.set(key, memo);
135
+ return memo;
136
+ }
137
+ }
124
138
  function peekInternalSignal(signals, key) {
125
139
  return signals?.get(key);
126
140
  }
127
141
  function consumeInternalSignal(signal) {
142
+ TrackingFrame?.signals.add(signal);
128
143
  consumeSignal(signal.signal);
129
144
  }
130
145
  function notifyInternalSignal(signal) {
@@ -133,6 +148,164 @@ function notifyInternalSignal(signal) {
133
148
  notifySignal(signal.signal);
134
149
  }
135
150
  }
151
+ let TrackingFrame = null;
152
+
153
+ /**
154
+ * This is currently just for signals debugging, but it could be used in production
155
+ * if we wanted to eliminate the need for frameworks to implement createMemo / to
156
+ * allow us to add our own Watcher.
157
+ *
158
+ * @internal
159
+ */
160
+ function withFrame(signals, object, key, fn) {
161
+ const frameSignals = new Set();
162
+ const frameFn = () => {
163
+ if (frameSignals.size) {
164
+ frameSignals.clear();
165
+ }
166
+ TrackingFrame = {
167
+ object,
168
+ key,
169
+ signals: frameSignals,
170
+ parent: TrackingFrame
171
+ };
172
+ try {
173
+ return fn();
174
+ } finally {
175
+ TrackingFrame = TrackingFrame.parent;
176
+ }
177
+ };
178
+ const memo = createMemo(object, key, frameFn);
179
+ // @ts-expect-error
180
+ memo.signals = frameSignals;
181
+ signals.set(key, memo);
182
+ return memo;
183
+ }
184
+ function isMemo(obj) {
185
+ // @ts-expect-error
186
+ return typeof obj === 'function' && obj.signals instanceof Set;
187
+ }
188
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
189
+ // @ts-expect-error adding to global API
190
+ globalThis.debugWarpDriveSignals = (obj, key) => {
191
+ const signals = obj[Signals];
192
+ if (!signals) {
193
+ log$1('The object has no associated signals');
194
+ return false;
195
+ }
196
+ if (key) {
197
+ const signal = signals.get(key);
198
+ if (!signal) {
199
+ log$1(`No signal found for key "${String(key)}"`);
200
+ return false;
201
+ }
202
+ log$1(signal);
203
+ if (isMemo(signal)) {
204
+ colorizeLines(printMemo(signal, key));
205
+ return true;
206
+ } else {
207
+ colorizeLines(printSignal(signal, key));
208
+ return true;
209
+ }
210
+ }
211
+ const lines = [];
212
+ for (const [k, signal] of signals) {
213
+ if (isMemo(signal)) continue;
214
+ printSignal(signal, k, lines);
215
+ }
216
+ for (const [k, signal] of signals) {
217
+ if (isMemo(signal)) {
218
+ printMemo(signal, k, lines);
219
+ }
220
+ }
221
+ log$1(signals);
222
+ colorizeLines(lines);
223
+ return true;
224
+ };
225
+ }
226
+ const LightColors = {
227
+ red: 'color: red;',
228
+ green: 'color: green;',
229
+ reset: 'color: inherit;'
230
+ };
231
+ const DarkColors = {
232
+ red: 'color: red;',
233
+ green: 'color: lightgreen;',
234
+ reset: 'color: inherit;'
235
+ };
236
+ function isLightMode$1() {
237
+ if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
238
+ return true;
239
+ }
240
+ return false;
241
+ }
242
+ const RED = {};
243
+ const GREEN = {};
244
+ const RESET = {};
245
+ const EOL = {};
246
+ function colorizeLines(lines) {
247
+ const Colors = isLightMode$1() ? LightColors : DarkColors;
248
+ const colors = [];
249
+ let line = '';
250
+ for (const str of lines) {
251
+ if (str === RED) {
252
+ colors.push(Colors.red);
253
+ line += '%c';
254
+ } else if (str === GREEN) {
255
+ colors.push(Colors.green);
256
+ line += '%c';
257
+ } else if (str === RESET) {
258
+ colors.push(Colors.reset);
259
+ line += '%c';
260
+ } else if (str === EOL) {
261
+ line += '\n';
262
+ } else {
263
+ line += str;
264
+ }
265
+ }
266
+ log$1(line, ...colors);
267
+ }
268
+ function log$1(...args) {
269
+ // eslint-disable-next-line no-console
270
+ console.log(...args);
271
+ }
272
+ function isDirty(signal) {
273
+ return signal.isStale;
274
+ }
275
+ function isDirtyMemo(memo) {
276
+ // iterate simple signals first to get fastest answer
277
+ for (const signal of memo.signals) {
278
+ if (isMemo(signal)) continue;
279
+ if (isDirty(signal)) {
280
+ return true;
281
+ }
282
+ }
283
+ for (const signal of memo.signals) {
284
+ if (isMemo(signal)) {
285
+ return isDirtyMemo(signal);
286
+ }
287
+ }
288
+ return false;
289
+ }
290
+ function printSignal(signal, key, lines = [], depth = 0) {
291
+ const _dirty = isDirty(signal);
292
+ lines.push(`${''.padStart(depth * 2, ' ')}${_dirty ? '❌' : '✅'} `, _dirty ? RED : GREEN, `${String(key)}`, RESET, EOL);
293
+ return lines;
294
+ }
295
+ function printMemo(memo, key, lines = [], depth = 0) {
296
+ const _dirty = isDirtyMemo(memo);
297
+ lines.push(`${''.padStart(depth * 2, ' ')}${_dirty ? '❌' : '✅'} `, _dirty ? RED : GREEN, `<memo> ${String(key)}`, RESET, `: (consumes ${memo.signals.size} signals)`, EOL);
298
+ for (const signal of memo.signals) {
299
+ if (isMemo(signal)) continue;
300
+ printSignal(signal, signal.key, lines, depth + 1);
301
+ }
302
+ for (const signal of memo.signals) {
303
+ if (isMemo(signal)) {
304
+ printMemo(signal, signal.key, lines, depth + 1);
305
+ }
306
+ }
307
+ return lines;
308
+ }
136
309
  function entangleSignal(signals, obj, key, initialValue) {
137
310
  let internalSignal = peekInternalSignal(signals, key);
138
311
  if (!internalSignal) {
@@ -141,13 +314,24 @@ function entangleSignal(signals, obj, key, initialValue) {
141
314
  consumeInternalSignal(internalSignal);
142
315
  return internalSignal;
143
316
  }
317
+ function entangleInitiallyStaleSignal(signals, obj, key, initialValue) {
318
+ let internalSignal = peekInternalSignal(signals, key);
319
+ if (!internalSignal) {
320
+ internalSignal = createInternalSignal(signals, obj, key, initialValue);
321
+ internalSignal.isStale = true; // mark it as stale
322
+ }
323
+ consumeInternalSignal(internalSignal);
324
+ return internalSignal;
325
+ }
144
326
  function createSignalDescriptor(key, intialValue) {
145
327
  return {
146
328
  enumerable: true,
147
329
  configurable: false,
148
330
  get() {
149
331
  const signals = withSignalStore(this);
150
- return entangleSignal(signals, this, key, intialValue).value;
332
+ const internalSignal = entangleSignal(signals, this, key, intialValue);
333
+ internalSignal.isStale = false; // reset stale state
334
+ return internalSignal.value;
151
335
  },
152
336
  set(value) {
153
337
  const signals = withSignalStore(this);
@@ -229,8 +413,7 @@ function memoized(target, key, descriptor) {
229
413
  const signals = withSignalStore(this);
230
414
  let memoSignal = signals.get(key);
231
415
  if (!memoSignal) {
232
- memoSignal = createMemo(this, key, getter.bind(this));
233
- signals.set(key, memoSignal);
416
+ memoSignal = createInternalMemo(signals, this, key, getter.bind(this));
234
417
  }
235
418
  return memoSignal();
236
419
  };
@@ -352,6 +535,10 @@ class ReactiveDocument {
352
535
  * @public
353
536
  */
354
537
 
538
+ /** @internal */
539
+
540
+ /** @internal */
541
+
355
542
  constructor(store, cacheKey, localCache) {
356
543
  this._store = store;
357
544
  this._localCache = localCache;
@@ -375,6 +562,8 @@ class ReactiveDocument {
375
562
  });
376
563
  }
377
564
  }
565
+
566
+ /** @internal */
378
567
  async #request(link, options = withBrand({
379
568
  url: '',
380
569
  method: 'GET'
@@ -1191,7 +1380,7 @@ function setArrayField(context) {
1191
1380
  return true;
1192
1381
  }
1193
1382
  function getAttributeField(context) {
1194
- entangleSignal(context.signals, context.record, context.path.at(-1), null);
1383
+ entangleInitiallyStaleSignal(context.signals, context.record, context.path.at(-1), null);
1195
1384
  const {
1196
1385
  cache
1197
1386
  } = context.store;
@@ -1284,7 +1473,12 @@ function setDerivedField(context) {
1284
1473
  return false;
1285
1474
  }
1286
1475
  function getGenericField(context) {
1287
- entangleSignal(context.signals, context.record, context.path.at(-1), null);
1476
+ const signal = entangleInitiallyStaleSignal(context.signals, context.record, context.path.at(-1), null);
1477
+ // FIXME we should be able to cache the computation here, but some tests fail.
1478
+ // if (!signal.isStale) {
1479
+ // return signal.value;
1480
+ // }
1481
+ signal.isStale = false;
1288
1482
  const {
1289
1483
  cache,
1290
1484
  schema
@@ -1294,9 +1488,12 @@ function getGenericField(context) {
1294
1488
  field
1295
1489
  } = context;
1296
1490
  if (!field.type) {
1491
+ // signal.value = rawValue;
1297
1492
  return rawValue;
1298
1493
  }
1299
1494
  const transform = schema.transformation(field);
1495
+ // signal.value = transform.hydrate(rawValue, field.options ?? null, context.record);
1496
+ // return signal.value;
1300
1497
  return transform.hydrate(rawValue, field.options ?? null, context.record);
1301
1498
  }
1302
1499
  function setGenericField(context) {
@@ -2745,6 +2942,9 @@ function badge(isLight, color, bgColor, border) {
2745
2942
  return [`color: ${correctColor(isLight, color)}; background-color: ${correctColor(isLight, bgColor)}; padding: ${border}px ${2 * border}px; border-radius: ${border}px;`, `color: ${TEXT_COLORS.TEXT}; background-color: ${BG_COLORS.TEXT};`];
2746
2943
  }
2747
2944
  function colorForBucket(isLight, scope, bucket) {
2945
+ if (scope === 'request') {
2946
+ return bucket === 'blocking' ? badge(isLight, 'red', 'transparent', 0) : bucket === 'cached' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'non-blocking' ? badge(isLight, 'orange', 'transparent', 0) : badge(isLight, 'gray', 'transparent', 0);
2947
+ }
2748
2948
  if (scope === 'notify') {
2749
2949
  return bucket === 'added' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
2750
2950
  }
@@ -2779,6 +2979,7 @@ function isLightMode() {
2779
2979
  function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
2780
2980
  const isLight = isLightMode();
2781
2981
  switch (scope) {
2982
+ case 'request':
2782
2983
  case 'reactive-ui':
2783
2984
  case 'notify':
2784
2985
  {
@@ -4267,6 +4468,9 @@ function unloadRecord(instances, identifier) {
4267
4468
  */
4268
4469
  class CacheManager {
4269
4470
  version = '2';
4471
+
4472
+ /** @internal */
4473
+
4270
4474
  constructor(cache) {
4271
4475
  this.___cache = cache;
4272
4476
  }
@@ -4945,6 +5149,8 @@ class NotificationManager {
4945
5149
  _onNextFlush(cb) {
4946
5150
  this._onFlushCB = cb;
4947
5151
  }
5152
+
5153
+ /** @internal */
4948
5154
  _scheduleNotify() {
4949
5155
  const asyncFlush = this.store._enableAsyncFlush;
4950
5156
  if (this._hasFlush) {
@@ -5862,6 +6068,8 @@ class RecordArrayManager {
5862
6068
  this._managed.add(array);
5863
6069
  return array;
5864
6070
  }
6071
+
6072
+ /** @internal */
5865
6073
  dirtyArray(array, delta, shouldSyncFromCache) {
5866
6074
  if (array === FAKE_ARR) {
5867
6075
  return;
@@ -6226,6 +6434,8 @@ class RequestStateService {
6226
6434
  });
6227
6435
  this._toFlush = [];
6228
6436
  }
6437
+
6438
+ /** @internal */
6229
6439
  _flushRequest(req) {
6230
6440
  req[Touching].forEach(identifier => {
6231
6441
  const subscriptions = this._subscriptions.get(identifier);
@@ -6234,10 +6444,14 @@ class RequestStateService {
6234
6444
  }
6235
6445
  });
6236
6446
  }
6447
+
6448
+ /** @internal */
6237
6449
  _dequeue(identifier, request) {
6238
6450
  const pending = this._pending.get(identifier);
6239
6451
  this._pending.set(identifier, pending.filter(req => req !== request));
6240
6452
  }
6453
+
6454
+ /** @internal */
6241
6455
  _addDone(request) {
6242
6456
  request[Touching].forEach(identifier => {
6243
6457
  // TODO add support for multiple
@@ -8397,8 +8611,18 @@ const CacheHandler = {
8397
8611
  activeRequest.priority = {
8398
8612
  blocking: true
8399
8613
  };
8614
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
8615
+ if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
8616
+ log('request', '', 'DEDUPED', identifier.lid, 'blocking', '');
8617
+ }
8618
+ }
8400
8619
  return activeRequest.promise;
8401
8620
  }
8621
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
8622
+ if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
8623
+ log('request', '', 'ISSUED', identifier?.lid ?? context.request.url ?? context.request.op ?? '<unknown request>', 'blocking', '');
8624
+ }
8625
+ }
8402
8626
  let promise = fetchContentAndHydrate(next, context, identifier, {
8403
8627
  blocking: true
8404
8628
  });
@@ -8413,7 +8637,9 @@ const CacheHandler = {
8413
8637
  },
8414
8638
  promise
8415
8639
  });
8416
- store.notifications.notify(identifier, 'state', null);
8640
+ queueMicrotask(() => {
8641
+ store.notifications.notify(identifier, 'state', null);
8642
+ });
8417
8643
  }
8418
8644
  store.requestManager._pending.set(context.id, promise);
8419
8645
  return promise;
@@ -8435,10 +8661,26 @@ const CacheHandler = {
8435
8661
  },
8436
8662
  promise
8437
8663
  });
8438
- store.notifications.notify(identifier, 'state', null);
8664
+ queueMicrotask(() => {
8665
+ store.notifications.notify(identifier, 'state', null);
8666
+ });
8667
+ }
8668
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
8669
+ if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
8670
+ if (activeRequest && identifier) {
8671
+ log('request', '', 'DEDUPED', identifier.lid, activeRequest.priority.blocking ? 'blocking' : 'non-blocking', '');
8672
+ } else {
8673
+ log('request', '', 'ISSUED', identifier?.lid ?? context.request.url ?? context.request.op ?? '<unknown request>', 'non-blocking', '');
8674
+ }
8675
+ }
8439
8676
  }
8440
8677
  store.requestManager._pending.set(context.id, promise);
8441
8678
  }
8679
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REQUESTS)) {
8680
+ if (getGlobalConfig().WarpDrive.debug.LOG_REQUESTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REQUESTS) {
8681
+ log('request', '', 'CACHE-HIT', identifier?.lid ?? context.request.url ?? context.request.op ?? '<unknown request>', 'cached', '');
8682
+ }
8683
+ }
8442
8684
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
8443
8685
  if (!test) {
8444
8686
  throw new Error(`Expected a peeked request to be present`);
@@ -9233,6 +9475,8 @@ function isNeverString(val) {
9233
9475
  * Utilities to assist in recovering from the error.
9234
9476
  */
9235
9477
 
9478
+ /** @deprecated use {@link RecoveryFeatures} */
9479
+
9236
9480
  /**
9237
9481
  * Utilities for keeping the request fresh
9238
9482
  */
@@ -9398,6 +9642,7 @@ class RequestSubscription {
9398
9642
  // if we need to react to those changes, we can
9399
9643
  // use a modifier or internal component or some
9400
9644
  // such to trigger a re-run of this function.
9645
+ /** @internal */
9401
9646
  static {
9402
9647
  decorateMethodV2(this.prototype, "autorefreshTypes", [memoized]);
9403
9648
  }
@@ -9437,6 +9682,8 @@ class RequestSubscription {
9437
9682
  this._maybeUpdate();
9438
9683
  }, autorefreshThreshold);
9439
9684
  }
9685
+
9686
+ /** @internal */
9440
9687
  _clearInterval() {
9441
9688
  if (this._nextInterval) {
9442
9689
  clearTimeout(this._nextInterval);
@@ -9910,9 +10157,35 @@ async function watchStream(stream, loadingState) {
9910
10157
  * @hideconstructor
9911
10158
  */
9912
10159
  class RequestLoadingState {
10160
+ /** @internal */
10161
+
10162
+ /** @internal */
10163
+
10164
+ /** @internal */
10165
+
10166
+ /** @internal */
10167
+
10168
+ /** @internal */
10169
+
10170
+ /** @internal */
10171
+
10172
+ /** @internal */
10173
+
10174
+ /** @internal */
10175
+
10176
+ /** @internal */
10177
+
10178
+ /** @internal */
10179
+
10180
+ /** @internal */
10181
+
10182
+ /** @internal */
9913
10183
  _stream = null;
10184
+ /** @internal */
9914
10185
  _future;
10186
+ /** @internal */
9915
10187
  _triggered = false;
10188
+ /** @internal */
9916
10189
  _trigger() {
9917
10190
  if (this._triggered) {
9918
10191
  return;
@@ -10276,4 +10549,4 @@ function getRequestState(future) {
10276
10549
  }
10277
10550
  return state;
10278
10551
  }
10279
- export { defineNonEnumerableSignal as A, Signals as B, CacheHandler as C, DISPOSE as D, peekInternalSignal as E, withSignalStore as F, notifyInternalSignal as G, consumeInternalSignal as H, getOrCreateInternalSignal as I, ReactiveResource as J, isNonIdentityCacheableField as K, getFieldCacheKeyStrict as L, checkout as M, commit as N, setIdentifierGenerationMethod as O, setIdentifierUpdateMethod as P, setIdentifierForgetMethod as Q, RecordArrayManager as R, Store as S, setIdentifierResetMethod as T, setKeyInfoForResource as U, _clearCaches as _, isRequestKey as a, coerceId as b, constructResource as c, assertPrivateStore as d, ensureStringId as e, fastPush as f, isPrivateStore as g, assertPrivateCapabilities as h, isResourceKey as i, setRecordIdentifier as j, StoreMap as k, createLegacyManyArray as l, log as m, normalizeModelName as n, logGroup as o, getPromiseState as p, createRequestSubscription as q, recordIdentifierFor as r, storeFor as s, getRequestState as t, signal as u, memoized as v, gate as w, entangleSignal as x, defineSignal as y, defineGate as z };
10552
+ export { defineGate as A, defineNonEnumerableSignal as B, CacheHandler as C, DISPOSE as D, Signals as E, peekInternalSignal as F, createInternalMemo as G, withSignalStore as H, notifyInternalSignal as I, consumeInternalSignal as J, getOrCreateInternalSignal as K, ReactiveResource as L, isNonIdentityCacheableField as M, getFieldCacheKeyStrict as N, checkout as O, commit as P, setIdentifierGenerationMethod as Q, RecordArrayManager as R, Store as S, setIdentifierUpdateMethod as T, setIdentifierForgetMethod as U, setIdentifierResetMethod as V, setKeyInfoForResource as W, _clearCaches as _, isRequestKey as a, coerceId as b, constructResource as c, assertPrivateStore as d, ensureStringId as e, fastPush as f, isPrivateStore as g, assertPrivateCapabilities as h, isResourceKey as i, setRecordIdentifier as j, StoreMap as k, createLegacyManyArray as l, log as m, normalizeModelName as n, logGroup as o, getPromiseState as p, createRequestSubscription as q, recordIdentifierFor as r, storeFor as s, getRequestState as t, signal as u, memoized as v, gate as w, entangleSignal as x, entangleInitiallyStaleSignal as y, defineSignal as z };
package/dist/request.js CHANGED
@@ -1 +1 @@
1
- export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./context-Bh-MA_tH.js";
1
+ export { c as createDeferred, g as getPromiseResult, s as setPromiseResult } from "./context-C_7OLieY.js";
@@ -1,2 +1,2 @@
1
- export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager, B as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, H as consumeInternalSignal, l as createLegacyManyArray, q as createRequestSubscription, z as defineGate, A as defineNonEnumerableSignal, y as defineSignal, e as ensureStringId, x as entangleSignal, f as fastPush, w as gate, I as getOrCreateInternalSignal, p as getPromiseState, t as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, v as memoized, G as notifyInternalSignal, E as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, u as signal, s as storeFor, F as withSignalStore } from "../request-state-B908BvPK.js";
2
- export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo, w as waitFor } from "../configure-CiFDHArV.js";
1
+ export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager, E as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, J as consumeInternalSignal, G as createInternalMemo, l as createLegacyManyArray, q as createRequestSubscription, A as defineGate, B as defineNonEnumerableSignal, z as defineSignal, e as ensureStringId, y as entangleInitiallyStaleSignal, x as entangleSignal, f as fastPush, w as gate, K as getOrCreateInternalSignal, p as getPromiseState, t as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, v as memoized, I as notifyInternalSignal, F as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, u as signal, s as storeFor, H as withSignalStore } from "../request-state-CxDzTjFX.js";
2
+ export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-C3x8YXzL.js";
@@ -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.30";
3
+ const version = "5.7.0-alpha.32";
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/core",
3
- "version": "5.7.0-alpha.30",
3
+ "version": "5.7.0-alpha.32",
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.18.1",
40
- "@warp-drive/build-config": "5.7.0-alpha.30"
40
+ "@warp-drive/build-config": "5.7.0-alpha.32"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.28.0",
44
44
  "@babel/plugin-transform-typescript": "^7.28.0",
45
45
  "@babel/preset-typescript": "^7.27.1",
46
- "@warp-drive/internal-config": "5.7.0-alpha.30",
46
+ "@warp-drive/internal-config": "5.7.0-alpha.32",
47
47
  "decorator-transforms": "^2.3.0",
48
48
  "ember-source": "~6.6.0",
49
49
  "expect-type": "^1.2.1",