effect 4.0.0-beta.17 → 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 (164) 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 +337 -437
  17. package/dist/Effect.d.ts.map +1 -1
  18. package/dist/Effect.js +118 -134
  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/TxChunk.d.ts +37 -37
  56. package/dist/TxChunk.d.ts.map +1 -1
  57. package/dist/TxChunk.js +3 -3
  58. package/dist/TxChunk.js.map +1 -1
  59. package/dist/TxDeferred.d.ts +328 -0
  60. package/dist/TxDeferred.d.ts.map +1 -0
  61. package/dist/TxDeferred.js +196 -0
  62. package/dist/TxDeferred.js.map +1 -0
  63. package/dist/TxHashMap.d.ts +84 -83
  64. package/dist/TxHashMap.d.ts.map +1 -1
  65. package/dist/TxHashMap.js +24 -24
  66. package/dist/TxHashMap.js.map +1 -1
  67. package/dist/TxHashSet.d.ts +35 -35
  68. package/dist/TxHashSet.d.ts.map +1 -1
  69. package/dist/TxHashSet.js +14 -14
  70. package/dist/TxHashSet.js.map +1 -1
  71. package/dist/TxPriorityQueue.d.ts +609 -0
  72. package/dist/TxPriorityQueue.d.ts.map +1 -0
  73. package/dist/TxPriorityQueue.js +415 -0
  74. package/dist/TxPriorityQueue.js.map +1 -0
  75. package/dist/TxPubSub.d.ts +585 -0
  76. package/dist/TxPubSub.d.ts.map +1 -0
  77. package/dist/TxPubSub.js +521 -0
  78. package/dist/TxPubSub.js.map +1 -0
  79. package/dist/TxQueue.d.ts +32 -32
  80. package/dist/TxQueue.d.ts.map +1 -1
  81. package/dist/TxQueue.js +26 -26
  82. package/dist/TxQueue.js.map +1 -1
  83. package/dist/TxReentrantLock.d.ts +523 -0
  84. package/dist/TxReentrantLock.d.ts.map +1 -0
  85. package/dist/TxReentrantLock.js +504 -0
  86. package/dist/TxReentrantLock.js.map +1 -0
  87. package/dist/TxRef.d.ts +34 -34
  88. package/dist/TxRef.d.ts.map +1 -1
  89. package/dist/TxRef.js +21 -14
  90. package/dist/TxRef.js.map +1 -1
  91. package/dist/TxSemaphore.d.ts +8 -8
  92. package/dist/TxSemaphore.d.ts.map +1 -1
  93. package/dist/TxSemaphore.js +7 -7
  94. package/dist/TxSemaphore.js.map +1 -1
  95. package/dist/TxSubscriptionRef.d.ts +508 -0
  96. package/dist/TxSubscriptionRef.d.ts.map +1 -0
  97. package/dist/TxSubscriptionRef.js +293 -0
  98. package/dist/TxSubscriptionRef.js.map +1 -0
  99. package/dist/index.d.ts +40 -0
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +40 -0
  102. package/dist/index.js.map +1 -1
  103. package/dist/internal/effect.js +99 -42
  104. package/dist/internal/effect.js.map +1 -1
  105. package/dist/internal/hashMap.js +3 -2
  106. package/dist/internal/hashMap.js.map +1 -1
  107. package/dist/internal/trie.js +5 -4
  108. package/dist/internal/trie.js.map +1 -1
  109. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  110. package/dist/unstable/ai/Tool.js +0 -9
  111. package/dist/unstable/ai/Tool.js.map +1 -1
  112. package/dist/unstable/cli/Command.d.ts +1 -1
  113. package/dist/unstable/cli/Command.d.ts.map +1 -1
  114. package/dist/unstable/cli/Command.js +1 -1
  115. package/dist/unstable/cli/Command.js.map +1 -1
  116. package/dist/unstable/cluster/K8sHttpClient.js +4 -4
  117. package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
  118. package/dist/unstable/cluster/Sharding.js +1 -1
  119. package/dist/unstable/cluster/Sharding.js.map +1 -1
  120. package/dist/unstable/encoding/Sse.js +1 -1
  121. package/dist/unstable/encoding/Sse.js.map +1 -1
  122. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  123. package/dist/unstable/rpc/RpcServer.js +1 -2
  124. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  125. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  126. package/dist/unstable/socket/Socket.js +3 -3
  127. package/dist/unstable/socket/Socket.js.map +1 -1
  128. package/package.json +1 -1
  129. package/src/Array.ts +190 -342
  130. package/src/Cache.ts +6 -5
  131. package/src/Channel.ts +506 -102
  132. package/src/Chunk.ts +81 -268
  133. package/src/Effect.ts +437 -518
  134. package/src/Filter.ts +0 -57
  135. package/src/HashMap.ts +15 -14
  136. package/src/Iterable.ts +105 -50
  137. package/src/Option.ts +30 -20
  138. package/src/Pull.ts +1 -1
  139. package/src/Record.ts +43 -152
  140. package/src/Sink.ts +75 -23
  141. package/src/Stream.ts +442 -502
  142. package/src/Trie.ts +18 -17
  143. package/src/TxChunk.ts +72 -53
  144. package/src/TxDeferred.ts +394 -0
  145. package/src/TxHashMap.ts +332 -285
  146. package/src/TxHashSet.ts +111 -116
  147. package/src/TxPriorityQueue.ts +767 -0
  148. package/src/TxPubSub.ts +789 -0
  149. package/src/TxQueue.ts +241 -251
  150. package/src/TxReentrantLock.ts +753 -0
  151. package/src/TxRef.ts +50 -38
  152. package/src/TxSemaphore.ts +29 -32
  153. package/src/TxSubscriptionRef.ts +639 -0
  154. package/src/index.ts +45 -0
  155. package/src/internal/effect.ts +368 -163
  156. package/src/internal/hashMap.ts +7 -5
  157. package/src/internal/trie.ts +16 -9
  158. package/src/unstable/ai/Tool.ts +0 -9
  159. package/src/unstable/cli/Command.ts +6 -4
  160. package/src/unstable/cluster/K8sHttpClient.ts +4 -4
  161. package/src/unstable/cluster/Sharding.ts +1 -1
  162. package/src/unstable/encoding/Sse.ts +1 -1
  163. package/src/unstable/rpc/RpcServer.ts +1 -7
  164. 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<
@@ -1622,15 +1622,6 @@ export const getJsonSchema = <Tool extends Any>(tool: Tool, options?: {
1622
1622
  export const getJsonSchemaFromSchema = <S extends Schema.Top>(schema: S, options?: {
1623
1623
  readonly transformer?: CodecTransformer
1624
1624
  }): JsonSchema.JsonSchema => {
1625
- const props = AST.isObjects(schema.ast) ? schema.ast.propertySignatures : []
1626
- if (props.length === 0) {
1627
- return {
1628
- type: "object",
1629
- properties: {},
1630
- required: [],
1631
- additionalProperties: false
1632
- }
1633
- }
1634
1625
  if (Predicate.isNotUndefined(options?.transformer)) {
1635
1626
  return options.transformer(schema).jsonSchema
1636
1627
  }
@@ -994,8 +994,10 @@ export const withGlobalFlags: {
994
994
  )
995
995
 
996
996
  // Type extractors for subcommand arrays - T[number] gives union of all elements
997
- type ExtractGlobalFlagContext<T extends ReadonlyArray<GlobalFlag.GlobalFlag<any>>> = T[number] extends
998
- GlobalFlag.Setting<infer Id, any> ? GlobalFlag.Setting.Identifier<Id> : never
997
+ type ExtractGlobalFlagContext<T extends ReadonlyArray<GlobalFlag.GlobalFlag<any>>> = T[number] extends infer F
998
+ ? F extends GlobalFlag.Setting<infer Id, any> ? GlobalFlag.Setting.Identifier<Id>
999
+ : never
1000
+ : never
999
1001
  type ExtractSubcommand<T> = T extends Command<any, any, any, any> ? T
1000
1002
  : T extends Command.SubcommandGroup<infer Commands> ? Commands[number]
1001
1003
  : never
@@ -1847,14 +1849,14 @@ export const runWith = <const Name extends string, Input, E, R>(
1847
1849
  // 9. Run command handler with composed context
1848
1850
  yield* Effect.provideServices(program, services)
1849
1851
  },
1850
- Effect.catchIf(
1852
+ Effect.catchFilter(
1851
1853
  ((error: any) =>
1852
1854
  CliError.isCliError(error) && error._tag === "ShowHelp"
1853
1855
  ? Result.succeed(error)
1854
1856
  : Result.fail(error)) as any,
1855
1857
  (error: any) => showHelp(command, error.commandPath)
1856
1858
  ),
1857
- Effect.catchIf(
1859
+ Effect.catchFilter(
1858
1860
  (e) =>
1859
1861
  Terminal.isQuitError(e)
1860
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
  (_) => _,