@warp-drive/legacy 5.8.0-alpha.3 → 5.8.0-alpha.30
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/json-api.d.ts +4 -6
- package/declarations/adapter/rest.d.ts +5 -8
- package/declarations/adapter.d.ts +4 -6
- package/declarations/compat/-private.d.ts +1 -1
- 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 +32 -8
- 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 +8 -8
- package/declarations/model/-private/record-state.d.ts +1 -1
- package/declarations/model/-private/references/belongs-to.d.ts +1 -1
- package/declarations/model/-private/references/has-many.d.ts +1 -1
- package/declarations/model/migration-support.d.ts +12 -3
- 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/serializer/-private/embedded-records-mixin.d.ts +0 -5
- 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 +4 -6
- package/declarations/serializer/json.d.ts +6 -8
- package/declarations/serializer/rest.d.ts +4 -6
- package/declarations/serializer.d.ts +8 -11
- package/dist/{-private-8UmnAf9J.js → -private-B1pSSN52.js} +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +5 -6
- package/dist/adapter/json-api.js +4 -1
- package/dist/adapter/rest.js +6 -9
- package/dist/adapter.js +4 -6
- package/dist/compat/-private.js +1 -1
- package/dist/compat/utils.js +17 -17
- package/dist/compat.js +55 -38
- package/dist/{errors-8kD2mSe_.js → errors-B9CDPh3R.js} +75 -53
- package/dist/hooks-CQXyievu.js +74 -0
- package/dist/index.js +195 -0
- package/dist/{json-DziiodPf.js → json-BHxlccxF.js} +8 -12
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +15 -2
- package/dist/model-for-B0TSd9HU.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +18 -90
- package/dist/{schema-provider-DQu4Rjco.js → schema-provider-BnVr_CnJ.js} +8 -10
- package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-BnYvPex3.js} +1 -1
- package/dist/serializer/json-api.js +11 -38
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +5 -12
- package/dist/serializer/transform.js +15 -6
- package/dist/serializer.js +8 -12
- package/dist/store.js +3 -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 +6 -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
package/dist/compat/utils.js
CHANGED
|
@@ -33,7 +33,7 @@ let NormalizedType = str => {
|
|
|
33
33
|
* changes during normalization. This is useful for instrumenting
|
|
34
34
|
* to discover places where usage in the app is not consistent.
|
|
35
35
|
*
|
|
36
|
-
* @param
|
|
36
|
+
* @param fn - a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
|
39
39
|
function configureMismatchReporter(fn) {
|
|
@@ -45,7 +45,7 @@ function configureMismatchReporter(fn) {
|
|
|
45
45
|
* fails validation. This is useful for instrumenting
|
|
46
46
|
* to discover places where usage in the app is not consistent.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
48
|
+
* @param fn - a function which takes a message and a condition
|
|
49
49
|
* @public
|
|
50
50
|
*/
|
|
51
51
|
function configureAssertFn(fn) {
|
|
@@ -62,7 +62,7 @@ function configureAssertFn(fn) {
|
|
|
62
62
|
* the configured mismatch reporter and assert functions will
|
|
63
63
|
* be called.
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
65
|
+
* @param fn - a function which takes a string and returns a string
|
|
66
66
|
* @public
|
|
67
67
|
*/
|
|
68
68
|
function configureTypeNormalization(fn) {
|
|
@@ -72,7 +72,7 @@ const NORMALIZED_TYPES = new Map();
|
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Converts a potentially unnormalized type into the format expected
|
|
75
|
-
* by our
|
|
75
|
+
* by our WarpDrive Cache. Currently this is singular-dasherized.
|
|
76
76
|
*
|
|
77
77
|
* you should not rely on this function to give you an exact format
|
|
78
78
|
* for display purposes. Formatting for display should be handled
|
|
@@ -95,8 +95,8 @@ const NORMALIZED_TYPES = new Map();
|
|
|
95
95
|
* formattedType('PostComment'); // => 'post-comment'
|
|
96
96
|
* ```
|
|
97
97
|
*
|
|
98
|
-
* @param
|
|
99
|
-
* @return
|
|
98
|
+
* @param type the potentially un-normalized type
|
|
99
|
+
* @return the normalized type
|
|
100
100
|
* @public
|
|
101
101
|
*/
|
|
102
102
|
function formattedType(type) {
|
|
@@ -116,7 +116,7 @@ function formattedType(type) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Format an id to the format expected by the
|
|
119
|
+
* Format an id to the format expected by the WarpDrive Cache.
|
|
120
120
|
* Currently this means that id should be `string | null`.
|
|
121
121
|
*
|
|
122
122
|
* Asserts invalid IDs (undefined, '', 0, '0') in dev.
|
|
@@ -131,8 +131,8 @@ function formattedType(type) {
|
|
|
131
131
|
* formattedId(null); // => null
|
|
132
132
|
* ```
|
|
133
133
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @return
|
|
134
|
+
* @param id the potentially un-normalized id
|
|
135
|
+
* @return the normalized id
|
|
136
136
|
* @public
|
|
137
137
|
*/
|
|
138
138
|
|
|
@@ -154,7 +154,7 @@ function expectId(id) {
|
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Compares two types for strict equality, converting them to
|
|
157
|
-
* the format expected by the
|
|
157
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
158
158
|
* differences in format are accounted for in the comparison.
|
|
159
159
|
*
|
|
160
160
|
* Asserts when expected or actual are invalid types in dev.
|
|
@@ -172,9 +172,9 @@ function expectId(id) {
|
|
|
172
172
|
* isEquivType('posts', null); // false
|
|
173
173
|
* ```
|
|
174
174
|
*
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @return
|
|
175
|
+
* @param expected a potentially unnormalized type to match against
|
|
176
|
+
* @param actual a potentially unnormalized type to match against
|
|
177
|
+
* @return true if the types are equivalent
|
|
178
178
|
* @public
|
|
179
179
|
*/
|
|
180
180
|
function isEquivType(expected, actual) {
|
|
@@ -191,7 +191,7 @@ function isEquivType(expected, actual) {
|
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
* Compares two IDs for strict equality, converting them to
|
|
194
|
-
* the format expected by the
|
|
194
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
195
195
|
* differences in format are accounted for in the comparison.
|
|
196
196
|
*
|
|
197
197
|
* Asserts when expected or actual are invalid IDs in dev.
|
|
@@ -205,9 +205,9 @@ function isEquivType(expected, actual) {
|
|
|
205
205
|
* isEquivId(1, null); // false
|
|
206
206
|
* ```
|
|
207
207
|
*
|
|
208
|
-
* @param
|
|
209
|
-
* @param
|
|
210
|
-
* @return
|
|
208
|
+
* @param expected a potentially un-normalized id to match against
|
|
209
|
+
* @param actual a potentially un-normalized id to match against
|
|
210
|
+
* @return true if the ids are equivalent
|
|
211
211
|
* @public
|
|
212
212
|
*/
|
|
213
213
|
function isEquivId(expected, actual) {
|
package/dist/compat.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getOwner } from '@ember/application';
|
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
3
|
import { assertPrivateStore, waitFor, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
4
4
|
import '@warp-drive/core/reactive/-private';
|
|
5
|
-
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-
|
|
5
|
+
import { p as payloadIsNotBlank, n as normalizeResponseHelper, i as iterateData, F as FetchManager, S as SaveOp, a as assertIdentifierHasId, b as SnapshotRecordArray } from "./-private-B1pSSN52.js";
|
|
6
6
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
7
7
|
function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
8
8
|
const promise = Promise.resolve().then(() => {
|
|
@@ -737,18 +737,30 @@ function queryRecord(context) {
|
|
|
737
737
|
}
|
|
738
738
|
|
|
739
739
|
/**
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
740
|
+
* Extends the signature of {@link Store} with additional
|
|
741
|
+
* methods available when using the legacy network layer.
|
|
742
|
+
*
|
|
743
|
+
* @public
|
|
744
|
+
* @noInheritDoc
|
|
745
|
+
* @legacy
|
|
746
|
+
*/
|
|
743
747
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
748
|
+
/**
|
|
749
|
+
* @deprecated - use {@link LegacyStoreCompat} instead
|
|
750
|
+
*/
|
|
747
751
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
+
/**
|
|
753
|
+
Returns an instance of the adapter for a given type. For
|
|
754
|
+
example, `adapterFor('person')` will return an instance of
|
|
755
|
+
the adapter located at `app/adapters/person.js`
|
|
756
|
+
|
|
757
|
+
If no `person` adapter is found, this method will look
|
|
758
|
+
for an `application` adapter (the default adapter for
|
|
759
|
+
your entire application).
|
|
760
|
+
|
|
761
|
+
@public
|
|
762
|
+
@param modelName
|
|
763
|
+
*/
|
|
752
764
|
|
|
753
765
|
function adapterFor(modelName, _allowMissing) {
|
|
754
766
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -799,20 +811,19 @@ function adapterFor(modelName, _allowMissing) {
|
|
|
799
811
|
}
|
|
800
812
|
|
|
801
813
|
/**
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
814
|
+
Returns an instance of the serializer for a given type. For
|
|
815
|
+
example, `serializerFor('person')` will return an instance of
|
|
816
|
+
`App.PersonSerializer`.
|
|
805
817
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
818
|
+
If no `App.PersonSerializer` is found, this method will look
|
|
819
|
+
for an `App.ApplicationSerializer` (the default serializer for
|
|
820
|
+
your entire application).
|
|
809
821
|
|
|
810
|
-
|
|
811
|
-
|
|
822
|
+
If a serializer cannot be found on the adapter, it will fall back
|
|
823
|
+
to an instance of `JSONSerializer`.
|
|
812
824
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
@return {Serializer}
|
|
825
|
+
@public
|
|
826
|
+
@param modelName the record to serialize
|
|
816
827
|
*/
|
|
817
828
|
function serializerFor(modelName) {
|
|
818
829
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -859,23 +870,29 @@ function serializerFor(modelName) {
|
|
|
859
870
|
}
|
|
860
871
|
|
|
861
872
|
/**
|
|
862
|
-
|
|
863
|
-
|
|
873
|
+
`normalize` converts a json payload into the normalized form expected by
|
|
874
|
+
{@link Store.push | push} using the serializer specified by `modelName`
|
|
864
875
|
|
|
865
|
-
|
|
876
|
+
:::warning
|
|
877
|
+
Generally it would be better to invoke the serializer yourself directly,
|
|
878
|
+
or write a more specialized normalization utility.
|
|
879
|
+
:::
|
|
866
880
|
|
|
867
|
-
|
|
868
|
-
socket.on('message', function(message) {
|
|
869
|
-
let modelName = message.model;
|
|
870
|
-
let data = message.data;
|
|
871
|
-
store.push(store.normalize(modelName, data));
|
|
872
|
-
});
|
|
873
|
-
```
|
|
881
|
+
Example
|
|
874
882
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
883
|
+
```js
|
|
884
|
+
socket.on('message', function(message) {
|
|
885
|
+
let modelName = message.model;
|
|
886
|
+
let data = message.data;
|
|
887
|
+
store.push(store.normalize(modelName, data));
|
|
888
|
+
});
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
@legacy
|
|
892
|
+
@public
|
|
893
|
+
@param modelName The name of the model type for this payload
|
|
894
|
+
@return The normalized payload
|
|
895
|
+
*/
|
|
879
896
|
// TODO @runspired @deprecate users should call normalize on the associated serializer directly
|
|
880
897
|
function normalize(modelName, payload) {
|
|
881
898
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -956,8 +973,8 @@ function normalize(modelName, payload) {
|
|
|
956
973
|
```
|
|
957
974
|
|
|
958
975
|
@public
|
|
959
|
-
@param
|
|
960
|
-
@param
|
|
976
|
+
@param modelName Optionally, a model type used to determine which serializer will be used
|
|
977
|
+
@param inputPayload
|
|
961
978
|
*/
|
|
962
979
|
// TODO @runspired @deprecate pushPayload in favor of looking up the serializer
|
|
963
980
|
function pushPayload(modelName, inputPayload) {
|
|
@@ -2,7 +2,7 @@ import { Context } from '@warp-drive/core/reactive/-private';
|
|
|
2
2
|
import { memoized, defineSignal, assertPrivateStore, defineNonEnumerableSignal, isResourceKey, recordIdentifierFor, isPrivateStore, storeFor, fastPush, createLegacyManyArray, notifyInternalSignal } from '@warp-drive/core/store/-private';
|
|
3
3
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
4
4
|
import { EnableHydration } from '@warp-drive/core/types/request';
|
|
5
|
-
import { u as upgradeStore } from "./-private-
|
|
5
|
+
import { u as upgradeStore } from "./-private-B1pSSN52.js";
|
|
6
6
|
import { computed, get } from '@ember/object';
|
|
7
7
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
8
8
|
import ObjectProxy from '@ember/object/proxy';
|
|
@@ -632,7 +632,7 @@ class HasManyReference {
|
|
|
632
632
|
}
|
|
633
633
|
|
|
634
634
|
/**
|
|
635
|
-
`push` can be used to update the data in the relationship and
|
|
635
|
+
`push` can be used to update the data in the relationship and WarpDrive
|
|
636
636
|
will treat the new data as the canonical value of this relationship on
|
|
637
637
|
the backend. An empty array will signify the canonical value should be
|
|
638
638
|
empty.
|
|
@@ -1231,7 +1231,7 @@ class BelongsToReference {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
|
|
1233
1233
|
/**
|
|
1234
|
-
`push` can be used to update the data in the relationship and
|
|
1234
|
+
`push` can be used to update the data in the relationship and WarpDrive
|
|
1235
1235
|
will treat the new data as the canonical value of this relationship on
|
|
1236
1236
|
the backend. A value of `null` (e.g. `{ data: null }`) can be passed to
|
|
1237
1237
|
clear the relationship.
|
|
@@ -1581,28 +1581,31 @@ class LegacySupport {
|
|
|
1581
1581
|
this.cache.mutate(mutation);
|
|
1582
1582
|
}
|
|
1583
1583
|
_findBelongsTo(key, resource, relationship, options) {
|
|
1584
|
+
const name = getRealFieldName(this, key);
|
|
1585
|
+
|
|
1584
1586
|
// TODO @runspired follow up if parent isNew then we should not be attempting load here
|
|
1585
1587
|
// 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,
|
|
1588
|
+
return this._findBelongsToByJsonApiResource(resource, this.identifier, relationship, options).then(identifier => handleCompletedRelationshipRequest(this, name, relationship, identifier), e => handleCompletedRelationshipRequest(this, name, relationship, null, e));
|
|
1587
1589
|
}
|
|
1588
1590
|
reloadBelongsTo(key, options) {
|
|
1589
1591
|
const loadingPromise = this._relationshipPromisesCache[key];
|
|
1590
1592
|
if (loadingPromise) {
|
|
1591
1593
|
return loadingPromise;
|
|
1592
1594
|
}
|
|
1593
|
-
const
|
|
1595
|
+
const name = getRealFieldName(this, key);
|
|
1596
|
+
const resource = this.store.cache.getRelationship(this.identifier, name);
|
|
1597
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1594
1598
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1595
1599
|
if (!test) {
|
|
1596
|
-
throw new Error(`Expected ${key} to be a belongs-to relationship`);
|
|
1600
|
+
throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
|
|
1597
1601
|
}
|
|
1598
1602
|
})(isBelongsTo(relationship)) : {};
|
|
1599
|
-
const resource = this.cache.getRelationship(this.identifier, key);
|
|
1600
1603
|
relationship.state.hasFailedLoadAttempt = false;
|
|
1601
1604
|
relationship.state.shouldForceReload = true;
|
|
1602
|
-
const promise = this._findBelongsTo(
|
|
1603
|
-
if (this._relationshipProxyCache[
|
|
1605
|
+
const promise = this._findBelongsTo(name, resource, relationship, options);
|
|
1606
|
+
if (this._relationshipProxyCache[name]) {
|
|
1604
1607
|
// @ts-expect-error
|
|
1605
|
-
return this._updatePromiseProxyFor('belongsTo',
|
|
1608
|
+
return this._updatePromiseProxyFor('belongsTo', name, {
|
|
1606
1609
|
promise
|
|
1607
1610
|
});
|
|
1608
1611
|
}
|
|
@@ -1610,10 +1613,10 @@ class LegacySupport {
|
|
|
1610
1613
|
}
|
|
1611
1614
|
getBelongsTo(key, options) {
|
|
1612
1615
|
const {
|
|
1613
|
-
identifier
|
|
1614
|
-
cache
|
|
1616
|
+
identifier
|
|
1615
1617
|
} = this;
|
|
1616
|
-
const
|
|
1618
|
+
const name = getRealFieldName(this, key);
|
|
1619
|
+
const resource = this.store.cache.getRelationship(this.identifier, name);
|
|
1617
1620
|
const relatedIdentifier = resource && resource.data ? resource.data : null;
|
|
1618
1621
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1619
1622
|
if (!test) {
|
|
@@ -1621,10 +1624,10 @@ class LegacySupport {
|
|
|
1621
1624
|
}
|
|
1622
1625
|
})(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
|
|
1623
1626
|
const store = this.store;
|
|
1624
|
-
const relationship = this.graph.get(this.identifier,
|
|
1627
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1625
1628
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1626
1629
|
if (!test) {
|
|
1627
|
-
throw new Error(`Expected ${key} to be a belongs-to relationship`);
|
|
1630
|
+
throw new Error(`Expected ${key === name ? name : `${key} (source: ${name})`} to be a belongs-to relationship`);
|
|
1628
1631
|
}
|
|
1629
1632
|
})(isBelongsTo(relationship)) : {};
|
|
1630
1633
|
const isAsync = relationship.definition.isAsync;
|
|
@@ -1636,11 +1639,11 @@ class LegacySupport {
|
|
|
1636
1639
|
};
|
|
1637
1640
|
if (isAsync) {
|
|
1638
1641
|
if (relationship.state.hasFailedLoadAttempt) {
|
|
1639
|
-
return this._relationshipProxyCache[
|
|
1642
|
+
return this._relationshipProxyCache[name];
|
|
1640
1643
|
}
|
|
1641
|
-
const promise = this._findBelongsTo(
|
|
1644
|
+
const promise = this._findBelongsTo(name, resource, relationship, options);
|
|
1642
1645
|
const isLoaded = relatedIdentifier && store._instanceCache.recordIsLoaded(relatedIdentifier);
|
|
1643
|
-
return this._updatePromiseProxyFor('belongsTo',
|
|
1646
|
+
return this._updatePromiseProxyFor('belongsTo', name, {
|
|
1644
1647
|
promise,
|
|
1645
1648
|
content: isLoaded ? store._instanceCache.getRecord(relatedIdentifier) : null,
|
|
1646
1649
|
_belongsToState
|
|
@@ -1651,7 +1654,7 @@ class LegacySupport {
|
|
|
1651
1654
|
} else {
|
|
1652
1655
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1653
1656
|
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> })\`)`);
|
|
1657
|
+
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
1658
|
}
|
|
1656
1659
|
})(store._instanceCache.recordIsLoaded(relatedIdentifier, true)) : {};
|
|
1657
1660
|
return store._instanceCache.getRecord(relatedIdentifier);
|
|
@@ -1659,10 +1662,11 @@ class LegacySupport {
|
|
|
1659
1662
|
}
|
|
1660
1663
|
}
|
|
1661
1664
|
setDirtyBelongsTo(key, value) {
|
|
1665
|
+
const name = getRealFieldName(this, key);
|
|
1662
1666
|
return this.cache.mutate({
|
|
1663
1667
|
op: 'replaceRelatedRecord',
|
|
1664
1668
|
record: this.identifier,
|
|
1665
|
-
field:
|
|
1669
|
+
field: name,
|
|
1666
1670
|
value: extractIdentifierFromRecord(value)
|
|
1667
1671
|
},
|
|
1668
1672
|
// @ts-expect-error
|
|
@@ -1688,13 +1692,15 @@ class LegacySupport {
|
|
|
1688
1692
|
return [identifiers, jsonApi];
|
|
1689
1693
|
}
|
|
1690
1694
|
getManyArray(key, definition) {
|
|
1695
|
+
const name = getRealFieldName(this, key);
|
|
1691
1696
|
if (this.graph) {
|
|
1692
|
-
let manyArray = this._manyArrayCache[
|
|
1697
|
+
let manyArray = this._manyArrayCache[name];
|
|
1693
1698
|
if (!definition) {
|
|
1694
|
-
definition = this.graph.get(this.identifier,
|
|
1699
|
+
definition = this.graph.get(this.identifier, name).definition;
|
|
1695
1700
|
}
|
|
1696
1701
|
if (!manyArray) {
|
|
1697
|
-
const [identifiers, doc] = this._getCurrentState(this.identifier,
|
|
1702
|
+
const [identifiers, doc] = this._getCurrentState(this.identifier, name);
|
|
1703
|
+
const field = getField(this, name);
|
|
1698
1704
|
manyArray = createLegacyManyArray({
|
|
1699
1705
|
store: this.store,
|
|
1700
1706
|
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
@@ -1705,12 +1711,12 @@ class LegacySupport {
|
|
|
1705
1711
|
editable: true,
|
|
1706
1712
|
isAsync: definition.isAsync,
|
|
1707
1713
|
isPolymorphic: definition.isPolymorphic,
|
|
1708
|
-
field:
|
|
1714
|
+
field: field,
|
|
1709
1715
|
identifier: this.identifier,
|
|
1710
1716
|
links: doc.links || null,
|
|
1711
1717
|
meta: doc.meta || null
|
|
1712
1718
|
});
|
|
1713
|
-
this._manyArrayCache[
|
|
1719
|
+
this._manyArrayCache[name] = manyArray;
|
|
1714
1720
|
}
|
|
1715
1721
|
return manyArray;
|
|
1716
1722
|
}
|
|
@@ -1721,19 +1727,20 @@ class LegacySupport {
|
|
|
1721
1727
|
})() : {};
|
|
1722
1728
|
}
|
|
1723
1729
|
fetchAsyncHasMany(key, relationship, manyArray, options) {
|
|
1730
|
+
const name = getRealFieldName(this, key);
|
|
1724
1731
|
if (this.graph) {
|
|
1725
|
-
let loadingPromise = this._relationshipPromisesCache[
|
|
1732
|
+
let loadingPromise = this._relationshipPromisesCache[name];
|
|
1726
1733
|
if (loadingPromise) {
|
|
1727
1734
|
return loadingPromise;
|
|
1728
1735
|
}
|
|
1729
|
-
const jsonApi = this.cache.getRelationship(this.identifier,
|
|
1736
|
+
const jsonApi = this.cache.getRelationship(this.identifier, name);
|
|
1730
1737
|
const promise = this._findHasManyByJsonApiResource(jsonApi, this.identifier, relationship, options);
|
|
1731
1738
|
if (!promise) {
|
|
1732
1739
|
manyArray.isLoaded = true;
|
|
1733
1740
|
return Promise.resolve(manyArray);
|
|
1734
1741
|
}
|
|
1735
|
-
loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this,
|
|
1736
|
-
this._relationshipPromisesCache[
|
|
1742
|
+
loadingPromise = promise.then(() => handleCompletedRelationshipRequest(this, name, relationship, manyArray), e => handleCompletedRelationshipRequest(this, name, relationship, manyArray, e));
|
|
1743
|
+
this._relationshipPromisesCache[name] = loadingPromise;
|
|
1737
1744
|
return loadingPromise;
|
|
1738
1745
|
}
|
|
1739
1746
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -1743,22 +1750,23 @@ class LegacySupport {
|
|
|
1743
1750
|
})() : {};
|
|
1744
1751
|
}
|
|
1745
1752
|
reloadHasMany(key, options) {
|
|
1753
|
+
const name = getRealFieldName(this, key);
|
|
1746
1754
|
if (this.graph) {
|
|
1747
|
-
const loadingPromise = this._relationshipPromisesCache[
|
|
1755
|
+
const loadingPromise = this._relationshipPromisesCache[name];
|
|
1748
1756
|
if (loadingPromise) {
|
|
1749
1757
|
return loadingPromise;
|
|
1750
1758
|
}
|
|
1751
|
-
const relationship = this.graph.get(this.identifier,
|
|
1759
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1752
1760
|
const {
|
|
1753
1761
|
definition,
|
|
1754
1762
|
state
|
|
1755
1763
|
} = relationship;
|
|
1756
1764
|
state.hasFailedLoadAttempt = false;
|
|
1757
1765
|
state.shouldForceReload = true;
|
|
1758
|
-
const manyArray = this.getManyArray(
|
|
1759
|
-
const promise = this.fetchAsyncHasMany(
|
|
1760
|
-
if (this._relationshipProxyCache[
|
|
1761
|
-
return this._updatePromiseProxyFor('hasMany',
|
|
1766
|
+
const manyArray = this.getManyArray(name, definition);
|
|
1767
|
+
const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
|
|
1768
|
+
if (this._relationshipProxyCache[name]) {
|
|
1769
|
+
return this._updatePromiseProxyFor('hasMany', name, {
|
|
1762
1770
|
promise
|
|
1763
1771
|
});
|
|
1764
1772
|
}
|
|
@@ -1771,26 +1779,27 @@ class LegacySupport {
|
|
|
1771
1779
|
})() : {};
|
|
1772
1780
|
}
|
|
1773
1781
|
getHasMany(key, options) {
|
|
1782
|
+
const name = getRealFieldName(this, key);
|
|
1774
1783
|
if (this.graph) {
|
|
1775
|
-
const relationship = this.graph.get(this.identifier,
|
|
1784
|
+
const relationship = this.graph.get(this.identifier, name);
|
|
1776
1785
|
const {
|
|
1777
1786
|
definition,
|
|
1778
1787
|
state
|
|
1779
1788
|
} = relationship;
|
|
1780
|
-
const manyArray = this.getManyArray(
|
|
1789
|
+
const manyArray = this.getManyArray(name, definition);
|
|
1781
1790
|
if (definition.isAsync) {
|
|
1782
1791
|
if (state.hasFailedLoadAttempt) {
|
|
1783
|
-
return this._relationshipProxyCache[
|
|
1792
|
+
return this._relationshipProxyCache[name];
|
|
1784
1793
|
}
|
|
1785
|
-
const promise = this.fetchAsyncHasMany(
|
|
1786
|
-
return this._updatePromiseProxyFor('hasMany',
|
|
1794
|
+
const promise = this.fetchAsyncHasMany(name, relationship, manyArray, options);
|
|
1795
|
+
return this._updatePromiseProxyFor('hasMany', name, {
|
|
1787
1796
|
promise,
|
|
1788
1797
|
content: manyArray
|
|
1789
1798
|
});
|
|
1790
1799
|
} else {
|
|
1791
1800
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1792
1801
|
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> })')`);
|
|
1802
|
+
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
1803
|
}
|
|
1795
1804
|
})(!anyUnloaded(this.store, relationship)) : {};
|
|
1796
1805
|
return manyArray;
|
|
@@ -1841,7 +1850,8 @@ class LegacySupport {
|
|
|
1841
1850
|
}
|
|
1842
1851
|
return promiseProxy;
|
|
1843
1852
|
}
|
|
1844
|
-
referenceFor(kind,
|
|
1853
|
+
referenceFor(kind, key) {
|
|
1854
|
+
const name = getRealFieldName(this, key);
|
|
1845
1855
|
let reference = this.references[name];
|
|
1846
1856
|
if (!reference) {
|
|
1847
1857
|
if (!this.graph) {
|
|
@@ -1865,16 +1875,16 @@ class LegacySupport {
|
|
|
1865
1875
|
const actualRelationshipKind = relationship.definition.kind;
|
|
1866
1876
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1867
1877
|
if (!test) {
|
|
1868
|
-
throw new Error(`You tried to get the '${name}' relationship on a '${modelName}' via record.${kind}('${
|
|
1878
|
+
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
1879
|
}
|
|
1870
1880
|
})(actualRelationshipKind === kind) : {};
|
|
1871
1881
|
}
|
|
1872
1882
|
}
|
|
1873
1883
|
const relationshipKind = relationship.definition.kind;
|
|
1874
1884
|
if (relationshipKind === 'belongsTo') {
|
|
1875
|
-
reference = new BelongsToReference(this.store, graph, identifier, relationship,
|
|
1885
|
+
reference = new BelongsToReference(this.store, graph, identifier, relationship, key);
|
|
1876
1886
|
} else if (relationshipKind === 'hasMany') {
|
|
1877
|
-
reference = new HasManyReference(this.store, graph, identifier, relationship,
|
|
1887
|
+
reference = new HasManyReference(this.store, graph, identifier, relationship, key);
|
|
1878
1888
|
}
|
|
1879
1889
|
this.references[name] = reference;
|
|
1880
1890
|
}
|
|
@@ -1991,12 +2001,13 @@ class LegacySupport {
|
|
|
1991
2001
|
return Promise.resolve(null);
|
|
1992
2002
|
}
|
|
1993
2003
|
const key = relationship.definition.key;
|
|
2004
|
+
const name = getRealFieldName(this, key);
|
|
1994
2005
|
|
|
1995
2006
|
// interleaved promises mean that we MUST cache this here
|
|
1996
2007
|
// in order to prevent infinite re-render if the request
|
|
1997
2008
|
// fails.
|
|
1998
|
-
if (this._pending[
|
|
1999
|
-
return this._pending[
|
|
2009
|
+
if (this._pending[name]) {
|
|
2010
|
+
return this._pending[name];
|
|
2000
2011
|
}
|
|
2001
2012
|
const identifier = resource.data ? resource.data : null;
|
|
2002
2013
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -2046,10 +2057,10 @@ class LegacySupport {
|
|
|
2046
2057
|
}
|
|
2047
2058
|
};
|
|
2048
2059
|
const future = this.store.request(req);
|
|
2049
|
-
this._pending[
|
|
2050
|
-
this._pending[
|
|
2060
|
+
this._pending[name] = future.then(doc => field.options.linksMode ? doc.content.data : doc.content).finally(() => {
|
|
2061
|
+
this._pending[name] = undefined;
|
|
2051
2062
|
});
|
|
2052
|
-
return this._pending[
|
|
2063
|
+
return this._pending[name];
|
|
2053
2064
|
}
|
|
2054
2065
|
const preferLocalCache = hasReceivedData && allInverseRecordsAreLoaded && !isEmpty;
|
|
2055
2066
|
const hasLocalPartialData = hasDematerializedInverse || isEmpty && resource.data;
|
|
@@ -2076,7 +2087,7 @@ class LegacySupport {
|
|
|
2076
2087
|
}
|
|
2077
2088
|
})(identifier) : {};
|
|
2078
2089
|
options.reload = options.reload || !attemptLocalCache || undefined;
|
|
2079
|
-
this._pending[
|
|
2090
|
+
this._pending[name] = this.store.request({
|
|
2080
2091
|
op: 'findBelongsTo',
|
|
2081
2092
|
records: [identifier],
|
|
2082
2093
|
data: request,
|
|
@@ -2084,9 +2095,9 @@ class LegacySupport {
|
|
|
2084
2095
|
[Symbol.for('wd:skip-cache')]: true
|
|
2085
2096
|
}
|
|
2086
2097
|
}).then(doc => doc.content).finally(() => {
|
|
2087
|
-
this._pending[
|
|
2098
|
+
this._pending[name] = undefined;
|
|
2088
2099
|
});
|
|
2089
|
-
return this._pending[
|
|
2100
|
+
return this._pending[name];
|
|
2090
2101
|
}
|
|
2091
2102
|
|
|
2092
2103
|
// we were explicitly told we have no data and no links.
|
|
@@ -2213,6 +2224,17 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2213
2224
|
function isBelongsTo(relationship) {
|
|
2214
2225
|
return relationship.definition.kind === 'belongsTo';
|
|
2215
2226
|
}
|
|
2227
|
+
function getField(context, key) {
|
|
2228
|
+
const {
|
|
2229
|
+
identifier,
|
|
2230
|
+
store
|
|
2231
|
+
} = context;
|
|
2232
|
+
return store.schema.fields(identifier).get(key) ?? store.schema.cacheFields?.(identifier).get(key);
|
|
2233
|
+
}
|
|
2234
|
+
function getRealFieldName(context, key) {
|
|
2235
|
+
const field = getField(context, key);
|
|
2236
|
+
return field ? field.sourceKey ?? field.name : key;
|
|
2237
|
+
}
|
|
2216
2238
|
|
|
2217
2239
|
// we force the type here to our own construct because mixin and extend patterns
|
|
2218
2240
|
// lose generic signatures. We also do this because we need to Omit `clear` from
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { setOwner, getOwner } from '@ember/application';
|
|
2
|
+
import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
|
|
3
|
+
import { g as getModelFactory } from "./schema-provider-BnVr_CnJ.js";
|
|
4
|
+
import { n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
5
|
+
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
6
|
+
function instantiateRecord(identifier, createRecordArgs) {
|
|
7
|
+
const type = identifier.type;
|
|
8
|
+
|
|
9
|
+
// TODO deprecate allowing unknown args setting
|
|
10
|
+
const createOptions = {
|
|
11
|
+
_createProps: createRecordArgs ?? {},
|
|
12
|
+
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
|
|
13
|
+
_secretInit: {
|
|
14
|
+
identifier,
|
|
15
|
+
store: this,
|
|
16
|
+
cb: secretInit
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// ensure that `getOwner(this)` works inside a model instance
|
|
21
|
+
setOwner(createOptions, getOwner(this));
|
|
22
|
+
const factory = getModelFactory(this, type);
|
|
23
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
24
|
+
if (!test) {
|
|
25
|
+
throw new Error(`No model was found for '${type}'`);
|
|
26
|
+
}
|
|
27
|
+
})(factory) : {};
|
|
28
|
+
return factory.class.create(createOptions);
|
|
29
|
+
}
|
|
30
|
+
function teardownRecord(record) {
|
|
31
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
32
|
+
if (!test) {
|
|
33
|
+
throw new Error(`expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`);
|
|
34
|
+
}
|
|
35
|
+
})('destroy' in record) : {};
|
|
36
|
+
record.destroy();
|
|
37
|
+
}
|
|
38
|
+
function modelFor(modelName) {
|
|
39
|
+
assertPrivateStore(this);
|
|
40
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
41
|
+
if (!test) {
|
|
42
|
+
throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
|
|
43
|
+
}
|
|
44
|
+
})(!this.isDestroyed && !this.isDestroying) : {};
|
|
45
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
46
|
+
if (!test) {
|
|
47
|
+
throw new Error(`You need to pass a model name to the store's modelFor method`);
|
|
48
|
+
}
|
|
49
|
+
})(modelName) : {};
|
|
50
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
51
|
+
if (!test) {
|
|
52
|
+
throw new Error(`Please pass a proper model name to the store's modelFor method`);
|
|
53
|
+
}
|
|
54
|
+
})(typeof modelName === 'string' && modelName.length) : {};
|
|
55
|
+
const type = normalizeModelName(modelName);
|
|
56
|
+
const maybeFactory = getModelFactory(this, type);
|
|
57
|
+
const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;
|
|
58
|
+
const ignoreType = !klass || !klass.isModel || this._forceShim;
|
|
59
|
+
if (!ignoreType) {
|
|
60
|
+
return klass;
|
|
61
|
+
}
|
|
62
|
+
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
63
|
+
if (!test) {
|
|
64
|
+
throw new Error(`No model was found for '${type}' and no schema handles the type`);
|
|
65
|
+
}
|
|
66
|
+
})(this.schema.hasResource({
|
|
67
|
+
type
|
|
68
|
+
})) : {};
|
|
69
|
+
}
|
|
70
|
+
function secretInit(record, identifier, store) {
|
|
71
|
+
setRecordIdentifier(record, identifier);
|
|
72
|
+
StoreMap.set(record, store);
|
|
73
|
+
}
|
|
74
|
+
export { instantiateRecord as i, modelFor as m, teardownRecord as t };
|