@shware/http 2.0.1 → 2.2.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/dist/error/parse.cjs +13 -1
- package/dist/error/parse.cjs.map +1 -1
- package/dist/error/parse.mjs +11 -1
- package/dist/error/parse.mjs.map +1 -1
- package/dist/hono/geolocation.cjs +30 -30
- package/dist/hono/geolocation.cjs.map +1 -1
- package/dist/hono/geolocation.d.cts +10 -10
- package/dist/hono/geolocation.d.ts +10 -10
- package/dist/hono/geolocation.mjs +30 -30
- package/dist/hono/geolocation.mjs.map +1 -1
- package/dist/index.cjs +0 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.mjs +0 -12
- package/dist/index.mjs.map +1 -1
- package/dist/response.cjs +13 -1
- package/dist/response.cjs.map +1 -1
- package/dist/response.mjs +11 -1
- package/dist/response.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/utils/__tests__/base62.test.cjs +0 -29
- package/dist/utils/__tests__/base62.test.cjs.map +0 -1
- package/dist/utils/__tests__/base62.test.d.cts +0 -2
- package/dist/utils/__tests__/base62.test.d.ts +0 -2
- package/dist/utils/__tests__/base62.test.mjs +0 -27
- package/dist/utils/__tests__/base62.test.mjs.map +0 -1
- package/dist/utils/__tests__/ip.test.cjs +0 -38
- package/dist/utils/__tests__/ip.test.cjs.map +0 -1
- package/dist/utils/__tests__/ip.test.d.cts +0 -2
- package/dist/utils/__tests__/ip.test.d.ts +0 -2
- package/dist/utils/__tests__/ip.test.mjs +0 -36
- package/dist/utils/__tests__/ip.test.mjs.map +0 -1
- package/dist/utils/base62.cjs +0 -85
- package/dist/utils/base62.cjs.map +0 -1
- package/dist/utils/base62.d.cts +0 -6
- package/dist/utils/base62.d.ts +0 -6
- package/dist/utils/base62.mjs +0 -60
- package/dist/utils/base62.mjs.map +0 -1
- package/dist/utils/fetch.cjs +0 -78
- package/dist/utils/fetch.cjs.map +0 -1
- package/dist/utils/fetch.d.cts +0 -16
- package/dist/utils/fetch.d.ts +0 -16
- package/dist/utils/fetch.mjs +0 -53
- package/dist/utils/fetch.mjs.map +0 -1
- package/dist/utils/invariant.cjs +0 -37
- package/dist/utils/invariant.cjs.map +0 -1
- package/dist/utils/invariant.d.cts +0 -3
- package/dist/utils/invariant.d.ts +0 -3
- package/dist/utils/invariant.mjs +0 -12
- package/dist/utils/invariant.mjs.map +0 -1
- package/dist/utils/promise.cjs +0 -47
- package/dist/utils/promise.cjs.map +0 -1
- package/dist/utils/promise.d.cts +0 -3
- package/dist/utils/promise.d.ts +0 -3
- package/dist/utils/promise.mjs +0 -22
- package/dist/utils/promise.mjs.map +0 -1
- package/dist/utils/string.cjs +0 -33
- package/dist/utils/string.cjs.map +0 -1
- package/dist/utils/string.d.cts +0 -6
- package/dist/utils/string.d.ts +0 -6
- package/dist/utils/string.mjs +0 -8
- package/dist/utils/string.mjs.map +0 -1
- package/dist/utils/token-bucket.cjs +0 -73
- package/dist/utils/token-bucket.cjs.map +0 -1
- package/dist/utils/token-bucket.d.cts +0 -20
- package/dist/utils/token-bucket.d.ts +0 -20
- package/dist/utils/token-bucket.mjs +0 -48
- package/dist/utils/token-bucket.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/http",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"ts-jest": "^29.4.6",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
47
|
"@repo/eslint-config": "0.0.10",
|
|
48
|
-
"@repo/typescript-config": "0.0.0"
|
|
48
|
+
"@repo/typescript-config": "0.0.0",
|
|
49
|
+
"@shware/utils": "^1.0.1"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"zod": "^4.1.13"
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// src/utils/__tests__/base62.test.ts
|
|
4
|
-
var import_base62 = require("../base62.cjs");
|
|
5
|
-
describe("base62", () => {
|
|
6
|
-
it("should encode", () => {
|
|
7
|
-
const buffer = Buffer.from([1]);
|
|
8
|
-
const encoded = import_base62.base62.encode(buffer);
|
|
9
|
-
expect(encoded).toEqual("1");
|
|
10
|
-
});
|
|
11
|
-
it("should decode", () => {
|
|
12
|
-
const encoded = "1";
|
|
13
|
-
const decoded = import_base62.base62.decode(encoded);
|
|
14
|
-
expect(decoded).toEqual(Buffer.from([1]));
|
|
15
|
-
});
|
|
16
|
-
it("should encode and decode", () => {
|
|
17
|
-
const buffer = Buffer.from("hello", "utf-8");
|
|
18
|
-
const encoded = import_base62.base62.encode(buffer);
|
|
19
|
-
const decoded = import_base62.base62.decode(encoded, buffer.length);
|
|
20
|
-
expect(decoded).toEqual(buffer);
|
|
21
|
-
});
|
|
22
|
-
it("should encode and decode with leading zeros", () => {
|
|
23
|
-
const buffer = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
24
|
-
const encoded = import_base62.base62.encode(buffer);
|
|
25
|
-
const decoded = import_base62.base62.decode(encoded, buffer.length);
|
|
26
|
-
expect(decoded).toEqual(buffer);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
//# sourceMappingURL=base62.test.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/__tests__/base62.test.ts"],"sourcesContent":["import { base62 } from '../base62';\n\ndescribe('base62', () => {\n it('should encode', () => {\n const buffer = Buffer.from([1]);\n const encoded = base62.encode(buffer);\n expect(encoded).toEqual('1');\n });\n\n it('should decode', () => {\n const encoded = '1';\n const decoded = base62.decode(encoded);\n expect(decoded).toEqual(Buffer.from([1]));\n });\n\n it('should encode and decode', () => {\n const buffer = Buffer.from('hello', 'utf-8');\n const encoded = base62.encode(buffer);\n const decoded = base62.decode(encoded, buffer.length);\n expect(decoded).toEqual(buffer);\n });\n\n it('should encode and decode with leading zeros', () => {\n const buffer = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n const encoded = base62.encode(buffer);\n const decoded = base62.decode(encoded, buffer.length);\n expect(decoded).toEqual(buffer);\n });\n});\n"],"mappings":";;;AAAA,oBAAuB;AAEvB,SAAS,UAAU,MAAM;AACvB,KAAG,iBAAiB,MAAM;AACxB,UAAM,SAAS,OAAO,KAAK,CAAC,CAAC,CAAC;AAC9B,UAAM,UAAU,qBAAO,OAAO,MAAM;AACpC,WAAO,OAAO,EAAE,QAAQ,GAAG;AAAA,EAC7B,CAAC;AAED,KAAG,iBAAiB,MAAM;AACxB,UAAM,UAAU;AAChB,UAAM,UAAU,qBAAO,OAAO,OAAO;AACrC,WAAO,OAAO,EAAE,QAAQ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAAA,EAC1C,CAAC;AAED,KAAG,4BAA4B,MAAM;AACnC,UAAM,SAAS,OAAO,KAAK,SAAS,OAAO;AAC3C,UAAM,UAAU,qBAAO,OAAO,MAAM;AACpC,UAAM,UAAU,qBAAO,OAAO,SAAS,OAAO,MAAM;AACpD,WAAO,OAAO,EAAE,QAAQ,MAAM;AAAA,EAChC,CAAC;AAED,KAAG,+CAA+C,MAAM;AACtD,UAAM,SAAS,OAAO,KAAK,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;AAC3E,UAAM,UAAU,qBAAO,OAAO,MAAM;AACpC,UAAM,UAAU,qBAAO,OAAO,SAAS,OAAO,MAAM;AACpD,WAAO,OAAO,EAAE,QAAQ,MAAM;AAAA,EAChC,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/utils/__tests__/base62.test.ts
|
|
2
|
-
import { base62 } from "../base62.mjs";
|
|
3
|
-
describe("base62", () => {
|
|
4
|
-
it("should encode", () => {
|
|
5
|
-
const buffer = Buffer.from([1]);
|
|
6
|
-
const encoded = base62.encode(buffer);
|
|
7
|
-
expect(encoded).toEqual("1");
|
|
8
|
-
});
|
|
9
|
-
it("should decode", () => {
|
|
10
|
-
const encoded = "1";
|
|
11
|
-
const decoded = base62.decode(encoded);
|
|
12
|
-
expect(decoded).toEqual(Buffer.from([1]));
|
|
13
|
-
});
|
|
14
|
-
it("should encode and decode", () => {
|
|
15
|
-
const buffer = Buffer.from("hello", "utf-8");
|
|
16
|
-
const encoded = base62.encode(buffer);
|
|
17
|
-
const decoded = base62.decode(encoded, buffer.length);
|
|
18
|
-
expect(decoded).toEqual(buffer);
|
|
19
|
-
});
|
|
20
|
-
it("should encode and decode with leading zeros", () => {
|
|
21
|
-
const buffer = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
22
|
-
const encoded = base62.encode(buffer);
|
|
23
|
-
const decoded = base62.decode(encoded, buffer.length);
|
|
24
|
-
expect(decoded).toEqual(buffer);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=base62.test.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/__tests__/base62.test.ts"],"sourcesContent":["import { base62 } from '../base62';\n\ndescribe('base62', () => {\n it('should encode', () => {\n const buffer = Buffer.from([1]);\n const encoded = base62.encode(buffer);\n expect(encoded).toEqual('1');\n });\n\n it('should decode', () => {\n const encoded = '1';\n const decoded = base62.decode(encoded);\n expect(decoded).toEqual(Buffer.from([1]));\n });\n\n it('should encode and decode', () => {\n const buffer = Buffer.from('hello', 'utf-8');\n const encoded = base62.encode(buffer);\n const decoded = base62.decode(encoded, buffer.length);\n expect(decoded).toEqual(buffer);\n });\n\n it('should encode and decode with leading zeros', () => {\n const buffer = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n const encoded = base62.encode(buffer);\n const decoded = base62.decode(encoded, buffer.length);\n expect(decoded).toEqual(buffer);\n });\n});\n"],"mappings":";AAAA,SAAS,cAAc;AAEvB,SAAS,UAAU,MAAM;AACvB,KAAG,iBAAiB,MAAM;AACxB,UAAM,SAAS,OAAO,KAAK,CAAC,CAAC,CAAC;AAC9B,UAAM,UAAU,OAAO,OAAO,MAAM;AACpC,WAAO,OAAO,EAAE,QAAQ,GAAG;AAAA,EAC7B,CAAC;AAED,KAAG,iBAAiB,MAAM;AACxB,UAAM,UAAU;AAChB,UAAM,UAAU,OAAO,OAAO,OAAO;AACrC,WAAO,OAAO,EAAE,QAAQ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAAA,EAC1C,CAAC;AAED,KAAG,4BAA4B,MAAM;AACnC,UAAM,SAAS,OAAO,KAAK,SAAS,OAAO;AAC3C,UAAM,UAAU,OAAO,OAAO,MAAM;AACpC,UAAM,UAAU,OAAO,OAAO,SAAS,OAAO,MAAM;AACpD,WAAO,OAAO,EAAE,QAAQ,MAAM;AAAA,EAChC,CAAC;AAED,KAAG,+CAA+C,MAAM;AACtD,UAAM,SAAS,OAAO,KAAK,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;AAC3E,UAAM,UAAU,OAAO,OAAO,MAAM;AACpC,UAAM,UAAU,OAAO,OAAO,SAAS,OAAO,MAAM;AACpD,WAAO,OAAO,EAAE,QAAQ,MAAM;AAAA,EAChC,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// src/utils/__tests__/ip.test.ts
|
|
4
|
-
var import_ip = require("../ip.cjs");
|
|
5
|
-
describe("extractIpAddress", () => {
|
|
6
|
-
it("should extract the ipv4 address from the request", () => {
|
|
7
|
-
expect((0, import_ip.extractIpAddress)("127.0.0.1")).toBe("127.0.0.1");
|
|
8
|
-
expect((0, import_ip.extractIpAddress)("192.168.0.1")).toBe("192.168.0.1");
|
|
9
|
-
expect((0, import_ip.extractIpAddress)("127.0.0.1:8080")).toBe("127.0.0.1");
|
|
10
|
-
expect((0, import_ip.extractIpAddress)("192.168.0.1:8080")).toBe("192.168.0.1");
|
|
11
|
-
expect((0, import_ip.extractIpAddress)("127.0.0.1:8080/path")).toBe("127.0.0.1");
|
|
12
|
-
});
|
|
13
|
-
it("should extract the ipv6 address from the request", () => {
|
|
14
|
-
expect((0, import_ip.extractIpAddress)("::1")).toBe("::1");
|
|
15
|
-
expect((0, import_ip.extractIpAddress)("[::1]:8080")).toBe("::1");
|
|
16
|
-
expect((0, import_ip.extractIpAddress)("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
|
|
17
|
-
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
|
18
|
-
);
|
|
19
|
-
expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
|
|
20
|
-
"2001:db8:85a3::8a2e:370:7334"
|
|
21
|
-
// remove leading zeros
|
|
22
|
-
);
|
|
23
|
-
expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
|
|
24
|
-
"2001:db8:85a3::8a2e:370:7334"
|
|
25
|
-
// remove leading zeros
|
|
26
|
-
);
|
|
27
|
-
expect((0, import_ip.extractIpAddress)("2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704")).toBe(
|
|
28
|
-
"2404:7ac0:614d:bba7:cf41:992e:98e:9186"
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
it("should return null if the ip address is not valid", () => {
|
|
32
|
-
expect((0, import_ip.extractIpAddress)(null)).toBeNull();
|
|
33
|
-
expect((0, import_ip.extractIpAddress)(void 0)).toBeNull();
|
|
34
|
-
expect((0, import_ip.extractIpAddress)("invalid")).toBeNull();
|
|
35
|
-
expect((0, import_ip.extractIpAddress)("example.com")).toBeNull();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
//# sourceMappingURL=ip.test.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n\n expect(extractIpAddress('2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704')).toBe(\n '2404:7ac0:614d:bba7:cf41:992e:98e:9186'\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";;;AAAA,gBAAiC;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,eAAO,4BAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,eAAO,4BAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,eAAO,4BAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,eAAO,4BAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,eAAO,4BAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,eAAO,4BAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,eAAO,4BAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,eAAO,4BAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAEA,eAAO,4BAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,eAAO,4BAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,eAAO,4BAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// src/utils/__tests__/ip.test.ts
|
|
2
|
-
import { extractIpAddress } from "../ip.mjs";
|
|
3
|
-
describe("extractIpAddress", () => {
|
|
4
|
-
it("should extract the ipv4 address from the request", () => {
|
|
5
|
-
expect(extractIpAddress("127.0.0.1")).toBe("127.0.0.1");
|
|
6
|
-
expect(extractIpAddress("192.168.0.1")).toBe("192.168.0.1");
|
|
7
|
-
expect(extractIpAddress("127.0.0.1:8080")).toBe("127.0.0.1");
|
|
8
|
-
expect(extractIpAddress("192.168.0.1:8080")).toBe("192.168.0.1");
|
|
9
|
-
expect(extractIpAddress("127.0.0.1:8080/path")).toBe("127.0.0.1");
|
|
10
|
-
});
|
|
11
|
-
it("should extract the ipv6 address from the request", () => {
|
|
12
|
-
expect(extractIpAddress("::1")).toBe("::1");
|
|
13
|
-
expect(extractIpAddress("[::1]:8080")).toBe("::1");
|
|
14
|
-
expect(extractIpAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
|
|
15
|
-
"2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
|
16
|
-
);
|
|
17
|
-
expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
|
|
18
|
-
"2001:db8:85a3::8a2e:370:7334"
|
|
19
|
-
// remove leading zeros
|
|
20
|
-
);
|
|
21
|
-
expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
|
|
22
|
-
"2001:db8:85a3::8a2e:370:7334"
|
|
23
|
-
// remove leading zeros
|
|
24
|
-
);
|
|
25
|
-
expect(extractIpAddress("2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704")).toBe(
|
|
26
|
-
"2404:7ac0:614d:bba7:cf41:992e:98e:9186"
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
it("should return null if the ip address is not valid", () => {
|
|
30
|
-
expect(extractIpAddress(null)).toBeNull();
|
|
31
|
-
expect(extractIpAddress(void 0)).toBeNull();
|
|
32
|
-
expect(extractIpAddress("invalid")).toBeNull();
|
|
33
|
-
expect(extractIpAddress("example.com")).toBeNull();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
//# sourceMappingURL=ip.test.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n\n expect(extractIpAddress('2404:7ac0:614d:bba7:cf41:992e:98e:9186:60704')).toBe(\n '2404:7ac0:614d:bba7:cf41:992e:98e:9186'\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,WAAO,iBAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,WAAO,iBAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,WAAO,iBAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,WAAO,iBAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,WAAO,iBAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,WAAO,iBAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,WAAO,iBAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,WAAO,iBAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAEA,WAAO,iBAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,WAAO,iBAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,WAAO,iBAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","names":[]}
|
package/dist/utils/base62.cjs
DELETED
|
@@ -1,85 +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/utils/base62.ts
|
|
21
|
-
var base62_exports = {};
|
|
22
|
-
__export(base62_exports, {
|
|
23
|
-
base62: () => base62
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(base62_exports);
|
|
26
|
-
var base62 = {
|
|
27
|
-
encode: (buffer) => {
|
|
28
|
-
const base = 62n;
|
|
29
|
-
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
30
|
-
let leadingZeros = 0;
|
|
31
|
-
for (const byte of buffer) {
|
|
32
|
-
if (byte === 0) leadingZeros++;
|
|
33
|
-
else break;
|
|
34
|
-
}
|
|
35
|
-
let num = BigInt("0x" + buffer.toString("hex"));
|
|
36
|
-
if (num === 0n) return "0".repeat(buffer.length);
|
|
37
|
-
const chars = [];
|
|
38
|
-
while (num > 0n) {
|
|
39
|
-
const remainder = num % base;
|
|
40
|
-
chars.push(charset[Number(remainder)]);
|
|
41
|
-
num /= base;
|
|
42
|
-
}
|
|
43
|
-
return "0".repeat(leadingZeros) + chars.reverse().join("");
|
|
44
|
-
},
|
|
45
|
-
decode: (string, expectedLength) => {
|
|
46
|
-
const base = 62n;
|
|
47
|
-
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
48
|
-
let leadingZeros = 0;
|
|
49
|
-
for (const ch of string) {
|
|
50
|
-
if (ch === "0") leadingZeros++;
|
|
51
|
-
else break;
|
|
52
|
-
}
|
|
53
|
-
if (leadingZeros === string.length) {
|
|
54
|
-
return Buffer.alloc(expectedLength ?? leadingZeros);
|
|
55
|
-
}
|
|
56
|
-
let num = 0n;
|
|
57
|
-
for (let i = leadingZeros; i < string.length; i++) {
|
|
58
|
-
const ch = string[i];
|
|
59
|
-
const idx = charset.indexOf(ch);
|
|
60
|
-
if (idx === -1) {
|
|
61
|
-
throw new Error(`Invalid base62 character: ${ch}`);
|
|
62
|
-
}
|
|
63
|
-
num = num * base + BigInt(idx);
|
|
64
|
-
}
|
|
65
|
-
let hex = num.toString(16);
|
|
66
|
-
if (hex.length % 2 !== 0) hex = "0" + hex;
|
|
67
|
-
let buf = Buffer.from(hex, "hex");
|
|
68
|
-
if (leadingZeros > 0) {
|
|
69
|
-
buf = Buffer.concat([Buffer.alloc(leadingZeros), buf]);
|
|
70
|
-
}
|
|
71
|
-
if (expectedLength !== void 0) {
|
|
72
|
-
if (buf.length < expectedLength) {
|
|
73
|
-
buf = Buffer.concat([Buffer.alloc(expectedLength - buf.length), buf]);
|
|
74
|
-
} else if (buf.length > expectedLength) {
|
|
75
|
-
buf = buf.subarray(buf.length - expectedLength);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return buf;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
-
0 && (module.exports = {
|
|
83
|
-
base62
|
|
84
|
-
});
|
|
85
|
-
//# sourceMappingURL=base62.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/base62.ts"],"sourcesContent":["export const base62 = {\n encode: (buffer: Buffer): string => {\n const base = 62n;\n const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n let leadingZeros = 0;\n for (const byte of buffer) {\n if (byte === 0) leadingZeros++;\n else break;\n }\n\n let num = BigInt('0x' + buffer.toString('hex'));\n if (num === 0n) return '0'.repeat(buffer.length);\n\n const chars: string[] = [];\n while (num > 0n) {\n const remainder = num % base;\n chars.push(charset[Number(remainder)]!);\n num /= base;\n }\n\n return '0'.repeat(leadingZeros) + chars.reverse().join('');\n },\n decode: (string: string, expectedLength?: number): Buffer => {\n const base = 62n;\n const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\n let leadingZeros = 0;\n for (const ch of string) {\n if (ch === '0') leadingZeros++;\n else break;\n }\n\n if (leadingZeros === string.length) {\n return Buffer.alloc(expectedLength ?? leadingZeros);\n }\n\n let num = 0n;\n for (let i = leadingZeros; i < string.length; i++) {\n const ch = string[i];\n const idx = charset.indexOf(ch);\n if (idx === -1) {\n throw new Error(`Invalid base62 character: ${ch}`);\n }\n num = num * base + BigInt(idx);\n }\n\n let hex = num.toString(16);\n if (hex.length % 2 !== 0) hex = '0' + hex;\n let buf = Buffer.from(hex, 'hex');\n\n if (leadingZeros > 0) {\n buf = Buffer.concat([Buffer.alloc(leadingZeros), buf]);\n }\n\n if (expectedLength !== undefined) {\n if (buf.length < expectedLength) {\n buf = Buffer.concat([Buffer.alloc(expectedLength - buf.length), buf]);\n } else if (buf.length > expectedLength) {\n buf = buf.subarray(buf.length - expectedLength);\n }\n }\n\n return buf;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,SAAS;AAAA,EACpB,QAAQ,CAAC,WAA2B;AAClC,UAAM,OAAO;AACb,UAAM,UAAU;AAChB,QAAI,eAAe;AACnB,eAAW,QAAQ,QAAQ;AACzB,UAAI,SAAS,EAAG;AAAA,UACX;AAAA,IACP;AAEA,QAAI,MAAM,OAAO,OAAO,OAAO,SAAS,KAAK,CAAC;AAC9C,QAAI,QAAQ,GAAI,QAAO,IAAI,OAAO,OAAO,MAAM;AAE/C,UAAM,QAAkB,CAAC;AACzB,WAAO,MAAM,IAAI;AACf,YAAM,YAAY,MAAM;AACxB,YAAM,KAAK,QAAQ,OAAO,SAAS,CAAC,CAAE;AACtC,aAAO;AAAA,IACT;AAEA,WAAO,IAAI,OAAO,YAAY,IAAI,MAAM,QAAQ,EAAE,KAAK,EAAE;AAAA,EAC3D;AAAA,EACA,QAAQ,CAAC,QAAgB,mBAAoC;AAC3D,UAAM,OAAO;AACb,UAAM,UAAU;AAEhB,QAAI,eAAe;AACnB,eAAW,MAAM,QAAQ;AACvB,UAAI,OAAO,IAAK;AAAA,UACX;AAAA,IACP;AAEA,QAAI,iBAAiB,OAAO,QAAQ;AAClC,aAAO,OAAO,MAAM,kBAAkB,YAAY;AAAA,IACpD;AAEA,QAAI,MAAM;AACV,aAAS,IAAI,cAAc,IAAI,OAAO,QAAQ,KAAK;AACjD,YAAM,KAAK,OAAO,CAAC;AACnB,YAAM,MAAM,QAAQ,QAAQ,EAAE;AAC9B,UAAI,QAAQ,IAAI;AACd,cAAM,IAAI,MAAM,6BAA6B,EAAE,EAAE;AAAA,MACnD;AACA,YAAM,MAAM,OAAO,OAAO,GAAG;AAAA,IAC/B;AAEA,QAAI,MAAM,IAAI,SAAS,EAAE;AACzB,QAAI,IAAI,SAAS,MAAM,EAAG,OAAM,MAAM;AACtC,QAAI,MAAM,OAAO,KAAK,KAAK,KAAK;AAEhC,QAAI,eAAe,GAAG;AACpB,YAAM,OAAO,OAAO,CAAC,OAAO,MAAM,YAAY,GAAG,GAAG,CAAC;AAAA,IACvD;AAEA,QAAI,mBAAmB,QAAW;AAChC,UAAI,IAAI,SAAS,gBAAgB;AAC/B,cAAM,OAAO,OAAO,CAAC,OAAO,MAAM,iBAAiB,IAAI,MAAM,GAAG,GAAG,CAAC;AAAA,MACtE,WAAW,IAAI,SAAS,gBAAgB;AACtC,cAAM,IAAI,SAAS,IAAI,SAAS,cAAc;AAAA,MAChD;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/utils/base62.d.cts
DELETED
package/dist/utils/base62.d.ts
DELETED
package/dist/utils/base62.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/utils/base62.ts
|
|
2
|
-
var base62 = {
|
|
3
|
-
encode: (buffer) => {
|
|
4
|
-
const base = 62n;
|
|
5
|
-
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6
|
-
let leadingZeros = 0;
|
|
7
|
-
for (const byte of buffer) {
|
|
8
|
-
if (byte === 0) leadingZeros++;
|
|
9
|
-
else break;
|
|
10
|
-
}
|
|
11
|
-
let num = BigInt("0x" + buffer.toString("hex"));
|
|
12
|
-
if (num === 0n) return "0".repeat(buffer.length);
|
|
13
|
-
const chars = [];
|
|
14
|
-
while (num > 0n) {
|
|
15
|
-
const remainder = num % base;
|
|
16
|
-
chars.push(charset[Number(remainder)]);
|
|
17
|
-
num /= base;
|
|
18
|
-
}
|
|
19
|
-
return "0".repeat(leadingZeros) + chars.reverse().join("");
|
|
20
|
-
},
|
|
21
|
-
decode: (string, expectedLength) => {
|
|
22
|
-
const base = 62n;
|
|
23
|
-
const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
24
|
-
let leadingZeros = 0;
|
|
25
|
-
for (const ch of string) {
|
|
26
|
-
if (ch === "0") leadingZeros++;
|
|
27
|
-
else break;
|
|
28
|
-
}
|
|
29
|
-
if (leadingZeros === string.length) {
|
|
30
|
-
return Buffer.alloc(expectedLength ?? leadingZeros);
|
|
31
|
-
}
|
|
32
|
-
let num = 0n;
|
|
33
|
-
for (let i = leadingZeros; i < string.length; i++) {
|
|
34
|
-
const ch = string[i];
|
|
35
|
-
const idx = charset.indexOf(ch);
|
|
36
|
-
if (idx === -1) {
|
|
37
|
-
throw new Error(`Invalid base62 character: ${ch}`);
|
|
38
|
-
}
|
|
39
|
-
num = num * base + BigInt(idx);
|
|
40
|
-
}
|
|
41
|
-
let hex = num.toString(16);
|
|
42
|
-
if (hex.length % 2 !== 0) hex = "0" + hex;
|
|
43
|
-
let buf = Buffer.from(hex, "hex");
|
|
44
|
-
if (leadingZeros > 0) {
|
|
45
|
-
buf = Buffer.concat([Buffer.alloc(leadingZeros), buf]);
|
|
46
|
-
}
|
|
47
|
-
if (expectedLength !== void 0) {
|
|
48
|
-
if (buf.length < expectedLength) {
|
|
49
|
-
buf = Buffer.concat([Buffer.alloc(expectedLength - buf.length), buf]);
|
|
50
|
-
} else if (buf.length > expectedLength) {
|
|
51
|
-
buf = buf.subarray(buf.length - expectedLength);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return buf;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
export {
|
|
58
|
-
base62
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=base62.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/base62.ts"],"sourcesContent":["export const base62 = {\n encode: (buffer: Buffer): string => {\n const base = 62n;\n const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n let leadingZeros = 0;\n for (const byte of buffer) {\n if (byte === 0) leadingZeros++;\n else break;\n }\n\n let num = BigInt('0x' + buffer.toString('hex'));\n if (num === 0n) return '0'.repeat(buffer.length);\n\n const chars: string[] = [];\n while (num > 0n) {\n const remainder = num % base;\n chars.push(charset[Number(remainder)]!);\n num /= base;\n }\n\n return '0'.repeat(leadingZeros) + chars.reverse().join('');\n },\n decode: (string: string, expectedLength?: number): Buffer => {\n const base = 62n;\n const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\n let leadingZeros = 0;\n for (const ch of string) {\n if (ch === '0') leadingZeros++;\n else break;\n }\n\n if (leadingZeros === string.length) {\n return Buffer.alloc(expectedLength ?? leadingZeros);\n }\n\n let num = 0n;\n for (let i = leadingZeros; i < string.length; i++) {\n const ch = string[i];\n const idx = charset.indexOf(ch);\n if (idx === -1) {\n throw new Error(`Invalid base62 character: ${ch}`);\n }\n num = num * base + BigInt(idx);\n }\n\n let hex = num.toString(16);\n if (hex.length % 2 !== 0) hex = '0' + hex;\n let buf = Buffer.from(hex, 'hex');\n\n if (leadingZeros > 0) {\n buf = Buffer.concat([Buffer.alloc(leadingZeros), buf]);\n }\n\n if (expectedLength !== undefined) {\n if (buf.length < expectedLength) {\n buf = Buffer.concat([Buffer.alloc(expectedLength - buf.length), buf]);\n } else if (buf.length > expectedLength) {\n buf = buf.subarray(buf.length - expectedLength);\n }\n }\n\n return buf;\n },\n};\n"],"mappings":";AAAO,IAAM,SAAS;AAAA,EACpB,QAAQ,CAAC,WAA2B;AAClC,UAAM,OAAO;AACb,UAAM,UAAU;AAChB,QAAI,eAAe;AACnB,eAAW,QAAQ,QAAQ;AACzB,UAAI,SAAS,EAAG;AAAA,UACX;AAAA,IACP;AAEA,QAAI,MAAM,OAAO,OAAO,OAAO,SAAS,KAAK,CAAC;AAC9C,QAAI,QAAQ,GAAI,QAAO,IAAI,OAAO,OAAO,MAAM;AAE/C,UAAM,QAAkB,CAAC;AACzB,WAAO,MAAM,IAAI;AACf,YAAM,YAAY,MAAM;AACxB,YAAM,KAAK,QAAQ,OAAO,SAAS,CAAC,CAAE;AACtC,aAAO;AAAA,IACT;AAEA,WAAO,IAAI,OAAO,YAAY,IAAI,MAAM,QAAQ,EAAE,KAAK,EAAE;AAAA,EAC3D;AAAA,EACA,QAAQ,CAAC,QAAgB,mBAAoC;AAC3D,UAAM,OAAO;AACb,UAAM,UAAU;AAEhB,QAAI,eAAe;AACnB,eAAW,MAAM,QAAQ;AACvB,UAAI,OAAO,IAAK;AAAA,UACX;AAAA,IACP;AAEA,QAAI,iBAAiB,OAAO,QAAQ;AAClC,aAAO,OAAO,MAAM,kBAAkB,YAAY;AAAA,IACpD;AAEA,QAAI,MAAM;AACV,aAAS,IAAI,cAAc,IAAI,OAAO,QAAQ,KAAK;AACjD,YAAM,KAAK,OAAO,CAAC;AACnB,YAAM,MAAM,QAAQ,QAAQ,EAAE;AAC9B,UAAI,QAAQ,IAAI;AACd,cAAM,IAAI,MAAM,6BAA6B,EAAE,EAAE;AAAA,MACnD;AACA,YAAM,MAAM,OAAO,OAAO,GAAG;AAAA,IAC/B;AAEA,QAAI,MAAM,IAAI,SAAS,EAAE;AACzB,QAAI,IAAI,SAAS,MAAM,EAAG,OAAM,MAAM;AACtC,QAAI,MAAM,OAAO,KAAK,KAAK,KAAK;AAEhC,QAAI,eAAe,GAAG;AACpB,YAAM,OAAO,OAAO,CAAC,OAAO,MAAM,YAAY,GAAG,GAAG,CAAC;AAAA,IACvD;AAEA,QAAI,mBAAmB,QAAW;AAChC,UAAI,IAAI,SAAS,gBAAgB;AAC/B,cAAM,OAAO,OAAO,CAAC,OAAO,MAAM,iBAAiB,IAAI,MAAM,GAAG,GAAG,CAAC;AAAA,MACtE,WAAW,IAAI,SAAS,gBAAgB;AACtC,cAAM,IAAI,SAAS,IAAI,SAAS,cAAc;AAAA,MAChD;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/utils/fetch.cjs
DELETED
|
@@ -1,78 +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/utils/fetch.ts
|
|
21
|
-
var fetch_exports = {};
|
|
22
|
-
__export(fetch_exports, {
|
|
23
|
-
fetch: () => fetch
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(fetch_exports);
|
|
26
|
-
function defaultRetryCondition(response) {
|
|
27
|
-
return response.status === 408 || response.status === 429 || response.status >= 500;
|
|
28
|
-
}
|
|
29
|
-
function parseRetryAfter(response) {
|
|
30
|
-
if (!response) return null;
|
|
31
|
-
const header = response.headers.get("retry-after");
|
|
32
|
-
if (!header) return null;
|
|
33
|
-
const seconds = Number(header);
|
|
34
|
-
if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
|
|
35
|
-
const dateMs = Date.parse(header);
|
|
36
|
-
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
async function fetch(input, {
|
|
40
|
-
retries = 3,
|
|
41
|
-
delayFactor = 500,
|
|
42
|
-
maxDelay = 3e4,
|
|
43
|
-
retryCondition = defaultRetryCondition,
|
|
44
|
-
...init
|
|
45
|
-
} = {}) {
|
|
46
|
-
let retryCount = 0;
|
|
47
|
-
let lastError = null;
|
|
48
|
-
let lastResponse = null;
|
|
49
|
-
while (retryCount <= retries) {
|
|
50
|
-
try {
|
|
51
|
-
const response = await globalThis.fetch(input, init);
|
|
52
|
-
lastResponse = response;
|
|
53
|
-
if (response.ok || !retryCondition(response) || retryCount === retries) {
|
|
54
|
-
return response;
|
|
55
|
-
}
|
|
56
|
-
const retryAfter = parseRetryAfter(response);
|
|
57
|
-
const delay = delayFactor * Math.pow(2, retryCount);
|
|
58
|
-
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
59
|
-
const timeout = Math.min(retryAfter ?? delay + jitter, maxDelay);
|
|
60
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
61
|
-
} catch (error) {
|
|
62
|
-
lastError = error;
|
|
63
|
-
if (retryCount === retries) throw error;
|
|
64
|
-
const delay = delayFactor * Math.pow(2, retryCount);
|
|
65
|
-
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
66
|
-
const timeout = Math.min(delay + jitter, maxDelay);
|
|
67
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
68
|
-
}
|
|
69
|
-
retryCount++;
|
|
70
|
-
}
|
|
71
|
-
if (lastResponse) return lastResponse;
|
|
72
|
-
throw lastError ?? new Error("Fetch failed");
|
|
73
|
-
}
|
|
74
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
-
0 && (module.exports = {
|
|
76
|
-
fetch
|
|
77
|
-
});
|
|
78
|
-
//# sourceMappingURL=fetch.cjs.map
|
package/dist/utils/fetch.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["export interface RetryOptions {\n /** The number of times to retry before failing, default: 3 */\n retries?: number;\n\n /** The delay factor in milliseconds, default: 500 */\n delayFactor?: number;\n\n /** The maximum delay in milliseconds, default: 30_000 (30s) */\n maxDelay?: number;\n\n /**\n * A callback to further control if a request should be retried.\n * default: 408 (Request Timeout) or 429 (Too Many Requests) or 5xx (Server Error).\n */\n retryCondition?: (response: Response) => boolean;\n}\n\nfunction defaultRetryCondition(response: Response): boolean {\n return response.status === 408 || response.status === 429 || response.status >= 500;\n}\n\nfunction parseRetryAfter(response: Response | null): number | null {\n if (!response) return null;\n const header = response.headers.get('retry-after');\n if (!header) return null;\n\n // if the retry after header is a number, convert it to milliseconds\n const seconds = Number(header);\n if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1000);\n\n // if the retry after header is a date, get the number of milliseconds until that date\n const dateMs = Date.parse(header);\n if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());\n\n return null;\n}\n\nexport async function fetch(\n input: RequestInfo,\n {\n retries = 3,\n delayFactor = 500,\n maxDelay = 30_000,\n retryCondition = defaultRetryCondition,\n ...init\n }: RequestInit & RetryOptions = {}\n): Promise<Response> {\n let retryCount = 0;\n let lastError: unknown | null = null;\n let lastResponse: Response | null = null;\n\n while (retryCount <= retries) {\n try {\n const response = await globalThis.fetch(input, init);\n lastResponse = response;\n if (response.ok || !retryCondition(response) || retryCount === retries) {\n return response;\n }\n\n const retryAfter = parseRetryAfter(response);\n const delay = delayFactor * Math.pow(2, retryCount);\n const jitter = delay * 0.25 * (Math.random() * 2 - 1); // 25% jitter\n\n const timeout = Math.min(retryAfter ?? delay + jitter, maxDelay);\n await new Promise((resolve) => setTimeout(resolve, timeout));\n } catch (error) {\n lastError = error;\n if (retryCount === retries) throw error;\n\n const delay = delayFactor * Math.pow(2, retryCount);\n const jitter = delay * 0.25 * (Math.random() * 2 - 1); // 25% jitter\n\n const timeout = Math.min(delay + jitter, maxDelay);\n await new Promise((resolve) => setTimeout(resolve, timeout));\n }\n\n retryCount++;\n }\n\n if (lastResponse) return lastResponse;\n throw lastError ?? new Error('Fetch failed');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,SAAS,sBAAsB,UAA6B;AAC1D,SAAO,SAAS,WAAW,OAAO,SAAS,WAAW,OAAO,SAAS,UAAU;AAClF;AAEA,SAAS,gBAAgB,UAA0C;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,SAAS,SAAS,QAAQ,IAAI,aAAa;AACjD,MAAI,CAAC,OAAQ,QAAO;AAGpB,QAAM,UAAU,OAAO,MAAM;AAC7B,MAAI,CAAC,OAAO,MAAM,OAAO,EAAG,QAAO,KAAK,IAAI,GAAG,UAAU,GAAI;AAG7D,QAAM,SAAS,KAAK,MAAM,MAAM;AAChC,MAAI,CAAC,OAAO,MAAM,MAAM,EAAG,QAAO,KAAK,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;AAEjE,SAAO;AACT;AAEA,eAAsB,MACpB,OACA;AAAA,EACE,UAAU;AAAA,EACV,cAAc;AAAA,EACd,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,GAAG;AACL,IAAgC,CAAC,GACd;AACnB,MAAI,aAAa;AACjB,MAAI,YAA4B;AAChC,MAAI,eAAgC;AAEpC,SAAO,cAAc,SAAS;AAC5B,QAAI;AACF,YAAM,WAAW,MAAM,WAAW,MAAM,OAAO,IAAI;AACnD,qBAAe;AACf,UAAI,SAAS,MAAM,CAAC,eAAe,QAAQ,KAAK,eAAe,SAAS;AACtE,eAAO;AAAA,MACT;AAEA,YAAM,aAAa,gBAAgB,QAAQ;AAC3C,YAAM,QAAQ,cAAc,KAAK,IAAI,GAAG,UAAU;AAClD,YAAM,SAAS,QAAQ,QAAQ,KAAK,OAAO,IAAI,IAAI;AAEnD,YAAM,UAAU,KAAK,IAAI,cAAc,QAAQ,QAAQ,QAAQ;AAC/D,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,OAAO,CAAC;AAAA,IAC7D,SAAS,OAAO;AACd,kBAAY;AACZ,UAAI,eAAe,QAAS,OAAM;AAElC,YAAM,QAAQ,cAAc,KAAK,IAAI,GAAG,UAAU;AAClD,YAAM,SAAS,QAAQ,QAAQ,KAAK,OAAO,IAAI,IAAI;AAEnD,YAAM,UAAU,KAAK,IAAI,QAAQ,QAAQ,QAAQ;AACjD,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,OAAO,CAAC;AAAA,IAC7D;AAEA;AAAA,EACF;AAEA,MAAI,aAAc,QAAO;AACzB,QAAM,aAAa,IAAI,MAAM,cAAc;AAC7C;","names":[]}
|
package/dist/utils/fetch.d.cts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface RetryOptions {
|
|
2
|
-
/** The number of times to retry before failing, default: 3 */
|
|
3
|
-
retries?: number;
|
|
4
|
-
/** The delay factor in milliseconds, default: 500 */
|
|
5
|
-
delayFactor?: number;
|
|
6
|
-
/** The maximum delay in milliseconds, default: 30_000 (30s) */
|
|
7
|
-
maxDelay?: number;
|
|
8
|
-
/**
|
|
9
|
-
* A callback to further control if a request should be retried.
|
|
10
|
-
* default: 408 (Request Timeout) or 429 (Too Many Requests) or 5xx (Server Error).
|
|
11
|
-
*/
|
|
12
|
-
retryCondition?: (response: Response) => boolean;
|
|
13
|
-
}
|
|
14
|
-
declare function fetch(input: RequestInfo, { retries, delayFactor, maxDelay, retryCondition, ...init }?: RequestInit & RetryOptions): Promise<Response>;
|
|
15
|
-
|
|
16
|
-
export { type RetryOptions, fetch };
|
package/dist/utils/fetch.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface RetryOptions {
|
|
2
|
-
/** The number of times to retry before failing, default: 3 */
|
|
3
|
-
retries?: number;
|
|
4
|
-
/** The delay factor in milliseconds, default: 500 */
|
|
5
|
-
delayFactor?: number;
|
|
6
|
-
/** The maximum delay in milliseconds, default: 30_000 (30s) */
|
|
7
|
-
maxDelay?: number;
|
|
8
|
-
/**
|
|
9
|
-
* A callback to further control if a request should be retried.
|
|
10
|
-
* default: 408 (Request Timeout) or 429 (Too Many Requests) or 5xx (Server Error).
|
|
11
|
-
*/
|
|
12
|
-
retryCondition?: (response: Response) => boolean;
|
|
13
|
-
}
|
|
14
|
-
declare function fetch(input: RequestInfo, { retries, delayFactor, maxDelay, retryCondition, ...init }?: RequestInit & RetryOptions): Promise<Response>;
|
|
15
|
-
|
|
16
|
-
export { type RetryOptions, fetch };
|
package/dist/utils/fetch.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/utils/fetch.ts
|
|
2
|
-
function defaultRetryCondition(response) {
|
|
3
|
-
return response.status === 408 || response.status === 429 || response.status >= 500;
|
|
4
|
-
}
|
|
5
|
-
function parseRetryAfter(response) {
|
|
6
|
-
if (!response) return null;
|
|
7
|
-
const header = response.headers.get("retry-after");
|
|
8
|
-
if (!header) return null;
|
|
9
|
-
const seconds = Number(header);
|
|
10
|
-
if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
|
|
11
|
-
const dateMs = Date.parse(header);
|
|
12
|
-
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
async function fetch(input, {
|
|
16
|
-
retries = 3,
|
|
17
|
-
delayFactor = 500,
|
|
18
|
-
maxDelay = 3e4,
|
|
19
|
-
retryCondition = defaultRetryCondition,
|
|
20
|
-
...init
|
|
21
|
-
} = {}) {
|
|
22
|
-
let retryCount = 0;
|
|
23
|
-
let lastError = null;
|
|
24
|
-
let lastResponse = null;
|
|
25
|
-
while (retryCount <= retries) {
|
|
26
|
-
try {
|
|
27
|
-
const response = await globalThis.fetch(input, init);
|
|
28
|
-
lastResponse = response;
|
|
29
|
-
if (response.ok || !retryCondition(response) || retryCount === retries) {
|
|
30
|
-
return response;
|
|
31
|
-
}
|
|
32
|
-
const retryAfter = parseRetryAfter(response);
|
|
33
|
-
const delay = delayFactor * Math.pow(2, retryCount);
|
|
34
|
-
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
35
|
-
const timeout = Math.min(retryAfter ?? delay + jitter, maxDelay);
|
|
36
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
37
|
-
} catch (error) {
|
|
38
|
-
lastError = error;
|
|
39
|
-
if (retryCount === retries) throw error;
|
|
40
|
-
const delay = delayFactor * Math.pow(2, retryCount);
|
|
41
|
-
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
42
|
-
const timeout = Math.min(delay + jitter, maxDelay);
|
|
43
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
44
|
-
}
|
|
45
|
-
retryCount++;
|
|
46
|
-
}
|
|
47
|
-
if (lastResponse) return lastResponse;
|
|
48
|
-
throw lastError ?? new Error("Fetch failed");
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
fetch
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=fetch.mjs.map
|
package/dist/utils/fetch.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["export interface RetryOptions {\n /** The number of times to retry before failing, default: 3 */\n retries?: number;\n\n /** The delay factor in milliseconds, default: 500 */\n delayFactor?: number;\n\n /** The maximum delay in milliseconds, default: 30_000 (30s) */\n maxDelay?: number;\n\n /**\n * A callback to further control if a request should be retried.\n * default: 408 (Request Timeout) or 429 (Too Many Requests) or 5xx (Server Error).\n */\n retryCondition?: (response: Response) => boolean;\n}\n\nfunction defaultRetryCondition(response: Response): boolean {\n return response.status === 408 || response.status === 429 || response.status >= 500;\n}\n\nfunction parseRetryAfter(response: Response | null): number | null {\n if (!response) return null;\n const header = response.headers.get('retry-after');\n if (!header) return null;\n\n // if the retry after header is a number, convert it to milliseconds\n const seconds = Number(header);\n if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1000);\n\n // if the retry after header is a date, get the number of milliseconds until that date\n const dateMs = Date.parse(header);\n if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());\n\n return null;\n}\n\nexport async function fetch(\n input: RequestInfo,\n {\n retries = 3,\n delayFactor = 500,\n maxDelay = 30_000,\n retryCondition = defaultRetryCondition,\n ...init\n }: RequestInit & RetryOptions = {}\n): Promise<Response> {\n let retryCount = 0;\n let lastError: unknown | null = null;\n let lastResponse: Response | null = null;\n\n while (retryCount <= retries) {\n try {\n const response = await globalThis.fetch(input, init);\n lastResponse = response;\n if (response.ok || !retryCondition(response) || retryCount === retries) {\n return response;\n }\n\n const retryAfter = parseRetryAfter(response);\n const delay = delayFactor * Math.pow(2, retryCount);\n const jitter = delay * 0.25 * (Math.random() * 2 - 1); // 25% jitter\n\n const timeout = Math.min(retryAfter ?? delay + jitter, maxDelay);\n await new Promise((resolve) => setTimeout(resolve, timeout));\n } catch (error) {\n lastError = error;\n if (retryCount === retries) throw error;\n\n const delay = delayFactor * Math.pow(2, retryCount);\n const jitter = delay * 0.25 * (Math.random() * 2 - 1); // 25% jitter\n\n const timeout = Math.min(delay + jitter, maxDelay);\n await new Promise((resolve) => setTimeout(resolve, timeout));\n }\n\n retryCount++;\n }\n\n if (lastResponse) return lastResponse;\n throw lastError ?? new Error('Fetch failed');\n}\n"],"mappings":";AAiBA,SAAS,sBAAsB,UAA6B;AAC1D,SAAO,SAAS,WAAW,OAAO,SAAS,WAAW,OAAO,SAAS,UAAU;AAClF;AAEA,SAAS,gBAAgB,UAA0C;AACjE,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,SAAS,SAAS,QAAQ,IAAI,aAAa;AACjD,MAAI,CAAC,OAAQ,QAAO;AAGpB,QAAM,UAAU,OAAO,MAAM;AAC7B,MAAI,CAAC,OAAO,MAAM,OAAO,EAAG,QAAO,KAAK,IAAI,GAAG,UAAU,GAAI;AAG7D,QAAM,SAAS,KAAK,MAAM,MAAM;AAChC,MAAI,CAAC,OAAO,MAAM,MAAM,EAAG,QAAO,KAAK,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;AAEjE,SAAO;AACT;AAEA,eAAsB,MACpB,OACA;AAAA,EACE,UAAU;AAAA,EACV,cAAc;AAAA,EACd,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,GAAG;AACL,IAAgC,CAAC,GACd;AACnB,MAAI,aAAa;AACjB,MAAI,YAA4B;AAChC,MAAI,eAAgC;AAEpC,SAAO,cAAc,SAAS;AAC5B,QAAI;AACF,YAAM,WAAW,MAAM,WAAW,MAAM,OAAO,IAAI;AACnD,qBAAe;AACf,UAAI,SAAS,MAAM,CAAC,eAAe,QAAQ,KAAK,eAAe,SAAS;AACtE,eAAO;AAAA,MACT;AAEA,YAAM,aAAa,gBAAgB,QAAQ;AAC3C,YAAM,QAAQ,cAAc,KAAK,IAAI,GAAG,UAAU;AAClD,YAAM,SAAS,QAAQ,QAAQ,KAAK,OAAO,IAAI,IAAI;AAEnD,YAAM,UAAU,KAAK,IAAI,cAAc,QAAQ,QAAQ,QAAQ;AAC/D,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,OAAO,CAAC;AAAA,IAC7D,SAAS,OAAO;AACd,kBAAY;AACZ,UAAI,eAAe,QAAS,OAAM;AAElC,YAAM,QAAQ,cAAc,KAAK,IAAI,GAAG,UAAU;AAClD,YAAM,SAAS,QAAQ,QAAQ,KAAK,OAAO,IAAI,IAAI;AAEnD,YAAM,UAAU,KAAK,IAAI,QAAQ,QAAQ,QAAQ;AACjD,YAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,OAAO,CAAC;AAAA,IAC7D;AAEA;AAAA,EACF;AAEA,MAAI,aAAc,QAAO;AACzB,QAAM,aAAa,IAAI,MAAM,cAAc;AAC7C;","names":[]}
|
package/dist/utils/invariant.cjs
DELETED
|
@@ -1,37 +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/utils/invariant.ts
|
|
21
|
-
var invariant_exports = {};
|
|
22
|
-
__export(invariant_exports, {
|
|
23
|
-
invariant: () => invariant
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(invariant_exports);
|
|
26
|
-
var prefix = "Invariant failed";
|
|
27
|
-
function invariant(condition, message) {
|
|
28
|
-
if (condition) return;
|
|
29
|
-
const provided = typeof message === "function" ? message() : message;
|
|
30
|
-
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
31
|
-
throw new Error(value);
|
|
32
|
-
}
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
invariant
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=invariant.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/invariant.ts"],"sourcesContent":["const prefix = 'Invariant failed';\n\nexport function invariant(\n condition: unknown,\n message?: string | (() => string)\n): asserts condition {\n if (condition) return;\n const provided: string | undefined = typeof message === 'function' ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,SAAS;AAER,SAAS,UACd,WACA,SACmB;AACnB,MAAI,UAAW;AACf,QAAM,WAA+B,OAAO,YAAY,aAAa,QAAQ,IAAI;AACjF,QAAM,QAAgB,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK;AAC5D,QAAM,IAAI,MAAM,KAAK;AACvB;","names":[]}
|
package/dist/utils/invariant.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/utils/invariant.ts
|
|
2
|
-
var prefix = "Invariant failed";
|
|
3
|
-
function invariant(condition, message) {
|
|
4
|
-
if (condition) return;
|
|
5
|
-
const provided = typeof message === "function" ? message() : message;
|
|
6
|
-
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
7
|
-
throw new Error(value);
|
|
8
|
-
}
|
|
9
|
-
export {
|
|
10
|
-
invariant
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=invariant.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/invariant.ts"],"sourcesContent":["const prefix = 'Invariant failed';\n\nexport function invariant(\n condition: unknown,\n message?: string | (() => string)\n): asserts condition {\n if (condition) return;\n const provided: string | undefined = typeof message === 'function' ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"mappings":";AAAA,IAAM,SAAS;AAER,SAAS,UACd,WACA,SACmB;AACnB,MAAI,UAAW;AACf,QAAM,WAA+B,OAAO,YAAY,aAAa,QAAQ,IAAI;AACjF,QAAM,QAAgB,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK;AAC5D,QAAM,IAAI,MAAM,KAAK;AACvB;","names":[]}
|