@warp-drive/core 5.6.0-alpha.14 → 5.6.0-alpha.17

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 (287) hide show
  1. package/declarations/build-config/babel-macros.d.ts +1 -2
  2. package/declarations/build-config/canary-features.d.ts +1 -2
  3. package/declarations/build-config/debugging.d.ts +1 -2
  4. package/declarations/build-config/deprecations.d.ts +1 -2
  5. package/declarations/build-config/env.d.ts +1 -2
  6. package/declarations/build-config/macros.d.ts +1 -2
  7. package/declarations/build-config.d.ts +1 -2
  8. package/declarations/configure.d.ts +6 -7
  9. package/declarations/graph/-private/-diff.d.ts +21 -22
  10. package/declarations/graph/-private/-edge-definition.d.ts +134 -135
  11. package/declarations/graph/-private/-state.d.ts +93 -7
  12. package/declarations/graph/-private/-utils.d.ts +18 -13
  13. package/declarations/graph/-private/coerce-id.d.ts +6 -1
  14. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +15 -4
  15. package/declarations/graph/-private/edges/collection.d.ts +35 -36
  16. package/declarations/graph/-private/edges/implicit.d.ts +28 -29
  17. package/declarations/graph/-private/edges/resource.d.ts +19 -20
  18. package/declarations/graph/-private/graph.d.ts +83 -48
  19. package/declarations/graph/-private/normalize-link.d.ts +7 -2
  20. package/declarations/graph/-private/operations/add-to-related-records.d.ts +3 -4
  21. package/declarations/graph/-private/operations/merge-identifier.d.ts +2 -3
  22. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +3 -4
  23. package/declarations/graph/-private/operations/replace-related-record.d.ts +2 -3
  24. package/declarations/graph/-private/operations/replace-related-records.d.ts +58 -4
  25. package/declarations/graph/-private/operations/update-relationship.d.ts +11 -9
  26. package/declarations/graph/-private.d.ts +9 -10
  27. package/declarations/index.d.ts +11 -12
  28. package/declarations/reactive/-private/document.d.ts +143 -144
  29. package/declarations/reactive/-private/fields/compute.d.ts +31 -28
  30. package/declarations/reactive/-private/fields/extension.d.ts +8 -0
  31. package/declarations/reactive/-private/fields/managed-array.d.ts +19 -20
  32. package/declarations/reactive/-private/fields/managed-object.d.ts +16 -16
  33. package/declarations/reactive/-private/fields/many-array-manager.d.ts +15 -16
  34. package/declarations/reactive/-private/hooks.d.ts +3 -4
  35. package/declarations/reactive/-private/record.d.ts +61 -58
  36. package/declarations/reactive/-private/schema.d.ts +256 -165
  37. package/declarations/reactive/-private/symbols.d.ts +27 -2
  38. package/declarations/reactive/-private.d.ts +1 -2
  39. package/declarations/reactive.d.ts +4 -5
  40. package/declarations/request/-private/context.d.ts +34 -35
  41. package/declarations/request/-private/debug.d.ts +2 -3
  42. package/declarations/request/-private/fetch.d.ts +23 -24
  43. package/declarations/request/-private/future.d.ts +3 -4
  44. package/declarations/request/-private/manager.d.ts +159 -157
  45. package/declarations/request/-private/promise-cache.d.ts +21 -13
  46. package/declarations/request/-private/types.d.ts +124 -124
  47. package/declarations/request/-private/utils.d.ts +8 -9
  48. package/declarations/request.d.ts +5 -6
  49. package/declarations/store/-private/cache-handler/handler.d.ts +57 -52
  50. package/declarations/store/-private/cache-handler/types.d.ts +95 -96
  51. package/declarations/store/-private/cache-handler/utils.d.ts +16 -16
  52. package/declarations/store/-private/caches/cache-utils.d.ts +7 -4
  53. package/declarations/store/-private/caches/identifier-cache.d.ts +234 -246
  54. package/declarations/store/-private/caches/instance-cache.d.ts +47 -47
  55. package/declarations/store/-private/caches/resource-utils.d.ts +3 -4
  56. package/declarations/store/-private/debug/utils.d.ts +6 -7
  57. package/declarations/store/-private/default-cache-policy.d.ts +362 -361
  58. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +154 -159
  59. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +14 -14
  60. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +21 -22
  61. package/declarations/store/-private/managers/cache-manager.d.ts +440 -425
  62. package/declarations/store/-private/managers/notification-manager.d.ts +88 -83
  63. package/declarations/store/-private/managers/record-array-manager.d.ts +89 -90
  64. package/declarations/store/-private/network/request-cache.d.ts +86 -83
  65. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +252 -244
  66. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +155 -72
  67. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +148 -149
  68. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +28 -23
  69. package/declarations/store/-private/new-core-tmp/request-state.d.ts +263 -241
  70. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +261 -0
  71. package/declarations/store/-private/record-arrays/identifier-array.d.ts +125 -119
  72. package/declarations/store/-private/record-arrays/many-array.d.ts +180 -182
  73. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +120 -110
  74. package/declarations/store/-private/store-service.d.ts +1594 -1586
  75. package/declarations/store/-private/utils/coerce-id.d.ts +6 -1
  76. package/declarations/store/-private/utils/construct-resource.d.ts +1 -2
  77. package/declarations/store/-private/utils/is-non-empty-string.d.ts +0 -1
  78. package/declarations/store/-private/utils/normalize-model-name.d.ts +0 -1
  79. package/declarations/store/-private/utils/uuid-polyfill.d.ts +0 -1
  80. package/declarations/store/-private.d.ts +31 -27
  81. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +96 -97
  82. package/declarations/store/-types/q/ds-model.d.ts +17 -18
  83. package/declarations/store/-types/q/identifier.d.ts +11 -12
  84. package/declarations/store/-types/q/record-instance.d.ts +16 -17
  85. package/declarations/store/-types/q/schema-service.d.ts +346 -323
  86. package/declarations/store/-types/q/store.d.ts +25 -28
  87. package/declarations/store.d.ts +1 -2
  88. package/declarations/types/-private.d.ts +16 -8
  89. package/declarations/types/cache/aliases.d.ts +11 -1
  90. package/declarations/types/cache/change.d.ts +4 -5
  91. package/declarations/types/cache/mutations.d.ts +51 -28
  92. package/declarations/types/cache/operations.d.ts +60 -47
  93. package/declarations/types/cache/relationship.d.ts +11 -9
  94. package/declarations/types/cache.d.ts +495 -484
  95. package/declarations/types/graph.d.ts +31 -32
  96. package/declarations/types/identifier.d.ts +83 -82
  97. package/declarations/types/json/raw.d.ts +1 -2
  98. package/declarations/types/params.d.ts +4 -5
  99. package/declarations/types/record.d.ts +117 -76
  100. package/declarations/types/request.d.ts +289 -266
  101. package/declarations/types/runtime.d.ts +8 -9
  102. package/declarations/types/schema/concepts.d.ts +19 -13
  103. package/declarations/types/schema/fields.d.ts +1712 -1587
  104. package/declarations/types/schema/fields.type-test.d.ts +0 -1
  105. package/declarations/types/spec/document.d.ts +28 -22
  106. package/declarations/types/spec/error.d.ts +16 -17
  107. package/declarations/types/spec/json-api-raw.d.ts +102 -102
  108. package/declarations/types/symbols.d.ts +74 -75
  109. package/declarations/types/utils.d.ts +5 -5
  110. package/declarations/types.d.ts +10 -11
  111. package/declarations/utils/string.d.ts +43 -40
  112. package/dist/{configure-BgaZESRo.js → configure-B48bFHOl.js} +38 -2
  113. package/dist/configure.js +1 -1
  114. package/dist/graph/-private.js +2 -2
  115. package/dist/{handler-cHghx9Y9.js → handler-C2T-IyJK.js} +1 -1
  116. package/dist/index.js +3 -3
  117. package/dist/reactive/-private.js +1 -1
  118. package/dist/reactive.js +287 -101
  119. package/dist/{request-state-DgwTEXLU.js → request-state-CjLph1LP.js} +1030 -249
  120. package/dist/store/-private.js +3 -3
  121. package/dist/{symbols-BmDcn6hS.js → symbols-SIstXMLI.js} +3 -3
  122. package/dist/types/-private.js +1 -1
  123. package/dist/types/schema/fields.js +4 -4
  124. package/package.json +4 -4
  125. package/declarations/build-config/babel-macros.d.ts.map +0 -1
  126. package/declarations/build-config/canary-features.d.ts.map +0 -1
  127. package/declarations/build-config/debugging.d.ts.map +0 -1
  128. package/declarations/build-config/deprecations.d.ts.map +0 -1
  129. package/declarations/build-config/env.d.ts.map +0 -1
  130. package/declarations/build-config/macros.d.ts.map +0 -1
  131. package/declarations/build-config.d.ts.map +0 -1
  132. package/declarations/configure.d.ts.map +0 -1
  133. package/declarations/graph/-private/-diff.d.ts.map +0 -1
  134. package/declarations/graph/-private/-edge-definition.d.ts.map +0 -1
  135. package/declarations/graph/-private/-state.d.ts.map +0 -1
  136. package/declarations/graph/-private/-utils.d.ts.map +0 -1
  137. package/declarations/graph/-private/coerce-id.d.ts.map +0 -1
  138. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
  139. package/declarations/graph/-private/edges/collection.d.ts.map +0 -1
  140. package/declarations/graph/-private/edges/implicit.d.ts.map +0 -1
  141. package/declarations/graph/-private/edges/resource.d.ts.map +0 -1
  142. package/declarations/graph/-private/graph.d.ts.map +0 -1
  143. package/declarations/graph/-private/normalize-link.d.ts.map +0 -1
  144. package/declarations/graph/-private/operations/add-to-related-records.d.ts.map +0 -1
  145. package/declarations/graph/-private/operations/merge-identifier.d.ts.map +0 -1
  146. package/declarations/graph/-private/operations/remove-from-related-records.d.ts.map +0 -1
  147. package/declarations/graph/-private/operations/replace-related-record.d.ts.map +0 -1
  148. package/declarations/graph/-private/operations/replace-related-records.d.ts.map +0 -1
  149. package/declarations/graph/-private/operations/update-relationship.d.ts.map +0 -1
  150. package/declarations/graph/-private.d.ts.map +0 -1
  151. package/declarations/index.d.ts.map +0 -1
  152. package/declarations/reactive/-private/document.d.ts.map +0 -1
  153. package/declarations/reactive/-private/fields/compute.d.ts.map +0 -1
  154. package/declarations/reactive/-private/fields/managed-array.d.ts.map +0 -1
  155. package/declarations/reactive/-private/fields/managed-object.d.ts.map +0 -1
  156. package/declarations/reactive/-private/fields/many-array-manager.d.ts.map +0 -1
  157. package/declarations/reactive/-private/hooks.d.ts.map +0 -1
  158. package/declarations/reactive/-private/record.d.ts.map +0 -1
  159. package/declarations/reactive/-private/schema.d.ts.map +0 -1
  160. package/declarations/reactive/-private/symbols.d.ts.map +0 -1
  161. package/declarations/reactive/-private.d.ts.map +0 -1
  162. package/declarations/reactive.d.ts.map +0 -1
  163. package/declarations/request/-private/context.d.ts.map +0 -1
  164. package/declarations/request/-private/debug.d.ts.map +0 -1
  165. package/declarations/request/-private/fetch.d.ts.map +0 -1
  166. package/declarations/request/-private/future.d.ts.map +0 -1
  167. package/declarations/request/-private/manager.d.ts.map +0 -1
  168. package/declarations/request/-private/promise-cache.d.ts.map +0 -1
  169. package/declarations/request/-private/types.d.ts.map +0 -1
  170. package/declarations/request/-private/utils.d.ts.map +0 -1
  171. package/declarations/request.d.ts.map +0 -1
  172. package/declarations/store/-private/cache-handler/handler.d.ts.map +0 -1
  173. package/declarations/store/-private/cache-handler/types.d.ts.map +0 -1
  174. package/declarations/store/-private/cache-handler/utils.d.ts.map +0 -1
  175. package/declarations/store/-private/caches/cache-utils.d.ts.map +0 -1
  176. package/declarations/store/-private/caches/identifier-cache.d.ts.map +0 -1
  177. package/declarations/store/-private/caches/instance-cache.d.ts.map +0 -1
  178. package/declarations/store/-private/caches/resource-utils.d.ts.map +0 -1
  179. package/declarations/store/-private/debug/utils.d.ts.map +0 -1
  180. package/declarations/store/-private/default-cache-policy.d.ts.map +0 -1
  181. package/declarations/store/-private/legacy-model-support/record-reference.d.ts.map +0 -1
  182. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts.map +0 -1
  183. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts.map +0 -1
  184. package/declarations/store/-private/managers/cache-manager.d.ts.map +0 -1
  185. package/declarations/store/-private/managers/notification-manager.d.ts.map +0 -1
  186. package/declarations/store/-private/managers/record-array-manager.d.ts.map +0 -1
  187. package/declarations/store/-private/network/request-cache.d.ts.map +0 -1
  188. package/declarations/store/-private/new-core-tmp/promise-state.d.ts.map +0 -1
  189. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts.map +0 -1
  190. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts.map +0 -1
  191. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts.map +0 -1
  192. package/declarations/store/-private/new-core-tmp/request-state.d.ts.map +0 -1
  193. package/declarations/store/-private/record-arrays/identifier-array.d.ts.map +0 -1
  194. package/declarations/store/-private/record-arrays/many-array.d.ts.map +0 -1
  195. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts.map +0 -1
  196. package/declarations/store/-private/store-service.d.ts.map +0 -1
  197. package/declarations/store/-private/store-service.type-test.d.ts +0 -2
  198. package/declarations/store/-private/store-service.type-test.d.ts.map +0 -1
  199. package/declarations/store/-private/utils/coerce-id.d.ts.map +0 -1
  200. package/declarations/store/-private/utils/construct-resource.d.ts.map +0 -1
  201. package/declarations/store/-private/utils/is-non-empty-string.d.ts.map +0 -1
  202. package/declarations/store/-private/utils/normalize-model-name.d.ts.map +0 -1
  203. package/declarations/store/-private/utils/uuid-polyfill.d.ts.map +0 -1
  204. package/declarations/store/-private.d.ts.map +0 -1
  205. package/declarations/store/-types/q/cache-capabilities-manager.d.ts.map +0 -1
  206. package/declarations/store/-types/q/ds-model.d.ts.map +0 -1
  207. package/declarations/store/-types/q/identifier.d.ts.map +0 -1
  208. package/declarations/store/-types/q/promise-proxies.d.ts +0 -2
  209. package/declarations/store/-types/q/promise-proxies.d.ts.map +0 -1
  210. package/declarations/store/-types/q/record-data-json-api.d.ts +0 -31
  211. package/declarations/store/-types/q/record-data-json-api.d.ts.map +0 -1
  212. package/declarations/store/-types/q/record-instance.d.ts.map +0 -1
  213. package/declarations/store/-types/q/schema-service.d.ts.map +0 -1
  214. package/declarations/store/-types/q/store.d.ts.map +0 -1
  215. package/declarations/store.d.ts.map +0 -1
  216. package/declarations/types/-private.d.ts.map +0 -1
  217. package/declarations/types/cache/aliases.d.ts.map +0 -1
  218. package/declarations/types/cache/change.d.ts.map +0 -1
  219. package/declarations/types/cache/mutations.d.ts.map +0 -1
  220. package/declarations/types/cache/operations.d.ts.map +0 -1
  221. package/declarations/types/cache/relationship.d.ts.map +0 -1
  222. package/declarations/types/cache.d.ts.map +0 -1
  223. package/declarations/types/graph.d.ts.map +0 -1
  224. package/declarations/types/identifier.d.ts.map +0 -1
  225. package/declarations/types/json/raw.d.ts.map +0 -1
  226. package/declarations/types/params.d.ts.map +0 -1
  227. package/declarations/types/record.d.ts.map +0 -1
  228. package/declarations/types/record.type-test.d.ts +0 -2
  229. package/declarations/types/record.type-test.d.ts.map +0 -1
  230. package/declarations/types/request.d.ts.map +0 -1
  231. package/declarations/types/request.type-test.d.ts +0 -2
  232. package/declarations/types/request.type-test.d.ts.map +0 -1
  233. package/declarations/types/runtime.d.ts.map +0 -1
  234. package/declarations/types/schema/concepts.d.ts.map +0 -1
  235. package/declarations/types/schema/fields.d.ts.map +0 -1
  236. package/declarations/types/schema/fields.type-test.d.ts.map +0 -1
  237. package/declarations/types/spec/document.d.ts.map +0 -1
  238. package/declarations/types/spec/error.d.ts.map +0 -1
  239. package/declarations/types/spec/json-api-raw.d.ts.map +0 -1
  240. package/declarations/types/symbols.d.ts.map +0 -1
  241. package/declarations/types/utils.d.ts.map +0 -1
  242. package/declarations/types.d.ts.map +0 -1
  243. package/declarations/utils/string.d.ts.map +0 -1
  244. package/dist/build-config/babel-macros.js.map +0 -1
  245. package/dist/build-config/canary-features.js.map +0 -1
  246. package/dist/build-config/debugging.js.map +0 -1
  247. package/dist/build-config/deprecations.js.map +0 -1
  248. package/dist/build-config/env.js.map +0 -1
  249. package/dist/build-config/macros.js.map +0 -1
  250. package/dist/build-config.js.map +0 -1
  251. package/dist/configure-BgaZESRo.js.map +0 -1
  252. package/dist/configure.js.map +0 -1
  253. package/dist/context-COmAnXUQ.js.map +0 -1
  254. package/dist/graph/-private.js.map +0 -1
  255. package/dist/handler-cHghx9Y9.js.map +0 -1
  256. package/dist/index.js.map +0 -1
  257. package/dist/reactive/-private.js.map +0 -1
  258. package/dist/reactive.js.map +0 -1
  259. package/dist/request-state-DgwTEXLU.js.map +0 -1
  260. package/dist/request.js.map +0 -1
  261. package/dist/store/-private.js.map +0 -1
  262. package/dist/store.js.map +0 -1
  263. package/dist/symbols-BmDcn6hS.js.map +0 -1
  264. package/dist/types/-private.js.map +0 -1
  265. package/dist/types/cache/aliases.js.map +0 -1
  266. package/dist/types/cache/change.js.map +0 -1
  267. package/dist/types/cache/mutations.js.map +0 -1
  268. package/dist/types/cache/operations.js.map +0 -1
  269. package/dist/types/cache/relationship.js.map +0 -1
  270. package/dist/types/cache.js.map +0 -1
  271. package/dist/types/graph.js.map +0 -1
  272. package/dist/types/identifier.js.map +0 -1
  273. package/dist/types/json/raw.js.map +0 -1
  274. package/dist/types/params.js.map +0 -1
  275. package/dist/types/record.js.map +0 -1
  276. package/dist/types/request.js.map +0 -1
  277. package/dist/types/runtime.js.map +0 -1
  278. package/dist/types/schema/concepts.js.map +0 -1
  279. package/dist/types/schema/fields.js.map +0 -1
  280. package/dist/types/schema/fields.type-test.js.map +0 -1
  281. package/dist/types/spec/document.js.map +0 -1
  282. package/dist/types/spec/error.js.map +0 -1
  283. package/dist/types/spec/json-api-raw.js.map +0 -1
  284. package/dist/types/symbols.js.map +0 -1
  285. package/dist/types/utils.js.map +0 -1
  286. package/dist/types.js.map +0 -1
  287. package/dist/utils/string.js.map +0 -1
@@ -1,11 +1,11 @@
1
+ import { withBrand, EnableHydration, SkipCache } from './types/request.js';
1
2
  import { deprecate, warn } from '@ember/debug';
2
3
  import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
3
- import { withBrand, EnableHydration, SkipCache } from './types/request.js';
4
4
  import { setLogging, getRuntimeConfig } from './types/runtime.js';
5
5
  import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
6
- import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, d as willSyncFlushWatchers, A as ARRAY_SIGNAL } from "./configure-BgaZESRo.js";
7
6
  import { CACHE_OWNER, DEBUG_STALE_CACHE_OWNER, DEBUG_IDENTIFIER_BUCKET, DEBUG_CLIENT_ORIGINATED } from './types/identifier.js';
8
7
  import { dasherize } from './utils/string.js';
8
+ import { a as createSignal, b as consumeSignal, n as notifySignal, c as createMemo, d as willSyncFlushWatchers, A as ARRAY_SIGNAL } from "./configure-B48bFHOl.js";
9
9
  import { g as getPromiseResult, s as setPromiseResult } from "./context-COmAnXUQ.js";
10
10
  function coerceId(id) {
11
11
  if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_ID)) {
@@ -393,7 +393,7 @@ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
393
393
  }
394
394
 
395
395
  /**
396
- * Each instance of {Store} receives a unique instance of a IdentifierCache.
396
+ * Each instance of {@link Store} receives a unique instance of a IdentifierCache.
397
397
  *
398
398
  * This cache is responsible for assigning or retrieving the unique identify
399
399
  * for arbitrary resource data encountered by the store. Data representing
@@ -402,10 +402,12 @@ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
402
402
  *
403
403
  * It can be configured by consuming applications.
404
404
  *
405
- * @class IdentifierCache
406
- @public
405
+ * @hideconstructor
406
+ * @public
407
407
  */
408
408
  class IdentifierCache {
409
+ /** @internal */
410
+
409
411
  constructor() {
410
412
  // we cache the user configuredGenerationMethod at init because it must
411
413
  // be configured prior and is not allowed to be changed
@@ -435,6 +437,8 @@ class IdentifierCache {
435
437
  __configureMerge(method) {
436
438
  this._merge = method || defaultMergeMethod;
437
439
  }
440
+
441
+ /** @internal */
438
442
  upgradeIdentifier(resource) {
439
443
  return this._getRecordIdentifier(resource, 2);
440
444
  }
@@ -524,8 +528,6 @@ class IdentifierCache {
524
528
  * useful for the "create" case when we need to see if
525
529
  * we are accidentally overwritting something
526
530
  *
527
- * @param resource
528
- * @return {StableRecordIdentifier | undefined}
529
531
  * @private
530
532
  */
531
533
  peekRecordIdentifier(resource) {
@@ -535,9 +537,7 @@ class IdentifierCache {
535
537
  /**
536
538
  Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
537
539
  Returns `null` if the request does not have a `cacheKey` or `url`.
538
- @param request
539
- @return {StableDocumentIdentifier | null}
540
- @public
540
+ @public
541
541
  */
542
542
  getOrCreateDocumentIdentifier(request) {
543
543
  let cacheKey = request.cacheOptions?.key;
@@ -568,9 +568,7 @@ class IdentifierCache {
568
568
  - return an object with an `lid` that is stable (repeated calls with the same
569
569
  `id` + `type` or `lid` will return the same `lid` value)
570
570
  - this referential stability of the object itself is guaranteed
571
- @param resource
572
- @return {StableRecordIdentifier}
573
- @public
571
+ @public
574
572
  */
575
573
  getOrCreateRecordIdentifier(resource) {
576
574
  return this._getRecordIdentifier(resource, 1);
@@ -582,9 +580,7 @@ class IdentifierCache {
582
580
  potentially does not have an `id`.
583
581
  Delegates generation to the user supplied `GenerateMethod` if one has been provided
584
582
  with the signature `generateMethod({ type }, 'record')`.
585
- @param data
586
- @return {StableRecordIdentifier}
587
- @public
583
+ @public
588
584
  */
589
585
  createIdentifierForNewRecord(data) {
590
586
  const newLid = this._generate(data, 'record');
@@ -625,10 +621,7 @@ class IdentifierCache {
625
621
  If a merge occurs, it is possible the returned identifier does not match the originally
626
622
  provided identifier. In this case the abandoned identifier will go through the usual
627
623
  `forgetRecordIdentifier` codepaths.
628
- @param identifierObject
629
- @param data
630
- @return {StableRecordIdentifier}
631
- @public
624
+ @public
632
625
  */
633
626
  updateRecordIdentifier(identifierObject, data) {
634
627
  let identifier = this.getOrCreateRecordIdentifier(identifierObject);
@@ -741,8 +734,7 @@ class IdentifierCache {
741
734
  Useful when a record has been deleted and the deletion has been persisted and
742
735
  we do not care about the record anymore. Especially useful when an `id` of a
743
736
  deleted record might be reused later for a new record.
744
- @param identifierObject
745
- @public
737
+ @public
746
738
  */
747
739
  forgetRecordIdentifier(identifierObject) {
748
740
  const identifier = this.getOrCreateRecordIdentifier(identifierObject);
@@ -776,6 +768,8 @@ class IdentifierCache {
776
768
  }
777
769
  }
778
770
  }
771
+
772
+ /** @internal */
779
773
  destroy() {
780
774
  NEW_IDENTIFIERS.clear();
781
775
  this._cache.documents.forEach(identifier => {
@@ -1568,13 +1562,12 @@ function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
1568
1562
  A `RecordReference` is a low-level API that allows users and
1569
1563
  addon authors to perform meta-operations on a record.
1570
1564
 
1571
- @class RecordReference
1565
+ @hideconstructor
1572
1566
  @public
1573
1567
  */
1574
1568
  class RecordReference {
1575
1569
  // unsubscribe token given to us by the notification manager
1576
- ___token;
1577
- ___identifier;
1570
+
1578
1571
  constructor(store, identifier) {
1579
1572
  this.store = store;
1580
1573
  this.___identifier = identifier;
@@ -1584,6 +1577,8 @@ class RecordReference {
1584
1577
  }
1585
1578
  });
1586
1579
  }
1580
+
1581
+ /** @internal */
1587
1582
  destroy() {
1588
1583
  this.store.notifications.unsubscribe(this.___token);
1589
1584
  }
@@ -1601,7 +1596,6 @@ class RecordReference {
1601
1596
  userRef.id(); // '1'
1602
1597
  ```
1603
1598
  @public
1604
- @return {String} The id of the record.
1605
1599
  */
1606
1600
  id() {
1607
1601
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
@@ -1619,7 +1613,6 @@ class RecordReference {
1619
1613
  userRef.identifier(); // '1'
1620
1614
  ```
1621
1615
  @public
1622
- @return {String} The identifier of the record.
1623
1616
  */
1624
1617
  identifier() {
1625
1618
  return this.___identifier;
@@ -1635,7 +1628,6 @@ class RecordReference {
1635
1628
  userRef.remoteType(); // 'identity'
1636
1629
  ```
1637
1630
  @public
1638
- @return {String} 'identity'
1639
1631
  */
1640
1632
  remoteType() {
1641
1633
  return 'identity';
@@ -1690,7 +1682,6 @@ class RecordReference {
1690
1682
  userRef.value(); // user
1691
1683
  ```
1692
1684
  @public
1693
- @return {Model} the record for this RecordReference
1694
1685
  */
1695
1686
  value() {
1696
1687
  return this.store.peekRecord(this.___identifier);
@@ -1706,7 +1697,6 @@ class RecordReference {
1706
1697
  userRef.load().then(...)
1707
1698
  ```
1708
1699
  @public
1709
- @return {Promise<record>} the record for this RecordReference
1710
1700
  */
1711
1701
  load() {
1712
1702
  const id = this.id();
@@ -1730,7 +1720,6 @@ class RecordReference {
1730
1720
  userRef.reload().then(...)
1731
1721
  ```
1732
1722
  @public
1733
- @return {Promise<record>} the record for this RecordReference
1734
1723
  */
1735
1724
  reload() {
1736
1725
  const id = this.id();
@@ -2977,10 +2966,22 @@ function _unsubscribe(token, cache) {
2977
2966
  * This Feature is what allows WarpDrive to create subscriptions that
2978
2967
  * work with any framework or change-notification system.
2979
2968
  *
2980
- * @class NotificationManager
2969
+ * @hideconstructor
2981
2970
  * @public
2982
2971
  */
2983
2972
  class NotificationManager {
2973
+ /** @internal */
2974
+
2975
+ /** @internal */
2976
+
2977
+ /** @internal */
2978
+
2979
+ /** @internal */
2980
+
2981
+ /** @internal */
2982
+
2983
+ /** @internal */
2984
+
2984
2985
  constructor(store) {
2985
2986
  this.store = store;
2986
2987
  this.isDestroyed = false;
@@ -3048,7 +3049,6 @@ class NotificationManager {
3048
3049
  * remove a previous subscription
3049
3050
  *
3050
3051
  * @public
3051
- * @param {UnsubscribeToken} token
3052
3052
  */
3053
3053
  unsubscribe(token) {
3054
3054
  if (!this.isDestroyed) {
@@ -3059,10 +3059,6 @@ class NotificationManager {
3059
3059
  /**
3060
3060
  * Custom Caches and Application Code should not call this method directly.
3061
3061
  *
3062
- * @param identifier
3063
- * @param value
3064
- * @param key
3065
- * @return {Boolean} whether a notification was delivered to any subscribers
3066
3062
  * @private
3067
3063
  */
3068
3064
 
@@ -3115,6 +3111,8 @@ class NotificationManager {
3115
3111
  }
3116
3112
  return hasSubscribers;
3117
3113
  }
3114
+
3115
+ /** @internal */
3118
3116
  _onNextFlush(cb) {
3119
3117
  this._onFlushCB = cb;
3120
3118
  }
@@ -3132,6 +3130,8 @@ class NotificationManager {
3132
3130
  this._flush();
3133
3131
  return true;
3134
3132
  }
3133
+
3134
+ /** @internal */
3135
3135
  _flush() {
3136
3136
  const buffered = this._buffered;
3137
3137
  if (buffered.size) {
@@ -3173,11 +3173,149 @@ class NotificationManager {
3173
3173
  });
3174
3174
  return true;
3175
3175
  }
3176
+
3177
+ /** @internal */
3176
3178
  destroy() {
3177
3179
  this.isDestroyed = true;
3178
3180
  this._cache.clear();
3179
3181
  }
3180
3182
  }
3183
+ function isExtensionProp(extensions, prop) {
3184
+ return Boolean(extensions && typeof prop !== 'number' && extensions.has(prop));
3185
+ }
3186
+ function performObjectExtensionGet(receiver, extensions, signals, prop) {
3187
+ const desc = extensions.get(prop);
3188
+ switch (desc.kind) {
3189
+ case 'method':
3190
+ {
3191
+ return desc.fn;
3192
+ }
3193
+ case 'readonly-value':
3194
+ {
3195
+ return desc.value;
3196
+ }
3197
+ case 'mutable-value':
3198
+ {
3199
+ const signal = getOrCreateInternalSignal(signals, receiver, prop, desc.value);
3200
+ // we don't consume this signal, since its not a true local.
3201
+ return signal.value;
3202
+ }
3203
+ case 'readonly-field':
3204
+ case 'mutable-field':
3205
+ {
3206
+ return desc.get.call(receiver);
3207
+ }
3208
+ case 'writeonly-field':
3209
+ {
3210
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3211
+ {
3212
+ throw new Error(`Cannot get extended field ${String(prop)} as its definition has only a setter`);
3213
+ }
3214
+ })() : {};
3215
+ return undefined;
3216
+ }
3217
+ default:
3218
+ {
3219
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3220
+ {
3221
+ throw new Error(`Unhandled extension kind ${desc.kind}`);
3222
+ }
3223
+ })() : {};
3224
+ return undefined;
3225
+ }
3226
+ }
3227
+ }
3228
+ function performExtensionSet(receiver, extensions, signals, prop, value) {
3229
+ const desc = extensions.get(prop);
3230
+ switch (desc.kind) {
3231
+ case 'method':
3232
+ case 'readonly-value':
3233
+ case 'readonly-field':
3234
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3235
+ {
3236
+ throw new Error(`Cannot set extension field ${String(prop)} as it is a ${desc.kind}`);
3237
+ }
3238
+ })() : {};
3239
+ return false;
3240
+ case 'mutable-value':
3241
+ {
3242
+ const signal = getOrCreateInternalSignal(signals, receiver, prop, desc.value);
3243
+ if (signal.value !== value) {
3244
+ // we don't notify this signal, since its not a true local.
3245
+ signal.value = value;
3246
+ }
3247
+ return true;
3248
+ }
3249
+ case 'writeonly-field':
3250
+ case 'mutable-field':
3251
+ {
3252
+ desc.set.call(receiver, value);
3253
+ return true;
3254
+ }
3255
+ default:
3256
+ {
3257
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3258
+ {
3259
+ throw new Error(`Unhandled extension kind ${desc.kind}`);
3260
+ }
3261
+ })() : {};
3262
+ return false;
3263
+ }
3264
+ }
3265
+ }
3266
+ function performArrayExtensionGet(receiver, extensions, signals, prop, _SIGNAL, boundFns, transaction) {
3267
+ const desc = extensions.get(prop);
3268
+ switch (desc.kind) {
3269
+ case 'method':
3270
+ {
3271
+ let fn = boundFns.get(prop);
3272
+ if (fn === undefined) {
3273
+ fn = function () {
3274
+ consumeInternalSignal(_SIGNAL);
3275
+ transaction(true);
3276
+ const result = Reflect.apply(desc.fn, receiver, arguments);
3277
+ transaction(false);
3278
+ return result;
3279
+ };
3280
+ boundFns.set(prop, fn);
3281
+ }
3282
+ return fn;
3283
+ }
3284
+ case 'mutable-field':
3285
+ case 'readonly-field':
3286
+ {
3287
+ return desc.get.call(receiver);
3288
+ }
3289
+ case 'readonly-value':
3290
+ {
3291
+ return desc.value;
3292
+ }
3293
+ case 'mutable-value':
3294
+ {
3295
+ const signal = getOrCreateInternalSignal(signals, receiver, prop, desc.value);
3296
+ // we don't consume this signal, since its not a true local.
3297
+ return signal.value;
3298
+ }
3299
+ case 'writeonly-field':
3300
+ {
3301
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3302
+ {
3303
+ throw new Error(`Cannot get extended field ${String(prop)} as its definition has only a setter`);
3304
+ }
3305
+ })() : {};
3306
+ return undefined;
3307
+ }
3308
+ default:
3309
+ {
3310
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3311
+ {
3312
+ throw new Error(`Unhandled extension kind ${desc.kind}`);
3313
+ }
3314
+ })() : {};
3315
+ return undefined;
3316
+ }
3317
+ }
3318
+ }
3181
3319
 
3182
3320
  /* eslint-disable @typescript-eslint/no-explicit-any */
3183
3321
  /*
@@ -3246,6 +3384,12 @@ function safeForEach(instance, arr, store, callback, target) {
3246
3384
  @public
3247
3385
  */
3248
3386
 
3387
+ // these are "internally" mutable, they should not be mutated by consumers
3388
+ // though this is not currently enforced.
3389
+ //
3390
+ // all of these should become gated by field-type as they shouldn't be available
3391
+ // on request results or non-legacy relationships.
3392
+ const MUTABLE_PROPS = ['_updatingPromise', 'isDestroying', 'isDestroyed', 'query', 'isUpdating', 'isLoaded', 'meta', 'links', 'isAsync', 'isPolymorphic', 'identifier', 'cache', '_inverseIsAsync', 'key', 'DEPRECATED_CLASS_NAME'];
3249
3393
  class IdentifierArray {
3250
3394
  /**
3251
3395
  The flag to signal a `RecordArray` is currently loading data.
@@ -3307,6 +3451,7 @@ class IdentifierArray {
3307
3451
  // we track all mutations within the call
3308
3452
  // and forward them as one
3309
3453
  let _SIGNAL = null;
3454
+ const extensions = options.field && this.store.schema.CAUTION_MEGA_DANGER_ZONE_arrayExtensions ? this.store.schema.CAUTION_MEGA_DANGER_ZONE_arrayExtensions(options.field) : null;
3310
3455
  const proxy = new NativeProxy(this[SOURCE], {
3311
3456
  get(target, prop, receiver) {
3312
3457
  const index = convertToInt(prop);
@@ -3377,7 +3522,7 @@ class IdentifierArray {
3377
3522
  }
3378
3523
  })(!transaction) : {};
3379
3524
  transaction = true;
3380
- const result = self[MUTATE](target, receiver, prop, args, _SIGNAL);
3525
+ const result = options[MUTATE](target, receiver, prop, args, _SIGNAL);
3381
3526
  transaction = false;
3382
3527
  return result;
3383
3528
  };
@@ -3404,14 +3549,25 @@ class IdentifierArray {
3404
3549
  }
3405
3550
  return consumeInternalSignal(_SIGNAL), outcome;
3406
3551
  }
3552
+ if (isExtensionProp(extensions, prop)) {
3553
+ return performArrayExtensionGet(receiver, extensions, signals, prop, _SIGNAL, boundFns, v => void (transaction = v));
3554
+ }
3407
3555
  return target[prop];
3408
3556
  },
3409
3557
  // FIXME: Should this get a generic like get above?
3410
3558
  set(target, prop, value, receiver) {
3559
+ if (!options.allowMutation && !MUTABLE_PROPS.includes(prop)) {
3560
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3561
+ if (!test) {
3562
+ throw new Error(`Mutating ${String(prop)} on this Array is not allowed.`);
3563
+ }
3564
+ })(options.allowMutation) : {};
3565
+ return false;
3566
+ }
3411
3567
  if (prop === 'length') {
3412
3568
  if (!transaction && value === 0) {
3413
3569
  transaction = true;
3414
- self[MUTATE](target, receiver, 'length 0', [], _SIGNAL);
3570
+ options[MUTATE](target, receiver, 'length 0', [], _SIGNAL);
3415
3571
  transaction = false;
3416
3572
  return true;
3417
3573
  } else if (transaction) {
@@ -3432,6 +3588,9 @@ class IdentifierArray {
3432
3588
  PrivateState.meta = value || null;
3433
3589
  return true;
3434
3590
  }
3591
+ if (isExtensionProp(extensions, prop)) {
3592
+ return performExtensionSet(receiver, extensions, signals, prop, value);
3593
+ }
3435
3594
  const index = convertToInt(prop);
3436
3595
 
3437
3596
  // we do not allow "holey" arrays and so if the index is
@@ -3458,14 +3617,6 @@ class IdentifierArray {
3458
3617
  }
3459
3618
  return false;
3460
3619
  }
3461
- if (!options.allowMutation) {
3462
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
3463
- if (!test) {
3464
- throw new Error(`Mutating ${String(prop)} on this Array is not allowed.`);
3465
- }
3466
- })(options.allowMutation) : {};
3467
- return false;
3468
- }
3469
3620
  const original = target[index];
3470
3621
  const newIdentifier = extractIdentifierFromRecord$2(value);
3471
3622
  macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
@@ -3490,7 +3641,7 @@ class IdentifierArray {
3490
3641
  // a transaction.
3491
3642
  // while "arr[arr.length] = newVal;" is handled by this replace cell code path.
3492
3643
  if (!transaction) {
3493
- self[MUTATE](target, receiver, 'replace cell', [index, original, newIdentifier], _SIGNAL);
3644
+ options[MUTATE](target, receiver, 'replace cell', [index, original, newIdentifier], _SIGNAL);
3494
3645
  } else {
3495
3646
  target[index] = newIdentifier;
3496
3647
  }
@@ -4088,10 +4239,11 @@ function hasRecordIdentifier(op) {
4088
4239
  * The RequestStateService is used to track the state of requests
4089
4240
  * for fetching or updating known resource identifies that are inflight.
4090
4241
  *
4091
- * @class RequestStateService
4242
+ * @hideconstructor
4092
4243
  * @public
4093
4244
  */
4094
4245
  class RequestStateService {
4246
+ /** @internal */
4095
4247
  _pending = new Map();
4096
4248
  _done = new Map();
4097
4249
  _subscriptions = new Map();
@@ -4100,9 +4252,11 @@ class RequestStateService {
4100
4252
  constructor(store) {
4101
4253
  this._store = store;
4102
4254
  }
4255
+ /** @internal */
4103
4256
  _clearEntries(identifier) {
4104
4257
  this._done.delete(identifier);
4105
4258
  }
4259
+ /** @internal */
4106
4260
  _enqueue(promise, queryRequest) {
4107
4261
  const query = queryRequest.data[0];
4108
4262
  if (hasRecordIdentifier(query)) {
@@ -4456,6 +4610,8 @@ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_METRIC_COUNTS))
4456
4610
  *
4457
4611
  */
4458
4612
 
4613
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4614
+
4459
4615
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
4460
4616
  const EmptyClass = class {
4461
4617
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
@@ -6331,7 +6487,202 @@ function extractIdentifierFromRecord$1(recordOrPromiseRecord) {
6331
6487
  const extract = recordIdentifierFor;
6332
6488
  return extract(recordOrPromiseRecord);
6333
6489
  }
6490
+ function _MUTATE(target, receiver, prop, args, _SIGNAL) {
6491
+ const collection = receiver;
6492
+ switch (prop) {
6493
+ case 'length 0':
6494
+ {
6495
+ Reflect.set(target, 'length', 0);
6496
+ mutateReplaceRelatedRecords(collection, [], _SIGNAL);
6497
+ return true;
6498
+ }
6499
+ case 'replace cell':
6500
+ {
6501
+ const [index, prior, value] = args;
6502
+ target[index] = value;
6503
+ mutateReplaceRelatedRecord(collection, {
6504
+ value,
6505
+ prior,
6506
+ index
6507
+ }, _SIGNAL);
6508
+ return true;
6509
+ }
6510
+ case 'push':
6511
+ {
6512
+ const newValues = extractIdentifiersFromRecords(args);
6513
+ assertNoDuplicates(collection, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
6514
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6515
+ // dedupe
6516
+ const seen = new Set(target);
6517
+ const unique = new Set();
6518
+ args.forEach(item => {
6519
+ const identifier = recordIdentifierFor(item);
6520
+ if (!seen.has(identifier)) {
6521
+ seen.add(identifier);
6522
+ unique.add(item);
6523
+ }
6524
+ });
6525
+ const newArgs = Array.from(unique);
6526
+ const result = Reflect.apply(target[prop], receiver, newArgs);
6527
+ if (newArgs.length) {
6528
+ mutateAddToRelatedRecords(collection, {
6529
+ value: extractIdentifiersFromRecords(newArgs)
6530
+ }, _SIGNAL);
6531
+ }
6532
+ return result;
6533
+ }
6534
+
6535
+ // else, no dedupe, error on duplicates
6536
+ const result = Reflect.apply(target[prop], receiver, args);
6537
+ if (newValues.length) {
6538
+ mutateAddToRelatedRecords(collection, {
6539
+ value: newValues
6540
+ }, _SIGNAL);
6541
+ }
6542
+ return result;
6543
+ }
6544
+ case 'pop':
6545
+ {
6546
+ const result = Reflect.apply(target[prop], receiver, args);
6547
+ if (result) {
6548
+ mutateRemoveFromRelatedRecords(collection, {
6549
+ value: recordIdentifierFor(result)
6550
+ }, _SIGNAL);
6551
+ }
6552
+ return result;
6553
+ }
6554
+ case 'unshift':
6555
+ {
6556
+ const newValues = extractIdentifiersFromRecords(args);
6557
+ assertNoDuplicates(collection, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
6558
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6559
+ // dedupe
6560
+ const seen = new Set(target);
6561
+ const unique = new Set();
6562
+ args.forEach(item => {
6563
+ const identifier = recordIdentifierFor(item);
6564
+ if (!seen.has(identifier)) {
6565
+ seen.add(identifier);
6566
+ unique.add(item);
6567
+ }
6568
+ });
6569
+ const newArgs = Array.from(unique);
6570
+ const result = Reflect.apply(target[prop], receiver, newArgs);
6571
+ if (newArgs.length) {
6572
+ mutateAddToRelatedRecords(collection, {
6573
+ value: extractIdentifiersFromRecords(newArgs),
6574
+ index: 0
6575
+ }, _SIGNAL);
6576
+ }
6577
+ return result;
6578
+ }
6579
+
6580
+ // else, no dedupe, error on duplicates
6581
+ const result = Reflect.apply(target[prop], receiver, args);
6582
+ if (newValues.length) {
6583
+ mutateAddToRelatedRecords(collection, {
6584
+ value: newValues,
6585
+ index: 0
6586
+ }, _SIGNAL);
6587
+ }
6588
+ return result;
6589
+ }
6590
+ case 'shift':
6591
+ {
6592
+ const result = Reflect.apply(target[prop], receiver, args);
6593
+ if (result) {
6594
+ mutateRemoveFromRelatedRecords(collection, {
6595
+ value: recordIdentifierFor(result),
6596
+ index: 0
6597
+ }, _SIGNAL);
6598
+ }
6599
+ return result;
6600
+ }
6601
+ case 'sort':
6602
+ {
6603
+ const result = Reflect.apply(target[prop], receiver, args);
6604
+ mutateSortRelatedRecords(collection, result.map(recordIdentifierFor), _SIGNAL);
6605
+ return result;
6606
+ }
6607
+ case 'splice':
6608
+ {
6609
+ const [start, deleteCount, ...adds] = args;
6610
+
6611
+ // detect a full replace
6612
+ if (start === 0 && deleteCount === collection[SOURCE].length) {
6613
+ const newValues = extractIdentifiersFromRecords(adds);
6614
+ assertNoDuplicates(collection, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
6615
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6616
+ // dedupe
6617
+ const current = new Set(adds);
6618
+ const unique = Array.from(current);
6619
+ const newArgs = [start, deleteCount].concat(unique);
6620
+ const result = Reflect.apply(target[prop], receiver, newArgs);
6621
+ mutateReplaceRelatedRecords(collection, extractIdentifiersFromRecords(unique), _SIGNAL);
6622
+ return result;
6623
+ }
6624
+
6625
+ // else, no dedupe, error on duplicates
6626
+ const result = Reflect.apply(target[prop], receiver, args);
6627
+ mutateReplaceRelatedRecords(collection, newValues, _SIGNAL);
6628
+ return result;
6629
+ }
6630
+ const newValues = extractIdentifiersFromRecords(adds);
6631
+ assertNoDuplicates(collection, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
6632
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6633
+ // dedupe
6634
+ const currentState = target.slice();
6635
+ currentState.splice(start, deleteCount);
6636
+ const seen = new Set(currentState);
6637
+ const unique = [];
6638
+ adds.forEach(item => {
6639
+ const identifier = recordIdentifierFor(item);
6640
+ if (!seen.has(identifier)) {
6641
+ seen.add(identifier);
6642
+ unique.push(item);
6643
+ }
6644
+ });
6645
+ const newArgs = [start, deleteCount, ...unique];
6646
+ const result = Reflect.apply(target[prop], receiver, newArgs);
6647
+ if (deleteCount > 0) {
6648
+ mutateRemoveFromRelatedRecords(collection, {
6649
+ value: result.map(recordIdentifierFor),
6650
+ index: start
6651
+ }, _SIGNAL);
6652
+ }
6653
+ if (unique.length > 0) {
6654
+ mutateAddToRelatedRecords(collection, {
6655
+ value: extractIdentifiersFromRecords(unique),
6656
+ index: start
6657
+ }, _SIGNAL);
6658
+ }
6659
+ return result;
6660
+ }
6334
6661
 
6662
+ // else, no dedupe, error on duplicates
6663
+ const result = Reflect.apply(target[prop], receiver, args);
6664
+ if (deleteCount > 0) {
6665
+ mutateRemoveFromRelatedRecords(collection, {
6666
+ value: result.map(recordIdentifierFor),
6667
+ index: start
6668
+ }, _SIGNAL);
6669
+ }
6670
+ if (newValues.length > 0) {
6671
+ mutateAddToRelatedRecords(collection, {
6672
+ value: newValues,
6673
+ index: start
6674
+ }, _SIGNAL);
6675
+ }
6676
+ return result;
6677
+ }
6678
+ default:
6679
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6680
+ {
6681
+ throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
6682
+ }
6683
+ })() : {};
6684
+ }
6685
+ }
6335
6686
  /**
6336
6687
  A `ManyArray` is a `MutableArray` that represents the contents of a has-many
6337
6688
  relationship.
@@ -6430,6 +6781,7 @@ class RelatedCollection extends IdentifierArray {
6430
6781
  */
6431
6782
 
6432
6783
  constructor(options) {
6784
+ options[MUTATE] = _MUTATE;
6433
6785
  super(options);
6434
6786
  this.isLoaded = options.isLoaded || false;
6435
6787
  this.isAsync = options.isAsync || false;
@@ -6437,204 +6789,9 @@ class RelatedCollection extends IdentifierArray {
6437
6789
  this.identifier = options.identifier;
6438
6790
  this.key = options.key;
6439
6791
  }
6440
- [MUTATE](target, receiver, prop, args, _SIGNAL) {
6441
- switch (prop) {
6442
- case 'length 0':
6443
- {
6444
- Reflect.set(target, 'length', 0);
6445
- mutateReplaceRelatedRecords(this, [], _SIGNAL);
6446
- return true;
6447
- }
6448
- case 'replace cell':
6449
- {
6450
- const [index, prior, value] = args;
6451
- target[index] = value;
6452
- mutateReplaceRelatedRecord(this, {
6453
- value,
6454
- prior,
6455
- index
6456
- }, _SIGNAL);
6457
- return true;
6458
- }
6459
- case 'push':
6460
- {
6461
- const newValues = extractIdentifiersFromRecords(args);
6462
- assertNoDuplicates(this, target, currentState => currentState.push(...newValues), `Cannot push duplicates to a hasMany's state.`);
6463
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6464
- // dedupe
6465
- const seen = new Set(target);
6466
- const unique = new Set();
6467
- args.forEach(item => {
6468
- const identifier = recordIdentifierFor(item);
6469
- if (!seen.has(identifier)) {
6470
- seen.add(identifier);
6471
- unique.add(item);
6472
- }
6473
- });
6474
- const newArgs = Array.from(unique);
6475
- const result = Reflect.apply(target[prop], receiver, newArgs);
6476
- if (newArgs.length) {
6477
- mutateAddToRelatedRecords(this, {
6478
- value: extractIdentifiersFromRecords(newArgs)
6479
- }, _SIGNAL);
6480
- }
6481
- return result;
6482
- }
6483
-
6484
- // else, no dedupe, error on duplicates
6485
- const result = Reflect.apply(target[prop], receiver, args);
6486
- if (newValues.length) {
6487
- mutateAddToRelatedRecords(this, {
6488
- value: newValues
6489
- }, _SIGNAL);
6490
- }
6491
- return result;
6492
- }
6493
- case 'pop':
6494
- {
6495
- const result = Reflect.apply(target[prop], receiver, args);
6496
- if (result) {
6497
- mutateRemoveFromRelatedRecords(this, {
6498
- value: recordIdentifierFor(result)
6499
- }, _SIGNAL);
6500
- }
6501
- return result;
6502
- }
6503
- case 'unshift':
6504
- {
6505
- const newValues = extractIdentifiersFromRecords(args);
6506
- assertNoDuplicates(this, target, currentState => currentState.unshift(...newValues), `Cannot unshift duplicates to a hasMany's state.`);
6507
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6508
- // dedupe
6509
- const seen = new Set(target);
6510
- const unique = new Set();
6511
- args.forEach(item => {
6512
- const identifier = recordIdentifierFor(item);
6513
- if (!seen.has(identifier)) {
6514
- seen.add(identifier);
6515
- unique.add(item);
6516
- }
6517
- });
6518
- const newArgs = Array.from(unique);
6519
- const result = Reflect.apply(target[prop], receiver, newArgs);
6520
- if (newArgs.length) {
6521
- mutateAddToRelatedRecords(this, {
6522
- value: extractIdentifiersFromRecords(newArgs),
6523
- index: 0
6524
- }, _SIGNAL);
6525
- }
6526
- return result;
6527
- }
6528
-
6529
- // else, no dedupe, error on duplicates
6530
- const result = Reflect.apply(target[prop], receiver, args);
6531
- if (newValues.length) {
6532
- mutateAddToRelatedRecords(this, {
6533
- value: newValues,
6534
- index: 0
6535
- }, _SIGNAL);
6536
- }
6537
- return result;
6538
- }
6539
- case 'shift':
6540
- {
6541
- const result = Reflect.apply(target[prop], receiver, args);
6542
- if (result) {
6543
- mutateRemoveFromRelatedRecords(this, {
6544
- value: recordIdentifierFor(result),
6545
- index: 0
6546
- }, _SIGNAL);
6547
- }
6548
- return result;
6549
- }
6550
- case 'sort':
6551
- {
6552
- const result = Reflect.apply(target[prop], receiver, args);
6553
- mutateSortRelatedRecords(this, result.map(recordIdentifierFor), _SIGNAL);
6554
- return result;
6555
- }
6556
- case 'splice':
6557
- {
6558
- const [start, deleteCount, ...adds] = args;
6559
-
6560
- // detect a full replace
6561
- if (start === 0 && deleteCount === this[SOURCE].length) {
6562
- const newValues = extractIdentifiersFromRecords(adds);
6563
- assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot replace a hasMany's state with a new state that contains duplicates.`);
6564
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6565
- // dedupe
6566
- const current = new Set(adds);
6567
- const unique = Array.from(current);
6568
- const newArgs = [start, deleteCount].concat(unique);
6569
- const result = Reflect.apply(target[prop], receiver, newArgs);
6570
- mutateReplaceRelatedRecords(this, extractIdentifiersFromRecords(unique), _SIGNAL);
6571
- return result;
6572
- }
6573
-
6574
- // else, no dedupe, error on duplicates
6575
- const result = Reflect.apply(target[prop], receiver, args);
6576
- mutateReplaceRelatedRecords(this, newValues, _SIGNAL);
6577
- return result;
6578
- }
6579
- const newValues = extractIdentifiersFromRecords(adds);
6580
- assertNoDuplicates(this, target, currentState => currentState.splice(start, deleteCount, ...newValues), `Cannot splice a hasMany's state with a new state that contains duplicates.`);
6581
- if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_MANY_ARRAY_DUPLICATES)) {
6582
- // dedupe
6583
- const currentState = target.slice();
6584
- currentState.splice(start, deleteCount);
6585
- const seen = new Set(currentState);
6586
- const unique = [];
6587
- adds.forEach(item => {
6588
- const identifier = recordIdentifierFor(item);
6589
- if (!seen.has(identifier)) {
6590
- seen.add(identifier);
6591
- unique.push(item);
6592
- }
6593
- });
6594
- const newArgs = [start, deleteCount, ...unique];
6595
- const result = Reflect.apply(target[prop], receiver, newArgs);
6596
- if (deleteCount > 0) {
6597
- mutateRemoveFromRelatedRecords(this, {
6598
- value: result.map(recordIdentifierFor),
6599
- index: start
6600
- }, _SIGNAL);
6601
- }
6602
- if (unique.length > 0) {
6603
- mutateAddToRelatedRecords(this, {
6604
- value: extractIdentifiersFromRecords(unique),
6605
- index: start
6606
- }, _SIGNAL);
6607
- }
6608
- return result;
6609
- }
6610
-
6611
- // else, no dedupe, error on duplicates
6612
- const result = Reflect.apply(target[prop], receiver, args);
6613
- if (deleteCount > 0) {
6614
- mutateRemoveFromRelatedRecords(this, {
6615
- value: result.map(recordIdentifierFor),
6616
- index: start
6617
- }, _SIGNAL);
6618
- }
6619
- if (newValues.length > 0) {
6620
- mutateAddToRelatedRecords(this, {
6621
- value: newValues,
6622
- index: start
6623
- }, _SIGNAL);
6624
- }
6625
- return result;
6626
- }
6627
- default:
6628
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
6629
- {
6630
- throw new Error(`unable to convert ${prop} into a transaction that updates the cache state for this record array`);
6631
- }
6632
- })() : {};
6633
- }
6634
- }
6635
- notify() {
6636
- notifyInternalSignal(this[ARRAY_SIGNAL]);
6637
- }
6792
+ notify() {
6793
+ notifyInternalSignal(this[ARRAY_SIGNAL]);
6794
+ }
6638
6795
 
6639
6796
  /**
6640
6797
  Reloads all of the records in the manyArray. If the manyArray
@@ -6953,6 +7110,11 @@ function getPromise(promise) {
6953
7110
  *
6954
7111
  */
6955
7112
  function getPromiseState(promise) {
7113
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
7114
+ if (!test) {
7115
+ throw new Error(`getPromiseState expects to be called with a promise: called with ${String(promise)}`);
7116
+ }
7117
+ })(promise) : {};
6956
7118
  const _promise = getPromise(promise);
6957
7119
  let state = PromiseCache.get(_promise);
6958
7120
  if (!state) {
@@ -6961,11 +7123,630 @@ function getPromiseState(promise) {
6961
7123
  }
6962
7124
  return state;
6963
7125
  }
7126
+ function decorateMethodV2(prototype, prop, decorators) {
7127
+ const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
7128
+ let desc = {
7129
+ ...origDesc
7130
+ };
7131
+ for (let decorator of decorators) {
7132
+ desc = decorator(prototype, prop, desc) || desc;
7133
+ }
7134
+ if (desc.initializer !== void 0) {
7135
+ desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
7136
+ desc.initializer = void 0;
7137
+ }
7138
+ Object.defineProperty(prototype, prop, desc);
7139
+ }
7140
+ const DEFAULT_DEADLINE = 30_000;
7141
+ const DISPOSE = Symbol.dispose || Symbol.for('dispose');
7142
+ function isNeverString(val) {
7143
+ return val;
7144
+ }
7145
+
7146
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7147
+
7148
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7149
+
7150
+ /**
7151
+ * A reactive class
7152
+ *
7153
+ * @hideconstructor
7154
+ */
7155
+ class RequestSubscription {
7156
+ /**
7157
+ * Whether the browser reports that the network is online.
7158
+ */
7159
+
7160
+ /**
7161
+ * Whether the browser reports that the tab is hidden.
7162
+ */
7163
+
7164
+ /**
7165
+ * Whether the component is currently refreshing the request.
7166
+ */
7167
+
7168
+ /**
7169
+ * The most recent blocking request that was made, typically
7170
+ * the result of a reload.
7171
+ *
7172
+ * This will never be the original request passed as an arg to
7173
+ * the component.
7174
+ *
7175
+ * @internal
7176
+ */
7177
+
7178
+ /**
7179
+ * The most recent request that was made, typically due to either a
7180
+ * reload or a refresh.
7181
+ *
7182
+ * This will never be the original request passed as an arg to
7183
+ * the component.
7184
+ *
7185
+ * @internal
7186
+ */
7187
+
7188
+ /**
7189
+ * The time at which the network was reported as offline.
7190
+ *
7191
+ * @internal
7192
+ */
7193
+
7194
+ /** @internal */
7195
+
7196
+ /** @internal */
7197
+
7198
+ /** @internal */
7199
+
7200
+ /** @internal */
7201
+
7202
+ /** @internal */
7203
+
7204
+ /**
7205
+ * The event listener for network status changes,
7206
+ * cached to use the reference for removal.
7207
+ *
7208
+ * @internal
7209
+ */
7210
+
7211
+ /**
7212
+ * The event listener for visibility status changes,
7213
+ * cached to use the reference for removal.
7214
+ *
7215
+ * @internal
7216
+ */
7217
+
7218
+ /**
7219
+ * The last request passed as an arg to the component,
7220
+ * cached for comparison.
7221
+ *
7222
+ * @internal
7223
+ */
7224
+
7225
+ /**
7226
+ * The last query passed as an arg to the component,
7227
+ * cached for comparison.
7228
+ *
7229
+ * @internal
7230
+ */
7231
+
7232
+ /** @internal */
7233
+
7234
+ /** @internal */
7235
+
7236
+ /** @internal */
7237
+
7238
+ /** @internal */
7239
+
7240
+ constructor(store, args) {
7241
+ this._args = args;
7242
+ this.store = store;
7243
+ this._subscribedTo = null;
7244
+ this._subscription = null;
7245
+ this._intervalStart = null;
7246
+ this._invalidated = false;
7247
+ this._nextInterval = null;
7248
+ this.isDestroyed = false;
7249
+ this[DISPOSE] = _DISPOSE;
7250
+ this._installListeners();
7251
+ void this._beginPolling();
7252
+ }
7253
+
7254
+ /**
7255
+ * @internal
7256
+ */
7257
+ async _beginPolling() {
7258
+ // await the initial request
7259
+ try {
7260
+ if (!this.isIdle) {
7261
+ await this.request;
7262
+ }
7263
+ } catch {
7264
+ // ignore errors here, we just want to wait for the request to finish
7265
+ } finally {
7266
+ if (!this.isDestroyed) {
7267
+ void this._scheduleInterval();
7268
+ }
7269
+ }
7270
+ }
7271
+ get isIdle() {
7272
+ const {
7273
+ request,
7274
+ query
7275
+ } = this._args;
7276
+ return Boolean(!request && !query);
7277
+ }
7278
+ static {
7279
+ decorateMethodV2(this.prototype, "isIdle", [memoized]);
7280
+ }
7281
+ get autorefreshTypes() {
7282
+ const {
7283
+ autorefresh
7284
+ } = this._args;
7285
+ let types;
7286
+ if (autorefresh === true) {
7287
+ types = ['online', 'invalid'];
7288
+ } else if (typeof autorefresh === 'string') {
7289
+ types = autorefresh.split(',');
7290
+ } else {
7291
+ types = [];
7292
+ }
7293
+ return new Set(types);
7294
+ }
7295
+
7296
+ // we only run this function on component creation
7297
+ // and when an update is triggered, so it does not
7298
+ // react to changes in the autorefreshThreshold
7299
+ // or autorefresh args.
7300
+ //
7301
+ // if we need to react to those changes, we can
7302
+ // use a modifier or internal component or some
7303
+ // such to trigger a re-run of this function.
7304
+ static {
7305
+ decorateMethodV2(this.prototype, "autorefreshTypes", [memoized]);
7306
+ }
7307
+ async _scheduleInterval() {
7308
+ const {
7309
+ autorefreshThreshold
7310
+ } = this._args;
7311
+ const hasValidThreshold = typeof autorefreshThreshold === 'number' && autorefreshThreshold > 0;
7312
+ if (
7313
+ // dont schedule in SSR
7314
+ typeof window === 'undefined' ||
7315
+ // dont schedule without a threshold
7316
+ !hasValidThreshold ||
7317
+ // dont schedule if we weren't told to
7318
+ !this.autorefreshTypes.has('interval') ||
7319
+ // dont schedule if we're already scheduled
7320
+ this._intervalStart !== null) {
7321
+ return;
7322
+ }
7323
+
7324
+ // if we have a current request, wait for it to finish
7325
+ // before scheduling the next one
7326
+ if (this._latestRequest) {
7327
+ try {
7328
+ await this._latestRequest;
7329
+ } catch {
7330
+ // ignore errors here, we just want to wait for the request to finish
7331
+ }
7332
+ if (this.isDestroyed) {
7333
+ return;
7334
+ }
7335
+ }
7336
+
7337
+ // setup the next interval
7338
+ this._intervalStart = Date.now();
7339
+ this._nextInterval = setTimeout(() => {
7340
+ this._maybeUpdate();
7341
+ }, autorefreshThreshold);
7342
+ }
7343
+ _clearInterval() {
7344
+ if (this._nextInterval) {
7345
+ clearTimeout(this._nextInterval);
7346
+ this._intervalStart = null;
7347
+ }
7348
+ }
7349
+ /**
7350
+ * @internal
7351
+ */
7352
+ _updateSubscriptions() {
7353
+ if (this.isIdle) {
7354
+ return;
7355
+ }
7356
+ const requestId = this._request.lid;
7357
+
7358
+ // if we're already subscribed to this request, we don't need to do anything
7359
+ if (this._subscribedTo === requestId) {
7360
+ return;
7361
+ }
7362
+
7363
+ // if we're subscribed to a different request, we need to unsubscribe
7364
+ this._removeSubscriptions();
7365
+
7366
+ // if we have a request, we need to subscribe to it
7367
+ const {
7368
+ store
7369
+ } = this;
7370
+ if (requestId && isStore(store)) {
7371
+ this._subscribedTo = requestId;
7372
+ this._subscription = store.notifications.subscribe(requestId, (_id, op) => {
7373
+ // ignore subscription events that occur while our own component's request
7374
+ // is ocurring
7375
+ if (this._isUpdating) {
7376
+ return;
7377
+ }
7378
+ switch (op) {
7379
+ case 'invalidated':
7380
+ {
7381
+ // if we're subscribed to invalidations, we need to update
7382
+ if (this.autorefreshTypes.has('invalid')) {
7383
+ this._invalidated = true;
7384
+ this._maybeUpdate();
7385
+ }
7386
+ break;
7387
+ }
7388
+ case 'state':
7389
+ {
7390
+ const latest = store.requestManager._deduped.get(requestId);
7391
+ const priority = latest?.priority;
7392
+ const state = this.reqState;
7393
+ if (!priority) {
7394
+ // if there is no priority, we have completed whatever request
7395
+ // was occurring and so we are no longer refreshing (if we were)
7396
+ this.isRefreshing = false;
7397
+ } else if (priority.blocking && !state.isLoading) {
7398
+ // if we are blocking, there is an active request for this identity
7399
+ // that MUST be fulfilled from network (not cache).
7400
+ // Thus this is not "refreshing" because we should clear out and
7401
+ // block on this request.
7402
+ //
7403
+ // we receive state notifications when either a request initiates
7404
+ // or completes.
7405
+ //
7406
+ // In the completes case: we may receive the state notification
7407
+ // slightly before the request is finalized because the NotificationManager
7408
+ // may sync flush it (and thus deliver it before the microtask completes)
7409
+ //
7410
+ // In the initiates case: we aren't supposed to receive one unless there
7411
+ // is no other request in flight for this identity.
7412
+ //
7413
+ // However, there is a race condition here where the completed
7414
+ // notification can trigger an update that generates a new request
7415
+ // thus giving us an initiated notification before the older request
7416
+ // finalizes.
7417
+ //
7418
+ // When this occurs, if the triggered update happens to have caused
7419
+ // a new request to be made for the same identity AND that request
7420
+ // is the one passed into this component as the @request arg, then
7421
+ // getRequestState will return the state of the new request.
7422
+ // We can detect this by checking if the request state is "loading"
7423
+ // as outside of this case we would have a completed request.
7424
+ //
7425
+ // That is the reason for the `&& !state.isLoading` check above.
7426
+
7427
+ // TODO should we just treat this as refreshing?
7428
+ this.isRefreshing = false;
7429
+ this._maybeUpdate('policy', true);
7430
+ } else {
7431
+ this.isRefreshing = true;
7432
+ }
7433
+ }
7434
+ }
7435
+ });
7436
+ }
7437
+ }
7438
+
7439
+ /**
7440
+ * @internal
7441
+ */
7442
+ _removeSubscriptions() {
7443
+ if (this._subscription && isStore(this.store)) {
7444
+ this.store.notifications.unsubscribe(this._subscription);
7445
+ this._subscribedTo = null;
7446
+ this._subscription = null;
7447
+ }
7448
+ }
7449
+
7450
+ /**
7451
+ * Install the event listeners for network and visibility changes.
7452
+ * This is only done in browser environments with a global `window`.
7453
+ *
7454
+ * @internal
7455
+ */
7456
+ _installListeners() {
7457
+ if (typeof window === 'undefined') {
7458
+ return;
7459
+ }
7460
+ this.isOnline = window.navigator.onLine;
7461
+ this._unavailableStart = this.isOnline ? null : Date.now();
7462
+ this.isHidden = document.visibilityState === 'hidden';
7463
+ this._onlineChanged = event => {
7464
+ this.isOnline = event.type === 'online';
7465
+ if (event.type === 'offline' && this._unavailableStart === null) {
7466
+ this._unavailableStart = Date.now();
7467
+ }
7468
+ this._maybeUpdate();
7469
+ };
7470
+ this._backgroundChanged = () => {
7471
+ const isHidden = document.visibilityState === 'hidden';
7472
+ this.isHidden = isHidden;
7473
+ if (isHidden && this._unavailableStart === null) {
7474
+ this._unavailableStart = Date.now();
7475
+ }
7476
+ this._maybeUpdate();
7477
+ };
7478
+ window.addEventListener('online', this._onlineChanged, {
7479
+ passive: true,
7480
+ capture: true
7481
+ });
7482
+ window.addEventListener('offline', this._onlineChanged, {
7483
+ passive: true,
7484
+ capture: true
7485
+ });
7486
+ document.addEventListener('visibilitychange', this._backgroundChanged, {
7487
+ passive: true,
7488
+ capture: true
7489
+ });
7490
+ }
7491
+
7492
+ /**
7493
+ * If the network is online and the tab is visible, either reload or refresh the request
7494
+ * based on the component's configuration and the requested update mode.
7495
+ *
7496
+ * Valid modes are:
7497
+ *
7498
+ * - `'reload'`: Force a reload of the request.
7499
+ * - `'refresh'`: Refresh the request in the background.
7500
+ * - `'policy'`: Make the request, letting the store's configured CachePolicy decide whether to reload, refresh, or do nothing.
7501
+ * - `undefined`: Make the request using the component's autorefreshBehavior setting if the autorefreshThreshold has passed.
7502
+ *
7503
+ * @internal
7504
+ */
7505
+ _maybeUpdate(mode, silent) {
7506
+ if (this.isIdle) {
7507
+ return;
7508
+ }
7509
+ const canAttempt = Boolean(this.isOnline && !this.isHidden && (mode || this.autorefreshTypes.size));
7510
+ if (!canAttempt) {
7511
+ if (!silent && mode && mode !== '_invalidated') {
7512
+ throw new Error(`Reload not available: the network is not online or the tab is hidden`);
7513
+ }
7514
+ return;
7515
+ }
7516
+ const {
7517
+ autorefreshTypes
7518
+ } = this;
7519
+ let shouldAttempt = this._invalidated || Boolean(mode);
7520
+ if (!shouldAttempt && autorefreshTypes.has('online')) {
7521
+ const {
7522
+ _unavailableStart
7523
+ } = this;
7524
+ const {
7525
+ autorefreshThreshold
7526
+ } = this._args;
7527
+ const deadline = typeof autorefreshThreshold === 'number' ? autorefreshThreshold : DEFAULT_DEADLINE;
7528
+ shouldAttempt = Boolean(_unavailableStart && Date.now() - _unavailableStart > deadline);
7529
+ }
7530
+ if (!shouldAttempt && autorefreshTypes.has('interval')) {
7531
+ const {
7532
+ _intervalStart
7533
+ } = this;
7534
+ const {
7535
+ autorefreshThreshold
7536
+ } = this._args;
7537
+ if (_intervalStart && typeof autorefreshThreshold === 'number' && autorefreshThreshold > 0) {
7538
+ shouldAttempt = Boolean(Date.now() - _intervalStart >= autorefreshThreshold);
7539
+ }
7540
+ }
7541
+ this._unavailableStart = null;
7542
+ this._invalidated = false;
7543
+ if (shouldAttempt) {
7544
+ this._clearInterval();
7545
+ const request = Object.assign({}, this.reqState.request);
7546
+ const realMode = mode === '_invalidated' ? null : mode;
7547
+ const val = realMode ?? this._args.autorefreshBehavior ?? 'policy';
7548
+ switch (val) {
7549
+ case 'reload':
7550
+ request.cacheOptions = Object.assign({}, request.cacheOptions, {
7551
+ reload: true
7552
+ });
7553
+ break;
7554
+ case 'refresh':
7555
+ request.cacheOptions = Object.assign({}, request.cacheOptions, {
7556
+ backgroundReload: true
7557
+ });
7558
+ break;
7559
+ case 'policy':
7560
+ break;
7561
+ default:
7562
+ throw new Error(`Invalid ${mode ? 'update mode' : '@autorefreshBehavior'} for <Request />: ${isNeverString(val)}`);
7563
+ }
7564
+ const wasStoreRequest = request[EnableHydration] === true;
7565
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
7566
+ if (!test) {
7567
+ throw new Error(`Cannot supply a different store than was used to create the request`);
7568
+ }
7569
+ })(!request.store || request.store === this.store) : {};
7570
+ const store = request.store || this.store;
7571
+ const requester = wasStoreRequest && 'requestManager' in store ? store.requestManager : store;
7572
+ this._isUpdating = true;
7573
+ this._latestRequest = requester.request(request);
7574
+ if (val !== 'refresh') {
7575
+ this._localRequest = this._latestRequest;
7576
+ }
7577
+ void this._scheduleInterval();
7578
+ void this._latestRequest.finally(() => {
7579
+ this._isUpdating = false;
7580
+ });
7581
+ }
7582
+ }
7583
+
7584
+ /**
7585
+ * Retry the request, reloading it from the server.
7586
+ */
7587
+ retry = async () => {
7588
+ this._maybeUpdate('reload');
7589
+ await this._localRequest;
7590
+ };
7591
+
7592
+ /**
7593
+ * Refresh the request, updating it in the background.
7594
+ */
7595
+ refresh = async () => {
7596
+ this._maybeUpdate('refresh');
7597
+ await this._latestRequest;
7598
+ };
7599
+
7600
+ /**
7601
+ * features to yield to the error slot of a component
7602
+ */
7603
+ get errorFeatures() {
7604
+ return {
7605
+ isHidden: this.isHidden,
7606
+ isOnline: this.isOnline,
7607
+ retry: this.retry
7608
+ };
7609
+ }
7610
+
7611
+ /**
7612
+ * features to yield to the content slot of a component
7613
+ */
7614
+ static {
7615
+ decorateMethodV2(this.prototype, "errorFeatures", [memoized]);
7616
+ }
7617
+ get contentFeatures() {
7618
+ const feat = {
7619
+ isHidden: this.isHidden,
7620
+ isOnline: this.isOnline,
7621
+ reload: this.retry,
7622
+ refresh: this.refresh,
7623
+ isRefreshing: this.isRefreshing,
7624
+ latestRequest: this._latestRequest
7625
+ };
7626
+ if (feat.isRefreshing) {
7627
+ feat.abort = () => {
7628
+ this._latestRequest?.abort();
7629
+ };
7630
+ }
7631
+ return feat;
7632
+ }
7633
+
7634
+ /**
7635
+ * @internal
7636
+ */
7637
+ static {
7638
+ decorateMethodV2(this.prototype, "contentFeatures", [memoized]);
7639
+ }
7640
+ get _request() {
7641
+ const {
7642
+ request,
7643
+ query
7644
+ } = this._args;
7645
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
7646
+ if (!test) {
7647
+ throw new Error(`Cannot use both @request and @query args with the <Request> component`);
7648
+ }
7649
+ })(!request || !query) : {};
7650
+ const {
7651
+ _localRequest,
7652
+ _originalRequest,
7653
+ _originalQuery
7654
+ } = this;
7655
+ const isOriginalRequest = request === _originalRequest && query === _originalQuery;
7656
+ if (_localRequest && isOriginalRequest) {
7657
+ return _localRequest;
7658
+ }
7659
+
7660
+ // update state checks for the next time
7661
+ this._originalQuery = query;
7662
+ this._originalRequest = request;
7663
+ if (request) {
7664
+ return request;
7665
+ }
7666
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
7667
+ if (!test) {
7668
+ throw new Error(`You must provide either @request or an @query arg with the <Request> component`);
7669
+ }
7670
+ })(query) : {};
7671
+ // @ts-expect-error TODO investigate this
7672
+ return this.store.request(query);
7673
+ }
7674
+ static {
7675
+ decorateMethodV2(this.prototype, "_request", [memoized]);
7676
+ }
7677
+ get request() {
7678
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
7679
+ try {
7680
+ const request = this._request;
7681
+ this._updateSubscriptions();
7682
+ return request;
7683
+ } catch (e) {
7684
+ // eslint-disable-next-line no-console
7685
+ console.log(e);
7686
+ throw new Error(`Unable to initialize the request`, {
7687
+ cause: e
7688
+ });
7689
+ }
7690
+ } else {
7691
+ const request = this._request;
7692
+ this._updateSubscriptions();
7693
+ return request;
7694
+ }
7695
+ }
7696
+ static {
7697
+ decorateMethodV2(this.prototype, "request", [memoized]);
7698
+ }
7699
+ get reqState() {
7700
+ return getRequestState(this.request);
7701
+ }
7702
+ get result() {
7703
+ return this.reqState.result;
7704
+ }
7705
+ }
7706
+ defineSignal(RequestSubscription.prototype, 'isOnline', true);
7707
+ defineSignal(RequestSubscription.prototype, 'isHidden', false);
7708
+ defineSignal(RequestSubscription.prototype, 'isRefreshing', false);
7709
+ defineSignal(RequestSubscription.prototype, '_localRequest', undefined);
7710
+ defineSignal(RequestSubscription.prototype, '_latestRequest', undefined);
7711
+ function isStore(store) {
7712
+ return 'requestManager' in store;
7713
+ }
7714
+ function createRequestSubscription(store, args) {
7715
+ return new RequestSubscription(store, args);
7716
+ }
7717
+ function upgradeSubscription(sub) {
7718
+ return sub;
7719
+ }
7720
+ function _DISPOSE() {
7721
+ const self = upgradeSubscription(this);
7722
+ self.isDestroyed = true;
7723
+ self._removeSubscriptions();
7724
+ if (typeof window === 'undefined') {
7725
+ return;
7726
+ }
7727
+ self._clearInterval();
7728
+ window.removeEventListener('online', self._onlineChanged, {
7729
+ passive: true,
7730
+ capture: true
7731
+ });
7732
+ window.removeEventListener('offline', self._onlineChanged, {
7733
+ passive: true,
7734
+ capture: true
7735
+ });
7736
+ document.removeEventListener('visibilitychange', self._backgroundChanged, {
7737
+ passive: true,
7738
+ capture: true
7739
+ });
7740
+ }
6964
7741
  const RequestCache = new WeakMap();
6965
7742
  function isAbortError(error) {
6966
7743
  return error instanceof DOMException && error.name === 'AbortError';
6967
7744
  }
6968
- async function watchStream(stream, state) {
7745
+ function upgradeLoadingState(state) {
7746
+ return state;
7747
+ }
7748
+ async function watchStream(stream, loadingState) {
7749
+ const state = upgradeLoadingState(loadingState);
6969
7750
  const reader = stream.getReader();
6970
7751
  let bytesLoaded = 0;
6971
7752
  let shouldForward = state._stream !== null && state._stream.readable.locked;
@@ -7355,4 +8136,4 @@ function getRequestState(future) {
7355
8136
  }
7356
8137
  return state;
7357
8138
  }
7358
- export { peekInternalSignal as A, withSignalStore as B, Collection as C, notifyInternalSignal as D, consumeInternalSignal as E, getOrCreateInternalSignal as F, ReactiveDocument as G, setIdentifierGenerationMethod as H, IdentifierArray as I, setIdentifierUpdateMethod as J, setIdentifierForgetMethod as K, setIdentifierResetMethod as L, MUTATE as M, setKeyInfoForResource as N, RecordArrayManager as R, Store as S, _clearCaches as _, isDocumentIdentifier as a, coerceId as b, constructResource as c, SOURCE as d, ensureStringId as e, fastPush as f, removeRecordDataFor as g, setRecordIdentifier as h, isStableIdentifier as i, StoreMap as j, setCacheFor as k, RelatedCollection as l, log as m, normalizeModelName as n, logGroup as o, peekCache as p, getPromiseState as q, recordIdentifierFor as r, storeFor as s, getRequestState as t, memoized as u, gate as v, entangleSignal as w, defineSignal as x, defineNonEnumerableSignal as y, Signals as z };
8139
+ export { Signals as A, peekInternalSignal as B, Collection as C, DISPOSE as D, withSignalStore as E, notifyInternalSignal as F, consumeInternalSignal as G, getOrCreateInternalSignal as H, IdentifierArray as I, ReactiveDocument as J, setIdentifierGenerationMethod as K, setIdentifierUpdateMethod as L, MUTATE as M, setIdentifierForgetMethod as N, setIdentifierResetMethod as O, setKeyInfoForResource as P, isExtensionProp as Q, RecordArrayManager as R, Store as S, performExtensionSet as T, performArrayExtensionGet as U, performObjectExtensionGet as V, _clearCaches as _, isDocumentIdentifier as a, coerceId as b, constructResource as c, SOURCE as d, ensureStringId as e, fastPush as f, removeRecordDataFor as g, setRecordIdentifier as h, isStableIdentifier as i, StoreMap as j, setCacheFor as k, RelatedCollection as l, log as m, normalizeModelName as n, logGroup as o, peekCache as p, getPromiseState as q, recordIdentifierFor as r, storeFor as s, createRequestSubscription as t, getRequestState as u, memoized as v, gate as w, entangleSignal as x, defineSignal as y, defineNonEnumerableSignal as z };