@warp-drive-mirror/json-api 5.6.0-alpha.12 → 5.6.0-alpha.13
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/-private/cache.d.ts +154 -99
- package/declarations/-private/cache.d.ts.map +1 -1
- package/dist/index.js +177 -111
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -956,26 +956,95 @@ function makeCache() {
|
|
|
956
956
|
}
|
|
957
957
|
|
|
958
958
|
/**
|
|
959
|
-
|
|
959
|
+
* ### JSONAPICache
|
|
960
|
+
*
|
|
961
|
+
* ```ts
|
|
962
|
+
* import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
963
|
+
* ```
|
|
964
|
+
*
|
|
965
|
+
A {@link Cache} implementation tuned for [{json:api}](https://jsonapi.org/)
|
|
966
|
+
|
|
967
|
+
This format excels at simiplifying common complex problems around cache
|
|
968
|
+
consistency and information density. Because most API responses can be quickly
|
|
969
|
+
transformed into {json:api} format without losing any information, WarpDrive
|
|
970
|
+
recommends that most apps use this Cache implementation.
|
|
971
|
+
|
|
972
|
+
If a cache built to understand another format would do better for your app then
|
|
973
|
+
it just needs to follow the same interface.
|
|
974
|
+
|
|
975
|
+
Do you really need a cache? Are sunsets beautiful? Caching is what powers features like
|
|
976
|
+
immutability, mutation management, and allows ***Warp*Drive** to understand your relational
|
|
977
|
+
data.
|
|
978
|
+
|
|
979
|
+
Some caches are simple request/response maps. ***Warp*Drive**'s is not. The Cache deeply
|
|
980
|
+
understands the structure of your data, ensuring your data remains consistent both within
|
|
981
|
+
and across requests.
|
|
982
|
+
|
|
983
|
+
### Installation
|
|
984
|
+
|
|
985
|
+
::: code-group
|
|
960
986
|
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
987
|
+
```sh [pnpm]
|
|
988
|
+
pnpm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
989
|
+
```
|
|
990
|
+
|
|
991
|
+
```sh [npm]
|
|
992
|
+
npm add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
```sh [yarn]
|
|
996
|
+
yarn add -E @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
```sh [bun]
|
|
1000
|
+
bun add --exact @warp-drive-mirror/core@latest @warp-drive-mirror/json-api@latest
|
|
1001
|
+
```
|
|
964
1002
|
|
|
965
|
-
|
|
1003
|
+
:::
|
|
966
1004
|
|
|
967
|
-
|
|
968
|
-
import Cache from '@ember-data-mirror/json-api';
|
|
969
|
-
import Store from '@ember-data-mirror/store';
|
|
1005
|
+
### Setup
|
|
970
1006
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1007
|
+
```ts [services/store.ts]
|
|
1008
|
+
import { Fetch, RequestManager, Store } from '@warp-drive-mirror/core';
|
|
1009
|
+
import {
|
|
1010
|
+
registerDerivations,
|
|
1011
|
+
SchemaService,
|
|
1012
|
+
} from '@warp-drive-mirror/core/reactive';
|
|
1013
|
+
import { CacheHandler } from '@warp-drive-mirror/core/store';
|
|
1014
|
+
import type { CacheCapabilitiesManager } from '@warp-drive-mirror/core/types'; // [!code focus:2]
|
|
1015
|
+
import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
1016
|
+
|
|
1017
|
+
export default class AppStore extends Store {
|
|
1018
|
+
|
|
1019
|
+
requestManager = new RequestManager()
|
|
1020
|
+
.use([Fetch])
|
|
1021
|
+
.useCache(CacheHandler);
|
|
1022
|
+
|
|
1023
|
+
createSchemaService() {
|
|
1024
|
+
const schema = new SchemaService();
|
|
1025
|
+
registerDerivations(schema);
|
|
1026
|
+
return schema;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
createCache(capabilities: CacheCapabilitiesManager) { // [!code focus:3]
|
|
1030
|
+
return new JSONAPICache(capabilities);
|
|
974
1031
|
}
|
|
975
1032
|
}
|
|
976
1033
|
```
|
|
977
1034
|
|
|
978
|
-
|
|
1035
|
+
* @categoryDescription Cache Management
|
|
1036
|
+
* APIs for primary cache management functionality
|
|
1037
|
+
* @categoryDescription Cache Forking
|
|
1038
|
+
* APIs that support Cache Forking
|
|
1039
|
+
* @categoryDescription SSR Support
|
|
1040
|
+
* APIs that support SSR functionality
|
|
1041
|
+
* @categoryDescription Resource Lifecycle
|
|
1042
|
+
* APIs that support management of resource data
|
|
1043
|
+
* @categoryDescription Resource Data
|
|
1044
|
+
* APIs that support granular field level management of resource data
|
|
1045
|
+
* @categoryDescription Resource State
|
|
1046
|
+
* APIs that support managing Resource states
|
|
1047
|
+
|
|
979
1048
|
@public
|
|
980
1049
|
*/
|
|
981
1050
|
|
|
@@ -983,9 +1052,7 @@ class JSONAPICache {
|
|
|
983
1052
|
/**
|
|
984
1053
|
* The Cache Version that this implementation implements.
|
|
985
1054
|
*
|
|
986
|
-
* @type {'2'}
|
|
987
1055
|
* @public
|
|
988
|
-
* @property version
|
|
989
1056
|
*/
|
|
990
1057
|
|
|
991
1058
|
/** @internal */
|
|
@@ -1007,8 +1074,9 @@ class JSONAPICache {
|
|
|
1007
1074
|
this.__documents = new Map();
|
|
1008
1075
|
}
|
|
1009
1076
|
|
|
1010
|
-
|
|
1011
|
-
|
|
1077
|
+
////////// ================ //////////
|
|
1078
|
+
////////// Cache Management //////////
|
|
1079
|
+
////////// ================ //////////
|
|
1012
1080
|
|
|
1013
1081
|
/**
|
|
1014
1082
|
* Cache the response to a request
|
|
@@ -1044,8 +1112,7 @@ class JSONAPICache {
|
|
|
1044
1112
|
* associated resource membership order and contents preserved but linked
|
|
1045
1113
|
* into the cache.
|
|
1046
1114
|
*
|
|
1047
|
-
* @
|
|
1048
|
-
* @return {ResourceDocument}
|
|
1115
|
+
* @category Cache Management
|
|
1049
1116
|
* @public
|
|
1050
1117
|
*/
|
|
1051
1118
|
|
|
@@ -1193,9 +1260,9 @@ class JSONAPICache {
|
|
|
1193
1260
|
* Update the "remote" or "canonical" (persisted) state of the Cache
|
|
1194
1261
|
* by merging new information into the existing state.
|
|
1195
1262
|
*
|
|
1263
|
+
* @category Cache Management
|
|
1196
1264
|
* @public
|
|
1197
|
-
* @param
|
|
1198
|
-
* @return {void}
|
|
1265
|
+
* @param op the operation or list of operations to perform
|
|
1199
1266
|
*/
|
|
1200
1267
|
patch(op) {
|
|
1201
1268
|
if (Array.isArray(op)) {
|
|
@@ -1224,8 +1291,7 @@ class JSONAPICache {
|
|
|
1224
1291
|
/**
|
|
1225
1292
|
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
1226
1293
|
*
|
|
1227
|
-
* @
|
|
1228
|
-
* @return {void}
|
|
1294
|
+
* @category Cache Management
|
|
1229
1295
|
* @public
|
|
1230
1296
|
*/
|
|
1231
1297
|
mutate(mutation) {
|
|
@@ -1278,9 +1344,8 @@ class JSONAPICache {
|
|
|
1278
1344
|
* of the Graph handling necessary entanglements and
|
|
1279
1345
|
* notifications for relational data.
|
|
1280
1346
|
*
|
|
1347
|
+
* @category Cache Management
|
|
1281
1348
|
* @public
|
|
1282
|
-
* @param {StableRecordIdentifier | StableDocumentIdentifier} identifier
|
|
1283
|
-
* @return {ResourceDocument | ResourceObject | null} the known resource data
|
|
1284
1349
|
*/
|
|
1285
1350
|
|
|
1286
1351
|
peek(identifier) {
|
|
@@ -1336,6 +1401,14 @@ class JSONAPICache {
|
|
|
1336
1401
|
}
|
|
1337
1402
|
return null;
|
|
1338
1403
|
}
|
|
1404
|
+
|
|
1405
|
+
/**
|
|
1406
|
+
* Peek the remote resource data from the Cache.
|
|
1407
|
+
*
|
|
1408
|
+
* @category Cache Management
|
|
1409
|
+
* @public
|
|
1410
|
+
*/
|
|
1411
|
+
|
|
1339
1412
|
peekRemoteState(identifier) {
|
|
1340
1413
|
if ('type' in identifier) {
|
|
1341
1414
|
const peeked = this.__safePeek(identifier, false);
|
|
@@ -1386,6 +1459,7 @@ class JSONAPICache {
|
|
|
1386
1459
|
}
|
|
1387
1460
|
return null;
|
|
1388
1461
|
}
|
|
1462
|
+
|
|
1389
1463
|
/**
|
|
1390
1464
|
* Peek the Cache for the existing request data associated with
|
|
1391
1465
|
* a cacheable request.
|
|
@@ -1394,8 +1468,7 @@ class JSONAPICache {
|
|
|
1394
1468
|
* that it will return the the request, response, and content
|
|
1395
1469
|
* whereas `peek` will return just the `content`.
|
|
1396
1470
|
*
|
|
1397
|
-
* @
|
|
1398
|
-
* @return {StructuredDocument<ResourceDocument> | null}
|
|
1471
|
+
* @category Cache Management
|
|
1399
1472
|
* @public
|
|
1400
1473
|
*/
|
|
1401
1474
|
peekRequest(identifier) {
|
|
@@ -1405,11 +1478,9 @@ class JSONAPICache {
|
|
|
1405
1478
|
/**
|
|
1406
1479
|
* Push resource data from a remote source into the cache for this identifier
|
|
1407
1480
|
*
|
|
1481
|
+
* @category Cache Management
|
|
1408
1482
|
* @public
|
|
1409
|
-
* @
|
|
1410
|
-
* @param data
|
|
1411
|
-
* @param hasRecord
|
|
1412
|
-
* @return {void | string[]} if `hasRecord` is true then calculated key changes should be returned
|
|
1483
|
+
* @return if `calculateChanges` is true then calculated key changes should be returned
|
|
1413
1484
|
*/
|
|
1414
1485
|
upsert(identifier, data, calculateChanges) {
|
|
1415
1486
|
upgradeCapabilities(this._capabilities);
|
|
@@ -1424,8 +1495,9 @@ class JSONAPICache {
|
|
|
1424
1495
|
return cacheUpsert(this, identifier, data, calculateChanges);
|
|
1425
1496
|
}
|
|
1426
1497
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1498
|
+
////////// ============= //////////
|
|
1499
|
+
////////// Cache Forking //////////
|
|
1500
|
+
////////// ============= //////////
|
|
1429
1501
|
|
|
1430
1502
|
/**
|
|
1431
1503
|
* Create a fork of the cache from the current state.
|
|
@@ -1434,8 +1506,8 @@ class JSONAPICache {
|
|
|
1434
1506
|
* preferring instead to fork at the Store level, which will
|
|
1435
1507
|
* utilize this method to fork the cache.
|
|
1436
1508
|
*
|
|
1509
|
+
* @category Cache Forking
|
|
1437
1510
|
* @internal
|
|
1438
|
-
* @return {Promise<Cache>}
|
|
1439
1511
|
*/
|
|
1440
1512
|
fork() {
|
|
1441
1513
|
throw new Error(`Not Implemented`);
|
|
@@ -1448,11 +1520,10 @@ class JSONAPICache {
|
|
|
1448
1520
|
* preferring instead to merge at the Store level, which will
|
|
1449
1521
|
* utilize this method to merge the caches.
|
|
1450
1522
|
*
|
|
1451
|
-
* @
|
|
1452
|
-
* @
|
|
1453
|
-
* @return {Promise<void>}
|
|
1523
|
+
* @category Cache Forking
|
|
1524
|
+
* @internal
|
|
1454
1525
|
*/
|
|
1455
|
-
merge(
|
|
1526
|
+
merge(_cache) {
|
|
1456
1527
|
throw new Error(`Not Implemented`);
|
|
1457
1528
|
}
|
|
1458
1529
|
|
|
@@ -1486,22 +1557,24 @@ class JSONAPICache {
|
|
|
1486
1557
|
* }
|
|
1487
1558
|
* ```
|
|
1488
1559
|
*
|
|
1489
|
-
* @
|
|
1560
|
+
* @category Cache Forking
|
|
1561
|
+
* @internal
|
|
1490
1562
|
*/
|
|
1491
1563
|
diff() {
|
|
1492
1564
|
throw new Error(`Not Implemented`);
|
|
1493
1565
|
}
|
|
1494
1566
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1567
|
+
////////// =========== //////////
|
|
1568
|
+
////////// SSR Support //////////
|
|
1569
|
+
////////// =========== //////////
|
|
1497
1570
|
|
|
1498
1571
|
/**
|
|
1499
1572
|
* Serialize the entire contents of the Cache into a Stream
|
|
1500
1573
|
* which may be fed back into a new instance of the same Cache
|
|
1501
1574
|
* via `cache.hydrate`.
|
|
1502
1575
|
*
|
|
1503
|
-
* @
|
|
1504
|
-
* @
|
|
1576
|
+
* @category SSR Support
|
|
1577
|
+
* @internal
|
|
1505
1578
|
*/
|
|
1506
1579
|
dump() {
|
|
1507
1580
|
throw new Error(`Not Implemented`);
|
|
@@ -1519,16 +1592,16 @@ class JSONAPICache {
|
|
|
1519
1592
|
* behavior supports optimizing pre/fetching of data for route transitions
|
|
1520
1593
|
* via data-only SSR modes.
|
|
1521
1594
|
*
|
|
1522
|
-
* @
|
|
1523
|
-
* @
|
|
1524
|
-
* @public
|
|
1595
|
+
* @category SSR Support
|
|
1596
|
+
* @internal
|
|
1525
1597
|
*/
|
|
1526
1598
|
hydrate(stream) {
|
|
1527
1599
|
throw new Error('Not Implemented');
|
|
1528
1600
|
}
|
|
1529
1601
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1602
|
+
////////// ================== //////////
|
|
1603
|
+
////////// Resource Lifecycle //////////
|
|
1604
|
+
////////// ================== //////////
|
|
1532
1605
|
|
|
1533
1606
|
/**
|
|
1534
1607
|
* [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
|
|
@@ -1536,9 +1609,8 @@ class JSONAPICache {
|
|
|
1536
1609
|
* It returns properties from options that should be set on the record during the create
|
|
1537
1610
|
* process. This return value behavior is deprecated.
|
|
1538
1611
|
*
|
|
1612
|
+
* @category Resource Lifecycle
|
|
1539
1613
|
* @public
|
|
1540
|
-
* @param identifier
|
|
1541
|
-
* @param createArgs
|
|
1542
1614
|
*/
|
|
1543
1615
|
clientDidCreate(identifier, options) {
|
|
1544
1616
|
if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_CACHE)) {
|
|
@@ -1611,8 +1683,8 @@ class JSONAPICache {
|
|
|
1611
1683
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
1612
1684
|
* will be part of a save transaction.
|
|
1613
1685
|
*
|
|
1686
|
+
* @category Resource Lifecycle
|
|
1614
1687
|
* @public
|
|
1615
|
-
* @param identifier
|
|
1616
1688
|
*/
|
|
1617
1689
|
willCommit(identifier) {
|
|
1618
1690
|
const cached = this.__peek(identifier, false);
|
|
@@ -1666,9 +1738,8 @@ class JSONAPICache {
|
|
|
1666
1738
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
1667
1739
|
* was successfully updated as part of a save transaction.
|
|
1668
1740
|
*
|
|
1741
|
+
* @category Resource Lifecycle
|
|
1669
1742
|
* @public
|
|
1670
|
-
* @param identifier
|
|
1671
|
-
* @param data
|
|
1672
1743
|
*/
|
|
1673
1744
|
didCommit(committedIdentifier, result) {
|
|
1674
1745
|
const payload = result.content;
|
|
@@ -1788,9 +1859,8 @@ class JSONAPICache {
|
|
|
1788
1859
|
* [LIFECYCLE] Signals to the cache that a resource
|
|
1789
1860
|
* was update via a save transaction failed.
|
|
1790
1861
|
*
|
|
1862
|
+
* @category Resource Lifecycle
|
|
1791
1863
|
* @public
|
|
1792
|
-
* @param identifier
|
|
1793
|
-
* @param errors
|
|
1794
1864
|
*/
|
|
1795
1865
|
commitWasRejected(identifier, errors) {
|
|
1796
1866
|
const cached = this.__peek(identifier, false);
|
|
@@ -1818,8 +1888,8 @@ class JSONAPICache {
|
|
|
1818
1888
|
*
|
|
1819
1889
|
* This method is a candidate to become a mutation
|
|
1820
1890
|
*
|
|
1891
|
+
* @category Resource Lifecycle
|
|
1821
1892
|
* @public
|
|
1822
|
-
* @param identifier
|
|
1823
1893
|
*/
|
|
1824
1894
|
unloadRecord(identifier) {
|
|
1825
1895
|
const storeWrapper = this._capabilities;
|
|
@@ -1888,16 +1958,16 @@ class JSONAPICache {
|
|
|
1888
1958
|
}
|
|
1889
1959
|
}
|
|
1890
1960
|
|
|
1891
|
-
|
|
1892
|
-
|
|
1961
|
+
////////// ============= //////////
|
|
1962
|
+
////////// Resource Data //////////
|
|
1963
|
+
////////// ============= //////////
|
|
1893
1964
|
|
|
1894
1965
|
/**
|
|
1895
1966
|
* Retrieve the data for an attribute from the cache
|
|
1967
|
+
* with local mutations applied.
|
|
1896
1968
|
*
|
|
1969
|
+
* @category Resource Data
|
|
1897
1970
|
* @public
|
|
1898
|
-
* @param identifier
|
|
1899
|
-
* @param field
|
|
1900
|
-
* @return {unknown}
|
|
1901
1971
|
*/
|
|
1902
1972
|
getAttr(identifier, attr) {
|
|
1903
1973
|
const isSimplePath = !Array.isArray(attr) || attr.length === 1;
|
|
@@ -1961,6 +2031,13 @@ class JSONAPICache {
|
|
|
1961
2031
|
}
|
|
1962
2032
|
return current;
|
|
1963
2033
|
}
|
|
2034
|
+
|
|
2035
|
+
/**
|
|
2036
|
+
* Retrieve the remote data for an attribute from the cache
|
|
2037
|
+
*
|
|
2038
|
+
* @category Resource Data
|
|
2039
|
+
* @public
|
|
2040
|
+
*/
|
|
1964
2041
|
getRemoteAttr(identifier, attr) {
|
|
1965
2042
|
const isSimplePath = !Array.isArray(attr) || attr.length === 1;
|
|
1966
2043
|
if (Array.isArray(attr) && attr.length === 1) {
|
|
@@ -2021,10 +2098,8 @@ class JSONAPICache {
|
|
|
2021
2098
|
*
|
|
2022
2099
|
* This method is a candidate to become a mutation
|
|
2023
2100
|
*
|
|
2101
|
+
* @category Resource Data
|
|
2024
2102
|
* @public
|
|
2025
|
-
* @param identifier
|
|
2026
|
-
* @param field
|
|
2027
|
-
* @param value
|
|
2028
2103
|
*/
|
|
2029
2104
|
setAttr(identifier, attr, value) {
|
|
2030
2105
|
// this assert works to ensure we have a non-empty string and/or a non-empty array
|
|
@@ -2120,9 +2195,9 @@ class JSONAPICache {
|
|
|
2120
2195
|
/**
|
|
2121
2196
|
* Query the cache for the changed attributes of a resource.
|
|
2122
2197
|
*
|
|
2198
|
+
* @category Resource Data
|
|
2123
2199
|
* @public
|
|
2124
|
-
* @
|
|
2125
|
-
* @return {ChangedAttributesHash} `{ <field>: [<old>, <new>] }`
|
|
2200
|
+
* @return `{ '<field>': ['<old>', '<new>'] }`
|
|
2126
2201
|
*/
|
|
2127
2202
|
changedAttrs(identifier) {
|
|
2128
2203
|
const cached = this.__peek(identifier, false);
|
|
@@ -2145,9 +2220,8 @@ class JSONAPICache {
|
|
|
2145
2220
|
/**
|
|
2146
2221
|
* Query the cache for whether any mutated attributes exist
|
|
2147
2222
|
*
|
|
2223
|
+
* @category Resource Data
|
|
2148
2224
|
* @public
|
|
2149
|
-
* @param identifier
|
|
2150
|
-
* @return {Boolean}
|
|
2151
2225
|
*/
|
|
2152
2226
|
hasChangedAttrs(identifier) {
|
|
2153
2227
|
const cached = this.__peek(identifier, true);
|
|
@@ -2170,9 +2244,9 @@ class JSONAPICache {
|
|
|
2170
2244
|
*
|
|
2171
2245
|
* This method is a candidate to become a mutation
|
|
2172
2246
|
*
|
|
2247
|
+
* @category Resource Data
|
|
2173
2248
|
* @public
|
|
2174
|
-
* @
|
|
2175
|
-
* @return {String[]} the names of fields that were restored
|
|
2249
|
+
* @return the names of fields that were restored
|
|
2176
2250
|
*/
|
|
2177
2251
|
rollbackAttrs(identifier) {
|
|
2178
2252
|
const cached = this.__peek(identifier, false);
|
|
@@ -2203,31 +2277,30 @@ class JSONAPICache {
|
|
|
2203
2277
|
}
|
|
2204
2278
|
|
|
2205
2279
|
/**
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2280
|
+
* Query the cache for the changes to relationships of a resource.
|
|
2281
|
+
*
|
|
2282
|
+
* Returns a map of relationship names to RelationshipDiff objects.
|
|
2283
|
+
*
|
|
2284
|
+
* ```ts
|
|
2285
|
+
* type RelationshipDiff =
|
|
2286
|
+
| {
|
|
2213
2287
|
kind: 'collection';
|
|
2214
2288
|
remoteState: StableRecordIdentifier[];
|
|
2215
2289
|
additions: Set<StableRecordIdentifier>;
|
|
2216
2290
|
removals: Set<StableRecordIdentifier>;
|
|
2217
2291
|
localState: StableRecordIdentifier[];
|
|
2218
2292
|
reordered: boolean;
|
|
2219
|
-
|
|
2220
|
-
|
|
2293
|
+
}
|
|
2294
|
+
| {
|
|
2221
2295
|
kind: 'resource';
|
|
2222
2296
|
remoteState: StableRecordIdentifier | null;
|
|
2223
2297
|
localState: StableRecordIdentifier | null;
|
|
2224
2298
|
};
|
|
2225
2299
|
```
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
*/
|
|
2300
|
+
*
|
|
2301
|
+
* @category Resource Data
|
|
2302
|
+
* @public
|
|
2303
|
+
*/
|
|
2231
2304
|
changedRelationships(identifier) {
|
|
2232
2305
|
return this.__graph.getChanged(identifier);
|
|
2233
2306
|
}
|
|
@@ -2235,9 +2308,8 @@ class JSONAPICache {
|
|
|
2235
2308
|
/**
|
|
2236
2309
|
* Query the cache for whether any mutated relationships exist
|
|
2237
2310
|
*
|
|
2311
|
+
* @category Resource Data
|
|
2238
2312
|
* @public
|
|
2239
|
-
* @param {StableRecordIdentifier} identifier
|
|
2240
|
-
* @return {Boolean}
|
|
2241
2313
|
*/
|
|
2242
2314
|
hasChangedRelationships(identifier) {
|
|
2243
2315
|
return this.__graph.hasChanged(identifier);
|
|
@@ -2250,9 +2322,9 @@ class JSONAPICache {
|
|
|
2250
2322
|
*
|
|
2251
2323
|
* This method is a candidate to become a mutation
|
|
2252
2324
|
*
|
|
2325
|
+
* @category Resource Data
|
|
2253
2326
|
* @public
|
|
2254
|
-
* @
|
|
2255
|
-
* @return {String[]} the names of relationships that were restored
|
|
2327
|
+
* @return the names of relationships that were restored
|
|
2256
2328
|
*/
|
|
2257
2329
|
rollbackRelationships(identifier) {
|
|
2258
2330
|
upgradeCapabilities(this._capabilities);
|
|
@@ -2266,20 +2338,28 @@ class JSONAPICache {
|
|
|
2266
2338
|
/**
|
|
2267
2339
|
* Query the cache for the current state of a relationship property
|
|
2268
2340
|
*
|
|
2341
|
+
* @category Resource Data
|
|
2269
2342
|
* @public
|
|
2270
|
-
* @param identifier
|
|
2271
|
-
* @param field
|
|
2272
2343
|
* @return resource relationship object
|
|
2273
2344
|
*/
|
|
2274
2345
|
getRelationship(identifier, field) {
|
|
2275
2346
|
return this.__graph.getData(identifier, field);
|
|
2276
2347
|
}
|
|
2348
|
+
|
|
2349
|
+
/**
|
|
2350
|
+
* Query the cache for the remote state of a relationship property
|
|
2351
|
+
*
|
|
2352
|
+
* @category Resource Data
|
|
2353
|
+
* @public
|
|
2354
|
+
* @return resource relationship object
|
|
2355
|
+
*/
|
|
2277
2356
|
getRemoteRelationship(identifier, field) {
|
|
2278
2357
|
return this.__graph.getRemoteData(identifier, field);
|
|
2279
2358
|
}
|
|
2280
2359
|
|
|
2281
|
-
|
|
2282
|
-
|
|
2360
|
+
////////// ============== //////////
|
|
2361
|
+
////////// Resource State //////////
|
|
2362
|
+
////////// ============== //////////
|
|
2283
2363
|
|
|
2284
2364
|
/**
|
|
2285
2365
|
* Update the cache state for the given resource to be marked
|
|
@@ -2287,9 +2367,8 @@ class JSONAPICache {
|
|
|
2287
2367
|
*
|
|
2288
2368
|
* This method is a candidate to become a mutation
|
|
2289
2369
|
*
|
|
2370
|
+
* @category Resource State
|
|
2290
2371
|
* @public
|
|
2291
|
-
* @param identifier
|
|
2292
|
-
* @param {Boolean} isDeleted
|
|
2293
2372
|
*/
|
|
2294
2373
|
setIsDeleted(identifier, isDeleted) {
|
|
2295
2374
|
const cached = this.__peek(identifier, false);
|
|
@@ -2301,9 +2380,8 @@ class JSONAPICache {
|
|
|
2301
2380
|
/**
|
|
2302
2381
|
* Query the cache for any validation errors applicable to the given resource.
|
|
2303
2382
|
*
|
|
2383
|
+
* @category Resource State
|
|
2304
2384
|
* @public
|
|
2305
|
-
* @param identifier
|
|
2306
|
-
* @return {JsonApiError[]}
|
|
2307
2385
|
*/
|
|
2308
2386
|
getErrors(identifier) {
|
|
2309
2387
|
return this.__peek(identifier, true).errors || [];
|
|
@@ -2312,9 +2390,8 @@ class JSONAPICache {
|
|
|
2312
2390
|
/**
|
|
2313
2391
|
* Query the cache for whether a given resource has any available data
|
|
2314
2392
|
*
|
|
2393
|
+
* @category Resource State
|
|
2315
2394
|
* @public
|
|
2316
|
-
* @param identifier
|
|
2317
|
-
* @return {Boolean}
|
|
2318
2395
|
*/
|
|
2319
2396
|
isEmpty(identifier) {
|
|
2320
2397
|
const cached = this.__safePeek(identifier, true);
|
|
@@ -2325,9 +2402,8 @@ class JSONAPICache {
|
|
|
2325
2402
|
* Query the cache for whether a given resource was created locally and not
|
|
2326
2403
|
* yet persisted.
|
|
2327
2404
|
*
|
|
2405
|
+
* @category Resource State
|
|
2328
2406
|
* @public
|
|
2329
|
-
* @param identifier
|
|
2330
|
-
* @return {Boolean}
|
|
2331
2407
|
*/
|
|
2332
2408
|
isNew(identifier) {
|
|
2333
2409
|
// TODO can we assert here?
|
|
@@ -2338,9 +2414,8 @@ class JSONAPICache {
|
|
|
2338
2414
|
* Query the cache for whether a given resource is marked as deleted (but not
|
|
2339
2415
|
* necessarily persisted yet).
|
|
2340
2416
|
*
|
|
2417
|
+
* @category Resource State
|
|
2341
2418
|
* @public
|
|
2342
|
-
* @param identifier
|
|
2343
|
-
* @return {Boolean}
|
|
2344
2419
|
*/
|
|
2345
2420
|
isDeleted(identifier) {
|
|
2346
2421
|
// TODO can we assert here?
|
|
@@ -2351,9 +2426,8 @@ class JSONAPICache {
|
|
|
2351
2426
|
* Query the cache for whether a given resource has been deleted and that deletion
|
|
2352
2427
|
* has also been persisted.
|
|
2353
2428
|
*
|
|
2429
|
+
* @category Resource State
|
|
2354
2430
|
* @public
|
|
2355
|
-
* @param identifier
|
|
2356
|
-
* @return {Boolean}
|
|
2357
2431
|
*/
|
|
2358
2432
|
isDeletionCommitted(identifier) {
|
|
2359
2433
|
// TODO can we assert here?
|
|
@@ -2364,8 +2438,6 @@ class JSONAPICache {
|
|
|
2364
2438
|
* Private method used to populate an entry for the identifier
|
|
2365
2439
|
*
|
|
2366
2440
|
* @internal
|
|
2367
|
-
* @param {StableRecordIdentifier} identifier
|
|
2368
|
-
* @return {CachedResource}
|
|
2369
2441
|
*/
|
|
2370
2442
|
_createCache(identifier) {
|
|
2371
2443
|
macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
|
|
@@ -2382,10 +2454,7 @@ class JSONAPICache {
|
|
|
2382
2454
|
* Peek whether we have cached resource data matching the identifier
|
|
2383
2455
|
* without asserting if the resource data is missing.
|
|
2384
2456
|
*
|
|
2385
|
-
* @param {StableRecordIdentifier} identifier
|
|
2386
|
-
* @param {Boolean} allowDestroyed
|
|
2387
2457
|
* @internal
|
|
2388
|
-
* @return {CachedResource | undefined}
|
|
2389
2458
|
*/
|
|
2390
2459
|
__safePeek(identifier, allowDestroyed) {
|
|
2391
2460
|
let resource = this.__cache.get(identifier);
|
|
@@ -2399,10 +2468,7 @@ class JSONAPICache {
|
|
|
2399
2468
|
* Peek whether we have cached resource data matching the identifier
|
|
2400
2469
|
* Asserts if the resource data is missing.
|
|
2401
2470
|
*
|
|
2402
|
-
* @param {StableRecordIdentifier} identifier
|
|
2403
|
-
* @param {Boolean} allowDestroyed
|
|
2404
2471
|
* @internal
|
|
2405
|
-
* @return {CachedResource}
|
|
2406
2472
|
*/
|
|
2407
2473
|
__peek(identifier, allowDestroyed) {
|
|
2408
2474
|
const resource = this.__safePeek(identifier, allowDestroyed);
|