brass-runtime 1.16.1 → 1.18.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 (123) hide show
  1. package/README.md +40 -8
  2. package/dist/agent/cli/main.cjs +31 -32
  3. package/dist/agent/cli/main.js +3 -4
  4. package/dist/agent/cli/main.mjs +3 -4
  5. package/dist/agent/index.cjs +4 -5
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -4
  8. package/dist/agent/index.mjs +3 -4
  9. package/dist/{chunk-GYM3LLGS.mjs → chunk-2QNREG6K.mjs} +188 -5
  10. package/dist/{chunk-4ROBZFL6.cjs → chunk-2SLT3X6G.cjs} +6 -8
  11. package/dist/{chunk-KZJQ723N.cjs → chunk-3PFZGP23.cjs} +13 -15
  12. package/dist/{chunk-AVNQLJ5V.js → chunk-3PHU7FWS.js} +528 -23
  13. package/dist/{chunk-CIZFIMK5.js → chunk-4YQHPIWJ.js} +60 -11
  14. package/dist/chunk-5XADBMSU.cjs +33 -0
  15. package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
  16. package/dist/chunk-7TKI527D.cjs +123 -0
  17. package/dist/{chunk-AGR5B2BC.cjs → chunk-7TXQJFZX.cjs} +564 -12
  18. package/dist/{chunk-RKGKFN2A.js → chunk-AADFFVYS.js} +1 -1
  19. package/dist/{chunk-52PPNNI4.cjs → chunk-AJMKZXRB.cjs} +2 -2
  20. package/dist/{chunk-3AYM6WPJ.js → chunk-BG5RNEA2.js} +20 -299
  21. package/dist/{chunk-2HQTDLHF.mjs → chunk-ELLF55ER.mjs} +555 -3
  22. package/dist/{chunk-EOC4UHBS.mjs → chunk-G5JTCFMI.mjs} +2 -2
  23. package/dist/chunk-H5GYX7RZ.js +6126 -0
  24. package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
  25. package/dist/{chunk-6IXXWIUM.js → chunk-IBRHSH5H.js} +555 -3
  26. package/dist/{chunk-Q2I37RP3.cjs → chunk-IFRBVMWJ.cjs} +44 -323
  27. package/dist/{chunk-52OB2ROS.js → chunk-ITG6I7ZS.js} +2 -4
  28. package/dist/chunk-ITZQ526U.mjs +33 -0
  29. package/dist/{chunk-7JIJOVCT.js → chunk-JH4GI3DW.js} +2 -4
  30. package/dist/{chunk-76YMRMH2.cjs → chunk-KHACHFBQ.cjs} +583 -78
  31. package/dist/{chunk-MT3OWDPC.mjs → chunk-KRYP6CAE.mjs} +60 -11
  32. package/dist/chunk-KTGDLBLD.mjs +123 -0
  33. package/dist/{chunk-ENKODRU3.cjs → chunk-LXBU5E77.cjs} +143 -94
  34. package/dist/{chunk-PD4EJTQC.cjs → chunk-N6QNSTWD.cjs} +5 -5
  35. package/dist/{chunk-HLWLMW2F.mjs → chunk-OI4ESUMC.mjs} +9 -11
  36. package/dist/{chunk-EJ6BPYVR.mjs → chunk-OT2TESZU.mjs} +1 -1
  37. package/dist/{chunk-BABBZK4Y.js → chunk-PSEU65ND.js} +9 -11
  38. package/dist/{chunk-DNFO2EIZ.mjs → chunk-QCOLAHU3.mjs} +528 -23
  39. package/dist/{chunk-KH4SYAOS.mjs → chunk-QZ6QFJNM.mjs} +20 -299
  40. package/dist/{chunk-MBEJI5HF.mjs → chunk-R6WDSZA6.mjs} +2 -4
  41. package/dist/{chunk-FHQGHPMO.mjs → chunk-RREBJX2S.mjs} +2 -4
  42. package/dist/{chunk-5QC7LRZ3.js → chunk-S4HHFUYP.js} +2 -2
  43. package/dist/{chunk-GLE2WY7Z.cjs → chunk-SSQJKDN3.cjs} +194 -11
  44. package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
  45. package/dist/chunk-VIFA4DPN.cjs +6126 -0
  46. package/dist/chunk-W6WR37HN.js +33 -0
  47. package/dist/{chunk-FH2X7BVP.js → chunk-XSAHV5HQ.js} +188 -5
  48. package/dist/chunk-YM3EDNYD.js +123 -0
  49. package/dist/{chunk-VN44DYYT.cjs → chunk-YTX2JYYP.cjs} +18 -20
  50. package/dist/chunk-Z3PSSXP3.mjs +6126 -0
  51. package/dist/core/index.cjs +31 -9
  52. package/dist/core/index.d.ts +19 -152
  53. package/dist/core/index.js +80 -58
  54. package/dist/core/index.mjs +80 -58
  55. package/dist/defaultClient-DhpCQW9m.d.ts +1623 -0
  56. package/dist/{effect-DIUHZ9IN.d.ts → effect-CtUDl5M5.d.ts} +1 -1
  57. package/dist/http/index.cjs +202 -59
  58. package/dist/http/index.d.ts +55 -819
  59. package/dist/http/index.js +216 -73
  60. package/dist/http/index.mjs +216 -73
  61. package/dist/http/testing.cjs +31 -10
  62. package/dist/http/testing.d.ts +16 -5
  63. package/dist/http/testing.js +29 -8
  64. package/dist/http/testing.mjs +29 -8
  65. package/dist/index.cjs +110 -88
  66. package/dist/index.d.ts +9 -8
  67. package/dist/index.js +81 -59
  68. package/dist/index.mjs +81 -59
  69. package/dist/{schedule-CK3Ml_7p.d.ts → layer-BalPI6cN.d.ts} +176 -2
  70. package/dist/observability/index.cjs +22 -7
  71. package/dist/observability/index.d.ts +32 -8
  72. package/dist/observability/index.js +21 -6
  73. package/dist/observability/index.mjs +21 -6
  74. package/dist/perf/cli.cjs +26 -28
  75. package/dist/perf/cli.js +11 -13
  76. package/dist/perf/cli.mjs +11 -13
  77. package/dist/perf/index.cjs +13 -15
  78. package/dist/perf/index.js +11 -13
  79. package/dist/perf/index.mjs +11 -13
  80. package/dist/schema/index.cjs +2 -2
  81. package/dist/schema/index.js +1 -1
  82. package/dist/schema/index.mjs +1 -1
  83. package/dist/{server-GJPg8ZSG.d.ts → server-C1zVmqE6.d.ts} +16 -5
  84. package/dist/{stream-B4oK9JFP.d.ts → stream-Bb4FTejt.d.ts} +1 -1
  85. package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DzfuE6um.d.ts} +2 -2
  86. package/dist/{tracing-DqbTKGcf.d.ts → tracing-BABA5arE.d.ts} +1 -1
  87. package/docs/README.md +4 -0
  88. package/docs/ai/PUBLIC_API.md +31 -7
  89. package/docs/articles/brass-runtime-http-observability.md +467 -0
  90. package/docs/framework-integrations.md +38 -0
  91. package/docs/frameworks/angular.md +204 -0
  92. package/docs/frameworks/express.md +183 -0
  93. package/docs/frameworks/fastify.md +173 -0
  94. package/docs/frameworks/nestjs.md +335 -0
  95. package/docs/frameworks/nextjs.md +202 -0
  96. package/docs/frameworks/react.md +183 -0
  97. package/docs/frameworks/vanilla.md +280 -0
  98. package/docs/guides/layers.md +130 -0
  99. package/docs/http-recipes.md +31 -1
  100. package/docs/http.md +50 -1
  101. package/docs/nestjs.md +6 -0
  102. package/docs/observability-framework-examples.md +12 -0
  103. package/docs/observability.md +239 -0
  104. package/docs/performance-profiler.md +6 -2
  105. package/docs/recipes/layers.md +46 -2
  106. package/docs/recipes/testing.md +25 -0
  107. package/package.json +4 -1
  108. package/dist/chunk-3LOYJFRR.cjs +0 -300
  109. package/dist/chunk-3Y2RIUMM.js +0 -300
  110. package/dist/chunk-5EC274J5.cjs +0 -2874
  111. package/dist/chunk-5VRJNBLZ.mjs +0 -2874
  112. package/dist/chunk-62AZW6UT.cjs +0 -313
  113. package/dist/chunk-74ZTY6CP.js +0 -2871
  114. package/dist/chunk-7CMJS3QE.mjs +0 -2871
  115. package/dist/chunk-A2OM6NEH.mjs +0 -194
  116. package/dist/chunk-B33ICAKP.js +0 -313
  117. package/dist/chunk-JF5WGYJJ.cjs +0 -194
  118. package/dist/chunk-KN32XNTH.mjs +0 -313
  119. package/dist/chunk-KQLYONSE.cjs +0 -2871
  120. package/dist/chunk-L2SYFEBS.js +0 -194
  121. package/dist/chunk-MIIYDLGM.js +0 -2874
  122. package/dist/chunk-PWC3RBQE.mjs +0 -300
  123. package/dist/client-CZHU674n.d.ts +0 -820
@@ -1,12 +1,10 @@
1
1
  import {
2
- ensuring
3
- } from "./chunk-KN32XNTH.mjs";
2
+ makeRuntimeEventRecord
3
+ } from "./chunk-OT2TESZU.mjs";
4
4
  import {
5
+ layerEffect,
5
6
  makeScheduleDriver
6
- } from "./chunk-2HQTDLHF.mjs";
7
- import {
8
- makeRuntimeEventRecord
9
- } from "./chunk-EJ6BPYVR.mjs";
7
+ } from "./chunk-ELLF55ER.mjs";
10
8
  import {
11
9
  Runtime,
12
10
  getCurrentFiber,
@@ -14,7 +12,7 @@ import {
14
12
  runtimeClockFromEnv,
15
13
  toPromise,
16
14
  unsafeRunAsync
17
- } from "./chunk-GYM3LLGS.mjs";
15
+ } from "./chunk-2QNREG6K.mjs";
18
16
  import {
19
17
  Cause,
20
18
  Exit,
@@ -24,9 +22,11 @@ import {
24
22
  asyncFold,
25
23
  asyncMap,
26
24
  asyncSucceed,
27
- asyncSync,
28
- unit
25
+ asyncSync
29
26
  } from "./chunk-36I3M4UC.mjs";
27
+ import {
28
+ parseConfig
29
+ } from "./chunk-6MLAZPBL.mjs";
30
30
 
31
31
  // src/core/types/cancel.ts
32
32
  function makeCancelToken() {
@@ -636,275 +636,19 @@ function neverEffect() {
636
636
  });
637
637
  }
638
638
 
639
- // src/core/runtime/layer.ts
640
- var MissingLayerServiceError = class extends Error {
641
- _tag = "MissingLayerService";
642
- serviceName;
643
- constructor(serviceName) {
644
- super(`Missing layer service '${serviceName}'. Add a layer that provides this ServiceTag or pass a LayerContext containing it.`);
645
- this.name = "MissingLayerServiceError";
646
- this.serviceName = serviceName;
647
- }
648
- };
649
- function formatLayerError(error) {
650
- if (error instanceof MissingLayerServiceError) return error.message;
651
- if (isObjectRecord(error) && error._tag === "MissingLayerService" && typeof error.serviceName === "string") {
652
- return `Missing layer service '${error.serviceName}'. Add the provider layer before using the service.`;
653
- }
654
- return error instanceof Error ? error.message : String(error);
655
- }
656
- function makeServiceTag(name) {
657
- return {
658
- _tag: "ServiceTag",
659
- key: Symbol(name),
660
- name
661
- };
662
- }
663
- var serviceTag = makeServiceTag;
664
- var defineService = makeServiceTag;
665
- var LayerContext = class _LayerContext {
666
- services;
667
- constructor(entries) {
668
- if (entries instanceof Map) {
669
- this.services = new Map(entries);
670
- return;
671
- }
672
- this.services = /* @__PURE__ */ new Map();
673
- if (!entries) return;
674
- for (const [tag, service] of entries) this.services.set(tag.key, service);
675
- }
676
- static empty() {
677
- return new _LayerContext();
678
- }
679
- get(tag) {
680
- return this.services.get(tag.key);
681
- }
682
- unsafeGet(tag) {
683
- if (!this.services.has(tag.key)) {
684
- throw new MissingLayerServiceError(tag.name);
685
- }
686
- return this.services.get(tag.key);
687
- }
688
- has(tag) {
689
- return this.services.has(tag.key);
690
- }
691
- add(tag, service) {
692
- const next = new Map(this.services);
693
- next.set(tag.key, service);
694
- return new _LayerContext(next);
695
- }
696
- merge(other) {
697
- const next = new Map(this.services);
698
- for (const [key, service] of other.services) next.set(key, service);
699
- return new _LayerContext(next);
700
- }
701
- size() {
702
- return this.services.size;
703
- }
704
- };
705
- function makeLayerScope() {
706
- const cache = /* @__PURE__ */ new WeakMap();
707
- const finalizers = [];
708
- let closed = false;
709
- const scope = {
710
- get: (l, deps) => {
711
- if (closed) return asyncFail(new Error("LayerScope is closed"));
712
- if (cache.has(l)) return asyncSucceed(cache.get(l));
713
- const built = l.buildScoped ? l.buildScoped(deps, scope) : asyncFlatMap(
714
- l.build(deps),
715
- ({ service, release }) => asyncFlatMap(scope.addFinalizer(release), () => asyncSucceed(service))
716
- );
717
- return asyncFlatMap(
718
- built,
719
- (service) => asyncSync(() => {
720
- cache.set(l, service);
721
- return service;
722
- })
723
- );
724
- },
725
- close: () => {
726
- if (closed) return unit();
727
- closed = true;
728
- return releaseAll(finalizers);
729
- },
730
- size: () => finalizers.length,
731
- addFinalizer: (release) => asyncSync(() => {
732
- if (!closed) finalizers.push(release);
733
- })
734
- };
735
- return scope;
736
- }
737
- function releaseAll(finalizers) {
738
- const next = finalizers.pop();
739
- if (!next) return unit();
740
- return asyncFold(
741
- next(),
742
- () => releaseAll(finalizers),
743
- () => releaseAll(finalizers)
744
- );
745
- }
746
- function mergeServices(a, b) {
747
- if (a instanceof LayerContext && b instanceof LayerContext) {
748
- return a.merge(b);
749
- }
750
- if (isObjectRecord(a) && isObjectRecord(b)) {
751
- return { ...a, ...b };
752
- }
753
- return Object.assign({}, a, b);
754
- }
755
- function isObjectRecord(value) {
756
- return typeof value === "object" && value !== null;
757
- }
758
- function layer(acquire, release) {
759
- return {
760
- _tag: "Layer",
761
- build: (_deps) => asyncFlatMap(acquire(), (service) => asyncSucceed({
762
- service,
763
- release: release ? () => release(service) : () => unit()
764
- }))
765
- };
766
- }
767
- function layerValue(tag, value) {
768
- return layerEffect(tag, () => asyncSucceed(value));
769
- }
770
- function layerEffect(tag, acquire, release) {
771
- return {
772
- _tag: "Layer",
773
- build: (deps = LayerContext.empty()) => asyncFlatMap(acquire(deps), (service) => asyncSucceed({
774
- service: deps.add(tag, service),
775
- release: release ? () => release(service) : () => unit()
776
- }))
777
- };
778
- }
779
- var layerFromContext = layerEffect;
780
- var defineLayer = layerEffect;
781
- function getService(tag) {
782
- return asyncSync((context) => context.unsafeGet(tag));
783
- }
784
- function layerFrom() {
785
- return (acquire, release) => ({
786
- _tag: "Layer",
787
- build: (deps) => asyncFlatMap(acquire(deps), (service) => asyncSucceed({
788
- service,
789
- release: release ? () => release(service) : () => unit()
790
- }))
791
- });
792
- }
793
- function layerSucceed(value) {
794
- return {
795
- _tag: "Layer",
796
- build: () => asyncSucceed({ service: value, release: () => unit() })
797
- };
798
- }
799
- function layerFail(error) {
800
- return {
801
- _tag: "Layer",
802
- build: () => asyncFail(error)
803
- };
804
- }
805
- function compose(from, to) {
806
- return {
807
- _tag: "Layer",
808
- buildScoped: (deps, scope) => asyncFlatMap(
809
- scope.get(from, deps),
810
- (mid) => scope.get(to, mid)
811
- ),
812
- build: (deps) => asyncFlatMap(
813
- from.build(deps),
814
- ({ service: mid, release: releaseMid }) => asyncFold(
815
- to.build(mid),
816
- (error) => asyncFlatMap(releaseMid(), () => asyncFail(error)),
817
- ({ service: out, release: releaseOut }) => asyncSucceed({
818
- service: out,
819
- release: () => asyncFlatMap(releaseOut(), () => releaseMid())
820
- })
821
- )
822
- )
823
- };
824
- }
825
- function merge(left, right) {
826
- return {
827
- _tag: "Layer",
828
- buildScoped: (deps, scope) => asyncFlatMap(
829
- scope.get(left, deps),
830
- (a) => asyncFlatMap(
831
- scope.get(right, deps),
832
- (b) => asyncSucceed(mergeServices(a, b))
833
- )
834
- ),
835
- build: (deps) => asyncFlatMap(
836
- left.build(deps),
837
- ({ service: a, release: releaseA }) => asyncFold(
838
- right.build(deps),
839
- (error) => asyncFlatMap(releaseA(), () => asyncFail(error)),
840
- ({ service: b, release: releaseB }) => asyncSucceed({
841
- service: mergeServices(a, b),
842
- release: () => asyncFlatMap(releaseB(), () => releaseA())
843
- })
844
- )
845
- )
846
- };
847
- }
848
- function mapLayer(l, f) {
849
- return {
850
- _tag: "Layer",
851
- buildScoped: (deps, scope) => asyncFlatMap(
852
- scope.get(l, deps),
853
- (service) => asyncSucceed(f(service))
854
- ),
855
- build: (deps) => asyncFlatMap(
856
- l.build(deps),
857
- ({ service, release }) => asyncSucceed({ service: f(service), release })
639
+ // src/core/runtime/configLayer.ts
640
+ function makeConfigLayer(tag, schema, source, options = {}) {
641
+ return layerEffect(
642
+ tag,
643
+ (context) => asyncSync(
644
+ () => parseConfig(options.name ?? tag.name, schema, readConfigSource(source, context))
858
645
  )
859
- };
860
- }
861
- function buildLayer(l, deps) {
862
- const scope = makeLayerScope();
863
- return asyncFold(
864
- scope.get(l, deps),
865
- (error) => asyncFlatMap(scope.close(), () => asyncFail(error)),
866
- (service) => asyncSucceed({
867
- service,
868
- scope,
869
- close: scope.close,
870
- use: (body) => body(service)
871
- })
872
646
  );
873
647
  }
874
- function provideLayer(l, use, deps) {
875
- return asyncFlatMap(
876
- buildLayer(l, deps ?? {}),
877
- ({ service, close }) => ensuring(
878
- use(service),
879
- () => close()
880
- )
881
- );
648
+ var defineConfigLayer = makeConfigLayer;
649
+ function readConfigSource(source, context) {
650
+ return typeof source === "function" ? source(context) : source;
882
651
  }
883
- function provideLayerContext(l, use, deps = LayerContext.empty()) {
884
- return provideLayer(l, use, deps);
885
- }
886
- var provide = provideLayer;
887
- var provideContext = provideLayerContext;
888
- var Layer = Object.freeze({
889
- make: layer,
890
- from: layerFrom,
891
- succeed: layerSucceed,
892
- fail: layerFail,
893
- value: layerValue,
894
- effect: layerEffect,
895
- define: defineLayer,
896
- fromContext: layerFromContext,
897
- compose,
898
- merge,
899
- map: mapLayer,
900
- provide: provideLayer,
901
- provideContext: provideLayerContext,
902
- build: buildLayer,
903
- scope: makeLayerScope,
904
- context: LayerContext.empty,
905
- tag: makeServiceTag,
906
- service: getService
907
- });
908
652
 
909
653
  // src/core/runtime/workerPool.ts
910
654
  function makeWorkerPool(config = {}) {
@@ -1586,31 +1330,8 @@ export {
1586
1330
  flakyEffect,
1587
1331
  delayedEffect,
1588
1332
  neverEffect,
1589
- MissingLayerServiceError,
1590
- formatLayerError,
1591
- makeServiceTag,
1592
- serviceTag,
1593
- defineService,
1594
- LayerContext,
1595
- makeLayerScope,
1596
- layer,
1597
- layerValue,
1598
- layerEffect,
1599
- layerFromContext,
1600
- defineLayer,
1601
- getService,
1602
- layerFrom,
1603
- layerSucceed,
1604
- layerFail,
1605
- compose,
1606
- merge,
1607
- mapLayer,
1608
- buildLayer,
1609
- provideLayer,
1610
- provideLayerContext,
1611
- provide,
1612
- provideContext,
1613
- Layer,
1333
+ makeConfigLayer,
1334
+ defineConfigLayer,
1614
1335
  makeWorkerPool,
1615
1336
  makeTracer,
1616
1337
  consoleJsonLogger,
@@ -2,11 +2,9 @@ import {
2
2
  race
3
3
  } from "./chunk-B5JD23U7.mjs";
4
4
  import {
5
+ fromPromiseAbortable,
5
6
  withScopeAsync
6
- } from "./chunk-A2OM6NEH.mjs";
7
- import {
8
- fromPromiseAbortable
9
- } from "./chunk-GYM3LLGS.mjs";
7
+ } from "./chunk-2QNREG6K.mjs";
10
8
  import {
11
9
  Cause,
12
10
  Exit,
@@ -2,13 +2,11 @@ import {
2
2
  raceWith
3
3
  } from "./chunk-B5JD23U7.mjs";
4
4
  import {
5
- Scope
6
- } from "./chunk-A2OM6NEH.mjs";
7
- import {
5
+ Scope,
8
6
  getCurrentFiber,
9
7
  unsafeGetCurrentRuntime,
10
8
  unsafeRunFoldWithEnv
11
- } from "./chunk-GYM3LLGS.mjs";
9
+ } from "./chunk-2QNREG6K.mjs";
12
10
  import {
13
11
  Cause,
14
12
  Exit,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  makeRuntimeEventRecord
3
- } from "./chunk-RKGKFN2A.js";
3
+ } from "./chunk-AADFFVYS.js";
4
4
  import {
5
5
  emptyContext,
6
6
  getCurrentFiber
7
- } from "./chunk-FH2X7BVP.js";
7
+ } from "./chunk-XSAHV5HQ.js";
8
8
  import {
9
9
  Cause,
10
10
  asyncFlatMap,
@@ -1,4 +1,7 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19;
2
+
3
+
4
+
2
5
 
3
6
 
4
7
 
@@ -7,7 +10,7 @@ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
7
10
 
8
11
 
9
12
 
10
- var _chunkCZIVE6NTcjs = require('./chunk-CZIVE6NT.cjs');
13
+ var _chunkUUMKZJRJcjs = require('./chunk-UUMKZJRJ.cjs');
11
14
 
12
15
  // src/core/runtime/ringBuffer.ts
13
16
  var PushStatus = /* @__PURE__ */ ((PushStatus3) => {
@@ -2824,11 +2827,11 @@ function normalizeRuntimeEngineMode(value) {
2824
2827
  function unreachableEngine(value) {
2825
2828
  throw new Error(`brass-runtime unsupported engine '${String(value)}'`);
2826
2829
  }
2827
- var runtimeOptionsSchema = _chunkCZIVE6NTcjs.Schema.object({
2828
- env: _chunkCZIVE6NTcjs.Schema.any(),
2829
- lane: _chunkCZIVE6NTcjs.Schema.string({ minLength: 1 }).optional(),
2830
- inferLane: _chunkCZIVE6NTcjs.Schema.boolean().optional(),
2831
- engine: _chunkCZIVE6NTcjs.Schema.enum(["ts", "wasm"]).optional()
2830
+ var runtimeOptionsSchema = _chunkUUMKZJRJcjs.Schema.object({
2831
+ env: _chunkUUMKZJRJcjs.Schema.any(),
2832
+ lane: _chunkUUMKZJRJcjs.Schema.string({ minLength: 1 }).optional(),
2833
+ inferLane: _chunkUUMKZJRJcjs.Schema.boolean().optional(),
2834
+ engine: _chunkUUMKZJRJcjs.Schema.enum(["ts", "wasm"]).optional()
2832
2835
  }, { unknownKeys: "passthrough" });
2833
2836
  var Runtime = class _Runtime {
2834
2837
 
@@ -2845,7 +2848,7 @@ var Runtime = class _Runtime {
2845
2848
  // opcional: registry para observabilidad
2846
2849
 
2847
2850
  constructor(args) {
2848
- _chunkCZIVE6NTcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
2851
+ _chunkUUMKZJRJcjs.parseConfig.call(void 0, "RuntimeOptions", runtimeOptionsSchema, args);
2849
2852
  this.env = args.env;
2850
2853
  this.scheduler = _nullishCoalesce(args.scheduler, () => ( globalScheduler));
2851
2854
  this.lane = args.lane;
@@ -2978,7 +2981,7 @@ var Runtime = class _Runtime {
2978
2981
  if (this.hooks !== NoopHooks) return false;
2979
2982
  if (getCurrentFiber() !== null) return false;
2980
2983
  if (this.scheduler !== globalScheduler) return false;
2981
- if (this.lane !== void 0 || this.inferLane) return false;
2984
+ if (this.inferLane) return false;
2982
2985
  if (this.engineMode !== "ts") return false;
2983
2986
  new NativeTopLevelRunner(this, effect, cb).start();
2984
2987
  return true;
@@ -3137,7 +3140,7 @@ var NativeTopLevelRunner = (_class16 = class {
3137
3140
  syncExit = exit;
3138
3141
  return;
3139
3142
  }
3140
- queueMicrotask(() => this.resumeAsync(exit));
3143
+ this.resumeAsync(exit);
3141
3144
  };
3142
3145
  try {
3143
3146
  current.register(this.runtime.env, resume);
@@ -4035,6 +4038,186 @@ var JsFiberEngine = (_class18 = class {
4035
4038
  }
4036
4039
  }, _class18);
4037
4040
 
4041
+ // src/core/runtime/scope.ts
4042
+ var nextScopeId = 1;
4043
+ function awaitAll(fibers) {
4044
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
4045
+ let remaining = fibers.length;
4046
+ if (remaining === 0) {
4047
+ cb({ _tag: "Success", value: void 0 });
4048
+ return;
4049
+ }
4050
+ for (const f of fibers) {
4051
+ f.join(() => {
4052
+ remaining -= 1;
4053
+ if (remaining === 0) cb({ _tag: "Success", value: void 0 });
4054
+ });
4055
+ }
4056
+ });
4057
+ }
4058
+ var Scope = (_class19 = class _Scope {
4059
+ constructor(runtime, parentScopeId) {;_class19.prototype.__init119.call(this);_class19.prototype.__init120.call(this);_class19.prototype.__init121.call(this);_class19.prototype.__init122.call(this);
4060
+ this.runtime = runtime;
4061
+ this.parentScopeId = parentScopeId;
4062
+ this.id = nextScopeId++;
4063
+ const inferredParent = _nullishCoalesce(this.parentScopeId, () => ( _optionalChain([getCurrentFiber, 'call', _218 => _218(), 'optionalAccess', _219 => _219.scopeId])));
4064
+ if (this.runtime.hasActiveHooks()) {
4065
+ this.runtime.emit({
4066
+ type: "scope.open",
4067
+ scopeId: this.id,
4068
+ parentScopeId: inferredParent
4069
+ });
4070
+ }
4071
+ }
4072
+
4073
+
4074
+
4075
+ __init119() {this.closed = false}
4076
+ __init120() {this.children = /* @__PURE__ */ new Set()}
4077
+ __init121() {this.subScopes = /* @__PURE__ */ new Set()}
4078
+ __init122() {this.finalizers = []}
4079
+ /** registra un finalizer (LIFO) */
4080
+ addFinalizer(f) {
4081
+ if (this.closed) {
4082
+ throw new Error("Trying to add finalizer to closed scope");
4083
+ }
4084
+ this.finalizers.push(f);
4085
+ }
4086
+ /** crea un sub scope (mismo runtime) */
4087
+ subScope() {
4088
+ if (this.closed) throw new Error("Scope closed");
4089
+ const s = new _Scope(this.runtime, this.id);
4090
+ this.subScopes.add(s);
4091
+ return s;
4092
+ }
4093
+ /** ✅ fork en este scope */
4094
+ fork(eff) {
4095
+ if (this.closed) throw new Error("Scope closed");
4096
+ const f = this.runtime.fork(eff, this.id);
4097
+ this.children.add(f);
4098
+ f.join(() => this.children.delete(f));
4099
+ return f;
4100
+ }
4101
+ /** close fire-and-forget (no bloquea) */
4102
+ close(exit = { _tag: "Success", value: void 0 }) {
4103
+ this.runtime.fork(this.closeAsync(exit));
4104
+ }
4105
+ /** Emit the scope.close event if hooks are active. */
4106
+ emitCloseEvent(exit) {
4107
+ if (this.runtime.hasActiveHooks()) {
4108
+ const status = exit._tag === "Success" ? "success" : _chunkMVGUEJ5Zcjs.Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failure";
4109
+ const failure = exit._tag === "Failure" ? _chunkMVGUEJ5Zcjs.Cause.firstFailure(exit.cause) : void 0;
4110
+ this.runtime.emit({
4111
+ type: "scope.close",
4112
+ scopeId: this.id,
4113
+ status,
4114
+ error: _optionalChain([failure, 'optionalAccess', _220 => _220._tag]) === "Some" ? failure.value : exit._tag === "Failure" ? exit.cause : void 0
4115
+ });
4116
+ }
4117
+ }
4118
+ /**
4119
+ * Build an effect that executes finalizers in LIFO order.
4120
+ *
4121
+ * Optimization over the original: instead of wrapping every finalizer in
4122
+ * `asyncFold(fin(exit), () => unit(), () => unit())` which creates 3 effect
4123
+ * nodes per finalizer (Fold + 2 Succeed), we use a single Sync thunk per
4124
+ * finalizer that catches errors inline. When the finalizer returns a
4125
+ * Succeed effect (like `unit()`), the Sync thunk completes without creating
4126
+ * additional effect nodes.
4127
+ */
4128
+ buildFinalizerEffect(exit) {
4129
+ const fins = this.finalizers;
4130
+ if (fins.length === 0) return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4131
+ let chain = _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4132
+ for (let i = fins.length - 1; i >= 0; i--) {
4133
+ const fin = fins[i];
4134
+ chain = _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, chain, () => {
4135
+ let result;
4136
+ try {
4137
+ result = fin(exit);
4138
+ } catch (e15) {
4139
+ return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4140
+ }
4141
+ if (result._tag === "Succeed") {
4142
+ return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4143
+ }
4144
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
4145
+ result,
4146
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
4147
+ () => _chunkMVGUEJ5Zcjs.unit.call(void 0, )
4148
+ );
4149
+ });
4150
+ }
4151
+ return chain;
4152
+ }
4153
+ closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
4154
+ return _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0,
4155
+ _chunkMVGUEJ5Zcjs.unit.call(void 0, ),
4156
+ () => _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (env, cb) => {
4157
+ if (this.closed) {
4158
+ cb({ _tag: "Success", value: void 0 });
4159
+ return;
4160
+ }
4161
+ this.closed = true;
4162
+ const children = Array.from(this.children);
4163
+ const subScopes = Array.from(this.subScopes);
4164
+ for (const child of children) {
4165
+ child.interrupt();
4166
+ }
4167
+ const closeSubs = subScopes.reduceRight(
4168
+ (acc, s) => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, acc, () => s.closeAsync(exit, opts)),
4169
+ _chunkMVGUEJ5Zcjs.unit.call(void 0, )
4170
+ );
4171
+ const runFinalizers = this.buildFinalizerEffect(exit);
4172
+ const needsAwait = opts.awaitChildren && children.length > 0;
4173
+ const awaitChildrenEff = needsAwait ? awaitAll(children) : _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4174
+ const hasSubScopes = subScopes.length > 0;
4175
+ const hasNoFinalizers = this.finalizers.length === 0;
4176
+ if (!hasSubScopes && !needsAwait && hasNoFinalizers) {
4177
+ this.emitCloseEvent(exit);
4178
+ cb({ _tag: "Success", value: void 0 });
4179
+ return;
4180
+ }
4181
+ const all = _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, closeSubs, () => _chunkMVGUEJ5Zcjs.asyncFlatMap.call(void 0, awaitChildrenEff, () => runFinalizers));
4182
+ this.runtime.fork(all).join(() => {
4183
+ this.emitCloseEvent(exit);
4184
+ cb({ _tag: "Success", value: void 0 });
4185
+ });
4186
+ })
4187
+ );
4188
+ }
4189
+ }, _class19);
4190
+ function withScopeAsync(runtime, f) {
4191
+ return _chunkMVGUEJ5Zcjs.asyncEffect.call(void 0, (_env, cb) => {
4192
+ const scope = new Scope(runtime);
4193
+ let done = false;
4194
+ const completeAfterClose = (exit) => {
4195
+ runtime.fork(scope.closeAsync(exit)).join(() => {
4196
+ if (done) return;
4197
+ done = true;
4198
+ cb(exit);
4199
+ });
4200
+ };
4201
+ const fiber = runtime.fork(f(scope));
4202
+ fiber.join(completeAfterClose);
4203
+ return () => {
4204
+ if (done) return;
4205
+ fiber.interrupt();
4206
+ runtime.fork(scope.closeAsync(_chunkMVGUEJ5Zcjs.Exit.failCause(_chunkMVGUEJ5Zcjs.Cause.interrupt())));
4207
+ };
4208
+ });
4209
+ }
4210
+ function withScope(runtime, f) {
4211
+ return withScopeAsync(runtime, (scope) => {
4212
+ const out = f(scope);
4213
+ if (out && typeof out === "object" && "_tag" in out) return out;
4214
+ return _chunkMVGUEJ5Zcjs.unit.call(void 0, );
4215
+ });
4216
+ }
4217
+
4218
+
4219
+
4220
+
4038
4221
 
4039
4222
 
4040
4223
 
@@ -4086,4 +4269,4 @@ var JsFiberEngine = (_class18 = class {
4086
4269
 
4087
4270
 
4088
4271
 
4089
- exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.emptyContext = emptyContext; exports.ctxExtend = ctxExtend; exports.ctxToObject = ctxToObject; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.liveClock = liveClock; exports.runtimeClockFromEnv = runtimeClockFromEnv; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber;
4272
+ exports.PushStatus = PushStatus; exports.RingBuffer = RingBuffer; exports.resolveWasmModule = resolveWasmModule; exports.makeBoundedRingBuffer = makeBoundedRingBuffer; exports.sanitizeLaneKey = sanitizeLaneKey; exports.laneTag = laneTag; exports.inferCallerLaneFromStack = inferCallerLaneFromStack; exports.Scheduler = Scheduler; exports.globalScheduler = globalScheduler; exports.emptyContext = emptyContext; exports.ctxExtend = ctxExtend; exports.ctxToObject = ctxToObject; exports.DefaultHostExecutor = DefaultHostExecutor; exports.JsFiberEngine = JsFiberEngine; exports.HostRegistry = HostRegistry; exports.ProgramBuilder = ProgramBuilder; exports.EngineFiberHandle = EngineFiberHandle; exports.ABI_VERSION = ABI_VERSION; exports.EVENT_WORDS = EVENT_WORDS; exports.NONE_U32 = NONE_U32; exports.OpcodeTagCode = OpcodeTagCode; exports.EventKindCode = EventKindCode; exports.encodeOpcodeProgram = encodeOpcodeProgram; exports.encodeOpcodeNodes = encodeOpcodeNodes; exports.decodeEvent = decodeEvent; exports.decodeEventBatch = decodeEventBatch; exports.WasmPackFiberBridge = WasmPackFiberBridge; exports.WasmFiberRegistryBridge = WasmFiberRegistryBridge; exports.makeFiberReadyQueue = makeFiberReadyQueue; exports.WasmFiberEngine = WasmFiberEngine; exports.runtimeCapabilities = runtimeCapabilities; exports.liveClock = liveClock; exports.runtimeClockFromEnv = runtimeClockFromEnv; exports.NoopHooks = NoopHooks; exports.Runtime = Runtime; exports.fork = fork; exports.runtimeForCaller = runtimeForCaller; exports.toPromiseByCaller = toPromiseByCaller; exports.unsafeRunAsync = unsafeRunAsync; exports.toPromise = toPromise; exports.abortablePromiseStats = abortablePromiseStats; exports.resetAbortablePromiseStats = resetAbortablePromiseStats; exports.fromPromiseAbortable = fromPromiseAbortable; exports.unsafeRunFoldWithEnv = unsafeRunFoldWithEnv; exports.setBenchmarkBudget = setBenchmarkBudget; exports.getBenchmarkBudget = getBenchmarkBudget; exports.RuntimeFiber = RuntimeFiber; exports.getCurrentFiber = getCurrentFiber; exports.unsafeGetCurrentRuntime = unsafeGetCurrentRuntime; exports.withCurrentFiber = withCurrentFiber; exports.Scope = Scope; exports.withScopeAsync = withScopeAsync; exports.withScope = withScope;