effect 4.0.0-beta.40 → 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.
- package/dist/BigDecimal.d.ts +36 -0
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +52 -0
- package/dist/BigDecimal.js.map +1 -1
- package/dist/Effect.d.ts +20 -63
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +24 -65
- package/dist/Effect.js.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/Layer.js.map +1 -1
- package/dist/ManagedRuntime.d.ts.map +1 -1
- package/dist/ManagedRuntime.js +19 -7
- package/dist/ManagedRuntime.js.map +1 -1
- package/dist/MutableList.d.ts.map +1 -1
- package/dist/MutableList.js +3 -0
- package/dist/MutableList.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +12 -3
- package/dist/Number.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +16 -14
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ServiceMap.d.ts +14 -26
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +6 -5
- package/dist/ServiceMap.js.map +1 -1
- package/dist/TxChunk.d.ts +39 -39
- 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 +9 -9
- package/dist/TxDeferred.d.ts.map +1 -1
- package/dist/TxDeferred.js +2 -2
- package/dist/TxDeferred.js.map +1 -1
- package/dist/TxHashMap.d.ts +59 -59
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +8 -8
- 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 +7 -7
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +23 -23
- package/dist/TxPriorityQueue.d.ts.map +1 -1
- package/dist/TxPriorityQueue.js +4 -4
- package/dist/TxPriorityQueue.js.map +1 -1
- package/dist/TxPubSub.d.ts +14 -14
- package/dist/TxPubSub.d.ts.map +1 -1
- package/dist/TxPubSub.js +12 -12
- package/dist/TxPubSub.js.map +1 -1
- package/dist/TxQueue.d.ts +33 -33
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +29 -44
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +10 -33
- package/dist/TxReentrantLock.d.ts.map +1 -1
- package/dist/TxReentrantLock.js +14 -37
- package/dist/TxReentrantLock.js.map +1 -1
- package/dist/TxRef.d.ts +36 -42
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +16 -25
- 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 +10 -10
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +14 -14
- package/dist/TxSubscriptionRef.d.ts.map +1 -1
- package/dist/TxSubscriptionRef.js +5 -5
- package/dist/TxSubscriptionRef.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/internal/effect.js +3 -0
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/representation.js +28 -0
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +31 -2
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +68 -6
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +88 -11
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js +3 -0
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +1 -1
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +12 -1
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.d.ts +18 -0
- package/dist/unstable/cluster/ClusterSchema.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterSchema.js +21 -1
- package/dist/unstable/cluster/ClusterSchema.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +6 -3
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js +1 -0
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +4 -2
- package/dist/unstable/cluster/Message.d.ts.map +1 -1
- package/dist/unstable/cluster/Message.js +13 -6
- package/dist/unstable/cluster/Message.js.map +1 -1
- package/dist/unstable/cluster/MessageStorage.d.ts +23 -0
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +22 -7
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +24 -20
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +3 -1
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +10 -4
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/http/index.d.ts +2 -2
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +2 -2
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +1 -3
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -0
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -0
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +43 -26
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +1 -1
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +5 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +13 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +54 -0
- package/src/Effect.ts +25 -75
- package/src/Layer.ts +1 -1
- package/src/ManagedRuntime.ts +33 -20
- package/src/MutableList.ts +3 -0
- package/src/Number.ts +13 -3
- package/src/SchemaRepresentation.ts +8 -6
- package/src/ServiceMap.ts +16 -31
- package/src/TxChunk.ts +53 -62
- package/src/TxDeferred.ts +14 -17
- package/src/TxHashMap.ts +91 -101
- package/src/TxHashSet.ts +68 -70
- package/src/TxPriorityQueue.ts +34 -38
- package/src/TxPubSub.ts +30 -32
- package/src/TxQueue.ts +70 -84
- package/src/TxReentrantLock.ts +30 -54
- package/src/TxRef.ts +53 -65
- package/src/TxSemaphore.ts +23 -24
- package/src/TxSubscriptionRef.ts +25 -27
- package/src/index.ts +6 -6
- package/src/internal/effect.ts +3 -0
- package/src/internal/schema/representation.ts +28 -0
- package/src/unstable/ai/Chat.ts +79 -18
- package/src/unstable/ai/LanguageModel.ts +182 -66
- package/src/unstable/ai/OpenAiStructuredOutput.ts +3 -0
- package/src/unstable/cli/Prompt.ts +3 -1
- package/src/unstable/cli/internal/command.ts +16 -1
- package/src/unstable/cluster/ClusterSchema.ts +29 -1
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +22 -3
- package/src/unstable/cluster/Entity.ts +1 -0
- package/src/unstable/cluster/Message.ts +22 -10
- package/src/unstable/cluster/MessageStorage.ts +37 -6
- package/src/unstable/cluster/Sharding.ts +31 -23
- package/src/unstable/cluster/SqlMessageStorage.ts +6 -1
- package/src/unstable/cluster/internal/entityManager.ts +14 -5
- package/src/unstable/http/index.ts +2 -2
- package/src/unstable/httpapi/HttpApiSchema.ts +1 -1
- package/src/unstable/httpapi/OpenApi.ts +1 -0
- package/src/unstable/rpc/Rpc.ts +1 -0
- package/src/unstable/rpc/RpcClient.ts +45 -33
- package/src/unstable/socket/Socket.ts +1 -1
- package/src/unstable/workflow/Activity.ts +23 -0
package/src/Effect.ts
CHANGED
|
@@ -15966,6 +15966,7 @@ export interface RunOptions {
|
|
|
15966
15966
|
readonly signal?: AbortSignal | undefined
|
|
15967
15967
|
readonly scheduler?: Scheduler | undefined
|
|
15968
15968
|
readonly uninterruptible?: boolean | undefined
|
|
15969
|
+
readonly onFiberStart?: ((fiber: Fiber<unknown, unknown>) => void) | undefined
|
|
15969
15970
|
}
|
|
15970
15971
|
|
|
15971
15972
|
/**
|
|
@@ -22603,107 +22604,56 @@ export class Transaction extends ServiceMap.Service<
|
|
|
22603
22604
|
}
|
|
22604
22605
|
>()("effect/Effect/Transaction") {}
|
|
22605
22606
|
|
|
22606
|
-
/**
|
|
22607
|
-
* Accesses the current transaction state within an active transaction.
|
|
22608
|
-
*
|
|
22609
|
-
* This function requires `Transaction` in the context and does NOT create or strip
|
|
22610
|
-
* transaction boundaries. Use it to interact with the transaction journal (e.g. in
|
|
22611
|
-
* `TxRef` internals). To define a transaction boundary, use {@link transaction}.
|
|
22612
|
-
*
|
|
22613
|
-
* @example
|
|
22614
|
-
* ```ts
|
|
22615
|
-
* import { Effect, TxRef } from "effect"
|
|
22616
|
-
*
|
|
22617
|
-
* const program = Effect.gen(function*() {
|
|
22618
|
-
* const ref = yield* Effect.transaction(TxRef.make(0))
|
|
22619
|
-
*
|
|
22620
|
-
* yield* Effect.transaction(Effect.gen(function*() {
|
|
22621
|
-
* yield* TxRef.set(ref, 42)
|
|
22622
|
-
* return yield* TxRef.get(ref)
|
|
22623
|
-
* }))
|
|
22624
|
-
* })
|
|
22625
|
-
* ```
|
|
22626
|
-
*
|
|
22627
|
-
* @since 4.0.0
|
|
22628
|
-
* @category Transactions
|
|
22629
|
-
*/
|
|
22630
|
-
export const withTxState = <A, E, R>(
|
|
22631
|
-
f: (state: Transaction["Service"]) => Effect<A, E, R>
|
|
22632
|
-
): Effect<A, E, R | Transaction> =>
|
|
22633
|
-
flatMap(
|
|
22634
|
-
Transaction.asEffect(),
|
|
22635
|
-
(state) => internalCall(() => f(state))
|
|
22636
|
-
)
|
|
22637
|
-
|
|
22638
22607
|
/**
|
|
22639
22608
|
* Defines a transaction boundary. Transactions are "all or nothing" with respect to changes
|
|
22640
22609
|
* made to transactional values (i.e. TxRef) that occur within the transaction body.
|
|
22641
22610
|
*
|
|
22611
|
+
* If called inside an active transaction, `tx` composes with the current transaction and reuses
|
|
22612
|
+
* its journal and retry state instead of creating a nested boundary.
|
|
22613
|
+
*
|
|
22642
22614
|
* In Effect transactions are optimistic with retry, that means transactions are retried when:
|
|
22643
22615
|
*
|
|
22644
|
-
* - the body of the transaction explicitely calls to `Effect.
|
|
22616
|
+
* - the body of the transaction explicitely calls to `Effect.txRetry` and any of the
|
|
22645
22617
|
* accessed transactional values changes.
|
|
22646
22618
|
*
|
|
22647
22619
|
* - any of the accessed transactional values change during the execution of the transaction
|
|
22648
22620
|
* due to a different transaction committing before the current.
|
|
22649
22621
|
*
|
|
22650
|
-
*
|
|
22651
|
-
*
|
|
22622
|
+
* The outermost `tx` call creates the transaction boundary and commits or rolls back the full
|
|
22623
|
+
* composed transaction.
|
|
22652
22624
|
*
|
|
22653
22625
|
* @example
|
|
22654
22626
|
* ```ts
|
|
22655
22627
|
* import { Effect, TxRef } from "effect"
|
|
22656
22628
|
*
|
|
22657
22629
|
* const program = Effect.gen(function*() {
|
|
22658
|
-
* const ref1 = yield*
|
|
22659
|
-
* const ref2 = yield*
|
|
22630
|
+
* const ref1 = yield* TxRef.make(0)
|
|
22631
|
+
* const ref2 = yield* TxRef.make(0)
|
|
22660
22632
|
*
|
|
22661
|
-
* //
|
|
22662
|
-
* yield* Effect.
|
|
22633
|
+
* // Nested tx calls compose into the same transaction
|
|
22634
|
+
* yield* Effect.tx(Effect.gen(function*() {
|
|
22663
22635
|
* yield* TxRef.set(ref1, 10)
|
|
22664
|
-
* yield* TxRef.set(ref2, 20)
|
|
22636
|
+
* yield* Effect.tx(TxRef.set(ref2, 20))
|
|
22665
22637
|
* const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
|
|
22666
22638
|
* console.log(`Transaction sum: ${sum}`)
|
|
22667
22639
|
* }))
|
|
22668
22640
|
*
|
|
22669
|
-
* console.log(`Final ref1: ${yield*
|
|
22670
|
-
* console.log(`Final ref2: ${yield*
|
|
22641
|
+
* console.log(`Final ref1: ${yield* TxRef.get(ref1)}`) // 10
|
|
22642
|
+
* console.log(`Final ref2: ${yield* TxRef.get(ref2)}`) // 20
|
|
22671
22643
|
* })
|
|
22672
22644
|
* ```
|
|
22673
22645
|
*
|
|
22674
22646
|
* @since 4.0.0
|
|
22675
22647
|
* @category Transactions
|
|
22676
22648
|
*/
|
|
22677
|
-
export const
|
|
22649
|
+
export const tx = <A, E, R>(
|
|
22678
22650
|
effect: Effect<A, E, R>
|
|
22679
|
-
): Effect<A, E, Exclude<R, Transaction>> => transactionWith(() => effect)
|
|
22680
|
-
|
|
22681
|
-
/**
|
|
22682
|
-
* Like {@link transaction} but provides access to the transaction state.
|
|
22683
|
-
*
|
|
22684
|
-
* Always creates a new isolated transaction boundary with its own journal and retry logic.
|
|
22685
|
-
*
|
|
22686
|
-
* @example
|
|
22687
|
-
* ```ts
|
|
22688
|
-
* import { Effect, TxRef } from "effect"
|
|
22689
|
-
*
|
|
22690
|
-
* const program = Effect.transactionWith((_txState) =>
|
|
22691
|
-
* Effect.gen(function*() {
|
|
22692
|
-
* const ref = yield* TxRef.make(0)
|
|
22693
|
-
* yield* TxRef.set(ref, 42)
|
|
22694
|
-
* return yield* TxRef.get(ref)
|
|
22695
|
-
* })
|
|
22696
|
-
* )
|
|
22697
|
-
* ```
|
|
22698
|
-
*
|
|
22699
|
-
* @since 4.0.0
|
|
22700
|
-
* @category Transactions
|
|
22701
|
-
*/
|
|
22702
|
-
export const transactionWith = <A, E, R>(
|
|
22703
|
-
f: (state: Transaction["Service"]) => Effect<A, E, R>
|
|
22704
22651
|
): Effect<A, E, Exclude<R, Transaction>> =>
|
|
22705
22652
|
withFiber((fiber) => {
|
|
22706
|
-
|
|
22653
|
+
if (fiber.services.mapUnsafe.has(Transaction.key)) {
|
|
22654
|
+
return effect as Effect<A, E, Exclude<R, Transaction>>
|
|
22655
|
+
}
|
|
22656
|
+
// Create transaction state only at the outermost boundary
|
|
22707
22657
|
const state: Transaction["Service"] = { journal: new Map(), retry: false }
|
|
22708
22658
|
let result: Exit.Exit<A, E> | undefined
|
|
22709
22659
|
return uninterruptibleMask((restore) =>
|
|
@@ -22711,7 +22661,7 @@ export const transactionWith = <A, E, R>(
|
|
|
22711
22661
|
whileLoop({
|
|
22712
22662
|
while: () => !result,
|
|
22713
22663
|
body: constant(
|
|
22714
|
-
restore(
|
|
22664
|
+
restore(effect).pipe(
|
|
22715
22665
|
provideService(Transaction, state),
|
|
22716
22666
|
tapCause(() => {
|
|
22717
22667
|
if (!state.retry) return void_
|
|
@@ -22800,20 +22750,20 @@ function clearTransaction(state: Transaction["Service"]) {
|
|
|
22800
22750
|
*
|
|
22801
22751
|
* const program = Effect.gen(function*() {
|
|
22802
22752
|
* // create a transactional reference
|
|
22803
|
-
* const ref = yield*
|
|
22753
|
+
* const ref = yield* TxRef.make(0)
|
|
22804
22754
|
*
|
|
22805
22755
|
* // forks a fiber that increases the value of `ref` every 100 millis
|
|
22806
22756
|
* yield* Effect.forkChild(Effect.forever(
|
|
22807
22757
|
* // update to transactional value
|
|
22808
|
-
* Effect.
|
|
22758
|
+
* Effect.tx(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
|
|
22809
22759
|
* ))
|
|
22810
22760
|
*
|
|
22811
22761
|
* // the following will retry 10 times until the `ref` value is 10
|
|
22812
|
-
* yield* Effect.
|
|
22762
|
+
* yield* Effect.tx(Effect.gen(function*() {
|
|
22813
22763
|
* const value = yield* TxRef.get(ref)
|
|
22814
22764
|
* if (value < 10) {
|
|
22815
22765
|
* yield* Effect.log(`retry due to value: ${value}`)
|
|
22816
|
-
* return yield* Effect.
|
|
22766
|
+
* return yield* Effect.txRetry
|
|
22817
22767
|
* }
|
|
22818
22768
|
* yield* Effect.log(`transaction done with value: ${value}`)
|
|
22819
22769
|
* }))
|
|
@@ -22822,7 +22772,7 @@ function clearTransaction(state: Transaction["Service"]) {
|
|
|
22822
22772
|
* Effect.runPromise(program).catch(console.error)
|
|
22823
22773
|
* ```
|
|
22824
22774
|
*/
|
|
22825
|
-
export const
|
|
22775
|
+
export const txRetry: Effect<never, never, Transaction> = flatMap(
|
|
22826
22776
|
Transaction.asEffect(),
|
|
22827
22777
|
(state) => {
|
|
22828
22778
|
state.retry = true
|
package/src/Layer.ts
CHANGED
|
@@ -3024,7 +3024,7 @@ export const updateService: {
|
|
|
3024
3024
|
layer: Layer<A1, E1, R1>,
|
|
3025
3025
|
service: ServiceMap.Key<I, A>,
|
|
3026
3026
|
f: (a: A) => A
|
|
3027
|
-
): Layer<A1, E1, I | R1> => provide(layer, effect(service
|
|
3027
|
+
): Layer<A1, E1, I | R1> => provide(layer, effect(service, internalEffect.map(service.asEffect(), f)))
|
|
3028
3028
|
)
|
|
3029
3029
|
|
|
3030
3030
|
/**
|
package/src/ManagedRuntime.ts
CHANGED
|
@@ -164,22 +164,35 @@ export const make = <R, ER>(
|
|
|
164
164
|
} | undefined
|
|
165
165
|
): ManagedRuntime<R, ER> => {
|
|
166
166
|
const memoMap = options?.memoMap ?? Layer.makeMemoMapUnsafe()
|
|
167
|
-
const scope = Scope.makeUnsafe()
|
|
167
|
+
const scope = Scope.makeUnsafe("parallel")
|
|
168
|
+
const layerScope = Scope.forkUnsafe(scope, "sequential")
|
|
169
|
+
const defaultRunOptions: Effect.RunOptions = {
|
|
170
|
+
onFiberStart: Fiber.runIn(scope)
|
|
171
|
+
}
|
|
172
|
+
const mergeRunOptions = <O extends Effect.RunOptions>(options?: O): O =>
|
|
173
|
+
options
|
|
174
|
+
? {
|
|
175
|
+
...options,
|
|
176
|
+
onFiberStart: options.onFiberStart ?
|
|
177
|
+
(fiber) => {
|
|
178
|
+
defaultRunOptions.onFiberStart!(fiber)
|
|
179
|
+
options.onFiberStart!(fiber)
|
|
180
|
+
} :
|
|
181
|
+
defaultRunOptions.onFiberStart
|
|
182
|
+
}
|
|
183
|
+
: defaultRunOptions as O
|
|
168
184
|
let buildFiber: Fiber.Fiber<ServiceMap.ServiceMap<R>, ER> | undefined
|
|
169
185
|
const servicesEffect = Effect.withFiber<ServiceMap.ServiceMap<R>, ER>((fiber) => {
|
|
170
186
|
if (!buildFiber) {
|
|
171
|
-
buildFiber =
|
|
172
|
-
Effect.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
})
|
|
179
|
-
),
|
|
180
|
-
{ scheduler: fiber.currentScheduler }
|
|
187
|
+
buildFiber = Effect.runFork(
|
|
188
|
+
Effect.tap(
|
|
189
|
+
Layer.buildWithMemoMap(layer, memoMap, layerScope),
|
|
190
|
+
(services) =>
|
|
191
|
+
Effect.sync(() => {
|
|
192
|
+
self.cachedServices = services
|
|
193
|
+
})
|
|
181
194
|
),
|
|
182
|
-
|
|
195
|
+
{ ...defaultRunOptions, scheduler: fiber.currentScheduler }
|
|
183
196
|
)
|
|
184
197
|
}
|
|
185
198
|
return Effect.flatten(Fiber.await(buildFiber))
|
|
@@ -205,8 +218,8 @@ export const make = <R, ER>(
|
|
|
205
218
|
}),
|
|
206
219
|
runFork<A, E>(effect: Effect.Effect<A, E, R>, options?: Effect.RunOptions): Fiber.Fiber<A, E | ER> {
|
|
207
220
|
return self.cachedServices === undefined ?
|
|
208
|
-
Effect.runFork(provide(self, effect), options) :
|
|
209
|
-
Effect.runForkWith(self.cachedServices)(effect, options)
|
|
221
|
+
Effect.runFork(provide(self, effect), mergeRunOptions(options)) :
|
|
222
|
+
Effect.runForkWith(self.cachedServices)(effect, mergeRunOptions(options))
|
|
210
223
|
},
|
|
211
224
|
runCallback<A, E>(
|
|
212
225
|
effect: Effect.Effect<A, E, R>,
|
|
@@ -215,8 +228,8 @@ export const make = <R, ER>(
|
|
|
215
228
|
}
|
|
216
229
|
): (interruptor?: number | undefined) => void {
|
|
217
230
|
return self.cachedServices === undefined ?
|
|
218
|
-
Effect.runCallback(provide(self, effect), options) :
|
|
219
|
-
Effect.runCallbackWith(self.cachedServices)(effect, options)
|
|
231
|
+
Effect.runCallback(provide(self, effect), mergeRunOptions(options)) :
|
|
232
|
+
Effect.runCallbackWith(self.cachedServices)(effect, mergeRunOptions(options))
|
|
220
233
|
},
|
|
221
234
|
runSyncExit<A, E>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, E | ER> {
|
|
222
235
|
return self.cachedServices === undefined ?
|
|
@@ -230,15 +243,15 @@ export const make = <R, ER>(
|
|
|
230
243
|
},
|
|
231
244
|
runPromiseExit<A, E>(effect: Effect.Effect<A, E, R>, options?: Effect.RunOptions): Promise<Exit.Exit<A, E | ER>> {
|
|
232
245
|
return self.cachedServices === undefined ?
|
|
233
|
-
Effect.runPromiseExit(provide(self, effect), options) :
|
|
234
|
-
Effect.runPromiseExitWith(self.cachedServices)(effect, options)
|
|
246
|
+
Effect.runPromiseExit(provide(self, effect), mergeRunOptions(options)) :
|
|
247
|
+
Effect.runPromiseExitWith(self.cachedServices)(effect, mergeRunOptions(options))
|
|
235
248
|
},
|
|
236
249
|
runPromise<A, E>(effect: Effect.Effect<A, E, R>, options?: {
|
|
237
250
|
readonly signal?: AbortSignal | undefined
|
|
238
251
|
}): Promise<A> {
|
|
239
252
|
return self.cachedServices === undefined ?
|
|
240
|
-
Effect.runPromise(provide(self, effect), options) :
|
|
241
|
-
Effect.runPromiseWith(self.cachedServices)(effect, options)
|
|
253
|
+
Effect.runPromise(provide(self, effect), mergeRunOptions(options)) :
|
|
254
|
+
Effect.runPromiseWith(self.cachedServices)(effect, mergeRunOptions(options))
|
|
242
255
|
}
|
|
243
256
|
}
|
|
244
257
|
return self
|
package/src/MutableList.ts
CHANGED
|
@@ -507,6 +507,9 @@ export const appendAll = <A>(self: MutableList<A>, messages: Iterable<A>): numbe
|
|
|
507
507
|
* @category mutations
|
|
508
508
|
*/
|
|
509
509
|
export const appendAllUnsafe = <A>(self: MutableList<A>, messages: ReadonlyArray<A>, mutable = false): number => {
|
|
510
|
+
if (messages.length === 0) {
|
|
511
|
+
return 0
|
|
512
|
+
}
|
|
510
513
|
const chunk: MutableList.Bucket<A> = {
|
|
511
514
|
array: messages as Array<A>,
|
|
512
515
|
mutable,
|
package/src/Number.ts
CHANGED
|
@@ -957,15 +957,25 @@ export const remainder: {
|
|
|
957
957
|
*/
|
|
958
958
|
(self: number, divisor: number): number
|
|
959
959
|
} = dual(2, (self: number, divisor: number): number => {
|
|
960
|
-
|
|
961
|
-
const
|
|
962
|
-
const divisorDecCount = (divisor.toString().split(".")[1] || "").length
|
|
960
|
+
const selfDecCount = decimalCount(self)
|
|
961
|
+
const divisorDecCount = decimalCount(divisor)
|
|
963
962
|
const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount
|
|
964
963
|
const selfInt = parseInt(self.toFixed(decCount).replace(".", ""))
|
|
965
964
|
const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", ""))
|
|
966
965
|
return (selfInt % divisorInt) / Math.pow(10, decCount)
|
|
967
966
|
})
|
|
968
967
|
|
|
968
|
+
function decimalCount(n: number): number {
|
|
969
|
+
const s = n.toString()
|
|
970
|
+
const eIndex = s.indexOf("e-")
|
|
971
|
+
if (eIndex !== -1) {
|
|
972
|
+
const exp = parseInt(s.slice(eIndex + 2))
|
|
973
|
+
const mantissaDecimals = (s.slice(0, eIndex).split(".")[1] || "").length
|
|
974
|
+
return mantissaDecimals + exp
|
|
975
|
+
}
|
|
976
|
+
return (s.split(".")[1] || "").length
|
|
977
|
+
}
|
|
978
|
+
|
|
969
979
|
/**
|
|
970
980
|
* Returns the next power of 2 from the given number.
|
|
971
981
|
*
|
|
@@ -3015,7 +3015,13 @@ export function fromJsonSchemaMultiDocument(document: JsonSchema.MultiDocument<"
|
|
|
3015
3015
|
}
|
|
3016
3016
|
|
|
3017
3017
|
if (Array.isArray(js.allOf)) {
|
|
3018
|
-
|
|
3018
|
+
out = js.allOf.reduce((acc, curr) => combine(acc, recur(curr)), out)
|
|
3019
|
+
}
|
|
3020
|
+
if (Array.isArray(js.anyOf)) {
|
|
3021
|
+
out = combine({ _tag: "Union", types: js.anyOf.map((type) => recur(type)), mode: "anyOf" }, out)
|
|
3022
|
+
}
|
|
3023
|
+
if (Array.isArray(js.oneOf)) {
|
|
3024
|
+
out = combine({ _tag: "Union", types: js.oneOf.map((type) => recur(type)), mode: "oneOf" }, out)
|
|
3019
3025
|
}
|
|
3020
3026
|
|
|
3021
3027
|
return out
|
|
@@ -3054,10 +3060,6 @@ export function fromJsonSchemaMultiDocument(document: JsonSchema.MultiDocument<"
|
|
|
3054
3060
|
} else {
|
|
3055
3061
|
return { _tag: "Union", types, mode: "anyOf" }
|
|
3056
3062
|
}
|
|
3057
|
-
} else if (Array.isArray(js.anyOf)) {
|
|
3058
|
-
return { _tag: "Union", types: js.anyOf.map((type) => recur(type)), mode: "anyOf" }
|
|
3059
|
-
} else if (Array.isArray(js.oneOf)) {
|
|
3060
|
-
return { _tag: "Union", types: js.oneOf.map((type) => recur(type)), mode: "oneOf" }
|
|
3061
3063
|
}
|
|
3062
3064
|
|
|
3063
3065
|
const type = isType(js.type) ? js.type : getType(js)
|
|
@@ -3290,7 +3292,7 @@ export function fromJsonSchemaMultiDocument(document: JsonSchema.MultiDocument<"
|
|
|
3290
3292
|
return {
|
|
3291
3293
|
_tag: "Union",
|
|
3292
3294
|
types,
|
|
3293
|
-
mode:
|
|
3295
|
+
mode: a.mode,
|
|
3294
3296
|
...makeAnnotations(a.annotations)
|
|
3295
3297
|
}
|
|
3296
3298
|
}
|
package/src/ServiceMap.ts
CHANGED
|
@@ -22,7 +22,17 @@ import type { Pipeable } from "./Pipeable.ts"
|
|
|
22
22
|
import { hasProperty } from "./Predicate.ts"
|
|
23
23
|
import type * as Types from "./Types.ts"
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @since 4.0.0
|
|
27
|
+
* @category Type Identifiers
|
|
28
|
+
*/
|
|
29
|
+
export type ServiceTypeId = "~effect/ServiceMap/Service"
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @since 4.0.0
|
|
33
|
+
* @category Type Identifiers
|
|
34
|
+
*/
|
|
35
|
+
export const ServiceTypeId: ServiceTypeId = "~effect/ServiceMap/Service"
|
|
26
36
|
|
|
27
37
|
/**
|
|
28
38
|
* The base type used for all ServiceMap keys.
|
|
@@ -30,11 +40,8 @@ const ServiceTypeId = "~effect/ServiceMap/Service" as const
|
|
|
30
40
|
* @since 4.0.0
|
|
31
41
|
* @category Models
|
|
32
42
|
*/
|
|
33
|
-
export interface Key<
|
|
34
|
-
readonly [ServiceTypeId]:
|
|
35
|
-
readonly _Service: Types.Invariant<Shape>
|
|
36
|
-
readonly _Identifier: Types.Invariant<Identifier>
|
|
37
|
-
}
|
|
43
|
+
export interface Key<out Identifier, out Shape> extends Pipeable, Inspectable {
|
|
44
|
+
readonly [ServiceTypeId]: ServiceTypeId
|
|
38
45
|
readonly Service: Shape
|
|
39
46
|
readonly Identifier: Identifier
|
|
40
47
|
readonly key: string
|
|
@@ -262,10 +269,7 @@ export const Service: {
|
|
|
262
269
|
} as any
|
|
263
270
|
|
|
264
271
|
const ServiceProto: any = {
|
|
265
|
-
[ServiceTypeId]:
|
|
266
|
-
_Service: (_: unknown) => _,
|
|
267
|
-
_Identifier: (_: unknown) => _
|
|
268
|
-
},
|
|
272
|
+
[ServiceTypeId]: ServiceTypeId,
|
|
269
273
|
...PipeInspectableProto,
|
|
270
274
|
...YieldableProto,
|
|
271
275
|
toJSON<I, A>(this: Service<I, A>) {
|
|
@@ -344,25 +348,6 @@ export interface Reference<in out Shape> extends Service<never, Shape> {
|
|
|
344
348
|
* @category Models
|
|
345
349
|
*/
|
|
346
350
|
export declare namespace Service {
|
|
347
|
-
/**
|
|
348
|
-
* @example
|
|
349
|
-
* ```ts
|
|
350
|
-
* import type { ServiceMap } from "effect"
|
|
351
|
-
*
|
|
352
|
-
* // Variance interface is used internally for type inference
|
|
353
|
-
* type MyVariance = ServiceMap.Service.Variance<"MyId", { value: number }>
|
|
354
|
-
* ```
|
|
355
|
-
*
|
|
356
|
-
* @since 4.0.0
|
|
357
|
-
* @category Models
|
|
358
|
-
*/
|
|
359
|
-
export interface Variance<in out Identifier, in out Shape> {
|
|
360
|
-
readonly [ServiceTypeId]: {
|
|
361
|
-
readonly _Service: Types.Invariant<Shape>
|
|
362
|
-
readonly _Identifier: Types.Invariant<Identifier>
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
351
|
/**
|
|
367
352
|
* @example
|
|
368
353
|
* ```ts
|
|
@@ -397,7 +382,7 @@ export declare namespace Service {
|
|
|
397
382
|
* @since 4.0.0
|
|
398
383
|
* @category Models
|
|
399
384
|
*/
|
|
400
|
-
export type Shape<T> = T extends
|
|
385
|
+
export type Shape<T> = T extends Key<infer _I, infer S> ? S : never
|
|
401
386
|
|
|
402
387
|
/**
|
|
403
388
|
* @example
|
|
@@ -416,7 +401,7 @@ export declare namespace Service {
|
|
|
416
401
|
* @since 4.0.0
|
|
417
402
|
* @category Models
|
|
418
403
|
*/
|
|
419
|
-
export type Identifier<T> = T extends
|
|
404
|
+
export type Identifier<T> = T extends Key<infer I, infer _S> ? I : never
|
|
420
405
|
}
|
|
421
406
|
|
|
422
407
|
const TypeId = "~effect/ServiceMap" as const
|