brass-runtime 1.15.0 → 1.16.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 (93) hide show
  1. package/README.md +409 -137
  2. package/dist/agent/cli/main.cjs +40 -35
  3. package/dist/agent/cli/main.js +9 -4
  4. package/dist/agent/cli/main.mjs +9 -4
  5. package/dist/agent/index.cjs +8 -4
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +7 -3
  8. package/dist/agent/index.mjs +7 -3
  9. package/dist/{chunk-PPUXIH5R.js → chunk-2WC63LJK.mjs} +11 -7
  10. package/dist/chunk-3RG5ZIWI.js +10 -0
  11. package/dist/chunk-45F7OKGT.cjs +104 -0
  12. package/dist/chunk-5YOQOXEQ.cjs +2491 -0
  13. package/dist/{chunk-STVLQ3XD.cjs → chunk-7HUOJA4W.cjs} +78 -74
  14. package/dist/{chunk-BMH5AV44.js → chunk-7LVI2GIN.js} +251 -370
  15. package/dist/chunk-7TL2LHQJ.js +2491 -0
  16. package/dist/chunk-7V4KY4RL.mjs +104 -0
  17. package/dist/chunk-7XOPAB5Q.js +2143 -0
  18. package/dist/chunk-CCKHV5BT.mjs +193 -0
  19. package/dist/{chunk-AR22SXML.js → chunk-CY33PGEX.mjs} +488 -421
  20. package/dist/chunk-DJQ7OMMB.cjs +144 -0
  21. package/dist/chunk-F5EUMJL7.mjs +2143 -0
  22. package/dist/chunk-FM4W4QPL.js +193 -0
  23. package/dist/{chunk-TO7IKXYT.js → chunk-G3XGCZDQ.js} +1 -1
  24. package/dist/{chunk-BDF4AMWX.mjs → chunk-G6IQOE4P.mjs} +251 -370
  25. package/dist/chunk-GOV47PPB.mjs +552 -0
  26. package/dist/chunk-H55LI6WY.js +93 -0
  27. package/dist/chunk-IJT6RRQ5.cjs +93 -0
  28. package/dist/{chunk-ELOOF35R.mjs → chunk-J3H54ZRV.mjs} +1 -1
  29. package/dist/chunk-JF4XXPZ5.cjs +552 -0
  30. package/dist/chunk-JNFRRJYH.cjs +2143 -0
  31. package/dist/chunk-JX3LZQJH.cjs +354 -0
  32. package/dist/chunk-K2T3DV26.mjs +93 -0
  33. package/dist/chunk-KCPT2D6G.js +552 -0
  34. package/dist/chunk-MWXMNYJS.cjs +1110 -0
  35. package/dist/{chunk-VEZNF5GZ.cjs → chunk-N6VHMOWB.cjs} +130 -126
  36. package/dist/{chunk-3QMOKAS5.js → chunk-NC5SDRYE.js} +9 -5
  37. package/dist/chunk-NOYZIMUJ.mjs +144 -0
  38. package/dist/{chunk-R3R2FVLG.cjs → chunk-NYL4D7SK.cjs} +5 -5
  39. package/dist/chunk-OBGZSXTJ.cjs +10 -0
  40. package/dist/{chunk-4NHES7VK.mjs → chunk-OOGJ73B6.js} +11 -7
  41. package/dist/chunk-PNVFW245.js +144 -0
  42. package/dist/chunk-PRWCB3QL.mjs +2491 -0
  43. package/dist/{chunk-JFPU5GQI.mjs → chunk-QY5FKYEQ.js} +488 -421
  44. package/dist/chunk-ROJC3NBJ.js +104 -0
  45. package/dist/chunk-SPUEME2B.cjs +343 -0
  46. package/dist/chunk-TDVMADDN.js +343 -0
  47. package/dist/chunk-TVN5I4U6.cjs +193 -0
  48. package/dist/chunk-U5KWK3PX.mjs +343 -0
  49. package/dist/chunk-VFIUZG7J.mjs +354 -0
  50. package/dist/{chunk-TGIFUAK4.cjs → chunk-WQ5QNU5R.cjs} +459 -578
  51. package/dist/chunk-XDZOO4L5.js +354 -0
  52. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  53. package/dist/{chunk-K6M7MDZ4.mjs → chunk-ZGLD4TVZ.mjs} +9 -5
  54. package/dist/client-CtFmoDvM.d.ts +645 -0
  55. package/dist/core/index.cjs +72 -4
  56. package/dist/core/index.d.ts +92 -198
  57. package/dist/core/index.js +106 -38
  58. package/dist/core/index.mjs +106 -38
  59. package/dist/{effect-CMOQKX8y.d.ts → effect-CGNl5Rqp.d.ts} +107 -1
  60. package/dist/effectRunner-3ZHAD3LE.cjs +8 -0
  61. package/dist/effectRunner-A4CHJXJI.js +8 -0
  62. package/dist/effectRunner-OPUF6QRN.mjs +8 -0
  63. package/dist/http/index.cjs +2189 -1271
  64. package/dist/http/index.d.ts +830 -270
  65. package/dist/http/index.js +2008 -1090
  66. package/dist/http/index.mjs +2008 -1090
  67. package/dist/http/testing.cjs +159 -0
  68. package/dist/http/testing.d.ts +42 -0
  69. package/dist/http/testing.js +159 -0
  70. package/dist/http/testing.mjs +159 -0
  71. package/dist/index.cjs +246 -178
  72. package/dist/index.d.ts +9 -35
  73. package/dist/index.js +120 -52
  74. package/dist/index.mjs +120 -52
  75. package/dist/observability/index.cjs +677 -0
  76. package/dist/observability/index.d.ts +79 -0
  77. package/dist/observability/index.js +677 -0
  78. package/dist/observability/index.mjs +677 -0
  79. package/dist/schedule-Fque9Abz.d.ts +70 -0
  80. package/dist/schema/index.cjs +25 -0
  81. package/dist/schema/index.d.ts +177 -0
  82. package/dist/schema/index.js +25 -0
  83. package/dist/schema/index.mjs +25 -0
  84. package/dist/server-C8hDXA74.d.ts +674 -0
  85. package/dist/{stream-FQm9h4Mg.d.ts → stream-dvSs0QS5.d.ts} +1 -1
  86. package/dist/tracer-B5tRH9H7.d.ts +230 -0
  87. package/dist/tracing-Dt9S_6V8.d.ts +148 -0
  88. package/package.json +27 -1
  89. package/dist/chunk-BDYEENHT.js +0 -224
  90. package/dist/chunk-MS34J5LY.cjs +0 -224
  91. package/dist/chunk-UMAZLXAB.mjs +0 -224
  92. package/dist/chunk-XPZNXSVN.cjs +0 -1043
  93. package/dist/tracing-DNT9jEbr.d.ts +0 -106
@@ -0,0 +1,193 @@
1
+ import {
2
+ getCurrentFiber
3
+ } from "./chunk-G6IQOE4P.mjs";
4
+ import {
5
+ Cause,
6
+ Exit,
7
+ asyncEffect,
8
+ asyncFlatMap,
9
+ asyncFold,
10
+ unit
11
+ } from "./chunk-NOYZIMUJ.mjs";
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" : exit.cause._tag === "Interrupt" ? "interrupted" : "failure";
81
+ this.runtime.emit({
82
+ type: "scope.close",
83
+ scopeId: this.id,
84
+ status,
85
+ error: exit._tag === "Failure" && exit.cause._tag === "Fail" ? exit.cause.error : void 0
86
+ });
87
+ }
88
+ }
89
+ /**
90
+ * Build an effect that executes finalizers in LIFO order.
91
+ *
92
+ * Optimization over the original: instead of wrapping every finalizer in
93
+ * `asyncFold(fin(exit), () => unit(), () => unit())` which creates 3 effect
94
+ * nodes per finalizer (Fold + 2 Succeed), we use a single Sync thunk per
95
+ * finalizer that catches errors inline. When the finalizer returns a
96
+ * Succeed effect (like `unit()`), the Sync thunk completes without creating
97
+ * additional effect nodes.
98
+ */
99
+ buildFinalizerEffect(exit) {
100
+ const fins = this.finalizers;
101
+ if (fins.length === 0) return unit();
102
+ let chain = unit();
103
+ for (let i = fins.length - 1; i >= 0; i--) {
104
+ const fin = fins[i];
105
+ chain = asyncFlatMap(chain, () => {
106
+ let result;
107
+ try {
108
+ result = fin(exit);
109
+ } catch {
110
+ return unit();
111
+ }
112
+ if (result._tag === "Succeed") {
113
+ return unit();
114
+ }
115
+ return asyncFold(
116
+ result,
117
+ () => unit(),
118
+ () => unit()
119
+ );
120
+ });
121
+ }
122
+ return chain;
123
+ }
124
+ closeAsync(exit = { _tag: "Success", value: void 0 }, opts = { awaitChildren: true }) {
125
+ return asyncFlatMap(
126
+ unit(),
127
+ () => asyncEffect((env, cb) => {
128
+ if (this.closed) {
129
+ cb({ _tag: "Success", value: void 0 });
130
+ return;
131
+ }
132
+ this.closed = true;
133
+ const children = Array.from(this.children);
134
+ const subScopes = Array.from(this.subScopes);
135
+ for (const child of children) {
136
+ child.interrupt();
137
+ }
138
+ const closeSubs = subScopes.reduceRight(
139
+ (acc, s) => asyncFlatMap(acc, () => s.closeAsync(exit, opts)),
140
+ unit()
141
+ );
142
+ const runFinalizers = this.buildFinalizerEffect(exit);
143
+ const needsAwait = opts.awaitChildren && children.length > 0;
144
+ const awaitChildrenEff = needsAwait ? awaitAll(children) : unit();
145
+ const hasSubScopes = subScopes.length > 0;
146
+ const hasNoFinalizers = this.finalizers.length === 0;
147
+ if (!hasSubScopes && !needsAwait && hasNoFinalizers) {
148
+ this.emitCloseEvent(exit);
149
+ cb({ _tag: "Success", value: void 0 });
150
+ return;
151
+ }
152
+ const all = asyncFlatMap(closeSubs, () => asyncFlatMap(awaitChildrenEff, () => runFinalizers));
153
+ this.runtime.fork(all).join(() => {
154
+ this.emitCloseEvent(exit);
155
+ cb({ _tag: "Success", value: void 0 });
156
+ });
157
+ })
158
+ );
159
+ }
160
+ };
161
+ function withScopeAsync(runtime, f) {
162
+ return asyncEffect((_env, cb) => {
163
+ const scope = new Scope(runtime);
164
+ let done = false;
165
+ const completeAfterClose = (exit) => {
166
+ runtime.fork(scope.closeAsync(exit)).join(() => {
167
+ if (done) return;
168
+ done = true;
169
+ cb(exit);
170
+ });
171
+ };
172
+ const fiber = runtime.fork(f(scope));
173
+ fiber.join(completeAfterClose);
174
+ return () => {
175
+ if (done) return;
176
+ fiber.interrupt();
177
+ runtime.fork(scope.closeAsync(Exit.failCause(Cause.interrupt())));
178
+ };
179
+ });
180
+ }
181
+ function withScope(runtime, f) {
182
+ return withScopeAsync(runtime, (scope) => {
183
+ const out = f(scope);
184
+ if (out && typeof out === "object" && "_tag" in out) return out;
185
+ return unit();
186
+ });
187
+ }
188
+
189
+ export {
190
+ Scope,
191
+ withScopeAsync,
192
+ withScope
193
+ };