@warp-drive/core 5.8.0-alpha.7 → 5.8.0-alpha.8

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.
@@ -6,7 +6,7 @@ import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
6
6
  import { CacheCapabilitiesManager } from "../managers/cache-capabilities-manager.js";
7
7
  import type { CacheManager } from "../managers/cache-manager.js";
8
8
  import type { CreateRecordProperties, Store } from "../store-service.js";
9
- export declare function peekRecordIdentifier(record: OpaqueRecordInstance): ResourceKey | undefined;
9
+ export declare function peekResourceKey(record: OpaqueRecordInstance): ResourceKey | undefined;
10
10
  /**
11
11
  Retrieves the unique referentially-stable {@link ResourceKey}
12
12
  assigned to the given record instance.
@@ -1,5 +1,5 @@
1
1
  import { type PersistedResourceKey, type RequestKey, type ResourceKey } from "../../../types/identifier.js";
2
- import type { ImmutableRequestInfo } from "../../../types/request.js";
2
+ import type { RequestInfo } from "../../../types/request.js";
3
3
  import type { ExistingResourceIdentifierObject, ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
4
4
  import type { ForgetMethod, GenerationMethod, KeyInfo, KeyInfoMethod, ResetMethod, UpdateMethod } from "../../-types/q/identifier.js";
5
5
  type TypeFromIdentifier<T> = T extends {
@@ -197,16 +197,34 @@ export declare class CacheKeyManager {
197
197
  *
198
198
  * @private
199
199
  */
200
- peekRecordIdentifier(resource: ResourceIdentifierObject): ResourceKey | undefined;
200
+ peekResourceKey(resource: ResourceIdentifierObject): ResourceKey | undefined;
201
201
  /**
202
- Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
203
- Returns `null` if the request does not have a `cacheKey` or `url`.
204
-
205
- @public
202
+ * Peeks the {@link RequestKey} for the given {@link RequestInfo}, but will not
203
+ * create one if none has been previously generated.
204
+ *
205
+ * @public
206
+ */
207
+ peekRequestKey(request: RequestInfo): RequestKey | null;
208
+ /**
209
+ * Returns the {@link RequestKey} for the given {@link RequestInfo} if the request is
210
+ * considered cacheable. For cacheable requests, this method will create
211
+ * a RequestKey if none is found.
212
+ *
213
+ * A `null` response indicates the request cannot/will not be cached,
214
+ * generally this means either
215
+ *
216
+ * - {@link RequestInfo.cacheOptions.key} is not present on the `RequestInfo`
217
+ * - the request's method is `GET` but it has no `url`
218
+ *
219
+ * Generally you should not seek to cache requests that are not idempotent
220
+ * or have side effects, such as mutations that create, update or delete
221
+ * a resource.
222
+ *
223
+ * @public
206
224
  */
207
- getOrCreateDocumentIdentifier(request: ImmutableRequestInfo): RequestKey | null;
225
+ getOrCreateDocumentIdentifier(request: RequestInfo): RequestKey | null;
208
226
  /**
209
- Returns the Identifier for the given Resource, creates one if it does not yet exist.
227
+ Returns the {@link ResourceKey} for the given Resource, creates one if it does not yet exist.
210
228
 
211
229
  Specifically this means that we:
212
230
 
@@ -1307,15 +1307,45 @@ class CacheKeyManager {
1307
1307
  *
1308
1308
  * @private
1309
1309
  */
1310
- peekRecordIdentifier(resource) {
1310
+ peekResourceKey(resource) {
1311
1311
  return this._getRecordIdentifier(resource, 0);
1312
1312
  }
1313
1313
 
1314
1314
  /**
1315
- Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
1316
- Returns `null` if the request does not have a `cacheKey` or `url`.
1317
- @public
1318
- */
1315
+ * Peeks the {@link RequestKey} for the given {@link RequestInfo}, but will not
1316
+ * create one if none has been previously generated.
1317
+ *
1318
+ * @public
1319
+ */
1320
+ peekRequestKey(request) {
1321
+ let cacheKey = request.cacheOptions?.key;
1322
+ if (!cacheKey) {
1323
+ cacheKey = this._generate(request, 'document');
1324
+ }
1325
+ if (!cacheKey) {
1326
+ return null;
1327
+ }
1328
+ const identifier = this._cache.documents.get(cacheKey);
1329
+ return identifier ?? null;
1330
+ }
1331
+
1332
+ /**
1333
+ * Returns the {@link RequestKey} for the given {@link RequestInfo} if the request is
1334
+ * considered cacheable. For cacheable requests, this method will create
1335
+ * a RequestKey if none is found.
1336
+ *
1337
+ * A `null` response indicates the request cannot/will not be cached,
1338
+ * generally this means either
1339
+ *
1340
+ * - {@link RequestInfo.cacheOptions.key} is not present on the `RequestInfo`
1341
+ * - the request's method is `GET` but it has no `url`
1342
+ *
1343
+ * Generally you should not seek to cache requests that are not idempotent
1344
+ * or have side effects, such as mutations that create, update or delete
1345
+ * a resource.
1346
+ *
1347
+ * @public
1348
+ */
1319
1349
  getOrCreateDocumentIdentifier(request) {
1320
1350
  let cacheKey = request.cacheOptions?.key;
1321
1351
  if (!cacheKey) {
@@ -1340,7 +1370,7 @@ class CacheKeyManager {
1340
1370
  }
1341
1371
 
1342
1372
  /**
1343
- Returns the Identifier for the given Resource, creates one if it does not yet exist.
1373
+ Returns the {@link ResourceKey} for the given Resource, creates one if it does not yet exist.
1344
1374
  Specifically this means that we:
1345
1375
  - validate the `id` `type` and `lid` combo against known identifiers
1346
1376
  - return an object with an `lid` that is stable (repeated calls with the same
@@ -1845,7 +1875,7 @@ function isDestroyable(record) {
1845
1875
  return Boolean(record && typeof record === 'object' && typeof record.destroy === 'function');
1846
1876
  }
1847
1877
  const RecordCache = getOrSetGlobal('RecordCache', new Map());
1848
- function peekRecordIdentifier(record) {
1878
+ function peekResourceKey(record) {
1849
1879
  return RecordCache.get(record);
1850
1880
  }
1851
1881
 
@@ -2111,7 +2141,7 @@ class InstanceCache {
2111
2141
  console.log(`InstanceCache: updating id to '${id}' for record ${String(identifier)}`);
2112
2142
  }
2113
2143
  }
2114
- const existingIdentifier = this.store.cacheKeyManager.peekRecordIdentifier({
2144
+ const existingIdentifier = this.store.cacheKeyManager.peekResourceKey({
2115
2145
  type,
2116
2146
  id
2117
2147
  });
@@ -5102,7 +5132,7 @@ class Store extends BaseClass {
5102
5132
  id
5103
5133
  };
5104
5134
  if (resource.id) {
5105
- const identifier = this.cacheKeyManager.peekRecordIdentifier(resource);
5135
+ const identifier = this.cacheKeyManager.peekResourceKey(resource);
5106
5136
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5107
5137
  if (!test) {
5108
5138
  throw new Error(`The id ${String(properties.id)} has already been used with another '${normalizedModelName}' record.`);
@@ -5110,7 +5140,7 @@ class Store extends BaseClass {
5110
5140
  })(!identifier) : {};
5111
5141
  }
5112
5142
  if (context?.lid) {
5113
- const identifier = this.cacheKeyManager.peekRecordIdentifier({
5143
+ const identifier = this.cacheKeyManager.peekResourceKey({
5114
5144
  lid: context?.lid
5115
5145
  });
5116
5146
  resource.lid = context.lid;
@@ -5145,7 +5175,7 @@ class Store extends BaseClass {
5145
5175
  if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5146
5176
  assertDestroyingStore(this, 'deleteRecord');
5147
5177
  }
5148
- const identifier = peekRecordIdentifier(record);
5178
+ const identifier = peekResourceKey(record);
5149
5179
  const cache = this.cache;
5150
5180
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
5151
5181
  if (!test) {
@@ -5175,7 +5205,7 @@ class Store extends BaseClass {
5175
5205
  if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
5176
5206
  assertDestroyingStore(this, 'unloadRecord');
5177
5207
  }
5178
- const identifier = peekRecordIdentifier(record);
5208
+ const identifier = peekResourceKey(record);
5179
5209
  if (identifier) {
5180
5210
  this._instanceCache.unloadRecord(identifier);
5181
5211
  }
@@ -5214,7 +5244,7 @@ class Store extends BaseClass {
5214
5244
 
5215
5245
  peekRecord(identifier, id) {
5216
5246
  if (arguments.length === 1 && isMaybeIdentifier(identifier)) {
5217
- const stableIdentifier = this.cacheKeyManager.peekRecordIdentifier(identifier);
5247
+ const stableIdentifier = this.cacheKeyManager.peekResourceKey(identifier);
5218
5248
  const isLoaded = stableIdentifier && this._instanceCache.recordIsLoaded(stableIdentifier);
5219
5249
  // TODO come up with a better mechanism for determining if we have data and could peek.
5220
5250
  // this is basically an "are we not empty" query.
@@ -5239,7 +5269,7 @@ class Store extends BaseClass {
5239
5269
  type,
5240
5270
  id: normalizedId
5241
5271
  };
5242
- const stableIdentifier = this.cacheKeyManager.peekRecordIdentifier(resource);
5272
+ const stableIdentifier = this.cacheKeyManager.peekResourceKey(resource);
5243
5273
  const isLoaded = stableIdentifier && this._instanceCache.recordIsLoaded(stableIdentifier);
5244
5274
  return isLoaded ? this._instanceCache.getRecord(stableIdentifier) : null;
5245
5275
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheHandler, V as Fetch, W as RequestManager, S as Store, r as recordIdentifierFor, $ as setIdentifierForgetMethod, Y as setIdentifierGenerationMethod, a0 as setIdentifierResetMethod, Z as setIdentifierUpdateMethod, a1 as setKeyInfoForResource, s as storeFor, X as useRecommendedStore } from "./index-BMCk_UD5.js";
1
+ export { C as CacheHandler, V as Fetch, W as RequestManager, S as Store, r as recordIdentifierFor, $ as setIdentifierForgetMethod, Y as setIdentifierGenerationMethod, a0 as setIdentifierResetMethod, Z as setIdentifierUpdateMethod, a1 as setKeyInfoForResource, s as storeFor, X as useRecommendedStore } from "./index-CKXq9_RZ.js";
2
2
  import "./symbols-sql1_mdx.js";
3
3
  import '@ember/debug';
4
4
  import '@embroider/macros';
package/dist/reactive.js CHANGED
@@ -1,4 +1,4 @@
1
- export { O as SchemaService, L as checkout, U as commit, q as createRequestSubscription, Q as fromIdentity, p as getPromiseState, t as getRequestState, M as instantiateRecord, T as registerDerivations, N as teardownRecord, P as withDefaults } from "./index-BMCk_UD5.js";
1
+ export { O as SchemaService, L as checkout, U as commit, q as createRequestSubscription, Q as fromIdentity, p as getPromiseState, t as getRequestState, M as instantiateRecord, T as registerDerivations, N as teardownRecord, P as withDefaults } from "./index-CKXq9_RZ.js";
2
2
  export { a as Checkout } from "./symbols-sql1_mdx.js";
3
3
  import './types/request.js';
4
4
  import '@embroider/macros';
@@ -1,2 +1,2 @@
1
- export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager, E as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, J as consumeInternalSignal, G as createInternalMemo, l as createLegacyManyArray, q as createRequestSubscription, A as defineGate, B as defineNonEnumerableSignal, z as defineSignal, e as ensureStringId, y as entangleInitiallyStaleSignal, x as entangleSignal, f as fastPush, w as gate, K as getOrCreateInternalSignal, p as getPromiseState, t as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, v as memoized, I as notifyInternalSignal, F as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, u as signal, s as storeFor, H as withSignalStore } from "../index-BMCk_UD5.js";
1
+ export { C as CacheHandler, D as DISPOSE, R as RecordArrayManager, E as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, J as consumeInternalSignal, G as createInternalMemo, l as createLegacyManyArray, q as createRequestSubscription, A as defineGate, B as defineNonEnumerableSignal, z as defineSignal, e as ensureStringId, y as entangleInitiallyStaleSignal, x as entangleSignal, f as fastPush, w as gate, K as getOrCreateInternalSignal, p as getPromiseState, t as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, v as memoized, I as notifyInternalSignal, F as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, u as signal, s as storeFor, H as withSignalStore } from "../index-CKXq9_RZ.js";
2
2
  export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-C3x8YXzL.js";
@@ -1,6 +1,6 @@
1
1
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
2
2
  const name = "@warp-drive/core";
3
- const version = "5.8.0-alpha.7";
3
+ const version = "5.8.0-alpha.8";
4
4
 
5
5
  // in testing mode, we utilize globals to ensure only one copy exists of
6
6
  // these maps, due to bugs in ember-auto-import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/core",
3
- "version": "5.8.0-alpha.7",
3
+ "version": "5.8.0-alpha.8",
4
4
  "description": "Core package for WarpDrive | All the Universal Basics",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@embroider/macros": "^1.18.1",
40
- "@warp-drive/build-config": "5.8.0-alpha.7"
40
+ "@warp-drive/build-config": "5.8.0-alpha.8"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.28.3",
44
44
  "@babel/plugin-transform-typescript": "^7.28.0",
45
45
  "@babel/preset-typescript": "^7.27.1",
46
- "@warp-drive/internal-config": "5.8.0-alpha.7",
46
+ "@warp-drive/internal-config": "5.8.0-alpha.8",
47
47
  "decorator-transforms": "^2.3.0",
48
48
  "ember-source": "~6.6.0",
49
49
  "expect-type": "^1.2.2",