@warp-drive/legacy 5.8.0-alpha.4 → 5.8.0-alpha.41
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/README.md +14 -27
- package/declarations/adapter/error.d.ts +7 -7
- package/declarations/adapter/json-api.d.ts +6 -8
- package/declarations/adapter/rest.d.ts +26 -112
- package/declarations/adapter.d.ts +6 -8
- package/declarations/compat/-private.d.ts +1 -1
- package/declarations/compat/builders/find-all.d.ts +6 -6
- package/declarations/compat/builders/find-record.d.ts +8 -8
- package/declarations/compat/builders/query.d.ts +12 -12
- package/declarations/compat/extensions.d.ts +1 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
- package/declarations/compat/utils.d.ts +17 -17
- package/declarations/compat.d.ts +35 -11
- package/declarations/index.d.ts +70 -0
- package/declarations/model/-private/attr.d.ts +5 -6
- package/declarations/model/-private/belongs-to.d.ts +4 -5
- package/declarations/model/-private/has-many.d.ts +4 -5
- package/declarations/model/-private/hooks.d.ts +1 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +18 -59
- package/declarations/model/-private/promise-many-array.d.ts +0 -18
- package/declarations/model/-private/record-state.d.ts +1 -1
- package/declarations/model/-private/references/belongs-to.d.ts +19 -29
- package/declarations/model/-private/references/has-many.d.ts +14 -16
- package/declarations/model/migration-support.d.ts +46 -21
- package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
- package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
- package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
- package/declarations/model-fragments/index.d.ts +5 -0
- package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
- package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
- package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
- package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
- package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
- package/declarations/model-fragments.d.ts +9 -0
- package/declarations/model.d.ts +2 -2
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
- package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
- package/declarations/serializer/-private/transforms/date.d.ts +2 -2
- package/declarations/serializer/-private/transforms/number.d.ts +1 -1
- package/declarations/serializer/-private/transforms/string.d.ts +1 -1
- package/declarations/serializer/json-api.d.ts +11 -12
- package/declarations/serializer/json.d.ts +9 -11
- package/declarations/serializer/rest.d.ts +4 -6
- package/declarations/serializer.d.ts +9 -12
- package/dist/{-private-8UmnAf9J.js → -private-BG3bMiKp.js} +3 -2
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +14 -15
- package/dist/adapter/json-api.js +4 -1
- package/dist/adapter/rest.js +38 -125
- package/dist/adapter.js +6 -8
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +26 -26
- package/dist/compat/utils.js +17 -18
- package/dist/compat.js +61 -43
- package/dist/{errors-8kD2mSe_.js → errors-Cz5KrzBk.js} +115 -122
- package/dist/hooks-D6diaM34.js +74 -0
- package/dist/index.js +195 -0
- package/dist/{json-DziiodPf.js → json-ChdEfB0X.js} +18 -35
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +57 -25
- package/dist/model-for-CqXsIKws.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +18 -90
- package/dist/{schema-provider-DQu4Rjco.js → schema-provider-DJCV_6AF.js} +50 -95
- package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-DPZYoF-i.js} +1 -1
- package/dist/serializer/json-api.js +18 -45
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +14 -21
- package/dist/serializer/transform.js +15 -6
- package/dist/serializer.js +9 -13
- package/dist/store.js +5 -1
- package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev/adapter/-private.js +1 -0
- package/dist/unpkg/dev/adapter/error.js +335 -0
- package/dist/unpkg/dev/adapter/json-api.js +271 -0
- package/dist/unpkg/dev/adapter/rest.js +1171 -0
- package/dist/unpkg/dev/adapter.js +1252 -0
- package/dist/unpkg/dev/compat/-private.js +1 -0
- package/dist/unpkg/dev/compat/builders.js +275 -0
- package/dist/unpkg/dev/compat/extensions.js +242 -0
- package/dist/unpkg/dev/compat/utils.js +223 -0
- package/dist/unpkg/dev/compat.js +1147 -0
- package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
- package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
- package/dist/unpkg/dev/index.js +197 -0
- package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev/model/-private.js +1 -0
- package/dist/unpkg/dev/model/migration-support.js +553 -0
- package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev/model-fragments.js +76 -0
- package/dist/unpkg/dev/model.js +678 -0
- package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +2186 -0
- package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev/serializer/json-api.js +649 -0
- package/dist/unpkg/dev/serializer/json.js +4 -0
- package/dist/unpkg/dev/serializer/rest.js +1242 -0
- package/dist/unpkg/dev/serializer/transform.js +278 -0
- package/dist/unpkg/dev/serializer.js +248 -0
- package/dist/unpkg/dev/store.js +637 -0
- package/dist/unpkg/dev/util-DvanW33H.js +20 -0
- package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
- package/dist/unpkg/dev-deprecated/adapter/rest.js +1171 -0
- package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
- package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
- package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
- package/dist/unpkg/dev-deprecated/compat.js +1147 -0
- package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
- package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
- package/dist/unpkg/dev-deprecated/index.js +196 -0
- package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -0
- package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/dev-deprecated/model.js +682 -0
- package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +2211 -0
- package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -0
- package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
- package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/dev-deprecated/serializer.js +248 -0
- package/dist/unpkg/dev-deprecated/store.js +637 -0
- package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
- package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
- package/dist/unpkg/prod/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -0
- package/dist/unpkg/prod/adapter/error.js +330 -0
- package/dist/unpkg/prod/adapter/json-api.js +266 -0
- package/dist/unpkg/prod/adapter/rest.js +1134 -0
- package/dist/unpkg/prod/adapter.js +1219 -0
- package/dist/unpkg/prod/compat/-private.js +1 -0
- package/dist/unpkg/prod/compat/builders.js +210 -0
- package/dist/unpkg/prod/compat/extensions.js +232 -0
- package/dist/unpkg/prod/compat/utils.js +218 -0
- package/dist/unpkg/prod/compat.js +727 -0
- package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
- package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
- package/dist/unpkg/prod/index.js +151 -0
- package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod/model/-private.js +1 -0
- package/dist/unpkg/prod/model/migration-support.js +546 -0
- package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod/model-fragments.js +76 -0
- package/dist/unpkg/prod/model.js +593 -0
- package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +1861 -0
- package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod/serializer/json-api.js +592 -0
- package/dist/unpkg/prod/serializer/json.js +4 -0
- package/dist/unpkg/prod/serializer/rest.js +1210 -0
- package/dist/unpkg/prod/serializer/transform.js +278 -0
- package/dist/unpkg/prod/serializer.js +248 -0
- package/dist/unpkg/prod/store.js +505 -0
- package/dist/unpkg/prod/util-DvanW33H.js +20 -0
- package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
- package/dist/unpkg/prod-deprecated/adapter/rest.js +1134 -0
- package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
- package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
- package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
- package/dist/unpkg/prod-deprecated/compat.js +727 -0
- package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
- package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
- package/dist/unpkg/prod-deprecated/index.js +150 -0
- package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -0
- package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/prod-deprecated/model.js +596 -0
- package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +1904 -0
- package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -0
- package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
- package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/prod-deprecated/serializer.js +248 -0
- package/dist/unpkg/prod-deprecated/store.js +505 -0
- package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
- package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +14 -6
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
2
|
-
import { memoized, defineSignal,
|
|
2
|
+
import { memoized, defineSignal, defineNonEnumerableSignal, notifyInternalSignal } from '@warp-drive/core/signals/-leaked';
|
|
3
|
+
import { assertPrivateStore, isResourceKey, recordIdentifierFor, isPrivateStore, storeFor, fastPush, createLegacyManyArray } from '@warp-drive/core/store/-private';
|
|
3
4
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
4
5
|
import { EnableHydration } from '@warp-drive/core/types/request';
|
|
5
|
-
import { u as upgradeStore } from "./-private-
|
|
6
|
+
import { u as upgradeStore } from "./-private-BG3bMiKp.js";
|
|
6
7
|
import { computed, get } from '@ember/object';
|
|
7
8
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
8
9
|
import ObjectProxy from '@ember/object/proxy';
|
|
@@ -87,7 +88,6 @@ PromiseBelongsTo.prototype[LegacyPromiseProxy] = true;
|
|
|
87
88
|
const comments = await post.comments;
|
|
88
89
|
```
|
|
89
90
|
|
|
90
|
-
@class PromiseManyArray
|
|
91
91
|
@public
|
|
92
92
|
*/
|
|
93
93
|
class PromiseManyArray {
|
|
@@ -99,7 +99,6 @@ class PromiseManyArray {
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Retrieve the length of the content
|
|
102
|
-
* @property length
|
|
103
102
|
* @public
|
|
104
103
|
*/
|
|
105
104
|
get length() {
|
|
@@ -148,8 +147,6 @@ class PromiseManyArray {
|
|
|
148
147
|
/**
|
|
149
148
|
* Reload the relationship
|
|
150
149
|
* @public
|
|
151
|
-
* @param options
|
|
152
|
-
* @return
|
|
153
150
|
*/
|
|
154
151
|
reload(options) {
|
|
155
152
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -166,32 +163,24 @@ class PromiseManyArray {
|
|
|
166
163
|
/**
|
|
167
164
|
* Whether the loading promise is still pending
|
|
168
165
|
*
|
|
169
|
-
* @property isPending
|
|
170
|
-
* @type {Boolean}
|
|
171
166
|
* @public
|
|
172
167
|
*/
|
|
173
168
|
|
|
174
169
|
/**
|
|
175
170
|
* Whether the loading promise rejected
|
|
176
171
|
*
|
|
177
|
-
* @property isRejected
|
|
178
|
-
* @type {Boolean}
|
|
179
172
|
* @public
|
|
180
173
|
*/
|
|
181
174
|
|
|
182
175
|
/**
|
|
183
176
|
* Whether the loading promise succeeded
|
|
184
177
|
*
|
|
185
|
-
* @property isFulfilled
|
|
186
|
-
* @type {Boolean}
|
|
187
178
|
* @public
|
|
188
179
|
*/
|
|
189
180
|
|
|
190
181
|
/**
|
|
191
182
|
* Whether the loading promise completed (resolved or rejected)
|
|
192
183
|
*
|
|
193
|
-
* @property isSettled
|
|
194
|
-
* @type {Boolean}
|
|
195
184
|
* @public
|
|
196
185
|
*/
|
|
197
186
|
|
|
@@ -207,8 +196,6 @@ class PromiseManyArray {
|
|
|
207
196
|
/**
|
|
208
197
|
* catch errors thrown by this promise
|
|
209
198
|
* @public
|
|
210
|
-
* @param callback
|
|
211
|
-
* @return {Promise}
|
|
212
199
|
*/
|
|
213
200
|
catch(cb) {
|
|
214
201
|
return this.promise.catch(cb);
|
|
@@ -218,8 +205,6 @@ class PromiseManyArray {
|
|
|
218
205
|
* run cleanup after this promise completes
|
|
219
206
|
*
|
|
220
207
|
* @public
|
|
221
|
-
* @param callback
|
|
222
|
-
* @return {Promise}
|
|
223
208
|
*/
|
|
224
209
|
finally(cb) {
|
|
225
210
|
return this.promise.finally(cb);
|
|
@@ -237,7 +222,6 @@ class PromiseManyArray {
|
|
|
237
222
|
|
|
238
223
|
/**
|
|
239
224
|
* Retrieve the links for this relationship
|
|
240
|
-
* @property links
|
|
241
225
|
* @public
|
|
242
226
|
*/
|
|
243
227
|
get links() {
|
|
@@ -246,7 +230,6 @@ class PromiseManyArray {
|
|
|
246
230
|
|
|
247
231
|
/**
|
|
248
232
|
* Retrieve the meta for this relationship
|
|
249
|
-
* @property meta
|
|
250
233
|
* @public
|
|
251
234
|
*/
|
|
252
235
|
static {
|
|
@@ -344,11 +327,11 @@ function isResourceIdentiferWithRelatedLinks$1(value) {
|
|
|
344
327
|
and manipulation of a hasMany relationship.
|
|
345
328
|
|
|
346
329
|
It is especially useful when you're dealing with `async` relationships
|
|
347
|
-
from `@
|
|
330
|
+
from `@warp-drive/legacy/model` as it allows synchronous access to
|
|
348
331
|
the relationship data if loaded, as well as APIs for loading, reloading
|
|
349
332
|
the data or accessing available information without triggering a load.
|
|
350
333
|
|
|
351
|
-
It may also be useful when using `sync` relationships with `@
|
|
334
|
+
It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
|
|
352
335
|
that need to be loaded/reloaded with more precise timing than marking the
|
|
353
336
|
relationship as `async` and relying on autofetch would have allowed.
|
|
354
337
|
|
|
@@ -494,7 +477,7 @@ class HasManyReference {
|
|
|
494
477
|
}
|
|
495
478
|
```
|
|
496
479
|
@public
|
|
497
|
-
@return
|
|
480
|
+
@return The name of the remote type. This should either be `link` or `ids`
|
|
498
481
|
*/
|
|
499
482
|
remoteType() {
|
|
500
483
|
const value = this._resource();
|
|
@@ -529,14 +512,14 @@ class HasManyReference {
|
|
|
529
512
|
commentsRef.ids(); // ['1']
|
|
530
513
|
```
|
|
531
514
|
@public
|
|
532
|
-
@return
|
|
515
|
+
@return The ids in this has-many relationship
|
|
533
516
|
*/
|
|
534
517
|
ids() {
|
|
535
518
|
return this.identifiers.map(identifier => identifier.id);
|
|
536
519
|
}
|
|
537
520
|
|
|
538
521
|
/**
|
|
539
|
-
The link
|
|
522
|
+
The link WarpDrive will use to fetch or reload this belongs-to
|
|
540
523
|
relationship. By default it uses only the "related" resource linkage.
|
|
541
524
|
Example
|
|
542
525
|
```javascript
|
|
@@ -565,7 +548,7 @@ class HasManyReference {
|
|
|
565
548
|
}
|
|
566
549
|
```
|
|
567
550
|
@public
|
|
568
|
-
@return
|
|
551
|
+
@return The link WarpDrive will use to fetch or reload this belongs-to relationship.
|
|
569
552
|
*/
|
|
570
553
|
link() {
|
|
571
554
|
const resource = this._resource();
|
|
@@ -620,7 +603,7 @@ class HasManyReference {
|
|
|
620
603
|
usersRef.meta() // { lastUpdated: 1458014400000 }
|
|
621
604
|
```
|
|
622
605
|
@public
|
|
623
|
-
@return
|
|
606
|
+
@return The meta information for the belongs-to relationship.
|
|
624
607
|
*/
|
|
625
608
|
meta() {
|
|
626
609
|
let meta = null;
|
|
@@ -632,7 +615,7 @@ class HasManyReference {
|
|
|
632
615
|
}
|
|
633
616
|
|
|
634
617
|
/**
|
|
635
|
-
`push` can be used to update the data in the relationship and
|
|
618
|
+
`push` can be used to update the data in the relationship and WarpDrive
|
|
636
619
|
will treat the new data as the canonical value of this relationship on
|
|
637
620
|
the backend. An empty array will signify the canonical value should be
|
|
638
621
|
empty.
|
|
@@ -706,9 +689,8 @@ class HasManyReference {
|
|
|
706
689
|
particularly useful if you want to update the state of the relationship without
|
|
707
690
|
forcing the load of all of the associated records.
|
|
708
691
|
@public
|
|
709
|
-
@param
|
|
710
|
-
@param
|
|
711
|
-
@return {Promise<ManyArray | void>}
|
|
692
|
+
@param doc a JSONAPI document object describing the new value of this relationship.
|
|
693
|
+
@param skipFetch [optional] if `true`, do not attempt to fetch unloaded records
|
|
712
694
|
*/
|
|
713
695
|
async push(doc, skipFetch) {
|
|
714
696
|
const {
|
|
@@ -800,7 +782,6 @@ class HasManyReference {
|
|
|
800
782
|
})
|
|
801
783
|
```
|
|
802
784
|
@public
|
|
803
|
-
@return {ManyArray}
|
|
804
785
|
*/
|
|
805
786
|
value() {
|
|
806
787
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
@@ -860,8 +841,8 @@ class HasManyReference {
|
|
|
860
841
|
});
|
|
861
842
|
```
|
|
862
843
|
@public
|
|
863
|
-
@param
|
|
864
|
-
@return
|
|
844
|
+
@param options the options to pass in.
|
|
845
|
+
@return a promise that resolves with the ManyArray in
|
|
865
846
|
this has-many relationship.
|
|
866
847
|
*/
|
|
867
848
|
async load(options) {
|
|
@@ -908,9 +889,9 @@ class HasManyReference {
|
|
|
908
889
|
```javascript
|
|
909
890
|
commentsRef.reload({ adapterOptions: { isPrivate: true } })
|
|
910
891
|
```
|
|
911
|
-
|
|
912
|
-
@param
|
|
913
|
-
@return
|
|
892
|
+
@public
|
|
893
|
+
@param options the options to pass in.
|
|
894
|
+
@return a promise that resolves with the ManyArray in this has-many relationship.
|
|
914
895
|
*/
|
|
915
896
|
reload(options) {
|
|
916
897
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
@@ -951,11 +932,11 @@ function isResourceIdentiferWithRelatedLinks(value) {
|
|
|
951
932
|
and manipulation of a belongsTo relationship.
|
|
952
933
|
|
|
953
934
|
It is especially useful when you're dealing with `async` relationships
|
|
954
|
-
from `@
|
|
935
|
+
from `@warp-drive/legacy/model` as it allows synchronous access to
|
|
955
936
|
the relationship data if loaded, as well as APIs for loading, reloading
|
|
956
937
|
the data or accessing available information without triggering a load.
|
|
957
938
|
|
|
958
|
-
It may also be useful when using `sync` relationships with `@
|
|
939
|
+
It may also be useful when using `sync` relationships with `@warp-drive/legacy/model`
|
|
959
940
|
that need to be loaded/reloaded with more precise timing than marking the
|
|
960
941
|
relationship as `async` and relying on autofetch would have allowed.
|
|
961
942
|
|
|
@@ -971,24 +952,17 @@ function isResourceIdentiferWithRelatedLinks(value) {
|
|
|
971
952
|
References are "stable", meaning that multiple calls to retrieve the reference
|
|
972
953
|
for a given relationship will always return the same HasManyReference.
|
|
973
954
|
|
|
974
|
-
@class BelongsToReference
|
|
975
955
|
@public
|
|
976
956
|
*/
|
|
977
957
|
class BelongsToReference {
|
|
978
958
|
/**
|
|
979
959
|
* The field name on the parent record for this has-many relationship.
|
|
980
960
|
*
|
|
981
|
-
* @property key
|
|
982
|
-
* @type {String}
|
|
983
|
-
* @public
|
|
984
961
|
*/
|
|
985
962
|
|
|
986
963
|
/**
|
|
987
964
|
* The type of resource this relationship will contain.
|
|
988
965
|
*
|
|
989
|
-
* @property type
|
|
990
|
-
* @type {String}
|
|
991
|
-
* @public
|
|
992
966
|
*/
|
|
993
967
|
|
|
994
968
|
// unsubscribe tokens given to us by the notification manager
|
|
@@ -1024,9 +998,6 @@ class BelongsToReference {
|
|
|
1024
998
|
* The identifier of the record that this reference refers to.
|
|
1025
999
|
* `null` if no related record is known.
|
|
1026
1000
|
*
|
|
1027
|
-
* @property identifier
|
|
1028
|
-
* @type {ResourceKey | null}
|
|
1029
|
-
* @public
|
|
1030
1001
|
*/
|
|
1031
1002
|
get identifier() {
|
|
1032
1003
|
if (this.___relatedToken) {
|
|
@@ -1077,7 +1048,7 @@ class BelongsToReference {
|
|
|
1077
1048
|
}
|
|
1078
1049
|
```
|
|
1079
1050
|
@public
|
|
1080
|
-
@return
|
|
1051
|
+
@return The id of the record in this belongsTo relationship.
|
|
1081
1052
|
*/
|
|
1082
1053
|
static {
|
|
1083
1054
|
decorateMethodV2(this.prototype, "identifier", [memoized]);
|
|
@@ -1087,7 +1058,7 @@ class BelongsToReference {
|
|
|
1087
1058
|
}
|
|
1088
1059
|
|
|
1089
1060
|
/**
|
|
1090
|
-
The link
|
|
1061
|
+
The link WarpDrive will use to fetch or reload this belongs-to
|
|
1091
1062
|
relationship. By default it uses only the "related" resource linkage.
|
|
1092
1063
|
Example
|
|
1093
1064
|
```javascript
|
|
@@ -1116,7 +1087,7 @@ class BelongsToReference {
|
|
|
1116
1087
|
}
|
|
1117
1088
|
```
|
|
1118
1089
|
@public
|
|
1119
|
-
@return
|
|
1090
|
+
@return The link WarpDrive will use to fetch or reload this belongs-to relationship.
|
|
1120
1091
|
*/
|
|
1121
1092
|
link() {
|
|
1122
1093
|
const resource = this._resource();
|
|
@@ -1171,7 +1142,7 @@ class BelongsToReference {
|
|
|
1171
1142
|
userRef.meta() // { lastUpdated: 1458014400000 }
|
|
1172
1143
|
```
|
|
1173
1144
|
@public
|
|
1174
|
-
@return
|
|
1145
|
+
@return The meta information for the belongs-to relationship.
|
|
1175
1146
|
*/
|
|
1176
1147
|
meta() {
|
|
1177
1148
|
let meta = null;
|
|
@@ -1194,7 +1165,7 @@ class BelongsToReference {
|
|
|
1194
1165
|
use the "link" otherwise it defaults to "id".
|
|
1195
1166
|
Example
|
|
1196
1167
|
```js [app/models/post.js]
|
|
1197
|
-
import Model, { hasMany } from '@
|
|
1168
|
+
import Model, { hasMany } from '@warp-drive/legacy/model';
|
|
1198
1169
|
export default class PostModel extends Model {
|
|
1199
1170
|
@hasMany('comment', { async: true, inverse: null }) comments;
|
|
1200
1171
|
}
|
|
@@ -1220,7 +1191,7 @@ class BelongsToReference {
|
|
|
1220
1191
|
}
|
|
1221
1192
|
```
|
|
1222
1193
|
@public
|
|
1223
|
-
@return
|
|
1194
|
+
@return The name of the remote type. This should either be `link` or `id`
|
|
1224
1195
|
*/
|
|
1225
1196
|
remoteType() {
|
|
1226
1197
|
const value = this._resource();
|
|
@@ -1231,7 +1202,7 @@ class BelongsToReference {
|
|
|
1231
1202
|
}
|
|
1232
1203
|
|
|
1233
1204
|
/**
|
|
1234
|
-
`push` can be used to update the data in the relationship and
|
|
1205
|
+
`push` can be used to update the data in the relationship and WarpDrive
|
|
1235
1206
|
will treat the new data as the canonical value of this relationship on
|
|
1236
1207
|
the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
|
|
1237
1208
|
clear the relationship.
|
|
@@ -1303,9 +1274,9 @@ class BelongsToReference {
|
|
|
1303
1274
|
particularly useful if you want to update the state of the relationship without
|
|
1304
1275
|
forcing the load of all of the associated record.
|
|
1305
1276
|
@public
|
|
1306
|
-
@param
|
|
1307
|
-
@param
|
|
1308
|
-
@return
|
|
1277
|
+
@param doc a JSONAPI document object describing the new value of this relationship.
|
|
1278
|
+
@param skipFetch [optional] if `true`, do not attempt to fetch unloaded records
|
|
1279
|
+
@return a promise that resolves with the record in this belongs-to relationship after the push has completed.
|
|
1309
1280
|
*/
|
|
1310
1281
|
async push(doc, skipFetch) {
|
|
1311
1282
|
const {
|
|
@@ -1385,7 +1356,7 @@ class BelongsToReference {
|
|
|
1385
1356
|
});
|
|
1386
1357
|
```
|
|
1387
1358
|
@public
|
|
1388
|
-
@return
|
|
1359
|
+
@return the record in this relationship
|
|
1389
1360
|
*/
|
|
1390
1361
|
value() {
|
|
1391
1362
|
const resource = this._resource();
|
|
@@ -1430,7 +1401,7 @@ class BelongsToReference {
|
|
|
1430
1401
|
});
|
|
1431
1402
|
```
|
|
1432
1403
|
```js [app/adapters/user.js]
|
|
1433
|
-
import Adapter from '@
|
|
1404
|
+
import Adapter from '@warp-drive/legacy/adapter';
|
|
1434
1405
|
export default class UserAdapter extends Adapter {
|
|
1435
1406
|
findRecord(store, type, id, snapshot) {
|
|
1436
1407
|
// In the adapter you will have access to adapterOptions.
|
|
@@ -1439,8 +1410,8 @@ class BelongsToReference {
|
|
|
1439
1410
|
});
|
|
1440
1411
|
```
|
|
1441
1412
|
@public
|
|
1442
|
-
@param
|
|
1443
|
-
@return
|
|
1413
|
+
@param options the options to pass in.
|
|
1414
|
+
@return a promise that resolves with the record in this belongs-to relationship.
|
|
1444
1415
|
*/
|
|
1445
1416
|
async load(options) {
|
|
1446
1417
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
@@ -1453,7 +1424,7 @@ class BelongsToReference {
|
|
|
1453
1424
|
|
|
1454
1425
|
/**
|
|
1455
1426
|
Triggers a reload of the value in this relationship. If the
|
|
1456
|
-
remoteType is `"link"`
|
|
1427
|
+
remoteType is `"link"` WarpDrive will use the relationship link to
|
|
1457
1428
|
reload the relationship. Otherwise it will reload the record by its
|
|
1458
1429
|
id.
|
|
1459
1430
|
Example
|
|
@@ -1488,8 +1459,8 @@ class BelongsToReference {
|
|
|
1488
1459
|
userRef.reload({ adapterOptions: { isPrivate: true } })
|
|
1489
1460
|
```
|
|
1490
1461
|
@public
|
|
1491
|
-
@param
|
|
1492
|
-
@return
|
|
1462
|
+
@param options the options to pass in.
|
|
1463
|
+
@return a promise that resolves with the record in this belongs-to relationship after the reload has completed.
|
|
1493
1464
|
*/
|
|
1494
1465
|
reload(options) {
|
|
1495
1466
|
const support = LEGACY_SUPPORT.get(this.___identifier);
|
|
@@ -1581,28 +1552,31 @@ class LegacySupport {
|
|
|
1581
1552
|
this.cache.mutate(mutation);
|
|
1582
1553
|
}
|
|
1583
1554
|
_findBelongsTo(key, resource, relationship, options) {
|
|
1555
|
+
const name = getRealFieldName(this, key);
|
|
1556
|
+
|
|
1584
1557
|
// TODO @runspired follow up if parent isNew then we should not be attempting load here
|
|
1585
1558
|
// TODO @runspired follow up on whether this should be in the relationship requests cache
|
|
1586
|
-
return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this,
|
|
1559
|
+
return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this, name, relationship, identifier), e => handleCompletedRelationshipRequest(this, name, relationship, null, e));
|
|
1587
1560
|
}
|
|
1588
1561
|
reloadBelongsTo(key, options) {
|
|
1589
1562
|
const loadingPromise = this._relationshipPromisesCache[key];
|
|
1590
1563
|
if (loadingPromise) {
|
|
1591
1564
|
return loadingPromise;
|
|
1592
1565
|
}
|
|
1593
|
-
const
|
|
1566
|
+
const name = getRealFieldName(this, key);
|
|
1567
|
+
const resource = this.store.cache.getRelationship(this.identifier, name);
|
|
1568
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1594
1569
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1595
1570
|
if (!test) {
|
|
1596
|
-
throw new Error(`Expected ${key} to be a belongs-to relationship`);
|
|
1571
|
+
throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
|
|
1597
1572
|
}
|
|
1598
1573
|
})(isBelongsTo(relationship)) : {};
|
|
1599
|
-
const resource = this.cache.getRelationship(this.identifier, key);
|
|
1600
1574
|
relationship.state.hasFailedLoadAttempt = false;
|
|
1601
1575
|
relationship.state.shouldForceReload = true;
|
|
1602
|
-
const promise = this._findBelongsTo(
|
|
1603
|
-
if (this._relationshipProxyCache[
|
|
1576
|
+
const promise = this._findBelongsTo(name, resource, relationship, options);
|
|
1577
|
+
if (this._relationshipProxyCache[name]) {
|
|
1604
1578
|
// @ts-expect-error
|
|
1605
|
-
return this._updatePromiseProxyFor('belongsTo',
|
|
1579
|
+
return this._updatePromiseProxyFor('belongsTo', name, {
|
|
1606
1580
|
promise
|
|
1607
1581
|
});
|
|
1608
1582
|
}
|
|
@@ -1610,10 +1584,10 @@ class LegacySupport {
|
|
|
1610
1584
|
}
|
|
1611
1585
|
getBelongsTo(key, options) {
|
|
1612
1586
|
const {
|
|
1613
|
-
identifier
|
|
1614
|
-
cache
|
|
1587
|
+
identifier
|
|
1615
1588
|
} = this;
|
|
1616
|
-
const
|
|
1589
|
+
const name = getRealFieldName(this, key);
|
|
1590
|
+
const resource = this.store.cache.getRelationship(this.identifier, name);
|
|
1617
1591
|
const relatedIdentifier = resource && resource.data ? resource.data : null;
|
|
1618
1592
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1619
1593
|
if (!test) {
|
|
@@ -1621,10 +1595,10 @@ class LegacySupport {
|
|
|
1621
1595
|
}
|
|
1622
1596
|
})(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
|
|
1623
1597
|
const store = this.store;
|
|
1624
|
-
const relationship = this.graph.get(this.identifier,
|
|
1598
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1625
1599
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1626
1600
|
if (!test) {
|
|
1627
|
-
throw new Error(`Expected ${key} to be a belongs-to relationship`);
|
|
1601
|
+
throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
|
|
1628
1602
|
}
|
|
1629
1603
|
})(isBelongsTo(relationship)) : {};
|
|
1630
1604
|
const isAsync = relationship.definition.isAsync;
|
|
@@ -1636,11 +1610,11 @@ class LegacySupport {
|
|
|
1636
1610
|
};
|
|
1637
1611
|
if (isAsync) {
|
|
1638
1612
|
if (relationship.state.hasFailedLoadAttempt) {
|
|
1639
|
-
return this._relationshipProxyCache[
|
|
1613
|
+
return this._relationshipProxyCache[name];
|
|
1640
1614
|
}
|
|
1641
|
-
const promise = this._findBelongsTo(
|
|
1615
|
+
const promise = this._findBelongsTo(name, resource, relationship, options);
|
|
1642
1616
|
const isLoaded = relatedIdentifier && store._instanceCache.recordIsLoaded(relatedIdentifier);
|
|
1643
|
-
return this._updatePromiseProxyFor('belongsTo',
|
|
1617
|
+
return this._updatePromiseProxyFor('belongsTo', name, {
|
|
1644
1618
|
promise,
|
|
1645
1619
|
content: isLoaded ? store._instanceCache.getRecord(relatedIdentifier) : null,
|
|
1646
1620
|
_belongsToState
|
|
@@ -1651,7 +1625,7 @@ class LegacySupport {
|
|
|
1651
1625
|
} else {
|
|
1652
1626
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1653
1627
|
if (!test) {
|
|
1654
|
-
throw new Error(`You looked up the '${key}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`);
|
|
1628
|
+
throw new Error(`You looked up the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${identifier.type}' with id ${identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\`belongsTo(<type>, { async: true, inverse: <inverse> })\`)`);
|
|
1655
1629
|
}
|
|
1656
1630
|
})(store._instanceCache.recordIsLoaded(relatedIdentifier, true)) : {};
|
|
1657
1631
|
return store._instanceCache.getRecord(relatedIdentifier);
|
|
@@ -1659,10 +1633,11 @@ class LegacySupport {
|
|
|
1659
1633
|
}
|
|
1660
1634
|
}
|
|
1661
1635
|
setDirtyBelongsTo(key, value) {
|
|
1636
|
+
const name = getRealFieldName(this, key);
|
|
1662
1637
|
return this.cache.mutate({
|
|
1663
1638
|
op: 'replaceRelatedRecord',
|
|
1664
1639
|
record: this.identifier,
|
|
1665
|
-
field:
|
|
1640
|
+
field: name,
|
|
1666
1641
|
value: extractIdentifierFromRecord(value)
|
|
1667
1642
|
},
|
|
1668
1643
|
// @ts-expect-error
|
|
@@ -1688,13 +1663,15 @@ class LegacySupport {
|
|
|
1688
1663
|
return [identifiers, jsonApi];
|
|
1689
1664
|
}
|
|
1690
1665
|
getManyArray(key, definition) {
|
|
1666
|
+
const name = getRealFieldName(this, key);
|
|
1691
1667
|
if (this.graph) {
|
|
1692
|
-
let manyArray = this._manyArrayCache[
|
|
1668
|
+
let manyArray = this._manyArrayCache[name];
|
|
1693
1669
|
if (!definition) {
|
|
1694
|
-
definition = this.graph.get(this.identifier,
|
|
1670
|
+
definition = this.graph.get(this.identifier, name).definition;
|
|
1695
1671
|
}
|
|
1696
1672
|
if (!manyArray) {
|
|
1697
|
-
const [identifiers, doc] = this._getCurrentState(this.identifier,
|
|
1673
|
+
const [identifiers, doc] = this._getCurrentState(this.identifier, name);
|
|
1674
|
+
const field = getField(this, name);
|
|
1698
1675
|
manyArray = createLegacyManyArray({
|
|
1699
1676
|
store: this.store,
|
|
1700
1677
|
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
@@ -1705,60 +1682,62 @@ class LegacySupport {
|
|
|
1705
1682
|
editable: true,
|
|
1706
1683
|
isAsync: definition.isAsync,
|
|
1707
1684
|
isPolymorphic: definition.isPolymorphic,
|
|
1708
|
-
field:
|
|
1685
|
+
field: field,
|
|
1709
1686
|
identifier: this.identifier,
|
|
1710
1687
|
links: doc.links || null,
|
|
1711
1688
|
meta: doc.meta || null
|
|
1712
1689
|
});
|
|
1713
|
-
this._manyArrayCache[
|
|
1690
|
+
this._manyArrayCache[name] = manyArray;
|
|
1714
1691
|
}
|
|
1715
1692
|
return manyArray;
|
|
1716
1693
|
}
|
|
1717
1694
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1718
1695
|
{
|
|
1719
|
-
throw new Error('hasMany only works with the
|
|
1696
|
+
throw new Error('hasMany only works with the JSONAPICache');
|
|
1720
1697
|
}
|
|
1721
1698
|
})() : {};
|
|
1722
1699
|
}
|
|
1723
1700
|
fetchAsyncHasMany(key, relationship, manyArray, options) {
|
|
1701
|
+
const name = getRealFieldName(this, key);
|
|
1724
1702
|
if (this.graph) {
|
|
1725
|
-
let loadingPromise = this._relationshipPromisesCache[
|
|
1703
|
+
let loadingPromise = this._relationshipPromisesCache[name];
|
|
1726
1704
|
if (loadingPromise) {
|
|
1727
1705
|
return loadingPromise;
|
|
1728
1706
|
}
|
|
1729
|
-
const jsonApi = this.cache.getRelationship(this.identifier,
|
|
1707
|
+
const jsonApi = this.cache.getRelationship(this.identifier, name);
|
|
1730
1708
|
const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
|
|
1731
1709
|
if (!promise) {
|
|
1732
1710
|
manyArray.isLoaded = true;
|
|
1733
1711
|
return Promise.resolve(manyArray);
|
|
1734
1712
|
}
|
|
1735
|
-
loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this,
|
|
1736
|
-
this._relationshipPromisesCache[
|
|
1713
|
+
loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, name, relationship, manyArray), e => handleCompletedRelationshipRequest(this, name, relationship, manyArray, e));
|
|
1714
|
+
this._relationshipPromisesCache[name] = loadingPromise;
|
|
1737
1715
|
return loadingPromise;
|
|
1738
1716
|
}
|
|
1739
1717
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1740
1718
|
{
|
|
1741
|
-
throw new Error('hasMany only works with the
|
|
1719
|
+
throw new Error('hasMany only works with the JSONAPICache');
|
|
1742
1720
|
}
|
|
1743
1721
|
})() : {};
|
|
1744
1722
|
}
|
|
1745
1723
|
reloadHasMany(key, options) {
|
|
1724
|
+
const name = getRealFieldName(this, key);
|
|
1746
1725
|
if (this.graph) {
|
|
1747
|
-
const loadingPromise = this._relationshipPromisesCache[
|
|
1726
|
+
const loadingPromise = this._relationshipPromisesCache[name];
|
|
1748
1727
|
if (loadingPromise) {
|
|
1749
1728
|
return loadingPromise;
|
|
1750
1729
|
}
|
|
1751
|
-
const relationship = this.graph.get(this.identifier,
|
|
1730
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1752
1731
|
const {
|
|
1753
1732
|
definition,
|
|
1754
1733
|
state
|
|
1755
1734
|
} = relationship;
|
|
1756
1735
|
state.hasFailedLoadAttempt = false;
|
|
1757
1736
|
state.shouldForceReload = true;
|
|
1758
|
-
const manyArray = this.getManyArray(
|
|
1759
|
-
const promise = this.fetchAsyncHasMany(
|
|
1760
|
-
if (this._relationshipProxyCache[
|
|
1761
|
-
return this._updatePromiseProxyFor('hasMany',
|
|
1737
|
+
const manyArray = this.getManyArray(name, definition);
|
|
1738
|
+
const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
|
|
1739
|
+
if (this._relationshipProxyCache[name]) {
|
|
1740
|
+
return this._updatePromiseProxyFor('hasMany', name, {
|
|
1762
1741
|
promise
|
|
1763
1742
|
});
|
|
1764
1743
|
}
|
|
@@ -1766,31 +1745,32 @@ class LegacySupport {
|
|
|
1766
1745
|
}
|
|
1767
1746
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1768
1747
|
{
|
|
1769
|
-
throw new Error(`hasMany only works with the
|
|
1748
|
+
throw new Error(`hasMany only works with the JSONAPICache`);
|
|
1770
1749
|
}
|
|
1771
1750
|
})() : {};
|
|
1772
1751
|
}
|
|
1773
1752
|
getHasMany(key, options) {
|
|
1753
|
+
const name = getRealFieldName(this, key);
|
|
1774
1754
|
if (this.graph) {
|
|
1775
|
-
const relationship = this.graph.get(this.identifier,
|
|
1755
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1776
1756
|
const {
|
|
1777
1757
|
definition,
|
|
1778
1758
|
state
|
|
1779
1759
|
} = relationship;
|
|
1780
|
-
const manyArray = this.getManyArray(
|
|
1760
|
+
const manyArray = this.getManyArray(name, definition);
|
|
1781
1761
|
if (definition.isAsync) {
|
|
1782
1762
|
if (state.hasFailedLoadAttempt) {
|
|
1783
|
-
return this._relationshipProxyCache[
|
|
1763
|
+
return this._relationshipProxyCache[name];
|
|
1784
1764
|
}
|
|
1785
|
-
const promise = this.fetchAsyncHasMany(
|
|
1786
|
-
return this._updatePromiseProxyFor('hasMany',
|
|
1765
|
+
const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
|
|
1766
|
+
return this._updatePromiseProxyFor('hasMany', name, {
|
|
1787
1767
|
promise,
|
|
1788
1768
|
content: manyArray
|
|
1789
1769
|
});
|
|
1790
1770
|
} else {
|
|
1791
1771
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1792
1772
|
if (!test) {
|
|
1793
|
-
throw new Error(`You looked up the '${key}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`);
|
|
1773
|
+
throw new Error(`You looked up the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${this.identifier.type}' with id ${this.identifier.id || 'null'} but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async ('hasMany(<type>, { async: true, inverse: <inverse> })')`);
|
|
1794
1774
|
}
|
|
1795
1775
|
})(!anyUnloaded(this.store, relationship)) : {};
|
|
1796
1776
|
return manyArray;
|
|
@@ -1798,7 +1778,7 @@ class LegacySupport {
|
|
|
1798
1778
|
}
|
|
1799
1779
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1800
1780
|
{
|
|
1801
|
-
throw new Error(`hasMany only works with the
|
|
1781
|
+
throw new Error(`hasMany only works with the JSONAPICache`);
|
|
1802
1782
|
}
|
|
1803
1783
|
})() : {};
|
|
1804
1784
|
}
|
|
@@ -1841,7 +1821,8 @@ class LegacySupport {
|
|
|
1841
1821
|
}
|
|
1842
1822
|
return promiseProxy;
|
|
1843
1823
|
}
|
|
1844
|
-
referenceFor(kind,
|
|
1824
|
+
referenceFor(kind, key) {
|
|
1825
|
+
const name = getRealFieldName(this, key);
|
|
1845
1826
|
let reference = this.references[name];
|
|
1846
1827
|
if (!reference) {
|
|
1847
1828
|
if (!this.graph) {
|
|
@@ -1850,7 +1831,7 @@ class LegacySupport {
|
|
|
1850
1831
|
// because of the intimate API access involved. This is something we will need to redesign.
|
|
1851
1832
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1852
1833
|
{
|
|
1853
|
-
throw new Error(`snapshot.belongsTo only supported
|
|
1834
|
+
throw new Error(`snapshot.belongsTo only supported when using the JSONAPICache`);
|
|
1854
1835
|
}
|
|
1855
1836
|
})() : {};
|
|
1856
1837
|
}
|
|
@@ -1865,16 +1846,16 @@ class LegacySupport {
|
|
|
1865
1846
|
const actualRelationshipKind = relationship.definition.kind;
|
|
1866
1847
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1867
1848
|
if (!test) {
|
|
1868
|
-
throw new Error(`You tried to get the '${name}' relationship on a '${modelName}' via record.${kind}('${
|
|
1849
|
+
throw new Error(`You tried to get the '${key === name ? name : `${key} (source: ${name})`}' relationship on a '${modelName}' via record.${kind}('${key}'), but the relationship is of kind '${actualRelationshipKind}'. Use record.${actualRelationshipKind}('${key}') instead.`);
|
|
1869
1850
|
}
|
|
1870
1851
|
})(actualRelationshipKind === kind) : {};
|
|
1871
1852
|
}
|
|
1872
1853
|
}
|
|
1873
1854
|
const relationshipKind = relationship.definition.kind;
|
|
1874
1855
|
if (relationshipKind === 'belongsTo') {
|
|
1875
|
-
reference = new BelongsToReference(this.store, graph, identifier, relationship,
|
|
1856
|
+
reference = new BelongsToReference(this.store, graph, identifier, relationship, key);
|
|
1876
1857
|
} else if (relationshipKind === 'hasMany') {
|
|
1877
|
-
reference = new HasManyReference(this.store, graph, identifier, relationship,
|
|
1858
|
+
reference = new HasManyReference(this.store, graph, identifier, relationship, key);
|
|
1878
1859
|
}
|
|
1879
1860
|
this.references[name] = reference;
|
|
1880
1861
|
}
|
|
@@ -1982,7 +1963,7 @@ class LegacySupport {
|
|
|
1982
1963
|
}
|
|
1983
1964
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1984
1965
|
{
|
|
1985
|
-
throw new Error(`hasMany only works with the
|
|
1966
|
+
throw new Error(`hasMany only works with the JSONAPICache`);
|
|
1986
1967
|
}
|
|
1987
1968
|
})() : {};
|
|
1988
1969
|
}
|
|
@@ -1991,12 +1972,13 @@ class LegacySupport {
|
|
|
1991
1972
|
return Promise.resolve(null);
|
|
1992
1973
|
}
|
|
1993
1974
|
const key = relationship.definition.key;
|
|
1975
|
+
const name = getRealFieldName(this, key);
|
|
1994
1976
|
|
|
1995
1977
|
// interleaved promises mean that we MUST cache this here
|
|
1996
1978
|
// in order to prevent infinite re-render if the request
|
|
1997
1979
|
// fails.
|
|
1998
|
-
if (this._pending[
|
|
1999
|
-
return this._pending[
|
|
1980
|
+
if (this._pending[name]) {
|
|
1981
|
+
return this._pending[name];
|
|
2000
1982
|
}
|
|
2001
1983
|
const identifier = resource.data ? resource.data : null;
|
|
2002
1984
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -2046,10 +2028,10 @@ class LegacySupport {
|
|
|
2046
2028
|
}
|
|
2047
2029
|
};
|
|
2048
2030
|
const future = this.store.request(req);
|
|
2049
|
-
this._pending[
|
|
2050
|
-
this._pending[
|
|
2031
|
+
this._pending[name] = future.then(doc => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
|
|
2032
|
+
this._pending[name] = undefined;
|
|
2051
2033
|
});
|
|
2052
|
-
return this._pending[
|
|
2034
|
+
return this._pending[name];
|
|
2053
2035
|
}
|
|
2054
2036
|
const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
|
|
2055
2037
|
const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
|
|
@@ -2076,7 +2058,7 @@ class LegacySupport {
|
|
|
2076
2058
|
}
|
|
2077
2059
|
})(identifier) : {};
|
|
2078
2060
|
options.reload = options.reload || !attemptLocalCache || undefined;
|
|
2079
|
-
this._pending[
|
|
2061
|
+
this._pending[name] = this.store.request({
|
|
2080
2062
|
op: 'findBelongsTo',
|
|
2081
2063
|
records: [identifier],
|
|
2082
2064
|
data: request,
|
|
@@ -2084,9 +2066,9 @@ class LegacySupport {
|
|
|
2084
2066
|
[Symbol.for('wd:skip-cache')]: true
|
|
2085
2067
|
}
|
|
2086
2068
|
}).then(doc => doc.content).finally(() => {
|
|
2087
|
-
this._pending[
|
|
2069
|
+
this._pending[name] = undefined;
|
|
2088
2070
|
});
|
|
2089
|
-
return this._pending[
|
|
2071
|
+
return this._pending[name];
|
|
2090
2072
|
}
|
|
2091
2073
|
|
|
2092
2074
|
// we were explicitly told we have no data and no links.
|
|
@@ -2213,6 +2195,17 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2213
2195
|
function isBelongsTo(relationship) {
|
|
2214
2196
|
return relationship.definition.kind === 'belongsTo';
|
|
2215
2197
|
}
|
|
2198
|
+
function getField(context, key) {
|
|
2199
|
+
const {
|
|
2200
|
+
identifier,
|
|
2201
|
+
store
|
|
2202
|
+
} = context;
|
|
2203
|
+
return store.schema.fields(identifier).get(key) ?? store.schema.cacheFields?.(identifier).get(key);
|
|
2204
|
+
}
|
|
2205
|
+
function getRealFieldName(context, key) {
|
|
2206
|
+
const field = getField(context, key);
|
|
2207
|
+
return field ? field.sourceKey ?? field.name : key;
|
|
2208
|
+
}
|
|
2216
2209
|
|
|
2217
2210
|
// we force the type here to our own construct because mixin and extend patterns
|
|
2218
2211
|
// lose generic signatures. We also do this because we need to Omit `clear` from
|