@warp-drive/core 5.7.0-alpha.3 → 5.7.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/graph/-private/-diff.d.ts +7 -20
- package/declarations/graph/-private/-edge-definition.d.ts +3 -12
- package/declarations/graph/-private/-state.d.ts +2 -2
- package/declarations/graph/-private/-utils.d.ts +5 -5
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +6 -7
- package/declarations/graph/-private/graph.d.ts +17 -15
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -21
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +44 -33
- package/declarations/reactive/-private/schema.d.ts +16 -72
- package/declarations/reactive/-private/symbols.d.ts +2 -7
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +3 -3
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +24 -28
- package/declarations/request/-private/types.d.ts +22 -23
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
- package/declarations/store/-private/caches/instance-cache.d.ts +21 -19
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -38
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +38 -52
- package/declarations/store/-private/managers/cache-manager.d.ts +47 -95
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -42
- package/declarations/store/-private/managers/record-array-manager.d.ts +45 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -21
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +129 -22
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -123
- package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
- package/declarations/store/-private/record-arrays/resource-array.d.ts +75 -0
- package/declarations/store/-private/store-service.d.ts +156 -101
- package/declarations/store/-private.d.ts +12 -9
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/record-instance.d.ts +0 -1
- package/declarations/store/-types/q/schema-service.d.ts +28 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -23
- package/declarations/store/deprecated/store.d.ts +11 -12
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +2 -2
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -13
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -4
- package/declarations/types/cache.d.ts +51 -113
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -76
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +69 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +378 -14
- package/declarations/types/spec/document.d.ts +6 -6
- package/declarations/types/spec/json-api-raw.d.ts +6 -8
- package/declarations/utils/string.d.ts +2 -2
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-Bh-MA_tH.js} +40 -6
- package/dist/graph/-private.js +137 -144
- package/dist/index.js +25 -14
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +203 -1413
- package/dist/{request-state-CejVJgdj.js → request-state-DGyt5EV8.js} +5674 -2812
- package/dist/request.js +1 -1
- package/dist/store/-private.js +2 -3
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +45 -3
- package/dist/types/schema/fields.js +23 -2
- package/dist/utils/string.js +2 -2
- package/package.json +10 -10
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
- package/dist/handler-D2jjnIA-.js +0 -339
|
@@ -1,4 +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";
|
|
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 {
|
|
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,7 +26,7 @@ export declare class ContextOwner {
|
|
|
26
26
|
setResponse(response: ResponseInfo | Response | null): void;
|
|
27
27
|
}
|
|
28
28
|
export declare class Context {
|
|
29
|
-
|
|
29
|
+
private ___owner;
|
|
30
30
|
request: ImmutableRequestInfo;
|
|
31
31
|
id: number;
|
|
32
32
|
private _isCacheHandler;
|
|
@@ -34,7 +34,7 @@ export declare class Context {
|
|
|
34
34
|
constructor(owner: ContextOwner, isCacheHandler: boolean);
|
|
35
35
|
setStream(stream: ReadableStream | Promise<ReadableStream | null>): void;
|
|
36
36
|
setResponse(response: ResponseInfo | Response | null): void;
|
|
37
|
-
setIdentifier(identifier:
|
|
37
|
+
setIdentifier(identifier: RequestKey): void;
|
|
38
38
|
get hasRequestedStream(): boolean;
|
|
39
39
|
_finalize(): void;
|
|
40
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
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,16 @@
|
|
|
1
1
|
/* eslint-disable no-irregular-whitespace */
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { Store } from "../../store/-private.js";
|
|
3
|
+
import type { RequestKey } from "../../types/identifier.js";
|
|
4
|
+
import type { RequestContext, RequestInfo, ResponseInfo, StructuredDataDocument } from "../../types/request.js";
|
|
5
|
+
import type { RequestManager } from "./manager.js";
|
|
4
6
|
export interface GodContext {
|
|
5
7
|
controller: AbortController;
|
|
6
8
|
response: ResponseInfo | null;
|
|
7
9
|
stream: ReadableStream | Promise<ReadableStream | null> | null;
|
|
8
10
|
hasRequestedStream: boolean;
|
|
9
11
|
id: number;
|
|
10
|
-
identifier:
|
|
12
|
+
identifier: RequestKey | null;
|
|
13
|
+
requester: RequestManager | Store;
|
|
11
14
|
}
|
|
12
15
|
export type Deferred<T> = {
|
|
13
16
|
resolve(v: T): void;
|
|
@@ -32,10 +35,12 @@ export type DeferredStream = {
|
|
|
32
35
|
* @public
|
|
33
36
|
*/
|
|
34
37
|
export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
35
|
-
[IS_FUTURE]: true;
|
|
36
38
|
/**
|
|
37
39
|
* Cancel this request by firing the {@link AbortController}'s signal.
|
|
38
40
|
*
|
|
41
|
+
* This method can be used as an action or event handler as its
|
|
42
|
+
* context is bound to the Future instance.
|
|
43
|
+
*
|
|
39
44
|
* @privateRemarks
|
|
40
45
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort)
|
|
41
46
|
*
|
|
@@ -46,8 +51,10 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
|
46
51
|
/**
|
|
47
52
|
* Get the response stream, if any, once made available.
|
|
48
53
|
*
|
|
54
|
+
* This method can be used as an action or event handler as its
|
|
55
|
+
* context is bound to the Future instance.
|
|
56
|
+
*
|
|
49
57
|
* @public
|
|
50
|
-
* @return {Promise<ReadableStream | null>}
|
|
51
58
|
*/
|
|
52
59
|
getStream(): Promise<ReadableStream | null>;
|
|
53
60
|
/**
|
|
@@ -55,28 +62,27 @@ export interface Future<T> extends Promise<StructuredDataDocument<T>> {
|
|
|
55
62
|
* mostly useful for instrumentation and infrastructure.
|
|
56
63
|
*
|
|
57
64
|
* @param cb the callback to run
|
|
58
|
-
* @public
|
|
59
|
-
* @return {void}
|
|
60
65
|
*/
|
|
61
66
|
onFinalize(cb: () => void): void;
|
|
62
67
|
/**
|
|
63
68
|
* The identifier of the associated request, if any, as
|
|
64
69
|
* assigned by the CacheHandler.
|
|
65
|
-
*
|
|
66
|
-
* @property lid
|
|
67
|
-
* @type {StableDocumentIdentifier | null}
|
|
68
|
-
* @public
|
|
69
70
|
*/
|
|
70
|
-
lid:
|
|
71
|
+
lid: RequestKey | null;
|
|
71
72
|
/**
|
|
72
73
|
* The id of the associated request, if any, as assigned
|
|
73
74
|
* by the RequestManager
|
|
74
75
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
76
|
+
* This is not unique across Manager instances and cannot
|
|
77
|
+
* be used to identify or dedupe requests.
|
|
78
78
|
*/
|
|
79
79
|
id: number;
|
|
80
|
+
/**
|
|
81
|
+
* The RequestManager or Store that initiated this request.
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
requester: RequestManager | Store;
|
|
80
86
|
}
|
|
81
87
|
export type DeferredFuture<T> = {
|
|
82
88
|
resolve(v: StructuredDataDocument<T>): void;
|
|
@@ -191,8 +197,6 @@ const manager = new RequestManager()
|
|
|
191
197
|
|
|
192
198
|
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
199
|
|
|
194
|
-
|
|
195
|
-
@class (Interface) Handler
|
|
196
200
|
@public
|
|
197
201
|
*/
|
|
198
202
|
export interface Handler {
|
|
@@ -202,20 +206,17 @@ export interface Handler {
|
|
|
202
206
|
* other handlers.
|
|
203
207
|
*
|
|
204
208
|
* @public
|
|
205
|
-
* @param context
|
|
206
|
-
* @param next
|
|
207
209
|
*/
|
|
208
210
|
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
|
|
209
211
|
}
|
|
210
212
|
/**
|
|
211
|
-
* The CacheHandler is identical to other handlers
|
|
213
|
+
* The CacheHandler is identical to other handlers except that it
|
|
212
214
|
* is allowed to return a value synchronously. This is useful for
|
|
213
215
|
* features like reducing microtask queueing when de-duping.
|
|
214
216
|
*
|
|
215
217
|
* A RequestManager may only have one CacheHandler, registered via
|
|
216
218
|
* `manager.useCache(CacheHandler)`.
|
|
217
219
|
*
|
|
218
|
-
* @class (Interface) CacheHandler
|
|
219
220
|
* @public
|
|
220
221
|
*/
|
|
221
222
|
export interface CacheHandler {
|
|
@@ -225,8 +226,6 @@ export interface CacheHandler {
|
|
|
225
226
|
* other handlers.
|
|
226
227
|
*
|
|
227
228
|
* @public
|
|
228
|
-
* @param context
|
|
229
|
-
* @param next
|
|
230
229
|
*/
|
|
231
230
|
request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T> | T;
|
|
232
231
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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:
|
|
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 {
|
|
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:
|
|
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 {
|
|
58
|
+
* @param {RequestKey | null} identifier
|
|
59
59
|
* @param {Store} store
|
|
60
60
|
* @return {void}
|
|
61
61
|
*/
|
|
62
|
-
willRequest?(request: ImmutableRequestInfo, identifier:
|
|
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 {
|
|
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:
|
|
97
|
+
didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: RequestKey | null, store: Store): void;
|
|
98
98
|
}
|