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.
@@ -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
- } = dual(
646
- 2,
647
- <I, S extends object>(tag: Context.Tag<I, S>, service: Layer.PartialEffectful<S>): Layer.Layer<I> =>
648
- succeed(
649
- tag,
650
- new Proxy({ ...service as object } as S, {
651
- get(target, prop, _receiver) {
652
- if (prop in target) {
653
- return target[prop as keyof S]
654
- }
655
- const prevLimit = Error.stackTraceLimit
656
- Error.stackTraceLimit = 2
657
- const error = new Error(`${tag.key}: Unimplemented method "${prop.toString()}"`)
658
- Error.stackTraceLimit = prevLimit
659
- error.name = "UnimplementedError"
660
- return makeUnimplemented(error)
661
- },
662
- has: constTrue
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)
@@ -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
- if (index === input.length) {
1183
- return [s, cost, dirty, Chunk.empty<In>()]
1184
- }
1185
- const elem = pipe(input, Chunk.unsafeGet(index))
1186
- const total = cost + costFn(s, elem)
1187
- if (total <= max) {
1188
- return foldWeightedDecomposeFold(input, index + 1, f(s, elem), total, true, max, costFn, decompose, f)
1189
- }
1190
- const decomposed = decompose(elem)
1191
- if (decomposed.length <= 1 && !dirty) {
1192
- // If `elem` cannot be decomposed, we need to cross the `max` threshold. To
1193
- // minimize "injury", we only allow this when we haven't added anything else
1194
- // to the aggregate (dirty = false).
1195
- return [f(s, elem), total, true, pipe(input, Chunk.drop(index + 1))]
1196
- }
1197
- if (decomposed.length <= 1 && dirty) {
1198
- // If the state is dirty and `elem` cannot be decomposed, we stop folding
1199
- // and include `elem` in the leftovers.
1200
- return [s, cost, dirty, pipe(input, Chunk.drop(index))]
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
- // `elem` got decomposed, so we will recurse with the decomposed elements pushed
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 */
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.17.0"
1
+ let moduleVersion = "3.17.2"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4