effect 3.0.7 → 3.1.0

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 (96) hide show
  1. package/dist/cjs/Channel.js.map +1 -1
  2. package/dist/cjs/Data.js +15 -1
  3. package/dist/cjs/Data.js.map +1 -1
  4. package/dist/cjs/Effect.js +44 -7
  5. package/dist/cjs/Effect.js.map +1 -1
  6. package/dist/cjs/Layer.js.map +1 -1
  7. package/dist/cjs/SortedMap.js +24 -1
  8. package/dist/cjs/SortedMap.js.map +1 -1
  9. package/dist/cjs/Stream.js +8 -3
  10. package/dist/cjs/Stream.js.map +1 -1
  11. package/dist/cjs/Tracer.js.map +1 -1
  12. package/dist/cjs/internal/cause.js +3 -3
  13. package/dist/cjs/internal/cause.js.map +1 -1
  14. package/dist/cjs/internal/channel.js.map +1 -1
  15. package/dist/cjs/internal/core-effect.js +1 -1
  16. package/dist/cjs/internal/core-effect.js.map +1 -1
  17. package/dist/cjs/internal/core.js +1 -0
  18. package/dist/cjs/internal/core.js.map +1 -1
  19. package/dist/cjs/internal/effect/circular.js +7 -1
  20. package/dist/cjs/internal/effect/circular.js.map +1 -1
  21. package/dist/cjs/internal/fiberRuntime.js +15 -1
  22. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  23. package/dist/cjs/internal/layer/circular.js.map +1 -1
  24. package/dist/cjs/internal/layer.js.map +1 -1
  25. package/dist/cjs/internal/stream.js +23 -3
  26. package/dist/cjs/internal/stream.js.map +1 -1
  27. package/dist/cjs/internal/tracer.js +4 -2
  28. package/dist/cjs/internal/tracer.js.map +1 -1
  29. package/dist/cjs/internal/version.js +1 -1
  30. package/dist/dts/Channel.d.ts +2 -14
  31. package/dist/dts/Channel.d.ts.map +1 -1
  32. package/dist/dts/Data.d.ts +20 -5
  33. package/dist/dts/Data.d.ts.map +1 -1
  34. package/dist/dts/Effect.d.ts +56 -60
  35. package/dist/dts/Effect.d.ts.map +1 -1
  36. package/dist/dts/Layer.d.ts +3 -18
  37. package/dist/dts/Layer.d.ts.map +1 -1
  38. package/dist/dts/SortedMap.d.ts +13 -0
  39. package/dist/dts/SortedMap.d.ts.map +1 -1
  40. package/dist/dts/Stream.d.ts +7 -14
  41. package/dist/dts/Stream.d.ts.map +1 -1
  42. package/dist/dts/Tracer.d.ts +19 -1
  43. package/dist/dts/Tracer.d.ts.map +1 -1
  44. package/dist/dts/Types.d.ts +18 -0
  45. package/dist/dts/Types.d.ts.map +1 -1
  46. package/dist/dts/internal/fiberRuntime.d.ts +6 -1
  47. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  48. package/dist/esm/Channel.js.map +1 -1
  49. package/dist/esm/Data.js +14 -0
  50. package/dist/esm/Data.js.map +1 -1
  51. package/dist/esm/Effect.js +40 -3
  52. package/dist/esm/Effect.js.map +1 -1
  53. package/dist/esm/Layer.js.map +1 -1
  54. package/dist/esm/SortedMap.js +22 -0
  55. package/dist/esm/SortedMap.js.map +1 -1
  56. package/dist/esm/Stream.js +5 -0
  57. package/dist/esm/Stream.js.map +1 -1
  58. package/dist/esm/Tracer.js.map +1 -1
  59. package/dist/esm/internal/cause.js +3 -3
  60. package/dist/esm/internal/cause.js.map +1 -1
  61. package/dist/esm/internal/channel.js.map +1 -1
  62. package/dist/esm/internal/core-effect.js +1 -1
  63. package/dist/esm/internal/core-effect.js.map +1 -1
  64. package/dist/esm/internal/core.js +1 -0
  65. package/dist/esm/internal/core.js.map +1 -1
  66. package/dist/esm/internal/effect/circular.js +6 -0
  67. package/dist/esm/internal/effect/circular.js.map +1 -1
  68. package/dist/esm/internal/fiberRuntime.js +13 -0
  69. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  70. package/dist/esm/internal/layer/circular.js.map +1 -1
  71. package/dist/esm/internal/layer.js.map +1 -1
  72. package/dist/esm/internal/stream.js +19 -0
  73. package/dist/esm/internal/stream.js.map +1 -1
  74. package/dist/esm/internal/tracer.js +4 -2
  75. package/dist/esm/internal/tracer.js.map +1 -1
  76. package/dist/esm/internal/version.js +1 -1
  77. package/package.json +1 -1
  78. package/src/Channel.ts +2 -14
  79. package/src/Data.ts +39 -3
  80. package/src/Effect.ts +60 -66
  81. package/src/Layer.ts +3 -18
  82. package/src/SortedMap.ts +35 -0
  83. package/src/Stream.ts +12 -14
  84. package/src/Tracer.ts +22 -1
  85. package/src/Types.ts +21 -0
  86. package/src/internal/cause.ts +3 -3
  87. package/src/internal/channel.ts +2 -14
  88. package/src/internal/core-effect.ts +19 -43
  89. package/src/internal/core.ts +1 -0
  90. package/src/internal/effect/circular.ts +16 -0
  91. package/src/internal/fiberRuntime.ts +33 -21
  92. package/src/internal/layer/circular.ts +1 -6
  93. package/src/internal/layer.ts +17 -20
  94. package/src/internal/stream.ts +27 -14
  95. package/src/internal/tracer.ts +5 -3
  96. package/src/internal/version.ts +1 -1
@@ -31,6 +31,7 @@ export class NativeSpan {
31
31
  context;
32
32
  links;
33
33
  startTime;
34
+ kind;
34
35
  _tag = "Span";
35
36
  spanId;
36
37
  traceId = "native";
@@ -38,12 +39,13 @@ export class NativeSpan {
38
39
  status;
39
40
  attributes;
40
41
  events = [];
41
- constructor(name, parent, context, links, startTime) {
42
+ constructor(name, parent, context, links, startTime, kind) {
42
43
  this.name = name;
43
44
  this.parent = parent;
44
45
  this.context = context;
45
46
  this.links = links;
46
47
  this.startTime = startTime;
48
+ this.kind = kind;
47
49
  this.status = {
48
50
  _tag: "Started",
49
51
  startTime
@@ -69,7 +71,7 @@ export class NativeSpan {
69
71
  }
70
72
  /** @internal */
71
73
  export const nativeTracer = /*#__PURE__*/make({
72
- span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime),
74
+ span: (name, parent, context, links, startTime, kind) => new NativeSpan(name, parent, context, links, startTime, kind),
73
75
  context: f => f()
74
76
  });
75
77
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"tracer.js","names":["Context","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","randomHexString","characters","charactersLength","length","result","i","charAt","Math","floor","random","NativeSpan","name","parent","context","links","startTime","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","value","end","endTime","exit","attribute","key","set","event","push","nativeTracer","span","f","externalSpan","empty"],"sources":["../../../src/internal/tracer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,eAAe;AAKxC;AACA,OAAO,MAAMC,YAAY,gBAAwBC,MAAM,CAACC,GAAG,CAAC,eAAe,CAAwB;AAEnG;AACA,OAAO,MAAMC,IAAI,GAAIC,OAAiD,KAAqB;EACzF,CAACJ,YAAY,GAAGA,YAAY;EAC5B,GAAGI;CACJ,CAAC;AAEF;AACA,OAAO,MAAMC,SAAS,gBAAGN,OAAO,CAACO,UAAU,CAAgB,eAAe,CAAC;AAE3E;AACA,OAAO,MAAMC,OAAO,gBAAGR,OAAO,CAACO,UAAU,CAAoC,mBAAmB,CAAC;AAEjG,MAAME,eAAe,gBAAI;EACvB,MAAMC,UAAU,GAAG,kBAAkB;EACrC,MAAMC,gBAAgB,GAAGD,UAAU,CAACE,MAAM;EAC1C,OAAO,UAASA,MAAc;IAC5B,IAAIC,MAAM,GAAG,EAAE;IACf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,EAAEE,CAAC,EAAE,EAAE;MAC/BD,MAAM,IAAIH,UAAU,CAACK,MAAM,CAACC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,EAAE,GAAGP,gBAAgB,CAAC,CAAC;IAC3E;IACA,OAAOE,MAAM;EACf,CAAC;AACH,CAAC,CAAC,CAAE;AAEJ;AACA,OAAM,MAAOM,UAAU;EAWVC,IAAA;EACAC,MAAA;EACAC,OAAA;EACAC,KAAA;EACAC,SAAA;EAdFC,IAAI,GAAG,MAAM;EACbC,MAAM;EACNC,OAAO,GAAW,QAAQ;EAC1BC,OAAO,GAAG,IAAI;EAEvBC,MAAM;EACNC,UAAU;EACVC,MA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,EACLC,SAAS,CACV;EACHF,OAAO,EAAGuB,CAAC,IAAKA,CAAC;CAClB,CAAC;AAEF;AACA,OAAO,MAAMC,YAAY,GAAIzC,OAK5B,KAA2B;EAC1BoB,IAAI,EAAE,cAAc;EACpBC,MAAM,EAAErB,OAAO,CAACqB,MAAM;EACtBC,OAAO,EAAEtB,OAAO,CAACsB,OAAO;EACxBC,OAAO,EAAEvB,OAAO,CAACuB,OAAO,IAAI,IAAI;EAChCN,OAAO,EAAEjB,OAAO,CAACiB,OAAO,IAAItB,OAAO,CAAC+C,KAAK;CAC1C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"tracer.js","names":["Context","TracerTypeId","Symbol","for","make","options","tracerTag","GenericTag","spanTag","randomHexString","characters","charactersLength","length","result","i","charAt","Math","floor","random","NativeSpan","name","parent","context","links","startTime","kind","_tag","spanId","traceId","sampled","status","attributes","events","constructor","Map","value","end","endTime","exit","attribute","key","set","event","push","nativeTracer","span","f","externalSpan","empty"],"sources":["../../../src/internal/tracer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,eAAe;AAKxC;AACA,OAAO,MAAMC,YAAY,gBAAwBC,MAAM,CAACC,GAAG,CAAC,eAAe,CAAwB;AAEnG;AACA,OAAO,MAAMC,IAAI,GAAIC,OAAiD,KAAqB;EACzF,CAACJ,YAAY,GAAGA,YAAY;EAC5B,GAAGI;CACJ,CAAC;AAEF;AACA,OAAO,MAAMC,SAAS,gBAAGN,OAAO,CAACO,UAAU,CAAgB,eAAe,CAAC;AAE3E;AACA,OAAO,MAAMC,OAAO,gBAAGR,OAAO,CAACO,UAAU,CAAoC,mBAAmB,CAAC;AAEjG,MAAME,eAAe,gBAAI;EACvB,MAAMC,UAAU,GAAG,kBAAkB;EACrC,MAAMC,gBAAgB,GAAGD,UAAU,CAACE,MAAM;EAC1C,OAAO,UAASA,MAAc;IAC5B,IAAIC,MAAM,GAAG,EAAE;IACf,KAAK,IAAIC,CA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M,MAAM,CAACN;KACxB;EACH;EAEAe,SAASA,CAACC,GAAW,EAAEL,KAAc;IACnC,IAAI,CAACJ,UAAU,CAACU,GAAG,CAACD,GAAG,EAAEL,KAAK,CAAC;EACjC;EAEAO,KAAKA,CAACtB,IAAY,EAAEI,SAAiB,EAAEO,UAAoC;IACzE,IAAI,CAACC,MAAM,CAACW,IAAI,CAAC,CAACvB,IAAI,EAAEI,SAAS,EAAEO,UAAU,IAAI,EAAE,CAAC,CAAC;EACvD;;AAGF;AACA,OAAO,MAAMa,YAAY,gBAAkBxC,IAAI,CAAC;EAC9CyC,IAAI,EAAEA,CAACzB,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,IAAI,KAClD,IAAIN,UAAU,CACZC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,SAAS,EACTC,IAAI,CACL;EACHH,OAAO,EAAGwB,CAAC,IAAKA,CAAC;CAClB,CAAC;AAEF;AACA,OAAO,MAAMC,YAAY,GAAI1C,OAK5B,KAA2B;EAC1BqB,IAAI,EAAE,cAAc;EACpBC,MAAM,EAAEtB,OAAO,CAACsB,MAAM;EACtBC,OAAO,EAAEvB,OAAO,CAACuB,OAAO;EACxBC,OAAO,EAAExB,OAAO,CAACwB,OAAO,IAAI,IAAI;EAChCP,OAAO,EAAEjB,OAAO,CAACiB,OAAO,IAAItB,OAAO,CAACgD,KAAK;CAC1C,CAAC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.0.7";
1
+ let moduleVersion = "3.1.0";
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": "3.0.7",
3
+ "version": "3.1.0",
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
@@ -2107,26 +2107,14 @@ export const updateService: {
2107
2107
  export const withSpan: {
2108
2108
  (
2109
2109
  name: string,
2110
- options?: {
2111
- readonly attributes?: Record<string, unknown> | undefined
2112
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
2113
- readonly parent?: Tracer.AnySpan | undefined
2114
- readonly root?: boolean | undefined
2115
- readonly context?: Context.Context<never> | undefined
2116
- } | undefined
2110
+ options?: Tracer.SpanOptions | undefined
2117
2111
  ): <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2118
2112
  self: Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
2119
2113
  ) => Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Tracer.ParentSpan>>
2120
2114
  <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2121
2115
  self: Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
2122
2116
  name: string,
2123
- options?: {
2124
- readonly attributes?: Record<string, unknown> | undefined
2125
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
2126
- readonly parent?: Tracer.AnySpan | undefined
2127
- readonly root?: boolean | undefined
2128
- readonly context?: Context.Context<never> | undefined
2129
- } | undefined
2117
+ options?: Tracer.SpanOptions | undefined
2130
2118
  ): Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Tracer.ParentSpan>>
2131
2119
  } = channel.withSpan
2132
2120
 
package/src/Data.ts CHANGED
@@ -5,6 +5,7 @@ import type * as Cause from "./Cause.js"
5
5
  import * as core from "./internal/core.js"
6
6
  import * as internal from "./internal/data.js"
7
7
  import { StructuralPrototype } from "./internal/effectable.js"
8
+ import * as Predicate from "./Predicate.js"
8
9
  import type * as Types from "./Types.js"
9
10
 
10
11
  /**
@@ -331,6 +332,23 @@ export declare namespace TaggedEnum {
331
332
  A extends { readonly _tag: string },
332
333
  K extends A["_tag"]
333
334
  > = Extract<A, { readonly _tag: K }>
335
+
336
+ /**
337
+ * @since 3.1.0
338
+ */
339
+ export type Constructor<A extends { readonly _tag: string }> = Types.Simplify<
340
+ & {
341
+ readonly [Tag in A["_tag"]]: Case.Constructor<Extract<A, { readonly _tag: Tag }>, "_tag">
342
+ }
343
+ & {
344
+ readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, { readonly _tag: Tag }>
345
+ readonly $match: <
346
+ Cases extends {
347
+ readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
348
+ }
349
+ >(cases: Cases) => (value: A) => ReturnType<Cases[A["_tag"]]>
350
+ }
351
+ >
334
352
  }
335
353
 
336
354
  /**
@@ -407,16 +425,34 @@ export const taggedEnum: {
407
425
  ) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
408
426
  }
409
427
 
410
- <A extends { readonly _tag: string }>(): {
411
- readonly [Tag in A["_tag"]]: Case.Constructor<Extract<A, { readonly _tag: Tag }>, "_tag">
412
- }
428
+ <A extends { readonly _tag: string }>(): TaggedEnum.Constructor<A>
413
429
  } = () =>
414
430
  new Proxy({}, {
415
431
  get(_target, tag, _receiver) {
432
+ if (tag === "$is") {
433
+ return taggedIs
434
+ } else if (tag === "$match") {
435
+ return taggedMatch
436
+ }
416
437
  return tagged(tag as string)
417
438
  }
418
439
  }) as any
419
440
 
441
+ function taggedIs<A extends { readonly _tag: string }, Tag extends A["_tag"]>(tag: Tag) {
442
+ return Predicate.isTagged(tag)
443
+ }
444
+
445
+ function taggedMatch<
446
+ A extends { readonly _tag: string },
447
+ Cases extends {
448
+ readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
449
+ }
450
+ >(cases: Cases) {
451
+ return function(value: A): ReturnType<Cases[A["_tag"]]> {
452
+ return cases[value._tag as A["_tag"]](value as any)
453
+ }
454
+ }
455
+
420
456
  /**
421
457
  * Provides a constructor for a Case Class.
422
458
  *
package/src/Effect.ts CHANGED
@@ -673,24 +673,15 @@ export const forEach: {
673
673
  readonly discard: true
674
674
  }
675
675
  ): (self: Iterable<A>) => Effect<void, E, R>
676
- <A, B, E, R>(
677
- self: RA.NonEmptyReadonlyArray<A>,
678
- f: (a: A, i: number) => Effect<B, E, R>,
679
- options?: {
680
- readonly concurrency?: Concurrency | undefined
681
- readonly batching?: boolean | "inherit" | undefined
682
- readonly discard?: false | undefined
683
- } | undefined
684
- ): Effect<RA.NonEmptyArray<B>, E, R>
685
- <A, B, E, R>(
686
- self: Iterable<A>,
687
- f: (a: A, i: number) => Effect<B, E, R>,
676
+ <B, E, R, S extends Iterable<any>>(
677
+ self: S,
678
+ f: (a: RA.ReadonlyArray.Infer<S>, i: number) => Effect<B, E, R>,
688
679
  options?: {
689
680
  readonly concurrency?: Concurrency | undefined
690
681
  readonly batching?: boolean | "inherit" | undefined
691
682
  readonly discard?: false | undefined
692
683
  } | undefined
693
- ): Effect<Array<B>, E, R>
684
+ ): Effect<RA.ReadonlyArray.With<S, B>, E, R>
694
685
  <A, B, E, R>(
695
686
  self: Iterable<A>,
696
687
  f: (a: A, i: number) => Effect<B, E, R>,
@@ -1415,7 +1406,7 @@ export interface Adapter {
1415
1406
  }
1416
1407
 
1417
1408
  /**
1418
- * Returns a effect that will never produce anything. The moral equivalent of
1409
+ * Returns an effect that will never produce anything. The moral equivalent of
1419
1410
  * `while(true) {}`, only without the wasted CPU cycles.
1420
1411
  *
1421
1412
  * @since 2.0.0
@@ -2932,9 +2923,8 @@ export const timedWith: {
2932
2923
  } = effect.timedWith
2933
2924
 
2934
2925
  /**
2935
- * Returns an effect that will timeout this effect, returning `None` if the
2936
- * timeout elapses before the effect has produced a value; and returning
2937
- * `Some` of the produced value otherwise.
2926
+ * Returns an effect that will timeout this effect, failing with a `Cause.TimeoutException`
2927
+ * if the timeout elapses before the effect has produced a value.
2938
2928
  *
2939
2929
  * If the timeout elapses without producing a value, the running effect will
2940
2930
  * be safely interrupted.
@@ -2955,6 +2945,30 @@ export const timeout: {
2955
2945
  <A, E, R>(self: Effect<A, E, R>, duration: Duration.DurationInput): Effect<A, Cause.TimeoutException | E, R>
2956
2946
  } = circular.timeout
2957
2947
 
2948
+ /**
2949
+ * Returns an effect that will timeout this effect, returning `None` if the
2950
+ * timeout elapses before the effect has produced a value; and returning
2951
+ * `Some` of the produced value otherwise.
2952
+ *
2953
+ * If the timeout elapses without producing a value, the running effect will
2954
+ * be safely interrupted.
2955
+ *
2956
+ * WARNING: The effect returned by this method will not itself return until
2957
+ * the underlying effect is actually interrupted. This leads to more
2958
+ * predictable resource utilization. If early return is desired, then instead
2959
+ * of using `effect.timeout(d)`, use `effect.disconnect.timeout(d)`, which
2960
+ * first disconnects the effect's interruption signal before performing the
2961
+ * timeout, resulting in earliest possible return, before an underlying effect
2962
+ * has been successfully interrupted.
2963
+ *
2964
+ * @since 3.1.0
2965
+ * @category delays & timeouts
2966
+ */
2967
+ export const timeoutOption: {
2968
+ (duration: Duration.DurationInput): <A, E, R>(self: Effect<A, E, R>) => Effect<Option.Option<A>, E, R>
2969
+ <A, E, R>(self: Effect<A, E, R>, duration: Duration.DurationInput): Effect<Option.Option<A>, E, R>
2970
+ } = circular.timeoutOption
2971
+
2958
2972
  /**
2959
2973
  * The same as `timeout`, but instead of producing a `None` in the event of
2960
2974
  * timeout, it will produce the specified error.
@@ -4438,6 +4452,28 @@ export const annotateLogs: {
4438
4452
  <A, E, R>(effect: Effect<A, E, R>, values: Record<string, unknown>): Effect<A, E, R>
4439
4453
  } = effect.annotateLogs
4440
4454
 
4455
+ /**
4456
+ * Annotates each log with the specified log annotation(s), until the Scope is closed.
4457
+ *
4458
+ * @since 3.1.0
4459
+ * @category logging
4460
+ * @example
4461
+ * import { Effect } from "effect"
4462
+ *
4463
+ * Effect.gen(function*() {
4464
+ * yield* Effect.log("no annotations")
4465
+ * yield* Effect.annotateLogsScoped({ foo: "bar" })
4466
+ * yield* Effect.log("annotated with foo=bar")
4467
+ * }).pipe(
4468
+ * Effect.scoped,
4469
+ * Effect.andThen(Effect.log("no annotations again"))
4470
+ * )
4471
+ */
4472
+ export const annotateLogsScoped: {
4473
+ (key: string, value: unknown): Effect<void, never, Scope.Scope>
4474
+ (values: Record<string, unknown>): Effect<void, never, Scope.Scope>
4475
+ } = fiberRuntime.annotateLogsScoped
4476
+
4441
4477
  /**
4442
4478
  * Retrieves the log annotations associated with the current scope.
4443
4479
  *
@@ -5183,13 +5219,7 @@ export const linkSpans: {
5183
5219
  */
5184
5220
  export const makeSpan: (
5185
5221
  name: string,
5186
- options?: {
5187
- readonly attributes?: Record<string, unknown> | undefined
5188
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5189
- readonly parent?: Tracer.AnySpan | undefined
5190
- readonly root?: boolean | undefined
5191
- readonly context?: Context.Context<never> | undefined
5192
- }
5222
+ options?: Tracer.SpanOptions
5193
5223
  ) => Effect<Tracer.Span> = effect.makeSpan
5194
5224
 
5195
5225
  /**
@@ -5204,13 +5234,7 @@ export const makeSpan: (
5204
5234
  */
5205
5235
  export const makeSpanScoped: (
5206
5236
  name: string,
5207
- options?: {
5208
- readonly attributes?: Record<string, unknown> | undefined
5209
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5210
- readonly parent?: Tracer.AnySpan | undefined
5211
- readonly root?: boolean | undefined
5212
- readonly context?: Context.Context<never> | undefined
5213
- } | undefined
5237
+ options?: Tracer.SpanOptions | undefined
5214
5238
  ) => Effect<Tracer.Span, never, Scope.Scope> = fiberRuntime.makeSpanScoped
5215
5239
 
5216
5240
  /**
@@ -5227,13 +5251,7 @@ export const useSpan: {
5227
5251
  <A, E, R>(name: string, evaluate: (span: Tracer.Span) => Effect<A, E, R>): Effect<A, E, R>
5228
5252
  <A, E, R>(
5229
5253
  name: string,
5230
- options: {
5231
- readonly attributes?: Record<string, unknown> | undefined
5232
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5233
- readonly parent?: Tracer.AnySpan | undefined
5234
- readonly root?: boolean | undefined
5235
- readonly context?: Context.Context<never> | undefined
5236
- },
5254
+ options: Tracer.SpanOptions,
5237
5255
  evaluate: (span: Tracer.Span) => Effect<A, E, R>
5238
5256
  ): Effect<A, E, R>
5239
5257
  } = effect.useSpan
@@ -5247,24 +5265,12 @@ export const useSpan: {
5247
5265
  export const withSpan: {
5248
5266
  (
5249
5267
  name: string,
5250
- options?: {
5251
- readonly attributes?: Record<string, unknown> | undefined
5252
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5253
- readonly parent?: Tracer.AnySpan | undefined
5254
- readonly root?: boolean | undefined
5255
- readonly context?: Context.Context<never> | undefined
5256
- } | undefined
5268
+ options?: Tracer.SpanOptions | undefined
5257
5269
  ): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan>>
5258
5270
  <A, E, R>(
5259
5271
  self: Effect<A, E, R>,
5260
5272
  name: string,
5261
- options?: {
5262
- readonly attributes?: Record<string, unknown> | undefined
5263
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5264
- readonly parent?: Tracer.AnySpan | undefined
5265
- readonly root?: boolean | undefined
5266
- readonly context?: Context.Context<never> | undefined
5267
- } | undefined
5273
+ options?: Tracer.SpanOptions | undefined
5268
5274
  ): Effect<A, E, Exclude<R, Tracer.ParentSpan>>
5269
5275
  } = effect.withSpan
5270
5276
 
@@ -5279,24 +5285,12 @@ export const withSpan: {
5279
5285
  export const withSpanScoped: {
5280
5286
  (
5281
5287
  name: string,
5282
- options?: {
5283
- readonly attributes?: Record<string, unknown> | undefined
5284
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5285
- readonly parent?: Tracer.AnySpan | undefined
5286
- readonly root?: boolean | undefined
5287
- readonly context?: Context.Context<never> | undefined
5288
- }
5288
+ options?: Tracer.SpanOptions
5289
5289
  ): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>
5290
5290
  <A, E, R>(
5291
5291
  self: Effect<A, E, R>,
5292
5292
  name: string,
5293
- options?: {
5294
- readonly attributes?: Record<string, unknown> | undefined
5295
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
5296
- readonly parent?: Tracer.AnySpan | undefined
5297
- readonly root?: boolean | undefined
5298
- readonly context?: Context.Context<never> | undefined
5299
- }
5293
+ options?: Tracer.SpanOptions
5300
5294
  ): Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>
5301
5295
  } = fiberRuntime.withSpanScoped
5302
5296
 
package/src/Layer.ts CHANGED
@@ -959,12 +959,7 @@ export const setScheduler: (scheduler: Scheduler.Scheduler) => Layer<never> = (
959
959
  */
960
960
  export const span: (
961
961
  name: string,
962
- options?: {
963
- readonly attributes?: Record<string, unknown> | undefined
964
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
965
- readonly parent?: Tracer.AnySpan | undefined
966
- readonly root?: boolean | undefined
967
- readonly context?: Context.Context<never> | undefined
962
+ options?: Tracer.SpanOptions & {
968
963
  readonly onEnd?:
969
964
  | ((span: Tracer.Span, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>)
970
965
  | undefined
@@ -1015,12 +1010,7 @@ export const setUnhandledErrorLogLevel: (level: Option.Option<LogLevel>) => Laye
1015
1010
  export const withSpan: {
1016
1011
  (
1017
1012
  name: string,
1018
- options?: {
1019
- readonly attributes?: Record<string, unknown> | undefined
1020
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
1021
- readonly parent?: Tracer.AnySpan | undefined
1022
- readonly root?: boolean | undefined
1023
- readonly context?: Context.Context<never> | undefined
1013
+ options?: Tracer.SpanOptions & {
1024
1014
  readonly onEnd?:
1025
1015
  | ((span: Tracer.Span, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>)
1026
1016
  | undefined
@@ -1029,12 +1019,7 @@ export const withSpan: {
1029
1019
  <A, E, R>(
1030
1020
  self: Layer<A, E, R>,
1031
1021
  name: string,
1032
- options?: {
1033
- readonly attributes?: Record<string, unknown> | undefined
1034
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
1035
- readonly parent?: Tracer.AnySpan | undefined
1036
- readonly root?: boolean | undefined
1037
- readonly context?: Context.Context<never> | undefined
1022
+ options?: Tracer.SpanOptions & {
1038
1023
  readonly onEnd?:
1039
1024
  | ((span: Tracer.Span, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>)
1040
1025
  | undefined
package/src/SortedMap.ts CHANGED
@@ -250,3 +250,38 @@ export const entries = <K, V>(self: SortedMap<K, V>): IterableIterator<[K, V]> =
250
250
  iterator[Symbol.iterator] = () => entries(self)
251
251
  return iterator
252
252
  }
253
+
254
+ /**
255
+ * @since 3.1.0
256
+ * @category elements
257
+ */
258
+ export const lastOption = <K, V>(self: SortedMap<K, V>): Option.Option<[K, V]> => RBT.last(self.tree)
259
+
260
+ /**
261
+ * @since 3.1.0
262
+ * @category filtering
263
+ */
264
+ export const partition: {
265
+ <K, V>(
266
+ predicate: (a: Types.NoInfer<K>) => boolean
267
+ ): (self: SortedMap<K, V>) => [excluded: SortedMap<K, V>, satisfying: SortedMap<K, V>]
268
+ <K, V>(self: SortedMap<K, V>, predicate: (a: K) => boolean): [excluded: SortedMap<K, V>, satisfying: SortedMap<K, V>]
269
+ } = Dual.dual(
270
+ 2,
271
+ <K, V>(
272
+ self: SortedMap<K, V>,
273
+ predicate: (a: K) => boolean
274
+ ): [excluded: SortedMap<K, V>, satisfying: SortedMap<K, V>] => {
275
+ const ord = RBT.getOrder(self.tree)
276
+ let right = empty<K, V>(ord)
277
+ let left = empty<K, V>(ord)
278
+ for (const value of self) {
279
+ if (predicate(value[0])) {
280
+ right = set(right, value[0], value[1])
281
+ } else {
282
+ left = set(left, value[0], value[1])
283
+ }
284
+ }
285
+ return [left, right]
286
+ }
287
+ )
package/src/Stream.ts CHANGED
@@ -4025,24 +4025,12 @@ export const whenEffect: {
4025
4025
  export const withSpan: {
4026
4026
  (
4027
4027
  name: string,
4028
- options?: {
4029
- readonly attributes?: Record<string, unknown> | undefined
4030
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
4031
- readonly parent?: Tracer.AnySpan | undefined
4032
- readonly root?: boolean | undefined
4033
- readonly context?: Context.Context<never> | undefined
4034
- } | undefined
4028
+ options?: Tracer.SpanOptions | undefined
4035
4029
  ): <A, E, R>(self: Stream<A, E, R>) => Stream<A, E, Exclude<R, Tracer.ParentSpan>>
4036
4030
  <A, E, R>(
4037
4031
  self: Stream<A, E, R>,
4038
4032
  name: string,
4039
- options?: {
4040
- readonly attributes?: Record<string, unknown> | undefined
4041
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
4042
- readonly parent?: Tracer.AnySpan | undefined
4043
- readonly root?: boolean | undefined
4044
- readonly context?: Context.Context<never> | undefined
4045
- } | undefined
4033
+ options?: Tracer.SpanOptions | undefined
4046
4034
  ): Stream<A, E, Exclude<R, Tracer.ParentSpan>>
4047
4035
  } = internal.withSpan
4048
4036
 
@@ -4558,3 +4546,13 @@ export const decodeText: {
4558
4546
  * @category encoding
4559
4547
  */
4560
4548
  export const encodeText: <E, R>(self: Stream<string, E, R>) => Stream<Uint8Array, E, R> = internal.encodeText
4549
+
4550
+ /**
4551
+ * Creates a `Stream` using addEventListener.
4552
+ * @since 3.1.0
4553
+ */
4554
+ export const fromEventListener: <A = Event>(
4555
+ target: EventTarget,
4556
+ type: string,
4557
+ options?: boolean | Omit<AddEventListenerOptions, "signal">
4558
+ ) => Stream<A> = internal.fromEventListener
package/src/Tracer.ts CHANGED
@@ -29,7 +29,8 @@ export interface Tracer {
29
29
  parent: Option.Option<AnySpan>,
30
30
  context: Context.Context<never>,
31
31
  links: ReadonlyArray<SpanLink>,
32
- startTime: bigint
32
+ startTime: bigint,
33
+ kind: SpanKind
33
34
  ): Span
34
35
  context<X>(f: () => X, fiber: Fiber.RuntimeFiber<any, any>): X
35
36
  }
@@ -80,6 +81,25 @@ export interface ExternalSpan {
80
81
  readonly context: Context.Context<never>
81
82
  }
82
83
 
84
+ /**
85
+ * @since 3.1.0
86
+ * @category models
87
+ */
88
+ export interface SpanOptions {
89
+ readonly attributes?: Record<string, unknown> | undefined
90
+ readonly links?: ReadonlyArray<SpanLink> | undefined
91
+ readonly parent?: AnySpan | undefined
92
+ readonly root?: boolean | undefined
93
+ readonly context?: Context.Context<never> | undefined
94
+ readonly kind?: SpanKind | undefined
95
+ }
96
+
97
+ /**
98
+ * @since 3.1.0
99
+ * @category models
100
+ */
101
+ export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer"
102
+
83
103
  /**
84
104
  * @since 2.0.0
85
105
  * @category models
@@ -95,6 +115,7 @@ export interface Span {
95
115
  readonly attributes: ReadonlyMap<string, unknown>
96
116
  readonly links: ReadonlyArray<SpanLink>
97
117
  readonly sampled: boolean
118
+ readonly kind: SpanKind
98
119
  end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void
99
120
  attribute(key: string, value: unknown): void
100
121
  event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void
package/src/Types.ts CHANGED
@@ -170,6 +170,27 @@ export type Mutable<T> = {
170
170
  -readonly [P in keyof T]: T[P]
171
171
  }
172
172
 
173
+ /**
174
+ * Like `Types.Mutable`, but works recursively.
175
+ *
176
+ * @example
177
+ * import type * as Types from "effect/Types"
178
+ *
179
+ * type DeepMutableStruct = Types.DeepMutable<{
180
+ * readonly a: string;
181
+ * readonly b: readonly string[]
182
+ * }>
183
+ * // { a: string; b: string[] }
184
+ *
185
+ * @since 3.1.0
186
+ * @category types
187
+ */
188
+ export type DeepMutable<T> = T extends ReadonlyMap<infer K, infer V> ? Map<DeepMutable<K>, DeepMutable<V>>
189
+ : T extends ReadonlySet<infer V> ? Set<DeepMutable<V>>
190
+ : T extends ReadonlyArray<infer V> ? Array<DeepMutable<V>>
191
+ : [keyof T] extends [never] ? T
192
+ : { -readonly [K in keyof T]: DeepMutable<T[K]> }
193
+
173
194
  /**
174
195
  * Avoid inference on a specific parameter
175
196
  *
@@ -686,7 +686,7 @@ const evaluateCause = (
686
686
  break
687
687
  }
688
688
  case OpCodes.OP_FAIL: {
689
- _parallel = HashSet.add(_parallel, cause.error)
689
+ _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.error))
690
690
  if (stack.length === 0) {
691
691
  return [_parallel, _sequential]
692
692
  }
@@ -694,7 +694,7 @@ const evaluateCause = (
694
694
  break
695
695
  }
696
696
  case OpCodes.OP_DIE: {
697
- _parallel = HashSet.add(_parallel, cause.defect)
697
+ _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.defect))
698
698
  if (stack.length === 0) {
699
699
  return [_parallel, _sequential]
700
700
  }
@@ -702,7 +702,7 @@ const evaluateCause = (
702
702
  break
703
703
  }
704
704
  case OpCodes.OP_INTERRUPT: {
705
- _parallel = HashSet.add(_parallel, cause.fiberId as unknown)
705
+ _parallel = HashSet.add(_parallel, Chunk.make(cause._tag, cause.fiberId as unknown))
706
706
  if (stack.length === 0) {
707
707
  return [_parallel, _sequential]
708
708
  }
@@ -2313,26 +2313,14 @@ export const updateService = dual<
2313
2313
  export const withSpan = dual<
2314
2314
  (
2315
2315
  name: string,
2316
- options?: {
2317
- readonly attributes?: Record<string, unknown> | undefined
2318
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
2319
- readonly parent?: Tracer.AnySpan | undefined
2320
- readonly root?: boolean | undefined
2321
- readonly context?: Context.Context<never> | undefined
2322
- }
2316
+ options?: Tracer.SpanOptions
2323
2317
  ) => <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2324
2318
  self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>
2325
2319
  ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Tracer.ParentSpan>>,
2326
2320
  <OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>(
2327
2321
  self: Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Env>,
2328
2322
  name: string,
2329
- options?: {
2330
- readonly attributes?: Record<string, unknown> | undefined
2331
- readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
2332
- readonly parent?: Tracer.AnySpan | undefined
2333
- readonly root?: boolean | undefined
2334
- readonly context?: Context.Context<never> | undefined
2335
- }
2323
+ options?: Tracer.SpanOptions
2336
2324
  ) => Channel.Channel<OutElem, InElem, OutErr, InErr, OutDone, InDone, Exclude<Env, Tracer.ParentSpan>>
2337
2325
  >(3, (self, name, options) =>
2338
2326
  unwrapScoped(