brass-runtime 1.13.5 → 1.13.6
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.
- package/dist/agent/cli/main.cjs +2022 -0
- package/dist/agent/cli/main.js +184 -184
- package/dist/agent/index.cjs +153 -0
- package/dist/agent/index.js +153 -153
- package/dist/chunk-3IF374MG.js +121 -121
- package/dist/chunk-AC4RFFVX.cjs +407 -0
- package/dist/chunk-DB57UZBE.cjs +2879 -0
- package/dist/chunk-HRVX2IYW.js +345 -345
- package/dist/chunk-KT4IKCIU.cjs +2556 -0
- package/dist/chunk-TGOMLZ65.js +317 -317
- package/dist/http/index.cjs +453 -0
- package/dist/http/index.js +74 -74
- package/dist/index.cjs +855 -0
- package/dist/index.js +340 -340
- package/package.json +5 -5
- package/dist/agent/cli/main.d.mts +0 -1
- package/dist/agent/index.d.mts +0 -688
- package/dist/effect-ISvXPLgc.d.mts +0 -797
- package/dist/http/index.d.mts +0 -154
- package/dist/index.d.mts +0 -258
- package/dist/stream-C0-LWnUP.d.mts +0 -66
package/dist/http/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import {
|
|
2
|
+
streamFromReadableStream
|
|
3
|
+
} from "../chunk-3IF374MG.js";
|
|
4
|
+
import {
|
|
5
|
+
asyncFail,
|
|
6
|
+
asyncFlatMap,
|
|
7
|
+
asyncFold,
|
|
8
|
+
asyncSucceed,
|
|
9
|
+
fromPromiseAbortable,
|
|
10
|
+
mapTryAsync,
|
|
11
|
+
toPromise,
|
|
12
|
+
withAsyncPromise
|
|
13
|
+
} from "../chunk-TGOMLZ65.js";
|
|
14
14
|
|
|
15
15
|
// src/http/optics/lens.ts
|
|
16
16
|
var Lens = {
|
|
@@ -31,7 +31,7 @@ var Lens = {
|
|
|
31
31
|
// src/http/optics/request.ts
|
|
32
32
|
var Request = {
|
|
33
33
|
headers: Lens.make(
|
|
34
|
-
(req) =>
|
|
34
|
+
(req) => req.headers ?? {},
|
|
35
35
|
(headers) => (req) => ({ ...req, headers })
|
|
36
36
|
)
|
|
37
37
|
};
|
|
@@ -48,7 +48,7 @@ var normalizeHttpError = (e) => {
|
|
|
48
48
|
}
|
|
49
49
|
return { _tag: "FetchError", message: String(e) };
|
|
50
50
|
};
|
|
51
|
-
var sleepMs = (ms) =>
|
|
51
|
+
var sleepMs = (ms) => fromPromiseAbortable(
|
|
52
52
|
(signal) => new Promise((resolve, reject) => {
|
|
53
53
|
if (signal.aborted) return reject({ _tag: "Abort" });
|
|
54
54
|
const id = setTimeout(resolve, ms);
|
|
@@ -84,28 +84,28 @@ var normalizeHeadersInit = (h) => {
|
|
|
84
84
|
};
|
|
85
85
|
var normalizeRequest = (defaultHeaders) => (req0) => {
|
|
86
86
|
let req = Object.keys(defaultHeaders).length ? mergeHeadersUnder(defaultHeaders)(req0) : req0;
|
|
87
|
-
const initHeaders = normalizeHeadersInit(
|
|
87
|
+
const initHeaders = normalizeHeadersInit(req0.init?.headers);
|
|
88
88
|
if (initHeaders && Object.keys(initHeaders).length) {
|
|
89
89
|
req = mergeHeadersUnder(initHeaders)(req);
|
|
90
90
|
}
|
|
91
91
|
return req;
|
|
92
92
|
};
|
|
93
93
|
function makeHttpStream(cfg = {}) {
|
|
94
|
-
const baseUrl =
|
|
95
|
-
const defaultHeaders =
|
|
94
|
+
const baseUrl = cfg.baseUrl ?? "";
|
|
95
|
+
const defaultHeaders = cfg.headers ?? {};
|
|
96
96
|
const normalize = normalizeRequest(defaultHeaders);
|
|
97
|
-
return (req0) =>
|
|
97
|
+
return (req0) => fromPromiseAbortable(
|
|
98
98
|
async (signal) => {
|
|
99
99
|
const req = normalize(req0);
|
|
100
100
|
let url;
|
|
101
101
|
try {
|
|
102
102
|
url = new URL(req.url, baseUrl);
|
|
103
|
-
} catch
|
|
103
|
+
} catch {
|
|
104
104
|
throw { _tag: "BadUrl", message: `URL inv\xE1lida: ${req.url}` };
|
|
105
105
|
}
|
|
106
106
|
const started = performance.now();
|
|
107
107
|
const res = await fetch(url, {
|
|
108
|
-
...
|
|
108
|
+
...req.init ?? {},
|
|
109
109
|
method: req.method,
|
|
110
110
|
headers: Request.headers.get(req),
|
|
111
111
|
// 👈 optics: headers ya normalizados
|
|
@@ -114,7 +114,7 @@ function makeHttpStream(cfg = {}) {
|
|
|
114
114
|
});
|
|
115
115
|
const headers = {};
|
|
116
116
|
res.headers.forEach((v, k) => headers[k] = v);
|
|
117
|
-
const body =
|
|
117
|
+
const body = streamFromReadableStream(res.body, normalizeHttpError2);
|
|
118
118
|
return {
|
|
119
119
|
status: res.status,
|
|
120
120
|
statusText: res.statusText,
|
|
@@ -127,21 +127,21 @@ function makeHttpStream(cfg = {}) {
|
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
function makeHttp(cfg = {}) {
|
|
130
|
-
const baseUrl =
|
|
131
|
-
const defaultHeaders =
|
|
130
|
+
const baseUrl = cfg.baseUrl ?? "";
|
|
131
|
+
const defaultHeaders = cfg.headers ?? {};
|
|
132
132
|
const normalize = normalizeRequest(defaultHeaders);
|
|
133
|
-
const run = (req0) =>
|
|
133
|
+
const run = (req0) => fromPromiseAbortable(
|
|
134
134
|
async (signal) => {
|
|
135
135
|
const req = normalize(req0);
|
|
136
136
|
let url;
|
|
137
137
|
try {
|
|
138
138
|
url = new URL(req.url, baseUrl);
|
|
139
|
-
} catch
|
|
139
|
+
} catch {
|
|
140
140
|
throw { _tag: "BadUrl", message: `URL inv\xE1lida: ${req.url}` };
|
|
141
141
|
}
|
|
142
142
|
const started = performance.now();
|
|
143
143
|
const res = await fetch(url, {
|
|
144
|
-
...
|
|
144
|
+
...req.init ?? {},
|
|
145
145
|
method: req.method,
|
|
146
146
|
headers: Request.headers.get(req),
|
|
147
147
|
// 👈 optics
|
|
@@ -174,7 +174,7 @@ var backoffDelayMs = (attempt, base, cap) => {
|
|
|
174
174
|
var retryAfterMs = (headers) => {
|
|
175
175
|
const key = Object.keys(headers).find((k) => k.toLowerCase() === "retry-after");
|
|
176
176
|
if (!key) return void 0;
|
|
177
|
-
const v =
|
|
177
|
+
const v = headers[key]?.trim();
|
|
178
178
|
if (!v) return void 0;
|
|
179
179
|
const secs = Number(v);
|
|
180
180
|
if (Number.isFinite(secs)) return Math.max(0, Math.floor(secs * 1e3));
|
|
@@ -183,21 +183,21 @@ var retryAfterMs = (headers) => {
|
|
|
183
183
|
return void 0;
|
|
184
184
|
};
|
|
185
185
|
var withRetryStream = (p) => (next) => ((req) => {
|
|
186
|
-
const loop = (attempt) =>
|
|
186
|
+
const loop = (attempt) => asyncFold(
|
|
187
187
|
next(req),
|
|
188
188
|
(e) => {
|
|
189
|
-
if (e._tag === "Abort" || e._tag === "BadUrl") return
|
|
190
|
-
const canRetry = attempt < p.maxRetries && (
|
|
191
|
-
if (!canRetry) return
|
|
189
|
+
if (e._tag === "Abort" || e._tag === "BadUrl") return asyncFail(e);
|
|
190
|
+
const canRetry = attempt < p.maxRetries && (p.retryOnError ?? defaultRetryOnError)(e);
|
|
191
|
+
if (!canRetry) return asyncFail(e);
|
|
192
192
|
const d = backoffDelayMs(attempt, p.baseDelayMs, p.maxDelayMs);
|
|
193
|
-
return
|
|
193
|
+
return asyncFlatMap(sleepMs(d), () => loop(attempt + 1));
|
|
194
194
|
},
|
|
195
195
|
(w) => {
|
|
196
|
-
const canRetry = attempt < p.maxRetries && (
|
|
197
|
-
if (!canRetry) return
|
|
196
|
+
const canRetry = attempt < p.maxRetries && (p.retryOnStatus ?? defaultRetryOnStatus)(w.status);
|
|
197
|
+
if (!canRetry) return asyncSucceed(w);
|
|
198
198
|
const ra = retryAfterMs(w.headers);
|
|
199
|
-
const d =
|
|
200
|
-
return
|
|
199
|
+
const d = ra ?? backoffDelayMs(attempt, p.baseDelayMs, p.maxDelayMs);
|
|
200
|
+
return asyncFlatMap(sleepMs(d), () => loop(attempt + 1));
|
|
201
201
|
}
|
|
202
202
|
);
|
|
203
203
|
return loop(0);
|
|
@@ -220,7 +220,7 @@ var headerCI = (h, name) => {
|
|
|
220
220
|
return k ? h[k] : void 0;
|
|
221
221
|
};
|
|
222
222
|
var retryAfterMs2 = (headers) => {
|
|
223
|
-
const v =
|
|
223
|
+
const v = headerCI(headers, "retry-after")?.trim();
|
|
224
224
|
if (!v) return void 0;
|
|
225
225
|
const secs = Number(v);
|
|
226
226
|
if (Number.isFinite(secs)) return Math.max(0, Math.floor(secs * 1e3));
|
|
@@ -229,27 +229,27 @@ var retryAfterMs2 = (headers) => {
|
|
|
229
229
|
return void 0;
|
|
230
230
|
};
|
|
231
231
|
var withRetry = (p) => (next) => {
|
|
232
|
-
const retryOnMethods =
|
|
233
|
-
const retryOnStatus =
|
|
234
|
-
const retryOnError =
|
|
232
|
+
const retryOnMethods = p.retryOnMethods ?? defaultRetryableMethods;
|
|
233
|
+
const retryOnStatus = p.retryOnStatus ?? defaultRetryOnStatus2;
|
|
234
|
+
const retryOnError = p.retryOnError ?? defaultRetryOnError2;
|
|
235
235
|
const isMethodRetryable = (req) => retryOnMethods.includes(req.method);
|
|
236
236
|
const loop = (req, attempt) => {
|
|
237
237
|
if (!isMethodRetryable(req)) return next(req);
|
|
238
|
-
return
|
|
238
|
+
return asyncFold(
|
|
239
239
|
next(req),
|
|
240
240
|
(e) => {
|
|
241
|
-
if (e._tag === "Abort" || e._tag === "BadUrl") return
|
|
241
|
+
if (e._tag === "Abort" || e._tag === "BadUrl") return asyncFail(e);
|
|
242
242
|
const canRetry = attempt < p.maxRetries && retryOnError(e);
|
|
243
|
-
if (!canRetry) return
|
|
243
|
+
if (!canRetry) return asyncFail(e);
|
|
244
244
|
const d = backoffDelayMs2(attempt, p.baseDelayMs, p.maxDelayMs);
|
|
245
|
-
return
|
|
245
|
+
return asyncFlatMap(sleepMs(d), () => loop(req, attempt + 1));
|
|
246
246
|
},
|
|
247
247
|
(w) => {
|
|
248
248
|
const canRetry = attempt < p.maxRetries && retryOnStatus(w.status);
|
|
249
|
-
if (!canRetry) return
|
|
249
|
+
if (!canRetry) return asyncSucceed(w);
|
|
250
250
|
const ra = retryAfterMs2(w.headers);
|
|
251
|
-
const d =
|
|
252
|
-
return
|
|
251
|
+
const d = ra ?? backoffDelayMs2(attempt, p.baseDelayMs, p.maxDelayMs);
|
|
252
|
+
return asyncFlatMap(sleepMs(d), () => loop(req, attempt + 1));
|
|
253
253
|
}
|
|
254
254
|
);
|
|
255
255
|
};
|
|
@@ -259,17 +259,17 @@ var withRetry = (p) => (next) => {
|
|
|
259
259
|
// src/http/httpClient.ts
|
|
260
260
|
var resolveFinalUrl = (baseUrl, url) => {
|
|
261
261
|
try {
|
|
262
|
-
return new URL(url,
|
|
263
|
-
} catch
|
|
264
|
-
return (
|
|
262
|
+
return new URL(url, baseUrl ?? "").toString();
|
|
263
|
+
} catch {
|
|
264
|
+
return (baseUrl ?? "") + url;
|
|
265
265
|
}
|
|
266
266
|
};
|
|
267
267
|
var createHttpCore = (cfg = {}) => {
|
|
268
268
|
const wire = makeHttp(cfg);
|
|
269
|
-
const withPromise = (eff) =>
|
|
269
|
+
const withPromise = (eff) => withAsyncPromise((e, env) => toPromise(e, env))(eff);
|
|
270
270
|
const requestRaw = (req) => wire(req);
|
|
271
271
|
const splitInit = (init) => {
|
|
272
|
-
const { headers, ...rest } =
|
|
272
|
+
const { headers, ...rest } = init ?? {};
|
|
273
273
|
return {
|
|
274
274
|
headers: normalizeHeadersInit(headers),
|
|
275
275
|
init: rest
|
|
@@ -312,20 +312,20 @@ function httpClient(cfg = {}) {
|
|
|
312
312
|
const post = (url, body, init) => request(core.buildReq("POST", url, init, body));
|
|
313
313
|
const getText = (url, init) => {
|
|
314
314
|
const req = core.buildReq("GET", url, init);
|
|
315
|
-
return core.withPromise(
|
|
315
|
+
return core.withPromise(mapTryAsync(requestRaw(req), (w) => core.toResponse(w, w.bodyText)));
|
|
316
316
|
};
|
|
317
317
|
const getJson = (url, init) => {
|
|
318
318
|
const base = core.buildReq("GET", url, init);
|
|
319
319
|
const req = setHeaderIfMissing("accept", "application/json")(base);
|
|
320
|
-
return core.withPromise(
|
|
320
|
+
return core.withPromise(mapTryAsync(requestRaw(req), (w) => core.toResponse(w, JSON.parse(w.bodyText))));
|
|
321
321
|
};
|
|
322
322
|
const postJson = (url, bodyObj, init) => {
|
|
323
|
-
const base = core.buildReq("POST", url, init, JSON.stringify(
|
|
323
|
+
const base = core.buildReq("POST", url, init, JSON.stringify(bodyObj ?? {}));
|
|
324
324
|
const req = setHeaderIfMissing("content-type", "application/json")(
|
|
325
325
|
setHeaderIfMissing("accept", "application/json")(base)
|
|
326
326
|
);
|
|
327
327
|
return core.withPromise(
|
|
328
|
-
|
|
328
|
+
mapTryAsync(requestRaw(req), (w) => core.toResponse(w, JSON.parse(w.bodyText)))
|
|
329
329
|
);
|
|
330
330
|
};
|
|
331
331
|
return {
|
|
@@ -353,7 +353,7 @@ function httpClientWithMeta(cfg = {}) {
|
|
|
353
353
|
const request = (req) => {
|
|
354
354
|
const startedAt = Date.now();
|
|
355
355
|
return core.withPromise(
|
|
356
|
-
|
|
356
|
+
mapTryAsync(core.requestRaw(req), (w) => ({
|
|
357
357
|
wire: w,
|
|
358
358
|
meta: mkMeta(req, w, startedAt)
|
|
359
359
|
}))
|
|
@@ -368,13 +368,13 @@ function httpClientWithMeta(cfg = {}) {
|
|
|
368
368
|
return request(req);
|
|
369
369
|
};
|
|
370
370
|
const postJson = (url, bodyObj, init) => {
|
|
371
|
-
const base = core.buildReq("POST", url, init, JSON.stringify(
|
|
371
|
+
const base = core.buildReq("POST", url, init, JSON.stringify(bodyObj ?? {}));
|
|
372
372
|
const req = setHeaderIfMissing("content-type", "application/json")(
|
|
373
373
|
setHeaderIfMissing("accept", "application/json")(base)
|
|
374
374
|
);
|
|
375
375
|
const startedAt = Date.now();
|
|
376
376
|
return core.withPromise(
|
|
377
|
-
|
|
377
|
+
mapTryAsync(core.requestRaw(req), (w) => ({
|
|
378
378
|
wire: w,
|
|
379
379
|
response: core.toResponse(w, JSON.parse(w.bodyText)),
|
|
380
380
|
meta: mkMeta(req, w, startedAt)
|
|
@@ -385,7 +385,7 @@ function httpClientWithMeta(cfg = {}) {
|
|
|
385
385
|
const req = core.buildReq("GET", url, init);
|
|
386
386
|
const startedAt = Date.now();
|
|
387
387
|
return core.withPromise(
|
|
388
|
-
|
|
388
|
+
mapTryAsync(core.requestRaw(req), (w) => ({
|
|
389
389
|
wire: w,
|
|
390
390
|
response: core.toResponse(w, w.bodyText),
|
|
391
391
|
meta: mkMeta(req, w, startedAt)
|
|
@@ -397,7 +397,7 @@ function httpClientWithMeta(cfg = {}) {
|
|
|
397
397
|
const req = setHeaderIfMissing("accept", "application/json")(base);
|
|
398
398
|
const startedAt = Date.now();
|
|
399
399
|
return core.withPromise(
|
|
400
|
-
|
|
400
|
+
mapTryAsync(core.requestRaw(req), (w) => ({
|
|
401
401
|
wire: w,
|
|
402
402
|
response: core.toResponse(w, JSON.parse(w.bodyText)),
|
|
403
403
|
meta: mkMeta(req, w, startedAt)
|
|
@@ -422,7 +422,7 @@ function httpClientWithMeta(cfg = {}) {
|
|
|
422
422
|
function httpClientStream(cfg = {}) {
|
|
423
423
|
const wire = makeHttpStream(cfg);
|
|
424
424
|
const make = (w) => {
|
|
425
|
-
const withPromise = (eff) =>
|
|
425
|
+
const withPromise = (eff) => withAsyncPromise((e, env) => toPromise(e, env))(eff);
|
|
426
426
|
const request = (req) => withPromise(w(req));
|
|
427
427
|
const getStream = (url, init) => {
|
|
428
428
|
const base = { method: "GET", url, init };
|
|
@@ -440,14 +440,14 @@ function httpClientStream(cfg = {}) {
|
|
|
440
440
|
};
|
|
441
441
|
return make(wire);
|
|
442
442
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
443
|
+
export {
|
|
444
|
+
decorate,
|
|
445
|
+
httpClient,
|
|
446
|
+
httpClientStream,
|
|
447
|
+
httpClientWithMeta,
|
|
448
|
+
makeHttp,
|
|
449
|
+
makeHttpStream,
|
|
450
|
+
normalizeHeadersInit,
|
|
451
|
+
withMiddleware,
|
|
452
|
+
withRetryStream
|
|
453
|
+
};
|