@warp-drive/core 5.6.0-beta.1 → 5.6.0-beta.3
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 +0 -87
- package/declarations/graph/-private/-utils.d.ts +5 -11
- package/declarations/graph/-private/coerce-id.d.ts +0 -6
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
- 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 -51
- package/declarations/graph/-private/normalize-link.d.ts +0 -6
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
- 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 -27
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -11
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -11
- 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 -34
- package/declarations/reactive/-private/schema.d.ts +50 -68
- package/declarations/reactive/-private/symbols.d.ts +2 -33
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +3 -5
- 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 -24
- 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 -5
- package/declarations/store/-private/caches/instance-cache.d.ts +22 -28
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -40
- 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} +35 -53
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
- package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -25
- 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 +132 -37
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
- 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 +67 -0
- package/declarations/store/-private/store-service.d.ts +167 -877
- package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
- package/declarations/store/-private.d.ts +13 -14
- 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 +64 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +223 -0
- package/declarations/store/deprecated/store.d.ts +783 -0
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +0 -11
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -37
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -7
- package/declarations/types/cache.d.ts +51 -127
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -78
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +66 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +391 -14
- package/declarations/types/spec/document.d.ts +6 -10
- package/declarations/types/spec/json-api-raw.d.ts +6 -9
- package/declarations/types.d.ts +1 -1
- package/declarations/utils/string.d.ts +2 -3
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -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 +337 -1422
- package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
- 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 +11 -11
- 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/legacy-model-support/record-reference.d.ts +0 -159
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
- 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/declarations/store/-types/q/ds-model.d.ts +0 -21
- package/dist/handler-C2T-IyJK.js +0 -339
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
// Great, got your attention with that warning didn't we?
|
|
2
|
-
// Good. Here's the deal: typescript treats symbols as unique types.
|
|
3
|
-
// If by accident a module creating a symbol is processed more than
|
|
4
|
-
// once, the symbol will be different in each processing. This will
|
|
5
|
-
// cause a type error.
|
|
6
|
-
// It could also cause a runtime error if the symbol is used innapropriately.
|
|
7
|
-
// However, this case is extremely hard to hit and would require other things
|
|
8
|
-
// to go wrong first.
|
|
9
|
-
//
|
|
10
|
-
// So, why do the warning? And why do we lie about the types of the symbols?
|
|
11
|
-
//
|
|
12
|
-
// Because we intentionally create multiple copies of them within the types
|
|
13
|
-
// at build time. This is because we rollup our d.ts files in order to give
|
|
14
|
-
// our consumers a better experience.
|
|
15
|
-
//
|
|
16
|
-
// However, no tool today supports rolling up d.ts files with multiple entry
|
|
17
|
-
// points correctly. The tool we use currently (vite-plugin-dts) uses @microsoft/api-extractor
|
|
18
|
-
// which creates a fully unique stand-alone types file per-entry-point. Thus
|
|
19
|
-
// every entry point that uses one of these symbols somewhere will have accidentally
|
|
20
|
-
// created a new symbol type.
|
|
21
|
-
//
|
|
22
|
-
// This cast allows us to rollup these types using this tool while not encountering
|
|
23
|
-
// the unique symbol type issue.
|
|
24
|
-
//
|
|
25
|
-
// Note that none of these symbols are part of the public API, these are used for
|
|
26
|
-
// debugging DX and as a safe way to provide an intimate contract on public objects.
|
|
27
1
|
export declare const SOURCE: "___(unique) Symbol(SOURCE)";
|
|
28
|
-
export declare const MUTATE: "___(unique) Symbol(MUTATE)";
|
|
29
2
|
export declare const Destroy: "___(unique) Symbol(Destroy)";
|
|
30
|
-
export declare const Identifier: "___(unique) Symbol(Identifier)";
|
|
31
|
-
export declare const Editable: "___(unique) Symbol(Editable)";
|
|
32
|
-
export declare const Parent: "___(unique) Symbol(Parent)";
|
|
33
3
|
export declare const Checkout: "___(unique) Symbol(Checkout)";
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const EmbeddedField: "___(unique) Symbol(EmbeddedField)";
|
|
4
|
+
export declare const Commit: "___(unique) Symbol(Commit)";
|
|
5
|
+
export declare const Context: "___(unique) Symbol(Context)";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Context } from "./-private/symbols.js";
|
|
@@ -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,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:
|
|
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,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,15 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
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:
|
|
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:
|
|
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
|
-
*
|
|
76
|
-
*
|
|
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
|
|
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
|
-
|
|
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;
|