effect 4.0.0-beta.41 → 4.0.0-beta.42

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 (92) 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/MutableList.d.ts.map +1 -1
  6. package/dist/MutableList.js +3 -0
  7. package/dist/MutableList.js.map +1 -1
  8. package/dist/Number.d.ts.map +1 -1
  9. package/dist/Number.js +12 -3
  10. package/dist/Number.js.map +1 -1
  11. package/dist/SchemaRepresentation.d.ts.map +1 -1
  12. package/dist/SchemaRepresentation.js +16 -14
  13. package/dist/SchemaRepresentation.js.map +1 -1
  14. package/dist/TxChunk.d.ts +39 -39
  15. package/dist/TxChunk.d.ts.map +1 -1
  16. package/dist/TxChunk.js +3 -3
  17. package/dist/TxChunk.js.map +1 -1
  18. package/dist/TxDeferred.d.ts +9 -9
  19. package/dist/TxDeferred.d.ts.map +1 -1
  20. package/dist/TxDeferred.js +2 -2
  21. package/dist/TxDeferred.js.map +1 -1
  22. package/dist/TxHashMap.d.ts +59 -59
  23. package/dist/TxHashMap.d.ts.map +1 -1
  24. package/dist/TxHashMap.js +8 -8
  25. package/dist/TxHashMap.js.map +1 -1
  26. package/dist/TxHashSet.d.ts +35 -35
  27. package/dist/TxHashSet.d.ts.map +1 -1
  28. package/dist/TxHashSet.js +7 -7
  29. package/dist/TxHashSet.js.map +1 -1
  30. package/dist/TxPriorityQueue.d.ts +23 -23
  31. package/dist/TxPriorityQueue.d.ts.map +1 -1
  32. package/dist/TxPriorityQueue.js +4 -4
  33. package/dist/TxPriorityQueue.js.map +1 -1
  34. package/dist/TxPubSub.d.ts +14 -14
  35. package/dist/TxPubSub.d.ts.map +1 -1
  36. package/dist/TxPubSub.js +12 -12
  37. package/dist/TxPubSub.js.map +1 -1
  38. package/dist/TxQueue.d.ts +33 -33
  39. package/dist/TxQueue.d.ts.map +1 -1
  40. package/dist/TxQueue.js +29 -44
  41. package/dist/TxQueue.js.map +1 -1
  42. package/dist/TxReentrantLock.d.ts +10 -33
  43. package/dist/TxReentrantLock.d.ts.map +1 -1
  44. package/dist/TxReentrantLock.js +14 -37
  45. package/dist/TxReentrantLock.js.map +1 -1
  46. package/dist/TxRef.d.ts +36 -42
  47. package/dist/TxRef.d.ts.map +1 -1
  48. package/dist/TxRef.js +16 -25
  49. package/dist/TxRef.js.map +1 -1
  50. package/dist/TxSemaphore.d.ts +8 -8
  51. package/dist/TxSemaphore.d.ts.map +1 -1
  52. package/dist/TxSemaphore.js +10 -10
  53. package/dist/TxSemaphore.js.map +1 -1
  54. package/dist/TxSubscriptionRef.d.ts +14 -14
  55. package/dist/TxSubscriptionRef.d.ts.map +1 -1
  56. package/dist/TxSubscriptionRef.js +5 -5
  57. package/dist/TxSubscriptionRef.js.map +1 -1
  58. package/dist/index.d.ts +3 -3
  59. package/dist/index.js +3 -3
  60. package/dist/unstable/ai/OpenAiStructuredOutput.js +3 -0
  61. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  62. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  63. package/dist/unstable/cli/internal/command.js +12 -1
  64. package/dist/unstable/cli/internal/command.js.map +1 -1
  65. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  66. package/dist/unstable/cluster/SqlMessageStorage.js +1 -4
  67. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  68. package/dist/unstable/socket/Socket.d.ts +1 -1
  69. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  70. package/dist/unstable/socket/Socket.js +1 -1
  71. package/dist/unstable/socket/Socket.js.map +1 -1
  72. package/package.json +1 -1
  73. package/src/Effect.ts +24 -75
  74. package/src/MutableList.ts +3 -0
  75. package/src/Number.ts +13 -3
  76. package/src/SchemaRepresentation.ts +8 -6
  77. package/src/TxChunk.ts +53 -62
  78. package/src/TxDeferred.ts +14 -17
  79. package/src/TxHashMap.ts +91 -101
  80. package/src/TxHashSet.ts +68 -70
  81. package/src/TxPriorityQueue.ts +34 -38
  82. package/src/TxPubSub.ts +30 -32
  83. package/src/TxQueue.ts +70 -84
  84. package/src/TxReentrantLock.ts +30 -54
  85. package/src/TxRef.ts +53 -65
  86. package/src/TxSemaphore.ts +23 -24
  87. package/src/TxSubscriptionRef.ts +25 -27
  88. package/src/index.ts +3 -3
  89. package/src/unstable/ai/OpenAiStructuredOutput.ts +3 -0
  90. package/src/unstable/cli/internal/command.ts +16 -1
  91. package/src/unstable/cluster/SqlMessageStorage.ts +0 -4
  92. package/src/unstable/socket/Socket.ts +1 -1
package/dist/Effect.d.ts CHANGED
@@ -17620,93 +17620,49 @@ declare const Transaction_base: ServiceMap.ServiceClass<Transaction, "effect/Eff
17620
17620
  */
17621
17621
  export declare class Transaction extends Transaction_base {
17622
17622
  }
17623
- /**
17624
- * Accesses the current transaction state within an active transaction.
17625
- *
17626
- * This function requires `Transaction` in the context and does NOT create or strip
17627
- * transaction boundaries. Use it to interact with the transaction journal (e.g. in
17628
- * `TxRef` internals). To define a transaction boundary, use {@link transaction}.
17629
- *
17630
- * @example
17631
- * ```ts
17632
- * import { Effect, TxRef } from "effect"
17633
- *
17634
- * const program = Effect.gen(function*() {
17635
- * const ref = yield* Effect.transaction(TxRef.make(0))
17636
- *
17637
- * yield* Effect.transaction(Effect.gen(function*() {
17638
- * yield* TxRef.set(ref, 42)
17639
- * return yield* TxRef.get(ref)
17640
- * }))
17641
- * })
17642
- * ```
17643
- *
17644
- * @since 4.0.0
17645
- * @category Transactions
17646
- */
17647
- export declare const withTxState: <A, E, R>(f: (state: Transaction["Service"]) => Effect<A, E, R>) => Effect<A, E, R | Transaction>;
17648
17623
  /**
17649
17624
  * Defines a transaction boundary. Transactions are "all or nothing" with respect to changes
17650
17625
  * made to transactional values (i.e. TxRef) that occur within the transaction body.
17651
17626
  *
17627
+ * If called inside an active transaction, `tx` composes with the current transaction and reuses
17628
+ * its journal and retry state instead of creating a nested boundary.
17629
+ *
17652
17630
  * In Effect transactions are optimistic with retry, that means transactions are retried when:
17653
17631
  *
17654
- * - the body of the transaction explicitely calls to `Effect.retryTransaction` and any of the
17632
+ * - the body of the transaction explicitely calls to `Effect.txRetry` and any of the
17655
17633
  * accessed transactional values changes.
17656
17634
  *
17657
17635
  * - any of the accessed transactional values change during the execution of the transaction
17658
17636
  * due to a different transaction committing before the current.
17659
17637
  *
17660
- * Each call to `transaction` always creates a new isolated transaction boundary with its own
17661
- * journal and retry logic.
17638
+ * The outermost `tx` call creates the transaction boundary and commits or rolls back the full
17639
+ * composed transaction.
17662
17640
  *
17663
17641
  * @example
17664
17642
  * ```ts
17665
17643
  * import { Effect, TxRef } from "effect"
17666
17644
  *
17667
17645
  * const program = Effect.gen(function*() {
17668
- * const ref1 = yield* Effect.transaction(TxRef.make(0))
17669
- * const ref2 = yield* Effect.transaction(TxRef.make(0))
17646
+ * const ref1 = yield* TxRef.make(0)
17647
+ * const ref2 = yield* TxRef.make(0)
17670
17648
  *
17671
- * // All operations within transaction block succeed or fail together
17672
- * yield* Effect.transaction(Effect.gen(function*() {
17649
+ * // Nested tx calls compose into the same transaction
17650
+ * yield* Effect.tx(Effect.gen(function*() {
17673
17651
  * yield* TxRef.set(ref1, 10)
17674
- * yield* TxRef.set(ref2, 20)
17652
+ * yield* Effect.tx(TxRef.set(ref2, 20))
17675
17653
  * const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
17676
17654
  * console.log(`Transaction sum: ${sum}`)
17677
17655
  * }))
17678
17656
  *
17679
- * console.log(`Final ref1: ${yield* Effect.transaction(TxRef.get(ref1))}`) // 10
17680
- * console.log(`Final ref2: ${yield* Effect.transaction(TxRef.get(ref2))}`) // 20
17657
+ * console.log(`Final ref1: ${yield* TxRef.get(ref1)}`) // 10
17658
+ * console.log(`Final ref2: ${yield* TxRef.get(ref2)}`) // 20
17681
17659
  * })
17682
17660
  * ```
17683
17661
  *
17684
17662
  * @since 4.0.0
17685
17663
  * @category Transactions
17686
17664
  */
17687
- export declare const transaction: <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, Exclude<R, Transaction>>;
17688
- /**
17689
- * Like {@link transaction} but provides access to the transaction state.
17690
- *
17691
- * Always creates a new isolated transaction boundary with its own journal and retry logic.
17692
- *
17693
- * @example
17694
- * ```ts
17695
- * import { Effect, TxRef } from "effect"
17696
- *
17697
- * const program = Effect.transactionWith((_txState) =>
17698
- * Effect.gen(function*() {
17699
- * const ref = yield* TxRef.make(0)
17700
- * yield* TxRef.set(ref, 42)
17701
- * return yield* TxRef.get(ref)
17702
- * })
17703
- * )
17704
- * ```
17705
- *
17706
- * @since 4.0.0
17707
- * @category Transactions
17708
- */
17709
- export declare const transactionWith: <A, E, R>(f: (state: Transaction["Service"]) => Effect<A, E, R>) => Effect<A, E, Exclude<R, Transaction>>;
17665
+ export declare const tx: <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, Exclude<R, Transaction>>;
17710
17666
  /**
17711
17667
  * Signals that the current transaction needs to be retried.
17712
17668
  *
@@ -17722,20 +17678,20 @@ export declare const transactionWith: <A, E, R>(f: (state: Transaction["Service"
17722
17678
  *
17723
17679
  * const program = Effect.gen(function*() {
17724
17680
  * // create a transactional reference
17725
- * const ref = yield* Effect.transaction(TxRef.make(0))
17681
+ * const ref = yield* TxRef.make(0)
17726
17682
  *
17727
17683
  * // forks a fiber that increases the value of `ref` every 100 millis
17728
17684
  * yield* Effect.forkChild(Effect.forever(
17729
17685
  * // update to transactional value
17730
- * Effect.transaction(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
17686
+ * Effect.tx(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
17731
17687
  * ))
17732
17688
  *
17733
17689
  * // the following will retry 10 times until the `ref` value is 10
17734
- * yield* Effect.transaction(Effect.gen(function*() {
17690
+ * yield* Effect.tx(Effect.gen(function*() {
17735
17691
  * const value = yield* TxRef.get(ref)
17736
17692
  * if (value < 10) {
17737
17693
  * yield* Effect.log(`retry due to value: ${value}`)
17738
- * return yield* Effect.retryTransaction
17694
+ * return yield* Effect.txRetry
17739
17695
  * }
17740
17696
  * yield* Effect.log(`transaction done with value: ${value}`)
17741
17697
  * }))
@@ -17744,7 +17700,7 @@ export declare const transactionWith: <A, E, R>(f: (state: Transaction["Service"
17744
17700
  * Effect.runPromise(program).catch(console.error)
17745
17701
  * ```
17746
17702
  */
17747
- export declare const retryTransaction: Effect<never, never, Transaction>;
17703
+ export declare const txRetry: Effect<never, never, Transaction>;
17748
17704
  /**
17749
17705
  * @since 4.0.0
17750
17706
  * @category Effectify