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

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