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.
@@ -1,16 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunk3IF374MGjs = require('../chunk-3IF374MG.js');
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
- var _chunkTGOMLZ65js = require('../chunk-TGOMLZ65.js');
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) => _nullishCoalesce(req.headers, () => ( {})),
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) => _chunkTGOMLZ65js.fromPromiseAbortable.call(void 0,
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(_optionalChain([req0, 'access', _ => _.init, 'optionalAccess', _2 => _2.headers]));
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 = _nullishCoalesce(cfg.baseUrl, () => ( ""));
95
- const defaultHeaders = _nullishCoalesce(cfg.headers, () => ( {}));
94
+ const baseUrl = cfg.baseUrl ?? "";
95
+ const defaultHeaders = cfg.headers ?? {};
96
96
  const normalize = normalizeRequest(defaultHeaders);
97
- return (req0) => _chunkTGOMLZ65js.fromPromiseAbortable.call(void 0,
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 (e2) {
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
- ..._nullishCoalesce(req.init, () => ( {})),
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 = _chunk3IF374MGjs.streamFromReadableStream.call(void 0, res.body, normalizeHttpError2);
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 = _nullishCoalesce(cfg.baseUrl, () => ( ""));
131
- const defaultHeaders = _nullishCoalesce(cfg.headers, () => ( {}));
130
+ const baseUrl = cfg.baseUrl ?? "";
131
+ const defaultHeaders = cfg.headers ?? {};
132
132
  const normalize = normalizeRequest(defaultHeaders);
133
- const run = (req0) => _chunkTGOMLZ65js.fromPromiseAbortable.call(void 0,
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 (e3) {
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
- ..._nullishCoalesce(req.init, () => ( {})),
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 = _optionalChain([headers, 'access', _3 => _3[key], 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()]);
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) => _chunkTGOMLZ65js.asyncFold.call(void 0,
186
+ const loop = (attempt) => asyncFold(
187
187
  next(req),
188
188
  (e) => {
189
- if (e._tag === "Abort" || e._tag === "BadUrl") return _chunkTGOMLZ65js.asyncFail.call(void 0, e);
190
- const canRetry = attempt < p.maxRetries && (_nullishCoalesce(p.retryOnError, () => ( defaultRetryOnError)))(e);
191
- if (!canRetry) return _chunkTGOMLZ65js.asyncFail.call(void 0, e);
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 _chunkTGOMLZ65js.asyncFlatMap.call(void 0, sleepMs(d), () => loop(attempt + 1));
193
+ return asyncFlatMap(sleepMs(d), () => loop(attempt + 1));
194
194
  },
195
195
  (w) => {
196
- const canRetry = attempt < p.maxRetries && (_nullishCoalesce(p.retryOnStatus, () => ( defaultRetryOnStatus)))(w.status);
197
- if (!canRetry) return _chunkTGOMLZ65js.asyncSucceed.call(void 0, w);
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 = _nullishCoalesce(ra, () => ( backoffDelayMs(attempt, p.baseDelayMs, p.maxDelayMs)));
200
- return _chunkTGOMLZ65js.asyncFlatMap.call(void 0, sleepMs(d), () => loop(attempt + 1));
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 = _optionalChain([headerCI, 'call', _6 => _6(headers, "retry-after"), 'optionalAccess', _7 => _7.trim, 'call', _8 => _8()]);
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 = _nullishCoalesce(p.retryOnMethods, () => ( defaultRetryableMethods));
233
- const retryOnStatus = _nullishCoalesce(p.retryOnStatus, () => ( defaultRetryOnStatus2));
234
- const retryOnError = _nullishCoalesce(p.retryOnError, () => ( defaultRetryOnError2));
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 _chunkTGOMLZ65js.asyncFold.call(void 0,
238
+ return asyncFold(
239
239
  next(req),
240
240
  (e) => {
241
- if (e._tag === "Abort" || e._tag === "BadUrl") return _chunkTGOMLZ65js.asyncFail.call(void 0, e);
241
+ if (e._tag === "Abort" || e._tag === "BadUrl") return asyncFail(e);
242
242
  const canRetry = attempt < p.maxRetries && retryOnError(e);
243
- if (!canRetry) return _chunkTGOMLZ65js.asyncFail.call(void 0, e);
243
+ if (!canRetry) return asyncFail(e);
244
244
  const d = backoffDelayMs2(attempt, p.baseDelayMs, p.maxDelayMs);
245
- return _chunkTGOMLZ65js.asyncFlatMap.call(void 0, sleepMs(d), () => loop(req, attempt + 1));
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 _chunkTGOMLZ65js.asyncSucceed.call(void 0, w);
249
+ if (!canRetry) return asyncSucceed(w);
250
250
  const ra = retryAfterMs2(w.headers);
251
- const d = _nullishCoalesce(ra, () => ( backoffDelayMs2(attempt, p.baseDelayMs, p.maxDelayMs)));
252
- return _chunkTGOMLZ65js.asyncFlatMap.call(void 0, sleepMs(d), () => loop(req, attempt + 1));
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, _nullishCoalesce(baseUrl, () => ( ""))).toString();
263
- } catch (e4) {
264
- return (_nullishCoalesce(baseUrl, () => ( ""))) + url;
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) => _chunkTGOMLZ65js.withAsyncPromise.call(void 0, (e, env) => _chunkTGOMLZ65js.toPromise.call(void 0, e, env))(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 } = _nullishCoalesce(init, () => ( {}));
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(_chunkTGOMLZ65js.mapTryAsync.call(void 0, requestRaw(req), (w) => core.toResponse(w, w.bodyText)));
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(_chunkTGOMLZ65js.mapTryAsync.call(void 0, requestRaw(req), (w) => core.toResponse(w, JSON.parse(w.bodyText))));
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(_nullishCoalesce(bodyObj, () => ( {}))));
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
- _chunkTGOMLZ65js.mapTryAsync.call(void 0, requestRaw(req), (w) => core.toResponse(w, JSON.parse(w.bodyText)))
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
- _chunkTGOMLZ65js.mapTryAsync.call(void 0, core.requestRaw(req), (w) => ({
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(_nullishCoalesce(bodyObj, () => ( {}))));
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
- _chunkTGOMLZ65js.mapTryAsync.call(void 0, core.requestRaw(req), (w) => ({
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
- _chunkTGOMLZ65js.mapTryAsync.call(void 0, core.requestRaw(req), (w) => ({
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
- _chunkTGOMLZ65js.mapTryAsync.call(void 0, core.requestRaw(req), (w) => ({
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) => _chunkTGOMLZ65js.withAsyncPromise.call(void 0, (e, env) => _chunkTGOMLZ65js.toPromise.call(void 0, e, env))(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
- exports.decorate = decorate; exports.httpClient = httpClient; exports.httpClientStream = httpClientStream; exports.httpClientWithMeta = httpClientWithMeta; exports.makeHttp = makeHttp; exports.makeHttpStream = makeHttpStream; exports.normalizeHeadersInit = normalizeHeadersInit; exports.withMiddleware = withMiddleware; exports.withRetryStream = withRetryStream;
443
+ export {
444
+ decorate,
445
+ httpClient,
446
+ httpClientStream,
447
+ httpClientWithMeta,
448
+ makeHttp,
449
+ makeHttpStream,
450
+ normalizeHeadersInit,
451
+ withMiddleware,
452
+ withRetryStream
453
+ };