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,159 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunk5YOQOXEQcjs = require('../chunk-5YOQOXEQ.cjs');
4
+ require('../chunk-7HUOJA4W.cjs');
5
+ require('../chunk-45F7OKGT.cjs');
6
+ require('../chunk-NYL4D7SK.cjs');
7
+ require('../chunk-TVN5I4U6.cjs');
8
+
9
+
10
+ var _chunkWQ5QNU5Rcjs = require('../chunk-WQ5QNU5R.cjs');
11
+
12
+
13
+
14
+ var _chunkDJQ7OMMBcjs = require('../chunk-DJQ7OMMB.cjs');
15
+ require('../chunk-SPUEME2B.cjs');
16
+ require('../chunk-OBGZSXTJ.cjs');
17
+
18
+ // src/http/testing.ts
19
+ function makeHttpResponse(bodyText = "", init = {}) {
20
+ return {
21
+ status: _nullishCoalesce(init.status, () => ( 200)),
22
+ statusText: _nullishCoalesce(init.statusText, () => ( "OK")),
23
+ headers: _nullishCoalesce(init.headers, () => ( {})),
24
+ bodyText,
25
+ ms: _nullishCoalesce(init.ms, () => ( 0))
26
+ };
27
+ }
28
+ function makeTextHttpResponse(bodyText, init = {}) {
29
+ return makeHttpResponse(bodyText, init);
30
+ }
31
+ function makeJsonHttpResponse(body, init = {}) {
32
+ return makeHttpResponse(JSON.stringify(body), {
33
+ ...init,
34
+ headers: {
35
+ "content-type": "application/json",
36
+ ..._nullishCoalesce(init.headers, () => ( {}))
37
+ }
38
+ });
39
+ }
40
+ function makeMockHttpClient(handler = () => makeHttpResponse()) {
41
+ const calls = [];
42
+ const stats = {
43
+ inFlight: 0,
44
+ started: 0,
45
+ succeeded: 0,
46
+ failed: 0,
47
+ aborted: 0,
48
+ timedOut: 0,
49
+ poolRejected: 0,
50
+ poolTimeouts: 0
51
+ };
52
+ const run = (req) => {
53
+ calls.push(req);
54
+ stats.started++;
55
+ try {
56
+ const result = handler(req, calls.length - 1);
57
+ if (isAsync(result)) return result;
58
+ stats.succeeded++;
59
+ return _chunkDJQ7OMMBcjs.asyncSucceed.call(void 0, result);
60
+ } catch (error) {
61
+ stats.failed++;
62
+ return _chunkDJQ7OMMBcjs.asyncFail.call(void 0, toHttpError(error));
63
+ }
64
+ };
65
+ return Object.assign(_chunk5YOQOXEQcjs.decorate.call(void 0, run, () => ({ ...stats })), {
66
+ calls: () => [...calls],
67
+ calledTimes: () => calls.length,
68
+ lastRequest: () => calls.at(-1),
69
+ reset: () => {
70
+ calls.length = 0;
71
+ stats.inFlight = 0;
72
+ stats.started = 0;
73
+ stats.succeeded = 0;
74
+ stats.failed = 0;
75
+ stats.aborted = 0;
76
+ stats.timedOut = 0;
77
+ stats.poolRejected = 0;
78
+ stats.poolTimeouts = 0;
79
+ delete stats.lastDurationMs;
80
+ }
81
+ });
82
+ }
83
+ function makeSequenceHttpClient(responses, fallback = makeHttpResponse()) {
84
+ return makeMockHttpClient((_req, index) => _nullishCoalesce(responses[index], () => ( fallback)));
85
+ }
86
+ function runHttpEffect(effect, env = {}) {
87
+ return _chunkWQ5QNU5Rcjs.toPromise.call(void 0, effect, env);
88
+ }
89
+ function makeFetchResponse(body = null, init = {}) {
90
+ assertResponseAvailable();
91
+ return new Response(body, init);
92
+ }
93
+ function makeJsonFetchResponse(body, init = {}) {
94
+ assertResponseAvailable();
95
+ return new Response(JSON.stringify(body), {
96
+ ...init,
97
+ headers: {
98
+ "content-type": "application/json",
99
+ ...init.headers
100
+ }
101
+ });
102
+ }
103
+ function installMockFetch(handler) {
104
+ const target = globalThis;
105
+ const original = target.fetch;
106
+ const calls = [];
107
+ const mockFetch = (async (input, init) => {
108
+ calls.push({ input, init });
109
+ return handler(input, init, calls.length - 1);
110
+ });
111
+ target.fetch = mockFetch;
112
+ return {
113
+ fetch: mockFetch,
114
+ calls: () => [...calls],
115
+ calledTimes: () => calls.length,
116
+ lastCall: () => calls.at(-1),
117
+ restore: () => {
118
+ if (original) target.fetch = original;
119
+ else Reflect.deleteProperty(target, "fetch");
120
+ }
121
+ };
122
+ }
123
+ async function withMockFetch(handler, run) {
124
+ const mock = installMockFetch(handler);
125
+ try {
126
+ return await run(mock);
127
+ } finally {
128
+ mock.restore();
129
+ }
130
+ }
131
+ function isAsync(value) {
132
+ return typeof value === "object" && value !== null && "_tag" in value;
133
+ }
134
+ function toHttpError(error) {
135
+ if (isHttpError(error)) return error;
136
+ return { _tag: "FetchError", message: error instanceof Error ? error.message : String(error) };
137
+ }
138
+ function isHttpError(error) {
139
+ if (typeof error !== "object" || error === null || !("_tag" in error)) return false;
140
+ const tag = error._tag;
141
+ return tag === "Abort" || tag === "BadUrl" || tag === "FetchError" || tag === "Timeout" || tag === "PoolRejected" || tag === "PoolTimeout" || tag === "PoolClosed" || tag === "BatchSplitError";
142
+ }
143
+ function assertResponseAvailable() {
144
+ if (typeof Response === "undefined") {
145
+ throw new Error("HTTP test helpers require global Response for fetch response mocks.");
146
+ }
147
+ }
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+ exports.installMockFetch = installMockFetch; exports.makeFetchResponse = makeFetchResponse; exports.makeHttpResponse = makeHttpResponse; exports.makeJsonFetchResponse = makeJsonFetchResponse; exports.makeJsonHttpResponse = makeJsonHttpResponse; exports.makeMockHttpClient = makeMockHttpClient; exports.makeSequenceHttpClient = makeSequenceHttpClient; exports.makeTextHttpResponse = makeTextHttpResponse; exports.runHttpEffect = runHttpEffect; exports.withMockFetch = withMockFetch;
@@ -0,0 +1,42 @@
1
+ import { A as Async } from '../effect-CGNl5Rqp.js';
2
+ import { H as HttpClient, a as HttpRequest, b as HttpWireResponse, c as HttpError } from '../client-CtFmoDvM.js';
3
+ import '../stream-dvSs0QS5.js';
4
+ import '../schedule-Fque9Abz.js';
5
+
6
+ type HttpTestResponseInit = {
7
+ readonly status?: number;
8
+ readonly statusText?: string;
9
+ readonly headers?: Record<string, string>;
10
+ readonly ms?: number;
11
+ };
12
+ type MockHttpHandler = (req: HttpRequest, index: number) => HttpWireResponse | Async<unknown, HttpError, HttpWireResponse>;
13
+ type MockHttpClient = HttpClient & {
14
+ readonly calls: () => readonly HttpRequest[];
15
+ readonly calledTimes: () => number;
16
+ readonly lastRequest: () => HttpRequest | undefined;
17
+ readonly reset: () => void;
18
+ };
19
+ type MockFetchCall = {
20
+ readonly input: RequestInfo | URL;
21
+ readonly init?: RequestInit;
22
+ };
23
+ type MockFetchHandler = (input: RequestInfo | URL, init: RequestInit | undefined, index: number) => Response | Promise<Response>;
24
+ type MockFetchController = {
25
+ readonly fetch: typeof fetch;
26
+ readonly calls: () => readonly MockFetchCall[];
27
+ readonly calledTimes: () => number;
28
+ readonly lastCall: () => MockFetchCall | undefined;
29
+ readonly restore: () => void;
30
+ };
31
+ declare function makeHttpResponse(bodyText?: string, init?: HttpTestResponseInit): HttpWireResponse;
32
+ declare function makeTextHttpResponse(bodyText: string, init?: HttpTestResponseInit): HttpWireResponse;
33
+ declare function makeJsonHttpResponse(body: unknown, init?: HttpTestResponseInit): HttpWireResponse;
34
+ declare function makeMockHttpClient(handler?: MockHttpHandler): MockHttpClient;
35
+ declare function makeSequenceHttpClient(responses: readonly HttpWireResponse[], fallback?: HttpWireResponse): MockHttpClient;
36
+ declare function runHttpEffect<E, A>(effect: Async<unknown, E, A>, env?: unknown): Promise<A>;
37
+ declare function makeFetchResponse(body?: BodyInit | null, init?: ResponseInit): Response;
38
+ declare function makeJsonFetchResponse(body: unknown, init?: ResponseInit): Response;
39
+ declare function installMockFetch(handler: MockFetchHandler): MockFetchController;
40
+ declare function withMockFetch<A>(handler: MockFetchHandler, run: (mock: MockFetchController) => Promise<A> | A): Promise<A>;
41
+
42
+ export { type HttpTestResponseInit, type MockFetchCall, type MockFetchController, type MockFetchHandler, type MockHttpClient, type MockHttpHandler, installMockFetch, makeFetchResponse, makeHttpResponse, makeJsonFetchResponse, makeJsonHttpResponse, makeMockHttpClient, makeSequenceHttpClient, makeTextHttpResponse, runHttpEffect, withMockFetch };
@@ -0,0 +1,159 @@
1
+ import {
2
+ decorate
3
+ } from "../chunk-7TL2LHQJ.js";
4
+ import "../chunk-OOGJ73B6.js";
5
+ import "../chunk-ROJC3NBJ.js";
6
+ import "../chunk-G3XGCZDQ.js";
7
+ import "../chunk-FM4W4QPL.js";
8
+ import {
9
+ toPromise
10
+ } from "../chunk-7LVI2GIN.js";
11
+ import {
12
+ asyncFail,
13
+ asyncSucceed
14
+ } from "../chunk-PNVFW245.js";
15
+ import "../chunk-TDVMADDN.js";
16
+ import "../chunk-3RG5ZIWI.js";
17
+
18
+ // src/http/testing.ts
19
+ function makeHttpResponse(bodyText = "", init = {}) {
20
+ return {
21
+ status: init.status ?? 200,
22
+ statusText: init.statusText ?? "OK",
23
+ headers: init.headers ?? {},
24
+ bodyText,
25
+ ms: init.ms ?? 0
26
+ };
27
+ }
28
+ function makeTextHttpResponse(bodyText, init = {}) {
29
+ return makeHttpResponse(bodyText, init);
30
+ }
31
+ function makeJsonHttpResponse(body, init = {}) {
32
+ return makeHttpResponse(JSON.stringify(body), {
33
+ ...init,
34
+ headers: {
35
+ "content-type": "application/json",
36
+ ...init.headers ?? {}
37
+ }
38
+ });
39
+ }
40
+ function makeMockHttpClient(handler = () => makeHttpResponse()) {
41
+ const calls = [];
42
+ const stats = {
43
+ inFlight: 0,
44
+ started: 0,
45
+ succeeded: 0,
46
+ failed: 0,
47
+ aborted: 0,
48
+ timedOut: 0,
49
+ poolRejected: 0,
50
+ poolTimeouts: 0
51
+ };
52
+ const run = (req) => {
53
+ calls.push(req);
54
+ stats.started++;
55
+ try {
56
+ const result = handler(req, calls.length - 1);
57
+ if (isAsync(result)) return result;
58
+ stats.succeeded++;
59
+ return asyncSucceed(result);
60
+ } catch (error) {
61
+ stats.failed++;
62
+ return asyncFail(toHttpError(error));
63
+ }
64
+ };
65
+ return Object.assign(decorate(run, () => ({ ...stats })), {
66
+ calls: () => [...calls],
67
+ calledTimes: () => calls.length,
68
+ lastRequest: () => calls.at(-1),
69
+ reset: () => {
70
+ calls.length = 0;
71
+ stats.inFlight = 0;
72
+ stats.started = 0;
73
+ stats.succeeded = 0;
74
+ stats.failed = 0;
75
+ stats.aborted = 0;
76
+ stats.timedOut = 0;
77
+ stats.poolRejected = 0;
78
+ stats.poolTimeouts = 0;
79
+ delete stats.lastDurationMs;
80
+ }
81
+ });
82
+ }
83
+ function makeSequenceHttpClient(responses, fallback = makeHttpResponse()) {
84
+ return makeMockHttpClient((_req, index) => responses[index] ?? fallback);
85
+ }
86
+ function runHttpEffect(effect, env = {}) {
87
+ return toPromise(effect, env);
88
+ }
89
+ function makeFetchResponse(body = null, init = {}) {
90
+ assertResponseAvailable();
91
+ return new Response(body, init);
92
+ }
93
+ function makeJsonFetchResponse(body, init = {}) {
94
+ assertResponseAvailable();
95
+ return new Response(JSON.stringify(body), {
96
+ ...init,
97
+ headers: {
98
+ "content-type": "application/json",
99
+ ...init.headers
100
+ }
101
+ });
102
+ }
103
+ function installMockFetch(handler) {
104
+ const target = globalThis;
105
+ const original = target.fetch;
106
+ const calls = [];
107
+ const mockFetch = (async (input, init) => {
108
+ calls.push({ input, init });
109
+ return handler(input, init, calls.length - 1);
110
+ });
111
+ target.fetch = mockFetch;
112
+ return {
113
+ fetch: mockFetch,
114
+ calls: () => [...calls],
115
+ calledTimes: () => calls.length,
116
+ lastCall: () => calls.at(-1),
117
+ restore: () => {
118
+ if (original) target.fetch = original;
119
+ else Reflect.deleteProperty(target, "fetch");
120
+ }
121
+ };
122
+ }
123
+ async function withMockFetch(handler, run) {
124
+ const mock = installMockFetch(handler);
125
+ try {
126
+ return await run(mock);
127
+ } finally {
128
+ mock.restore();
129
+ }
130
+ }
131
+ function isAsync(value) {
132
+ return typeof value === "object" && value !== null && "_tag" in value;
133
+ }
134
+ function toHttpError(error) {
135
+ if (isHttpError(error)) return error;
136
+ return { _tag: "FetchError", message: error instanceof Error ? error.message : String(error) };
137
+ }
138
+ function isHttpError(error) {
139
+ if (typeof error !== "object" || error === null || !("_tag" in error)) return false;
140
+ const tag = error._tag;
141
+ return tag === "Abort" || tag === "BadUrl" || tag === "FetchError" || tag === "Timeout" || tag === "PoolRejected" || tag === "PoolTimeout" || tag === "PoolClosed" || tag === "BatchSplitError";
142
+ }
143
+ function assertResponseAvailable() {
144
+ if (typeof Response === "undefined") {
145
+ throw new Error("HTTP test helpers require global Response for fetch response mocks.");
146
+ }
147
+ }
148
+ export {
149
+ installMockFetch,
150
+ makeFetchResponse,
151
+ makeHttpResponse,
152
+ makeJsonFetchResponse,
153
+ makeJsonHttpResponse,
154
+ makeMockHttpClient,
155
+ makeSequenceHttpClient,
156
+ makeTextHttpResponse,
157
+ runHttpEffect,
158
+ withMockFetch
159
+ };
@@ -0,0 +1,159 @@
1
+ import {
2
+ decorate
3
+ } from "../chunk-PRWCB3QL.mjs";
4
+ import "../chunk-2WC63LJK.mjs";
5
+ import "../chunk-7V4KY4RL.mjs";
6
+ import "../chunk-J3H54ZRV.mjs";
7
+ import "../chunk-CCKHV5BT.mjs";
8
+ import {
9
+ toPromise
10
+ } from "../chunk-G6IQOE4P.mjs";
11
+ import {
12
+ asyncFail,
13
+ asyncSucceed
14
+ } from "../chunk-NOYZIMUJ.mjs";
15
+ import "../chunk-U5KWK3PX.mjs";
16
+ import "../chunk-Y6FXYEAI.mjs";
17
+
18
+ // src/http/testing.ts
19
+ function makeHttpResponse(bodyText = "", init = {}) {
20
+ return {
21
+ status: init.status ?? 200,
22
+ statusText: init.statusText ?? "OK",
23
+ headers: init.headers ?? {},
24
+ bodyText,
25
+ ms: init.ms ?? 0
26
+ };
27
+ }
28
+ function makeTextHttpResponse(bodyText, init = {}) {
29
+ return makeHttpResponse(bodyText, init);
30
+ }
31
+ function makeJsonHttpResponse(body, init = {}) {
32
+ return makeHttpResponse(JSON.stringify(body), {
33
+ ...init,
34
+ headers: {
35
+ "content-type": "application/json",
36
+ ...init.headers ?? {}
37
+ }
38
+ });
39
+ }
40
+ function makeMockHttpClient(handler = () => makeHttpResponse()) {
41
+ const calls = [];
42
+ const stats = {
43
+ inFlight: 0,
44
+ started: 0,
45
+ succeeded: 0,
46
+ failed: 0,
47
+ aborted: 0,
48
+ timedOut: 0,
49
+ poolRejected: 0,
50
+ poolTimeouts: 0
51
+ };
52
+ const run = (req) => {
53
+ calls.push(req);
54
+ stats.started++;
55
+ try {
56
+ const result = handler(req, calls.length - 1);
57
+ if (isAsync(result)) return result;
58
+ stats.succeeded++;
59
+ return asyncSucceed(result);
60
+ } catch (error) {
61
+ stats.failed++;
62
+ return asyncFail(toHttpError(error));
63
+ }
64
+ };
65
+ return Object.assign(decorate(run, () => ({ ...stats })), {
66
+ calls: () => [...calls],
67
+ calledTimes: () => calls.length,
68
+ lastRequest: () => calls.at(-1),
69
+ reset: () => {
70
+ calls.length = 0;
71
+ stats.inFlight = 0;
72
+ stats.started = 0;
73
+ stats.succeeded = 0;
74
+ stats.failed = 0;
75
+ stats.aborted = 0;
76
+ stats.timedOut = 0;
77
+ stats.poolRejected = 0;
78
+ stats.poolTimeouts = 0;
79
+ delete stats.lastDurationMs;
80
+ }
81
+ });
82
+ }
83
+ function makeSequenceHttpClient(responses, fallback = makeHttpResponse()) {
84
+ return makeMockHttpClient((_req, index) => responses[index] ?? fallback);
85
+ }
86
+ function runHttpEffect(effect, env = {}) {
87
+ return toPromise(effect, env);
88
+ }
89
+ function makeFetchResponse(body = null, init = {}) {
90
+ assertResponseAvailable();
91
+ return new Response(body, init);
92
+ }
93
+ function makeJsonFetchResponse(body, init = {}) {
94
+ assertResponseAvailable();
95
+ return new Response(JSON.stringify(body), {
96
+ ...init,
97
+ headers: {
98
+ "content-type": "application/json",
99
+ ...init.headers
100
+ }
101
+ });
102
+ }
103
+ function installMockFetch(handler) {
104
+ const target = globalThis;
105
+ const original = target.fetch;
106
+ const calls = [];
107
+ const mockFetch = (async (input, init) => {
108
+ calls.push({ input, init });
109
+ return handler(input, init, calls.length - 1);
110
+ });
111
+ target.fetch = mockFetch;
112
+ return {
113
+ fetch: mockFetch,
114
+ calls: () => [...calls],
115
+ calledTimes: () => calls.length,
116
+ lastCall: () => calls.at(-1),
117
+ restore: () => {
118
+ if (original) target.fetch = original;
119
+ else Reflect.deleteProperty(target, "fetch");
120
+ }
121
+ };
122
+ }
123
+ async function withMockFetch(handler, run) {
124
+ const mock = installMockFetch(handler);
125
+ try {
126
+ return await run(mock);
127
+ } finally {
128
+ mock.restore();
129
+ }
130
+ }
131
+ function isAsync(value) {
132
+ return typeof value === "object" && value !== null && "_tag" in value;
133
+ }
134
+ function toHttpError(error) {
135
+ if (isHttpError(error)) return error;
136
+ return { _tag: "FetchError", message: error instanceof Error ? error.message : String(error) };
137
+ }
138
+ function isHttpError(error) {
139
+ if (typeof error !== "object" || error === null || !("_tag" in error)) return false;
140
+ const tag = error._tag;
141
+ return tag === "Abort" || tag === "BadUrl" || tag === "FetchError" || tag === "Timeout" || tag === "PoolRejected" || tag === "PoolTimeout" || tag === "PoolClosed" || tag === "BatchSplitError";
142
+ }
143
+ function assertResponseAvailable() {
144
+ if (typeof Response === "undefined") {
145
+ throw new Error("HTTP test helpers require global Response for fetch response mocks.");
146
+ }
147
+ }
148
+ export {
149
+ installMockFetch,
150
+ makeFetchResponse,
151
+ makeHttpResponse,
152
+ makeJsonFetchResponse,
153
+ makeJsonHttpResponse,
154
+ makeMockHttpClient,
155
+ makeSequenceHttpClient,
156
+ makeTextHttpResponse,
157
+ runHttpEffect,
158
+ withMockFetch
159
+ };