@warp-drive/legacy 5.7.0-alpha.3 → 5.7.0-alpha.31
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/utils/continue-on-reject.d.ts +1 -7
- 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 -16
- 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 -3
- package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +40 -18
- package/declarations/compat/legacy-network-handler/snapshot.d.ts +70 -44
- package/declarations/compat.d.ts +3 -3
- package/declarations/model/-private/attr.d.ts +1 -1
- package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +2 -2
- package/declarations/model/-private/hooks.d.ts +2 -2
- package/declarations/model/-private/legacy-relationships-support.d.ts +21 -27
- package/declarations/model/-private/model-methods.d.ts +0 -4
- package/declarations/model/-private/model.d.ts +13 -31
- package/declarations/model/-private/notify-changes.d.ts +2 -2
- package/declarations/model/-private/promise-many-array.d.ts +0 -3
- package/declarations/model/-private/record-state.d.ts +2 -25
- package/declarations/model/-private/references/belongs-to.d.ts +6 -6
- package/declarations/model/-private/references/has-many.d.ts +6 -12
- package/declarations/model/-private/schema-provider.d.ts +6 -6
- package/declarations/model/-private.d.ts +2 -1
- package/declarations/model/migration-support.d.ts +10 -34
- package/declarations/store/-private.d.ts +12 -23
- package/dist/{-private-CKrP0ogQ.js → -private-HaYCdCCm.js} +155 -141
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/json-api.js +1 -1
- package/dist/adapter/rest.js +1 -1
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +3 -2
- package/dist/compat.js +7 -2
- package/dist/{errors-BX5wowuz.js → errors-BMZPmFxm.js} +46 -36
- package/dist/model/-private.js +1 -2
- package/dist/model/migration-support.js +14 -6
- package/dist/model.js +13 -11
- package/dist/{schema-provider-Cbnf6sKm.js → schema-provider-Dhk-879f.js} +55 -26
- package/dist/{serialize-into-hash-Bp58npke.js → serialize-into-hash-Ceon-MrI.js} +2 -1
- package/dist/store.js +8 -6
- package/package.json +13 -13
|
@@ -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-HaYCdCCm.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,25 @@ 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
|
}
|
|
1517
1520
|
class LegacySupport {
|
|
1518
|
-
|
|
1521
|
+
/** @internal */
|
|
1522
|
+
|
|
1523
|
+
/** @internal */
|
|
1524
|
+
|
|
1525
|
+
/** @internal */
|
|
1526
|
+
|
|
1527
|
+
/** @internal */
|
|
1528
|
+
|
|
1529
|
+
constructor(record, identifier) {
|
|
1519
1530
|
this.record = record;
|
|
1520
|
-
this.store = storeFor(record);
|
|
1521
|
-
this.identifier =
|
|
1522
|
-
this.cache =
|
|
1531
|
+
this.store = isPrivateStore(storeFor(record, false));
|
|
1532
|
+
this.identifier = identifier;
|
|
1533
|
+
this.cache = this.store.cache;
|
|
1523
1534
|
if (this.store._graph) {
|
|
1524
1535
|
this.graph = this.store._graph;
|
|
1525
1536
|
}
|
|
@@ -1534,7 +1545,7 @@ class LegacySupport {
|
|
|
1534
1545
|
if (this.isDestroyed || this.isDestroying) {
|
|
1535
1546
|
return;
|
|
1536
1547
|
}
|
|
1537
|
-
const currentState = array[
|
|
1548
|
+
const currentState = array[Context].source;
|
|
1538
1549
|
const identifier = this.identifier;
|
|
1539
1550
|
const [identifiers, jsonApi] = this._getCurrentState(identifier, array.key);
|
|
1540
1551
|
if (jsonApi.meta) {
|
|
@@ -1588,7 +1599,7 @@ class LegacySupport {
|
|
|
1588
1599
|
if (!test) {
|
|
1589
1600
|
throw new Error(`Expected a stable identifier`);
|
|
1590
1601
|
}
|
|
1591
|
-
})(!relatedIdentifier ||
|
|
1602
|
+
})(!relatedIdentifier || isResourceKey(relatedIdentifier)) : {};
|
|
1592
1603
|
const store = this.store;
|
|
1593
1604
|
const relationship = this.graph.get(this.identifier, key);
|
|
1594
1605
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -1648,7 +1659,7 @@ class LegacySupport {
|
|
|
1648
1659
|
if (!test) {
|
|
1649
1660
|
throw new Error(`Expected a stable identifier`);
|
|
1650
1661
|
}
|
|
1651
|
-
})(
|
|
1662
|
+
})(isResourceKey(relatedIdentifier)) : {};
|
|
1652
1663
|
if (cache.recordIsLoaded(relatedIdentifier, true)) {
|
|
1653
1664
|
identifiers.push(relatedIdentifier);
|
|
1654
1665
|
}
|
|
@@ -1664,23 +1675,20 @@ class LegacySupport {
|
|
|
1664
1675
|
}
|
|
1665
1676
|
if (!manyArray) {
|
|
1666
1677
|
const [identifiers, doc] = this._getCurrentState(this.identifier, key);
|
|
1667
|
-
manyArray =
|
|
1678
|
+
manyArray = createLegacyManyArray({
|
|
1668
1679
|
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
1680
|
// @ts-expect-error Typescript doesn't have a way for us to thread the generic backwards so it infers unknown instead of T
|
|
1681
1681
|
manager: this,
|
|
1682
|
+
source: identifiers,
|
|
1683
|
+
type: definition.type,
|
|
1682
1684
|
isLoaded: !definition.isAsync,
|
|
1683
|
-
|
|
1685
|
+
editable: true,
|
|
1686
|
+
isAsync: definition.isAsync,
|
|
1687
|
+
isPolymorphic: definition.isPolymorphic,
|
|
1688
|
+
field: this.store.schema.fields(this.identifier).get(key),
|
|
1689
|
+
identifier: this.identifier,
|
|
1690
|
+
links: doc.links || null,
|
|
1691
|
+
meta: doc.meta || null
|
|
1684
1692
|
});
|
|
1685
1693
|
this._manyArrayCache[key] = manyArray;
|
|
1686
1694
|
}
|
|
@@ -1901,7 +1909,7 @@ class LegacySupport {
|
|
|
1901
1909
|
if (!test) {
|
|
1902
1910
|
throw new Error(`Expected stable identifiers`);
|
|
1903
1911
|
}
|
|
1904
|
-
})(!identifiers || identifiers.every(
|
|
1912
|
+
})(!identifiers || identifiers.every(isResourceKey)) : {};
|
|
1905
1913
|
const req = field.options.linksMode ? {
|
|
1906
1914
|
url: getRelatedLink(resource),
|
|
1907
1915
|
op: 'findHasMany',
|
|
@@ -1936,7 +1944,7 @@ class LegacySupport {
|
|
|
1936
1944
|
if (!test) {
|
|
1937
1945
|
throw new Error(`Expected stable identifiers`);
|
|
1938
1946
|
}
|
|
1939
|
-
})(identifiers.every(
|
|
1947
|
+
})(identifiers.every(isResourceKey)) : {};
|
|
1940
1948
|
options.reload = options.reload || !attemptLocalCache || undefined;
|
|
1941
1949
|
return this.store.request({
|
|
1942
1950
|
op: 'findHasMany',
|
|
@@ -1975,7 +1983,7 @@ class LegacySupport {
|
|
|
1975
1983
|
if (!test) {
|
|
1976
1984
|
throw new Error(`Expected a stable identifier`);
|
|
1977
1985
|
}
|
|
1978
|
-
})(!identifier ||
|
|
1986
|
+
})(!identifier || isResourceKey(identifier)) : {};
|
|
1979
1987
|
const {
|
|
1980
1988
|
isStale,
|
|
1981
1989
|
hasDematerializedInverse,
|
|
@@ -2104,7 +2112,7 @@ function handleCompletedRelationshipRequest(recordExt, key, relationship, value,
|
|
|
2104
2112
|
if (isHasMany) {
|
|
2105
2113
|
// we don't notify the record property here to avoid refetch
|
|
2106
2114
|
// only the many array
|
|
2107
|
-
notifyInternalSignal(value[
|
|
2115
|
+
notifyInternalSignal(value[Context].signal);
|
|
2108
2116
|
}
|
|
2109
2117
|
if (error) {
|
|
2110
2118
|
relationship.state.hasFailedLoadAttempt = true;
|
|
@@ -2142,6 +2150,7 @@ function extractIdentifierFromRecord(record) {
|
|
|
2142
2150
|
return recordIdentifierFor(record);
|
|
2143
2151
|
}
|
|
2144
2152
|
function anyUnloaded(store, relationship) {
|
|
2153
|
+
assertPrivateStore(store);
|
|
2145
2154
|
const graph = store._graph;
|
|
2146
2155
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2147
2156
|
if (!test) {
|
|
@@ -2158,6 +2167,7 @@ function anyUnloaded(store, relationship) {
|
|
|
2158
2167
|
return unloaded || false;
|
|
2159
2168
|
}
|
|
2160
2169
|
function areAllInverseRecordsLoaded(store, resource) {
|
|
2170
|
+
assertPrivateStore(store);
|
|
2161
2171
|
const instanceCache = store._instanceCache;
|
|
2162
2172
|
const identifiers = resource.data;
|
|
2163
2173
|
if (Array.isArray(identifiers)) {
|
|
@@ -2165,7 +2175,7 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2165
2175
|
if (!test) {
|
|
2166
2176
|
throw new Error(`Expected stable identifiers`);
|
|
2167
2177
|
}
|
|
2168
|
-
})(identifiers.every(
|
|
2178
|
+
})(identifiers.every(isResourceKey)) : {};
|
|
2169
2179
|
// treat as collection
|
|
2170
2180
|
// check for unloaded records
|
|
2171
2181
|
return identifiers.every(identifier => instanceCache.recordIsLoaded(identifier));
|
|
@@ -2177,7 +2187,7 @@ function areAllInverseRecordsLoaded(store, resource) {
|
|
|
2177
2187
|
if (!test) {
|
|
2178
2188
|
throw new Error(`Expected stable identifiers`);
|
|
2179
2189
|
}
|
|
2180
|
-
})(
|
|
2190
|
+
})(isResourceKey(identifiers)) : {};
|
|
2181
2191
|
return instanceCache.recordIsLoaded(identifiers);
|
|
2182
2192
|
}
|
|
2183
2193
|
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-BMZPmFxm.js";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { deprecate } from '@ember/debug';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
|
-
import {
|
|
3
|
+
import { Context } from '@warp-drive/core/reactive/-private';
|
|
4
|
+
import { notifyInternalSignal, assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
4
5
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
5
6
|
import { Type } from '@warp-drive/core/types/symbols';
|
|
6
|
-
import { l as lookupLegacySupport, E as Errors } from "../errors-
|
|
7
|
-
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-
|
|
7
|
+
import { l as lookupLegacySupport, E as Errors } from "../errors-BMZPmFxm.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-Dhk-879f.js";
|
|
8
9
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -310,27 +311,34 @@ function registerDerivations(schema) {
|
|
|
310
311
|
schema._registerMode('@legacy', {
|
|
311
312
|
belongsTo: {
|
|
312
313
|
get(store, record, cacheKey, field) {
|
|
314
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
313
315
|
return lookupLegacySupport(record).getBelongsTo(field.name);
|
|
314
316
|
},
|
|
315
317
|
set(store, record, cacheKey, field, value) {
|
|
318
|
+
assertPrivateStore(store);
|
|
316
319
|
store._join(() => {
|
|
320
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
317
321
|
lookupLegacySupport(record).setDirtyBelongsTo(field.name, value);
|
|
318
322
|
});
|
|
319
323
|
}
|
|
320
324
|
},
|
|
321
325
|
hasMany: {
|
|
322
326
|
get(store, record, cacheKey, field) {
|
|
327
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
323
328
|
return lookupLegacySupport(record).getHasMany(field.name);
|
|
324
329
|
},
|
|
325
330
|
set(store, record, cacheKey, field, value) {
|
|
331
|
+
assertPrivateStore(store);
|
|
326
332
|
store._join(() => {
|
|
327
333
|
const support = lookupLegacySupport(record);
|
|
334
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
328
335
|
const manyArray = support.getManyArray(field.name);
|
|
329
336
|
manyArray.splice(0, manyArray.length, ...value);
|
|
330
337
|
});
|
|
331
338
|
},
|
|
332
339
|
notify(store, record, cacheKey, field) {
|
|
333
340
|
const support = lookupLegacySupport(record);
|
|
341
|
+
// FIXME field.name here should likely be field.sourceKey || field.name
|
|
334
342
|
const manyArray = support && support._manyArrayCache[field.name];
|
|
335
343
|
const hasPromise = support && support._relationshipPromisesCache[field.name];
|
|
336
344
|
if (manyArray && hasPromise) {
|
|
@@ -339,7 +347,7 @@ function registerDerivations(schema) {
|
|
|
339
347
|
return false;
|
|
340
348
|
}
|
|
341
349
|
if (manyArray) {
|
|
342
|
-
notifyInternalSignal(manyArray[
|
|
350
|
+
notifyInternalSignal(manyArray[Context].signal);
|
|
343
351
|
return true;
|
|
344
352
|
}
|
|
345
353
|
return false;
|
|
@@ -480,8 +488,8 @@ class DelegatingSchemaService {
|
|
|
480
488
|
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource) {
|
|
481
489
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource);
|
|
482
490
|
}
|
|
483
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field) {
|
|
484
|
-
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);
|
|
485
493
|
}
|
|
486
494
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field) {
|
|
487
495
|
return this._preferred.CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field);
|
package/dist/model.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { computed } from '@ember/object';
|
|
2
2
|
import { recordIdentifierFor } from '@warp-drive/core';
|
|
3
|
-
import {
|
|
3
|
+
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
4
4
|
import { i as isElementDescriptor, n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
5
5
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
6
6
|
import { warn, deprecate } from '@ember/debug';
|
|
7
|
-
import {
|
|
8
|
-
import { l as lookupLegacySupport } from "./errors-
|
|
7
|
+
import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
|
|
8
|
+
import { l as lookupLegacySupport } from "./errors-BMZPmFxm.js";
|
|
9
9
|
import { singularize, dasherize } from '@warp-drive/utilities/string';
|
|
10
|
-
import { l as getModelFactory } from "./schema-provider-
|
|
11
|
-
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-
|
|
10
|
+
import { l as getModelFactory } from "./schema-provider-Dhk-879f.js";
|
|
11
|
+
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-Dhk-879f.js";
|
|
12
12
|
import { setOwner, getOwner } from '@ember/application';
|
|
13
13
|
function _attr(type, options) {
|
|
14
14
|
if (typeof type === 'object') {
|
|
@@ -34,7 +34,8 @@ function _attr(type, options) {
|
|
|
34
34
|
if (this.isDestroyed || this.isDestroying) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
const cache = this[RecordStore].cache;
|
|
38
|
+
return cache.getAttr(recordIdentifierFor(this), key);
|
|
38
39
|
},
|
|
39
40
|
set(key, value) {
|
|
40
41
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
@@ -48,7 +49,7 @@ function _attr(type, options) {
|
|
|
48
49
|
throw new Error(`Attempted to set '${key}' on the deleted record ${identifier.type}:${identifier.id} (${identifier.lid})`);
|
|
49
50
|
}
|
|
50
51
|
})(!this.currentState.isDeleted) : {};
|
|
51
|
-
const cache =
|
|
52
|
+
const cache = this[RecordStore].cache;
|
|
52
53
|
const currentValue = cache.getAttr(identifier, key);
|
|
53
54
|
if (currentValue !== value) {
|
|
54
55
|
cache.setAttr(identifier, key, value);
|
|
@@ -246,6 +247,7 @@ function _belongsTo(type, options) {
|
|
|
246
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()}`);
|
|
247
248
|
}
|
|
248
249
|
}
|
|
250
|
+
assertPrivateStore(this[RecordStore]);
|
|
249
251
|
this[RecordStore]._join(() => {
|
|
250
252
|
support.setDirtyBelongsTo(key, value);
|
|
251
253
|
});
|
|
@@ -484,6 +486,7 @@ function _hasMany(type, options) {
|
|
|
484
486
|
throw new Error(`You must pass an array of records to set a hasMany relationship`);
|
|
485
487
|
}
|
|
486
488
|
})(Array.isArray(records)) : {};
|
|
489
|
+
assertPrivateStore(this[RecordStore]);
|
|
487
490
|
this[RecordStore]._join(() => {
|
|
488
491
|
manyArray.splice(0, manyArray.length, ...records);
|
|
489
492
|
});
|
|
@@ -667,14 +670,13 @@ function hasMany(type, options) {
|
|
|
667
670
|
}
|
|
668
671
|
function instantiateRecord(identifier, createRecordArgs) {
|
|
669
672
|
const type = identifier.type;
|
|
670
|
-
|
|
673
|
+
|
|
671
674
|
// TODO deprecate allowing unknown args setting
|
|
672
675
|
const createOptions = {
|
|
673
676
|
_createProps: createRecordArgs,
|
|
674
677
|
// TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
|
|
675
678
|
_secretInit: {
|
|
676
679
|
identifier,
|
|
677
|
-
cache,
|
|
678
680
|
store: this,
|
|
679
681
|
cb: secretInit
|
|
680
682
|
}
|
|
@@ -699,6 +701,7 @@ function teardownRecord(record) {
|
|
|
699
701
|
record.destroy();
|
|
700
702
|
}
|
|
701
703
|
function modelFor(modelName) {
|
|
704
|
+
assertPrivateStore(this);
|
|
702
705
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
703
706
|
if (!test) {
|
|
704
707
|
throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
|
|
@@ -729,9 +732,8 @@ function modelFor(modelName) {
|
|
|
729
732
|
type
|
|
730
733
|
})) : {};
|
|
731
734
|
}
|
|
732
|
-
function secretInit(record,
|
|
735
|
+
function secretInit(record, identifier, store) {
|
|
733
736
|
setRecordIdentifier(record, identifier);
|
|
734
737
|
StoreMap.set(record, store);
|
|
735
|
-
setCacheFor(record, cache);
|
|
736
738
|
}
|
|
737
739
|
export { attr, belongsTo, hasMany, instantiateRecord, modelFor, teardownRecord };
|
|
@@ -2,12 +2,13 @@ import { getOwner } from '@ember/application';
|
|
|
2
2
|
import { deprecate } from '@ember/debug';
|
|
3
3
|
import EmberObject from '@ember/object';
|
|
4
4
|
import { recordIdentifierFor, storeFor } from '@warp-drive/core';
|
|
5
|
-
import {
|
|
5
|
+
import { assertPrivateStore, notifyInternalSignal, peekInternalSignal, withSignalStore, recordIdentifierFor as recordIdentifierFor$1, gate, memoized, defineSignal, coerceId, entangleSignal, defineGate } from '@warp-drive/core/store/-private';
|
|
6
6
|
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
7
|
-
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-
|
|
8
|
-
import { u as upgradeStore, F as FetchManager } from "./-private-
|
|
7
|
+
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-BMZPmFxm.js";
|
|
8
|
+
import { u as upgradeStore, F as FetchManager } from "./-private-HaYCdCCm.js";
|
|
9
9
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
10
10
|
import { cacheFor } from '@ember/object/internals';
|
|
11
|
+
import { Context } from '@warp-drive/core/reactive/-private';
|
|
11
12
|
import { d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
|
|
12
13
|
import { n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
13
14
|
function rollbackAttributes() {
|
|
@@ -17,8 +18,10 @@ function rollbackAttributes() {
|
|
|
17
18
|
const {
|
|
18
19
|
isNew
|
|
19
20
|
} = currentState;
|
|
20
|
-
this[RecordStore]
|
|
21
|
-
|
|
21
|
+
const store = this[RecordStore];
|
|
22
|
+
assertPrivateStore(store);
|
|
23
|
+
store._join(() => {
|
|
24
|
+
store.cache.rollbackAttrs(recordIdentifierFor(this));
|
|
22
25
|
this.errors.clear();
|
|
23
26
|
currentState.cleanErrorRequests();
|
|
24
27
|
if (isNew) {
|
|
@@ -84,7 +87,7 @@ function _reload(options = {}) {
|
|
|
84
87
|
return promise;
|
|
85
88
|
}
|
|
86
89
|
function changedAttributes() {
|
|
87
|
-
return
|
|
90
|
+
return this[RecordStore].cache.changedAttrs(recordIdentifierFor(this));
|
|
88
91
|
}
|
|
89
92
|
function serialize(options) {
|
|
90
93
|
upgradeStore(this[RecordStore]);
|
|
@@ -215,7 +218,7 @@ function notifyRelationship(identifier, key, record, meta) {
|
|
|
215
218
|
return;
|
|
216
219
|
}
|
|
217
220
|
if (manyArray) {
|
|
218
|
-
notifyInternalSignal(manyArray[
|
|
221
|
+
notifyInternalSignal(manyArray[Context].signal);
|
|
219
222
|
|
|
220
223
|
//We need to notifyPropertyChange in the adding case because we need to make sure
|
|
221
224
|
//we fetch the newly added record in case it is unloaded
|
|
@@ -287,11 +290,34 @@ root
|
|
|
287
290
|
invalid
|
|
288
291
|
inFlight
|
|
289
292
|
|
|
290
|
-
@
|
|
293
|
+
@hideconstructor
|
|
294
|
+
@private
|
|
291
295
|
*/
|
|
292
296
|
class RecordState {
|
|
297
|
+
/** @internal */
|
|
298
|
+
|
|
299
|
+
/** @internal */
|
|
300
|
+
|
|
301
|
+
/** @internal */
|
|
302
|
+
|
|
303
|
+
/** @internal */
|
|
304
|
+
|
|
305
|
+
/** @internal */
|
|
306
|
+
|
|
307
|
+
/** @internal */
|
|
308
|
+
|
|
309
|
+
/** @internal */
|
|
310
|
+
|
|
311
|
+
/** @internal */
|
|
312
|
+
|
|
313
|
+
/** @internal */
|
|
314
|
+
|
|
315
|
+
/** @internal */
|
|
316
|
+
|
|
317
|
+
/** @internal */
|
|
318
|
+
|
|
293
319
|
constructor(record) {
|
|
294
|
-
const store = storeFor(record);
|
|
320
|
+
const store = storeFor(record, false);
|
|
295
321
|
const identity = recordIdentifierFor$1(record);
|
|
296
322
|
this.identifier = identity;
|
|
297
323
|
this.record = record;
|
|
@@ -382,7 +408,7 @@ class RecordState {
|
|
|
382
408
|
|
|
383
409
|
/** @internal */
|
|
384
410
|
destroy() {
|
|
385
|
-
storeFor(this.record).notifications.unsubscribe(this.handler);
|
|
411
|
+
storeFor(this.record, false).notifications.unsubscribe(this.handler);
|
|
386
412
|
}
|
|
387
413
|
|
|
388
414
|
/** @internal */
|
|
@@ -719,7 +745,7 @@ class Model extends EmberObject {
|
|
|
719
745
|
super.init(options);
|
|
720
746
|
this[RecordStore] = store;
|
|
721
747
|
const identity = _secretInit.identifier;
|
|
722
|
-
_secretInit.cb(this,
|
|
748
|
+
_secretInit.cb(this, identity, _secretInit.store);
|
|
723
749
|
this.___recordState = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? new RecordState(this) : null;
|
|
724
750
|
this.setProperties(createProps);
|
|
725
751
|
const notifications = store.notifications;
|
|
@@ -728,16 +754,18 @@ class Model extends EmberObject {
|
|
|
728
754
|
});
|
|
729
755
|
}
|
|
730
756
|
|
|
731
|
-
/** @
|
|
757
|
+
/** @private */
|
|
732
758
|
// @ts-expect-error destroy should not return a value, but ember's types force it to
|
|
733
759
|
destroy() {
|
|
734
760
|
const identifier = recordIdentifierFor(this);
|
|
735
761
|
this.___recordState?.destroy();
|
|
736
|
-
const store = storeFor(this);
|
|
762
|
+
const store = storeFor(this, false);
|
|
737
763
|
store.notifications.unsubscribe(this.___private_notifications);
|
|
738
|
-
LEGACY_SUPPORT.get(
|
|
739
|
-
|
|
740
|
-
|
|
764
|
+
const support = LEGACY_SUPPORT.get(identifier);
|
|
765
|
+
if (support) {
|
|
766
|
+
support.destroy();
|
|
767
|
+
LEGACY_SUPPORT.delete(identifier);
|
|
768
|
+
}
|
|
741
769
|
super.destroy();
|
|
742
770
|
}
|
|
743
771
|
|
|
@@ -1027,6 +1055,7 @@ class Model extends EmberObject {
|
|
|
1027
1055
|
const normalizedId = coerceId(id);
|
|
1028
1056
|
const identifier = recordIdentifierFor(this);
|
|
1029
1057
|
const didChange = normalizedId !== identifier.id;
|
|
1058
|
+
assertPrivateStore(this.store);
|
|
1030
1059
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1031
1060
|
if (!test) {
|
|
1032
1061
|
throw new Error(`Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`);
|
|
@@ -1034,7 +1063,7 @@ class Model extends EmberObject {
|
|
|
1034
1063
|
})(!didChange || identifier.id === null) : {};
|
|
1035
1064
|
if (normalizedId !== null && didChange) {
|
|
1036
1065
|
this.store._instanceCache.setRecordId(identifier, normalizedId);
|
|
1037
|
-
this.store.notifications.notify(identifier, 'identity');
|
|
1066
|
+
this.store.notifications.notify(identifier, 'identity', null);
|
|
1038
1067
|
}
|
|
1039
1068
|
}
|
|
1040
1069
|
toString() {
|
|
@@ -1202,8 +1231,8 @@ class Model extends EmberObject {
|
|
|
1202
1231
|
}
|
|
1203
1232
|
```
|
|
1204
1233
|
@public
|
|
1205
|
-
@param
|
|
1206
|
-
@param
|
|
1234
|
+
@param callback the callback to invoke
|
|
1235
|
+
@param binding the value to which the callback's `this` should be bound
|
|
1207
1236
|
*/
|
|
1208
1237
|
eachRelationship(callback, binding) {
|
|
1209
1238
|
this.constructor.eachRelationship(callback, binding);
|
|
@@ -1212,7 +1241,7 @@ class Model extends EmberObject {
|
|
|
1212
1241
|
return this.constructor.relationshipsByName.get(name);
|
|
1213
1242
|
}
|
|
1214
1243
|
inverseFor(name) {
|
|
1215
|
-
return this.constructor.inverseFor(name, storeFor(this));
|
|
1244
|
+
return this.constructor.inverseFor(name, storeFor(this, false));
|
|
1216
1245
|
}
|
|
1217
1246
|
eachAttribute(callback, binding) {
|
|
1218
1247
|
this.constructor.eachAttribute(callback, binding);
|
|
@@ -1274,9 +1303,9 @@ class Model extends EmberObject {
|
|
|
1274
1303
|
```
|
|
1275
1304
|
Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
|
|
1276
1305
|
@public
|
|
1277
|
-
@param
|
|
1278
|
-
@param
|
|
1279
|
-
@return
|
|
1306
|
+
@param name the name of the relationship
|
|
1307
|
+
@param store an instance of Store
|
|
1308
|
+
@return the type of the relationship, or undefined
|
|
1280
1309
|
*/
|
|
1281
1310
|
static typeForRelationship(name, store) {
|
|
1282
1311
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -1316,9 +1345,9 @@ class Model extends EmberObject {
|
|
|
1316
1345
|
store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
|
|
1317
1346
|
```
|
|
1318
1347
|
@public
|
|
1319
|
-
@param
|
|
1320
|
-
@param
|
|
1321
|
-
@return
|
|
1348
|
+
@param name the name of the relationship
|
|
1349
|
+
@param store
|
|
1350
|
+
@return the inverse relationship, or null
|
|
1322
1351
|
*/
|
|
1323
1352
|
static {
|
|
1324
1353
|
decorateMethodV2(this, "inverseMap", [computeOnce]);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { warn } from '@ember/debug';
|
|
2
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
3
|
+
import '@warp-drive/core/reactive/-private';
|
|
4
|
+
import "./-private-HaYCdCCm.js";
|
|
3
5
|
import '@warp-drive/core/store/-private';
|
|
4
|
-
import "./-private-CKrP0ogQ.js";
|
|
5
6
|
const newline = /\r?\n/;
|
|
6
7
|
function parseResponseHeaders(headersString) {
|
|
7
8
|
const headers = Object.create(null);
|
package/dist/store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineSignal, ensureStringId, recordIdentifierFor, constructResource, storeFor } from '@warp-drive/core/store/-private';
|
|
1
|
+
import { defineSignal, assertPrivateStore, ensureStringId, recordIdentifierFor, constructResource, storeFor } from '@warp-drive/core/store/-private';
|
|
2
2
|
import { SkipCache } from '@warp-drive/core/types/request';
|
|
3
3
|
import { i as isMaybeIdentifier } from "./utils-Cqw9eRj5.js";
|
|
4
4
|
import { n as normalizeModelName } from "./util-Dul6TZts.js";
|
|
@@ -37,6 +37,7 @@ function preloadData(store, identifier, preload) {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
const cache = store.cache;
|
|
40
|
+
assertPrivateStore(store);
|
|
40
41
|
const hasRecord = Boolean(store._instanceCache.peek(identifier));
|
|
41
42
|
cache.upsert(identifier, jsonPayload, hasRecord);
|
|
42
43
|
}
|
|
@@ -399,8 +400,9 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
399
400
|
const normalizedId = ensureStringId(id);
|
|
400
401
|
resource = constructResource(type, normalizedId);
|
|
401
402
|
}
|
|
402
|
-
const identifier = this.
|
|
403
|
+
const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resource);
|
|
403
404
|
options = options || {};
|
|
405
|
+
assertPrivateStore(this);
|
|
404
406
|
if (options.preload) {
|
|
405
407
|
// force reload if we preload to ensure we don't resolve the promise
|
|
406
408
|
// until we are complete, else we will end up background-reloading
|
|
@@ -522,8 +524,6 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
522
524
|
});
|
|
523
525
|
return promise.then(document => document.content);
|
|
524
526
|
};
|
|
525
|
-
|
|
526
|
-
// @ts-expect-error RecordReference private store shouldn't matter
|
|
527
527
|
StoreKlass.prototype.getReference = function (resource, id) {
|
|
528
528
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
529
529
|
if (!test) {
|
|
@@ -543,7 +543,8 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
543
543
|
throw new Error('getReference expected to receive either a resource identifier or type and id as arguments');
|
|
544
544
|
}
|
|
545
545
|
})(isMaybeIdentifier(resourceIdentifier)) : {};
|
|
546
|
-
const identifier = this.
|
|
546
|
+
const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);
|
|
547
|
+
assertPrivateStore(this);
|
|
547
548
|
const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;
|
|
548
549
|
let reference = cache.get(identifier);
|
|
549
550
|
if (!reference) {
|
|
@@ -582,7 +583,7 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
582
583
|
if (!test) {
|
|
583
584
|
throw new Error(`Unable to initiate save for a record in a disconnected state`);
|
|
584
585
|
}
|
|
585
|
-
})(storeFor(record)) : {};
|
|
586
|
+
})(storeFor(record, true)) : {};
|
|
586
587
|
const identifier = recordIdentifierFor(record);
|
|
587
588
|
const cache = this.cache;
|
|
588
589
|
if (!identifier) {
|
|
@@ -590,6 +591,7 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
590
591
|
// but just in case we reject here to prevent bad things.
|
|
591
592
|
return Promise.reject(new Error(`Record Is Disconnected`));
|
|
592
593
|
}
|
|
594
|
+
assertPrivateStore(this);
|
|
593
595
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
594
596
|
if (!test) {
|
|
595
597
|
throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
|