@warp-drive/legacy 5.6.0-beta.1 → 5.6.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/adapter/-private/build-url-mixin.d.ts +0 -13
- package/declarations/adapter/-private/utils/continue-on-reject.d.ts +1 -7
- package/declarations/adapter/-private/utils/serialize-query-params.d.ts +0 -4
- package/declarations/adapter/error.d.ts +2 -3
- package/declarations/adapter/rest.d.ts +0 -2
- package/declarations/adapter.d.ts +0 -5
- package/declarations/compat/builders/find-all.d.ts +2 -2
- package/declarations/compat/builders/query.d.ts +2 -2
- package/declarations/compat/builders/save-record.d.ts +3 -3
- package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +24 -17
- package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +2 -2
- package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +5 -5
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +3 -8
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +40 -18
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +63 -44
- package/declarations/compat.d.ts +3 -6
- package/declarations/model/-private/attr.d.ts +1 -14
- package/declarations/model/-private/belongs-to.d.ts +0 -11
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -14
- package/declarations/model/-private/errors.d.ts +0 -6
- package/declarations/model/-private/has-many.d.ts +0 -4
- package/declarations/model/-private/hooks.d.ts +2 -2
- package/declarations/model/-private/legacy-relationships-support.d.ts +18 -27
- package/declarations/model/-private/model-for-mixin.d.ts +0 -16
- package/declarations/model/-private/model-methods.d.ts +3 -4
- package/declarations/model/-private/model.d.ts +14 -67
- package/declarations/model/-private/notify-changes.d.ts +2 -2
- package/declarations/model/-private/promise-belongs-to.d.ts +0 -6
- package/declarations/model/-private/promise-many-array.d.ts +0 -11
- package/declarations/model/-private/record-state.d.ts +2 -25
- package/declarations/model/-private/references/belongs-to.d.ts +6 -7
- package/declarations/model/-private/references/has-many.d.ts +6 -13
- package/declarations/model/-private/schema-provider.d.ts +6 -10
- package/declarations/model/-private.d.ts +2 -2
- package/declarations/model/migration-support.d.ts +11 -53
- package/declarations/model.d.ts +1 -1
- package/declarations/serializer/json-api.d.ts +0 -1
- package/declarations/serializer/json.d.ts +0 -1
- package/declarations/serializer/rest.d.ts +0 -1
- package/declarations/store/-private.d.ts +223 -0
- package/declarations/store.d.ts +3 -0
- package/dist/{-private-CKrP0ogQ.js → -private-8UmnAf9J.js} +169 -141
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +66 -0
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +2 -2
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +4 -23
- package/dist/compat.js +7 -2
- package/dist/{errors-BX5wowuz.js → errors-8kD2mSe_.js} +66 -36
- package/dist/model/-private.js +1 -2
- package/dist/model/migration-support.js +96 -11
- package/dist/model.js +14 -11
- package/dist/{schema-provider-BdQhkT-Q.js → schema-provider-DQu4Rjco.js} +165 -60
- package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-CS0MIv4F.js} +2 -1
- package/dist/store.js +633 -0
- package/dist/util-Dul6TZts.js +35 -0
- package/dist/utils-Cqw9eRj5.js +23 -0
- package/package.json +15 -15
package/dist/compat.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getOwner } from '@ember/application';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
|
-
import { waitFor, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
4
|
-
import
|
|
3
|
+
import { assertPrivateStore, waitFor, _deprecatingNormalize } from '@warp-drive/core/store/-private';
|
|
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-8UmnAf9J.js";
|
|
5
6
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
6
7
|
function _findHasMany(adapter, store, identifier, link, relationship, options) {
|
|
7
8
|
const promise = Promise.resolve().then(() => {
|
|
@@ -424,6 +425,7 @@ function saveRecord(context) {
|
|
|
424
425
|
options,
|
|
425
426
|
record: identifier
|
|
426
427
|
} = data;
|
|
428
|
+
assertPrivateStore(store);
|
|
427
429
|
store.cache.willCommit(identifier, context);
|
|
428
430
|
const saveOptions = Object.assign({
|
|
429
431
|
[SaveOp]: operation
|
|
@@ -529,6 +531,7 @@ function findRecord(context) {
|
|
|
529
531
|
record: identifier,
|
|
530
532
|
options
|
|
531
533
|
} = data;
|
|
534
|
+
assertPrivateStore(store);
|
|
532
535
|
let promise;
|
|
533
536
|
|
|
534
537
|
// if not loaded start loading
|
|
@@ -583,6 +586,7 @@ function findAll(context) {
|
|
|
583
586
|
type,
|
|
584
587
|
options
|
|
585
588
|
} = data;
|
|
589
|
+
assertPrivateStore(store);
|
|
586
590
|
const adapter = store.adapterFor(type);
|
|
587
591
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
588
592
|
if (!test) {
|
|
@@ -647,6 +651,7 @@ function query(context) {
|
|
|
647
651
|
store,
|
|
648
652
|
data
|
|
649
653
|
} = context.request;
|
|
654
|
+
assertPrivateStore(store);
|
|
650
655
|
let {
|
|
651
656
|
options
|
|
652
657
|
} = data;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '@warp-drive/core/reactive/-private';
|
|
2
|
+
import { memoized, defineSignal, assertPrivateStore, defineNonEnumerableSignal, isResourceKey, recordIdentifierFor, isPrivateStore, storeFor, fastPush, createLegacyManyArray, notifyInternalSignal } from '@warp-drive/core/store/-private';
|
|
2
3
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
3
4
|
import { EnableHydration } from '@warp-drive/core/types/request';
|
|
4
|
-
import { u as upgradeStore } from "./-private-
|
|
5
|
+
import { u as upgradeStore } from "./-private-8UmnAf9J.js";
|
|
5
6
|
import { computed, get } from '@ember/object';
|
|
6
7
|
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
7
8
|
import ObjectProxy from '@ember/object/proxy';
|
|
@@ -420,7 +421,7 @@ class HasManyReference {
|
|
|
420
421
|
* An array of identifiers for the records that this reference refers to.
|
|
421
422
|
*
|
|
422
423
|
* @property identifiers
|
|
423
|
-
* @type {
|
|
424
|
+
* @type {ResourceKey[]}
|
|
424
425
|
* @public
|
|
425
426
|
*/
|
|
426
427
|
get identifiers() {
|
|
@@ -432,7 +433,7 @@ class HasManyReference {
|
|
|
432
433
|
this.___relatedTokenMap = new Map();
|
|
433
434
|
if (resource && resource.data) {
|
|
434
435
|
return resource.data.map(resourceIdentifier => {
|
|
435
|
-
const identifier = this.store.
|
|
436
|
+
const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);
|
|
436
437
|
let token = map.get(identifier);
|
|
437
438
|
if (token) {
|
|
438
439
|
map.delete(identifier);
|
|
@@ -724,7 +725,7 @@ class HasManyReference {
|
|
|
724
725
|
throw new Error(`You must provide at least one of 'links', 'meta' or 'data' when calling hasManyReference.push`);
|
|
725
726
|
}
|
|
726
727
|
})('links' in dataDoc || 'meta' in dataDoc || 'data' in dataDoc) : {};
|
|
727
|
-
const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map(i => store.
|
|
728
|
+
const identifiers = !Array.isArray(dataDoc.data) ? [] : isResourceData ? store._push(dataDoc, true) : dataDoc.data.map(i => store.cacheKeyManager.getOrCreateRecordIdentifier(i));
|
|
728
729
|
const {
|
|
729
730
|
identifier
|
|
730
731
|
} = this.hasManyRelationship;
|
|
@@ -745,6 +746,7 @@ class HasManyReference {
|
|
|
745
746
|
if ('meta' in dataDoc) {
|
|
746
747
|
newData.meta = dataDoc.meta;
|
|
747
748
|
}
|
|
749
|
+
assertPrivateStore(store);
|
|
748
750
|
store._join(() => {
|
|
749
751
|
this.graph.push({
|
|
750
752
|
op: 'updateRelationship',
|
|
@@ -762,6 +764,7 @@ class HasManyReference {
|
|
|
762
764
|
}
|
|
763
765
|
const relationship = this.graph.getData(this.hasManyRelationship.identifier, this.key);
|
|
764
766
|
return relationship.data ? relationship.data.every(identifier => {
|
|
767
|
+
assertPrivateStore(this.store);
|
|
765
768
|
return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
|
|
766
769
|
}) : false;
|
|
767
770
|
}
|
|
@@ -1022,7 +1025,7 @@ class BelongsToReference {
|
|
|
1022
1025
|
* `null` if no related record is known.
|
|
1023
1026
|
*
|
|
1024
1027
|
* @property identifier
|
|
1025
|
-
* @type {
|
|
1028
|
+
* @type {ResourceKey | null}
|
|
1026
1029
|
* @public
|
|
1027
1030
|
*/
|
|
1028
1031
|
get identifier() {
|
|
@@ -1032,7 +1035,7 @@ class BelongsToReference {
|
|
|
1032
1035
|
}
|
|
1033
1036
|
const resource = this._resource();
|
|
1034
1037
|
if (resource && resource.data) {
|
|
1035
|
-
const identifier = this.store.
|
|
1038
|
+
const identifier = this.store.cacheKeyManager.getOrCreateRecordIdentifier(resource.data);
|
|
1036
1039
|
this.___relatedToken = this.store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
|
|
1037
1040
|
if (bucket === 'identity' || bucket === 'attributes' && notifiedKey === 'id') {
|
|
1038
1041
|
this._ref++;
|
|
@@ -1309,7 +1312,7 @@ class BelongsToReference {
|
|
|
1309
1312
|
store
|
|
1310
1313
|
} = this;
|
|
1311
1314
|
const isResourceData = doc.data && isMaybeResource(doc.data);
|
|
1312
|
-
const added = isResourceData ? store._push(doc, true) : doc.data ? store.
|
|
1315
|
+
const added = isResourceData ? store._push(doc, true) : doc.data ? store.cacheKeyManager.getOrCreateRecordIdentifier(doc.data) : null;
|
|
1313
1316
|
const {
|
|
1314
1317
|
identifier
|
|
1315
1318
|
} = this.belongsToRelationship;
|
|
@@ -1330,6 +1333,7 @@ class BelongsToReference {
|
|
|
1330
1333
|
if ('meta' in doc) {
|
|
1331
1334
|
newData.meta = doc.meta;
|
|
1332
1335
|
}
|
|
1336
|
+
assertPrivateStore(store);
|
|
1333
1337
|
store._join(() => {
|
|
1334
1338
|
this.graph.push({
|
|
1335
1339
|
op: 'updateRelationship',
|
|
@@ -1508,18 +1512,43 @@ function lookupLegacySupport(record) {
|
|
|
1508
1512
|
throw new Error(`Memory Leak Detected`);
|
|
1509
1513
|
}
|
|
1510
1514
|
})(!record.isDestroyed && !record.isDestroying) : {};
|
|
1511
|
-
support = new LegacySupport(record);
|
|
1515
|
+
support = new LegacySupport(record, identifier);
|
|
1512
1516
|
LEGACY_SUPPORT.set(identifier, support);
|
|
1513
|
-
LEGACY_SUPPORT.set(record, support);
|
|
1514
1517
|
}
|
|
1515
1518
|
return support;
|
|
1516
1519
|
}
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* @hideconstructor
|
|
1523
|
+
*/
|
|
1517
1524
|
class LegacySupport {
|
|
1518
|
-
|
|
1525
|
+
/** @internal */
|
|
1526
|
+
|
|
1527
|
+
/** @internal */
|
|
1528
|
+
|
|
1529
|
+
/** @internal */
|
|
1530
|
+
|
|
1531
|
+
/** @internal */
|
|
1532
|
+
|
|
1533
|
+
/** @internal */
|
|
1534
|
+
|
|
1535
|
+
/** @internal */
|
|
1536
|
+
|
|
1537
|
+
/** @internal */
|
|
1538
|
+
|
|
1539
|
+
/** @internal */
|
|
1540
|
+
|
|
1541
|
+
/** @internal */
|
|
1542
|
+
|
|
1543
|
+
/** @internal */
|
|
1544
|
+
|
|
1545
|
+
/** @internal */
|
|
1546
|
+
|
|
1547
|
+
constructor(record, identifier) {
|
|
1519
1548
|
this.record = record;
|
|
1520
|
-
this.store = storeFor(record);
|
|
1521
|
-
this.identifier =
|
|
1522
|
-
this.cache =
|
|
1549
|
+
this.store = isPrivateStore(storeFor(record, false));
|
|
1550
|
+
this.identifier = identifier;
|
|
1551
|
+
this.cache = this.store.cache;
|
|
1523
1552
|
if (this.store._graph) {
|
|
1524
1553
|
this.graph = this.store._graph;
|
|
1525
1554
|
}
|
|
@@ -1529,12 +1558,14 @@ class LegacySupport {
|
|
|
1529
1558
|
this._pending = Object.create(null);
|
|
1530
1559
|
this.references = Object.create(null);
|
|
1531
1560
|
}
|
|
1561
|
+
|
|
1562
|
+
/** @private */
|
|
1532
1563
|
_syncArray(array) {
|
|
1533
1564
|
// It’s possible the parent side of the relationship may have been destroyed by this point
|
|
1534
1565
|
if (this.isDestroyed || this.isDestroying) {
|
|
1535
1566
|
return;
|
|
1536
1567
|
}
|
|
1537
|
-
const currentState = array[
|
|
1568
|
+
const currentState = array[Context].source;
|
|
1538
1569
|
const identifier = this.identifier;
|
|
1539
1570
|
const [identifiers, jsonApi] = this._getCurrentState(identifier, array.key);
|
|
1540
1571
|
if (jsonApi.meta) {
|
|
@@ -1588,7 +1619,7 @@ class LegacySupport {
|
|
|
1588
1619
|
if (!test) {
|
|
1589
1620
|
throw new Error(`Expected a stable identifier`);
|
|
1590
1621
|
}
|
|
1591
|
-
})(!relatedIdentifier ||
|
|
1622
|
+
})(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
|
|
1592
1623
|
const store = this.store;
|
|
1593
1624
|
const relationship = this.graph.get(this.identifier, key);
|
|
1594
1625
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -1648,7 +1679,7 @@ class LegacySupport {
|
|
|
1648
1679
|
if (!test) {
|
|
1649
1680
|
throw new Error(`Expected a stable identifier`);
|
|
1650
1681
|
}
|
|
1651
|
-
})(
|
|
1682
|
+
})(isResourceKey(relatedIdentifier)) : {};
|
|
1652
1683
|
if (cache.recordIsLoaded(relatedIdentifier, true)) {
|
|
1653
1684
|
identifiers.push(relatedIdentifier);
|
|
1654
1685
|
}
|
|
@@ -1664,23 +1695,20 @@ class LegacySupport {
|
|
|
1664
1695
|
}
|
|
1665
1696
|
if (!manyArray) {
|
|
1666
1697
|
const [identifiers, doc] = this._getCurrentState(this.identifier, key);
|
|
1667
|
-
manyArray =
|
|
1698
|
+
manyArray = createLegacyManyArray({
|
|
1668
1699
|
store: this.store,
|
|
1669
|
-
type: definition.type,
|
|
1670
|
-
identifier: this.identifier,
|
|
1671
|
-
cache: this.cache,
|
|
1672
|
-
field: this.store.schema.fields(this.identifier).get(key),
|
|
1673
|
-
identifiers,
|
|
1674
|
-
key,
|
|
1675
|
-
meta: doc.meta || null,
|
|
1676
|
-
links: doc.links || null,
|
|
1677
|
-
isPolymorphic: definition.isPolymorphic,
|
|
1678
|
-
isAsync: definition.isAsync,
|
|
1679
|
-
_inverseIsAsync: definition.inverseIsAsync,
|
|
1680
1700
|
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
1681
1701
|
manager: this,
|
|
1702
|
+
source: identifiers,
|
|
1703
|
+
type: definition.type,
|
|
1682
1704
|
isLoaded: !definition.isAsync,
|
|
1683
|
-
|
|
1705
|
+
editable: true,
|
|
1706
|
+
isAsync: definition.isAsync,
|
|
1707
|
+
isPolymorphic: definition.isPolymorphic,
|
|
1708
|
+
field: this.store.schema.fields(this.identifier).get(key),
|
|
1709
|
+
identifier: this.identifier,
|
|
1710
|
+
links: doc.links || null,
|
|
1711
|
+
meta: doc.meta || null
|
|
1684
1712
|
});
|
|
1685
1713
|
this._manyArrayCache[key] = manyArray;
|
|
1686
1714
|
}
|
|
@@ -1901,7 +1929,7 @@ class LegacySupport {
|
|
|
1901
1929
|
if (!test) {
|
|
1902
1930
|
throw new Error(`Expected stable identifiers`);
|
|
1903
1931
|
}
|
|
1904
|
-
})(!identifiers || identifiers.every(
|
|
1932
|
+
})(!identifiers || identifiers.every(isResourceKey)) : {};
|
|
1905
1933
|
const req = field.options.linksMode ? {
|
|
1906
1934
|
url: getRelatedLink(resource),
|
|
1907
1935
|
op: 'findHasMany',
|
|
@@ -1936,7 +1964,7 @@ class LegacySupport {
|
|
|
1936
1964
|
if (!test) {
|
|
1937
1965
|
throw new Error(`Expected stable identifiers`);
|
|
1938
1966
|
}
|
|
1939
|
-
})(identifiers.every(
|
|
1967
|
+
})(identifiers.every(isResourceKey)) : {};
|
|
1940
1968
|
options.reload = options.reload || !attemptLocalCache || undefined;
|
|
1941
1969
|
return this.store.request({
|
|
1942
1970
|
op: 'findHasMany',
|
|
@@ -1975,7 +2003,7 @@ class LegacySupport {
|
|
|
1975
2003
|
if (!test) {
|
|
1976
2004
|
throw new Error(`Expected a stable identifier`);
|
|
1977
2005
|
}
|
|
1978
|
-
})(!identifier ||
|
|
2006
|
+
})(!identifier || isResourceKey(identifier)) : {};
|
|
1979
2007
|
const {
|
|
1980
2008
|
isStale,
|
|
1981
2009
|
hasDematerializedInverse,
|
|
@@ -2104,7 +2132,7 @@ function handleCompletedRelationshipRequest(recordExt, key, relationship, value,
|
|
|
2104
2132
|
if (isHasMany) {
|
|
2105
2133
|
// we don't notify the record property here to avoid refetch
|
|
2106
2134
|
// only the many array
|
|
2107
|
-
notifyInternalSignal(value[
|
|
2135
|
+
notifyInternalSignal(value[Context].signal);
|
|
2108
2136
|
}
|
|
2109
2137
|
if (error) {
|
|
2110
2138
|
relationship.state.hasFailedLoadAttempt = true;
|
|
@@ -2142,6 +2170,7 @@ function extractIdentifierFromRecord(record) {
|
|
|
2142
2170
|
return recordIdentifierFor(record);
|
|
2143
2171
|
}
|
|
2144
2172
|
function anyUnloaded(store, relationship) {
|
|
2173
|
+
assertPrivateStore(store);
|
|
2145
2174
|
const graph = store._graph;
|
|
2146
2175
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2147
2176
|
if (!test) {
|
|
@@ -2158,6 +2187,7 @@ function anyUnloaded(store, relationship) {
|
|
|
2158
2187
|
return unloaded || false;
|
|
2159
2188
|
}
|
|
2160
2189
|
function areAllInverseRecordsLoaded(store, resource) {
|
|
2190
|
+
assertPrivateStore(store);
|
|
2161
2191
|
const instanceCache = store._instanceCache;
|
|
2162
2192
|
const identifiers = resource.data;
|
|
2163
2193
|
if (Array.isArray(identifiers)) {
|
|
@@ -2165,7 +2195,7 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2165
2195
|
if (!test) {
|
|
2166
2196
|
throw new Error(`Expected stable identifiers`);
|
|
2167
2197
|
}
|
|
2168
|
-
})(identifiers.every(
|
|
2198
|
+
})(identifiers.every(isResourceKey)) : {};
|
|
2169
2199
|
// treat as collection
|
|
2170
2200
|
// check for unloaded records
|
|
2171
2201
|
return identifiers.every(identifier => instanceCache.recordIsLoaded(identifier));
|
|
@@ -2177,7 +2207,7 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2177
2207
|
if (!test) {
|
|
2178
2208
|
throw new Error(`Expected stable identifiers`);
|
|
2179
2209
|
}
|
|
2180
|
-
})(
|
|
2210
|
+
})(isResourceKey(identifiers)) : {};
|
|
2181
2211
|
return instanceCache.recordIsLoaded(identifiers);
|
|
2182
2212
|
}
|
|
2183
2213
|
function isBelongsTo(relationship) {
|
package/dist/model/-private.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-
|
|
2
|
-
export { RelatedCollection as ManyArray } from '@warp-drive/core/store/-private';
|
|
1
|
+
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-8kD2mSe_.js";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { deprecate } from '@ember/debug';
|
|
1
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
2
|
-
import {
|
|
3
|
+
import { Context } from '@warp-drive/core/reactive/-private';
|
|
4
|
+
import { notifyInternalSignal, assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
3
5
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
4
6
|
import { Type } from '@warp-drive/core/types/symbols';
|
|
5
|
-
import { l as lookupLegacySupport, E as Errors } from "../errors-
|
|
6
|
-
import { b as buildSchema, u as unloadRecord, s as serialize, a as save, r as rollbackAttributes, c as reload, h as hasMany,
|
|
7
|
+
import { l as lookupLegacySupport, E as Errors } from "../errors-8kD2mSe_.js";
|
|
8
|
+
import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, g as deleteRecord, R as RecordState, i as changedAttributes, j as belongsTo, k as createSnapshot } from "../schema-provider-DQu4Rjco.js";
|
|
7
9
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -25,7 +27,6 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
|
25
27
|
*
|
|
26
28
|
* @module
|
|
27
29
|
*/
|
|
28
|
-
|
|
29
30
|
// 'isDestroying', 'isDestroyed'
|
|
30
31
|
const LegacyFields = ['_createSnapshot', 'adapterError', 'belongsTo', 'changedAttributes', 'constructor', 'currentState', 'deleteRecord', 'destroyRecord', 'dirtyType', 'errors', 'hasDirtyAttributes', 'hasMany', 'isDeleted', 'isEmpty', 'isError', 'isLoaded', 'isLoading', 'isNew', 'isSaving', 'isValid', 'reload', 'rollbackAttributes', 'save', 'serialize', 'unloadRecord'];
|
|
31
32
|
|
|
@@ -78,10 +79,13 @@ function legacySupport(record, options, prop) {
|
|
|
78
79
|
state = {};
|
|
79
80
|
LegacySupport.set(record, state);
|
|
80
81
|
}
|
|
82
|
+
const suppressDeprecation = Boolean(options && options.suppressDeprecation);
|
|
81
83
|
switch (prop) {
|
|
82
84
|
case '_createSnapshot':
|
|
85
|
+
// FIXME should be deprecated too?
|
|
83
86
|
return createSnapshot;
|
|
84
87
|
case 'adapterError':
|
|
88
|
+
// FIXME should be deprecated too?
|
|
85
89
|
return record.currentState.adapterError;
|
|
86
90
|
case 'belongsTo':
|
|
87
91
|
return belongsTo;
|
|
@@ -98,10 +102,11 @@ function legacySupport(record, options, prop) {
|
|
|
98
102
|
case 'deleteRecord':
|
|
99
103
|
return deleteRecord;
|
|
100
104
|
case 'destroyRecord':
|
|
101
|
-
return destroyRecord;
|
|
105
|
+
return suppressDeprecation ? _destroyRecord : destroyRecord;
|
|
102
106
|
case 'dirtyType':
|
|
103
107
|
return record.currentState.dirtyType;
|
|
104
108
|
case 'errors':
|
|
109
|
+
// FIXME should be deprecated too?
|
|
105
110
|
// @ts-expect-error
|
|
106
111
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
107
112
|
return state.errors = state.errors || Errors.create({
|
|
@@ -128,12 +133,13 @@ function legacySupport(record, options, prop) {
|
|
|
128
133
|
case 'isValid':
|
|
129
134
|
return record.currentState.isValid;
|
|
130
135
|
case 'reload':
|
|
131
|
-
return reload;
|
|
136
|
+
return suppressDeprecation ? _reload : reload;
|
|
132
137
|
case 'rollbackAttributes':
|
|
133
138
|
return rollbackAttributes;
|
|
134
139
|
case 'save':
|
|
135
|
-
return save;
|
|
140
|
+
return suppressDeprecation ? _save : save;
|
|
136
141
|
case 'serialize':
|
|
142
|
+
// FIXME should be deprecated too? (is somewhat deprecated via store.serializeRecord)
|
|
137
143
|
return serialize;
|
|
138
144
|
case 'unloadRecord':
|
|
139
145
|
return unloadRecord;
|
|
@@ -214,6 +220,50 @@ function withDefaults(schema) {
|
|
|
214
220
|
kind: 'derived'
|
|
215
221
|
});
|
|
216
222
|
});
|
|
223
|
+
schema.fields.push({
|
|
224
|
+
name: '_isReloading',
|
|
225
|
+
kind: '@local',
|
|
226
|
+
type: 'boolean',
|
|
227
|
+
options: {
|
|
228
|
+
defaultValue: false
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
schema.fields.push({
|
|
232
|
+
name: 'isDestroying',
|
|
233
|
+
kind: '@local',
|
|
234
|
+
type: 'boolean',
|
|
235
|
+
options: {
|
|
236
|
+
defaultValue: false
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
schema.fields.push({
|
|
240
|
+
name: 'isDestroyed',
|
|
241
|
+
kind: '@local',
|
|
242
|
+
type: 'boolean',
|
|
243
|
+
options: {
|
|
244
|
+
defaultValue: false
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
schema.objectExtensions = schema.objectExtensions || [];
|
|
248
|
+
schema.objectExtensions.push('deprecated-model-behaviors');
|
|
249
|
+
return schema;
|
|
250
|
+
}
|
|
251
|
+
function withRestoredDeprecatedModelRequestBehaviors(schema) {
|
|
252
|
+
schema.legacy = true;
|
|
253
|
+
schema.identity = {
|
|
254
|
+
kind: '@id',
|
|
255
|
+
name: 'id'
|
|
256
|
+
};
|
|
257
|
+
LegacyFields.forEach(field => {
|
|
258
|
+
schema.fields.push({
|
|
259
|
+
type: '@legacy',
|
|
260
|
+
name: field,
|
|
261
|
+
kind: 'derived',
|
|
262
|
+
options: {
|
|
263
|
+
suppressDeprecation: true
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
217
267
|
schema.fields.push({
|
|
218
268
|
name: 'isReloading',
|
|
219
269
|
kind: '@local',
|
|
@@ -261,27 +311,34 @@ function registerDerivations(schema) {
|
|
|
261
311
|
schema._registerMode('@legacy', {
|
|
262
312
|
belongsTo: {
|
|
263
313
|
get(store, record, cacheKey, field) {
|
|
314
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
264
315
|
return lookupLegacySupport(record).getBelongsTo(field.name);
|
|
265
316
|
},
|
|
266
317
|
set(store, record, cacheKey, field, value) {
|
|
318
|
+
assertPrivateStore(store);
|
|
267
319
|
store._join(() => {
|
|
320
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
268
321
|
lookupLegacySupport(record).setDirtyBelongsTo(field.name, value);
|
|
269
322
|
});
|
|
270
323
|
}
|
|
271
324
|
},
|
|
272
325
|
hasMany: {
|
|
273
326
|
get(store, record, cacheKey, field) {
|
|
327
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
274
328
|
return lookupLegacySupport(record).getHasMany(field.name);
|
|
275
329
|
},
|
|
276
330
|
set(store, record, cacheKey, field, value) {
|
|
331
|
+
assertPrivateStore(store);
|
|
277
332
|
store._join(() => {
|
|
278
333
|
const support = lookupLegacySupport(record);
|
|
334
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
279
335
|
const manyArray = support.getManyArray(field.name);
|
|
280
336
|
manyArray.splice(0, manyArray.length, ...value);
|
|
281
337
|
});
|
|
282
338
|
},
|
|
283
339
|
notify(store, record, cacheKey, field) {
|
|
284
340
|
const support = lookupLegacySupport(record);
|
|
341
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
285
342
|
const manyArray = support && support._manyArrayCache[field.name];
|
|
286
343
|
const hasPromise = support && support._relationshipPromisesCache[field.name];
|
|
287
344
|
if (manyArray && hasPromise) {
|
|
@@ -290,13 +347,41 @@ function registerDerivations(schema) {
|
|
|
290
347
|
return false;
|
|
291
348
|
}
|
|
292
349
|
if (manyArray) {
|
|
293
|
-
notifyInternalSignal(manyArray[
|
|
350
|
+
notifyInternalSignal(manyArray[Context].signal);
|
|
294
351
|
return true;
|
|
295
352
|
}
|
|
296
353
|
return false;
|
|
297
354
|
}
|
|
298
355
|
}
|
|
299
356
|
});
|
|
357
|
+
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension({
|
|
358
|
+
name: 'deprecated-model-behaviors',
|
|
359
|
+
kind: 'object',
|
|
360
|
+
features: {
|
|
361
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
362
|
+
get isReloading() {
|
|
363
|
+
deprecate(`record.isReloading is deprecated, please use store.request and either <Request> or getRequuestState to keep track of the request state instead.`, false, {
|
|
364
|
+
id: 'warp-drive:deprecate-legacy-request-methods',
|
|
365
|
+
until: '6.0',
|
|
366
|
+
for: '@warp-drive/core',
|
|
367
|
+
url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',
|
|
368
|
+
since: {
|
|
369
|
+
enabled: '5.7',
|
|
370
|
+
available: '5.7'
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// @ts-expect-error
|
|
374
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
375
|
+
return this._isReloading;
|
|
376
|
+
},
|
|
377
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
378
|
+
set isReloading(v) {
|
|
379
|
+
// @ts-expect-error
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
381
|
+
this._isReloading = v;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
300
385
|
}
|
|
301
386
|
|
|
302
387
|
/**
|
|
@@ -403,8 +488,8 @@ class DelegatingSchemaService {
|
|
|
403
488
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource) {
|
|
404
489
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource);
|
|
405
490
|
}
|
|
406
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field) {
|
|
407
|
-
return this._preferred.CAUTION_MEGA_DANGER_ZONE_objectExtensions(field);
|
|
491
|
+
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType) {
|
|
492
|
+
return this._preferred.CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType);
|
|
408
493
|
}
|
|
409
494
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field) {
|
|
410
495
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field);
|
|
@@ -461,4 +546,4 @@ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA
|
|
|
461
546
|
return this._preferred.doesTypeExist?.(type) || this._secondary.doesTypeExist?.(type) || false;
|
|
462
547
|
};
|
|
463
548
|
}
|
|
464
|
-
export { DelegatingSchemaService, registerDerivations, withDefaults };
|
|
549
|
+
export { DelegatingSchemaService, registerDerivations, withDefaults, withRestoredDeprecatedModelRequestBehaviors };
|
package/dist/model.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { computed } from '@ember/object';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export { M as Model, b as buildSchema, M as default } from "./schema-provider-BdQhkT-Q.js";
|
|
3
|
+
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
4
|
+
import { i as isElementDescriptor, n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
6
5
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
7
6
|
import { warn, deprecate } from '@ember/debug';
|
|
8
|
-
import {
|
|
9
|
-
import { l as lookupLegacySupport } from "./errors-
|
|
7
|
+
import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
|
|
8
|
+
import { l as lookupLegacySupport } from "./errors-8kD2mSe_.js";
|
|
10
9
|
import { singularize, dasherize } from '@warp-drive/utilities/string';
|
|
10
|
+
import { l as getModelFactory } from "./schema-provider-DQu4Rjco.js";
|
|
11
|
+
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-DQu4Rjco.js";
|
|
11
12
|
import { setOwner, getOwner } from '@ember/application';
|
|
12
13
|
function _attr(type, options) {
|
|
13
14
|
if (typeof type === 'object') {
|
|
@@ -33,7 +34,8 @@ function _attr(type, options) {
|
|
|
33
34
|
if (this.isDestroyed || this.isDestroying) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
const cache = this[RecordStore].cache;
|
|
38
|
+
return cache.getAttr(recordIdentifierFor(this), key);
|
|
37
39
|
},
|
|
38
40
|
set(key, value) {
|
|
39
41
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
@@ -47,7 +49,7 @@ function _attr(type, options) {
|
|
|
47
49
|
throw new Error(`Attempted to set '${key}' on the deleted record ${identifier.type}:${identifier.id} (${identifier.lid})`);
|
|
48
50
|
}
|
|
49
51
|
})(!this.currentState.isDeleted) : {};
|
|
50
|
-
const cache =
|
|
52
|
+
const cache = this[RecordStore].cache;
|
|
51
53
|
const currentValue = cache.getAttr(identifier, key);
|
|
52
54
|
if (currentValue !== value) {
|
|
53
55
|
cache.setAttr(identifier, key, value);
|
|
@@ -245,6 +247,7 @@ function _belongsTo(type, options) {
|
|
|
245
247
|
throw new Error(`'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`);
|
|
246
248
|
}
|
|
247
249
|
}
|
|
250
|
+
assertPrivateStore(this[RecordStore]);
|
|
248
251
|
this[RecordStore]._join(() => {
|
|
249
252
|
support.setDirtyBelongsTo(key, value);
|
|
250
253
|
});
|
|
@@ -483,6 +486,7 @@ function _hasMany(type, options) {
|
|
|
483
486
|
throw new Error(`You must pass an array of records to set a hasMany relationship`);
|
|
484
487
|
}
|
|
485
488
|
})(Array.isArray(records)) : {};
|
|
489
|
+
assertPrivateStore(this[RecordStore]);
|
|
486
490
|
this[RecordStore]._join(() => {
|
|
487
491
|
manyArray.splice(0, manyArray.length, ...records);
|
|
488
492
|
});
|
|
@@ -666,14 +670,13 @@ function hasMany(type, options) {
|
|
|
666
670
|
}
|
|
667
671
|
function instantiateRecord(identifier, createRecordArgs) {
|
|
668
672
|
const type = identifier.type;
|
|
669
|
-
|
|
673
|
+
|
|
670
674
|
// TODO deprecate allowing unknown args setting
|
|
671
675
|
const createOptions = {
|
|
672
676
|
_createProps: createRecordArgs,
|
|
673
677
|
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
|
|
674
678
|
_secretInit: {
|
|
675
679
|
identifier,
|
|
676
|
-
cache,
|
|
677
680
|
store: this,
|
|
678
681
|
cb: secretInit
|
|
679
682
|
}
|
|
@@ -698,6 +701,7 @@ function teardownRecord(record) {
|
|
|
698
701
|
record.destroy();
|
|
699
702
|
}
|
|
700
703
|
function modelFor(modelName) {
|
|
704
|
+
assertPrivateStore(this);
|
|
701
705
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
702
706
|
if (!test) {
|
|
703
707
|
throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
|
|
@@ -728,9 +732,8 @@ function modelFor(modelName) {
|
|
|
728
732
|
type
|
|
729
733
|
})) : {};
|
|
730
734
|
}
|
|
731
|
-
function secretInit(record,
|
|
735
|
+
function secretInit(record, identifier, store) {
|
|
732
736
|
setRecordIdentifier(record, identifier);
|
|
733
737
|
StoreMap.set(record, store);
|
|
734
|
-
setCacheFor(record, cache);
|
|
735
738
|
}
|
|
736
739
|
export { attr, belongsTo, hasMany, instantiateRecord, modelFor, teardownRecord };
|