@bgd-labs/toolbox 0.0.0 → 0.0.1
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/index.d.mts +16 -18
- package/dist/index.d.ts +16 -18
- package/dist/index.js +67 -1
- package/dist/index.mjs +56 -1
- package/package.json +9 -6
package/dist/index.d.mts
CHANGED
|
@@ -52,23 +52,19 @@ type GetSourceCodeParams = {
|
|
|
52
52
|
apiKey?: string;
|
|
53
53
|
};
|
|
54
54
|
declare function getSourceCode(params: GetSourceCodeParams): Promise<{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
SimilarMatch: string;
|
|
69
|
-
SourceCode: string;
|
|
70
|
-
}[];
|
|
71
|
-
status: string;
|
|
55
|
+
ABI: any;
|
|
56
|
+
CompilerVersion: string;
|
|
57
|
+
ConstructorArguments: Hex;
|
|
58
|
+
ContractName: string;
|
|
59
|
+
EVMVersion: string;
|
|
60
|
+
Implementation: Address;
|
|
61
|
+
Library: string;
|
|
62
|
+
LicenseType: string;
|
|
63
|
+
OptimizationUsed: string;
|
|
64
|
+
Proxy: string;
|
|
65
|
+
Runs: string;
|
|
66
|
+
SimilarMatch: string;
|
|
67
|
+
SourceCode: string;
|
|
72
68
|
}>;
|
|
73
69
|
declare function parseApiSourceCode(sourceCode: string): {
|
|
74
70
|
language: string;
|
|
@@ -85,4 +81,6 @@ declare function parseApiSourceCode(sourceCode: string): {
|
|
|
85
81
|
}>;
|
|
86
82
|
};
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
declare function diffCode(codeBefore: string, codeAfter: string): Promise<Record<string, string>>;
|
|
85
|
+
|
|
86
|
+
export { type ExplorerConfig, bitmapToIndexes, decodeUserConfiguration, diffCode, getBits, getExplorer, getSourceCode, parseApiSourceCode };
|
package/dist/index.d.ts
CHANGED
|
@@ -52,23 +52,19 @@ type GetSourceCodeParams = {
|
|
|
52
52
|
apiKey?: string;
|
|
53
53
|
};
|
|
54
54
|
declare function getSourceCode(params: GetSourceCodeParams): Promise<{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
SimilarMatch: string;
|
|
69
|
-
SourceCode: string;
|
|
70
|
-
}[];
|
|
71
|
-
status: string;
|
|
55
|
+
ABI: any;
|
|
56
|
+
CompilerVersion: string;
|
|
57
|
+
ConstructorArguments: Hex;
|
|
58
|
+
ContractName: string;
|
|
59
|
+
EVMVersion: string;
|
|
60
|
+
Implementation: Address;
|
|
61
|
+
Library: string;
|
|
62
|
+
LicenseType: string;
|
|
63
|
+
OptimizationUsed: string;
|
|
64
|
+
Proxy: string;
|
|
65
|
+
Runs: string;
|
|
66
|
+
SimilarMatch: string;
|
|
67
|
+
SourceCode: string;
|
|
72
68
|
}>;
|
|
73
69
|
declare function parseApiSourceCode(sourceCode: string): {
|
|
74
70
|
language: string;
|
|
@@ -85,4 +81,6 @@ declare function parseApiSourceCode(sourceCode: string): {
|
|
|
85
81
|
}>;
|
|
86
82
|
};
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
declare function diffCode(codeBefore: string, codeAfter: string): Promise<Record<string, string>>;
|
|
85
|
+
|
|
86
|
+
export { type ExplorerConfig, bitmapToIndexes, decodeUserConfiguration, diffCode, getBits, getExplorer, getSourceCode, parseApiSourceCode };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -22,6 +32,7 @@ var index_exports = {};
|
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
bitmapToIndexes: () => bitmapToIndexes,
|
|
24
34
|
decodeUserConfiguration: () => decodeUserConfiguration,
|
|
35
|
+
diffCode: () => diffCode,
|
|
25
36
|
getBits: () => getBits,
|
|
26
37
|
getExplorer: () => getExplorer,
|
|
27
38
|
getSourceCode: () => getSourceCode,
|
|
@@ -944,7 +955,11 @@ async function getSourceCode(params) {
|
|
|
944
955
|
const formattedPayload = new URLSearchParams(payload).toString();
|
|
945
956
|
const url = `${params.apiUrl ? params.apiUrl : getExplorer(params.chainId).api}?${formattedPayload}`;
|
|
946
957
|
const request = await fetch(url);
|
|
947
|
-
|
|
958
|
+
const { status, message, result } = await request.json();
|
|
959
|
+
if (status != "1") {
|
|
960
|
+
throw new Error(result);
|
|
961
|
+
}
|
|
962
|
+
return result[0];
|
|
948
963
|
}
|
|
949
964
|
function parseApiSourceCode(sourceCode) {
|
|
950
965
|
if (sourceCode.startsWith("{{") && sourceCode.endsWith("}}")) {
|
|
@@ -952,10 +967,61 @@ function parseApiSourceCode(sourceCode) {
|
|
|
952
967
|
}
|
|
953
968
|
return JSON.parse(sourceCode);
|
|
954
969
|
}
|
|
970
|
+
|
|
971
|
+
// src/operations/diffCode.ts
|
|
972
|
+
var import_diff = require("diff");
|
|
973
|
+
var import_standalone = require("prettier/standalone");
|
|
974
|
+
var import_standalone2 = __toESM(require("prettier-plugin-solidity/standalone"));
|
|
975
|
+
var prettierOptions = { parser: "solidity-parse", plugins: [import_standalone2.default] };
|
|
976
|
+
async function diffCode(codeBefore, codeAfter) {
|
|
977
|
+
const before = parseApiSourceCode(codeBefore);
|
|
978
|
+
const after = parseApiSourceCode(codeAfter);
|
|
979
|
+
const changes = {};
|
|
980
|
+
const settingsBefore = JSON.stringify(before.settings, null, 2);
|
|
981
|
+
const settingsAfter = JSON.stringify(after.settings, null, 2);
|
|
982
|
+
if (settingsBefore !== settingsAfter)
|
|
983
|
+
changes.settings = (0, import_diff.createPatch)("settings", settingsBefore, settingsAfter);
|
|
984
|
+
const contractsBefore = await Promise.all(
|
|
985
|
+
Object.entries(before.sources).map(async ([path, source]) => [
|
|
986
|
+
path.replace(/^.*[\\/]/, ""),
|
|
987
|
+
path,
|
|
988
|
+
await (0, import_standalone.format)(source.content, prettierOptions)
|
|
989
|
+
])
|
|
990
|
+
);
|
|
991
|
+
const contractsAfter = await Promise.all(
|
|
992
|
+
Object.entries(after.sources).map(async ([path, source]) => [
|
|
993
|
+
path.replace(/^.*[\\/]/, ""),
|
|
994
|
+
path,
|
|
995
|
+
await (0, import_standalone.format)(source.content, prettierOptions)
|
|
996
|
+
])
|
|
997
|
+
);
|
|
998
|
+
for (const [name, path, source] of contractsBefore) {
|
|
999
|
+
const indexAfter = contractsAfter.findIndex(([_name]) => _name === name);
|
|
1000
|
+
if (indexAfter === -1) {
|
|
1001
|
+
changes[name] = (0, import_diff.createPatch)(path, source, "");
|
|
1002
|
+
} else {
|
|
1003
|
+
if (source !== contractsAfter[indexAfter][2])
|
|
1004
|
+
changes[name] = (0, import_diff.createTwoFilesPatch)(
|
|
1005
|
+
path,
|
|
1006
|
+
contractsAfter[indexAfter][1],
|
|
1007
|
+
source,
|
|
1008
|
+
contractsAfter[indexAfter][2]
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
for (const [name, path, source] of contractsAfter) {
|
|
1013
|
+
const indexAfter = contractsBefore.findIndex(([_name]) => _name === name);
|
|
1014
|
+
if (indexAfter === -1) {
|
|
1015
|
+
changes[name] = (0, import_diff.createPatch)(path, "", source);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return changes;
|
|
1019
|
+
}
|
|
955
1020
|
// Annotate the CommonJS export names for ESM import in node:
|
|
956
1021
|
0 && (module.exports = {
|
|
957
1022
|
bitmapToIndexes,
|
|
958
1023
|
decodeUserConfiguration,
|
|
1024
|
+
diffCode,
|
|
959
1025
|
getBits,
|
|
960
1026
|
getExplorer,
|
|
961
1027
|
getSourceCode,
|
package/dist/index.mjs
CHANGED
|
@@ -913,7 +913,11 @@ async function getSourceCode(params) {
|
|
|
913
913
|
const formattedPayload = new URLSearchParams(payload).toString();
|
|
914
914
|
const url = `${params.apiUrl ? params.apiUrl : getExplorer(params.chainId).api}?${formattedPayload}`;
|
|
915
915
|
const request = await fetch(url);
|
|
916
|
-
|
|
916
|
+
const { status, message, result } = await request.json();
|
|
917
|
+
if (status != "1") {
|
|
918
|
+
throw new Error(result);
|
|
919
|
+
}
|
|
920
|
+
return result[0];
|
|
917
921
|
}
|
|
918
922
|
function parseApiSourceCode(sourceCode) {
|
|
919
923
|
if (sourceCode.startsWith("{{") && sourceCode.endsWith("}}")) {
|
|
@@ -921,9 +925,60 @@ function parseApiSourceCode(sourceCode) {
|
|
|
921
925
|
}
|
|
922
926
|
return JSON.parse(sourceCode);
|
|
923
927
|
}
|
|
928
|
+
|
|
929
|
+
// src/operations/diffCode.ts
|
|
930
|
+
import { createPatch, createTwoFilesPatch } from "diff";
|
|
931
|
+
import { format } from "prettier/standalone";
|
|
932
|
+
import solidityPlugin from "prettier-plugin-solidity/standalone";
|
|
933
|
+
var prettierOptions = { parser: "solidity-parse", plugins: [solidityPlugin] };
|
|
934
|
+
async function diffCode(codeBefore, codeAfter) {
|
|
935
|
+
const before = parseApiSourceCode(codeBefore);
|
|
936
|
+
const after = parseApiSourceCode(codeAfter);
|
|
937
|
+
const changes = {};
|
|
938
|
+
const settingsBefore = JSON.stringify(before.settings, null, 2);
|
|
939
|
+
const settingsAfter = JSON.stringify(after.settings, null, 2);
|
|
940
|
+
if (settingsBefore !== settingsAfter)
|
|
941
|
+
changes.settings = createPatch("settings", settingsBefore, settingsAfter);
|
|
942
|
+
const contractsBefore = await Promise.all(
|
|
943
|
+
Object.entries(before.sources).map(async ([path, source]) => [
|
|
944
|
+
path.replace(/^.*[\\/]/, ""),
|
|
945
|
+
path,
|
|
946
|
+
await format(source.content, prettierOptions)
|
|
947
|
+
])
|
|
948
|
+
);
|
|
949
|
+
const contractsAfter = await Promise.all(
|
|
950
|
+
Object.entries(after.sources).map(async ([path, source]) => [
|
|
951
|
+
path.replace(/^.*[\\/]/, ""),
|
|
952
|
+
path,
|
|
953
|
+
await format(source.content, prettierOptions)
|
|
954
|
+
])
|
|
955
|
+
);
|
|
956
|
+
for (const [name, path, source] of contractsBefore) {
|
|
957
|
+
const indexAfter = contractsAfter.findIndex(([_name]) => _name === name);
|
|
958
|
+
if (indexAfter === -1) {
|
|
959
|
+
changes[name] = createPatch(path, source, "");
|
|
960
|
+
} else {
|
|
961
|
+
if (source !== contractsAfter[indexAfter][2])
|
|
962
|
+
changes[name] = createTwoFilesPatch(
|
|
963
|
+
path,
|
|
964
|
+
contractsAfter[indexAfter][1],
|
|
965
|
+
source,
|
|
966
|
+
contractsAfter[indexAfter][2]
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
for (const [name, path, source] of contractsAfter) {
|
|
971
|
+
const indexAfter = contractsBefore.findIndex(([_name]) => _name === name);
|
|
972
|
+
if (indexAfter === -1) {
|
|
973
|
+
changes[name] = createPatch(path, "", source);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return changes;
|
|
977
|
+
}
|
|
924
978
|
export {
|
|
925
979
|
bitmapToIndexes,
|
|
926
980
|
decodeUserConfiguration,
|
|
981
|
+
diffCode,
|
|
927
982
|
getBits,
|
|
928
983
|
getExplorer,
|
|
929
984
|
getSourceCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgd-labs/toolbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,23 +14,26 @@
|
|
|
14
14
|
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
15
15
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
16
16
|
"test": "vitest",
|
|
17
|
-
"generate": "npm run generate:explorers",
|
|
18
|
-
"generate:explorers": "bun scripts/explorer.ts"
|
|
17
|
+
"generate": "npm run generate:explorers && npm run generate:rpcs",
|
|
18
|
+
"generate:explorers": "bun scripts/explorer.ts",
|
|
19
|
+
"generate:rpcs": "bun scripts/rpc.ts"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"@types/diff": "^7.0.1",
|
|
22
23
|
"@types/node": "^22.13.4",
|
|
23
24
|
"tsup": "^8.0.2",
|
|
24
|
-
"typescript": "5.5.4"
|
|
25
|
+
"typescript": "5.5.4",
|
|
26
|
+
"vitest": "^3.0.6"
|
|
25
27
|
},
|
|
26
28
|
"publishConfig": {
|
|
27
29
|
"access": "public"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
32
|
+
"blockstore-core": "^5.0.2",
|
|
30
33
|
"diff": "^7.0.0",
|
|
34
|
+
"ipfs-unixfs-importer": "^15.3.1",
|
|
31
35
|
"prettier": "^3.5.2",
|
|
32
36
|
"prettier-plugin-solidity": "^1.4.2",
|
|
33
|
-
"viem": "^2.23.4"
|
|
34
|
-
"vitest": "^3.0.6"
|
|
37
|
+
"viem": "^2.23.4"
|
|
35
38
|
}
|
|
36
39
|
}
|