effect 4.0.0-beta.41 → 4.0.0-beta.43

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 (125) hide show
  1. package/dist/Effect.d.ts +19 -63
  2. package/dist/Effect.d.ts.map +1 -1
  3. package/dist/Effect.js +24 -65
  4. package/dist/Effect.js.map +1 -1
  5. package/dist/Layer.d.ts +25 -0
  6. package/dist/Layer.d.ts.map +1 -1
  7. package/dist/Layer.js +25 -0
  8. package/dist/Layer.js.map +1 -1
  9. package/dist/MutableList.d.ts.map +1 -1
  10. package/dist/MutableList.js +3 -0
  11. package/dist/MutableList.js.map +1 -1
  12. package/dist/Number.d.ts.map +1 -1
  13. package/dist/Number.js +12 -3
  14. package/dist/Number.js.map +1 -1
  15. package/dist/SchemaRepresentation.d.ts.map +1 -1
  16. package/dist/SchemaRepresentation.js +16 -14
  17. package/dist/SchemaRepresentation.js.map +1 -1
  18. package/dist/TxChunk.d.ts +39 -39
  19. package/dist/TxChunk.d.ts.map +1 -1
  20. package/dist/TxChunk.js +3 -3
  21. package/dist/TxChunk.js.map +1 -1
  22. package/dist/TxDeferred.d.ts +9 -9
  23. package/dist/TxDeferred.d.ts.map +1 -1
  24. package/dist/TxDeferred.js +2 -2
  25. package/dist/TxDeferred.js.map +1 -1
  26. package/dist/TxHashMap.d.ts +59 -59
  27. package/dist/TxHashMap.d.ts.map +1 -1
  28. package/dist/TxHashMap.js +8 -8
  29. package/dist/TxHashMap.js.map +1 -1
  30. package/dist/TxHashSet.d.ts +35 -35
  31. package/dist/TxHashSet.d.ts.map +1 -1
  32. package/dist/TxHashSet.js +7 -7
  33. package/dist/TxHashSet.js.map +1 -1
  34. package/dist/TxPriorityQueue.d.ts +23 -23
  35. package/dist/TxPriorityQueue.d.ts.map +1 -1
  36. package/dist/TxPriorityQueue.js +4 -4
  37. package/dist/TxPriorityQueue.js.map +1 -1
  38. package/dist/TxPubSub.d.ts +14 -14
  39. package/dist/TxPubSub.d.ts.map +1 -1
  40. package/dist/TxPubSub.js +12 -12
  41. package/dist/TxPubSub.js.map +1 -1
  42. package/dist/TxQueue.d.ts +33 -33
  43. package/dist/TxQueue.d.ts.map +1 -1
  44. package/dist/TxQueue.js +29 -44
  45. package/dist/TxQueue.js.map +1 -1
  46. package/dist/TxReentrantLock.d.ts +10 -33
  47. package/dist/TxReentrantLock.d.ts.map +1 -1
  48. package/dist/TxReentrantLock.js +14 -37
  49. package/dist/TxReentrantLock.js.map +1 -1
  50. package/dist/TxRef.d.ts +36 -42
  51. package/dist/TxRef.d.ts.map +1 -1
  52. package/dist/TxRef.js +16 -25
  53. package/dist/TxRef.js.map +1 -1
  54. package/dist/TxSemaphore.d.ts +8 -8
  55. package/dist/TxSemaphore.d.ts.map +1 -1
  56. package/dist/TxSemaphore.js +10 -10
  57. package/dist/TxSemaphore.js.map +1 -1
  58. package/dist/TxSubscriptionRef.d.ts +14 -14
  59. package/dist/TxSubscriptionRef.d.ts.map +1 -1
  60. package/dist/TxSubscriptionRef.js +5 -5
  61. package/dist/TxSubscriptionRef.js.map +1 -1
  62. package/dist/index.d.ts +3 -3
  63. package/dist/index.js +3 -3
  64. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +1 -1
  65. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  66. package/dist/unstable/ai/AnthropicStructuredOutput.js +5 -2
  67. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  68. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +1 -1
  69. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  70. package/dist/unstable/ai/OpenAiStructuredOutput.js +5 -1
  71. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  72. package/dist/unstable/ai/internal/codec-transformer.js +5 -2
  73. package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
  74. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  75. package/dist/unstable/cli/internal/command.js +12 -1
  76. package/dist/unstable/cli/internal/command.js.map +1 -1
  77. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +1 -0
  78. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  79. package/dist/unstable/cluster/ClusterWorkflowEngine.js +55 -26
  80. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  81. package/dist/unstable/cluster/Entity.d.ts +2 -2
  82. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  83. package/dist/unstable/cluster/Entity.js +13 -8
  84. package/dist/unstable/cluster/Entity.js.map +1 -1
  85. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  86. package/dist/unstable/cluster/SqlMessageStorage.js +1 -4
  87. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  88. package/dist/unstable/rpc/RpcSerialization.js +5 -5
  89. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  90. package/dist/unstable/socket/Socket.d.ts +1 -1
  91. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  92. package/dist/unstable/socket/Socket.js +1 -1
  93. package/dist/unstable/socket/Socket.js.map +1 -1
  94. package/dist/unstable/workflow/WorkflowEngine.d.ts +6 -0
  95. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  96. package/dist/unstable/workflow/WorkflowEngine.js +9 -0
  97. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  98. package/package.json +1 -1
  99. package/src/Effect.ts +24 -75
  100. package/src/Layer.ts +27 -0
  101. package/src/MutableList.ts +3 -0
  102. package/src/Number.ts +13 -3
  103. package/src/SchemaRepresentation.ts +8 -6
  104. package/src/TxChunk.ts +53 -62
  105. package/src/TxDeferred.ts +14 -17
  106. package/src/TxHashMap.ts +91 -101
  107. package/src/TxHashSet.ts +68 -70
  108. package/src/TxPriorityQueue.ts +34 -38
  109. package/src/TxPubSub.ts +30 -32
  110. package/src/TxQueue.ts +70 -84
  111. package/src/TxReentrantLock.ts +30 -54
  112. package/src/TxRef.ts +53 -65
  113. package/src/TxSemaphore.ts +23 -24
  114. package/src/TxSubscriptionRef.ts +25 -27
  115. package/src/index.ts +3 -3
  116. package/src/unstable/ai/AnthropicStructuredOutput.ts +3 -3
  117. package/src/unstable/ai/OpenAiStructuredOutput.ts +5 -2
  118. package/src/unstable/ai/internal/codec-transformer.ts +3 -2
  119. package/src/unstable/cli/internal/command.ts +16 -1
  120. package/src/unstable/cluster/ClusterWorkflowEngine.ts +77 -38
  121. package/src/unstable/cluster/Entity.ts +18 -7
  122. package/src/unstable/cluster/SqlMessageStorage.ts +0 -4
  123. package/src/unstable/rpc/RpcSerialization.ts +5 -5
  124. package/src/unstable/socket/Socket.ts +1 -1
  125. package/src/unstable/workflow/WorkflowEngine.ts +22 -0
@@ -98,14 +98,14 @@ const TxReentrantLockProto: Omit<TxReentrantLock, typeof TypeId | "stateRef"> =
98
98
  * @since 4.0.0
99
99
  * @category constructors
100
100
  */
101
- export const make = (): Effect.Effect<TxReentrantLock, never, Effect.Transaction> =>
101
+ export const make = (): Effect.Effect<TxReentrantLock> =>
102
102
  Effect.gen(function*() {
103
103
  const stateRef = yield* TxRef.make<LockState>(emptyState)
104
104
  const self = Object.create(TxReentrantLockProto)
105
105
  self[TypeId] = TypeId
106
106
  self.stateRef = stateRef
107
107
  return self
108
- })
108
+ }).pipe(Effect.tx)
109
109
 
110
110
  // =============================================================================
111
111
  // Mutations
@@ -131,7 +131,7 @@ export const make = (): Effect.Effect<TxReentrantLock, never, Effect.Transaction
131
131
  * @since 4.0.0
132
132
  * @category mutations
133
133
  */
134
- export const acquireRead = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
134
+ export const acquireRead = (self: TxReentrantLock): Effect.Effect<number> =>
135
135
  Effect.withFiber((fiber) =>
136
136
  Effect.gen(function*() {
137
137
  const state = yield* TxRef.get(self.stateRef)
@@ -139,7 +139,7 @@ export const acquireRead = (self: TxReentrantLock): Effect.Effect<number, never,
139
139
 
140
140
  // If another fiber holds the write lock, retry
141
141
  if (Option.isSome(state.writer) && state.writer.value[0] !== fiberId) {
142
- return yield* Effect.retryTransaction
142
+ return yield* Effect.txRetry
143
143
  }
144
144
 
145
145
  // Grant read lock
@@ -150,7 +150,7 @@ export const acquireRead = (self: TxReentrantLock): Effect.Effect<number, never,
150
150
  readers: HashMap.set(state.readers, fiberId, newCount)
151
151
  })
152
152
  return newCount
153
- })
153
+ }).pipe(Effect.tx)
154
154
  )
155
155
 
156
156
  /**
@@ -174,7 +174,7 @@ export const acquireRead = (self: TxReentrantLock): Effect.Effect<number, never,
174
174
  * @since 4.0.0
175
175
  * @category mutations
176
176
  */
177
- export const acquireWrite = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
177
+ export const acquireWrite = (self: TxReentrantLock): Effect.Effect<number> =>
178
178
  Effect.withFiber((fiber) =>
179
179
  Effect.gen(function*() {
180
180
  const state = yield* TxRef.get(self.stateRef)
@@ -182,13 +182,13 @@ export const acquireWrite = (self: TxReentrantLock): Effect.Effect<number, never
182
182
 
183
183
  // If another fiber holds the write lock, retry
184
184
  if (Option.isSome(state.writer) && state.writer.value[0] !== fiberId) {
185
- return yield* Effect.retryTransaction
185
+ return yield* Effect.txRetry
186
186
  }
187
187
 
188
188
  // If other fibers hold read locks, retry
189
189
  for (const [readerId] of state.readers) {
190
190
  if (readerId !== fiberId && Option.getOrElse(HashMap.get(state.readers, readerId), () => 0) > 0) {
191
- return yield* Effect.retryTransaction
191
+ return yield* Effect.txRetry
192
192
  }
193
193
  }
194
194
 
@@ -209,7 +209,7 @@ export const acquireWrite = (self: TxReentrantLock): Effect.Effect<number, never
209
209
  writer: Option.some([fiberId, 1] as const)
210
210
  })
211
211
  return 1
212
- })
212
+ }).pipe(Effect.tx)
213
213
  )
214
214
 
215
215
  /**
@@ -231,7 +231,7 @@ export const acquireWrite = (self: TxReentrantLock): Effect.Effect<number, never
231
231
  * @since 4.0.0
232
232
  * @category mutations
233
233
  */
234
- export const releaseRead = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
234
+ export const releaseRead = (self: TxReentrantLock): Effect.Effect<number> =>
235
235
  Effect.withFiber((fiber) =>
236
236
  Effect.gen(function*() {
237
237
  const state = yield* TxRef.get(self.stateRef)
@@ -247,7 +247,7 @@ export const releaseRead = (self: TxReentrantLock): Effect.Effect<number, never,
247
247
 
248
248
  yield* TxRef.set(self.stateRef, { ...state, readers: newReaders })
249
249
  return newCount
250
- })
250
+ }).pipe(Effect.tx)
251
251
  )
252
252
 
253
253
  /**
@@ -269,7 +269,7 @@ export const releaseRead = (self: TxReentrantLock): Effect.Effect<number, never,
269
269
  * @since 4.0.0
270
270
  * @category mutations
271
271
  */
272
- export const releaseWrite = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
272
+ export const releaseWrite = (self: TxReentrantLock): Effect.Effect<number> =>
273
273
  Effect.withFiber((fiber) =>
274
274
  Effect.gen(function*() {
275
275
  const state = yield* TxRef.get(self.stateRef)
@@ -284,7 +284,7 @@ export const releaseWrite = (self: TxReentrantLock): Effect.Effect<number, never
284
284
 
285
285
  yield* TxRef.set(self.stateRef, { ...state, writer: newWriter })
286
286
  return newCount
287
- })
287
+ }).pipe(Effect.tx)
288
288
  )
289
289
 
290
290
  /**
@@ -313,8 +313,8 @@ export const releaseWrite = (self: TxReentrantLock): Effect.Effect<number, never
313
313
  */
314
314
  export const readLock = (self: TxReentrantLock): Effect.Effect<number, never, Scope.Scope> =>
315
315
  Effect.acquireRelease(
316
- Effect.transaction(acquireRead(self)),
317
- () => Effect.transaction(releaseRead(self))
316
+ acquireRead(self),
317
+ () => releaseRead(self)
318
318
  )
319
319
 
320
320
  /**
@@ -343,34 +343,10 @@ export const readLock = (self: TxReentrantLock): Effect.Effect<number, never, Sc
343
343
  */
344
344
  export const writeLock = (self: TxReentrantLock): Effect.Effect<number, never, Scope.Scope> =>
345
345
  Effect.acquireRelease(
346
- Effect.transaction(acquireWrite(self)),
347
- () => Effect.transaction(releaseWrite(self))
346
+ acquireWrite(self),
347
+ () => releaseWrite(self)
348
348
  )
349
349
 
350
- /**
351
- * Alias for `writeLock`. Acquires a write lock for the duration of the scope.
352
- *
353
- * @example
354
- * ```ts
355
- * import { Effect, TxReentrantLock } from "effect"
356
- *
357
- * const program = Effect.gen(function*() {
358
- * const lock = yield* TxReentrantLock.make()
359
- *
360
- * yield* Effect.scoped(
361
- * Effect.gen(function*() {
362
- * yield* TxReentrantLock.lock(lock)
363
- * // exclusive lock is held
364
- * })
365
- * )
366
- * })
367
- * ```
368
- *
369
- * @since 4.0.0
370
- * @category mutations
371
- */
372
- export const lock = writeLock
373
-
374
350
  /**
375
351
  * Runs the provided effect while holding a read lock. The lock is automatically
376
352
  * released after the effect completes, fails, or is interrupted.
@@ -442,16 +418,16 @@ export const withReadLock: {
442
418
  const [effect] = args
443
419
  return (self: TxReentrantLock) =>
444
420
  Effect.acquireUseRelease(
445
- Effect.transaction(acquireRead(self)),
421
+ acquireRead(self),
446
422
  () => effect,
447
- () => Effect.transaction(releaseRead(self))
423
+ () => releaseRead(self)
448
424
  )
449
425
  }
450
426
  const [self, effect] = args
451
427
  return Effect.acquireUseRelease(
452
- Effect.transaction(acquireRead(self)),
428
+ acquireRead(self),
453
429
  () => effect,
454
- () => Effect.transaction(releaseRead(self))
430
+ () => releaseRead(self)
455
431
  )
456
432
  }) as any
457
433
 
@@ -526,16 +502,16 @@ export const withWriteLock: {
526
502
  const [effect] = args
527
503
  return (self: TxReentrantLock) =>
528
504
  Effect.acquireUseRelease(
529
- Effect.transaction(acquireWrite(self)),
505
+ acquireWrite(self),
530
506
  () => effect,
531
- () => Effect.transaction(releaseWrite(self))
507
+ () => releaseWrite(self)
532
508
  )
533
509
  }
534
510
  const [self, effect] = args
535
511
  return Effect.acquireUseRelease(
536
- Effect.transaction(acquireWrite(self)),
512
+ acquireWrite(self),
537
513
  () => effect,
538
- () => Effect.transaction(releaseWrite(self))
514
+ () => releaseWrite(self)
539
515
  )
540
516
  }) as any
541
517
 
@@ -627,7 +603,7 @@ export const withLock: {
627
603
  * @since 4.0.0
628
604
  * @category getters
629
605
  */
630
- export const readLocks = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
606
+ export const readLocks = (self: TxReentrantLock): Effect.Effect<number> =>
631
607
  Effect.gen(function*() {
632
608
  const state = yield* TxRef.get(self.stateRef)
633
609
  let total = 0
@@ -654,7 +630,7 @@ export const readLocks = (self: TxReentrantLock): Effect.Effect<number, never, E
654
630
  * @since 4.0.0
655
631
  * @category getters
656
632
  */
657
- export const writeLocks = (self: TxReentrantLock): Effect.Effect<number, never, Effect.Transaction> =>
633
+ export const writeLocks = (self: TxReentrantLock): Effect.Effect<number> =>
658
634
  Effect.gen(function*() {
659
635
  const state = yield* TxRef.get(self.stateRef)
660
636
  return Option.isSome(state.writer) ? state.writer.value[1] : 0
@@ -677,7 +653,7 @@ export const writeLocks = (self: TxReentrantLock): Effect.Effect<number, never,
677
653
  * @since 4.0.0
678
654
  * @category getters
679
655
  */
680
- export const locked = (self: TxReentrantLock): Effect.Effect<boolean, never, Effect.Transaction> =>
656
+ export const locked = (self: TxReentrantLock): Effect.Effect<boolean> =>
681
657
  Effect.gen(function*() {
682
658
  const state = yield* TxRef.get(self.stateRef)
683
659
  return HashMap.size(state.readers) > 0 || Option.isSome(state.writer)
@@ -700,7 +676,7 @@ export const locked = (self: TxReentrantLock): Effect.Effect<boolean, never, Eff
700
676
  * @since 4.0.0
701
677
  * @category getters
702
678
  */
703
- export const readLocked = (self: TxReentrantLock): Effect.Effect<boolean, never, Effect.Transaction> =>
679
+ export const readLocked = (self: TxReentrantLock): Effect.Effect<boolean> =>
704
680
  Effect.gen(function*() {
705
681
  const state = yield* TxRef.get(self.stateRef)
706
682
  return HashMap.size(state.readers) > 0
@@ -723,7 +699,7 @@ export const readLocked = (self: TxReentrantLock): Effect.Effect<boolean, never,
723
699
  * @since 4.0.0
724
700
  * @category getters
725
701
  */
726
- export const writeLocked = (self: TxReentrantLock): Effect.Effect<boolean, never, Effect.Transaction> =>
702
+ export const writeLocked = (self: TxReentrantLock): Effect.Effect<boolean> =>
727
703
  Effect.gen(function*() {
728
704
  const state = yield* TxRef.get(self.stateRef)
729
705
  return Option.isSome(state.writer)
package/src/TxRef.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Accessed values are tracked by the transaction in order to detect conflicts and in order to
5
5
  * track changes, a transaction will retry whenever a conflict is detected or whenever the
6
- * transaction explicitely calls to `Effect.retryTransaction` and any of the accessed TxRef values
6
+ * transaction explicitely calls to `Effect.txRetry` and any of the accessed TxRef values
7
7
  * change.
8
8
  *
9
9
  * @since 4.0.0
@@ -21,7 +21,7 @@ const TypeId = "~effect/transactions/TxRef"
21
21
  *
22
22
  * Accessed values are tracked by the transaction in order to detect conflicts and in order to
23
23
  * track changes, a transaction will retry whenever a conflict is detected or whenever the
24
- * transaction explicitely calls to `Effect.retryTransaction` and any of the accessed TxRef values
24
+ * transaction explicitely calls to `Effect.txRetry` and any of the accessed TxRef values
25
25
  * change.
26
26
  *
27
27
  * @since 4.0.0
@@ -35,12 +35,12 @@ const TypeId = "~effect/transactions/TxRef"
35
35
  * const ref: TxRef.TxRef<number> = yield* TxRef.make(0)
36
36
  *
37
37
  * // Use within a transaction
38
- * yield* Effect.transaction(Effect.gen(function*() {
38
+ * yield* Effect.tx(Effect.gen(function*() {
39
39
  * const current = yield* TxRef.get(ref)
40
40
  * yield* TxRef.set(ref, current + 1)
41
41
  * }))
42
42
  *
43
- * const final = yield* Effect.transaction(TxRef.get(ref))
43
+ * const final = yield* TxRef.get(ref)
44
44
  * console.log(final) // 1
45
45
  * })
46
46
  * ```
@@ -64,28 +64,21 @@ export interface TxRef<in out A> extends Pipeable {
64
64
  *
65
65
  * const program = Effect.gen(function*() {
66
66
  * // Create a transactional reference with initial value
67
- * const counter = yield* Effect.transaction(TxRef.make(0))
68
- * const name = yield* Effect.transaction(TxRef.make("Alice"))
67
+ * const counter = yield* TxRef.make(0)
68
+ * const name = yield* TxRef.make("Alice")
69
69
  *
70
70
  * // Use in transactions
71
- * yield* Effect.transaction(Effect.gen(function*() {
71
+ * yield* Effect.tx(Effect.gen(function*() {
72
72
  * yield* TxRef.set(counter, 42)
73
73
  * yield* TxRef.set(name, "Bob")
74
74
  * }))
75
75
  *
76
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 42
77
- * console.log(yield* Effect.transaction(TxRef.get(name))) // "Bob"
76
+ * console.log(yield* TxRef.get(counter)) // 42
77
+ * console.log(yield* TxRef.get(name)) // "Bob"
78
78
  * })
79
79
  * ```
80
80
  */
81
- export const make = <A>(initial: A) =>
82
- Effect.withTxState((state) =>
83
- Effect.sync(() => {
84
- const ref = makeUnsafe(initial)
85
- state.journal.set(ref, { version: ref.version, value: ref.value })
86
- return ref
87
- })
88
- )
81
+ export const make = <A>(initial: A) => Effect.sync(() => makeUnsafe(initial))
89
82
 
90
83
  /**
91
84
  * Creates a new `TxRef` with the specified initial value.
@@ -128,12 +121,10 @@ export const makeUnsafe = <A>(initial: A): TxRef<A> => ({
128
121
  * const counter = yield* TxRef.make(0)
129
122
  *
130
123
  * // Modify and return both old and new value
131
- * const result = yield* Effect.transaction(
132
- * TxRef.modify(counter, (current) => [current * 2, current + 1])
133
- * )
124
+ * const result = yield* TxRef.modify(counter, (current) => [current * 2, current + 1])
134
125
  *
135
126
  * console.log(result) // 0 (the return value: current * 2)
136
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 1 (the new value: current + 1)
127
+ * console.log(yield* TxRef.get(counter)) // 1 (the new value: current + 1)
137
128
  * })
138
129
  * ```
139
130
  */
@@ -151,16 +142,14 @@ export const modify: {
151
142
  * const counter = yield* TxRef.make(0)
152
143
  *
153
144
  * // Modify and return both old and new value
154
- * const result = yield* Effect.transaction(
155
- * TxRef.modify(counter, (current) => [current * 2, current + 1])
156
- * )
145
+ * const result = yield* TxRef.modify(counter, (current) => [current * 2, current + 1])
157
146
  *
158
147
  * console.log(result) // 0 (the return value: current * 2)
159
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 1 (the new value: current + 1)
148
+ * console.log(yield* TxRef.get(counter)) // 1 (the new value: current + 1)
160
149
  * })
161
150
  * ```
162
151
  */
163
- <A, R>(f: (current: NoInfer<A>) => [returnValue: R, newValue: A]): (self: TxRef<A>) => Effect.Effect<R, never, Effect.Transaction>
152
+ <A, R>(f: (current: NoInfer<A>) => [returnValue: R, newValue: A]): (self: TxRef<A>) => Effect.Effect<R>
164
153
  /**
165
154
  * Modifies the value of the `TxRef` using the provided function.
166
155
  *
@@ -174,23 +163,20 @@ export const modify: {
174
163
  * const counter = yield* TxRef.make(0)
175
164
  *
176
165
  * // Modify and return both old and new value
177
- * const result = yield* Effect.transaction(
178
- * TxRef.modify(counter, (current) => [current * 2, current + 1])
179
- * )
166
+ * const result = yield* TxRef.modify(counter, (current) => [current * 2, current + 1])
180
167
  *
181
168
  * console.log(result) // 0 (the return value: current * 2)
182
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 1 (the new value: current + 1)
169
+ * console.log(yield* TxRef.get(counter)) // 1 (the new value: current + 1)
183
170
  * })
184
171
  * ```
185
172
  */
186
- <A, R>(self: TxRef<A>, f: (current: A) => [returnValue: R, newValue: A]): Effect.Effect<R, never, Effect.Transaction>
187
- } = dual(
188
- 2,
189
- <A, R>(
190
- self: TxRef<A>,
191
- f: (current: A) => [returnValue: R, newValue: A]
192
- ): Effect.Effect<R, never, Effect.Transaction> =>
193
- Effect.withTxState((state) =>
173
+ <A, R>(self: TxRef<A>, f: (current: A) => [returnValue: R, newValue: A]): Effect.Effect<R>
174
+ } = dual(2, <A, R>(
175
+ self: TxRef<A>,
176
+ f: (current: A) => [returnValue: R, newValue: A]
177
+ ): Effect.Effect<R> =>
178
+ Effect.Transaction.asEffect().pipe(
179
+ Effect.flatMap((state) =>
194
180
  Effect.sync(() => {
195
181
  if (!state.journal.has(self)) {
196
182
  state.journal.set(self, { version: self.version, value: self.value })
@@ -200,8 +186,9 @@ export const modify: {
200
186
  current.value = next
201
187
  return returnValue
202
188
  })
203
- )
204
- )
189
+ ),
190
+ Effect.tx
191
+ ))
205
192
 
206
193
  /**
207
194
  * Updates the value of the `TxRef` using the provided function.
@@ -216,11 +203,11 @@ export const modify: {
216
203
  * const counter = yield* TxRef.make(10)
217
204
  *
218
205
  * // Update the value using a function
219
- * yield* Effect.transaction(
206
+ * yield* Effect.tx(
220
207
  * TxRef.update(counter, (current) => current * 2)
221
208
  * )
222
209
  *
223
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 20
210
+ * console.log(yield* TxRef.get(counter)) // 20
224
211
  * })
225
212
  * ```
226
213
  */
@@ -238,15 +225,15 @@ export const update: {
238
225
  * const counter = yield* TxRef.make(10)
239
226
  *
240
227
  * // Update the value using a function
241
- * yield* Effect.transaction(
228
+ * yield* Effect.tx(
242
229
  * TxRef.update(counter, (current) => current * 2)
243
230
  * )
244
231
  *
245
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 20
232
+ * console.log(yield* TxRef.get(counter)) // 20
246
233
  * })
247
234
  * ```
248
235
  */
249
- <A>(f: (current: NoInfer<A>) => A): (self: TxRef<A>) => Effect.Effect<void, never, Effect.Transaction>
236
+ <A>(f: (current: NoInfer<A>) => A): (self: TxRef<A>) => Effect.Effect<void>
250
237
  /**
251
238
  * Updates the value of the `TxRef` using the provided function.
252
239
  *
@@ -260,20 +247,19 @@ export const update: {
260
247
  * const counter = yield* TxRef.make(10)
261
248
  *
262
249
  * // Update the value using a function
263
- * yield* Effect.transaction(
250
+ * yield* Effect.tx(
264
251
  * TxRef.update(counter, (current) => current * 2)
265
252
  * )
266
253
  *
267
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 20
254
+ * console.log(yield* TxRef.get(counter)) // 20
268
255
  * })
269
256
  * ```
270
257
  */
271
- <A>(self: TxRef<A>, f: (current: A) => A): Effect.Effect<void, never, Effect.Transaction>
272
- } = dual(
273
- 2,
274
- <A>(self: TxRef<A>, f: (current: A) => A): Effect.Effect<void, never, Effect.Transaction> =>
275
- modify(self, (current) => [void 0, f(current)])
276
- )
258
+ <A>(self: TxRef<A>, f: (current: A) => A): Effect.Effect<void>
259
+ } = dual(2, <A>(
260
+ self: TxRef<A>,
261
+ f: (current: A) => A
262
+ ): Effect.Effect<void> => modify(self, (current) => [void 0, f(current)]))
277
263
 
278
264
  /**
279
265
  * Reads the current value of the `TxRef`.
@@ -288,7 +274,7 @@ export const update: {
288
274
  * const counter = yield* TxRef.make(42)
289
275
  *
290
276
  * // Read the value within a transaction
291
- * const value = yield* Effect.transaction(
277
+ * const value = yield* Effect.tx(
292
278
  * TxRef.get(counter)
293
279
  * )
294
280
  *
@@ -296,8 +282,7 @@ export const update: {
296
282
  * })
297
283
  * ```
298
284
  */
299
- export const get = <A>(self: TxRef<A>): Effect.Effect<A, never, Effect.Transaction> =>
300
- modify(self, (current) => [current, current])
285
+ export const get = <A>(self: TxRef<A>): Effect.Effect<A> => modify(self, (current) => [current, current])
301
286
 
302
287
  /**
303
288
  * Sets the value of the `TxRef`.
@@ -312,11 +297,11 @@ export const get = <A>(self: TxRef<A>): Effect.Effect<A, never, Effect.Transacti
312
297
  * const counter = yield* TxRef.make(0)
313
298
  *
314
299
  * // Set a new value within a transaction
315
- * yield* Effect.transaction(
300
+ * yield* Effect.tx(
316
301
  * TxRef.set(counter, 100)
317
302
  * )
318
303
  *
319
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 100
304
+ * console.log(yield* TxRef.get(counter)) // 100
320
305
  * })
321
306
  * ```
322
307
  */
@@ -334,15 +319,15 @@ export const set: {
334
319
  * const counter = yield* TxRef.make(0)
335
320
  *
336
321
  * // Set a new value within a transaction
337
- * yield* Effect.transaction(
322
+ * yield* Effect.tx(
338
323
  * TxRef.set(counter, 100)
339
324
  * )
340
325
  *
341
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 100
326
+ * console.log(yield* TxRef.get(counter)) // 100
342
327
  * })
343
328
  * ```
344
329
  */
345
- <A>(value: A): (self: TxRef<A>) => Effect.Effect<void, never, Effect.Transaction>
330
+ <A>(value: A): (self: TxRef<A>) => Effect.Effect<void>
346
331
  /**
347
332
  * Sets the value of the `TxRef`.
348
333
  *
@@ -356,13 +341,16 @@ export const set: {
356
341
  * const counter = yield* TxRef.make(0)
357
342
  *
358
343
  * // Set a new value within a transaction
359
- * yield* Effect.transaction(
344
+ * yield* Effect.tx(
360
345
  * TxRef.set(counter, 100)
361
346
  * )
362
347
  *
363
- * console.log(yield* Effect.transaction(TxRef.get(counter))) // 100
348
+ * console.log(yield* TxRef.get(counter)) // 100
364
349
  * })
365
350
  * ```
366
351
  */
367
- <A>(self: TxRef<A>, value: A): Effect.Effect<void, never, Effect.Transaction>
368
- } = dual(2, <A>(self: TxRef<A>, value: A): Effect.Effect<void, never, Effect.Transaction> => update(self, () => value))
352
+ <A>(self: TxRef<A>, value: A): Effect.Effect<void>
353
+ } = dual(2, <A>(
354
+ self: TxRef<A>,
355
+ value: A
356
+ ): Effect.Effect<void> => update(self, () => value))
@@ -101,7 +101,7 @@ const makeTxSemaphore = (permitsRef: TxRef.TxRef<number>, capacity: number): TxS
101
101
  * @since 4.0.0
102
102
  * @category constructors
103
103
  */
104
- export const make = (permits: number): Effect.Effect<TxSemaphore, never, Effect.Transaction> =>
104
+ export const make = (permits: number): Effect.Effect<TxSemaphore> =>
105
105
  Effect.gen(function*() {
106
106
  if (permits < 0) {
107
107
  return yield* Effect.die(new Error("Permits must be non-negative"))
@@ -109,7 +109,7 @@ export const make = (permits: number): Effect.Effect<TxSemaphore, never, Effect.
109
109
 
110
110
  const permitsRef = yield* TxRef.make(permits)
111
111
  return makeTxSemaphore(permitsRef, permits)
112
- })
112
+ }).pipe(Effect.tx)
113
113
 
114
114
  /**
115
115
  * Gets the current number of available permits in the semaphore.
@@ -141,8 +141,7 @@ export const make = (permits: number): Effect.Effect<TxSemaphore, never, Effect.
141
141
  * @since 4.0.0
142
142
  * @category combinators
143
143
  */
144
- export const available = (self: TxSemaphore): Effect.Effect<number, never, Effect.Transaction> =>
145
- TxRef.get(self.permitsRef)
144
+ export const available = (self: TxSemaphore): Effect.Effect<number> => TxRef.get(self.permitsRef)
146
145
 
147
146
  /**
148
147
  * Gets the maximum capacity (total permits) of the semaphore.
@@ -202,14 +201,14 @@ export const capacity = (self: TxSemaphore): Effect.Effect<number> => Effect.suc
202
201
  * @since 4.0.0
203
202
  * @category combinators
204
203
  */
205
- export const acquire = (self: TxSemaphore): Effect.Effect<void, never, Effect.Transaction> =>
204
+ export const acquire = (self: TxSemaphore): Effect.Effect<void> =>
206
205
  Effect.gen(function*() {
207
206
  const permits = yield* TxRef.get(self.permitsRef)
208
207
  if (permits <= 0) {
209
- return yield* Effect.retryTransaction
208
+ return yield* Effect.txRetry
210
209
  }
211
210
  yield* TxRef.set(self.permitsRef, permits - 1)
212
- })
211
+ }).pipe(Effect.tx)
213
212
 
214
213
  /**
215
214
  * Acquires the specified number of permits from the semaphore. If not enough
@@ -238,17 +237,17 @@ export const acquire = (self: TxSemaphore): Effect.Effect<void, never, Effect.Tr
238
237
  * @since 4.0.0
239
238
  * @category combinators
240
239
  */
241
- export const acquireN = (self: TxSemaphore, n: number): Effect.Effect<void, never, Effect.Transaction> => {
240
+ export const acquireN = (self: TxSemaphore, n: number): Effect.Effect<void> => {
242
241
  if (n <= 0) {
243
242
  return Effect.die(new Error("Number of permits must be positive"))
244
243
  }
245
244
  return Effect.gen(function*() {
246
245
  const permits = yield* TxRef.get(self.permitsRef)
247
246
  if (permits < n) {
248
- return yield* Effect.retryTransaction
247
+ return yield* Effect.txRetry
249
248
  }
250
249
  yield* TxRef.set(self.permitsRef, permits - n)
251
- })
250
+ }).pipe(Effect.tx)
252
251
  }
253
252
 
254
253
  /**
@@ -278,7 +277,7 @@ export const acquireN = (self: TxSemaphore, n: number): Effect.Effect<void, neve
278
277
  * @since 4.0.0
279
278
  * @category combinators
280
279
  */
281
- export const tryAcquire = (self: TxSemaphore): Effect.Effect<boolean, never, Effect.Transaction> =>
280
+ export const tryAcquire = (self: TxSemaphore): Effect.Effect<boolean> =>
282
281
  TxRef.modify(self.permitsRef, (permits: number) => {
283
282
  if (permits > 0) {
284
283
  return [true, permits - 1]
@@ -314,7 +313,7 @@ export const tryAcquire = (self: TxSemaphore): Effect.Effect<boolean, never, Eff
314
313
  * @since 4.0.0
315
314
  * @category combinators
316
315
  */
317
- export const tryAcquireN = (self: TxSemaphore, n: number): Effect.Effect<boolean, never, Effect.Transaction> => {
316
+ export const tryAcquireN = (self: TxSemaphore, n: number): Effect.Effect<boolean> => {
318
317
  if (n <= 0) {
319
318
  return Effect.die(new Error("Number of permits must be positive"))
320
319
  }
@@ -354,7 +353,7 @@ export const tryAcquireN = (self: TxSemaphore, n: number): Effect.Effect<boolean
354
353
  * @since 4.0.0
355
354
  * @category combinators
356
355
  */
357
- export const release = (self: TxSemaphore): Effect.Effect<void, never, Effect.Transaction> =>
356
+ export const release = (self: TxSemaphore): Effect.Effect<void> =>
358
357
  TxRef.update(self.permitsRef, (permits: number) => permits >= self.capacity ? permits : permits + 1)
359
358
 
360
359
  /**
@@ -386,7 +385,7 @@ export const release = (self: TxSemaphore): Effect.Effect<void, never, Effect.Tr
386
385
  * @since 4.0.0
387
386
  * @category combinators
388
387
  */
389
- export const releaseN = (self: TxSemaphore, n: number): Effect.Effect<void, never, Effect.Transaction> => {
388
+ export const releaseN = (self: TxSemaphore, n: number): Effect.Effect<void> => {
390
389
  if (n <= 0) {
391
390
  return Effect.die(new Error("Number of permits must be positive"))
392
391
  }
@@ -518,16 +517,16 @@ export const withPermit: {
518
517
  const [self] = args
519
518
  return (effect: Effect.Effect<any, any, any>) =>
520
519
  Effect.acquireUseRelease(
521
- Effect.transaction(acquire(self)),
520
+ acquire(self),
522
521
  () => effect,
523
- () => Effect.transaction(release(self))
522
+ () => release(self)
524
523
  )
525
524
  }
526
525
  const [self, effect] = args
527
526
  return Effect.acquireUseRelease(
528
- Effect.transaction(acquire(self)),
527
+ acquire(self),
529
528
  () => effect,
530
- () => Effect.transaction(release(self))
529
+ () => release(self)
531
530
  )
532
531
  }) as any
533
532
 
@@ -656,16 +655,16 @@ export const withPermits: {
656
655
  const [self, n] = args
657
656
  return (effect: Effect.Effect<any, any, any>) =>
658
657
  Effect.acquireUseRelease(
659
- Effect.transaction(acquireN(self, n)),
658
+ acquireN(self, n),
660
659
  () => effect,
661
- () => Effect.transaction(releaseN(self, n))
660
+ () => releaseN(self, n)
662
661
  )
663
662
  }
664
663
  const [self, n, effect] = args
665
664
  return Effect.acquireUseRelease(
666
- Effect.transaction(acquireN(self, n)),
665
+ acquireN(self, n),
667
666
  () => effect,
668
- () => Effect.transaction(releaseN(self, n))
667
+ () => releaseN(self, n)
669
668
  )
670
669
  }) as any
671
670
 
@@ -710,8 +709,8 @@ export const withPermits: {
710
709
  */
711
710
  export const withPermitScoped = (self: TxSemaphore): Effect.Effect<void, never, Scope.Scope> =>
712
711
  Effect.acquireRelease(
713
- Effect.transaction(acquire(self)),
714
- () => Effect.transaction(release(self))
712
+ acquire(self),
713
+ () => release(self)
715
714
  )
716
715
 
717
716
  /**