effect 4.0.0-beta.18 → 4.0.0-beta.19

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 (103) hide show
  1. package/dist/Array.d.ts +127 -299
  2. package/dist/Array.d.ts.map +1 -1
  3. package/dist/Array.js +102 -62
  4. package/dist/Array.js.map +1 -1
  5. package/dist/Cache.d.ts.map +1 -1
  6. package/dist/Cache.js +5 -4
  7. package/dist/Cache.js.map +1 -1
  8. package/dist/Channel.d.ts +97 -11
  9. package/dist/Channel.d.ts.map +1 -1
  10. package/dist/Channel.js +72 -29
  11. package/dist/Channel.js.map +1 -1
  12. package/dist/Chunk.d.ts +54 -247
  13. package/dist/Chunk.d.ts.map +1 -1
  14. package/dist/Chunk.js +36 -67
  15. package/dist/Chunk.js.map +1 -1
  16. package/dist/Effect.d.ts +304 -336
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +85 -26
  19. package/dist/Effect.js.map +1 -1
  20. package/dist/Filter.d.ts +0 -33
  21. package/dist/Filter.d.ts.map +1 -1
  22. package/dist/Filter.js +0 -13
  23. package/dist/Filter.js.map +1 -1
  24. package/dist/HashMap.d.ts +15 -14
  25. package/dist/HashMap.d.ts.map +1 -1
  26. package/dist/HashMap.js +4 -4
  27. package/dist/HashMap.js.map +1 -1
  28. package/dist/Iterable.d.ts +40 -39
  29. package/dist/Iterable.d.ts.map +1 -1
  30. package/dist/Iterable.js +94 -22
  31. package/dist/Iterable.js.map +1 -1
  32. package/dist/Option.d.ts +22 -15
  33. package/dist/Option.d.ts.map +1 -1
  34. package/dist/Option.js +14 -7
  35. package/dist/Option.js.map +1 -1
  36. package/dist/Pull.d.ts.map +1 -1
  37. package/dist/Pull.js +1 -1
  38. package/dist/Pull.js.map +1 -1
  39. package/dist/Record.d.ts +24 -120
  40. package/dist/Record.d.ts.map +1 -1
  41. package/dist/Record.js +21 -41
  42. package/dist/Record.js.map +1 -1
  43. package/dist/Sink.d.ts +11 -11
  44. package/dist/Sink.d.ts.map +1 -1
  45. package/dist/Sink.js +53 -6
  46. package/dist/Sink.js.map +1 -1
  47. package/dist/Stream.d.ts +198 -386
  48. package/dist/Stream.d.ts.map +1 -1
  49. package/dist/Stream.js +103 -59
  50. package/dist/Stream.js.map +1 -1
  51. package/dist/Trie.d.ts +18 -17
  52. package/dist/Trie.d.ts.map +1 -1
  53. package/dist/Trie.js +5 -5
  54. package/dist/Trie.js.map +1 -1
  55. package/dist/TxHashMap.d.ts +27 -26
  56. package/dist/TxHashMap.d.ts.map +1 -1
  57. package/dist/TxHashMap.js +8 -8
  58. package/dist/TxHashMap.js.map +1 -1
  59. package/dist/internal/effect.js +99 -42
  60. package/dist/internal/effect.js.map +1 -1
  61. package/dist/internal/hashMap.js +3 -2
  62. package/dist/internal/hashMap.js.map +1 -1
  63. package/dist/internal/trie.js +5 -4
  64. package/dist/internal/trie.js.map +1 -1
  65. package/dist/unstable/cli/Command.js +1 -1
  66. package/dist/unstable/cli/Command.js.map +1 -1
  67. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  68. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  69. package/dist/unstable/cluster/Sharding.js +1 -1
  70. package/dist/unstable/cluster/Sharding.js.map +1 -1
  71. package/dist/unstable/encoding/Sse.js +1 -1
  72. package/dist/unstable/encoding/Sse.js.map +1 -1
  73. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  74. package/dist/unstable/rpc/RpcServer.js +1 -2
  75. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  76. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  77. package/dist/unstable/socket/Socket.js +3 -3
  78. package/dist/unstable/socket/Socket.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/Array.ts +190 -342
  81. package/src/Cache.ts +6 -5
  82. package/src/Channel.ts +506 -102
  83. package/src/Chunk.ts +81 -268
  84. package/src/Effect.ts +399 -401
  85. package/src/Filter.ts +0 -57
  86. package/src/HashMap.ts +15 -14
  87. package/src/Iterable.ts +105 -50
  88. package/src/Option.ts +30 -20
  89. package/src/Pull.ts +1 -1
  90. package/src/Record.ts +43 -152
  91. package/src/Sink.ts +75 -23
  92. package/src/Stream.ts +442 -502
  93. package/src/Trie.ts +18 -17
  94. package/src/TxHashMap.ts +29 -28
  95. package/src/internal/effect.ts +368 -163
  96. package/src/internal/hashMap.ts +7 -5
  97. package/src/internal/trie.ts +16 -9
  98. package/src/unstable/cli/Command.ts +2 -2
  99. package/src/unstable/cluster/K8sHttpClient.ts +4 -4
  100. package/src/unstable/cluster/Sharding.ts +1 -1
  101. package/src/unstable/encoding/Sse.ts +1 -1
  102. package/src/unstable/rpc/RpcServer.ts +1 -7
  103. package/src/unstable/socket/Socket.ts +9 -11
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as Equal_ from "../Equal.ts"
6
+ import type * as Filter from "../Filter.ts"
6
7
  import { format } from "../Formatter.ts"
7
8
  import { dual, pipe } from "../Function.ts"
8
9
  import * as Hash from "../Hash.ts"
@@ -12,6 +13,7 @@ import * as Option from "../Option.ts"
12
13
  import type { Pipeable } from "../Pipeable.ts"
13
14
  import { pipeArguments } from "../Pipeable.ts"
14
15
  import { hasProperty } from "../Predicate.ts"
16
+ import * as Result from "../Result.ts"
15
17
  import type { NoInfer } from "../Types.ts"
16
18
 
17
19
  /** @internal */
@@ -1255,14 +1257,14 @@ export const compact = <K, A>(self: HashMap<K, Option.Option<A>>): HashMap<K, A>
1255
1257
 
1256
1258
  /** @internal */
1257
1259
  export const filterMap = dual<
1258
- <A, K, B>(f: (value: A, key: K) => Option.Option<B>) => (self: HashMap<K, A>) => HashMap<K, B>,
1259
- <K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => Option.Option<B>) => HashMap<K, B>
1260
- >(2, <K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => Option.Option<B>): HashMap<K, B> => {
1260
+ <A, K, B, X>(f: Filter.Filter<A, B, X, [key: K]>) => (self: HashMap<K, A>) => HashMap<K, B>,
1261
+ <K, A, B, X>(self: HashMap<K, A>, f: Filter.Filter<A, B, X, [key: K]>) => HashMap<K, B>
1262
+ >(2, <K, A, B, X>(self: HashMap<K, A>, f: Filter.Filter<A, B, X, [key: K]>): HashMap<K, B> => {
1261
1263
  let result = empty<K, B>()
1262
1264
  for (const [key, value] of self) {
1263
1265
  const mapped = f(value, key)
1264
- if (Option.isSome(mapped)) {
1265
- result = set(result, key, mapped.value)
1266
+ if (Result.isSuccess(mapped)) {
1267
+ result = set(result, key, mapped.success)
1266
1268
  }
1267
1269
  }
1268
1270
  return result
@@ -1,12 +1,14 @@
1
1
  import * as Equal from "../Equal.ts"
2
+ import type * as Filter from "../Filter.ts"
2
3
  import { format } from "../Formatter.ts"
3
- import { dual, identity, pipe } from "../Function.ts"
4
+ import { dual, pipe } from "../Function.ts"
4
5
  import * as Hash from "../Hash.ts"
5
6
  import { NodeInspectSymbol, toJson } from "../Inspectable.ts"
6
7
  import * as Option from "../Option.ts"
7
8
  import type * as Ordering from "../Ordering.ts"
8
9
  import { pipeArguments } from "../Pipeable.ts"
9
10
  import { hasProperty } from "../Predicate.ts"
11
+ import * as Result from "../Result.ts"
10
12
  import type * as TR from "../Trie.ts"
11
13
  import type { NoInfer } from "../Types.ts"
12
14
 
@@ -309,22 +311,27 @@ export const filter: {
309
311
 
310
312
  /** @internal */
311
313
  export const filterMap = dual<
312
- <A, B>(
313
- f: (value: A, key: string) => Option.Option<B>
314
+ <A, B, X>(
315
+ f: Filter.Filter<A, B, X, [key: string]>
314
316
  ) => (self: TR.Trie<A>) => TR.Trie<B>,
315
- <A, B>(self: TR.Trie<A>, f: (value: A, key: string) => Option.Option<B>) => TR.Trie<B>
316
- >(2, (self, f) =>
317
+ <A, B, X>(self: TR.Trie<A>, f: Filter.Filter<A, B, X, [key: string]>) => TR.Trie<B>
318
+ >(2, <A, B, X>(self: TR.Trie<A>, f: Filter.Filter<A, B, X, [key: string]>): TR.Trie<B> =>
317
319
  reduce(
318
320
  self,
319
- empty(),
321
+ empty<B>(),
320
322
  (trie, value, key) => {
321
- const option = f(value, key)
322
- return Option.isSome(option) ? insert(trie, key, option.value) : trie
323
+ const result = f(value, key)
324
+ return Result.isSuccess(result) ? insert(trie, key, result.success) : trie
323
325
  }
324
326
  ))
325
327
 
326
328
  /** @internal */
327
- export const compact = <A>(self: TR.Trie<Option.Option<A>>) => filterMap(self, identity)
329
+ export const compact = <A>(self: TR.Trie<Option.Option<A>>) =>
330
+ reduce(
331
+ self,
332
+ empty<A>(),
333
+ (trie, option, key) => Option.isSome(option) ? insert(trie, key, option.value) : trie
334
+ )
328
335
 
329
336
  /** @internal */
330
337
  export const forEach = dual<
@@ -1849,14 +1849,14 @@ export const runWith = <const Name extends string, Input, E, R>(
1849
1849
  // 9. Run command handler with composed context
1850
1850
  yield* Effect.provideServices(program, services)
1851
1851
  },
1852
- Effect.catchIf(
1852
+ Effect.catchFilter(
1853
1853
  ((error: any) =>
1854
1854
  CliError.isCliError(error) && error._tag === "ShowHelp"
1855
1855
  ? Result.succeed(error)
1856
1856
  : Result.fail(error)) as any,
1857
1857
  (error: any) => showHelp(command, error.commandPath)
1858
1858
  ),
1859
- Effect.catchIf(
1859
+ Effect.catchFilter(
1860
1860
  (e) =>
1861
1861
  Terminal.isQuitError(e)
1862
1862
  ? Result.succeed(e)
@@ -121,7 +121,7 @@ export const makeCreatePod = Effect.gen(function*() {
121
121
  while: (e) => e._tag === "SchemaError",
122
122
  schedule: Schedule.spaced("1 seconds")
123
123
  }),
124
- Effect.catchIf(
124
+ Effect.catchFilter(
125
125
  (err) =>
126
126
  HttpClientError.isHttpClientError(err) && err.reason._tag === "StatusCodeError" &&
127
127
  err.reason.response.status === 404
@@ -133,7 +133,7 @@ export const makeCreatePod = Effect.gen(function*() {
133
133
  )
134
134
  const isPodFound = readPodRaw.pipe(
135
135
  Effect.as(true),
136
- Effect.catchIf(
136
+ Effect.catchFilter(
137
137
  (err) =>
138
138
  HttpClientError.isHttpClientError(err) && err.reason._tag === "StatusCodeError" &&
139
139
  err.reason.response.status === 404
@@ -145,7 +145,7 @@ export const makeCreatePod = Effect.gen(function*() {
145
145
  const createPod = HttpClientRequest.post(`/v1/namespaces/${namespace}/pods`).pipe(
146
146
  HttpClientRequest.bodyJsonUnsafe(spec),
147
147
  client.execute,
148
- Effect.catchIf(
148
+ Effect.catchFilter(
149
149
  (err) =>
150
150
  HttpClientError.isHttpClientError(err) && err.reason._tag === "StatusCodeError" &&
151
151
  err.reason.response.status === 409
@@ -159,7 +159,7 @@ export const makeCreatePod = Effect.gen(function*() {
159
159
  const deletePod = HttpClientRequest.delete(`/v1/namespaces/${namespace}/pods/${name}`).pipe(
160
160
  client.execute,
161
161
  Effect.flatMap((res) => res.json),
162
- Effect.catchIf(
162
+ Effect.catchFilter(
163
163
  (err) =>
164
164
  HttpClientError.isHttpClientError(err) && err.reason._tag === "StatusCodeError" &&
165
165
  err.reason.response.status === 404
@@ -812,7 +812,7 @@ const make = Effect.gen(function*() {
812
812
  void,
813
813
  MailboxFull | AlreadyProcessingMessage | PersistenceError
814
814
  > {
815
- return Effect.catchIf(
815
+ return Effect.catchFilter(
816
816
  Effect.suspend(() => {
817
817
  const address = message.envelope.address
818
818
  const isPersisted = ServiceMap.get(message.rpc.annotations, Persisted)
@@ -311,7 +311,7 @@ export const encode = <IE, Done>(): Channel.Channel<
311
311
  let done = false
312
312
  const pull = upstream.pipe(
313
313
  Effect.map(Arr.map(encoder.write)),
314
- Effect.catchIf(Retry.filter as any, (retry: any) => {
314
+ Effect.catchFilter(Retry.filter as any, (retry: any) => {
315
315
  done = true
316
316
  return Effect.succeed(Arr.of(encoder.write(retry)))
317
317
  }),
@@ -15,7 +15,6 @@ import type * as Option from "../../Option.ts"
15
15
  import * as Predicate from "../../Predicate.ts"
16
16
  import * as Pull from "../../Pull.ts"
17
17
  import * as Queue from "../../Queue.ts"
18
- import * as Result from "../../Result.ts"
19
18
  import * as Schedule from "../../Schedule.ts"
20
19
  import * as Schema from "../../Schema.ts"
21
20
  import * as Scope from "../../Scope.ts"
@@ -1362,12 +1361,7 @@ const makeSocketProtocol: Effect.Effect<
1362
1361
  return writeRaw(parser.encode(ResponseDefectEncoded(cause))!)
1363
1362
  }
1364
1363
  }).pipe(
1365
- Effect.catchIf(
1366
- ((
1367
- error: any
1368
- ) => (error.reason._tag === "SocketCloseError" ? Result.succeed(error.reason) : Result.fail(error))) as any,
1369
- (_: any) => Effect.void
1370
- ),
1364
+ Effect.catchReason("SocketError", "SocketCloseError", (_) => Effect.void),
1371
1365
  Effect.orDie
1372
1366
  )
1373
1367
  }
@@ -281,7 +281,7 @@ export const toChannelMap = <IE, A>(
281
281
  return writeChunk
282
282
  }),
283
283
  Effect.forever({ disableYield: true }),
284
- Effect.catchCauseIf(
284
+ Effect.catchCauseFilter(
285
285
  Pull.filterNoDone,
286
286
  (cause) => Queue.failCause(queue, cause)
287
287
  ),
@@ -545,11 +545,10 @@ export const fromWebSocket = <RO>(
545
545
  currentWS = ws
546
546
  latch.openUnsafe()
547
547
  if (opts?.onOpen) yield* opts.onOpen
548
- return yield* FiberSet.join(fiberSet).pipe(
549
- Effect.catchIf(
550
- SocketCloseError.filterClean((_) => !closeCodeIsError(_)) as any,
551
- (_: any) => Effect.void
552
- )
548
+ return yield* Effect.catchFilter(
549
+ FiberSet.join(fiberSet),
550
+ SocketCloseError.filterClean((_) => !closeCodeIsError(_)),
551
+ () => Effect.void
553
552
  )
554
553
  })).pipe(
555
554
  Effect.updateServices((input: ServiceMap.ServiceMap<R>) => ServiceMap.merge(acquireContext, input)),
@@ -693,11 +692,10 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
693
692
  yield* latch.open
694
693
  if (opts?.onOpen) yield* opts.onOpen
695
694
 
696
- return yield* FiberSet.join(fiberSet).pipe(
697
- Effect.catchIf(
698
- SocketCloseError.filterClean((_) => !closeCodeIsError(_)) as any,
699
- (_: any) => Effect.void
700
- )
695
+ return yield* Effect.catchFilter(
696
+ FiberSet.join(fiberSet),
697
+ SocketCloseError.filterClean((_) => !closeCodeIsError(_)),
698
+ () => Effect.void
701
699
  )
702
700
  })).pipe(
703
701
  (_) => _,