@tradejs/infra 3.0.0 → 3.1.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.
- package/README.md +0 -1
- package/package.json +2 -7
- package/dist/http.d.mts +0 -8
- package/dist/http.d.ts +0 -8
- package/dist/http.js +0 -79
- package/dist/http.mjs +0 -54
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/infra",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "MIT-licensed server infrastructure adapters for TradeJS: Redis, Timescale, ML, logging, and IO.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -44,11 +44,6 @@
|
|
|
44
44
|
"import": "./dist/files.mjs",
|
|
45
45
|
"require": "./dist/files.js"
|
|
46
46
|
},
|
|
47
|
-
"./http": {
|
|
48
|
-
"types": "./dist/http.d.ts",
|
|
49
|
-
"import": "./dist/http.mjs",
|
|
50
|
-
"require": "./dist/http.js"
|
|
51
|
-
},
|
|
52
47
|
"./logger": {
|
|
53
48
|
"types": "./dist/logger.d.ts",
|
|
54
49
|
"import": "./dist/logger.mjs",
|
|
@@ -123,7 +118,7 @@
|
|
|
123
118
|
"dependencies": {
|
|
124
119
|
"@grpc/grpc-js": "^1.14.4",
|
|
125
120
|
"@grpc/proto-loader": "^0.8.1",
|
|
126
|
-
"@tradejs/types": "^3.
|
|
121
|
+
"@tradejs/types": "^3.1.0",
|
|
127
122
|
"chalk": "4.1.2",
|
|
128
123
|
"date-fns": "^3.6.0",
|
|
129
124
|
"ioredis": "5.11.1",
|
package/dist/http.d.mts
DELETED
package/dist/http.d.ts
DELETED
package/dist/http.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/http.ts
|
|
21
|
-
var http_exports = {};
|
|
22
|
-
__export(http_exports, {
|
|
23
|
-
fetchWithRetry: () => fetchWithRetry
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(http_exports);
|
|
26
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
27
|
-
var parseRetryAfterMs = (value) => {
|
|
28
|
-
if (!value) return 0;
|
|
29
|
-
const seconds = Number(value);
|
|
30
|
-
if (Number.isFinite(seconds)) {
|
|
31
|
-
return Math.max(0, seconds * 1e3);
|
|
32
|
-
}
|
|
33
|
-
const dateMs = Date.parse(value);
|
|
34
|
-
if (Number.isFinite(dateMs)) {
|
|
35
|
-
return Math.max(0, dateMs - Date.now());
|
|
36
|
-
}
|
|
37
|
-
return 0;
|
|
38
|
-
};
|
|
39
|
-
var fetchWithRetry = async (url, options = {}) => {
|
|
40
|
-
const {
|
|
41
|
-
attempts = 5,
|
|
42
|
-
baseDelayMs = 300,
|
|
43
|
-
maxDelayMs = 5e3,
|
|
44
|
-
...fetchOptions
|
|
45
|
-
} = options;
|
|
46
|
-
let lastError;
|
|
47
|
-
for (let i = 0; i < attempts; i++) {
|
|
48
|
-
try {
|
|
49
|
-
const response = await fetch(url, fetchOptions);
|
|
50
|
-
if (response.ok) {
|
|
51
|
-
return response;
|
|
52
|
-
}
|
|
53
|
-
const shouldRetry = response.status === 429 || response.status >= 500;
|
|
54
|
-
if (!shouldRetry || i === attempts - 1) {
|
|
55
|
-
return response;
|
|
56
|
-
}
|
|
57
|
-
const retryAfterMs = parseRetryAfterMs(
|
|
58
|
-
response.headers.get("retry-after")
|
|
59
|
-
);
|
|
60
|
-
const backoffMs = Math.min(maxDelayMs, baseDelayMs * 2 ** i);
|
|
61
|
-
await sleep(Math.max(retryAfterMs, backoffMs));
|
|
62
|
-
} catch (error) {
|
|
63
|
-
lastError = error;
|
|
64
|
-
if (i === attempts - 1) {
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
const backoffMs = Math.min(maxDelayMs, baseDelayMs * 2 ** i);
|
|
68
|
-
await sleep(backoffMs);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (lastError) {
|
|
72
|
-
throw lastError;
|
|
73
|
-
}
|
|
74
|
-
return fetch(url, fetchOptions);
|
|
75
|
-
};
|
|
76
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
-
0 && (module.exports = {
|
|
78
|
-
fetchWithRetry
|
|
79
|
-
});
|
package/dist/http.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// src/http.ts
|
|
2
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
-
var parseRetryAfterMs = (value) => {
|
|
4
|
-
if (!value) return 0;
|
|
5
|
-
const seconds = Number(value);
|
|
6
|
-
if (Number.isFinite(seconds)) {
|
|
7
|
-
return Math.max(0, seconds * 1e3);
|
|
8
|
-
}
|
|
9
|
-
const dateMs = Date.parse(value);
|
|
10
|
-
if (Number.isFinite(dateMs)) {
|
|
11
|
-
return Math.max(0, dateMs - Date.now());
|
|
12
|
-
}
|
|
13
|
-
return 0;
|
|
14
|
-
};
|
|
15
|
-
var fetchWithRetry = async (url, options = {}) => {
|
|
16
|
-
const {
|
|
17
|
-
attempts = 5,
|
|
18
|
-
baseDelayMs = 300,
|
|
19
|
-
maxDelayMs = 5e3,
|
|
20
|
-
...fetchOptions
|
|
21
|
-
} = options;
|
|
22
|
-
let lastError;
|
|
23
|
-
for (let i = 0; i < attempts; i++) {
|
|
24
|
-
try {
|
|
25
|
-
const response = await fetch(url, fetchOptions);
|
|
26
|
-
if (response.ok) {
|
|
27
|
-
return response;
|
|
28
|
-
}
|
|
29
|
-
const shouldRetry = response.status === 429 || response.status >= 500;
|
|
30
|
-
if (!shouldRetry || i === attempts - 1) {
|
|
31
|
-
return response;
|
|
32
|
-
}
|
|
33
|
-
const retryAfterMs = parseRetryAfterMs(
|
|
34
|
-
response.headers.get("retry-after")
|
|
35
|
-
);
|
|
36
|
-
const backoffMs = Math.min(maxDelayMs, baseDelayMs * 2 ** i);
|
|
37
|
-
await sleep(Math.max(retryAfterMs, backoffMs));
|
|
38
|
-
} catch (error) {
|
|
39
|
-
lastError = error;
|
|
40
|
-
if (i === attempts - 1) {
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
const backoffMs = Math.min(maxDelayMs, baseDelayMs * 2 ** i);
|
|
44
|
-
await sleep(backoffMs);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (lastError) {
|
|
48
|
-
throw lastError;
|
|
49
|
-
}
|
|
50
|
-
return fetch(url, fetchOptions);
|
|
51
|
-
};
|
|
52
|
-
export {
|
|
53
|
-
fetchWithRetry
|
|
54
|
-
};
|