@solana/rpc-spec-types 2.0.0-rc.0 → 2.0.0-rc.2
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 +25 -4
- package/dist/index.browser.cjs +78 -3
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +77 -4
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +77 -4
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +78 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +77 -4
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/parse-json-with-bigints.d.ts +7 -0
- package/dist/types/parse-json-with-bigints.d.ts.map +1 -0
- package/dist/types/rpc-message.d.ts +2 -1
- package/dist/types/rpc-message.d.ts.map +1 -1
- package/dist/types/rpc-request.d.ts +8 -0
- package/dist/types/rpc-request.d.ts.map +1 -0
- package/dist/types/rpc-response.d.ts +8 -3
- package/dist/types/rpc-response.d.ts.map +1 -1
- package/dist/types/stringify-json-with-bigints.d.ts +5 -0
- package/dist/types/stringify-json-with-bigints.d.ts.map +1 -0
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -6,12 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
8
|
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
-
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/rpc-spec-types/
|
|
10
|
-
[npm-image]: https://img.shields.io/npm/v/@solana/rpc-spec-types/
|
|
11
|
-
[npm-url]: https://www.npmjs.com/package/@solana/rpc-spec-types/v/
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/rpc-spec-types/rc.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/rpc-spec-types/rc.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/rpc-spec-types/v/rc
|
|
12
12
|
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
13
|
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
14
|
|
|
15
15
|
# @solana/rpc-spec-types
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
This package contains core types that can be used on both RPC and RPC Subscriptions specifications. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@rc`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
|
|
18
|
+
|
|
19
|
+
## Types
|
|
20
|
+
|
|
21
|
+
### `RpcRequest`
|
|
22
|
+
|
|
23
|
+
An object that describes the elements of an RPC or RPC Subscriptions request. It consists of the following properties:
|
|
24
|
+
|
|
25
|
+
- `methodName`: The name of the RPC method or subscription requested.
|
|
26
|
+
- `params`: The parameters to be passed to the RPC server.
|
|
27
|
+
|
|
28
|
+
### `RpcRequestTransformer`
|
|
29
|
+
|
|
30
|
+
A function that accepts an `RpcRequest` and returns another `RpcRequest`. This allows the `RpcApi` to transform the request before it is sent to the RPC server.
|
|
31
|
+
|
|
32
|
+
### `RpcResponse`
|
|
33
|
+
|
|
34
|
+
A type that represents the response from an RPC server. This could be any sort of data which is why `RpcResponse` defaults to `unknown`. You may use a type parameter to specify the shape of the response — e.g. `RpcResponse<{ result: number }>`.
|
|
35
|
+
|
|
36
|
+
### `RpcResponseTransformer`
|
|
37
|
+
|
|
38
|
+
A function that accepts an `RpcResponse` and returns another `RpcResponse`. This allows the `RpcApi` to transform the response before it is returned to the caller.
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/parse-json-with-bigints.ts
|
|
4
|
+
function parseJsonWithBigInts(json) {
|
|
5
|
+
return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {
|
|
6
|
+
return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function wrapIntegersInBigIntValueObject(json) {
|
|
10
|
+
const out = [];
|
|
11
|
+
let inQuote = false;
|
|
12
|
+
for (let ii = 0; ii < json.length; ii++) {
|
|
13
|
+
let isEscaped = false;
|
|
14
|
+
if (json[ii] === "\\") {
|
|
15
|
+
out.push(json[ii++]);
|
|
16
|
+
isEscaped = !isEscaped;
|
|
17
|
+
}
|
|
18
|
+
if (json[ii] === '"') {
|
|
19
|
+
out.push(json[ii]);
|
|
20
|
+
if (!isEscaped) {
|
|
21
|
+
inQuote = !inQuote;
|
|
22
|
+
}
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!inQuote) {
|
|
26
|
+
const consumedNumber = consumeNumber(json, ii);
|
|
27
|
+
if (consumedNumber?.length) {
|
|
28
|
+
ii += consumedNumber.length - 1;
|
|
29
|
+
if (consumedNumber.match(/\.|[eE]-/)) {
|
|
30
|
+
out.push(consumedNumber);
|
|
31
|
+
} else {
|
|
32
|
+
out.push(wrapBigIntValueObject(consumedNumber));
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
out.push(json[ii]);
|
|
38
|
+
}
|
|
39
|
+
return out.join("");
|
|
40
|
+
}
|
|
41
|
+
function consumeNumber(json, ii) {
|
|
42
|
+
const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
43
|
+
if (!json[ii]?.match(/[-\d]/)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);
|
|
47
|
+
return numberMatch ? numberMatch[0] : null;
|
|
48
|
+
}
|
|
49
|
+
function wrapBigIntValueObject(value) {
|
|
50
|
+
return `{"$n":"${value}"}`;
|
|
51
|
+
}
|
|
52
|
+
function unwrapBigIntValueObject({ $n }) {
|
|
53
|
+
if ($n.match(/[eE]/)) {
|
|
54
|
+
const [units, exponent] = $n.split(/[eE]/);
|
|
55
|
+
return BigInt(units) * BigInt(10) ** BigInt(exponent);
|
|
56
|
+
}
|
|
57
|
+
return BigInt($n);
|
|
58
|
+
}
|
|
59
|
+
function isBigIntValueObject(value) {
|
|
60
|
+
return !!value && typeof value === "object" && "$n" in value && typeof value.$n === "string";
|
|
61
|
+
}
|
|
62
|
+
|
|
3
63
|
// src/rpc-message.ts
|
|
4
64
|
var _nextMessageId = 0;
|
|
5
65
|
function getNextMessageId() {
|
|
@@ -7,15 +67,30 @@ function getNextMessageId() {
|
|
|
7
67
|
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
8
68
|
return id;
|
|
9
69
|
}
|
|
10
|
-
function createRpcMessage(
|
|
70
|
+
function createRpcMessage(request) {
|
|
11
71
|
return {
|
|
12
72
|
id: getNextMessageId(),
|
|
13
73
|
jsonrpc: "2.0",
|
|
14
|
-
method,
|
|
15
|
-
params
|
|
74
|
+
method: request.methodName,
|
|
75
|
+
params: request.params
|
|
16
76
|
};
|
|
17
77
|
}
|
|
18
78
|
|
|
79
|
+
// src/stringify-json-with-bigints.ts
|
|
80
|
+
function stringifyJsonWithBigints(value, space) {
|
|
81
|
+
return unwrapBigIntValueObject2(
|
|
82
|
+
JSON.stringify(value, (_, v) => typeof v === "bigint" ? wrapBigIntValueObject2(v) : v, space)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function wrapBigIntValueObject2(value) {
|
|
86
|
+
return { $n: `${value}` };
|
|
87
|
+
}
|
|
88
|
+
function unwrapBigIntValueObject2(value) {
|
|
89
|
+
return value.replace(/\{\s*"\$n"\s*:\s*"(-?\d+)"\s*\}/g, "$1");
|
|
90
|
+
}
|
|
91
|
+
|
|
19
92
|
exports.createRpcMessage = createRpcMessage;
|
|
93
|
+
exports.parseJsonWithBigInts = parseJsonWithBigInts;
|
|
94
|
+
exports.stringifyJsonWithBigints = stringifyJsonWithBigints;
|
|
20
95
|
//# sourceMappingURL=index.browser.cjs.map
|
|
21
96
|
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rpc-message.ts"],"names":[],"mappings":";;;AAAA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/parse-json-with-bigints.ts","../src/rpc-message.ts","../src/stringify-json-with-bigints.ts"],"names":["unwrapBigIntValueObject","wrapBigIntValueObject"],"mappings":";;;AAKO,SAAS,qBAAqB,IAAuB,EAAA;AACxD,EAAA,OAAO,KAAK,KAAM,CAAA,+BAAA,CAAgC,IAAI,CAAG,EAAA,CAAC,GAAG,KAAU,KAAA;AACnE,IAAA,OAAO,mBAAoB,CAAA,KAAK,CAAI,GAAA,uBAAA,CAAwB,KAAK,CAAI,GAAA,KAAA,CAAA;AAAA,GACxE,CAAA,CAAA;AACL,CAAA;AAEA,SAAS,gCAAgC,IAAsB,EAAA;AAC3D,EAAA,MAAM,MAAM,EAAC,CAAA;AACb,EAAA,IAAI,OAAU,GAAA,KAAA,CAAA;AACd,EAAA,KAAA,IAAS,EAAK,GAAA,CAAA,EAAG,EAAK,GAAA,IAAA,CAAK,QAAQ,EAAM,EAAA,EAAA;AACrC,IAAA,IAAI,SAAY,GAAA,KAAA,CAAA;AAChB,IAAI,IAAA,IAAA,CAAK,EAAE,CAAA,KAAM,IAAM,EAAA;AACnB,MAAI,GAAA,CAAA,IAAA,CAAK,IAAK,CAAA,EAAA,EAAI,CAAC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A,OAAAA,wBAAAA;AAAA,IACH,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,CAAC,CAAG,EAAA,CAAA,KAAO,OAAO,CAAA,KAAM,QAAWC,GAAAA,sBAAAA,CAAsB,CAAC,CAAA,GAAI,GAAI,KAAK,CAAA;AAAA,GACjG,CAAA;AACJ,CAAA;AAQA,SAASA,uBAAsB,KAAkC,EAAA;AAC7D,EAAA,OAAO,EAAE,EAAA,EAAI,CAAG,EAAA,KAAK,CAAG,CAAA,EAAA,CAAA;AAC5B,CAAA;AAEA,SAASD,yBAAwB,KAAuB,EAAA;AACpD,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,kCAAA,EAAoC,IAAI,CAAA,CAAA;AACjE","file":"index.browser.cjs","sourcesContent":["/**\n * This function is a replacement for `JSON.parse` that can handle large\n * unsafe integers by parsing them as BigInts. It transforms every\n * numerical value into a BigInt without loss of precision.\n */\nexport function parseJsonWithBigInts(json: string): unknown {\n return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {\n return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;\n });\n}\n\nfunction wrapIntegersInBigIntValueObject(json: string): string {\n const out = [];\n let inQuote = false;\n for (let ii = 0; ii < json.length; ii++) {\n let isEscaped = false;\n if (json[ii] === '\\\\') {\n out.push(json[ii++]);\n isEscaped = !isEscaped;\n }\n if (json[ii] === '\"') {\n out.push(json[ii]);\n if (!isEscaped) {\n inQuote = !inQuote;\n }\n continue;\n }\n if (!inQuote) {\n const consumedNumber = consumeNumber(json, ii);\n if (consumedNumber?.length) {\n ii += consumedNumber.length - 1;\n // Don't wrap numbers that contain a decimal point or a negative exponent.\n if (consumedNumber.match(/\\.|[eE]-/)) {\n out.push(consumedNumber);\n } else {\n out.push(wrapBigIntValueObject(consumedNumber));\n }\n continue;\n }\n }\n out.push(json[ii]);\n }\n\n return out.join('');\n}\n\nfunction consumeNumber(json: string, ii: number): string | null {\n /** @see https://stackoverflow.com/a/13340826/11440277 */\n const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n // Stop early if the first character isn't a digit or a minus sign.\n if (!json[ii]?.match(/[-\\d]/)) {\n return null;\n }\n\n // Otherwise, check if the next characters form a valid JSON number.\n const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);\n return numberMatch ? numberMatch[0] : null;\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: string): string {\n return `{\"$n\":\"${value}\"}`;\n}\n\nfunction unwrapBigIntValueObject({ $n }: BigIntValueObject): bigint {\n if ($n.match(/[eE]/)) {\n const [units, exponent] = $n.split(/[eE]/);\n return BigInt(units) * BigInt(10) ** BigInt(exponent);\n }\n return BigInt($n);\n}\n\nfunction isBigIntValueObject(value: unknown): value is BigIntValueObject {\n return !!value && typeof value === 'object' && '$n' in value && typeof value.$n === 'string';\n}\n","import { RpcRequest } from './rpc-request';\n\nlet _nextMessageId = 0;\nfunction getNextMessageId() {\n const id = _nextMessageId;\n _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;\n return id;\n}\n\nexport function createRpcMessage<TParams>(request: RpcRequest<TParams>) {\n return {\n id: getNextMessageId(),\n jsonrpc: '2.0',\n method: request.methodName,\n params: request.params,\n };\n}\n","/**\n * Transforms a value into a JSON string, whilst rendering bigints as large unsafe integers.\n */\nexport function stringifyJsonWithBigints(value: unknown, space?: number | string): string {\n return unwrapBigIntValueObject(\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? wrapBigIntValueObject(v) : v), space),\n );\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: bigint): BigIntValueObject {\n return { $n: `${value}` };\n}\n\nfunction unwrapBigIntValueObject(value: string): string {\n return value.replace(/\\{\\s*\"\\$n\"\\s*:\\s*\"(-?\\d+)\"\\s*\\}/g, '$1');\n}\n"]}
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
// src/parse-json-with-bigints.ts
|
|
2
|
+
function parseJsonWithBigInts(json) {
|
|
3
|
+
return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {
|
|
4
|
+
return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function wrapIntegersInBigIntValueObject(json) {
|
|
8
|
+
const out = [];
|
|
9
|
+
let inQuote = false;
|
|
10
|
+
for (let ii = 0; ii < json.length; ii++) {
|
|
11
|
+
let isEscaped = false;
|
|
12
|
+
if (json[ii] === "\\") {
|
|
13
|
+
out.push(json[ii++]);
|
|
14
|
+
isEscaped = !isEscaped;
|
|
15
|
+
}
|
|
16
|
+
if (json[ii] === '"') {
|
|
17
|
+
out.push(json[ii]);
|
|
18
|
+
if (!isEscaped) {
|
|
19
|
+
inQuote = !inQuote;
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!inQuote) {
|
|
24
|
+
const consumedNumber = consumeNumber(json, ii);
|
|
25
|
+
if (consumedNumber?.length) {
|
|
26
|
+
ii += consumedNumber.length - 1;
|
|
27
|
+
if (consumedNumber.match(/\.|[eE]-/)) {
|
|
28
|
+
out.push(consumedNumber);
|
|
29
|
+
} else {
|
|
30
|
+
out.push(wrapBigIntValueObject(consumedNumber));
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
out.push(json[ii]);
|
|
36
|
+
}
|
|
37
|
+
return out.join("");
|
|
38
|
+
}
|
|
39
|
+
function consumeNumber(json, ii) {
|
|
40
|
+
const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
41
|
+
if (!json[ii]?.match(/[-\d]/)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);
|
|
45
|
+
return numberMatch ? numberMatch[0] : null;
|
|
46
|
+
}
|
|
47
|
+
function wrapBigIntValueObject(value) {
|
|
48
|
+
return `{"$n":"${value}"}`;
|
|
49
|
+
}
|
|
50
|
+
function unwrapBigIntValueObject({ $n }) {
|
|
51
|
+
if ($n.match(/[eE]/)) {
|
|
52
|
+
const [units, exponent] = $n.split(/[eE]/);
|
|
53
|
+
return BigInt(units) * BigInt(10) ** BigInt(exponent);
|
|
54
|
+
}
|
|
55
|
+
return BigInt($n);
|
|
56
|
+
}
|
|
57
|
+
function isBigIntValueObject(value) {
|
|
58
|
+
return !!value && typeof value === "object" && "$n" in value && typeof value.$n === "string";
|
|
59
|
+
}
|
|
60
|
+
|
|
1
61
|
// src/rpc-message.ts
|
|
2
62
|
var _nextMessageId = 0;
|
|
3
63
|
function getNextMessageId() {
|
|
@@ -5,15 +65,28 @@ function getNextMessageId() {
|
|
|
5
65
|
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
6
66
|
return id;
|
|
7
67
|
}
|
|
8
|
-
function createRpcMessage(
|
|
68
|
+
function createRpcMessage(request) {
|
|
9
69
|
return {
|
|
10
70
|
id: getNextMessageId(),
|
|
11
71
|
jsonrpc: "2.0",
|
|
12
|
-
method,
|
|
13
|
-
params
|
|
72
|
+
method: request.methodName,
|
|
73
|
+
params: request.params
|
|
14
74
|
};
|
|
15
75
|
}
|
|
16
76
|
|
|
17
|
-
|
|
77
|
+
// src/stringify-json-with-bigints.ts
|
|
78
|
+
function stringifyJsonWithBigints(value, space) {
|
|
79
|
+
return unwrapBigIntValueObject2(
|
|
80
|
+
JSON.stringify(value, (_, v) => typeof v === "bigint" ? wrapBigIntValueObject2(v) : v, space)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function wrapBigIntValueObject2(value) {
|
|
84
|
+
return { $n: `${value}` };
|
|
85
|
+
}
|
|
86
|
+
function unwrapBigIntValueObject2(value) {
|
|
87
|
+
return value.replace(/\{\s*"\$n"\s*:\s*"(-?\d+)"\s*\}/g, "$1");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { createRpcMessage, parseJsonWithBigInts, stringifyJsonWithBigints };
|
|
18
91
|
//# sourceMappingURL=index.browser.mjs.map
|
|
19
92
|
//# sourceMappingURL=index.browser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rpc-message.ts"],"names":[],"mappings":";AAAA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/parse-json-with-bigints.ts","../src/rpc-message.ts","../src/stringify-json-with-bigints.ts"],"names":["unwrapBigIntValueObject","wrapBigIntValueObject"],"mappings":";AAKO,SAAS,qBAAqB,IAAuB,EAAA;AACxD,EAAA,OAAO,KAAK,KAAM,CAAA,+BAAA,CAAgC,IAAI,CAAG,EAAA,CAAC,GAAG,KAAU,KAAA;AACnE,IAAA,OAAO,mBAAoB,CAAA,KAAK,CAAI,GAAA,uBAAA,CAAwB,KAAK,CAAI,GAAA,KAAA,CAAA;AAAA,GACxE,CAAA,CAAA;AACL,CAAA;AAEA,SAAS,gCAAgC,IAAsB,EAAA;AAC3D,EAAA,MAAM,MAAM,EAAC,CAAA;AACb,EAAA,IAAI,OAAU,GAAA,KAAA,CAAA;AACd,EAAA,KAAA,IAAS,EAAK,GAAA,CAAA,EAAG,EAAK,GAAA,IAAA,CAAK,QAAQ,EAAM,EAAA,EAAA;AACrC,IAAA,IAAI,SAA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AQ,CAAA,UAAA;AAAA,IAChB,QAAQ,OAAQ,CAAA,MAAA;AAAA,GACpB,CAAA;AACJ,CAAA;;;ACbO,SAAS,wBAAA,CAAyB,OAAgB,KAAiC,EAAA;AACtF,EAAOA,OAAAA,wBAAAA;AAAA,IACH,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,CAAC,CAAG,EAAA,CAAA,KAAO,OAAO,CAAA,KAAM,QAAWC,GAAAA,sBAAAA,CAAsB,CAAC,CAAA,GAAI,GAAI,KAAK,CAAA;AAAA,GACjG,CAAA;AACJ,CAAA;AAQA,SAASA,uBAAsB,KAAkC,EAAA;AAC7D,EAAA,OAAO,EAAE,EAAA,EAAI,CAAG,EAAA,KAAK,CAAG,CAAA,EAAA,CAAA;AAC5B,CAAA;AAEA,SAASD,yBAAwB,KAAuB,EAAA;AACpD,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,kCAAA,EAAoC,IAAI,CAAA,CAAA;AACjE","file":"index.browser.mjs","sourcesContent":["/**\n * This function is a replacement for `JSON.parse` that can handle large\n * unsafe integers by parsing them as BigInts. It transforms every\n * numerical value into a BigInt without loss of precision.\n */\nexport function parseJsonWithBigInts(json: string): unknown {\n return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {\n return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;\n });\n}\n\nfunction wrapIntegersInBigIntValueObject(json: string): string {\n const out = [];\n let inQuote = false;\n for (let ii = 0; ii < json.length; ii++) {\n let isEscaped = false;\n if (json[ii] === '\\\\') {\n out.push(json[ii++]);\n isEscaped = !isEscaped;\n }\n if (json[ii] === '\"') {\n out.push(json[ii]);\n if (!isEscaped) {\n inQuote = !inQuote;\n }\n continue;\n }\n if (!inQuote) {\n const consumedNumber = consumeNumber(json, ii);\n if (consumedNumber?.length) {\n ii += consumedNumber.length - 1;\n // Don't wrap numbers that contain a decimal point or a negative exponent.\n if (consumedNumber.match(/\\.|[eE]-/)) {\n out.push(consumedNumber);\n } else {\n out.push(wrapBigIntValueObject(consumedNumber));\n }\n continue;\n }\n }\n out.push(json[ii]);\n }\n\n return out.join('');\n}\n\nfunction consumeNumber(json: string, ii: number): string | null {\n /** @see https://stackoverflow.com/a/13340826/11440277 */\n const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n // Stop early if the first character isn't a digit or a minus sign.\n if (!json[ii]?.match(/[-\\d]/)) {\n return null;\n }\n\n // Otherwise, check if the next characters form a valid JSON number.\n const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);\n return numberMatch ? numberMatch[0] : null;\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: string): string {\n return `{\"$n\":\"${value}\"}`;\n}\n\nfunction unwrapBigIntValueObject({ $n }: BigIntValueObject): bigint {\n if ($n.match(/[eE]/)) {\n const [units, exponent] = $n.split(/[eE]/);\n return BigInt(units) * BigInt(10) ** BigInt(exponent);\n }\n return BigInt($n);\n}\n\nfunction isBigIntValueObject(value: unknown): value is BigIntValueObject {\n return !!value && typeof value === 'object' && '$n' in value && typeof value.$n === 'string';\n}\n","import { RpcRequest } from './rpc-request';\n\nlet _nextMessageId = 0;\nfunction getNextMessageId() {\n const id = _nextMessageId;\n _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;\n return id;\n}\n\nexport function createRpcMessage<TParams>(request: RpcRequest<TParams>) {\n return {\n id: getNextMessageId(),\n jsonrpc: '2.0',\n method: request.methodName,\n params: request.params,\n };\n}\n","/**\n * Transforms a value into a JSON string, whilst rendering bigints as large unsafe integers.\n */\nexport function stringifyJsonWithBigints(value: unknown, space?: number | string): string {\n return unwrapBigIntValueObject(\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? wrapBigIntValueObject(v) : v), space),\n );\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: bigint): BigIntValueObject {\n return { $n: `${value}` };\n}\n\nfunction unwrapBigIntValueObject(value: string): string {\n return value.replace(/\\{\\s*\"\\$n\"\\s*:\\s*\"(-?\\d+)\"\\s*\\}/g, '$1');\n}\n"]}
|
package/dist/index.native.mjs
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
// src/parse-json-with-bigints.ts
|
|
2
|
+
function parseJsonWithBigInts(json) {
|
|
3
|
+
return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {
|
|
4
|
+
return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function wrapIntegersInBigIntValueObject(json) {
|
|
8
|
+
const out = [];
|
|
9
|
+
let inQuote = false;
|
|
10
|
+
for (let ii = 0; ii < json.length; ii++) {
|
|
11
|
+
let isEscaped = false;
|
|
12
|
+
if (json[ii] === "\\") {
|
|
13
|
+
out.push(json[ii++]);
|
|
14
|
+
isEscaped = !isEscaped;
|
|
15
|
+
}
|
|
16
|
+
if (json[ii] === '"') {
|
|
17
|
+
out.push(json[ii]);
|
|
18
|
+
if (!isEscaped) {
|
|
19
|
+
inQuote = !inQuote;
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!inQuote) {
|
|
24
|
+
const consumedNumber = consumeNumber(json, ii);
|
|
25
|
+
if (consumedNumber?.length) {
|
|
26
|
+
ii += consumedNumber.length - 1;
|
|
27
|
+
if (consumedNumber.match(/\.|[eE]-/)) {
|
|
28
|
+
out.push(consumedNumber);
|
|
29
|
+
} else {
|
|
30
|
+
out.push(wrapBigIntValueObject(consumedNumber));
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
out.push(json[ii]);
|
|
36
|
+
}
|
|
37
|
+
return out.join("");
|
|
38
|
+
}
|
|
39
|
+
function consumeNumber(json, ii) {
|
|
40
|
+
const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
41
|
+
if (!json[ii]?.match(/[-\d]/)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);
|
|
45
|
+
return numberMatch ? numberMatch[0] : null;
|
|
46
|
+
}
|
|
47
|
+
function wrapBigIntValueObject(value) {
|
|
48
|
+
return `{"$n":"${value}"}`;
|
|
49
|
+
}
|
|
50
|
+
function unwrapBigIntValueObject({ $n }) {
|
|
51
|
+
if ($n.match(/[eE]/)) {
|
|
52
|
+
const [units, exponent] = $n.split(/[eE]/);
|
|
53
|
+
return BigInt(units) * BigInt(10) ** BigInt(exponent);
|
|
54
|
+
}
|
|
55
|
+
return BigInt($n);
|
|
56
|
+
}
|
|
57
|
+
function isBigIntValueObject(value) {
|
|
58
|
+
return !!value && typeof value === "object" && "$n" in value && typeof value.$n === "string";
|
|
59
|
+
}
|
|
60
|
+
|
|
1
61
|
// src/rpc-message.ts
|
|
2
62
|
var _nextMessageId = 0;
|
|
3
63
|
function getNextMessageId() {
|
|
@@ -5,15 +65,28 @@ function getNextMessageId() {
|
|
|
5
65
|
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
6
66
|
return id;
|
|
7
67
|
}
|
|
8
|
-
function createRpcMessage(
|
|
68
|
+
function createRpcMessage(request) {
|
|
9
69
|
return {
|
|
10
70
|
id: getNextMessageId(),
|
|
11
71
|
jsonrpc: "2.0",
|
|
12
|
-
method,
|
|
13
|
-
params
|
|
72
|
+
method: request.methodName,
|
|
73
|
+
params: request.params
|
|
14
74
|
};
|
|
15
75
|
}
|
|
16
76
|
|
|
17
|
-
|
|
77
|
+
// src/stringify-json-with-bigints.ts
|
|
78
|
+
function stringifyJsonWithBigints(value, space) {
|
|
79
|
+
return unwrapBigIntValueObject2(
|
|
80
|
+
JSON.stringify(value, (_, v) => typeof v === "bigint" ? wrapBigIntValueObject2(v) : v, space)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function wrapBigIntValueObject2(value) {
|
|
84
|
+
return { $n: `${value}` };
|
|
85
|
+
}
|
|
86
|
+
function unwrapBigIntValueObject2(value) {
|
|
87
|
+
return value.replace(/\{\s*"\$n"\s*:\s*"(-?\d+)"\s*\}/g, "$1");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { createRpcMessage, parseJsonWithBigInts, stringifyJsonWithBigints };
|
|
18
91
|
//# sourceMappingURL=index.native.mjs.map
|
|
19
92
|
//# sourceMappingURL=index.native.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rpc-message.ts"],"names":[],"mappings":";AAAA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/parse-json-with-bigints.ts","../src/rpc-message.ts","../src/stringify-json-with-bigints.ts"],"names":["unwrapBigIntValueObject","wrapBigIntValueObject"],"mappings":";AAKO,SAAS,qBAAqB,IAAuB,EAAA;AACxD,EAAA,OAAO,KAAK,KAAM,CAAA,+BAAA,CAAgC,IAAI,CAAG,EAAA,CAAC,GAAG,KAAU,KAAA;AACnE,IAAA,OAAO,mBAAoB,CAAA,KAAK,CAAI,GAAA,uBAAA,CAAwB,KAAK,CAAI,GAAA,KAAA,CAAA;AAAA,GACxE,CAAA,CAAA;AACL,CAAA;AAEA,SAAS,gCAAgC,IAAsB,EAAA;AAC3D,EAAA,MAAM,MAAM,EAAC,CAAA;AACb,EAAA,IAAI,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X,CAAA;AAEO,SAAS,iBAA0B,OAA8B,EAAA;AACpE,EAAO,OAAA;AAAA,IACH,IAAI,gBAAiB,EAAA;AAAA,IACrB,OAAS,EAAA,KAAA;AAAA,IACT,QAAQ,OAAQ,CAAA,UAAA;AAAA,IAChB,QAAQ,OAAQ,CAAA,MAAA;AAAA,GACpB,CAAA;AACJ,CAAA;;;ACbO,SAAS,wBAAA,CAAyB,OAAgB,KAAiC,EAAA;AACtF,EAAOA,OAAAA,wBAAAA;AAAA,IACH,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,CAAC,CAAG,EAAA,CAAA,KAAO,OAAO,CAAA,KAAM,QAAWC,GAAAA,sBAAAA,CAAsB,CAAC,CAAA,GAAI,GAAI,KAAK,CAAA;AAAA,GACjG,CAAA;AACJ,CAAA;AAQA,SAASA,uBAAsB,KAAkC,EAAA;AAC7D,EAAA,OAAO,EAAE,EAAA,EAAI,CAAG,EAAA,KAAK,CAAG,CAAA,EAAA,CAAA;AAC5B,CAAA;AAEA,SAASD,yBAAwB,KAAuB,EAAA;AACpD,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,kCAAA,EAAoC,IAAI,CAAA,CAAA;AACjE","file":"index.native.mjs","sourcesContent":["/**\n * This function is a replacement for `JSON.parse` that can handle large\n * unsafe integers by parsing them as BigInts. It transforms every\n * numerical value into a BigInt without loss of precision.\n */\nexport function parseJsonWithBigInts(json: string): unknown {\n return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {\n return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;\n });\n}\n\nfunction wrapIntegersInBigIntValueObject(json: string): string {\n const out = [];\n let inQuote = false;\n for (let ii = 0; ii < json.length; ii++) {\n let isEscaped = false;\n if (json[ii] === '\\\\') {\n out.push(json[ii++]);\n isEscaped = !isEscaped;\n }\n if (json[ii] === '\"') {\n out.push(json[ii]);\n if (!isEscaped) {\n inQuote = !inQuote;\n }\n continue;\n }\n if (!inQuote) {\n const consumedNumber = consumeNumber(json, ii);\n if (consumedNumber?.length) {\n ii += consumedNumber.length - 1;\n // Don't wrap numbers that contain a decimal point or a negative exponent.\n if (consumedNumber.match(/\\.|[eE]-/)) {\n out.push(consumedNumber);\n } else {\n out.push(wrapBigIntValueObject(consumedNumber));\n }\n continue;\n }\n }\n out.push(json[ii]);\n }\n\n return out.join('');\n}\n\nfunction consumeNumber(json: string, ii: number): string | null {\n /** @see https://stackoverflow.com/a/13340826/11440277 */\n const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n // Stop early if the first character isn't a digit or a minus sign.\n if (!json[ii]?.match(/[-\\d]/)) {\n return null;\n }\n\n // Otherwise, check if the next characters form a valid JSON number.\n const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);\n return numberMatch ? numberMatch[0] : null;\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: string): string {\n return `{\"$n\":\"${value}\"}`;\n}\n\nfunction unwrapBigIntValueObject({ $n }: BigIntValueObject): bigint {\n if ($n.match(/[eE]/)) {\n const [units, exponent] = $n.split(/[eE]/);\n return BigInt(units) * BigInt(10) ** BigInt(exponent);\n }\n return BigInt($n);\n}\n\nfunction isBigIntValueObject(value: unknown): value is BigIntValueObject {\n return !!value && typeof value === 'object' && '$n' in value && typeof value.$n === 'string';\n}\n","import { RpcRequest } from './rpc-request';\n\nlet _nextMessageId = 0;\nfunction getNextMessageId() {\n const id = _nextMessageId;\n _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;\n return id;\n}\n\nexport function createRpcMessage<TParams>(request: RpcRequest<TParams>) {\n return {\n id: getNextMessageId(),\n jsonrpc: '2.0',\n method: request.methodName,\n params: request.params,\n };\n}\n","/**\n * Transforms a value into a JSON string, whilst rendering bigints as large unsafe integers.\n */\nexport function stringifyJsonWithBigints(value: unknown, space?: number | string): string {\n return unwrapBigIntValueObject(\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? wrapBigIntValueObject(v) : v), space),\n );\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: bigint): BigIntValueObject {\n return { $n: `${value}` };\n}\n\nfunction unwrapBigIntValueObject(value: string): string {\n return value.replace(/\\{\\s*\"\\$n\"\\s*:\\s*\"(-?\\d+)\"\\s*\\}/g, '$1');\n}\n"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/parse-json-with-bigints.ts
|
|
4
|
+
function parseJsonWithBigInts(json) {
|
|
5
|
+
return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {
|
|
6
|
+
return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function wrapIntegersInBigIntValueObject(json) {
|
|
10
|
+
const out = [];
|
|
11
|
+
let inQuote = false;
|
|
12
|
+
for (let ii = 0; ii < json.length; ii++) {
|
|
13
|
+
let isEscaped = false;
|
|
14
|
+
if (json[ii] === "\\") {
|
|
15
|
+
out.push(json[ii++]);
|
|
16
|
+
isEscaped = !isEscaped;
|
|
17
|
+
}
|
|
18
|
+
if (json[ii] === '"') {
|
|
19
|
+
out.push(json[ii]);
|
|
20
|
+
if (!isEscaped) {
|
|
21
|
+
inQuote = !inQuote;
|
|
22
|
+
}
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!inQuote) {
|
|
26
|
+
const consumedNumber = consumeNumber(json, ii);
|
|
27
|
+
if (consumedNumber?.length) {
|
|
28
|
+
ii += consumedNumber.length - 1;
|
|
29
|
+
if (consumedNumber.match(/\.|[eE]-/)) {
|
|
30
|
+
out.push(consumedNumber);
|
|
31
|
+
} else {
|
|
32
|
+
out.push(wrapBigIntValueObject(consumedNumber));
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
out.push(json[ii]);
|
|
38
|
+
}
|
|
39
|
+
return out.join("");
|
|
40
|
+
}
|
|
41
|
+
function consumeNumber(json, ii) {
|
|
42
|
+
const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
43
|
+
if (!json[ii]?.match(/[-\d]/)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);
|
|
47
|
+
return numberMatch ? numberMatch[0] : null;
|
|
48
|
+
}
|
|
49
|
+
function wrapBigIntValueObject(value) {
|
|
50
|
+
return `{"$n":"${value}"}`;
|
|
51
|
+
}
|
|
52
|
+
function unwrapBigIntValueObject({ $n }) {
|
|
53
|
+
if ($n.match(/[eE]/)) {
|
|
54
|
+
const [units, exponent] = $n.split(/[eE]/);
|
|
55
|
+
return BigInt(units) * BigInt(10) ** BigInt(exponent);
|
|
56
|
+
}
|
|
57
|
+
return BigInt($n);
|
|
58
|
+
}
|
|
59
|
+
function isBigIntValueObject(value) {
|
|
60
|
+
return !!value && typeof value === "object" && "$n" in value && typeof value.$n === "string";
|
|
61
|
+
}
|
|
62
|
+
|
|
3
63
|
// src/rpc-message.ts
|
|
4
64
|
var _nextMessageId = 0;
|
|
5
65
|
function getNextMessageId() {
|
|
@@ -7,15 +67,30 @@ function getNextMessageId() {
|
|
|
7
67
|
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
8
68
|
return id;
|
|
9
69
|
}
|
|
10
|
-
function createRpcMessage(
|
|
70
|
+
function createRpcMessage(request) {
|
|
11
71
|
return {
|
|
12
72
|
id: getNextMessageId(),
|
|
13
73
|
jsonrpc: "2.0",
|
|
14
|
-
method,
|
|
15
|
-
params
|
|
74
|
+
method: request.methodName,
|
|
75
|
+
params: request.params
|
|
16
76
|
};
|
|
17
77
|
}
|
|
18
78
|
|
|
79
|
+
// src/stringify-json-with-bigints.ts
|
|
80
|
+
function stringifyJsonWithBigints(value, space) {
|
|
81
|
+
return unwrapBigIntValueObject2(
|
|
82
|
+
JSON.stringify(value, (_, v) => typeof v === "bigint" ? wrapBigIntValueObject2(v) : v, space)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function wrapBigIntValueObject2(value) {
|
|
86
|
+
return { $n: `${value}` };
|
|
87
|
+
}
|
|
88
|
+
function unwrapBigIntValueObject2(value) {
|
|
89
|
+
return value.replace(/\{\s*"\$n"\s*:\s*"(-?\d+)"\s*\}/g, "$1");
|
|
90
|
+
}
|
|
91
|
+
|
|
19
92
|
exports.createRpcMessage = createRpcMessage;
|
|
93
|
+
exports.parseJsonWithBigInts = parseJsonWithBigInts;
|
|
94
|
+
exports.stringifyJsonWithBigints = stringifyJsonWithBigints;
|
|
20
95
|
//# sourceMappingURL=index.node.cjs.map
|
|
21
96
|
//# sourceMappingURL=index.node.cjs.map
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rpc-message.ts"],"names":[],"mappings":";;;AAAA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/parse-json-with-bigints.ts","../src/rpc-message.ts","../src/stringify-json-with-bigints.ts"],"names":["unwrapBigIntValueObject","wrapBigIntValueObject"],"mappings":";;;AAKO,SAAS,qBAAqB,IAAuB,EAAA;AACxD,EAAA,OAAO,KAAK,KAAM,CAAA,+BAAA,CA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AAA,CAAM,EAAO,KAAA,QAAA,CAAA;AACxF,CAAA;;;AC9EA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,iBAA0B,OAA8B,EAAA;AACpE,EAAO,OAAA;AAAA,IACH,IAAI,gBAAiB,EAAA;AAAA,IACrB,OAAS,EAAA,KAAA;AAAA,IACT,QAAQ,OAAQ,CAAA,UAAA;AAAA,IAChB,QAAQ,OAAQ,CAAA,MAAA;AAAA,GACpB,CAAA;AACJ,CAAA;;;ACbO,SAAS,wBAAA,CAAyB,OAAgB,KAAiC,EAAA;AACtF,EAAOA,OAAAA,wBAAAA;AAAA,IACH,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,CAAC,CAAG,EAAA,CAAA,KAAO,OAAO,CAAA,KAAM,QAAWC,GAAAA,sBAAAA,CAAsB,CAAC,CAAA,GAAI,GAAI,KAAK,CAAA;AAAA,GACjG,CAAA;AACJ,CAAA;AAQA,SAASA,uBAAsB,KAAkC,EAAA;AAC7D,EAAA,OAAO,EAAE,EAAA,EAAI,CAAG,EAAA,KAAK,CAAG,CAAA,EAAA,CAAA;AAC5B,CAAA;AAEA,SAASD,yBAAwB,KAAuB,EAAA;AACpD,EAAO,OAAA,KAAA,CAAM,OAAQ,CAAA,kCAAA,EAAoC,IAAI,CAAA,CAAA;AACjE","file":"index.node.cjs","sourcesContent":["/**\n * This function is a replacement for `JSON.parse` that can handle large\n * unsafe integers by parsing them as BigInts. It transforms every\n * numerical value into a BigInt without loss of precision.\n */\nexport function parseJsonWithBigInts(json: string): unknown {\n return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {\n return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;\n });\n}\n\nfunction wrapIntegersInBigIntValueObject(json: string): string {\n const out = [];\n let inQuote = false;\n for (let ii = 0; ii < json.length; ii++) {\n let isEscaped = false;\n if (json[ii] === '\\\\') {\n out.push(json[ii++]);\n isEscaped = !isEscaped;\n }\n if (json[ii] === '\"') {\n out.push(json[ii]);\n if (!isEscaped) {\n inQuote = !inQuote;\n }\n continue;\n }\n if (!inQuote) {\n const consumedNumber = consumeNumber(json, ii);\n if (consumedNumber?.length) {\n ii += consumedNumber.length - 1;\n // Don't wrap numbers that contain a decimal point or a negative exponent.\n if (consumedNumber.match(/\\.|[eE]-/)) {\n out.push(consumedNumber);\n } else {\n out.push(wrapBigIntValueObject(consumedNumber));\n }\n continue;\n }\n }\n out.push(json[ii]);\n }\n\n return out.join('');\n}\n\nfunction consumeNumber(json: string, ii: number): string | null {\n /** @see https://stackoverflow.com/a/13340826/11440277 */\n const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n // Stop early if the first character isn't a digit or a minus sign.\n if (!json[ii]?.match(/[-\\d]/)) {\n return null;\n }\n\n // Otherwise, check if the next characters form a valid JSON number.\n const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);\n return numberMatch ? numberMatch[0] : null;\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: string): string {\n return `{\"$n\":\"${value}\"}`;\n}\n\nfunction unwrapBigIntValueObject({ $n }: BigIntValueObject): bigint {\n if ($n.match(/[eE]/)) {\n const [units, exponent] = $n.split(/[eE]/);\n return BigInt(units) * BigInt(10) ** BigInt(exponent);\n }\n return BigInt($n);\n}\n\nfunction isBigIntValueObject(value: unknown): value is BigIntValueObject {\n return !!value && typeof value === 'object' && '$n' in value && typeof value.$n === 'string';\n}\n","import { RpcRequest } from './rpc-request';\n\nlet _nextMessageId = 0;\nfunction getNextMessageId() {\n const id = _nextMessageId;\n _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;\n return id;\n}\n\nexport function createRpcMessage<TParams>(request: RpcRequest<TParams>) {\n return {\n id: getNextMessageId(),\n jsonrpc: '2.0',\n method: request.methodName,\n params: request.params,\n };\n}\n","/**\n * Transforms a value into a JSON string, whilst rendering bigints as large unsafe integers.\n */\nexport function stringifyJsonWithBigints(value: unknown, space?: number | string): string {\n return unwrapBigIntValueObject(\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? wrapBigIntValueObject(v) : v), space),\n );\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: bigint): BigIntValueObject {\n return { $n: `${value}` };\n}\n\nfunction unwrapBigIntValueObject(value: string): string {\n return value.replace(/\\{\\s*\"\\$n\"\\s*:\\s*\"(-?\\d+)\"\\s*\\}/g, '$1');\n}\n"]}
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
// src/parse-json-with-bigints.ts
|
|
2
|
+
function parseJsonWithBigInts(json) {
|
|
3
|
+
return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {
|
|
4
|
+
return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function wrapIntegersInBigIntValueObject(json) {
|
|
8
|
+
const out = [];
|
|
9
|
+
let inQuote = false;
|
|
10
|
+
for (let ii = 0; ii < json.length; ii++) {
|
|
11
|
+
let isEscaped = false;
|
|
12
|
+
if (json[ii] === "\\") {
|
|
13
|
+
out.push(json[ii++]);
|
|
14
|
+
isEscaped = !isEscaped;
|
|
15
|
+
}
|
|
16
|
+
if (json[ii] === '"') {
|
|
17
|
+
out.push(json[ii]);
|
|
18
|
+
if (!isEscaped) {
|
|
19
|
+
inQuote = !inQuote;
|
|
20
|
+
}
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (!inQuote) {
|
|
24
|
+
const consumedNumber = consumeNumber(json, ii);
|
|
25
|
+
if (consumedNumber?.length) {
|
|
26
|
+
ii += consumedNumber.length - 1;
|
|
27
|
+
if (consumedNumber.match(/\.|[eE]-/)) {
|
|
28
|
+
out.push(consumedNumber);
|
|
29
|
+
} else {
|
|
30
|
+
out.push(wrapBigIntValueObject(consumedNumber));
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
out.push(json[ii]);
|
|
36
|
+
}
|
|
37
|
+
return out.join("");
|
|
38
|
+
}
|
|
39
|
+
function consumeNumber(json, ii) {
|
|
40
|
+
const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/;
|
|
41
|
+
if (!json[ii]?.match(/[-\d]/)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);
|
|
45
|
+
return numberMatch ? numberMatch[0] : null;
|
|
46
|
+
}
|
|
47
|
+
function wrapBigIntValueObject(value) {
|
|
48
|
+
return `{"$n":"${value}"}`;
|
|
49
|
+
}
|
|
50
|
+
function unwrapBigIntValueObject({ $n }) {
|
|
51
|
+
if ($n.match(/[eE]/)) {
|
|
52
|
+
const [units, exponent] = $n.split(/[eE]/);
|
|
53
|
+
return BigInt(units) * BigInt(10) ** BigInt(exponent);
|
|
54
|
+
}
|
|
55
|
+
return BigInt($n);
|
|
56
|
+
}
|
|
57
|
+
function isBigIntValueObject(value) {
|
|
58
|
+
return !!value && typeof value === "object" && "$n" in value && typeof value.$n === "string";
|
|
59
|
+
}
|
|
60
|
+
|
|
1
61
|
// src/rpc-message.ts
|
|
2
62
|
var _nextMessageId = 0;
|
|
3
63
|
function getNextMessageId() {
|
|
@@ -5,15 +65,28 @@ function getNextMessageId() {
|
|
|
5
65
|
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
6
66
|
return id;
|
|
7
67
|
}
|
|
8
|
-
function createRpcMessage(
|
|
68
|
+
function createRpcMessage(request) {
|
|
9
69
|
return {
|
|
10
70
|
id: getNextMessageId(),
|
|
11
71
|
jsonrpc: "2.0",
|
|
12
|
-
method,
|
|
13
|
-
params
|
|
72
|
+
method: request.methodName,
|
|
73
|
+
params: request.params
|
|
14
74
|
};
|
|
15
75
|
}
|
|
16
76
|
|
|
17
|
-
|
|
77
|
+
// src/stringify-json-with-bigints.ts
|
|
78
|
+
function stringifyJsonWithBigints(value, space) {
|
|
79
|
+
return unwrapBigIntValueObject2(
|
|
80
|
+
JSON.stringify(value, (_, v) => typeof v === "bigint" ? wrapBigIntValueObject2(v) : v, space)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function wrapBigIntValueObject2(value) {
|
|
84
|
+
return { $n: `${value}` };
|
|
85
|
+
}
|
|
86
|
+
function unwrapBigIntValueObject2(value) {
|
|
87
|
+
return value.replace(/\{\s*"\$n"\s*:\s*"(-?\d+)"\s*\}/g, "$1");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { createRpcMessage, parseJsonWithBigInts, stringifyJsonWithBigints };
|
|
18
91
|
//# sourceMappingURL=index.node.mjs.map
|
|
19
92
|
//# sourceMappingURL=index.node.mjs.map
|
package/dist/index.node.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rpc-message.ts"],"names":[],"mappings":";AAAA,IAAI,cAAiB,GAAA,CAAA,CAAA;AACrB,SAAS,gBAAmB,GAAA;AACxB,EAAA,MAAM,EAAK,GAAA,cAAA,CAAA;AACX,EAAkB,cAAA,GAAA,CAAA,cAAA,GAAiB,KAAK,MAAO,CAAA,gBAAA,CAAA;AAC/C,EAAO,OAAA,EAAA,CAAA;AACX,CAAA;AAEO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/parse-json-with-big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integers by parsing them as BigInts. It transforms every\n * numerical value into a BigInt without loss of precision.\n */\nexport function parseJsonWithBigInts(json: string): unknown {\n return JSON.parse(wrapIntegersInBigIntValueObject(json), (_, value) => {\n return isBigIntValueObject(value) ? unwrapBigIntValueObject(value) : value;\n });\n}\n\nfunction wrapIntegersInBigIntValueObject(json: string): string {\n const out = [];\n let inQuote = false;\n for (let ii = 0; ii < json.length; ii++) {\n let isEscaped = false;\n if (json[ii] === '\\\\') {\n out.push(json[ii++]);\n isEscaped = !isEscaped;\n }\n if (json[ii] === '\"') {\n out.push(json[ii]);\n if (!isEscaped) {\n inQuote = !inQuote;\n }\n continue;\n }\n if (!inQuote) {\n const consumedNumber = consumeNumber(json, ii);\n if (consumedNumber?.length) {\n ii += consumedNumber.length - 1;\n // Don't wrap numbers that contain a decimal point or a negative exponent.\n if (consumedNumber.match(/\\.|[eE]-/)) {\n out.push(consumedNumber);\n } else {\n out.push(wrapBigIntValueObject(consumedNumber));\n }\n continue;\n }\n }\n out.push(json[ii]);\n }\n\n return out.join('');\n}\n\nfunction consumeNumber(json: string, ii: number): string | null {\n /** @see https://stackoverflow.com/a/13340826/11440277 */\n const JSON_NUMBER_REGEX = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/;\n\n // Stop early if the first character isn't a digit or a minus sign.\n if (!json[ii]?.match(/[-\\d]/)) {\n return null;\n }\n\n // Otherwise, check if the next characters form a valid JSON number.\n const numberMatch = json.slice(ii).match(JSON_NUMBER_REGEX);\n return numberMatch ? numberMatch[0] : null;\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: string): string {\n return `{\"$n\":\"${value}\"}`;\n}\n\nfunction unwrapBigIntValueObject({ $n }: BigIntValueObject): bigint {\n if ($n.match(/[eE]/)) {\n const [units, exponent] = $n.split(/[eE]/);\n return BigInt(units) * BigInt(10) ** BigInt(exponent);\n }\n return BigInt($n);\n}\n\nfunction isBigIntValueObject(value: unknown): value is BigIntValueObject {\n return !!value && typeof value === 'object' && '$n' in value && typeof value.$n === 'string';\n}\n","import { RpcRequest } from './rpc-request';\n\nlet _nextMessageId = 0;\nfunction getNextMessageId() {\n const id = _nextMessageId;\n _nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;\n return id;\n}\n\nexport function createRpcMessage<TParams>(request: RpcRequest<TParams>) {\n return {\n id: getNextMessageId(),\n jsonrpc: '2.0',\n method: request.methodName,\n params: request.params,\n };\n}\n","/**\n * Transforms a value into a JSON string, whilst rendering bigints as large unsafe integers.\n */\nexport function stringifyJsonWithBigints(value: unknown, space?: number | string): string {\n return unwrapBigIntValueObject(\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? wrapBigIntValueObject(v) : v), space),\n );\n}\n\ntype BigIntValueObject = {\n // `$` implies 'this is a value object'.\n // `n` implies 'interpret the value as a bigint'.\n $n: string;\n};\n\nfunction wrapBigIntValueObject(value: bigint): BigIntValueObject {\n return { $n: `${value}` };\n}\n\nfunction unwrapBigIntValueObject(value: string): string {\n return value.replace(/\\{\\s*\"\\$n\"\\s*:\\s*\"(-?\\d+)\"\\s*\\}/g, '$1');\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './overloads';
|
|
2
|
+
export * from './parse-json-with-bigints';
|
|
2
3
|
export * from './rpc-message';
|
|
4
|
+
export * from './rpc-request';
|
|
3
5
|
export * from './rpc-response';
|
|
6
|
+
export * from './stringify-json-with-bigints';
|
|
4
7
|
export * from './type-helpers';
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is a replacement for `JSON.parse` that can handle large
|
|
3
|
+
* unsafe integers by parsing them as BigInts. It transforms every
|
|
4
|
+
* numerical value into a BigInt without loss of precision.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseJsonWithBigInts(json: string): unknown;
|
|
7
|
+
//# sourceMappingURL=parse-json-with-bigints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-json-with-bigints.d.ts","sourceRoot":"","sources":["../../src/parse-json-with-bigints.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-message.d.ts","sourceRoot":"","sources":["../../src/rpc-message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc-message.d.ts","sourceRoot":"","sources":["../../src/rpc-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;;;;;EAOrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-request.d.ts","sourceRoot":"","sources":["../../src/rpc-request.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,OAAO,GAAG,OAAO,IAAI;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAChC,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;CACvD,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import type { RpcRequest } from './rpc-request';
|
|
2
|
+
export type RpcResponse<TResponse = unknown> = TResponse;
|
|
3
|
+
export type RpcResponseTransformer<TResponse = unknown> = {
|
|
4
|
+
(response: RpcResponse, request: RpcRequest): RpcResponse<TResponse>;
|
|
5
|
+
};
|
|
1
6
|
interface IHasIdentifier {
|
|
2
7
|
readonly id: number;
|
|
3
8
|
}
|
|
4
|
-
type
|
|
9
|
+
type RpcErrorResponsePayload = Readonly<{
|
|
5
10
|
code: number;
|
|
6
11
|
data?: unknown;
|
|
7
12
|
message: string;
|
|
8
13
|
}>;
|
|
9
|
-
export type
|
|
10
|
-
error:
|
|
14
|
+
export type RpcResponseData<TResponse> = IHasIdentifier & Readonly<{
|
|
15
|
+
error: RpcErrorResponsePayload;
|
|
11
16
|
} | {
|
|
12
17
|
result: TResponse;
|
|
13
18
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-response.d.ts","sourceRoot":"","sources":["../../src/rpc-response.ts"],"names":[],"mappings":"AAAA,UAAU,cAAc;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACvB;AAED,KAAK,
|
|
1
|
+
{"version":3,"file":"rpc-response.d.ts","sourceRoot":"","sources":["../../src/rpc-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,WAAW,CAAC,SAAS,GAAG,OAAO,IAAI,SAAS,CAAC;AAEzD,MAAM,MAAM,sBAAsB,CAAC,SAAS,GAAG,OAAO,IAAI;IACtD,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;CACxE,CAAC;AAEF,UAAU,cAAc;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACvB;AAED,KAAK,uBAAuB,GAAG,QAAQ,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH,MAAM,MAAM,eAAe,CAAC,SAAS,IAAI,cAAc,GACnD,QAAQ,CAAC;IAAE,KAAK,EAAE,uBAAuB,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify-json-with-bigints.d.ts","sourceRoot":"","sources":["../../src/stringify-json-with-bigints.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIxF"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/rpc-spec-types",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "Shared generic JSON RPC specifications",
|
|
5
5
|
"exports": {
|
|
6
|
+
"edge-light": {
|
|
7
|
+
"import": "./dist/index.node.mjs",
|
|
8
|
+
"require": "./dist/index.node.cjs"
|
|
9
|
+
},
|
|
10
|
+
"workerd": {
|
|
11
|
+
"import": "./dist/index.node.mjs",
|
|
12
|
+
"require": "./dist/index.node.cjs"
|
|
13
|
+
},
|
|
6
14
|
"browser": {
|
|
7
15
|
"import": "./dist/index.browser.mjs",
|
|
8
16
|
"require": "./dist/index.browser.cjs"
|
|
@@ -56,13 +64,16 @@
|
|
|
56
64
|
}
|
|
57
65
|
]
|
|
58
66
|
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=20.18.0"
|
|
69
|
+
},
|
|
59
70
|
"scripts": {
|
|
60
71
|
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
61
72
|
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
62
73
|
"dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
63
74
|
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks",
|
|
64
75
|
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
65
|
-
"style:fix": "pnpm eslint --fix src
|
|
76
|
+
"style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
|
|
66
77
|
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
67
78
|
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
68
79
|
"test:treeshakability:browser": "agadoo dist/index.browser.mjs",
|