@livestore/utils 0.4.0-dev.9 → 0.5.0-dev.0

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 (316) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/NoopTracer.d.ts +7 -8
  3. package/dist/NoopTracer.d.ts.map +1 -1
  4. package/dist/NoopTracer.js +13 -15
  5. package/dist/NoopTracer.js.map +1 -1
  6. package/dist/NoopTracer.test.d.ts +2 -0
  7. package/dist/NoopTracer.test.d.ts.map +1 -0
  8. package/dist/NoopTracer.test.js +17 -0
  9. package/dist/NoopTracer.test.js.map +1 -0
  10. package/dist/binary.js +1 -1
  11. package/dist/binary.js.map +1 -1
  12. package/dist/browser/Opfs/Opfs.d.ts +201 -0
  13. package/dist/browser/Opfs/Opfs.d.ts.map +1 -0
  14. package/dist/browser/Opfs/Opfs.js +170 -0
  15. package/dist/browser/Opfs/Opfs.js.map +1 -0
  16. package/dist/browser/Opfs/debug-utils.d.ts +20 -0
  17. package/dist/browser/Opfs/debug-utils.d.ts.map +1 -0
  18. package/dist/browser/Opfs/debug-utils.js +95 -0
  19. package/dist/browser/Opfs/debug-utils.js.map +1 -0
  20. package/dist/browser/Opfs/mod.d.ts +4 -0
  21. package/dist/browser/Opfs/mod.d.ts.map +1 -0
  22. package/dist/browser/Opfs/mod.js +4 -0
  23. package/dist/browser/Opfs/mod.js.map +1 -0
  24. package/dist/browser/Opfs/utils.d.ts +71 -0
  25. package/dist/browser/Opfs/utils.d.ts.map +1 -0
  26. package/dist/browser/Opfs/utils.js +227 -0
  27. package/dist/browser/Opfs/utils.js.map +1 -0
  28. package/dist/browser/QuotaExceededError.d.ts +60 -0
  29. package/dist/browser/QuotaExceededError.d.ts.map +1 -0
  30. package/dist/browser/QuotaExceededError.js +2 -0
  31. package/dist/browser/QuotaExceededError.js.map +1 -0
  32. package/dist/browser/WebChannelBrowser.d.ts +22 -0
  33. package/dist/browser/WebChannelBrowser.d.ts.map +1 -0
  34. package/dist/browser/WebChannelBrowser.js +87 -0
  35. package/dist/browser/WebChannelBrowser.js.map +1 -0
  36. package/dist/browser/WebError.d.ts +389 -0
  37. package/dist/browser/WebError.d.ts.map +1 -0
  38. package/dist/browser/WebError.js +423 -0
  39. package/dist/browser/WebError.js.map +1 -0
  40. package/dist/browser/WebError.test.d.ts +2 -0
  41. package/dist/browser/WebError.test.d.ts.map +1 -0
  42. package/dist/browser/WebError.test.js +46 -0
  43. package/dist/browser/WebError.test.js.map +1 -0
  44. package/dist/browser/WebLock.d.ts.map +1 -0
  45. package/dist/{effect → browser}/WebLock.js +21 -21
  46. package/dist/browser/WebLock.js.map +1 -0
  47. package/dist/{browser.d.ts → browser/detect.d.ts} +1 -1
  48. package/dist/browser/detect.d.ts.map +1 -0
  49. package/dist/{browser.js → browser/detect.js} +7 -7
  50. package/dist/browser/detect.js.map +1 -0
  51. package/dist/browser/mod.d.ts +8 -0
  52. package/dist/browser/mod.d.ts.map +1 -0
  53. package/dist/browser/mod.js +8 -0
  54. package/dist/browser/mod.js.map +1 -0
  55. package/dist/cuid/cuid.browser.js +1 -1
  56. package/dist/cuid/cuid.browser.js.map +1 -1
  57. package/dist/cuid/cuid.node.js +1 -1
  58. package/dist/cuid/cuid.node.js.map +1 -1
  59. package/dist/effect/Debug.d.ts +38 -0
  60. package/dist/effect/Debug.d.ts.map +1 -0
  61. package/dist/effect/Debug.js +350 -0
  62. package/dist/effect/Debug.js.map +1 -0
  63. package/dist/effect/Effect.d.ts +91 -22
  64. package/dist/effect/Effect.d.ts.map +1 -1
  65. package/dist/effect/Effect.js +126 -38
  66. package/dist/effect/Effect.js.map +1 -1
  67. package/dist/effect/Effect.test.d.ts +2 -0
  68. package/dist/effect/Effect.test.d.ts.map +1 -0
  69. package/dist/effect/Effect.test.js +72 -0
  70. package/dist/effect/Effect.test.js.map +1 -0
  71. package/dist/effect/Error.d.ts +4 -6
  72. package/dist/effect/Error.d.ts.map +1 -1
  73. package/dist/effect/Error.js +1 -1
  74. package/dist/effect/Error.js.map +1 -1
  75. package/dist/effect/Logger.d.ts +0 -6
  76. package/dist/effect/Logger.d.ts.map +1 -1
  77. package/dist/effect/Logger.js +0 -32
  78. package/dist/effect/Logger.js.map +1 -1
  79. package/dist/effect/OtelTracer.d.ts +1 -1
  80. package/dist/effect/OtelTracer.d.ts.map +1 -1
  81. package/dist/effect/OtelTracer.js +2 -3
  82. package/dist/effect/OtelTracer.js.map +1 -1
  83. package/dist/effect/RpcClient.d.ts +7 -7
  84. package/dist/effect/RpcClient.d.ts.map +1 -1
  85. package/dist/effect/RpcClient.js +74 -54
  86. package/dist/effect/RpcClient.js.map +1 -1
  87. package/dist/effect/Schedule.d.ts +1 -1
  88. package/dist/effect/Schedule.d.ts.map +1 -1
  89. package/dist/effect/Schedule.js +2 -2
  90. package/dist/effect/Schedule.js.map +1 -1
  91. package/dist/effect/Schema/debug-diff.d.ts +1 -1
  92. package/dist/effect/Schema/debug-diff.d.ts.map +1 -1
  93. package/dist/effect/Schema/debug-diff.js +9 -10
  94. package/dist/effect/Schema/debug-diff.js.map +1 -1
  95. package/dist/effect/Schema/debug-diff.test.js +7 -4
  96. package/dist/effect/Schema/debug-diff.test.js.map +1 -1
  97. package/dist/effect/Schema/index.d.ts +28 -18
  98. package/dist/effect/Schema/index.d.ts.map +1 -1
  99. package/dist/effect/Schema/index.js +55 -28
  100. package/dist/effect/Schema/index.js.map +1 -1
  101. package/dist/effect/Stream.d.ts +13 -5
  102. package/dist/effect/Stream.d.ts.map +1 -1
  103. package/dist/effect/Stream.js +19 -12
  104. package/dist/effect/Stream.js.map +1 -1
  105. package/dist/effect/Stream.test.js +12 -12
  106. package/dist/effect/Stream.test.js.map +1 -1
  107. package/dist/effect/Subscribable.d.ts +9 -3
  108. package/dist/effect/Subscribable.d.ts.map +1 -1
  109. package/dist/effect/Subscribable.js +20 -35
  110. package/dist/effect/Subscribable.js.map +1 -1
  111. package/dist/effect/SubscriptionRef.d.ts +5 -6
  112. package/dist/effect/SubscriptionRef.d.ts.map +1 -1
  113. package/dist/effect/SubscriptionRef.js +2 -3
  114. package/dist/effect/SubscriptionRef.js.map +1 -1
  115. package/dist/effect/TaskTracing.d.ts +1 -1
  116. package/dist/effect/TaskTracing.d.ts.map +1 -1
  117. package/dist/effect/TaskTracing.js +12 -16
  118. package/dist/effect/TaskTracing.js.map +1 -1
  119. package/dist/effect/WebChannel/WebChannel.d.ts +11 -30
  120. package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
  121. package/dist/effect/WebChannel/WebChannel.js +70 -125
  122. package/dist/effect/WebChannel/WebChannel.js.map +1 -1
  123. package/dist/effect/WebChannel/WebChannel.test.js +16 -16
  124. package/dist/effect/WebChannel/WebChannel.test.js.map +1 -1
  125. package/dist/effect/WebChannel/broadcastChannelWithAck.d.ts.map +1 -1
  126. package/dist/effect/WebChannel/broadcastChannelWithAck.js +20 -13
  127. package/dist/effect/WebChannel/broadcastChannelWithAck.js.map +1 -1
  128. package/dist/effect/WebChannel/common.d.ts +17 -18
  129. package/dist/effect/WebChannel/common.d.ts.map +1 -1
  130. package/dist/effect/WebChannel/common.js +7 -7
  131. package/dist/effect/WebChannel/common.js.map +1 -1
  132. package/dist/effect/WebSocket.d.ts +4 -6
  133. package/dist/effect/WebSocket.d.ts.map +1 -1
  134. package/dist/effect/WebSocket.js +17 -17
  135. package/dist/effect/WebSocket.js.map +1 -1
  136. package/dist/effect/WebSocket.test.js +2 -2
  137. package/dist/effect/WebSocket.test.js.map +1 -1
  138. package/dist/effect/mod.browser-build.test.d.ts +2 -0
  139. package/dist/effect/mod.browser-build.test.d.ts.map +1 -0
  140. package/dist/effect/mod.browser-build.test.js +18 -0
  141. package/dist/effect/mod.browser-build.test.js.map +1 -0
  142. package/dist/effect/mod.d.ts +30 -0
  143. package/dist/effect/mod.d.ts.map +1 -0
  144. package/dist/effect/mod.js +30 -0
  145. package/dist/effect/mod.js.map +1 -0
  146. package/dist/effect/spanEvent.d.ts +12 -0
  147. package/dist/effect/spanEvent.d.ts.map +1 -0
  148. package/dist/effect/spanEvent.js +12 -0
  149. package/dist/effect/spanEvent.js.map +1 -0
  150. package/dist/effect/spanEvent.test.d.ts +2 -0
  151. package/dist/effect/spanEvent.test.d.ts.map +1 -0
  152. package/dist/effect/spanEvent.test.js +79 -0
  153. package/dist/effect/spanEvent.test.js.map +1 -0
  154. package/dist/env.d.ts.map +1 -1
  155. package/dist/env.js +1 -1
  156. package/dist/env.js.map +1 -1
  157. package/dist/fast-deep-equal.d.ts.map +1 -1
  158. package/dist/fast-deep-equal.js +9 -10
  159. package/dist/fast-deep-equal.js.map +1 -1
  160. package/dist/global.d.ts +3 -0
  161. package/dist/global.d.ts.map +1 -1
  162. package/dist/global.js.map +1 -1
  163. package/dist/misc.d.ts +9 -1
  164. package/dist/misc.d.ts.map +1 -1
  165. package/dist/misc.js +12 -4
  166. package/dist/misc.js.map +1 -1
  167. package/dist/mod.d.ts +177 -20
  168. package/dist/mod.d.ts.map +1 -1
  169. package/dist/mod.js +159 -22
  170. package/dist/mod.js.map +1 -1
  171. package/dist/node/mod.d.ts +45 -6
  172. package/dist/node/mod.d.ts.map +1 -1
  173. package/dist/node/mod.js +51 -9
  174. package/dist/node/mod.js.map +1 -1
  175. package/dist/object/index.d.ts +0 -9
  176. package/dist/object/index.d.ts.map +1 -1
  177. package/dist/object/index.js +0 -9
  178. package/dist/object/index.js.map +1 -1
  179. package/dist/object/stringify-object.js +2 -2
  180. package/dist/object/stringify-object.js.map +1 -1
  181. package/dist/object/stringify-object.test.js.map +1 -1
  182. package/dist/qr.d.ts +38 -0
  183. package/dist/qr.d.ts.map +1 -0
  184. package/dist/qr.js +109 -0
  185. package/dist/qr.js.map +1 -0
  186. package/dist/set.js +1 -1
  187. package/dist/set.js.map +1 -1
  188. package/dist/string.d.ts +0 -2
  189. package/dist/string.d.ts.map +1 -1
  190. package/dist/string.js +0 -2
  191. package/dist/string.js.map +1 -1
  192. package/package.json +61 -55
  193. package/src/NoopTracer.test.ts +20 -0
  194. package/src/NoopTracer.ts +28 -37
  195. package/src/binary.ts +1 -1
  196. package/src/browser/Opfs/Opfs.ts +463 -0
  197. package/src/browser/Opfs/debug-utils.ts +154 -0
  198. package/src/browser/Opfs/mod.ts +3 -0
  199. package/src/browser/Opfs/utils.ts +297 -0
  200. package/src/browser/QuotaExceededError.ts +60 -0
  201. package/src/browser/WebChannelBrowser.ts +145 -0
  202. package/src/browser/WebError.test.ts +66 -0
  203. package/src/browser/WebError.ts +587 -0
  204. package/src/{effect → browser}/WebLock.ts +27 -28
  205. package/src/{browser.ts → browser/detect.ts} +6 -6
  206. package/src/browser/mod.ts +8 -0
  207. package/src/cuid/cuid.browser.ts +1 -1
  208. package/src/cuid/cuid.node.ts +1 -1
  209. package/src/effect/Debug.ts +477 -0
  210. package/src/effect/Effect.test.ts +117 -0
  211. package/src/effect/Effect.ts +174 -79
  212. package/src/effect/Error.ts +1 -1
  213. package/src/effect/Logger.ts +0 -48
  214. package/src/effect/OtelTracer.ts +2 -3
  215. package/src/effect/RpcClient.ts +85 -65
  216. package/src/effect/Schedule.ts +4 -5
  217. package/src/effect/Schema/debug-diff.test.ts +7 -7
  218. package/src/effect/Schema/debug-diff.ts +11 -12
  219. package/src/effect/Schema/index.ts +121 -57
  220. package/src/effect/Stream.test.ts +14 -13
  221. package/src/effect/Stream.ts +23 -16
  222. package/src/effect/Subscribable.ts +31 -42
  223. package/src/effect/SubscriptionRef.ts +9 -13
  224. package/src/effect/TaskTracing.ts +13 -16
  225. package/src/effect/WebChannel/WebChannel.test.ts +24 -24
  226. package/src/effect/WebChannel/WebChannel.ts +102 -192
  227. package/src/effect/WebChannel/broadcastChannelWithAck.ts +25 -15
  228. package/src/effect/WebChannel/common.ts +16 -17
  229. package/src/effect/WebSocket.test.ts +2 -2
  230. package/src/effect/WebSocket.ts +20 -16
  231. package/src/effect/mod.browser-build.test.ts +19 -0
  232. package/src/effect/{index.ts → mod.ts} +43 -69
  233. package/src/effect/spanEvent.test.ts +92 -0
  234. package/src/effect/spanEvent.ts +17 -0
  235. package/src/env.ts +2 -1
  236. package/src/fast-deep-equal.ts +9 -10
  237. package/src/global.ts +4 -2
  238. package/src/misc.ts +13 -5
  239. package/src/mod.ts +188 -32
  240. package/src/node/mod.ts +57 -12
  241. package/src/object/index.ts +0 -24
  242. package/src/object/stringify-object.test.ts +1 -0
  243. package/src/object/stringify-object.ts +2 -2
  244. package/src/qr.ts +125 -0
  245. package/src/set.ts +1 -1
  246. package/src/string.ts +0 -3
  247. package/dist/.tsbuildinfo.json +0 -1
  248. package/dist/browser.d.ts.map +0 -1
  249. package/dist/browser.js.map +0 -1
  250. package/dist/effect/BucketQueue.d.ts +0 -20
  251. package/dist/effect/BucketQueue.d.ts.map +0 -1
  252. package/dist/effect/BucketQueue.js +0 -34
  253. package/dist/effect/BucketQueue.js.map +0 -1
  254. package/dist/effect/Scheduler.d.ts +0 -4
  255. package/dist/effect/Scheduler.d.ts.map +0 -1
  256. package/dist/effect/Scheduler.js +0 -9
  257. package/dist/effect/Scheduler.js.map +0 -1
  258. package/dist/effect/ServiceContext.d.ts +0 -37
  259. package/dist/effect/ServiceContext.d.ts.map +0 -1
  260. package/dist/effect/ServiceContext.js +0 -55
  261. package/dist/effect/ServiceContext.js.map +0 -1
  262. package/dist/effect/WebLock.d.ts.map +0 -1
  263. package/dist/effect/WebLock.js.map +0 -1
  264. package/dist/effect/index.d.ts +0 -32
  265. package/dist/effect/index.d.ts.map +0 -1
  266. package/dist/effect/index.js +0 -35
  267. package/dist/effect/index.js.map +0 -1
  268. package/dist/guards.d.ts +0 -6
  269. package/dist/guards.d.ts.map +0 -1
  270. package/dist/guards.js +0 -6
  271. package/dist/guards.js.map +0 -1
  272. package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts +0 -4
  273. package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts.map +0 -1
  274. package/dist/node/ChildProcessRunner/ChildProcessRunner.js +0 -122
  275. package/dist/node/ChildProcessRunner/ChildProcessRunner.js.map +0 -1
  276. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts +0 -2
  277. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.d.ts.map +0 -1
  278. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js +0 -218
  279. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.js.map +0 -1
  280. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts +0 -84
  281. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts.map +0 -1
  282. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js +0 -68
  283. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.js.map +0 -1
  284. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts +0 -2
  285. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.d.ts.map +0 -1
  286. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js +0 -52
  287. package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.js.map +0 -1
  288. package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts +0 -23
  289. package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts.map +0 -1
  290. package/dist/node/ChildProcessRunner/ChildProcessWorker.js +0 -138
  291. package/dist/node/ChildProcessRunner/ChildProcessWorker.js.map +0 -1
  292. package/dist/object/omit.d.ts +0 -3
  293. package/dist/object/omit.d.ts.map +0 -1
  294. package/dist/object/omit.js +0 -14
  295. package/dist/object/omit.js.map +0 -1
  296. package/dist/object/pick.d.ts +0 -14
  297. package/dist/object/pick.d.ts.map +0 -1
  298. package/dist/object/pick.js +0 -17
  299. package/dist/object/pick.js.map +0 -1
  300. package/dist/time.d.ts +0 -12
  301. package/dist/time.d.ts.map +0 -1
  302. package/dist/time.js +0 -22
  303. package/dist/time.js.map +0 -1
  304. package/src/effect/BucketQueue.ts +0 -49
  305. package/src/effect/Scheduler.ts +0 -13
  306. package/src/effect/ServiceContext.ts +0 -108
  307. package/src/guards.ts +0 -8
  308. package/src/node/ChildProcessRunner/ChildProcessRunner.ts +0 -135
  309. package/src/node/ChildProcessRunner/ChildProcessRunnerTest/ChildProcessRunner.test.ts +0 -302
  310. package/src/node/ChildProcessRunner/ChildProcessRunnerTest/schema.ts +0 -78
  311. package/src/node/ChildProcessRunner/ChildProcessRunnerTest/serializedWorker.ts +0 -66
  312. package/src/node/ChildProcessRunner/ChildProcessWorker.ts +0 -168
  313. package/src/object/omit.ts +0 -17
  314. package/src/object/pick.ts +0 -27
  315. package/src/time.ts +0 -25
  316. /package/dist/{effect → browser}/WebLock.d.ts +0 -0
@@ -1,5 +1,4 @@
1
- import type { Deferred, Either, ParseResult } from 'effect'
2
- import { Effect, Predicate, Schema, Stream } from 'effect'
1
+ import { type Deferred, Effect, Predicate, Result, Schema, Stream } from 'effect'
3
2
 
4
3
  export const WebChannelSymbol = Symbol('WebChannel')
5
4
  export type WebChannelSymbol = typeof WebChannelSymbol
@@ -9,13 +8,13 @@ export const isWebChannel = <MsgListen, MsgSend>(value: unknown): value is WebCh
9
8
 
10
9
  export interface WebChannel<MsgListen, MsgSend, E = never> {
11
10
  readonly [WebChannelSymbol]: unknown
12
- send: (a: MsgSend) => Effect.Effect<void, ParseResult.ParseError | E>
13
- listen: Stream.Stream<Either.Either<MsgListen, ParseResult.ParseError>, E>
11
+ send: (a: MsgSend) => Effect.Effect<void, Schema.SchemaError | E>
12
+ listen: Stream.Stream<Result.Result<MsgListen, Schema.SchemaError>, E>
14
13
  supportsTransferables: boolean
15
14
  closedDeferred: Deferred.Deferred<void>
16
15
  shutdown: Effect.Effect<void>
17
- schema: { listen: Schema.Schema<MsgListen, any>; send: Schema.Schema<MsgSend, any> }
18
- debugInfo?: Record<string, any>
16
+ schema: { listen: Schema.Codec<MsgListen, any>; send: Schema.Codec<MsgSend, any> }
17
+ debugInfo?: Record<string, any> | undefined
19
18
  }
20
19
 
21
20
  export const DebugPingMessage = Schema.TaggedStruct('WebChannel.DebugPing', {
@@ -31,43 +30,43 @@ export const WebChannelPong = Schema.TaggedStruct('WebChannel.Pong', {
31
30
  requestId: Schema.String,
32
31
  })
33
32
 
34
- export const WebChannelHeartbeat = Schema.Union(WebChannelPing, WebChannelPong)
33
+ export const WebChannelHeartbeat = Schema.Union([WebChannelPing, WebChannelPong])
35
34
 
36
35
  type WebChannelMessages = typeof DebugPingMessage.Type | typeof WebChannelPing.Type | typeof WebChannelPong.Type
37
36
 
38
37
  export const schemaWithWebChannelMessages = <MsgListen, MsgSend>(
39
38
  schema: OutputSchema<MsgListen, MsgSend, any, any>,
40
39
  ): OutputSchema<MsgListen | WebChannelMessages, MsgSend | WebChannelMessages, any, any> => ({
41
- send: Schema.Union(schema.send, DebugPingMessage, WebChannelPing, WebChannelPong),
42
- listen: Schema.Union(schema.listen, DebugPingMessage, WebChannelPing, WebChannelPong),
40
+ send: Schema.Union([schema.send, DebugPingMessage, WebChannelPing, WebChannelPong]),
41
+ listen: Schema.Union([schema.listen, DebugPingMessage, WebChannelPing, WebChannelPong]),
43
42
  })
44
43
 
45
44
  export type InputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded> =
46
- | Schema.Schema<MsgListen | MsgSend, MsgListenEncoded | MsgSendEncoded>
45
+ | Schema.Codec<MsgListen | MsgSend, MsgListenEncoded | MsgSendEncoded>
47
46
  | OutputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>
48
47
 
49
48
  export type OutputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded> = {
50
- listen: Schema.Schema<MsgListen, MsgListenEncoded>
51
- send: Schema.Schema<MsgSend, MsgSendEncoded>
49
+ listen: Schema.Codec<MsgListen, MsgListenEncoded>
50
+ send: Schema.Codec<MsgSend, MsgSendEncoded>
52
51
  }
53
52
 
54
53
  export const mapSchema = <MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>(
55
54
  schema: InputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded>,
56
55
  ): OutputSchema<MsgListen, MsgSend, MsgListenEncoded, MsgSendEncoded> =>
57
- Predicate.hasProperty(schema, 'send') && Predicate.hasProperty(schema, 'listen')
56
+ Predicate.hasProperty(schema, 'send') === true && Predicate.hasProperty(schema, 'listen') === true
58
57
  ? (schemaWithWebChannelMessages(schema) as any)
59
58
  : (schemaWithWebChannelMessages({ send: schema, listen: schema }) as any)
60
59
 
61
60
  export const listenToDebugPing =
62
61
  (channelName: string) =>
63
62
  <MsgListen>(
64
- stream: Stream.Stream<Either.Either<MsgListen, ParseResult.ParseError>, never>,
65
- ): Stream.Stream<Either.Either<MsgListen, ParseResult.ParseError>, never> =>
63
+ stream: Stream.Stream<Result.Result<MsgListen, Schema.SchemaError>>,
64
+ ): Stream.Stream<Result.Result<MsgListen, Schema.SchemaError>> =>
66
65
  stream.pipe(
67
66
  Stream.filterEffect(
68
67
  Effect.fn(function* (msg) {
69
- if (msg._tag === 'Right' && Schema.is(DebugPingMessage)(msg.right)) {
70
- yield* Effect.logDebug(`WebChannel:ping [${channelName}] ${msg.right.message}`, msg.right.payload)
68
+ if (Result.isSuccess(msg) === true && Schema.is(DebugPingMessage)(msg.success) === true) {
69
+ yield* Effect.logDebug(`WebChannel:ping [${channelName}] ${msg.success.message}`, msg.success.payload)
71
70
  return false
72
71
  }
73
72
  return true
@@ -1,11 +1,11 @@
1
- import { FetchHttpClient } from '@effect/platform'
2
1
  import * as Vitest from '@effect/vitest'
3
2
  import { Effect, Exit } from 'effect'
3
+ import { FetchHttpClient } from 'effect/unstable/http'
4
4
 
5
5
  import { makeWebSocket } from './WebSocket.ts'
6
6
 
7
7
  Vitest.describe('WebSocket', () => {
8
- Vitest.scopedLive(
8
+ Vitest.live(
9
9
  'should create a WebSocket connection',
10
10
  Effect.fn(function* () {
11
11
  const exit = yield* makeWebSocket({ url: 'ws://localhost:1000' }).pipe(Effect.timeout(500), Effect.exit)
@@ -1,10 +1,13 @@
1
- import { HttpClient } from '@effect/platform'
2
1
  import type { Schedule, Scope } from 'effect'
3
2
  import { Effect, Exit, identity, Schema } from 'effect'
3
+ import { HttpClient } from 'effect/unstable/http'
4
4
 
5
- export class WebSocketError extends Schema.TaggedError<WebSocketError>()('WebSocketError', {
6
- cause: Schema.Defect,
7
- }) {}
5
+ export class WebSocketError extends Schema.TaggedError<WebSocketError>('~@livestore/utils/WebSocketError')(
6
+ 'WebSocketError',
7
+ {
8
+ cause: Schema.Defect(),
9
+ },
10
+ ) {}
8
11
 
9
12
  // TODO refactor using Effect socket implementation
10
13
  // https://github.com/Effect-TS/effect/blob/main/packages%2Fexperimental%2Fsrc%2FDevTools%2FClient.ts#L113
@@ -25,7 +28,7 @@ export const makeWebSocket = ({
25
28
  Effect.gen(function* () {
26
29
  yield* validateUrl(url)
27
30
 
28
- const socket = yield* Effect.async<globalThis.WebSocket, WebSocketError>((cb, signal) => {
31
+ const socket = yield* Effect.callback<globalThis.WebSocket, WebSocketError>((cb, signal) => {
29
32
  try {
30
33
  const socket = new globalThis.WebSocket(url)
31
34
 
@@ -63,7 +66,7 @@ export const makeWebSocket = ({
63
66
  }
64
67
  }).pipe(
65
68
  Effect.tapErrorTag('WebSocketError', () => tryLogWebsocketConnectError(url)),
66
- reconnect ? Effect.retry(reconnect) : identity,
69
+ reconnect !== undefined && reconnect !== false ? Effect.retry(reconnect) : identity,
67
70
  )
68
71
 
69
72
  /**
@@ -81,16 +84,17 @@ export const makeWebSocket = ({
81
84
  */
82
85
  yield* Effect.addFinalizer(
83
86
  Effect.fn(function* (exit) {
84
- try {
85
- if (Exit.isFailure(exit)) {
86
- socket.close(3000)
87
- } else {
88
- socket.close(1000)
89
- }
90
- } catch (error) {
91
- return yield* Effect.die(new WebSocketError({ cause: error }))
92
- }
93
- }),
87
+ yield* Effect.try({
88
+ try: () => {
89
+ if (Exit.isFailure(exit) === true) {
90
+ socket.close(3000)
91
+ } else {
92
+ socket.close(1000)
93
+ }
94
+ },
95
+ catch: (error) => new WebSocketError({ cause: error }),
96
+ })
97
+ }, Effect.orDie),
94
98
  )
95
99
 
96
100
  return socket
@@ -0,0 +1,19 @@
1
+ import { build } from 'esbuild'
2
+ import { expect, it } from 'vitest'
3
+
4
+ it('bundles the Effect facade for browsers without Node builtins', async () => {
5
+ const result = await build({
6
+ bundle: true,
7
+ format: 'esm',
8
+ platform: 'browser',
9
+ stdin: {
10
+ contents: `import { Schema } from './mod.ts'; export const BrowserSchema = Schema.Struct({ value: Schema.String })`,
11
+ loader: 'ts',
12
+ resolveDir: import.meta.dirname,
13
+ sourcefile: 'browser-build-fixture.ts',
14
+ },
15
+ write: false,
16
+ })
17
+
18
+ expect(result.outputFiles).toHaveLength(1)
19
+ })
@@ -1,34 +1,11 @@
1
1
  import '../global.ts'
2
2
 
3
+ export { Otlp } from 'effect/unstable/observability'
4
+ export { Msgpack } from 'effect/unstable/encoding'
3
5
  export {
4
- AiError,
5
- LanguageModel,
6
- LanguageModel as AiLanguageModel,
7
- McpSchema,
8
- McpServer,
9
- Model,
10
- Model as AiModel,
11
- Prompt,
12
- Tool,
13
- Tool as AiTool,
14
- Toolkit,
15
- Toolkit as AiToolkit,
16
- } from '@effect/ai'
17
- // export { DevTools as EffectDevtools } from '@effect/experimental'
18
- export { Sse } from '@effect/experimental'
19
- export * as Otlp from '@effect/opentelemetry/Otlp'
20
- export {
21
- Command,
22
- CommandExecutor,
23
- Error as PlatformError,
24
6
  FetchHttpClient,
25
- FileSystem,
26
7
  Headers,
27
- HttpApi,
28
- HttpApiClient,
29
- HttpApiEndpoint,
30
- HttpApiGroup,
31
- HttpApp,
8
+ HttpEffect,
32
9
  HttpClient,
33
10
  HttpClientError,
34
11
  HttpClientRequest,
@@ -38,20 +15,15 @@ export {
38
15
  HttpServer,
39
16
  HttpServerRequest,
40
17
  HttpServerResponse,
41
- KeyValueStore,
42
- MsgPack,
43
- Socket,
44
- Terminal,
45
- Transferable,
46
18
  UrlParams,
47
- Worker,
48
- WorkerError,
49
- WorkerRunner,
50
- } from '@effect/platform'
51
- export { BrowserWorker, BrowserWorkerRunner } from '@effect/platform-browser'
19
+ } from 'effect/unstable/http'
20
+ export { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup } from 'effect/unstable/httpapi'
21
+ export { KeyValueStore } from 'effect/unstable/persistence'
22
+ export { ChildProcess, ChildProcessSpawner } from 'effect/unstable/process'
23
+ export { Socket } from 'effect/unstable/socket'
24
+ export { Transferable, Worker, WorkerError, WorkerRunner } from 'effect/unstable/workers'
52
25
  export {
53
26
  Rpc,
54
- // RpcClient, // TODO bring back "original" RpcClient from effect/rpc
55
27
  RpcClientError,
56
28
  RpcGroup,
57
29
  RpcMessage,
@@ -61,7 +33,7 @@ export {
61
33
  RpcServer,
62
34
  RpcTest,
63
35
  RpcWorker,
64
- } from '@effect/rpc'
36
+ } from 'effect/unstable/rpc'
65
37
  export * as StandardSchema from '@standard-schema/spec'
66
38
  export {
67
39
  Array as ReadonlyArray,
@@ -71,85 +43,87 @@ export {
71
43
  Channel,
72
44
  Chunk,
73
45
  Config,
74
- ConfigError,
46
+ ConfigProvider,
75
47
  Console,
76
48
  Context,
77
49
  Data,
78
50
  Deferred,
79
51
  Duration,
80
- Either,
52
+ Result,
81
53
  Equal,
82
- ExecutionStrategy,
83
54
  Exit,
84
- FastCheck,
85
55
  Fiber,
56
+ Filter,
57
+ FileSystem,
58
+ Terminal,
86
59
  FiberHandle,
87
- FiberId,
88
60
  FiberMap,
89
- FiberRef,
90
- FiberRefs,
91
- FiberRefsPatch,
92
61
  FiberSet,
93
- GlobalValue,
62
+ Formatter,
63
+ Function,
94
64
  Hash,
95
65
  HashMap,
96
66
  HashSet,
97
67
  Inspectable,
98
68
  identity,
69
+ Latch,
99
70
  Layer,
100
- List,
101
71
  LogLevel,
102
- LogSpan,
103
- Mailbox,
104
72
  ManagedRuntime,
105
73
  Match,
106
74
  Metric,
107
- MetricState,
108
75
  MutableHashMap,
109
76
  MutableHashSet,
77
+ MutableList,
110
78
  Option,
111
- ParseResult,
79
+ Order,
112
80
  Predicate,
113
- Pretty,
114
81
  PrimaryKey,
82
+ PlatformError,
115
83
  PubSub,
116
- // Subscribable,
117
84
  pipe,
118
85
  Queue,
86
+ RcMap,
87
+ RcRef,
119
88
  Record as ReadonlyRecord,
89
+ References,
90
+ Redacted,
120
91
  Ref,
121
92
  Request,
122
93
  Runtime,
123
- RuntimeFlags,
124
94
  Scope,
125
- SortedMap,
126
- STM,
95
+ ScopedRef,
96
+ Scheduler,
97
+ SchemaIssue,
98
+ SchemaAST,
99
+ SchemaGetter,
100
+ SchemaParser,
101
+ SchemaRepresentation,
102
+ SchemaTransformation,
103
+ Semaphore,
104
+ Sink,
105
+ Struct,
106
+ Graph,
127
107
  SynchronizedRef,
128
- TestServices,
129
- TQueue,
130
- TRef,
131
108
  Tracer,
109
+ TxQueue,
110
+ TxRef,
132
111
  Types,
133
112
  } from 'effect'
134
- export type { NonEmptyArray } from 'effect/Array'
135
- export { constVoid, dual } from 'effect/Function'
136
- export { TreeFormatter } from 'effect/ParseResult'
137
- export type { Serializable, SerializableWithResult } from 'effect/Schema'
138
- export * as SchemaAST from 'effect/SchemaAST'
139
- export * as BucketQueue from './BucketQueue.ts'
113
+ export * as FastCheck from 'effect/testing/FastCheck'
114
+ export * as TestClock from 'effect/testing/TestClock'
115
+ export * as TestConsole from 'effect/testing/TestConsole'
116
+ export * as Debug from './Debug.ts'
140
117
  export * as Effect from './Effect.ts'
141
118
  export * from './Error.ts'
142
119
  export * as Logger from './Logger.ts'
143
120
  export * as OtelTracer from './OtelTracer.ts'
144
121
  export * as RpcClient from './RpcClient.ts'
145
122
  export * as Schedule from './Schedule.ts'
146
- export * as Scheduler from './Scheduler.ts'
147
123
  export * as Schema from './Schema/index.ts'
148
- export * as ServiceContext from './ServiceContext.ts'
149
124
  export * as Stream from './Stream.ts'
150
125
  export * as Subscribable from './Subscribable.ts'
151
126
  export * as SubscriptionRef from './SubscriptionRef.ts'
152
127
  export * as TaskTracing from './TaskTracing.ts'
153
128
  export * as WebChannel from './WebChannel/mod.ts'
154
- export * as WebLock from './WebLock.ts'
155
129
  export * as WebSocket from './WebSocket.ts'
@@ -0,0 +1,92 @@
1
+ import { describe, expect, it } from '@effect/vitest'
2
+ import { Effect, Tracer } from 'effect'
3
+
4
+ import { spanEvent } from './spanEvent.ts'
5
+
6
+ type RecordedEvent = { name: string; attributes: Record<string, unknown> | undefined }
7
+
8
+ /**
9
+ * Creates a test tracer that captures span events for assertion,
10
+ * using only the public `Tracer` API (no internal NativeSpan access).
11
+ * Each span records its own events, retrievable by span name.
12
+ */
13
+ const makeTestTracer = () => {
14
+ const spanEvents = new Map<string, Array<RecordedEvent>>()
15
+
16
+ const tracer = Tracer.make({
17
+ span(options) {
18
+ const events: Array<RecordedEvent> = []
19
+ spanEvents.set(options.name, events)
20
+ const attributes = new Map<string, unknown>()
21
+ return {
22
+ _tag: 'Span' as const,
23
+ name: options.name,
24
+ spanId: `test-${options.name}`,
25
+ traceId: 'test-trace',
26
+ parent: options.parent,
27
+ annotations: options.annotations,
28
+ status: { _tag: 'Started' as const, startTime: options.startTime },
29
+ attributes,
30
+ links: options.links,
31
+ sampled: true,
32
+ kind: options.kind,
33
+ end() {},
34
+ attribute(key: string, value: unknown) {
35
+ attributes.set(key, value)
36
+ },
37
+ event(eventName: string, _startTime: bigint, attrs?: Record<string, unknown>) {
38
+ events.push({ name: eventName, attributes: attrs })
39
+ },
40
+ addLinks() {},
41
+ }
42
+ },
43
+ })
44
+
45
+ return {
46
+ tracer,
47
+ getEvents: (spanName: string): Array<RecordedEvent> => spanEvents.get(spanName) ?? [],
48
+ }
49
+ }
50
+
51
+ describe('spanEvent', () => {
52
+ it.effect('should emit a span event with the given message', () => {
53
+ const { tracer, getEvents } = makeTestTracer()
54
+ return Effect.gen(function* () {
55
+ yield* spanEvent('test-event')
56
+ const events = getEvents('test-span')
57
+ expect(events).toHaveLength(1)
58
+ expect(events[0]!.name).toBe('test-event')
59
+ }).pipe(Effect.withSpan('test-span'), Effect.withTracer(tracer))
60
+ })
61
+
62
+ it.effect('should emit a span event with attributes', () => {
63
+ const { tracer, getEvents } = makeTestTracer()
64
+ return Effect.gen(function* () {
65
+ yield* spanEvent('event-with-attrs', { key1: 'value1', key2: 42 })
66
+ const events = getEvents('test-span')
67
+ expect(events).toHaveLength(1)
68
+ expect(events[0]!.name).toBe('event-with-attrs')
69
+ expect(events[0]!.attributes).toMatchObject({ key1: 'value1', key2: 42 })
70
+ }).pipe(Effect.withSpan('test-span'), Effect.withTracer(tracer))
71
+ })
72
+
73
+ it.effect('should emit to the nearest enclosing span', () => {
74
+ const { tracer, getEvents } = makeTestTracer()
75
+ return Effect.gen(function* () {
76
+ yield* spanEvent('outer-event')
77
+
78
+ yield* spanEvent('inner-event').pipe(Effect.withSpan('inner-span'))
79
+
80
+ const outerEvents = getEvents('outer-span')
81
+ const innerEvents = getEvents('inner-span')
82
+
83
+ expect(outerEvents).toHaveLength(1)
84
+ expect(outerEvents[0]!.name).toBe('outer-event')
85
+
86
+ expect(innerEvents).toHaveLength(1)
87
+ expect(innerEvents[0]!.name).toBe('inner-event')
88
+ }).pipe(Effect.withSpan('outer-span'), Effect.withTracer(tracer))
89
+ })
90
+
91
+ it.effect('should be a no-op when no span is in context', () => spanEvent('orphan-event'))
92
+ })
@@ -0,0 +1,17 @@
1
+ import { Effect, Logger } from 'effect'
2
+
3
+ /**
4
+ * Emits a span event on the current Effect span via the tracer logger.
5
+ *
6
+ * @remarks
7
+ *
8
+ * Unlike raw `otelSpan.addEvent`, this doesn't require manual span threading —
9
+ * it automatically targets the nearest enclosing `Effect.withSpan`. If no span
10
+ * is in context, the call is a no-op.
11
+ */
12
+ export const spanEvent = (message: any, attributes?: Record<string, unknown>) =>
13
+ Effect.provideService(
14
+ Effect.log(message).pipe(Effect.annotateLogs(attributes ?? {})),
15
+ Logger.CurrentLoggers,
16
+ new Set([Logger.tracerLogger]),
17
+ )
package/src/env.ts CHANGED
@@ -26,4 +26,5 @@ export const IS_CI = envTruish(env('CI'))
26
26
 
27
27
  export const IS_BUN = typeof Bun !== 'undefined'
28
28
 
29
- export const IS_REACT_NATIVE = typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
29
+ export const IS_REACT_NATIVE =
30
+ typeof navigator !== 'undefined' && (navigator as unknown as Record<string, unknown>)['product'] === 'ReactNative'
@@ -4,36 +4,36 @@
4
4
  export const deepEqual = <T>(a: T, b: T): boolean => {
5
5
  if (a === b) return true
6
6
 
7
- if (a && b && typeof a === 'object' && typeof b === 'object') {
7
+ if (a != null && b != null && typeof a === 'object' && typeof b === 'object') {
8
8
  if (a.constructor !== b.constructor) return false
9
9
 
10
10
  let length: number
11
11
  let i: any
12
12
  let keys: any
13
- if (Array.isArray(a)) {
13
+ if (Array.isArray(a) === true) {
14
14
  length = a.length
15
15
  // @ts-expect-error ...
16
16
  if (length !== b.length) return false
17
17
  for (i = length; i-- !== 0; )
18
18
  // @ts-expect-error ...
19
- if (!deepEqual(a[i], b[i])) return false
19
+ if (deepEqual(a[i], b[i]) === false) return false
20
20
  return true
21
21
  }
22
22
 
23
23
  if (a instanceof Map && b instanceof Map) {
24
24
  if (a.size !== b.size) return false
25
- for (i of a.entries()) if (!b.has(i[0])) return false
26
- for (i of a.entries()) if (!deepEqual(i[1], b.get(i[0]))) return false
25
+ for (i of a.entries()) if (b.has(i[0]) === false) return false
26
+ for (i of a.entries()) if (deepEqual(i[1], b.get(i[0])) === false) return false
27
27
  return true
28
28
  }
29
29
 
30
30
  if (a instanceof Set && b instanceof Set) {
31
31
  if (a.size !== b.size) return false
32
- for (i of a.entries()) if (!b.has(i[0])) return false
32
+ for (i of a.entries()) if (b.has(i[0]) === false) return false
33
33
  return true
34
34
  }
35
35
 
36
- if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
36
+ if (ArrayBuffer.isView(a) === true && ArrayBuffer.isView(b) === true) {
37
37
  // @ts-expect-error ...
38
38
  length = a.length
39
39
  // @ts-expect-error ...
@@ -53,19 +53,18 @@ export const deepEqual = <T>(a: T, b: T): boolean => {
53
53
  length = keys.length
54
54
  if (length !== Object.keys(b).length) return false
55
55
 
56
- for (i = length; i-- !== 0; ) if (!Object.hasOwn(b, keys[i])) return false
56
+ for (i = length; i-- !== 0; ) if (Object.hasOwn(b, keys[i]) === false) return false
57
57
 
58
58
  for (i = length; i-- !== 0; ) {
59
59
  const key = keys[i]
60
60
 
61
61
  // @ts-expect-error ...
62
- if (!deepEqual(a[key], b[key])) return false
62
+ if (deepEqual(a[key], b[key]) === false) return false
63
63
  }
64
64
 
65
65
  return true
66
66
  }
67
67
 
68
68
  // true if both NaN, false otherwise
69
- // biome-ignore lint/suspicious/noSelfCompare: comparing to itself is fine here
70
69
  return a !== a && b !== b
71
70
  }
package/src/global.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  declare global {
2
2
  export type TODO<_Reason extends string = 'unknown'> = any
3
3
  export type UNUSED<_Reason extends string = 'unknown'> = any
4
- }
5
4
 
6
- export {}
5
+ interface ImportMeta {
6
+ main: boolean
7
+ }
8
+ }
package/src/misc.ts CHANGED
@@ -9,8 +9,8 @@ export const isDevEnv = () => {
9
9
  return import.meta.env.DEV
10
10
  }
11
11
 
12
- // @ts-expect-error Only exists in Expo / RN
13
- if (globalThis?.__DEV__) {
12
+ const globals = globalThis as typeof globalThis & { readonly __DEV__?: boolean | undefined }
13
+ if (globals.__DEV__ === true) {
14
14
  return true
15
15
  }
16
16
 
@@ -46,10 +46,18 @@ export const tryAsFunctionAndNew = <TArg, TResult>(
46
46
  export const envTruish = (env: string | undefined) =>
47
47
  env !== undefined && env.toLowerCase() !== 'false' && env.toLowerCase() !== '0'
48
48
 
49
- export const shouldNeverHappen = (msg?: string, ...args: any[]): never => {
49
+ /**
50
+ * Logs and throws for impossible states, pausing at a breakpoint in development.
51
+ *
52
+ * @param msg - The error message to log and pass to the error.
53
+ * @param args - Arbitrary arguments to include in the log.
54
+ *
55
+ * @see {@link dieDebugger} for the Effect equivalent.
56
+ */
57
+ export const shouldNeverHappen = (msg?: string, ...args: ReadonlyArray<unknown>): never => {
50
58
  console.error(msg, ...args)
51
- if (isDevEnv()) {
52
- // biome-ignore lint/suspicious/noDebugger: debugging
59
+ if (isDevEnv() === true) {
60
+ // oxlint-disable-next-line eslint(no-debugger) -- intentional breakpoint during development
53
61
  debugger
54
62
  }
55
63