@warp-drive-mirror/core 5.10.0-alpha.13 → 5.10.0-alpha.14
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/dist/{-private-BpyvBYFj.js → -private-Y-13dsHO.js} +39 -9
- package/dist/-private-Y-13dsHO.js.map +1 -0
- package/dist/build-config/babel-macros.d.ts +5 -0
- package/dist/build-config/canary-features.d.ts +5 -0
- package/dist/build-config/debugging.d.ts +59 -0
- package/dist/build-config/deprecations.d.ts +5 -0
- package/dist/build-config.d.ts +17 -0
- package/dist/{configure-CjsojjiI.d.ts → configure-CodrrdQr.d.ts} +51 -8
- package/dist/configure-CodrrdQr.d.ts.map +1 -0
- package/dist/configure.d.ts +10 -2
- package/dist/configure.js +2 -2
- package/dist/graph/-private.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{internal-CgOlgOt3.d.ts → internal-BOC6nyCi.d.ts} +25 -15
- package/dist/{internal-CgOlgOt3.d.ts.map → internal-BOC6nyCi.d.ts.map} +1 -1
- package/dist/reactive/-private.d.ts +1 -1
- package/dist/reactive.d.ts +276 -1
- package/dist/reactive.js +2 -2
- package/dist/{request-MiwUbGdT.js → request-DUGpwUhf.js} +23 -13
- package/dist/{request-MiwUbGdT.js.map → request-DUGpwUhf.js.map} +1 -1
- package/dist/request.d.ts +9 -1
- package/dist/request.js +1 -1
- package/dist/signals/-leaked.d.ts +16 -2
- package/dist/signals/-leaked.d.ts.map +1 -1
- package/dist/signals/-leaked.js +1 -1
- package/dist/{src-DlNeupkA.js → src-DDLNZD8D.js} +5 -5
- package/dist/{src-DlNeupkA.js.map → src-DDLNZD8D.js.map} +1 -1
- package/dist/store/-private.d.ts +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/store.d.ts +6 -1
- package/dist/types/-private.d.ts +1 -0
- package/dist/types/-private.js +1 -1
- package/dist/types/cache/relationship.d.ts +5 -0
- package/dist/types/cache.d.ts +6 -1
- package/dist/types/graph.d.ts +5 -0
- package/dist/types/record.d.ts +5 -0
- package/dist/types/request.d.ts +1 -1
- package/dist/types/runtime.d.ts +10 -5
- package/dist/types/runtime.d.ts.map +1 -1
- package/dist/types/runtime.js +7 -3
- package/dist/types/runtime.js.map +1 -1
- package/dist/types/schema/concepts.d.ts +5 -0
- package/dist/types/schema/schema-service.d.ts +6 -1
- package/dist/types/spec/error.d.ts +4 -0
- package/dist/types/spec/json-api-raw.d.ts +5 -0
- package/dist/types.d.ts +9 -1
- package/dist/unpkg/dev/{-private-BH4O810v.js → -private-BoKjsWc1.js} +39 -9
- package/dist/unpkg/dev/-private-BoKjsWc1.js.map +1 -0
- package/dist/unpkg/dev/configure.js +2 -2
- package/dist/unpkg/dev/index.js +1 -1
- package/dist/unpkg/dev/reactive.js +2 -2
- package/dist/unpkg/dev/{request-Fe-vpe-u.js → request-BQUGZTOj.js} +23 -13
- package/dist/unpkg/dev/{request-Fe-vpe-u.js.map → request-BQUGZTOj.js.map} +1 -1
- package/dist/unpkg/dev/request.js +1 -1
- package/dist/unpkg/dev/signals/-leaked.js +1 -1
- package/dist/unpkg/dev/{src-FSk0Z_Lp.js → src-DqRXbeNO.js} +5 -5
- package/dist/unpkg/dev/{src-FSk0Z_Lp.js.map → src-DqRXbeNO.js.map} +1 -1
- package/dist/unpkg/dev/store/-private.js +1 -1
- package/dist/unpkg/dev/types/-private.js +1 -1
- package/dist/unpkg/dev/types/runtime.js +7 -3
- package/dist/unpkg/dev/types/runtime.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{-private-BH4O810v.js → -private-BoKjsWc1.js} +39 -9
- package/dist/unpkg/dev-deprecated/-private-BoKjsWc1.js.map +1 -0
- package/dist/unpkg/dev-deprecated/configure.js +2 -2
- package/dist/unpkg/dev-deprecated/index.js +1 -1
- package/dist/unpkg/dev-deprecated/reactive.js +2 -2
- package/dist/unpkg/dev-deprecated/{request-Fe-vpe-u.js → request-BQUGZTOj.js} +23 -13
- package/dist/unpkg/dev-deprecated/{request-Fe-vpe-u.js.map → request-BQUGZTOj.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/request.js +1 -1
- package/dist/unpkg/dev-deprecated/signals/-leaked.js +1 -1
- package/dist/unpkg/dev-deprecated/{src-Isk_Je7q.js → src-EY9o2zd6.js} +5 -5
- package/dist/unpkg/dev-deprecated/{src-Isk_Je7q.js.map → src-EY9o2zd6.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/store/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/types/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/types/runtime.js +7 -3
- package/dist/unpkg/dev-deprecated/types/runtime.js.map +1 -1
- package/dist/unpkg/{prod-deprecated/-private-DKVDMUfT.js → prod/-private-CRDwlN1v.js} +39 -9
- package/dist/unpkg/prod/-private-CRDwlN1v.js.map +1 -0
- package/dist/unpkg/prod/configure.js +2 -2
- package/dist/unpkg/prod/index.js +1 -1
- package/dist/unpkg/prod/reactive.js +2 -2
- package/dist/unpkg/{prod-deprecated/request-ndw2Fy91.js → prod/request-0h8eJko9.js} +23 -13
- package/dist/unpkg/{prod-deprecated/request-ndw2Fy91.js.map → prod/request-0h8eJko9.js.map} +1 -1
- package/dist/unpkg/prod/request.js +1 -1
- package/dist/unpkg/prod/signals/-leaked.js +1 -1
- package/dist/unpkg/prod/{src-CoSpuocQ.js → src-Dagh1FmP.js} +5 -5
- package/dist/unpkg/prod/{src-CoSpuocQ.js.map → src-Dagh1FmP.js.map} +1 -1
- package/dist/unpkg/prod/store/-private.js +1 -1
- package/dist/unpkg/prod/types/-private.js +1 -1
- package/dist/unpkg/prod/types/runtime.js +7 -3
- package/dist/unpkg/prod/types/runtime.js.map +1 -1
- package/dist/unpkg/{prod/-private-DKVDMUfT.js → prod-deprecated/-private-CRDwlN1v.js} +39 -9
- package/dist/unpkg/prod-deprecated/-private-CRDwlN1v.js.map +1 -0
- package/dist/unpkg/prod-deprecated/configure.js +2 -2
- package/dist/unpkg/prod-deprecated/index.js +1 -1
- package/dist/unpkg/prod-deprecated/reactive.js +2 -2
- package/dist/unpkg/{prod/request-ndw2Fy91.js → prod-deprecated/request-0h8eJko9.js} +23 -13
- package/dist/unpkg/{prod/request-ndw2Fy91.js.map → prod-deprecated/request-0h8eJko9.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/request.js +1 -1
- package/dist/unpkg/prod-deprecated/signals/-leaked.js +1 -1
- package/dist/unpkg/prod-deprecated/{src-FK_rMde5.js → src-CvV5lz9D.js} +5 -5
- package/dist/unpkg/prod-deprecated/{src-FK_rMde5.js.map → src-CvV5lz9D.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/store/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/types/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/types/runtime.js +7 -3
- package/dist/unpkg/prod-deprecated/types/runtime.js.map +1 -1
- package/logos/README.md +1 -1
- package/package.json +4 -4
- package/dist/-private-BpyvBYFj.js.map +0 -1
- package/dist/configure-CjsojjiI.d.ts.map +0 -1
- package/dist/unpkg/dev/-private-BH4O810v.js.map +0 -1
- package/dist/unpkg/dev-deprecated/-private-BH4O810v.js.map +0 -1
- package/dist/unpkg/prod/-private-DKVDMUfT.js.map +0 -1
- package/dist/unpkg/prod-deprecated/-private-DKVDMUfT.js.map +0 -1
package/dist/reactive.d.ts
CHANGED
|
@@ -1,2 +1,277 @@
|
|
|
1
|
-
|
|
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/configuration/)
|
|
9
|
+
* - For defining resource schemas, see [The Schema Guide](/guides/the-manual/schemas/)
|
|
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-mirror/legacy` is required (though most imports from it can be removed)
|
|
29
|
+
* - `async: true` relationships are supported (but not recommended outside of [LinksMode](/guides/the-manual/misc/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](/guides/the-manual/misc/links-mode.md))
|
|
42
|
+
* - The `@warp-drive-mirror/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 {@link @warp-drive-mirror/json-api! | @warp-drive-mirror/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-mirror/core/reactive';
|
|
192
|
+
*
|
|
193
|
+
* const editable = await checkout<EditableUser>(user);
|
|
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-mirror/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
|
+
* @summary Schema-driven reactive records, arrays, and documents the store builds from cached data, plus the
|
|
273
|
+
* `SchemaService` and schema types that define them.
|
|
274
|
+
* @module
|
|
275
|
+
*/
|
|
276
|
+
import { C as getRequestState, Cn as Transformation, D as ResolvedPromise, Dt as ReactiveDataDocument, E as RejectedPromise, En as withDefaults, H as checkout, K as LegacyManyArray, O as getPromiseState, Ot as ReactiveDocument, R as instantiateRecord, S as ResolvedRequest, Sn as SchemaService, T as PromiseState, Tn as registerDerivations, U as commit, V as ReactiveResource, _ as CancelledRequest, b as RequestLoadingState, bn as ExtensionDef, c as AutorefreshBehaviorCombos, dt as LegacyQueryArray, f as RecoveryFeatures, ft as LegacyLiveArray, g as createRequestSubscription, gt as Checkout, h as SubscriptionArgs, kt as ReactiveErrorDocument, l as AutorefreshBehaviorType, m as RequestSubscription, mt as ReactiveResourceArray, p as RequestArgs, u as ContentFeatures, v as PendingRequest, vn as CAUTION_MEGA_DANGER_ZONE_Extension, w as PendingPromise, wn as fromIdentity, x as RequestState, xn as ProcessedExtension, y as RejectedRequest, z as teardownRecord } from "./internal-BOC6nyCi.js";
|
|
2
277
|
export { type AutorefreshBehaviorCombos, type AutorefreshBehaviorType, type CAUTION_MEGA_DANGER_ZONE_Extension, type CancelledRequest, Checkout, type ContentFeatures, type ExtensionDef, type LegacyLiveArray, type LegacyManyArray, type LegacyQueryArray, type PendingPromise, type PendingRequest, type ProcessedExtension, type PromiseState, type ReactiveDataDocument, type ReactiveDocument, type ReactiveErrorDocument, type ReactiveResource, type ReactiveResourceArray, type RecoveryFeatures, type RejectedPromise, type RejectedRequest, type RequestArgs, type RequestLoadingState, type RequestState, type RequestSubscription, type ResolvedPromise, type ResolvedRequest, SchemaService, type SubscriptionArgs, type Transformation, checkout, commit, createRequestSubscription, fromIdentity, getPromiseState, getRequestState, instantiateRecord, registerDerivations, teardownRecord, withDefaults };
|
package/dist/reactive.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as getRequestState, t as getPromiseState, u as createRequestSubscription } from "./-private-
|
|
1
|
+
import { d as getRequestState, t as getPromiseState, u as createRequestSubscription } from "./-private-Y-13dsHO.js";
|
|
2
2
|
import { t as Checkout } from "./-private-CmNOwhK0.js";
|
|
3
|
-
import { a as fromIdentity, c as instantiateRecord, d as commit, i as SchemaService, l as teardownRecord, o as registerDerivations, s as withDefaults, u as checkout } from "./src-
|
|
3
|
+
import { a as fromIdentity, c as instantiateRecord, d as commit, i as SchemaService, l as teardownRecord, o as registerDerivations, s as withDefaults, u as checkout } from "./src-DDLNZD8D.js";
|
|
4
4
|
|
|
5
5
|
export { Checkout, SchemaService, checkout, commit, createRequestSubscription, fromIdentity, getPromiseState, getRequestState, instantiateRecord, registerDerivations, teardownRecord, withDefaults };
|
|
@@ -732,17 +732,21 @@ function createFuture(owner) {
|
|
|
732
732
|
/**
|
|
733
733
|
* Brands the supplied object with the supplied response type.
|
|
734
734
|
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
735
|
+
* Call it inside a [builder](/guides/the-manual/requests/builders), so the type is part of
|
|
736
|
+
* the builder's contract and every caller gets it through inference. Calling it inline
|
|
737
|
+
* where the request is made is a cast. The [Typing Requests](/guides/the-manual/requests/typing-requests)
|
|
738
|
+
* guide shows how to use it.
|
|
737
739
|
*
|
|
738
740
|
* ```ts
|
|
739
741
|
* import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';
|
|
740
742
|
* import { withResponseType } from '@warp-drive-mirror/core/request';
|
|
741
743
|
* import type { User } from '#/data/user.ts'
|
|
742
744
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
745
|
+
* export function getUser(id: string) {
|
|
746
|
+
* return withResponseType<ReactiveDataDocument<User>>({ url: `/users/${id}` });
|
|
747
|
+
* }
|
|
748
|
+
*
|
|
749
|
+
* const result = await store.request(getUser('1'));
|
|
746
750
|
*
|
|
747
751
|
* result.content.data; // will have type User
|
|
748
752
|
* ```
|
|
@@ -758,16 +762,20 @@ function withResponseType(obj) {
|
|
|
758
762
|
* wrapped in {@link ReactiveDataDocument}. This is a convenience for
|
|
759
763
|
* the common case of using {@link withResponseType} with `ReactiveDataDocument`.
|
|
760
764
|
*
|
|
761
|
-
*
|
|
765
|
+
* Like `withResponseType`, call it inside a [builder](/guides/the-manual/requests/builders)
|
|
766
|
+
* rather than where the request is made. The
|
|
767
|
+
* [Typing Requests](/guides/the-manual/requests/typing-requests#typing-reactive-responses)
|
|
762
768
|
* guide shows how to use it.
|
|
763
769
|
*
|
|
764
770
|
* ```ts
|
|
765
771
|
* import { withReactiveResponse } from '@warp-drive-mirror/core/request';
|
|
766
772
|
* import type { User } from '#/data/user.ts'
|
|
767
773
|
*
|
|
768
|
-
*
|
|
769
|
-
* withReactiveResponse<User>({ url:
|
|
770
|
-
*
|
|
774
|
+
* export function getUser(id: string) {
|
|
775
|
+
* return withReactiveResponse<User>({ url: `/users/${id}` });
|
|
776
|
+
* }
|
|
777
|
+
*
|
|
778
|
+
* const result = await store.request(getUser('1'));
|
|
771
779
|
*
|
|
772
780
|
* result.content.data; // will have type User
|
|
773
781
|
* ```
|
|
@@ -777,9 +785,11 @@ function withResponseType(obj) {
|
|
|
777
785
|
* ```ts
|
|
778
786
|
* type PageMeta = { page: { limit: number; offset: number }; total?: number };
|
|
779
787
|
*
|
|
780
|
-
*
|
|
781
|
-
* withReactiveResponse<User[], PageMeta>({ url: '/users' })
|
|
782
|
-
*
|
|
788
|
+
* export function getUsers() {
|
|
789
|
+
* return withReactiveResponse<User[], PageMeta>({ url: '/users' });
|
|
790
|
+
* }
|
|
791
|
+
*
|
|
792
|
+
* const result = await store.request(getUsers());
|
|
783
793
|
*
|
|
784
794
|
* result.content.meta?.total; // number | undefined
|
|
785
795
|
* ```
|
|
@@ -800,4 +810,4 @@ const withBrand = withResponseType;
|
|
|
800
810
|
|
|
801
811
|
//#endregion
|
|
802
812
|
export { upgradePromise as a, executeNextHandler as c, getRequestResult as d, setPromiseResult as f, createDeferred as i, clearRequestResult as l, assertValidRequest as m, withReactiveResponse as n, DOMError as o, cloneResponseProperties as p, withResponseType as r, IS_CACHE_HANDLER as s, withBrand as t, getPromiseResult as u };
|
|
803
|
-
//# sourceMappingURL=request-
|
|
813
|
+
//# sourceMappingURL=request-DUGpwUhf.js.map
|