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-B33ICAKP.js";
2
+ makeRuntimeEventRecord
3
+ } from "./chunk-AADFFVYS.js";
4
4
  import {
5
+ layerEffect,
5
6
  makeScheduleDriver
6
- } from "./chunk-6IXXWIUM.js";
7
- import {
8
- makeRuntimeEventRecord
9
- } from "./chunk-RKGKFN2A.js";
7
+ } from "./chunk-IBRHSH5H.js";
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-FH2X7BVP.js";
15
+ } from "./chunk-XSAHV5HQ.js";
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-UB4B6OFY.js";
27
+ import {
28
+ parseConfig
29
+ } from "./chunk-HCJ4S3YB.js";
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,