effect 2.4.5 → 2.4.6

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 (71) hide show
  1. package/dist/cjs/Channel.js +10 -2
  2. package/dist/cjs/Channel.js.map +1 -1
  3. package/dist/cjs/Effect.js +26 -4
  4. package/dist/cjs/Effect.js.map +1 -1
  5. package/dist/cjs/internal/cause.js +2 -2
  6. package/dist/cjs/internal/cause.js.map +1 -1
  7. package/dist/cjs/internal/channel.js +75 -1
  8. package/dist/cjs/internal/channel.js.map +1 -1
  9. package/dist/cjs/internal/core-effect.js +0 -2
  10. package/dist/cjs/internal/core-effect.js.map +1 -1
  11. package/dist/cjs/internal/core.js +148 -126
  12. package/dist/cjs/internal/core.js.map +1 -1
  13. package/dist/cjs/internal/fiberRuntime.js +29 -29
  14. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  15. package/dist/cjs/internal/layer.js +2 -2
  16. package/dist/cjs/internal/layer.js.map +1 -1
  17. package/dist/cjs/internal/runtime.js +4 -6
  18. package/dist/cjs/internal/runtime.js.map +1 -1
  19. package/dist/cjs/internal/stm/core.js +36 -36
  20. package/dist/cjs/internal/stm/core.js.map +1 -1
  21. package/dist/cjs/internal/stream.js +2 -73
  22. package/dist/cjs/internal/stream.js.map +1 -1
  23. package/dist/cjs/internal/version.js +1 -1
  24. package/dist/dts/Channel.d.ts +8 -0
  25. package/dist/dts/Channel.d.ts.map +1 -1
  26. package/dist/dts/Effect.d.ts +38 -2
  27. package/dist/dts/Effect.d.ts.map +1 -1
  28. package/dist/esm/Channel.js +8 -0
  29. package/dist/esm/Channel.js.map +1 -1
  30. package/dist/esm/Effect.js +22 -0
  31. package/dist/esm/Effect.js.map +1 -1
  32. package/dist/esm/internal/cause.js +2 -2
  33. package/dist/esm/internal/cause.js.map +1 -1
  34. package/dist/esm/internal/channel.js +73 -0
  35. package/dist/esm/internal/channel.js.map +1 -1
  36. package/dist/esm/internal/core-effect.js +0 -2
  37. package/dist/esm/internal/core-effect.js.map +1 -1
  38. package/dist/esm/internal/core.js +144 -123
  39. package/dist/esm/internal/core.js.map +1 -1
  40. package/dist/esm/internal/fiberRuntime.js +29 -29
  41. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  42. package/dist/esm/internal/layer.js +2 -2
  43. package/dist/esm/internal/layer.js.map +1 -1
  44. package/dist/esm/internal/runtime.js +4 -6
  45. package/dist/esm/internal/runtime.js.map +1 -1
  46. package/dist/esm/internal/stm/core.js +36 -36
  47. package/dist/esm/internal/stm/core.js.map +1 -1
  48. package/dist/esm/internal/stream.js +2 -73
  49. package/dist/esm/internal/stream.js.map +1 -1
  50. package/dist/esm/internal/version.js +1 -1
  51. package/package.json +1 -1
  52. package/src/Channel.ts +17 -0
  53. package/src/Effect.ts +45 -2
  54. package/src/Exit.ts +2 -2
  55. package/src/internal/cause.ts +2 -2
  56. package/src/internal/channel.ts +92 -0
  57. package/src/internal/core-effect.ts +0 -2
  58. package/src/internal/core.ts +167 -134
  59. package/src/internal/fiberRuntime.ts +30 -30
  60. package/src/internal/layer.ts +4 -4
  61. package/src/internal/runtime.ts +4 -6
  62. package/src/internal/stm/core.ts +49 -49
  63. package/src/internal/stream.ts +2 -82
  64. package/src/internal/version.ts +1 -1
  65. package/dist/cjs/internal/internalize.js +0 -15
  66. package/dist/cjs/internal/internalize.js.map +0 -1
  67. package/dist/dts/internal/internalize.d.ts +0 -2
  68. package/dist/dts/internal/internalize.d.ts.map +0 -1
  69. package/dist/esm/internal/internalize.js +0 -8
  70. package/dist/esm/internal/internalize.js.map +0 -1
  71. package/src/internal/internalize.ts +0 -5
@@ -1,4 +1,4 @@
1
- let moduleVersion = "2.4.5";
1
+ let moduleVersion = "2.4.6";
2
2
  export const getCurrentVersion = () => moduleVersion;
3
3
  export const setCurrentVersion = version => {
4
4
  moduleVersion = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "The missing standard library for TypeScript, for writing production-grade software.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/Channel.ts CHANGED
@@ -1951,6 +1951,23 @@ export const scoped: <A, E, R>(
1951
1951
  effect: Effect.Effect<A, E, R>
1952
1952
  ) => Channel<A, unknown, E, unknown, unknown, unknown, Exclude<R, Scope.Scope>> = channel.scoped
1953
1953
 
1954
+ /**
1955
+ * Splits strings on newlines. Handles both Windows newlines (`\r\n`) and UNIX
1956
+ * newlines (`\n`).
1957
+ *
1958
+ * @since 2.0.0
1959
+ * @category combinators
1960
+ */
1961
+ export const splitLines: <Err, Done>() => Channel<
1962
+ Chunk.Chunk<string>,
1963
+ Chunk.Chunk<string>,
1964
+ Err,
1965
+ Err,
1966
+ Done,
1967
+ Done,
1968
+ never
1969
+ > = channel.splitLines
1970
+
1954
1971
  /**
1955
1972
  * Constructs a channel that succeeds immediately with the specified value.
1956
1973
  *
package/src/Effect.ts CHANGED
@@ -18,6 +18,7 @@ import type * as FiberId from "./FiberId.js"
18
18
  import type * as FiberRef from "./FiberRef.js"
19
19
  import type * as FiberRefs from "./FiberRefs.js"
20
20
  import type * as FiberRefsPatch from "./FiberRefsPatch.js"
21
+ import type * as FiberStatus from "./FiberStatus.js"
21
22
  import type { LazyArg } from "./Function.js"
22
23
  import { dual } from "./Function.js"
23
24
  import type * as HashMap from "./HashMap.js"
@@ -129,8 +130,8 @@ export interface EffectTypeLambda extends TypeLambda {
129
130
  */
130
131
  export interface Blocked<out A, out E> extends Effect<A, E> {
131
132
  readonly _op: "Blocked"
132
- readonly i0: RequestBlock
133
- readonly i1: Effect<A, E>
133
+ readonly effect_instruction_i0: RequestBlock
134
+ readonly effect_instruction_i1: Effect<A, E>
134
135
  }
135
136
 
136
137
  /**
@@ -994,6 +995,48 @@ export const asyncEffect: <A, E, R, R3, E2, R2>(
994
995
  register: (callback: (_: Effect<A, E, R>) => void) => Effect<Effect<void, never, R3> | void, E2, R2>
995
996
  ) => Effect<A, E | E2, R | R2 | R3> = _runtime.asyncEffect
996
997
 
998
+ /**
999
+ * Low level constructor that enables for custom stack tracing cutpoints.
1000
+ *
1001
+ * It is meant to be called with a bag of instructions that become available in the "this" of the effect.
1002
+ *
1003
+ * @example
1004
+ * import * as Effect from "effect/Effect"
1005
+ *
1006
+ * const throwingFunction = () => { throw new Error() }
1007
+ * const blowUp = Effect.custom(throwingFunction, function() {
1008
+ * return Effect.succeed(this.effect_instruction_i0())
1009
+ * })
1010
+ *
1011
+ * @since 2.0.0
1012
+ * @category constructors
1013
+ */
1014
+ export const custom: {
1015
+ <X, A, E, R>(i0: X, body: (this: { effect_instruction_i0: X }) => Effect<A, E, R>): Effect<A, E, R>
1016
+ <X, Y, A, E, R>(
1017
+ i0: X,
1018
+ i1: Y,
1019
+ body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y }) => Effect<A, E, R>
1020
+ ): Effect<A, E, R>
1021
+ <X, Y, Z, A, E, R>(
1022
+ i0: X,
1023
+ i1: Y,
1024
+ i2: Z,
1025
+ body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y; effect_instruction_i2: Z }) => Effect<A, E, R>
1026
+ ): Effect<A, E, R>
1027
+ } = core.custom
1028
+
1029
+ /**
1030
+ * @since 2.0.0
1031
+ * @category constructors
1032
+ */
1033
+ export const withFiberRuntime: <A, E = never, R = never>(
1034
+ withRuntime: (
1035
+ fiber: Fiber.RuntimeFiber<A, E>,
1036
+ status: FiberStatus.Running
1037
+ ) => Effect<A, E, R>
1038
+ ) => Effect<A, E, R> = core.withFiberRuntime
1039
+
997
1040
  /**
998
1041
  * @since 2.0.0
999
1042
  * @category constructors
package/src/Exit.ts CHANGED
@@ -40,7 +40,7 @@ export interface Failure<out A, out E> extends Effect.Effect<A, E>, Pipeable, In
40
40
  [Unify.unifySymbol]?: ExitUnify<this>
41
41
  [Unify.ignoreSymbol]?: ExitUnifyIgnore
42
42
  /** @internal */
43
- readonly i0: Cause.Cause<E>
43
+ readonly effect_instruction_i0: Cause.Cause<E>
44
44
  }
45
45
 
46
46
  /**
@@ -74,7 +74,7 @@ export interface Success<out A, out E> extends Effect.Effect<A, E>, Pipeable, In
74
74
  [Unify.unifySymbol]?: ExitUnify<this>
75
75
  [Unify.ignoreSymbol]?: ExitUnifyIgnore
76
76
  /** @internal */
77
- readonly i0: A
77
+ readonly effect_instruction_i0: A
78
78
  }
79
79
 
80
80
  /**
@@ -971,8 +971,8 @@ const filterStack = (stack: string) => {
971
971
  const lines = stack.split("\n")
972
972
  const out: Array<string> = []
973
973
  for (let i = 0; i < lines.length; i++) {
974
- out.push(lines[i].replace(/at .*effect_cutpoint.*\((.*)\)/, "at $1"))
975
- if (lines[i].includes("effect_cutpoint")) {
974
+ out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1"))
975
+ if (lines[i].includes("effect_instruction_i")) {
976
976
  return out.join("\n")
977
977
  }
978
978
  }
@@ -2105,6 +2105,98 @@ export const serviceWithEffect = <T extends Context.Tag<any, any>>(tag: T) =>
2105
2105
  ): Channel.Channel<never, unknown, OutErr, unknown, OutDone, unknown, Env | Context.Tag.Identifier<T>> =>
2106
2106
  mapEffect(service(tag), f)
2107
2107
 
2108
+ /** @internal */
2109
+ export const splitLines = <Err, Done>(): Channel.Channel<
2110
+ Chunk.Chunk<string>,
2111
+ Chunk.Chunk<string>,
2112
+ Err,
2113
+ Err,
2114
+ Done,
2115
+ Done,
2116
+ never
2117
+ > =>
2118
+ core.suspend(() => {
2119
+ let stringBuilder = ""
2120
+ let midCRLF = false
2121
+ const splitLinesChunk = (chunk: Chunk.Chunk<string>): Chunk.Chunk<string> => {
2122
+ const chunkBuilder: Array<string> = []
2123
+ Chunk.map(chunk, (str) => {
2124
+ if (str.length !== 0) {
2125
+ let from = 0
2126
+ let indexOfCR = str.indexOf("\r")
2127
+ let indexOfLF = str.indexOf("\n")
2128
+ if (midCRLF) {
2129
+ if (indexOfLF === 0) {
2130
+ chunkBuilder.push(stringBuilder)
2131
+ stringBuilder = ""
2132
+ from = 1
2133
+ indexOfLF = str.indexOf("\n", from)
2134
+ } else {
2135
+ stringBuilder = stringBuilder + "\r"
2136
+ }
2137
+ midCRLF = false
2138
+ }
2139
+ while (indexOfCR !== -1 || indexOfLF !== -1) {
2140
+ if (indexOfCR === -1 || (indexOfLF !== -1 && indexOfLF < indexOfCR)) {
2141
+ if (stringBuilder.length === 0) {
2142
+ chunkBuilder.push(str.substring(from, indexOfLF))
2143
+ } else {
2144
+ chunkBuilder.push(stringBuilder + str.substring(from, indexOfLF))
2145
+ stringBuilder = ""
2146
+ }
2147
+ from = indexOfLF + 1
2148
+ indexOfLF = str.indexOf("\n", from)
2149
+ } else {
2150
+ if (str.length === indexOfCR + 1) {
2151
+ midCRLF = true
2152
+ indexOfCR = -1
2153
+ } else {
2154
+ if (indexOfLF === indexOfCR + 1) {
2155
+ if (stringBuilder.length === 0) {
2156
+ chunkBuilder.push(str.substring(from, indexOfCR))
2157
+ } else {
2158
+ stringBuilder = stringBuilder + str.substring(from, indexOfCR)
2159
+ chunkBuilder.push(stringBuilder)
2160
+ stringBuilder = ""
2161
+ }
2162
+ from = indexOfCR + 2
2163
+ indexOfCR = str.indexOf("\r", from)
2164
+ indexOfLF = str.indexOf("\n", from)
2165
+ } else {
2166
+ indexOfCR = str.indexOf("\r", indexOfCR + 1)
2167
+ }
2168
+ }
2169
+ }
2170
+ }
2171
+ if (midCRLF) {
2172
+ stringBuilder = stringBuilder + str.substring(from, str.length - 1)
2173
+ } else {
2174
+ stringBuilder = stringBuilder + str.substring(from, str.length)
2175
+ }
2176
+ }
2177
+ })
2178
+ return Chunk.unsafeFromArray(chunkBuilder)
2179
+ }
2180
+ const loop: Channel.Channel<Chunk.Chunk<string>, Chunk.Chunk<string>, Err, Err, Done, Done, never> = core
2181
+ .readWithCause({
2182
+ onInput: (input: Chunk.Chunk<string>) => {
2183
+ const out = splitLinesChunk(input)
2184
+ return Chunk.isEmpty(out)
2185
+ ? loop
2186
+ : core.flatMap(core.write(out), () => loop)
2187
+ },
2188
+ onFailure: (cause) =>
2189
+ stringBuilder.length === 0
2190
+ ? core.failCause(cause)
2191
+ : core.flatMap(core.write(Chunk.of(stringBuilder)), () => core.failCause(cause)),
2192
+ onDone: (done) =>
2193
+ stringBuilder.length === 0
2194
+ ? core.succeed(done)
2195
+ : core.flatMap(core.write(Chunk.of(stringBuilder)), () => core.succeed(done))
2196
+ })
2197
+ return loop
2198
+ })
2199
+
2108
2200
  /** @internal */
2109
2201
  export const toPubSub = <Done, Err, Elem>(
2110
2202
  pubsub: PubSub.PubSub<Either.Either<Elem, Exit.Exit<Done, Err>>>
@@ -30,7 +30,6 @@ import * as internalCause from "./cause.js"
30
30
  import * as core from "./core.js"
31
31
  import * as defaultServices from "./defaultServices.js"
32
32
  import * as fiberRefsPatch from "./fiberRefs/patch.js"
33
- import { internalize } from "./internalize.js"
34
33
  import * as metricLabel from "./metric/label.js"
35
34
  import * as runtimeFlags from "./runtimeFlags.js"
36
35
  import * as SingleShotGen from "./singleShotGen.js"
@@ -778,7 +777,6 @@ export const gen: typeof Effect.gen = function() {
778
777
  } else {
779
778
  f = arguments[1].bind(arguments[0])
780
779
  }
781
- internalize(f)
782
780
  return core.suspend(() => {
783
781
  const iterator = f(adapter)
784
782
  const state = iterator.next()