apps 0.0.1-beta.13 → 0.0.1-beta.132

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 (205) hide show
  1. package/README.md +60 -42
  2. package/framework-reference.json +1 -1
  3. package/js/{chunk-M3B3DE4K.js → chunk-2XDCAXAR.js} +612 -246
  4. package/js/{chunk-IPI4MFSN.js → chunk-34RH47V5.js} +2 -2
  5. package/js/{chunk-RFVIONFX.js → chunk-36COQXTI.js} +136 -45
  6. package/js/{chunk-ODEIDRGW.js → chunk-3PIXIKHR.js} +1152 -504
  7. package/js/chunk-5SSWQNLR.js +449 -0
  8. package/js/{chunk-KUMBKVJD.js → chunk-6QZVXLF2.js} +2 -2
  9. package/js/chunk-7MPPHKRW.js +5418 -0
  10. package/js/chunk-AYXVIAPV.js +335 -0
  11. package/js/chunk-H2K7OZ47.js +90 -0
  12. package/js/chunk-I6QAWNUM.js +161 -0
  13. package/js/chunk-IMTTIZID.js +576 -0
  14. package/js/chunk-JYH7YLV7.js +49 -0
  15. package/js/{chunk-QS6CAHKC.js → chunk-KVZRGT5A.js} +4 -3
  16. package/js/chunk-LSOHA2RH.js +88 -0
  17. package/js/{chunk-UK573G7W.js → chunk-MB6L5YZE.js} +1817 -632
  18. package/js/chunk-OBT33ZDK.js +95 -0
  19. package/js/chunk-OD3KFKZD.js +1617 -0
  20. package/js/chunk-PZQCBLMC.js +175 -0
  21. package/js/{chunk-JU7VHODU.js → chunk-QTX7OUFH.js} +65 -10
  22. package/js/{chunk-VFZKSM3T.js → chunk-VX36SA7Y.js} +3 -3
  23. package/js/{chunk-5T57N25Q.js → chunk-WXHRUWNT.js} +651 -70
  24. package/js/chunk-XNDA3277.js +724 -0
  25. package/js/{chunk-CDL5PM2Q.js → chunk-YFSOSNF3.js} +17265 -12477
  26. package/js/chunk-YRAKYZJP.js +1945 -0
  27. package/js/{chunk-IJX4CYZO.js → chunk-YVN2AMAU.js} +976 -447
  28. package/js/chunk-YYLI5HVR.js +1016 -0
  29. package/js/client.js +234 -92
  30. package/js/contracts.js +154 -21
  31. package/js/effect.js +18 -19
  32. package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
  33. package/js/graphql.js +231 -188
  34. package/js/host.js +138 -80
  35. package/js/index.js +153 -300
  36. package/js/mcp/effect.js +21 -21
  37. package/js/mcp.js +91 -57
  38. package/js/openapi.js +4357 -1415
  39. package/js/react.js +2 -3
  40. package/js/skills/effect.js +6 -3
  41. package/js/skills.js +220 -81
  42. package/js/storage/facet.js +1 -540
  43. package/js/ui/auth/contracts.js +2 -2
  44. package/js/ui/auth.js +5 -5
  45. package/js/ui/contracts.js +9 -8
  46. package/js/ui/serving.js +8618 -235
  47. package/package.json +3 -8
  48. package/runtime.json +1 -1
  49. package/types/app-cache/src/contracts/cache.d.ts +18 -0
  50. package/types/app-cache/src/index.d.ts +34 -2
  51. package/types/apps/src/contracts/api-response-error.d.ts +4 -0
  52. package/types/apps/src/contracts/app.d.ts +56 -11
  53. package/types/apps/src/contracts/cache.d.ts +20 -0
  54. package/types/apps/src/contracts/context.d.ts +60 -17
  55. package/types/apps/src/contracts/elicitation.d.ts +23 -7
  56. package/types/apps/src/contracts/events.d.ts +94 -0
  57. package/types/apps/src/contracts/failure.d.ts +30 -1
  58. package/types/apps/src/contracts/graphql.d.ts +40 -2
  59. package/types/apps/src/contracts/help-text.d.ts +31 -0
  60. package/types/apps/src/contracts/host.d.ts +1493 -20
  61. package/types/apps/src/contracts/icons.d.ts +28 -0
  62. package/types/apps/src/contracts/live.d.ts +2 -0
  63. package/types/apps/src/contracts/mcp.d.ts +81 -20
  64. package/types/apps/src/contracts/network.d.ts +120 -0
  65. package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
  66. package/types/apps/src/contracts/openapi-document.d.ts +1 -1
  67. package/types/apps/src/contracts/openapi.d.ts +40 -8
  68. package/types/apps/src/contracts/operations.d.ts +14 -7
  69. package/types/apps/src/contracts/placement.d.ts +102 -0
  70. package/types/apps/src/contracts/protocol-version.d.ts +2 -2
  71. package/types/apps/src/contracts/protocols/1.d.ts +513 -15
  72. package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
  73. package/types/apps/src/contracts/protocols/11.d.ts +1149 -0
  74. package/types/apps/src/contracts/protocols/12.d.ts +3310 -0
  75. package/types/apps/src/contracts/protocols/13.d.ts +6001 -0
  76. package/types/apps/src/contracts/protocols/2.d.ts +9 -8
  77. package/types/apps/src/contracts/protocols/3.d.ts +73 -15
  78. package/types/apps/src/contracts/protocols/4.d.ts +22 -15
  79. package/types/apps/src/contracts/protocols/5.d.ts +37 -11
  80. package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
  81. package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
  82. package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
  83. package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
  84. package/types/apps/src/contracts/protocols/current.d.ts +7114 -0
  85. package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
  86. package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
  87. package/types/apps/src/contracts/provider-error.d.ts +9 -0
  88. package/types/apps/src/contracts/provider.d.ts +56 -0
  89. package/types/apps/src/contracts/router.d.ts +2 -1
  90. package/types/apps/src/contracts/schedules.d.ts +7 -1
  91. package/types/apps/src/contracts/schema.d.ts +21 -0
  92. package/types/apps/src/contracts/shared-catalog.d.ts +11 -0
  93. package/types/apps/src/contracts/skills.d.ts +50 -13
  94. package/types/apps/src/contracts/sql.d.ts +63 -0
  95. package/types/apps/src/contracts/ui.d.ts +70 -30
  96. package/types/apps/src/contracts/webhooks.d.ts +24 -7
  97. package/types/apps/src/contracts/workflows.d.ts +56 -34
  98. package/types/apps/src/facet.d.ts +4 -5
  99. package/types/apps/src/host.d.ts +5 -0
  100. package/types/apps/src/implementation/account-router.d.ts +20 -3
  101. package/types/apps/src/implementation/app.d.ts +41 -14
  102. package/types/apps/src/implementation/authoring.d.ts +25 -5
  103. package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
  104. package/types/apps/src/implementation/cache.d.ts +29 -2
  105. package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
  106. package/types/apps/src/implementation/elicitation.d.ts +16 -13
  107. package/types/apps/src/implementation/events.d.ts +64 -0
  108. package/types/apps/src/implementation/failure-detail.d.ts +28 -5
  109. package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
  110. package/types/apps/src/implementation/graphql.d.ts +4 -3
  111. package/types/apps/src/implementation/help-text.d.ts +5 -0
  112. package/types/apps/src/implementation/input-problems.d.ts +6 -2
  113. package/types/apps/src/implementation/invocation-timing.d.ts +18 -0
  114. package/types/apps/src/implementation/live.d.ts +2 -2
  115. package/types/apps/src/implementation/mcp-call.d.ts +6 -5
  116. package/types/apps/src/implementation/mcp-catalog.d.ts +6 -4
  117. package/types/apps/src/implementation/mcp-client.d.ts +17 -9
  118. package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
  119. package/types/apps/src/implementation/mcp.d.ts +20 -9
  120. package/types/apps/src/implementation/network.d.ts +16 -0
  121. package/types/apps/src/implementation/openapi-compile.d.ts +38 -7
  122. package/types/apps/src/implementation/openapi-document.d.ts +50 -20
  123. package/types/apps/src/implementation/openapi-names.d.ts +9 -4
  124. package/types/apps/src/implementation/openapi-request.d.ts +10 -2
  125. package/types/apps/src/implementation/openapi-source.d.ts +23 -1
  126. package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
  127. package/types/apps/src/implementation/operations.d.ts +58 -7
  128. package/types/apps/src/implementation/optimistic.d.ts +1 -1
  129. package/types/apps/src/implementation/placement.d.ts +60 -0
  130. package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
  131. package/types/apps/src/implementation/provider-error.d.ts +28 -1
  132. package/types/apps/src/implementation/provider.d.ts +20 -4
  133. package/types/apps/src/implementation/query-commit.d.ts +1 -1
  134. package/types/apps/src/implementation/router-catalog.d.ts +22 -97
  135. package/types/apps/src/implementation/router.d.ts +26 -6
  136. package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
  137. package/types/apps/src/implementation/schedules.d.ts +39 -8
  138. package/types/apps/src/implementation/schema.d.ts +125 -17
  139. package/types/apps/src/implementation/skills.d.ts +18 -24
  140. package/types/apps/src/implementation/sql.d.ts +71 -0
  141. package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
  142. package/types/apps/src/implementation/ui-auth.d.ts +1 -1
  143. package/types/apps/src/implementation/ui-client.d.ts +3 -3
  144. package/types/apps/src/implementation/ui-document.d.ts +5 -0
  145. package/types/apps/src/implementation/ui-errors.d.ts +1 -1
  146. package/types/apps/src/implementation/ui-serving.d.ts +38 -12
  147. package/types/apps/src/implementation/upstream-error.d.ts +17 -0
  148. package/types/apps/src/implementation/webhooks.d.ts +15 -6
  149. package/types/apps/src/implementation/workflow-context.d.ts +6 -2
  150. package/types/apps/src/implementation/workflows.d.ts +11 -4
  151. package/types/apps/src/index.d.ts +67 -17
  152. package/types/apps/src/mcp.d.ts +20 -1
  153. package/types/apps/src/openapi.d.ts +22 -1
  154. package/types/apps/src/react.d.ts +1 -1
  155. package/types/apps/src/skills.d.ts +10 -8
  156. package/types/apps/src/ui-serving.d.ts +1 -2
  157. package/types/telemetry/src/app-records.d.ts +42 -0
  158. package/types/telemetry/src/browser-operations.d.ts +2 -2
  159. package/types/telemetry/src/browser.d.ts +8 -3
  160. package/types/telemetry/src/config.d.ts +2 -2
  161. package/types/telemetry/src/index.d.ts +3 -2
  162. package/types/telemetry/src/keepalive.d.ts +36 -0
  163. package/types/telemetry/src/layer.d.ts +10 -4
  164. package/types/telemetry/src/measurements.d.ts +6 -2
  165. package/types/telemetry/src/ownership.d.ts +60 -0
  166. package/types/telemetry/src/recorded-failure.d.ts +29 -0
  167. package/types/telemetry/src/relay.d.ts +32 -7
  168. package/types/telemetry/src/span-attributes.d.ts +22 -3
  169. package/types/telemetry/src/transport.d.ts +8 -1
  170. package/types/utils/src/api-error.d.ts +55 -0
  171. package/types/utils/src/connection-failure.d.ts +33 -0
  172. package/types/utils/src/legacy-keys.d.ts +20 -0
  173. package/types/utils/src/random-uuid.d.ts +6 -0
  174. package/types/utils/src/recorded-message.d.ts +18 -0
  175. package/types/utils/src/schema-definitions.d.ts +13 -0
  176. package/types/utils/src/user-facing-error.d.ts +83 -0
  177. package/js/chunk-27F7W2LG.js +0 -34
  178. package/js/chunk-4ASNKGCV.js +0 -242
  179. package/js/chunk-4DWF4ZWI.js +0 -1280
  180. package/js/chunk-57RKNWL2.js +0 -75
  181. package/js/chunk-6HSH75OI.js +0 -2688
  182. package/js/chunk-G4FT53I7.js +0 -224
  183. package/js/chunk-MKWZPDR6.js +0 -63
  184. package/js/chunk-N7YDVXYJ.js +0 -186
  185. package/js/chunk-NKLWZJLE.js +0 -172
  186. package/js/chunk-PJJ24GU7.js +0 -877
  187. package/js/chunk-PZB6T6KU.js +0 -19
  188. package/js/chunk-R3EV5FTO.js +0 -97
  189. package/js/chunk-S73JGVR5.js +0 -507
  190. package/js/chunk-TG6DOCRO.js +0 -299
  191. package/js/chunk-YPKG2QO5.js +0 -209
  192. package/js/chunk-ZQINWV4W.js +0 -630
  193. package/js/mcp/stdio.js +0 -128
  194. package/types/app-data/src/implementation/cursor.d.ts +0 -10
  195. package/types/app-data/src/implementation/index-key.d.ts +0 -7
  196. package/types/app-data/src/implementation/promise.d.ts +0 -68
  197. package/types/app-data/src/implementation/range.d.ts +0 -8
  198. package/types/app-data/src/implementation/schema.d.ts +0 -18
  199. package/types/app-data/src/implementation/sqlite.d.ts +0 -11
  200. package/types/app-data/src/index.d.ts +0 -4
  201. package/types/apps/src/contracts/storage.d.ts +0 -68
  202. package/types/apps/src/implementation/mcp-stdio.d.ts +0 -4
  203. package/types/apps/src/implementation/storage.d.ts +0 -15
  204. package/types/apps/src/implementation/ui-watch.d.ts +0 -2
  205. package/types/apps/src/mcp-stdio.d.ts +0 -5
@@ -1,9 +1,3 @@
1
- import {
2
- Reactivity,
3
- invalidate,
4
- layer,
5
- mutation
6
- } from "./chunk-PJJ24GU7.js";
7
1
  import {
8
2
  Boolean,
9
3
  Cause,
@@ -12,7 +6,7 @@ import {
12
6
  Int,
13
7
  InvalidType,
14
8
  MixedScheduler,
15
- Never,
9
+ Never2 as Never,
16
10
  NoSuchElementError,
17
11
  Option,
18
12
  Option_exports,
@@ -23,7 +17,7 @@ import {
23
17
  Service,
24
18
  TaggedError,
25
19
  TaggedStruct,
26
- Union,
20
+ Union2 as Union,
27
21
  acquireRelease,
28
22
  add,
29
23
  addFinalizer,
@@ -43,6 +37,7 @@ import {
43
37
  constTrue,
44
38
  constVoid,
45
39
  constant,
40
+ context,
46
41
  contextWith,
47
42
  declareConstructor,
48
43
  decodeEffect,
@@ -58,13 +53,13 @@ import {
58
53
  encodeEffect,
59
54
  encodeExit,
60
55
  encodeSync,
61
- ensuring2 as ensuring,
62
56
  equals,
63
57
  fail2 as fail,
64
58
  fail3 as fail2,
65
59
  fail4 as fail3,
66
60
  failCause,
67
61
  failCause2,
62
+ failCauseUnsafe,
68
63
  filter,
69
64
  filter2,
70
65
  filterInterruptors,
@@ -75,9 +70,11 @@ import {
75
70
  flatMap2,
76
71
  flatMapEager,
77
72
  flatMapNullishOr,
73
+ flow,
78
74
  forkDetach,
79
75
  fromInputUnsafe,
80
76
  fromJsonString,
77
+ fromQueue,
81
78
  gen,
82
79
  get,
83
80
  get2,
@@ -87,6 +84,7 @@ import {
87
84
  getOrNull,
88
85
  getOrThrowWith,
89
86
  getOrUndefined,
87
+ getOrUndefined2,
90
88
  getStackTraceLimit,
91
89
  getSuccess,
92
90
  getUnsafe,
@@ -94,6 +92,7 @@ import {
94
92
  hasProperty,
95
93
  hash,
96
94
  identity,
95
+ ignoreCause,
97
96
  interrupt,
98
97
  isDoneCause,
99
98
  isEffect,
@@ -103,17 +102,19 @@ import {
103
102
  isIterable,
104
103
  isNone,
105
104
  isReadonlyArrayNonEmpty,
105
+ isSchemaError,
106
106
  isSome,
107
107
  isStream,
108
108
  isSubscriptionRef,
109
109
  joinAll,
110
110
  lastNonEmpty,
111
111
  link,
112
+ make2 as make,
112
113
  makeCompositeAtKey,
113
114
  makeMemoMapUnsafe,
114
115
  makeUnsafe2 as makeUnsafe,
115
116
  map,
116
- map3 as map2,
117
+ map4 as map2,
117
118
  mapBothEager,
118
119
  mapEager,
119
120
  mapEffect,
@@ -124,14 +125,18 @@ import {
124
125
  never,
125
126
  none,
126
127
  offerUnsafe,
128
+ onEnd,
129
+ onExit,
127
130
  pipe,
128
131
  pipeArguments,
129
132
  provide2 as provide,
130
133
  provideMerge,
134
+ provideService,
131
135
  remove,
132
136
  runCallbackWith,
133
137
  runForEachArray,
134
138
  runForkWith,
139
+ runIn,
135
140
  runSync,
136
141
  runSyncWith,
137
142
  scope,
@@ -148,22 +153,23 @@ import {
148
153
  symbol,
149
154
  symbol2,
150
155
  sync2 as sync,
156
+ tap,
151
157
  toCodecJson,
152
158
  toMillis,
153
159
  toPull,
154
160
  toPullScoped,
155
161
  transform,
156
- unwrap3 as unwrap,
162
+ unwrap4 as unwrap,
157
163
  void_,
158
164
  void_2,
159
165
  whileLoop,
160
166
  zipRight
161
- } from "./chunk-CDL5PM2Q.js";
167
+ } from "./chunk-YFSOSNF3.js";
162
168
  import {
163
169
  __export
164
170
  } from "./chunk-CZ7CSFO4.js";
165
171
 
166
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/AsyncResult.js
172
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/AsyncResult.js
167
173
  var AsyncResult_exports = {};
168
174
  __export(AsyncResult_exports, {
169
175
  Schema: () => Schema,
@@ -212,7 +218,7 @@ var ResultProto = {
212
218
  return pipeArguments(this, arguments);
213
219
  },
214
220
  [symbol2](that) {
215
- if (this._tag !== that._tag || this.waiting !== that.waiting) {
221
+ if (!isAsyncResult(that) || this._tag !== that._tag || this.waiting !== that.waiting) {
216
222
  return false;
217
223
  }
218
224
  switch (this._tag) {
@@ -276,7 +282,7 @@ var failureWithPrevious = (cause2, options) => failure(cause2, {
276
282
  });
277
283
  var fail4 = (error2, options) => failure(fail(error2), options);
278
284
  var failWithPrevious = (error2, options) => failureWithPrevious(fail(error2), options);
279
- var waiting = (self, options) => {
285
+ var waiting = /* @__PURE__ */ dual((args) => isAsyncResult(args[0]), (self, options) => {
280
286
  if (self.waiting) {
281
287
  return options?.touch ? touch(self) : self;
282
288
  }
@@ -287,7 +293,7 @@ var waiting = (self, options) => {
287
293
  result.timestamp = Date.now();
288
294
  }
289
295
  return result;
290
- };
296
+ });
291
297
  var touch = (result) => {
292
298
  if (isSuccess(result)) {
293
299
  return success(result.value, {
@@ -296,7 +302,7 @@ var touch = (result) => {
296
302
  }
297
303
  return result;
298
304
  };
299
- var replacePrevious = (self, previous) => {
305
+ var replacePrevious = /* @__PURE__ */ dual(2, (self, previous) => {
300
306
  if (self._tag === "Failure") {
301
307
  return failureWithPrevious(self.cause, {
302
308
  previous,
@@ -304,7 +310,7 @@ var replacePrevious = (self, previous) => {
304
310
  });
305
311
  }
306
312
  return self;
307
- };
313
+ });
308
314
  var value = (self) => {
309
315
  if (self._tag === "Success") {
310
316
  return some(self.value);
@@ -412,6 +418,11 @@ var all = (results) => {
412
418
  if (!isAsyncResult(result)) {
413
419
  assignProperty(successes, key, result);
414
420
  continue;
421
+ } else if (isFailure2(result)) {
422
+ return failure(result.cause, {
423
+ previousSuccess: combinedPreviousSuccess(entries, isIter),
424
+ waiting: result.waiting
425
+ });
415
426
  } else if (!isSuccess(result)) {
416
427
  return result;
417
428
  }
@@ -424,6 +435,22 @@ var all = (results) => {
424
435
  waiting: waiting2
425
436
  });
426
437
  };
438
+ var combinedPreviousSuccess = (entries, isIter) => {
439
+ const values = isIter ? [] : {};
440
+ for (let i = 0; i < entries.length; i++) {
441
+ const [key, entry] = entries[i];
442
+ if (!isAsyncResult(entry)) {
443
+ assignProperty(values, key, entry);
444
+ continue;
445
+ }
446
+ const entryValue = value(entry);
447
+ if (isNone(entryValue)) {
448
+ return none();
449
+ }
450
+ assignProperty(values, key, entryValue.value);
451
+ }
452
+ return some(success(values));
453
+ };
427
454
  var builder = (self) => new BuilderImpl(self);
428
455
  var BuilderImpl = class {
429
456
  constructor(result) {
@@ -600,7 +627,7 @@ var Schema = (options) => {
600
627
  });
601
628
  };
602
629
 
603
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/AtomRegistry.js
630
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/AtomRegistry.js
604
631
  var AtomRegistry_exports = {};
605
632
  __export(AtomRegistry_exports, {
606
633
  AtomRegistry: () => AtomRegistry,
@@ -608,29 +635,46 @@ __export(AtomRegistry_exports, {
608
635
  TypeId: () => TypeId2,
609
636
  batch: () => batch,
610
637
  batchState: () => batchState,
638
+ consumeSkipInitialRun: () => consumeSkipInitialRun,
611
639
  getResult: () => getResult,
612
640
  isAtomRegistry: () => isAtomRegistry,
613
- layer: () => layer2,
641
+ layer: () => layer,
614
642
  layerOptions: () => layerOptions,
615
- make: () => make,
643
+ make: () => make2,
616
644
  mount: () => mount,
617
645
  toStream: () => toStream,
618
646
  toStreamResult: () => toStreamResult
619
647
  });
648
+
649
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/internal/hydration.js
650
+ var shouldHydrate = (current, incoming) => {
651
+ if (!isAsyncResult(current) || !isAsyncResult(incoming)) {
652
+ return true;
653
+ }
654
+ if (isInitial(incoming)) {
655
+ return isInitial(current);
656
+ }
657
+ if (isSuccess(current) && isSuccess(incoming)) {
658
+ return incoming.timestamp >= current.timestamp;
659
+ }
660
+ return true;
661
+ };
662
+
663
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/AtomRegistry.js
620
664
  var TypeId2 = "~effect/reactivity/AtomRegistry";
621
665
  var isAtomRegistry = (u) => hasProperty(u, TypeId2);
622
- var make = (options) => new RegistryImpl(options?.initialValues, options?.scheduleTask, options?.timeoutResolution, options?.defaultIdleTTL);
666
+ var make2 = (options) => new RegistryImpl(options?.initialValues, options?.scheduleTask, options?.timeoutResolution, options?.defaultIdleTTL);
623
667
  var AtomRegistry = /* @__PURE__ */ Service(TypeId2);
624
668
  var layerOptions = (options) => effect(AtomRegistry, gen(function* () {
625
669
  const scope2 = yield* scope;
626
- const registry = make({
670
+ const registry = make2({
627
671
  ...options,
628
672
  scheduleTask: options?.scheduleTask
629
673
  });
630
674
  yield* addFinalizer(scope2, sync(() => registry.dispose()));
631
675
  return registry;
632
676
  }));
633
- var layer2 = /* @__PURE__ */ layerOptions();
677
+ var layer = /* @__PURE__ */ layerOptions();
634
678
  var toStream = /* @__PURE__ */ dual(2, (self, atom) => callback2((queue) => suspend(() => {
635
679
  const fiber = getCurrent();
636
680
  const scope2 = getUnsafe(fiber.context, Scope);
@@ -660,9 +704,21 @@ var mount = /* @__PURE__ */ dual(2, (self, atom) => acquireRelease(sync(() => se
660
704
  var constImmediate = {
661
705
  immediate: true
662
706
  };
663
- var notifyListener = (listener) => {
664
- listener();
707
+ var invoke = (f) => {
708
+ f();
665
709
  };
710
+ var noFailure = {};
711
+ function runAll(items, f) {
712
+ let failure2 = noFailure;
713
+ for (const item of items) {
714
+ try {
715
+ f(item);
716
+ } catch (error2) {
717
+ if (failure2 === noFailure) failure2 = error2;
718
+ }
719
+ }
720
+ if (failure2 !== noFailure) throw failure2;
721
+ }
666
722
  var SerializableTypeId = "~effect-atom/atom/Atom/Serializable";
667
723
  var atomKey = (atom) => SerializableTypeId in atom ? atom[SerializableTypeId].key : atom;
668
724
  var RegistryImpl = class {
@@ -686,12 +742,12 @@ var RegistryImpl = class {
686
742
  this.timeoutResolution = timeoutResolution ?? 1e3;
687
743
  }
688
744
  if (initialValues !== void 0) {
689
- for (const [atom, value2] of initialValues) {
745
+ for (const [atom, value2, options] of initialValues) {
690
746
  let target = atom;
691
747
  while (target.initialValueTarget) {
692
748
  target = target.initialValueTarget;
693
749
  }
694
- this.ensureNode(target).setInitialValue(value2);
750
+ this.ensureNode(target).setInitialValue(value2, options?.skipInitialRun);
695
751
  }
696
752
  }
697
753
  }
@@ -733,6 +789,12 @@ var RegistryImpl = class {
733
789
  const node = this.ensureNode(atom);
734
790
  if (options?.immediate) {
735
791
  f(node.value());
792
+ } else {
793
+ try {
794
+ node.value();
795
+ } catch (error2) {
796
+ if ((node.state & NodeFlags.waitingForValue) === 0) throw error2;
797
+ }
736
798
  }
737
799
  const remove2 = node.subscribe(function() {
738
800
  f(node._value);
@@ -763,15 +825,21 @@ var RegistryImpl = class {
763
825
  if (typeof key === "string" && this.preloadedSerializable.has(key)) {
764
826
  const encoded = this.preloadedSerializable.get(key);
765
827
  this.preloadedSerializable.delete(key);
766
- const decoded = atom[SerializableTypeId].decode(encoded);
828
+ const serializable2 = atom[SerializableTypeId];
829
+ let decoded;
830
+ try {
831
+ decoded = serializable2.decode(encoded);
832
+ } catch (error2) {
833
+ if (isSchemaError(error2)) return node;
834
+ throw error2;
835
+ }
767
836
  let target = atom;
768
837
  while (target.initialValueTarget) {
769
838
  target = target.initialValueTarget;
770
839
  }
771
- if (target === atom) {
772
- node.setValue(decoded);
773
- } else {
774
- this.ensureNode(target).setInitialValue(decoded);
840
+ const targetNode = target === atom ? node : this.ensureNode(target);
841
+ if (shouldHydrate(targetNode._value, decoded)) {
842
+ targetNode.setInitialValue(decoded, serializable2.skipInitialRun);
775
843
  }
776
844
  }
777
845
  return node;
@@ -786,7 +854,9 @@ var RegistryImpl = class {
786
854
  return new NodeImpl(this, atom);
787
855
  }
788
856
  invalidateAtom = (atom) => {
789
- this.ensureNode(atom).invalidate();
857
+ const node = this.ensureNode(atom);
858
+ node.skipInitialRun = false;
859
+ node.invalidate();
790
860
  };
791
861
  scheduleAtomRemoval(atom) {
792
862
  this.dispatcher.scheduleTask(() => {
@@ -853,26 +923,35 @@ var RegistryImpl = class {
853
923
  sweepBucket(bucket) {
854
924
  const nodes = this.timeoutBuckets.get(bucket)[0];
855
925
  this.timeoutBuckets.delete(bucket);
856
- nodes.forEach((node) => {
857
- this.nodeTimeoutBucket.delete(node);
858
- if (!node.canBeRemoved) return;
859
- this.nodes.delete(atomKey(node.atom));
860
- this.onNodeRemoved?.(node);
861
- this.#currentSweepTTL = node.atom.idleTTL ?? this.defaultIdleTTL;
926
+ runAll(nodes, this.removeIdleNode);
927
+ }
928
+ removeIdleNode = (node) => {
929
+ this.nodeTimeoutBucket.delete(node);
930
+ if (!node.canBeRemoved) return;
931
+ this.nodes.delete(atomKey(node.atom));
932
+ this.onNodeRemoved?.(node);
933
+ this.#currentSweepTTL = node.atom.idleTTL ?? this.defaultIdleTTL;
934
+ try {
862
935
  node.remove();
936
+ } finally {
863
937
  this.#currentSweepTTL = null;
864
- });
865
- }
938
+ }
939
+ };
866
940
  reset() {
867
941
  this.timeoutBuckets.forEach(([, handle]) => clearTimeout(handle));
868
942
  this.timeoutBuckets.clear();
869
943
  this.nodeTimeoutBucket.clear();
870
- this.nodes.forEach((node) => {
871
- node.remove();
872
- this.onNodeRemoved?.(node);
873
- });
944
+ const nodes = Array.from(this.nodes.values());
874
945
  this.nodes.clear();
946
+ for (const node of nodes) {
947
+ node.state = NodeState.removed;
948
+ }
949
+ runAll(nodes, this.destroyNode);
875
950
  }
951
+ destroyNode = (node) => {
952
+ node.remove();
953
+ this.onNodeRemoved?.(node);
954
+ };
876
955
  dispose() {
877
956
  this.disposed = true;
878
957
  this.reset();
@@ -904,13 +983,19 @@ var NodeImpl = class {
904
983
  lifetime;
905
984
  writeContext;
906
985
  preserveInitialValueOnBuild = false;
986
+ skipInitialRun = false;
987
+ // the parents, and their lifetimes, of a build that kept the seed without
988
+ // reaching the effect, such as one waiting for a runtime
989
+ keptParents;
990
+ invalidatedDuringBuild = false;
991
+ failed = false;
992
+ // Every parent that holds this node as a child. A stale node keeps the
993
+ // parents of its last build, so they are not released and their next change
994
+ // still reaches it. A build drops the parents it did not read.
907
995
  parents = /* @__PURE__ */ new Set();
908
- previousParents;
909
996
  children = /* @__PURE__ */ new Set();
910
997
  listeners = /* @__PURE__ */ new Set();
911
- skipInvalidation = false;
912
- building = false;
913
- invalidatedDuringBuild = false;
998
+ observedChildren = 0;
914
999
  currentState() {
915
1000
  switch (this.state) {
916
1001
  case NodeState.uninitialized:
@@ -926,33 +1011,115 @@ var NodeImpl = class {
926
1011
  get canBeRemoved() {
927
1012
  return !this.atom.keepAlive && this.listeners.size === 0 && this.children.size === 0 && this.state !== 0;
928
1013
  }
1014
+ get building() {
1015
+ return this.lifetime !== void 0 && this.lifetime.reads !== void 0;
1016
+ }
1017
+ // An observed node is rebuilt as soon as it goes stale, because something
1018
+ // waits for its value without reading it. The count spares walking the
1019
+ // children on every invalidation.
1020
+ get isObserved() {
1021
+ return !this.atom.lazy || this.listeners.size > 0 || this.observedChildren > 0;
1022
+ }
1023
+ childObserved(delta) {
1024
+ const observed = this.isObserved;
1025
+ this.observedChildren += delta;
1026
+ if (observed !== this.isObserved) {
1027
+ this.observedChanged(delta);
1028
+ }
1029
+ }
1030
+ observedChanged(delta) {
1031
+ for (const parent of this.parents) {
1032
+ parent.childObserved(delta);
1033
+ }
1034
+ }
929
1035
  _value = void 0;
930
1036
  value() {
931
- if ((this.state & NodeFlags.waitingForValue) !== 0) {
932
- this.lifetime = makeLifetime(this);
933
- this.building = true;
934
- const value2 = this.atom.read(this.lifetime);
935
- this.building = false;
936
- if ((this.state & NodeFlags.waitingForValue) !== 0) {
937
- if (this.preserveInitialValueOnBuild) {
938
- this.preserveInitialValueOnBuild = false;
939
- this.state = NodeState.valid;
940
- } else {
941
- this.setValue(value2);
942
- }
1037
+ while ((this.state & NodeFlags.waitingForValue) !== 0) {
1038
+ this.build();
1039
+ }
1040
+ return this._value;
1041
+ }
1042
+ build() {
1043
+ const lifetime = makeLifetime(this);
1044
+ try {
1045
+ this.disposeLifetime();
1046
+ } catch (error2) {
1047
+ lifetime.failure = error2;
1048
+ }
1049
+ this.invalidatedDuringBuild = false;
1050
+ this.lifetime = lifetime;
1051
+ let value2;
1052
+ let read = false;
1053
+ try {
1054
+ value2 = this.atom.read(lifetime);
1055
+ read = true;
1056
+ } finally {
1057
+ const reads = lifetime.reads;
1058
+ lifetime.reads = void 0;
1059
+ if (this.lifetime === lifetime) {
1060
+ this.dropUnread(reads);
1061
+ if (!read) this.fail();
943
1062
  }
944
- if (this.previousParents) {
945
- const parents = this.previousParents;
946
- this.previousParents = void 0;
947
- for (const parent of parents) {
948
- parent.removeChild(this);
949
- if (parent.canBeRemoved) {
950
- this.registry.scheduleNodeRemoval(parent);
951
- }
1063
+ }
1064
+ if (this.lifetime === lifetime && (this.state & NodeFlags.waitingForValue) !== 0) {
1065
+ if (this.preserveInitialValueOnBuild) {
1066
+ this.preserveInitialValueOnBuild = false;
1067
+ if (this.skipInitialRun) {
1068
+ this.keptParents = Array.from(this.parents, (parent) => [parent, parent.lifetime]);
952
1069
  }
1070
+ this.failed = false;
1071
+ this.state = NodeState.valid;
1072
+ } else {
1073
+ this.setValue(value2);
1074
+ }
1075
+ }
1076
+ if (lifetime.failure !== noFailure) throw lifetime.failure;
1077
+ }
1078
+ // A build that threw leaves its dependents holding, or reading, a value
1079
+ // this node no longer stands behind, so they go stale and rebuild when
1080
+ // pulled or observed. The read's error is the one reported.
1081
+ fail() {
1082
+ this.failed = true;
1083
+ try {
1084
+ this.invalidateChildren();
1085
+ } catch {
1086
+ }
1087
+ }
1088
+ readTracked(atom, lifetime) {
1089
+ const parent = this.registry.ensureNode(atom);
1090
+ if (!this.parents.has(parent)) {
1091
+ this.parents.add(parent);
1092
+ parent.children.add(this);
1093
+ if (this.isObserved) {
1094
+ parent.childObserved(1);
1095
+ }
1096
+ }
1097
+ try {
1098
+ return parent.value();
1099
+ } catch (error2) {
1100
+ if (lifetime.reads === void 0 || parent.state !== NodeState.valid) throw error2;
1101
+ if (lifetime.failure === noFailure) lifetime.failure = error2;
1102
+ return parent._value;
1103
+ } finally {
1104
+ if (lifetime.reads !== void 0 && !lifetime.disposed) {
1105
+ lifetime.reads.add(parent);
1106
+ }
1107
+ }
1108
+ }
1109
+ dropUnread(reads) {
1110
+ if (reads.size === this.parents.size) return;
1111
+ const observed = this.isObserved;
1112
+ for (const parent of this.parents) {
1113
+ if (reads.has(parent)) continue;
1114
+ this.parents.delete(parent);
1115
+ parent.children.delete(this);
1116
+ if (observed) {
1117
+ parent.childObserved(-1);
1118
+ }
1119
+ if (parent.canBeRemoved) {
1120
+ this.registry.scheduleNodeRemoval(parent);
953
1121
  }
954
1122
  }
955
- return this._value;
956
1123
  }
957
1124
  valueOption() {
958
1125
  if ((this.state & NodeFlags.initialized) === 0) {
@@ -960,156 +1127,158 @@ var NodeImpl = class {
960
1127
  }
961
1128
  return some(this._value);
962
1129
  }
963
- setInitialValue(value2) {
1130
+ setInitialValue(value2, skipInitialRun = false) {
964
1131
  if ((this.state & NodeFlags.initialized) === 0) {
965
1132
  this.preserveInitialValueOnBuild = true;
1133
+ this.skipInitialRun = skipInitialRun;
966
1134
  this.state = NodeState.stale;
967
1135
  this._value = value2;
968
- if (batchState.phase === BatchPhase.collect) {
969
- batchState.notify.add(this);
970
- } else {
971
- this.notify();
1136
+ if (this.listeners.size > 0) {
1137
+ this.announce();
972
1138
  }
973
1139
  return;
974
1140
  }
975
1141
  this.setValue(value2);
976
1142
  }
977
1143
  setValue(value2) {
978
- if ((this.state & NodeFlags.initialized) === 0) {
979
- this.state = NodeState.valid;
980
- this._value = value2;
981
- if (batchState.phase === BatchPhase.collect) {
982
- batchState.notify.add(this);
983
- } else {
984
- this.notify();
985
- }
986
- return;
987
- }
1144
+ const recovered = this.failed;
1145
+ this.failed = false;
1146
+ const initialized = (this.state & NodeFlags.initialized) !== 0;
988
1147
  this.state = NodeState.valid;
989
- if (this.atom.equals(this._value, value2)) {
1148
+ if (initialized && this.atom.equals(this._value, value2)) {
1149
+ if (recovered) this.invalidateChildren();
990
1150
  return;
991
1151
  }
992
1152
  this._value = value2;
993
- if (this.skipInvalidation) {
994
- this.skipInvalidation = false;
995
- } else {
996
- this.invalidateChildren();
1153
+ let failure2 = noFailure;
1154
+ try {
1155
+ if (initialized || recovered) this.invalidateChildren();
1156
+ } catch (error2) {
1157
+ failure2 = error2;
997
1158
  }
998
1159
  if (this.listeners.size > 0) {
999
- if (batchState.phase === BatchPhase.collect) {
1000
- batchState.notify.add(this);
1001
- } else {
1002
- this.notify();
1160
+ try {
1161
+ this.announce();
1162
+ } catch (error2) {
1163
+ if (failure2 === noFailure) failure2 = error2;
1003
1164
  }
1004
1165
  }
1166
+ if (failure2 !== noFailure) throw failure2;
1005
1167
  }
1006
- addParent(parent) {
1007
- this.parents.add(parent);
1008
- if (this.previousParents !== void 0) {
1009
- this.previousParents.delete(parent);
1010
- if (this.previousParents.size === 0) {
1011
- this.previousParents = void 0;
1012
- }
1013
- }
1014
- if (!parent.children.has(this)) {
1015
- parent.children.add(this);
1016
- if (parent.skipInvalidation) {
1017
- parent.skipInvalidation = false;
1018
- }
1168
+ announce() {
1169
+ if (batchState.phase === BatchPhase.collect) {
1170
+ batchState.notify.add(this);
1171
+ } else {
1172
+ this.notify();
1019
1173
  }
1020
1174
  }
1021
- removeChild(child) {
1022
- this.children.delete(child);
1023
- }
1024
1175
  invalidate() {
1025
- if (this.building && batchState.phase === BatchPhase.collect) {
1026
- this.invalidatedDuringBuild = true;
1027
- }
1028
1176
  if (this.state === NodeState.valid) {
1029
1177
  this.state = NodeState.stale;
1030
- this.disposeLifetime();
1178
+ try {
1179
+ this.disposeLifetime();
1180
+ } finally {
1181
+ this.propagate();
1182
+ }
1183
+ } else if (this.building && batchState.phase !== BatchPhase.collect) {
1184
+ this.build();
1185
+ } else {
1186
+ this.propagate();
1031
1187
  }
1188
+ }
1189
+ propagate() {
1032
1190
  if (batchState.phase === BatchPhase.collect) {
1191
+ if (this.building) {
1192
+ this.invalidatedDuringBuild = true;
1193
+ }
1033
1194
  batchState.stale.push(this);
1034
- } else if (this.atom.lazy && this.listeners.size === 0 && !childrenAreActive(this.children)) {
1035
- this.invalidateChildren();
1036
- this.skipInvalidation = true;
1037
- } else {
1195
+ } else if (this.isObserved) {
1038
1196
  this.value();
1197
+ } else {
1198
+ this.invalidateChildren();
1039
1199
  }
1040
1200
  }
1041
1201
  invalidateChildren() {
1042
1202
  if (this.children.size === 0) {
1043
1203
  return;
1044
1204
  }
1045
- const children = this.children;
1046
- this.children = /* @__PURE__ */ new Set();
1047
- for (const child of children) {
1048
- child.invalidate();
1205
+ let failure2 = noFailure;
1206
+ for (const child of Array.from(this.children)) {
1207
+ if (!child.affectedBy(this)) continue;
1208
+ try {
1209
+ child.invalidate();
1210
+ } catch (error2) {
1211
+ if (failure2 === noFailure) failure2 = error2;
1212
+ }
1049
1213
  }
1214
+ if (failure2 !== noFailure) throw failure2;
1215
+ }
1216
+ // Whether a change of the parent reaches this node: it holds the parent's
1217
+ // value, or a running build has already read it. A stale node is stale
1218
+ // already, and a build that has not read the parent yet will read the new
1219
+ // value. The exception is an observed node that is still stale: its rebuild
1220
+ // failed, and a parent that has a value again is its chance to recover.
1221
+ affectedBy(parent) {
1222
+ if (this.state === NodeState.valid) return true;
1223
+ const reads = this.lifetime?.reads;
1224
+ if (reads !== void 0) return reads.has(parent);
1225
+ return this.isObserved && parent.state === NodeState.valid;
1050
1226
  }
1051
1227
  notify() {
1052
- this.listeners.forEach(notifyListener);
1053
1228
  if (batchState.phase === BatchPhase.commit) {
1054
1229
  batchState.notify.delete(this);
1055
1230
  }
1231
+ runAll(this.listeners, invoke);
1056
1232
  }
1057
1233
  disposeLifetime() {
1058
- if (this.lifetime !== void 0) {
1059
- this.lifetime.dispose();
1234
+ const lifetime = this.lifetime;
1235
+ if (lifetime !== void 0) {
1060
1236
  this.lifetime = void 0;
1061
- }
1062
- if (this.parents.size !== 0) {
1063
- this.previousParents = this.parents;
1064
- this.parents = /* @__PURE__ */ new Set();
1237
+ lifetime.dispose();
1065
1238
  }
1066
1239
  }
1067
1240
  remove() {
1241
+ const observed = this.isObserved;
1068
1242
  this.state = NodeState.removed;
1069
1243
  this.listeners.clear();
1070
- if (this.lifetime !== void 0) {
1244
+ try {
1071
1245
  this.disposeLifetime();
1072
- }
1073
- if (this.previousParents === void 0) {
1074
- return;
1075
- }
1076
- const parents = this.previousParents;
1077
- this.previousParents = void 0;
1078
- for (const parent of parents) {
1079
- parent.removeChild(this);
1080
- if (parent.canBeRemoved) {
1081
- this.registry.removeNode(parent);
1082
- }
1246
+ } finally {
1247
+ const parents = Array.from(this.parents);
1248
+ this.parents.clear();
1249
+ runAll(parents, (parent) => {
1250
+ parent.children.delete(this);
1251
+ if (observed) {
1252
+ parent.childObserved(-1);
1253
+ }
1254
+ if (parent.canBeRemoved) {
1255
+ this.registry.removeNode(parent);
1256
+ }
1257
+ });
1083
1258
  }
1084
1259
  }
1085
1260
  subscribe(listener) {
1261
+ const observed = this.isObserved;
1086
1262
  this.listeners.add(listener);
1087
- return () => this.listeners.delete(listener);
1088
- }
1089
- };
1090
- function childrenAreActive(children) {
1091
- if (children.size === 0) {
1092
- return false;
1093
- }
1094
- let current = children;
1095
- let stack;
1096
- let stackIndex = 0;
1097
- while (current !== void 0) {
1098
- for (const child of current) {
1099
- if (!child.atom.lazy || child.listeners.size > 0) {
1100
- return true;
1101
- } else if (child.children.size > 0) {
1102
- if (stack === void 0) {
1103
- stack = [child.children];
1104
- } else {
1105
- stack.push(child.children);
1106
- }
1107
- }
1263
+ if (!observed) {
1264
+ this.observedChanged(1);
1108
1265
  }
1109
- current = stack?.[stackIndex++];
1266
+ return () => {
1267
+ if (this.listeners.delete(listener) && !this.isObserved) {
1268
+ this.observedChanged(-1);
1269
+ }
1270
+ };
1110
1271
  }
1111
- return false;
1112
- }
1272
+ };
1273
+ var consumeSkipInitialRun = (ctx) => {
1274
+ const lifetime = ctx;
1275
+ const node = lifetime.node;
1276
+ if (!node.skipInitialRun) return false;
1277
+ const keptParents = node.keptParents;
1278
+ node.skipInitialRun = false;
1279
+ node.keptParents = void 0;
1280
+ return !lifetime.isFn && !isInitial(node._value) && (keptParents === void 0 || keptParents.every(([parent, lifetime2]) => parent.lifetime === lifetime2));
1281
+ };
1113
1282
  var LifetimeProto = {
1114
1283
  get registry() {
1115
1284
  return this.node.registry;
@@ -1123,10 +1292,7 @@ var LifetimeProto = {
1123
1292
  if (this.disposed) {
1124
1293
  return this.node.registry.get(atom);
1125
1294
  }
1126
- const parent = this.node.registry.ensureNode(atom);
1127
- const value2 = parent.value();
1128
- this.node.addParent(parent);
1129
- return value2;
1295
+ return this.node.readTracked(atom, this);
1130
1296
  },
1131
1297
  result(atom, options) {
1132
1298
  if (this.disposed || this.isFn) {
@@ -1243,28 +1409,23 @@ var LifetimeProto = {
1243
1409
  }
1244
1410
  const finalizers = this.finalizers;
1245
1411
  this.finalizers = void 0;
1246
- for (let i = finalizers.length - 1; i >= 0; i--) {
1247
- finalizers[i]();
1248
- }
1412
+ runAll(finalizers.reverse(), invoke);
1249
1413
  }
1250
1414
  };
1251
1415
  var makeLifetime = (node) => {
1252
1416
  function get5(atom) {
1253
- if (get5.disposed) {
1254
- return node.registry.get(atom);
1255
- } else if (get5.isFn) {
1417
+ if (get5.disposed || get5.isFn) {
1256
1418
  return node.registry.get(atom);
1257
1419
  }
1258
- const parent = node.registry.ensureNode(atom);
1259
- const value2 = parent.value();
1260
- node.addParent(parent);
1261
- return value2;
1420
+ return node.readTracked(atom, get5);
1262
1421
  }
1263
1422
  Object.setPrototypeOf(get5, LifetimeProto);
1264
1423
  get5.isFn = false;
1265
1424
  get5.disposed = false;
1266
1425
  get5.finalizers = void 0;
1267
1426
  get5.node = node;
1427
+ get5.reads = /* @__PURE__ */ new Set();
1428
+ get5.failure = noFailure;
1268
1429
  return get5;
1269
1430
  };
1270
1431
  var WriteContextImpl = class {
@@ -1299,27 +1460,45 @@ var batchState = {
1299
1460
  notify: /* @__PURE__ */ new Set()
1300
1461
  };
1301
1462
  function batch(f) {
1463
+ const previousPhase = batchState.phase;
1302
1464
  batchState.phase = BatchPhase.collect;
1303
1465
  batchState.depth++;
1466
+ let failure2 = noFailure;
1304
1467
  try {
1305
1468
  f();
1306
- if (batchState.depth === 1) {
1307
- for (let i = 0; i < batchState.stale.length; i++) {
1308
- batchRebuildNode(batchState.stale[i]);
1469
+ } catch (error2) {
1470
+ failure2 = error2;
1471
+ }
1472
+ if (batchState.depth === 1) {
1473
+ const {
1474
+ notify,
1475
+ stale
1476
+ } = batchState;
1477
+ let i = 0;
1478
+ do {
1479
+ batchState.phase = BatchPhase.collect;
1480
+ for (; i < stale.length; i++) {
1481
+ try {
1482
+ batchRebuildNode(stale[i]);
1483
+ } catch (error2) {
1484
+ if (failure2 === noFailure) failure2 = error2;
1485
+ }
1309
1486
  }
1310
1487
  batchState.phase = BatchPhase.commit;
1311
- for (const node of batchState.notify) {
1312
- node.notify();
1488
+ for (const node of notify) {
1489
+ try {
1490
+ node.notify();
1491
+ } catch (error2) {
1492
+ if (failure2 === noFailure) failure2 = error2;
1493
+ }
1313
1494
  }
1314
- batchState.notify.clear();
1315
- }
1316
- } finally {
1317
- batchState.depth--;
1318
- if (batchState.depth === 0) {
1319
- batchState.phase = BatchPhase.disabled;
1320
- batchState.stale = [];
1321
- }
1495
+ } while (i < stale.length);
1496
+ batchState.stale = [];
1497
+ notify.clear();
1322
1498
  }
1499
+ batchState.depth--;
1500
+ batchState.phase = previousPhase;
1501
+ if (failure2 !== noFailure) throw failure2;
1323
1502
  }
1324
1503
  function batchRebuildNode(node) {
1325
1504
  if (node.state === NodeState.valid) {
@@ -1330,28 +1509,21 @@ function batchRebuildNode(node) {
1330
1509
  node.state = NodeState.stale;
1331
1510
  node.disposeLifetime();
1332
1511
  }
1333
- for (const parent of node.parents) {
1334
- if (parent.state !== NodeState.valid) {
1335
- batchRebuildNode(parent);
1336
- }
1337
- }
1338
- if (node.state !== NodeState.valid) {
1339
- node.value();
1340
- }
1512
+ node.value();
1341
1513
  }
1342
1514
 
1343
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/Atom.js
1515
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/Atom.js
1344
1516
  var Atom_exports = {};
1345
1517
  __export(Atom_exports, {
1346
1518
  Interrupt: () => Interrupt,
1347
1519
  Reset: () => Reset,
1348
1520
  SerializableTypeId: () => SerializableTypeId2,
1349
1521
  ServerValueTypeId: () => ServerValueTypeId,
1350
- TypeId: () => TypeId3,
1522
+ TypeId: () => TypeId4,
1351
1523
  WritableTypeId: () => WritableTypeId,
1352
1524
  autoDispose: () => autoDispose,
1353
1525
  batch: () => batch2,
1354
- context: () => context,
1526
+ context: () => context2,
1355
1527
  debounce: () => debounce,
1356
1528
  family: () => family,
1357
1529
  fn: () => fn,
@@ -1365,7 +1537,7 @@ __export(Atom_exports, {
1365
1537
  isWritable: () => isWritable,
1366
1538
  keepAlive: () => keepAlive,
1367
1539
  kvs: () => kvs,
1368
- make: () => make2,
1540
+ make: () => make4,
1369
1541
  makeRefreshOnSignal: () => makeRefreshOnSignal,
1370
1542
  map: () => map5,
1371
1543
  mapResult: () => mapResult,
@@ -1400,12 +1572,155 @@ __export(Atom_exports, {
1400
1572
  writable: () => writable
1401
1573
  });
1402
1574
 
1403
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/persistence/KeyValueStore.js
1575
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/Reactivity.js
1576
+ var TypeId3 = "~effect/reactivity/Reactivity";
1577
+ var Reactivity = /* @__PURE__ */ Service("effect/reactivity/Reactivity");
1578
+ var make3 = /* @__PURE__ */ sync(() => {
1579
+ const handlers = /* @__PURE__ */ new Map();
1580
+ const runHandlers = (hashes) => {
1581
+ const ran = /* @__PURE__ */ new Set();
1582
+ for (const hash2 of hashes) {
1583
+ handlers.get(hash2)?.forEach((run) => {
1584
+ if (ran.has(run)) return;
1585
+ ran.add(run);
1586
+ run();
1587
+ });
1588
+ }
1589
+ };
1590
+ const invalidateUnsafe = (keys) => {
1591
+ const hashes = /* @__PURE__ */ new Set();
1592
+ keysToHashes(keys, (hash2) => hashes.add(hash2));
1593
+ runHandlers(hashes);
1594
+ };
1595
+ const invalidate2 = (keys) => contextWith((services) => {
1596
+ const pending = getOrUndefined2(services, PendingInvalidation);
1597
+ if (pending) {
1598
+ keysToHashes(keys, (hash2) => {
1599
+ pending.add(hash2);
1600
+ });
1601
+ } else {
1602
+ invalidateUnsafe(keys);
1603
+ }
1604
+ return void_2;
1605
+ });
1606
+ const mutation2 = (keys, effect3) => tap(effect3, invalidate2(keys));
1607
+ const registerUnsafe = (keys, handler) => {
1608
+ const resolvedKeys = [];
1609
+ keysToHashes(keys, (hash2) => {
1610
+ resolvedKeys.push(hash2);
1611
+ let set4 = handlers.get(hash2);
1612
+ if (set4 === void 0) {
1613
+ set4 = /* @__PURE__ */ new Set();
1614
+ handlers.set(hash2, set4);
1615
+ }
1616
+ set4.add(handler);
1617
+ });
1618
+ return () => {
1619
+ for (let i = 0; i < resolvedKeys.length; i++) {
1620
+ const set4 = handlers.get(resolvedKeys[i]);
1621
+ if (set4 === void 0) continue;
1622
+ set4.delete(handler);
1623
+ if (set4.size === 0) {
1624
+ handlers.delete(resolvedKeys[i]);
1625
+ }
1626
+ }
1627
+ };
1628
+ };
1629
+ const query = (keys, effect3) => gen(function* () {
1630
+ const services = yield* context();
1631
+ const scope2 = get(services, Scope);
1632
+ const results = yield* make();
1633
+ const runFork = flow(runForkWith(services), runIn(scope2));
1634
+ let running = false;
1635
+ let pending = false;
1636
+ let stopped = false;
1637
+ const handleExit = (exit) => {
1638
+ if (exit._tag === "Failure") {
1639
+ stopped = true;
1640
+ pending = false;
1641
+ running = false;
1642
+ cancel();
1643
+ failCauseUnsafe(results, exit.cause);
1644
+ return;
1645
+ } else {
1646
+ offerUnsafe(results, exit.value);
1647
+ }
1648
+ if (pending) {
1649
+ pending = false;
1650
+ runFork(effect3).addObserver(handleExit);
1651
+ } else {
1652
+ running = false;
1653
+ }
1654
+ };
1655
+ function run() {
1656
+ if (stopped) return;
1657
+ if (running) {
1658
+ pending = true;
1659
+ return;
1660
+ }
1661
+ running = true;
1662
+ runFork(effect3).addObserver(handleExit);
1663
+ }
1664
+ const cancel = registerUnsafe(keys, run);
1665
+ yield* addFinalizer(scope2, sync(cancel));
1666
+ run();
1667
+ return results;
1668
+ });
1669
+ const stream2 = (tables, effect3) => query(tables, effect3).pipe(map2(fromQueue), unwrap);
1670
+ const withBatch = (effect3) => suspend(() => {
1671
+ const pending = /* @__PURE__ */ new Set();
1672
+ return effect3.pipe(provideService(PendingInvalidation, pending), onExit((_) => sync(() => runHandlers(pending))));
1673
+ });
1674
+ return Reactivity.of({
1675
+ [TypeId3]: TypeId3,
1676
+ mutation: mutation2,
1677
+ query,
1678
+ stream: stream2,
1679
+ invalidateUnsafe,
1680
+ invalidate: invalidate2,
1681
+ registerUnsafe,
1682
+ withBatch
1683
+ });
1684
+ });
1685
+ var PendingInvalidation = class extends (/* @__PURE__ */ Service()("effect/reactivity/Reactivity/PendingInvalidation")) {
1686
+ };
1687
+ var mutation = /* @__PURE__ */ dual(2, (effect3, keys) => Reactivity.use((_) => _.mutation(keys, effect3)));
1688
+ var invalidate = (keys) => Reactivity.use((r) => r.invalidate(keys));
1689
+ var layer2 = /* @__PURE__ */ effect(Reactivity)(make3);
1690
+ function stringOrHash(u) {
1691
+ switch (typeof u) {
1692
+ case "string":
1693
+ case "number":
1694
+ case "bigint":
1695
+ case "boolean":
1696
+ return String(u);
1697
+ default:
1698
+ return hash(u);
1699
+ }
1700
+ }
1701
+ var keysToHashes = (keys, f) => {
1702
+ if (Array.isArray(keys)) {
1703
+ for (let i = 0; i < keys.length; i++) {
1704
+ f(stringOrHash(keys[i]));
1705
+ }
1706
+ return;
1707
+ }
1708
+ for (const key in keys) {
1709
+ f(key);
1710
+ const ids = keys[key];
1711
+ for (let i = 0; i < ids.length; i++) {
1712
+ f(`${key}:${stringOrHash(ids[i])}`);
1713
+ }
1714
+ }
1715
+ };
1716
+
1717
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/persistence/KeyValueStore.js
1404
1718
  var ErrorTypeId = "~effect/persistence/KeyValueStore/KeyValueStoreError";
1405
1719
  var KeyValueStoreError = class extends (/* @__PURE__ */ TaggedError("KeyValueStoreError")) {
1406
1720
  /**
1407
1721
  * Marks this value as a key-value store error for runtime guards.
1408
1722
  *
1723
+ * @stability unstable
1409
1724
  * @since 4.0.0
1410
1725
  */
1411
1726
  [ErrorTypeId] = ErrorTypeId;
@@ -1437,14 +1752,15 @@ var toSchemaStore = (self, schema) => {
1437
1752
  remove: self.remove,
1438
1753
  clear: self.clear,
1439
1754
  size: self.size,
1755
+ keys: self.keys,
1440
1756
  has: self.has,
1441
1757
  isEmpty: self.isEmpty
1442
1758
  };
1443
1759
  };
1444
1760
 
1445
- // ../../node_modules/.bun/effect@https+++pkg.pr.new+Effect-TS+effect+effect@c7d1ffff31a3e2ae0b0b+a654a55b752bdb24/node_modules/effect/dist/unstable/reactivity/Atom.js
1446
- var TypeId3 = "~effect/reactivity/Atom";
1447
- var isAtom = (u) => hasProperty(u, TypeId3);
1761
+ // ../../node_modules/.bun/effect@4.1.4/node_modules/effect/dist/reactivity/Atom.js
1762
+ var TypeId4 = "~effect/reactivity/Atom";
1763
+ var isAtom = (u) => hasProperty(u, TypeId4);
1448
1764
  var WritableTypeId = "~effect/reactivity/Atom/Writable";
1449
1765
  var setIdleTTL = /* @__PURE__ */ dual(2, (self, durationInput) => {
1450
1766
  const duration = fromInputUnsafe(durationInput);
@@ -1457,7 +1773,7 @@ var setIdleTTL = /* @__PURE__ */ dual(2, (self, durationInput) => {
1457
1773
  });
1458
1774
  var removeTtl = /* @__PURE__ */ setIdleTTL(0);
1459
1775
  var AtomProto = {
1460
- [TypeId3]: TypeId3,
1776
+ [TypeId4]: TypeId4,
1461
1777
  equals: Object.is,
1462
1778
  ...PipeInspectableProto,
1463
1779
  toJSON() {
@@ -1465,7 +1781,7 @@ var AtomProto = {
1465
1781
  _id: "Atom",
1466
1782
  keepAlive: this.keepAlive,
1467
1783
  lazy: this.lazy,
1468
- label: this.label
1784
+ label: this.label && [this.label[0], this.label[1]]
1469
1785
  };
1470
1786
  }
1471
1787
  };
@@ -1518,7 +1834,7 @@ var RuntimeProto = {
1518
1834
  var makeFnRuntime = (self, arg, options) => {
1519
1835
  const [read, write, argAtom] = makeResultFn(options?.reactivityKeys ? (a, get5) => {
1520
1836
  const effect3 = arg(a, get5);
1521
- return isEffect(effect3) ? mutation(effect3, options.reactivityKeys) : ensuring(effect3, invalidate(options.reactivityKeys));
1837
+ return isEffect(effect3) ? mutation(effect3, options.reactivityKeys) : onEnd(effect3, invalidate(options.reactivityKeys));
1522
1838
  } : arg, options);
1523
1839
  return writable((get5) => {
1524
1840
  get5.get(argAtom);
@@ -1555,9 +1871,9 @@ var writable = (read, write, refresh2) => {
1555
1871
  function constSetSelf(ctx, value2) {
1556
1872
  ctx.setSelf(value2);
1557
1873
  }
1558
- var make2 = (arg, options) => {
1874
+ var make4 = (arg, options) => {
1559
1875
  const readOrAtom = makeRead(arg, options);
1560
- if (TypeId3 in readOrAtom) {
1876
+ if (TypeId4 in readOrAtom) {
1561
1877
  return readOrAtom;
1562
1878
  }
1563
1879
  return readable(readOrAtom);
@@ -1602,18 +1918,23 @@ var effect2 = (get5, effect3, options, services) => {
1602
1918
  const initialValue2 = options?.initialValue !== void 0 ? success(options.initialValue) : initial();
1603
1919
  return makeEffect(get5, effect3, initialValue2, services, options?.uninterruptible);
1604
1920
  };
1605
- function makeEffect(ctx, effect3, initialValue2, services = empty2(), uninterruptible = false) {
1921
+ function makeEffect(ctx, effect3, initialValue2, services = empty(), uninterruptible = false) {
1606
1922
  const previous = ctx.self();
1923
+ if (previous._tag === "Some" && consumeSkipInitialRun(ctx)) {
1924
+ return previous.value;
1925
+ }
1926
+ const getServices = typeof services === "function" ? services : constant(services);
1607
1927
  const scope2 = makeUnsafe();
1608
1928
  ctx.addFinalizer(() => {
1609
- runForkWith(services)(close(scope2, void_));
1929
+ runForkWith(getServices())(closeScope(scope2));
1610
1930
  });
1611
1931
  let syncResult;
1612
1932
  let isAsync = false;
1613
- const cancel = runCallbackSync(services.pipe(add(Scope, scope2), add(AtomRegistry, ctx.registry), add(Scheduler, ctx.registry.scheduler)), effect3, function(exit) {
1614
- syncResult = fromExitWithPrevious(exit, previous);
1933
+ const cancel = runCallbackSync(getServices().pipe(add(Scope, scope2), add(AtomRegistry, ctx.registry), add(Scheduler, ctx.registry.scheduler)), effect3, function(exit) {
1615
1934
  if (isAsync) {
1616
- ctx.setSelf(syncResult);
1935
+ ctx.setSelf(fromExitWithPrevious(exit, ctx.self()));
1936
+ } else {
1937
+ syncResult = fromExitWithPrevious(exit, previous);
1617
1938
  }
1618
1939
  }, uninterruptible);
1619
1940
  isAsync = true;
@@ -1627,9 +1948,13 @@ function makeEffect(ctx, effect3, initialValue2, services = empty2(), uninterrup
1627
1948
  }
1628
1949
  return waiting(initialValue2);
1629
1950
  }
1630
- function runCallbackSync(services, effect3, onExit, uninterruptible = false) {
1951
+ var closeScope = (scope2) => catchCause(close(scope2, void_), (cause2) => hasInterruptsOnly(cause2) ? void_2 : ignoreCause(failCause2(cause2), {
1952
+ log: "Unhandled",
1953
+ message: "Unhandled error in atom finalizer"
1954
+ }));
1955
+ function runCallbackSync(services, effect3, onExit2, uninterruptible = false) {
1631
1956
  if (isExit(effect3)) {
1632
- onExit(effect3);
1957
+ onExit2(effect3);
1633
1958
  return void 0;
1634
1959
  }
1635
1960
  const runFork = runForkWith(services);
@@ -1637,10 +1962,10 @@ function runCallbackSync(services, effect3, onExit, uninterruptible = false) {
1637
1962
  fiber.currentDispatcher?.flush();
1638
1963
  const result = fiber.pollUnsafe();
1639
1964
  if (result) {
1640
- onExit(result);
1965
+ onExit2(result);
1641
1966
  return void 0;
1642
1967
  }
1643
- const remove2 = fiber.addObserver(onExit);
1968
+ const remove2 = fiber.addObserver(onExit2);
1644
1969
  function cancel() {
1645
1970
  remove2();
1646
1971
  if (!uninterruptible) {
@@ -1649,32 +1974,34 @@ function runCallbackSync(services, effect3, onExit, uninterruptible = false) {
1649
1974
  }
1650
1975
  return cancel;
1651
1976
  }
1652
- function context(options) {
1653
- const memoMap = options?.memoMap ?? removeTtl(make2(() => makeMemoMapUnsafe()));
1977
+ function context2(options) {
1978
+ const memoMap = options?.memoMap ?? removeTtl(make4(() => makeMemoMapUnsafe()));
1654
1979
  const resolveMemoMap = (get5) => isAtom(memoMap) ? get5(memoMap) : memoMap;
1655
- let globalLayer = layer;
1980
+ let globalLayer = layer2;
1656
1981
  function factory(create) {
1657
1982
  const self = Object.create(RuntimeProto);
1658
1983
  self.keepAlive = false;
1659
1984
  self.lazy = true;
1660
1985
  self.refresh = void 0;
1661
1986
  self.factory = factory;
1662
- const layerAtom = keepAlive(typeof create === "function" ? readable((get5) => provideMerge(create(get5), globalLayer)) : readable(() => provideMerge(create, globalLayer)));
1987
+ const layerAtom = keepAlive(typeof create === "function" ? readable(create) : readable(() => create));
1663
1988
  self.layer = layerAtom;
1664
1989
  self.read = function read(get5) {
1665
- const layer3 = get5(layerAtom);
1666
- const build = flatMap2(scope, (scope2) => buildWithMemoMap(layer3, resolveMemoMap(get5), scope2));
1667
- return effect2(get5, build, {
1668
- uninterruptible: true
1669
- });
1990
+ const layer3 = provideMerge(get5(layerAtom), globalLayer);
1991
+ let services = empty();
1992
+ const build = flatMap2(scope, (scope2) => map2(buildWithMemoMap(layer3, resolveMemoMap(get5), scope2), (context3) => {
1993
+ services = context3;
1994
+ return context3;
1995
+ }));
1996
+ return makeEffect(get5, build, initial(), () => services, true);
1670
1997
  };
1671
1998
  return self;
1672
1999
  }
1673
2000
  factory.memoMap = memoMap;
1674
2001
  factory.addGlobalLayer = (layer3) => {
1675
- globalLayer = provideMerge(globalLayer, provide(layer3, layer));
2002
+ globalLayer = provideMerge(globalLayer, provide(layer3, layer2));
1676
2003
  };
1677
- const reactivityAtom = removeTtl(make2((get5) => contextWith((services) => buildWithMemoMap(layer, resolveMemoMap(get5), get(services, Scope))).pipe(map2(get(Reactivity)))));
2004
+ const reactivityAtom = removeTtl(make4((get5) => contextWith((services) => buildWithMemoMap(layer2, resolveMemoMap(get5), get(services, Scope))).pipe(map2(get(Reactivity)))));
1678
2005
  factory.withReactivity = (keys) => (atom) => transform2(atom, (get5) => {
1679
2006
  const reactivity = getOrThrow(get5(reactivityAtom));
1680
2007
  get5.addFinalizer(reactivity.registerUnsafe(keys, () => {
@@ -1687,14 +2014,17 @@ function context(options) {
1687
2014
  });
1688
2015
  return factory;
1689
2016
  }
1690
- var runtime = /* @__PURE__ */ context();
2017
+ var runtime = /* @__PURE__ */ context2();
1691
2018
  var withReactivity = runtime.withReactivity;
1692
2019
  var stream = (get5, stream2, options, services) => {
1693
2020
  const initialValue2 = options?.initialValue !== void 0 ? success(options.initialValue) : initial();
1694
2021
  return makeStream(get5, stream2, initialValue2, services);
1695
2022
  };
1696
- function makeStream(ctx, stream2, initialValue2, services = empty2()) {
2023
+ function makeStream(ctx, stream2, initialValue2, services = empty()) {
1697
2024
  const previous = ctx.self();
2025
+ if (previous._tag === "Some" && consumeSkipInitialRun(ctx)) {
2026
+ return previous.value;
2027
+ }
1698
2028
  services = add(services, AtomRegistry, ctx.registry);
1699
2029
  const run = scopedWith((scope2) => flatMap2(toPullScoped(stream2.channel, scope2), (pull2) => whileLoop({
1700
2030
  while: constTrue,
@@ -1732,7 +2062,7 @@ var subscriptionRef = (ref) => makeSubRef(readable((get5) => {
1732
2062
  const value2 = typeof ref === "function" ? ref(get5) : ref;
1733
2063
  return isSubscriptionRef(value2) ? value2 : makeEffect(get5, value2, initial(true));
1734
2064
  }), readSubscriptionRef);
1735
- var readSubscriptionRef = (get5, sub, services = empty2()) => {
2065
+ var readSubscriptionRef = (get5, sub, services = empty()) => {
1736
2066
  if (isSubscriptionRef(sub)) {
1737
2067
  get5.addFinalizer(changes2(sub).pipe(runForEachArray((arr) => {
1738
2068
  for (let i = 0; i < arr.length; i++) {
@@ -1828,8 +2158,9 @@ function makeResultFn(f, options) {
1828
2158
  startImmediately: true
1829
2159
  }), (fiber) => {
1830
2160
  fibers.add(fiber);
2161
+ const runningFibers = Array.from(fibers);
1831
2162
  fiber.addObserver(() => fibers.delete(fiber));
1832
- return map2(joinAll(fibers), (arr) => arr[0]);
2163
+ return map2(joinAll(runningFibers), (arr) => arr[0]);
1833
2164
  });
1834
2165
  }
1835
2166
  return makeEffect(get5, value2, initialValue2, services, false);
@@ -1860,7 +2191,7 @@ var pull = (create, options) => {
1860
2191
  var makeStreamPullEffect = (get5, pullSignal, create, options) => flatMap2(toPull(typeof create === "function" ? create(get5) : create), (pullChunk) => {
1861
2192
  const fiber = getCurrent();
1862
2193
  const services = fiber.context;
1863
- let acc = empty();
2194
+ let acc = empty2();
1864
2195
  const pull2 = matchCauseEffect(pullChunk, {
1865
2196
  onFailure(cause2) {
1866
2197
  if (isDoneCause(cause2)) {
@@ -1923,7 +2254,10 @@ var family = typeof WeakRef === "undefined" || typeof FinalizationRegistry === "
1923
2254
  } : (f) => {
1924
2255
  const atoms = empty3();
1925
2256
  const registry = new FinalizationRegistry((arg) => {
1926
- remove(atoms, arg);
2257
+ const entry = get2(atoms, arg);
2258
+ if (entry._tag === "Some" && entry.value.deref() === void 0) {
2259
+ remove(atoms, arg);
2260
+ }
1927
2261
  });
1928
2262
  return function(arg) {
1929
2263
  const atomEntry = get2(atoms, arg).pipe(flatMapNullishOr((ref) => ref.deref()));
@@ -1970,9 +2304,28 @@ var withEquality = /* @__PURE__ */ dual(2, (self, equals2) => Object.assign(Obje
1970
2304
  }));
1971
2305
  var withLabel = /* @__PURE__ */ dual(2, (self, name) => Object.assign(Object.create(Object.getPrototypeOf(self)), {
1972
2306
  ...self,
1973
- label: [name, getStackTraceLimit() === 0 ? "" : new Error().stack?.split("\n")[5] ?? ""]
2307
+ label: makeLabel(name, getStackTraceLimit() === 0 ? void 0 : new Error())
1974
2308
  }));
1975
- var initialValue = /* @__PURE__ */ dual(2, (self, initialValue2) => [self, initialValue2]);
2309
+ function makeLabel(name, error2) {
2310
+ const label = [name, ""];
2311
+ if (error2 === void 0) {
2312
+ return label;
2313
+ }
2314
+ let location = "";
2315
+ Object.defineProperty(label, 1, {
2316
+ configurable: true,
2317
+ enumerable: true,
2318
+ get: () => {
2319
+ if (error2 !== void 0) {
2320
+ location = error2.stack?.split("\n")[5] ?? "";
2321
+ error2 = void 0;
2322
+ }
2323
+ return location;
2324
+ }
2325
+ });
2326
+ return label;
2327
+ }
2328
+ var initialValue = /* @__PURE__ */ dual((args) => args.length >= 2, (self, initialValue2, options) => options === void 0 ? [self, initialValue2] : [self, initialValue2, options]);
1976
2329
  var transform2 = /* @__PURE__ */ dual((args) => isAtom(args[0]), (self, f, options) => {
1977
2330
  const atom = removeTtl(isWritable(self) ? writable((get5) => f(get5, self), function(ctx, value2) {
1978
2331
  ctx.set(self, value2);
@@ -2049,7 +2402,15 @@ var swr = /* @__PURE__ */ dual(2, (self, options) => {
2049
2402
  return current;
2050
2403
  }
2051
2404
  if (shouldRevalidateSWR(current, staleTime)) {
2052
- get5.refresh(self);
2405
+ let active = true;
2406
+ get5.addFinalizer(() => {
2407
+ active = false;
2408
+ });
2409
+ get5.registry.schedulerAsync.makeDispatcher().scheduleTask(() => {
2410
+ if (active && shouldRevalidateSWR(get5.once(self), staleTime)) {
2411
+ get5.refresh(self);
2412
+ }
2413
+ }, 0);
2053
2414
  }
2054
2415
  return current;
2055
2416
  }, {
@@ -2187,6 +2548,9 @@ var optimisticFn = /* @__PURE__ */ dual(2, (self, options) => {
2187
2548
  });
2188
2549
  var batch2 = batch;
2189
2550
  var windowFocusSignal = /* @__PURE__ */ readable((get5) => {
2551
+ if (typeof window === "undefined") {
2552
+ return 0;
2553
+ }
2190
2554
  let count = 0;
2191
2555
  function update2() {
2192
2556
  if (document.visibilityState === "visible") {
@@ -2301,7 +2665,8 @@ function updateSearchParams() {
2301
2665
  }
2302
2666
  }
2303
2667
  searchParamState.updates.clear();
2304
- const newUrl = `${window.location.pathname}?${searchParams.toString()}`;
2668
+ const search = searchParams.toString();
2669
+ const newUrl = `${window.location.pathname}${search.length > 0 ? `?${search}` : ""}${window.location.hash}`;
2305
2670
  window.history.pushState({}, "", newUrl);
2306
2671
  searchParamState.updating = false;
2307
2672
  }
@@ -2320,11 +2685,12 @@ var serializable = /* @__PURE__ */ dual(2, (self, options) => {
2320
2685
  const codecJson = toCodecJson(options.schema);
2321
2686
  return Object.assign(Object.create(Object.getPrototypeOf(self)), {
2322
2687
  ...self,
2323
- label: self.label ?? [options.key, getStackTraceLimit() === 0 ? "" : new Error().stack?.split("\n")[5] ?? ""],
2688
+ label: self.label ?? makeLabel(options.key, getStackTraceLimit() === 0 ? void 0 : new Error()),
2324
2689
  [SerializableTypeId2]: {
2325
2690
  key: options.key,
2326
2691
  encode: encodeSync(codecJson),
2327
- decode: decodeSync(codecJson)
2692
+ decode: decodeSync(codecJson),
2693
+ skipInitialRun: options.skipInitialRun
2328
2694
  }
2329
2695
  });
2330
2696
  });