brass-runtime 1.16.0 → 1.17.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 (219) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +287 -23
  3. package/dist/agent/cli/main.cjs +38 -38
  4. package/dist/agent/cli/main.js +6 -6
  5. package/dist/agent/cli/main.mjs +6 -6
  6. package/dist/agent/index.cjs +7 -7
  7. package/dist/agent/index.d.ts +1 -1
  8. package/dist/agent/index.js +6 -6
  9. package/dist/agent/index.mjs +6 -6
  10. package/dist/chunk-2HQTDLHF.mjs +683 -0
  11. package/dist/chunk-36I3M4UC.mjs +370 -0
  12. package/dist/{chunk-QY5FKYEQ.js → chunk-3AYM6WPJ.js} +570 -51
  13. package/dist/chunk-3LOYJFRR.cjs +300 -0
  14. package/dist/chunk-3Y2RIUMM.js +300 -0
  15. package/dist/{chunk-7XOPAB5Q.js → chunk-4P2HHGAX.mjs} +83 -5
  16. package/dist/{chunk-N6VHMOWB.cjs → chunk-4ROBZFL6.cjs} +128 -128
  17. package/dist/{chunk-NC5SDRYE.js → chunk-52OB2ROS.js} +4 -4
  18. package/dist/{chunk-JX3LZQJH.cjs → chunk-52PPNNI4.cjs} +82 -20
  19. package/dist/{chunk-5YOQOXEQ.cjs → chunk-5EC274J5.cjs} +676 -293
  20. package/dist/chunk-5QC7LRZ3.js +229 -0
  21. package/dist/{chunk-7TL2LHQJ.js → chunk-5VRJNBLZ.mjs} +524 -141
  22. package/dist/chunk-62AZW6UT.cjs +313 -0
  23. package/dist/chunk-6IXXWIUM.js +683 -0
  24. package/dist/chunk-6RY2FFN4.mjs +2024 -0
  25. package/dist/chunk-74ZTY6CP.js +2871 -0
  26. package/dist/chunk-7CMJS3QE.mjs +2871 -0
  27. package/dist/{chunk-2WC63LJK.mjs → chunk-7JIJOVCT.js} +20 -10
  28. package/dist/chunk-7X3K5RMS.js +2024 -0
  29. package/dist/chunk-7ZPEZ57L.cjs +2024 -0
  30. package/dist/{chunk-FM4W4QPL.js → chunk-A2OM6NEH.mjs} +5 -4
  31. package/dist/chunk-AGR5B2BC.cjs +683 -0
  32. package/dist/chunk-B33ICAKP.js +313 -0
  33. package/dist/{chunk-J3H54ZRV.mjs → chunk-B5JD23U7.mjs} +1 -1
  34. package/dist/{chunk-F5EUMJL7.mjs → chunk-BKK77SBA.js} +83 -5
  35. package/dist/{chunk-U5KWK3PX.mjs → chunk-C3MDXTRZ.js} +11 -0
  36. package/dist/{chunk-SPUEME2B.cjs → chunk-CZIVE6NT.cjs} +12 -1
  37. package/dist/{chunk-TDVMADDN.js → chunk-DNFJLJMW.mjs} +11 -0
  38. package/dist/{chunk-XDZOO4L5.js → chunk-EJ6BPYVR.mjs} +79 -17
  39. package/dist/chunk-EOC4UHBS.mjs +229 -0
  40. package/dist/chunk-F6XWZQY4.cjs +777 -0
  41. package/dist/{chunk-7LVI2GIN.js → chunk-FH2X7BVP.js} +507 -72
  42. package/dist/{chunk-OOGJ73B6.js → chunk-FHQGHPMO.mjs} +20 -10
  43. package/dist/{chunk-WQ5QNU5R.cjs → chunk-GLE2WY7Z.cjs} +652 -217
  44. package/dist/{chunk-G6IQOE4P.mjs → chunk-GYM3LLGS.mjs} +507 -72
  45. package/dist/{chunk-TVN5I4U6.cjs → chunk-JF5WGYJJ.cjs} +25 -24
  46. package/dist/{chunk-CY33PGEX.mjs → chunk-KH4SYAOS.mjs} +570 -51
  47. package/dist/chunk-KN32XNTH.mjs +313 -0
  48. package/dist/chunk-KQLYONSE.cjs +2871 -0
  49. package/dist/{chunk-7HUOJA4W.cjs → chunk-KZJQ723N.cjs} +90 -80
  50. package/dist/{chunk-CCKHV5BT.mjs → chunk-L2SYFEBS.js} +5 -4
  51. package/dist/{chunk-IJT6RRQ5.cjs → chunk-L6VB5N7Q.cjs} +20 -9
  52. package/dist/{chunk-ZGLD4TVZ.mjs → chunk-MBEJI5HF.mjs} +4 -4
  53. package/dist/{chunk-PRWCB3QL.mjs → chunk-MIIYDLGM.js} +524 -141
  54. package/dist/{chunk-H55LI6WY.js → chunk-MOO4L7F4.mjs} +15 -4
  55. package/dist/chunk-MVGUEJ5Z.cjs +370 -0
  56. package/dist/chunk-PD4EJTQC.cjs +229 -0
  57. package/dist/chunk-PWC3RBQE.mjs +300 -0
  58. package/dist/{chunk-MWXMNYJS.cjs → chunk-Q2I37RP3.cjs} +643 -124
  59. package/dist/{chunk-VFIUZG7J.mjs → chunk-RKGKFN2A.js} +79 -17
  60. package/dist/{chunk-NYL4D7SK.cjs → chunk-SA6HUJVI.cjs} +5 -5
  61. package/dist/chunk-SK7UZRNI.mjs +777 -0
  62. package/dist/{chunk-K2T3DV26.mjs → chunk-TRM4JUZQ.js} +15 -4
  63. package/dist/chunk-UB4B6OFY.js +370 -0
  64. package/dist/{chunk-G3XGCZDQ.js → chunk-UCUBNWM2.js} +1 -1
  65. package/dist/chunk-VWIPB6I5.js +777 -0
  66. package/dist/{chunk-JNFRRJYH.cjs → chunk-WBGRHGBP.cjs} +270 -192
  67. package/dist/{client-CtFmoDvM.d.ts → client-CZHU674n.d.ts} +211 -36
  68. package/dist/core/index.cjs +135 -9
  69. package/dist/core/index.d.ts +238 -33
  70. package/dist/core/index.js +155 -29
  71. package/dist/core/index.mjs +155 -29
  72. package/dist/{effect-CGNl5Rqp.d.ts → effect-DIUHZ9IN.d.ts} +89 -1
  73. package/dist/effectRunner-CFLC32IK.cjs +8 -0
  74. package/dist/{effectRunner-A4CHJXJI.js → effectRunner-L4S7IPT3.js} +2 -2
  75. package/dist/{effectRunner-OPUF6QRN.mjs → effectRunner-NNGG75QA.mjs} +2 -2
  76. package/dist/http/index.cjs +324 -2986
  77. package/dist/http/index.d.ts +54 -68
  78. package/dist/http/index.js +238 -2900
  79. package/dist/http/index.mjs +238 -2900
  80. package/dist/http/testing.cjs +14 -12
  81. package/dist/http/testing.d.ts +5 -4
  82. package/dist/http/testing.js +10 -8
  83. package/dist/http/testing.mjs +10 -8
  84. package/dist/index.cjs +423 -255
  85. package/dist/index.d.ts +87 -69
  86. package/dist/index.js +301 -133
  87. package/dist/index.mjs +301 -133
  88. package/dist/observability/index.cjs +18 -531
  89. package/dist/observability/index.d.ts +81 -8
  90. package/dist/observability/index.js +25 -538
  91. package/dist/observability/index.mjs +25 -538
  92. package/dist/perf/cli.cjs +401 -0
  93. package/dist/perf/cli.d.ts +1 -0
  94. package/dist/perf/cli.js +401 -0
  95. package/dist/perf/cli.mjs +401 -0
  96. package/dist/perf/index.cjs +141 -0
  97. package/dist/perf/index.d.ts +483 -0
  98. package/dist/perf/index.js +141 -0
  99. package/dist/perf/index.mjs +141 -0
  100. package/dist/schedule-CK3Ml_7p.d.ts +259 -0
  101. package/dist/schema/index.cjs +6 -2
  102. package/dist/schema/index.d.ts +3 -1
  103. package/dist/schema/index.js +5 -1
  104. package/dist/schema/index.mjs +5 -1
  105. package/dist/{server-C8hDXA74.d.ts → server-D6JZ15_e.d.ts} +16 -4
  106. package/dist/{stream-dvSs0QS5.d.ts → stream-B4oK9JFP.d.ts} +1 -1
  107. package/dist/{tracer-B5tRH9H7.d.ts → tracer-Hwt1cl7h.d.ts} +13 -54
  108. package/dist/{tracing-Dt9S_6V8.d.ts → tracing-DqbTKGcf.d.ts} +1 -1
  109. package/docs/ARCHITECTURE.md +292 -0
  110. package/docs/README.md +65 -0
  111. package/docs/adr/0001-ai-context-pack.md +32 -0
  112. package/docs/agent-apply-mode.md +104 -0
  113. package/docs/agent-approvals.md +110 -0
  114. package/docs/agent-batch.md +185 -0
  115. package/docs/agent-boundaries.md +112 -0
  116. package/docs/agent-chat-sessions.md +160 -0
  117. package/docs/agent-ci.md +17 -0
  118. package/docs/agent-cli.md +405 -0
  119. package/docs/agent-config.md +480 -0
  120. package/docs/agent-context-discovery.md +159 -0
  121. package/docs/agent-copilot-like-dx.md +126 -0
  122. package/docs/agent-declarative-optimized-planning.md +138 -0
  123. package/docs/agent-dx.md +224 -0
  124. package/docs/agent-env-files.md +126 -0
  125. package/docs/agent-follow-up-context.md +43 -0
  126. package/docs/agent-global-usage.md +180 -0
  127. package/docs/agent-init.md +109 -0
  128. package/docs/agent-install-and-configure.md +516 -0
  129. package/docs/agent-language-workspace-ux.md +99 -0
  130. package/docs/agent-llm-adapters.md +123 -0
  131. package/docs/agent-local-install.md +190 -0
  132. package/docs/agent-local-tests.md +51 -0
  133. package/docs/agent-observability.md +155 -0
  134. package/docs/agent-patch-quality-loop.md +162 -0
  135. package/docs/agent-presets.md +22 -0
  136. package/docs/agent-project-commands.md +237 -0
  137. package/docs/agent-project-intelligence.md +156 -0
  138. package/docs/agent-redaction.md +18 -0
  139. package/docs/agent-release-readiness.md +76 -0
  140. package/docs/agent-rollback-safety.md +162 -0
  141. package/docs/agent-rollback.md +23 -0
  142. package/docs/agent-run-artifacts.md +16 -0
  143. package/docs/agent-vscode-auto-discovery.md +137 -0
  144. package/docs/agent-vscode-batch-runner.md +100 -0
  145. package/docs/agent-vscode-chat-layout.md +90 -0
  146. package/docs/agent-vscode-clean-install.md +147 -0
  147. package/docs/agent-vscode-code-actions.md +70 -0
  148. package/docs/agent-vscode-diff-preview.md +45 -0
  149. package/docs/agent-vscode-inline-assist.md +56 -0
  150. package/docs/agent-vscode-install.md +186 -0
  151. package/docs/agent-vscode-model-setup.md +97 -0
  152. package/docs/agent-vscode-patch-preview.md +92 -0
  153. package/docs/agent-vscode-problems.md +79 -0
  154. package/docs/agent-vscode-project-dashboard.md +106 -0
  155. package/docs/agent-vscode-run-history.md +92 -0
  156. package/docs/agent-vscode-ux.md +73 -0
  157. package/docs/ai/INVARIANTS.md +84 -0
  158. package/docs/ai/PROJECT_MAP.md +338 -0
  159. package/docs/ai/PUBLIC_API.md +339 -0
  160. package/docs/ai/VALIDATION_MATRIX.md +67 -0
  161. package/docs/api-polish.md +37 -0
  162. package/docs/cancellation.md +162 -0
  163. package/docs/coverage.md +46 -0
  164. package/docs/framework-integrations.md +38 -0
  165. package/docs/frameworks/angular.md +153 -0
  166. package/docs/frameworks/express.md +125 -0
  167. package/docs/frameworks/fastify.md +124 -0
  168. package/docs/frameworks/nestjs.md +282 -0
  169. package/docs/frameworks/nextjs.md +147 -0
  170. package/docs/frameworks/react.md +139 -0
  171. package/docs/frameworks/vanilla.md +224 -0
  172. package/docs/getting-started.md +159 -0
  173. package/docs/guides/README.md +40 -0
  174. package/docs/guides/circuit-breaker.md +89 -0
  175. package/docs/guides/error-handling.md +91 -0
  176. package/docs/guides/getting-started.md +107 -0
  177. package/docs/guides/layers.md +189 -0
  178. package/docs/guides/metrics.md +101 -0
  179. package/docs/guides/resource-management.md +141 -0
  180. package/docs/guides/retry.md +215 -0
  181. package/docs/guides/semaphore.md +66 -0
  182. package/docs/guides/streams.md +117 -0
  183. package/docs/guides/supervisors.md +98 -0
  184. package/docs/guides/testing.md +162 -0
  185. package/docs/guides/tracing.md +71 -0
  186. package/docs/http-recipes.md +399 -0
  187. package/docs/http.md +749 -0
  188. package/docs/modules.md +285 -0
  189. package/docs/nestjs.md +6 -0
  190. package/docs/observability-collector-smoke.md +31 -0
  191. package/docs/observability-framework-examples.md +110 -0
  192. package/docs/observability.md +649 -0
  193. package/docs/otel-collector-smoke.yaml +27 -0
  194. package/docs/performance-profiler.md +199 -0
  195. package/docs/production-readiness.md +73 -0
  196. package/docs/recipes/README.md +12 -0
  197. package/docs/recipes/http-server.md +45 -0
  198. package/docs/recipes/layers.md +44 -0
  199. package/docs/recipes/performance.md +47 -0
  200. package/docs/recipes/runtime.md +41 -0
  201. package/docs/recipes/testing.md +41 -0
  202. package/docs/release.md +53 -0
  203. package/docs/wasm-bounded-queues.md +44 -0
  204. package/docs/wasm-engine-observability-benchmarks.md +85 -0
  205. package/docs/wasm-fiber-engine.md +117 -0
  206. package/docs/wasm-scheduler-state-machine.md +122 -0
  207. package/docs/wasm-stream-chunks.md +54 -0
  208. package/package.json +22 -2
  209. package/dist/chunk-45F7OKGT.cjs +0 -104
  210. package/dist/chunk-7V4KY4RL.mjs +0 -104
  211. package/dist/chunk-DJQ7OMMB.cjs +0 -144
  212. package/dist/chunk-GOV47PPB.mjs +0 -552
  213. package/dist/chunk-JF4XXPZ5.cjs +0 -552
  214. package/dist/chunk-KCPT2D6G.js +0 -552
  215. package/dist/chunk-NOYZIMUJ.mjs +0 -144
  216. package/dist/chunk-PNVFW245.js +0 -144
  217. package/dist/chunk-ROJC3NBJ.js +0 -104
  218. package/dist/effectRunner-3ZHAD3LE.cjs +0 -8
  219. package/dist/schedule-Fque9Abz.d.ts +0 -70
package/dist/index.js CHANGED
@@ -1,30 +1,46 @@
1
1
  import {
2
+ Layer,
3
+ LayerContext,
2
4
  LinkedQueue,
5
+ MissingLayerServiceError,
3
6
  RuntimeRegistry,
4
7
  Supervisor,
8
+ TestClock,
9
+ TestScheduler,
5
10
  assertCompletesWithin,
6
11
  assertFails,
7
12
  assertFailsWith,
8
13
  assertSucceeds,
14
+ buildLayer,
9
15
  catchTag,
10
16
  catchTags,
11
17
  compose,
12
18
  consoleJsonLogger,
13
19
  defaultTracer,
20
+ defineLayer,
21
+ defineService,
14
22
  delayedEffect,
15
23
  derivedRef,
16
24
  dumpAllFibers,
17
25
  flakyEffect,
26
+ formatLayerError,
27
+ getService,
18
28
  gracefulShutdown,
19
29
  joinSupervised,
20
30
  layer,
31
+ layerEffect,
21
32
  layerFail,
22
33
  layerFrom,
34
+ layerFromContext,
23
35
  layerSucceed,
36
+ layerValue,
24
37
  linkAbortController,
25
38
  makeCancelToken,
39
+ makeLayerScope,
26
40
  makeRef,
41
+ makeRuntime,
27
42
  makeSemaphore,
43
+ makeServiceTag,
28
44
  makeSupervisor,
29
45
  makeTestRuntime,
30
46
  makeTracer,
@@ -34,44 +50,46 @@ import {
34
50
  merge,
35
51
  neverEffect,
36
52
  orElse,
53
+ provide,
54
+ provideContext,
37
55
  provideLayer,
56
+ provideLayerContext,
38
57
  registerShutdownHooks,
58
+ runEffect,
59
+ runExit,
60
+ runPromise,
61
+ serviceTag,
39
62
  supervise,
40
63
  tagError
41
- } from "./chunk-QY5FKYEQ.js";
64
+ } from "./chunk-3AYM6WPJ.js";
42
65
  import {
43
66
  Resource,
44
- andThen,
45
67
  bracket,
46
- contramap,
47
- elapsed,
48
68
  ensuring,
49
- exponential,
50
- fibonacci,
51
- fixed,
52
- intersect,
53
- jitter,
54
- jittered,
55
- jitteredSchedule,
56
69
  makeCircuitBreaker,
57
70
  makeResource,
58
71
  managed,
59
72
  managedAll,
60
- map as map2,
61
- recurs,
62
- repeatWithSchedule,
63
73
  resource,
64
74
  resourceAll,
65
75
  resourceFromManaged,
66
76
  resourceSucceed,
67
- retryWithSchedule,
68
- take,
69
- union,
70
77
  useManaged,
71
- useResource,
72
- whileInput,
73
- windowed
74
- } from "./chunk-KCPT2D6G.js";
78
+ useResource
79
+ } from "./chunk-B33ICAKP.js";
80
+ import {
81
+ fiberRefSnapshot,
82
+ getFiberRef,
83
+ locallyFiberRef,
84
+ locallyFiberRefWith,
85
+ makeFiberRef,
86
+ makeRuntimeRecorder,
87
+ modifyFiberRef,
88
+ setFiberRef,
89
+ unsafeGetFiberRef,
90
+ unsafeSetFiberRef,
91
+ updateFiberRef
92
+ } from "./chunk-5QC7LRZ3.js";
75
93
  import {
76
94
  assertNever,
77
95
  collectStream,
@@ -92,14 +110,63 @@ import {
92
110
  unwrapScoped,
93
111
  widenOpt,
94
112
  zip
95
- } from "./chunk-OOGJ73B6.js";
113
+ } from "./chunk-7JIJOVCT.js";
114
+ import {
115
+ collectAllPar,
116
+ race,
117
+ raceWith,
118
+ zipPar
119
+ } from "./chunk-UCUBNWM2.js";
96
120
  import {
121
+ Schedule,
122
+ andThen,
123
+ contramap,
124
+ elapsed,
125
+ exponential,
126
+ fibonacci,
127
+ fixed,
128
+ forever,
129
+ intersect,
130
+ jitter,
131
+ jittered,
132
+ jitteredSchedule,
133
+ linear,
134
+ makeScheduleDriver,
135
+ map as map2,
136
+ maxDelay,
137
+ maxElapsed,
138
+ named,
139
+ never,
140
+ once,
141
+ poll,
142
+ recurs,
143
+ repeat,
144
+ repeatWithSchedule,
97
145
  retry,
146
+ retry2,
98
147
  retryN,
99
148
  retryWithBackoff,
149
+ retryWithSchedule,
150
+ runSchedule,
151
+ scheduleDriver,
100
152
  sleep,
101
- timeout
102
- } from "./chunk-ROJC3NBJ.js";
153
+ spaced,
154
+ take,
155
+ tapDecision,
156
+ timeout,
157
+ union,
158
+ untilInput,
159
+ untilOutput,
160
+ upTo,
161
+ whileInput,
162
+ whileOutput,
163
+ windowed
164
+ } from "./chunk-6IXXWIUM.js";
165
+ import {
166
+ Scope,
167
+ withScope,
168
+ withScopeAsync
169
+ } from "./chunk-L2SYFEBS.js";
103
170
  import {
104
171
  EventBus,
105
172
  InMemoryTracer,
@@ -107,18 +174,7 @@ import {
107
174
  makeRuntimeEventRecord,
108
175
  runtimeEventRecordContext,
109
176
  runtimeHooksToEventHandler
110
- } from "./chunk-XDZOO4L5.js";
111
- import {
112
- collectAllPar,
113
- race,
114
- raceWith,
115
- zipPar
116
- } from "./chunk-G3XGCZDQ.js";
117
- import {
118
- Scope,
119
- withScope,
120
- withScopeAsync
121
- } from "./chunk-FM4W4QPL.js";
177
+ } from "./chunk-RKGKFN2A.js";
122
178
  import {
123
179
  ABI_VERSION,
124
180
  DefaultHostExecutor,
@@ -154,11 +210,13 @@ import {
154
210
  globalScheduler,
155
211
  inferCallerLaneFromStack,
156
212
  laneTag,
213
+ liveClock,
157
214
  makeBoundedRingBuffer,
158
215
  makeFiberReadyQueue,
159
216
  resetAbortablePromiseStats,
160
217
  resolveWasmModule,
161
218
  runtimeCapabilities,
219
+ runtimeClockFromEnv,
162
220
  runtimeForCaller,
163
221
  sanitizeLaneKey,
164
222
  setBenchmarkBudget,
@@ -168,7 +226,7 @@ import {
168
226
  unsafeRunAsync,
169
227
  unsafeRunFoldWithEnv,
170
228
  withCurrentFiber
171
- } from "./chunk-7LVI2GIN.js";
229
+ } from "./chunk-FH2X7BVP.js";
172
230
  import {
173
231
  Async,
174
232
  Cause,
@@ -189,19 +247,25 @@ import {
189
247
  end,
190
248
  fail,
191
249
  flatMap,
250
+ formatCause,
251
+ interruptible,
252
+ isCause,
192
253
  map,
193
254
  mapAsync,
194
255
  mapError,
195
256
  mapTryAsync,
196
257
  none,
197
258
  orElseOptional,
259
+ prettyCause,
198
260
  some,
199
261
  succeed,
200
262
  sync,
263
+ uninterruptible,
264
+ uninterruptibleMask,
201
265
  unit,
202
266
  withAsyncPromise
203
- } from "./chunk-PNVFW245.js";
204
- import "./chunk-TDVMADDN.js";
267
+ } from "./chunk-UB4B6OFY.js";
268
+ import "./chunk-C3MDXTRZ.js";
205
269
  import "./chunk-3RG5ZIWI.js";
206
270
 
207
271
  // src/core/stream/queue.ts
@@ -425,100 +489,6 @@ function buffer(stream, capacity, strategy = "backpressure") {
425
489
  return fromPull(pullDown);
426
490
  }
427
491
 
428
- // src/core/stream/hub.ts
429
- var toQueueStrategy = (s) => s === "BackPressure" ? "backpressure" : s === "Dropping" ? "dropping" : "sliding";
430
- function makeHub(capacity, strategy = "BackPressure") {
431
- const queues = /* @__PURE__ */ new Set();
432
- let closed = false;
433
- const publish = (a) => {
434
- if (closed) return asyncSucceed(false);
435
- const size = queues.size;
436
- if (size === 0) return asyncSucceed(true);
437
- if (size === 1) {
438
- const q = queues.values().next().value;
439
- return q.offer(a);
440
- }
441
- let eff = asyncSucceed(true);
442
- for (const q of queues) {
443
- eff = asyncFlatMap(
444
- eff,
445
- (okSoFar) => asyncFlatMap(q.offer(a), (ok) => asyncSucceed(okSoFar && ok))
446
- );
447
- }
448
- return eff;
449
- };
450
- const publishAll = (as) => {
451
- let eff = asyncSucceed(true);
452
- const it = as[Symbol.iterator]();
453
- while (true) {
454
- const n = it.next();
455
- if (n.done) break;
456
- const a = n.value;
457
- eff = asyncFlatMap(
458
- eff,
459
- (okSoFar) => asyncFlatMap(publish(a), (ok) => asyncSucceed(okSoFar && ok))
460
- );
461
- }
462
- return eff;
463
- };
464
- const subscribe = () => {
465
- if (closed) {
466
- return asyncTotal(() => {
467
- throw { _tag: "HubClosed" };
468
- });
469
- }
470
- return asyncFlatMap(
471
- bounded(capacity, toQueueStrategy(strategy)),
472
- (q) => asyncSync(() => {
473
- queues.add(q);
474
- return {
475
- ...q,
476
- unsubscribe: () => {
477
- if (!queues.has(q)) return;
478
- queues.delete(q);
479
- q.shutdown();
480
- }
481
- };
482
- })
483
- );
484
- };
485
- const shutdown = () => asyncSync(() => {
486
- if (closed) return;
487
- closed = true;
488
- for (const q of queues) q.shutdown();
489
- queues.clear();
490
- });
491
- return {
492
- publish,
493
- publishAll,
494
- subscribe,
495
- shutdown
496
- };
497
- }
498
- var broadcast = makeHub;
499
- function broadcastToHub(stream, hub) {
500
- return foreachStream(
501
- stream,
502
- (a) => asyncFlatMap(hub.publish(a), () => asyncSucceed(void 0))
503
- );
504
- }
505
- function fromHub(hub) {
506
- return managedStream(
507
- asyncFlatMap(hub.subscribe(), (sub) => {
508
- const loop = fromPull(
509
- asyncFlatMap(
510
- asyncMapError(sub.take(), (_queueClosed) => none),
511
- (a) => asyncSucceed([a, loop])
512
- )
513
- );
514
- return asyncSucceed({
515
- stream: loop,
516
- release: (_exit) => asyncSync(() => sub.unsubscribe())
517
- });
518
- })
519
- );
520
- }
521
-
522
492
  // src/core/stream/chunks.ts
523
493
  var cachedWasmChunkCtor;
524
494
  function resolveWasmChunkBuffer() {
@@ -1242,6 +1212,139 @@ function groupedP(n) {
1242
1212
  });
1243
1213
  }
1244
1214
 
1215
+ // src/core/stream/dx.ts
1216
+ var Stream = Object.freeze({
1217
+ from: (values) => asStream(fromArray(values)),
1218
+ empty: () => asStream(emptyStream()),
1219
+ range: (start, end2) => asStream(rangeStream(start, end2)),
1220
+ wrap: asStream
1221
+ });
1222
+ var Pipeline = Object.freeze({
1223
+ map: mapP,
1224
+ filter: filterP
1225
+ });
1226
+ function asStream(stream) {
1227
+ const target = stream;
1228
+ if (typeof target.pipe === "function") return target;
1229
+ Object.defineProperties(target, {
1230
+ pipe: {
1231
+ value(pipeline) {
1232
+ return asStream(via(target, pipeline));
1233
+ }
1234
+ },
1235
+ map: {
1236
+ value(f) {
1237
+ return asStream(via(target, mapP(f)));
1238
+ }
1239
+ },
1240
+ filter: {
1241
+ value(predicate) {
1242
+ return asStream(via(target, filterP(predicate)));
1243
+ }
1244
+ },
1245
+ collect: {
1246
+ value(runtime) {
1247
+ return runtime.toPromise(collectStream(target));
1248
+ }
1249
+ }
1250
+ });
1251
+ return target;
1252
+ }
1253
+
1254
+ // src/core/stream/hub.ts
1255
+ var toQueueStrategy = (s) => s === "BackPressure" ? "backpressure" : s === "Dropping" ? "dropping" : "sliding";
1256
+ function makeHub(capacity, strategy = "BackPressure") {
1257
+ const queues = /* @__PURE__ */ new Set();
1258
+ let closed = false;
1259
+ const publish = (a) => {
1260
+ if (closed) return asyncSucceed(false);
1261
+ const size = queues.size;
1262
+ if (size === 0) return asyncSucceed(true);
1263
+ if (size === 1) {
1264
+ const q = queues.values().next().value;
1265
+ return q.offer(a);
1266
+ }
1267
+ let eff = asyncSucceed(true);
1268
+ for (const q of queues) {
1269
+ eff = asyncFlatMap(
1270
+ eff,
1271
+ (okSoFar) => asyncFlatMap(q.offer(a), (ok) => asyncSucceed(okSoFar && ok))
1272
+ );
1273
+ }
1274
+ return eff;
1275
+ };
1276
+ const publishAll = (as) => {
1277
+ let eff = asyncSucceed(true);
1278
+ const it = as[Symbol.iterator]();
1279
+ while (true) {
1280
+ const n = it.next();
1281
+ if (n.done) break;
1282
+ const a = n.value;
1283
+ eff = asyncFlatMap(
1284
+ eff,
1285
+ (okSoFar) => asyncFlatMap(publish(a), (ok) => asyncSucceed(okSoFar && ok))
1286
+ );
1287
+ }
1288
+ return eff;
1289
+ };
1290
+ const subscribe = () => {
1291
+ if (closed) {
1292
+ return asyncTotal(() => {
1293
+ throw { _tag: "HubClosed" };
1294
+ });
1295
+ }
1296
+ return asyncFlatMap(
1297
+ bounded(capacity, toQueueStrategy(strategy)),
1298
+ (q) => asyncSync(() => {
1299
+ queues.add(q);
1300
+ return {
1301
+ ...q,
1302
+ unsubscribe: () => {
1303
+ if (!queues.has(q)) return;
1304
+ queues.delete(q);
1305
+ q.shutdown();
1306
+ }
1307
+ };
1308
+ })
1309
+ );
1310
+ };
1311
+ const shutdown = () => asyncSync(() => {
1312
+ if (closed) return;
1313
+ closed = true;
1314
+ for (const q of queues) q.shutdown();
1315
+ queues.clear();
1316
+ });
1317
+ return {
1318
+ publish,
1319
+ publishAll,
1320
+ subscribe,
1321
+ shutdown
1322
+ };
1323
+ }
1324
+ var broadcast = makeHub;
1325
+ function broadcastToHub(stream, hub) {
1326
+ return foreachStream(
1327
+ stream,
1328
+ (a) => asyncFlatMap(hub.publish(a), () => asyncSucceed(void 0))
1329
+ );
1330
+ }
1331
+ function fromHub(hub) {
1332
+ return managedStream(
1333
+ asyncFlatMap(hub.subscribe(), (sub) => {
1334
+ const loop = fromPull(
1335
+ asyncFlatMap(
1336
+ asyncMapError(sub.take(), (_queueClosed) => none),
1337
+ (a) => asyncSucceed([a, loop])
1338
+ )
1339
+ );
1340
+ return asyncSucceed({
1341
+ stream: loop,
1342
+ release: (_exit) => asyncSync(() => sub.unsubscribe())
1343
+ });
1344
+ })
1345
+ );
1346
+ }
1347
+
1245
1348
  // src/core/stream/operators.ts
1246
1349
  function throttle(stream, intervalMs) {
1247
1350
  let lastEmitTime = 0;
@@ -1419,10 +1522,14 @@ export {
1419
1522
  HostRegistry,
1420
1523
  InMemoryTracer,
1421
1524
  JsFiberEngine,
1525
+ Layer,
1526
+ LayerContext,
1527
+ MissingLayerServiceError,
1422
1528
  NONE_U32,
1423
1529
  NoopHooks,
1424
1530
  OpcodeTagCode,
1425
1531
  PURE_PIPELINE_TAG,
1532
+ Pipeline,
1426
1533
  ProgramBuilder,
1427
1534
  PushStatus,
1428
1535
  Resource,
@@ -1430,9 +1537,13 @@ export {
1430
1537
  Runtime,
1431
1538
  RuntimeFiber,
1432
1539
  RuntimeRegistry,
1540
+ Schedule,
1433
1541
  Scheduler,
1434
1542
  Scope,
1543
+ Stream,
1435
1544
  Supervisor,
1545
+ TestClock,
1546
+ TestScheduler,
1436
1547
  WasmFiberEngine,
1437
1548
  WasmFiberRegistryBridge,
1438
1549
  WasmPackFiberBridge,
@@ -1441,6 +1552,7 @@ export {
1441
1552
  andThen2 as andThen,
1442
1553
  andThen as andThenSchedule,
1443
1554
  applyFused,
1555
+ asStream,
1444
1556
  assertCompletesWithin,
1445
1557
  assertFails,
1446
1558
  assertFailsWith,
@@ -1463,6 +1575,7 @@ export {
1463
1575
  broadcastToHub,
1464
1576
  buffer,
1465
1577
  bufferP,
1578
+ buildLayer,
1466
1579
  catchAll,
1467
1580
  catchTag,
1468
1581
  catchTags,
@@ -1481,6 +1594,8 @@ export {
1481
1594
  decodeEvent,
1482
1595
  decodeEventBatch,
1483
1596
  defaultTracer,
1597
+ defineLayer,
1598
+ defineService,
1484
1599
  delayedEffect,
1485
1600
  derivedRef,
1486
1601
  deserializeFusedPipeline,
@@ -1498,6 +1613,7 @@ export {
1498
1613
  ensuring,
1499
1614
  exponential,
1500
1615
  fail,
1616
+ fiberRefSnapshot,
1501
1617
  fibonacci,
1502
1618
  filterMapP,
1503
1619
  filterP,
@@ -1506,7 +1622,10 @@ export {
1506
1622
  flatMap,
1507
1623
  flattenStream,
1508
1624
  foreachStream,
1625
+ forever,
1509
1626
  fork,
1627
+ formatCause,
1628
+ formatLayerError,
1510
1629
  fromArray,
1511
1630
  fromHub,
1512
1631
  fromPromiseAbortable,
@@ -1514,6 +1633,8 @@ export {
1514
1633
  fuse,
1515
1634
  getBenchmarkBudget,
1516
1635
  getCurrentFiber,
1636
+ getFiberRef,
1637
+ getService,
1517
1638
  getStats,
1518
1639
  globalScheduler,
1519
1640
  gracefulShutdown,
@@ -1522,7 +1643,9 @@ export {
1522
1643
  inferCallerLaneFromStack,
1523
1644
  initState,
1524
1645
  interleave,
1646
+ interruptible,
1525
1647
  intersect,
1648
+ isCause,
1526
1649
  isFusionEnabled,
1527
1650
  isFusionVerbose,
1528
1651
  jitter,
@@ -1531,20 +1654,33 @@ export {
1531
1654
  joinSupervised,
1532
1655
  laneTag,
1533
1656
  layer,
1657
+ layerEffect,
1534
1658
  layerFail,
1535
1659
  layerFrom,
1660
+ layerFromContext,
1536
1661
  layerSucceed,
1662
+ layerValue,
1663
+ linear,
1537
1664
  linkAbortController,
1665
+ liveClock,
1666
+ locallyFiberRef,
1667
+ locallyFiberRefWith,
1538
1668
  makeBoundedRingBuffer,
1539
1669
  makeCancelToken,
1540
1670
  makeCircuitBreaker,
1541
1671
  makeFiberReadyQueue,
1672
+ makeFiberRef,
1542
1673
  makeHub,
1674
+ makeLayerScope,
1543
1675
  makeMetrics,
1544
1676
  makeRef,
1545
1677
  makeResource,
1678
+ makeRuntime,
1546
1679
  makeRuntimeEventRecord,
1680
+ makeRuntimeRecorder,
1681
+ makeScheduleDriver,
1547
1682
  makeSemaphore,
1683
+ makeServiceTag,
1548
1684
  makeStreamChunker,
1549
1685
  makeSupervisor,
1550
1686
  makeTestRuntime,
@@ -1566,20 +1702,32 @@ export {
1566
1702
  map2 as mapSchedule,
1567
1703
  mapStream,
1568
1704
  mapTryAsync,
1705
+ maxDelay,
1706
+ maxElapsed,
1569
1707
  merge2 as merge,
1570
1708
  merge as mergeLayer,
1571
1709
  mergeStream,
1710
+ modifyFiberRef,
1711
+ named as namedSchedule,
1712
+ never,
1572
1713
  neverEffect,
1573
1714
  none,
1715
+ once,
1574
1716
  orElse,
1575
1717
  orElseOptional,
1718
+ poll as pollWithSchedule,
1719
+ prettyCause,
1720
+ provide,
1721
+ provideContext,
1576
1722
  provideLayer,
1723
+ provideLayerContext,
1577
1724
  race,
1578
1725
  raceWith,
1579
1726
  rangeStream,
1580
1727
  recurs,
1581
1728
  registerShutdownHooks,
1582
1729
  repeatWithSchedule,
1730
+ repeat as repeatWithScheduleAlias,
1583
1731
  resetAbortablePromiseStats,
1584
1732
  resource,
1585
1733
  resourceAll,
@@ -1589,20 +1737,30 @@ export {
1589
1737
  retryN,
1590
1738
  retryWithBackoff,
1591
1739
  retryWithSchedule,
1740
+ retry2 as retryWithScheduleAlias,
1741
+ runEffect,
1742
+ runExit,
1592
1743
  runFusedArray,
1744
+ runPromise,
1745
+ runSchedule,
1593
1746
  runtimeCapabilities,
1747
+ runtimeClockFromEnv,
1594
1748
  runtimeEventRecordContext,
1595
1749
  runtimeForCaller,
1596
1750
  runtimeHooksToEventHandler,
1597
1751
  sanitizeLaneKey,
1598
1752
  scan,
1753
+ scheduleDriver,
1599
1754
  selectedEngineStats,
1600
1755
  serializeFusedPipeline,
1756
+ serviceTag,
1601
1757
  setBenchmarkBudget,
1758
+ setFiberRef,
1602
1759
  setFusionEnabled,
1603
1760
  setFusionVerbose,
1604
1761
  sleep,
1605
1762
  some,
1763
+ spaced,
1606
1764
  streamFromReadableStream,
1607
1765
  succeed,
1608
1766
  supervise,
@@ -1611,22 +1769,32 @@ export {
1611
1769
  takeP,
1612
1770
  take as takeSchedule,
1613
1771
  take2 as takeStream,
1772
+ tapDecision,
1614
1773
  tapEffectP,
1615
1774
  throttle,
1616
1775
  timeout,
1617
1776
  toPromise,
1618
1777
  toPromiseByCaller,
1619
1778
  uncons,
1779
+ uninterruptible,
1780
+ uninterruptibleMask,
1620
1781
  union,
1621
1782
  unit,
1622
1783
  unsafeGetCurrentRuntime,
1784
+ unsafeGetFiberRef,
1623
1785
  unsafeRunAsync,
1624
1786
  unsafeRunFoldWithEnv,
1787
+ unsafeSetFiberRef,
1788
+ untilInput,
1789
+ untilOutput,
1625
1790
  unwrapScoped,
1791
+ upTo,
1792
+ updateFiberRef,
1626
1793
  useManaged,
1627
1794
  useResource,
1628
1795
  via,
1629
1796
  whileInput,
1797
+ whileOutput,
1630
1798
  widenOpt,
1631
1799
  windowed,
1632
1800
  withAsyncPromise,