effect 4.0.0-beta.50 → 4.0.0-beta.52

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 (135) hide show
  1. package/dist/BigDecimal.d.ts.map +1 -1
  2. package/dist/BigDecimal.js +18 -14
  3. package/dist/BigDecimal.js.map +1 -1
  4. package/dist/BigInt.d.ts.map +1 -1
  5. package/dist/BigInt.js +4 -4
  6. package/dist/BigInt.js.map +1 -1
  7. package/dist/Brand.d.ts +2 -4
  8. package/dist/Brand.d.ts.map +1 -1
  9. package/dist/Brand.js.map +1 -1
  10. package/dist/Data.js +2 -2
  11. package/dist/Data.js.map +1 -1
  12. package/dist/Duration.js +1 -1
  13. package/dist/Duration.js.map +1 -1
  14. package/dist/Schema.d.ts +77 -10
  15. package/dist/Schema.d.ts.map +1 -1
  16. package/dist/Schema.js +119 -18
  17. package/dist/Schema.js.map +1 -1
  18. package/dist/SchemaAST.d.ts +6 -0
  19. package/dist/SchemaAST.d.ts.map +1 -1
  20. package/dist/SchemaAST.js +216 -229
  21. package/dist/SchemaAST.js.map +1 -1
  22. package/dist/SchemaGetter.d.ts +3 -5
  23. package/dist/SchemaGetter.d.ts.map +1 -1
  24. package/dist/SchemaGetter.js +3 -2
  25. package/dist/SchemaGetter.js.map +1 -1
  26. package/dist/SchemaIssue.d.ts.map +1 -1
  27. package/dist/SchemaIssue.js +29 -11
  28. package/dist/SchemaIssue.js.map +1 -1
  29. package/dist/SchemaParser.js +14 -2
  30. package/dist/SchemaParser.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +3 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/effect.js +142 -65
  36. package/dist/internal/effect.js.map +1 -1
  37. package/dist/internal/schema/representation.js +1 -2
  38. package/dist/internal/schema/representation.js.map +1 -1
  39. package/dist/internal/schema/schema.d.ts.map +1 -1
  40. package/dist/internal/schema/schema.js +37 -0
  41. package/dist/internal/schema/schema.js.map +1 -1
  42. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  43. package/dist/unstable/ai/McpServer.js +7 -0
  44. package/dist/unstable/ai/McpServer.js.map +1 -1
  45. package/dist/unstable/cli/index.d.ts +2 -0
  46. package/dist/unstable/cli/index.d.ts.map +1 -1
  47. package/dist/unstable/cli/index.js +2 -0
  48. package/dist/unstable/cli/index.js.map +1 -1
  49. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  50. package/dist/unstable/cluster/Runners.js +3 -2
  51. package/dist/unstable/cluster/Runners.js.map +1 -1
  52. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  53. package/dist/unstable/cluster/SqlMessageStorage.js +1 -0
  54. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  55. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  56. package/dist/unstable/cluster/SqlRunnerStorage.js +6 -6
  57. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  58. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  59. package/dist/unstable/eventlog/SqlEventJournal.js +9 -8
  60. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  61. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  62. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +6 -5
  63. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  64. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
  65. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +6 -5
  66. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  68. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
  70. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
  72. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  74. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +17 -18
  75. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  76. package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
  77. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  78. package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
  79. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  80. package/dist/unstable/httpapi/HttpApiError.js +28 -15
  81. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  82. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  84. package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/OpenApi.d.ts +1 -10
  87. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/OpenApi.js +2 -11
  89. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  90. package/dist/unstable/observability/OtlpMetrics.js +1 -1
  91. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  92. package/dist/unstable/observability/internal/protobuf.js +4 -4
  93. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  94. package/dist/unstable/rpc/RpcSerialization.d.ts +11 -0
  95. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  96. package/dist/unstable/rpc/RpcSerialization.js +14 -9
  97. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  98. package/package.json +1 -1
  99. package/src/BigDecimal.ts +20 -16
  100. package/src/BigInt.ts +4 -4
  101. package/src/Brand.ts +2 -4
  102. package/src/Data.ts +1 -1
  103. package/src/Duration.ts +1 -1
  104. package/src/Schema.ts +183 -23
  105. package/src/SchemaAST.ts +315 -267
  106. package/src/SchemaGetter.ts +4 -6
  107. package/src/SchemaIssue.ts +28 -15
  108. package/src/SchemaParser.ts +8 -2
  109. package/src/index.ts +3 -0
  110. package/src/internal/effect.ts +196 -69
  111. package/src/internal/schema/representation.ts +1 -2
  112. package/src/internal/schema/schema.ts +43 -0
  113. package/src/unstable/ai/McpServer.ts +8 -0
  114. package/src/unstable/cli/index.ts +2 -0
  115. package/src/unstable/cluster/Runners.ts +8 -5
  116. package/src/unstable/cluster/SqlMessageStorage.ts +1 -0
  117. package/src/unstable/cluster/SqlRunnerStorage.ts +12 -6
  118. package/src/unstable/eventlog/SqlEventJournal.ts +10 -2
  119. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +8 -3
  120. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +9 -3
  121. package/src/unstable/httpapi/HttpApi.ts +1 -1
  122. package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
  123. package/src/unstable/httpapi/HttpApiClient.ts +5 -6
  124. package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
  125. package/src/unstable/httpapi/HttpApiError.ts +43 -22
  126. package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
  127. package/src/unstable/httpapi/OpenApi.ts +3 -15
  128. package/src/unstable/observability/OtlpMetrics.ts +1 -1
  129. package/src/unstable/observability/internal/protobuf.ts +4 -4
  130. package/src/unstable/rpc/RpcSerialization.ts +41 -36
  131. package/dist/internal/schema/to-codec.d.ts +0 -2
  132. package/dist/internal/schema/to-codec.d.ts.map +0 -1
  133. package/dist/internal/schema/to-codec.js +0 -126
  134. package/dist/internal/schema/to-codec.js.map +0 -1
  135. package/src/internal/schema/to-codec.ts +0 -138
@@ -17,7 +17,7 @@ import * as Result from "../Result.js";
17
17
  import * as Scheduler from "../Scheduler.js";
18
18
  import * as Tracer from "../Tracer.js";
19
19
  import { internalCall } from "../Utils.js";
20
- import { args, causeAnnotate, causeEmpty, causeFromReasons, CauseImpl, constEmptyAnnotations, contA, contAll, contE, Die, evaluate, exitDie, exitFail, exitFailCause, exitSucceed, ExitTypeId, Fail, InterruptorStackTrace, isCause, isDieReason, isEffect, isFailReason, isInterruptReason, isNoSuchElementError, makePrimitive, makePrimitiveProto, NoSuchElementError, ReasonBase, StackTraceKey as CauseStackTrace, TaggedError, withFiber, Yield } from "./core.js";
20
+ import { args, causeAnnotate, causeEmpty, causeFromReasons, CauseImpl, constEmptyAnnotations, contA, contAll, contE, evaluate, exitDie, exitFail, exitFailCause, exitSucceed, ExitTypeId, Fail, InterruptorStackTrace, isCause, isDieReason, isEffect, isFailReason, isInterruptReason, isNoSuchElementError, makePrimitive, makePrimitiveProto, NoSuchElementError, ReasonBase, StackTraceKey as CauseStackTrace, TaggedError, withFiber, Yield } from "./core.js";
21
21
  import * as doNotation from "./doNotation.js";
22
22
  import * as InternalMetric from "./metric.js";
23
23
  import { CurrentConcurrency, CurrentErrorReporters, CurrentLogAnnotations, CurrentLogLevel, CurrentLogSpans, CurrentStackFrame, MinimumLogLevel, TracerEnabled, TracerSpanAnnotations, TracerSpanLinks, TracerTimingEnabled } from "./references.js";
@@ -1834,70 +1834,13 @@ export const forEach = /*#__PURE__*/dual(args => typeof args[1] === "function",
1834
1834
  return options?.discard ? void_ : succeed([]);
1835
1835
  }
1836
1836
  const out = options?.discard ? undefined : new Array(length);
1837
- let index = 0;
1838
- const annotations = fiberStackAnnotations(parent);
1839
- return callback(resume => {
1840
- const fibers = new Set();
1841
- const failures = [];
1842
- let failed = false;
1843
- let inProgress = 0;
1844
- let doneCount = 0;
1845
- let pumping = false;
1846
- let interrupted = false;
1847
- function pump() {
1848
- pumping = true;
1849
- while (inProgress < concurrency && index < length) {
1850
- const currentIndex = index;
1851
- const item = items[currentIndex];
1852
- index++;
1853
- inProgress++;
1854
- try {
1855
- const child = forkUnsafe(parent, f(item, currentIndex), true, true, "inherit");
1856
- fibers.add(child);
1857
- child.addObserver(exit => {
1858
- if (interrupted) {
1859
- return;
1860
- }
1861
- fibers.delete(child);
1862
- if (exit._tag === "Failure") {
1863
- if (!failed) {
1864
- failed = true;
1865
- length = index;
1866
- failures.push(...exit.cause.reasons);
1867
- fibers.forEach(fiber => fiber.interruptUnsafe(parent.id, annotations));
1868
- } else {
1869
- for (const f of exit.cause.reasons) {
1870
- if (f._tag === "Interrupt") continue;
1871
- failures.push(f);
1872
- }
1873
- }
1874
- } else if (out !== undefined) {
1875
- out[currentIndex] = exit.value;
1876
- }
1877
- doneCount++;
1878
- inProgress--;
1879
- if (doneCount === length) {
1880
- resume(failures.length > 0 ? exitFailCause(causeFromReasons(failures)) : succeed(out));
1881
- } else if (!pumping && !failed && inProgress < concurrency) {
1882
- pump();
1883
- }
1884
- });
1885
- } catch (err) {
1886
- failed = true;
1887
- length = index;
1888
- failures.push(new Die(err));
1889
- fibers.forEach(fiber => fiber.interruptUnsafe(parent.id, annotations));
1890
- }
1891
- }
1892
- pumping = false;
1893
- }
1894
- pump();
1895
- return suspend(() => {
1896
- interrupted = true;
1897
- index = length;
1898
- return fiberInterruptAll(fibers);
1899
- });
1837
+ const eff = forEachConcurrent({
1838
+ f,
1839
+ out
1840
+ }, items, {
1841
+ concurrency
1900
1842
  });
1843
+ return eff ? as(eff, out) : succeed(out);
1901
1844
  }));
1902
1845
  const forEachSequential = (iterable, f, options) => suspend(() => {
1903
1846
  const out = options?.discard ? undefined : [];
@@ -1913,6 +1856,130 @@ const forEachSequential = (iterable, f, options) => suspend(() => {
1913
1856
  }
1914
1857
  }), out);
1915
1858
  });
1859
+ const iterateEagerImpl = options => {
1860
+ const onItem = options.onItem;
1861
+ const step = options.step;
1862
+ return (state, items, opts) => {
1863
+ let index = opts?.start ?? 0;
1864
+ const end = opts?.end ?? items.length;
1865
+ const concurrency = opts?.concurrency ?? 1;
1866
+ let done = false;
1867
+ let parentFiber;
1868
+ let fibers;
1869
+ let resume;
1870
+ let interrupted = false;
1871
+ let terminal;
1872
+ let effect;
1873
+ const go = () => {
1874
+ let paused = false;
1875
+ for (; !terminal && index < end; index++) {
1876
+ const item = items[index];
1877
+ const eff = effect ?? onItem(state, item, index);
1878
+ // fast case (already an exit)
1879
+ if (effectIsExit(eff)) {
1880
+ terminal = step(state, item, eff, index);
1881
+ if (terminal) break;
1882
+ // Use flatMap for concurrency of 1
1883
+ } else if (concurrency === 1) {
1884
+ return flatMap(exit(eff), exit => {
1885
+ terminal = step(state, item, exit, index);
1886
+ index++;
1887
+ return terminal ?? go() ?? void_;
1888
+ });
1889
+ // We have an effect, so enter "async" mode
1890
+ } else if (!parentFiber) {
1891
+ return callback(cb => {
1892
+ parentFiber = getCurrentFiber();
1893
+ effect = eff;
1894
+ resume = cb;
1895
+ const result = go();
1896
+ if (result) return cb(result);
1897
+ return suspend(() => {
1898
+ terminal = exitVoid;
1899
+ interrupted = true;
1900
+ return fibers ? fiberInterruptAll(fibers) : void_;
1901
+ });
1902
+ });
1903
+ // Fork the effect with concurrency > 1
1904
+ } else {
1905
+ // Clear the temporary effect from capturing the parentFiber
1906
+ effect = undefined;
1907
+ const fiber = forkUnsafe(parentFiber, eff, true, true, "inherit");
1908
+ if (fiber._exit) {
1909
+ terminal = step(state, item, fiber._exit, index);
1910
+ if (terminal) break;
1911
+ continue;
1912
+ }
1913
+ // Add the fiber to the Set
1914
+ if (fibers) fibers.add(fiber);else fibers = new Set([fiber]);
1915
+ const currentIndex = index;
1916
+ fiber.addObserver(exit => {
1917
+ fibers.delete(fiber);
1918
+ if (terminal) {
1919
+ if (!interrupted && exit._tag === "Failure") {
1920
+ for (const reason of exit.cause.reasons) {
1921
+ if (reason._tag === "Interrupt") continue;else if (terminal._tag === "Failure") {
1922
+ ;
1923
+ terminal.cause.reasons.push(reason);
1924
+ } else {
1925
+ terminal = exitFailCause(causeFromReasons([reason]));
1926
+ }
1927
+ }
1928
+ }
1929
+ } else {
1930
+ const result = step(state, item, exit, currentIndex);
1931
+ if (result) {
1932
+ terminal = result._tag === "Failure" ? exitFailCause(causeFromReasons(result.cause.reasons.slice())) : result;
1933
+ go();
1934
+ }
1935
+ }
1936
+ if (paused) {
1937
+ const eff = go();
1938
+ if (eff) resume(eff);
1939
+ } else if (done && fibers.size === 0) {
1940
+ resume(terminal ?? void_);
1941
+ }
1942
+ });
1943
+ // Check if we have reached the concurrency limit
1944
+ if (fibers.size < concurrency) continue;
1945
+ paused = true;
1946
+ index++;
1947
+ return;
1948
+ }
1949
+ }
1950
+ done = true;
1951
+ if (terminal) {
1952
+ if (fibers && fibers.size > 0) {
1953
+ const annotations = fiberStackAnnotations(parentFiber);
1954
+ fibers.forEach(f => f.interruptUnsafe(parentFiber.id, annotations));
1955
+ return;
1956
+ }
1957
+ if (resume || terminal._tag === "Failure") {
1958
+ return terminal;
1959
+ }
1960
+ } else if (resume) {
1961
+ if (!fibers) {
1962
+ return exitVoid;
1963
+ } else if (fibers.size === 0) {
1964
+ resume(void_);
1965
+ }
1966
+ }
1967
+ };
1968
+ return go();
1969
+ };
1970
+ };
1971
+ /** @internal */
1972
+ export const iterateEager = () => iterateEagerImpl;
1973
+ const forEachConcurrent = /*#__PURE__*/iterateEagerImpl({
1974
+ onItem(state, item, index) {
1975
+ return state.f(item, index);
1976
+ },
1977
+ step(state, _, exit, index) {
1978
+ if (exit._tag === "Failure") return exit;else if (state.out) {
1979
+ state.out[index] = exit.value;
1980
+ }
1981
+ }
1982
+ });
1916
1983
  /* @internal */
1917
1984
  export const filterOrElse = /*#__PURE__*/dual(3, (self, predicate, orElse) => flatMap(self, a => predicate(a) ? succeed(a) : orElse(a)));
1918
1985
  /** @internal */
@@ -2258,7 +2325,7 @@ export const makeSpanUnsafe = (fiber, name, options) => {
2258
2325
  parent,
2259
2326
  annotations: options?.annotations ?? Context.empty(),
2260
2327
  links,
2261
- startTime: timingEnabled ? clock.currentTimeNanosUnsafe() : 0n,
2328
+ startTime: timingEnabled ? clock.currentTimeNanosUnsafe() : BigInt(0),
2262
2329
  kind: options?.kind ?? "internal",
2263
2330
  root: options?.root ?? Option.isNone(parent),
2264
2331
  sampled: options?.sampled ?? (Option.isSome(parent) && parent.value.sampled === false ? false : !isLogLevelGreaterThan(fiber.getRef(Tracer.MinimumTraceLevel), level))
@@ -2756,6 +2823,7 @@ const prettyLoggerTty = options => {
2756
2823
  message: message_
2757
2824
  }) => {
2758
2825
  const console = fiber.getRef(ConsoleRef);
2826
+ // oxlint-disable-next-line no-console
2759
2827
  const log = fiber.getRef(LogToStderr) ? console.error : console.log;
2760
2828
  const message = Array.isArray(message_) ? message_.slice() : [message_];
2761
2829
  let firstLine = color(`[${options.formatDate(date)}]`, colors.white) + ` ${color(logLevel.toUpperCase(), ...logLevelColors[logLevel])}` + ` (#${fiber.id})`;
@@ -2774,6 +2842,7 @@ const prettyLoggerTty = options => {
2774
2842
  }
2775
2843
  }
2776
2844
  log(firstLine);
2845
+ // oxlint-disable-next-line no-console
2777
2846
  if (!processIsBun) console.group();
2778
2847
  if (cause.reasons.length > 0) {
2779
2848
  log(causePretty(cause));
@@ -2787,6 +2856,7 @@ const prettyLoggerTty = options => {
2787
2856
  for (const [key, value] of Object.entries(annotations)) {
2788
2857
  log(color(`${key}:`, colors.bold, colors.white), redact(value));
2789
2858
  }
2859
+ // oxlint-disable-next-line no-console
2790
2860
  if (!processIsBun) console.groupEnd();
2791
2861
  });
2792
2862
  };
@@ -2827,12 +2897,15 @@ const prettyLoggerBrowser = options => {
2827
2897
  messageIndex++;
2828
2898
  }
2829
2899
  }
2900
+ // oxlint-disable-next-line no-console
2830
2901
  console.groupCollapsed(firstLine, ...firstParams);
2831
2902
  if (cause.reasons.length > 0) {
2903
+ // oxlint-disable-next-line no-console
2832
2904
  console.error(causePretty(cause));
2833
2905
  }
2834
2906
  if (messageIndex < message.length) {
2835
2907
  for (; messageIndex < message.length; messageIndex++) {
2908
+ // oxlint-disable-next-line no-console
2836
2909
  console.log(redact(message[messageIndex]));
2837
2910
  }
2838
2911
  }
@@ -2840,11 +2913,14 @@ const prettyLoggerBrowser = options => {
2840
2913
  for (const [key, value] of Object.entries(annotations)) {
2841
2914
  const redacted = redact(value);
2842
2915
  if (options.colors) {
2916
+ // oxlint-disable-next-line no-console
2843
2917
  console.log(`%c${key}:`, "color:gray", redacted);
2844
2918
  } else {
2919
+ // oxlint-disable-next-line no-console
2845
2920
  console.log(`${key}:`, redacted);
2846
2921
  }
2847
2922
  }
2923
+ // oxlint-disable-next-line no-console
2848
2924
  console.groupEnd();
2849
2925
  });
2850
2926
  };
@@ -2871,6 +2947,7 @@ export const defaultLogger = /*#__PURE__*/loggerMake(({
2871
2947
  message_.push(annotations);
2872
2948
  }
2873
2949
  const console = fiber.getRef(ConsoleRef);
2950
+ // oxlint-disable-next-line no-console
2874
2951
  const log = fiber.getRef(LogToStderr) ? console.error : console.log;
2875
2952
  log(`[${defaultDateFormat(date)}] ${logLevel.toUpperCase()} (#${fiber.id})${spanString}:`, ...message_);
2876
2953
  });