@forgezero/providers 0.1.24 → 0.1.25
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/billing.js +1 -1
- package/dist/database.js +1 -1
- package/dist/email.js +1 -1
- package/dist/git.js +1 -1
- package/dist/http.d.ts +9 -12
- package/dist/http.js +8 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/pool.js +7 -6
- package/dist/storage.js +1 -1
- package/dist/translation.js +1 -1
- package/package.json +2 -2
package/dist/billing.js
CHANGED
package/dist/database.js
CHANGED
package/dist/email.js
CHANGED
package/dist/git.js
CHANGED
package/dist/http.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import { ProviderError } from './index';
|
|
|
2
2
|
/**
|
|
3
3
|
* Outbound HTTP with a budget that is actually respected.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* a trading system leans on, and the failure mode is a 418 and a temporary ban
|
|
10
|
-
* rather than a slowdown.
|
|
5
|
+
* Some providers rate-limit cost rather than request count. A call may consume
|
|
6
|
+
* many units while a status probe consumes one, so a per-request limiter can be
|
|
7
|
+
* wrong by an order of magnitude. This generic ledger accepts the provider's
|
|
8
|
+
* reported cost without embedding a vendor-specific protocol in the package.
|
|
11
9
|
*
|
|
12
10
|
* ## The budget is per HOST, and shared
|
|
13
11
|
*
|
|
@@ -24,7 +22,7 @@ import { ProviderError } from './index';
|
|
|
24
22
|
*/
|
|
25
23
|
export interface HostBudget {
|
|
26
24
|
host: string;
|
|
27
|
-
/**
|
|
25
|
+
/** Provider-defined units per window, or requests for a simpler API. */
|
|
28
26
|
limit: number;
|
|
29
27
|
windowMs: number;
|
|
30
28
|
/** Assumed cost before the real one is known. */
|
|
@@ -58,9 +56,8 @@ export interface HttpConfig {
|
|
|
58
56
|
baseUrl: string;
|
|
59
57
|
budget: HostBudget;
|
|
60
58
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* venue owns this rather than the client guessing.
|
|
59
|
+
* Reads the true cost out of a response. The provider adapter owns the
|
|
60
|
+
* response-header contract rather than this generic client guessing.
|
|
64
61
|
*/
|
|
65
62
|
costOf?: (response: Response) => number | undefined;
|
|
66
63
|
fetch?: typeof globalThis.fetch;
|
|
@@ -94,7 +91,7 @@ export type HttpClient = ReturnType<typeof createHttpClient>;
|
|
|
94
91
|
* that decides whether a retry helps or makes things worse.
|
|
95
92
|
*/
|
|
96
93
|
export declare const http: import("./index").ProviderDefinition<Record<"request", import("./index").ProviderMethodSpec<HttpRequest, HttpResponse<unknown>>>>;
|
|
97
|
-
/**
|
|
98
|
-
export declare const
|
|
94
|
+
/** Build a provider-specific response-cost reader without coupling this module to a vendor. */
|
|
95
|
+
export declare const responseHeaderCost: (headerName: string) => (response: Response) => number | undefined;
|
|
99
96
|
export declare const httpProviders: readonly [import("./index").ProviderDefinition<Record<"request", import("./index").ProviderMethodSpec<HttpRequest, HttpResponse<unknown>>>>];
|
|
100
97
|
export {};
|
package/dist/http.js
CHANGED
|
@@ -336,7 +336,7 @@ function createService(definition, methods, options = {}) {
|
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
}
|
|
339
|
-
var VERSION = "0.1.
|
|
339
|
+
var VERSION = "0.1.25";
|
|
340
340
|
|
|
341
341
|
// src/http.ts
|
|
342
342
|
class BudgetExhausted extends ProviderError {
|
|
@@ -465,8 +465,6 @@ var http = defineSingleMethodProvider({
|
|
|
465
465
|
},
|
|
466
466
|
classify(error) {
|
|
467
467
|
const status = error.status;
|
|
468
|
-
if (status === 418)
|
|
469
|
-
return "backoff";
|
|
470
468
|
if (status === 429)
|
|
471
469
|
return "backoff";
|
|
472
470
|
if (status === 400 || status === 422)
|
|
@@ -476,19 +474,22 @@ var http = defineSingleMethodProvider({
|
|
|
476
474
|
return "retryable";
|
|
477
475
|
}
|
|
478
476
|
});
|
|
479
|
-
var
|
|
480
|
-
const header = response.headers.get(
|
|
481
|
-
|
|
477
|
+
var responseHeaderCost = (headerName) => (response) => {
|
|
478
|
+
const header = response.headers.get(headerName);
|
|
479
|
+
if (header === null)
|
|
480
|
+
return;
|
|
481
|
+
const value = Number(header);
|
|
482
|
+
return Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
482
483
|
};
|
|
483
484
|
var httpProviders = [http];
|
|
484
485
|
export {
|
|
485
486
|
spend,
|
|
486
487
|
settle,
|
|
488
|
+
responseHeaderCost,
|
|
487
489
|
resetBudgets,
|
|
488
490
|
httpProviders,
|
|
489
491
|
http,
|
|
490
492
|
createHttpClient,
|
|
491
493
|
budgetState,
|
|
492
|
-
binanceWeight,
|
|
493
494
|
BudgetExhausted
|
|
494
495
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/pool.js
CHANGED
|
@@ -336,7 +336,7 @@ function createService(definition, methods, options = {}) {
|
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
}
|
|
339
|
-
var VERSION = "0.1.
|
|
339
|
+
var VERSION = "0.1.25";
|
|
340
340
|
|
|
341
341
|
// src/http.ts
|
|
342
342
|
class BudgetExhausted extends ProviderError {
|
|
@@ -465,8 +465,6 @@ var http = defineSingleMethodProvider({
|
|
|
465
465
|
},
|
|
466
466
|
classify(error) {
|
|
467
467
|
const status = error.status;
|
|
468
|
-
if (status === 418)
|
|
469
|
-
return "backoff";
|
|
470
468
|
if (status === 429)
|
|
471
469
|
return "backoff";
|
|
472
470
|
if (status === 400 || status === 422)
|
|
@@ -476,9 +474,12 @@ var http = defineSingleMethodProvider({
|
|
|
476
474
|
return "retryable";
|
|
477
475
|
}
|
|
478
476
|
});
|
|
479
|
-
var
|
|
480
|
-
const header = response.headers.get(
|
|
481
|
-
|
|
477
|
+
var responseHeaderCost = (headerName) => (response) => {
|
|
478
|
+
const header = response.headers.get(headerName);
|
|
479
|
+
if (header === null)
|
|
480
|
+
return;
|
|
481
|
+
const value = Number(header);
|
|
482
|
+
return Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
482
483
|
};
|
|
483
484
|
var httpProviders = [http];
|
|
484
485
|
|
package/dist/storage.js
CHANGED
package/dist/translation.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgezero/providers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -85,6 +85,6 @@
|
|
|
85
85
|
"LICENSE"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@forgezero/runtime": "^0.1.
|
|
88
|
+
"@forgezero/runtime": "^0.1.16"
|
|
89
89
|
}
|
|
90
90
|
}
|