effect 3.11.9 → 3.12.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 (183) hide show
  1. package/dist/cjs/Context.js +28 -1
  2. package/dist/cjs/Context.js.map +1 -1
  3. package/dist/cjs/Cron.js +75 -24
  4. package/dist/cjs/Cron.js.map +1 -1
  5. package/dist/cjs/Effect.js +113 -30
  6. package/dist/cjs/Effect.js.map +1 -1
  7. package/dist/cjs/Encoding.js +43 -2
  8. package/dist/cjs/Encoding.js.map +1 -1
  9. package/dist/cjs/FiberHandle.js +1 -5
  10. package/dist/cjs/FiberHandle.js.map +1 -1
  11. package/dist/cjs/FiberMap.js +1 -5
  12. package/dist/cjs/FiberMap.js.map +1 -1
  13. package/dist/cjs/FiberSet.js +2 -2
  14. package/dist/cjs/FiberSet.js.map +1 -1
  15. package/dist/cjs/JSONSchema.js +3 -30
  16. package/dist/cjs/JSONSchema.js.map +1 -1
  17. package/dist/cjs/Micro.js +1 -1
  18. package/dist/cjs/ParseResult.js +15 -2
  19. package/dist/cjs/ParseResult.js.map +1 -1
  20. package/dist/cjs/Runtime.js.map +1 -1
  21. package/dist/cjs/Schedule.js +2 -2
  22. package/dist/cjs/Schedule.js.map +1 -1
  23. package/dist/cjs/Schema.js +340 -196
  24. package/dist/cjs/Schema.js.map +1 -1
  25. package/dist/cjs/SchemaAST.js +55 -17
  26. package/dist/cjs/SchemaAST.js.map +1 -1
  27. package/dist/cjs/Stream.js +6 -5
  28. package/dist/cjs/Stream.js.map +1 -1
  29. package/dist/cjs/Tracer.js +6 -1
  30. package/dist/cjs/Tracer.js.map +1 -1
  31. package/dist/cjs/internal/cause.js +10 -4
  32. package/dist/cjs/internal/cause.js.map +1 -1
  33. package/dist/cjs/internal/context.js +12 -1
  34. package/dist/cjs/internal/context.js.map +1 -1
  35. package/dist/cjs/internal/core-effect.js +28 -21
  36. package/dist/cjs/internal/core-effect.js.map +1 -1
  37. package/dist/cjs/internal/core.js +15 -20
  38. package/dist/cjs/internal/core.js.map +1 -1
  39. package/dist/cjs/internal/doNotation.js.map +1 -1
  40. package/dist/cjs/internal/encoding/common.js +20 -2
  41. package/dist/cjs/internal/encoding/common.js.map +1 -1
  42. package/dist/cjs/internal/fiberRuntime.js +1 -1
  43. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  44. package/dist/cjs/internal/mailbox.js.map +1 -1
  45. package/dist/cjs/internal/redacted.js +1 -1
  46. package/dist/cjs/internal/redacted.js.map +1 -1
  47. package/dist/cjs/internal/runtime.js +1 -1
  48. package/dist/cjs/internal/runtime.js.map +1 -1
  49. package/dist/cjs/internal/schedule.js +4 -4
  50. package/dist/cjs/internal/schedule.js.map +1 -1
  51. package/dist/cjs/internal/schema/errors.js +10 -10
  52. package/dist/cjs/internal/schema/errors.js.map +1 -1
  53. package/dist/cjs/internal/schema/util.js +2 -2
  54. package/dist/cjs/internal/schema/util.js.map +1 -1
  55. package/dist/cjs/internal/stm/core.js +2 -3
  56. package/dist/cjs/internal/stm/core.js.map +1 -1
  57. package/dist/cjs/internal/tracer.js +6 -1
  58. package/dist/cjs/internal/tracer.js.map +1 -1
  59. package/dist/cjs/internal/version.js +1 -1
  60. package/dist/dts/Context.d.ts +29 -0
  61. package/dist/dts/Context.d.ts.map +1 -1
  62. package/dist/dts/Cron.d.ts +30 -2
  63. package/dist/dts/Cron.d.ts.map +1 -1
  64. package/dist/dts/Effect.d.ts +27 -1
  65. package/dist/dts/Effect.d.ts.map +1 -1
  66. package/dist/dts/Encoding.d.ts +50 -0
  67. package/dist/dts/Encoding.d.ts.map +1 -1
  68. package/dist/dts/FiberHandle.d.ts +2 -2
  69. package/dist/dts/FiberHandle.d.ts.map +1 -1
  70. package/dist/dts/FiberMap.d.ts +2 -2
  71. package/dist/dts/FiberMap.d.ts.map +1 -1
  72. package/dist/dts/FiberSet.d.ts +3 -6
  73. package/dist/dts/FiberSet.d.ts.map +1 -1
  74. package/dist/dts/ParseResult.d.ts.map +1 -1
  75. package/dist/dts/Runtime.d.ts +10 -0
  76. package/dist/dts/Runtime.d.ts.map +1 -1
  77. package/dist/dts/Schedule.d.ts +27 -3
  78. package/dist/dts/Schedule.d.ts.map +1 -1
  79. package/dist/dts/Schema.d.ts +56 -7
  80. package/dist/dts/Schema.d.ts.map +1 -1
  81. package/dist/dts/SchemaAST.d.ts.map +1 -1
  82. package/dist/dts/Stream.d.ts +6 -5
  83. package/dist/dts/Stream.d.ts.map +1 -1
  84. package/dist/dts/Tracer.d.ts +12 -0
  85. package/dist/dts/Tracer.d.ts.map +1 -1
  86. package/dist/dts/internal/core-effect.d.ts.map +1 -1
  87. package/dist/dts/internal/core.d.ts.map +1 -1
  88. package/dist/dts/internal/encoding/common.d.ts.map +1 -1
  89. package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
  90. package/dist/esm/Context.js +27 -0
  91. package/dist/esm/Context.js.map +1 -1
  92. package/dist/esm/Cron.js +72 -22
  93. package/dist/esm/Cron.js.map +1 -1
  94. package/dist/esm/Effect.js +108 -26
  95. package/dist/esm/Effect.js.map +1 -1
  96. package/dist/esm/Encoding.js +39 -0
  97. package/dist/esm/Encoding.js.map +1 -1
  98. package/dist/esm/FiberHandle.js +1 -4
  99. package/dist/esm/FiberHandle.js.map +1 -1
  100. package/dist/esm/FiberMap.js +1 -4
  101. package/dist/esm/FiberMap.js.map +1 -1
  102. package/dist/esm/FiberSet.js +2 -2
  103. package/dist/esm/FiberSet.js.map +1 -1
  104. package/dist/esm/JSONSchema.js +3 -30
  105. package/dist/esm/JSONSchema.js.map +1 -1
  106. package/dist/esm/Micro.js +1 -1
  107. package/dist/esm/Micro.js.map +1 -1
  108. package/dist/esm/ParseResult.js +12 -1
  109. package/dist/esm/ParseResult.js.map +1 -1
  110. package/dist/esm/Runtime.js.map +1 -1
  111. package/dist/esm/Schedule.js +2 -2
  112. package/dist/esm/Schedule.js.map +1 -1
  113. package/dist/esm/Schema.js +328 -186
  114. package/dist/esm/Schema.js.map +1 -1
  115. package/dist/esm/SchemaAST.js +53 -16
  116. package/dist/esm/SchemaAST.js.map +1 -1
  117. package/dist/esm/Stream.js +6 -5
  118. package/dist/esm/Stream.js.map +1 -1
  119. package/dist/esm/Tracer.js +5 -0
  120. package/dist/esm/Tracer.js.map +1 -1
  121. package/dist/esm/internal/cause.js +10 -4
  122. package/dist/esm/internal/cause.js.map +1 -1
  123. package/dist/esm/internal/context.js +10 -0
  124. package/dist/esm/internal/context.js.map +1 -1
  125. package/dist/esm/internal/core-effect.js +28 -21
  126. package/dist/esm/internal/core-effect.js.map +1 -1
  127. package/dist/esm/internal/core.js +9 -15
  128. package/dist/esm/internal/core.js.map +1 -1
  129. package/dist/esm/internal/doNotation.js.map +1 -1
  130. package/dist/esm/internal/encoding/common.js +16 -0
  131. package/dist/esm/internal/encoding/common.js.map +1 -1
  132. package/dist/esm/internal/fiberRuntime.js +1 -1
  133. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  134. package/dist/esm/internal/mailbox.js.map +1 -1
  135. package/dist/esm/internal/redacted.js +1 -1
  136. package/dist/esm/internal/redacted.js.map +1 -1
  137. package/dist/esm/internal/runtime.js +1 -1
  138. package/dist/esm/internal/runtime.js.map +1 -1
  139. package/dist/esm/internal/schedule.js +4 -4
  140. package/dist/esm/internal/schedule.js.map +1 -1
  141. package/dist/esm/internal/schema/errors.js +5 -5
  142. package/dist/esm/internal/schema/errors.js.map +1 -1
  143. package/dist/esm/internal/schema/util.js +2 -2
  144. package/dist/esm/internal/schema/util.js.map +1 -1
  145. package/dist/esm/internal/stm/core.js +1 -2
  146. package/dist/esm/internal/stm/core.js.map +1 -1
  147. package/dist/esm/internal/tracer.js +5 -0
  148. package/dist/esm/internal/tracer.js.map +1 -1
  149. package/dist/esm/internal/version.js +1 -1
  150. package/package.json +2 -2
  151. package/src/Context.ts +30 -0
  152. package/src/Cron.ts +85 -19
  153. package/src/Effect.ts +124 -24
  154. package/src/Encoding.ts +65 -0
  155. package/src/FiberHandle.ts +2 -2
  156. package/src/FiberMap.ts +2 -2
  157. package/src/FiberSet.ts +3 -3
  158. package/src/JSONSchema.ts +3 -29
  159. package/src/Micro.ts +1 -1
  160. package/src/ParseResult.ts +19 -3
  161. package/src/Runtime.ts +11 -0
  162. package/src/Schedule.ts +27 -3
  163. package/src/Schema.ts +282 -142
  164. package/src/SchemaAST.ts +65 -18
  165. package/src/Stream.ts +6 -5
  166. package/src/Tracer.ts +14 -0
  167. package/src/internal/cause.ts +10 -4
  168. package/src/internal/context.ts +13 -0
  169. package/src/internal/core-effect.ts +57 -43
  170. package/src/internal/core.ts +21 -15
  171. package/src/internal/doNotation.ts +1 -1
  172. package/src/internal/encoding/common.ts +21 -0
  173. package/src/internal/fiberRuntime.ts +1 -1
  174. package/src/internal/mailbox.ts +1 -1
  175. package/src/internal/pool.ts +1 -1
  176. package/src/internal/redacted.ts +1 -1
  177. package/src/internal/runtime.ts +1 -1
  178. package/src/internal/schedule.ts +8 -4
  179. package/src/internal/schema/errors.ts +6 -5
  180. package/src/internal/schema/util.ts +2 -2
  181. package/src/internal/stm/core.ts +1 -2
  182. package/src/internal/tracer.ts +6 -0
  183. package/src/internal/version.ts +1 -1
package/src/SchemaAST.ts CHANGED
@@ -1797,7 +1797,12 @@ export class Refinement<From extends AST = AST> implements Annotated {
1797
1797
  * @since 3.10.0
1798
1798
  */
1799
1799
  toString() {
1800
- return Option.getOrElse(getExpected(this), () => `{ ${this.from} | filter }`)
1800
+ return getIdentifierAnnotation(this).pipe(Option.getOrElse(() =>
1801
+ Option.match(getOrElseExpected(this), {
1802
+ onNone: () => `{ ${this.from} | filter }`,
1803
+ onSome: (expected) => isRefinement(this.from) ? String(this.from) + " & " + expected : expected
1804
+ })
1805
+ ))
1801
1806
  }
1802
1807
  /**
1803
1808
  * @since 3.10.0
@@ -2213,7 +2218,7 @@ export const getNumberIndexedAccess = (ast: AST): AST => {
2213
2218
  case "Suspend":
2214
2219
  return getNumberIndexedAccess(ast.f())
2215
2220
  }
2216
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2221
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2217
2222
  }
2218
2223
 
2219
2224
  const getTypeLiteralPropertySignature = (ast: TypeLiteral, name: PropertyKey): PropertySignature | undefined => {
@@ -2282,7 +2287,7 @@ export const getPropertyKeyIndexedAccess = (ast: AST, name: PropertyKey): Proper
2282
2287
  case "Refinement":
2283
2288
  return getPropertyKeyIndexedAccess(ast.from, name)
2284
2289
  }
2285
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2290
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2286
2291
  }
2287
2292
 
2288
2293
  const getPropertyKeys = (ast: AST): Array<PropertyKey> => {
@@ -2327,7 +2332,7 @@ export const record = (key: AST, value: AST): {
2327
2332
  if (Predicate.isString(key.literal) || Predicate.isNumber(key.literal)) {
2328
2333
  propertySignatures.push(new PropertySignature(key.literal, value, false, true))
2329
2334
  } else {
2330
- throw new Error(errors_.getASTUnsupportedLiteral(key.literal))
2335
+ throw new Error(errors_.getASTUnsupportedLiteralErrorMessage(key.literal))
2331
2336
  }
2332
2337
  break
2333
2338
  case "Enums": {
@@ -2343,7 +2348,7 @@ export const record = (key: AST, value: AST): {
2343
2348
  key.types.forEach(go)
2344
2349
  break
2345
2350
  default:
2346
- throw new Error(errors_.getASTUnsupportedKeySchema(key))
2351
+ throw new Error(errors_.getASTUnsupportedKeySchemaErrorMessage(key))
2347
2352
  }
2348
2353
  }
2349
2354
  go(key)
@@ -2417,7 +2422,7 @@ export const pick = (ast: AST, keys: ReadonlyArray<PropertyKey>): TypeLiteral |
2417
2422
  }
2418
2423
  }
2419
2424
  }
2420
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2425
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2421
2426
  }
2422
2427
 
2423
2428
  /**
@@ -2460,9 +2465,8 @@ export const partial = (ast: AST, options?: { readonly exact: true }): AST => {
2460
2465
  case "Suspend":
2461
2466
  return new Suspend(() => partial(ast.f(), options))
2462
2467
  case "Declaration":
2463
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2464
2468
  case "Refinement":
2465
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2469
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2466
2470
  case "Transformation": {
2467
2471
  if (
2468
2472
  isTypeLiteralTransformation(ast.transformation) &&
@@ -2470,7 +2474,7 @@ export const partial = (ast: AST, options?: { readonly exact: true }): AST => {
2470
2474
  ) {
2471
2475
  return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation)
2472
2476
  }
2473
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2477
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2474
2478
  }
2475
2479
  }
2476
2480
  return ast
@@ -2499,9 +2503,8 @@ export const required = (ast: AST): AST => {
2499
2503
  case "Suspend":
2500
2504
  return new Suspend(() => required(ast.f()))
2501
2505
  case "Declaration":
2502
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2503
2506
  case "Refinement":
2504
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2507
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2505
2508
  case "Transformation": {
2506
2509
  if (
2507
2510
  isTypeLiteralTransformation(ast.transformation) &&
@@ -2509,7 +2512,7 @@ export const required = (ast: AST): AST => {
2509
2512
  ) {
2510
2513
  return new Transformation(required(ast.from), required(ast.to), ast.transformation)
2511
2514
  }
2512
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2515
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2513
2516
  }
2514
2517
  }
2515
2518
  return ast
@@ -2876,7 +2879,7 @@ const _keyof = (ast: AST): Array<AST> => {
2876
2879
  case "Transformation":
2877
2880
  return _keyof(ast.to)
2878
2881
  }
2879
- throw new Error(errors_.getASTUnsupportedSchema(ast))
2882
+ throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2880
2883
  }
2881
2884
 
2882
2885
  /** @internal */
@@ -2928,15 +2931,59 @@ export const rename = (ast: AST, mapping: { readonly [K in PropertyKey]?: Proper
2928
2931
  case "Transformation":
2929
2932
  return compose(ast, rename(typeAST(ast), mapping))
2930
2933
  }
2931
- throw new Error(errors_.getASTUnsupportedRenameSchema(ast))
2934
+ throw new Error(errors_.getASTUnsupportedRenameSchemaErrorMessage(ast))
2932
2935
  }
2933
2936
 
2934
2937
  const formatKeyword = (ast: AST): string => Option.getOrElse(getExpected(ast), () => ast._tag)
2935
2938
 
2936
- const getExpected = (ast: Annotated): Option.Option<string> => {
2937
- return getIdentifierAnnotation(ast).pipe(
2938
- Option.orElse(() => getTitleAnnotation(ast)),
2939
+ function getBrands(ast: Annotated): string {
2940
+ return Option.match(getBrandAnnotation(ast), {
2941
+ onNone: () => "",
2942
+ onSome: (brands) => brands.map((brand) => ` & Brand<${util_.formatUnknown(brand)}>`).join("")
2943
+ })
2944
+ }
2945
+
2946
+ const getOrElseExpected = (ast: Annotated): Option.Option<string> =>
2947
+ getTitleAnnotation(ast).pipe(
2939
2948
  Option.orElse(() => getDescriptionAnnotation(ast)),
2940
- Option.orElse(() => getAutoTitleAnnotation(ast))
2949
+ Option.orElse(() => getAutoTitleAnnotation(ast)),
2950
+ Option.map((s) => s + getBrands(ast))
2941
2951
  )
2952
+
2953
+ const getExpected = (ast: Annotated): Option.Option<string> =>
2954
+ Option.orElse(getIdentifierAnnotation(ast), () => getOrElseExpected(ast))
2955
+
2956
+ /** @internal */
2957
+ export const pruneUndefined = (
2958
+ ast: AST,
2959
+ self: (ast: AST) => AST | undefined,
2960
+ onTransformation: (ast: Transformation) => AST | undefined
2961
+ ): AST | undefined => {
2962
+ switch (ast._tag) {
2963
+ case "UndefinedKeyword":
2964
+ return neverKeyword
2965
+ case "Union": {
2966
+ const types: Array<AST> = []
2967
+ let hasUndefined = false
2968
+ for (const type of ast.types) {
2969
+ const pruned = self(type)
2970
+ if (pruned) {
2971
+ hasUndefined = true
2972
+ if (!isNeverKeyword(pruned)) {
2973
+ types.push(pruned)
2974
+ }
2975
+ } else {
2976
+ types.push(type)
2977
+ }
2978
+ }
2979
+ if (hasUndefined) {
2980
+ return Union.make(types)
2981
+ }
2982
+ break
2983
+ }
2984
+ case "Suspend":
2985
+ return self(ast.f())
2986
+ case "Transformation":
2987
+ return onTransformation(ast)
2988
+ }
2942
2989
  }
package/src/Stream.ts CHANGED
@@ -8380,11 +8380,12 @@ export const scheduleWith: {
8380
8380
  *
8381
8381
  * // Creating a single-valued stream from a scoped resource
8382
8382
  * const stream = Stream.scoped(
8383
- * Effect.acquireUseRelease(
8384
- * Console.log("acquire"),
8385
- * () => Console.log("use"),
8386
- * () => Console.log("release")
8387
- * )
8383
+ * Effect.acquireRelease(
8384
+ * Console.log("acquire"),
8385
+ * () => Console.log("release")
8386
+ * )
8387
+ * ).pipe(
8388
+ * Stream.flatMap(() => Console.log("use"))
8388
8389
  * )
8389
8390
  *
8390
8391
  * // Effect.runPromise(Stream.runCollect(stream)).then(console.log)
package/src/Tracer.ts CHANGED
@@ -164,3 +164,17 @@ export const externalSpan: (
164
164
  */
165
165
  export const tracerWith: <A, E, R>(f: (tracer: Tracer) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> =
166
166
  defaultServices.tracerWith
167
+
168
+ /**
169
+ * @since 3.12.0
170
+ * @category annotations
171
+ */
172
+ export interface DisablePropagation {
173
+ readonly _: unique symbol
174
+ }
175
+
176
+ /**
177
+ * @since 3.12.0
178
+ * @category annotations
179
+ */
180
+ export const DisablePropagation: Context.Reference<DisablePropagation, boolean> = internal.DisablePropagation
@@ -1073,7 +1073,7 @@ export const prettyErrorMessage = (u: unknown): string => {
1073
1073
  return stringifyCircular(u)
1074
1074
  }
1075
1075
 
1076
- const locationRegex = /\((.*)\)/
1076
+ const locationRegex = /\((.*)\)/g
1077
1077
 
1078
1078
  /** @internal */
1079
1079
  export const spanToTrace = globalValue("effect/Tracer/spanToTrace", () => new WeakMap())
@@ -1105,9 +1105,15 @@ const prettyErrorStack = (message: string, stack: string, span?: Span | undefine
1105
1105
  if (typeof stackFn === "function") {
1106
1106
  const stack = stackFn()
1107
1107
  if (typeof stack === "string") {
1108
- const locationMatch = stack.match(locationRegex)
1109
- const location = locationMatch ? locationMatch[1] : stack.replace(/^at /, "")
1110
- out.push(` at ${current.name} (${location})`)
1108
+ const locationMatchAll = stack.matchAll(locationRegex)
1109
+ let match = false
1110
+ for (const [, location] of locationMatchAll) {
1111
+ match = true
1112
+ out.push(` at ${current.name} (${location})`)
1113
+ }
1114
+ if (!match) {
1115
+ out.push(` at ${current.name} (${stack.replace(/^at /, "")})`)
1116
+ }
1111
1117
  } else {
1112
1118
  out.push(` at ${current.name}`)
1113
1119
  }
@@ -295,6 +295,19 @@ export const merge = dual<
295
295
  return makeContext(map)
296
296
  })
297
297
 
298
+ /** @internal */
299
+ export const mergeAll = <T extends Array<unknown>>(
300
+ ...ctxs: [...{ [K in keyof T]: C.Context<T[K]> }]
301
+ ): C.Context<T[number]> => {
302
+ const map = new Map()
303
+ for (const ctx of ctxs) {
304
+ for (const [tag, s] of ctx.unsafeMap) {
305
+ map.set(tag, s)
306
+ }
307
+ }
308
+ return makeContext(map)
309
+ }
310
+
298
311
  /** @internal */
299
312
  export const pick =
300
313
  <Services, S extends Array<C.ValidTagsById<Services>>>(...tags: S) =>
@@ -1,5 +1,3 @@
1
- import type { Exit } from "effect/Exit"
2
- import { internalCall } from "effect/Utils"
3
1
  import * as Arr from "../Array.js"
4
2
  import type * as Cause from "../Cause.js"
5
3
  import * as Chunk from "../Chunk.js"
@@ -7,6 +5,7 @@ import * as Clock from "../Clock.js"
7
5
  import * as Context from "../Context.js"
8
6
  import * as Duration from "../Duration.js"
9
7
  import type * as Effect from "../Effect.js"
8
+ import type { Exit } from "../Exit.js"
10
9
  import type * as Fiber from "../Fiber.js"
11
10
  import type * as FiberId from "../FiberId.js"
12
11
  import type * as FiberRef from "../FiberRef.js"
@@ -29,6 +28,7 @@ import type * as runtimeFlagsPatch from "../RuntimeFlagsPatch.js"
29
28
  import * as Tracer from "../Tracer.js"
30
29
  import type { NoInfer } from "../Types.js"
31
30
  import type { Unify } from "../Unify.js"
31
+ import { internalCall } from "../Utils.js"
32
32
  import * as internalCause from "./cause.js"
33
33
  import { clockTag } from "./clock.js"
34
34
  import * as core from "./core.js"
@@ -2020,61 +2020,75 @@ export const linkSpans = dual<
2020
2020
 
2021
2021
  const bigint0 = BigInt(0)
2022
2022
 
2023
+ const filterDisablePropagation: (self: Option.Option<Tracer.AnySpan>) => Option.Option<Tracer.AnySpan> = Option.flatMap(
2024
+ (span) =>
2025
+ Context.get(span.context, internalTracer.DisablePropagation)
2026
+ ? span._tag === "Span" ? filterDisablePropagation(span.parent) : Option.none()
2027
+ : Option.some(span)
2028
+ )
2029
+
2023
2030
  /** @internal */
2024
2031
  export const unsafeMakeSpan = <XA, XE>(
2025
2032
  fiber: FiberRuntime<XA, XE>,
2026
2033
  name: string,
2027
2034
  options: Tracer.SpanOptions
2028
2035
  ) => {
2029
- const enabled = fiber.getFiberRef(core.currentTracerEnabled)
2030
- if (enabled === false) {
2031
- return core.noopSpan(name)
2032
- }
2033
-
2036
+ const disablePropagation = !fiber.getFiberRef(core.currentTracerEnabled) ||
2037
+ (options.context && Context.get(options.context, internalTracer.DisablePropagation))
2034
2038
  const context = fiber.getFiberRef(core.currentContext)
2035
- const services = fiber.getFiberRef(defaultServices.currentServices)
2036
-
2037
- const tracer = Context.get(services, internalTracer.tracerTag)
2038
- const clock = Context.get(services, Clock.Clock)
2039
- const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2040
-
2041
- const fiberRefs = fiber.getFiberRefs()
2042
- const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
2043
- const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
2044
-
2045
2039
  const parent = options.parent
2046
2040
  ? Option.some(options.parent)
2047
2041
  : options.root
2048
2042
  ? Option.none()
2049
- : Context.getOption(context, internalTracer.spanTag)
2050
-
2051
- const links = linksFromEnv._tag === "Some" ?
2052
- options.links !== undefined ?
2053
- [
2054
- ...Chunk.toReadonlyArray(linksFromEnv.value),
2055
- ...(options.links ?? [])
2056
- ] :
2057
- Chunk.toReadonlyArray(linksFromEnv.value) :
2058
- options.links ?? Arr.empty()
2059
-
2060
- const span = tracer.span(
2061
- name,
2062
- parent,
2063
- options.context ?? Context.empty(),
2064
- links,
2065
- timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0,
2066
- options.kind ?? "internal"
2067
- )
2043
+ : filterDisablePropagation(Context.getOption(context, internalTracer.spanTag))
2068
2044
 
2069
- if (typeof options.captureStackTrace === "function") {
2070
- internalCause.spanToTrace.set(span, options.captureStackTrace)
2071
- }
2045
+ let span: Tracer.Span
2072
2046
 
2073
- if (annotationsFromEnv._tag === "Some") {
2074
- HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
2047
+ if (disablePropagation) {
2048
+ span = core.noopSpan({
2049
+ name,
2050
+ parent,
2051
+ context: Context.add(options.context ?? Context.empty(), internalTracer.DisablePropagation, true)
2052
+ })
2053
+ } else {
2054
+ const services = fiber.getFiberRef(defaultServices.currentServices)
2055
+
2056
+ const tracer = Context.get(services, internalTracer.tracerTag)
2057
+ const clock = Context.get(services, Clock.Clock)
2058
+ const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2059
+
2060
+ const fiberRefs = fiber.getFiberRefs()
2061
+ const annotationsFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanAnnotations)
2062
+ const linksFromEnv = FiberRefs.get(fiberRefs, core.currentTracerSpanLinks)
2063
+
2064
+ const links = linksFromEnv._tag === "Some" ?
2065
+ options.links !== undefined ?
2066
+ [
2067
+ ...Chunk.toReadonlyArray(linksFromEnv.value),
2068
+ ...(options.links ?? [])
2069
+ ] :
2070
+ Chunk.toReadonlyArray(linksFromEnv.value) :
2071
+ options.links ?? Arr.empty()
2072
+
2073
+ span = tracer.span(
2074
+ name,
2075
+ parent,
2076
+ options.context ?? Context.empty(),
2077
+ links,
2078
+ timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0,
2079
+ options.kind ?? "internal"
2080
+ )
2081
+
2082
+ if (annotationsFromEnv._tag === "Some") {
2083
+ HashMap.forEach(annotationsFromEnv.value, (value, key) => span.attribute(key, value))
2084
+ }
2085
+ if (options.attributes !== undefined) {
2086
+ Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
2087
+ }
2075
2088
  }
2076
- if (options.attributes !== undefined) {
2077
- Object.entries(options.attributes).forEach(([k, v]) => span.attribute(k, v))
2089
+
2090
+ if (typeof options.captureStackTrace === "function") {
2091
+ internalCause.spanToTrace.set(span, options.captureStackTrace)
2078
2092
  }
2079
2093
 
2080
2094
  return span
@@ -1,4 +1,3 @@
1
- import { internalCall } from "effect/Utils"
2
1
  import * as Arr from "../Array.js"
3
2
  import type * as Cause from "../Cause.js"
4
3
  import * as Chunk from "../Chunk.js"
@@ -38,7 +37,7 @@ import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js"
38
37
  import type * as Scope from "../Scope.js"
39
38
  import type * as Tracer from "../Tracer.js"
40
39
  import type { NoInfer, NotFunction } from "../Types.js"
41
- import { YieldWrap } from "../Utils.js"
40
+ import { internalCall, YieldWrap } from "../Utils.js"
42
41
  import * as _blockedRequests from "./blockedRequests.js"
43
42
  import * as internalCause from "./cause.js"
44
43
  import * as deferred from "./deferred.js"
@@ -1428,13 +1427,23 @@ export const whileLoop = <A, E, R>(
1428
1427
  }
1429
1428
 
1430
1429
  /* @internal */
1431
- export const gen: typeof Effect.gen = function() {
1432
- const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
1433
- return suspend(() => {
1430
+ export const fromIterator = <Eff extends YieldWrap<Effect.Effect<any, any, any>>, AEff>(
1431
+ iterator: LazyArg<Iterator<Eff, AEff, never>>
1432
+ ): Effect.Effect<
1433
+ AEff,
1434
+ [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
1435
+ [Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
1436
+ > =>
1437
+ suspend(() => {
1434
1438
  const effect = new EffectPrimitive(OpCodes.OP_ITERATOR) as any
1435
- effect.effect_instruction_i0 = f(pipe)
1439
+ effect.effect_instruction_i0 = iterator()
1436
1440
  return effect
1437
1441
  })
1442
+
1443
+ /* @internal */
1444
+ export const gen: typeof Effect.gen = function() {
1445
+ const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
1446
+ return fromIterator(() => f(pipe))
1438
1447
  }
1439
1448
 
1440
1449
  /* @internal */
@@ -3063,14 +3072,11 @@ export const currentSpanFromFiber = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Opt
3063
3072
  return span !== undefined && span._tag === "Span" ? Option.some(span) : Option.none()
3064
3073
  }
3065
3074
 
3066
- const NoopSpanProto: Tracer.Span = {
3075
+ const NoopSpanProto: Omit<Tracer.Span, "parent" | "name" | "context"> = {
3067
3076
  _tag: "Span",
3068
3077
  spanId: "noop",
3069
3078
  traceId: "noop",
3070
- name: "noop",
3071
3079
  sampled: false,
3072
- parent: Option.none(),
3073
- context: Context.empty(),
3074
3080
  status: {
3075
3081
  _tag: "Ended",
3076
3082
  startTime: BigInt(0),
@@ -3086,8 +3092,8 @@ const NoopSpanProto: Tracer.Span = {
3086
3092
  }
3087
3093
 
3088
3094
  /** @internal */
3089
- export const noopSpan = (name: string): Tracer.Span => {
3090
- const span = Object.create(NoopSpanProto)
3091
- span.name = name
3092
- return span
3093
- }
3095
+ export const noopSpan = (options: {
3096
+ readonly name: string
3097
+ readonly parent: Option.Option<Tracer.AnySpan>
3098
+ readonly context: Context.Context<never>
3099
+ }): Tracer.Span => Object.assign(Object.create(NoopSpanProto), options)
@@ -1,6 +1,6 @@
1
- import type { NoInfer } from "effect/Types"
2
1
  import { dual } from "../Function.js"
3
2
  import type { Kind, TypeLambda } from "../HKT.js"
3
+ import type { NoInfer } from "../Types.js"
4
4
 
5
5
  type Map<F extends TypeLambda> = {
6
6
  <A, B>(f: (a: A) => B): <R, O, E>(self: Kind<F, R, O, E, A>) => Kind<F, R, O, E, B>
@@ -23,6 +23,27 @@ export const DecodeException = (input: string, message?: string): Encoding.Decod
23
23
  /** @internal */
24
24
  export const isDecodeException = (u: unknown): u is Encoding.DecodeException => hasProperty(u, DecodeExceptionTypeId)
25
25
 
26
+ /** @internal */
27
+ export const EncodeExceptionTypeId: Encoding.EncodeExceptionTypeId = Symbol.for(
28
+ "effect/Encoding/errors/Encode"
29
+ ) as Encoding.EncodeExceptionTypeId
30
+
31
+ /** @internal */
32
+ export const EncodeException = (input: string, message?: string): Encoding.EncodeException => {
33
+ const out: Mutable<Encoding.EncodeException> = {
34
+ _tag: "EncodeException",
35
+ [EncodeExceptionTypeId]: EncodeExceptionTypeId,
36
+ input
37
+ }
38
+ if (isString(message)) {
39
+ out.message = message
40
+ }
41
+ return out
42
+ }
43
+
44
+ /** @internal */
45
+ export const isEncodeException = (u: unknown): u is Encoding.EncodeException => hasProperty(u, EncodeExceptionTypeId)
46
+
26
47
  /** @interal */
27
48
  export const encoder = new TextEncoder()
28
49
 
@@ -1,4 +1,3 @@
1
- import { internalCall, yieldWrapGet } from "effect/Utils"
2
1
  import * as RA from "../Array.js"
3
2
  import * as Boolean from "../Boolean.js"
4
3
  import type * as Cause from "../Cause.js"
@@ -45,6 +44,7 @@ import type * as Scope from "../Scope.js"
45
44
  import type * as Supervisor from "../Supervisor.js"
46
45
  import type * as Tracer from "../Tracer.js"
47
46
  import type { Concurrency, NoInfer } from "../Types.js"
47
+ import { internalCall, yieldWrapGet } from "../Utils.js"
48
48
  import * as _RequestBlock from "./blockedRequests.js"
49
49
  import * as internalCause from "./cause.js"
50
50
  import * as clock from "./clock.js"
@@ -1,4 +1,3 @@
1
- import type { Scope } from "effect/Scope"
2
1
  import * as Arr from "../Array.js"
3
2
  import type { Cause } from "../Cause.js"
4
3
  import { NoSuchElementException } from "../Cause.js"
@@ -15,6 +14,7 @@ import * as Option from "../Option.js"
15
14
  import { pipeArguments } from "../Pipeable.js"
16
15
  import { hasProperty } from "../Predicate.js"
17
16
  import type { Scheduler } from "../Scheduler.js"
17
+ import type { Scope } from "../Scope.js"
18
18
  import type { Stream } from "../Stream.js"
19
19
  import * as channel from "./channel.js"
20
20
  import * as channelExecutor from "./channel/channelExecutor.js"
@@ -1,4 +1,4 @@
1
- import type { Cause } from "effect/Cause"
1
+ import type { Cause } from "../Cause.js"
2
2
  import * as Context from "../Context.js"
3
3
  import * as Duration from "../Duration.js"
4
4
  import type { Effect, Semaphore } from "../Effect.js"
@@ -1,8 +1,8 @@
1
- import { NodeInspectSymbol } from "effect/Inspectable"
2
1
  import * as Equal from "../Equal.js"
3
2
  import { pipe } from "../Function.js"
4
3
  import { globalValue } from "../GlobalValue.js"
5
4
  import * as Hash from "../Hash.js"
5
+ import { NodeInspectSymbol } from "../Inspectable.js"
6
6
  import { pipeArguments } from "../Pipeable.js"
7
7
  import { hasProperty } from "../Predicate.js"
8
8
  import type * as Redacted from "../Redacted.js"
@@ -1,8 +1,8 @@
1
- import { equals } from "effect/Equal"
2
1
  import type * as ReadonlyArray from "../Array.js"
3
2
  import type * as Cause from "../Cause.js"
4
3
  import * as Context from "../Context.js"
5
4
  import type * as Effect from "../Effect.js"
5
+ import { equals } from "../Equal.js"
6
6
  import * as Exit from "../Exit.js"
7
7
  import * as Fiber from "../Fiber.js"
8
8
  import * as FiberId from "../FiberId.js"
@@ -3,6 +3,7 @@ import * as Chunk from "../Chunk.js"
3
3
  import * as Clock from "../Clock.js"
4
4
  import * as Context from "../Context.js"
5
5
  import * as Cron from "../Cron.js"
6
+ import type * as DateTime from "../DateTime.js"
6
7
  import * as Duration from "../Duration.js"
7
8
  import type * as Effect from "../Effect.js"
8
9
  import * as Either from "../Either.js"
@@ -413,8 +414,11 @@ export const mapInputEffect = dual<
413
414
  )))
414
415
 
415
416
  /** @internal */
416
- export const cron = (expression: string | Cron.Cron): Schedule.Schedule<[number, number]> => {
417
- const parsed = Cron.isCron(expression) ? Either.right(expression) : Cron.parse(expression)
417
+ export const cron: {
418
+ (expression: Cron.Cron): Schedule.Schedule<[number, number]>
419
+ (expression: string, tz?: DateTime.TimeZone | string): Schedule.Schedule<[number, number]>
420
+ } = (expression: string | Cron.Cron, tz?: DateTime.TimeZone | string): Schedule.Schedule<[number, number]> => {
421
+ const parsed = Cron.isCron(expression) ? Either.right(expression) : Cron.parse(expression, tz)
418
422
  return makeWithState<[boolean, [number, number, number]], unknown, [number, number]>(
419
423
  [true, [Number.MIN_SAFE_INTEGER, 0, 0]],
420
424
  (now, _, [initial, previous]) => {
@@ -439,8 +443,8 @@ export const cron = (expression: string | Cron.Cron): Schedule.Schedule<[number,
439
443
  }
440
444
 
441
445
  next = Cron.next(cron, date).getTime()
442
- const start = beginningOfMinute(next)
443
- const end = endOfMinute(next)
446
+ const start = beginningOfSecond(next)
447
+ const end = endOfSecond(next)
444
448
  return core.succeed([
445
449
  [false, [next, start, end]],
446
450
  [start, end],
@@ -1,4 +1,4 @@
1
- import * as array_ from "effect/Array"
1
+ import * as array_ from "../../Array.js"
2
2
  import type * as AST from "../../SchemaAST.js"
3
3
  import * as util_ from "./util.js"
4
4
 
@@ -150,14 +150,15 @@ export const getSchemaUnsupportedLiteralSpanErrorMessage = (ast: AST.AST) =>
150
150
  // ---------------------------------------------
151
151
 
152
152
  /** @internal */
153
- export const getASTUnsupportedSchema = (ast: AST.AST) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast)
153
+ export const getASTUnsupportedSchemaErrorMessage = (ast: AST.AST) =>
154
+ getUnsupportedSchemaErrorMessage(undefined, undefined, ast)
154
155
 
155
156
  /** @internal */
156
- export const getASTUnsupportedKeySchema = (ast: AST.AST) =>
157
+ export const getASTUnsupportedKeySchemaErrorMessage = (ast: AST.AST) =>
157
158
  getErrorMessage("Unsupported key schema", undefined, undefined, ast)
158
159
 
159
160
  /** @internal */
160
- export const getASTUnsupportedLiteral = (literal: AST.LiteralValue) =>
161
+ export const getASTUnsupportedLiteralErrorMessage = (literal: AST.LiteralValue) =>
161
162
  getErrorMessage("Unsupported literal", `literal value: ${util_.formatUnknown(literal)}`)
162
163
 
163
164
  /** @internal */
@@ -181,7 +182,7 @@ export const getASTDuplicatePropertySignatureTransformationErrorMessage = (key:
181
182
  getErrorMessage("Duplicate property signature transformation", `Duplicate key ${util_.formatUnknown(key)}`)
182
183
 
183
184
  /** @internal */
184
- export const getASTUnsupportedRenameSchema = (ast: AST.AST): string =>
185
+ export const getASTUnsupportedRenameSchemaErrorMessage = (ast: AST.AST): string =>
185
186
  getUnsupportedSchemaErrorMessage(undefined, undefined, ast)
186
187
 
187
188
  /** @internal */
@@ -1,6 +1,6 @@
1
- import * as array_ from "effect/Array"
2
- import * as Predicate from "effect/Predicate"
1
+ import * as array_ from "../../Array.js"
3
2
  import type * as ParseResult from "../../ParseResult.js"
3
+ import * as Predicate from "../../Predicate.js"
4
4
  import type * as AST from "../../SchemaAST.js"
5
5
 
6
6
  /** @internal */
@@ -1,4 +1,3 @@
1
- import { internalCall } from "effect/Utils"
2
1
  import * as Cause from "../../Cause.js"
3
2
  import * as Context from "../../Context.js"
4
3
  import * as Effect from "../../Effect.js"
@@ -15,7 +14,7 @@ import { pipeArguments } from "../../Pipeable.js"
15
14
  import { hasProperty } from "../../Predicate.js"
16
15
  import type * as Scheduler from "../../Scheduler.js"
17
16
  import type * as STM from "../../STM.js"
18
- import { YieldWrap } from "../../Utils.js"
17
+ import { internalCall, YieldWrap } from "../../Utils.js"
19
18
  import { ChannelTypeId } from "../core-stream.js"
20
19
  import { withFiberRuntime } from "../core.js"
21
20
  import { effectVariance, StreamTypeId } from "../effectable.js"