@warp-drive/core 5.9.0-beta.1 → 5.9.0-beta.2

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 (277) hide show
  1. package/dist/{unpkg/dev-deprecated/-private-DL4tfrv9.js → -private-BYn1Vh-L.js} +2 -2
  2. package/dist/{-private-b1g4dhl0.js.map → -private-BYn1Vh-L.js.map} +1 -1
  3. package/dist/{-private-DMzvF_Q6.js → -private-CyhhcK1a.js} +2 -2
  4. package/dist/-private-CyhhcK1a.js.map +1 -0
  5. package/dist/-private-zrP4VGAf.js +3530 -0
  6. package/dist/-private-zrP4VGAf.js.map +1 -0
  7. package/{declarations/concepts-LHsLJZMl.d.ts → dist/concepts-DFldVwEM.d.ts} +2 -2
  8. package/{declarations/concepts-LHsLJZMl.d.ts.map → dist/concepts-DFldVwEM.d.ts.map} +1 -1
  9. package/dist/configure.js +1 -1
  10. package/dist/graph/-private.d.ts +2 -0
  11. package/dist/graph/-private.js +46 -33
  12. package/dist/graph/-private.js.map +1 -1
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +1 -1
  15. package/{declarations/internal-Cz-893zD.d.ts → dist/internal-DtWOpxrR.d.ts} +2763 -2271
  16. package/dist/internal-DtWOpxrR.d.ts.map +1 -0
  17. package/dist/reactive/-private.d.ts +2 -0
  18. package/dist/reactive/-private.js +1 -1
  19. package/dist/reactive.d.ts +2 -0
  20. package/dist/reactive.js +3 -3
  21. package/{declarations → dist}/record-D3QQcaIR.d.ts.map +1 -1
  22. package/dist/{request--vRFALbQ.js → request-7BJFgSu_.js} +2 -2
  23. package/dist/request-7BJFgSu_.js.map +1 -0
  24. package/dist/request.d.ts +2 -0
  25. package/dist/request.js +1 -1
  26. package/dist/signals/-leaked.d.ts +1060 -0
  27. package/dist/signals/-leaked.d.ts.map +1 -0
  28. package/dist/signals/-leaked.js +2 -2
  29. package/dist/{src-Dex_phWI.js → src-BOAWJH_S.js} +192 -53
  30. package/dist/src-BOAWJH_S.js.map +1 -0
  31. package/dist/store/-private.d.ts +2 -0
  32. package/dist/store/-private.js +1 -1
  33. package/dist/store-DNF9Rgoh.js.map +1 -1
  34. package/dist/store.d.ts +2 -0
  35. package/{declarations → dist}/types/-private.d.ts +1 -1
  36. package/{declarations → dist}/types/-private.d.ts.map +1 -1
  37. package/dist/types/-private.js +1 -1
  38. package/dist/types/cache.d.ts +2 -0
  39. package/dist/types/record.js.map +1 -1
  40. package/dist/types/request.d.ts +2 -0
  41. package/dist/types/request.js +1 -1
  42. package/dist/types/request.js.map +1 -1
  43. package/dist/types/runtime.js +1 -1
  44. package/dist/types/schema/concepts.d.ts +2 -0
  45. package/dist/types/schema/fields.js.map +1 -1
  46. package/dist/types/schema/schema-service.d.ts +2 -0
  47. package/dist/types/symbols.js +1 -1
  48. package/dist/types/symbols.js.map +1 -1
  49. package/{declarations → dist}/types.d.ts +1 -1
  50. package/dist/unpkg/dev/-private-BoSTJwp9.js +3519 -0
  51. package/dist/unpkg/dev/-private-BoSTJwp9.js.map +1 -0
  52. package/dist/{-private-b1g4dhl0.js → unpkg/dev/-private-CUkeqUhO.js} +2 -2
  53. package/dist/unpkg/{dev-deprecated/-private-DL4tfrv9.js.map → dev/-private-CUkeqUhO.js.map} +1 -1
  54. package/dist/unpkg/{dev-deprecated/-private-2RfQ2761.js → dev/-private-D6Tw25AD.js} +2 -2
  55. package/dist/unpkg/dev/-private-D6Tw25AD.js.map +1 -0
  56. package/dist/unpkg/dev/configure.js +1 -1
  57. package/dist/unpkg/dev/graph/-private.js +46 -33
  58. package/dist/unpkg/dev/graph/-private.js.map +1 -1
  59. package/dist/unpkg/dev/index.js +1 -1
  60. package/dist/unpkg/dev/reactive/-private.js +1 -1
  61. package/dist/unpkg/dev/reactive.js +3 -3
  62. package/dist/unpkg/{dev-deprecated/request-DAuXbfYi.js → dev/request-CwjpJB3r.js} +2 -2
  63. package/dist/unpkg/dev/request-CwjpJB3r.js.map +1 -0
  64. package/dist/unpkg/dev/request.js +1 -1
  65. package/dist/unpkg/dev/{runtime-EoVKAhTv.js → runtime-DoDtzXJb.js} +2 -2
  66. package/dist/unpkg/dev/runtime-DoDtzXJb.js.map +1 -0
  67. package/dist/unpkg/dev/signals/-leaked.js +2 -2
  68. package/dist/unpkg/dev/{src-Bxlr_vue.js → src-CP6e_ozt.js} +194 -55
  69. package/dist/unpkg/dev/src-CP6e_ozt.js.map +1 -0
  70. package/dist/unpkg/dev/store/-private.js +1 -1
  71. package/dist/unpkg/{dev-deprecated/store-TcP2H4Af.js → dev/store-DamE3C4y.js} +2 -2
  72. package/dist/unpkg/dev/store-DamE3C4y.js.map +1 -0
  73. package/dist/unpkg/dev/store.js +1 -1
  74. package/dist/unpkg/dev/types/-private.js +1 -1
  75. package/dist/unpkg/dev/types/record.js.map +1 -1
  76. package/dist/unpkg/dev/types/request.js +1 -1
  77. package/dist/unpkg/dev/types/request.js.map +1 -1
  78. package/dist/unpkg/dev/types/runtime.js +1 -1
  79. package/dist/unpkg/dev/types/schema/fields.js.map +1 -1
  80. package/dist/unpkg/dev/types/symbols.js +1 -1
  81. package/dist/unpkg/dev/types/symbols.js.map +1 -1
  82. package/dist/unpkg/dev-deprecated/-private-BoSTJwp9.js +3519 -0
  83. package/dist/unpkg/dev-deprecated/-private-BoSTJwp9.js.map +1 -0
  84. package/dist/unpkg/{dev/-private-DL4tfrv9.js → dev-deprecated/-private-CUkeqUhO.js} +2 -2
  85. package/dist/unpkg/{prod/-private-Z9i0icpE.js.map → dev-deprecated/-private-CUkeqUhO.js.map} +1 -1
  86. package/dist/unpkg/{dev/-private-2RfQ2761.js → dev-deprecated/-private-D6Tw25AD.js} +2 -2
  87. package/dist/unpkg/dev-deprecated/-private-D6Tw25AD.js.map +1 -0
  88. package/dist/unpkg/dev-deprecated/configure.js +1 -1
  89. package/dist/unpkg/dev-deprecated/graph/-private.js +47 -34
  90. package/dist/unpkg/dev-deprecated/graph/-private.js.map +1 -1
  91. package/dist/unpkg/dev-deprecated/index.js +1 -1
  92. package/dist/unpkg/dev-deprecated/reactive/-private.js +1 -1
  93. package/dist/unpkg/dev-deprecated/reactive.js +3 -3
  94. package/dist/unpkg/{dev/request-DAuXbfYi.js → dev-deprecated/request-CwjpJB3r.js} +2 -2
  95. package/dist/unpkg/dev-deprecated/request-CwjpJB3r.js.map +1 -0
  96. package/dist/unpkg/dev-deprecated/request.js +1 -1
  97. package/dist/unpkg/dev-deprecated/{runtime-BacZMq1r.js → runtime-CPL2BGgT.js} +2 -2
  98. package/dist/unpkg/dev-deprecated/runtime-CPL2BGgT.js.map +1 -0
  99. package/dist/unpkg/dev-deprecated/signals/-leaked.js +2 -2
  100. package/dist/unpkg/dev-deprecated/{src-DEl2Ca3T.js → src-De8OV58h.js} +195 -56
  101. package/dist/unpkg/dev-deprecated/src-De8OV58h.js.map +1 -0
  102. package/dist/unpkg/dev-deprecated/store/-private.js +1 -1
  103. package/dist/unpkg/{dev/store-DmiFvT1B.js → dev-deprecated/store-Bsdz5mRe.js} +2 -2
  104. package/dist/unpkg/dev-deprecated/store-Bsdz5mRe.js.map +1 -0
  105. package/dist/unpkg/dev-deprecated/store.js +1 -1
  106. package/dist/unpkg/dev-deprecated/types/-private.js +1 -1
  107. package/dist/unpkg/dev-deprecated/types/record.js.map +1 -1
  108. package/dist/unpkg/dev-deprecated/types/request.js +1 -1
  109. package/dist/unpkg/dev-deprecated/types/request.js.map +1 -1
  110. package/dist/unpkg/dev-deprecated/types/runtime.js +1 -1
  111. package/dist/unpkg/dev-deprecated/types/schema/fields.js.map +1 -1
  112. package/dist/unpkg/dev-deprecated/types/symbols.js +1 -1
  113. package/dist/unpkg/dev-deprecated/types/symbols.js.map +1 -1
  114. package/dist/unpkg/prod/-private-B36B1ztP.js +22 -0
  115. package/dist/unpkg/{prod-deprecated/-private-Z9i0icpE.js.map → prod/-private-B36B1ztP.js.map} +1 -1
  116. package/dist/unpkg/prod/-private-DHco-h0q.js +3294 -0
  117. package/dist/unpkg/prod/-private-DHco-h0q.js.map +1 -0
  118. package/dist/unpkg/prod/{-private-BK71-uXR.js → -private-Dhl123OI.js} +2 -2
  119. package/dist/unpkg/prod/-private-Dhl123OI.js.map +1 -0
  120. package/dist/unpkg/prod/configure.js +1 -1
  121. package/dist/unpkg/prod/graph/-private.js +45 -32
  122. package/dist/unpkg/prod/graph/-private.js.map +1 -1
  123. package/dist/unpkg/prod/index.js +1 -1
  124. package/dist/unpkg/prod/reactive/-private.js +1 -1
  125. package/dist/unpkg/prod/reactive.js +3 -3
  126. package/dist/unpkg/prod/{request-BcJNzSgv.js → request-BBdC1Sz7.js} +2 -2
  127. package/dist/unpkg/prod/request-BBdC1Sz7.js.map +1 -0
  128. package/dist/unpkg/prod/request.js +1 -1
  129. package/dist/unpkg/prod/signals/-leaked.js +2 -2
  130. package/dist/unpkg/prod/{src-Dzz-j6pp.js → src-nFHlZgKa.js} +196 -53
  131. package/dist/unpkg/prod/src-nFHlZgKa.js.map +1 -0
  132. package/dist/unpkg/prod/store/-private.js +1 -1
  133. package/dist/unpkg/prod/store-BWhmb7Ob.js.map +1 -1
  134. package/dist/unpkg/prod/types/-private.js +1 -1
  135. package/dist/unpkg/prod/types/record.js.map +1 -1
  136. package/dist/unpkg/prod/types/request.js +1 -1
  137. package/dist/unpkg/prod/types/request.js.map +1 -1
  138. package/dist/unpkg/prod/types/runtime.js +1 -1
  139. package/dist/unpkg/prod/types/schema/fields.js.map +1 -1
  140. package/dist/unpkg/prod/types/symbols.js +1 -1
  141. package/dist/unpkg/prod/types/symbols.js.map +1 -1
  142. package/dist/unpkg/prod-deprecated/{-private-Z9i0icpE.js → -private-B36B1ztP.js} +2 -2
  143. package/dist/unpkg/{dev/-private-DL4tfrv9.js.map → prod-deprecated/-private-B36B1ztP.js.map} +1 -1
  144. package/dist/unpkg/prod-deprecated/-private-DHco-h0q.js +3294 -0
  145. package/dist/unpkg/prod-deprecated/-private-DHco-h0q.js.map +1 -0
  146. package/dist/unpkg/prod-deprecated/{-private-BK71-uXR.js → -private-Dhl123OI.js} +2 -2
  147. package/dist/unpkg/prod-deprecated/-private-Dhl123OI.js.map +1 -0
  148. package/dist/unpkg/prod-deprecated/configure.js +1 -1
  149. package/dist/unpkg/prod-deprecated/graph/-private.js +46 -35
  150. package/dist/unpkg/prod-deprecated/graph/-private.js.map +1 -1
  151. package/dist/unpkg/prod-deprecated/index.js +1 -1
  152. package/dist/unpkg/prod-deprecated/reactive/-private.js +1 -1
  153. package/dist/unpkg/prod-deprecated/reactive.js +3 -3
  154. package/dist/unpkg/prod-deprecated/{request-BcJNzSgv.js → request-BBdC1Sz7.js} +2 -2
  155. package/dist/unpkg/prod-deprecated/request-BBdC1Sz7.js.map +1 -0
  156. package/dist/unpkg/prod-deprecated/request.js +1 -1
  157. package/dist/unpkg/prod-deprecated/signals/-leaked.js +2 -2
  158. package/dist/unpkg/prod-deprecated/{src-BOifHFQ5.js → src-Cku5ymUJ.js} +197 -54
  159. package/dist/unpkg/prod-deprecated/src-Cku5ymUJ.js.map +1 -0
  160. package/dist/unpkg/prod-deprecated/store/-private.js +1 -1
  161. package/dist/unpkg/prod-deprecated/store-BWhmb7Ob.js.map +1 -1
  162. package/dist/unpkg/prod-deprecated/types/-private.js +1 -1
  163. package/dist/unpkg/prod-deprecated/types/record.js.map +1 -1
  164. package/dist/unpkg/prod-deprecated/types/request.js +1 -1
  165. package/dist/unpkg/prod-deprecated/types/request.js.map +1 -1
  166. package/dist/unpkg/prod-deprecated/types/runtime.js +1 -1
  167. package/dist/unpkg/prod-deprecated/types/schema/fields.js.map +1 -1
  168. package/dist/unpkg/prod-deprecated/types/symbols.js +1 -1
  169. package/dist/unpkg/prod-deprecated/types/symbols.js.map +1 -1
  170. package/package.json +15 -19
  171. package/declarations/graph/-private.d.ts +0 -2
  172. package/declarations/index.d.ts +0 -2
  173. package/declarations/internal-Cz-893zD.d.ts.map +0 -1
  174. package/declarations/reactive/-private.d.ts +0 -2
  175. package/declarations/reactive.d.ts +0 -2
  176. package/declarations/request.d.ts +0 -2
  177. package/declarations/signals/-leaked.d.ts +0 -63
  178. package/declarations/signals/-leaked.d.ts.map +0 -1
  179. package/declarations/store/-private.d.ts +0 -2
  180. package/declarations/store.d.ts +0 -8358
  181. package/declarations/store.d.ts.map +0 -1
  182. package/declarations/types/cache.d.ts +0 -2
  183. package/declarations/types/request.d.ts +0 -2
  184. package/declarations/types/schema/concepts.d.ts +0 -2
  185. package/declarations/types/schema/schema-service.d.ts +0 -2
  186. package/dist/-private-DMzvF_Q6.js.map +0 -1
  187. package/dist/-private-HjaQ1wp1.js +0 -1695
  188. package/dist/-private-HjaQ1wp1.js.map +0 -1
  189. package/dist/request--vRFALbQ.js.map +0 -1
  190. package/dist/src-Dex_phWI.js.map +0 -1
  191. package/dist/unpkg/dev/-private-2RfQ2761.js.map +0 -1
  192. package/dist/unpkg/dev/-private-CM1zxNws.js +0 -1684
  193. package/dist/unpkg/dev/-private-CM1zxNws.js.map +0 -1
  194. package/dist/unpkg/dev/request-DAuXbfYi.js.map +0 -1
  195. package/dist/unpkg/dev/runtime-EoVKAhTv.js.map +0 -1
  196. package/dist/unpkg/dev/src-Bxlr_vue.js.map +0 -1
  197. package/dist/unpkg/dev/store-DmiFvT1B.js.map +0 -1
  198. package/dist/unpkg/dev-deprecated/-private-2RfQ2761.js.map +0 -1
  199. package/dist/unpkg/dev-deprecated/-private-CM1zxNws.js +0 -1684
  200. package/dist/unpkg/dev-deprecated/-private-CM1zxNws.js.map +0 -1
  201. package/dist/unpkg/dev-deprecated/request-DAuXbfYi.js.map +0 -1
  202. package/dist/unpkg/dev-deprecated/runtime-BacZMq1r.js.map +0 -1
  203. package/dist/unpkg/dev-deprecated/src-DEl2Ca3T.js.map +0 -1
  204. package/dist/unpkg/dev-deprecated/store-TcP2H4Af.js.map +0 -1
  205. package/dist/unpkg/prod/-private-BK71-uXR.js.map +0 -1
  206. package/dist/unpkg/prod/-private-TNaS5Piv.js +0 -1494
  207. package/dist/unpkg/prod/-private-TNaS5Piv.js.map +0 -1
  208. package/dist/unpkg/prod/-private-Z9i0icpE.js +0 -22
  209. package/dist/unpkg/prod/request-BcJNzSgv.js.map +0 -1
  210. package/dist/unpkg/prod/src-Dzz-j6pp.js.map +0 -1
  211. package/dist/unpkg/prod-deprecated/-private-BK71-uXR.js.map +0 -1
  212. package/dist/unpkg/prod-deprecated/-private-TNaS5Piv.js +0 -1494
  213. package/dist/unpkg/prod-deprecated/-private-TNaS5Piv.js.map +0 -1
  214. package/dist/unpkg/prod-deprecated/request-BcJNzSgv.js.map +0 -1
  215. package/dist/unpkg/prod-deprecated/src-BOifHFQ5.js.map +0 -1
  216. /package/{declarations → dist}/aliases-BWYW5EhX.d.ts +0 -0
  217. /package/{declarations → dist}/aliases-BWYW5EhX.d.ts.map +0 -0
  218. /package/{declarations → dist}/build-config/babel-macros.d.ts +0 -0
  219. /package/{declarations → dist}/build-config/canary-features.d.ts +0 -0
  220. /package/{declarations → dist}/build-config/debugging.d.ts +0 -0
  221. /package/{declarations → dist}/build-config/deprecations.d.ts +0 -0
  222. /package/{declarations → dist}/build-config/env.d.ts +0 -0
  223. /package/{declarations → dist}/build-config/macros.d.ts +0 -0
  224. /package/{declarations → dist}/build-config.d.ts +0 -0
  225. /package/{declarations → dist}/change-C7kqv2kW.d.ts +0 -0
  226. /package/{declarations → dist}/change-C7kqv2kW.d.ts.map +0 -0
  227. /package/{declarations → dist}/configure-B_F639tN.d.ts +0 -0
  228. /package/{declarations → dist}/configure-B_F639tN.d.ts.map +0 -0
  229. /package/{declarations → dist}/configure.d.ts +0 -0
  230. /package/{declarations → dist}/document-BEn91SwT.d.ts +0 -0
  231. /package/{declarations → dist}/document-BEn91SwT.d.ts.map +0 -0
  232. /package/{declarations → dist}/error-50OSEhsF.d.ts +0 -0
  233. /package/{declarations → dist}/error-50OSEhsF.d.ts.map +0 -0
  234. /package/{declarations → dist}/fields-FM7peCiM.d.ts +0 -0
  235. /package/{declarations → dist}/fields-FM7peCiM.d.ts.map +0 -0
  236. /package/{declarations → dist}/graph-DLqYXP2z.d.ts +0 -0
  237. /package/{declarations → dist}/graph-DLqYXP2z.d.ts.map +0 -0
  238. /package/{declarations → dist}/identifier-DQnqOSJK.d.ts +0 -0
  239. /package/{declarations → dist}/identifier-DQnqOSJK.d.ts.map +0 -0
  240. /package/{declarations → dist}/json-api-raw-C5APJHHB.d.ts +0 -0
  241. /package/{declarations → dist}/json-api-raw-C5APJHHB.d.ts.map +0 -0
  242. /package/{declarations → dist}/mutations-CqtoGB4t.d.ts +0 -0
  243. /package/{declarations → dist}/mutations-CqtoGB4t.d.ts.map +0 -0
  244. /package/{declarations → dist}/operations-D1qA6r0_.d.ts +0 -0
  245. /package/{declarations → dist}/operations-D1qA6r0_.d.ts.map +0 -0
  246. /package/{declarations → dist}/params-DrEx3bf8.d.ts +0 -0
  247. /package/{declarations → dist}/params-DrEx3bf8.d.ts.map +0 -0
  248. /package/{declarations → dist}/raw-D5hnjiq7.d.ts +0 -0
  249. /package/{declarations → dist}/raw-D5hnjiq7.d.ts.map +0 -0
  250. /package/{declarations → dist}/record-D3QQcaIR.d.ts +0 -0
  251. /package/{declarations → dist}/relationship-CmHzMPKf.d.ts +0 -0
  252. /package/{declarations → dist}/relationship-CmHzMPKf.d.ts.map +0 -0
  253. /package/{declarations → dist}/symbols-DjRDCeX0.d.ts +0 -0
  254. /package/{declarations → dist}/symbols-DjRDCeX0.d.ts.map +0 -0
  255. /package/{declarations → dist}/types/cache/aliases.d.ts +0 -0
  256. /package/{declarations → dist}/types/cache/change.d.ts +0 -0
  257. /package/{declarations → dist}/types/cache/mutations.d.ts +0 -0
  258. /package/{declarations → dist}/types/cache/operations.d.ts +0 -0
  259. /package/{declarations → dist}/types/cache/relationship.d.ts +0 -0
  260. /package/{declarations → dist}/types/graph.d.ts +0 -0
  261. /package/{declarations → dist}/types/identifier.d.ts +0 -0
  262. /package/{declarations → dist}/types/json/raw.d.ts +0 -0
  263. /package/{declarations → dist}/types/params.d.ts +0 -0
  264. /package/{declarations → dist}/types/record.d.ts +0 -0
  265. /package/{declarations → dist}/types/runtime.d.ts +0 -0
  266. /package/{declarations → dist}/types/runtime.d.ts.map +0 -0
  267. /package/{declarations → dist}/types/schema/fields.d.ts +0 -0
  268. /package/{declarations → dist}/types/schema/fields.type-test.d.ts +0 -0
  269. /package/{declarations → dist}/types/spec/document.d.ts +0 -0
  270. /package/{declarations → dist}/types/spec/error.d.ts +0 -0
  271. /package/{declarations → dist}/types/spec/json-api-raw.d.ts +0 -0
  272. /package/{declarations → dist}/types/symbols.d.ts +0 -0
  273. /package/{declarations → dist}/types/utils.d.ts +0 -0
  274. /package/{declarations → dist}/utils/string.d.ts +0 -0
  275. /package/{declarations → dist}/utils/string.d.ts.map +0 -0
  276. /package/{declarations → dist}/utils-BtURiy8l.d.ts +0 -0
  277. /package/{declarations → dist}/utils-BtURiy8l.d.ts.map +0 -0
@@ -1,1695 +0,0 @@
1
- import { a as setTransient, r as peekTransient, t as getOrSetGlobal } from "./-private-DMzvF_Q6.js";
2
- import { f as setPromiseResult, o as DOMError, u as getPromiseResult } from "./request--vRFALbQ.js";
3
- import { getGlobalConfig, macroCondition } from "@embroider/macros";
4
-
5
- //#region src/signals/reactivity/configure.ts
6
- const ARRAY_SIGNAL = getOrSetGlobal("#[]", Symbol("#[]"));
7
- const OBJECT_SIGNAL = getOrSetGlobal("#{}", Symbol("#{}"));
8
- /**
9
- * An Opaque type that represents a framework specific or TC39 signal.
10
- *
11
- * It may be an array of signals or a single signal.
12
- *
13
- * @private
14
- */
15
- /**
16
- * The hooks which MUST be configured in order to use reactive arrays,
17
- * resources and documents with framework specfic signals or TC39 signals.
18
- *
19
- * Support for multiple frameworks simultaneously can be done via
20
- * this abstraction by returning multiple signals from the `createSignal`
21
- * method, and consuming the correct one via the correct framework via
22
- * the `consumeSignal` and `notifySignal` methods.
23
- *
24
- * Unlike many signals implementations, WarpDrive does not wrap values as
25
- * signals directly, but instead uses signals to alert the reactive layer
26
- * to changes in the underlying cache. E.g. a signal is associated to a value,
27
- * but does not serve as the cache for that value directly. We refer to this as
28
- * a "gate", the pattern has also been called "side-signals".
29
- *
30
- * A no-op implementation is allowed, though it may lead to performance issues
31
- * in locations that use createMemo as no memoization would be done. This is
32
- * typically desirable only when integrating with a framework that does its own
33
- * memoization and does not integrate with any signals-like primitive. For these
34
- * scenarios you may also be interested in integrating with the {@link NotificationManager}
35
- * more directly.
36
- *
37
- * @public
38
- */
39
- /**
40
- * Contains information a {@link SignalHooks} implementation may want
41
- * to use, such as the specialized key used for the signal
42
- * representing an array's contents / length.
43
- *
44
- * ```ts
45
- * interface HooksOptions {
46
- * wellknown: {
47
- * Array: symbol | string;
48
- * }
49
- * }
50
- * ```
51
- *
52
- * @public
53
- */
54
- /**
55
- * Configures the signals implementation to use. Supports multiple
56
- * implementations simultaneously.
57
- *
58
- * See {@link HooksOptions} for the options passed to the provided function
59
- * when called.
60
- *
61
- * See {@link SignalHooks} for the implementation the callback function should
62
- * return.
63
- *
64
- * @public
65
- * @param buildConfig - a function that takes options and returns a configuration object
66
- */
67
- function setupSignals(buildConfig) {
68
- const hooks = buildConfig({ wellknown: { Array: ARRAY_SIGNAL } });
69
- setTransient("signalHooks", hooks);
70
- }
71
- /**
72
- * Internal method for consuming the configured `createSignal` hook
73
- *
74
- * @private
75
- */
76
- function createSignal(obj, key) {
77
- const signalHooks = peekTransient("signalHooks");
78
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
79
- if (!test) throw new Error(`Signal hooks not configured`);
80
- })(signalHooks);
81
- return signalHooks.createSignal(obj, key);
82
- }
83
- /**
84
- * Internal method for consuming the configured `consumeSignal` hook
85
- *
86
- * @private
87
- */
88
- function consumeSignal(signal) {
89
- const signalHooks = peekTransient("signalHooks");
90
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
91
- if (!test) throw new Error(`Signal hooks not configured`);
92
- })(signalHooks);
93
- return signalHooks.consumeSignal(signal);
94
- }
95
- /**
96
- * Internal method for consuming the configured `notifySignal` hook
97
- *
98
- * @private
99
- */
100
- function notifySignal(signal) {
101
- const signalHooks = peekTransient("signalHooks");
102
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
103
- if (!test) throw new Error(`Signal hooks not configured`);
104
- })(signalHooks);
105
- return signalHooks.notifySignal(signal);
106
- }
107
- function createMemo(object, key, fn) {
108
- const signalHooks = peekTransient("signalHooks");
109
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
110
- if (!test) throw new Error(`Signal hooks not configured`);
111
- })(signalHooks);
112
- return signalHooks.createMemo(object, key, fn);
113
- }
114
- function willSyncFlushWatchers() {
115
- const signalHooks = peekTransient("signalHooks");
116
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
117
- if (!test) throw new Error(`Signal hooks not configured`);
118
- })(signalHooks);
119
- return signalHooks.willSyncFlushWatchers();
120
- }
121
- /**
122
- * Wraps `promise` using the configured {@link SignalHooks.waitFor}, if any,
123
- * for things like test-waiters. Returns `promise` unchanged if no
124
- * `waitFor` hook is configured.
125
- */
126
- function waitFor(promise) {
127
- const signalHooks = peekTransient("signalHooks");
128
- if (signalHooks?.waitFor) return signalHooks.waitFor(promise);
129
- return promise;
130
- }
131
-
132
- //#endregion
133
- //#region src/signals/reactivity/internal.ts
134
- const INITIALIZER_PROTO = { isInitializer: true };
135
- /**
136
- * Wraps `fn` so that a signal can recognize it as a lazy initializer
137
- * for its value rather than the value itself, deferring the call to
138
- * `fn` until the signal is first accessed.
139
- */
140
- function makeInitializer(fn) {
141
- return Object.assign(Object.create(INITIALIZER_PROTO), { value: fn });
142
- }
143
- function isInitializer(obj) {
144
- return typeof obj === "object" && obj !== null && Object.getPrototypeOf(obj) === INITIALIZER_PROTO;
145
- }
146
- /**
147
- * A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
148
- * that enables us to store and manage the signal in a universal way.
149
- *
150
- * WarpDrive uses signals to manage three separate concepts:
151
- *
152
- * - as a `storage` for a value local to the object that we want to be reactive
153
- * (see `@local` schema field for an example)
154
- * - as a `gate` for a memoized getter that we want to act as a reactive property
155
- * but whose value is computed/pulled from a non-reactive source elsewhere
156
- * and whose latest value is stored in the signal
157
- * (see `field` schema field for an example)
158
- * - as a `gate` with a manually managed value updated on pull when `isStale` is true
159
- *
160
- *
161
- * It offers
162
- *
163
- * - a non-reactive way to access/update the current value
164
- * - a non-reactive way to mark the signal as dirtied
165
- * - a non-reactive way to store content for why the signal was dirtied
166
- * - access to the underlying Signal(s) in-use
167
- *
168
- * For debugging:
169
- * - the "key" or "name" of the signal
170
- * - the "object identity" or "context" to which the signal is attached
171
- *
172
- * @private
173
- */
174
- /**
175
- * We attach signals to their context object via
176
- * a Map attached to the object via this symbol.
177
- *
178
- * This allows us to store multiple signals
179
- * on the same object with smaller memory
180
- * overhead and no WeakMap lookups.
181
- *
182
- * Performance sensitive objects should
183
- * pre-warm their shape by assigning this
184
- * during initialization.
185
- *
186
- * ```ts
187
- * initializeSignalStore(obj);
188
- * ```
189
- *
190
- * @private
191
- */
192
- const Signals = getOrSetGlobal("Signals", Symbol("Signals"));
193
- /**
194
- * A type util to recast the object as having a signal store.
195
- *
196
- * @private
197
- */
198
- function upgradeWithSignals(obj) {}
199
- /**
200
- * A util that will create a signal store on the object
201
- * if it does not already exist and returns the associated
202
- * signal store.
203
- *
204
- * @private
205
- */
206
- function withSignalStore(obj) {
207
- /* @__PURE__ */ upgradeWithSignals(obj);
208
- if (!obj[Signals]) initializeSignalStore(obj);
209
- return obj[Signals];
210
- }
211
- /**
212
- * A util that will create a signal store on the object
213
- * if it does not already exist.
214
- *
215
- * Useful for pre-warming the shape of an object to ensure
216
- * a key-transition to add it is not required later.
217
- *
218
- * @private
219
- */
220
- function initializeSignalStore(obj) {
221
- /* @__PURE__ */ upgradeWithSignals(obj);
222
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
223
- if (!test) throw new Error(`Signal store already exists on object`);
224
- })(!obj[Signals]);
225
- obj[Signals] = /* @__PURE__ */ new Map();
226
- }
227
- function createInternalSignal(signals, obj, key, initialValue) {
228
- const warpDriveSignal = {
229
- key,
230
- context: obj,
231
- signal: createSignal(obj, key),
232
- value: isInitializer(initialValue) ? initialValue.value.call(obj) : initialValue,
233
- isStale: false
234
- };
235
- signals.set(key, warpDriveSignal);
236
- return warpDriveSignal;
237
- }
238
- function getOrCreateInternalSignal(signals, obj, key, initialValue) {
239
- let signal = peekInternalSignal(signals, key);
240
- if (!signal) signal = createInternalSignal(signals, obj, key, initialValue);
241
- return signal;
242
- }
243
- function createInternalMemo(signals, object, key, fn) {
244
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
245
- if (!test) throw new Error(`Expected no signal/memo to exist for key "${String(key)}"`);
246
- })(!peekInternalSignal(signals, key));
247
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) return withFrame(signals, object, key, fn);
248
- else {
249
- const memo = createMemo(object, key, fn);
250
- signals.set(key, memo);
251
- return memo;
252
- }
253
- }
254
- /**
255
- * Looks up the {@link WarpDriveSignal} stored for `key` in `signals`,
256
- * if one has already been created, without creating or consuming it.
257
- */
258
- function peekInternalSignal(signals, key) {
259
- return signals?.get(key);
260
- }
261
- function consumeInternalSignal(signal) {
262
- TrackingFrame?.signals.add(signal);
263
- consumeSignal(signal.signal);
264
- }
265
- /**
266
- * Marks `signal` as stale and notifies its underlying framework/TC39
267
- * signal, scheduling any of its consumers for re-render/re-computation.
268
- */
269
- function notifyInternalSignal(signal) {
270
- if (signal) {
271
- signal.isStale = true;
272
- notifySignal(signal.signal);
273
- }
274
- }
275
- let TrackingFrame = null;
276
- /**
277
- * This is currently just for signals debugging, but it could be used in production
278
- * if we wanted to eliminate the need for frameworks to implement createMemo / to
279
- * allow us to add our own Watcher.
280
- *
281
- * @internal
282
- */
283
- function withFrame(signals, object, key, fn) {
284
- const frameSignals = /* @__PURE__ */ new Set();
285
- const frameFn = () => {
286
- if (frameSignals.size) frameSignals.clear();
287
- TrackingFrame = {
288
- object,
289
- key,
290
- signals: frameSignals,
291
- parent: TrackingFrame
292
- };
293
- try {
294
- return fn();
295
- } finally {
296
- TrackingFrame = TrackingFrame.parent;
297
- }
298
- };
299
- const memo = createMemo(object, key, frameFn);
300
- memo.signals = frameSignals;
301
- signals.set(key, memo);
302
- return memo;
303
- }
304
- function isMemo(obj) {
305
- return typeof obj === "function" && obj.signals instanceof Set;
306
- }
307
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) globalThis.debugWarpDriveSignals = (obj, key) => {
308
- /* @__PURE__ */ upgradeWithSignals(obj);
309
- const signals = obj[Signals];
310
- if (!signals) {
311
- log("The object has no associated signals");
312
- return false;
313
- }
314
- if (key) {
315
- const signal = signals.get(key);
316
- if (!signal) {
317
- log(`No signal found for key "${String(key)}"`);
318
- return false;
319
- }
320
- log(signal);
321
- if (isMemo(signal)) {
322
- colorizeLines(printMemo(signal, key));
323
- return true;
324
- } else {
325
- colorizeLines(printSignal(signal, key));
326
- return true;
327
- }
328
- }
329
- const lines = [];
330
- for (const [k, signal] of signals) {
331
- if (isMemo(signal)) continue;
332
- printSignal(signal, k, lines);
333
- }
334
- for (const [k, signal] of signals) if (isMemo(signal)) printMemo(signal, k, lines);
335
- log(signals);
336
- colorizeLines(lines);
337
- return true;
338
- };
339
- const LightColors = {
340
- red: "color: red;",
341
- green: "color: green;",
342
- reset: "color: inherit;"
343
- };
344
- const DarkColors = {
345
- red: "color: red;",
346
- green: "color: lightgreen;",
347
- reset: "color: inherit;"
348
- };
349
- function isLightMode() {
350
- if (window?.matchMedia?.("(prefers-color-scheme: light)").matches) return true;
351
- return false;
352
- }
353
- const RED = {};
354
- const GREEN = {};
355
- const RESET = {};
356
- const EOL = {};
357
- function colorizeLines(lines) {
358
- const Colors = isLightMode() ? LightColors : DarkColors;
359
- const colors = [];
360
- let line = "";
361
- for (const str of lines) if (str === RED) {
362
- colors.push(Colors.red);
363
- line += "%c";
364
- } else if (str === GREEN) {
365
- colors.push(Colors.green);
366
- line += "%c";
367
- } else if (str === RESET) {
368
- colors.push(Colors.reset);
369
- line += "%c";
370
- } else if (str === EOL) line += "\n";
371
- else line += str;
372
- log(line, ...colors);
373
- }
374
- function log(...args) {
375
- console.log(...args);
376
- }
377
- function isDirty(signal) {
378
- return signal.isStale;
379
- }
380
- function isDirtyMemo(memo) {
381
- for (const signal of memo.signals) {
382
- if (isMemo(signal)) continue;
383
- if (isDirty(signal)) return true;
384
- }
385
- for (const signal of memo.signals) if (isMemo(signal)) return isDirtyMemo(signal);
386
- return false;
387
- }
388
- function printSignal(signal, key, lines = [], depth = 0) {
389
- const _dirty = isDirty(signal);
390
- lines.push(`${"".padStart(depth * 2, " ")}${_dirty ? "❌" : "✅"} `, _dirty ? RED : GREEN, `${String(key)}`, RESET, EOL);
391
- return lines;
392
- }
393
- function printMemo(memo, key, lines = [], depth = 0) {
394
- const _dirty = isDirtyMemo(memo);
395
- lines.push(`${"".padStart(depth * 2, " ")}${_dirty ? "❌" : "✅"} `, _dirty ? RED : GREEN, `<memo> ${String(key)}`, RESET, `: (consumes ${memo.signals.size} signals)`, EOL);
396
- for (const signal of memo.signals) {
397
- if (isMemo(signal)) continue;
398
- printSignal(signal, signal.key, lines, depth + 1);
399
- }
400
- for (const signal of memo.signals) if (isMemo(signal)) printMemo(signal, signal.key, lines, depth + 1);
401
- return lines;
402
- }
403
-
404
- //#endregion
405
- //#region src/signals/reactivity/signal.ts
406
- /**
407
- * Creates a signal for the key/object pairing and subscribes to the signal.
408
- *
409
- * Use when you need to ensure a signal exists and is subscribed to.
410
- *
411
- * @private
412
- */
413
- function entangleSignal(signals, obj, key, initialValue) {
414
- let internalSignal = peekInternalSignal(signals, key);
415
- if (!internalSignal) internalSignal = createInternalSignal(signals, obj, key, initialValue);
416
- consumeInternalSignal(internalSignal);
417
- return internalSignal;
418
- }
419
- function entangleInitiallyStaleSignal(signals, obj, key, initialValue) {
420
- let internalSignal = peekInternalSignal(signals, key);
421
- if (!internalSignal) {
422
- internalSignal = createInternalSignal(signals, obj, key, initialValue);
423
- internalSignal.isStale = true;
424
- }
425
- consumeInternalSignal(internalSignal);
426
- return internalSignal;
427
- }
428
- function createSignalDescriptor(key, intialValue) {
429
- return {
430
- enumerable: true,
431
- configurable: false,
432
- get() {
433
- const internalSignal = entangleSignal(withSignalStore(this), this, key, intialValue);
434
- internalSignal.isStale = false;
435
- return internalSignal.value;
436
- },
437
- set(value) {
438
- const signals = withSignalStore(this);
439
- const internalSignal = getOrCreateInternalSignal(signals, this, key, intialValue);
440
- if (internalSignal.value !== value) {
441
- internalSignal.value = value;
442
- notifyInternalSignal(internalSignal);
443
- }
444
- }
445
- };
446
- }
447
- /**
448
- * define an enumerable signal property.
449
- *
450
- * Akin to Object.defineProperty.
451
- *
452
- * The signal will be lazily created when accessed and scoped to the
453
- * instance of the object.
454
- *
455
- * @private
456
- */
457
- function defineSignal(obj, key, v) {
458
- Object.defineProperty(obj, key, createSignalDescriptor(key, v));
459
- }
460
- /**
461
- * Define a non-enumerable signal property.
462
- *
463
- * @private
464
- */
465
- function defineNonEnumerableSignal(obj, key, v) {
466
- const desc = createSignalDescriptor(key, v);
467
- desc.enumerable = false;
468
- Object.defineProperty(obj, key, desc);
469
- }
470
- /**
471
- * Decorator version of creating a signal.
472
- */
473
- function signal(target, key, descriptor) {
474
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
475
- if (!test) throw new Error("You attempted to use @signal(), which is not necessary nor supported. Remove the parentheses and you will be good to go!");
476
- })(target !== void 0);
477
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
478
- if (!test) throw new Error(`You attempted to use @signal on with ${arguments.length > 1 ? "arguments" : "an argument"} ( @signal(${Array.from(arguments).map((d) => `'${d}'`).join(", ")}) ), which is not supported. Dependencies are automatically tracked, so you can just use \`@signal\``);
479
- })(typeof target === "object" && typeof key === "string" && typeof descriptor === "object" && arguments.length === 3);
480
- return createSignalDescriptor(key, descriptor.initializer ? makeInitializer(descriptor.initializer) : null);
481
- }
482
- /**
483
- * Decorator version of creating a memoized getter
484
- */
485
- function memoized(target, key, descriptor) {
486
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
487
- if (!test) throw new Error("You attempted to use @memoized(), which is not necessary nor supported. Remove the parentheses and you will be good to go!");
488
- })(target !== void 0);
489
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
490
- if (!test) throw new Error(`You attempted to use @memoized on with ${arguments.length > 1 ? "arguments" : "an argument"} ( @memoized(${Array.from(arguments).map((d) => `'${d}'`).join(", ")}), which is not supported. Dependencies are automatically tracked, so you can just use \`@memoized\``);
491
- })(typeof target === "object" && typeof key === "string" && typeof descriptor === "object" && arguments.length === 3);
492
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
493
- if (!test) throw new Error(`The @memoized decorator must be applied to getters. '${key}' is not a getter.`);
494
- })(typeof descriptor.get === "function");
495
- const getter = descriptor.get;
496
- descriptor.get = function() {
497
- const signals = withSignalStore(this);
498
- let memoSignal = signals.get(key);
499
- if (!memoSignal) memoSignal = createInternalMemo(signals, this, key, getter.bind(this));
500
- return memoSignal();
501
- };
502
- return descriptor;
503
- }
504
- /**
505
- * Decorator version of creating a gate.
506
- *
507
- * @private
508
- */
509
- function gate(_target, key, desc) {
510
- const getter = desc.get;
511
- const setter = desc.set;
512
- const isLocal = desc.isLocal;
513
- desc.get = function() {
514
- const signals = withSignalStore(this);
515
- let internalSignal = peekInternalSignal(signals, key);
516
- if (!internalSignal) internalSignal = createInternalSignal(signals, this, key, getter.call(this));
517
- else if (internalSignal.isStale) {
518
- internalSignal.isStale = false;
519
- internalSignal.value = getter.call(this);
520
- }
521
- consumeInternalSignal(internalSignal);
522
- return internalSignal.value;
523
- };
524
- if (setter) desc.set = function(v) {
525
- const signals = withSignalStore(this);
526
- let internalSignal = peekInternalSignal(signals, key);
527
- if (!internalSignal) {
528
- internalSignal = createInternalSignal(signals, this, key, void 0);
529
- internalSignal.isStale = true;
530
- }
531
- setter.call(this, v);
532
- if (isLocal) {
533
- internalSignal.isStale = true;
534
- notifyInternalSignal(internalSignal);
535
- }
536
- };
537
- return desc;
538
- }
539
- /**
540
- * Defines a reactive "gated" property on `obj` using `desc` as its
541
- * getter/setter descriptor.
542
- *
543
- * Unlike a signal defined with {@link defineSignal}, a gated property's
544
- * consumers are not notified when the property is set, since its update
545
- * is expected to be controlled externally (for instance, by a signal it
546
- * derives its value from) unless the descriptor opts into being locally
547
- * managed.
548
- *
549
- * Akin to `Object.defineProperty`.
550
- *
551
- * @private
552
- */
553
- function defineGate(obj, key, desc) {
554
- const options = Object.assign({
555
- enumerable: true,
556
- configurable: false
557
- }, gate(obj, key, desc));
558
- Object.defineProperty(obj, key, options);
559
- }
560
-
561
- //#endregion
562
- //#region src/signals/request-state.ts
563
- const RequestCache = /* @__PURE__ */ new WeakMap();
564
- function isAbortError(error) {
565
- return error instanceof DOMError && error.name === "AbortError";
566
- }
567
- function upgradeLoadingState(state) {
568
- return state;
569
- }
570
- async function watchStream(stream, loadingState) {
571
- const state = upgradeLoadingState(loadingState);
572
- const reader = stream.getReader();
573
- let bytesLoaded = 0;
574
- let shouldForward = state._stream !== null && state._stream.readable.locked;
575
- let isForwarding = shouldForward;
576
- let writer = state._stream?.writable.getWriter();
577
- const buffer = [];
578
- state._isPending = false;
579
- state._isStarted = true;
580
- state._startTime = performance.now();
581
- while (true) {
582
- const { value, done } = await reader.read();
583
- if (done) break;
584
- bytesLoaded += value.byteLength;
585
- state._bytesLoaded = bytesLoaded;
586
- state._lastPacketTime = performance.now();
587
- shouldForward = shouldForward || state._stream !== null && state._stream.readable.locked;
588
- if (shouldForward) {
589
- if (!isForwarding) {
590
- isForwarding = true;
591
- writer = state._stream.writable.getWriter();
592
- for (const item of buffer) {
593
- await writer.ready;
594
- await writer.write(item);
595
- }
596
- buffer.length = 0;
597
- }
598
- await writer.ready;
599
- await writer.write(value);
600
- } else buffer.push(value);
601
- }
602
- if (isForwarding) {
603
- await writer.ready;
604
- await writer.close();
605
- } else if (state._stream) {
606
- await state._stream.readable.cancel("The Stream Has Already Ended");
607
- state._stream = null;
608
- }
609
- state._endTime = performance.now();
610
- state._isComplete = true;
611
- state._isStarted = false;
612
- }
613
- /**
614
- * Lazily consumes the stream of a request, providing a number of
615
- * reactive properties that can be used to build UIs that respond
616
- * to the progress of a request.
617
- *
618
- * @hideconstructor
619
- */
620
- var RequestLoadingState = class {
621
- /** @internal */
622
- /** @internal */
623
- /** @internal */
624
- /** @internal */
625
- /** @internal */
626
- /** @internal */
627
- /** @internal */
628
- /** @internal */
629
- /** @internal */
630
- /** @internal */
631
- /** @internal */
632
- /** @internal */
633
- _stream = null;
634
- /** @internal */
635
- _future;
636
- /** @internal */
637
- _triggered = false;
638
- /** @internal */
639
- _trigger() {
640
- if (this._triggered) return;
641
- this._triggered = true;
642
- const promise = this._future.getStream();
643
- if (promise.sizeHint) this._sizeHint = promise.sizeHint;
644
- this.promise = promise.then((stream) => {
645
- if (!stream) {
646
- this._isPending = false;
647
- this._isComplete = true;
648
- return;
649
- }
650
- return watchStream(stream, this);
651
- }, (error) => {
652
- this._isPending = false;
653
- this._isStarted = false;
654
- if (isAbortError(error)) {
655
- this._isCancelled = true;
656
- this._isComplete = true;
657
- }
658
- this._isErrored = true;
659
- this._error = error;
660
- });
661
- }
662
- /**
663
- * Resolves once the stream has finished being consumed, or rejects
664
- * if the request errors. `null` until first accessed.
665
- */
666
- promise = null;
667
- /**
668
- * Whether the stream has not yet started being consumed.
669
- */
670
- get isPending() {
671
- this._trigger();
672
- return this._isPending;
673
- }
674
- /**
675
- * The total size of the response in bytes, if known ahead of time
676
- * (via a `Content-Length` header or similar).
677
- */
678
- get sizeHint() {
679
- this._trigger();
680
- return this._sizeHint;
681
- }
682
- /**
683
- * A readable stream of the response content. Accessing this property
684
- * begins consumption of the underlying request stream.
685
- */
686
- get stream() {
687
- this._trigger();
688
- if (!this._stream) {
689
- if (this._isComplete || this._isCancelled || this._isErrored) return null;
690
- this._stream = new TransformStream();
691
- }
692
- return this._stream.readable;
693
- }
694
- /**
695
- * Whether the stream has started being consumed but has not yet completed.
696
- */
697
- get isStarted() {
698
- this._trigger();
699
- return this._isStarted;
700
- }
701
- /**
702
- * The number of bytes loaded so far.
703
- */
704
- get bytesLoaded() {
705
- this._trigger();
706
- return this._bytesLoaded;
707
- }
708
- /**
709
- * The `performance.now()` timestamp at which the stream started being consumed.
710
- */
711
- get startTime() {
712
- this._trigger();
713
- return this._startTime;
714
- }
715
- /**
716
- * The `performance.now()` timestamp at which the stream finished being consumed.
717
- */
718
- get endTime() {
719
- this._trigger();
720
- return this._endTime;
721
- }
722
- /**
723
- * The `performance.now()` timestamp at which the last chunk of data was received.
724
- */
725
- get lastPacketTime() {
726
- this._trigger();
727
- return this._lastPacketTime;
728
- }
729
- /**
730
- * Whether the stream has finished being consumed.
731
- */
732
- get isComplete() {
733
- this._trigger();
734
- return this._isComplete;
735
- }
736
- /**
737
- * Whether the request was aborted before the stream finished being consumed.
738
- */
739
- get isCancelled() {
740
- this._trigger();
741
- return this._isCancelled;
742
- }
743
- /**
744
- * Whether an error occurred while consuming the stream.
745
- */
746
- get isErrored() {
747
- this._trigger();
748
- return this._isErrored;
749
- }
750
- /**
751
- * The error that occurred while consuming the stream, if any.
752
- */
753
- get error() {
754
- this._trigger();
755
- return this._error;
756
- }
757
- /**
758
- * The number of milliseconds elapsed since the stream started being
759
- * consumed, using the last packet time (or end time, once complete)
760
- * as the endpoint.
761
- */
762
- get elapsedTime() {
763
- return (this.endTime || this.lastPacketTime) - this.startTime;
764
- }
765
- /**
766
- * The ratio (0 to 1) of {@link RequestLoadingState.bytesLoaded | bytesLoaded}
767
- * to {@link RequestLoadingState.sizeHint | sizeHint}, or `0` if no size hint is available.
768
- */
769
- get completedRatio() {
770
- return this.sizeHint ? this.bytesLoaded / this.sizeHint : 0;
771
- }
772
- /**
773
- * The inverse of {@link RequestLoadingState.completedRatio | completedRatio}.
774
- */
775
- get remainingRatio() {
776
- return 1 - this.completedRatio;
777
- }
778
- /**
779
- * The total number of milliseconds elapsed between
780
- * {@link RequestLoadingState.startTime | startTime} and {@link RequestLoadingState.endTime | endTime}.
781
- */
782
- get duration() {
783
- return this.endTime - this.startTime;
784
- }
785
- /**
786
- * The average download speed in bytes per second.
787
- */
788
- get speed() {
789
- return this.bytesLoaded / (this.elapsedTime / 1e3);
790
- }
791
- constructor(future) {
792
- this._future = future;
793
- }
794
- /**
795
- * Aborts the underlying request.
796
- */
797
- abort = () => {
798
- this._future.abort();
799
- };
800
- };
801
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_isPending", true);
802
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_isStarted", false);
803
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_isComplete", false);
804
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_isCancelled", false);
805
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_isErrored", false);
806
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_error", null);
807
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_sizeHint", 0);
808
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_bytesLoaded", 0);
809
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_startTime", 0);
810
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_endTime", 0);
811
- defineNonEnumerableSignal(RequestLoadingState.prototype, "_lastPacketTime", 0);
812
- /**
813
- * The state of a request in the "pending"
814
- * state. This is the default initial state.
815
- *
816
- * Extends the {@link PendingPromise} interface.
817
- *
818
- */
819
- /**
820
- * The state of a request in the "fulfilled" state.
821
- * This is the state of a request that has resolved
822
- * successfully.
823
- *
824
- * Extends the {@link ResolvedPromise} interface.
825
- *
826
- */
827
- /**
828
- * The state of a request in the "rejected" state.
829
- * This is the state of a request that has rejected
830
- * with an error.
831
- *
832
- * Extends the {@link RejectedPromise} interface.
833
- *
834
- */
835
- /**
836
- * The state of a request in the "cancelled" state.
837
- * This is the state of a promise that has been
838
- * cancelled.
839
- *
840
- */
841
- /**
842
- * RequestState extends the concept of {@link PromiseState} to provide a reactive
843
- * wrapper for a request {@link Future} which allows you write declarative code
844
- * around a Future's control flow.
845
- *
846
- * It is useful in both Template and JavaScript contexts, allowing you
847
- * to quickly derive behaviors and data from pending, error and success
848
- * states.
849
- *
850
- * The key difference between a {@link Promise} and a Future is that Futures provide
851
- * access to a {@link ReadableStream | stream} of their content, the {@link RequestKey} of the request (if any)
852
- * as well as the ability to attempt to {@link Future.abort | abort} the request.
853
- *
854
- * ```ts
855
- * interface Future<T> extends Promise<T>> {
856
- * getStream(): Promise<ReadableStream>;
857
- * abort(): void;
858
- * lid: RequestKey | null;
859
- * }
860
- * ```
861
- *
862
- * These additional APIs allow us to craft even richer state experiences.
863
- *
864
- * To get the state of a request, use {@link getRequestState}.
865
- *
866
- * See also:
867
- * - {@link PendingRequest}
868
- * - {@link ResolvedRequest}
869
- * - {@link RejectedRequest}
870
- * - {@link CancelledRequest}
871
- *
872
- */
873
- const RequestStateProto = {};
874
- function performRefresh(requester, request, isReload) {
875
- const req = Object.assign({}, request);
876
- const cacheOptions = Object.assign({}, req.cacheOptions);
877
- if (isReload) cacheOptions.reload = true;
878
- else if (isReload === false) {
879
- delete cacheOptions.reload;
880
- cacheOptions.backgroundReload = true;
881
- } else {
882
- delete cacheOptions.backgroundReload;
883
- delete cacheOptions.reload;
884
- }
885
- req.cacheOptions = cacheOptions;
886
- return requester.request(req);
887
- }
888
- defineSignal(RequestStateProto, "reason", null);
889
- defineSignal(RequestStateProto, "value", null);
890
- defineSignal(RequestStateProto, "result", null);
891
- defineSignal(RequestStateProto, "error", null);
892
- defineSignal(RequestStateProto, "status", "pending");
893
- defineSignal(RequestStateProto, "isPending", true);
894
- defineSignal(RequestStateProto, "isLoading", true);
895
- defineSignal(RequestStateProto, "isSuccess", false);
896
- defineSignal(RequestStateProto, "isError", false);
897
- defineSignal(RequestStateProto, "request", null);
898
- defineSignal(RequestStateProto, "response", null);
899
- Object.defineProperty(RequestStateProto, "isCancelled", { get() {
900
- return this.isError && isAbortError(this.reason);
901
- } });
902
- Object.defineProperty(RequestStateProto, "loadingState", { get() {
903
- if (!this._loadingState) this._loadingState = new RequestLoadingState(this._request);
904
- return this._loadingState;
905
- } });
906
- function createRequestState(future) {
907
- const state = getPromiseResult(future);
908
- const promiseState = Object.create(RequestStateProto);
909
- promiseState._request = future;
910
- promiseState.reload = () => {
911
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
912
- if (!test) throw new Error(`Cannot reload a request that is still pending. Await or abort the original request first.`);
913
- })(!promiseState.isPending);
914
- return performRefresh(future.requester, promiseState.request, true);
915
- };
916
- promiseState.refresh = (usePolicy = false) => {
917
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
918
- if (!test) throw new Error(`Cannot refresh a request that is still pending. Await or abort the original request first.`);
919
- })(!promiseState.isPending);
920
- return performRefresh(future.requester, promiseState.request, usePolicy === true ? null : false);
921
- };
922
- if (state) {
923
- if (state.isError) {
924
- promiseState.error = state.result;
925
- promiseState.reason = state.result;
926
- promiseState.status = "rejected";
927
- promiseState.isError = true;
928
- promiseState.isPending = false;
929
- promiseState.isLoading = false;
930
- promiseState.request = state.result.request;
931
- promiseState.response = state.result.response;
932
- } else {
933
- promiseState.result = state.result.content;
934
- promiseState.value = state.result.content;
935
- promiseState.status = "fulfilled";
936
- promiseState.isSuccess = true;
937
- promiseState.isPending = false;
938
- promiseState.isLoading = false;
939
- promiseState.request = state.result.request;
940
- promiseState.response = state.result.response;
941
- }
942
- } else future.then((result) => {
943
- setPromiseResult(future, {
944
- isError: false,
945
- result
946
- });
947
- promiseState.result = result.content;
948
- promiseState.value = result.content;
949
- promiseState.status = "fulfilled";
950
- promiseState.isSuccess = true;
951
- promiseState.isPending = false;
952
- promiseState.isLoading = false;
953
- promiseState.request = result.request;
954
- promiseState.response = result.response;
955
- }, (error) => {
956
- setPromiseResult(future, {
957
- isError: true,
958
- result: error
959
- });
960
- promiseState.error = error;
961
- promiseState.reason = error;
962
- promiseState.status = "rejected";
963
- promiseState.isError = true;
964
- promiseState.isPending = false;
965
- promiseState.isLoading = false;
966
- promiseState.request = error.request;
967
- promiseState.response = error.response;
968
- });
969
- return promiseState;
970
- }
971
- /**
972
- * `getRequestState` can be used in both JavaScript and Template contexts.
973
- *
974
- * ```ts
975
- * import { getRequestState } from '@warp-drive/ember';
976
- *
977
- * const state = getRequestState(future);
978
- * ```
979
- *
980
- * For instance, we could write a getter on a component that updates whenever
981
- * the request state advances or the future changes, by combining the function
982
- * with the use of `@cached`
983
- *
984
- * ```ts
985
- * class Component {
986
- * @cached
987
- * get title() {
988
- * const state = getRequestState(this.args.request);
989
- * if (state.isPending) {
990
- * return 'loading...';
991
- * }
992
- * if (state.isError) { return null; }
993
- * return state.result.title;
994
- * }
995
- * }
996
- * ```
997
- *
998
- * Or in a template as a helper:
999
- *
1000
- * ```gjs
1001
- * import { getRequestState } from '@warp-drive/ember';
1002
- *
1003
- * <template>
1004
- * {{#let (getRequestState @request) as |state|}}
1005
- * {{#if state.isPending}}
1006
- * <Spinner />
1007
- * {{else if state.isError}}
1008
- * <ErrorForm @error={{state.error}} />
1009
- * {{else}}
1010
- * <h1>{{state.result.title}}</h1>
1011
- * {{/if}}
1012
- * {{/let}}
1013
- * </template>
1014
- * ```
1015
- *
1016
- * If looking to use in a template, consider also the `<Request />` component
1017
- * which offers a number of additional capabilities for requests *beyond* what
1018
- * `RequestState` provides.
1019
- *
1020
- */
1021
- function getRequestState(future) {
1022
- let state = RequestCache.get(future);
1023
- if (!state) {
1024
- state = createRequestState(future);
1025
- RequestCache.set(future, state);
1026
- }
1027
- return state;
1028
- }
1029
-
1030
- //#endregion
1031
- //#region ../../node_modules/.pnpm/decorat_5005bbc272376d25df08203abab44e2f/node_modules/decorator-transforms/dist/runtime-BPCpkOf1.js
1032
- function decorateMethodV2(prototype, prop, decorators) {
1033
- let desc = { ...Object.getOwnPropertyDescriptor(prototype, prop) };
1034
- for (let decorator of decorators) desc = decorator(prototype, prop, desc) || desc;
1035
- if (desc.initializer !== void 0) {
1036
- desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
1037
- desc.initializer = void 0;
1038
- }
1039
- Object.defineProperty(prototype, prop, desc);
1040
- }
1041
-
1042
- //#endregion
1043
- //#region src/signals/request-subscription.ts
1044
- const DEFAULT_DEADLINE = 3e4;
1045
- /**
1046
- * A symbol used to dispose of a {@link RequestSubscription} when the
1047
- * component or context using it is torn down.
1048
- */
1049
- const DISPOSE = Symbol.dispose || Symbol.for("dispose");
1050
- function isNeverString(val) {
1051
- return val;
1052
- }
1053
- /**
1054
- * The individual autorefresh strategies a {@link RequestSubscription}
1055
- * may combine, see {@link AutorefreshBehaviorCombos}.
1056
- */
1057
- /**
1058
- * The value accepted by {@link SubscriptionArgs.autorefresh}: either a
1059
- * boolean, a single {@link AutorefreshBehaviorType}, or a comma-separated
1060
- * combination of up to three of them.
1061
- */
1062
- /**
1063
- * Utilities to assist in recovering from the error.
1064
- */
1065
- /** @deprecated use {@link RecoveryFeatures} */
1066
- /**
1067
- * Utilities for keeping the request fresh
1068
- */
1069
- /**
1070
- * The args accepted by the `<Request />` component.
1071
- */
1072
- /**
1073
- * The args accepted by a {@link RequestSubscription}.
1074
- */
1075
- /**
1076
- * A reactive class
1077
- *
1078
- * @hideconstructor
1079
- */
1080
- var RequestSubscription = class {
1081
- /**
1082
- * Whether the browser reports that the network is online.
1083
- */
1084
- /**
1085
- * Whether the browser reports that the tab is hidden.
1086
- */
1087
- /**
1088
- * Whether the component is currently refreshing the request.
1089
- */
1090
- /**
1091
- * The most recent blocking request that was made, typically
1092
- * the result of a reload.
1093
- *
1094
- * This will never be the original request passed as an arg to
1095
- * the component.
1096
- *
1097
- * @internal
1098
- */
1099
- /**
1100
- * The most recent request that was made, typically due to either a
1101
- * reload or a refresh.
1102
- *
1103
- * This will never be the original request passed as an arg to
1104
- * the component.
1105
- *
1106
- * @internal
1107
- */
1108
- /**
1109
- * The time at which the network was reported as offline.
1110
- *
1111
- * @internal
1112
- */
1113
- /** @internal */
1114
- /** @internal */
1115
- /** @internal */
1116
- /** @internal */
1117
- /** @internal */
1118
- /**
1119
- * The event listener for network status changes,
1120
- * cached to use the reference for removal.
1121
- *
1122
- * @internal
1123
- */
1124
- /**
1125
- * The event listener for visibility status changes,
1126
- * cached to use the reference for removal.
1127
- *
1128
- * @internal
1129
- */
1130
- /**
1131
- * The last request passed as an arg to the component,
1132
- * cached for comparison.
1133
- *
1134
- * @internal
1135
- */
1136
- /**
1137
- * The last query passed as an arg to the component,
1138
- * cached for comparison.
1139
- *
1140
- * @internal
1141
- */
1142
- /** @internal */
1143
- /** @internal */
1144
- /** @internal */
1145
- /**
1146
- * The Store this subscription subscribes to or the RequestManager
1147
- * which issues this request.
1148
- */
1149
- /**
1150
- * The Store or RequestManager that the last subscription is attached to.
1151
- *
1152
- * This differs from 'store' because a <Request /> may be passed a
1153
- * request originating from a different store than the <Request />
1154
- * component would use if it were to issue the request itself.
1155
- *
1156
- * @internal
1157
- */
1158
- _requester;
1159
- constructor(store, args) {
1160
- this._args = args;
1161
- this.store = store;
1162
- this._subscribedTo = null;
1163
- this._subscription = null;
1164
- this._intervalStart = null;
1165
- this._invalidated = false;
1166
- this._nextInterval = null;
1167
- this._requester = null;
1168
- this.isDestroyed = false;
1169
- this[DISPOSE] = _DISPOSE;
1170
- this._installListeners();
1171
- this._beginPolling();
1172
- }
1173
- /**
1174
- * @internal
1175
- */
1176
- async _beginPolling() {
1177
- try {
1178
- if (!this.isIdle) await this.request;
1179
- } catch {} finally {
1180
- if (!this.isDestroyed) this._scheduleInterval();
1181
- }
1182
- }
1183
- /**
1184
- * Whether neither a `request` nor a `query` arg was provided, and so
1185
- * this subscription has nothing to fetch or monitor.
1186
- */
1187
- get isIdle() {
1188
- const { request, query } = this._args;
1189
- return Boolean(!request && !query);
1190
- }
1191
- /**
1192
- * The set of {@link AutorefreshBehaviorType}s this subscription is
1193
- * configured to autorefresh for, derived from {@link SubscriptionArgs.autorefresh}.
1194
- */
1195
- static {
1196
- decorateMethodV2(this.prototype, "isIdle", [memoized]);
1197
- }
1198
- get autorefreshTypes() {
1199
- const { autorefresh } = this._args;
1200
- let types;
1201
- if (autorefresh === true) types = ["online", "invalid"];
1202
- else if (typeof autorefresh === "string") types = autorefresh.split(",");
1203
- else types = [];
1204
- return new Set(types);
1205
- }
1206
- /** @internal */
1207
- static {
1208
- decorateMethodV2(this.prototype, "autorefreshTypes", [memoized]);
1209
- }
1210
- async _scheduleInterval() {
1211
- const { autorefreshThreshold } = this._args;
1212
- if (typeof window === "undefined" || !(typeof autorefreshThreshold === "number" && autorefreshThreshold > 0) || !this.autorefreshTypes.has("interval") || this._intervalStart !== null) return;
1213
- if (this._latestRequest) {
1214
- try {
1215
- await this._latestRequest;
1216
- } catch {}
1217
- if (this.isDestroyed) return;
1218
- }
1219
- this._intervalStart = Date.now();
1220
- this._nextInterval = setTimeout(() => {
1221
- this._maybeUpdate();
1222
- }, autorefreshThreshold);
1223
- }
1224
- /** @internal */
1225
- _clearInterval() {
1226
- if (this._nextInterval) {
1227
- clearTimeout(this._nextInterval);
1228
- this._intervalStart = null;
1229
- }
1230
- }
1231
- /**
1232
- * @internal
1233
- */
1234
- _updateSubscriptions() {
1235
- if (this.isIdle) return;
1236
- const requestId = this._request.lid;
1237
- if (this._subscribedTo === requestId) return;
1238
- this._removeSubscriptions();
1239
- const store = this._getRequester();
1240
- this._requester = store;
1241
- if (requestId && isStore(store)) {
1242
- this._subscribedTo = requestId;
1243
- this._subscription = store.notifications.subscribe(requestId, (_id, op) => {
1244
- if (this._isUpdating) return;
1245
- switch (op) {
1246
- case "invalidated":
1247
- if (this.autorefreshTypes.has("invalid")) {
1248
- this._invalidated = true;
1249
- this._maybeUpdate();
1250
- }
1251
- break;
1252
- case "state": {
1253
- const priority = store.requestManager._deduped.get(requestId)?.priority;
1254
- const state = this.reqState;
1255
- if (!priority) this.isRefreshing = false;
1256
- else if (priority.blocking && !state.isLoading) {
1257
- this.isRefreshing = false;
1258
- this._maybeUpdate("policy", true);
1259
- } else this.isRefreshing = true;
1260
- }
1261
- }
1262
- });
1263
- }
1264
- }
1265
- /**
1266
- * @internal
1267
- */
1268
- _removeSubscriptions() {
1269
- const store = this._requester;
1270
- if (this._subscription && store && isStore(store)) {
1271
- store.notifications.unsubscribe(this._subscription);
1272
- this._subscribedTo = null;
1273
- this._subscription = null;
1274
- this._requester = null;
1275
- }
1276
- }
1277
- /**
1278
- * Install the event listeners for network and visibility changes.
1279
- *
1280
- * This is only done in environments that provide a fully-featured global
1281
- * `window` and/or `document`. Some non-DOM environments (e.g. React Native,
1282
- * SSR/Node, workers) may provide a `window` global without the APIs we
1283
- * rely on here (or no `window`/`document` at all), in which case we skip
1284
- * attaching the corresponding listeners rather than throwing.
1285
- *
1286
- * @internal
1287
- */
1288
- _installListeners() {
1289
- const hasWindow = typeof window !== "undefined";
1290
- const hasDocument = typeof document !== "undefined";
1291
- const hasWindowEvents = hasWindow && typeof window.addEventListener === "function";
1292
- const hasDocumentEvents = hasDocument && typeof document.addEventListener === "function";
1293
- this.isOnline = hasWindow && typeof window.navigator?.onLine === "boolean" ? window.navigator.onLine : true;
1294
- this._unavailableStart = this.isOnline ? null : Date.now();
1295
- this.isHidden = hasDocument && typeof document.visibilityState === "string" && document.visibilityState === "hidden";
1296
- if (hasWindowEvents) {
1297
- this._onlineChanged = (event) => {
1298
- this.isOnline = event.type === "online";
1299
- if (event.type === "offline" && this._unavailableStart === null) this._unavailableStart = Date.now();
1300
- this._maybeUpdate();
1301
- };
1302
- window.addEventListener("online", this._onlineChanged, {
1303
- passive: true,
1304
- capture: true
1305
- });
1306
- window.addEventListener("offline", this._onlineChanged, {
1307
- passive: true,
1308
- capture: true
1309
- });
1310
- }
1311
- if (hasDocumentEvents) {
1312
- this._backgroundChanged = () => {
1313
- const isHidden = document.visibilityState === "hidden";
1314
- this.isHidden = isHidden;
1315
- if (isHidden && this._unavailableStart === null) this._unavailableStart = Date.now();
1316
- this._maybeUpdate();
1317
- };
1318
- document.addEventListener("visibilitychange", this._backgroundChanged, {
1319
- passive: true,
1320
- capture: true
1321
- });
1322
- }
1323
- }
1324
- /**
1325
- * If the network is online and the tab is visible, either reload or refresh the request
1326
- * based on the component's configuration and the requested update mode.
1327
- *
1328
- * Valid modes are:
1329
- *
1330
- * - `'reload'`: Force a reload of the request.
1331
- * - `'refresh'`: Refresh the request in the background.
1332
- * - `'policy'`: Make the request, letting the store's configured CachePolicy decide whether to reload, refresh, or do nothing.
1333
- * - `undefined`: Make the request using the component's autorefreshBehavior setting if the autorefreshThreshold has passed.
1334
- *
1335
- * @internal
1336
- */
1337
- _maybeUpdate(mode, silent) {
1338
- if (this.isIdle) return;
1339
- const { reqState } = this;
1340
- if (reqState.isPending) return;
1341
- if (!Boolean(this.isOnline && !this.isHidden && (mode || this.autorefreshTypes.size))) {
1342
- if (!silent && mode && mode !== "_invalidated") throw new Error(`Reload not available: the network is not online or the tab is hidden`);
1343
- return;
1344
- }
1345
- const { autorefreshTypes } = this;
1346
- let shouldAttempt = this._invalidated || Boolean(mode);
1347
- if (!shouldAttempt && autorefreshTypes.has("online")) {
1348
- const { _unavailableStart } = this;
1349
- const { autorefreshThreshold } = this._args;
1350
- const deadline = typeof autorefreshThreshold === "number" ? autorefreshThreshold : DEFAULT_DEADLINE;
1351
- shouldAttempt = Boolean(_unavailableStart && Date.now() - _unavailableStart > deadline);
1352
- }
1353
- if (!shouldAttempt && autorefreshTypes.has("interval")) {
1354
- const { _intervalStart } = this;
1355
- const { autorefreshThreshold } = this._args;
1356
- if (_intervalStart && typeof autorefreshThreshold === "number" && autorefreshThreshold > 0) shouldAttempt = Boolean(Date.now() - _intervalStart >= autorefreshThreshold);
1357
- }
1358
- this._unavailableStart = null;
1359
- this._invalidated = false;
1360
- if (shouldAttempt) {
1361
- this._clearInterval();
1362
- this._isUpdating = true;
1363
- const val = (mode === "_invalidated" ? null : mode) ?? this._args.autorefreshBehavior ?? "policy";
1364
- const requester = this._getRequester();
1365
- if (!reqState._request.requester) reqState._request.requester = requester;
1366
- switch (val) {
1367
- case "reload":
1368
- this._latestRequest = reqState.reload();
1369
- break;
1370
- case "refresh":
1371
- this._latestRequest = reqState.refresh();
1372
- break;
1373
- case "policy":
1374
- this._latestRequest = reqState.refresh(true);
1375
- break;
1376
- default: macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1377
- if (!test) throw new Error(`Invalid ${mode ? "update mode" : "@autorefreshBehavior"} for <Request />: ${isNeverString(val)}`);
1378
- })(false);
1379
- }
1380
- if (val !== "refresh") this._localRequest = this._latestRequest;
1381
- this._scheduleInterval();
1382
- this._latestRequest.finally(() => {
1383
- this._isUpdating = false;
1384
- });
1385
- }
1386
- }
1387
- /**
1388
- * @internal
1389
- */
1390
- _getRequester() {
1391
- if (this._args.request?.requester) return this._args.request.requester;
1392
- return this.store;
1393
- }
1394
- /**
1395
- * Retry the request, reloading it from the server.
1396
- */
1397
- retry = async () => {
1398
- this._maybeUpdate("reload");
1399
- await this._localRequest;
1400
- };
1401
- /**
1402
- * Refresh the request, updating it in the background.
1403
- */
1404
- refresh = async () => {
1405
- this._maybeUpdate("refresh");
1406
- await this._latestRequest;
1407
- };
1408
- /**
1409
- * features to yield to the error slot of a component
1410
- */
1411
- get errorFeatures() {
1412
- return {
1413
- isHidden: this.isHidden,
1414
- isOnline: this.isOnline,
1415
- retry: this.retry
1416
- };
1417
- }
1418
- /**
1419
- * features to yield to the content slot of a component
1420
- */
1421
- static {
1422
- decorateMethodV2(this.prototype, "errorFeatures", [memoized]);
1423
- }
1424
- get contentFeatures() {
1425
- const feat = {
1426
- isHidden: this.isHidden,
1427
- isOnline: this.isOnline,
1428
- reload: this.retry,
1429
- refresh: this.refresh,
1430
- isRefreshing: this.isRefreshing,
1431
- latestRequest: this._latestRequest
1432
- };
1433
- if (feat.isRefreshing) feat.abort = () => {
1434
- this._latestRequest?.abort();
1435
- };
1436
- return feat;
1437
- }
1438
- /**
1439
- * @internal
1440
- */
1441
- static {
1442
- decorateMethodV2(this.prototype, "contentFeatures", [memoized]);
1443
- }
1444
- get _request() {
1445
- const { request, query } = this._args;
1446
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1447
- if (!test) throw new Error(`Cannot use both @request and @query args with the <Request> component`);
1448
- })(!request || !query);
1449
- const { _localRequest, _originalRequest, _originalQuery } = this;
1450
- if (_localRequest && request === _originalRequest && query === _originalQuery) return _localRequest;
1451
- this._originalQuery = query;
1452
- this._originalRequest = request;
1453
- if (request) return request;
1454
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1455
- if (!test) throw new Error(`You must provide either @request or an @query arg with the <Request> component`);
1456
- })(query);
1457
- return this.store.request(query);
1458
- }
1459
- /**
1460
- * The {@link Future} this subscription is currently monitoring, and
1461
- * (re-)subscribes to notifications for as a side effect of access.
1462
- */
1463
- static {
1464
- decorateMethodV2(this.prototype, "_request", [memoized]);
1465
- }
1466
- get request() {
1467
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) try {
1468
- const request = this._request;
1469
- this._updateSubscriptions();
1470
- return request;
1471
- } catch (e) {
1472
- console.log(e);
1473
- throw new Error(`Unable to initialize the request`, { cause: e });
1474
- }
1475
- else {
1476
- const request = this._request;
1477
- this._updateSubscriptions();
1478
- return request;
1479
- }
1480
- }
1481
- /**
1482
- * The {@link RequestState} for {@link RequestSubscription.request | request}.
1483
- */
1484
- static {
1485
- decorateMethodV2(this.prototype, "request", [memoized]);
1486
- }
1487
- get reqState() {
1488
- return getRequestState(this.request);
1489
- }
1490
- /**
1491
- * The resolved content of the request, once it has succeeded.
1492
- */
1493
- get result() {
1494
- return this.reqState.result;
1495
- }
1496
- };
1497
- defineSignal(RequestSubscription.prototype, "isOnline", true);
1498
- defineSignal(RequestSubscription.prototype, "isHidden", false);
1499
- defineSignal(RequestSubscription.prototype, "isRefreshing", false);
1500
- defineSignal(RequestSubscription.prototype, "_localRequest", void 0);
1501
- defineSignal(RequestSubscription.prototype, "_latestRequest", void 0);
1502
- function isStore(store) {
1503
- return "requestManager" in store;
1504
- }
1505
- /**
1506
- * Creates a {@link RequestSubscription}, the reactive class powering the
1507
- * `<Request />` component's autorefresh, retry, and refresh behaviors.
1508
- */
1509
- function createRequestSubscription(store, args) {
1510
- return new RequestSubscription(store, args);
1511
- }
1512
- function upgradeSubscription(sub) {
1513
- return sub;
1514
- }
1515
- function _DISPOSE() {
1516
- const self = upgradeSubscription(this);
1517
- self.isDestroyed = true;
1518
- self._removeSubscriptions();
1519
- self._clearInterval();
1520
- if (self._onlineChanged && typeof window !== "undefined" && typeof window.removeEventListener === "function") {
1521
- window.removeEventListener("online", self._onlineChanged, {
1522
- passive: true,
1523
- capture: true
1524
- });
1525
- window.removeEventListener("offline", self._onlineChanged, {
1526
- passive: true,
1527
- capture: true
1528
- });
1529
- }
1530
- if (self._backgroundChanged && typeof document !== "undefined" && typeof document.removeEventListener === "function") document.removeEventListener("visibilitychange", self._backgroundChanged, {
1531
- passive: true,
1532
- capture: true
1533
- });
1534
- }
1535
-
1536
- //#endregion
1537
- //#region src/signals/promise-state.ts
1538
- const PromiseCache = /* @__PURE__ */ new WeakMap();
1539
- /**
1540
- * The state of a promise in the "pending"
1541
- * state. This is the default initial state.
1542
- *
1543
- */
1544
- /**
1545
- * The state of a promise in the "fulfilled" state.
1546
- * This is the state of a promise that has resolved
1547
- * successfully.
1548
- *
1549
- */
1550
- /**
1551
- * The state of a promise in the "rejected" state.
1552
- * This is the state of a promise that has rejected
1553
- * with an error.
1554
- *
1555
- */
1556
- /**
1557
- * The state of a promise. This is the type that is returned
1558
- * from `getPromiseState`.
1559
- *
1560
- * See also:
1561
- * - {@link PendingPromise}
1562
- * - {@link ResolvedPromise}
1563
- * - {@link RejectedPromise}
1564
- *
1565
- */
1566
- const PromiseStateProto = {};
1567
- defineSignal(PromiseStateProto, "reason", null);
1568
- defineSignal(PromiseStateProto, "value", null);
1569
- defineSignal(PromiseStateProto, "result", null);
1570
- defineSignal(PromiseStateProto, "error", null);
1571
- defineSignal(PromiseStateProto, "status", "pending");
1572
- defineSignal(PromiseStateProto, "isPending", true);
1573
- defineSignal(PromiseStateProto, "isLoading", true);
1574
- defineSignal(PromiseStateProto, "isSuccess", false);
1575
- defineSignal(PromiseStateProto, "isError", false);
1576
- function createPromiseState(promise) {
1577
- const state = getPromiseResult(promise);
1578
- const promiseState = Object.create(PromiseStateProto);
1579
- if (state) {
1580
- if (state.isError) {
1581
- promiseState.error = state.result;
1582
- promiseState.reason = state.result;
1583
- promiseState.status = "rejected";
1584
- promiseState.isError = true;
1585
- promiseState.isPending = false;
1586
- promiseState.isLoading = false;
1587
- } else {
1588
- promiseState.result = state.result;
1589
- promiseState.value = state.result;
1590
- promiseState.status = "fulfilled";
1591
- promiseState.isSuccess = true;
1592
- promiseState.isPending = false;
1593
- promiseState.isLoading = false;
1594
- }
1595
- } else promise.then((result) => {
1596
- setPromiseResult(promise, {
1597
- isError: false,
1598
- result
1599
- });
1600
- promiseState.result = result;
1601
- promiseState.value = result;
1602
- promiseState.status = "fulfilled";
1603
- promiseState.isSuccess = true;
1604
- promiseState.isPending = false;
1605
- promiseState.isLoading = false;
1606
- }, (error) => {
1607
- setPromiseResult(promise, {
1608
- isError: true,
1609
- result: error
1610
- });
1611
- promiseState.error = error;
1612
- promiseState.reason = error;
1613
- promiseState.status = "rejected";
1614
- promiseState.isError = true;
1615
- promiseState.isPending = false;
1616
- promiseState.isLoading = false;
1617
- });
1618
- return promiseState;
1619
- }
1620
- const LegacyPromiseProxy = Symbol.for("LegacyPromiseProxy");
1621
- function isLegacyAwaitable(promise) {
1622
- return LegacyPromiseProxy in promise && "promise" in promise && promise[LegacyPromiseProxy] === true;
1623
- }
1624
- function getPromise(promise) {
1625
- return isLegacyAwaitable(promise) ? promise.promise : promise;
1626
- }
1627
- /**
1628
- * Returns a reactive state-machine for the provided promise or awaitable.
1629
- *
1630
- * Repeat calls to `getPromiseState` with the same promise will return the same state object
1631
- * making is safe and easy to use in templates and JavaScript code to produce reactive
1632
- * behaviors around promises.
1633
- *
1634
- * `getPromiseState` can be used in both JavaScript and Template contexts.
1635
- *
1636
- * ```ts
1637
- * import { getPromiseState } from '@warp-drive/ember';
1638
- *
1639
- * const state = getPromiseState(promise);
1640
- * ```
1641
- *
1642
- * For instance, we could write a getter on a component that updates whenever
1643
- * the promise state advances or the promise changes, by combining the function
1644
- * with the use of `@cached`
1645
- *
1646
- * ```ts
1647
- * class Component {
1648
- * @cached
1649
- * get title() {
1650
- * const state = getPromiseState(this.args.request);
1651
- * if (state.isPending) {
1652
- * return 'loading...';
1653
- * }
1654
- * if (state.isError) { return null; }
1655
- * return state.result.title;
1656
- * }
1657
- * }
1658
- * ```
1659
- *
1660
- * Or in a template as a helper:
1661
- *
1662
- * ```gjs
1663
- * import { getPromiseState } from '@warp-drive/ember';
1664
- *
1665
- * <template>
1666
- * {{#let (getPromiseState @request) as |state|}}
1667
- * {{#if state.isPending}} <Spinner />
1668
- * {{else if state.isError}} <ErrorForm @error={{state.error}} />
1669
- * {{else}}
1670
- * <h1>{{state.result.title}}</h1>
1671
- * {{/if}}
1672
- * {{/let}}
1673
- * </template>
1674
- * ```
1675
- *
1676
- * If looking to use in a template, consider also the `<Await />` component.
1677
- *
1678
- * See also {@link PromiseState}
1679
- */
1680
- function getPromiseState(promise) {
1681
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) && ((test) => {
1682
- if (!test) throw new Error(`getPromiseState expects to be called with a promise: called with ${String(promise)}`);
1683
- })(promise);
1684
- const _promise = getPromise(promise);
1685
- let state = PromiseCache.get(_promise);
1686
- if (!state) {
1687
- state = createPromiseState(_promise);
1688
- PromiseCache.set(_promise, state);
1689
- }
1690
- return state;
1691
- }
1692
-
1693
- //#endregion
1694
- export { ARRAY_SIGNAL as C, willSyncFlushWatchers as D, waitFor as E, withSignalStore as S, setupSignals as T, createInternalSignal as _, createSignalDescriptor as a, notifyInternalSignal as b, defineSignal as c, gate as d, memoized as f, createInternalMemo as g, consumeInternalSignal as h, getRequestState as i, entangleInitiallyStaleSignal as l, Signals as m, DISPOSE as n, defineGate as o, signal as p, createRequestSubscription as r, defineNonEnumerableSignal as s, getPromiseState as t, entangleSignal as u, getOrCreateInternalSignal as v, OBJECT_SIGNAL as w, peekInternalSignal as x, makeInitializer as y };
1695
- //# sourceMappingURL=-private-HjaQ1wp1.js.map