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,194 +0,0 @@
1
- import {
2
- getCurrentFiber
3
- } from "./chunk-FH2X7BVP.js";
4
- import {
5
- Cause,
6
- Exit,
7
- asyncEffect,
8
- asyncFlatMap,
9
- asyncFold,
10
- unit
11
- } from "./chunk-UB4B6OFY.js";
12
-
13
- // src/core/runtime/scope.ts
14
- var nextScopeId = 1;
15
- function awaitAll(fibers) {
16
- return asyncEffect((_env, cb) => {
17
- let remaining = fibers.length;
18
- if (remaining === 0) {
19
- cb({ _tag: "Success", value: void 0 });
20
- return;
21
- }
22
- for (const f of fibers) {
23
- f.join(() => {
24
- remaining -= 1;
25
- if (remaining === 0) cb({ _tag: "Success", value: void 0 });
26
- });
27
- }
28
- });
29
- }
30
- var Scope = class _Scope {
31
- constructor(runtime, parentScopeId) {
32
- this.runtime = runtime;
33
- this.parentScopeId = parentScopeId;
34
- this.id = nextScopeId++;
35
- const inferredParent = this.parentScopeId ?? getCurrentFiber()?.scopeId;
36
- if (this.runtime.hasActiveHooks()) {
37
- this.runtime.emit({
38
- type: "scope.open",
39
- scopeId: this.id,
40
- parentScopeId: inferredParent
41
- });
42
- }
43
- }
44
- runtime;
45
- parentScopeId;
46
- id;
47
- closed = false;
48
- children = /* @__PURE__ */ new Set();
49
- subScopes = /* @__PURE__ */ new Set();
50
- finalizers = [];
51
- /** registra un finalizer (LIFO) */
52
- addFinalizer(f) {
53
- if (this.closed) {
54
- throw new Error("Trying to add finalizer to closed scope");
55
- }
56
- this.finalizers.push(f);
57
- }
58
- /** crea un sub scope (mismo runtime) */
59
- subScope() {
60
- if (this.closed) throw new Error("Scope closed");
61
- const s = new _Scope(this.runtime, this.id);
62
- this.subScopes.add(s);
63
- return s;
64
- }
65
- /** ✅ fork en este scope */
66
- fork(eff) {
67
- if (this.closed) throw new Error("Scope closed");
68
- const f = this.runtime.fork(eff, this.id);
69
- this.children.add(f);
70
- f.join(() => this.children.delete(f));
71
- return f;
72
- }
73
- /** close fire-and-forget (no bloquea) */
74
- close(exit = { _tag: "Success", value: void 0 }) {
75
- this.runtime.fork(this.closeAsync(exit));
76
- }
77
- /** Emit the scope.close event if hooks are active. */
78
- emitCloseEvent(exit) {
79
- if (this.runtime.hasActiveHooks()) {
80
- const status = exit._tag === "Success" ? "success" : Cause.isInterruptedOnly(exit.cause) ? "interrupted" : "failure";
81
- const failure = exit._tag === "Failure" ? Cause.firstFailure(exit.cause) : void 0;
82
- this.runtime.emit({
83
- type: "scope.close",
84
- scopeId: this.id,
85
- status,
86
- error: failure?._tag === "Some" ? failure.value : exit._tag === "Failure" ? exit.cause : void 0
87
- });
88
- }
89
- }
90
- /**
91
- * Build an effect that executes finalizers in LIFO order.
92
- *
93
- * Optimization over the original: instead of wrapping every finalizer in
94
- * `asyncFold(fin(exit), () => unit(), () => unit())` which creates 3 effect
95
- * nodes per finalizer (Fold + 2 Succeed), we use a single Sync thunk per
96
- * finalizer that catches errors inline. When the finalizer returns a
97
- * Succeed effect (like `unit()`), the Sync thunk completes without creating
98
- * additional effect nodes.
99
- */
100
- buildFinalizerEffect(exit) {
101
- const fins = this.finalizers;
102
- if (fins.length === 0) return unit();
103
- let chain = unit();
104
- for (let i = fins.length - 1; i >= 0; i--) {
105
- const fin = fins[i];
106
- chain = asyncFlatMap(chain, () => {
107
- let result;
108
- try {
109
- result = fin(exit);
110
- } catch {
111
- return unit();
112
- }
113
- if (result._tag === "Succeed") {
114
- return unit();
115
- }
116
- return asyncFold(
117
- result,
118
- () => unit(),
119
- () => unit()
120
- );
121
- });
122
- }
123
- return chain;
124
- }
125
- closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
126
- return asyncFlatMap(
127
- unit(),
128
- () => asyncEffect((env, cb) => {
129
- if (this.closed) {
130
- cb({ _tag: "Success", value: void 0 });
131
- return;
132
- }
133
- this.closed = true;
134
- const children = Array.from(this.children);
135
- const subScopes = Array.from(this.subScopes);
136
- for (const child of children) {
137
- child.interrupt();
138
- }
139
- const closeSubs = subScopes.reduceRight(
140
- (acc, s) => asyncFlatMap(acc, () => s.closeAsync(exit, opts)),
141
- unit()
142
- );
143
- const runFinalizers = this.buildFinalizerEffect(exit);
144
- const needsAwait = opts.awaitChildren && children.length > 0;
145
- const awaitChildrenEff = needsAwait ? awaitAll(children) : unit();
146
- const hasSubScopes = subScopes.length > 0;
147
- const hasNoFinalizers = this.finalizers.length === 0;
148
- if (!hasSubScopes && !needsAwait && hasNoFinalizers) {
149
- this.emitCloseEvent(exit);
150
- cb({ _tag: "Success", value: void 0 });
151
- return;
152
- }
153
- const all = asyncFlatMap(closeSubs, () => asyncFlatMap(awaitChildrenEff, () => runFinalizers));
154
- this.runtime.fork(all).join(() => {
155
- this.emitCloseEvent(exit);
156
- cb({ _tag: "Success", value: void 0 });
157
- });
158
- })
159
- );
160
- }
161
- };
162
- function withScopeAsync(runtime, f) {
163
- return asyncEffect((_env, cb) => {
164
- const scope = new Scope(runtime);
165
- let done = false;
166
- const completeAfterClose = (exit) => {
167
- runtime.fork(scope.closeAsync(exit)).join(() => {
168
- if (done) return;
169
- done = true;
170
- cb(exit);
171
- });
172
- };
173
- const fiber = runtime.fork(f(scope));
174
- fiber.join(completeAfterClose);
175
- return () => {
176
- if (done) return;
177
- fiber.interrupt();
178
- runtime.fork(scope.closeAsync(Exit.failCause(Cause.interrupt())));
179
- };
180
- });
181
- }
182
- function withScope(runtime, f) {
183
- return withScopeAsync(runtime, (scope) => {
184
- const out = f(scope);
185
- if (out && typeof out === "object" && "_tag" in out) return out;
186
- return unit();
187
- });
188
- }
189
-
190
- export {
191
- Scope,
192
- withScopeAsync,
193
- withScope
194
- };