effect 4.0.0-beta.10 → 4.0.0-beta.12

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 (189) hide show
  1. package/dist/Channel.d.ts +7 -7
  2. package/dist/Config.d.ts +157 -0
  3. package/dist/Config.d.ts.map +1 -1
  4. package/dist/Config.js +56 -1
  5. package/dist/Config.js.map +1 -1
  6. package/dist/Effect.d.ts +296 -8
  7. package/dist/Effect.d.ts.map +1 -1
  8. package/dist/Effect.js +72 -0
  9. package/dist/Effect.js.map +1 -1
  10. package/dist/ErrorReporter.d.ts +376 -0
  11. package/dist/ErrorReporter.d.ts.map +1 -0
  12. package/dist/ErrorReporter.js +246 -0
  13. package/dist/ErrorReporter.js.map +1 -0
  14. package/dist/Fiber.d.ts +2 -2
  15. package/dist/Fiber.d.ts.map +1 -1
  16. package/dist/Fiber.js.map +1 -1
  17. package/dist/Graph.d.ts.map +1 -1
  18. package/dist/Graph.js +3 -6
  19. package/dist/Graph.js.map +1 -1
  20. package/dist/LogLevel.d.ts +5 -0
  21. package/dist/LogLevel.d.ts.map +1 -1
  22. package/dist/LogLevel.js.map +1 -1
  23. package/dist/Logger.d.ts +25 -91
  24. package/dist/Logger.d.ts.map +1 -1
  25. package/dist/Logger.js +2 -3
  26. package/dist/Logger.js.map +1 -1
  27. package/dist/Queue.d.ts.map +1 -1
  28. package/dist/Queue.js +0 -1
  29. package/dist/Queue.js.map +1 -1
  30. package/dist/Random.d.ts +17 -0
  31. package/dist/Random.d.ts.map +1 -1
  32. package/dist/Random.js +17 -0
  33. package/dist/Random.js.map +1 -1
  34. package/dist/References.d.ts +3 -3
  35. package/dist/References.d.ts.map +1 -1
  36. package/dist/Schema.d.ts +3 -1
  37. package/dist/Schema.d.ts.map +1 -1
  38. package/dist/SchemaAST.d.ts.map +1 -1
  39. package/dist/SchemaAST.js +2 -1
  40. package/dist/SchemaAST.js.map +1 -1
  41. package/dist/Stream.d.ts +5 -5
  42. package/dist/index.d.ts +4 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +4 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal/effect.js +98 -33
  47. package/dist/internal/effect.js.map +1 -1
  48. package/dist/internal/hashMap.js +2 -2
  49. package/dist/internal/hashMap.js.map +1 -1
  50. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  51. package/dist/unstable/ai/LanguageModel.js +86 -14
  52. package/dist/unstable/ai/LanguageModel.js.map +1 -1
  53. package/dist/unstable/ai/McpSchema.d.ts +112 -36
  54. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  55. package/dist/unstable/ai/McpSchema.js +47 -10
  56. package/dist/unstable/ai/McpSchema.js.map +1 -1
  57. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  58. package/dist/unstable/ai/McpServer.js +33 -6
  59. package/dist/unstable/ai/McpServer.js.map +1 -1
  60. package/dist/unstable/ai/Tool.d.ts +16 -0
  61. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  62. package/dist/unstable/ai/Tool.js +14 -0
  63. package/dist/unstable/ai/Tool.js.map +1 -1
  64. package/dist/unstable/cli/CliOutput.js +37 -6
  65. package/dist/unstable/cli/CliOutput.js.map +1 -1
  66. package/dist/unstable/cli/Command.d.ts +199 -7
  67. package/dist/unstable/cli/Command.d.ts.map +1 -1
  68. package/dist/unstable/cli/Command.js +116 -6
  69. package/dist/unstable/cli/Command.js.map +1 -1
  70. package/dist/unstable/cli/HelpDoc.d.ts +60 -2
  71. package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
  72. package/dist/unstable/cli/internal/command.d.ts +11 -1
  73. package/dist/unstable/cli/internal/command.d.ts.map +1 -1
  74. package/dist/unstable/cli/internal/command.js +33 -8
  75. package/dist/unstable/cli/internal/command.js.map +1 -1
  76. package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
  77. package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
  78. package/dist/unstable/cli/internal/parser.js +10 -2
  79. package/dist/unstable/cli/internal/parser.js.map +1 -1
  80. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  81. package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -2
  82. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  83. package/dist/unstable/http/Headers.d.ts.map +1 -1
  84. package/dist/unstable/http/Headers.js +27 -10
  85. package/dist/unstable/http/Headers.js.map +1 -1
  86. package/dist/unstable/http/HttpClient.d.ts +28 -4
  87. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  88. package/dist/unstable/http/HttpClient.js.map +1 -1
  89. package/dist/unstable/http/HttpEffect.d.ts +3 -8
  90. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  91. package/dist/unstable/http/HttpEffect.js +25 -31
  92. package/dist/unstable/http/HttpEffect.js.map +1 -1
  93. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  94. package/dist/unstable/http/HttpMiddleware.js +4 -8
  95. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  96. package/dist/unstable/http/HttpServerError.d.ts +14 -27
  97. package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
  98. package/dist/unstable/http/HttpServerError.js +37 -44
  99. package/dist/unstable/http/HttpServerError.js.map +1 -1
  100. package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
  101. package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
  102. package/dist/unstable/http/HttpServerRespondable.js +5 -5
  103. package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
  104. package/dist/unstable/http/HttpServerResponse.d.ts +2 -1
  105. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  106. package/dist/unstable/http/HttpServerResponse.js +2 -0
  107. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  108. package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
  109. package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
  110. package/dist/unstable/http/internal/preResponseHandler.js +10 -0
  111. package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
  112. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
  113. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  114. package/dist/unstable/httpapi/HttpApiBuilder.js +1 -1
  115. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  116. package/dist/unstable/httpapi/HttpApiError.d.ts +11 -0
  117. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  118. package/dist/unstable/httpapi/HttpApiError.js +29 -9
  119. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  120. package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
  121. package/dist/unstable/observability/OtlpLogger.js +7 -4
  122. package/dist/unstable/observability/OtlpLogger.js.map +1 -1
  123. package/dist/unstable/reactivity/Atom.js +1 -1
  124. package/dist/unstable/reactivity/Atom.js.map +1 -1
  125. package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
  126. package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
  127. package/dist/unstable/reactivity/AtomRegistry.js +22 -1
  128. package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
  129. package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
  130. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  131. package/dist/unstable/rpc/RpcSchema.js +14 -0
  132. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  133. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  134. package/dist/unstable/rpc/RpcSerialization.js +34 -9
  135. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  136. package/dist/unstable/rpc/RpcServer.d.ts +0 -7
  137. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  138. package/dist/unstable/rpc/RpcServer.js +9 -10
  139. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  140. package/dist/unstable/workflow/WorkflowEngine.d.ts +6 -0
  141. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  142. package/dist/unstable/workflow/WorkflowEngine.js +131 -0
  143. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  144. package/package.json +1 -1
  145. package/src/Channel.ts +9 -9
  146. package/src/Config.ts +171 -9
  147. package/src/Effect.ts +315 -8
  148. package/src/ErrorReporter.ts +459 -0
  149. package/src/Fiber.ts +9 -2
  150. package/src/Graph.ts +16 -6
  151. package/src/LogLevel.ts +6 -0
  152. package/src/Logger.ts +28 -95
  153. package/src/Queue.ts +0 -1
  154. package/src/Random.ts +18 -0
  155. package/src/References.ts +4 -4
  156. package/src/Schema.ts +1 -1
  157. package/src/SchemaAST.ts +2 -1
  158. package/src/Stream.ts +7 -7
  159. package/src/index.ts +5 -0
  160. package/src/internal/effect.ts +205 -49
  161. package/src/internal/hashMap.ts +2 -2
  162. package/src/unstable/ai/LanguageModel.ts +117 -16
  163. package/src/unstable/ai/McpSchema.ts +57 -11
  164. package/src/unstable/ai/McpServer.ts +44 -6
  165. package/src/unstable/ai/Tool.ts +15 -0
  166. package/src/unstable/cli/CliOutput.ts +45 -6
  167. package/src/unstable/cli/Command.ts +298 -11
  168. package/src/unstable/cli/HelpDoc.ts +68 -2
  169. package/src/unstable/cli/internal/command.ts +47 -11
  170. package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
  171. package/src/unstable/cli/internal/parser.ts +11 -3
  172. package/src/unstable/cluster/ClusterWorkflowEngine.ts +2 -2
  173. package/src/unstable/http/Headers.ts +28 -13
  174. package/src/unstable/http/HttpClient.ts +45 -10
  175. package/src/unstable/http/HttpEffect.ts +30 -44
  176. package/src/unstable/http/HttpMiddleware.ts +4 -14
  177. package/src/unstable/http/HttpServerError.ts +42 -45
  178. package/src/unstable/http/HttpServerRespondable.ts +6 -6
  179. package/src/unstable/http/HttpServerResponse.ts +3 -1
  180. package/src/unstable/http/internal/preResponseHandler.ts +15 -0
  181. package/src/unstable/httpapi/HttpApiBuilder.ts +2 -1
  182. package/src/unstable/httpapi/HttpApiError.ts +30 -9
  183. package/src/unstable/observability/OtlpLogger.ts +9 -5
  184. package/src/unstable/reactivity/Atom.ts +1 -1
  185. package/src/unstable/reactivity/AtomRegistry.ts +29 -1
  186. package/src/unstable/rpc/RpcSchema.ts +17 -0
  187. package/src/unstable/rpc/RpcSerialization.ts +44 -9
  188. package/src/unstable/rpc/RpcServer.ts +14 -19
  189. package/src/unstable/workflow/WorkflowEngine.ts +178 -0
@@ -201,7 +201,8 @@ export const causePrettyErrors = self => {
201
201
  Error.stackTraceLimit = prevStackLimit;
202
202
  return errors;
203
203
  };
204
- const causePrettyError = (original, annotations) => {
204
+ /** @internal */
205
+ export const causePrettyError = (original, annotations) => {
205
206
  const kind = typeof original;
206
207
  let error;
207
208
  if (original && kind === "object") {
@@ -322,17 +323,31 @@ const fiberIdStore = {
322
323
  /** @internal */
323
324
  export const getCurrentFiber = () => globalThis[currentFiberTypeId];
324
325
  const keepAlive = /*#__PURE__*/(() => {
326
+ let isAvailable;
327
+ const start = () => {
328
+ if (isAvailable === true) return setInterval(constVoid, 2_147_483_647);else if (isAvailable === false) return undefined;
329
+ try {
330
+ const running = setInterval(constVoid, 2_147_483_647);
331
+ isAvailable = true;
332
+ return running;
333
+ } catch {
334
+ isAvailable = false;
335
+ return undefined;
336
+ }
337
+ };
325
338
  let count = 0;
326
339
  let running = undefined;
327
340
  return {
328
341
  increment() {
329
342
  count++;
330
- running ??= globalThis.setInterval(constVoid, 2_147_483_647);
343
+ if (running === undefined) {
344
+ running = start();
345
+ }
331
346
  },
332
347
  decrement() {
333
348
  count--;
334
349
  if (count === 0 && running !== undefined) {
335
- globalThis.clearInterval(running);
350
+ clearInterval(running);
336
351
  running = undefined;
337
352
  }
338
353
  }
@@ -598,8 +613,10 @@ export const fiberJoinAll = self => callback(resume => {
598
613
  /** @internal */
599
614
  export const fiberInterrupt = self => withFiber(fiber => fiberInterruptAs(self, fiber.id));
600
615
  /** @internal */
601
- export const fiberInterruptAs = /*#__PURE__*/dual(2, (self, fiberId) => withFiber(parent => {
602
- self.interruptUnsafe(fiberId, fiberStackAnnotations(parent));
616
+ export const fiberInterruptAs = /*#__PURE__*/dual(args => hasProperty(args[0], FiberTypeId), (self, fiberId, annotations) => withFiber(parent => {
617
+ let ann = fiberStackAnnotations(parent);
618
+ ann = ann && annotations ? ServiceMap.merge(ann, annotations) : ann ?? annotations;
619
+ self.interruptUnsafe(fiberId, ann);
603
620
  return asVoid(fiberAwait(self));
604
621
  }));
605
622
  /** @internal */
@@ -1117,33 +1134,17 @@ export const updateServices = /*#__PURE__*/dual(2, (self, f) => withFiber(fiber
1117
1134
  const nextServices = f(prev);
1118
1135
  if (prev === nextServices) return self;
1119
1136
  fiber.setServices(nextServices);
1120
- const newServices = new Map();
1121
- for (const [key, value] of fiber.services.mapUnsafe) {
1122
- if (!prev.mapUnsafe.has(key) || value !== prev.mapUnsafe.get(key)) {
1123
- newServices.set(key, value);
1124
- }
1125
- }
1126
1137
  return onExitPrimitive(self, () => {
1127
- const map = new Map(fiber.services.mapUnsafe);
1128
- for (const [key, value] of newServices) {
1129
- if (value !== map.get(key)) continue;
1130
- if (prev.mapUnsafe.has(key)) {
1131
- map.set(key, prev.mapUnsafe.get(key));
1132
- } else {
1133
- map.delete(key);
1134
- }
1135
- }
1136
- fiber.setServices(ServiceMap.makeUnsafe(map));
1138
+ fiber.setServices(prev);
1137
1139
  return undefined;
1138
1140
  });
1139
1141
  }));
1140
1142
  /** @internal */
1141
- export const updateService = /*#__PURE__*/dual(3, (self, service, f) => withFiber(fiber => {
1142
- const prev = ServiceMap.getUnsafe(fiber.services, service);
1143
+ export const updateService = /*#__PURE__*/dual(3, (self, service, f) => updateServices(self, s => {
1144
+ const prev = ServiceMap.getUnsafe(s, service);
1143
1145
  const next = f(prev);
1144
- if (prev === next) return self;
1145
- fiber.setServices(ServiceMap.add(fiber.services, service, next));
1146
- return onExit(self, () => sync(() => fiber.setServices(ServiceMap.add(fiber.services, service, prev))));
1146
+ if (prev === next) return s;
1147
+ return ServiceMap.add(s, service, next);
1147
1148
  }));
1148
1149
  /** @internal */
1149
1150
  export const services = () => getServiceMap;
@@ -1162,11 +1163,10 @@ export const provideService = function () {
1162
1163
  }
1163
1164
  return dual(3, (self, service, impl) => provideServiceImpl(self, service, impl)).apply(this, arguments);
1164
1165
  };
1165
- const provideServiceImpl = (self, service, implementation) => withFiber(fiber => {
1166
- const prev = ServiceMap.getOption(fiber.services, service);
1167
- if (prev._tag === "Some" && prev.value === implementation) return self;
1168
- fiber.setServices(ServiceMap.add(fiber.services, service, implementation));
1169
- return onExit(self, () => sync(() => fiber.setServices(ServiceMap.addOrOmit(fiber.services, service, prev))));
1166
+ const provideServiceImpl = (self, service, implementation) => updateServices(self, s => {
1167
+ const prev = s.mapUnsafe.get(service.key);
1168
+ if (prev === implementation) return s;
1169
+ return ServiceMap.add(s, service, implementation);
1170
1170
  });
1171
1171
  /** @internal */
1172
1172
  export const provideServiceEffect = /*#__PURE__*/dual(3, (self, service, acquire) => flatMap(acquire, implementation => provideService(self, service, implementation)));
@@ -1569,11 +1569,11 @@ export const scope = /*#__PURE__*/scopeTag.asEffect();
1569
1569
  export const provideScope = /*#__PURE__*/provideService(scopeTag);
1570
1570
  /** @internal */
1571
1571
  export const scoped = self => withFiber(fiber => {
1572
- const prev = ServiceMap.getOption(fiber.services, scopeTag);
1572
+ const prev = fiber.services;
1573
1573
  const scope = scopeMakeUnsafe();
1574
1574
  fiber.setServices(ServiceMap.add(fiber.services, scopeTag, scope));
1575
1575
  return onExitPrimitive(self, exit => {
1576
- fiber.setServices(ServiceMap.addOrOmit(fiber.services, scopeTag, prev));
1576
+ fiber.setServices(prev);
1577
1577
  return scopeCloseUnsafe(scope, exit);
1578
1578
  });
1579
1579
  });
@@ -1735,6 +1735,15 @@ export const all = (arg, options) => {
1735
1735
  /** @internal */
1736
1736
  export const partition = /*#__PURE__*/dual(args => isIterable(args[0]) && !isEffect(args[0]), (elements, f, options) => map(forEach(elements, (a, i) => result(f(a, i)), options), results => Arr.partitionMap(results, identity)));
1737
1737
  /** @internal */
1738
+ export const validate = /*#__PURE__*/dual(args => isIterable(args[0]) && !isEffect(args[0]), (elements, f, options) => flatMap(partition(elements, f, {
1739
+ concurrency: options?.concurrency
1740
+ }), ([excluded, satisfying]) => {
1741
+ if (Arr.isArrayNonEmpty(excluded)) {
1742
+ return fail(excluded);
1743
+ }
1744
+ return options?.discard ? void_ : succeed(satisfying);
1745
+ }));
1746
+ /** @internal */
1738
1747
  export const whileLoop = /*#__PURE__*/makePrimitive({
1739
1748
  op: "While",
1740
1749
  [contA](value, fiber) {
@@ -2539,6 +2548,38 @@ export const LogToStderr = /*#__PURE__*/ServiceMap.Reference("effect/Logger/LogT
2539
2548
  defaultValue: constFalse
2540
2549
  });
2541
2550
  /** @internal */
2551
+ export const annotateLogsScoped = function () {
2552
+ const entries = typeof arguments[0] === "string" ? [[arguments[0], arguments[1]]] : Object.entries(arguments[0]);
2553
+ return uninterruptible(withFiber(fiber => {
2554
+ const prev = fiber.getRef(CurrentLogAnnotations);
2555
+ const next = {
2556
+ ...prev
2557
+ };
2558
+ for (let i = 0; i < entries.length; i++) {
2559
+ const [key, value] = entries[i];
2560
+ next[key] = value;
2561
+ }
2562
+ fiber.setServices(ServiceMap.add(fiber.services, CurrentLogAnnotations, next));
2563
+ return scopeAddFinalizerExit(ServiceMap.getUnsafe(fiber.services, scopeTag), _ => {
2564
+ const current = fiber.getRef(CurrentLogAnnotations);
2565
+ const next = {
2566
+ ...current
2567
+ };
2568
+ for (let i = 0; i < entries.length; i++) {
2569
+ const [key, value] = entries[i];
2570
+ if (current[key] !== value) continue;
2571
+ if (key in prev) {
2572
+ next[key] = prev[key];
2573
+ } else {
2574
+ delete next[key];
2575
+ }
2576
+ }
2577
+ fiber.setServices(ServiceMap.add(fiber.services, CurrentLogAnnotations, next));
2578
+ return void_;
2579
+ });
2580
+ }));
2581
+ };
2582
+ /** @internal */
2542
2583
  export const LoggerTypeId = "~effect/Logger";
2543
2584
  const LoggerProto = {
2544
2585
  [LoggerTypeId]: {
@@ -2845,4 +2886,28 @@ export function interruptChildrenPatch() {
2845
2886
  const undefined_ = /*#__PURE__*/succeed(undefined);
2846
2887
  /** @internal */
2847
2888
  export { undefined_ as undefined };
2889
+ // ----------------------------------------------------------------------------
2890
+ // ErrorReporter
2891
+ // ----------------------------------------------------------------------------
2892
+ /** @internal */
2893
+ export const CurrentErrorReporters = /*#__PURE__*/ServiceMap.Reference("effect/ErrorReporter/CurrentErrorReporters", {
2894
+ defaultValue: () => new Set()
2895
+ });
2896
+ /** @internal */
2897
+ export const withErrorReporting = /*#__PURE__*/dual(args => isEffect(args[0]), (self, options) => onError(self, cause => withFiber(fiber => {
2898
+ reportCauseUnsafe(fiber, cause, options?.defectsOnly);
2899
+ return void_;
2900
+ })));
2901
+ /** @internal */
2902
+ export const reportCauseUnsafe = (fiber, cause, defectsOnly) => {
2903
+ const reporters = fiber.getRef(CurrentErrorReporters);
2904
+ if (reporters.size === 0) return;
2905
+ if (defectsOnly && !hasDies(cause)) return;
2906
+ const opts = {
2907
+ cause,
2908
+ fiber,
2909
+ timestamp: fiber.getRef(ClockRef).currentTimeNanosUnsafe()
2910
+ };
2911
+ reporters.forEach(reporter => reporter.report(opts));
2912
+ };
2848
2913
  //# sourceMappingURL=effect.js.map