@warp-drive-mirror/json-api 5.7.0-alpha.2 → 5.7.0-alpha.4

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.
Files changed (2) hide show
  1. package/dist/index.js +17 -18
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1374,11 +1374,8 @@ class JSONAPICache {
1374
1374
  }
1375
1375
  upgradeCapabilities(this._capabilities);
1376
1376
  const store = this._capabilities._store;
1377
- const attrs = this._capabilities.schema.fields(identifier);
1377
+ const attrs = getCacheFields(this, identifier);
1378
1378
  attrs.forEach((attr, key) => {
1379
- if (attr.kind === 'alias') {
1380
- return;
1381
- }
1382
1379
  if (key in attributes && attributes[key] !== undefined) {
1383
1380
  return;
1384
1381
  }
@@ -1435,7 +1432,7 @@ class JSONAPICache {
1435
1432
  }
1436
1433
  upgradeCapabilities(this._capabilities);
1437
1434
  const store = this._capabilities._store;
1438
- const attrs = this._capabilities.schema.fields(identifier);
1435
+ const attrs = getCacheFields(this, identifier);
1439
1436
  attrs.forEach((attr, key) => {
1440
1437
  if (key in attributes && attributes[key] !== undefined) {
1441
1438
  return;
@@ -1629,8 +1626,7 @@ class JSONAPICache {
1629
1626
  cached.isNew = true;
1630
1627
  const createOptions = {};
1631
1628
  if (options !== undefined) {
1632
- const storeWrapper = this._capabilities;
1633
- const fields = storeWrapper.schema.fields(identifier);
1629
+ const fields = getCacheFields(this, identifier);
1634
1630
  const graph = this.__graph;
1635
1631
  const propertyNames = Object.keys(options);
1636
1632
  for (let i = 0; i < propertyNames.length; i++) {
@@ -1720,7 +1716,7 @@ class JSONAPICache {
1720
1716
  if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
1721
1717
  if (macroCondition(!getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE)) {
1722
1718
  // save off info about saved relationships
1723
- const fields = this._capabilities.schema.fields(identifier);
1719
+ const fields = getCacheFields(this, identifier);
1724
1720
  fields.forEach((schema, name) => {
1725
1721
  if (schema.kind === 'belongsTo') {
1726
1722
  if (this.__graph._isDirty(identifier, name)) {
@@ -1790,7 +1786,7 @@ class JSONAPICache {
1790
1786
  throw error;
1791
1787
  }
1792
1788
  }
1793
- const fields = this._capabilities.schema.fields(identifier);
1789
+ const fields = getCacheFields(this, identifier);
1794
1790
  cached.isNew = false;
1795
1791
  let newCanonicalAttributes;
1796
1792
  if (data) {
@@ -1997,7 +1993,7 @@ class JSONAPICache {
1997
1993
  } else if (cached.defaultAttrs && attribute in cached.defaultAttrs) {
1998
1994
  return cached.defaultAttrs[attribute];
1999
1995
  } else {
2000
- const attrSchema = this._capabilities.schema.fields(identifier).get(attribute);
1996
+ const attrSchema = getCacheFields(this, identifier).get(attribute);
2001
1997
  upgradeCapabilities(this._capabilities);
2002
1998
  const defaultValue = getDefaultValue(attrSchema, identifier, this._capabilities._store);
2003
1999
  if (schemaHasLegacyDefaultValueFn(attrSchema)) {
@@ -2064,7 +2060,7 @@ class JSONAPICache {
2064
2060
  } else if (cached.defaultAttrs && attribute in cached.defaultAttrs) {
2065
2061
  return cached.defaultAttrs[attribute];
2066
2062
  } else {
2067
- const attrSchema = this._capabilities.schema.fields(identifier).get(attribute);
2063
+ const attrSchema = getCacheFields(this, identifier).get(attribute);
2068
2064
  upgradeCapabilities(this._capabilities);
2069
2065
  const defaultValue = getDefaultValue(attrSchema, identifier, this._capabilities._store);
2070
2066
  if (schemaHasLegacyDefaultValueFn(attrSchema)) {
@@ -2719,11 +2715,6 @@ function hasLegacyDefaultValueFn(options) {
2719
2715
  return !!options && typeof options.defaultValue === 'function';
2720
2716
  }
2721
2717
  function getDefaultValue(schema, identifier, store) {
2722
- macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
2723
- if (!test) {
2724
- throw new Error(`AliasFields should not be directly accessed from the cache`);
2725
- }
2726
- })(schema?.kind !== 'alias') : {};
2727
2718
  const options = schema?.options;
2728
2719
  if (!schema || !options && !schema.type) {
2729
2720
  return;
@@ -3055,7 +3046,7 @@ function cacheUpsert(cache, identifier, data, calculateChanges) {
3055
3046
  cache._capabilities.notifyChange(identifier, 'identity', null);
3056
3047
  cache._capabilities.notifyChange(identifier, 'state', null);
3057
3048
  }
3058
- const fields = cache._capabilities.schema.fields(identifier);
3049
+ const fields = getCacheFields(cache, identifier);
3059
3050
 
3060
3051
  // if no cache entry existed, no record exists / property has been accessed
3061
3052
  // and thus we do not need to notify changes to any properties.
@@ -3124,7 +3115,7 @@ function patchCache(Cache, op) {
3124
3115
  {
3125
3116
  if (isRecord) {
3126
3117
  if ('field' in op) {
3127
- const field = Cache._capabilities.schema.fields(op.record).get(op.field);
3118
+ const field = getCacheFields(Cache, op.record).get(op.field);
3128
3119
  macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
3129
3120
  if (!test) {
3130
3121
  throw new Error(`Expected ${op.field} to be a field on ${op.record.type}`);
@@ -3227,5 +3218,13 @@ function patchCache(Cache, op) {
3227
3218
  }
3228
3219
  }
3229
3220
  }
3221
+ function getCacheFields(cache, identifier) {
3222
+ if (cache._capabilities.schema.cacheFields) {
3223
+ return cache._capabilities.schema.cacheFields(identifier);
3224
+ }
3225
+
3226
+ // the model schema service cannot process fields that are not cache fields
3227
+ return cache._capabilities.schema.fields(identifier);
3228
+ }
3230
3229
 
3231
3230
  export { JSONAPICache };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive-mirror/json-api",
3
- "version": "5.7.0-alpha.2",
3
+ "version": "5.7.0-alpha.4",
4
4
  "description": "A {JSON:API} Cache Implementation for WarpDrive",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "peerDependencies": {
35
- "@warp-drive-mirror/core": "5.7.0-alpha.2"
35
+ "@warp-drive-mirror/core": "5.7.0-alpha.4"
36
36
  },
37
37
  "dependencies": {
38
38
  "@embroider/macros": "^1.16.12",
@@ -44,8 +44,8 @@
44
44
  "@babel/plugin-transform-typescript": "^7.27.0",
45
45
  "@babel/preset-typescript": "^7.27.0",
46
46
  "@types/json-to-ast": "^2.1.4",
47
- "@warp-drive/internal-config": "5.7.0-alpha.2",
48
- "@warp-drive-mirror/core": "5.7.0-alpha.2",
47
+ "@warp-drive/internal-config": "5.7.0-alpha.4",
48
+ "@warp-drive-mirror/core": "5.7.0-alpha.4",
49
49
  "decorator-transforms": "^2.3.0",
50
50
  "expect-type": "^1.2.1",
51
51
  "typescript": "^5.8.3",