@warp-drive/core 5.7.0-alpha.9 → 5.7.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/declarations/graph/-private/-diff.d.ts +7 -20
  2. package/declarations/graph/-private/-edge-definition.d.ts +3 -12
  3. package/declarations/graph/-private/-state.d.ts +0 -87
  4. package/declarations/graph/-private/-utils.d.ts +5 -11
  5. package/declarations/graph/-private/coerce-id.d.ts +0 -6
  6. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
  7. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  8. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  9. package/declarations/graph/-private/edges/resource.d.ts +6 -7
  10. package/declarations/graph/-private/graph.d.ts +17 -51
  11. package/declarations/graph/-private/normalize-link.d.ts +0 -6
  12. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
  13. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
  14. package/declarations/index.d.ts +1 -1
  15. package/declarations/reactive/-private/default-mode.d.ts +2 -2
  16. package/declarations/reactive/-private/document.d.ts +11 -27
  17. package/declarations/reactive/-private/fields/managed-array.d.ts +4 -6
  18. package/declarations/reactive/-private/fields/managed-object.d.ts +2 -8
  19. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  20. package/declarations/reactive/-private/hooks.d.ts +2 -2
  21. package/declarations/reactive/-private/record.d.ts +42 -30
  22. package/declarations/reactive/-private/schema.d.ts +11 -73
  23. package/declarations/reactive/-private/symbols.d.ts +2 -33
  24. package/declarations/reactive/-private.d.ts +1 -1
  25. package/declarations/reactive.d.ts +277 -1
  26. package/declarations/request/-private/context.d.ts +3 -5
  27. package/declarations/request/-private/fetch.d.ts +2 -2
  28. package/declarations/request/-private/manager.d.ts +24 -28
  29. package/declarations/request/-private/types.d.ts +22 -24
  30. package/declarations/request/-private/utils.d.ts +44 -2
  31. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  32. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  33. package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
  34. package/declarations/store/-private/caches/instance-cache.d.ts +21 -20
  35. package/declarations/store/-private/debug/utils.d.ts +1 -0
  36. package/declarations/store/-private/default-cache-policy.d.ts +25 -40
  37. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  38. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
  39. package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
  40. package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
  41. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  42. package/declarations/store/-private/network/request-cache.d.ts +21 -25
  43. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  44. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  45. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  46. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  47. package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
  48. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
  49. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  50. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  51. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  52. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  53. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  54. package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
  55. package/declarations/store/-private/store-service.d.ts +156 -106
  56. package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
  57. package/declarations/store/-private.d.ts +11 -13
  58. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  59. package/declarations/store/-types/q/identifier.d.ts +9 -6
  60. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  61. package/declarations/store/-types/q/schema-service.d.ts +9 -9
  62. package/declarations/store/-types/q/store.d.ts +6 -7
  63. package/declarations/store/deprecated/-private.d.ts +12 -24
  64. package/declarations/store/deprecated/store.d.ts +11 -16
  65. package/declarations/types/-private.d.ts +1 -1
  66. package/declarations/types/cache/aliases.d.ts +0 -11
  67. package/declarations/types/cache/change.d.ts +2 -2
  68. package/declarations/types/cache/mutations.d.ts +13 -37
  69. package/declarations/types/cache/operations.d.ts +115 -32
  70. package/declarations/types/cache/relationship.d.ts +4 -7
  71. package/declarations/types/cache.d.ts +51 -125
  72. package/declarations/types/graph.d.ts +12 -12
  73. package/declarations/types/identifier.d.ts +52 -78
  74. package/declarations/types/params.d.ts +2 -3
  75. package/declarations/types/request.d.ts +66 -42
  76. package/declarations/types/schema/concepts.d.ts +2 -2
  77. package/declarations/types/schema/fields.d.ts +30 -3
  78. package/declarations/types/spec/document.d.ts +6 -10
  79. package/declarations/types/spec/json-api-raw.d.ts +6 -9
  80. package/declarations/types.d.ts +0 -1
  81. package/declarations/utils/string.d.ts +2 -3
  82. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  83. package/dist/configure.js +1 -1
  84. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  85. package/dist/graph/-private.js +137 -144
  86. package/dist/index.js +25 -14
  87. package/dist/reactive/-private.js +1 -1
  88. package/dist/reactive.js +144 -1926
  89. package/dist/{request-state-CeN66aML.js → request-state-C955e0AL.js} +5968 -3033
  90. package/dist/request.js +1 -1
  91. package/dist/store/-private.js +2 -3
  92. package/dist/store.js +32 -44
  93. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  94. package/dist/types/-private.js +1 -1
  95. package/dist/types/identifier.js +19 -45
  96. package/dist/types/request.js +45 -3
  97. package/dist/types/schema/fields.js +6 -0
  98. package/dist/utils/string.js +2 -2
  99. package/package.json +11 -11
  100. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  101. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  102. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  103. package/dist/handler-SdXlte1w.js +0 -339
@@ -1,5 +1,281 @@
1
+ /**
2
+ * # About
3
+ *
4
+ * This module provides an implementation of reactive objects that a Store may use for creating
5
+ * reactive representations of the raw data for requests, resources and their relationships
6
+ * stored in the cache.
7
+ *
8
+ * - For configuring the store to use these reactive objects, see [The Setup Guide](/guides/1-configuration/2-setup/1-universal.md)
9
+ * - For defining resource schemas, see [The Schema Guide](/guides)
10
+ *
11
+ * Any method that returns a record instance will use the `instantiateRecord`
12
+ * hook configured above to instantiate a ReactiveResource once this is in place.
13
+ * After that, its up to you what ReactiveResource can do.
14
+ *
15
+ * ## Modes
16
+ *
17
+ * ReactiveResource has two modes: `legacy` and `polaris`.
18
+ *
19
+ * **LegacyMode** can be used to emulate the behaviors and capabilities of WarpDrive's `Model` class,
20
+ * and because there is little distinction between Model and a ReactiveResource in LegacyMode we refer
21
+ * to both of these approaches as LegacyMode. This mode is the default experience in V5.
22
+ *
23
+ * In LegacyMode:
24
+ *
25
+ * - records are mutable
26
+ * - local changes immediately reflect app wide
27
+ * - records have all the APIs of Model (references, state props, currentState, methods etc)
28
+ * - the continued use of `@warp-drive/legacy` is required (though most imports from it can be removed)
29
+ * - `async: true` relationships are supported (but not recommended outside of [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
30
+ *
31
+ * ---
32
+ *
33
+ * **PolarisMode** is an upcoming suite of features that will become the default experience in V6.
34
+ *
35
+ * In PolarisMode:
36
+ *
37
+ * - records are immutable, unless creating a new resource or explicitly checking out a record for editing
38
+ * - local changes are isolated until committed, displaying only via the editable version of the record
39
+ * - records have a more limited API, focused on only what is in their schema.
40
+ * - some common operations may have more friction to perform because intended utilities are not yet available
41
+ * - `async: true` relationships are not supported (see [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
42
+ * - The `@warp-drive/legacy` package is not required
43
+ *
44
+ * These modes are interopable. The reactive object (record) for a resource in PolarisMode can relate to
45
+ * a record in LegacyMode and vice-versa. This interopability is true whether the record in LegacyMode is
46
+ * a ReactiveResource or a Model.
47
+ *
48
+ * ---
49
+ *
50
+ * ## Basic Usage
51
+ *
52
+ * ReactiveResource is a reactive object that transforms raw data from an associated
53
+ * cache into reactive data backed by Signals.
54
+ *
55
+ * The shape of the object and the transformation of raw cache data into its
56
+ * reactive form is controlled by a resource schema.
57
+ *
58
+ * For instance, lets say your API is a [{JSON:API}](https://jsonapi.org) and your store is using
59
+ * the Cache provided by [@warp-drive/json-api](/api/@warp-drive/json-api), and a request
60
+ * returns the following raw data:
61
+ *
62
+ * ```ts
63
+ * {
64
+ * data: {
65
+ * type: 'user',
66
+ * id: '1',
67
+ * attributes: { firstName: 'Chris', lastName: 'Thoburn' },
68
+ * relationships: { pets: { data: [{ type: 'dog', id: '1' }] }}
69
+ * },
70
+ * included: [
71
+ * {
72
+ * type: 'dog',
73
+ * id: '1',
74
+ * attributes: { name: 'Rey' },
75
+ * relationships: { owner: { data: { type: 'user', id: '1' }}}
76
+ * }
77
+ * ]
78
+ * }
79
+ * ```
80
+ *
81
+ * We could describe the `'user'` and `'dog'` resources in the above payload
82
+ * with the following schemas:
83
+ *
84
+ * ```ts
85
+ * store.schema.registerResources([
86
+ * {
87
+ * type: 'user',
88
+ * identity: { type: '@id', name: 'id' },
89
+ * fields: [
90
+ * {
91
+ * type: '@identity',
92
+ * name: '$type',
93
+ * kind: 'derived',
94
+ * options: { key: 'type' },
95
+ * },
96
+ * { kind: 'field', name: 'firstName' },
97
+ * { kind: 'field', name: 'lastName' },
98
+ * {
99
+ * kind: 'derived',
100
+ * name: 'name',
101
+ * type: 'concat',
102
+ * options: { fields: ['firstName', 'lastName'], separator: ' ' }
103
+ * },
104
+ * {
105
+ * kind: 'hasMany',
106
+ * name: 'pets',
107
+ * type: 'pet',
108
+ * options: {
109
+ * async: false,
110
+ * inverse: 'owner',
111
+ * polymorphic: true,
112
+ * linksMode: true,
113
+ * }
114
+ * }
115
+ * ]
116
+ * },
117
+ * {
118
+ * type: 'dog',
119
+ * identity: { type: '@id', name: 'id' },
120
+ * fields: [
121
+ * {
122
+ * type: '@identity',
123
+ * name: '$type',
124
+ * kind: 'derived',
125
+ * options: { key: 'type' },
126
+ * },
127
+ * { kind: 'field', name: 'name' },
128
+ * {
129
+ * kind: 'belongsTo',
130
+ * name: 'owner',
131
+ * type: 'user',
132
+ * options: {
133
+ * async: false,
134
+ * inverse: 'pets',
135
+ * as: 'pet',
136
+ * linksMode: true,
137
+ * }
138
+ * }
139
+ * ]
140
+ * }
141
+ * ]);
142
+ * ```
143
+ *
144
+ * With these schemas in place, the reactive objects that the store would
145
+ * provide us whenever we encountered a `'user'` or a `'dog'` would be:
146
+ *
147
+ * ```ts
148
+ * interface Pet {
149
+ * readonly id: string;
150
+ * readonly owner: User;
151
+ * }
152
+ *
153
+ * interface Dog extends Pet {
154
+ * readonly $type: 'dog';
155
+ * readonly name: string;
156
+ * }
157
+ *
158
+ * interface EditableUser {
159
+ * readonly $type: 'user';
160
+ * readonly id: string;
161
+ * firstName: string;
162
+ * lastName: string;
163
+ * readonly name: string;
164
+ * pets: Array<Dog | Pet>;
165
+ * }
166
+ *
167
+ * interface User {
168
+ * readonly $type: 'user';
169
+ * readonly id: string;
170
+ * readonly firstName: string;
171
+ * readonly lastName: string;
172
+ * readonly name: string;
173
+ * readonly pets: Readonly<Array<Dog | Pet>>;
174
+ * [Checkout](): Promise<EditableUser>
175
+ * }>
176
+ * ```
177
+ *
178
+ * Note how based on the schema the reactive object we receive is able to produce
179
+ * `name` on user (despite no name field being in the cache), provide `$type`
180
+ * pulled from the identity of the resource, and flatten the individual attributes
181
+ * and relationships onto the record for easier use.
182
+ *
183
+ * Notice also how we typed this object with `readonly`. This is because while
184
+ * ReactiveResource instances are ***deeply reactive***, they are also ***immutable***.
185
+ *
186
+ * We can mutate a ReactiveResource only be explicitly asking permission to do so, and
187
+ * in the process gaining access to an editable copy. The immutable version will
188
+ * not show any in-process edits made to this editable copy.
189
+ *
190
+ * ```ts
191
+ * import { Checkout } from '@warp-drive/schema-record';
192
+ *
193
+ * const editable = await user[Checkout]();
194
+ * ```
195
+ *
196
+ * ## Utilities
197
+ *
198
+ * ReactiveResource provides a schema builder that simplifies setting up a couple of
199
+ * conventional fields like identity and `$type`. We can rewrite the schema
200
+ * definition above using this utility like so:
201
+ *
202
+ * ```ts
203
+ * import { withDefaults } from '@warp-drive/core/reactive';
204
+ *
205
+ * store.schema.registerResources([
206
+ * withDefaults({
207
+ * type: 'user',
208
+ * fields: [
209
+ * { kind: 'field', name: 'firstName' },
210
+ * { kind: 'field', name: 'lastName' },
211
+ * {
212
+ * kind: 'derived',
213
+ * name: 'name',
214
+ * type: 'concat',
215
+ * options: { fields: ['firstName', 'lastName'], separator: ' ' }
216
+ * },
217
+ * {
218
+ * kind: 'hasMany',
219
+ * name: 'pets',
220
+ * type: 'pet',
221
+ * options: {
222
+ * async: false,
223
+ * inverse: 'owner',
224
+ * polymorphic: true,
225
+ * linksMode: true,
226
+ * resetOnRemoteUpdate: false,
227
+ * }
228
+ * }
229
+ * ]
230
+ * }),
231
+ * withDefaults({
232
+ * type: 'dog',
233
+ * fields: [
234
+ * { kind: 'field', name: 'name' },
235
+ * {
236
+ * kind: 'belongsTo',
237
+ * name: 'owner',
238
+ * type: 'user',
239
+ * options: {
240
+ * async: false,
241
+ * inverse: 'pets',
242
+ * as: 'pet',
243
+ * linksMode: true,
244
+ * resetOnRemoteUpdate: false,
245
+ * }
246
+ * }
247
+ * ]
248
+ * })
249
+ * ]);
250
+ * ```
251
+ *
252
+ * ## Type Support
253
+ *
254
+ * ### Resource Schemas
255
+ *
256
+ * - {@link PolarisResourceSchema}
257
+ * - {@link LegacyResourceSchema}
258
+ * - {@link ObjectSchema}
259
+ *
260
+ * ### Resource Schema Type Utils
261
+ *
262
+ * - {@link resourceSchema}
263
+ * - {@link objectSchema}
264
+ * - {@link isResourceSchema}
265
+ * - {@link isLegacyResourceSchema}
266
+ *
267
+ * ### Field Schemas
268
+ *
269
+ * - {@link LegacyModeFieldSchema}
270
+ * - {@link PolarisModeFieldSchema}
271
+ *
272
+ * @module
273
+ */
274
+ import { checkout } from "./reactive/-private/record.js";
1
275
  export { instantiateRecord, teardownRecord } from "./reactive/-private/hooks.js";
2
276
  export { type CAUTION_MEGA_DANGER_ZONE_Extension, type ProcessedExtension, type ExtensionDef, type Transformation, SchemaService, withDefaults, fromIdentity, registerDerivations } from "./reactive/-private/schema.js";
3
- export { type ReactiveResource } from "./reactive/-private/record.js";
277
+ export { commit, type ReactiveResource } from "./reactive/-private/record.js";
278
+ export { checkout };
4
279
  export { Checkout } from "./reactive/-private/symbols.js";
5
280
  export { type ReactiveDocument } from "./reactive/-private/document.js";
281
+ export { getExpensiveRequestSubscription } from "./store/-private/new-core-tmp/expensive-subscription.js";
@@ -1,4 +1,4 @@
1
- import type { StableDocumentIdentifier } from "../../types/identifier.js";
1
+ import type { RequestKey } from "../../types/identifier.js";
2
2
  import type { ImmutableHeaders, ImmutableRequestInfo, RequestInfo, ResponseInfo } from "../../types/request.js";
3
3
  import type { DeferredStream, GodContext } from "./types.js";
4
4
  export declare function upgradeHeaders(headers: Headers | ImmutableHeaders): ImmutableHeaders;
@@ -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;
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
- setIdentifier(identifier: StableDocumentIdentifier): void;
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,6 @@
1
1
  import { type Context } from "./context.js";
2
- import type { HttpErrorProps } from "./utils.js";
3
- export type { HttpErrorProps };
2
+ import type { FetchError } from "./utils.js";
3
+ export type { FetchError };
4
4
  interface FastbootRequest extends Request {
5
5
  protocol: string;
6
6
  host: string;
@@ -1,5 +1,5 @@
1
- import type { StableDocumentIdentifier } from "../../types/identifier.js";
2
- import type { RequestInfo } from "../../types/request.js";
1
+ import type { RequestKey } from "../../types/identifier.js";
2
+ import { type RequestInfo } from "../../types/request.js";
3
3
  import type { CacheHandler, Future, GenericCreateArgs, Handler, ManagedRequestPriority } from "./types.js";
4
4
  import { IS_CACHE_HANDLER } from "./utils.js";
5
5
  /**
@@ -90,27 +90,9 @@ import { IS_CACHE_HANDLER } from "./utils.js";
90
90
  * type StructuredDocument<T> = StructuredDataDocument<T> | StructuredErrorDocument;
91
91
  * ```
92
92
  *
93
- * @class RequestManager
94
93
  * @public
95
94
  */
96
95
  export declare class RequestManager {
97
- #private;
98
- /** @internal */
99
- _hasCacheHandler: boolean;
100
- /**
101
- * A map of pending requests from request.id to their
102
- * associated CacheHandler promise.
103
- *
104
- * This queue is managed by the CacheHandler
105
- *
106
- * @internal
107
- */
108
- _pending: Map<number, Promise<unknown>>;
109
- /** @internal */
110
- _deduped: Map<StableDocumentIdentifier, {
111
- priority: ManagedRequestPriority;
112
- promise: Promise<unknown>;
113
- }>;
114
96
  constructor(options?: GenericCreateArgs);
115
97
  /**
116
98
  * Register a handler to use for primary cache intercept.
@@ -132,8 +114,6 @@ export declare class RequestManager {
132
114
  * curry the request, or pass along a modified request.
133
115
  *
134
116
  * @public
135
- * @param {Handler[]} newHandlers
136
- * @return {ThisType}
137
117
  */
138
118
  use(newHandlers: Handler[]): this;
139
119
  /**
@@ -142,13 +122,8 @@ export declare class RequestManager {
142
122
  * Returns a Future that fulfills with a StructuredDocument
143
123
  *
144
124
  * @public
145
- * @param {RequestInfo} request
146
- * @return {Future}
147
125
  */
148
- request<
149
- RT,
150
- T = unknown
151
- >(request: RequestInfo<RT, T>): Future<RT>;
126
+ request<RT>(request: RequestInfo<RT>): Future<RT>;
152
127
  /**
153
128
  * This method exists so that the RequestManager can be created
154
129
  * can be created by container/factory systems that expect to
@@ -160,3 +135,24 @@ export declare class RequestManager {
160
135
  */
161
136
  static create(options?: GenericCreateArgs): RequestManager;
162
137
  }
138
+ /**
139
+ * This type exists for internal use only for
140
+ * where intimate contracts still exist either for
141
+ * the Test Suite or for Legacy code.
142
+ *
143
+ * @private
144
+ */
145
+ export interface PrivateRequestManager extends RequestManager {
146
+ /**
147
+ * A map of pending requests from request.id to their
148
+ * associated CacheHandler promise.
149
+ *
150
+ * This queue is managed by the CacheHandler
151
+ *
152
+ */
153
+ _pending: Map<number, Promise<unknown>>;
154
+ _deduped: Map<RequestKey, {
155
+ priority: ManagedRequestPriority;
156
+ promise: Promise<unknown>;
157
+ }>;
158
+ }
@@ -1,13 +1,15 @@
1
- /* eslint-disable no-irregular-whitespace */
2
- import type { StableDocumentIdentifier } from "../../types/identifier.js";
3
- import type { IS_FUTURE, RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
1
+ import type { Store } from "../../store/-private.js";
2
+ import type { RequestKey } from "../../types/identifier.js";
3
+ import type { RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
4
+ import type { RequestManager } from "./manager.js";
4
5
  export interface GodContext {
5
6
  controller: AbortController;
6
7
  response: ResponseInfo | null;
7
8
  stream: ReadableStream | Promise<ReadableStream | null> | null;
8
9
  hasRequestedStream: boolean;
9
10
  id: number;
10
- identifier: StableDocumentIdentifier | null;
11
+ identifier: RequestKey | null;
12
+ requester: RequestManager | Store;
11
13
  }
12
14
  export type Deferred<T> = {
13
15
  resolve(v: T): void;
@@ -32,10 +34,12 @@ export type DeferredStream = {
32
34
  * @public
33
35
  */
34
36
  export interface Future<T> extends Promise<StructuredDataDocument<T>> {
35
- [IS_FUTURE]: true;
36
37
  /**
37
38
  * Cancel this request by firing the {@link AbortController}'s signal.
38
39
  *
40
+ * This method can be used as an action or event handler as its
41
+ * context is bound to the Future instance.
42
+ *
39
43
  * @privateRemarks
40
44
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
41
45
  *
@@ -46,8 +50,10 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
46
50
  /**
47
51
  * Get the response stream, if any, once made available.
48
52
  *
53
+ * This method can be used as an action or event handler as its
54
+ * context is bound to the Future instance.
55
+ *
49
56
  * @public
50
- * @return {Promise<ReadableStream | null>}
51
57
  */
52
58
  getStream(): Promise<ReadableStream | null>;
53
59
  /**
@@ -55,28 +61,27 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
55
61
  * mostly useful for instrumentation and infrastructure.
56
62
  *
57
63
  * @param cb the callback to run
58
- * @public
59
- * @return {void}
60
64
  */
61
65
  onFinalize(cb: () => void): void;
62
66
  /**
63
67
  * The identifier of the associated request, if any, as
64
68
  * assigned by the CacheHandler.
65
- *
66
- * @property lid
67
- * @type {StableDocumentIdentifier | null}
68
- * @public
69
69
  */
70
- lid: StableDocumentIdentifier | null;
70
+ lid: RequestKey | null;
71
71
  /**
72
72
  * The id of the associated request, if any, as assigned
73
73
  * by the RequestManager
74
74
  *
75
- * @property id
76
- * @type {Number}
77
- * @public
75
+ * This is not unique across Manager instances and cannot
76
+ * be used to identify or dedupe requests.
78
77
  */
79
78
  id: number;
79
+ /**
80
+ * The RequestManager or Store that initiated this request.
81
+ *
82
+ * @private
83
+ */
84
+ requester: RequestManager | Store;
80
85
  }
81
86
  export type DeferredFuture<T> = {
82
87
  resolve(v: StructuredDataDocument<T>): void;
@@ -191,8 +196,6 @@ const manager = new RequestManager()
191
196
 
192
197
  Handlers will be invoked in the order they are registered ("fifo", first-in first-out), and may only be registered up until the first request is made. It is recommended but not required to register all handlers at one time in order to ensure explicitly visible handler ordering.
193
198
 
194
-
195
- @class (Interface) Handler
196
199
  @public
197
200
  */
198
201
  export interface Handler {
@@ -202,20 +205,17 @@ export interface Handler {
202
205
  * other handlers.
203
206
  *
204
207
  * @public
205
- * @param context
206
- * @param next
207
208
  */
208
209
  request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
209
210
  }
210
211
  /**
211
- * The CacheHandler is identical to other handlers ecxept that it
212
+ * The CacheHandler is identical to other handlers except that it
212
213
  * is allowed to return a value synchronously. This is useful for
213
214
  * features like reducing microtask queueing when de-duping.
214
215
  *
215
216
  * A RequestManager may only have one CacheHandler, registered via
216
217
  * `manager.useCache(CacheHandler)`.
217
218
  *
218
- * @class (Interface) CacheHandler
219
219
  * @public
220
220
  */
221
221
  export interface CacheHandler {
@@ -225,8 +225,6 @@ export interface CacheHandler {
225
225
  * other handlers.
226
226
  *
227
227
  * @public
228
- * @param context
229
- * @param next
230
228
  */
231
229
  request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
232
230
  }
@@ -3,12 +3,54 @@ import { ContextOwner } from "./context.js";
3
3
  import type { DeferredFuture, Future, GodContext, Handler } from "./types.js";
4
4
  export declare const IS_CACHE_HANDLER: "___(unique) Symbol(IS_CACHE_HANDLER)";
5
5
  export declare function curryFuture<T>(owner: ContextOwner, inbound: Future<T>, outbound: DeferredFuture<T>): Future<T>;
6
- export interface HttpErrorProps extends DOMException {
6
+ /**
7
+ * Additional properties exposed on errors thrown by the
8
+ * {@link Fetch | Fetch Handler}.
9
+ *
10
+ * In the case of an Abort or system/browser level issue,
11
+ * this extends {@link DOMException}.
12
+ *
13
+ * Else it extends from {@link AggregateError} if the
14
+ * response includes an array of errors, falling back
15
+ * to {@link Error} as its base.
16
+ */
17
+ export interface FetchError extends DOMException {
18
+ /**
19
+ * Alias for {@link FetchError.status | status}.
20
+ *
21
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status)
22
+ */
7
23
  code: number;
24
+ /**
25
+ * The name associated to the {@link FetchError.status | status code}.
26
+ *
27
+ * Typically this will be of the formula `StatusTextError` for instance
28
+ * a 404 status with status text of `Not Found` would have the name
29
+ * `NotFoundError`.
30
+ */
8
31
  name: string;
32
+ /**
33
+ * The http status code associated to the returned error.
34
+ *
35
+ * Browser/System level network errors will often have an error code of `0` or `5`.
36
+ * Aborted requests will have an error code of `20`.
37
+ *
38
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status)
39
+ */
9
40
  status: number;
41
+ /**
42
+ * The Status Text associated to the {@link FetchError.status | status code}
43
+ * for the error.
44
+ *
45
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText)
46
+ *
47
+ */
10
48
  statusText: string;
11
- isRequestError: boolean;
49
+ /**
50
+ * A property signifying that an Error uses the {@link FetchError}
51
+ * interface.
52
+ */
53
+ isRequestError: true;
12
54
  }
13
55
  export declare function enhanceReason(reason?: string): DOMException;
14
56
  export declare function handleOutcome<T>(owner: ContextOwner, inbound: Promise<T | StructuredDataDocument<T>>, outbound: DeferredFuture<T>): Future<T>;
@@ -3,17 +3,11 @@ import type { ImmutableRequestInfo, RequestContext } from "../../../types/reques
3
3
  import type { ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
4
4
  import type { RequestSignature } from "../../../types/symbols.js";
5
5
  import type { Store } from "../store-service.js";
6
- export type LooseStoreRequestInfo<
7
- RT = unknown,
8
- T = unknown
9
- > = Omit<ImmutableRequestInfo<RT, T>, "records" | "headers" | typeof RequestSignature> & {
6
+ export type LooseStoreRequestInfo<RT = unknown> = Omit<ImmutableRequestInfo<RT>, "records" | "headers" | typeof RequestSignature> & {
10
7
  records?: ResourceIdentifierObject[];
11
8
  headers?: Headers;
12
9
  };
13
- export type StoreRequestInput<
14
- RT = unknown,
15
- T = unknown
16
- > = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;
10
+ export type StoreRequestInput<RT = unknown> = ImmutableRequestInfo<RT> | LooseStoreRequestInfo<RT>;
17
11
  export interface StoreRequestContext extends RequestContext {
18
12
  request: ImmutableRequestInfo & {
19
13
  store: Store;
@@ -1,4 +1,4 @@
1
- import type { StableDocumentIdentifier } from "../../../types/identifier.js";
1
+ import type { RequestKey } from "../../../types/identifier.js";
2
2
  import type { ImmutableRequestInfo, ResponseInfo } from "../../../types/request.js";
3
3
  import type { Store } from "../store-service.js";
4
4
  /**
@@ -27,11 +27,11 @@ export interface CachePolicy {
27
27
  * and the cache will be updated before returning the response.
28
28
  *
29
29
  * @public
30
- * @param {StableDocumentIdentifier} identifier
30
+ * @param {RequestKey} identifier
31
31
  * @param {Store} store
32
32
  * @return {Boolean} true if the request is considered hard expired
33
33
  */
34
- isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
34
+ isHardExpired(identifier: RequestKey, store: Store): boolean;
35
35
  /**
36
36
  * Invoked if `isHardExpired` is false to determine if the request
37
37
  * should be update behind the scenes if cache data is already available.
@@ -42,11 +42,11 @@ export interface CachePolicy {
42
42
  * request is made to update the cache via the configured request handlers.
43
43
  *
44
44
  * @public
45
- * @param {StableDocumentIdentifier} identifier
45
+ * @param {RequestKey} identifier
46
46
  * @param {Store} store
47
47
  * @return {Boolean} true if the request is considered soft expired
48
48
  */
49
- isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
49
+ isSoftExpired(identifier: RequestKey, store: Store): boolean;
50
50
  /**
51
51
  * Invoked when a request will be sent to the configured request handlers.
52
52
  * This is invoked for both foreground and background requests.
@@ -55,11 +55,11 @@ export interface CachePolicy {
55
55
  *
56
56
  * @public
57
57
  * @param {ImmutableRequestInfo} request
58
- * @param {StableDocumentIdentifier | null} identifier
58
+ * @param {RequestKey | null} identifier
59
59
  * @param {Store} store
60
60
  * @return {void}
61
61
  */
62
- willRequest?(request: ImmutableRequestInfo, identifier: StableDocumentIdentifier | null, store: Store): void;
62
+ willRequest?(request: ImmutableRequestInfo, identifier: RequestKey | null, store: Store): void;
63
63
  /**
64
64
  * Invoked when a request has been fulfilled from the configured request handlers.
65
65
  * This is invoked for both foreground and background requests once the cache has
@@ -71,7 +71,7 @@ export interface CachePolicy {
71
71
  * so that request subscriptions can reload when needed.
72
72
  *
73
73
  * ```ts
74
- * store.notifications.notify(identifier, 'invalidated');
74
+ * store.notifications.notify(identifier, 'invalidated', null);
75
75
  * ```
76
76
  *
77
77
  * This allows anything subscribed to the request to be notified of the change
@@ -90,9 +90,9 @@ export interface CachePolicy {
90
90
  * @public
91
91
  * @param {ImmutableRequestInfo} request
92
92
  * @param {ImmutableResponse} response
93
- * @param {StableDocumentIdentifier | null} identifier
93
+ * @param {RequestKey | null} identifier
94
94
  * @param {Store} store
95
95
  * @return {void}
96
96
  */
97
- didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
97
+ didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: RequestKey | null, store: Store): void;
98
98
  }