effect 3.17.0 → 3.17.2
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/cjs/Layer.js.map +1 -1
- package/dist/cjs/internal/layer.js +9 -2
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/sink.js +29 -25
- package/dist/cjs/internal/sink.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Layer.d.ts +3 -2
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/internal/layer.js +8 -2
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/sink.js +29 -25
- package/dist/esm/internal/sink.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Layer.ts +9 -3
- package/src/internal/layer.ts +25 -21
- package/src/internal/sink.ts +27 -25
- package/src/internal/version.ts +1 -1
package/src/internal/layer.ts
CHANGED
|
@@ -642,27 +642,31 @@ export const launch = <RIn, E, ROut>(self: Layer.Layer<ROut, E, RIn>): Effect.Ef
|
|
|
642
642
|
export const mock: {
|
|
643
643
|
<I, S extends object>(tag: Context.Tag<I, S>): (service: Layer.PartialEffectful<S>) => Layer.Layer<I>
|
|
644
644
|
<I, S extends object>(tag: Context.Tag<I, S>, service: Layer.PartialEffectful<S>): Layer.Layer<I>
|
|
645
|
-
} =
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
)
|
|
645
|
+
} = function() {
|
|
646
|
+
if (arguments.length === 1) {
|
|
647
|
+
return (service: Layer.PartialEffectful<any>) => mockImpl(arguments[0], service)
|
|
648
|
+
}
|
|
649
|
+
return mockImpl(arguments[0], arguments[1])
|
|
650
|
+
} as any
|
|
651
|
+
|
|
652
|
+
const mockImpl = <I, S extends object>(tag: Context.Tag<I, S>, service: Layer.PartialEffectful<S>): Layer.Layer<I> =>
|
|
653
|
+
succeed(
|
|
654
|
+
tag,
|
|
655
|
+
new Proxy({ ...service as object } as S, {
|
|
656
|
+
get(target, prop, _receiver) {
|
|
657
|
+
if (prop in target) {
|
|
658
|
+
return target[prop as keyof S]
|
|
659
|
+
}
|
|
660
|
+
const prevLimit = Error.stackTraceLimit
|
|
661
|
+
Error.stackTraceLimit = 2
|
|
662
|
+
const error = new Error(`${tag.key}: Unimplemented method "${prop.toString()}"`)
|
|
663
|
+
Error.stackTraceLimit = prevLimit
|
|
664
|
+
error.name = "UnimplementedError"
|
|
665
|
+
return makeUnimplemented(error)
|
|
666
|
+
},
|
|
667
|
+
has: constTrue
|
|
668
|
+
})
|
|
669
|
+
)
|
|
666
670
|
|
|
667
671
|
const makeUnimplemented = (error: Error) => {
|
|
668
672
|
const dead = core.die(error)
|
package/src/internal/sink.ts
CHANGED
|
@@ -1146,7 +1146,6 @@ const foldWeightedDecomposeLoop = <S, In>(
|
|
|
1146
1146
|
onInput: (input: Chunk.Chunk<In>) => {
|
|
1147
1147
|
const [nextS, nextCost, nextDirty, leftovers] = foldWeightedDecomposeFold(
|
|
1148
1148
|
input,
|
|
1149
|
-
0,
|
|
1150
1149
|
s,
|
|
1151
1150
|
cost,
|
|
1152
1151
|
dirty,
|
|
@@ -1170,7 +1169,6 @@ const foldWeightedDecomposeLoop = <S, In>(
|
|
|
1170
1169
|
/** @internal */
|
|
1171
1170
|
const foldWeightedDecomposeFold = <In, S>(
|
|
1172
1171
|
input: Chunk.Chunk<In>,
|
|
1173
|
-
index: number,
|
|
1174
1172
|
s: S,
|
|
1175
1173
|
cost: number,
|
|
1176
1174
|
dirty: boolean,
|
|
@@ -1179,30 +1177,34 @@ const foldWeightedDecomposeFold = <In, S>(
|
|
|
1179
1177
|
decompose: (input: In) => Chunk.Chunk<In>,
|
|
1180
1178
|
f: (s: S, input: In) => S
|
|
1181
1179
|
): [S, number, boolean, Chunk.Chunk<In>] => {
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1180
|
+
for (let index = 0; index < input.length; index++) {
|
|
1181
|
+
const elem = Chunk.unsafeGet(input, index)
|
|
1182
|
+
const prevCost = cost
|
|
1183
|
+
cost = cost + costFn(s, elem)
|
|
1184
|
+
if (cost <= max) {
|
|
1185
|
+
s = f(s, elem)
|
|
1186
|
+
dirty = true
|
|
1187
|
+
continue
|
|
1188
|
+
}
|
|
1189
|
+
const decomposed = decompose(elem)
|
|
1190
|
+
if (decomposed.length <= 1 && !dirty) {
|
|
1191
|
+
// If `elem` cannot be decomposed, we need to cross the `max` threshold. To
|
|
1192
|
+
// minimize "injury", we only allow this when we haven't added anything else
|
|
1193
|
+
// to the aggregate (dirty = false).
|
|
1194
|
+
return [f(s, elem), cost, true, Chunk.drop(input, index + 1)]
|
|
1195
|
+
}
|
|
1196
|
+
if (decomposed.length <= 1 && dirty) {
|
|
1197
|
+
// If the state is dirty and `elem` cannot be decomposed, we stop folding
|
|
1198
|
+
// and include `elem` in the leftovers.
|
|
1199
|
+
return [s, prevCost, dirty, Chunk.drop(input, index)]
|
|
1200
|
+
}
|
|
1201
|
+
// `elem` got decomposed, so we will recurse with the decomposed elements pushed
|
|
1202
|
+
// into the chunk we're processing and see if we can aggregate further.
|
|
1203
|
+
input = Chunk.appendAll(decomposed, Chunk.drop(input, index + 1))
|
|
1204
|
+
cost = prevCost
|
|
1205
|
+
index = -1
|
|
1201
1206
|
}
|
|
1202
|
-
|
|
1203
|
-
// into the chunk we're processing and see if we can aggregate further.
|
|
1204
|
-
const next = pipe(decomposed, Chunk.appendAll(pipe(input, Chunk.drop(index + 1))))
|
|
1205
|
-
return foldWeightedDecomposeFold(next, 0, s, cost, dirty, max, costFn, decompose, f)
|
|
1207
|
+
return [s, cost, dirty, Chunk.empty<In>()]
|
|
1206
1208
|
}
|
|
1207
1209
|
|
|
1208
1210
|
/** @internal */
|
package/src/internal/version.ts
CHANGED