effect 2.0.0-next.60 → 2.0.0-next.62

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 (78) hide show
  1. package/dist/cjs/BigDecimal.js +19 -5
  2. package/dist/cjs/BigDecimal.js.map +1 -1
  3. package/dist/cjs/ConfigProvider.js +8 -1
  4. package/dist/cjs/ConfigProvider.js.map +1 -1
  5. package/dist/cjs/Effect.js +7 -2
  6. package/dist/cjs/Effect.js.map +1 -1
  7. package/dist/cjs/Layer.js +8 -1
  8. package/dist/cjs/Layer.js.map +1 -1
  9. package/dist/cjs/ReadonlyRecord.js +28 -1
  10. package/dist/cjs/ReadonlyRecord.js.map +1 -1
  11. package/dist/cjs/internal/configProvider.js +103 -32
  12. package/dist/cjs/internal/configProvider.js.map +1 -1
  13. package/dist/cjs/internal/core-effect.js +47 -38
  14. package/dist/cjs/internal/core-effect.js.map +1 -1
  15. package/dist/cjs/internal/effect/circular.js +2 -3
  16. package/dist/cjs/internal/effect/circular.js.map +1 -1
  17. package/dist/cjs/internal/fiberRuntime.js +4 -4
  18. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  19. package/dist/cjs/internal/layer.js +3 -1
  20. package/dist/cjs/internal/layer.js.map +1 -1
  21. package/dist/cjs/internal/matcher.js +13 -16
  22. package/dist/cjs/internal/matcher.js.map +1 -1
  23. package/dist/cjs/internal/metric.js +2 -2
  24. package/dist/cjs/internal/metric.js.map +1 -1
  25. package/dist/cjs/internal/version.js +1 -1
  26. package/dist/dts/BigDecimal.d.ts +2 -2
  27. package/dist/dts/BigDecimal.d.ts.map +1 -1
  28. package/dist/dts/ConfigProvider.d.ts +28 -0
  29. package/dist/dts/ConfigProvider.d.ts.map +1 -1
  30. package/dist/dts/Effect.d.ts +12 -7
  31. package/dist/dts/Effect.d.ts.map +1 -1
  32. package/dist/dts/Layer.d.ts +7 -0
  33. package/dist/dts/Layer.d.ts.map +1 -1
  34. package/dist/dts/Match.d.ts +15 -27
  35. package/dist/dts/Match.d.ts.map +1 -1
  36. package/dist/dts/ReadonlyRecord.d.ts +26 -0
  37. package/dist/dts/ReadonlyRecord.d.ts.map +1 -1
  38. package/dist/dts/internal/version.d.ts +1 -1
  39. package/dist/esm/BigDecimal.js +17 -4
  40. package/dist/esm/BigDecimal.js.map +1 -1
  41. package/dist/esm/ConfigProvider.js +7 -0
  42. package/dist/esm/ConfigProvider.js.map +1 -1
  43. package/dist/esm/Effect.js +5 -0
  44. package/dist/esm/Effect.js.map +1 -1
  45. package/dist/esm/Layer.js +7 -0
  46. package/dist/esm/Layer.js.map +1 -1
  47. package/dist/esm/ReadonlyRecord.js +26 -0
  48. package/dist/esm/ReadonlyRecord.js.map +1 -1
  49. package/dist/esm/internal/configProvider.js +101 -31
  50. package/dist/esm/internal/configProvider.js.map +1 -1
  51. package/dist/esm/internal/core-effect.js +43 -35
  52. package/dist/esm/internal/core-effect.js.map +1 -1
  53. package/dist/esm/internal/effect/circular.js +2 -3
  54. package/dist/esm/internal/effect/circular.js.map +1 -1
  55. package/dist/esm/internal/fiberRuntime.js +4 -4
  56. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  57. package/dist/esm/internal/layer.js +2 -0
  58. package/dist/esm/internal/layer.js.map +1 -1
  59. package/dist/esm/internal/matcher.js +13 -16
  60. package/dist/esm/internal/matcher.js.map +1 -1
  61. package/dist/esm/internal/metric.js +2 -2
  62. package/dist/esm/internal/metric.js.map +1 -1
  63. package/dist/esm/internal/version.js +1 -1
  64. package/package.json +1 -1
  65. package/src/BigDecimal.ts +19 -4
  66. package/src/ConfigProvider.ts +32 -0
  67. package/src/Effect.ts +18 -7
  68. package/src/Layer.ts +8 -0
  69. package/src/Match.ts +37 -75
  70. package/src/ReadonlyRecord.ts +28 -0
  71. package/src/internal/configProvider.ts +133 -33
  72. package/src/internal/core-effect.ts +74 -72
  73. package/src/internal/effect/circular.ts +7 -5
  74. package/src/internal/fiberRuntime.ts +4 -4
  75. package/src/internal/layer.ts +3 -0
  76. package/src/internal/matcher.ts +16 -16
  77. package/src/internal/metric.ts +2 -2
  78. package/src/internal/version.ts +1 -1
@@ -827,17 +827,14 @@ export const fiberRefs: Effect.Effect<never, never, FiberRefs.FiberRefs> = core.
827
827
  /* @internal */
828
828
  export const head = <R, E, A>(
829
829
  self: Effect.Effect<R, E, Iterable<A>>
830
- ): Effect.Effect<R, Option.Option<E>, A> =>
831
- core.matchEffect(self, {
832
- onFailure: (e) => core.fail(Option.some(e)),
833
- onSuccess: (as) => {
834
- const iterator = as[Symbol.iterator]()
835
- const next = iterator.next()
836
- if (next.done) {
837
- return core.fail(Option.none())
838
- }
839
- return core.succeed(next.value)
830
+ ): Effect.Effect<R, E | Cause.NoSuchElementException, A> =>
831
+ core.flatMap(self, (as) => {
832
+ const iterator = as[Symbol.iterator]()
833
+ const next = iterator.next()
834
+ if (next.done) {
835
+ return core.fail(new core.NoSuchElementException())
840
836
  }
837
+ return core.succeed(next.value)
841
838
  })
842
839
 
843
840
  /* @internal */
@@ -1109,17 +1106,14 @@ export const negate = <R, E>(self: Effect.Effect<R, E, boolean>): Effect.Effect<
1109
1106
  /* @internal */
1110
1107
  export const none = <R, E, A>(
1111
1108
  self: Effect.Effect<R, E, Option.Option<A>>
1112
- ): Effect.Effect<R, Option.Option<E>, void> =>
1113
- core.matchEffect(self, {
1114
- onFailure: (e) => core.fail(Option.some(e)),
1115
- onSuccess: (option) => {
1116
- switch (option._tag) {
1117
- case "None": {
1118
- return core.unit
1119
- }
1120
- case "Some": {
1121
- return core.fail(Option.none())
1122
- }
1109
+ ): Effect.Effect<R, E | Cause.NoSuchElementException, void> =>
1110
+ core.flatMap(self, (option) => {
1111
+ switch (option._tag) {
1112
+ case "None": {
1113
+ return core.unit
1114
+ }
1115
+ case "Some": {
1116
+ return core.fail(new core.NoSuchElementException())
1123
1117
  }
1124
1118
  }
1125
1119
  })
@@ -1899,6 +1893,10 @@ export const serviceMembers = <I, S>(tag: Context.Tag<I, S>): {
1899
1893
  /** @internal */
1900
1894
  export const serviceOption = <I, S>(tag: Context.Tag<I, S>) => core.map(core.context<never>(), Context.getOption(tag))
1901
1895
 
1896
+ /** @internal */
1897
+ export const serviceOptional = <I, S>(tag: Context.Tag<I, S>) =>
1898
+ core.flatMap(core.context<never>(), Context.getOption(tag))
1899
+
1902
1900
  // -----------------------------------------------------------------------------
1903
1901
  // tracing
1904
1902
  // -----------------------------------------------------------------------------
@@ -1909,21 +1907,19 @@ export const annotateCurrentSpan: {
1909
1907
  (values: Record<string, unknown>): Effect.Effect<never, never, void>
1910
1908
  } = function(): Effect.Effect<never, never, void> {
1911
1909
  const args = arguments
1912
- return core.flatMap(
1910
+ return ignore(core.flatMap(
1913
1911
  currentSpan,
1914
1912
  (span) =>
1915
- span._tag === "Some"
1916
- ? core.sync(() => {
1917
- if (typeof args[0] === "string") {
1918
- span.value.attribute(args[0], args[1])
1919
- } else {
1920
- for (const key in args[0]) {
1921
- span.value.attribute(key, args[0][key])
1922
- }
1913
+ core.sync(() => {
1914
+ if (typeof args[0] === "string") {
1915
+ span.attribute(args[0], args[1])
1916
+ } else {
1917
+ for (const key in args[0]) {
1918
+ span.attribute(key, args[0][key])
1923
1919
  }
1924
- })
1925
- : core.unit
1926
- )
1920
+ }
1921
+ })
1922
+ ))
1927
1923
  }
1928
1924
 
1929
1925
  /* @internal */
@@ -1957,16 +1953,18 @@ export const annotateSpans = dual<
1957
1953
  )
1958
1954
 
1959
1955
  /** @internal */
1960
- export const currentParentSpan: Effect.Effect<never, never, Option.Option<Tracer.ParentSpan>> = serviceOption(
1956
+ export const currentParentSpan: Effect.Effect<never, Cause.NoSuchElementException, Tracer.ParentSpan> = serviceOptional(
1961
1957
  internalTracer.spanTag
1962
1958
  )
1963
1959
 
1964
1960
  /** @internal */
1965
- export const currentSpan: Effect.Effect<never, never, Option.Option<Tracer.Span>> = core.map(
1961
+ export const currentSpan: Effect.Effect<never, Cause.NoSuchElementException, Tracer.Span> = core.flatMap(
1966
1962
  core.context<never>(),
1967
1963
  (context) => {
1968
1964
  const span = context.unsafeMap.get(internalTracer.spanTag) as Tracer.ParentSpan | undefined
1969
- return span !== undefined && span._tag === "Span" ? Option.some(span) : Option.none()
1965
+ return span !== undefined && span._tag === "Span"
1966
+ ? core.succeed(span)
1967
+ : core.fail(new core.NoSuchElementException())
1970
1968
  }
1971
1969
  )
1972
1970
 
@@ -2015,43 +2013,47 @@ export const makeSpan = (
2015
2013
  readonly context?: Context.Context<never> | undefined
2016
2014
  }
2017
2015
  ) =>
2018
- tracerWith((tracer) =>
2019
- core.flatMap(
2020
- options?.parent
2021
- ? succeedSome(options.parent)
2016
+ core.flatMap(fiberRefs, (fiberRefs) =>
2017
+ core.sync(() => {
2018
+ const context = FiberRefs.getOrDefault(fiberRefs, core.currentContext)
2019
+ const services = FiberRefs.getOrDefault(fiberRefs, defaultServices.currentServices)
2020
+
2021
+ const tracer = Context.get(services, internalTracer.tracerTag)
2022
+ const clock = Context.get(services, Clock.Clock)
2023
+ const timingEnabled = FiberRefs.getOrDefault(fiberRefs, core.currentTracerTimingEnabled)
2024
+ const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
2025
+ const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
2026
+
2027
+ const parent = options?.parent
2028
+ ? Option.some(options.parent)
2022
2029
  : options?.root
2023
- ? succeedNone
2024
- : currentParentSpan,
2025
- (parent) =>
2026
- core.flatMap(
2027
- core.fiberRefGet(core.currentTracerSpanAnnotations),
2028
- (annotations) =>
2029
- core.flatMap(
2030
- core.fiberRefGet(core.currentTracerSpanLinks),
2031
- (links) =>
2032
- core.flatMap(
2033
- currentTimeNanosTracing,
2034
- (startTime) =>
2035
- core.sync(() => {
2036
- const linksArray = options?.links
2037
- ? [...Chunk.toReadonlyArray(links), ...options.links]
2038
- : Chunk.toReadonlyArray(links)
2039
- const span = tracer.span(
2040
- name,
2041
- parent,
2042
- options?.context ?? Context.empty(),
2043
- linksArray,
2044
- startTime
2045
- )
2046
- HashMap.forEach(annotations, (value, key) => span.attribute(key, value))
2047
- Object.entries(options?.attributes ?? {}).forEach(([k, v]) => span.attribute(k, v))
2048
- return span
2049
- })
2050
- )
2051
- )
2052
- )
2053
- )
2054
- )
2030
+ ? Option.none()
2031
+ : Context.getOption(context, internalTracer.spanTag)
2032
+
2033
+ const links = linksFromEnv._tag === "Some" ?
2034
+ [
2035
+ ...Chunk.toReadonlyArray(linksFromEnv.value),
2036
+ ...(options?.links ?? [])
2037
+ ] :
2038
+ options?.links ?? []
2039
+
2040
+ const span = tracer.span(
2041
+ name,
2042
+ parent,
2043
+ options?.context ?? Context.empty(),
2044
+ links,
2045
+ timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0
2046
+ )
2047
+
2048
+ if (annotationsFromEnv._tag === "Some") {
2049
+ HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
2050
+ }
2051
+ if (options?.attributes) {
2052
+ Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
2053
+ }
2054
+
2055
+ return span
2056
+ }))
2055
2057
 
2056
2058
  /* @internal */
2057
2059
  export const spanAnnotations: Effect.Effect<never, never, HashMap.HashMap<string, unknown>> = core
@@ -399,12 +399,14 @@ export const supervised = dual<
399
399
  export const timeout = dual<
400
400
  (
401
401
  duration: Duration.DurationInput
402
- ) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, Option.Option<A>>,
403
- <R, E, A>(self: Effect.Effect<R, E, A>, duration: Duration.DurationInput) => Effect.Effect<R, E, Option.Option<A>>
402
+ ) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E | Cause.NoSuchElementException, A>,
403
+ <R, E, A>(
404
+ self: Effect.Effect<R, E, A>,
405
+ duration: Duration.DurationInput
406
+ ) => Effect.Effect<R, E | Cause.NoSuchElementException, A>
404
407
  >(2, (self, duration) =>
405
- timeoutTo(self, {
406
- onTimeout: Option.none,
407
- onSuccess: Option.some,
408
+ timeoutFail(self, {
409
+ onTimeout: () => new core.NoSuchElementException(),
408
410
  duration
409
411
  }))
410
412
 
@@ -80,9 +80,9 @@ export const fiberLifetimes = metric.tagged(
80
80
  metric.histogram(
81
81
  "effect_fiber_lifetimes",
82
82
  metricBoundaries.exponential({
83
- start: 1.0,
84
- factor: 1.3,
85
- count: 100
83
+ start: 0.5,
84
+ factor: 2,
85
+ count: 35
86
86
  })
87
87
  ),
88
88
  "time_unit",
@@ -2225,7 +2225,7 @@ export const mergeAll = dual<
2225
2225
  readonly batching?: boolean | "inherit" | undefined
2226
2226
  }) => Effect.Effect<R, E, Z>
2227
2227
  >(
2228
- (args) => Predicate.isIterable(args[0]),
2228
+ (args) => Predicate.isFunction(args[2]),
2229
2229
  <R, E, A, Z>(elements: Iterable<Effect.Effect<R, E, A>>, zero: Z, f: (z: Z, a: A, i: number) => Z, options?: {
2230
2230
  readonly concurrency?: Concurrency | undefined
2231
2231
  readonly batching?: boolean | "inherit" | undefined
@@ -912,6 +912,9 @@ export const succeedContext = <A>(
912
912
  return fromEffectContext(core.succeed(context))
913
913
  }
914
914
 
915
+ /** @internal */
916
+ export const empty = succeedContext(Context.empty())
917
+
915
918
  /** @internal */
916
919
  export const suspend = <RIn, E, ROut>(
917
920
  evaluate: LazyArg<Layer.Layer<RIn, E, ROut>>
@@ -366,15 +366,10 @@ export const discriminators = <D extends string>(field: D) =>
366
366
  >(
367
367
  fields: P
368
368
  ) => {
369
- const predicates: Array<When> = []
370
- for (const key in fields) {
371
- const pred = (_: any) => _[field] === key
372
- const f = fields[key]
373
- if (f) {
374
- predicates.push(makeWhen(pred, f as any))
375
- }
376
- }
377
- const len = predicates.length
369
+ const predicate = makeWhen(
370
+ (_: any) => _[field] in fields,
371
+ (data: any) => (fields as any)[data[field]](data)
372
+ )
378
373
 
379
374
  return <I, F, A, Pr>(
380
375
  self: Matcher<I, F, R, A, Pr>
@@ -384,13 +379,7 @@ export const discriminators = <D extends string>(field: D) =>
384
379
  Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
385
380
  A | ReturnType<P[keyof P] & {}>,
386
381
  Pr
387
- > => {
388
- let matcher: any = self
389
- for (let i = 0; i < len; i++) {
390
- matcher = matcher.add(predicates[i])
391
- }
392
- return matcher
393
- }
382
+ > => (self as any).add(predicate)
394
383
  }
395
384
 
396
385
  /** @internal */
@@ -532,6 +521,17 @@ export const either: <I, F, R, A, Pr>(
532
521
  }
533
522
 
534
523
  const len = self.cases.length
524
+ if (len === 1) {
525
+ const _case = self.cases[0]
526
+ return (input: I): Either.Either<RA, A> => {
527
+ if (_case._tag === "When" && _case.guard(input) === true) {
528
+ return Either.right(_case.evaluate(input))
529
+ } else if (_case._tag === "Not" && _case.guard(input) === false) {
530
+ return Either.right(_case.evaluate(input))
531
+ }
532
+ return Either.left(input as any)
533
+ }
534
+ }
535
535
  return (input: I): Either.Either<RA, A> => {
536
536
  for (let i = 0; i < len; i++) {
537
537
  const _case = self.cases[i]
@@ -308,9 +308,9 @@ export const timer = (name: string, description?: string): Metric.Metric<
308
308
  MetricState.MetricState.Histogram
309
309
  > => {
310
310
  const boundaries = metricBoundaries.exponential({
311
- start: 1,
311
+ start: 0.5,
312
312
  factor: 2,
313
- count: 100
313
+ count: 35
314
314
  })
315
315
  const base = pipe(histogram(name, boundaries, description), tagged("time_unit", "milliseconds"))
316
316
  return mapInput(base, Duration.toMillis)
@@ -1 +1 @@
1
- export const moduleVersion = "2.0.0-next.60"
1
+ export const moduleVersion = "2.0.0-next.62"