effect 4.0.0-beta.16 → 4.0.0-beta.18
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.
- package/dist/Effect.d.ts +33 -101
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +33 -108
- package/dist/Effect.js.map +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -2
- package/dist/Schema.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +196 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +59 -59
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +16 -16
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +14 -14
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +415 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +7 -7
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +0 -9
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +1 -1
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/package.json +1 -1
- package/src/Effect.ts +38 -117
- package/src/Schema.ts +3 -2
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +307 -261
- package/src/TxHashSet.ts +111 -116
- package/src/TxPriorityQueue.ts +767 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +29 -32
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/index.ts +45 -0
- package/src/unstable/ai/Tool.ts +0 -9
- package/src/unstable/cli/Command.ts +4 -2
package/dist/Effect.d.ts
CHANGED
|
@@ -17427,118 +17427,63 @@ declare const Transaction_base: ServiceMap.ServiceClass<Transaction, "effect/Eff
|
|
|
17427
17427
|
export declare class Transaction extends Transaction_base {
|
|
17428
17428
|
}
|
|
17429
17429
|
/**
|
|
17430
|
-
*
|
|
17431
|
-
* transactional values (i.e. TxRef) that occur within the transaction body.
|
|
17430
|
+
* Accesses the current transaction state within an active transaction.
|
|
17432
17431
|
*
|
|
17433
|
-
*
|
|
17434
|
-
*
|
|
17435
|
-
*
|
|
17436
|
-
* accessed transactional values changes.
|
|
17437
|
-
*
|
|
17438
|
-
* - any of the accessed transactional values change during the execution of the transaction
|
|
17439
|
-
* due to a different transaction committing before the current.
|
|
17440
|
-
*
|
|
17441
|
-
* - parent transaction retry, if you have a transaction within another transaction and
|
|
17442
|
-
* the parent retries the child will also retry together with the parent.
|
|
17432
|
+
* This function requires `Transaction` in the context and does NOT create or strip
|
|
17433
|
+
* transaction boundaries. Use it to interact with the transaction journal (e.g. in
|
|
17434
|
+
* `TxRef` internals). To define a transaction boundary, use {@link transaction}.
|
|
17443
17435
|
*
|
|
17444
17436
|
* @example
|
|
17445
17437
|
* ```ts
|
|
17446
17438
|
* import { Effect, TxRef } from "effect"
|
|
17447
17439
|
*
|
|
17448
17440
|
* const program = Effect.gen(function*() {
|
|
17449
|
-
* const
|
|
17450
|
-
* const ref2 = yield* TxRef.make(0)
|
|
17451
|
-
*
|
|
17452
|
-
* // All operations within atomic block succeed or fail together
|
|
17453
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
17454
|
-
* yield* TxRef.set(ref1, 10)
|
|
17455
|
-
* yield* TxRef.set(ref2, 20)
|
|
17456
|
-
* const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
|
|
17457
|
-
* console.log(`Transaction sum: ${sum}`)
|
|
17458
|
-
* }))
|
|
17459
|
-
*
|
|
17460
|
-
* console.log(`Final ref1: ${yield* TxRef.get(ref1)}`) // 10
|
|
17461
|
-
* console.log(`Final ref2: ${yield* TxRef.get(ref2)}`) // 20
|
|
17462
|
-
* })
|
|
17463
|
-
* ```
|
|
17464
|
-
*
|
|
17465
|
-
* @since 4.0.0
|
|
17466
|
-
* @category Transactions
|
|
17467
|
-
*/
|
|
17468
|
-
export declare const atomic: <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, Exclude<R, Transaction>>;
|
|
17469
|
-
/**
|
|
17470
|
-
* Executes a function within a transaction context, providing access to the transaction state.
|
|
17471
|
-
*
|
|
17472
|
-
* @example
|
|
17473
|
-
* ```ts
|
|
17474
|
-
* import { Effect, TxRef } from "effect"
|
|
17475
|
-
*
|
|
17476
|
-
* const program = Effect.atomicWith((txState) =>
|
|
17477
|
-
* Effect.gen(function*() {
|
|
17478
|
-
* const ref = yield* TxRef.make(0)
|
|
17479
|
-
*
|
|
17480
|
-
* // Access transaction state for debugging
|
|
17481
|
-
* console.log(`Journal size: ${txState.journal.size}`)
|
|
17482
|
-
* console.log(`Retry flag: ${txState.retry}`)
|
|
17441
|
+
* const ref = yield* Effect.transaction(TxRef.make(0))
|
|
17483
17442
|
*
|
|
17443
|
+
* yield* Effect.transaction(Effect.gen(function*() {
|
|
17484
17444
|
* yield* TxRef.set(ref, 42)
|
|
17485
17445
|
* return yield* TxRef.get(ref)
|
|
17486
|
-
* })
|
|
17487
|
-
* )
|
|
17488
|
-
*
|
|
17489
|
-
* Effect.runPromise(program).then(console.log) // 42
|
|
17446
|
+
* }))
|
|
17447
|
+
* })
|
|
17490
17448
|
* ```
|
|
17491
17449
|
*
|
|
17492
17450
|
* @since 4.0.0
|
|
17493
17451
|
* @category Transactions
|
|
17494
17452
|
*/
|
|
17495
|
-
export declare const
|
|
17453
|
+
export declare const withTxState: <A, E, R>(f: (state: Transaction["Service"]) => Effect<A, E, R>) => Effect<A, E, R | Transaction>;
|
|
17496
17454
|
/**
|
|
17497
|
-
*
|
|
17455
|
+
* Defines a transaction boundary. Transactions are "all or nothing" with respect to changes
|
|
17456
|
+
* made to transactional values (i.e. TxRef) that occur within the transaction body.
|
|
17498
17457
|
*
|
|
17499
|
-
*
|
|
17458
|
+
* In Effect transactions are optimistic with retry, that means transactions are retried when:
|
|
17500
17459
|
*
|
|
17501
|
-
*
|
|
17502
|
-
*
|
|
17503
|
-
* This ensures complete isolation between different transaction scopes.
|
|
17460
|
+
* - the body of the transaction explicitely calls to `Effect.retryTransaction` and any of the
|
|
17461
|
+
* accessed transactional values changes.
|
|
17504
17462
|
*
|
|
17505
|
-
*
|
|
17506
|
-
*
|
|
17507
|
-
* - Parent transaction failures don't affect isolated transactions
|
|
17508
|
-
* - Isolated transaction failures don't affect parent transactions
|
|
17509
|
-
* - Each transaction has its own journal and retry logic
|
|
17463
|
+
* - any of the accessed transactional values change during the execution of the transaction
|
|
17464
|
+
* due to a different transaction committing before the current.
|
|
17510
17465
|
*
|
|
17511
|
-
*
|
|
17512
|
-
*
|
|
17513
|
-
* - For implementing independent operations that shouldn't be affected by outer transactions
|
|
17514
|
-
* - When building transaction-based systems where isolation is critical
|
|
17466
|
+
* Each call to `transaction` always creates a new isolated transaction boundary with its own
|
|
17467
|
+
* journal and retry logic.
|
|
17515
17468
|
*
|
|
17516
17469
|
* @example
|
|
17517
17470
|
* ```ts
|
|
17518
17471
|
* import { Effect, TxRef } from "effect"
|
|
17519
17472
|
*
|
|
17520
17473
|
* const program = Effect.gen(function*() {
|
|
17521
|
-
* const ref1 = yield* TxRef.make(0)
|
|
17522
|
-
* const ref2 = yield* TxRef.make(
|
|
17523
|
-
*
|
|
17524
|
-
* // Nested atomic transaction - ref1 will be part of outer transaction
|
|
17525
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
17526
|
-
* yield* TxRef.set(ref1, 10)
|
|
17527
|
-
*
|
|
17528
|
-
* // This atomic operation composes with the parent
|
|
17529
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
17530
|
-
* yield* TxRef.set(ref1, 20) // Part of same transaction
|
|
17531
|
-
* }))
|
|
17532
|
-
* }))
|
|
17474
|
+
* const ref1 = yield* Effect.transaction(TxRef.make(0))
|
|
17475
|
+
* const ref2 = yield* Effect.transaction(TxRef.make(0))
|
|
17533
17476
|
*
|
|
17534
|
-
* //
|
|
17477
|
+
* // All operations within transaction block succeed or fail together
|
|
17535
17478
|
* yield* Effect.transaction(Effect.gen(function*() {
|
|
17536
|
-
* yield* TxRef.set(
|
|
17479
|
+
* yield* TxRef.set(ref1, 10)
|
|
17480
|
+
* yield* TxRef.set(ref2, 20)
|
|
17481
|
+
* const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
|
|
17482
|
+
* console.log(`Transaction sum: ${sum}`)
|
|
17537
17483
|
* }))
|
|
17538
17484
|
*
|
|
17539
|
-
*
|
|
17540
|
-
*
|
|
17541
|
-
* return { ref1: val1, ref2: val2 }
|
|
17485
|
+
* console.log(`Final ref1: ${yield* Effect.transaction(TxRef.get(ref1))}`) // 10
|
|
17486
|
+
* console.log(`Final ref2: ${yield* Effect.transaction(TxRef.get(ref2))}`) // 20
|
|
17542
17487
|
* })
|
|
17543
17488
|
* ```
|
|
17544
17489
|
*
|
|
@@ -17547,34 +17492,21 @@ export declare const atomicWith: <A, E, R>(f: (state: Transaction["Service"]) =>
|
|
|
17547
17492
|
*/
|
|
17548
17493
|
export declare const transaction: <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, Exclude<R, Transaction>>;
|
|
17549
17494
|
/**
|
|
17550
|
-
*
|
|
17495
|
+
* Like {@link transaction} but provides access to the transaction state.
|
|
17551
17496
|
*
|
|
17552
|
-
*
|
|
17553
|
-
* within another transaction. This ensures complete isolation between transaction scopes.
|
|
17497
|
+
* Always creates a new isolated transaction boundary with its own journal and retry logic.
|
|
17554
17498
|
*
|
|
17555
17499
|
* @example
|
|
17556
17500
|
* ```ts
|
|
17557
17501
|
* import { Effect, TxRef } from "effect"
|
|
17558
17502
|
*
|
|
17559
|
-
* const program = Effect.transactionWith((
|
|
17503
|
+
* const program = Effect.transactionWith((_txState) =>
|
|
17560
17504
|
* Effect.gen(function*() {
|
|
17561
17505
|
* const ref = yield* TxRef.make(0)
|
|
17562
|
-
*
|
|
17563
|
-
* // This transaction is isolated - it has its own journal
|
|
17564
|
-
* // txState.journal is independent of any parent transaction
|
|
17565
|
-
*
|
|
17566
17506
|
* yield* TxRef.set(ref, 42)
|
|
17567
17507
|
* return yield* TxRef.get(ref)
|
|
17568
17508
|
* })
|
|
17569
17509
|
* )
|
|
17570
|
-
*
|
|
17571
|
-
* // Even when nested in another atomic block, this transaction is isolated
|
|
17572
|
-
* const nestedProgram = Effect.atomic(
|
|
17573
|
-
* Effect.gen(function*() {
|
|
17574
|
-
* const result = yield* program // Runs in its own isolated transaction
|
|
17575
|
-
* return result
|
|
17576
|
-
* })
|
|
17577
|
-
* )
|
|
17578
17510
|
* ```
|
|
17579
17511
|
*
|
|
17580
17512
|
* @since 4.0.0
|
|
@@ -17596,16 +17528,16 @@ export declare const transactionWith: <A, E, R>(f: (state: Transaction["Service"
|
|
|
17596
17528
|
*
|
|
17597
17529
|
* const program = Effect.gen(function*() {
|
|
17598
17530
|
* // create a transactional reference
|
|
17599
|
-
* const ref = yield* TxRef.make(0)
|
|
17531
|
+
* const ref = yield* Effect.transaction(TxRef.make(0))
|
|
17600
17532
|
*
|
|
17601
17533
|
* // forks a fiber that increases the value of `ref` every 100 millis
|
|
17602
17534
|
* yield* Effect.forkChild(Effect.forever(
|
|
17603
17535
|
* // update to transactional value
|
|
17604
|
-
* TxRef.update(ref, (n) => n + 1).pipe(Effect.delay("100 millis"))
|
|
17536
|
+
* Effect.transaction(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
|
|
17605
17537
|
* ))
|
|
17606
17538
|
*
|
|
17607
17539
|
* // the following will retry 10 times until the `ref` value is 10
|
|
17608
|
-
* yield* Effect.
|
|
17540
|
+
* yield* Effect.transaction(Effect.gen(function*() {
|
|
17609
17541
|
* const value = yield* TxRef.get(ref)
|
|
17610
17542
|
* if (value < 10) {
|
|
17611
17543
|
* yield* Effect.log(`retry due to value: ${value}`)
|